13 changed files with 319 additions and 0 deletions
@ -0,0 +1,52 @@ |
|||||||
|
package com.logpm.factorydata.suofeiya.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("sfy_order_full_info") |
||||||
|
@ApiModel(value = "索菲亚齐套信息表", description = "索菲亚齐套信息表") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class OrderFullInfoEntity extends BaseEntity { |
||||||
|
|
||||||
|
@ApiModelProperty(name = "主单号", notes = "") |
||||||
|
private String mainOrderNo; |
||||||
|
@ApiModelProperty(name = "订单号") |
||||||
|
private String orderNo; |
||||||
|
@ApiModelProperty(name = "齐套标识 Y齐套 N未齐套") |
||||||
|
private String fullSet; |
||||||
|
@ApiModelProperty(name = "标签号") |
||||||
|
private String paNo; |
||||||
|
@ApiModelProperty(name = "物料编码") |
||||||
|
private String itemCode; |
||||||
|
@ApiModelProperty(name = "物料名称") |
||||||
|
private String itemName; |
||||||
|
@ApiModelProperty(name = "物料数量") |
||||||
|
private String quantity; |
||||||
|
@ApiModelProperty(name = "订单类型 (空为衣柜,”Z”为家品直发单)") |
||||||
|
private String orderType; |
||||||
|
@ApiModelProperty(name = "租户") |
||||||
|
private String tenantCode; |
||||||
|
|
||||||
|
@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,171 @@ |
|||||||
|
package com.logpm.factorydata.suofeiya.job; |
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64; |
||||||
|
import cn.hutool.core.collection.CollUtil; |
||||||
|
import cn.hutool.core.convert.Convert; |
||||||
|
import cn.hutool.core.date.DateUtil; |
||||||
|
import cn.hutool.core.util.ObjectUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import cn.hutool.crypto.digest.MD5; |
||||||
|
import cn.hutool.http.HttpUtil; |
||||||
|
import cn.hutool.json.JSONArray; |
||||||
|
import cn.hutool.json.JSONObject; |
||||||
|
import cn.hutool.json.JSONUtil; |
||||||
|
import com.logpm.factorydata.suofeiya.entity.OrderFullInfoEntity; |
||||||
|
import com.logpm.factorydata.suofeiya.entity.OrderInfoEntity; |
||||||
|
import com.logpm.factorydata.suofeiya.pros.FactoryDataSuoFeiYaProperties; |
||||||
|
import com.logpm.factorydata.suofeiya.service.DeliveryNoteService; |
||||||
|
import com.logpm.factorydata.suofeiya.service.OrderFullInfoService; |
||||||
|
import com.logpm.factorydata.suofeiya.service.OrderInfoService; |
||||||
|
import com.logpm.factorydata.suofeiya.vo.FactoryAuthVO; |
||||||
|
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.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* 工厂job |
||||||
|
* |
||||||
|
* @author zhaoqiaobo |
||||||
|
* @create 2024-04-02 |
||||||
|
*/ |
||||||
|
@AllArgsConstructor |
||||||
|
@Component |
||||||
|
@Slf4j |
||||||
|
public class FactoryJob { |
||||||
|
|
||||||
|
private final OrderInfoService orderInfoService; |
||||||
|
private final OrderFullInfoService orderFullInfoService; |
||||||
|
private final DeliveryNoteService deliveryNoteService; |
||||||
|
private final FactoryDataSuoFeiYaProperties dataSuoFeiYaProperties; |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取齐套标识 |
||||||
|
* |
||||||
|
* @param param |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
@XxlJob("orderFull") |
||||||
|
public ReturnT<String> orderFull(String param) throws Exception { |
||||||
|
// 查询出未齐套的主单号
|
||||||
|
List<OrderInfoEntity> orderInfoEntityList = orderInfoService.findNotFullOrder(); |
||||||
|
if (CollUtil.isNotEmpty(orderInfoEntityList)) { |
||||||
|
// 根据 tenantCode 和 orderType 分组
|
||||||
|
Map<String, List<OrderInfoEntity>> collect = orderInfoEntityList.stream().filter(orderInfoEntity -> { |
||||||
|
return StrUtil.isNotEmpty(orderInfoEntity.getTenantCode()); |
||||||
|
}).collect(Collectors.groupingBy(OrderInfoEntity::getTenantCode)); |
||||||
|
if (CollUtil.isNotEmpty(collect)) { |
||||||
|
// 查询出未齐套的记录
|
||||||
|
orderFullInfoService.deleteAll(); |
||||||
|
for (Map.Entry<String, List<OrderInfoEntity>> stringListEntry : collect.entrySet()) { |
||||||
|
String tenantCode = stringListEntry.getKey(); |
||||||
|
List<OrderInfoEntity> value = stringListEntry.getValue(); |
||||||
|
FactoryAuthVO authVO = deliveryNoteService.findFactoryAuthByTenantCode(tenantCode); |
||||||
|
if (ObjectUtil.isNotEmpty(authVO)) { |
||||||
|
if (CollUtil.isNotEmpty(value)) { |
||||||
|
// 按不同订单类型查询齐套
|
||||||
|
Map<String, List<OrderInfoEntity>> collect1 = value.stream().collect(Collectors.groupingBy(OrderInfoEntity::getOrderType)); |
||||||
|
for (Map.Entry<String, List<OrderInfoEntity>> listEntry : collect1.entrySet()) { |
||||||
|
String orderType = listEntry.getKey(); |
||||||
|
List<OrderInfoEntity> list = listEntry.getValue(); |
||||||
|
Long time = DateUtil.current(); |
||||||
|
JSONObject jsons = new JSONObject(); |
||||||
|
if (StrUtil.isNotEmpty(orderType)) { |
||||||
|
jsons.set("orderType", orderType); |
||||||
|
} |
||||||
|
jsons.set("mainOrderNo", list.stream().map(OrderInfoEntity::getMainOrderNo).collect(Collectors.toList())); |
||||||
|
String s = sendFactory(authVO.getCompanyCode(), JSONUtil.toJsonStr(jsons), time, authVO.getAppKey(), dataSuoFeiYaProperties.getPush().getOrderFullUrl()); |
||||||
|
if (StrUtil.isNotEmpty(s)) { |
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(s); |
||||||
|
if (StrUtil.equals(jsonObject.getStr("result_code"), "0000")) { |
||||||
|
List<OrderFullInfoEntity> orderFullInfoEntities = new ArrayList<>(); |
||||||
|
// 推送成功
|
||||||
|
JSONArray fullSetInfos = jsonObject.getJSONArray("fullSetInfo"); |
||||||
|
if (CollUtil.isNotEmpty(fullSetInfos)) { |
||||||
|
for (Object fullSetInfoObj : fullSetInfos) { |
||||||
|
JSONObject fullSetInfo = JSONUtil.parseObj(fullSetInfoObj); |
||||||
|
String mainOrderNo = fullSetInfo.getStr("mainOrderNo"); |
||||||
|
String fullSet = fullSetInfo.getStr("fullSet"); |
||||||
|
// 家品数据取 orderDetail 衣柜取 paNos
|
||||||
|
if ("Z".equals(orderType)) { |
||||||
|
JSONArray orderDetails = fullSetInfo.getJSONArray("orderDetail"); |
||||||
|
if (CollUtil.isNotEmpty(orderDetails)) { |
||||||
|
for (Object orderDetailObj : orderDetails) { |
||||||
|
JSONObject orderDetail = JSONUtil.parseObj(orderDetailObj); |
||||||
|
String orderNo = orderDetail.getStr("orderNo"); |
||||||
|
String itemCode = orderDetail.getStr("itemCode"); |
||||||
|
String itemName = orderDetail.getStr("itemName"); |
||||||
|
String quantity = orderDetail.getStr("quantity"); |
||||||
|
OrderFullInfoEntity entity = new OrderFullInfoEntity(); |
||||||
|
entity.setMainOrderNo(mainOrderNo); |
||||||
|
entity.setOrderNo(orderNo); |
||||||
|
entity.setItemCode(itemCode); |
||||||
|
entity.setItemName(itemName); |
||||||
|
entity.setQuantity(quantity); |
||||||
|
entity.setFullSet(fullSet); |
||||||
|
entity.setOrderType(orderType); |
||||||
|
entity.setTenantCode(tenantCode); |
||||||
|
orderFullInfoEntities.add(entity); |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
JSONArray paNos = fullSetInfo.getJSONArray("paNo"); |
||||||
|
if (CollUtil.isNotEmpty(paNos)) { |
||||||
|
for (Object paNo : paNos) { |
||||||
|
String str = Convert.toStr(paNo); |
||||||
|
OrderFullInfoEntity entity = new OrderFullInfoEntity(); |
||||||
|
entity.setMainOrderNo(mainOrderNo); |
||||||
|
entity.setPaNo(str); |
||||||
|
entity.setFullSet(fullSet); |
||||||
|
entity.setOrderType(orderType); |
||||||
|
entity.setTenantCode(tenantCode); |
||||||
|
orderFullInfoEntities.add(entity); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if (CollUtil.isNotEmpty(orderFullInfoEntities)) { |
||||||
|
orderFullInfoService.saveBatch(orderFullInfoEntities); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return ReturnT.SUCCESS; |
||||||
|
} |
||||||
|
|
||||||
|
private String sendFactory(String companyCode, String jsonStr, Long time, String appKey, String paStatusUrl) { |
||||||
|
try { |
||||||
|
Map<String, Object> param = new HashMap<>(); |
||||||
|
param.put("companyCode", companyCode); |
||||||
|
param.put("params", jsonStr); |
||||||
|
param.put("timestamp", time); |
||||||
|
// 加密
|
||||||
|
String digest = MD5.create().digestHex(jsonStr + appKey + time); |
||||||
|
String encode = Base64.encode(digest); |
||||||
|
param.put("digest", encode); |
||||||
|
log.info("推送节点数据:{}", JSONUtil.toJsonStr(param)); |
||||||
|
String post = HttpUtil.post(dataSuoFeiYaProperties.getPush().getPushHost() + paStatusUrl, param); |
||||||
|
log.info("推送结果:{}", post); |
||||||
|
return post; |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
log.error("推送节点数据错误:{}", e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package com.logpm.factorydata.suofeiya.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.logpm.factorydata.suofeiya.entity.OrderFullInfoEntity; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* 索菲亚齐套信息表 mapper |
||||||
|
* |
||||||
|
* @author zqb |
||||||
|
* @since 2024-03-26 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface OrderFullInfoMapper extends BaseMapper<OrderFullInfoEntity> { |
||||||
|
|
||||||
|
void deleteAll(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
<?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.suofeiya.mapper.OrderFullInfoMapper"> |
||||||
|
|
||||||
|
<delete id="deleteAll"> |
||||||
|
DELETE FROM sfy_order_full_info |
||||||
|
</delete> |
||||||
|
</mapper> |
@ -0,0 +1,16 @@ |
|||||||
|
package com.logpm.factorydata.suofeiya.service; |
||||||
|
|
||||||
|
import com.logpm.factorydata.suofeiya.entity.OrderFullInfoEntity; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 索菲亚齐套信息表 服务类 |
||||||
|
* |
||||||
|
* @Author zqb |
||||||
|
* @Date 2024/4/26 |
||||||
|
**/ |
||||||
|
public interface OrderFullInfoService extends BaseService<OrderFullInfoEntity> { |
||||||
|
|
||||||
|
void deleteAll(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
package com.logpm.factorydata.suofeiya.service.impl; |
||||||
|
|
||||||
|
import com.logpm.factorydata.suofeiya.entity.OrderFullInfoEntity; |
||||||
|
import com.logpm.factorydata.suofeiya.mapper.OrderFullInfoMapper; |
||||||
|
import com.logpm.factorydata.suofeiya.service.OrderFullInfoService; |
||||||
|
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 OrderFullInfoServiceImpl extends BaseServiceImpl<OrderFullInfoMapper, OrderFullInfoEntity> implements OrderFullInfoService { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void deleteAll() { |
||||||
|
baseMapper.deleteAll(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue