package com.ygtx.gxt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ygtx.common.annotation.Log;
import com.ygtx.common.core.controller.BaseController;
import com.ygtx.common.core.domain.AjaxResult;
import com.ygtx.common.enums.BusinessType;
import com.ygtx.gxt.domain.GxtRepairOrder;
import com.ygtx.gxt.service.IGxtRepairOrderService;
import com.ygtx.common.utils.poi.ExcelUtil;
import com.ygtx.common.core.page.TableDataInfo;

/**
 * 维修工单Controller
 * 
 * @author ouyj
 * @date 2025-10-30
 */
@RestController
@RequestMapping("/gxt/repairOrder")
public class GxtRepairOrderController extends BaseController
{
    @Autowired
    private IGxtRepairOrderService gxtRepairOrderService;

    /**
     * 查询维修工单列表
     */
    @PreAuthorize("@ss.hasPermi('gxt:repairOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxtRepairOrder gxtRepairOrder)
    {
        startPage();
        List<GxtRepairOrder> list = gxtRepairOrderService.selectGxtRepairOrderList(gxtRepairOrder);
        return getDataTable(list);
    }

    /**
     * 导出维修工单列表
     */
    @PreAuthorize("@ss.hasPermi('gxt:repairOrder:export')")
    @Log(title = "维修工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxtRepairOrder gxtRepairOrder)
    {
        List<GxtRepairOrder> list = gxtRepairOrderService.selectGxtRepairOrderList(gxtRepairOrder);
        ExcelUtil<GxtRepairOrder> util = new ExcelUtil<GxtRepairOrder>(GxtRepairOrder.class);
        util.exportExcel(response, list, "维修工单数据");
    }

    /**
     * 获取维修工单详细信息
     */
    @PreAuthorize("@ss.hasPermi('gxt:repairOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gxtRepairOrderService.selectGxtRepairOrderById(id));
    }

    /**
     * 新增维修工单
     */
    @PreAuthorize("@ss.hasPermi('gxt:repairOrder:add')")
    @Log(title = "维修工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxtRepairOrder gxtRepairOrder)
    {
        return toAjax(gxtRepairOrderService.insertGxtRepairOrder(gxtRepairOrder));
    }

    /**
     * 修改维修工单
     */
    @PreAuthorize("@ss.hasPermi('gxt:repairOrder:edit')")
    @Log(title = "维修工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxtRepairOrder gxtRepairOrder)
    {
        return toAjax(gxtRepairOrderService.updateGxtRepairOrder(gxtRepairOrder));
    }

    /**
     * 删除维修工单
     */
    @PreAuthorize("@ss.hasPermi('gxt:repairOrder:remove')")
    @Log(title = "维修工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gxtRepairOrderService.deleteGxtRepairOrderByIds(ids));
    }
}
