CustomerServiceImpl.java 55 KB

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