package com.fs.task.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.task.domain.TaskDeliveryInfo;
import com.fs.task.service.ITaskDeliveryInfoService;
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-04
 */
@RestController
@RequestMapping("/task/delivery")
public class TaskDeliveryInfoController extends BaseController {
    @Autowired
    private ITaskDeliveryInfoService taskDeliveryInfoService;

    /**
     * 查询交付物信息列表
     */
    @PreAuthorize("@ss.hasPermi('task:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskDeliveryInfo taskDeliveryInfo) {
        startPage();
        List<TaskDeliveryInfo> list = taskDeliveryInfoService.selectTaskDeliveryInfoList(taskDeliveryInfo);
        return getDataTable(list);
    }

    /**
     * 导出交付物信息列表
     */
    @PreAuthorize("@ss.hasPermi('task:delivery:export')")
    @Log(title = "交付物信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TaskDeliveryInfo taskDeliveryInfo) {
        List<TaskDeliveryInfo> list = taskDeliveryInfoService.selectTaskDeliveryInfoList(taskDeliveryInfo);
        ExcelUtil<TaskDeliveryInfo> util = new ExcelUtil<TaskDeliveryInfo>(TaskDeliveryInfo.class);
        return util.exportExcel(list, "交付物信息数据");
    }

    /**
     * 获取交付物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:delivery:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(taskDeliveryInfoService.selectTaskDeliveryInfoById(id));
    }

    /**
     * 新增交付物信息
     */
    @PreAuthorize("@ss.hasPermi('task:delivery:add')")
    @Log(title = "交付物信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskDeliveryInfo taskDeliveryInfo) {
        return toAjax(taskDeliveryInfoService.insertTaskDeliveryInfo(taskDeliveryInfo));
    }

    /**
     * 修改交付物信息
     */
    @PreAuthorize("@ss.hasPermi('task:delivery:edit')")
    @Log(title = "交付物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskDeliveryInfo taskDeliveryInfo) {
        return toAjax(taskDeliveryInfoService.updateTaskDeliveryInfo(taskDeliveryInfo));
    }

    /**
     * 删除交付物信息
     */
    @PreAuthorize("@ss.hasPermi('task:delivery:remove')")
    @Log(title = "交付物信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(taskDeliveryInfoService.deleteTaskDeliveryInfoByIds(ids));
    }



    /**
     * 通过任务类别与交付物编号查询出交付物信息
     */
    @PreAuthorize("@ss.hasPermi('task:delivery:query')")
    @GetMapping("/getDeliveryInfoByTaskTypeAndDeliveryNo")
    public AjaxResult getDeliveryInfoByTaskTypeAndDeliveryNo(TaskDeliveryInfo taskDeliveryInfo) {
        return AjaxResult.success(taskDeliveryInfoService.getDeliveryInfoByTaskTypeAndDeliveryNo(taskDeliveryInfo)
        );
    }
}
