CustomerServiceImpl.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import com.goafanti.common.bo.Error;
  18. import com.goafanti.common.constant.AFTConstants;
  19. import com.goafanti.common.constant.ErrorConstants;
  20. import com.goafanti.common.dao.BusinessGlossoryMapper;
  21. import com.goafanti.common.dao.OrganizationContactBookMapper;
  22. import com.goafanti.common.dao.OrganizationIdentityMapper;
  23. import com.goafanti.common.dao.UserBusinessMapper;
  24. import com.goafanti.common.dao.UserFollowBusinessMapper;
  25. import com.goafanti.common.dao.UserFollowMapper;
  26. import com.goafanti.common.dao.UserIdentityMapper;
  27. import com.goafanti.common.dao.UserMapper;
  28. import com.goafanti.common.error.BusinessException;
  29. import com.goafanti.common.model.OrganizationContactBook;
  30. import com.goafanti.common.model.OrganizationIdentity;
  31. import com.goafanti.common.model.User;
  32. import com.goafanti.common.model.UserBusiness;
  33. import com.goafanti.common.model.UserFollow;
  34. import com.goafanti.common.model.UserFollowBusiness;
  35. import com.goafanti.common.model.UserIdentity;
  36. import com.goafanti.common.utils.BeanUtilsExt;
  37. import com.goafanti.common.utils.PasswordUtil;
  38. import com.goafanti.common.utils.StringUtils;
  39. import com.goafanti.core.mybatis.BaseMybatisDao;
  40. import com.goafanti.core.mybatis.page.Pagination;
  41. import com.goafanti.core.shiro.token.TokenManager;
  42. import com.goafanti.customer.bo.CustomerExcelBo;
  43. import com.goafanti.customer.bo.CustomerListIn;
  44. import com.goafanti.customer.bo.CustomerListOut;
  45. import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
  46. import com.goafanti.customer.bo.CustomerPersonalDetailBo;
  47. import com.goafanti.customer.bo.CustomerSimpleBo;
  48. import com.goafanti.customer.bo.FollowBusinessBo;
  49. import com.goafanti.customer.bo.FollowListBo;
  50. import com.goafanti.customer.service.CustomerService;
  51. @Service
  52. public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements CustomerService {
  53. @Autowired
  54. private UserMapper userMapper;
  55. @Autowired
  56. private UserIdentityMapper userIdentityMapper;
  57. @Autowired
  58. private OrganizationIdentityMapper organizationIdentityMapper;
  59. @Autowired
  60. private OrganizationContactBookMapper organizationContactBookMapper;
  61. @Resource(name = "passwordUtil")
  62. private PasswordUtil passwordUtil;
  63. @Resource
  64. private UserFollowMapper userFollowMapper;
  65. @Resource
  66. private UserBusinessMapper userBusinessMapper;
  67. @Resource
  68. private UserFollowBusinessMapper userFollowBusinessMapper;
  69. @Resource
  70. private BusinessGlossoryMapper businessGlossoryMapper;
  71. @Override
  72. public Pagination<CustomerListOut> listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  73. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  74. cli.setAid(TokenManager.getAdminId());
  75. cli.setShareType(String.valueOf(AFTConstants.SHARE_TYPE_PRIVATE));
  76. Map<String,Object> params = disposeParams(cli);
  77. @SuppressWarnings("unchecked")
  78. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
  79. return list;
  80. }
  81. @Override
  82. public Pagination<CustomerListOut> listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  83. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  84. cli.setAid(TokenManager.getAdminId());
  85. cli.setShareType(String.valueOf(AFTConstants.SHARE_TYPE_PUBLIC));
  86. Map<String,Object> params = disposeParams(cli);
  87. @SuppressWarnings("unchecked")
  88. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
  89. return list;
  90. }
  91. @Override
  92. public Pagination<CustomerListOut> listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  93. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  94. Map<String,Object> params = disposeParams(cli);
  95. @SuppressWarnings("unchecked")
  96. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
  97. return list;
  98. }
  99. @Override
  100. public Pagination<CustomerListOut> listPrivateOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  101. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  102. cli.setAid(TokenManager.getAdminId());
  103. cli.setShareType(String.valueOf(AFTConstants.SHARE_TYPE_PRIVATE));
  104. Map<String,Object> params = disposeParams(cli);
  105. @SuppressWarnings("unchecked")
  106. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  107. return list;
  108. }
  109. @Override
  110. public Pagination<CustomerListOut> listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  111. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  112. cli.setAid(TokenManager.getAdminId());
  113. cli.setShareType(String.valueOf(AFTConstants.SHARE_TYPE_PUBLIC));
  114. Map<String,Object> params = disposeParams(cli);
  115. @SuppressWarnings("unchecked")
  116. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  117. return list;
  118. }
  119. @Override
  120. public Pagination<CustomerListOut> listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  121. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  122. Map<String,Object> params = disposeParams(cli);
  123. @SuppressWarnings("unchecked")
  124. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  125. return list;
  126. }
  127. private Map<String,Object> disposeParams(CustomerListIn cli){
  128. Map<String,Object> params = new HashMap<String, Object>();
  129. if(StringUtils.isNotBlank(cli.getType())) params.put("type", Integer.parseInt(cli.getType()));
  130. if(StringUtils.isNotBlank(cli.getShareType())) params.put("shareType", Integer.parseInt(cli.getShareType()));
  131. if(StringUtils.isNotBlank(cli.getName())) params.put("name", cli.getName());
  132. if(StringUtils.isNotBlank(cli.getProvince())) params.put("province", Integer.parseInt(cli.getProvince()));
  133. if(StringUtils.isNotBlank(cli.getCity())) params.put("city", Integer.parseInt(cli.getCity()));
  134. if(StringUtils.isNotBlank(cli.getArea())) params.put("area", Integer.parseInt(cli.getArea()));
  135. if(StringUtils.isNotBlank(cli.getContacts())) params.put("contacts", cli.getContacts());
  136. if(StringUtils.isNotBlank(cli.getContactMobile())) params.put("contactMobile", cli.getContactMobile());
  137. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate());
  138. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate());
  139. if(StringUtils.isNotBlank(cli.getExpert())) params.put("expert", Integer.parseInt(cli.getExpert()));
  140. if(StringUtils.isNotBlank(cli.getIndustry())) params.put("industry", Integer.parseInt(cli.getIndustry()));
  141. if(StringUtils.isNotBlank(cli.getInternational())) params.put("international", Integer.parseInt(cli.getInternational()));
  142. if(StringUtils.isNotBlank(cli.getServiceCertification())) params.put("serviceCertification", Integer.parseInt(cli.getServiceCertification()));
  143. if(StringUtils.isNotBlank(cli.getUserCertification())) params.put("userCertification", Integer.parseInt(cli.getUserCertification()));
  144. if(StringUtils.isNotBlank(cli.getCurrentMemberStatus())) params.put("currentMemberStatus", Integer.parseInt(cli.getCurrentMemberStatus()));
  145. if(StringUtils.isNotBlank(cli.getLvl())) params.put("lvl", Integer.parseInt(cli.getLvl()));
  146. if(StringUtils.isNotBlank(cli.getListed())) params.put("listed", Integer.parseInt(cli.getListed()));
  147. if(StringUtils.isNotBlank(cli.getHighTechZone())) params.put("highTechZone", Integer.parseInt(cli.getHighTechZone()));
  148. if(StringUtils.isNotBlank(cli.getExpert())) params.put("expert", Integer.parseInt(cli.getExpert()));
  149. if(StringUtils.isNotBlank(cli.getCelebrity())) params.put("celebrity", Integer.parseInt(cli.getCelebrity()));
  150. if(StringUtils.isNotBlank(cli.getAid())) params.put("aid", cli.getAid());
  151. if(StringUtils.isNotBlank(cli.getIsMember())) params.put("isMember", Integer.parseInt(cli.getIsMember()));
  152. if(StringUtils.isNotBlank(cli.getStatus())) params.put("status", Integer.parseInt(cli.getStatus()));
  153. if(StringUtils.isNotBlank(cli.getSocietyTag())) params.put("societyTag", cli.getSocietyTag());
  154. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate()+" 00:00:00");
  155. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate()+" 23:59:59");
  156. return params;
  157. }
  158. @Override
  159. public List<CustomerSimpleBo> findCustomerByName(String name) {
  160. return userMapper.findCustomerByName(name);
  161. }
  162. @Override
  163. public int judgeCustomerByName(String name) {
  164. return userMapper.judgeCustomerByName(name);
  165. }
  166. @Override
  167. @Transactional
  168. public int addCustomer(String name, String contacts, String contactMobile, Integer type,String societyTag) throws BusinessException{
  169. User user = new User();
  170. Date now = new Date();
  171. String uid = UUID.randomUUID().toString();
  172. String identifyId = UUID.randomUUID().toString();
  173. user.setId(uid);
  174. user.setIdentifyName(name);
  175. user.setSource(1);
  176. user.setNickname(name);
  177. user.setStatus(0);
  178. user.setShareType(0);
  179. user.setServiceCertification(0);
  180. user.setUserCertification(0);
  181. user.setAid(TokenManager.getAdminId());
  182. user.setType(type);
  183. user.setCurrentMemberStatus(0);
  184. user.setLvl(1);
  185. user.setSocietyTag(societyTag);
  186. user.setCreateTime(now);
  187. user.setUpdateTime(now);
  188. user.setMobile(contactMobile);
  189. user.setPassword(AFTConstants.INITIALPASSWORD);
  190. user.setIsMember(0);
  191. passwordUtil.encryptPassword(user);
  192. if(type == 0){
  193. if(userMapper.checkUser("", "", contactMobile, type).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,""));
  194. UserIdentity ui = new UserIdentity();
  195. ui.setId(identifyId);
  196. ui.setUid(uid);
  197. ui.setContacts(contacts);
  198. ui.setContactMobile(contactMobile);
  199. ui.setUsername(name);
  200. ui.setExpert(0);
  201. ui.setCelebrity(0);
  202. ui.setInternational(0);
  203. ui.setAuditStatus(0);
  204. userIdentityMapper.insert(ui);
  205. }else if(type == 1){
  206. if(userMapper.judgeCustomerByName(name)>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,""));
  207. // 创建企业认证信息
  208. OrganizationIdentity oi = new OrganizationIdentity();
  209. oi.setUnitName(name);
  210. oi.setId(identifyId);
  211. oi.setUid(uid);
  212. oi.setContacts(contacts);
  213. oi.setContactMobile(contactMobile);
  214. oi.setHighTechZone(0);
  215. oi.setInternational(0);
  216. oi.setListed(0);
  217. oi.setAuditStatus(5); //实名企业
  218. organizationIdentityMapper.insert(oi);
  219. }
  220. userMapper.insert(user);
  221. //新增企业联系人
  222. OrganizationContactBook cob = new OrganizationContactBook();
  223. cob.setAid(TokenManager.getAdminId());
  224. cob.setId(UUID.randomUUID().toString());
  225. cob.setUid(uid);
  226. cob.setName(contacts);
  227. cob.setMobile(contactMobile);
  228. organizationContactBookMapper.insert(cob);
  229. return 1;
  230. }
  231. @Override
  232. public CustomerPersonalDetailBo findPersonalCustomerDetail(String uid) {
  233. return userMapper.findPersonalCustomerDetail(uid);
  234. }
  235. @Override
  236. public CustomerOrganizationDetailBo findOrganizationCustomerDetail(String uid) {
  237. return userMapper.findOrganizationCustomerDetail(uid);
  238. }
  239. @Override
  240. @Transactional
  241. public int updateOrganizationCustomer(CustomerOrganizationDetailBo bo) {
  242. OrganizationIdentity oi = new OrganizationIdentity();
  243. User user = new User();
  244. try {
  245. BeanUtilsExt.copyProperties(oi, bo);
  246. user.setId(bo.getUid());
  247. user.setSocietyTag(bo.getSocietyTag());
  248. user.setCompanyLogoUrl(bo.getCompanyLogoUrl());
  249. user.setIntroduction(bo.getIntroduction());
  250. user.setUpdateTime(new Date());
  251. } catch (IllegalAccessException |InvocationTargetException e) {
  252. e.printStackTrace();
  253. }
  254. organizationIdentityMapper.updateByPrimaryKeySelective(oi);
  255. userMapper.updateByPrimaryKeySelective(user);
  256. return 1;
  257. }
  258. @Override
  259. public int updatePersonalCustomer(CustomerPersonalDetailBo bo) {
  260. UserIdentity ui = new UserIdentity();
  261. User user = new User();
  262. try {
  263. BeanUtilsExt.copyProperties(ui, bo);
  264. user.setId(bo.getUid());
  265. user.setSocietyTag(bo.getSocietyTag());
  266. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  267. user.setIntroduction(bo.getIntroduction());
  268. user.setUpdateTime(new Date());
  269. } catch (InvocationTargetException | IllegalAccessException e) {
  270. e.printStackTrace();
  271. }
  272. userIdentityMapper.updateByPrimaryKeySelective(ui);
  273. userMapper.updateByPrimaryKeySelective(user);
  274. return 1;
  275. }
  276. @SuppressWarnings("unchecked")
  277. @Override
  278. public Pagination<FollowListBo> listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessGlossoryId) {
  279. Map<String, Object> params = new HashMap<String, Object>();
  280. if(StringUtils.isNotBlank(uid))params.put("uid", uid);
  281. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  282. return (Pagination<FollowListBo>)findPage("selectFollowHistoryList","selectFollowHistoryCount",params, pageNo, pageSize);
  283. }
  284. @Override
  285. public User findUserAccountDetail(String uid) {
  286. return userMapper.findUserAccountDetail(uid);
  287. }
  288. @Override
  289. public int updateUserAccount(User user) {
  290. return userMapper.updateByPrimaryKeySelective(user);
  291. }
  292. @Override
  293. public List<OrganizationContactBook> findCustomerContacts(String uid) {
  294. return userMapper.findCustomerContacts(uid,TokenManager.getAdminId());
  295. }
  296. @Override
  297. @Transactional
  298. public int addFollow(FollowBusinessBo fbb) throws BusinessException{
  299. if(fbb.getUserBusinessList().size()<1) throw new BusinessException(new Error(ErrorConstants.AT_LEAST_A_BUSINESS,"",""));
  300. //更新跟进记录表
  301. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  302. UserFollow userFollow = new UserFollow();
  303. String followId = UUID.randomUUID().toString();
  304. userFollow.setId(followId);
  305. userFollow.setAid(TokenManager.getAdminId());
  306. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  307. userFollow.setEffective(0);
  308. try {
  309. userFollow.setCreateTime(format.parse(fbb.getFollowTime()));
  310. } catch (ParseException e) {
  311. e.printStackTrace();
  312. }
  313. userFollow.setOcbId(fbb.getOcbId());
  314. userFollow.setResult(fbb.getResult());
  315. userFollow.setUid(fbb.getUid());
  316. int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), TokenManager.getAdminId()) + 1;
  317. userFollow.setFollowCount(followCount);
  318. userFollowMapper.insert(userFollow);
  319. String ufbId = "";
  320. UserBusiness userBusiness = null;
  321. UserFollowBusiness userFollowBusiness = null;
  322. for(UserBusiness ub: fbb.getUserBusinessList()){
  323. userBusiness = new UserBusiness();
  324. userFollowBusiness = new UserFollowBusiness();
  325. ufbId = UUID.randomUUID().toString();
  326. if(StringUtils.isNotBlank(ub.getId())){
  327. //更新业务表
  328. userBusiness.setId(ub.getId());
  329. userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  330. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  331. userBusiness.setFollowSituation(ub.getFollowSituation());
  332. userBusiness.setUid(fbb.getUid());
  333. try {
  334. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  335. } catch (ParseException e) {
  336. e.printStackTrace();
  337. }
  338. userBusiness.setAid(TokenManager.getAdminId());
  339. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  340. //更新业务中间表
  341. userFollowBusiness.setBusinessId(ub.getId());
  342. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  343. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  344. userFollowBusiness.setId(ufbId);
  345. userFollowBusiness.setFollowId(followId);
  346. userFollowBusiness.setRemarks(ub.getRemarks());
  347. userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  348. userFollowBusinessMapper.insert(userFollowBusiness);
  349. }else{
  350. //检测是否可以创建业务
  351. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessGlossoryId(), "")>0){
  352. String businessName = businessGlossoryMapper.selectByPrimaryKey(ub.getBusinessGlossoryId()).getName();
  353. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  354. }
  355. String ubId = UUID.randomUUID().toString();
  356. //更新业务表
  357. userBusiness.setId(ubId);
  358. userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  359. try {
  360. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  361. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  362. } catch (ParseException e) {
  363. e.printStackTrace();
  364. }
  365. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  366. userBusiness.setFollowSituation(ub.getFollowSituation());
  367. userBusiness.setUid(fbb.getUid());
  368. userBusiness.setAid(TokenManager.getAdminId());
  369. userBusinessMapper.insert(userBusiness);
  370. //更新业务中间表
  371. userFollowBusiness.setBusinessId(ubId);
  372. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  373. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  374. userFollowBusiness.setId(ufbId);
  375. userFollowBusiness.setFollowId(followId);
  376. userFollowBusiness.setRemarks(ub.getRemarks());
  377. userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  378. userFollowBusinessMapper.insert(userFollowBusiness);
  379. }
  380. }
  381. return 1;
  382. }
  383. @Override
  384. public FollowBusinessBo findFollowById(String followId) {
  385. return userMapper.findFollowById(followId);
  386. }
  387. @Override
  388. public List<UserBusiness> findBusinessByFollowId(String followId) {
  389. return userMapper.findBusinessByFollowId(followId);
  390. }
  391. @Override
  392. @Transactional
  393. public int updateFollow(FollowBusinessBo fbb) throws BusinessException{
  394. UserFollow userFollow = new UserFollow();
  395. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  396. userFollow.setId(fbb.getFollowId());
  397. if(StringUtils.isNotBlank(fbb.getOcbId())) userFollow.setOcbId(fbb.getOcbId());
  398. userFollow.setResult(fbb.getResult());
  399. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  400. userFollowMapper.updateByPrimaryKeySelective(userFollow); //修改拜访记录表
  401. UserFollowBusiness userFollowBusiness = null;
  402. for(UserBusiness ub: fbb.getUserBusinessList()){
  403. userFollowBusiness = new UserFollowBusiness();
  404. if(StringUtils.isNotBlank(ub.getId())){
  405. userFollowBusiness.setId(ub.getId());
  406. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  407. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  408. userFollowBusiness.setRemarks(ub.getRemarks());
  409. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); //修改拜访记录中间表
  410. }else{
  411. //检测是否可以创建业务
  412. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessGlossoryId(), "")>0){
  413. String businessName = businessGlossoryMapper.selectByPrimaryKey(ub.getBusinessGlossoryId()).getName();
  414. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  415. }
  416. String ubId = UUID.randomUUID().toString();
  417. UserBusiness userBusiness = new UserBusiness();
  418. //更新业务表
  419. userBusiness.setId(ubId);
  420. userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  421. try {
  422. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  423. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  424. } catch (ParseException e) {
  425. e.printStackTrace();
  426. }
  427. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  428. userBusiness.setFollowSituation(ub.getFollowSituation());
  429. userBusiness.setUid(fbb.getUid());
  430. userBusiness.setAid(TokenManager.getAdminId());
  431. userBusinessMapper.insert(userBusiness);
  432. //更新业务中间表
  433. String ufbId = UUID.randomUUID().toString();
  434. userFollowBusiness.setId(ufbId);
  435. userFollowBusiness.setFollowId(fbb.getFollowId());
  436. userFollowBusiness.setBusinessId(ubId);
  437. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  438. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  439. userFollowBusiness.setRemarks(ub.getRemarks());
  440. userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  441. userFollowBusinessMapper.insert(userFollowBusiness);
  442. }
  443. }
  444. return 1;
  445. }
  446. @Override
  447. public Set<OrganizationContactBook> findAllContacts(String uid) {
  448. Set<OrganizationContactBook> result = new HashSet<OrganizationContactBook>();
  449. result.addAll(userMapper.findAllContacts(uid));
  450. return result;
  451. }
  452. @Override
  453. public int updateCustomerContacts(List<OrganizationContactBook> ocbList,String uid) {
  454. if(ocbList.size()>0){
  455. OrganizationContactBook ocb = null;
  456. for(OrganizationContactBook item: ocbList){
  457. ocb = new OrganizationContactBook();
  458. try {
  459. BeanUtils.copyProperties(ocb, item);
  460. if(StringUtils.isBlank(ocb.getId())){
  461. ocb.setId(UUID.randomUUID().toString());
  462. ocb.setUid(uid);
  463. ocb.setAid(TokenManager.getAdminId());
  464. organizationContactBookMapper.insert(ocb);
  465. }else{
  466. organizationContactBookMapper.updateByPrimaryKeySelective(ocb);
  467. }
  468. } catch (IllegalAccessException | InvocationTargetException e) {
  469. e.printStackTrace();
  470. }
  471. }
  472. }
  473. return 1;
  474. }
  475. @Override
  476. public int deleteFollow(String followId) {
  477. UserFollow uf = new UserFollow();
  478. uf.setId(followId);
  479. uf.setEffective(1);
  480. return userFollowMapper.updateByPrimaryKeySelective(uf);
  481. }
  482. @Override
  483. public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows) {
  484. List<User> list = null;
  485. User user = null;
  486. for (CustomerExcelBo bo : boSet) {
  487. list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()));
  488. if (list.size() > 0) {
  489. user = list.get(0);
  490. bo.setUid(user.getId());
  491. if (userBusinessMapper.judgeBusiness(bo.getUid(), Integer.parseInt(bo.getBusinessGlossoryId()),"") > 0) {
  492. existRows.add(bo.getRowNumber());
  493. }
  494. }
  495. }
  496. }
  497. @Override
  498. @Transactional
  499. public int saveUploadData(Set<CustomerExcelBo> boSet) {
  500. Date now = new Date();
  501. String uid = "";
  502. for(CustomerExcelBo bo : boSet){
  503. if(StringUtils.isBlank(bo.getUid())){ //新建客户
  504. uid = UUID.randomUUID().toString();
  505. createUser(bo, uid, now);
  506. createIdentity(bo, bo.getCustomerType(), uid);
  507. createBusiness(bo, uid, now);
  508. createContacts(bo, uid);
  509. }else{ //新建业务
  510. uid = bo.getUid();
  511. createBusiness(bo, uid, now);
  512. if(organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId())<=0){
  513. createContacts(bo, uid);
  514. }
  515. }
  516. }
  517. return 1;
  518. }
  519. private void createUser(CustomerExcelBo bo,String uid,Date now){
  520. User user = new User();
  521. user.setId(uid);
  522. user.setIdentifyName(bo.getIdentifyName());
  523. user.setSource(1);
  524. user.setNickname(bo.getIdentifyName());
  525. user.setStatus(0);
  526. user.setShareType(0);
  527. user.setServiceCertification(0);
  528. user.setUserCertification(0);
  529. user.setAid(TokenManager.getAdminId());
  530. user.setType(Integer.parseInt(bo.getCustomerType()));
  531. user.setCurrentMemberStatus(0);
  532. user.setLvl(1);
  533. user.setCreateTime(now);
  534. user.setUpdateTime(now);
  535. user.setMobile(bo.getMobile());
  536. user.setPassword(AFTConstants.INITIALPASSWORD);
  537. user.setIsMember(0);
  538. passwordUtil.encryptPassword(user);
  539. userMapper.insert(user);
  540. }
  541. private void createIdentity(CustomerExcelBo bo,String type,String uid){
  542. String identifyId = UUID.randomUUID().toString();
  543. if(type.equals(AFTConstants.USER_TYPE_PERSONAL)){
  544. //新增个人认证信息
  545. UserIdentity ui = new UserIdentity();
  546. ui.setId(identifyId);
  547. ui.setUid(uid);
  548. ui.setContacts(bo.getContacts());
  549. ui.setContactMobile(bo.getMobile());
  550. ui.setUsername(bo.getIdentifyName());
  551. ui.setExpert(0);
  552. ui.setCelebrity(0);
  553. ui.setInternational(0);
  554. ui.setAuditStatus(0);
  555. userIdentityMapper.insert(ui);
  556. }else if(type.equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  557. // 创建企业认证信息
  558. OrganizationIdentity oi = new OrganizationIdentity();
  559. oi.setId(identifyId);
  560. oi.setUnitName(bo.getIdentifyName());
  561. oi.setUid(uid);
  562. oi.setContacts(bo.getContacts());
  563. oi.setContactMobile(bo.getMobile());
  564. oi.setHighTechZone(0);
  565. oi.setInternational(0);
  566. oi.setListed(0);
  567. oi.setAuditStatus(5); //实名企业
  568. organizationIdentityMapper.insert(oi);
  569. }
  570. }
  571. private void createContacts(CustomerExcelBo bo,String uid){
  572. //新增企业联系人
  573. OrganizationContactBook cob = new OrganizationContactBook();
  574. cob.setAid(TokenManager.getAdminId());
  575. cob.setId(UUID.randomUUID().toString());
  576. cob.setUid(uid);
  577. cob.setName(bo.getContacts());
  578. cob.setMobile(bo.getMobile());
  579. organizationContactBookMapper.insert(cob);
  580. }
  581. private void createBusiness(CustomerExcelBo bo,String uid,Date now){
  582. //新增业务
  583. UserBusiness ub = new UserBusiness();
  584. ub.setId(UUID.randomUUID().toString());
  585. ub.setAid(TokenManager.getAdminId());
  586. ub.setBusinessGlossoryId(Integer.parseInt(bo.getBusinessGlossoryId()));
  587. ub.setUid(uid);
  588. ub.setCreateTime(now);
  589. ub.setUpdateTime(now);
  590. ub.setCustomerStatus(Integer.parseInt(bo.getCustomerStatus()));
  591. ub.setFollowSituation(Integer.parseInt(bo.getFollowSituation()));
  592. userBusinessMapper.insert(ub);
  593. }
  594. @Override
  595. public int updateByOperatorType(String uid, String operatorType) {
  596. User user = new User();
  597. user.setId(uid);
  598. if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_PUBLIC)){
  599. user.setShareType(AFTConstants.SHARE_TYPE_PUBLIC);
  600. }else if(operatorType.equals(AFTConstants.USER_RECEIVE)){
  601. user.setAid(TokenManager.getAdminId());
  602. user.setShareType(AFTConstants.SHARE_TYPE_PRIVATE);
  603. }else if(operatorType.equals(AFTConstants.USER_DELETE)){
  604. user.setStatus(AFTConstants.USER_STATUS_CANCEL);
  605. }
  606. return userMapper.updateByPrimaryKeySelective(user);
  607. }
  608. }