lipenghui 5 mesiacov pred
rodič
commit
9ca7970048

+ 2 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotInfoSaveReqVO.java

@@ -21,7 +21,7 @@ public class IotInfoSaveReqVO {
     private Long classId;
 
     @Schema(description = "部门id", requiredMode = Schema.RequiredMode.REQUIRED, example = "2503")
-    @NotNull(message = "部门id不能为空")
+//    @NotNull(message = "部门id不能为空")
     private Long orgId;
 
     @Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@@ -29,7 +29,7 @@ public class IotInfoSaveReqVO {
     private String filename;
 
     @Schema(description = "文件类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
-    @NotEmpty(message = "文件类型不能为空")
+//    @NotEmpty(message = "文件类型不能为空")
     private String fileType;
 
     @Schema(description = "文件路径", requiredMode = Schema.RequiredMode.REQUIRED)

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotInfoClassifyMapper.java

@@ -29,6 +29,7 @@ public interface IotInfoClassifyMapper extends BaseMapperX<IotInfoClassifyDO> {
     default List<IotInfoClassifyDO> selectList(IotInfoClassifyListReqVO reqVO) {
         return selectList(new LambdaQueryWrapperX<IotInfoClassifyDO>()
                 .likeIfPresent(IotInfoClassifyDO::getName, reqVO.getName())
+                .eqIfPresent(IotInfoClassifyDO::getDeviceId, reqVO.getDeviceId())
                 .eqIfPresent(IotInfoClassifyDO::getStatus, reqVO.getStatus()));
     }
     default Long selectCountByParentId(Long parentId) {

+ 3 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotInfoMapper.java

@@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoPageReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoDO;
+import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
 import org.apache.ibatis.annotations.Mapper;
 
 /**
@@ -17,14 +18,14 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface IotInfoMapper extends BaseMapperX<IotInfoDO> {
 
-    default PageResult<IotInfoDO> selectPage(IotInfoPageReqVO reqVO) {
+    default PageResult<IotInfoDO> selectPage(IotInfoPageReqVO reqVO, Collection<Long> classIds ) {
         return selectPage(reqVO, new LambdaQueryWrapperX<IotInfoDO>()
                 .eqIfPresent(IotInfoDO::getDeviceId, reqVO.getDeviceId())
                 .eqIfPresent(IotInfoDO::getOrgId, reqVO.getOrgId())
                 .likeIfPresent(IotInfoDO::getFilename, reqVO.getFilename())
                 .eqIfPresent(IotInfoDO::getFileType, reqVO.getFileType())
                 .eqIfPresent(IotInfoDO::getFilePath, reqVO.getFilePath())
-                .eqIfPresent(IotInfoDO::getClassId, reqVO.getClassId())
+                .inIfPresent(IotInfoDO::getClassId, classIds)
                 .eqIfPresent(IotInfoDO::getRemark, reqVO.getRemark())
                 .betweenIfPresent(IotInfoDO::getCreateTime, reqVO.getCreateTime())
                 .orderByDesc(IotInfoDO::getId));

+ 13 - 15
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotInfoClassifyService.java

@@ -4,11 +4,9 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoClassifyListReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoClassifySaveReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 产品分类 Service 接口
@@ -74,16 +72,6 @@ public interface IotInfoClassifyService {
         return CollectionUtils.convertMap(list, IotInfoClassifyDO::getId);
     }
 
-    /**
-     * 获得指定产品分类的所有子产品分类
-     *
-     * @param id 产品分类编号
-     * @return 子产品分类列表
-     */
-    default List<IotInfoClassifyDO> getChildIotInfoClassifyList(Long id) {
-        return getChildIotInfoClassifyList(Collections.singleton(id));
-    }
-
     /**
      * 获得指定产品分类的所有子产品分类
      *
@@ -106,7 +94,7 @@ public interface IotInfoClassifyService {
 //     * @param id 父产品分类编号
 //     * @return 子产品分类列表
 //     */
-//    Set<Long> getChildIotInfoClassifyIdListFromCache(Long id);
+    Set<Long> getChildIotInfoClassifyIdListFromCache(Long id);
 //
 //    /**
 //     * 校验产品分类们是否有效。如下情况,视为无效:
@@ -116,5 +104,15 @@ public interface IotInfoClassifyService {
 //     * @param ids 角色编号数组
 //     */
 //    void validateIotInfoClassifyList(Collection<Long> ids);
+default List<IotInfoClassifyDO> getChildInfoList(Long id) {
+    return getChildInfoList(Collections.singleton(id));
+}
 
+    /**
+     * 获得指定部门的所有子部门
+     *
+     * @param ids 部门编号数组
+     * @return 子部门列表
+     */
+    List<IotInfoClassifyDO> getChildInfoList(Collection<Long> ids);
 }

+ 36 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotInfoClassifyServiceImpl.java

@@ -3,12 +3,17 @@ package cn.iocoder.yudao.module.pms.service;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoClassifyListReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoClassifySaveReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.IotInfoClassifyMapper;
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
+import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
 import com.google.common.annotations.VisibleForTesting;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
@@ -33,6 +38,8 @@ public class IotInfoClassifyServiceImpl implements IotInfoClassifyService {
     private IotInfoClassifyMapper iotInfoClassifyMapper;
 
     @Override
+    @CacheEvict(cacheNames = RedisKeyConstants.IOT_INFO_CHILDREN_ID_LIST,
+            allEntries = true)
     public Long createIotInfoClassify(IotInfoClassifySaveReqVO createReqVO) {
         if (createReqVO.getParentId() == null) {
             createReqVO.setParentId(IotInfoClassifyDO.PARENT_ID_ROOT);
@@ -49,6 +56,8 @@ public class IotInfoClassifyServiceImpl implements IotInfoClassifyService {
     }
 
     @Override
+    @CacheEvict(cacheNames = RedisKeyConstants.IOT_INFO_CHILDREN_ID_LIST,
+            allEntries = true)
     public void updateIotInfoClassify(IotInfoClassifySaveReqVO updateReqVO) {
         if (updateReqVO.getParentId() == null) {
             updateReqVO.setParentId(IotInfoClassifyDO.PARENT_ID_ROOT);
@@ -66,6 +75,8 @@ public class IotInfoClassifyServiceImpl implements IotInfoClassifyService {
     }
 
     @Override
+    @CacheEvict(cacheNames = RedisKeyConstants.IOT_INFO_CHILDREN_ID_LIST,
+            allEntries = true)
     public void deleteIotInfoClassify(Long id) {
         // 校验是否存在
         validateIotInfoClassifyExists(id);
@@ -176,5 +187,30 @@ public class IotInfoClassifyServiceImpl implements IotInfoClassifyService {
         }
         return children;
     }
+    @Override
+    @DataPermission(enable = false) // 禁用数据权限,避免建立不正确的缓存
+    @Cacheable(cacheNames = RedisKeyConstants.IOT_INFO_CHILDREN_ID_LIST, key = "#id")
+    public Set<Long> getChildIotInfoClassifyIdListFromCache(Long id) {
+        List<IotInfoClassifyDO> children = getChildInfoList(id);
+        return convertSet(children, IotInfoClassifyDO::getId);
+    }
 
+    @Override
+    public List<IotInfoClassifyDO> getChildInfoList(Collection<Long> ids) {
+        List<IotInfoClassifyDO> children = new LinkedList<>();
+        // 遍历每一层
+        Collection<Long> parentIds = ids;
+        for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环
+            // 查询当前层,所有的子部门
+            List<IotInfoClassifyDO> depts = iotInfoClassifyMapper.selectListByParentId(parentIds);
+            // 1. 如果没有子部门,则结束遍历
+            if (CollUtil.isEmpty(depts)) {
+                break;
+            }
+            // 2. 如果有子部门,继续遍历
+            children.addAll(depts);
+            parentIds = convertSet(depts, IotInfoClassifyDO::getId);
+        }
+        return children;
+    }
 }

+ 15 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotInfoServiceImpl.java

@@ -2,8 +2,10 @@ package cn.iocoder.yudao.module.pms.service;
 
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoSaveReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.IotInfoMapper;
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import org.springframework.validation.annotation.Validated;
@@ -16,6 +18,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_INFO_NOT_EXISTS;
 
 /**
@@ -29,11 +32,14 @@ public class IotInfoServiceImpl implements IotInfoService {
 
     @Resource
     private IotInfoMapper iotInfoMapper;
+    @Resource
+    private IotInfoClassifyService iotInfoClassifyService;
 
     @Override
     public Long createIotInfo(IotInfoSaveReqVO createReqVO) {
         // 插入
         IotInfoDO iotInfo = BeanUtils.toBean(createReqVO, IotInfoDO.class);
+        iotInfo.setDeleted(false);
         iotInfoMapper.insert(iotInfo);
         // 返回
         return iotInfo.getId();
@@ -69,7 +75,14 @@ public class IotInfoServiceImpl implements IotInfoService {
 
     @Override
     public PageResult<IotInfoDO> getIotInfoPage(IotInfoPageReqVO pageReqVO) {
-        return iotInfoMapper.selectPage(pageReqVO);
+        return iotInfoMapper.selectPage(pageReqVO, getInfoCondition(pageReqVO.getClassId()));
+    }
+    private Set<Long> getInfoCondition(Long classId) {
+        if (classId == null) {
+            return Collections.emptySet();
+        }
+        Set<Long> deptIds = convertSet(iotInfoClassifyService.getChildInfoList(classId), IotInfoClassifyDO::getId);
+        deptIds.add(classId); // 包括自身
+        return deptIds;
     }
-
 }

+ 2 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/redis/RedisKeyConstants.java

@@ -17,6 +17,8 @@ public interface RedisKeyConstants {
      */
     String DEPT_CHILDREN_ID_LIST = "dept_children_ids";
 
+    String IOT_INFO_CHILDREN_ID_LIST = "iot_info_children_ids";
+
     /**
      * 角色的缓存
      * <p>