|
@@ -1,11 +1,32 @@
|
|
|
package com.fdkankan.manage.service.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.manage.common.PageInfo;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
+import com.fdkankan.manage.entity.JyUser;
|
|
|
import com.fdkankan.manage.entity.JyUserShare;
|
|
|
+import com.fdkankan.manage.entity.ScenePlus;
|
|
|
+import com.fdkankan.manage.entity.UserShareParam;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
import com.fdkankan.manage.mapper.IJyUserShareMapper;
|
|
|
+import com.fdkankan.manage.service.IJyUserService;
|
|
|
import com.fdkankan.manage.service.IJyUserShareService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.manage.service.IScenePlusService;
|
|
|
+import com.fdkankan.manage.service.IUserService;
|
|
|
+import com.fdkankan.manage.vo.response.UserShareSceneVo;
|
|
|
+import com.fdkankan.manage.vo.response.UserShareVo;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 服务实现类
|
|
@@ -17,4 +38,72 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class JyUserShareServiceImpl extends ServiceImpl<IJyUserShareMapper, JyUserShare> implements IJyUserShareService {
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IJyUserService jyUserService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusService scenePlusService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pageList(UserShareParam param) {
|
|
|
+ JyUser mainUser = jyUserService.getBySysId(StpUtil.getLoginId().toString());
|
|
|
+ if(mainUser == null){
|
|
|
+ throw new BusinessException(ResultCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ if(param.getType() == null || param.getType() == 0){
|
|
|
+ param.setMainUserId(mainUser.getId());
|
|
|
+ }
|
|
|
+ if(param.getType() == 1){
|
|
|
+ param.setJyUserId(mainUser.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<UserShareVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(), param.getPageSize()),param);
|
|
|
+ if(param.getType() == 1){
|
|
|
+ List<Long> userIds = page.getRecords().stream().map(UserShareVo::getUserId).collect(Collectors.toList());
|
|
|
+ HashMap<Long, Long> map = scenePlusService.getCountGroupByUserId(userIds, null);
|
|
|
+ for (UserShareVo record : page.getRecords()) {
|
|
|
+ record.setSceneCount(map.get(record.getUserId())== null?0: map.get(record.getUserId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(Integer jyUserId) {
|
|
|
+ JyUser jyUser = jyUserService.getById(jyUserId);
|
|
|
+ if(jyUser == null || jyUser.getStatus() != 1){
|
|
|
+ throw new BusinessException(ResultCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ JyUser mainUser = jyUserService.getBySysId(StpUtil.getLoginId().toString());
|
|
|
+ if(mainUser == null){
|
|
|
+ throw new BusinessException(ResultCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ JyUserShare jyUserShare = this.getByMainUserIdAndUserId(mainUser.getId(),jyUserId);
|
|
|
+ if(jyUserShare != null){
|
|
|
+ throw new BusinessException(ResultCode.SHARE_USER_ERROR);
|
|
|
+ }
|
|
|
+ jyUserShare = new JyUserShare();
|
|
|
+ jyUserShare.setJyUserId(jyUserId);
|
|
|
+ jyUserShare.setMainJyUserId(mainUser.getId());
|
|
|
+ this.save(jyUserShare);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JyUserShare getByMainUserIdAndUserId(Integer sysUserId, Integer jyUserId) {
|
|
|
+ LambdaQueryWrapper<JyUserShare> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(JyUserShare::getMainJyUserId,sysUserId);
|
|
|
+ wrapper.eq(JyUserShare::getJyUserId,jyUserId);
|
|
|
+ return this.getOne(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object sceneList(UserShareParam param) {
|
|
|
+ if(param.getJyUserId() == null){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ Page<UserShareSceneVo> page = scenePlusService.shareScenePageList(new Page<>(param.getPageNum(), param.getPageSize()),param);
|
|
|
+
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
}
|