package com.hw.mes.controller;

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

import com.hw.common.security.utils.SecurityUtils;
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.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.mes.domain.MesBaseMaterialType;
import com.hw.mes.service.IMesBaseMaterialTypeService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;

/**
 * 物料类型信息Controller
 * 
 * @author Yinq
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/baseMaterialType")
public class MesBaseMaterialTypeController extends BaseController
{
    @Autowired
    private IMesBaseMaterialTypeService mesBaseMaterialTypeService;

    /**
     * 查询物料类型信息列表
     */
    @RequiresPermissions("mes:baseMaterialType:list")
    @GetMapping("/list")
    public AjaxResult list(MesBaseMaterialType mesBaseMaterialType)
    {
        List<MesBaseMaterialType> list = mesBaseMaterialTypeService.selectMesBaseMaterialTypeList(mesBaseMaterialType);
        return success(list);
    }

    /**
     * 导出物料类型信息列表
     */
    @RequiresPermissions("mes:baseMaterialType:export")
    @Log(title = "物料类型信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesBaseMaterialType mesBaseMaterialType)
    {
        List<MesBaseMaterialType> list = mesBaseMaterialTypeService.selectMesBaseMaterialTypeList(mesBaseMaterialType);
        ExcelUtil<MesBaseMaterialType> util = new ExcelUtil<MesBaseMaterialType>(MesBaseMaterialType.class);
        util.exportExcel(response, list, "物料类型信息数据");
    }

    /**
     * 获取物料类型信息详细信息
     */
    @RequiresPermissions("mes:baseMaterialType:query")
    @GetMapping(value = "/{matrialTypeId}")
    public AjaxResult getInfo(@PathVariable("matrialTypeId") Long matrialTypeId)
    {
        return success(mesBaseMaterialTypeService.selectMesBaseMaterialTypeByMatrialTypeId(matrialTypeId));
    }

    /**
     * 新增物料类型信息
     */
    @RequiresPermissions("mes:baseMaterialType:add")
    @Log(title = "物料类型信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesBaseMaterialType mesBaseMaterialType)
    {
        mesBaseMaterialType.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesBaseMaterialTypeService.insertMesBaseMaterialType(mesBaseMaterialType));
    }

    /**
     * 修改物料类型信息
     */
    @RequiresPermissions("mes:baseMaterialType:edit")
    @Log(title = "物料类型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesBaseMaterialType mesBaseMaterialType)
    {
        mesBaseMaterialType.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesBaseMaterialTypeService.updateMesBaseMaterialType(mesBaseMaterialType));
    }

    /**
     * 删除物料类型信息
     */
    @RequiresPermissions("mes:baseMaterialType:remove")
    @Log(title = "物料类型信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{matrialTypeIds}")
    public AjaxResult remove(@PathVariable Long[] matrialTypeIds)
    {
        return toAjax(mesBaseMaterialTypeService.deleteMesBaseMaterialTypeByMatrialTypeIds(matrialTypeIds));
    }
}
