Commit 74198e4b authored by huangcb's avatar huangcb

增加承运商接口:查询指定车辆可以绑定的司机列表

parent 957d834b
......@@ -225,6 +225,9 @@ public class ErrorMessageComponent {
@Value("${error-message.carrier.driver.driver-list.1002}")
private String carrierDriverDriverList1002;
@Value("${error-message.carrier.driver.vehicle-can-bind.1001}")
private String carrierDriverVehicleCanBind1001;
@Value("${error-message.carrier.driver.vehicle-bind.1001}")
private String carrierDriverVehicleBind1001;
@Value("${error-message.carrier.driver.vehicle-bind.1002}")
......
......@@ -8,6 +8,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.ValidatorCanBind;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorCheckBind;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorUnbind;
import com.esv.freight.customer.module.vehicle.form.VehicleQueryForm;
......@@ -116,4 +117,16 @@ public class DriverVehicleController {
public EResponse listByCarrier(@RequestBody CarrierForm form) throws EException {
return EResponse.ok(driverVehicleService.getDriverVehicle4Carrier(form.getId()));
}
/**
* description 查询指定车辆可以绑定的司机列表
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/05/13 10:49
**/
@PostMapping("/canBindDriver")
public EResponse canBindDriver(@RequestBody @Validated(ValidatorCanBind.class) DriverQueryForm form) throws EException {
return EResponse.ok(driverVehicleService.selectVehicleCanBindDriverList(form));
}
}
......@@ -33,7 +33,7 @@ public class DriverVehicleDto {
/**
* 司机ID
*/
private String driverId;
private Long driverId;
/**
* 司机(帐号)手机号
*/
......@@ -41,15 +41,15 @@ public class DriverVehicleDto {
/**
* 司机帐号状态:1-正常、2-停用
*/
private String driverAccountStatus;
private Integer driverAccountStatus;
/**
* 司机帐号创建来源:1-平台创建、2-自行注册
*/
private String driverSourceType;
private Integer driverSourceType;
/**
* 司机帐号审核状态(字典表):0-待审核、1-审核成功,2-审核失败
*/
private String driverAuditStatus;
private Integer driverAuditStatus;
/**
* 司机姓名
*/
......@@ -57,19 +57,19 @@ public class DriverVehicleDto {
/**
* 车辆ID
*/
private String vehicleId;
private Long vehicleId;
/**
* 车辆状态:1-正常、2-停用
*/
private String vehicleStatus;
private Integer vehicleStatus;
/**
* 车辆审核状态(字典表):0-待审核、1-审核成功,2-审核失败
*/
private String vehicleAuditStatus;
private Integer vehicleAuditStatus;
/**
* 车辆创建来源:1-平台创建、2-司机创建
*/
private String vehicleSourceType;
private Integer vehicleSourceType;
/**
* 车辆车牌号
*/
......
......@@ -2,6 +2,7 @@ package com.esv.freight.customer.module.driver.form;
import com.esv.freight.customer.common.validator.groups.ValidatorDetail;
import com.esv.freight.customer.common.validator.groups.ValidatorList;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorCanBind;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorDetailAccount;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
......@@ -26,7 +27,7 @@ public class DriverQueryForm {
/**
*
*/
@NotNull(message = "参数id不能为空", groups = {ValidatorDetail.class})
@NotNull(message = "参数id不能为空", groups = {ValidatorDetail.class, ValidatorCanBind.class})
private Long id;
/**
* 承运商帐号ID
......@@ -60,20 +61,20 @@ public class DriverQueryForm {
/**
* keywords
*/
@Length(max = 20, message = "参数keywords长度不合法", groups = {ValidatorList.class})
@Length(max = 20, message = "参数keywords长度不合法", groups = {ValidatorList.class, ValidatorCanBind.class})
private String keywords;
/**
* 页码
**/
@Range(min = 1, max = 65535, message = "无效的pageNum", groups = {ValidatorList.class})
@NotNull(message = "参数pageNum不能为空", groups = {ValidatorList.class})
@Range(min = 1, max = 65535, message = "无效的pageNum", groups = {ValidatorList.class, ValidatorCanBind.class})
@NotNull(message = "参数pageNum不能为空", groups = {ValidatorList.class, ValidatorCanBind.class})
private Integer pageNum;
/**
* 每页记录条数
**/
@Range(min = 1, max = 100, message = "pageSize", groups = {ValidatorList.class})
@NotNull(message = "参数pageSize不能为空", groups = {ValidatorList.class})
@Range(min = 1, max = 100, message = "pageSize", groups = {ValidatorList.class, ValidatorCanBind.class})
@NotNull(message = "参数pageSize不能为空", groups = {ValidatorList.class, ValidatorCanBind.class})
private Integer pageSize;
@Override
......
package com.esv.freight.customer.module.driver.service;
import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.common.vo.PageResultVO;
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.vo.CarrierDriverVehicleVO;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import com.esv.freight.customer.module.driver.vo.VehicleCanBindDriverVO;
import com.esv.freight.customer.module.driver.vo.VehicleDriverListVO;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
......@@ -83,4 +86,13 @@ public interface DriverVehicleService {
**/
List<CarrierDriverVehicleVO> getDriverVehicle4Carrier(Long carrierId);
/**
* description 查询车辆可以绑定的司机列表
* param [form]
* return com.esv.freight.customer.common.vo.PageResultVO
* author Administrator
* createTime 2020/05/13 10:37
**/
PageResultVO selectVehicleCanBindDriverList(DriverQueryForm form);
}
......@@ -2,14 +2,18 @@ package com.esv.freight.customer.module.driver.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.common.vo.PageResultVO;
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.dto.DriverVehicleDto;
import com.esv.freight.customer.module.driver.entity.DriverAccountEntity;
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.DriverAccountService;
import com.esv.freight.customer.module.driver.service.DriverVehicleService;
......@@ -21,11 +25,14 @@ 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.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description:
......@@ -262,4 +269,36 @@ public class DriverVehicleServiceImpl implements DriverVehicleService {
return voList;
}
@Override
public PageResultVO selectVehicleCanBindDriverList(DriverQueryForm form) {
// 1:校验是否有效车辆ID
VehicleEntity vehicleEntity = this.vehicleService.getById(form.getId());
if (null == vehicleEntity) {
throw new EException(1001, errorMessageComponent.getCarrierDriverVehicleCanBind1001());
}
// 2:构建查询条件
Map<String, Object> queryObj = new HashMap<>(2);
queryObj.put("vehicleId", form.getId());
queryObj.put("keywords", StringUtils.trimToNull(form.getKeywords()));
// 3:查询
IPage<DriverVehicleDto> page = new Page<>(form.getPageNum(), form.getPageSize());
this.vehicleDriverService.getVehicleCanBindDriverList(page, queryObj);
// 4:数据转换
List<DriverVehicleDto> dtoList = page.getRecords();
List<VehicleCanBindDriverVO> targetRecordList = new ArrayList<>();
for (DriverVehicleDto dto : dtoList) {
VehicleCanBindDriverVO vo = new VehicleCanBindDriverVO();
vo.setId(dto.getDriverId());
vo.setAccount(dto.getDriverAccount());
vo.setName(dto.getDriverName());
targetRecordList.add(vo);
}
return new PageResultVO(page, targetRecordList);
}
}
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.ValidatorCanBind
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorCanBind extends Default {
}
package com.esv.freight.customer.module.driver.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.driver.vo.VehicleCanBindDriverVO
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/07 16:02
* @version:1.0
*/
@Data
public class VehicleCanBindDriverVO {
/**
*
*/
private Long id;
/**
* 登录帐号,司机手机号
*/
private String account;
/**
* 姓名
*/
private String name;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
package com.esv.freight.customer.module.vehicle.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.esv.freight.customer.module.driver.dto.DriverVehicleDto;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import com.esv.freight.customer.module.driver.vo.VehicleDriverListVO;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
import com.esv.freight.customer.module.vehicle.form.VehicleQueryForm;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
/**
* 车辆司机表
......@@ -46,4 +49,13 @@ public interface VehicleDriverDao extends BaseMapper<VehicleDriverEntity> {
**/
List<DriverVehicleDto> selectDriverVehicle4Carrier(Long carrierId);
/**
* description 查询车辆可以绑定的司机列表
* param [page, queryObj]
* return com.baomidou.mybatisplus.core.metadata.IPage
* author Administrator
* createTime 2020/05/13 10:32
**/
IPage selectVehicleCanBindDriverList(IPage page, Map<String, Object> queryObj);
}
package com.esv.freight.customer.module.vehicle.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.driver.dto.DriverVehicleDto;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
......@@ -7,6 +8,7 @@ import com.esv.freight.customer.module.driver.vo.VehicleDriverListVO;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
import java.util.List;
import java.util.Map;
/**
* 车辆司机表
......@@ -44,5 +46,14 @@ public interface VehicleDriverService extends IService<VehicleDriverEntity> {
**/
List<DriverVehicleDto> getDriverVehicle4Carrier(Long carrierId);
/**
* description 查询车辆可以绑定的司机列表
* param [page, queryObj]
* return com.baomidou.mybatisplus.core.metadata.IPage
* author Administrator
* createTime 2020/05/13 10:43
**/
IPage getVehicleCanBindDriverList(IPage page, Map<String, Object> queryObj);
}
package com.esv.freight.customer.module.vehicle.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.module.driver.dto.DriverVehicleDto;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
......@@ -10,6 +11,7 @@ import com.esv.freight.customer.module.vehicle.service.VehicleDriverService;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service("vehicleDriverService")
......@@ -29,4 +31,9 @@ public class VehicleDriverServiceImpl extends ServiceImpl<VehicleDriverDao, Vehi
public List<VehicleDriverListVO> getVehicleBindDriverList(Long vehicleId) {
return this.baseMapper.selectVehicleBindDriverList(vehicleId);
}
@Override
public IPage getVehicleCanBindDriverList(IPage page, Map<String, Object> queryObj) {
return this.baseMapper.selectVehicleCanBindDriverList(page, queryObj);
}
}
\ No newline at end of file
......@@ -191,6 +191,8 @@ error-message:
driver-list:
1001: 无效的车辆ID
1002: 该车辆未绑定司机
vehicle-can-bind:
1001: 无效的车辆ID
vehicle-bind:
1001: 无效的司机ID
1002: 司机帐号已停用
......
......@@ -191,6 +191,8 @@ error-message:
driver-list:
1001: 无效的车辆ID
1002: 该车辆未绑定司机
vehicle-can-bind:
1001: 无效的车辆ID
vehicle-bind:
1001: 无效的司机ID
1002: 司机帐号已停用
......
......@@ -40,6 +40,23 @@
order by ab.account asc
</select>
<!-- 查询车辆可以绑定的司机列表 -->
<select id="selectVehicleCanBindDriverList" parameterType="java.util.Map" resultType="com.esv.freight.customer.module.driver.dto.DriverVehicleDto">
select a.id as driverId, a.account as driverAccount, a.account_status as driverAccountStatus, a.carrier_id as carrierId,
b.name as driverName
from driver_account a, driver_info b
where a.id = b.driver_id
and a.account_status = 1
and a.audit_status = 1
<if test="queryObj.keywords != null">
and (a.account like CONCAT('%', #{queryObj.keywords}, '%')
or b.name like CONCAT('%', #{queryObj.keywords}, '%'))
</if>
and a.id not in (select vd.driver_id from vehicle_driver vd where vd.vehicle_id = #{queryObj.vehicleId})
and a.carrier_id = (select v.carrier_id from vehicle v where v.id = #{queryObj.vehicleId})
order by a.account asc
</select>
<!-- 查询指定承运商的司机与车辆绑定列表 -->
<select id="selectDriverVehicle4Carrier" parameterType="java.lang.Long" resultType="com.esv.freight.customer.module.driver.dto.DriverVehicleDto">
select ab.*,
......
......@@ -419,4 +419,63 @@ public class DriverVehicleControllerTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1002, result.getIntValue("code"));
}
/**
* 查询指定车辆可以绑定的司机列表
**/
@Test
public void g1_canBindDriver_success_test() throws Exception {
String url = "/carrier/driver/vehicle/canBindDriver";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(3L);
form.setKeywords("1");
form.setPageNum(1);
form.setPageSize(10);
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(null != result.getJSONObject("data"));
}
/**
* 查询指定车辆可以绑定的司机列表:错误的车辆ID
**/
@Test
public void g2_canBindDriver_wrong_id_failure_test() throws Exception {
String url = "/carrier/driver/vehicle/canBindDriver";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(99999L);
form.setKeywords("1");
form.setPageNum(1);
form.setPageSize(10);
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