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 "配置更新成功!";
|
}
|
}
|