Commit 9d58d337 authored by huangcb's avatar huangcb

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

parent 99665a71
......@@ -299,11 +299,15 @@ public class ErrorMessageComponent {
private String contractOfflineCarrierDelete1001;
@Value("${error-message.contract.online.goods-owner.sign.1001}")
private String contractOnlineGoodsOwnerAdd1001;
private String contractOnlineGoodsOwnerSign1001;
@Value("${error-message.contract.online.driver.sign.1001}")
private String contractOnlineDriverSign1001;
@Value("${error-message.contract.online.platform.sign.1001}")
private String contractOnlinePlatformSign1001;
@Value("${error-message.contract.online.get-by-number.1001}")
private String contractOnlineGetByNumber1001;
@Value("${error-message.contract.online.goods-owner.platform-sign.1001}")
private String contractOnlineGoodsOwnerPlatformSign1001;
}
......@@ -4,6 +4,7 @@ import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.EResponse;
import com.esv.freight.customer.common.validator.groups.ValidatorDetail;
import com.esv.freight.customer.module.contract.form.ContractOnlineRecordForm;
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.service.ContractOnlineRecordService;
import lombok.extern.slf4j.Slf4j;
......@@ -48,6 +49,18 @@ public class ContractOnlineRecordController {
return EResponse.ok(contractOnlineRecordService.goodsOwnerSign(form));
}
/**
* description 司机与平台的电子合同-司机签订
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/05/26 15:19
**/
@PostMapping("/driver/sign")
public EResponse driverSign(@RequestBody @Validated ContractOnlineRecordSignDriverForm form) throws EException {
return EResponse.ok(contractOnlineRecordService.driverSign(form));
}
/**
* description 电子合同-平台签订
* param [form]
......
package com.esv.freight.customer.module.contract.form;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.contract.form.ContractOnlineRecordSignDriverForm
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/21 17:44
* @version:1.0
*/
@Data
public class ContractOnlineRecordSignDriverForm {
/**
* 司机ID
*/
@NotNull(message = "参数driverId不能为空")
private Long driverId;
/**
* 业务编号(订单号或运单号)
*/
@Length(max = 50, message = "参数businessNumber长度不合法")
@NotBlank(message = "参数businessNumber不能为空")
private String businessNumber;
/**
* 货物名称
*/
@Length(max = 50, message = "参数goodsName长度不合法")
@NotBlank(message = "参数goodsName不能为空")
private String goodsName;
/**
* 货物总量
*/
@Length(max = 50, message = "参数goodsTotal长度不合法")
@NotBlank(message = "参数goodsTotal不能为空")
private String goodsTotal;
/**
* 货物单位
*/
@Length(max = 50, message = "参数goodsUnit长度不合法")
@NotBlank(message = "参数goodsUnit不能为空")
private String goodsUnit;
/**
* 货物单价
*/
@Length(max = 50, message = "参数goodsUnitPrice长度不合法")
@NotBlank(message = "参数goodsUnitPrice不能为空")
private String goodsUnitPrice;
/**
* 货物总价
*/
@Length(max = 50, message = "参数goodsTotalPrice长度不合法")
@NotBlank(message = "参数goodsTotalPrice不能为空")
private String goodsTotalPrice;
/**
* 发货地址
*/
@Length(max = 200, message = "参数deliverAddress长度不合法")
@NotBlank(message = "参数deliverAddress不能为空")
private String deliverAddress;
/**
* 收货地址
*/
@Length(max = 200, message = "参数receiveAddress长度不合法")
@NotBlank(message = "参数receiveAddress不能为空")
private String receiveAddress;
/**
* 发货时间
*/
@Length(max = 50, message = "参数deliverTime长度不合法")
@NotBlank(message = "参数deliverTime不能为空")
private String deliverTime;
/**
* 交货时间
*/
@Length(max = 50, message = "参数receiveTime长度不合法")
@NotBlank(message = "参数receiveTime不能为空")
private String receiveTime;
/**
* 运费
*/
@Length(max = 50, message = "参数freightCharge长度不合法")
@NotBlank(message = "参数freightCharge不能为空")
private String freightCharge;
/**
* 货主签名数据,base64编码
*/
@NotBlank(message = "参数signData不能为空")
private String signData;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
package com.esv.freight.customer.module.contract.pojo;
import lombok.Data;
/**
* @description: 货主与平台签订合同的模板内容项
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.contract.pojo.ContractOnlineDriverPojo
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/22 10:05
* @version:1.0
*/
@Data
public class ContractOnlineDriverPojo {
/**
* 合同编号
*/
private String contactNumber;
/**
* 承运方
*/
private String driverName;
/**
* 承运方身份证号码
*/
private String driverId;
/**
* 承运方
*/
private String platformName;
/**
* 承运方组织机构代码
*/
private String platformId;
/**
* 货物名称
*/
private String goodsName;
/**
* 货物总量
*/
private String goodsTotal;
/**
* 货物单位
*/
private String goodsUnit;
/**
* 货物单价
*/
private String goodsUnitPrice;
/**
* 货物总价
*/
private String goodsTotalPrice;
/**
* 发货地址
*/
private String deliverAddress;
/**
* 收货地址
*/
private String receiveAddress;
/**
* 发货时间
*/
private String deliverTime;
/**
* 交货时间
*/
private String receiveTime;
/**
* 本次运输运费
*/
private String freightCharge;
/**
* 承运方签字
*/
private Object driverSignImg;
/**
* 委托方签字
*/
private Object platformFreightSealImg;
/**
* 生效时间
*/
private String effectiveTime;
}
......@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.module.contract.entity.ContractOnlineRecordEntity;
import com.esv.freight.customer.module.contract.form.ContractOnlineRecordForm;
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.vo.ContractOnlineRecordSignDriverVO;
import com.esv.freight.customer.module.contract.vo.ContractOnlineRecordSignGoodsOwnerVO;
import com.esv.freight.customer.module.contract.vo.ContractOnlineRecordVO;
......@@ -26,6 +28,15 @@ public interface ContractOnlineRecordService extends IService<ContractOnlineReco
**/
ContractOnlineRecordSignGoodsOwnerVO goodsOwnerSign(ContractOnlineRecordSignGoodsOwnerForm form);
/**
* description 司机与平台的电子合同-司机签订
* param [form]
* return com.esv.freight.customer.module.contract.vo.ContractOnlineRecordSignDriverVO
* author Administrator
* createTime 2020/05/26 15:03
**/
ContractOnlineRecordSignDriverVO driverSign(ContractOnlineRecordSignDriverForm form);
/**
* description 根据合同编号获取合同信息
* param [contractNumber]
......
......@@ -23,14 +23,19 @@ import com.esv.freight.customer.module.contract.dao.ContractOnlineRecordDao;
import com.esv.freight.customer.module.contract.entity.ContractOnlinePlatformDataEntity;
import com.esv.freight.customer.module.contract.entity.ContractOnlineRecordEntity;
import com.esv.freight.customer.module.contract.entity.ContractOnlineTemplateEntity;
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.pojo.ContractOnlineDriverPojo;
import com.esv.freight.customer.module.contract.pojo.ContractOnlineGoodsOwnerPojo;
import com.esv.freight.customer.module.contract.pojo.ContractOnlinePlatformPojo;
import com.esv.freight.customer.module.contract.service.ContractOnlinePlatformDataService;
import com.esv.freight.customer.module.contract.service.ContractOnlineRecordService;
import com.esv.freight.customer.module.contract.service.ContractOnlineTemplateService;
import com.esv.freight.customer.module.contract.vo.ContractOnlineRecordSignDriverVO;
import com.esv.freight.customer.module.contract.vo.ContractOnlineRecordSignGoodsOwnerVO;
import com.esv.freight.customer.module.contract.vo.ContractOnlineRecordVO;
import com.esv.freight.customer.module.driver.dto.DriverDetailDto;
import com.esv.freight.customer.module.driver.service.DriverAccountService;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.dto.AccountInfoDto;
import com.esv.freight.customer.module.goodsowner.form.AccountForm;
......@@ -64,10 +69,10 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
private static final Long CONTRACT_CACHE_TIME = 86400L;
/**
* 货主签名图像宽度、长度
* 货主/司机签名图像宽度、长度
**/
private static final int GOODS_OWNER_SIGN_WIDTH = 150;
private static final int GOODS_OWNER_SIGN_HEIGHT = 60;
private static final int CUSTOMER_SIGN_WIDTH = 150;
private static final int CUSTOMER_SIGN_HEIGHT = 60;
/**
* 平台公章图像宽度、长度
......@@ -81,19 +86,21 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
private RedisComponent redisComponent;
private ContractOnlineTemplateService contractOnlineTemplateService;
private GoodsOwnerAccountService goodsOwnerAccountService;
private DriverAccountService driverAccountService;
private ContractOnlinePlatformDataService contractOnlinePlatformDataService;
@Autowired
public ContractOnlineRecordServiceImpl(ErrorMessageComponent errorMessageComponent, FeignFileService feignFileService,
FeignBaseService feignBaseService, RedisComponent redisComponent,
ContractOnlineTemplateService contractOnlineTemplateService, GoodsOwnerAccountService goodsOwnerAccountService,
ContractOnlinePlatformDataService contractOnlinePlatformDataService) {
DriverAccountService driverAccountService, ContractOnlinePlatformDataService contractOnlinePlatformDataService) {
this.errorMessageComponent = errorMessageComponent;
this.feignFileService = feignFileService;
this.feignBaseService = feignBaseService;
this.redisComponent = redisComponent;
this.contractOnlineTemplateService = contractOnlineTemplateService;
this.goodsOwnerAccountService = goodsOwnerAccountService;
this.driverAccountService = driverAccountService;
this.contractOnlinePlatformDataService = contractOnlinePlatformDataService;
}
......@@ -105,7 +112,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
accountForm.setId(form.getGoodsOwnerId());
AccountInfoDto accountInfo = goodsOwnerAccountService.getAccountInfo(accountForm);
if (null == accountInfo) {
throw new EException(1001, errorMessageComponent.getContractOnlineGoodsOwnerAdd1001());
throw new EException(1001, errorMessageComponent.getContractOnlineGoodsOwnerSign1001());
}
// 2:获取电子合同模板数据
......@@ -173,6 +180,79 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
return vo;
}
@Override
public ContractOnlineRecordSignDriverVO driverSign(ContractOnlineRecordSignDriverForm form) {
// 1:获取司机信息
DriverDetailDto accountInfo = driverAccountService.getDriverDetailById(form.getDriverId());
if (null == accountInfo) {
throw new EException(1001, errorMessageComponent.getContractOnlineDriverSign1001());
}
// 2:获取电子合同模板数据
String contractTemplateData = this.getContractOnlineTemplateEntity(ContractConstants.CONTRACT_TYPE_DRIVER);
byte[] contractTemplateBytes = Base64.getDecoder().decode(contractTemplateData);
// 3:填充电子合同模板
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ContractOnlineDriverPojo pojo;
byte[] signBytes;
XWPFTemplate template = null;
try {
template = XWPFTemplate.compile(InputStreamUtils.byte2InputStream(contractTemplateBytes));
pojo = this.getDriverSignDataMap(form, accountInfo);
template.render(pojo);
template.write(byteArrayOutputStream);
byteArrayOutputStream.flush();
signBytes = byteArrayOutputStream.toByteArray();
} catch (IOException e) {
log.error("填充电子合同模板失败:" + e.getMessage());
throw new EException(ECode.SERVER_ERROR.code(), "生成电子合同失败[填充电子合同模板失败]");
} finally {
if (null != template) {
try {
template.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
IOUtils.closeQuietly(byteArrayOutputStream);
}
// 4:保存司机签订后的电子合同文件
String contractNumber = pojo.getContactNumber();
JSONObject feignReqJson = new JSONObject();
feignReqJson.put("fileType", "word");
feignReqJson.put("fileName", "电子合同-司机签名-" + contractNumber + ".docx");
feignReqJson.put("fileData", Base64.getEncoder().encodeToString(signBytes));
JSONObject feignResJson;
try {
feignResJson = FeignUtils.getFeignResultData(feignFileService.uploadSingleFile(feignReqJson));
} catch (Exception e) {
log.error("调用[文件服务]上传货主签名合同文件数据失败:" + e.getMessage());
throw new EException("生成电子合同失败[上传司机签名合同文件数据失败]");
}
// 5:保存货主签订后的电子合同记录
ContractOnlineRecordEntity onlineRecordEntity = new ContractOnlineRecordEntity();
onlineRecordEntity.setContractType(ContractConstants.CONTRACT_TYPE_DRIVER);
onlineRecordEntity.setSourceFileId(feignResJson.getString("id"));
onlineRecordEntity.setSourceFileUrl(feignResJson.getString("url"));
onlineRecordEntity.setContractNumber(contractNumber);
onlineRecordEntity.setBusinessNumber(form.getBusinessNumber());
onlineRecordEntity.setCustomerId(form.getDriverId());
onlineRecordEntity.setCustomerSignTime(new Date());
onlineRecordEntity.setSignComplete(ContractConstants.CONTRACT_SIGN_COMPLETE_NO);
this.baseMapper.insert(onlineRecordEntity);
// 6:异步保存线上合同目标文件(PDF)及信息
this.asyncSaveTargetFileInfo(MDC.get("traceId"), onlineRecordEntity, signBytes);
// 7:返回
ContractOnlineRecordSignDriverVO vo = new ContractOnlineRecordSignDriverVO();
vo.setContractNumber(contractNumber);
return vo;
}
@Override
public ContractOnlineRecordVO getContractInfoByNumber(String contractNumber) {
ContractOnlineRecordEntity recordEntity = this.baseMapper.selectOne(new LambdaQueryWrapper<ContractOnlineRecordEntity>()
......@@ -197,7 +277,8 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
}
}
} else {
// TODO,司机签订的合同
DriverDetailDto driverDetailDto = driverAccountService.getDriverDetailById(recordEntity.getCustomerId());
customerName = driverDetailDto.getName();
}
vo.setCustomerName(customerName);
vo.setContractFileId(recordEntity.getTargetFileId());
......@@ -245,7 +326,44 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
pojo.setPlatformName("{{platformName}}");
pojo.setPlatformId("{{platformId}}");
pojo.setEffectiveTime("{{effectiveTime}}");
pojo.setGoodsOwnerSignImg(new PictureRenderData(GOODS_OWNER_SIGN_WIDTH, GOODS_OWNER_SIGN_HEIGHT, ".png", Base64.getDecoder().decode(form.getSignData())));
pojo.setGoodsOwnerSignImg(new PictureRenderData(CUSTOMER_SIGN_WIDTH, CUSTOMER_SIGN_HEIGHT, ".png", Base64.getDecoder().decode(form.getSignData())));
pojo.setPlatformFreightSealImg("{{@platformFreightSealImg}}");
return pojo;
}
/**
* description 获取司机签订合同时的数据
* param [form, accountInfo]
* return com.esv.freight.customer.module.contract.pojo.ContractOnlineDriverPojo
* author Administrator
* createTime 2020/05/26 15:16
**/
private ContractOnlineDriverPojo getDriverSignDataMap(ContractOnlineRecordSignDriverForm form, DriverDetailDto accountInfo) {
ContractOnlineDriverPojo pojo = new ContractOnlineDriverPojo();
BeanUtils.copyProperties(form, pojo);
// 设置合同编号
JSONObject feignReqJson = new JSONObject();
feignReqJson.put("prefix", "SJHT");
feignReqJson.put("formatter", "yyyyMMdd");
feignReqJson.put("length", 18);
JSONObject feignResJson;
try {
feignResJson = FeignUtils.getFeignResultData(feignBaseService.getBatchId(feignReqJson));
pojo.setContactNumber(feignResJson.getString("batchId"));
} catch (Exception e) {
log.error("调用[基础服务]获取合同编号失败:" + e.getMessage());
throw new EException("生成电子合同失败[获取合同编号失败]");
}
// 设置司机信息
pojo.setDriverId(accountInfo.getIdCard());
pojo.setDriverName(accountInfo.getName());
pojo.setPlatformName("{{platformName}}");
pojo.setPlatformId("{{platformId}}");
pojo.setEffectiveTime("{{effectiveTime}}");
pojo.setDriverSignImg(new PictureRenderData(CUSTOMER_SIGN_WIDTH, CUSTOMER_SIGN_HEIGHT, ".png", Base64.getDecoder().decode(form.getSignData())));
pojo.setPlatformFreightSealImg("{{@platformFreightSealImg}}");
return pojo;
......@@ -258,7 +376,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
ContractOnlineRecordEntity contractOnlineRecordEntity = this.baseMapper.selectOne(new LambdaQueryWrapper<ContractOnlineRecordEntity>()
.eq(ContractOnlineRecordEntity::getContractNumber, contractNumber));
if (null == contractOnlineRecordEntity) {
throw new EException(1001, errorMessageComponent.getContractOnlineGoodsOwnerPlatformSign1001());
throw new EException(1001, errorMessageComponent.getContractOnlinePlatformSign1001());
}
// 2:获取合同数据
......@@ -432,7 +550,7 @@ public class ContractOnlineRecordServiceImpl extends ServiceImpl<ContractOnlineR
// 保存PDF文件
JSONObject feignReqJson = new JSONObject();
feignReqJson.put("fileType", "pdf");
feignReqJson.put("fileName", "电子合同-平台签名-" + contractNumber + ".pdf");
feignReqJson.put("fileName", "电子合同-" + contractNumber + ".pdf");
feignReqJson.put("fileData", Base64.getEncoder().encodeToString(targetFileBytes));
JSONObject feignResJson;
try {
......
package com.esv.freight.customer.module.contract.vo;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.contract.vo.ContractOnlineRecordSignDriverVO
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/21 17:54
* @version:1.0
*/
@Data
public class ContractOnlineRecordSignDriverVO {
/**
* 合同编号
*/
private String contractNumber;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
......@@ -249,7 +249,11 @@ error-message:
goods-owner:
sign:
1001: 无效的货主ID
platform-sign:
driver:
sign:
1001: 无效的司机ID
platform:
sign:
1001: 无效的合同编号
get-by-number:
1001: 无效的合同编号
\ No newline at end of file
......@@ -249,7 +249,11 @@ error-message:
goods-owner:
sign:
1001: 无效的货主ID
platform-sign:
driver:
sign:
1001: 无效的司机ID
platform:
sign:
1001: 无效的合同编号
get-by-number:
1001: 无效的合同编号
\ No newline at end of file
......@@ -43,7 +43,7 @@
<!-- mybatis sql日志 日志的级别需要是DEBUG -->
<!-- 日志打印的包的范围,及分类日志文件存储 -->
<logger name="com.esv" level="INFO" additivity="false">
<logger name="com.esv" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE_APPENDER" />
<appender-ref ref="FILE_APPENDER" />
</logger>
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.BaseTestController;
import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.module.contract.form.ContractOnlineRecordForm;
import com.esv.freight.customer.module.contract.form.ContractOnlineRecordSignDriverForm;
import com.esv.freight.customer.module.contract.form.ContractOnlineRecordSignGoodsOwnerForm;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
......@@ -139,7 +140,7 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
// 构造数据
ContractOnlineRecordForm form = new ContractOnlineRecordForm();
form.setContractNumber("HZHT20200526000002");
form.setContractNumber("SJHT20200526000001");
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
......@@ -191,7 +192,7 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
// 构造数据
ContractOnlineRecordForm form = new ContractOnlineRecordForm();
form.setContractNumber("HZHT20200526000002");
form.setContractNumber("SJHT20200526000001");
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
......@@ -234,4 +235,88 @@ public class ContractOnlineRecordControllerTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1001, result.getIntValue("code"));
}
/**
* 司机与平台的电子合同-司机签订
**/
@Test
public void a1_driverSign_success_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 filepath = "D:\\test\\何锋.jpg";
File signFile = new File(filepath);
InputStream input = new FileInputStream(signFile);
form.setSignData(Base64.getEncoder().encodeToString(IOUtils.toByteArray(input)));
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(ECode.SUCCESS.code(), result.getIntValue("code"));
Assert.assertTrue(result.getJSONObject("data").containsKey("contractNumber"));
}
/**
* 司机与平台的电子合同-司机签订:无效的司机ID
**/
@Test
@Rollback
public void a2_driverSign_failure_test() throws Exception {
String url = "/contract/online/driver/sign";
// 构造数据
ContractOnlineRecordSignDriverForm form = new ContractOnlineRecordSignDriverForm();
form.setDriverId(99999L);
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 filepath = "D:\\test\\何锋.jpg";
File signFile = new File(filepath);
InputStream input = new FileInputStream(signFile);
form.setSignData(Base64.getEncoder().encodeToString(IOUtils.toByteArray(input)));
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(1001, 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