package utils;
import java.io.File;
import java.util.List;
import com.google.zxing.BarcodeFormat;
import com.shove.code.Qrcode;
import constants.Constants;
import models.t_users;
import play.Logger;
public class QcodeUtil {
public static void main(String[] args) {
QcodeUtil.createQcode();
}
public static void createQcode() {
try {
// EntityManager em = JPA.em();
// Query queryList = em.createNativeQuery("select * from t_users",
// t_voucher_use_h.class);
// List<t_users> list = queryList.getResultList();
List<t_users> list = t_users.findAll();
for (t_users user : list) {
Long invite_code = user.id + 10000000; // 邀请码
// String uuid = UUID.randomUUID().toString();
String uuid = user.qr_code;
Qrcode code = new Qrcode();
String qcodeUrl = Constants.BASE_URL + "wechat/registAndLogin/register?un=" + invite_code;
String qcodePath = "E:/attachments";
try {
// Blob blob = new Blob();
code.create(qcodeUrl, BarcodeFormat.QR_CODE, 116, 116, new File(qcodePath, uuid).getAbsolutePath(),
"png");
// code.create(qcodeUrl, BarcodeFormat.QR_CODE, 116, 116,
// new File(blob.getStore(), uuid).getAbsolutePath(),
// "png");
} catch (Exception e) {
e.printStackTrace();
Logger.info("创建二维码图片失败" + e.getMessage());
}
/*
* String sql = "update t_users qr_code=? where id = ?"; Query
* query = JPA.em().createQuery(sql).setParameter(1,
* invite_code).setParameter(2, user.id);
*
* int rows = 0;
*
* try { rows = query.executeUpdate(); } catch (Exception e) {
* JPA.setRollbackOnly(); e.printStackTrace();
* Logger.info("更新用户二维码失败:" + e.getMessage()); }
*
* if (rows == 0) { Logger.info("更新用户二维码失败");
* JPA.setRollbackOnly(); }
*/
}
} catch (Exception e) {
Logger.info("更新用户二维码异常:" + e.getMessage());
}
}
}
import java.io.File;
import java.util.List;
import com.google.zxing.BarcodeFormat;
import com.shove.code.Qrcode;
import constants.Constants;
import models.t_users;
import play.Logger;
public class QcodeUtil {
public static void main(String[] args) {
QcodeUtil.createQcode();
}
public static void createQcode() {
try {
// EntityManager em = JPA.em();
// Query queryList = em.createNativeQuery("select * from t_users",
// t_voucher_use_h.class);
// List<t_users> list = queryList.getResultList();
List<t_users> list = t_users.findAll();
for (t_users user : list) {
Long invite_code = user.id + 10000000; // 邀请码
// String uuid = UUID.randomUUID().toString();
String uuid = user.qr_code;
Qrcode code = new Qrcode();
String qcodeUrl = Constants.BASE_URL + "wechat/registAndLogin/register?un=" + invite_code;
String qcodePath = "E:/attachments";
try {
// Blob blob = new Blob();
code.create(qcodeUrl, BarcodeFormat.QR_CODE, 116, 116, new File(qcodePath, uuid).getAbsolutePath(),
"png");
// code.create(qcodeUrl, BarcodeFormat.QR_CODE, 116, 116,
// new File(blob.getStore(), uuid).getAbsolutePath(),
// "png");
} catch (Exception e) {
e.printStackTrace();
Logger.info("创建二维码图片失败" + e.getMessage());
}
/*
* String sql = "update t_users qr_code=? where id = ?"; Query
* query = JPA.em().createQuery(sql).setParameter(1,
* invite_code).setParameter(2, user.id);
*
* int rows = 0;
*
* try { rows = query.executeUpdate(); } catch (Exception e) {
* JPA.setRollbackOnly(); e.printStackTrace();
* Logger.info("更新用户二维码失败:" + e.getMessage()); }
*
* if (rows == 0) { Logger.info("更新用户二维码失败");
* JPA.setRollbackOnly(); }
*/
}
} catch (Exception e) {
Logger.info("更新用户二维码异常:" + e.getMessage());
}
}
}