UserServiceImpl.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.fdkankan.manage.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.fdkankan.manage.common.ResultCode;
  6. import com.fdkankan.manage.exception.BusinessException;
  7. import com.fdkankan.manage.common.PageInfo;
  8. import com.fdkankan.manage.entity.User;
  9. import com.fdkankan.manage.httpClient.service.LaserService;
  10. import com.fdkankan.manage.mapper.IUserMapper;
  11. import com.fdkankan.manage.service.*;
  12. import com.fdkankan.manage.vo.request.SceneParam;
  13. import com.fdkankan.manage.vo.request.UserIncrementParam;
  14. import com.fdkankan.manage.vo.request.UserParam;
  15. import com.fdkankan.manage.vo.response.UserVo;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.BeanUtils;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.stream.Collectors;
  25. /**
  26. * <p>
  27. * 用户信息表 服务实现类
  28. * </p>
  29. *
  30. * @author
  31. * @since 2022-06-16
  32. */
  33. @Service
  34. public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements IUserService {
  35. @Autowired
  36. private IUserIncrementService userIncrementService;
  37. @Autowired
  38. private ICameraDetailService cameraDetailService;
  39. @Autowired
  40. private ISceneService sceneService;
  41. @Autowired
  42. private ISceneProService sceneProService;
  43. @Autowired
  44. private IScenePlusService scenePlusService;
  45. @Autowired
  46. private LaserService laserService;
  47. @Override
  48. public PageInfo pageList(UserParam param) {
  49. LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
  50. if(StringUtils.isNotBlank(param.getUserName())){
  51. wrapper.like(User::getUserName,param.getUserName());
  52. }
  53. if(StringUtils.isNotBlank(param.getEmail())){
  54. wrapper.like(User::getEmail,param.getEmail());
  55. }
  56. wrapper.orderByDesc(User::getCreateTime);
  57. Page<User> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  58. List<User> records = page.getRecords();
  59. List<UserVo> userVo = getUserVo(records);
  60. Page<UserVo> pageVo = new Page<>(page.getCurrent(),page.getSize());
  61. pageVo.setTotal(page.getTotal());
  62. pageVo.setRecords(userVo);
  63. return PageInfo.PageInfo(pageVo);
  64. }
  65. @Override
  66. public void addDownNum(UserIncrementParam param) {
  67. User user = this.getById(param.getUserId());
  68. if(user == null){
  69. throw new BusinessException(ResultCode.USER_NOT_EXIST);
  70. }
  71. Integer totalNum = user.getDownloadNumTotal() == null ? 0 : user.getDownloadNumTotal() + param.getCount();
  72. user.setDownloadNumTotal(totalNum);
  73. this.updateById(user);
  74. }
  75. @Override
  76. public List<UserVo> userDetail(Integer userId) {
  77. User user = this.getById(userId);
  78. if(user!=null){
  79. return getUserVo(Arrays.asList(user));
  80. }
  81. return new ArrayList<>();
  82. }
  83. private List<UserVo> getUserVo(List<User> userList){
  84. List<UserVo> voList = new ArrayList<>();
  85. if(userList.size() >0){
  86. List<Long> userIdList = userList.parallelStream().map(User::getId).collect(Collectors.toList());
  87. HashMap<Long,Long> incrementCountMap = userIncrementService.getValidCountGroupByUserId(userIdList);
  88. HashMap<Long,Long> cameraCountMap = cameraDetailService.getCountGroupByUserId(userIdList);
  89. HashMap<Long,Long> sceneCountMap = sceneService.getCountGroupByUserId(userIdList);
  90. HashMap<Long,Long> sceneProCountMap = sceneProService.getCountGroupByUserId(userIdList,0);
  91. HashMap<Long,Long> scenePlusCountMap = scenePlusService.getCountGroupByUserId(userIdList,0);
  92. // HashMap<Long,Long> sceneProCountObjMap = sceneProService.getCountGroupByUserId(userIdList,1);
  93. // HashMap<Long,Long> scenePlusCountObjMap = scenePlusService.getCountGroupByUserId(userIdList,1);
  94. for (User user :userList) {
  95. long incrementCount = incrementCountMap.get(user.getId()) == null ? 0 : incrementCountMap.get(user.getId());
  96. long cameraCount = cameraCountMap.get(user.getId()) == null ? 0 : cameraCountMap.get(user.getId());
  97. long sceneCount = sceneCountMap.get(user.getId()) == null ? 0 : sceneCountMap.get(user.getId());
  98. long sceneProCount = sceneProCountMap.get(user.getId()) == null ? 0 : sceneProCountMap.get(user.getId());
  99. long scenePlusCount = scenePlusCountMap.get(user.getId()) == null ? 0 : scenePlusCountMap.get(user.getId());
  100. // long sceneProObjCount = sceneProCountObjMap.get(user.getId()) == null ? 0 : sceneProCountObjMap.get(user.getId());
  101. // long scenePlusObjCount = scenePlusCountObjMap.get(user.getId()) == null ? 0 : scenePlusCountObjMap.get(user.getId());
  102. SceneParam param = new SceneParam();
  103. param.setUserName(user.getUserName());
  104. PageInfo pageInfo = laserService.pageList(param);
  105. UserVo vo = new UserVo();
  106. BeanUtils.copyProperties(user,vo);
  107. vo.setVip(incrementCount > 0 ? 1: 0);
  108. vo.setIncrementCount(incrementCount);
  109. vo.setSurDownNum(user.getDownloadNumTotal() - user.getDownloadNum());
  110. vo.setCameraCount(cameraCount);
  111. vo.setSceneNum(sceneCount + sceneProCount + scenePlusCount + pageInfo.getTotal());
  112. voList.add(vo);
  113. }
  114. }
  115. return voList;
  116. }
  117. @Override
  118. public HashMap<Long, User> getByIds(List<Long> userIds) {
  119. LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
  120. wrapper.in(User::getId,userIds);
  121. List<User> list = this.list(wrapper);
  122. HashMap<Long,User> map = new HashMap<>();
  123. list.forEach(entity -> map.put(entity.getId(),entity));
  124. return map;
  125. }
  126. @Override
  127. public List<User> getByUserName(String userName) {
  128. LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
  129. wrapper.eq(User::getUserName,userName);
  130. return this.list(wrapper);
  131. }
  132. @Override
  133. public Boolean checkUserName(String userName) {
  134. List<User> userList = this.getByUserName(userName);
  135. if(userList == null || userList.size() <=0){
  136. return false;
  137. }
  138. return true;
  139. }
  140. @Override
  141. public void addUcenterUser(UserParam userParam) {
  142. if(StringUtils.isBlank(userParam.getUserName()) || StringUtils.isBlank(userParam.getNickName()) || StringUtils.isBlank(userParam.getPassword())){
  143. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  144. }
  145. Boolean ubo = this.checkUserName(userParam.getUserName());
  146. if(ubo){
  147. throw new BusinessException(ResultCode.USER_EXIST);
  148. }
  149. }
  150. }