InBoxServiceImpl.java
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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.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.List;
import java.util.Map;
/**
* Created by shengguo.cai on 2018/9/11.
*/
@Service
public class InBoxServiceImpl implements IInBoxService {
private static Logger log = LoggerFactory.getLogger(InBoxServiceImpl.class);
@Autowired
private InBoxMapper inBoxMapper;
@Override
public JSONArray listInboxTypeInfo(ListInboxTypeInfoReqVO reqBO) {
log.info("listInboxTypeInfo begin.param is {}",reqBO);
Integer uid = reqBO.getUid();
Map<Integer,TypeCountInbox> typeCountMap = inBoxMapper.selectTypeCount(getTableName(uid), uid, "N", "N");
JSONArray result = new JSONArray();
for(InboxTypeEnum typeEnum : InboxTypeEnum.values()) {
JSONObject obj = new JSONObject();
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);
}
return result;
}
@Override
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<InBox> response = new PageResponseVO<>();
int total = inBoxMapper.selectTotalNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
reqVO.getUid());
if(total == 0){
log.info("listNewInboxByTypes query inbox is empty with param is {}", reqVO);
response.setPage(reqVO.getPage());
response.setTotal(0);
return response;
}
List<InBox> inBoxes = inBoxMapper.selectNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
reqVO.getUid(),reqVO.getRowNo(),reqVO.getLimit());
response.setList(inBoxes);
response.setPage(reqVO.getPage());
response.setSize(reqVO.getLimit());
response.setTotal(total);
return response;
}
@Override
public void addInbox(InboxReqVO reqVO) {
InBox inBox = new InBox();
inBox.setUid(reqVO.getUid());
inBox.setType(reqVO.getBusinessType());
inBox.setIsRead("N");
inBox.setIsDel("N");
inBox.setTitle(reqVO.getTitle());
inBox.setCreateTime(DateUtil.getCurrentTimeSecond());
inBox.setContent(reqVO.getContent());
inBox.setVerifyKey(reqVO.getVerifyKey());
inBox.setBusinessType(reqVO.getBusinessType());
inBoxMapper.insertInbox(getTableName(inBox.getUid()),inBox);
}
@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);
}
inBoxMapper.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
}
private String getTableName(Integer uid) {
return "inbox_" + uid % 10;
}
}