SysNoticeController.java 3.08 KB
package com.huaheng.pc.system.notice.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.system.notice.domain.SysNotice;
import com.huaheng.pc.system.notice.service.SysNoticeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;

@Controller
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {
    @Resource
    private SysNoticeService sysNoticeService;

    private String prefix = "system/notice";

    @GetMapping("/mailbox")
    public String mailbox(ModelMap mmap){
        mmap.put("user",ShiroUtils.getUser());
        return prefix+"/mailbox";
    }

    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(String status) {
        LambdaQueryWrapper<SysNotice> lambdaQueryWrapper = Wrappers.lambdaQuery();
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(status), SysNotice::getStatus, status)
                            .orderByAsc(SysNotice::getStatus);
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            Page<SysNotice> page = new Page(pageNum, pageSize);
            IPage<SysNotice> iPage = sysNoticeService.page(page, lambdaQueryWrapper);
            return getMpDataTable(iPage.getRecords(), iPage.getTotal());
        } else {
            return getDataTable(sysNoticeService.list(lambdaQueryWrapper));
        }
    }

    /**
     * 将所有消息已读
     * @return
     */
    @GetMapping("/readAll")
    @ResponseBody
    public AjaxResult readAll(){
        if (sysNoticeService.readAll()){
            return AjaxResult.success();
        }else {
            return AjaxResult.error("消息记录状态修改失败");
        }
    }

    @GetMapping("/readOne")
    @ResponseBody
    public AjaxResult readOne(@RequestParam String id){
        if (sysNoticeService.readOne(id)){
            return AjaxResult.success();
        }else {
            return AjaxResult.error("id为"+id+"消息记录状态修改失败");
        }
    }
}