|
|
@@ -1,20 +1,36 @@
|
|
|
package com.uas.platform.b2c.common.psmessage.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.uas.platform.b2c.common.account.model.Enterprise;
|
|
|
import com.uas.platform.b2c.common.account.model.User;
|
|
|
+import com.uas.platform.b2c.common.account.service.EnterpriseService;
|
|
|
+import com.uas.platform.b2c.common.account.service.UserService;
|
|
|
import com.uas.platform.b2c.common.message.model.MessageModel;
|
|
|
+import com.uas.platform.b2c.common.message.type.ConsumerApp;
|
|
|
import com.uas.platform.b2c.common.message.type.ProducerApp;
|
|
|
import com.uas.platform.b2c.common.psmessage.service.MessageService;
|
|
|
+import com.uas.platform.b2c.common.psmessage.util.JsonObjectUtil;
|
|
|
import com.uas.platform.b2c.core.config.SysConf;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
+import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
+import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
import com.uas.platform.b2c.trade.util.BoundedExecutor;
|
|
|
+import com.uas.platform.core.model.PageInfo;
|
|
|
+import com.uas.platform.core.model.PageParams;
|
|
|
import com.uas.platform.core.util.HttpUtil;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
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.util.StringUtils;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
@@ -26,12 +42,19 @@ import java.util.concurrent.Executors;
|
|
|
@Service
|
|
|
public class MessageServiceImpl implements MessageService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private SysConf sysConf;
|
|
|
+ private final SysConf sysConf;
|
|
|
|
|
|
private final BoundedExecutor executor;
|
|
|
|
|
|
- public MessageServiceImpl() {
|
|
|
+ private final EnterpriseService enterpriseService;
|
|
|
+
|
|
|
+ private final UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public MessageServiceImpl(SysConf sysConf, EnterpriseService enterpriseService, UserService userService) {
|
|
|
+ this.sysConf = sysConf;
|
|
|
+ this.enterpriseService = enterpriseService;
|
|
|
+ this.userService = userService;
|
|
|
ExecutorService executorService = Executors.newCachedThreadPool();
|
|
|
executor = new BoundedExecutor(executorService, 1600);
|
|
|
}
|
|
|
@@ -42,7 +65,8 @@ public class MessageServiceImpl implements MessageService {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
- HttpUtil.doPost(sysConf.getMessageServiceUrl() + "messages", FastjsonUtils.toJson(models));
|
|
|
+ String result = HttpUtil.doPost(sysConf.getMessageServiceUrl() + "messages", FastjsonUtils.toJson(models));
|
|
|
+ System.out.println(result);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -57,6 +81,76 @@ public class MessageServiceImpl implements MessageService {
|
|
|
return "true";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据分页信息和过滤类型分页获取站内信
|
|
|
+ *
|
|
|
+ * @param params
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<MessageModel> findByPageAndParams(PageParams params, String type) {
|
|
|
+ if (params == null) {
|
|
|
+ params = new PageParams();
|
|
|
+ params.setPage(1);
|
|
|
+ params.setCount(10);
|
|
|
+ } else {
|
|
|
+ int page = params.getPage();
|
|
|
+ if (page < 1) {
|
|
|
+ params.setPage(1);
|
|
|
+ }
|
|
|
+ int count = params.getCount();
|
|
|
+ if (count < 1) {
|
|
|
+ params.setCount(10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ map.put("consumerApp", ConsumerApp.MALL);
|
|
|
+ map.put("isRead", 0);
|
|
|
+ map.put("page", params.getPage());
|
|
|
+ map.put("count", params.getCount());
|
|
|
+ map.put("sorting", "{\"createTime\":\"DESC\"}");
|
|
|
+ User user = SystemSession.getUser();
|
|
|
+ if (user != null) {
|
|
|
+ map.put("receiverUu", user.getUserUU());
|
|
|
+ Enterprise enterprise = user.getEnterprise();
|
|
|
+ if (enterprise != null) {
|
|
|
+ map.put("receiverEnuu", enterprise.getUu());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ HttpUtil.Response response = HttpUtil.sendGetRequest(sysConf.getMessageServiceUrl() + "messages", map);
|
|
|
+ int statusCode = response.getStatusCode();
|
|
|
+ if (statusCode == HttpStatus.OK.value()) {
|
|
|
+ String text = response.getResponseText();
|
|
|
+ if (!StringUtils.isEmpty(text)) {
|
|
|
+ JSONObject jsonObject = FastjsonUtils.fromJson(text, JSONObject.class);
|
|
|
+ Page<MessageModel> messageModels = JsonObjectUtil.convertToMessageModelPage(jsonObject);
|
|
|
+ for (MessageModel messageModel : messageModels) {
|
|
|
+ if (messageModel.getSenderEnuu() != null) {
|
|
|
+ Enterprise enterpriseInfo = enterpriseService.getEnterpriseInfo(messageModel.getSenderEnuu());
|
|
|
+ if (enterpriseInfo != null) {
|
|
|
+ messageModel.setSendEnterpriseName(enterpriseInfo.getEnName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (messageModel.getSenderUu() != null) {
|
|
|
+ User userByUserUU = userService.findUserByUserUU(messageModel.getSenderUu());
|
|
|
+ if (userByUserUU != null) {
|
|
|
+ messageModel.setSendUserName(userByUserUU.getUserName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return messageModels;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new PageImpl<MessageModel>(Collections.<MessageModel>emptyList(), new PageInfo(params), 0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return new PageImpl<MessageModel>(Collections.<MessageModel>emptyList(), new PageInfo(params), 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据所给字段生成消息
|
|
|
*
|
|
|
@@ -96,4 +190,89 @@ public class MessageServiceImpl implements MessageService {
|
|
|
return model;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取未读消息数量
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getUnReadMessageCount() {
|
|
|
+ Map<String , Object> resultMap = new HashedMap();
|
|
|
+ resultMap.put("success", "success");
|
|
|
+ resultMap.put("count", "0");
|
|
|
+ User user = SystemSession.getUser();
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ if (user != null) {
|
|
|
+ map.put("receiverUu", user.getUserUU());
|
|
|
+ Enterprise enterprise = user.getEnterprise();
|
|
|
+ if (enterprise != null) {
|
|
|
+ map.put("receiverEnuu", enterprise.getUu());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("consumerApp", ConsumerApp.MALL);
|
|
|
+ try {
|
|
|
+ HttpUtil.Response response = HttpUtil.sendGetRequest(sysConf.getMessageServiceUrl() + "messages/count/unread", map);
|
|
|
+ int statusCode = response.getStatusCode();
|
|
|
+ if (statusCode == HttpStatus.OK.value()) {
|
|
|
+ String responseText = response.getResponseText();
|
|
|
+ if (!StringUtils.isEmpty(responseText)) {
|
|
|
+ resultMap = FastjsonUtils.fromJson(responseText, HashedMap.class);
|
|
|
+ return resultMap;
|
|
|
+ } else {
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 短信
|
|
|
+ *
|
|
|
+ * @param messageId 消息的接口
|
|
|
+ * @return ModelMap
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap readMessage(Long messageId) {
|
|
|
+ Map<String, Object> resultMap = new HashedMap();
|
|
|
+ resultMap.put("success", "success");
|
|
|
+ resultMap.put("data", "");
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ if (messageId == null) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "未阅读任何信息");
|
|
|
+ } else {
|
|
|
+ map.put("messageId", messageId);
|
|
|
+ }
|
|
|
+ User user = SystemSession.getUser();
|
|
|
+ if (user != null) {
|
|
|
+ map.put("receiverUu", user.getUserUU());
|
|
|
+ Enterprise enterprise = user.getEnterprise();
|
|
|
+ if (enterprise != null) {
|
|
|
+ map.put("receiverEnuu", enterprise.getUu());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("consumerApp", ConsumerApp.MALL);
|
|
|
+ String response = null;
|
|
|
+ try {
|
|
|
+ response = HttpUtil.doPost(sysConf.getMessageServiceUrl() + "messages/read", FastjsonUtils.toJson(map));
|
|
|
+ if (!StringUtils.isEmpty(response)) {
|
|
|
+ HashedMap hashedMap = FastjsonUtils.fromJson(response, HashedMap.class);
|
|
|
+ if (hashedMap != null) {
|
|
|
+ Object success = hashedMap.get("success");
|
|
|
+ if ("success".equals(success)) {
|
|
|
+ return ResultMap.success(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return new ResultMap(CodeType.ERROR_STATE, "删除失败");
|
|
|
+ }
|
|
|
+ return new ResultMap(CodeType.ERROR_STATE, "删除失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|