Browse Source

Merge branch 'usky-zyj' into server-165

james 3 weeks ago
parent
commit
29acf1115c

+ 1 - 1
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpProductInfoController.java

@@ -34,7 +34,7 @@ public class DmpProductInfoController {
      * @return
      */
     @PostMapping
-    public ApiResult<Void> add(@RequestBody DmpProductInfo dmpProductInfo){
+    public ApiResult<Void> add(@RequestBody List<DmpProductInfo> dmpProductInfo){
         dmpProductInfoService.add(dmpProductInfo);
         return ApiResult.success();
     }

+ 1 - 1
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/DmpProductInfoService.java

@@ -19,7 +19,7 @@ import java.util.Map;
 public interface DmpProductInfoService extends CrudService<DmpProductInfo> {
 
 
-    void add(DmpProductInfo dmpProductInfo);
+    void add(List<DmpProductInfo> dmpProductInfo);
 
     void update(DmpProductInfo dmpProductInfo);
 

+ 66 - 59
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpProductInfoServiceImpl.java

@@ -59,71 +59,78 @@ public class DmpProductInfoServiceImpl extends AbstractCrudService<DmpProductInf
     private RemoteTransferService remoteTransferService;
 
     @Override
-    public void add(DmpProductInfo dmpProductInfo) {
-        if (checkNameUnique(dmpProductInfo)){
-            throw new BusinessException("新增产品信息'" + dmpProductInfo.getProductCode() + "'失败,产品信息已存在");
-        }
-        int deviceType = dmpProductInfo.getDeviceType();
-        LambdaQueryWrapper<DmpDeviceType> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.select(DmpDeviceType::getDataField)
-                .eq(DmpDeviceType::getTypeCode,deviceType);
-        DmpDeviceType one  = dmpDeviceTypeService.getOne(queryWrapper);
-        String dd = one.getDataField();
-        if (StringUtils.isBlank(dd) || dd.length() == 0){
-            throw new BusinessException("新增产品信息'" + dmpProductInfo.getProductCode() + "'失败,设备类型缺少属性");
+    public void add(List<DmpProductInfo> dmpProductInfo) {
+        if (CollectionUtils.isEmpty(dmpProductInfo)) {
+            throw new BusinessException("数据不能为空");
         }
 
-        QueryWrapper<DmpProductInfo> query = Wrappers.query();
-        query.select("max(id) as id");
-        DmpProductInfo info1 = this.getOne(query);
-        int id = info1.getId()+1;
-        String productCode = String.format("%03d",deviceType)+"_"+String.format("%04d",id);
-        dmpProductInfo.setProductCode(productCode);
-
-        dmpProductInfo.setCreatedBy(SecurityUtils.getUsername());
-        dmpProductInfo.setCreatedTime(new Date());
-        dmpProductInfo.setDeleteFlag(0);
-        dmpProductInfo.setTenantId(SecurityUtils.getTenantId());
-        this.save(dmpProductInfo);
-
-        remoteTransferService.deleteProductCache();
+        for (int k = 0; k < dmpProductInfo.size(); k++) {
+            if (checkNameUnique(dmpProductInfo.get(k))){
+                throw new BusinessException("新增产品信息'" + dmpProductInfo.get(k).getProductCode() + "'失败,产品信息已存在");
+            }
+            int deviceType = dmpProductInfo.get(k).getDeviceType();
+            LambdaQueryWrapper<DmpDeviceType> queryWrapper = Wrappers.lambdaQuery();
+            queryWrapper.select(DmpDeviceType::getDataField)
+                    .eq(DmpDeviceType::getTypeCode,deviceType);
+            DmpDeviceType one  = dmpDeviceTypeService.getOne(queryWrapper);
+            String dd = one.getDataField();
+            if (StringUtils.isBlank(dd) || dd.length() == 0){
+                throw new BusinessException("新增产品信息'" + dmpProductInfo.get(k).getProductCode() + "'失败,设备类型缺少属性");
+            }
 
-        int productId = dmpProductInfo.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);
+            QueryWrapper<DmpProductInfo> query = Wrappers.query();
+            query.select("max(id) as id");
+            DmpProductInfo info1 = this.getOne(query);
+            int id = info1.getId()+1;
+            String productCode = String.format("%03d",deviceType)+"_"+id;
+            dmpProductInfo.get(k).setProductCode(productCode);
+
+            dmpProductInfo.get(k).setCreatedBy(SecurityUtils.getUsername());
+            dmpProductInfo.get(k).setCreatedTime(new Date());
+            dmpProductInfo.get(k).setDeleteFlag(0);
+            dmpProductInfo.get(k).setTenantId(SecurityUtils.getTenantId());
+            this.save(dmpProductInfo.get(k));
+
+            remoteTransferService.deleteProductCache();
+
+            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);
+                    }
                 }
             }
         }
+
     }
 
     @Override