Browse Source

1、重构优化添加任务代码;2、测试添加任务调用高德接口;3、测试添加任务调用飞手平台接口,优化代码;

tags/v1.0.0^2
wanjing 1 year ago
parent
commit
e5b1afc39e
2 changed files with 44 additions and 58 deletions
  1. +39
    -50
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/add/AddInspectionService.java
  2. +5
    -8
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/pilot/AddPilotTskService.java

+ 39
- 50
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/add/AddInspectionService.java View File

@@ -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();
}


+ 5
- 8
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/pilot/AddPilotTskService.java View File

@@ -13,7 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
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;
import org.springframework.web.client.RestTemplate;
@@ -37,10 +36,10 @@ public class AddPilotTskService {
pilotTaskRequest.setTaskCode(inspection.getCode());
pilotTaskRequest.setTaskName(inspection.getName());
pilotTaskRequest.setTenantName(tenant.getName());
pilotTaskRequest.setPatrolLocation(inspection.getPatrolLocation());
pilotTaskRequest.setPlatformCode("hhz");
pilotTaskRequest.setPatrolLocation(inspection.getPatrolLocation() == null ? "" : inspection.getPatrolLocation());
pilotTaskRequest.setPlatformCode("gs");
pilotTaskRequest.setSponsorName(user.getRealname());
pilotTaskRequest.setSponsorPhone(inspection.getMobile());
pilotTaskRequest.setSponsorPhone(inspection.getMobile() == null ? "" : inspection.getMobile());
pilotTaskRequest.setTaskStartTime(inspection.getInspectionTime());
pilotTaskRequest.setRemark(inspection.getNote());

@@ -57,11 +56,9 @@ public class AddPilotTskService {
pilotTaskRequest.setInspectionType(0);
HttpEntity httpEntity = new HttpEntity(pilotTaskRequest);

//设置地址(飞手平台)
// 设置地址(飞手平台)
String url = CommonConfig.pilotURL + SystemConstant.ADD_PILOTTASK;

//String url ="http://localhost:9115/apiTask/add";
ResponseEntity<JsonResult> response = null;
ResponseEntity<JsonResult> response;
try {
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
} catch (Exception e) {

Loading…
Cancel
Save