package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.AppGoodsType;
import com.ruoyi.app.service.IAppGoodsTypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物料类别管理Controller
 *
 * @author ruoyi
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/system/goodsType")
public class AppGoodsTypeController extends BaseController
{
    @Autowired
    private IAppGoodsTypeService appGoodsTypeService;

    /**
     * 查询物料类别管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public AjaxResult list(AppGoodsType appGoodsType)
    {
        List<AppGoodsType> list = appGoodsTypeService.selectAppGoodsTypeList(appGoodsType);
        return success(list);
    }

    /**
     * 导出物料类别管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "物料类别管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppGoodsType appGoodsType)
    {
        List<AppGoodsType> list = appGoodsTypeService.selectAppGoodsTypeList(appGoodsType);
        ExcelUtil<AppGoodsType> util = new ExcelUtil<AppGoodsType>(AppGoodsType.class);
        util.exportExcel(response, list, "物料类别管理数据");
    }

    /**
     * 获取物料类别管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(appGoodsTypeService.selectAppGoodsTypeByTypeId(typeId));
    }

    /**
     * 新增物料类别管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "物料类别管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppGoodsType appGoodsType)
    {
        return toAjax(appGoodsTypeService.insertAppGoodsType(appGoodsType));
    }

    /**
     * 修改物料类别管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "物料类别管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppGoodsType appGoodsType)
    {
        return toAjax(appGoodsTypeService.updateAppGoodsType(appGoodsType));
    }

    /**
     * 删除物料类别管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "物料类别管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(appGoodsTypeService.deleteAppGoodsTypeByTypeIds(typeIds));
    }
}
