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.GxtRepairOrderFlow;
import com.ygtx.gxt.service.IGxtRepairOrderFlowService;
import com.ygtx.common.utils.poi.ExcelUtil;
import com.ygtx.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

/**
 * 维修工单流转记录Controller
 *
 * @author ouyj
 * @date 2025-10-30
 */
@RestController
@RequestMapping("/gxt/repairOrderFlow")
@Api(tags = "维修工单流转记录")
public class GxtRepairOrderFlowController extends BaseController
{
    @Autowired
    private IGxtRepairOrderFlowService gxtRepairOrderFlowService;

    /**
     * 查询维修工单流转记录列表
     */
    @ApiOperation("查询维修工单流转记录列表")
    @GetMapping("/list")
    public TableDataInfo list(GxtRepairOrderFlow gxtRepairOrderFlow)
    {
        startPage();
        List<GxtRepairOrderFlow> list = gxtRepairOrderFlowService.selectGxtRepairOrderFlowList(gxtRepairOrderFlow);
        return getDataTable(list);
    }

    /**
     * 导出维修工单流转记录列表
     */
    @Log(title = "维修工单流转记录", businessType = BusinessType.EXPORT)
    @ApiOperation("导出维修工单流转记录列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxtRepairOrderFlow gxtRepairOrderFlow)
    {
        List<GxtRepairOrderFlow> list = gxtRepairOrderFlowService.selectGxtRepairOrderFlowList(gxtRepairOrderFlow);
        ExcelUtil<GxtRepairOrderFlow> util = new ExcelUtil<GxtRepairOrderFlow>(GxtRepairOrderFlow.class);
        util.exportExcel(response, list, "维修工单流转记录数据");
    }

    /**
     * 获取维修工单流转记录详细信息
     */
    @ApiOperation("获取维修工单流转记录详细信息")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gxtRepairOrderFlowService.selectGxtRepairOrderFlowById(id));
    }

    /**
     * 新增维修工单流转记录
     */
    @Log(title = "维修工单流转记录", businessType = BusinessType.INSERT)
    @ApiOperation("新增维修工单流转记录")
    @PostMapping
    public AjaxResult add(@RequestBody GxtRepairOrderFlow gxtRepairOrderFlow)
    {
        return toAjax(gxtRepairOrderFlowService.insertGxtRepairOrderFlow(gxtRepairOrderFlow));
    }

    /**
     * 修改维修工单流转记录
     */
    @Log(title = "维修工单流转记录", businessType = BusinessType.UPDATE)
    @ApiOperation("修改维修工单流转记录")
    @PutMapping
    public AjaxResult edit(@RequestBody GxtRepairOrderFlow gxtRepairOrderFlow)
    {
        return toAjax(gxtRepairOrderFlowService.updateGxtRepairOrderFlow(gxtRepairOrderFlow));
    }

    /**
     * 删除维修工单流转记录
     */
    @Log(title = "维修工单流转记录", businessType = BusinessType.DELETE)
    @ApiOperation("删除维修工单流转记录")
    @ApiImplicitParam(name = "ids", value = "主键ID数组", required = true, dataType = "Long[]", paramType = "path", dataTypeClass = Long[].class)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gxtRepairOrderFlowService.deleteGxtRepairOrderFlowByIds(ids));
    }

    /**
     * 根据工单ID查询流转记录列表
     */
    @ApiOperation("根据工单ID查询流转记录列表")
    @ApiImplicitParam(name = "orderId", value = "工单ID", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping("/listByOrderId/{orderId}")
    public AjaxResult listByOrderId(@PathVariable("orderId") Long orderId)
    {
        GxtRepairOrderFlow gxtRepairOrderFlow = new GxtRepairOrderFlow();
        gxtRepairOrderFlow.setOrderId(orderId);
        List<GxtRepairOrderFlow> list = gxtRepairOrderFlowService.selectGxtRepairOrderFlowList(gxtRepairOrderFlow);
        return success(list);
    }

    /**
     * 记录工单流转
     */
    @Log(title = "维修工单流转记录", businessType = BusinessType.INSERT)
    @ApiOperation("记录工单流转")
    @PostMapping("/record")
    public AjaxResult record(@RequestBody GxtRepairOrderFlow gxtRepairOrderFlow)
    {
        return toAjax(gxtRepairOrderFlowService.insertGxtRepairOrderFlow(gxtRepairOrderFlow));
    }
}