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.ZsColumnVo;
import com.ruoyi.system.domain.bo.ZsColumnBo;
import com.ruoyi.system.service.IZsColumnService;

/**
 * 站点栏目管理
 *
 * @author ruoyi
 * @date 2025-04-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/column")
public class ZsColumnController extends BaseController {

    private final IZsColumnService iZsColumnService;

    /**
     * 查询站点栏目管理列表
     */
    @SaCheckPermission("system:column:list")
    @GetMapping("/list")
    public R<List<ZsColumnVo>> list(ZsColumnBo bo) {
        List<ZsColumnVo> list = iZsColumnService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出站点栏目管理列表
     */
    @SaCheckPermission("system:column:export")
    @Log(title = "站点栏目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZsColumnBo bo, HttpServletResponse response) {
        List<ZsColumnVo> list = iZsColumnService.queryList(bo);
        ExcelUtil.exportExcel(list, "站点栏目管理", ZsColumnVo.class, response);
    }

    /**
     * 获取站点栏目管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:column:query")
    @GetMapping("/{id}")
    public R<ZsColumnVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iZsColumnService.queryById(id));
    }

    /**
     * 新增站点栏目管理
     */
    @SaCheckPermission("system:column:add")
    @Log(title = "站点栏目管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZsColumnBo bo) {
        return toAjax(iZsColumnService.insertByBo(bo));
    }

    /**
     * 修改站点栏目管理
     */
    @SaCheckPermission("system:column:edit")
    @Log(title = "站点栏目管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZsColumnBo bo) {
        return toAjax(iZsColumnService.updateByBo(bo));
    }

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