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 groupList = JSON.parseArray(groupJSON.getString("Groups"),AudioGroup.class); for(AudioGroup ag : groupList){ screenMapper.insertAudioGroup(ag); } } catch (Exception e) { throw new RuntimeException(e); } } }