Browse Source

Merge branch 'dev' into pre-production

newStockUp
pref_mail@163.com 1 year ago
parent
commit
046f427e7d
  1. 42
      blade-service-api/logpm-factory-api/src/main/java/com/logpm/factory/zb/entity/ZbFactoryLogEntity.java
  2. 100
      blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/controller/ZbFactoryDataController.java
  3. 9
      blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.java
  4. 9
      blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.xml
  5. 7
      blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/IZbFactoryLogService.java
  6. 12
      blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/service/impl/ZbFactoryLogServiceImpl.java
  7. 15
      blade-service/logpm-factory/src/test/java/com/logpm/factory/TestService.java

42
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 ;
}

100
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);
}
}

9
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<ZbFactoryLogEntity> {
}

9
blade-service/logpm-factory/src/main/java/com/logpm/factory/zb/mapper/ZbFactoryLogMapper.xml

@ -0,0 +1,9 @@
<?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.factory.zb.mapper.ZbFactoryLogMapper">
</mapper>

7
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<ZbFactoryLogEntity> {
}

12
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<ZbFactoryLogMapper, ZbFactoryLogEntity> implements IZbFactoryLogService {
}

15
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);
}
}

Loading…
Cancel
Save