art: 系统管理-用户管理-添加选择设备,并根据是否有设备管理模块功能区分加载 哪个模块的设备倏
已添加2个文件
已修改6个文件
322 ■■■■■ 文件已修改
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentProductionUtil.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java 121 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/pom.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamEquipment.java
@@ -180,4 +180,6 @@
     */
    @ApiModelProperty(value = "使用部门所有ID")
    private String orgParentIds;
    @ApiModelProperty(value = "MDC设备类型")
    private String deviceType;
}
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/EamEquipmentMapper.java
@@ -1,7 +1,10 @@
package org.jeecg.modules.eam.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.eam.entity.EamEquipment;
import java.util.List;
/**
 * @Description: è®¾å¤‡å°è´¦
@@ -10,5 +13,11 @@
 * @Version: V1.0
 */
public interface EamEquipmentMapper extends BaseMapper<EamEquipment> {
    /**
     * æŸ¥è¯¢äº§çº¿ä¸‹çš„设备
     * @param productionId äº§çº¿id
     * @return
     */
    @Select("select * from eam_equipment where del_flag = 0 and org_id = #{productionId}")
    List<EamEquipment> queryByProductionId(String productionId);
}
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/IEamEquipmentService.java
@@ -2,6 +2,9 @@
import org.jeecg.modules.eam.entity.EamEquipment;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.eam.vo.EamEquipmentTree;
import java.util.List;
/**
 * @Description: è®¾å¤‡å°è´¦
@@ -16,4 +19,11 @@
     * @param eamEquipment
     */
    EamEquipment saveEquipment(EamEquipment eamEquipment);
    /**
     * èŽ·å–äº§çº¿ä¸‹çš„è®¾å¤‡ä¿¡æ¯
     * @param ids äº§çº¿ids
     * @return
     */
    List<EamEquipmentTree> loadTreeListByProductionIds(String ids);
}
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
@@ -1,6 +1,9 @@
package org.jeecg.modules.eam.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
import org.jeecg.modules.eam.constant.AssetStatusEnum;
@@ -12,11 +15,20 @@
import org.jeecg.modules.eam.mapper.EamEquipmentMapper;
import org.jeecg.modules.eam.service.IEamEquipmentExtendService;
import org.jeecg.modules.eam.service.IEamEquipmentService;
import org.jeecg.modules.eam.tree.FindsEquipmentProductionUtil;
import org.jeecg.modules.eam.vo.EamEquipmentTree;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @Description: è®¾å¤‡å°è´¦
@@ -31,6 +43,8 @@
    private EamEquipmentMapper eamEquipmentMapper;
    @Autowired
    private IEamEquipmentExtendService equipmentExtendService;
    @Autowired
    private IMdcProductionService mdcProductionService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -55,4 +69,67 @@
        //插入设备履历 TODO
        return eamEquipment;
    }
    @Override
    public List<EamEquipmentTree> loadTreeListByProductionIds(String ids) {
        List<String> productionIds = Arrays.asList(ids.split(","));
        //获取所有产线数据
        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
        List<String> allProductionIds = new ArrayList<>();
        //找到所有产线id的上级id
        if (!productionIds.isEmpty()) {
            for (String productionId : productionIds) {
                this.getAllProductionIds(productionList, productionId, allProductionIds);
            }
        }
        //过滤产线数据
        List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList());
        //组装产线设备树
        List<EamEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        fillEquipmentByProduction(treeList);
        return treeList;
    }
    /**
     * èŽ·å–æ‰€æœ‰çš„äº§çº¿id(包含所有上级)
     */
    private void getAllProductionIds(List<MdcProduction> productionList, String productionId, List<String> allProductionIds) {
        if (!allProductionIds.contains(productionId)) {
            allProductionIds.add(productionId);
        }
        for (MdcProduction mdcProduction : productionList) {
            if (StringUtils.isEmpty(mdcProduction.getParentId())) {
                continue;
            }
            if (productionId.equals(mdcProduction.getId())) {
                if (!allProductionIds.contains(mdcProduction.getParentId())) {
                    allProductionIds.add(mdcProduction.getParentId());
                    getAllProductionIds(productionList, mdcProduction.getParentId(), allProductionIds);
                }
            }
        }
    }
    /**
     * äº§çº¿è®¾å¤‡æ ‘填充设备数据
     */
    private void fillEquipmentByProduction(List<EamEquipmentTree> treeList) {
        for (EamEquipmentTree mdcEquipmentTree : treeList) {
            List<EamEquipment> equipmentList = eamEquipmentMapper.queryByProductionId(mdcEquipmentTree.getKey());
            if (CollectionUtil.isNotEmpty(equipmentList)) {
                for (EamEquipment mdcEquipment : equipmentList) {
                    EamEquipmentTree tree = new EamEquipmentTree().convert(mdcEquipment);
                    tree.setParentId(mdcEquipmentTree.getKey());
                    tree.setType(2);
                    mdcEquipmentTree.getChildren().add(tree);
                }
                mdcEquipmentTree.setLeaf(false);
            }
            if (CollectionUtil.isNotEmpty(mdcEquipmentTree.getChildren())) {
                fillEquipmentByProduction(mdcEquipmentTree.getChildren());
            }
        }
    }
}
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/tree/FindsEquipmentProductionUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,79 @@
package org.jeecg.modules.eam.tree;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.vo.EamEquipmentTree;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.model.MdcProductionTreeModel;
import java.util.ArrayList;
import java.util.List;
/**
 * äº§çº¿è®¾å¤‡æ ‘
 * @author: LiuS
 * @create: 2023-04-03 15:59
 */
public class FindsEquipmentProductionUtil {
    /**
     * èŽ·å– MdcEquipmentTree
     */
    public static List<EamEquipmentTree> wrapEquipmentProductionTreeList(List<MdcProduction> recordList) {
        List<EamEquipmentTree> idList = new ArrayList<>();
        List<MdcProductionTreeModel> records = new ArrayList<>();
        for (MdcProduction mdcProduction : recordList) {
            records.add(new MdcProductionTreeModel(mdcProduction));
        }
        getChildren(records, idList);
        setEmptyChildrenAsNull(idList);
        return idList;
    }
    /**
     * è¯¥æ–¹æ³•是找到并封装顶级父类的节点到TreeList集合
     */
    private static void getChildren(List<MdcProductionTreeModel> recordList, List<EamEquipmentTree> idList) {
        List<MdcProductionTreeModel> treeList = new ArrayList<>();
        for (MdcProductionTreeModel mdcProductionTreeModel : recordList) {
            if (oConvertUtils.isEmpty(mdcProductionTreeModel.getParentId())) {
                mdcProductionTreeModel.setType(1);
                treeList.add(mdcProductionTreeModel);
                idList.add(new EamEquipmentTree().convertByProduction(mdcProductionTreeModel));
            }
        }
        getGrandChildren(treeList, recordList, idList);
    }
    /**
     *该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
     */
    private static void getGrandChildren(List<MdcProductionTreeModel> treeList, List<MdcProductionTreeModel> recordList, List<EamEquipmentTree> idList) {
        for (int i = 0; i < treeList.size(); i++) {
            MdcProductionTreeModel model = treeList.get(i);
            EamEquipmentTree mdcEquipmentTree = idList.get(i);
            for (int i1 = 0; i1 < recordList.size(); i1++) {
                MdcProductionTreeModel m = recordList.get(i1);
                if (m.getParentId() != null && m.getParentId().equals(model.getId())) {
                    model.getChildren().add(m);
                    m.setType(1);
                    mdcEquipmentTree.getChildren().add(new EamEquipmentTree().convertByProduction(m));
                }
            }
            getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren());
        }
    }
    /**
     * è¯¥æ–¹æ³•是将子节点为空的List集合设置为Null值
     */
    private static void setEmptyChildrenAsNull(List<EamEquipmentTree> idList) {
        for (EamEquipmentTree mdcEquipmentTree : idList) {
            if (mdcEquipmentTree.getChildren().isEmpty()) {
                mdcEquipmentTree.setLeaf(true);
            } else {
                setEmptyChildrenAsNull(mdcEquipmentTree.getChildren());
                mdcEquipmentTree.setLeaf(false);
            }
        }
    }
}
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/vo/EamEquipmentTree.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,121 @@
package org.jeecg.modules.eam.vo;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.modules.eam.entity.EamEquipment;
import org.jeecg.modules.system.model.MdcProductionTreeModel;
import org.jeecg.modules.system.model.SysDepartTreeModel;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
 * è®¾å¤‡æ ‘
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "设备树结构数据实体", description = "设备")
public class EamEquipmentTree implements Serializable {
    /**
     * å‰ç«¯æ•°æ®æ ‘中的key
     */
    private String key;
    /**
     * å‰ç«¯æ•°æ®æ ‘中的value
     */
    private String value;
    /**
     * å‰ç«¯æ•°æ®æ ‘中的title
     */
    private String title;
    /**
     * æ˜¯å¦æ˜¯å­èŠ‚ç‚¹
     */
    private boolean isLeaf;
    /**
     * è®¾å¤‡ç¼–号(前端定位用)
     */
    private String equipmentId;
    /**
     * è®¾å¤‡åç§°ï¼ˆå‰ç«¯å®šä½ç”¨ï¼‰
     */
    private String equipmentName;
    /**
     * çˆ¶çº§id(前端请求用)
     */
    private String parentId;
    /**
     * è½¦é—´æè¿°
     */
    private String memo;
    /**
     * ç±»åž‹ 1 è½¦é—´ 2设备
     */
    private Integer type;
    /**
     * orgType
     */
    private String orgType;
    private List<EamEquipmentTree> children = new ArrayList<>();
    /**
     * å°†è®¾å¤‡æ•°æ®æ”¾åœ¨è¯¥å¯¹è±¡ä¸­
     *
     * @param mdcEquipment
     * @return
     */
    public EamEquipmentTree convert(EamEquipment mdcEquipment) {
        this.key = mdcEquipment.getId();
        this.value = mdcEquipment.getId();
        this.title = mdcEquipment.getEquipmentCode() + "/" + mdcEquipment.getEquipmentName();
        this.equipmentId = mdcEquipment.getEquipmentCode();
        this.equipmentName = mdcEquipment.getEquipmentName();
        this.isLeaf = true;
        return this;
    }
    /**
     * å°†SysDepartTreeModel的部分数据放在该对象当中
     *
     * @param treeModel
     * @return
     */
    public EamEquipmentTree convertByDepart(SysDepartTreeModel treeModel) {
        this.key = treeModel.getId();
        this.value = treeModel.getId();
        this.title = treeModel.getDepartName();
        return this;
    }
    /**
     * å°†mdcProductionTreeModel的部分数据放在该对象当中
     *
     * @param treeModel
     * @return
     */
    public EamEquipmentTree convertByProduction(MdcProductionTreeModel treeModel) {
        this.key = treeModel.getId();
        this.value = treeModel.getId();
        this.title = treeModel.getProductionName();
        this.memo = treeModel.getMemo();
        this.type = treeModel.getType();
        this.orgType = treeModel.getOrgType();
        return this;
    }
}
lxzn-module-eam/pom.xml
@@ -25,6 +25,11 @@
            <artifactId>lxzn-module-eam-common</artifactId>
            <version>3.4.3</version>
        </dependency>
        <dependency>
            <groupId>org.jeecgframework.boot</groupId>
            <artifactId>lxzn-module-mdc-common</artifactId>
            <version>3.4.3</version>
        </dependency>
    </dependencies>
</project>
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
@@ -12,6 +12,7 @@
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.eam.entity.EamEquipment;
import org.jeecg.modules.eam.service.IEamEquipmentService;
import org.jeecg.modules.eam.vo.EamEquipmentTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@@ -19,6 +20,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
/**
 * @Description: è®¾å¤‡å°è´¦
@@ -152,4 +154,19 @@
        return super.importExcel(request, response, EamEquipment.class);
    }
    @AutoLog(value = "设备表-通过车间ids获取设备树")
    @ApiOperation(value = "设备表-通过车间ids获取设备树", notes = "设备表-通过车间ids获取设备树")
    @GetMapping(value = "/loadTreeListByProductionIds")
    public Result<List<EamEquipmentTree>> loadTreeListByProductionIds(@RequestParam(name = "ids", required = true) String ids) {
        Result<List<EamEquipmentTree>> result = new Result<>();
        try {
            List<EamEquipmentTree> mdcEquipmentTreeList = eamEquipmentService.loadTreeListByProductionIds(ids);
            result.setSuccess(true);
            result.setResult(mdcEquipmentTreeList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return result;
    }
}