package org.springblade.prize.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.boot.ctrl.BladeController;
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.prize.entity.BladePrize;
import org.springblade.prize.service.IBladePrizeService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zbc
 * @since 2021-03-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("prize/bladePrize")
@Api(value = "奖品管理", tags = "奖品管理接口")
public class BladePrizeController extends BladeController {

	private final IBladePrizeService bladePrizeService;


	/**
	 * 新增奖品
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "新增", notes = "传入bladePrize")
	public R save(@Valid @RequestBody BladePrize bladePrize) {
		return R.status(bladePrizeService.save(bladePrize));
	}


	/**
	 * 删除奖品
	 */
	@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(bladePrizeService.removeByIds(Func.toLongList(ids)));
	}


	/**
	 * 修改 可视化配置表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "修改", notes = "传入bladePrize")
	public R update(@Valid @RequestBody BladePrize bladePrize) {
		return R.status(bladePrizeService.updateById(bladePrize));
	}


	/**
	 * 分页 可视化配置表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "分页", notes = "传入bladePrize")
	public R<IPage<BladePrize>> list(BladePrize bladePrize, Query query) {
		IPage<BladePrize> pages = bladePrizeService.page(Condition.getPage(query), Condition.getQueryWrapper(bladePrize));
		return R.data(pages);
	}


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

}

