package org.dromara.progress.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import org.dromara.common.core.domain.R;
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.progressplandetail.PgsProgressPlanDetailQueryReq;
import org.dromara.progress.domain.dto.progressplandetail.PgsProgressPlanDetailUpdateReq;
import org.dromara.progress.domain.vo.progressplandetail.PgsProgressPlanDetailFacilityVo;
import org.dromara.progress.domain.vo.progressplandetail.PgsProgressPlanDetailVo;
import org.dromara.progress.service.IPgsProgressPlanDetailService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 进度计划详情
 *
 * @author lcj
 * @date 2025-05-27
 */
@Validated
@RestController
@RequestMapping("/progress/progressPlanDetail")
public class PgsProgressPlanDetailController extends BaseController {

    @Resource
    private IPgsProgressPlanDetailService pgsProgressPlanDetailService;

    /**
     * 查询进度计划详情列表
     */
    @SaCheckPermission("progress:progressPlanDetail:list")
    @GetMapping("/list")
    public TableDataInfo<PgsProgressPlanDetailVo> list(PgsProgressPlanDetailQueryReq req, PageQuery pageQuery) {
        return pgsProgressPlanDetailService.queryPageList(req, pageQuery);
    }

    /**
     * 导出进度计划详情列表
     */
    @SaCheckPermission("progress:progressPlanDetail:export")
    @Log(title = "进度计划详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PgsProgressPlanDetailQueryReq req, HttpServletResponse response) {
        List<PgsProgressPlanDetailVo> list = pgsProgressPlanDetailService.queryList(req);
        ExcelUtil.exportExcel(list, "进度计划详情", PgsProgressPlanDetailVo.class, response);
    }

    /**
     * 获取进度计划详情详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("progress:progressPlanDetail:query")
    @GetMapping("/{id}")
    public R<PgsProgressPlanDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable Long id) {
        return R.ok(pgsProgressPlanDetailService.queryById(id));
    }

    /**
     * 获取进度计划详情详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("progress:progressPlanDetail:query")
    @GetMapping("/detail/{id}")
    public R<TableDataInfo<PgsProgressPlanDetailFacilityVo>> getDetail(@NotNull(message = "主键不能为空")
                                                                       @PathVariable Long id,
                                                                       PageQuery pageQuery) {
        return R.ok(pgsProgressPlanDetailService.queryFacilityById(id, pageQuery));
    }

    /**
     * 修改进度计划详情
     */
    @SaCheckPermission("progress:progressPlanDetail:edit")
    @Log(title = "进度计划详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PgsProgressPlanDetailUpdateReq req) {
        return toAjax(pgsProgressPlanDetailService.updateByBo(req));
    }

}
