Authored by csgyoho

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

package com.yohoufo.user.controller.inbox;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.ApiResponse;
... ... @@ -39,7 +40,7 @@ public class InBoxController {
logger.info("enter listInboxTypeInfo param is {}", reqBO);
// (1)判断用户id是否存在
if (null == reqBO || reqBO.getUid() < 1) {
logger.warn("Uid is null or 0.");
logger.warn("listInboxTypeInfo:Uid is null or 0.");
throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
}
JSONArray allTabs = inBoxService.listInboxTypeInfo(reqBO);
... ... @@ -47,6 +48,22 @@ public class InBoxController {
}
/**
* 获取未读消息总数和最新一条未读记录
* @param reqBO
*/
@RequestMapping(params = "method=ufo.users.getTotalUnread")
public ApiResponse getTotalUnread(ListInboxTypeInfoReqVO reqBO){
logger.info("enter getTotalUnread param is {}", reqBO);
// (1)判断用户id是否存在
if (null == reqBO || reqBO.getUid() < 1) {
logger.warn("getTotalUnread:Uid is null or 0.");
throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
}
JSONObject result = inBoxService.getTotalUnread(reqBO.getUid());
return new ApiResponse(200,"操作成功",result);
}
/**
* 查询消息列表
* @param reqVO
* reqVO.type 为 null,查询最新消息;
... ...
... ... @@ -14,7 +14,7 @@ public class PageReqVO extends BaseVO{
}
public void setLimit(int limit) {
this.limit = limit<10 ? 10 : limit;
this.limit = limit;
}
public int getPage() {
... ...
package com.yohoufo.user.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yohoufo.dal.user.model.InBox;
import com.yohoufo.user.requestVO.ListInboxReqVO;
import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
... ... @@ -20,4 +21,6 @@ public interface IInBoxService {
PageResponseVO<InBox> listInboxByTypes(ListInboxReqVO reqVO);
void addInbox(int uid, Integer type, Integer businessType, String params);
JSONObject getTotalUnread(int uid);
}
... ...
... ... @@ -18,6 +18,7 @@ import com.yohoufo.user.requestVO.ListInboxReqVO;
import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yohoufo.user.responseVO.PageResponseVO;
import com.yohoufo.user.service.IInBoxService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -43,6 +44,13 @@ public class InBoxServiceImpl implements IInBoxService {
public JSONArray listInboxTypeInfo(ListInboxTypeInfoReqVO reqBO) {
log.info("listInboxTypeInfo begin.param is {}",reqBO);
Integer uid = reqBO.getUid();
JSONArray result = getInboxTypeInfo(uid);
//添加新用户引导消息
addNewUserGuideMessage(uid);
return result;
}
private JSONArray getInboxTypeInfo(int uid){
//优先从缓存查
JSONArray result = getInboxTypeInfoByRedis(uid);
if(result != null){
... ... @@ -61,8 +69,6 @@ public class InBoxServiceImpl implements IInBoxService {
}
//查询结果存入缓存
setInboxTypeInfoByRedis(uid,result);
//添加新用户引导消息
addNewUserGuideMessage(uid);
return result;
}
... ... @@ -209,6 +215,36 @@ public class InBoxServiceImpl implements IInBoxService {
deleteIboxsByRedis(uid,type);
}
@Override
public JSONObject getTotalUnread(int uid) {
JSONObject result = new JSONObject();
//查询最新一条未读消息
ListInboxReqVO vo = new ListInboxReqVO();
vo.setUid(uid);
vo.setPage(1);
vo.setLimit(1);
PageResponseVO<InBox> inBoxVo = listInboxByTypes(vo);
if(inBoxVo != null && !CollectionUtils.isEmpty(inBoxVo.getList())){
result.put("lastMessage",inBoxVo.getList().get(0).getContent());
}
//查询未读消息总数
JSONArray inboxTypeInfo = getInboxTypeInfo(uid);
if(CollectionUtils.isEmpty(inboxTypeInfo)){
result.put("count",0);
}else{
int total=0;
for(Object obj : inboxTypeInfo){
JSONObject jsonObject = (JSONObject)obj;
Integer count = (Integer)jsonObject.get("unReadCount");
if(count != null){
total +=count;
}
}
result.put("count",total);
}
return result;
}
private void deleteIboxsByRedis(int uid,int type){
log.info("deleteIboxsByRedis params uid is {} type is {}",uid,type);
RedisKeyBuilder inboxKey = CacheEnum.USERS_INBOX_LIST.generateKey(uid);
... ...