Commit 8bd9bef9 authored by 李灿灿's avatar 李灿灿

订单对接ekp

parent d1b469e5
......@@ -37,5 +37,10 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>
package com.yifu.cloud.plus.v1.yifu.ekp.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
/**
* @author licancan
* @description 对接ekp订单
* @date 2022-08-31 15:35:20
*/
@Data
@Component
@PropertySource("classpath:ekpOrderConfig.properties")
@ConfigurationProperties(value = "ekporder",ignoreInvalidFields = false)
public class EkpOrderProperties {
/**
* 接口url
*/
String url;
/**
* 订单modelId
*/
String orderFdModelId;
/**
* 订单flowID
*/
String orderFdFlowId;
/**
* 订单回复modelId
*/
String replyFdModelId;
/**
* 订单回复flowID
*/
String replyFdFlowId;
/**
* 订单附件key
*/
String replyAttachKey;
String docStatus;
String LoginName;
String docSubject;
}
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;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.io.FileUtils;
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.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;
/**
* @author licancan
* @description 对接ekp订单
* @date 2022-08-31 15:35:20
*/
@Log4j2
@EnableConfigurationProperties(EkpOrderProperties.class)
public class EkpOrderUtil {
@Autowired
private static EkpOrderProperties ekpProperties;
/**
* 更新订单状态
*
* @author licancan
* @param param
* @return {@link String}
*/
public String sendOrderToEKP(EkpOrderParam param){
log.info("推送EKP开始--订单状态");
RestTemplate yourRestTemplate = new RestTemplate();
try{
String formValues = new ObjectMapper().writeValueAsString(param);
//指向EKP的接口url
//把ModelingAppModelParameterAddForm转换成MultiValueMap
MultiValueMap<String,Object> wholeForm = new LinkedMultiValueMap<>();
wholeForm.add("docSubject",ekpProperties.getDocSubject());
wholeForm.add("docCreator", "{\"LoginName\":\"admin\"}");
wholeForm.add("docStatus", ekpProperties.getDocStatus());
wholeForm.add("fdModelId", ekpProperties.getOrderFdModelId());
wholeForm.add("fdFlowId", ekpProperties.getOrderFdFlowId());
wholeForm.add("formValues", formValues);
System.out.println("wholeForm:" + wholeForm);
HttpHeaders headers = new HttpHeaders();
//如果EKP对该接口启用了Basic认证,那么客户端需要加入
//addAuth(headers,"yourAccount"+":"+"yourPassword");是VO,则使用APPLICATION_JSON
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
//必须设置上传类型,如果入参是字符串,使用MediaType.TEXT_PLAIN;如果
HttpEntity<MultiValueMap<String,Object>> entity = new HttpEntity<MultiValueMap<String,Object>>(wholeForm,headers);
//有返回值的情况 VO可以替换成具体的JavaBean
ResponseEntity<String> obj = yourRestTemplate.exchange(ekpProperties.getUrl(), HttpMethod.POST, entity, String.class);
String body = obj.getBody();
if (StringUtils.isBlank(body)){
log.error(EkpConstants.SEND_FAILED);
return null;
}else{
log.info(EkpConstants.SEND_SUCCESS+body);
return body;
}
}catch (Exception e){
log.info(e);
return null;
}
}
/**
* 推送订单回复
*
* @author licancan
* @param param
* @return {@link String}
*/
public String sendReplyToEKP(EkpOrderReplyParam param, MultipartFile[] multipartFiles){
log.info("推送EKP开始--订单回复信息");
RestTemplate yourRestTemplate = new RestTemplate();
try{
String formValues = new ObjectMapper().writeValueAsString(param);
//指向EKP的接口url
//把ModelingAppModelParameterAddForm转换成MultiValueMap
MultiValueMap<String,Object> wholeForm = new LinkedMultiValueMap<>();
wholeForm.add("docSubject",ekpProperties.getDocSubject());
wholeForm.add("docCreator", "{\"LoginName\":\"admin\"}");
wholeForm.add("docStatus", ekpProperties.getDocStatus());
wholeForm.add("fdModelId", ekpProperties.getReplyFdModelId());
wholeForm.add("fdFlowId", ekpProperties.getReplyFdFlowId());
wholeForm.add("formValues", formValues);
//注意附件列表的key是一样的
wholeForm.add("attachmentForms",createAllAttach(multipartFiles));
System.out.println("wholeForm:" + wholeForm);
HttpHeaders headers = new HttpHeaders();
//如果EKP对该接口启用了Basic认证,那么客户端需要加入
//addAuth(headers,"yourAccount"+":"+"yourPassword");是VO,则使用APPLICATION_JSON
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
//必须设置上传类型,如果入参是字符串,使用MediaType.TEXT_PLAIN;如果
HttpEntity<MultiValueMap<String,Object>> entity = new HttpEntity<MultiValueMap<String,Object>>(wholeForm,headers);
//有返回值的情况 VO可以替换成具体的JavaBean
ResponseEntity<String> obj = yourRestTemplate.exchange(ekpProperties.getUrl(), HttpMethod.POST, entity, String.class);
String body = obj.getBody();
if (StringUtils.isBlank(body)){
log.error(EkpConstants.SEND_FAILED);
return null;
}else{
log.info(EkpConstants.SEND_SUCCESS + body);
return body;
}
}catch (Exception e){
log.info(e);
return null;
}
}
/**
* 处理成ekp要的附件格式
*
* @author licancan
* @param multipartFiles
* @return {@link List<AttachmentForm>}
*/
public static List<AttachmentForm> createAllAttach(MultipartFile[] multipartFiles) throws Exception {
List<AttachmentForm> attForms = new ArrayList<>();
if (ArrayUtils.isNotEmpty(multipartFiles)){
for (MultipartFile multipartFile : multipartFiles) {
AttachmentForm attForm = new AttachmentForm();
//设置附件关键字,表单模式下为附件控件的id
attForm.setFdKey(ekpProperties.getReplyAttachKey());
attForm.setFdFileName(multipartFile.getOriginalFilename());
File file = null;
FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), file);
DataSource dataSource = new FileDataSource(file);
DataHandler dataHandler = new DataHandler(dataSource);
attForm.setFdAttachment(dataHandler);
attForms.add(attForm);
}
}
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;
}
package com.yifu.cloud.plus.v1.yifu.ekp.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @author licancan
* @description 对接ekp订单请求参数
* @date 2022-08-31 15:35:20
*/
@Data
public class EkpOrderParam implements Serializable {
private static final long serialVersionUID = 8276721461475968927L;
/**
* 订单编号
**/
private String fd_3b0b02a93e9cda;
/**
* 订单状态 待处理,处理中,已办结
**/
private String fd_3b0b02a34a0134;
}
package com.yifu.cloud.plus.v1.yifu.ekp.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @author licancan
* @description 对接ekp订单回复请求参数
* @date 2022-08-31 15:35:20
*/
@Data
public class EkpOrderReplyParam implements Serializable {
private static final long serialVersionUID = 8671347855651484998L;
/**
* 订单编号
**/
private String fd_3ac904bbaf972a;
/**
* 回复人 (人员账号)
**/
private String fd_3ac904badcaa06;
/**
* 回复时间
**/
private String fd_3ac904b8590598;
/**
* 回复内容
*/
private String fd_3ac904c7798e5c;
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.yifu.cloud.plus.v1.yifu.ekp.util.EkpOrderUtil,\
com.yifu.cloud.plus.v1.yifu.ekp.util.EkpInsuranceUtil,\
com.yifu.cloud.plus.v1.yifu.ekp.util.EkpSalaryUtil,\
com.yifu.cloud.plus.v1.yifu.ekp.util.EkpSocialUtil,\
......
ekporder.url=http://119.96.227.251:8080/api/sys-modeling/appModelRestService/addModel
ekporder.orderFdModelId=182f1b7ffe2e96f975564e44e559847d
ekporder.orderFdFlowId=182f1c098ce991ca96bc927408792beb
ekporder.replyFdModelId=182f1bb35bb2156fb9a02904bc88dd8a
ekporder.replyFdFlowId=182f1c3d6f5724e335b88d544be8c993
ekporder.replyAttachKey=fd_3ac904c9342fe2
ekporder.docStatus=20
ekporder.LoginName=admin
ekporder.docSubject=\u85AA\u8D44\u8BA2\u5355\u660E\u7EC6\u6570\u636E\u63A5\u53E3
......@@ -65,6 +65,12 @@
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-ekp</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
......
......@@ -10,6 +10,9 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import com.yifu.cloud.plus.v1.yifu.ekp.util.EkpOrderUtil;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpOrderParam;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpOrderReplyParam;
import com.yifu.cloud.plus.v1.yifu.order.constants.OrderConstants;
import com.yifu.cloud.plus.v1.yifu.order.entity.TOrder;
import com.yifu.cloud.plus.v1.yifu.order.entity.TOrderEnclosure;
......@@ -56,6 +59,8 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
private TOrderHandlerService tOrderHandlerService;
@Resource
private OSSUtil ossUtil;
@Resource
private EkpOrderUtil ekpOrderUtil;
/**
* 订单列表分页查询
......@@ -120,10 +125,39 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
byId.setUpdateName(user.getNickname());
byId.setUpdateTime(LocalDateTime.now());
this.updateById(byId);
// todo 如果是办结完成同步给ekp
// 状态同步给ekp
EkpOrderParam param = new EkpOrderParam();
param.setFd_3b0b02a93e9cda(byId.getOrderNo());
param.setFd_3b0b02a34a0134(getOrderStatus(status));
ekpOrderUtil.sendOrderToEKP(param);
return R.ok(OrderConstants.OPERATE_SUCCESS);
}
/**
* 获取订单状态
*
* @author licancan
* @param orderStatus
* @return {@link String}
*/
private String getOrderStatus(Integer orderStatus){
String result;
switch (orderStatus){
case 0:
result = "待处理";
break;
case 1:
result = "处理中";
break;
case 2:
result = "已办结";
break;
default:
result = "";
}
return result;
}
/**
* 通过id查询详情
*
......@@ -231,7 +265,13 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
reply.setCreateTime(LocalDateTime.now());
reply.setDeleteFlag(CommonConstants.ZERO_INT);
boolean save = tOrderReplyService.save(reply);
//todo 同步推送ekp
//同步推送ekp
EkpOrderReplyParam param = new EkpOrderReplyParam();
param.setFd_3ac904bbaf972a(orderNo);
param.setFd_3ac904badcaa06(user.getUsername());
param.setFd_3ac904b8590598(reply.getCreateTime().toString());
param.setFd_3ac904c7798e5c(replyContent);
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