Browse Source

修复代码

master
主管理员 1 week ago
parent
commit
b12ea7f2ed
4 changed files with 114 additions and 6 deletions
  1. +1
    -1
      admin-pc/.env.development
  2. +1
    -1
      admin-pc/.env.production
  3. +111
    -3
      module-common/src/main/java/org/jeecg/api/service/impl/AppletIndexServiceImpl.java
  4. +1
    -1
      module-system/src/main/resources/application-dev.yml

+ 1
- 1
admin-pc/.env.development View File

@ -1,5 +1,5 @@
NODE_ENV=development
VUE_APP_API_BASE_URL=https://jewelry-admin.hhlm1688.com/jewelry-admin/
VUE_APP_API_BASE_URL=http://localhost:8001/jewelry-admin/
VUE_APP_CAS_BASE_URL=http://cas.example.org:8443/cas
VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview


+ 1
- 1
admin-pc/.env.production View File

@ -1,4 +1,4 @@
NODE_ENV=production
VUE_APP_API_BASE_URL=https://jewelry-admin.hhlm1688.com/jewelry-admin/
VUE_APP_API_BASE_URL=http://localhost:8001/jewelry-admin/
VUE_APP_CAS_BASE_URL=http://localhost:8888/cas
VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview

+ 111
- 3
module-common/src/main/java/org/jeecg/api/service/impl/AppletIndexServiceImpl.java View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -74,13 +75,18 @@ import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.transaction.Transactional;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.net.URL;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@ -1058,7 +1064,10 @@ public class AppletIndexServiceImpl implements AppletIndexService {
.eq(CommonConfig::getKeyName, "codeImg")
.one();
//获取二维码背景图
CommonConfig qr_code = commonConfigService.lambdaQuery()
.eq(CommonConfig::getKeyName, "qr_code")
.one();
String codeImg = oneImage.getKeyContent();
@ -1073,6 +1082,9 @@ public class AppletIndexServiceImpl implements AppletIndexService {
line_color.put("g", 0);
line_color.put("b", 0);
param.put("line_color", line_color);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
org.springframework.http.HttpEntity requestEntity = new org.springframework.http.HttpEntity(JSON.toJSONString(param), headers);
ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
@ -1114,13 +1126,21 @@ public class AppletIndexServiceImpl implements AppletIndexService {
MultipartFile mf = new CommonsMultipartFile(item);
//返回图片下载地址
WxQrCodeVo wxCodeVo = new WxQrCodeVo();
wxCodeVo.setUrl(this.uploadAliYunOss(mf));
this.uploadAliYunOss(mf);
CommonConfig image_go_url = commonConfigService.lambdaQuery()
.eq(CommonConfig::getKeyName, "image_go_url")
.one();
String qrCodeImageUrl = image_go_url.getKeyContent()+this.uploadAliYunOss(mf);
String backgroundImageUrl = qr_code.getKeyContent();
String outputFilePath = "combined_image.png";
String s = this.generateAndCombineImagesFromUrl(qrCodeImageUrl, backgroundImageUrl, outputFilePath);
wxCodeVo.setUrl(s);
wxCodeVo.setName("陌美人珠宝欢迎您");
// redisUtil.set("CodeImage::"+trial+member.getId(),wxCodeVo);
return Result.OK(wxCodeVo);
@ -1150,6 +1170,94 @@ public class AppletIndexServiceImpl implements AppletIndexService {
return null;
}
public String generateAndCombineImagesFromUrl(String qrCodeImageUrl, String backgroundUrl, String outputFilePath) {
File file = null;
try {
// 从URL加载小程序码图像
URL qrCodeUrl = new URL(qrCodeImageUrl);
BufferedImage qrCodeImage = ImageIO.read(qrCodeUrl);
// 从URL加载背景图像
URL backgroundImageUrl = new URL(backgroundUrl);
BufferedImage backgroundImage = ImageIO.read(backgroundImageUrl);
// 创建一个新的BufferedImage来保存合并后的图像
BufferedImage combinedImage = new BufferedImage(backgroundImage.getWidth(), backgroundImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = combinedImage.createGraphics();
// 绘制背景图像
g2d.drawImage(backgroundImage, 0, 0, null);
// 计算小程序码放置的位置这里以中心位置为例
int qrCodeX = (backgroundImage.getWidth() - qrCodeImage.getWidth()) / 2;
int qrCodeY = (backgroundImage.getHeight() - qrCodeImage.getHeight()) / 2;
//
// int backgroundHeight = backgroundImage.getHeight();
// int qrCodeHeight = qrCodeImage.getHeight();
// int qrCodeY = (int) (backgroundHeight - qrCodeHeight / 2);
// 绘制小程序码图像
g2d.drawImage(qrCodeImage, qrCodeX, 1100, null);
// 释放Graphics2D资源
g2d.dispose();
// 将合并后的图像保存到文件或根据需要执行其他操作
file = new java.io.File(outputFilePath);
ImageIO.write(combinedImage, "png", file);
String tempSave = outputFilePath;
String filePath = tempSave;
file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
}
// 上传到阿里云
DiskFileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem item = factory.createItem("File", "text/plain", true, file.getName());
int bytesRead = 0;
byte[] buffer = new byte[8192];
try {
FileInputStream fis = new FileInputStream(file);
OutputStream os = item.getOutputStream();
while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
MultipartFile mf = new CommonsMultipartFile(item);
String rul = this.uploadAliYunOss(mf);
System.out.println("合并后的图像已保存到" + this.uploadAliYunOss(mf));
return rul;
} catch (Exception e) {
e.printStackTrace();
} finally {
//删除文件
if (file.exists()) {
file.delete();
}
}
return null;
}
@Override
public Result<?> getInfoIntroduce(String type) {
return null;


+ 1
- 1
module-system/src/main/resources/application-dev.yml View File

@ -196,7 +196,7 @@ jeecg :
secretKey: qHI7C3PaXYZySr84HTToviC71AYlFq
endpoint: oss-cn-shenzhen.aliyuncs.com
bucketName: hanhaiimage
staticDomain: https://image.hhlm1688.com/
staticDomain: https://image.hhlm1688.com
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES


Loading…
Cancel
Save