From 904727f59b7e10a291ce7d1576e33192a619f2f2 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期二, 05 八月 2025 17:08:39 +0800 Subject: [PATCH] MDC设备树和设备权限改造 --- src/main/java/org/jeecg/modules/base/service/IUserFactoryService.java | 5 src/main/java/org/jeecg/modules/base/service/IFactoryService.java | 5 src/main/java/org/jeecg/modules/base/service/impl/UserFactoryServiceImpl.java | 9 src/main/java/org/jeecg/modules/mdc/model/FactoryTreeModel.java | 112 ++++++++ src/main/java/org/jeecg/modules/mdc/service/IFactoryEquipmentService.java | 30 ++ src/main/java/org/jeecg/modules/base/mapper/FactoryMapper.java | 6 src/main/java/org/jeecg/modules/mdc/service/impl/FactoryEquipmentServiceImpl.java | 87 ++++++ src/main/java/org/jeecg/modules/mdc/entity/MdcEquipment.java | 2 src/main/java/org/jeecg/modules/base/mapper/UserFactoryMapper.java | 4 src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentProVo.java | 2 src/main/java/org/jeecg/modules/mdc/mapper/FactoryEquipmentMapper.java | 13 + src/main/java/org/jeecg/modules/mdc/entity/FactoryEquipment.java | 53 ++++ src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java | 5 src/main/java/org/jeecg/modules/mdc/mapper/xml/FactoryEquipmentMapper.xml | 5 src/main/java/org/jeecg/modules/mdc/util/FindsEquipmentFactoryUtil.java | 80 ++++++ src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml | 27 ++ src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java | 13 src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java | 64 ++++ src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml | 2 src/main/java/org/jeecg/modules/base/mapper/xml/UserFactoryMapper.xml | 4 src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java | 9 src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java | 189 +++++++++++-- src/main/java/org/jeecg/modules/mdc/model/MdcEquipmentTree.java | 13 + src/main/java/org/jeecg/modules/system/controller/SysUserController.java | 20 24 files changed, 695 insertions(+), 64 deletions(-) diff --git a/src/main/java/org/jeecg/modules/base/mapper/FactoryMapper.java b/src/main/java/org/jeecg/modules/base/mapper/FactoryMapper.java index 893ab77..840fc19 100644 --- a/src/main/java/org/jeecg/modules/base/mapper/FactoryMapper.java +++ b/src/main/java/org/jeecg/modules/base/mapper/FactoryMapper.java @@ -3,6 +3,7 @@ import java.util.List; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import org.jeecg.modules.base.entity.Factory; import com.baomidou.mybatisplus.core.mapper.BaseMapper; @@ -14,4 +15,9 @@ */ public interface FactoryMapper extends BaseMapper<Factory> { + /** + * 鏍规嵁id涓嬬骇浜х嚎 + */ + @Select("SELECT * FROM base_factory where del_flag ='0' AND parent_id = #{parentId,jdbcType=VARCHAR}") + List<Factory> queryFacByPid(@Param("parentId") String parentId); } diff --git a/src/main/java/org/jeecg/modules/base/mapper/UserFactoryMapper.java b/src/main/java/org/jeecg/modules/base/mapper/UserFactoryMapper.java index f1253a4..f897d00 100644 --- a/src/main/java/org/jeecg/modules/base/mapper/UserFactoryMapper.java +++ b/src/main/java/org/jeecg/modules/base/mapper/UserFactoryMapper.java @@ -14,4 +14,8 @@ */ public interface UserFactoryMapper extends BaseMapper<UserFactory> { + /** + * 鏍规嵁鎸囧畾鐢ㄦ埛id鏌ヨ浜х嚎id闆嗗悎 + */ + List<String> queryFactoryIdsByUserId(@Param("userId") String userId); } diff --git a/src/main/java/org/jeecg/modules/base/mapper/xml/UserFactoryMapper.xml b/src/main/java/org/jeecg/modules/base/mapper/xml/UserFactoryMapper.xml index a1118b4..4dc2b30 100644 --- a/src/main/java/org/jeecg/modules/base/mapper/xml/UserFactoryMapper.xml +++ b/src/main/java/org/jeecg/modules/base/mapper/xml/UserFactoryMapper.xml @@ -2,4 +2,8 @@ <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.jeecg.modules.base.mapper.UserFactoryMapper"> + <select id="queryFactoryIdsByUserId" resultType="java.lang.String"> + SELECT factory_id FROM base_user_factory WHERE user_id = #{userId} + </select> + </mapper> \ No newline at end of file diff --git a/src/main/java/org/jeecg/modules/base/service/IFactoryService.java b/src/main/java/org/jeecg/modules/base/service/IFactoryService.java index 5ac34ff..0cd42ea 100644 --- a/src/main/java/org/jeecg/modules/base/service/IFactoryService.java +++ b/src/main/java/org/jeecg/modules/base/service/IFactoryService.java @@ -38,4 +38,9 @@ * 鏌ヨ鎵�鏈塮actoryId淇℃伅,骞跺垎鑺傜偣杩涜鏄剧ず */ List<FactoryIdModel> queryFactoryIdTreeList(); + + /** + * 鑾峰彇涓嬬骇浜х嚎 + */ + List<Factory> queryFacByPid(String pid); } diff --git a/src/main/java/org/jeecg/modules/base/service/IUserFactoryService.java b/src/main/java/org/jeecg/modules/base/service/IUserFactoryService.java index 9c3b490..0b47eed 100644 --- a/src/main/java/org/jeecg/modules/base/service/IUserFactoryService.java +++ b/src/main/java/org/jeecg/modules/base/service/IUserFactoryService.java @@ -18,4 +18,9 @@ * 鏍规嵁鎸囧畾鐢ㄦ埛id鏌ヨ浜х嚎淇℃伅 */ List<FactoryIdModel> queryFactoryIdsOfUser(String userId); + + /** + * 鏍规嵁鎸囧畾鐢ㄦ埛id鏌ヨ浜х嚎id闆嗗悎 + */ + List<String> queryFactoryIdsByUserId(String userId); } diff --git a/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java b/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java index b68cd8b..c34c7c9 100644 --- a/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java +++ b/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java @@ -24,6 +24,7 @@ import javax.annotation.Resource; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -159,6 +160,14 @@ } /** + * 鏍规嵁id鏌ヨ涓嬬骇浜х嚎 + */ + @Override + public List<Factory> queryFacByPid(String pid) { + return this.baseMapper.queryFacByPid(pid); + } + + /** * 鎵撳紑 鐖惰妭鐐� 鍙� 浠ヤ笂鐨刴dc鏍囪 * @param parentId */ diff --git a/src/main/java/org/jeecg/modules/base/service/impl/UserFactoryServiceImpl.java b/src/main/java/org/jeecg/modules/base/service/impl/UserFactoryServiceImpl.java index 38addc4..d05ba52 100644 --- a/src/main/java/org/jeecg/modules/base/service/impl/UserFactoryServiceImpl.java +++ b/src/main/java/org/jeecg/modules/base/service/impl/UserFactoryServiceImpl.java @@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -56,4 +57,12 @@ } return null; } + + /** + * 鏍规嵁鎸囧畾鐢ㄦ埛id鏌ヨ浜х嚎id闆嗗悎 + */ + @Override + public List<String> queryFactoryIdsByUserId(String userId) { + return this.baseMapper.queryFactoryIdsByUserId(userId); + } } diff --git a/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java b/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java index 13fc9dd..ec495da 100644 --- a/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java +++ b/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java @@ -13,10 +13,12 @@ import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.modules.base.model.FactoryIdModel; import org.jeecg.modules.mdc.entity.MdcEquipment; import org.jeecg.modules.mdc.entity.MdcEquipmentMonitor; import org.jeecg.modules.mdc.model.MdcEquipmentTree; import org.jeecg.modules.mdc.model.ProductionIdModel; +import org.jeecg.modules.mdc.service.IFactoryEquipmentService; import org.jeecg.modules.mdc.service.IMdcEquipmentDepartService; import org.jeecg.modules.mdc.service.IMdcEquipmentService; import org.jeecg.modules.mdc.service.IMdcProductionEquipmentService; @@ -55,7 +57,10 @@ private IMdcEquipmentDepartService mdcEquipmentDepartService; @Resource - private IMdcProductionEquipmentService mdcProductionEquipmentService; + private IFactoryEquipmentService factoryEquipmentService; + +// @Resource +// private IMdcProductionEquipmentService mdcProductionEquipmentService; /** * 鍒嗛〉鍒楄〃鏌ヨ @@ -244,7 +249,7 @@ public Result<MdcEquipment> add(@RequestBody MdcEquipment mdcEquipment) { Result<MdcEquipment> result = new Result<>(); String selectedDeparts = mdcEquipment.getSelectedDeparts(); - String selectedProduction = mdcEquipment.getSelectedProduction(); + String selectedProduction = mdcEquipment.getSelectedFactory(); mdcEquipment.setEquipmentStatus(CommonConstant.STATUS_NORMAL); try { mdcEquipmentService.saveMdcEquipment(mdcEquipment, selectedDeparts, selectedProduction); @@ -367,11 +372,11 @@ */ @AutoLog(value = "璁惧琛�-鏌ヨ鎸囧畾璁惧鍜屼骇绾垮叧鑱旂殑鏁版嵁") @ApiOperation(value = "璁惧琛�-鏌ヨ鎸囧畾璁惧鍜屼骇绾垮叧鑱旂殑鏁版嵁", notes = "璁惧琛�-鏌ヨ鎸囧畾璁惧鍜屼骇绾垮叧鑱旂殑鏁版嵁") - @GetMapping(value = "/equipmentProductionList") - public Result<List<ProductionIdModel>> getEquipmentProductionList(@RequestParam(name = "equipmentId", required = true) String equipmentId) { - Result<List<ProductionIdModel>> result = new Result<>(); + @GetMapping(value = "/equipmentFactoryList") + public Result<List<FactoryIdModel>> equipmentFactoryList(@RequestParam(name = "equipmentId", required = true) String equipmentId) { + Result<List<FactoryIdModel>> result = new Result<>(); try { - List<ProductionIdModel> proIdModelList = this.mdcProductionEquipmentService.queryProductionIdsOfEquipment(equipmentId); + List<FactoryIdModel> proIdModelList = this.factoryEquipmentService.queryFactoryIdsOfEquipment(equipmentId); if (proIdModelList != null && !proIdModelList.isEmpty()) { result.setSuccess(true); result.setMessage("鏌ユ壘鎴愬姛"); @@ -388,6 +393,33 @@ return result; } } + +// /** +// * 鏌ヨ鎸囧畾璁惧鍜屼骇绾垮叧鑱旂殑鏁版嵁 +// */ +// @AutoLog(value = "璁惧琛�-鏌ヨ鎸囧畾璁惧鍜屼骇绾垮叧鑱旂殑鏁版嵁") +// @ApiOperation(value = "璁惧琛�-鏌ヨ鎸囧畾璁惧鍜屼骇绾垮叧鑱旂殑鏁版嵁", notes = "璁惧琛�-鏌ヨ鎸囧畾璁惧鍜屼骇绾垮叧鑱旂殑鏁版嵁") +// @GetMapping(value = "/equipmentProductionList") +// public Result<List<ProductionIdModel>> getEquipmentProductionList(@RequestParam(name = "equipmentId", required = true) String equipmentId) { +// Result<List<ProductionIdModel>> result = new Result<>(); +// try { +// List<ProductionIdModel> proIdModelList = this.mdcProductionEquipmentService.queryProductionIdsOfEquipment(equipmentId); +// if (proIdModelList != null && !proIdModelList.isEmpty()) { +// result.setSuccess(true); +// result.setMessage("鏌ユ壘鎴愬姛"); +// result.setResult(proIdModelList); +// } else { +// result.setSuccess(false); +// result.setMessage("鏌ユ壘澶辫触"); +// } +// return result; +// } catch (Exception e) { +// log.error(e.getMessage(), e); +// result.setSuccess(false); +// result.setMessage("鏌ユ壘杩囩▼涓嚭鐜颁簡寮傚父: " + e.getMessage()); +// return result; +// } +// } /** * 鍔犺浇閮ㄩ棬璁惧鏍� @@ -430,6 +462,26 @@ } /** + * 鍔犺浇浜х嚎璁惧鏍� + */ + @AutoLog(value = "璁惧琛�-鍔犺浇浜х嚎璁惧鏍�") + @ApiOperation(value = "璁惧琛�-鍔犺浇浜х嚎璁惧鏍�", notes = "璁惧琛�-鍔犺浇浜х嚎璁惧鏍�") + @GetMapping(value = "/queryTreeListByFactory") + public Result<List<MdcEquipmentTree>> queryTreeListByFactory() { + Result<List<MdcEquipmentTree>> result = new Result<>(); + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String userId = user.getId(); + try { + List<MdcEquipmentTree> mdcEquipmentTreeList = mdcEquipmentService.loadTreeListByProduction(userId); + result.setSuccess(true); + result.setResult(mdcEquipmentTreeList); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return result; + } + + /** * 瀵煎嚭excel * * @param request diff --git a/src/main/java/org/jeecg/modules/mdc/entity/FactoryEquipment.java b/src/main/java/org/jeecg/modules/mdc/entity/FactoryEquipment.java new file mode 100644 index 0000000..7f3df6a --- /dev/null +++ b/src/main/java/org/jeecg/modules/mdc/entity/FactoryEquipment.java @@ -0,0 +1,53 @@ +package org.jeecg.modules.mdc.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 浜х嚎璁惧 + * + * @author: LiuS + * @create: 2023-03-24 15:54 + */ +@Data +@TableName("base_equipment_factory") +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value = "base_equipment_factory瀵硅薄", description = "浜х嚎璁惧琛�") +public class FactoryEquipment implements Serializable { + + private static final long serialVersionUID = 1684188898785392096L; + + /** + * 涓婚敭id + */ + @TableId(type = IdType.ASSIGN_ID) + private String id; + /** + * 浜х嚎id + */ + private String factoryId; + /** + * 璁惧id + */ + private String equipmentId; + + public FactoryEquipment(String id, String factoryId, String equipmentId) { + super(); + this.id = id; + this.factoryId = factoryId; + this.equipmentId = equipmentId; + } + + public FactoryEquipment(String id, String factoryId) { + this.equipmentId = id; + this.factoryId = factoryId; + } +} diff --git a/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipment.java b/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipment.java index cacada2..8f7631e 100644 --- a/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipment.java +++ b/src/main/java/org/jeecg/modules/mdc/entity/MdcEquipment.java @@ -172,7 +172,7 @@ @TableField(exist = false) @ApiModelProperty(value = "閫夋嫨鐨勪骇绾縤d闆嗗悎") - private String selectedProduction; + private String selectedFactory; // 鍏宠仈浜х嚎锛堥潪鏁版嵁搴撳瓧娈碉級 private transient String productionId; diff --git a/src/main/java/org/jeecg/modules/mdc/mapper/FactoryEquipmentMapper.java b/src/main/java/org/jeecg/modules/mdc/mapper/FactoryEquipmentMapper.java new file mode 100644 index 0000000..7e6ea01 --- /dev/null +++ b/src/main/java/org/jeecg/modules/mdc/mapper/FactoryEquipmentMapper.java @@ -0,0 +1,13 @@ +package org.jeecg.modules.mdc.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.mdc.entity.FactoryEquipment; + +/** + * 浜х嚎璁惧mapper鎺ュ彛 + * + * @author: LiuS + * @create: 2023-03-24 16:00 + */ +public interface FactoryEquipmentMapper extends BaseMapper<FactoryEquipment> { +} diff --git a/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java b/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java index 0a71450..f5b6fba 100644 --- a/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java +++ b/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java @@ -144,4 +144,9 @@ List<String> getEquIdsByProIds(@Param("proIds") List<String> proIds); List<MdcEquipment> getEquipmentList(@Param("allProductionIds") List<String> allProductionIds); + + List<MdcEquipment> queryByFactoryId(@Param("factoryId") String factoryId); + + List<String> queryIdsByFactorys(@Param("allFactoryIds") List<String> allFactoryIds); + } diff --git a/src/main/java/org/jeecg/modules/mdc/mapper/xml/FactoryEquipmentMapper.xml b/src/main/java/org/jeecg/modules/mdc/mapper/xml/FactoryEquipmentMapper.xml new file mode 100644 index 0000000..bad8d7f --- /dev/null +++ b/src/main/java/org/jeecg/modules/mdc/mapper/xml/FactoryEquipmentMapper.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="org.jeecg.modules.mdc.mapper.FactoryEquipmentMapper"> + +</mapper> \ No newline at end of file diff --git a/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml b/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml index 4e876b7..3087928 100644 --- a/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml +++ b/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml @@ -12,7 +12,7 @@ <!--鏌ヨ璁惧鐨勬墍灞炰骇绾垮悕绉颁俊鎭�--> <select id="getProNamesByEquipmentIds" resultType="org.jeecg.modules.mdc.vo.MdcEquipmentProVo"> - SELECT p.production_name, pe.equipment_id FROM mdc_production_equipment pe, mdc_production p WHERE p.id = pe.production_id AND pe.equipment_id IN + SELECT f.factory_name, bef.equipment_id FROM base_equipment_factory bef, base_factory f WHERE f.id = bef.factory_id AND bef.equipment_id IN <foreach collection="equipmentIds" index="index" item="id" open="(" separator="," close=")"> #{id} </foreach> @@ -402,4 +402,29 @@ </where> </select> + <select id="queryByFactoryId" resultType="org.jeecg.modules.mdc.entity.MdcEquipment"> + SELECT + me.* + FROM + base_equipment_factory bef, + mdc_equipment me + WHERE + bef.equipment_id = me.id + AND bef.factory_id = #{ factoryId } + ORDER BY me.equipment_id + </select> + + <select id="queryIdsByFactorys" resultType="java.lang.String"> + SELECT + me.equipment_id + FROM + mdc_equipment me + LEFT JOIN base_equipment_factory bef ON me.id = bef.equipment_id + WHERE + bef.factory_id IN + <foreach collection="allFactoryIds" index="index" item="id" open="(" separator="," close=")"> + #{id} + </foreach> + </select> + </mapper> diff --git a/src/main/java/org/jeecg/modules/mdc/model/FactoryTreeModel.java b/src/main/java/org/jeecg/modules/mdc/model/FactoryTreeModel.java new file mode 100644 index 0000000..fce7e1a --- /dev/null +++ b/src/main/java/org/jeecg/modules/mdc/model/FactoryTreeModel.java @@ -0,0 +1,112 @@ +package org.jeecg.modules.mdc.model; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.modules.base.entity.Factory; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @author: LiuS + * @create: 2023-03-23 14:16 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value = "浜х嚎琛ㄦ爲缁撴瀯鏁版嵁瀹炰綋", description = "浜х嚎琛�") +public class FactoryTreeModel implements Serializable { + + private static final long serialVersionUID = -1309711609760828658L; + + /** + * 瀵瑰簲MdcProduction涓殑id瀛楁,鍓嶇鏁版嵁鏍戜腑鐨刱ey + */ + private String key; + + /** + * 瀵瑰簲MdcProduction涓殑id瀛楁,鍓嶇鏁版嵁鏍戜腑鐨剉alue + */ + private String value; + + /** + * 瀵瑰簲depart_name瀛楁,鍓嶇鏁版嵁鏍戜腑鐨則itle + */ + private String title; + + private boolean isLeaf; + + /** + * 绫诲瀷 + */ + private Integer type; + //浠ヤ笅鎵�鏈夊瓧娈靛潎涓嶮dcProduction鐩稿悓 + + private String id; + + private String createBy; + + private Date createTime; + + private String updateBy; + + private Date updateTime; + + private Integer delFlag; + + private String factoryName; + + private String factoryCode; + + private String parentId; + + private String factoryStatus; + + private String factoryCategory; + + private Integer sorter; + + private String address; + + private String mdcFlag; + + private String remark; + + /** + * 浜х嚎璐熻矗浜篿ds + */ + private String directorUserIds; + + private List<FactoryTreeModel> children = new ArrayList<>(); + + public FactoryTreeModel() { + + } + + /** + * 灏哅dcProduction瀵硅薄杞崲鎴怣dcProductionTreeModel瀵硅薄 + * + * @param factory + */ + public FactoryTreeModel(Factory factory) { + this.key = factory.getId(); + this.value = factory.getId(); + this.title = factory.getFactoryName(); + this.id = factory.getId(); + this.parentId = factory.getParentId(); + this.factoryName = factory.getFactoryName(); + this.sorter = factory.getSorter(); + this.factoryCode = factory.getFactoryCode(); + this.address = factory.getAddress(); + this.delFlag = factory.getDelFlag(); + this.createBy = factory.getCreateBy(); + this.createTime = factory.getCreateTime(); + this.updateBy = factory.getUpdateBy(); + this.updateTime = factory.getUpdateTime(); + this.mdcFlag = factory.getMdcFlag(); + } +} diff --git a/src/main/java/org/jeecg/modules/mdc/model/MdcEquipmentTree.java b/src/main/java/org/jeecg/modules/mdc/model/MdcEquipmentTree.java index 1e2740f..c825cc7 100644 --- a/src/main/java/org/jeecg/modules/mdc/model/MdcEquipmentTree.java +++ b/src/main/java/org/jeecg/modules/mdc/model/MdcEquipmentTree.java @@ -122,5 +122,18 @@ return this; } + /** + * 灏唌dcProductionTreeModel鐨勯儴鍒嗘暟鎹斁鍦ㄨ瀵硅薄褰撲腑 + * @param treeModel + * @return + */ + public MdcEquipmentTree convertByFactory(FactoryTreeModel treeModel) { + this.key = treeModel.getId(); + this.value = treeModel.getId(); + this.title = treeModel.getFactoryName(); + this.type = treeModel.getType(); + return this; + } + } diff --git a/src/main/java/org/jeecg/modules/mdc/service/IFactoryEquipmentService.java b/src/main/java/org/jeecg/modules/mdc/service/IFactoryEquipmentService.java new file mode 100644 index 0000000..2173a5a --- /dev/null +++ b/src/main/java/org/jeecg/modules/mdc/service/IFactoryEquipmentService.java @@ -0,0 +1,30 @@ +package org.jeecg.modules.mdc.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.base.model.FactoryIdModel; +import org.jeecg.modules.mdc.entity.MdcEquipment; +import org.jeecg.modules.mdc.entity.FactoryEquipment; + +import java.util.List; + +/** + * @author: LiuS + * @create: 2023-03-28 10:30 + */ +public interface IFactoryEquipmentService extends IService<FactoryEquipment> { + + /** + * 鏍规嵁鎸囧畾璁惧id鏌ヨ浜х嚎淇℃伅 + */ + List<FactoryIdModel> queryFactoryIdsOfEquipment(String equipmentId); + + /** + * 鏍规嵁鎸囧畾浜х嚎id鏌ヨ璁惧淇℃伅 + */ + List<MdcEquipment> queryEquipmentsOfFactory(String factoryId); + + /** + * 鏍规嵁鎸囧畾浜х嚎ids鏌ヨ璁惧淇℃伅 + */ + List<MdcEquipment> queryEquipmentsOfFactorys(List<String> factoryIds); +} diff --git a/src/main/java/org/jeecg/modules/mdc/service/impl/FactoryEquipmentServiceImpl.java b/src/main/java/org/jeecg/modules/mdc/service/impl/FactoryEquipmentServiceImpl.java new file mode 100644 index 0000000..46c2c99 --- /dev/null +++ b/src/main/java/org/jeecg/modules/mdc/service/impl/FactoryEquipmentServiceImpl.java @@ -0,0 +1,87 @@ +package org.jeecg.modules.mdc.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.base.entity.Factory; +import org.jeecg.modules.base.model.FactoryIdModel; +import org.jeecg.modules.base.service.IFactoryService; +import org.jeecg.modules.mdc.entity.MdcEquipment; +import org.jeecg.modules.mdc.entity.FactoryEquipment; +import org.jeecg.modules.mdc.mapper.FactoryEquipmentMapper; +import org.jeecg.modules.mdc.service.IMdcEquipmentService; +import org.jeecg.modules.mdc.service.IFactoryEquipmentService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author: LiuS + * @create: 2023-03-28 10:31 + */ +@Service +public class FactoryEquipmentServiceImpl extends ServiceImpl<FactoryEquipmentMapper, FactoryEquipment> implements IFactoryEquipmentService { + + @Resource + private IFactoryService mdcFactoryService; + @Resource + private IMdcEquipmentService mdcEquipmentService; + + /** + * 鏍规嵁璁惧id鏌ヨ浜х嚎淇℃伅 + */ + @Override + public List<FactoryIdModel> queryFactoryIdsOfEquipment(String equipmentId) { + LambdaQueryWrapper<FactoryEquipment> queryEquipmentFac = new LambdaQueryWrapper<>(); + LambdaQueryWrapper<Factory> queryFac = new LambdaQueryWrapper<>(); + try { + queryEquipmentFac.eq(FactoryEquipment::getEquipmentId, equipmentId); + List<String> facIdList = new ArrayList<>(); + List<FactoryIdModel> facIdModelList = new ArrayList<>(); + List<FactoryEquipment> equipmentProList = this.list(queryEquipmentFac); + if (equipmentProList != null && !equipmentProList.isEmpty()) { + for (FactoryEquipment factoryEquipment : equipmentProList) { + facIdList.add(factoryEquipment.getFactoryId()); + } + queryFac.in(Factory::getId, facIdList); + List<Factory> proList = mdcFactoryService.list(queryFac); + if (proList != null && !proList.isEmpty()) { + for (Factory mdcFactory : proList) { + facIdModelList.add(new FactoryIdModel().convertByUserFactory(mdcFactory)); + } + } + return facIdModelList; + } + } catch (Exception e) { + e.fillInStackTrace(); + } + return null; + } + /** + * 鏍规嵁鎸囧畾浜х嚎id鏌ヨ璁惧淇℃伅 + */ + @Override + public List<MdcEquipment> queryEquipmentsOfFactory(String factoryId){ + List<String> equipmentIds = this.list(new LambdaQueryWrapper<FactoryEquipment>().eq(FactoryEquipment::getFactoryId, factoryId)) + .stream().map(FactoryEquipment::getEquipmentId).collect(Collectors.toList()); + if (!equipmentIds.isEmpty()) { + return mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().in(MdcEquipment::getId, equipmentIds)); + } + return null; + } + + /** + * 鏍规嵁鎸囧畾浜х嚎ids鏌ヨ璁惧淇℃伅 + */ + @Override + public List<MdcEquipment> queryEquipmentsOfFactorys(List<String> factoryIds){ + List<String> equipmentIds = this.list(new LambdaQueryWrapper<FactoryEquipment>() + .in(FactoryEquipment::getFactoryId, factoryIds)).stream().map(FactoryEquipment::getEquipmentId).collect(Collectors.toList()); + if (!equipmentIds.isEmpty()) { + return mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().in(MdcEquipment::getId, equipmentIds)); + } + return null; + } +} diff --git a/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java b/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java index cda1062..05d9f78 100644 --- a/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java +++ b/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java @@ -15,24 +15,23 @@ import org.jeecg.common.system.api.ISysBaseAPI; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.oConvertUtils; +import org.jeecg.modules.base.entity.Factory; +import org.jeecg.modules.base.service.IFactoryService; +import org.jeecg.modules.base.service.IUserFactoryService; +import org.jeecg.modules.base.service.impl.FactoryServiceImpl; import org.jeecg.modules.mdc.dto.MdcEquDepDto; import org.jeecg.modules.mdc.dto.MdcEquProDto; import org.jeecg.modules.mdc.dto.MdcEquipmentDetailedDto; import org.jeecg.modules.mdc.dto.MdcEquipmentDto; import org.jeecg.modules.mdc.entity.*; -import org.jeecg.modules.mdc.mapper.MdcEquipmentDepartMapper; -import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper; -import org.jeecg.modules.mdc.mapper.MdcProductionEquipmentMapper; -import org.jeecg.modules.mdc.mapper.MdcTorqueConfigMapper; +import org.jeecg.modules.mdc.mapper.*; import org.jeecg.modules.mdc.model.MdcEquipmentTree; import org.jeecg.modules.mdc.service.*; -import org.jeecg.modules.mdc.util.DateUtils; -import org.jeecg.modules.mdc.util.DncCopyEquipment; -import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil; -import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil; +import org.jeecg.modules.mdc.util.*; import org.jeecg.modules.mdc.vo.*; import org.jeecg.modules.system.entity.*; import org.jeecg.modules.system.service.*; +import org.jeecg.modules.system.util.FindsFactorysChildrenUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.CacheEvict; @@ -91,6 +90,15 @@ @Autowired private IEquipmentService equipmentService; + @Autowired + private IFactoryService factoryService; + + @Autowired + private IUserFactoryService userFactoryService; + + @Autowired + private FactoryEquipmentMapper factoryEquipmentMapper; + @Override public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) { @@ -104,7 +112,7 @@ public Map<String, String> getProNamesByEquipmentIds(List<String> equipmentIds) { List<MdcEquipmentProVo> list = this.baseMapper.getProNamesByEquipmentIds(equipmentIds); Map<String, String> res = new HashMap(5); - list.forEach(item -> res.merge(item.getEquipmentId(), item.getProductionName(), (a, b) -> a + "," + b)); + list.forEach(item -> res.merge(item.getEquipmentId(), item.getFactoryName(), (a, b) -> a + "," + b)); return res; } @@ -125,8 +133,8 @@ if (oConvertUtils.isNotEmpty(selectedProduction)) { String[] arr = selectedProduction.split(","); for (String productionId : arr) { - MdcProductionEquipment mdcProductionEquipment = new MdcProductionEquipment(mdcEquipment.getId(), productionId); - mdcProductionEquipmentMapper.insert(mdcProductionEquipment); + FactoryEquipment mdcProductionEquipment = new FactoryEquipment(mdcEquipment.getId(), productionId); + factoryEquipmentMapper.insert(mdcProductionEquipment); } } } @@ -152,17 +160,17 @@ } } //step.3 淇敼浜х嚎 - String productions = mdcEquipment.getSelectedProduction(); + String productions = mdcEquipment.getSelectedFactory(); String[] array = {}; if (oConvertUtils.isNotEmpty(productions)) { array = productions.split(","); } //鍏堝垹鍚庡姞 - mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, mdcEquipment.getId())); + factoryEquipmentMapper.delete(new LambdaQueryWrapper<FactoryEquipment>().eq(FactoryEquipment::getEquipmentId, mdcEquipment.getId())); if (oConvertUtils.isNotEmpty(productions)) { for (String productionId : array) { - MdcProductionEquipment productionEquipment = new MdcProductionEquipment(mdcEquipment.getId(), productionId); - mdcProductionEquipmentMapper.insert(productionEquipment); + FactoryEquipment productionEquipment = new FactoryEquipment(mdcEquipment.getId(), productionId); + factoryEquipmentMapper.insert(productionEquipment); } } } @@ -176,7 +184,7 @@ // 2. 鍒犻櫎璁惧閮ㄩ棬鍏崇郴 line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, id)); // 3. 鍒犻櫎璁惧浜х嚎鍏崇郴 - line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, id)); + line += factoryEquipmentMapper.delete(new LambdaQueryWrapper<FactoryEquipment>().eq(FactoryEquipment::getEquipmentId, id)); return line != 0; } @@ -189,7 +197,7 @@ // 2. 鍒犻櫎璁惧閮ㄩ棬鍏崇郴 line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().in(MdcEquipmentDepart::getEquipmentId, equipmentIds)); // 3. 鍒犻櫎璁惧浜х嚎鍏崇郴 - line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().in(MdcProductionEquipment::getEquipmentId, equipmentIds)); + line += factoryEquipmentMapper.delete(new LambdaQueryWrapper<FactoryEquipment>().in(FactoryEquipment::getEquipmentId, equipmentIds)); return line != 0; } @@ -293,23 +301,84 @@ @Override public List<MdcEquipmentTree> loadTreeListByProduction(String userId) { //鑾峰彇鎵�鏈変骇绾挎暟鎹� - List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).eq(MdcProduction::getMdcFlag, CommonConstant.DEFAULT_1).orderByAsc(MdcProduction::getProductionOrder)); + List<Factory> factoryList = factoryService.list(new LambdaQueryWrapper<Factory>().eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(Factory::getSorter)); //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� - List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); - List<String> allProductionIds = new ArrayList<>(); + List<String> factoryIds = userFactoryService.queryFactoryIdsByUserId(userId); + List<String> allFactoryIds = new ArrayList<>(); //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d - if (productionIds != null && !productionIds.isEmpty()) { - for (String productionId : productionIds) { - this.getAllProductionIds(productionList, productionId, allProductionIds); + if (factoryIds != null && !factoryIds.isEmpty()) { + for (String factoryId : factoryIds) { + this.getAllFactoryIds(factoryList, factoryId, allFactoryIds); } } //杩囨护浜х嚎鏁版嵁 - List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList()); + List<Factory> list = factoryList.stream().filter((Factory factory) -> allFactoryIds.contains(factory.getId())).collect(Collectors.toList()); //缁勮浜х嚎璁惧鏍� - List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); + List<MdcEquipmentTree> treeList = FindsEquipmentFactoryUtil.wrapEquipmentFactoryTreeList(list); //濉厖璁惧鏁版嵁 - FillEquipmentByProduction(treeList); + FillEquipmentByFactory(treeList); + + +// //鑾峰彇鎵�鏈変骇绾挎暟鎹� +// List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).eq(MdcProduction::getMdcFlag, CommonConstant.DEFAULT_1).orderByAsc(MdcProduction::getProductionOrder)); +// //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� +// List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); +// List<String> allProductionIds = new ArrayList<>(); +// //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d +// if (productionIds != null && !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<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); +// 濉厖璁惧鏁版嵁 +// FillEquipmentByProduction(treeList); return treeList; + } + + /** + * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹� + */ + private void FillEquipmentByFactory(List<MdcEquipmentTree> treeList) { + for (MdcEquipmentTree mdcEquipmentTree : treeList) { + List<MdcEquipment> equipmentList = this.baseMapper.queryByFactoryId(mdcEquipmentTree.getKey()); + if (equipmentList != null && !equipmentList.isEmpty()) { + for (MdcEquipment mdcEquipment : equipmentList) { + MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment); + tree.setParentId(mdcEquipmentTree.getKey()); + tree.setEntity(mdcEquipment); + tree.setType(2); + mdcEquipmentTree.getChildren().add(tree); + } + mdcEquipmentTree.setLeaf(false); + } + if (!mdcEquipmentTree.getChildren().isEmpty()) { + FillEquipmentByFactory(mdcEquipmentTree.getChildren()); + } + } + } + + /** + * 鑾峰彇鎵�鏈夌殑浜х嚎id锛堝寘鍚墍鏈変笂绾э級 + */ + private void getAllFactoryIds(List<Factory> factoryList, String factoryId, List<String> allFactoryIds) { + if (!allFactoryIds.contains(factoryId)) { + allFactoryIds.add(factoryId); + } + for (Factory factory : factoryList) { + if (StringUtils.isEmpty(factory.getParentId())) { + continue; + } + if (factoryId.equals(factory.getId())) { + if (!allFactoryIds.contains(factory.getParentId())) { + allFactoryIds.add(factory.getParentId()); + getAllFactoryIds(factoryList, factory.getParentId(), allFactoryIds); + } + } + } } /** @@ -513,30 +582,74 @@ @Override public List<String> getEquipmentIdsProduction(String userId, String key) { //鑾峰彇鎵�鏈変骇绾挎暟鎹� - List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); + List<Factory> factoryList = factoryService.list(new LambdaQueryWrapper<Factory>().eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0).orderByAsc(Factory::getSorter)); //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� - List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); - List<String> allProductionIds = new ArrayList<>(); + List<String> factoryIds = userFactoryService.queryFactoryIdsByUserId(userId); + List<String> allFactoryIds = new ArrayList<>(); //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d - if (productionIds != null && !productionIds.isEmpty()) { - for (String productionId : productionIds) { - this.getAllProductionIds(productionList, productionId, allProductionIds); + if (factoryIds != null && !factoryIds.isEmpty()) { + for (String productionId : factoryIds) { + this.getAllFactoryIds(factoryList, productionId, allFactoryIds); } } //鏍规嵁浜х嚎闆嗗悎鏌ユ壘鎵�鏈夎澶噄d - if (allProductionIds.isEmpty()) { + if (allFactoryIds.isEmpty()) { return null; } - List<String> equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIds); + List<String> equipmentIds = this.baseMapper.queryIdsByFactorys(allFactoryIds); if (StringUtils.isNotEmpty(key)) { //key涓嶄负绌猴紝鏌ヨ鎵�鏈変笅绾т骇绾縤d - List<String> partProduction = this.findAllProductions(key); - partProduction.add(key); + List<String> partFactory = this.findAllFactorys(key); + partFactory.add(key); //杩囨护鏃犳潈闄愪骇绾縤d - List<String> allProductionIdsByKey = partProduction.stream().filter(allProductionIds::contains).collect(Collectors.toList()); - equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIdsByKey); + List<String> allFactoryIdsByKey = partFactory.stream().filter(allFactoryIds::contains).collect(Collectors.toList()); + equipmentIds = this.baseMapper.queryIdsByFactorys(allFactoryIdsByKey); } return equipmentIds; + + //鑾峰彇鎵�鏈変骇绾挎暟鎹� +// List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); +// //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� +// List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId); +// List<String> allProductionIds = new ArrayList<>(); +// //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d +// if (productionIds != null && !productionIds.isEmpty()) { +// for (String productionId : productionIds) { +// this.getAllProductionIds(productionList, productionId, allProductionIds); +// } +// } +// //鏍规嵁浜х嚎闆嗗悎鏌ユ壘鎵�鏈夎澶噄d +// if (allProductionIds.isEmpty()) { +// return null; +// } +// List<String> equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIds); +// if (StringUtils.isNotEmpty(key)) { +// //key涓嶄负绌猴紝鏌ヨ鎵�鏈変笅绾т骇绾縤d +// List<String> partProduction = this.findAllProductions(key); +// partProduction.add(key); +// //杩囨护鏃犳潈闄愪骇绾縤d +// List<String> allProductionIdsByKey = partProduction.stream().filter(allProductionIds::contains).collect(Collectors.toList()); +// equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIdsByKey); +// } +// return equipmentIds; +// + } + + /** + * 鏍规嵁鐖剁骇id閫掑綊鏌ヨ鎵�鏈変笅绾d闆嗗悎 + */ + private List<String> findAllFactorys(String key) { + List<String> factoryIds = new ArrayList<>(); + List<Factory> factorys = factoryService.queryFacByPid(key); + if (factorys != null && !factorys.isEmpty()) { + List<String> ids = factorys.stream().map(Factory::getId).collect(Collectors.toList()); + factoryIds.addAll(ids); + for (Factory factory : factorys) { + List<String> allFactorys = findAllFactorys(factory.getId()); + factoryIds.addAll(allFactorys); + } + } + return factoryIds; } /** diff --git a/src/main/java/org/jeecg/modules/mdc/util/FindsEquipmentFactoryUtil.java b/src/main/java/org/jeecg/modules/mdc/util/FindsEquipmentFactoryUtil.java new file mode 100644 index 0000000..856e836 --- /dev/null +++ b/src/main/java/org/jeecg/modules/mdc/util/FindsEquipmentFactoryUtil.java @@ -0,0 +1,80 @@ +package org.jeecg.modules.mdc.util; + +import org.jeecg.common.util.oConvertUtils; +import org.jeecg.modules.base.entity.Factory; +import org.jeecg.modules.mdc.model.MdcEquipmentTree; +import org.jeecg.modules.mdc.model.FactoryTreeModel; +import org.jeecg.modules.mdc.model.MdcProductionTreeModel; + +import java.util.ArrayList; +import java.util.List; + +/** + * 浜х嚎璁惧鏍� + * @author: LiuS + * @create: 2023-04-03 15:59 + */ +public class FindsEquipmentFactoryUtil { + + /** + * 鑾峰彇 MdcEquipmentTree + */ + public static List<MdcEquipmentTree> wrapEquipmentFactoryTreeList(List<Factory> recordList) { + List<MdcEquipmentTree> idList = new ArrayList<>(); + List<FactoryTreeModel> records = new ArrayList<>(); + for (Factory factory : recordList) { + records.add(new FactoryTreeModel(factory)); + } + getChildren(records, idList); + setEmptyChildrenAsNull(idList); + return idList; + } + + /** + * 璇ユ柟娉曟槸鎵惧埌骞跺皝瑁呴《绾х埗绫荤殑鑺傜偣鍒癟reeList闆嗗悎 + */ + private static void getChildren(List<FactoryTreeModel> recordList, List<MdcEquipmentTree> idList) { + List<FactoryTreeModel> treeList = new ArrayList<>(); + for (FactoryTreeModel factoryTreeModel : recordList) { + if (oConvertUtils.isEmpty(factoryTreeModel.getParentId())) { + factoryTreeModel.setType(1); + treeList.add(factoryTreeModel); + idList.add(new MdcEquipmentTree().convertByFactory(factoryTreeModel)); + } + } + getGrandChildren(treeList, recordList, idList); + } + + /** + *璇ユ柟娉曟槸鎵惧埌椤剁骇鐖剁被涓嬬殑鎵�鏈夊瓙鑺傜偣闆嗗悎骞跺皝瑁呭埌TreeList闆嗗悎 + */ + private static void getGrandChildren(List<FactoryTreeModel> treeList, List<FactoryTreeModel> recordList, List<MdcEquipmentTree> idList) { + for (int i = 0; i < treeList.size(); i++) { + FactoryTreeModel model = treeList.get(i); + MdcEquipmentTree mdcEquipmentTree = idList.get(i); + for (int i1 = 0; i1 < recordList.size(); i1++) { + FactoryTreeModel m = recordList.get(i1); + if (m.getParentId() != null && m.getParentId().equals(model.getId())) { + model.getChildren().add(m); + m.setType(1); + mdcEquipmentTree.getChildren().add(new MdcEquipmentTree().convertByFactory(m)); + } + } + getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren()); + } + } + + /** + * 璇ユ柟娉曟槸灏嗗瓙鑺傜偣涓虹┖鐨凩ist闆嗗悎璁剧疆涓篘ull鍊� + */ + private static void setEmptyChildrenAsNull(List<MdcEquipmentTree> idList) { + for (MdcEquipmentTree mdcEquipmentTree : idList) { + if (mdcEquipmentTree.getChildren().isEmpty()) { + mdcEquipmentTree.setLeaf(true); + } else { + setEmptyChildrenAsNull(mdcEquipmentTree.getChildren()); + mdcEquipmentTree.setLeaf(false); + } + } + } +} diff --git a/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentProVo.java b/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentProVo.java index e303df6..7e9db44 100644 --- a/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentProVo.java +++ b/src/main/java/org/jeecg/modules/mdc/vo/MdcEquipmentProVo.java @@ -9,5 +9,5 @@ @Data public class MdcEquipmentProVo { private String equipmentId; - private String productionName; + private String factoryName; } diff --git a/src/main/java/org/jeecg/modules/system/controller/SysUserController.java b/src/main/java/org/jeecg/modules/system/controller/SysUserController.java index ee03b35..9cc6fdd 100644 --- a/src/main/java/org/jeecg/modules/system/controller/SysUserController.java +++ b/src/main/java/org/jeecg/modules/system/controller/SysUserController.java @@ -253,7 +253,7 @@ Result<SysUser> result = new Result<SysUser>(); String selectedRoles = jsonObject.getString("selectedroles"); String selectedDeparts = jsonObject.getString("selecteddeparts"); - String selectedProductions = jsonObject.getString("selectedProduction"); + String selectedProductions = jsonObject.getString("selectedFactorys"); try { SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class); user.setCreateTime(new Date());//璁剧疆鍒涘缓鏃堕棿 @@ -295,7 +295,7 @@ user.setPassword(sysUser.getPassword()); String roles = jsonObject.getString("selectedroles"); String departs = jsonObject.getString("selecteddeparts"); - String productions = jsonObject.getString("selectedProduction"); + String productions = jsonObject.getString("selectedFactorys"); if (oConvertUtils.isEmpty(departs)) { //vue3.0鍓嶇鍙紶閫掍簡departIds departs = user.getDepartIds(); @@ -476,17 +476,17 @@ } - @AutoLog(value = "鐢ㄦ埛琛�-鏌ヨ鎸囧畾鐢ㄦ埛鍜屼骇绾垮叧鑱旂殑鏁版嵁") - @ApiOperation(value = "鐢ㄦ埛琛�-鏌ヨ鎸囧畾鐢ㄦ埛鍜屼骇绾垮叧鑱旂殑鏁版嵁", notes = "鐢ㄦ埛琛�-鏌ヨ鎸囧畾鐢ㄦ埛鍜屼骇绾垮叧鑱旂殑鏁版嵁") - @GetMapping(value = "/userProductionList") - public Result<List<ProductionIdModel>> getUserProductionsList(@RequestParam(name = "userId", required = true) String userId) { - Result<List<ProductionIdModel>> result = new Result<>(); + @AutoLog(value = "鐢ㄦ埛琛�-鏌ヨ鎸囧畾鐢ㄦ埛鍜屽伐鍘傚缓妯″叧鑱旂殑鏁版嵁") + @ApiOperation(value = "鐢ㄦ埛琛�-鏌ヨ鎸囧畾鐢ㄦ埛鍜屽伐鍘傚缓妯″叧鑱旂殑鏁版嵁", notes = "鐢ㄦ埛琛�-鏌ヨ鎸囧畾鐢ㄦ埛鍜屽伐鍘傚缓妯″叧鑱旂殑鏁版嵁") + @GetMapping(value = "/userFactorysList") + public Result<List<FactoryIdModel>> getUserFactorysList(@RequestParam(name = "userId", required = true) String userId) { + Result<List<FactoryIdModel>> result = new Result<>(); try { - List<ProductionIdModel> proIdModelList = this.userProductionService.queryProductionIdsOfUser(userId); - if (proIdModelList != null && !proIdModelList.isEmpty()) { + List<FactoryIdModel> facIdModelList = this.userFactoryService.queryFactoryIdsOfUser(userId); + if (facIdModelList != null && !facIdModelList.isEmpty()) { result.setSuccess(true); result.setMessage("鏌ユ壘鎴愬姛"); - result.setResult(proIdModelList); + result.setResult(facIdModelList); } else { result.setSuccess(false); result.setMessage("鏌ユ壘澶辫触"); diff --git a/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml b/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml index f698980..3cd3bec 100644 --- a/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml +++ b/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml @@ -185,7 +185,7 @@ <!-- 鏌ヨ鐢ㄦ埛鐨勬墍灞炰骇绾垮悕绉颁俊鎭� --> <select id="getProNamesByUserIds" resultType="org.jeecg.modules.system.vo.MdcUserProVo"> - SELECT p.production_name, up.user_id FROM mdc_user_production up, mdc_production p WHERE p.id = up.pro_id AND up.user_id IN + SELECT p.factory_name productionName, up.user_id FROM base_user_factory up, base_factory p WHERE p.id = up.factory_id AND up.user_id IN <foreach collection="userIds" index="index" item="id" open="(" separator="," close=")"> #{id} </foreach> diff --git a/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java b/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java index f00f3a7..b38d527 100644 --- a/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java +++ b/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java @@ -522,7 +522,7 @@ // 2. 鍒犻櫎鐢ㄦ埛閮ㄩ棬鍏崇郴 line += sysUserDepartMapper.delete(new LambdaQueryWrapper<SysUserDepart>().in(SysUserDepart::getUserId, userIds)); // 3. 鍒犻櫎鐢ㄦ埛浜х嚎鍏崇郴 - line += mdcUserProductionMapper.delete(new LambdaQueryWrapper<MdcUserProduction>().in(MdcUserProduction::getUserId, userIds)); + line += userFactoryMapper.delete(new LambdaQueryWrapper<UserFactory>().in(UserFactory::getUserId, userIds)); //3. 鍒犻櫎鐢ㄦ埛瑙掕壊鍏崇郴 line += sysUserRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, userIds)); //4.鍚屾鍒犻櫎绗笁鏂笰pp鐨勭敤鎴� @@ -592,8 +592,8 @@ if (oConvertUtils.isNotEmpty(selectedProductions)) { arr = selectedProductions.split(","); for (String productionId : arr) { - MdcUserProduction mdcUserProduction = new MdcUserProduction(user.getId(), productionId); - mdcUserProductionMapper.insert(mdcUserProduction); + UserFactory mdcUserProduction = new UserFactory(productionId, user.getId()); + userFactoryMapper.insert(mdcUserProduction); } } //step.5 淇濆瓨璁惧鏉冮檺 @@ -661,13 +661,14 @@ array = productions.split(","); } //鍏堝垹鍚庡姞 - mdcUserProductionMapper.delete(new QueryWrapper<MdcUserProduction>().lambda().eq(MdcUserProduction::getUserId, user.getId())); + userFactoryMapper.delete(new QueryWrapper<UserFactory>().lambda().eq(UserFactory::getUserId, user.getId())); if (oConvertUtils.isNotEmpty(productions)) { for (String productionId : array) { - MdcUserProduction mdcUserProduction = new MdcUserProduction(user.getId(), productionId); - mdcUserProductionMapper.insert(mdcUserProduction); + UserFactory mdcUserProduction = new UserFactory(productionId, user.getId()); + userFactoryMapper.insert(mdcUserProduction); } } + //step.5 淇敼璁惧鏉冮檺 //鍏堝垹鍚庡姞 // dncDevicePermissionMapper.delete(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getUserId, user.getId())); -- Gitblit v1.9.3