diff --git a/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/util/FactoryDataUtil.java b/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/util/FactoryDataUtil.java index da57fe852..3cec54208 100644 --- a/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/util/FactoryDataUtil.java +++ b/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/util/FactoryDataUtil.java @@ -16,11 +16,14 @@ import java.util.concurrent.ConcurrentHashMap; public class FactoryDataUtil { static Map factorys = new ConcurrentHashMap(); - private FactoryDataUtil(){ + + private FactoryDataUtil() { } + static { factorys.put(BrandEnums.ZB.getValue(), FactoryDataConstants.Mq.RoutingKeys.ZBOM_NODE_DATA_PUSH); + factorys.put(BrandEnums.LINSY.getValue(), FactoryDataConstants.Mq.RoutingKeys.LINSY_NODE_DATA_PUSH); } diff --git a/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/vo/PushData.java b/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/vo/PushData.java new file mode 100644 index 000000000..280e55086 --- /dev/null +++ b/blade-service-api/logpm-factory-data-api/src/main/java/com/logpm/factorydata/vo/PushData.java @@ -0,0 +1,33 @@ +package com.logpm.factorydata.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.logpm.factorydata.enums.BrandEnums; +import com.logpm.factorydata.enums.SignForStatusEnums; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springblade.common.constant.WorkNodeEnums; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 提送数据 + * + * @author zhaoqiaobo + * @create 2024-03-18 0:45 + */ +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PushData implements Serializable { + + /** + * 包件 + */ + private String packageCode; + +} diff --git a/blade-service-api/logpm-factory-data-zbom-api/pom.xml b/blade-service-api/logpm-factory-data-zbom-api/pom.xml new file mode 100644 index 000000000..80bc8d10a --- /dev/null +++ b/blade-service-api/logpm-factory-data-zbom-api/pom.xml @@ -0,0 +1,16 @@ + +blade-service-apiorg.springblade3.2.0.RELEASE + 4.0.0 + + com.logpm + logpm-factory-data-zbom-api + ${bladex.project.version} + jar + + 8 + 8 + + + diff --git a/blade-service-api/logpm-factory-data-zbom-api/src/main/java/com/logpm/factorydata/zbom/feign/IFactoryDataZbomClient.java b/blade-service-api/logpm-factory-data-zbom-api/src/main/java/com/logpm/factorydata/zbom/feign/IFactoryDataZbomClient.java new file mode 100644 index 000000000..cfcfb0d66 --- /dev/null +++ b/blade-service-api/logpm-factory-data-zbom-api/src/main/java/com/logpm/factorydata/zbom/feign/IFactoryDataZbomClient.java @@ -0,0 +1,30 @@ +package com.logpm.factorydata.zbom.feign; + +import org.springblade.common.constant.ModuleNameConstant; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @author zhaoqiaobo + * @create 2024-03-16 15:04 + */ +@FeignClient(value = ModuleNameConstant.LOGPM_FACTORY_DATA_ZBOM_NAME) +public interface IFactoryDataZbomClient { + + String API_PREFIX = "/client/factoryDataZbom"; + String ORDER = API_PREFIX + "/order"; + + + /** + * 保存志邦的订单数据 + * + * @param data + * @return org.springblade.core.tool.api.R + * @author zqb 2024/5/25 + **/ + @PostMapping(ORDER) + R order(@RequestBody String data); + +} diff --git a/blade-service-api/pom.xml b/blade-service-api/pom.xml index 235761346..b7b10a21b 100644 --- a/blade-service-api/pom.xml +++ b/blade-service-api/pom.xml @@ -44,6 +44,7 @@ logpm-factory-data-base-api logpm-business-conversion-api + logpm-factory-data-zbom-api diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/job/AdvanceJob.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/job/AdvanceJob.java index 592b1f3c0..a3812bf5b 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/job/AdvanceJob.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/job/AdvanceJob.java @@ -33,7 +33,6 @@ 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; diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java index 4836e8e22..068267977 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/mq/FactoryOrderListener.java @@ -52,7 +52,6 @@ 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.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; diff --git a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mq/FactoryOrderListener.java b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mq/FactoryOrderListener.java index 107b56005..84a6d100f 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mq/FactoryOrderListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-olo/src/main/java/com/logpm/factorydata/olo/mq/FactoryOrderListener.java @@ -39,7 +39,6 @@ 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.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; diff --git a/blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mq/FactoryOrderListener.java b/blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mq/FactoryOrderListener.java index 9404ecde7..b8666965a 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mq/FactoryOrderListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/mq/FactoryOrderListener.java @@ -41,7 +41,6 @@ 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.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/pom.xml b/blade-service/logpm-factory-data/logpm-factory-data-zbom/pom.xml index cc87f95c7..321222a75 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/pom.xml +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/pom.xml @@ -68,6 +68,11 @@ 3.2.0.RELEASE compile + + com.logpm + logpm-factory-data-zbom-api + 3.2.0.RELEASE + diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/controller/OrderController.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/controller/OrderController.java index fc344839e..c9047b0cb 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/controller/OrderController.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/controller/OrderController.java @@ -89,60 +89,12 @@ public class OrderController { String corpId = request.getHeader("corpId"); zbReceiptDTO.setCorpId(corpId); - // 1 上传数据到 minio 获取到地址 - String url = uploadFile(JSONUtil.toJsonStr(zbReceiptDTO)); - // 2 保存地址到数据库 - FactoryLogEntity logEntity = new FactoryLogEntity(); - logEntity.setType(1); - logEntity.setSaxStatus(SaxStatusEnums.NOMAL.getCode()); - logEntity.setLogUrl(url); - factoryLogService.save(logEntity); + factoryLogService.orderData(zbReceiptDTO); - // 3 将消息发送给 mq,解析保存 - SendMsg build = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER) - .routingKey(FactoryDataConstants.Mq.RoutingKeys.ZBOM_FACTORY_ORDER) - .message(JSONUtil.toJsonStr(logEntity)).build(); - factoryDataClient.sendMessage(build); return ZbResp.success("成功"); } - private String uploadFile(String body) { - //文本内容和保存为本地文件 并上传 - String logPath = FileLogsUtil.saveFileLogs(body); - log.info(">>> 文件路径 {}", logPath); - MultipartFile multi = getMultipartFile(logPath); - //上传到服务器 - R r = ossClient.fileUpload(multi, "zb-order-logs"); - if (r.isSuccess()) { - BladeFile data = (BladeFile) r.getData(); - // 删除本地文件 - FileUtil.del(logPath); - return data.getLink(); - } - return null; - } - - @NotNull - private MultipartFile getMultipartFile(String logPath) { - File file = new File(logPath); - - // File 转 MultipartFile - FileItem item = new DiskFileItemFactory().createItem("file" - , MediaType.MULTIPART_FORM_DATA_VALUE - , true - , file.getName()); - try ( - InputStream input = Files.newInputStream(file.toPath()); - OutputStream os = item.getOutputStream()) { - // 流转移 - IOUtils.copy(input, os); - } catch (Exception e) { - throw new IllegalArgumentException("Invalid file: " + e, e); - } - - return new CommonsMultipartFile(item); - } } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/feign/FactoryDataZbomClient.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/feign/FactoryDataZbomClient.java new file mode 100644 index 000000000..b621af8f4 --- /dev/null +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/feign/FactoryDataZbomClient.java @@ -0,0 +1,26 @@ +package com.logpm.factorydata.zbom.feign; + +import cn.hutool.json.JSONUtil; +import com.logpm.factorydata.zbom.service.FactoryLogService; +import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author zhaoqiaobo + * @create 2024-05-25 + */ +@RestController +@AllArgsConstructor +public class FactoryDataZbomClient implements IFactoryDataZbomClient { + + private final FactoryLogService factoryLogService; + + @Override + public R order(String data) { + factoryLogService.orderData(JSONUtil.toBean(data, ZBReceiptDTO.class)); + return R.success("成功"); + } + +} diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java index 28f005ece..c00f30801 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java @@ -10,8 +10,6 @@ import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; -import cn.hutool.json.JSONArray; -import cn.hutool.json.JSONConfig; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -50,7 +48,6 @@ 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.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -81,10 +78,6 @@ public class ZbomFactoryOrderListener { private final IReceiptService receiptService; private final IPackageInfoService packageInfoService; private final IOrderPackageService orderPackageService; - private final BladeRedis bladeRedis; - private final ZbCategoryContrastMapper zbCategoryContrastMapper; - private final IFactoryDataBaseClient baseClient; - private final IFactoryDataClient factoryDataClient; @RabbitListener(bindings = @QueueBinding( value = @Queue(name = FactoryDataConstants.Mq.Queues.ZBOM_FACTORY_ORDER), @@ -148,8 +141,8 @@ public class ZbomFactoryOrderListener { } } ZbReceiptEntity zbReceiptEntity = new ZbReceiptEntity(); - zbReceiptEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); BeanUtil.copyProperties(zbReceiptDTO, zbReceiptEntity); + zbReceiptEntity.setLogId(ObjectUtil.isNotEmpty(logId) ? logId.toString() : null); // 保存订单数据 receiptService.save(zbReceiptEntity); if (CollUtil.isNotEmpty(details)) { @@ -192,208 +185,8 @@ public class ZbomFactoryOrderListener { // 保存物料数据 packageInfoService.saveBatch(packageInfoEntities); } - // 处理暂存单 - buildAdvance(zbReceiptDTO, packageCode); - } - - @LogpmAsync("asyncExecutor") - public void buildAdvance(ZBReceiptDTO zbReceiptDTO, Set packageCode) { - // 新起线程构建暂存单发送mq - Long startWarehouseId = null; - String startWarehouseName = null; - String tenantId = null; - // 获取工厂基地绑定的始发仓信息 - R warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(zbReceiptDTO.getSenderName(), zbReceiptDTO.getSenderName()); - if (ObjectUtil.equal(HttpConstants.HTTP.HTTP_RESOURCE_CODE.SUCCESS_CODE, warehouseByBrandAndSiteName.getCode())) { - FactoryWarehouseBindVO data = warehouseByBrandAndSiteName.getData(); - if (ObjectUtil.isNotNull(data)) { - startWarehouseId = data.getWarehouseId(); - startWarehouseName = data.getWarehouseName(); - tenantId = data.getTenantId(); - } - } - Map> advanceMap = new HashMap<>(); - List details = zbReceiptDTO.getDetails(); - // 入库单号 + 订单自编号 + 发车单号 一个暂存单 - for (OrderPackageDTO detail : details) { - if (packageCode.contains(detail.getPackageCode())) { - log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不生成暂存单。", detail.getPackageCode()); - continue; - } - String taskCode = zbReceiptDTO.getTaskCode(); - String departCode = zbReceiptDTO.getDepartCode(); - String platformOrderCode = detail.getPlatformOrderCode(); - String advanceKey = taskCode + departCode + platformOrderCode; - if (advanceMap.containsKey(advanceKey)) { - advanceMap.get(advanceKey).add(detail); - } else { - ArrayList orderPackageDTOS = new ArrayList<>(); - orderPackageDTOS.add(detail); - advanceMap.put(advanceKey, orderPackageDTOS); - } - } - // 组装暂存单数据 - List advances = new ArrayList<>(); - for (Map.Entry> stringListEntry : advanceMap.entrySet()) { - List value = stringListEntry.getValue(); - TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); - advanceEntity.setTenantId(tenantId); - advanceEntity.setStatus(0); - advanceEntity.setIsDeleted(0); - advanceEntity.setHasPackage(CollUtil.isNotEmpty(zbReceiptDTO.getDetails()) ? 1 : 0); - advanceEntity.setOrderType(zbReceiptDTO.getOrderType()); - advanceEntity.setBrand(zbReceiptDTO.getSenderName()); - advanceEntity.setSiteName(""); - advanceEntity.setArea(""); - advanceEntity.setTotalNum(CollUtil.isNotEmpty(value) ? value.size() : 0); - advanceEntity.setPackName(""); - advanceEntity.setPackCode(""); - advanceEntity.setWarehouseId(startWarehouseId); - advanceEntity.setWarehouseName(startWarehouseName); - - advanceEntity.setIsGcp(0); - advanceEntity.setCarrierName(zbReceiptDTO.getVendorName()); - advanceEntity.setSystemType("线上"); - advanceEntity.setMatingType("1"); - advanceEntity.setSenderName(zbReceiptDTO.getSenderName()); - advanceEntity.setSenderPhone(zbReceiptDTO.getSenderTel()); - advanceEntity.setSenderAddress(zbReceiptDTO.getSenderAddress()); - advanceEntity.setWaybillStatus("0"); - advanceEntity.setWaybillNo(""); - advanceEntity.setTrainNumber(zbReceiptDTO.getDepartCode()); - advanceEntity.setFreezeStatus("0"); - - advanceEntity.setSenderFactory(zbReceiptDTO.getSenderName()); - List packageList = new ArrayList<>(); - for (OrderPackageDTO orderPackageDTO : value) { - advanceEntity.setOrderCode(orderPackageDTO.getPlatformOrderCode()); - advanceEntity.setDealerCode(orderPackageDTO.getCustomerCode()); - advanceEntity.setDealerName(orderPackageDTO.getCustomerName()); - advanceEntity.setStoreCode(orderPackageDTO.getCustomerCode()); - advanceEntity.setStoreName(orderPackageDTO.getCustomerName()); - advanceEntity.setServiceNum(orderPackageDTO.getRelationOrderCode()); - advanceEntity.setCustomerName(orderPackageDTO.getReceiverName()); - advanceEntity.setCustomerPhone(orderPackageDTO.getReceiverMobile()); - advanceEntity.setCustomerAddress(orderPackageDTO.getReceiverAddress()); - // 根据志邦的一流单标识赋值 - advanceEntity.setLegacyStatus("0"); - if (ObjectUtil.equal(orderPackageDTO.getLegacyFlag(), "Y")) { - advanceEntity.setLegacyStatus("1"); - } - // 封装包件 - TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); - advanceDetailEntity.setWarehouseId(startWarehouseId); - advanceDetailEntity.setWarehouseName(startWarehouseName); - advanceDetailEntity.setOrderCode(orderPackageDTO.getPlatformOrderCode()); - advanceDetailEntity.setBrand(zbReceiptDTO.getSenderName()); - advanceDetailEntity.setSystemType("线上"); - advanceDetailEntity.setFirstPackName(orderPackageDTO.getPackageTypeName()); - advanceDetailEntity.setFirstPackCode(orderPackageDTO.getPackageType()); - // 获取映射志邦映射品类信息 - ZbCategoryContrastEntity zbCategoryContrastEntity = buildZbCategoryContrastEntityCache(orderPackageDTO.getPackageClass()); - if (zbCategoryContrastEntity != null) { - advanceDetailEntity.setSecondPackName(zbCategoryContrastEntity.getSecondName());//二级品类名称 - advanceDetailEntity.setSecondPackCode(zbCategoryContrastEntity.getSecondCode());//二级品类 - advanceDetailEntity.setThirdPackName(zbCategoryContrastEntity.getThirdName());//三级品类名称 - advanceDetailEntity.setThirdPackCode(zbCategoryContrastEntity.getThirdCode());//三级品类 - } else { - advanceDetailEntity.setSecondPackName(StringUtil.isBlank(orderPackageDTO.getPackageClass()) ? "" : orderPackageDTO.getPackageClass());//二级品类名称 - advanceDetailEntity.setSecondPackCode("");//二级品类 - advanceDetailEntity.setThirdPackName(StringUtil.isBlank(orderPackageDTO.getPackageClass()) ? "" : orderPackageDTO.getPackageClass());//三级品类名称 - advanceDetailEntity.setThirdPackCode("");//三级品类 - } - advanceDetailEntity.setSiteName(""); - advanceDetailEntity.setSiteCode(""); - String planQty = orderPackageDTO.getPlanQty(); - advanceDetailEntity.setQuantity((StrUtil.isNotBlank(planQty) && NumberUtil.isNumber(planQty)) ? Convert.toInt(planQty) : 0); - advanceDetailEntity.setOrderPackageCode(orderPackageDTO.getPackageCode()); - advanceDetailEntity.setTrainNumber(zbReceiptDTO.getDepartCode()); - advanceDetailEntity.setServiceNum(orderPackageDTO.getRelationOrderCode()); - advanceDetailEntity.setWaybillNo(""); - advanceDetailEntity.setPackageStatus("0"); - advanceDetailEntity.setWeight(StrUtil.isNotBlank(orderPackageDTO.getTotalGrossWeight()) ? new BigDecimal(orderPackageDTO.getTotalGrossWeight()) : BigDecimal.ZERO); - advanceDetailEntity.setVolume(StrUtil.isNotBlank(orderPackageDTO.getTotalVolume()) ? new BigDecimal(orderPackageDTO.getTotalVolume()) : BigDecimal.ZERO); -// advanceDetailEntity.setChargeType(0); - advanceDetailEntity.setSupple(""); - advanceDetailEntity.setManifest(""); - advanceDetailEntity.setReturnNum(""); - advanceDetailEntity.setSendDateStr(DateUtil.formatLocalDateTime(LocalDateTime.now())); - advanceDetailEntity.setCarNumber(""); - advanceDetailEntity.setGoodsMan(""); - advanceDetailEntity.setTenantId(tenantId); - advanceDetailEntity.setStatus(0); - advanceDetailEntity.setIsDeleted(0); - List itemJsons = new ArrayList<>(); - List items = orderPackageDTO.getItems(); - for (PackageInfoDTO item : items) { - TrunklineDetailProductEntity detailProductEntity = new TrunklineDetailProductEntity(); - detailProductEntity.setTenantId(tenantId); - detailProductEntity.setWarehouseId(startWarehouseId); - detailProductEntity.setWarehouseName(startWarehouseName); - detailProductEntity.setUnitNo(orderPackageDTO.getPackageCode()); - detailProductEntity.setProductCode(item.getItemCode()); - detailProductEntity.setProductName(item.getItemName()); - detailProductEntity.setQuantity(item.getPlanQty()); - detailProductEntity.setStatus(0); - detailProductEntity.setIsDeleted(0); - itemJsons.add(JSONUtil.parseObj(detailProductEntity)); - } - JSONObject entries = JSONUtil.parseObj(advanceDetailEntity); - entries.set("items", itemJsons); - 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); - } - } - } - - private ZbCategoryContrastEntity buildZbCategoryContrastEntityCache(String packageClass) { - - - if (StringUtil.isBlank(packageClass)) { - return null; - } - if (containsChinese(packageClass)) { - return null; - } - - String key = TenantNum.HUITONGCODE + ":" + ZbCategoryContrastEntity.class.getName() + ":" + packageClass; - ZbCategoryContrastEntity zbCategoryContrastEntity = bladeRedis.get(key); - if (zbCategoryContrastEntity == null) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("source_code", packageClass); - queryWrapper.eq("status", "1"); - zbCategoryContrastEntity = zbCategoryContrastMapper.selectOne(queryWrapper); - if (!Objects.isNull(zbCategoryContrastEntity)) { - // 缓存起来 - bladeRedis.setEx(key, zbCategoryContrastEntity, 3600 * 24L); - } - } - return zbCategoryContrastEntity; - - - } - - /** - * 验证参数中是否包含中文 - * - * @param str 匹配参数 - * @return true 包含中文 false 不包含中文 - */ - private boolean containsChinese(String str) { - Pattern pattern = Pattern.compile(PatternConstant.REGEX_CHINESE); - Matcher matcher = pattern.matcher(str); - return matcher.find(); + // 处理暂存单 TODO 暂时关闭推送新系统暂存单 +// receiptService.buildAdvance(zbReceiptDTO, packageCode); } } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/FactoryLogService.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/FactoryLogService.java index 97fb2001c..a541316f7 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/FactoryLogService.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/FactoryLogService.java @@ -1,6 +1,7 @@ package com.logpm.factorydata.zbom.service; import com.logpm.factorydata.zbom.entity.FactoryLogEntity; +import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; import org.springblade.core.mp.base.BaseService; /** @@ -11,4 +12,5 @@ import org.springblade.core.mp.base.BaseService; **/ public interface FactoryLogService extends BaseService { + void orderData(ZBReceiptDTO zbReceiptDTO); } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IReceiptService.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IReceiptService.java index f7ebdee19..f2cd4e869 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IReceiptService.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/IReceiptService.java @@ -17,8 +17,11 @@ package com.logpm.factorydata.zbom.service; import com.logpm.factorydata.zbom.entity.ZbReceiptEntity; +import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; import org.springblade.core.mp.base.BaseService; +import java.util.Set; + /** * 志邦入库单 服务类 * @@ -27,4 +30,6 @@ import org.springblade.core.mp.base.BaseService; */ public interface IReceiptService extends BaseService { + void buildAdvance(ZBReceiptDTO zbReceiptDTO, Set packageCode); + } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/FactoryLogServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/FactoryLogServiceImpl.java index 95f402004..fd35e8e87 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/FactoryLogServiceImpl.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/FactoryLogServiceImpl.java @@ -1,12 +1,35 @@ package com.logpm.factorydata.zbom.service.impl; +import cn.hutool.core.io.FileUtil; +import cn.hutool.json.JSONUtil; +import com.logpm.factorydata.enums.SaxStatusEnums; +import com.logpm.factorydata.feign.IFactoryDataClient; +import com.logpm.factorydata.vo.SendMsg; import com.logpm.factorydata.zbom.entity.FactoryLogEntity; import com.logpm.factorydata.zbom.mapper.FactoryLogMapper; import com.logpm.factorydata.zbom.service.FactoryLogService; +import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.io.IOUtils; +import org.jetbrains.annotations.NotNull; +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.tool.api.R; +import org.springblade.resource.feign.IOssClient; +import org.springframework.http.MediaType; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.commons.CommonsMultipartFile; + +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; /** * 工厂订单日志 业务实现类 @@ -19,4 +42,64 @@ import org.springframework.stereotype.Service; @AllArgsConstructor public class FactoryLogServiceImpl extends BaseServiceImpl implements FactoryLogService { + + private final IFactoryDataClient factoryDataClient; + + private final IOssClient ossClient; + + @Override + public void orderData(ZBReceiptDTO zbReceiptDTO) { + // 1 上传数据到 minio 获取到地址 + String url = uploadFile(JSONUtil.toJsonStr(zbReceiptDTO)); + // 2 保存地址到数据库 + FactoryLogEntity logEntity = new FactoryLogEntity(); + logEntity.setType(1); + logEntity.setSaxStatus(SaxStatusEnums.NOMAL.getCode()); + logEntity.setLogUrl(url); + this.save(logEntity); + + // 3 将消息发送给 mq,解析保存 + SendMsg build = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.FACTORY_ORDER) + .routingKey(FactoryDataConstants.Mq.RoutingKeys.ZBOM_FACTORY_ORDER) + .message(JSONUtil.toJsonStr(logEntity)).build(); + factoryDataClient.sendMessage(build); + } + + private String uploadFile(String body) { + //文本内容和保存为本地文件 并上传 + String logPath = FileLogsUtil.saveFileLogs(body); + log.info(">>> 文件路径 {}", logPath); + + MultipartFile multi = getMultipartFile(logPath); + //上传到服务器 + R r = ossClient.fileUpload(multi, "zb-order-logs"); + if (r.isSuccess()) { + BladeFile data = (BladeFile) r.getData(); + // 删除本地文件 + FileUtil.del(logPath); + return data.getLink(); + } + return null; + } + + @NotNull + private MultipartFile getMultipartFile(String logPath) { + File file = new File(logPath); + + // File 转 MultipartFile + FileItem item = new DiskFileItemFactory().createItem("file" + , MediaType.MULTIPART_FORM_DATA_VALUE + , true + , file.getName()); + try ( + InputStream input = Files.newInputStream(file.toPath()); + OutputStream os = item.getOutputStream()) { + // 流转移 + IOUtils.copy(input, os); + } catch (Exception e) { + throw new IllegalArgumentException("Invalid file: " + e, e); + } + + return new CommonsMultipartFile(item); + } } diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java index 11878d7fb..5a84b31de 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/service/impl/ReceiptServiceImpl.java @@ -16,14 +16,54 @@ */ package com.logpm.factorydata.zbom.service.impl; +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.conditions.query.QueryWrapper; +import com.logpm.factorydata.base.feign.IFactoryDataBaseClient; +import com.logpm.factorydata.base.vo.FactoryWarehouseBindVO; +import com.logpm.factorydata.feign.IFactoryDataClient; +import com.logpm.factorydata.vo.SendMsg; +import com.logpm.factorydata.zbom.entity.ZbCategoryContrastEntity; import com.logpm.factorydata.zbom.entity.ZbReceiptEntity; import com.logpm.factorydata.zbom.mapper.ReceiptMapper; +import com.logpm.factorydata.zbom.mapper.ZbCategoryContrastMapper; import com.logpm.factorydata.zbom.service.IReceiptService; +import com.logpm.factorydata.zbom.vo.OrderPackageDTO; +import com.logpm.factorydata.zbom.vo.PackageInfoDTO; +import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; +import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; +import com.logpm.trunkline.entity.TrunklineAdvanceEntity; +import com.logpm.trunkline.entity.TrunklineDetailProductEntity; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.common.annotations.LogpmAsync; +import org.springblade.common.constant.HttpConstants; +import org.springblade.common.constant.PatternConstant; +import org.springblade.common.constant.TenantNum; +import org.springblade.common.constant.factorydata.FactoryDataConstants; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.redis.cache.BladeRedis; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * 志邦入库单 服务实现类 * @@ -35,4 +75,209 @@ import org.springframework.stereotype.Service; @AllArgsConstructor public class ReceiptServiceImpl extends BaseServiceImpl implements IReceiptService { + private final BladeRedis bladeRedis; + private final ZbCategoryContrastMapper zbCategoryContrastMapper; + private final IFactoryDataBaseClient baseClient; + private final IFactoryDataClient factoryDataClient; + + @Override + @LogpmAsync("asyncExecutor") + public void buildAdvance(ZBReceiptDTO zbReceiptDTO, Set packageCode) { + // 新起线程构建暂存单发送mq + Long startWarehouseId = null; + String startWarehouseName = null; + String tenantId = null; + // 获取工厂基地绑定的始发仓信息 + R warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(zbReceiptDTO.getSenderName(), zbReceiptDTO.getSenderName()); + if (ObjectUtil.equal(HttpConstants.HTTP.HTTP_RESOURCE_CODE.SUCCESS_CODE, warehouseByBrandAndSiteName.getCode())) { + FactoryWarehouseBindVO data = warehouseByBrandAndSiteName.getData(); + if (ObjectUtil.isNotNull(data)) { + startWarehouseId = data.getWarehouseId(); + startWarehouseName = data.getWarehouseName(); + tenantId = data.getTenantId(); + } + } + Map> advanceMap = new HashMap<>(); + List details = zbReceiptDTO.getDetails(); + // 入库单号 + 订单自编号 + 发车单号 一个暂存单 + for (OrderPackageDTO detail : details) { + if (packageCode.contains(detail.getPackageCode())) { + log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不生成暂存单。", detail.getPackageCode()); + continue; + } + String taskCode = zbReceiptDTO.getTaskCode(); + String departCode = zbReceiptDTO.getDepartCode(); + String platformOrderCode = detail.getPlatformOrderCode(); + String advanceKey = taskCode + departCode + platformOrderCode; + if (advanceMap.containsKey(advanceKey)) { + advanceMap.get(advanceKey).add(detail); + } else { + ArrayList orderPackageDTOS = new ArrayList<>(); + orderPackageDTOS.add(detail); + advanceMap.put(advanceKey, orderPackageDTOS); + } + } + // 组装暂存单数据 + List advances = new ArrayList<>(); + for (Map.Entry> stringListEntry : advanceMap.entrySet()) { + List value = stringListEntry.getValue(); + TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); + advanceEntity.setTenantId(tenantId); + advanceEntity.setStatus(0); + advanceEntity.setIsDeleted(0); + advanceEntity.setHasPackage(CollUtil.isNotEmpty(zbReceiptDTO.getDetails()) ? 1 : 0); + advanceEntity.setOrderType(zbReceiptDTO.getOrderType()); + advanceEntity.setBrand(zbReceiptDTO.getSenderName()); + advanceEntity.setSiteName(""); + advanceEntity.setArea(""); + advanceEntity.setTotalNum(CollUtil.isNotEmpty(value) ? value.size() : 0); + advanceEntity.setPackName(""); + advanceEntity.setPackCode(""); + advanceEntity.setWarehouseId(startWarehouseId); + advanceEntity.setWarehouseName(startWarehouseName); + + advanceEntity.setIsGcp(0); + advanceEntity.setCarrierName(zbReceiptDTO.getVendorName()); + advanceEntity.setSystemType("线上"); + advanceEntity.setMatingType("1"); + advanceEntity.setSenderName(zbReceiptDTO.getSenderName()); + advanceEntity.setSenderPhone(zbReceiptDTO.getSenderTel()); + advanceEntity.setSenderAddress(zbReceiptDTO.getSenderAddress()); + advanceEntity.setWaybillStatus("0"); + advanceEntity.setWaybillNo(""); + advanceEntity.setTrainNumber(zbReceiptDTO.getDepartCode()); + advanceEntity.setFreezeStatus("0"); + + advanceEntity.setSenderFactory(zbReceiptDTO.getSenderName()); + List packageList = new ArrayList<>(); + for (OrderPackageDTO orderPackageDTO : value) { + advanceEntity.setOrderCode(orderPackageDTO.getPlatformOrderCode()); + advanceEntity.setDealerCode(orderPackageDTO.getCustomerCode()); + advanceEntity.setDealerName(orderPackageDTO.getCustomerName()); + advanceEntity.setStoreCode(orderPackageDTO.getCustomerCode()); + advanceEntity.setStoreName(orderPackageDTO.getCustomerName()); + advanceEntity.setServiceNum(orderPackageDTO.getRelationOrderCode()); + advanceEntity.setCustomerName(orderPackageDTO.getReceiverName()); + advanceEntity.setCustomerPhone(orderPackageDTO.getReceiverMobile()); + advanceEntity.setCustomerAddress(orderPackageDTO.getReceiverAddress()); + // 根据志邦的一流单标识赋值 + advanceEntity.setLegacyStatus("0"); + if (ObjectUtil.equal(orderPackageDTO.getLegacyFlag(), "Y")) { + advanceEntity.setLegacyStatus("1"); + } + // 封装包件 + TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); + advanceDetailEntity.setWarehouseId(startWarehouseId); + advanceDetailEntity.setWarehouseName(startWarehouseName); + advanceDetailEntity.setOrderCode(orderPackageDTO.getPlatformOrderCode()); + advanceDetailEntity.setBrand(zbReceiptDTO.getSenderName()); + advanceDetailEntity.setSystemType("线上"); + advanceDetailEntity.setFirstPackName(orderPackageDTO.getPackageTypeName()); + advanceDetailEntity.setFirstPackCode(orderPackageDTO.getPackageType()); + // 获取映射志邦映射品类信息 + ZbCategoryContrastEntity zbCategoryContrastEntity = buildZbCategoryContrastEntityCache(orderPackageDTO.getPackageClass()); + if (zbCategoryContrastEntity != null) { + advanceDetailEntity.setSecondPackName(zbCategoryContrastEntity.getSecondName());//二级品类名称 + advanceDetailEntity.setSecondPackCode(zbCategoryContrastEntity.getSecondCode());//二级品类 + advanceDetailEntity.setThirdPackName(zbCategoryContrastEntity.getThirdName());//三级品类名称 + advanceDetailEntity.setThirdPackCode(zbCategoryContrastEntity.getThirdCode());//三级品类 + } else { + advanceDetailEntity.setSecondPackName(StringUtil.isBlank(orderPackageDTO.getPackageClass()) ? "" : orderPackageDTO.getPackageClass());//二级品类名称 + advanceDetailEntity.setSecondPackCode("");//二级品类 + advanceDetailEntity.setThirdPackName(StringUtil.isBlank(orderPackageDTO.getPackageClass()) ? "" : orderPackageDTO.getPackageClass());//三级品类名称 + advanceDetailEntity.setThirdPackCode("");//三级品类 + } + advanceDetailEntity.setSiteName(""); + advanceDetailEntity.setSiteCode(""); + String planQty = orderPackageDTO.getPlanQty(); + advanceDetailEntity.setQuantity((StrUtil.isNotBlank(planQty) && NumberUtil.isNumber(planQty)) ? Convert.toInt(planQty) : 0); + advanceDetailEntity.setOrderPackageCode(orderPackageDTO.getPackageCode()); + advanceDetailEntity.setTrainNumber(zbReceiptDTO.getDepartCode()); + advanceDetailEntity.setServiceNum(orderPackageDTO.getRelationOrderCode()); + advanceDetailEntity.setWaybillNo(""); + advanceDetailEntity.setPackageStatus("0"); + advanceDetailEntity.setWeight(StrUtil.isNotBlank(orderPackageDTO.getTotalGrossWeight()) ? new BigDecimal(orderPackageDTO.getTotalGrossWeight()) : BigDecimal.ZERO); + advanceDetailEntity.setVolume(StrUtil.isNotBlank(orderPackageDTO.getTotalVolume()) ? new BigDecimal(orderPackageDTO.getTotalVolume()) : BigDecimal.ZERO); +// advanceDetailEntity.setChargeType(0); + advanceDetailEntity.setSupple(""); + advanceDetailEntity.setManifest(""); + advanceDetailEntity.setReturnNum(""); + advanceDetailEntity.setSendDateStr(DateUtil.formatLocalDateTime(LocalDateTime.now())); + advanceDetailEntity.setCarNumber(""); + advanceDetailEntity.setGoodsMan(""); + advanceDetailEntity.setTenantId(tenantId); + advanceDetailEntity.setStatus(0); + advanceDetailEntity.setIsDeleted(0); + List itemJsons = new ArrayList<>(); + List items = orderPackageDTO.getItems(); + for (PackageInfoDTO item : items) { + TrunklineDetailProductEntity detailProductEntity = new TrunklineDetailProductEntity(); + detailProductEntity.setTenantId(tenantId); + detailProductEntity.setWarehouseId(startWarehouseId); + detailProductEntity.setWarehouseName(startWarehouseName); + detailProductEntity.setUnitNo(orderPackageDTO.getPackageCode()); + detailProductEntity.setProductCode(item.getItemCode()); + detailProductEntity.setProductName(item.getItemName()); + detailProductEntity.setQuantity(item.getPlanQty()); + detailProductEntity.setStatus(0); + detailProductEntity.setIsDeleted(0); + itemJsons.add(JSONUtil.parseObj(detailProductEntity)); + } + JSONObject entries = JSONUtil.parseObj(advanceDetailEntity); + entries.set("items", itemJsons); + 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); + } + } + } + + private ZbCategoryContrastEntity buildZbCategoryContrastEntityCache(String packageClass) { + + + if (StringUtil.isBlank(packageClass)) { + return null; + } + if (containsChinese(packageClass)) { + return null; + } + + String key = TenantNum.HUITONGCODE + ":" + ZbCategoryContrastEntity.class.getName() + ":" + packageClass; + ZbCategoryContrastEntity zbCategoryContrastEntity = bladeRedis.get(key); + if (zbCategoryContrastEntity == null) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("source_code", packageClass); + queryWrapper.eq("status", "1"); + zbCategoryContrastEntity = zbCategoryContrastMapper.selectOne(queryWrapper); + if (!Objects.isNull(zbCategoryContrastEntity)) { + // 缓存起来 + bladeRedis.setEx(key, zbCategoryContrastEntity, 3600 * 24L); + } + } + return zbCategoryContrastEntity; + + + } + + /** + * 验证参数中是否包含中文 + * + * @param str 匹配参数 + * @return true 包含中文 false 不包含中文 + */ + private boolean containsChinese(String str) { + Pattern pattern = Pattern.compile(PatternConstant.REGEX_CHINESE); + Matcher matcher = pattern.matcher(str); + return matcher.find(); + } } diff --git a/blade-service/logpm-factory/pom.xml b/blade-service/logpm-factory/pom.xml index 7cb61d98f..a441e8eb8 100644 --- a/blade-service/logpm-factory/pom.xml +++ b/blade-service/logpm-factory/pom.xml @@ -129,6 +129,11 @@ logpm-factory-data-api 3.2.0.RELEASE + + com.logpm + logpm-factory-data-zbom-api + 3.2.0.RELEASE + diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/AsyncDataServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/AsyncDataServiceImpl.java index 58da45406..d70d6360a 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/AsyncDataServiceImpl.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/service/impl/AsyncDataServiceImpl.java @@ -64,7 +64,6 @@ import lombok.extern.log4j.Log4j2; import org.jetbrains.annotations.Nullable; import org.springblade.common.annotations.LogpmAsync; import org.springblade.common.constant.HttpConstants; -import org.springblade.common.constant.PackagesTypeEnum; import org.springblade.common.constant.PatternConstant; import org.springblade.common.constant.TenantNum; import org.springblade.common.constant.factorydata.FactoryDataConstants; @@ -72,9 +71,7 @@ import org.springblade.core.redis.cache.BladeRedis; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; import java.math.BigDecimal; import java.sql.Timestamp; diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java index 190350ed0..1724153db 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java @@ -36,8 +36,8 @@ public class InterceptorAdapterConfig implements WebMvcConfigurer { excludePathPatterns("/factory/oupai/**"). excludePathPatterns("/factory/zb/**") .excludePathPatterns("/factory/common/**").order(2); - interceptorRegistry.addInterceptor(new ZbFactoryAccountsInterceptor(zbFactoryProperties)) - .addPathPatterns("/factory/zb/**").order(3); +// interceptorRegistry.addInterceptor(new ZbFactoryAccountsInterceptor(zbFactoryProperties)) +// .addPathPatterns("/factory/zb/**").order(3); interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis,environment,redisLockClient)).addPathPatterns("/**").order(1); } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/FactoryXxlJob.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/FactoryXxlJob.java index c4bc88834..3e848b056 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/FactoryXxlJob.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/FactoryXxlJob.java @@ -4,8 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -18,7 +16,6 @@ import com.logpm.factory.snm.entity.StaorderPackagesEntity; import com.logpm.factory.snm.entity.StationOrderEntity; import com.logpm.factory.snm.entity.StationlinenumEntity; import com.logpm.factory.snm.service.*; -import com.logpm.factory.zb.vo.PackageInfoVO; import com.logpm.factorydata.base.feign.IFactoryDataBaseClient; import com.logpm.factorydata.base.vo.FactoryWarehouseBindVO; import com.logpm.factorydata.enums.BrandEnums; @@ -43,7 +40,6 @@ import org.springblade.common.constant.PackagesTypeEnum; import org.springblade.common.constant.factorydata.FactoryDataConstants; import org.springblade.common.utils.CommonUtil; import org.springblade.core.tool.api.R; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/controller/ZbFactoryDataController.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/controller/ZbFactoryDataController.java index 053398d46..ff332bdd9 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/controller/ZbFactoryDataController.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/controller/ZbFactoryDataController.java @@ -21,13 +21,16 @@ import org.springblade.core.oss.model.BladeFile; import org.springblade.core.tool.api.R; import org.springblade.resource.feign.IOssClient; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; +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 org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.commons.CommonsMultipartFile; import javax.servlet.http.HttpServletRequest; import java.io.File; -import java.io.FileInputStream; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; @@ -35,6 +38,7 @@ import java.util.Objects; /** * 志邦工厂数据推送 + * * @author pref * @data 2023-02-21 */ @@ -55,6 +59,7 @@ public class ZbFactoryDataController { private final IOssClient ossClient; + /** * 工厂数据推送接口 */ @@ -62,15 +67,15 @@ public class ZbFactoryDataController { @PostMapping("/data") @ApiOperationSupport(order = 1) @ApiOperation(value = "工厂数据推送", notes = "传入factoryOrderDTO") - public ZbResp data(@RequestBody ZBReceiptDTO zbReceiptDTO, HttpServletRequest request) { + public ZbResp data(@RequestBody ZBReceiptDTO zbReceiptDTO, HttpServletRequest request) { - log.info("############zbReceiptDTO: {}",zbReceiptDTO); + log.info("############zbReceiptDTO: {}", zbReceiptDTO); String corpId = request.getHeader("corpId"); zbReceiptDTO.setCorpId(corpId); String method = request.getParameter("method"); - if(!"entry.order.create".equals(method)){ - log.warn("############data: 暂不支持该功能 method={}",method); + if (!"entry.order.create".equals(method)) { + log.warn("############data: 暂不支持该功能 method={}", method); return ZbResp.fail("暂不支持该功能"); } @@ -99,12 +104,12 @@ public class ZbFactoryDataController { // //判断数据是否已存入 Long orderId = null; - try{ + try { orderId = zbFactoryDataService.saveData(zbReceiptDTO); // orderStatusLog.setStatus(0); zbFactoryLogEntity.setSaxStatus(1); - }catch (Exception e){ - log.error("############data: 保存数据失败",e); + } catch (Exception e) { + log.error("############data: 保存数据失败", e); //修改保存数据的状态 // orderStatusLog.setStatus(2); zbFactoryLogEntity.setSaxStatus(2); @@ -113,9 +118,15 @@ public class ZbFactoryDataController { zbFactoryLogService.saveOrUpdate(zbFactoryLogEntity); //开启异步线程处理数据 - if(!Objects.isNull(orderId)){ + if (!Objects.isNull(orderId)) { syncDataService.handlerZbDataToHt(orderId); } + // 推送数据到新系统 + try { + zbFactoryDataService.saveDataNew(zbReceiptDTO); + } catch (Exception e) { + log.error("志邦数据传新系统失败"); + } return ZbResp.success("成功"); } @@ -126,7 +137,7 @@ public class ZbFactoryDataController { MultipartFile multi = getMultipartFile(logPath); //上传到服务器 - R r = ossClient.fileUpload(multi,"zb-logs"); + R r = ossClient.fileUpload(multi, "zb-logs"); if (r.isSuccess()) { BladeFile data = (BladeFile) r.getData(); return data.getLink(); @@ -147,8 +158,8 @@ public class ZbFactoryDataController { , true , file.getName()); try ( - InputStream input = Files.newInputStream(file.toPath()); - OutputStream os = item.getOutputStream()) { + InputStream input = Files.newInputStream(file.toPath()); + OutputStream os = item.getOutputStream()) { // 流转移 IOUtils.copy(input, os); } catch (Exception e) { diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryDataService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryDataService.java index be748a7f6..ccd0c0c97 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryDataService.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryDataService.java @@ -16,4 +16,6 @@ public interface IZbFactoryDataService { R handleStatusData(OrderStatusDTO orderStatusDTO); + void saveDataNew(ZBReceiptDTO zbReceiptDTO); + } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryDataServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryDataServiceImpl.java index 074f2e2b9..e9c24b8e3 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryDataServiceImpl.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryDataServiceImpl.java @@ -17,12 +17,14 @@ import com.logpm.factory.zb.entity.ZbPackageInfoEntity; import com.logpm.factory.zb.entity.ZbReceiptEntity; import com.logpm.factory.zb.service.*; import com.logpm.factory.zb.untils.QmSignUntil; +import com.logpm.factorydata.zbom.feign.IFactoryDataZbomClient; import com.logpm.oldproject.entity.AdvanceDetailEntity; import com.logpm.oldproject.feign.IAdvanceClient; import com.logpm.oldproject.feign.IAdvanceDetailClient; import com.logpm.oldproject.feign.IOrderDetailClient; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.common.annotations.LogpmAsync; import org.springblade.common.utils.CommonUtil; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; @@ -46,6 +48,7 @@ public class ZbFactoryDataServiceImpl implements IZbFactoryDataService { private final IPackageInfoService packageInfoService; private final ZbFactoryProperties zbFactoryProperties; private final IZbOrderLogService zbOrderLogService; + private final IFactoryDataZbomClient zbomClient; @Override public Long saveData(ZBReceiptDTO zbReceiptDTO) { @@ -218,6 +221,12 @@ public class ZbFactoryDataServiceImpl implements IZbFactoryDataService { } } + @Override + @LogpmAsync("asyncExecutor") + public void saveDataNew(ZBReceiptDTO zbReceiptDTO) { + zbomClient.order(JSONObject.toJSONString(zbReceiptDTO)); + } + private String getZbUrl(String url, Map params, String sign) { String[] keys = params.keySet().toArray(new String[0]); diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/InComingServiceImpl.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/InComingServiceImpl.java index 24148ed30..f0a7f33c1 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/InComingServiceImpl.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/InComingServiceImpl.java @@ -1,16 +1,25 @@ package com.logpm.trunkline.service.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.logpm.basicdata.entity.BasicdataWarehouseEntity; import com.logpm.basicdata.feign.IBasicdataWarehouseClient; +import com.logpm.factorydata.enums.BrandEnums; +import com.logpm.factorydata.util.FactoryDataMessageSender; +import com.logpm.factorydata.vo.NodePushMsg; +import com.logpm.factorydata.vo.PushData; import com.logpm.trunkline.bean.Resp; import com.logpm.trunkline.dto.InComingDTO; import com.logpm.trunkline.dto.OrderStatusDTO; import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; import com.logpm.trunkline.entity.TrunklineBillladingPackageEntity; -import com.logpm.trunkline.service.*; +import com.logpm.trunkline.service.IInComingService; +import com.logpm.trunkline.service.IPackageTrackLogAsyncService; +import com.logpm.trunkline.service.ITrunklineAdvanceDetailService; +import com.logpm.trunkline.service.ITrunklineAdvanceService; +import com.logpm.trunkline.service.ITrunklineBillladingPackageServicie; import com.logpm.trunkline.vo.TrunklineAdvanceVO; import com.logpm.warehouse.entity.WarehouseWaybillEntity; import com.logpm.warehouse.feign.IWarehouseTrayTypeClient; @@ -26,7 +35,13 @@ import org.springblade.core.tool.utils.StringUtil; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; @Slf4j @Service @@ -41,6 +56,7 @@ public class InComingServiceImpl implements IInComingService { private final IPackageTrackLogAsyncService packageTrackLogAsyncService; // private final DynamicDataSourceProvider dynamicDataSourceProvider; private final RabbitTemplate rabbitTemplate; + private final FactoryDataMessageSender factoryDataMessageSender; @Override @@ -145,6 +161,16 @@ public class InComingServiceImpl implements IInComingService { Map map = new HashMap<>(); map.put("messageData", JSONUtil.toJsonStr(orderStatusDTO)); rabbitTemplate.convertAndSend(RabbitConstant.HWY_ORDER_STATUS_EXCHANGE, RabbitConstant.HWY_ORDER_STATUS_ROUTING, map); + + NodePushMsg nodePushMsg = NodePushMsg.builder() + .operator(AuthUtil.getNickName()) + .operatorTime(new Date()) + .address("在【"+ warehouseName +"】入库") + .brand(BrandEnums.getByValue(advanceDetailEntity.getBrand())) + .node(WorkNodeEnums.INITIAL_WAREHOUSE_ENTRY) + .content(Arrays.asList(PushData.builder().packageCode(packageCode).build())) + .build(); + factoryDataMessageSender.sendNodeDataByBrand(nodePushMsg); } catch (Exception e) { log.error("入库推送失败:{}", e); } @@ -215,6 +241,20 @@ public class InComingServiceImpl implements IInComingService { //存入日志 packageTrackLogAsyncService.addPackageTrackLog(tenantId, userId, deptId, nickName, orderPackageCodes, warehouseId, warehouseName, WorkNodeEnums.INITIAL_WAREHOUSE_ENTRY.getCode(), "包件" + IncomingTypeEnum.getValue(incomingType)); total = total + detailList.size(); + if(CollUtil.isNotEmpty(detailList)){ + for (TrunklineAdvanceDetailEntity advanceDetailEntity : detailList) { + NodePushMsg nodePushMsg = NodePushMsg.builder() + .operator(AuthUtil.getNickName()) + .operatorTime(new Date()) + .address("在【"+ warehouseName +"】入库") + .brand(BrandEnums.getByValue(advanceDetailEntity.getBrand())) + .node(WorkNodeEnums.INITIAL_WAREHOUSE_ENTRY) + .content(Arrays.asList(PushData.builder().packageCode(advanceDetailEntity.getOrderPackageCode()).build())) + .build(); + factoryDataMessageSender.sendNodeDataByBrand(nodePushMsg); + } + } + } // DynamicDataSourceContextHolder.clear();