Commit 222feac8c52a8bf03db37cf0258f37d5c33a6b7e
1 parent
014e55c3
修改的定时器时间
Showing
5 changed files
with
103 additions
and
68 deletions
src/main/java/com/example/demo/SaticScheduleTask.java
| ... | ... | @@ -50,61 +50,73 @@ public class SaticScheduleTask implements InitializingBean { |
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | @Scheduled(cron = "0 0/10 * * * ?") |
| 53 | - void getArrivalInfos() throws Exception { | |
| 53 | + void getArrivalInfos(){ | |
| 54 | 54 | logger.info("票务数据缓存加载: " + LocalDateTime.now()); |
| 55 | - LocalDateTime now=LocalDateTime.now(); | |
| 56 | - List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1); | |
| 57 | - contrast.getSchedulingS=result.get(0); | |
| 58 | - contrast.getSchedulingSSell=result.get(1); | |
| 59 | - logger.info("===============================数据存放结束,开始读取文件================================"); | |
| 60 | - WatchKey watchKey = null; | |
| 61 | - List<File> files = new ArrayList<>(); | |
| 62 | - while ((watchKey = watchService.poll()) != null) { | |
| 63 | - for (WatchEvent watchEvent : watchKey.pollEvents()) { | |
| 64 | - Path path = (Path)watchEvent.context(); | |
| 65 | - if(path!=null){ | |
| 66 | - files.add(new File(rootPath + File.separator + path)); | |
| 67 | - } | |
| 55 | + try { | |
| 56 | + LocalDateTime now=LocalDateTime.now(); | |
| 57 | + List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1); | |
| 58 | + contrast.getSchedulingS=result.get(0); | |
| 59 | + contrast.getSchedulingSSell=result.get(1); | |
| 60 | + logger.info("===============================数据存放结束,开始读取文件================================"); | |
| 61 | + WatchKey watchKey = null; | |
| 62 | + List<File> files = new ArrayList<>(); | |
| 63 | + while ((watchKey = watchService.poll()) != null) { | |
| 64 | + for (WatchEvent watchEvent : watchKey.pollEvents()) { | |
| 65 | + Path path = (Path)watchEvent.context(); | |
| 66 | + if(path!=null){ | |
| 67 | + files.add(new File(rootPath + File.separator + path)); | |
| 68 | + } | |
| 68 | 69 | |
| 70 | + } | |
| 71 | + watchKey.reset(); | |
| 69 | 72 | } |
| 70 | - watchKey.reset(); | |
| 71 | - } | |
| 72 | - System.out.println("文件数"+files.size()); | |
| 73 | - logger.info("===============================文件数"+files.size()+",读取文件结束================================"); | |
| 74 | - //先把处理上一次没匹配到的 | |
| 75 | - logger.info("===============================处理上次未匹配到的数据"+contrast.oldData.size()+"================================"); | |
| 76 | - if(!contrast.oldData.isEmpty()){ | |
| 77 | - contrast.filterCardList(contrast.oldData,true); | |
| 73 | + System.out.println("文件数"+files.size()); | |
| 74 | + logger.info("===============================文件数"+files.size()+",读取文件结束================================"); | |
| 75 | + //先把处理上一次没匹配到的 | |
| 76 | + logger.info("===============================处理上次未匹配到的数据"+contrast.oldData.size()+"================================"); | |
| 77 | + if(!contrast.oldData.isEmpty()){ | |
| 78 | + contrast.filterCardList(contrast.oldData,true); | |
| 79 | + } | |
| 80 | + logger.info("===============================文件解析开始================================"); | |
| 81 | + List<TJRLDB> allFile = analysis.getAllFile(files); | |
| 82 | + logger.info("===============================交易数"+allFile.size()+"文件解析结束================================"); | |
| 83 | + contrast.filterCardList(allFile,false); | |
| 84 | + } catch (Exception e) { | |
| 85 | + e.printStackTrace(); | |
| 78 | 86 | } |
| 79 | - logger.info("===============================文件解析开始================================"); | |
| 80 | - List<TJRLDB> allFile = analysis.getAllFile(files); | |
| 81 | - logger.info("===============================交易数"+allFile.size()+"文件解析结束================================"); | |
| 82 | - contrast.filterCardList(allFile,false); | |
| 83 | 87 | } |
| 84 | 88 | |
| 85 | 89 | |
| 86 | 90 | |
| 87 | 91 | void getArrivalInfos2() { |
| 88 | 92 | logger.info("票务数据缓存加载: " + LocalDateTime.now()); |
| 89 | - LocalDateTime now=LocalDateTime.now(); | |
| 90 | - //测试 | |
| 91 | - DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | |
| 92 | - now=LocalDateTime.parse("2021-11-19 00:00",tdf); | |
| 93 | - List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1); | |
| 94 | - contrast.getSchedulingS=result.get(0); | |
| 95 | - contrast.getSchedulingSSell=result.get(1); | |
| 96 | - List<File> fl= FileUtil.loopFiles("/home/sftp/20211118"); | |
| 97 | - System.out.println(fl.size()); | |
| 98 | - List<List<File>> subList=getSubList(100,fl); | |
| 99 | - if(!subList.isEmpty()){ | |
| 100 | - subList.forEach(fs->{ | |
| 101 | - if (!fs.isEmpty()) { | |
| 102 | - System.out.println("文件数"+fs.size()); | |
| 103 | - List<TJRLDB> allFile = analysis.getAllFile(fs); | |
| 104 | - System.out.println("交易数"+allFile.size()); | |
| 105 | - contrast.filterCardList(allFile,true); | |
| 106 | - } | |
| 107 | - }); | |
| 93 | + try { | |
| 94 | + LocalDateTime now=LocalDateTime.now(); | |
| 95 | + //测试 | |
| 96 | + DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | |
| 97 | + now=LocalDateTime.parse("2021-11-19 00:00",tdf); | |
| 98 | + List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1); | |
| 99 | + contrast.getSchedulingS=result.get(0); | |
| 100 | + contrast.getSchedulingSSell=result.get(1); | |
| 101 | + List<File> fl= FileUtil.loopFiles("/home/oldFile/20211118COPY"); | |
| 102 | + System.out.println(fl.size()); | |
| 103 | + List<List<File>> subList=getSubList(100,fl); | |
| 104 | + if(!subList.isEmpty()){ | |
| 105 | + subList.forEach(fs->{ | |
| 106 | + if (!fs.isEmpty()) { | |
| 107 | + System.out.println("文件数"+fs.size()); | |
| 108 | + try { | |
| 109 | + List<TJRLDB> allFile = analysis.getAllFile(fs); | |
| 110 | + System.out.println("交易数"+allFile.size()); | |
| 111 | + contrast.filterCardList(allFile,true); | |
| 112 | + } catch (Exception e) { | |
| 113 | + e.printStackTrace(); | |
| 114 | + } | |
| 115 | + } | |
| 116 | + }); | |
| 117 | + } | |
| 118 | + } catch (Exception e) { | |
| 119 | + e.printStackTrace(); | |
| 108 | 120 | } |
| 109 | 121 | } |
| 110 | 122 | ... | ... |
src/main/java/com/example/demo/service/Analysis.java
| ... | ... | @@ -34,7 +34,7 @@ public class Analysis { |
| 34 | 34 | * @param files 需要遍历的文件夹路径 |
| 35 | 35 | * @return |
| 36 | 36 | */ |
| 37 | - public List<TJRLDB> getAllFile(List<File> files) { | |
| 37 | + public List<TJRLDB> getAllFile(List<File> files) throws Exception { | |
| 38 | 38 | List<TJRLDB> listMap = new ArrayList<>(); |
| 39 | 39 | List<String> list = new ArrayList<String>(); |
| 40 | 40 | for (File file : files) { |
| ... | ... | @@ -55,6 +55,8 @@ public class Analysis { |
| 55 | 55 | String text = strings.get(i); |
| 56 | 56 | Map<String, Object> map = new HashMap<>(); |
| 57 | 57 | TJRLDB tjrl=new TJRLDB(); |
| 58 | + String POSID=text.substring(0,8); | |
| 59 | + tjrl.setTJRLPOSID(POSID); | |
| 58 | 60 | Long val = Long.parseLong(text.substring(30, 40)); |
| 59 | 61 | String cardId = Long.toHexString(val).toUpperCase(); |
| 60 | 62 | tjrl.setTJRLDRVCRDID(cardId);//司售卡号 DriverCardId签到卡片ID号,BCD编码,司售卡卡号 |
| ... | ... | @@ -62,8 +64,7 @@ public class Analysis { |
| 62 | 64 | //map.put("CHECKINDATE", text.substring(42, 54));//签到时间YYYYMMDDhhmm,BCD编码 |
| 63 | 65 | //map.put("CHECKOUTCOUNT", text.substring(54, 60));//签到总次数,BCD编码 |
| 64 | 66 | tjrl.setTJRLTXFG(text.substring(60, 62));//交易类型 Txn Flag HEX格式,交易标志,其中88为正常交易,99为锁卡交易,BCD编码,定义见附录1交易类型对照表 |
| 65 | - String TJRLPOSID=text.substring(62, 68); | |
| 66 | - tjrl.setTJRLPOSID(TJRLPOSID);//HEX格式,消费交易流水号,BCD编码 | |
| 67 | + String POSSEQID=text.substring(62, 68);//HEX格式,消费交易流水号,BCD编码 | |
| 67 | 68 | //map.put("CITYCODE", text.substring(68, 72)); //城市代码号,BCD编码 |
| 68 | 69 | tjrl.setTJRLCARDNO(text.substring(72, 82));//CARDID消费卡的ID号,BCD编码 |
| 69 | 70 | tjrl.setTJRLCDKIND(text.substring(82, 84));//Card Type HEX格式,消费卡卡型,BCD编码 |
| ... | ... | @@ -89,7 +90,7 @@ public class Analysis { |
| 89 | 90 | tjrl.setTJRLORGAMT(text.substring(120, 124));//交易原始金额Orignal Txn Amount |
| 90 | 91 | //map.put("CARDSPEC", text.substring(124, 126)); //卡规范,BCD编码 01—建设部卡 02—交通部卡 03-交通部二维码 |
| 91 | 92 | String TAC=text.substring(126, 134);//HEX格式,交易认证码,BCD编码 |
| 92 | - String TRAD_ID=TAC+TJRLPOSID+TJRLRDATE+TJRLRTIME; | |
| 93 | + String TRAD_ID=TAC+POSSEQID+TJRLRDATE+TJRLRTIME; | |
| 93 | 94 | tjrl.setTRAD_ID(TRAD_ID);////pos交易数据需要加上 trad_id 用tac+pos流水+交易日期+交易时间 |
| 94 | 95 | |
| 95 | 96 | listMap.add(tjrl); |
| ... | ... | @@ -176,5 +177,25 @@ public class Analysis { |
| 176 | 177 | Analysis.oldFile = oldFile; |
| 177 | 178 | }*/ |
| 178 | 179 | |
| 180 | + | |
| 181 | + public static boolean containsWords(String inputString, String[] items) { | |
| 182 | + boolean found = false; | |
| 183 | + for (String item : items) { | |
| 184 | + if (inputString.contains(item)) { | |
| 185 | + found = true; | |
| 186 | + break; | |
| 187 | + } | |
| 188 | + | |
| 189 | + } | |
| 190 | + return found; | |
| 191 | + } | |
| 192 | + | |
| 193 | + public static void main(String[] args) { | |
| 194 | + String s="A123"; | |
| 195 | + String[] arr={"A","B","C","D","E","F"}; | |
| 196 | + if(containsWords(s,arr)){ | |
| 197 | + System.out.println(s); | |
| 198 | + } | |
| 199 | + } | |
| 179 | 200 | } |
| 180 | 201 | ... | ... |
src/main/java/com/example/demo/service/Contrast.java
| ... | ... | @@ -50,7 +50,7 @@ public class Contrast { |
| 50 | 50 | private final int TIME=5; |
| 51 | 51 | private final int TIME2=0;//刷卡的时间和到站实际允许误差值 |
| 52 | 52 | |
| 53 | - public List<Map> getDriverCardList() { | |
| 53 | + public List<Map> getDriverCardList() throws Exception{ | |
| 54 | 54 | List<Map> list = new ArrayList<>(); |
| 55 | 55 | String drivercard = HttpUtils.sendPost("http://112.64.187.3:1080/gjService/gjService/drivercard", null); |
| 56 | 56 | JSONObject obj = JSONObject.parseObject(drivercard); |
| ... | ... | @@ -79,7 +79,7 @@ public class Contrast { |
| 79 | 79 | * @Author: YM |
| 80 | 80 | * @Date: 2021/10/12 |
| 81 | 81 | */ |
| 82 | - public List<Map<String,List<Scheduling>>> getSchedulingS(LocalDateTime now,int day) { | |
| 82 | + public List<Map<String,List<Scheduling>>> getSchedulingS(LocalDateTime now,int day) throws Exception{ | |
| 83 | 83 | List<Scheduling> schedulingS=new ArrayList<>(); |
| 84 | 84 | long start = System.currentTimeMillis(); |
| 85 | 85 | Map map = new HashMap(); |
| ... | ... | @@ -192,7 +192,7 @@ public class Contrast { |
| 192 | 192 | * @Author: YM |
| 193 | 193 | * @Date: 2021/10/13 |
| 194 | 194 | */ |
| 195 | - public void filterCardList(List<TJRLDB> allData, Boolean isOld) { | |
| 195 | + public void filterCardList(List<TJRLDB> allData, Boolean isOld) throws Exception { | |
| 196 | 196 | logger.info("===============================票务数据匹配开始================================"); |
| 197 | 197 | long start = System.currentTimeMillis(); |
| 198 | 198 | List<Map> driverCardList = getDriverCardList();//获取司机信息 |
| ... | ... | @@ -342,7 +342,7 @@ public class Contrast { |
| 342 | 342 | |
| 343 | 343 | |
| 344 | 344 | |
| 345 | - public static int getWeek(String today){ | |
| 345 | + public static int getWeek(String today)throws Exception{ | |
| 346 | 346 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| 347 | 347 | Date date = null; |
| 348 | 348 | try { |
| ... | ... | @@ -364,7 +364,7 @@ public class Contrast { |
| 364 | 364 | return out; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - public static String getTransTime(String timeStr) { | |
| 367 | + public static String getTransTime(String timeStr) throws Exception{ | |
| 368 | 368 | DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd HHmmss"); |
| 369 | 369 | LocalDateTime date = LocalDateTime.parse(timeStr, df); |
| 370 | 370 | DateTimeFormatter f2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| ... | ... | @@ -384,7 +384,7 @@ public class Contrast { |
| 384 | 384 | filterCardList(records,false); |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - public List<List<TJRLDB>> getSubList(int length, List<TJRLDB> list){ | |
| 387 | + public List<List<TJRLDB>> getSubList(int length, List<TJRLDB> list)throws Exception{ | |
| 388 | 388 | int size = list.size(); |
| 389 | 389 | int temp = size / length + 1; |
| 390 | 390 | boolean result = size % length == 0; |
| ... | ... | @@ -402,7 +402,7 @@ public class Contrast { |
| 402 | 402 | return subList; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - public static void main(String[] args) { | |
| 405 | + public static void main(String[] args) throws Exception{ | |
| 406 | 406 | String carId="B140C906"; |
| 407 | 407 | Contrast contrast=new Contrast(); |
| 408 | 408 | List<Map> driverCardList = contrast.getDriverCardList(); | ... | ... |
src/main/resources/application.properties
src/main/resources/logback.xml
| ... | ... | @@ -6,6 +6,8 @@ |
| 6 | 6 | </layout> |
| 7 | 7 | </appender> |
| 8 | 8 | |
| 9 | + | |
| 10 | + <property name="LOG_INFO_HOME" value="./logs/info" /> | |
| 9 | 11 | <!--获取比info级别高(包括info级别)但除error级别的日志--> |
| 10 | 12 | <appender name="INFO-LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| 11 | 13 | <filter class="ch.qos.logback.classic.filter.LevelFilter"> |
| ... | ... | @@ -24,6 +26,18 @@ |
| 24 | 26 | <maxHistory>30</maxHistory> |
| 25 | 27 | </rollingPolicy> |
| 26 | 28 | </appender> |
| 29 | + | |
| 30 | + <appender name="ASYNC-INFO" class="ch.qos.logback.classic.AsyncAppender"> | |
| 31 | + <!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 --> | |
| 32 | + <discardingThreshold>0</discardingThreshold> | |
| 33 | + <!-- 更改默认的队列的深度,该值会影响性能.默认值为256 --> | |
| 34 | + <queueSize>256</queueSize> | |
| 35 | + <!-- 添加附加的appender,最多只能添加一个 --> | |
| 36 | + <appender-ref ref="INFO-LOG"/> | |
| 37 | + </appender> | |
| 38 | + | |
| 39 | + <property name="LOG_ERROR_HOME" value="./logs/error" /> | |
| 40 | + | |
| 27 | 41 | <appender name="ERROR-LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| 28 | 42 | <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
| 29 | 43 | <level>ERROR</level> |
| ... | ... | @@ -39,15 +53,6 @@ |
| 39 | 53 | </rollingPolicy> |
| 40 | 54 | </appender> |
| 41 | 55 | |
| 42 | - <appender name="ASYNC-INFO" class="ch.qos.logback.classic.AsyncAppender"> | |
| 43 | - <!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 --> | |
| 44 | - <discardingThreshold>0</discardingThreshold> | |
| 45 | - <!-- 更改默认的队列的深度,该值会影响性能.默认值为256 --> | |
| 46 | - <queueSize>256</queueSize> | |
| 47 | - <!-- 添加附加的appender,最多只能添加一个 --> | |
| 48 | - <appender-ref ref="INFO-LOG"/> | |
| 49 | - </appender> | |
| 50 | - | |
| 51 | 56 | <appender name="ASYNC-ERROR" class="ch.qos.logback.classic.AsyncAppender"> |
| 52 | 57 | <!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 --> |
| 53 | 58 | <discardingThreshold>0</discardingThreshold> | ... | ... |