123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package com.fdkankan.manage.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.common.PageInfo;
- import com.fdkankan.manage.entity.User;
- import com.fdkankan.manage.httpClient.service.LaserService;
- import com.fdkankan.manage.mapper.IUserMapper;
- import com.fdkankan.manage.service.*;
- import com.fdkankan.manage.vo.request.SceneParam;
- import com.fdkankan.manage.vo.request.UserIncrementParam;
- import com.fdkankan.manage.vo.request.UserParam;
- import com.fdkankan.manage.vo.response.UserVo;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 用户信息表 服务实现类
- * </p>
- *
- * @author
- * @since 2022-06-16
- */
- @Service
- public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements IUserService {
- @Autowired
- private IUserIncrementService userIncrementService;
- @Autowired
- private ICameraDetailService cameraDetailService;
- @Autowired
- private ISceneService sceneService;
- @Autowired
- private ISceneProService sceneProService;
- @Autowired
- private IScenePlusService scenePlusService;
- @Autowired
- private LaserService laserService;
- @Override
- public PageInfo pageList(UserParam param) {
- LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
- if(StringUtils.isNotBlank(param.getUserName())){
- wrapper.like(User::getUserName,param.getUserName());
- }
- if(StringUtils.isNotBlank(param.getEmail())){
- wrapper.like(User::getEmail,param.getEmail());
- }
- wrapper.orderByDesc(User::getCreateTime);
- Page<User> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- List<User> records = page.getRecords();
- List<UserVo> userVo = getUserVo(records);
- Page<UserVo> pageVo = new Page<>(page.getCurrent(),page.getSize());
- pageVo.setTotal(page.getTotal());
- pageVo.setRecords(userVo);
- return PageInfo.PageInfo(pageVo);
- }
- @Override
- public void addDownNum(UserIncrementParam param) {
- User user = this.getById(param.getUserId());
- if(user == null){
- throw new BusinessException(ResultCode.USER_NOT_EXIST);
- }
- Integer totalNum = user.getDownloadNumTotal() == null ? 0 : user.getDownloadNumTotal() + param.getCount();
- user.setDownloadNumTotal(totalNum);
- this.updateById(user);
- }
- @Override
- public List<UserVo> userDetail(Integer userId) {
- User user = this.getById(userId);
- if(user!=null){
- return getUserVo(Arrays.asList(user));
- }
- return new ArrayList<>();
- }
- private List<UserVo> getUserVo(List<User> userList){
- List<UserVo> voList = new ArrayList<>();
- if(userList.size() >0){
- List<Long> userIdList = userList.parallelStream().map(User::getId).collect(Collectors.toList());
- HashMap<Long,Long> incrementCountMap = userIncrementService.getValidCountGroupByUserId(userIdList);
- HashMap<Long,Long> cameraCountMap = cameraDetailService.getCountGroupByUserId(userIdList);
- HashMap<Long,Long> sceneCountMap = sceneService.getCountGroupByUserId(userIdList);
- HashMap<Long,Long> sceneProCountMap = sceneProService.getCountGroupByUserId(userIdList,0);
- HashMap<Long,Long> scenePlusCountMap = scenePlusService.getCountGroupByUserId(userIdList,0);
- // HashMap<Long,Long> sceneProCountObjMap = sceneProService.getCountGroupByUserId(userIdList,1);
- // HashMap<Long,Long> scenePlusCountObjMap = scenePlusService.getCountGroupByUserId(userIdList,1);
- for (User user :userList) {
- long incrementCount = incrementCountMap.get(user.getId()) == null ? 0 : incrementCountMap.get(user.getId());
- long cameraCount = cameraCountMap.get(user.getId()) == null ? 0 : cameraCountMap.get(user.getId());
- long sceneCount = sceneCountMap.get(user.getId()) == null ? 0 : sceneCountMap.get(user.getId());
- long sceneProCount = sceneProCountMap.get(user.getId()) == null ? 0 : sceneProCountMap.get(user.getId());
- long scenePlusCount = scenePlusCountMap.get(user.getId()) == null ? 0 : scenePlusCountMap.get(user.getId());
- // long sceneProObjCount = sceneProCountObjMap.get(user.getId()) == null ? 0 : sceneProCountObjMap.get(user.getId());
- // long scenePlusObjCount = scenePlusCountObjMap.get(user.getId()) == null ? 0 : scenePlusCountObjMap.get(user.getId());
- SceneParam param = new SceneParam();
- param.setUserName(user.getUserName());
- PageInfo pageInfo = laserService.pageList(param);
- UserVo vo = new UserVo();
- BeanUtils.copyProperties(user,vo);
- vo.setVip(incrementCount > 0 ? 1: 0);
- vo.setIncrementCount(incrementCount);
- vo.setSurDownNum(user.getDownloadNumTotal() - user.getDownloadNum());
- vo.setCameraCount(cameraCount);
- vo.setSceneNum(sceneCount + sceneProCount + scenePlusCount + pageInfo.getTotal());
- voList.add(vo);
- }
- }
- return voList;
- }
- @Override
- public HashMap<Long, User> getByIds(List<Long> userIds) {
- LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(User::getId,userIds);
- List<User> list = this.list(wrapper);
- HashMap<Long,User> map = new HashMap<>();
- list.forEach(entity -> map.put(entity.getId(),entity));
- return map;
- }
- @Override
- public List<User> getByUserName(String userName) {
- LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(User::getUserName,userName);
- return this.list(wrapper);
- }
- @Override
- public Boolean checkUserName(String userName) {
- List<User> userList = this.getByUserName(userName);
- if(userList == null || userList.size() <=0){
- return false;
- }
- return true;
- }
- @Override
- public void addUcenterUser(UserParam userParam) {
- if(StringUtils.isBlank(userParam.getUserName()) || StringUtils.isBlank(userParam.getNickName()) || StringUtils.isBlank(userParam.getPassword())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Boolean ubo = this.checkUserName(userParam.getUserName());
- if(ubo){
- throw new BusinessException(ResultCode.USER_EXIST);
- }
- }
- }
|