package com.cyksj.service.mange.account;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cyksj.common.constant.Constant;
import com.cyksj.mapper.AccountMapper;
import com.cyksj.model.entity.Account;
import com.cyksj.service.mange.AccountCommonService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/*
 *项目名: netflix
 *文件名: AccountCommonServiceImpl
 *创建者: JavaZou
 *创建时间:2023/8/16 17:12
 */
@Service
@RequiredArgsConstructor
public class AccountCommonServiceImpl implements AccountCommonService {

	private final AccountMapper accountMapper;

	@Override
	public Boolean checkIsDupAccount(Long goodsId, String account) {
		LambdaQueryWrapper<Account> wrapper = Wrappers.lambdaQuery(Account.class)
				.eq(Account::getAccount, account);
		if (Constant.GPT_GOODS_IDS.contains(goodsId)) {
			wrapper.in(Account::getGoodsId, Constant.GPT_GOODS_IDS);
		} else {
			wrapper.eq(Account::getGoodsId, goodsId);
		}
		int count = accountMapper.selectCount(wrapper);
		if (count > 0) return true;
		return false;
	}
}
