CustomerServiceImpl.java 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  1. package com.goafanti.customer.service.impl;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.HashSet;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Set;
  11. import java.util.UUID;
  12. import javax.annotation.Resource;
  13. import org.apache.commons.beanutils.BeanUtils;
  14. import org.apache.commons.beanutils.PropertyUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import com.goafanti.common.bo.Error;
  19. import com.goafanti.common.constant.AFTConstants;
  20. import com.goafanti.common.constant.ErrorConstants;
  21. import com.goafanti.common.dao.AdminMapper;
  22. import com.goafanti.common.dao.BusinessGlossoryMapper;
  23. import com.goafanti.common.dao.BusinessProjectMapper;
  24. import com.goafanti.common.dao.OrganizationAnnualReportMapper;
  25. import com.goafanti.common.dao.OrganizationApplicationInfoMapper;
  26. import com.goafanti.common.dao.OrganizationContactBookMapper;
  27. import com.goafanti.common.dao.OrganizationIdentityMapper;
  28. import com.goafanti.common.dao.OrganizationYearProjectMapper;
  29. import com.goafanti.common.dao.UserBusinessMapper;
  30. import com.goafanti.common.dao.UserFollowBusinessMapper;
  31. import com.goafanti.common.dao.UserFollowMapper;
  32. import com.goafanti.common.dao.UserIdentityMapper;
  33. import com.goafanti.common.dao.UserLockReleaseMapper;
  34. import com.goafanti.common.dao.UserMapper;
  35. import com.goafanti.common.enums.CustomerStatusFiled;
  36. import com.goafanti.common.enums.DeleteStatus;
  37. import com.goafanti.common.enums.IdentityProcess;
  38. import com.goafanti.common.enums.UserLevel;
  39. import com.goafanti.common.enums.UserLockReleaseStatus;
  40. import com.goafanti.common.enums.UserType;
  41. import com.goafanti.common.error.BusinessException;
  42. import com.goafanti.common.model.Admin;
  43. import com.goafanti.common.model.OrganizationApplicationInfo;
  44. import com.goafanti.common.model.OrganizationContactBook;
  45. import com.goafanti.common.model.OrganizationIdentity;
  46. import com.goafanti.common.model.User;
  47. import com.goafanti.common.model.UserBusiness;
  48. import com.goafanti.common.model.UserFollow;
  49. import com.goafanti.common.model.UserFollowBusiness;
  50. import com.goafanti.common.model.UserIdentity;
  51. import com.goafanti.common.model.UserLockRelease;
  52. import com.goafanti.common.utils.BeanUtilsExt;
  53. import com.goafanti.common.utils.DateUtils;
  54. import com.goafanti.common.utils.PasswordUtil;
  55. import com.goafanti.common.utils.StringUtils;
  56. import com.goafanti.core.mybatis.BaseMybatisDao;
  57. import com.goafanti.core.mybatis.page.Pagination;
  58. import com.goafanti.core.shiro.token.TokenManager;
  59. import com.goafanti.customer.bo.BusinessListBo;
  60. import com.goafanti.customer.bo.BussinessFollowBo;
  61. import com.goafanti.customer.bo.CustomerExcelBo;
  62. import com.goafanti.customer.bo.CustomerListIn;
  63. import com.goafanti.customer.bo.CustomerListOut;
  64. import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
  65. import com.goafanti.customer.bo.CustomerPersonalDetailBo;
  66. import com.goafanti.customer.bo.CustomerSimpleBo;
  67. import com.goafanti.customer.bo.FollowBusinessBo;
  68. import com.goafanti.customer.bo.FollowListBo;
  69. import com.goafanti.customer.bo.LockingReleaseBo;
  70. import com.goafanti.customer.bo.StatisticBo;
  71. import com.goafanti.customer.service.CustomerService;
  72. @Service
  73. public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements CustomerService {
  74. @Autowired
  75. private UserMapper userMapper;
  76. @Autowired
  77. private UserIdentityMapper userIdentityMapper;
  78. @Autowired
  79. private OrganizationIdentityMapper organizationIdentityMapper;
  80. @Autowired
  81. private OrganizationContactBookMapper organizationContactBookMapper;
  82. @Resource(name = "passwordUtil")
  83. private PasswordUtil passwordUtil;
  84. @Resource
  85. private UserFollowMapper userFollowMapper;
  86. @Resource
  87. private UserBusinessMapper userBusinessMapper;
  88. @Resource
  89. private UserFollowBusinessMapper userFollowBusinessMapper;
  90. @Resource
  91. private BusinessGlossoryMapper businessGlossoryMapper;
  92. @Resource
  93. private BusinessProjectMapper businessProjectMapper;
  94. @Resource
  95. private UserLockReleaseMapper userLockReleaseMapper;
  96. @Resource
  97. private AdminMapper adminMapper;
  98. @Resource
  99. private OrganizationApplicationInfoMapper organizationApplicationInfoMapper;
  100. @Resource
  101. private OrganizationAnnualReportMapper organizationAnnualReportMapper;
  102. @Resource
  103. private OrganizationYearProjectMapper organizationYearProjectMapper;
  104. @SuppressWarnings("unchecked")
  105. @Override
  106. public Pagination<CustomerListOut> listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  107. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  108. cli.setAid(TokenManager.getAdminId());
  109. Map<String,Object> params = disposeParams(cli);
  110. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPrivatePersonalCustomerList","selectPrivatePersonalCustomerCount",params,pageNo,pageSize);
  111. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  112. setCustomerList(tmpList);
  113. list.setList(tmpList);
  114. return list;
  115. }
  116. @SuppressWarnings("unchecked")
  117. @Override
  118. public Pagination<CustomerListOut> listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  119. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  120. Map<String,Object> params = disposeParams(cli);
  121. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPublicPersonalCustomerList","selectPublicPersonalCustomerCount",params,pageNo,pageSize);
  122. return list;
  123. }
  124. @SuppressWarnings("unchecked")
  125. @Override
  126. public Pagination<CustomerListOut> listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  127. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  128. Map<String,Object> params = disposeParams(cli);
  129. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
  130. return list;
  131. }
  132. @SuppressWarnings("unchecked")
  133. @Override
  134. public Pagination<CustomerListOut> listAllManagePersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  135. cli.setType(AFTConstants.USER_TYPE_PERSONAL);
  136. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  137. Map<String,Object> params = disposeParams(cli);
  138. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManagePersonalCustomerList","selectManagePersonalCustomerCount",params,pageNo,pageSize);
  139. return list;
  140. }
  141. @SuppressWarnings("unchecked")
  142. @Override
  143. public Pagination<CustomerListOut> listPrivateOrganizationCustomer(CustomerListIn cli,Integer sort,Integer sortType, Integer pageNo,Integer pageSize) {
  144. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  145. cli.setAid(TokenManager.getAdminId());
  146. // cli.setAid("1");
  147. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  148. Map<String,Object> params = disposeParams(cli);
  149. params.put("sort", sort);
  150. params.put("sortType",sortType);
  151. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPrivateOrganizationCustomerList","selectPrivateOrganizationCustomerCount",params,pageNo,pageSize);
  152. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  153. setCustomerList(tmpList);
  154. list.setList(tmpList);
  155. return list;
  156. }
  157. @SuppressWarnings("unchecked")
  158. @Override
  159. public Pagination<CustomerListOut> listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  160. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  161. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC));
  162. Map<String,Object> params = disposeParams(cli);
  163. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPublicOrganizationCustomerList","selectPublicOrganizationCustomerCount",params,pageNo,pageSize);
  164. return list;
  165. }
  166. @SuppressWarnings("unchecked")
  167. @Override
  168. public Pagination<CustomerListOut> listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  169. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  170. Map<String,Object> params = disposeParams(cli);
  171. Pagination<CustomerListOut> p=(Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
  172. List<CustomerListOut> l=(List<CustomerListOut>) p.getList();
  173. for (CustomerListOut c : l) {
  174. if (null!=c) {
  175. if(null!=c.getAid())c.setAdminName(adminMapper.selectNameByid(c.getAid()));
  176. if (null!=c.getShareType()&&c.getShareType().equals("1"))c.setAdminName("暂无");
  177. if(null!=c.getMid())c.setInformationMaintainer(adminMapper.selectNameByid(c.getMid()));
  178. }
  179. }
  180. return p;
  181. }
  182. @Override
  183. public Pagination<CustomerListOut> listAllManageOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
  184. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  185. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  186. cli.setAid(TokenManager.getAdminId());
  187. Map<String,Object> params = disposeParams(cli);
  188. @SuppressWarnings("unchecked")
  189. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManageOrganizationCustomerList","selectManageOrganizationCustomerCount",params,pageNo,pageSize);
  190. return list;
  191. }
  192. private Map<String,Object> disposeParams(CustomerListIn cli){
  193. Map<String,Object> params = new HashMap<String, Object>();
  194. if(StringUtils.isNotBlank(cli.getType())) params.put("type", Integer.parseInt(cli.getType()));
  195. if(StringUtils.isNotBlank(cli.getShareType())) params.put("shareType", Integer.parseInt(cli.getShareType()));
  196. if(StringUtils.isNotBlank(cli.getName())) params.put("name", cli.getName());
  197. if(StringUtils.isNotBlank(cli.getProvince())) params.put("province", Integer.parseInt(cli.getProvince()));
  198. if(StringUtils.isNotBlank(cli.getCity())) params.put("city", Integer.parseInt(cli.getCity()));
  199. if(StringUtils.isNotBlank(cli.getArea())) params.put("area", Integer.parseInt(cli.getArea()));
  200. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate());
  201. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate());
  202. if(StringUtils.isNotBlank(cli.getIndustry())) params.put("industry", Integer.parseInt(cli.getIndustry()));
  203. if(StringUtils.isNotBlank(cli.getAid())) params.put("aid", cli.getAid());
  204. if(StringUtils.isNotBlank(cli.getDepartmentId())) params.put("departmentId", cli.getDepartmentId());
  205. if(StringUtils.isNotBlank(cli.getStatus())) params.put("status", Integer.parseInt(cli.getStatus()));
  206. if(StringUtils.isNotBlank(cli.getSocietyTag())) params.put("societyTag", cli.getSocietyTag());
  207. if(StringUtils.isNotBlank(cli.getFollow())) params.put("follow", cli.getFollow());
  208. if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate()+" 00:00:00");
  209. if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate()+" 23:59:59");
  210. if(null!=cli.getDataGrade()) params.put("dataGrade", cli.getDataGrade());
  211. if(null!=cli.getLevel())params.put("level", cli.getLevel());
  212. return params;
  213. }
  214. @Override
  215. public List<CustomerSimpleBo> findCustomerByName(String name) {
  216. return userMapper.findCustomerByName(name);
  217. }
  218. @Override
  219. public int judgeCustomerByName(String name) {
  220. return userMapper.judgeCustomerByName(name);
  221. }
  222. @Override
  223. @Transactional
  224. public int addCustomer(String name, String contacts, String contactMobile, Integer type, Integer source,String societyTag,
  225. Integer province ,Integer city, Integer area) throws BusinessException{
  226. User user = new User();
  227. Date now = new Date();
  228. String uid = UUID.randomUUID().toString();
  229. String identifyId = UUID.randomUUID().toString();
  230. user.setId(uid);
  231. user.setIdentifyName(name);
  232. user.setSource(1);//客户来源为录入
  233. user.setNickname(name);
  234. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  235. user.setShareType(AFTConstants.NO);
  236. user.setAid(TokenManager.getAdminId());
  237. // user.setAid("1");
  238. user.setType(type);
  239. user.setLvl(UserLevel.CERTIFIED.getCode());
  240. user.setSocietyTag(societyTag);
  241. user.setCreateTime(now);
  242. user.setTransferTime(now);
  243. user.setUpdateTime(now);
  244. user.setMobile(contactMobile);
  245. user.setPassword(AFTConstants.INITIALPASSWORD);
  246. user.setInformationMaintainer(TokenManager.getAdminId());
  247. float f=0;
  248. user.setIntegrity(f);
  249. // user.setInformationMaintainer("1");
  250. passwordUtil.encryptPassword(user);
  251. if(type == UserType.PERSONAL.getCode()){
  252. if(userMapper.checkUser("", "", contactMobile, type,null,null).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,""));
  253. UserIdentity ui = new UserIdentity();
  254. ui.setId(identifyId);
  255. ui.setUid(uid);
  256. ui.setContacts(contacts);
  257. ui.setContactMobile(contactMobile);
  258. ui.setUsername(name);
  259. ui.setProvince(province);
  260. ui.setCity(city);
  261. ui.setArea(area);
  262. ui.setExpert(AFTConstants.NO);
  263. ui.setCelebrity(AFTConstants.NO);
  264. ui.setInternational(AFTConstants.NO);
  265. ui.setAuditStatus(IdentityProcess.SUCCESS.getCode());//认证个人
  266. userIdentityMapper.insert(ui);
  267. }else if(type == UserType.ORGANIZATION.getCode()){
  268. if(userMapper.checkUser("",name,"",type,null,null).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,""));
  269. // 创建企业认证信息
  270. OrganizationIdentity oi = new OrganizationIdentity();
  271. oi.setUnitName(name);
  272. oi.setId(identifyId);
  273. oi.setUid(uid);
  274. oi.setContacts(contacts);
  275. oi.setContactMobile(contactMobile);
  276. oi.setLocationProvince(province);
  277. oi.setLocationCity(city);
  278. oi.setLocationArea(area);
  279. oi.setHighTechZone(AFTConstants.NO);
  280. oi.setInternational(AFTConstants.NO);
  281. oi.setListed(AFTConstants.NO);
  282. oi.setAuditStatus(IdentityProcess.SUCCESS.getCode()); //实名企业
  283. organizationIdentityMapper.insert(oi);
  284. }
  285. userMapper.insert(user);
  286. //新增企业联系人
  287. OrganizationContactBook cob = new OrganizationContactBook();
  288. cob.setAid(TokenManager.getAdminId());
  289. // cob.setAid("1");
  290. cob.setId(UUID.randomUUID().toString());
  291. cob.setUid(uid);
  292. cob.setName(contacts);
  293. cob.setMobile(contactMobile);
  294. cob.setMajor(AFTConstants.NO);
  295. organizationContactBookMapper.insert(cob);
  296. //新增锁定数据
  297. addUserLock(uid, TokenManager.getAdminId(), now);
  298. // addUserLock(uid, "1", now);
  299. return 1;
  300. }
  301. @Override
  302. public CustomerPersonalDetailBo findPersonalCustomerDetail(String uid) {
  303. return userMapper.findPersonalCustomerDetail(uid);
  304. }
  305. @Override
  306. public CustomerOrganizationDetailBo findOrganizationCustomerDetail(String uid) {
  307. return userMapper.findOrganizationCustomerDetail(uid);
  308. }
  309. @Override
  310. @Transactional
  311. public int updateOrganizationCustomer(CustomerOrganizationDetailBo bo) {
  312. OrganizationIdentity oi = new OrganizationIdentity();
  313. User user = new User();
  314. Date date =new Date();
  315. OrganizationApplicationInfo oa=new OrganizationApplicationInfo();
  316. try {
  317. BeanUtilsExt.copyProperties(oi, bo);
  318. user.setId(bo.getUid());
  319. user.setSocietyTag(bo.getSocietyTag());
  320. user.setCompanyLogoUrl(bo.getCompanyLogoUrl());
  321. user.setIntroduction(bo.getIntroduction());
  322. user.setUpdateTime(date);
  323. user.setInformationMaintainer(bo.getInformationMaintainer());
  324. user.setCoreTechnology(bo.getCoreTechnology());
  325. user.setAccomplishSituation(bo.getAccomplishSituation());
  326. user.setIntellectualProperty(bo.getIntellectualProperty());
  327. user.setCreditRating(bo.getCreditRating());
  328. user.setIntegrity(countIntegrity(bo));
  329. if (StringUtils.isNotBlank(bo.getPojectApplicationUrl())) {
  330. List<OrganizationApplicationInfo> l=organizationApplicationInfoMapper.selectByUid(bo.getUid());
  331. if(l.size()>0){
  332. oa=l.get(0);
  333. oa.setPojectApplicationUrl(bo.getPojectApplicationUrl());
  334. organizationApplicationInfoMapper.updateByPrimaryKey(oa);
  335. }else {
  336. oa.setId(UUID.randomUUID().toString());
  337. oa.setCreateTime(date);
  338. oa.setUid(bo.getUid());
  339. oa.setPojectApplicationUrl(bo.getPojectApplicationUrl());
  340. organizationApplicationInfoMapper.insert(oa);
  341. }
  342. }
  343. } catch (IllegalAccessException |InvocationTargetException e) {
  344. e.printStackTrace();
  345. }
  346. organizationIdentityMapper.updateByPrimaryKey(oi);
  347. userMapper.updateByPrimaryKeySelective(user);
  348. return 1;
  349. }
  350. public Float countIntegrity(CustomerOrganizationDetailBo bo) {
  351. //完整资料总数
  352. int max=10;
  353. int number=0;
  354. if(null!=bo.getIndustry())number+=1;
  355. if(bo.getLocationProvince()!=null)number+=1;
  356. if(StringUtils.isNotBlank(bo.getBusinessScope()))number+=1;
  357. if(bo.getRegisteredCapital()!=null)number+=1;
  358. if(StringUtils.isNotBlank(bo.getCooperationSituation()))number+=1;
  359. if(StringUtils.isNotBlank(bo.getQualification()))number+=1;
  360. // if(bo.getAssets()!=null)number+=1;
  361. // if(bo.getLastYearResearchAmount()!=null)number+=1;
  362. // if(bo.getYearSalesAmount()!=null)number+=1;
  363. // if(StringUtils.isNotBlank(bo.getAccomplishSituation()))number+=1;
  364. if (organizationAnnualReportMapper.selectOrgAnnualCount(bo.getUid())>0)number+=1;
  365. if (organizationAnnualReportMapper.selectOrgYearProjectCount(bo.getUid())>0)number+=1;
  366. if(StringUtils.isNotBlank(bo.getCoreTechnology()))number+=1;
  367. if(bo.getCreditRating()!=null)number+=1;
  368. float f= (float)number/max;
  369. return f;
  370. }
  371. @Override
  372. public int updatePersonalCustomer(CustomerPersonalDetailBo bo) {
  373. UserIdentity ui = new UserIdentity();
  374. User user = new User();
  375. try {
  376. try {
  377. PropertyUtils.copyProperties(ui,bo);
  378. } catch (NoSuchMethodException e) {
  379. e.printStackTrace();
  380. }
  381. //BeanUtilsExt.copyProperties(ui, bo);
  382. user.setId(bo.getUid());
  383. user.setSocietyTag(bo.getSocietyTag());
  384. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  385. user.setIntroduction(bo.getIntroduction());
  386. user.setUpdateTime(new Date());
  387. if(null==bo.getExpertAudit()&&bo.getExpert()==1)ui.setExpertAudit(2);
  388. } catch (InvocationTargetException | IllegalAccessException e) {
  389. e.printStackTrace();
  390. }
  391. userIdentityMapper.updateByPrimaryKeySelective(ui);
  392. userMapper.updateByPrimaryKeySelective(user);
  393. return 1;
  394. }
  395. @SuppressWarnings("unchecked")
  396. @Override
  397. public Pagination<FollowListBo> listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessProjectId) {
  398. Map<String, Object> params = new HashMap<String, Object>();
  399. if(StringUtils.isNotBlank(uid))params.put("uid", uid);
  400. if(StringUtils.isNotBlank(businessProjectId)) params.put("businessProjectId", businessProjectId);
  401. Pagination<FollowListBo> page = (Pagination<FollowListBo>)findPage("selectFollowHistoryList","selectFollowHistoryCount",params, pageNo, pageSize);
  402. List<FollowListBo> list = (List<FollowListBo>)page.getList();
  403. for(FollowListBo bo : list){
  404. if(bo.getAid().equals(TokenManager.getAdminId())){
  405. bo.setReadOnly(AFTConstants.NO);
  406. }else{
  407. bo.setReadOnly(AFTConstants.YES);
  408. }
  409. }
  410. page.setList(list);
  411. return page;
  412. }
  413. @Override
  414. public User findUserAccountDetail(String uid) {
  415. return userMapper.findUserAccountDetail(uid);
  416. }
  417. @Override
  418. public int updateUserAccount(User user) {
  419. return userMapper.updateByPrimaryKeySelective(user);
  420. }
  421. @Override
  422. public List<OrganizationContactBook> findCustomerContacts(String uid) {
  423. return userMapper.findCustomerContacts(uid,TokenManager.getAdminId());
  424. }
  425. @Override
  426. @Transactional
  427. public int addFollow(FollowBusinessBo fbb) throws BusinessException{
  428. //if(fbb.getUserBusinessList().size()<1) throw new BusinessException(new Error(ErrorConstants.AT_LEAST_A_BUSINESS,"",""));
  429. //更新跟进记录表
  430. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  431. UserFollow userFollow = new UserFollow();
  432. String followId = UUID.randomUUID().toString();
  433. userFollow.setId(followId);
  434. userFollow.setAid(TokenManager.getAdminId());
  435. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  436. userFollow.setEffective(DeleteStatus.UNDELETE.getCode());
  437. try {
  438. userFollow.setCreateTime(format.parse(fbb.getFollowTime()));
  439. } catch (ParseException e) {
  440. e.printStackTrace();
  441. }
  442. userFollow.setOcbId(fbb.getOcbId());
  443. userFollow.setResult(fbb.getResult());
  444. userFollow.setUid(fbb.getUid());
  445. int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), TokenManager.getAdminId()) + 1;
  446. userFollow.setFollowCount(followCount);
  447. userFollowMapper.insert(userFollow);
  448. //检查客户锁定情况
  449. if(fbb.getUserBusinessList().size()>0){
  450. boolean isUserOwner = false;
  451. List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(), TokenManager.getAdminId(),null, 0, UserLockReleaseStatus.LOCKED.getCode());
  452. if(userLockedList.size() > 0){
  453. isUserOwner = true;
  454. }
  455. boolean isBusinessOwner = false;
  456. List<LockingReleaseBo> businessLockedList = null;
  457. String businessName= "";
  458. String ufbId = "";
  459. UserBusiness userBusiness = null;
  460. UserFollowBusiness userFollowBusiness = null;
  461. for(BusinessListBo ub: fbb.getUserBusinessList()){
  462. userBusiness = new UserBusiness();
  463. userFollowBusiness = new UserFollowBusiness();
  464. ufbId = UUID.randomUUID().toString();
  465. businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
  466. UserBusiness us=userBusinessMapper.selectByPrimaryKey(ub.getBusinessId());
  467. //sas
  468. if(StringUtils.isNotBlank(ub.getBusinessId())){
  469. //更新业务表
  470. userBusiness.setId(ub.getBusinessId());
  471. if (us.getFollowSituation()==5) {//如果已签合同,则不允许变更
  472. /*if (ub.getFollowSituation()!=5&&checkCustomerInformation(uid)) {
  473. throw new BusinessException(new Error("","请到客户资料-客户资料维护模块完善您的客户信息!"));
  474. }*/
  475. if (ub.getCustomerStatus()!=us.getCustomerStatus()|| ub.getFollowSituation()!=5) {
  476. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));
  477. }
  478. }
  479. //检查业务锁定情况
  480. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  481. if(businessLockedList.size() > 0){
  482. for(LockingReleaseBo bo : businessLockedList){
  483. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  484. }
  485. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  486. }else{
  487. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  488. }
  489. //releaseProject(businessLockedList);
  490. if (us.getFollowSituation()!=5&&ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
  491. if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
  492. lockProject(ub);//锁定客户业务
  493. }
  494. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  495. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  496. userBusiness.setFollowSituation(ub.getFollowSituation());
  497. userBusiness.setRemarks(ub.getRemarks());
  498. userBusiness.setUid(fbb.getUid());
  499. try {
  500. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  501. } catch (ParseException e) {
  502. e.printStackTrace();
  503. }
  504. userBusiness.setAid(TokenManager.getAdminId());
  505. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  506. //更新业务中间表
  507. userFollowBusiness.setBusinessId(ub.getBusinessProjectId());
  508. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  509. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  510. userFollowBusiness.setId(ufbId);
  511. userFollowBusiness.setFollowId(followId);
  512. userFollowBusiness.setRemarks(ub.getRemarks());
  513. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  514. userFollowBusinessMapper.insert(userFollowBusiness);
  515. }else{
  516. //检查业务锁定情况
  517. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  518. if(businessLockedList.size() > 0){
  519. for(LockingReleaseBo bo : businessLockedList){
  520. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  521. }
  522. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  523. }else{
  524. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  525. }
  526. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "")>0){
  527. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  528. }
  529. if (ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
  530. if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
  531. lockProject(ub);//锁定客户业务
  532. }
  533. String ubId = UUID.randomUUID().toString();
  534. //更新业务表
  535. userBusiness.setId(ubId);
  536. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  537. try {
  538. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  539. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  540. } catch (ParseException e) {
  541. e.printStackTrace();
  542. }
  543. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  544. userBusiness.setFollowSituation(ub.getFollowSituation());
  545. userBusiness.setUid(fbb.getUid());
  546. userBusiness.setAid(TokenManager.getAdminId());
  547. userBusiness.setRemarks(ub.getRemarks());
  548. userBusinessMapper.insert(userBusiness);
  549. //更新业务中间表
  550. userFollowBusiness.setBusinessId(ubId);
  551. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  552. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  553. userFollowBusiness.setId(ufbId);
  554. userFollowBusiness.setFollowId(followId);
  555. userFollowBusiness.setRemarks(ub.getRemarks());
  556. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  557. userFollowBusinessMapper.insert(userFollowBusiness);
  558. }
  559. }
  560. }
  561. return 1;
  562. }
  563. private void lockProject(BusinessListBo ub) {
  564. UserLockRelease ulr= new UserLockRelease();
  565. ulr.setId(UUID.randomUUID().toString());
  566. ulr.setType(1);
  567. ulr.setAid(TokenManager.getAdminId());
  568. ulr.setBusinessProjectId(ub.getBusinessProjectId());
  569. SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
  570. try {
  571. if (null==ub.getCreateTime()) {
  572. ulr.setLockTime(new Date());
  573. }else {
  574. ulr.setLockTime(sdf.parse(ub.getCreateTime()));
  575. }
  576. } catch (ParseException e) {
  577. e.printStackTrace();
  578. }
  579. ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
  580. ulr.setUid(ub.getUid());
  581. userLockReleaseMapper.insert(ulr);
  582. }
  583. @SuppressWarnings("unused")
  584. private void releaseProject(List<LockingReleaseBo> businessLockedList) {
  585. if(businessLockedList != null && businessLockedList.size()>0){
  586. UserLockRelease ulr = null;
  587. for(LockingReleaseBo bo : businessLockedList){
  588. ulr = new UserLockRelease();
  589. ulr.setId(bo.getId());
  590. ulr.setStatus(UserLockReleaseStatus.RELEASE.getCode());
  591. userLockReleaseMapper.updateByPrimaryKeySelective(ulr);
  592. }
  593. }
  594. }
  595. @Override
  596. public FollowBusinessBo findFollowById(String followId) {
  597. return userMapper.findFollowById(followId);
  598. }
  599. @Override
  600. public List<BusinessListBo> findBusinessByFollowId(String followId) {
  601. return userMapper.findBusinessByFollowId(followId);
  602. }
  603. @Override
  604. @Transactional
  605. public int updateFollow(FollowBusinessBo fbb) throws BusinessException{
  606. UserFollow userFollow = new UserFollow();
  607. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  608. userFollow.setId(fbb.getFollowId());
  609. if(StringUtils.isNotBlank(fbb.getOcbId())) userFollow.setOcbId(fbb.getOcbId());
  610. userFollow.setResult(fbb.getResult());
  611. userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
  612. userFollowMapper.updateByPrimaryKeySelective(userFollow); //修改拜访记录表
  613. if(fbb.getUserBusinessList().size()>0){
  614. //检查客户锁定情况
  615. boolean isUserOwner = false;
  616. List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(), TokenManager.getAdminId(),null, 0, UserLockReleaseStatus.LOCKED.getCode());
  617. if(userLockedList.size() > 0){
  618. isUserOwner = true;
  619. }
  620. boolean isBusinessOwner = false;
  621. List<LockingReleaseBo> businessLockedList = null;
  622. String businessName= "";
  623. UserFollowBusiness userFollowBusiness = null;
  624. for(BusinessListBo ub: fbb.getUserBusinessList()){
  625. userFollowBusiness = new UserFollowBusiness();
  626. businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
  627. if(StringUtils.isNotBlank(ub.getUfbId())){
  628. userFollowBusiness.setId(ub.getUfbId());
  629. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  630. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  631. userFollowBusiness.setRemarks(ub.getRemarks());
  632. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); //修改拜访记录中间表
  633. }else{
  634. //检查业务锁定情况
  635. businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null,ub.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  636. if(businessLockedList.size() > 0){
  637. for(LockingReleaseBo bo : businessLockedList){
  638. if(bo.getAid().equals(TokenManager.getAdminId())) isBusinessOwner = true;
  639. }
  640. if(!isBusinessOwner) throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,businessName,""));
  641. }else{
  642. if(!isUserOwner) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED,businessName,""));
  643. }
  644. if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "")>0){
  645. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,""));
  646. }
  647. String ubId = UUID.randomUUID().toString();
  648. UserBusiness userBusiness = new UserBusiness();
  649. //更新业务表
  650. userBusiness.setId(ubId);
  651. userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  652. try {
  653. userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
  654. userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
  655. } catch (ParseException e) {
  656. e.printStackTrace();
  657. }
  658. userBusiness.setCustomerStatus(ub.getCustomerStatus());
  659. userBusiness.setFollowSituation(ub.getFollowSituation());
  660. userBusiness.setUid(fbb.getUid());
  661. userBusiness.setAid(TokenManager.getAdminId());
  662. userBusinessMapper.insert(userBusiness);
  663. //更新业务中间表
  664. String ufbId = UUID.randomUUID().toString();
  665. userFollowBusiness.setId(ufbId);
  666. userFollowBusiness.setFollowId(fbb.getFollowId());
  667. userFollowBusiness.setBusinessId(ubId);
  668. userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
  669. userFollowBusiness.setFollowSituation(ub.getFollowSituation());
  670. userFollowBusiness.setRemarks(ub.getRemarks());
  671. userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
  672. userFollowBusinessMapper.insert(userFollowBusiness);
  673. }
  674. }
  675. }
  676. return 1;
  677. }
  678. @Override
  679. public Set<OrganizationContactBook> findAllContacts(String uid) {
  680. Set<OrganizationContactBook> result = new HashSet<OrganizationContactBook>();
  681. result.addAll(userMapper.findAllContacts(uid));
  682. return result;
  683. }
  684. @Override
  685. public int updateCustomerContacts(List<OrganizationContactBook> ocbList,String uid) {
  686. if(ocbList.size()>0){
  687. OrganizationContactBook ocb = null;
  688. for(OrganizationContactBook item: ocbList){
  689. ocb = new OrganizationContactBook();
  690. try {
  691. BeanUtils.copyProperties(ocb, item);
  692. if(StringUtils.isBlank(ocb.getId())){
  693. ocb.setId(UUID.randomUUID().toString());
  694. ocb.setUid(uid);
  695. ocb.setAid(TokenManager.getAdminId());
  696. organizationContactBookMapper.insert(ocb);
  697. }else{
  698. organizationContactBookMapper.updateByPrimaryKeySelective(ocb);
  699. }
  700. } catch (IllegalAccessException | InvocationTargetException e) {
  701. e.printStackTrace();
  702. }
  703. }
  704. }
  705. return 1;
  706. }
  707. @Override
  708. public int deleteFollow(String followId) {
  709. UserFollow uf = new UserFollow();
  710. List<BusinessListBo> list= userMapper.findBusinessByFollowId(followId);
  711. for (BusinessListBo b : list) {
  712. if(b.getFollowSituation()==5)throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));;
  713. }
  714. uf.setId(followId);
  715. uf.setEffective(DeleteStatus.DELETED.getCode());
  716. return userFollowMapper.updateByPrimaryKeySelective(uf);
  717. }
  718. @Override
  719. public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows, Set<Integer> filterRows) {
  720. List<User> list = null;
  721. CustomerExcelBo[] bos = (CustomerExcelBo[])boSet.toArray(new CustomerExcelBo[] {});
  722. for (int i=0;i<bos.length;i++) {
  723. CustomerExcelBo bo = bos[i];
  724. CustomerExcelBo ceb = null;
  725. for(int j=0;j<i;j++){
  726. ceb = bos[j];
  727. if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){ //个人
  728. if(ceb.getMobile().equals(bo.getMobile()) && ceb.getCustomerType().equals(bo.getCustomerType())){
  729. bo.setUid(ceb.getUid());
  730. bo.setNewData(false);
  731. filterRows.add(bo.getRowNumber());
  732. break;
  733. }
  734. }else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){ //单位
  735. if(ceb.getIdentifyName().equals(bo.getIdentifyName()) && ceb.getCustomerType().equals(bo.getCustomerType())){
  736. bo.setUid(ceb.getUid());
  737. bo.setNewData(false);
  738. filterRows.add(bo.getRowNumber());
  739. break;
  740. }
  741. }
  742. }
  743. if(StringUtils.isBlank(bo.getUid())){ //是否已经存在
  744. if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)){
  745. list = userMapper.checkUser("", "", bo.getMobile(), Integer.parseInt(bo.getCustomerType()),null,null);
  746. }else if(bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  747. list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()),null,null);
  748. }
  749. if (list.size() > 0) {
  750. bo.setUid(list.get(0).getId());
  751. bo.setNewData(false);
  752. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  753. if(businessLockedList.size() > 0){
  754. existRows.add(bo.getRowNumber());
  755. }
  756. }else{
  757. bo.setUid(UUID.randomUUID().toString());
  758. bo.setNewData(true);
  759. }
  760. }else{
  761. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
  762. if(businessLockedList.size() > 0){
  763. existRows.add(bo.getRowNumber());
  764. }
  765. }
  766. }
  767. }
  768. @Override
  769. @Transactional
  770. public int saveUploadData(Set<CustomerExcelBo> boSet) {
  771. Date now = new Date();
  772. String uid = "";
  773. for(CustomerExcelBo bo : boSet){
  774. uid = bo.getUid();
  775. if(bo.isNewData()){ //新建客户
  776. createUser(bo, uid, now);
  777. createIdentity(bo, bo.getCustomerType(), uid);
  778. createBusiness(bo, uid, now);
  779. createContacts(bo, uid);
  780. }else{ //新建业务
  781. createBusiness(bo, uid, now);
  782. if(organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId())<=0){
  783. createContacts(bo, uid);
  784. }
  785. }
  786. }
  787. return 1;
  788. }
  789. private void createUser(CustomerExcelBo bo,String uid,Date now){
  790. User user = new User();
  791. user.setId(uid);
  792. user.setIdentifyName(bo.getIdentifyName());
  793. user.setSource(AFTConstants.USER_SOURCE_CREATE);
  794. user.setNickname(bo.getIdentifyName());
  795. user.setStatus(AFTConstants.USER_STATUS_NORMAL);
  796. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  797. user.setAid(TokenManager.getAdminId());
  798. user.setType(Integer.parseInt(bo.getCustomerType()));
  799. user.setLvl(UserLevel.CERTIFIED.getCode());
  800. user.setCreateTime(now);
  801. user.setUpdateTime(now);
  802. user.setMobile(bo.getMobile());
  803. user.setPassword(AFTConstants.INITIALPASSWORD);
  804. passwordUtil.encryptPassword(user);
  805. userMapper.insert(user);
  806. }
  807. private void createIdentity(CustomerExcelBo bo,String type,String uid){
  808. String identifyId = UUID.randomUUID().toString();
  809. if(type.equals(AFTConstants.USER_TYPE_PERSONAL)){
  810. //新增个人认证信息
  811. UserIdentity ui = new UserIdentity();
  812. ui.setId(identifyId);
  813. ui.setUid(uid);
  814. ui.setContacts(bo.getContacts());
  815. ui.setContactMobile(bo.getMobile());
  816. ui.setUsername(bo.getIdentifyName());
  817. ui.setExpert(AFTConstants.NO);
  818. ui.setCelebrity(AFTConstants.NO);
  819. ui.setInternational(AFTConstants.NO);
  820. ui.setAuditStatus(5);
  821. userIdentityMapper.insert(ui);
  822. }else if(type.equals(AFTConstants.USER_TYPE_ORGANIZATION)){
  823. // 创建企业认证信息
  824. OrganizationIdentity oi = new OrganizationIdentity();
  825. oi.setId(identifyId);
  826. oi.setUnitName(bo.getIdentifyName());
  827. oi.setUid(uid);
  828. oi.setContacts(bo.getContacts());
  829. oi.setContactMobile(bo.getMobile());
  830. oi.setHighTechZone(AFTConstants.NO);
  831. oi.setInternational(AFTConstants.NO);
  832. oi.setListed(AFTConstants.NO);
  833. oi.setAuditStatus(5); //实名企业
  834. organizationIdentityMapper.insert(oi);
  835. }
  836. }
  837. private void createContacts(CustomerExcelBo bo,String uid){
  838. //新增企业联系人
  839. OrganizationContactBook cob = new OrganizationContactBook();
  840. cob.setAid(TokenManager.getAdminId());
  841. cob.setId(UUID.randomUUID().toString());
  842. cob.setUid(uid);
  843. cob.setName(bo.getContacts());
  844. cob.setMobile(bo.getMobile());
  845. cob.setMajor(AFTConstants.NO);
  846. organizationContactBookMapper.insert(cob);
  847. }
  848. private void createBusiness(CustomerExcelBo bo,String uid,Date now){
  849. //新增业务
  850. UserBusiness ub = new UserBusiness();
  851. ub.setId(UUID.randomUUID().toString());
  852. ub.setAid(TokenManager.getAdminId());
  853. ub.setBusinessProjectId(bo.getBusinessProjectId());
  854. ub.setUid(uid);
  855. ub.setCreateTime(now);
  856. ub.setUpdateTime(now);
  857. ub.setCustomerStatus(Integer.parseInt(bo.getCustomerStatus()));
  858. ub.setFollowSituation(Integer.parseInt(bo.getFollowSituation()));
  859. userBusinessMapper.insert(ub);
  860. }
  861. @Override
  862. public int updateByOperatorType(String uid,String oldAid, String operatorType,Object... params) {
  863. User user = new User();
  864. Date now = new Date();
  865. user.setId(uid);
  866. int flag = 0;
  867. if(operatorType.equals(AFTConstants.USER_RECEIVE)){
  868. user.setAid(TokenManager.getAdminId());
  869. user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
  870. user.setInformationMaintainer(TokenManager.getAdminId());
  871. user.setSource(2);//客户来源设置为领取
  872. user.setTransferTime(now);
  873. flag = addUserLock(uid,TokenManager.getAdminId(),now); //指定用户锁定客户
  874. if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_RECEIVE,""));
  875. if(userMapper.UserReceiveCount(TokenManager.getAdminId())>AFTConstants.USER_RCEIVE_MAX)
  876. throw new BusinessException(new Error(ErrorConstants.CUSTOM_EREXCESS,""+(AFTConstants.USER_RCEIVE_MAX+1),""));
  877. organizationContactBookMapper.updateAdmin(uid,TokenManager.getAdminId());
  878. }else if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_OTHER)){
  879. user.setAid(String.valueOf(params[0]));
  880. user.setSource(3);//客户来源设置为转交
  881. user.setTransferTime(now);
  882. flag = updateUserLock(uid,oldAid,UserLockReleaseStatus.LOCKED.getCode(),UserLockReleaseStatus.RELEASE.getCode()); //原用户释放客户
  883. if(flag > 0 ) flag = addUserLock(uid,String.valueOf(params[0]),now); //指定用户锁定客户
  884. if(flag <= 0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL,""));
  885. }
  886. return userMapper.updateByPrimaryKeySelective(user);
  887. }
  888. @SuppressWarnings("unchecked")
  889. @Override
  890. public Pagination<StatisticBo> customerStatistics(Date sDate, Date eDate, String depNo, String businessGlossoryId, Integer pageNo, Integer pageSize) {
  891. Map<String,Object> params = new HashMap<String,Object>();
  892. if(null != sDate) params.put("sDate", sDate);
  893. if(null != eDate) params.put("eDate", eDate);
  894. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  895. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  896. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("customerStatisticsList", "customerStatisticsCount", params, pageNo, pageSize);
  897. return page;
  898. }
  899. @SuppressWarnings("unchecked")
  900. @Override
  901. public Pagination<StatisticBo> businessStatistic(Date sDate, Date eDate,String depNo, String businessGlossoryId,Integer pageNo, Integer pageSize) {
  902. Map<String,Object> params = new HashMap<String,Object>();
  903. if(null != sDate) params.put("sDate", sDate);
  904. if(null != eDate) params.put("eDate", eDate);
  905. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  906. if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
  907. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("businessStatisticList", "businessStatisticCount", params, pageNo, pageSize);
  908. return page;
  909. }
  910. @SuppressWarnings("unchecked")
  911. @Override
  912. public Pagination<StatisticBo> followStatistic(Date sDate, Date eDate, String depNo, Integer pageNo, Integer pageSize) {
  913. Map<String,Object> params = new HashMap<String,Object>();
  914. if(null != sDate) params.put("sDate", sDate);
  915. if(null != eDate) params.put("eDate", eDate);
  916. if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo);
  917. Pagination<StatisticBo> page = (Pagination<StatisticBo>)findPage("followStatisticList", "followStatisticCount", params, pageNo, pageSize);
  918. return page;
  919. }
  920. @SuppressWarnings("unchecked")
  921. @Override
  922. public Pagination<BusinessListBo> listBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) {
  923. blo.setAid(TokenManager.getAdminId());
  924. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  925. }
  926. @SuppressWarnings("unchecked")
  927. @Override
  928. public Pagination<BusinessListBo> listAllBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
  929. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  930. }
  931. @SuppressWarnings("unchecked")
  932. @Override
  933. public Pagination<BusinessListBo> listManageBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) {
  934. blo.setAid(TokenManager.getAdminId());
  935. return (Pagination<BusinessListBo>) findPage("selectBusinessManageList", "selectBusinessManageCount", disposeParams(blo), pageNo, pageSize);
  936. }
  937. private Map<String,Object> disposeParams(BusinessListBo blo){
  938. Map<String, Object> params = new HashMap<String, Object>();
  939. if(StringUtils.isNotBlank(blo.getUid())) params.put("uid", blo.getUid());
  940. if(StringUtils.isNotBlank(blo.getAid())) params.put("aid", blo.getAid());
  941. if(StringUtils.isNotBlank(blo.getAdminName())) params.put("adminName", blo.getAdminName());
  942. if(StringUtils.isNotBlank(blo.getStartDate())) params.put("startDate", blo.getStartDate()+" 00:00:00");
  943. if(StringUtils.isNotBlank(blo.getEndDate())) params.put("endDate", blo.getEndDate()+ " 23:59:59");
  944. if(StringUtils.isNotBlank(blo.getIdentifyName())) params.put("identifyName", blo.getIdentifyName());
  945. if(blo.getFollowSituation() != null) params.put("followSituation", blo.getFollowSituation());
  946. if(blo.getCustomerStatus() != null) params.put("customerStatus", blo.getCustomerStatus());
  947. return params;
  948. }
  949. @Override
  950. public List<BusinessListBo> findBusinessGlossory() {
  951. return userBusinessMapper.selectBusinessGlossory();
  952. }
  953. @Override
  954. public int judgeBusiness(String uid, String businessProjectId) {
  955. return userMapper.selectLockedProject(uid, null,businessProjectId, 1, UserLockReleaseStatus.LOCKED.getCode()).size();
  956. }
  957. @Override
  958. @Transactional
  959. public void addBusinessAndFollow(BussinessFollowBo bfb) throws ParseException {
  960. UserBusiness ub = new UserBusiness();
  961. String ubId = UUID.randomUUID().toString();
  962. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  963. ub.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  964. ub.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  965. ub.setId(ubId);
  966. ub.setUid(bfb.getUid());
  967. ub.setAid(TokenManager.getAdminId());
  968. ub.setRemarks(bfb.getRemarks());
  969. ub.setBusinessProjectId(bfb.getBusinessProjectId());
  970. ub.setUpdateTime(format.parse(bfb.getCreateTime()));
  971. ub.setCreateTime(format.parse(bfb.getCreateTime()));
  972. userBusinessMapper.insert(ub);
  973. if (StringUtils.isNotBlank(bfb.getOcbId())) { // 跟进联系人不为空则添加跟进记录
  974. UserFollow uf = new UserFollow();
  975. String ufId = UUID.randomUUID().toString();
  976. uf.setId(ufId);
  977. uf.setUid(bfb.getUid());
  978. uf.setCreateTime(format.parse(bfb.getFollowTime()));
  979. uf.setOcbId(bfb.getOcbId());
  980. uf.setResult(bfb.getResult());
  981. uf.setContactType(Integer.parseInt(bfb.getContactType()));
  982. uf.setAid(TokenManager.getAdminId());
  983. uf.setEffective(0);
  984. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  985. uf.setFollowCount(followCount);
  986. userFollowMapper.insert(uf);
  987. UserFollowBusiness ufb = new UserFollowBusiness();
  988. ufb.setId(UUID.randomUUID().toString());
  989. ufb.setBusinessId(ubId);
  990. ufb.setFollowId(ufId);
  991. ufb.setCustomerStatus(ub.getCustomerStatus());
  992. ufb.setFollowSituation(ub.getFollowSituation());
  993. ufb.setBusinessProjectId(bfb.getBusinessProjectId());
  994. userFollowBusinessMapper.insert(ufb);
  995. }
  996. }
  997. @Override
  998. public List<BusinessListBo> findBusinessByUAid(String uid, String aid) {
  999. return userBusinessMapper.selectBusinessByUAid(uid,aid);
  1000. }
  1001. @Override
  1002. public List<BusinessListBo> findLockedBusinessByUAid(String uid, String aid) {
  1003. return userBusinessMapper.selectLockedBusinessByUAid(uid,aid);
  1004. }
  1005. @Override
  1006. public BussinessFollowBo findBusinessDetail(String businessId) {
  1007. return userBusinessMapper.findBusinessDetail(businessId);
  1008. }
  1009. @Override
  1010. public int updateBusiness(BussinessFollowBo bfb) {
  1011. UserBusiness userBusiness = new UserBusiness();
  1012. userBusiness.setId(bfb.getBusinessId());
  1013. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1014. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1015. userBusiness.setRemarks(bfb.getRemarks());
  1016. userBusiness.setUpdateTime(new Date());
  1017. return userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  1018. }
  1019. @Override
  1020. @Transactional
  1021. public int addFollowOneBusiness(BussinessFollowBo bfb) throws ParseException {
  1022. Date updateTime = new Date();
  1023. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  1024. UserBusiness userBusiness = new UserBusiness();
  1025. userBusiness.setId(bfb.getBusinessId());
  1026. userBusiness.setUpdateTime(updateTime);
  1027. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1028. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1029. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  1030. UserFollow userFollow = new UserFollow();
  1031. String followId = UUID.randomUUID().toString();
  1032. int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1;
  1033. userFollow.setId(followId);
  1034. userFollow.setResult(bfb.getResult());
  1035. userFollow.setCreateTime(format.parse(bfb.getFollowTime()));
  1036. userFollow.setEffective(0);
  1037. userFollow.setOcbId(bfb.getOcbId());
  1038. userFollow.setFollowCount(followCount);
  1039. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  1040. userFollow.setAid(TokenManager.getAdminId());
  1041. userFollow.setUid(bfb.getUid());
  1042. userFollowMapper.insert(userFollow);
  1043. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  1044. String ufbId = UUID.randomUUID().toString();
  1045. userFollowBusiness.setId(ufbId);
  1046. userFollowBusiness.setFollowId(followId);
  1047. userFollowBusiness.setBusinessProjectId(bfb.getBusinessProjectId());
  1048. userFollowBusiness.setBusinessId(bfb.getBusinessId());
  1049. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1050. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1051. userFollowBusiness.setRemarks(bfb.getRemarks());
  1052. userFollowBusinessMapper.insert(userFollowBusiness);
  1053. return 1;
  1054. }
  1055. @Override
  1056. public BussinessFollowBo findFollowOneBusiness(String ufbId) {
  1057. return userBusinessMapper.findFollowOneBusiness(ufbId);
  1058. }
  1059. @Override
  1060. public int updateFollowOneBusiness(BussinessFollowBo bfb) {
  1061. //修改业务跟进中间表
  1062. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  1063. userFollowBusiness.setId(bfb.getUfbId());
  1064. userFollowBusiness.setRemarks(bfb.getRemarks());
  1065. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  1066. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  1067. userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness);
  1068. //修改跟进记录表
  1069. UserFollow userFollow = new UserFollow();
  1070. userFollow.setId(bfb.getFollowId());
  1071. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  1072. userFollow.setResult(bfb.getResult());
  1073. if(StringUtils.isNotBlank(bfb.getOcbId())) userFollow.setOcbId(bfb.getOcbId());
  1074. userFollowMapper.updateByPrimaryKeySelective(userFollow);
  1075. return 1;
  1076. }
  1077. @Override
  1078. public int addOneContact(OrganizationContactBook ocb) {
  1079. ocb.setAid(TokenManager.getAdminId());
  1080. ocb.setId(UUID.randomUUID().toString());
  1081. ocb.setMajor(AFTConstants.NO);
  1082. return organizationContactBookMapper.insert(ocb);
  1083. }
  1084. @Override
  1085. public int deleteBusiness(String businessId) {
  1086. return userBusinessMapper.deleteByPrimaryKey(businessId);
  1087. }
  1088. @Override
  1089. public int updateBusinessToStop(String businessId) {
  1090. UserBusiness ub = new UserBusiness();
  1091. ub.setId(businessId);
  1092. ub.setCustomerStatus(CustomerStatusFiled.STATUS_STOP.getCode());
  1093. return userBusinessMapper.updateByPrimaryKeySelective(ub);
  1094. }
  1095. @Override
  1096. public int deleteFollowOneBusiness(String ufbId) {
  1097. UserFollowBusiness ufb=userFollowBusinessMapper.selectByPrimaryKey(ufbId);
  1098. if (ufb.getFollowSituation()==5) {//如果业务是已签合同则不允许删除
  1099. throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED,""));
  1100. }
  1101. return userFollowBusinessMapper.deleteByPrimaryKey(ufbId);
  1102. }
  1103. @Override
  1104. public int deleteOneContact(String ocbId) {
  1105. return organizationContactBookMapper.deleteByPrimaryKey(ocbId);
  1106. }
  1107. @Override
  1108. public List<Admin> findAdminName() {
  1109. String aid=TokenManager.getAdminId();
  1110. return userMapper.findAdminName(aid);
  1111. }
  1112. @Override
  1113. public int updatePersonalCustomerz(CustomerPersonalDetailBo bo) {
  1114. UserIdentity ui = new UserIdentity();
  1115. User user = new User();
  1116. try {
  1117. BeanUtilsExt.copyProperties(ui, bo);
  1118. user.setId(bo.getUid());
  1119. user.setSocietyTag(bo.getSocietyTag());
  1120. user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
  1121. user.setIntroduction(bo.getIntroduction());
  1122. user.setUpdateTime(new Date());
  1123. if(!StringUtils.isBlank(bo.getAid())){
  1124. user.setAid(bo.getAid());
  1125. user.setShareType(0);
  1126. }
  1127. } catch (InvocationTargetException | IllegalAccessException e) {
  1128. e.printStackTrace();
  1129. }
  1130. userMapper.updateByPrimaryKeySelective(user);
  1131. return 1;
  1132. }
  1133. @Override
  1134. public Pagination<CustomerListOut> findEnteringAudit(CustomerListOut clo, Integer pageNo, Integer pageSize) {
  1135. Map<String,Object> params = disposeParams(clo);
  1136. if(!StringUtils.isBlank(clo.getAdminName()))params.put("adminName", clo.getAdminName());
  1137. @SuppressWarnings("unchecked")
  1138. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditList","findEnteringAuditCount",params,pageNo,pageSize);
  1139. return list;
  1140. }
  1141. @Override
  1142. public Pagination<CustomerListOut> findEnteringAuditIsNo(CustomerListOut clo, Integer pageNo, Integer pageSize) {
  1143. clo.setAid(TokenManager.getAdminId());
  1144. Map<String,Object> params = disposeParams(clo);
  1145. if(!StringUtils.isBlank(clo.getAdminName()))params.put("adminName", clo.getAdminName());
  1146. @SuppressWarnings("unchecked")
  1147. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditIsNoList","findEnteringAuditIsNoCount",params,pageNo,pageSize);
  1148. return list;
  1149. }
  1150. @Override
  1151. public int updateEnteringAudit(User bo) {
  1152. String[] ary=bo.getId().split(",");
  1153. for (String s : ary) {
  1154. String id=s;
  1155. Integer auditStatus=bo.getAuditStatus();
  1156. String auditOpinion=bo.getAuditOpinion();
  1157. userMapper.updateEnteringAudit(id,auditStatus,auditOpinion);
  1158. }
  1159. return 1;
  1160. }
  1161. @Override
  1162. public int updateMainContact(String ocbId,String uid) {
  1163. organizationContactBookMapper.updateSubContact(uid);
  1164. organizationContactBookMapper.updateMainContact(ocbId);
  1165. return 1;
  1166. }
  1167. @Override
  1168. public int updateRefusedCustomer(String id,String nickname, String mobile, String societyTag) {
  1169. User u=userMapper.selectByPrimaryKey(id);
  1170. u.setNickname(nickname);
  1171. u.setMobile(mobile);
  1172. u.setSocietyTag(societyTag);
  1173. return userMapper.updateRefusedCustomer(id, nickname, mobile, societyTag);
  1174. }
  1175. private void setCustomerList(List<CustomerListOut> tmpList){
  1176. Date now = new Date();
  1177. String s1,s2;
  1178. Long l1,l2;
  1179. int diff1,diff2;
  1180. for(CustomerListOut clo: tmpList){
  1181. //s1 = StringUtils.isBlank(clo.getLastFollowTime()) ? clo.getTransferTime() : clo.getLastFollowTime();
  1182. try {
  1183. if (StringUtils.isNotBlank(clo.getLastFollowTime())){
  1184. if(DateUtils.parseDate(clo.getLastFollowTime(), AFTConstants.YYYYMMDDHHMMSS).getTime()>DateUtils.parseDate(clo.getTransferTime(), AFTConstants.YYYYMMDDHHMMSS).getTime()) {
  1185. s1=clo.getLastFollowTime();
  1186. }else {
  1187. s1=clo.getTransferTime();
  1188. }
  1189. }else {
  1190. s1=clo.getTransferTime();
  1191. }
  1192. s2 = StringUtils.isBlank(clo.getLastSignTime()) ? clo.getTransferTime() : clo.getLastSignTime();
  1193. l1 = DateUtils.parseDate(s1, AFTConstants.YYYYMMDDHHMMSS).getTime();
  1194. l2 = DateUtils.parseDate(s2, AFTConstants.YYYYMMDDHHMMSS).getTime();
  1195. diff1 = (int)((l1 + AFTConstants.USER_FOLLOW_LIMIT_MS - now.getTime())/(24*3600*1000));
  1196. diff2 = (int)((l2 + AFTConstants.USER_SIGN_LIMIT_MS - now.getTime())/(24*3600*1000));
  1197. clo.setSurplusFollowTime(diff1 + "");
  1198. clo.setSurplusSignTime(diff2 + "");
  1199. } catch (ParseException e) {
  1200. e.printStackTrace();
  1201. }
  1202. }
  1203. }
  1204. @SuppressWarnings("unchecked")
  1205. @Override
  1206. public Pagination<CustomerListOut> listSignOrganizationCustomer(CustomerListIn cli, Integer pageNo,
  1207. Integer pageSize) {
  1208. cli.setAid(TokenManager.getAdminId());
  1209. // cli.setAid("1");
  1210. Map<String,Object> params = disposeParams(cli);
  1211. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignOrganizationCustomerList","selectSignOrganizationCustomerCount",params,pageNo,pageSize);
  1212. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  1213. setCustomerList(tmpList);
  1214. list.setList(tmpList);
  1215. return list;
  1216. }
  1217. @SuppressWarnings("unchecked")
  1218. @Override
  1219. public Pagination<CustomerListOut> listSignPersonalCustomer(CustomerListIn cli, Integer pageNo,
  1220. Integer pageSize) {
  1221. cli.setAid(TokenManager.getAdminId());
  1222. Map<String,Object> params = disposeParams(cli);
  1223. Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignPersonalCustomerList","selectSignPersonalCustomerCount",params,pageNo,pageSize);
  1224. List<CustomerListOut> tmpList = (List<CustomerListOut>)list.getList();
  1225. setCustomerList(tmpList);
  1226. list.setList(tmpList);
  1227. return list;
  1228. }
  1229. @Override
  1230. public List<LockingReleaseBo> selectLockedProject(String uid) {
  1231. return userMapper.selectLockedProject(uid,null,null,1,null);
  1232. }
  1233. @Override
  1234. public List<CustomerSimpleBo> getPrivateCustomerByName(String name) {
  1235. return userMapper.selectPrivateCustomerByName(name,TokenManager.getAdminId());
  1236. }
  1237. @Override
  1238. public List<CustomerSimpleBo> getSignedCustomerByName(String name) {
  1239. return userMapper.selectSignedCustomerByName(name,TokenManager.getAdminId());
  1240. }
  1241. private int updateUserLock(String uid,String aid,Integer oldStatus,Integer newStatus){
  1242. return userLockReleaseMapper.updateUserLock(uid,aid,oldStatus,newStatus);
  1243. }
  1244. private int addUserLock(String uid,String aid,Date lockTime){
  1245. UserLockRelease ulr = new UserLockRelease();
  1246. ulr.setId(UUID.randomUUID().toString());
  1247. ulr.setType(0);
  1248. ulr.setAid(aid);
  1249. ulr.setLockTime(lockTime);
  1250. ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
  1251. ulr.setUid(uid);
  1252. return userLockReleaseMapper.insert(ulr);
  1253. }
  1254. /**
  1255. * 查询需要释放客户
  1256. * @param uid
  1257. * @return
  1258. */
  1259. @Override
  1260. public List<LockingReleaseBo> selectWaitReleaseCustomer(String uid){
  1261. return userLockReleaseMapper.selectWaitReleaseCustomer(uid);
  1262. }
  1263. /**
  1264. * 查询需要释放的业务
  1265. * @param uid
  1266. * @return
  1267. */
  1268. @Override
  1269. public List<LockingReleaseBo> selectWaitReleaseBusiness(String uid){
  1270. return userLockReleaseMapper.selectWaitReleaseBusiness(uid);
  1271. }
  1272. /**
  1273. * 处理需要释放
  1274. * @param list
  1275. */
  1276. @Override
  1277. public void updateReleaseLock(Date releaseTime){
  1278. SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1279. String time=formatter.format(releaseTime);
  1280. userMapper.updateReleaseLock(time);
  1281. userLockReleaseMapper.updateReleaseLock(time);
  1282. }
  1283. @Override
  1284. public int updateAgainProjectTask(String uid, String projectId,String aid) {
  1285. List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, TokenManager.getAdminId(), projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
  1286. // List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, aid, projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
  1287. UserLockRelease u= new UserLockRelease();
  1288. if (businessLockedList.size()==1) {
  1289. for (LockingReleaseBo l : businessLockedList) {
  1290. u.setId(l.getId());
  1291. u.setLockTime(new Date());
  1292. }
  1293. return userLockReleaseMapper.updateByPrimaryKeySelective(u);
  1294. }
  1295. return 0;
  1296. }
  1297. @Override
  1298. public int updateInformationMaintainerr(String id, String aid) {
  1299. User u=new User();
  1300. u.setId(id);
  1301. u.setInformationMaintainer(aid);
  1302. return userMapper.updateByPrimaryKeySelective(u);
  1303. }
  1304. @SuppressWarnings("unchecked")
  1305. @Override
  1306. public Pagination<CustomerListIn> listCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1307. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1308. cli.setAid(TokenManager.getAdminId());
  1309. // cli.setAid("1");
  1310. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1311. Map<String,Object> params = disposeParams(cli);
  1312. return (Pagination<CustomerListIn>) findPage("selectCustomerInformationList","selectCustomerInformationCount",params,pageNo,pageSize);
  1313. }
  1314. @SuppressWarnings("unchecked")
  1315. @Override
  1316. public Pagination<CustomerListIn> listDepCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
  1317. cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
  1318. cli.setAid(TokenManager.getAdminId());
  1319. // cli.setAid("1");
  1320. cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
  1321. Map<String,Object> params = disposeParams(cli);
  1322. return (Pagination<CustomerListIn>) findPage("selectDepCustomerInformationList","selectDepCustomerInformationCount",params,pageNo,pageSize);
  1323. }
  1324. public boolean checkCustomerInformation(String uid) {
  1325. int i=userMapper.checkCustomerInformation(uid);
  1326. if (i<1) {
  1327. return true;
  1328. }
  1329. return false;
  1330. }
  1331. @Override
  1332. public void updatePendingReleaseLock(List<LockingReleaseBo> newList) {
  1333. String lockIds = "";
  1334. for(LockingReleaseBo bo:newList){
  1335. lockIds += bo.getId() + ",";
  1336. }
  1337. if(lockIds.length()>0) {
  1338. lockIds = "'" + lockIds.substring(0,lockIds.length()-1).replace(",", "','") + "'";
  1339. userLockReleaseMapper.updatePendingReleaseLock(lockIds);
  1340. }
  1341. }
  1342. @Override
  1343. public List<LockingReleaseBo> selectPendinglockUserList() {
  1344. return userLockReleaseMapper.selectPendinglockUserList();
  1345. }
  1346. @Override
  1347. public int updateUserLevel(User u) {
  1348. return userMapper.updateByPrimaryKeySelective(u);
  1349. }
  1350. }