Commit 54aac010 authored by 李灿灿's avatar 李灿灿

订单对接ekp接口调试

parent ad166ca7
......@@ -2,7 +2,6 @@ package com.yifu.cloud.plus.v1.yifu.ekp.util;
import com.yifu.cloud.plus.v1.yifu.ekp.config.EkpOrderProperties;
import com.yifu.cloud.plus.v1.yifu.ekp.constant.EkpConstants;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.AttachmentForm;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpOrderParam;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpOrderReplyParam;
import io.micrometer.core.instrument.util.StringUtils;
......@@ -12,15 +11,13 @@ import org.apache.commons.lang.ArrayUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
......@@ -90,7 +87,7 @@ public class EkpOrderUtil {
public String sendReplyToEKP(EkpOrderReplyParam param, MultipartFile[] multipartFiles){
log.info("推送EKP开始--订单回复信息");
RestTemplate yourRestTemplate = new RestTemplate();
List<AttachmentForm> fileList = createAllAttach(multipartFiles);
List<File> fileList = new ArrayList<>();
try{
String formValues = new ObjectMapper().writeValueAsString(param);
//指向EKP的接口url
......@@ -102,7 +99,17 @@ public class EkpOrderUtil {
wholeForm.add("fdModelId", ekpProperties.getReplyFdModelId());
wholeForm.add("fdFlowId", ekpProperties.getReplyFdFlowId());
wholeForm.add("formValues", formValues);
wholeForm.add("attachmentForms", fileList);
if (ArrayUtils.isNotEmpty(multipartFiles)){
for (int i = 0; i < multipartFiles.length; i++) {
String fileName = multipartFiles[i].getOriginalFilename();
File file = new File(fileName);
FileUtils.copyInputStreamToFile(multipartFiles[i].getInputStream(), file);
wholeForm.add("attachmentForms["+i+"].fdKey", ekpProperties.getReplyAttachKey());
wholeForm.add("attachmentForms["+i+"].fdFileName", multipartFiles[i].getOriginalFilename());
wholeForm.add("attachmentForms["+i+"].fdAttachment", new FileSystemResource(file));
fileList.add(file);
}
}
log.info("wholeForm:" + wholeForm);
HttpHeaders headers = new HttpHeaders();
......@@ -127,42 +134,11 @@ public class EkpOrderUtil {
}finally {
//将产生的临时附件删除,这里的fileList没值得话是[],不会是null,如果是null需要做判空处理
fileList.stream().forEach(e -> {
FileDataSource dataSource = (FileDataSource)e.getFdAttachment().getDataSource();
boolean delete = dataSource.getFile().delete();
log.info("临时附件删除结果:",delete);
boolean delete = e.delete();
log.info("临时附件删除结果:{}",delete);
});
}
}
/**
* 处理成ekp要的附件格式
*
* @author licancan
* @param multipartFiles
* @return {@link List<AttachmentForm>}
*/
public List<AttachmentForm> createAllAttach(MultipartFile[] multipartFiles){
List<AttachmentForm> attForms = new ArrayList<>();
if (ArrayUtils.isNotEmpty(multipartFiles)){
try {
for (MultipartFile multipartFile : multipartFiles) {
AttachmentForm attForm = new AttachmentForm();
//设置附件关键字,注意附件列表的key是一样的
attForm.setFdKey(ekpProperties.getReplyAttachKey());
attForm.setFdFileName(multipartFile.getOriginalFilename());
File file = new File(multipartFile.getOriginalFilename());
FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), file);
DataSource dataSource = new FileDataSource(file);
DataHandler dataHandler = new DataHandler(dataSource);
attForm.setFdAttachment(dataHandler);
attForms.add(attForm);
}
}catch (Exception e){
log.error("createAllAttach--->error:",e);
}
}
return attForms;
}
}
package com.yifu.cloud.plus.v1.yifu.ekp.vo;
import lombok.Data;
import javax.activation.DataHandler;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlMimeType;
/**
* @author licancan
* @description ekp附件类
* @date 2022-08-31 17:02:49
*/
@XmlAccessorType(XmlAccessType.FIELD)
@Data
public class AttachmentForm {
private String fdKey;
private String fdFileName;
@XmlMimeType("application/octet-stream")
private DataHandler fdAttachment;
}
......@@ -129,7 +129,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
EkpOrderParam param = new EkpOrderParam();
param.setFd_3b0b02a93e9cda(byId.getOrderNo());
param.setFd_3b0b02a34a0134(getOrderStatus(status));
//ekpOrderUtil.sendOrderToEKP(param);
ekpOrderUtil.sendOrderToEKP(param);
return R.ok(OrderConstants.OPERATE_SUCCESS);
}
......@@ -275,7 +275,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
param.setFd_3ac904badcaa06(user.getUsername());
param.setFd_3ac904b8590598(reply.getCreateTime().toString());
param.setFd_3ac904c7798e5c(replyContent);
//ekpOrderUtil.sendReplyToEKP(param,file);
ekpOrderUtil.sendReplyToEKP(param,file);
if (save && ArrayUtils.isNotEmpty(file)){
for (MultipartFile multipartFile : file) {
String fileName = System.currentTimeMillis() + "_" + multipartFile.getOriginalFilename();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment