CustomerServiceImpl.java 114 KB

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