package com.ruoyi.web.controller.warehouse.warehouseBusiness;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.warehouseBusiness.domain.TEnclosure;
import com.ruoyi.warehouseBusiness.service.ITEnclosureService;
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 ruoyi
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/warehouseBusiness/enclosure")
public class TEnclosureController extends BaseController {
    @Autowired
    private ITEnclosureService tEnclosureService;

    /**
     * 查询附件列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:enclosure:list')")
    @GetMapping("/list")
    public TableDataInfo list(TEnclosure tEnclosure) {
        startPage();
        List<TEnclosure> list = tEnclosureService.selectTEnclosureList(tEnclosure);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:enclosure:export')")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TEnclosure tEnclosure) {
        List<TEnclosure> list = tEnclosureService.selectTEnclosureList(tEnclosure);
        ExcelUtil<TEnclosure> util = new ExcelUtil<TEnclosure>(TEnclosure.class);
        return util.exportExcel(list, "enclosure");
    }

    /**
     * 获取附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:enclosure:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tEnclosureService.selectTEnclosureById(fId));
    }

    /**
     * 新增附件
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:enclosure:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TEnclosure tEnclosure) {
        return toAjax(tEnclosureService.insertTEnclosure(tEnclosure));
    }

    /**
     * 修改附件
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:enclosure:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TEnclosure tEnclosure) {
        return toAjax(tEnclosureService.updateTEnclosure(tEnclosure));
    }

    /**
     * 删除附件
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:enclosure:remove')")
    @Log(title = "附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(tEnclosureService.deleteTEnclosureByIds(fIds));
    }
}
