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