package com.fs.task.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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.task.domain.TaskMaterialInfo;
import com.fs.task.service.ITaskMaterialInfoService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 材料信息Controller
 * 
 * @author fs
 * @date 2026-01-04
 */
@RestController
@RequestMapping("/task/material")
public class TaskMaterialInfoController extends BaseController
{
    @Autowired
    private ITaskMaterialInfoService taskMaterialInfoService;

    /**
     * 查询材料信息列表
     */
    @PreAuthorize("@ss.hasPermi('task:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskMaterialInfo taskMaterialInfo)
    {
        startPage();
        List<TaskMaterialInfo> list = taskMaterialInfoService.selectTaskMaterialInfoList(taskMaterialInfo);
        return getDataTable(list);
    }

    /**
     * 导出材料信息列表
     */
    @PreAuthorize("@ss.hasPermi('task:material:export')")
    @Log(title = "材料信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TaskMaterialInfo taskMaterialInfo)
    {
        List<TaskMaterialInfo> list = taskMaterialInfoService.selectTaskMaterialInfoList(taskMaterialInfo);
        ExcelUtil<TaskMaterialInfo> util = new ExcelUtil<TaskMaterialInfo>(TaskMaterialInfo.class);
        return util.exportExcel(list, "材料信息数据");
    }

    /**
     * 获取材料信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:material:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(taskMaterialInfoService.selectTaskMaterialInfoById(id));
    }

    /**
     * 新增材料信息
     */
    @PreAuthorize("@ss.hasPermi('task:material:add')")
    @Log(title = "材料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskMaterialInfo taskMaterialInfo)
    {
        return toAjax(taskMaterialInfoService.insertTaskMaterialInfo(taskMaterialInfo));
    }

    /**
     * 修改材料信息
     */
    @PreAuthorize("@ss.hasPermi('task:material:edit')")
    @Log(title = "材料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskMaterialInfo taskMaterialInfo)
    {
        return toAjax(taskMaterialInfoService.updateTaskMaterialInfo(taskMaterialInfo));
    }

    /**
     * 删除材料信息
     */
    @PreAuthorize("@ss.hasPermi('task:material:remove')")
    @Log(title = "材料信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(taskMaterialInfoService.deleteTaskMaterialInfoByIds(ids));
    }
}
