lyh
2025-03-07 b864148d2a9afd5e1627b761da923cca8f8dfbd2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package org.jeecg.modules.dnc.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.dnc.entity.DeviceType;
import org.jeecg.modules.dnc.exception.ExceptionCast;
import org.jeecg.modules.dnc.mapper.DeviceTypeMapper;
import org.jeecg.modules.dnc.response.CommonCode;
import org.jeecg.modules.dnc.response.ProcessInfoCode;
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.MdcProductionEquipment;
import org.jeecg.modules.system.entity.SysParams;
import org.jeecg.modules.system.service.ISysParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements IDeviceTypeService {
 
    @Autowired
    private ISysParamsService sysParamsService;
 
    @Autowired
    private IMdcEquipmentService mdcEquipmentService;
 
    @Autowired
    private IMdcProductionEquipmentService mdcProductionEquipmentService;
 
    /**
     * 新增设备类
     * @param deviceType
     * @return
     */
    public Result<?> add(DeviceType deviceType){
        SysParams sysParams = sysParamsService.getSysPramBySettingKey("dnc_nc_device_type");
        if ("-1".equals(sysParams.getSettingValue())){
            //未启动设备类
            return Result.error("设备类未启动,请联系管理员");
        }else {
            //已启动设备类
            if(deviceType == null)
                ExceptionCast.cast(CommonCode.INVALID_PARAM);
            if(!ValidateUtil.validateString(deviceType.getProcessStepId()))
                Result.error("无效的设备类");
            boolean save = this.save(deviceType);
            if(save){
                return Result.OK("添加设备类成功");
            }
            return Result.error("新增设备类失败");
        }
    }
    /**
     * 编辑设备类
     * @param deviceType
     * @return
     */
    public Result<?> edit(DeviceType deviceType){
        if(deviceType == null)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        if(deviceType.getDeviceType()==null)
            ExceptionCast.cast(ProcessInfoCode.PROCESS_NAME_NONE);
        DeviceType en = super.getById(deviceType.getId());
        if(en == null)
            ExceptionCast.cast(ProcessInfoCode.WORKSTEP_NOT_EXIST);
        boolean save = this.updateById(deviceType);
        if(save){
            return Result.OK("设备类编辑成功");
        }
        return Result.OK("设备类编辑失败");
    }
    /**
     * 根据id删除设备类
     * @param id
     * @return
     */
    public Result<?> delete(String id){
        if(!ValidateUtil.validateString(id))
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        DeviceType en = super.getById(id);
        if(en == null)
            return Result.error("无效的设备类");
        boolean b=super.removeById(id);
        if(!b) {
            return Result.error("删除设备类失败");
        }
        return Result.OK("删除设备类成功");
    }
 
    /**
     * 根据设备类信息查询对应设备类
     * @param deviceTypes
     * @return
     */
    public Result<?> getByDeviceType(List<DeviceType> deviceTypes){
        if (deviceTypes == null || deviceTypes.isEmpty()) {
            return Result.error("设备类信息为空");
        }
        List<Integer> deviceTypeIds = deviceTypes.stream().map(DeviceType::getDeviceType).collect(Collectors.toList());
        QueryWrapper<MdcEquipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("device_type", deviceTypeIds);
        List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(queryWrapper);
        return Result.OK(mdcEquipmentList);
    }
 
    /**
     * 根据业务id查询设备类列表
     * @param businessId
     * @param type
     * @return
     */
    public Result<?> getByBusinessId(String businessId,String type){
        List<DeviceType> list = this.list(new QueryWrapper<DeviceType>().eq("production_id", businessId).eq("type", type));
        if (list == null || list.isEmpty()) {
            return Result.error("设备类信息为空");
        }
        List<Integer> deviceTypeIds = list.stream().map(DeviceType::getDeviceType).collect(Collectors.toList());
        List<String> equipmentIds=mdcProductionEquipmentService.list(new QueryWrapper<MdcProductionEquipment>().in("production_id",deviceTypeIds))
                .stream().map(MdcProductionEquipment::getEquipmentId).collect(Collectors.toList());
        list.forEach(item->{
            List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(new QueryWrapper<MdcEquipment>()
                    .eq("device_type", item.getDeviceType()).in("id", equipmentIds));
            item.setEquipmentList(mdcEquipmentList);
        });
        return Result.OK(list);
    }
}