43 changed files with 1917 additions and 360 deletions
@ -0,0 +1,79 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.config; |
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.slf4j.MDC; |
||||||
|
import org.springblade.core.tool.utils.ThreadLocalUtil; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.core.task.TaskDecorator; |
||||||
|
import org.springframework.http.HttpHeaders; |
||||||
|
import org.springframework.scheduling.annotation.EnableAsync; |
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
||||||
|
import org.springframework.web.context.request.RequestAttributes; |
||||||
|
import org.springframework.web.context.request.RequestContextHolder; |
||||||
|
|
||||||
|
import javax.annotation.Nonnull; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.Executor; |
||||||
|
import java.util.concurrent.ThreadPoolExecutor; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
@Slf4j |
||||||
|
@EnableAsync |
||||||
|
public class ExecutorConfig { |
||||||
|
|
||||||
|
@Bean |
||||||
|
public Executor asyncExecutor() { |
||||||
|
log.info("start async executor"); |
||||||
|
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); |
||||||
|
// 配置核心线程数
|
||||||
|
threadPoolTaskExecutor.setCorePoolSize(10); |
||||||
|
// 配置最大线程数
|
||||||
|
threadPoolTaskExecutor.setMaxPoolSize(20); |
||||||
|
// 配置队列大小
|
||||||
|
threadPoolTaskExecutor.setQueueCapacity(50); |
||||||
|
// 配置线程池中线程的名称前缀
|
||||||
|
threadPoolTaskExecutor.setThreadNamePrefix("ASYNC_THREAD_"); |
||||||
|
// HelloWorldServiceImpl rejection-policy: 当pool已经达到max size时,如何处理新任务:
|
||||||
|
// CallerRunsPolicy: 不在新线程中执行任务,而是由调用者所在的线程来执行;
|
||||||
|
// AbortPolicy: 拒绝执行新任务,并抛出RejectedExecutionException异常;
|
||||||
|
// DiscardPolicy:丢弃当前将要加入队列的任务;
|
||||||
|
// DiscardOldestPolicy:丢弃任务队列中最旧的任务;
|
||||||
|
threadPoolTaskExecutor.setRejectedExecutionHandler( |
||||||
|
new ThreadPoolExecutor.CallerRunsPolicy() |
||||||
|
); |
||||||
|
threadPoolTaskExecutor.setTaskDecorator(new ContextCopyingDecorator()); |
||||||
|
threadPoolTaskExecutor.initialize(); |
||||||
|
return threadPoolTaskExecutor; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
static class ContextCopyingDecorator implements TaskDecorator { |
||||||
|
@Nonnull |
||||||
|
@Override |
||||||
|
public Runnable decorate(@Nonnull Runnable runnable) { |
||||||
|
RequestAttributes context = RequestContextHolder.currentRequestAttributes(); |
||||||
|
HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext"); |
||||||
|
Map<String, String> mdcMap = MDC.getCopyOfContextMap(); |
||||||
|
return () -> { |
||||||
|
try { |
||||||
|
ThreadLocalUtil.put("bladeContext", headers); |
||||||
|
if (mdcMap != null && !mdcMap.isEmpty()) { |
||||||
|
MDC.setContextMap(mdcMap); |
||||||
|
} |
||||||
|
RequestContextHolder.setRequestAttributes(context); |
||||||
|
|
||||||
|
runnable.run(); |
||||||
|
} finally { |
||||||
|
RequestContextHolder.resetRequestAttributes(); |
||||||
|
if (mdcMap != null) { |
||||||
|
mdcMap.clear(); |
||||||
|
} |
||||||
|
ThreadLocalUtil.clear(); |
||||||
|
MDC.clear(); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.config; |
||||||
|
|
||||||
|
import com.logpm.factorydata.jinpai.interceptor.FactoryAccountsInterceptor; |
||||||
|
import com.logpm.factorydata.jinpai.interceptor.LocalServerLoginAccountsInterceptor; |
||||||
|
import com.logpm.factorydata.jinpai.service.IFactoryTokenService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.redis.cache.BladeRedis; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.core.env.Environment; |
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
@AllArgsConstructor |
||||||
|
public class InterceptorAdapterConfig implements WebMvcConfigurer { |
||||||
|
|
||||||
|
private final IFactoryTokenService factoryTokenService; |
||||||
|
|
||||||
|
private final BladeRedis redis; |
||||||
|
|
||||||
|
private final Environment environment; |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void addInterceptors(InterceptorRegistry interceptorRegistry) { |
||||||
|
// interceptorRegistry.addInterceptor(new FactoryAccountsInterceptor(factoryTokenService))
|
||||||
|
// .addPathPatterns("/**").order(1);
|
||||||
|
interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis, environment)) |
||||||
|
.addPathPatterns("/**").order(2); |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.config; |
||||||
|
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
|
||||||
|
/** |
||||||
|
* xxl-job config |
||||||
|
* |
||||||
|
* @author xuxueli 2017-04-28 |
||||||
|
*/ |
||||||
|
@Configuration(proxyBeanMethods = false) |
||||||
|
public class XxlJobConfig { |
||||||
|
private final Logger logger = LoggerFactory.getLogger(XxlJobConfig.class); |
||||||
|
|
||||||
|
@Value("${xxl.job.admin.addresses}") |
||||||
|
private String adminAddresses; |
||||||
|
|
||||||
|
@Value("${xxl.job.executor.appname}") |
||||||
|
private String appName; |
||||||
|
|
||||||
|
@Value("${xxl.job.executor.ip}") |
||||||
|
private String ip; |
||||||
|
|
||||||
|
@Value("${xxl.job.executor.port}") |
||||||
|
private int port; |
||||||
|
|
||||||
|
@Value("${xxl.job.accessToken}") |
||||||
|
private String accessToken; |
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logpath}") |
||||||
|
private String logPath; |
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logretentiondays}") |
||||||
|
private int logRetentionDays; |
||||||
|
|
||||||
|
|
||||||
|
@Bean |
||||||
|
public XxlJobSpringExecutor xxlJobExecutor() { |
||||||
|
logger.info(">>>>>>>>>>> xxl-job config init."); |
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); |
||||||
|
xxlJobSpringExecutor.setAdminAddresses(adminAddresses); |
||||||
|
xxlJobSpringExecutor.setAppName(appName); |
||||||
|
xxlJobSpringExecutor.setIp(ip); |
||||||
|
xxlJobSpringExecutor.setPort(port); |
||||||
|
xxlJobSpringExecutor.setAccessToken(accessToken); |
||||||
|
xxlJobSpringExecutor.setLogPath(logPath); |
||||||
|
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); |
||||||
|
|
||||||
|
return xxlJobSpringExecutor; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP; |
||||||
|
* |
||||||
|
* 1、引入依赖: |
||||||
|
* <dependency> |
||||||
|
* <groupId>org.springframework.cloud</groupId> |
||||||
|
* <artifactId>spring-cloud-commons</artifactId> |
||||||
|
* <version>${version}</version> |
||||||
|
* </dependency> |
||||||
|
* |
||||||
|
* 2、配置文件,或者容器启动变量 |
||||||
|
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.' |
||||||
|
* |
||||||
|
* 3、获取IP |
||||||
|
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
@Data |
||||||
|
@TableName("factory_token") |
||||||
|
@ApiModel(value = "FactoryToken对象", description = "工厂账户token") |
||||||
|
public class FactoryToken extends BaseEntity { |
||||||
|
|
||||||
|
@ApiModelProperty("token") |
||||||
|
private String token; |
||||||
|
|
||||||
|
@ApiModelProperty("token摘要") |
||||||
|
private String tokenAbst; |
||||||
|
|
||||||
|
@JsonFormat( |
||||||
|
pattern = "yyyy-MM-dd HH:mm:ss" |
||||||
|
) |
||||||
|
@ApiModelProperty("过期时间") |
||||||
|
private Date expireTime; |
||||||
|
|
||||||
|
@ApiModelProperty("企业id") |
||||||
|
private String corpid; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,109 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
|
||||||
|
/** |
||||||
|
* 金牌订单明细 实体类 |
||||||
|
* |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-26 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("jp_push_order_detail") |
||||||
|
@ApiModel(value = "金牌订单明细", description = "金牌订单明细") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class PushOrderDetailEntity extends BaseEntity { |
||||||
|
|
||||||
|
@ApiModelProperty(name = "订单id") |
||||||
|
private String orderId; |
||||||
|
@ApiModelProperty(name = "日志id") |
||||||
|
private String logId; |
||||||
|
|
||||||
|
@ApiModelProperty(name = "明细编号") |
||||||
|
private String itemId; |
||||||
|
@ApiModelProperty(name = "发运类型(gx:干线, zy:直运, db:短驳)") |
||||||
|
private String transportType; |
||||||
|
@ApiModelProperty(name = "发站") |
||||||
|
private String sendSite; |
||||||
|
@ApiModelProperty(name = "到站") |
||||||
|
private String endSite; |
||||||
|
@ApiModelProperty(name = "收货联系人名称") |
||||||
|
private String recvLinker; |
||||||
|
@ApiModelProperty(name = "收货联系人手机") |
||||||
|
private String recvMobile; |
||||||
|
@ApiModelProperty(name = "收货联系人电话") |
||||||
|
private String recvPhone; |
||||||
|
@ApiModelProperty(name = "收货地址") |
||||||
|
private String recvAddr; |
||||||
|
@ApiModelProperty(name = "代收款") |
||||||
|
private String codAmount; |
||||||
|
@ApiModelProperty(name = "物品名称") |
||||||
|
private String goodsName; |
||||||
|
@ApiModelProperty(name = "物品数量(件)") |
||||||
|
private String goodsNumber; |
||||||
|
@ApiModelProperty(name = "物品重量(吨)") |
||||||
|
private String goodsWeight; |
||||||
|
@ApiModelProperty(name = "物品毛重(吨)") |
||||||
|
private String goodsGrossWeight; |
||||||
|
@ApiModelProperty(name = "物品净重(吨)") |
||||||
|
private String goodsNetWeight; |
||||||
|
@ApiModelProperty(name = "物品体积(方)") |
||||||
|
private String goodsVolume; |
||||||
|
@ApiModelProperty(name = "货品类型") |
||||||
|
private String goodsType; |
||||||
|
@ApiModelProperty(name = "货品包装说明") |
||||||
|
private String goodsPack; |
||||||
|
@ApiModelProperty(name = "长") |
||||||
|
private String carLength; |
||||||
|
@ApiModelProperty(name = "宽") |
||||||
|
private String carWidth; |
||||||
|
@ApiModelProperty(name = "高") |
||||||
|
private String carHeight; |
||||||
|
@ApiModelProperty(name = "订单类型(1-零售正单、2-普通零售单、3-样块单、4-增补单、5-返修单、6-缺件单、7-售后单、8-精板或其他)") |
||||||
|
private String orderType; |
||||||
|
@ApiModelProperty(name = "承运类型编码(编码含义:sfwl- 三方物流;sczp- 干仓配)") |
||||||
|
private String shipType; |
||||||
|
@ApiModelProperty(name = "送货模式编码(编码含义:gc-wf-基地-外发;sc-zt-干仓配-自提;sc-ps-干仓配-2C;sc-wf-干仓配-2B)") |
||||||
|
private String transType; |
||||||
|
@ApiModelProperty(name = "门店名称") |
||||||
|
private String shopName; |
||||||
|
@ApiModelProperty(name = "门店编码") |
||||||
|
private String shopCode; |
||||||
|
@ApiModelProperty(name = "门店电话") |
||||||
|
private String shopPhone; |
||||||
|
@ApiModelProperty(name = "门店地址") |
||||||
|
private String shopAddr; |
||||||
|
@ApiModelProperty(name = "预约送货时间") |
||||||
|
private String appointmentTime; |
||||||
|
@ApiModelProperty(name = "安装地址") |
||||||
|
private String installAddr; |
||||||
|
@ApiModelProperty(name = "安装联系人") |
||||||
|
private String installLinker; |
||||||
|
@ApiModelProperty(name = "安装联系电话") |
||||||
|
private String installPhone; |
||||||
|
@ApiModelProperty(name = "客户单号(YS单号)") |
||||||
|
private String customOrderNo; |
||||||
|
@ApiModelProperty(name = "客户明细单号(DD单号)") |
||||||
|
private String customItemNo; |
||||||
|
@ApiModelProperty(name = "箱码列表") |
||||||
|
private String boxCodeList; |
||||||
|
@ApiModelProperty(name = "包件品类") |
||||||
|
private String boxDetailList; |
||||||
|
|
||||||
|
@ApiModelProperty(name = "预留1", notes = "") |
||||||
|
private String reserve1; |
||||||
|
@ApiModelProperty(name = "预留2", notes = "") |
||||||
|
private String reserve2; |
||||||
|
@ApiModelProperty(name = "预留3", notes = "") |
||||||
|
private String reserve3; |
||||||
|
@ApiModelProperty(name = "预留4", notes = "") |
||||||
|
private String reserve4; |
||||||
|
@ApiModelProperty(name = "预留5", notes = "") |
||||||
|
private String reserve5; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
|
||||||
|
/** |
||||||
|
* 金牌推送的下单数据 实体类 |
||||||
|
* |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-26 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("jp_push_order") |
||||||
|
@ApiModel(value = "金牌订单", description = "金牌订单") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class PushOrderEntity extends BaseEntity { |
||||||
|
|
||||||
|
@ApiModelProperty(name = "日志id") |
||||||
|
private String logId; |
||||||
|
@ApiModelProperty(name = "装车单号") |
||||||
|
private String transportNo; |
||||||
|
@ApiModelProperty(name = "计划发车时间(yyyy-MM-dd HH:mm:ss)") |
||||||
|
private String planBeginTime; |
||||||
|
@ApiModelProperty(name = "计划到达时间(yyyy-MM-dd HH:mm:ss)") |
||||||
|
private String planEndTime; |
||||||
|
@ApiModelProperty(name = "货品总重量(吨)") |
||||||
|
private String goodsTotalWeight; |
||||||
|
@ApiModelProperty(name = "货品总数量(件)") |
||||||
|
private String goodsTotalNumber; |
||||||
|
@ApiModelProperty(name = "货品总体积(方)") |
||||||
|
private String goodsTotalVolume; |
||||||
|
@ApiModelProperty(name = "始发站") |
||||||
|
private String sendSite; |
||||||
|
@ApiModelProperty(name = "途经站") |
||||||
|
private String passSite; |
||||||
|
@ApiModelProperty(name = "终点站") |
||||||
|
private String endSite; |
||||||
|
@ApiModelProperty(name = "车型") |
||||||
|
private String carType; |
||||||
|
@ApiModelProperty(name = "车长") |
||||||
|
private String carSize; |
||||||
|
@ApiModelProperty(name = "制单人") |
||||||
|
private String userName; |
||||||
|
@ApiModelProperty(name = "基地") |
||||||
|
private String orgName; |
||||||
|
|
||||||
|
@ApiModelProperty(name = "预留1", notes = "") |
||||||
|
private String reserve1; |
||||||
|
@ApiModelProperty(name = "预留2", notes = "") |
||||||
|
private String reserve2; |
||||||
|
@ApiModelProperty(name = "预留3", notes = "") |
||||||
|
private String reserve3; |
||||||
|
@ApiModelProperty(name = "预留4", notes = "") |
||||||
|
private String reserve4; |
||||||
|
@ApiModelProperty(name = "预留5", notes = "") |
||||||
|
private String reserve5; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.enums; |
||||||
|
|
||||||
|
import org.springblade.common.model.IDict; |
||||||
|
|
||||||
|
/** |
||||||
|
* 金牌基地枚举 |
||||||
|
* |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-28 |
||||||
|
*/ |
||||||
|
public enum BusSourceEnums implements IDict<String> { |
||||||
|
|
||||||
|
XIAMEN("1", "厦门基地"), |
||||||
|
SIYANG("2", "泗阳基地"), |
||||||
|
OB_XIAMEN("4", "橙鸟厦门仓"), |
||||||
|
OB_FOSHAN("5", "橙鸟佛山仓"), |
||||||
|
CHENGDU("6", "成都基地"), |
||||||
|
; |
||||||
|
|
||||||
|
BusSourceEnums(String code, String text) { |
||||||
|
init(code, text); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,87 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.interceptor; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.logpm.factorydata.jinpai.wrapper.RequestWrapper; |
||||||
|
import com.logpm.factorydata.jinpai.service.IFactoryTokenService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.log4j.Log4j2; |
||||||
|
import org.springblade.common.exception.CustomerException; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.StringUtil; |
||||||
|
import org.springframework.web.servlet.HandlerInterceptor; |
||||||
|
import org.springframework.web.servlet.ModelAndView; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.PrintWriter; |
||||||
|
|
||||||
|
@Log4j2 |
||||||
|
@AllArgsConstructor |
||||||
|
public class FactoryAccountsInterceptor implements HandlerInterceptor { |
||||||
|
|
||||||
|
private final IFactoryTokenService factoryTokenService; |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException { |
||||||
|
try { |
||||||
|
|
||||||
|
RequestWrapper myRequestWrapper = new RequestWrapper(request); |
||||||
|
String body = myRequestWrapper.getBody(); |
||||||
|
JSONObject jsonObject = JSONObject.parseObject(body); |
||||||
|
//获取头中参数
|
||||||
|
String token = request.getHeader("Authorization"); |
||||||
|
String corpId = request.getHeader("corpid"); |
||||||
|
if(StringUtil.isBlank(corpId)){ |
||||||
|
corpId = jsonObject.getString("corpid"); |
||||||
|
} |
||||||
|
if(!StringUtil.hasLength(token)){ |
||||||
|
returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,token有误"))); |
||||||
|
return false; |
||||||
|
} |
||||||
|
if(!StringUtil.hasLength(corpId)){ |
||||||
|
returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,corpId有误"))); |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
log.info("##########preHandle: token={}",token); |
||||||
|
//验证token
|
||||||
|
boolean b = factoryTokenService.verifyToken(token,corpId); |
||||||
|
if(!b){ |
||||||
|
returnJson(response,JSONObject.toJSONString(R.fail(203,"认证不通过,token不存在或已过期"))); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} catch (Exception e) { |
||||||
|
returnJson(response,JSONObject.toJSONString(R.fail(500,"服务异常,请联系管理员"))); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void returnJson(HttpServletResponse response, String json) { |
||||||
|
PrintWriter writer = null; |
||||||
|
response.setCharacterEncoding("UTF-8"); |
||||||
|
response.setContentType("application/json"); |
||||||
|
try { |
||||||
|
writer = response.getWriter(); |
||||||
|
writer.print(json); |
||||||
|
|
||||||
|
} catch (IOException e) { |
||||||
|
System.out.println(e.getMessage()); |
||||||
|
} finally { |
||||||
|
if (writer != null){ |
||||||
|
writer.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
||||||
|
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
||||||
|
HandlerInterceptor.super.afterCompletion(request, response, handler, ex); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,100 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.interceptor; |
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest; |
||||||
|
import cn.hutool.http.HttpResponse; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.logpm.factorydata.jinpai.wrapper.CustomHttpServletRequestWrapper; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.log4j.Log4j2; |
||||||
|
import org.springblade.common.cache.CacheNames; |
||||||
|
import org.springblade.common.constant.LauncherConstant; |
||||||
|
import org.springblade.common.exception.CustomerException; |
||||||
|
import org.springblade.core.redis.cache.BladeRedis; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.ThreadLocalUtil; |
||||||
|
import org.springframework.core.env.Environment; |
||||||
|
import org.springframework.http.HttpHeaders; |
||||||
|
import org.springframework.web.context.request.RequestContextHolder; |
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes; |
||||||
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.PrintWriter; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
@Log4j2 |
||||||
|
@AllArgsConstructor |
||||||
|
public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapter { |
||||||
|
|
||||||
|
private final BladeRedis bladeRedis; |
||||||
|
private final Environment environment; |
||||||
|
@Override |
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException { |
||||||
|
|
||||||
|
|
||||||
|
try { |
||||||
|
CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request); |
||||||
|
String account ="shujutongbu"; |
||||||
|
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); |
||||||
|
if(Objects.isNull(data)){ |
||||||
|
String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; |
||||||
|
HttpRequest urlRequest = HttpRequest.post(url); |
||||||
|
urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); |
||||||
|
urlRequest.header("Tenant-Id", "627683"); |
||||||
|
|
||||||
|
Map<String, Object> params = new HashMap<>(); |
||||||
|
params.put("grant_type", "local_server"); |
||||||
|
params.put("scope", "all"); |
||||||
|
params.put("username", account); |
||||||
|
params.put("tenantId", "627683"); |
||||||
|
HttpResponse execute = urlRequest.form(params).execute(); |
||||||
|
String body = execute.body(); |
||||||
|
data = JSONObject.parseObject(body); |
||||||
|
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,3200L); |
||||||
|
} |
||||||
|
|
||||||
|
// 修改或添加header
|
||||||
|
|
||||||
|
// 发送登录请求
|
||||||
|
log.info("##########preHandle: request={}", request); |
||||||
|
|
||||||
|
wrappedRequest.addHeader("Blade-Auth", "bearer "+data.getString("access_token")); |
||||||
|
HttpHeaders httpHeaders = new HttpHeaders(); |
||||||
|
httpHeaders.add("Blade-Auth","bearer "+data.get("access_token") ); |
||||||
|
httpHeaders.add( "Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); |
||||||
|
ThreadLocalUtil.put("bladeContext", httpHeaders); |
||||||
|
|
||||||
|
|
||||||
|
// 用包装后的request替换原始request
|
||||||
|
request = wrappedRequest; |
||||||
|
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); |
||||||
|
return true; |
||||||
|
} catch (Exception e) { |
||||||
|
returnJson(response, JSONObject.toJSONString(R.fail(500, "服务异常,请联系管理员"))); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void returnJson(HttpServletResponse response, String json) { |
||||||
|
PrintWriter writer = null; |
||||||
|
response.setCharacterEncoding("UTF-8"); |
||||||
|
response.setContentType("application/json"); |
||||||
|
try { |
||||||
|
writer = response.getWriter(); |
||||||
|
writer.print(json); |
||||||
|
|
||||||
|
} catch (IOException e) { |
||||||
|
System.out.println(e.getMessage()); |
||||||
|
} finally { |
||||||
|
if (writer != null) { |
||||||
|
writer.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,300 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.job; |
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil; |
||||||
|
import cn.hutool.core.convert.Convert; |
||||||
|
import cn.hutool.core.date.DateUtil; |
||||||
|
import cn.hutool.core.util.NumberUtil; |
||||||
|
import cn.hutool.core.util.ObjectUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import cn.hutool.json.JSONObject; |
||||||
|
import cn.hutool.json.JSONUtil; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.logpm.factorydata.base.feign.IFactoryDataBaseClient; |
||||||
|
import com.logpm.factorydata.base.vo.FactoryWarehouseBindVO; |
||||||
|
import com.logpm.factorydata.enums.BrandEnums; |
||||||
|
import com.logpm.factorydata.feign.IFactoryDataClient; |
||||||
|
import com.logpm.factorydata.jinpai.entity.DeliveryNoteEntity; |
||||||
|
import com.logpm.factorydata.jinpai.entity.OrderInfoEntity; |
||||||
|
import com.logpm.factorydata.jinpai.entity.PackageInfoEntity; |
||||||
|
import com.logpm.factorydata.jinpai.enums.BusSourceEnums; |
||||||
|
import com.logpm.factorydata.jinpai.service.DeliveryNoteService; |
||||||
|
import com.logpm.factorydata.jinpai.service.OrderInfoService; |
||||||
|
import com.logpm.factorydata.jinpai.service.PackageInfoService; |
||||||
|
import com.logpm.factorydata.jinpai.vo.ThirdPlWarehouseMappingVO; |
||||||
|
import com.logpm.factorydata.vo.SendMsg; |
||||||
|
import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; |
||||||
|
import com.logpm.trunkline.entity.TrunklineAdvanceEntity; |
||||||
|
import com.xxl.job.core.biz.model.ReturnT; |
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.common.constant.HttpConstants; |
||||||
|
import org.springblade.common.constant.factorydata.FactoryDataConstants; |
||||||
|
import org.springblade.common.model.IDict; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springframework.scheduling.annotation.Async; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-02 |
||||||
|
*/ |
||||||
|
@AllArgsConstructor |
||||||
|
@Component |
||||||
|
@Slf4j |
||||||
|
public class AdvanceJob { |
||||||
|
|
||||||
|
private final DeliveryNoteService deliveryNoteService; |
||||||
|
private final OrderInfoService orderInfoService; |
||||||
|
private final PackageInfoService packageInfoService; |
||||||
|
|
||||||
|
private final IFactoryDataBaseClient baseClient; |
||||||
|
private final IFactoryDataClient factoryDataClient; |
||||||
|
|
||||||
|
/** |
||||||
|
* 定时扫描数据库,保存所有齐套未推送的数据 |
||||||
|
* |
||||||
|
* @param param |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
@XxlJob("createAdvance") |
||||||
|
public ReturnT<String> createAdvance(String param) throws Exception { |
||||||
|
// 查询出齐套未生成暂存单的订单数据
|
||||||
|
Map<String, DeliveryNoteEntity> deliveryNoteEntityMap = new HashMap<>(); |
||||||
|
Map<String, OrderInfoEntity> orderInfoEntityMap = new HashMap<>(); |
||||||
|
Map<String, List<PackageInfoEntity>> packageInfoEntityMap = new HashMap<>(); |
||||||
|
|
||||||
|
Set<String> deliveryNoteSet = new HashSet<>(); |
||||||
|
Set<String> orderInfoSet = new HashSet<>(); |
||||||
|
// 按dd编号分组
|
||||||
|
List<PackageInfoEntity> list = packageInfoService.list(Wrappers.<PackageInfoEntity>lambdaQuery().eq(PackageInfoEntity::getSendStatus, 0)); |
||||||
|
if (CollUtil.isNotEmpty(list)) { |
||||||
|
for (PackageInfoEntity entity : list) { |
||||||
|
deliveryNoteSet.add(entity.getOrderId()); |
||||||
|
orderInfoSet.add(entity.getOmsExtOrderNo()); |
||||||
|
// 将数据封装到packageInfoEntityMap中 其中omsExtOrderNo为key
|
||||||
|
packageInfoEntityMap.computeIfAbsent(entity.getOmsExtOrderNo(), k -> new ArrayList<>()).add(entity); |
||||||
|
} |
||||||
|
// 根据订单数据查询出所有订单明细和包件信息
|
||||||
|
List<DeliveryNoteEntity> deliveryNoteEntities = deliveryNoteService.list(Wrappers.<DeliveryNoteEntity>lambdaQuery().in(DeliveryNoteEntity::getOrderId, deliveryNoteSet)); |
||||||
|
if (CollUtil.isNotEmpty(deliveryNoteEntities)) { |
||||||
|
for (DeliveryNoteEntity entity : deliveryNoteEntities) { |
||||||
|
deliveryNoteEntityMap.put(entity.getOrderId(), entity); |
||||||
|
} |
||||||
|
} |
||||||
|
List<OrderInfoEntity> orderInfoEntities = orderInfoService.list(Wrappers.<OrderInfoEntity>lambdaQuery().in(OrderInfoEntity::getOmsExtOrderNo, orderInfoSet)); |
||||||
|
if (CollUtil.isNotEmpty(orderInfoEntities)) { |
||||||
|
for (OrderInfoEntity entity : orderInfoEntities) { |
||||||
|
orderInfoEntityMap.put(entity.getOmsExtOrderNo(), entity); |
||||||
|
} |
||||||
|
} |
||||||
|
// 组装数据,然后生成暂存单
|
||||||
|
buildAdvance(packageInfoEntityMap, deliveryNoteEntityMap, orderInfoEntityMap); |
||||||
|
// 修改包件的发送状态 TODO 后面修改为暂存单消费完成之后回调更新状态
|
||||||
|
List<PackageInfoEntity> updatePackageList = new ArrayList<>(); |
||||||
|
for (PackageInfoEntity entity : list) { |
||||||
|
PackageInfoEntity updateEntity = new PackageInfoEntity(); |
||||||
|
updateEntity.setSendStatus(1); |
||||||
|
updateEntity.setId(entity.getId()); |
||||||
|
updatePackageList.add(updateEntity); |
||||||
|
} |
||||||
|
if (CollUtil.isNotEmpty(updatePackageList)) { |
||||||
|
packageInfoService.updateBatchById(updatePackageList); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return ReturnT.SUCCESS; |
||||||
|
} |
||||||
|
|
||||||
|
@Async("asyncExecutor") |
||||||
|
public void buildAdvance(Map<String, List<PackageInfoEntity>> packageMap, Map<String, DeliveryNoteEntity> deliveryMap, |
||||||
|
Map<String, OrderInfoEntity> orderInfoMap) { |
||||||
|
// 新起线程构建暂存单发送mq
|
||||||
|
// 获取非干线仓库映射表数据
|
||||||
|
Map<String, ThirdPlWarehouseMappingVO> thirdPlWarehouseMapping = new HashMap<>(); |
||||||
|
List<ThirdPlWarehouseMappingVO> warehouseMappingVOList = deliveryNoteService.getThirdPlWarehouseMappingVO(); |
||||||
|
if (CollUtil.isNotEmpty(warehouseMappingVOList)) { |
||||||
|
warehouseMappingVOList.forEach(vo -> { |
||||||
|
thirdPlWarehouseMapping.put(vo.getArriveOrgName(), vo); |
||||||
|
}); |
||||||
|
} |
||||||
|
Map<String, FactoryWarehouseBindVO> warehouseBindVOMap = new HashMap<>(); |
||||||
|
if (CollUtil.isNotEmpty(deliveryMap)) { |
||||||
|
for (Map.Entry<String, DeliveryNoteEntity> entry : deliveryMap.entrySet()) { |
||||||
|
DeliveryNoteEntity deliveryNoteEntity = entry.getValue(); |
||||||
|
if (ObjectUtil.isNotEmpty(deliveryNoteEntity)) { |
||||||
|
// 获取工厂基地绑定的始发仓信息
|
||||||
|
String textByCode = IDict.getTextByCode(BusSourceEnums.class, deliveryNoteEntity.getBusSource()); |
||||||
|
R<FactoryWarehouseBindVO> warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(BrandEnums.JP.getValue(), textByCode); |
||||||
|
if (ObjectUtil.equal(HttpConstants.HTTP.HTTP_RESOURCE_CODE.SUCCESS_CODE, warehouseByBrandAndSiteName.getCode())) { |
||||||
|
FactoryWarehouseBindVO data = warehouseByBrandAndSiteName.getData(); |
||||||
|
if (ObjectUtil.isNotNull(data)) { |
||||||
|
warehouseBindVOMap.put(deliveryNoteEntity.getBusSource(), data); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
// 组装暂存单数据
|
||||||
|
List<JSONObject> advances = new ArrayList<>(); |
||||||
|
for (Map.Entry<String, List<PackageInfoEntity>> stringListEntry : packageMap.entrySet()) { |
||||||
|
String key = stringListEntry.getKey(); |
||||||
|
OrderInfoEntity orderInfo = orderInfoMap.get(key); |
||||||
|
if (ObjectUtil.isEmpty(orderInfo)) { |
||||||
|
log.error("订单明细信息不存在,dd单号:{}", key); |
||||||
|
continue; |
||||||
|
} |
||||||
|
DeliveryNoteEntity order = deliveryMap.get(orderInfo.getOrderId()); |
||||||
|
if (ObjectUtil.isEmpty(order)) { |
||||||
|
log.error("订单信息不存在,订单号:{}", orderInfo.getOrderId()); |
||||||
|
continue; |
||||||
|
} |
||||||
|
List<PackageInfoEntity> value = stringListEntry.getValue(); |
||||||
|
TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); |
||||||
|
// 承运商是汇通的数据 走干线,不是汇通的直接走仓配。
|
||||||
|
String carrierName = order.getCarrierName(); |
||||||
|
Long warehouseId = null; |
||||||
|
String warehouseName = ""; |
||||||
|
String tenantId = ""; |
||||||
|
if (ObjectUtil.equal(carrierName, "广州市汇通运输有限公司")) { |
||||||
|
if (ObjectUtil.isNotNull(warehouseBindVOMap.get(order.getBusSource()))) { |
||||||
|
warehouseId = warehouseBindVOMap.get(order.getBusSource()).getWarehouseId(); |
||||||
|
warehouseName = warehouseBindVOMap.get(order.getBusSource()).getWarehouseName(); |
||||||
|
tenantId = warehouseBindVOMap.get(order.getBusSource()).getTenantId(); |
||||||
|
} |
||||||
|
} else { |
||||||
|
if (ObjectUtil.isNotNull(thirdPlWarehouseMapping.get(order.getArriveOrgName()))) { |
||||||
|
if (ObjectUtil.isNotEmpty(thirdPlWarehouseMapping.get(order.getArriveOrgName()).getWarehouseId())) { |
||||||
|
warehouseId = Convert.toLong(thirdPlWarehouseMapping.get(order.getArriveOrgName()).getWarehouseId()); |
||||||
|
} |
||||||
|
warehouseName = thirdPlWarehouseMapping.get(order.getArriveOrgName()).getWarehouseName(); |
||||||
|
tenantId = thirdPlWarehouseMapping.get(order.getArriveOrgName()).getTenantId(); |
||||||
|
} |
||||||
|
} |
||||||
|
advanceEntity.setTenantId(tenantId); |
||||||
|
advanceEntity.setStatus(0); |
||||||
|
advanceEntity.setIsDeleted(0); |
||||||
|
advanceEntity.setHasPackage(CollUtil.isNotEmpty(value) ? 1 : 0); |
||||||
|
advanceEntity.setOrderType(orderInfo.getYjOrderType()); |
||||||
|
advanceEntity.setBrand(BrandEnums.JP.getValue()); |
||||||
|
advanceEntity.setSiteName(IDict.getTextByCode(BusSourceEnums.class, order.getBusSource())); |
||||||
|
advanceEntity.setArea(""); |
||||||
|
advanceEntity.setTotalNum(CollUtil.isNotEmpty(value) ? value.size() : 0); |
||||||
|
advanceEntity.setPackName(""); |
||||||
|
advanceEntity.setPackCode(""); |
||||||
|
advanceEntity.setWarehouseId(warehouseId); |
||||||
|
advanceEntity.setWarehouseName(warehouseName); |
||||||
|
|
||||||
|
if (StrUtil.equals("sczp", order.getDistributionMode())) { |
||||||
|
advanceEntity.setIsGcp(1); |
||||||
|
} else { |
||||||
|
advanceEntity.setIsGcp(0); |
||||||
|
} |
||||||
|
advanceEntity.setCarrierName(carrierName); |
||||||
|
advanceEntity.setSystemType("线上"); |
||||||
|
advanceEntity.setMatingType("1"); |
||||||
|
advanceEntity.setSenderName(order.getConsignerName()); |
||||||
|
advanceEntity.setSenderPhone(order.getConsignerMobile()); |
||||||
|
advanceEntity.setSenderAddress(order.getConsignerAddr()); |
||||||
|
advanceEntity.setWaybillStatus("0"); |
||||||
|
advanceEntity.setWaybillNo(""); |
||||||
|
advanceEntity.setTrainNumber(""); |
||||||
|
advanceEntity.setFreezeStatus("0"); |
||||||
|
|
||||||
|
advanceEntity.setSenderFactory(IDict.getTextByCode(BusSourceEnums.class, order.getBusSource())); |
||||||
|
|
||||||
|
advanceEntity.setOrderCode(orderInfo.getOmsExtOrderNo()); |
||||||
|
advanceEntity.setDealerCode(orderInfo.getShopCode()); |
||||||
|
advanceEntity.setDealerName(orderInfo.getShopName()); |
||||||
|
advanceEntity.setStoreCode(orderInfo.getShopCode()); |
||||||
|
advanceEntity.setStoreName(orderInfo.getShopName()); |
||||||
|
advanceEntity.setServiceNum(orderInfo.getOmsExtYsId()); |
||||||
|
// 安装
|
||||||
|
advanceEntity.setCustomerName(orderInfo.getYjInstallLinker()); |
||||||
|
advanceEntity.setCustomerPhone(orderInfo.getYjInstallPhone()); |
||||||
|
advanceEntity.setCustomerAddress(orderInfo.getYjInstallAddr()); |
||||||
|
advanceEntity.setConsigneePerson(order.getReceiverContacts()); |
||||||
|
advanceEntity.setConsigneeMobile(order.getReceiverMobile()); |
||||||
|
advanceEntity.setConsigneeAddress(order.getReceiverMobile()); |
||||||
|
List<JSONObject> packageList = new ArrayList<>(); |
||||||
|
|
||||||
|
for (PackageInfoEntity orderPackageDTO : value) { |
||||||
|
// 封装包件
|
||||||
|
TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); |
||||||
|
advanceDetailEntity.setWarehouseId(warehouseId); |
||||||
|
advanceDetailEntity.setWarehouseName(warehouseName); |
||||||
|
// 根据的一流单标识赋值
|
||||||
|
advanceEntity.setLegacyStatus("0"); |
||||||
|
advanceDetailEntity.setOrderCode(orderPackageDTO.getOmsExtOrderNo()); |
||||||
|
advanceDetailEntity.setBrand(BrandEnums.JP.getValue()); |
||||||
|
advanceDetailEntity.setSystemType("线上"); |
||||||
|
String boxType1 = orderPackageDTO.getBoxType1(); |
||||||
|
String boxType2 = orderPackageDTO.getBoxType2(); |
||||||
|
String boxType3 = orderPackageDTO.getBoxType3(); |
||||||
|
if (StrUtil.isNotEmpty(boxType1)) { |
||||||
|
advanceDetailEntity.setFirstPackName(orderPackageDTO.getBoxType1()); |
||||||
|
} |
||||||
|
if (StrUtil.isNotEmpty(boxType2)) { |
||||||
|
advanceDetailEntity.setSecondPackName(orderPackageDTO.getBoxType2()); |
||||||
|
} else { |
||||||
|
advanceDetailEntity.setSecondPackName(orderPackageDTO.getBoxType1()); |
||||||
|
} |
||||||
|
if (StrUtil.isNotEmpty(boxType3)) { |
||||||
|
advanceDetailEntity.setThirdPackName(orderPackageDTO.getBoxType3()); |
||||||
|
} else { |
||||||
|
if (StrUtil.isNotEmpty(boxType2)) { |
||||||
|
advanceDetailEntity.setThirdPackName(orderPackageDTO.getBoxType2()); |
||||||
|
} else { |
||||||
|
advanceDetailEntity.setThirdPackName(orderPackageDTO.getBoxType1()); |
||||||
|
} |
||||||
|
} |
||||||
|
advanceDetailEntity.setSiteName(IDict.getTextByCode(BusSourceEnums.class, order.getBusSource())); |
||||||
|
advanceDetailEntity.setSiteCode(""); |
||||||
|
String planQty = orderPackageDTO.getGoodsNum(); |
||||||
|
advanceDetailEntity.setQuantity((StrUtil.isNotBlank(planQty) && NumberUtil.isNumber(planQty)) ? Convert.toInt(planQty) : 0); |
||||||
|
advanceDetailEntity.setOrderPackageCode(orderPackageDTO.getExtBoxCode()); |
||||||
|
advanceDetailEntity.setTrainNumber(""); |
||||||
|
advanceDetailEntity.setServiceNum(orderInfo.getOmsExtYsId()); |
||||||
|
advanceDetailEntity.setWaybillNo(""); |
||||||
|
advanceDetailEntity.setPackageStatus("0"); |
||||||
|
advanceDetailEntity.setWeight(StrUtil.isNotBlank(orderPackageDTO.getGoodsWeight()) ? new BigDecimal(orderPackageDTO.getGoodsWeight()) : BigDecimal.ZERO); |
||||||
|
advanceDetailEntity.setVolume(StrUtil.isNotBlank(orderPackageDTO.getGoodsVolume()) ? new BigDecimal(orderPackageDTO.getGoodsVolume()) : BigDecimal.ZERO); |
||||||
|
// advanceDetailEntity.setChargeType(0);
|
||||||
|
advanceDetailEntity.setSupple(""); |
||||||
|
advanceDetailEntity.setManifest(""); |
||||||
|
advanceDetailEntity.setReturnNum(""); |
||||||
|
advanceDetailEntity.setSendDateStr(StrUtil.isNotBlank(order.getDepartTime()) ? order.getDepartTime() : DateUtil.formatLocalDateTime(LocalDateTime.now())); |
||||||
|
advanceDetailEntity.setCarNumber(order.getCarNo()); |
||||||
|
advanceDetailEntity.setGoodsMan(""); |
||||||
|
advanceDetailEntity.setTenantId(tenantId); |
||||||
|
advanceDetailEntity.setStatus(0); |
||||||
|
advanceDetailEntity.setIsDeleted(0); |
||||||
|
JSONObject entries = JSONUtil.parseObj(advanceDetailEntity); |
||||||
|
packageList.add(entries); |
||||||
|
} |
||||||
|
// 转成json对象,然后将包件明细放到detail中
|
||||||
|
JSONObject entries = JSONUtil.parseObj(advanceEntity); |
||||||
|
entries.set("details", JSONUtil.toJsonStr(packageList)); |
||||||
|
advances.add(entries); |
||||||
|
} |
||||||
|
// 将组装好的暂存单发送到 MQ ,由暂存单服务统一消费SendMsg.
|
||||||
|
if (CollUtil.isNotEmpty(advances)) { |
||||||
|
for (JSONObject advance : advances) { |
||||||
|
SendMsg sendMsg = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER) |
||||||
|
.routingKey(FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER).message(JSONUtil.toJsonStr(advance)).build(); |
||||||
|
factoryDataClient.sendMessage(sendMsg); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||||
|
* |
||||||
|
* Redistribution and use in source and binary forms, with or without |
||||||
|
* modification, are permitted provided that the following conditions are met: |
||||||
|
* |
||||||
|
* Redistributions of source code must retain the above copyright notice, |
||||||
|
* this list of conditions and the following disclaimer. |
||||||
|
* Redistributions in binary form must reproduce the above copyright |
||||||
|
* notice, this list of conditions and the following disclaimer in the |
||||||
|
* documentation and/or other materials provided with the distribution. |
||||||
|
* Neither the name of the dreamlu.net developer nor the names of its |
||||||
|
* contributors may be used to endorse or promote products derived from |
||||||
|
* this software without specific prior written permission. |
||||||
|
* Author: Chill 庄骞 (smallchill@163.com) |
||||||
|
*/ |
||||||
|
package com.logpm.factorydata.jinpai.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.logpm.factorydata.jinpai.entity.FactoryToken; |
||||||
|
|
||||||
|
/** |
||||||
|
* 工厂账号接口日志 Mapper 接口 |
||||||
|
* |
||||||
|
* @author zhy |
||||||
|
* @since 2023-03-28 |
||||||
|
*/ |
||||||
|
public interface FactoryTokenMapper extends BaseMapper<FactoryToken> { |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.logpm.factorydata.jinpai.mapper.FactoryTokenMapper"> |
||||||
|
|
||||||
|
<!-- 通用查询映射结果 --> |
||||||
|
<!-- <resultMap id="orderLogResultMap" type="com.logpm.factory.snm.entity.FactoryOrder">--> |
||||||
|
<!-- <result column="id" property="id"/>--> |
||||||
|
<!-- <result column="req_args" property="reqArgs"/>--> |
||||||
|
<!-- <result column="res_body" property="resBody"/>--> |
||||||
|
<!-- <result column="type" property="type"/>--> |
||||||
|
<!-- <result column="create_user" property="createUser"/>--> |
||||||
|
<!-- <result column="create_time" property="createTime"/>--> |
||||||
|
<!-- <result column="update_user" property="updateUser"/>--> |
||||||
|
<!-- <result column="update_time" property="updateTime"/>--> |
||||||
|
<!-- <result column="status" property="status"/>--> |
||||||
|
<!-- <result column="is_deleted" property="isDeleted"/>--> |
||||||
|
<!-- <result column="create_dept" property="createDept"/>--> |
||||||
|
<!-- </resultMap>--> |
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,16 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单信息 mapper |
||||||
|
* |
||||||
|
* @author zqb |
||||||
|
* @since 2024-03-26 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface PushOrderDetailMapper extends BaseMapper<PushOrderDetailEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.logpm.factorydata.jinpai.mapper.PushOrderDetailMapper"> |
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,16 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderEntity; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单信息 mapper |
||||||
|
* |
||||||
|
* @author zqb |
||||||
|
* @since 2024-03-26 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface PushOrderMapper extends BaseMapper<PushOrderEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="com.logpm.factorydata.jinpai.mapper.PushOrderMapper"> |
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,15 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.service; |
||||||
|
|
||||||
|
import com.logpm.factorydata.jinpai.entity.FactoryToken; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
|
||||||
|
/** |
||||||
|
* 工厂推送数据接口 |
||||||
|
*/ |
||||||
|
public interface IFactoryTokenService extends BaseService<FactoryToken> { |
||||||
|
|
||||||
|
|
||||||
|
boolean verifyToken(String token, String corpId) throws NoSuchAlgorithmException; |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.service; |
||||||
|
|
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单 服务类 |
||||||
|
* |
||||||
|
* @Author zqb |
||||||
|
* @Date 2024/4/26 |
||||||
|
**/ |
||||||
|
public interface PushOrderDetailService extends BaseService<PushOrderDetailEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.service; |
||||||
|
|
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderEntity; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单 服务类 |
||||||
|
* |
||||||
|
* @Author zqb |
||||||
|
* @Date 2024/4/26 |
||||||
|
**/ |
||||||
|
public interface PushOrderService extends BaseService<PushOrderEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.logpm.factorydata.jinpai.entity.FactoryToken; |
||||||
|
import com.logpm.factorydata.jinpai.mapper.FactoryTokenMapper; |
||||||
|
import com.logpm.factorydata.jinpai.service.IFactoryTokenService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.redis.cache.BladeRedis; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
@AllArgsConstructor |
||||||
|
@Service |
||||||
|
public class FactoryTokenServiceImpl extends BaseServiceImpl<FactoryTokenMapper, FactoryToken> implements IFactoryTokenService { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(FactoryTokenServiceImpl.class); |
||||||
|
|
||||||
|
private final BladeRedis bladeRedis; |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean verifyToken(String token, String corpId) throws NoSuchAlgorithmException { |
||||||
|
logger.info("#########verifyToken: 验证token开始"); |
||||||
|
//先生成token摘要
|
||||||
|
// String tokenAbst = MD5Utils.md5Hex(token.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
//编写查询条件
|
||||||
|
String key = "corpId:" + corpId; |
||||||
|
FactoryToken factoryToken = bladeRedis.get(key); |
||||||
|
|
||||||
|
if (Objects.isNull(factoryToken)) { |
||||||
|
QueryWrapper<FactoryToken> queryWrapper = new QueryWrapper<>(); |
||||||
|
queryWrapper.eq("token", token); |
||||||
|
factoryToken = baseMapper.selectOne(queryWrapper); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if (Objects.isNull(factoryToken)) { |
||||||
|
logger.error("#########verifyToken: token1验证不通过 token={},corpid={}", token, corpId); |
||||||
|
return false; |
||||||
|
} |
||||||
|
logger.info("#########verifyToken: 验证token 传入token {} 验证token {}", token, factoryToken.getToken()); |
||||||
|
if (!factoryToken.getToken().equals(token)) { |
||||||
|
logger.error("#########verifyToken: token2验证不通过 token={},corpid={}", token, corpId); |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
Long expireTimeLong = factoryToken.getExpireTime().getTime(); |
||||||
|
Long now = System.currentTimeMillis(); |
||||||
|
//判断是否过期
|
||||||
|
if (now > expireTimeLong) { |
||||||
|
logger.error("#########verifyToken: token验证不通过 已过期 token={},corpId={}", token, corpId); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.service.impl; |
||||||
|
|
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; |
||||||
|
import com.logpm.factorydata.jinpai.mapper.PushOrderDetailMapper; |
||||||
|
import com.logpm.factorydata.jinpai.service.PushOrderDetailService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单信息 业务实现类 |
||||||
|
* |
||||||
|
* @Author zqb |
||||||
|
* @Date 2024/4/26 |
||||||
|
**/ |
||||||
|
@Slf4j |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
public class PushOrderDetailServiceImpl extends BaseServiceImpl<PushOrderDetailMapper, PushOrderDetailEntity> implements PushOrderDetailService { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.service.impl; |
||||||
|
|
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderEntity; |
||||||
|
import com.logpm.factorydata.jinpai.mapper.PushOrderMapper; |
||||||
|
import com.logpm.factorydata.jinpai.service.PushOrderService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单信息 业务实现类 |
||||||
|
* |
||||||
|
* @Author zqb |
||||||
|
* @Date 2024/4/26 |
||||||
|
**/ |
||||||
|
@Slf4j |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
public class PushOrderServiceImpl extends BaseServiceImpl<PushOrderMapper, PushOrderEntity> implements PushOrderService { |
||||||
|
|
||||||
|
} |
@ -1,43 +0,0 @@ |
|||||||
package com.logpm.factorydata.jinpai.util; |
|
||||||
|
|
||||||
import cn.hutool.core.thread.ExecutorBuilder; |
|
||||||
import cn.hutool.core.thread.ThreadFactoryBuilder; |
|
||||||
import lombok.extern.slf4j.Slf4j; |
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author zhaoqiaobo |
|
||||||
* @create 2024-03-14 10:26 |
|
||||||
*/ |
|
||||||
@Slf4j |
|
||||||
public class ThreadPoolUtil { |
|
||||||
|
|
||||||
private ThreadPoolUtil() { |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 线程池 |
|
||||||
*/ |
|
||||||
public static ExecutorService executor = null; |
|
||||||
|
|
||||||
static { |
|
||||||
init(); |
|
||||||
} |
|
||||||
|
|
||||||
synchronized public static void init() { |
|
||||||
if (null != executor) { |
|
||||||
executor.shutdownNow(); |
|
||||||
} |
|
||||||
executor = ExecutorBuilder.create() |
|
||||||
.setCorePoolSize(8) |
|
||||||
.setMaxPoolSize(20) |
|
||||||
.setThreadFactory(ThreadFactoryBuilder.create().setNamePrefix("logpm-factory-data-sfy-").build()) |
|
||||||
.useSynchronousQueue().build(); |
|
||||||
} |
|
||||||
|
|
||||||
public static ExecutorService getThreadPool() { |
|
||||||
return executor; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,26 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.vo; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-30 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class PackageCategoryVO implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty(name = "一级品类") |
||||||
|
private String typea; |
||||||
|
@ApiModelProperty(name = "二级品类") |
||||||
|
private String typeb; |
||||||
|
@ApiModelProperty(name = "三级品类") |
||||||
|
private String typec; |
||||||
|
@ApiModelProperty(name = "包件码") |
||||||
|
private String extBoxCode; |
||||||
|
@ApiModelProperty(name = "包件类型") |
||||||
|
private String extBoxType; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.vo; |
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject; |
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderDetailEntity; |
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 金牌下单明细 实体类 |
||||||
|
* |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-26 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ApiModel(value = "金牌下单明细", description = "金牌下单明细") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class PushOrderDetailVO extends PushOrderDetailEntity { |
||||||
|
|
||||||
|
@ApiModelProperty(name = "箱码列表") |
||||||
|
private List<String> boxCodes; |
||||||
|
@ApiModelProperty(name = "包件品类") |
||||||
|
private List<PackageCategoryVO> boxDetails; |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.vo; |
||||||
|
|
||||||
|
import com.logpm.factorydata.jinpai.entity.PushOrderEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 金牌下单 实体类 |
||||||
|
* |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-26 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ApiModel(value = "金牌下单", description = "金牌下单") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class PushOrderVO extends PushOrderEntity { |
||||||
|
|
||||||
|
@ApiModelProperty(name = "订单明细") |
||||||
|
private List<PushOrderDetailVO> items; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.vo; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* 金牌三方物流仓库映射表 |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-30 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ThirdPlWarehouseMappingVO implements Serializable { |
||||||
|
|
||||||
|
/** |
||||||
|
* 到站网点 |
||||||
|
*/ |
||||||
|
private String arriveOrgName; |
||||||
|
/** |
||||||
|
* 仓库id |
||||||
|
*/ |
||||||
|
private String warehouseId; |
||||||
|
/** |
||||||
|
* 仓库名称 |
||||||
|
*/ |
||||||
|
private String warehouseName; |
||||||
|
/** |
||||||
|
* 租户id |
||||||
|
*/ |
||||||
|
private String tenantId; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.wrapper; |
||||||
|
|
||||||
|
import org.springframework.http.HttpHeaders; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletRequestWrapper; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.Enumeration; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class CustomHttpServletRequestWrapper extends HttpServletRequestWrapper { |
||||||
|
|
||||||
|
private final HttpHeaders headers; |
||||||
|
|
||||||
|
public CustomHttpServletRequestWrapper(HttpServletRequest request) { |
||||||
|
super(request); |
||||||
|
headers = new HttpHeaders(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getHeader(String name) { |
||||||
|
String headerValue = headers.getFirst(name); |
||||||
|
return headerValue != null ? headerValue : super.getHeader(name); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Enumeration<String> getHeaderNames() { |
||||||
|
List<String> names = Collections.list(super.getHeaderNames()); |
||||||
|
headers.forEach((key, value) -> names.add(key)); |
||||||
|
return Collections.enumeration(names); |
||||||
|
} |
||||||
|
|
||||||
|
// 其他需要覆盖的方法...
|
||||||
|
|
||||||
|
public void addHeader(String name, String value) { |
||||||
|
headers.add(name, value); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
package com.logpm.factorydata.jinpai.wrapper; |
||||||
|
|
||||||
|
import javax.servlet.ReadListener; |
||||||
|
import javax.servlet.ServletInputStream; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletRequestWrapper; |
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.ByteArrayInputStream; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.io.InputStreamReader; |
||||||
|
|
||||||
|
public class RequestWrapper extends HttpServletRequestWrapper { |
||||||
|
private final String body; |
||||||
|
public RequestWrapper(HttpServletRequest request) throws IOException { |
||||||
|
super(request); |
||||||
|
StringBuilder stringBuilder = new StringBuilder(); |
||||||
|
BufferedReader bufferedReader = null; |
||||||
|
try { |
||||||
|
InputStream inputStream = request.getInputStream(); |
||||||
|
if (inputStream != null) { |
||||||
|
bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); |
||||||
|
char[] charBuffer = new char[128]; |
||||||
|
int bytesRead = -1; |
||||||
|
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { |
||||||
|
stringBuilder.append(charBuffer, 0, bytesRead); |
||||||
|
} |
||||||
|
} else { |
||||||
|
stringBuilder.append(""); |
||||||
|
} |
||||||
|
} catch (IOException ex) { |
||||||
|
throw ex; |
||||||
|
} finally { |
||||||
|
if (bufferedReader != null) { |
||||||
|
try { |
||||||
|
bufferedReader.close(); |
||||||
|
} catch (IOException ex) { |
||||||
|
throw ex; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
body = stringBuilder.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ServletInputStream getInputStream() throws IOException { |
||||||
|
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes()); |
||||||
|
ServletInputStream servletInputStream = new ServletInputStream() { |
||||||
|
@Override |
||||||
|
public boolean isFinished() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
@Override |
||||||
|
public boolean isReady() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
@Override |
||||||
|
public void setReadListener(ReadListener readListener) {} |
||||||
|
@Override |
||||||
|
public int read() throws IOException { |
||||||
|
return byteArrayInputStream.read(); |
||||||
|
} |
||||||
|
}; |
||||||
|
return servletInputStream; |
||||||
|
|
||||||
|
} |
||||||
|
@Override |
||||||
|
public BufferedReader getReader() throws IOException { |
||||||
|
return new BufferedReader(new InputStreamReader(this.getInputStream())); |
||||||
|
} |
||||||
|
public String getBody() { |
||||||
|
return this.body; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue