package com.hotwj.platform.noticeManagerment.noticeSignDocument.controller;

import com.hotwj.platform.noticeManagerment.noticeSignDocument.domain.bo.HotNoticeSignDocumentBo;
import com.hotwj.platform.noticeManagerment.noticeSignDocument.domain.vo.HotNoticeSignDocumentVo;
import com.hotwj.platform.noticeManagerment.noticeSignDocument.service.IHotNoticeSignDocumentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
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.core.validate.AddGroup;
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.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 签订文件
 *
 * @author shihongwei
 * @date 2026-01-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/noticeManagerment/noticeSignDocument")
@Tag(name = "签订文件", description = "签订文件管理")
public class HotNoticeSignDocumentController extends BaseController {

    private final IHotNoticeSignDocumentService hotNoticeSignDocumentService;

    /**
     * 查询签订文件列表
     */
    //@SaCheckPermission("noticeManagerment:noticeSignDocument:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询签订文件列表")
    public TableDataInfo<HotNoticeSignDocumentVo> list(HotNoticeSignDocumentBo bo, PageQuery pageQuery) {
        return hotNoticeSignDocumentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出签订文件列表
     */
    //@SaCheckPermission("noticeManagerment:noticeSignDocument:export")
    @Log(title = "签订文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出签订文件列表")
    public void export(HotNoticeSignDocumentBo bo, HttpServletResponse response) {
        List<HotNoticeSignDocumentVo> list = hotNoticeSignDocumentService.queryList(bo);
        ExcelUtil.exportExcel(list, "签订文件", HotNoticeSignDocumentVo.class, response);
    }

    /**
     * 获取签订文件详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("noticeManagerment:noticeSignDocument:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取签订文件详细信息")
    public R<HotNoticeSignDocumentVo> getInfo(@NotNull(message = "主键不能为空")
                                              @Parameter(name = "id", description = "主键", required = true, example = "1")
                                              @PathVariable Long id) {
        return R.ok(hotNoticeSignDocumentService.queryById(id));
    }

    /**
     * 新增签订文件
     */
    //@SaCheckPermission("noticeManagerment:noticeSignDocument:add")
    @Log(title = "签订文件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增签订文件")
    public R<Long> add(@Validated(AddGroup.class) @RequestBody HotNoticeSignDocumentBo bo) {
        Long id = hotNoticeSignDocumentService.insertByBo(bo);
        return R.ok(id);
    }

    /**
     * 修改签订文件
     */
    //@SaCheckPermission("noticeManagerment:noticeSignDocument:edit")
    @Log(title = "签订文件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改签订文件")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotNoticeSignDocumentBo bo) {
        return toAjax(hotNoticeSignDocumentService.updateByBo(bo));
    }

    /**
     * 删除签订文件
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("noticeManagerment:noticeSignDocument:remove")
    @Log(title = "签订文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除签订文件")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(hotNoticeSignDocumentService.deleteWithValidByIds(List.of(ids), true));
    }
}
