CustomerServiceImpl.java 95 KB

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