Commit d5bc2c35 by lixian7

调整接口返回体

parent 1135a081
package com.hikcreate.edl.pub.web.mobile.api.controller;
import cn.hutool.core.date.DateTime;
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.domain.IBindService;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result;
import com.hikcreate.edl.pub.web.mobile.infra.core.annotatiion.ResponseEncryptAnnotation;
......@@ -45,9 +48,9 @@ public class BindInfoControlller extends BaseController {
*/
@PostMapping("bind")
@ResponseEncryptAnnotation
public Result<String> bindInfo(@RequestBody BindInfo info) {
public Response<String> bindInfo(@RequestBody BindInfo info) {
if (info == null) {
return Result.errorResult(ResultCode.PARAMETER_ERROR, "参数不能为空");
return ResponseGenerator.fail(StatusCode.PARAM_ERROR);
}
return service.bind(info);
}
......@@ -62,13 +65,13 @@ public class BindInfoControlller extends BaseController {
* @date: 2020/6/19 10:27
*/
@PostMapping("unbind")
public Result unbindInfo(@RequestBody BindInfo info) {
public Response unbindInfo( @RequestBody BindInfo info) {
if (info == null) {
return Result.errorResult(ResultCode.PARAMETER_ERROR);
return ResponseGenerator.fail(StatusCode.PARAM_ERROR);
}
info.setStatus("0");
info.setUnbindTime(DateTime.now());
return mapper.updateById(info) > 0 ? Result.successResult() : Result.errorResult();
return mapper.updateById(info) > 0 ? ResponseGenerator.success() : ResponseGenerator.fail("");
}
/**
......@@ -81,12 +84,11 @@ public class BindInfoControlller extends BaseController {
*/
@PostMapping("query")
@ResponseEncryptAnnotation
public Result<ResultList<BindInfo>> bindInfoQery(@RequestBody BindInfoQuery query) {
public Response<ResultList<BindInfo>> bindInfoQery(@RequestBody BindInfoQuery query) {
if (query == null) {
return Result.errorResult(ResultCode.PARAMETER_ERROR);
return ResponseGenerator.fail(StatusCode.PARAM_ERROR);
}
return Result.successResult(new ResultList<BindInfo>(mapper.selectByQuery(query).getDataItems()));
return ResponseGenerator.success(new ResultList<BindInfo>(mapper.selectByQuery(query).getDataItems()));
}
......
package com.hikcreate.edl.pub.web.mobile.api.controller;
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.domain.IBindService;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result;
import com.hikcreate.edl.pub.web.mobile.infra.core.enums.ResultCode;
......@@ -40,9 +43,9 @@ public class H5Controller {
* @date: 2020/6/19 10:32
*/
@GetMapping("yearCheckInfo")
public Result<YearCheckInfoRes> yearCheckInfo(@RequestBody @Validated BindInfoQuery query) {
public Response<YearCheckInfoRes> yearCheckInfo( @RequestBody @Validated BindInfoQuery query) {
if (query == null) {
return Result.errorResult(ResultCode.PARAMETER_ERROR);
return ResponseGenerator.fail(StatusCode.PARAM_ERROR);
}
return service.yearCheckInfo(query);
}
......@@ -56,9 +59,9 @@ public class H5Controller {
* @date: 2020/6/19 16:28
*/
@GetMapping("violationInfo")
public Result<ResultList<ViolationInfoRes>> violationInfo(@RequestBody @Validated BindInfoQuery query) {
public Response<ResultList<ViolationInfoRes>> violationInfo(@RequestBody @Validated BindInfoQuery query) {
if (query == null) {
return Result.errorResult(ResultCode.PARAMETER_ERROR);
return ResponseGenerator.fail(StatusCode.PARAM_ERROR);
}
return service.violationInfo(query);
}
......@@ -72,9 +75,9 @@ public class H5Controller {
* @date: 2020/6/19 16:28
*/
@GetMapping("insuranceInfo")
public Result<InsuranceInfoRes> insuranceInfo(@RequestBody @Validated BindInfoQuery query) {
public Response<InsuranceInfoRes> insuranceInfo(@RequestBody @Validated BindInfoQuery query) {
if (query == null) {
return Result.errorResult(ResultCode.PARAMETER_ERROR);
return ResponseGenerator.fail(StatusCode.PARAM_ERROR);
}
return service.insuranceInfo(query);
}
......@@ -88,9 +91,9 @@ public class H5Controller {
* @date: 2020/6/19 16:28
*/
@GetMapping("drivingLicenseInfo")
public Result<DrivingLicenseInfoRes> drivingLicenseInfo(@RequestBody BindInfoQuery query) {
public Response<DrivingLicenseInfoRes> drivingLicenseInfo(@RequestBody BindInfoQuery query) {
if (query == null) {
return Result.errorResult(ResultCode.PARAMETER_ERROR);
return ResponseGenerator.fail(StatusCode.PARAM_ERROR);
}
return service.drivingLicenseInfo(query);
}
......
package com.hikcreate.edl.pub.web.mobile.api.exception;
import com.hikcreate.common.sdk.exception.DefaultExceptionHandler;
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 feign.RetryableException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
/**
* 全局异常处理类 FOR controller层以下的异常,Filter的异常不能捕获
*/
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler extends DefaultExceptionHandler {
@Override
@ExceptionHandler(value = ServletRequestBindingException.class)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Response handleServletRequestBindingException(ServletRequestBindingException e) {
log.error("param bind failure", e);
return ResponseGenerator.fail(StatusCode.PARAM_ERROR.getCode(), e.getMessage());
}
/**
* 参数验证失败
* <p>
* GET 方法入口
*
* @param e
* @return
*/
@ExceptionHandler(ConstraintViolationException.class)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Response handleValidationException(ConstraintViolationException e) {
for (ConstraintViolation<?> s : e.getConstraintViolations()) {
log.error("Request parameter is invalid {}", s.getMessage());
return ResponseGenerator.fail(StatusCode.PARAM_ERROR.getCode(), s.getMessage());
}
return ResponseGenerator.fail(StatusCode.PARAM_ERROR);
}
@ExceptionHandler(value = RetryableException.class)
@ResponseBody
public Response retryableExceptionHandler(HttpServletRequest req, RetryableException e) throws Exception {
log.error(" connect timed out", e);
return ResponseGenerator.fail(StatusCode.SYSTEM_ERROR.getCode(), "服务请求超时或不可用", e.getMessage());
}
}
\ No newline at end of file
......@@ -21,6 +21,11 @@
<artifactId>infra</artifactId>
<version>${parent.version}</version>
</dependency>
<dependency>
<groupId>com.hikcreate.edl.common</groupId>
<artifactId>sdk</artifactId>
<version>${parent.version}</version>
</dependency>
</dependencies>
</project>
package com.hikcreate.edl.pub.web.mobile.domain;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result;
import com.hikcreate.common.sdk.response.apiparam.Response;
import com.hikcreate.edl.pub.web.mobile.infra.model.BindInfo;
import com.hikcreate.edl.pub.web.mobile.infra.model.BindInfoQuery;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.DrivingLicenseInfoRes;
/**
* 客户绑定服务接口
*
......@@ -22,7 +23,7 @@ public interface IBindService extends IService<BindInfo> {
* @author: xsx
* @date: 2020/6/19 10:32
*/
Result bind(BindInfo info);
Response bind( BindInfo info);
/**
* 年检信息查询接口
......@@ -30,14 +31,14 @@ public interface IBindService extends IService<BindInfo> {
* @param query
* @return
*/
Result yearCheckInfo(BindInfoQuery query);
Response yearCheckInfo(BindInfoQuery query);
/**
* 保险信息查询接口
* @param query
* @return
*/
Result insuranceInfo(BindInfoQuery query);
Response insuranceInfo(BindInfoQuery query);
/**
* 违法信息查询接口
......@@ -47,7 +48,7 @@ public interface IBindService extends IService<BindInfo> {
* @author: xsx
* @date: 2020/6/19 16:06
*/
Result violationInfo(BindInfoQuery query);
Response violationInfo( BindInfoQuery query);
/**
* 驾照信息查询接口
......@@ -57,6 +58,6 @@ public interface IBindService extends IService<BindInfo> {
* @author: xsx
* @date: 2020/6/19 16:29
*/
Result<DrivingLicenseInfoRes> drivingLicenseInfo(BindInfoQuery query);
Response<DrivingLicenseInfoRes> drivingLicenseInfo(BindInfoQuery query);
}
package com.hikcreate.edl.pub.web.mobile.domain.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.domain.IBindService;
import com.hikcreate.edl.pub.web.mobile.infra.core.Result;
import com.hikcreate.edl.pub.web.mobile.infra.core.enums.ResultCode;
......@@ -21,12 +23,7 @@ import com.hikcreate.edl.pub.web.mobile.infra.data.mapper.VerifyInfoMapper;
import com.hikcreate.edl.pub.web.mobile.infra.model.BindInfo;
import com.hikcreate.edl.pub.web.mobile.infra.model.BindInfoQuery;
import com.hikcreate.edl.pub.web.mobile.infra.model.VerifyInfo;
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.ViolationInfoRes;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.YearCheckInfoRes;
import lombok.Data;
import com.hikcreate.edl.pub.web.mobile.infra.model.param.response.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
......@@ -60,7 +57,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, BindInfo> imple
@Override
public Result bind(BindInfo info) {
public Response bind(BindInfo info) {
info.setUnqId(UUID.randomUUID().toString());
info.setGmtBindTime(DateTime.now());
......@@ -69,7 +66,7 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, BindInfo> imple
boundQuery.eq("user_id", info.getUserId());
Integer bound = mapper.selectCount(boundQuery);
if (bound >= 3) {
return Result.errorResult(ResultCode.SERVICE_ERROR);
return ResponseGenerator.fail(StatusCode.BUSINESS_ERROR);
}
//规则2:客户手机号与车辆对应的车主手机号一致
......@@ -82,64 +79,76 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, BindInfo> imple
}
}
if (info.getPlateType() == null || info.getPlateType().equals("")) {
return Result.errorResult(ResultCode.DATA_ERROR);
return ResponseGenerator.fail(StatusCode.DATA_ERROR);
}
return mapper.insert(info) > 0 ? Result.successResult(info.getUnqId()) :
Result.errorResult(ResultCode.SERVICE_ERROR);
return mapper.insert(info) > 0 ? ResponseGenerator.success(info.getUnqId()) :
ResponseGenerator.fail(StatusCode.BUSINESS_ERROR);
}
@Override
public Result<YearCheckInfoRes> yearCheckInfo(BindInfoQuery query) {
public Response<YearCheckInfoRes> yearCheckInfo( BindInfoQuery query) {
BindInfo bindInfo = mapper.selectById(query.getUnqId());
if (bindInfo == null || "0".equals(bindInfo.getStatus())) {
return Result.errorResult(ResultCode.DATA_ERROR);
return ResponseGenerator.fail(StatusCode.DATA_ERROR);
}
PlateNumAndTypeQueryReq req = new PlateNumAndTypeQueryReq();
req.setPlateNum(bindInfo.getPlateNum());
req.setPlateType(bindInfo.getPlateType());
VehicleRes vehicleRes = vechicle.getByPlateNumAndType(req);
if( Objects.isNull(vehicleRes) ) {
return Result.successResult();
return ResponseGenerator.success();
}
YearCheckInfoRes yearCheckInfoRes = new YearCheckInfoRes();
yearCheckInfoRes.setYxqz(vehicleRes.getYxqz());
yearCheckInfoRes.setPlateNum(bindInfo.getPlateNum());
yearCheckInfoRes.setValidityTime(vehicleRes.getYxqz());
Long checkTime = DateUtil.parse(vehicleRes.getYxqz(),"yyyy-MM-dd HH:mm:ss").getTime();
if( checkTime>=System.currentTimeMillis() ) {
yearCheckInfoRes.setZt("未到期");
yearCheckInfoRes.setStatus("未到期");
} else {
yearCheckInfoRes.setZt("已到期");
yearCheckInfoRes.setStatus("已到期");
}
return Result.successResult(yearCheckInfoRes);
return ResponseGenerator.success(yearCheckInfoRes);
}
@Override
public Result<InsuranceInfoRes> insuranceInfo(BindInfoQuery query) {
public Response<InsuranceInfoRes> insuranceInfo(BindInfoQuery query) {
BindInfo bindInfo = mapper.selectById(query.getUnqId());
if (bindInfo == null || "0".equals(bindInfo.getStatus())) {
return Result.errorResult(ResultCode.DATA_ERROR);
return ResponseGenerator.fail(StatusCode.DATA_ERROR);
}
PlateNumAndTypeQueryReq req = new PlateNumAndTypeQueryReq();
req.setPlateNum(bindInfo.getPlateNum());
req.setPlateType(bindInfo.getPlateType());
VehicleRes vehicleRes = vechicle.getByPlateNumAndType(req);
if( Objects.isNull(vehicleRes) ) {
return Result.successResult();
return ResponseGenerator.success();
}
InsuranceInfoRes insuranceInfoRes = new InsuranceInfoRes();
insuranceInfoRes.setPlateNum(bindInfo.getPlateNum());
if( StrUtil.isNotBlank(vehicleRes.getBxzzrq()) ) {
Long time = DateUtil.parse(vehicleRes.getBxzzrq(),"yyyy-MM-dd HH:mm:ss").getTime();
if( time>=System.currentTimeMillis()) {
insuranceInfoRes.setStatus("有效");
} else {
insuranceInfoRes.setStatus("已到期");
}
insuranceInfoRes.setValidityTimeEnd(vehicleRes.getBxzzrq().substring(0,10));
String endTime = DateUtil.format(
DateUtil.offsetMonth(DateUtil.parse(vehicleRes.getBxzzrq(),"yyyy-MM-dd HH:mm:ss"), -12),
"yyyy-MM-dd");
insuranceInfoRes.setValidityTimeStart(endTime);
} else {
insuranceInfoRes.setStatus("未知");
}
return null;
return ResponseGenerator.success(insuranceInfoRes);
}
@Override
public Result<ResultList<ViolationInfoRes>> violationInfo(BindInfoQuery query) {
public Response<ResultList<ViolationInfoRes>> violationInfo(BindInfoQuery query) {
BindInfo bindInfo = mapper.selectById(query.getUnqId());
if (bindInfo == null || "0".equals(bindInfo.getStatus())) {
return Result.errorResult(ResultCode.DATA_ERROR);
return ResponseGenerator.fail(StatusCode.DATA_ERROR);
}
ViolationPlateNumAndTypeQueryReq req = new ViolationPlateNumAndTypeQueryReq();
......@@ -156,14 +165,14 @@ public class BindServiceImpl extends ServiceImpl<BindInfoMapper, BindInfo> imple
info.setMoney(res.getfk);
violationInfoResList.add(info);
}
return Result.successResult(new ResultList<>(violationInfoResList));
return ResponseGenerator.success(new ResultList<>(violationInfoResList));
}
@Override
public Result<DrivingLicenseInfoRes> drivingLicenseInfo(BindInfoQuery query) {
public Response<DrivingLicenseInfoRes> drivingLicenseInfo(BindInfoQuery query) {
BindInfo bindInfo = mapper.selectById(query.getUnqId());
if (bindInfo == null || "0".equals(bindInfo.getStatus())) {
return Result.errorResult(ResultCode.DATA_ERROR);
return ResponseGenerator.fail(StatusCode.DATA_ERROR);
}
......
......@@ -56,7 +56,7 @@
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>2.5.4</version>
<version>${dynamic-datasource.version}</version>
</dependency>
<!--多数据源支持 End-->
......
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