package org.springblade.product.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.product.entity.ProductSubCategory;
import org.springblade.product.service.IProductSubCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zbc
 * @since 2021-07-30
 */

@RestController
@AllArgsConstructor
@RequestMapping("/productSubCategory")
@Api(value = "产品小类管理", tags = "产品小类接口")
public class ProductSubCategoryController {

	private final IProductSubCategoryService productSubCategoryService;

	@PostMapping("/save")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "新增产品小类", notes = "传入productSubCategory")
	public R save(@Valid @RequestBody ProductSubCategory productSubCategory) {
		return R.status(productSubCategoryService.save(productSubCategory));
	}


	@PostMapping("/remove")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "删除产品小类", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合  1,2,3", required = true) @RequestParam String ids) {
		return R.status(productSubCategoryService.removeByIds(Func.toLongList(ids)));
	}


	@PostMapping("/update")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "修改产品小类", notes = "传入productSubCategory")
	public R update(@Valid @RequestBody ProductSubCategory productSubCategory) {
		return R.status(productSubCategoryService.updateById(productSubCategory));
	}


	@GetMapping("/page")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "分页")
	public R<IPage<ProductSubCategory>> page(Query query) {
		IPage<ProductSubCategory> page = Condition.getPage(query);
		IPage<ProductSubCategory> pages = productSubCategoryService.getPageByQuery(page);
		return R.data(pages);
	}


	@GetMapping("/detail")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "详情", notes = "传入productSubCategory")
	public R<ProductSubCategory> detail(ProductSubCategory productSubCategory) {
		ProductSubCategory detail = productSubCategoryService.getOne(Condition.getQueryWrapper(productSubCategory));
		return R.data(detail);
	}

}

