|
|
@@ -8,6 +8,7 @@ import com.tuoheng.admin.enums.InspectionWayEnum; |
|
|
|
import com.tuoheng.admin.enums.code.inspection.AddInspectionCodeEnum; |
|
|
|
import com.tuoheng.admin.mapper.*; |
|
|
|
import com.tuoheng.admin.request.inspection.AddInspectionRequest; |
|
|
|
import com.tuoheng.admin.utils.GaodeUtil; |
|
|
|
import com.tuoheng.admin.utils.ShiroUtils; |
|
|
|
import com.tuoheng.common.core.utils.DateUtils; |
|
|
|
import com.tuoheng.common.core.utils.JsonResult; |
|
|
@@ -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; |
|
|
|
|
|
|
|
/** |
|
|
|
* 添加任务业务层处理 |
|
|
@@ -51,78 +53,34 @@ public class AddInspectionService { |
|
|
|
log.info("进入添加任务业务"); |
|
|
|
String userId = ShiroUtils.getUserId(); |
|
|
|
String tenantId = ShiroUtils.getTenantId(); |
|
|
|
JsonResult result = this.check(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)); |
|
|
|
|
|
|
|
Dept dept = deptMapper.selectOne(new LambdaQueryWrapper<Dept>() |
|
|
|
.eq(Dept::getTenantId, tenantId) |
|
|
|
.eq(Dept::getId, user.getDeptId()) |
|
|
|
.eq(Dept::getMark, 1)); |
|
|
|
|
|
|
|
Inspection inspection = InspectionConverMapper.INSTANCE.fromAddInspectionRequestToInspection(addInspectionRequest); |
|
|
|
String code = DateUtils.generateCode("XJRW"); |
|
|
|
inspection.setCode(code); |
|
|
|
inspection.setTenantId(tenantId); |
|
|
|
inspection.setDeptId(dept.getId()); |
|
|
|
inspection.setCreateUser(userId); |
|
|
|
inspection.setCreateTime(DateUtils.now()); |
|
|
|
inspection.setMobile(user.getMobile()); |
|
|
|
|
|
|
|
Integer rowId = inspectionMapper.insert(inspection); |
|
|
|
log.info("添加任务, 返回结果: deptId={}", rowId); |
|
|
|
|
|
|
|
if (rowId <= 0) { |
|
|
|
log.info("添加任务业务:添加任务失败:{}", result.getMsg()); |
|
|
|
return JsonResult.error(AddInspectionCodeEnum.ADD_INSPECTION_IS_FAILED.getCode(), AddInspectionCodeEnum.ADD_INSPECTION_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("添加任务业务:添加任务成功:{}", inspection); |
|
|
|
return JsonResult.success(inspection); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查参数、验证与第三方平台(飞手、dsp、高德)对接 |
|
|
|
* @param tenantId |
|
|
|
* @param addInspectionRequest |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult check(String tenantId, AddInspectionRequest addInspectionRequest) { |
|
|
|
JsonResult result = this.checkParam(tenantId, addInspectionRequest); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
log.info("添加任务业务:校验失败:{}", result.getMsg()); |
|
|
|
log.info("添加任务业务:校验参数失败:{}", result.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
// 对接飞手平台 |
|
|
|
result = this.callPilot(addInspectionRequest); |
|
|
|
// 构造inspection对象 |
|
|
|
result = this.buildInspection(userId, tenantId, addInspectionRequest); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
log.info("添加任务业务:对接飞手平台失败:{}", result.getMsg()); |
|
|
|
log.info("添加任务业务:构建inspection对象失败:{}", result.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
Inspection inspection = (Inspection) result.getData(); |
|
|
|
|
|
|
|
// 对接DSP平台 |
|
|
|
result = this.callDSP(addInspectionRequest); |
|
|
|
// 调用第三方平台 |
|
|
|
result = this.callThirdPlatform(tenantId, inspection); |
|
|
|
if (0 != result.getCode()) { |
|
|
|
log.info("添加任务业务:对接DSP平台失败:{}", result.getMsg()); |
|
|
|
log.info("添加任务业务:对接第三方平台失败:{}", result.getMsg()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
// 对接高德地图 |
|
|
|
result = this.callAmap(addInspectionRequest); |
|
|
|
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(AddInspectionCodeEnum.ADD_INSPECTION_IS_FAILED.getCode(), AddInspectionCodeEnum.ADD_INSPECTION_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
return JsonResult.success(); |
|
|
|
log.info("添加任务业务:添加任务成功:{}", inspection); |
|
|
|
return JsonResult.success(inspection); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -203,16 +161,78 @@ public class AddInspectionService { |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 构造Inspection对象 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param tenantId |
|
|
|
* @param addInspectionRequest |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult buildInspection(String userId, String tenantId, AddInspectionRequest addInspectionRequest) { |
|
|
|
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()); |
|
|
|
} |
|
|
|
Inspection inspection = InspectionConverMapper.INSTANCE.fromAddInspectionRequestToInspection(addInspectionRequest); |
|
|
|
String code = DateUtils.generateCode("XJRW"); |
|
|
|
inspection.setCode(code); |
|
|
|
inspection.setTenantId(tenantId); |
|
|
|
inspection.setDeptId(dept.getId()); |
|
|
|
inspection.setCreateUser(userId); |
|
|
|
inspection.setCreateTime(DateUtils.now()); |
|
|
|
inspection.setMobile(user.getMobile()); |
|
|
|
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(AddInspectionRequest addInspectionRequest) { |
|
|
|
private JsonResult callPilot(Inspection inspection) { |
|
|
|
// TODO |
|
|
|
// 具体业务逻辑待实现,以下写法只是为了体现调用飞手平台成功或失败场景 |
|
|
|
if (StringUtils.isEmpty(addInspectionRequest.getName())) { |
|
|
|
if (StringUtils.isEmpty(inspection.getName())) { |
|
|
|
return JsonResult.error(AddInspectionCodeEnum.CALL_PILOT_IS_FAILED.getCode(), AddInspectionCodeEnum.CALL_PILOT_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
@@ -224,10 +244,10 @@ public class AddInspectionService { |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult callDSP(AddInspectionRequest addInspectionRequest) { |
|
|
|
private JsonResult callDSP(Inspection inspection) { |
|
|
|
// TODO |
|
|
|
// 具体业务逻辑待实现,以下写法只是为了体现调用DSP平台成功或失败场景 |
|
|
|
if (StringUtils.isEmpty(addInspectionRequest.getName())) { |
|
|
|
if (StringUtils.isEmpty(inspection.getName())) { |
|
|
|
return JsonResult.error(AddInspectionCodeEnum.CALL_DSP_IS_FAILED.getCode(), AddInspectionCodeEnum.CALL_DSP_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
@@ -235,16 +255,18 @@ public class AddInspectionService { |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 对接高德地图平台 |
|
|
|
* 对接高德地图平台:将经纬度转换成巡逻地点 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult callAmap(AddInspectionRequest addInspectionRequest) { |
|
|
|
// TODO |
|
|
|
// 具体业务逻辑待实现,以下写法只是为了体现调用高德地图平台成功或失败体现 |
|
|
|
if (StringUtils.isEmpty(addInspectionRequest.getName())) { |
|
|
|
return JsonResult.error(AddInspectionCodeEnum.CALL_AMAP_IS_FAILED.getCode(), AddInspectionCodeEnum.CALL_AMAP_IS_FAILED.getMsg()); |
|
|
|
} |
|
|
|
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); |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|