Commit 0f92aa9f authored by 周健威's avatar 周健威

修改代码

parent 64852da0
package com.upyuns.platform.rs.website.controller.web; package com.upyuns.platform.rs.website.controller.web;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken; import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController; import com.github.wxiaoqi.security.common.rest.BaseController;
...@@ -83,36 +84,37 @@ public class GainDataController extends BaseController<GainDataBiz,GainData> { ...@@ -83,36 +84,37 @@ public class GainDataController extends BaseController<GainDataBiz,GainData> {
gainData.setIsDel(SYS_FALSE); gainData.setIsDel(SYS_FALSE);
List<GainData> gainData1 = baseBiz.selectAll(gainData); List<GainData> gainData1 = baseBiz.selectAll(gainData);
for(GainData gainData2 : gainData1) { for(GainData gainData2 : gainData1) {
String path = gainData2.getPictureUrl().replaceAll("https://gdxm.upyuns.com/image","/sdbdata/www/gdweb_resources/image"); if(StrUtil.isNotBlank(gainData2.getPictureUrl())) {
path = path.replaceAll("https://zzrsmgmt.upyuns.com/image","/sdbdata/www/gdweb_resources/image"); String path = gainData2.getPictureUrl().replaceAll("https://gdxm.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
String path250 = path + "_250"; path = path.replaceAll("https://zzrsmgmt.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
if(!FileUtil.exist(path250)) { String path250 = path + "_250";
//生成250 if(!FileUtil.exist(path250)) {
BufferedImage originalImage = ImageIO.read(new File(path)); //生成250
int originalWidth = originalImage.getWidth(); BufferedImage originalImage = ImageIO.read(new File(path));
int originalHeight = originalImage.getHeight(); int originalWidth = originalImage.getWidth();
double scaleFactor = 1.0; int originalHeight = originalImage.getHeight();
double scaleFactor = 1.0;
if (originalWidth > originalHeight) { if (originalWidth > originalHeight) {
scaleFactor = (double) 500 / originalWidth; scaleFactor = (double) 500 / originalWidth;
} else { } else {
scaleFactor = (double) 500 / originalHeight; scaleFactor = (double) 500 / originalHeight;
} }
int newWidth = (int) (originalWidth * scaleFactor); int newWidth = (int) (originalWidth * scaleFactor);
int newHeight = (int) (originalHeight * scaleFactor); int newHeight = (int) (originalHeight * scaleFactor);
BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, originalImage.getType()); BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, originalImage.getType());
Graphics2D g = resizedImage.createGraphics(); Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null); g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
g.dispose(); g.dispose();
// 保存压缩后的图片 // 保存压缩后的图片
String compressedFilePath = path250; String compressedFilePath = path250;
String lastFormat = path.substring(path.lastIndexOf(".")); String lastFormat = path.substring(path.lastIndexOf("."));
ImageIO.write(resizedImage, lastFormat.substring(1, lastFormat.length()), new File(compressedFilePath)); ImageIO.write(resizedImage, lastFormat.substring(1, lastFormat.length()), new File(compressedFilePath));
}
} }
} }
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment