Commit a511391d authored by suhuiguang's avatar suhuiguang

1.删除路线,去掉数据约束-维保

2.路线bug修改-维保
parent 9015fec7
......@@ -209,7 +209,6 @@ public class PointController extends AbstractBaseController {
Page<PointDto> pointList = iPointService.queryPointInfoWithItem(criterias, commonPageable, ownerId);
return CommonResponseUtil.success(pointList);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
return CommonResponseUtil.failure("查询巡检点信息失败");
}
......
package com.yeejoin.amos.maintenance.business.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.yeejoin.amos.maintenance.core.framework.PersonIdentify;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.maintenance.business.param.RoutePageParam;
import com.yeejoin.amos.maintenance.business.service.intfc.IRouteService;
......@@ -35,14 +9,23 @@ import com.yeejoin.amos.maintenance.business.util.RoutePageParamUtil;
import com.yeejoin.amos.maintenance.core.common.request.CommonPageable;
import com.yeejoin.amos.maintenance.core.common.request.CommonRequest;
import com.yeejoin.amos.maintenance.core.common.request.RoutePointInputItemRequest;
import com.yeejoin.amos.maintenance.core.framework.PersonIdentify;
import com.yeejoin.amos.maintenance.dao.entity.InputItem;
import com.yeejoin.amos.maintenance.dao.entity.Plan;
import com.yeejoin.amos.maintenance.dao.entity.Route;
import com.yeejoin.amos.maintenance.dao.entity.RoutePoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping(value = "/api/route")
......@@ -122,39 +105,8 @@ public class RouteController extends AbstractBaseController {
@ApiOperation(value = "删除巡检路线", notes = "删除巡检路线")
@DeleteMapping(value = "/deleteRoute", produces = "application/json;charset=UTF-8")
public CommonResponse deleteRoute(@ApiParam(value = "巡检路线ID", required = false) @RequestParam List<Long> routeIds) {
try {
//校验1:线路上有点时返回删除失败
Map<Long, String> idNameMap = new HashMap<>();
for (long id : routeIds) {
int routePointCount = routeService.countRoutePoint(id);
if (routePointCount > 0) {
Route route = routeService.queryRouteById(id);
idNameMap.put(id, route.getName());
}
}
if (idNameMap.size() > 0) {
return CommonResponseUtil.failure(idNameMap, "删除路线失败:路线上已设置巡检点");
}
//校验2:计划在使用,删除失败
idNameMap.clear();
for (long id : routeIds) {
int routePointCount = routeService.countRoutePoint(id);
if (routePointCount > 0) {
List<Plan> planList = routeService.queryPlanByRouteId(id);
if (planList != null && planList.size() > 0) {
idNameMap.put(id, planList.get(0).getName());
}
}
}
if (idNameMap.size() > 0) {
return CommonResponseUtil.failure(idNameMap, "删除路线失败:计划在使用");
}
routeService.delRouteById(routeIds.toArray(new Long[0]));
return CommonResponseUtil.success();
} catch (Exception e) {
log.error(e.getMessage(), e);
return CommonResponseUtil.failure("删除巡检路线失败");
}
routeService.delRouteById(routeIds.toArray(new Long[0]));
return CommonResponseUtil.success();
}
/**
......
......@@ -76,30 +76,37 @@ public class RouteServiceImpl implements IRouteService {
@Override
@Transactional
public Route addRoute(Route route) {
public Route addRoute(Route route) {
String creatorId = route.getCreatorId();
String orgCode = route.getOrgCode();
//1.保存主表
route = iRouteDao.saveAndFlush(route);
Long rId = route.getId();
List<RoutePoint> routePoints = route.getRoutePointList();
//2.保存子表
routePoints.forEach(rp -> {
rp.setOrgCode(orgCode);
rp.setRouteId(rId);
rp.setCreatorId(creatorId);
List<RoutePointItem> routePointItems = rp.getRoutePointItem();
//2.1保存点路线关系表
rp = iRoutePointDao.saveAndFlush(rp);
Long rpId = rp.getId();
routePointItems = routePointItems.stream().filter(RoutePointItem::getIsBound).collect(Collectors.toList());
routePointItems.forEach(rpi -> {
rpi.setRoutePointId(rpId);
rpi.setCreatorId(creatorId);
iRoutePointItemDao.saveAndFlush(rpi);
});
//2.2保存点项关系表
if (!routePointItems.isEmpty()) {
iRoutePointItemDao.saveAll(routePointItems);
}
});
return route;
}
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public void delRouteById(Long[] ids) {
//0.删除路线
iRouteDao.delRouteById(Arrays.asList(ids));
......@@ -126,7 +133,7 @@ public class RouteServiceImpl implements IRouteService {
iRoutePointItemDao.delRoutePointItem(rp.getId());
iRoutePointDao.deleteById(rp.getId());
//删除p_plan_task_detail 对应点、更新p_plan_task点数量、完成数量
this.updatePlanTask(rp.getPointId(),finalRoute.getId());
this.updatePlanTask(rp.getPointId(), finalRoute.getId());
} else {
List<RoutePointItem> routePointItems = rp.getRoutePointItem();
iRoutePointDao.saveAndFlush(rp);
......@@ -156,9 +163,15 @@ public class RouteServiceImpl implements IRouteService {
}
private void updatePlanTask(long pointId, long routeId) {
//1.查询指定路线的任务
List<PlanTask> planTaskList = planTaskDao.findByRouteId(routeId);
Map<Long, PlanTask> planTaskMap = planTaskList.stream().collect(Collectors.toMap(BasicEntity::getId, Function.identity()));
//2.查询指定的点
List<PlanTaskDetail> planTaskDetailList = iPlanTaskDetailDao.findByPointId(pointId);
Map<Long,PlanTask> planTaskMap = planTaskList.stream().collect(Collectors.toMap(BasicEntity::getId, Function.identity()));
//3.过滤指定父任务id的执行数据
planTaskDetailList = planTaskDetailList.stream().filter(e ->
planTaskList.stream().map(BasicEntity::getId).collect(Collectors.toList()).contains(e.getTaskNo())).collect(Collectors.toList());
//4.更新任务主表点的数量及完成数量
for (PlanTaskDetail planTaskDetail : planTaskDetailList) {
PlanTask planTask = planTaskMap.get(planTaskDetail.getTaskNo());
if (1 == planTaskDetail.getIsFinish()) {
......@@ -168,9 +181,9 @@ public class RouteServiceImpl implements IRouteService {
planTask.setPointNum(planTask.getPointNum() - 1);
}
}
//更新主表完成数量,点数量
//5.更新主表完成数量,点数量
planTaskDao.saveAll(planTaskList);
//删除路线下的维保点
//6.删除路线下的维保点
planTaskDetailMapper.deleteByPointIdAndRouteId(pointId, routeId);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment