|
|
|
@ -1,6 +1,10 @@
|
|
|
|
package cn.iocoder.yudao.module.iot.service.recipeplandetail;
|
|
|
|
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 com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
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 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.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
|
|
|
|
|
|
@ -28,6 +35,13 @@ public class RecipePlanDetailServiceImpl implements RecipePlanDetailService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private RecipePlanDetailMapper recipePlanDetailMapper;
|
|
|
|
private RecipePlanDetailMapper recipePlanDetailMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
|
|
private RecipeMapper recipeMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private TDengineService tDengineService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Long createRecipePlanDetail(RecipePlanDetailSaveReqVO createReqVO) {
|
|
|
|
public Long createRecipePlanDetail(RecipePlanDetailSaveReqVO createReqVO) {
|
|
|
|
// 校验编码是否存在
|
|
|
|
// 校验编码是否存在
|
|
|
|
@ -84,4 +98,36 @@ public class RecipePlanDetailServiceImpl implements RecipePlanDetailService {
|
|
|
|
return recipePlanDetailMapper.selectPageWithRelationsWrap(reqVO);
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|