Commit 5ec5bec0 authored by 黎博's avatar 黎博

/api/message/get逻辑优化

parent e83ccfc6
package cn.qg.holmes.controller.mock.keystone.jdbuy; package cn.qg.holmes.controller.mock.keystone.jdbuy;
import cn.qg.holmes.bean.KeystoneService; import cn.qg.holmes.bean.KeystoneService;
import cn.qg.holmes.common.JsonResult;
import cn.qg.holmes.entity.mock.keystone.ProductItem; import cn.qg.holmes.entity.mock.keystone.ProductItem;
import cn.qg.holmes.entity.mock.keystone.SupplierOrderSku; import cn.qg.holmes.entity.mock.keystone.SupplierOrderSku;
import cn.qg.holmes.entity.mock.keystone.jdbuy.*; import cn.qg.holmes.entity.mock.keystone.jdbuy.*;
...@@ -15,6 +16,7 @@ import org.apache.commons.lang.RandomStringUtils; ...@@ -15,6 +16,7 @@ import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -41,6 +43,7 @@ public class OrderController { ...@@ -41,6 +43,7 @@ public class OrderController {
@Autowired @Autowired
RedisUtils redisUtils; RedisUtils redisUtils;
private String QYG_ORDER_PREFIX = "qyg_order_"; private String QYG_ORDER_PREFIX = "qyg_order_";
private String API_MESSAGE_PREFIX = "api_msg_";
/** /**
* 7.3 企业购提交订单 * 7.3 企业购提交订单
...@@ -433,6 +436,24 @@ public class OrderController { ...@@ -433,6 +436,24 @@ public class OrderController {
return response; return response;
} }
/**
* 上传mock消息给/api/message/get接口使用
* @param request
* @return
*/
@PostMapping("/jdbuy/message/mock")
public JsonResult jdbuyMessageMock(@RequestBody ApiMessageGetRequest request) {
try {
String type = request.getType();
String result = JSON.toJSONString(request.getResult());
redisUtils.set(API_MESSAGE_PREFIX + type, result, 172800);
return JsonResult.buildSuccessResult("消息上传成功.");
} catch (Exception e) {
e.printStackTrace();
return JsonResult.buildErrorStateResult("消息上传失败, result格式不对", false);
}
}
/** /**
* 11.1 查询推送消息 * 11.1 查询推送消息
* *
...@@ -442,50 +463,64 @@ public class OrderController { ...@@ -442,50 +463,64 @@ public class OrderController {
public JdCompanyMsgResponse qygMessageGet(JdCompanyMsgRequest request) { public JdCompanyMsgResponse qygMessageGet(JdCompanyMsgRequest request) {
String type = request.getType(); String type = request.getType();
JdCompanyMsgResponse response = new JdCompanyMsgResponse(); JdCompanyMsgResponse response = new JdCompanyMsgResponse();
Object value = redisUtils.get(API_MESSAGE_PREFIX + type);
if (value != null) {
response.setSuccess(true); response.setSuccess(true);
response.setResultMessage(""); response.setResultMessage("");
response.setResultCode("0000"); response.setResultCode("0000");
List<Map<String, Object>> result = new ArrayList<>(); response.setResult((List<Map<String, Object>>) JSONArray.parse(value.toString()));
switch (type) { redisUtils.del(API_MESSAGE_PREFIX + type);
case "10": } else {
// TODO response.setSuccess(false);
break; response.setResultCode("0010");
case "31": response.setResultMessage("暂无新消息");
// TODO response.setResult(null);
break;
case "104":
// 获取所有key
Set<String> set = redisUtils.keys("afs:outline:*");
if (!set.isEmpty()) {
// 循环遍历key,获取value
for (String afsOutlineKey: set) {
String afsOutlineValue = redisUtils.get(afsOutlineKey).toString();
AfsOutlineRequest.AfsOutlineParam afsOutlineParam = JSON.parseObject(afsOutlineValue, AfsOutlineRequest.AfsOutlineParam.class);
Map<String, Object> map = new HashMap<>();
map.put("id", Long.valueOf(RandomStringUtils.randomNumeric(16)));
map.put("time", DateUtils.convertDate(new Date(), "yyyy-mm-dd hh:MM:ss"));
map.put("type", 104);
Map<String, Object> childMap = new HashMap<>();
childMap.put("expectationChanged", true);
childMap.put("thirdApplyId", afsOutlineParam.getThirdApplyId());
childMap.put("pin", "北京量化派VOP");
childMap.put("stepPassType", 10);
childMap.put("isOffline", true);
childMap.put("applyStep", 60);
childMap.put("contractNumber", "VOP-20201209182245");
childMap.put("orderId", afsOutlineParam.getOrderId());
map.put("result", childMap);
// 处理完就删除
redisUtils.del("afs:outline:" + afsOutlineParam.getOrderId());
result.add(map);
}
}
break;
default:
break;
} }
response.setResult(result); // switch (type) {
// case "2":
// case "10":
// case "50":
// case "109":
// // 2-商品价格变更, 10-订单消息取消,50-京东地址变更,109-退款消息
// Object value = redisUtils.get(API_MESSAGE_PREFIX + type);
// if (value != null) {
// response.setResult((List<Map<String, Object>>) JSONArray.parse(value.toString()));
// }
// break;
// case "104":
// // 获取所有key
// List<Map<String, Object>> result = new ArrayList<>();
// Set<String> set = redisUtils.keys("afs:outline:*");
// if (!set.isEmpty()) {
// // 循环遍历key,获取value
// for (String afsOutlineKey: set) {
// String afsOutlineValue = redisUtils.get(afsOutlineKey).toString();
// AfsOutlineRequest.AfsOutlineParam afsOutlineParam = JSON.parseObject(afsOutlineValue, AfsOutlineRequest.AfsOutlineParam.class);
// Map<String, Object> map = new HashMap<>();
// map.put("id", Long.valueOf(RandomStringUtils.randomNumeric(16)));
// map.put("time", DateUtils.convertDate(new Date(), "yyyy-mm-dd hh:MM:ss"));
// map.put("type", 104);
// Map<String, Object> childMap = new HashMap<>();
// childMap.put("expectationChanged", true);
// childMap.put("thirdApplyId", afsOutlineParam.getThirdApplyId());
// childMap.put("pin", "北京量化派VOP");
// childMap.put("stepPassType", 10);
// childMap.put("isOffline", true);
// childMap.put("applyStep", 60);
// childMap.put("contractNumber", "VOP-20201209182245");
// childMap.put("orderId", afsOutlineParam.getOrderId());
// map.put("result", childMap);
//
// // 处理完就删除
// redisUtils.del("afs:outline:" + afsOutlineParam.getOrderId());
// result.add(map);
// }
// }
// response.setResult(result);
// break;
// default:
// break;
// }
return response; return response;
} }
......
package cn.qg.holmes.entity.mock.keystone.jdbuy;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class ApiMessageGetRequest {
private String type;
private List<Map<String, Object>> result;
}
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