CustomerServiceImpl.java 44 KB

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