Commit 6d2ece09 authored by huangcb's avatar huangcb

承运商接口:查询司机绑定的车辆列表

parent e3023535
...@@ -213,4 +213,9 @@ public class ErrorMessageComponent { ...@@ -213,4 +213,9 @@ public class ErrorMessageComponent {
@Value("${error-message.carrier.driver.audit-history.1001}") @Value("${error-message.carrier.driver.audit-history.1001}")
private String carrierDriverAuditHistory1001; private String carrierDriverAuditHistory1001;
@Value("${error-message.carrier.driver.vehicle-list.1001}")
private String carrierDriverVehicleList1001;
@Value("${error-message.carrier.driver.vehicle-list.1002}")
private String carrierDriverVehicleList1002;
} }
package com.esv.freight.customer.module.driver.controller;
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.service.DriverVehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.driver.controller.DriverVehicleController
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/29 19:14
* @version:1.0
*/
@Slf4j
@RestController
@RequestMapping("/carrier/driver/vehicle")
@Validated
public class DriverVehicleController {
private DriverVehicleService driverVehicleService;
@Autowired
public DriverVehicleController(DriverVehicleService driverVehicleService) {
this.driverVehicleService = driverVehicleService;
}
/**
* description 查询司机绑定的车辆列表
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/29 19:16
**/
@PostMapping("/list")
public EResponse list(@RequestBody @Validated(ValidatorDetail.class) DriverQueryForm form) throws EException {
return EResponse.ok(driverVehicleService.getDriverBindVehicleList(form.getId()));
}
}
package com.esv.freight.customer.module.driver.service;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import java.util.List;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.driver.service.DriverVehicleService
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/29 16:51
* @version:1.0
*/
public interface DriverVehicleService {
/**
* description 获取司机绑定的车辆列表
* param [id]
* return java.util.List<com.esv.freight.customer.module.driver.vo.DriverVehicleListVO>
* author Administrator
* createTime 2020/04/29 16:55
**/
List<DriverVehicleListVO> getDriverBindVehicleList(Long id);
}
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.module.driver.entity.DriverAccountEntity;
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.service.VehicleDriverService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.driver.service.impl.DriverVehicleServiceImpl
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/29 16:55
* @version:1.0
*/
@Service("driverVehicleService")
public class DriverVehicleServiceImpl implements DriverVehicleService {
private ErrorMessageComponent errorMessageComponent;
private DriverAccountService driverAccountService;
private VehicleDriverService vehicleDriverService;
public DriverVehicleServiceImpl(ErrorMessageComponent errorMessageComponent, DriverAccountService driverAccountService,
VehicleDriverService vehicleDriverService) {
this.errorMessageComponent = errorMessageComponent;
this.driverAccountService = driverAccountService;
this.vehicleDriverService = vehicleDriverService;
}
@Override
public List<DriverVehicleListVO> getDriverBindVehicleList(Long id) {
// 1:校验是否有效司机ID
int count = this.driverAccountService.getBaseMapper().selectCount(new QueryWrapper<DriverAccountEntity>().lambda()
.eq(DriverAccountEntity::getId, id));
if (0 == count) {
throw new EException(1001, errorMessageComponent.getCarrierDriverVehicleList1001());
}
// 2:查询司机绑定的车辆列表
List<DriverVehicleListVO> voList = this.vehicleDriverService.getDriverBindVehicleList(id);
if (0 == voList.size()) {
throw new EException(1002, errorMessageComponent.getCarrierDriverVehicleList1002());
}
return voList;
}
}
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.DriverVehicleListVO
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/29 16:52
* @version:1.0
*/
@Data
public class DriverVehicleListVO {
/**
*
*/
private Long id;
/**
* 车牌号
*/
private String licenseNumber;
/**
* 车辆状态:1-正常、2-停用
*/
private Integer vehicleStatus;
/**
* 审核状态(字典表):0-待审核、1-审核成功,2-审核失败
*/
private Integer auditStatus;
/**
* 创建来源:1-平台创建、2-司机创建
*/
private Integer sourceType;
/**
* 是否默认车辆:0-不是、1-是
*/
private Integer selected;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
package com.esv.freight.customer.module.vehicle.dao; package com.esv.freight.customer.module.vehicle.dao;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* 车辆司机表 * 车辆司机表
* *
...@@ -13,5 +16,14 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -13,5 +16,14 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface VehicleDriverDao extends BaseMapper<VehicleDriverEntity> { public interface VehicleDriverDao extends BaseMapper<VehicleDriverEntity> {
/**
* description 查询司机绑定的车辆列表
* param [driverId]
* return java.util.List<com.esv.freight.customer.module.driver.vo.DriverVehicleListVO>
* author Administrator
* createTime 2020/04/29 17:54
**/
List<DriverVehicleListVO> selectDriverBindVehicleList(Long driverId);
} }
package com.esv.freight.customer.module.vehicle.service; package com.esv.freight.customer.module.vehicle.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity; import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
import java.util.List;
/** /**
* 车辆司机表 * 车辆司机表
* *
...@@ -12,5 +15,14 @@ import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity; ...@@ -12,5 +15,14 @@ import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
*/ */
public interface VehicleDriverService extends IService<VehicleDriverEntity> { public interface VehicleDriverService extends IService<VehicleDriverEntity> {
/**
* description 查询司机绑定的车辆列表
* param [driverId]
* return java.util.List<com.esv.freight.customer.module.driver.vo.DriverVehicleListVO>
* author Administrator
* createTime 2020/04/29 18:00
**/
List<DriverVehicleListVO> getDriverBindVehicleList(Long driverId);
} }
package com.esv.freight.customer.module.vehicle.service.impl; package com.esv.freight.customer.module.vehicle.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.module.driver.vo.DriverVehicleListVO;
import com.esv.freight.customer.module.vehicle.dao.VehicleDriverDao; import com.esv.freight.customer.module.vehicle.dao.VehicleDriverDao;
import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity; import com.esv.freight.customer.module.vehicle.entity.VehicleDriverEntity;
import com.esv.freight.customer.module.vehicle.service.VehicleDriverService; import com.esv.freight.customer.module.vehicle.service.VehicleDriverService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service("vehicleDriverService") @Service("vehicleDriverService")
public class VehicleDriverServiceImpl extends ServiceImpl<VehicleDriverDao, VehicleDriverEntity> implements VehicleDriverService { public class VehicleDriverServiceImpl extends ServiceImpl<VehicleDriverDao, VehicleDriverEntity> implements VehicleDriverService {
@Override
public List<DriverVehicleListVO> getDriverBindVehicleList(Long driverId) {
return this.baseMapper.selectDriverBindVehicleList(driverId);
}
} }
\ No newline at end of file
...@@ -171,4 +171,7 @@ error-message: ...@@ -171,4 +171,7 @@ error-message:
1001: 帐号已存在 1001: 帐号已存在
1002: 无效的承运商ID​ 1002: 无效的承运商ID​
audit-history: audit-history:
1001: 无效的账号ID 1001: 无效的账号ID
\ No newline at end of file vehicle-list:
1001: 无效的司机ID
1002: 该司机未绑定车辆
\ No newline at end of file
...@@ -16,5 +16,14 @@ ...@@ -16,5 +16,14 @@
<result property="operateTime" column="operate_time"/> <result property="operateTime" column="operate_time"/>
</resultMap> </resultMap>
<!-- 查询司机绑定的车辆列表 -->
<select id="selectDriverBindVehicleList" parameterType="java.lang.Long" resultType="com.esv.freight.customer.module.driver.vo.DriverVehicleListVO">
select a.id, a.license_number, a.vehicle_status, a.audit_status, a.source_type,
b.selected
from vehicle a, vehicle_driver b
where a.deleted = false and a.id = b.vehicle_id
and b.driver_id = #{driverId}
order by b.selected desc
</select>
</mapper> </mapper>
\ No newline at end of file
package com.esv.freight.customer.module.driver.controller;
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 lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.transaction.annotation.Transactional;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.driver.controller.DriverVehicleControllerTest
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/29 19:17
* @version:1.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback(false)
public class DriverVehicleControllerTest extends BaseTestController {
/**
* 查询司机绑定的车辆列表
**/
@Test
public void a1_list_success_test() throws Exception {
String url = "/carrier/driver/vehicle/list";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
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"));
Assert.assertTrue(null != result.getJSONArray("data"));
}
/**
* 查询司机绑定的车辆列表:无效的司机ID
**/
@Test
public void a2_list_wrong_id_failure_test() throws Exception {
String url = "/carrier/driver/vehicle/list";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
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
public void a3_list_not_bind_vehicle_failure_test() throws Exception {
String url = "/carrier/driver/vehicle/list";
// 构造数据
DriverQueryForm form = new DriverQueryForm();
form.setId(2L);
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