CustomerServiceImpl.java 40 KB

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