|
@@ -0,0 +1,76 @@
|
|
|
+package com.bosshand.virgo.core.service;
|
|
|
+
|
|
|
+import com.bosshand.virgo.core.dao.InviteDao;
|
|
|
+import com.bosshand.virgo.core.dao.InviteQrDao;
|
|
|
+import com.bosshand.virgo.core.model.Invite;
|
|
|
+import com.bosshand.virgo.core.model.InviteQr;
|
|
|
+import com.bosshand.virgo.core.model.MgrUser;
|
|
|
+import com.bosshand.virgo.core.utils.ContextUtils;
|
|
|
+import com.bosshand.virgo.core.utils.QRCodeUtil;
|
|
|
+import com.bosshand.virgo.exception.ServiceException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class InviteQrService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ InviteQrDao inviteQrDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ InviteDao inviteDao;
|
|
|
+
|
|
|
+ public Map<String, Object> get() {
|
|
|
+
|
|
|
+ MgrUser user = ContextUtils.getCurrentUser();
|
|
|
+
|
|
|
+ long userId = user.getId();
|
|
|
+
|
|
|
+ String content = null;
|
|
|
+
|
|
|
+ InviteQr inviteQr = inviteQrDao.getUser(userId);
|
|
|
+
|
|
|
+ String st = "https://www.waywish.com/workark/index.html#/loginRegister/login";
|
|
|
+
|
|
|
+ if (inviteQr != null) {
|
|
|
+ content = inviteQr.getContent();
|
|
|
+ } else {
|
|
|
+ InviteQr qr = new InviteQr();
|
|
|
+ qr.setUserId(userId);
|
|
|
+ String randomString = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ qr.setContent(randomString);
|
|
|
+ content = randomString;
|
|
|
+ qr.setUrl(st);
|
|
|
+ inviteQrDao.insert(qr);
|
|
|
+ }
|
|
|
+
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ byte[] qrCodeBytes = QRCodeUtil.getQRCodeBytes(st + "?content=" + content);
|
|
|
+ result = "data:image/png;base64," + Base64.getEncoder().encodeToString(qrCodeBytes);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("generate qr fail.");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ int number = inviteDao.getTotalCount(userId);
|
|
|
+ map.put("inviteNumber", number);
|
|
|
+ map.put("content", content);
|
|
|
+ map.put("url", st + "?content=" + content);
|
|
|
+ map.put("qrCodeBase64", result);
|
|
|
+ return map;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getTotalCount(long userId) {
|
|
|
+ return inviteDao.getTotalCount(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Invite> getLimit(long userId, int currPage, int pageSize) {
|
|
|
+ int currIndex = (currPage - 1) * pageSize;
|
|
|
+ return inviteDao.getLimit(userId, currIndex, pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|