CustomerServiceImpl.java 83 KB

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