Commit eb656d8d authored by huangcb's avatar huangcb

调整接口:货主与平台的电子合同-司机签订

parent f6249cc5
...@@ -312,6 +312,8 @@ public class ErrorMessageComponent { ...@@ -312,6 +312,8 @@ public class ErrorMessageComponent {
@Value("${error-message.contract.online.goods-owner.sign.1001}") @Value("${error-message.contract.online.goods-owner.sign.1001}")
private String contractOnlineGoodsOwnerSign1001; private String contractOnlineGoodsOwnerSign1001;
@Value("${error-message.contract.online.goods-owner.sign.1002}")
private String contractOnlineGoodsOwnerSign1002;
@Value("${error-message.contract.online.driver.sign.1001}") @Value("${error-message.contract.online.driver.sign.1001}")
private String contractOnlineDriverSign1001; private String contractOnlineDriverSign1001;
......
...@@ -25,6 +25,11 @@ public class ContractOnlineRecordSignGoodsOwnerForm { ...@@ -25,6 +25,11 @@ public class ContractOnlineRecordSignGoodsOwnerForm {
*/ */
@NotNull(message = "参数goodsOwnerId不能为空") @NotNull(message = "参数goodsOwnerId不能为空")
private Long goodsOwnerId; private Long goodsOwnerId;
/**
* 货主签名数据Id
*/
@NotBlank(message = "参数signId不能为空")
private String signId;
/** /**
* 业务编号(订单号或运单号) * 业务编号(订单号或运单号)
*/ */
...@@ -97,11 +102,6 @@ public class ContractOnlineRecordSignGoodsOwnerForm { ...@@ -97,11 +102,6 @@ public class ContractOnlineRecordSignGoodsOwnerForm {
@Length(max = 50, message = "参数depositCharge长度不合法") @Length(max = 50, message = "参数depositCharge长度不合法")
@NotBlank(message = "参数depositCharge不能为空") @NotBlank(message = "参数depositCharge不能为空")
private String depositCharge; private String depositCharge;
/**
* 货主签名数据,base64编码
*/
@NotBlank(message = "参数signData不能为空")
private String signData;
@Override @Override
public String toString() { public String toString() {
......
...@@ -114,6 +114,11 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -114,6 +114,11 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
if (null == accountInfo) { if (null == accountInfo) {
throw new EException(1001, errorMessageComponent.getContractOnlineGoodsOwnerSign1001()); throw new EException(1001, errorMessageComponent.getContractOnlineGoodsOwnerSign1001());
} }
String goodsOwnerSignData = this.getSignData(form.getSignId());
byte[] goodsOwnerSignBytes = Base64.getDecoder().decode(goodsOwnerSignData);
if (!FileUtils.isValidImage(goodsOwnerSignBytes)) {
throw new EException(1002, errorMessageComponent.getContractOnlineGoodsOwnerSign1002());
}
// 2:获取电子合同模板数据 // 2:获取电子合同模板数据
String contractTemplateData = this.getContractOnlineTemplateEntity(ContractConstants.CONTRACT_TYPE_GOODS_OWNER); String contractTemplateData = this.getContractOnlineTemplateEntity(ContractConstants.CONTRACT_TYPE_GOODS_OWNER);
...@@ -126,7 +131,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -126,7 +131,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
XWPFTemplate template = null; XWPFTemplate template = null;
try { try {
template = XWPFTemplate.compile(InputStreamUtils.byte2InputStream(contractTemplateBytes)); template = XWPFTemplate.compile(InputStreamUtils.byte2InputStream(contractTemplateBytes));
pojo = this.getGoodsOwnerSignDataMap(form, accountInfo); pojo = this.getGoodsOwnerSignDataMap(goodsOwnerSignBytes, form, accountInfo);
template.render(pojo); template.render(pojo);
template.write(byteArrayOutputStream); template.write(byteArrayOutputStream);
byteArrayOutputStream.flush(); byteArrayOutputStream.flush();
...@@ -187,7 +192,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -187,7 +192,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
if (null == accountInfo) { if (null == accountInfo) {
throw new EException(1001, errorMessageComponent.getContractOnlineDriverSign1001()); throw new EException(1001, errorMessageComponent.getContractOnlineDriverSign1001());
} }
String driverSignData = this.getDriverSignData(form.getSignId()); String driverSignData = this.getSignData(form.getSignId());
byte[] driverSignBytes = Base64.getDecoder().decode(driverSignData); byte[] driverSignBytes = Base64.getDecoder().decode(driverSignData);
if (!FileUtils.isValidImage(driverSignBytes)) { if (!FileUtils.isValidImage(driverSignBytes)) {
throw new EException(1002, errorMessageComponent.getContractOnlineDriverSign1002()); throw new EException(1002, errorMessageComponent.getContractOnlineDriverSign1002());
...@@ -297,12 +302,12 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -297,12 +302,12 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
/** /**
* description 获取货主签订合同时的数据 * description 获取货主签订合同时的数据
* param [form, accountInfo] * param [signBytes, form, accountInfo]
* return java.util.Map<java.lang.String,java.lang.Object> * return java.util.Map<java.lang.String,java.lang.Object>
* author Administrator * author Administrator
* createTime 2020/05/21 19:32 * createTime 2020/05/21 19:32
**/ **/
private ContractOnlineGoodsOwnerPojo getGoodsOwnerSignDataMap(ContractOnlineRecordSignGoodsOwnerForm form, AccountInfoDto accountInfo) { private ContractOnlineGoodsOwnerPojo getGoodsOwnerSignDataMap(byte[] signBytes, ContractOnlineRecordSignGoodsOwnerForm form, AccountInfoDto accountInfo) {
ContractOnlineGoodsOwnerPojo pojo = new ContractOnlineGoodsOwnerPojo(); ContractOnlineGoodsOwnerPojo pojo = new ContractOnlineGoodsOwnerPojo();
BeanUtils.copyProperties(form, pojo); BeanUtils.copyProperties(form, pojo);
...@@ -331,7 +336,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -331,7 +336,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
pojo.setPlatformName("{{platformName}}"); pojo.setPlatformName("{{platformName}}");
pojo.setPlatformId("{{platformId}}"); pojo.setPlatformId("{{platformId}}");
pojo.setEffectiveTime("{{effectiveTime}}"); pojo.setEffectiveTime("{{effectiveTime}}");
pojo.setGoodsOwnerSignImg(new PictureRenderData(CUSTOMER_SIGN_WIDTH, CUSTOMER_SIGN_HEIGHT, ".png", Base64.getDecoder().decode(form.getSignData()))); pojo.setGoodsOwnerSignImg(new PictureRenderData(CUSTOMER_SIGN_WIDTH, CUSTOMER_SIGN_HEIGHT, ".png", signBytes));
pojo.setPlatformFreightSealImg("{{@platformFreightSealImg}}"); pojo.setPlatformFreightSealImg("{{@platformFreightSealImg}}");
return pojo; return pojo;
...@@ -339,12 +344,12 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -339,12 +344,12 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
/** /**
* description 获取司机签订合同时的数据 * description 获取司机签订合同时的数据
* param [driverSignBytes, form, accountInfo] * param [signBytes, form, accountInfo]
* return com.esv.freight.customer.module.contract.pojo.ContractOnlineDriverPojo * return com.esv.freight.customer.module.contract.pojo.ContractOnlineDriverPojo
* author Administrator * author Administrator
* createTime 2020/05/26 15:16 * createTime 2020/05/26 15:16
**/ **/
private ContractOnlineDriverPojo getDriverSignDataMap(byte[] driverSignBytes, ContractOnlineRecordSignDriverForm form, DriverDetailDto accountInfo) { private ContractOnlineDriverPojo getDriverSignDataMap(byte[] signBytes, ContractOnlineRecordSignDriverForm form, DriverDetailDto accountInfo) {
ContractOnlineDriverPojo pojo = new ContractOnlineDriverPojo(); ContractOnlineDriverPojo pojo = new ContractOnlineDriverPojo();
BeanUtils.copyProperties(form, pojo); BeanUtils.copyProperties(form, pojo);
...@@ -368,7 +373,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -368,7 +373,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
pojo.setPlatformName("{{platformName}}"); pojo.setPlatformName("{{platformName}}");
pojo.setPlatformId("{{platformId}}"); pojo.setPlatformId("{{platformId}}");
pojo.setEffectiveTime("{{effectiveTime}}"); pojo.setEffectiveTime("{{effectiveTime}}");
pojo.setDriverSignImg(new PictureRenderData(CUSTOMER_SIGN_WIDTH, CUSTOMER_SIGN_HEIGHT, ".png", driverSignBytes)); pojo.setDriverSignImg(new PictureRenderData(CUSTOMER_SIGN_WIDTH, CUSTOMER_SIGN_HEIGHT, ".png", signBytes));
pojo.setPlatformFreightSealImg("{{@platformFreightSealImg}}"); pojo.setPlatformFreightSealImg("{{@platformFreightSealImg}}");
return pojo; return pojo;
...@@ -518,17 +523,17 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -518,17 +523,17 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
} }
/** /**
* 获取司机签名数据 * 获取签名数据
**/ **/
private String getDriverSignData(String fileId) { private String getSignData(String fileId) {
JSONObject feignReqJson = new JSONObject(); JSONObject feignReqJson = new JSONObject();
feignReqJson.put("id", fileId); feignReqJson.put("id", fileId);
JSONObject feignResJson; JSONObject feignResJson;
try { try {
feignResJson = FeignUtils.getFeignResultData(feignFileService.getFileData(feignReqJson)); feignResJson = FeignUtils.getFeignResultData(feignFileService.getFileData(feignReqJson));
} catch (Exception e) { } catch (Exception e) {
log.error("调用[文件服务]获取司机签名数据失败:{}", e.getMessage(), e); log.error("调用[文件服务]获取签名数据失败:{}", e.getMessage(), e);
throw new EException("生成电子合同失败[获取司机签名数据失败]"); throw new EException("生成电子合同失败[获取签名数据失败]");
} }
return feignResJson.getString("fileData"); return feignResJson.getString("fileData");
......
...@@ -31,7 +31,7 @@ public class AppFrontRcvServlet extends HttpServlet { ...@@ -31,7 +31,7 @@ public class AppFrontRcvServlet extends HttpServlet {
* createTime 2020/06/02 19:28 * createTime 2020/06/02 19:28
**/ **/
@Override @Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { protected void service(HttpServletRequest req, HttpServletResponse resp) {
Map<String, String> reqParam = this.getAllRequestParam(req); Map<String, String> reqParam = this.getAllRequestParam(req);
log.info(reqParam.toString()); log.info(reqParam.toString());
......
...@@ -270,10 +270,11 @@ error-message: ...@@ -270,10 +270,11 @@ error-message:
goods-owner: goods-owner:
sign: sign:
1001: 无效的货主ID 1001: 无效的货主ID
1002: 无效的签名
driver: driver:
sign: sign:
1001: 无效的司机ID 1001: 无效的司机ID
1002: 无效的司机签名 1002: 无效的签名
platform: platform:
sign: sign:
1001: 无效的合同编号 1001: 无效的合同编号
......
...@@ -270,10 +270,11 @@ error-message: ...@@ -270,10 +270,11 @@ error-message:
goods-owner: goods-owner:
sign: sign:
1001: 无效的货主ID 1001: 无效的货主ID
1002: 无效的签名
driver: driver:
sign: sign:
1001: 无效的司机ID 1001: 无效的司机ID
1002: 无效的司机签名 1002: 无效的签名
platform: platform:
sign: sign:
1001: 无效的合同编号 1001: 无效的合同编号
......
...@@ -8,7 +8,6 @@ import com.esv.freight.customer.module.contract.form.ContractOnlineRecordQueryFo ...@@ -8,7 +8,6 @@ import com.esv.freight.customer.module.contract.form.ContractOnlineRecordQueryFo
import com.esv.freight.customer.module.contract.form.ContractOnlineRecordSignDriverForm; import com.esv.freight.customer.module.contract.form.ContractOnlineRecordSignDriverForm;
import com.esv.freight.customer.module.contract.form.ContractOnlineRecordSignGoodsOwnerForm; import com.esv.freight.customer.module.contract.form.ContractOnlineRecordSignGoodsOwnerForm;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
...@@ -24,11 +23,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers; ...@@ -24,11 +23,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Base64;
/** /**
* @description: * @description:
* @project: freight-customer-service * @project: freight-customer-service
...@@ -68,10 +62,8 @@ public class ContractOnlineRecordControllerTest extends BaseTestController { ...@@ -68,10 +62,8 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
form.setReceiveTime("2020-05-28 18:00:00"); form.setReceiveTime("2020-05-28 18:00:00");
form.setFreightCharge("500"); form.setFreightCharge("500");
form.setDepositCharge("0"); form.setDepositCharge("0");
String filepath = "D:\\test\\张志臣-签名.PNG"; String signId = "5ee2161a6069f62ff8ee9b13";
File signFile = new File(filepath); form.setSignId(signId);
InputStream input = new FileInputStream(signFile);
form.setSignData(Base64.getEncoder().encodeToString(IOUtils.toByteArray(input)));
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url) MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
...@@ -112,10 +104,8 @@ public class ContractOnlineRecordControllerTest extends BaseTestController { ...@@ -112,10 +104,8 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
form.setReceiveTime("2020-05-28 18:00:00"); form.setReceiveTime("2020-05-28 18:00:00");
form.setFreightCharge("500"); form.setFreightCharge("500");
form.setDepositCharge("0"); form.setDepositCharge("0");
String filepath = "D:\\test\\何锋.jpg"; String signId = "5ee2161a6069f62ff8ee9b13";
File signFile = new File(filepath); form.setSignId(signId);
InputStream input = new FileInputStream(signFile);
form.setSignData(Base64.getEncoder().encodeToString(IOUtils.toByteArray(input)));
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url) MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
......
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