Authored by csgyoho

Merge branch 'dev-ufoyohoinbox-20181218' into test6.8.4

1 package com.yohoufo.user.controller.inbox; 1 package com.yohoufo.user.controller.inbox;
2 2
3 import com.alibaba.fastjson.JSONArray; 3 import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
4 import com.yoho.error.ServiceError; 5 import com.yoho.error.ServiceError;
5 import com.yoho.error.exception.ServiceException; 6 import com.yoho.error.exception.ServiceException;
6 import com.yohoufo.common.ApiResponse; 7 import com.yohoufo.common.ApiResponse;
@@ -39,7 +40,7 @@ public class InBoxController { @@ -39,7 +40,7 @@ public class InBoxController {
39 logger.info("enter listInboxTypeInfo param is {}", reqBO); 40 logger.info("enter listInboxTypeInfo param is {}", reqBO);
40 // (1)判断用户id是否存在 41 // (1)判断用户id是否存在
41 if (null == reqBO || reqBO.getUid() < 1) { 42 if (null == reqBO || reqBO.getUid() < 1) {
42 - logger.warn("Uid is null or 0."); 43 + logger.warn("listInboxTypeInfo:Uid is null or 0.");
43 throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL); 44 throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
44 } 45 }
45 JSONArray allTabs = inBoxService.listInboxTypeInfo(reqBO); 46 JSONArray allTabs = inBoxService.listInboxTypeInfo(reqBO);
@@ -47,6 +48,22 @@ public class InBoxController { @@ -47,6 +48,22 @@ public class InBoxController {
47 } 48 }
48 49
49 /** 50 /**
  51 + * 获取未读消息总数和最新一条未读记录
  52 + * @param reqBO
  53 + */
  54 + @RequestMapping(params = "method=ufo.users.getTotalUnread")
  55 + public ApiResponse getTotalUnread(ListInboxTypeInfoReqVO reqBO){
  56 + logger.info("enter getTotalUnread param is {}", reqBO);
  57 + // (1)判断用户id是否存在
  58 + if (null == reqBO || reqBO.getUid() < 1) {
  59 + logger.warn("getTotalUnread:Uid is null or 0.");
  60 + throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
  61 + }
  62 + JSONObject result = inBoxService.getTotalUnread(reqBO.getUid());
  63 + return new ApiResponse(200,"操作成功",result);
  64 + }
  65 +
  66 + /**
50 * 查询消息列表 67 * 查询消息列表
51 * @param reqVO 68 * @param reqVO
52 * reqVO.type 为 null,查询最新消息; 69 * reqVO.type 为 null,查询最新消息;
@@ -14,7 +14,7 @@ public class PageReqVO extends BaseVO{ @@ -14,7 +14,7 @@ public class PageReqVO extends BaseVO{
14 } 14 }
15 15
16 public void setLimit(int limit) { 16 public void setLimit(int limit) {
17 - this.limit = limit<10 ? 10 : limit; 17 + this.limit = limit;
18 } 18 }
19 19
20 public int getPage() { 20 public int getPage() {
1 package com.yohoufo.user.service; 1 package com.yohoufo.user.service;
2 2
3 import com.alibaba.fastjson.JSONArray; 3 import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
4 import com.yohoufo.dal.user.model.InBox; 5 import com.yohoufo.dal.user.model.InBox;
5 import com.yohoufo.user.requestVO.ListInboxReqVO; 6 import com.yohoufo.user.requestVO.ListInboxReqVO;
6 import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO; 7 import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
@@ -20,4 +21,6 @@ public interface IInBoxService { @@ -20,4 +21,6 @@ public interface IInBoxService {
20 PageResponseVO<InBox> listInboxByTypes(ListInboxReqVO reqVO); 21 PageResponseVO<InBox> listInboxByTypes(ListInboxReqVO reqVO);
21 22
22 void addInbox(int uid, Integer type, Integer businessType, String params); 23 void addInbox(int uid, Integer type, Integer businessType, String params);
  24 +
  25 + JSONObject getTotalUnread(int uid);
23 } 26 }
@@ -18,6 +18,7 @@ import com.yohoufo.user.requestVO.ListInboxReqVO; @@ -18,6 +18,7 @@ import com.yohoufo.user.requestVO.ListInboxReqVO;
18 import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO; 18 import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
19 import com.yohoufo.user.responseVO.PageResponseVO; 19 import com.yohoufo.user.responseVO.PageResponseVO;
20 import com.yohoufo.user.service.IInBoxService; 20 import com.yohoufo.user.service.IInBoxService;
  21 +import org.apache.commons.collections.CollectionUtils;
21 import org.apache.commons.lang3.StringUtils; 22 import org.apache.commons.lang3.StringUtils;
22 import org.slf4j.Logger; 23 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory; 24 import org.slf4j.LoggerFactory;
@@ -43,6 +44,13 @@ public class InBoxServiceImpl implements IInBoxService { @@ -43,6 +44,13 @@ public class InBoxServiceImpl implements IInBoxService {
43 public JSONArray listInboxTypeInfo(ListInboxTypeInfoReqVO reqBO) { 44 public JSONArray listInboxTypeInfo(ListInboxTypeInfoReqVO reqBO) {
44 log.info("listInboxTypeInfo begin.param is {}",reqBO); 45 log.info("listInboxTypeInfo begin.param is {}",reqBO);
45 Integer uid = reqBO.getUid(); 46 Integer uid = reqBO.getUid();
  47 + JSONArray result = getInboxTypeInfo(uid);
  48 + //添加新用户引导消息
  49 + addNewUserGuideMessage(uid);
  50 + return result;
  51 + }
  52 +
  53 + private JSONArray getInboxTypeInfo(int uid){
46 //优先从缓存查 54 //优先从缓存查
47 JSONArray result = getInboxTypeInfoByRedis(uid); 55 JSONArray result = getInboxTypeInfoByRedis(uid);
48 if(result != null){ 56 if(result != null){
@@ -61,8 +69,6 @@ public class InBoxServiceImpl implements IInBoxService { @@ -61,8 +69,6 @@ public class InBoxServiceImpl implements IInBoxService {
61 } 69 }
62 //查询结果存入缓存 70 //查询结果存入缓存
63 setInboxTypeInfoByRedis(uid,result); 71 setInboxTypeInfoByRedis(uid,result);
64 - //添加新用户引导消息  
65 - addNewUserGuideMessage(uid);  
66 return result; 72 return result;
67 } 73 }
68 74
@@ -209,6 +215,36 @@ public class InBoxServiceImpl implements IInBoxService { @@ -209,6 +215,36 @@ public class InBoxServiceImpl implements IInBoxService {
209 deleteIboxsByRedis(uid,type); 215 deleteIboxsByRedis(uid,type);
210 } 216 }
211 217
  218 + @Override
  219 + public JSONObject getTotalUnread(int uid) {
  220 + JSONObject result = new JSONObject();
  221 + //查询最新一条未读消息
  222 + ListInboxReqVO vo = new ListInboxReqVO();
  223 + vo.setUid(uid);
  224 + vo.setPage(1);
  225 + vo.setLimit(1);
  226 + PageResponseVO<InBox> inBoxVo = listInboxByTypes(vo);
  227 + if(inBoxVo != null && !CollectionUtils.isEmpty(inBoxVo.getList())){
  228 + result.put("lastMessage",inBoxVo.getList().get(0).getContent());
  229 + }
  230 + //查询未读消息总数
  231 + JSONArray inboxTypeInfo = getInboxTypeInfo(uid);
  232 + if(CollectionUtils.isEmpty(inboxTypeInfo)){
  233 + result.put("count",0);
  234 + }else{
  235 + int total=0;
  236 + for(Object obj : inboxTypeInfo){
  237 + JSONObject jsonObject = (JSONObject)obj;
  238 + Integer count = (Integer)jsonObject.get("unReadCount");
  239 + if(count != null){
  240 + total +=count;
  241 + }
  242 + }
  243 + result.put("count",total);
  244 + }
  245 + return result;
  246 + }
  247 +
212 private void deleteIboxsByRedis(int uid,int type){ 248 private void deleteIboxsByRedis(int uid,int type){
213 log.info("deleteIboxsByRedis params uid is {} type is {}",uid,type); 249 log.info("deleteIboxsByRedis params uid is {} type is {}",uid,type);
214 RedisKeyBuilder inboxKey = CacheEnum.USERS_INBOX_LIST.generateKey(uid); 250 RedisKeyBuilder inboxKey = CacheEnum.USERS_INBOX_LIST.generateKey(uid);