jsk 图片同步

This commit is contained in:
skjia 2025-03-21 09:34:47 +08:00
parent 35fa8cc00d
commit d5c313b47b
1 changed files with 59 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -643,44 +644,88 @@ public class GreenTaskController {
/** /**
* 图片同步服务 * 图片同步服务
*/ */
// @SuppressWarnings({ "unchecked" })
// @Scheduled(cron = "0 0 23 * * ?")
//// @Scheduled(cron = "0 30 17 * * ?")
// @Transactional(rollbackFor = Exception.class)
// public void getWebImage() {
// try {
// System.out.println("getWebImage");
// String sql = "select id,IMAGE_CONTENT_BLOB from green_image_info where IMAGE_STATUS = '1'";
// // 返回结果list
// List<Map<String, Object>> resultList = hibernateDao.queryForListWithSql(sql);
// String id = null;
// byte[] iamgeContent = null;
// String path = baseService.getWebImgDir();//"/home/appImageDir/zhhq_sj/";//
// for(int i=0;i<resultList.size();i++){
// id = resultList.get(i).get("ID").toString();
// java.sql.Blob blob = null;
//// blob = (java.sql.Blob) resultList.get(i).get("IMAGE_CONTENT_BLOB");
//// byte b[]=blob.getBytes(0,1024);
// iamgeContent = (byte[]) resultList.get(i).get("IMAGE_CONTENT_BLOB");
// String imageBase64 = new String(iamgeContent);
// imageBase64 = imageBase64.substring(imageBase64.indexOf(",") + 1);
// String d1 = path + id + ".jpg";
// boolean b = Base64Utils.Base64ToImage(imageBase64, d1);
// if(b){
// String sqlString = "update green_image_info set IMAGE_STATUS = '4' where id = ? ";
// hibernateDao.updateWithSql(sqlString, new Object[] {id });
// }
//// ByteArrayInputStream bais = new ByteArrayInputStream(iamgeContent);
//// BufferedImage bi1 = ImageIO.read(bais);
////
//// File w2 = new File(path+id+".jpg");// 可以是jpg,png,gif格式
//// ImageIO.write(bi1, "jpg", w2);
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
/**
* 图片双节点同步服务
*/
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
@Scheduled(cron = "0 0 23 * * ?") @Scheduled(cron = "0 0 23 * * ?")
// @Scheduled(cron = "0 30 17 * * ?")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void getWebImage() { public void getWebServerImage() {
try { try {
System.out.println("getWebImage"); String serverIP="";
String sql = "select id,IMAGE_CONTENT_BLOB from green_image_info where IMAGE_STATUS = '1'"; try{
InetAddress ip = InetAddress.getLocalHost();
serverIP= ip.getHostName();
System.out.println("Server IP: " + serverIP);
} catch (Exception e) {
e.printStackTrace();
}
System.err.println("当前服务地址==="+serverIP);
if("".equals(serverIP)){
return;
}
String sql = "select id,IMAGE_CONTENT_BLOB,IMAGE_NAME from green_image_info where SERVER_ADDR NOT NULL AND SERVER_ADDR != '"+serverIP+"' AND SERVER_STATE='2' ";
// 返回结果list // 返回结果list
List<Map<String, Object>> resultList = hibernateDao.queryForListWithSql(sql); List<Map<String, Object>> resultList = hibernateDao.queryForListWithSql(sql);
String id = null; String id = null;
String imageName = null;
byte[] iamgeContent = null; byte[] iamgeContent = null;
String path = baseService.getWebImgDir();//"/home/appImageDir/zhhq_sj/";// String path = baseService.getWebImgDir();//"/home/appImageDir/zhhq_sj/";//
for(int i=0;i<resultList.size();i++){ for(int i=0;i<resultList.size();i++){
id = resultList.get(i).get("ID").toString(); id = resultList.get(i).get("ID").toString();
imageName = resultList.get(i).get("IMAGE_NAME").toString();
java.sql.Blob blob = null; java.sql.Blob blob = null;
// blob = (java.sql.Blob) resultList.get(i).get("IMAGE_CONTENT_BLOB");
// byte b[]=blob.getBytes(0,1024);
iamgeContent = (byte[]) resultList.get(i).get("IMAGE_CONTENT_BLOB"); iamgeContent = (byte[]) resultList.get(i).get("IMAGE_CONTENT_BLOB");
String imageBase64 = new String(iamgeContent); String imageBase64 = new String(iamgeContent);
imageBase64 = imageBase64.substring(imageBase64.indexOf(",") + 1); imageBase64 = imageBase64.substring(imageBase64.indexOf(",") + 1);
String d1 = path + id + ".jpg"; String d1 = path + imageName;
boolean b = Base64Utils.Base64ToImage(imageBase64, d1); boolean b = Base64Utils.Base64ToImage(imageBase64, d1);
if(b){ if(b){
String sqlString = "update green_image_info set IMAGE_STATUS = '4' where id = ? "; String sqlString = "update green_image_info set SERVER_STATE = '3' where id = ? ";
hibernateDao.updateWithSql(sqlString, new Object[] {id }); hibernateDao.updateWithSql(sqlString, new Object[] {id });
} }
// ByteArrayInputStream bais = new ByteArrayInputStream(iamgeContent);
// BufferedImage bi1 = ImageIO.read(bais);
//
// File w2 = new File(path+id+".jpg");// 可以是jpg,png,gif格式
// ImageIO.write(bi1, "jpg", w2);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
* 每天下午23时更新 更新合同状态 * 每天下午23时更新 更新合同状态
*/ */