package com.hotwj.platform.resourceManagement.vehicleMaintenance.controller;

import com.hotwj.platform.resourceManagement.vehicleMaintenance.domain.bo.HotVehicleMaintenanceBo;
import com.hotwj.platform.resourceManagement.vehicleMaintenance.domain.vo.HotVehicleMaintenanceVo;
import com.hotwj.platform.resourceManagement.vehicleMaintenance.service.IHotVehicleMaintenanceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆维护记录
 *
 * @author shihongwei
 * @date 2025-12-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/resourceManagement/vehicleMaintenance")
@Tag(name = "车辆维护记录", description = "车辆维护记录管理")
public class HotVehicleMaintenanceController extends BaseController {

    private final IHotVehicleMaintenanceService hotVehicleMaintenanceService;

    /**
     * 查询车辆维护记录列表
     */
    //@SaCheckPermission("resourceManagement:vehicleMaintenance:list")
    @GetMapping("/list")
    @Operation(summary = "查询车辆维护记录列表")
    public TableDataInfo<HotVehicleMaintenanceVo> list(HotVehicleMaintenanceBo bo, PageQuery pageQuery) {
        return hotVehicleMaintenanceService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出车辆维护记录列表
     */
    //@SaCheckPermission("resourceManagement:vehicleMaintenance:export")
    @Log(title = "车辆维护记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出车辆维护记录列表")
    public void export(HotVehicleMaintenanceBo bo, HttpServletResponse response) {
        List<HotVehicleMaintenanceVo> list = hotVehicleMaintenanceService.queryList(bo);
        ExcelUtil.exportExcel(list, "车辆维护记录", HotVehicleMaintenanceVo.class, response);
    }

    /**
     * 获取车辆维护记录详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("resourceManagement:vehicleMaintenance:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取车辆维护记录详细信息")
    public R<HotVehicleMaintenanceVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(hotVehicleMaintenanceService.queryById(id));
    }

    /**
     * 新增车辆维护记录
     */
    //@SaCheckPermission("resourceManagement:vehicleMaintenance:add")
    @Log(title = "车辆维护记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增车辆维护记录")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotVehicleMaintenanceBo bo) {
        return toAjax(hotVehicleMaintenanceService.insertByBo(bo));
    }

    /**
     * 修改车辆维护记录
     */
    //@SaCheckPermission("resourceManagement:vehicleMaintenance:edit")
    @Log(title = "车辆维护记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改车辆维护记录")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotVehicleMaintenanceBo bo) {
        return toAjax(hotVehicleMaintenanceService.updateByBo(bo));
    }

    /**
     * 删除车辆维护记录
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("resourceManagement:vehicleMaintenance:remove")
    @Log(title = "车辆维护记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除车辆维护记录")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hotVehicleMaintenanceService.deleteWithValidByIds(List.of(ids), true));
    }
}
