Commit 77b116e5 authored by huangcb's avatar huangcb

线下文本合同:货主合同-编辑

parent c58cbc5b
......@@ -276,4 +276,9 @@ public class ErrorMessageComponent {
private String contractOfflineGoodsOwnerAdd1001;
@Value("${error-message.contract.offline.goods-owner.add.1002}")
private String contractOfflineGoodsOwnerAdd1002;
@Value("${error-message.contract.offline.goods-owner.edit.1001}")
private String contractOfflineGoodsOwnerEdit1001;
@Value("${error-message.contract.offline.goods-owner.edit.1002}")
private String contractOfflineGoodsOwnerEdit1002;
}
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.EResponse;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.contract.form.ContractOfflineGoodsOwnerForm;
import com.esv.freight.customer.module.contract.service.ContractOfflineGoodsOwnerService;
import lombok.extern.slf4j.Slf4j;
......@@ -50,4 +51,17 @@ public class ContractOfflineGoodsOwnerController {
data.put("id", id);
return EResponse.ok(data);
}
/**
* description 编辑合同
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/05/19 19:44
**/
@PostMapping("/edit")
public EResponse edit(@RequestBody @Validated(ValidatorUpdate.class) ContractOfflineGoodsOwnerForm form) throws EException {
contractOfflineGoodsOwnerService.editOfflineContract(form);
return EResponse.ok();
}
}
package com.esv.freight.customer.module.contract.form;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
......@@ -25,6 +26,7 @@ public class ContractOfflineGoodsOwnerForm {
/**
*
*/
@NotNull(message = "参数id不能为空", groups = {ValidatorUpdate.class})
private Long id;
/**
* 货主帐号ID
......@@ -34,49 +36,49 @@ public class ContractOfflineGoodsOwnerForm {
/**
* 合同编号
*/
@Length(max = 50, message = "参数contractNumber长度不合法", groups = {ValidatorInsert.class})
@Length(max = 50, message = "参数contractNumber长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@NotBlank(message = "参数contractNumber不能为空", groups = {ValidatorInsert.class})
private String contractNumber;
/**
* 合同名称
*/
@Length(max = 50, message = "参数contractName长度不合法", groups = {ValidatorInsert.class})
@Length(max = 50, message = "参数contractName长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@NotBlank(message = "参数contractName不能为空", groups = {ValidatorInsert.class})
private String contractName;
/**
* 合同类型:1-主合同、2-补充合同、3-临时合同
*/
@Range(min = 1, max = 3, message = "参数contractType不合法", groups = {ValidatorInsert.class})
@Range(min = 1, max = 3, message = "参数contractType不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@NotNull(message = "参数contractType不能为空", groups = {ValidatorInsert.class})
private Integer contractType;
/**
* 合同签订日期
*/
@Length(min = 10, max = 10, message = "参数signDate长度不合法", groups = {ValidatorInsert.class})
@Length(min = 10, max = 10, message = "参数signDate长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@NotBlank(message = "参数signDate不能为空", groups = {ValidatorInsert.class})
private String signDate;
/**
* 合同起始日期
*/
@Length(min = 10, max = 10, message = "参数startDate长度不合法", groups = {ValidatorInsert.class})
@Length(min = 10, max = 10, message = "参数startDate长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@NotBlank(message = "参数startDate不能为空", groups = {ValidatorInsert.class})
private String startDate;
/**
* 合同截止日期
*/
@Length(min = 10, max = 10, message = "参数endDate长度不合法", groups = {ValidatorInsert.class})
@Length(min = 10, max = 10, message = "参数endDate长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@NotBlank(message = "参数endDate不能为空", groups = {ValidatorInsert.class})
private String endDate;
/**
* 合同文件URL
*/
@Length(max = 200, message = "参数fileUrl长度不合法", groups = {ValidatorInsert.class})
@Length(max = 200, message = "参数fileUrl长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@NotBlank(message = "参数fileUrl不能为空", groups = {ValidatorInsert.class})
private String fileUrl;
/**
* 备注
*/
@Length(max = 200, message = "参数remark长度不合法", groups = {ValidatorInsert.class})
@Length(max = 200, message = "参数remark长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
private String remark;
@Override
......
......@@ -22,5 +22,14 @@ public interface ContractOfflineGoodsOwnerService extends IService<ContractOffli
**/
Long addOfflineContract(ContractOfflineGoodsOwnerForm form);
/**
* description 编辑线下文本合同(货主)
* param [form]
* return java.lang.Integer
* author Administrator
* createTime 2020/05/19 19:34
**/
Integer editOfflineContract(ContractOfflineGoodsOwnerForm form);
}
......@@ -53,4 +53,30 @@ public class ContractOfflineGoodsOwnerServiceImpl extends ServiceImpl<ContractOf
return contractOfflineGoodsOwnerEntity.getId();
}
@Override
public Integer editOfflineContract(ContractOfflineGoodsOwnerForm form) {
// 1:校验
ContractOfflineGoodsOwnerEntity dbEntity = this.baseMapper.selectById(form.getId());
if (null == dbEntity) {
throw new EException(1001, errorMessageComponent.getContractOfflineGoodsOwnerEdit1001());
}
int count = this.baseMapper.selectCount(new LambdaQueryWrapper<ContractOfflineGoodsOwnerEntity>()
.ne(ContractOfflineGoodsOwnerEntity::getId, form.getId())
.eq(ContractOfflineGoodsOwnerEntity::getGoodsOwnerId, dbEntity.getGoodsOwnerId())
.eq(ContractOfflineGoodsOwnerEntity::getContractNumber, form.getContractNumber()));
if (0 < count) {
throw new EException(1002, errorMessageComponent.getContractOfflineGoodsOwnerAdd1002());
}
// 2:更新记录
ContractOfflineGoodsOwnerEntity contractOfflineGoodsOwnerEntity = new ContractOfflineGoodsOwnerEntity();
BeanUtils.copyProperties(form, contractOfflineGoodsOwnerEntity);
contractOfflineGoodsOwnerEntity.setGoodsOwnerId(null);
contractOfflineGoodsOwnerEntity.setSignDate(DateUtils.parse(form.getSignDate(), DateUtils.DATE_FORMAT3));
contractOfflineGoodsOwnerEntity.setStartDate(DateUtils.parse(form.getStartDate(), DateUtils.DATE_FORMAT3));
contractOfflineGoodsOwnerEntity.setEndDate(DateUtils.parse(form.getEndDate(), DateUtils.DATE_FORMAT3));
return this.baseMapper.updateById(contractOfflineGoodsOwnerEntity);
}
}
\ No newline at end of file
......@@ -223,4 +223,7 @@ error-message:
goods-owner:
add:
1001: 无效的货主ID
1002: 合同编号已存在
edit:
1001: 无效的合同ID
1002: 合同编号已存在
\ No newline at end of file
......@@ -139,4 +139,109 @@ public class ContractOfflineGoodsOwnerControllerTest extends BaseTestController
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1002, result.getIntValue("code"));
}
/**
* 编辑合同
**/
@Test
@Rollback
public void b1_edit_success_test() throws Exception {
String url = "/contract/offline/goodsowner/edit";
// 构造数据
ContractOfflineGoodsOwnerForm form = new ContractOfflineGoodsOwnerForm();
form.setId(1L);
form.setContractNumber("202005191001");
form.setContractName("黄朝斌测试有限公司01-运输业务框架合同");
form.setContractType(1); // 合同类型:1-主合同、2-补充合同、3-临时合同
form.setSignDate("2020-05-19");
form.setStartDate("2020-05-20");
form.setEndDate("2021-05-19");
form.setFileUrl("http://192.168.31.248:8082/file/download/direct/6FB1DC2B9961B3AFFDE452A479766F6C2E5B46D3534376A8C40ACB4987D0602B85D1E1739AF93D52A92AEB7ACABB90DC");
form.setRemark("这是一条测试数据");
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"));
}
/**
* 编辑合同:无效的合同ID
**/
@Test
@Rollback
public void b2_edit_wrong_id_failure_test() throws Exception {
String url = "/contract/offline/goodsowner/edit";
// 构造数据
ContractOfflineGoodsOwnerForm form = new ContractOfflineGoodsOwnerForm();
form.setId(99999L);
form.setContractNumber("202005191001");
form.setContractName("黄朝斌测试有限公司01-运输业务框架合同");
form.setContractType(1); // 合同类型:1-主合同、2-补充合同、3-临时合同
form.setSignDate("2020-05-19");
form.setStartDate("2020-05-20");
form.setEndDate("2021-05-19");
form.setFileUrl("http://192.168.31.248:8082/file/download/direct/6FB1DC2B9961B3AFFDE452A479766F6C2E5B46D3534376A8C40ACB4987D0602B85D1E1739AF93D52A92AEB7ACABB90DC");
form.setRemark("这是一条测试数据");
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"));
}
/**
* 编辑合同:合同编号已存在
**/
@Test
@Rollback
public void b3_edit_wrong_contractNumber_failure_test() throws Exception {
String url = "/contract/offline/goodsowner/edit";
// 构造数据
ContractOfflineGoodsOwnerForm form = new ContractOfflineGoodsOwnerForm();
form.setId(1L);
form.setContractNumber("202005191002");
form.setContractName("黄朝斌测试有限公司01-运输业务框架合同");
form.setContractType(1); // 合同类型:1-主合同、2-补充合同、3-临时合同
form.setSignDate("2020-05-19");
form.setStartDate("2020-05-20");
form.setEndDate("2021-05-19");
form.setFileUrl("http://192.168.31.248:8082/file/download/direct/6FB1DC2B9961B3AFFDE452A479766F6C2E5B46D3534376A8C40ACB4987D0602B85D1E1739AF93D52A92AEB7ACABB90DC");
form.setRemark("这是一条测试数据");
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