CustomerServiceImpl.java 78 KB

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