package com.rongyichuang.judge.service;
|
|
import com.rongyichuang.judge.entity.Tag;
|
import com.rongyichuang.judge.repository.TagRepository;
|
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Arrays;
|
import java.util.List;
|
|
@Service
|
public class DataInitService implements CommandLineRunner {
|
|
private final TagRepository tagRepository;
|
|
public DataInitService(TagRepository tagRepository) {
|
this.tagRepository = tagRepository;
|
}
|
|
@Override
|
public void run(String... args) throws Exception {
|
// 检查是否已有数据
|
if (tagRepository.count() == 0) {
|
initTags();
|
}
|
}
|
|
private void initTags() {
|
List<Tag> tags = Arrays.asList(
|
createTag("软件工程", "software_engineering", "major"),
|
createTag("人工智能", "artificial_intelligence", "major"),
|
createTag("机械设计", "mechanical_design", "major"),
|
createTag("工业设计", "industrial_design", "major"),
|
createTag("创新创业", "innovation_entrepreneurship", "major"),
|
createTag("项目管理", "project_management", "major"),
|
createTag("数据科学", "data_science", "major"),
|
createTag("网络安全", "cyber_security", "major"),
|
createTag("物联网", "internet_of_things", "major"),
|
createTag("区块链", "blockchain", "major"),
|
createTag("云计算", "cloud_computing", "major"),
|
createTag("移动开发", "mobile_development", "major")
|
);
|
|
tagRepository.saveAll(tags);
|
System.out.println("初始化专业标签数据完成,共创建 " + tags.size() + " 个标签");
|
}
|
|
private Tag createTag(String name, String code, String category) {
|
Tag tag = new Tag();
|
tag.setName(name);
|
tag.setCode(code);
|
tag.setCategory(category);
|
return tag;
|
}
|
}
|