package com.fs.provider.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.provider.domain.ServiceOrderTaskRel;
import com.fs.provider.service.IServiceOrderTaskRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务单-任务关联Controller
 * 
 * @author fs
 * @date 2026-01-26
 */
@RestController
@RequestMapping("/service/rel")
public class ServiceOrderTaskRelController extends BaseController
{
    @Autowired
    private IServiceOrderTaskRelService serviceOrderTaskRelService;

    /**
     * 查询服务单-任务关联列表
     */
    @PreAuthorize("@ss.hasPermi('service:rel:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceOrderTaskRel serviceOrderTaskRel)
    {
        startPage();
        List<ServiceOrderTaskRel> list = serviceOrderTaskRelService.selectServiceOrderTaskRelList(serviceOrderTaskRel);
        return getDataTable(list);
    }

    /**
     * 导出服务单-任务关联列表
     */
    @PreAuthorize("@ss.hasPermi('service:rel:export')")
    @Log(title = "服务单-任务关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ServiceOrderTaskRel serviceOrderTaskRel)
    {
        List<ServiceOrderTaskRel> list = serviceOrderTaskRelService.selectServiceOrderTaskRelList(serviceOrderTaskRel);
        ExcelUtil<ServiceOrderTaskRel> util = new ExcelUtil<ServiceOrderTaskRel>(ServiceOrderTaskRel.class);
        return util.exportExcel(list, "服务单-任务关联数据");
    }

    /**
     * 获取服务单-任务关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:rel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(serviceOrderTaskRelService.selectServiceOrderTaskRelById(id));
    }

    /**
     * 新增服务单-任务关联
     */
    @PreAuthorize("@ss.hasPermi('service:rel:add')")
    @Log(title = "服务单-任务关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceOrderTaskRel serviceOrderTaskRel)
    {
        return toAjax(serviceOrderTaskRelService.insertServiceOrderTaskRel(serviceOrderTaskRel));
    }

    /**
     * 修改服务单-任务关联
     */
    @PreAuthorize("@ss.hasPermi('service:rel:edit')")
    @Log(title = "服务单-任务关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceOrderTaskRel serviceOrderTaskRel)
    {
        return toAjax(serviceOrderTaskRelService.updateServiceOrderTaskRel(serviceOrderTaskRel));
    }

    /**
     * 删除服务单-任务关联
     */
    @PreAuthorize("@ss.hasPermi('service:rel:remove')")
    @Log(title = "服务单-任务关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceOrderTaskRelService.deleteServiceOrderTaskRelByIds(ids));
    }
}
