package com.fs.watch.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.watch.domain.DeviceMaterialsType;
import com.fs.watch.service.DeviceMaterialsTypeService;
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 2024-08-27
 */
@RestController
@RequestMapping("/type")
public class DeviceMaterialsTypeController extends BaseController
{
    @Autowired
    private DeviceMaterialsTypeService deviceMaterialsTypeService;

    /**
     * 查询设备物料种类列表
     */
    @PreAuthorize("@ss.hasPermi('watchApi:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceMaterialsType deviceMaterialsType)
    {
        startPage();
        List<DeviceMaterialsType> list = deviceMaterialsTypeService.selectDeviceMaterialsTypeList(deviceMaterialsType);
        return getDataTable(list);
    }

    /**
     * 导出设备物料种类列表
     */
    @PreAuthorize("@ss.hasPermi('watchApi:type:export')")
    @Log(title = "设备物料种类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeviceMaterialsType deviceMaterialsType)
    {
        List<DeviceMaterialsType> list = deviceMaterialsTypeService.selectDeviceMaterialsTypeList(deviceMaterialsType);
        ExcelUtil<DeviceMaterialsType> util = new ExcelUtil<DeviceMaterialsType>(DeviceMaterialsType.class);
        return util.exportExcel(list, "设备物料种类数据");
    }

    /**
     * 获取设备物料种类详细信息
     */
    @PreAuthorize("@ss.hasPermi('watchApi:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(deviceMaterialsTypeService.selectDeviceMaterialsTypeById(id));
    }

    /**
     * 新增设备物料种类
     */
    @PreAuthorize("@ss.hasPermi('watchApi:type:add')")
    @Log(title = "设备物料种类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceMaterialsType deviceMaterialsType)
    {
        return toAjax(deviceMaterialsTypeService.insertDeviceMaterialsType(deviceMaterialsType));
    }

    /**
     * 修改设备物料种类
     */
    @PreAuthorize("@ss.hasPermi('watchApi:type:edit')")
    @Log(title = "设备物料种类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceMaterialsType deviceMaterialsType)
    {
        return toAjax(deviceMaterialsTypeService.updateDeviceMaterialsType(deviceMaterialsType));
    }

    /**
     * 删除设备物料种类
     */
    @PreAuthorize("@ss.hasPermi('watchApi:type:remove')")
    @Log(title = "设备物料种类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceMaterialsTypeService.deleteDeviceMaterialsTypeByIds(ids));
    }
}
