InBoxController.java 2.91 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.dal.user.model.InBox;
import com.yohoufo.user.requestVO.InboxReqVO;
import com.yohoufo.user.requestVO.ListInboxTypeInfoReqVO;
import com.yohoufo.user.requestVO.ListInboxReqVO;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by shengguo.cai on 2018/9/11.
 */
@RestController
public class InBoxController {

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

    @Resource
    private IInBoxService inBoxService;

    /**
     * 查询消息类型以及每个类型下的未读消息
     * @param reqBO
     */
    @RequestMapping(params = "method=ufo.users.listInboxTypeInfo")
    public ResponseBean listInboxTypeInfo(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(params = "method=ufo.users.listInboxs")
    public ResponseBean listInboxs(ListInboxReqVO reqVO){
        logger.info("enter listInboxByTypes param is {}", reqVO);
        ResponseBean responseBean = new ResponseBean();
        PageResponseVO<InBox> pageList = inBoxService.listInboxByTypes(reqVO);
        responseBean.setCode("200");
        responseBean.setMessage("success");
        responseBean.setData(pageList);
        logger.info("listInboxByTypes success with param is {}, count is {}", reqVO, pageList.getTotal());
        return responseBean;
    }

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