Commit 1368af06 authored by huangcb's avatar huangcb

承运商接口:司机帐号密码校验

parent e1efd106
......@@ -244,4 +244,9 @@ public class ErrorMessageComponent {
private String carrierDriverVehicleUnbind1020;
@Value("${error-message.carrier.driver.vehicle-unbind.1021}")
private String carrierDriverVehicleUnbind1021;
@Value("${error-message.carrier.driver.account-check.1001}")
private String carrierDriverAccountCheck1001;
@Value("${error-message.carrier.driver.account-check.1002}")
private String carrierDriverAccountCheck1002;
}
......@@ -2,6 +2,7 @@ package com.esv.freight.customer.module.driver.controller;
import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.component.PasswordComponent;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.common.response.EResponse;
......@@ -18,6 +19,8 @@ import com.esv.freight.customer.module.driver.form.DriverAuditForm;
import com.esv.freight.customer.module.driver.form.DriverInfoForm;
import com.esv.freight.customer.module.driver.form.DriverQueryForm;
import com.esv.freight.customer.module.driver.service.DriverAccountService;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorDetailAccount;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorLogin;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorRegister;
import com.esv.freight.customer.module.driver.vo.DriverAuditHistoryVO;
import com.esv.freight.customer.module.driver.vo.DriverDetailVO;
......@@ -51,11 +54,15 @@ public class DriverController {
private ErrorMessageComponent errorMessageComponent;
private PasswordComponent passwordComponent;
private DriverAccountService driverAccountService;
@Autowired
public DriverController(ErrorMessageComponent errorMessageComponent, DriverAccountService driverAccountService) {
public DriverController(ErrorMessageComponent errorMessageComponent, PasswordComponent passwordComponent,
DriverAccountService driverAccountService) {
this.errorMessageComponent = errorMessageComponent;
this.passwordComponent = passwordComponent;
this.driverAccountService = driverAccountService;
}
......@@ -112,7 +119,7 @@ public class DriverController {
}
/**
* description 查询司机详情
* description 查询司机详情-通过ID
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
......@@ -120,7 +127,29 @@ public class DriverController {
**/
@PostMapping("/detail")
public EResponse detail(@RequestBody @Validated(ValidatorDetail.class) DriverQueryForm form) throws EException {
DriverDetailDto dto = driverAccountService.getDriverDetail(form.getId());
DriverDetailDto dto = driverAccountService.getDriverDetailById(form.getId());
if (null == dto) {
throw new EException(1001, errorMessageComponent.getCarrierDriverDetail1001());
}
// 数据转换
DriverDetailVO vo = new DriverDetailVO();
BeanUtils.copyProperties(dto, vo);
vo.setCreateTime(dto.getCreateTime().getTime());
return EResponse.ok(vo);
}
/**
* description 查询司机详情-通过帐号
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/28 20:26
**/
@PostMapping("/detailByAccount")
public EResponse detailByAccount(@RequestBody @Validated(ValidatorDetailAccount.class) DriverQueryForm form) throws EException {
DriverDetailDto dto = driverAccountService.getDriverDetailByAccount(form.getAccount());
if (null == dto) {
throw new EException(1001, errorMessageComponent.getCarrierDriverDetail1001());
}
......@@ -229,4 +258,33 @@ public class DriverController {
public EResponse list(@RequestBody @Validated(ValidatorList.class) DriverQueryForm form) throws EException {
return EResponse.ok(driverAccountService.getDriver4Page(form));
}
/**
* description 帐号密码校验
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/30 11:14
**/
@PostMapping("/account/check")
public EResponse accountCheck(@RequestBody @Validated(ValidatorLogin.class) DriverInfoForm form) throws EException {
// 查询司机详情-通过帐号
DriverDetailDto dto = driverAccountService.getDriverDetailByAccount(form.getAccount());
// 校验
if (null == dto) {
throw new EException(1001, errorMessageComponent.getCarrierDriverAccountCheck1001());
}
String password = passwordComponent.generatePwd4Salt(form.getPassword(), dto.getSalt());
if (!password.equals(dto.getPassword())) {
throw new EException(1002, errorMessageComponent.getCarrierDriverAccountCheck1002());
}
// 数据转换
DriverDetailVO vo = new DriverDetailVO();
BeanUtils.copyProperties(dto, vo);
vo.setCreateTime(dto.getCreateTime().getTime());
return EResponse.ok(vo);
}
}
......@@ -19,13 +19,22 @@ import org.apache.ibatis.annotations.Mapper;
public interface DriverAccountDao extends BaseMapper<DriverAccountEntity> {
/**
* description 查询司机详情
* description 查询司机详情-通过ID
* param [id]
* return com.esv.freight.customer.module.driver.dto.DriverDetailDto
* author Administrator
* createTime 2020/04/28 20:21
**/
DriverDetailDto selectDriverDetail(Long id);
DriverDetailDto selectDetailById(Long id);
/**
* description 查询司机详情-通过帐号
* param [account]
* return com.esv.freight.customer.module.driver.dto.DriverDetailDto
* author Administrator
* createTime 2020/04/30 11:24
**/
DriverDetailDto selectDetailByAccount(String account);
/**
* description 分页查询司机列表
......
......@@ -2,6 +2,7 @@ package com.esv.freight.customer.module.driver.form;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorLogin;
import com.esv.freight.customer.module.driver.validator.groups.ValidatorRegister;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
......@@ -37,14 +38,14 @@ public class DriverInfoForm {
/**
* 登录帐号,司机手机号
*/
@Length(min = 11, max = 11, message = "参数account长度不合法", groups = {ValidatorInsert.class, ValidatorRegister.class})
@NotBlank(message = "参数account不能为空", groups = {ValidatorInsert.class})
@Length(min = 11, max = 11, message = "参数account长度不合法", groups = {ValidatorInsert.class, ValidatorRegister.class, ValidatorLogin.class})
@NotBlank(message = "参数account不能为空", groups = {ValidatorInsert.class, ValidatorLogin.class})
private String account;
/**
* 密码
*/
@Length(min = 32, max = 32, message = "参数password长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@NotBlank(message = "参数password不能为空", groups = {ValidatorInsert.class})
@Length(min = 32, max = 32, message = "参数password长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class, ValidatorLogin.class})
@NotBlank(message = "参数password不能为空", groups = {ValidatorInsert.class, ValidatorLogin.class})
private String password;
/**
* 帐号状态:1-正常、2-停用
......
......@@ -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.ValidatorDetailAccount;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
......@@ -54,7 +55,7 @@ public class DriverQueryForm {
/**
* 登录帐号,司机手机号
*/
@Length(max = 11, message = "参数account长度不合法", groups = {ValidatorList.class})
@Length(max = 11, message = "参数account长度不合法", groups = {ValidatorList.class, ValidatorDetailAccount.class})
private String account;
/**
* keywords
......
......@@ -39,13 +39,22 @@ public interface DriverAccountService extends IService<DriverAccountEntity> {
Integer updateDriver(DriverInfoForm form);
/**
* description 查询司机详情
* description 查询司机详情-通过ID
* param [id]
* return com.esv.freight.customer.module.driver.dto.DriverDetailDto
* author Administrator
* createTime 2020/04/28 20:22
**/
DriverDetailDto getDriverDetail(Long id);
DriverDetailDto getDriverDetailById(Long id);
/**
* description 查询司机详情-通过帐号
* param [account]
* return com.esv.freight.customer.module.driver.dto.DriverDetailDto
* author Administrator
* createTime 2020/04/30 11:30
**/
DriverDetailDto getDriverDetailByAccount(String account);
/**
* description 审核司机信息
......@@ -101,5 +110,14 @@ public interface DriverAccountService extends IService<DriverAccountEntity> {
**/
PageResultVO getDriver4Page(DriverQueryForm queryObj);
/**
* description 帐号密码校验
* param [form]
* return com.esv.freight.customer.module.driver.dto.DriverDetailDto
* author Administrator
* createTime 2020/04/30 11:21
**/
DriverDetailDto checkAccount(DriverInfoForm form);
}
......@@ -11,10 +11,8 @@ 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.carrier.dto.CarrierInfoDto;
import com.esv.freight.customer.module.carrier.entity.CarrierAccountEntity;
import com.esv.freight.customer.module.carrier.service.CarrierAccountService;
import com.esv.freight.customer.module.carrier.vo.CarrierInfoListVO;
import com.esv.freight.customer.module.driver.DriverConstants;
import com.esv.freight.customer.module.driver.dao.DriverAccountDao;
import com.esv.freight.customer.module.driver.dto.DriverDetailDto;
......@@ -179,8 +177,13 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
}
@Override
public DriverDetailDto getDriverDetail(Long id) {
return this.baseMapper.selectDriverDetail(id);
public DriverDetailDto getDriverDetailById(Long id) {
return this.baseMapper.selectDetailById(id);
}
@Override
public DriverDetailDto getDriverDetailByAccount(String account) {
return this.baseMapper.selectDetailByAccount(account);
}
@Override
......@@ -329,4 +332,9 @@ public class DriverAccountServiceImpl extends ServiceImpl<DriverAccountDao, Driv
return new PageResultVO(page, targetRecordList);
}
@Override
public DriverDetailDto checkAccount(DriverInfoForm form) {
return null;
}
}
\ No newline at end of file
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.ValidatorDetailAccount
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorDetailAccount 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.ValidatorLogin
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/03/12 17:58
* @version:1.0
*/
public interface ValidatorLogin extends Default {
}
......@@ -188,4 +188,7 @@ error-message:
1001: 无效的司机ID
1010: 无效的车辆ID
1020: 车辆与司机未绑定
1021: 司机自主绑定的车辆,平台不可解绑
\ No newline at end of file
1021: 司机自主绑定的车辆,平台不可解绑
account-check:
1001: 无效的手机号
1002: 密码错误
\ No newline at end of file
......@@ -24,7 +24,7 @@
</resultMap>
<!-- 查询司机详情 -->
<select id="selectDriverDetail" parameterType="java.lang.Long" resultType="com.esv.freight.customer.module.driver.dto.DriverDetailDto">
<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,
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,
......@@ -33,6 +33,15 @@
where a.id = b.driver_id and a.id = #{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,
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}
</select>
<!-- 分页查询司机列表 -->
<select id="selectDriver4Page" parameterType="com.esv.freight.customer.module.driver.form.DriverQueryForm"
resultType="com.esv.freight.customer.module.driver.dto.DriverDetailDto">
......
......@@ -562,4 +562,85 @@ public class DriverAccountTest extends BaseTestController {
Assert.assertTrue(result.getJSONObject("data").containsKey("records"));
}
/**
* 帐号密码校验
**/
@Test
public void g1_accountCheck_success_test() throws Exception {
String url = "/carrier/driver/account/check";
// 构造数据
DriverInfoForm form = new DriverInfoForm();
form.setAccount("18512340001");
form.setPassword("e10adc3949ba59abbe56e057f20f883e");
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("id"));
}
/**
* 帐号密码校验:无效的手机号
**/
@Test
public void g2_accountCheck_wrong_account_failure_test() throws Exception {
String url = "/carrier/driver/account/check";
// 构造数据
DriverInfoForm form = new DriverInfoForm();
form.setAccount("18912340001");
form.setPassword("e10adc3949ba59abbe56e057f20f883e");
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"));
}
/**
* 帐号密码校验:密码错误
**/
@Test
public void g3_accountCheck_wrong_password_failure_test() throws Exception {
String url = "/carrier/driver/account/check";
// 构造数据
DriverInfoForm form = new DriverInfoForm();
form.setAccount("18512340001");
form.setPassword("f10adc3949ba59abbe56e057f20f883e");
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(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