提交 7d963feb authored 作者: hzh's avatar hzh

代码优化

上级 3567bfe7
...@@ -264,7 +264,16 @@ public class Api { ...@@ -264,7 +264,16 @@ public class Api {
* @return {@link ApiHttpResponse} 请求返回的结果 * @return {@link ApiHttpResponse} 请求返回的结果
*/ */
public static ApiHttpResponse get(String url, Map<String, Object> params, Map<String, String> headers) { public static ApiHttpResponse get(String url, Map<String, Object> params, Map<String, String> headers) {
return HttpKit.getDelegate().get(url, params, headers); log.info("请求路径:{}", url);
log.info("请求头:{}", JSON.toJSONString(headers));
log.info("请求参数:{}", params);
StopWatch watch = new StopWatch();
watch.start();
ApiHttpResponse res = HttpKit.getDelegate().get(url, params, headers);
log.info("返回参数:{}", JSON.toJSONString(res));
watch.stop();
log.info("请求耗时:{}ms", watch.getTotalTimeMillis());
return res;
} }
public static Map<String, String> getHeaders(String authorization) { public static Map<String, String> getHeaders(String authorization) {
......
...@@ -15,7 +15,7 @@ public class AuthResponse { ...@@ -15,7 +15,7 @@ public class AuthResponse {
/** /**
* 超时时间 * 超时时间
*/ */
private int expires_in; private Integer expires_in;
/** /**
* 令牌类型 * 令牌类型
*/ */
......
...@@ -24,7 +24,7 @@ public interface WeishiService { ...@@ -24,7 +24,7 @@ public interface WeishiService {
* @param request 请求参数 * @param request 请求参数
* @return 响应数据 * @return 响应数据
*/ */
ApplyResponse insureApply(ApplyRequest request); ApplyResponse insureApply(String token, ApplyRequest request);
/** /**
* 核保接口 * 核保接口
...@@ -32,7 +32,7 @@ public interface WeishiService { ...@@ -32,7 +32,7 @@ public interface WeishiService {
* @param request 请求参数 * @param request 请求参数
* @return 响应数据 * @return 响应数据
*/ */
ProposalResponse insureProposal(ProposalRequest request); ProposalResponse insureProposal(String token, ProposalRequest request);
/** /**
* 签单接口 * 签单接口
...@@ -40,28 +40,28 @@ public interface WeishiService { ...@@ -40,28 +40,28 @@ public interface WeishiService {
* @param orderNum 订单号 * @param orderNum 订单号
* @return 数据 * @return 数据
*/ */
IssueResponse insureDetail(String orderNum); IssueResponse insureDetail(String token, String orderNum);
/** /**
* 订单撤单接口 * 订单撤单接口
* *
* @param orderNum 订单号 * @param orderNum 订单号
*/ */
void insureCancel(String orderNum); void insureCancel(String token, String orderNum);
/** /**
* 保单撤单接口 * 保单撤单接口
* *
* @param policyNum 保单号 * @param policyNum 保单号
*/ */
void policyCancel(String policyNum); void policyCancel(String token, String policyNum);
/** /**
* 产品列表接口 * 产品列表接口
* *
* @return 产品列表 * @return 产品列表
*/ */
List<ProductsResponse> productList(); List<ProductsResponse> productList(String token);
/** /**
* 产品详情 * 产品详情
...@@ -69,7 +69,7 @@ public interface WeishiService { ...@@ -69,7 +69,7 @@ public interface WeishiService {
* @param productId 产品id * @param productId 产品id
* @return 产品详情 * @return 产品详情
*/ */
ProductResponse productDetail(Integer productId); ProductResponse productDetail(String token, Integer productId);
/** /**
* 获取保险公司相关文档接口 * 获取保险公司相关文档接口
...@@ -78,5 +78,5 @@ public interface WeishiService { ...@@ -78,5 +78,5 @@ public interface WeishiService {
* @param annexTp annexTp * @param annexTp annexTp
* @return 数据 * @return 数据
*/ */
AnnexResponse annex(Integer productId,String annexTp); AnnexResponse annex(String token, Integer productId, String annexTp);
} }
...@@ -47,11 +47,11 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -47,11 +47,11 @@ public class WeishiServiceImpl implements WeishiService {
} }
@Override @Override
public ApplyResponse insureApply(ApplyRequest request) { public ApplyResponse insureApply(String token, ApplyRequest request) {
ApiHttpResponse res = Api.v1(RequestMethodEnum.POST, ApiHttpResponse res = Api.v1(RequestMethodEnum.POST,
DomainEnum.TEST.getDomain(), DomainEnum.TEST.getDomain(),
InsureApiEnum.APPLY.getUrl(), InsureApiEnum.APPLY.getUrl(),
getToken(), token,
JSON.toJSONString(request)); JSON.toJSONString(request));
if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) { if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) {
throw new WeishiException(res.getResultMsg()); throw new WeishiException(res.getResultMsg());
...@@ -60,11 +60,11 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -60,11 +60,11 @@ public class WeishiServiceImpl implements WeishiService {
} }
@Override @Override
public ProposalResponse insureProposal(ProposalRequest request) { public ProposalResponse insureProposal(String token, ProposalRequest request) {
ApiHttpResponse res = Api.v1(RequestMethodEnum.POST, ApiHttpResponse res = Api.v1(RequestMethodEnum.POST,
DomainEnum.TEST.getDomain(), DomainEnum.TEST.getDomain(),
InsureApiEnum.PROPOSAL.getUrl(), InsureApiEnum.PROPOSAL.getUrl(),
getToken(), token,
JSON.toJSONString(request)); JSON.toJSONString(request));
if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) { if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) {
throw new WeishiException(res.getResultMsg()); throw new WeishiException(res.getResultMsg());
...@@ -73,14 +73,14 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -73,14 +73,14 @@ public class WeishiServiceImpl implements WeishiService {
} }
@Override @Override
public IssueResponse insureDetail(String orderNum) { public IssueResponse insureDetail(String token, String orderNum) {
Map<String, Object> map = MapUtil.<String, Object>builder() Map<String, Object> map = MapUtil.<String, Object>builder()
.put("OrderNum", orderNum) .put("OrderNum", orderNum)
.build(); .build();
ApiHttpResponse res = Api.v1(RequestMethodEnum.POST, ApiHttpResponse res = Api.v1(RequestMethodEnum.POST,
DomainEnum.TEST.getDomain(), DomainEnum.TEST.getDomain(),
StrUtil.format(InsureApiEnum.ISSUE.getUrl(), map), StrUtil.format(InsureApiEnum.ISSUE.getUrl(), map),
getToken(), token,
null); null);
if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) { if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) {
throw new WeishiException(res.getResultMsg()); throw new WeishiException(res.getResultMsg());
...@@ -89,14 +89,14 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -89,14 +89,14 @@ public class WeishiServiceImpl implements WeishiService {
} }
@Override @Override
public void insureCancel(String orderNum) { public void insureCancel(String token, String orderNum) {
Map<String, Object> map = MapUtil.<String, Object>builder() Map<String, Object> map = MapUtil.<String, Object>builder()
.put("OrderNum", orderNum) .put("OrderNum", orderNum)
.build(); .build();
ApiHttpResponse res = Api.v1(RequestMethodEnum.POST, ApiHttpResponse res = Api.v1(RequestMethodEnum.POST,
DomainEnum.TEST.getDomain(), DomainEnum.TEST.getDomain(),
StrUtil.format(InsureApiEnum.CANCEL.getUrl(), map), StrUtil.format(InsureApiEnum.CANCEL.getUrl(), map),
getToken(), token,
null); null);
if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) { if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) {
throw new WeishiException(res.getResultMsg()); throw new WeishiException(res.getResultMsg());
...@@ -104,14 +104,14 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -104,14 +104,14 @@ public class WeishiServiceImpl implements WeishiService {
} }
@Override @Override
public void policyCancel(String policyNum) { public void policyCancel(String token, String policyNum) {
Map<String, Object> map = MapUtil.<String, Object>builder() Map<String, Object> map = MapUtil.<String, Object>builder()
.put("policyNum", policyNum) .put("policyNum", policyNum)
.build(); .build();
ApiHttpResponse res = Api.v1(RequestMethodEnum.POST, ApiHttpResponse res = Api.v1(RequestMethodEnum.POST,
DomainEnum.TEST.getDomain(), DomainEnum.TEST.getDomain(),
StrUtil.format(InsureApiEnum.POLICY_CANCEL.getUrl(), map), StrUtil.format(InsureApiEnum.POLICY_CANCEL.getUrl(), map),
getToken(), token,
null); null);
if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) { if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) {
throw new WeishiException(res.getResultMsg()); throw new WeishiException(res.getResultMsg());
...@@ -128,11 +128,11 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -128,11 +128,11 @@ public class WeishiServiceImpl implements WeishiService {
} }
@Override @Override
public List<ProductsResponse> productList() { public List<ProductsResponse> productList(String token) {
ApiHttpResponse res = Api.v1(RequestMethodEnum.GET, ApiHttpResponse res = Api.v1(RequestMethodEnum.GET,
DomainEnum.TEST.getDomain(), DomainEnum.TEST.getDomain(),
ProductApiEnum.PRODUCT_LIST.getUrl(), ProductApiEnum.PRODUCT_LIST.getUrl(),
getToken(), token,
null); null);
if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) { if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) {
throw new WeishiException(res.getResultMsg()); throw new WeishiException(res.getResultMsg());
...@@ -141,14 +141,14 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -141,14 +141,14 @@ public class WeishiServiceImpl implements WeishiService {
} }
@Override @Override
public ProductResponse productDetail(Integer productId) { public ProductResponse productDetail(String token, Integer productId) {
Map<String, Object> map = MapUtil.<String, Object>builder() Map<String, Object> map = MapUtil.<String, Object>builder()
.put("productId", productId) .put("productId", productId)
.build(); .build();
ApiHttpResponse res = Api.v1(RequestMethodEnum.GET, ApiHttpResponse res = Api.v1(RequestMethodEnum.GET,
DomainEnum.TEST.getDomain(), DomainEnum.TEST.getDomain(),
StrUtil.format(ProductApiEnum.PRODUCT_DETAIL.getUrl(), map), StrUtil.format(ProductApiEnum.PRODUCT_DETAIL.getUrl(), map),
getToken(), token,
null); null);
if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) { if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) {
throw new WeishiException(res.getResultMsg()); throw new WeishiException(res.getResultMsg());
...@@ -157,7 +157,7 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -157,7 +157,7 @@ public class WeishiServiceImpl implements WeishiService {
} }
@Override @Override
public AnnexResponse annex(Integer productId, String annexTp) { public AnnexResponse annex(String token, Integer productId, String annexTp) {
Map<String, Object> map = MapUtil.<String, Object>builder() Map<String, Object> map = MapUtil.<String, Object>builder()
.put("productId", productId) .put("productId", productId)
.put("annexTp", annexTp) .put("annexTp", annexTp)
...@@ -165,7 +165,7 @@ public class WeishiServiceImpl implements WeishiService { ...@@ -165,7 +165,7 @@ public class WeishiServiceImpl implements WeishiService {
ApiHttpResponse res = Api.v1(RequestMethodEnum.GET, ApiHttpResponse res = Api.v1(RequestMethodEnum.GET,
DomainEnum.TEST.getDomain(), DomainEnum.TEST.getDomain(),
StrUtil.format(ProductApiEnum.ANNEX.getUrl(), map), StrUtil.format(ProductApiEnum.ANNEX.getUrl(), map),
getToken(), token,
null); null);
if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) { if (!Objects.equals(res.getResultTp(), Code.SUCCESS.getCode())) {
throw new WeishiException(res.getResultMsg()); throw new WeishiException(res.getResultMsg());
......
...@@ -3,6 +3,8 @@ package org.dromara.mall.controller.weishi.app; ...@@ -3,6 +3,8 @@ package org.dromara.mall.controller.weishi.app;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.common.weishi.model.req.ApplyRequest; import org.dromara.common.weishi.model.req.ApplyRequest;
import org.dromara.common.weishi.model.req.ProposalRequest; import org.dromara.common.weishi.model.req.ProposalRequest;
import org.dromara.common.weishi.model.res.*; import org.dromara.common.weishi.model.res.*;
...@@ -10,6 +12,7 @@ import org.dromara.common.weishi.service.WeishiService; ...@@ -10,6 +12,7 @@ import org.dromara.common.weishi.service.WeishiService;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.Duration;
import java.util.List; import java.util.List;
/** /**
...@@ -32,7 +35,7 @@ public class WeishiController { ...@@ -32,7 +35,7 @@ public class WeishiController {
*/ */
@GetMapping("/productList") @GetMapping("/productList")
public R<List<ProductsResponse>> productList() { public R<List<ProductsResponse>> productList() {
return R.ok(weishiService.productList()); return R.ok(weishiService.productList(getToken()));
} }
/** /**
...@@ -43,7 +46,7 @@ public class WeishiController { ...@@ -43,7 +46,7 @@ public class WeishiController {
*/ */
@GetMapping("/productDetail") @GetMapping("/productDetail")
public R<ProductResponse> productDetail(@RequestParam Integer productId) { public R<ProductResponse> productDetail(@RequestParam Integer productId) {
return R.ok(weishiService.productDetail(productId)); return R.ok(weishiService.productDetail(getToken(), productId));
} }
/** /**
...@@ -56,7 +59,7 @@ public class WeishiController { ...@@ -56,7 +59,7 @@ public class WeishiController {
@GetMapping("/annex") @GetMapping("/annex")
public R<AnnexResponse> annex(@RequestParam(value = "productId") Integer productId, public R<AnnexResponse> annex(@RequestParam(value = "productId") Integer productId,
@RequestParam(value = "annexTp") String annexTp) { @RequestParam(value = "annexTp") String annexTp) {
return R.ok(weishiService.annex(productId, annexTp)); return R.ok(weishiService.annex(getToken(), productId, annexTp));
} }
/** /**
...@@ -67,7 +70,7 @@ public class WeishiController { ...@@ -67,7 +70,7 @@ public class WeishiController {
*/ */
@PostMapping("/insureApply") @PostMapping("/insureApply")
public R<ApplyResponse> insureApply(@RequestBody ApplyRequest req) { public R<ApplyResponse> insureApply(@RequestBody ApplyRequest req) {
return R.ok(weishiService.insureApply(req)); return R.ok(weishiService.insureApply(getToken(), req));
} }
...@@ -79,7 +82,7 @@ public class WeishiController { ...@@ -79,7 +82,7 @@ public class WeishiController {
*/ */
@PostMapping("/insureProposal") @PostMapping("/insureProposal")
public R<ProposalResponse> insureProposal(@RequestBody ProposalRequest req) { public R<ProposalResponse> insureProposal(@RequestBody ProposalRequest req) {
return R.ok(weishiService.insureProposal(req)); return R.ok(weishiService.insureProposal(getToken(), req));
} }
...@@ -91,7 +94,7 @@ public class WeishiController { ...@@ -91,7 +94,7 @@ public class WeishiController {
*/ */
@GetMapping("/insureDetail") @GetMapping("/insureDetail")
public R<IssueResponse> insureDetail(@RequestParam String orderNum) { public R<IssueResponse> insureDetail(@RequestParam String orderNum) {
return R.ok(weishiService.insureDetail(orderNum)); return R.ok(weishiService.insureDetail(getToken(), orderNum));
} }
...@@ -102,7 +105,7 @@ public class WeishiController { ...@@ -102,7 +105,7 @@ public class WeishiController {
*/ */
@PostMapping("/insureCancel/{orderNum}") @PostMapping("/insureCancel/{orderNum}")
public R<Void> insureCancel(@PathVariable String orderNum) { public R<Void> insureCancel(@PathVariable String orderNum) {
weishiService.insureCancel(orderNum); weishiService.insureCancel(getToken(), orderNum);
return R.ok(); return R.ok();
} }
...@@ -113,8 +116,26 @@ public class WeishiController { ...@@ -113,8 +116,26 @@ public class WeishiController {
*/ */
@PostMapping("/policyCancel/{policyNum}") @PostMapping("/policyCancel/{policyNum}")
public R<Void> policyCancel(@PathVariable String policyNum) { public R<Void> policyCancel(@PathVariable String policyNum) {
weishiService.policyCancel(policyNum); weishiService.policyCancel(getToken(), policyNum);
return R.ok(); return R.ok();
} }
private static final String WEISHI_TOKEN = "mall:third:weishi:token";
/**
* 获取token
*
* @return token
*/
private String getToken() {
String token = RedisUtils.getCacheObject(WEISHI_TOKEN);
if (StringUtils.isEmpty(token)) {
AuthResponse res = weishiService.authorize();
RedisUtils.setCacheObject(WEISHI_TOKEN, res.getAccess_token(), Duration.ofSeconds(res.getExpires_in().longValue()));
token = res.getAccess_token();
}
return token;
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论