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.EWorkOperationRecordVo;
import org.dromara.elevator.domain.bo.EWorkOperationRecordBo;
import org.dromara.elevator.service.IEWorkOperationRecordService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 工作操作记录
 *
 * @author ym
 * @date 2024-09-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/elevator/workOperationRecord")
public class EWorkOperationRecordController extends BaseController {

    private final IEWorkOperationRecordService eWorkOperationRecordService;

    /**
     * 查询工作操作记录列表
     */
    @SaCheckPermission("elevator:workOperationRecord:list")
    @GetMapping("/list")
    public TableDataInfo<EWorkOperationRecordVo> list(EWorkOperationRecordBo bo, PageQuery pageQuery) {
        return eWorkOperationRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工作操作记录列表
     */
    @SaCheckPermission("elevator:workOperationRecord:export")
    @Log(title = "工作操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EWorkOperationRecordBo bo, HttpServletResponse response) {
        List<EWorkOperationRecordVo> list = eWorkOperationRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "工作操作记录", EWorkOperationRecordVo.class, response);
    }

    /**
     * 获取工作操作记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("elevator:workOperationRecord:query")
    @GetMapping("/{id}")
    public R<EWorkOperationRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(eWorkOperationRecordService.queryById(id));
    }

    /**
     * 新增工作操作记录
     */
    @SaCheckPermission("elevator:workOperationRecord:add")
    @Log(title = "工作操作记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EWorkOperationRecordBo bo) {
        return toAjax(eWorkOperationRecordService.insertByBo(bo));
    }

    /**
     * 修改工作操作记录
     */
    @SaCheckPermission("elevator:workOperationRecord:edit")
    @Log(title = "工作操作记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EWorkOperationRecordBo bo) {
        return toAjax(eWorkOperationRecordService.updateByBo(bo));
    }

    /**
     * 删除工作操作记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("elevator:workOperationRecord:remove")
    @Log(title = "工作操作记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(eWorkOperationRecordService.deleteWithValidByIds(List.of(ids), true));
    }
}
