InBoxController.java 3.02 KB
package com.yohoufo.user.controller.inbox;

import com.alibaba.fastjson.JSONArray;
import com.yoho.core.common.restbean.ResponseBean;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.user.dal.model.InBox;
import com.yohoufo.user.requestVO.InboxReqVO;
import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yohoufo.user.requestVO.ListNewInboxReqVO;
import com.yohoufo.user.responseVO.PageResponseVO;
import com.yohoufo.user.service.IInBoxService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by shengguo.cai on 2018/9/11.
 */
@RestController
@RequestMapping("/inbox")
public class InBoxController {

    private static Logger logger = LoggerFactory.getLogger(InBoxController.class);

    @Resource
    private IInBoxService inBoxService;

    /**
     * 查询消息类型以及每个类型下的未读消息
     * @param reqBO
     */
    @RequestMapping("/listInboxTypeInfo")
    public ResponseBean listInboxTypeInfo(@RequestBody ListInboxTypeInfoReqVO reqBO){
        logger.info("enter listInboxTypeInfo param is {}", reqBO);
        // (1)判断用户id是否存在
        if (null == reqBO || reqBO.getUid() < 1) {
            logger.warn("Uid is null or 0.");
            throw new ServiceException(ServiceError.SMS_INBOX_UID_NULL);
        }
        JSONArray allTabs = inBoxService.listInboxTypeInfo(reqBO);
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode("200");
        responseBean.setData(allTabs);
        responseBean.setMessage("listInboxTypeInfo success");
        return responseBean;
    }

    /**
     * 查看某个消息类型下的未读消息列表
     * @param reqVO
     * reqVO.type 为 null,查询最新未读消息;
     * reqVO.type 不为null,根据type查询未读消息
     * @return
     */
    @RequestMapping("/listNewInboxs")
    public ResponseBean listNewInboxs(@RequestBody ListNewInboxReqVO reqVO){
        logger.info("enter listNewInboxByTypes param is {}", reqVO);
        ResponseBean responseBean = new ResponseBean();
        PageResponseVO<InBox> pageList = inBoxService.listNewInboxByTypes(reqVO);
        responseBean.setCode("200");
        responseBean.setMessage("success");
        responseBean.setData(pageList);
        logger.info("listNewInboxByTypes success with param is {}, count is {}", reqVO, pageList.getTotal());
        return responseBean;
    }

    /**
     * 新增消息
     */
    @RequestMapping("/addInbox")
    public ResponseBean addInbox(@RequestBody InboxReqVO reqVO){
        logger.info("addInbox with param is {}", reqVO);
        inBoxService.addInbox(reqVO);
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode("200");
        responseBean.setMessage("保存成功");
        return responseBean;
    }
}