CustomerServiceImpl.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  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.enums.CustomerStatusFiled;
  29. import com.goafanti.common.enums.DeleteStatus;
  30. import com.goafanti.common.enums.IdentityProcess;
  31. import com.goafanti.common.enums.MemberStatus;
  32. import com.goafanti.common.enums.UserLevel;
  33. import com.goafanti.common.enums.UserType;
  34. import com.goafanti.common.error.BusinessException;
  35. import com.goafanti.common.model.Admin;
  36. import com.goafanti.common.model.OrganizationContactBook;
  37. import com.goafanti.common.model.OrganizationIdentity;
  38. import com.goafanti.common.model.User;
  39. import com.goafanti.common.model.UserBusiness;
  40. import com.goafanti.common.model.UserFollow;
  41. import com.goafanti.common.model.UserFollowBusiness;
  42. import com.goafanti.common.model.UserIdentity;
  43. import com.goafanti.common.utils.BeanUtilsExt;
  44. import com.goafanti.common.utils.PasswordUtil;
  45. import com.goafanti.common.utils.StringUtils;
  46. import com.goafanti.core.mybatis.BaseMybatisDao;
  47. import com.goafanti.core.mybatis.page.Pagination;
  48. import com.goafanti.core.shiro.token.TokenManager;
  49. import com.goafanti.customer.bo.BusinessListBo;
  50. import com.goafanti.customer.bo.BussinessFollowBo;
  51. import com.goafanti.customer.bo.CustomerExcelBo;
  52. import com.goafanti.customer.bo.CustomerListIn;
  53. import com.goafanti.customer.bo.CustomerListOut;
  54. import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
  55. import com.goafanti.customer.bo.CustomerPersonalDetailBo;
  56. import com.goafanti.customer.bo.CustomerSimpleBo;
  57. import com.goafanti.customer.bo.FollowBusinessBo;
  58. import com.goafanti.customer.bo.FollowListBo;
  59. import com.goafanti.customer.bo.StatisticBo;
  60. import com.goafanti.customer.service.CustomerService;
  61. @Service
  62. public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements CustomerService {
  63. @Autowired
  64. private UserMapper userMapper;
  65. @Autowired
  66. private UserIdentityMapper userIdentityMapper;
  67. @Autowired
  68. private OrganizationIdentityMapper organizationIdentityMapper;
  69. @Autowired
  70. private OrganizationContactBookMapper organizationContactBookMapper;
  71. @Resource(name = "passwordUtil")
  72. private PasswordUtil passwordUtil;
  73. @Resource
  74. private UserFollowMapper userFollowMapper;
  75. @Resource
  76. private UserBusinessMapper userBusinessMapper;
  77. @Resource
  78. private UserFollowBusinessMapper userFollowBusinessMapper;
  79. @Resource
  80. private BusinessGlossoryMapper businessGlossoryMapper;
  81. @Override
  82. public Pagination<CustomerListOut> listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  83. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  84. cli.setAid(TokenManager.getAdminId());
  85. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  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> listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  93. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  94. /*cli.setAid(TokenManager.getAdminId());*/
  95. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC));
  96. Map<String,Object> params = disposeParams(cli);
  97. @SuppressWarnings("unchecked")
  98. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
  99. return list;
  100. }
  101. @Override
  102. public Pagination<CustomerListOut> listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  103. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  104. Map<String,Object> params = disposeParams(cli);
  105. if(null!=cli.getExpertAudit())params.put("expertAudit", cli.getExpertAudit());
  106. @SuppressWarnings("unchecked")
  107. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
  108. return list;
  109. }
  110. @Override
  111. public Pagination<CustomerListOut> listAllManagePersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  112. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  113. Map<String,Object> params = disposeParams(cli);
  114. @SuppressWarnings("unchecked")
  115. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManagePersonalCustomerList","selectManagePersonalCustomerCount",params,pageNo,pageSize);
  116. return list;
  117. }
  118. @Override
  119. public Pagination<CustomerListOut> listPrivateOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  120. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  121. cli.setAid(TokenManager.getAdminId());
  122. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  123. Map<String,Object> params = disposeParams(cli);
  124. @SuppressWarnings("unchecked")
  125. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  126. return list;
  127. }
  128. @Override
  129. public Pagination<CustomerListOut> listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  130. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  131. /*cli.setAid(TokenManager.getAdminId());*/
  132. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC));
  133. Map<String,Object> params = disposeParams(cli);
  134. @SuppressWarnings("unchecked")
  135. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  136. return list;
  137. }
  138. @Override
  139. public Pagination<CustomerListOut> listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  140. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  141. Map<String,Object> params = disposeParams(cli);
  142. @SuppressWarnings("unchecked")
  143. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  144. return list;
  145. }
  146. @Override
  147. public Pagination<CustomerListOut> listAllManageOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  148. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  149. Map<String,Object> params = disposeParams(cli);
  150. @SuppressWarnings("unchecked")
  151. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManageOrganizationCustomerList","selectManageOrganizationCustomerCount",params,pageNo,pageSize);
  152. return list;
  153. }
  154. private Map<String,Object> disposeParams(CustomerListIn cli){
  155. Map<String,Object> params = new HashMap<String, Object>();
  156. if(StringUtils.isNotBlank(cli.getType())) params.put("type", Integer.parseInt(cli.getType()));
  157. if(StringUtils.isNotBlank(cli.getShareType())) params.put("shareType", Integer.parseInt(cli.getShareType()));
  158. if(StringUtils.isNotBlank(cli.getName())) params.put("name", cli.getName());
  159. if(StringUtils.isNotBlank(cli.getProvince())) params.put("province", Integer.parseInt(cli.getProvince()));
  160. if(StringUtils.isNotBlank(cli.getCity())) params.put("city", Integer.parseInt(cli.getCity()));
  161. if(StringUtils.isNotBlank(cli.getArea())) params.put("area", Integer.parseInt(cli.getArea()));
  162. if(StringUtils.isNotBlank(cli.getContacts())) params.put("contacts", cli.getContacts());
  163. if(StringUtils.isNotBlank(cli.getContactMobile())) params.put("contactMobile", cli.getContactMobile());
  164. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate());
  165. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate());
  166. if(StringUtils.isNotBlank(cli.getExpert())) params.put("expert", Integer.parseInt(cli.getExpert()));
  167. if(StringUtils.isNotBlank(cli.getIndustry())) params.put("industry", Integer.parseInt(cli.getIndustry()));
  168. if(StringUtils.isNotBlank(cli.getInternational())) params.put("international", Integer.parseInt(cli.getInternational()));
  169. if(StringUtils.isNotBlank(cli.getAuditStatus())) params.put("auditStatus", Integer.parseInt(cli.getAuditStatus()));
  170. if(StringUtils.isNotBlank(cli.getBusinessAudit())) params.put("businessAudit", Integer.parseInt(cli.getBusinessAudit()));
  171. if(StringUtils.isNotBlank(cli.getCurrentMemberStatus())) params.put("currentMemberStatus", Integer.parseInt(cli.getCurrentMemberStatus()));
  172. if(StringUtils.isNotBlank(cli.getLvl())) params.put("lvl", Integer.parseInt(cli.getLvl()));
  173. if(StringUtils.isNotBlank(cli.getListed())) params.put("listed", Integer.parseInt(cli.getListed()));
  174. if(StringUtils.isNotBlank(cli.getHighTechZone())) params.put("highTechZone", Integer.parseInt(cli.getHighTechZone()));
  175. if(StringUtils.isNotBlank(cli.getExpert())) params.put("expert", Integer.parseInt(cli.getExpert()));
  176. if(StringUtils.isNotBlank(cli.getCelebrity())) params.put("celebrity", Integer.parseInt(cli.getCelebrity()));
  177. if(StringUtils.isNotBlank(cli.getAid())) params.put("aid", cli.getAid());
  178. if(StringUtils.isNotBlank(cli.getIsMember())) params.put("isMember", Integer.parseInt(cli.getIsMember()));
  179. if(StringUtils.isNotBlank(cli.getStatus())) params.put("status", Integer.parseInt(cli.getStatus()));
  180. if(StringUtils.isNotBlank(cli.getSocietyTag())) params.put("societyTag", cli.getSocietyTag());
  181. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate()+" 00:00:00");
  182. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate()+" 23:59:59");
  183. return params;
  184. }
  185. @Override
  186. public List<CustomerSimpleBo> findCustomerByName(String name) {
  187. return userMapper.findCustomerByName(name);
  188. }
  189. @Override
  190. public int judgeCustomerByName(String name) {
  191. return userMapper.judgeCustomerByName(name);
  192. }
  193. @Override
  194. @Transactional
  195. public int addCustomer(String name, String contacts, String contactMobile, Integer type,String societyTag) throws BusinessException{
  196. User user = new User();
  197. Date now = new Date();
  198. String uid = UUID.randomUUID().toString();
  199. String identifyId = UUID.randomUUID().toString();
  200. user.setId(uid);
  201. user.setIdentifyName(name);
  202. user.setSource(AFTConstants.USER_SOURCE_CREATE);
  203. user.setNickname(name);
  204. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  205. user.setShareType(AFTConstants.NO);
  206. user.setAid(TokenManager.getAdminId());
  207. user.setType(type);
  208. user.setCurrentMemberStatus(MemberStatus.NORMAL.getCode());
  209. user.setLvl(UserLevel.CERTIFIED.getCode());
  210. user.setSocietyTag(societyTag);
  211. user.setCreateTime(now);
  212. user.setUpdateTime(now);
  213. user.setMobile(contactMobile);
  214. user.setPassword(AFTConstants.INITIALPASSWORD);
  215. user.setIsMember(AFTConstants.NO);
  216. user.setBusinessAudit(AFTConstants.NO);
  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.judgeCustomerByName(name)>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. organizationContactBookMapper.insert(cob);
  255. return 1;
  256. }
  257. @Override
  258. public CustomerPersonalDetailBo findPersonalCustomerDetail(String uid) {
  259. return userMapper.findPersonalCustomerDetail(uid);
  260. }
  261. @Override
  262. public CustomerOrganizationDetailBo findOrganizationCustomerDetail(String uid) {
  263. return userMapper.findOrganizationCustomerDetail(uid);
  264. }
  265. @Override
  266. @Transactional
  267. public int updateOrganizationCustomer(CustomerOrganizationDetailBo bo) {
  268. OrganizationIdentity oi = new OrganizationIdentity();
  269. User user = new User();
  270. try {
  271. BeanUtilsExt.copyProperties(oi, bo);
  272. user.setId(bo.getUid());
  273. user.setSocietyTag(bo.getSocietyTag());
  274. user.setCompanyLogoUrl(bo.getCompanyLogoUrl());
  275. user.setIntroduction(bo.getIntroduction());
  276. user.setUpdateTime(new Date());
  277. user.setBusinessAudit(bo.getBusinessAudit());
  278. } catch (IllegalAccessException |InvocationTargetException e) {
  279. e.printStackTrace();
  280. }
  281. organizationIdentityMapper.updateByPrimaryKeySelective(oi);
  282. userMapper.updateByPrimaryKeySelective(user);
  283. return 1;
  284. }
  285. @Override
  286. public int updatePersonalCustomer(CustomerPersonalDetailBo bo) {
  287. UserIdentity ui = new UserIdentity();
  288. User user = new User();
  289. try {
  290. BeanUtilsExt.copyProperties(ui, bo);
  291. user.setId(bo.getUid());
  292. user.setSocietyTag(bo.getSocietyTag());
  293. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  294. user.setIntroduction(bo.getIntroduction());
  295. user.setUpdateTime(new Date());
  296. user.setBusinessAudit(bo.getBusinessAudit());
  297. if(null==bo.getExpertAudit()&&bo.getExpert()==1)ui.setExpertAudit(2);
  298. } catch (InvocationTargetException | IllegalAccessException e) {
  299. e.printStackTrace();
  300. }
  301. userIdentityMapper.updateByPrimaryKeySelective(ui);
  302. userMapper.updateByPrimaryKeySelective(user);
  303. return 1;
  304. }
  305. @SuppressWarnings("unchecked")
  306. @Override
  307. public Pagination<FollowListBo> listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessGlossoryId) {
  308. Map<String, Object> params = new HashMap<String, Object>();
  309. if(StringUtils.isNotBlank(uid))params.put("uid", uid);
  310. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  311. return (Pagination<FollowListBo>)findPage("selectFollowHistoryList","selectFollowHistoryCount",params, pageNo, pageSize);
  312. }
  313. @Override
  314. public User findUserAccountDetail(String uid) {
  315. return userMapper.findUserAccountDetail(uid);
  316. }
  317. @Override
  318. public int updateUserAccount(User user) {
  319. return userMapper.updateByPrimaryKeySelective(user);
  320. }
  321. @Override
  322. public List<OrganizationContactBook> findCustomerContacts(String uid) {
  323. return userMapper.findCustomerContacts(uid,TokenManager.getAdminId());
  324. }
  325. @Override
  326. @Transactional
  327. public int addFollow(FollowBusinessBo fbb) throws BusinessException{
  328. if(fbb.getUserBusinessList().size()<1) throw new BusinessException(new Error(ErrorConstants.AT_LEAST_A_BUSINESS,"",""));
  329. //更新跟进记录表
  330. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  331. UserFollow userFollow = new UserFollow();
  332. String followId = UUID.randomUUID().toString();
  333. userFollow.setId(followId);
  334. userFollow.setAid(TokenManager.getAdminId());
  335. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  336. userFollow.setEffective(DeleteStatus.UNDELETE.getCode());
  337. try {
  338. userFollow.setCreateTime(format.parse(fbb.getFollowTime()));
  339. } catch (ParseException e) {
  340. e.printStackTrace();
  341. }
  342. userFollow.setOcbId(fbb.getOcbId());
  343. userFollow.setResult(fbb.getResult());
  344. userFollow.setUid(fbb.getUid());
  345. int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), TokenManager.getAdminId()) + 1;
  346. userFollow.setFollowCount(followCount);
  347. userFollowMapper.insert(userFollow);
  348. String ufbId = "";
  349. UserBusiness userBusiness = null;
  350. UserFollowBusiness userFollowBusiness = null;
  351. for(UserBusiness ub: fbb.getUserBusinessList()){
  352. userBusiness = new UserBusiness();
  353. userFollowBusiness = new UserFollowBusiness();
  354. ufbId = UUID.randomUUID().toString();
  355. if(StringUtils.isNotBlank(ub.getId())){
  356. //更新业务表
  357. userBusiness.setId(ub.getId());
  358. userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  359. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  360. userBusiness.setFollowSituation(ub.getFollowSituation());
  361. userBusiness.setUid(fbb.getUid());
  362. try {
  363. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  364. } catch (ParseException e) {
  365. e.printStackTrace();
  366. }
  367. userBusiness.setAid(TokenManager.getAdminId());
  368. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  369. //更新业务中间表
  370. userFollowBusiness.setBusinessId(ub.getId());
  371. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  372. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  373. userFollowBusiness.setId(ufbId);
  374. userFollowBusiness.setFollowId(followId);
  375. userFollowBusiness.setRemarks(ub.getRemarks());
  376. userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  377. userFollowBusinessMapper.insert(userFollowBusiness);
  378. }else{
  379. //检测是否可以创建业务
  380. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessGlossoryId(), "")>0){
  381. String businessName = businessGlossoryMapper.selectByPrimaryKey(ub.getBusinessGlossoryId()).getName();
  382. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  383. }
  384. String ubId = UUID.randomUUID().toString();
  385. //更新业务表
  386. userBusiness.setId(ubId);
  387. userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  388. try {
  389. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  390. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  391. } catch (ParseException e) {
  392. e.printStackTrace();
  393. }
  394. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  395. userBusiness.setFollowSituation(ub.getFollowSituation());
  396. userBusiness.setUid(fbb.getUid());
  397. userBusiness.setAid(TokenManager.getAdminId());
  398. userBusinessMapper.insert(userBusiness);
  399. //更新业务中间表
  400. userFollowBusiness.setBusinessId(ubId);
  401. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  402. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  403. userFollowBusiness.setId(ufbId);
  404. userFollowBusiness.setFollowId(followId);
  405. userFollowBusiness.setRemarks(ub.getRemarks());
  406. userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  407. userFollowBusinessMapper.insert(userFollowBusiness);
  408. }
  409. }
  410. return 1;
  411. }
  412. @Override
  413. public FollowBusinessBo findFollowById(String followId) {
  414. return userMapper.findFollowById(followId);
  415. }
  416. @Override
  417. public List<UserBusiness> findBusinessByFollowId(String followId) {
  418. return userMapper.findBusinessByFollowId(followId);
  419. }
  420. @Override
  421. @Transactional
  422. public int updateFollow(FollowBusinessBo fbb) throws BusinessException{
  423. UserFollow userFollow = new UserFollow();
  424. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  425. userFollow.setId(fbb.getFollowId());
  426. if(StringUtils.isNotBlank(fbb.getOcbId())) userFollow.setOcbId(fbb.getOcbId());
  427. userFollow.setResult(fbb.getResult());
  428. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  429. userFollowMapper.updateByPrimaryKeySelective(userFollow); //修改拜访记录表
  430. UserFollowBusiness userFollowBusiness = null;
  431. for(UserBusiness ub: fbb.getUserBusinessList()){
  432. userFollowBusiness = new UserFollowBusiness();
  433. if(StringUtils.isNotBlank(ub.getId())){
  434. userFollowBusiness.setId(ub.getId());
  435. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  436. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  437. userFollowBusiness.setRemarks(ub.getRemarks());
  438. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); //修改拜访记录中间表
  439. }else{
  440. //检测是否可以创建业务
  441. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessGlossoryId(), "")>0){
  442. String businessName = businessGlossoryMapper.selectByPrimaryKey(ub.getBusinessGlossoryId()).getName();
  443. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  444. }
  445. String ubId = UUID.randomUUID().toString();
  446. UserBusiness userBusiness = new UserBusiness();
  447. //更新业务表
  448. userBusiness.setId(ubId);
  449. userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  450. try {
  451. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  452. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  453. } catch (ParseException e) {
  454. e.printStackTrace();
  455. }
  456. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  457. userBusiness.setFollowSituation(ub.getFollowSituation());
  458. userBusiness.setUid(fbb.getUid());
  459. userBusiness.setAid(TokenManager.getAdminId());
  460. userBusinessMapper.insert(userBusiness);
  461. //更新业务中间表
  462. String ufbId = UUID.randomUUID().toString();
  463. userFollowBusiness.setId(ufbId);
  464. userFollowBusiness.setFollowId(fbb.getFollowId());
  465. userFollowBusiness.setBusinessId(ubId);
  466. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  467. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  468. userFollowBusiness.setRemarks(ub.getRemarks());
  469. userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId());
  470. userFollowBusinessMapper.insert(userFollowBusiness);
  471. }
  472. }
  473. return 1;
  474. }
  475. @Override
  476. public Set<OrganizationContactBook> findAllContacts(String uid) {
  477. Set<OrganizationContactBook> result = new HashSet<OrganizationContactBook>();
  478. result.addAll(userMapper.findAllContacts(uid));
  479. return result;
  480. }
  481. @Override
  482. public int updateCustomerContacts(List<OrganizationContactBook> ocbList,String uid) {
  483. if(ocbList.size()>0){
  484. OrganizationContactBook ocb = null;
  485. for(OrganizationContactBook item: ocbList){
  486. ocb = new OrganizationContactBook();
  487. try {
  488. BeanUtils.copyProperties(ocb, item);
  489. if(StringUtils.isBlank(ocb.getId())){
  490. ocb.setId(UUID.randomUUID().toString());
  491. ocb.setUid(uid);
  492. ocb.setAid(TokenManager.getAdminId());
  493. organizationContactBookMapper.insert(ocb);
  494. }else{
  495. organizationContactBookMapper.updateByPrimaryKeySelective(ocb);
  496. }
  497. } catch (IllegalAccessException | InvocationTargetException e) {
  498. e.printStackTrace();
  499. }
  500. }
  501. }
  502. return 1;
  503. }
  504. @Override
  505. public int deleteFollow(String followId) {
  506. UserFollow uf = new UserFollow();
  507. uf.setId(followId);
  508. uf.setEffective(DeleteStatus.DELETED.getCode());
  509. return userFollowMapper.updateByPrimaryKeySelective(uf);
  510. }
  511. @Override
  512. public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows, Set<Integer> filterRows) {
  513. List<User> list = null;
  514. CustomerExcelBo[] bos = (CustomerExcelBo[])boSet.toArray(new CustomerExcelBo[] {});
  515. for (int i=0;i<bos.length;i++) {
  516. CustomerExcelBo bo = bos[i];
  517. CustomerExcelBo ceb = null;
  518. for(int j=0;j<i;j++){
  519. ceb = bos[j];
  520. if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){ //个人
  521. if(ceb.getMobile().equals(bo.getMobile()) && ceb.getCustomerType().equals(bo.getCustomerType())){
  522. bo.setUid(ceb.getUid());
  523. bo.setNewData(false);
  524. filterRows.add(bo.getRowNumber());
  525. break;
  526. }
  527. }else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){ //单位
  528. if(ceb.getIdentifyName().equals(bo.getIdentifyName()) && ceb.getCustomerType().equals(bo.getCustomerType())){
  529. bo.setUid(ceb.getUid());
  530. bo.setNewData(false);
  531. filterRows.add(bo.getRowNumber());
  532. break;
  533. }
  534. }
  535. }
  536. if(StringUtils.isBlank(bo.getUid())){ //是否已经存在
  537. if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){
  538. list = userMapper.checkUser("", "", bo.getMobile(), Integer.parseInt(bo.getCustomerType()),null,null);
  539. }else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  540. list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()),null,null);
  541. }
  542. if (list.size() > 0) {
  543. bo.setUid(list.get(0).getId());
  544. bo.setNewData(false);
  545. if (userBusinessMapper.judgeBusiness(bo.getUid(), Integer.parseInt(bo.getBusinessGlossoryId()),"") > 0) {
  546. existRows.add(bo.getRowNumber());
  547. }
  548. }else{
  549. bo.setUid(UUID.randomUUID().toString());
  550. bo.setNewData(true);
  551. }
  552. }else{
  553. if (userBusinessMapper.judgeBusiness(bo.getUid(), Integer.parseInt(bo.getBusinessGlossoryId()),"") > 0) {
  554. existRows.add(bo.getRowNumber());
  555. }
  556. }
  557. }
  558. }
  559. @Override
  560. @Transactional
  561. public int saveUploadData(Set<CustomerExcelBo> boSet) {
  562. Date now = new Date();
  563. String uid = "";
  564. for(CustomerExcelBo bo : boSet){
  565. uid = bo.getUid();
  566. if(bo.isNewData()){ //新建客户
  567. createUser(bo, uid, now);
  568. createIdentity(bo, bo.getCustomerType(), uid);
  569. createBusiness(bo, uid, now);
  570. createContacts(bo, uid);
  571. }else{ //新建业务
  572. createBusiness(bo, uid, now);
  573. if(organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId())<=0){
  574. createContacts(bo, uid);
  575. }
  576. }
  577. }
  578. return 1;
  579. }
  580. private void createUser(CustomerExcelBo bo,String uid,Date now){
  581. User user = new User();
  582. user.setId(uid);
  583. user.setIdentifyName(bo.getIdentifyName());
  584. user.setSource(AFTConstants.USER_SOURCE_CREATE);
  585. user.setNickname(bo.getIdentifyName());
  586. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  587. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  588. user.setAid(TokenManager.getAdminId());
  589. user.setType(Integer.parseInt(bo.getCustomerType()));
  590. user.setCurrentMemberStatus(MemberStatus.NORMAL.getCode());
  591. user.setLvl(UserLevel.CERTIFIED.getCode());
  592. user.setCreateTime(now);
  593. user.setUpdateTime(now);
  594. user.setMobile(bo.getMobile());
  595. user.setPassword(AFTConstants.INITIALPASSWORD);
  596. user.setIsMember(AFTConstants.NO);
  597. user.setBusinessAudit(AFTConstants.NO);
  598. passwordUtil.encryptPassword(user);
  599. userMapper.insert(user);
  600. }
  601. private void createIdentity(CustomerExcelBo bo,String type,String uid){
  602. String identifyId = UUID.randomUUID().toString();
  603. if(type.equals(AFTConstants.USER_TYPE_PERSONAL)){
  604. //新增个人认证信息
  605. UserIdentity ui = new UserIdentity();
  606. ui.setId(identifyId);
  607. ui.setUid(uid);
  608. ui.setContacts(bo.getContacts());
  609. ui.setContactMobile(bo.getMobile());
  610. ui.setUsername(bo.getIdentifyName());
  611. ui.setExpert(AFTConstants.NO);
  612. ui.setCelebrity(AFTConstants.NO);
  613. ui.setInternational(AFTConstants.NO);
  614. ui.setAuditStatus(5);
  615. userIdentityMapper.insert(ui);
  616. }else if(type.equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  617. // 创建企业认证信息
  618. OrganizationIdentity oi = new OrganizationIdentity();
  619. oi.setId(identifyId);
  620. oi.setUnitName(bo.getIdentifyName());
  621. oi.setUid(uid);
  622. oi.setContacts(bo.getContacts());
  623. oi.setContactMobile(bo.getMobile());
  624. oi.setHighTechZone(AFTConstants.NO);
  625. oi.setInternational(AFTConstants.NO);
  626. oi.setListed(AFTConstants.NO);
  627. oi.setAuditStatus(5); //实名企业
  628. organizationIdentityMapper.insert(oi);
  629. }
  630. }
  631. private void createContacts(CustomerExcelBo bo,String uid){
  632. //新增企业联系人
  633. OrganizationContactBook cob = new OrganizationContactBook();
  634. cob.setAid(TokenManager.getAdminId());
  635. cob.setId(UUID.randomUUID().toString());
  636. cob.setUid(uid);
  637. cob.setName(bo.getContacts());
  638. cob.setMobile(bo.getMobile());
  639. organizationContactBookMapper.insert(cob);
  640. }
  641. private void createBusiness(CustomerExcelBo bo,String uid,Date now){
  642. //新增业务
  643. UserBusiness ub = new UserBusiness();
  644. ub.setId(UUID.randomUUID().toString());
  645. ub.setAid(TokenManager.getAdminId());
  646. ub.setBusinessGlossoryId(Integer.parseInt(bo.getBusinessGlossoryId()));
  647. ub.setUid(uid);
  648. ub.setCreateTime(now);
  649. ub.setUpdateTime(now);
  650. ub.setCustomerStatus(Integer.parseInt(bo.getCustomerStatus()));
  651. ub.setFollowSituation(Integer.parseInt(bo.getFollowSituation()));
  652. userBusinessMapper.insert(ub);
  653. }
  654. @Override
  655. public int updateByOperatorType(String uid, String operatorType,Object... params) {
  656. User user = new User();
  657. user.setId(uid);
  658. if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_PUBLIC)){
  659. user.setShareType(AFTConstants.USER_SHARE_PUBLIC);
  660. }else if(operatorType.equals(AFTConstants.USER_RECEIVE)){
  661. user.setAid(TokenManager.getAdminId());
  662. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  663. }else if(operatorType.equals(AFTConstants.USER_DELETE)){
  664. user.setStatus(AFTConstants.USER_STATUS_CANCEL);
  665. }else if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_OTHER)){
  666. user.setAid(String.valueOf(params[0]));
  667. }
  668. return userMapper.updateByPrimaryKeySelective(user);
  669. }
  670. @SuppressWarnings("unchecked")
  671. @Override
  672. public Pagination<StatisticBo> customerStatistics(Date sDate, Date eDate, String depNo, String businessGlossoryId, Integer pageNo, Integer pageSize) {
  673. Map<String,Object> params = new HashMap<String,Object>();
  674. if(null != sDate) params.put("sDate", sDate);
  675. if(null != eDate) params.put("eDate", eDate);
  676. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  677. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  678. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("customerStatisticsList", "customerStatisticsCount", params, pageNo, pageSize);
  679. return page;
  680. }
  681. @SuppressWarnings("unchecked")
  682. @Override
  683. public Pagination<StatisticBo> businessStatistic(Date sDate, Date eDate,String depNo, String businessGlossoryId,Integer pageNo, Integer pageSize) {
  684. Map<String,Object> params = new HashMap<String,Object>();
  685. if(null != sDate) params.put("sDate", sDate);
  686. if(null != eDate) params.put("eDate", eDate);
  687. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  688. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  689. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("businessStatisticList", "businessStatisticCount", params, pageNo, pageSize);
  690. return page;
  691. }
  692. @SuppressWarnings("unchecked")
  693. @Override
  694. public Pagination<StatisticBo> followStatistic(Date sDate, Date eDate, String depNo, Integer pageNo, Integer pageSize) {
  695. Map<String,Object> params = new HashMap<String,Object>();
  696. if(null != sDate) params.put("sDate", sDate);
  697. if(null != eDate) params.put("eDate", eDate);
  698. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  699. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("followStatisticList", "followStatisticCount", params, pageNo, pageSize);
  700. return page;
  701. }
  702. @SuppressWarnings("unchecked")
  703. @Override
  704. public Pagination<BusinessListBo> listBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) {
  705. blo.setAid(TokenManager.getAdminId());
  706. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  707. }
  708. @SuppressWarnings("unchecked")
  709. @Override
  710. public Pagination<BusinessListBo> listAllBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
  711. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  712. }
  713. private Map<String,Object> disposeParams(BusinessListBo blo){
  714. Map<String, Object> params = new HashMap<String, Object>();
  715. if(StringUtils.isNotBlank(blo.getUid())) params.put("uid", blo.getUid());
  716. if(StringUtils.isNotBlank(blo.getAid())) params.put("aid", blo.getAid());
  717. if(StringUtils.isNotBlank(blo.getAdminName())) params.put("adminName", blo.getAdminName());
  718. if(StringUtils.isNotBlank(blo.getBusinessGlossoryId())) params.put("businessGlossoryId", blo.getBusinessGlossoryId());
  719. if(StringUtils.isNotBlank(blo.getStartDate())) params.put("startDate", blo.getStartDate()+" 00:00:00");
  720. if(StringUtils.isNotBlank(blo.getEndDate())) params.put("endDate", blo.getEndDate()+ " 23:59:59");
  721. if(StringUtils.isNotBlank(blo.getIdentifyName())) params.put("identifyName", blo.getIdentifyName());
  722. if(StringUtils.isNoneBlank(blo.getFollowSituation())) params.put("followSituation", blo.getFollowSituation());
  723. if(StringUtils.isNotBlank(blo.getCustomerStatus())) params.put("customerStatus", blo.getCustomerStatus());
  724. return params;
  725. }
  726. @Override
  727. public List<BusinessListBo> findBusinessGlossory() {
  728. return userBusinessMapper.findBusinessGlossory();
  729. }
  730. @Override
  731. public int judgeBusiness(String uid, Integer businessGlossoryId) {
  732. return userBusinessMapper.judgeBusiness(uid,businessGlossoryId,"");
  733. }
  734. @Override
  735. @Transactional
  736. public void addBusinessAndFollow(BussinessFollowBo bfb) throws ParseException {
  737. UserBusiness ub = new UserBusiness();
  738. String ubId = UUID.randomUUID().toString();
  739. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  740. ub.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  741. ub.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  742. ub.setId(ubId);
  743. ub.setUid(bfb.getUid());
  744. ub.setAid(TokenManager.getAdminId());
  745. ub.setRemarks(bfb.getRemarks());
  746. ub.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId()));
  747. ub.setUpdateTime(format.parse(bfb.getCreateTime()));
  748. ub.setCreateTime(format.parse(bfb.getCreateTime()));
  749. userBusinessMapper.insert(ub);
  750. if (StringUtils.isNotBlank(bfb.getOcbId())) { // 跟进联系人不为空则添加跟进记录
  751. UserFollow uf = new UserFollow();
  752. String ufId = UUID.randomUUID().toString();
  753. uf.setId(ufId);
  754. uf.setUid(bfb.getUid());
  755. uf.setCreateTime(format.parse(bfb.getFollowTime()));
  756. uf.setOcbId(bfb.getOcbId());
  757. uf.setResult(bfb.getResult());
  758. uf.setContactType(Integer.parseInt(bfb.getContactType()));
  759. uf.setAid(TokenManager.getAdminId());
  760. uf.setEffective(0);
  761. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  762. uf.setFollowCount(followCount);
  763. userFollowMapper.insert(uf);
  764. UserFollowBusiness ufb = new UserFollowBusiness();
  765. ufb.setId(UUID.randomUUID().toString());
  766. ufb.setBusinessId(ubId);
  767. ufb.setFollowId(ufId);
  768. ufb.setCustomerStatus(ub.getCustomerStatus());
  769. ufb.setFollowSituation(ub.getFollowSituation());
  770. ufb.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId()));
  771. userFollowBusinessMapper.insert(ufb);
  772. }
  773. }
  774. @Override
  775. public List<UserBusiness> findBusinessByUAid(String uid, String aid) {
  776. return userBusinessMapper.findBusinessByUAid(uid,aid);
  777. }
  778. @Override
  779. public BussinessFollowBo findBusinessDetail(String businessId) {
  780. return userBusinessMapper.findBusinessDetail(businessId);
  781. }
  782. @Override
  783. public int updateBusiness(BussinessFollowBo bfb) {
  784. UserBusiness userBusiness = new UserBusiness();
  785. userBusiness.setId(bfb.getBusinessId());
  786. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  787. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  788. userBusiness.setRemarks(bfb.getRemarks());
  789. userBusiness.setUpdateTime(new Date());
  790. return userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  791. }
  792. @Override
  793. @Transactional
  794. public int addFollowOneBusiness(BussinessFollowBo bfb) throws ParseException {
  795. Date updateTime = new Date();
  796. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  797. UserBusiness userBusiness = new UserBusiness();
  798. userBusiness.setId(bfb.getBusinessId());
  799. userBusiness.setUpdateTime(updateTime);
  800. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  801. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  802. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  803. UserFollow userFollow = new UserFollow();
  804. String followId = UUID.randomUUID().toString();
  805. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  806. userFollow.setId(followId);
  807. userFollow.setResult(bfb.getResult());
  808. userFollow.setCreateTime(format.parse(bfb.getFollowTime()));
  809. userFollow.setEffective(0);
  810. userFollow.setOcbId(bfb.getOcbId());
  811. userFollow.setFollowCount(followCount);
  812. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  813. userFollow.setAid(TokenManager.getAdminId());
  814. userFollow.setUid(bfb.getUid());
  815. userFollowMapper.insert(userFollow);
  816. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  817. String ufbId = UUID.randomUUID().toString();
  818. userFollowBusiness.setId(ufbId);
  819. userFollowBusiness.setFollowId(followId);
  820. userFollowBusiness.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId()));
  821. userFollowBusiness.setBusinessId(bfb.getBusinessId());
  822. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  823. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  824. userFollowBusiness.setRemarks(bfb.getRemarks());
  825. userFollowBusinessMapper.insert(userFollowBusiness);
  826. return 1;
  827. }
  828. @Override
  829. public BussinessFollowBo findFollowOneBusiness(String ufbId) {
  830. return userBusinessMapper.findFollowOneBusiness(ufbId);
  831. }
  832. @Override
  833. public int updateFollowOneBusiness(BussinessFollowBo bfb) {
  834. //修改业务跟进中间表
  835. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  836. userFollowBusiness.setId(bfb.getUfbId());
  837. userFollowBusiness.setRemarks(bfb.getRemarks());
  838. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  839. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  840. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness);
  841. //修改跟进记录表
  842. UserFollow userFollow = new UserFollow();
  843. userFollow.setId(bfb.getFollowId());
  844. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  845. userFollow.setResult(bfb.getResult());
  846. if(StringUtils.isNotBlank(bfb.getOcbId())) userFollow.setOcbId(bfb.getOcbId());
  847. userFollowMapper.updateByPrimaryKeySelective(userFollow);
  848. return 1;
  849. }
  850. @Override
  851. public int addOneContact(OrganizationContactBook ocb) {
  852. ocb.setAid(TokenManager.getAdminId());
  853. ocb.setId(UUID.randomUUID().toString());
  854. return organizationContactBookMapper.insert(ocb);
  855. }
  856. @Override
  857. public int deleteBusiness(String businessId) {
  858. return userBusinessMapper.deleteByPrimaryKey(businessId);
  859. }
  860. @Override
  861. public int updateBusinessToStop(String businessId) {
  862. UserBusiness ub = new UserBusiness();
  863. ub.setId(businessId);
  864. ub.setCustomerStatus(CustomerStatusFiled.STATUS_STOP.getCode());
  865. return userBusinessMapper.updateByPrimaryKeySelective(ub);
  866. }
  867. @Override
  868. public int deleteFollowOneBusiness(String ufbId) {
  869. UserFollowBusiness ufb = new UserFollowBusiness();
  870. ufb.setId(ufbId);
  871. return userFollowBusinessMapper.deleteByPrimaryKey(ufbId);
  872. }
  873. @Override
  874. public int deleteOneContact(String ocbId) {
  875. return organizationContactBookMapper.deleteByPrimaryKey(ocbId);
  876. }
  877. @Override
  878. public List<Admin> findAdminName() {
  879. String aid=TokenManager.getAdminId();
  880. return userMapper.findAdminName(aid);
  881. }
  882. @Override
  883. public int updatePersonalCustomerz(CustomerPersonalDetailBo bo) {
  884. UserIdentity ui = new UserIdentity();
  885. User user = new User();
  886. try {
  887. BeanUtilsExt.copyProperties(ui, bo);
  888. user.setId(bo.getUid());
  889. user.setSocietyTag(bo.getSocietyTag());
  890. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  891. user.setIntroduction(bo.getIntroduction());
  892. user.setUpdateTime(new Date());
  893. user.setBusinessAudit(bo.getBusinessAudit());
  894. if(!StringUtils.isBlank(bo.getAid())){
  895. user.setAid(bo.getAid());
  896. user.setShareType(0);
  897. }
  898. } catch (InvocationTargetException | IllegalAccessException e) {
  899. e.printStackTrace();
  900. }
  901. userMapper.updateByPrimaryKeySelective(user);
  902. return 1;
  903. }
  904. }