fix:修复已知bug

liutao_branch
HuangHuiKang 5 days ago
parent 3f3c0eb2b8
commit a64d96fb78

@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.time.LocalDateTime;
import java.util.*;
import java.io.IOException;
import java.util.function.Function;
@ -221,6 +222,7 @@ public class RecipeDeviceRecordController {
// recipeDeviceRecordDO.setValue(data.get("addressValue").toString());
// }
recipeDeviceRecordDO.setValue(map.get(deviceContactModelDO.getAttributeCode()));
recipeDeviceRecordDO.setCollectionTime((LocalDateTime) map.get("ts"));
recipeDeviceRecordService.createRecipeDeviceRecord(BeanUtils.toBean(recipeDeviceRecordDO, RecipeDeviceRecordSaveReqVO.class));

@ -63,4 +63,6 @@ public class RecipeDeviceRecordRespVO {
@Schema(description = "配方id", example = "32535")
private Long recipeId;
@Schema(description = "采集时间", example = "32535")
private LocalDateTime collectionTime;
}

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.iot.controller.admin.recipedevicerecord.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
import java.util.*;
import javax.validation.constraints.*;
@ -45,4 +47,7 @@ public class RecipeDeviceRecordSaveReqVO {
@Schema(description = "配方id", example = "32535")
private Long recipeId;
@Schema(description = "采集时间", example = "32535")
private LocalDateTime collectionTime;
}

@ -72,6 +72,16 @@ public class RecipePlanDetailController {
return success(BeanUtils.toBean(recipePlanDetail, RecipePlanDetailRespVO.class));
}
@GetMapping("/getCollectLatestTime")
@Operation(summary = "获得数据采集最新时间")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('iot:recipe-plan-detail:query')")
public CommonResult<CollectTimeResult> getCollectLatestTime(@RequestParam("id") Long id) {
CollectTimeResult collectTimeResult = recipePlanDetailService.getCollectLatestTime(id);
return success(collectTimeResult);
}
// @GetMapping("/page")
// @Operation(summary = "获得配方计划详情表(配方库)分页")
// @PreAuthorize("@ss.hasPermission('iot:recipe-plan-detail:query')")

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.iot.controller.admin.recipeplandetail.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
public class CollectTimeResult {
@Schema(description = "采集时间")
private LocalDateTime collectTime;
@Schema(description = "是否时间异常")
private Boolean timeAbnormal;
}

@ -49,6 +49,9 @@ public class RecipePointRecordRespVO {
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间")
private LocalDateTime updateTime;
@Schema(description = "参考值")
@ExcelProperty("参考值")
private BigDecimal refer;

@ -73,4 +73,9 @@ public class RecipeDeviceRecordDO extends BaseDO {
*/
private Long recipeId;
/**
*
*/
private LocalDateTime collectionTime;
}

@ -58,26 +58,32 @@ public class MqttserviceImpl implements IMqttservice, ApplicationListener<Applic
*/
@Override
public void subscribeMysqlTopic() {
if (client.isConnected()) {
List<GatewayDO> gatewayList = gatewayService.selectListByIsEnable(IsEnableConstant.IsEnableTrue);
for (GatewayDO gateway : gatewayList) {
if (StringUtils.isNotBlank(gateway.getTopic())) {
SubscriptTopic topic = new SubscriptTopic(gateway.getTopic(),
gateway.getTopic(), Pattern.QUEUE, 0, dataHandler);
defaultBizTopicSet.getTopicMap().add(topic);
try {
client.subscribe(topic.getSubTopic(), 0, dataHandler);
} catch (MqttException e) {
e.printStackTrace();
}
if (!client.isConnected()) {
try {
log.warn("MQTT未连接尝试重新连接...");
client.reconnect();
} catch (Exception e) {
log.error("MQTT重连失败", e);
return;
}
}
List<GatewayDO> gatewayList = gatewayService.selectListByIsEnable(IsEnableConstant.IsEnableTrue);
for (GatewayDO gateway : gatewayList) {
if (StringUtils.isNotBlank(gateway.getTopic())) {
SubscriptTopic topic = new SubscriptTopic(gateway.getTopic(),
gateway.getTopic(), Pattern.QUEUE, 0, dataHandler);
defaultBizTopicSet.getTopicMap().add(topic);
try {
client.subscribe(topic.getSubTopic(), 0, dataHandler);
} catch (MqttException e) {
e.printStackTrace();
}
}
client.setCallback(new MqttCallbackImpl(defaultBizTopicSet.getTopicMap(), client, options));
log.info("共订阅: " + defaultBizTopicSet.getTopicMap().size() + " 个主题!");
} else {
log.error("Mqtt is not connected !");
}
client.setCallback(new MqttCallbackImpl(defaultBizTopicSet.getTopicMap(), client, options));
log.info("共订阅: " + defaultBizTopicSet.getTopicMap().size() + " 个主题!");
}
@ -86,6 +92,13 @@ public class MqttserviceImpl implements IMqttservice, ApplicationListener<Applic
*/
@Override
public int subscribeTopic(String topic) throws MqttException {
//断线重连
if (!client.isConnected()) {
log.warn("MQTT未连接尝试重新连接...");
client.reconnect();
}
SubscriptTopic subscriptTopic = new SubscriptTopic(topic, topic, Pattern.QUEUE, 0, dataHandler);
defaultBizTopicSet.getTopicMap().add(subscriptTopic);
client.subscribe(topic, 0, dataHandler);

@ -1024,7 +1024,7 @@ public class TDengineService {
Map<String, Object> row = list.get(0);
// 转换 ts 为 LocalDateTime(推荐)
// 转换 ts 为 LocalDateTime
Object tsObj = row.get("ts");
if (tsObj instanceof Timestamp) {
row.put("ts", ((Timestamp) tsObj).toLocalDateTime());

@ -52,4 +52,5 @@ public interface RecipePlanDetailService {
PageResult<RecipePlanDetailPageRespDTO> pageRecipePlanDetail(RecipePlanDetailPageReqVO reqVO);
CollectTimeResult getCollectLatestTime(Long id);
}

@ -1,6 +1,10 @@
package cn.iocoder.yudao.module.iot.service.recipeplandetail;
import cn.iocoder.yudao.module.iot.dal.dataobject.recipe.RecipeDO;
import cn.iocoder.yudao.module.iot.dal.mysql.recipe.RecipeMapper;
import cn.iocoder.yudao.module.iot.service.device.TDengineService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -12,6 +16,9 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.iot.dal.mysql.recipeplandetail.RecipePlanDetailMapper;
import java.time.LocalDateTime;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
@ -28,6 +35,13 @@ public class RecipePlanDetailServiceImpl implements RecipePlanDetailService {
@Resource
private RecipePlanDetailMapper recipePlanDetailMapper;
@Resource
@Lazy
private RecipeMapper recipeMapper;
@Resource
private TDengineService tDengineService;
@Override
public Long createRecipePlanDetail(RecipePlanDetailSaveReqVO createReqVO) {
// 校验编码是否存在
@ -84,4 +98,36 @@ public class RecipePlanDetailServiceImpl implements RecipePlanDetailService {
return recipePlanDetailMapper.selectPageWithRelationsWrap(reqVO);
}
@Override
public CollectTimeResult getCollectLatestTime(Long id) {
// 查询配方计划详情
RecipePlanDetailDO recipePlanDetailDO = recipePlanDetailMapper.selectById(id);
if (recipePlanDetailDO == null) {
throw exception(RECIPE_PLAN_DETAIL_NOT_EXISTS);
}
// 查询配方
RecipeDO recipeDO = recipeMapper.selectById(recipePlanDetailDO.getRecipeId());
if (recipeDO == null) {
throw exception(RECIPE_NOT_EXISTS);
}
// 查询 TDengine 最新采集数据
Map<String, Object> map = tDengineService.newSelectLatestRow(recipeDO.getMachineId());
LocalDateTime collectTime = null;
if (map != null) {
collectTime = (LocalDateTime) map.get("ts");
}
// 当前时间
LocalDateTime now = LocalDateTime.now();
// 判断是否异常
boolean abnormal = collectTime != null && now.isAfter(collectTime.plusMinutes(2));
return new CollectTimeResult(collectTime, abnormal);
}
}
Loading…
Cancel
Save