package org.dromara.safety.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.dromara.common.core.domain.R;
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.safety.domain.dto.documentsafetymeeting.HseDocumentSafetyMeetingCreateFileReq;
import org.dromara.safety.domain.dto.documentsafetymeeting.HseDocumentSafetyMeetingCreateFolderReq;
import org.dromara.safety.domain.dto.documentsafetymeeting.HseDocumentSafetyMeetingQueryReq;
import org.dromara.safety.domain.vo.documentsafetymeeting.HseDocumentSafetyMeetingVo;
import org.dromara.safety.domain.vo.documentsafetymeeting.HseDocumentSafetyMeetingRecycleBinVo;
import org.dromara.safety.service.IHseDocumentSafetyMeetingService;
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-14
 */
@Validated
@RestController
@RequestMapping("/safety/documentSafetyMeeting")
public class HseDocumentSafetyMeetingController extends BaseController {

    @Resource
    private IHseDocumentSafetyMeetingService documentSafetyMeetingService;

    /**
     * 查询安全会议纪要列表
     */
    @SaCheckPermission("safety:documentSafetyMeeting:list")
    @GetMapping("/list")
    public R<List<HseDocumentSafetyMeetingVo>> list(HseDocumentSafetyMeetingQueryReq req) {
        return R.ok(documentSafetyMeetingService.queryList(req));
    }

    /**
     * 查询安全会议纪要回收站列表
     */
    @SaCheckPermission("safety:documentSafetyMeeting:list")
    @GetMapping("/recycleBin/list")
    public TableDataInfo<HseDocumentSafetyMeetingRecycleBinVo> list(HseDocumentSafetyMeetingQueryReq req, PageQuery pageQuery) {
        return documentSafetyMeetingService.queryRecycleBinPageList(req, pageQuery);
    }

    /**
     * 获取安全会议纪要详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("safety:documentSafetyMeeting:query")
    @GetMapping("/{id}")
    public R<HseDocumentSafetyMeetingVo> getInfo(@NotNull(message = "主键不能为空")
                                                 @PathVariable Long id) {
        return R.ok(documentSafetyMeetingService.queryById(id));
    }

    /**
     * 新增安全会议纪要文件夹
     */
    @SaCheckPermission("safety:documentSafetyMeeting:add")
    @Log(title = "安全会议纪要", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/folder")
    public R<Long> addFolder(@RequestBody HseDocumentSafetyMeetingCreateFolderReq req) {
        return R.ok(documentSafetyMeetingService.insertByFolder(req));
    }

    /**
     * 新增安全会议纪要文件
     */
    @SaCheckPermission("safety:documentSafetyMeeting:add")
    @Log(title = "安全会议纪要", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/file")
    public R<Long> addFile(@RequestPart("file") MultipartFile file, HseDocumentSafetyMeetingCreateFileReq req) {
        return R.ok(documentSafetyMeetingService.insertByFile(file, req));
    }

    /**
     * 批量恢复安全会议纪要文件
     *
     * @param ids 主键串
     */
    @SaCheckPermission("safety:documentSafetyMeeting:edit")
    @Log(title = "安全会议纪要", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/recovery/{ids}")
    public R<Void> recovery(@NotEmpty(message = "主键不能为空")
                            @PathVariable Long[] ids) {
        return toAjax(documentSafetyMeetingService.recoveryBatchById(List.of(ids)));
    }

    /**
     * 删除安全会议纪要
     *
     * @param ids 主键串
     */
    @SaCheckPermission("safety:documentSafetyMeeting:remove")
    @Log(title = "安全会议纪要", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(documentSafetyMeetingService.deleteWithRecycleBin(List.of(ids)));
    }

    /**
     * 彻底删除安全会议纪要
     *
     * @param ids 主键串
     */
    @SaCheckPermission("safety:documentSafetyMeeting:remove")
    @Log(title = "安全会议纪要", businessType = BusinessType.DELETE)
    @DeleteMapping("/completelyDelete/{ids}")
    public R<Void> completelyDelete(@NotEmpty(message = "主键不能为空")
                                    @PathVariable Long[] ids) {
        return toAjax(documentSafetyMeetingService.completelyDelete(List.of(ids)));
    }

}
