|
@@ -1,5 +1,6 @@
|
|
|
package cn.com.ty.lift.business.maintenance.service;
|
|
|
|
|
|
+import cn.com.ty.lift.business.framework.util.MessageUtils;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceDetailRequest;
|
|
|
import cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceGenerateRequest;
|
|
|
import cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance;
|
|
@@ -13,6 +14,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.com.xwy.boot.web.dto.RestResponse;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -60,8 +62,6 @@ 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};
|
|
|
|
|
@@ -83,6 +83,7 @@ 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,15 +92,42 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
return list(lambdaQueryWrapper);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return 判断结果
|
|
|
+ * @description 新增维保计划前置判断条件
|
|
|
+ * @date 2020/1/9 3:56 下午
|
|
|
+ */
|
|
|
+ public boolean preJudgment(List<MaintenancePlan> planList, LocalDate firstTime) {
|
|
|
+ Collection<Project> projects = projectService.getProjectList(planList);
|
|
|
+ for (Project entry : projects) {
|
|
|
+ //若首保时间早于项目开始时间,则不能新增维保计划
|
|
|
+ boolean startResult = firstTime.isBefore(entry.getStartDate());
|
|
|
+ if (startResult) return false;
|
|
|
+ //若首保时间晚于项目结束时间,也不能新增维保计划
|
|
|
+ boolean endResult = firstTime.isAfter(entry.getEndDate());
|
|
|
+ if (endResult) return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param request 电梯列表
|
|
|
* @return 是否成功
|
|
|
* @description 批量生成维保计划
|
|
|
* @date 2019/12/16 2:14 PM
|
|
|
*/
|
|
|
- public boolean insertBatch(MaintenanceGenerateRequest request) {
|
|
|
+ public RestResponse insertBatch(MaintenanceGenerateRequest request) {
|
|
|
+ boolean result = preJudgment(request.getPlanList(), request.getFirstTime());
|
|
|
+ if (!result){
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.error.time"));
|
|
|
+ }
|
|
|
List<MaintenancePlan> resultList = addPlan(request);
|
|
|
- return saveBatch(resultList, resultList.size());
|
|
|
+ boolean ret = saveBatch(resultList, resultList.size());
|
|
|
+ if (ret) {
|
|
|
+ return RestResponse.success(null, MessageUtils.get("msg.add.success"));
|
|
|
+ } else {
|
|
|
+ return RestResponse.fail(MessageUtils.get("msg.add.fail"));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -110,7 +138,7 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
*/
|
|
|
public List<MaintenancePlan> addPlan(MaintenanceGenerateRequest request) {
|
|
|
List<MaintenancePlan> plans = request.getPlanList();
|
|
|
- Collection<Project> projects = projectService.getProjectList(request);
|
|
|
+ Collection<Project> projects = projectService.getProjectList(request.getPlanList());
|
|
|
//获取保养间隔
|
|
|
int interval = request.getInterval();
|
|
|
//获取从第几期开始
|
|
@@ -164,6 +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);
|
|
|
int length = maintenanceType.length;
|
|
|
for (int i = 0; i <= times; i++) {
|
|
|
MaintenancePlan entry = new MaintenancePlan();
|
|
@@ -187,7 +216,7 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
entry.setPlanDate(planDate);
|
|
|
}
|
|
|
entry.setCount(periods);
|
|
|
- System.out.printf("i:%s,期数:%s,类型:%s,计划时间:%s,%s", (i + 1), periods, entry.getType(), entry.getPlanDate(), "\n");
|
|
|
+ log.info("每期期数{},类型{},计划时间{}", periods, entry.getType(), entry.getPlanDate());
|
|
|
periods++;
|
|
|
planList.add(entry);
|
|
|
}
|
|
@@ -201,6 +230,7 @@ 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());
|
|
@@ -214,16 +244,35 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
* @param mtCompanyId 公司id
|
|
|
* @param liftId 电梯id
|
|
|
* @return 维保计划列表
|
|
|
- * @description 获取电梯所有维保计划
|
|
|
+ * @description 获取当前期数后的维保计划列表
|
|
|
* @date 2020/1/8 10:33 上午
|
|
|
*/
|
|
|
- public List<MaintenancePlan> findAllPlanList(Long mtCompanyId, Long liftId) {
|
|
|
+ public List<MaintenancePlan> findPlanList(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::getMtCompanyId, mtCompanyId);
|
|
|
+ lambdaQueryWrapper.eq(MaintenancePlan::getLiftId, liftId);
|
|
|
+ lambdaQueryWrapper.ge(MaintenancePlan::getCount, periods);
|
|
|
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 修改维保计划请求
|
|
@@ -270,15 +319,17 @@ public class MaintenancePlanService extends ServiceImpl<MaintenancePlanMapper, M
|
|
|
//按照修改时间重新生成计划
|
|
|
plans = generatePlan(plan, periods, interval, updateTime, endDate);
|
|
|
} else if (isNull && ObjectUtil.isNotEmpty(updateInterval)) {
|
|
|
- //获取电梯所有维保计划,并清除计划
|
|
|
- planList = findAllPlanList(mtCompanyId, liftId);
|
|
|
+ //获取当前期数后的维保计划列表,并清除计划
|
|
|
+ planList = findPlanList(mtCompanyId, liftId, periods);
|
|
|
+ MaintenancePlan entity = detail(request.getMtCompanyId(), request.getLiftId(), request.getPeriods());
|
|
|
+ LocalDate planDate = entity.getPlanDate();
|
|
|
removeByIds(planList.stream().map(MaintenancePlan::getId).collect(Collectors.toList()));
|
|
|
//更新项目电梯关联表保养间隔
|
|
|
projectLiftRelevanceService.modifyPlanInterval(request.getRelevanceId(), updateInterval);
|
|
|
- plans = generatePlan(plan, periods, updateInterval, entry.getFirstTime(), endDate);
|
|
|
+ plans = generatePlan(plan, periods, updateInterval, planDate, endDate);
|
|
|
} else if (isNotNull && ObjectUtil.isNotEmpty(updateInterval)) {
|
|
|
- //获取当前时间后的维保计划列表,并清除计划
|
|
|
- planList = findPlanList(request);
|
|
|
+ //获取当前期数后的维保计划列表,并清除计划
|
|
|
+ planList = findPlanList(mtCompanyId, liftId, periods);
|
|
|
removeByIds(planList.stream().map(MaintenancePlan::getId).collect(Collectors.toList()));
|
|
|
//更新项目电梯关联表保养间隔
|
|
|
projectLiftRelevanceService.modifyPlanInterval(request.getRelevanceId(), updateInterval);
|
|
@@ -296,6 +347,7 @@ 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<>();
|
|
|
LambdaQueryWrapper<MaintenancePlan> lambdaQueryWrapper = queryWrapper.lambda();
|
|
|
lambdaQueryWrapper.eq(MaintenancePlan::getMtCompanyId, mtCompanyId);
|
|
|
lambdaQueryWrapper.in(MaintenancePlan::getLiftId, liftList);
|