package org.springblade.gateway.active_gateway.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.tool.api.R;
import org.springblade.gateway.active_gateway.service.ProductSortService;
import org.springblade.gateway.active_gateway.vo.ProductSortVO;
import org.springblade.sing.active.entity.ActiveHelpRecord;
import org.springblade.sing.active.entity.ActiveProductRecord;
import org.springblade.sing.active.service.IActiveProductRecordService;
import org.springblade.sing.active.vo.ActiveHelpRecordVO;
import org.springblade.sing.active.vo.ActiveProductRecordVO;
import org.springblade.sing.active.wrapper.ActiveHelpRecordWrapper;
import org.springblade.sing.active.wrapper.ActiveProductRecordWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cy-computer
 */
@RequestMapping("app/active/product")
@RestController
@AllArgsConstructor
@Api(value = "排行", tags = "排行接口")
@Slf4j
public class ProductSortController {

	private ProductSortService productSortService;
	private IActiveProductRecordService activeProductRecordService;
	private BladeRedis bladeRedis;

	@GetMapping("/sortList")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "作品排行", notes = "传入productSortVO")
	public R<List<ActiveProductRecordVO>> list(ProductSortVO productSortVO) throws IllegalAccessException {
		return R.data(productSortService.sortList(productSortVO));
	}


	@GetMapping("/sortListQuery")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "首页排行分页显示", notes = "传入productSortVO")
	public R sortListQuery(ProductSortVO productSortVO, Query query) throws IllegalAccessException {
		IPage page= productSortService.sortListQuery(productSortVO, query);
		return R.data(page);
	}


	/**
	 * 分页 活动作品搜索
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入activeProductRecord")
	public R<IPage<ActiveProductRecordVO>> list(ActiveProductRecord activeProductRecord, Query query) {
		IPage<ActiveProductRecord> pages = activeProductRecordService.page(Condition.getPage(query), Condition.getQueryWrapper(activeProductRecord).lambda().orderByAsc(ActiveProductRecord::getProductNo));
		return R.data(ActiveProductRecordWrapper.build(bladeRedis).pageVO(pages));
	}


}
