package com.fjhx.item.controller.product;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.fjhx.common.constant.SourceConstant;
import com.fjhx.item.entity.product.dto.ProductClassifyDto;
import com.fjhx.item.entity.product.po.ProductClassify;
import com.fjhx.item.service.product.ProductClassifyService;
import com.ruoyi.common.core.domain.BaseSelectDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 产品分类 前端控制器
 * </p>
 *
 * @author zlj
 * @since 2023-03-15
 */
@DS(SourceConstant.ITEM)
@RestController
@RequestMapping("/productClassify")
public class ProductClassifyController {

    @Autowired
    private ProductClassifyService productClassifyService;

    /**
     * 产品分类树形
     */
    @PostMapping("/tree")
    public List<JSONObject> tree(@Validated @RequestBody ProductClassify productClassify) {
        List<JSONObject> tree = productClassifyService.tree(productClassify);
        return tree;
    }

    /**
     * 产品分类新增
     */
    @PostMapping("/add")
    public void add(@Validated @RequestBody ProductClassifyDto productClassifyDto) {
        productClassifyService.add(productClassifyDto);
    }

    /**
     * 产品分类编辑
     */
    @PostMapping("/edit")
    public void edit(@Validated @RequestBody ProductClassifyDto productClassifyDto) {
        productClassifyService.edit(productClassifyDto);
    }

    /**
     * 产品分类删除
     */
    @PostMapping("/delete")
    public void delete(@RequestBody BaseSelectDto dto) {
        productClassifyService.delete(dto.getId());
    }

}
