Browse Source

Merge branch 'wanghaicheng' of lift-manager/lift-server into develop

wanghaicheng 5 years ago
parent
commit
6025a2d73c

+ 4 - 3
lift-business-service/src/main/java/cn/com/ty/lift/business/library/controller/LiftController.java

@@ -175,9 +175,9 @@ public class LiftController {
      * @date 2019/11/27 10:03 AM
      */
     @PostMapping("add")
-    @Validation(fields = {"mtCompanyId", "source", "mark"})
     public RestResponse add(@Val @RequestBody LiftExtensionRequest request) {
-        Validator.valid(request.getLift(), "registrationCode");
+        Validator.valid(request,"mtCompanyId", "source", "mark","workerId","lift");
+        liftService.validLiftRequest(request.getLift());
         return liftService.add(request);
     }
 
@@ -188,9 +188,10 @@ public class LiftController {
      * @date 2019/11/27 10:03 AM
      */
     @PostMapping("modify")
-    @Validation(fields = {"mtCompanyId"})
     public RestResponse modify(@Val @RequestBody LiftRequest request) {
+        Validator.valid(request,"mtCompanyId" ,"workerId","lift");
         Validator.valid(request.getLift(), "id");
+        liftService.validLiftRequest(request.getLift());
        return liftService.modify(request);
     }
 

+ 32 - 3
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/entity/Lift.java

@@ -7,13 +7,13 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.NotNull;
+import javax.validation.constraints.*;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 
 /**
  * 实体类 - 表:lift 电梯
+ *
  * @author bieao
  * @since 2019-11-25 17:37:16
  */
@@ -24,7 +24,7 @@ public class Lift extends BaseEntity {
     /**
      * 电梯id
      */
-    @TableId(value = "id",type = IdType.ID_WORKER)
+    @TableId(value = "id", type = IdType.ID_WORKER)
     @NotNull(message = "电梯id不能为空")
     private Long id;
 
@@ -39,12 +39,18 @@ public class Lift extends BaseEntity {
      * 电梯类别(1:曳引梯;2:液压梯;3:杂物梯;4:自动扶梯;5:自动人行道)
      */
     @FieldName(name = "电梯类别")
+    @Min(value = 1, message = "电梯类别错误")
+    @Max(value = 5, message = "电梯类别错误")
+    @NotNull(message = "电梯类别不能为空")
     private Integer category;
 
     /**
      * 电梯类型(1:直梯;2:扶梯)
      */
     @FieldName(name = "电梯类型")
+    @Min(value = 1, message = "电梯类型错误")
+    @Max(value = 2, message = "电梯类型错误")
+    @NotNull(message = "电梯类型不能为空")
     private Integer liftType;
 
     /**
@@ -69,18 +75,23 @@ public class Lift extends BaseEntity {
      * 设备用途(11:货梯;12:客梯;13:医梯;14:观光梯;15:杂物梯;16:别墅梯;21:扶梯;22:人行道)
      */
     @FieldName(name = "设备用途")
+    @Min(value = 11, message = "设备用途错误")
+    @Max(value = 22, message = "设备用途错误")
+    @NotNull(message = "设备用途不能为空")
     private Integer deviceUsage;
 
     /**
      * 电梯品牌
      */
     @FieldName(name = "电梯品牌")
+    @NotBlank(message = "电梯品牌不能为空")
     private String liftBrand;
 
     /**
      * 安装单位
      */
     @FieldName(name = "安装单位")
+    @NotBlank(message = "安装单位不能为空")
     private String installCompany;
 
     /**
@@ -111,54 +122,65 @@ public class Lift extends BaseEntity {
      * 电梯载重
      */
     @FieldName(name = "电梯载重")
+    @NotNull(message = "电梯载重不能为空")
     private Integer ratedLoad;
 
     /**
      * 提升高度m
      */
     @FieldName(name = "提升高度")
+    @NotNull(message = "提升高度不能为空")
     private BigDecimal promoteHeight;
 
     /**
      * 梯级宽度
      */
     @FieldName(name = "梯级宽度")
+    @NotNull(message = "梯级宽度不能为空")
     private BigDecimal stepWidth;
 
     /**
      * 人行道长度m
      */
     @FieldName(name = "人行道长度")
+    @NotNull(message = "人行道长度不能为空")
     private BigDecimal sidewalkLength;
 
     /**
      * 倾斜角度°
      */
     @FieldName(name = "倾斜角度")
+    @NotNull(message = "倾斜角度不能为空")
     private BigDecimal tiltAngle;
 
     /**
      * 电动机功率kw
      */
     @FieldName(name = "电动机功率")
+    @NotNull(message = "电动机功率不能为空")
     private BigDecimal motorPower;
 
     /**
      * 额定速度m/s
      */
     @FieldName(name = "额定速度")
+    @NotNull(message = "额定速度不能为空")
     private BigDecimal ratedSpeed;
 
     /**
      * 层站门
      */
     @FieldName(name = "层站门")
+    @NotBlank(message = "层站门不能为空")
     private String layerStationDoor;
 
     /**
      * 安全钳类型(1:瞬时式安全钳;2:渐进式安全钳)
      */
     @FieldName(name = "安全钳类型")
+    @Min(value = 1, message = "安全钳类型错误")
+    @Max(value = 2, message = "安全钳类型错误")
+    @NotNull(message = "安全钳类型不能为空")
     private Integer clampType;
 
     /**
@@ -171,6 +193,7 @@ public class Lift extends BaseEntity {
      * 设备使用地点
      */
     @FieldName(name = "设备使用地点")
+    @NotBlank(message = "设备安装地址不能为空")
     private String devicePosition;
 
     /**
@@ -195,6 +218,7 @@ public class Lift extends BaseEntity {
      * 油缸型式
      */
     @FieldName(name = "油缸型式")
+    @NotBlank(message = "油缸型式不能为空")
     private String cylinderType;
 
     /**
@@ -207,12 +231,14 @@ public class Lift extends BaseEntity {
      * 顶升型式
      */
     @FieldName(name = "顶升型式")
+    @NotNull(message = "顶升型式不能为空")
     private Integer topType;
 
     /**
      * 控制方式
      */
     @FieldName(name = "控制方式")
+    @NotNull(message = "控制方式不能为空")
     private String controlType;
 
     /**
@@ -237,6 +263,7 @@ public class Lift extends BaseEntity {
      * 单位设备编号
      */
     @FieldName(name = "单位设备编号")
+    @NotBlank(message = "设备内部编号不能为空")
     private String useCompanyCode;
 
     /**
@@ -261,6 +288,7 @@ public class Lift extends BaseEntity {
      * 设备安装日期
      */
     @FieldName(name = "设备安装日期")
+    @NotNull(message = "设备安装日期不能为空")
     private LocalDate installDate;
 
     /**
@@ -273,6 +301,7 @@ public class Lift extends BaseEntity {
      * 年检日期
      */
     @FieldName(name = "年检日期")
+    @NotNull(message = "年检日期不能为空")
     private LocalDate annualInspectionDate;
 
     /**

+ 5 - 4
lift-business-service/src/main/java/cn/com/ty/lift/business/library/dao/entity/model/request/LiftExtensionRequest.java

@@ -16,6 +16,7 @@ public class LiftExtensionRequest {
     /**
      * 维保工
      */
+    @NotNull(message = "维保工不能为空")
     private Long workerId;
 
     /**
@@ -26,19 +27,19 @@ public class LiftExtensionRequest {
     /**
      * 新增电梯来源入口 (0:从电梯管理新增,1:从项目管理中新增)
      */
-    @NotNull(message = "notEmpty")
+    @NotNull(message = "电梯来源入口不能为空")
     private String source;
 
     /**
      * 新增标记 (0:新增,1:查询后带入)
      */
-    @NotNull(message = "notEmpty")
+    @NotNull(message = "新增标记不能为空")
     private String mark;
 
     /**
      * 维保公司ID
      */
-    @NotNull(message = "notEmpty")
+    @NotNull(message = "维保公司ID不能为空")
     private Long mtCompanyId;
 
     /**
@@ -49,6 +50,6 @@ public class LiftExtensionRequest {
     /**
      * 电梯
      */
-    @NotNull(message = "notEmpty")
+    @NotNull(message = "电梯信息不能为空")
     private Lift lift;
 }

+ 35 - 2
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/LiftService.java

@@ -33,6 +33,8 @@ import cn.com.ty.lift.common.model.PushUserInfo;
 import cn.com.ty.lift.common.utils.DateUtils;
 import cn.com.ty.lift.common.utils.SendMessageUtil;
 import cn.com.ty.lift.common.verify.Validate;
+import cn.com.ty.lift.common.verify.ValidateException;
+import cn.com.ty.lift.common.verify.Validator;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
@@ -101,7 +103,7 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
     @Resource
     private MaintenancePlanService maintenancePlanService;
 
-    private Map<String, String> headsMap = new LinkedHashMap<String,String>() {{
+    private Map<String, String> headsMap = new LinkedHashMap<String, String>() {{
         put("liftCode", "电梯号");
         put("registrationCode", "注册代码");
         put("liftBrand", "电梯品牌");
@@ -480,7 +482,7 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
         return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
     }
 
-    public List<Map<String,String>> exportList(List<String> ids){
+    public List<Map<String, String>> exportList(List<String> ids) {
         return baseMapper.exportList(ids);
     }
 
@@ -736,4 +738,35 @@ public class LiftService extends ServiceImpl<LiftMapper, Lift> {
         return true;
     }
 
+    /**
+     * 检查新增和编辑电梯时必传的属性
+     *
+     * @param lift 电梯信息
+     */
+    public void validLiftRequest(Lift lift) {
+        Validator.valid(lift, "registrationCode", "category", "liftType", "deviceUsage", "liftBrand",
+                "devicePosition", "useCompanyCode", "installDate", "annualInspectionDate");
+
+        if (lift.getInstallDate().compareTo(lift.getAnnualInspectionDate()) > 0) {
+            throw new ValidateException("设备年检日期不能在安装日期之前");
+        }
+
+        switch (lift.getCategory()) {
+            case 1:
+                Validator.valid(lift, "layerStationDoor", "clampType", "ratedLoad", "promoteHeight", "ratedSpeed");
+                break;
+            case 2:
+                Validator.valid(lift, "ratedLoad", "promoteHeight", "motorPower", "ratedSpeed", "layerStationDoor",
+                        "clampType", "controlType", "cylinderNum", "cylinderType", "topType");
+                break;
+            case 3:
+                Validator.valid(lift, "ratedLoad", "promoteHeight", "motorPower", "ratedSpeed", "layerStationDoor", "clampType");
+                break;
+            case 4:
+                Validator.valid(lift, "ratedLoad", "promoteHeight", "stepWidth", "tiltAngle");
+                break;
+            case 5:
+                Validator.valid(lift, "ratedLoad", "promoteHeight", "stepWidth", "tiltAngle", "sidewalkLength");
+        }
+    }
 }

+ 2 - 2
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/controller/MaintenanceRecordController.java

@@ -415,7 +415,7 @@ public class MaintenanceRecordController {
 
     @PostMapping("export")
     @Validation(fields = {"recordIds"})
-    public void export(@Val @RequestBody MtRecordRequest mtRecordRequest, HttpServletResponse response) {
-        maintenanceRecordService.export(mtRecordRequest, response);
+    public RestResponse<?> export(@Val @RequestBody MtRecordRequest mtRecordRequest) {
+       return RestResponse.success(maintenanceRecordService.export(mtRecordRequest));
     }
 }

+ 26 - 41
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/service/MaintenanceRecordService.java

@@ -21,12 +21,14 @@ import cn.com.ty.lift.business.project.dao.entity.Project;
 import cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance;
 import cn.com.ty.lift.business.project.service.ProjectLiftRelevanceService;
 import cn.com.ty.lift.business.project.service.ProjectService;
+import cn.com.ty.lift.common.aliservice.aliyunoss.AliyunOSS;
 import cn.com.ty.lift.common.constants.CommonEnum;
 import cn.com.ty.lift.common.utils.DateUtils;
 import cn.com.ty.lift.common.utils.MapHelper;
 import cn.com.ty.lift.common.utils.ValuePool;
 import cn.com.ty.lift.common.verify.Val;
 import cn.com.ty.lift.common.verify.Validate;
+import cn.com.ty.lift.common.verify.ValidateException;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.IterUtil;
@@ -843,7 +845,7 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
         return baseMapper.pageByLift(request.getPage(), request);
     }
 
-    public void export(MtRecordRequest mtRecordRequest, HttpServletResponse response) {
+    public String export(MtRecordRequest mtRecordRequest) {
         Map<String, String> headerAlias = new LinkedHashMap<>();
         headerAlias.put("projectName", "项目名称");
         headerAlias.put("useCompanyCode", "梯号");
@@ -907,62 +909,45 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
                 projectName = StrUtil.isNotEmpty(projectName) ? projectName.replace(illegalChars, "-") : "[项目]";
                 registrationCode = StrUtil.isNotEmpty(registrationCode) ? registrationCode.replace(illegalChars, "-") : "[电梯注册代码]";
                 //保养单及图片文件夹 dir/i.ProjectName-RegistrationCode/
-//                String imgDir = StrUtil.format("{}{}{}.{}-{}{}", dir, File.separator, (i + 1), projectName, registrationCode, File.separator);
+                String imgDir = StrUtil.format("{}{}{}.{}-{}{}", dir, File.separator, (i + 1), projectName, registrationCode, File.separator);
                 //生成维保图片
-//                List<MtRecordImg> mtRecordImgs = mtRecordResponse.getMtRecordImgs();
-//                List<MtRecordImg> imgs = mtRecordImgs.stream().filter(img -> mtRecordResponse.getId().equals(img.getMtRecordId())).collect(Collectors.toList());
-//                if (IterUtil.isNotEmpty(imgs)) {
-//                    for (int n = 0; n < imgs.size(); n++) {
-//                        String imgUrl = imgs.get(n).getImgUrl();
-//                        if (StrUtil.isNotEmpty(imgUrl)) {
-//                            log.info("imgUrl: {}", imgUrl);
-//                            String filename = imgDir + StrUtil.format("维保图片{}.jpg", (n + 1));
-//                            log.info("生成维保图片文件: {}", filename);
-//                            HttpUtil.downloadFile(imgUrl, filename);
-//                        }
-//                    }
-//                }
+                List<MtRecordImg> mtRecordImgs = mtRecordResponse.getMtRecordImgs();
+                List<MtRecordImg> imgs = mtRecordImgs.stream().filter(img -> mtRecordResponse.getId().equals(img.getMtRecordId())).collect(Collectors.toList());
+                if (IterUtil.isNotEmpty(imgs)) {
+                    for (int n = 0; n < imgs.size(); n++) {
+                        String imgUrl = imgs.get(n).getImgUrl();
+                        if (StrUtil.isNotEmpty(imgUrl)) {
+                            log.info("imgUrl: {}", imgUrl);
+                            String filename = imgDir + StrUtil.format("维保图片{}.jpg", (n + 1));
+                            log.info("生成维保图片文件: {}", filename);
+                            HttpUtil.downloadFile(imgUrl, filename);
+                        }
+                    }
+                }
                 //生成保养单
-                String maintenanceExcelDir = StrUtil.format("{}{}{}.{}-{}{}", dir, File.separator, (i + 1), projectName, registrationCode, "保养单.xlsx");
+                String maintenanceExcelDir = imgDir + "保养单.xlsx";
                 log.info("生成保养单: {}", maintenanceExcelDir);
                 excelWriter(mtRecordResponse, maintenanceExcelDir);
             }
             //压缩文件夹
             log.info("生成zipFile路径: {}", zip);
             ZipUtil.zip(dir, zip);
+            //上传文件到阿里云,并返回路径给前端
+            return AliyunOSS.me().putObject("maintenance/export/zip/" + generateCode + ".zip", readInputStream(new FileInputStream(new File(zip))));
         } catch (Exception e) {
-            FileUtil.del(zipFile);
-            FileUtil.del(baseDir);
             log.error("生成保养文件失败", e);
             throw Validate.validateException("生成保养文件失败");
-        }
-        //下载压缩文件
-        if (FileUtil.exist(zipFile)) {
-            // 设置强制下载不打开, ZIP的application/x-zip-compressed
-            response.setContentType("application/force-download");
-            // 设置文件名
-            response.addHeader("Content-Disposition", "attachment;fileName=" + zipFile.getName());
-            byte[] buffer = new byte[1024];
-            try (FileInputStream fis = new FileInputStream(zipFile);
-                 BufferedInputStream bis = new BufferedInputStream(fis)) {
-                OutputStream os = response.getOutputStream();
-                int i;
-                while ((i = bis.read(buffer)) != -1) {
-                    os.write(buffer, 0, i);
-                }
-            } catch (Exception e) {
-                log.error("下载保养文件失败", e);
-                throw Validate.validateException("下载保养文件失败");
-            } finally {
-                //删除临时根目录和zip文件
-                FileUtil.del(zipFile);
-                FileUtil.del(baseDir);
-            }
+        } finally {
+            FileUtil.del(zipFile);
+            FileUtil.del(baseDir);
         }
     }
 
     private MtRecordResponse getMtRecordResponse(@RequestBody @Val MtRecordRequest request) {
         MtRecordResponse entity = this.infoById(request);
+        if (entity == null) {
+            throw new ValidateException("维保记录不存在");
+        }
         String repairDuration = this.getRepairDuration(entity.getRepairDiff());
         entity.setRepairDuration(repairDuration);
         Validate.notNull(entity, ValuePool.MAINTENANCE_RECORD_NOT_EXIST);