package org.dromara.project.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
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.project.domain.dto.constructionuserexit.BusConstructionUserExitQueryReq;
import org.dromara.project.domain.vo.constructionuserexit.BusConstructionUserExitVo;
import org.dromara.project.service.IBusConstructionUserExitService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 施工人员入场退场记录信息
 *
 * @author lcj
 * @date 2025-03-31
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/constructionUserExit")
public class BusConstructionUserExitController extends BaseController {

    private final IBusConstructionUserExitService busConstructionUserExitService;

    /**
     * 查询施工人员入场退场记录信息列表
     */
    @SaCheckPermission("project:constructionUserExit:list")
    @GetMapping("/list")
    public TableDataInfo<BusConstructionUserExitVo> list(BusConstructionUserExitQueryReq req, PageQuery pageQuery) {
        return busConstructionUserExitService.queryPageList(req, pageQuery);
    }

    /**
     * 导出施工人员入场退场记录信息列表
     */
    @SaCheckPermission("project:constructionUserExit:export")
    @Log(title = "施工人员入场退场记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusConstructionUserExitQueryReq req, HttpServletResponse response) {
        List<BusConstructionUserExitVo> list = busConstructionUserExitService.queryList(req);
        ExcelUtil.exportExcel(list, "施工人员入场退场记录信息", BusConstructionUserExitVo.class, response);
    }

    /**
     * 获取施工人员入场退场记录信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("project:constructionUserExit:query")
    @GetMapping("/{id}")
    public R<BusConstructionUserExitVo> getInfo(@NotNull(message = "主键不能为空")
                                                @PathVariable Long id) {
        return R.ok(busConstructionUserExitService.queryById(id));
    }
}
