package org.dromara.project.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
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.project.domain.dto.reissuecard.BusReissueCardManagerReviewReq;
import org.dromara.project.domain.dto.reissuecard.BusReissueCardQueryReq;
import org.dromara.project.domain.vo.reissuecard.BusReissueCardVo;
import org.dromara.project.service.IBusReissueCardService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 施工人员补卡申请
 *
 * @author lcj
 * @date 2025-04-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/reissueCard")
public class BusReissueCardController extends BaseController {

    private final IBusReissueCardService busReissueCardService;

    /**
     * 查询施工人员补卡申请列表
     */
    @SaCheckPermission("project:reissueCard:list")
    @GetMapping("/list")
    public TableDataInfo<BusReissueCardVo> list(BusReissueCardQueryReq req, PageQuery pageQuery) {
        return busReissueCardService.queryPageList(req, pageQuery);
    }

    /**
     * 导出施工人员补卡申请列表
     */
    @SaCheckPermission("project:reissueCard:export")
    @Log(title = "施工人员补卡申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusReissueCardQueryReq req, HttpServletResponse response) {
        List<BusReissueCardVo> list = busReissueCardService.queryList(req);
        ExcelUtil.exportExcel(list, "施工人员补卡申请", BusReissueCardVo.class, response);
    }

    /**
     * 获取施工人员补卡申请详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("project:reissueCard:query")
    @GetMapping("/{id}")
    public R<BusReissueCardVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long id) {
        return R.ok(busReissueCardService.queryById(id));
    }

    /**
     * 管理员审核施工人员补卡申请
     */
    @SaCheckPermission("project:reissueCard:edit")
    @Log(title = "施工人员补卡申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/review/manager")
    public R<Void> managerReview(@RequestBody BusReissueCardManagerReviewReq req) {
        return toAjax(busReissueCardService.managerReview(req));
    }

    /**
     * 删除施工人员补卡申请
     *
     * @param ids 主键串
     */
    @SaCheckPermission("project:reissueCard:remove")
    @Log(title = "施工人员补卡申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(busReissueCardService.deleteWithValidByIds(List.of(ids), true));
    }
}
