package com.ruoyi.web.controller.maintenance;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.maintenance.MaintenanceStaff;
import com.ruoyi.system.service.IMaintenanceStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维修人员管理Controller
 *
 * @author boman
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/wuYe/staff")
public class MaintenanceStaffController extends BaseController
{
    @Autowired
    private IMaintenanceStaffService maintenanceStaffService;

/**
 * 查询维修人员管理列表
 */
@PreAuthorize("@ss.hasPermi('wuYe:staff:list')")
@GetMapping("/list")
    public TableDataInfo list(MaintenanceStaff maintenanceStaff)
    {
        startPage();
        List<MaintenanceStaff> list = maintenanceStaffService.selectMaintenanceStaffList(maintenanceStaff);
        return getDataTable(list);
    }

    /**
     * 导出维修人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staff:export')")
    @Log(title = "维修人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaintenanceStaff maintenanceStaff)
    {
        List<MaintenanceStaff> list = maintenanceStaffService.selectMaintenanceStaffList(maintenanceStaff);
        ExcelUtil<MaintenanceStaff> util = new ExcelUtil<MaintenanceStaff>(MaintenanceStaff.class);
        util.exportExcel(response, list, "维修人员管理数据");
    }

    /**
     * 获取维修人员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staff:query')")
    @GetMapping(value = "/{staffId}")
    public AjaxResult getInfo(@PathVariable("staffId") Long staffId)
    {
        return success(maintenanceStaffService.selectMaintenanceStaffByStaffId(staffId));
    }

    /**
     * 新增维修人员管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staff:add')")
    @Log(title = "维修人员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaintenanceStaff maintenanceStaff)
    {
        return toAjax(maintenanceStaffService.insertMaintenanceStaff(maintenanceStaff));
    }

    /**
     * 修改维修人员管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staff:edit')")
    @Log(title = "维修人员管理", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody MaintenanceStaff maintenanceStaff)
    {
        return toAjax(maintenanceStaffService.updateMaintenanceStaff(maintenanceStaff));
    }

    /**
     * 删除维修人员管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:staff:remove')")
    @Log(title = "维修人员管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{staffIds}")
    public AjaxResult remove(@PathVariable Long[] staffIds)
    {
        return toAjax(maintenanceStaffService.deleteMaintenanceStaffByStaffIds(staffIds));
    }
}
