Commit 738fdc3e by 田超

add qrcodeTypeEnum

parent 48db857d
package com.pcloud.common.enums;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* @author lily
* @date 2018/12/6 11:36
*/
public enum QrcodeTypeEnum {
MAGIC("AUDIO", 0, "听画书", "MAGIC", "APP", true),
REWARD("CLOCK", 1, "打卡书", "REWARD", "APP", true),
PREVIEW_APP("VIDEO", 2, "预习课", "PREVIEW", "APP", true),
PREVIEW_PRODUCT("VIDEO_SCHEDULE", 3, "预习课", "PREVIEW", "PRODUCT", true),
ZSCORE("ZSCORE", 4, "查分书", "ZSCORE", "APP", true);
/**
* 类型
*/
private String type;
private Integer value;
private String description;
private String scene;
private String typeCode;
private Boolean isNeedCover;
public static final Map<String, QrcodeTypeEnum> QRCODE_TYPE_MAP = new HashMap<>();
QrcodeTypeEnum(String type, Integer value, String description, String scene, String typeCode, Boolean isNeedCover) {
this.type = type;
this.value = value;
this.description = description;
this.scene = scene;
this.typeCode = typeCode;
this.isNeedCover = isNeedCover;
}
static {
Arrays.asList(values()).forEach((m) -> {
QRCODE_TYPE_MAP.put(m.type, m);
});
}
public String getType() {
return type;
}
public Integer getValue() {
return value;
}
public String getDescription() {
return description;
}
public String getScene() {
return scene;
}
public String getTypeCode() {
return typeCode;
}
public Boolean getNeedCover() {
return isNeedCover;
}
}
......@@ -21,6 +21,7 @@ import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -223,21 +224,30 @@ public class QrcodeUtils {
* @throws Exception
*/
public static String createWithMargin(String url, Integer marginNum) throws BizException {
LOGGER.info("【二维码】创建二维码,<START>.[url]=" + url);
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.put(EncodeHintType.ERROR_CORRECTION, level);
hints.put(EncodeHintType.MARGIN, marginNum); // 设置白边
try {
// 生成矩阵
BitMatrix bitMatrix = new MultiFormatWriter().encode(url, BarcodeFormat.QR_CODE, ImageConstant.QRCODE_WITH,
ImageConstant.QRCODE_HEIGHT, hints);
BufferedImage bufferedImage = toBufferedImage(bitMatrix, onColor);
bufferedImage.flush();
return uploadImage(bufferedImage);
} catch (Exception e) {
LOGGER.error("【二维码】创建二维码失败,<ERROR>:" + e.getMessage(), e);
throw new FileException(FileException.FILE_UPLOAD_FAILURE, "创建二维码失败");
String key = "createWithMargin:"+url+"_"+marginNum;
if(JedisClusterUtils.exists(key)){
String s = JedisClusterUtils.get(key);
return s;
}else {
LOGGER.info("【二维码】创建二维码,<START>.[url]=" + url);
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.put(EncodeHintType.ERROR_CORRECTION, level);
hints.put(EncodeHintType.MARGIN, marginNum); // 设置白边
try {
// 生成矩阵
BitMatrix bitMatrix = new MultiFormatWriter().encode(url, BarcodeFormat.QR_CODE, ImageConstant.QRCODE_WITH,
ImageConstant.QRCODE_HEIGHT, hints);
BufferedImage bufferedImage = toBufferedImage(bitMatrix, onColor);
bufferedImage.flush();
String s = uploadImage(bufferedImage);
JedisClusterUtils.set(key,s,24*3600);
return s;
} catch (Exception e) {
LOGGER.error("【二维码】创建二维码失败,<ERROR>:" + e.getMessage(), e);
throw new FileException(FileException.FILE_UPLOAD_FAILURE, "创建二维码失败");
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment