Commit 63000c7d authored by huangcb's avatar huangcb

承运商接口:司机绑定车辆

parent 6d2ece09
......@@ -218,4 +218,21 @@ public class ErrorMessageComponent {
private String carrierDriverVehicleList1001;
@Value("${error-message.carrier.driver.vehicle-list.1002}")
private String carrierDriverVehicleList1002;
@Value("${error-message.carrier.driver.vehicle-bind.1001}")
private String carrierDriverVehicleBind1001;
@Value("${error-message.carrier.driver.vehicle-bind.1002}")
private String carrierDriverVehicleBind1002;
@Value("${error-message.carrier.driver.vehicle-bind.1003}")
private String carrierDriverVehicleBind1003;
@Value("${error-message.carrier.driver.vehicle-bind.1010}")
private String carrierDriverVehicleBind1010;
@Value("${error-message.carrier.driver.vehicle-bind.1011}")
private String carrierDriverVehicleBind1011;
@Value("${error-message.carrier.driver.vehicle-bind.1012}")
private String carrierDriverVehicleBind1012;
@Value("${error-message.carrier.driver.vehicle-bind.1020}")
private String carrierDriverVehicleBind1020;
@Value("${error-message.carrier.driver.vehicle-bind.1021}")
private String carrierDriverVehicleBind1021;
}
......@@ -4,7 +4,9 @@ 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.driver.form.DriverQueryForm;
import com.esv.freight.customer.module.driver.form.DriverVehicleForm;
import com.esv.freight.customer.module.driver.service.DriverVehicleService;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorBind;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
......@@ -46,4 +48,18 @@ public class DriverVehicleController {
public EResponse list(@RequestBody @Validated(ValidatorDetail.class) DriverQueryForm form) throws EException {
return EResponse.ok(driverVehicleService.getDriverBindVehicleList(form.getId()));
}
/**
* description 司机绑定车辆
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/29 20:16
**/
@PostMapping("/bind")
public EResponse bind(@RequestBody @Validated(ValidatorBind.class) DriverVehicleForm form) throws EException {
driverVehicleService.driverBindVehicle(form);
return EResponse.ok();
}
}
package com.esv.freight.customer.module.driver.form;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorBind;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorUnbind;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotNull;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.driver.form.DriverVehicleForm
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/29 19:54
* @version:1.0
*/
@Data
public class DriverVehicleForm {
/**
* 司机ID
*/
@NotNull(message = "参数driverId不能为空", groups = {ValidatorBind.class, ValidatorUnbind.class})
private Long driverId;
/**
* 车辆ID
*/
@NotNull(message = "参数vehicleId不能为空", groups = {ValidatorBind.class, ValidatorUnbind.class})
private Long vehicleId;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
package com.esv.freight.customer.module.driver.service;
import com.esv.freight.customer.module.driver.form.DriverVehicleForm;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import java.util.List;
......@@ -24,4 +25,13 @@ public interface DriverVehicleService {
**/
List<DriverVehicleListVO> getDriverBindVehicleList(Long id);
/**
* description 司机绑定车辆
* param [form]
* return java.lang.Integer
* author Administrator
* createTime 2020/04/29 19:57
**/
Integer driverBindVehicle(DriverVehicleForm form);
}
......@@ -3,11 +3,18 @@ package com.esv.freight.customer.module.driver.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.freight.customer.module.driver.DriverConstants;
import com.esv.freight.customer.module.driver.entity.DriverAccountEntity;
import com.esv.freight.customer.module.driver.form.DriverVehicleForm;
import com.esv.freight.customer.module.driver.service.DriverAccountService;
import com.esv.freight.customer.module.driver.service.DriverVehicleService;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import com.esv.freight.customer.module.vehicle.VehicleConstants;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
import com.esv.freight.customer.module.vehicle.entity.VehicleEntity;
import com.esv.freight.customer.module.vehicle.service.VehicleDriverService;
import com.esv.freight.customer.module.vehicle.service.VehicleService;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -28,12 +35,15 @@ public class DriverVehicleServiceImpl implements DriverVehicleService {
private DriverAccountService driverAccountService;
private VehicleService vehicleService;
private VehicleDriverService vehicleDriverService;
public DriverVehicleServiceImpl(ErrorMessageComponent errorMessageComponent, DriverAccountService driverAccountService,
VehicleDriverService vehicleDriverService) {
VehicleService vehicleService, VehicleDriverService vehicleDriverService) {
this.errorMessageComponent = errorMessageComponent;
this.driverAccountService = driverAccountService;
this.vehicleService = vehicleService;
this.vehicleDriverService = vehicleDriverService;
}
......@@ -54,4 +64,55 @@ public class DriverVehicleServiceImpl implements DriverVehicleService {
return voList;
}
@Override
public Integer driverBindVehicle(DriverVehicleForm form) {
// 1:校验
// 1.1:校验司机ID是否有效
DriverAccountEntity driverAccountEntity = this.driverAccountService.getById(form.getDriverId());
if (null == driverAccountEntity) {
throw new EException(1001, errorMessageComponent.getCarrierDriverVehicleBind1001());
}
// 1.2:校验司机帐号是否停用
if (DriverConstants.ACCOUNT_STATUS_BLOCK.equals(driverAccountEntity.getAccountStatus())) {
throw new EException(1002, errorMessageComponent.getCarrierDriverVehicleBind1002());
}
// 1.3:校验司机帐号是否未审核通过
if (!DriverConstants.ACCOUNT_AUDIT_STATUS_SUCCESS.equals(driverAccountEntity.getAuditStatus())) {
throw new EException(1003, errorMessageComponent.getCarrierDriverVehicleBind1003());
}
// 1.4:校验车辆ID是否有效
VehicleEntity vehicleEntity = this.vehicleService.getById(form.getVehicleId());
if (null == vehicleEntity) {
throw new EException(1010, errorMessageComponent.getCarrierDriverVehicleBind1010());
}
// 1.5:校验车辆是否已停用
if (VehicleConstants.VEHICLE_ACCOUNT_STATUS_BLOCK.equals(vehicleEntity.getVehicleStatus())) {
throw new EException(1011, errorMessageComponent.getCarrierDriverVehicleBind1011());
}
// 1.6:校验车辆是否未审核通过
if (!VehicleConstants.VEHICLE_AUDIT_STATUS_SUCCESS.equals(vehicleEntity.getAuditStatus())) {
throw new EException(1012, errorMessageComponent.getCarrierDriverVehicleBind1012());
}
// 1.7:校验司机与车辆所属承运商是否不一致
if (!driverAccountEntity.getCarrierId().equals(vehicleEntity.getCarrierId())) {
throw new EException(1020, errorMessageComponent.getCarrierDriverVehicleBind1020());
}
// 1.8:校验是否重复绑定
int count = this.vehicleDriverService.getBaseMapper().selectCount(new QueryWrapper<VehicleDriverEntity>().lambda()
.eq(VehicleDriverEntity::getVehicleId, form.getVehicleId())
.eq(VehicleDriverEntity::getDriverId, form.getDriverId()));
if (0 < count) {
throw new EException(1021, errorMessageComponent.getCarrierDriverVehicleBind1021());
}
// 2:绑定司机与车辆
VehicleDriverEntity vehicleDriverEntity = new VehicleDriverEntity();
vehicleDriverEntity.setCarrierId(driverAccountEntity.getCarrierId());
vehicleDriverEntity.setVehicleId(form.getVehicleId());
vehicleDriverEntity.setDriverId(form.getDriverId());
vehicleDriverEntity.setSelected(false);
vehicleDriverEntity.setOperateUser(ReqUtils.getRequestUserAccount());
return this.vehicleDriverService.getBaseMapper().insert(vehicleDriverEntity);
}
}
package com.esv.freight.customer.module.driver.validator.groups;
import javax.validation.groups.Default;
/**
* @description: 参数校验分组:绑定
* @project: SpringCloudTemplate
* @name: com.esv.freight.customer.module.driver.validator.groups.ValidatorBind
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorBind extends Default {
}
package com.esv.freight.customer.module.driver.validator.groups;
import javax.validation.groups.Default;
/**
* @description: 参数校验分组:解绑
* @project: SpringCloudTemplate
* @name: com.esv.freight.customer.module.driver.validator.groups.ValidatorUnbind
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorUnbind extends Default {
}
......@@ -174,4 +174,13 @@ error-message:
1001: 无效的账号ID
vehicle-list:
1001: 无效的司机ID
1002: 该司机未绑定车辆
\ No newline at end of file
1002: 该司机未绑定车辆
vehicle-bind:
1001: 无效的司机ID
1002: 司机帐号已停用
1003: 司机帐号未审核通过
1010: 无效的车辆ID
1011: 车辆已停用
1012: 车辆未审核通过
1020: 司机与车辆所属承运商不一致
1021: 重复绑定
\ No newline at end of file
......@@ -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.driver.form.DriverQueryForm;
import com.esv.freight.customer.module.driver.form.DriverVehicleForm;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
......@@ -121,4 +122,34 @@ public class DriverVehicleControllerTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1002, result.getIntValue("code"));
}
/**
* 司机绑定车辆
**/
@Test
@Rollback
public void b1_bind_success_test() throws Exception {
String url = "/carrier/driver/vehicle/bind";
// 构造数据
DriverVehicleForm form = new DriverVehicleForm();
form.setDriverId(3L);
form.setVehicleId(4L);
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"));
}
}
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