Procházet zdrojové kódy

修改新增任务代码

tags/v1.0.0^2
wanjing před 1 rokem
rodič
revize
c027748af7
4 změnil soubory, kde provedl 257 přidání a 74 odebrání
  1. +5
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/constant/SystemConstant.java
  2. +5
    -4
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/AddInspectionCodeEnum.java
  3. +92
    -70
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/add/AddInspectionService.java
  4. +155
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/GaodeUtil.java

+ 5
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/constant/SystemConstant.java Zobrazit soubor

@@ -7,4 +7,9 @@ public interface SystemConstant {
*/
String ROOT_DEPT_PID = "0";

/**
* 高德url地址
*/
String GAO_DE_URL = "https://restapi.amap.com/v3/geocode/regeo";

}

+ 5
- 4
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/AddInspectionCodeEnum.java Zobrazit soubor

@@ -33,10 +33,11 @@ public enum AddInspectionCodeEnum {
INSPECTION_TIME_IS_NULL(1230113, "巡检时间为空"),
ROAD_IS_NOT_EXIST(1230114, "公路不存在"),
SECTION_IS_NOT_EXIST(1230115, "路段不存在"),

CALL_PILOT_IS_FAILED(1230116, "对接飞手平台失败"),
CALL_DSP_IS_FAILED(1230117, "对接DSP平台失败"),
CALL_AMAP_IS_FAILED(1230118, "对接高德地图平台失败");
USER_IS_NOT_EXIST(1230116, "用户不存在"),
DEPT_IS_NOT_EXIST(1230117, "部门不存在"),
CALL_PILOT_IS_FAILED(123018, "对接飞手平台失败"),
CALL_DSP_IS_FAILED(1230119, "对接DSP平台失败"),
CALL_AMAP_IS_FAILED(1230120, "对接高德地图平台失败");

/**
* 错误码

+ 92
- 70
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/add/AddInspectionService.java Zobrazit soubor

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


+ 155
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/GaodeUtil.java Zobrazit soubor

@@ -0,0 +1,155 @@
package com.tuoheng.admin.utils;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.common.core.config.common.CommonConfig;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.Map;

@Slf4j
public class GaodeUtil {

/**
* 逆地理编码
*
* @param longitude 经度
* @param latitude 纬度
* @return
*/
public static String getGaodeAddress(String longitude, String latitude) {
String address = null;
JSONObject json = new JSONObject();
try {
json.put("key", CommonConfig.gaodeKey);
json.put("location", longitude + "," + latitude);
log.info("调用高德逆地理编码API请求参数:" + json);
String result = doGet(SystemConstant.GAO_DE_URL, json, null);
log.info("调用高德逆地理编码API成功:" + result);
JSONObject resultJson = JSONObject.parseObject(result.trim());
if("1".equals(resultJson.getString("status"))){
address = resultJson.getJSONObject("regeocode").getString("formatted_address");
}
} catch (Exception e) {
log.error("逆地理编码方法异常:", e);
}
return address;
}

/**
* 高德坐标转换
*
* @param longitude 经度
* @param latitude 纬度
* @return
*/
public static JSONObject getGaodeCoordinate(String longitude, String latitude) {
JSONObject json = new JSONObject();
JSONObject param = new JSONObject();
try {
//取六位小数
DecimalFormat df = new DecimalFormat("0.000000");
param.put("key", CommonConfig.gaodeKey);
param.put("locations", df.format(Double.valueOf(longitude)) + "," + df.format(Double.valueOf(latitude)));
param.put("coordsys", "gps");

log.info("调用高德坐标转换API请求参数:" + param);
String result = doGet("https://restapi.amap.com/v3/assistant/coordinate/convert", param, null);
log.info("调用高德坐标转换API成功:" + result);
JSONObject resultJson = JSONObject.parseObject(result.trim());
if("1".equals(resultJson.getString("status"))){
String locations = JSONObject.parseObject(result).getString("locations");
String lonStr = locations.substring(0, locations.indexOf(","));
String latStr = locations.substring(lonStr.length()+1);
json.put("longitude", lonStr);
json.put("latitude", latStr);
}
} catch (Exception e) {
log.error("高德坐标转换方法异常:", e);
}

return json;
}

public static String doGet(String url, JSONObject data, Map<String, String> properties) {
HttpURLConnection connection = null;
InputStream is = null;
BufferedReader br = null;
String result = null;// 返回结果字符串

StringBuffer urlNameString = new StringBuffer().append(url).append("?");
if (data != null) {
for (String key : data.keySet()) {
urlNameString.append(key).append("=").append(data.get(key)).append("&");
}
url = urlNameString.substring(0, urlNameString.lastIndexOf("&"));
}

try {
// 创建远程url连接对象
URL httpUrl = new URL(url);
// 通过远程url连接对象打开一个连接,强转成httpURLConnection类
connection = (HttpURLConnection) httpUrl.openConnection();
// 设置连接方式:get
connection.setRequestMethod("GET");
// 设置连接主机服务器的超时时间:15000毫秒
connection.setConnectTimeout(15000);
// 设置读取远程返回的数据时间:60000毫秒
connection.setReadTimeout(60000);
if(null != properties && !properties.isEmpty()){
for (String key:properties.keySet()){
connection.setRequestProperty(key, properties.get(key));
}
}
// 发送请求
connection.connect();
// 通过connection连接,获取输入流
if (connection.getResponseCode() == 200) {
is = connection.getInputStream();
// 封装输入流is,并指定字符集
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
// 存放数据
StringBuffer sbf = new StringBuffer();
String temp = null;
while ((temp = br.readLine()) != null) {
sbf.append(temp);
sbf.append("\r\n");
}
result = sbf.toString();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭资源
if (null != br) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}

if (null != is) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}

connection.disconnect();// 关闭远程连接
}
return result;
}

}

Načítá se…
Zrušit
Uložit