CustomerServiceImpl.java 60 KB

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