|
|
|
|
@ -156,16 +156,17 @@ public class RecipeDeviceRecordController {
|
|
|
|
|
@Operation(summary = "批量创建设备点位采集记录和配方点位记录")
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('iot:recipe-device-record:create')")
|
|
|
|
|
public CommonResult<Boolean> batchCreateRecipeDeviceRecord(
|
|
|
|
|
@RequestParam("id") Long recipeId) {
|
|
|
|
|
@RequestParam("id") Long id) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RecipePlanDetailDO recipePlanDetailDO = recipePlanDetailService.getRecipePlanDetail(recipeId);
|
|
|
|
|
RecipePlanDetailDO recipePlanDetailDO = recipePlanDetailService.getRecipePlanDetail(id);
|
|
|
|
|
Long recipeId = recipePlanDetailDO.getRecipeId();
|
|
|
|
|
|
|
|
|
|
// ========== 第一步:查询配方关联的点位属性信息 ==========
|
|
|
|
|
// 1.1 根据recipeId查询iot_recipe_device_attribute表记录
|
|
|
|
|
|
|
|
|
|
recipePlanDetailDO.setRecipeId(recipeId);
|
|
|
|
|
List<RecipeDeviceAttributeDO> attributeList = recipeDeviceAttributeService.getByRecipeId(recipePlanDetailDO.getRecipeId());
|
|
|
|
|
// recipePlanDetailDO.setRecipeId(recipeId);
|
|
|
|
|
List<RecipeDeviceAttributeDO> attributeList = recipeDeviceAttributeService.getByRecipeId(recipeId);
|
|
|
|
|
|
|
|
|
|
//先删除在添加
|
|
|
|
|
List<RecipeDeviceRecordDO> recipeDeviceRecordDOS = recipeDeviceRecordService.getListByRecipeId(recipeId);
|
|
|
|
|
@ -178,15 +179,15 @@ public class RecipeDeviceRecordController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceRespVO device = deviceService.getDevice(recipe.getMachineId());
|
|
|
|
|
if (device== null ){
|
|
|
|
|
throw exception(DEVICE_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
if (device != null) {
|
|
|
|
|
// throw exception(DEVICE_NOT_EXISTS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
Map<Long, DeviceContactModelDO> deviceContactModelMap = new HashMap<>();
|
|
|
|
|
List<DeviceContactModelDO> deviceContactModelDOS = deviceContactModelService.selectListByDeviceId(device.getId());
|
|
|
|
|
if (!deviceContactModelDOS.isEmpty()){
|
|
|
|
|
if (!deviceContactModelDOS.isEmpty()) {
|
|
|
|
|
deviceContactModelMap = deviceContactModelDOS.stream()
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
DeviceContactModelDO::getId,
|
|
|
|
|
@ -194,20 +195,30 @@ public class RecipeDeviceRecordController {
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpcUtils.connect(device.getId(),device.getUrl(),device.getUsername(),device.getPassword(),10);
|
|
|
|
|
|
|
|
|
|
Map<Long, Map<String, Object>> deviceDataMap = deviceService.createDeviceDataMap(device.getId());//recipeRespVO.getDeviceId()
|
|
|
|
|
|
|
|
|
|
// OpcUtils.connect(device.getId(),device.getUrl(),device.getUsername(),device.getPassword(),10);
|
|
|
|
|
|
|
|
|
|
for (RecipeDeviceAttributeDO attributeDO : attributeList) {
|
|
|
|
|
Map<String, Object> data = deviceDataMap.get(attributeDO.getAttributeId());
|
|
|
|
|
|
|
|
|
|
DeviceContactModelDO deviceContactModelDO = deviceContactModelMap.get(attributeDO.getAttributeId());
|
|
|
|
|
if (deviceContactModelDO == null){
|
|
|
|
|
if (deviceContactModelDO == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// 创建
|
|
|
|
|
RecipeDeviceRecordDO recipeDeviceRecordDO = new RecipeDeviceRecordDO();
|
|
|
|
|
recipeDeviceRecordDO.setRecipeId(recipeId);
|
|
|
|
|
recipeDeviceRecordDO.setAttributeCode(deviceContactModelDO.getAttributeName());
|
|
|
|
|
recipeDeviceRecordDO.setAttributeCode(deviceContactModelDO.getAttributeCode());
|
|
|
|
|
recipeDeviceRecordDO.setAttributeName(deviceContactModelDO.getAttributeName());
|
|
|
|
|
recipeDeviceRecordDO.setDataType(deviceContactModelDO.getDataType());
|
|
|
|
|
recipeDeviceRecordDO.setDeviceId(deviceContactModelDO.getDeviceId());
|
|
|
|
|
recipeDeviceRecordDO.setDataUnit(deviceContactModelDO.getDataUnit());
|
|
|
|
|
// recipeDeviceRecordDO.setValue((String) OpcUtils.readValues(device.getId(),deviceContactModelDO.getAddress()));
|
|
|
|
|
if (data.get("addressValue") != null && data.get("addressValue").toString() != null) {
|
|
|
|
|
recipeDeviceRecordDO.setValue(data.get("addressValue").toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recipeDeviceRecordService.createRecipeDeviceRecord(BeanUtils.toBean(recipeDeviceRecordDO, RecipeDeviceRecordSaveReqVO.class));
|
|
|
|
|
|
|
|
|
|
@ -215,6 +226,7 @@ public class RecipeDeviceRecordController {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success(true);
|
|
|
|
|
}
|
|
|
|
|
|