package com.aucma.base.controller;

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

import com.aucma.common.core.page.TableDataInfo;
import com.aucma.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
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.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.base.domain.OrderBomInfo;
import com.aucma.base.service.IOrderBomInfoService;
import com.aucma.common.utils.poi.ExcelUtil;

/**
 * 订单BOMController
 *
 * @author Yinq
 * @date 2023-09-28
 */
@RestController
@RequestMapping("/base/orderBomInfo")
public class OrderBomInfoController extends BaseController {
    @Autowired
    private IOrderBomInfoService orderBomInfoService;

    /**
     * 查询订单BOM列表
     */
    @PreAuthorize("@ss.hasPermi('base:orderBomInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderBomInfo orderBomInfo) {
        startPage();
        List<OrderBomInfo> list = orderBomInfoService.selectOrderBomInfoList(orderBomInfo);
        return getDataTable(list);
    }

    /**
     * 查询订单BOM下拉框列表
     * @param orderBomInfo
     * @return
     */
    @GetMapping("/findOrderBomList")
    public AjaxResult findOrderBomList(OrderBomInfo orderBomInfo) {
        List<OrderBomInfo> list = orderBomInfoService.selectOrderBomInfoList(orderBomInfo);
        return success(list);
    }

    /**
     * 导出订单BOM列表
     */
    @PreAuthorize("@ss.hasPermi('base:orderBomInfo:export')")
    @Log(title = "订单BOM", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderBomInfo orderBomInfo) {
        List<OrderBomInfo> list = orderBomInfoService.selectOrderBomInfoList(orderBomInfo);
        ExcelUtil<OrderBomInfo> util = new ExcelUtil<OrderBomInfo>(OrderBomInfo.class);
        util.exportExcel(response, list, "订单BOM数据");
    }

    /**
     * 获取订单BOM详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:orderBomInfo:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(orderBomInfoService.selectOrderBomInfoByObjId(objId));
    }

    /**
     * 新增订单BOM
     */
    @PreAuthorize("@ss.hasPermi('base:orderBomInfo:add')")
    @Log(title = "订单BOM", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderBomInfo orderBomInfo) {
        orderBomInfo.setCreatedBy(getUsername());
        return toAjax(orderBomInfoService.insertOrderBomInfo(orderBomInfo));
    }

    /**
     * 修改订单BOM
     */
    @PreAuthorize("@ss.hasPermi('base:orderBomInfo:edit')")
    @Log(title = "订单BOM", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderBomInfo orderBomInfo) {
        orderBomInfo.setUpdatedBy(getUsername());
        orderBomInfo.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(orderBomInfoService.updateOrderBomInfo(orderBomInfo));
    }

    /**
     * 删除订单BOM
     */
    @PreAuthorize("@ss.hasPermi('base:orderBomInfo:remove')")
    @Log(title = "订单BOM", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(orderBomInfoService.deleteOrderBomInfoByObjIds(objIds));
    }
}
