Browse Source

编码分类处理

lipenghui 1 day ago
parent
commit
c6ee870f75
14 changed files with 179 additions and 0 deletions
  1. 8 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java
  2. 3 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDevicePageReqVO.java
  3. 6 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceRespVO.java
  4. 5 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceSaveReqVO.java
  5. 15 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/yfclass/IotYfClassifyController.java
  6. 24 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/yfclass/vo/IotYfCasCaderVo.java
  7. 2 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/yfclass/vo/IotYfClassifyRespVO.java
  8. 5 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/IotDeviceDO.java
  9. 4 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/yfclass/IotYfClassifyDO.java
  10. 1 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotDeviceMapper.java
  11. 1 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceService.java
  12. 38 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java
  13. 3 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/yfclass/IotYfClassifyService.java
  14. 64 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/yfclass/IotYfClassifyServiceImpl.java

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java

@@ -10,6 +10,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
 import cn.iocoder.yudao.module.pms.ThingsModelDTO;
+import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfCasCaderVo;
 import cn.iocoder.yudao.module.pms.oa.OaFlow;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceperson.vo.IotDevicePersonRelationSaveReqVO;
@@ -99,6 +100,13 @@ public class IotDeviceController {
         return success(iotDeviceService.createIotDevice(createReqVO));
     }
 
+    @GetMapping(value = {"/max"})
+    @Operation(summary = "获取最大的编码", description = "获取最大的编码")
+    public CommonResult<String> getMaxYfCode(@RequestParam String yfCode) {
+        String maxCode = iotDeviceService.getMaxCode(yfCode);
+        return success(maxCode);
+    }
+
     @PostMapping("/saveDeviceStatuses")
     @Operation(summary = "批量调整设备状态")
     @PreAuthorize("@ss.hasPermission('pms:iot-device-status-log:create')")

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDevicePageReqVO.java

@@ -143,4 +143,7 @@ public class IotDevicePageReqVO extends PageParam {
 
     @Schema(description = "部门id集合 项目-任务 根据选择的部门筛选设备")
     private List<Long> deptIds;
+
+    @Schema(description = "油服设备编码")
+    private String yfDeviceCode;
 }

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceRespVO.java

@@ -232,4 +232,10 @@ public class IotDeviceRespVO {
 
     @Schema(description = "保养/维修项关联的设备bom物料列表")
     private List<IotDeviceMaterialRespVO> deviceBomMaterials;
+
+    @Schema(description = "编码分类")
+    private String yfClass;
+
+    @Schema(description = "油服设备编码")
+    private String yfDeviceCode;
 }

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/vo/IotDeviceSaveReqVO.java

@@ -114,4 +114,9 @@ public class IotDeviceSaveReqVO {
 
     @Schema(description = "启用日期")
     private LocalDateTime enableDate;
+
+    @Schema(description = "油服编码分类")
+    private String yfClass;
+    @Schema(description = "油服设备编码")
+    private String yfDeviceCode;
 }

+ 15 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/yfclass/IotYfClassifyController.java

@@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotProductClassifyListReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotProductClassifyRespVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotProductClassifySimpleRespVO;
+import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfCasCaderVo;
 import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfClassifyPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfClassifyRespVO;
 import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfClassifySaveReqVO;
@@ -18,11 +19,13 @@ import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.Operation;
 
+import javax.annotation.security.PermitAll;
 import javax.validation.constraints.*;
 import javax.validation.*;
 import javax.servlet.http.*;
 import java.util.*;
 import java.io.IOException;
+import java.util.stream.Collectors;
 
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -95,6 +98,13 @@ public class IotYfClassifyController {
         return success(BeanUtils.toBean(list, IotProductClassifySimpleRespVO.class));
     }
 
+    @GetMapping(value = {"/children-list"})
+    @Operation(summary = "获取树形结构", description = "获取树形结构")
+    public CommonResult<List<IotYfCasCaderVo>> getChildrenList() {
+        List<IotYfCasCaderVo> casCaderList = iotYfClassifyService.getCasCaderList();
+        return success(casCaderList);
+    }
+
     @GetMapping("/export-excel")
     @Operation(summary = "导出油服设备分类 Excel")
     @PreAuthorize("@ss.hasPermission('rq:iot-yf-classify:export')")
@@ -108,4 +118,9 @@ public class IotYfClassifyController {
                         BeanUtils.toBean(list, IotYfClassifyRespVO.class));
     }
 
+    @GetMapping("/init")
+    @PermitAll
+    public void initClassify() {
+        iotYfClassifyService.initClassify();
+    }
 }

+ 24 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/yfclass/vo/IotYfCasCaderVo.java

@@ -0,0 +1,24 @@
+package cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class IotYfCasCaderVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    private String label;
+    private String value;
+    private List<IotYfCasCaderVo> children;
+
+    public IotYfCasCaderVo(String value, String label) {
+        this.value = value;
+        this.label = label;
+        this.children = new ArrayList<>();
+    }
+    public void addChild(IotYfCasCaderVo child) {
+        this.children.add(child);
+    }
+}

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

@@ -44,4 +44,6 @@ public class IotYfClassifyRespVO {
     @ExcelProperty("备注扩展字段")
     private String remark;
 
+    @Schema(description = "所在公司")
+    private String company;
 }

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/IotDeviceDO.java

@@ -170,4 +170,9 @@ public class IotDeviceDO extends BaseDO {
     private String vehicleName;
     private String assetOwnership;
     private String useProject;
+    /**
+     * 编码分类
+     */
+    private String yfClass;
+    private String yfDeviceCode;
 }

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/yfclass/IotYfClassifyDO.java

@@ -52,4 +52,8 @@ public class IotYfClassifyDO extends BaseDO {
      */
     private String remark;
 
+    /**
+     * 所属公司
+     */
+    private String company;
 }

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

@@ -78,6 +78,7 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
     default List<IotDeviceDO> selectList(IotDevicePageReqVO reqVO) {
         return selectList(new LambdaQueryWrapperX<IotDeviceDO>()
                 .inIfPresent(IotDeviceDO::getDeptId, reqVO.getDeptIds())
+                .likeIfPresent(IotDeviceDO::getYfDeviceCode, reqVO.getYfDeviceCode())
                 .likeIfPresent(IotDeviceDO::getDeviceCode, reqVO.getDeviceCode())
                 .likeIfPresent(IotDeviceDO::getDeviceName, reqVO.getDeviceName())
                 .eqIfPresent(IotDeviceDO::getDeptId, reqVO.getDeptId())

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceService.java

@@ -22,6 +22,7 @@ import java.util.Map;
  * @author 芋道源码
  */
 public interface IotDeviceService {
+    String getMaxCode(String prefix);
     List<IotDeviceDO> getAllDevices(IotDevicePageReqVO pageReqVO);
     void templateChange(String categoryId, List<IotDeviceProperty> properties);
     void importDevice(List<DeviceImportExcelVO> list);

+ 38 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -70,6 +70,8 @@ import org.springframework.web.client.RestTemplate;
 import javax.annotation.Resource;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -132,6 +134,42 @@ public class IotDeviceServiceImpl implements IotDeviceService {
     @Autowired
     private DeptApi deptApi;
 
+    @Override
+    public String getMaxCode(String prefix) {
+        IotDevicePageReqVO iotDevicePageReqVO = new IotDevicePageReqVO();
+        iotDevicePageReqVO.setYfDeviceCode(prefix);
+        List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList(iotDevicePageReqVO);
+        if (iotDeviceDOS == null || iotDeviceDOS.isEmpty()) {
+            return "001"; // 列表为空时默认从001开始
+        }
+        Pattern CODE_PATTERN = Pattern.compile(prefix + "(\\d{3})");
+        // 提取所有符合格式的编码的最后三位数字
+        List<Integer> suffixNumbers = iotDeviceDOS.stream()
+                .map(code -> {
+                    Matcher matcher = CODE_PATTERN.matcher(code.getYfDeviceCode());
+                    if (matcher.matches()) {
+                        try {
+                            return Integer.parseInt(matcher.group(1));
+                        } catch (NumberFormatException e) {
+                            return null; // 忽略格式错误的编码
+                        }
+                    }
+                    return null; // 忽略不符合格式的编码
+                })
+                .filter(num -> num != null) // 过滤掉空值
+                .collect(Collectors.toList());
+
+        // 找到最大的数字
+        Integer maxNum = suffixNumbers.stream()
+                .mapToInt(Integer::intValue)
+                .max()
+                .orElse(-1); // 如果没有符合条件的编码,使用-1
+
+        // 计算下一个数字并格式化为三位数字
+        int nextNum = maxNum + 1;
+        return String.format("%03d", nextNum);
+    }
+
     @Override
     public void templateChange(String categoryId, List<IotDeviceProperty> properties) {
         List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList("asset_class", categoryId);

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/yfclass/IotYfClassifyService.java

@@ -5,6 +5,7 @@ import javax.validation.*;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotProductClassifyListReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfCasCaderVo;
 import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfClassifyPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfClassifySaveReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
@@ -16,6 +17,8 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.yfclass.IotYfClassifyDO;
  * @author 超级管理员
  */
 public interface IotYfClassifyService {
+    List<IotYfCasCaderVo> getCasCaderList();
+    void initClassify();
     List<IotYfClassifyDO> getYfClassifyList(IotProductClassifyListReqVO reqVO);
     /**
      * 获得产品分类信息数组

+ 64 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/yfclass/IotYfClassifyServiceImpl.java

@@ -2,11 +2,15 @@ package cn.iocoder.yudao.module.pms.service.yfclass;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.exception.ErrorCode;
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotProductClassifyListReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfCasCaderVo;
 import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfClassifyPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.yfclass.vo.IotYfClassifySaveReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.yfclass.IotYfClassifyDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.yfclass.IotYfClassifyMapper;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
@@ -14,6 +18,10 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -32,6 +40,8 @@ public class IotYfClassifyServiceImpl implements IotYfClassifyService {
 
     @Resource
     private IotYfClassifyMapper iotYfClassifyMapper;
+    @Resource
+    private IotDeviceMapper iotDeviceMapper;
 
     @Override
     public List<IotYfClassifyDO> getYfClassifyList(Collection<Long> ids) {
@@ -41,6 +51,60 @@ public class IotYfClassifyServiceImpl implements IotYfClassifyService {
         return iotYfClassifyMapper.selectBatchIds(ids);
     }
 
+    @Override
+    public List<IotYfCasCaderVo> getCasCaderList() {
+        List<IotYfClassifyDO> nodes = iotYfClassifyMapper.selectList();
+        // 创建节点ID到CascaderNode的映射,方便查找
+        Map<Long, IotYfCasCaderVo> nodeMap = new HashMap<>();
+
+        // 先创建所有节点
+        for (IotYfClassifyDO node : nodes) {
+            IotYfCasCaderVo cascaderNode = new IotYfCasCaderVo(node.getCode(), node.getName());
+            nodeMap.put(node.getId(), cascaderNode);
+        }
+
+        // 构建树形结构
+        List<IotYfCasCaderVo> result = new ArrayList<>();
+        for (IotYfClassifyDO node : nodes) {
+            IotYfCasCaderVo currentNode = nodeMap.get(node.getId());
+            Long parentId = node.getParentId();
+
+            if (parentId == null || parentId == 0) {
+                // 没有父节点,是根节点
+                result.add(currentNode);
+            } else {
+                // 有父节点,添加到父节点的children中
+                IotYfCasCaderVo parentNode = nodeMap.get(parentId);
+                if (parentNode != null) {
+                    parentNode.addChild(currentNode);
+                } else {
+                    // 如果父节点不存在,作为根节点处理
+                    result.add(currentNode);
+                }
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public void initClassify() {
+        List<IotYfClassifyDO> list = iotYfClassifyMapper.selectList();
+
+        List<IotYfClassifyDO> collect = list.stream().filter(e -> e.getParentId() == 0).collect(Collectors.toList());
+        collect.stream().forEach(e -> {
+            List<IotYfClassifyDO> iotYfClassifyDOS = iotYfClassifyMapper.selectList("parent_id", e.getId());
+            iotYfClassifyDOS.forEach(f ->{
+                f.setCompany(e.getCode());
+                iotYfClassifyMapper.updateById(f);
+                List<IotYfClassifyDO> iotYfClassifyDOS1 = iotYfClassifyMapper.selectList("parent_id", f.getId());
+                iotYfClassifyDOS1.forEach(g -> {
+                    g.setCompany(e.getCode());
+                    iotYfClassifyMapper.updateById(g);
+                });
+            });
+        });
+    }
+
     @Override
     public List<IotYfClassifyDO> getYfClassifyList(IotProductClassifyListReqVO reqVO) {
         List<IotYfClassifyDO> list = iotYfClassifyMapper.selectList(reqVO);