Commit 64852da0 authored by 周健威's avatar 周健威

修改代码

parent 10b6a6f7
package com.upyuns.platform.rs.website.controller.web;
import cn.hutool.core.io.FileUtil;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
......@@ -14,8 +15,15 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
@RestController
@RequestMapping("gainData/web")
public class GainDataController extends BaseController<GainDataBiz,GainData> {
......@@ -67,4 +75,53 @@ public class GainDataController extends BaseController<GainDataBiz,GainData> {
return ObjectRestResponse.succ();
}
@ApiModelProperty("处理历史图片")
@IgnoreUserToken
@RequestMapping(value = "/app/unauth/dealHisimg",method = RequestMethod.GET)
public ObjectRestResponse dealHisimg(GainData gainData) throws IOException {
gainData.setIsDel(SYS_FALSE);
List<GainData> gainData1 = baseBiz.selectAll(gainData);
for(GainData gainData2 : gainData1) {
String path = gainData2.getPictureUrl().replaceAll("https://gdxm.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
path = path.replaceAll("https://zzrsmgmt.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
String path250 = path + "_250";
if(!FileUtil.exist(path250)) {
//生成250
BufferedImage originalImage = ImageIO.read(new File(path));
int originalWidth = originalImage.getWidth();
int originalHeight = originalImage.getHeight();
double scaleFactor = 1.0;
if (originalWidth > originalHeight) {
scaleFactor = (double) 500 / originalWidth;
} else {
scaleFactor = (double) 500 / originalHeight;
}
int newWidth = (int) (originalWidth * scaleFactor);
int newHeight = (int) (originalHeight * scaleFactor);
BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, originalImage.getType());
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
g.dispose();
// 保存压缩后的图片
String compressedFilePath = path250;
String lastFormat = path.substring(path.lastIndexOf("."));
ImageIO.write(resizedImage, lastFormat.substring(1, lastFormat.length()), new File(compressedFilePath));
}
}
return ObjectRestResponse.succ();
}
public static void main(String[] args) {
String url = "https://zzrsmgmt.upyuns.com/image/admin/2024-05-30/11.JPG";
String url2 = url.replaceAll("https://zzrsmgmt.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
String lastFormat = url2.substring(url2.lastIndexOf("."));
System.out.println(url2);
System.out.println(lastFormat);
}
}
\ No newline at end of file
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