Commit cc108409 authored by huangcb's avatar huangcb

承运商接口:停用/启用车辆

parent c27be7fb
......@@ -157,4 +157,14 @@ public class ErrorMessageComponent {
@Value("${error-message.carrier.vehicle.audit-list.1001}")
private String carrierVehicleAuditList1001;
@Value("${error-message.carrier.vehicle.block.1001}")
private String carrierVehicleBlock1001;
@Value("${error-message.carrier.vehicle.block.1002}")
private String carrierVehicleBlock1002;
@Value("${error-message.carrier.vehicle.unblock.1001}")
private String carrierVehicleUnBlock1001;
@Value("${error-message.carrier.vehicle.unblock.1002}")
private String carrierVehicleUnBlock1002;
}
......@@ -18,6 +18,8 @@ import com.esv.freight.customer.module.vehicle.form.VehicleQueryForm;
import com.esv.freight.customer.module.vehicle.service.VehicleAuditHistoryService;
import com.esv.freight.customer.module.vehicle.service.VehicleService;
import com.esv.freight.customer.module.vehicle.validator.groups.ValidatorAuditHistory;
import com.esv.freight.customer.module.vehicle.validator.groups.ValidatorBlock;
import com.esv.freight.customer.module.vehicle.validator.groups.ValidatorUnblock;
import com.esv.freight.customer.module.vehicle.vo.VehicleAuditVO;
import com.esv.freight.customer.module.vehicle.vo.VehicleDetailVO;
import lombok.extern.slf4j.Slf4j;
......@@ -172,4 +174,32 @@ public class VehicleController {
return EResponse.ok(voList);
}
/**
* description 停用车辆
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/27 17:37
**/
@PostMapping("/block")
public EResponse block(@RequestBody @Validated(ValidatorBlock.class) VehicleQueryForm form) throws EException {
vehicleService.blockVehicle(form.getId());
return EResponse.ok();
}
/**
* description 启用车辆
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/27 17:37
**/
@PostMapping("/unblock")
public EResponse unblock(@RequestBody @Validated(ValidatorUnblock.class) VehicleQueryForm form) throws EException {
vehicleService.unBlockVehicle(form.getId());
return EResponse.ok();
}
}
......@@ -3,6 +3,8 @@ package com.esv.freight.customer.module.vehicle.form;
import com.esv.freight.customer.common.validator.groups.ValidatorDetail;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.vehicle.validator.groups.ValidatorAuditHistory;
import com.esv.freight.customer.module.vehicle.validator.groups.ValidatorBlock;
import com.esv.freight.customer.module.vehicle.validator.groups.ValidatorUnblock;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
......@@ -24,7 +26,7 @@ public class VehicleQueryForm {
/**
*
*/
@NotNull(message = "参数id不能为空", groups = {ValidatorDetail.class, ValidatorAuditHistory.class})
@NotNull(message = "参数id不能为空", groups = {ValidatorDetail.class, ValidatorAuditHistory.class, ValidatorBlock.class, ValidatorUnblock.class})
private Long id;
/**
* 承运商帐号ID
......
......@@ -59,6 +59,24 @@ public interface VehicleService extends IService<VehicleEntity> {
* createTime 2020/04/27 16:29
**/
Boolean vehicleExits(Long id);
/**
* description 停用车辆
* param [id]
* return java.lang.Integer
* author Administrator
* createTime 2020/04/27 17:23
**/
Integer blockVehicle(Long id);
/**
* description 启用
* param [id]
* return java.lang.Integer
* author Administrator
* createTime 2020/04/27 17:26
**/
Integer unBlockVehicle(Long id);
}
......@@ -203,7 +203,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> i
VehicleEntity updateEntity = new VehicleEntity();
updateEntity.setId(form.getId());
updateEntity.setAuditStatus(form.getAuditState());
this.baseMapper.updateById(vehicleEntity);
this.baseMapper.updateById(updateEntity);
// 3:更新车辆审核记录
VehicleAuditHistoryEntity vehicleAuditHistoryEntity = new VehicleAuditHistoryEntity();
......@@ -223,4 +223,36 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleDao, VehicleEntity> i
return true;
}
}
@Override
public Integer blockVehicle(Long id) {
VehicleEntity vehicleEntity = this.baseMapper.selectById(id);
if (null == vehicleEntity) {
throw new EException(1001, errorMessageComponent.getCarrierVehicleBlock1001());
}
if (VehicleConstants.VEHICLE_ACCOUNT_STATUS_BLOCK.equals(vehicleEntity.getVehicleStatus())) {
throw new EException(1002, errorMessageComponent.getCarrierVehicleBlock1002());
}
VehicleEntity updateEntity = new VehicleEntity();
updateEntity.setId(id);
updateEntity.setVehicleStatus(VehicleConstants.VEHICLE_ACCOUNT_STATUS_BLOCK);
return this.baseMapper.updateById(updateEntity);
}
@Override
public Integer unBlockVehicle(Long id) {
VehicleEntity vehicleEntity = this.baseMapper.selectById(id);
if (null == vehicleEntity) {
throw new EException(1001, errorMessageComponent.getCarrierVehicleUnBlock1001());
}
if (VehicleConstants.VEHICLE_ACCOUNT_STATUS_UNBLOCK.equals(vehicleEntity.getVehicleStatus())) {
throw new EException(1002, errorMessageComponent.getCarrierVehicleUnBlock1002());
}
VehicleEntity updateEntity = new VehicleEntity();
updateEntity.setId(id);
updateEntity.setVehicleStatus(VehicleConstants.VEHICLE_ACCOUNT_STATUS_UNBLOCK);
return this.baseMapper.updateById(updateEntity);
}
}
\ No newline at end of file
package com.esv.freight.customer.module.vehicle.validator.groups;
import javax.validation.groups.Default;
/**
* @description: 参数校验分组:停用
* @project: SpringCloudTemplate
* @name: com.esv.freight.customer.module.vehicle.validator.groups.ValidatorBlock
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorBlock extends Default {
}
package com.esv.freight.customer.module.vehicle.validator.groups;
import javax.validation.groups.Default;
/**
* @description: 参数校验分组:启用
* @project: SpringCloudTemplate
* @name: com.esv.freight.customer.module.vehicle.validator.groups.ValidatorUnblock
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorUnblock extends Default {
}
......@@ -137,4 +137,10 @@ error-message:
1001: 无效的车辆ID
1002: 车辆已审核通过
audit-list:
1001: 无效的车辆ID
\ No newline at end of file
1001: 无效的车辆ID
block:
1001: 无效的车辆ID
1002: 车辆已停用
unblock:
1001: 无效的车辆ID
1002: 车辆已启用
\ No newline at end of file
......@@ -247,4 +247,206 @@ public class VehicleControllerTest extends BaseTestController {
Assert.assertEquals(ECode.SUCCESS.code(), result.getIntValue("code"));
Assert.assertTrue(null != result.getJSONArray("data"));
}
/**
* 查看审核历史:无效的车辆ID
**/
@Test
public void c2_auditList_wrong_id_failure_test() throws Exception {
String url = "/carrier/vehicle/auditList";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(99999L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.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 d1_block_success_test() throws Exception {
String url = "/carrier/vehicle/block";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(1L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.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 d2_block_wrong_id_failure_test() throws Exception {
String url = "/carrier/vehicle/block";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(99999L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.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 d3_block_has_block_failure_test() throws Exception {
String url = "/carrier/vehicle/block";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(1L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.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"));
}
/**
* 启用车辆
**/
@Test
@Rollback
public void e1_unblock_success_test() throws Exception {
String url = "/carrier/vehicle/unblock";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(1L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.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 e2_unblock_wrong_id_failure_test() throws Exception {
String url = "/carrier/vehicle/unblock";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(99999L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.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 e3_unblock_has_unblock_failure_test() throws Exception {
String url = "/carrier/vehicle/unblock";
// 构造数据
VehicleQueryForm form = new VehicleQueryForm();
form.setId(1L);
JSONObject reqJson = JSONObject.parseObject(form.toString());
MvcResult mvcResult = this.getMockMvc().perform(MockMvcRequestBuilders.post(url)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.headers(this.getDefaultHttpHeaders())
.content(reqJson.toJSONString()))
.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