package com.zbf.web.controller.system;

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

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.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.enums.BusinessType;
import com.zbf.system.domain.TBaseGoodsBom;
import com.zbf.system.service.ITBaseGoodsBomService;
import com.zbf.common.utils.poi.ExcelUtil;

/**
 * 物料bomController
 *
 * @author tony
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/system/bom")
public class TBaseGoodsBomController extends BaseController {
    @Autowired
    private ITBaseGoodsBomService tBaseGoodsBomService;

    /**
     * 查询物料bom列表
     */
    @PreAuthorize("@ss.hasPermi('system:bom:list')")
    @GetMapping("/list")
    public AjaxResult list(TBaseGoodsBom tBaseGoodsBom) {
        HashMap<String, Object> map = new HashMap<>();
        List<TBaseGoodsBom> list = tBaseGoodsBomService.selectTBaseGoodsBomList(tBaseGoodsBom);
        map.put("list", list);
        map.put("column", tBaseGoodsBom.getColumnsJson());
        return success(map);
    }

    /**
     * 导出物料bom列表
     */
    @PreAuthorize("@ss.hasPermi('system:bom:export')")
    @Log(title = "物料bom", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBaseGoodsBom tBaseGoodsBom) {
        List<TBaseGoodsBom> list = tBaseGoodsBomService.selectTBaseGoodsBomList(tBaseGoodsBom);
        ExcelUtil<TBaseGoodsBom> util = new ExcelUtil<TBaseGoodsBom>(TBaseGoodsBom.class);
        util.exportExcel(response, list, "物料bom数据");
    }

    /**
     * 获取物料bom详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tBaseGoodsBomService.selectTBaseGoodsBomById(id));
    }

    /**
     * 新增物料bom
     */
    @PreAuthorize("@ss.hasPermi('system:bom:add')")
    @Log(title = "物料bom", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBaseGoodsBom tBaseGoodsBom) {
        return toAjax(tBaseGoodsBomService.insertTBaseGoodsBom(tBaseGoodsBom));
    }

    /**
     * 修改物料bom
     */
    @PreAuthorize("@ss.hasPermi('system:bom:edit')")
    @Log(title = "物料bom", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBaseGoodsBom tBaseGoodsBom) {
        return toAjax(tBaseGoodsBomService.updateTBaseGoodsBom(tBaseGoodsBom));
    }

    /**
     * 删除物料bom
     */
    @PreAuthorize("@ss.hasPermi('system:bom:remove')")
    @Log(title = "物料bom", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tBaseGoodsBomService.deleteTBaseGoodsBomByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:bom:remove')")
    @Log(title = "物料bom", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable Long[] ids) {
        return toAjax(tBaseGoodsBomService.disabledTBaseGoodsBomByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:bom:edit')")
    @Log(title = "物料bom", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable Long[] ids) {
        return toAjax(tBaseGoodsBomService.enableTBaseGoodsBomByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:bom:edit')")
    @Log(title = "物料bom", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TBaseGoodsBom tBaseGoodsBom) {
        return toAjax(tBaseGoodsBomService.updateStatus(tBaseGoodsBom));
    }

}

