Commit efbe29e53e1bd51f7b3bba3b74223e4ee282c06a
1 parent
c959f812
票务数据接口加密验证
Showing
4 changed files
with
52 additions
and
6 deletions
src/main/java/com/example/demo/SaticScheduleTask.java
| 1 | 1 | package com.example.demo; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import cn.hutool.crypto.digest.DigestUtil; | |
| 5 | +import cn.hutool.http.HttpRequest; | |
| 6 | +import cn.hutool.http.HttpResponse; | |
| 4 | 7 | import cn.hutool.http.HttpUtil; |
| 5 | 8 | import com.alibaba.fastjson.JSON; |
| 6 | 9 | import com.alibaba.fastjson.JSONObject; |
| 10 | +import com.example.demo.mapper.db1.SiteMapper1; | |
| 7 | 11 | import com.example.demo.model.Scheduling; |
| 8 | 12 | import com.example.demo.model.TJRLDB; |
| 9 | 13 | import com.example.demo.service.Contrast; |
| ... | ... | @@ -15,9 +19,11 @@ import org.springframework.scheduling.annotation.EnableScheduling; |
| 15 | 19 | import org.springframework.scheduling.annotation.Scheduled; |
| 16 | 20 | import org.springframework.stereotype.Component; |
| 17 | 21 | import javax.annotation.PostConstruct; |
| 22 | +import java.time.LocalDate; | |
| 18 | 23 | import java.time.LocalDateTime; |
| 19 | 24 | import java.time.format.DateTimeFormatter; |
| 20 | 25 | import java.util.*; |
| 26 | +import java.util.stream.Collectors; | |
| 21 | 27 | |
| 22 | 28 | /** |
| 23 | 29 | * @author Hill |
| ... | ... | @@ -34,21 +40,30 @@ public class SaticScheduleTask { |
| 34 | 40 | @Autowired |
| 35 | 41 | private Contrast contrast; |
| 36 | 42 | |
| 43 | + @Autowired | |
| 44 | + private SiteMapper1 siteMapper1; | |
| 37 | 45 | |
| 38 | 46 | |
| 39 | 47 | private static DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); |
| 40 | 48 | |
| 41 | 49 | |
| 50 | + private String pwd="qaz#123_abc"; | |
| 42 | 51 | |
| 43 | - | |
| 44 | - @Scheduled(cron = "0 0/5 * * * ?") | |
| 45 | - //@PostConstruct | |
| 52 | + @Scheduled(cron = "0 0 */4 * * ?") | |
| 53 | + @PostConstruct | |
| 46 | 54 | void getArrivalInfos(){ |
| 47 | 55 | logger.info("票务数据缓存加载: " + LocalDateTime.now()); |
| 48 | 56 | try { |
| 49 | - LocalDateTime now=LocalDateTime.now(); | |
| 57 | + LocalDateTime now= LocalDate.now().atStartOfDay(); | |
| 50 | 58 | /*DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); |
| 51 | 59 | now=LocalDateTime.parse("2025-03-14 00:00",tdf);*/ |
| 60 | + LocalDateTime rq=now.minusDays(1); | |
| 61 | + DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
| 62 | + int count=siteMapper1.countResult(rq.format(tdf)); | |
| 63 | + if(count>0){ | |
| 64 | + logger.info("==============================="+rq.format(tdf)+"已生成================================"); | |
| 65 | + return; | |
| 66 | + } | |
| 52 | 67 | List<Map<String,List<Scheduling>>> result=contrast.getSchedulingS(now,1); |
| 53 | 68 | contrast.getSchedulingS=result.get(0); |
| 54 | 69 | contrast.getSchedulingSSell=result.get(1); |
| ... | ... | @@ -56,6 +71,12 @@ public class SaticScheduleTask { |
| 56 | 71 | DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyyMMdd"); |
| 57 | 72 | String date=now.minusDays(1).format(dtf); |
| 58 | 73 | List<TJRLDB> tjrldbs=loadTJRL(date); |
| 74 | + tjrldbs.stream() | |
| 75 | + .collect(Collectors.toMap( | |
| 76 | + tjrldb -> Arrays.asList(tjrldb.getTJRLPOSID(), tjrldb.getPOS_SEQ_ID(), tjrldb.getTJRLCARDNO(), tjrldb.getCOUNT()), // 创建复合键 | |
| 77 | + tjrldb -> tjrldb, | |
| 78 | + (existing, replacement) -> existing // 当键冲突时,保留现有的元素 | |
| 79 | + )).values().stream().collect(Collectors.toList()); // 将Map转换回List | |
| 59 | 80 | logger.info("===============================交易数"+tjrldbs.size()+",读取文件结束================================"); |
| 60 | 81 | contrast.filterCardList(tjrldbs); |
| 61 | 82 | } catch (Exception e) { |
| ... | ... | @@ -67,10 +88,19 @@ public class SaticScheduleTask { |
| 67 | 88 | public List<TJRLDB> loadTJRL(String date){ |
| 68 | 89 | List<TJRLDB> listMap = new ArrayList<>(); |
| 69 | 90 | try { |
| 91 | + String md5Hex = DigestUtil.md5Hex(pwd); | |
| 92 | + // 转换为32位大写字符串 | |
| 93 | + String md5HexUpperCase = md5Hex.toUpperCase(); | |
| 70 | 94 | JSONObject params=new JSONObject(); |
| 71 | 95 | 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()); | |
| 96 | + HttpResponse resp = HttpRequest.post("http://10.10.150.53:8184/cardSys/data/act") | |
| 97 | + .header("Content-Type", "application/json") | |
| 98 | + .header("username", "lgpw_act") | |
| 99 | + .header("password", md5HexUpperCase) | |
| 100 | + .header("timestamp", String.valueOf(System.currentTimeMillis())) | |
| 101 | + .body(params.toString()) // 将JSON对象转为字符串 | |
| 102 | + .execute(); | |
| 103 | + JSONObject jsonObject=JSONObject.parseObject(resp.body()); | |
| 74 | 104 | if(jsonObject.getString("code").equals("0")){ |
| 75 | 105 | String ja=jsonObject.getString("data"); |
| 76 | 106 | List<Map> result= JSON.parseArray(ja,Map.class); |
| ... | ... | @@ -91,6 +121,7 @@ public class SaticScheduleTask { |
| 91 | 121 | tjrl.setTJRLORGAMT(String.valueOf(map.get("ORIGNAL_TXN_AMOUNT")));//优惠前原始票价,单位:分 |
| 92 | 122 | tjrl.setTJRLTXFG(String.valueOf(map.get("CARD_SPEC")));//卡规范(01—建设部卡、02—交通部卡、03—二维码扫码) |
| 93 | 123 | tjrl.setCOUNT(String.valueOf(map.get("COUNT")));//卡计数器 |
| 124 | + tjrl.setPOS_SEQ_ID(String.valueOf(map.get("POS_SEQ_ID")));//POS流水号 | |
| 94 | 125 | listMap.add(tjrl); |
| 95 | 126 | } |
| 96 | 127 | } | ... | ... |
src/main/java/com/example/demo/mapper/db1/SiteMapper1.java
src/main/java/com/example/demo/model/TJRL.java
| ... | ... | @@ -49,6 +49,7 @@ public class TJRL implements Cloneable { |
| 49 | 49 | private String TRAD_ID; |
| 50 | 50 | private String COUNT;//计数器 |
| 51 | 51 | private String lineId; |
| 52 | + private String POS_SEQ_ID; | |
| 52 | 53 | public TJRL(){ |
| 53 | 54 | |
| 54 | 55 | } |
| ... | ... | @@ -400,4 +401,12 @@ public class TJRL implements Cloneable { |
| 400 | 401 | public void setLineId(String lineId) { |
| 401 | 402 | this.lineId = lineId; |
| 402 | 403 | } |
| 404 | + | |
| 405 | + public String getPOS_SEQ_ID() { | |
| 406 | + return POS_SEQ_ID; | |
| 407 | + } | |
| 408 | + | |
| 409 | + public void setPOS_SEQ_ID(String POS_SEQ_ID) { | |
| 410 | + this.POS_SEQ_ID = POS_SEQ_ID; | |
| 411 | + } | |
| 403 | 412 | } | ... | ... |
src/main/resources/mapping/db1/Site-mapper1.xml
| ... | ... | @@ -70,5 +70,8 @@ |
| 70 | 70 | from ${table} where TJRLRDATE >= '${start}' and TJRLRDATE < '${end}' |
| 71 | 71 | </select> |
| 72 | 72 | |
| 73 | + <select id="countResult" resultType="int"> | |
| 74 | + select count(*) from passenger_flow.t_jc_result where TJRLRDATE = #{rq} | |
| 75 | + </select> | |
| 73 | 76 | |
| 74 | 77 | </mapper> |
| 75 | 78 | \ No newline at end of file | ... | ... |