Browse Source

部件字典管理接口和部件po

shiyue 8 tháng trước cách đây
mục cha
commit
a2bda513ea

+ 28 - 12
energy-manage-service/src/main/java/com/energy/manage/service/controller/units/UnitController.java

@@ -37,7 +37,7 @@ public class UnitController extends BaseServiceController {
     @PostMapping(value = "/getBrandModelNameOrModelNumber")
     @ApiOperation(value = "根据部件类型,查询部件类型对应品牌/型号")
     public ResultResp<List<String>> getBrandModelNameOrModelNumber(@RequestBody @Valid UnitDictBrandModelDto unitDictBrandModelDto) {
-        if(unitDictBrandModelDto.getUnitType()==null){
+        if (unitDictBrandModelDto.getUnitType() == null) {
             log.error("查询部件,部件类型unitType不能为空");
             return ResultResp.NOTNULLPARAM();
         }
@@ -46,7 +46,6 @@ public class UnitController extends BaseServiceController {
     }
 
 
-
     @UserLoginToken
     @PostMapping(value = "/getUnitDictRoutineList")
     @ApiOperation(value = "根据部件类型,查询部件常用类型字典")
@@ -56,20 +55,44 @@ public class UnitController extends BaseServiceController {
     }
 
 
-
     @UserLoginToken
     @PostMapping(value = "/modificationUnit")
     @ApiOperation(value = "更新部件相关信息")
     public ResultResp modificationUnit(@RequestBody @Valid UnitDto unitDto) {
 
+        // 验证主轴数据
+        UnitDto.validateAndSetEmptyToNull(unitDto.getUnitBearingsDto());
+        if (unitDto.getUnitBearingsDto().allPropertiesAreNull()) {
+            unitDto.setUnitBearingsDto(null);
+        }
+        // 验证齿轮箱数据
+        UnitDto.validateAndSetEmptyToNull(unitDto.getUnitGearDto());
+        if (!unitDto.getUnitGearDto().allPropertiesGearboxBearingsListNull()) {
+            unitDto.getUnitGearDto().setUnitGearboxBearingsDtoList(null);
+        }
+        if (!unitDto.getUnitGearDto().allPropertiesGearboxStructureListNull()) {
+            unitDto.getUnitGearDto().setUnitGearboxStructureDtoList(null);
+        }
 
+        if (unitDto.getUnitGearDto().allPropertiesAreNull()) {
+            unitDto.setUnitGearDto(null);
+        }
+        // 验证发电机数据
+        UnitDto.validateAndSetEmptyToNull(unitDto.getUnitDynamoDto());
+        if (unitDto.getUnitDynamoDto().allPropertiesAreNull()) {
+            unitDto.setUnitDynamoDto(null);
+        }
 
-        boolean flg =  unitService.modificationUnit(unitDto);
+        if (unitDto.getUnitBearingsDto() == null &&
+                unitDto.getUnitDynamoDto() == null &&
+                unitDto.getUnitGearDto() == null) {
+            return ResultResp.FAIL("所有数据均为空,不进行部件数据维护!");
+        }
+        boolean flg = unitService.modificationUnit(unitDto);
         return flg ? ResultResp.SUCCESS() : ResultResp.FAIL();
     }
 
 
-
     @UserLoginToken
     @GetMapping(value = "/getUnitVo")
     @ApiOperation(value = "通过机型编号查询部件信息")
@@ -79,11 +102,4 @@ public class UnitController extends BaseServiceController {
     }
 
 
-
-
-
-
-
-
-
 }

+ 159 - 9
energy-manage-service/src/main/java/com/energy/manage/service/domain/dto/units/UnitDto.java

@@ -6,6 +6,8 @@ import lombok.Getter;
 import lombok.Setter;
 import org.springframework.util.CollectionUtils;
 
+import javax.validation.constraints.NotNull;
+import java.lang.reflect.Field;
 import java.util.List;
 
 /**
@@ -20,6 +22,7 @@ public class UnitDto {
      * 机型编号
      */
     @ApiModelProperty("机型编号")
+    @NotNull(message = "机型编号不能为空")
     private String millTypeCode;
 
     @ApiModelProperty("主轴相关参数")
@@ -40,7 +43,7 @@ public class UnitDto {
     @Setter
     @Getter
     @ApiModel
-    public static class UnitGearDto{
+    public static class UnitGearDto {
 
         /**
          * 主键
@@ -78,8 +81,49 @@ public class UnitDto {
         @ApiModelProperty("齿轮箱结构集合")
         List<UnitGearboxStructureDto> unitGearboxStructureDtoList;
 
+        // 判断所有属性是否都为空
+        public boolean allPropertiesAreNull() {
+            return (this.id == null || this.id == 0) &&
+                    (this.code == null || this.code.isEmpty()) &&
+                    (this.lubricantBrand == null || this.lubricantBrand.isEmpty()) &&
+                    (this.lubricantModel == null || this.lubricantModel.isEmpty()) &&
+                    (CollectionUtils.isEmpty(this.unitGearboxBearingsDtoList)) &&
+                    (CollectionUtils.isEmpty(this.unitGearboxStructureDtoList));
+        }
+
+        // 判断齿轮箱轴承集合所有属性是否都为空
+        public boolean allPropertiesGearboxBearingsListNull() {
+           List<UnitGearboxBearingsDto> list =  this.unitGearboxBearingsDtoList;
+           for(int i =0;i<list.size();i++){
+               UnitGearboxBearingsDto unitGearboxBearingsDto = list.get(i);
+               if(unitGearboxBearingsDto.allPropertiesAreNull()){
+                   list.remove(i);
+               }
+           }
+           if(list.size()<=0){
+               return false;
+           }
+           return true;
+        }
+
+        // 判断齿轮箱结构集合所有属性是否都为空
+        public boolean allPropertiesGearboxStructureListNull() {
+            List<UnitGearboxStructureDto> list =  this.unitGearboxStructureDtoList;
+            for(int i =0;i<list.size();i++){
+                UnitGearboxStructureDto unitGearboxStructureDto = list.get(i);
+                if(unitGearboxStructureDto.allPropertiesAreNull()){
+                    list.remove(i);
+                }
+            }
+            if(list.size()<=0){
+                return false;
+            }
+            return true;
+        }
+
         /**
          * 数据校验
+         *
          * @param unitGearDto
          * @return
          */
@@ -87,7 +131,6 @@ public class UnitDto {
             if (unitGearDto == null) {
                 return false;
             }
-
             if (unitGearDto.getId() == null) {
                 return false;
             }
@@ -116,6 +159,8 @@ public class UnitDto {
         }
 
 
+
+
     }
 
     /**
@@ -124,7 +169,7 @@ public class UnitDto {
     @Setter
     @Getter
     @ApiModel
-    public static class UnitGearboxStructureDto{
+    public static class UnitGearboxStructureDto {
 
         @ApiModelProperty("主键")
         private Integer id;
@@ -197,6 +242,7 @@ public class UnitDto {
 
         /**
          * 数据校验
+         *
          * @param dto
          * @return
          */
@@ -204,7 +250,6 @@ public class UnitDto {
             if (dto == null) {
                 return false;
             }
-
             if (dto.getId() == null) {
                 return false;
             }
@@ -264,6 +309,23 @@ public class UnitDto {
             return true;
         }
 
+        // 判断所有属性是否都为空
+        public boolean allPropertiesAreNull() {
+            return (this.id == null || this.id == 0) &&
+                    (this.gearboxCode == null || this.gearboxCode.isEmpty()) &&
+                    (this.gearboxStructure == null || this.gearboxStructure == 0) &&
+                    (this.planetaryGearGrade == null || this.planetaryGearGrade == 0) &&
+                    (this.largeGearTeethCount == null || this.largeGearTeethCount.isEmpty()) &&
+                    (this.smallGearTeethCount == null || this.smallGearTeethCount.isEmpty()) &&
+                    (this.bearingBrand == null || this.bearingBrand.isEmpty()) &&
+                    (this.bearingModel == null || this.bearingModel.isEmpty()) &&
+                    (this.gearRingTeethCount == null || this.gearRingTeethCount.isEmpty()) &&
+                    (this.sunWheelTeethCount == null || this.sunWheelTeethCount.isEmpty()) &&
+                    (this.planetWheelCount == null || this.planetWheelCount.isEmpty()) &&
+                    (this.planetWheelTeethCount == null || this.planetWheelTeethCount.isEmpty()) &&
+                    (this.sunWheelBearingBrand == null || this.sunWheelBearingBrand.isEmpty()) &&
+                    (this.sunWheelBearingModel == null || this.sunWheelBearingModel.isEmpty());
+        }
     }
 
 
@@ -273,7 +335,7 @@ public class UnitDto {
     @Setter
     @Getter
     @ApiModel
-    public static class UnitGearboxBearingsDto{
+    public static class UnitGearboxBearingsDto {
 
         @ApiModelProperty("主键")
         private Integer id;
@@ -337,6 +399,7 @@ public class UnitDto {
 
         /**
          * 数据校验
+         *
          * @param gearboxBearing
          * @return
          */
@@ -344,7 +407,6 @@ public class UnitDto {
             if (gearboxBearing == null) {
                 return false;
             }
-
             if (gearboxBearing.getId() == null) {
                 return false;
             }
@@ -396,9 +458,26 @@ public class UnitDto {
             return true;
         }
 
-    }
+
+        // 判断所有属性是否都为空
+        public boolean allPropertiesAreNull() {
+            return (this.id == null || this.id == 0) &&
+                    (this.gearboxCode == null || this.gearboxCode.isEmpty()) &&
+                    (this.parallelWheelGrade == null || this.parallelWheelGrade == 0) &&
+                    (this.gearboxBearingNumber == null || this.gearboxBearingNumber.isEmpty()) &&
+                    (this.gearboxBearingLevel == null || this.gearboxBearingLevel.isEmpty()) &&
+                    (this.bearingBrand == null || this.bearingBrand.isEmpty()) &&
+                    (this.bearingModel == null || this.bearingModel.isEmpty()) &&
+                    (this.gearRingTeethCount == null || this.gearRingTeethCount.isEmpty()) &&
+                    (this.bearingRsBrand == null || this.bearingRsBrand.isEmpty()) &&
+                    (this.bearingRsModel == null || this.bearingRsModel.isEmpty()) &&
+                    (this.bearingGsBrand == null || this.bearingGsBrand.isEmpty()) &&
+                    (this.bearingGsModel == null || this.bearingGsModel.isEmpty());
+        }
 
 
+    }
+
 
     /**
      * 主轴相关参数
@@ -453,14 +532,15 @@ public class UnitDto {
 
         /**
          * 数据验证
+         *
          * @param component
          * @return
          */
         public static boolean isValid(UnitBearingsDto component) {
+
             if (component == null) {
                 return false;
             }
-
             if (component.getId() == null) {
                 return false;
             }
@@ -496,6 +576,18 @@ public class UnitDto {
             return true;
         }
 
+        // 判断所有属性是否都为空
+        public boolean allPropertiesAreNull() {
+            return (this.id == null || this.id == 0) &&
+                    (this.code == null || this.code.isEmpty()) &&
+                    (this.lubricantBrand == null || this.lubricantBrand.isEmpty()) &&
+                    (this.lubricantModel == null || this.lubricantModel.isEmpty()) &&
+                    (this.frontBearingBrand == null || this.frontBearingBrand.isEmpty()) &&
+                    (this.frontBearingModel == null || this.frontBearingModel.isEmpty()) &&
+                    (this.rearBearingBrand == null || this.rearBearingBrand.isEmpty()) &&
+                    (this.rearBearingModel == null || this.rearBearingModel.isEmpty());
+        }
+
     }
 
 
@@ -556,6 +648,7 @@ public class UnitDto {
 
         /**
          * 数据校验
+         *
          * @param motor
          * @return
          */
@@ -563,7 +656,6 @@ public class UnitDto {
             if (motor == null) {
                 return false;
             }
-
             if (motor.getId() == null) {
                 return false;
             }
@@ -603,6 +695,64 @@ public class UnitDto {
             return true;
         }
 
+        // 判断所有属性是否都为空
+        public boolean allPropertiesAreNull() {
+            return (this.id == null || this.id == 0) &&
+                    (this.polePairs == null || this.polePairs == 0) &&
+                    (this.coolingMethod == null || this.coolingMethod == 0) &&
+                    (this.lubricantBrand == null || this.lubricantBrand.isEmpty()) &&
+                    (this.lubricantModel == null || this.lubricantModel.isEmpty()) &&
+                    (this.driveEndBearingBrand == null || this.driveEndBearingBrand.isEmpty()) &&
+                    (this.driveEndBearingModel == null || this.driveEndBearingModel.isEmpty()) &&
+                    (this.nonDriveEndBearingBrand == null || this.nonDriveEndBearingBrand.isEmpty()) &&
+                    (this.nonDriveEndBearingModel == null || this.nonDriveEndBearingModel.isEmpty());
+        }
+
+
+    }
+
+
+    // 通用方法:传入一个对象,当对象中的字符串属性为空时将其设置为null
+    public static <T> T validateAndSetEmptyToNull(T obj) {
+        if (obj == null) {
+            return null;
+        }
+        boolean allFieldsNull = true;
+        Field[] fields = obj.getClass().getDeclaredFields();
+        for (Field field : fields) {
+            try {
+                field.setAccessible(true);
+                Object value = field.get(obj);
+
+                if (value instanceof String) {
+                    String strValue = (String) value;
+                    if (strValue != null && !strValue.trim().isEmpty()) {
+                        allFieldsNull = false;
+                    }else{
+                        field.set(obj, null);
+                    }
+                }
+                if (value instanceof Integer) {
+                    Integer strValue = (Integer) value;
+                    if (strValue != null && strValue > 0) {
+                        allFieldsNull = false;
+                    }else{
+                        field.set(obj, null);
+                    }
+                }
+            } catch (IllegalAccessException e) {
+                e.printStackTrace();
+            }
+        }
+
+        if (allFieldsNull) {
+            try {
+                return (T) obj.getClass().newInstance();
+            } catch (InstantiationException | IllegalAccessException e) {
+                e.printStackTrace();
+            }
+        }
+        return obj;
     }
 
 

+ 38 - 35
energy-manage-service/src/main/java/com/energy/manage/service/service/units/impl/UnitServiceImpl.java

@@ -88,7 +88,7 @@ public class UnitServiceImpl implements UnitService {
     @Transactional(rollbackFor = Exception.class)
     public boolean modificationUnit(UnitDto unitDto) {
 
-        boolean flg = true;
+        boolean flg = false;
         // 处理主轴
         outBearings:
         if (unitDto.getUnitBearingsDto() != null) {
@@ -136,9 +136,10 @@ public class UnitServiceImpl implements UnitService {
         }
 
         // 处理齿轮箱总表数据
-        UnitGearboxPO unitGearboxPO = new UnitGearboxPO();
+        UnitGearboxPO unitGearboxPO = null;
         outunitGearbox:
         if (unitDto.getUnitGearDto() != null) {
+            unitGearboxPO = new UnitGearboxPO();
             unitGearboxPO.setLubricantBrand(unitDto.getUnitGearDto().getLubricantBrand());
             unitGearboxPO.setLubricantModel(unitDto.getUnitGearDto().getLubricantModel());
             unitGearboxPO.setUpdateTime(new Date());
@@ -160,42 +161,44 @@ public class UnitServiceImpl implements UnitService {
 
         }
 
-        // 处理齿轮箱轴承处理
-        if (!CollectionUtils.isEmpty(unitDto.getUnitGearDto().getUnitGearboxBearingsDtoList())) {
-            UnitGearboxBearingsPO unitGearboxBearingsPO = null;
-            List<UnitGearboxBearingsPO> unitGearboxBearingsPOList = Lists.newArrayList();
-            for (UnitDto.UnitGearboxBearingsDto dto : unitDto.getUnitGearDto().getUnitGearboxBearingsDtoList()) {
-                unitGearboxBearingsPO = new UnitGearboxBearingsPO();
-                BeanUtil.copyProperties(dto, unitGearboxBearingsPO);
-                unitGearboxBearingsPO.setGearboxCode(unitGearboxPO.getCode());
-                unitGearboxBearingsPO.setCreateTime(new Date());
-                unitGearboxBearingsPO.setUpdateTime(new Date());
-                unitGearboxBearingsPOList.add(unitGearboxBearingsPO);
+        if(unitGearboxPO!=null){
+            // 处理齿轮箱轴承处理
+            if (!CollectionUtils.isEmpty(unitDto.getUnitGearDto().getUnitGearboxBearingsDtoList())) {
+                UnitGearboxBearingsPO unitGearboxBearingsPO = null;
+                List<UnitGearboxBearingsPO> unitGearboxBearingsPOList = Lists.newArrayList();
+                for (UnitDto.UnitGearboxBearingsDto dto : unitDto.getUnitGearDto().getUnitGearboxBearingsDtoList()) {
+                    unitGearboxBearingsPO = new UnitGearboxBearingsPO();
+                    BeanUtil.copyProperties(dto, unitGearboxBearingsPO);
+                    unitGearboxBearingsPO.setGearboxCode(unitGearboxPO.getCode());
+                    unitGearboxBearingsPO.setCreateTime(new Date());
+                    unitGearboxBearingsPO.setUpdateTime(new Date());
+                    unitGearboxBearingsPOList.add(unitGearboxBearingsPO);
+                }
+                UnitGearboxBearingsPO po = new UnitGearboxBearingsPO();
+                po.setGearboxCode(unitGearboxPO.getCode());
+                unitGearboxBearingsMapper.delete(po);
+
+                flg = unitGearboxBearingsMapper.insertList(unitGearboxBearingsPOList) > 0;
             }
-            UnitGearboxBearingsPO po = new UnitGearboxBearingsPO();
-            po.setGearboxCode(unitGearboxPO.getCode());
-            unitGearboxBearingsMapper.delete(po);
 
-            flg = unitGearboxBearingsMapper.insertList(unitGearboxBearingsPOList) > 0;
-        }
-
-        // 处理齿轮箱结构
-        if (!CollectionUtils.isEmpty(unitDto.getUnitGearDto().getUnitGearboxStructureDtoList())) {
-            UnitGearboxStructurePO unitGearboxStructurePO = null;
-            List<UnitGearboxStructurePO> unitGearboxStructurePOList = Lists.newArrayList();
-            for (UnitDto.UnitGearboxStructureDto dto : unitDto.getUnitGearDto().getUnitGearboxStructureDtoList()) {
-                unitGearboxStructurePO = new UnitGearboxStructurePO();
-                BeanUtil.copyProperties(dto, unitGearboxStructurePO);
-                unitGearboxStructurePO.setGearboxCode(unitGearboxPO.getCode());
-                unitGearboxStructurePO.setCreateTime(new Date());
-                unitGearboxStructurePO.setUpdateTime(new Date());
-                unitGearboxStructurePOList.add(unitGearboxStructurePO);
+            // 处理齿轮箱结构
+            if (!CollectionUtils.isEmpty(unitDto.getUnitGearDto().getUnitGearboxStructureDtoList())) {
+                UnitGearboxStructurePO unitGearboxStructurePO = null;
+                List<UnitGearboxStructurePO> unitGearboxStructurePOList = Lists.newArrayList();
+                for (UnitDto.UnitGearboxStructureDto dto : unitDto.getUnitGearDto().getUnitGearboxStructureDtoList()) {
+                    unitGearboxStructurePO = new UnitGearboxStructurePO();
+                    BeanUtil.copyProperties(dto, unitGearboxStructurePO);
+                    unitGearboxStructurePO.setGearboxCode(unitGearboxPO.getCode());
+                    unitGearboxStructurePO.setCreateTime(new Date());
+                    unitGearboxStructurePO.setUpdateTime(new Date());
+                    unitGearboxStructurePOList.add(unitGearboxStructurePO);
+                }
+                UnitGearboxStructurePO po = new UnitGearboxStructurePO();
+                po.setGearboxCode(unitGearboxPO.getCode());
+                unitGearboxStructureMapper.delete(po);
+
+                flg = unitGearboxStructureMapper.insertList(unitGearboxStructurePOList) > 0;
             }
-            UnitGearboxStructurePO po = new UnitGearboxStructurePO();
-            po.setGearboxCode(unitGearboxPO.getCode());
-            unitGearboxStructureMapper.delete(po);
-
-            flg = unitGearboxStructureMapper.insertList(unitGearboxStructurePOList) > 0;
         }
         return flg;
     }