|
@@ -0,0 +1,131 @@
|
|
|
+package com.fdkankan.jp.xspace.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.common.constant.RecStatus;
|
|
|
+import com.fdkankan.jp.xspace.common.PageInfo;
|
|
|
+import com.fdkankan.jp.xspace.common.Result;
|
|
|
+import com.fdkankan.jp.xspace.common.ResultCode;
|
|
|
+import com.fdkankan.jp.xspace.common.rabbitmq.RabbitmqConstant;
|
|
|
+import com.fdkankan.jp.xspace.dto.XspacePageDTO;
|
|
|
+import com.fdkankan.jp.xspace.entity.ScenePlus;
|
|
|
+import com.fdkankan.jp.xspace.entity.SceneXspace;
|
|
|
+import com.fdkankan.jp.xspace.entity.User;
|
|
|
+import com.fdkankan.jp.xspace.mapper.ISceneXspaceMapper;
|
|
|
+import com.fdkankan.jp.xspace.service.IScenePlusService;
|
|
|
+import com.fdkankan.jp.xspace.service.ISceneXspaceService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.jp.xspace.service.IUserRoleService;
|
|
|
+import com.fdkankan.jp.xspace.service.IUserService;
|
|
|
+import com.fdkankan.jp.xspace.util.UniqueStringGenerator;
|
|
|
+import com.fdkankan.jp.xspace.vo.XspaceVO;
|
|
|
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * xspace同步表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2024-07-22
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SceneXspaceServiceImpl extends ServiceImpl<ISceneXspaceMapper, SceneXspace> implements ISceneXspaceService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserRoleService userRoleService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private RabbitMqProducer mqProducer;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo pageXspace(XspacePageDTO param, User user) {
|
|
|
+ Set<Long> roleIds = userRoleService.getByUser(user);
|
|
|
+ if(!roleIds.contains(5)){//平台管理员可以看到所有
|
|
|
+ if(roleIds.contains(6)){//公司管理员可以看到同一公司下所有
|
|
|
+ param.setCompanyId(user.getCompanyId());
|
|
|
+ }else{//普通员工只能看到自己的
|
|
|
+ param.setUserId(user.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Page<XspaceVO> xspaceVOPage = this.baseMapper.pageXspace(new Page(param.getPageNum(), param.getPageSize()), param);
|
|
|
+ return PageInfo.PageInfo(xspaceVOPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result delete(List<Long> ids, User user) {
|
|
|
+
|
|
|
+ List<SceneXspace> sceneXspaces = this.listByIds(ids);
|
|
|
+ if(CollUtil.isEmpty(sceneXspaces)){
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+ //校验数据
|
|
|
+ Set<Long> userIds = sceneXspaces.stream().map(x -> x.getUserId()).collect(Collectors.toSet());
|
|
|
+ Set<Long> roleIds = userRoleService.getByUser(user);
|
|
|
+ boolean notPermission = false;
|
|
|
+ if(!roleIds.contains(5)){//平台管理员可以看到所有
|
|
|
+ if(roleIds.contains(6)){//公司管理员可以看到同一公司下所有
|
|
|
+ List<User> users = userService.listByIds(userIds);
|
|
|
+ notPermission = users.stream().anyMatch(u -> !u.getCompanyId().equals(user.getCompanyId()));
|
|
|
+ }else{//普通员工只能删除自己的
|
|
|
+ notPermission = userIds.stream().anyMatch(id -> !id.equals(user.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(notPermission){
|
|
|
+ return Result.failure(ResultCode.NOT_PERMISSION);
|
|
|
+ }
|
|
|
+
|
|
|
+ sceneXspaces.stream().forEach(x->{
|
|
|
+ // TODO: 2024/7/24 删除oss文件
|
|
|
+
|
|
|
+ x.setUpdater(user.getId());
|
|
|
+ x.setRecStatus(RecStatus.DISABLE.code());
|
|
|
+ this.updateById(x);
|
|
|
+ this.removeById(x.getId());
|
|
|
+ });
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result sync(List<String> nums, User user) {
|
|
|
+
|
|
|
+ List<SceneXspace> syncList = this.list(new LambdaQueryWrapper<SceneXspace>().in(SceneXspace::getNum, nums).eq(SceneXspace::getUserId, user.getId()));
|
|
|
+ List<String> canSyncList = nums;
|
|
|
+ if(CollUtil.isNotEmpty(syncList)){
|
|
|
+ List<String> doneNumsList = syncList.stream().map(v -> v.getNum()).collect(Collectors.toList());
|
|
|
+ canSyncList = nums.stream().filter(v->!doneNumsList.contains(v)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ScenePlus> scenePlusList = scenePlusService.list(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getUserId, user.getId()).in(ScenePlus::getNum, canSyncList));
|
|
|
+ if(CollUtil.isEmpty(scenePlusList)){
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<SceneXspace> sceneXspaceList = scenePlusList.stream().map(p -> {
|
|
|
+ SceneXspace sceneXspace = new SceneXspace();
|
|
|
+ sceneXspace.setNum(p.getNum());
|
|
|
+ sceneXspace.setUserId(p.getUserId());
|
|
|
+ sceneXspace.setSerial(UniqueStringGenerator.getUniqueString());
|
|
|
+ return sceneXspace;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ this.saveBatch(sceneXspaceList);
|
|
|
+ sceneXspaceList.stream().forEach(v->{
|
|
|
+ mqProducer.sendByWorkQueue(RabbitmqConstant.QUEUE_PACK_XSPACE, v);
|
|
|
+ });
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+}
|