package org.dromara.progress.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.progress.domain.dto.progresscategorytemplate.PgsProgressCategoryTemplateCreateReq;
import org.dromara.progress.domain.dto.progresscategorytemplate.PgsProgressCategoryTemplateQueryReq;
import org.dromara.progress.domain.dto.progresscategorytemplate.PgsProgressCategoryTemplateUpdateReq;
import org.dromara.progress.domain.vo.progresscategorytemplate.PgsProgressCategoryTemplateVo;
import org.dromara.progress.service.IPgsProgressCategoryTemplateService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 进度类别模版
 *
 * @author lcj
 * @date 2025-05-22
 */
@Validated
@RestController
@RequestMapping("/progress/progressCategoryTemplate")
public class PgsProgressCategoryTemplateController extends BaseController {

    @Resource
    private IPgsProgressCategoryTemplateService pgsProgressCategoryTemplateService;

    /**
     * 分页查询进度类别模版列表
     */
    @SaCheckPermission("progress:progressCategoryTemplate:page")
    @GetMapping("/page")
    public TableDataInfo<PgsProgressCategoryTemplateVo> page(PgsProgressCategoryTemplateQueryReq req, PageQuery pageQuery) {
        return pgsProgressCategoryTemplateService.queryPageList(req, pageQuery);
    }

    /**
     * 查询进度类别模版列表
     */
    @SaCheckPermission("progress:progressCategoryTemplate:list")
    @GetMapping("/list")
    public R<List<PgsProgressCategoryTemplateVo>> list(PgsProgressCategoryTemplateQueryReq req) {
        List<PgsProgressCategoryTemplateVo> list = pgsProgressCategoryTemplateService.queryList(req);
        return R.ok(list);
    }

    /**
     * 导出进度类别模版列表
     */
    @SaCheckPermission("progress:progressCategoryTemplate:export")
    @Log(title = "进度类别模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PgsProgressCategoryTemplateQueryReq req, HttpServletResponse response) {
        List<PgsProgressCategoryTemplateVo> list = pgsProgressCategoryTemplateService.queryList(req);
        ExcelUtil.exportExcel(list, "进度类别模版", PgsProgressCategoryTemplateVo.class, response);
    }

    /**
     * 获取进度类别模版详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("progress:progressCategoryTemplate:query")
    @GetMapping("/{id}")
    public R<PgsProgressCategoryTemplateVo> getInfo(@NotNull(message = "主键不能为空")
                                                    @PathVariable Long id) {
        return R.ok(pgsProgressCategoryTemplateService.queryById(id));
    }

    /**
     * 新增进度类别模版
     */
    @SaCheckPermission("progress:progressCategoryTemplate:add")
    @Log(title = "进度类别模版", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Long> add(@Validated(AddGroup.class) @RequestBody PgsProgressCategoryTemplateCreateReq req) {
        return R.ok(pgsProgressCategoryTemplateService.insertByBo(req));
    }

    /**
     * 修改进度类别模版
     */
    @SaCheckPermission("progress:progressCategoryTemplate:edit")
    @Log(title = "进度类别模版", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PgsProgressCategoryTemplateUpdateReq req) {
        return toAjax(pgsProgressCategoryTemplateService.updateByBo(req));
    }

    /**
     * 删除进度类别模版
     *
     * @param ids 主键串
     */
    @SaCheckPermission("progress:progressCategoryTemplate:remove")
    @Log(title = "进度类别模版", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(pgsProgressCategoryTemplateService.deleteWithValidByIds(List.of(ids), true));
    }
}
