...
|
...
|
@@ -5,15 +5,14 @@ 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.InboxBusinessTypeEnum;
|
|
|
import com.yohoufo.user.dal.enums.InboxTypeEnum;
|
|
|
import com.yohoufo.common.enums.InboxBusinessTypeEnum;
|
|
|
import com.yohoufo.common.enums.InboxTypeEnum;
|
|
|
import com.yohoufo.user.dal.IInBoxDao;
|
|
|
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;
|
...
|
...
|
@@ -31,13 +30,13 @@ import java.util.Map; |
|
|
public class InBoxServiceImpl implements IInBoxService {
|
|
|
private static Logger log = LoggerFactory.getLogger(InBoxServiceImpl.class);
|
|
|
@Autowired
|
|
|
private InBoxMapper inBoxMapper;
|
|
|
private IInBoxDao inBoxDao;
|
|
|
|
|
|
@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");
|
|
|
Map<Integer,TypeCountInbox> typeCountMap = inBoxDao.selectTypeCount(getTableName(uid), uid, "N", "N");
|
|
|
JSONArray result = new JSONArray();
|
|
|
for(InboxTypeEnum typeEnum : InboxTypeEnum.values()) {
|
|
|
JSONObject obj = new JSONObject();
|
...
|
...
|
@@ -60,7 +59,7 @@ public class InBoxServiceImpl implements IInBoxService { |
|
|
}
|
|
|
PageResponseVO<InBox> response = new PageResponseVO<>();
|
|
|
|
|
|
int total = inBoxMapper.selectTotalNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
|
|
|
int total = inBoxDao.selectTotalNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
|
|
|
reqVO.getUid());
|
|
|
if(total == 0){
|
|
|
log.info("listNewInboxByTypes query inbox is empty with param is {}", reqVO);
|
...
|
...
|
@@ -68,10 +67,13 @@ public class InBoxServiceImpl implements IInBoxService { |
|
|
response.setTotal(0);
|
|
|
return response;
|
|
|
}
|
|
|
List<InBox> inBoxes = inBoxMapper.selectNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
|
|
|
List<InBox> inBoxes = inBoxDao.selectNewInboxs(getTableName(reqVO.getUid()),reqVO.getType(),
|
|
|
reqVO.getUid(),reqVO.getRowNo(),reqVO.getLimit());
|
|
|
|
|
|
//如果根据类型查看,设置未读为已读
|
|
|
if(null != reqVO.getType()){
|
|
|
inBoxDao.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
|
|
|
response.setList(inBoxes);
|
|
|
}
|
|
|
response.setPage(reqVO.getPage());
|
|
|
response.setSize(reqVO.getLimit());
|
|
|
response.setTotal(total);
|
...
|
...
|
@@ -80,27 +82,30 @@ public class InBoxServiceImpl implements IInBoxService { |
|
|
|
|
|
@Override
|
|
|
public void addInbox(InboxReqVO reqVO) {
|
|
|
InboxBusinessTypeEnum businessTypeEnum = InboxBusinessTypeEnum
|
|
|
InboxBusinessTypeEnum businessTypeEnum = InboxBusinessTypeEnum.getByTypeAndBusinessType(reqVO.getType(),reqVO.getBusinessType());
|
|
|
if(businessTypeEnum == null){
|
|
|
throw new ServiceException(ServiceError.ERROR);//TODO 自定义
|
|
|
}
|
|
|
InBox inBox = new InBox();
|
|
|
inBox.setUid(reqVO.getUid());
|
|
|
inBox.setType(reqVO.getBusinessType());
|
|
|
inBox.setIsRead("N");
|
|
|
inBox.setIsDel("N");
|
|
|
inBox.setTitle(reqVO.getTitle());
|
|
|
inBox.setIsRead(InBox.N);
|
|
|
inBox.setIsDel(InBox.N);
|
|
|
inBox.setTitle(businessTypeEnum.getTitle());
|
|
|
inBox.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
inBox.setContent(reqVO.getContent());
|
|
|
inBox.setVerifyKey(reqVO.getVerifyKey());
|
|
|
inBox.setContent(createContent(businessTypeEnum.getContent(),reqVO.getParams()));
|
|
|
inBox.setBusinessType(reqVO.getBusinessType());
|
|
|
inBoxMapper.insertInbox(getTableName(inBox.getUid()),inBox);
|
|
|
inBoxDao.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);
|
|
|
private String createContent(String template, List<String> params){
|
|
|
if(params==null){
|
|
|
return template;
|
|
|
}
|
|
|
for(String param : params){
|
|
|
template=template.replaceFirst("\\{\\}",param);
|
|
|
}
|
|
|
inBoxMapper.updateReadedByUidAndType(getTableName(reqVO.getUid()),reqVO.getUid(),reqVO.getType(),DateUtil.getCurrentTimeSecond());
|
|
|
return template;
|
|
|
}
|
|
|
|
|
|
private String getTableName(Integer uid) {
|
...
|
...
|
|