package com.xinda.itsm.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.xinda.common.annotation.Log;
import com.xinda.common.core.controller.BaseController;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.enums.BusinessType;
import com.xinda.itsm.domain.RepairOrder;
import com.xinda.itsm.service.IRepairOrderService;
import com.xinda.common.utils.poi.ExcelUtil;
import com.xinda.common.core.page.TableDataInfo;

/**
 * 维修工单Controller
 *
 * @author kerwincui
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/itsm/order")
@Api(tags = "维修工单")
public class RepairOrderController extends BaseController
{
    @Autowired
    private IRepairOrderService repairOrderService;

/**
 * 查询维修工单列表
 */
@PreAuthorize("@ss.hasPermi('itsm:order:list')")
@GetMapping("/list")
@ApiOperation("查询维修工单列表")
    public TableDataInfo list(RepairOrder repairOrder)
    {
        startPage();
        List<RepairOrder> list = repairOrderService.selectRepairOrderList(repairOrder);
        return getDataTable(list);
    }

    /**
     * 导出维修工单列表
     */
    @ApiOperation("导出维修工单列表")
    @PreAuthorize("@ss.hasPermi('itsm:order:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairOrder repairOrder)
    {
        List<RepairOrder> list = repairOrderService.selectRepairOrderList(repairOrder);
        ExcelUtil<RepairOrder> util = new ExcelUtil<RepairOrder>(RepairOrder.class);
        util.exportExcel(response, list, "维修工单数据");
    }

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

    /**
     * 新增维修工单
     */
    @PreAuthorize("@ss.hasPermi('itsm:order:add')")
    @PostMapping
    @ApiOperation("新增维修工单")
    public AjaxResult add(@RequestBody RepairOrder repairOrder)
    {
        return toAjax(repairOrderService.insertRepairOrder(repairOrder));
    }

    /**
     * 修改维修工单
     */
    @PreAuthorize("@ss.hasPermi('itsm:order:edit')")
    @PutMapping
    @ApiOperation("修改维修工单")
    public AjaxResult edit(@RequestBody RepairOrder repairOrder)
    {
        return toAjax(repairOrderService.updateRepairOrder(repairOrder));
    }

    /**
     * 删除维修工单
     */
    @PreAuthorize("@ss.hasPermi('itsm:order:remove')")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除维修工单")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(repairOrderService.deleteRepairOrderByIds(ids));
    }
}
