package com.yonge.cooleshow.teacher.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonge.cooleshow.biz.dal.dao.ImGroupNoticeDao;
import com.yonge.cooleshow.biz.dal.dto.ImGroupNoticeDto;
import com.yonge.cooleshow.biz.dal.entity.ImGroupNotice;
import com.yonge.cooleshow.biz.dal.service.ImGroupNoticeService;
import com.yonge.cooleshow.biz.dal.support.PageUtil;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.mybatis.page.PageInfo;
import com.yonge.toolset.utils.validator.ValidationKit;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * 群公告(ImGroupNotice)表控制层
 *
 * @author zx
 * @since 2022-03-22 10:45:58
 */
@Api(tags = "群公告")
@RestController
@RequestMapping("/imGroupNotice")
public class ImGroupNoticeController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ImGroupNoticeService imGroupNoticeService;

    @ApiOperation("新增群公告")
    @PostMapping(value = "/create")
    public HttpResponseResult<Boolean> create(@Valid @RequestBody ImGroupNotice imGroupNotice, BindingResult bindingResult){
        ValidationKit.ignoreFields(bindingResult,"id");
        imGroupNoticeService.create(imGroupNotice);
        return succeed();
    }

    @ApiOperation("删除群公告")
    @PostMapping(value = "/del/{noticeId}")
    public HttpResponseResult<Boolean> del(@ApiParam(value = "群公告编号", required = true) @PathVariable("noticeId") Long noticeId){
        imGroupNoticeService.del(noticeId);
        return succeed();
    }

    @ApiOperation("修改群公告")
    @PostMapping(value = "/update")
    public HttpResponseResult<Boolean> modify(@Valid @RequestBody ImGroupNotice imGroupNotice){
        imGroupNoticeService.modify(imGroupNotice);
        return succeed();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", dataType = "Long", value = "群编号",required = true)
    })
    @ApiOperation("分页查询")
    @PostMapping(value = "/queryPage")
    public HttpResponseResult<PageInfo<ImGroupNoticeDto>> queryPage(@RequestBody Map<String,Object> params) throws Exception {
        return succeed(imGroupNoticeService.queryPage(params));
    }
}

