parent
36eb8e64c3
commit
47f92fa866
@ -1,95 +0,0 @@ |
|||||||
//--------------------------------
|
|
||||||
// InitStuffs.java
|
|
||||||
//
|
|
||||||
// 更新履歴:2025/06/10 新規作成
|
|
||||||
// Copyright(c) 2025 IVIS All rights reserved.
|
|
||||||
//
|
|
||||||
// Stuffsの初期データを起動時に設定するクラス
|
|
||||||
// すでにデータが存在する場合は、一時的にコメント部を有効にして
|
|
||||||
// 既存データを削除してから実行してください。
|
|
||||||
//--------------------------------------------
|
|
||||||
|
|
||||||
package com.example.todoapp.config; |
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct; |
|
||||||
|
|
||||||
import com.example.todoapp.model.ToBuys; |
|
||||||
import com.example.todoapp.repository.ToBuysRepository; |
|
||||||
import com.example.todoapp.model.Stocks; |
|
||||||
import com.example.todoapp.repository.StocksRepository; |
|
||||||
import com.example.todoapp.model.Recipes; |
|
||||||
import com.example.todoapp.repository.RecipesRepository; |
|
||||||
import com.example.todoapp.model.RecipeStuffs; |
|
||||||
import com.example.todoapp.repository.RecipeStuffsRepository; |
|
||||||
import com.example.todoapp.model.Stuffs; |
|
||||||
import com.example.todoapp.repository.StuffsRepository; |
|
||||||
|
|
||||||
@Configuration |
|
||||||
public class InitStuff { |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private ToBuysRepository tobuysRepository; |
|
||||||
@Autowired |
|
||||||
private StocksRepository stocksRepository; |
|
||||||
@Autowired |
|
||||||
private RecipesRepository recipesRepository; |
|
||||||
@Autowired |
|
||||||
private RecipeStuffsRepository recipeStuffsRepository; |
|
||||||
@Autowired |
|
||||||
private StuffsRepository stuffsRepository; |
|
||||||
|
|
||||||
@PostConstruct |
|
||||||
public void initStuff() { |
|
||||||
|
|
||||||
// tobuysRepository.deleteAll();
|
|
||||||
// stocksRepository.deleteAll();
|
|
||||||
// stuffsRepository.deleteAll();
|
|
||||||
|
|
||||||
if (stuffsRepository.count() > 0) { |
|
||||||
return; // すでにデータが存在する場合は何もしない
|
|
||||||
|
|
||||||
} else { |
|
||||||
setNewStuff(1L, "牛乳", null, "乳製品"); |
|
||||||
setNewStuff(2L, "ヨーグルト", null, "乳製品"); |
|
||||||
setNewStuff(3L, "チーズ", null, "乳製品"); |
|
||||||
setNewStuff(4L, "バター", null, "乳製品"); |
|
||||||
setNewStuff(5L, "生クリーム", null, "乳製品"); |
|
||||||
|
|
||||||
setNewStuff(6L, "鮭", null, "魚・肉"); |
|
||||||
setNewStuff(7L, "鶏むね肉", null, "魚・肉"); |
|
||||||
setNewStuff(8L, "豚バラ肉", null, "魚・肉"); |
|
||||||
setNewStuff(9L, "牛ひき肉", null, "魚・肉"); |
|
||||||
setNewStuff(10L, "まぐろ", null, "魚・肉"); |
|
||||||
|
|
||||||
setNewStuff(11L, "にんじん", null, "野菜"); |
|
||||||
setNewStuff(12L, "キャベツ", null, "野菜"); |
|
||||||
setNewStuff(13L, "ほうれん草", null, "野菜"); |
|
||||||
setNewStuff(14L, "玉ねぎ", null, "野菜"); |
|
||||||
setNewStuff(15L, "ピーマン", null, "野菜"); |
|
||||||
|
|
||||||
setNewStuff(16L, "醤油", null, "調味料"); |
|
||||||
setNewStuff(17L, "味噌", null, "調味料"); |
|
||||||
setNewStuff(18L, "塩", null, "調味料"); |
|
||||||
setNewStuff(19L, "砂糖", null, "調味料"); |
|
||||||
setNewStuff(20L, "酢", null, "調味料"); |
|
||||||
|
|
||||||
setNewStuff(21L, "米", null, "その他"); |
|
||||||
setNewStuff(22L, "パスタ", null, "その他"); |
|
||||||
setNewStuff(23L, "小麦粉", null, "その他"); |
|
||||||
setNewStuff(24L, "卵", null, "その他"); |
|
||||||
setNewStuff(25L, "豆腐", null, "その他"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void setNewStuff(Long stuffId, String stuffName, String summary, String category) { |
|
||||||
Stuffs stuff = new Stuffs(); |
|
||||||
stuff.setStuffId(stuffId); |
|
||||||
stuff.setStuffName(stuffName); |
|
||||||
stuff.setSummary(summary); |
|
||||||
stuff.setCategory(category); |
|
||||||
stuffsRepository.save(stuff); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue