124 lines
4.2 KiB
Plaintext
124 lines
4.2 KiB
Plaintext
package com.cmeim.system.controller;
|
||
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.cmeim.common.core.exception.ServiceException;
|
||
import com.cmeim.common.core.utils.SecurityUtils;
|
||
import com.cmeim.common.core.web.controller.BaseController;
|
||
import com.cmeim.common.core.web.domain.AjaxResult;
|
||
import com.cmeim.common.core.web.domain.RespondEnum;
|
||
import com.cmeim.common.core.web.page.PageVo;
|
||
import com.cmeim.system.api.domain.SysMessage;
|
||
import com.cmeim.system.api.domain.SysUser;
|
||
import com.cmeim.system.service.ISysMessageService;
|
||
import io.swagger.annotations.ApiOperation;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
import java.util.stream.Collectors;
|
||
|
||
/**
|
||
* 用户消息
|
||
*
|
||
* @author wangshijie
|
||
*/
|
||
@Slf4j //加个注解用于调试用,方便服务器管理,比system.out好控制,用法:log.日志级别("str",object)
|
||
@RestController
|
||
@RequestMapping("message")
|
||
public class SysMessageController extends BaseController {
|
||
|
||
@Autowired
|
||
private ISysMessageService messageService;
|
||
|
||
//全部查询,系统首页显示,根据当前登录用户,只看当前用户的消息,未读在前,已读在后,有条件查询功能.
|
||
@ApiOperation(value = "list")
|
||
@GetMapping("/list")
|
||
public AjaxResult list(PageVo pageVo, SysMessage sysMessage){
|
||
startPage();
|
||
logger.info("---->"+ JSON.toJSON(SecurityUtils.getUserId()));
|
||
logger.info(JSON.toJSONString(sysMessage));
|
||
List<SysMessage> AllMsg = messageService.selectAllData(pageVo,sysMessage);
|
||
pageVo.setRecordsTotal(AllMsg.size());//数据总量;
|
||
pageVo.setData(AllMsg);
|
||
return AjaxResult.success("操作成功",pageVo);
|
||
}
|
||
|
||
//删除接口byid
|
||
/**
|
||
* 删除数据
|
||
*
|
||
*/
|
||
@ApiOperation(value = "delete")
|
||
@DeleteMapping("/delete")
|
||
public long delete(Long id)
|
||
{
|
||
return messageService.deleteMsgById(id);
|
||
}
|
||
|
||
/**
|
||
* 新增用户消息,后台API
|
||
*
|
||
*/
|
||
@ApiOperation(value = "add")
|
||
@PostMapping("/add")
|
||
public AjaxResult add(@RequestBody SysMessage sysMessage)
|
||
{
|
||
if(sysMessage.getCode()==null || sysMessage.getCode()==""){
|
||
ServiceException exception = new ServiceException(RespondEnum.FAILURE);
|
||
exception.setErrorMessage("无代码信息,不能发送消息");
|
||
throw exception;
|
||
}
|
||
List<String> userIdList = messageService.selectUserIdListByCode(sysMessage.getCode());
|
||
userIdList = userIdList.stream().distinct().collect(Collectors.toList());
|
||
for (int i = 0; i < userIdList.size(); i++) {
|
||
sysMessage.setReceiver(Long.parseLong(userIdList.get(i)));
|
||
messageService.add(sysMessage);
|
||
}
|
||
return AjaxResult.success("操作成功");
|
||
}
|
||
|
||
|
||
@ApiOperation(value = "根据code查询 userList")
|
||
@GetMapping("/selectUserListByCode")
|
||
public AjaxResult selectUserListByCode(String code){
|
||
List<SysUser> userIdList = messageService.selectUserListByCode(code);
|
||
return AjaxResult.success(userIdList);
|
||
}
|
||
|
||
|
||
|
||
|
||
/**
|
||
* 修改数据byStatus
|
||
* @return 修改消息状态
|
||
*/
|
||
@ApiOperation(value = "修改状态")
|
||
@GetMapping("/updateSysStatus")
|
||
public AjaxResult updateSysStatus(SysMessage sysMessage)
|
||
{
|
||
return toAjax(messageService.updateSysStatus(sysMessage));
|
||
}
|
||
|
||
/**
|
||
* 查询数据by分页
|
||
* @return page
|
||
*/
|
||
//全部查询,系统首页显示,更具当前登录用户,只看当前用户的消息,未读在前,已读在后,有条件查询功能
|
||
@ApiOperation(value = "查询所有数据,有分页")
|
||
@GetMapping("/queryMsgByPage")
|
||
public AjaxResult queryMsgByPage(PageVo pageVo,SysMessage sysMessage){
|
||
// PageHelper.startPage(sysMessage);
|
||
// startPage();
|
||
List<SysMessage> AllMsgByPage = messageService.queryMsgByPage(pageVo,sysMessage);
|
||
// pageVo.setRecordsTotal(AllMsgByPage.size());//数据总量;
|
||
pageVo.setData(AllMsgByPage);
|
||
log.debug("这是debug",AllMsgByPage);
|
||
// System.out.println(AllMsgByPage);
|
||
//dialect.getCountString(sql)
|
||
return AjaxResult.success("操作成功",pageVo);
|
||
}
|
||
|
||
}
|