|
|
@@ -1,16 +1,36 @@
|
|
|
package com.uas.platform.b2c.common.message.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.alibaba.fastjson.parser.Feature;
|
|
|
+import com.uas.platform.b2c.advertise.ad.model.Message;
|
|
|
+import com.uas.platform.b2c.common.message.model.MessageModel;
|
|
|
import com.uas.platform.b2c.common.message.service.InternalMessageService;
|
|
|
+import com.uas.platform.b2c.core.config.MessageConf;
|
|
|
import com.uas.platform.b2c.core.config.MicroServicesConf;
|
|
|
import com.uas.platform.b2c.core.config.SysConf;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
+import com.uas.platform.b2c.core.utils.ContextUtils;
|
|
|
+import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
import com.uas.platform.b2c.trade.deprecated.model.BasicMessage;
|
|
|
+import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.PageParams;
|
|
|
import com.uas.platform.core.model.Type;
|
|
|
+import com.uas.platform.core.util.HttpUtil;
|
|
|
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
+import com.uas.ps.core.util.ObjectUtils;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
+import org.apache.commons.collections.map.ListOrderedMap;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.apache.velocity.app.VelocityEngine;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.velocity.VelocityEngineUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
@@ -18,6 +38,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
@@ -34,6 +55,34 @@ public class InternalMessageServiceImpl implements InternalMessageService {
|
|
|
|
|
|
private final SysConf sysConf;
|
|
|
|
|
|
+ private static final String MESSAGE_PUBLIC_SERVICE_URL = ContextUtils.getBean(MessageConf.class).getMessagePublicServiceDevUrl();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消息类型,公共询价的采纳结果
|
|
|
+ */
|
|
|
+ private final String INQUIRY_DECIDE_TYPE = "公共询价采纳结果";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消息类型 (在MALL消息中拼接跳转单据详情url请求时需要)
|
|
|
+ */
|
|
|
+ private final String INQUIRY_TYPE = "公共询价";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消息类型,公共询价的采纳结果
|
|
|
+ */
|
|
|
+ private final String INQUIRY_DECIDE_TYPE_MALL = "商城公共询价采纳结果";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消息类型 (在MALL消息中拼接求购询价待报价)
|
|
|
+ */
|
|
|
+ private final String INQUIRY_TYPE_SELLER_MALL = "MALL跳转卖家待报价页面";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消息类型 (在B2B消息中拼接跳转单据详情url请求时需要)
|
|
|
+ */
|
|
|
+ private final String INQUIRY_TYPE_MALL = "MALL公共询价";
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
public InternalMessageServiceImpl(MicroServicesConf conf, RestTemplate restTemplate,VelocityEngine velocityEngine, SysConf sysConf) {
|
|
|
this.conf = conf;
|
|
|
@@ -203,5 +252,133 @@ public class InternalMessageServiceImpl implements InternalMessageService {
|
|
|
JSONObject result = restTemplate.getForObject(url, JSONObject.class);
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置已读
|
|
|
+ * @param content 传入信息内容
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void setRead(JSONArray content)throws Exception {
|
|
|
+ if (!ObjectUtils.isEmpty(content)) {
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ StringBuilder idString = new StringBuilder();
|
|
|
+ List<MessageModel> models = FastjsonUtils.fromJsonArray( content.toString(), MessageModel.class);
|
|
|
+ for(MessageModel m :models) {
|
|
|
+ if (!StringUtils.isEmpty(idString.toString())) {
|
|
|
+ idString.append(",");
|
|
|
+ }
|
|
|
+ idString.append(m.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+ params.put("messageId", idString.toString());
|
|
|
+ params.put("receiverUu", SystemSession.getUser().getUserUU());
|
|
|
+ params.put("receiverEnuu", SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ params.put("consumerApp", "MALL");
|
|
|
+
|
|
|
+ String res = HttpUtil.doPost(MESSAGE_PUBLIC_SERVICE_URL + "/messages/read", FlexJsonUtils.toJsonDeep(params));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前企业当前用户未读消息数量
|
|
|
+ *
|
|
|
+ * @author dongbw
|
|
|
+ * @param enUU 企业UU
|
|
|
+ * @param userUU 用户UU
|
|
|
+ * @return isRead 0为未读 1为已读 不传即为所有信息
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer getMessageNum(Long enUU, Long userUU, Short isRead) throws Exception {
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ params.put("receiverUu", userUU);
|
|
|
+ params.put("receiverEnuu", enUU);
|
|
|
+ params.put("consumerApp", "MALL");
|
|
|
+ params.put("isRead", isRead == null ? "" : isRead);
|
|
|
+ HttpUtil.Response res = HttpUtil.sendGetRequest(MESSAGE_PUBLIC_SERVICE_URL + "/messages/count", 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("获取消息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取消息的方法
|
|
|
+ *
|
|
|
+ * @author dongbw
|
|
|
+ * @param pageParams 分页参数
|
|
|
+ * @param isRead 阅读状态 1已读 0 未读
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public JSONObject getMessagesPagePrivate(PageParams pageParams, Short isRead, String keyword) throws Exception {
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ params.put("receiverUu", SystemSession.getUser().getUserUU());
|
|
|
+ params.put("receiverEnuu", SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ params.put("consumerApp", "MALL");
|
|
|
+// params.put("pageParams", FlexJsonUtils.toJsonDeep(pageParams));
|
|
|
+ params.put("page", pageParams.getPage());
|
|
|
+ params.put("sorting", pageParams.getSorting() == null ? "{\"createTime\":\"DESC\"}" : pageParams.getSorting());
|
|
|
+ params.put("count", pageParams.getCount());
|
|
|
+ params.put("isRead", isRead == null ? "" : isRead);
|
|
|
+ if (null != keyword && !"".equals(keyword)) {
|
|
|
+ params.put("keyword", keyword);
|
|
|
+ }
|
|
|
+ HttpUtil.Response res = HttpUtil.sendGetRequest(MESSAGE_PUBLIC_SERVICE_URL + "/messages", params);
|
|
|
+
|
|
|
+ if (HttpStatus.OK.value() == res.getStatusCode()) {
|
|
|
+ if (null != res.getResponseText()) {
|
|
|
+ System.out.println(res.getResponseText());
|
|
|
+ JSONObject jsonObject = FastjsonUtils.fromJson(res.getResponseText(), JSONObject.class);
|
|
|
+ String content = jsonObject.getString("content");
|
|
|
+ if (!StringUtils.isEmpty(content)) {
|
|
|
+ List<MessageModel> models = FastjsonUtils.fromJsonArray(content, MessageModel.class);
|
|
|
+ if (CollectionUtils.isNotEmpty(models)) {
|
|
|
+ for (MessageModel messageModel : models) {
|
|
|
+ // 拼接公共询价链接
|
|
|
+ if (INQUIRY_TYPE_MALL.equals(messageModel.getType()) ) {
|
|
|
+ messageModel.setUrl("/user#/seekPurchase" );
|
|
|
+ } else if (INQUIRY_DECIDE_TYPE_MALL.equals(messageModel.getType())||INQUIRY_DECIDE_TYPE.equals(messageModel.getType())) {
|
|
|
+ messageModel.setUrl("/vendor#/vendorPurchaseOffer" );
|
|
|
+ } else if (INQUIRY_TYPE_SELLER_MALL.equals(messageModel.getType())||INQUIRY_TYPE.equals(messageModel.getType())) {
|
|
|
+ messageModel.setUrl("/vendor#/seekPurchase" );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jsonObject.remove("content");
|
|
|
+ jsonObject.put("content", models);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return jsonObject;
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("获取消息失败");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+// public Page<MessageModel> getMessageUrl(String keyword, PageParams params, Short isRead) throws Exception {
|
|
|
+// Page<MessageModel> page = getMessagesPagePrivate(params,isRead,keyword);
|
|
|
+// if (page != null) {
|
|
|
+// for (MessageModel messageModel : page.getContent()) {
|
|
|
+// // 拼接公共询价链接
|
|
|
+// if (INQUIRY_TYPE.equals(messageModel.getType())) {
|
|
|
+// messageModel.setUrl("#/DECIDE" );
|
|
|
+// } else if (INQUIRY_DECIDE_TYPE_MALL.equals(messageModel.getType())) {
|
|
|
+// messageModel.setUrl("#/vendorPurchaseOffer" );
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return page;
|
|
|
+// }
|
|
|
+
|
|
|
}
|
|
|
|