Commit acd1f70c by wubh

包活干V1.9.0-新增:平台保险、长城欧了保险相关文件 - wubh

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@26981 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 14acb7d9
Showing 55 changed files with 3885 additions and 43 deletions
package com.glsx.ordercenter.constants;
/**
*
*
* @Title ResultCodeEnum.java
* @Package com.glsx.manager.constants
* @Description TODO
......@@ -107,16 +107,16 @@ public enum ResultCodeEnum {
*/
DEVICE_REPERTORY_NOT_EXIST(5200, "用户没有库存"),
DEVICE_REPERTORY_NOT_ENOUGH(5201, "用户库存不足"),
/**
* 服务项目相关
*/
SERVICE_ITEM_SERVICE_CODE_EXIST(5300, "服务代码重复"),
/**
* 对账单相关
*/
RECONCILIATION_MONTHLY_GENERATING(5400,"对账单生成中,请稍后重试"),
RECONCILIATION_AUDIT(5401,"有对账详单被运营审核,不支持重新生成"),
......@@ -128,34 +128,44 @@ public enum ResultCodeEnum {
SOUCHE_SIGN_EXCEPTION(2,"校验签名发生错误"),
/**
* 保单-导出数据过多
*/
INSURANCE_EXPORT_TO_MANY(1, "保单导出数据量大于5000条,请条件过滤后重新导出"),
INSURANCE_ID_NOT_FOUND(2, "无法根据保单ID获取保单数据"),
INSURANCE_EXPORT_NOT_SUPPORTED(3, "非页面请求,无法导出保单"),
INSURANCE_PDF_NOT_FOUND(4, "无法获取到保单相关的PDF文件"),
INSURANCE_API_FAIL(5, "TSP保险接口异常"),
INSURANCE_UPDATE_ERROR(6, "修改保单状态异常"),
;
/**
*状态码
*状态码
*/
private int code;
/**
* 状态码对应的信息
*/
private String msg;
ResultCodeEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
return this.code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
return this.msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
package com.glsx.ordercenter.constants.insurance;
/**
* <p>Description: 证件类型
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public enum InsuranceCardType {
/**
* 身份证
*/
ID_CARD(1, "身份证"),
/**
* 统一社会信用代码
*/
CREDIT_CODE(2, "统一社会信用代码"),
/**
* 其他
*/
OTHER(3, "其他"),
;
private final Integer type;
private final String typeText;
InsuranceCardType(Integer type, String typeText) {
this.type = type;
this.typeText = typeText;
}
public static Integer getType(String typeText) {
Integer type = null;
InsuranceCardType[] values = InsuranceCardType.values();
for (InsuranceCardType value : values) {
if (value.typeText.equalsIgnoreCase(typeText)) {
type = value.type;
break;
}
}
return type;
}
public static String getTypeText(int type) {
String typeText = null;
InsuranceCardType[] values = InsuranceCardType.values();
for (InsuranceCardType value : values) {
if (value.type == type) {
typeText = value.typeText;
break;
}
}
return typeText;
}
public Integer getType() {
return this.type;
}
public String getTypeText() {
return this.typeText;
}
}
package com.glsx.ordercenter.constants.insurance;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public enum InsuranceCompany {
SINOSAFE("华安", "sinosafe"),
SINOFD("富德", "sinofd"),
SINOSIG("阳光", "sinosig"),
PICC("人保", "picc"),
;
private final String companyName;
private final String companyCode;
InsuranceCompany(String companyName, String companyCode) {
this.companyName = companyName;
this.companyCode = companyCode;
}
public String getCompanyName() {
return this.companyName;
}
public String getCompanyCode() {
return this.companyCode;
}
}
package com.glsx.ordercenter.constants.insurance;
/**
* <p>Description: 客户类型
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public enum InsuranceCustomerType {
/**
* 个人
*/
INDIVIDUAL(1, "个人"),
/**
* 企业
*/
ENTERPRISE(2, "企业"),
;
private final Integer type;
private final String typeText;
InsuranceCustomerType(Integer type, String typeText) {
this.type = type;
this.typeText = typeText;
}
public static Integer getType(String typeName) {
Integer type = null;
InsuranceCustomerType[] values = InsuranceCustomerType.values();
for (InsuranceCustomerType value : values) {
if (value.typeText.equalsIgnoreCase(typeName)) {
type = value.type;
break;
}
}
return type;
}
public static String getTypeText(int type) {
String typeText = null;
InsuranceCustomerType[] values = InsuranceCustomerType.values();
for (InsuranceCustomerType value : values) {
if (value.type == type) {
typeText = value.typeText;
break;
}
}
return typeText;
}
public Integer getType() {
return this.type;
}
public String getTypeText() {
return this.typeText;
}
}
package com.glsx.ordercenter.constants.insurance;
/**
* <p>Description: 保单来源
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-27
*/
public enum InsuranceSource {
/**
* 长城欧了
*/
ORA(1, "ora", "长城欧了");
private final Integer company;
private final String companyCode;
private final String companyText;
InsuranceSource(Integer company, String companyCode, String companyText) {
this.company = company;
this.companyCode = companyCode;
this.companyText = companyText;
}
public static Integer getCompany(String companyCode) {
Integer company = null;
InsuranceSource[] values = InsuranceSource.values();
for (InsuranceSource value : values) {
if (value.companyCode.equalsIgnoreCase(companyCode)) {
company = value.company;
break;
}
}
return company;
}
public static String getCompanyCode(int company) {
String companyCode = null;
InsuranceSource[] values = InsuranceSource.values();
for (InsuranceSource value : values) {
if (value.company == company) {
companyCode = value.companyCode;
break;
}
}
return companyCode;
}
public Integer getCompany() {
return this.company;
}
public String getCompanyCode() {
return this.companyCode;
}
public String getCompanyText() {
return this.companyText;
}
}
package com.glsx.ordercenter.constants.insurance;
/**
* <p>Description: 保单状态
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public enum InsuranceStatus {
/**
* 待投保
*/
TO_APPLY(1, "待投保"),
/**
* 已投保
*/
APPLIED(2, "已投保"),
/**
* 待退保
*/
TO_REFUND(3, "待退保"),
/**
* 已退保
*/
REFUNDED(9, "已退保"),
;
private final Integer status;
private final String statusText;
InsuranceStatus(Integer status, String statusText) {
this.status = status;
this.statusText = statusText;
}
public static Integer getStatus(String statusText) {
InsuranceStatus[] values = InsuranceStatus.values();
Integer status = null;
for (InsuranceStatus value : values) {
if (value.statusText.equalsIgnoreCase(statusText)) {
status = value.status;
break;
}
}
return status;
}
public static String getStatusText(int status) {
InsuranceStatus[] values = InsuranceStatus.values();
String statusText = null;
for (InsuranceStatus value : values) {
if (value.status == status) {
statusText = value.statusText;
break;
}
}
return statusText;
}
public Integer getStatus() {
return this.status;
}
public String getStatusText() {
return this.statusText;
}
}
package com.glsx.ordercenter.constants.insurance;
import com.glsx.common.utils.PropertiesUtil;
/**
* <p>Description: TSP可调用方法配置类
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-27
*/
public enum InsuranceTspMethod {
/**
* 投保
*/
APPLY("ora.tsp.method.apply"),
/**
* 查询
*/
QUERY("ora.tsp.method.query"),
/**
* 获取PDF
*/
PDF("ora.tsp.method.pdf"),
/**
* 修改
*/
UPDATE("ora.tsp.method.update"),
/**
* 退保
*/
REFUND("ora.tsp.method.refund"),
;
private final String key;
InsuranceTspMethod(String key) {
this.key = key;
}
public String get() {
return PropertiesUtil.getProperty(this.key);
}
public String getKey() {
return this.key;
}
}
package com.glsx.ordercenter.constants.insurance;
/**
* <p>Description: 长城欧了返回状态码
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-26
*/
public enum OraInsuranceResultCode {
/**
* 操作成功
*/
SUCCESS(0, "操作成功"),
/**
* 服务器内部错误
*/
SERVER_ERROR(1, "服务器内部错误"),
/**
* 输入参数有误
*/
PARAM_ERROR(11, "输入参数有误"),
/**
* AK参数不存在
*/
AK_NOT_FOUND(101, "AK参数不存在"),
/**
* APP不存在,AK有误请检查再重试
*/
AK_INVALID(200, "APP不存在,AK有误请检查再重试"),
/**
* APP被禁用
*/
APP_FORBIDDEN(201, "APP被禁用"),
/**
* APP IP校验失败
*/
APP_INVALID(210, "APP IP校验失败"),
/**
* 配额超限,限制访问
*/
RESTRICTED(301, "配额超限,限制访问"),
/**
* 当前并发量已经超过约定并发配额,限制访问
*/
TPS_RESTRICTED(401, "当前并发量已经超过约定并发配额,限制访问"),
;
private final int code;
private final String message;
OraInsuranceResultCode(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return this.code;
}
public String getMessage() {
return this.message;
}
}
package com.glsx.ordercenter.controller.api;
import com.glsx.ordercenter.constants.insurance.OraInsuranceResultCode;
import com.glsx.ordercenter.controller.common.BaseOrderController;
import com.glsx.ordercenter.dto.common.BaseOrderResponse;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-27
*/
public abstract class OraBaseController extends BaseOrderController {
protected <T extends BaseOrderResponse> T oraWebOk(T baseResponse) {
//baseResponse.setCode(OraInsuranceResultCode.SUCCESS.getCode());
//baseResponse.setMessage(OraInsuranceResultCode.SUCCESS.getMessage());
baseResponse.setSuccess(null);
return baseResponse;
}
protected <T extends BaseOrderResponse> T oraWebOops(Throwable t, T baseResponse) {
super.logError("长城欧了Controller异常", t);
baseResponse.setSuccess(null);
baseResponse.setCode(OraInsuranceResultCode.SERVER_ERROR.getCode());
baseResponse.setMessage(OraInsuranceResultCode.SERVER_ERROR.getMessage());
return baseResponse;
}
protected <T extends BaseOrderResponse> T oraWebOops(OraInsuranceResultCode code, Throwable t,
T baseResponse) {
super.logError("长城欧了Controller异常", t);
baseResponse.setSuccess(null);
baseResponse.setCode(code.getCode());
baseResponse.setMessage(code.getMessage());
return baseResponse;
}
}
package com.glsx.ordercenter.controller.api;
import com.glsx.ordercenter.dto.api.OraInsuranceRefundReq;
import com.glsx.ordercenter.dto.api.OraInsuranceRefundResp;
import com.glsx.ordercenter.dto.api.OraInsuranceUpdateReq;
import com.glsx.ordercenter.dto.api.OraInsuranceUpdateResp;
import com.glsx.ordercenter.exception.insurance.OraBizException;
import com.glsx.ordercenter.service.api.OraInsuranceRefundService;
import com.glsx.ordercenter.service.api.OraInsuranceUpdateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>Description: 长城欧了-保单接口
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
@RestController
@RequestMapping("/ora-insurance")
public class OraInsuranceController extends OraBaseController {
@Autowired
private OraInsuranceUpdateService insuranceUpdateService;
@Autowired
private OraInsuranceRefundService insuranceRefundService;
@RequestMapping(value = "/update", method = RequestMethod.POST)
public OraInsuranceUpdateResp update(@RequestBody OraInsuranceUpdateReq insuranceUpdateReq) {
super.logInfo("长城修改保单-参数", insuranceUpdateReq);
OraInsuranceUpdateResp insuranceUpdateResp;
try {
insuranceUpdateResp = super.oraWebOk(
this.insuranceUpdateService.update(insuranceUpdateReq));
} catch (OraBizException e) {
insuranceUpdateResp = super.oraWebOops(e.getCode(), e, new OraInsuranceUpdateResp());
} catch (RuntimeException e) {
insuranceUpdateResp = super.oraWebOops(e, new OraInsuranceUpdateResp());
}
super.logInfo("长城修改保单-结果", insuranceUpdateResp);
return insuranceUpdateResp;
}
@RequestMapping(value = "/refund", method = RequestMethod.POST)
public OraInsuranceRefundResp refund(@RequestBody OraInsuranceRefundReq insuranceRefundReq) {
super.logInfo("长城退保-参数", insuranceRefundReq);
OraInsuranceRefundResp insuranceRefundResp;
try {
insuranceRefundResp = super.oraWebOk(
this.insuranceRefundService.refund(insuranceRefundReq));
} catch (OraBizException e) {
insuranceRefundResp = super.oraWebOops(e.getCode(), e, new OraInsuranceRefundResp());
} catch (RuntimeException e) {
insuranceRefundResp = super.oraWebOops(e, new OraInsuranceRefundResp());
}
super.logInfo("长城退保-结果", insuranceRefundResp);
return insuranceRefundResp;
}
}
package com.glsx.ordercenter.controller.api;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
......@@ -13,16 +17,10 @@ import com.glsx.ordercenter.service.OraOrderService;
import com.glsx.ordercenter.utils.OraOperationUtil;
import com.glsx.ordercenter.utils.OraSignUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author think.wang
* @version 1.9.0
......@@ -35,13 +33,13 @@ import java.util.Map;
@RequestMapping(("/api/ora"))
public class OraOrderController extends BaseController {
@Value("${ora.api.url}")
//@Value("${ora.api.url}")
private String serverUrl;
@Value("${ora.appKey}")
//@Value("${ora.appKey}")
private String appKey;
@Value("${ora.appSecret}")
//@Value("${ora.appSecret}")
private String appSecret;
@Autowired
......@@ -50,14 +48,14 @@ public class OraOrderController extends BaseController {
@RequestMapping(value = "/saveCarOrder", method = RequestMethod.POST)
public String saveCarOrder(HttpServletRequest request) {
OraParamsReq oraParams = OraOperationUtil.getUrlParams(request);
logger.info("/api/ora/saveCarOrder接口请求参数:{}", oraParams.toString());
this.logger.info("/api/ora/saveCarOrder接口请求参数:{}", oraParams.toString());
List<OraResultObject> list = new ArrayList<>();
try {
//验签操作
Map<String, String> paramsMap = OraOperationUtil.objectToMap(oraParams);
String sign = OraSignUtil.sign(paramsMap, null, appSecret); //加密操作
if (!sign.equals(oraParams.getSign()) || !appKey.equals(oraParams.getAppkey())) {
logger.info("/api/ora/saveCarOrder接口验签失败:{}", sign);
String sign = OraSignUtil.sign(paramsMap, null, this.appSecret); //加密操作
if (!sign.equals(oraParams.getSign()) || !this.appKey.equals(oraParams.getAppkey())) {
this.logger.info("/api/ora/saveCarOrder接口验签失败:{}", sign);
list.add(new OraResultObject(ResultCodeEnum.SING_ERROR));
return JSON.toJSONString(list);
}
......@@ -72,34 +70,34 @@ public class OraOrderController extends BaseController {
for (int i = 0; i < len; i++) {
SysOrder order = this.orderDataTrans(jsonArray.getJSONObject(i));
try {
list.add(oraOrderService.save(order));
list.add(this.oraOrderService.save(order));
} catch (Exception e) {
logger.error("工单保存失败:{}", order.toString());
this.logger.error("工单保存失败:{}", order.toString());
list.add(new OraResultObject(ResultCodeEnum.ERROR, order.getWorkOrderNo()));
}
}
}
} catch (Exception e) {
logger.error("/api/ora/saveCarOrder接口异常:{}", e);
this.logger.error("/api/ora/saveCarOrder接口异常:{}", e);
list.add(new OraResultObject(ResultCodeEnum.ERROR));
return JSON.toJSONString(list);
}
String str = JSON.toJSONString(list);
logger.info("/api/ora/saveCarOrder接口处理数据返回结果:{}", str);
this.logger.info("/api/ora/saveCarOrder接口处理数据返回结果:{}", str);
return str;
}
@RequestMapping(value = "/updateCarOrder", method = RequestMethod.POST)
public String updateCarOrder(HttpServletRequest request) {
OraParamsReq oraParams = OraOperationUtil.getUrlParams(request);
logger.info("/api/ora/updateCarOrder接口请求参数:{}", oraParams.toString());
this.logger.info("/api/ora/updateCarOrder接口请求参数:{}", oraParams.toString());
List<OraResultObject> list = new ArrayList<>();
try {
//验签操作
Map<String, String> paramsMap = OraOperationUtil.objectToMap(oraParams);
String sign = OraSignUtil.sign(paramsMap, null, appSecret); //加密操作
if (!sign.equals(oraParams.getSign()) || !appKey.equals(oraParams.getAppkey())) {
logger.info("/api/ora/updateCarOrder接口验签失败:{}", sign);
String sign = OraSignUtil.sign(paramsMap, null, this.appSecret); //加密操作
if (!sign.equals(oraParams.getSign()) || !this.appKey.equals(oraParams.getAppkey())) {
this.logger.info("/api/ora/updateCarOrder接口验签失败:{}", sign);
list.add(new OraResultObject(ResultCodeEnum.SING_ERROR));
return JSON.toJSONString(list);
}
......@@ -114,34 +112,34 @@ public class OraOrderController extends BaseController {
for (int i = 0; i < len; i++) {
SysOrder order = this.orderDataTrans(jsonArray.getJSONObject(i));
try {
list.add(oraOrderService.update(order));
list.add(this.oraOrderService.update(order));
} catch (Exception e) {
logger.error("工单更新失败:{}", order.toString());
this.logger.error("工单更新失败:{}", order.toString());
list.add(new OraResultObject(ResultCodeEnum.ERROR, order.getWorkOrderNo()));
}
}
}
} catch (Exception e) {
logger.error("/api/ora/updateCarOrder接口异常:{}", e);
this.logger.error("/api/ora/updateCarOrder接口异常:{}", e);
list.add(new OraResultObject(ResultCodeEnum.ERROR));
return JSON.toJSONString(list);
}
String str = JSON.toJSONString(list);
logger.info("/api/ora/updateCarOrder接口处理数据返回结果:{}", str);
this.logger.info("/api/ora/updateCarOrder接口处理数据返回结果:{}", str);
return str;
}
@RequestMapping(value = "/cancelCarOrder", method = RequestMethod.POST)
public String cancelCarOrder(HttpServletRequest request) {
OraParamsReq oraParams = OraOperationUtil.getUrlParams(request);
logger.info("/api/ora/cancelCarOrder接口请求参数:{}", oraParams.toString());
this.logger.info("/api/ora/cancelCarOrder接口请求参数:{}", oraParams.toString());
List<OraResultObject> list = new ArrayList<>();
try {
//验签操作
Map<String, String> paramsMap = OraOperationUtil.objectToMap(oraParams);
String sign = OraSignUtil.sign(paramsMap, null, appSecret); //加密操作
if (!sign.equals(oraParams.getSign()) || !appKey.equals(oraParams.getAppkey())) {
logger.info("/api/ora/cancelCarOrder接口验签失败:{}", sign);
String sign = OraSignUtil.sign(paramsMap, null, this.appSecret); //加密操作
if (!sign.equals(oraParams.getSign()) || !this.appKey.equals(oraParams.getAppkey())) {
this.logger.info("/api/ora/cancelCarOrder接口验签失败:{}", sign);
list.add(new OraResultObject(ResultCodeEnum.SING_ERROR));
return JSON.toJSONString(list);
}
......@@ -154,15 +152,15 @@ public class OraOrderController extends BaseController {
list.add(new OraResultObject(ResultCodeEnum.FAIL.getCode(), "一次最多处理10条工单"));
return JSON.toJSONString(list);
}
list = oraOrderService.cancelOrder(orderIds, BizConstants.CC_ORA);
list = this.oraOrderService.cancelOrder(orderIds, BizConstants.CC_ORA);
}
} catch (Exception e) {
logger.error("/api/ora/cancelCarOrder接口异常:{}", e);
this.logger.error("/api/ora/cancelCarOrder接口异常:{}", e);
list.add(new OraResultObject(ResultCodeEnum.ERROR));
return JSON.toJSONString(list);
}
String str = JSON.toJSONString(list);
logger.info("/api/ora/cancelCarOrder接口处理数据返回结果:{}", str);
this.logger.info("/api/ora/cancelCarOrder接口处理数据返回结果:{}", str);
return str;
}
......
package com.glsx.ordercenter.controller.common;
import com.glsx.common.constants.ResultCodeEnum;
import com.glsx.common.constants.ResultObject;
import com.glsx.ordercenter.dto.common.BaseOrderResponse;
import com.glsx.ordercenter.utils.LogUtils;
/**
* <p>Description: Controller基类
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public abstract class BaseOrderController {
private static final String LOG_PREFIX = "Controller-";
protected <T extends BaseOrderResponse> ResultObject webOk(T baseResponse) {
ResultObject resultObject;
//if (baseResponse.getSuccess()) {
// resultObject = new ResultObject(ResultCodeEnum.SUCCESS, baseResponse);
//} else {
// resultObject = new ResultObject(ResultCodeEnum.ERROR, baseResponse);
//}
resultObject = new ResultObject(baseResponse.getCode(), baseResponse.getMessage(),
baseResponse);
return resultObject;
}
protected <T extends BaseOrderResponse> ResultObject webOops(Throwable t,
T baseResponse) {
this.logError("Controller异常", t);
return new ResultObject(ResultCodeEnum.ERROR, baseResponse);
}
protected void logInfo(String msg, Object... params) {
LogUtils.logInfo(this.getClass(), LOG_PREFIX + msg, params);
}
protected void logError(String msg, Throwable t, Object... params) {
LogUtils.logError(this.getClass(), LOG_PREFIX + msg, t, params);
}
}
package com.glsx.ordercenter.controller.insurance;
import com.glsx.common.constants.ResultObject;
import com.glsx.ordercenter.controller.common.BaseOrderController;
import com.glsx.ordercenter.dto.common.PagedOrderResponse;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailReq;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailResp;
import com.glsx.ordercenter.dto.insurance.InsuranceQueryReq;
import com.glsx.ordercenter.dto.insurance.InsuranceQueryResp;
import com.glsx.ordercenter.dto.insurance.InsuranceRefundReq;
import com.glsx.ordercenter.dto.insurance.InsuranceRefundResp;
import com.glsx.ordercenter.service.insurance.InsuranceDetailService;
import com.glsx.ordercenter.service.insurance.InsuranceDownloadService;
import com.glsx.ordercenter.service.insurance.InsuranceQueryService;
import com.glsx.ordercenter.service.insurance.InsuranceRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>Description: 保单列表查询
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
@RestController
@RequestMapping("/insurance")
public class InsuranceController extends BaseOrderController {
@Autowired
private InsuranceQueryService insuranceQueryService;
@Autowired
private InsuranceDetailService insuranceDetailService;
@Autowired
private InsuranceDownloadService insuranceDownloadService;
@Autowired
private InsuranceRefundService insuranceRefundService;
/**
* 获取保单列表
*
* @param insuranceQueryReq 请求体
* @return 查询结果
*/
@RequestMapping(value = "/getList", method = RequestMethod.POST)
public ResultObject query(@RequestBody InsuranceQueryReq insuranceQueryReq) {
super.logInfo("保单列表查询-参数", insuranceQueryReq);
ResultObject resultObject;
PagedOrderResponse<InsuranceQueryResp> pagedOrderResponse;
pagedOrderResponse = this.insuranceQueryService.query(insuranceQueryReq);
resultObject = super.webOk(pagedOrderResponse);
super.logInfo("保单列表查询-结果", resultObject);
return resultObject;
}
/**
* 获取保单详情
*
* @param insuranceDetailReq 请求体
* @return 保单详情
*/
//@AuthCheck
@RequestMapping(value = "/detail", method = RequestMethod.POST)
public ResultObject detail(@RequestBody InsuranceDetailReq insuranceDetailReq) {
super.logInfo("保单详情查询-参数", insuranceDetailReq);
ResultObject resultObject;
PagedOrderResponse<InsuranceDetailResp> pagedOrderResponse;
pagedOrderResponse = this.insuranceDetailService.detail(insuranceDetailReq);
resultObject = super.webOk(pagedOrderResponse);
super.logInfo("保单详情查询-结果", resultObject);
return resultObject;
}
/**
* 下载保单PDF
*
* @param insuranceDetailReq 请求体
*/
//@AuthCheck
@RequestMapping(value = "/download", method = RequestMethod.POST)
public ResultObject download(@RequestBody InsuranceDetailReq insuranceDetailReq) {
super.logInfo("下载保单-参数", insuranceDetailReq);
ResultObject resultObject;
//ServletRequestAttributes requestAttributes =
// (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//HttpServletResponse response = requestAttributes.getResponse();
InsuranceDetailResp insuranceDetailResp =
this.insuranceDownloadService.download(insuranceDetailReq);
//try {
// response.sendRedirect(insuranceDetailResp.getInsurancePdf());
//} catch (IOException e) {
// super.logError("保单下载异常", e);
//}
resultObject = super.webOk(insuranceDetailResp);
super.logInfo("下载保单-结果", resultObject);
return resultObject;
}
/**
* 退保
*
* @param insuranceRefundReq 请求体
* @return 退保结果
*/
//@AuthCheck
@RequestMapping(value = "/refund", method = RequestMethod.POST)
public ResultObject refund(@RequestBody InsuranceRefundReq insuranceRefundReq) {
super.logInfo("退保-参数", insuranceRefundReq);
InsuranceRefundResp insuranceRefundResp =
this.insuranceRefundService.refund(insuranceRefundReq);
ResultObject resultObject = super.webOk(insuranceRefundResp);
super.logInfo("退保-结果", resultObject);
return resultObject;
}
}
package com.glsx.ordercenter.dto.api;
import com.glsx.ordercenter.dto.common.BaseOrderRequest;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class OraBaseRequest extends BaseOrderRequest {
}
package com.glsx.ordercenter.dto.api;
import com.glsx.ordercenter.dto.common.BaseOrderResponse;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class OraBaseResponse extends BaseOrderResponse {
}
package com.glsx.ordercenter.dto.api;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class OraInsuranceRefundReq extends OraBaseRequest {
/**
* 聚合保单ID(唯一不变值)
*/
private String insuranceId;
/**
* 作废原因
*/
private String reason;
public String getInsuranceId() {
return this.insuranceId;
}
public void setInsuranceId(String insuranceId) {
this.insuranceId = insuranceId;
}
public String getReason() {
return this.reason;
}
public void setReason(String reason) {
this.reason = reason;
}
@Override
public String toString() {
return "OraInsuranceRefundReq{" +
"insuranceId='" + this.insuranceId + '\'' +
", reason='" + this.reason + '\'' +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.api;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class OraInsuranceRefundResp extends OraBaseResponse {
/**
* 保单ID
*/
private String insuranceId;
public String getInsuranceId() {
return this.insuranceId;
}
public void setInsuranceId(String insuranceId) {
this.insuranceId = insuranceId;
}
@Override
public String toString() {
return "OraInsuranceRefundResp{" +
"insuranceId='" + this.insuranceId + '\'' +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.api;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class OraInsuranceUpdateReq extends OraBaseRequest {
/**
* 聚合保单ID(唯一不变值)
*/
private String insuranceId;
/**
* 投保设备SN
*/
private String gpsNo;
/**
* 设备安装时间(格式yyyy-MM-dd HH:mm:ss)
*/
private String installationTime;
/**
* 车架号
*/
private String vin;
/**
* 车牌号
*/
private String vehicleNo;
/**
* 发动机号
*/
private String engineNumber;
/**
* 品牌车型
*/
private String carBrand;
/**
* 车辆类型(1:新车、2:二手车、3:进口车)
*/
private String vehicleType;
/**
* 车主姓名
*/
private String vehicleOwnerName;
/**
* 车主电话
*/
private String phone;
/**
* 车主地址
*/
private String vehicleOwnerAddress;
/**
* 证件号码
*/
private String idCardNum;
/**
* 保险商品(1:盗抢监控服务)
*/
private String insuranceCommodity;
/**
* 盗抢险额
*/
private String pilferInsuranceMoney;
/**
* 盗抢保障服务费
*/
private String insuranceMoney;
/**
* 保险期限
*/
private String insurancePeriod;
/**
* 车辆开票价格
*/
private String vehicleInvoiceMoney;
/**
* 结算单位
*/
private String settlementUnit;
/**
* 受偿单位
*/
private String tastingUnit;
/**
* 客户标识(见表1-3)
*/
private Integer customerId;
/**
* 初次登记日期(格式yyyy-MM-dd)
*/
private String registrationDate;
public String getInsuranceId() {
return this.insuranceId;
}
public void setInsuranceId(String insuranceId) {
this.insuranceId = insuranceId;
}
public String getGpsNo() {
return this.gpsNo;
}
public void setGpsNo(String gpsNo) {
this.gpsNo = gpsNo;
}
public String getInstallationTime() {
return this.installationTime;
}
public void setInstallationTime(String installationTime) {
this.installationTime = installationTime;
}
public String getVin() {
return this.vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getVehicleNo() {
return this.vehicleNo;
}
public void setVehicleNo(String vehicleNo) {
this.vehicleNo = vehicleNo;
}
public String getEngineNumber() {
return this.engineNumber;
}
public void setEngineNumber(String engineNumber) {
this.engineNumber = engineNumber;
}
public String getCarBrand() {
return this.carBrand;
}
public void setCarBrand(String carBrand) {
this.carBrand = carBrand;
}
public String getVehicleType() {
return this.vehicleType;
}
public void setVehicleType(String vehicleType) {
this.vehicleType = vehicleType;
}
public String getVehicleOwnerName() {
return this.vehicleOwnerName;
}
public void setVehicleOwnerName(String vehicleOwnerName) {
this.vehicleOwnerName = vehicleOwnerName;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getVehicleOwnerAddress() {
return this.vehicleOwnerAddress;
}
public void setVehicleOwnerAddress(String vehicleOwnerAddress) {
this.vehicleOwnerAddress = vehicleOwnerAddress;
}
public String getIdCardNum() {
return this.idCardNum;
}
public void setIdCardNum(String idCardNum) {
this.idCardNum = idCardNum;
}
public String getInsuranceCommodity() {
return this.insuranceCommodity;
}
public void setInsuranceCommodity(String insuranceCommodity) {
this.insuranceCommodity = insuranceCommodity;
}
public String getPilferInsuranceMoney() {
return this.pilferInsuranceMoney;
}
public void setPilferInsuranceMoney(String pilferInsuranceMoney) {
this.pilferInsuranceMoney = pilferInsuranceMoney;
}
public String getInsuranceMoney() {
return this.insuranceMoney;
}
public void setInsuranceMoney(String insuranceMoney) {
this.insuranceMoney = insuranceMoney;
}
public String getInsurancePeriod() {
return this.insurancePeriod;
}
public void setInsurancePeriod(String insurancePeriod) {
this.insurancePeriod = insurancePeriod;
}
public String getVehicleInvoiceMoney() {
return this.vehicleInvoiceMoney;
}
public void setVehicleInvoiceMoney(String vehicleInvoiceMoney) {
this.vehicleInvoiceMoney = vehicleInvoiceMoney;
}
public String getSettlementUnit() {
return this.settlementUnit;
}
public void setSettlementUnit(String settlementUnit) {
this.settlementUnit = settlementUnit;
}
public String getTastingUnit() {
return this.tastingUnit;
}
public void setTastingUnit(String tastingUnit) {
this.tastingUnit = tastingUnit;
}
public Integer getCustomerId() {
return this.customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public String getRegistrationDate() {
return this.registrationDate;
}
public void setRegistrationDate(String registrationDate) {
this.registrationDate = registrationDate;
}
@Override
public String toString() {
return "OraInsuranceUpdateReq{" +
"insuranceId='" + this.insuranceId + '\'' +
", gpsNo='" + this.gpsNo + '\'' +
", installationTime='" + this.installationTime + '\'' +
", vin='" + this.vin + '\'' +
", vehicleNo='" + this.vehicleNo + '\'' +
", engineNumber='" + this.engineNumber + '\'' +
", carBrand='" + this.carBrand + '\'' +
", vehicleType='" + this.vehicleType + '\'' +
", vehicleOwnerName='" + this.vehicleOwnerName + '\'' +
", phone='" + this.phone + '\'' +
", vehicleOwnerAddress='" + this.vehicleOwnerAddress + '\'' +
", idCardNum='" + this.idCardNum + '\'' +
", insuranceCommodity='" + this.insuranceCommodity + '\'' +
", pilferInsuranceMoney='" + this.pilferInsuranceMoney + '\'' +
", insuranceMoney='" + this.insuranceMoney + '\'' +
", insurancePeriod='" + this.insurancePeriod + '\'' +
", vehicleInvoiceMoney='" + this.vehicleInvoiceMoney + '\'' +
", settlementUnit='" + this.settlementUnit + '\'' +
", tastingUnit='" + this.tastingUnit + '\'' +
", customerId=" + this.customerId +
", registrationDate='" + this.registrationDate + '\'' +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.api;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class OraInsuranceUpdateResp extends OraBaseResponse {
/**
* 保单ID
*/
private String insuranceId;
public String getInsuranceId() {
return this.insuranceId;
}
public void setInsuranceId(String insuranceId) {
this.insuranceId = insuranceId;
}
@Override
public String toString() {
return "OraInsuranceUpdateResp{" +
"insuranceId='" + this.insuranceId + '\'' +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.common;
import java.io.Serializable;
import com.glsx.common.utils.Page;
/**
* <p>Description: 分页查询基类
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public abstract class BaseOrderRequest implements Serializable {
/**
* 页码
*/
private Integer pageIndex = Page.DEFAULT_PAGE_INDEX;
/**
* 每页大小
*/
private Integer pageSize = Page.DEFAULT_PAGE_SIZE;
public Integer getPageIndex() {
return this.pageIndex;
}
public void setPageIndex(Integer pageIndex) {
this.pageIndex = pageIndex;
}
public Integer getPageSize() {
return this.pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
@Override
public String toString() {
return "BaseOrderRequest{" +
"pageIndex=" + this.pageIndex +
", pageSize=" + this.pageSize +
'}';
}
}
package com.glsx.ordercenter.dto.common;
import java.io.Serializable;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public abstract class BaseOrderResponse implements Serializable {
/**
* 是否成功
*/
private Boolean success;
/**
* 状态码
*/
private Integer code;
/**
* 信息
*/
private String message;
public Boolean getSuccess() {
return this.success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public Integer getCode() {
return this.code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return "BaseOrderResponse{" +
"success=" + this.success +
", code=" + this.code +
", message='" + this.message + '\'' +
'}';
}
}
package com.glsx.ordercenter.dto.common;
import java.util.List;
import com.glsx.common.utils.Page;
/**
* <p>Description: 分页查询的通用结果
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public class PagedOrderResponse<E> extends BaseOrderResponse {
private Page page;
private List<E> items;
public PagedOrderResponse() {}
private PagedOrderResponse(Page page, List<E> items) {
this.page = page;
this.items = items;
}
public static <E> PagedOrderResponse<E> of(long totalCount, BaseOrderRequest baseOrderRequest,
List<E> list) {
Page page = new Page(baseOrderRequest.getPageIndex(),
baseOrderRequest.getPageSize());
page.setTotalCount((int) totalCount);
return of(page, list);
}
public static <E> PagedOrderResponse<E> of(Page page, List<E> list) {
return new PagedOrderResponse<>(page, list);
}
public Page getPage() {
return this.page;
}
public void setPage(Page page) {
this.page = page;
}
public List<E> getItems() {
return this.items;
}
public void setItems(List<E> items) {
this.items = items;
}
@Override
public String toString() {
return "PagedOrderResponse{" +
"page=" + this.page +
", items=" + this.items +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.insurance;
/**
* <p>Description: 保单详情请求体
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public class InsuranceDetailReq extends InsuranceQueryReq {
}
package com.glsx.ordercenter.dto.insurance;
/**
* <p>Description: 保单详情响应体
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public class InsuranceDetailResp extends InsuranceQueryResp {
/**
* 客户类型
*/
private Byte customerType;
/**
* 联系地址
*/
private String vehicleOwnerAddress;
/**
* 车辆颜色
*/
private String vehicleColor;
/**
* PDF地址
*/
private String insurancePdf;
public Byte getCustomerType() {
return this.customerType;
}
public void setCustomerType(Byte customerType) {
this.customerType = customerType;
}
public String getVehicleOwnerAddress() {
return this.vehicleOwnerAddress;
}
public void setVehicleOwnerAddress(String vehicleOwnerAddress) {
this.vehicleOwnerAddress = vehicleOwnerAddress;
}
public String getVehicleColor() {
return this.vehicleColor;
}
public void setVehicleColor(String vehicleColor) {
this.vehicleColor = vehicleColor;
}
public String getInsurancePdf() {
return this.insurancePdf;
}
public void setInsurancePdf(String insurancePdf) {
this.insurancePdf = insurancePdf;
}
@Override
public String toString() {
return "InsuranceDetailResp{" +
"customerType=" + this.customerType +
", vehicleOwnerAddress='" + this.vehicleOwnerAddress + '\'' +
", vehicleColor='" + this.vehicleColor + '\'' +
", insurancePdf='" + this.insurancePdf + '\'' +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.insurance;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.glsx.ordercenter.dto.common.BaseOrderRequest;
/**
* <p>Description: 保单列表请求体
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public class InsuranceQueryReq extends BaseOrderRequest {
/**
* 保单ID
*/
private Integer id;
/**
* 第三方ID
*/
private String insuranceId;
/**
* 车主姓名
*/
private String vehicleOwnerName;
/**
* 车架号
*/
private String vin;
/**
* 设备号
*/
private String gpsNo;
/**
* 保单状态
*/
private Byte status;
/**
* 提交时间起始
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date applyTimeStart;
/**
* 提交时间结束
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date applyTimeEnd;
/**
* 生效时间起始
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date startTimeStart;
/**
* 生效时间结束
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date startTimeEnd;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getInsuranceId() {
return this.insuranceId;
}
public void setInsuranceId(String insuranceId) {
this.insuranceId = insuranceId;
}
public String getVehicleOwnerName() {
return this.vehicleOwnerName;
}
public void setVehicleOwnerName(String vehicleOwnerName) {
this.vehicleOwnerName = vehicleOwnerName;
}
public String getVin() {
return this.vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getGpsNo() {
return this.gpsNo;
}
public void setGpsNo(String gpsNo) {
this.gpsNo = gpsNo;
}
public Byte getStatus() {
return this.status;
}
public void setStatus(Byte status) {
this.status = status;
}
public Date getApplyTimeStart() {
return this.applyTimeStart;
}
public void setApplyTimeStart(Date applyTimeStart) {
this.applyTimeStart = applyTimeStart;
}
public Date getApplyTimeEnd() {
return this.applyTimeEnd;
}
public void setApplyTimeEnd(Date applyTimeEnd) {
this.applyTimeEnd = applyTimeEnd;
}
public Date getStartTimeStart() {
return this.startTimeStart;
}
public void setStartTimeStart(Date startTimeStart) {
this.startTimeStart = startTimeStart;
}
public Date getStartTimeEnd() {
return this.startTimeEnd;
}
public void setStartTimeEnd(Date startTimeEnd) {
this.startTimeEnd = startTimeEnd;
}
@Override
public String toString() {
return "InsuranceQueryReq{" +
"id=" + this.id +
", insuranceId='" + this.insuranceId + '\'' +
", vehicleOwnerName='" + this.vehicleOwnerName + '\'' +
", vin='" + this.vin + '\'' +
", gpsNo='" + this.gpsNo + '\'' +
", status=" + this.status +
", applyTimeStart=" + this.applyTimeStart +
", applyTimeEnd=" + this.applyTimeEnd +
", startTimeStart=" + this.startTimeStart +
", startTimeEnd=" + this.startTimeEnd +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.insurance;
import com.glsx.excel.poi.annotation.ExcelColumn;
import com.glsx.excel.poi.annotation.ExcelExport;
import com.glsx.ordercenter.dto.common.BaseOrderResponse;
/**
* <p>Description: 保单列表响应体
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
@ExcelExport
public class InsuranceQueryResp extends BaseOrderResponse {
/**
* ID
*/
@ExcelColumn(value = "ID", index = 0)
private Integer id;
/**
* 第三方公司保单ID
*/
@ExcelColumn(value = "第三方公司保单ID", index = 1)
private String insuranceId;
/**
* 车主姓名
*/
@ExcelColumn(value = "车主姓名", index = 2)
private String vehicleOwnerName;
/**
* 联系电话
*/
@ExcelColumn(value = "联系电话", index = 3)
private String phone;
/**
* 车架号
*/
@ExcelColumn(value = "车架号", index = 4)
private String vin;
/**
* 设备号
*/
@ExcelColumn(value = "设备号", index = 5)
private String gpsNo;
/**
* 提交时间
*/
@ExcelColumn(value = "提交时间", index = 6)
private String applyTime;
/**
* 生效时间
*/
@ExcelColumn(value = "生效时间", index = 7)
private String expectedEffectiveTime;
/**
* 保单状态
*/
private Byte status;
/**
* 保单状态文本
*/
@ExcelColumn(value = "保单状态", index = 8)
private String statusText;
/**
* 投保期限(年)
*/
@ExcelColumn(value = "投保期限(年)", index = 9)
private Integer insurancePeriod;
/**
* 车牌号
*/
@ExcelColumn(value = "车牌号", index = 10)
private String vehicleNo;
/**
* 发动机号
*/
@ExcelColumn(value = "发动机号", index = 11)
private String engineNumber;
/**
* 品牌车型
*/
@ExcelColumn(value = "品牌车型", index = 12)
private String carBrand;
/**
* 证件类型
*/
private Byte idCardType;
/**
* 证件类型文本
*/
@ExcelColumn(value = "证件类型", index = 13)
private String idCardTypeText;
/**
* 证件号码
*/
@ExcelColumn(value = "证件号码", index = 14)
private String idCardNum;
/**
* 车辆价格
*/
@ExcelColumn(value = "车辆价格(元)", index = 15)
private String vehicleInvoiceMoney;
/**
* 第一受益人
*/
@ExcelColumn(value = "第一受益人", index = 16)
private String tastingUnit;
/**
* 备注(对方请求报文)
*/
@ExcelColumn(value = "备注", index = 17)
private String responseData;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getInsuranceId() {
return this.insuranceId;
}
public void setInsuranceId(String insuranceId) {
this.insuranceId = insuranceId;
}
public String getVehicleOwnerName() {
return this.vehicleOwnerName;
}
public void setVehicleOwnerName(String vehicleOwnerName) {
this.vehicleOwnerName = vehicleOwnerName;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getVin() {
return this.vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getGpsNo() {
return this.gpsNo;
}
public void setGpsNo(String gpsNo) {
this.gpsNo = gpsNo;
}
public String getApplyTime() {
return this.applyTime;
}
public void setApplyTime(String applyTime) {
this.applyTime = applyTime;
}
public String getExpectedEffectiveTime() {
return this.expectedEffectiveTime;
}
public void setExpectedEffectiveTime(String expectedEffectiveTime) {
this.expectedEffectiveTime = expectedEffectiveTime;
}
public Byte getStatus() {
return this.status;
}
public void setStatus(Byte status) {
this.status = status;
}
public String getStatusText() {
return this.statusText;
}
public void setStatusText(String statusText) {
this.statusText = statusText;
}
public Integer getInsurancePeriod() {
return this.insurancePeriod;
}
public void setInsurancePeriod(Integer insurancePeriod) {
this.insurancePeriod = insurancePeriod;
}
public String getVehicleNo() {
return this.vehicleNo;
}
public void setVehicleNo(String vehicleNo) {
this.vehicleNo = vehicleNo;
}
public String getEngineNumber() {
return this.engineNumber;
}
public void setEngineNumber(String engineNumber) {
this.engineNumber = engineNumber;
}
public String getCarBrand() {
return this.carBrand;
}
public void setCarBrand(String carBrand) {
this.carBrand = carBrand;
}
public Byte getIdCardType() {
return this.idCardType;
}
public void setIdCardType(Byte idCardType) {
this.idCardType = idCardType;
}
public String getIdCardTypeText() {
return this.idCardTypeText;
}
public void setIdCardTypeText(String idCardTypeText) {
this.idCardTypeText = idCardTypeText;
}
public String getIdCardNum() {
return this.idCardNum;
}
public void setIdCardNum(String idCardNum) {
this.idCardNum = idCardNum;
}
public String getVehicleInvoiceMoney() {
return this.vehicleInvoiceMoney;
}
public void setVehicleInvoiceMoney(String vehicleInvoiceMoney) {
this.vehicleInvoiceMoney = vehicleInvoiceMoney;
}
public String getTastingUnit() {
return this.tastingUnit;
}
public void setTastingUnit(String tastingUnit) {
this.tastingUnit = tastingUnit;
}
public String getResponseData() {
return this.responseData;
}
public void setResponseData(String responseData) {
this.responseData = responseData;
}
@Override
public String toString() {
return "InsuranceQueryResp{" +
"id=" + this.id +
", insuranceId='" + this.insuranceId + '\'' +
", vehicleOwnerName='" + this.vehicleOwnerName + '\'' +
", phone='" + this.phone + '\'' +
", vin='" + this.vin + '\'' +
", gpsNo='" + this.gpsNo + '\'' +
", applyTime='" + this.applyTime + '\'' +
", expectedEffectiveTime='" + this.expectedEffectiveTime + '\'' +
", status=" + this.status +
", statusText='" + this.statusText + '\'' +
", insurancePeriod=" + this.insurancePeriod +
", vehicleNo='" + this.vehicleNo + '\'' +
", engineNumber='" + this.engineNumber + '\'' +
", carBrand='" + this.carBrand + '\'' +
", idCardType=" + this.idCardType +
", idCardTypeText='" + this.idCardTypeText + '\'' +
", idCardNum='" + this.idCardNum + '\'' +
", vehicleInvoiceMoney='" + this.vehicleInvoiceMoney + '\'' +
", tastingUnit='" + this.tastingUnit + '\'' +
", responseData='" + this.responseData + '\'' +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.insurance;
import com.glsx.ordercenter.dto.common.BaseOrderRequest;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class InsuranceRefundReq extends BaseOrderRequest {
/**
* 保单ID
*/
private Integer id;
/**
* 第三方保单ID
*/
private String insuranceId;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getInsuranceId() {
return this.insuranceId;
}
public void setInsuranceId(String insuranceId) {
this.insuranceId = insuranceId;
}
@Override
public String toString() {
return "InsuranceRefundReq{" +
"id=" + this.id +
", insuranceId='" + this.insuranceId + '\'' +
"} " + super.toString();
}
}
package com.glsx.ordercenter.dto.insurance;
import com.glsx.ordercenter.dto.common.BaseOrderResponse;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class InsuranceRefundResp extends BaseOrderResponse {
}
package com.glsx.ordercenter.exception.insurance;
import com.alibaba.fastjson.JSON;
import com.glsx.ordercenter.constants.insurance.OraInsuranceResultCode;
/**
* <p>Description: 长城欧了业务异常
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-27
*/
public class OraBizException extends RuntimeException {
private OraInsuranceResultCode code;
private Object[] params;
public OraBizException(Throwable cause) {
super(cause);
}
public OraBizException(OraInsuranceResultCode code) {
super(code.getMessage());
this.code = code;
}
public OraBizException(OraInsuranceResultCode code, Object... params) {
this(code);
this.params = params;
}
@Override
public String getMessage() {
String message;
message = (this.code == null) ? super.getMessage() : this.buildMessage();
return message;
}
public OraInsuranceResultCode getCode() {
return this.code;
}
public void setCode(OraInsuranceResultCode code) {
this.code = code;
}
private String buildMessage() {
StringBuilder messageSb = new StringBuilder();
String message;
if (this.code != null) {
messageSb.append(this.code.getMessage());
}
if (this.params != null) {
messageSb.append(":");
for (Object param : this.params) {
messageSb.append(JSON.toJSONString(param)).append(",");
}
}
message = messageSb.toString();
return message.substring(0, message.length() - 1);
}
}
package com.glsx.ordercenter.service.api;
import com.glsx.ordercenter.constants.insurance.OraInsuranceResultCode;
import com.glsx.ordercenter.dto.common.BaseOrderResponse;
import com.glsx.ordercenter.service.common.BaseOrderService;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-27
*/
public abstract class OraBaseService extends BaseOrderService {
@Override
protected <T extends BaseOrderResponse> T serviceOk(T baseResponse) {
baseResponse.setSuccess(true);
baseResponse.setCode(OraInsuranceResultCode.SUCCESS.getCode());
baseResponse.setMessage(OraInsuranceResultCode.SUCCESS.getMessage());
return baseResponse;
}
@Override
protected <T extends BaseOrderResponse> T serviceOops(Throwable t, T baseResponse) {
this.logError("长城欧了Service异常", t);
baseResponse.setSuccess(false);
baseResponse.setCode(OraInsuranceResultCode.SERVER_ERROR.getCode());
baseResponse.setMessage(OraInsuranceResultCode.SERVER_ERROR.getMessage());
return baseResponse;
}
protected <T extends BaseOrderResponse> T serviceOops(OraInsuranceResultCode code, Throwable t,
T baseResponse) {
this.logError("长城欧了Service异常", t);
baseResponse.setSuccess(false);
baseResponse.setCode(code.getCode());
baseResponse.setMessage(code.getMessage());
return baseResponse;
}
}
package com.glsx.ordercenter.service.api;
import com.glsx.ordercenter.dto.api.OraInsuranceRefundReq;
import com.glsx.ordercenter.dto.api.OraInsuranceRefundResp;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public interface OraInsuranceRefundService {
OraInsuranceRefundResp refund(OraInsuranceRefundReq insuranceRefundReq);
}
package com.glsx.ordercenter.service.api;
import com.glsx.ordercenter.dto.api.OraInsuranceUpdateReq;
import com.glsx.ordercenter.dto.api.OraInsuranceUpdateResp;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public interface OraInsuranceUpdateService {
OraInsuranceUpdateResp update(OraInsuranceUpdateReq insuranceUpdateReq);
}
package com.glsx.ordercenter.service.api.impl;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.constants.insurance.InsuranceStatus;
import com.glsx.ordercenter.constants.insurance.OraInsuranceResultCode;
import com.glsx.ordercenter.dto.api.OraInsuranceRefundReq;
import com.glsx.ordercenter.dto.api.OraInsuranceRefundResp;
import com.glsx.ordercenter.exception.insurance.OraBizException;
import com.glsx.ordercenter.mapper.insurance.SysInsurancePolicyMapper;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicy;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicyExample;
import com.glsx.ordercenter.service.api.OraBaseService;
import com.glsx.ordercenter.service.api.OraInsuranceRefundService;
import com.glsx.ordercenter.utils.EmilUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
@Service
public class OraInsuranceRefundServiceImpl extends OraBaseService
implements OraInsuranceRefundService {
@Value("${ora.insurance.email}")
private String targetEmail;
private final ExecutorService executorService = Executors.newFixedThreadPool(10);
@Autowired
private SysInsurancePolicyMapper insurancePolicyMapper;
@Override
public OraInsuranceRefundResp refund(OraInsuranceRefundReq insuranceRefundReq) {
super.logInfo("长城退保-参数", insuranceRefundReq);
OraInsuranceRefundResp insuranceRefundResp;
try {
SysInsurancePolicy insurancePolicy = this.getInsurancePolicy(insuranceRefundReq);
String title = this.buildMailTitle(insuranceRefundReq);
String content = this.buildMailContent(insuranceRefundReq, insurancePolicy);
this.sendMail(title, content);
insuranceRefundResp = super.serviceOk(this.updateInsurancePolicy(insurancePolicy));
} catch (OraBizException e) {
insuranceRefundResp = super.serviceOops(e.getCode(), e, new OraInsuranceRefundResp());
} catch (RuntimeException e) {
insuranceRefundResp = super.serviceOops(e, new OraInsuranceRefundResp());
}
this.logInfo("长城退保-结果", insuranceRefundResp);
return insuranceRefundResp;
}
private SysInsurancePolicy getInsurancePolicy(OraInsuranceRefundReq insuranceRefundReq) {
SysInsurancePolicyExample example = new SysInsurancePolicyExample();
SysInsurancePolicyExample.Criteria byInsuranceId = example.createCriteria();
byInsuranceId.andInsuranceIdEqualTo(insuranceRefundReq.getInsuranceId());
List<SysInsurancePolicy> insurancePolicyList =
this.insurancePolicyMapper.selectByExample(example);
if (insurancePolicyList.isEmpty()) {
throw new OraBizException(OraInsuranceResultCode.PARAM_ERROR, "保单不存在");
}
return insurancePolicyList.get(0);
}
private String buildMailTitle(OraInsuranceRefundReq insuranceRefundReq) {
String title;
title = "包活干保单退保申请:" + insuranceRefundReq.getInsuranceId();
return title;
}
private String buildMailContent(OraInsuranceRefundReq insuranceRefundReq,
SysInsurancePolicy insurancePolicy) {
String content = "<table>" +
"<tr>" +
" <td>" + "第三方ID" + "</td>" +
" <td>" + insurancePolicy.getInsuranceId() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "客户姓名" + "</td>" +
" <td>" + insurancePolicy.getVehicleOwnerName() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "车架号" + "</td>" +
" <td>" + insurancePolicy.getVin() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "设备号" + "</td>" +
" <td>" + insurancePolicy.getGpsNo() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "状态" + "</td>" +
" <td>" + InsuranceStatus.getStatusText(insurancePolicy.getStatus()) + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "提交日期" + "</td>" +
" <td>" + insurancePolicy.getCreateTime() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "生效日期" + "</td>" +
" <td>" + insurancePolicy.getExpectedEffectiveTime() + "</td>" +
"</tr>" +
"</table>";
super.logInfo("长城退保-邮件内容", content);
return content;
}
private void sendMail(String title, String content) {
this.executorService.submit(() -> {
try {
EmilUtils.sendEmail(this.targetEmail, title, content);
} catch (Exception e) {
super.logError("长城退保-邮件发送异常", e);
}
});
}
@Transactional(rollbackFor = Exception.class)
public OraInsuranceRefundResp updateInsurancePolicy(SysInsurancePolicy insurancePolicy) {
OraInsuranceRefundResp insuranceRefundResp = new OraInsuranceRefundResp();
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
insurancePolicy.setStatus(InsuranceStatus.TO_REFUND.getStatus().byteValue());
insurancePolicy.setUpdateTime(new Date());
if (attributes != null) {
insurancePolicy.setUpdateBy(UserUtils.getUserId(attributes.getRequest()));
}
this.insurancePolicyMapper.updateByPrimaryKeySelective(insurancePolicy);
insuranceRefundResp.setInsuranceId(insurancePolicy.getInsuranceId());
return insuranceRefundResp;
}
}
package com.glsx.ordercenter.service.api.impl;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.glsx.ordercenter.constants.insurance.InsuranceCardType;
import com.glsx.ordercenter.constants.insurance.InsuranceCustomerType;
import com.glsx.ordercenter.constants.insurance.OraInsuranceResultCode;
import com.glsx.ordercenter.dto.api.OraInsuranceUpdateReq;
import com.glsx.ordercenter.dto.api.OraInsuranceUpdateResp;
import com.glsx.ordercenter.exception.insurance.OraBizException;
import com.glsx.ordercenter.mapper.insurance.SysInsurancePolicyMapper;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicy;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicyExample;
import com.glsx.ordercenter.service.api.OraBaseService;
import com.glsx.ordercenter.service.api.OraInsuranceUpdateService;
import com.glsx.ordercenter.utils.EmilUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
@Service
public class OraInsuranceUpdateServiceImpl extends OraBaseService
implements OraInsuranceUpdateService {
@Value("${ora.insurance.email}")
private String targetEmail;
private final ExecutorService executorService = Executors.newFixedThreadPool(10);
@Autowired
private SysInsurancePolicyMapper insurancePolicyMapper;
@Override
public OraInsuranceUpdateResp update(OraInsuranceUpdateReq insuranceUpdateReq) {
super.logInfo("长城修改保单-参数", insuranceUpdateReq);
OraInsuranceUpdateResp insuranceUpdateResp;
try {
SysInsurancePolicy insurancePolicy = this.getInsurancePolicy(insuranceUpdateReq);
String title = this.buildMailTitle(insuranceUpdateReq);
String content = this.buildMailContent(insuranceUpdateReq, insurancePolicy);
this.sendMail(title, content);
insuranceUpdateResp = super.serviceOk(this.updateInsurancePolicy(insurancePolicy));
} catch (OraBizException e) {
super.logError("长城修改保单-错误", e);
insuranceUpdateResp = super.serviceOops(e.getCode(), e, new OraInsuranceUpdateResp());
} catch (RuntimeException e) {
super.logError("长城修改保单-错误", e);
insuranceUpdateResp = super.serviceOops(e, new OraInsuranceUpdateResp());
}
super.logInfo("长城修改保单-结果", insuranceUpdateResp);
return insuranceUpdateResp;
}
private SysInsurancePolicy getInsurancePolicy(OraInsuranceUpdateReq insuranceUpdateReq) {
SysInsurancePolicyExample example = new SysInsurancePolicyExample();
SysInsurancePolicyExample.Criteria byInsuranceId = example.createCriteria();
byInsuranceId.andInsuranceIdEqualTo(insuranceUpdateReq.getInsuranceId());
List<SysInsurancePolicy> insurancePolicyList =
this.insurancePolicyMapper.selectByExample(example);
if (insurancePolicyList.isEmpty()) {
throw new OraBizException(OraInsuranceResultCode.PARAM_ERROR, "保单不存在");
}
return insurancePolicyList.get(0);
}
private String buildMailTitle(OraInsuranceUpdateReq insuranceUpdateReq) {
String title;
title = "包活干保单修改申请:" + insuranceUpdateReq.getInsuranceId();
return title;
}
private String buildMailContent(OraInsuranceUpdateReq insuranceUpdateReq,
SysInsurancePolicy insurancePolicy) {
String content = "<table>" +
"<tr>" +
" <td>" + "客户类型" + "</td>" +
" <td>" + InsuranceCustomerType.INDIVIDUAL.getTypeText() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "客户姓名" + "</td>" +
" <td>" + insuranceUpdateReq.getVehicleOwnerName() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "证件类型" + "</td>" +
" <td>" + InsuranceCardType.ID_CARD.getTypeText() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "证件号码" + "</td>" +
" <td>" + insuranceUpdateReq.getIdCardNum() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "联系方式" + "</td>" +
" <td>" + insuranceUpdateReq.getPhone() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "联系地址" + "</td>" +
" <td>" + insuranceUpdateReq.getVehicleOwnerAddress() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "设备信息" + "</td>" +
" <td>" + insuranceUpdateReq.getGpsNo() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "车辆价格" + "</td>" +
" <td>" + insuranceUpdateReq.getVehicleInvoiceMoney() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "车架号" + "</td>" +
" <td>" + insuranceUpdateReq.getVin() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "品牌车型" + "</td>" +
" <td>" + insuranceUpdateReq.getCarBrand() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "发动机号" + "</td>" +
" <td>" + insuranceUpdateReq.getEngineNumber() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "安装日期" + "</td>" +
" <td>" + insuranceUpdateReq.getInstallationTime() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "生效日期" + "</td>" +
" <td>" + insurancePolicy.getExpectedEffectiveTime() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "车身颜色" + "</td>" +
" <td>" + "其他" + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "车牌号码" + "</td>" +
" <td>" + insuranceUpdateReq.getVehicleNo() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "保单年限" + "</td>" +
" <td>" + insuranceUpdateReq.getInsurancePeriod() + " 年</td>" +
"</tr>" +
"<tr>" +
" <td>" + "第一受益人" + "</td>" +
" <td>" + insuranceUpdateReq.getTastingUnit() + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "保单PDF地址" + "</td>" +
" <td>" + insurancePolicy.getInsurancePdf() + "</td>" +
"</tr>" +
"</table>";
super.logInfo("长城修改保单-邮件内容", content);
return content;
}
private void sendMail(String title, String content) {
this.executorService.submit(() -> {
try {
EmilUtils.sendEmail(this.targetEmail, title, content);
} catch (Exception e) {
super.logError("长城修改保单-发送邮件异常", e);
}
});
}
private OraInsuranceUpdateResp updateInsurancePolicy(SysInsurancePolicy insurancePolicy) {
OraInsuranceUpdateResp insuranceUpdateResp = new OraInsuranceUpdateResp();
insuranceUpdateResp.setInsuranceId(insurancePolicy.getInsuranceId());
return insuranceUpdateResp;
}
}
package com.glsx.ordercenter.service.common;
import com.glsx.common.constants.ResultObject;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.common.BaseOrderResponse;
import com.glsx.ordercenter.utils.LogUtils;
/**
* <p>Description: Service基类
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public abstract class BaseOrderService {
private static final String LOG_PREFIX = "Service-";
protected <T extends BaseOrderResponse> T serviceOk(T baseResponse) {
baseResponse.setSuccess(true);
baseResponse.setCode(ResultCodeEnum.SUCCESS.getCode());
baseResponse.setMessage(ResultCodeEnum.SUCCESS.getMsg());
return baseResponse;
}
protected <T extends BaseOrderResponse> T serviceOops(ResultObject resultObject,
T baseResponse) {
baseResponse.setSuccess(false);
baseResponse.setCode(resultObject.getCode());
baseResponse.setMessage(resultObject.getMessage());
return baseResponse;
}
protected <T extends BaseOrderResponse> T serviceOops(Throwable t, T baseResponse) {
this.logError("Service异常", t);
baseResponse.setSuccess(false);
baseResponse.setCode(ResultCodeEnum.ERROR.getCode());
baseResponse.setMessage(ResultCodeEnum.ERROR.getMsg());
return baseResponse;
}
//protected <E> PagedOrderResponse<E> pagedOk(PagedOrderResponse<E> pagedOrderResponse) {
// pagedOrderResponse.setSuccess(true);
// pagedOrderResponse.setCode(ResultCodeEnum.SUCCESS.getCode());
// pagedOrderResponse.setMessage("");
//
// return pagedOrderResponse;
//}
//
//protected <E> PagedOrderResponse<E> pagedOops(ResultObject resultObject,
// PagedOrderResponse<E> pagedOrderResponse) {
//
// pagedOrderResponse.setSuccess(false);
// pagedOrderResponse.setCode(resultObject.getCode());
// pagedOrderResponse.setMessage(resultObject.getMessage());
//
// return pagedOrderResponse;
//}
//
//protected <E> PagedOrderResponse<E> pagedOops(Throwable t,
// PagedOrderResponse<E> pagedOrderResponse) {
//
// this.logError("Service异常", t);
//
// pagedOrderResponse.setSuccess(false);
// pagedOrderResponse.setCode(ResultCodeEnum.ERROR.getCode());
// pagedOrderResponse.setMessage(t.getMessage());
//
// return pagedOrderResponse;
//}
protected void logInfo(String msg, Object... params) {
LogUtils.logInfo(this.getClass(), LOG_PREFIX + msg, params);
}
protected void logError(String msg, Throwable t, Object... params) {
LogUtils.logError(this.getClass(), LOG_PREFIX + msg, t, params);
}
}
package com.glsx.ordercenter.service.insurance;
import com.glsx.ordercenter.dto.common.PagedOrderResponse;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailReq;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailResp;
/**
* <p>Description: 保单详情查询
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public interface InsuranceDetailService {
//List<InsuranceDetailResp> detail(InsuranceDetailReq insuranceDetailReq);
PagedOrderResponse<InsuranceDetailResp> detail(InsuranceDetailReq insuranceDetailReq);
}
package com.glsx.ordercenter.service.insurance;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailReq;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailResp;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public interface InsuranceDownloadService {
InsuranceDetailResp download(InsuranceDetailReq insuranceDetailReq);
}
package com.glsx.ordercenter.service.insurance;
import com.glsx.ordercenter.dto.common.PagedOrderResponse;
import com.glsx.ordercenter.dto.insurance.InsuranceQueryReq;
import com.glsx.ordercenter.dto.insurance.InsuranceQueryResp;
/**
* <p>Description: 保单列表查询
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public interface InsuranceQueryService {
PagedOrderResponse<InsuranceQueryResp> query(InsuranceQueryReq insuranceQueryReq);
}
package com.glsx.ordercenter.service.insurance;
import com.glsx.ordercenter.dto.insurance.InsuranceRefundReq;
import com.glsx.ordercenter.dto.insurance.InsuranceRefundResp;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public interface InsuranceRefundService {
InsuranceRefundResp refund(InsuranceRefundReq insuranceRefundReq);
}
package com.glsx.ordercenter.service.insurance.impl;
import java.util.List;
import com.github.pagehelper.PageInfo;
import com.glsx.ordercenter.dto.common.PagedOrderResponse;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailReq;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailResp;
import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.mapper.insurance.SysInsurancePolicyMapper;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicy;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicyExample;
import com.glsx.ordercenter.service.common.BaseOrderService;
import com.glsx.ordercenter.service.insurance.InsuranceDetailService;
import com.glsx.ordercenter.utils.insurance.InsuranceDataConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
@Service
public class InsuranceDetailServiceImpl extends BaseOrderService implements InsuranceDetailService {
@Autowired
private SysInsurancePolicyMapper insurancePolicyMapper;
@Override
public PagedOrderResponse<InsuranceDetailResp> detail(InsuranceDetailReq insuranceDetailReq) {
super.logInfo("保单详情查询-参数", insuranceDetailReq);
PagedOrderResponse<InsuranceDetailResp> result;
try {
SysInsurancePolicyExample example = this.buildExample(insuranceDetailReq);
List<SysInsurancePolicy> insurancePolicyList = this.getInsurancePolicyList(example);
result = super.serviceOk(this.getResult(insuranceDetailReq, insurancePolicyList));
} catch (BusinessException e) {
result = super.serviceOops(e.getResultEntity(), new PagedOrderResponse<>());
} catch (RuntimeException e) {
result = super.serviceOops(e, new PagedOrderResponse<>());
}
super.logInfo("保单详情查询-结果", result);
return result;
}
private SysInsurancePolicyExample buildExample(InsuranceDetailReq insuranceDetailReq) {
SysInsurancePolicyExample example = new SysInsurancePolicyExample();
SysInsurancePolicyExample.Criteria byIdList = example.createCriteria();
byIdList.andIdEqualTo(insuranceDetailReq.getId());
example.setOrderByClause("installation_time DESC");
return example;
}
private List<SysInsurancePolicy> getInsurancePolicyList(SysInsurancePolicyExample example) {
List<SysInsurancePolicy> insurancePolicyList;
insurancePolicyList = this.insurancePolicyMapper.selectByExample(example);
return insurancePolicyList;
}
private PagedOrderResponse<InsuranceDetailResp> getResult(InsuranceDetailReq insuranceDetailReq,
List<SysInsurancePolicy> insurancePolicyList) {
PagedOrderResponse<InsuranceDetailResp> result;
PageInfo<SysInsurancePolicy> pageInfo = new PageInfo<>(insurancePolicyList);
List<InsuranceDetailResp> insuranceDetailRespList =
InsuranceDataConverter.entityToDetailResp(insurancePolicyList);
result = PagedOrderResponse.of(pageInfo.getTotal(), insuranceDetailReq,
insuranceDetailRespList);
return result;
}
}
package com.glsx.ordercenter.service.insurance.impl;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailReq;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailResp;
import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.exception.SysException;
import com.glsx.ordercenter.mapper.insurance.SysInsurancePolicyMapper;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicy;
import com.glsx.ordercenter.service.common.BaseOrderService;
import com.glsx.ordercenter.service.insurance.InsuranceDownloadService;
import com.glsx.ordercenter.utils.insurance.InsuranceDataConverter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
@Service
public class InsuranceDownloadServiceImpl extends BaseOrderService
implements InsuranceDownloadService {
@Autowired
private SysInsurancePolicyMapper insurancePolicyMapper;
@Override
public InsuranceDetailResp download(InsuranceDetailReq insuranceDetailReq) {
super.logInfo("保单下载-参数", insuranceDetailReq);
InsuranceDetailResp result;
try {
SysInsurancePolicy insurancePolicy = this.getInsurancePolicy(insuranceDetailReq);
result = super.serviceOk(this.getResult(insurancePolicy));
} catch (BusinessException e) {
result = super.serviceOops(e.getResultEntity(), new InsuranceDetailResp());
} catch (RuntimeException e) {
result = super.serviceOops(e, new InsuranceDetailResp());
}
return result;
}
private SysInsurancePolicy getInsurancePolicy(InsuranceDetailReq insuranceDetailReq) {
SysInsurancePolicy insurancePolicy =
this.insurancePolicyMapper.selectByPrimaryKey(insuranceDetailReq.getId());
if (insurancePolicy == null) {
throw SysException.create(ResultCodeEnum.INSURANCE_ID_NOT_FOUND.getCode(),
ResultCodeEnum.INSURANCE_ID_NOT_FOUND.getMsg());
}
if (StringUtils.isBlank(insurancePolicy.getInsurancePdf())) {
throw SysException.create(ResultCodeEnum.INSURANCE_PDF_NOT_FOUND.getCode(),
ResultCodeEnum.INSURANCE_PDF_NOT_FOUND.getMsg());
}
return insurancePolicy;
}
private InsuranceDetailResp getResult(SysInsurancePolicy insurancePolicy) {
InsuranceDetailResp insuranceDetailResp;
insuranceDetailResp = InsuranceDataConverter.entityToDetailResp(insurancePolicy);
return insuranceDetailResp;
}
}
package com.glsx.ordercenter.service.insurance.impl;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.ordercenter.dto.common.PagedOrderResponse;
import com.glsx.ordercenter.dto.insurance.InsuranceQueryReq;
import com.glsx.ordercenter.dto.insurance.InsuranceQueryResp;
import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.mapper.insurance.SysInsurancePolicyMapper;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicy;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicyExample;
import com.glsx.ordercenter.service.common.BaseOrderService;
import com.glsx.ordercenter.service.insurance.InsuranceQueryService;
import com.glsx.ordercenter.utils.insurance.InsuranceDataConverter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
@Service
public class InsuranceQueryServiceImpl extends BaseOrderService implements InsuranceQueryService {
@Autowired
private SysInsurancePolicyMapper insurancePolicyMapper;
@Override
public PagedOrderResponse<InsuranceQueryResp> query(InsuranceQueryReq insuranceQueryReq) {
super.logInfo("保单列表查询-参数", insuranceQueryReq);
PagedOrderResponse<InsuranceQueryResp> result;
try {
SysInsurancePolicyExample example = this.buildExample(insuranceQueryReq);
List<SysInsurancePolicy> insurancePolicyList = this.getInsurancePolicyList(example,
insuranceQueryReq);
result = super.serviceOk(this.getResult(insuranceQueryReq, insurancePolicyList));
} catch (BusinessException e) {
result = super.serviceOops(e.getResultEntity(), new PagedOrderResponse<>());
} catch (RuntimeException e) {
result = super.serviceOops(e, new PagedOrderResponse<>());
}
super.logInfo("保单列表查询-结果", result);
return result;
}
private SysInsurancePolicyExample buildExample(InsuranceQueryReq insuranceQueryReq) {
SysInsurancePolicyExample example = new SysInsurancePolicyExample();
SysInsurancePolicyExample.Criteria byKeyword = example.createCriteria();
if (StringUtils.isNotBlank(insuranceQueryReq.getVehicleOwnerName())) {
byKeyword.andVehicleOwnerNameLike(
"%" + insuranceQueryReq.getVehicleOwnerName() + "%");
}
if (StringUtils.isNotBlank(insuranceQueryReq.getVin())) {
byKeyword.andVinLike("%" + insuranceQueryReq.getVin() + "%");
}
if (StringUtils.isNotBlank(insuranceQueryReq.getGpsNo())) {
byKeyword.andGpsNoLike("%" + insuranceQueryReq.getGpsNo() + "%");
}
if (insuranceQueryReq.getStatus() != null) {
byKeyword.andStatusEqualTo(insuranceQueryReq.getStatus());
}
if (insuranceQueryReq.getApplyTimeStart() != null) {
byKeyword.andInstallationTimeGreaterThanOrEqualTo(
insuranceQueryReq.getApplyTimeStart());
}
if (insuranceQueryReq.getApplyTimeEnd() != null) {
byKeyword.andInstallationTimeLessThan(insuranceQueryReq.getApplyTimeEnd());
}
if (insuranceQueryReq.getStartTimeStart() != null) {
byKeyword.andExpectedEffectiveTimeGreaterThanOrEqualTo(
insuranceQueryReq.getStartTimeStart());
}
if (insuranceQueryReq.getStartTimeEnd() != null) {
byKeyword.andExpectedEffectiveTimeLessThan(insuranceQueryReq.getStartTimeEnd());
}
example.setOrderByClause("installation_time DESC");
return example;
}
private List<SysInsurancePolicy> getInsurancePolicyList(SysInsurancePolicyExample example,
InsuranceQueryReq insuranceQueryReq) {
List<SysInsurancePolicy> insurancePolicyList;
if (insuranceQueryReq.getPageIndex() > 0 && insuranceQueryReq.getPageSize() > 0) {
PageHelper.startPage(insuranceQueryReq.getPageIndex(),
insuranceQueryReq.getPageSize(), true);
}
insurancePolicyList = this.insurancePolicyMapper.selectByExample(example);
return insurancePolicyList;
}
private PagedOrderResponse<InsuranceQueryResp> getResult(InsuranceQueryReq insuranceQueryReq,
List<SysInsurancePolicy> insurancePolicyList) {
PagedOrderResponse<InsuranceQueryResp> result;
PageInfo<SysInsurancePolicy> pageInfo = new PageInfo<>(insurancePolicyList);
List<InsuranceQueryResp> insuranceQueryRespList =
InsuranceDataConverter.entityToQueryResp(insurancePolicyList);
result = PagedOrderResponse.of(pageInfo.getTotal(), insuranceQueryReq,
insuranceQueryRespList);
return result;
}
}
package com.glsx.ordercenter.service.insurance.impl;
import java.util.Date;
import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.constants.insurance.InsuranceStatus;
import com.glsx.ordercenter.dto.insurance.InsuranceRefundReq;
import com.glsx.ordercenter.dto.insurance.InsuranceRefundResp;
import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.exception.SysException;
import com.glsx.ordercenter.mapper.insurance.SysInsurancePolicyMapper;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicy;
import com.glsx.ordercenter.service.common.BaseOrderService;
import com.glsx.ordercenter.service.insurance.InsuranceRefundService;
import com.glsx.ordercenter.utils.insurance.InsuranceApiInvoker;
import com.glsx.ordercenter.utils.insurance.pojo.InsuranceRefundParam;
import com.glsx.ordercenter.utils.insurance.pojo.InsuranceRefundResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
@Service
public class InsuranceRefundServiceImpl extends BaseOrderService
implements InsuranceRefundService {
/**
* 一星期的毫秒数
*/
private static final Long MILLISECONDS_PER_WEEK = 7 * 24 * 3600 * 1000L;
@Autowired
private SysInsurancePolicyMapper insurancePolicyMapper;
@Override
public InsuranceRefundResp refund(InsuranceRefundReq insuranceRefundReq) {
super.logInfo("退保-参数", insuranceRefundReq);
InsuranceRefundResp result;
try {
SysInsurancePolicy insurancePolicy = this.getInsurancePolicy(insuranceRefundReq);
result = super.serviceOk(this.getResult(insurancePolicy));
} catch (BusinessException e) {
result = super.serviceOops(e.getResultEntity(), new InsuranceRefundResp());
} catch (RuntimeException e) {
result = super.serviceOops(e, new InsuranceRefundResp());
}
super.logInfo("退保-结果", result);
return result;
}
private SysInsurancePolicy getInsurancePolicy(InsuranceRefundReq insuranceRefundReq) {
SysInsurancePolicy insurancePolicy;
insurancePolicy = this.insurancePolicyMapper.selectByPrimaryKey(
insuranceRefundReq.getId());
if (insurancePolicy == null) {
throw SysException.create(
ResultCodeEnum.INSURANCE_ID_NOT_FOUND.getCode(),
ResultCodeEnum.INSURANCE_ID_NOT_FOUND.getMsg());
}
return insurancePolicy;
}
private InsuranceRefundResp getResult(SysInsurancePolicy insurancePolicy) {
InsuranceRefundResp result;
if (!this.hasOutdated(insurancePolicy)) {
this.refundByApi(insurancePolicy);
}
result = this.refundByManually(insurancePolicy);
return result;
}
private boolean hasOutdated(SysInsurancePolicy insurancePolicy) {
Date createTime = insurancePolicy.getCreateTime();
Date currentDate = new Date();
return ((currentDate.getTime() - createTime.getTime()) > MILLISECONDS_PER_WEEK);
}
private InsuranceRefundResp refundByApi(SysInsurancePolicy insurancePolicy) {
InsuranceRefundResp insuranceRefundResp = new InsuranceRefundResp();
InsuranceRefundParam insuranceRefundParam = new InsuranceRefundParam();
insuranceRefundParam.setInsuranceCompany(insurancePolicy.getInsuranceCompany());
insuranceRefundParam.setFullInsuranceNo(insurancePolicy.getInsuranceNo());
insuranceRefundParam.setSeqNo(insurancePolicy.getInsuranceSeqNo());
InsuranceRefundResult insuranceRefundResult =
InsuranceApiInvoker.refund(insuranceRefundParam);
boolean invokeSuccess = "0".equals(insuranceRefundResult.getCode())
&& insuranceRefundResult.getData().getCallResult();
insuranceRefundResp.setSuccess(invokeSuccess);
insuranceRefundResp.setMessage(insuranceRefundResult.getData().getErrorMsg());
if (!insuranceRefundResp.getSuccess()) {
throw SysException.create(
ResultCodeEnum.INSURANCE_API_FAIL.getCode(),
ResultCodeEnum.INSURANCE_API_FAIL.getMsg());
}
return insuranceRefundResp;
}
@Transactional(rollbackFor = Exception.class)
public InsuranceRefundResp refundByManually(SysInsurancePolicy insurancePolicy) {
InsuranceRefundResp insuranceRefundResp = new InsuranceRefundResp();
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
try {
insurancePolicy.setStatus(InsuranceStatus.REFUNDED.getStatus().byteValue());
insurancePolicy.setUpdateTime(new Date());
if (attributes != null) {
insurancePolicy.setUpdateBy(UserUtils.getUserId(attributes.getRequest()));
}
this.insurancePolicyMapper.updateByPrimaryKeySelective(insurancePolicy);
} catch (RuntimeException e) {
throw SysException.create(
ResultCodeEnum.INSURANCE_UPDATE_ERROR.getCode(),
ResultCodeEnum.INSURANCE_UPDATE_ERROR.getMsg());
}
return insuranceRefundResp;
}
}
package com.glsx.ordercenter.utils;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.lang3.StringUtils;
/**
* <p>Description: 加密工具类
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class CypherUtils {
private static final String ALGORITHM_SHA1 = "SHA-1";
private static final String ALGORITHM_MD5 = "MD5";
private CypherUtils() {}
public static String generateSha1(String str) {
String result;
try {
MessageDigest messageDigest = MessageDigest.getInstance(ALGORITHM_SHA1);
byte[] resultBytes = messageDigest.digest(str.getBytes(StandardCharsets.UTF_8));
result = byteToHex(resultBytes).toUpperCase();
} catch (NoSuchAlgorithmException e) {
result = "";
e.printStackTrace();
}
return result;
}
public static String generateMd5(String str) {
//return DigestUtils.md5DigestAsHex(str.getBytes(StandardCharsets.UTF_8));
String result;
try {
MessageDigest messageDigest = MessageDigest.getInstance(ALGORITHM_MD5);
byte[] resultBytes = messageDigest.digest(str.getBytes(StandardCharsets.UTF_8));
result = byteToHex(resultBytes).toUpperCase();
} catch (NoSuchAlgorithmException e) {
result = "";
e.printStackTrace();
}
return result;
}
private static String byteToHex(byte[] resultBytes) {
StringBuilder resultSb = new StringBuilder();
for (byte resultByte : resultBytes) {
String hexStr = StringUtils.leftPad(
Integer.toHexString(resultByte & 0xFF), 2, "0");
resultSb.append(hexStr);
}
return resultSb.toString();
}
}
package com.glsx.ordercenter.utils;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* <p>Description: 日志工具类
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-22
*/
public class LogUtils {
private static final Map<String, Logger> loggerMap = new HashMap<>();
private LogUtils() {}
public static void logInfo(Class<?> clazz, String msg, Object... params) {
getLogger(clazz).info(buildLogContent(msg, params));
}
public static void logError(Class<?> clazz, String msg, Throwable t, Object... params) {
getLogger(clazz).error(buildLogContent(msg, params), t);
}
private static Logger getLogger(Class<?> clazz) {
Logger logger;
if (loggerMap.containsKey(clazz.getName())) {
logger = loggerMap.get(clazz.getName());
} else {
logger = LoggerFactory.getLogger(clazz.getName());
loggerMap.put(clazz.getName(), logger);
}
return logger;
}
private static String buildLogContent(String msg, Object... params) {
StringBuilder paramSb = new StringBuilder(msg).append(": ");
for (Object param : params) {
paramSb.append(JSON.toJSONString(param));
}
return paramSb.toString();
}
}
package com.glsx.ordercenter.utils;
import java.util.HashMap;
import java.util.Map;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-26
*/
public class UrlUtils {
private UrlUtils() {}
public static String mergeUrlParams(Map<String, String> urlParams) {
String urlParamStr;
StringBuilder urlParamSb = new StringBuilder();
urlParams.forEach((key, value) ->
urlParamSb.append(key).append("=").append(value).append("&"));
urlParamStr = urlParamSb.toString();
return urlParamStr.substring(0, urlParamStr.length() - 1);
}
public static Map<String, String> splitUrlParam(String url) {
Map<String, String> urlParams = new HashMap<>();
String subUrl = url.contains("?") ? url.substring(url.indexOf('?')) : url;
String[] entryPairs = subUrl.split("&");
for (String entryPair : entryPairs) {
String[] entry = entryPair.split("=");
if (entry.length > 1) {
urlParams.put(entry[0], entry[1]);
}
}
return urlParams;
}
}
package com.glsx.ordercenter.utils.insurance;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.glsx.common.utils.DateUtil;
import com.glsx.ordercenter.constants.insurance.InsuranceSource;
import com.glsx.ordercenter.constants.insurance.InsuranceTspMethod;
import com.glsx.ordercenter.utils.insurance.pojo.InsuranceRefundParam;
import com.glsx.ordercenter.utils.insurance.pojo.InsuranceRefundResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* <p>Description: TSP投保工具类
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
@Component
public class InsuranceApiInvoker {
private static String tspUrl;
private static String tspFormat;
private static String tspVersion;
private static String appKey;
private static String secret;
private InsuranceApiInvoker() {}
public static InsuranceRefundResult refund(InsuranceRefundParam insuranceRefundParam) {
InsuranceRefundResult insuranceRefundResult;
Map<String, String> signParamMap = buildSignParamMap(InsuranceTspMethod.REFUND.get(),
insuranceRefundParam);
insuranceRefundResult = InsuranceRestUtils.postForObject(
tspUrl, signParamMap, insuranceRefundParam, InsuranceRefundResult.class);
return insuranceRefundResult;
}
private static <T> Map<String, String> buildSignParamMap(String method, T requestBody) {
Map<String, String> rawSignParamMap = buildRawSignParamMap(method);
Map<String, String> signParamMap = InsuranceSignUtils.buildSignParamMap(
rawSignParamMap, requestBody);
InsuranceSignUtils.signBySha1(secret, signParamMap);
return signParamMap;
}
private static Map<String, String> buildRawSignParamMap(String method) {
Map<String, String> rawSignParamMap = new HashMap<>();
rawSignParamMap.put(InsuranceSysParamConstants.METHOD, method);
rawSignParamMap.put(InsuranceSysParamConstants.FORMAT, tspFormat);
rawSignParamMap.put(InsuranceSysParamConstants.APPKEY, appKey);
rawSignParamMap.put(InsuranceSysParamConstants.V, tspVersion);
rawSignParamMap.put(InsuranceSysParamConstants.TIMESTAMP, DateUtil.formatDate(new Date()));
rawSignParamMap.put(InsuranceSysParamConstants.SOURCE, InsuranceSource.ORA.getCompanyCode());
return rawSignParamMap;
}
@Value("${ora.tsp.url}")
public void setUrl(String tspUrl) {
InsuranceApiInvoker.tspUrl = tspUrl;
}
@Value("${ora.tsp.format}")
public void setTspFormat(String tspFormat) {
InsuranceApiInvoker.tspFormat = tspFormat;
}
@Value("${ora.tsp.version}")
public void setTspVersion(String tspVersion) {
InsuranceApiInvoker.tspVersion = tspVersion;
}
@Value("${ora.insurance.appKey}")
public void setAppKey(String appKey) {
InsuranceApiInvoker.appKey = appKey;
}
@Value("${ora.insurance.secret}")
public void setSecret(String secret) {
InsuranceApiInvoker.secret = secret;
}
}
package com.glsx.ordercenter.utils.insurance;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import com.glsx.common.utils.DateUtil;
import com.glsx.ordercenter.constants.insurance.InsuranceCardType;
import com.glsx.ordercenter.constants.insurance.InsuranceStatus;
import com.glsx.ordercenter.dto.insurance.InsuranceDetailResp;
import com.glsx.ordercenter.dto.insurance.InsuranceQueryResp;
import com.glsx.ordercenter.pojo.insurance.SysInsurancePolicy;
import org.springframework.beans.BeanUtils;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class InsuranceDataConverter {
private InsuranceDataConverter() {}
public static List<InsuranceQueryResp> entityToQueryResp(
List<SysInsurancePolicy> insurancePolicyList) {
List<InsuranceQueryResp> insuranceQueryRespList = new ArrayList<>();
insurancePolicyList.forEach(insurancePolicy ->
insuranceQueryRespList.add(entityToQueryResp(insurancePolicy)));
return insuranceQueryRespList;
}
public static List<InsuranceDetailResp> entityToDetailResp(
List<SysInsurancePolicy> insurancePolicyList) {
List<InsuranceDetailResp> insuranceDetailRespList = new ArrayList<>();
insurancePolicyList.forEach(insurancePolicy ->
insuranceDetailRespList.add(entityToDetailResp(insurancePolicy)));
return insuranceDetailRespList;
}
public static InsuranceQueryResp entityToQueryResp(SysInsurancePolicy insurancePolicy) {
InsuranceQueryResp insuranceQueryResp = new InsuranceQueryResp();
String moneyStr = insurancePolicy.getVehicleInvoiceMoney()
.setScale(2, RoundingMode.HALF_UP)
.toPlainString();
BeanUtils.copyProperties(insurancePolicy, insuranceQueryResp);
insuranceQueryResp.setApplyTime(
DateUtil.formatDate(insurancePolicy.getCreateTime()));
insuranceQueryResp.setExpectedEffectiveTime(
DateUtil.formatDate(insurancePolicy.getExpectedEffectiveTime()));
insuranceQueryResp.setStatusText(
InsuranceStatus.getStatusText(insurancePolicy.getStatus()));
insuranceQueryResp.setIdCardTypeText(
InsuranceCardType.getTypeText(insurancePolicy.getIdCardType()));
insuranceQueryResp.setVehicleInvoiceMoney(moneyStr);
return insuranceQueryResp;
}
public static InsuranceDetailResp entityToDetailResp(SysInsurancePolicy insurancePolicy) {
InsuranceDetailResp insuranceDetailResp = new InsuranceDetailResp();
String moneyStr = insurancePolicy.getVehicleInvoiceMoney()
.setScale(2, RoundingMode.HALF_UP)
.toPlainString();
BeanUtils.copyProperties(insurancePolicy, insuranceDetailResp);
insuranceDetailResp.setApplyTime(
DateUtil.formatDate(insurancePolicy.getCreateTime()));
insuranceDetailResp.setExpectedEffectiveTime(
DateUtil.formatDate(insurancePolicy.getExpectedEffectiveTime()));
insuranceDetailResp.setStatusText(
InsuranceStatus.getStatusText(insurancePolicy.getStatus()));
insuranceDetailResp.setIdCardTypeText(
InsuranceCardType.getTypeText(insurancePolicy.getIdCardType()));
insuranceDetailResp.setVehicleInvoiceMoney(moneyStr);
return insuranceDetailResp;
}
}
package com.glsx.ordercenter.utils.insurance;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.glsx.ordercenter.utils.UrlUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
@Component
public class InsuranceRestUtils {
private static final RestTemplate restTemplate = new RestTemplate();
private InsuranceRestUtils() {}
public static <T> T postForObject(String url, Map<String, String> urlParamMap,
Object requestBody, Class<T> tClass) {
T responseBody;
String mergedUrl = mergeUrlWithParam(url, urlParamMap);
String responseStr = restTemplate.postForObject(mergedUrl, requestBody, String.class,
urlParamMap);
responseBody = JSON.parseObject(responseStr, tClass);
return responseBody;
}
private static String mergeUrlWithParam(String url, Map<String, String> urlParamMap) {
String realUrl;
realUrl = url + "?" + UrlUtils.mergeUrlParams(urlParamMap);
return realUrl;
}
}
package com.glsx.ordercenter.utils.insurance;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.glsx.common.utils.DateUtil;
import com.glsx.ordercenter.constants.insurance.InsuranceSource;
import com.glsx.ordercenter.utils.CypherUtils;
import com.glsx.ordercenter.utils.insurance.pojo.InsuranceRefundParam;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* <p>Description: 签名工具类
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-26
*/
public class InsuranceSignUtils {
private InsuranceSignUtils() {}
public static void main(String[] args) {
String seqNo = "SEQ0000000001";
String insuranceNo = "INO238467238658";
String company = "picc";
String method = "ora.apply";
String appKey = "AK5873489577556";
String secret = "S38925789734698";
InsuranceRefundParam insuranceRefundParam = new InsuranceRefundParam();
insuranceRefundParam.setSeqNo(seqNo);
insuranceRefundParam.setFullInsuranceNo(insuranceNo);
insuranceRefundParam.setInsuranceCompany(company);
Map<String, String> signParamMap = buildSignParamMap(method, appKey, insuranceRefundParam);
System.out.println(signParamMap);
System.out.println(signBySha1(secret, signParamMap));
System.out.println(signParamMap);
System.out.println("====================");
Map<String, String[]> paramMap = new HashMap<>();
signParamMap.forEach((key, value) -> paramMap.put(key, new String[]{value}));
Map<String, String> verifyParamMap = buildVerifyParamMap(paramMap, insuranceRefundParam);
System.out.println(verifyBySha1(secret, verifyParamMap));
}
/**
* 获取HTTP请求体中的信息进行验签,使用 SHA-1
*
* @param secret 密钥
* @param requestBody 请求体
* @param <T> 请求体类型
* @return 是否验签成功
*/
public static <T> boolean verifyRequestBySha1(String secret, T requestBody) {
boolean verified;
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
Map<String, String[]> paramMap = request.getParameterMap();
Map<String, String> verifyParamMap = buildVerifyParamMap(paramMap, requestBody);
verified = verifyBySha1(secret, verifyParamMap);
} else {
verified = true;
}
return verified;
}
/**
* 获取HTTP请求体中的信息进行验签,使用 MD5
*
* @param secret 密钥
* @param requestBody 请求体
* @param <T> 请求体类型
* @return 是否验签成功
*/
public static <T> boolean verifyRequestByMd5(String secret, T requestBody) {
boolean verified;
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
Map<String, String[]> paramMap = request.getParameterMap();
Map<String, String> verifyParamMap = buildVerifyParamMap(paramMap, requestBody);
verified = verifyByMd5(secret, verifyParamMap);
} else {
verified = true;
}
return verified;
}
public static <T> Map<String, String> buildSignParamMap(Map<String, String> rawSignParamMap,
T requestBody) {
Map<String, String> signParamMap = new HashMap<>();
Map<String, Object> requestBodyParam = JSON.parseObject(JSON.toJSONString(requestBody));
requestBodyParam.putAll(rawSignParamMap);
requestBodyParam.forEach((key, value) -> signParamMap.put(key, String.valueOf(value)));
return signParamMap;
}
@Deprecated
public static <T> Map<String, String> buildSignParamMap(String method, String appKey,
T requestBody) {
Map<String, String> signParamMap = new HashMap<>();
Map<String, Object> requestBodyParam = JSON.parseObject(JSON.toJSONString(requestBody));
signParamMap.put(InsuranceSysParamConstants.METHOD, method);
signParamMap.put(InsuranceSysParamConstants.FORMAT, "json");
signParamMap.put(InsuranceSysParamConstants.APPKEY, appKey);
signParamMap.put(InsuranceSysParamConstants.V, "1.0.0");
signParamMap.put(InsuranceSysParamConstants.TIMESTAMP, DateUtil.formatDate(new Date()));
signParamMap.put(InsuranceSysParamConstants.SOURCE, InsuranceSource.ORA.getCompanyCode());
requestBodyParam.forEach((key, value) -> signParamMap.put(key, String.valueOf(value)));
return signParamMap;
}
public static <T> Map<String, String> buildVerifyParamMap(Map<String, String[]> paramMap,
T requestBody) {
Map<String, String> verifyParamMap = new HashMap<>();
Map<String, Object> requestBodyParam = JSON.parseObject(JSON.toJSONString(requestBody));
paramMap.forEach((key, value) -> verifyParamMap.put(key, value[value.length - 1]));
requestBodyParam.forEach((key, value) -> verifyParamMap.put(key, String.valueOf(value)));
return verifyParamMap;
}
public static <T> boolean verifyBySha1(String secret, Map<String, String> verifyParamMap) {
String storedSignStr = verifyParamMap.get(InsuranceSysParamConstants.SIGN);
verifyParamMap.remove(InsuranceSysParamConstants.SIGN);
String signStr = signBySha1(secret, verifyParamMap);
return signStr.equals(storedSignStr);
}
public static <T> boolean verifyByMd5(String secret, Map<String, String> verifyParamMap) {
String storedSignStr = verifyParamMap.get(InsuranceSysParamConstants.SIGN);
verifyParamMap.remove(InsuranceSysParamConstants.SIGN);
String signStr = signByMd5(secret, verifyParamMap);
return signStr.equals(storedSignStr);
}
public static String signBySha1(String secret, Map<String, String> signParamMap) {
String signStr;
String rawSignStr = buildRawSignStr(secret, signParamMap);
signStr = CypherUtils.generateSha1(rawSignStr);
signParamMap.put(InsuranceSysParamConstants.SIGN, signStr);
return signStr;
}
public static String signByMd5(String secret, Map<String, String> signParamMap) {
String signStr;
String rawSignStr = buildRawSignStr(secret, signParamMap);
signStr = CypherUtils.generateMd5(rawSignStr);
signParamMap.put(InsuranceSysParamConstants.SIGN, signStr);
return signStr;
}
private static String buildRawSignStr(String secret, Map<String, String> signParamMap) {
StringBuilder rawSignSb = new StringBuilder(secret);
List<String> keyList = new ArrayList<>(signParamMap.keySet());
keyList.sort(Comparator.naturalOrder());
keyList.forEach(key -> rawSignSb.append(key).append(signParamMap.get(key)));
rawSignSb.append(secret);
return rawSignSb.toString();
}
}
package com.glsx.ordercenter.utils.insurance;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-26
*/
public class InsuranceSysParamConstants {
/**
* API接口名称 dj.system.login
*/
public static final String METHOD = "method";
/**
* 可选,指定响应格式。目前支持格式为json
*/
public static final String FORMAT = "format";
/**
* 嘀加开放平台分配给应用的AppKey ,创建应用时可获得
*/
public static final String APPKEY = "appKey";
/**
* API协议版本,可选值: 1.0.0。
*/
public static final String V = "v";
/**
* 对 API 输入参数进行 sha1 加密获得,详细参考如下签名sign
*/
public static final String SIGN = "sign";
/**
* 请求时间戳,pattern为"yyyy-MM-dd HH:mm:ss"
*/
public static final String TIMESTAMP = "timestamp";
/**
* 请求来源,建议传公司英文名称,如:glsx
*/
public static final String SOURCE = "source";
private InsuranceSysParamConstants() {}
}
package com.glsx.ordercenter.utils.insurance.pojo;
import java.io.Serializable;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class InsuranceData implements Serializable {
private Boolean callResult;
private String errorCode;
private String errorMsg;
private String obj;
private String info;
private String ok;
public Boolean getCallResult() {
return this.callResult;
}
public void setCallResult(Boolean callResult) {
this.callResult = callResult;
}
public String getErrorCode() {
return this.errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public String getErrorMsg() {
return this.errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
public String getObj() {
return this.obj;
}
public void setObj(String obj) {
this.obj = obj;
}
public String getInfo() {
return this.info;
}
public void setInfo(String info) {
this.info = info;
}
public String getOk() {
return this.ok;
}
public void setOk(String ok) {
this.ok = ok;
}
@Override
public String toString() {
return "InsuranceData{" +
"callResult=" + this.callResult +
", errorCode='" + this.errorCode + '\'' +
", errorMsg='" + this.errorMsg + '\'' +
", obj='" + this.obj + '\'' +
", info='" + this.info + '\'' +
", ok='" + this.ok + '\'' +
'}';
}
}
package com.glsx.ordercenter.utils.insurance.pojo;
import java.io.Serializable;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class InsuranceRefundParam implements Serializable {
/**
* 保险公司名称(华安:sinosafe,富德:sinofd,阳光:sinosig,人保:picc)
*/
private String insuranceCompany;
/**
* 保险公司投保保单号
*/
private String fullInsuranceNo;
/**
* 保单序列号(保险公司为人保时,必填)
*/
private String seqNo;
public String getInsuranceCompany() {
return this.insuranceCompany;
}
public void setInsuranceCompany(String insuranceCompany) {
this.insuranceCompany = insuranceCompany;
}
public String getFullInsuranceNo() {
return this.fullInsuranceNo;
}
public void setFullInsuranceNo(String fullInsuranceNo) {
this.fullInsuranceNo = fullInsuranceNo;
}
public String getSeqNo() {
return this.seqNo;
}
public void setSeqNo(String seqNo) {
this.seqNo = seqNo;
}
@Override
public String toString() {
return "InsuranceRefundParam{" +
"insuranceCompany='" + this.insuranceCompany + '\'' +
", fullInsuranceNo='" + this.fullInsuranceNo + '\'' +
", seqNo='" + this.seqNo + '\'' +
'}';
}
}
package com.glsx.ordercenter.utils.insurance.pojo;
import java.io.Serializable;
/**
* <p>Description:
*
* <p>Project: car-service
*
* @author wbh
* @date 2020-05-25
*/
public class InsuranceRefundResult implements Serializable {
/**
* 消息返回码 “0”表示成功,错误信息详见“错误码列表”
*/
private String code;
/**
* 错误码
*/
private String errId;
/**
* 错误信息内容
*/
private String message;
/**
* 成功返回数据
*/
private InsuranceData data;
/**
* 退保结果("SUCCESS"或者"保单号+全额退款成功")
*/
private String errorMsg;
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code = code;
}
public String getErrId() {
return this.errId;
}
public void setErrId(String errId) {
this.errId = errId;
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public InsuranceData getData() {
return this.data;
}
public void setData(InsuranceData data) {
this.data = data;
}
public String getErrorMsg() {
return this.errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
@Override
public String toString() {
return "InsuranceRefundResult{" +
"code='" + this.code + '\'' +
", errId='" + this.errId + '\'' +
", message='" + this.message + '\'' +
", data=" + this.data +
", errorMsg='" + this.errorMsg + '\'' +
'}';
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!