参数下载服务程序优化,生成最小费额文件时报错处理,针对nfs网络延迟问题,将最小费额文件本地目录生成再上传的nfs共享目录

main
gaoshuguang 1 year ago
parent 0c0ca2b421
commit 61bd7d167b

@ -0,0 +1,19 @@
package com.nm.gsgl.service.impl;
import com.nm.gsgl.entity.sqlite.BusinessTasks;
/**
* @author: shuguang
* @date: 20231030 21:13
* @description: SQB
*/
public interface CreateMinFeeSqbService {
/**
*dllosSQB()
* @author shuguang
* @date 2024-10-30 21:13
* @param uuid uuid
* @param businessTask Sqlite
*/
void createMinFeeSqbNew(String uuid, BusinessTasks businessTask);
}

@ -0,0 +1,286 @@
package com.nm.gsgl.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.nm.gsgl.common.Constant;
import com.nm.gsgl.common.config.MyEnvironmentPostProcessor;
import com.nm.gsgl.common.dbfmodule.CMinFeeCreator;
import com.nm.gsgl.common.utils.DatabaseUtil;
import com.nm.gsgl.common.utils.DateTimeUtil;
import com.nm.gsgl.common.utils.FileUtil;
import com.nm.gsgl.common.utils.LogUtil;
import com.nm.gsgl.common.utils.MD5Util;
import com.nm.gsgl.common.utils.PathUtil;
import com.nm.gsgl.common.utils.PropertiesUtil;
import com.nm.gsgl.common.utils.UnzipUtil;
import com.nm.gsgl.entity.business.NameTable;
import com.nm.gsgl.entity.dis.DisMinFeeFile;
import com.nm.gsgl.entity.sqlite.BusinessTasks;
import com.nm.gsgl.mapper.NameTableMapper;
import com.nm.gsgl.mapper.dis.DisMinFeeFileMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.File;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
/**
* @author: shuguang
* @date: 20241030 21:15
* @description:
*/
@Service
public class CreateMinFeeSqbServiceImpl implements CreateMinFeeSqbService{
@Value("${sqliteDriverName}")
private String sqliteDriverName;
@Value("${sqliteUrl}")
private String sqliteUrl;
@Resource
private NameTableMapper nameTableMapper;
@Value("${NFSFilePath}")
public String NFSFilePath;
private static final String driverName = MyEnvironmentPostProcessor.driverClassName;
/**
*
*/
@Value("${HRConnectionStringOracle}")
private String HRConnectionStringOracle;
@Value("${HROracleName}")
private String HROracleName;
@Value("${HROraclePass}")
private String HROraclePass;
@Resource
private DisMinFeeFileMapper disMinFeeFileMapper;
/**
* dllosSQB()
*
* @param uuid uuid
* @param businessTask Sqlite
* @author shuguang
* @date 2024-10-30 21:13
*/
@Override
public void createMinFeeSqbNew(String uuid, BusinessTasks businessTask) {
byte[] bytMd5 = new byte[256];
String protocolType = businessTask.getProtocolType();
String fileName = businessTask.getFileName();
String version = businessTask.getNewVersion();
String id = businessTask.getId();
//获取本地路径将文件复制到本地路径生成SQB然后再移动到nfs共享目录中
String localDownZipPath = PropertiesUtil.getValue("localDownZipPath");
String localUnZipPath = PropertiesUtil.getValue("localUnZipPath")+File.separator + id;
String localSqbPath = PropertiesUtil.getValue("localSqbPath");
FileUtil.fileCreat(localDownZipPath);
FileUtil.fileCreat(localUnZipPath);
FileUtil.fileCreat(localSqbPath);
String nfsDownFilePath = NFSFilePath + PathUtil.downFile;
String nfsSqbPath = NFSFilePath + PathUtil.sqbPath;
FileUtil.fileCreat(nfsSqbPath);
//String localPath = NFSFilePath + PathUtil.downFile;
//String sqlLiteDir = NFSFilePath + PathUtil.sqbPath;
//String unZip = sqlLiteDir + "sqbUnZip";
//FileUtil.fileCreat(sqlLiteDir);
//FileUtil.fileCreat(unZip);
//压缩文件存放-会被删除
if (!FileUtil.fileExists(nfsDownFilePath + fileName)) {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-下载的zip文件不存在" + nfsDownFilePath + fileName, "CreateMinFeeSqbServiceImpl");
//更新sqlite任务表的任务状态为2-报错,轮询下次再处理
DatabaseUtil.insertSqlite(sqliteDriverName, sqliteUrl, Constant.ERROR_UPDATE_BUSINESS_HANDLER + businessTask.getId());
} else {
FileUtil.copyFile(nfsDownFilePath + fileName,localDownZipPath + fileName);
//解压之前先清空解压目标目录
FileUtil.removeFiles(new File(localUnZipPath));
List<String> stringList = UnzipUtil.decompress(localDownZipPath + fileName, localUnZipPath);
String unzipFilePath = "";
for (String s : stringList) {
unzipFilePath = s;
}
String[] split = unzipFilePath.split(Constant.STR_);
String exId = split[1];
String fileDt = split[2].replace(Constant.STR_ZIP, Constant.NULL_STRING);
QueryWrapper<NameTable> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("GBSTATIONID", exId);
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-查询的NAME_TABLE中GBSTATIONID=" + exId, "CreateMinFeeSqbServiceImpl");
NameTable nameTable = nameTableMapper.selectOne(queryWrapper);
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-查询的NAME_TABLE中GBSTATIONID=" + exId + "的数据为" + nameTable, "CreateMinFeeSqbServiceImpl");
if (nameTable != null) {
String subComNO;
subComNO = String.valueOf(nameTable.getSubComNo());
switch (subComNO) {
case "37"://十大
subComNO = "38";
break;
case "34"://大东 和城大
subComNO = "33";
break;
case "29"://东察
subComNO = "35";
break;
}
Integer staNo = nameTable.getStaNo();
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-获取分公司编号为=" + subComNO, "CreateMinFeeSqbServiceImpl");
String zlibName = "ALLROADMINFEE_" + fileDt + Constant.STR_ + staNo;
//版本号_gb编号_分公司号_站号
String staInfo = fileDt + Constant.STR_ + exId + Constant.STR_ + subComNO + Constant.STR_ + staNo;
String localSqbPathDll = localSqbPath + "SQLLITE" + File.separator + fileDt + File.separator + subComNO + File.separator;
FileUtil.fileCreat(localSqbPathDll);
String nfsSqbPathDll = nfsSqbPath + "SQLLITE" + File.separator + fileDt + File.separator + subComNO + File.separator;
FileUtil.fileCreat(nfsSqbPathDll);
//zip文件备份
String backUpDir = NFSFilePath + PathUtil.downFileBackup + "SQB" + File.separator + fileDt + File.separator + subComNO;
FileUtil.fileCreat(backUpDir);
FileUtil.copyFile(nfsDownFilePath + fileName, backUpDir + File.separator + fileName);
//获取上一版本最新的文件夹
//上一版本路径
List<Long> longs = FileUtil.folderNames(nfsSqbPath + File.separator + "SQLLITE" + File.separator);
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-获取SQB下的文件夹个数为=" + longs.size(), "CreateMinFeeSqbServiceImpl");
//排序
longs.sort(Comparator.naturalOrder());
String sqlLiteName = "ALLROADMINFEE_" + staInfo + Constant.STR_SQB;
String localSqbFileDll = localSqbPathDll + sqlLiteName;
if (longs.size() > 1) {
String pre_Version = String.valueOf(longs.get(longs.size() - 2));
String pre_sqlLitePath = nfsSqbPath + "SQLLITE" + File.separator + pre_Version + File.separator + subComNO;
//从上一版本的文件夹下找到当前站的文件
String pre_sqlLiteName = FileUtil.zlibFileName(pre_sqlLitePath, exId);
String preSqlLitePath = pre_sqlLitePath + File.separator + pre_sqlLiteName;
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-获取SQB上一个版本号是" + pre_Version + "sqb文件全路径是" + preSqlLitePath, "CreateMinFeeSqbServiceImpl");
//前一版本拷贝新版本-并重新命名
if (StringUtils.isNotBlank(pre_sqlLiteName) && FileUtil.fileExists(pre_sqlLitePath + File.separator + pre_sqlLiteName)) {
FileUtil.fileCopyReName(pre_sqlLitePath + File.separator + pre_sqlLiteName, localSqbFileDll);
} else {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-获取上一版本SQB文件不存在新创建文件" + localSqbFileDll, "CreateMinFeeSqbServiceImpl");
FileUtil.newFileCreat(localSqbFileDll);
}
} else {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-获取上一版本SQB文件不存在新创建文件" + localSqbFileDll, "CreateMinFeeSqbServiceImpl");
FileUtil.newFileCreat(localSqbFileDll);
}
String zlibFileDll = localSqbPathDll + zlibName + Constant.STR_ZLIB;
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-调用动态库生成最小费额SQB文件中,协议类型为" + protocolType + "zip文件名为" + fileName, "CreateMinFeeSqbServiceImpl");
String zipFilePath = (localDownZipPath + fileName).replace("\\", "/");
String sqbFileDllPath = localSqbFileDll.replace("\\", "/");
String zlibFileDllPath = zlibFileDll.replace("\\", "/");
int count = CMinFeeCreator.INSTANCE.MakeMinFee(zipFilePath, sqbFileDllPath, zlibFileDllPath, bytMd5);
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-调用动态库生成最小费额SQB文件返回count为" + count, "CreateMinFeeSqbServiceImpl");
if (count >= 0) {
String sqbInsertPath = NFSFilePath + File.separator + "ParamInsertDb" + File.separator + "MinFeeInToDataBase" + File.separator;
FileUtil.fileCreat(sqbInsertPath);
String newSqbBackUpName = exId + Constant.STR_ + sqlLiteName;
//sqb源文件复制到备份文件夹再重命名
FileUtil.copyFile(sqbFileDllPath, sqbInsertPath + newSqbBackUpName);
FileUtil.copyFile(sqbFileDllPath, nfsSqbPathDll + sqlLiteName);
//获取生成的zlib的文件名
String zlibFileNameMd5 = FileUtil.zlibFileName(localSqbPathDll, zlibName.replace(Constant.STR_ZLIB, Constant.NULL_STRING) + Constant.STR_);
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-获取zlib的文件名称为" + zlibFileNameMd5, "CreateMinFeeSqbServiceImpl");
FileUtil.copyFile(localSqbPathDll+ File.separator +zlibFileNameMd5, nfsSqbPathDll + zlibFileNameMd5);
//获取高路分中心需要下发的收费站编码,如果是多个站,站编码用,间隔
String glMinFeeFZXs = PropertiesUtil.getValue("GLMinFeeFZXs");
String glMinFeeStaNos = PropertiesUtil.getValue("GLMinFeeStaNos");
if (StringUtils.isNotBlank(glMinFeeFZXs) && StringUtils.isNotBlank(glMinFeeStaNos)) {
String[] split1 = glMinFeeFZXs.split(Constant.FIELD_SEPARATE);
String[] split2 = glMinFeeStaNos.split(Constant.FIELD_SEPARATE);
for (String subcomno : split1) {
for (String stano : split2) {
if (zlibFileNameMd5.contains(Constant.STR_ + stano + Constant.STR_)) {
//按照分中心的编码存入数据库表联网中心最小费额下发分中心表
QueryWrapper<DisMinFeeFile> query = new QueryWrapper<>();
query.eq("SUBCOMNO", subcomno).eq("STANO", stano);
//判断是否存在此分公司和收费站的最小费额数据
boolean exists = disMinFeeFileMapper.exists(query);
if (!exists) {
DisMinFeeFile file = new DisMinFeeFile();
file.setSubComNO(Integer.valueOf(subcomno));
file.setStaNo(Integer.valueOf(stano));
file.setZlibName(zlibFileNameMd5);
file.setZlibPath(nfsSqbPathDll);
file.setMd5(MD5Util.getMd5ByFilePath(nfsSqbPathDll + File.separator + zlibFileNameMd5));
file.setVersion(version);
file.setCreateTime(new Date());
file.setState(0);
disMinFeeFileMapper.insert(file);
} else {
//更新
UpdateWrapper<DisMinFeeFile> updateWrap = new UpdateWrapper<>();
updateWrap.eq("SUBCOMNO", Integer.valueOf(subcomno)).eq("STANO", Integer.valueOf(stano)).set("ZLIBNAME", zlibFileNameMd5).set("ZLIBPATH", nfsSqbPathDll).set("MD5", MD5Util.getMd5ByFilePath(nfsSqbPathDll + File.separator + zlibFileNameMd5)).set("VERSION", version).set("UPDATETIME", new Date()).set("STATE", 0);
disMinFeeFileMapper.update(null, updateWrap);
}
}
}
}
}
//最小费额按照分中心下发,下发到分中心后,分中心手动下发到车道
//按照分中心的编码存入数据库表联网中心最小费额下发分中心表
QueryWrapper<DisMinFeeFile> query = new QueryWrapper<>();
query.eq("SUBCOMNO", subComNO).eq("STANO", staNo);
//判断是否存在此分公司和收费站的最小费额数据
boolean exists = disMinFeeFileMapper.exists(query);
if (!exists) {
DisMinFeeFile file = new DisMinFeeFile();
file.setSubComNO(Integer.parseInt(subComNO));
file.setStaNo(staNo);
file.setZlibName(zlibFileNameMd5);
file.setZlibPath(nfsSqbPathDll);
file.setMd5(MD5Util.getMd5ByFilePath(nfsSqbPathDll + File.separator + zlibFileNameMd5));
file.setVersion(version);
file.setCreateTime(new Date());
file.setState(0);
disMinFeeFileMapper.insert(file);
} else {
//更新
UpdateWrapper<DisMinFeeFile> updateWrap = new UpdateWrapper<>();
updateWrap.eq("SUBCOMNO", Integer.parseInt(subComNO)).eq("STANO", staNo).set("ZLIBNAME", zlibFileNameMd5).set("ZLIBPATH", nfsSqbPathDll).set("MD5", MD5Util.getMd5ByFilePath(nfsSqbPathDll + File.separator + zlibFileNameMd5)).set("VERSION", version).set("UPDATETIME", new Date()).set("STATE", 0);
disMinFeeFileMapper.update(null, updateWrap);
}
FileUtil.delete(new File(sqbFileDllPath));
FileUtil.delete(new File(localUnZipPath +File.separator+ businessTask.getFileName()));
FileUtil.delete(new File(localDownZipPath + businessTask.getFileName()));
FileUtil.delete(new File(NFSFilePath + PathUtil.downFile + businessTask.getFileName()));
FileUtil.delete(new File(localSqbPathDll+ File.separator +zlibFileNameMd5));
String nowString = DateTimeUtil.getFormateString(new Date(), Constant.YYYY_MM_DD_HH_MM_SS);
String sqlParam = Constant.UPDATE_BUSINESS_HANDLER + nowString + Constant.PUBLISH_TIME + nowString + Constant.WHERE_ID + businessTask.getId();
if (DatabaseUtil.insertSqlite(sqliteDriverName, sqliteUrl, sqlParam) > 0) {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-更新business_tasks_info调用动态库任务列表成功id为" + businessTask.getId(), "CreateMinFeeSqbServiceImpl");
}
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-更新中介库TF_DOWNLOAD_NOTIFY(id为" + id + ")下载状态为1-已下载", "MinFeeServiceImpl");
DatabaseUtil.updateSql(driverName, HRConnectionStringOracle, HROracleName, HROraclePass, Constant.UPDATE_TF_DOWNLOAD_NOTIFY_HR + id, uuid);
} else {
LogUtil.WriteLog_Error("[uuid:" + uuid + "]-调用动态库生成最小费额SQB操作失败返回值count为" + count, "CreateMinFeeSqbServiceImpl");
//更新sqlite任务表的任务状态为2-报错
DatabaseUtil.insertSqlite(sqliteDriverName, sqliteUrl, Constant.ERROR_UPDATE_BUSINESS_HANDLER + businessTask.getId());
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-最小费额文件数据处理失败,中介下载任务(id为" + id + ")不更新", "MinFeeServiceImpl");
}
} else {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-查询的NAME_TABLE中GBSTATIONID=" + exId + "的数据为null,跳过本次处理", "CreateMinFeeSqbServiceImpl");
String nowString = DateTimeUtil.getFormateString(new Date(), Constant.YYYY_MM_DD_HH_MM_SS);
String sqlParam = Constant.UPDATE_BUSINESS_HANDLER + nowString + Constant.PUBLISH_TIME + nowString + Constant.WHERE_ID + businessTask.getId();
if (DatabaseUtil.insertSqlite(sqliteDriverName, sqliteUrl, sqlParam) > 0) {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-更新business_tasks_info调用动态库任务列表成功id为" + businessTask.getId(), "CreateMinFeeSqbServiceImpl");
}
}
}
}
}

@ -3,6 +3,7 @@ package com.nm.gsgl.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.nm.gsgl.common.Constant; import com.nm.gsgl.common.Constant;
import com.nm.gsgl.common.config.MyEnvironmentPostProcessor;
import com.nm.gsgl.common.dbfmodule.CMinFeeCreator; import com.nm.gsgl.common.dbfmodule.CMinFeeCreator;
import com.nm.gsgl.common.utils.DatabaseUtil; import com.nm.gsgl.common.utils.DatabaseUtil;
import com.nm.gsgl.common.utils.DateTimeUtil; import com.nm.gsgl.common.utils.DateTimeUtil;
@ -45,6 +46,16 @@ public class CreateSqbByDllServiceImpl implements CreateSqbByDllService {
private NameTableMapper nameTableMapper; private NameTableMapper nameTableMapper;
@Value("${NFSFilePath}") @Value("${NFSFilePath}")
public String NFSFilePath; public String NFSFilePath;
private static final String driverName = MyEnvironmentPostProcessor.driverClassName;
/**
*
*/
@Value("${HRConnectionStringOracle}")
private String HRConnectionStringOracle;
@Value("${HROracleName}")
private String HROracleName;
@Value("${HROraclePass}")
private String HROraclePass;
@Resource @Resource
private DisMinFeeFileMapper disMinFeeFileMapper; private DisMinFeeFileMapper disMinFeeFileMapper;
//public static Logger log = LoggerFactory.getLogger("MinFee"); //public static Logger log = LoggerFactory.getLogger("MinFee");
@ -67,6 +78,7 @@ public class CreateSqbByDllServiceImpl implements CreateSqbByDllService {
String protocolType = businessTask.getProtocolType(); String protocolType = businessTask.getProtocolType();
String fileName = businessTask.getFileName(); String fileName = businessTask.getFileName();
String version = businessTask.getNewVersion(); String version = businessTask.getNewVersion();
String id = businessTask.getId();
//压缩文件存放-会被删除 //压缩文件存放-会被删除
if (!FileUtil.fileExists(localPath + fileName)) { if (!FileUtil.fileExists(localPath + fileName)) {
//log.info("[uuid:{}]下载的zip文件{}不存在", uuid, localPath + fileName); //log.info("[uuid:{}]下载的zip文件{}不存在", uuid, localPath + fileName);
@ -185,7 +197,7 @@ public class CreateSqbByDllServiceImpl implements CreateSqbByDllService {
String newSqbBackUpName = exId + Constant.STR_ + sqlLiteName; String newSqbBackUpName = exId + Constant.STR_ + sqlLiteName;
//sqb源文件复制到备份文件夹再重命名 //sqb源文件复制到备份文件夹再重命名
FileUtil.copyFile(sqbFileDllPath, sqbInsertPath + newSqbBackUpName); FileUtil.copyFile(sqbFileDllPath, sqbInsertPath + newSqbBackUpName);
FileUtil.delete(new File(NFSFilePath + PathUtil.downFile + businessTask.getFileName()));
//获取生成的zlib的文件名 //获取生成的zlib的文件名
String zlibFileNameMd5 = FileUtil.zlibFileName(sqlLitePathDll, zlibName.replace(Constant.STR_ZLIB, Constant.NULL_STRING) + Constant.STR_); String zlibFileNameMd5 = FileUtil.zlibFileName(sqlLitePathDll, zlibName.replace(Constant.STR_ZLIB, Constant.NULL_STRING) + Constant.STR_);
@ -257,12 +269,17 @@ public class CreateSqbByDllServiceImpl implements CreateSqbByDllService {
//log.info("[uuid:{}]更新business_tasks_info调用动态库任务列表成功id为:{}", uuid, businessTask.getId()); //log.info("[uuid:{}]更新business_tasks_info调用动态库任务列表成功id为:{}", uuid, businessTask.getId());
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-更新business_tasks_info调用动态库任务列表成功id为" + businessTask.getId(), "CreateSqbByDllServiceImpl"); LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-更新business_tasks_info调用动态库任务列表成功id为" + businessTask.getId(), "CreateSqbByDllServiceImpl");
} }
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-更新中介库TF_DOWNLOAD_NOTIFY(id为" + id + ")下载状态为1-已下载", "MinFeeServiceImpl");
DatabaseUtil.updateSql(driverName, HRConnectionStringOracle, HROracleName, HROraclePass, Constant.UPDATE_TF_DOWNLOAD_NOTIFY_HR + id, uuid);
} else { } else {
//log.error("[uuid:{}]调用动态库生成SQB操作失败返回值count为{}", uuid, count); //log.error("[uuid:{}]调用动态库生成SQB操作失败返回值count为{}", uuid, count);
LogUtil.WriteLog_Error("[uuid:" + uuid + "]-调用动态库生成最小费额SQB操作失败返回值count为" + count, "CreateSqbByDllServiceImpl"); LogUtil.WriteLog_Error("[uuid:" + uuid + "]-调用动态库生成最小费额SQB操作失败返回值count为" + count, "CreateSqbByDllServiceImpl");
//更新sqlite任务表的任务状态为2-报错 //更新sqlite任务表的任务状态为2-报错
DatabaseUtil.insertSqlite(sqliteDriverName, sqliteUrl, Constant.ERROR_UPDATE_BUSINESS_HANDLER + businessTask.getId()); DatabaseUtil.insertSqlite(sqliteDriverName, sqliteUrl, Constant.ERROR_UPDATE_BUSINESS_HANDLER + businessTask.getId());
//throw new PPException(MessageEnum.调用动态库生成SQB操作失败.getCode(), MessageEnum.调用动态库生成SQB操作失败.getMessage()); //throw new PPException(MessageEnum.调用动态库生成SQB操作失败.getCode(), MessageEnum.调用动态库生成SQB操作失败.getMessage());
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-最小费额文件数据处理失败,中介下载任务(id为" + id + ")不更新", "MinFeeServiceImpl");
} }
} else { } else {

@ -1,11 +1,10 @@
package com.nm.gsgl.service.impl; package com.nm.gsgl.service.impl;
import com.nm.gsgl.common.Constant; import com.nm.gsgl.common.Constant;
import com.nm.gsgl.common.config.MyEnvironmentPostProcessor;
import com.nm.gsgl.common.utils.DatabaseUtil; import com.nm.gsgl.common.utils.DatabaseUtil;
import com.nm.gsgl.common.utils.FileUtil; import com.nm.gsgl.common.utils.FileUtil;
import com.nm.gsgl.common.utils.LogUtil; import com.nm.gsgl.common.utils.LogUtil;
import com.nm.gsgl.common.utils.PathUtil; import com.nm.gsgl.common.utils.PropertiesUtil;
import com.nm.gsgl.entity.sqlite.BusinessTasks; import com.nm.gsgl.entity.sqlite.BusinessTasks;
import com.nm.gsgl.service.CreateSqbByDllService; import com.nm.gsgl.service.CreateSqbByDllService;
import com.nm.gsgl.service.MinDualMachineService; import com.nm.gsgl.service.MinDualMachineService;
@ -20,8 +19,6 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -45,22 +42,13 @@ public class MinFeeServiceImpl implements MinFeeService {
private String sqliteDriverName; private String sqliteDriverName;
@Value("${sqliteUrl}") @Value("${sqliteUrl}")
private String sqliteUrl; private String sqliteUrl;
private static final String driverName = MyEnvironmentPostProcessor.driverClassName; @Value("${retainDays}")
/** private String retainDays;
*
*/
@Value("${HRConnectionStringOracle}")
private String HRConnectionStringOracle;
@Value("${HROracleName}")
private String HROracleName;
@Value("${HROraclePass}")
private String HROraclePass;
@Value("${NFSFilePath}")
private String NFSFilePath;
@Resource @Resource
private SqliteBackupsService sqliteBackupsService; private SqliteBackupsService sqliteBackupsService;
//public static Logger log = LoggerFactory.getLogger("MinFee"); @Resource
private CreateMinFeeSqbService createMinFeeSqbService;
/** /**
* () * ()
* *
@ -73,8 +61,7 @@ public class MinFeeServiceImpl implements MinFeeService {
//双机方案 //双机方案
//获取本机的机器ID,本机的机器ID 1-主机2-备用机 //获取本机的机器ID,本机的机器ID 1-主机2-备用机
int mId = Integer.parseInt(machineId); int mId = Integer.parseInt(machineId);
//log.info("[uuid:{}]获取当前机器的id为{}", uuid, mId); LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-获取当前机器的id为" + mId, "MinFeeServiceImpl");
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-获取当前机器的id为" +mId, "MinFeeServiceImpl");
//验证是否当前服务程序处理事件 //验证是否当前服务程序处理事件
boolean validateHR; boolean validateHR;
if (mId == 1) { if (mId == 1) {
@ -83,10 +70,10 @@ public class MinFeeServiceImpl implements MinFeeService {
validateHR = minDualMachineService.validateDualSpare(uuid, mId); validateHR = minDualMachineService.validateDualSpare(uuid, mId);
} }
//如果是当前服务处理,继续下一步,否则程序定时任务不做处理,等待下次轮询 //如果是当前服务处理,继续下一步,否则程序定时任务不做处理,等待下次轮询
//log.info("[uuid:{}]验证是否当前服务程序处理事件{}", uuid, validateHR); LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-验证是否当前服务程序处理事件" + validateHR, "MinFeeServiceImpl");
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-验证是否当前服务程序处理事件" +validateHR, "MinFeeServiceImpl");
//2024-10-24 主机生成黑名单,备机生成最小费额文件 //2024-10-24 主机生成黑名单,备机生成最小费额文件
if (!validateHR) { if (!validateHR) {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-当前机器开始生成最小费额文件", "MinFeeServiceImpl");
//开始下载扫描华软最小费额下载任务 //开始下载扫描华软最小费额下载任务
minFtpDownloadService.getMinFeeHrMdTask(uuid); minFtpDownloadService.getMinFeeHrMdTask(uuid);
//开始查询sqlite任务表中华软未处理数据任务 //开始查询sqlite任务表中华软未处理数据任务
@ -94,65 +81,18 @@ public class MinFeeServiceImpl implements MinFeeService {
if (businessTasks.size() > 0) { if (businessTasks.size() > 0) {
//for (BusinessTasks businessTask : businessTasks) {
// String protocolType = businessTask.getProtocolType();
// String id = businessTask.getId();
// //是否处理完成
// boolean isFinished = false;
// //最小费额
// if (Constant.STR_SQB_250.equals(protocolType)) {
// createSqbByDllService.createMinFeeSqbByDll(uuid, businessTask);
// isFinished = true;
// }
// if (isFinished) {
// //更新中介库华软的下载状态
// //log.info("[uuid:{}]-更新中介库TF_DOWNLOAD_NOTIFY(id为:{})下载状态为1-已下载", uuid, id);
// LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-更新中介库TF_DOWNLOAD_NOTIFY(id为" +id+")下载状态为1-已下载", "MinFeeServiceImpl");
// DatabaseUtil.updateSql(driverName, HRConnectionStringOracle, HROracleName, HROraclePass, Constant.UPDATE_TF_DOWNLOAD_NOTIFY_HR + id, uuid);
// //删除下载的zip文件
// FileUtil.delete(new File(NFSFilePath + PathUtil.downFile + businessTask.getFileName()));
//
// } else {
// //log.info("[uuid:{}]最小费额文件数据处理失败中介下载任务id{}不更新", uuid, id);
// LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-最小费额文件数据处理失败,中介下载任务(id为" +id+")不更新", "MinFeeServiceImpl");
// }
//}
//创建线程池
//ExecutorService executor = Executors.newFixedThreadPool(2); // 可以根据实际情况调整线程池的大小
int poolSize = 2; // 根据实际情况调整线程池大小
ExecutorService executor = new ThreadPoolExecutor(
poolSize,
poolSize,
0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.AbortPolicy()
);
//创建线程池
ExecutorService executor = Executors.newFixedThreadPool(2); // 可以根据实际情况调整线程池的大小
for (BusinessTasks businessTask : businessTasks) { for (BusinessTasks businessTask : businessTasks) {
final String protocolType = businessTask.getProtocolType(); final String protocolType = businessTask.getProtocolType();
final String id = businessTask.getId();
executor.submit(() -> { executor.submit(() -> {
// 执行具体的任务 // 执行具体的任务
boolean isFinished = false;
if (Constant.STR_SQB_250.equals(protocolType)) { if (Constant.STR_SQB_250.equals(protocolType)) {
createSqbByDllService.createMinFeeSqbByDll(uuid, businessTask); //createSqbByDllService.createMinFeeSqbByDll(uuid, businessTask);
isFinished = true; createMinFeeSqbService.createMinFeeSqbNew(uuid, businessTask);
} }
if (isFinished) {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-更新中介库TF_DOWNLOAD_NOTIFY(id为" + id + ")下载状态为1-已下载", "MinFeeServiceImpl");
DatabaseUtil.updateSql(driverName, HRConnectionStringOracle, HROracleName, HROraclePass, Constant.UPDATE_TF_DOWNLOAD_NOTIFY_HR + id, uuid);
FileUtil.delete(new File(NFSFilePath + PathUtil.downFile + businessTask.getFileName()));
} else {
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-最小费额文件数据处理失败,中介下载任务(id为" + id + ")不更新", "MinFeeServiceImpl");
}
}); });
} }
@ -166,7 +106,7 @@ public class MinFeeServiceImpl implements MinFeeService {
// 如果超时,则取消当前执行的任务 // 如果超时,则取消当前执行的任务
executor.shutdownNow(); executor.shutdownNow();
// 这里可以添加一些日志记录或者其他处理 // 这里可以添加一些日志记录或者其他处理
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-最小费额文件数据处理任务执行超时,已尝试取消剩余任务" , "MinFeeServiceImpl"); LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-最小费额文件数据处理任务执行超时,已尝试取消剩余任务", "MinFeeServiceImpl");
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
// 如果等待过程中被中断,重新设置线程中断标志 // 如果等待过程中被中断,重新设置线程中断标志
@ -174,11 +114,20 @@ public class MinFeeServiceImpl implements MinFeeService {
// 取消当前执行的任务 // 取消当前执行的任务
executor.shutdownNow(); executor.shutdownNow();
// 这里可以添加一些日志记录或者其他处理 // 这里可以添加一些日志记录或者其他处理
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-最小费额文件数据处理等待任务执行过程中线程被中断" , "MinFeeServiceImpl"); LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-最小费额文件数据处理等待任务执行过程中线程被中断", "MinFeeServiceImpl");
} }
} }
sqliteBackupsService.buildBackups(uuid); sqliteBackupsService.buildBackups(uuid);
//获取本地路径将文件复制到本地路径生成SQB然后再移动到nfs共享目录中
String localDownZipPath = PropertiesUtil.getValue("localDownZipPath");
String localUnZipPath = PropertiesUtil.getValue("localUnZipPath");
String localSqbPath = PropertiesUtil.getValue("localSqbPath");
FileUtil.removeFiles(new File(localDownZipPath));
FileUtil.removeFiles(new File(localUnZipPath));
FileUtil.removeFiles(new File(localSqbPath));
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-开始删除超期的sqlite任务表business_tasks_info信息,sqlite数据保留天数为" + retainDays, "MinFeeServiceImpl");
DatabaseUtil.insertSqlite(sqliteDriverName, sqliteUrl, Constant.DEL_BUSINESS_OVERDUE.replace(Constant.STR_AAAAA, retainDays));
LogUtil.WriteLog_MinFee("[uuid:" + uuid + "]-删除超期的sqlite任务表business_tasks_info信息完成", "MinFeeServiceImpl");
} }
} }
} }

Loading…
Cancel
Save