package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.ZsArticleCategoryVo;
import com.ruoyi.system.domain.bo.ZsArticleCategoryBo;
import com.ruoyi.system.service.IZsArticleCategoryService;

/**
 * 站点文章分类管理
 *
 * @author 网球
 * @date 2025-04-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/articleCategory")
public class ZsArticleCategoryController extends BaseController {

    private final IZsArticleCategoryService iZsArticleCategoryService;

    /**
     * 查询站点文章分类管理列表
     */
    @SaCheckPermission("system:articleCategory:list")
    @GetMapping("/list")
    public R<List<ZsArticleCategoryVo>> list(ZsArticleCategoryBo bo) {
        List<ZsArticleCategoryVo> list = iZsArticleCategoryService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出站点文章分类管理列表
     */
    @SaCheckPermission("system:articleCategory:export")
    @Log(title = "站点文章分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZsArticleCategoryBo bo, HttpServletResponse response) {
        List<ZsArticleCategoryVo> list = iZsArticleCategoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "站点文章分类管理", ZsArticleCategoryVo.class, response);
    }

    /**
     * 获取站点文章分类管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:articleCategory:query")
    @GetMapping("/{id}")
    public R<ZsArticleCategoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iZsArticleCategoryService.queryById(id));
    }

    /**
     * 新增站点文章分类管理
     */
    @SaCheckPermission("system:articleCategory:add")
    @Log(title = "站点文章分类管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZsArticleCategoryBo bo) {
        return toAjax(iZsArticleCategoryService.insertByBo(bo));
    }

    /**
     * 修改站点文章分类管理
     */
    @SaCheckPermission("system:articleCategory:edit")
    @Log(title = "站点文章分类管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZsArticleCategoryBo bo) {
        return toAjax(iZsArticleCategoryService.updateByBo(bo));
    }

    /**
     * 删除站点文章分类管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:articleCategory:remove")
    @Log(title = "站点文章分类管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iZsArticleCategoryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
