package com.ygtx.gxt.controller;

import java.util.List;
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.GxtWorkOrderFlow;
import com.ygtx.gxt.service.IGxtWorkOrderFlowService;
import com.ygtx.common.utils.poi.ExcelUtil;

/**
 * 维修工单流转记录Controller
 *
 * @author ygtx
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/gxt/workOrderFlow")
public class GxtWorkOrderFlowController extends BaseController
{
    @Autowired
    private IGxtWorkOrderFlowService gxtWorkOrderFlowService;

    /**
     * 查询维修工单流转记录列表
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:flow:list')")
    @GetMapping("/list")
    public AjaxResult list(GxtWorkOrderFlow gxtWorkOrderFlow)
    {
        List<GxtWorkOrderFlow> list = gxtWorkOrderFlowService.selectGxtWorkOrderFlowList(gxtWorkOrderFlow);
        return success(list);
    }

    /**
     * 根据工单ID查询流转记录列表
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:flow:query')")
    @GetMapping("/listByOrderId/{orderId}")
    public AjaxResult listByOrderId(@PathVariable Long orderId)
    {
        List<GxtWorkOrderFlow> list = gxtWorkOrderFlowService.selectGxtWorkOrderFlowByOrderId(orderId);
        return success(list);
    }

    /**
     * 导出维修工单流转记录列表
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:flow:export')")
    @Log(title = "维修工单流转记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GxtWorkOrderFlow gxtWorkOrderFlow)
    {
        List<GxtWorkOrderFlow> list = gxtWorkOrderFlowService.selectGxtWorkOrderFlowList(gxtWorkOrderFlow);
        ExcelUtil<GxtWorkOrderFlow> util = new ExcelUtil<GxtWorkOrderFlow>(GxtWorkOrderFlow.class);
        return util.exportExcel(list, "维修工单流转记录");
    }

    /**
     * 获取维修工单流转记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:flow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(gxtWorkOrderFlowService.selectGxtWorkOrderFlowById(id));
    }

    /**
     * 新增维修工单流转记录
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:flow:add')")
    @Log(title = "维修工单流转记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxtWorkOrderFlow gxtWorkOrderFlow)
    {
        return toAjax(gxtWorkOrderFlowService.insertGxtWorkOrderFlow(gxtWorkOrderFlow));
    }

    /**
     * 修改维修工单流转记录
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:flow:edit')")
    @Log(title = "维修工单流转记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxtWorkOrderFlow gxtWorkOrderFlow)
    {
        return toAjax(gxtWorkOrderFlowService.updateGxtWorkOrderFlow(gxtWorkOrderFlow));
    }

    /**
     * 删除维修工单流转记录
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:flow:remove')")
    @Log(title = "维修工单流转记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(gxtWorkOrderFlowService.deleteGxtWorkOrderFlowById(id));
    }

    /**
     * 批量删除维修工单流转记录
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:flow:remove')")
    @Log(title = "维修工单流转记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult removeByIds(@PathVariable Long[] ids)
    {
        return toAjax(gxtWorkOrderFlowService.deleteGxtWorkOrderFlowByIds(ids));
    }
}
