package com.ld.igds.n2.manager;
|
|
import com.ld.igds.common.CoreCommonService;
|
import com.ld.igds.common.CoreSerService;
|
import com.ld.igds.constant.BizType;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.io.RemoteControlService;
|
import com.ld.igds.io.RemoteManager;
|
import com.ld.igds.io.constant.OrderRespEnum;
|
import com.ld.igds.io.request.DeviceAutoControlRequest;
|
import com.ld.igds.io.response.DeviceControlResponse;
|
import com.ld.igds.models.DepotConf;
|
import com.ld.igds.models.DeviceSer;
|
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.N2Param;
|
import com.ld.igds.n2.dto.N2TaskParam;
|
import com.ld.igds.n2.service.HN2Service;
|
import com.ld.igds.util.ContextUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.List;
|
|
|
/**
|
* @Desc: 智能气调业务逻辑管理页面,主要包括气密性检测流程,智能气调流程控制管理
|
* @author: Andy
|
* @update-time: 2022/12/27
|
*/
|
@Slf4j
|
@Component
|
public class N2IntelManager {
|
|
@Autowired
|
private CoreCommonService coreCommonService;
|
@Autowired
|
private RemoteManager remoteManager;
|
@Autowired
|
private CoreSerService coreSerService;
|
@Autowired
|
private HN2Service hn2Service;
|
|
|
// /**
|
// * 智能气调操作入口,实现逻辑
|
// * 1,首先验证是否满足执行的标准,设备状态是否满足,当前是否有正在执行的智能任务,比如智能通风或者其他智能任务。
|
// * 2.将新增的任务添加到任务队列中,有系统自动调用参数判断执行
|
// *
|
// * @param autoData
|
// * @param param
|
// * @param modeClose 是否执行关闭操作,针对流程来讲关闭操作的动作是停止运行,不去回复已经打开的设备状态
|
// * @return
|
// */
|
// public DeviceControlResponse exeIntel(N2AutoData autoData, N2Param param, String modeClose) {
|
// String result;
|
// if (N2Util.EXE_MODE_02.equals(autoData.getExeMode())) {
|
// result = exeIntelBySer(autoData, param, modeClose);
|
// } else {
|
// result = exeIntelBySys(autoData, param, modeClose);
|
// }
|
//
|
// if (null == result) {
|
// return new DeviceControlResponse(
|
// OrderRespEnum.ORDER_SUCCESS.getCode(), "命令发送成功,待终端执行!");
|
// }
|
//
|
// return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(),
|
// result);
|
// }
|
//
|
// /**
|
// * 当前系统执行 智能化任务
|
// *
|
// * @param autoData
|
// * @param param
|
// * @param modeClose
|
// * @return
|
// */
|
// private String exeIntelBySys(N2AutoData autoData, N2Param param, String modeClose) {
|
//
|
// //如果执行关闭任务
|
// if (Constant.YN_Y.equals(modeClose)) {
|
// return exeStopIntel(autoData, param);
|
// }
|
//
|
// //正常开启任务,系统执行需要多验证设备状态是否满足开启任务条件
|
// boolean checkTag = n2TaskCheck(param.getCompanyId(), param.getDepotId());
|
// if (checkTag) {
|
// return "当前仓库有气调任务执行中,请先关闭当前子任务!";
|
// }
|
// checkTag = airTaskCheck(param.getCompanyId(), param.getDepotId());
|
// if (checkTag) {
|
// return "当前仓库有通风任务执行中,请先关闭当前子任务!";
|
// }
|
//
|
// checkTag = airDeviceStatus(param.getCompanyId(), param.getDepotId());
|
// if (checkTag) {
|
// return "当前仓库设备通风状态有开启,不能执行当前操作!";
|
// }
|
//
|
//
|
// //创建任务,任务创建可能有多个,主任务 + 子任务
|
// addN2TaskByAuto(autoData);
|
//
|
// return null;
|
// }
|
//
|
//
|
// /**
|
// * 智能控制柜执行智能化任务
|
// *
|
// * @param autoData
|
// * @param param
|
// * @param modeClose
|
// * @return
|
// */
|
// private String exeIntelBySer(N2AutoData autoData, N2Param param, String modeClose) {
|
//
|
// //如果执行关闭任务,先要发送通知给智能控制柜,然后关闭当前任务
|
// if (Constant.YN_Y.equals(modeClose)) {
|
// String msg = exeAutoActionBySer(autoData, param, modeClose);
|
// if (null == msg) {
|
// msg = exeStopIntel(autoData, param);
|
// }
|
// return msg;
|
// }
|
//
|
// //正常开启任务,控制柜执行不验证通风状态
|
// boolean checkTag = n2TaskCheck(param.getCompanyId(), param.getDepotId());
|
// if (checkTag) {
|
// return "当前仓库有气调任务执行中,请先关闭当前子任务!";
|
// }
|
// checkTag = airTaskCheck(param.getCompanyId(), param.getDepotId());
|
// if (checkTag) {
|
// return "当前仓库有通风任务执行中,请先关闭当前子任务!";
|
// }
|
//
|
// //新增智能任务
|
// addN2TaskByAuto(autoData);
|
//
|
// return exeAutoActionBySer(autoData, param, modeClose);
|
// }
|
//
|
//
|
// public String exeAutoActionBySer(N2AutoData autoData, N2Param param, String modeClose) {
|
//
|
// DepotConf depotConf = coreCommonService.getCacheDepotConf(param.getCompanyId(), param.getDepotId());
|
//
|
// //获取粮情分机的主控信息
|
// DeviceSer ser = coreSerService.getCacheSer(param.getCompanyId(), depotConf.getGrainSer());
|
//
|
// if (null == ser || Constant.YN_N.equals(ser.getStatus())) {
|
// return "当前仓库控制分机不存在或者已经掉线,系统无法执行,请联系管理员!";
|
// }
|
//
|
// DeviceAutoControlRequest request = new DeviceAutoControlRequest();
|
// request.setDepotId(param.getDepotId());
|
// request.setCompanyId(param.getCompanyId());
|
// request.setBizType(BizType.AREATION.getCode());
|
// request.setModeTag(autoData.getModeTag());
|
// request.setSerId(ser.getId());
|
// request.setSerName(ser.getName());
|
// request.setModeClose(modeClose);
|
// request.setIp(ser.getIp());
|
// request.setPort(ser.getPort());
|
// request.setDepotName(depotConf.getDepotName());
|
//
|
// RemoteControlService remoteControlService = remoteManager.getRemoteControlService(ser.getProtocol());
|
//
|
// if (null == remoteControlService) {
|
// return "当前仓库控制分机协议没有实现,系统无法执行,请联系管理员!";
|
// }
|
//
|
// DeviceControlResponse response = remoteControlService.n2AutoControl(request);
|
//
|
// if (OrderRespEnum.ORDER_SUCCESS.getCode().equals(response.getCode())) {
|
// return null;
|
// }
|
//
|
// return "后台发送命令执行失败,原因:" + response.getMsg();
|
// }
|
//
|
// /**
|
// * 执行关闭智能任务
|
// *
|
// * @param autoData
|
// * @param param
|
// * @return 执行异常信息,正常返回 null
|
// */
|
// private String exeStopIntel(N2AutoData autoData, N2Param param) {
|
//
|
// // TODO 执行智能任务关闭操作
|
//
|
//
|
// return null;
|
// }
|
//
|
//
|
// /**
|
// * 核对气调任务,有返回true 没有返回false
|
// *
|
// * @param companyId
|
// * @param depotId
|
// * @return
|
// */
|
// public boolean n2TaskCheck(String companyId, String depotId) {
|
// // TODO 暂时不做处理
|
// N2TaskParam param = new N2TaskParam();
|
// param.setCompanyId(companyId);
|
// param.setDepotId(depotId);
|
// param.setNotStatus(N2Util.TASK_STATUS_03);
|
//
|
// List<N2IntelTask> list = null;//
|
//
|
// if (null == list || list.isEmpty()) return false;
|
//
|
// return true;
|
// }
|
//
|
//
|
// /**
|
// * 核对通风任务,有返回true 没有返回false
|
// *
|
// * @param companyId
|
// * @param depotId
|
// * @return
|
// */
|
// public boolean airTaskCheck(String companyId, String depotId) {
|
// // TODO 验证是否有通风任务正在执行,暂时不核对
|
//
|
// log.warn("------------验证是否有通风任务正在执行,暂时不核对");
|
//
|
// return false;
|
// }
|
//
|
// /**
|
// * 核对通风设备状态,有开启返回 true,没有返回false
|
// *
|
// * @param companyId
|
// * @param depotId
|
// * @return
|
// */
|
// private boolean airDeviceStatus(String companyId, String depotId) {
|
// // TODO 验证设备通风状态,暂时不核对
|
//
|
// return false;
|
// }
|
//
|
// /**
|
// * 新增智能任务,主任务,主任务创建需要自动创建至少一个子任务
|
// *
|
// * @param autoData
|
// */
|
// private void addN2TaskByAuto(N2AutoData autoData) {
|
// N2IntelTask task = new N2IntelTask();
|
// String parentId = ContextUtil.getUUID();
|
// task.setId(parentId);
|
// task.setCompanyId(autoData.getCompanyId());
|
// task.setDepotId(autoData.getDepotId());
|
// task.setDeptId(autoData.getDeptId());
|
// task.setAutoName(autoData.getName());
|
// task.setExeNum(1);
|
// task.setStatus(N2Util.TASK_STATUS_01);
|
// task.setStart(new Date());
|
// task.setExeMode(autoData.getExeMode());
|
// task.setModeTag(autoData.getModeTag());
|
//
|
// //主任务
|
// hn2Service.saveIntelTask(task);
|
//
|
// //气密性检测-子任务
|
// if (N2ModelTag.MODEL_30.getCode().equals(autoData.getModeTag())) {
|
// // -添加气压检测任务
|
// task.setParentId(parentId);
|
// task.setId(ContextUtil.getUUID());
|
// task.setModeTag(N2ModelTag.MODEL_42.getCode());
|
// task.setAutoName(N2ModelTag.MODEL_42.getMsg());
|
// hn2Service.saveIntelTask(task);
|
//
|
// //-添加第一个动作抽负压
|
// task.setParentId(parentId);
|
// task.setId(ContextUtil.getUUID());
|
// task.setModeTag(N2ModelTag.MODEL_01.getCode());
|
// task.setAutoName(N2ModelTag.MODEL_01.getMsg());
|
// hn2Service.saveIntelTask(task);
|
// }
|
//
|
//
|
// //智能气调-子任务
|
// if (N2ModelTag.MODEL_31.getCode().equals(autoData.getModeTag())) {
|
//
|
// // -添加气压检测任务
|
// task.setParentId(parentId);
|
// task.setId(ContextUtil.getUUID());
|
// task.setModeTag(N2ModelTag.MODEL_42.getCode());
|
// task.setAutoName(N2ModelTag.MODEL_42.getMsg());
|
// hn2Service.saveIntelTask(task);
|
//
|
// // -添加一个气体检测任务
|
// task.setParentId(parentId);
|
// task.setId(ContextUtil.getUUID());
|
// task.setModeTag(N2ModelTag.MODEL_41.getCode());
|
// task.setAutoName(N2ModelTag.MODEL_41.getMsg());
|
// hn2Service.saveIntelTask(task);
|
//
|
// //-添加第一个动作充氮
|
// task.setParentId(parentId);
|
// task.setId(ContextUtil.getUUID());
|
// task.setModeTag(N2ModelTag.MODEL_03.getCode());
|
// task.setAutoName(N2ModelTag.MODEL_03.getMsg());
|
//
|
// hn2Service.saveIntelTask(task);
|
// }
|
//
|
// }
|
|
|
}
|