package com.yingpaipay.business.controller;

import java.util.List;

import com.yingpaipay.business.domain.bo.DocumentQcTaskBo;
import com.yingpaipay.business.domain.bo.ProjectListOnQcBo;
import com.yingpaipay.business.domain.vo.ProjectListOnQcVo;
import com.yingpaipay.business.domain.vo.ProjectVo;
import com.yingpaipay.business.service.IProjectService;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import com.yingpaipay.business.domain.vo.DocumentQcTaskVo;
import com.yingpaipay.business.service.IDocumentQcTaskService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 文档质控任务
 *
 * @author Huanyi
 * @date 2026-01-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/qc/task")
public class DocumentQcTaskController extends BaseController {

    private final IDocumentQcTaskService documentQcTaskDetailService;
    private final IProjectService projectService;

    /**
     * 查询文档质控任务列表
     */
    @SaCheckPermission("qc:task:list")
    @GetMapping("/list")
    public TableDataInfo<DocumentQcTaskVo> list(DocumentQcTaskBo bo, PageQuery pageQuery) {
        return documentQcTaskDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出文档质控任务列表
     */
    @SaCheckPermission("qc:task:export")
    @Log(title = "文档质控任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DocumentQcTaskBo bo, HttpServletResponse response) {
        List<DocumentQcTaskVo> list = documentQcTaskDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "文档质控任务", DocumentQcTaskVo.class, response);
    }

    /**
     * 获取文档质控任务详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("qc:task:query")
    @GetMapping("/{id}")
    public R<DocumentQcTaskVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(documentQcTaskDetailService.queryById(id));
    }

    /**
     * 新增文档质控任务
     */
    @SaCheckPermission("qc:task:add")
    @Log(title = "文档质控任务", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DocumentQcTaskBo bo) {
        return toAjax(documentQcTaskDetailService.insertByBo(bo));
    }

    /**
     * 修改文档质控任务
     */
    @SaCheckPermission("qc:task:edit")
    @Log(title = "文档质控任务", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DocumentQcTaskBo bo) {
        return toAjax(documentQcTaskDetailService.updateByBo(bo));
    }

    /**
     * 删除文档质控任务
     *
     * @param ids 主键串
     */
    @SaCheckPermission("qc:task:remove")
    @Log(title = "文档质控任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(documentQcTaskDetailService.deleteWithValidByIds(List.of(ids), true));
    }

    @SaCheckPermission("qc:task:start")
    @Log(title = "文档指控任务", businessType = BusinessType.UPDATE)
    @PutMapping("/{id}")
    public R<Void> start(@PathVariable Long id) {
        return toAjax(documentQcTaskDetailService.start(id));
    }

}
