CustomerServiceImpl.java 61 KB

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