CustomerServiceImpl.java 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. package com.goafanti.customer.service.impl;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.math.BigDecimal;
  4. import java.text.ParseException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.HashSet;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.Set;
  12. import java.util.UUID;
  13. import javax.annotation.Resource;
  14. import org.apache.commons.beanutils.BeanUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import com.goafanti.common.bo.Error;
  19. import com.goafanti.common.constant.AFTConstants;
  20. import com.goafanti.common.constant.ErrorConstants;
  21. import com.goafanti.common.dao.BusinessGlossoryMapper;
  22. import com.goafanti.common.dao.BusinessProjectMapper;
  23. import com.goafanti.common.dao.OrganizationContactBookMapper;
  24. import com.goafanti.common.dao.OrganizationIdentityMapper;
  25. import com.goafanti.common.dao.UserBusinessMapper;
  26. import com.goafanti.common.dao.UserFollowBusinessMapper;
  27. import com.goafanti.common.dao.UserFollowMapper;
  28. import com.goafanti.common.dao.UserIdentityMapper;
  29. import com.goafanti.common.dao.UserLockReleaseMapper;
  30. import com.goafanti.common.dao.UserMapper;
  31. import com.goafanti.common.enums.CustomerStatusFiled;
  32. import com.goafanti.common.enums.DeleteStatus;
  33. import com.goafanti.common.enums.IdentityProcess;
  34. import com.goafanti.common.enums.UserLevel;
  35. import com.goafanti.common.enums.UserLockReleaseStatus;
  36. import com.goafanti.common.enums.UserType;
  37. import com.goafanti.common.error.BusinessException;
  38. import com.goafanti.common.model.Admin;
  39. import com.goafanti.common.model.OrganizationContactBook;
  40. import com.goafanti.common.model.OrganizationIdentity;
  41. import com.goafanti.common.model.User;
  42. import com.goafanti.common.model.UserBusiness;
  43. import com.goafanti.common.model.UserFollow;
  44. import com.goafanti.common.model.UserFollowBusiness;
  45. import com.goafanti.common.model.UserIdentity;
  46. import com.goafanti.common.model.UserLockRelease;
  47. import com.goafanti.common.utils.BeanUtilsExt;
  48. import com.goafanti.common.utils.DateUtils;
  49. import com.goafanti.common.utils.PasswordUtil;
  50. import com.goafanti.common.utils.StringUtils;
  51. import com.goafanti.core.mybatis.BaseMybatisDao;
  52. import com.goafanti.core.mybatis.page.Pagination;
  53. import com.goafanti.core.shiro.token.TokenManager;
  54. import com.goafanti.customer.bo.BusinessListBo;
  55. import com.goafanti.customer.bo.BussinessFollowBo;
  56. import com.goafanti.customer.bo.CustomerExcelBo;
  57. import com.goafanti.customer.bo.CustomerListIn;
  58. import com.goafanti.customer.bo.CustomerListOut;
  59. import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
  60. import com.goafanti.customer.bo.CustomerPersonalDetailBo;
  61. import com.goafanti.customer.bo.CustomerSimpleBo;
  62. import com.goafanti.customer.bo.FollowBusinessBo;
  63. import com.goafanti.customer.bo.FollowListBo;
  64. import com.goafanti.customer.bo.LockingReleaseBo;
  65. import com.goafanti.customer.bo.StatisticBo;
  66. import com.goafanti.customer.service.CustomerService;
  67. @Service
  68. public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements CustomerService {
  69. @Autowired
  70. private UserMapper userMapper;
  71. @Autowired
  72. private UserIdentityMapper userIdentityMapper;
  73. @Autowired
  74. private OrganizationIdentityMapper organizationIdentityMapper;
  75. @Autowired
  76. private OrganizationContactBookMapper organizationContactBookMapper;
  77. @Resource(name = "passwordUtil")
  78. private PasswordUtil passwordUtil;
  79. @Resource
  80. private UserFollowMapper userFollowMapper;
  81. @Resource
  82. private UserBusinessMapper userBusinessMapper;
  83. @Resource
  84. private UserFollowBusinessMapper userFollowBusinessMapper;
  85. @Resource
  86. private BusinessGlossoryMapper businessGlossoryMapper;
  87. @Resource
  88. private BusinessProjectMapper businessProjectMapper;
  89. @Resource
  90. private UserLockReleaseMapper userLockReleaseMapper;
  91. @SuppressWarnings("unchecked")
  92. @Override
  93. public Pagination<CustomerListOut> listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  94. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  95. cli.setAid(TokenManager.getAdminId());
  96. Map<String,Object> params = disposeParams(cli);
  97. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPrivatePersonalCustomerList","selectPrivatePersonalCustomerCount",params,pageNo,pageSize);
  98. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  99. setCustomerList(tmpList);
  100. list.setList(tmpList);
  101. return list;
  102. }
  103. @SuppressWarnings("unchecked")
  104. @Override
  105. public Pagination<CustomerListOut> listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  106. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  107. Map<String,Object> params = disposeParams(cli);
  108. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPublicPersonalCustomerList","selectPublicPersonalCustomerCount",params,pageNo,pageSize);
  109. return list;
  110. }
  111. @SuppressWarnings("unchecked")
  112. @Override
  113. public Pagination<CustomerListOut> listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  114. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  115. Map<String,Object> params = disposeParams(cli);
  116. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
  117. return list;
  118. }
  119. @SuppressWarnings("unchecked")
  120. @Override
  121. public Pagination<CustomerListOut> listAllManagePersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  122. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  123. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  124. Map<String,Object> params = disposeParams(cli);
  125. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManagePersonalCustomerList","selectManagePersonalCustomerCount",params,pageNo,pageSize);
  126. return list;
  127. }
  128. @SuppressWarnings("unchecked")
  129. @Override
  130. public Pagination<CustomerListOut> listPrivateOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  131. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  132. cli.setAid(TokenManager.getAdminId());
  133. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  134. Map<String,Object> params = disposeParams(cli);
  135. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPrivateOrganizationCustomerList","selectPrivateOrganizationCustomerCount",params,pageNo,pageSize);
  136. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  137. setCustomerList(tmpList);
  138. list.setList(tmpList);
  139. return list;
  140. }
  141. @SuppressWarnings("unchecked")
  142. @Override
  143. public Pagination<CustomerListOut> listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  144. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  145. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC));
  146. Map<String,Object> params = disposeParams(cli);
  147. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPublicOrganizationCustomerList","selectPublicOrganizationCustomerCount",params,pageNo,pageSize);
  148. return list;
  149. }
  150. @SuppressWarnings("unchecked")
  151. @Override
  152. public Pagination<CustomerListOut> listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  153. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  154. Map<String,Object> params = disposeParams(cli);
  155. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  156. return list;
  157. }
  158. @Override
  159. public Pagination<CustomerListOut> listAllManageOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  160. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  161. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  162. cli.setAid(TokenManager.getAdminId());
  163. Map<String,Object> params = disposeParams(cli);
  164. @SuppressWarnings("unchecked")
  165. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManageOrganizationCustomerList","selectManageOrganizationCustomerCount",params,pageNo,pageSize);
  166. return list;
  167. }
  168. private Map<String,Object> disposeParams(CustomerListIn cli){
  169. Map<String,Object> params = new HashMap<String, Object>();
  170. if(StringUtils.isNotBlank(cli.getType())) params.put("type", Integer.parseInt(cli.getType()));
  171. if(StringUtils.isNotBlank(cli.getShareType())) params.put("shareType", Integer.parseInt(cli.getShareType()));
  172. if(StringUtils.isNotBlank(cli.getName())) params.put("name", cli.getName());
  173. if(StringUtils.isNotBlank(cli.getProvince())) params.put("province", Integer.parseInt(cli.getProvince()));
  174. if(StringUtils.isNotBlank(cli.getCity())) params.put("city", Integer.parseInt(cli.getCity()));
  175. if(StringUtils.isNotBlank(cli.getArea())) params.put("area", Integer.parseInt(cli.getArea()));
  176. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate());
  177. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate());
  178. if(StringUtils.isNotBlank(cli.getIndustry())) params.put("industry", Integer.parseInt(cli.getIndustry()));
  179. if(StringUtils.isNotBlank(cli.getAid())) params.put("aid", cli.getAid());
  180. if(StringUtils.isNotBlank(cli.getStatus())) params.put("status", Integer.parseInt(cli.getStatus()));
  181. if(StringUtils.isNotBlank(cli.getSocietyTag())) params.put("societyTag", cli.getSocietyTag());
  182. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate()+" 00:00:00");
  183. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate()+" 23:59:59");
  184. return params;
  185. }
  186. @Override
  187. public List<CustomerSimpleBo> findCustomerByName(String name) {
  188. return userMapper.findCustomerByName(name);
  189. }
  190. @Override
  191. public int judgeCustomerByName(String name) {
  192. return userMapper.judgeCustomerByName(name);
  193. }
  194. @Override
  195. @Transactional
  196. public int addCustomer(String name, String contacts, String contactMobile, Integer type, Integer source,String societyTag) throws BusinessException{
  197. User user = new User();
  198. Date now = new Date();
  199. String uid = UUID.randomUUID().toString();
  200. String identifyId = UUID.randomUUID().toString();
  201. user.setId(uid);
  202. user.setIdentifyName(name);
  203. user.setSource(source);
  204. user.setNickname(name);
  205. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  206. user.setShareType(AFTConstants.NO);
  207. user.setAid(TokenManager.getAdminId());
  208. user.setType(type);
  209. user.setLvl(UserLevel.CERTIFIED.getCode());
  210. user.setSocietyTag(societyTag);
  211. user.setCreateTime(now);
  212. user.setTransferTime(now);
  213. user.setUpdateTime(now);
  214. user.setMobile(contactMobile);
  215. user.setPassword(AFTConstants.INITIALPASSWORD);
  216. user.setInformationMaintainer(TokenManager.getAdminId());
  217. passwordUtil.encryptPassword(user);
  218. if(type == UserType.PERSONAL.getCode()){
  219. if(userMapper.checkUser("", "", contactMobile, type,null,null).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,""));
  220. UserIdentity ui = new UserIdentity();
  221. ui.setId(identifyId);
  222. ui.setUid(uid);
  223. ui.setContacts(contacts);
  224. ui.setContactMobile(contactMobile);
  225. ui.setUsername(name);
  226. ui.setExpert(AFTConstants.NO);
  227. ui.setCelebrity(AFTConstants.NO);
  228. ui.setInternational(AFTConstants.NO);
  229. ui.setAuditStatus(IdentityProcess.SUCCESS.getCode());//认证个人
  230. userIdentityMapper.insert(ui);
  231. }else if(type == UserType.ORGANIZATION.getCode()){
  232. if(userMapper.checkUser("",name,"",type,null,null).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,""));
  233. // 创建企业认证信息
  234. OrganizationIdentity oi = new OrganizationIdentity();
  235. oi.setUnitName(name);
  236. oi.setId(identifyId);
  237. oi.setUid(uid);
  238. oi.setContacts(contacts);
  239. oi.setContactMobile(contactMobile);
  240. oi.setHighTechZone(AFTConstants.NO);
  241. oi.setInternational(AFTConstants.NO);
  242. oi.setListed(AFTConstants.NO);
  243. oi.setAuditStatus(IdentityProcess.SUCCESS.getCode()); //实名企业
  244. organizationIdentityMapper.insert(oi);
  245. }
  246. userMapper.insert(user);
  247. //新增企业联系人
  248. OrganizationContactBook cob = new OrganizationContactBook();
  249. cob.setAid(TokenManager.getAdminId());
  250. cob.setId(UUID.randomUUID().toString());
  251. cob.setUid(uid);
  252. cob.setName(contacts);
  253. cob.setMobile(contactMobile);
  254. cob.setMajor(AFTConstants.NO);
  255. organizationContactBookMapper.insert(cob);
  256. //新增锁定数据
  257. addUserLock(uid, TokenManager.getAdminId(), now);
  258. return 1;
  259. }
  260. @Override
  261. public CustomerPersonalDetailBo findPersonalCustomerDetail(String uid) {
  262. return userMapper.findPersonalCustomerDetail(uid);
  263. }
  264. @Override
  265. public CustomerOrganizationDetailBo findOrganizationCustomerDetail(String uid) {
  266. return userMapper.findOrganizationCustomerDetail(uid);
  267. }
  268. @Override
  269. @Transactional
  270. public int updateOrganizationCustomer(CustomerOrganizationDetailBo bo) {
  271. OrganizationIdentity oi = new OrganizationIdentity();
  272. User user = new User();
  273. try {
  274. BeanUtilsExt.copyProperties(oi, bo);
  275. if(null==oi.getYearSalesAmount())oi.setYearSalesAmount(new BigDecimal(0));
  276. if(null==oi.getLastYearResearchAmount())oi.setLastYearResearchAmount(new BigDecimal(0));
  277. if(null==oi.getAssets())oi.setAssets(new BigDecimal(0));
  278. if(null==oi.getRegisteredCapital())oi.setRegisteredCapital(new BigDecimal(0));
  279. if(null==oi.getEnterpriseScale())oi.setEnterpriseScale(0);
  280. user.setId(bo.getUid());
  281. user.setSocietyTag(bo.getSocietyTag());
  282. user.setCompanyLogoUrl(bo.getCompanyLogoUrl());
  283. user.setIntroduction(bo.getIntroduction());
  284. user.setUpdateTime(new Date());
  285. user.setInformationMaintainer(bo.getInformationMaintainer());
  286. user.setCoreTechnology(bo.getCoreTechnology());
  287. user.setAccomplishSituation(bo.getAccomplishSituation());
  288. user.setIntellectualProperty(bo.getIntellectualProperty());
  289. } catch (IllegalAccessException |InvocationTargetException e) {
  290. e.printStackTrace();
  291. }
  292. organizationIdentityMapper.updateByPrimaryKeySelective(oi);
  293. userMapper.updateByPrimaryKeySelective(user);
  294. return 1;
  295. }
  296. @Override
  297. public int updatePersonalCustomer(CustomerPersonalDetailBo bo) {
  298. UserIdentity ui = new UserIdentity();
  299. User user = new User();
  300. try {
  301. BeanUtilsExt.copyProperties(ui, bo);
  302. user.setId(bo.getUid());
  303. user.setSocietyTag(bo.getSocietyTag());
  304. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  305. user.setIntroduction(bo.getIntroduction());
  306. user.setUpdateTime(new Date());
  307. if(null==bo.getExpertAudit()&&bo.getExpert()==1)ui.setExpertAudit(2);
  308. } catch (InvocationTargetException | IllegalAccessException e) {
  309. e.printStackTrace();
  310. }
  311. userIdentityMapper.updateByPrimaryKeySelective(ui);
  312. userMapper.updateByPrimaryKeySelective(user);
  313. return 1;
  314. }
  315. @SuppressWarnings("unchecked")
  316. @Override
  317. public Pagination<FollowListBo> listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessProjectId) {
  318. Map<String, Object> params = new HashMap<String, Object>();
  319. if(StringUtils.isNotBlank(uid))params.put("uid", uid);
  320. if(StringUtils.isNotBlank(businessProjectId)) params.put("businessProjectId", businessProjectId);
  321. Pagination<FollowListBo> page = (Pagination<FollowListBo>)findPage("selectFollowHistoryList","selectFollowHistoryCount",params, pageNo, pageSize);
  322. List<FollowListBo> list = (List<FollowListBo>)page.getList();
  323. for(FollowListBo bo : list){
  324. if(bo.getAid().equals(TokenManager.getAdminId())){
  325. bo.setReadOnly(AFTConstants.NO);
  326. }else{
  327. bo.setReadOnly(AFTConstants.YES);
  328. }
  329. }
  330. page.setList(list);
  331. return page;
  332. }
  333. @Override
  334. public User findUserAccountDetail(String uid) {
  335. return userMapper.findUserAccountDetail(uid);
  336. }
  337. @Override
  338. public int updateUserAccount(User user) {
  339. return userMapper.updateByPrimaryKeySelective(user);
  340. }
  341. @Override
  342. public List<OrganizationContactBook> findCustomerContacts(String uid) {
  343. return userMapper.findCustomerContacts(uid,TokenManager.getAdminId());
  344. }
  345. @Override
  346. @Transactional
  347. public int addFollow(FollowBusinessBo fbb) throws BusinessException{
  348. //if(fbb.getUserBusinessList().size()<1) throw new BusinessException(new Error(ErrorConstants.AT_LEAST_A_BUSINESS,"",""));
  349. //更新跟进记录表
  350. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  351. UserFollow userFollow = new UserFollow();
  352. String followId = UUID.randomUUID().toString();
  353. userFollow.setId(followId);
  354. userFollow.setAid(TokenManager.getAdminId());
  355. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  356. userFollow.setEffective(DeleteStatus.UNDELETE.getCode());
  357. try {
  358. userFollow.setCreateTime(format.parse(fbb.getFollowTime()));
  359. } catch (ParseException e) {
  360. e.printStackTrace();
  361. }
  362. userFollow.setOcbId(fbb.getOcbId());
  363. userFollow.setResult(fbb.getResult());
  364. userFollow.setUid(fbb.getUid());
  365. int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), TokenManager.getAdminId()) + 1;
  366. userFollow.setFollowCount(followCount);
  367. userFollowMapper.insert(userFollow);
  368. //检查客户锁定情况
  369. if(fbb.getUserBusinessList().size()>0){
  370. boolean isUserOwner = false;
  371. List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(), TokenManager.getAdminId(),null, 0, UserLockReleaseStatus.LOCKED.getCode());
  372. if(userLockedList.size() > 0){
  373. isUserOwner = true;
  374. }
  375. boolean isBusinessOwner = false;
  376. List<LockingReleaseBo> businessLockedList = null;
  377. String businessName= "";
  378. String ufbId = "";
  379. UserBusiness userBusiness = null;
  380. UserFollowBusiness userFollowBusiness = null;
  381. for(BusinessListBo ub: fbb.getUserBusinessList()){
  382. userBusiness = new UserBusiness();
  383. userFollowBusiness = new UserFollowBusiness();
  384. ufbId = UUID.randomUUID().toString();
  385. businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
  386. UserBusiness us=userBusinessMapper.selectByPrimaryKey(ub.getBusinessId());
  387. if(StringUtils.isNotBlank(ub.getBusinessId())){
  388. //更新业务表
  389. userBusiness.setId(ub.getBusinessId());
  390. if (us.getFollowSituation()==5) {//如果已签合同,则不允许变更
  391. if (ub.getCustomerStatus()!=us.getCustomerStatus()|| ub.getFollowSituation()!=5) {
  392. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));
  393. }
  394. }
  395. //检查业务锁定情况
  396. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  397. if(businessLockedList.size() > 0){
  398. for(LockingReleaseBo bo : businessLockedList){
  399. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  400. }
  401. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  402. }else{
  403. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  404. }
  405. //releaseProject(businessLockedList);
  406. if (us.getFollowSituation()!=5&&ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
  407. if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
  408. lockProject(ub);//锁定客户业务
  409. }
  410. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  411. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  412. userBusiness.setFollowSituation(ub.getFollowSituation());
  413. userBusiness.setRemarks(ub.getRemarks());
  414. userBusiness.setUid(fbb.getUid());
  415. try {
  416. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  417. } catch (ParseException e) {
  418. e.printStackTrace();
  419. }
  420. userBusiness.setAid(TokenManager.getAdminId());
  421. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  422. //更新业务中间表
  423. userFollowBusiness.setBusinessId(ub.getBusinessProjectId());
  424. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  425. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  426. userFollowBusiness.setId(ufbId);
  427. userFollowBusiness.setFollowId(followId);
  428. userFollowBusiness.setRemarks(ub.getRemarks());
  429. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  430. userFollowBusinessMapper.insert(userFollowBusiness);
  431. }else{
  432. //检查业务锁定情况
  433. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  434. if(businessLockedList.size() > 0){
  435. for(LockingReleaseBo bo : businessLockedList){
  436. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  437. }
  438. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  439. }else{
  440. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  441. }
  442. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "")>0){
  443. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  444. }
  445. if (ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
  446. if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
  447. lockProject(ub);//锁定客户业务
  448. }
  449. String ubId = UUID.randomUUID().toString();
  450. //更新业务表
  451. userBusiness.setId(ubId);
  452. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  453. try {
  454. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  455. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  456. } catch (ParseException e) {
  457. e.printStackTrace();
  458. }
  459. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  460. userBusiness.setFollowSituation(ub.getFollowSituation());
  461. userBusiness.setUid(fbb.getUid());
  462. userBusiness.setAid(TokenManager.getAdminId());
  463. userBusiness.setRemarks(ub.getRemarks());
  464. userBusinessMapper.insert(userBusiness);
  465. //更新业务中间表
  466. userFollowBusiness.setBusinessId(ubId);
  467. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  468. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  469. userFollowBusiness.setId(ufbId);
  470. userFollowBusiness.setFollowId(followId);
  471. userFollowBusiness.setRemarks(ub.getRemarks());
  472. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  473. userFollowBusinessMapper.insert(userFollowBusiness);
  474. }
  475. }
  476. }
  477. return 1;
  478. }
  479. private void lockProject(BusinessListBo ub) {
  480. UserLockRelease ulr= new UserLockRelease();
  481. ulr.setId(UUID.randomUUID().toString());
  482. ulr.setType(1);
  483. ulr.setAid(TokenManager.getAdminId());
  484. ulr.setBusinessProjectId(ub.getBusinessProjectId());
  485. SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
  486. try {
  487. if (null==ub.getCreateTime()) {
  488. ulr.setLockTime(new Date());
  489. }else {
  490. ulr.setLockTime(sdf.parse(ub.getCreateTime()));
  491. }
  492. } catch (ParseException e) {
  493. e.printStackTrace();
  494. }
  495. ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
  496. ulr.setUid(ub.getUid());
  497. userLockReleaseMapper.insert(ulr);
  498. }
  499. @SuppressWarnings("unused")
  500. private void releaseProject(List<LockingReleaseBo> businessLockedList) {
  501. if(businessLockedList != null && businessLockedList.size()>0){
  502. UserLockRelease ulr = null;
  503. for(LockingReleaseBo bo : businessLockedList){
  504. ulr = new UserLockRelease();
  505. ulr.setId(bo.getId());
  506. ulr.setStatus(UserLockReleaseStatus.RELEASE.getCode());
  507. userLockReleaseMapper.updateByPrimaryKeySelective(ulr);
  508. }
  509. }
  510. }
  511. @Override
  512. public FollowBusinessBo findFollowById(String followId) {
  513. return userMapper.findFollowById(followId);
  514. }
  515. @Override
  516. public List<BusinessListBo> findBusinessByFollowId(String followId) {
  517. return userMapper.findBusinessByFollowId(followId);
  518. }
  519. @Override
  520. @Transactional
  521. public int updateFollow(FollowBusinessBo fbb) throws BusinessException{
  522. UserFollow userFollow = new UserFollow();
  523. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  524. userFollow.setId(fbb.getFollowId());
  525. if(StringUtils.isNotBlank(fbb.getOcbId())) userFollow.setOcbId(fbb.getOcbId());
  526. userFollow.setResult(fbb.getResult());
  527. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  528. userFollowMapper.updateByPrimaryKeySelective(userFollow); //修改拜访记录表
  529. if(fbb.getUserBusinessList().size()>0){
  530. //检查客户锁定情况
  531. boolean isUserOwner = false;
  532. List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(), TokenManager.getAdminId(),null, 0, UserLockReleaseStatus.LOCKED.getCode());
  533. if(userLockedList.size() > 0){
  534. isUserOwner = true;
  535. }
  536. boolean isBusinessOwner = false;
  537. List<LockingReleaseBo> businessLockedList = null;
  538. String businessName= "";
  539. UserFollowBusiness userFollowBusiness = null;
  540. for(BusinessListBo ub: fbb.getUserBusinessList()){
  541. userFollowBusiness = new UserFollowBusiness();
  542. businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
  543. if(StringUtils.isNotBlank(ub.getUfbId())){
  544. userFollowBusiness.setId(ub.getUfbId());
  545. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  546. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  547. userFollowBusiness.setRemarks(ub.getRemarks());
  548. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); //修改拜访记录中间表
  549. }else{
  550. //检查业务锁定情况
  551. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null,ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  552. if(businessLockedList.size() > 0){
  553. for(LockingReleaseBo bo : businessLockedList){
  554. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  555. }
  556. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  557. }else{
  558. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  559. }
  560. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "")>0){
  561. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  562. }
  563. String ubId = UUID.randomUUID().toString();
  564. UserBusiness userBusiness = new UserBusiness();
  565. //更新业务表
  566. userBusiness.setId(ubId);
  567. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  568. try {
  569. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  570. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  571. } catch (ParseException e) {
  572. e.printStackTrace();
  573. }
  574. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  575. userBusiness.setFollowSituation(ub.getFollowSituation());
  576. userBusiness.setUid(fbb.getUid());
  577. userBusiness.setAid(TokenManager.getAdminId());
  578. userBusinessMapper.insert(userBusiness);
  579. //更新业务中间表
  580. String ufbId = UUID.randomUUID().toString();
  581. userFollowBusiness.setId(ufbId);
  582. userFollowBusiness.setFollowId(fbb.getFollowId());
  583. userFollowBusiness.setBusinessId(ubId);
  584. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  585. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  586. userFollowBusiness.setRemarks(ub.getRemarks());
  587. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  588. userFollowBusinessMapper.insert(userFollowBusiness);
  589. }
  590. }
  591. }
  592. return 1;
  593. }
  594. @Override
  595. public Set<OrganizationContactBook> findAllContacts(String uid) {
  596. Set<OrganizationContactBook> result = new HashSet<OrganizationContactBook>();
  597. result.addAll(userMapper.findAllContacts(uid));
  598. return result;
  599. }
  600. @Override
  601. public int updateCustomerContacts(List<OrganizationContactBook> ocbList,String uid) {
  602. if(ocbList.size()>0){
  603. OrganizationContactBook ocb = null;
  604. for(OrganizationContactBook item: ocbList){
  605. ocb = new OrganizationContactBook();
  606. try {
  607. BeanUtils.copyProperties(ocb, item);
  608. if(StringUtils.isBlank(ocb.getId())){
  609. ocb.setId(UUID.randomUUID().toString());
  610. ocb.setUid(uid);
  611. ocb.setAid(TokenManager.getAdminId());
  612. organizationContactBookMapper.insert(ocb);
  613. }else{
  614. organizationContactBookMapper.updateByPrimaryKeySelective(ocb);
  615. }
  616. } catch (IllegalAccessException | InvocationTargetException e) {
  617. e.printStackTrace();
  618. }
  619. }
  620. }
  621. return 1;
  622. }
  623. @Override
  624. public int deleteFollow(String followId) {
  625. UserFollow uf = new UserFollow();
  626. List<BusinessListBo> list= userMapper.findBusinessByFollowId(followId);
  627. for (BusinessListBo b : list) {
  628. if(b.getFollowSituation()==5)throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));;
  629. }
  630. uf.setId(followId);
  631. uf.setEffective(DeleteStatus.DELETED.getCode());
  632. return userFollowMapper.updateByPrimaryKeySelective(uf);
  633. }
  634. @Override
  635. public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows, Set<Integer> filterRows) {
  636. List<User> list = null;
  637. CustomerExcelBo[] bos = (CustomerExcelBo[])boSet.toArray(new CustomerExcelBo[] {});
  638. for (int i=0;i<bos.length;i++) {
  639. CustomerExcelBo bo = bos[i];
  640. CustomerExcelBo ceb = null;
  641. for(int j=0;j<i;j++){
  642. ceb = bos[j];
  643. if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){ //个人
  644. if(ceb.getMobile().equals(bo.getMobile()) && ceb.getCustomerType().equals(bo.getCustomerType())){
  645. bo.setUid(ceb.getUid());
  646. bo.setNewData(false);
  647. filterRows.add(bo.getRowNumber());
  648. break;
  649. }
  650. }else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){ //单位
  651. if(ceb.getIdentifyName().equals(bo.getIdentifyName()) && ceb.getCustomerType().equals(bo.getCustomerType())){
  652. bo.setUid(ceb.getUid());
  653. bo.setNewData(false);
  654. filterRows.add(bo.getRowNumber());
  655. break;
  656. }
  657. }
  658. }
  659. if(StringUtils.isBlank(bo.getUid())){ //是否已经存在
  660. if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){
  661. list = userMapper.checkUser("", "", bo.getMobile(), Integer.parseInt(bo.getCustomerType()),null,null);
  662. }else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  663. list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()),null,null);
  664. }
  665. if (list.size() > 0) {
  666. bo.setUid(list.get(0).getId());
  667. bo.setNewData(false);
  668. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  669. if(businessLockedList.size() > 0){
  670. existRows.add(bo.getRowNumber());
  671. }
  672. }else{
  673. bo.setUid(UUID.randomUUID().toString());
  674. bo.setNewData(true);
  675. }
  676. }else{
  677. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  678. if(businessLockedList.size() > 0){
  679. existRows.add(bo.getRowNumber());
  680. }
  681. }
  682. }
  683. }
  684. @Override
  685. @Transactional
  686. public int saveUploadData(Set<CustomerExcelBo> boSet) {
  687. Date now = new Date();
  688. String uid = "";
  689. for(CustomerExcelBo bo : boSet){
  690. uid = bo.getUid();
  691. if(bo.isNewData()){ //新建客户
  692. createUser(bo, uid, now);
  693. createIdentity(bo, bo.getCustomerType(), uid);
  694. createBusiness(bo, uid, now);
  695. createContacts(bo, uid);
  696. }else{ //新建业务
  697. createBusiness(bo, uid, now);
  698. if(organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId())<=0){
  699. createContacts(bo, uid);
  700. }
  701. }
  702. }
  703. return 1;
  704. }
  705. private void createUser(CustomerExcelBo bo,String uid,Date now){
  706. User user = new User();
  707. user.setId(uid);
  708. user.setIdentifyName(bo.getIdentifyName());
  709. user.setSource(AFTConstants.USER_SOURCE_CREATE);
  710. user.setNickname(bo.getIdentifyName());
  711. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  712. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  713. user.setAid(TokenManager.getAdminId());
  714. user.setType(Integer.parseInt(bo.getCustomerType()));
  715. user.setLvl(UserLevel.CERTIFIED.getCode());
  716. user.setCreateTime(now);
  717. user.setUpdateTime(now);
  718. user.setMobile(bo.getMobile());
  719. user.setPassword(AFTConstants.INITIALPASSWORD);
  720. passwordUtil.encryptPassword(user);
  721. userMapper.insert(user);
  722. }
  723. private void createIdentity(CustomerExcelBo bo,String type,String uid){
  724. String identifyId = UUID.randomUUID().toString();
  725. if(type.equals(AFTConstants.USER_TYPE_PERSONAL)){
  726. //新增个人认证信息
  727. UserIdentity ui = new UserIdentity();
  728. ui.setId(identifyId);
  729. ui.setUid(uid);
  730. ui.setContacts(bo.getContacts());
  731. ui.setContactMobile(bo.getMobile());
  732. ui.setUsername(bo.getIdentifyName());
  733. ui.setExpert(AFTConstants.NO);
  734. ui.setCelebrity(AFTConstants.NO);
  735. ui.setInternational(AFTConstants.NO);
  736. ui.setAuditStatus(5);
  737. userIdentityMapper.insert(ui);
  738. }else if(type.equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  739. // 创建企业认证信息
  740. OrganizationIdentity oi = new OrganizationIdentity();
  741. oi.setId(identifyId);
  742. oi.setUnitName(bo.getIdentifyName());
  743. oi.setUid(uid);
  744. oi.setContacts(bo.getContacts());
  745. oi.setContactMobile(bo.getMobile());
  746. oi.setHighTechZone(AFTConstants.NO);
  747. oi.setInternational(AFTConstants.NO);
  748. oi.setListed(AFTConstants.NO);
  749. oi.setAuditStatus(5); //实名企业
  750. organizationIdentityMapper.insert(oi);
  751. }
  752. }
  753. private void createContacts(CustomerExcelBo bo,String uid){
  754. //新增企业联系人
  755. OrganizationContactBook cob = new OrganizationContactBook();
  756. cob.setAid(TokenManager.getAdminId());
  757. cob.setId(UUID.randomUUID().toString());
  758. cob.setUid(uid);
  759. cob.setName(bo.getContacts());
  760. cob.setMobile(bo.getMobile());
  761. cob.setMajor(AFTConstants.NO);
  762. organizationContactBookMapper.insert(cob);
  763. }
  764. private void createBusiness(CustomerExcelBo bo,String uid,Date now){
  765. //新增业务
  766. UserBusiness ub = new UserBusiness();
  767. ub.setId(UUID.randomUUID().toString());
  768. ub.setAid(TokenManager.getAdminId());
  769. ub.setBusinessProjectId(bo.getBusinessProjectId());
  770. ub.setUid(uid);
  771. ub.setCreateTime(now);
  772. ub.setUpdateTime(now);
  773. ub.setCustomerStatus(Integer.parseInt(bo.getCustomerStatus()));
  774. ub.setFollowSituation(Integer.parseInt(bo.getFollowSituation()));
  775. userBusinessMapper.insert(ub);
  776. }
  777. @Override
  778. public int updateByOperatorType(String uid,String oldAid, String operatorType,Object... params) {
  779. User user = new User();
  780. Date now = new Date();
  781. user.setId(uid);
  782. int flag = 0;
  783. if(operatorType.equals(AFTConstants.USER_RECEIVE)){
  784. user.setAid(TokenManager.getAdminId());
  785. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  786. user.setInformationMaintainer(TokenManager.getAdminId());
  787. user.setTransferTime(now);
  788. flag = addUserLock(uid,TokenManager.getAdminId(),now); //指定用户锁定客户
  789. if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_RECEIVE,""));
  790. }else if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_OTHER)){
  791. user.setAid(String.valueOf(params[0]));
  792. user.setTransferTime(now);
  793. flag = updateUserLock(uid,oldAid,UserLockReleaseStatus.LOCKED.getCode(),UserLockReleaseStatus.RELEASE.getCode()); //原用户释放客户
  794. if(flag > 0 ) flag = addUserLock(uid,String.valueOf(params[0]),now); //指定用户锁定客户
  795. if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL,""));
  796. }
  797. return userMapper.updateByPrimaryKeySelective(user);
  798. }
  799. @SuppressWarnings("unchecked")
  800. @Override
  801. public Pagination<StatisticBo> customerStatistics(Date sDate, Date eDate, String depNo, String businessGlossoryId, Integer pageNo, Integer pageSize) {
  802. Map<String,Object> params = new HashMap<String,Object>();
  803. if(null != sDate) params.put("sDate", sDate);
  804. if(null != eDate) params.put("eDate", eDate);
  805. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  806. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  807. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("customerStatisticsList", "customerStatisticsCount", params, pageNo, pageSize);
  808. return page;
  809. }
  810. @SuppressWarnings("unchecked")
  811. @Override
  812. public Pagination<StatisticBo> businessStatistic(Date sDate, Date eDate,String depNo, String businessGlossoryId,Integer pageNo, Integer pageSize) {
  813. Map<String,Object> params = new HashMap<String,Object>();
  814. if(null != sDate) params.put("sDate", sDate);
  815. if(null != eDate) params.put("eDate", eDate);
  816. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  817. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  818. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("businessStatisticList", "businessStatisticCount", params, pageNo, pageSize);
  819. return page;
  820. }
  821. @SuppressWarnings("unchecked")
  822. @Override
  823. public Pagination<StatisticBo> followStatistic(Date sDate, Date eDate, String depNo, Integer pageNo, Integer pageSize) {
  824. Map<String,Object> params = new HashMap<String,Object>();
  825. if(null != sDate) params.put("sDate", sDate);
  826. if(null != eDate) params.put("eDate", eDate);
  827. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  828. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("followStatisticList", "followStatisticCount", params, pageNo, pageSize);
  829. return page;
  830. }
  831. @SuppressWarnings("unchecked")
  832. @Override
  833. public Pagination<BusinessListBo> listBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) {
  834. blo.setAid(TokenManager.getAdminId());
  835. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  836. }
  837. @SuppressWarnings("unchecked")
  838. @Override
  839. public Pagination<BusinessListBo> listAllBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
  840. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  841. }
  842. @SuppressWarnings("unchecked")
  843. @Override
  844. public Pagination<BusinessListBo> listManageBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) {
  845. blo.setAid(TokenManager.getAdminId());
  846. return (Pagination<BusinessListBo>) findPage("selectBusinessManageList", "selectBusinessManageCount", disposeParams(blo), pageNo, pageSize);
  847. }
  848. private Map<String,Object> disposeParams(BusinessListBo blo){
  849. Map<String, Object> params = new HashMap<String, Object>();
  850. if(StringUtils.isNotBlank(blo.getUid())) params.put("uid", blo.getUid());
  851. if(StringUtils.isNotBlank(blo.getAid())) params.put("aid", blo.getAid());
  852. if(StringUtils.isNotBlank(blo.getAdminName())) params.put("adminName", blo.getAdminName());
  853. if(StringUtils.isNotBlank(blo.getStartDate())) params.put("startDate", blo.getStartDate()+" 00:00:00");
  854. if(StringUtils.isNotBlank(blo.getEndDate())) params.put("endDate", blo.getEndDate()+ " 23:59:59");
  855. if(StringUtils.isNotBlank(blo.getIdentifyName())) params.put("identifyName", blo.getIdentifyName());
  856. if(blo.getFollowSituation() != null) params.put("followSituation", blo.getFollowSituation());
  857. if(blo.getCustomerStatus() != null) params.put("customerStatus", blo.getCustomerStatus());
  858. return params;
  859. }
  860. @Override
  861. public List<BusinessListBo> findBusinessGlossory() {
  862. return userBusinessMapper.selectBusinessGlossory();
  863. }
  864. @Override
  865. public int judgeBusiness(String uid, String businessProjectId) {
  866. return userMapper.selectLockedProject(uid, null,businessProjectId, 1, UserLockReleaseStatus.LOCKED.getCode()).size();
  867. }
  868. @Override
  869. @Transactional
  870. public void addBusinessAndFollow(BussinessFollowBo bfb) throws ParseException {
  871. UserBusiness ub = new UserBusiness();
  872. String ubId = UUID.randomUUID().toString();
  873. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  874. ub.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  875. ub.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  876. ub.setId(ubId);
  877. ub.setUid(bfb.getUid());
  878. ub.setAid(TokenManager.getAdminId());
  879. ub.setRemarks(bfb.getRemarks());
  880. ub.setBusinessProjectId(bfb.getBusinessProjectId());
  881. ub.setUpdateTime(format.parse(bfb.getCreateTime()));
  882. ub.setCreateTime(format.parse(bfb.getCreateTime()));
  883. userBusinessMapper.insert(ub);
  884. if (StringUtils.isNotBlank(bfb.getOcbId())) { // 跟进联系人不为空则添加跟进记录
  885. UserFollow uf = new UserFollow();
  886. String ufId = UUID.randomUUID().toString();
  887. uf.setId(ufId);
  888. uf.setUid(bfb.getUid());
  889. uf.setCreateTime(format.parse(bfb.getFollowTime()));
  890. uf.setOcbId(bfb.getOcbId());
  891. uf.setResult(bfb.getResult());
  892. uf.setContactType(Integer.parseInt(bfb.getContactType()));
  893. uf.setAid(TokenManager.getAdminId());
  894. uf.setEffective(0);
  895. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  896. uf.setFollowCount(followCount);
  897. userFollowMapper.insert(uf);
  898. UserFollowBusiness ufb = new UserFollowBusiness();
  899. ufb.setId(UUID.randomUUID().toString());
  900. ufb.setBusinessId(ubId);
  901. ufb.setFollowId(ufId);
  902. ufb.setCustomerStatus(ub.getCustomerStatus());
  903. ufb.setFollowSituation(ub.getFollowSituation());
  904. ufb.setBusinessProjectId(bfb.getBusinessProjectId());
  905. userFollowBusinessMapper.insert(ufb);
  906. }
  907. }
  908. @Override
  909. public List<BusinessListBo> findBusinessByUAid(String uid, String aid) {
  910. return userBusinessMapper.selectBusinessByUAid(uid,aid);
  911. }
  912. @Override
  913. public List<BusinessListBo> findLockedBusinessByUAid(String uid, String aid) {
  914. return userBusinessMapper.selectLockedBusinessByUAid(uid,aid);
  915. }
  916. @Override
  917. public BussinessFollowBo findBusinessDetail(String businessId) {
  918. return userBusinessMapper.findBusinessDetail(businessId);
  919. }
  920. @Override
  921. public int updateBusiness(BussinessFollowBo bfb) {
  922. UserBusiness userBusiness = new UserBusiness();
  923. userBusiness.setId(bfb.getBusinessId());
  924. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  925. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  926. userBusiness.setRemarks(bfb.getRemarks());
  927. userBusiness.setUpdateTime(new Date());
  928. return userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  929. }
  930. @Override
  931. @Transactional
  932. public int addFollowOneBusiness(BussinessFollowBo bfb) throws ParseException {
  933. Date updateTime = new Date();
  934. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  935. UserBusiness userBusiness = new UserBusiness();
  936. userBusiness.setId(bfb.getBusinessId());
  937. userBusiness.setUpdateTime(updateTime);
  938. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  939. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  940. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  941. UserFollow userFollow = new UserFollow();
  942. String followId = UUID.randomUUID().toString();
  943. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  944. userFollow.setId(followId);
  945. userFollow.setResult(bfb.getResult());
  946. userFollow.setCreateTime(format.parse(bfb.getFollowTime()));
  947. userFollow.setEffective(0);
  948. userFollow.setOcbId(bfb.getOcbId());
  949. userFollow.setFollowCount(followCount);
  950. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  951. userFollow.setAid(TokenManager.getAdminId());
  952. userFollow.setUid(bfb.getUid());
  953. userFollowMapper.insert(userFollow);
  954. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  955. String ufbId = UUID.randomUUID().toString();
  956. userFollowBusiness.setId(ufbId);
  957. userFollowBusiness.setFollowId(followId);
  958. userFollowBusiness.setBusinessProjectId(bfb.getBusinessProjectId());
  959. userFollowBusiness.setBusinessId(bfb.getBusinessId());
  960. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  961. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  962. userFollowBusiness.setRemarks(bfb.getRemarks());
  963. userFollowBusinessMapper.insert(userFollowBusiness);
  964. return 1;
  965. }
  966. @Override
  967. public BussinessFollowBo findFollowOneBusiness(String ufbId) {
  968. return userBusinessMapper.findFollowOneBusiness(ufbId);
  969. }
  970. @Override
  971. public int updateFollowOneBusiness(BussinessFollowBo bfb) {
  972. //修改业务跟进中间表
  973. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  974. userFollowBusiness.setId(bfb.getUfbId());
  975. userFollowBusiness.setRemarks(bfb.getRemarks());
  976. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  977. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  978. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness);
  979. //修改跟进记录表
  980. UserFollow userFollow = new UserFollow();
  981. userFollow.setId(bfb.getFollowId());
  982. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  983. userFollow.setResult(bfb.getResult());
  984. if(StringUtils.isNotBlank(bfb.getOcbId())) userFollow.setOcbId(bfb.getOcbId());
  985. userFollowMapper.updateByPrimaryKeySelective(userFollow);
  986. return 1;
  987. }
  988. @Override
  989. public int addOneContact(OrganizationContactBook ocb) {
  990. ocb.setAid(TokenManager.getAdminId());
  991. ocb.setId(UUID.randomUUID().toString());
  992. ocb.setMajor(AFTConstants.NO);
  993. return organizationContactBookMapper.insert(ocb);
  994. }
  995. @Override
  996. public int deleteBusiness(String businessId) {
  997. return userBusinessMapper.deleteByPrimaryKey(businessId);
  998. }
  999. @Override
  1000. public int updateBusinessToStop(String businessId) {
  1001. UserBusiness ub = new UserBusiness();
  1002. ub.setId(businessId);
  1003. ub.setCustomerStatus(CustomerStatusFiled.STATUS_STOP.getCode());
  1004. return userBusinessMapper.updateByPrimaryKeySelective(ub);
  1005. }
  1006. @Override
  1007. public int deleteFollowOneBusiness(String ufbId) {
  1008. UserFollowBusiness ufb=userFollowBusinessMapper.selectByPrimaryKey(ufbId);
  1009. if (ufb.getFollowSituation()==5) {//如果业务是已签合同则不允许删除
  1010. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));
  1011. }
  1012. return userFollowBusinessMapper.deleteByPrimaryKey(ufbId);
  1013. }
  1014. @Override
  1015. public int deleteOneContact(String ocbId) {
  1016. return organizationContactBookMapper.deleteByPrimaryKey(ocbId);
  1017. }
  1018. @Override
  1019. public List<Admin> findAdminName() {
  1020. String aid=TokenManager.getAdminId();
  1021. return userMapper.findAdminName(aid);
  1022. }
  1023. @Override
  1024. public int updatePersonalCustomerz(CustomerPersonalDetailBo bo) {
  1025. UserIdentity ui = new UserIdentity();
  1026. User user = new User();
  1027. try {
  1028. BeanUtilsExt.copyProperties(ui, bo);
  1029. user.setId(bo.getUid());
  1030. user.setSocietyTag(bo.getSocietyTag());
  1031. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  1032. user.setIntroduction(bo.getIntroduction());
  1033. user.setUpdateTime(new Date());
  1034. if(!StringUtils.isBlank(bo.getAid())){
  1035. user.setAid(bo.getAid());
  1036. user.setShareType(0);
  1037. }
  1038. } catch (InvocationTargetException | IllegalAccessException e) {
  1039. e.printStackTrace();
  1040. }
  1041. userMapper.updateByPrimaryKeySelective(user);
  1042. return 1;
  1043. }
  1044. @Override
  1045. public Pagination<CustomerListOut> findEnteringAudit(CustomerListOut clo, Integer pageNo, Integer pageSize) {
  1046. Map<String,Object> params = disposeParams(clo);
  1047. if(!StringUtils.isBlank(clo.getAdminName()))params.put("adminName", clo.getAdminName());
  1048. @SuppressWarnings("unchecked")
  1049. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditList","findEnteringAuditCount",params,pageNo,pageSize);
  1050. return list;
  1051. }
  1052. @Override
  1053. public Pagination<CustomerListOut> findEnteringAuditIsNo(CustomerListOut clo, Integer pageNo, Integer pageSize) {
  1054. clo.setAid(TokenManager.getAdminId());
  1055. Map<String,Object> params = disposeParams(clo);
  1056. if(!StringUtils.isBlank(clo.getAdminName()))params.put("adminName", clo.getAdminName());
  1057. @SuppressWarnings("unchecked")
  1058. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditIsNoList","findEnteringAuditIsNoCount",params,pageNo,pageSize);
  1059. return list;
  1060. }
  1061. @Override
  1062. public int updateEnteringAudit(User bo) {
  1063. String[] ary=bo.getId().split(",");
  1064. for (String s : ary) {
  1065. String id=s;
  1066. Integer auditStatus=bo.getAuditStatus();
  1067. String auditOpinion=bo.getAuditOpinion();
  1068. userMapper.updateEnteringAudit(id,auditStatus,auditOpinion);
  1069. }
  1070. return 1;
  1071. }
  1072. @Override
  1073. public int updateMainContact(String ocbId,String uid) {
  1074. organizationContactBookMapper.updateSubContact(uid);
  1075. organizationContactBookMapper.updateMainContact(ocbId);
  1076. return 1;
  1077. }
  1078. @Override
  1079. public int updateRefusedCustomer(String id,String nickname, String mobile, String societyTag) {
  1080. User u=userMapper.selectByPrimaryKey(id);
  1081. u.setNickname(nickname);
  1082. u.setMobile(mobile);
  1083. u.setSocietyTag(societyTag);
  1084. return userMapper.updateRefusedCustomer(id, nickname, mobile, societyTag);
  1085. }
  1086. private void setCustomerList(List<CustomerListOut> tmpList){
  1087. Date now = new Date();
  1088. String s1,s2;
  1089. Long l1,l2;
  1090. int diff1,diff2;
  1091. for(CustomerListOut clo: tmpList){
  1092. s1 = StringUtils.isBlank(clo.getLastFollowTime()) ? clo.getTransferTime() : clo.getLastFollowTime();
  1093. s2 = StringUtils.isBlank(clo.getLastSignTime()) ? clo.getTransferTime() : clo.getLastSignTime();
  1094. try {
  1095. l1 = DateUtils.parseDate(s1, AFTConstants.YYYYMMDDHHMMSS).getTime();
  1096. l2 = DateUtils.parseDate(s2, AFTConstants.YYYYMMDDHHMMSS).getTime();
  1097. diff1 = (int)((l1 + AFTConstants.USER_FOLLOW_LIMIT_MS - now.getTime())/(24*3600*1000));
  1098. diff2 = (int)((l2 + AFTConstants.USER_SIGN_LIMIT_MS - now.getTime())/(24*3600*1000));
  1099. clo.setSurplusFollowTime(diff1 + "");
  1100. clo.setSurplusSignTime(diff2 + "");
  1101. } catch (ParseException e) {
  1102. e.printStackTrace();
  1103. }
  1104. }
  1105. }
  1106. @SuppressWarnings("unchecked")
  1107. @Override
  1108. public Pagination<CustomerListOut> listSignOrganizationCustomer(CustomerListIn cli, Integer pageNo,
  1109. Integer pageSize) {
  1110. cli.setAid(TokenManager.getAdminId());
  1111. Map<String,Object> params = disposeParams(cli);
  1112. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignOrganizationCustomerList","selectSignOrganizationCustomerCount",params,pageNo,pageSize);
  1113. return list;
  1114. }
  1115. @SuppressWarnings("unchecked")
  1116. @Override
  1117. public Pagination<CustomerListOut> listSignPersonalCustomer(CustomerListIn cli, Integer pageNo,
  1118. Integer pageSize) {
  1119. cli.setAid(TokenManager.getAdminId());
  1120. Map<String,Object> params = disposeParams(cli);
  1121. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignPersonalCustomerList","selectSignPersonalCustomerCount",params,pageNo,pageSize);
  1122. return list;
  1123. }
  1124. @Override
  1125. public List<LockingReleaseBo> selectLockedProject(String uid) {
  1126. return userMapper.selectLockedProject(uid,null,null,1,null);
  1127. }
  1128. @Override
  1129. public List<CustomerSimpleBo> getPrivateCustomerByName(String name) {
  1130. return userMapper.selectPrivateCustomerByName(name,TokenManager.getAdminId());
  1131. }
  1132. @Override
  1133. public List<CustomerSimpleBo> getSignedCustomerByName(String name) {
  1134. return userMapper.selectSignedCustomerByName(name,TokenManager.getAdminId());
  1135. }
  1136. private int updateUserLock(String uid,String aid,Integer oldStatus,Integer newStatus){
  1137. return userLockReleaseMapper.updateUserLock(uid,aid,oldStatus,newStatus);
  1138. }
  1139. private int addUserLock(String uid,String aid,Date lockTime){
  1140. UserLockRelease ulr = new UserLockRelease();
  1141. ulr.setId(UUID.randomUUID().toString());
  1142. ulr.setType(0);
  1143. ulr.setAid(aid);
  1144. ulr.setLockTime(lockTime);
  1145. ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
  1146. ulr.setUid(uid);
  1147. return userLockReleaseMapper.insert(ulr);
  1148. }
  1149. /**
  1150. * 查询需要释放客户
  1151. * @param uid
  1152. * @return
  1153. */
  1154. @Override
  1155. public List<LockingReleaseBo> selectWaitReleaseCustomer(String uid){
  1156. return userLockReleaseMapper.selectWaitReleaseCustomer(uid);
  1157. }
  1158. /**
  1159. * 查询需要释放的业务
  1160. * @param uid
  1161. * @return
  1162. */
  1163. @Override
  1164. public List<LockingReleaseBo> selectWaitReleaseBusiness(String uid){
  1165. return userLockReleaseMapper.selectWaitReleaseBusiness(uid);
  1166. }
  1167. /**
  1168. * 处理需要释放
  1169. * @param list
  1170. */
  1171. @Override
  1172. public void updateReleaseLock(List<LockingReleaseBo> list,Date releaseTime){
  1173. String lockIds = "";
  1174. for(LockingReleaseBo bo:list){
  1175. lockIds += bo.getId() + ",";
  1176. }
  1177. if(lockIds.length()>0) {
  1178. lockIds = "'" + lockIds.substring(0,lockIds.length()-1).replace(",", "','") + "'";
  1179. userLockReleaseMapper.updateReleaseLock(lockIds,releaseTime);
  1180. }
  1181. }
  1182. @Override
  1183. public int updateAgainProjectTask(String uid, String projectId,String aid) {
  1184. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, TokenManager.getAdminId(), projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
  1185. // List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, aid, projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
  1186. UserLockRelease u= new UserLockRelease();
  1187. if (businessLockedList.size()==1) {
  1188. for (LockingReleaseBo l : businessLockedList) {
  1189. u.setId(l.getId());
  1190. u.setLockTime(new Date());
  1191. }
  1192. return userLockReleaseMapper.updateByPrimaryKeySelective(u);
  1193. }
  1194. return 0;
  1195. }
  1196. @Override
  1197. public int updateInformationMaintainerr(String id, String aid) {
  1198. User u=new User();
  1199. u.setId(id);
  1200. u.setInformationMaintainer(aid);
  1201. return userMapper.updateByPrimaryKeySelective(u);
  1202. }
  1203. @SuppressWarnings("unchecked")
  1204. @Override
  1205. public Pagination<CustomerListIn> listCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1206. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1207. cli.setAid(TokenManager.getAdminId());
  1208. //cli.setAid("1");
  1209. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1210. Map<String,Object> params = disposeParams(cli);
  1211. return (Pagination<CustomerListIn>) findPage("selectCustomerInformationList","selectCustomerInformationCount",params,pageNo,pageSize);
  1212. }
  1213. @SuppressWarnings("unchecked")
  1214. @Override
  1215. public Pagination<CustomerListIn> listDepCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1216. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1217. cli.setAid(TokenManager.getAdminId());
  1218. // cli.setAid("1");
  1219. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1220. Map<String,Object> params = disposeParams(cli);
  1221. return (Pagination<CustomerListIn>) findPage("selectDepCustomerInformationList","selectDepCustomerInformationCount",params,pageNo,pageSize);
  1222. }
  1223. }