UserArchivesServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. package com.goafanti.customer.service.impl;
  2. import com.goafanti.Interview.bo.selectByUidAidBo;
  3. import com.goafanti.common.constant.AFTConstants;
  4. import com.goafanti.common.dao.*;
  5. import com.goafanti.common.model.*;
  6. import com.goafanti.common.utils.DateUtils;
  7. import com.goafanti.common.utils.excel.NewExcelUtil;
  8. import com.goafanti.core.mybatis.BaseMybatisDao;
  9. import com.goafanti.core.mybatis.page.Pagination;
  10. import com.goafanti.core.shiro.token.TokenManager;
  11. import com.goafanti.customer.bo.InputSelectUserArchives;
  12. import com.goafanti.customer.bo.OutSelectUserArchives;
  13. import com.goafanti.customer.bo.UserArchivesDetails;
  14. import com.goafanti.customer.service.CustomerService;
  15. import com.goafanti.customer.service.UserArchivesService;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.stereotype.Service;
  19. import javax.annotation.Resource;
  20. import java.util.*;
  21. import java.util.stream.Collectors;
  22. /**
  23. * 客户档案表(UserArchives)表服务实现类
  24. *
  25. * @author makejava
  26. * @since 2024-07-12 11:52:01
  27. */
  28. @Service("userArchivesService")
  29. public class UserArchivesServiceImpl extends BaseMybatisDao< UserArchivesMapper> implements UserArchivesService {
  30. @Resource
  31. private UserArchivesMapper userArchivesMapper;
  32. @Resource
  33. private UserArchivesInterviewMapper userArchivesInterviewMapper;
  34. @Resource
  35. private CustomerService customerService;
  36. @Resource
  37. private UserMapper userMapper;
  38. @Resource
  39. private UserMidMapper userMidMapper;
  40. @Resource
  41. private UserLimitCheckMapper userLimitCheckMapper;
  42. @Resource
  43. private AdminMapper adminMapper;
  44. @Resource
  45. private UserDataLogMapper userDataLogMapper;
  46. @Resource
  47. private UserFirstInterviewMapper userFirstInterviewMapper;
  48. @Resource
  49. private OrganizationIdentityMapper organizationIdentityMapper;
  50. @Resource
  51. private DistrictGlossoryMapper districtGlossoryMapper;
  52. @Resource
  53. private UserInterviewProjectMapper userInterviewProjectMapper;
  54. @Value(value = "${upload.path}")
  55. private final String uploadPath = null;
  56. @Override
  57. public Pagination<UserArchives> list(UserArchives userArchives, Integer pageNo, Integer pageSize) {
  58. Map<String, Object> params = new HashMap<>();
  59. params.put("in",userArchives);
  60. return (Pagination<UserArchives>) findPage("findUserArchivesList",
  61. "findUserArchivesCount", params, pageNo, pageSize);
  62. }
  63. @Override
  64. public UserArchives queryByUid(String id) {
  65. UserArchives userArchives =userArchivesMapper.queryByUid(id);
  66. if (userArchives==null)userArchives =new UserArchives();
  67. return userArchives;
  68. }
  69. @Override
  70. public Object queryByUidAll(String id) {
  71. //查询等级 0=自己 1=全部
  72. int type=0;
  73. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  74. type=1;
  75. }
  76. UserArchivesDetails user = customerService.selectUserByUid(id);
  77. User u = userMapper.queryById(id);
  78. OrganizationIdentity ori = organizationIdentityMapper.selectOrgIdentityByUserId(id);
  79. pushProvincePlus(ori, user);
  80. if (u.getAid().equals(TokenManager.getAdminId())){
  81. user.setMyUser(1);
  82. }else {
  83. user.setMyUser(0);
  84. }
  85. user.setSignBills(u.getSignBills());
  86. UserArchives userArchives = queryByUid(id);
  87. List<OrganizationContactBook> customerContacts = userMapper.findCustomerContacts(id, TokenManager.getAdminId());
  88. List<OrganizationContactBook> collect = customerContacts.stream()
  89. .filter(e -> e.getMajor() == 1).collect(Collectors.toList());
  90. if (user.getMyUser()==0){
  91. for (OrganizationContactBook ob : collect) {
  92. ob.setName("***");
  93. ob.setMobile("***");
  94. }
  95. }
  96. if (!customerContacts.isEmpty()){
  97. user.setContactList(collect);
  98. }
  99. BeanUtils.copyProperties(userArchives, user);
  100. user.setUid(id);
  101. List<selectByUidAidBo> userArchivesInterviews;
  102. if (type==0){
  103. userArchivesInterviews = userArchivesInterviewMapper.selectByUidAid(id, TokenManager.getAdminId());
  104. user.setInterviewList(userArchivesInterviews);
  105. }else {
  106. userArchivesInterviews = userArchivesInterviewMapper.selectByUidAid(id, TokenManager.getAdminId());
  107. }
  108. user.setInterviewList(userArchivesInterviews);
  109. //获取首次面谈时间
  110. List<UserFirstInterview> firstList;
  111. if (type == 0){
  112. firstList = userFirstInterviewMapper.selectByUidAid(id, TokenManager.getAdminId());
  113. }else {
  114. firstList = userFirstInterviewMapper.selectByUidAid(id, null);
  115. }
  116. if (!firstList.isEmpty()){
  117. UserFirstInterview userFirstInterview = firstList.get(0);
  118. user.setFirstInterviewDate(userFirstInterview.getFirstTime());
  119. }
  120. List<UserInterviewProjectBo> userInterviewProjects ;
  121. if (type==0){
  122. userInterviewProjects =userInterviewProjectMapper.selectByAid(TokenManager.getAdminId(), id);
  123. } else {
  124. userInterviewProjects =userInterviewProjectMapper.selectByAid(null, id);
  125. }
  126. user.setProjectList(userInterviewProjects);
  127. return user;
  128. }
  129. private void pushProvincePlus(OrganizationIdentity ori, UserArchivesDetails user) {
  130. user.setLocationProvince(ori.getLocationProvince());
  131. user.setLocationCity(ori.getLocationCity());
  132. user.setLocationArea(ori.getLocationArea());
  133. user.setIndustryName(ori.getIndustryName());
  134. List<DistrictGlossory> all = districtGlossoryMapper.getAll();
  135. if (ori.getLocationProvince()!=null){
  136. all.stream().filter(e -> e.getLevel()==1).collect(Collectors.toList()).forEach(e -> {
  137. if (ori.getLocationProvince().equals(e.getId())){
  138. user.setLocationProvinceName(e.getName());
  139. }
  140. });
  141. }
  142. if (ori.getLocationCity()!=null){
  143. all.stream().filter(e -> e.getLevel()==2).collect(Collectors.toList()).forEach(e -> {
  144. if (ori.getLocationCity().equals(e.getId())){
  145. user.setLocationCityName(e.getName());
  146. }
  147. });
  148. }
  149. if (ori.getLocationArea()!=null){
  150. all.stream().filter(e -> e.getLevel()==3).collect(Collectors.toList()).forEach(e -> {
  151. if (ori.getLocationArea().equals(e.getId())){
  152. user.setLocationAreaName(e.getName());
  153. }
  154. });
  155. }
  156. }
  157. @Override
  158. public boolean checkPermission(String id) {
  159. User user = userMapper.queryById(id);
  160. if (user.getAid().equals(TokenManager.getAdminId())){
  161. return false;
  162. }
  163. UserLimitCheck userLimitCheck = userLimitCheckMapper.selectByUid(id);
  164. //如果没有和大于时间则不能查看
  165. return userLimitCheck == null || System.currentTimeMillis() > userLimitCheck.getCheckTime().getTime();
  166. }
  167. /**
  168. * 通过ID查询单条数据
  169. *
  170. * @param id 主键
  171. * @return 实例对象
  172. */
  173. @Override
  174. public UserArchives queryById(Integer id) {
  175. return this.userArchivesMapper.queryById(id);
  176. }
  177. /**
  178. * 新增数据
  179. *
  180. * @param userArchives 实例对象
  181. * @return 实例对象
  182. */
  183. @Override
  184. public UserArchives insert(UserArchives userArchives) {
  185. UserArchives query = userArchivesMapper.queryByUid(userArchives.getUid());
  186. if (query != null){
  187. userArchives.setId(query.getId());
  188. return update(userArchives,null);
  189. }else {
  190. if (userArchives.getAppearancePatentCount()!=null||
  191. userArchives.getInventionPatentCount()!=null||
  192. userArchives.getUtilityModelCount() !=null||
  193. userArchives.getSoftwareWorksCount()!=null||
  194. userArchives.getOtherCount()!=null
  195. ){
  196. int count = getCount(userArchives);
  197. userArchives.setPatentCount(count);
  198. }
  199. if(userArchives.getPatentCount()==null)userArchives.setPatentCount(0);
  200. userArchives.setCreateTime(new Date());
  201. this.userArchivesMapper.insert(userArchives);
  202. }
  203. return userArchives;
  204. }
  205. /**
  206. * 修改数据
  207. *
  208. * @param userArchives 实例对象
  209. * @return 实例对象
  210. */
  211. @Override
  212. public UserArchives update(UserArchives userArchives,Integer channelType) {
  213. if (userArchives.getAppearancePatentCount()!=null||
  214. userArchives.getInventionPatentCount()!=null||
  215. userArchives.getUtilityModelCount() !=null||
  216. userArchives.getSoftwareWorksCount()!=null||
  217. userArchives.getOtherCount()!=null
  218. ){
  219. int count = getCount(userArchives);
  220. userArchives.setPatentCount(count);
  221. }
  222. if (channelType!=null){
  223. String uid=null;
  224. if (userArchives.getUid()==null){
  225. UserArchives useData = this.queryById(userArchives.getId());
  226. uid=useData.getUid();
  227. }else {
  228. uid=userArchives.getUid();
  229. }
  230. userMidMapper.updateByUid(new UserMid(uid,channelType));
  231. }
  232. if(userArchives.getId()==null){
  233. return insert(userArchives);
  234. }else {
  235. addUserLog( userArchives);
  236. userArchives.setUpdateTime(new Date());
  237. this.userArchivesMapper.update(userArchives);
  238. return this.queryById(userArchives.getId());
  239. }
  240. }
  241. private void addUserLog(UserArchives userArchives) {
  242. UserArchives use = userArchivesMapper.queryById(userArchives.getId());
  243. Admin admin = adminMapper.selectById(TokenManager.getAdminId());
  244. List<UserDataLog> list =new ArrayList<>();
  245. if(userArchives.getFinancialData()!=null&&!Objects.equals(use.getFinancialData(),userArchives.getFinancialData())){
  246. String builder = admin.getName() + "修改了财务数据: " + use.getFinancialData() + "=>" + userArchives.getFinancialData();
  247. UserDataLog userDataLog = new UserDataLog(userArchives.getUid(), builder,1);
  248. list.add(userDataLog);
  249. }
  250. if (userArchives.getEarlyCommunication()!=null&&!Objects.equals(use.getEarlyCommunication(),userArchives.getEarlyCommunication())){
  251. String builder = admin.getName() + "修改了前期沟通: " + use.getEarlyCommunication() + "=>" + userArchives.getEarlyCommunication();
  252. UserDataLog userDataLog = new UserDataLog(userArchives.getUid(), builder,2);
  253. list.add(userDataLog);
  254. }
  255. if (userArchives.getInterviewIdeas()!=null&&!Objects.equals(use.getInterviewIdeas(),userArchives.getInterviewIdeas())){
  256. String builder = admin.getName() + "修改了面谈思路: " + use.getInterviewIdeas() + "=>" + userArchives.getInterviewIdeas();
  257. UserDataLog userDataLog = new UserDataLog(userArchives.getUid(), builder,3);
  258. list.add(userDataLog);
  259. }
  260. if (!list.isEmpty())userDataLogMapper.insertBatch(list);
  261. }
  262. /**
  263. * 计算专利总数,必须5个都传,不然会导致计算漏掉
  264. * @param userArchives 用户档案参数
  265. * @return count
  266. */
  267. private int getCount(UserArchives userArchives) {
  268. int count = 0;
  269. if (userArchives.getAppearancePatentCount()!=null){
  270. count+= userArchives.getAppearancePatentCount();
  271. }
  272. if (userArchives.getInventionPatentCount()!=null){
  273. count+= userArchives.getInventionPatentCount();
  274. }
  275. if (userArchives.getUtilityModelCount() !=null){
  276. count+= userArchives.getUtilityModelCount();
  277. }
  278. if (userArchives.getSoftwareWorksCount() !=null){
  279. count+= userArchives.getSoftwareWorksCount();
  280. }
  281. if (userArchives.getOtherCount()!=null){
  282. count+= userArchives.getOtherCount();
  283. }
  284. return count;
  285. }
  286. /**
  287. * 通过主键删除数据
  288. *
  289. * @param id 主键
  290. * @return 是否成功
  291. */
  292. @Override
  293. public boolean deleteById(Integer id) {
  294. return this.userArchivesMapper.deleteById(id) > 0;
  295. }
  296. @Override
  297. public Object selectUserArchives(InputSelectUserArchives in) {
  298. Map<String, Object> params = getParams(in);
  299. Pagination<?> page = findPage("selectUserArchivesList",
  300. "selectUserArchivesCount", params, in.getPageNo(), in.getPageSize());
  301. // List<OutSelectUserArchives> list = (List<OutSelectUserArchives>) page.getList();
  302. // list.stream().forEach(e ->{
  303. // List<selectByUidAidBo> userArchivesInterviews = userArchivesInterviewMapper.selectByUidAid(e.getId(), null);
  304. // e.setPublicContent(pushContent(userArchivesInterviews));
  305. // });
  306. return page;
  307. }
  308. private String pushContent(List<selectByUidAidBo> list) {
  309. if (!list.isEmpty()){
  310. StringBuilder builder = new StringBuilder();
  311. list.stream().forEach(e ->{
  312. builder.append(e.getAdminName()).append( "[").append(DateUtils.formatDateChineseYYYYMMddHH(e.getCreateTime())).append("]:");
  313. builder.append("前期沟通-客户的难处:").append(e.getEarlyCommunication()).append("\n");
  314. builder.append("客户的需求:").append(e.getCustomerDemand()).append("\n");
  315. builder.append("面谈思路:").append(e.getInterviewIdeas()).append("\n");
  316. builder.append("面谈达成的目的:").append(e.getInterviewPurpose()).append("\n");
  317. builder.append("经理/上级面谈建议:").append(e.getInterviewRecommend()).append("\n");
  318. if (e.getInterviewFeedback()!=null)builder.append("面谈的反馈:").append(e.getInterviewFeedback()).append("\n");
  319. if (e.getFollowUpPlan()!=null)builder.append("后续计划:").append(e.getFollowUpPlan()).append("\n");
  320. builder.append("\n");
  321. });
  322. return builder.toString();
  323. }
  324. return null;
  325. }
  326. private Map<String, Object> getParams(InputSelectUserArchives in) {
  327. Map<String, Object> params = new HashMap<>();
  328. if (in.getNewChannel() != null)params.put("newChannel", in.getNewChannel());
  329. if (in.getShareType() != null)params.put("shareType", in.getShareType());
  330. if (in.getChannelType() != null){
  331. String[] split = in.getChannelType().split(",");
  332. params.put("channelType", split);
  333. }
  334. if (in.getName() != null)params.put("name", in.getName());
  335. if (in.getAid() != null)params.put("aid", in.getAid());
  336. if (in.getBusinessScope() != null)params.put("businessScope", in.getBusinessScope());
  337. if (in.getIndustry() != null){
  338. String[] split = in.getIndustry().split(",");
  339. params.put("industry", split);
  340. }
  341. if (in.getSignBills()!=null)params.put("signBills", in.getSignBills());
  342. if (in.getStartTime() != null&&in.getEndTime() != null){
  343. params.put("startTime", in.getStartTime());
  344. params.put("endTime", in.getEndTime()+" 23:59:59");
  345. }
  346. return params;
  347. }
  348. @Override
  349. public Object addAwards(String uid,Integer status) {
  350. return updateAwards(uid,status);
  351. }
  352. @Override
  353. public Object updateAwards(String uid, Integer status) {
  354. UserArchives use = userArchivesMapper.queryByUid(uid);
  355. UserArchives userArchives = new UserArchives();
  356. userArchives.setId(use.getId());
  357. userArchives.setAwardsStatus(status);
  358. if (status==2)userArchives.setAwardsTime(new Date());
  359. userArchivesMapper.update(userArchives);
  360. if (status==2){
  361. userArchivesMapper.updateStatus();
  362. }
  363. return 1;
  364. }
  365. @Override
  366. public Object selectUserArchivesExport(InputSelectUserArchives in) {
  367. Map<String, Object> params = getParams(in);
  368. List<OutSelectUserArchives> list= (List<OutSelectUserArchives>) findList("selectUserArchivesList",
  369. params, 1, 999999);
  370. list.stream().forEach(e ->{
  371. List<selectByUidAidBo> userArchivesInterviews = userArchivesInterviewMapper.selectByUidAid(e.getId(), null);
  372. e.setPublicContent(pushContent(userArchivesInterviews));
  373. });
  374. NewExcelUtil<OutSelectUserArchives> newExcelUtil = new NewExcelUtil<>(OutSelectUserArchives.class);
  375. return newExcelUtil.exportExcel( list,"用户档案",uploadPath);
  376. }
  377. }