package com.qxueyou.scc.controller;
|
|
import java.util.List;
|
import java.util.Map;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import com.alibaba.druid.util.StringUtils;
|
import com.qxueyou.scc.base.model.Pager;
|
import com.qxueyou.scc.base.model.Result;
|
import com.qxueyou.scc.base.util.CollectionUtils;
|
import com.qxueyou.scc.base.util.QBeanUtils;
|
import com.qxueyou.scc.msg.model.MsgInfo;
|
import com.qxueyou.scc.msg.service.IMsgInfoService;
|
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
|
@Api(tags="消息管理接口")
|
@Controller
|
@CrossOrigin(origins="*",maxAge=3600)
|
@RequestMapping(value = "/msg/msg/")
|
public class MsgInfoController {
|
|
// 分页查询中,默认记录条数和页数
|
private static final int DEFAULT_PAGE_SIZE = 10;
|
private static final int DEFAULT_PAGE_NUM = 1;
|
|
@Autowired
|
IMsgInfoService msgInfoService;
|
|
/**
|
* 消息列表
|
*/
|
@ApiOperation(value = "获取消息列表")
|
@RequestMapping(value = "list", method = RequestMethod.GET)
|
public @ResponseBody Result list(Short type,Integer pageSize,Integer pageNum) {
|
pageSize = pageSize != null && pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE;
|
pageNum = pageNum != null && pageNum > 0 ? pageNum : DEFAULT_PAGE_NUM;
|
|
//消息数量
|
int totalCount = msgInfoService.listCount(type);
|
Pager pager = new Pager(pageSize,pageNum);
|
pager.setTotalCount(totalCount);
|
|
List<MsgInfo> list = msgInfoService.list(type,pageSize,pageNum);
|
|
List<Map<String, Object>> listResult =QBeanUtils.listBean2ListMap(list,
|
CollectionUtils.newStringMap("msgId", "msgId", "type", "type", "content", "content",
|
"readFlag","readFlag","createTime", "createTime"));
|
|
return new Result(true,"",CollectionUtils.newObjectMap("msgList",listResult,"page",pager));
|
}
|
|
/**
|
* 删除消息
|
* @param msgIds
|
* @return
|
*/
|
@ApiOperation(value = "删除消息")
|
@RequestMapping(value = "delete", method = RequestMethod.GET)
|
public @ResponseBody Result deleteUserMsg(String msgIds){
|
if(StringUtils.isEmpty(msgIds)){
|
return new Result(false,"参数错误!");
|
}
|
|
return this.msgInfoService.deleteUserMsg(msgIds.split(","));
|
}
|
|
/**
|
* 清空个人消息
|
*
|
* @return
|
*/
|
@ApiOperation(value = "清空消息")
|
@RequestMapping(value = "clear", method = RequestMethod.GET)
|
public @ResponseBody Result deleteAllUserMsg(Short type){
|
return this.msgInfoService.deleteAllUserMsg(type);
|
}
|
|
/**
|
* 修改已读标志位
|
* @param msgId
|
* @return
|
*/
|
@ApiOperation(value = "更新为已读")
|
@RequestMapping(value = "read", method = RequestMethod.GET)
|
public @ResponseBody Result updateReadFlag(String msgIds){
|
return this.msgInfoService.updateReadStatus(msgIds.split(","));
|
}
|
|
/**
|
* 全部已读
|
* @param msgId
|
* @return
|
*/
|
@ApiOperation(value = "全部更新为已读")
|
@RequestMapping(value = "readall", method = RequestMethod.GET)
|
public @ResponseBody Result updateAllUserReadFlag(Short type){
|
return this.msgInfoService.updateUserAllReadStatus(type);
|
}
|
|
|
/**
|
* 最近的提醒消息
|
* @param msgId
|
* @return
|
*/
|
@ApiOperation(value = "最近的一条提醒信息")
|
@RequestMapping(value = "last", method = RequestMethod.GET)
|
public @ResponseBody Result getLatest(){
|
return new Result(true,"",this.msgInfoService.readLastRemindMsg());
|
}
|
|
|
/**
|
* 最近的提醒消息
|
* @param msgId
|
* @return
|
*/
|
@ApiOperation(value = "按类型获取未读消息的数量")
|
@RequestMapping(value = "count", method = RequestMethod.GET)
|
public @ResponseBody Result queryUnReadMsgCountByType(){
|
return new Result(true,"",this.msgInfoService.queryUnReadMsgCountByType());
|
}
|
|
/**
|
* 查询未读消息总数
|
* @param msgId
|
* @return
|
*/
|
@ApiOperation(value = "查询用户未读消息总数")
|
@RequestMapping(value = "totalcount", method = RequestMethod.GET)
|
public @ResponseBody Result queryUnReadTotalCount(){
|
return new Result(true,"",CollectionUtils.newObjectMap("totalCount",this.msgInfoService.queryUnReadTotalCount()));
|
}
|
|
}
|