Browse Source

[chg] 优化对null三元判断

wcz 5 years ago
parent
commit
126c61a3f9

+ 4 - 3
lift-business-service/src/main/java/cn/com/ty/lift/business/annualinspection/dto/InspectionResponse.java

@@ -1,6 +1,7 @@
 package cn.com.ty.lift.business.annualinspection.dto;
 
 import cn.com.ty.lift.business.annualinspection.entity.AnnualInspection;
+import cn.com.ty.lift.common.utils.ValuePool;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -56,21 +57,21 @@ public class InspectionResponse extends AnnualInspection{
     private String checkGoverner;
 
     public String getCheckGoverner() {
-        return null != this.getIsCheckGoverner() && 1 == this.getIsCheckGoverner() ? "是" : "否";
+        return ValuePool.nullable(this.getIsCheckGoverner(), 0) == 1 ? "是" : "否";
     }
 
     //是否荷载年检设置(0 否;1 是;默认0)
     private String loadInspection;
 
     public String getLoadInspection() {
-        return this.getLoadInspectionSetting() != null && this.getLoadInspectionSetting() == 1 ? "是" : "否";
+        return ValuePool.nullable(this.getLoadInspectionSetting(), 0) == 1 ? "是" : "否";
     }
 
     //状态(0 待完成;1 已完成;2 超期)
     private String statusDesc;
 
     public String getStatusDesc() {
-        int status = this.getStatus() == null ? 0 : this.getStatus();
+        int status = ValuePool.nullable(this.getStatus(), 0);
         switch (status) {
             case 0:
                 return "待完成";

+ 3 - 3
lift-business-service/src/main/java/cn/com/ty/lift/business/common/CommonController.java

@@ -148,11 +148,11 @@ public class CommonController {
         Validate.notNull(fileSuffix, ValuePool.UPLOAD_FORMAT_ILLEGAL);
         long fileSize = file.getSize();
         log.info("the size of file: {}", fileSize);
-        if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_PICS)) {
+        if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_TYPE_PICS)) {
             Validate.notTrue(fileSize > ValuePool.UPLOAD_MAX_SIZE_PIC, ValuePool.UPLOAD_MAX_SIZE_PIC_DESC);
-        } else if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_FILES)) {
+        } else if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_TYPE_FILES)) {
             Validate.notTrue(fileSize > ValuePool.UPLOAD_MAX_SIZE_FILE, ValuePool.UPLOAD_MAX_SIZE_FILE_DESC);
-        } else if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_VIDEOS)) {
+        } else if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_TYPE_VIDEOS)) {
             Validate.notTrue(fileSize > ValuePool.UPLOAD_MAX_SIZE_VIDEO, ValuePool.UPLOAD_MAX_SIZE_VIDEO_DESC);
         } else {
             throw Validate.validateException(ValuePool.UPLOAD_FORMAT_NOT_SUPPORT);

+ 3 - 2
lift-business-service/src/main/java/cn/com/ty/lift/business/emergency/dto/RepairResponse.java

@@ -5,6 +5,7 @@ import cn.com.ty.lift.business.emergency.entity.ErRecordCost;
 import cn.com.ty.lift.business.emergency.entity.ErRecordImg;
 import cn.com.ty.lift.business.emergency.entity.LiftFault;
 import cn.com.ty.lift.business.evaluation.dao.entity.Evaluation;
+import cn.com.ty.lift.common.utils.ValuePool;
 import cn.hutool.core.date.BetweenFormater;
 import cn.hutool.core.date.DateUtil;
 import lombok.Data;
@@ -145,7 +146,7 @@ public class RepairResponse extends EmergencyRepair{
     //报修来源(1 物业;2 维保;3 物联)
     private String sourceDesc;
     private String getSourceDesc(){
-        int source = this.getSource() == null ? 0 : this.getSource();
+        int source = ValuePool.nullable(this.getSource(), 0);
         switch (source){
             case 1:
                 return "物业";
@@ -161,7 +162,7 @@ public class RepairResponse extends EmergencyRepair{
     //急修原因(0 其他;1 停电;2 故障)
     private String repairReasonDesc;
     public String getRepairReasonDesc(){
-        int repairReason = this.getRepairReason() == null ? 0 : this.getRepairReason();
+        int repairReason = ValuePool.nullable(this.getRepairReason(), 0);
         switch (repairReason){
             case 0:
                 return "其他";

+ 2 - 2
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/entity/model/response/MtPlanResponse.java

@@ -58,8 +58,8 @@ public class MtPlanResponse extends MaintenancePlan {
      * 关联维保记录的状态
      * -3:没有维保记录(可以补录)
      * -2:已补录工单,(没有维保项,可以继续填写)
-     * -1:待审核(通过app端添加的),通过后台添加的,直接 ->3
-     * 3:审核通过或者后台直接添加
+     * -1:待审核(通过app端添加的),通过后台添加的,直接 ->2
+     * 2:审核通过或者后台直接添加
      */
     private String recordStatus;
 }

+ 7 - 6
lift-common/src/main/java/cn.com.ty.lift.common/utils/ValuePool.java

@@ -229,29 +229,29 @@ public interface ValuePool {
      * 图片上传最大大小10M * 1024 * 1024
      */
     long     UPLOAD_MAX_SIZE_PIC                      = 10 << 20;
-    String   UPLOAD_MAX_SIZE_PIC_DESC                 = "文件大小不超过10M";
+    String   UPLOAD_MAX_SIZE_PIC_DESC                 = "图片文件大小不超过10M";
     /**
      * 文件上传最大大小50M * 1024 * 1024
      */
     long     UPLOAD_MAX_SIZE_FILE                     = 50 << 20;
-    String   UPLOAD_MAX_SIZE_FILE_DESC                = "文件大小不超过50M";
+    String   UPLOAD_MAX_SIZE_FILE_DESC                = "常用文件大小不超过50M";
     /**
      * 视频上传最大大小100M * 1024 * 1024
      */
     long     UPLOAD_MAX_SIZE_VIDEO                    = 100 << 20;
-    String   UPLOAD_MAX_SIZE_VIDEO_DESC               = "文件大小不超过100M";
+    String   UPLOAD_MAX_SIZE_VIDEO_DESC               = "视频文件大小不超过100M";
     /**
      * 上传图片文件类型
      */
-    String[] UPLOAD_PICS                              = {".jpg", ".jpeg", ".png", ".bmp", ".gif"};
+    String[] UPLOAD_TYPE_PICS                         = {".jpg", ".jpeg", ".png", ".bmp", ".gif"};
     /**
      * 上传其他文件类型
      */
-    String[] UPLOAD_FILES                             = {".pdf", ".txt", ".rar", ".zip", ".7z", ".xls", ".xlsx", ".doc", ".docx", ".ppt", ".pptx"};
+    String[] UPLOAD_TYPE_FILES                        = {".pdf", ".txt", ".rar", ".zip", ".7z", ".xls", ".xlsx", ".doc", ".docx", ".ppt", ".pptx"};
     /**
      * 上传视频文件类型
      */
-    String[] UPLOAD_VIDEOS                            = {".mov", ".mp4", ".avi", ".mpg", ".mpeg", ".rm", ".rmvb", ".wmv"};
+    String[] UPLOAD_TYPE_VIDEOS                       = {".mov", ".mp4", ".avi", ".mpg", ".mpeg", ".rm", ".rmvb", ".wmv"};
     String   UPLOAD_DATA_MISSING                      = "没有接收到文件数据";
     String   UPLOAD_FAIL                              = "上传文件失败";
     String   UPLOAD_FORMAT_NOT_SUPPORT                = "文件格式暂时不支持";
@@ -291,6 +291,7 @@ public interface ValuePool {
      */
     int      EXCEL_IMPORT_MAX_ROWS_ONETIME            = 5000;
     String   EXCEL_IMPORT_MAX_ROWS_DESC               = "一次性导入不能超过5000条数据";
+
     //三元运算,判断object是否为空,为空返回默认值
     static <T> T nullable(T object, T valueForNull) {
         return Objects.isNull(object) ? valueForNull : object;

+ 9 - 9
lift-enterprise-service/src/main/java/cn/com/ty/lift/enterprise/oa/controller/AttendanceController.java

@@ -164,7 +164,7 @@ public class AttendanceController {
         entity.setTopTimeOt(topTimeOt);
         entity.setDownTimeOt(downTimeOt);
 
-        boolean result = maintenanceCompanyService.saveOrUpdate(entity);
+        boolean result = maintenanceCompanyService.updateById(entity);
         return RestResponse.success(result);
     }
 
@@ -189,46 +189,46 @@ public class AttendanceController {
             String message = Objects.isNull(createDate) ? "" : String.format("(打卡时间:%tF %tT)", createDate, createDate);
             return RestResponse.fail(ValuePool.ATTEND_HAD_CLOCK + message);
         }
-        MaintenanceCompany maintenanceCompany = maintenanceCompanyService.getById(mtCompanyId);
-        Validate.notNull(maintenanceCompany, ValuePool.ATTEND_MAINTAIN_COMPANY_MISSING);
+        MaintenanceCompany company = maintenanceCompanyService.getById(mtCompanyId);
+        Validate.notNull(company, ValuePool.ATTEND_MAINTAIN_COMPANY_MISSING);
 
         LocalTime now = LocalTime.now();
         //状态(是否迟到早退,0:否,1:是)
         switch (type) {
             case 11:
-                LocalTime topTime = maintenanceCompany.getTopTime();
+                LocalTime topTime = company.getTopTime();
                 Validate.notNull(topTime, ValuePool.ATTEND_SET_AM_TIME);
                 //打卡时间比上班时间早-正常,否则迟到
                 entity.setStatus(now.isBefore(topTime) ? 0 : 1);
                 entity.setRemarks(ValuePool.ATTEND_AM_TOP_CLOCK);
                 break;
             case 12:
-                LocalTime downTime = maintenanceCompany.getDownTime();
+                LocalTime downTime = company.getDownTime();
                 Validate.notNull(downTime, ValuePool.ATTEND_SET_AM_TIME);
                 //打卡时间比下班时间晚-正常,否则早退
                 entity.setStatus(now.isAfter(downTime) ? 0 : 1);
                 entity.setRemarks(ValuePool.ATTEND_AM_DOWN_CLOCK);
                 break;
             case 21:
-                LocalTime topTimePm = maintenanceCompany.getTopTimePm();
+                LocalTime topTimePm = company.getTopTimePm();
                 Validate.notNull(topTimePm, ValuePool.ATTEND_SET_PM_TIME);
                 entity.setStatus(now.isBefore(topTimePm) ? 0 : 1);
                 entity.setRemarks(ValuePool.ATTEND_PM_TOP_CLOCK);
                 break;
             case 22:
-                LocalTime downTimePm = maintenanceCompany.getDownTimePm();
+                LocalTime downTimePm = company.getDownTimePm();
                 Validate.notNull(downTimePm, ValuePool.ATTEND_SET_PM_TIME);
                 entity.setStatus(now.isAfter(downTimePm) ? 0 : 1);
                 entity.setRemarks(ValuePool.ATTEND_PM_DOWN_CLOCK);
                 break;
             case 31:
-                LocalTime topTimeOt = maintenanceCompany.getTopTimeOt();
+                LocalTime topTimeOt = company.getTopTimeOt();
                 Validate.notNull(topTimeOt, ValuePool.ATTEND_SET_OT_TIME);
                 entity.setStatus(now.isBefore(topTimeOt) ? 0 : 1);
                 entity.setRemarks(ValuePool.ATTEND_OT_TOP_CLOCK);
                 break;
             case 32:
-                LocalTime downTimeOt = maintenanceCompany.getDownTimeOt();
+                LocalTime downTimeOt = company.getDownTimeOt();
                 Validate.notNull(downTimeOt, ValuePool.ATTEND_SET_OT_TIME);
                 entity.setStatus(now.isAfter(downTimeOt) ? 0 : 1);
                 entity.setRemarks(ValuePool.ATTEND_OT_DOWN_CLOCK);

+ 11 - 10
lift-enterprise-service/src/main/java/cn/com/ty/lift/enterprise/oa/dto/AttendanceResponse.java

@@ -1,5 +1,6 @@
 package cn.com.ty.lift.enterprise.oa.dto;
 
+import cn.com.ty.lift.common.utils.ValuePool;
 import cn.com.ty.lift.enterprise.oa.entity.Attendance;
 import cn.com.ty.lift.enterprise.oa.entity.AttendanceImg;
 import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -74,7 +75,7 @@ public class AttendanceResponse extends Attendance{
 
     public String getRequiredTime() {
         LocalTime localTime;
-        int type = Objects.isNull(this.getType()) ? 0 : this.getType();
+        int type = ValuePool.nullable(this.getType(), 0);
         switch (type) {
             case 11:
                 localTime = this.getTopTime();
@@ -99,7 +100,7 @@ public class AttendanceResponse extends Attendance{
         }
 
         if(Objects.isNull(localTime)){
-            return "";
+            return "--";
         }else{
             return String.format("%tT", localTime);
         }
@@ -111,7 +112,7 @@ public class AttendanceResponse extends Attendance{
     private String typeDesc;
 
     public String getTypeDesc() {
-        int type = this.getType() == null ? 0 : this.getType();
+        int type = ValuePool.nullable(this.getType(), 0);
         switch (type) {
             case 11:
                 return "上午上班打卡";
@@ -126,7 +127,7 @@ public class AttendanceResponse extends Attendance{
             case 32:
                 return "加班下班打卡";
             default:
-                return "";
+                return "--";
         }
     }
 
@@ -134,8 +135,8 @@ public class AttendanceResponse extends Attendance{
 
     //状态(是否迟到早退,0:否,1:是)
     public String getStatusDesc() {
-        int type = Objects.isNull(this.getType()) ? 0 : this.getType();
-        int status = Objects.isNull(this.getStatus()) ? 0: this.getStatus();
+        int type = ValuePool.nullable(this.getType(), 0);
+        int status = ValuePool.nullable(this.getStatus(), 0);
         switch (status) {
             case 0:
                 return "正常";
@@ -145,10 +146,10 @@ public class AttendanceResponse extends Attendance{
                 }else if(type % 2 == 0){
                     return "早退";
                 }else {
-                    return "";
+                    return "--";
                 }
             default:
-                return "";
+                return "--";
         }
     }
 
@@ -156,14 +157,14 @@ public class AttendanceResponse extends Attendance{
     private String clockTime;
     public String getClockDate(){
         if(Objects.isNull(this.getCreateDate())){
-            return "";
+            return "--";
         }else{
             return String.format("%tF", this.getCreateDate());
         }
     }
     public String getClockTime(){
         if(Objects.isNull(this.getCreateDate())){
-            return "";
+            return "--";
         }else{
             return String.format("%tT", this.getCreateDate());
         }

+ 3 - 3
lift-upload/src/main/java/com/controller/common/CommonController.java

@@ -100,11 +100,11 @@ public class CommonController {
         Validate.notNull(fileSuffix, ValuePool.UPLOAD_FORMAT_ILLEGAL);
         long fileSize = file.getSize();
         log.info("the size of file: {}", fileSize);
-        if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_PICS)) {
+        if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_TYPE_PICS)) {
             Validate.notTrue(fileSize > ValuePool.UPLOAD_MAX_SIZE_PIC, ValuePool.UPLOAD_MAX_SIZE_PIC_DESC);
-        } else if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_FILES)) {
+        } else if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_TYPE_FILES)) {
             Validate.notTrue(fileSize > ValuePool.UPLOAD_MAX_SIZE_FILE, ValuePool.UPLOAD_MAX_SIZE_FILE_DESC);
-        } else if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_VIDEOS)) {
+        } else if (StrUtil.equalsAny(fileSuffix, ValuePool.UPLOAD_TYPE_VIDEOS)) {
             Validate.notTrue(fileSize > ValuePool.UPLOAD_MAX_SIZE_VIDEO, ValuePool.UPLOAD_MAX_SIZE_VIDEO_DESC);
         } else {
             throw Validate.validateException(ValuePool.UPLOAD_FORMAT_NOT_SUPPORT);