package com.goldenwater.slgc.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.slgc.domain.CmsArticle;
import com.goldenwater.slgc.service.CmsArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "13. 内容文章管理")
@RestController
@RequestMapping("/slgc/cms-article")
public class CmsArticleController extends BaseController {
    @Autowired
    private CmsArticleService cmsArticleService;

    @Operation(summary = "13.01 查询内容文章列表")
    @GetMapping("/list")
    public TableDataInfo list(CmsArticle cmsArticle) {
        startPage();
        List<CmsArticle> list = cmsArticleService.selectCmsArticleList(cmsArticle);
        return getDataTable(list);
    }

    @Operation(summary = "13.02 获取内容文章详细信息")
    @GetMapping(value = "/{aid}")
    public AjaxResult getInfo(@PathVariable String aid) {
        return success(cmsArticleService.selectCmsArticleById(aid));
    }

    @Operation(summary = "13.03 新增内容文章")
    @Log(title = "内容文章管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsArticle cmsArticle) {
        return toAjax(cmsArticleService.insertCmsArticle(cmsArticle));
    }

    @Operation(summary = "13.04 修改内容文章")
    @Log(title = "内容文章管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsArticle cmsArticle) {
        return toAjax(cmsArticleService.updateCmsArticle(cmsArticle));
    }

    @Operation(summary = "13.05 删除内容文章")
    @Log(title = "内容文章管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{aids}")
    public AjaxResult remove(@PathVariable String[] aids) {
        return toAjax(cmsArticleService.deleteCmsArticleByIds(aids));
    }

    @Operation(summary = "13.06 批量新增内容文章")
    @Log(title = "内容文章管理", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult batchAdd(@RequestBody List<CmsArticle> list) {
        return toAjax(cmsArticleService.batchInsert(list));
    }

    @Operation(summary = "13.07 批量修改内容文章")
    @Log(title = "内容文章管理", businessType = BusinessType.UPDATE)
    @PutMapping("/batch")
    public AjaxResult batchEdit(@RequestBody List<CmsArticle> list) {
        return toAjax(cmsArticleService.batchUpdate(list));
    }

    @Operation(summary = "13.08 批量删除内容文章")
    @Log(title = "内容文章管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/batch/{aids}")
    public AjaxResult batchRemove(@PathVariable String[] aids) {
        return toAjax(cmsArticleService.deleteCmsArticleByIds(aids));
    }

    @Operation(summary = "13.09 获取今日发布文章数")
    @GetMapping("/published/today")
    public AjaxResult getArticlesPublicNum() {
        return success(cmsArticleService.selectTodayPublishedCount());
    }
}
