package com.ruoyi.demo.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import jakarta.annotation.Resource;
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.ruoyi.common.core.annotation.Log;
import com.ruoyi.common.core.core.controller.BaseController;
import com.ruoyi.common.core.core.domain.AjaxResult;
import com.ruoyi.common.core.enums.BusinessType;
import com.ruoyi.demo.domain.DemoProduct;
import com.ruoyi.demo.service.IDemoProductService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;


/**
 * 产品树表（mb）Controller
 * 
 * @author 数据小王子
 * 2023-07-11
 */
@RestController
@RequestMapping("/demo/product")
public class DemoProductController extends BaseController
{
    @Resource
    private IDemoProductService demoProductService;

    /**
     * 查询产品树表（mb）列表
     */
    @PreAuthorize("@ss.hasPermi('demo:product:list')")
    @GetMapping("/list")
    public AjaxResult list(DemoProduct demoProduct)
    {
        List<DemoProduct> list = demoProductService.selectDemoProductList(demoProduct);
        return success(list);
    }

    /**
     * 导出产品树表（mb）列表
     */
    @PreAuthorize("@ss.hasPermi('demo:product:export')")
    @Log(title = "产品树表（mb）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoProduct demoProduct)
    {
        List<DemoProduct> list = demoProductService.selectDemoProductList(demoProduct);
        ExcelUtil<DemoProduct> util = new ExcelUtil<>(DemoProduct.class);
        util.exportExcel(response, list, "产品树表（mb）数据");
    }

    /**
     * 获取产品树表（mb）详细信息
     */
    @PreAuthorize("@ss.hasPermi('demo:product:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(demoProductService.selectDemoProductByProductId(productId));
    }

    /**
     * 新增产品树表（mb）
     */
    @PreAuthorize("@ss.hasPermi('demo:product:add')")
    @Log(title = "产品树表（mb）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DemoProduct demoProduct)
    {
        return toAjax(demoProductService.insertDemoProduct(demoProduct));
    }

    /**
     * 修改产品树表（mb）
     */
    @PreAuthorize("@ss.hasPermi('demo:product:edit')")
    @Log(title = "产品树表（mb）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DemoProduct demoProduct)
    {
        return toAjax(demoProductService.updateDemoProduct(demoProduct));
    }

    /**
     * 删除产品树表（mb）
     */
    @PreAuthorize("@ss.hasPermi('demo:product:remove')")
    @Log(title = "产品树表（mb）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(demoProductService.deleteDemoProductByProductIds(productIds));
    }
}
