Browse Source

feat(all): 索菲亚工厂

1 增加华之韵物流对接
pre-production
zhaoqiaobo 3 months ago
parent
commit
8d842dd5b5
  1. 30
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/config/InterceptorAdapterConfig.java
  2. 33
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/controller/OrderController.java
  3. 10
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/entity/DeliveryNoteEntity.java
  4. 5
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/entity/FactoryOrderLogEntity.java
  5. 2
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/entity/OrderInfoEntity.java
  6. 4
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/entity/PackageInfoEntity.java
  7. 1
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/interceptor/FactoryAccountsInterceptor.java
  8. 145
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/interceptor/LocalServerLoginAccountsInterceptor.java
  9. 3
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mapper/DeliveryNoteMapper.java
  10. 11
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mapper/FactoryNodeOrderMapper.xml
  11. 5
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mq/FactoryOrderListener.java
  12. 8
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/pros/FactoryDataSuoFeiYaProperties.java
  13. 3
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/service/DeliveryNoteService.java
  14. 55
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/service/impl/DeliveryNoteServiceImpl.java
  15. 26
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/vo/FactoryAuthVO.java
  16. 27
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/vo/FactoryOrderDataVO.java

30
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/config/InterceptorAdapterConfig.java

@ -1,32 +1,44 @@
package com.logpm.factorydata.suofeiya.config;
import com.logpm.factorydata.suofeiya.interceptor.FactoryAccountsInterceptor;
import com.logpm.factorydata.suofeiya.interceptor.LocalServerLoginAccountsInterceptor;
import com.logpm.factorydata.suofeiya.pros.FactoryDataSuoFeiYaProperties;
import com.logpm.factorydata.suofeiya.service.DeliveryNoteService;
import com.logpm.factorydata.suofeiya.service.IFactoryTokenService;
import lombok.AllArgsConstructor;
import org.springblade.common.component.MockLoginService;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
@AllArgsConstructor
public class InterceptorAdapterConfig implements WebMvcConfigurer {
private final IFactoryTokenService factoryTokenService;
private final BladeRedis redis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Resource
private IFactoryTokenService factoryTokenService;
@Resource
private BladeRedis redis;
@Resource
private Environment environment;
@Resource
private RedisLockClient redisLockClient;
@Resource
private MockLoginService mockLoginService;
@Lazy
@Resource
private DeliveryNoteService deliveryNoteService;
@Resource
private FactoryDataSuoFeiYaProperties suoFeiYaProperties;
@Override
public void addInterceptors(InterceptorRegistry interceptorRegistry) {
// interceptorRegistry.addInterceptor(new FactoryAccountsInterceptor(factoryTokenService))
// .addPathPatterns("/**").order(1);
interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis, environment,redisLockClient,mockLoginService))
interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis, environment, redisLockClient, mockLoginService, suoFeiYaProperties, deliveryNoteService))
.addPathPatterns("/**").order(2);
}
}

33
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/controller/OrderController.java

@ -5,18 +5,20 @@ import cn.hutool.json.JSONUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.logpm.factorydata.suofeiya.service.DeliveryNoteService;
import com.logpm.factorydata.suofeiya.vo.DeliveryNoteVO;
import com.logpm.factorydata.suofeiya.vo.ParamVO;
import com.logpm.factorydata.suofeiya.vo.FactoryOrderDataVO;
import com.logpm.factorydata.suofeiya.vo.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 工厂订单 前端控制器
*
@ -26,16 +28,17 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/order")
@AllArgsConstructor
@Api(value = "工厂订单", tags = "工厂订单")
public class OrderController {
private final DeliveryNoteService service;
@Lazy
@Resource
private DeliveryNoteService service;
@ResponseBody
@PostMapping
@ApiOperationSupport(order = 1)
@ApiOperation(value = "工厂订单", notes = "工厂订单")
@ApiOperation(value = "老系统-工厂订单", notes = "老系统-工厂订单")
public Resp order(@RequestBody DeliveryNoteVO params) {
String jsonStr = JSONUtil.toJsonStr(params);
log.info("接收工厂订单:{} ", jsonStr);
@ -52,4 +55,24 @@ public class OrderController {
return Resp.success(res);
}
@ResponseBody
@PostMapping("/v1")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "索菲亚-工厂订单", notes = "索菲亚-工厂订单")
public Resp orderV1(@RequestBody FactoryOrderDataVO vo) {
String jsonStr = JSONUtil.toJsonStr(vo);
log.info("接收工厂订单:{} ", jsonStr);
String res = "";
try {
DeliveryNoteVO params = vo.getParams();
if (ObjectUtil.isNotEmpty(params)) {
res = service.order(params);
}
} catch (Exception e) {
log.error("工厂订单异常:{} ", e);
return Resp.success("服务器异常");
}
return Resp.success(res);
}
}

10
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/entity/DeliveryNoteEntity.java

@ -2,6 +2,7 @@ package com.logpm.factorydata.suofeiya.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -20,6 +21,8 @@ import org.springblade.core.mp.base.BaseEntity;
@EqualsAndHashCode(callSuper = true)
public class DeliveryNoteEntity extends BaseEntity {
@ApiModelProperty(name = "租户", notes = "")
private String tenantCode;
@ApiModelProperty(name = "日志id")
private String logId;
@ApiModelProperty(name = "渠道单号")
@ -39,7 +42,12 @@ public class DeliveryNoteEntity extends BaseEntity {
private String gpsLeaveWhTime;
@ApiModelProperty(name = "发货方地址")
private String sendAddr;
@ApiModelProperty(name = "下单模式")
@ApiModelProperty(name = "中转物流商")
@JsonProperty("zCarrierName")
private String zCarrierName;
@ApiModelProperty(name = "供应商")
private String supplierName;
@ApiModelProperty(name = "订单类型(空为衣柜,”Z”为家品直发单)")
private String orderType;
@ApiModelProperty(name = "运输方式/产品类型")
private String transportType;

5
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/entity/FactoryOrderLogEntity.java

@ -38,6 +38,11 @@ public class FactoryOrderLogEntity extends BaseEntity {
*/
@ApiModelProperty(name = "预留5", notes = "")
private String reserve5;
/**
* 租户
*/
@ApiModelProperty(name = "租户", notes = "")
private String tenantCode;
/**
* 日志文件存放地址
*/

2
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/entity/OrderInfoEntity.java

@ -19,6 +19,8 @@ import org.springblade.core.mp.base.BaseEntity;
@EqualsAndHashCode(callSuper = true)
public class OrderInfoEntity extends BaseEntity {
@ApiModelProperty(name = "租户", notes = "")
private String tenantCode;
@ApiModelProperty(name = "日志id")
private String logId;
@ApiModelProperty(name = "发货单id")

4
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/entity/PackageInfoEntity.java

@ -19,6 +19,8 @@ import org.springblade.core.mp.base.BaseEntity;
@EqualsAndHashCode(callSuper = true)
public class PackageInfoEntity extends BaseEntity {
@ApiModelProperty(name = "租户", notes = "")
private String tenantCode;
@ApiModelProperty(name = "日志id")
private String logId;
@ApiModelProperty(name = "发货单id")
@ -37,6 +39,8 @@ public class PackageInfoEntity extends BaseEntity {
private String orderNo;
@ApiModelProperty(name = "重量")
private String weight;
@ApiModelProperty(name = "数量")
private Double number;
@ApiModelProperty(name = "体积")
private String volume;
@ApiModelProperty(name = "预留1", notes = "")

1
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/interceptor/FactoryAccountsInterceptor.java

@ -25,7 +25,6 @@ public class FactoryAccountsInterceptor implements HandlerInterceptor {
@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);

145
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/interceptor/LocalServerLoginAccountsInterceptor.java

@ -1,84 +1,139 @@
package com.logpm.factorydata.suofeiya.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import com.logpm.factorydata.suofeiya.pros.FactoryDataSuoFeiYaProperties;
import com.logpm.factorydata.suofeiya.service.DeliveryNoteService;
import com.logpm.factorydata.suofeiya.vo.FactoryAuthVO;
import com.logpm.factorydata.suofeiya.wrapper.RequestWrapper;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.context.annotation.Lazy;
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.annotation.Resource;
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.time.Instant;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapter {
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
@Resource
private BladeRedis bladeRedis;
@Resource
private Environment environment;
@Resource
private RedisLockClient redisLockClient;
@Resource
private MockLoginService mockLoginService;
@Resource
private FactoryDataSuoFeiYaProperties suoFeiYaProperties;
@Lazy
@Resource
private DeliveryNoteService deliveryNoteService;
public LocalServerLoginAccountsInterceptor(BladeRedis redis, Environment environment, RedisLockClient redisLockClient, MockLoginService mockLoginService, FactoryDataSuoFeiYaProperties suoFeiYaProperties, DeliveryNoteService deliveryNoteService) {
this.bladeRedis = redis;
this.environment = environment;
this.redisLockClient = redisLockClient;
this.mockLoginService = mockLoginService;
this.suoFeiYaProperties = suoFeiYaProperties;
this.deliveryNoteService = deliveryNoteService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
try {
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String account ="shujutongbu";
String tenantId ="627683";
String key =CacheNames.LOCAL_SERVER_USER+tenantId+":"+account;
String lockKey =key+":lock";
JSONObject data =bladeRedis.get(key);
if(Objects.isNull(data)){
boolean flag = redisLockClient.tryLock(lockKey, LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(key);
if(Objects.isNull(data)){
data = mockLoginService.mockToken(tenantId,account);
bladeRedis.setEx(key,data,2591990L);
redisLockClient.unLock(lockKey, LockType.FAIR);
}
RequestWrapper myRequestWrapper = new RequestWrapper(request);
String body = myRequestWrapper.getBody();
JSONObject jsonObject = JSONObject.parseObject(body);
// 获取头中参数
String authTime = request.getHeader("authTime");
if (StrUtil.isEmpty(authTime)) {
returnJson(response, JSONObject.toJSONString(R.fail(1, "时间戳不能为空")));
return false;
}
String sign = request.getHeader("sign");
String companyCodeH = request.getHeader("companyCode");
log.info("##########preHandle: authTime={},sign={},companyCodeH={}", authTime, sign, companyCodeH);
String companyCode = jsonObject.getString("companyCode");
long secondTimestamp = Instant.now().getEpochSecond();
// 验证时间 不能大于5秒
if (StringUtil.isNotBlank(authTime)) {
long authTimeLong = Long.parseLong(authTime);
if (secondTimestamp - authTimeLong > 5) {
returnJson(response, JSONObject.toJSONString(R.fail(1, "认证不通过,时间戳过期")));
return false;
}
}
// 验证签名
String auth = suoFeiYaProperties.getAuth();
String md5Hex = new String(MD5.create().digest(authTime + auth)).toUpperCase();
if (!StrUtil.equals(md5Hex, sign)) {
returnJson(response, JSONObject.toJSONString(R.fail(1, "认证不通过,签名不正确")));
return false;
}
String account = "shujutongbu";
String tenantId = "627683";
String authorizationHeader = "bG9jYWw6bG9jYWxfc2VjcmV0";
if (StringUtil.isNotBlank(companyCode)) {
FactoryAuthVO authVO = deliveryNoteService.findFactoryAuth(companyCode);
if (ObjectUtil.isNotEmpty(authVO)) {
account = authVO.getLoginAccount();
tenantId = authVO.getTenantCode();
authorizationHeader = authVO.getAuthorizationHeader();
org.springblade.common.wrapper.CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String key = CacheNames.LOCAL_SERVER_USER + tenantId + ":" + account;
String lockKey = key + ":lock";
JSONObject data = bladeRedis.get(key);
if (Objects.isNull(data)) {
boolean flag = redisLockClient.tryLock(lockKey, LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if (flag) {
data = bladeRedis.get(key);
if (Objects.isNull(data)) {
data = mockLoginService.mockToken(tenantId, account);
bladeRedis.setEx(key, data, 2591990L);
redisLockClient.unLock(lockKey, LockType.FAIR);
}
}
}
// 发送登录请求
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 " + authorizationHeader);
ThreadLocalUtil.put("bladeContext", httpHeaders);
// 用包装后的request替换原始request
request = wrappedRequest;
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
return true;
// 修改或添加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 bG9jYWw6bG9jYWxfc2VjcmV0");
ThreadLocalUtil.put("bladeContext", httpHeaders);
// 用包装后的request替换原始request
request = wrappedRequest;
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
return true;
}
}
return false;
} catch (Exception e) {
returnJson(response, JSONObject.toJSONString(R.fail(500, "服务异常,请联系管理员")));
returnJson(response, JSONObject.toJSONString(R.fail(5, "服务异常,请联系管理员")));
return false;
}
}

3
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mapper/DeliveryNoteMapper.java

@ -2,7 +2,9 @@ package com.logpm.factorydata.suofeiya.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.logpm.factorydata.suofeiya.entity.DeliveryNoteEntity;
import com.logpm.factorydata.suofeiya.vo.FactoryAuthVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 发货单 mapper
@ -13,4 +15,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface DeliveryNoteMapper extends BaseMapper<DeliveryNoteEntity> {
FactoryAuthVO findFactoryAuth(@Param("companyCode") String companyCode);
}

11
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mapper/FactoryNodeOrderMapper.xml

@ -2,4 +2,15 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.logpm.factorydata.suofeiya.mapper.DeliveryNoteMapper">
<select id="findFactoryAuth" resultType="com.logpm.factorydata.suofeiya.vo.FactoryAuthVO">
select
logistics_code,
app_key,
tenant_code,
login_account,
authorization_header
from sfy_factory_auth
where
logistics_code = #{companyCode}
</select>
</mapper>

5
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mq/FactoryOrderListener.java

@ -24,13 +24,13 @@ import com.logpm.factorydata.suofeiya.vo.PackageInfoVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.constant.factorydata.FactoryDataConstants;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@ -97,6 +97,7 @@ public class FactoryOrderListener {
vo.setOrderExtendField(JSONUtil.toJsonStr(vo.getOrderExtendFields()));
}
vo.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
vo.setTenantCode(AuthUtil.getTenantId());
deliveryNoteService.save(vo);
List<OrderInfoVO> orderInfos = vo.getOrderInfo();
if (CollUtil.isNotEmpty(orderInfos)) {
@ -106,6 +107,7 @@ public class FactoryOrderListener {
BeanUtil.copyProperties(orderInfo, orderInfoEntity);
orderInfoEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
orderInfoEntity.setDeliveryNoteId(vo.getId().toString());
orderInfoEntity.setTenantCode(AuthUtil.getTenantId());
infoEntities.add(orderInfoEntity);
}
orderInfoService.saveBatch(infoEntities);
@ -117,6 +119,7 @@ public class FactoryOrderListener {
BeanUtil.copyProperties(packageInfo, entity);
entity.setDeliveryNoteId(vo.getId().toString());
entity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null);
entity.setTenantCode(AuthUtil.getTenantId());
packageInfoEntities.add(entity);
}
packageInfoService.saveBatch(packageInfoEntities);

8
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/pros/FactoryDataSuoFeiYaProperties.java

@ -9,12 +9,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author pref
*/
@Data
@ConfigurationProperties(prefix = "logpm")
@ConfigurationProperties(prefix = "suofeiya")
public class FactoryDataSuoFeiYaProperties {
/**
* 名称
* 颁布给工厂的认证码
*/
private String name;
private String auth;
}

3
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/service/DeliveryNoteService.java

@ -2,6 +2,7 @@ package com.logpm.factorydata.suofeiya.service;
import com.logpm.factorydata.suofeiya.entity.DeliveryNoteEntity;
import com.logpm.factorydata.suofeiya.vo.DeliveryNoteVO;
import com.logpm.factorydata.suofeiya.vo.FactoryAuthVO;
import org.springblade.core.mp.base.BaseService;
/**
@ -15,4 +16,6 @@ public interface DeliveryNoteService extends BaseService<DeliveryNoteEntity> {
String order(DeliveryNoteVO vo);
void buildAdvance(DeliveryNoteVO vo);
FactoryAuthVO findFactoryAuth(String companyCode);
}

55
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/service/impl/DeliveryNoteServiceImpl.java

@ -17,12 +17,12 @@ import com.logpm.factorydata.suofeiya.mapper.DeliveryNoteMapper;
import com.logpm.factorydata.suofeiya.service.DeliveryNoteService;
import com.logpm.factorydata.suofeiya.service.FactoryOrderLogService;
import com.logpm.factorydata.suofeiya.vo.DeliveryNoteVO;
import com.logpm.factorydata.suofeiya.vo.FactoryAuthVO;
import com.logpm.factorydata.suofeiya.vo.OrderInfoVO;
import com.logpm.factorydata.suofeiya.vo.PackageInfoVO;
import com.logpm.factorydata.vo.SendMsg;
import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity;
import com.logpm.trunkline.entity.TrunklineAdvanceEntity;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
@ -34,6 +34,8 @@ import org.springblade.common.constant.factorydata.FactoryDataConstants;
import org.springblade.common.utils.FileLogsUtil;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.resource.feign.IOssClient;
import org.springframework.http.MediaType;
@ -41,11 +43,13 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -59,13 +63,18 @@ import java.util.Map;
**/
@Slf4j
@Service
@AllArgsConstructor
public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper, DeliveryNoteEntity> implements DeliveryNoteService {
private final IFactoryDataClient factoryDataClient;
private final FactoryOrderLogService factoryOrderLogService;
private final IOssClient ossClient;
private final IFactoryDataBaseClient baseClient;
@Resource
private IFactoryDataClient factoryDataClient;
@Resource
private FactoryOrderLogService factoryOrderLogService;
@Resource
private IOssClient ossClient;
@Resource
private IFactoryDataBaseClient baseClient;
@Resource
private BladeRedis bladeRedis;
@Override
public String order(DeliveryNoteVO vo) {
@ -77,6 +86,7 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper,
logEntity.setType(1);
logEntity.setSaxStatus(SaxStatusEnums.NOMAL.getCode());
logEntity.setLogUrl(url);
logEntity.setTenantCode(AuthUtil.getTenantId());
factoryOrderLogService.save(logEntity);
// 3 将消息发送给 mq,解析保存
@ -87,8 +97,8 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper,
}
@LogpmAsync("asyncExecutor")
@Override
public void buildAdvance(DeliveryNoteVO vo) {
@Override
public void buildAdvance(DeliveryNoteVO vo) {
// 新起线程构建暂存单发送mq
Long startWarehouseId = null;
String startWarehouseName = null;
@ -165,10 +175,10 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper,
advanceEntity.setServiceNum(orderInfoVO.getMainOrderNo());
advanceEntity.setSenderFactory(vo.getSendAddr());
// 工长名字为无,则取客户名字 工长名字不为无 则取工长电话 客户名字转工长名字
if(StrUtil.equals(orderInfoVO.getConnectName(),"无") || StrUtil.isEmpty(orderInfoVO.getConnectName())){
if (StrUtil.equals(orderInfoVO.getConnectName(), "无") || StrUtil.isEmpty(orderInfoVO.getConnectName())) {
advanceEntity.setCustomerName(orderInfoVO.getReceiver());
advanceEntity.setCustomerPhone(orderInfoVO.getReceiveTel());
}else{
} else {
advanceEntity.setCustomerName(orderInfoVO.getReceiver() + " 转 " + orderInfoVO.getConnectName());
advanceEntity.setCustomerPhone(orderInfoVO.getConnectPhone());
}
@ -238,15 +248,32 @@ public class DeliveryNoteServiceImpl extends BaseServiceImpl<DeliveryNoteMapper,
factoryDataClient.sendMessage(sendMsg);
}
}
}
}
@Override
public FactoryAuthVO findFactoryAuth(String companyCode) {
// redis 缓存数据 缓存时间 1天
if (StrUtil.isNotBlank(companyCode)) {
String key = StrUtil.format("factory-data:suofeiya:", companyCode);
String json = bladeRedis.get(key);
if (StrUtil.isNotBlank(json)) {
return JSONUtil.toBean(json, FactoryAuthVO.class);
} else {
FactoryAuthVO factoryAuth = baseMapper.findFactoryAuth(companyCode);
bladeRedis.setEx(key, JSONUtil.toJsonStr(factoryAuth), Duration.ofDays(1));
return baseMapper.findFactoryAuth(companyCode);
}
}
return null;
}
private String uploadFile(String body) {
//文本内容和保存为本地文件 并上传
private String uploadFile(String body) {
// 文本内容和保存为本地文件 并上传
String logPath = FileLogsUtil.saveFileLogs(body);
log.info(">>> 文件路径 {}", logPath);
MultipartFile multi = getMultipartFile(logPath);
//上传到服务器
// 上传到服务器
R r = ossClient.fileUpload(multi, "sfy-order-logs");
if (r.isSuccess()) {
BladeFile data = (BladeFile) r.getData();

26
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/vo/FactoryAuthVO.java

@ -0,0 +1,26 @@
package com.logpm.factorydata.suofeiya.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 物流商认证
*
* @author zhaoqiaobo
* @create 2024-04-26
*/
@Data
public class FactoryAuthVO {
@ApiModelProperty(name = "物流编码")
private String logisticsCode;
@ApiModelProperty(name = "秘钥")
private String appKey;
@ApiModelProperty(name = "租户")
private String tenantCode;
@ApiModelProperty(name = "登录账号")
private String loginAccount;
@ApiModelProperty(name = "Authorization头")
private String authorizationHeader;
}

27
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/vo/FactoryOrderDataVO.java

@ -0,0 +1,27 @@
package com.logpm.factorydata.suofeiya.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 送货单 实体类
*
* @author zhaoqiaobo
* @create 2024-04-26
*/
@Data
@ApiModel(value = "索菲亚发货单", description = "索菲亚发货单")
public class FactoryOrderDataVO {
@ApiModelProperty("加密后的密文")
private String digest;
@ApiModelProperty("时间戳 毫秒")
private Long timestamp;
@ApiModelProperty("公司编码")
private String companyCode;
@ApiModelProperty("订单信息")
private DeliveryNoteVO params;
}
Loading…
Cancel
Save