|
|
@@ -2,7 +2,6 @@ package com.tuoheng.admin.service.inspection.add; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.tuoheng.admin.constant.SystemConstant; |
|
|
|
import com.tuoheng.admin.conver.InspectionConverMapper; |
|
|
|
import com.tuoheng.admin.entity.*; |
|
|
|
import com.tuoheng.admin.enums.InspectionStatusEnum; |
|
|
@@ -10,19 +9,14 @@ import com.tuoheng.admin.enums.InspectionTypeEnum; |
|
|
|
import com.tuoheng.admin.enums.code.inspection.AddInspectionCodeEnum; |
|
|
|
import com.tuoheng.admin.mapper.*; |
|
|
|
import com.tuoheng.admin.request.inspection.AddInspectionRequest; |
|
|
|
import com.tuoheng.admin.request.third.PilotTaskRequest; |
|
|
|
import com.tuoheng.admin.service.third.pilot.PilotService; |
|
|
|
import com.tuoheng.admin.utils.GaodeUtil; |
|
|
|
import com.tuoheng.admin.utils.ShiroUtils; |
|
|
|
import com.tuoheng.common.core.config.common.CommonConfig; |
|
|
|
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.http.HttpEntity; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
/** |
|
|
@@ -66,27 +60,15 @@ public class AddInspectionService { |
|
|
|
log.info("进入添加任务业务"); |
|
|
|
String userId = ShiroUtils.getUserId(); |
|
|
|
String tenantId = ShiroUtils.getTenantId(); |
|
|
|
JsonResult result = this.checkParam(tenantId, addInspectionRequest); |
|
|
|
JsonResult result = this.checkParam(userId, tenantId, addInspectionRequest); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
log.info("添加任务业务:校验参数失败:{}", result.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
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(AddInspectionCodeEnum.USER_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.USER_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
User user = (User) result.getData(); |
|
|
|
|
|
|
|
// 构造inspection对象 |
|
|
|
result = this.buildInspection(user, tenantId, addInspectionRequest); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
log.info("添加任务业务:构建inspection对象失败:{}", result.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
Inspection inspection = (Inspection) result.getData(); |
|
|
|
Inspection inspection = this.buildInspection(user, tenantId, addInspectionRequest); |
|
|
|
|
|
|
|
// 调用第三方平台 |
|
|
|
result = this.callThirdPlatform(user, tenantId, inspection); |
|
|
@@ -106,11 +88,12 @@ public class AddInspectionService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查参数 |
|
|
|
* |
|
|
|
* @param tenantId |
|
|
|
* @param addInspectionRequest |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult checkParam(String tenantId, AddInspectionRequest addInspectionRequest) { |
|
|
|
private JsonResult checkParam(String userId, String tenantId, AddInspectionRequest addInspectionRequest) { |
|
|
|
if (StringUtils.isEmpty(addInspectionRequest.getName())) { |
|
|
|
return JsonResult.error(AddInspectionCodeEnum.NAME_IS_NULL.getCode(), AddInspectionCodeEnum.NAME_IS_NULL.getMsg()); |
|
|
|
} |
|
|
@@ -161,55 +144,63 @@ public class AddInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
Integer roadCount = roadInformationMapper.selectCount(Wrappers.<RoadInformation>lambdaQuery() |
|
|
|
.eq(RoadInformation::getTenantId, tenantId) |
|
|
|
.eq(RoadInformation::getId, addInspectionRequest.getRoadId()) |
|
|
|
.eq(RoadInformation::getMark, 1)); |
|
|
|
.eq(RoadInformation::getTenantId, tenantId) |
|
|
|
.eq(RoadInformation::getId, addInspectionRequest.getRoadId()) |
|
|
|
.eq(RoadInformation::getMark, 1)); |
|
|
|
|
|
|
|
if (roadCount <= 0) { |
|
|
|
return JsonResult.error(AddInspectionCodeEnum.ROAD_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.ROAD_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
Integer sectionCount = sectionMapper.selectCount(Wrappers.<Section>lambdaQuery() |
|
|
|
.eq(Section::getTenantId, tenantId) |
|
|
|
.eq(Section::getId, addInspectionRequest.getSectionId()) |
|
|
|
.eq(Section::getMark, 1)); |
|
|
|
.eq(Section::getTenantId, tenantId) |
|
|
|
.eq(Section::getId, addInspectionRequest.getSectionId()) |
|
|
|
.eq(Section::getMark, 1)); |
|
|
|
if (sectionCount <= 0) { |
|
|
|
return JsonResult.error(AddInspectionCodeEnum.SECTION_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.SECTION_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
|
|
|
|
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(AddInspectionCodeEnum.USER_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.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(AddInspectionCodeEnum.DEPT_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.DEPT_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
return JsonResult.success(user); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 构造Inspection对象 |
|
|
|
* 构造Inspection对象 |
|
|
|
* |
|
|
|
* @param user |
|
|
|
* @param tenantId |
|
|
|
* @param addInspectionRequest |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult buildInspection(User user, String tenantId, AddInspectionRequest addInspectionRequest) { |
|
|
|
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(AddInspectionCodeEnum.DEPT_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.DEPT_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
private Inspection buildInspection(User user, String tenantId, AddInspectionRequest addInspectionRequest) { |
|
|
|
Inspection inspection = InspectionConverMapper.INSTANCE.fromAddInspectionRequestToInspection(addInspectionRequest); |
|
|
|
String code = DateUtils.generateCode("XJRW"); |
|
|
|
inspection.setCode(code); |
|
|
|
inspection.setTenantId(tenantId); |
|
|
|
inspection.setDeptId(dept.getId()); |
|
|
|
inspection.setDeptId(user.getDeptId()); |
|
|
|
inspection.setCreateUser(user.getId()); |
|
|
|
inspection.setCreateTime(DateUtils.now()); |
|
|
|
inspection.setMobile(user.getMobile()); |
|
|
|
inspection.setStatus(InspectionStatusEnum.WAIT_FLIGHT.getCode()); |
|
|
|
return JsonResult.success(inspection); |
|
|
|
return inspection; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 与第三方平台(飞手、高德)对接 |
|
|
|
* 与第三方平台(飞手、高德)对接 |
|
|
|
* |
|
|
|
* @param user |
|
|
|
* @param tenantId |
|
|
@@ -222,7 +213,6 @@ public class AddInspectionService { |
|
|
|
if (0 != result.getCode()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
if (InspectionTypeEnum.MABNNEDFLIGHT.getCode() == inspection.getInspectionType()) { |
|
|
|
// 对接飞手平台 |
|
|
|
result = pilotService.addTask(user, inspection); |
|
|
@@ -234,7 +224,6 @@ public class AddInspectionService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 对接高德地图平台:将经纬度转换成巡逻地点 |
|
|
|
* |
|
|
|
* @return |
|
|
@@ -242,11 +231,11 @@ public class AddInspectionService { |
|
|
|
private JsonResult callGaode(Inspection inspection) { |
|
|
|
// 经纬度转换成巡逻地点 |
|
|
|
// 接口暂未调通,直接返回成功 |
|
|
|
// String patrolLocation = GaodeUtil.getGaodeAddress(inspection.getStartLongitude(), inspection.getStartLatitude()); |
|
|
|
// if (StringUtils.isEmpty(patrolLocation)) { |
|
|
|
// return JsonResult.error(AddInspectionCodeEnum.CALL_AMAP_IS_FAILED.getCode(), AddInspectionCodeEnum.CALL_AMAP_IS_FAILED.getMsg()); |
|
|
|
// } |
|
|
|
// inspection.setPatrolLocation(patrolLocation); |
|
|
|
String patrolLocation = GaodeUtil.getGaodeAddress(inspection.getStartLongitude(), inspection.getStartLatitude()); |
|
|
|
if (StringUtils.isEmpty(patrolLocation)) { |
|
|
|
return JsonResult.error(AddInspectionCodeEnum.CALL_AMAP_IS_FAILED.getCode(), AddInspectionCodeEnum.CALL_AMAP_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
inspection.setPatrolLocation(patrolLocation); |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|