|
|
@@ -1,290 +0,0 @@
|
|
|
-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.prod.commodity.constant.IntegerConstant;
|
|
|
-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;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by wangyc on 2018/6/29.
|
|
|
- *
|
|
|
- * @version 2018/6/29 15:12 wangyc
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class MessageServiceImpl implements MessageService {
|
|
|
-
|
|
|
- private final SysConf sysConf;
|
|
|
-
|
|
|
- private final BoundedExecutor executor;
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String sendMessage(final List<MessageModel> models) {
|
|
|
- final Runnable sendMessage = new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- String result = HttpUtil.doPost(sysConf.getMessageServiceUrl() + "messages", FastjsonUtils.toJson(models));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- try {
|
|
|
- executor.submitTask(sendMessage);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return "false";
|
|
|
- }
|
|
|
- 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\"}");
|
|
|
- if (!StringUtils.isEmpty(type)) {
|
|
|
- map.put("type", type);
|
|
|
- }
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据所给字段生成消息
|
|
|
- *
|
|
|
- * @param content 发送内容
|
|
|
- * @param type 消息的类型,用户自己定义
|
|
|
- * @param receiverUu 接收人
|
|
|
- * @param receiverEnuu
|
|
|
- * @param consumerType 消费类型(所有应用共享:"PUBLIC",单个应用独享:"SINGLE",多个应用共享:"MULTI")
|
|
|
- * @param consumerApp MALL等
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public MessageModel initMessage(String content, String type, Long receiverUu, Long receiverEnuu, String consumerType, String consumerApp, String smsType, String remark, Long... args) {
|
|
|
- if (StringUtils.isEmpty(content) || StringUtils.isEmpty(type) || receiverUu == null || receiverEnuu == null || StringUtils.isEmpty(consumerType) || StringUtils.isEmpty(consumerApp)) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- MessageModel model = new MessageModel();
|
|
|
- model.setRemark(remark);
|
|
|
- model.setConsumerApp(consumerApp);
|
|
|
- model.setConsumerType(consumerType);
|
|
|
- model.setSmsType(smsType);
|
|
|
- model.setContent(content);
|
|
|
- model.setType(type);
|
|
|
- model.setCreateTime(new Date());
|
|
|
- model.setReceiverEnuu(receiverEnuu);
|
|
|
- model.setReceiverUu(receiverUu);
|
|
|
- if (args.length == 0) {
|
|
|
- User user = SystemSession.getUser();
|
|
|
- model.setSenderUu(user.getUserUU());
|
|
|
- if (user.getEnterprise() != null) {
|
|
|
- model.setSenderEnuu(user.getEnterprise().getUu());
|
|
|
- }
|
|
|
- } else {
|
|
|
- model.setSenderUu(args[0]);
|
|
|
- model.setSenderEnuu(args[1]);
|
|
|
- }
|
|
|
- model.setProducerApp(ProducerApp.MALL);
|
|
|
- return model;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取未读消息数量
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Map<String, Object> getUnReadMessageCount(String type) {
|
|
|
- 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);
|
|
|
- if (!StringUtils.isEmpty(type)) {
|
|
|
- map.put("type", type);
|
|
|
- }
|
|
|
- map.put("isRead", IntegerConstant.NO_INT);
|
|
|
- try {
|
|
|
- HttpUtil.Response response = HttpUtil.sendGetRequest(sysConf.getMessageServiceUrl() + "messages/count", 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);
|
|
|
- } else {
|
|
|
- return new ResultMap(CodeType.ERROR_STATE, hashedMap.get("data").toString());
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- return new ResultMap(CodeType.ERROR_STATE, "删除失败");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return new ResultMap(CodeType.ERROR_STATE, "删除失败");
|
|
|
- }
|
|
|
- return new ResultMap(CodeType.ERROR_STATE, "删除失败");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|