ipo
zyy3
2026-01-06 97f6fdc09138a2346b61ccc4c716e87ab58e590f
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
package com.yami.trading.service.cms.impl;
 
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.trading.bean.cms.Infomation;
import com.yami.trading.common.http.HttpHelper;
import com.yami.trading.common.util.RedisUtil;
import com.yami.trading.dao.cms.InfomationMapper;
import com.yami.trading.service.cms.InfomationService;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lucas
 * @since 2023-06-19 23:44:55
 */
@Service
public class InfomationServiceImpl extends ServiceImpl<InfomationMapper, Infomation> implements InfomationService {
    public void getInformation() {
        String cookie = HttpHelper.getCookie("https://xueqiu.com/");
        String url = "https://xueqiu.com/statuses/livenews/list.json?since_id=-1&max_id=-1&count=15";
        String json = HttpHelper.sendGetHttp(url, null, cookie);
        JSONArray items = JSONObject.parseObject(json).getJSONArray("items");
        List<Infomation> infomations = new ArrayList<>();
        items.forEach(d -> {
            Infomation infom = new Infomation();
            JSONObject data = (JSONObject) d;
            String dataId = data.getString("id");
            infom.setDataId(dataId);
            String description = data.getString("text");
            infom.setDescription(description);
            String createAt = data.getString("created_at");
            infom.setCreatedAt(createAt);
            infom.setType("1");
            String originUrl = data.getString("target");
            infom.setOriginUrl(originUrl);
            String source = getSource(description);
            infom.setSource(source);
            infom.setLang("zh-CN");
            String key = "infomation" + originUrl;
            if (RedisUtil.get(key) == null) {
                infomations.add(infom);
                // url存一周
                RedisUtil.set(key, 1, 60 * 60 * 24 * 7);
            }
        });
        if(infomations.size()>1){
            saveBatch(infomations);
        }
    }
 
    public static String getSource(String text) {
 
        String pattern = "(([^()]*))$"; // 匹配最后一个括号内的文本
 
        Pattern regex = Pattern.compile(pattern);
        Matcher matcher = regex.matcher(text);
 
        if (matcher.find()) {
            String endText = matcher.group(1);
            return endText;
        } else {
            return "";
        }
    }
}