package com.fjhx.controller.product;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.params.product.ProductCombinationEx;
import com.fjhx.params.product.ProductInfoVo;
import com.fjhx.service.product.ProductInfoService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-29
 */
@RestController
@RequestMapping("/productInfo")
public class ProductInfoController {

    @Autowired
    private ProductInfoService productInfoService;

    @PostMapping("/page")
    public R page(@RequestBody Map<String, Object> condition) {
        Page<Map<String, Object>> result = productInfoService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody ProductInfoVo productInfoVo) {
        productInfoService.add(productInfoVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody ProductInfoVo productInfoVo) {
        productInfoService.edit(productInfoVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody ProductInfoVo productInfoVo) {
        productInfoService.delete(productInfoVo);
        return R.success();
    }

    /**
     * 获取组合
     */
    @PostMapping("/getCombinationPage")
    public R getCombinationPage(@RequestBody Condition condition) {
        Page<ProductCombinationEx> page = productInfoService.getCombinationPage(condition);
        return R.success(page);
    }

}

