Commit f6249cc5 authored by huangcb's avatar huangcb

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

parent e4a77357
...@@ -315,6 +315,8 @@ public class ErrorMessageComponent { ...@@ -315,6 +315,8 @@ public class ErrorMessageComponent {
@Value("${error-message.contract.online.driver.sign.1001}") @Value("${error-message.contract.online.driver.sign.1001}")
private String contractOnlineDriverSign1001; private String contractOnlineDriverSign1001;
@Value("${error-message.contract.online.driver.sign.1002}")
private String contractOnlineDriverSign1002;
@Value("${error-message.contract.online.platform.sign.1001}") @Value("${error-message.contract.online.platform.sign.1001}")
private String contractOnlinePlatformSign1001; private String contractOnlinePlatformSign1001;
......
package com.esv.freight.customer.common.util;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* @description: 文件工具类
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.util.FileUtils
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/06/11 19:20
* @version:1.0
*/
public class FileUtils {
/**
* description 校验是否有效图片
* param [input]
* return boolean
* author HuangChaobin
* createTime 2020/06/10 11:29
**/
public static boolean isValidImage(InputStream input) {
boolean isValid = false;
BufferedImage bufferedImage;
try {
bufferedImage = ImageIO.read(input);
} catch (IOException e) {
return isValid;
}
if (null == bufferedImage) {
isValid = false;
} else {
isValid = true;
}
return isValid;
}
/**
* description 校验是否有效图片
* param [bytes]
* return boolean
* author HuangChaobin
* createTime 2020/06/10 11:30
**/
public static boolean isValidImage(byte[] bytes) {
return isValidImage(new ByteArrayInputStream(bytes));
}
/**
* description 校验是否有效图片
* param [file]
* return boolean
* author HuangChaobin
* createTime 2020/06/10 11:39
**/
public static boolean isValidImage(File file) {
InputStream inputStream;
try {
inputStream = org.apache.commons.io.FileUtils.openInputStream(file);
} catch (IOException e) {
return false;
}
return isValidImage(inputStream);
}
}
...@@ -25,6 +25,11 @@ public class ContractOnlineRecordSignDriverForm { ...@@ -25,6 +25,11 @@ public class ContractOnlineRecordSignDriverForm {
*/ */
@NotNull(message = "参数driverId不能为空") @NotNull(message = "参数driverId不能为空")
private Long driverId; private Long driverId;
/**
* 司机签名数据Id
*/
@NotBlank(message = "参数signId不能为空")
private String signId;
/** /**
* 业务编号(订单号或运单号) * 业务编号(订单号或运单号)
*/ */
...@@ -91,11 +96,6 @@ public class ContractOnlineRecordSignDriverForm { ...@@ -91,11 +96,6 @@ public class ContractOnlineRecordSignDriverForm {
@Length(max = 50, message = "参数freightCharge长度不合法") @Length(max = 50, message = "参数freightCharge长度不合法")
@NotBlank(message = "参数freightCharge不能为空") @NotBlank(message = "参数freightCharge不能为空")
private String freightCharge; private String freightCharge;
/**
* 货主签名数据,base64编码
*/
@NotBlank(message = "参数signData不能为空")
private String signData;
@Override @Override
public String toString() { public String toString() {
......
...@@ -11,10 +11,7 @@ import com.esv.freight.customer.common.component.ErrorMessageComponent; ...@@ -11,10 +11,7 @@ import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.component.RedisComponent; import com.esv.freight.customer.common.component.RedisComponent;
import com.esv.freight.customer.common.exception.EException; import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.ECode; import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.common.util.DateUtils; import com.esv.freight.customer.common.util.*;
import com.esv.freight.customer.common.util.FeignUtils;
import com.esv.freight.customer.common.util.InputStreamUtils;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.freight.customer.common.vo.PageResultVO; import com.esv.freight.customer.common.vo.PageResultVO;
import com.esv.freight.customer.feign.FeignBaseService; import com.esv.freight.customer.feign.FeignBaseService;
import com.esv.freight.customer.feign.FeignFileService; import com.esv.freight.customer.feign.FeignFileService;
...@@ -86,27 +83,25 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -86,27 +83,25 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
private FeignFileService feignFileService; private FeignFileService feignFileService;
private FeignBaseService feignBaseService; private FeignBaseService feignBaseService;
private RedisComponent redisComponent; private RedisComponent redisComponent;
@Autowired
private ContractOnlineTemplateService contractOnlineTemplateService; private ContractOnlineTemplateService contractOnlineTemplateService;
@Autowired
private GoodsOwnerAccountService goodsOwnerAccountService; private GoodsOwnerAccountService goodsOwnerAccountService;
@Autowired
private DriverAccountService driverAccountService; private DriverAccountService driverAccountService;
@Autowired
private ContractOnlinePlatformDataService contractOnlinePlatformDataService; private ContractOnlinePlatformDataService contractOnlinePlatformDataService;
@Autowired @Autowired
private PdfService pdfService; private PdfService pdfService;
@Autowired @Autowired
public ContractOnlineRecordServiceImpl(ErrorMessageComponent errorMessageComponent, FeignFileService feignFileService, public ContractOnlineRecordServiceImpl(ErrorMessageComponent errorMessageComponent, FeignFileService feignFileService,
FeignBaseService feignBaseService, RedisComponent redisComponent, FeignBaseService feignBaseService, RedisComponent redisComponent) {
ContractOnlineTemplateService contractOnlineTemplateService, GoodsOwnerAccountService goodsOwnerAccountService,
DriverAccountService driverAccountService, ContractOnlinePlatformDataService contractOnlinePlatformDataService) {
this.errorMessageComponent = errorMessageComponent; this.errorMessageComponent = errorMessageComponent;
this.feignFileService = feignFileService; this.feignFileService = feignFileService;
this.feignBaseService = feignBaseService; this.feignBaseService = feignBaseService;
this.redisComponent = redisComponent; this.redisComponent = redisComponent;
this.contractOnlineTemplateService = contractOnlineTemplateService;
this.goodsOwnerAccountService = goodsOwnerAccountService;
this.driverAccountService = driverAccountService;
this.contractOnlinePlatformDataService = contractOnlinePlatformDataService;
} }
@Override @Override
...@@ -187,11 +182,16 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -187,11 +182,16 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
@Override @Override
public ContractOnlineRecordSignDriverVO driverSign(ContractOnlineRecordSignDriverForm form) { public ContractOnlineRecordSignDriverVO driverSign(ContractOnlineRecordSignDriverForm form) {
// 1:获取司机信息 // 1:获取司机信息及签名数据
DriverDetailDto accountInfo = driverAccountService.getDriverDetailById(form.getDriverId()); DriverDetailDto accountInfo = driverAccountService.getDriverDetailById(form.getDriverId());
if (null == accountInfo) { if (null == accountInfo) {
throw new EException(1001, errorMessageComponent.getContractOnlineDriverSign1001()); throw new EException(1001, errorMessageComponent.getContractOnlineDriverSign1001());
} }
String driverSignData = this.getDriverSignData(form.getSignId());
byte[] driverSignBytes = Base64.getDecoder().decode(driverSignData);
if (!FileUtils.isValidImage(driverSignBytes)) {
throw new EException(1002, errorMessageComponent.getContractOnlineDriverSign1002());
}
// 2:获取电子合同模板数据 // 2:获取电子合同模板数据
String contractTemplateData = this.getContractOnlineTemplateEntity(ContractConstants.CONTRACT_TYPE_DRIVER); String contractTemplateData = this.getContractOnlineTemplateEntity(ContractConstants.CONTRACT_TYPE_DRIVER);
...@@ -204,7 +204,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -204,7 +204,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.getDriverSignDataMap(form, accountInfo); pojo = this.getDriverSignDataMap(driverSignBytes, form, accountInfo);
template.render(pojo); template.render(pojo);
template.write(byteArrayOutputStream); template.write(byteArrayOutputStream);
byteArrayOutputStream.flush(); byteArrayOutputStream.flush();
...@@ -339,12 +339,12 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -339,12 +339,12 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
/** /**
* description 获取司机签订合同时的数据 * description 获取司机签订合同时的数据
* param [form, accountInfo] * param [driverSignBytes, 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(ContractOnlineRecordSignDriverForm form, DriverDetailDto accountInfo) { private ContractOnlineDriverPojo getDriverSignDataMap(byte[] driverSignBytes, ContractOnlineRecordSignDriverForm form, DriverDetailDto accountInfo) {
ContractOnlineDriverPojo pojo = new ContractOnlineDriverPojo(); ContractOnlineDriverPojo pojo = new ContractOnlineDriverPojo();
BeanUtils.copyProperties(form, pojo); BeanUtils.copyProperties(form, pojo);
...@@ -368,7 +368,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -368,7 +368,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", Base64.getDecoder().decode(form.getSignData()))); pojo.setDriverSignImg(new PictureRenderData(CUSTOMER_SIGN_WIDTH, CUSTOMER_SIGN_HEIGHT, ".png", driverSignBytes));
pojo.setPlatformFreightSealImg("{{@platformFreightSealImg}}"); pojo.setPlatformFreightSealImg("{{@platformFreightSealImg}}");
return pojo; return pojo;
...@@ -517,6 +517,23 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR ...@@ -517,6 +517,23 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
return pojo; return pojo;
} }
/**
* 获取司机签名数据
**/
private String getDriverSignData(String fileId) {
JSONObject feignReqJson = new JSONObject();
feignReqJson.put("id", fileId);
JSONObject feignResJson;
try {
feignResJson = FeignUtils.getFeignResultData(feignFileService.getFileData(feignReqJson));
} catch (Exception e) {
log.error("调用[文件服务]获取司机签名数据失败:{}", e.getMessage(), e);
throw new EException("生成电子合同失败[获取司机签名数据失败]");
}
return feignResJson.getString("fileData");
}
@Override @Override
public PageResultVO getContractList(ContractOnlineRecordQueryForm queryForm) { public PageResultVO getContractList(ContractOnlineRecordQueryForm queryForm) {
IPage<ContractOnlineRecordEntity> page = new Page<>(queryForm.getPageNum(), queryForm.getPageSize()); IPage<ContractOnlineRecordEntity> page = new Page<>(queryForm.getPageNum(), queryForm.getPageSize());
......
...@@ -273,6 +273,7 @@ error-message: ...@@ -273,6 +273,7 @@ error-message:
driver: driver:
sign: sign:
1001: 无效的司机ID 1001: 无效的司机ID
1002: 无效的司机签名
platform: platform:
sign: sign:
1001: 无效的合同编号 1001: 无效的合同编号
......
...@@ -273,6 +273,7 @@ error-message: ...@@ -273,6 +273,7 @@ error-message:
driver: driver:
sign: sign:
1001: 无效的司机ID 1001: 无效的司机ID
1002: 无效的司机签名
platform: platform:
sign: sign:
1001: 无效的合同编号 1001: 无效的合同编号
......
...@@ -258,10 +258,8 @@ public class ContractOnlineRecordControllerTest extends BaseTestController { ...@@ -258,10 +258,8 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
form.setReceiveAddress("辽宁沈阳市沈河区泉园二路85号"); form.setReceiveAddress("辽宁沈阳市沈河区泉园二路85号");
form.setReceiveTime("2020-05-28 18:00:00"); form.setReceiveTime("2020-05-28 18:00:00");
form.setFreightCharge("500"); form.setFreightCharge("500");
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)
...@@ -284,7 +282,7 @@ public class ContractOnlineRecordControllerTest extends BaseTestController { ...@@ -284,7 +282,7 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
**/ **/
@Test @Test
@Rollback @Rollback
public void d2_driverSign_failure_test() throws Exception { public void d2_driverSign_wrong_driverId_failure_test() throws Exception {
String url = "/contract/online/driver/sign"; String url = "/contract/online/driver/sign";
// 构造数据 // 构造数据
...@@ -301,10 +299,8 @@ public class ContractOnlineRecordControllerTest extends BaseTestController { ...@@ -301,10 +299,8 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
form.setReceiveAddress("辽宁沈阳市沈河区泉园二路85号"); form.setReceiveAddress("辽宁沈阳市沈河区泉园二路85号");
form.setReceiveTime("2020-05-28 18:00:00"); form.setReceiveTime("2020-05-28 18:00:00");
form.setFreightCharge("500"); form.setFreightCharge("500");
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)
...@@ -321,6 +317,46 @@ public class ContractOnlineRecordControllerTest extends BaseTestController { ...@@ -321,6 +317,46 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
Assert.assertEquals(1001, result.getIntValue("code")); Assert.assertEquals(1001, result.getIntValue("code"));
} }
/**
* 司机与平台的电子合同-司机签订:无效的司机签名
**/
@Test
@Rollback
public void d3_driverSign_wrong_signId_failure_test() throws Exception {
String url = "/contract/online/driver/sign";
// 构造数据
ContractOnlineRecordSignDriverForm form = new ContractOnlineRecordSignDriverForm();
form.setDriverId(1L);
form.setBusinessNumber("DD" + System.currentTimeMillis());
form.setGoodsName("煤炭");
form.setGoodsTotal("5");
form.setGoodsUnit("吨");
form.setGoodsUnitPrice("230");
form.setGoodsTotalPrice("1150");
form.setDeliverAddress("辽宁沈阳市沈河区惠工街10号卓越大厦2710");
form.setDeliverTime("2020-05-28 11:00:00");
form.setReceiveAddress("辽宁沈阳市沈河区泉园二路85号");
form.setReceiveTime("2020-05-28 18:00:00");
form.setFreightCharge("500");
String signId = "5ecb56a6febc3351ffd3dfb0";
form.setSignId(signId);;
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(form.toString()))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String responseStr = mvcResult.getResponse().getContentAsString();
log.info(responseStr);
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1002, result.getIntValue("code"));
}
/** /**
* 分页查询电子合同列表 * 分页查询电子合同列表
**/ **/
......
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