[chuni] fix user item being overwritten

[api] fix set diva news
pull/1/head
samnyan 2020-01-18 13:29:34 +09:00
parent c230c47c36
commit a417e4032c
6 changed files with 24 additions and 13 deletions

View File

@ -13,7 +13,10 @@ import icu.samnyan.aqua.sega.chunithm.model.userdata.UserMusicDetail;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserPlaylog; import icu.samnyan.aqua.sega.chunithm.model.userdata.UserPlaylog;
import icu.samnyan.aqua.sega.chunithm.service.*; import icu.samnyan.aqua.sega.chunithm.service.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
@ -129,11 +132,11 @@ public class ApiAmazonController {
return gameMusicService.getAll(); return gameMusicService.getAll();
} }
@PostMapping("music/import") // @PostMapping("music/import")
public List<Music> addMusic(@RequestBody List<Music> musicList) { // public List<Music> addMusic(@RequestBody List<Music> musicList) {
musicList.forEach(music -> music.getLevels().forEach((integer, level) -> level.setMusic(music))); // musicList.forEach(music -> music.getLevels().forEach((integer, level) -> level.setMusic(music)));
return gameMusicService.saveAll(musicList); // return gameMusicService.saveAll(musicList);
} // }
private int calculateRating(int levelBase, int score) { private int calculateRating(int levelBase, int score) {
if (score >= 1007500) return levelBase + 200; if (score >= 1007500) return levelBase + 200;

View File

@ -113,7 +113,9 @@ public class ApiDivaManageController {
@PutMapping("news") @PutMapping("news")
public PropertyEntry updateNews(@RequestBody PropertyEntry property) { public PropertyEntry updateNews(@RequestBody PropertyEntry property) {
PropertyEntry entry = propertyEntryRepository.findByPropertyKey("diva_news").orElseGet(() -> new PropertyEntry("diva_news", property.getPropertyValue())); PropertyEntry entry = propertyEntryRepository.findByPropertyKey("diva_news")
.orElseGet(() -> new PropertyEntry("diva_news"));
entry.setPropertyValue(property.getPropertyValue());
return propertyEntryRepository.save(entry); return propertyEntryRepository.save(entry);
} }
@ -124,7 +126,9 @@ public class ApiDivaManageController {
@PutMapping("warning") @PutMapping("warning")
public PropertyEntry updateWarning(@RequestBody PropertyEntry property) { public PropertyEntry updateWarning(@RequestBody PropertyEntry property) {
PropertyEntry entry = propertyEntryRepository.findByPropertyKey("diva_warning").orElseGet(() -> new PropertyEntry("diva_warning", property.getPropertyValue())); PropertyEntry entry = propertyEntryRepository.findByPropertyKey("diva_warning")
.orElseGet(() -> new PropertyEntry("diva_warning"));
entry.setPropertyValue(property.getPropertyValue());
return propertyEntryRepository.save(entry); return propertyEntryRepository.save(entry);
} }

View File

@ -15,7 +15,7 @@ import java.util.Optional;
@Repository @Repository
public interface UserItemRepository extends JpaRepository<UserItem, Long> { public interface UserItemRepository extends JpaRepository<UserItem, Long> {
Optional<UserItem> findTopByUserAndItemIdOrderByIdDesc(UserData user, int itemId); Optional<UserItem> findTopByUserAndItemIdAndItemKindOrderByIdDesc(UserData user, int itemId, int itemKind);
Page<UserItem> findAllByUser_Card_ExtIdAndItemKind(long extId, int itemKind, Pageable pageable); Page<UserItem> findAllByUser_Card_ExtIdAndItemKind(long extId, int itemKind, Pageable pageable);
} }

View File

@ -191,16 +191,17 @@ public class UpsertUserAllHandler implements BaseHandler {
userItemList.forEach(userItemMap -> { userItemList.forEach(userItemMap -> {
String itemId = (String) userItemMap.get("itemId"); String itemId = (String) userItemMap.get("itemId");
String itemKind = (String) userItemMap.get("itemKind");
Optional<UserItem> userItemOptional = userItemService.getByUserAndItemId(newUserData, itemId); Optional<UserItem> userItemOptional = userItemService.getByUserAndItemId(newUserData, itemId, itemKind);
UserItem userItem = userItemOptional.orElseGet(() -> new UserItem(newUserData)); UserItem userItem = userItemOptional.orElseGet(() -> new UserItem(newUserData));
UserItem newUserItem = mapper.convert(userItemMap, UserItem.class); UserItem newUserItem = mapper.convert(userItemMap, UserItem.class);
newUserItem.setId(userItem.getId()); newUserItem.setId(userItem.getId());
newUserItem.setUser(userItem.getUser()); newUserItem.setUser(userItem.getUser());
newUserItemMap.put(itemId, newUserItem); newUserItemMap.put(itemId + "-" + itemKind, newUserItem);
}); });
userItemService.saveAll(newUserItemMap.values()); userItemService.saveAll(newUserItemMap.values());
} }

View File

@ -25,8 +25,8 @@ public class UserItemService {
} }
public Optional<UserItem> getByUserAndItemId(UserData user, String itemId) { public Optional<UserItem> getByUserAndItemId(UserData user, String itemId, String itemKind) {
return userItemRepository.findTopByUserAndItemIdOrderByIdDesc(user, Integer.parseInt(itemId)); return userItemRepository.findTopByUserAndItemIdAndItemKindOrderByIdDesc(user, Integer.parseInt(itemId), Integer.parseInt(itemKind));
} }
public UserItem save(UserItem userItem) { public UserItem save(UserItem userItem) {

View File

@ -30,4 +30,7 @@ public class PropertyEntry implements Serializable {
this.propertyKey = propertyKey; this.propertyKey = propertyKey;
this.propertyValue = propertyValue; this.propertyValue = propertyValue;
} }
public PropertyEntry(String propertyKey) {
this.propertyKey = propertyKey;
}
} }