|
|
@@ -0,0 +1,288 @@ |
|
|
|
package com.tuoheng.admin.service.inspection.resubmit; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.tuoheng.admin.conver.InspectionConverMapper; |
|
|
|
import com.tuoheng.admin.entity.*; |
|
|
|
import com.tuoheng.admin.enums.InspectionStatusEnum; |
|
|
|
import com.tuoheng.admin.enums.InspectionTypeEnum; |
|
|
|
import com.tuoheng.admin.enums.code.inspection.ResubmitInspectionCodeEnum; |
|
|
|
import com.tuoheng.admin.mapper.*; |
|
|
|
import com.tuoheng.admin.request.inspection.EditInspectionRequest; |
|
|
|
import com.tuoheng.admin.utils.ShiroUtils; |
|
|
|
import com.tuoheng.common.core.utils.DateUtils; |
|
|
|
import com.tuoheng.common.core.utils.JsonResult; |
|
|
|
import com.tuoheng.common.core.utils.StringUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
/** |
|
|
|
* 重新提交任务业务层处理 |
|
|
|
* |
|
|
|
* @author wanjing |
|
|
|
* @team tuoheng |
|
|
|
* @date 2022-12-201 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class ResubmitInspectionService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserMapper userMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DeptMapper deptMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RoadInformationMapper roadInformationMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SectionMapper sectionMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private InspectionMapper inspectionMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 重新提交任务 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public JsonResult resubmit(EditInspectionRequest request) { |
|
|
|
log.info("进入重新提交任务业务"); |
|
|
|
String userId = ShiroUtils.getUserId(); |
|
|
|
String tenantId = ShiroUtils.getTenantId(); |
|
|
|
JsonResult result = this.checkParam(tenantId, request); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
log.info("重新提交任务业务:校验参数失败:{}", result.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
// 构造inspection对象 |
|
|
|
result = this.buildInspection(userId, tenantId, request); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
log.info("重新提交任务业务:构建inspection对象失败:{}", result.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
Inspection inspection = (Inspection) result.getData(); |
|
|
|
|
|
|
|
// 调用第三方平台 |
|
|
|
result = this.callThirdPlatform(tenantId, inspection); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
log.info("重新提交任务业务:对接第三方平台失败:{}", result.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
Integer rowId = inspectionMapper.insert(inspection); |
|
|
|
log.info("重新提交任务, 返回结果: deptId={}", rowId); |
|
|
|
if (rowId <= 0) { |
|
|
|
log.info("重新提交任务业务:重新提交任务失败:{}", result.getMsg()); |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.RESUBMIT_IS_FAILED.getCode(), ResubmitInspectionCodeEnum.RESUBMIT_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
log.info("重新提交任务业务:重新提交任务成功:{}", inspection); |
|
|
|
return JsonResult.success(inspection); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查参数 |
|
|
|
* @param tenantId |
|
|
|
* @param request |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult checkParam(String tenantId, EditInspectionRequest request) { |
|
|
|
if (StringUtils.isEmpty(request.getId())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.ID_IS_NULL.getCode(), ResubmitInspectionCodeEnum.ID_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(request.getName())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.NAME_IS_NULL.getCode(), ResubmitInspectionCodeEnum.NAME_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (null == request.getType()) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.TYPE_IS_NULL.getCode(), ResubmitInspectionCodeEnum.TYPE_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (null == request.getInspectionType()) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.INSPECTION_TYPE_IS_NULL.getCode(), ResubmitInspectionCodeEnum.INSPECTION_TYPE_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (null == request.getRoadId() || StringUtils.isEmpty(request.getRoadName())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.ROAD_IS_NULL.getCode(), ResubmitInspectionCodeEnum.ROAD_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
if (null == request.getSectionId() || StringUtils.isEmpty(request.getSectionName())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.SECTION_IS_NULL.getCode(), ResubmitInspectionCodeEnum.SECTION_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (InspectionTypeEnum.AIRPORT.getCode() == request.getInspectionType()) { |
|
|
|
// 巡检方式:机场巡逻,可选择巡检机场和巡检路线 |
|
|
|
if (null == request.getAirportId() || StringUtils.isEmpty(request.getAirportName())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.AIRPORT_IS_NULL.getCode(), ResubmitInspectionCodeEnum.AIRPORT_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (null == request.getInspectionLine() || StringUtils.isEmpty(request.getInspectionLineName())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.INSPECTION_LINE_IS_NULL.getCode(), ResubmitInspectionCodeEnum.INSPECTION_LINE_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
} else if (InspectionTypeEnum.MABNNEDFLIGHT.getCode() == request.getInspectionType()) { |
|
|
|
// 巡检方式:飞手值飞,可选择是否直播,起点坐标,终点坐标 |
|
|
|
if (null == request.getIsLive()) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.LIVE_IS_NULL.getCode(), ResubmitInspectionCodeEnum.LIVE_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(request.getStartLongitude())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.START_LONGITUDE_IS_NULL.getCode(), ResubmitInspectionCodeEnum.START_LONGITUDE_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(request.getStartLatitude())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.START_LATITUDE_IS_NULL.getCode(), ResubmitInspectionCodeEnum.START_LATITUDE_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(request.getEndLongitude())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.END_LONGITUDE_IS_NULL.getCode(), ResubmitInspectionCodeEnum.END_LONGITUDE_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(request.getEndLatitude())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.END_LATITUDE_IS_NULL.getCode(), ResubmitInspectionCodeEnum.END_LATITUDE_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (null == request.getInspectionTime()) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.INSPECTION_TIME_IS_NULL.getCode(), ResubmitInspectionCodeEnum.INSPECTION_TIME_IS_NULL.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
Inspection inspectionOld = inspectionMapper.selectById(request.getId()); |
|
|
|
if (null == inspectionOld) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.INSPECTION_IS_NOT_EXIST.getCode(), ResubmitInspectionCodeEnum.INSPECTION_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
if (inspectionOld.getStatus() != InspectionStatusEnum.FLIGHT_FAILED.getCode()) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.FAILED_INSPECTION_CANNOT_RESUBMIT.getCode(), ResubmitInspectionCodeEnum.FAILED_INSPECTION_CANNOT_RESUBMIT.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
if (inspectionOld.getType() != request.getType()) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.TYPE_IS_NOT_EDIT.getCode(), ResubmitInspectionCodeEnum.TYPE_IS_NOT_EDIT.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
if (inspectionOld.getInspectionType() != request.getInspectionType()) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.INSPECTION_TYPE_IS_NOT_EDIT.getCode(), ResubmitInspectionCodeEnum.INSPECTION_TYPE_IS_NOT_EDIT.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
Integer roadCount = roadInformationMapper.selectCount(Wrappers.<RoadInformation>lambdaQuery() |
|
|
|
.eq(RoadInformation::getTenantId, tenantId) |
|
|
|
.eq(RoadInformation::getId, request.getRoadId()) |
|
|
|
.eq(RoadInformation::getMark, 1)); |
|
|
|
|
|
|
|
if (roadCount <= 0) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.ROAD_IS_NOT_EXIST.getCode(), ResubmitInspectionCodeEnum.ROAD_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
Integer sectionCount = sectionMapper.selectCount(Wrappers.<Section>lambdaQuery() |
|
|
|
.eq(Section::getTenantId, tenantId) |
|
|
|
.eq(Section::getId, request.getSectionId()) |
|
|
|
.eq(Section::getMark, 1)); |
|
|
|
if (sectionCount <= 0) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.SECTION_IS_NOT_EXIST.getCode(), ResubmitInspectionCodeEnum.SECTION_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 构造Inspection对象 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param tenantId |
|
|
|
* @param request |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult buildInspection(String userId, String tenantId, EditInspectionRequest request) { |
|
|
|
User user = userMapper.selectOne(new LambdaQueryWrapper<User>() |
|
|
|
.eq(User::getTenantId, tenantId) |
|
|
|
.eq(User::getId, userId) |
|
|
|
.eq(User::getMark, 1)); |
|
|
|
if (null == user) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.USER_IS_NOT_EXIST.getCode(), ResubmitInspectionCodeEnum.USER_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
Dept dept = deptMapper.selectOne(new LambdaQueryWrapper<Dept>() |
|
|
|
.eq(Dept::getTenantId, tenantId) |
|
|
|
.eq(Dept::getId, user.getDeptId()) |
|
|
|
.eq(Dept::getMark, 1)); |
|
|
|
if (null == dept) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.DEPT_IS_NOT_EXIST.getCode(), ResubmitInspectionCodeEnum.DEPT_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
Inspection inspection = InspectionConverMapper.INSTANCE.fromEditInspectionRequestToInspection(request); |
|
|
|
inspection.setId(""); |
|
|
|
inspection.setTenantId(tenantId); |
|
|
|
inspection.setDeptId(dept.getId()); |
|
|
|
inspection.setCreateUser(userId); |
|
|
|
inspection.setCreateTime(DateUtils.now()); |
|
|
|
inspection.setMobile(user.getMobile()); |
|
|
|
inspection.setStatus(InspectionStatusEnum.WAIT_FLIGHT.getCode()); // 重新提交,状态设置为等待飞行 |
|
|
|
return JsonResult.success(inspection); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 验证与第三方平台(飞手、dsp、高德)对接 |
|
|
|
* @param tenantId |
|
|
|
* @param inspection |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult callThirdPlatform(String tenantId, Inspection inspection) { |
|
|
|
// 对接高德地图 |
|
|
|
JsonResult result = this.callGaode(inspection); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
// 对接飞手平台 |
|
|
|
result = this.callPilot(inspection); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
// 对接DSP平台 |
|
|
|
result = this.callDSP(inspection); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 对接飞手平台 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult callPilot(Inspection inspection) { |
|
|
|
// TODO |
|
|
|
// 具体业务逻辑待实现,以下写法只是为了体现调用飞手平台成功或失败场景 |
|
|
|
if (StringUtils.isEmpty(inspection.getName())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.CALL_PILOT_IS_FAILED.getCode(), ResubmitInspectionCodeEnum.CALL_PILOT_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 对接DSP平台 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult callDSP(Inspection inspection) { |
|
|
|
// TODO |
|
|
|
// 具体业务逻辑待实现,以下写法只是为了体现调用DSP平台成功或失败场景 |
|
|
|
if (StringUtils.isEmpty(inspection.getName())) { |
|
|
|
return JsonResult.error(ResubmitInspectionCodeEnum.CALL_DSP_IS_FAILED.getCode(), ResubmitInspectionCodeEnum.CALL_DSP_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 对接高德地图平台:将经纬度转换成巡逻地点 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult callGaode(Inspection inspection) { |
|
|
|
// 经纬度转换成巡逻地点 |
|
|
|
// 接口暂未调通,直接返回成功 |
|
|
|
// String patrolLocation = GaodeUtil.getGaodeAddress(inspection.getStartLongitude(), inspection.getStartLatitude()); |
|
|
|
// if (StringUtils.isEmpty(patrolLocation)) { |
|
|
|
// return JsonResult.error(ResubmitInspectionCodeEnum.CALL_AMAP_IS_FAILED.getCode(), ResubmitInspectionCodeEnum.CALL_AMAP_IS_FAILED.getMsg()); |
|
|
|
// } |
|
|
|
// inspection.setPatrolLocation(patrolLocation); |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
} |