CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package com.ld.igds.verb.service;
 
import com.ld.igds.constant.Constant;
import com.ld.igds.constant.DeviceStatus;
import com.ld.igds.constant.DeviceType;
import com.ld.igds.io.request.ExeDevice;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.verb.AreationConst;
import com.ld.igds.verb.dto.VerbAutoData;
import com.ld.igds.verb.dto.VerbParam;
import com.ld.igds.verb.mapper.AreationMapper;
 
import lombok.extern.slf4j.Slf4j;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
 
/**
 * 接口实现类型
 *
 * @author: andy.jia
 * @description:
 * @version:
 * @data:2020年1月12日
 */
@Slf4j
@Component
public class CoreAreationServiceImpl implements CoreAreationService {
 
    @Autowired
    private AreationMapper areationMapper;
 
    @Override
    public List<VerbAutoData> listAutoData(VerbParam param) {
        return areationMapper.listAutoData(param);
    }
 
    @Override
    public List<ExeDevice> listAutoConfData(VerbParam param) {
        if (null == param.getAutoId()) {
            log.error("没有获取到模式的信息,查询失败");
            return null;
        }
 
        List<ExeDevice> list = areationMapper.listAutoDataConf(param);
        if (null == list || list.isEmpty())
            return null;
 
        // 调整数据,只获取通风设备
        List<ExeDevice> result = new ArrayList<>();
        for (ExeDevice device : list) {
            if (DeviceType.TYPE_04.getCode().equals(device.getType())) {
                continue;
            }
            if (DeviceType.TYPE_05.getCode().equals(device.getType())) {
                continue;
            }
            if (DeviceType.TYPE_06.getCode().equals(device.getType())) {
                continue;
            }
            if (DeviceType.TYPE_07.getCode().equals(device.getType())) {
                continue;
            }
            if (DeviceType.TYPE_08.getCode().equals(device.getType())) {
                continue;
            }
            if (DeviceType.TYPE_0D.getCode().equals(device.getType())) {
                continue;
            }
            if (DeviceType.TYPE_0E.getCode().equals(device.getType())) {
                continue;
            }
 
            result.add(device);
        }
        return result;
    }
 
    @Override
    public VerbAutoData queryAutoDataById(VerbParam param) {
        if (StringUtils.isEmpty(param.getAutoId())) {
            return null;
        }
        VerbAutoData data = areationMapper.queryAutoDataById(param);
 
        if (null == data) {
            return null;
        }
        List<ExeDevice> list = this.listAutoConfData(param);
        data.setListConf(list);
 
        return data;
    }
 
    @Override
    public Map<String, List<ExeDevice>> getExeDeviceByAutoConf(
            List<ExeDevice> listConf, String modeClose) {
        if (null == listConf || listConf.isEmpty())
            return null;
 
        Map<String, List<ExeDevice>> result = new HashMap<>();
        for (ExeDevice device : listConf) {
 
            // 屏蔽需要操作的设备信息
            if (null == device.getTargetStatus()) {
                continue;
            }
            if (DeviceStatus.CLOSE.getCode().equals(device.getTargetStatus())) {
                continue;
            }
            if (DeviceStatus.F_CLOSE.getCode().equals(device.getTargetStatus())) {
                continue;
            }
            if (DeviceStatus.W_CLOSE.getCode().equals(device.getTargetStatus())) {
                continue;
            }
 
            // 需要操作的设备,在执行关闭时候执行反向动作
            if (Constant.YN_Y.equals(modeClose)) {
                if (DeviceStatus.OPEN.getCode().equals(device.getTargetStatus())) {
                    device.setTargetStatus(DeviceStatus.CLOSE.getCode());
                }
                if (DeviceStatus.W_OPEN.getCode().equals(device.getTargetStatus())) {
                    device.setTargetStatus(DeviceStatus.W_CLOSE.getCode());
                }
                if (DeviceStatus.F_OPEN.getCode().equals(device.getTargetStatus())) {
                    device.setTargetStatus(DeviceStatus.F_CLOSE.getCode());
                }
                if (DeviceStatus.F_OPEN_F.getCode().equals(device.getTargetStatus())) {
                    device.setTargetStatus(DeviceStatus.F_CLOSE.getCode());
                }
            }
 
            // 执行分组
            if (null == result.get(device.getSerId())) {
                result.put(device.getSerId(), new ArrayList<>());
            }
 
            result.get(device.getSerId()).add(device);
        }
 
        return result;
    }
 
    @Override
    public String updateAuto(VerbAutoData data) {
        if (StringUtils.isNotEmpty(data.getDelTag())
                && Constant.YN_Y.equals(data.getDelTag())) {
            areationMapper.delAuto(data.getId());
            return "数据删除完成!";
        }
 
        if (StringUtils.isEmpty(data.getId())) {
            data.setId(ContextUtil.getUUID());
            areationMapper.addAuto(data);
            return "数据新增成功!";
        }
 
        areationMapper.updateAuto(data);
        return "数据更新完成!";
    }
 
    @Override
    public String updateAutoConf(String autoId, List<ExeDevice> deviceList) {
 
        // 根据模式ID删除原有的配置信息
        areationMapper.delAutoConfByAutoId(autoId);
 
        // 遍历设备信息,将目标状态= NONE的设备踢出
        for (ExeDevice device : deviceList) {
            if (StringUtils.isEmpty(device.getTargetStatus())
                    || DeviceStatus.ZERO.getCode().equals(
                    device.getTargetStatus())) {
                // do nothing
            } else {
                device.setAutoId(autoId);
                areationMapper.addAutoConf(device);
            }
        }
        return "配置更新成功!";
    }
}