张晓波
2023-12-05 d2db97aec62ef8a567f2f61eda1c5b7a6f95dc4b
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
package com.thhy.screen.config;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.utils.StringUtils;
import com.thhy.screen.modules.biz.audio.entity.AudioGroup;
import com.thhy.screen.modules.biz.bigscreen.mapper.BigScreenMapper;
import com.thhy.screen.utils.AudioUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
 
import java.util.List;
 
@Configuration
public class StartListener implements ApplicationRunner {
 
    @Autowired
    private BigScreenMapper screenMapper;
 
    @Override
    public void run(ApplicationArguments args){
        try {
            String result = AudioUtils.getGroups();
            if(StringUtils.isEmpty(result)){
                return;
            }
            JSONObject groupJSON = JSON.parseObject(result);
            List<AudioGroup> groupList = JSON.parseArray(groupJSON.getString("Groups"),AudioGroup.class);
            for(AudioGroup ag : groupList){
                screenMapper.insertAudioGroup(ag);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}