package com.ruoyi.project.reliability.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.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.reliability.domain.TDeviceInventoryParts;
import com.ruoyi.project.reliability.service.ITDeviceInventoryPartsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 关键部件库存清单Controller
 *
 * @author ruoyi
 * @date 2022-07-07
 */
@RestController
@RequestMapping("/reliability/parts")
public class TDeviceInventoryPartsController extends BaseController
{
    @Autowired
    private ITDeviceInventoryPartsService tDeviceInventoryPartsService;

    /**
     * 查询关键部件库存清单列表
     */
    @PreAuthorize("@ss.hasPermi('reliability:parts:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDeviceInventoryParts tDeviceInventoryParts)
    {
        startPage();
        List<TDeviceInventoryParts> list = tDeviceInventoryPartsService.selectTDeviceInventoryPartsList(tDeviceInventoryParts);
        return getDataTable(list);
    }

    /**
     * 导出关键部件库存清单列表
     */
    @PreAuthorize("@ss.hasPermi('reliability:parts:export')")
    @Log(title = "关键部件库存清单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDeviceInventoryParts tDeviceInventoryParts)
    {
        List<TDeviceInventoryParts> list = tDeviceInventoryPartsService.selectTDeviceInventoryPartsList(tDeviceInventoryParts);
        ExcelUtil<TDeviceInventoryParts> util = new ExcelUtil<TDeviceInventoryParts>(TDeviceInventoryParts.class);
        return util.exportExcel(list, "parts");
    }

    /**
     * 获取关键部件库存清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('reliability:parts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDeviceInventoryPartsService.selectTDeviceInventoryPartsById(id));
    }

    /**
     * 新增关键部件库存清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:parts:add')")
    @Log(title = "关键部件库存清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDeviceInventoryParts tDeviceInventoryParts)
    {
        return toAjax(tDeviceInventoryPartsService.insertTDeviceInventoryParts(tDeviceInventoryParts));
    }

    /**
     * 修改关键部件库存清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:parts:edit')")
    @Log(title = "关键部件库存清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDeviceInventoryParts tDeviceInventoryParts)
    {
        return toAjax(tDeviceInventoryPartsService.updateTDeviceInventoryParts(tDeviceInventoryParts));
    }

    /**
     * 删除关键部件库存清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:parts:remove')")
    @Log(title = "关键部件库存清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDeviceInventoryPartsService.deleteTDeviceInventoryPartsByIds(ids));
    }
}
