设备dnc接口调整

master
zpl 3 years ago
parent 657ba6c4f4
commit c5e66620fb

@ -37,7 +37,7 @@ public class ResourceMQConsume {
public void resourceStatusProcess(String text, MessageHeaders headers) { public void resourceStatusProcess(String text, MessageHeaders headers) {
logger.info("接收设备状态变更数据:" + text); logger.info("接收设备状态变更数据:" + text);
String resultString = resourceMQProcess.resourceStatusProcess(text); resourceMQProcess.resourceStatusProcess(text);
//返回设备处理结果 //返回设备处理结果
// template.convertAndSend((Queue) headers.get("jms_replyTo"), resultString); // template.convertAndSend((Queue) headers.get("jms_replyTo"), resultString);
} }
@ -45,7 +45,7 @@ public class ResourceMQConsume {
@JmsListener(destination = "resource.alarm.process", containerFactory = "defaultFactory") @JmsListener(destination = "resource.alarm.process", containerFactory = "defaultFactory")
public void resourceAlarmProcess(String text, MessageHeaders headers) { public void resourceAlarmProcess(String text, MessageHeaders headers) {
logger.info("接收设备报警数据:" + text); logger.info("接收设备报警数据:" + text);
String resultString = resourceMQProcess.resourceFaultProcess(text); resourceMQProcess.resourceFaultProcess(text);
// template.convertAndSend((Queue) headers.get("jms_replyTo"), resultString); // template.convertAndSend((Queue) headers.get("jms_replyTo"), resultString);
} }

@ -1,10 +1,11 @@
package com.foreverwin.mesnac.equip.consumer; package com.foreverwin.mesnac.equip.consumer;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.mesnac.equip.dto.MQResponseDto;
import com.foreverwin.mesnac.equip.service.EdcDataResourceService; import com.foreverwin.mesnac.equip.service.EdcDataResourceService;
import com.foreverwin.mesnac.equip.service.ResourceFaultReceiveService; import com.foreverwin.mesnac.equip.service.ResourceFaultReceiveService;
import com.foreverwin.mesnac.equip.service.ResourceStatusReceiveService; import com.foreverwin.mesnac.equip.service.ResourceStatusReceiveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -19,6 +20,8 @@ import org.springframework.stereotype.Component;
@Component @Component
public class ResourceMQProcess { public class ResourceMQProcess {
private static Logger logger = LoggerFactory.getLogger(ResourceMQProcess.class);
@Autowired @Autowired
private ResourceStatusReceiveService resourceStatusReceiveService; private ResourceStatusReceiveService resourceStatusReceiveService;
@ -34,18 +37,13 @@ public class ResourceMQProcess {
* @param text * @param text
* @return * @return
*/ */
public String resourceStatusProcess(String text) { public void resourceStatusProcess(String text) {
MQResponseDto mqResponseDto = new MQResponseDto();
try { try {
String handle = resourceStatusReceiveService.updateResourceStatusByMq(text); resourceStatusReceiveService.updateResourceStatusByMq(text);
mqResponseDto.setHANDLE(handle); logger.info("设备状态修改成功!");
mqResponseDto.setSTATUS("Success");
mqResponseDto.setMESSAGE("设备状态修改成功!");
} catch (Exception e) { } catch (Exception e) {
mqResponseDto.setSTATUS("Error"); logger.error("设备状态修改失败:" + e.getMessage());
mqResponseDto.setMESSAGE("设备状态修改失败:" + e.getMessage());
} }
return JSONObject.toJSONString(mqResponseDto);
} }
/** /**
@ -53,36 +51,26 @@ public class ResourceMQProcess {
* @param text * @param text
* @return * @return
*/ */
public String resourceFaultProcess(String text){ public void resourceFaultProcess(String text){
MQResponseDto mqResponseDto = new MQResponseDto();
try { try {
String handle = resourceFaultReceiveService.parseResourceFaultInfo(text); resourceFaultReceiveService.parseResourceFaultInfo(text);
mqResponseDto.setHANDLE(handle); logger.info("设备故障信息记录成功!");
mqResponseDto.setSTATUS("Success");
mqResponseDto.setMESSAGE("设备状态修改成功!");
} catch (Exception e) { } catch (Exception e) {
mqResponseDto.setSTATUS("Error"); logger.error("设备故障信息记录失败:" + e.getMessage());
mqResponseDto.setMESSAGE("设备状态修改失败:" + e.getMessage());
} }
return JSONObject.toJSONString(mqResponseDto);
} }
/** /**
* *
* @param text * @param text
* @return * @return
*/ */
public String resourceParamProcess(String text){ public void resourceParamProcess(String text){
MQResponseDto mqResponseDto = new MQResponseDto();
try { try {
String handle = edcDataResourceService.saveResourceParamByMq(text); edcDataResourceService.saveResourceParamByMq(text);
mqResponseDto.setHANDLE(handle); logger.info("设备参数信息记录成功");
mqResponseDto.setSTATUS("Success");
mqResponseDto.setMESSAGE("设备状态修改成功!");
} catch (Exception e) { } catch (Exception e) {
mqResponseDto.setSTATUS("Error"); logger.error("设备参数信息记录失败:"+e.getMessage());
mqResponseDto.setMESSAGE("设备状态修改失败:" + e.getMessage());
} }
return JSONObject.toJSONString(mqResponseDto);
} }
} }

@ -31,6 +31,6 @@ public interface EdcDataResourceService extends IService<EdcDataResource> {
* @param text * @param text
* @return * @return
*/ */
String saveResourceParamByMq(String text); void saveResourceParamByMq(String text);
} }

@ -26,7 +26,7 @@ public interface ResourceFaultReceiveService extends IService<ResourceFaultRecei
List<ResourceFaultReceive> selectList(ResourceFaultReceive resourceFaultReceive); List<ResourceFaultReceive> selectList(ResourceFaultReceive resourceFaultReceive);
String parseResourceFaultInfo(String text); void parseResourceFaultInfo(String text);
} }

@ -27,10 +27,10 @@ public interface ResourceStatusReceiveService extends IService<ResourceStatusRec
List<ResourceStatusReceive> selectList(ResourceStatusReceive resourceStatusReceive); List<ResourceStatusReceive> selectList(ResourceStatusReceive resourceStatusReceive);
/** /**
* *
* @param text * @param text
*/ */
String updateResourceStatusByMq(String text); void updateResourceStatusByMq(String text);
} }

@ -17,8 +17,6 @@ import com.foreverwin.mesnac.equip.model.EdcDataResource;
import com.foreverwin.mesnac.equip.mapper.EdcDataResourceMapper; import com.foreverwin.mesnac.equip.mapper.EdcDataResourceMapper;
import com.foreverwin.mesnac.equip.service.EdcDataResourceService; import com.foreverwin.mesnac.equip.service.EdcDataResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -41,8 +39,6 @@ import java.util.UUID;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class EdcDataResourceServiceImpl extends ServiceImpl<EdcDataResourceMapper, EdcDataResource> implements EdcDataResourceService { public class EdcDataResourceServiceImpl extends ServiceImpl<EdcDataResourceMapper, EdcDataResource> implements EdcDataResourceService {
private static Logger logger = LoggerFactory.getLogger(EdcDataResourceServiceImpl.class);
@Autowired @Autowired
private EdcDataResourceMapper edcDataResourceMapper; private EdcDataResourceMapper edcDataResourceMapper;
@Autowired @Autowired
@ -65,7 +61,7 @@ public class EdcDataResourceServiceImpl extends ServiceImpl<EdcDataResourceMappe
} }
@Override @Override
public String saveResourceParamByMq(String text) { public void saveResourceParamByMq(String text) {
// json解析获取json中数据 // json解析获取json中数据
JSONObject jsonObject = JSONObject.parseObject(text); JSONObject jsonObject = JSONObject.parseObject(text);
String handle = jsonObject.getString("TRANID"); String handle = jsonObject.getString("TRANID");
@ -73,21 +69,17 @@ public class EdcDataResourceServiceImpl extends ServiceImpl<EdcDataResourceMappe
String resource = jsonObject.getString("RESOURCE"); String resource = jsonObject.getString("RESOURCE");
String sendTime = jsonObject.getString("SEND_TIME"); String sendTime = jsonObject.getString("SEND_TIME");
if (StringUtil.isBlank(handle)) { if (StringUtil.isBlank(handle)) {
logger.error("唯一标识不能为空!");
throw BusinessException.build("唯一标识不能为空!"); throw BusinessException.build("唯一标识不能为空!");
} }
if (StringUtil.isBlank(site)) { if (StringUtil.isBlank(site)) {
logger.error("站点不能为空!");
throw BusinessException.build("站点不能为空!"); throw BusinessException.build("站点不能为空!");
} }
if (StringUtil.isBlank(resource)) { if (StringUtil.isBlank(resource)) {
logger.error("设备编号不能为空!");
throw BusinessException.build("设备编号不能为空!"); throw BusinessException.build("设备编号不能为空!");
} }
String resourceHandle = HandleEnum.RESOURCE.getHandle(site, resource); String resourceHandle = HandleEnum.RESOURCE.getHandle(site, resource);
Resrce resourceById = resrceService.getById(resourceHandle); Resrce resourceById = resrceService.getById(resourceHandle);
if (resourceById == null){ if (resourceById == null){
logger.error("未找到设备编号为" + resource + "的设备!");
throw BusinessException.build("未找到设备编号为" + resource + "的设备!"); throw BusinessException.build("未找到设备编号为" + resource + "的设备!");
} }
@ -107,7 +99,6 @@ public class EdcDataResourceServiceImpl extends ServiceImpl<EdcDataResourceMappe
if (dcGroupBo == null){ if (dcGroupBo == null){
dcGroupBo = edcDataResourceMapper.getDcGroupBoByResourceBo2(resourceBo); dcGroupBo = edcDataResourceMapper.getDcGroupBoByResourceBo2(resourceBo);
if (dcGroupBo == null){ if (dcGroupBo == null){
logger.info("设备编号" + resource + "未找到数据收集组");
throw BusinessException.build("设备编号未找到数据收集组!"); throw BusinessException.build("设备编号未找到数据收集组!");
} }
} }
@ -116,7 +107,6 @@ public class EdcDataResourceServiceImpl extends ServiceImpl<EdcDataResourceMappe
StringBuilder columnSql = new StringBuilder(); StringBuilder columnSql = new StringBuilder();
List<DcParameter> getParamList = dcParameterMapper.getDcParameterByDcGroupBo(dcGroupBo); List<DcParameter> getParamList = dcParameterMapper.getDcParameterByDcGroupBo(dcGroupBo);
if (getParamList.size() < 1){ if (getParamList.size() < 1){
logger.info("数据收集组" + dcGroupBo + "未维护字段信息");
throw BusinessException.build("数据收集组" + dcGroupBo + "未维护字段信息"); throw BusinessException.build("数据收集组" + dcGroupBo + "未维护字段信息");
} }
for (DcParameter dcParam:getParamList) { for (DcParameter dcParam:getParamList) {
@ -156,7 +146,6 @@ public class EdcDataResourceServiceImpl extends ServiceImpl<EdcDataResourceMappe
.append(columnValSql.substring(0,columnValSql.length()-1)) .append(columnValSql.substring(0,columnValSql.length()-1))
.append(" )"); .append(" )");
edcDataResourceMapper.insertBySql(sqlStr.toString()); edcDataResourceMapper.insertBySql(sqlStr.toString());
return handle;
} }
} }

@ -16,8 +16,6 @@ import com.foreverwin.mesnac.equip.model.ResourceFaultReceive;
import com.foreverwin.mesnac.equip.mapper.ResourceFaultReceiveMapper; import com.foreverwin.mesnac.equip.mapper.ResourceFaultReceiveMapper;
import com.foreverwin.mesnac.equip.service.ResourceFaultReceiveService; import com.foreverwin.mesnac.equip.service.ResourceFaultReceiveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -40,7 +38,6 @@ import java.util.UUID;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class ResourceFaultReceiveServiceImpl extends ServiceImpl<ResourceFaultReceiveMapper, ResourceFaultReceive> implements ResourceFaultReceiveService { public class ResourceFaultReceiveServiceImpl extends ServiceImpl<ResourceFaultReceiveMapper, ResourceFaultReceive> implements ResourceFaultReceiveService {
private static Logger logger = LoggerFactory.getLogger(ResourceFaultReceiveServiceImpl.class);
@Autowired @Autowired
private ResourceFaultReceiveService resourceFaultReceiveService; private ResourceFaultReceiveService resourceFaultReceiveService;
@ -62,7 +59,7 @@ public class ResourceFaultReceiveServiceImpl extends ServiceImpl<ResourceFaultRe
} }
@Override @Override
public String parseResourceFaultInfo(String text) { public void parseResourceFaultInfo(String text) {
String user = CommonMethods.getUser(); String user = CommonMethods.getUser();
JSONObject jsonObject = JSONObject.parseObject(text); JSONObject jsonObject = JSONObject.parseObject(text);
@ -76,25 +73,20 @@ public class ResourceFaultReceiveServiceImpl extends ServiceImpl<ResourceFaultRe
LocalDateTime sendDate = LocalDateTime.parse(sendTime, dataFormatter); LocalDateTime sendDate = LocalDateTime.parse(sendTime, dataFormatter);
if (StringUtil.isBlank(handle)) { if (StringUtil.isBlank(handle)) {
logger.error("唯一标识不能为空!");
throw BusinessException.build("唯一标识不能为空!"); throw BusinessException.build("唯一标识不能为空!");
} }
if (StringUtil.isBlank(site)) { if (StringUtil.isBlank(site)) {
logger.error("站点不能为空!");
throw BusinessException.build("站点不能为空!"); throw BusinessException.build("站点不能为空!");
} }
if (StringUtil.isBlank(faultList)) { if (StringUtil.isBlank(faultList)) {
logger.error("故障参数列表不能为空!");
throw BusinessException.build("故障参数列表不能为空!"); throw BusinessException.build("故障参数列表不能为空!");
} }
if (StringUtil.isBlank(resource)) { if (StringUtil.isBlank(resource)) {
logger.error("设备编号不能为空!");
throw BusinessException.build("设备编号不能为空!"); throw BusinessException.build("设备编号不能为空!");
} }
String resourceHandle = HandleEnum.RESOURCE.getHandle(site, resource); String resourceHandle = HandleEnum.RESOURCE.getHandle(site, resource);
Resrce resourceById = resrceService.getById(resourceHandle); Resrce resourceById = resrceService.getById(resourceHandle);
if (resourceById == null){ if (resourceById == null){
logger.error("未找到设备编号为" + resource + "的设备!");
throw BusinessException.build("未找到设备编号为" + resource + "的设备!"); throw BusinessException.build("未找到设备编号为" + resource + "的设备!");
} }
@ -102,7 +94,6 @@ public class ResourceFaultReceiveServiceImpl extends ServiceImpl<ResourceFaultRe
// 故障编码及故障时间 // 故障编码及故障时间
JSONArray jsonArray = JSON.parseArray(faultList); JSONArray jsonArray = JSON.parseArray(faultList);
if (jsonArray == null || jsonArray.size() < 1){ if (jsonArray == null || jsonArray.size() < 1){
logger.error("设备编号:" + resource + ",故障参数列表不能为空!");
throw BusinessException.build("设备编号:" + resource + ",故障参数列表不能为空!"); throw BusinessException.build("设备编号:" + resource + ",故障参数列表不能为空!");
} }
for (int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
@ -125,7 +116,6 @@ public class ResourceFaultReceiveServiceImpl extends ServiceImpl<ResourceFaultRe
list.add(resourceFaultReceive); list.add(resourceFaultReceive);
} }
resourceFaultReceiveService.saveBatch(list); resourceFaultReceiveService.saveBatch(list);
return handle;
} }

@ -20,7 +20,6 @@ import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
@ -65,7 +64,7 @@ public class ResourceStatusReceiveServiceImpl extends ServiceImpl<ResourceStatus
* @return * @return
*/ */
@Override @Override
public String updateResourceStatusByMq(String text) { public void updateResourceStatusByMq(String text) {
String user = CommonMethods.getUser(); String user = CommonMethods.getUser();
JSONObject jsonObject = JSONObject.parseObject(text); JSONObject jsonObject = JSONObject.parseObject(text);
// 传输数据的唯一标识HANDLE站点、设备编号、状态 // 传输数据的唯一标识HANDLE站点、设备编号、状态
@ -79,47 +78,45 @@ public class ResourceStatusReceiveServiceImpl extends ServiceImpl<ResourceStatus
LocalDateTime dateTime = LocalDateTime.parse(sendTime,dataFormatter); LocalDateTime dateTime = LocalDateTime.parse(sendTime,dataFormatter);
if (StringUtil.isBlank(handle)) { if (StringUtil.isBlank(handle)) {
logger.error("唯一标识不能为空!");
throw BusinessException.build("唯一标识不能为空!"); throw BusinessException.build("唯一标识不能为空!");
} }
if (StringUtil.isBlank(site)) { if (StringUtil.isBlank(site)) {
logger.error("站点不能为空!");
throw BusinessException.build("站点不能为空!"); throw BusinessException.build("站点不能为空!");
} }
if (StringUtil.isBlank(resource)) { if (StringUtil.isBlank(resource)) {
logger.error("设备编号不能为空!");
throw BusinessException.build("设备编号不能为空!"); throw BusinessException.build("设备编号不能为空!");
} }
String resourceHandle = HandleEnum.RESOURCE.getHandle(site, resource); String resourceHandle = HandleEnum.RESOURCE.getHandle(site, resource);
Resrce resourceById = resrceService.getById(resourceHandle); Resrce resourceById = resrceService.getById(resourceHandle);
if (resourceById == null){ if (resourceById == null){
logger.error("未找到设备编号为" + resource + "的设备!");
throw BusinessException.build("未找到设备编号为" + resource + "的设备!"); throw BusinessException.build("未找到设备编号为" + resource + "的设备!");
} }
if (StringUtil.isBlank(sendStatus)) { if (StringUtil.isBlank(sendStatus)) {
logger.error("设备状态不能为空!");
throw BusinessException.build("设备状态不能为空!"); throw BusinessException.build("设备状态不能为空!");
} }
// 获取最新数据 // 获取最新数据
ResourceStatusReceive resourceStatus = resourceStatusReceiveMapper.getOneByMaxCreateDateTime(site,resource); ResourceStatusReceive resourceStatus = resourceStatusReceiveMapper.getOneByMaxCreateDateTime(site,resource);
if (resourceStatus != null){ if (resourceStatus != null){
resourceStatus.setCreateUser(user);
resourceStatus.setCreatedDateTime(resourceStatus.getModifiedDateTime());
resourceStatus.setModifiedDateTime(dateTime); resourceStatus.setModifiedDateTime(dateTime);
resourceStatus.setModifyUser(user); resourceStatus.setModifyUser(user);
resourceStatusReceiveMapper.updateById(resourceStatus); resourceStatusReceiveMapper.updateById(resourceStatus);
}else{ }else{
// 数据库录入新数据
ResourceStatusReceive resourceStatusReceive = new ResourceStatusReceive();
resourceStatusReceive.setHandle(UUID.randomUUID().toString());
resourceStatusReceive.setSite(site);
resourceStatusReceive.setResrce(resource);
resourceStatusReceive.setStatus(sendStatus);
resourceStatusReceive.setCreateUser(user);
resourceStatusReceive.setCreatedDateTime(dateTime);
resourceStatusReceive.setModifyUser(user);
resourceStatusReceive.setModifiedDateTime(dateTime);
resourceStatusReceiveMapper.insert(resourceStatusReceive);
logger.info("设备编号:" + resource + ",记录第一笔数据!"); logger.info("设备编号:" + resource + ",记录第一笔数据!");
} }
// 数据库录入新数据
ResourceStatusReceive resourceStatusReceive = new ResourceStatusReceive();
resourceStatusReceive.setHandle(UUID.randomUUID().toString());
resourceStatusReceive.setSite(site);
resourceStatusReceive.setResrce(resource);
resourceStatusReceive.setStatus(sendStatus);
resourceStatusReceive.setCreateUser(user);
resourceStatusReceive.setCreatedDateTime(dateTime);
resourceStatusReceiveMapper.insert(resourceStatusReceive);
return handle;
} }
} }
Loading…
Cancel
Save