package com.ld.igds.protocol.fzzy.analysis;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.ld.igds.common.CoreCommonService;
|
import com.ld.igds.common.CoreDeviceService;
|
import com.ld.igds.common.CoreSerService;
|
import com.ld.igds.constant.BizType;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.io.notify.NotifyWebInvoker;
|
import com.ld.igds.io.constant.OrderRespEnum;
|
import com.ld.igds.models.Depot;
|
import com.ld.igds.models.DepotConf;
|
import com.ld.igds.models.Device;
|
import com.ld.igds.models.DeviceSer;
|
import com.ld.igds.protocol.fzzy.ServerUtils;
|
import com.ld.igds.protocol.fzzy.command.BaseRemoteImpl;
|
import com.ld.igds.protocol.fzzy.dto.ReMessage;
|
import com.ld.igds.protocol.fzzy.dto.SendMessage;
|
import com.ld.igds.protocol.fzzy.req.Request1004;
|
import com.ld.igds.protocol.fzzy.req.Request1006;
|
import com.ld.igds.protocol.fzzy.req.Request1007;
|
import com.ld.igds.protocol.fzzy.resp.Response1001;
|
import com.ld.igds.protocol.fzzy.resp.Response1003;
|
import com.ld.igds.protocol.fzzy.resp.Response1010;
|
import com.ld.igds.protocol.fzzy.builder.ObjectCommandBuilder;
|
import com.ld.igds.protocol.fzzy.builder.SimpleCommandBuilder;
|
import com.ld.igds.util.ContextUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 系统类协议解析
|
*/
|
@Slf4j
|
@Component(AnalysisSystem.BEAN_ID)
|
public class AnalysisSystem extends BaseRemoteImpl {
|
|
public static final String BEAN_ID = "fzzy.analysisSystem";
|
|
@Autowired
|
private CoreSerService coreSerService;
|
@Autowired
|
private CoreCommonService coreCommonService;
|
@Autowired
|
private CoreDeviceService deviceService;
|
@Autowired
|
private NotifyWebInvoker notifyWebInvoker;
|
|
|
public void analysis1001(ReMessage reMessage) {
|
//返回当前系统时间
|
Response1001 response = new Response1001();
|
response.setTime(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"));
|
ObjectCommandBuilder commandBuilder = ObjectCommandBuilder.getInstance();
|
SendMessage message = commandBuilder.buildMessage(reMessage, ServerUtils.FUNCTION_1001, response);
|
send(message);
|
|
if (null == reMessage.getContent()) return;
|
|
DeviceSer ser = coreSerService.getCacheSer(reMessage.getCompanyId(), reMessage.getIedId());
|
if (null == ser) {
|
log.warn("控制柜----->>>平台:组织编码={},分机ID={},系统没有获取到分机信息,报文无法进行解析", reMessage.getCompanyId(), reMessage.getIedId());
|
return;
|
}
|
|
//更新分机上线信息
|
ser.setIp(reMessage.getIp());
|
ser.setPort(reMessage.getPort());
|
ser.setStatus(Constant.YN_Y);
|
coreSerService.updateByData(ser);
|
|
// Request1001 resp = JSONObject.parseObject(reMessage.getContent(), Request1001.class);
|
|
log.info("控制柜----->>>平台:控制柜上线更新完成-IP={}", reMessage.getIp());
|
}
|
|
public void analysis1003(ReMessage reMessage, DeviceSer ser) {
|
List<Response1003> list = JSONObject.parseArray(reMessage.getContent(), Response1003.class);
|
|
Device device;
|
int index = 0;
|
for (Response1003 response1003 : list) {
|
device = new Device();
|
device.setCompanyId(ser.getCompanyId());
|
device.setDepotId(response1003.getHouseId());
|
device.setSerId(ser.getId());
|
device.setPassCode(Integer.valueOf(response1003.getDeviceId()));
|
if (StringUtils.isNotEmpty(response1003.getFanId())) {
|
device.setLink(response1003.getFanId());
|
}
|
device.setName(response1003.getName());
|
device.setLocation(ServerUtils.analysisLocation(response1003.getPos(),response1003.getName()));
|
|
device.setType(ServerUtils.analysisDeviceType(response1003.getType(), response1003.isFan()));
|
|
index++;
|
|
if (index == list.size()) {
|
deviceService.updateDeviceNoId(device, true);
|
} else {
|
deviceService.updateDeviceNoId(device, false);
|
}
|
}
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, ser.getName() + " 远程获取设备信息并解析完成!");
|
|
log.info("控制柜----->>>平台:控制柜设备列表同步到平台完成-控制柜={}", ser.getName());
|
}
|
|
public void analysis1004(ReMessage reMessage, DeviceSer ser) {
|
Request1004 request = JSONObject.parseObject(reMessage.getContent(), Request1004.class);
|
|
log.info("控制柜----->>>平台:控制柜推送警告信息-控制柜={}", request.toString());
|
|
//平台反馈
|
SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();
|
SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_1004);
|
send(message);
|
}
|
|
public void analysis1005(ReMessage reMessage, DeviceSer ser) {
|
//请求不处理
|
|
//直接返回
|
SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();
|
SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_1005);
|
send(message);
|
}
|
|
public void analysis1006(ReMessage reMessage, DeviceSer ser) {
|
|
//返回
|
Request1006 request = JSONObject.parseObject(reMessage.getContent(), Request1006.class);
|
|
//TODO
|
}
|
|
public void analysis1007(ReMessage reMessage, DeviceSer ser) {
|
//直接返回
|
SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();
|
SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_1007);
|
send(message);
|
|
|
//開始解析
|
List<Request1007> requestList = JSONObject.parseArray(reMessage.getContent(), Request1007.class);
|
//获取到仓库状态变更信息
|
String status;
|
for (Request1007 request : requestList) {
|
status = ServerUtils.analysisDepotStatus(request.getStatus());
|
if (null != status) coreCommonService.updateDepotStatus(ser.getCompanyId(), request.getHouseId(), status);
|
}
|
|
log.info("控制柜----->>>平台:控制柜仓库状态信息同步完成-控制柜={}", ser.getName());
|
|
}
|
|
public void analysis1008(ReMessage message, DeviceSer ser) {
|
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, "仓库状态远程同步成功!");
|
}
|
|
public void analysis1009(ReMessage message, DeviceSer ser) {
|
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, ser.getName() + " 远程授权成功!");
|
}
|
|
public void analysis1010(ReMessage reMessage, DeviceSer ser) {
|
List<Response1010> list = JSONObject.parseArray(reMessage.getContent(), Response1010.class);
|
|
Depot depot;
|
DepotConf depotConf;
|
for (Response1010 resp : list) {
|
depot = new Depot();
|
depot.setId(resp.getHouseId());
|
depot.setName(resp.getName());
|
depot.setDepotType(ServerUtils.analysisDepotType(resp.getHouseType()));
|
depot.setCompanyId(ser.getCompanyId());
|
//默认添加所属分库
|
depot.setDeptId(ContextUtil.subDeptId(null));
|
|
coreCommonService.updateDepot(depot);
|
|
depotConf = new DepotConf();
|
depotConf.setCompanyId(ser.getCompanyId());
|
depotConf.setDepotId(resp.getHouseId());
|
depotConf.setThConf(resp.getTempHumChn());
|
depotConf.setCableRule(resp.getLay() + "-" + resp.getRow() + "-" + resp.getCol());
|
|
depotConf.setCableStart(resp.getStartCol());
|
depotConf.setCableEnd(resp.getEndCol());
|
|
depotConf.setGasStart(resp.getStartNo());
|
depotConf.setGasEnd(resp.getEndNo());
|
|
depotConf.setPestStart(resp.getStartNo());
|
depotConf.setPestEnd(resp.getEndNo());
|
depotConf.setGrainSer(ser.getId());
|
|
if (StringUtils.isNotEmpty(resp.getLayout())) {
|
depotConf.setCableRule(resp.getLayout());
|
}
|
depotConf.setCableCir(resp.getLayerPerCircle());
|
|
coreCommonService.updateDepotConf(depotConf);
|
|
}
|
notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, ser.getName() + " 远程获取仓库信息并解析完成!");
|
|
log.info("控制柜----->>>平台:控制柜仓库配置信息同步完成-控制柜={}", ser.getName());
|
}
|
}
|