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.GxtWorkOrderPerson;
import com.ygtx.gxt.service.IGxtWorkOrderPersonService;
import com.ygtx.common.utils.poi.ExcelUtil;

/**
 * 工单工作组员Controller
 *
 * @author ygtx
 * @date 2025-10-29
 */
@RestController
@RequestMapping("/gxt/workOrderPerson")
public class GxtWorkOrderPersonController extends BaseController
{
    @Autowired
    private IGxtWorkOrderPersonService gxtWorkOrderPersonService;

    /**
     * 查询工单工作组员列表
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:list')")
    @GetMapping("/list")
    public AjaxResult list(GxtWorkOrderPerson gxtWorkOrderPerson)
    {
        List<GxtWorkOrderPerson> list = gxtWorkOrderPersonService.selectGxtWorkOrderPersonList(gxtWorkOrderPerson);
        return success(list);
    }

    /**
     * 根据工单ID查询工作组员列表
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:query')")
    @GetMapping("/listByOrderId/{orderId}")
    public AjaxResult listByOrderId(@PathVariable Long orderId)
    {
        List<GxtWorkOrderPerson> list = gxtWorkOrderPersonService.selectGxtWorkOrderPersonByOrderId(orderId);
        return success(list);
    }

    /**
     * 导出工单工作组员列表
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:export')")
    @Log(title = "工单工作组员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GxtWorkOrderPerson gxtWorkOrderPerson)
    {
        List<GxtWorkOrderPerson> list = gxtWorkOrderPersonService.selectGxtWorkOrderPersonList(gxtWorkOrderPerson);
        ExcelUtil<GxtWorkOrderPerson> util = new ExcelUtil<GxtWorkOrderPerson>(GxtWorkOrderPerson.class);
        return util.exportExcel(list, "工单工作组员");
    }

    /**
     * 获取工单工作组员详细信息
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(gxtWorkOrderPersonService.selectGxtWorkOrderPersonById(id));
    }

    /**
     * 新增工单工作组员
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:add')")
    @Log(title = "工单工作组员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxtWorkOrderPerson gxtWorkOrderPerson)
    {
        return toAjax(gxtWorkOrderPersonService.insertGxtWorkOrderPerson(gxtWorkOrderPerson));
    }

    /**
     * 批量新增工单工作组员
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:add')")
    @Log(title = "工单工作组员", businessType = BusinessType.INSERT)
    @PostMapping("/insertBatch/{orderId}/{orderCode}")
    public AjaxResult insertBatch(@PathVariable Long orderId, @PathVariable String orderCode, @RequestBody List<GxtWorkOrderPerson> personList)
    {
        return toAjax(gxtWorkOrderPersonService.insertBatchGxtWorkOrderPerson(orderId, orderCode, personList));
    }

    /**
     * 修改工单工作组员
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:edit')")
    @Log(title = "工单工作组员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxtWorkOrderPerson gxtWorkOrderPerson)
    {
        return toAjax(gxtWorkOrderPersonService.updateGxtWorkOrderPerson(gxtWorkOrderPerson));
    }

    /**
     * 删除工单工作组员
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:remove')")
    @Log(title = "工单工作组员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(gxtWorkOrderPersonService.deleteGxtWorkOrderPersonById(id));
    }

    /**
     * 批量删除工单工作组员
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:remove')")
    @Log(title = "工单工作组员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult removeByIds(@PathVariable Long[] ids)
    {
        return toAjax(gxtWorkOrderPersonService.deleteGxtWorkOrderPersonByIds(ids));
    }

    /**
     * 根据工单ID删除工作组员
     */
    @PreAuthorize("@ss.hasPermi('worklog:Gxt:person:remove')")
    @Log(title = "工单工作组员", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeByOrderId/{orderId}")
    public AjaxResult removeByOrderId(@PathVariable Long orderId)
    {
        return toAjax(gxtWorkOrderPersonService.deleteGxtWorkOrderPersonByOrderId(orderId));
    }
}
