package org.dromara.elevator.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.elevator.domain.vo.ESignInInfoVo;
import org.dromara.elevator.domain.bo.ESignInInfoBo;
import org.dromara.elevator.service.IESignInInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 签到管理;
 *
 * @author zy
 * @date 2024-07-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sign/signInInfo")
public class ESignInInfoController extends BaseController {

    private final IESignInInfoService eSignInInfoService;

    /**
     * 查询签到管理;列表
     */
    @SaCheckPermission("elevator:signInInfo:list")
    @GetMapping("/list")
    public TableDataInfo<ESignInInfoVo> list(ESignInInfoBo bo, PageQuery pageQuery) {
        return eSignInInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出签到管理;列表
     */
    @SaCheckPermission("elevator:signInInfo:export")
    @Log(title = "签到管理;", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ESignInInfoBo bo, HttpServletResponse response) {
        List<ESignInInfoVo> list = eSignInInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "签到管理;", ESignInInfoVo.class, response);
    }

    /**
     * 获取签到管理;详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("elevator:signInInfo:query")
    @GetMapping("/{id}")
    public R<ESignInInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(eSignInInfoService.queryById(id));
    }

    /**
     * 新增签到管理;
     */
    @SaCheckPermission("elevator:signInInfo:add")
    @Log(title = "签到管理;", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ESignInInfoBo bo) {
        return toAjax(eSignInInfoService.insertByBo(bo));
    }

    /**
     * 修改签到管理;
     */
    @SaCheckPermission("elevator:signInInfo:edit")
    @Log(title = "签到管理;", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ESignInInfoBo bo) {
        return toAjax(eSignInInfoService.updateByBo(bo));
    }

    /**
     * 删除签到管理;
     *
     * @param ids 主键串
     */
    @SaCheckPermission("elevator:signInInfo:remove")
    @Log(title = "签到管理;", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(eSignInInfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
