package com.njzscloud.supervisory.biz.service;


import cn.hutool.core.img.ImgUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.njzscloud.supervisory.biz.pojo.param.QRCodeParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 获取二维码
 * @author ljw
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class QRCodeService {

    public String getCode(QRCodeParam codeParam) {
        Integer width = codeParam.getWidth();
        Integer height = codeParam.getHeight();
        if (width == null) {
            width = 300;
        }
        if (height == null) {
            height = 300;
        }
        String imgType = codeParam.getImgType();
        if (imgType == null) {
            imgType = ImgUtil.IMAGE_TYPE_JPG;
        }

        return QrCodeUtil.generateAsBase64(codeParam.getContent(), new QrConfig(width, height), imgType);

    }

}
