| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.FileInputStream;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | |
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | | import org.yeshi.utils.ListUtil;
|
| | | import org.yeshi.utils.tencentcloud.COSManager;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.share.SpreadUserImgMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.user.SpreadImgMapper;
|
| | | import com.yeshi.fanli.dao.user.UserInfoDao;
|
| | | import com.yeshi.fanli.entity.bus.invite.SpreadImg;
|
| | | import com.yeshi.fanli.entity.bus.invite.SpreadUserImg;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.service.inter.user.QrCodeService;
|
| | | import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.FileUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | |
| | | private QrCodeService qrCodeService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoDao userInfoDao;
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public List<String> getUserSpreadImg(Long uid) {
|
| | | public List<String> getUserSpreadImg(Long uid, HttpServletRequest request) {
|
| | | List<String> imgList = new ArrayList<>();
|
| | |
|
| | | // 查询当前用户的推广图
|
| | |
| | |
|
| | | UserInfo user = null;
|
| | | if (dlist != null && dlist.size() > 0)
|
| | | user = userInfoDao.find(UserInfo.class, uid);
|
| | | user = userInfoService.selectByPKey(uid);
|
| | |
|
| | | String inviteCode = null;
|
| | | UserInfoExtra extraInfo = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (extraInfo != null) {
|
| | | inviteCode = extraInfo.getInviteCode();
|
| | | }
|
| | | String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
|
| | | |
| | | // 缓存路径
|
| | | String rootPath = request.getSession().getServletContext().getRealPath("/").replace("\\", "/");
|
| | | String projectName = request.getContextPath(); |
| | | String path = rootPath.replace(projectName, "/temp");
|
| | | File f = new File(path);
|
| | | if (!f.exists())
|
| | | f.mkdirs();
|
| | | |
| | | // 添加原来没有的
|
| | | for (String md5 : dlist) {
|
| | | for (SpreadImg img : spreadImgList)
|
| | |
| | | portrait = Constant.systemCommonConfig.getDefaultPortrait();
|
| | | }
|
| | |
|
| | | String imgUrl = qrCodeService.drawInviteQrCodeNew(img.getUrl(), uid, portrait, null, null, null, inviteCode);
|
| | | // 背景图片缓存
|
| | | int index = img.getUrl().lastIndexOf("/");
|
| | | String fileName = img.getUrl().substring(index + 1);
|
| | |
|
| | | InputStream inputStream = null;
|
| | | String cachePath = path + fileName;
|
| | | File file = new File(cachePath);
|
| | | if (file.exists()) {
|
| | | inputStream = new FileInputStream(file);
|
| | | } else {
|
| | | // 网络下载
|
| | | InputStream input = HttpUtil.getAsInputStream(img.getUrl());
|
| | | // 缓存本地
|
| | | FileUtil.saveAsFile(input, cachePath);
|
| | | // 获取流
|
| | | inputStream = new FileInputStream(file);
|
| | | }
|
| | | |
| | | String imgUrl = qrCodeService.drawInviteQrCodeNew(inputStream, fileName, uid, portrait, null, null, null, inviteCode);
|
| | | if (!StringUtil.isNullOrEmpty(imgUrl)) {
|
| | | if (imgUrl != null) {
|
| | | addUserInviteImg(uid, imgUrl);
|
| | |
| | | // }
|
| | |
|
| | | // 生成
|
| | | UserInfo user = userInfoDao.find(UserInfo.class, uid);
|
| | | UserInfo user = userInfoService.selectByPKey(uid);
|
| | | try {
|
| | | String imgUrl = qrCodeService.drawInviteQrCode(bgImg, uid, user.getPortrait(), null);
|
| | | return imgUrl;
|
| | |
| | |
|
| | | @Override
|
| | | public String getUserSpreadImg(Long uid, String bgImg, int erCodePostionX, int erCodePostionY, int erCodeSize) {
|
| | | UserInfo user = userInfoDao.find(UserInfo.class, uid);
|
| | | UserInfo user = userInfoService.selectByPKey(uid);
|
| | | try {
|
| | | String imgUrl = qrCodeService.drawInviteQrCode(bgImg, uid, user.getPortrait(), erCodePostionX,
|
| | | erCodePostionY, erCodeSize, null);
|
| | |
| | |
|
| | | @Override
|
| | | public String drawInviteQrCodeNew(String bgImg, Long uid, String portrait, Integer pX, Integer pY, Integer size, String inviteCode) throws Exception {
|
| | | return qrCodeService.drawInviteQrCodeNew(bgImg, uid, portrait, pX, pY, size, inviteCode);
|
| | | InputStream asInputStream = HttpUtil.getAsInputStream(bgImg);
|
| | | |
| | | int index = bgImg.lastIndexOf("/");
|
| | | String newUrl = bgImg.substring(index + 1);
|
| | | String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf("."));
|
| | | |
| | | return qrCodeService.drawInviteQrCodeNew(asInputStream, urlMd5, uid, portrait, pX, pY, size, inviteCode);
|
| | | }
|
| | |
|
| | |
|
| | |
| | | public String getInviteImgToGreet(String bgImg, Long uid, String portrait, String inviteCode, String content, Date date) throws Exception {
|
| | | return qrCodeService.drawInviteToGreet(bgImg, uid,portrait, inviteCode, content, date);
|
| | | }
|
| | | |
| | | |
| | | private static String getProjectRootPath(){ |
| | | String rootPath=Thread.currentThread().getContextClassLoader().getResource("").getPath(); |
| | | rootPath = rootPath.substring(1,rootPath.indexOf("WEB-INF")); |
| | | return rootPath;
|
| | | }
|
| | | |
| | | }
|