package com.hw.dms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.dms.domain.DmsBaseDeviceBom;
import com.hw.dms.service.IDmsBaseDeviceBomService;
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 xins
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/bom")
public class DmsBaseDeviceBomController extends BaseController
{
    @Autowired
    private IDmsBaseDeviceBomService dmsBaseDeviceBomService;

    /**
     * 查询设备BOM信息列表
     */
    @RequiresPermissions("dms:bom:list")
    @GetMapping("/list")
    public AjaxResult list(DmsBaseDeviceBom dmsBaseDeviceBom)
    {
        List<DmsBaseDeviceBom> list = dmsBaseDeviceBomService.selectDmsBaseDeviceBomList(dmsBaseDeviceBom);
        return success(list);
    }

    /**
     * 导出设备BOM信息列表
     */
    @RequiresPermissions("dms:bom:export")
    @Log(title = "设备BOM信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsBaseDeviceBom dmsBaseDeviceBom)
    {
        List<DmsBaseDeviceBom> list = dmsBaseDeviceBomService.selectDmsBaseDeviceBomList(dmsBaseDeviceBom);
        ExcelUtil<DmsBaseDeviceBom> util = new ExcelUtil<DmsBaseDeviceBom>(DmsBaseDeviceBom.class);
        util.exportExcel(response, list, "设备BOM信息数据");
    }

    /**
     * 获取设备BOM信息详细信息
     */
    @RequiresPermissions("dms:bom:query")
    @GetMapping(value = "/{deviceBomId}")
    public AjaxResult getInfo(@PathVariable("deviceBomId") Long deviceBomId)
    {
        return success(dmsBaseDeviceBomService.selectDmsBaseDeviceBomByDeviceBomId(deviceBomId));
    }

    /**
     * 新增设备BOM信息
     */
    @RequiresPermissions("dms:bom:add")
    @Log(title = "设备BOM信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsBaseDeviceBom dmsBaseDeviceBom)
    {
        return toAjax(dmsBaseDeviceBomService.insertDmsBaseDeviceBom(dmsBaseDeviceBom));
    }

    /**
     * 修改设备BOM信息
     */
    @RequiresPermissions("dms:bom:edit")
    @Log(title = "设备BOM信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsBaseDeviceBom dmsBaseDeviceBom)
    {
        return toAjax(dmsBaseDeviceBomService.updateDmsBaseDeviceBom(dmsBaseDeviceBom));
    }

    /**
     * 删除设备BOM信息
     */
    @RequiresPermissions("dms:bom:remove")
    @Log(title = "设备BOM信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceBomIds}")
    public AjaxResult remove(@PathVariable Long[] deviceBomIds)
    {
        return toAjax(dmsBaseDeviceBomService.deleteDmsBaseDeviceBomByDeviceBomIds(deviceBomIds));
    }
    /**
     * 通过类型查询bom信息
     * */
    @PostMapping("/selectBomByDeviceType")
    @ResponseBody
    public AjaxResult selectBomByDeviceType(@RequestBody String deviceType)
    {
        List<DmsBaseDeviceBom> dmsBaseDeviceBoms = dmsBaseDeviceBomService.selectBomByDeviceType(deviceType);
        return success(dmsBaseDeviceBoms);
    }

}
