package com.jjt.order.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.jjt.common.annotation.Log;
import com.jjt.common.core.controller.BaseController;
import com.jjt.common.core.domain.AjaxResult;
import com.jjt.common.enums.BusinessType;
import com.jjt.order.domain.TwinBom;
import com.jjt.order.service.ITwinBomService;
import com.jjt.common.utils.poi.ExcelUtil;
import com.jjt.common.core.page.TableDataInfo;

/**
 * 物料管理Controller
 *
 * @author wukai
 * @date 2025-01-16
 */
@Api(tags="物料管理")
@RestController
@RequestMapping("/order/bom")
public class TwinBomController extends BaseController{
    @Resource
    private ITwinBomService twinBomService;

    /**
     * 查询物料管理列表
     */
    @ApiOperation("查询物料管理列表")
    @PreAuthorize("@ss.hasPermi('order:bom:list')")
    @GetMapping("/list")
    public TableDataInfo list(TwinBom twinBom)
    {
        startPage();
        List<TwinBom> list = twinBomService.selectTwinBomList(twinBom);
        return getDataTable(list);
    }

    /**
     * 导出物料管理列表
     */
    @ApiOperation("导出物料管理列表")
    @PreAuthorize("@ss.hasPermi('order:bom:export')")
    @Log(title = "物料管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TwinBom twinBom)
    {
        List<TwinBom> list = twinBomService.selectTwinBomList(twinBom);
        ExcelUtil<TwinBom> util = new ExcelUtil<TwinBom>(TwinBom.class);
        util.exportExcel(response, list, "物料管理数据");
    }

    /**
     * 获取物料管理详细信息
     */
    @ApiOperation("获取物料管理详细信息")
    @PreAuthorize("@ss.hasPermi('order:bom:query')")
    @GetMapping(value = "/{bomId}")
    public AjaxResult getInfo(@PathVariable("bomId") Long bomId)
    {
        return success(twinBomService.selectTwinBomByBomId(bomId));
    }

    /**
     * 新增物料管理
     */
    @ApiOperation("新增物料管理")
    @PreAuthorize("@ss.hasPermi('order:bom:add')")
    @Log(title = "物料管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TwinBom twinBom)
    {
        return toAjax(twinBomService.insertTwinBom(twinBom));
    }

    /**
     * 修改物料管理
     */
    @ApiOperation("修改物料管理")
    @PreAuthorize("@ss.hasPermi('order:bom:edit')")
    @Log(title = "物料管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TwinBom twinBom)
    {
        return toAjax(twinBomService.updateTwinBom(twinBom));
    }

    /**
     * 删除物料管理
     */
    @ApiOperation("删除物料管理")
    @PreAuthorize("@ss.hasPermi('order:bom:remove')")
    @Log(title = "物料管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bomIds}")
    public AjaxResult remove(@PathVariable Long[] bomIds)
    {
        return toAjax(twinBomService.deleteTwinBomByBomIds(bomIds));
    }
}
