Browse Source

Merge branch 'feature-bieao' of lift-manager/lift-server into develop

bieao 5 years ago
parent
commit
1f782867b3

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

@@ -197,12 +197,12 @@ public class LiftController {
     /**
      * @param request idList 电梯id列表
      * @return 1.成功, 0.失败, 消息描述
-     * @description 更新电梯状态为停保
+     * @description 更新电梯状态为停保或恢复为正常
      * @date 2019/12/5 5:24 PM
      */
-    @PostMapping("stop/insurance")
-    public RestResponse stopInsurance(@RequestBody PlatformCompanyRequest request) {
-        return platformService.stopInsurance(request);
+    @PostMapping("stop/recover")
+    public RestResponse stopOrRecover(@RequestBody PlatformCompanyRequest request) {
+        return platformService.stopOrRecover(request);
     }
 
     /**

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

@@ -243,4 +243,9 @@ public class Lift extends BaseEntity {
      * 设备类型
      */
     private String deviceType;
+
+    /**
+     * 电梯状态 1:弃用 2:正常
+     */
+    private String liftStatus;
 }

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

@@ -29,4 +29,9 @@ public class PlatformCompanyRequest {
      */
     @NotNull(message = "notEmpty")
     private Long liftId;
+
+    /**
+     * 0:恢复,1:停保
+     */
+    private String operate;
 }

+ 10 - 25
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/LiftService.java

@@ -13,8 +13,6 @@ import cn.com.ty.lift.business.library.dao.entity.model.request.ProjectLiftReque
 import cn.com.ty.lift.business.library.dao.entity.model.response.LiftExtendResponse;
 import cn.com.ty.lift.business.library.dao.entity.model.response.LiftResponse;
 import cn.com.ty.lift.business.library.dao.mapper.LiftMapper;
-import cn.com.ty.lift.business.maintenance.dao.entity.MaintenanceCompany;
-import cn.com.ty.lift.business.maintenance.service.MaintenanceService;
 import cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance;
 import cn.com.ty.lift.business.project.service.ProjectLiftRelevanceService;
 import cn.com.ty.lift.common.base.ExportRequest;
@@ -58,9 +56,6 @@ public class LiftService extends ServiceImpl<LiftMapper,Lift> {
     @Resource
     private ProjectLiftRelevanceService projectRelevanceService;
 
-    @Resource
-    private MaintenanceService maintenanceService;
-
     private Map<String, String> paramMap = new HashMap<String, String>() {{
         put("liftCode", "电梯号");
         put("registrationCode", "注册代码");
@@ -122,7 +117,8 @@ public class LiftService extends ServiceImpl<LiftMapper,Lift> {
      */
     public RestResponse preJudgment(Long mtCompanyId, String registrationCode) {
         //查询电梯表是否有该电梯
-        Long liftId = findLiftExist(registrationCode);
+        Optional<Lift> lift = getOne(registrationCode, null);
+        Long liftId = lift.map(Lift::getId).orElse(null);
         if (ObjectUtil.isNotEmpty(liftId)) {
             Map<String, Object> paramMap = new HashMap<>(2);
             paramMap.put("liftId", liftId);
@@ -140,33 +136,22 @@ public class LiftService extends ServiceImpl<LiftMapper,Lift> {
         }
     }
 
-    /**
-     * @param mtCompanyId 维保公司id
-     * @return 比较结果
-     * @description 判断当前公司台量是否大于企业设置的台量
-     * @date 2019/12/12 5:27 PM
-     */
-    public boolean judge(Long mtCompanyId) {
-        //查询维保公司设置的最大电梯台量
-        MaintenanceCompany company = maintenanceService.selectById(mtCompanyId);
-        Integer limitedNum = company.getLimitedNum();
-        //获取该公司企业电梯关联表的实际电梯台量
-        Integer currentNum = platformService.countLiftNum(mtCompanyId);
-        return currentNum >= limitedNum;
-    }
-
     /**
      * @param registrationCode 电梯注册代码
      * @return 电梯id
      * @description 查询电梯是否存在
      * @date 2019/12/20 11:04 AM
      */
-    public Long findLiftExist(String registrationCode) {
+    public Optional<Lift> getOne(String registrationCode, Long liftId) {
         QueryWrapper<Lift> queryWrapper = new QueryWrapper<>();
         LambdaQueryWrapper<Lift> lambdaQueryWrapper = queryWrapper.lambda();
-        lambdaQueryWrapper.eq(Lift::getRegistrationCode, registrationCode);
-        Lift lift = getOne(lambdaQueryWrapper);
-        return Optional.ofNullable(lift).map(Lift::getId).orElse(null);
+        if (ObjectUtil.isNotEmpty(liftId)) {
+            lambdaQueryWrapper.eq(Lift::getId, liftId);
+        }
+        if (StrUtil.isNotEmpty(registrationCode)) {
+            lambdaQueryWrapper.eq(Lift::getRegistrationCode, registrationCode);
+        }
+        return Optional.ofNullable(getOne(lambdaQueryWrapper));
     }
 
     /**

+ 24 - 17
lift-business-service/src/main/java/cn/com/ty/lift/business/library/service/PlatformCompanyLiftRelevanceService.java

@@ -1,12 +1,14 @@
 package cn.com.ty.lift.business.library.service;
 
 import cn.com.ty.lift.business.framework.util.MessageUtils;
+import cn.com.ty.lift.business.library.dao.entity.Lift;
 import cn.com.ty.lift.business.library.dao.entity.PlatformCompanyLiftRelevance;
 import cn.com.ty.lift.business.library.dao.entity.model.request.PlatformCompanyBatchRequest;
 import cn.com.ty.lift.business.library.dao.entity.model.request.SelectBatchPlatformCompanyRequest;
 import cn.com.ty.lift.business.library.dao.entity.model.request.PlatformCompanyRequest;
 import cn.com.ty.lift.business.library.dao.mapper.PlatformCompanyLiftRelevanceMapper;
 import cn.com.ty.lift.business.maintenance.service.MaintenancePlanService;
+import cn.com.ty.lift.business.maintenance.service.MaintenanceService;
 import cn.com.ty.lift.business.project.dao.entity.Project;
 import cn.com.ty.lift.business.project.dao.mapper.ProjectMapper;
 import cn.com.ty.lift.common.constants.CommonEnum;
@@ -21,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * @author bieao
@@ -42,6 +45,9 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
     @Resource
     private MaintenancePlanService maintenancePlanService;
 
+    @Resource
+    private MaintenanceService maintenanceService;
+
     /**
      * @param id          电梯id
      * @param mtCompanyId 公司id
@@ -77,7 +83,7 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
      * @description 查询维保公司下的实际电梯台量
      * @date 2019/12/12 5:16 PM
      */
-    public Integer countLiftNum(Long mtCompanyId) {
+    public int countLiftNum(Long mtCompanyId) {
         QueryWrapper<PlatformCompanyLiftRelevance> queryWrapper = new QueryWrapper<>();
         LambdaQueryWrapper<PlatformCompanyLiftRelevance> lambdaQueryWrapper = queryWrapper.lambda();
         lambdaQueryWrapper.eq(PlatformCompanyLiftRelevance::getMtCompanyId, mtCompanyId);
@@ -109,7 +115,7 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
         switch (operate) {
             //恢复服务
             case "1":
-                boolean judgeResult = liftService.judge(request.getMtCompanyId());
+                boolean judgeResult = maintenanceService.judge(request.getMtCompanyId());
                 if (!judgeResult) {
                     return RestResponse.fail(MessageUtils.get("msg.limit.num"));
                 }
@@ -148,22 +154,26 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
      * @param request mtCompanyId 公司id
      * @param request liftId 电梯id
      * @return 1.成功, 0.失败, 消息描述
-     * @description 更新电梯状态为停保, 并清除维保计划
+     * @description 更新电梯状态为停保或恢复为正常, 并清除维保计划
      * @date 2019/12/5 5:24 PM
      */
     @Transactional(rollbackFor = Exception.class)
-    public RestResponse stopInsurance(PlatformCompanyRequest request) {
+    public RestResponse stopOrRecover(PlatformCompanyRequest request) {
         PlatformCompanyLiftRelevance entry = new PlatformCompanyLiftRelevance();
         entry.setId(request.getRelevanceId());
-        entry.setLiftCompanyStatus(CommonEnum.LiftStatus.STOP_INSURANCE.getCode());
-        boolean result = updateById(entry);
-        if (!result) {
-            return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
-        }
-        //清除维保计划
-        boolean ret = maintenancePlanService.cleanPlan(request.getMtCompanyId(), request.getLiftId());
-        if (!ret) {
-            return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
+        //恢复电梯为正常状态
+        if ("0".equals(request.getOperate())) {
+            Optional<Lift> lift = liftService.getOne(null, request.getLiftId());
+            String liftStatus = lift.map(Lift::getLiftStatus).orElse(null);
+            // 1:弃用 2:正常
+            if ("1".equals(liftStatus)) return RestResponse.fail(MessageUtils.get("msg.error.lift.status"));
+            entry.setLiftCompanyStatus(CommonEnum.LiftStatus.NORMAL.getCode());
+            updateById(entry);
+        } else {
+            entry.setLiftCompanyStatus(CommonEnum.LiftStatus.STOP_INSURANCE.getCode());
+            updateById(entry);
+            //清除维保计划
+            maintenancePlanService.cleanPlan(request.getMtCompanyId(), request.getLiftId());
         }
         return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
     }
@@ -192,10 +202,7 @@ public class PlatformCompanyLiftRelevanceService extends ServiceImpl<PlatformCom
             return RestResponse.fail(MessageUtils.get("msg.modify.batch.fail"));
         }
         //批量清除维保计划
-        boolean ret = maintenancePlanService.removeMaintenancePlan(request.getMtCompanyId(), request.getLiftList());
-        if (!ret) {
-            return RestResponse.fail(MessageUtils.get("msg.modify.batch.fail"));
-        }
+        maintenancePlanService.removeMaintenancePlan(request.getMtCompanyId(), request.getLiftList());
         return RestResponse.success(null, MessageUtils.get("msg.modify.batch.success"));
     }
 

+ 12 - 27
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/service/MaintenancePlanService.java

@@ -147,7 +147,7 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
         LocalDate firstTime = request.getFirstTime();
         List<MaintenancePlan> planList = new ArrayList<>();
         plans.forEach(plan -> {
-            Optional<Project> project = projects.stream().filter(p -> (p.getId().equals(plan.getProjectId()))).findFirst();
+            Optional<Project> project = projects.stream().filter(p -> p.getId().equals(plan.getProjectId())).findFirst();
             if (project.isPresent()) {
                 Project entry = project.get();
                 planList.addAll(generatePlan(plan, periods, interval, firstTime, entry.getEndDate()));
@@ -192,7 +192,7 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
         //返回维保计划列表
         List<MaintenancePlan> planList = new ArrayList<>();
         int times = getTimes(interval, beginTime, endTime);
-        log.info("总期数{},从第几期开始{},间隔{},开始时间{},结束时间{}", times, periods, interval, beginTime, endTime);
+        log.info("总期数:{},从第{}期开始,保养间隔:{}天,开始时间:{},结束时间:{}", times + 1, periods, interval, beginTime, endTime);
         int length = maintenanceType.length;
         for (int i = 0; i <= times; i++) {
             MaintenancePlan entry = new MaintenancePlan();
@@ -216,7 +216,7 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
                 entry.setPlanDate(planDate);
             }
             entry.setCount(periods);
-            log.info("每期期数{},类型{},计划时间{}", periods, entry.getType(), entry.getPlanDate());
+            log.info("第{}期,类型:{},计划时间:{}", periods, entry.getType(), entry.getPlanDate());
             periods++;
             planList.add(entry);
         }
@@ -256,24 +256,6 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
         return list(lambdaQueryWrapper);
     }
 
-    /**
-     * @param mtCompanyId 公司id
-     * @param liftId 电梯id
-     * @param periods 期数
-     * @return 维保计划
-     * @description 获取当前期数的计划时间
-     * @date 2020/1/9 5:06 下午
-     */
-    public MaintenancePlan detail(Long mtCompanyId, Long liftId, Integer periods){
-        QueryWrapper<MaintenancePlan> queryWrapper = new QueryWrapper<>();
-        LambdaQueryWrapper<MaintenancePlan> lambdaQueryWrapper = queryWrapper.lambda();
-        lambdaQueryWrapper.eq(MaintenancePlan::getMtCompanyId, mtCompanyId);
-        lambdaQueryWrapper.eq(MaintenancePlan::getLiftId, liftId);
-        lambdaQueryWrapper.eq(MaintenancePlan::getCount, periods);
-        MaintenancePlan plan = getOne(lambdaQueryWrapper);
-        return plan;
-    }
-
     /**
      * @param request 修改维保计划请求
      * @return 是否修改成功
@@ -284,12 +266,10 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
     public boolean modifyPlan(MaintenanceModifyRequest request) {
         //获取公司id
         Long mtCompanyId = request.getMtCompanyId();
-        //获取公司id
-        Long projectId = request.getProjectId();
-        //获取公司id
+        //获取电梯id
         Long liftId = request.getLiftId();
         MaintenancePlan plan = new MaintenancePlan();
-        plan.setProjectId(projectId);
+        plan.setProjectId(request.getProjectId());
         plan.setMtCompanyId(mtCompanyId);
         plan.setLiftId(liftId);
         plan.setWorkerId(request.getWorkerId());
@@ -321,8 +301,13 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
         } else if (isNull && ObjectUtil.isNotEmpty(updateInterval)) {
             //获取当前期数后的维保计划列表,并清除计划
             planList = findPlanList(mtCompanyId, liftId, periods);
-            MaintenancePlan entity = detail(request.getMtCompanyId(), request.getLiftId(), request.getPeriods());
-            LocalDate planDate = entity.getPlanDate();
+            LocalDate planDate;
+            Optional<MaintenancePlan> planOptional = planList.stream()
+                    .filter(entity -> entity.getCount().equals(periods)).findFirst();
+            if (planOptional.isPresent()) {
+                MaintenancePlan maintenancePlan = planOptional.get();
+                planDate = maintenancePlan.getPlanDate();
+            } else return false;
             removeByIds(planList.stream().map(MaintenancePlan::getId).collect(Collectors.toList()));
             //更新项目电梯关联表保养间隔
             projectLiftRelevanceService.modifyPlanInterval(request.getRelevanceId(), updateInterval);

+ 15 - 6
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/service/MaintenanceService.java

@@ -1,5 +1,6 @@
 package cn.com.ty.lift.business.maintenance.service;
 
+import cn.com.ty.lift.business.library.service.PlatformCompanyLiftRelevanceService;
 import cn.com.ty.lift.business.maintenance.dao.entity.MaintenanceCompany;
 import cn.com.ty.lift.business.maintenance.dao.mapper.MaintenanceCompanyMapper;
 import org.springframework.stereotype.Service;
@@ -17,13 +18,21 @@ public class MaintenanceService {
     @Resource
     private MaintenanceCompanyMapper maintenanceCompanyMapper;
 
+    @Resource
+    private PlatformCompanyLiftRelevanceService platformService;
+
     /**
-     * @param id 公司id
-     * @return MaintenanceCompany
-     * @description 查询维保公司信息
-     * @date 2019/12/12 4:47 PM
+     * @param mtCompanyId 维保公司id
+     * @return 比较结果
+     * @description 判断当前公司台量是否大于企业设置的台量
+     * @date 2019/12/12 5:27 PM
      */
-    public MaintenanceCompany selectById(Long id) {
-        return maintenanceCompanyMapper.selectById(id);
+    public boolean judge(Long mtCompanyId) {
+        //查询维保公司设置的最大电梯台量
+        MaintenanceCompany company = maintenanceCompanyMapper.selectById(mtCompanyId);
+        int limitedNum = company.getLimitedNum();
+        //获取该公司企业电梯关联表的实际电梯台量
+        int currentNum = platformService.countLiftNum(mtCompanyId);
+        return currentNum >= limitedNum;
     }
 }

+ 4 - 4
lift-business-service/src/main/java/cn/com/ty/lift/business/project/service/ProjectLiftRelevanceService.java

@@ -88,7 +88,7 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
      * @description 批量移动电梯
      * @date 2020/1/7 7:57 下午
      */
-    public boolean move(LiftBatchMoveRequest request){
+    public boolean move(LiftBatchMoveRequest request) {
         List<ProjectLiftRelevance> list = request.getList();
         list.forEach(entry -> entry.setProjectId(request.getProjectId()));
         return updateBatchById(list, list.size());
@@ -146,7 +146,7 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
 
     /**
      * @param mtCompanyId 公司id
-     * @param liftId 电梯id
+     * @param liftId      电梯id
      * @return ProjectLiftRelevance 项目电梯记录
      * @description 根据公司id和电梯id查询项目电梯记录
      * @date 2020/1/8 9:59 上午
@@ -156,13 +156,13 @@ public class ProjectLiftRelevanceService extends ServiceImpl<ProjectLiftRelevanc
         LambdaQueryWrapper<ProjectLiftRelevance> lambdaQueryWrapper = queryWrapper.lambda();
         lambdaQueryWrapper.eq(ProjectLiftRelevance::getMtCompanyId, mtCompanyId);
         lambdaQueryWrapper.eq(ProjectLiftRelevance::getLiftId, liftId);
-        ProjectLiftRelevance entry=  getOne(lambdaQueryWrapper);
+        ProjectLiftRelevance entry = getOne(lambdaQueryWrapper);
         return ObjectUtil.isNotEmpty(entry) ? entry : null;
     }
 
     /**
      * @param relevanceId 项目电梯关联id
-     * @param interval 保养间隔
+     * @param interval    保养间隔
      * @description 根据项目电梯关联id和保养间隔修改项目电梯关联保养间隔
      * @date 2020/1/8 9:59 上午
      */

+ 0 - 1
lift-business-service/src/main/java/cn/com/ty/lift/business/project/service/ProjectService.java

@@ -5,7 +5,6 @@ import cn.com.ty.lift.business.framework.util.MessageUtils;
 import cn.com.ty.lift.business.project.dao.entity.*;
 import cn.com.ty.lift.business.project.dao.entity.model.ProjectImportModel;
 import cn.com.ty.lift.business.maintenance.dao.entity.MaintenancePlan;
-import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceGenerateRequest;
 import cn.com.ty.lift.business.project.dao.entity.Project;
 import cn.com.ty.lift.business.project.dao.entity.ProjectHistory;
 import cn.com.ty.lift.business.project.dao.entity.ProjectUser;

+ 2 - 1
lift-business-service/src/main/resources/locale/response.properties

@@ -20,4 +20,5 @@ msg.pre.judge=\u524D\u7F6E\u6821\u9A8C\u901A\u8FC7
 notEmpty={0}\u4E0D\u80FD\u4E3A\u7A7A
 msg.project.status.update=\u9879\u76EE\u9501\u5B9A\u72B6\u6001\u66F4\u65B0\u6210\u529F\uFF0C\u9879\u76EE\u4E0B\u6682\u65F6\u6CA1\u6709\u7535\u68AF
 msg.company.lift.empty=\u8BE5\u516C\u53F8\u4E0B\u6682\u65F6\u6CA1\u6709\u7535\u68AF
-msg.error.time=\u9996\u4FDD\u65F6\u95F4\u5E94\u5728\u9879\u76EE\u5F00\u59CB\u65F6\u95F4\u548C\u7ED3\u675F\u65F6\u95F4\u8303\u56F4\u5185
+msg.error.time=\u9996\u4FDD\u65F6\u95F4\u5E94\u5728\u9879\u76EE\u5F00\u59CB\u65F6\u95F4\u548C\u7ED3\u675F\u65F6\u95F4\u8303\u56F4\u5185
+msg.error.lift.status=\u8BE5\u7535\u68AF\u5DF2\u5F03\u7528