| | |
| | | package com.yeshi.fanli.util;
|
| | |
|
| | | import java.lang.reflect.Type;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | |
| | | import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.qcloud.cmq.Message;
|
| | | import com.yeshi.fanli.dto.HongBao;
|
| | | import com.yeshi.fanli.entity.bus.user.AlipayTransferResultInfo;
|
| | |
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.common.AdminUser;
|
| | | import com.yeshi.fanli.entity.push.PushQueueRecord;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | public class CMQManager {
|
| | | private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25";
|
| | |
| | | private static CMQUtil cmqUtil;
|
| | | // TODO 订单处理队列
|
| | | public static String QUEUENAME_ORDER = "fanli-orders";
|
| | |
|
| | | // 刚刚产生的订单处理队列
|
| | | public static String QUEUENAME_NEW_ORDER = "fanli-new-orders";
|
| | |
|
| | | // 提现结果处理队列
|
| | | public static String EXTRACT_RESULT = "extract-result";
|
| | | // TODO IOS推送队列
|
| | |
| | |
|
| | | if (Constant.IS_TEST) {
|
| | | QUEUENAME_ORDER = "test-" + QUEUENAME_ORDER;
|
| | | QUEUENAME_NEW_ORDER = "test-" + QUEUENAME_NEW_ORDER;
|
| | | EXTRACT_RESULT = "test-" + EXTRACT_RESULT;
|
| | | PUSH_IOS = "test-" + PUSH_IOS;
|
| | | FANLI_ORDER = "test-" + FANLI_ORDER;
|
| | |
| | | }
|
| | |
|
| | | QUEUENAME_ORDER += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | QUEUENAME_NEW_ORDER += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | EXTRACT_RESULT += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | PUSH_IOS += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | FANLI_ORDER += "-" + Constant.systemCommonConfig.getProjectName();
|
| | |
| | | cmqUtil = CMQUtil.getInstance(secretId, secretKey);
|
| | | // 最大消息为1M
|
| | | cmqUtil.createQueue(QUEUENAME_ORDER, 1024 * 1024);
|
| | | cmqUtil.createQueue(QUEUENAME_NEW_ORDER, 1024 * 1024);
|
| | | cmqUtil.createQueue(EXTRACT_RESULT);
|
| | | cmqUtil.createQueue(PUSH_IOS);
|
| | | cmqUtil.createQueue(FANLI_ORDER);
|
| | |
| | | *
|
| | | * @param orderMap
|
| | | */
|
| | | public void addTaoBaoOrderMsg(String orderId, List<TaoBaoOrder> orderList) {
|
| | | if (!StringUtil.isNullOrEmpty(orderId) && orderList != null && orderList.size() > 0) {
|
| | | JSONObject item = new JSONObject();
|
| | | item.put(orderId, new GsonBuilder().create().toJson(orderList));
|
| | | cmqUtil.sendMsg(QUEUENAME_ORDER, item.toString());
|
| | | public void addTaoBaoOrderMsg(String orderId) {
|
| | | if (!StringUtil.isNullOrEmpty(orderId)) {
|
| | | cmqUtil.sendMsg(QUEUENAME_ORDER, orderId);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | *
|
| | | * @param count
|
| | | */
|
| | | @SuppressWarnings("unchecked")
|
| | | public Map<String, List<TaoBaoOrder>> consumeTaoBaoOrderMsg(int count) {
|
| | | public List<String> consumeTaoBaoOrderMsg(int count) {
|
| | | List<String> resultList = new ArrayList<>();
|
| | | List<Message> list = cmqUtil.recieveMsg(count, QUEUENAME_ORDER);
|
| | | Map<String, List<TaoBaoOrder>> map = new HashMap<>();
|
| | |
|
| | | if (list != null)
|
| | | for (Message msg : list) {
|
| | | String result = msg.msgBody;
|
| | | JSONObject data = JSONObject.fromObject(result);
|
| | | Iterator<String> its = data.keySet().iterator();
|
| | | if (its.hasNext()) {
|
| | | String orderId = its.next();
|
| | | Type type = new TypeToken<List<TaoBaoOrder>>() {
|
| | | }.getType();
|
| | | List<TaoBaoOrder> orderList = new Gson().fromJson(data.optJSONArray(orderId).toString(), type);
|
| | | map.put(orderId, orderList);
|
| | | }
|
| | | resultList.add(result);
|
| | | // 删除消息
|
| | | cmqUtil.deleteMsg(QUEUENAME_ORDER, msg.receiptHandle);
|
| | | }
|
| | | return map;
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param receiptHandle
|
| | | */
|
| | | public void deleteTaoBaoOrderMsg(String receiptHandle) {
|
| | | cmqUtil.deleteMsg(EXTRACT_RESULT, receiptHandle);
|
| | | cmqUtil.deleteMsg(QUEUENAME_ORDER, receiptHandle);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 发送订单消息(刚刚产生的订单)
|
| | | * |
| | | * @param orderMap
|
| | | */
|
| | | public void addTaoBaoNewOrderMsg(String orderId) {
|
| | | if (!StringUtil.isNullOrEmpty(orderId)) {
|
| | | cmqUtil.sendMsg(QUEUENAME_NEW_ORDER, orderId);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 消费淘宝订单消息(刚刚产生的订单)
|
| | | * |
| | | * @param count
|
| | | */
|
| | | public List<String> consumeTaoBaoNewOrderMsg(int count) {
|
| | | List<String> resultList = new ArrayList<>();
|
| | | List<Message> list = cmqUtil.recieveMsg(count, QUEUENAME_NEW_ORDER);
|
| | |
|
| | | if (list != null)
|
| | | for (Message msg : list) {
|
| | | String result = msg.msgBody;
|
| | | resultList.add(result);
|
| | | // 删除消息
|
| | | cmqUtil.deleteMsg(QUEUENAME_NEW_ORDER, msg.receiptHandle);
|
| | | }
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除淘宝订单消息(刚刚产生的订单)
|
| | | * |
| | | * @param receiptHandle
|
| | | */
|
| | | public void deleteTaoBaoNewOrderMsg(String receiptHandle) {
|
| | | cmqUtil.deleteMsg(QUEUENAME_NEW_ORDER, receiptHandle);
|
| | | }
|
| | |
|
| | | /**
|