package com.yccrc.kede.controller.other;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yccrc.common.core.controller.BaseController;
import com.yccrc.common.utils.PageUtils;
import com.yccrc.common.vo.Result;
import com.yccrc.system.domain.SysNotice;
import com.yccrc.system.service.ISysNoticeService;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags = "消息管理")
@RestController
@RequestMapping("/notice")
public class NoticeController extends BaseController
{
    @Autowired
    private ISysNoticeService noticeService;

    @ApiOperation(value = "消息列表")
    @GetMapping("/list")
    public Result<Page<SysNotice>> list(SysNotice notice)
    {
    	Page<SysNotice> data  = noticeService.page(PageUtils.initPage(), new QueryWrapper<SysNotice>()
    			.eq("user_id", super.getUserId())
    			.like(!StrUtil.isEmpty(notice.getNoticeContent()), "notice_content", notice.getNoticeContent()).orderByDesc("notice_id"));
        return new Result<Page<SysNotice>>().ok(data);
    }

   
    @ApiOperation(value = "消息详情")
    @GetMapping(value = "/{noticeId}")
    public  Result<SysNotice> getInfo(@PathVariable Long noticeId)
    {
    	noticeService.lambdaUpdate().set(SysNotice::getStatus, "1").eq(SysNotice::getNoticeId, noticeId).update();
    	 return new Result<SysNotice>().ok(noticeService.getById(noticeId));
    }

   
}
