package org.springblade.test;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springblade.Application;
import org.springblade.common.constant.SystemConstant;
import org.springblade.core.test.BladeBootTest;
import org.springblade.core.test.BladeSpringRunner;
import org.springblade.modules.guosen.billRecord.entity.BillRecord;
import org.springblade.modules.guosen.billRecord.service.IBillRecordService;
import org.springblade.modules.guosen.bussiness.entity.BussinessBonusAccount;
import org.springblade.modules.guosen.bussiness.entity.BussinessBonusStatic;
import org.springblade.modules.guosen.bussiness.service.IBussinessBonusAccountService;
import org.springblade.modules.guosen.bussiness.service.IBussinessBonusStaticService;
import org.springblade.modules.guosen.userActivityStatistical.entity.UserActivityStatistical;
import org.springblade.modules.guosen.userActivityStatistical.service.IUserActivityStatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Blade单元测试
 *
 * @author Chill
 */
@RunWith(BladeSpringRunner.class)
@BladeBootTest(appName = "blade-runner", profile = "test")
@Component
public class BladeTest {

	@Autowired
	private IBillRecordService billRecordService;
	@Autowired
	private IBussinessBonusAccountService bussinessBonusAccountService;

	@Test
	public void contextLoads() {
		BigDecimal n = new BigDecimal("10.00");
	}


	@Test
	public void contextLoads2() {
		//获取前一天的日期
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, -1);

		Date yesterday = calendar.getTime();
		//查询采购商充值记录
		List<BillRecord> billRecords = billRecordService.getBaseMapper().selectList(new QueryWrapper<>(new BillRecord()).lambda()
			.eq(BillRecord::getType, SystemConstant.BillRecordType.ADS).like(BillRecord::getCreateTime, yesterday)
			.eq(BillRecord::getPayStatus, SystemConstant.BillRecordPayStatus.PAYED));
		//采购商充值总额
		BigDecimal total = billRecords.stream().map(BillRecord::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
		//采购商充值技术服务总费用-即可分配利润
		BigDecimal bonusAmt = billRecords.stream().map(BillRecord::getBussinessFee).reduce(BigDecimal.ZERO, BigDecimal::add);


		BussinessBonusStatic bussinessBonusStatic = new BussinessBonusStatic();
		bussinessBonusStatic.setDate(yesterday);
		bussinessBonusStatic.setFee(BigDecimal.ZERO);
		bussinessBonusStatic.setTotalAmt(total);
		bussinessBonusStatic.setServiceAmt(bonusAmt);
		bussinessBonusStatic.setBonusAmt(bonusAmt);

//		bussinessBonusStaticService.save(bussinessBonusStatic);
	}

}
