admin
2025-05-09 6159dc58f50d3e4680779b7989bbd4d49a76bad5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.taoke.autopay;
 
import com.taoke.autopay.dao.KeyOrderMapper;
import com.taoke.autopay.entity.KeyOrder;
import com.taoke.autopay.utils.Constant;
import com.taoke.autopay.utils.TimeUtil;
import net.sf.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.util.*;
 
/**
 * @author hxh
 * @title: LogTest
 * @description: TODO
 * @date 2024/7/19 12:15
 */
@SpringBootTest
public class LogTest {
 
 
    @Resource
    private KeyOrderMapper keyOrderMapper;
 
    @Test
    public void parseLog() throws FileNotFoundException {
 
        String[] days = new String[]{"2024-07-15","2024-07-16","2024-07-17","2024-07-18"};
        for(String day:days) {
            Scanner scanner = new Scanner(new FileInputStream("D:\\文件传输\\交易\\日志文件\\xcp\\pay.log.gz."+day));
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                if (!line.contains("setOrderNo:")) {
                    continue;
                }
                String[] sts = line.split("setOrderNo:")[1].split("-");
                String id = sts[0].trim();
                String money = sts[sts.length - 1].replace("¥", "");
                System.out.println(id + ":" + money);
                KeyOrder order = keyOrderMapper.selectById(id);
                if(order!=null){
                    KeyOrder update=new KeyOrder();
                    update.setId(id);
                    update.setOrderMoney(new BigDecimal(money));
                    keyOrderMapper.updateByPrimaryKeySelective(update);
                }
            }
            scanner.close();
 
        }
 
    }
 
    @Test
    public void parseLogForChannel() throws FileNotFoundException {
 
        String[] days = new String[]{"2024-07-15","2024-07-16","2024-07-17","2024-07-18"};
 
        for(String day:days) {
            Set<String> bps=new HashSet<>();
            Set<String> cyx=new HashSet<>();
            Scanner scanner = new Scanner(new FileInputStream("D:\\文件传输\\交易\\日志文件\\xcp\\info.log.gz."+day));
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                if (!line.contains("抖音订单查询")) {
                    continue;
                }
                line =  line.split("dyorderApiLogger -")[1];
                int startIndex = line.indexOf(":");
                String tag = line.substring(0,startIndex).trim();
                String id =  line.substring(startIndex + 1,line.indexOf("-")).trim();
                String data =  line.substring(line.indexOf("-")+1);
                if(tag.contains("(1)")){
                    cyx.add(id);
                }else if(tag.contains("(2)")){
                    bps.add(id);
                }
            }
 
            Set<String> totalOrderNos=new HashSet<>();
            totalOrderNos.addAll(bps);
            totalOrderNos.addAll(cyx);
            Map<String,String> orderChannelMap = new HashMap<>();
            // 交集里面的订单不属于任何一个渠道
            Set<String> intersection = new HashSet<>(bps);
            intersection.retainAll(cyx);
            for(String r:intersection){
                orderChannelMap.put(r,null);
            }
            // 差集属于bps
            Set<String> difference = new HashSet<>(cyx);
            difference.removeAll(bps);
            for(String r:difference){
                orderChannelMap.put(r,Constant.ORDER_CHANNEL_BPS);
            }
 
            // 当天订单与totalOrderNos的所有差集属于cyx
            Date minCreateTime =new Date(TimeUtil.convertToTimeTemp(day,"yyyy-MM-dd"));
            Date maxCreateTime =TimeUtil.getNextDay(1,new Date(TimeUtil.convertToTimeTemp(day,"yyyy-MM-dd")).getTime());
            KeyOrderMapper.DaoQuery query=new KeyOrderMapper.DaoQuery();
            query.minCreateTime =minCreateTime;
            query.maxCreateTime =maxCreateTime;
            query.start = 0;
            query.count =10000;
            query.state = KeyOrder.STATE_PAY;
            List<KeyOrder> orders =  keyOrderMapper.list(query);
            Set<String> dayOrderNos=new HashSet<>();
            for(KeyOrder o:orders){
                if(!StringUtil.isNullOrEmpty(o.getOrderNo())) {
                    dayOrderNos.add(o.getOrderNo());
                }
            }
            dayOrderNos.removeAll(totalOrderNos);
            for(String r:dayOrderNos){
                orderChannelMap.put(r,Constant.ORDER_CHANNEL_CYX);
            }
        for(Iterator<String> its= orderChannelMap.keySet().iterator();its.hasNext();){
            String orderNo = its.next();
            query=new KeyOrderMapper.DaoQuery();
            query.orderNo = orderNo;
            query.start=0;
            query.count =100;
            orders =  keyOrderMapper.list(query);
            for(KeyOrder order:orders){
                if(order.getState()== KeyOrder.STATE_PAY){
                  String channel =  orderChannelMap.get(orderNo);
                  if(channel!=null){
                      KeyOrder update=new KeyOrder();
                      update.setId(order.getId());
                      update.setOrderChannel(channel);
                      update.setUpdateTime(new Date());
                      keyOrderMapper.updateByPrimaryKeySelective(update);
                  }
                }
            }
        }
            scanner.close();
        }
 
 
 
    }
 
}