package org.dromara.safety.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.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.dromara.safety.domain.dto.teammeeting.HseTeamMeetingCreateReq;
import org.dromara.safety.domain.dto.teammeeting.HseTeamMeetingQueryReq;
import org.dromara.safety.domain.dto.teammeeting.HseTeamMeetingUpdateReq;
import org.dromara.safety.domain.vo.teammeeting.HseTeamMeetingVo;
import org.dromara.safety.service.IHseTeamMeetingService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 站班会
 *
 * @author lcj
 * @date 2025-03-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/safety/teamMeeting")
public class HseTeamMeetingController extends BaseController {

    private final IHseTeamMeetingService teamMeetingService;

    /**
     * 查询站班会列表
     */
    @SaCheckPermission("safety:teamMeeting:list")
    @GetMapping("/list")
    public TableDataInfo<HseTeamMeetingVo> list(HseTeamMeetingQueryReq req, PageQuery pageQuery) {
        return teamMeetingService.queryPageList(req, pageQuery);
    }

    /**
     * 导出站班会列表
     */
    @SaCheckPermission("safety:teamMeeting:export")
    @Log(title = "站班会", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HseTeamMeetingQueryReq req, HttpServletResponse response) {
        List<HseTeamMeetingVo> list = teamMeetingService.queryList(req);
        ExcelUtil.exportExcel(list, "站班会", HseTeamMeetingVo.class, response);
    }

    /**
     * 获取站班会详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("safety:teamMeeting:query")
    @GetMapping("/{id}")
    public R<HseTeamMeetingVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long id) {
        return R.ok(teamMeetingService.queryById(id));
    }

    /**
     * 新增站班会
     */
    @SaCheckPermission("safety:teamMeeting:add")
    @Log(title = "站班会", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Long> add(@Validated(AddGroup.class) @RequestBody HseTeamMeetingCreateReq req) {
        return R.ok(teamMeetingService.insertByBo(req));
    }

    /**
     * 修改站班会
     */
    @SaCheckPermission("safety:teamMeeting:edit")
    @Log(title = "站班会", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HseTeamMeetingUpdateReq req) {
        return toAjax(teamMeetingService.updateByBo(req));
    }

    /**
     * 删除站班会
     *
     * @param ids 主键串
     */
    @SaCheckPermission("safety:teamMeeting:remove")
    @Log(title = "站班会", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(teamMeetingService.deleteWithValidByIds(List.of(ids), true));
    }
}
