From 23855599412c4d61b38d78f0f3abd3430a48b5b1 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期三, 25 六月 2025 11:51:38 +0800
Subject: [PATCH] Merge branch 'mdc_hyjs_master'

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceManagementServiceImpl.java |  244 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 244 insertions(+), 0 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceManagementServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceManagementServiceImpl.java
new file mode 100644
index 0000000..bd5c852
--- /dev/null
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceManagementServiceImpl.java
@@ -0,0 +1,244 @@
+package org.jeecg.modules.dnc.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.modules.dnc.entity.DeviceManagement;
+import org.jeecg.modules.dnc.entity.DeviceType;
+import org.jeecg.modules.dnc.exception.ExceptionCast;
+import org.jeecg.modules.dnc.mapper.DeviceManagementMapper;
+import org.jeecg.modules.dnc.response.CommonCode;
+import org.jeecg.modules.dnc.service.IDeviceManagementService;
+import org.jeecg.modules.dnc.service.IDeviceTypeService;
+import org.jeecg.modules.dnc.utils.ValidateUtil;
+import org.jeecg.modules.mdc.entity.MdcEquipment;
+import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.mdc.service.IMdcProductionEquipmentService;
+import org.jeecg.modules.system.entity.MdcProduction;
+import org.jeecg.modules.system.entity.MdcProductionEquipment;
+import org.jeecg.modules.system.entity.MdcUserProduction;
+import org.jeecg.modules.system.service.IMdcProductionService;
+import org.jeecg.modules.system.service.IMdcUserProductionService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class DeviceManagementServiceImpl  extends ServiceImpl<DeviceManagementMapper, DeviceManagement> implements IDeviceManagementService {
+
+    @Autowired
+    private IMdcProductionService productionService;
+    @Autowired
+    private IMdcUserProductionService userProductionService;
+    @Autowired
+    private IMdcProductionEquipmentService productionEquipmentService;
+    @Autowired
+    private IMdcEquipmentService equipmentService;
+    @Autowired
+    private IDeviceTypeService deviceTypeService;
+    /**
+     * 鏂板璁惧绫讳俊鎭�
+     * @param deviceManagement
+     * @return
+     */
+    @Override
+    public Result<?> add(DeviceManagement deviceManagement){
+        if(deviceManagement == null)
+            ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        if(!ValidateUtil.validateString(deviceManagement.getEquipmentIds()))
+            Result.error("鏃犳晥鐨勮澶囩被");
+        List<DeviceManagement> deviceManagementList =this.getDeviceManagementList(deviceManagement.getProductionId(),deviceManagement.getDeviceManagementName(),deviceManagement.getDeviceManagementCode());
+        if (deviceManagementList != null && !deviceManagementList.isEmpty()) {
+            return Result.error("宸插瓨鍦ㄧ浉鍚岀殑璁惧绫�");
+        }
+        boolean save = this.save(deviceManagement);
+        if(save){
+            return Result.OK("娣诲姞璁惧绫绘垚鍔�");
+        }
+        return Result.error("鏂板璁惧绫诲け璐�");
+    }
+    /**
+     * 缂栬緫璁惧绫讳俊鎭�
+     * @param deviceManagement
+     * @return
+     */
+    @Override
+    public Result<?> edit(DeviceManagement deviceManagement){
+        // 妫�鏌ヤ紶鍏ョ殑璁惧绫诲璞℃槸鍚︿负绌�
+        if (deviceManagement == null) {
+            return Result.OK("璁惧绫诲璞′笉鑳戒负绌�");
+        }
+        // 妫�鏌ヨ澶囩被鍚嶇О鏄惁鏈夋晥
+        if (!ValidateUtil.validateString(deviceManagement.getDeviceManagementName())) {
+            return Result.OK("璁惧绫诲悕绉版棤鏁�");
+        }
+        // 鏍规嵁璁惧绫� ID 鑾峰彇璁惧绫讳俊鎭�
+        DeviceManagement existingCutter = super.getById(deviceManagement.getId());
+        if (existingCutter == null) {
+            return Result.OK("璁惧绫讳笉瀛樺湪");
+        }
+        // 杩囨护鎺夊綋鍓嶈缂栬緫鐨勮澶囩被锛屾鏌ユ槸鍚︽湁鍏朵粬璁惧绫诲瓨鍦ㄧ浉鍚岀紪鍙�
+        List<DeviceManagement> otherCuttersWithSameNo =this.getDeviceManagementList(deviceManagement.getProductionId(),deviceManagement.getDeviceManagementName(),deviceManagement.getDeviceManagementCode()).stream()
+                .filter(cut -> !cut.getId().equals(deviceManagement.getId()))
+                .collect(Collectors.toList());
+        if (!otherCuttersWithSameNo.isEmpty()) {
+            // 濡傛灉瀛樺湪闄ゅ綋鍓嶈澶囩被澶栫殑鍏朵粬璁惧绫荤紪鍙烽噸澶�
+            return Result.error("宸插瓨鍦ㄧ浉鍚岀殑璁惧绫荤紪鍙�");
+        }
+        // 灏濊瘯鏇存柊璁惧绫讳俊鎭�
+        boolean updated = this.updateById(deviceManagement);
+        if (updated) {
+            return Result.OK("璁惧绫讳俊鎭紪杈戞垚鍔�");
+        } else {
+            return Result.error("璁惧绫讳俊鎭紪杈戝け璐�");
+        }
+    }
+    /**
+     * 鏍规嵁id鍒犻櫎璁惧绫讳俊鎭�
+     * @param id
+     * @return
+     */
+    @Override
+    public Result<?> delete(String id){
+        if(!ValidateUtil.validateString(id))
+            ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        DeviceManagement en = super.getById(id);
+        if(en == null)
+            return Result.error("鏃犳晥鐨勮澶囩被");
+        List<DeviceType> deviceTypes=deviceTypeService.list(new QueryWrapper<DeviceType>().eq("device_management_id",id));
+        if(deviceTypes != null && !deviceTypes.isEmpty()){
+            return Result.error("璇ヨ澶囩被宸茶浣跨敤锛屼笉鑳藉垹闄�");
+        }
+        boolean b=super.removeById(id);
+        if(!b) {
+            return Result.error("鍒犻櫎璁惧绫诲け璐�");
+        }
+        return Result.OK("鍒犻櫎璁惧绫绘垚鍔�");
+    }
+
+    /**
+     * 鎵归噺鍒犻櫎璁惧绫�
+     * @param ids
+     * @return
+     */
+    @Override
+    public Result<?> deleteBatch(List<String> ids){
+        if(ids == null || ids.isEmpty())
+            ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        return super.removeByIds(ids) ? Result.OK("鎵归噺鍒犻櫎璁惧绫绘垚鍔�") : Result.error("鎵归噺鍒犻櫎璁惧绫诲け璐�");
+    }
+
+    /**
+     * 璁惧绫讳俊鎭垎椤垫煡璇�
+     * @param deviceManagement
+     * @param pageNo
+     * @param pageSize
+     * @return
+     */
+    @Override
+    public Result<?> query(DeviceManagement deviceManagement, Integer pageNo, Integer pageSize){
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        List<String> productIdList = Arrays.asList(user.getProductionIds().split(","));
+        QueryWrapper<DeviceManagement> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq(StrUtil.isNotEmpty(deviceManagement.getProductionId()),"production_id",deviceManagement.getProductionId());
+        queryWrapper.like(StrUtil.isNotEmpty(deviceManagement.getDeviceManagementName()),"device_management_name",deviceManagement.getDeviceManagementName());
+        queryWrapper.like(StrUtil.isNotEmpty(deviceManagement.getDeviceManagementCode()),"device_management_code",deviceManagement.getDeviceManagementCode());
+        queryWrapper.in("production_id",productIdList);
+        queryWrapper.orderByDesc("create_time");
+        Page<DeviceManagement> page = new Page<>(pageNo, pageSize);
+        IPage<DeviceManagement> pageList = super.page(page, queryWrapper);
+        return Result.OK(pageList);
+    }
+
+    /**
+     * 閫氳繃杞﹂棿id鍜岃澶囩被鍚嶇О鏌ヨ璁惧绫讳俊鎭�
+     * @param productionId
+     * @parame deviceManagementName
+     * @return
+     */
+    public List<DeviceManagement> getDeviceManagementList(String productionId,String deviceManagementName,String deviceManagementCode){
+        return super.list(new QueryWrapper<DeviceManagement>()
+                .eq(StrUtil.isNotEmpty(productionId),"production_id", productionId)
+                .eq(StrUtil.isNotEmpty(deviceManagementName),"device_management_name", deviceManagementName)
+                .eq(StrUtil.isNotEmpty(deviceManagementCode),"device_management_code", deviceManagementCode));
+    }
+
+    /**
+     * 鑾峰彇鐢ㄦ埛鏉冮檺鎷ユ湁鐨勮溅闂翠俊鎭�
+     * @param userId
+     * @return
+     */
+    @Override
+    public List<MdcProduction> getProductionIdsByUserId(String userId){
+        //鏉冮檺淇℃伅锛屾敼涓虹粨鏋勬爲鏉冮檺
+        List<MdcUserProduction> productionList = userProductionService.list(new QueryWrapper<MdcUserProduction>().eq("user_id", userId));
+        List<String> productionIds = productionList.stream().map(MdcUserProduction::getProId).collect(Collectors.toList());
+        return productionService.list(new QueryWrapper<MdcProduction>().in("id", productionIds)
+                .eq("org_type","2"));
+    }
+
+    /**
+     * 閫氳繃杞﹂棿id鏌ヨ璁惧鍒楄〃淇℃伅
+     * @param productionId
+     * @return
+     */
+    @Override
+    public IPage<MdcEquipment> getEquipmentListByProductionId(String productionId,String equipmentId,String equipmentName,Integer pageNo,Integer pageSize){
+        //鏌ヨ瀛愯妭鐐�
+        List<String> productionIds = productionService.recursionChildren(productionId);
+        if (productionIds == null) {
+            return null;
+        }
+        List<String> equipmentIds = productionEquipmentService.list(new QueryWrapper<MdcProductionEquipment>()
+               .in("production_id", productionIds))
+               .stream().map(MdcProductionEquipment::getEquipmentId).collect(Collectors.toList());
+        if (!equipmentIds.isEmpty()) {
+            QueryWrapper<MdcEquipment> queryWrapper = new QueryWrapper<MdcEquipment>()
+                    .in("id", equipmentIds)
+                    .like(StrUtil.isNotEmpty(equipmentName),"equipment_name", equipmentName)
+                    .eq(StrUtil.isNotEmpty(equipmentId),"equipment_id", equipmentId);
+            queryWrapper.orderByDesc("create_time");
+            Page<MdcEquipment> page = new Page<>(pageNo, pageSize);
+            return equipmentService.page(page, queryWrapper);
+        }
+        return null;
+    }
+
+    /**
+     * 閫氳繃杞﹂棿id鏌ヨ璁惧绫荤鐞嗗垪琛ㄤ俊鎭�
+     * @param productionId
+     * @return
+     */
+    @Override
+    public List<DeviceManagement> getDeviceManagementListByProductionId(String productionId){
+        QueryWrapper<DeviceManagement> queryWrapper = new QueryWrapper<DeviceManagement>()
+                .eq(StrUtil.isNotEmpty(productionId),"production_id", productionId);
+        queryWrapper.orderByDesc("create_time");
+        return super.list(queryWrapper);
+    }
+
+    /**
+     * 閫氳繃id鏌ヨ璁惧鍒楄〃淇℃伅
+     * @param id
+     * @return
+     */
+    @Override
+    public List<MdcEquipment> getEquipmentListById(String id){
+        DeviceManagement deviceManagement = super.getById(id);
+        if (deviceManagement == null) {
+            return null;
+        }else {
+            List<String> equipmentIds = Arrays.asList(deviceManagement.getEquipmentIds().split(","));
+            return equipmentService.list(new QueryWrapper<MdcEquipment>()
+                   .in("equipment_id", equipmentIds));
+        }
+    }
+}

--
Gitblit v1.9.3