|
@@ -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);
|