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.MaterialType;
import com.zg.project.information.service.IMaterialTypeService;
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-05-27
 */
@RestController
@RequestMapping("/information/materialtype")
public class MaterialTypeController extends BaseController
{
    @Autowired
    private IMaterialTypeService materialTypeService;

    /**
     * 查询物资类型列表
     */
    @PreAuthorize("@ss.hasPermi('information:materialtype:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialType materialType)
    {
        startPage();
        List<MaterialType> list = materialTypeService.selectMaterialTypeList(materialType);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('information:materialtype:list')")
    @GetMapping("/getAll")
    public AjaxResult getAll()
    {
        List<MaterialType> list = materialTypeService.selectMaterialTypeList(new MaterialType());
        return success(list);
    }

    /**
     * 导出物资类型列表
     */
    @PreAuthorize("@ss.hasPermi('information:materialtype:export')")
    @Log(title = "物资类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialType materialType)
    {
        List<MaterialType> list = materialTypeService.selectMaterialTypeList(materialType);
        ExcelUtil<MaterialType> util = new ExcelUtil<MaterialType>(MaterialType.class);
        util.exportExcel(response, list, "物资类型数据");
    }

    /**
     * 获取物资类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:materialtype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(materialTypeService.selectMaterialTypeById(id));
    }

    /**
     * 新增物资类型
     */
    @PreAuthorize("@ss.hasPermi('information:materialtype:add')")
    @Log(title = "物资类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialType materialType)
    {
        return toAjax(materialTypeService.insertMaterialType(materialType));
    }

    /**
     * 修改物资类型
     */
    @PreAuthorize("@ss.hasPermi('information:materialtype:edit')")
    @Log(title = "物资类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialType materialType)
    {
        return toAjax(materialTypeService.updateMaterialType(materialType));
    }

    /**
     * 删除物资类型
     */
    @PreAuthorize("@ss.hasPermi('information:materialtype:remove')")
    @Log(title = "物资类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(materialTypeService.deleteMaterialTypeByIds(ids));
    }
}
