/*
 *      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.modules.guosen.bonusgroupstrategyaccount.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springblade.core.tool.api.R;
import org.springblade.modules.guosen.bonusgroupaccount.entity.BonusGroupAccount;
import org.springblade.modules.guosen.bonusgroupstrategyaccount.entity.BonusGroupStrategyAccount;
import org.springblade.modules.guosen.bonusgroupstrategyaccount.vo.BonusGroupStrategyAccountVO;
import org.springblade.modules.guosen.bonusgroupstrategyaccount.mapper.BonusGroupStrategyAccountMapper;
import org.springblade.modules.guosen.bonusgroupstrategyaccount.service.IBonusGroupStrategyAccountService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.lang.invoke.LambdaMetafactory;
import java.util.List;

/**
 * 分润业务场景 服务实现类
 *
 * @author BladeX
 * @since 2021-11-13
 */
@Service
public class BonusGroupStrategyAccountServiceImpl extends BaseServiceImpl<BonusGroupStrategyAccountMapper, BonusGroupStrategyAccount> implements IBonusGroupStrategyAccountService {

	@Override
	public IPage<BonusGroupStrategyAccountVO> selectBonusGroupStrategyAccountPage(IPage<BonusGroupStrategyAccountVO> page, BonusGroupStrategyAccountVO bonusGroupStrategyAccount) {
		return page.setRecords(baseMapper.selectBonusGroupStrategyAccountPage(page, bonusGroupStrategyAccount));
	}

	@Override
	public R generateStrategyAccount(Long sceneId, Long groupId, Long strategyId, List<BonusGroupAccount> accountList) {
		for(BonusGroupAccount account : accountList){
			BonusGroupStrategyAccount strategyAccount = new BonusGroupStrategyAccount();
			strategyAccount.setBonusSceneId(sceneId);
			strategyAccount.setBonusGroupId(groupId);
			strategyAccount.setBonusGroupStrategyId(strategyId);
			strategyAccount.setBonusGroupAccountId(account.getId());
			strategyAccount.setRate(account.getRate());
			this.save(strategyAccount);
		}
		return R.status(true);
	}

	@Override
	public List<BonusGroupStrategyAccount> getBySceneGroupStrategy(Long sceneId, Long groupId, Long strategyId) {
		LambdaQueryWrapper<BonusGroupStrategyAccount> lambda = new LambdaQueryWrapper<>();
		lambda.eq(BonusGroupStrategyAccount::getBonusSceneId, sceneId);
		lambda.eq(BonusGroupStrategyAccount::getBonusGroupId, groupId);
		lambda.eq(BonusGroupStrategyAccount::getBonusGroupStrategyId, strategyId);
		return this.list(lambda);
	}

}
