Commit 6fc6da3d authored by hongguangwu's avatar hongguangwu

1.7.21-优化

parent 3f9f5c77
...@@ -205,6 +205,18 @@ public class SocialTask { ...@@ -205,6 +205,18 @@ public class SocialTask {
"/tsocialfriend/inner/doPushFriend","", Object.class, SecurityConstants.FROM_IN); "/tsocialfriend/inner/doPushFriend","", Object.class, SecurityConstants.FROM_IN);
log.info("------------1定时任务推送税友-定时任务结束------------"); log.info("------------1定时任务推送税友-定时任务结束------------");
} }
/**
* @Description: 定时任务清理临时文件
* @Author: hgw
* @Date: 20260409
**/
public void doClearFriend() {
log.info("------------定时任务清理临时文件-定时任务开始------------");
HttpDaprUtil.invokeMethodPost(daprProperties.getAppUrl(),daprProperties.getAppId(),
"/tsocialfriend/inner/doClearFriend","", Object.class, SecurityConstants.FROM_IN);
log.info("------------定时任务清理临时文件-定时任务结束------------");
}
/** /**
* @Description: 2定时任务获取税友 * @Description: 2定时任务获取税友
* @Author: hgw * @Author: hgw
......
...@@ -87,6 +87,14 @@ public class TSocialFriendController { ...@@ -87,6 +87,14 @@ public class TSocialFriendController {
return tSocialFriendPushService.pushFriend(null, null, CommonConstants.ONE_INT, null); return tSocialFriendPushService.pushFriend(null, null, CommonConstants.ONE_INT, null);
} }
@Operation(description = "定时任务清理临时文件")
@PostMapping("/inner/doClearFriend")
@SysLog("定时任务清理临时文件")
@Inner
public void doClearFriend() {
tSocialFriendPushService.doClearFriend();
}
@Operation(description = "2定时任务获取税友") @Operation(description = "2定时任务获取税友")
@PostMapping("/inner/doGetFriendByRequestId") @PostMapping("/inner/doGetFriendByRequestId")
@SysLog("2定时任务获取税友") @SysLog("2定时任务获取税友")
......
...@@ -43,6 +43,9 @@ public interface TSocialFriendPushService extends IService<TSocialInfo> { ...@@ -43,6 +43,9 @@ public interface TSocialFriendPushService extends IService<TSocialInfo> {
**/ **/
R<String> pushFriend(List<String> dispatchIdList, List<String> pushDispatchIdList, Integer isAuto, String userId); R<String> pushFriend(List<String> dispatchIdList, List<String> pushDispatchIdList, Integer isAuto, String userId);
// 定时任务清理临时文件
void doClearFriend();
R<String> doExportRoster(String socialId, String type, String unitCreditCode, List<SociaFriendYgsAddVo> listVo); R<String> doExportRoster(String socialId, String type, String unitCreditCode, List<SociaFriendYgsAddVo> listVo);
R<String> test(); R<String> test();
......
...@@ -117,8 +117,6 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -117,8 +117,6 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
@Override @Override
public R<String> pushFriend(List<String> dispatchIdList, List<String> pushDispatchIdList, Integer isAuto, String userId) { public R<String> pushFriend(List<String> dispatchIdList, List<String> pushDispatchIdList, Integer isAuto, String userId) {
if (atomicPushFriend.incrementAndGet() <= 1) { if (atomicPushFriend.incrementAndGet() <= 1) {
// 先清理上一次的文件
//cleanSpireTempFiles();
try { try {
TSocialFreindSet set = tSocialFreindSetService.getById("1"); TSocialFreindSet set = tSocialFreindSetService.getById("1");
if (set != null && Common.isNotNull(set.getType()) && 1 == set.getType()) { if (set != null && Common.isNotNull(set.getType()) && 1 == set.getType()) {
...@@ -204,41 +202,23 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -204,41 +202,23 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
// 不可以并发,会使花名册转图片的字体不正确 // 不可以并发,会使花名册转图片的字体不正确
// 后续优化,考虑升级(spire.xls)的版本 // 后续优化,考虑升级(spire.xls)的版本
// 此方法是:删除临时文件 // 此方法是:删除临时文件
public void cleanSpireTempFiles() { @Override
public void doClearFriend() {
try { try {
// 暂停1分钟:不暂停,删10分钟前的数据
/*try {
Thread.sleep(60000);
} catch (InterruptedException e) {
}*/
String tempDirPath = System.getProperty("java.io.tmpdir"); String tempDirPath = System.getProperty("java.io.tmpdir");
File tempDir = new File(tempDirPath); File tempDir = new File(tempDirPath);
if (tempDir.exists() && tempDir.isDirectory()) { if (tempDir.exists() && tempDir.isDirectory()) {
File[] spireTempFiles = tempDir.listFiles((dir, name) -> File[] spireTempFiles = tempDir.listFiles((dir, name) ->
name.startsWith("+~JF") && name.endsWith(".tmp") name.startsWith("+~JF") && name.endsWith(".tmp")
); );
if (spireTempFiles != null && spireTempFiles.length > 0) { if (spireTempFiles != null && spireTempFiles.length > 0) {
int count = 0;
long totalSize = 0;
// 删30分钟前的数据 // 删30分钟前的数据
long oneMinuteAgo = System.currentTimeMillis() - 30L * 60 * 1000; long thirtyMinutesAgo = System.currentTimeMillis() - 30L * 60 * 1000;
long fileSize;
for (File file : spireTempFiles) { for (File file : spireTempFiles) {
if (file.isFile() && file.canWrite()) { if (file.isFile() && file.canWrite() && file.lastModified() < thirtyMinutesAgo) {
if (file.isFile() && file.canWrite() && file.lastModified() < oneMinuteAgo) { file.delete();
fileSize = file.length();
if (file.delete()) {
count++;
totalSize += fileSize;
}
}
} }
} }
log.info("清理 Spire.XLS 临时文件完成:删除 {} 个文件,释放 {} MB 空间",
count, totalSize / 1024 / 1024);
} }
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -90,12 +90,7 @@ public class ExcelToImage { ...@@ -90,12 +90,7 @@ public class ExcelToImage {
return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagConvertError+e.getMessage()); return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagConvertError+e.getMessage());
} finally { } finally {
if (wb != null) { if (wb != null) {
try { wb.dispose(); // 重要:释放资源并删除临时文件
wb.dispose();
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
} }
if (tempFile != null && tempFile.exists()){ if (tempFile != null && tempFile.exists()){
tempFile.delete(); tempFile.delete();
......
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