Commit 62432d18 authored by 李灿灿's avatar 李灿灿

Merge branch 'feature-licancan' into 'develop'

Feature licancan

See merge request fangxinjiang/yifu!223
parents fb12f8b0 7acc2051
......@@ -67,7 +67,7 @@ public class ValidityConstants {
/** 最多60位 规则 */
public static final String PATTERN_60 = "^.{1,60}$";
/** 最多200位 规则 */
public static final String PATTERN_200 = "^.{1,200}$";
public static final String PATTERN_200 = "[\\s\\S]{1,200}$";
/** 不超过两位小数的正数 */
public static final String POSITIVE_INTEGER_PATTERN_TWO_FLOAT = "^[+]?([0-9]+(.[0-9]{1,2})?)$";
......
......@@ -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 orderDocSubject;
/**
* 描述:用于订单回复接口
*/
String replyDocSubject;
}
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 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.getOrderDocSubject());
wholeForm.add("docCreator", "{\"LoginName\":\"admin\"}");
wholeForm.add("docStatus", ekpProperties.getDocStatus());
wholeForm.add("fdModelId", ekpProperties.getOrderFdModelId());
wholeForm.add("fdFlowId", ekpProperties.getOrderFdFlowId());
wholeForm.add("formValues", formValues);
log.info("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.error(e);
return null;
}
}
/**
* 推送订单回复
*
* @author licancan
* @param param
* @return {@link String}
*/
public String sendReplyToEKP(EkpOrderReplyParam param, MultipartFile[] multipartFiles){
log.info("推送EKP开始--订单回复信息");
RestTemplate yourRestTemplate = new RestTemplate();
List<AttachmentForm> fileList = createAllAttach(multipartFiles);
try{
String formValues = new ObjectMapper().writeValueAsString(param);
//指向EKP的接口url
//把ModelingAppModelParameterAddForm转换成MultiValueMap
MultiValueMap<String,Object> wholeForm = new LinkedMultiValueMap<>();
wholeForm.add("docSubject",ekpProperties.getReplyDocSubject());
wholeForm.add("docCreator", "{\"LoginName\":\"admin\"}");
wholeForm.add("docStatus", ekpProperties.getDocStatus());
wholeForm.add("fdModelId", ekpProperties.getReplyFdModelId());
wholeForm.add("fdFlowId", ekpProperties.getReplyFdFlowId());
wholeForm.add("formValues", formValues);
wholeForm.add("attachmentForms", fileList);
log.info("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.error(e);
return null;
}finally {
//将产生的临时附件删除,这里的fileList没值得话是[],不会是null,如果是null需要做判空处理
fileList.stream().forEach(e -> {
FileDataSource dataSource = (FileDataSource)e.getFdAttachment().getDataSource();
boolean delete = dataSource.getFile().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;
}
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.orderDocSubject=\u7528\u4e8e\u9879\u76ee\u8ba2\u5355\u66f4\u65b0\u63a5\u53e3
ekporder.replyDocSubject=\u7528\u4e8e\u8ba2\u5355\u56de\u590d\u63a5\u53e3
......@@ -42,6 +42,10 @@ public class OrderConstants {
* 订单不存在
*/
public static final String ORDER_NO_NOT_EXIST = "订单不存在";
/**
* 订单已办结,无法添加回复
*/
public static final String ORDER_STATUS_IS_TWO = "订单已办结,无法添加回复";
/**
* 订单已存在
*/
......
......@@ -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查询详情
*
......@@ -200,6 +234,10 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
);
if (!Optional.ofNullable(one).isPresent()){
return R.failed(OrderConstants.ORDER_NO_NOT_EXIST);
}else {
if (CommonConstants.TWO_INT == one.getOrderStatus()){
return R.failed(OrderConstants.ORDER_STATUS_IS_TWO);
}
}
if (Common.isEmpty(replyContent) && ArrayUtils.isEmpty(file)){
return R.failed(OrderConstants.REPLY_CONTENT_AND_ENCLOSURE_IS_EMPTY);
......@@ -231,7 +269,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();
......@@ -408,6 +452,10 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
);
if (!Optional.ofNullable(one).isPresent()){
return R.failed(OrderConstants.ORDER_NO_NOT_EXIST);
}else {
if (CommonConstants.TWO_INT == one.getOrderStatus()){
return R.failed(OrderConstants.ORDER_STATUS_IS_TWO);
}
}
if (Common.isEmpty(vo.getCreateName())){
return R.failed(OrderConstants.REPLY_NAME_IS_EMPTY);
......
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