package com.zg.project.information.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.zg.framework.aspectj.lang.annotation.Log;
import com.zg.framework.aspectj.lang.enums.BusinessType;
import com.zg.project.information.domain.Mtd;
import com.zg.project.information.service.IMtdService;
import com.zg.framework.web.controller.BaseController;
import com.zg.framework.web.domain.AjaxResult;
import com.zg.common.utils.poi.ExcelUtil;
import com.zg.framework.web.page.TableDataInfo;

/**
 * 物料字典Controller
 * 
 * @author zg
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/information/mtd")
public class MtdController extends BaseController
{
    @Autowired
    private IMtdService mtdService;

    /**
     * 查询物料字典列表
     */
    @PreAuthorize("@ss.hasPermi('information:mtd:list')")
    @GetMapping("/list")
    public TableDataInfo list(Mtd mtd)
    {
        startPage();
        List<Mtd> list = mtdService.selectMtdList(mtd);
        return getDataTable(list);
    }

    /**
     * 导出物料字典列表
     */
    @PreAuthorize("@ss.hasPermi('information:mtd:export')")
    @Log(title = "物料字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Mtd mtd)
    {
        List<Mtd> list = mtdService.selectMtdList(mtd);
        ExcelUtil<Mtd> util = new ExcelUtil<Mtd>(Mtd.class);
        util.exportExcel(response, list, "物料字典数据");
    }

    /**
     * 获取物料字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:mtd:query')")
    @GetMapping(value = "/{Id}")
    public AjaxResult getInfo(@PathVariable("Id") Long Id)
    {
        return success(mtdService.selectMtdById(Id));
    }

    /**
     * 新增物料字典
     */
    @PreAuthorize("@ss.hasPermi('information:mtd:add')")
    @Log(title = "物料字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Mtd mtd)
    {
        return toAjax(mtdService.insertMtd(mtd));
    }

    /**
     * 修改物料字典
     */
    @PreAuthorize("@ss.hasPermi('information:mtd:edit')")
    @Log(title = "物料字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Mtd mtd)
    {
        return toAjax(mtdService.updateMtd(mtd));
    }

    /**
     * 删除物料字典
     */
    @PreAuthorize("@ss.hasPermi('information:mtd:remove')")
    @Log(title = "物料字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable Long[] Ids)
    {
        return toAjax(mtdService.deleteMtdByIds(Ids));
    }
}
