Commit a3aa07b5629ffa7c47f029e1c9a3b67dd9ea5c3e
1 parent
afdd1ef3
临港客流
Showing
6 changed files
with
209 additions
and
546 deletions
src/main/java/com/example/demo/SaticScheduleTask.java
| 1 | package com.example.demo; | 1 | package com.example.demo; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -import cn.hutool.core.io.FileUtil; | 4 | +import cn.hutool.http.HttpUtil; |
| 5 | +import com.alibaba.fastjson.JSON; | ||
| 6 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | import com.example.demo.model.Scheduling; | 7 | import com.example.demo.model.Scheduling; |
| 6 | -import com.example.demo.model.TJRL; | ||
| 7 | import com.example.demo.model.TJRLDB; | 8 | import com.example.demo.model.TJRLDB; |
| 8 | -import com.example.demo.service.Analysis; | ||
| 9 | import com.example.demo.service.Contrast; | 9 | import com.example.demo.service.Contrast; |
| 10 | import org.slf4j.Logger; | 10 | import org.slf4j.Logger; |
| 11 | import org.slf4j.LoggerFactory; | 11 | import org.slf4j.LoggerFactory; |
| 12 | -import org.springframework.beans.factory.InitializingBean; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | -import org.springframework.beans.factory.annotation.Value; | ||
| 15 | import org.springframework.context.annotation.Configuration; | 13 | import org.springframework.context.annotation.Configuration; |
| 16 | import org.springframework.scheduling.annotation.EnableScheduling; | 14 | import org.springframework.scheduling.annotation.EnableScheduling; |
| 17 | import org.springframework.scheduling.annotation.Scheduled; | 15 | import org.springframework.scheduling.annotation.Scheduled; |
| 18 | import org.springframework.stereotype.Component; | 16 | import org.springframework.stereotype.Component; |
| 19 | - | ||
| 20 | import javax.annotation.PostConstruct; | 17 | import javax.annotation.PostConstruct; |
| 21 | -import java.io.*; | ||
| 22 | -import java.nio.file.*; | ||
| 23 | import java.time.LocalDateTime; | 18 | import java.time.LocalDateTime; |
| 24 | import java.time.format.DateTimeFormatter; | 19 | import java.time.format.DateTimeFormatter; |
| 25 | import java.util.*; | 20 | import java.util.*; |
| @@ -34,16 +29,12 @@ public class SaticScheduleTask { | @@ -34,16 +29,12 @@ public class SaticScheduleTask { | ||
| 34 | 29 | ||
| 35 | private final static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class); | 30 | private final static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class); |
| 36 | 31 | ||
| 37 | - @Value("${ftp.root}") | ||
| 38 | - private String rootPath; | ||
| 39 | 32 | ||
| 40 | - private WatchService watchService; | ||
| 41 | 33 | ||
| 42 | @Autowired | 34 | @Autowired |
| 43 | private Contrast contrast; | 35 | private Contrast contrast; |
| 44 | 36 | ||
| 45 | - @Autowired | ||
| 46 | - private Analysis analysis; | 37 | + |
| 47 | 38 | ||
| 48 | private static DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | 39 | private static DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); |
| 49 | 40 | ||
| @@ -51,138 +42,62 @@ public class SaticScheduleTask { | @@ -51,138 +42,62 @@ public class SaticScheduleTask { | ||
| 51 | 42 | ||
| 52 | 43 | ||
| 53 | @Scheduled(cron = "0 0/5 * * * ?") | 44 | @Scheduled(cron = "0 0/5 * * * ?") |
| 54 | - @PostConstruct | 45 | + //@PostConstruct |
| 55 | void getArrivalInfos(){ | 46 | void getArrivalInfos(){ |
| 56 | logger.info("票务数据缓存加载: " + LocalDateTime.now()); | 47 | logger.info("票务数据缓存加载: " + LocalDateTime.now()); |
| 57 | try { | 48 | try { |
| 58 | LocalDateTime now=LocalDateTime.now(); | 49 | LocalDateTime now=LocalDateTime.now(); |
| 50 | + /*DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
| 51 | + now=LocalDateTime.parse("2025-03-14 00:00",tdf);*/ | ||
| 59 | List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1); | 52 | List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1); |
| 60 | contrast.getSchedulingS=result.get(0); | 53 | contrast.getSchedulingS=result.get(0); |
| 61 | contrast.getSchedulingSSell=result.get(1); | 54 | contrast.getSchedulingSSell=result.get(1); |
| 62 | logger.info("===============================数据存放结束,开始读取文件================================"); | 55 | logger.info("===============================数据存放结束,开始读取文件================================"); |
| 63 | DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyyMMdd"); | 56 | DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyyMMdd"); |
| 64 | - String date=now.format(dtf); | ||
| 65 | - System.out.println(rootPath+File.separator+date); | ||
| 66 | - List<File> files = FileUtil.loopFiles(Paths.get(rootPath+File.separator+date),1,new wdbFileFilter()); | ||
| 67 | - System.out.println("文件数"+files.size()); | ||
| 68 | - logger.info("===============================文件数"+files.size()+",读取文件结束================================"); | ||
| 69 | - //先把处理上一次没匹配到的 | ||
| 70 | - logger.info("===============================处理上次未匹配到的数据"+contrast.oldData.size()+"================================"); | ||
| 71 | - if(!contrast.oldData.isEmpty()){ | ||
| 72 | - contrast.filterCardList(contrast.oldData,true); | ||
| 73 | - } | ||
| 74 | - logger.info("===============================文件解析开始================================"); | ||
| 75 | - List<TJRLDB> allFile = analysis.getAllFile(files); | ||
| 76 | - logger.info("===============================交易数"+allFile.size()+"文件解析结束================================"); | ||
| 77 | - contrast.filterCardList(allFile,false); | 57 | + String date=now.minusDays(1).format(dtf); |
| 58 | + List<TJRLDB> tjrldbs=loadTJRL(date); | ||
| 59 | + logger.info("===============================交易数"+tjrldbs.size()+",读取文件结束================================"); | ||
| 60 | + contrast.filterCardList(tjrldbs); | ||
| 78 | } catch (Exception e) { | 61 | } catch (Exception e) { |
| 79 | e.printStackTrace(); | 62 | e.printStackTrace(); |
| 80 | } | 63 | } |
| 81 | } | 64 | } |
| 82 | 65 | ||
| 83 | - | ||
| 84 | - | ||
| 85 | - void getArrivalInfos2(String date,String path) { | ||
| 86 | - LocalDateTime now=LocalDateTime.parse(date,tdf); | ||
| 87 | - logger.info("票务数据缓存加载: " + now); | 66 | + //获取刷卡数据 |
| 67 | + public List<TJRLDB> loadTJRL(String date){ | ||
| 68 | + List<TJRLDB> listMap = new ArrayList<>(); | ||
| 88 | try { | 69 | try { |
| 89 | - List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1); | ||
| 90 | - contrast.getSchedulingS=result.get(0); | ||
| 91 | - contrast.getSchedulingSSell=result.get(1); | ||
| 92 | - List<File> fl= FileUtil.loopFiles(path); | ||
| 93 | - System.out.println(fl.size()); | ||
| 94 | - List<List<File>> subList=getSubList(100,fl); | ||
| 95 | - if(!subList.isEmpty()){ | ||
| 96 | - subList.forEach(fs->{ | ||
| 97 | - if (!fs.isEmpty()) { | ||
| 98 | - System.out.println("文件数"+fs.size()); | ||
| 99 | - try { | ||
| 100 | - List<TJRLDB> allFile = analysis.getAllFile(fs); | ||
| 101 | - System.out.println("交易数"+allFile.size()); | ||
| 102 | - contrast.filterCardList(allFile,true); | ||
| 103 | - } catch (Exception e) { | ||
| 104 | - e.printStackTrace(); | ||
| 105 | - } | 70 | + JSONObject params=new JSONObject(); |
| 71 | + params.put("cdate",date); | ||
| 72 | + String sb = HttpUtil.post("http://10.10.150.53:8184/cardSys/data/act",params.toJSONString()); | ||
| 73 | + JSONObject jsonObject=JSONObject.parseObject(sb.toString()); | ||
| 74 | + if(jsonObject.getString("code").equals("0")){ | ||
| 75 | + String ja=jsonObject.getString("data"); | ||
| 76 | + List<Map> result= JSON.parseArray(ja,Map.class); | ||
| 77 | + for (Map map : result) { | ||
| 78 | + TJRLDB tjrl=new TJRLDB(); | ||
| 79 | + tjrl.setTJRLDRVCRDID(String.valueOf(map.get("DRIVER_CARD_ID")));//司售卡号 | ||
| 80 | + tjrl.setTJRLCARDNO(String.valueOf(map.get("CARD_ID")));//消费卡的ID号 | ||
| 81 | + tjrl.setTJRLCDKIND(String.valueOf(map.get("CARD_TYPE")));//消费卡卡型 | ||
| 82 | + tjrl.setTJRLPOSID(String.valueOf(map.get("POS_ID")));//POS编号 | ||
| 83 | + tjrl.setTJRLRDATE(String.valueOf(map.get("TXN_DATE")));//交易日期 | ||
| 84 | + if(String.valueOf(map.get("TXN_TIME")).length()<6){ | ||
| 85 | + tjrl.setTJRLRTIME("0"+map.get("TXN_TIME"));//交易时间 | ||
| 86 | + }else { | ||
| 87 | + tjrl.setTJRLRTIME(String.valueOf(map.get("TXN_TIME")));//交易时间 | ||
| 106 | } | 88 | } |
| 107 | - }); | 89 | + tjrl.setTJRLCDBAL(String.valueOf(map.get("BAL_BEF")));//消费卡交易前金额,单位:分 |
| 90 | + tjrl.setTJRLAMT(String.valueOf(map.get("TXN_AMOUNT")));//消费交易金额,单位:分 | ||
| 91 | + tjrl.setTJRLORGAMT(String.valueOf(map.get("ORIGNAL_TXN_AMOUNT")));//优惠前原始票价,单位:分 | ||
| 92 | + tjrl.setTJRLTXFG(String.valueOf(map.get("CARD_SPEC")));//卡规范(01—建设部卡、02—交通部卡、03—二维码扫码) | ||
| 93 | + tjrl.setCOUNT(String.valueOf(map.get("COUNT")));//卡计数器 | ||
| 94 | + listMap.add(tjrl); | ||
| 95 | + } | ||
| 108 | } | 96 | } |
| 109 | - logger.info("==============================="+now.minusDays(1)+"数据处理完成================================"); | ||
| 110 | } catch (Exception e) { | 97 | } catch (Exception e) { |
| 111 | e.printStackTrace(); | 98 | e.printStackTrace(); |
| 112 | } | 99 | } |
| 113 | - } | ||
| 114 | - | ||
| 115 | - //@PostConstruct | ||
| 116 | - void processingHistory(){ | ||
| 117 | - getArrivalInfos2("2022-11-22 00:00","/home/oldFile/20221121"); | ||
| 118 | - //getArrivalInfos2("2022-11-23 00:00","/home/oldFile/20221122"); | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | - /** | ||
| 122 | - * @Description: 用来计算数据库中的乘车记录 | ||
| 123 | - * @Param: | ||
| 124 | - * @return: | ||
| 125 | - * @Author: YM | ||
| 126 | - * @Date: 2021/10/13 | ||
| 127 | - */ | ||
| 128 | - //@PostConstruct | ||
| 129 | - private void filterCardListByDB() throws Exception { | ||
| 130 | - DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
| 131 | - LocalDateTime now=LocalDateTime.parse("2021-08-07 00:00",tdf); | ||
| 132 | - | ||
| 133 | - int day=1; | ||
| 134 | - List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,day); | ||
| 135 | - contrast.getSchedulingS=result.get(0); | ||
| 136 | - contrast.getSchedulingSSell=result.get(1); | ||
| 137 | - Map<String,Object> map=new HashMap<>(); | ||
| 138 | - map.put("table","pd_control."+"fhtxnjrltb_jtb_copy1"); | ||
| 139 | - LocalDateTime startDate=now.minusDays(day); | ||
| 140 | - String start=startDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
| 141 | - String end=now.format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
| 142 | - map.put("start",start); | ||
| 143 | - map.put("end",end); | ||
| 144 | - contrast.filterCardListByDB(map); | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - public List<List<File>> getSubList(int length, List<File> list){ | ||
| 151 | - int size = list.size(); | ||
| 152 | - int temp = size / length + 1; | ||
| 153 | - boolean result = size % length == 0; | ||
| 154 | - List<List<File>> subList = new ArrayList<>(); | ||
| 155 | - for (int i = 0; i < temp; i++) { | ||
| 156 | - if (i == temp - 1) { | ||
| 157 | - if (result) { | ||
| 158 | - break; | ||
| 159 | - } | ||
| 160 | - subList.add(list.subList(length * i, size)) ; | ||
| 161 | - } else { | ||
| 162 | - subList.add(list.subList(length * i, length * (i + 1))) ; | ||
| 163 | - } | ||
| 164 | - } | ||
| 165 | - return subList; | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | - | ||
| 169 | - public static class wdbFileFilter implements FileFilter { | ||
| 170 | - @Override | ||
| 171 | - public boolean accept(File file) { | ||
| 172 | - if(file.isDirectory()) | ||
| 173 | - return false; | ||
| 174 | - String name = file.getName(); | ||
| 175 | - if(name.endsWith(".wdb")) //mp3则返回true | ||
| 176 | - return true; | ||
| 177 | - return false; | ||
| 178 | - } | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - public static void main(String[] args) { | ||
| 182 | - List<File> files = FileUtil.loopFiles(Paths.get("E:\\sftp\\home\\sftp\\20220725"),1,new wdbFileFilter()); | ||
| 183 | - files.forEach(file->{ | ||
| 184 | - System.out.println(file.getName()); | ||
| 185 | - }); | 100 | + return listMap; |
| 186 | } | 101 | } |
| 187 | 102 | ||
| 188 | } | 103 | } |
| 189 | \ No newline at end of file | 104 | \ No newline at end of file |
src/main/java/com/example/demo/model/CardDriver.java
0 → 100644
| 1 | +package com.example.demo.model; | ||
| 2 | + | ||
| 3 | +import java.util.Map; | ||
| 4 | + | ||
| 5 | +public class CardDriver { | ||
| 6 | + private String card_no; | ||
| 7 | + private String inside_no;//司售卡号 | ||
| 8 | + private String driver_no;//工号 | ||
| 9 | + private String gh;//工号 | ||
| 10 | + private String name; | ||
| 11 | + | ||
| 12 | + public static CardDriver getInstance(Map m){ | ||
| 13 | + CardDriver cardDriver = new CardDriver(); | ||
| 14 | + cardDriver.setCard_no(m.get("faceNo")!=null?m.get("faceNo").toString():null); | ||
| 15 | + cardDriver.setInside_no(m.get("inlineNo")!=null?m.get("inlineNo").toString():null); | ||
| 16 | + cardDriver.setDriver_no(m.get("bandUId")!=null?m.get("bandUId").toString():null); | ||
| 17 | + cardDriver.setName(m.get("bandUName")!=null?m.get("bandUName").toString():null); | ||
| 18 | + return cardDriver; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public String getCard_no() { | ||
| 22 | + return card_no; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public void setCard_no(String card_no) { | ||
| 26 | + this.card_no = card_no; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public String getInside_no() { | ||
| 30 | + return inside_no; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setInside_no(String inside_no) { | ||
| 34 | + this.inside_no = inside_no; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getDriver_no() { | ||
| 38 | + return driver_no; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setDriver_no(String driver_no) { | ||
| 42 | + this.driver_no = driver_no; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public String getName() { | ||
| 46 | + return name; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setName(String name) { | ||
| 50 | + this.name = name; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public String getGh() { | ||
| 54 | + String ghStr=null; | ||
| 55 | + if(this.driver_no!=null && this.driver_no.split("-").length==2){ | ||
| 56 | + ghStr=this.driver_no.split("-")[1]; | ||
| 57 | + } | ||
| 58 | + return ghStr; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setGh(String gh) { | ||
| 62 | + this.gh = gh; | ||
| 63 | + } | ||
| 64 | +} |
src/main/java/com/example/demo/service/Analysis.java deleted
100644 → 0
| 1 | -package com.example.demo.service; | ||
| 2 | - | ||
| 3 | -import com.example.demo.SaticScheduleTask; | ||
| 4 | -import com.example.demo.model.TJRL; | ||
| 5 | -import com.example.demo.model.TJRLDB; | ||
| 6 | -import org.slf4j.Logger; | ||
| 7 | -import org.slf4j.LoggerFactory; | ||
| 8 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | -import org.springframework.beans.factory.annotation.Value; | ||
| 10 | -import org.springframework.kafka.core.KafkaTemplate; | ||
| 11 | -import org.springframework.stereotype.Component; | ||
| 12 | - | ||
| 13 | -import java.io.BufferedReader; | ||
| 14 | -import java.io.File; | ||
| 15 | -import java.io.FileReader; | ||
| 16 | -import java.text.ParseException; | ||
| 17 | -import java.text.SimpleDateFormat; | ||
| 18 | -import java.util.*; | ||
| 19 | - | ||
| 20 | -@Component | ||
| 21 | -public class Analysis { | ||
| 22 | - protected final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 23 | - | ||
| 24 | - private static Date startDate = subtractTime(new Date(), -300000); | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - @Value("${ftp.oldFile}") | ||
| 28 | - private String oldFile; | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - /** | ||
| 32 | - * 获取路径下的所有文件/文件夹 /读取文件 返回时间和carid | ||
| 33 | - * | ||
| 34 | - * @param files 需要遍历的文件夹路径 | ||
| 35 | - * @return | ||
| 36 | - */ | ||
| 37 | - public List<TJRLDB> getAllFile(List<File> files) throws Exception { | ||
| 38 | - List<TJRLDB> listMap = new ArrayList<>(); | ||
| 39 | - List<String> list = new ArrayList<String>(); | ||
| 40 | - for (File file : files) { | ||
| 41 | - if (!file.isDirectory()) { | ||
| 42 | - String name=file.getName().substring(2,10); | ||
| 43 | - String absolutePath = file.getAbsolutePath(); | ||
| 44 | - String time = (absolutePath.substring(absolutePath.indexOf("GJ"), absolutePath.indexOf("GJ") + 16)).replace("GJ", ""); | ||
| 45 | - Date nowTime = null; | ||
| 46 | - try { | ||
| 47 | - nowTime = new SimpleDateFormat("yyyyMMddHHmmss").parse(time); | ||
| 48 | - } catch (ParseException e) { | ||
| 49 | - e.printStackTrace(); | ||
| 50 | - } | ||
| 51 | - //if (belongCalendar(nowTime)) { //判断是否在对应时间内 | ||
| 52 | - list.add(file.getAbsolutePath()); | ||
| 53 | - List<String> strings = txt2String(new File(file.getAbsolutePath()));//读取文件 | ||
| 54 | - for (int i = 0; i < strings.size(); i++) { | ||
| 55 | - String text = strings.get(i); | ||
| 56 | - Map<String, Object> map = new HashMap<>(); | ||
| 57 | - TJRLDB tjrl=new TJRLDB(); | ||
| 58 | - String POSID=text.substring(0,8); | ||
| 59 | - tjrl.setTJRLPOSID(POSID); | ||
| 60 | - Long val = Long.parseLong(text.substring(30, 40)); | ||
| 61 | - String cardId = Long.toHexString(val).toUpperCase(); | ||
| 62 | - tjrl.setTJRLDRVCRDID(cardId);//司售卡号 DriverCardId签到卡片ID号,BCD编码,司售卡卡号 | ||
| 63 | - //map.put("DriverCardType", text.substring(40, 42));//DriverCardType HEX格式,签到卡的卡型,BCD编码 | ||
| 64 | - //map.put("CHECKINDATE", text.substring(42, 54));//签到时间YYYYMMDDhhmm,BCD编码 | ||
| 65 | - //map.put("CHECKOUTCOUNT", text.substring(54, 60));//签到总次数,BCD编码 | ||
| 66 | - tjrl.setTJRLTXFG(text.substring(60, 62));//交易类型 Txn Flag HEX格式,交易标志,其中88为正常交易,99为锁卡交易,BCD编码,定义见附录1交易类型对照表 | ||
| 67 | - String POSSEQID=text.substring(62, 68);//HEX格式,消费交易流水号,BCD编码 | ||
| 68 | - //map.put("CITYCODE", text.substring(68, 72)); //城市代码号,BCD编码 | ||
| 69 | - tjrl.setTJRLCARDNO(text.substring(72, 82));//CARDID消费卡的ID号,BCD编码 | ||
| 70 | - tjrl.setTJRLCDKIND(text.substring(82, 84));//Card Type HEX格式,消费卡卡型,BCD编码 | ||
| 71 | - tjrl.setTJRLCDBAL(text.substring(84, 92));//交易前余额 BalBef消费卡交易前金额,BCD编码 BCD编码之前最高位1表示负数,0表示正数 | ||
| 72 | - tjrl.setTJRLAMT(text.substring(92, 100));//交易金额 TxnAmount本次消费交易金额,BCD编码 | ||
| 73 | - String TJRLRDATE=text.substring(100, 108); | ||
| 74 | - try { | ||
| 75 | - tjrl.setTJRLRDATE(new SimpleDateFormat("yyyy-MM-dd"). | ||
| 76 | - format(new SimpleDateFormat("yyyyMMdd").parse(text.substring(100, 108)))); | ||
| 77 | - //交易日期 本次消费交易日期,BCD编码YYYYMMDD | ||
| 78 | - } catch (ParseException e) { | ||
| 79 | - e.printStackTrace(); | ||
| 80 | - } | ||
| 81 | - String TJRLRTIME=text.substring(108, 114); | ||
| 82 | - try { | ||
| 83 | - tjrl.setTJRLRTIME(new SimpleDateFormat("HH:mm:ss"). | ||
| 84 | - format(new SimpleDateFormat("HHmmss").parse(text.substring(108, 114)))); | ||
| 85 | - //交易时间 Txn Time本次消费交易时间,BCD编码hhmmss | ||
| 86 | - } catch (ParseException e) { | ||
| 87 | - e.printStackTrace(); | ||
| 88 | - } | ||
| 89 | - tjrl.setCOUNT(text.substring(114, 120));//交易计数器,BCD编码 | ||
| 90 | - tjrl.setTJRLORGAMT(text.substring(120, 124));//交易原始金额Orignal Txn Amount | ||
| 91 | - //map.put("CARDSPEC", text.substring(124, 126)); //卡规范,BCD编码 01—建设部卡 02—交通部卡 03-交通部二维码 | ||
| 92 | - String TAC=text.substring(126, 134);//HEX格式,交易认证码,BCD编码 | ||
| 93 | - String TRAD_ID=TAC+POSSEQID+TJRLRDATE+TJRLRTIME; | ||
| 94 | - tjrl.setTRAD_ID(TRAD_ID);////pos交易数据需要加上 trad_id 用tac+pos流水+交易日期+交易时间 | ||
| 95 | - | ||
| 96 | - listMap.add(tjrl); | ||
| 97 | - } | ||
| 98 | - //} | ||
| 99 | - /* Analysis analysis=new Analysis(); | ||
| 100 | - analysis.setOldFile(oldFile);*/ | ||
| 101 | - File f2=new File(oldFile+File.separator+name); | ||
| 102 | - if(!f2.exists()&&!f2.isDirectory()){ | ||
| 103 | - f2.mkdir(); | ||
| 104 | - } | ||
| 105 | - File f=new File(oldFile+File.separator+name+File.separator+file.getName()); | ||
| 106 | - file.renameTo(f); | ||
| 107 | - } | ||
| 108 | - } | ||
| 109 | - return listMap; | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - | ||
| 113 | - /** | ||
| 114 | - * 读取文件内容 | ||
| 115 | - */ | ||
| 116 | - public static List<String> txt2String(File file) { | ||
| 117 | - List<String> list = new ArrayList<>(); | ||
| 118 | - StringBuilder result = new StringBuilder(); | ||
| 119 | - try { | ||
| 120 | - BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件 | ||
| 121 | - String s = null; | ||
| 122 | - while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行 | ||
| 123 | - list.add(s); | ||
| 124 | - } | ||
| 125 | - br.close(); | ||
| 126 | - } catch (Exception e) { | ||
| 127 | - e.printStackTrace(); | ||
| 128 | - } | ||
| 129 | - return list; | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - | ||
| 133 | - /** | ||
| 134 | - * 加减对应时间后的日期 | ||
| 135 | - * | ||
| 136 | - * @param date 需要加减时间的日期 | ||
| 137 | - * @param amount 加减的时间(毫秒) | ||
| 138 | - * @return 加减对应时间后的日期 | ||
| 139 | - */ | ||
| 140 | - | ||
| 141 | - private static Date subtractTime(Date date, int amount) { | ||
| 142 | - try { | ||
| 143 | - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| 144 | - String strTime = sdf.format(date.getTime() + amount); | ||
| 145 | - Date time = sdf.parse(strTime); | ||
| 146 | - return time; | ||
| 147 | - } catch (Exception e) { | ||
| 148 | - e.printStackTrace(); | ||
| 149 | - } | ||
| 150 | - return null; | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | - /** | ||
| 154 | - * 判断时间是否在时间段内 | ||
| 155 | - * | ||
| 156 | - * @param nowTime | ||
| 157 | - * @return | ||
| 158 | - */ | ||
| 159 | - public static boolean belongCalendar(Date nowTime) { | ||
| 160 | - Calendar date = Calendar.getInstance(); | ||
| 161 | - date.setTime(nowTime); | ||
| 162 | - | ||
| 163 | - Calendar begin = Calendar.getInstance(); | ||
| 164 | - begin.setTime(startDate); | ||
| 165 | - | ||
| 166 | - Calendar end = Calendar.getInstance(); | ||
| 167 | - end.setTime(new Date()); | ||
| 168 | - | ||
| 169 | - if (date.after(begin) && date.before(end)) { | ||
| 170 | - return true; | ||
| 171 | - } else { | ||
| 172 | - return false; | ||
| 173 | - } | ||
| 174 | - } | ||
| 175 | - /* @Value("${ftp.oldFile}") | ||
| 176 | - public void setOldFile(String oldFile) { | ||
| 177 | - Analysis.oldFile = oldFile; | ||
| 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 | - } | ||
| 200 | -} | ||
| 201 | - |
src/main/java/com/example/demo/service/Contrast.java
| 1 | package com.example.demo.service; | 1 | package com.example.demo.service; |
| 2 | 2 | ||
| 3 | -import cn.hutool.json.JSON; | ||
| 4 | -import com.alibaba.fastjson.JSONArray; | ||
| 5 | -import com.alibaba.fastjson.JSONObject; | ||
| 6 | -import com.bsth.util.HttpUtils; | ||
| 7 | -import com.example.demo.SaticScheduleTask; | 3 | +import cn.hutool.http.HttpUtil; |
| 8 | import com.example.demo.mapper.db1.SiteMapper1; | 4 | import com.example.demo.mapper.db1.SiteMapper1; |
| 9 | import com.example.demo.mapper.db2.SiteMapper2; | 5 | import com.example.demo.mapper.db2.SiteMapper2; |
| 10 | import com.example.demo.model.*; | 6 | import com.example.demo.model.*; |
| 11 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; | 8 | import org.slf4j.LoggerFactory; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | -import org.springframework.kafka.core.KafkaTemplate; | ||
| 15 | -import org.springframework.kafka.support.SendResult; | ||
| 16 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
| 17 | -import org.springframework.util.concurrent.ListenableFuture; | ||
| 18 | -import org.springframework.util.concurrent.ListenableFutureCallback; | ||
| 19 | -import java.text.ParseException; | ||
| 20 | import java.text.SimpleDateFormat; | 11 | import java.text.SimpleDateFormat; |
| 21 | import java.time.*; | 12 | import java.time.*; |
| 22 | import java.time.format.DateTimeFormatter; | 13 | import java.time.format.DateTimeFormatter; |
| @@ -35,11 +26,7 @@ public class Contrast { | @@ -35,11 +26,7 @@ public class Contrast { | ||
| 35 | @Autowired | 26 | @Autowired |
| 36 | private SiteMapper2 siteMapper2; | 27 | private SiteMapper2 siteMapper2; |
| 37 | 28 | ||
| 38 | - @Autowired | ||
| 39 | - private KafkaTemplate kafkaTemplate; | ||
| 40 | 29 | ||
| 41 | - @Autowired | ||
| 42 | - private SaticScheduleTask saticScheduleTask; | ||
| 43 | 30 | ||
| 44 | public Map<String,List<Scheduling>> getSchedulingS; | 31 | public Map<String,List<Scheduling>> getSchedulingS; |
| 45 | public Map<String,List<Scheduling>> getSchedulingSSell; | 32 | public Map<String,List<Scheduling>> getSchedulingSSell; |
| @@ -48,26 +35,24 @@ public class Contrast { | @@ -48,26 +35,24 @@ public class Contrast { | ||
| 48 | private final int TIME=5; | 35 | private final int TIME=5; |
| 49 | private final int TIME2=0;//刷卡的时间和到站实际允许误差值 | 36 | private final int TIME2=0;//刷卡的时间和到站实际允许误差值 |
| 50 | 37 | ||
| 51 | - public List<Map> getDriverCardList() throws Exception{ | ||
| 52 | - List<Map> list = new ArrayList<>(); | ||
| 53 | - String drivercard = HttpUtils.sendPost("http://112.64.187.3:1080/gjService/gjService/drivercard", null); | ||
| 54 | - JSONObject obj = JSONObject.parseObject(drivercard); | ||
| 55 | - String errorCode = obj.get("errorCode").toString(); | ||
| 56 | - if (errorCode.equals("1")) { | ||
| 57 | - JSONArray dateBeans = obj.getJSONArray("dateBean"); | ||
| 58 | - for (int i = 0; i < dateBeans.size(); i++) { | ||
| 59 | - Map dataList = new HashMap(); | ||
| 60 | - JSONObject o = (JSONObject) dateBeans.get(i); | ||
| 61 | - dataList.put("outcardno", o.get("outcardno")); | ||
| 62 | - dataList.put("cardno", o.get("cardno")); | ||
| 63 | - dataList.put("jobCode", o.get("jobCode")); | ||
| 64 | - dataList.put("companyNo", o.get("companyNo")); | ||
| 65 | - dataList.put("brancheCompanyNo", o.get("brancheCompanyNo")); | ||
| 66 | - dataList.put("personalName", o.get("personalName")); | ||
| 67 | - list.add(dataList); | 38 | + |
| 39 | + //获取司售卡数据 | ||
| 40 | + public Map<String,CardDriver> getDriverCardList(){ | ||
| 41 | + Map<String,CardDriver> cardDrivers = new HashMap<>(); | ||
| 42 | + try { | ||
| 43 | + String sb = HttpUtil.post("http://10.10.150.53:18080/demoserver/business/findDriverSaleCardList",new HashMap<>()); | ||
| 44 | + List<Map> result= com.alibaba.fastjson.JSON.parseArray(sb,Map.class); | ||
| 45 | + if(result!=null && result.size()>0){ | ||
| 46 | + for (Map map : result) { | ||
| 47 | + if(map.get("inlineNo")!=null &&!"".equals(map.get("inlineNo").toString())){ | ||
| 48 | + cardDrivers.put(map.get("inlineNo").toString(),CardDriver.getInstance(map)); | ||
| 49 | + } | ||
| 50 | + } | ||
| 68 | } | 51 | } |
| 52 | + } catch (Exception e) { | ||
| 53 | + e.printStackTrace(); | ||
| 69 | } | 54 | } |
| 70 | - return list; | 55 | + return cardDrivers; |
| 71 | } | 56 | } |
| 72 | 57 | ||
| 73 | 58 | ||
| @@ -185,8 +170,8 @@ public class Contrast { | @@ -185,8 +170,8 @@ public class Contrast { | ||
| 185 | } | 170 | } |
| 186 | } | 171 | } |
| 187 | } | 172 | } |
| 188 | - Map<String,List<Scheduling>> getSchedulingS=schedulingS.stream().collect(Collectors.groupingBy(s->s.getJ_name())); | ||
| 189 | - Map<String,List<Scheduling>> getSchedulingSSell=schedulingS.stream().collect(Collectors.groupingBy(s->s.getS_name())); | 173 | + Map<String,List<Scheduling>> getSchedulingS=schedulingS.stream().collect(Collectors.groupingBy(s->s.getJ_gh())); |
| 174 | + Map<String,List<Scheduling>> getSchedulingSSell=schedulingS.stream().collect(Collectors.groupingBy(s->s.getS_gh())); | ||
| 190 | List<Map<String,List<Scheduling>>> result=new ArrayList<>(); | 175 | List<Map<String,List<Scheduling>>> result=new ArrayList<>(); |
| 191 | result.add(getSchedulingS); | 176 | result.add(getSchedulingS); |
| 192 | result.add(getSchedulingSSell); | 177 | result.add(getSchedulingSSell); |
| @@ -202,108 +187,98 @@ public class Contrast { | @@ -202,108 +187,98 @@ public class Contrast { | ||
| 202 | * @Author: YM | 187 | * @Author: YM |
| 203 | * @Date: 2021/10/13 | 188 | * @Date: 2021/10/13 |
| 204 | */ | 189 | */ |
| 205 | - public void filterCardList(List<TJRLDB> allData, Boolean isOld) throws Exception { | 190 | + public void filterCardList(List<TJRLDB> tjrldbs) throws Exception { |
| 206 | logger.info("===============================票务数据匹配开始================================"); | 191 | logger.info("===============================票务数据匹配开始================================"); |
| 207 | long start = System.currentTimeMillis(); | 192 | long start = System.currentTimeMillis(); |
| 208 | - List<Map> driverCardList = getDriverCardList();//获取司机信息 | 193 | + Map<String,CardDriver> driverCards = getDriverCardList();//获取司机信息 |
| 209 | Map<String,List<Scheduling>> schedulingS =getSchedulingS; | 194 | Map<String,List<Scheduling>> schedulingS =getSchedulingS; |
| 210 | Map<String,List<Scheduling>> schedulingSSell =getSchedulingSSell; | 195 | Map<String,List<Scheduling>> schedulingSSell =getSchedulingSSell; |
| 211 | System.out.println(schedulingS.size()); | 196 | System.out.println(schedulingS.size()); |
| 212 | System.out.println(schedulingSSell.size()); | 197 | System.out.println(schedulingSSell.size()); |
| 213 | - DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | 198 | + DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyyMMdd HHmmss"); |
| 214 | int b=0;//用于计算匹配成功的数量 | 199 | int b=0;//用于计算匹配成功的数量 |
| 215 | - for (int i = 0; i < allData.size(); i++) { | ||
| 216 | - TJRLDB data = allData.get(i); | 200 | + for (int i = 0; i < tjrldbs.size(); i++) { |
| 201 | + TJRLDB data = tjrldbs.get(i); | ||
| 217 | //通过司售卡找到司机 | 202 | //通过司售卡找到司机 |
| 218 | - String carId = data.getTJRLDRVCRDID().length()>8? | ||
| 219 | - data.getTJRLDRVCRDID().substring( data.getTJRLDRVCRDID().length()-8): | ||
| 220 | - data.getTJRLDRVCRDID(); | ||
| 221 | - List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList()); | 203 | + String carId = data.getTJRLDRVCRDID(); |
| 204 | + CardDriver driver =driverCards.get(carId); | ||
| 222 | String mark=""; | 205 | String mark=""; |
| 223 | - String jobCodes = ""; | 206 | + String gh = ""; |
| 224 | Boolean flag=false;//用来判断是否没有匹配成功 | 207 | Boolean flag=false;//用来判断是否没有匹配成功 |
| 225 | Long cardDate = null; | 208 | Long cardDate = null; |
| 226 | - if (!collect.isEmpty()) { | ||
| 227 | - if (null != collect.get(0).get("jobCode") && null != collect.get(0).get("personalName")) { | ||
| 228 | - String personalName = collect.get(0).get("personalName").toString();//姓名 | ||
| 229 | - String[] arr=collect.get(0).get("jobCode").toString().split("-"); | ||
| 230 | - jobCodes =arr.length==0?collect.get(0).get("jobCode").toString():arr[arr.length-1];//工号 | ||
| 231 | - String time=String.valueOf(data.getTJRLRTIME());//时间 | ||
| 232 | - String date=String.valueOf(data.getTJRLRDATE());//日期 | ||
| 233 | - cardDate = LocalDateTime.parse(date+" "+time,dtf).toInstant(ZoneOffset.of("+8")).toEpochMilli(); //刷卡时间(时间戳) | ||
| 234 | - | ||
| 235 | - //通过司机姓名获得进出记录 | ||
| 236 | - List<Scheduling> schedulingList1=schedulingS.get(personalName); | ||
| 237 | - //没匹配到匹配售票员 | ||
| 238 | - if(schedulingList1==null){ | ||
| 239 | - schedulingList1=schedulingSSell.get(personalName); | ||
| 240 | - } | ||
| 241 | - Scheduling scheduling = null; | ||
| 242 | - | ||
| 243 | - if(schedulingList1!=null){ | ||
| 244 | - Collections.sort(schedulingList1, Comparator.comparing(Scheduling::getTs).reversed()); | ||
| 245 | - for (int i1 = 0; i1 < schedulingList1.size(); i1++) { | ||
| 246 | - Scheduling s=schedulingList1.get(i1); | ||
| 247 | - //进站时间小于刷卡时间 | ||
| 248 | - if((Long.parseLong(s.getTs())-TIME2*60*1000)<=cardDate){ | ||
| 249 | - scheduling=s; | ||
| 250 | - b++; | ||
| 251 | - flag=true; | ||
| 252 | - break; | ||
| 253 | - } | 209 | + if (driver!=null) { |
| 210 | + String personalName = driver.getName();//司机姓名 | ||
| 211 | + gh=driver.getGh(); | ||
| 212 | + String time=String.valueOf(data.getTJRLRTIME());//时间 | ||
| 213 | + String date=String.valueOf(data.getTJRLRDATE());//日期 | ||
| 214 | + cardDate = LocalDateTime.parse(date+" "+time,dtf).toInstant(ZoneOffset.of("+8")).toEpochMilli(); //刷卡时间(时间戳) | ||
| 215 | + | ||
| 216 | + //通过司机姓名获得进出记录 | ||
| 217 | + List<Scheduling> schedulingList1=schedulingS.get(gh); | ||
| 218 | + //没匹配到匹配售票员 | ||
| 219 | + if(schedulingList1==null){ | ||
| 220 | + schedulingList1=schedulingSSell.get(gh); | ||
| 221 | + } | ||
| 222 | + Scheduling scheduling = null; | ||
| 223 | + | ||
| 224 | + if(schedulingList1!=null){ | ||
| 225 | + Collections.sort(schedulingList1, Comparator.comparing(Scheduling::getTs).reversed()); | ||
| 226 | + for (int i1 = 0; i1 < schedulingList1.size(); i1++) { | ||
| 227 | + Scheduling s=schedulingList1.get(i1); | ||
| 228 | + //进站时间小于刷卡时间 | ||
| 229 | + if((Long.parseLong(s.getTs())-TIME2*60*1000)<=cardDate){ | ||
| 230 | + scheduling=s; | ||
| 231 | + b++; | ||
| 232 | + flag=true; | ||
| 233 | + break; | ||
| 254 | } | 234 | } |
| 255 | - }else { | ||
| 256 | - mark="没有匹配的进站记录:"+personalName+" 工号:"+jobCodes; | ||
| 257 | } | 235 | } |
| 236 | + }else { | ||
| 237 | + mark="没有匹配的进站记录:"+personalName+" 工号:"+gh; | ||
| 238 | + System.out.println(mark); | ||
| 239 | + } | ||
| 258 | 240 | ||
| 259 | - if (scheduling!=null) { | ||
| 260 | - data.setLineId(scheduling.getXl_bm()); | ||
| 261 | - data.setSTATION_FLAG("1"); | ||
| 262 | - data.setTJRLUNITID(scheduling.getGs_name()); | ||
| 263 | - data.setTJRLSTATID(scheduling.getXl_name()); | ||
| 264 | - data.setROAD_FORM_TYPE(scheduling.getBc_type()); | ||
| 265 | - data.setUPDOWN(scheduling.getXl_dir()); | ||
| 266 | - data.setBUS_CODE(scheduling.getCl_zbh()); | ||
| 267 | - data.setBUS_PLATE(scheduling.getCar_plate()); | ||
| 268 | - data.setROAD_CODE(scheduling.getLp_name()); | ||
| 269 | - data.setDEPART_NAME(scheduling.getQdz_name()); | ||
| 270 | - data.setDEPART_CODE(scheduling.getQdz_code()); | ||
| 271 | - data.setDEPART_ACTUAL_TIME(scheduling.getFcsj_actual()); | ||
| 272 | - data.setREACH_NAME(scheduling.getZdz_name()); | ||
| 273 | - data.setREACH_CODE(scheduling.getZdz_code()); | ||
| 274 | - data.setREACH_ACTUAL_TIME(scheduling.getZdsj_actual()); | ||
| 275 | - if(scheduling.getStation_name()!=null){ | ||
| 276 | - data.setLEVELS_FLAG("1"); | ||
| 277 | - data.setLEVELS1(scheduling.getStation_route_code());//站点路由序号 | ||
| 278 | - data.setLEVELS_NAME1(scheduling.getStation_name());//站点名 | ||
| 279 | - data.setLEVELS1_CODE(scheduling.getStop_no());//站点编号 | ||
| 280 | - }else { | ||
| 281 | - data.setLEVELS_FLAG("0"); | ||
| 282 | - } | ||
| 283 | - } else { | ||
| 284 | - data.setSTATION_FLAG("0"); | 241 | + if (scheduling!=null) { |
| 242 | + data.setLineId(scheduling.getXl_bm()); | ||
| 243 | + data.setSTATION_FLAG("1"); | ||
| 244 | + data.setTJRLUNITID(scheduling.getGs_name()); | ||
| 245 | + data.setTJRLSTATID(scheduling.getXl_name()); | ||
| 246 | + data.setROAD_FORM_TYPE(scheduling.getBc_type()); | ||
| 247 | + data.setUPDOWN(scheduling.getXl_dir()); | ||
| 248 | + data.setBUS_CODE(scheduling.getCl_zbh()); | ||
| 249 | + data.setBUS_PLATE(scheduling.getCar_plate()); | ||
| 250 | + data.setROAD_CODE(scheduling.getLp_name()); | ||
| 251 | + data.setDEPART_NAME(scheduling.getQdz_name()); | ||
| 252 | + data.setDEPART_CODE(scheduling.getQdz_code()); | ||
| 253 | + data.setDEPART_ACTUAL_TIME(scheduling.getFcsj_actual()); | ||
| 254 | + data.setREACH_NAME(scheduling.getZdz_name()); | ||
| 255 | + data.setREACH_CODE(scheduling.getZdz_code()); | ||
| 256 | + data.setREACH_ACTUAL_TIME(scheduling.getZdsj_actual()); | ||
| 257 | + if(scheduling.getStation_name()!=null){ | ||
| 258 | + data.setLEVELS_FLAG("1"); | ||
| 259 | + data.setLEVELS1(scheduling.getStation_route_code());//站点路由序号 | ||
| 260 | + data.setLEVELS_NAME1(scheduling.getStation_name());//站点名 | ||
| 261 | + data.setLEVELS1_CODE(scheduling.getStop_no());//站点编号 | ||
| 262 | + }else { | ||
| 263 | + data.setLEVELS_FLAG("0"); | ||
| 285 | } | 264 | } |
| 265 | + } else { | ||
| 266 | + data.setSTATION_FLAG("0"); | ||
| 286 | } | 267 | } |
| 287 | }else { | 268 | }else { |
| 288 | - mark="未查工号:"+carId; | 269 | + mark="未查到工号:"+carId; |
| 289 | data.setSTATION_FLAG("0"); | 270 | data.setSTATION_FLAG("0"); |
| 271 | + System.out.println(mark); | ||
| 290 | } | 272 | } |
| 291 | if(mark.length()==0 && !flag){ | 273 | if(mark.length()==0 && !flag){ |
| 292 | - mark="没有匹配的班次 "+jobCodes+"刷卡时间为:"+LocalDateTime.ofEpochSecond(cardDate/1000, 0, ZoneOffset.ofHours(8)); | 274 | + mark="没有匹配的班次 "+gh+"刷卡时间为:"+LocalDateTime.ofEpochSecond(cardDate/1000, 0, ZoneOffset.ofHours(8)); |
| 275 | + System.out.println(mark); | ||
| 293 | } | 276 | } |
| 294 | data.setMARK(mark); | 277 | data.setMARK(mark); |
| 295 | - //如果是新数据 没匹配到 去除这条记录 并放入缓存等到下次继续匹配 | ||
| 296 | - if(!isOld && !flag){ | ||
| 297 | - List<TJRLDB> m =oldData; | ||
| 298 | - m.add(data); | ||
| 299 | - allData.set(i,null); | ||
| 300 | - | ||
| 301 | - } | ||
| 302 | } | 278 | } |
| 303 | - int size=allData.size(); | ||
| 304 | - allData.removeIf(Objects::isNull); | 279 | + int size=tjrldbs.size(); |
| 305 | //防止数据过多 分批插入 | 280 | //防止数据过多 分批插入 |
| 306 | - List<List<TJRLDB>> subList = getSubList(2000, allData); | 281 | + List<List<TJRLDB>> subList = getSubList(2000, tjrldbs); |
| 307 | if(!subList.isEmpty()){ | 282 | if(!subList.isEmpty()){ |
| 308 | subList.forEach(data->{ | 283 | subList.forEach(data->{ |
| 309 | if (!data.isEmpty()) { | 284 | if (!data.isEmpty()) { |
| @@ -311,91 +286,10 @@ public class Contrast { | @@ -311,91 +286,10 @@ public class Contrast { | ||
| 311 | } | 286 | } |
| 312 | }); | 287 | }); |
| 313 | } | 288 | } |
| 314 | - | ||
| 315 | - List<List<TJRLDB>> subList2 = getSubList(500, allData); | ||
| 316 | - if(!subList2.isEmpty()){ | ||
| 317 | - subList2.forEach(data->{ | ||
| 318 | - if (!data.isEmpty()) { | ||
| 319 | - Map<String, Object> map = new HashMap<>(); | ||
| 320 | - map.put("datatype", "passengerflow"); | ||
| 321 | - List<TJRL> data2 =new ArrayList<>(); | ||
| 322 | - for (TJRLDB tjrldb : data) { | ||
| 323 | - TJRL tjrl= new TJRL(tjrldb); | ||
| 324 | - data2.add(tjrl); | ||
| 325 | - } | ||
| 326 | - map.put("datas", data2); | ||
| 327 | - JSON j=new cn.hutool.json.JSONObject(map); | ||
| 328 | - String json =j.toString(); | ||
| 329 | - ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ", json); | ||
| 330 | - future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { | ||
| 331 | - @Override | ||
| 332 | - public void onSuccess(SendResult<String, String> result) { | ||
| 333 | - logger.info("kafka发送票务数据成功条数:"+data.size()); | ||
| 334 | - } | ||
| 335 | - @Override | ||
| 336 | - public void onFailure(Throwable ex) { | ||
| 337 | - logger.error("kafka发送票务数据异常", ex); | ||
| 338 | - } | ||
| 339 | - }); | ||
| 340 | - } | ||
| 341 | - }); | ||
| 342 | - } | ||
| 343 | - //如果是上次遗留的数据不管这是是否匹配到都清空 | ||
| 344 | - if(isOld){ | ||
| 345 | - oldData.clear(); | ||
| 346 | - } | ||
| 347 | logger.warn("======匹配"+size+"条======匹配到"+b+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒"); | 289 | logger.warn("======匹配"+size+"条======匹配到"+b+"条=====耗时=="+(System.currentTimeMillis() - start)/1000 + "秒"); |
| 348 | logger.info("===============================票务数据匹配结束================================"); | 290 | logger.info("===============================票务数据匹配结束================================"); |
| 349 | } | 291 | } |
| 350 | 292 | ||
| 351 | - | ||
| 352 | - | ||
| 353 | - | ||
| 354 | - | ||
| 355 | - | ||
| 356 | - | ||
| 357 | - public static int getWeek(String today)throws Exception{ | ||
| 358 | - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 359 | - Date date = null; | ||
| 360 | - try { | ||
| 361 | - date = format.parse(today); | ||
| 362 | - } catch (ParseException e) { | ||
| 363 | - // TODO Auto-generated catch block | ||
| 364 | - e.printStackTrace(); | ||
| 365 | - } | ||
| 366 | - | ||
| 367 | - Calendar calendar = Calendar.getInstance(); | ||
| 368 | - calendar.setFirstDayOfWeek(Calendar.MONDAY); | ||
| 369 | - calendar.setTime(date); | ||
| 370 | - return calendar.get(Calendar.WEEK_OF_YEAR); | ||
| 371 | - } | ||
| 372 | - | ||
| 373 | - public static String upperHeadChar(String in) { | ||
| 374 | - String head = in.substring(0, 1); | ||
| 375 | - String out = head.toUpperCase() + in.substring(1, in.length()); | ||
| 376 | - return out; | ||
| 377 | - } | ||
| 378 | - | ||
| 379 | - public static String getTransTime(String timeStr) throws Exception{ | ||
| 380 | - DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd HHmmss"); | ||
| 381 | - LocalDateTime date = LocalDateTime.parse(timeStr, df); | ||
| 382 | - DateTimeFormatter f2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
| 383 | - String transTime = f2.format(date); | ||
| 384 | - return transTime; | ||
| 385 | - } | ||
| 386 | - | ||
| 387 | - | ||
| 388 | - public void filterCardListByDB(Map<String,Object> params) throws Exception{ | ||
| 389 | - List<TJRLDB> records=siteMapper1.getRecords(params); | ||
| 390 | - for (TJRL record : records) { | ||
| 391 | - String date=record.getTJRLRDATE()+" "+String.format("%06d", Integer.parseInt(record.getTJRLRTIME())); | ||
| 392 | - String s=this.getTransTime(date); | ||
| 393 | - record.setTJRLRDATE(s.split(" ")[0]); | ||
| 394 | - record.setTJRLRTIME(s.split(" ")[1]); | ||
| 395 | - } | ||
| 396 | - filterCardList(records,false); | ||
| 397 | - } | ||
| 398 | - | ||
| 399 | public List<List<TJRLDB>> getSubList(int length, List<TJRLDB> list)throws Exception{ | 293 | public List<List<TJRLDB>> getSubList(int length, List<TJRLDB> list)throws Exception{ |
| 400 | int size = list.size(); | 294 | int size = list.size(); |
| 401 | int temp = size / length + 1; | 295 | int temp = size / length + 1; |
| @@ -414,13 +308,4 @@ public class Contrast { | @@ -414,13 +308,4 @@ public class Contrast { | ||
| 414 | return subList; | 308 | return subList; |
| 415 | } | 309 | } |
| 416 | 310 | ||
| 417 | - public static void main(String[] args) throws Exception{ | ||
| 418 | - String carId="B140C906"; | ||
| 419 | - Contrast contrast=new Contrast(); | ||
| 420 | - List<Map> driverCardList = contrast.getDriverCardList(); | ||
| 421 | - List<Map> collect = driverCardList.stream().filter(map -> map.get("cardno").equals(carId)).collect(Collectors.toList()); | ||
| 422 | - System.out.println(collect); | ||
| 423 | - } | ||
| 424 | - | ||
| 425 | - | ||
| 426 | } | 311 | } |
src/main/resources/application.properties
| 1 | -server.port=8088 | 1 | +server.port=8090 |
| 2 | 2 | ||
| 3 | -spring.datasource.db1.jdbc-url=jdbc:mysql://192.170.100.132:3306/control?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC | ||
| 4 | -spring.datasource.db1.username=ym | ||
| 5 | -spring.datasource.db1.password=Ym(12345678) | 3 | +spring.datasource.db1.jdbc-url=jdbc:mysql://10.10.150.103:3306/control?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC |
| 4 | +spring.datasource.db1.username=root | ||
| 5 | +spring.datasource.db1.password=fsodlgjiuigAQF2$9fs9 | ||
| 6 | spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver | 6 | spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver |
| 7 | spring.datasource.db1.druid.test-on-borrow=true | 7 | spring.datasource.db1.druid.test-on-borrow=true |
| 8 | spring.datasource.db1.druid.test-while-idle=true | 8 | spring.datasource.db1.druid.test-while-idle=true |
| 9 | 9 | ||
| 10 | -spring.datasource.db2.jdbc-url=jdbc:mysql://192.170.100.63:3306/ms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC | ||
| 11 | -spring.datasource.db2.username=ym | ||
| 12 | -spring.datasource.db2.password=Ym(12345678) | 10 | +spring.datasource.db2.jdbc-url=jdbc:mysql://10.10.150.103:3306/ms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC |
| 11 | +spring.datasource.db2.username=root | ||
| 12 | +spring.datasource.db2.password=fsodlgjiuigAQF2$9fs9 | ||
| 13 | spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver | 13 | spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver |
| 14 | spring.datasource.db2.druid.test-on-borrow=true | 14 | spring.datasource.db2.druid.test-on-borrow=true |
| 15 | spring.datasource.db2.druid.test-while-idle=true | 15 | spring.datasource.db2.druid.test-while-idle=true |
| @@ -22,16 +22,16 @@ logging.level.com.example.demo.mapper=info | @@ -22,16 +22,16 @@ logging.level.com.example.demo.mapper=info | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | #ftp | 24 | #ftp |
| 25 | -ftp.root= /home/sftp | ||
| 26 | -ftp.oldFile= /home/oldFile | ||
| 27 | - | ||
| 28 | - | ||
| 29 | -spring.kafka.bootstrap-servers=192.170.100.129:9092 | ||
| 30 | -spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer | ||
| 31 | -spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer | ||
| 32 | -spring.kafka.producer.buffer-memory=33554432 | ||
| 33 | -spring.kafka.producer.acks=all | ||
| 34 | -spring.kafka.producer.properties.max.request.size=20971520 | 25 | +#ftp.root= /home/sftp |
| 26 | +#ftp.oldFile= /home/oldFile | ||
| 27 | +# | ||
| 28 | +# | ||
| 29 | +#spring.kafka.bootstrap-servers=192.170.100.129:9092 | ||
| 30 | +#spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer | ||
| 31 | +#spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer | ||
| 32 | +#spring.kafka.producer.buffer-memory=33554432 | ||
| 33 | +#spring.kafka.producer.acks=all | ||
| 34 | +#spring.kafka.producer.properties.max.request.size=20971520 | ||
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | # | 37 | # |
src/main/resources/mapping/db1/Site-mapper1.xml
| @@ -55,7 +55,7 @@ | @@ -55,7 +55,7 @@ | ||
| 55 | cars.car_plate | 55 | cars.car_plate |
| 56 | FROM control.bsth_c_s_sp_info_real | 56 | FROM control.bsth_c_s_sp_info_real |
| 57 | LEFT JOIN control.bsth_c_cars cars ON cars.inside_code = cl_zbh | 57 | LEFT JOIN control.bsth_c_cars cars ON cars.inside_code = cl_zbh |
| 58 | - WHERE schedule_date_str in ('${startTime}','${endTime}') | 58 | + WHERE schedule_date_str ='${startTime}' and bc_type in ('normal','region') |
| 59 | order by equipment_code,fcsj_actual | 59 | order by equipment_code,fcsj_actual |
| 60 | </select> | 60 | </select> |
| 61 | 61 |