package com.hw.mes.controller;

import java.util.List;
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.MesMaterialBom;
import com.hw.mes.service.IMesMaterialBomService;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;

/**
 * 物料BOM信息Controller
 * 
 * @author Yinq
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/materialBom")
public class MesMaterialBomController extends BaseController
{
    @Autowired
    private IMesMaterialBomService mesMaterialBomService;

    /**
     * 查询物料BOM信息列表
     */
    @RequiresPermissions("mes:materialBom:list")
    @GetMapping("/list")
    public AjaxResult list(MesMaterialBom mesMaterialBom)
    {
        List<MesMaterialBom> list = mesMaterialBomService.selectMesMaterialBomList(mesMaterialBom);
        return success(list);
    }

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

    /**
     * 获取物料BOM信息详细信息
     */
    @RequiresPermissions("mes:materialBom:query")
    @GetMapping(value = "/{materialBomId}")
    public AjaxResult getInfo(@PathVariable("materialBomId") Long materialBomId)
    {
        return success(mesMaterialBomService.selectMesMaterialBomByMaterialBomId(materialBomId));
    }

    /**
     * 新增物料BOM信息
     */
    @RequiresPermissions("mes:materialBom:add")
    @Log(title = "物料BOM信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesMaterialBom mesMaterialBom)
    {
        mesMaterialBom.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesMaterialBomService.insertMesMaterialBom(mesMaterialBom));
    }

    /**
     * 修改物料BOM信息
     */
    @RequiresPermissions("mes:materialBom:edit")
    @Log(title = "物料BOM信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesMaterialBom mesMaterialBom)
    {
        mesMaterialBom.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        return toAjax(mesMaterialBomService.updateMesMaterialBom(mesMaterialBom));
    }

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

    /**
     * 查询物料BOM版本列表
     */
    @GetMapping(value = "/getMaterialVisionList/{materialId}")
    public AjaxResult getMaterialVisionList(@PathVariable("materialId") Long materialId)
    {
        return success(mesMaterialBomService.getMaterialVisionList(materialId));
    }

}
