diff --git a/ParamDownload/pom.xml b/ParamDownload/pom.xml index 837b483d..9769bb50 100644 --- a/ParamDownload/pom.xml +++ b/ParamDownload/pom.xml @@ -162,7 +162,7 @@ cn.hutool hutool-all - 5.3.7 + 5.7.16 diff --git a/ParamDownload/src/main/java/com/nm/gsgl/common/Constant.java b/ParamDownload/src/main/java/com/nm/gsgl/common/Constant.java index e21a36df..ec2de810 100644 --- a/ParamDownload/src/main/java/com/nm/gsgl/common/Constant.java +++ b/ParamDownload/src/main/java/com/nm/gsgl/common/Constant.java @@ -184,6 +184,7 @@ public class Constant { //测试环境使用 begin public static final String SELECT_TF_DOWNLOAD_NOTIFY_BLACK = "SELECT ID,SYSTEMID,TABLENAME,BATCHNO,VERSION,PROTOCOL_TYPE,CREATETIME,RECORDNUM,UPDATEFLAG,UPDATETIME,DOMAIN1,DOMAIN2,DOMAIN3,DOMAIN4 FROM TF_DOWNLOAD_NOTIFY_CS where createtime>=to_date('20240624','yyyyMMdd') and protocol_type in(101,102,103,104,105,106,107,108,111,801,802,808,809,919,920) and updateflag=0 and length(domain1)>18 and substr(domain1,0,3)='ftp'"; public static final String SELECT_TF_DOWNLOAD_NOTIFY_INSERT_DB = "SELECT ID,SYSTEMID,TABLENAME,BATCHNO,VERSION,PROTOCOL_TYPE,CREATETIME,RECORDNUM,UPDATEFLAG,UPDATETIME,DOMAIN1,DOMAIN2,DOMAIN3,DOMAIN4 FROM TF_DOWNLOAD_NOTIFY_CS where createtime>=to_date('20240624','yyyyMMdd') and protocol_type in(237,240,241,242,243,244,245,246,302,304,306,501,502,503,604,605,804,803,901,902,903,904,905,917,918,922,923,924,925) and updateflag=0 and length(domain1)>18 and substr(domain1,0,3)='ftp'"; + //public static final String SELECT_TF_DOWNLOAD_NOTIFY_INSERT_DB = "SELECT ID,SYSTEMID,TABLENAME,BATCHNO,VERSION,PROTOCOL_TYPE,CREATETIME,RECORDNUM,UPDATEFLAG,UPDATETIME,DOMAIN1,DOMAIN2,DOMAIN3,DOMAIN4 FROM TF_DOWNLOAD_NOTIFY_CS where createtime>=to_date('2024-06-26 00:00:00','yyyy-mm-dd hh24:mi:ss') and createtime<=to_date('2024-07-04 16:30:00','yyyy-mm-dd hh24:mi:ss') and protocol_type in(242) and updateflag=1 and length(domain1)>18 and substr(domain1,0,3)='ftp'"; public static final String UPDATE_TF_DOWNLOAD_NOTIFY_HR = "UPDATE TF_DOWNLOAD_NOTIFY_CS SET UPDATEFLAG = 1 WHERE ID ="; //public static final String UPDATE_TF_DOWNLOAD_NOTIFY_HR = "UPDATE TF_DOWNLOAD_NOTIFY_CS SET UPDATEFLAG = 2 WHERE ID ="; public static final String SELECT_TF_DOWNLOAD_NOTIFY_MIN_FEE = "SELECT ID,SYSTEMID,TABLENAME,BATCHNO,VERSION,PROTOCOL_TYPE,CREATETIME,RECORDNUM,UPDATEFLAG,UPDATETIME,DOMAIN1,DOMAIN2,DOMAIN3,DOMAIN4 FROM TF_DOWNLOAD_NOTIFY_CS where createtime>=to_date('20230101','yyyyMMdd') and protocol_type in(250) and updateflag=0 and length(domain1)>18 and substr(domain1,0,3)='ftp'"; diff --git a/ParamDownload/src/main/java/com/nm/gsgl/common/timetask/TimeTaskInfo.java b/ParamDownload/src/main/java/com/nm/gsgl/common/timetask/TimeTaskInfo.java index 7fd6116b..727648ce 100644 --- a/ParamDownload/src/main/java/com/nm/gsgl/common/timetask/TimeTaskInfo.java +++ b/ParamDownload/src/main/java/com/nm/gsgl/common/timetask/TimeTaskInfo.java @@ -1,13 +1,14 @@ package com.nm.gsgl.common.timetask; +import com.nm.gsgl.common.Constant; import com.nm.gsgl.common.utils.LogUtil; +import com.nm.gsgl.common.utils.PropertiesUtil; import com.nm.gsgl.common.utils.UuidUtil; import com.nm.gsgl.service.CallSendOutInterfaceService; import com.nm.gsgl.service.DelOverdueService; import com.nm.gsgl.service.EctService; import com.nm.gsgl.service.IntoDatabaseService; import com.nm.gsgl.service.MinFeeService; -import com.nm.gsgl.service.SqliteBackupsService; import org.springframework.context.annotation.PropertySource; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; @@ -135,7 +136,13 @@ public class TimeTaskInfo { LogUtil.WriteLog_InsertDB("[uuid:" + uuid + "]-根据配置时间定时将入库文件入库操作,当前时间=" + LocalDateTime.now(), "TimeTaskInfo-timeTaskIntoDatabase"); long start = System.currentTimeMillis(); - boolean b = intoDatabaseService.downAndInsert(uuid); + boolean b=false; + //1-入库,0-不入库 + String isNotInsertDb = PropertiesUtil.getValue("isNotInsertDb"); + if (Constant.STR_ONE.equals(isNotInsertDb)) { + b = intoDatabaseService.downAndInsert(uuid); + + } long end = System.currentTimeMillis(); if (b) { //insertDBLog.info("[uuid:{}]-根据配置时间定时下载入库文件执行完成,耗时毫秒:{}", uuid, (end - start)); diff --git a/ParamDownload/src/main/java/com/nm/gsgl/common/utils/JsonUtils.java b/ParamDownload/src/main/java/com/nm/gsgl/common/utils/JsonUtils.java new file mode 100644 index 00000000..5f9fa360 --- /dev/null +++ b/ParamDownload/src/main/java/com/nm/gsgl/common/utils/JsonUtils.java @@ -0,0 +1,54 @@ +package com.nm.gsgl.common.utils; + +import cn.hutool.json.JSONArray; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; + +/** + * @author: shuguang + * @date: 2024年07月04日 11:31 + * @description: + */ +public class JsonUtils { + public static int getTollFee(String json){ + JSONArray jsonArray = new JSONArray(json); + + // 初始化求和变量 + int sum = 0; + + // 遍历JSONArray中的每个元素 + for (Object obj : jsonArray) { + String s = JSON.toJSONString(obj); + JSONObject ob = JSONObject.parseObject(s); + + // 检查serProvinceId是否为150201 + if ("150201".equals(ob.get("serProvinceId").toString())) { + // 累加tollFee + sum += ob.getInteger("tollFee"); + } + } + return sum; + } + public static void main(String[] args) { + String json = "[{\"enPointId\":\"X0614150010010\",\"enTime\":\"2024-07-03T15:01:48\",\"enTollStationName\":null,\"exPointId\":\"X0614150010010\",\"exTime\":\"2024-07-03T15:01:48\",\"exTollStationName\":\"内蒙壕托线\",\"id\":\"X061415001001030205302024070315014885000\",\"serProvinceId\":\"150201\",\"tollFee\":4500,\"tollIntervalChargeFee\":\"4500\",\"tollIntervalDiscountFee\":\"0\",\"tollIntervalPayFee\":\"4500\",\"tollIntervalRateVersion\":null,\"tollIntervals\":\"X061415001001010\"}]"; + // 使用Hutool的JsonUtil解析JSON字符串为JSONArray + JSONArray jsonArray = new JSONArray(json); + + // 初始化求和变量 + int sum = 0; + + // 遍历JSONArray中的每个元素 + for (Object obj : jsonArray) { + String s = JSON.toJSONString(obj); + JSONObject ob = JSONObject.parseObject(s); + + // 检查serProvinceId是否为150201 + if ("150201".equals(ob.get("serProvinceId").toString())) { + // 累加tollFee + sum += ob.getInteger("tollFee"); + } + } + System.out.println("Sum of tollFee where serProvinceId is 150201: " + sum); + } + +} diff --git a/ParamDownload/src/main/java/com/nm/gsgl/common/utils/SqliteUtil.java b/ParamDownload/src/main/java/com/nm/gsgl/common/utils/SqliteUtil.java new file mode 100644 index 00000000..89116455 --- /dev/null +++ b/ParamDownload/src/main/java/com/nm/gsgl/common/utils/SqliteUtil.java @@ -0,0 +1,61 @@ +package com.nm.gsgl.common.utils; + + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; + +/** + * @author: shuguang + * @date: 2024年07月02日 8:48 + * @description: + */ +public class SqliteUtil { + + public static void backupDatabase(String sourcePath, String backupPath) throws Exception { + // 加载SQLite JDBC驱动 + Class.forName("org.sqlite.JDBC"); + + // 建立到源数据库的连接 + Connection sourceConnection = DriverManager.getConnection("jdbc:sqlite:" + sourcePath); + + // 打开源数据库的"读写"连接 + Statement statement = sourceConnection.createStatement(); + + // 创建备份文件 + File backupFile = new File(backupPath); + if (backupFile.exists()) { + backupFile.delete(); + } + backupFile.createNewFile(); + + // 执行数据库备份命令 + statement.executeQuery("VACUUM"); // SQLITE自带的备份命令 + statement.executeQuery("ATTACH DATABASE '" + backupPath + "' AS backup_db"); + statement.executeQuery("BACKUP DATABASE TO backup_db"); + statement.executeQuery("DETACH DATABASE backup_db"); + + // 关闭连接 + statement.close(); + sourceConnection.close(); + } + public static void main(String[] args) { + String uuid = UuidUtil.getUuid(); + String sqlitePath = PathUtil.webPathSqlite+ "identifier.sqlite"; + LogUtil.WriteLog_BackupSqlite("[uuid:" + uuid + "]-开始备份sqlite文件" + sqlitePath, "SqliteBackupsServiceImpl"); + String sqliteBackupsPath = PathUtil.backUpPath+"/sqliteBackups/"; + FileUtil.fileCreat(sqliteBackupsPath); + + // 执行备份 + try { + SqliteUtil.backupDatabase(sqlitePath, sqliteBackupsPath+"identifier.sqlite"); + } catch (Exception e) { + LogUtil.WriteLog_Error("[uuid:" + uuid + "]-备份sqlite失败" +e.getMessage()+ e, "SqliteBackupsServiceImpl"); + + } + + LogUtil.WriteLog_BackupSqlite("[uuid:" + uuid + "]-备份sqlite到目录" + sqliteBackupsPath+"identifier.sqlite", "SqliteBackupsServiceImpl"); + } + +} diff --git a/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OtherOutPort.java b/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OtherOutPort.java index a042be1a..48b2735e 100644 --- a/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OtherOutPort.java +++ b/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OtherOutPort.java @@ -15,6 +15,7 @@ import java.util.List; */ @Data @TableName("CT_OTHER_OUT_PORT") +//@TableName("CT_OTHER_OUT_PORT_JAVA") public class OtherOutPort { /** *出口交易编号 @@ -261,4 +262,6 @@ public class OtherOutPort { */ @TableField("BASICFILENAME") private String basicFilename; + @TableField("SPLITFEE") + private Integer splitFee; } diff --git a/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OutPortEtc.java b/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OutPortEtc.java index 740afa48..cb278da7 100644 --- a/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OutPortEtc.java +++ b/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OutPortEtc.java @@ -21,6 +21,7 @@ import java.util.List; @Data @TableName("CT_OUT_PORT_ETC") +//@TableName("CT_OUT_PORT_ETC_JAVA") @NoArgsConstructor public class OutPortEtc implements Serializable { //public class OutPortEtc { @@ -194,4 +195,6 @@ public class OutPortEtc implements Serializable { */ @TableField("BASICFILENAME") private String basicFilename; + @TableField("SPLITFEE") + private Integer splitFee; } diff --git a/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OutPortEtcNopay.java b/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OutPortEtcNopay.java index fb33ff55..c5513675 100644 --- a/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OutPortEtcNopay.java +++ b/ParamDownload/src/main/java/com/nm/gsgl/entity/business/db/OutPortEtcNopay.java @@ -15,6 +15,8 @@ import java.util.List; */ @Data @TableName("CT_OUT_PORT_ETC_NOPAY") +//@TableName("CT_OUT_PORT_ETC_NOPAY_JAVA") + public class OutPortEtcNopay { /** *出口省中心 Id,表示交易文件是由哪个出口省中心生成的 @@ -186,4 +188,6 @@ public class OutPortEtcNopay { */ @TableField("BASICFILENAME") private String basicFilename; + @TableField("SPLITFEE") + private Integer splitFee; } diff --git a/ParamDownload/src/main/java/com/nm/gsgl/service/impl/ApplicationRunnerImpl.java b/ParamDownload/src/main/java/com/nm/gsgl/service/impl/ApplicationRunnerImpl.java index cad5b2df..9aed00d3 100644 --- a/ParamDownload/src/main/java/com/nm/gsgl/service/impl/ApplicationRunnerImpl.java +++ b/ParamDownload/src/main/java/com/nm/gsgl/service/impl/ApplicationRunnerImpl.java @@ -24,12 +24,13 @@ public class ApplicationRunnerImpl implements ApplicationRunner { String sqliteBackupsPath = PathUtil.backUpPath + "/sqliteBackups/identifier.sqlite"; File backUp = new File(sqliteBackupsPath); if (backUp.exists()) { + long start = System.currentTimeMillis(); //log.info("identifier.sqlite存在备份,恢复备份,当前时间={}", LocalDateTime.now()); LogUtil.WriteLog_Info("identifier.sqlite存在备份,恢复备份,当前时间="+LocalDateTime.now(), "ApplicationRunnerImpl"); File my = new File(sqlitePath); my.delete(); FileUtil.copyFile(sqliteBackupsPath, sqlitePath); - long start = System.currentTimeMillis(); + long end = System.currentTimeMillis(); //log.info("identifier.sqlite恢复执行完成,耗时:{}毫秒", end - start); LogUtil.WriteLog_Info("identifier.sqlite恢复执行完成,耗时毫秒"+(end - start), "ApplicationRunnerImpl"); diff --git a/ParamDownload/src/main/java/com/nm/gsgl/service/impl/CreateDbServiceImpl.java b/ParamDownload/src/main/java/com/nm/gsgl/service/impl/CreateDbServiceImpl.java index cc35a89b..22301b19 100644 --- a/ParamDownload/src/main/java/com/nm/gsgl/service/impl/CreateDbServiceImpl.java +++ b/ParamDownload/src/main/java/com/nm/gsgl/service/impl/CreateDbServiceImpl.java @@ -11,6 +11,7 @@ import com.nm.gsgl.common.exception.PPException; 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.JsonUtils; import com.nm.gsgl.common.utils.LogUtil; import com.nm.gsgl.common.utils.PathUtil; import com.nm.gsgl.common.utils.PropertiesUtil; @@ -1368,6 +1369,8 @@ public class CreateDbServiceImpl implements CreateDbService { op.setProvinceDiscountFee((mapList.get("provinceDiscountFee") != null) ? Long.valueOf(String.valueOf(mapList.get("provinceDiscountFee"))) : null); op.setOriginFee((mapList.get("originFee") != null) ? Long.valueOf(String.valueOf(mapList.get("originFee"))) : null); op.setSplitProvince(JSONObject.toJSONString(mapList.get("splitProvince"), JSONWriter.Feature.WriteMapNullValue)); + //2024-07-04增加 + op.setSplitFee(JsonUtils.getTollFee(mapList.get("splitProvince").toString())); op.setBasicFilename(fileName); otherOutPortMapper.insert(op); count++; @@ -1427,6 +1430,9 @@ public class CreateDbServiceImpl implements CreateDbService { op.setAppointId(StringUtils.isNotBlank((CharSequence) mapList.get("appointId")) ? (String) mapList.get("appointId") : null); op.setResult((mapList.get("result") != null) ? Integer.valueOf(String.valueOf(mapList.get("result"))) : null); op.setSplitProvince(JSONObject.toJSONString(mapList.get("splitProvince"), JSONWriter.Feature.WriteMapNullValue)); + + //2024-07-04增加 + op.setSplitFee(JsonUtils.getTollFee(mapList.get("splitProvince").toString())); op.setBasicFilename(fileName); outPortEtcNopayMapper.insert(op); @@ -1490,6 +1496,8 @@ public class CreateDbServiceImpl implements CreateDbService { op.setVehicleSign(StringUtils.isNotBlank((CharSequence) mapList.get("vehicleSign")) ? (String) mapList.get("vehicleSign") : null); op.setAppointId(StringUtils.isNotBlank((CharSequence) mapList.get("appointId")) ? (String) mapList.get("appointId") : null); op.setSplitProvince(JSONObject.toJSONString(mapList.get("splitProvince"), JSONWriter.Feature.WriteMapNullValue)); + //2024-07-04增加 + op.setSplitFee(JsonUtils.getTollFee(mapList.get("splitProvince").toString())); op.setBasicFilename(fileName); outPortEtcMapper.insert(op); count++; diff --git a/ParamDownload/src/main/java/com/nm/gsgl/service/impl/SqliteBackupsServiceImpl.java b/ParamDownload/src/main/java/com/nm/gsgl/service/impl/SqliteBackupsServiceImpl.java index 74b10745..3b368828 100644 --- a/ParamDownload/src/main/java/com/nm/gsgl/service/impl/SqliteBackupsServiceImpl.java +++ b/ParamDownload/src/main/java/com/nm/gsgl/service/impl/SqliteBackupsServiceImpl.java @@ -3,6 +3,7 @@ package com.nm.gsgl.service.impl; import com.nm.gsgl.common.utils.FileUtil; import com.nm.gsgl.common.utils.LogUtil; import com.nm.gsgl.common.utils.PathUtil; +import com.nm.gsgl.common.utils.SqliteUtil; import com.nm.gsgl.service.SqliteBackupsService; import org.springframework.stereotype.Service; @@ -23,17 +24,19 @@ public class SqliteBackupsServiceImpl implements SqliteBackupsService { @Override public void buildBackups(String uuid) { String sqlitePath = PathUtil.webPathSqlite+ "identifier.sqlite"; - //log.info("[uuid:{}]开始备份sqlite文件{}", uuid,sqlitePath); LogUtil.WriteLog_BackupSqlite("[uuid:" + uuid + "]-开始备份sqlite文件" + sqlitePath, "SqliteBackupsServiceImpl"); - //if(!FileUtil.fileExists(sqlitePath)){ - // //log.info("[uuid:{}]备份sqlite文件{}不存在", uuid,sqlitePath); - // LogUtil.WriteLog_BackupSqlite("[uuid:" + uuid + "]-备份sqlite文件不存在" + sqlitePath, "SqliteBackupsServiceImpl"); - // return false; - //} String sqliteBackupsPath = PathUtil.backUpPath+"/sqliteBackups/"; FileUtil.fileCreat(sqliteBackupsPath); - FileUtil.copyFile(sqlitePath, sqliteBackupsPath+"identifier.sqlite"); - //log.info("[uuid:{}]备份sqlite到目录{}", uuid,sqliteBackupsPath+"identifier.sqlite"); + + // 执行备份 + try { + FileUtil.copyFile(sqlitePath, sqliteBackupsPath+"identifier.sqlite"); + //SqliteUtil.backupDatabase(sqlitePath, sqliteBackupsPath+"identifier.sqlite"); + } catch (Exception e) { + LogUtil.WriteLog_Error("[uuid:" + uuid + "]-备份sqlite失败" +e.getMessage()+ e, "SqliteBackupsServiceImpl"); + + } + LogUtil.WriteLog_BackupSqlite("[uuid:" + uuid + "]-备份sqlite到目录" + sqliteBackupsPath+"identifier.sqlite", "SqliteBackupsServiceImpl"); } }