CustomerServiceImpl.java 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634
  1. package com.goafanti.customer.service.impl;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.HashSet;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Set;
  11. import java.util.UUID;
  12. import javax.annotation.Resource;
  13. import org.apache.commons.beanutils.BeanUtils;
  14. import org.apache.commons.beanutils.PropertyUtils;
  15. import org.apache.ibatis.builder.BuilderException;
  16. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import com.goafanti.common.bo.Error;
  22. import com.goafanti.common.bo.userDaysBo;
  23. import com.goafanti.common.constant.AFTConstants;
  24. import com.goafanti.common.constant.ErrorConstants;
  25. import com.goafanti.common.dao.AdminMapper;
  26. import com.goafanti.common.dao.BusinessGlossoryMapper;
  27. import com.goafanti.common.dao.BusinessProjectMapper;
  28. import com.goafanti.common.dao.OrganizationAnnualReportMapper;
  29. import com.goafanti.common.dao.OrganizationApplicationInfoMapper;
  30. import com.goafanti.common.dao.OrganizationContactBookMapper;
  31. import com.goafanti.common.dao.OrganizationIdentityMapper;
  32. import com.goafanti.common.dao.OrganizationYearProjectMapper;
  33. import com.goafanti.common.dao.UserBusinessMapper;
  34. import com.goafanti.common.dao.UserFollowBusinessMapper;
  35. import com.goafanti.common.dao.UserFollowMapper;
  36. import com.goafanti.common.dao.UserIdentityMapper;
  37. import com.goafanti.common.dao.UserLockReleaseMapper;
  38. import com.goafanti.common.dao.UserMapper;
  39. import com.goafanti.common.dao.UserTransferLogMapper;
  40. import com.goafanti.common.enums.CustomerStatusFiled;
  41. import com.goafanti.common.enums.DeleteStatus;
  42. import com.goafanti.common.enums.IdentityProcess;
  43. import com.goafanti.common.enums.UserLevel;
  44. import com.goafanti.common.enums.UserLockReleaseStatus;
  45. import com.goafanti.common.enums.UserType;
  46. import com.goafanti.common.error.BusinessException;
  47. import com.goafanti.common.model.Admin;
  48. import com.goafanti.common.model.OrganizationApplicationInfo;
  49. import com.goafanti.common.model.OrganizationContactBook;
  50. import com.goafanti.common.model.OrganizationIdentity;
  51. import com.goafanti.common.model.User;
  52. import com.goafanti.common.model.UserBusiness;
  53. import com.goafanti.common.model.UserFollow;
  54. import com.goafanti.common.model.UserFollowBusiness;
  55. import com.goafanti.common.model.UserIdentity;
  56. import com.goafanti.common.model.UserLockRelease;
  57. import com.goafanti.common.model.UserTransferLog;
  58. import com.goafanti.common.utils.BeanUtilsExt;
  59. import com.goafanti.common.utils.DateUtils;
  60. import com.goafanti.common.utils.ExportExcelUtil;
  61. import com.goafanti.common.utils.PasswordUtil;
  62. import com.goafanti.common.utils.StringUtils;
  63. import com.goafanti.core.mybatis.BaseMybatisDao;
  64. import com.goafanti.core.mybatis.page.Pagination;
  65. import com.goafanti.core.shiro.token.TokenManager;
  66. import com.goafanti.customer.bo.BusinessListBo;
  67. import com.goafanti.customer.bo.BussinessFollowBo;
  68. import com.goafanti.customer.bo.CustomerExcelBo;
  69. import com.goafanti.customer.bo.CustomerListIn;
  70. import com.goafanti.customer.bo.CustomerListOut;
  71. import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
  72. import com.goafanti.customer.bo.CustomerPersonalDetailBo;
  73. import com.goafanti.customer.bo.CustomerSimpleBo;
  74. import com.goafanti.customer.bo.FollowBusinessBo;
  75. import com.goafanti.customer.bo.FollowListBo;
  76. import com.goafanti.customer.bo.LockingReleaseBo;
  77. import com.goafanti.customer.bo.StatisticBo;
  78. import com.goafanti.customer.bo.transferListBo;
  79. import com.goafanti.customer.service.CustomerService;
  80. @Service
  81. public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements CustomerService {
  82. @Autowired
  83. private UserMapper userMapper;
  84. @Autowired
  85. private UserIdentityMapper userIdentityMapper;
  86. @Autowired
  87. private OrganizationIdentityMapper organizationIdentityMapper;
  88. @Autowired
  89. private OrganizationContactBookMapper organizationContactBookMapper;
  90. @Resource(name = "passwordUtil")
  91. private PasswordUtil passwordUtil;
  92. @Value(value = "${user.receive.max}")
  93. private Integer USER_RECEIVE_MAX=null;
  94. @Value(value = "${user.private.max}")
  95. private Integer USER_PRIVATE_MAX=null;
  96. @Value(value = "${user_remind_days}")
  97. private Integer USER_REMIND_DAYS=null;
  98. @Resource
  99. private UserFollowMapper userFollowMapper;
  100. @Resource
  101. private UserBusinessMapper userBusinessMapper;
  102. @Resource
  103. private UserFollowBusinessMapper userFollowBusinessMapper;
  104. @Resource
  105. private BusinessGlossoryMapper businessGlossoryMapper;
  106. @Resource
  107. private BusinessProjectMapper businessProjectMapper;
  108. @Resource
  109. private UserLockReleaseMapper userLockReleaseMapper;
  110. @Resource
  111. private AdminMapper adminMapper;
  112. @Resource
  113. private OrganizationApplicationInfoMapper organizationApplicationInfoMapper;
  114. @Resource
  115. private OrganizationAnnualReportMapper organizationAnnualReportMapper;
  116. @Resource
  117. private OrganizationYearProjectMapper organizationYearProjectMapper;
  118. @Resource
  119. private UserTransferLogMapper userTransferLogMapper;
  120. @Value(value = "${upload.path}")
  121. private String uploadPath = null;
  122. @SuppressWarnings("unchecked")
  123. @Override
  124. public Pagination<CustomerListOut> listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  125. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  126. cli.setAid(TokenManager.getAdminId());
  127. Map<String,Object> params = disposeParams(cli);
  128. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPrivatePersonalCustomerList","selectPrivatePersonalCustomerCount",params,pageNo,pageSize);
  129. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  130. setCustomerList(tmpList,0);
  131. list.setList(tmpList);
  132. return list;
  133. }
  134. @SuppressWarnings("unchecked")
  135. @Override
  136. public Pagination<CustomerListOut> listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  137. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  138. Map<String,Object> params = disposeParams(cli);
  139. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPublicPersonalCustomerList","selectPublicPersonalCustomerCount",params,pageNo,pageSize);
  140. return list;
  141. }
  142. @SuppressWarnings("unchecked")
  143. @Override
  144. public Pagination<CustomerListOut> listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  145. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  146. Map<String,Object> params = disposeParams(cli);
  147. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
  148. return list;
  149. }
  150. @SuppressWarnings("unchecked")
  151. @Override
  152. public Pagination<CustomerListOut> listAllManagePersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  153. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  154. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  155. Map<String,Object> params = disposeParams(cli);
  156. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManagePersonalCustomerList","selectManagePersonalCustomerCount",params,pageNo,pageSize);
  157. return list;
  158. }
  159. @SuppressWarnings("unchecked")
  160. @Override
  161. public Pagination<CustomerListOut> listPrivateOrganizationCustomer(CustomerListIn cli,Integer sort,Integer sortType, Integer power,
  162. Integer pageNo,Integer pageSize) {
  163. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  164. cli.setAid(TokenManager.getAdminId());
  165. // cli.setAid("1");
  166. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  167. Map<String,Object> params = disposeParams(cli);
  168. params.put("sort", sort);
  169. params.put("sortType",sortType);
  170. if (power==null||TokenManager.hasRole(AFTConstants.SALESMAN)) {
  171. params.put("power", 0);
  172. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)) {
  173. params.put("power", 1);
  174. }else if (TokenManager.hasRole(AFTConstants.SALESMAN_DIRECTOR)) {
  175. params.put("power", 2);
  176. }
  177. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPrivateOrganizationCustomerList","selectPrivateOrganizationCustomerCount",params,pageNo,pageSize);
  178. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  179. setCustomerList(tmpList,0);
  180. list.setList(tmpList);
  181. return list;
  182. }
  183. @SuppressWarnings("unchecked")
  184. @Override
  185. public Pagination<CustomerListOut> listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  186. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  187. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC));
  188. Map<String,Object> params = disposeParams(cli);
  189. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPublicOrganizationCustomerList","selectPublicOrganizationCustomerCount",params,pageNo,pageSize);
  190. return list;
  191. }
  192. @SuppressWarnings("unchecked")
  193. @Override
  194. public Pagination<CustomerListOut> listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  195. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  196. Map<String,Object> params = disposeParams(cli);
  197. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  198. params.put("role", 1);
  199. }else {
  200. params.put("role", 0);
  201. }
  202. Pagination<CustomerListOut> p=(Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  203. List<CustomerListOut> l=(List<CustomerListOut>) p.getList();
  204. for (CustomerListOut c : l) {
  205. if (null!=c) {
  206. if(null!=c.getAid())c.setAdminName(adminMapper.selectNameByid(c.getAid()));
  207. if (null!=c.getShareType()&&c.getShareType().equals("1"))c.setAdminName("暂无");
  208. if(null!=c.getMid())c.setInformationMaintainer(adminMapper.selectNameByid(c.getMid()));
  209. }
  210. }
  211. return p;
  212. }
  213. @Override
  214. public Pagination<CustomerListOut> listAllManageOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  215. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  216. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  217. cli.setAid(TokenManager.getAdminId());
  218. Map<String,Object> params = disposeParams(cli);
  219. @SuppressWarnings("unchecked")
  220. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManageOrganizationCustomerList","selectManageOrganizationCustomerCount",params,pageNo,pageSize);
  221. return list;
  222. }
  223. private Map<String,Object> disposeParams(CustomerListIn cli){
  224. Map<String,Object> params = new HashMap<String, Object>();
  225. if(StringUtils.isNotBlank(cli.getType())) params.put("type", Integer.parseInt(cli.getType()));
  226. if(StringUtils.isNotBlank(cli.getShareType())) params.put("shareType", Integer.parseInt(cli.getShareType()));
  227. if(StringUtils.isNotBlank(cli.getName())) params.put("name", cli.getName());
  228. if(StringUtils.isNotBlank(cli.getProvince())) params.put("province", Integer.parseInt(cli.getProvince()));
  229. if(StringUtils.isNotBlank(cli.getCity())) params.put("city", Integer.parseInt(cli.getCity()));
  230. if(StringUtils.isNotBlank(cli.getArea())) params.put("area", Integer.parseInt(cli.getArea()));
  231. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate());
  232. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate());
  233. if(StringUtils.isNotBlank(cli.getIndustry())) params.put("industry", Integer.parseInt(cli.getIndustry()));
  234. if(StringUtils.isNotBlank(cli.getAid())) params.put("aid", cli.getAid());
  235. if(StringUtils.isNotBlank(cli.getDepartmentId())) params.put("departmentId", cli.getDepartmentId());
  236. if(StringUtils.isNotBlank(cli.getStatus())) params.put("status", Integer.parseInt(cli.getStatus()));
  237. if(StringUtils.isNotBlank(cli.getSocietyTag())) params.put("societyTag", cli.getSocietyTag());
  238. if(StringUtils.isNotBlank(cli.getFollow())) params.put("follow", cli.getFollow());
  239. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate()+" 00:00:00");
  240. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate()+" 23:59:59");
  241. if(null!=cli.getDataGrade()) params.put("dataGrade", cli.getDataGrade());
  242. if(null!=cli.getLevel())params.put("level", cli.getLevel());
  243. if(null!=cli.getSort())params.put("sort", cli.getSort());
  244. return params;
  245. }
  246. @Override
  247. public List<CustomerSimpleBo> findCustomerByName(String name) {
  248. return userMapper.findCustomerByName(name);
  249. }
  250. @Override
  251. public int judgeCustomerByName(String name) {
  252. return userMapper.judgeCustomerByName(name);
  253. }
  254. @Override
  255. @Transactional
  256. public int addCustomer(String name, String contacts, String contactMobile, Integer type, Integer source,String societyTag,
  257. Integer province ,Integer city, Integer area) throws BusinessException{
  258. User user = new User();
  259. Date now = new Date();
  260. String uid = UUID.randomUUID().toString();
  261. String identifyId = UUID.randomUUID().toString();
  262. user.setId(uid);
  263. user.setIdentifyName(name);
  264. user.setSource(1);//客户来源为录入
  265. user.setNickname(name);
  266. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  267. user.setShareType(AFTConstants.NO);
  268. user.setAid(TokenManager.getAdminId());
  269. // user.setAid("1");
  270. user.setType(type);
  271. user.setLvl(UserLevel.CERTIFIED.getCode());
  272. user.setSocietyTag(societyTag);
  273. user.setCreateTime(now);
  274. user.setTransferTime(now);
  275. user.setUpdateTime(now);
  276. user.setMobile(contactMobile);
  277. user.setPassword(AFTConstants.INITIALPASSWORD);
  278. user.setInformationMaintainer(TokenManager.getAdminId());
  279. float f=0;
  280. user.setIntegrity(f);
  281. // user.setInformationMaintainer("1");
  282. passwordUtil.encryptPassword(user);
  283. if(type == UserType.PERSONAL.getCode()){
  284. if(userMapper.checkUser("", "", contactMobile, type,null,null).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,""));
  285. UserIdentity ui = new UserIdentity();
  286. ui.setId(identifyId);
  287. ui.setUid(uid);
  288. ui.setContacts(contacts);
  289. ui.setContactMobile(contactMobile);
  290. ui.setUsername(name);
  291. ui.setProvince(province);
  292. ui.setCity(city);
  293. ui.setArea(area);
  294. ui.setExpert(AFTConstants.NO);
  295. ui.setCelebrity(AFTConstants.NO);
  296. ui.setInternational(AFTConstants.NO);
  297. ui.setAuditStatus(IdentityProcess.SUCCESS.getCode());//认证个人
  298. userIdentityMapper.insert(ui);
  299. }else if(type == UserType.ORGANIZATION.getCode()){
  300. if(userMapper.checkUser("",name,"",type,null,null).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,""));
  301. // 创建企业认证信息
  302. OrganizationIdentity oi = new OrganizationIdentity();
  303. oi.setUnitName(name);
  304. oi.setId(identifyId);
  305. oi.setUid(uid);
  306. oi.setContacts(contacts);
  307. oi.setContactMobile(contactMobile);
  308. oi.setLocationProvince(province);
  309. oi.setLocationCity(city);
  310. oi.setLocationArea(area);
  311. oi.setHighTechZone(AFTConstants.NO);
  312. oi.setInternational(AFTConstants.NO);
  313. oi.setListed(AFTConstants.NO);
  314. oi.setAuditStatus(IdentityProcess.SUCCESS.getCode()); //实名企业
  315. organizationIdentityMapper.insert(oi);
  316. }
  317. userMapper.insert(user);
  318. //新增企业联系人
  319. OrganizationContactBook cob = new OrganizationContactBook();
  320. cob.setAid(TokenManager.getAdminId());
  321. // cob.setAid("1");
  322. cob.setId(UUID.randomUUID().toString());
  323. cob.setUid(uid);
  324. cob.setName(contacts);
  325. cob.setMobile(contactMobile);
  326. cob.setMajor(AFTConstants.YES);
  327. organizationContactBookMapper.insert(cob);
  328. //新增锁定数据
  329. addUserLock(uid, TokenManager.getAdminId(),0,null, now);
  330. return 1;
  331. }
  332. @Override
  333. public CustomerPersonalDetailBo findPersonalCustomerDetail(String uid) {
  334. return userMapper.findPersonalCustomerDetail(uid);
  335. }
  336. @Override
  337. public CustomerOrganizationDetailBo findOrganizationCustomerDetail(String uid) {
  338. return userMapper.findOrganizationCustomerDetail(uid);
  339. }
  340. @Override
  341. @Transactional
  342. public int updateOrganizationCustomer(CustomerOrganizationDetailBo bo) {
  343. OrganizationIdentity oi = new OrganizationIdentity();
  344. User user = new User();
  345. Date date =new Date();
  346. OrganizationApplicationInfo oa=new OrganizationApplicationInfo();
  347. try {
  348. BeanUtilsExt.copyProperties(oi, bo);
  349. user.setId(bo.getUid());
  350. user.setSocietyTag(bo.getSocietyTag());
  351. user.setCompanyLogoUrl(bo.getCompanyLogoUrl());
  352. user.setIntroduction(bo.getIntroduction());
  353. user.setUpdateTime(date);
  354. user.setInformationMaintainer(bo.getInformationMaintainer());
  355. user.setCoreTechnology(bo.getCoreTechnology());
  356. user.setAccomplishSituation(bo.getAccomplishSituation());
  357. user.setIntellectualProperty(bo.getIntellectualProperty());
  358. user.setCreditRating(bo.getCreditRating());
  359. user.setIntegrity(countIntegrity(bo));
  360. if (StringUtils.isNotBlank(bo.getPojectApplicationUrl())) {
  361. List<OrganizationApplicationInfo> l=organizationApplicationInfoMapper.selectByUid(bo.getUid());
  362. if(l.size()>0){
  363. oa=l.get(0);
  364. oa.setPojectApplicationUrl(bo.getPojectApplicationUrl());
  365. organizationApplicationInfoMapper.updateByPrimaryKey(oa);
  366. }else {
  367. oa.setId(UUID.randomUUID().toString());
  368. oa.setCreateTime(date);
  369. oa.setUid(bo.getUid());
  370. oa.setPojectApplicationUrl(bo.getPojectApplicationUrl());
  371. organizationApplicationInfoMapper.insert(oa);
  372. }
  373. }
  374. } catch (IllegalAccessException |InvocationTargetException e) {
  375. e.printStackTrace();
  376. }
  377. organizationIdentityMapper.updateByPrimaryKey(oi);
  378. userMapper.updateByPrimaryKeySelective(user);
  379. return 1;
  380. }
  381. public Float countIntegrity(CustomerOrganizationDetailBo bo) {
  382. //完整资料总数
  383. int max=10;
  384. int number=0;
  385. if(null!=bo.getIndustry())number+=1;
  386. if(bo.getLocationProvince()!=null)number+=1;
  387. if(StringUtils.isNotBlank(bo.getBusinessScope()))number+=1;
  388. if(bo.getRegisteredCapital()!=null)number+=1;
  389. if(StringUtils.isNotBlank(bo.getCooperationSituation()))number+=1;
  390. if(StringUtils.isNotBlank(bo.getQualification()))number+=1;
  391. if (organizationAnnualReportMapper.selectOrgAnnualCount(bo.getUid())>0)number+=1;
  392. if (organizationAnnualReportMapper.selectOrgYearProjectCount(bo.getUid())>0)number+=1;
  393. if(StringUtils.isNotBlank(bo.getCoreTechnology()))number+=1;
  394. if(bo.getCreditRating()!=null)number+=1;
  395. float f= (float)number/max;
  396. return f;
  397. }
  398. @Override
  399. public int updatePersonalCustomer(CustomerPersonalDetailBo bo) {
  400. UserIdentity ui = new UserIdentity();
  401. User user = new User();
  402. try {
  403. try {
  404. PropertyUtils.copyProperties(ui,bo);
  405. } catch (NoSuchMethodException e) {
  406. e.printStackTrace();
  407. }
  408. user.setId(bo.getUid());
  409. user.setSocietyTag(bo.getSocietyTag());
  410. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  411. user.setIntroduction(bo.getIntroduction());
  412. user.setUpdateTime(new Date());
  413. if(null==bo.getExpertAudit()&&bo.getExpert()==1)ui.setExpertAudit(2);
  414. } catch (InvocationTargetException | IllegalAccessException e) {
  415. e.printStackTrace();
  416. }
  417. userIdentityMapper.updateByPrimaryKeySelective(ui);
  418. userMapper.updateByPrimaryKeySelective(user);
  419. return 1;
  420. }
  421. @SuppressWarnings("unchecked")
  422. @Override
  423. public Pagination<FollowListBo> listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessProjectId) {
  424. Map<String, Object> params = new HashMap<String, Object>();
  425. if(StringUtils.isNotBlank(uid))params.put("uid", uid);
  426. if(StringUtils.isNotBlank(businessProjectId)) params.put("businessProjectId", businessProjectId);
  427. Pagination<FollowListBo> page = (Pagination<FollowListBo>)findPage("selectFollowHistoryList","selectFollowHistoryCount",params, pageNo, pageSize);
  428. List<FollowListBo> list = (List<FollowListBo>)page.getList();
  429. for(FollowListBo bo : list){
  430. if(bo.getAid().equals(TokenManager.getAdminId())){
  431. bo.setReadOnly(AFTConstants.NO);
  432. }else{
  433. bo.setContactMobile("***");
  434. bo.setContacts("***");
  435. bo.setReadOnly(AFTConstants.YES);
  436. }
  437. }
  438. page.setList(list);
  439. return page;
  440. }
  441. @Override
  442. public User findUserAccountDetail(String uid) {
  443. return userMapper.findUserAccountDetail(uid);
  444. }
  445. @Override
  446. public int updateUserAccount(User user) {
  447. return userMapper.updateByPrimaryKeySelective(user);
  448. }
  449. @Override
  450. public List<OrganizationContactBook> findCustomerContacts(String uid) {
  451. return userMapper.findCustomerContacts(uid,TokenManager.getAdminId());
  452. }
  453. @Override
  454. @Transactional
  455. public int addFollow(FollowBusinessBo fbb) throws BusinessException{
  456. //更新跟进记录表
  457. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  458. UserFollow userFollow = new UserFollow();
  459. String followId = UUID.randomUUID().toString();
  460. userFollow.setId(followId);
  461. userFollow.setAid(TokenManager.getAdminId());
  462. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  463. userFollow.setEffective(DeleteStatus.UNDELETE.getCode());
  464. try {
  465. userFollow.setCreateTime(format.parse(fbb.getFollowTime()));
  466. } catch (ParseException e) {
  467. e.printStackTrace();
  468. }
  469. userFollow.setOcbId(fbb.getOcbId());
  470. userFollow.setResult(fbb.getResult());
  471. userFollow.setUid(fbb.getUid());
  472. int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), TokenManager.getAdminId()) + 1;
  473. userFollow.setFollowCount(followCount);
  474. userFollowMapper.insert(userFollow);
  475. //检查客户锁定情况
  476. if(fbb.getUserBusinessList().size()>0){
  477. boolean isUserOwner = false;
  478. List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(), TokenManager.getAdminId(),null, 0, UserLockReleaseStatus.LOCKED.getCode());
  479. if(userLockedList.size() > 0){
  480. isUserOwner = true;
  481. }
  482. boolean isBusinessOwner = false;
  483. List<LockingReleaseBo> businessLockedList = null;
  484. String businessName= "";
  485. String ufbId = "";
  486. UserBusiness userBusiness = null;
  487. UserFollowBusiness userFollowBusiness = null;
  488. for(BusinessListBo ub: fbb.getUserBusinessList()){
  489. userBusiness = new UserBusiness();
  490. userFollowBusiness = new UserFollowBusiness();
  491. ufbId = UUID.randomUUID().toString();
  492. businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
  493. UserBusiness us=userBusinessMapper.selectByPrimaryKey(ub.getBusinessId());
  494. if(StringUtils.isNotBlank(ub.getBusinessId())){
  495. //更新业务表
  496. userBusiness.setId(ub.getBusinessId());
  497. if (us.getFollowSituation()==5) {//如果已签合同,则不允许变更
  498. if (ub.getCustomerStatus()!=us.getCustomerStatus()&& ub.getFollowSituation()!=5) {
  499. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));
  500. }
  501. }
  502. //检查业务锁定情况
  503. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  504. if(businessLockedList.size() > 0){
  505. for(LockingReleaseBo bo : businessLockedList){
  506. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  507. }
  508. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  509. }else{
  510. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  511. }
  512. if (us.getFollowSituation()!=5&&ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
  513. if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
  514. lockProject(ub);//锁定客户业务
  515. }
  516. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  517. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  518. userBusiness.setFollowSituation(ub.getFollowSituation());
  519. userBusiness.setRemarks(ub.getRemarks());
  520. userBusiness.setUid(fbb.getUid());
  521. try {
  522. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  523. } catch (ParseException e) {
  524. e.printStackTrace();
  525. }
  526. userBusiness.setAid(TokenManager.getAdminId());
  527. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  528. //更新业务中间表
  529. userFollowBusiness.setBusinessId(ub.getBusinessProjectId());
  530. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  531. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  532. userFollowBusiness.setId(ufbId);
  533. userFollowBusiness.setFollowId(followId);
  534. userFollowBusiness.setRemarks(ub.getRemarks());
  535. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  536. userFollowBusinessMapper.insert(userFollowBusiness);
  537. }else{
  538. //检查业务锁定情况
  539. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  540. if(businessLockedList.size() > 0){
  541. for(LockingReleaseBo bo : businessLockedList){
  542. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  543. }
  544. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  545. }else{
  546. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  547. }
  548. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "")>0){
  549. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  550. }
  551. if (ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
  552. if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
  553. lockProject(ub);//锁定客户业务
  554. }
  555. String ubId = UUID.randomUUID().toString();
  556. //更新业务表
  557. userBusiness.setId(ubId);
  558. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  559. try {
  560. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  561. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  562. } catch (ParseException e) {
  563. e.printStackTrace();
  564. }
  565. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  566. userBusiness.setFollowSituation(ub.getFollowSituation());
  567. userBusiness.setUid(fbb.getUid());
  568. userBusiness.setAid(TokenManager.getAdminId());
  569. userBusiness.setRemarks(ub.getRemarks());
  570. userBusinessMapper.insert(userBusiness);
  571. //更新业务中间表
  572. userFollowBusiness.setBusinessId(ubId);
  573. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  574. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  575. userFollowBusiness.setId(ufbId);
  576. userFollowBusiness.setFollowId(followId);
  577. userFollowBusiness.setRemarks(ub.getRemarks());
  578. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  579. userFollowBusinessMapper.insert(userFollowBusiness);
  580. }
  581. }
  582. }
  583. return 1;
  584. }
  585. private void lockProject(BusinessListBo ub) {
  586. UserLockRelease ulr= new UserLockRelease();
  587. ulr.setId(UUID.randomUUID().toString());
  588. ulr.setType(1);
  589. ulr.setAid(TokenManager.getAdminId());
  590. ulr.setBusinessProjectId(ub.getBusinessProjectId());
  591. SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
  592. try {
  593. if (null==ub.getCreateTime()) {
  594. ulr.setLockTime(new Date());
  595. }else {
  596. ulr.setLockTime(sdf.parse(ub.getCreateTime()));
  597. }
  598. } catch (ParseException e) {
  599. e.printStackTrace();
  600. }
  601. ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
  602. ulr.setUid(ub.getUid());
  603. userLockReleaseMapper.insert(ulr);
  604. }
  605. @SuppressWarnings("unused")
  606. private void releaseProject(List<LockingReleaseBo> businessLockedList) {
  607. if(businessLockedList != null && businessLockedList.size()>0){
  608. UserLockRelease ulr = null;
  609. for(LockingReleaseBo bo : businessLockedList){
  610. ulr = new UserLockRelease();
  611. ulr.setId(bo.getId());
  612. ulr.setStatus(UserLockReleaseStatus.RELEASE.getCode());
  613. userLockReleaseMapper.updateByPrimaryKeySelective(ulr);
  614. }
  615. }
  616. }
  617. @Override
  618. public FollowBusinessBo findFollowById(String followId) {
  619. return userMapper.findFollowById(followId);
  620. }
  621. @Override
  622. public List<BusinessListBo> findBusinessByFollowId(String followId) {
  623. return userMapper.findBusinessByFollowId(followId);
  624. }
  625. @Override
  626. @Transactional
  627. public int updateFollow(FollowBusinessBo fbb) throws BusinessException{
  628. UserFollow userFollow = new UserFollow();
  629. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  630. userFollow.setId(fbb.getFollowId());
  631. if(StringUtils.isNotBlank(fbb.getOcbId())) userFollow.setOcbId(fbb.getOcbId());
  632. userFollow.setResult(fbb.getResult());
  633. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  634. userFollowMapper.updateByPrimaryKeySelective(userFollow); //修改拜访记录表
  635. if(fbb.getUserBusinessList().size()>0){
  636. //检查客户锁定情况
  637. boolean isUserOwner = false;
  638. List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(), TokenManager.getAdminId(),null, 0, UserLockReleaseStatus.LOCKED.getCode());
  639. if(userLockedList.size() > 0){
  640. isUserOwner = true;
  641. }
  642. boolean isBusinessOwner = false;
  643. List<LockingReleaseBo> businessLockedList = null;
  644. String businessName= "";
  645. UserFollowBusiness userFollowBusiness = null;
  646. for(BusinessListBo ub: fbb.getUserBusinessList()){
  647. userFollowBusiness = new UserFollowBusiness();
  648. businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
  649. if(StringUtils.isNotBlank(ub.getUfbId())){
  650. userFollowBusiness.setId(ub.getUfbId());
  651. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  652. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  653. userFollowBusiness.setRemarks(ub.getRemarks());
  654. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); //修改拜访记录中间表
  655. }else{
  656. //检查业务锁定情况
  657. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null,ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  658. if(businessLockedList.size() > 0){
  659. for(LockingReleaseBo bo : businessLockedList){
  660. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  661. }
  662. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  663. }else{
  664. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  665. }
  666. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "")>0){
  667. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  668. }
  669. String ubId = UUID.randomUUID().toString();
  670. UserBusiness userBusiness = new UserBusiness();
  671. //更新业务表
  672. userBusiness.setId(ubId);
  673. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  674. try {
  675. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  676. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  677. } catch (ParseException e) {
  678. e.printStackTrace();
  679. }
  680. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  681. userBusiness.setFollowSituation(ub.getFollowSituation());
  682. userBusiness.setUid(fbb.getUid());
  683. userBusiness.setAid(TokenManager.getAdminId());
  684. userBusinessMapper.insert(userBusiness);
  685. //更新业务中间表
  686. String ufbId = UUID.randomUUID().toString();
  687. userFollowBusiness.setId(ufbId);
  688. userFollowBusiness.setFollowId(fbb.getFollowId());
  689. userFollowBusiness.setBusinessId(ubId);
  690. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  691. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  692. userFollowBusiness.setRemarks(ub.getRemarks());
  693. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  694. userFollowBusinessMapper.insert(userFollowBusiness);
  695. }
  696. }
  697. }
  698. return 1;
  699. }
  700. @Override
  701. public Set<OrganizationContactBook> findAllContacts(String uid) {
  702. Set<OrganizationContactBook> result = new HashSet<OrganizationContactBook>();
  703. result.addAll(userMapper.findAllContacts(uid));
  704. return result;
  705. }
  706. @Override
  707. public int updateCustomerContacts(List<OrganizationContactBook> ocbList,String uid) {
  708. if(ocbList.size()>0){
  709. OrganizationContactBook ocb = null;
  710. for(OrganizationContactBook item: ocbList){
  711. if(item!=null&&item.getMajor()!=null&&item.getMajor()==1) {
  712. //改变用户原本的联系人
  713. OrganizationIdentity oi=new OrganizationIdentity();
  714. oi.setContacts(item.getName());
  715. oi.setContactMobile(item.getMobile());
  716. oi.setUid(uid);
  717. organizationIdentityMapper.updateServiceByUid(oi);
  718. }
  719. ocb = new OrganizationContactBook();
  720. try {
  721. BeanUtils.copyProperties(ocb, item);
  722. if(StringUtils.isBlank(ocb.getId())){
  723. ocb.setId(UUID.randomUUID().toString());
  724. ocb.setUid(uid);
  725. ocb.setAid(TokenManager.getAdminId());
  726. Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  727. ocb.setAname(ad.getName());
  728. organizationContactBookMapper.insert(ocb);
  729. }else{
  730. organizationContactBookMapper.updateByPrimaryKeySelective(ocb);
  731. }
  732. } catch (IllegalAccessException | InvocationTargetException e) {
  733. e.printStackTrace();
  734. }
  735. }
  736. }
  737. return 1;
  738. }
  739. @Override
  740. public int deleteFollow(String followId) {
  741. UserFollow uf = new UserFollow();
  742. List<BusinessListBo> list= userMapper.findBusinessByFollowId(followId);
  743. for (BusinessListBo b : list) {
  744. if(b.getFollowSituation()==5)throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));;
  745. }
  746. uf.setId(followId);
  747. uf.setEffective(DeleteStatus.DELETED.getCode());
  748. return userFollowMapper.updateByPrimaryKeySelective(uf);
  749. }
  750. @Override
  751. public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows, Set<Integer> filterRows) {
  752. List<User> list = null;
  753. CustomerExcelBo[] bos = (CustomerExcelBo[])boSet.toArray(new CustomerExcelBo[] {});
  754. for (int i=0;i<bos.length;i++) {
  755. CustomerExcelBo bo = bos[i];
  756. CustomerExcelBo ceb = null;
  757. for(int j=0;j<i;j++){
  758. ceb = bos[j];
  759. if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){ //个人
  760. if(ceb.getMobile().equals(bo.getMobile()) && ceb.getCustomerType().equals(bo.getCustomerType())){
  761. bo.setUid(ceb.getUid());
  762. bo.setNewData(false);
  763. filterRows.add(bo.getRowNumber());
  764. break;
  765. }
  766. }else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){ //单位
  767. if(ceb.getIdentifyName().equals(bo.getIdentifyName()) && ceb.getCustomerType().equals(bo.getCustomerType())){
  768. bo.setUid(ceb.getUid());
  769. bo.setNewData(false);
  770. filterRows.add(bo.getRowNumber());
  771. break;
  772. }
  773. }
  774. }
  775. if(StringUtils.isBlank(bo.getUid())){ //是否已经存在
  776. if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){
  777. list = userMapper.checkUser("", "", bo.getMobile(), Integer.parseInt(bo.getCustomerType()),null,null);
  778. }else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  779. list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()),null,null);
  780. }
  781. if (list.size() > 0) {
  782. bo.setUid(list.get(0).getId());
  783. bo.setNewData(false);
  784. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  785. if(businessLockedList.size() > 0){
  786. existRows.add(bo.getRowNumber());
  787. }
  788. }else{
  789. bo.setUid(UUID.randomUUID().toString());
  790. bo.setNewData(true);
  791. }
  792. }else{
  793. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  794. if(businessLockedList.size() > 0){
  795. existRows.add(bo.getRowNumber());
  796. }
  797. }
  798. }
  799. }
  800. @Override
  801. @Transactional
  802. public int saveUploadData(Set<CustomerExcelBo> boSet) {
  803. Date now = new Date();
  804. String uid = "";
  805. for(CustomerExcelBo bo : boSet){
  806. uid = bo.getUid();
  807. if(bo.isNewData()){ //新建客户
  808. createUser(bo, uid, now);
  809. createIdentity(bo, bo.getCustomerType(), uid);
  810. createBusiness(bo, uid, now);
  811. createContacts(bo, uid);
  812. }else{ //新建业务
  813. createBusiness(bo, uid, now);
  814. if(organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId())<=0){
  815. createContacts(bo, uid);
  816. }
  817. }
  818. }
  819. return 1;
  820. }
  821. private void createUser(CustomerExcelBo bo,String uid,Date now){
  822. User user = new User();
  823. user.setId(uid);
  824. user.setIdentifyName(bo.getIdentifyName());
  825. user.setSource(AFTConstants.USER_SOURCE_CREATE);
  826. user.setNickname(bo.getIdentifyName());
  827. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  828. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  829. user.setAid(TokenManager.getAdminId());
  830. user.setType(Integer.parseInt(bo.getCustomerType()));
  831. user.setLvl(UserLevel.CERTIFIED.getCode());
  832. user.setCreateTime(now);
  833. user.setUpdateTime(now);
  834. user.setMobile(bo.getMobile());
  835. user.setPassword(AFTConstants.INITIALPASSWORD);
  836. passwordUtil.encryptPassword(user);
  837. userMapper.insert(user);
  838. }
  839. private void createIdentity(CustomerExcelBo bo,String type,String uid){
  840. String identifyId = UUID.randomUUID().toString();
  841. if(type.equals(AFTConstants.USER_TYPE_PERSONAL)){
  842. //新增个人认证信息
  843. UserIdentity ui = new UserIdentity();
  844. ui.setId(identifyId);
  845. ui.setUid(uid);
  846. ui.setContacts(bo.getContacts());
  847. ui.setContactMobile(bo.getMobile());
  848. ui.setUsername(bo.getIdentifyName());
  849. ui.setExpert(AFTConstants.NO);
  850. ui.setCelebrity(AFTConstants.NO);
  851. ui.setInternational(AFTConstants.NO);
  852. ui.setAuditStatus(5);
  853. userIdentityMapper.insert(ui);
  854. }else if(type.equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  855. // 创建企业认证信息
  856. OrganizationIdentity oi = new OrganizationIdentity();
  857. oi.setId(identifyId);
  858. oi.setUnitName(bo.getIdentifyName());
  859. oi.setUid(uid);
  860. oi.setContacts(bo.getContacts());
  861. oi.setContactMobile(bo.getMobile());
  862. oi.setHighTechZone(AFTConstants.NO);
  863. oi.setInternational(AFTConstants.NO);
  864. oi.setListed(AFTConstants.NO);
  865. oi.setAuditStatus(5); //实名企业
  866. organizationIdentityMapper.insert(oi);
  867. }
  868. }
  869. private void createContacts(CustomerExcelBo bo,String uid){
  870. //新增企业联系人
  871. OrganizationContactBook cob = new OrganizationContactBook();
  872. cob.setAid(TokenManager.getAdminId());
  873. cob.setId(UUID.randomUUID().toString());
  874. cob.setUid(uid);
  875. cob.setName(bo.getContacts());
  876. cob.setMobile(bo.getMobile());
  877. cob.setMajor(AFTConstants.NO);
  878. organizationContactBookMapper.insert(cob);
  879. }
  880. private void createBusiness(CustomerExcelBo bo,String uid,Date now){
  881. //新增业务
  882. UserBusiness ub = new UserBusiness();
  883. ub.setId(UUID.randomUUID().toString());
  884. ub.setAid(TokenManager.getAdminId());
  885. ub.setBusinessProjectId(bo.getBusinessProjectId());
  886. ub.setUid(uid);
  887. ub.setCreateTime(now);
  888. ub.setUpdateTime(now);
  889. ub.setCustomerStatus(Integer.parseInt(bo.getCustomerStatus()));
  890. ub.setFollowSituation(Integer.parseInt(bo.getFollowSituation()));
  891. userBusinessMapper.insert(ub);
  892. }
  893. @Override
  894. public int updateByOperatorType(String uid,String oldAid, String operatorType,Object... params) {
  895. User user = new User();
  896. Date now = new Date();
  897. user.setId(uid);
  898. int flag = 0;
  899. if(operatorType.equals(AFTConstants.USER_RECEIVE)){
  900. if(userMapper.UserReceiveCount(TokenManager.getAdminId())>=USER_RECEIVE_MAX)
  901. throw new BusinessException(new Error(ErrorConstants.CUSTOM_EREXCESS,""+USER_RECEIVE_MAX,""));
  902. user.setAid(TokenManager.getAdminId());
  903. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  904. user.setInformationMaintainer(TokenManager.getAdminId());
  905. user.setSource(2);//客户来源设置为领取
  906. user.setTransferTime(now);
  907. flag = addUserLock(uid,TokenManager.getAdminId(),0,null,now); //指定用户锁定客户
  908. if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_RECEIVE,""));
  909. organizationContactBookMapper.updateAdmin(uid,TokenManager.getAdminId());
  910. }else if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_OTHER)){
  911. user.setAid(String.valueOf(params[0]));
  912. user.setSource(3);//客户来源设置为转交
  913. // 转换不重置时间
  914. // user.setTransferTime(now);
  915. //查询这个客户是否是登陆人的客户
  916. if(userMapper.getAidAndUser(uid,TokenManager.getAdminId())<=0)throw new BusinessException(new Error("请勿非法操作!","请勿非法操作!"));
  917. flag = updateUserLock(uid,oldAid,UserLockReleaseStatus.LOCKED.getCode(),UserLockReleaseStatus.RELEASE.getCode()); //原用户释放客户
  918. if(flag > 0 ) flag = addUserLock(uid,String.valueOf(params[0]),0,null,now); //指定用户锁定客户
  919. if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL,""));
  920. addtransferLog(uid,null,TokenManager.getAdminId(),String.valueOf(params[0]),0);
  921. }
  922. return userMapper.updateByPrimaryKeySelective(user);
  923. }
  924. @SuppressWarnings("unchecked")
  925. @Override
  926. public Pagination<StatisticBo> customerStatistics(Date sDate, Date eDate, String depNo, String businessGlossoryId, Integer pageNo, Integer pageSize) {
  927. Map<String,Object> params = new HashMap<String,Object>();
  928. if(null != sDate) params.put("sDate", sDate);
  929. if(null != eDate) params.put("eDate", eDate);
  930. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  931. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  932. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("customerStatisticsList", "customerStatisticsCount", params, pageNo, pageSize);
  933. return page;
  934. }
  935. @SuppressWarnings("unchecked")
  936. @Override
  937. public Pagination<StatisticBo> businessStatistic(Date sDate, Date eDate,String depNo, String businessGlossoryId,Integer pageNo, Integer pageSize) {
  938. Map<String,Object> params = new HashMap<String,Object>();
  939. if(null != sDate) params.put("sDate", sDate);
  940. if(null != eDate) params.put("eDate", eDate);
  941. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  942. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  943. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("businessStatisticList", "businessStatisticCount", params, pageNo, pageSize);
  944. return page;
  945. }
  946. @SuppressWarnings("unchecked")
  947. @Override
  948. public Pagination<StatisticBo> followStatistic(Date sDate, Date eDate, String depNo, Integer pageNo, Integer pageSize) {
  949. Map<String,Object> params = new HashMap<String,Object>();
  950. if(null != sDate) params.put("sDate", sDate);
  951. if(null != eDate) params.put("eDate", eDate);
  952. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  953. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("followStatisticList", "followStatisticCount", params, pageNo, pageSize);
  954. return page;
  955. }
  956. @SuppressWarnings("unchecked")
  957. @Override
  958. public Pagination<BusinessListBo> listBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) {
  959. blo.setAid(TokenManager.getAdminId());
  960. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  961. }
  962. @SuppressWarnings("unchecked")
  963. @Override
  964. public Pagination<BusinessListBo> listAllBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
  965. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  966. }
  967. @SuppressWarnings("unchecked")
  968. @Override
  969. public Pagination<BusinessListBo> listManageBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) {
  970. blo.setAid(TokenManager.getAdminId());
  971. return (Pagination<BusinessListBo>) findPage("selectBusinessManageList", "selectBusinessManageCount", disposeParams(blo), pageNo, pageSize);
  972. }
  973. private Map<String,Object> disposeParams(BusinessListBo blo){
  974. Map<String, Object> params = new HashMap<String, Object>();
  975. if(StringUtils.isNotBlank(blo.getUid())) params.put("uid", blo.getUid());
  976. if(StringUtils.isNotBlank(blo.getAid())) params.put("aid", blo.getAid());
  977. if(StringUtils.isNotBlank(blo.getAdminName())) params.put("adminName", blo.getAdminName());
  978. if(StringUtils.isNotBlank(blo.getStartDate())) params.put("startDate", blo.getStartDate()+" 00:00:00");
  979. if(StringUtils.isNotBlank(blo.getEndDate())) params.put("endDate", blo.getEndDate()+ " 23:59:59");
  980. if(StringUtils.isNotBlank(blo.getIdentifyName())) params.put("identifyName", blo.getIdentifyName());
  981. if(blo.getFollowSituation() != null) params.put("followSituation", blo.getFollowSituation());
  982. if(blo.getCustomerStatus() != null) params.put("customerStatus", blo.getCustomerStatus());
  983. return params;
  984. }
  985. @Override
  986. public List<BusinessListBo> findBusinessGlossory() {
  987. return userBusinessMapper.selectBusinessGlossory();
  988. }
  989. @Override
  990. public int judgeBusiness(String uid, String businessProjectId) {
  991. return userMapper.selectLockedProject(uid, null,businessProjectId, 1, UserLockReleaseStatus.LOCKED.getCode()).size();
  992. }
  993. @Override
  994. @Transactional
  995. public void addBusinessAndFollow(BussinessFollowBo bfb) throws ParseException {
  996. UserBusiness ub = new UserBusiness();
  997. String ubId = UUID.randomUUID().toString();
  998. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  999. ub.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1000. ub.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1001. ub.setId(ubId);
  1002. ub.setUid(bfb.getUid());
  1003. ub.setAid(TokenManager.getAdminId());
  1004. ub.setRemarks(bfb.getRemarks());
  1005. ub.setBusinessProjectId(bfb.getBusinessProjectId());
  1006. ub.setUpdateTime(format.parse(bfb.getCreateTime()));
  1007. ub.setCreateTime(format.parse(bfb.getCreateTime()));
  1008. userBusinessMapper.insert(ub);
  1009. if (StringUtils.isNotBlank(bfb.getOcbId())) { // 跟进联系人不为空则添加跟进记录
  1010. UserFollow uf = new UserFollow();
  1011. String ufId = UUID.randomUUID().toString();
  1012. uf.setId(ufId);
  1013. uf.setUid(bfb.getUid());
  1014. uf.setCreateTime(format.parse(bfb.getFollowTime()));
  1015. uf.setOcbId(bfb.getOcbId());
  1016. uf.setResult(bfb.getResult());
  1017. uf.setContactType(Integer.parseInt(bfb.getContactType()));
  1018. uf.setAid(TokenManager.getAdminId());
  1019. uf.setEffective(0);
  1020. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  1021. uf.setFollowCount(followCount);
  1022. userFollowMapper.insert(uf);
  1023. UserFollowBusiness ufb = new UserFollowBusiness();
  1024. ufb.setId(UUID.randomUUID().toString());
  1025. ufb.setBusinessId(ubId);
  1026. ufb.setFollowId(ufId);
  1027. ufb.setCustomerStatus(ub.getCustomerStatus());
  1028. ufb.setFollowSituation(ub.getFollowSituation());
  1029. ufb.setBusinessProjectId(bfb.getBusinessProjectId());
  1030. userFollowBusinessMapper.insert(ufb);
  1031. }
  1032. }
  1033. @Override
  1034. public List<BusinessListBo> findBusinessByUAid(String uid, String aid) {
  1035. return userBusinessMapper.selectBusinessByUAid(uid,aid);
  1036. }
  1037. @Override
  1038. public List<BusinessListBo> findLockedBusinessByUAid(String uid, String aid) {
  1039. return userBusinessMapper.selectLockedBusinessByUAid(uid,aid);
  1040. }
  1041. @Override
  1042. public BussinessFollowBo findBusinessDetail(String businessId) {
  1043. return userBusinessMapper.findBusinessDetail(businessId);
  1044. }
  1045. @Override
  1046. public int updateBusiness(BussinessFollowBo bfb) {
  1047. UserBusiness userBusiness = new UserBusiness();
  1048. userBusiness.setId(bfb.getBusinessId());
  1049. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1050. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1051. userBusiness.setRemarks(bfb.getRemarks());
  1052. userBusiness.setUpdateTime(new Date());
  1053. return userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  1054. }
  1055. @Override
  1056. @Transactional
  1057. public int addFollowOneBusiness(BussinessFollowBo bfb) throws ParseException {
  1058. Date updateTime = new Date();
  1059. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  1060. UserBusiness userBusiness = new UserBusiness();
  1061. userBusiness.setId(bfb.getBusinessId());
  1062. userBusiness.setUpdateTime(updateTime);
  1063. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1064. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1065. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  1066. UserFollow userFollow = new UserFollow();
  1067. String followId = UUID.randomUUID().toString();
  1068. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  1069. userFollow.setId(followId);
  1070. userFollow.setResult(bfb.getResult());
  1071. userFollow.setCreateTime(format.parse(bfb.getFollowTime()));
  1072. userFollow.setEffective(0);
  1073. userFollow.setOcbId(bfb.getOcbId());
  1074. userFollow.setFollowCount(followCount);
  1075. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  1076. userFollow.setAid(TokenManager.getAdminId());
  1077. userFollow.setUid(bfb.getUid());
  1078. userFollowMapper.insert(userFollow);
  1079. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  1080. String ufbId = UUID.randomUUID().toString();
  1081. userFollowBusiness.setId(ufbId);
  1082. userFollowBusiness.setFollowId(followId);
  1083. userFollowBusiness.setBusinessProjectId(bfb.getBusinessProjectId());
  1084. userFollowBusiness.setBusinessId(bfb.getBusinessId());
  1085. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1086. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1087. userFollowBusiness.setRemarks(bfb.getRemarks());
  1088. userFollowBusinessMapper.insert(userFollowBusiness);
  1089. return 1;
  1090. }
  1091. @Override
  1092. public BussinessFollowBo findFollowOneBusiness(String ufbId) {
  1093. return userBusinessMapper.findFollowOneBusiness(ufbId);
  1094. }
  1095. @Override
  1096. public int updateFollowOneBusiness(BussinessFollowBo bfb) {
  1097. //修改业务跟进中间表
  1098. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  1099. userFollowBusiness.setId(bfb.getUfbId());
  1100. userFollowBusiness.setRemarks(bfb.getRemarks());
  1101. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1102. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1103. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness);
  1104. //修改跟进记录表
  1105. UserFollow userFollow = new UserFollow();
  1106. userFollow.setId(bfb.getFollowId());
  1107. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  1108. userFollow.setResult(bfb.getResult());
  1109. if(StringUtils.isNotBlank(bfb.getOcbId())) userFollow.setOcbId(bfb.getOcbId());
  1110. userFollowMapper.updateByPrimaryKeySelective(userFollow);
  1111. return 1;
  1112. }
  1113. @Override
  1114. public int addOneContact(OrganizationContactBook ocb) {
  1115. ocb.setAid(TokenManager.getAdminId());
  1116. ocb.setId(UUID.randomUUID().toString());
  1117. ocb.setMajor(AFTConstants.NO);
  1118. Admin ad=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  1119. ocb.setAname(ad.getName());
  1120. return organizationContactBookMapper.insert(ocb);
  1121. }
  1122. @Override
  1123. public int deleteBusiness(String businessId) {
  1124. return userBusinessMapper.deleteByPrimaryKey(businessId);
  1125. }
  1126. @Override
  1127. public int updateBusinessToStop(String businessId) {
  1128. UserBusiness ub = new UserBusiness();
  1129. ub.setId(businessId);
  1130. ub.setCustomerStatus(CustomerStatusFiled.STATUS_STOP.getCode());
  1131. return userBusinessMapper.updateByPrimaryKeySelective(ub);
  1132. }
  1133. @Override
  1134. public int deleteFollowOneBusiness(String ufbId) {
  1135. UserFollowBusiness ufb=userFollowBusinessMapper.selectByPrimaryKey(ufbId);
  1136. if (ufb.getFollowSituation()==5) {//如果业务是已签合同则不允许删除
  1137. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));
  1138. }
  1139. return userFollowBusinessMapper.deleteByPrimaryKey(ufbId);
  1140. }
  1141. @Override
  1142. public int deleteOneContact(String ocbId) {
  1143. return organizationContactBookMapper.deleteByPrimaryKey(ocbId);
  1144. }
  1145. @Override
  1146. public List<Admin> findAdminName() {
  1147. String aid=TokenManager.getAdminId();
  1148. return userMapper.findAdminName(aid);
  1149. }
  1150. @Override
  1151. public int updatePersonalCustomerz(CustomerPersonalDetailBo bo) {
  1152. UserIdentity ui = new UserIdentity();
  1153. User user = new User();
  1154. try {
  1155. BeanUtilsExt.copyProperties(ui, bo);
  1156. user.setId(bo.getUid());
  1157. user.setSocietyTag(bo.getSocietyTag());
  1158. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  1159. user.setIntroduction(bo.getIntroduction());
  1160. user.setUpdateTime(new Date());
  1161. if(!StringUtils.isBlank(bo.getAid())){
  1162. user.setAid(bo.getAid());
  1163. user.setShareType(0);
  1164. }
  1165. } catch (InvocationTargetException | IllegalAccessException e) {
  1166. e.printStackTrace();
  1167. }
  1168. userMapper.updateByPrimaryKeySelective(user);
  1169. return 1;
  1170. }
  1171. @Override
  1172. public Pagination<CustomerListOut> findEnteringAudit(CustomerListOut clo, Integer pageNo, Integer pageSize) {
  1173. Map<String,Object> params = disposeParams(clo);
  1174. if(!StringUtils.isBlank(clo.getAdminName()))params.put("adminName", clo.getAdminName());
  1175. @SuppressWarnings("unchecked")
  1176. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditList","findEnteringAuditCount",params,pageNo,pageSize);
  1177. return list;
  1178. }
  1179. @Override
  1180. public Pagination<CustomerListOut> findEnteringAuditIsNo(CustomerListOut clo, Integer pageNo, Integer pageSize) {
  1181. clo.setAid(TokenManager.getAdminId());
  1182. Map<String,Object> params = disposeParams(clo);
  1183. if(!StringUtils.isBlank(clo.getAdminName()))params.put("adminName", clo.getAdminName());
  1184. @SuppressWarnings("unchecked")
  1185. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditIsNoList","findEnteringAuditIsNoCount",params,pageNo,pageSize);
  1186. return list;
  1187. }
  1188. @Override
  1189. public int updateEnteringAudit(User bo) {
  1190. String[] ary=bo.getId().split(",");
  1191. for (String s : ary) {
  1192. String id=s;
  1193. Integer auditStatus=bo.getAuditStatus();
  1194. String auditOpinion=bo.getAuditOpinion();
  1195. userMapper.updateEnteringAudit(id,auditStatus,auditOpinion);
  1196. }
  1197. return 1;
  1198. }
  1199. @Override
  1200. public int updateMainContact(String ocbId,String uid) {
  1201. organizationContactBookMapper.updateSubContact(uid);
  1202. OrganizationIdentity oi=new OrganizationIdentity();
  1203. OrganizationContactBook ocb= organizationContactBookMapper.selectByPrimaryKey(ocbId);
  1204. oi.setUid(uid);
  1205. oi.setContacts(ocb.getName());
  1206. oi.setContactMobile(ocb.getMobile());
  1207. organizationIdentityMapper.updateServiceByUid(oi);
  1208. organizationContactBookMapper.updateMainContact(ocbId);
  1209. return 1;
  1210. }
  1211. @Override
  1212. public int updateRefusedCustomer(String id,String nickname, String mobile, String societyTag) {
  1213. User u=userMapper.selectByPrimaryKey(id);
  1214. u.setNickname(nickname);
  1215. u.setMobile(mobile);
  1216. u.setSocietyTag(societyTag);
  1217. return userMapper.updateRefusedCustomer(id, nickname, mobile, societyTag);
  1218. }
  1219. private void setCustomerList(List<CustomerListOut> tmpList,int i){
  1220. Date now = new Date();
  1221. String s1,s2;
  1222. Long l1,l2;
  1223. int diff1=0,diff2=0;
  1224. for(CustomerListOut clo: tmpList){
  1225. try {
  1226. //如果最近跟进为空直接取转换时间
  1227. if (StringUtils.isNotBlank(clo.getLastFollowTime())){
  1228. //如果最近跟进小于转换取转换时间
  1229. if(DateUtils.parseDate(clo.getLastFollowTime(), AFTConstants.YYYYMMDDHHMMSS).getTime()>DateUtils.parseDate(clo.getTransferTime(), AFTConstants.YYYYMMDDHHMMSS).getTime()) {
  1230. s1=clo.getLastFollowTime();
  1231. }else {
  1232. s1=clo.getTransferTime();
  1233. }
  1234. }else {
  1235. s1=clo.getTransferTime();
  1236. }
  1237. //另外一个时间取转换时间
  1238. s2 = clo.getTransferTime();
  1239. l1 = DateUtils.parseDate(s1, AFTConstants.YYYYMMDDHHMMSS).getTime();
  1240. l2 = DateUtils.parseDate(s2, AFTConstants.YYYYMMDDHHMMSS).getTime();
  1241. if(i==0) {
  1242. diff1 = (int)((l1 + AFTConstants.USER_FOLLOW_LIMIT_MS - now.getTime())/(24*3600*1000));
  1243. diff2 = (int)((l2 + AFTConstants.USER_SIGN_LIMIT_MS - now.getTime())/(24*3600*1000));
  1244. }else if (i==1) {
  1245. diff1 = (int)((l1 + AFTConstants.PROJECT_FOLLOW_LIMIT_MS - now.getTime())/(24*3600*1000));
  1246. diff2 = (int)((l2 + AFTConstants.PROJECT_SIGN_LIMIT_MS - now.getTime())/(24*3600*1000));
  1247. }
  1248. clo.setSurplusFollowTime(diff1 + "");
  1249. clo.setSurplusSignTime(diff2 + "");
  1250. } catch (ParseException e) {
  1251. e.printStackTrace();
  1252. }
  1253. if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)||TokenManager.hasRole(AFTConstants.SALESMAN_ADMIN)) {
  1254. if(!clo.getAid().equals(TokenManager.getAdminId())) {
  1255. clo.setContacts("***");
  1256. clo.setContactMobile("***");
  1257. }
  1258. }
  1259. }
  1260. }
  1261. @SuppressWarnings("unchecked")
  1262. @Override
  1263. public Pagination<CustomerListOut> listSignOrganizationCustomer(CustomerListIn cli, Integer pageNo,
  1264. Integer pageSize) {
  1265. cli.setAid(TokenManager.getAdminId());
  1266. // cli.setAid("1");
  1267. Map<String,Object> params = disposeParams(cli);
  1268. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignOrganizationCustomerList","selectSignOrganizationCustomerCount",params,pageNo,pageSize);
  1269. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  1270. setCustomerList(tmpList,1);
  1271. list.setList(tmpList);
  1272. return list;
  1273. }
  1274. @SuppressWarnings("unchecked")
  1275. @Override
  1276. public Pagination<CustomerListOut> listSignPersonalCustomer(CustomerListIn cli, Integer pageNo,
  1277. Integer pageSize) {
  1278. cli.setAid(TokenManager.getAdminId());
  1279. Map<String,Object> params = disposeParams(cli);
  1280. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignPersonalCustomerList","selectSignPersonalCustomerCount",params,pageNo,pageSize);
  1281. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  1282. setCustomerList(tmpList,0);
  1283. list.setList(tmpList);
  1284. return list;
  1285. }
  1286. @Override
  1287. public List<LockingReleaseBo> selectLockedProject(String uid) {
  1288. return userMapper.selectLockedProject(uid,null,null,1,null);
  1289. }
  1290. @Override
  1291. public List<CustomerSimpleBo> getPrivateCustomerByName(String name) {
  1292. return userMapper.selectPrivateCustomerByName(name,TokenManager.getAdminId());
  1293. }
  1294. @Override
  1295. public List<CustomerSimpleBo> getSignedCustomerByName(String name) {
  1296. return userMapper.selectSignedCustomerByName(name,TokenManager.getAdminId());
  1297. }
  1298. private int updateUserLock(String uid,String aid,Integer oldStatus,Integer newStatus){
  1299. return userLockReleaseMapper.updateUserLock(uid,aid,oldStatus,newStatus);
  1300. }
  1301. private int addUserLock(String uid,String aid,Integer type,String pid,Date lockTime){
  1302. UserLockRelease ulr = new UserLockRelease();
  1303. ulr.setId(UUID.randomUUID().toString());
  1304. if (type==0) {
  1305. ulr.setType(0);
  1306. }else {
  1307. ulr.setType(1);
  1308. ulr.setBusinessProjectId(pid);
  1309. }
  1310. ulr.setAid(aid);
  1311. ulr.setLockTime(lockTime);
  1312. ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
  1313. ulr.setUid(uid);
  1314. return userLockReleaseMapper.insert(ulr);
  1315. }
  1316. /**
  1317. * 查询需要释放客户
  1318. * @param uid
  1319. * @return
  1320. */
  1321. @Override
  1322. public List<LockingReleaseBo> selectWaitReleaseCustomer(String uid){
  1323. return userLockReleaseMapper.selectWaitReleaseCustomer(uid);
  1324. }
  1325. /**
  1326. * 查询需要释放的业务
  1327. * @param uid
  1328. * @return
  1329. */
  1330. @Override
  1331. public List<LockingReleaseBo> selectWaitReleaseBusiness(String uid){
  1332. return userLockReleaseMapper.selectWaitReleaseBusiness(uid);
  1333. }
  1334. /**
  1335. * 处理需要释放
  1336. * @param list
  1337. */
  1338. @Override
  1339. public void updateReleaseLock(Date releaseTime){
  1340. SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1341. String time=formatter.format(releaseTime);
  1342. userMapper.updateReleaseLock(time);
  1343. userLockReleaseMapper.updateReleaseLock(time);
  1344. }
  1345. @Override
  1346. public int updateAgainProjectTask(String uid, String projectId,String aid) {
  1347. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, TokenManager.getAdminId(), projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
  1348. // List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, aid, projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
  1349. UserLockRelease u= new UserLockRelease();
  1350. if (businessLockedList.size()==1) {
  1351. for (LockingReleaseBo l : businessLockedList) {
  1352. u.setId(l.getId());
  1353. u.setLockTime(new Date());
  1354. }
  1355. return userLockReleaseMapper.updateByPrimaryKeySelective(u);
  1356. }
  1357. return 0;
  1358. }
  1359. @Override
  1360. public int updateInformationMaintainerr(String id, String aid) {
  1361. User u=new User();
  1362. u.setId(id);
  1363. u.setInformationMaintainer(aid);
  1364. return userMapper.updateByPrimaryKeySelective(u);
  1365. }
  1366. @SuppressWarnings("unchecked")
  1367. @Override
  1368. public Pagination<CustomerListIn> listCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1369. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1370. cli.setAid(TokenManager.getAdminId());
  1371. // cli.setAid("1");
  1372. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1373. Map<String,Object> params = disposeParams(cli);
  1374. return (Pagination<CustomerListIn>) findPage("selectCustomerInformationList","selectCustomerInformationCount",params,pageNo,pageSize);
  1375. }
  1376. @SuppressWarnings("unchecked")
  1377. @Override
  1378. public Pagination<CustomerListIn> listDepCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1379. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1380. cli.setAid(TokenManager.getAdminId());
  1381. // cli.setAid("1");
  1382. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1383. Map<String,Object> params = disposeParams(cli);
  1384. return (Pagination<CustomerListIn>) findPage("selectDepCustomerInformationList","selectDepCustomerInformationCount",params,pageNo,pageSize);
  1385. }
  1386. public boolean checkCustomerInformation(String uid) {
  1387. int i=userMapper.checkCustomerInformation(uid);
  1388. if (i<1) {
  1389. return true;
  1390. }
  1391. return false;
  1392. }
  1393. @Override
  1394. public void updatePendingReleaseLock(List<LockingReleaseBo> newList) {
  1395. String lockIds = "";
  1396. for(LockingReleaseBo bo:newList){
  1397. lockIds += bo.getId() + ",";
  1398. }
  1399. if(lockIds.length()>0) {
  1400. lockIds = "'" + lockIds.substring(0,lockIds.length()-1).replace(",", "','") + "'";
  1401. userLockReleaseMapper.updatePendingReleaseLock(lockIds);
  1402. }
  1403. }
  1404. @Override
  1405. public List<LockingReleaseBo> selectPendinglockUserList() {
  1406. return userLockReleaseMapper.selectPendinglockUserList();
  1407. }
  1408. @Override
  1409. public int updateUserLevel(User u) {
  1410. return userMapper.updateByPrimaryKeySelective(u);
  1411. }
  1412. @Override
  1413. public XSSFWorkbook privateUnitCustomerOutXls(CustomerListIn cli, Integer sort, Integer sortType, Integer pageNo,
  1414. Integer pageSize) {
  1415. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1416. cli.setAid(TokenManager.getAdminId());
  1417. // cli.setAid("1");
  1418. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1419. Map<String,Object> params = disposeParams(cli);
  1420. params.put("sort", sort);
  1421. params.put("sortType",sortType);
  1422. List<CustomerListOut> list= userMapper.privateUnitCustomerList(params);
  1423. setCustomerList(list,0);
  1424. if (list==null || list.size()==0) return null;
  1425. String[] comment = {"客户名称","地区","联系人","联系电话","社会性质","客户初始时间","剩余私有天数","最新跟进时间","客户等级"};
  1426. String filePath = uploadPath + "/privateUnitCustomer";
  1427. XSSFWorkbook wb = ExportExcelUtil.exportSelectPrivateOrganizationCustomer(list, comment, filePath);
  1428. return wb;
  1429. }
  1430. @Override
  1431. public int customerHandOver(String userIds, String receiveId) {
  1432. /* String [] str=userIds.split(",");
  1433. String aid=TokenManager.getAdminId();
  1434. List<String> uids=Arrays.asList(str);
  1435. userLockReleaseMapper.updateBatchReleaseProject(uids,receiveId,aid);
  1436. userLockReleaseMapper.updateBatchlockProject(uids,receiveId,aid);*/
  1437. return 0;
  1438. }
  1439. @Override
  1440. public int updatePrivateBusinessTransfer(String inputId, String uid, String pid) {
  1441. List<LockingReleaseBo> list=userLockReleaseMapper.checkUserProject(uid, pid,TokenManager.getAdminId());
  1442. if (list.isEmpty()) {
  1443. throw new BusinessException(new Error("客户归属错误","客户归属错误"));
  1444. }else if(list.size()>1) {
  1445. throw new BusinessException(new Error("业务数量错误","业务数量错误"));
  1446. }
  1447. LockingReleaseBo l=list.get(0);
  1448. UserLockRelease ul=new UserLockRelease();
  1449. ul.setId(l.getId());
  1450. // 不做释放与锁定的动作
  1451. // ul.setStatus(2);
  1452. ul.setAid(inputId);
  1453. // 不修改时间
  1454. // ul.setReleaseTime(now);
  1455. userLockReleaseMapper.updateByPrimaryKeySelective(ul);
  1456. addtransferLog(uid,pid,TokenManager.getAdminId(),inputId,1);
  1457. // addUserLock(uid,inputId,1,pid,now); //指定用户锁定客户
  1458. List<BusinessListBo> bl=userBusinessMapper.selectBusinessProjectByUAPid(uid, TokenManager.getAdminId(), pid);
  1459. if (bl.size()==1) {
  1460. UserBusiness ub=new UserBusiness();
  1461. ub.setId(bl.get(0).getBusinessId());
  1462. ub.setAid(inputId);
  1463. ub.setRemarks("转交客户业务触发");
  1464. userBusinessMapper.updateByPrimaryKeySelective(ub);
  1465. }
  1466. return 1;
  1467. }
  1468. private void addtransferLog(String uid, String pid, String aid, String takeAid,Integer type) {
  1469. UserTransferLog utl=new UserTransferLog();
  1470. utl.setAid(aid);
  1471. utl.setCreateTime(new Date());
  1472. utl.setPid(pid);
  1473. utl.setTakeAid(takeAid);
  1474. utl.setType(type);
  1475. utl.setUid(uid);
  1476. userTransferLogMapper.insertSelective(utl);
  1477. }
  1478. @Override
  1479. public List<transferListBo> transferList(String uid) {
  1480. return userTransferLogMapper.selectByUidGetList(uid);
  1481. }
  1482. @Override
  1483. public int pushReleaseUser(String id) {
  1484. Date date =new Date();
  1485. User u=userMapper.selectByPrimaryKey(id);
  1486. System.out.println(u.getAid());
  1487. System.out.println(TokenManager.getAdminId());
  1488. if (!u.getAid().equals(TokenManager.getAdminId())) {
  1489. throw new BuilderException("客户归属错误!");
  1490. }
  1491. u.setTransferTime(date);
  1492. u.setShareType(1);
  1493. userMapper.updateByPrimaryKeySelective(u);
  1494. userLockReleaseMapper.updateUserTypeLock(u.getId(), TokenManager.getAdminId(), 0, 2,date);
  1495. return 1;
  1496. }
  1497. @Override
  1498. public List<userDaysBo> selectUserDays(String id) {
  1499. Integer x=30,y=270;
  1500. x=x-USER_REMIND_DAYS;
  1501. y=y-USER_REMIND_DAYS;
  1502. List<userDaysBo> list=userLockReleaseMapper.selectUserDays(id,x,y);
  1503. return list;
  1504. }
  1505. @Override
  1506. public int addGuidance(String followId, String guidance) {
  1507. UserFollow uf=new UserFollow();
  1508. uf.setId(followId);
  1509. uf.setGuidance(guidance);
  1510. return userFollowMapper.updateByPrimaryKeySelective(uf);
  1511. }
  1512. }