package org.dromara.project.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.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.workerdailyreport.BusWorkerDailyReportQueryReq;
import org.dromara.project.domain.vo.workerdailyreport.BusWorkerDailyReportVo;
import org.dromara.project.service.IBusWorkerDailyReportService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 施工人员日报
 *
 * @author lcj
 * @date 2025-04-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/workerDailyReport")
public class BusWorkerDailyReportController extends BaseController {

    private final IBusWorkerDailyReportService busWorkerDailyReportService;

    /**
     * 查询施工人员日报列表
     */
    @SaCheckPermission("project:workerDailyReport:list")
    @GetMapping("/list")
    public TableDataInfo<BusWorkerDailyReportVo> list(BusWorkerDailyReportQueryReq req, PageQuery pageQuery) {
        return busWorkerDailyReportService.queryPageList(req, pageQuery);
    }

    /**
     * 导出施工人员日报列表
     */
    @SaCheckPermission("project:workerDailyReport:export")
    @Log(title = "施工人员日报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BusWorkerDailyReportQueryReq req, HttpServletResponse response) {
        List<BusWorkerDailyReportVo> list = busWorkerDailyReportService.queryList(req);
        ExcelUtil.exportExcel(list, "施工人员日报", BusWorkerDailyReportVo.class, response);
    }

    /**
     * 获取施工人员日报详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("project:workerDailyReport:query")
    @GetMapping("/{id}")
    public R<BusWorkerDailyReportVo> getInfo(@NotNull(message = "主键不能为空")
                                             @PathVariable Long id) {
        return R.ok(busWorkerDailyReportService.queryById(id));
    }

    /**
     * 删除施工人员日报
     *
     * @param ids 主键串
     */
    @SaCheckPermission("project:workerDailyReport:remove")
    @Log(title = "施工人员日报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(busWorkerDailyReportService.deleteWithValidByIds(List.of(ids), true));
    }

}
