Commit 4c19a6e9 by 牟邦恺

调整驾驶证信息

parent d9ed238c
......@@ -6,14 +6,24 @@ import com.hikcreate.common.sdk.response.apiparam.ResponseGenerator;
import com.hikcreate.common.sdk.response.statuscode.StatusCode;
import com.hikcreate.edl.common.image.builder.domain.DlImageDO;
import com.hikcreate.edl.pub.web.mobile.domain.CredentialsImageService;
import com.hikcreate.edl.pub.web.mobile.domain.DrivingLicenseService;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultGenerator;
import com.hikcreate.edl.pub.web.mobile.infra.core.annotatiion.HeaderDecryptAnnotation;
import com.hikcreate.edl.pub.web.mobile.infra.core.configbean.FastDfsConfigBean;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.DrivingLicenseFeign;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.request.CreditIdCardMicReq;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.response.DrivingLicenseMicRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.DrivingLicenseSendSmsCodeReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.DrivingLicenseValidReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.DrivingLicenseValidSmsCodeReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.DrivingLicenseValidRes;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
......@@ -33,15 +43,38 @@ import java.io.IOException;
@RequestMapping("/drivingLicense")
@Slf4j
public class DrivingLicenseController {
@Autowired
private CredentialsImageService credentialsImageService;
@Autowired
private DrivingLicenseFeign drivingLicenseFeign;
@Autowired
private FastDfsConfigBean fastDfsConfigBean;
@Autowired
private DrivingLicenseService drivingLicenseService;
@GetMapping("/image")
@PostMapping("/valid")
@HeaderDecryptAnnotation
public Result<DrivingLicenseValidRes> valid(@RequestBody @Validated DrivingLicenseValidReq req) {
DrivingLicenseValidRes drivingLicenseValidRes = drivingLicenseService.checkIdCard(req.getIdCard(), req.getUserId());
return ResultGenerator.success(drivingLicenseValidRes);
}
@PostMapping("/sendSmsCode")
@HeaderDecryptAnnotation
public Result<Void> sendSmsCode(@RequestBody @Validated DrivingLicenseSendSmsCodeReq req) {
drivingLicenseService.sendSmsCode(req.getUserId());
return ResultGenerator.success();
}
@PostMapping("/validSmsCode")
@HeaderDecryptAnnotation
public Result<Void> validSmsCode(@RequestBody @Validated DrivingLicenseValidSmsCodeReq req) {
drivingLicenseService.validSmsCode(req.getUserId(), req.getSmsCode());
return ResultGenerator.success();
}
@GetMapping("/image")
public void image(@RequestParam("idCard") String idCard, HttpServletResponse response) {
DrivingLicenseMicRes drivingLicenseMicRes = drivingLicenseFeign.getByIdCard(new CreditIdCardMicReq().setIdCard(idCard)).fallback().getData();
DlImageDO dlImageDO = new DlImageDO();
......@@ -78,6 +111,7 @@ public class DrivingLicenseController {
}
}
private void getResException(HttpServletResponse response, String msg) {
try {
Response<Void> res = ResponseGenerator.fail(StatusCode.SYSTEM_ERROR, msg);
......
......@@ -114,7 +114,7 @@ public class H5Controller {
*/
@PostMapping( "drivingLicenseInfo" )
@HeaderDecryptAnnotation
public Result<DrivingLicenseInfoRes> drivingLicenseInfo( @RequestBody @Validated H5BindInfoQuery query ) {
public Result<VehicleDrivingLicenseInfoRes> drivingLicenseInfo( @RequestBody @Validated H5BindInfoQuery query ) {
return service.drivingLicenseInfo(query);
}
......
package com.hikcreate.edl.pub.web.mobile.domain;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.DrivingLicenseValidRes;
/**
* @author MOUBK
* @create 2020/7/21 14:02
*/
public interface DrivingLicenseService {
DrivingLicenseValidRes checkIdCard(String idCard, String userId);
void sendSmsCode(String userId);
void validSmsCode(String userId, String smsCode);
}
package com.hikcreate.edl.pub.web.mobile.domain;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hikcreate.common.sdk.response.apiparam.Response;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result;
import com.hikcreate.edl.pub.web.mobile.infra.model.entity.ParkBindInfo;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindInfoQueryReq;
......@@ -9,7 +8,7 @@ import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindSmsValidRe
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.H5BindInfoQuery;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.UnBindReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.BindInfoQueryRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.DrivingLicenseInfoRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.VehicleDrivingLicenseInfoRes;
import java.util.List;
......@@ -86,6 +85,6 @@ public interface IBindService extends IService<ParkBindInfo> {
* @author: xsx
* @date: 2020/6/19 16:29
*/
Result<DrivingLicenseInfoRes> drivingLicenseInfo( H5BindInfoQuery query);
Result<VehicleDrivingLicenseInfoRes> drivingLicenseInfo(H5BindInfoQuery query);
}
......@@ -43,9 +43,9 @@ import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.H5BindInfoQuer
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.UnBindReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.BindInfoQueryRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.BindInfoRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.DrivingLicenseInfoRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.InsuranceInfoRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.ResultList;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.VehicleDrivingLicenseInfoRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.ViolationInfoRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.YearCheckInfoRes;
import lombok.extern.slf4j.Slf4j;
......@@ -418,7 +418,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
}
@Override
public Result<DrivingLicenseInfoRes> drivingLicenseInfo(H5BindInfoQuery query) {
public Result<VehicleDrivingLicenseInfoRes> drivingLicenseInfo(H5BindInfoQuery query) {
/**
* 校验当前的绑定信息是否存在
*/
......@@ -470,7 +470,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, ParkBindInfo> i
/**
* 构建驾照信息查询结果
*/
DrivingLicenseInfoRes result = new DrivingLicenseInfoRes();
VehicleDrivingLicenseInfoRes result = new VehicleDrivingLicenseInfoRes();
result.setDriverName(drivingLicenseRes.getXm());
result.setPlateNum(byPlateNumAndType.getHphm());
result.setDlQr(qrInfo.getData().getQr());
......
package com.hikcreate.edl.pub.web.mobile.domain.impl;
import com.alibaba.fastjson.JSONObject;
import com.hikcreate.common.sdk.exception.BusinessException;
import com.hikcreate.edl.common.sdk.util.VerifyCodeUtil;
import com.hikcreate.edl.pub.web.mobile.domain.DrivingLicenseService;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultCode;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pub_service_sms.SmsFeign;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pub_service_sms.param.request.CheckVerifyCodeMicReq;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pub_service_sms.param.request.SendVerifyCodeMicReq;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.DrivingLicenseFeign;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.request.CreditIdCardMicReq;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.response.DrivingLicenseMicRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.DrivingLicenseValidRes;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* @author MOUBK
* @create 2020/7/21 14:03
*/
@Slf4j
@Service
public class DrivingLicenseServiceImpl implements DrivingLicenseService {
@Autowired
private DrivingLicenseFeign drivingLicenseFeign;
@Autowired
private SmsFeign smsFeign;
@Autowired
private RedisTemplate<String, String> redisTemplate;
private static final String REDIS_KEY = "drv:idcard";
private static final String REDIS_SMS_KEY = "drv:idcard:sms";
@Override
public DrivingLicenseValidRes checkIdCard(String idCard, String userId) {
DrivingLicenseMicRes drivingLicenseMicRes = drivingLicenseFeign.getByIdCard(new CreditIdCardMicReq().setIdCard(idCard)).fallback().getData();
if (drivingLicenseMicRes == null) {
throw new BusinessException(ResultCode.DRIVING_LICENSE_UNKNOWN);
}
// 保存在缓存
saveToRedis(userId, drivingLicenseMicRes);
DrivingLicenseValidRes drivingLicenseValidRes = new DrivingLicenseValidRes();
drivingLicenseValidRes.setUserId(userId);
drivingLicenseValidRes.setPhone(drivingLicenseMicRes.getPhone());
// 检查短信发送
if (checkSmsValid(userId, idCard, drivingLicenseMicRes.getPhone())) {
drivingLicenseValidRes.setSendSmsFlag(true);
} else {
drivingLicenseValidRes.setSendSmsFlag(false);
}
return drivingLicenseValidRes;
}
@Override
public void sendSmsCode(String userId) {
DrivingLicenseMicRes drivingLicenseMicRes = getFromRedis(userId);
SendVerifyCodeMicReq micReq = new SendVerifyCodeMicReq();
micReq.setPhone(drivingLicenseMicRes.getPhone());
micReq.setVerifyCode(VerifyCodeUtil.getCode());
micReq.setTemplateCode("PARK_DRIVING_LICENSE_IDCARD");
smsFeign.sendVerifyCode(micReq).fallback();
}
@Override
public void validSmsCode(String userId, String smsCode) {
DrivingLicenseMicRes drivingLicenseMicRes = getFromRedis(userId);
CheckVerifyCodeMicReq req = new CheckVerifyCodeMicReq();
req.setPhone(drivingLicenseMicRes.getPhone());
req.setVerifyCode(smsCode);
req.setTemplateCode("PARK_DRIVING_LICENSE_IDCARD");
smsFeign.checkVerifyCode(req).fallback();
// 保存验证redis
saveSmsValid(userId, drivingLicenseMicRes.getIdCard(), drivingLicenseMicRes.getPhone());
}
private void saveSmsValid(String userId, String idCard, String phone) {
redisTemplate.opsForValue().set(getSmsKey(userId, idCard), phone, 300, TimeUnit.SECONDS);
}
private boolean checkSmsValid(String userId, String idCard, String phone) {
String value = redisTemplate.opsForValue().get(getSmsKey(userId, idCard));
if (Objects.equals(phone, value)) {
return true;
}
return false;
}
private String getSmsKey(String userId, String idCard) {
return REDIS_SMS_KEY + userId + ":" + idCard;
}
private void saveToRedis(String userId, DrivingLicenseMicRes drivingLicenseMicRes) {
redisTemplate.opsForValue().set(getKey(userId), JSONObject.toJSONString(drivingLicenseMicRes), 24 * 3600, TimeUnit.SECONDS);
}
private DrivingLicenseMicRes getFromRedis(String userId) {
String value = redisTemplate.opsForValue().get(getKey(userId));
if (!StringUtils.isEmpty(value)) {
return JSONObject.parseObject(value, DrivingLicenseMicRes.class);
}
return null;
}
private String getKey(String userId) {
return REDIS_KEY + userId;
}
}
package com.hikcreate.edl.pub.web.mobile.infra.model.param.request;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author MOUBK
* @create 2020/7/21 15:17
*/
@Data
public class DrivingLicenseSendSmsCodeReq {
@NotBlank(message = "手机号不能为空")
private String userId;
}
package com.hikcreate.edl.pub.web.mobile.infra.model.param.request;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author MOUBK
* @create 2020/7/21 11:24
*/
@Data
public class DrivingLicenseValidReq {
@NotBlank(message = "驾驶证号不能为空")
private String idCard;
@NotBlank(message = "用户Id不能为空")
private String userId;
private Long timestamp;
}
package com.hikcreate.edl.pub.web.mobile.infra.model.param.request;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author MOUBK
* @create 2020/7/21 15:17
*/
@Data
public class DrivingLicenseValidSmsCodeReq {
@NotBlank(message = "手机号不能为空")
private String userId;
@NotBlank(message = "手机验证码不能为空")
private String smsCode;
}
......@@ -9,10 +9,7 @@ import lombok.Data;
@Data
public class DrivingLicenseInfoRes {
/**
* 车牌号
*/
private String plateNum;
/**
*有效期止
*/
......
package com.hikcreate.edl.pub.web.mobile.infra.model.param.response;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author MOUBK
* @create 2020/7/21 11:26
*/
@Data
@Accessors(chain = true)
public class DrivingLicenseValidRes {
private String phone;
private String userId;
private Boolean sendSmsFlag;
}
package com.hikcreate.edl.pub.web.mobile.infra.model.param.response;
import lombok.Data;
/**
* @author MOUBK
* @create 2019/7/5 15:31
*/
@Data
public class VehicleDrivingLicenseInfoRes extends DrivingLicenseInfoRes {
/**
* 车牌号
*/
private String plateNum;
}
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