Commit 24d71786 authored by huangcb's avatar huangcb

承运商接口:验证司机与车辆是否绑定

parent 12f004b1
......@@ -252,4 +252,11 @@ public class ErrorMessageComponent {
private String carrierDriverAccountCheck1001;
@Value("${error-message.carrier.driver.account-check.1002}")
private String carrierDriverAccountCheck1002;
@Value("${error-message.carrier.driver.vehicle-check-bind.1001}")
private String carrierDriverVehicleCheckBind1001;
@Value("${error-message.carrier.driver.vehicle-check-bind.1002}")
private String carrierDriverVehicleCheckBind1002;
@Value("${error-message.carrier.driver.vehicle-check-bind.1003}")
private String carrierDriverVehicleCheckBind1003;
}
......@@ -12,6 +12,7 @@ import com.esv.freight.customer.common.validator.groups.ValidatorDetail;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorList;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.carrier.CarrierConstants;
import com.esv.freight.customer.module.driver.DriverConstants;
import com.esv.freight.customer.module.driver.dto.DriverDetailDto;
import com.esv.freight.customer.module.driver.entity.DriverAuditHistoryEntity;
......@@ -125,8 +126,8 @@ public class DriverController {
* author Administrator
* createTime 2020/04/28 20:26
**/
@PostMapping("/detail")
public EResponse detail(@RequestBody @Validated(ValidatorDetail.class) DriverQueryForm form) throws EException {
@PostMapping("/getDetailById")
public EResponse getDetailById(@RequestBody @Validated(ValidatorDetail.class) DriverQueryForm form) throws EException {
DriverDetailDto dto = driverAccountService.getDriverDetailById(form.getId());
if (null == dto) {
throw new EException(1001, errorMessageComponent.getCarrierDriverDetail1001());
......@@ -136,6 +137,11 @@ public class DriverController {
DriverDetailVO vo = new DriverDetailVO();
BeanUtils.copyProperties(dto, vo);
vo.setCreateTime(dto.getCreateTime().getTime());
if (CarrierConstants.CARRIER_TYPE_COMPANY.equals(dto.getCarrierType())) {
vo.setCarrierName(dto.getCarrierFullName());
} else {
vo.setCarrierName(dto.getCarrierContactor());
}
return EResponse.ok(vo);
}
......@@ -158,6 +164,11 @@ public class DriverController {
DriverDetailVO vo = new DriverDetailVO();
BeanUtils.copyProperties(dto, vo);
vo.setCreateTime(dto.getCreateTime().getTime());
if (CarrierConstants.CARRIER_TYPE_COMPANY.equals(dto.getCarrierType())) {
vo.setCarrierName(dto.getCarrierFullName());
} else {
vo.setCarrierName(dto.getCarrierContactor());
}
return EResponse.ok(vo);
}
......
......@@ -7,6 +7,7 @@ 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 com.esv.freight.customer.module.driver.validator.groups.ValidatorCheckBind;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorUnbind;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -30,7 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/carrier/driver/vehicle")
@Validated
public class DriverVehicleController {
private DriverVehicleService driverVehicleService;
@Autowired
......@@ -77,4 +78,16 @@ public class DriverVehicleController {
return EResponse.ok();
}
/**
* description 验证司机与车辆是否绑定
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/30 16:00
**/
@PostMapping("/checkBind")
public EResponse checkBind(@RequestBody @Validated(ValidatorCheckBind.class) DriverVehicleForm form) throws EException {
return EResponse.ok(driverVehicleService.checkBind(form));
}
}
package com.esv.freight.customer.module.driver.service;
import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.module.driver.form.DriverVehicleForm;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
import java.util.List;
......@@ -43,4 +45,22 @@ public interface DriverVehicleService {
**/
Integer driverUnbindVehicle(DriverVehicleForm form);
/**
* description 通过司机ID/车辆ID获取绑定记录
* param [form]
* return com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity
* author Administrator
* createTime 2020/04/30 15:56
**/
VehicleDriverEntity getRecordBy2Id(DriverVehicleForm form);
/**
* description 验证司机与车辆是否绑定
* param [form]
* return com.alibaba.fastjson.JSONObject
* author Administrator
* createTime 2020/04/30 15:59
**/
JSONObject checkBind(DriverVehicleForm form);
}
package com.esv.freight.customer.module.driver.service.impl;
import com.alibaba.fastjson.JSONObject;
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.carrier.CarrierConstants;
import com.esv.freight.customer.module.driver.DriverConstants;
import com.esv.freight.customer.module.driver.dto.DriverDetailDto;
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.DriverDetailVO;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import com.esv.freight.customer.module.vehicle.VehicleConstants;
import com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto;
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 com.esv.freight.customer.module.vehicle.vo.VehicleDetailVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -148,4 +155,56 @@ public class DriverVehicleServiceImpl implements DriverVehicleService {
.eq(VehicleDriverEntity::getVehicleId, form.getVehicleId())
.eq(VehicleDriverEntity::getDriverId, form.getDriverId()));
}
@Override
public VehicleDriverEntity getRecordBy2Id(DriverVehicleForm form) {
return this.vehicleDriverService.getBaseMapper().selectOne(new QueryWrapper<VehicleDriverEntity>().lambda()
.eq(VehicleDriverEntity::getVehicleId, form.getVehicleId())
.eq(VehicleDriverEntity::getDriverId, form.getDriverId()));
}
@Override
public JSONObject checkBind(DriverVehicleForm form) {
JSONObject data = new JSONObject();
// 1:校验司机与车辆是否绑定
VehicleDriverEntity vehicleDriverEntity = this.getRecordBy2Id(form);
if (null == vehicleDriverEntity) {
throw new EException(1001, errorMessageComponent.getCarrierDriverVehicleCheckBind1001());
}
// 2:获取司机信息
DriverDetailDto driverDetailDto = this.driverAccountService.getDriverDetailById(form.getDriverId());
if (null == driverDetailDto) {
throw new EException(1002, errorMessageComponent.getCarrierDriverVehicleCheckBind1002());
} else {
DriverDetailVO driverDetailVO = new DriverDetailVO();
BeanUtils.copyProperties(driverDetailDto, driverDetailVO);
driverDetailVO.setCreateTime(driverDetailDto.getCreateTime().getTime());
if (CarrierConstants.CARRIER_TYPE_COMPANY.equals(driverDetailDto.getCarrierType())) {
driverDetailVO.setCarrierName(driverDetailDto.getCarrierFullName());
} else {
driverDetailVO.setCarrierName(driverDetailDto.getCarrierContactor());
}
data.put("driverInfo", driverDetailVO);
}
// 3:获取车辆信息
VehicleDetailDto vehicleDetailDto = this.vehicleService.getVehicleDetail(form.getVehicleId());
if (null == vehicleDetailDto) {
throw new EException(1003, errorMessageComponent.getCarrierDriverVehicleCheckBind1003());
} else {
VehicleDetailVO vehicleDetailVO = new VehicleDetailVO();
BeanUtils.copyProperties(vehicleDetailDto, vehicleDetailVO);
vehicleDetailVO.setCreateTime(vehicleDetailDto.getCreateTime().getTime());
if (CarrierConstants.CARRIER_TYPE_COMPANY.equals(vehicleDetailDto.getCarrierType())) {
vehicleDetailVO.setCarrierName(vehicleDetailDto.getCarrierFullName());
} else {
vehicleDetailVO.setCarrierName(vehicleDetailDto.getCarrierContactor());
}
data.put("vehicleInfo", vehicleDetailVO);
}
return data;
}
}
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.ValidatorCheckBind
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorCheckBind extends Default {
}
......@@ -26,6 +26,10 @@ public class DriverDetailVO {
* 承运商帐号ID
*/
private Long carrierId;
/**
* 承运商名称
*/
private String carrierName;
/**
* 登录帐号,司机手机号
*/
......
......@@ -9,6 +9,7 @@ import com.esv.freight.customer.common.validator.groups.ValidatorDetail;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorList;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.carrier.CarrierConstants;
import com.esv.freight.customer.module.carrier.service.CarrierInfoService;
import com.esv.freight.customer.module.vehicle.VehicleConstants;
import com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto;
......@@ -124,8 +125,12 @@ public class VehicleController {
}
VehicleDetailVO vo = new VehicleDetailVO();
BeanUtils.copyProperties(dto, vo);
vo.setCarrierName(carrierInfoService.getCarrierNameById(dto.getCarrierId()));
vo.setCreateTime(dto.getCreateTime().getTime());
if (CarrierConstants.CARRIER_TYPE_COMPANY.equals(dto.getCarrierType())) {
vo.setCarrierName(dto.getCarrierFullName());
} else {
vo.setCarrierName(dto.getCarrierContactor());
}
return EResponse.ok(vo);
}
......
......@@ -17,4 +17,5 @@ public class VehicleDriverServiceImpl extends ServiceImpl<VehicleDriverDao, Vehi
public List<DriverVehicleListVO> getDriverBindVehicleList(Long driverId) {
return this.baseMapper.selectDriverBindVehicleList(driverId);
}
}
\ No newline at end of file
......@@ -41,7 +41,7 @@ public class VehicleDetailVO {
/**
* 车辆状态:1-正常、2-停用
*/
private String vehicleStatus;
private Integer vehicleStatus;
/**
* 审核状态(字典表):0-待审核、1-审核成功,2-审核失败
*/
......
......@@ -193,4 +193,8 @@ error-message:
1021: 司机自主绑定的车辆,平台不可解绑
account-check:
1001: 无效的手机号
1002: 密码错误
\ No newline at end of file
1002: 密码错误
vehicle-check-bind:
1001: 司机与车辆未绑定
1002: 无效的司机ID
1003: 无效的车辆ID
......@@ -25,21 +25,31 @@
<!-- 查询司机详情 -->
<select id="selectDetailById" parameterType="java.lang.Long" resultType="com.esv.freight.customer.module.driver.dto.DriverDetailDto">
select a.*, b.name, b.id_card, b.id_card_expire_date, b.id_card_front_url, b.id_card_back_url, b.settlement_type, b.sex, b.birth_date,
select ab.*, b.name, b.id_card, b.id_card_expire_date, b.id_card_front_url, b.id_card_back_url, b.settlement_type, b.sex, b.birth_date,
b.nation, b.native_place, b.province_code, b.city_code, b.district_code, b.detail_address, b.driving_license, b.driving_license_type,
b.driving_license_start_date, b.driving_license_end_date, b.driving_license_issue_department, b.driving_license_init_date, b.driving_license_url,
b.certificate_vehicle, b.certificate_end_date, b.certificate_number, b.certificate_url, b.remark
from driver_account a, driver_info b
where a.id = b.driver_id and a.id = #{id}
from (
select a.*, c.carrier_type as carrierType, c.carrier_full_name as carrierFullName, c.contactor as carrierContactor
from driver_account a, carrier_info c
where a.carrier_id = c.account_id and a.id = #{id}
) ab
left join driver_info b
on ab.id = b.driver_id
</select>
<select id="selectDetailByAccount" parameterType="java.lang.String" resultType="com.esv.freight.customer.module.driver.dto.DriverDetailDto">
select a.*, b.name, b.id_card, b.id_card_expire_date, b.id_card_front_url, b.id_card_back_url, b.settlement_type, b.sex, b.birth_date,
select ab.*, b.name, b.id_card, b.id_card_expire_date, b.id_card_front_url, b.id_card_back_url, b.settlement_type, b.sex, b.birth_date,
b.nation, b.native_place, b.province_code, b.city_code, b.district_code, b.detail_address, b.driving_license, b.driving_license_type,
b.driving_license_start_date, b.driving_license_end_date, b.driving_license_issue_department, b.driving_license_init_date, b.driving_license_url,
b.certificate_vehicle, b.certificate_end_date, b.certificate_number, b.certificate_url, b.remark
from driver_account a, driver_info b
where a.id = b.driver_id and a.account = #{account}
from (
select a.*, c.carrier_type as carrierType, c.carrier_full_name as carrierFullName, c.contactor as carrierContactor
from driver_account a, carrier_info c
where a.carrier_id = c.account_id and a.account = #{account}
) ab
left join driver_info b
on ab.id = b.driver_id
</select>
<!-- 分页查询司机列表 -->
......
......@@ -57,11 +57,15 @@
<!-- 查询车辆详情 -->
<select id="selectVehicleDetail" parameterType="java.lang.Long" resultType="com.esv.freight.customer.module.vehicle.dto.VehicleDetailDto">
select a.*, b.vehicle_head_url, b.vehicle_head_person_url, b.vehicle_license_front_url,
b.vehicle_license_back_url, b.road_certificate_front_url, b.attached_statement_url
from vehicle a, vehicle_attachment b
where a.id = b.vehicle_id
and a.id = #{id}
select ab.*, b.vehicle_head_url, b.vehicle_head_person_url, b.vehicle_license_front_url,
b.vehicle_license_back_url, b.road_certificate_front_url, b.attached_statement_url
from (
select a.*, c.carrier_type as carrierType, c.carrier_full_name as carrierFullName, c.contactor as carrierContactor
from vehicle a, carrier_info c
where a.carrier_id = c.account_id and a.id = #{id}
) ab
left join vehicle_attachment b
on ab.id = b.vehicle_id
</select>
<!-- 分页查询车辆列表 -->
......
......@@ -41,11 +41,11 @@ import org.springframework.transaction.annotation.Transactional;
public class DriverAccountTest extends BaseTestController {
/**
* 查询司机详情
* 查询司机详情-通过ID
**/
@Test
public void a1_detail_success_test() throws Exception {
String url = "/carrier/driver/detail";
public void a1_getDetailById_success_test() throws Exception {
String url = "/carrier/driver/getDetailById";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
......@@ -68,11 +68,11 @@ public class DriverAccountTest extends BaseTestController {
}
/**
* 查询司机详情:无效的账号ID
* 查询司机详情-通过ID:无效的账号ID
**/
@Test
public void a2_detail_wrong_id_failure_test() throws Exception {
String url = "/carrier/driver/detail";
public void a2_getDetailById_wrong_id_failure_test() throws Exception {
String url = "/carrier/driver/getDetailById";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
......
......@@ -228,4 +228,34 @@ public class DriverVehicleControllerTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1020, result.getIntValue("code"));
}
/**
* 验证司机与车辆是否绑定
**/
@Test
@Rollback
public void d1_checkBind_success_test() throws Exception {
String url = "/carrier/driver/vehicle/checkBind";
// 构造数据
DriverVehicleForm form = new DriverVehicleForm();
form.setDriverId(3L);
form.setVehicleId(4L);
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("driverInfo"));
Assert.assertTrue(result.getJSONObject("data").containsKey("vehicleInfo"));
}
}
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