package com.xtd.project.system.controller;

import java.util.List;

import com.xtd.project.system.domain.vo.TreeNodeVo;
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.xtd.framework.aspectj.lang.annotation.Log;
import com.xtd.framework.aspectj.lang.enums.BusinessType;
import com.xtd.project.system.domain.DbMateriel;
import com.xtd.project.system.service.IDbMaterielService;
import com.xtd.framework.web.controller.BaseController;
import com.xtd.framework.web.domain.AjaxResult;
import com.xtd.common.utils.poi.ExcelUtil;
import com.xtd.framework.web.page.TableDataInfo;

/**
 * 物料Controller
 *
 * @author xtd
 * @date 2020-04-07
 */
@RestController
@RequestMapping("/system/materiel")
public class DbMaterielController extends BaseController
{
    @Autowired
    private IDbMaterielService dbMaterielService;

    /**
     * 查询物料列表
     */
    @PreAuthorize("@ss.hasPermi('system:materiel:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbMateriel dbMateriel)
    {
        startPage();
        List<DbMateriel> list = dbMaterielService.selectDbMaterielList(dbMateriel);
        return getDataTable(list);
    }
    /**
     * 查询物料列表
     */
    @GetMapping("/tree/list")
    public AjaxResult truelist()
    {
        List<TreeNodeVo> list = dbMaterielService.treelist();

        return AjaxResult.success(list);
    }


    /**
     * 导出物料列表
     */
    @PreAuthorize("@ss.hasPermi('system:materiel:export')")
    @Log(title = "物料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DbMateriel dbMateriel)
    {
        List<DbMateriel> list = dbMaterielService.selectDbMaterielList(dbMateriel);
        ExcelUtil<DbMateriel> util = new ExcelUtil<DbMateriel>(DbMateriel.class);
        return util.exportExcel(list, "materiel");
    }

    /**
     * 获取物料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:materiel:query')")
    @GetMapping(value = "/{mId}")
    public AjaxResult getInfo(@PathVariable("mId") Long mId)
    {
        return AjaxResult.success(dbMaterielService.selectDbMaterielById(mId));
    }

    /**
     * 新增物料
     */
    @PreAuthorize("@ss.hasPermi('system:materiel:add')")
    @Log(title = "物料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbMateriel dbMateriel)
    {
        return toAjax(dbMaterielService.insertDbMateriel(dbMateriel));
    }

    /**
     * 修改物料
     */
    @PreAuthorize("@ss.hasPermi('system:materiel:edit')")
    @Log(title = "物料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbMateriel dbMateriel)
    {
        return toAjax(dbMaterielService.updateDbMateriel(dbMateriel));
    }

    /**
     * 删除物料
     */
    @PreAuthorize("@ss.hasPermi('system:materiel:remove')")
    @Log(title = "物料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mIds}")
    public AjaxResult remove(@PathVariable Long[] mIds)
    {
        return toAjax(dbMaterielService.deleteDbMaterielByIds(mIds));
    }
}
