package com.hw.mes.controller;

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

import com.hw.common.security.annotation.InnerAuth;
import com.hw.mes.api.domain.vo.MesBaseMaterialInfoVo;
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.api.domain.MesBaseMaterialInfo;
import com.hw.mes.service.IMesBaseMaterialInfoService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.page.TableDataInfo;

/**
 * 物料信息Controller
 *
 * @author xins
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/materialinfo")
public class MesBaseMaterialInfoController extends BaseController
{
    @Autowired
    private IMesBaseMaterialInfoService mesBaseMaterialInfoService;

    /**
     * 查询物料信息列表
     */
    @RequiresPermissions("mes:materialinfo:list")
    @GetMapping("/list")
    public TableDataInfo list(MesBaseMaterialInfo mesBaseMaterialInfo)
    {
        startPage();
        List<MesBaseMaterialInfo> list = mesBaseMaterialInfoService.selectMesBaseMaterialInfoList(mesBaseMaterialInfo);
        return getDataTable(list);
    }

    /**
     * 导出物料信息列表
     */
    @RequiresPermissions("mes:materialinfo:export")
    @Log(title = "物料信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesBaseMaterialInfo mesBaseMaterialInfo)
    {
        List<MesBaseMaterialInfo> list = mesBaseMaterialInfoService.selectMesBaseMaterialInfoList(mesBaseMaterialInfo);
        ExcelUtil<MesBaseMaterialInfo> util = new ExcelUtil<MesBaseMaterialInfo>(MesBaseMaterialInfo.class);
        util.exportExcel(response, list, "物料信息数据");
    }

    /**
     * 获取物料信息详细信息
     */
    @RequiresPermissions("mes:materialinfo:query")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return success(mesBaseMaterialInfoService.selectMesBaseMaterialInfoByMaterialId(materialId));
    }

    /**
     * 新增物料信息
     */
    @RequiresPermissions("mes:materialinfo:add")
    @Log(title = "物料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesBaseMaterialInfo mesBaseMaterialInfo)
    {
        return toAjax(mesBaseMaterialInfoService.insertMesBaseMaterialInfo(mesBaseMaterialInfo));
    }

    /**
     * 修改物料信息
     */
    @RequiresPermissions("mes:materialinfo:edit")
    @Log(title = "物料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesBaseMaterialInfo mesBaseMaterialInfo)
    {
        return toAjax(mesBaseMaterialInfoService.updateMesBaseMaterialInfo(mesBaseMaterialInfo));
    }

    /**
     * 删除物料信息
     */
    @RequiresPermissions("mes:materialinfo:remove")
    @Log(title = "物料信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(mesBaseMaterialInfoService.deleteMesBaseMaterialInfoByMaterialIds(materialIds));
    }



    /**
     * 根据物料ID列表查询物料信息列表
     */
    @InnerAuth
    @PostMapping("/getMaterialsByMaterialIds")
    public AjaxResult getMaterialsByMaterialIds(@RequestBody MesBaseMaterialInfoVo mesBaseMaterialInfo)
    {
        startPage();
        List<MesBaseMaterialInfo> list = mesBaseMaterialInfoService.selectMesBaseMaterialInfoListByMaterialIds(mesBaseMaterialInfo.getMaterialIds());
        return success(list);
    }

}
