Commit 83df66ae by 牟邦恺

Merge branch 'feature-20200720' into 'master'

Feature 20200720

See merge request !35
parents 7ae0c35a 45185eda
......@@ -64,6 +64,7 @@
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
<build>
......
package com.hikcreate.edl.pub.web.mobile.api.controller;
import com.hikcreate.common.orika.DefaultConverter;
import com.hikcreate.common.sdk.response.statuscode.StatusCode;
import com.hikcreate.edl.common.distributed.lock.exception.DistributedLockException;
import com.hikcreate.edl.pub.web.mobile.domain.IBindService;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultCode;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultGenerator;
import com.hikcreate.edl.pub.web.mobile.infra.core.annotatiion.BodyDecryptAnnotation;
import com.hikcreate.edl.pub.web.mobile.infra.core.annotatiion.ResponseEncryptAnnotation;
import com.hikcreate.edl.pub.web.mobile.infra.model.entity.ParkBindInfo;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.AdminUnbindReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.AdminUnbindSmsValidReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindInfoQueryReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindInfoReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.BindSmsValidReq;
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;
......@@ -38,9 +38,6 @@ public class BindInfoControlller extends BaseController {
@Autowired
IBindService service;
@Autowired
DefaultConverter defaultConverter;
/**
* 绑定用户信息的接口
......@@ -53,22 +50,39 @@ public class BindInfoControlller extends BaseController {
@PostMapping( "bind" )
@BodyDecryptAnnotation
@ResponseEncryptAnnotation
public Result<BindInfoRes> bindInfo( @RequestBody @Validated BindInfoReq req ) {
ParkBindInfo bindInfo = new ParkBindInfo();
defaultConverter.getMapperFacade().map(req, bindInfo);
public Result bindInfo( @RequestBody @Validated BindInfoReq req ) {
Result response = null;
try {
response = service.bind(bindInfo);
response = service.bind(req);
} catch ( DistributedLockException e ) {
log.error("分布式锁超时");
return ResultGenerator.fail(StatusCode.REPEAT_SUBMIT);
} catch ( Exception e ) {
log.error("系统异常:{}", e);
return ResultGenerator.fail(StatusCode.SYSTEM_ERROR);
}
// catch ( Exception e ) {
// log.error("系统异常:{}", e);
// return ResultGenerator.fail(StatusCode.SYSTEM_ERROR);
// }
return response;
}
/**
* 车辆绑定短信验证
* @param req
* @return
*/
@PostMapping("bind/smsValid")
@BodyDecryptAnnotation
@ResponseEncryptAnnotation
public Result<BindInfoRes> bindSmsValid(@RequestBody @Validated BindSmsValidReq req) {
Result result = null;
try {
result = service.bindSmsValid(req);
} catch ( DistributedLockException e ) {
return ResultGenerator.fail(StatusCode.REPEAT_SUBMIT);
}
return result;
}
/**
* 解绑用户信息的接口
......@@ -87,9 +101,42 @@ public class BindInfoControlller extends BaseController {
result = service.unbindInfo(req);
} catch ( DistributedLockException e ) {
return ResultGenerator.fail(StatusCode.REPEAT_SUBMIT);
} catch ( Exception e ) {
log.error("系统异常:{}", e);
return ResultGenerator.fail(StatusCode.SYSTEM_ERROR);
}
return result;
}
/**
* 车辆解绑发送短信(后台操作)
* @param req
* @return
*/
@PostMapping( "admin/unbind" )
@BodyDecryptAnnotation
@ResponseEncryptAnnotation
public Result adminUnbind(@RequestBody @Validated AdminUnbindReq req ) {
Result result = null;
try {
result = service.adminUnbind(req);
} catch ( DistributedLockException e ) {
return ResultGenerator.fail(StatusCode.REPEAT_SUBMIT);
}
return result;
}
/**
* 车辆解绑短信验证(后台操作)
* @param req
* @return
*/
@PostMapping( "admin/unbind/smsValid" )
@BodyDecryptAnnotation
@ResponseEncryptAnnotation
public Result adminUnbindSmsValid(@RequestBody @Validated AdminUnbindSmsValidReq req) {
Result result = null;
try {
result = service.adminUnbindSmsValid(req);
} catch ( DistributedLockException e ) {
return ResultGenerator.fail(StatusCode.REPEAT_SUBMIT);
}
return result;
}
......
package com.hikcreate.edl.pub.web.mobile.api.controller;
import com.alibaba.fastjson.JSONObject;
import com.hikcreate.common.sdk.exception.BusinessException;
import com.hikcreate.common.sdk.response.apiparam.Response;
import com.hikcreate.common.sdk.response.apiparam.ResponseGenerator;
import com.hikcreate.common.sdk.response.statuscode.StatusCode;
import com.hikcreate.edl.common.image.builder.domain.DlBackImageDO;
import com.hikcreate.edl.common.image.builder.domain.DlImageDO;
import com.hikcreate.edl.common.sdk.util.RegexUtil;
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.domain.IBindService;
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.DrivingLicenseValidReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.request.DrivingLicenseValidSmsCodeReq;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.DrivingLicenseInfoRes;
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;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Objects;
/**
* 驾驶证图片接口
*
* @author MOUBK
* @menu
* @create 2020/7/20 17:44
**/
@RestController
@RequestMapping("/drivingLicense")
@Slf4j
public class DrivingLicenseController {
@Autowired
private CredentialsImageService credentialsImageService;
@Autowired
private DrivingLicenseFeign drivingLicenseFeign;
@Autowired
private FastDfsConfigBean fastDfsConfigBean;
@Autowired
private DrivingLicenseService drivingLicenseService;
@Autowired
private IBindService iBindService;
@PostMapping("/valid")
@HeaderDecryptAnnotation
public Result<DrivingLicenseValidRes> valid(@RequestBody @Validated DrivingLicenseValidReq req) {
DrivingLicenseValidRes drivingLicenseValidRes = drivingLicenseService.checkIdCard(req.getIdCard(), req.getUserId());
return ResultGenerator.success(drivingLicenseValidRes);
}
@GetMapping("/sendSmsCode")
public Result<Void> sendSmsCode(@RequestParam("userId") String userId) {
drivingLicenseService.sendSmsCode(userId);
return ResultGenerator.success();
}
@PostMapping("/validSmsCode")
public Result<Void> validSmsCode(@RequestBody @Validated DrivingLicenseValidSmsCodeReq req) {
drivingLicenseService.validSmsCode(req.getUserId(), req.getSmsCode());
return ResultGenerator.success();
}
@GetMapping("/info")
public Result<DrivingLicenseInfoRes> getDrivingLicenseInfo(@RequestParam("userId") String userId) {
DrivingLicenseInfoRes drivingLicenseInfoRes = drivingLicenseService.getDrivingLicenseInfo(userId);
return ResultGenerator.success(drivingLicenseInfoRes);
}
@GetMapping("/image")
public void image(@RequestParam("userId") String userId, @RequestParam("idCard") String idCard, @RequestParam("type") Integer type, HttpServletResponse response) {
// 验证是否有查看权限
if (!drivingLicenseService.checkValid(userId, idCard) && !iBindService.checkValid(userId, idCard)) {
throw new BusinessException(StatusCode.PARAM_ERROR);
}
DrivingLicenseMicRes drivingLicenseMicRes = drivingLicenseFeign.getByIdCard(new CreditIdCardMicReq().setIdCard(idCard)).fallback().getData();
ByteArrayOutputStream outputStream;
if (type == null || Objects.equals(type, 1)) {
DlImageDO dlImageDO = new DlImageDO();
dlImageDO.setAddress(RegexUtil.addressMask(drivingLicenseMicRes.getAddress()));
dlImageDO.setBelowLicenseNumber(RegexUtil.idCardMask(drivingLicenseMicRes.getIdCard()));
dlImageDO.setAvatarFullUrl(fastDfsConfigBean.genBigDataInnerUrl(drivingLicenseMicRes.getAvatar()));
dlImageDO.setBirthday(drivingLicenseMicRes.getBirthday());
dlImageDO.setLicenseNumber(RegexUtil.idCardMask(drivingLicenseMicRes.getIdCard()));
dlImageDO.setInitLicenseDate(drivingLicenseMicRes.getIssueDate());
dlImageDO.setName(RegexUtil.nameMask(drivingLicenseMicRes.getRealName()));
dlImageDO.setBelowName(RegexUtil.nameMask(drivingLicenseMicRes.getRealName()));
dlImageDO.setModel(drivingLicenseMicRes.getLicenseType());
dlImageDO.setNationality(drivingLicenseMicRes.getNationality());
dlImageDO.setSex(drivingLicenseMicRes.getGender());
dlImageDO.setValidityPeriod(drivingLicenseMicRes.getEffectiveDate() + "至" + drivingLicenseMicRes.getExpiryDate());
dlImageDO.setRecord("");
dlImageDO.setFileNumber(RegexUtil.fileNumMask(drivingLicenseMicRes.getFileNum()));
outputStream = (ByteArrayOutputStream) credentialsImageService.genDlImage(dlImageDO);
} else {
DlBackImageDO dlBackImageDO = new DlBackImageDO();
dlBackImageDO.setRecordContents("");
dlBackImageDO.setSerialNum("");
outputStream = (ByteArrayOutputStream) credentialsImageService.genDlBackImage(dlBackImageDO);
}
try {
setHeader(response, drivingLicenseMicRes.getIdCard() + ".jpg");
response.getOutputStream().write(outputStream.toByteArray());
} catch (Exception e) {
log.error("Get dl img E, idCard={}, userId={}, msg={}", idCard, userId, e);
getResException(response, "获取驾照图片异常");
} finally {
try {
if (null != outputStream) {
outputStream.close();
}
} catch (Exception e) {
log.error("Get dl img IOE, msg={}", e);
}
}
}
private void getResException(HttpServletResponse response, String msg) {
try {
Response<Void> res = ResponseGenerator.fail(StatusCode.SYSTEM_ERROR, msg);
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(JSONObject.toJSONString(res));
} catch (IOException e) {
log.error("Get dl header IOE, msg={}", e);
}
}
private void setHeader(HttpServletResponse resposne, String fileName) {
resposne.setDateHeader("Expires", 0L);
resposne.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
resposne.addHeader("Cache-Control", "post-check=0, pre-check=0");
resposne.setHeader("Pragma", "no-cache");
resposne.setContentType("image/jpeg");
resposne.setHeader("Content-Disposition", "attachment;filename=" + fileName);
}
}
......@@ -114,13 +114,13 @@ 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);
}
/**
* 验证当前手机号是否在1天内,已通过验证
* 【驾照信息查询】验证当前手机号是否在1天内,已通过验证
*
* @param query
* @return
......@@ -143,7 +143,7 @@ public class H5Controller {
}
/***
* 发送短信验证码
* 【驾照信息查询】发送短信验证码
*
* @param req
* @return Result
......@@ -161,7 +161,7 @@ public class H5Controller {
}
/**
* 校验短信验证码
* 【驾照信息查询】校验短信验证码
*
* @param req
* @return Result
......@@ -184,6 +184,8 @@ public class H5Controller {
verifyInfo.setPhone(req.getPhone());
verifyInfo.setPassTime(DateTime.now());
verifyInfoMapper.insert(verifyInfo);
// 保存验证信息到redis
service.saveValid(req.getUserId(), req.getUnqId(), req.getPhone());
}
return checkResult;
}
......
package com.hikcreate.edl.pub.web.mobile.api.exception;
import com.hikcreate.common.sdk.exception.DefaultExceptionHandler;
import com.hikcreate.common.sdk.exception.BusinessException;
import com.hikcreate.common.sdk.response.apiparam.Response;
import com.hikcreate.common.sdk.response.apiparam.ResponseGenerator;
import com.hikcreate.common.sdk.response.statuscode.StatusCode;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.Result;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultCode;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result.ResultGenerator;
import feign.RetryableException;
import lombok.extern.slf4j.Slf4j;
......@@ -88,6 +87,13 @@ public class GlobalExceptionHandler {
return ResultGenerator.fail(StatusCode.SYSTEM_ERROR.getCode(), "服务请求超时或不可用");
}
@ExceptionHandler({BusinessException.class})
@ResponseBody
public Response<Object> handle(BusinessException e) {
log.error(e.toString(), e);
return ResponseGenerator.fail(e.getCode(), e.getMsg(), e.getErrorMsg(), e.getParam());
}
/**
* 从{@code @BindingResult}中构建异常信息
* on field 'verifyCode': null];
......
......@@ -28,10 +28,20 @@
</dependency>
<dependency>
<groupId>com.hikcreate.common</groupId>
<artifactId>orika</artifactId>
<version>${parent.version}</version>
</dependency>
<dependency>
<groupId>com.hikcreate.edl.common</groupId>
<artifactId>distributed-lock-starter</artifactId>
<version>${parent.version}</version>
</dependency>
<dependency>
<groupId>com.hikcreate.edl.common</groupId>
<artifactId>image-builder</artifactId>
</dependency>
</dependencies>
</project>
package com.hikcreate.edl.pub.web.mobile.domain;
import com.hikcreate.edl.common.image.builder.domain.DlBackImageDO;
import com.hikcreate.edl.common.image.builder.domain.DlImageDO;
import java.io.OutputStream;
/**
* @author MOUBK
* @create 2020/7/20 17:52
*/
public interface CredentialsImageService {
/**
* 生成驾驶证图片.包含主副页
*
* @param params 参数
* @return
*/
OutputStream genDlImage(DlImageDO params);
/**
* 生成驾驶证背面图片
*
* @param params 参数
* @return
*/
OutputStream genDlBackImage(DlBackImageDO params);
}
package com.hikcreate.edl.pub.web.mobile.domain;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.DrivingLicenseInfoRes;
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);
DrivingLicenseInfoRes getDrivingLicenseInfo(String userId);
Boolean checkValid(String userId, String idCard);
}
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;
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.request.*;
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;
......@@ -24,12 +21,19 @@ public interface IBindService extends IService<ParkBindInfo> {
/**
* 信息绑定接口
*
* @param info
* @param req
* @return Result
* @author: xsx
* @date: 2020/6/19 10:32
*/
Result bind( ParkBindInfo info);
Result bind( BindInfoReq req);
/**
* 车辆绑定短信验证接口
* @param req
* @return
*/
Result bindSmsValid( BindSmsValidReq req);
/**
* 信息解绑
......@@ -39,6 +43,20 @@ public interface IBindService extends IService<ParkBindInfo> {
Result unbindInfo( UnBindReq req );
/**
* 车辆解绑发送短信(后台操作)
* @param req
* @return
*/
Result adminUnbind( AdminUnbindReq req);
/**
* 车辆解绑短信验证(后台操作)
* @param req
* @return
*/
Result adminUnbindSmsValid(AdminUnbindSmsValidReq req);
/**
* 查询用户绑定信息
* @param query
* @return
......@@ -78,6 +96,21 @@ public interface IBindService extends IService<ParkBindInfo> {
* @author: xsx
* @date: 2020/6/19 16:29
*/
Result<DrivingLicenseInfoRes> drivingLicenseInfo( H5BindInfoQuery query);
Result<VehicleDrivingLicenseInfoRes> drivingLicenseInfo(H5BindInfoQuery query);
/**
* 保存校验信息
* @param userId
* @param unqId
* @param phone
*/
void saveValid(String userId, String unqId, String phone);
/**
* 验证是否通过短信校验
* @param userId
* @param idCard
* @return
*/
Boolean checkValid(String userId, String idCard);
}
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.image.builder.domain.DlBackImageDO;
import com.hikcreate.edl.common.image.builder.domain.DlImageDO;
import com.hikcreate.edl.common.image.builder.refactor.DrawDispatcher;
import com.hikcreate.edl.pub.web.mobile.domain.CredentialsImageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.OutputStream;
/**
* @author MOUBK
* @create 2020/7/20 17:53
*/
@Slf4j
@Service
public class CredentialsImageServiceImpl implements CredentialsImageService {
@Autowired
private DrawDispatcher drawDispatcher;
@Override
public OutputStream genDlImage(DlImageDO params) {
OutputStream outputStream;
try {
outputStream = drawDispatcher.drawDl(params);
} catch (Exception e) {
log.error("Gen DrivingLicense Image Error, param={}, msg={}", JSONObject.toJSONString(params), e);
throw new BusinessException("获取驾驶证图片失败");
}
return outputStream;
}
/**
* 生成驾驶证背面图片
*
* @param params 参数
* @return
*/
@Override
public OutputStream genDlBackImage(DlBackImageDO params) {
OutputStream outputStream;
try {
outputStream = drawDispatcher.drawDlBack(params);
} catch (Exception e) {
log.error("Gen DrivingLicense back Image Error, param={}, msg={}", JSONObject.toJSONString(params), e);
throw new BusinessException("获取驾驶证图片失败");
}
return outputStream;
}
}
package com.hikcreate.edl.pub.web.mobile.domain.impl;
import cn.hutool.core.date.DateUtil;
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.request.IdCardMicReq;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.response.DlQrRes;
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.DrivingLicenseInfoRes;
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.Date;
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 = "park:extend:drv:userId:";
private static final String REDIS_SMS_KEY = "park:extend:drv:sms:";
private static final String SMS_CODE = "PARK_DRIVING_LICENSE_IDCARD";
@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(false);
} else {
drivingLicenseValidRes.setSendSmsFlag(true);
}
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(SMS_CODE);
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(SMS_CODE);
smsFeign.checkVerifyCode(req).fallback();
// 保存验证redis
saveSmsValid(userId, drivingLicenseMicRes.getIdCard(), drivingLicenseMicRes.getPhone());
}
@Override
public DrivingLicenseInfoRes getDrivingLicenseInfo(String userId) {
DrivingLicenseMicRes drivingLicenseMicRes = getFromRedis(userId);
DlQrRes data = drivingLicenseFeign.getQrInfo(new IdCardMicReq().setIdCard(drivingLicenseMicRes.getIdCard())).fallback().getData();
/**
* 构建驾照信息查询结果
*/
DrivingLicenseInfoRes result = new DrivingLicenseInfoRes();
result.setDriverName(drivingLicenseMicRes.getRealName());
result.setDlQr(data.getQr());
result.setValidityTime(drivingLicenseMicRes.getExpiryDate());
String status = DateUtil.compare(DateUtil.parseDate(drivingLicenseMicRes.getExpiryDate()), new Date()) >= 0 ? "有效" :
"已过期";
result.setStatus(status);
result.setUserId(userId);
result.setIdCard(drivingLicenseMicRes.getIdCard());
result.setSurplusGrade(String.valueOf(drivingLicenseMicRes.getResidualScore()));
return result;
}
private void saveSmsValid(String userId, String idCard, String phone) {
redisTemplate.opsForValue().set(getSmsKey(userId, idCard), phone, 24 * 3600, 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;
}
@Override
public Boolean checkValid(String userId, String idCard) {
String value = redisTemplate.opsForValue().get(getSmsKey(userId, idCard));
if (!StringUtils.isEmpty(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;
}
}
......@@ -92,6 +92,10 @@
<artifactId>sdk</artifactId>
<version>${parent.version}</version>
</dependency>
<dependency>
<groupId>com.hikcreate.edl.common</groupId>
<artifactId>image-builder</artifactId>
</dependency>
</dependencies>
</project>
......@@ -19,7 +19,7 @@ public enum ResultCode implements IStatusCode {
REPEAT_SUBMIT(1004, "重复提交"),
PARAM_ERROR(1005, "参数错误"),
BUSINESS_ERROR(1006, "业务错误"),*/
BIND_NUM_ERROR(1, "同一客户绑定认证不超过3辆"),
BIND_NUM_ERROR(1, "可绑定车辆数已用完"),
UNBIND_TOTAL_ERROR(2, "30天内解绑次数超过10次,不能再次绑定认证"),
USERID_PHONE_ERROR(3, "客户ID与手机号不一致"),
CAR_MESSAGE_UNKNOWN(4, "车辆信息不存在"),
......
package com.hikcreate.edl.pub.web.mobile.infra.core.config;
import com.hikcreate.edl.common.image.builder.refactor.material.DlBackMaterial;
import com.hikcreate.edl.common.image.builder.refactor.material.DlMaterial;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author 赵东
* @date 2019/7/8 10:25
*/
@Configuration
public class DrawConfig {
@Bean
@ConfigurationProperties("biz.image.builder.dl")
public DlMaterial dlMaterial() {
return new DlMaterial();
}
@Bean
@ConfigurationProperties("biz.image.builder.dl-back")
public DlBackMaterial dlBackMaterial() {
return new DlBackMaterial();
}
}
package com.hikcreate.edl.pub.web.mobile.infra.core.configbean;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author zhangfubing
* @create 2019/4/28 15:28
*/
@Component
@ConfigurationProperties("biz.fastdfs")
@Data
public class FastDfsConfigBean {
/**
* FastDfs地址
*/
private String bigDataInnerUrl;
/**
* 大数据fastUrl
*
* @param suffix
* @return
*/
public String genBigDataInnerUrl(String suffix) {
return bigDataInnerUrl + suffix;
}
}
\ No newline at end of file
package com.hikcreate.edl.pub.web.mobile.infra.data.feign.dcp_service_vehicle.param.request;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
......@@ -9,6 +10,7 @@ package com.hikcreate.edl.pub.web.mobile.infra.data.feign.dcp_service_vehicle.pa
* @create 2019/7/5 14:56
*/
@Data
@Accessors(chain = true)
public class IdCardQueryReq {
@NotBlank(message = "IdCard is not blank")
......
package com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense;
import com.hikcreate.common.sdk.response.apiparam.Response;
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.request.IdCardMicReq;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.response.DlQrRes;
import com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.response.DrivingLicenseMicRes;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* 驾照调用
*
* @author MOUBK
* @create 2019/4/9 19:49
*/
@FeignClient(value = "edl-pvt-service-dl", path = "drivingLicense/qr")
public interface DrivingLicenseQrFeign {
@FeignClient(value = "edl-pvt-service-dl", path = "drivingLicense")
public interface DrivingLicenseFeign {
@PostMapping("getByIdCard")
Response<DrivingLicenseMicRes> getByIdCard(@RequestBody CreditIdCardMicReq req);
@PostMapping("getQrInfo")
@PostMapping("/qr/getQrInfo")
Response<DlQrRes> getQrInfo(@RequestBody @Validated IdCardMicReq req);
}
package com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.request;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import static com.hikcreate.edl.common.constant.ValidateConstant.ID_CARD_CONSTRAINT_REGEXP;
/**
* @author MOUBK
* @create 2019/4/8 19:43
*/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class CreditIdCardMicReq {
@Pattern(regexp = ID_CARD_CONSTRAINT_REGEXP, message = "身份证号不正确")
@NotNull
private String idCard;
}
package com.hikcreate.edl.pub.web.mobile.infra.data.feign.edl_pvt_service_drivinglicense.response;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.List;
/**
* @author MOUBK
* @create 2019/4/9 17:49
*/
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class DrivingLicenseMicRes {
// 驾照ID
private Long id;
// 驾驶证头像
private String avatar;
// 清分日期
private String clearDate;
// 出身年月日
private String birthday;
// 剩余计分
private Integer residualScore;
// 累计计分
private Integer cumulativeScore;
// 生效开始日期
private String effectiveDate;
// 有效期止
private String expiryDate;
// 下一审验日期
private String verifyDate;
// 姓名
private String realName;
// 身份证号
private String idCard;
// 档案号
private String fileNum;
// 准驾车型
private String licenseType;
// 发证机关
private String certDepart;
// 发证日期
private String issueDate;
// 国籍
private String nationality;
// 地址
private String address;
// 性别
private String gender;
// 驾驶证状态
private String licenseStatus;
// 联系电话
private String phone;
// 地址区划
private String residenceZone;
// 是否锁定
private Boolean isLock;
// 准驾车型列表
private List<String> licenseTypes;
}
......@@ -29,6 +29,10 @@ public class ParkBindInfo implements Serializable {
*/
private String phone;
/**
* 车主手机号码
*/
private String ownerPhone;
/**
* 车牌颜色:A:白,B:灰,C:黄,D:粉,E:红,
* F:紫,G:绿,H:蓝,I:棕,J:黑',
*/
......
package com.hikcreate.edl.pub.web.mobile.infra.model.param.request;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @author lixian
* @description
* @date 2020/7/20 18:19
**/
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class AdminUnbindReq {
/**
* 客户id
*/
@NotBlank(message = "客户唯一编码不能为空")
private String userId;
/**
* 用户车辆绑定唯一编号
*/
@NotBlank(message = "用户车辆绑定唯一编号不能为空")
private String unqId;
/**
* 时间戳
*/
@NotNull(message = "时间戳不能为空")
private Long timestamp;
}
package com.hikcreate.edl.pub.web.mobile.infra.model.param.request;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @author lixian
* @description
* @date 2020/7/20 18:36
**/
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class AdminUnbindSmsValidReq {
/**
* 用户车辆绑定唯一编号
*/
@NotBlank(message = "用户车辆绑定唯一编号不能为空")
private String unqId;
/**
* 验证码
*/
@NotBlank(message = "验证码不能为空")
private String smsCode;
/**
* 时间戳
*/
@NotNull(message = "时间戳不能为空")
private Long timestamp;
}
......@@ -22,8 +22,15 @@ public class BindInfoReq {
* 客户电话号码
*/
@NotBlank(message = "客户手机号不能为空")
@Pattern(regexp = "^(1)\\d{10}$", message = "客户手机号无效")
private String phone;
/**
* 车主手机号码
*/
@NotBlank(message = "车主手机号不能为空")
@Pattern(regexp = "^(1)\\d{10}$", message = "车主手机号无效")
private String ownerPhone;
/**
* 车牌颜色:A:白,B:灰,C:黄,D:粉,E:红,
* F:紫,G:绿,H:蓝,I:棕,J:黑',
*/
......
package com.hikcreate.edl.pub.web.mobile.infra.model.param.request;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* @author lixian
* @description
* @date 2020/7/20 17:09
**/
@Data
public class BindSmsValidReq {
/**
* 客户电话号码
*/
@NotBlank(message = "客户手机号不能为空")
private String phone;
/**
* 车主手机号码
*/
@NotBlank(message = "车主手机号不能为空")
@Size(max = 11, message = "车主手机号无效")
private String ownerPhone;
/**
* 验证码
*/
@NotBlank(message = "验证码不能为空")
private String smsCode;
/**
* 时间戳
*/
@NotNull(message = "时间戳不能为空")
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 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,12 +9,11 @@ import lombok.Data;
@Data
public class DrivingLicenseInfoRes {
private String userId;
// 身份证号
private String idCard;
/**
* 车牌号
*/
private String plateNum;
/**
*有效期止
* 有效期止
*/
private String validityTime;
/**
......
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;
}
......@@ -73,6 +73,11 @@
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.hikcreate.edl.common</groupId>
<artifactId>image-builder</artifactId>
<version>1.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.hikcreate.edl.pub.web.mobile</groupId>
<artifactId>api</artifactId>
<version>${version}</version>
......
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