|
|
@@ -2,10 +2,11 @@ package com.tuoheng.admin.service.inspection.delete; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.tuoheng.admin.entity.*; |
|
|
|
import com.tuoheng.admin.entity.Inspection; |
|
|
|
import com.tuoheng.admin.entity.InspectionFile; |
|
|
|
import com.tuoheng.admin.entity.User; |
|
|
|
import com.tuoheng.admin.enums.InspectionStatusEnum; |
|
|
|
import com.tuoheng.admin.enums.UserTypeEnum; |
|
|
|
import com.tuoheng.admin.enums.code.dept.DeleteDeptCodeEnum; |
|
|
|
import com.tuoheng.admin.enums.code.inspection.DeleteInspectionCodeEnum; |
|
|
|
import com.tuoheng.admin.mapper.*; |
|
|
|
import com.tuoheng.admin.utils.ShiroUtils; |
|
|
@@ -15,6 +16,7 @@ import com.tuoheng.common.core.utils.StringUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
@@ -51,18 +53,18 @@ public class DeleteInspectionService { |
|
|
|
private InspectionHistoryMapper inspectionHistoryMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 删除任务业务 |
|
|
|
* 1)、对入参判断 |
|
|
|
* 2)、对任务状态判断,处于飞行中的任务无法删除 |
|
|
|
* 3)、对用户权限判断,超级管理员可删除任何任务;管理员能删除本部门任务,不能删除子部门任务;普通用户不能删除任务 |
|
|
|
* 4)、删除任务、任务问题、任务处理数据 |
|
|
|
* 4.1)、已完成的任务,进行逻辑删除 |
|
|
|
* 4.2)、待飞行任务、失败状态的任务,进行物理删除 |
|
|
|
* 1)、对入参判断 |
|
|
|
* 2)、对任务状态判断,处于飞行中的任务无法删除 |
|
|
|
* 3)、对用户权限判断,超级管理员可删除任何任务;管理员能删除本部门任务,不能删除子部门任务;普通用户不能删除任务 |
|
|
|
* 4)、删除任务、任务问题、任务处理数据 |
|
|
|
* 4.1)、已完成的任务,进行逻辑删除 |
|
|
|
* 4.2)、待飞行任务、失败状态的任务,进行物理删除 |
|
|
|
* |
|
|
|
* @param id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
public JsonResult deleteById(String id) { |
|
|
|
log.info("进入删除任务业务接口"); |
|
|
|
String userId = ShiroUtils.getUserId(); |
|
|
@@ -107,6 +109,7 @@ public class DeleteInspectionService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查参数 |
|
|
|
* |
|
|
|
* @param tenantId |
|
|
|
* @param id |
|
|
|
* @return |
|
|
@@ -119,9 +122,9 @@ public class DeleteInspectionService { |
|
|
|
|
|
|
|
// 判断任务是否存在 |
|
|
|
Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>() |
|
|
|
.eq(Inspection::getTenantId, tenantId) |
|
|
|
.eq(Inspection::getId, id) |
|
|
|
.eq(Inspection::getMark, 1)); |
|
|
|
.eq(Inspection::getTenantId, tenantId) |
|
|
|
.eq(Inspection::getId, id) |
|
|
|
.eq(Inspection::getMark, 1)); |
|
|
|
if (null == inspection) { |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.INSPECTION_IS_NOT_EXIST.getCode(), DeleteInspectionCodeEnum.INSPECTION_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
@@ -142,12 +145,10 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 判断是否有删除权限 |
|
|
|
* 1)、超级管理员可以删除所有任务 |
|
|
|
* 2)、管理员可删除本部门任务,无法删除子部门任务 |
|
|
|
* 3)、普通用户无权限删除任务 |
|
|
|
* |
|
|
|
* 1)、超级管理员可以删除所有任务 |
|
|
|
* 2)、管理员可删除本部门任务,无法删除子部门任务 |
|
|
|
* 3)、普通用户无权限删除任务 |
|
|
|
* |
|
|
|
* @param tenantId |
|
|
|
* @param userId |
|
|
@@ -173,21 +174,19 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除任务 |
|
|
|
* 1)、已完成的任务被删除后任务历史信息保留在服务器中,不再展示 |
|
|
|
* 2)、待飞行任务、失败状态的任务被删除后,任务不再执行,不保存任务信息到服务器中 |
|
|
|
* 3)、此处删除根据 1,2中需求,涉及逻辑删除和物理删除,不同删除操作,对任务、任务问题、任务问题处理结果的关联删除也不一样 |
|
|
|
* 4)、此方法,提前将任务问题、任务问题处理结果给取出,后面进行不同的处理业务 |
|
|
|
* 删除任务 |
|
|
|
* 1)、已完成的任务被删除后任务历史信息保留在服务器中,不再展示 |
|
|
|
* 2)、待飞行任务、失败状态的任务被删除后,任务不再执行,不保存任务信息到服务器中 |
|
|
|
* 3)、此处删除根据 1,2中需求,涉及逻辑删除和物理删除,不同删除操作,对任务、任务问题、任务问题处理结果的关联删除也不一样 |
|
|
|
* 4)、此方法,提前将任务问题、任务问题处理结果给取出,后面进行不同的处理业务 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult deleted(Inspection inspection) { |
|
|
|
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(new LambdaQueryWrapper<InspectionFile>() |
|
|
|
.eq(InspectionFile::getInspectionId, inspection.getId()) |
|
|
|
.eq(InspectionFile::getMark, 1)); |
|
|
|
|
|
|
|
.eq(InspectionFile::getInspectionId, inspection.getId()) |
|
|
|
.eq(InspectionFile::getMark, 1)); |
|
|
|
List<String> inspectionFileIdList = inspectionFileList.stream().map(o -> o.getId()).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if (InspectionStatusEnum.FLIGHT_COMPLETED.getCode() == inspection.getStatus()) { |
|
|
|
this.deleteByLogic(inspection, inspectionFileIdList); |
|
|
|
} else if (InspectionStatusEnum.WAIT_FLIGHT.getCode() == inspection.getStatus()) { |
|
|
@@ -199,7 +198,7 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 逻辑删除已完成的任务,任务被删除后任务历史信息保留在服务器中,不再展示,做逻辑删除,mark置为0,不去真正删除 |
|
|
|
* 逻辑删除已完成的任务,任务被删除后任务历史信息保留在服务器中,不再展示,做逻辑删除,mark置为0,不去真正删除 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
@@ -208,7 +207,7 @@ public class DeleteInspectionService { |
|
|
|
inspection.setMark(0); |
|
|
|
Integer rowId = inspectionMapper.deleteByLogic(inspection); |
|
|
|
log.info("删除任务业务, 返回结果: rowId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
if (rowId < 0) { |
|
|
|
log.info("删除任务业务:逻辑删除任务失败"); |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.DELETE_IS_FAILED.getCode(), DeleteInspectionCodeEnum.DELETE_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
@@ -226,9 +225,9 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 逻辑删除已完成的任务问题, |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、任务问题信息保留在服务器中,不再展示,做逻辑删除,mark置为0,不去真正删除 |
|
|
|
* 逻辑删除已完成的任务问题, |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、任务问题信息保留在服务器中,不再展示,做逻辑删除,mark置为0,不去真正删除 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
@@ -236,7 +235,7 @@ public class DeleteInspectionService { |
|
|
|
Map<String, Object> map = this.getInspectionMap(inspection); |
|
|
|
Integer rowId = inspectionFileMapper.deleteLogicByMap(map); |
|
|
|
log.info("删除任务, 返回结果: rowId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
if (rowId < 0) { |
|
|
|
log.info("删除任务业务接口:逻辑删除任务问题失败"); |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.DELETE_IS_FAILED.getCode(), DeleteInspectionCodeEnum.DELETE_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
@@ -244,9 +243,9 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 逻辑删除已完成的任务问题, |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、任务问题信息保留在服务器中,不再展示,做逻辑删除,mark置为0,不去真正删除 |
|
|
|
* 逻辑删除已完成的任务问题, |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、任务问题信息保留在服务器中,不再展示,做逻辑删除,mark置为0,不去真正删除 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
@@ -257,7 +256,7 @@ public class DeleteInspectionService { |
|
|
|
Map<String, Object> map = this.getInspectionFileMap(inspection, inspectionFileIdList); |
|
|
|
Integer rowId = inspectionFileHandleMapper.deleteLogicByMap(map); |
|
|
|
log.info("删除任务, 返回结果: rowId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
if (rowId < 0) { |
|
|
|
log.info("删除任务业务接口:逻辑删除任务问题处理结果失败"); |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.DELETE_IS_FAILED.getCode(), DeleteInspectionCodeEnum.DELETE_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
@@ -265,17 +264,17 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 逻辑删除任务历史记录 |
|
|
|
* 1)、已完成任务被删除后,任务历史记录也需要删除 |
|
|
|
* 2)、任务历史记录保留在服务器中,不再展示,做逻辑删除,mark置为0,不去真正删除 |
|
|
|
* 逻辑删除任务历史记录 |
|
|
|
* 1)、已完成任务被删除后,任务历史记录也需要删除 |
|
|
|
* 2)、任务历史记录保留在服务器中,不再展示,做逻辑删除,mark置为0,不去真正删除 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult deleteInspectionHistoryByLogic(Inspection inspection) { |
|
|
|
Map<String, Object> map = this.getInspectionMap(inspection); |
|
|
|
Integer rowId = inspectionFileMapper.deleteLogicByMap(map); |
|
|
|
Integer rowId = inspectionHistoryMapper.deleteLogicByMap(map); |
|
|
|
log.info("删除任务, 返回结果: rowId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
if (rowId < 0) { |
|
|
|
log.info("删除任务业务接口:逻辑删除任务历史记录失败"); |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.DELETE_IS_FAILED.getCode(), DeleteInspectionCodeEnum.DELETE_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
@@ -283,14 +282,14 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 物理删除待飞行任务、失败状态的任务,删除后,任务不再执行,不保存任务信息到服务器中,做物理删除,真正删除 |
|
|
|
* 物理删除待飞行任务、失败状态的任务,删除后,任务不再执行,不保存任务信息到服务器中,做物理删除,真正删除 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult deleteByPhysical(Inspection inspection, List<String> inspectionFileIdList) { |
|
|
|
Integer rowId = inspectionMapper.deleteById(inspection.getId()); |
|
|
|
log.info("删除任务, 返回结果: rowId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
if (rowId < 0) { |
|
|
|
log.info("删除任务业务接口:物理删除任务失败"); |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.DELETE_IS_FAILED.getCode(), DeleteInspectionCodeEnum.DELETE_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
@@ -308,17 +307,16 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 物理删除已完成的任务问题, |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、物理删除 |
|
|
|
* 物理删除已完成的任务问题, |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、物理删除 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult deleteInspectionFileByPhysical(Inspection inspection) { |
|
|
|
Map<String, Object> map = this.getInspectionMap(inspection); |
|
|
|
Integer rowId = inspectionFileMapper.deleteLogicByMap(map); |
|
|
|
Integer rowId = inspectionFileMapper.deleteByInspectionId(inspection.getId()); |
|
|
|
log.info("删除任务, 返回结果: rowId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
if (rowId < 0) { |
|
|
|
log.info("删除任务业务接口:逻辑删除任务问题失败"); |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.DELETE_IS_FAILED.getCode(), DeleteInspectionCodeEnum.DELETE_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
@@ -326,20 +324,16 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 物理删除已完成的任务问题, |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、物理删除 |
|
|
|
* 物理删除已完成的任务问题, |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、物理删除 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult deleteInspectionFileHandleByPhysical(Inspection inspection, List<String> inspectionFileIdList) { |
|
|
|
if (CollectionUtil.isEmpty(inspectionFileIdList)) { |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
Map<String, Object> map = this.getInspectionFileMap(inspection, inspectionFileIdList); |
|
|
|
Integer rowId = inspectionFileHandleMapper.deleteLogicByMap(map); |
|
|
|
Integer rowId = inspectionFileHandleMapper.deleteByInspectionFileIdList(inspectionFileIdList); |
|
|
|
log.info("删除任务, 返回结果: rowId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
if (rowId < 0) { |
|
|
|
log.info("删除任务业务接口:逻辑删除任务问题处理结果失败"); |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.DELETE_IS_FAILED.getCode(), DeleteInspectionCodeEnum.DELETE_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
@@ -347,17 +341,16 @@ public class DeleteInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 物理删除任务历史记录 |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、物理删除 |
|
|
|
* 物理删除任务历史记录 |
|
|
|
* 1)、已完成任务被删除后,同步任务问题也需要删除 |
|
|
|
* 2)、物理删除 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult deleteInspectionHistoryByPhysical(Inspection inspection) { |
|
|
|
Map<String, Object> map = this.getInspectionMap(inspection); |
|
|
|
Integer rowId = inspectionHistoryMapper.deleteLogicByMap(map); |
|
|
|
Integer rowId = inspectionHistoryMapper.deleteByInspectionId(inspection.getId()); |
|
|
|
log.info("删除任务, 返回结果: rowId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
if (rowId < 0) { |
|
|
|
log.info("删除任务业务接口:逻辑删除任务历史记录失败"); |
|
|
|
return JsonResult.error(DeleteInspectionCodeEnum.DELETE_IS_FAILED.getCode(), DeleteInspectionCodeEnum.DELETE_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
@@ -366,18 +359,18 @@ public class DeleteInspectionService { |
|
|
|
|
|
|
|
private Map<String, Object> getInspectionMap(Inspection inspection) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("mark", 0); |
|
|
|
map.put("updateUser", inspection.getUpdateUser()); |
|
|
|
map.put("updateTime", DateUtils.now()); |
|
|
|
map.put("mark", 0); |
|
|
|
map.put("inspectionId", inspection.getId()); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, Object> getInspectionFileMap(Inspection inspection, List<String> inspectionFileIdList) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("mark", 0); |
|
|
|
map.put("updateUser", inspection.getUpdateUser()); |
|
|
|
map.put("updateTime", DateUtils.now()); |
|
|
|
map.put("mark", 0); |
|
|
|
map.put("inspectionFileIdList", inspectionFileIdList); |
|
|
|
return map; |
|
|
|
} |