From cfc36d052728c12d87b2bfa4cd45ce7b3127f880 Mon Sep 17 00:00:00 2001 From: "pref_mail@163.com" <123456> Date: Wed, 4 Oct 2023 13:11:35 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E5=BF=97=E9=82=A6=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E9=87=87=E7=94=A8=E6=96=87=E4=BB=B6=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../factory/zb/entity/ZbFactoryLogEntity.java | 42 ++++++++ .../controller/ZbFactoryDataController.java | 100 ++++++++++++++++-- .../factory/zb/mapper/ZbFactoryLogMapper.java | 9 ++ .../factory/zb/mapper/ZbFactoryLogMapper.xml | 9 ++ .../zb/service/IZbFactoryLogService.java | 7 ++ .../service/impl/ZbFactoryLogServiceImpl.java | 12 +++ .../java/com/logpm/factory/TestService.java | 15 +++ 7 files changed, 184 insertions(+), 10 deletions(-) create mode 100644 blade-service-api/logpm-factory-api/src/main/java/com/logpm/factory/zb/entity/ZbFactoryLogEntity.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.xml create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryLogService.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryLogServiceImpl.java diff --git a/blade-service-api/logpm-factory-api/src/main/java/com/logpm/factory/zb/entity/ZbFactoryLogEntity.java b/blade-service-api/logpm-factory-api/src/main/java/com/logpm/factory/zb/entity/ZbFactoryLogEntity.java new file mode 100644 index 000000000..dc13a3a0b --- /dev/null +++ b/blade-service-api/logpm-factory-api/src/main/java/com/logpm/factory/zb/entity/ZbFactoryLogEntity.java @@ -0,0 +1,42 @@ +package com.logpm.factory.zb.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; + +@Data +@TableName("zb_factory_log") +@ApiModel(value = "志邦工厂数据推送", description = "志邦接口日志") +@EqualsAndHashCode(callSuper = true) +public class ZbFactoryLogEntity extends BaseEntity { + + /** 预留1 */ + @ApiModelProperty(name = "预留1",notes = "") + private String reserve1 ; + /** 预留2 */ + @ApiModelProperty(name = "预留2",notes = "") + private String reserve2 ; + /** 预留3 */ + @ApiModelProperty(name = "预留3",notes = "") + private String reserve3 ; + /** 预留4 */ + @ApiModelProperty(name = "预留4",notes = "") + private String reserve4 ; + /** 预留5 */ + @ApiModelProperty(name = "预留5",notes = "") + private String reserve5 ; + /** 日志文件存放地址 */ + @ApiModelProperty(name = "日志文件存放地址",notes = "") + private String logUrl ; + /** 数据类型 1.入库数据 */ + @ApiModelProperty(name = "数据类型 1.入库数据",notes = "") + private Integer type ; + /** 解析状态 0 未解析 1 已解析 2 解析失败 */ + @ApiModelProperty(name = "解析状态 0 未解析 1 已解析 2 解析失败",notes = "") + private Integer saxStatus ; + + +} 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 59c5cbde1..16e7e43f9 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 @@ -7,16 +7,34 @@ import com.logpm.factory.comfac.service.IOrderStatusLogService; import com.logpm.factory.snm.entity.OrderStatusLog; import com.logpm.factory.zb.bean.ZbResp; import com.logpm.factory.zb.dto.ZBReceiptDTO; +import com.logpm.factory.zb.entity.ZbFactoryLogEntity; import com.logpm.factory.zb.entity.ZbOrderLogEntity; import com.logpm.factory.zb.service.IZbFactoryDataService; +import com.logpm.factory.zb.service.IZbFactoryLogService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import lombok.extern.log4j.Log4j2; +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.utils.FileLogsUtil; +import org.springblade.core.oss.model.BladeFile; +import org.springblade.core.tool.api.R; +import org.springblade.resource.feign.IOssClient; import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; +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.util.Objects; /** @@ -31,12 +49,16 @@ import java.util.Objects; @Api(value = "工厂数据", tags = "工厂数据接口") public class ZbFactoryDataController { - private final IOrderStatusLogService orderStatusLogService; private final IZbFactoryDataService zbFactoryDataService; private final IAsyncDataService syncDataService; + private final IZbFactoryLogService zbFactoryLogService; + + + private final IOssClient ossClient; + /** * 工厂数据推送接口 */ @@ -51,26 +73,46 @@ public class ZbFactoryDataController { zbReceiptDTO.setCorpId(corpId); // 先保存原始请求数据 - OrderStatusLog orderStatusLog = new OrderStatusLog(); - orderStatusLog.setArgs(JSONObject.toJSONString(zbReceiptDTO)); - orderStatusLog.setStatus(1); - orderStatusLog.setType(3); - orderStatusLog.setBrand("志邦"); +// OrderStatusLog orderStatusLog = new OrderStatusLog(); +// orderStatusLog.setArgs(JSONObject.toJSONString(zbReceiptDTO)); +// orderStatusLog.setStatus(1); +// orderStatusLog.setType(3); +// orderStatusLog.setBrand("志邦"); + + +// 增加对请求日志的数据存储 + + ZbFactoryLogEntity zbFactoryLogEntity = new ZbFactoryLogEntity(); + zbFactoryLogEntity.setType(1); + zbFactoryLogEntity.setSaxStatus(0); + + String url = uploadFile(JSONObject.toJSONString(zbReceiptDTO)); + + zbFactoryLogEntity.setLogUrl(url); + // 上传文件 + zbFactoryLogService.save(zbFactoryLogEntity); + + + + - orderStatusLogService.save(orderStatusLog); +// orderStatusLogService.save(orderStatusLog); // //判断数据是否已存入 Long orderId = null; try{ orderId = zbFactoryDataService.saveData(zbReceiptDTO); - orderStatusLog.setStatus(0); +// orderStatusLog.setStatus(0); + zbFactoryLogEntity.setSaxStatus(1); }catch (Exception e){ log.error("############data: 保存数据失败",e); //修改保存数据的状态 - orderStatusLog.setStatus(2); +// orderStatusLog.setStatus(2); + zbFactoryLogEntity.setSaxStatus(2); } - orderStatusLogService.saveOrUpdate(orderStatusLog); +// orderStatusLogService.saveOrUpdate(orderStatusLog); + zbFactoryLogService.saveOrUpdate(zbFactoryLogEntity); //开启异步线程处理数据 if(!Objects.isNull(orderId)){ @@ -79,4 +121,42 @@ public class ZbFactoryDataController { 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); + if (r.isSuccess()) { + BladeFile data = (BladeFile) r.getData(); + return data.getLink(); + } + return null; + } + + /** + * 通过文件构建 MultipartFile + */ + @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 = new FileInputStream(file); + 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/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.java new file mode 100644 index 000000000..dddb8014c --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.java @@ -0,0 +1,9 @@ +package com.logpm.factory.zb.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.logpm.factory.zb.entity.ZbFactoryLogEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ZbFactoryLogMapper extends BaseMapper { +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.xml b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.xml new file mode 100644 index 000000000..8a4aea072 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryLogService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryLogService.java new file mode 100644 index 000000000..d52349ae1 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryLogService.java @@ -0,0 +1,7 @@ +package com.logpm.factory.zb.service; + +import com.logpm.factory.zb.entity.ZbFactoryLogEntity; +import org.springblade.core.mp.base.BaseService; + +public interface IZbFactoryLogService extends BaseService { +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryLogServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryLogServiceImpl.java new file mode 100644 index 000000000..307d27b30 --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryLogServiceImpl.java @@ -0,0 +1,12 @@ +package com.logpm.factory.zb.service.impl; + +import com.logpm.factory.zb.entity.ZbFactoryLogEntity; +import com.logpm.factory.zb.mapper.ZbFactoryLogMapper; +import com.logpm.factory.zb.service.IZbFactoryLogService; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; +@Slf4j +@Service +public class ZbFactoryLogServiceImpl extends BaseServiceImpl implements IZbFactoryLogService { +} diff --git a/blade-service/logpm-factory/src/test/java/com/logpm/factory/TestService.java b/blade-service/logpm-factory/src/test/java/com/logpm/factory/TestService.java index 4da25f185..7c5f94eef 100644 --- a/blade-service/logpm-factory/src/test/java/com/logpm/factory/TestService.java +++ b/blade-service/logpm-factory/src/test/java/com/logpm/factory/TestService.java @@ -33,7 +33,9 @@ import com.logpm.factory.oupai.service.impl.OuPaiFactoryServiceImpl; import com.logpm.factory.pan.service.IPanFactoryDataService; import com.logpm.factory.snm.vo.MTOrderPackageRelationVO; import com.logpm.factory.zb.dto.ZBReceiptDTO; +import com.logpm.factory.zb.entity.ZbFactoryLogEntity; import com.logpm.factory.zb.service.IZbFactoryDataService; +import com.logpm.factory.zb.service.IZbFactoryLogService; import com.logpm.oldproject.entity.AdvanceDetailEntity; import com.logpm.oldproject.feign.IAdvanceDetailClient; import com.rabbitmq.client.Channel; @@ -94,6 +96,9 @@ public class TestService { @Autowired private OuPaiFactoryServiceImpl ouPaiFactoryService; + @Autowired + private IZbFactoryLogService zbFactoryLogService; + @Test public void test2() { // ouPaiFactoryService.findOuPaiFactoryOrderDTOByCarCarNumber("LCD230505047"); @@ -346,5 +351,15 @@ public class TestService { zbFactoryDataService.saveData(javaObject); } + + @Test + public void test9() { + + ZbFactoryLogEntity zbFactoryLogEntity = new ZbFactoryLogEntity(); + zbFactoryLogEntity.setLogUrl("111111"); + + zbFactoryLogService.save(zbFactoryLogEntity); + } + }