yang 4 år sedan
förälder
incheckning
8b6bd6687c

+ 2 - 1
lift-business-service/src/main/java/cn/com/ty/lift/business/project/controller/ProjectController.java

@@ -170,7 +170,8 @@ public class ProjectController {
     @PostMapping("modify")
     @Validation(fields = {"id"})
     public RestResponse modify(@Val @RequestBody Project project) {
-        return projectService.modify(project);
+//        return projectService.modify(project);
+        return projectService.modifyProject(project);
     }
 
     /**

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

@@ -1,6 +1,7 @@
 package cn.com.ty.lift.business.project.service;
 
 import cn.com.ty.lift.business.framework.util.MessageUtils;
+import cn.com.ty.lift.business.library.dao.entity.PlatformCompanyLiftRelevance;
 import cn.com.ty.lift.business.library.service.PlatformCompanyLiftRelevanceService;
 import cn.com.ty.lift.business.maintenance.dao.entity.MaintenancePlan;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.LiftPrintResponse;
@@ -493,7 +494,7 @@ public class ProjectService extends ServiceImpl<ProjectMapper, Project> {
         /**
          * 项目id和维保公司id获取maxworkDate
          */
-        LocalDate maxWorkDate = maintenancePlanService.queryWorkDateByProjectId(projectId,mtCompanyId );
+        LocalDate maxWorkDate = maintenancePlanService.queryWorkDateByProjectId(projectId, mtCompanyId);
 
         LocalDate endDate = project.getEndDate();
         Project entry = oldProject.get();
@@ -538,6 +539,149 @@ public class ProjectService extends ServiceImpl<ProjectMapper, Project> {
         return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
     }
 
+    /**
+     * 修改项目 更新计划表
+     *
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class)
+    @SuppressWarnings("all")
+    public RestResponse modifyProject(Project project) {
+        //获取项目ID
+        Long projectId = project.getId();
+        //获取维保公司id
+        Long mtCompanyId = project.getMtCompanyId();
+        //根据项目id查询原来的项目信息
+        Optional<Project> oldProject = getOne(projectId);
+        //如果项目不存在则抛出错误
+        if (!oldProject.isPresent()) {
+            return RestResponse.fail(MessageUtils.get("msg.project.not.exist"));
+        }
+        //提交项目的更新时间
+        LocalDate endDate = project.getEndDate();
+        //修改项目的结束时间不能小于当前时间
+        LocalDate now = LocalDate.now();
+        if (endDate.plusMonths(3).isBefore(now)) {
+            log.info("项目结束时间:{} ,加上三个月,不能小于当前时间:{}", endDate, now);
+            return RestResponse.fail("项目结束时间不合法...");
+        }
+        //获取原项目的数据对象
+        Project entry = oldProject.get();
+        //如果原项目的结束时间和提交项目的结束时间不一样 更新维保计划表
+        if (!endDate.isEqual(entry.getEndDate())) {
+            //延期三个月
+            endDate = endDate.plusMonths(3);
+            List<ProjectLiftRelevance> projectLiftRelevanceList = projectLiftRelevanceService.getBaseMapper().selectList(new QueryWrapper<ProjectLiftRelevance>()
+                    .lambda()
+                    .eq(ProjectLiftRelevance::getProjectId, projectId)
+                    .eq(ProjectLiftRelevance::getMtCompanyId, mtCompanyId)
+                    //未锁定
+                    .eq(ProjectLiftRelevance::getLiftLocked, 0)
+                    //未删除
+                    .eq(ProjectLiftRelevance::getDeleteFlag, 0));
+            //遍历项目下的电梯
+            for (ProjectLiftRelevance projectLiftRelevance : projectLiftRelevanceList) {
+                //停保的电梯不制定计划
+                if (platformCompanyService.getBaseMapper().selectCount(new QueryWrapper<PlatformCompanyLiftRelevance>()
+                        .lambda()
+                        .eq(PlatformCompanyLiftRelevance::getLiftId, projectLiftRelevance.getLiftId())
+                        .eq(PlatformCompanyLiftRelevance::getMtCompanyId, projectLiftRelevance.getMtCompanyId())
+                        .eq(PlatformCompanyLiftRelevance::getLiftCompanyStatus, 1)) == 1) {
+                    log.info("当前电梯:{} ,已经停保,不制定计划", projectLiftRelevance.getLiftId());
+                    continue;
+                }
+
+                //获取电梯的最后一次维保计划
+                MaintenancePlan lastPlan = maintenancePlanService.getBaseMapper().selectOne(new QueryWrapper<MaintenancePlan>()
+                        .lambda()
+                        .eq(MaintenancePlan::getLiftId, projectLiftRelevance.getLiftId())
+                        .eq(MaintenancePlan::getProjectId, projectLiftRelevance.getProjectId())
+                        .eq(MaintenancePlan::getMtCompanyId, projectLiftRelevance.getMtCompanyId())
+                        .orderByDesc(MaintenancePlan::getPlanDate)
+                        .last("limit 1"));
+                if (lastPlan != null) {
+                    //计算当前电梯所在项目开始时间到结束时间需要保养的期数
+                    long days = lastPlan.getPlanDate().until(endDate, ChronoUnit.DAYS);
+                    int times = (int) Math.floor(Double.parseDouble(String.valueOf((days / projectLiftRelevance.getPlanInterval()))));
+                    if (times > 0) {
+                        //延期维保计划
+                        List<MaintenancePlan> maintenancePlanArrayList = new ArrayList<>();
+                        LocalDate planDate = lastPlan.getPlanDate();
+                        //防止查出来的count值大于24
+                        int count = lastPlan.getCount() == null ? 0 : lastPlan.getCount() % 24;
+                        //
+                        int[] constant = {1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 4};
+                        //开始补记录
+                        for (int i = 1; i <= times; i++) {
+                            MaintenancePlan plan = new MaintenancePlan();
+                            //超期 状态维护
+                            planDate = planDate.plusDays(projectLiftRelevance.getPlanInterval());
+                            if (planDate.isBefore(now)) {
+                                plan.setStatus(-1);
+                            } else {
+                                plan.setStatus(0);
+                            }
+                            //计划值维护
+                            plan.setPlanDate(planDate);
+                            plan.setCreateDate(LocalDateTime.now());
+                            plan.setUpdateDate(LocalDateTime.now());
+                            plan.setLiftId(lastPlan.getLiftId());
+                            plan.setMtCompanyId(lastPlan.getMtCompanyId());
+                            plan.setProjectId(lastPlan.getProjectId());
+                            plan.setWorkerId(lastPlan.getWorkerId());
+                            count++;
+                            plan.setCount(count);
+                            plan.setType(constant[count - 1]);
+                            //count值维护
+                            if (count >= 24) {
+                                count = 0;
+                            }
+                            plan.setCreatorId(lastPlan.getCreatorId());
+                            plan.setUpdateId(lastPlan.getUpdateId());
+                            plan.setDemand(lastPlan.getDemand());
+                            maintenancePlanArrayList.add(plan);
+                        }
+                        if (maintenancePlanArrayList.size() != 0 && maintenancePlanService.saveBatch(maintenancePlanArrayList)) {
+                            log.info("电梯号:{} 的计划制定成功!", projectLiftRelevance.getLiftId());
+                        }
+                    } else if (times < 0) {
+                        //缩短维保计划  删除多余的维保计划
+                        boolean flag = maintenancePlanService.remove(new QueryWrapper<MaintenancePlan>()
+                                .lambda()
+                                .eq(MaintenancePlan::getProjectId, projectId)
+                                .eq(MaintenancePlan::getLiftId, lastPlan.getLiftId())
+                                .eq(MaintenancePlan::getMtCompanyId, mtCompanyId)
+                                //计划时间大于项目的结束时间
+                                .gt(MaintenancePlan::getPlanDate, endDate));
+                        if (!flag) {
+                            rollback();
+                        }
+                    }
+
+                }
+            }
+        }
+        log.debug("维护项目状态");
+        this.setProjectStatus(project, oldProject.get().getProjectStatus());
+        project.setUpdateDate(LocalDateTime.now());
+        boolean result = updateById(project);
+        if (!result)
+            return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
+        //生成项目操作记录
+        ProjectHistory history = projectHistoryService.createOperaHistory(entry, project, project.getMtCompanyId());
+        if (Objects.nonNull(history)) {
+            //保存项目操作记录
+            boolean projectResult = projectHistoryService.save(history);
+            if (!projectResult) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return RestResponse.fail(MessageUtils.get("msg.modify.fail"));
+            }
+        }
+
+        return RestResponse.success(null, MessageUtils.get("msg.modify.success"));
+    }
+
+
     public List<Map<String, String>> exportList(List<String> ids) {
         return baseMapper.List(ids);
     }