CustomerServiceImpl.java 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207
  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.ArrayList;
  6. import java.util.Arrays;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.HashSet;
  10. import java.util.List;
  11. import java.util.Map;
  12. import java.util.Set;
  13. import java.util.UUID;
  14. import javax.annotation.Resource;
  15. import org.apache.commons.beanutils.BeanUtils;
  16. import org.apache.commons.beanutils.PropertyUtils;
  17. import org.apache.ibatis.builder.BuilderException;
  18. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.beans.factory.annotation.Value;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import com.goafanti.common.bo.Error;
  24. import com.goafanti.common.bo.userDaysBo;
  25. import com.goafanti.common.constant.AFTConstants;
  26. import com.goafanti.common.constant.ErrorConstants;
  27. import com.goafanti.common.dao.AdminMapper;
  28. import com.goafanti.common.dao.BusinessGlossoryMapper;
  29. import com.goafanti.common.dao.BusinessProjectMapper;
  30. import com.goafanti.common.dao.OrganizationAnnualReportMapper;
  31. import com.goafanti.common.dao.OrganizationApplicationInfoMapper;
  32. import com.goafanti.common.dao.OrganizationBusinessScopeMapper;
  33. import com.goafanti.common.dao.OrganizationContactBookMapper;
  34. import com.goafanti.common.dao.OrganizationIdentityMapper;
  35. import com.goafanti.common.dao.OrganizationSalesTargetMapper;
  36. import com.goafanti.common.dao.OrganizationYearProjectMapper;
  37. import com.goafanti.common.dao.UserBusinessMapper;
  38. import com.goafanti.common.dao.UserChannelMapper;
  39. import com.goafanti.common.dao.UserFollowBusinessMapper;
  40. import com.goafanti.common.dao.UserFollowMapper;
  41. import com.goafanti.common.dao.UserIdentityMapper;
  42. import com.goafanti.common.dao.UserLockReleaseMapper;
  43. import com.goafanti.common.dao.UserMapper;
  44. import com.goafanti.common.dao.UserTransferLogMapper;
  45. import com.goafanti.common.enums.ChannelStatus;
  46. import com.goafanti.common.enums.CustomerStatusFiled;
  47. import com.goafanti.common.enums.DeleteStatus;
  48. import com.goafanti.common.enums.IdentityProcess;
  49. import com.goafanti.common.enums.UserLevel;
  50. import com.goafanti.common.enums.UserLockReleaseStatus;
  51. import com.goafanti.common.enums.UserType;
  52. import com.goafanti.common.error.BusinessException;
  53. import com.goafanti.common.model.Admin;
  54. import com.goafanti.common.model.OrganizationApplicationInfo;
  55. import com.goafanti.common.model.OrganizationBusinessScope;
  56. import com.goafanti.common.model.OrganizationContactBook;
  57. import com.goafanti.common.model.OrganizationIdentity;
  58. import com.goafanti.common.model.OrganizationSalesTarget;
  59. import com.goafanti.common.model.User;
  60. import com.goafanti.common.model.UserBusiness;
  61. import com.goafanti.common.model.UserFollow;
  62. import com.goafanti.common.model.UserFollowBusiness;
  63. import com.goafanti.common.model.UserIdentity;
  64. import com.goafanti.common.model.UserLockRelease;
  65. import com.goafanti.common.model.UserTransferLog;
  66. import com.goafanti.common.utils.BeanUtilsExt;
  67. import com.goafanti.common.utils.DateUtils;
  68. import com.goafanti.common.utils.ExportExcelUtil;
  69. import com.goafanti.common.utils.PasswordUtil;
  70. import com.goafanti.common.utils.StringUtils;
  71. import com.goafanti.core.mybatis.BaseMybatisDao;
  72. import com.goafanti.core.mybatis.page.Pagination;
  73. import com.goafanti.core.shiro.token.TokenManager;
  74. import com.goafanti.customer.bo.BusinessListBo;
  75. import com.goafanti.customer.bo.BussinessFollowBo;
  76. import com.goafanti.customer.bo.CustomerExcelBo;
  77. import com.goafanti.customer.bo.CustomerListIn;
  78. import com.goafanti.customer.bo.CustomerListOut;
  79. import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
  80. import com.goafanti.customer.bo.CustomerPersonalDetailBo;
  81. import com.goafanti.customer.bo.CustomerSimpleBo;
  82. import com.goafanti.customer.bo.FollowBusinessBo;
  83. import com.goafanti.customer.bo.FollowListBo;
  84. import com.goafanti.customer.bo.InputChannelCounts;
  85. import com.goafanti.customer.bo.InputListChannel;
  86. import com.goafanti.customer.bo.LockingReleaseBo;
  87. import com.goafanti.customer.bo.StatisticBo;
  88. import com.goafanti.customer.bo.transferListBo;
  89. import com.goafanti.customer.service.CustomerService;
  90. import com.goafanti.user.bo.OutUserChannel;
  91. @Service
  92. public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements CustomerService {
  93. @Autowired
  94. private UserMapper userMapper;
  95. @Autowired
  96. private UserIdentityMapper userIdentityMapper;
  97. @Autowired
  98. private OrganizationIdentityMapper organizationIdentityMapper;
  99. @Autowired
  100. private OrganizationContactBookMapper organizationContactBookMapper;
  101. @Resource(name = "passwordUtil")
  102. private PasswordUtil passwordUtil;
  103. @Value(value = "${user.receive.max}")
  104. private Integer USER_RECEIVE_MAX = null;
  105. @Value(value = "${user_remind_days}")
  106. private Integer USER_REMIND_DAYS = null;
  107. @Resource
  108. private UserFollowMapper userFollowMapper;
  109. @Resource
  110. private UserBusinessMapper userBusinessMapper;
  111. @Resource
  112. private UserFollowBusinessMapper userFollowBusinessMapper;
  113. @Resource
  114. private BusinessGlossoryMapper businessGlossoryMapper;
  115. @Resource
  116. private BusinessProjectMapper businessProjectMapper;
  117. @Resource
  118. private UserLockReleaseMapper userLockReleaseMapper;
  119. @Resource
  120. private AdminMapper adminMapper;
  121. @Resource
  122. private OrganizationApplicationInfoMapper organizationApplicationInfoMapper;
  123. @Resource
  124. private OrganizationAnnualReportMapper organizationAnnualReportMapper;
  125. @Resource
  126. private OrganizationYearProjectMapper organizationYearProjectMapper;
  127. @Resource
  128. private OrganizationBusinessScopeMapper organizationBusinessScopeMapper;
  129. @Resource
  130. private OrganizationSalesTargetMapper organizationSalesTargetMapper;
  131. @Resource
  132. private UserTransferLogMapper userTransferLogMapper;
  133. @Resource
  134. private UserChannelMapper userChannelMapper;
  135. @Value(value = "${upload.path}")
  136. private String uploadPath = null;
  137. @SuppressWarnings("unchecked")
  138. @Override
  139. public Pagination<CustomerListOut> listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,
  140. Integer pageSize) {
  141. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  142. cli.setAid(TokenManager.getAdminId());
  143. Map<String, Object> params = disposeParams(cli);
  144. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPrivatePersonalCustomerList",
  145. "selectPrivatePersonalCustomerCount", params, pageNo, pageSize);
  146. List<CustomerListOut> tmpList = (List<CustomerListOut>) list.getList();
  147. setCustomerList(tmpList, 0, null);
  148. list.setList(tmpList);
  149. return list;
  150. }
  151. @SuppressWarnings("unchecked")
  152. @Override
  153. public Pagination<CustomerListOut> listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,
  154. Integer pageSize) {
  155. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  156. Map<String, Object> params = disposeParams(cli);
  157. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPublicPersonalCustomerList",
  158. "selectPublicPersonalCustomerCount", params, pageNo, pageSize);
  159. return list;
  160. }
  161. @SuppressWarnings("unchecked")
  162. @Override
  163. public Pagination<CustomerListOut> listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  164. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  165. Map<String, Object> params = disposeParams(cli);
  166. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList",
  167. "selectPersonalCustomerCount", params, pageNo, pageSize);
  168. return list;
  169. }
  170. @SuppressWarnings("unchecked")
  171. @Override
  172. public Pagination<CustomerListOut> listAllManagePersonalCustomer(CustomerListIn cli, Integer pageNo,
  173. Integer pageSize) {
  174. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  175. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  176. Map<String, Object> params = disposeParams(cli);
  177. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManagePersonalCustomerList",
  178. "selectManagePersonalCustomerCount", params, pageNo, pageSize);
  179. return list;
  180. }
  181. @SuppressWarnings("unchecked")
  182. @Override
  183. public Pagination<CustomerListOut> listPrivateOrganizationCustomer(CustomerListIn cli, Integer sort,
  184. Integer sortType, Integer type, Integer pageNo, Integer pageSize) {
  185. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  186. cli.setAid(TokenManager.getAdminId());
  187. // cli.setAid("1");
  188. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  189. Map<String, Object> params = disposeParams(cli);
  190. params.put("sort", sort);
  191. params.put("sortType", sortType);
  192. List<String> alist = new ArrayList<>();
  193. if (type == 0 || TokenManager.hasRole(AFTConstants.SALESMAN)) {
  194. params.put("power", 0);
  195. } else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)) {
  196. params.put("power", 1);
  197. alist = adminMapper.selectBySuperId(cli.getAid());
  198. } else if (TokenManager.hasRole(AFTConstants.SALESMAN_DIRECTOR)) {
  199. params.put("power", 2);
  200. alist = adminMapper.selectBySuperId(cli.getAid());
  201. List<String> alist2 = new ArrayList<>();
  202. if (!alist.isEmpty()) {
  203. for (String string : alist) {
  204. alist2.addAll(adminMapper.selectBySuperId(string));
  205. }
  206. alist.addAll(alist2);
  207. }
  208. } else if (TokenManager.hasRole(AFTConstants.CED)) {
  209. params.put("power", 3);
  210. }
  211. params.put("alist", alist);
  212. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage(
  213. "selectPrivateOrganizationCustomerList", "selectPrivateOrganizationCustomerCount", params, pageNo,
  214. pageSize);
  215. List<CustomerListOut> tmpList = (List<CustomerListOut>) list.getList();
  216. setCustomerList(tmpList, 0, type);
  217. list.setList(tmpList);
  218. return list;
  219. }
  220. @SuppressWarnings("unchecked")
  221. @Override
  222. public Pagination<CustomerListOut> listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,
  223. Integer pageSize) {
  224. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  225. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC));
  226. Map<String, Object> params = disposeParams(cli);
  227. Pagination<CustomerListOut> p = (Pagination<CustomerListOut>) findPage("selectPublicOrganizationCustomerList",
  228. "selectPublicOrganizationCustomerCount", params, pageNo, pageSize);
  229. return p;
  230. }
  231. @SuppressWarnings("unchecked")
  232. @Override
  233. public Pagination<CustomerListOut> listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,
  234. Integer pageSize) {
  235. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  236. Map<String, Object> params = disposeParams(cli);
  237. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  238. params.put("role", 1);
  239. } else {
  240. params.put("role", 0);
  241. }
  242. Pagination<CustomerListOut> p = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList",
  243. "selectOrganizationCustomerCount", params, pageNo, pageSize);
  244. List<CustomerListOut> l = (List<CustomerListOut>) p.getList();
  245. for (CustomerListOut c : l) {
  246. if (null != c) {
  247. if (null != c.getAid())
  248. c.setAdminName(adminMapper.selectNameByid(c.getAid()));
  249. if (null != c.getShareType() && c.getShareType().equals("1"))
  250. c.setAdminName("暂无");
  251. if (null != c.getMid())
  252. c.setInformationMaintainer(adminMapper.selectNameByid(c.getMid()));
  253. }
  254. }
  255. return p;
  256. }
  257. @Override
  258. public Pagination<CustomerListOut> listAllManageOrganizationCustomer(CustomerListIn cli, Integer pageNo,
  259. Integer pageSize) {
  260. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  261. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  262. cli.setAid(TokenManager.getAdminId());
  263. Map<String, Object> params = disposeParams(cli);
  264. @SuppressWarnings("unchecked")
  265. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage(
  266. "selectManageOrganizationCustomerList", "selectManageOrganizationCustomerCount", params, pageNo,
  267. pageSize);
  268. return list;
  269. }
  270. private Map<String, Object> disposeParams(CustomerListIn cli) {
  271. Map<String, Object> params = new HashMap<String, Object>();
  272. if (StringUtils.isNotBlank(cli.getType()))
  273. params.put("type", Integer.parseInt(cli.getType()));
  274. if (StringUtils.isNotBlank(cli.getShareType()))
  275. params.put("shareType", Integer.parseInt(cli.getShareType()));
  276. if (StringUtils.isNotBlank(cli.getName()))
  277. params.put("name", cli.getName());
  278. if (StringUtils.isNotBlank(cli.getProvince()))
  279. params.put("province", Integer.parseInt(cli.getProvince()));
  280. if (StringUtils.isNotBlank(cli.getCity()))
  281. params.put("city", Integer.parseInt(cli.getCity()));
  282. if (StringUtils.isNotBlank(cli.getArea()))
  283. params.put("area", Integer.parseInt(cli.getArea()));
  284. if (StringUtils.isNotBlank(cli.getStartDate()))
  285. params.put("startDate", cli.getStartDate());
  286. if (StringUtils.isNotBlank(cli.getEndDate()))
  287. params.put("endDate", cli.getEndDate());
  288. if (StringUtils.isNotBlank(cli.getIndustry()))
  289. params.put("industry", Integer.parseInt(cli.getIndustry()));
  290. if (StringUtils.isNotBlank(cli.getAid()))
  291. params.put("aid", cli.getAid());
  292. if (StringUtils.isNotBlank(cli.getDepartmentId()))
  293. params.put("departmentId", cli.getDepartmentId());
  294. if (StringUtils.isNotBlank(cli.getStatus()))
  295. params.put("status", Integer.parseInt(cli.getStatus()));
  296. if (StringUtils.isNotBlank(cli.getSocietyTag()))
  297. params.put("societyTag", cli.getSocietyTag());
  298. if (StringUtils.isNotBlank(cli.getFollow()))
  299. params.put("follow", cli.getFollow());
  300. if (StringUtils.isNotBlank(cli.getStartDate()))
  301. params.put("startDate", cli.getStartDate() + " 00:00:00");
  302. if (StringUtils.isNotBlank(cli.getEndDate()))
  303. params.put("endDate", cli.getEndDate() + " 23:59:59");
  304. if (null != cli.getDataGrade())
  305. params.put("dataGrade", cli.getDataGrade());
  306. if (null != cli.getLevel())
  307. params.put("level", cli.getLevel());
  308. if (null != cli.getSort())
  309. params.put("sort", cli.getSort());
  310. if (null != cli.getChannel())
  311. params.put("channel", cli.getChannel());
  312. return params;
  313. }
  314. @Override
  315. public List<CustomerSimpleBo> findCustomerByName(String name) {
  316. return userMapper.findCustomerByName(name);
  317. }
  318. @Override
  319. public int judgeCustomerByName(String name) {
  320. return userMapper.judgeCustomerByName(name);
  321. }
  322. @Override
  323. @Transactional
  324. public int addCustomer(String name, String contacts, String contactMobile, Integer type, Integer source,
  325. String societyTag, Integer province, Integer city, Integer area) throws BusinessException {
  326. User user = new User();
  327. Date now = new Date();
  328. String uid = UUID.randomUUID().toString();
  329. String identifyId = UUID.randomUUID().toString();
  330. user.setId(uid);
  331. user.setIdentifyName(name);
  332. user.setSource(1);// 客户来源为录入
  333. user.setNickname(name);
  334. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  335. user.setShareType(AFTConstants.NO);
  336. user.setAid(TokenManager.getAdminId());
  337. // user.setAid("1");
  338. user.setType(type);
  339. user.setLvl(UserLevel.CERTIFIED.getCode());
  340. user.setSocietyTag(societyTag);
  341. user.setCreateTime(now);
  342. user.setTransferTime(now);
  343. user.setUpdateTime(now);
  344. user.setMobile(contactMobile);
  345. user.setPassword(AFTConstants.INITIALPASSWORD);
  346. user.setInformationMaintainer(TokenManager.getAdminId());
  347. float f = 0;
  348. user.setIntegrity(f);
  349. // user.setInformationMaintainer("1");
  350. passwordUtil.encryptPassword(user);
  351. if (type == UserType.PERSONAL.getCode()) {
  352. if (userMapper.checkUser("", "", contactMobile, type, null, null).size() > 0)
  353. throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name, ""));
  354. UserIdentity ui = new UserIdentity();
  355. ui.setId(identifyId);
  356. ui.setUid(uid);
  357. ui.setContacts(contacts);
  358. ui.setContactMobile(contactMobile);
  359. ui.setUsername(name);
  360. ui.setProvince(province);
  361. ui.setCity(city);
  362. ui.setArea(area);
  363. ui.setExpert(AFTConstants.NO);
  364. ui.setCelebrity(AFTConstants.NO);
  365. ui.setInternational(AFTConstants.NO);
  366. ui.setAuditStatus(IdentityProcess.SUCCESS.getCode());// 认证个人
  367. userIdentityMapper.insert(ui);
  368. } else if (type == UserType.ORGANIZATION.getCode()) {
  369. if (userMapper.checkUser("", name, "", type, null, null).size() > 0)
  370. throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name, ""));
  371. // 创建企业认证信息
  372. OrganizationIdentity oi = new OrganizationIdentity();
  373. oi.setUnitName(name);
  374. oi.setId(identifyId);
  375. oi.setUid(uid);
  376. oi.setContacts(contacts);
  377. oi.setContactMobile(contactMobile);
  378. oi.setLocationProvince(province);
  379. oi.setLocationCity(city);
  380. oi.setLocationArea(area);
  381. oi.setHighTechZone(AFTConstants.NO);
  382. oi.setInternational(AFTConstants.NO);
  383. oi.setListed(AFTConstants.NO);
  384. oi.setAuditStatus(IdentityProcess.SUCCESS.getCode()); // 实名企业
  385. organizationIdentityMapper.insert(oi);
  386. }
  387. userMapper.insert(user);
  388. // 新增企业联系人
  389. OrganizationContactBook cob = new OrganizationContactBook();
  390. cob.setAid(TokenManager.getAdminId());
  391. cob.setAname(adminMapper.selectByPrimaryKey(TokenManager.getAdminId()).getName());
  392. cob.setId(UUID.randomUUID().toString());
  393. cob.setUid(uid);
  394. cob.setName(contacts);
  395. cob.setMobile(contactMobile);
  396. cob.setMajor(AFTConstants.YES);
  397. organizationContactBookMapper.insert(cob);
  398. // 新增锁定数据
  399. boolean isUs = false;
  400. if (uid.contains(",")) {
  401. isUs = true;
  402. }
  403. List<String> uList = new ArrayList<>();
  404. if (isUs) {
  405. uList = Arrays.asList(uid.split(","));
  406. }
  407. addUserLock(uid, TokenManager.getAdminId(), now, uList);
  408. addUserTransferLog(uid, TokenManager.getAdminId(), 0, null, now, uList);
  409. return 1;
  410. }
  411. @Override
  412. public CustomerPersonalDetailBo findPersonalCustomerDetail(String uid) {
  413. return userMapper.findPersonalCustomerDetail(uid);
  414. }
  415. @Override
  416. public CustomerOrganizationDetailBo findOrganizationCustomerDetail(String uid) {
  417. return userMapper.findOrganizationCustomerDetail(uid);
  418. }
  419. @Override
  420. @Transactional
  421. public int updateOrganizationCustomer(CustomerOrganizationDetailBo bo) {
  422. OrganizationIdentity oi = new OrganizationIdentity();
  423. User user = new User();
  424. Date date = new Date();
  425. OrganizationApplicationInfo oa = new OrganizationApplicationInfo();
  426. try {
  427. BeanUtilsExt.copyProperties(oi, bo);
  428. user.setId(bo.getUid());
  429. user.setSocietyTag(bo.getSocietyTag());
  430. user.setCompanyLogoUrl(bo.getCompanyLogoUrl());
  431. user.setIntroduction(bo.getIntroduction());
  432. user.setUpdateTime(date);
  433. user.setInformationMaintainer(bo.getInformationMaintainer());
  434. user.setCoreTechnology(bo.getCoreTechnology());
  435. user.setAccomplishSituation(bo.getAccomplishSituation());
  436. user.setIntellectualProperty(bo.getIntellectualProperty());
  437. user.setCreditRating(bo.getCreditRating());
  438. user.setIntegrity(countIntegrity(bo));
  439. if (StringUtils.isNotBlank(bo.getPojectApplicationUrl())) {
  440. List<OrganizationApplicationInfo> l = organizationApplicationInfoMapper.selectByUid(bo.getUid());
  441. if (l.size() > 0) {
  442. oa = l.get(0);
  443. oa.setPojectApplicationUrl(bo.getPojectApplicationUrl());
  444. organizationApplicationInfoMapper.updateByPrimaryKey(oa);
  445. } else {
  446. oa.setId(UUID.randomUUID().toString());
  447. oa.setCreateTime(date);
  448. oa.setUid(bo.getUid());
  449. oa.setPojectApplicationUrl(bo.getPojectApplicationUrl());
  450. organizationApplicationInfoMapper.insert(oa);
  451. }
  452. }
  453. } catch (IllegalAccessException | InvocationTargetException e) {
  454. e.printStackTrace();
  455. }
  456. organizationBusinessScopeMapper.deleteByUid(bo.getUid());
  457. if (bo.getBusinessScope() != null) {
  458. if (bo.getBusinessScope().contains(",")) {
  459. String[] ss = bo.getBusinessScope().split(",");
  460. List<OrganizationBusinessScope> list = new ArrayList<>();
  461. for (int i = 0; i < ss.length; i++) {
  462. String string = ss[i];
  463. OrganizationBusinessScope obs = new OrganizationBusinessScope();
  464. obs.setUid(bo.getUid());
  465. obs.setKeyword(string);
  466. list.add(obs);
  467. }
  468. organizationBusinessScopeMapper.insertBatch(list);
  469. } else {
  470. OrganizationBusinessScope obs = new OrganizationBusinessScope();
  471. obs.setUid(bo.getUid());
  472. obs.setKeyword(bo.getBusinessScope());
  473. organizationBusinessScopeMapper.insertSelective(obs);
  474. }
  475. }
  476. organizationSalesTargetMapper.deleteByUid(bo.getUid());
  477. if (bo.getSalesTarget() != null) {
  478. if (bo.getSalesTarget().contains(",")) {
  479. String[] ss = bo.getSalesTarget().split(",");
  480. List<OrganizationSalesTarget> list = new ArrayList<>();
  481. for (int i = 0; i < ss.length; i++) {
  482. String string = ss[i];
  483. OrganizationSalesTarget obs = new OrganizationSalesTarget();
  484. obs.setUid(bo.getUid());
  485. obs.setKeyword(string);
  486. list.add(obs);
  487. }
  488. organizationSalesTargetMapper.insertBatch(list);
  489. } else {
  490. OrganizationSalesTarget obs = new OrganizationSalesTarget();
  491. obs.setUid(bo.getUid());
  492. obs.setKeyword(bo.getSalesTarget());
  493. organizationSalesTargetMapper.insertSelective(obs);
  494. }
  495. }
  496. organizationIdentityMapper.updateByPrimaryKey(oi);
  497. userMapper.updateByPrimaryKeySelective(user);
  498. return 1;
  499. }
  500. public Float countIntegrity(CustomerOrganizationDetailBo bo) {
  501. // 完整资料总数
  502. int max = 10;
  503. int number = 0;
  504. if (null != bo.getIndustry())
  505. number += 1;
  506. if (bo.getLocationProvince() != null)
  507. number += 1;
  508. if (StringUtils.isNotBlank(bo.getBusinessScope()))
  509. number += 1;
  510. if (bo.getRegisteredCapital() != null)
  511. number += 1;
  512. if (StringUtils.isNotBlank(bo.getCooperationSituation()))
  513. number += 1;
  514. if (StringUtils.isNotBlank(bo.getQualification()))
  515. number += 1;
  516. if (organizationAnnualReportMapper.selectOrgAnnualCount(bo.getUid()) > 0)
  517. number += 1;
  518. if (organizationAnnualReportMapper.selectOrgYearProjectCount(bo.getUid()) > 0)
  519. number += 1;
  520. if (StringUtils.isNotBlank(bo.getCoreTechnology()))
  521. number += 1;
  522. if (bo.getCreditRating() != null)
  523. number += 1;
  524. float f = (float) number / max;
  525. return f;
  526. }
  527. @Override
  528. public int updatePersonalCustomer(CustomerPersonalDetailBo bo) {
  529. UserIdentity ui = new UserIdentity();
  530. User user = new User();
  531. try {
  532. try {
  533. PropertyUtils.copyProperties(ui, bo);
  534. } catch (NoSuchMethodException e) {
  535. e.printStackTrace();
  536. }
  537. user.setId(bo.getUid());
  538. user.setSocietyTag(bo.getSocietyTag());
  539. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  540. user.setIntroduction(bo.getIntroduction());
  541. user.setUpdateTime(new Date());
  542. if (null == bo.getExpertAudit() && bo.getExpert() == 1)
  543. ui.setExpertAudit(2);
  544. } catch (InvocationTargetException | IllegalAccessException e) {
  545. e.printStackTrace();
  546. }
  547. userIdentityMapper.updateByPrimaryKeySelective(ui);
  548. userMapper.updateByPrimaryKeySelective(user);
  549. return 1;
  550. }
  551. @SuppressWarnings("unchecked")
  552. @Override
  553. public Pagination<FollowListBo> listFollowHistory(Integer pageNo, Integer pageSize, String uid,
  554. String businessProjectId, Integer type) {
  555. Map<String, Object> params = new HashMap<String, Object>();
  556. if (StringUtils.isNotBlank(uid))
  557. params.put("uid", uid);
  558. if (StringUtils.isNotBlank(businessProjectId))
  559. params.put("businessProjectId", businessProjectId);
  560. Pagination<FollowListBo> page = (Pagination<FollowListBo>) findPage("selectFollowHistoryList",
  561. "selectFollowHistoryCount", params, pageNo, pageSize);
  562. List<FollowListBo> list = (List<FollowListBo>) page.getList();
  563. for (FollowListBo bo : list) {
  564. if (bo.getAid().equals(TokenManager.getAdminId())) {
  565. bo.setReadOnly(AFTConstants.NO);
  566. } else {
  567. bo.setContactMobile("***");
  568. bo.setContacts("***");
  569. bo.setReadOnly(AFTConstants.YES);
  570. }
  571. }
  572. page.setList(list);
  573. return page;
  574. }
  575. /**
  576. * 推动指导已读
  577. *
  578. * @param uid
  579. */
  580. @Override
  581. public int pushGuidance(String uid) {
  582. User u = userMapper.findUserAccountDetail(uid);
  583. if (u != null && u.getGuidance() != 0) {
  584. return userMapper.pushUserGuidance(uid, 2);
  585. }
  586. return 0;
  587. }
  588. @Override
  589. public User findUserAccountDetail(String uid) {
  590. return userMapper.findUserAccountDetail(uid);
  591. }
  592. @Override
  593. public int updateUserAccount(User user) {
  594. return userMapper.updateByPrimaryKeySelective(user);
  595. }
  596. @Override
  597. public List<OrganizationContactBook> findCustomerContacts(String uid) {
  598. List<OrganizationContactBook> list = userMapper.findCustomerContacts(uid, TokenManager.getAdminId());
  599. return list;
  600. }
  601. @Override
  602. @Transactional
  603. public int addFollow(FollowBusinessBo fbb,String ufid) throws BusinessException {
  604. // 更新跟进记录表
  605. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  606. UserFollow userFollow = new UserFollow();
  607. String followId = ufid==null?UUID.randomUUID().toString():ufid;
  608. userFollow.setId(followId);
  609. userFollow.setAid(TokenManager.getAdminId());
  610. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  611. userFollow.setEffective(DeleteStatus.UNDELETE.getCode());
  612. try {
  613. userFollow.setCreateTime(format.parse(fbb.getFollowTime()));
  614. } catch (ParseException e) {
  615. e.printStackTrace();
  616. }
  617. userFollow.setOcbId(fbb.getOcbId());
  618. userFollow.setResult(fbb.getResult());
  619. userFollow.setUid(fbb.getUid());
  620. int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), TokenManager.getAdminId()) + 1;
  621. userFollow.setFollowCount(followCount);
  622. userFollowMapper.insert(userFollow);
  623. // 判断是跟进还是签单
  624. int x = 0;
  625. // 检查客户锁定情况
  626. if (fbb.getUserBusinessList()!=null&&fbb.getUserBusinessList().size() > 0) {
  627. boolean isUserOwner = false;
  628. List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(),
  629. TokenManager.getAdminId(), null, 0, UserLockReleaseStatus.LOCKED.getCode());
  630. if (userLockedList.size() > 0) {
  631. isUserOwner = true;
  632. }
  633. boolean isBusinessOwner = false;
  634. List<LockingReleaseBo> businessLockedList = null;
  635. String businessName = "";
  636. String ufbId = "";
  637. UserBusiness userBusiness = null;
  638. UserFollowBusiness userFollowBusiness = null;
  639. for (BusinessListBo ub : fbb.getUserBusinessList()) {
  640. userBusiness = new UserBusiness();
  641. userFollowBusiness = new UserFollowBusiness();
  642. ufbId = UUID.randomUUID().toString();
  643. businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
  644. UserBusiness us = userBusinessMapper.selectByPrimaryKey(ub.getBusinessId());
  645. if (StringUtils.isNotBlank(ub.getBusinessId())) {
  646. // 更新业务表
  647. userBusiness.setId(ub.getBusinessId());
  648. if (us.getFollowSituation() == 5) {// 如果已签合同,则不允许变更
  649. if (ub.getCustomerStatus() != us.getCustomerStatus() && ub.getFollowSituation() != 5) {
  650. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, ""));
  651. }
  652. }
  653. // 检查业务锁定情况
  654. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(),
  655. 1, UserLockReleaseStatus.LOCKED.getCode());
  656. if (businessLockedList.size() > 0) {
  657. for (LockingReleaseBo bo : businessLockedList) {
  658. if (bo.getAid().equals(TokenManager.getAdminId()))
  659. isBusinessOwner = true;
  660. }
  661. if (!isBusinessOwner)
  662. throw new BusinessException(
  663. new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, businessName, ""));
  664. } else {
  665. if (!isUserOwner)
  666. throw new BusinessException(
  667. new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED, businessName, ""));
  668. }
  669. // if (us.getFollowSituation()!=5&&ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
  670. // if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
  671. // lockProject(ub);//锁定客户业务
  672. // x=1;
  673. // }
  674. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  675. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  676. userBusiness.setFollowSituation(ub.getFollowSituation());
  677. userBusiness.setRemarks(ub.getRemarks());
  678. userBusiness.setUid(fbb.getUid());
  679. try {
  680. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  681. } catch (ParseException e) {
  682. e.printStackTrace();
  683. }
  684. userBusiness.setAid(TokenManager.getAdminId());
  685. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  686. // 更新业务中间表
  687. userFollowBusiness.setBusinessId(ub.getBusinessProjectId());
  688. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  689. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  690. userFollowBusiness.setId(ufbId);
  691. userFollowBusiness.setFollowId(followId);
  692. userFollowBusiness.setRemarks(ub.getRemarks());
  693. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  694. userFollowBusinessMapper.insert(userFollowBusiness);
  695. } else {
  696. // 检查业务锁定情况
  697. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(),
  698. 1, UserLockReleaseStatus.LOCKED.getCode());
  699. if (businessLockedList.size() > 0) {
  700. for (LockingReleaseBo bo : businessLockedList) {
  701. if (bo.getAid().equals(TokenManager.getAdminId()))
  702. isBusinessOwner = true;
  703. }
  704. if (!isBusinessOwner)
  705. throw new BusinessException(
  706. new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, businessName, ""));
  707. } else {
  708. if (!isUserOwner)
  709. throw new BusinessException(
  710. new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED, businessName, ""));
  711. }
  712. if (userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "") > 0) {
  713. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST, businessName, ""));
  714. }
  715. // if (ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
  716. // if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
  717. // lockProject(ub);//锁定客户业务
  718. // x=1;
  719. // }
  720. String ubId = UUID.randomUUID().toString();
  721. // 更新业务表
  722. userBusiness.setId(ubId);
  723. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  724. try {
  725. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  726. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  727. } catch (ParseException e) {
  728. e.printStackTrace();
  729. }
  730. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  731. userBusiness.setFollowSituation(ub.getFollowSituation());
  732. userBusiness.setUid(fbb.getUid());
  733. userBusiness.setAid(TokenManager.getAdminId());
  734. userBusiness.setRemarks(ub.getRemarks());
  735. userBusinessMapper.insert(userBusiness);
  736. // 更新业务中间表
  737. userFollowBusiness.setBusinessId(ubId);
  738. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  739. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  740. userFollowBusiness.setId(ufbId);
  741. userFollowBusiness.setFollowId(followId);
  742. userFollowBusiness.setRemarks(ub.getRemarks());
  743. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  744. userFollowBusinessMapper.insert(userFollowBusiness);
  745. }
  746. }
  747. }
  748. followProject(fbb.getUid(), x);
  749. return 1;
  750. }
  751. /**
  752. * 跟进更新用户中间表
  753. *
  754. * @param ub
  755. */
  756. private void followProject(String uid, int x) {
  757. Date date = new Date();
  758. String aid = TokenManager.getAdminId();
  759. if (x == 0) {
  760. if (userLockReleaseMapper.updateUserMid(uid, aid, date, null) < 1) {
  761. userLockReleaseMapper.insertUserMid(uid, aid, date, null);
  762. }
  763. } else {
  764. if (userLockReleaseMapper.updateUserMid(uid, aid, date, date) < 1) {
  765. userLockReleaseMapper.insertUserMid(uid, aid, date, date);
  766. }
  767. }
  768. }
  769. @SuppressWarnings("unused")
  770. private void releaseProject(List<LockingReleaseBo> businessLockedList) {
  771. if (businessLockedList != null && businessLockedList.size() > 0) {
  772. UserLockRelease ulr = null;
  773. for (LockingReleaseBo bo : businessLockedList) {
  774. ulr = new UserLockRelease();
  775. ulr.setId(bo.getId());
  776. ulr.setStatus(UserLockReleaseStatus.RELEASE.getCode());
  777. userLockReleaseMapper.updateByPrimaryKeySelective(ulr);
  778. }
  779. }
  780. }
  781. @Override
  782. public FollowBusinessBo findFollowById(String followId) {
  783. return userMapper.findFollowById(followId);
  784. }
  785. @Override
  786. public List<BusinessListBo> findBusinessByFollowId(String followId) {
  787. return userMapper.findBusinessByFollowId(followId);
  788. }
  789. @Override
  790. @Transactional
  791. public int updateFollow(FollowBusinessBo fbb) throws BusinessException {
  792. UserFollow userFollow = new UserFollow();
  793. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  794. userFollow.setId(fbb.getFollowId());
  795. if (StringUtils.isNotBlank(fbb.getOcbId()))
  796. userFollow.setOcbId(fbb.getOcbId());
  797. userFollow.setResult(fbb.getResult());
  798. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  799. userFollowMapper.updateByPrimaryKeySelective(userFollow); // 修改拜访记录表
  800. if (fbb.getUserBusinessList().size() > 0) {
  801. // 检查客户锁定情况
  802. boolean isUserOwner = false;
  803. List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(),
  804. TokenManager.getAdminId(), null, 0, UserLockReleaseStatus.LOCKED.getCode());
  805. if (userLockedList.size() > 0) {
  806. isUserOwner = true;
  807. }
  808. boolean isBusinessOwner = false;
  809. List<LockingReleaseBo> businessLockedList = null;
  810. String businessName = "";
  811. UserFollowBusiness userFollowBusiness = null;
  812. for (BusinessListBo ub : fbb.getUserBusinessList()) {
  813. userFollowBusiness = new UserFollowBusiness();
  814. businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
  815. if (StringUtils.isNotBlank(ub.getUfbId())) {
  816. userFollowBusiness.setId(ub.getUfbId());
  817. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  818. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  819. userFollowBusiness.setRemarks(ub.getRemarks());
  820. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); // 修改拜访记录中间表
  821. } else {
  822. // 检查业务锁定情况
  823. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(),
  824. 1, UserLockReleaseStatus.LOCKED.getCode());
  825. if (businessLockedList.size() > 0) {
  826. for (LockingReleaseBo bo : businessLockedList) {
  827. if (bo.getAid().equals(TokenManager.getAdminId()))
  828. isBusinessOwner = true;
  829. }
  830. if (!isBusinessOwner)
  831. throw new BusinessException(
  832. new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, businessName, ""));
  833. } else {
  834. if (!isUserOwner)
  835. throw new BusinessException(
  836. new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED, businessName, ""));
  837. }
  838. if (userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "") > 0) {
  839. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST, businessName, ""));
  840. }
  841. String ubId = UUID.randomUUID().toString();
  842. UserBusiness userBusiness = new UserBusiness();
  843. // 更新业务表
  844. userBusiness.setId(ubId);
  845. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  846. try {
  847. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  848. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  849. } catch (ParseException e) {
  850. e.printStackTrace();
  851. }
  852. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  853. userBusiness.setFollowSituation(ub.getFollowSituation());
  854. userBusiness.setUid(fbb.getUid());
  855. userBusiness.setAid(TokenManager.getAdminId());
  856. userBusinessMapper.insert(userBusiness);
  857. // 更新业务中间表
  858. String ufbId = UUID.randomUUID().toString();
  859. userFollowBusiness.setId(ufbId);
  860. userFollowBusiness.setFollowId(fbb.getFollowId());
  861. userFollowBusiness.setBusinessId(ubId);
  862. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  863. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  864. userFollowBusiness.setRemarks(ub.getRemarks());
  865. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  866. userFollowBusinessMapper.insert(userFollowBusiness);
  867. }
  868. }
  869. }
  870. return 1;
  871. }
  872. @Override
  873. public Set<OrganizationContactBook> findAllContacts(String uid) {
  874. Set<OrganizationContactBook> result = new HashSet<OrganizationContactBook>();
  875. result.addAll(userMapper.findAllContacts(uid));
  876. return result;
  877. }
  878. @Override
  879. public int updateCustomerContacts(List<OrganizationContactBook> ocbList, String uid) {
  880. if (ocbList.size() > 0) {
  881. OrganizationContactBook ocb = null;
  882. for (OrganizationContactBook item : ocbList) {
  883. if (item != null && item.getMajor() != null && item.getMajor() == 1) {
  884. // 改变用户原本的联系人
  885. OrganizationIdentity oi = new OrganizationIdentity();
  886. oi.setContacts(item.getName());
  887. oi.setContactMobile(item.getMobile());
  888. oi.setUid(uid);
  889. organizationIdentityMapper.updateServiceByUid(oi);
  890. }
  891. ocb = new OrganizationContactBook();
  892. try {
  893. BeanUtils.copyProperties(ocb, item);
  894. if (StringUtils.isBlank(ocb.getId())) {
  895. ocb.setId(UUID.randomUUID().toString());
  896. ocb.setUid(uid);
  897. ocb.setAid(TokenManager.getAdminId());
  898. Admin ad = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  899. ocb.setAname(ad.getName());
  900. organizationContactBookMapper.insert(ocb);
  901. } else {
  902. organizationContactBookMapper.updateByPrimaryKeySelective(ocb);
  903. }
  904. } catch (IllegalAccessException | InvocationTargetException e) {
  905. e.printStackTrace();
  906. }
  907. }
  908. }
  909. return 1;
  910. }
  911. @Override
  912. public int deleteFollow(String followId) {
  913. UserFollow uf = new UserFollow();
  914. List<BusinessListBo> list = userMapper.findBusinessByFollowId(followId);
  915. for (BusinessListBo b : list) {
  916. if (b.getFollowSituation() == 5)
  917. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, ""));
  918. ;
  919. }
  920. uf.setId(followId);
  921. uf.setEffective(DeleteStatus.DELETED.getCode());
  922. return userFollowMapper.updateByPrimaryKeySelective(uf);
  923. }
  924. @Override
  925. public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows, Set<Integer> filterRows) {
  926. List<User> list = null;
  927. CustomerExcelBo[] bos = (CustomerExcelBo[]) boSet.toArray(new CustomerExcelBo[] {});
  928. for (int i = 0; i < bos.length; i++) {
  929. CustomerExcelBo bo = bos[i];
  930. CustomerExcelBo ceb = null;
  931. for (int j = 0; j < i; j++) {
  932. ceb = bos[j];
  933. if (bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)) { // 个人
  934. if (ceb.getMobile().equals(bo.getMobile()) && ceb.getCustomerType().equals(bo.getCustomerType())) {
  935. bo.setUid(ceb.getUid());
  936. bo.setNewData(false);
  937. filterRows.add(bo.getRowNumber());
  938. break;
  939. }
  940. } else if (bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)) { // 单位
  941. if (ceb.getIdentifyName().equals(bo.getIdentifyName())
  942. && ceb.getCustomerType().equals(bo.getCustomerType())) {
  943. bo.setUid(ceb.getUid());
  944. bo.setNewData(false);
  945. filterRows.add(bo.getRowNumber());
  946. break;
  947. }
  948. }
  949. }
  950. if (StringUtils.isBlank(bo.getUid())) { // 是否已经存在
  951. if (bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)) {
  952. list = userMapper.checkUser("", "", bo.getMobile(), Integer.parseInt(bo.getCustomerType()), null,
  953. null);
  954. } else if (bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)) {
  955. list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()),
  956. null, null);
  957. }
  958. if (list.size() > 0) {
  959. bo.setUid(list.get(0).getId());
  960. bo.setNewData(false);
  961. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,
  962. bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  963. if (businessLockedList.size() > 0) {
  964. existRows.add(bo.getRowNumber());
  965. }
  966. } else {
  967. bo.setUid(UUID.randomUUID().toString());
  968. bo.setNewData(true);
  969. }
  970. } else {
  971. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,
  972. bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  973. if (businessLockedList.size() > 0) {
  974. existRows.add(bo.getRowNumber());
  975. }
  976. }
  977. }
  978. }
  979. @Override
  980. @Transactional
  981. public int saveUploadData(Set<CustomerExcelBo> boSet) {
  982. Date now = new Date();
  983. String uid = "";
  984. for (CustomerExcelBo bo : boSet) {
  985. uid = bo.getUid();
  986. if (bo.isNewData()) { // 新建客户
  987. createUser(bo, uid, now);
  988. createIdentity(bo, bo.getCustomerType(), uid);
  989. createBusiness(bo, uid, now);
  990. createContacts(bo, uid);
  991. } else { // 新建业务
  992. createBusiness(bo, uid, now);
  993. if (organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId()) <= 0) {
  994. createContacts(bo, uid);
  995. }
  996. }
  997. }
  998. return 1;
  999. }
  1000. private void createUser(CustomerExcelBo bo, String uid, Date now) {
  1001. User user = new User();
  1002. user.setId(uid);
  1003. user.setIdentifyName(bo.getIdentifyName());
  1004. user.setSource(AFTConstants.USER_SOURCE_CREATE);
  1005. user.setNickname(bo.getIdentifyName());
  1006. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  1007. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  1008. user.setAid(TokenManager.getAdminId());
  1009. user.setType(Integer.parseInt(bo.getCustomerType()));
  1010. user.setLvl(UserLevel.CERTIFIED.getCode());
  1011. user.setCreateTime(now);
  1012. user.setUpdateTime(now);
  1013. user.setMobile(bo.getMobile());
  1014. user.setPassword(AFTConstants.INITIALPASSWORD);
  1015. passwordUtil.encryptPassword(user);
  1016. userMapper.insert(user);
  1017. }
  1018. private void createIdentity(CustomerExcelBo bo, String type, String uid) {
  1019. String identifyId = UUID.randomUUID().toString();
  1020. if (type.equals(AFTConstants.USER_TYPE_PERSONAL)) {
  1021. // 新增个人认证信息
  1022. UserIdentity ui = new UserIdentity();
  1023. ui.setId(identifyId);
  1024. ui.setUid(uid);
  1025. ui.setContacts(bo.getContacts());
  1026. ui.setContactMobile(bo.getMobile());
  1027. ui.setUsername(bo.getIdentifyName());
  1028. ui.setExpert(AFTConstants.NO);
  1029. ui.setCelebrity(AFTConstants.NO);
  1030. ui.setInternational(AFTConstants.NO);
  1031. ui.setAuditStatus(5);
  1032. userIdentityMapper.insert(ui);
  1033. } else if (type.equals(AFTConstants.USER_TYPE_ORGANIZATION)) {
  1034. // 创建企业认证信息
  1035. OrganizationIdentity oi = new OrganizationIdentity();
  1036. oi.setId(identifyId);
  1037. oi.setUnitName(bo.getIdentifyName());
  1038. oi.setUid(uid);
  1039. oi.setContacts(bo.getContacts());
  1040. oi.setContactMobile(bo.getMobile());
  1041. oi.setHighTechZone(AFTConstants.NO);
  1042. oi.setInternational(AFTConstants.NO);
  1043. oi.setListed(AFTConstants.NO);
  1044. oi.setAuditStatus(5); // 实名企业
  1045. organizationIdentityMapper.insert(oi);
  1046. }
  1047. }
  1048. private void createContacts(CustomerExcelBo bo, String uid) {
  1049. // 新增企业联系人
  1050. OrganizationContactBook cob = new OrganizationContactBook();
  1051. cob.setAid(TokenManager.getAdminId());
  1052. cob.setId(UUID.randomUUID().toString());
  1053. cob.setUid(uid);
  1054. cob.setName(bo.getContacts());
  1055. cob.setMobile(bo.getMobile());
  1056. cob.setMajor(AFTConstants.NO);
  1057. organizationContactBookMapper.insert(cob);
  1058. }
  1059. private void createBusiness(CustomerExcelBo bo, String uid, Date now) {
  1060. // 新增业务
  1061. UserBusiness ub = new UserBusiness();
  1062. ub.setId(UUID.randomUUID().toString());
  1063. ub.setAid(TokenManager.getAdminId());
  1064. ub.setBusinessProjectId(bo.getBusinessProjectId());
  1065. ub.setUid(uid);
  1066. ub.setCreateTime(now);
  1067. ub.setUpdateTime(now);
  1068. ub.setCustomerStatus(Integer.parseInt(bo.getCustomerStatus()));
  1069. ub.setFollowSituation(Integer.parseInt(bo.getFollowSituation()));
  1070. userBusinessMapper.insert(ub);
  1071. }
  1072. @Override
  1073. public int updateByOperatorType(String uid, String oldAid, Integer operatorType, Object... params) {
  1074. User user = new User();
  1075. Date now = new Date();
  1076. // 是否多个客户
  1077. boolean isUs = false;
  1078. if (uid.contains(",")) {
  1079. isUs = true;
  1080. }
  1081. List<String> uList = new ArrayList<>();
  1082. if (isUs) {
  1083. uList = Arrays.asList(uid.split(","));
  1084. }
  1085. user.setId(uid);
  1086. int flag = 0;
  1087. if (AFTConstants.USER_RECEIVE.equals(operatorType)) {
  1088. if (userMapper.UserReceiveCount(TokenManager.getAdminId()) >= USER_RECEIVE_MAX)
  1089. throw new BusinessException(new Error(ErrorConstants.CUSTOM_EREXCESS, "" + USER_RECEIVE_MAX, ""));
  1090. user.setAid(TokenManager.getAdminId());
  1091. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  1092. user.setInformationMaintainer(TokenManager.getAdminId());
  1093. user.setSource(2);// 客户来源设置为领取
  1094. user.setTransferTime(now);
  1095. flag = addUserLock(uid, TokenManager.getAdminId(), now, uList); // 指定用户锁定客户
  1096. addUserTransferLog(uid, TokenManager.getAdminId(), 1, null, now, uList);
  1097. if (flag <= 0)
  1098. throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_RECEIVE, ""));
  1099. } else if (AFTConstants.USER_TRANSFER_TO_OTHER.equals(operatorType)
  1100. || AFTConstants.SIGN_USER_TRANSFER_TO_OTHER == operatorType) {
  1101. if (!isUs) {
  1102. user.setAid(String.valueOf(params[0]));
  1103. user.setSource(3);// 客户来源设置为转交
  1104. if (AFTConstants.USER_TRANSFER_TO_OTHER == operatorType) {
  1105. // 查询这个客户是否是登陆人的客户
  1106. if (userMapper.getAidAndUser(uid, TokenManager.getAdminId()) <= 0)
  1107. throw new BusinessException(new Error("请勿非法操作!", "请勿非法操作!"));
  1108. flag = updateUserLock(uid, oldAid, UserLockReleaseStatus.LOCKED.getCode(),
  1109. UserLockReleaseStatus.RELEASE.getCode()); // 原用户释放客户
  1110. if (flag > 0)
  1111. flag = addUserLock(uid, String.valueOf(params[0]), now, uList); // 指定用户锁定客户
  1112. if (flag <= 0)
  1113. throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL, ""));
  1114. }
  1115. } else {
  1116. for (String us : uList) {
  1117. if (userMapper.getAidAndUser(us, TokenManager.getAdminId()) <= 0)
  1118. throw new BusinessException(new Error("请勿非法操作!", "请勿非法操作!"));
  1119. }
  1120. if (AFTConstants.USER_TRANSFER_TO_OTHER == operatorType) {
  1121. flag = updateUsersLock(uList, oldAid, UserLockReleaseStatus.LOCKED.getCode(),
  1122. UserLockReleaseStatus.RELEASE.getCode()); // 原用户释放客户
  1123. if (flag > 0)
  1124. flag = addUserLock(uid, String.valueOf(params[0]), now, uList); // 指定用户锁定客户
  1125. if (flag <= 0)
  1126. throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL, ""));
  1127. }
  1128. }
  1129. Integer type = 2;
  1130. if (AFTConstants.SIGN_USER_TRANSFER_TO_OTHER == operatorType)
  1131. type = 7;
  1132. addUserTransferLog(uid, String.valueOf(params[0]), type, null, now, uList);
  1133. }
  1134. if (isUs) {
  1135. if (AFTConstants.USER_RECEIVE == operatorType) {
  1136. userMapper.updateList(String.valueOf(params[0]), null, 3, null, 2, uList);
  1137. } else {
  1138. userMapper.updateList(String.valueOf(params[0]), null, 3, null, null, uList);
  1139. }
  1140. } else {
  1141. userMapper.updateByPrimaryKeySelective(user);
  1142. }
  1143. return 1;
  1144. }
  1145. /**
  1146. *
  1147. * @param uid 客户id
  1148. * @param aid 接受者id
  1149. * @param lockTime 时间
  1150. * @param uList 是不是多人客户
  1151. * @return
  1152. */
  1153. private int addUserLock(String uid, String aid, Date lockTime, List<String> uList) {
  1154. if (uList.isEmpty()) {
  1155. UserLockRelease ulr = new UserLockRelease();
  1156. ulr.setId(UUID.randomUUID().toString());
  1157. ulr.setType(0);
  1158. ulr.setAid(aid);
  1159. ulr.setLockTime(lockTime);
  1160. ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
  1161. ulr.setUid(uid);
  1162. userLockReleaseMapper.insert(ulr);
  1163. } else {
  1164. List<UserLockRelease> ulrList = new ArrayList<>();
  1165. for (String s : uList) {
  1166. UserLockRelease ulr = new UserLockRelease();
  1167. ulr.setId(UUID.randomUUID().toString());
  1168. ulr.setType(0);
  1169. ulr.setAid(aid);
  1170. ulr.setLockTime(lockTime);
  1171. ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
  1172. ulr.setUid(s);
  1173. ulrList.add(ulr);
  1174. }
  1175. userLockReleaseMapper.insertList(ulrList);
  1176. }
  1177. return 1;
  1178. }
  1179. /**
  1180. *
  1181. * @param type 0录入 1 领取 2 转交私有客户 3转交业务 4 未跟进丢失(30) 5未签单丢失(270天)6释放 7转交签单客户
  1182. */
  1183. private void addUserTransferLog(String uid, String aid, Integer type, String pid, Date lockTime,
  1184. List<String> uList) {
  1185. if (uList.isEmpty()) {
  1186. UserTransferLog utl = new UserTransferLog();
  1187. if (type == 0 || type == 1)
  1188. utl.setAid(aid);
  1189. else if (type == 2 || type == 3 || type == 7) {
  1190. utl.setAid(TokenManager.getAdminId());
  1191. utl.setTakeAid(aid);
  1192. }
  1193. if (type == 3)
  1194. utl.setPid(pid);
  1195. utl.setType(type);
  1196. utl.setCreateTime(lockTime);
  1197. utl.setUid(uid);
  1198. userTransferLogMapper.insertSelective(utl);
  1199. } else {
  1200. List<String> ulist = Arrays.asList(uid.split(","));
  1201. List<UserTransferLog> utlList = new ArrayList<>();
  1202. for (String string : ulist) {
  1203. UserTransferLog utl = new UserTransferLog();
  1204. if (type == 0 || type == 1)
  1205. utl.setAid(string);
  1206. else if (type == 2 || type == 3 || type == 7) {
  1207. utl.setAid(TokenManager.getAdminId());
  1208. utl.setTakeAid(string);
  1209. }
  1210. if (type == 3)
  1211. utl.setPid(pid);
  1212. utl.setCreateTime(lockTime);
  1213. utl.setUid(uid);
  1214. utl.setType(type);
  1215. utlList.add(utl);
  1216. }
  1217. userTransferLogMapper.insertList(utlList);
  1218. }
  1219. }
  1220. @SuppressWarnings("unchecked")
  1221. @Override
  1222. public Pagination<StatisticBo> customerStatistics(Date sDate, Date eDate, String depNo, String businessGlossoryId,
  1223. Integer pageNo, Integer pageSize) {
  1224. Map<String, Object> params = new HashMap<String, Object>();
  1225. if (null != sDate)
  1226. params.put("sDate", sDate);
  1227. if (null != eDate)
  1228. params.put("eDate", eDate);
  1229. if (StringUtils.isNotBlank(depNo))
  1230. params.put("depNo", depNo);
  1231. if (StringUtils.isNotBlank(businessGlossoryId))
  1232. params.put("businessGlossoryId", businessGlossoryId);
  1233. Pagination<StatisticBo> page = (Pagination<StatisticBo>) findPage("customerStatisticsList",
  1234. "customerStatisticsCount", params, pageNo, pageSize);
  1235. return page;
  1236. }
  1237. @SuppressWarnings("unchecked")
  1238. @Override
  1239. public Pagination<StatisticBo> businessStatistic(Date sDate, Date eDate, String depNo, String businessGlossoryId,
  1240. Integer pageNo, Integer pageSize) {
  1241. Map<String, Object> params = new HashMap<String, Object>();
  1242. if (null != sDate)
  1243. params.put("sDate", sDate);
  1244. if (null != eDate)
  1245. params.put("eDate", eDate);
  1246. if (StringUtils.isNotBlank(depNo))
  1247. params.put("depNo", depNo);
  1248. if (StringUtils.isNotBlank(businessGlossoryId))
  1249. params.put("businessGlossoryId", businessGlossoryId);
  1250. Pagination<StatisticBo> page = (Pagination<StatisticBo>) findPage("businessStatisticList",
  1251. "businessStatisticCount", params, pageNo, pageSize);
  1252. return page;
  1253. }
  1254. @SuppressWarnings("unchecked")
  1255. @Override
  1256. public Pagination<StatisticBo> followStatistic(Date sDate, Date eDate, String depNo, Integer pageNo,
  1257. Integer pageSize) {
  1258. Map<String, Object> params = new HashMap<String, Object>();
  1259. if (null != sDate)
  1260. params.put("sDate", sDate);
  1261. if (null != eDate)
  1262. params.put("eDate", eDate);
  1263. if (StringUtils.isNotBlank(depNo))
  1264. params.put("depNo", depNo);
  1265. Pagination<StatisticBo> page = (Pagination<StatisticBo>) findPage("followStatisticList", "followStatisticCount",
  1266. params, pageNo, pageSize);
  1267. return page;
  1268. }
  1269. @SuppressWarnings("unchecked")
  1270. @Override
  1271. public Pagination<BusinessListBo> listBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
  1272. blo.setAid(TokenManager.getAdminId());
  1273. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo),
  1274. pageNo, pageSize);
  1275. }
  1276. @SuppressWarnings("unchecked")
  1277. @Override
  1278. public Pagination<BusinessListBo> listAllBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
  1279. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo),
  1280. pageNo, pageSize);
  1281. }
  1282. @SuppressWarnings("unchecked")
  1283. @Override
  1284. public Pagination<BusinessListBo> listManageBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
  1285. blo.setAid(TokenManager.getAdminId());
  1286. return (Pagination<BusinessListBo>) findPage("selectBusinessManageList", "selectBusinessManageCount",
  1287. disposeParams(blo), pageNo, pageSize);
  1288. }
  1289. private Map<String, Object> disposeParams(BusinessListBo blo) {
  1290. Map<String, Object> params = new HashMap<String, Object>();
  1291. if (StringUtils.isNotBlank(blo.getUid()))
  1292. params.put("uid", blo.getUid());
  1293. if (StringUtils.isNotBlank(blo.getAid()))
  1294. params.put("aid", blo.getAid());
  1295. if (StringUtils.isNotBlank(blo.getAdminName()))
  1296. params.put("adminName", blo.getAdminName());
  1297. if (StringUtils.isNotBlank(blo.getStartDate()))
  1298. params.put("startDate", blo.getStartDate() + " 00:00:00");
  1299. if (StringUtils.isNotBlank(blo.getEndDate()))
  1300. params.put("endDate", blo.getEndDate() + " 23:59:59");
  1301. if (StringUtils.isNotBlank(blo.getIdentifyName()))
  1302. params.put("identifyName", blo.getIdentifyName());
  1303. if (blo.getFollowSituation() != null)
  1304. params.put("followSituation", blo.getFollowSituation());
  1305. if (blo.getCustomerStatus() != null)
  1306. params.put("customerStatus", blo.getCustomerStatus());
  1307. return params;
  1308. }
  1309. @Override
  1310. public List<BusinessListBo> findBusinessGlossory() {
  1311. return userBusinessMapper.selectBusinessGlossory();
  1312. }
  1313. @Override
  1314. public int judgeBusiness(String uid, String businessProjectId) {
  1315. return userMapper.selectLockedProject(uid, null, businessProjectId, 1, UserLockReleaseStatus.LOCKED.getCode())
  1316. .size();
  1317. }
  1318. @Override
  1319. @Transactional
  1320. public void addBusinessAndFollow(BussinessFollowBo bfb) throws ParseException {
  1321. UserBusiness ub = new UserBusiness();
  1322. String ubId = UUID.randomUUID().toString();
  1323. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  1324. ub.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1325. ub.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1326. ub.setId(ubId);
  1327. ub.setUid(bfb.getUid());
  1328. ub.setAid(TokenManager.getAdminId());
  1329. ub.setRemarks(bfb.getRemarks());
  1330. ub.setBusinessProjectId(bfb.getBusinessProjectId());
  1331. ub.setUpdateTime(format.parse(bfb.getCreateTime()));
  1332. ub.setCreateTime(format.parse(bfb.getCreateTime()));
  1333. userBusinessMapper.insert(ub);
  1334. if (StringUtils.isNotBlank(bfb.getOcbId())) { // 跟进联系人不为空则添加跟进记录
  1335. UserFollow uf = new UserFollow();
  1336. String ufId = UUID.randomUUID().toString();
  1337. uf.setId(ufId);
  1338. uf.setUid(bfb.getUid());
  1339. uf.setCreateTime(format.parse(bfb.getFollowTime()));
  1340. uf.setOcbId(bfb.getOcbId());
  1341. uf.setResult(bfb.getResult());
  1342. uf.setContactType(Integer.parseInt(bfb.getContactType()));
  1343. uf.setAid(TokenManager.getAdminId());
  1344. uf.setEffective(0);
  1345. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  1346. uf.setFollowCount(followCount);
  1347. userFollowMapper.insert(uf);
  1348. UserFollowBusiness ufb = new UserFollowBusiness();
  1349. ufb.setId(UUID.randomUUID().toString());
  1350. ufb.setBusinessId(ubId);
  1351. ufb.setFollowId(ufId);
  1352. ufb.setCustomerStatus(ub.getCustomerStatus());
  1353. ufb.setFollowSituation(ub.getFollowSituation());
  1354. ufb.setBusinessProjectId(bfb.getBusinessProjectId());
  1355. userFollowBusinessMapper.insert(ufb);
  1356. }
  1357. }
  1358. @Override
  1359. public List<BusinessListBo> findBusinessByUAid(String uid, String aid) {
  1360. return userBusinessMapper.selectBusinessByUAid(uid, aid);
  1361. }
  1362. @Override
  1363. public List<BusinessListBo> findLockedBusinessByUAid(String uid, String aid) {
  1364. return userBusinessMapper.selectLockedBusinessByUAid(uid, aid);
  1365. }
  1366. @Override
  1367. public BussinessFollowBo findBusinessDetail(String businessId) {
  1368. return userBusinessMapper.findBusinessDetail(businessId);
  1369. }
  1370. @Override
  1371. public int updateBusiness(BussinessFollowBo bfb) {
  1372. UserBusiness userBusiness = new UserBusiness();
  1373. userBusiness.setId(bfb.getBusinessId());
  1374. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1375. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1376. userBusiness.setRemarks(bfb.getRemarks());
  1377. userBusiness.setUpdateTime(new Date());
  1378. return userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  1379. }
  1380. @Override
  1381. @Transactional
  1382. public int addFollowOneBusiness(BussinessFollowBo bfb) throws ParseException {
  1383. Date updateTime = new Date();
  1384. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  1385. UserBusiness userBusiness = new UserBusiness();
  1386. userBusiness.setId(bfb.getBusinessId());
  1387. userBusiness.setUpdateTime(updateTime);
  1388. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1389. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1390. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  1391. UserFollow userFollow = new UserFollow();
  1392. String followId = UUID.randomUUID().toString();
  1393. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  1394. userFollow.setId(followId);
  1395. userFollow.setResult(bfb.getResult());
  1396. userFollow.setCreateTime(format.parse(bfb.getFollowTime()));
  1397. userFollow.setEffective(0);
  1398. userFollow.setOcbId(bfb.getOcbId());
  1399. userFollow.setFollowCount(followCount);
  1400. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  1401. userFollow.setAid(TokenManager.getAdminId());
  1402. userFollow.setUid(bfb.getUid());
  1403. userFollowMapper.insert(userFollow);
  1404. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  1405. String ufbId = UUID.randomUUID().toString();
  1406. userFollowBusiness.setId(ufbId);
  1407. userFollowBusiness.setFollowId(followId);
  1408. userFollowBusiness.setBusinessProjectId(bfb.getBusinessProjectId());
  1409. userFollowBusiness.setBusinessId(bfb.getBusinessId());
  1410. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1411. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1412. userFollowBusiness.setRemarks(bfb.getRemarks());
  1413. userFollowBusinessMapper.insert(userFollowBusiness);
  1414. return 1;
  1415. }
  1416. @Override
  1417. public BussinessFollowBo findFollowOneBusiness(String ufbId) {
  1418. return userBusinessMapper.findFollowOneBusiness(ufbId);
  1419. }
  1420. @Override
  1421. public int updateFollowOneBusiness(BussinessFollowBo bfb) {
  1422. // 修改业务跟进中间表
  1423. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  1424. userFollowBusiness.setId(bfb.getUfbId());
  1425. userFollowBusiness.setRemarks(bfb.getRemarks());
  1426. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1427. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1428. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness);
  1429. // 修改跟进记录表
  1430. UserFollow userFollow = new UserFollow();
  1431. userFollow.setId(bfb.getFollowId());
  1432. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  1433. userFollow.setResult(bfb.getResult());
  1434. if (StringUtils.isNotBlank(bfb.getOcbId()))
  1435. userFollow.setOcbId(bfb.getOcbId());
  1436. userFollowMapper.updateByPrimaryKeySelective(userFollow);
  1437. return 1;
  1438. }
  1439. @Override
  1440. public int addOneContact(OrganizationContactBook ocb) {
  1441. ocb.setAid(TokenManager.getAdminId());
  1442. ocb.setId(UUID.randomUUID().toString());
  1443. ocb.setMajor(AFTConstants.NO);
  1444. Admin ad = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  1445. ocb.setAname(ad.getName());
  1446. return organizationContactBookMapper.insert(ocb);
  1447. }
  1448. @Override
  1449. public int deleteBusiness(String businessId) {
  1450. return userBusinessMapper.deleteByPrimaryKey(businessId);
  1451. }
  1452. @Override
  1453. public int updateBusinessToStop(String businessId) {
  1454. UserBusiness ub = new UserBusiness();
  1455. ub.setId(businessId);
  1456. ub.setCustomerStatus(CustomerStatusFiled.STATUS_STOP.getCode());
  1457. return userBusinessMapper.updateByPrimaryKeySelective(ub);
  1458. }
  1459. @Override
  1460. public int deleteFollowOneBusiness(String ufbId) {
  1461. UserFollowBusiness ufb = userFollowBusinessMapper.selectByPrimaryKey(ufbId);
  1462. if (ufb.getFollowSituation() == 5) {// 如果业务是已签合同则不允许删除
  1463. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, ""));
  1464. }
  1465. return userFollowBusinessMapper.deleteByPrimaryKey(ufbId);
  1466. }
  1467. @Override
  1468. public int deleteOneContact(String ocbId) {
  1469. return organizationContactBookMapper.deleteByPrimaryKey(ocbId);
  1470. }
  1471. @Override
  1472. public List<Admin> findAdminName() {
  1473. String aid = TokenManager.getAdminId();
  1474. return userMapper.findAdminName(aid);
  1475. }
  1476. @Override
  1477. public int updatePersonalCustomerz(CustomerPersonalDetailBo bo) {
  1478. UserIdentity ui = new UserIdentity();
  1479. User user = new User();
  1480. try {
  1481. BeanUtilsExt.copyProperties(ui, bo);
  1482. user.setId(bo.getUid());
  1483. user.setSocietyTag(bo.getSocietyTag());
  1484. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  1485. user.setIntroduction(bo.getIntroduction());
  1486. user.setUpdateTime(new Date());
  1487. if (!StringUtils.isBlank(bo.getAid())) {
  1488. user.setAid(bo.getAid());
  1489. user.setShareType(0);
  1490. }
  1491. } catch (InvocationTargetException | IllegalAccessException e) {
  1492. e.printStackTrace();
  1493. }
  1494. userMapper.updateByPrimaryKeySelective(user);
  1495. return 1;
  1496. }
  1497. @Override
  1498. public Pagination<CustomerListOut> findEnteringAudit(CustomerListOut clo, Integer pageNo, Integer pageSize) {
  1499. Map<String, Object> params = disposeParams(clo);
  1500. if (!StringUtils.isBlank(clo.getAdminName()))
  1501. params.put("adminName", clo.getAdminName());
  1502. @SuppressWarnings("unchecked")
  1503. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditList",
  1504. "findEnteringAuditCount", params, pageNo, pageSize);
  1505. return list;
  1506. }
  1507. @Override
  1508. public Pagination<CustomerListOut> findEnteringAuditIsNo(CustomerListOut clo, Integer pageNo, Integer pageSize) {
  1509. clo.setAid(TokenManager.getAdminId());
  1510. Map<String, Object> params = disposeParams(clo);
  1511. if (!StringUtils.isBlank(clo.getAdminName()))
  1512. params.put("adminName", clo.getAdminName());
  1513. @SuppressWarnings("unchecked")
  1514. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditIsNoList",
  1515. "findEnteringAuditIsNoCount", params, pageNo, pageSize);
  1516. return list;
  1517. }
  1518. @Override
  1519. public int updateEnteringAudit(User bo) {
  1520. String[] ary = bo.getId().split(",");
  1521. for (String s : ary) {
  1522. String id = s;
  1523. Integer auditStatus = bo.getAuditStatus();
  1524. String auditOpinion = bo.getAuditOpinion();
  1525. userMapper.updateEnteringAudit(id, auditStatus, auditOpinion);
  1526. }
  1527. return 1;
  1528. }
  1529. @Override
  1530. public int updateMainContact(String ocbId, String uid) {
  1531. organizationContactBookMapper.updateSubContact(uid);
  1532. OrganizationIdentity oi = new OrganizationIdentity();
  1533. OrganizationContactBook ocb = organizationContactBookMapper.selectByPrimaryKey(ocbId);
  1534. oi.setUid(uid);
  1535. oi.setContacts(ocb.getName());
  1536. oi.setContactMobile(ocb.getMobile());
  1537. organizationIdentityMapper.updateServiceByUid(oi);
  1538. organizationContactBookMapper.updateMainContact(ocbId);
  1539. return 1;
  1540. }
  1541. @Override
  1542. public int updateRefusedCustomer(String id, String nickname, String mobile, String societyTag) {
  1543. User u = userMapper.selectByPrimaryKey(id);
  1544. u.setNickname(nickname);
  1545. u.setMobile(mobile);
  1546. u.setSocietyTag(societyTag);
  1547. return userMapper.updateRefusedCustomer(id, nickname, mobile, societyTag);
  1548. }
  1549. private void setCustomerList(List<CustomerListOut> tmpList, int i, Integer power) {
  1550. Date now = new Date();
  1551. String s1, s2;
  1552. Long l1, l2;
  1553. int diff1 = 0, diff2 = 0;
  1554. for (CustomerListOut clo : tmpList) {
  1555. try {
  1556. // 如果最近跟进为空直接取转换时间
  1557. if (StringUtils.isNotBlank(clo.getLastFollowTime())) {
  1558. // 如果最近跟进小于转换取转换时间
  1559. if (DateUtils.parseDate(clo.getLastFollowTime(), AFTConstants.YYYYMMDDHHMMSS).getTime() > DateUtils
  1560. .parseDate(clo.getTransferTime(), AFTConstants.YYYYMMDDHHMMSS).getTime()) {
  1561. s1 = clo.getLastFollowTime();
  1562. } else {
  1563. s1 = clo.getTransferTime();
  1564. }
  1565. } else {
  1566. s1 = clo.getTransferTime();
  1567. }
  1568. // 另外一个时间取转换时间
  1569. s2 = clo.getTransferTime();
  1570. l1 = DateUtils.parseDate(s1, AFTConstants.YYYYMMDDHHMMSS).getTime();
  1571. l2 = DateUtils.parseDate(s2, AFTConstants.YYYYMMDDHHMMSS).getTime();
  1572. if (i == 0) {
  1573. diff1 = (int) ((l1 + AFTConstants.USER_FOLLOW_LIMIT_MS - now.getTime()) / (24 * 3600 * 1000));
  1574. diff2 = (int) ((l2 + AFTConstants.USER_SIGN_LIMIT_MS - now.getTime()) / (24 * 3600 * 1000));
  1575. } else if (i == 1) {
  1576. diff1 = (int) ((l1 + AFTConstants.PROJECT_FOLLOW_LIMIT_MS - now.getTime()) / (24 * 3600 * 1000));
  1577. diff2 = (int) ((l2 + AFTConstants.PROJECT_SIGN_LIMIT_MS - now.getTime()) / (24 * 3600 * 1000));
  1578. }
  1579. clo.setSurplusFollowTime(diff1 + "");
  1580. clo.setSurplusSignTime(diff2 + "");
  1581. } catch (ParseException e) {
  1582. e.printStackTrace();
  1583. }
  1584. if (power == 1) {
  1585. if (!clo.getAid().equals(TokenManager.getAdminId())) {
  1586. clo.setContacts("***");
  1587. clo.setContactMobile("***");
  1588. }
  1589. }
  1590. }
  1591. }
  1592. @SuppressWarnings("unchecked")
  1593. @Override
  1594. public Pagination<CustomerListOut> listSignOrganizationCustomer(CustomerListIn cli, Integer pageNo,
  1595. Integer pageSize) {
  1596. cli.setAid(TokenManager.getAdminId());
  1597. Map<String, Object> params = disposeParams(cli);
  1598. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignOrganizationCustomerList",
  1599. "selectSignOrganizationCustomerCount", params, pageNo, pageSize);
  1600. return list;
  1601. }
  1602. @SuppressWarnings("unchecked")
  1603. @Override
  1604. public Pagination<CustomerListOut> listSignPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1605. cli.setAid(TokenManager.getAdminId());
  1606. Map<String, Object> params = disposeParams(cli);
  1607. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignPersonalCustomerList",
  1608. "selectSignPersonalCustomerCount", params, pageNo, pageSize);
  1609. List<CustomerListOut> tmpList = (List<CustomerListOut>) list.getList();
  1610. setCustomerList(tmpList, 0, null);
  1611. list.setList(tmpList);
  1612. return list;
  1613. }
  1614. @Override
  1615. public List<LockingReleaseBo> selectLockedProject(String uid) {
  1616. List<LockingReleaseBo> list = userMapper.selectLockedProject(uid, null, null, 1, 0);
  1617. for (LockingReleaseBo lrb : list) {
  1618. if (lrb.getAid().equals(TokenManager.getAdminId())) {
  1619. lrb.setMySign(1);
  1620. } else {
  1621. lrb.setMySign(0);
  1622. }
  1623. }
  1624. return list;
  1625. }
  1626. @Override
  1627. public List<CustomerSimpleBo> getPrivateCustomerByName(String name) {
  1628. return userMapper.selectPrivateCustomerByName(name, TokenManager.getAdminId());
  1629. }
  1630. @Override
  1631. public List<CustomerSimpleBo> getSignedCustomerByName(String name) {
  1632. return userMapper.selectSignedCustomerByName(name, TokenManager.getAdminId(), 1);
  1633. }
  1634. @Override
  1635. public List<CustomerSimpleBo> getChannelCustomerByName(String name) {
  1636. return userMapper.selectSignedCustomerByName(name, TokenManager.getAdminId(), 2);
  1637. }
  1638. private int updateUserLock(String uid, String aid, Integer oldStatus, Integer newStatus) {
  1639. return userLockReleaseMapper.updateUserLock(uid, aid, oldStatus, newStatus);
  1640. }
  1641. private int updateUsersLock(List<String> uList, String aid, Integer oldStatus, Integer newStatus) {
  1642. return userLockReleaseMapper.updateUsersLock(uList, aid, oldStatus, newStatus);
  1643. }
  1644. @Override
  1645. public List<LockingReleaseBo> selectWaitReleaseCustomer(String uid, Integer type) {
  1646. return userLockReleaseMapper.selectWaitReleaseCustomer(uid, type);
  1647. }
  1648. /**
  1649. * 查询需要释放的业务
  1650. *
  1651. * @param uid
  1652. * @return
  1653. */
  1654. @Override
  1655. public List<LockingReleaseBo> selectWaitReleaseBusiness(String uid) {
  1656. return userLockReleaseMapper.selectWaitReleaseBusiness(uid);
  1657. }
  1658. /**
  1659. * 处理需要释放
  1660. *
  1661. * @param list
  1662. */
  1663. @Override
  1664. public void updateReleaseLock(Date releaseTime) {
  1665. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1666. String time = formatter.format(releaseTime);
  1667. userMapper.updateReleaseLock(time);
  1668. userLockReleaseMapper.updateReleaseLock(time);
  1669. }
  1670. @Override
  1671. public int updateAgainProjectTask(String uid, String projectId, String aid) {
  1672. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, TokenManager.getAdminId(),
  1673. projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
  1674. // List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, aid, projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
  1675. UserLockRelease u = new UserLockRelease();
  1676. if (businessLockedList.size() == 1) {
  1677. for (LockingReleaseBo l : businessLockedList) {
  1678. u.setId(l.getId());
  1679. u.setLockTime(new Date());
  1680. }
  1681. return userLockReleaseMapper.updateByPrimaryKeySelective(u);
  1682. }
  1683. return 0;
  1684. }
  1685. @Override
  1686. public int updateInformationMaintainerr(String id, String aid) {
  1687. User u = new User();
  1688. u.setId(id);
  1689. u.setInformationMaintainer(aid);
  1690. return userMapper.updateByPrimaryKeySelective(u);
  1691. }
  1692. @SuppressWarnings("unchecked")
  1693. @Override
  1694. public Pagination<CustomerListIn> listCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1695. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1696. cli.setAid(TokenManager.getAdminId());
  1697. // cli.setAid("1");
  1698. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1699. Map<String, Object> params = disposeParams(cli);
  1700. return (Pagination<CustomerListIn>) findPage("selectCustomerInformationList", "selectCustomerInformationCount",
  1701. params, pageNo, pageSize);
  1702. }
  1703. @SuppressWarnings("unchecked")
  1704. @Override
  1705. public Pagination<CustomerListIn> listDepCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1706. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1707. cli.setAid(TokenManager.getAdminId());
  1708. // cli.setAid("1");
  1709. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1710. Map<String, Object> params = disposeParams(cli);
  1711. return (Pagination<CustomerListIn>) findPage("selectDepCustomerInformationList",
  1712. "selectDepCustomerInformationCount", params, pageNo, pageSize);
  1713. }
  1714. public boolean checkCustomerInformation(String uid) {
  1715. int i = userMapper.checkCustomerInformation(uid);
  1716. if (i < 1) {
  1717. return true;
  1718. }
  1719. return false;
  1720. }
  1721. @Override
  1722. public void updatePendingReleaseLock(List<LockingReleaseBo> newList) {
  1723. String lockIds = "";
  1724. for (LockingReleaseBo bo : newList) {
  1725. lockIds += bo.getId() + ",";
  1726. }
  1727. if (lockIds.length() > 0) {
  1728. lockIds = "'" + lockIds.substring(0, lockIds.length() - 1).replace(",", "','") + "'";
  1729. userLockReleaseMapper.updatePendingReleaseLock(lockIds);
  1730. }
  1731. }
  1732. @Override
  1733. public List<LockingReleaseBo> selectPendinglockUserList() {
  1734. return userLockReleaseMapper.selectPendinglockUserList();
  1735. }
  1736. @Override
  1737. public int updateUserLevel(User u) {
  1738. if (!u.getId().contains(",")) {
  1739. userMapper.updateByPrimaryKeySelective(u);
  1740. } else {
  1741. List<String> ulist = Arrays.asList(u.getId().split(","));
  1742. userMapper.updateList(null, u.getLevel(), null, null, null, ulist);
  1743. }
  1744. return 1;
  1745. }
  1746. @Override
  1747. public XSSFWorkbook privateUnitCustomerOutXls(CustomerListIn cli, Integer sort, Integer sortType, Integer pageNo,
  1748. Integer pageSize) {
  1749. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1750. cli.setAid(TokenManager.getAdminId());
  1751. // cli.setAid("1");
  1752. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1753. Map<String, Object> params = disposeParams(cli);
  1754. params.put("sort", sort);
  1755. params.put("sortType", sortType);
  1756. List<CustomerListOut> list = userMapper.privateUnitCustomerList(params);
  1757. setCustomerList(list, 0, 0);
  1758. if (list == null || list.size() == 0)
  1759. return null;
  1760. String[] comment = { "客户名称", "地区", "联系人", "联系电话", "社会性质", "客户初始时间", "剩余私有天数", "最新跟进时间", "客户等级" };
  1761. String filePath = uploadPath + "/privateUnitCustomer";
  1762. XSSFWorkbook wb = ExportExcelUtil.exportSelectPrivateOrganizationCustomer(list, comment, filePath);
  1763. return wb;
  1764. }
  1765. @Override
  1766. public int customerHandOver(String userIds, String receiveId) {
  1767. /*
  1768. * String [] str=userIds.split(","); String aid=TokenManager.getAdminId();
  1769. * List<String> uids=Arrays.asList(str);
  1770. * userLockReleaseMapper.updateBatchReleaseProject(uids,receiveId,aid);
  1771. * userLockReleaseMapper.updateBatchlockProject(uids,receiveId,aid);
  1772. */
  1773. return 0;
  1774. }
  1775. @Override
  1776. public int updatePrivateBusinessTransfer(String inputId, String uid, String pid) {
  1777. List<LockingReleaseBo> list = userLockReleaseMapper.checkUserProject(uid, pid, TokenManager.getAdminId());
  1778. if (list.isEmpty()) {
  1779. throw new BusinessException(new Error("客户归属错误", "客户归属错误"));
  1780. }
  1781. LockingReleaseBo l = list.get(0);
  1782. UserLockRelease ul = new UserLockRelease();
  1783. ul.setId(l.getId());
  1784. ul.setAid(inputId);
  1785. userLockReleaseMapper.updateByPrimaryKeySelective(ul);
  1786. addtransferLog(uid, pid, TokenManager.getAdminId(), inputId, 3, false);
  1787. List<BusinessListBo> bl = userBusinessMapper.selectBusinessProjectByUAPid(uid, TokenManager.getAdminId(), pid);
  1788. if (bl.size() == 1) {
  1789. UserBusiness ub = new UserBusiness();
  1790. ub.setId(bl.get(0).getBusinessId());
  1791. ub.setAid(inputId);
  1792. ub.setRemarks("转交客户业务触发");
  1793. userBusinessMapper.updateByPrimaryKeySelective(ub);
  1794. }
  1795. return 1;
  1796. }
  1797. private void addtransferLog(String uid, String pid, String aid, String takeAid, Integer type, boolean isUs) {
  1798. if (!isUs) {
  1799. UserTransferLog utl = new UserTransferLog();
  1800. utl.setAid(aid);
  1801. utl.setCreateTime(new Date());
  1802. utl.setPid(pid);
  1803. utl.setTakeAid(takeAid);
  1804. utl.setType(type);
  1805. utl.setUid(uid);
  1806. userTransferLogMapper.insertSelective(utl);
  1807. } else {
  1808. List<String> ulist = Arrays.asList(uid.split(","));
  1809. List<UserTransferLog> utfList = new ArrayList<>();
  1810. for (String us : ulist) {
  1811. UserTransferLog utl = new UserTransferLog();
  1812. utl.setAid(aid);
  1813. utl.setCreateTime(new Date());
  1814. utl.setPid(pid);
  1815. utl.setTakeAid(takeAid);
  1816. utl.setType(type);
  1817. utl.setUid(us);
  1818. utfList.add(utl);
  1819. }
  1820. userTransferLogMapper.insertList(utfList);
  1821. }
  1822. }
  1823. @Override
  1824. public List<transferListBo> transferList(String uid) {
  1825. return userTransferLogMapper.selectByUidGetList(uid);
  1826. }
  1827. @Override
  1828. public int pushReleaseUser(String id) {
  1829. Date date = new Date();
  1830. String aid = TokenManager.getAdminId();
  1831. if (!id.contains(",")) {
  1832. User u = userMapper.selectByPrimaryKey(id);
  1833. if (!u.getAid().equals(aid)) {
  1834. throw new BuilderException("客户归属错误!");
  1835. }
  1836. UserTransferLog utl = new UserTransferLog();
  1837. u.setTransferTime(date);
  1838. u.setShareType(1);
  1839. userMapper.updateByPrimaryKeySelective(u);
  1840. utl.setAid(aid);
  1841. utl.setCreateTime(date);
  1842. utl.setType(6);
  1843. utl.setUid(id);
  1844. userTransferLogMapper.insertSelective(utl);
  1845. userLockReleaseMapper.updateUserTypeLock(u.getId(), TokenManager.getAdminId(), 0, 2, date);
  1846. } else {
  1847. List<String> list = Arrays.asList(id.split(","));
  1848. List<UserTransferLog> ulList = new ArrayList<UserTransferLog>();
  1849. for (String str : list) {
  1850. User u = userMapper.selectByPrimaryKey(str);
  1851. if (!u.getAid().equals(TokenManager.getAdminId())) {
  1852. throw new BuilderException("客户归属错误!");
  1853. }
  1854. UserTransferLog utl = new UserTransferLog();
  1855. utl.setAid(aid);
  1856. utl.setCreateTime(date);
  1857. utl.setType(6);
  1858. utl.setUid(str);
  1859. ulList.add(utl);
  1860. }
  1861. userTransferLogMapper.insertList(ulList);
  1862. userMapper.updateList(null, null, null, date, 1, list);
  1863. userLockReleaseMapper.updateUserTypeLockList(list, TokenManager.getAdminId(), 0, 2, date);
  1864. }
  1865. return 1;
  1866. }
  1867. @Override
  1868. public List<userDaysBo> selectReleaseUserDays(String id) {
  1869. Integer x = 270, y = 90;
  1870. x = x - USER_REMIND_DAYS;
  1871. y = y - USER_REMIND_DAYS;
  1872. List<userDaysBo> list = userLockReleaseMapper.selectUserDays(id, x, y);
  1873. return list;
  1874. }
  1875. @Override
  1876. public List<userDaysBo> selectChannelUserDays(String id) {
  1877. Integer days = 90;
  1878. return userLockReleaseMapper.selectChannelUserDays(days,id);
  1879. }
  1880. @Override
  1881. public int addGuidance(String followId, String guidance) {
  1882. UserFollow uf = new UserFollow();
  1883. uf.setId(followId);
  1884. uf.setGuidance(guidance);
  1885. uf.setGuidanceTime(new Date());
  1886. userFollowMapper.pushUserGuidance(followId, 1);
  1887. return userFollowMapper.updateByPrimaryKeySelective(uf);
  1888. }
  1889. @Override
  1890. public boolean checkMax(String aid) {
  1891. int y = 0;
  1892. int i = userMapper.checkUserMax(aid);
  1893. // 营销员100 经理200 总监500
  1894. String maxRole = userMapper.checkRoleMax(aid);
  1895. if (maxRole.equals(AFTConstants.SALESMAN_DIRECTOR))
  1896. y = 800;
  1897. else if (maxRole.equals(AFTConstants.SALESMAN_MANAGER))
  1898. y = 200;
  1899. else if (maxRole.equals(AFTConstants.SALESMAN))
  1900. y = 100;
  1901. if (i >= y) {
  1902. return true;
  1903. }
  1904. return false;
  1905. }
  1906. @Override
  1907. public void pushReleaseLog(List<LockingReleaseBo> list, Integer type) throws InterruptedException {
  1908. Date date = new Date();
  1909. List<LockingReleaseBo> newList = new ArrayList<LockingReleaseBo>();
  1910. if (list != null && list.size() > 0) {
  1911. for (int i = 0; i < list.size(); i++) {
  1912. newList.add(list.get(i));
  1913. if (50 == newList.size() || i == list.size() - 1) {
  1914. if (newList.size() > 0) {
  1915. // 处理日志
  1916. List<UserTransferLog> list3 = new ArrayList<UserTransferLog>();
  1917. for (LockingReleaseBo lrb : newList) {
  1918. UserTransferLog utl = new UserTransferLog();
  1919. utl.setAid(lrb.getAid());
  1920. utl.setCreateTime(date);
  1921. if (type == 0)
  1922. utl.setType(4);
  1923. else if (type == 1)
  1924. utl.setType(5);
  1925. utl.setUid(lrb.getUid());
  1926. list3.add(utl);
  1927. }
  1928. userTransferLogMapper.insertList(list3);
  1929. }
  1930. }
  1931. newList.clear();
  1932. Thread.sleep(2000);
  1933. }
  1934. }
  1935. }
  1936. @Override
  1937. public Object listChannelCustomer(InputListChannel in) {
  1938. Map<String, Object> params = new HashMap<>();
  1939. if (StringUtils.isNotBlank(in.getName()))
  1940. params.put("name", in.getName());
  1941. if (in.getProvince() != null)
  1942. params.put("province", in.getProvince());
  1943. if (in.getCity() != null)
  1944. params.put("city", in.getCity());
  1945. if (in.getStatus() != null)
  1946. params.put("status", in.getStatus());
  1947. params.put("type", in.getType() == null ? 0 : in.getType());
  1948. if (StringUtils.isNotBlank(in.getStartTime()))
  1949. params.put("startTime", in.getStartTime());
  1950. if (StringUtils.isNotBlank(in.getEndTime()))
  1951. params.put("endTime", in.getEndTime() + " 23:59:59");
  1952. // 0营销员 1渠道专员 2营销总监 3营销经理 4释放 5未分配 6已分配 7已签单
  1953. if (in.getType()==0) {
  1954. if(StringUtils.isNotBlank(in.getAid()))params.put("aid", in.getAid());
  1955. params.put("sid", TokenManager.getAdminId());
  1956. } else if (in.getType()==1) {
  1957. params.put("aid", in.getAid() == null ? TokenManager.getAdminId() : in.getAid());
  1958. } else if (in.getType()==2) {
  1959. if(StringUtils.isNotBlank(in.getAid()))params.put("aid", in.getAid());
  1960. }else if (in.getType()==3) {
  1961. params.put("maid", TokenManager.getAdminId());
  1962. if(StringUtils.isNotBlank(in.getAid()))params.put("aid", in.getAid());
  1963. } else {
  1964. params.put("aid", in.getAid() == null ? TokenManager.getAdminId() : in.getAid());
  1965. }
  1966. Pagination<?> p=findPage("selectChannelCustomerList", "selectChannelCustomerCount", params, in.getPageNo(),
  1967. in.getPageSize());
  1968. @SuppressWarnings("unchecked")
  1969. List<OutUserChannel> list=(List<OutUserChannel>) p.getList();
  1970. Date date=new Date();
  1971. for (OutUserChannel o : list) {
  1972. if (o.getDistributionTime()!=null) {
  1973. int days = (int) ((o.getDistributionTime().getTime() + AFTConstants.USER_CHENNL_LIMIT_MS - date.getTime()) / (24 * 3600 * 1000));
  1974. o.setDays(days);
  1975. }
  1976. }
  1977. return p;
  1978. }
  1979. @Override
  1980. public Object pushChannelDeliver(List<String> uids, String receiveId, String remarks, Integer type) {
  1981. Date date = new Date();
  1982. Integer i = userMapper.updatechannelCustomerDeliver(uids, receiveId);
  1983. Integer status = null;
  1984. if (i > 0) {
  1985. List<UserTransferLog> l = new ArrayList<UserTransferLog>();
  1986. for (String string : uids) {
  1987. UserTransferLog u = new UserTransferLog();
  1988. u.setAid(TokenManager.getAdminId());
  1989. u.setUid(string);
  1990. if (type == 0) {
  1991. u.setTakeAid(receiveId);
  1992. u.setType(9);
  1993. } else if (type == 1) {
  1994. u.setTakeAid(receiveId);
  1995. u.setType(10);
  1996. } else if (type == 2) {
  1997. u.setType(12);
  1998. }
  1999. u.setCreateTime(date);
  2000. u.setRemarks(remarks);
  2001. l.add(u);
  2002. }
  2003. userTransferLogMapper.insertList(l);
  2004. }
  2005. if (type != 2) {
  2006. userLockReleaseMapper.insertChannelList(uids, receiveId);
  2007. String role = userMapper.checkRoleMax(receiveId);
  2008. if (role.equals(AFTConstants.SALESMAN_MANAGER)) {
  2009. status = ChannelStatus.YFPJL.getCode();
  2010. } else {
  2011. status = ChannelStatus.YFPYXY.getCode();
  2012. }
  2013. } else {
  2014. userLockReleaseMapper.updateChannelList(uids);
  2015. status = ChannelStatus.HT.getCode();
  2016. }
  2017. if (type == 0) {
  2018. userChannelMapper.updateByuids(uids, type, date, receiveId, status);
  2019. } else {
  2020. userChannelMapper.updateByuids(uids, type, date, null, status);
  2021. }
  2022. organizationContactBookMapper.updateByUids(uids, receiveId);
  2023. return 1;
  2024. }
  2025. @Override
  2026. public boolean checkChannel(List<String> uids) {
  2027. for (String uid : uids) {
  2028. List<UserFollow> list = userFollowMapper.selectbyUid(uid, TokenManager.getAdminId());
  2029. if (!list.isEmpty()) {
  2030. return true;
  2031. }
  2032. }
  2033. return false;
  2034. }
  2035. @Override
  2036. public boolean checkBeforeChannel(String uid) {
  2037. String aid = userMapper.checkBeforeChannel(uid);
  2038. if (aid != null && aid.equals(TokenManager.getAdminId())) {
  2039. return true;
  2040. }
  2041. return false;
  2042. }
  2043. @Override
  2044. public boolean checkRecovery(List<String> uids) {
  2045. List<String> list = userChannelMapper.checkRecovery(uids);
  2046. for (String string : list) {
  2047. if (string.equals("1")) {
  2048. return true;
  2049. }
  2050. }
  2051. return false;
  2052. }
  2053. @Override
  2054. public List<userDaysBo> selectChannelNotFollow(String aid) {
  2055. Integer days = 15;
  2056. return userLockReleaseMapper.selectChannelNotFollow(days,aid);
  2057. }
  2058. @Override
  2059. public Object listChannelCounts(InputChannelCounts in) {
  2060. Map<String, Object> params = new HashMap<>();
  2061. params.put("type", in.getType() == null ? 0 : in.getType());
  2062. if (StringUtils.isNotBlank(in.getStartTime()))
  2063. params.put("startTime", in.getStartTime());
  2064. if (StringUtils.isNotBlank(in.getEndTime()))
  2065. params.put("endTime", in.getEndTime() + " 23:59:59");
  2066. return findPage("selectChannelCountsList", "selectChannelCountsCount", params, in.getPageNo(),
  2067. in.getPageSize());
  2068. }
  2069. @Override
  2070. public List<CustomerSimpleBo> getUserByName(String name) {
  2071. return userMapper.getUserByName(name);
  2072. }
  2073. }