|
@@ -0,0 +1,93 @@
|
|
|
|
|
+package com.uas.ps.inquiry.util;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.uas.ps.core.util.ContextUtils;
|
|
|
|
|
+import com.uas.ps.inquiry.AccessConfiguration;
|
|
|
|
|
+import com.uas.ps.inquiry.entity.MessageModel;
|
|
|
|
|
+import org.apache.log4j.Logger;
|
|
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 对接公共消息服务的接口
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author dongbw
|
|
|
|
|
+ * 2018-01-22 15:43:41
|
|
|
|
|
+ * @version 2018年6月13日 11:28:50 从B2B dongbw
|
|
|
|
|
+ */
|
|
|
|
|
+public class MessageUtils {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private static final String MESSAGE_PUBLIC_SERVICE_URL = ContextUtils.getBean(AccessConfiguration.class).getPsMessageUrl();
|
|
|
|
|
+
|
|
|
|
|
+ private static final Logger log = Logger.getLogger(Logger.class);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单次请求数据量大小
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final int ONE_TIME_DATA_SIZE = 500;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 产生消息
|
|
|
|
|
+ * @param models 消息实体List
|
|
|
|
|
+ * @return 返回信息
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String paginationProduceMessage(List<MessageModel> models) throws Exception {
|
|
|
|
|
+ if (models.size() < ONE_TIME_DATA_SIZE) {
|
|
|
|
|
+ return produceMessage(models);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ String res = "";
|
|
|
|
|
+ for (int i = 0; i < models.size(); i = i + ONE_TIME_DATA_SIZE) {
|
|
|
|
|
+ if (i + ONE_TIME_DATA_SIZE < models.size()) {
|
|
|
|
|
+ res = produceMessage(models.subList(i, i + ONE_TIME_DATA_SIZE));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ res = produceMessage(models.subList(i, models.size()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当前企业当前用户未读消息数量
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author dongbw
|
|
|
|
|
+ * @param enUU 企业UU
|
|
|
|
|
+ * @param userUU 用户UU
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Integer getMessageNotReadNum(Long enUU, Long userUU) throws Exception {
|
|
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("receiverUu", userUU);
|
|
|
|
|
+ params.put("receiverEnuu", enUU);
|
|
|
|
|
+ params.put("consumerApp", "B2B");
|
|
|
|
|
+ HttpUtil.Response res = HttpUtil.sendGetRequest(MESSAGE_PUBLIC_SERVICE_URL + "/messages/count/unread", params);
|
|
|
|
|
+ if (res.getStatusCode() == HttpStatus.OK.value() && null != res.getResponseText()) {
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(res.getResponseText());
|
|
|
|
|
+ return (Integer) jsonObject.get("count");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new RuntimeException("获取消息失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 产生消息
|
|
|
|
|
+ * @param models 消息实体List
|
|
|
|
|
+ * @return 返回信息
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String produceMessage(List<MessageModel> models) throws Exception {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String res = HttpUtil.doPost(MESSAGE_PUBLIC_SERVICE_URL + "/messages", FlexJsonUtils.toJsonDeep(models));
|
|
|
|
|
+ log.info("发送消息" + models.size());
|
|
|
|
|
+ return res;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException("本次产生消息失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //TODO 调用消息服务的方法都迁移到工具类中
|
|
|
|
|
+}
|