Commit fc13a61d authored by 黎博's avatar 黎博

优化mock

parent 8c7260e1
......@@ -3,9 +3,14 @@ package cn.qg.holmes.interceptor;
import cn.qg.holmes.encrypt.LanzhouBankEncrypt;
import cn.qg.holmes.entity.lanzhou.BaseReq;
import cn.qg.holmes.entity.lanzhou.BaseResp;
import cn.qg.holmes.entity.mock.Mock;
import cn.qg.holmes.entity.mock.MockModule;
import cn.qg.holmes.mapper.mock.MockMapper;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
......@@ -28,6 +33,9 @@ public class LanzhouBankInterceptor implements HandlerInterceptor {
@Value("${lanzhou.lhp.private.key}")
private String lhpPrivateKey;
@Autowired
MockMapper mockMapper;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{
String uri = request.getRequestURI();
......@@ -38,16 +46,33 @@ public class LanzhouBankInterceptor implements HandlerInterceptor {
Map<String, Object> responseMap = new HashMap<>();
if (StringUtils.isNotBlank(requestMessage)) {
BaseReq<Map<String, String>> req = JSON.parseObject(requestMessage, BaseReq.class);
QueryWrapper<Mock> mockQueryWrapper = new QueryWrapper<>();
mockQueryWrapper.eq("url", uri);
Mock mock = mockMapper.selectOne(mockQueryWrapper);
if (req.getTranscode().equals("channel.common.queryapplyresult")) {
// 资方预审结果查询
Map<String, String> params = req.getT();
responseMap.put("channelserialno", params.get("channelserialno"));
responseMap.put("producttype", params.get("producttype"));
responseMap.put("submitflag", "10"); // 10-授信成功,04-授信失败,03-处理中
String submitflag = "10";
if (mock.getFlag() == 1) {
submitflag = JSON.parseObject(mock.getSuccess(), Map.class).get("submitflag").toString();
} else if (mock.getFlag() == 0) {
submitflag = JSON.parseObject(mock.getFail(), Map.class).get("submitflag").toString();
}
responseMap.put("submitflag", submitflag); // 10-授信成功,04-授信失败,03-处理中
} else if (req.getTranscode().equals("channel.common.querybusinessrate")) {
Double businessrate = 0.36;
if (mock.getFlag() == 1) {
businessrate = (Double) JSON.parseObject(mock.getSuccess(), Map.class).get("businessrate");
} else if (mock.getFlag() == 0) {
businessrate = (Double) JSON.parseObject(mock.getFail(), Map.class).get("businessrate");
}
// 利率查询接口
responseMap.put("businessrate", 0.36);
responseMap.put("businessrate", businessrate);
} else {
responseMap.put("msg", "接口mock暂不支持!");
}
BaseResp<Map<String, Object>> resp = new BaseResp();
resp.setResult(responseMap);
......@@ -60,13 +85,10 @@ public class LanzhouBankInterceptor implements HandlerInterceptor {
respStr.put("signature", messageArray[1]);
InterceptorUtils.constructResponse(response, JSON.toJSONString(respStr), "application/json; charset=utf-8");
return false;
} else {
log.info("接口{} 的mock暂不支持!", uri);
Map<String, String> respStr = new HashMap<>();
respStr.put("message", "Mock暂不支持!");
InterceptorUtils.constructResponse(response, JSON.toJSONString(respStr), "application/json; charset=utf-8");
return false;
}
log.info("兰银请求异常!");
InterceptorUtils.constructResponse(response, null, "application/json; charset=utf-8");
return false;
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment