|
|
|
@ -1,5 +1,16 @@
|
|
|
|
package cn.iocoder.yudao.module.iot.controller.admin.recipedevicerecord;
|
|
|
|
package cn.iocoder.yudao.module.iot.controller.admin.recipedevicerecord;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.controller.admin.recipe.vo.RecipePageReqVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.controller.admin.recipe.vo.RecipeRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.controller.admin.recipepointrecord.vo.RecipePointRecordSaveReqVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.recipe.RecipeDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.recipeplandetail.RecipePlanDetailDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.recipepointrecord.RecipePointRecordDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.devicecontactmodel.DeviceContactModelDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.service.device.DeviceService;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipe.RecipeService;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipeplandetail.RecipePlanDetailService;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
@ -30,43 +41,23 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.recipedevicerecord.RecipeDevic
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipedevicerecord.RecipeDeviceRecordService;
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipedevicerecord.RecipeDeviceRecordService;
|
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.validation.constraints.*;
|
|
|
|
import javax.validation.constraints.*;
|
|
|
|
import javax.validation.*;
|
|
|
|
import javax.validation.*;
|
|
|
|
import javax.servlet.http.*;
|
|
|
|
import javax.servlet.http.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.controller.admin.recipedevicerecord.vo.*;
|
|
|
|
import cn.iocoder.yudao.module.iot.controller.admin.recipedevicerecord.vo.*;
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.recipedevicerecord.RecipeDeviceRecordDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipedevicerecord.RecipeDeviceRecordService;
|
|
|
|
|
|
|
|
// 新增必要的导入
|
|
|
|
// 新增必要的导入
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipedeviceattribute.RecipeDeviceAttributeService;
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipedeviceattribute.RecipeDeviceAttributeService;
|
|
|
|
import cn.iocoder.yudao.module.iot.service.device.TDengineService;
|
|
|
|
import cn.iocoder.yudao.module.iot.service.device.TDengineService;
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.recipedeviceattribute.RecipeDeviceAttributeDO;
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.recipedeviceattribute.RecipeDeviceAttributeDO;
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.recipepoint.RecipePointDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipepoint.RecipePointService;
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipepoint.RecipePointService;
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.recipepointrecord.RecipePointRecordDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipepointrecord.RecipePointRecordService;
|
|
|
|
import cn.iocoder.yudao.module.iot.service.recipepointrecord.RecipePointRecordService;
|
|
|
|
|
|
|
|
|
|
|
|
@Tag(name = "管理后台 - 设备点位采集值记录")
|
|
|
|
@Tag(name = "管理后台 - 设备点位采集值记录")
|
|
|
|
@ -80,6 +71,13 @@ public class RecipeDeviceRecordController {
|
|
|
|
// 新增注入的服务
|
|
|
|
// 新增注入的服务
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private RecipeDeviceAttributeService recipeDeviceAttributeService;
|
|
|
|
private RecipeDeviceAttributeService recipeDeviceAttributeService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private RecipePlanDetailService recipePlanDetailService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private RecipeService recipeService;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private TDengineService tDengineService;
|
|
|
|
private TDengineService tDengineService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
@ -89,6 +87,11 @@ public class RecipeDeviceRecordController {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private DeviceService deviceService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/create")
|
|
|
|
@PostMapping("/create")
|
|
|
|
@Operation(summary = "创建设备点位采集值记录")
|
|
|
|
@Operation(summary = "创建设备点位采集值记录")
|
|
|
|
@PreAuthorize("@ss.hasPermission('iot:recipe-device-record:create')")
|
|
|
|
@PreAuthorize("@ss.hasPermission('iot:recipe-device-record:create')")
|
|
|
|
@ -145,117 +148,53 @@ public class RecipeDeviceRecordController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 批量创建设备点位采集记录和配方点位记录
|
|
|
|
|
|
|
|
* @param recipeId 配方ID
|
|
|
|
|
|
|
|
* @param pointList 点位列表 [{id: 1, refer: "参考值1"}, {id: 2, refer: "参考值2"}]
|
|
|
|
|
|
|
|
* @return 创建结果
|
|
|
|
|
|
|
|
* @throws JsonProcessingException JSON处理异常
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@PostMapping("/batch-create")
|
|
|
|
|
|
|
|
@Operation(summary = "批量创建设备点位采集记录和配方点位记录")
|
|
|
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('iot:recipe-device-record:create')")
|
|
|
|
|
|
|
|
public CommonResult<Boolean> batchCreateRecipeDeviceRecord(
|
|
|
|
|
|
|
|
@RequestParam("id") Long recipeId) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RecipePlanDetailDO recipePlanDetailDO = recipePlanDetailService.getRecipePlanDetail(recipeId);
|
|
|
|
|
|
|
|
//RecipeRespVO recipeRespVO = recipeService.getRecipeWithDeviceId(recipePlanDetailDO.getRecipeId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//RecipeDO recipeDO = recipeService.getRecipe(recipePlanDetailDO.getRecipeId());
|
|
|
|
|
|
|
|
// ========== 第一步:查询配方关联的点位属性信息 ==========
|
|
|
|
|
|
|
|
// 1.1 根据recipeId查询iot_recipe_device_attribute表记录
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
recipePlanDetailDO.setRecipeId(32L);
|
|
|
|
//
|
|
|
|
List<RecipeDeviceAttributeDO> attributeList = recipeDeviceAttributeService.getByRecipeId(recipePlanDetailDO.getRecipeId());
|
|
|
|
// /**
|
|
|
|
|
|
|
|
// * 批量创建设备点位采集记录和配方点位记录
|
|
|
|
|
|
|
|
// * @param recipeId 配方ID
|
|
|
|
|
|
|
|
// * @param pointList 点位列表 [{id: 1, refer: "参考值1"}, {id: 2, refer: "参考值2"}]
|
|
|
|
|
|
|
|
// * @return 创建结果
|
|
|
|
|
|
|
|
// * @throws JsonProcessingException JSON处理异常
|
|
|
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
// @PostMapping("/batch-create")
|
|
|
|
|
|
|
|
// @Operation(summary = "批量创建设备点位采集记录和配方点位记录")
|
|
|
|
|
|
|
|
// @PreAuthorize("@ss.hasPermission('iot:recipe-device-record:create')")
|
|
|
|
|
|
|
|
// public CommonResult<Boolean> batchCreateRecipeDeviceRecord(
|
|
|
|
|
|
|
|
// @RequestParam("recipeId") Long recipeId,
|
|
|
|
|
|
|
|
// @RequestBody List<PointReferVO> pointList) throws JsonProcessingException {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // ========== 第一步:查询配方关联的点位属性信息 ==========
|
|
|
|
|
|
|
|
// // 1.1 根据recipeId查询iot_recipe_device_attribute表记录
|
|
|
|
|
|
|
|
// List<RecipeDeviceAttributeDO> attributeList = recipeDeviceAttributeService.getByRecipeId(recipeId);
|
|
|
|
|
|
|
|
// if (CollectionUtils.isEmpty(attributeList)) {
|
|
|
|
// if (CollectionUtils.isEmpty(attributeList)) {
|
|
|
|
// return success(false); // 无关联属性,直接返回
|
|
|
|
// return success(false); // 无关联属性,直接返回
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
Map<Long, Map<String, Object>> deviceDataMap = deviceService.createDeviceDataMap(103L);//recipeRespVO.getDeviceId()
|
|
|
|
// // 1.2 构建attributeName -> (attributeId, dataUnit)的映射关系
|
|
|
|
|
|
|
|
// Map<String, AttributeInfo> attributeMap = new HashMap<>();
|
|
|
|
for (RecipeDeviceAttributeDO attributeDO : attributeList) {
|
|
|
|
// for (RecipeDeviceAttributeDO attributeDO : attributeList) {
|
|
|
|
Map<String, Object> data = deviceDataMap.get(attributeDO.getAttributeId());
|
|
|
|
// // 根据attribute_id查询iot_device_contact_model表获取attribute_name和data_unit
|
|
|
|
if (data != null ) {
|
|
|
|
// // 假设通过service方法获取,需根据实际业务调整
|
|
|
|
// 创建
|
|
|
|
// Map<String, String> modelAttr = recipeDeviceAttributeService.getDeviceContactModelAttr(attributeDO.getAttributeId());
|
|
|
|
RecipeDeviceRecordDO recipeDeviceRecordDO = new RecipeDeviceRecordDO();
|
|
|
|
// String attributeName = modelAttr.get("attributeName");
|
|
|
|
recipeDeviceRecordDO.setRecipeId(recipeId);
|
|
|
|
// String dataUnit = modelAttr.get("dataUnit");
|
|
|
|
recipeDeviceRecordDO.setAttributeCode(attributeDO.getAttributeName());
|
|
|
|
//
|
|
|
|
recipeDeviceRecordDO.setDataType(attributeDO.getDataType());
|
|
|
|
// attributeMap.put(attributeName, new AttributeInfo(
|
|
|
|
recipeDeviceRecordDO.setDataUnit(attributeDO.getDataUnit());
|
|
|
|
// attributeDO.getId(), attributeName, dataUnit, attributeDO.getDeviceId()));
|
|
|
|
if (data.get("addressValue") != null && data.get("addressValue").toString() != null) {
|
|
|
|
// }
|
|
|
|
recipeDeviceRecordDO.setValue(data.get("addressValue").toString());
|
|
|
|
//
|
|
|
|
}
|
|
|
|
// // ========== 第二步:获取设备运行参数并创建设备点位采集记录 ==========
|
|
|
|
recipeDeviceRecordService.createRecipeDeviceRecord(BeanUtils.toBean(recipeDeviceRecordDO, RecipeDeviceRecordSaveReqVO.class));
|
|
|
|
// // 2.1 获取设备运行参数JSON数据(复用singleDevice逻辑,取第一个设备ID)
|
|
|
|
|
|
|
|
// if (attributeList.isEmpty()) {
|
|
|
|
}
|
|
|
|
// return success(false);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Long deviceId = attributeList.get(0).getDeviceId();
|
|
|
|
return success(true);
|
|
|
|
// Map<String, List<Map<String, Object>>> deviceData = recipeDeviceAttributeService.singleDevice(deviceId);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 2.2 解析JSON数据并匹配属性名
|
|
|
|
|
|
|
|
// if (deviceData != null && deviceData.containsKey("data")) {
|
|
|
|
|
|
|
|
// // 解析嵌套的data节点(适配示例JSON结构)
|
|
|
|
|
|
|
|
// String dataJson = objectMapper.writeValueAsString(deviceData.get("data"));
|
|
|
|
|
|
|
|
// JsonNode dataNode = objectMapper.readTree(dataJson);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 遍历所有数据分类(设备基础数据、班次信息等)
|
|
|
|
|
|
|
|
// Iterator<Map.Entry<String, JsonNode>> categoryIterator = dataNode.fields();
|
|
|
|
|
|
|
|
// while (categoryIterator.hasNext()) {
|
|
|
|
|
|
|
|
// Map.Entry<String, JsonNode> categoryEntry = categoryIterator.next();
|
|
|
|
|
|
|
|
// JsonNode attrListNode = categoryEntry.getValue();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 遍历分类下的每个属性
|
|
|
|
|
|
|
|
// if (attrListNode.isArray()) {
|
|
|
|
|
|
|
|
// for (JsonNode attrNode : attrListNode) {
|
|
|
|
|
|
|
|
// String attributeName = attrNode.get("attributeName").asText();
|
|
|
|
|
|
|
|
// JsonNode addressValueNode = attrNode.get("addressValue");
|
|
|
|
|
|
|
|
// Object addressValue = addressValueNode.isNull() ? null :
|
|
|
|
|
|
|
|
// (addressValueNode.isNumber() ? addressValueNode.numberValue() : addressValueNode.textValue());
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 匹配第一步的属性名,匹配成功则创建记录
|
|
|
|
|
|
|
|
// if (attributeMap.containsKey(attributeName)) {
|
|
|
|
|
|
|
|
// AttributeInfo attrInfo = attributeMap.get(attributeName);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 构建设备点位采集记录DO
|
|
|
|
|
|
|
|
// RecipeDeviceRecordDO recordDO = new RecipeDeviceRecordDO();
|
|
|
|
|
|
|
|
// recordDO.setRecipeId(recipeId);
|
|
|
|
|
|
|
|
// recordDO.setAttributeName(attributeName);
|
|
|
|
|
|
|
|
// recordDO.setAddressValue(addressValue != null ? addressValue.toString() : null);
|
|
|
|
|
|
|
|
// recordDO.setDataUnit(attrInfo.getDataUnit());
|
|
|
|
|
|
|
|
// recordDO.setDeviceId(deviceId);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 创建记录
|
|
|
|
|
|
|
|
// recipeDeviceRecordService.createRecipeDeviceRecord(recordDO);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // ========== 第三步:创建配方点位记录 ==========
|
|
|
|
|
|
|
|
// for (PointReferVO pointVO : pointList) {
|
|
|
|
|
|
|
|
// // 3.1 根据id查询iot_recipe_point表记录
|
|
|
|
|
|
|
|
// RecipePointDO pointDO = recipePointService.getRecipePoint(pointVO.getId());
|
|
|
|
|
|
|
|
// if (pointDO == null) {
|
|
|
|
|
|
|
|
// continue; // 点位不存在则跳过
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 3.2 构建配方点位记录DO
|
|
|
|
|
|
|
|
// RecipePointRecordDO pointRecordDO = new RecipePointRecordDO();
|
|
|
|
|
|
|
|
// pointRecordDO.setPointId(pointDO.getId());
|
|
|
|
|
|
|
|
// pointRecordDO.setName(pointDO.getName());
|
|
|
|
|
|
|
|
// pointRecordDO.setMax(pointDO.getMax());
|
|
|
|
|
|
|
|
// pointRecordDO.setMin(pointDO.getMin());
|
|
|
|
|
|
|
|
// pointRecordDO.setDataUnit(pointDO.getDataUnit());
|
|
|
|
|
|
|
|
// pointRecordDO.setRemark(pointDO.getRemark());
|
|
|
|
|
|
|
|
// pointRecordDO.setRefer(pointVO.getRefer()); // 入参的refer值
|
|
|
|
|
|
|
|
// pointRecordDO.setRecipeId(recipeId);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 3.3 创建配方点位记录
|
|
|
|
|
|
|
|
// recipePointRecordService.createRecipePointRecord(pointRecordDO);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return success(true);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 内部辅助类 ==========
|
|
|
|
// ========== 内部辅助类 ==========
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|