package cn.iocoder.yudao.module.jx.controller.admin;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.jx.core.controller.BaseController;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolNews;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolNewsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 校内新闻Controller
 *
 * @author ruoyi
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/drivingSchool/system/news")
public class DriveSchoolNewsController extends BaseController
{
    @Autowired
    private IDriveSchoolNewsService driveSchoolNewsService;

    /**
     * 查询校内新闻列表
     */
    @GetMapping("/list")
    public CommonResult<IPage<?>> pclist(DriveSchoolNews driveSchoolNews)
    {
        Page<DriveSchoolNews> page = new Page<>(driveSchoolNews.getPageNum(), driveSchoolNews.getPageSize());
        IPage<DriveSchoolNews> driveSchoolNewsIPage = driveSchoolNewsService.selectDriveSchoolNewsList(driveSchoolNews, page);
        return CommonResult.success(driveSchoolNewsIPage);
        //return getDataTable(list);
    }

    /**
     * 查询校内新闻列表
     */
    @GetMapping("/applist")
    public CommonResult list(DriveSchoolNews driveSchoolNews)
    {
        List<DriveSchoolNews> list = driveSchoolNewsService.selectDriveSchoolNewsListAll(driveSchoolNews);
        return CommonResult.success(list);
    }

    /**
     * 导出校内新闻列表
     */
    //@Log(title = "校内新闻", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, DriveSchoolNews driveSchoolNews)
//    {
//        List<DriveSchoolNews> list = driveSchoolNewsService.selectDriveSchoolNewsList(driveSchoolNews);
//        ExcelUtil<DriveSchoolNews> util = new ExcelUtil<DriveSchoolNews>(DriveSchoolNews.class);
//        util.exportExcel(response, list, "校内新闻数据");
//    }

    /**
     * 获取校内新闻详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(driveSchoolNewsService.selectDriveSchoolNewsById(id));
    }

    /**
     * 新增校内新闻
     */
    //@Log(title = "校内新闻", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody DriveSchoolNews driveSchoolNews)
    {
        return toAjax(driveSchoolNewsService.insertDriveSchoolNews(driveSchoolNews));
    }

    /**
     * 修改校内新闻
     */
    //@Log(title = "校内新闻", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody DriveSchoolNews driveSchoolNews)
    {
        return toAjax(driveSchoolNewsService.updateDriveSchoolNews(driveSchoolNews));
    }

    /**
     * 删除校内新闻
     */
    //@Log(title = "校内新闻", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driveSchoolNewsService.deleteDriveSchoolNewsByIds(ids));
    }
}
