package com.bonus.material.notice.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.notice.entity.Notice;
import com.bonus.material.notice.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author：liang.chao
 * @Date：2024/12/20 - 19:12
 */
@RestController
@RequestMapping("/notice")
@Api(value = "消息通知", tags = "消息通知")
@Slf4j
public class NoticeController extends BaseController {

    @Resource
    private NoticeService noticeService;

    @GetMapping("/list")
    @ApiOperation(value = "消息列表（web）")
    public AjaxResult list(Notice notice) {
        startPage();
        List<Notice> sysNotices = noticeService.selectNoticeList(notice);
        return AjaxResult.success(getDataTable(sysNotices));
    }

    /**
     * 新增通知公告
     * @param notice
     * @return
     */
    @PostMapping
    @SysLog(title = "通知公告", businessType = OperaType.INSERT,logType = 0,module = "系统管理->通知公告")
    public AjaxResult add(@Validated @RequestBody Notice notice) {
        try{
            notice.setCreateBy(SecurityUtils.getUsername());
            return noticeService.insertNotice(notice);
        }catch (Exception e){
            log.error(e.toString(),e);
        }
        return error("系统异常");
    }

    /**
     * 修改通知公告
     * @param notice
     * @return
     */
    @PostMapping("/edit")
    @SysLog(title = "通知公告", businessType = OperaType.UPDATE,logType = 0,module = "系统管理->通知公告")
    public AjaxResult edit(@Validated @RequestBody Notice notice) {
        try{
            notice.setUpdateBy(SecurityUtils.getUsername());
            return noticeService.updateNotice(notice);
        }catch (Exception e){
            log.error(e.toString(),e);
        }
        return error("系统异常");

    }

    /**
     * 删除通知公告
     * @param noticeIds
     * @return
     */
    @PostMapping("/delete/{noticeIds}")
    @SysLog(title = "通知公告", businessType = OperaType.DELETE,logType = 0,module = "系统管理->通知公告")
    public AjaxResult remove(@PathVariable Long[] noticeIds) {
        try{
            return noticeService.deleteNoticeByIds(noticeIds);
        }catch (Exception e){
            log.error(e.toString(),e);
        }
        return error("系统异常");

    }

/*    @GetMapping("/noticeList")
    @ApiOperation(value = "系统公告（app）")
    public AjaxResult noticeList(Notice notice) {
        List<Notice> sysNotices = noticeService.noticeList(notice);
        return AjaxResult.success(sysNotices);
    }

    @GetMapping("/messageList")
    @ApiOperation(value = "系统消息（app）")
    public AjaxResult messageList(Notice notice) {
        List<Notice> sysNotices = noticeService.messageList(notice);
        return AjaxResult.success(sysNotices);
    }*/
}
