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