|
|
package com.yoho.ufo.user.service.impl;
|
|
|
package com.yohoufo.user.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.ufo.user.dal.inbox.InBoxMapper;
|
|
|
import com.yoho.ufo.user.dal.inbox.enums.InboxTypeEnum;
|
|
|
import com.yoho.ufo.user.dal.inbox.model.InBox;
|
|
|
import com.yoho.ufo.user.dal.inbox.model.TypeCountInbox;
|
|
|
import com.yoho.ufo.user.requestVO.InboxReqVO;
|
|
|
import com.yoho.ufo.user.requestVO.ListInboxTypeInfoReqVO;
|
|
|
import com.yoho.ufo.user.requestVO.ListNewInboxReqVO;
|
|
|
import com.yoho.ufo.user.responseVO.InboxDetailRespVO;
|
|
|
import com.yoho.ufo.user.responseVO.PageResponseVO;
|
|
|
import com.yoho.ufo.user.service.IInBoxService;
|
|
|
import com.yohoufo.user.dal.InBoxMapper;
|
|
|
import com.yohoufo.user.dal.enums.InboxTypeEnum;
|
|
|
import com.yohoufo.user.dal.model.InBox;
|
|
|
import com.yohoufo.user.dal.model.TypeCountInbox;
|
|
|
import com.yohoufo.user.requestVO.InboxReqVO;
|
|
|
import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
|
|
|
import com.yohoufo.user.requestVO.ListNewInboxReqVO;
|
|
|
import com.yohoufo.user.requestVO.UpdateReadedReqVO;
|
|
|
import com.yohoufo.user.responseVO.PageResponseVO;
|
|
|
import com.yohoufo.user.service.IInBoxService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
...
|
...
|
@@ -42,8 +40,8 @@ public class InBoxServiceImpl implements IInBoxService { |
|
|
JSONArray result = new JSONArray();
|
|
|
for(InboxTypeEnum typeEnum : InboxTypeEnum.values()) {
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("id", typeEnum.getId());
|
|
|
obj.put("img_url", typeEnum.getImgUrl());
|
|
|
obj.put("type", typeEnum.getId());
|
|
|
obj.put("imgUrl", typeEnum.getImgUrl());
|
|
|
obj.put("description", typeEnum.getDescription());
|
|
|
obj.put("unReadCount", typeCountMap.containsKey(typeEnum.getId()) ? typeCountMap.get(typeEnum.getId()) : 0);
|
|
|
result.add(obj);
|
...
|
...
|
@@ -52,14 +50,14 @@ public class InBoxServiceImpl implements IInBoxService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageResponseVO<InboxDetailRespVO> listNewInboxByTypes(ListNewInboxReqVO reqVO) {
|
|
|
public PageResponseVO<InBox> listNewInboxByTypes(ListNewInboxReqVO reqVO) {
|
|
|
log.info("entre listNewInboxByTypes with param is {}", reqVO);
|
|
|
//判断为空
|
|
|
if (reqVO.getUid() <= 0) {
|
|
|
log.warn("listNewInboxByTypes error because uid is null with param is {}", reqVO);
|
|
|
throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
|
|
|
}
|
|
|
PageResponseVO<InboxDetailRespVO> response = new PageResponseVO<>();
|
|
|
PageResponseVO<InBox> response = new PageResponseVO<>();
|
|
|
|
|
|
int total = inBoxMapper.selectTotalNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
|
|
|
reqVO.getUid());
|
...
|
...
|
@@ -69,15 +67,10 @@ public class InBoxServiceImpl implements IInBoxService { |
|
|
response.setTotal(0);
|
|
|
return response;
|
|
|
}
|
|
|
List<InBox> list = inBoxMapper.selectNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
|
|
|
List<InBox> inBoxes = inBoxMapper.selectNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
|
|
|
reqVO.getUid(),reqVO.getRowNo(),reqVO.getLimit());
|
|
|
List<InboxDetailRespVO> inboxDetailRespVOList = initInboxDetails(list);
|
|
|
// 将当前分类下用户所有的未读消息置为已读
|
|
|
if(null!=reqVO.getType()){
|
|
|
inBoxMapper.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
|
|
|
}
|
|
|
|
|
|
response.setList(inboxDetailRespVOList);
|
|
|
response.setList(inBoxes);
|
|
|
response.setPage(reqVO.getPage());
|
|
|
response.setSize(reqVO.getLimit());
|
|
|
response.setTotal(total);
|
...
|
...
|
@@ -88,8 +81,7 @@ public class InBoxServiceImpl implements IInBoxService { |
|
|
public void addInbox(InboxReqVO reqVO) {
|
|
|
InBox inBox = new InBox();
|
|
|
inBox.setUid(reqVO.getUid());
|
|
|
inBox.setSendUid(reqVO.getSendUid());
|
|
|
inBox.setType(reqVO.getBusinessType() / 100);
|
|
|
inBox.setType(reqVO.getBusinessType());
|
|
|
inBox.setIsRead("N");
|
|
|
inBox.setIsDel("N");
|
|
|
inBox.setTitle(reqVO.getTitle());
|
...
|
...
|
@@ -100,50 +92,13 @@ public class InBoxServiceImpl implements IInBoxService { |
|
|
inBoxMapper.insertInbox(getTableName(inBox.getUid()),inBox);
|
|
|
}
|
|
|
|
|
|
private List<InboxDetailRespVO> initInboxDetails(List<InBox> inBoxList){
|
|
|
List<InboxDetailRespVO> inboxDetailRespVOList = new ArrayList<>();
|
|
|
InboxDetailRespVO resp = null;
|
|
|
String date = "";
|
|
|
//取当天的年月日的时间毫秒数
|
|
|
long now = DateUtil.stringToDate(DateUtil.long2DateStr(new Date().getTime(), DateUtil.DATE_FORMAT), DateUtil.DATE_FORMAT).getTime();
|
|
|
String lastDate = DateUtil.dateAdd(DateUtil.getcurrentDate(), "d", -1, DateUtil.DATE_FORMAT);
|
|
|
for (InBox box : inBoxList) {
|
|
|
// 校验消息业务类型
|
|
|
if (box.getBusinessType() == null) {
|
|
|
log.warn("initInboxDetails inbox BusinessType is null. with box={}", box);
|
|
|
continue;
|
|
|
}
|
|
|
date = DateUtil.long2DateStr((long) box.getCreateTime() * 1000, DateUtil.DATE_TIME_FORMAT);
|
|
|
if (box.getCreateTime() * 1000 >= now) {
|
|
|
date = "今天" + DateUtil.dateToString(DateUtil.long2Date(box.getCreateTime() * 1000), "HH:mm");
|
|
|
} else if (box.getCreateTime() * 1000 > DateUtil.stringToDate(lastDate, DateUtil.DATE_FORMAT).getTime()) {
|
|
|
date = "昨天" + DateUtil.dateToString(DateUtil.long2Date(box.getCreateTime() * 1000), "HH:mm");
|
|
|
}
|
|
|
resp = new InboxDetailRespVO();
|
|
|
resp.setContent(box.getContent());
|
|
|
resp.setId(box.getId());
|
|
|
resp.setUid(box.getUid());
|
|
|
resp.setTitle(box.getTitle());
|
|
|
resp.setBusinessType(box.getBusinessType());
|
|
|
if (box.getBusinessType() != null && box.getBusinessType() > 0) {
|
|
|
// final String beanName = InboxBusinessTypeEnum.getBeanNameByBusinessType(box.getBusinessType());
|
|
|
// IInBoxBusinessService service = SpringContextUtil.getBean(beanName, IInBoxBusinessService.class);
|
|
|
// Map<String, Object> map = service.getMessage(box);
|
|
|
// String imgUrl = BusinessTypeEnum.getImgUrlByBusinessType(box.getBusinessType());
|
|
|
// resp.setBody(map);
|
|
|
} else {
|
|
|
continue;
|
|
|
}
|
|
|
// Map<String, String> urlMap = InboxJumpUrlHelper.getJumpUrl(box, resp.getBody());
|
|
|
// resp.setPcLink(StringUtils.isNotEmpty(urlMap.get("pc_link")) ? urlMap.get("pc_link") : "");
|
|
|
// resp.setAppLink(StringUtils.isNotEmpty(urlMap.get("app_link")) ? urlMap.get("app_link") : "");
|
|
|
resp.setIs_read(box.getIsRead());
|
|
|
resp.setCreate_time(box.getCreateTime());
|
|
|
resp.setCreate_date(date);
|
|
|
resp.setType(String.valueOf(box.getType()));
|
|
|
inboxDetailRespVOList.add(resp);
|
|
|
@Override
|
|
|
public void updateReadedByType(UpdateReadedReqVO reqVO) {
|
|
|
if (reqVO.getUid() < 1) {
|
|
|
log.warn("updateReadedByType error because uid is null with param is {}", reqVO);
|
|
|
throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
|
|
|
}
|
|
|
return inboxDetailRespVOList;
|
|
|
inBoxMapper.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
|
|
|
}
|
|
|
|
|
|
private String getTableName(Integer uid) {
|
...
|
...
|
|