package com.fuyuanshen.equipment.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.query.DeviceRepairRecordsQueryCriteria;
import io.swagger.v3.oas.annotations.Operation;
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 com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
import com.fuyuanshen.common.log.annotation.Log;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.common.log.enums.BusinessType;
import com.fuyuanshen.common.excel.utils.ExcelUtil;
import com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo;
import com.fuyuanshen.equipment.domain.bo.DeviceRepairRecordsBo;
import com.fuyuanshen.equipment.service.IDeviceRepairRecordsService;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;

/**
 * 设备维修记录
 *
 * @author Lion Li
 * @date 2025-08-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/equipment/repairRecords")
public class DeviceRepairRecordsController extends BaseController {

    private final IDeviceRepairRecordsService deviceRepairRecordsService;


    /**
     * 查询设备维修记录列表
     */
    @SaCheckPermission("equipment:repairRecords:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询维修记录列表")
    public TableDataInfo<DeviceRepairRecordsVo> list(DeviceRepairRecordsQueryCriteria criteria) {
        Page<DeviceRepairRecords> page = new Page<>(criteria.getPageNum(), criteria.getPageSize());
        return deviceRepairRecordsService.queryPageList(criteria, page);
    }


    /**
     * 导出设备维修记录列表
     */
    @SaCheckPermission("equipment:repairRecords:export")
    @Log(title = "设备维修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DeviceRepairRecordsQueryCriteria bo, HttpServletResponse response) {
        List<DeviceRepairRecordsVo> list = deviceRepairRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "设备维修记录", DeviceRepairRecordsVo.class, response);
    }


    /**
     * 获取设备维修记录详细信息
     *
     * @param recordId 主键
     */
    @SaCheckPermission("equipment:repairRecords:query")
    @GetMapping("/{recordId}")
    public R<DeviceRepairRecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long recordId) {
        return R.ok(deviceRepairRecordsService.queryById(recordId));
    }


    /**
     * 新增设备维修记录
     */
    @SaCheckPermission("equipment:repairRecords:add")
    @Log(title = "设备维修记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping(consumes = "multipart/form-data")
    public R<Void> add(@Validated(AddGroup.class) DeviceRepairRecordsBo bo) {
        return toAjax(deviceRepairRecordsService.insertByBo(bo));
    }


    /**
     * 修改设备维修记录
     */
    @SaCheckPermission("equipment:repairRecords:edit")
    @Log(title = "设备维修记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping(consumes = "multipart/form-data")
    public R<Void> edit(@Validated(EditGroup.class) DeviceRepairRecordsBo bo) {
        return toAjax(deviceRepairRecordsService.updateByBo(bo));
    }

    /**
     * 删除设备维修记录
     *
     * @param recordIds 主键串
     */
    @SaCheckPermission("equipment:repairRecords:remove")
    @Log(title = "设备维修记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] recordIds) {
        return toAjax(deviceRepairRecordsService.deleteWithValidByIds(List.of(recordIds), true));
    }

}
