lyh
2 天以前 b508ec38ddf9ed93d4435e8f1e3c4effef798aaa
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
package com.lxzn.nc.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxzn.framework.domain.nc.DeviceType;
import com.lxzn.framework.domain.nc.response.DeviceCode;
import com.lxzn.framework.domain.nc.response.ProcessInfoCode;
import com.lxzn.framework.exception.ExceptionCast;
import com.lxzn.framework.model.response.CommonCode;
import com.lxzn.framework.utils.ValidateUtil;
import com.lxzn.nc.dao.DeviceTypeMapper;
import com.lxzn.nc.service.IDeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements IDeviceTypeService {
 
 
    /**
     * 新增设备类
     * @param deviceType
     * @return
     */
    @Override
    public boolean add(DeviceType deviceType){
 
        //已启动设备类
        if(!ValidateUtil.validateString(deviceType.getAttributionId()))
            ExceptionCast.cast(DeviceCode.DEVICE_CLASS_ERROR);
        List<DeviceType> deviceTypes=this.getByProductionIdAndDeviceManagementId(deviceType);
        if(!deviceTypes.isEmpty()){
            ExceptionCast.cast(DeviceCode.DEVICE_CLASS_NAME_EXIST);
        }
        return this.save(deviceType);
    }
    /**
     * 编辑设备类
     * @param deviceType
     * @return
     */
    @Override
    public boolean edit(DeviceType deviceType){
        if(deviceType == null)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        if(deviceType.getDeviceManagementId()==null)
            ExceptionCast.cast(ProcessInfoCode.PROCESS_NAME_NONE);
        DeviceType en = super.getById(deviceType.getId());
        if(en == null)
            ExceptionCast.cast(DeviceCode.DEVICE_CLASS_ERROR);
        //判断设备类是否为本身
        if(en.getDeviceManagementId().equals(deviceType.getDeviceManagementId())
                &&en.getProductionId().equals(deviceType.getProductionId())
                &&en.getAttributionId().equals(deviceType.getAttributionId())
                &&en.getAttributionType().equals(deviceType.getAttributionType())){
            return true;
        }
        //判断设备类是否被使用
        List<DeviceType> deviceTypeList=this.getByProductionIdAndDeviceManagementId(deviceType);
        if(!deviceTypeList.isEmpty()){
            ExceptionCast.cast(DeviceCode.DEVICE_CLASS_EXIST);
        }
        return this.updateById(deviceType);
    }
    /**
     * 根据id删除设备类
     * @param id
     * @return
     */
    @Override
    public boolean delete(String id){
        if(!ValidateUtil.validateString(id))
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        DeviceType en = super.getById(id);
        if(en == null)
            ExceptionCast.cast(DeviceCode.DEVICE_CLASS_ERROR);
        return super.removeById(id);
    }
 
 
    /**
     * 通过车间id与设备类id查询设备信息
     * @param deviceType
     * @return
     */
    public List<DeviceType> getByProductionIdAndDeviceManagementId(DeviceType deviceType) {
        List<DeviceType> list = this.list(new QueryWrapper<DeviceType>().eq("attribution_id", deviceType.getAttributionId())
                .eq("attribution_type", deviceType.getAttributionType())
                .eq("device_management_id", deviceType.getDeviceManagementId()));
//        list.forEach(item->{
//            item.setDeviceManagementCode(item.getDeviceManagementId());
//        });
        return list;
    }
 
 
    /**
     * 根据业务id查询设备类列表
     * @param businessId
     * @param type
     * @return
     */
    @Override
    public List<DeviceType> getByBusinessId(String businessId,String type){
        List<DeviceType> list = this.list(new QueryWrapper<DeviceType>().eq("attribution_id", businessId).eq("attribution_type", type));
//        list.forEach(item->{
//            item.setDeviceManagementCode(item.getDeviceManagementId());
//        });
        return list;
    }
}