package com.taais.demo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.taais.common.core.core.domain.CommonResult;
import com.taais.common.core.utils.poi.ExcelUtil;
import com.taais.common.web.core.BaseController;
import com.taais.demo.domain.DemoProduct;
import com.taais.demo.service.IDemoProductService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


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

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

    /**
     * 导出产品树表（mb）列表
     */
    @SaCheckPermission("demo:product: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）详细信息
     */
    @SaCheckPermission("demo:product:query")
    @GetMapping(value = "/{productId}")
    public CommonResult<DemoProduct> getInfo(@PathVariable("productId") Long productId) {
        return CommonResult.success(demoProductService.selectDemoProductByProductId(productId));
    }

    /**
     * 新增产品树表（mb）
     */
    @SaCheckPermission("demo:product:add")
    @PostMapping
    public CommonResult<Integer> add(@RequestBody DemoProduct demoProduct) {
        return CommonResult.success(demoProductService.insertDemoProduct(demoProduct));
    }

    /**
     * 修改产品树表（mb）
     */
    @SaCheckPermission("demo:product:edit")
    @PutMapping
    public CommonResult<Integer> edit(@RequestBody DemoProduct demoProduct) {
        return CommonResult.success(demoProductService.updateDemoProduct(demoProduct));
    }

    /**
     * 删除产品树表（mb）
     */
    @SaCheckPermission("demo:product:remove")
    @DeleteMapping("/{productIds}")
    public CommonResult<Integer> remove(@PathVariable Long[] productIds) {
        return CommonResult.success(demoProductService.deleteDemoProductByProductIds(productIds));
    }
}
