package org.springblade.modules.platform.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.tool.utils.DigestUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.platform.service.UserAppService;
import org.springblade.modules.system.entity.UserApp;
import org.springblade.modules.system.mapper.UserAppMapper;
import org.springblade.modules.system.vo.UserAppVO;
import org.springframework.stereotype.Service;



@Service
public class UserAppServiceImpl extends ServiceImpl<UserAppMapper, UserApp> implements UserAppService {



	@Override
	public IPage<UserAppVO> pageList(IPage<UserAppVO> page, UserAppVO vo) {
		IPage<UserAppVO> pageList = this.getBaseMapper().getPageList(page, vo);
		return pageList;
	}

	@Override
	public Boolean verifyPayPassword(String payPassword, Long userId){
		UserApp userApp = this.getBaseMapper().selectOne(Wrappers.lambdaQuery(UserApp.class).eq(UserApp::getUserId, userId));
		if(ObjectUtil.isNull(userApp) || StringUtil.isEmpty(userApp.getPayPassword())){
			throw new RuntimeException("未查询到该用户支付信息");
		}
		String encrypt = DigestUtil.encrypt(userApp.getOffsetCode() + payPassword);
		return userApp.getPayPassword().equals(encrypt);
	}

	@Override
	public UserApp getByUserId(Long userId) {
		return getOne(Wrappers.lambdaQuery(UserApp.class).eq(UserApp::getUserId, userId));
	}
}
