UserArchivesServiceImpl.java 13 KB

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