package com.hotwj.platform.securityManagement.securityMeetingAttendee.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.hotwj.platform.securityManagement.securityMeetingAttendee.domain.bo.HotSecurityMeetingAttendeeBo;
import com.hotwj.platform.securityManagement.securityMeetingAttendee.domain.bo.HotSecurityMeetingMyQueryBo;
import com.hotwj.platform.securityManagement.securityMeetingAttendee.domain.bo.HotSecurityMeetingSignBo;
import com.hotwj.platform.securityManagement.securityMeetingAttendee.domain.vo.HotSecurityMeetingAttendeeVo;
import com.hotwj.platform.securityManagement.securityMeetingAttendee.domain.vo.HotSecurityMeetingMyVo;
import com.hotwj.platform.securityManagement.securityMeetingAttendee.service.IHotSecurityMeetingAttendeeService;
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-02-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/securityManagement/securityMeetingAttendee")
@Tag(name = "会议参会人员详情", description = "会议参会人员详情管理")
public class HotSecurityMeetingAttendeeController extends BaseController {

    private final IHotSecurityMeetingAttendeeService hotSecurityMeetingAttendeeService;

    /**
     * 查询我的会议列表
     */
//    @SaCheckPermission("securityManagement:securityMeetingAttendee:list")
    @GetMapping("/myList")
    @Operation(summary = "查询我的会议列表")
    public TableDataInfo<HotSecurityMeetingMyVo> myList(HotSecurityMeetingMyQueryBo bo, PageQuery pageQuery) {
        return hotSecurityMeetingAttendeeService.queryMyMeetingList(bo, pageQuery);
    }

    /**
     * 查询会议参会人员详情列表
     */
    @SaCheckPermission("securityManagement:securityMeetingAttendee:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询会议参会人员详情列表")
    public TableDataInfo<HotSecurityMeetingAttendeeVo> list(HotSecurityMeetingAttendeeBo bo, PageQuery pageQuery) {
        return hotSecurityMeetingAttendeeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出会议参会人员详情列表
     */
    @SaCheckPermission("securityManagement:securityMeetingAttendee:export")
    @Log(title = "会议参会人员详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出会议参会人员详情列表")
    public void export(HotSecurityMeetingAttendeeBo bo, HttpServletResponse response) {
        List<HotSecurityMeetingAttendeeVo> list = hotSecurityMeetingAttendeeService.queryList(bo);
        ExcelUtil.exportExcel(list, "会议参会人员详情", HotSecurityMeetingAttendeeVo.class, response);
    }

    /**
     * 获取会议参会人员详情详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("securityManagement:securityMeetingAttendee:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取会议参会人员详情详细信息")
    public R<HotSecurityMeetingAttendeeVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @Parameter(name = "id", description = "主键", required = true, example = "1")
                                                   @PathVariable Long id) {
        return R.ok(hotSecurityMeetingAttendeeService.queryById(id));
    }

    /**
     * 新增会议参会人员详情
     */
    @SaCheckPermission("securityManagement:securityMeetingAttendee:add")
    @Log(title = "会议参会人员详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增会议参会人员详情")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotSecurityMeetingAttendeeBo bo) {
        return toAjax(hotSecurityMeetingAttendeeService.insertByBo(bo));
    }

    /**
     * 修改会议参会人员详情
     */
    @SaCheckPermission("securityManagement:securityMeetingAttendee:edit")
    @Log(title = "会议参会人员详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改会议参会人员详情")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotSecurityMeetingAttendeeBo bo) {
        return toAjax(hotSecurityMeetingAttendeeService.updateByBo(bo));
    }

    /**
     * 删除会议参会人员详情
     *
     * @param ids 主键串
     */
    @SaCheckPermission("securityManagement:securityMeetingAttendee: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(hotSecurityMeetingAttendeeService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 完成会议签到
     *
     * @param bo 签到业务对象
     */
    @Log(title = "完成会议签到", businessType = BusinessType.UPDATE)
    @PostMapping("/completeSign")
    @Operation(summary = "完成会议签到")
    public R<Boolean> completeSign(@Validated @RequestBody HotSecurityMeetingSignBo bo) {
        return R.ok(hotSecurityMeetingAttendeeService.completeSign(bo.getTaskId(), bo.getPhotoOssId(), bo.getSignOssId()));
    }
}
