package com.ld.igds.n2.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.models.DicTrigger;
|
import com.ld.igds.models.N2IntelTask;
|
import com.ld.igds.n2.N2ModelTag;
|
import com.ld.igds.n2.N2Util;
|
import com.ld.igds.n2.dto.N2AutoData;
|
import com.ld.igds.n2.dto.N2MacData;
|
import com.ld.igds.n2.dto.N2Param;
|
import com.ld.igds.n2.mapper.N2ServiceMapper;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.RedisUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
@Slf4j
|
@Component
|
public class CoreN2ServiceImpl implements CoreN2Service {
|
|
|
@Autowired
|
private N2ServiceMapper n2ServiceMapper;
|
@Autowired
|
private RedisUtil redisUtil;
|
@Resource
|
private HMacConfService hMacConfService;
|
|
@Override
|
public void updateN2MacBySerId(N2MacData data) {
|
hMacConfService.updateMac(data);
|
}
|
|
@Override
|
public List<N2AutoData> listAutoData(N2Param param) {
|
return n2ServiceMapper.listAutoData(param);
|
}
|
|
@Override
|
public List<ExeDevice> listAutoConfData(N2Param param) {
|
if (null == param.getAutoId()) {
|
log.error("没有获取到模式的信息,查询失败");
|
return null;
|
}
|
|
List<ExeDevice> list = n2ServiceMapper.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())) {
|
result.add(device);
|
}
|
if (DeviceType.TYPE_07.getCode().equals(device.getType())) {
|
result.add(device);
|
}
|
if (DeviceType.TYPE_09.getCode().equals(device.getType())) {
|
result.add(device);
|
}
|
if (DeviceType.TYPE_0D.getCode().equals(device.getType())) {
|
result.add(device);
|
}
|
|
}
|
return result;
|
}
|
|
@Override
|
public N2AutoData queryAutoDataById(N2Param param) {
|
if (StringUtils.isEmpty(param.getAutoId())) {
|
return null;
|
}
|
N2AutoData result = n2ServiceMapper.queryAutoDataById(param);
|
if (null == result) {
|
return null;
|
}
|
result.setListConf(this.listAutoConfData(param));
|
return result;
|
}
|
|
@Override
|
public N2AutoData queryAutoDataByModeTag(N2Param param) {
|
if (StringUtils.isEmpty(param.getModeTag())) {
|
return null;
|
}
|
|
List<N2AutoData> list = n2ServiceMapper.queryAutoDataByModeTag(param);
|
|
if (null == list || list.isEmpty()) return null;
|
|
N2AutoData result = list.get(0);
|
param.setAutoId(result.getId());
|
result.setListConf(this.listAutoConfData(param));
|
return result;
|
}
|
|
@Override
|
public Map<String, List<ExeDevice>> getExeDeviceByAutoConf(
|
List<ExeDevice> listConf, String closeTag) {
|
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(closeTag)) {
|
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 (DeviceType.TYPE_0C.getCode().equals(device.getType())
|
|| DeviceType.TYPE_02.getCode().equals(
|
device.getType())) {
|
device.setTargetStatus(DeviceStatus.W_CLOSE.getCode());
|
}
|
}
|
if (DeviceStatus.F_OPEN_F.getCode().equals(
|
device.getTargetStatus())) {
|
device.setTargetStatus(DeviceStatus.F_CLOSE.getCode());
|
if (DeviceType.TYPE_0C.getCode().equals(device.getType())
|
|| DeviceType.TYPE_02.getCode().equals(
|
device.getType())) {
|
device.setTargetStatus(DeviceStatus.W_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(N2AutoData data) {
|
|
if (null == data.getDelTag()) data.setDelTag(Constant.YN_N);
|
|
if (Constant.YN_Y.equals(data.getDelTag())) {
|
n2ServiceMapper.delAuto(data.getId());
|
return "数据删除完成!";
|
}
|
|
data.setUpdateTime(new Date());
|
data.setUpdateUser(ContextUtil.getLoginUserCName());
|
|
if (StringUtils.isEmpty(data.getExeMode())) {
|
data.setExeMode(N2Util.EXE_MODE_01);
|
}
|
|
if (StringUtils.isEmpty(data.getId())) {
|
data.setId(ContextUtil.getUUID());
|
n2ServiceMapper.addAuto(data);
|
|
return "数据新增成功!";
|
}
|
|
n2ServiceMapper.updateAuto(data);
|
return "数据更新完成!";
|
}
|
|
@Override
|
public String updateAutoConf(String autoId, List<ExeDevice> deviceList) {
|
// 根据模式ID删除原有的配置信息
|
n2ServiceMapper.delAutoConfByAutoId(autoId);
|
|
// 遍历设备信息,将目标状态= NONE的设备踢出
|
for (ExeDevice device : deviceList) {
|
if (StringUtils.isEmpty(device.getTargetStatus())
|
|| DeviceStatus.ZERO.getCode().equals(
|
device.getTargetStatus())) {
|
// do nothing
|
} else {
|
device.setAutoId(autoId);
|
n2ServiceMapper.addAutoConf(device);
|
}
|
}
|
return "配置更新成功!";
|
}
|
|
@Override
|
public List<DicTrigger> listN2ModelTag(String allTag) {
|
List<DicTrigger> list = new ArrayList<>();
|
|
list.add(new DicTrigger(N2ModelTag.MODEL_01.getCode(), N2ModelTag.MODEL_01.getMsg()));
|
list.add(new DicTrigger(N2ModelTag.MODEL_02.getCode(), N2ModelTag.MODEL_02.getMsg()));
|
list.add(new DicTrigger(N2ModelTag.MODEL_03.getCode(), N2ModelTag.MODEL_03.getMsg()));
|
list.add(new DicTrigger(N2ModelTag.MODEL_04.getCode(), N2ModelTag.MODEL_04.getMsg()));
|
|
list.add(new DicTrigger(N2ModelTag.MODEL_30.getCode(), N2ModelTag.MODEL_30.getMsg()));
|
list.add(new DicTrigger(N2ModelTag.MODEL_31.getCode(), N2ModelTag.MODEL_31.getMsg()));
|
|
list.add(new DicTrigger(N2ModelTag.MODEL_99.getCode(), N2ModelTag.MODEL_99.getMsg()));
|
return list;
|
}
|
|
@Override
|
public void addIntelTaskCache(N2IntelTask task) {
|
String key = N2Util.createIntelTaskKey(task);
|
long time = N2Util.getIntelTaskTime(task);
|
|
redisUtil.set(key, task, time);
|
}
|
|
@Override
|
public List<N2IntelTask> listIntelTaskByCache(N2Param param) {
|
if (null == param) param = new N2Param();
|
String patten = N2Util.createIntelTaskKeyPatten();
|
|
Set<String> keys = redisUtil.keys(patten);
|
|
if (null == keys || keys.isEmpty()) return null;
|
|
List<N2IntelTask> result = new ArrayList<>();
|
N2IntelTask task;
|
for (String key : keys) {
|
task = (N2IntelTask) redisUtil.get(key);
|
if (null == task) continue;
|
|
if (null == param.getDepotId()) {
|
result.add(task);
|
continue;
|
}
|
|
//如果有仓库信息,只返回当前仓库相关的任务
|
if (task.getDepotId().equals(param.getDepotId())) {
|
result.add(task);
|
continue;
|
}
|
}
|
return result;
|
}
|
|
|
}
|