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; } }