1、完善项目
2、完善合同 3、完善费用项 4、司机管理对接OCR 5、完善运输计划 6、完善临时额度
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package org.springblade.thirdparty.track.config;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 第三方api 轨迹配置类
|
||||
* @author bfhuange
|
||||
* @date 2024/12/18
|
||||
*/
|
||||
@ComponentScan("org.springblade.thirdparty.track")
|
||||
@EnableConfigurationProperties(TrackProperties.class)
|
||||
@Configuration
|
||||
public class ThirdPartyTrackAutoConfiguration {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.springblade.thirdparty.track.config;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* @author bfhuange
|
||||
* @since 2024/12/18
|
||||
*/
|
||||
public class TrackFeignClientConfig {
|
||||
@Bean
|
||||
public RequestInterceptor requestInterceptor() {
|
||||
return template -> {
|
||||
// 空实现屏蔽 全局拦截器 BladeFeignRequestInterceptor
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.springblade.thirdparty.track.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 轨迹 配置
|
||||
* @author bfhuange
|
||||
* @since 2024/12/16
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "third-party.track")
|
||||
public class TrackProperties {
|
||||
/**
|
||||
* 是否启用推送到轨迹系统
|
||||
*/
|
||||
private boolean enabled = false;
|
||||
/**
|
||||
* 轨迹基础路径
|
||||
*/
|
||||
private String baseUrl;
|
||||
/**
|
||||
* 系统标识
|
||||
*/
|
||||
private Integer bpsType;
|
||||
/**
|
||||
* 轨迹url
|
||||
*/
|
||||
private String trackUrlFormat = "/#/home/location-path?id=%s";
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.springblade.thirdparty.track.constant;
|
||||
|
||||
/**
|
||||
* 轨迹常量
|
||||
* @author bfhuange
|
||||
* @since 2024/12/16
|
||||
*/
|
||||
public class TrackConstant {
|
||||
/**
|
||||
* 响应成功状态码
|
||||
*/
|
||||
public static final Integer SUCCESS_CODE = 200;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springblade.thirdparty.track.exception;
|
||||
|
||||
/**
|
||||
* 轨迹异常
|
||||
* @author bfhuange
|
||||
* @since 2024/12/16
|
||||
*/
|
||||
public class TrackException extends RuntimeException {
|
||||
public TrackException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TrackException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.springblade.thirdparty.track.exception;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.api.ResultCode;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* @author bfhuange
|
||||
* @since 2025/3/29
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
@RestControllerAdvice
|
||||
public class TrackExceptionTranslator {
|
||||
|
||||
@ExceptionHandler(TrackException.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public R handleError(TrackException e) {
|
||||
log.error("track异常", e);
|
||||
return R.fail(ResultCode.INTERNAL_SERVER_ERROR, (Func.isEmpty(e.getMessage()) ? ResultCode.INTERNAL_SERVER_ERROR.getMessage() : e.getMessage()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.springblade.thirdparty.track.feign;
|
||||
|
||||
import org.springblade.thirdparty.track.config.TrackFeignClientConfig;
|
||||
import org.springblade.thirdparty.track.pojo.dto.TrackWaybillSendDTO;
|
||||
import org.springblade.thirdparty.track.pojo.vo.TrackResultVO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* 轨迹接口
|
||||
* @author bfhuange
|
||||
* @date 2024/12/16
|
||||
*/
|
||||
@FeignClient(name = "TRACK", url = "${thirdParty.track.baseUrl}", configuration = TrackFeignClientConfig.class)
|
||||
public interface ITrackClient {
|
||||
|
||||
/**
|
||||
* 发送运单
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/baseapi/nnl_waybill/send")
|
||||
TrackResultVO sendWaybills(@RequestBody TrackWaybillSendDTO param);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.springblade.thirdparty.track.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 运单发送参数
|
||||
* @author bfhuange
|
||||
* @since 2024/12/16
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class TrackWaybillSendDTO implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 历史运单id列表
|
||||
*/
|
||||
private List<String> ids;
|
||||
/**
|
||||
* 系统标识
|
||||
*/
|
||||
@JsonProperty("ibps_type")
|
||||
private Integer bpsType;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.springblade.thirdparty.track.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 轨迹响应结果
|
||||
* @author bfhuange
|
||||
* @date 2024/12/16
|
||||
*/
|
||||
@Data
|
||||
public class TrackResultVO implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 响应代码。200为正确
|
||||
*/
|
||||
private Integer code;
|
||||
/**
|
||||
* 对应的提示信息
|
||||
*/
|
||||
private String msg;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.springblade.thirdparty.track.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 轨迹 接口
|
||||
* @author bfhuange
|
||||
* @since 2024/12/16
|
||||
*/
|
||||
public interface ITrackService {
|
||||
|
||||
/**
|
||||
* 发送运单
|
||||
* @param ids
|
||||
*/
|
||||
void sendWaybills(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获取轨迹url
|
||||
* @param id 轨迹id
|
||||
* @return
|
||||
*/
|
||||
String getTrackUrl(String id);
|
||||
|
||||
/**
|
||||
* 获取轨迹url前缀,后面拼接id就是正常url
|
||||
* @return
|
||||
*/
|
||||
String getTrackUrlPrefix();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.springblade.thirdparty.track.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tool.utils.CollectionUtil;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.thirdparty.track.config.TrackProperties;
|
||||
import org.springblade.thirdparty.track.constant.TrackConstant;
|
||||
import org.springblade.thirdparty.track.exception.TrackException;
|
||||
import org.springblade.thirdparty.track.feign.ITrackClient;
|
||||
import org.springblade.thirdparty.track.pojo.dto.TrackWaybillSendDTO;
|
||||
import org.springblade.thirdparty.track.pojo.vo.TrackResultVO;
|
||||
import org.springblade.thirdparty.track.service.ITrackService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author bfhuange
|
||||
* @since 2024/12/16
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class TrackServiceImpl implements ITrackService {
|
||||
|
||||
private final TrackProperties trackProperties;
|
||||
private final ITrackClient client;
|
||||
|
||||
@Override
|
||||
public void sendWaybills(List<Long> ids) {
|
||||
if (!trackProperties.isEnabled()) {
|
||||
log.warn("未启用轨迹系统");
|
||||
return;
|
||||
}
|
||||
log.info("推送运单到轨迹,参数:{}", JSONUtil.toJsonStr(ids));
|
||||
if (CollectionUtil.isEmpty(ids)) {
|
||||
log.warn("推送运单到轨迹 参数为空");
|
||||
return;
|
||||
}
|
||||
List<String> list = ids.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.map(String::valueOf)
|
||||
.toList();
|
||||
if (CollectionUtil.isEmpty(ids)) {
|
||||
log.warn("推送运单到轨迹 参数为空");
|
||||
return;
|
||||
}
|
||||
TrackResultVO result = null;
|
||||
try {
|
||||
for (List<String> subList : Lists.partition(list, 100)) {
|
||||
result = client.sendWaybills(new TrackWaybillSendDTO(subList, trackProperties.getBpsType()));
|
||||
if (result == null || !TrackConstant.SUCCESS_CODE.equals(result.getCode())) {
|
||||
// 结果为空,或不是成功,抛出异常
|
||||
log.error("推送运单到轨迹异常 响应参数:{}", JSONUtil.toJsonStr(result));
|
||||
String message = Optional.ofNullable(result)
|
||||
.map(TrackResultVO::getMsg)
|
||||
.orElse(StringPool.EMPTY);
|
||||
throw new TrackException("推送运单到轨迹异常 " + message);
|
||||
}
|
||||
}
|
||||
} catch (TrackException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("推送运单到轨迹 异常", e);
|
||||
throw new TrackException("推送运单到轨迹异常");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTrackUrl(String id) {
|
||||
return trackProperties.getBaseUrl() + trackProperties.getTrackUrlFormat().formatted(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTrackUrlPrefix() {
|
||||
return trackProperties.getBaseUrl() + trackProperties.getTrackUrlFormat().replace("%s", "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
org.springblade.thirdparty.track.config.ThirdPartyTrackAutoConfiguration
|
||||
Reference in New Issue
Block a user