/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.gateway.common_gateway.controller;

import cn.hutool.core.date.DateUtil;
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.common.enums.AppConstant;
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.gateway.common_gateway.entity.vo.AppBalanceBillsVO;
import org.springblade.gateway.common_gateway.wrapper.AppBalanceBillsWrapper;
import org.springblade.ldt.bills.entity.BalanceBills;
import org.springblade.ldt.bills.service.IBalanceBillsService;
import org.springblade.ldt.bills.vo.BalanceBillsVO;
import org.springblade.ldt.bills.wrapper.BalanceBillsWrapper;
import org.springblade.ldt.shop.service.IShopService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *  控制器
 *
 * @author BladeX
 * @since 2021-08-31
 */
@RestController
@AllArgsConstructor
@RequestMapping("common/balancebills")
@Api(value = "", tags = "接口")
public class AppBalanceBillsController extends BladeController {

	private final IBalanceBillsService balanceBillsService;
	private final IShopService shopService;
	/**
	 * 分页【d端积分余额】
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入balanceBills")
	public R<IPage<AppBalanceBillsVO>> list(BalanceBills balanceBills, Query query) {
		Long receiveId = balanceBills.getReceiveId();
		Long payId = balanceBills.getPayId();
		String format = DateUtil.format(balanceBills.getCreateTime(), "yyyy-MM");

		BalanceBills bills = new BalanceBills();
		bills.setPayStatus( AppConstant.BillPayStatus.付款成功.name());
		IPage<BalanceBills> pages = balanceBillsService.page(Condition.getPage(query), Condition.getQueryWrapper(bills).lambda()
			.like(format != null, BalanceBills::getCreateTime, format)
			.eq(payId != null, BalanceBills::getPayId, payId)
			.or(receiveId != null).eq(receiveId != null, BalanceBills::getReceiveId, receiveId)
			.orderByDesc(BalanceBills::getCreateTime));
		return R.data(AppBalanceBillsWrapper.build(shopService).pageVO(pages));
	}


}
