| | |
| | | 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 net.sf.json.JSONObject;
|
| | | import org.yeshi.utils.CMQUtil;
|
| | |
|
| | | 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.Extract;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBao;
|
| | | 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 org.yeshi.utils.CMQUtil;
|
| | |
|
| | | public class CMQManager {
|
| | | private static String secretId = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25";
|
| | | private static String secretKey = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo";
|
| | | private static CMQManager cmqManager;
|
| | | 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推送队列
|
| | | // IOS推送队列
|
| | | public static String PUSH_IOS = "push-ios";
|
| | |
|
| | | // TODO 返利队列
|
| | | // 返利队列
|
| | | public static String FANLI_ORDER = "fanli-order";
|
| | | // TODO 提成订单
|
| | |
|
| | | // 返利队列
|
| | | public static String FANLI_ORDER_NEW = "fanli-order-new";
|
| | |
|
| | | // 提成订单
|
| | | public static String FANLI_TICHENG_ORDER = "fanli-ticheng-order";
|
| | | // TODO 维权订单
|
| | | |
| | | // 团队奖励到账
|
| | | public static String FANLI_ORDER_TEAM_REWARD="fanli-order-team-reward";
|
| | | |
| | | // 维权订单
|
| | | public static String ORDER_WEIQUAN = "weiquan-order";
|
| | |
|
| | | public static String GOODS_UPDATE = "goods_update_queue";
|
| | | // 重要数据更新
|
| | | public static String IMPORTANT_GOODS_UPDATE = "imp_goods_update_queue";
|
| | |
|
| | | static {
|
| | |
|
| | | 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;
|
| | | FANLI_ORDER_NEW = "test-" + FANLI_ORDER_NEW;
|
| | | FANLI_TICHENG_ORDER = "test-" + FANLI_TICHENG_ORDER;
|
| | | |
| | | FANLI_ORDER_TEAM_REWARD = "test-" + FANLI_ORDER_TEAM_REWARD;
|
| | | |
| | | ORDER_WEIQUAN = "test-" + ORDER_WEIQUAN;
|
| | | IMPORTANT_GOODS_UPDATE = "test-" + IMPORTANT_GOODS_UPDATE;
|
| | | }
|
| | |
|
| | | 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();
|
| | | FANLI_ORDER_NEW += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | FANLI_TICHENG_ORDER += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | FANLI_ORDER_TEAM_REWARD += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | |
| | | ORDER_WEIQUAN += "-" + Constant.systemCommonConfig.getProjectName();
|
| | | IMPORTANT_GOODS_UPDATE += "-" + 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);
|
| | | cmqUtil.createQueue(FANLI_ORDER_NEW);
|
| | | cmqUtil.createQueue(FANLI_TICHENG_ORDER);
|
| | | cmqUtil.createQueue(FANLI_ORDER_TEAM_REWARD);
|
| | | cmqUtil.createQueue(ORDER_WEIQUAN);
|
| | | cmqUtil.createQueue(GOODS_UPDATE);
|
| | | cmqUtil.createQueue(IMPORTANT_GOODS_UPDATE);
|
| | | }
|
| | |
|
| | | public static CMQManager getInstance() {
|
| | |
| | | *
|
| | | * @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);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | cmqUtil.sendMsg(FANLI_ORDER, content);
|
| | | }
|
| | |
|
| | | // 新版订单返利
|
| | | public void addFanLiMsgNew(HongBaoV2 hongBao) {
|
| | | String content = new Gson().toJson(hongBao);
|
| | | cmqUtil.sendMsg(FANLI_ORDER_NEW, content);
|
| | | }
|
| | |
|
| | | public Map<String, HongBao> consumeFanLiMsg(int count) {
|
| | | List<Message> list = cmqUtil.recieveMsg(count, FANLI_ORDER);
|
| | | Map<String, HongBao> map = new HashMap<>();
|
| | |
| | | return map;
|
| | | }
|
| | |
|
| | | public Map<String, HongBaoV2> consumeFanLiMsgNew(int count) {
|
| | | List<Message> list = cmqUtil.recieveMsg(count, FANLI_ORDER_NEW);
|
| | | Map<String, HongBaoV2> map = new HashMap<>();
|
| | | if (list != null)
|
| | | for (Message msg : list) {
|
| | | String result = msg.msgBody;
|
| | | if (!StringUtil.isNullOrEmpty(result)) {
|
| | | HongBaoV2 hongBao = new Gson().fromJson(result, HongBaoV2.class);
|
| | | map.put(msg.receiptHandle, hongBao);
|
| | | }
|
| | | }
|
| | | return map;
|
| | | }
|
| | |
|
| | | public void deleteFanLiMsg(String receiptHandle) {
|
| | | cmqUtil.deleteMsg(FANLI_ORDER, receiptHandle);
|
| | | }
|
| | |
|
| | | public void deleteFanLiMsgNew(String receiptHandle) {
|
| | | cmqUtil.deleteMsg(FANLI_ORDER_NEW, receiptHandle);
|
| | | }
|
| | |
|
| | | // 提成返利
|
| | |
| | | cmqUtil.deleteMsg(FANLI_TICHENG_ORDER, receiptHandle);
|
| | | }
|
| | |
|
| | | |
| | | |
| | | // 团队奖励
|
| | | public void addFanLiOrderTeamRewardMsg(Long uid) {
|
| | | cmqUtil.sendMsg(FANLI_ORDER_TEAM_REWARD, uid + "");
|
| | | }
|
| | |
|
| | | public Map<String, Long> consumeOrderTeamRewardMsg(int count) {
|
| | | List<Message> list = cmqUtil.recieveMsg(count, FANLI_ORDER_TEAM_REWARD);
|
| | | Map<String, Long> map = new HashMap<>();
|
| | | if (list != null)
|
| | | for (Message msg : list) {
|
| | | String result = msg.msgBody;
|
| | | if (!StringUtil.isNullOrEmpty(result)) {
|
| | | map.put(msg.receiptHandle, Long.parseLong(result));
|
| | | }
|
| | | }
|
| | | return map;
|
| | | }
|
| | |
|
| | | public void deleteOrderTeamRewardMsg(String receiptHandle) {
|
| | | cmqUtil.deleteMsg(FANLI_ORDER_TEAM_REWARD, receiptHandle);
|
| | | }
|
| | | |
| | | // 维权订单
|
| | | public void addWeiQuanOrderMsg(TaoBaoWeiQuanOrder order) {
|
| | | cmqUtil.sendMsg(ORDER_WEIQUAN, new Gson().toJson(order));
|
| | |
| | | cmqUtil.deleteMsg(GOODS_UPDATE, receiptHandle);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加淘宝重要商品更新
|
| | | * |
| | | * @param actionId
|
| | | */
|
| | | public void addTBImpGoodsUpdate(Long actionId) {
|
| | | cmqUtil.sendMsg(IMPORTANT_GOODS_UPDATE, actionId + "");
|
| | | }
|
| | |
|
| | | /**
|
| | | * 读取重要商品更新队列
|
| | | * |
| | | * @param count
|
| | | * @return
|
| | | */
|
| | | public Map<String, Long> consumeTBImpGoodsUpdateMsg(int count) {
|
| | | List<Message> list = cmqUtil.recieveMsg(count, IMPORTANT_GOODS_UPDATE);
|
| | | if (list == null) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | Map<String, Long> map = new HashMap<>();
|
| | | for (Message msg : list) {
|
| | | String result = msg.msgBody;
|
| | | if (!StringUtil.isNullOrEmpty(result)) {
|
| | | map.put(msg.receiptHandle, Long.parseLong(result));
|
| | | }
|
| | | }
|
| | | return map;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除队列消息
|
| | | * |
| | | * @param receiptHandle
|
| | | */
|
| | | public void deleteTBImpGoodsUpdateMsg(String receiptHandle) {
|
| | | cmqUtil.deleteMsg(IMPORTANT_GOODS_UPDATE, receiptHandle);
|
| | | }
|
| | |
|
| | | }
|