Forráskód Böngészése

优化产品信息表-新增接口,将新增单个产品改为可以同时新增多个产品逻辑,同时新增产品时自动带入命令数据到产品命令表中,实现产品与命令的绑定

james 2 napja
szülő
commit
085251546f

+ 5 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/DmpDeviceType.java

@@ -87,5 +87,10 @@ public class DmpDeviceType implements Serializable {
      */
     private LocalDateTime updatedTime;
 
+    /**
+     * 命令字段
+     */
+    private String commandField;
+
 
 }

+ 73 - 32
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpProductInfoServiceImpl.java

@@ -58,6 +58,9 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
     @Autowired
     private RemoteTransferService remoteTransferService;
 
+    @Autowired
+    private DmpProductCommandService dmpProductCommandService;
+
     @Override
     public void add(List<DmpProductInfo> dmpProductInfo) {
         if (CollectionUtils.isEmpty(dmpProductInfo)) {
@@ -70,7 +73,7 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
             }
             int deviceType = dmpProductInfo.get(k).getDeviceType();
             LambdaQueryWrapper<DmpDeviceType> queryWrapper = Wrappers.lambdaQuery();
-            queryWrapper.select(DmpDeviceType::getDataField)
+            queryWrapper.select(DmpDeviceType::getDataField,DmpDeviceType::getCommandField)
                     .eq(DmpDeviceType::getTypeCode,deviceType);
             DmpDeviceType one  = dmpDeviceTypeService.getOne(queryWrapper);
             String dd = one.getDataField();
@@ -95,37 +98,75 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
 
             int productId = dmpProductInfo.get(k).getId();
             if(null != one){
-                String dataField = one.getDataField();
-                JSONArray array = new JSONArray();
-                array =  JSONArray.parseArray(dataField);
-                if(array.size()>0){
-                    for(int i=0;i<array.size();i++){
-                        JSONObject obj = JSONObject.parseObject(array.getString(i));
-                        String attribute_name = obj.getString("attribute_name");
-                        String attribute_code = obj.getString("attribute_code");
-                        int attribute_port = obj.getInteger("attribute_port");
-                        int data_type = obj.getInteger("data_type");
-                        int attribute_length = obj.getInteger("attribute_length");
-                        String attribute_unit = obj.getString("attribute_unit");
-                        int maximum = obj.getInteger("maximum");
-                        int minimum = obj.getInteger("minimum");
-
-                        DmpProductAttribute dmpProductAttribute = new DmpProductAttribute();
-                        dmpProductAttribute.setProductId(productId);
-                        dmpProductAttribute.setAttributeName(attribute_name);
-                        dmpProductAttribute.setAttributeCode(attribute_code);
-                        dmpProductAttribute.setAttributePort(attribute_port);
-                        dmpProductAttribute.setAttributeType(1);
-                        dmpProductAttribute.setDataType(data_type);
-                        dmpProductAttribute.setAttributeLength(attribute_length);
-                        dmpProductAttribute.setAttributeUnit(attribute_unit);
-                        dmpProductAttribute.setMaximum(BigDecimal.valueOf(maximum));
-                        dmpProductAttribute.setMinimum(BigDecimal.valueOf(minimum));
-                        dmpProductAttribute.setDeleteFlag(0);
-                        dmpProductAttribute.setCreatedBy(SecurityUtils.getUsername());
-                        dmpProductAttribute.setCreatedTime(new Date());
-                        dmpProductAttribute.setTenantId(SecurityUtils.getTenantId());
-                        dmpProductAttributeService.save(dmpProductAttribute);
+                if(Objects.nonNull(one.getDataField())){
+                    String dataField = one.getDataField();
+                    JSONArray array = new JSONArray();
+                    array =  JSONArray.parseArray(dataField);
+                    if(array.size()>0){
+                        for(int i=0;i<array.size();i++){
+                            JSONObject obj = JSONObject.parseObject(array.getString(i));
+                            String attribute_name = obj.getString("attribute_name");
+                            String attribute_code = obj.getString("attribute_code");
+                            int attribute_port = obj.getInteger("attribute_port");
+                            int data_type = obj.getInteger("data_type");
+                            int attribute_length = obj.getInteger("attribute_length");
+                            String attribute_unit = obj.getString("attribute_unit");
+                            int maximum = obj.getInteger("maximum");
+                            int minimum = obj.getInteger("minimum");
+
+                            DmpProductAttribute dmpProductAttribute = new DmpProductAttribute();
+                            dmpProductAttribute.setProductId(productId);
+                            dmpProductAttribute.setAttributeName(attribute_name);
+                            dmpProductAttribute.setAttributeCode(attribute_code);
+                            dmpProductAttribute.setAttributePort(attribute_port);
+                            dmpProductAttribute.setAttributeType(1);
+                            dmpProductAttribute.setDataType(data_type);
+                            dmpProductAttribute.setAttributeLength(attribute_length);
+                            dmpProductAttribute.setAttributeUnit(attribute_unit);
+                            dmpProductAttribute.setMaximum(BigDecimal.valueOf(maximum));
+                            dmpProductAttribute.setMinimum(BigDecimal.valueOf(minimum));
+                            dmpProductAttribute.setDeleteFlag(0);
+                            dmpProductAttribute.setCreatedBy(SecurityUtils.getUsername());
+                            dmpProductAttribute.setCreatedTime(new Date());
+                            dmpProductAttribute.setTenantId(SecurityUtils.getTenantId());
+                            dmpProductAttributeService.save(dmpProductAttribute);
+                        }
+                    }
+                }
+
+                if(Objects.nonNull(one.getCommandField())){
+                    String commandField = one.getCommandField();
+                    JSONArray array = JSONArray.parseArray(commandField);
+                    if(array.size()>0){
+                        for(int i=0;i<array.size();i++){
+                            JSONObject obj = JSONObject.parseObject(array.getString(i));
+                            String command_name = obj.getString("command_name");
+                            String command_code = obj.getString("command_code");
+                            int data_type = obj.getInteger("data_type");
+
+                            DmpProductCommand dmpProductCommand = new DmpProductCommand();
+                            dmpProductCommand.setProductCode(productCode);
+                            dmpProductCommand.setCommandName(command_name);
+                            dmpProductCommand.setCommandCode(command_code);
+                            dmpProductCommand.setDataType(data_type);
+                            if(!(obj.getString("command_dict")).equals("")){
+                                dmpProductCommand.setCommandDict(obj.getString("command_dict"));
+                            }
+                            if(!(obj.getString("command_unit")).equals("")){
+                                dmpProductCommand.setCommandUnit(obj.getString("command_unit"));
+                            }
+                            if(!(obj.getString("maximum")).equals("")){
+                                dmpProductCommand.setMaximum(BigDecimal.valueOf(Long.parseLong(obj.getString("maximum"))));
+                            }
+                            if(!(obj.getString("minimum")).equals("")){
+                                dmpProductCommand.setMinimum(BigDecimal.valueOf(Long.parseLong(obj.getString("minimum"))));
+                            }
+                            dmpProductCommand.setDeleteFlag(0);
+                            dmpProductCommand.setCreatedBy(SecurityUtils.getUsername());
+                            dmpProductCommand.setCreatedTime(LocalDateTime.now());
+                            dmpProductCommand.setTenantId(SecurityUtils.getTenantId());
+                            dmpProductCommandService.save(dmpProductCommand);
+                        }
                     }
                 }
             }

+ 1 - 0
service-iot/service-iot-biz/src/main/resources/mapper/iot/DmpDeviceTypeMapper.xml

@@ -17,6 +17,7 @@
         <result column="created_time" property="createdTime" />
         <result column="updated_by" property="updatedBy" />
         <result column="updated_time" property="updatedTime" />
+        <result column="command_field" property="commandField" />
     </resultMap>
     <select id="getProductInfo" resultType="com.usky.iot.domain.DmpProductInfo">
         select