|
@@ -9,9 +9,8 @@ import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.DictUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.company.domain.CompanyTag;
|
|
|
-import com.fs.company.domain.CompanyTagUser;
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
import com.fs.company.mapper.CompanyTagMapper;
|
|
|
-import com.fs.company.mapper.CompanyTagUserMapper;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
@@ -28,6 +27,7 @@ import com.google.zxing.EncodeHintType;
|
|
|
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
|
import com.google.zxing.common.BitMatrix;
|
|
|
import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -36,13 +36,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
import java.util.*;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -53,6 +51,7 @@ import java.util.List;
|
|
|
* @date 2024-05-15
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class FsUserCourseServiceImpl implements IFsUserCourseService
|
|
|
{
|
|
|
@Autowired
|
|
@@ -451,7 +450,7 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public String createCourseImageQR(String url, String backgroundImagePath, File file,
|
|
|
+ public String createCourseImageQR(String url, String backgroundImagePath, InputStream file,
|
|
|
String outputFormat, String title, String duration) throws Exception {
|
|
|
// 读取并缩放背景图片
|
|
|
BufferedImage backgroundImage = createScaledBackgroundImage(backgroundImagePath);
|
|
@@ -470,7 +469,7 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
|
|
|
graphics.fillRect(0, scaledHeight, scaledWidth, bottomHeight);
|
|
|
|
|
|
// 绘制推荐区域(图片和文字)
|
|
|
- drawRecommendationArea(graphics, file, scaledHeight);
|
|
|
+ drawRecommendationArea(graphics, file, scaledHeight, "云联融智", "为您推荐");
|
|
|
|
|
|
// 绘制二维码
|
|
|
drawQRCode(graphics, url, scaledWidth, totalHeight);
|
|
@@ -529,7 +528,7 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
|
|
|
/**
|
|
|
* 绘制推荐区域
|
|
|
*/
|
|
|
- private void drawRecommendationArea(Graphics2D graphics, File file, int scaledHeight) throws IOException {
|
|
|
+ private void drawRecommendationArea(Graphics2D graphics, InputStream file, int scaledHeight, String recommendName, String recommendContent) throws IOException {
|
|
|
// 读取并绘制推荐图片
|
|
|
BufferedImage referenceImg = ImageIO.read(file);
|
|
|
int refHeight = 40;
|
|
@@ -546,16 +545,16 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
|
|
|
int textX = refX + refWidth + 10;
|
|
|
int textY = refY + 25;
|
|
|
graphics.setColor(new Color(51, 51, 51));
|
|
|
- graphics.drawString("云联融智", textX, textY);
|
|
|
+ graphics.drawString(recommendName, textX, textY);
|
|
|
|
|
|
// 绘制"为您推荐"
|
|
|
FontMetrics metrics = graphics.getFontMetrics(recommendFont);
|
|
|
- int brandWidth = metrics.stringWidth("云联融智");
|
|
|
+ int brandWidth = metrics.stringWidth(recommendName);
|
|
|
int textX1 = textX + brandWidth + 5;
|
|
|
graphics.setColor(new Color(102, 102, 102));
|
|
|
- graphics.drawString("为您推荐", textX1, textY);
|
|
|
+ graphics.drawString(recommendContent, textX1, textY);
|
|
|
// FontMetrics metrics = graphics.getFontMetrics(recommendFont);
|
|
|
- int reWidth = metrics.stringWidth("为您推荐");
|
|
|
+ int reWidth = metrics.stringWidth(recommendContent);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -665,6 +664,61 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
|
|
|
return R.error("生成链接失败!");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public InputStream handleImage(String url, String path) throws IOException {
|
|
|
+ InputStream inputstream = null;
|
|
|
+ if(StringUtils.isNotEmpty(url)){
|
|
|
+ URL newUrl = new URL(url);
|
|
|
+ URLConnection connection = newUrl.openConnection();
|
|
|
+ // 设置用户代理,避免被服务器拒绝
|
|
|
+ connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
|
|
+ inputstream = connection.getInputStream();
|
|
|
+ } else {
|
|
|
+ File file = new File(path);
|
|
|
+ try{
|
|
|
+ inputstream = new FileInputStream(file);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("获取本地路径失败:{}", path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("头像/logo路径, url:{}, path:{}", url, path);
|
|
|
+ return inputstream;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String createUserImageQR(String url, String backgroundImagePath, InputStream file, String outputFormat, Long companyUserId) throws Exception {
|
|
|
+ // 读取并缩放背景图片
|
|
|
+ BufferedImage backgroundImage = createScaledBackgroundImage(backgroundImagePath);
|
|
|
+ int scaledWidth = backgroundImage.getWidth();
|
|
|
+ int scaledHeight = backgroundImage.getHeight();
|
|
|
+
|
|
|
+ // 创建最终的合成图片,确保底部区域有足够空间
|
|
|
+ int bottomHeight = 200; // 增加底部区域高度,确保内容完全显示
|
|
|
+ int totalHeight = scaledHeight + bottomHeight;
|
|
|
+ BufferedImage combined = new BufferedImage(scaledWidth, totalHeight, BufferedImage.TYPE_INT_ARGB);
|
|
|
+ Graphics2D graphics = initializeGraphics(combined);
|
|
|
+
|
|
|
+ // 绘制背景和底部白色区域
|
|
|
+ graphics.drawImage(backgroundImage, 0, 0, null);
|
|
|
+ graphics.setColor(Color.WHITE);
|
|
|
+ graphics.fillRect(0, scaledHeight, scaledWidth, bottomHeight);
|
|
|
+
|
|
|
+ //获取销售名称
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserById(companyUserId);
|
|
|
+
|
|
|
+ // 绘制推荐区域(图片和文字)
|
|
|
+ drawRecommendationArea(graphics, file, scaledHeight, companyUser != null ? companyUser.getUserName(): "云联融智", "邀请您成为会员");
|
|
|
+
|
|
|
+ // 绘制二维码
|
|
|
+ drawQRCode(graphics, url, scaledWidth, totalHeight);
|
|
|
+
|
|
|
+ graphics.dispose();
|
|
|
+
|
|
|
+ // 转换为Base64
|
|
|
+ return convertToBase64(combined, outputFormat);
|
|
|
+ }
|
|
|
+
|
|
|
private static Calendar getExpireDay(FsCourseLinkCreateParam param, CourseConfig config, Date createTime) {
|
|
|
Integer expireDuration;
|
|
|
if (param.getEffectiveDuration() == null || param.getEffectiveDuration() == 0){
|