package org.dromara.project.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
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.web.core.BaseController;
import org.dromara.project.domain.dto.constructionuserfile.BusConstructionUserFileQueryReq;
import org.dromara.project.domain.dto.constructionuserfile.BusConstructionUserFileSaveReq;
import org.dromara.project.domain.dto.constructionuserfile.BusConstructionUserFileTemplateReq;
import org.dromara.project.domain.vo.constructionuserfile.BusConstructionUserFileVo;
import org.dromara.project.service.IBusConstructionUserFileService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 施工人员文件存储
 *
 * @author lcj
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/constructionUserFile")
public class BusConstructionUserFileController extends BaseController {

    private final IBusConstructionUserFileService busConstructionUserFileService;

    /**
     * 查询施工人员文件存储列表
     */
    @SaCheckPermission("project:constructionUserFile:list")
    @GetMapping("/list")
    public R<List<BusConstructionUserFileVo>> list(BusConstructionUserFileQueryReq req) {
        return R.ok(busConstructionUserFileService.queryList(req));
    }

    /**
     * 导出施工人员文件存储列表
     */
    @SaCheckPermission("project:constructionUserFile:export")
    @Log(title = "施工人员文件存储", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusConstructionUserFileQueryReq req, HttpServletResponse response) {
        List<BusConstructionUserFileVo> list = busConstructionUserFileService.queryList(req);
        ExcelUtil.exportExcel(list, "施工人员文件存储", BusConstructionUserFileVo.class, response);
    }

    /**
     * 下载施工人员文件存储模板
     */
    @SaCheckPermission("project:constructionUserFile:export")
    @Log(title = "施工人员文件存储", businessType = BusinessType.EXPORT)
    @RepeatSubmit()
    @PostMapping("/exportFileTemplate")
    public void exportFileTemplate(BusConstructionUserFileTemplateReq req, HttpServletResponse response) {
        busConstructionUserFileService.downloadFileTemplate(req, response);
    }

    /**
     * 上传施工人员文件压缩包，批量导入存储施工人员文件
     */
    @SaCheckPermission("project:constructionUserFile:edit")
    @Log(title = "施工人员文件存储", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/upload/zip")
    public R<Boolean> uploadFileZip(@RequestParam("file") MultipartFile file) {
        Boolean result = busConstructionUserFileService.batchUploadFileByZip(file);
        return R.ok(result);
    }

    /**
     * 获取施工人员文件存储详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("project:constructionUserFile:query")
    @GetMapping("/{id}")
    public R<BusConstructionUserFileVo> getInfo(@NotNull(message = "主键不能为空")
                                                @PathVariable Long id) {
        return R.ok(busConstructionUserFileService.queryById(id));
    }

    /**
     * 保存施工人员文件存储详情信息
     */
    @SaCheckPermission("project:constructionUserFile:edit")
    @Log(title = "施工人员文件存储", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public R<Boolean> save(@RequestBody BusConstructionUserFileSaveReq req) {
        return R.ok(busConstructionUserFileService.saveFileList(req));
    }

}
