|
@@ -13,6 +13,7 @@ import cn.com.ty.lift.business.project.dao.entity.Project;
|
|
|
import cn.com.ty.lift.business.project.service.ProjectService;
|
|
|
import cn.com.ty.lift.common.base.ExportRequest;
|
|
|
import cn.com.ty.lift.common.export.ExportUtils;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -20,11 +21,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author bieao
|
|
@@ -57,6 +60,11 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
put("planDate", "计划时间");
|
|
|
}};
|
|
|
|
|
|
+ private QueryWrapper<MaintenancePlan> queryWrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
+ //保养类型 1.半月,2.季度,3.半年,4.全年
|
|
|
+ private int[] maintenanceType = {1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 4};
|
|
|
+
|
|
|
/**
|
|
|
* @param request 维保计划列表
|
|
|
* @return 1.成功, 0.失败, 消息描述
|
|
@@ -75,7 +83,6 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
* @date 2020/1/2 9:43 上午
|
|
|
*/
|
|
|
public List<MaintenancePlan> detailList(MaintenanceDetailRequest request) {
|
|
|
- QueryWrapper<MaintenancePlan> queryWrapper = new QueryWrapper<>();
|
|
|
LambdaQueryWrapper<MaintenancePlan> lambdaQueryWrapper = queryWrapper.lambda();
|
|
|
lambdaQueryWrapper.eq(MaintenancePlan::getMtCompanyId, request.getMtCompanyId());
|
|
|
lambdaQueryWrapper.eq(MaintenancePlan::getProjectId, request.getProjectId());
|
|
@@ -91,78 +98,33 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
* @date 2019/12/16 2:14 PM
|
|
|
*/
|
|
|
public boolean insertBatch(MaintenanceGenerateRequest request) {
|
|
|
- List<MaintenancePlan> resultList = generatePlan(request);
|
|
|
+ List<MaintenancePlan> resultList = addPlan(request);
|
|
|
return saveBatch(resultList, resultList.size());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param beginTime 项目开始时间
|
|
|
- * @param endTime 项目结束时间
|
|
|
- * @param interval 保养间隔
|
|
|
- * @return 实际期数
|
|
|
- * @description 计算当前电梯所在项目开始时间到结束时间需要保养的期数
|
|
|
- * @date 2019/12/16 2:11 PM
|
|
|
- */
|
|
|
- public int calculatePeriods(LocalDate beginTime, LocalDate endTime, int interval) {
|
|
|
- long days = beginTime.until(endTime, ChronoUnit.DAYS);
|
|
|
- double num = Math.floor(Double.parseDouble(String.valueOf((days / interval))));
|
|
|
- return (int) num;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @param request 需要保养的电梯
|
|
|
* @return List<MaintenancePlan> 维保计划列表
|
|
|
- * @description 生成维保计划
|
|
|
+ * @description 新增维保计划
|
|
|
* @date 2019/12/16 1:21 PM
|
|
|
*/
|
|
|
- public List<MaintenancePlan> generatePlan(MaintenanceGenerateRequest request) {
|
|
|
+ public List<MaintenancePlan> addPlan(MaintenanceGenerateRequest request) {
|
|
|
List<MaintenancePlan> plans = request.getPlanList();
|
|
|
- //返回维保计划列表
|
|
|
- List<MaintenancePlan> planList = new ArrayList<>();
|
|
|
- //保养类型 1.半月,2.季度,3.半年,4.全年
|
|
|
- int[] maintenanceType = {1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 4};
|
|
|
- int times = 0;
|
|
|
- //获取从第几期开始
|
|
|
- int periods = request.getPeriods();
|
|
|
+ Collection<Project> projects = projectService.getProjectList(request);
|
|
|
//获取保养间隔
|
|
|
int interval = request.getInterval();
|
|
|
+ //获取从第几期开始
|
|
|
+ int periods = request.getPeriods();
|
|
|
//获取首保时间
|
|
|
LocalDate firstTime = request.getFirstTime();
|
|
|
- for (MaintenancePlan plan : plans) {
|
|
|
- //获取项目id
|
|
|
- Long projectId = plan.getProjectId();
|
|
|
- Project project = projectService.detail(projectId);
|
|
|
- if (project != null) {
|
|
|
- LocalDate beginTime = project.getStartDate();
|
|
|
- LocalDate endTime = project.getEndDate();
|
|
|
- //计算当前电梯所在项目开始时间到结束时间需要保养的期数
|
|
|
- times = calculatePeriods(beginTime, endTime, interval);
|
|
|
- }
|
|
|
- for (int i = 0; i < times; i++) {
|
|
|
- MaintenancePlan entry = new MaintenancePlan();
|
|
|
- //设置维保计划电梯ID,维保公司ID,项目ID,维保工ID,维保类型
|
|
|
- entry.setLiftId(plan.getLiftId());
|
|
|
- entry.setMtCompanyId(plan.getMtCompanyId());
|
|
|
- entry.setProjectId(projectId);
|
|
|
- entry.setWorkerId(plan.getWorkerId());
|
|
|
- entry.setType(maintenanceType[periods - 1]);
|
|
|
- entry.setDemand(request.getDemand());
|
|
|
- if (i == 0) {
|
|
|
- entry.setPlanDate(firstTime);
|
|
|
- } else {
|
|
|
- //设置维护保养时间
|
|
|
- MaintenancePlan maintenancePlan = planList.get(i - 1);
|
|
|
- LocalDate planDate = maintenancePlan.getPlanDate().plusDays(interval);
|
|
|
- entry.setPlanDate(planDate);
|
|
|
- }
|
|
|
- System.out.printf("i:%s,期数:%s,类型:%s,计划时间:%s,%s", (i + 1), periods, entry.getType(), entry.getPlanDate(), "\n");
|
|
|
- periods++;
|
|
|
- if (periods == 25) {
|
|
|
- periods = 1;
|
|
|
- }
|
|
|
- planList.add(entry);
|
|
|
+ List<MaintenancePlan> planList = new ArrayList<>();
|
|
|
+ plans.forEach(plan -> {
|
|
|
+ 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()));
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
//更新项目电梯关联表中电梯的首保时间和保养间隔
|
|
|
List<ProjectLiftRelevance> entryList = request.getRelevanceList();
|
|
|
entryList.forEach(entry -> {
|
|
@@ -173,6 +135,64 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
return planList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param interval 保养间隔
|
|
|
+ * @param beginTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 期数
|
|
|
+ * @description 获取维保计划生成期数
|
|
|
+ * @date 2020/1/8 8:11 下午
|
|
|
+ */
|
|
|
+ public int getTimes(int interval, LocalDate beginTime, LocalDate endTime) {
|
|
|
+ //计算当前电梯所在项目开始时间到结束时间需要保养的期数
|
|
|
+ long days = beginTime.until(endTime, ChronoUnit.DAYS);
|
|
|
+ double num = Math.floor(Double.parseDouble(String.valueOf((days / interval))));
|
|
|
+ return (int) num;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param plan 维保计划
|
|
|
+ * @param periods 期数
|
|
|
+ * @param interval 保养间隔
|
|
|
+ * @param beginTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return 维保计划列表
|
|
|
+ * @description 生成维保计划
|
|
|
+ * @date 2020/1/8 8:20 下午
|
|
|
+ */
|
|
|
+ public List<MaintenancePlan> generatePlan(MaintenancePlan plan, int periods, int interval, LocalDate beginTime, LocalDate endTime) {
|
|
|
+ //返回维保计划列表
|
|
|
+ List<MaintenancePlan> planList = new ArrayList<>();
|
|
|
+ int times = getTimes(interval, beginTime, endTime);
|
|
|
+ int length = maintenanceType.length;
|
|
|
+ for (int i = 0; i <= times; i++) {
|
|
|
+ MaintenancePlan entry = new MaintenancePlan();
|
|
|
+ entry.setWorkerId(plan.getWorkerId());
|
|
|
+ entry.setLiftId(plan.getLiftId());
|
|
|
+ entry.setProjectId(plan.getProjectId());
|
|
|
+ entry.setMtCompanyId(plan.getMtCompanyId());
|
|
|
+ int mod = periods % length;
|
|
|
+ //设置维保类型
|
|
|
+ if (mod == 0) {
|
|
|
+ entry.setType(maintenanceType[length - 1]);
|
|
|
+ } else {
|
|
|
+ entry.setType(maintenanceType[mod - 1]);
|
|
|
+ }
|
|
|
+ if (i == 0) {
|
|
|
+ entry.setPlanDate(beginTime);
|
|
|
+ } else {
|
|
|
+ //设置维护保养时间
|
|
|
+ MaintenancePlan maintenancePlan = planList.get(i - 1);
|
|
|
+ LocalDate planDate = maintenancePlan.getPlanDate().plusDays(interval);
|
|
|
+ entry.setPlanDate(planDate);
|
|
|
+ }
|
|
|
+ System.out.printf("i:%s,期数:%s,类型:%s,计划时间:%s,%s", (i + 1), periods, entry.getType(), entry.getPlanDate(), "\n");
|
|
|
+ periods++;
|
|
|
+ planList.add(entry);
|
|
|
+ }
|
|
|
+ return planList;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param request 当前时间
|
|
|
* @return List<MaintenancePlan> 维保计划列表
|
|
@@ -180,39 +200,91 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
* @date 2020/1/7 2:40 下午
|
|
|
*/
|
|
|
public List<MaintenancePlan> findPlanList(MaintenanceModifyRequest request){
|
|
|
- QueryWrapper<MaintenancePlan> queryWrapper = new QueryWrapper<>();
|
|
|
LambdaQueryWrapper<MaintenancePlan> lambdaQueryWrapper = queryWrapper.lambda();
|
|
|
lambdaQueryWrapper.eq(MaintenancePlan::getLiftId, request.getLiftId());
|
|
|
lambdaQueryWrapper.eq(MaintenancePlan::getProjectId, request.getProjectId());
|
|
|
lambdaQueryWrapper.eq(MaintenancePlan::getMtCompanyId, request.getMtCompanyId());
|
|
|
- lambdaQueryWrapper.gt(MaintenancePlan::getPlanDate, request.getCurrentTime());
|
|
|
+ lambdaQueryWrapper.ge(MaintenancePlan::getPlanDate, request.getCurrentTime());
|
|
|
return list(lambdaQueryWrapper);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param mtCompanyId 公司id
|
|
|
+ * @param liftId 电梯id
|
|
|
+ * @return 维保计划列表
|
|
|
+ * @description 获取电梯所有维保计划
|
|
|
+ * @date 2020/1/8 10:33 上午
|
|
|
+ */
|
|
|
+ public List<MaintenancePlan> findAllPlanList(Long mtCompanyId, Long liftId) {
|
|
|
+ LambdaQueryWrapper<MaintenancePlan> lambdaQueryWrapper = queryWrapper.lambda();
|
|
|
+ lambdaQueryWrapper.eq(MaintenancePlan::getMtCompanyId,mtCompanyId);
|
|
|
+ lambdaQueryWrapper.eq(MaintenancePlan::getLiftId,liftId);
|
|
|
+ return list(lambdaQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @param request 修改维保计划请求
|
|
|
* @return 是否修改成功
|
|
|
* @description 修改维保计划
|
|
|
* @date 2019/12/16 5:25 PM
|
|
|
*/
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean modifyPlan(MaintenanceModifyRequest request) {
|
|
|
- List<MaintenancePlan> resultList = new ArrayList<>();
|
|
|
+ //获取公司id
|
|
|
+ Long mtCompanyId = request.getMtCompanyId();
|
|
|
+ //获取公司id
|
|
|
+ Long projectId = request.getProjectId();
|
|
|
+ //获取公司id
|
|
|
+ Long liftId = request.getLiftId();
|
|
|
+ MaintenancePlan plan = new MaintenancePlan();
|
|
|
+ plan.setProjectId(projectId);
|
|
|
+ plan.setMtCompanyId(mtCompanyId);
|
|
|
+ plan.setLiftId(liftId);
|
|
|
+ plan.setWorkerId(request.getWorkerId());
|
|
|
+ Project project = projectService.detail(request.getProjectId());
|
|
|
+ if (ObjectUtil.isEmpty(project)) return false;
|
|
|
+ LocalDate endDate = project.getEndDate();
|
|
|
+ //获取当前的保养时间
|
|
|
+ LocalDate currentTime = request.getCurrentTime();
|
|
|
//获取修改的保养时间
|
|
|
LocalDate updateTime = request.getUpdateTime();
|
|
|
- //获取保养间隔
|
|
|
- Integer interval = request.getInterval();
|
|
|
- //获取当前时间后的维保计划列表
|
|
|
- List<MaintenancePlan> planList = findPlanList(request);
|
|
|
- for (int i = 0, size = planList.size(); i < size; i++) {
|
|
|
- MaintenancePlan entry = planList.get(i);
|
|
|
- if (i == 0) {
|
|
|
- entry.setPlanDate(updateTime);
|
|
|
- } else {
|
|
|
- entry.setPlanDate(entry.getPlanDate().plusDays(interval));
|
|
|
- }
|
|
|
- resultList.add(entry);
|
|
|
+ //获取修改的保养间隔
|
|
|
+ Integer updateInterval = request.getInterval();
|
|
|
+ //获取当前期数
|
|
|
+ Integer periods = request.getPeriods();
|
|
|
+ //获取当前电梯的保养间隔
|
|
|
+ ProjectLiftRelevance entry = projectLiftRelevanceService.getOne(mtCompanyId, liftId);
|
|
|
+ if (ObjectUtil.isEmpty(entry)) return false;
|
|
|
+ int interval = entry.getPlanInterval();
|
|
|
+ boolean isNotNull = ObjectUtil.isNotEmpty(currentTime) && ObjectUtil.isNotEmpty(updateTime);
|
|
|
+ boolean isNull = ObjectUtil.isEmpty(currentTime) && ObjectUtil.isEmpty(updateTime);
|
|
|
+ List<MaintenancePlan> planList;
|
|
|
+ List<MaintenancePlan> plans = new ArrayList<>();
|
|
|
+ if (isNotNull && ObjectUtil.isEmpty(updateInterval)) {
|
|
|
+ //获取当前时间后的维保计划列表,并清除计划
|
|
|
+ planList = findPlanList(request);
|
|
|
+ removeByIds(planList.stream().map(MaintenancePlan::getId).collect(Collectors.toList()));
|
|
|
+ //按照修改时间重新生成计划
|
|
|
+ plans = generatePlan(plan, periods, interval, updateTime, endDate);
|
|
|
+ } else if (isNull && ObjectUtil.isNotEmpty(updateInterval)) {
|
|
|
+ //获取电梯所有维保计划,并清除计划
|
|
|
+ planList = findAllPlanList(mtCompanyId, liftId);
|
|
|
+ removeByIds(planList.stream().map(MaintenancePlan::getId).collect(Collectors.toList()));
|
|
|
+ //更新项目电梯关联表保养间隔
|
|
|
+ projectLiftRelevanceService.modifyPlanInterval(request.getRelevanceId(), updateInterval);
|
|
|
+ plans = generatePlan(plan, periods, updateInterval, entry.getFirstTime(), endDate);
|
|
|
+ } else if (isNotNull && ObjectUtil.isNotEmpty(updateInterval)) {
|
|
|
+ //获取当前时间后的维保计划列表,并清除计划
|
|
|
+ planList = findPlanList(request);
|
|
|
+ removeByIds(planList.stream().map(MaintenancePlan::getId).collect(Collectors.toList()));
|
|
|
+ //更新项目电梯关联表保养间隔
|
|
|
+ projectLiftRelevanceService.modifyPlanInterval(request.getRelevanceId(), updateInterval);
|
|
|
+ //按照修改时间重新生成计划
|
|
|
+ plans = generatePlan(plan, periods, updateInterval, updateTime, endDate);
|
|
|
}
|
|
|
- return updateBatchById(resultList, resultList.size());
|
|
|
+ return saveBatch(plans, plans.size());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -223,9 +295,9 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
* @date 2019/12/28 2:00 PM
|
|
|
*/
|
|
|
public boolean removeMaintenancePlan(Long mtCompanyId, List<Long> liftList) {
|
|
|
- QueryWrapper<MaintenancePlan> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("mt_company_id", mtCompanyId);
|
|
|
- queryWrapper.in("lift_id", liftList);
|
|
|
+ LambdaQueryWrapper<MaintenancePlan> lambdaQueryWrapper = queryWrapper.lambda();
|
|
|
+ lambdaQueryWrapper.eq(MaintenancePlan::getMtCompanyId, mtCompanyId);
|
|
|
+ lambdaQueryWrapper.in(MaintenancePlan::getLiftId, liftList);
|
|
|
return remove(queryWrapper);
|
|
|
}
|
|
|
|