package com.inspur.web.controller.work;

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

import com.inspur.common.annotation.Anonymous;
import com.inspur.domain.ElevatorWorkOrder;
import com.inspur.service.IElevatorWorkOrderService;
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.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.enums.BusinessType;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.common.core.page.TableDataInfo;

/**
 * 电梯工单信息Controller
 *
 * @author inspur
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/work/workOrder")
public class ElevatorWorkOrderController extends BaseController
{
    @Autowired
    private IElevatorWorkOrderService elevatorWorkOrderService;

    /**
     * 查询电梯工单信息列表
     */
    //@PreAuthorize("@ss.hasPermi('work:workOrder:list')")
    @GetMapping("/list")
    @Anonymous
    @ApiOperation("获取工单列表")
    public TableDataInfo list(ElevatorWorkOrder elevatorWorkOrder)
    {
        startPage();
        List<ElevatorWorkOrder> list = elevatorWorkOrderService.selectElevatorWorkOrderList(elevatorWorkOrder);
        return getDataTable(list);
    }

    /**
     * 导出电梯工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('work:workOrder:export')")
    @Log(title = "电梯工单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElevatorWorkOrder elevatorWorkOrder)
    {
        List<ElevatorWorkOrder> list = elevatorWorkOrderService.selectElevatorWorkOrderList(elevatorWorkOrder);
        ExcelUtil<ElevatorWorkOrder> util = new ExcelUtil<ElevatorWorkOrder>(ElevatorWorkOrder.class);
        util.exportExcel(response, list, "电梯工单信息数据");
    }

    /**
     * 获取电梯工单信息详细信息
     */
    // @PreAuthorize("@ss.hasPermi('work:workOrder:query')")
    @GetMapping(value = "/{id}")
    @Anonymous
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(elevatorWorkOrderService.selectElevatorWorkOrderById(id));
    }

    /**
     * 新增电梯工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:workOrder:add')")
    @Log(title = "电梯工单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElevatorWorkOrder elevatorWorkOrder)
    {
        return toAjax(elevatorWorkOrderService.insertElevatorWorkOrder(elevatorWorkOrder));
    }

    /**
     * 修改电梯工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:workOrder:edit')")
    @Log(title = "电梯工单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElevatorWorkOrder elevatorWorkOrder)
    {
        return toAjax(elevatorWorkOrderService.updateElevatorWorkOrder(elevatorWorkOrder));
    }

    /**
     * 删除电梯工单信息
     */
    // @PreAuthorize("@ss.hasPermi('work:workOrder:remove')")
    @Log(title = "电梯工单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @Anonymous
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elevatorWorkOrderService.deleteElevatorWorkOrderByIds(ids));
    }
}
