/*
 *      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.api.service.impl;

import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.modules.api.service.IApiService;
import org.springblade.modules.platform.service.IUserAddressService;
import org.springblade.modules.platform.service.IUserCardInfoService;
import org.springblade.modules.resource.builder.oss.OssBuilder;
import org.springblade.modules.resource.service.IAttachService;
import org.springblade.modules.system.entity.UserApp;
import org.springblade.modules.system.vo.UserAppVO;
import org.springblade.modules.system.wrapper.UserWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 商品规格值表 服务实现类
 *
 * @author BladeX
 * @since 2022-02-13
 */
@Service
public class ApiServiceImpl implements IApiService {



	@Autowired
	private OssBuilder ossBuilder;

	@Autowired
	private IAttachService attachService;

	@Autowired
	private IUserAddressService userAddressService;

	@Autowired
	private IUserCardInfoService userCardInfoService;

	@Autowired
	private BladeRedis bladeRedis;

	@Override
	public String userCodeUrl(String code){
		try {
			String href = "https://wine.gzzzyd.com/login.html?code=" + code;
			QrConfig config = new QrConfig(300, 300);
			// 设置边距，既二维码和背景之间的边距
			config.setMargin(3);
			// 生成base64二维码到文件，也可以到流
			return QrCodeUtil.generateAsBase64(href, config, "png");
		}catch (Exception e){
			e.printStackTrace();
		}
		return "";
	}

	@Override
	public UserAppVO getUserAppVo(Long userId) {
		UserApp userApp = new UserApp();
		UserApp query = userApp.selectOne(Wrappers.<UserApp>lambdaQuery().eq(UserApp::getUserId, userId));
		if (query == null){
			return null;
		}
		return UserWrapper.build().entityVo(query);
	}


}
