SQL formatting
This commit is contained in:
parent
dfaffa20f6
commit
265bc1d608
4
pom.xml
4
pom.xml
@ -153,8 +153,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>14</source>
|
||||
<target>14</target>
|
||||
<source>15</source>
|
||||
<target>15</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -104,6 +104,7 @@ public class GameServer {
|
||||
switch (UserCommandType.fromString(message.getCommandType())) {
|
||||
case GetUserInitData:
|
||||
String r = xmlMapper.writeValueAsString(users.getUserInitInfoByUserId(playerId));
|
||||
log.info("GetUserInitData: {}", r);
|
||||
this.sendResult(playerId, message.getTransactionId(), r);
|
||||
break;
|
||||
case UserFriendsGet: // todo: implement
|
||||
|
@ -6,14 +6,14 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class InitMagicAbility {
|
||||
|
||||
public interface InitMagicAbility {
|
||||
@JacksonXmlProperty(localName = "Id", isAttribute = true)
|
||||
private Integer id;
|
||||
Integer getId();
|
||||
|
||||
@JacksonXmlProperty(localName = "ExpirationDate", isAttribute = true)
|
||||
private String expirationDate;
|
||||
String getExpirationDate();
|
||||
|
||||
@JacksonXmlProperty(localName = "IsLimited", isAttribute = true)
|
||||
@JsonSerialize(using= NumericBooleanSerializer.class)
|
||||
private Boolean isLimited;
|
||||
Integer getIsLimited();
|
||||
}
|
||||
|
@ -3,8 +3,10 @@ package com.alterdekim.game.repository;
|
||||
import com.alterdekim.game.component.game.AvatarInventoryType;
|
||||
import com.alterdekim.game.component.game.avatar.IBodyAvatarItem;
|
||||
import com.alterdekim.game.component.game.avatar.GoodClothType;
|
||||
import com.alterdekim.game.component.game.avatar.InitMagicAbility;
|
||||
import com.alterdekim.game.component.game.inventory.InventoryItem;
|
||||
import com.alterdekim.game.entity.AvatarInventory;
|
||||
import com.alterdekim.game.entity.Smile;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
@ -33,18 +35,107 @@ public interface AvatarInventoryRepository extends JpaRepository<AvatarInventory
|
||||
@Query(value = "UPDATE AvatarInventory a SET a.isUsed = true WHERE a.user.id = :userId AND a.type = :type AND a.goodId = :goodId")
|
||||
void setUsed(@Param("userId") Long userId, @Param("goodId") Long goodId, @Param("type") AvatarInventoryType type);
|
||||
|
||||
@Query(value = "SELECT a.good_id AS id, g.trid AS textResourceId, 0 AS bodyPartId, g.mrid AS mediaResourceId, (case when (a.is_used > 0) then true else false end) AS isUsed, false AS isColorable, 0 AS color, false AS isLimited, g.publish_date AS date, 0 AS pollution, false AS isBodyPart, 0 AS phoneId FROM avatar_inventory AS a JOIN goods AS g ON a.good_id = g.id WHERE a.user_id = :uid AND a.type = 'Clothes' AND g.good_type_id = :#{#goodTypeId.getVal()}", nativeQuery = true)
|
||||
@Query(value = """
|
||||
SELECT
|
||||
a.good_id AS id,
|
||||
g.trid AS textResourceId,
|
||||
0 AS bodyPartId,
|
||||
g.mrid AS mediaResourceId,
|
||||
(case when (a.is_used > 0) then true else false end) AS isUsed,
|
||||
false AS isColorable,
|
||||
0 AS color,
|
||||
false AS isLimited,
|
||||
g.publish_date AS date,
|
||||
0 AS pollution,
|
||||
false AS isBodyPart,
|
||||
0 AS phoneId
|
||||
FROM avatar_inventory AS a
|
||||
JOIN goods AS g
|
||||
ON a.good_id = g.id
|
||||
WHERE a.user_id = :uid AND a.type = 'Clothes' AND g.good_type_id = :#{#goodTypeId.getVal()}""", nativeQuery = true)
|
||||
List<InventoryItem> findInventoryItems(@Param("uid") Long userId, @Param("goodTypeId") GoodClothType goodClothType);
|
||||
|
||||
@Query(value = "SELECT b.id AS id, 0 AS textResourceId, 0 AS bodyPartId, 0 AS mediaResourceId, (case when (a.is_used > 0) then true else false end) AS isUsed, false AS isColorable, 0 AS color, false AS isLimited, '' AS date, 0 AS pollution, false AS isBodyPart, 0 AS phoneId FROM backgrounds b JOIN (SELECT a.good_id, a.is_used FROM avatar_inventory a WHERE a.`type` = 'Backgrounds' AND a.user_id = :uid) AS a ON a.good_id = b.id", nativeQuery = true)
|
||||
@Query(value = """
|
||||
SELECT
|
||||
b.id AS id,
|
||||
0 AS textResourceId,
|
||||
0 AS bodyPartId,
|
||||
0 AS mediaResourceId,
|
||||
(case when (a.is_used > 0) then true else false end) AS isUsed,
|
||||
false AS isColorable,
|
||||
0 AS color,
|
||||
false AS isLimited,
|
||||
'' AS date,
|
||||
0 AS pollution,
|
||||
false AS isBodyPart,
|
||||
0 AS phoneId
|
||||
FROM backgrounds b
|
||||
JOIN (SELECT a.good_id, a.is_used FROM avatar_inventory a WHERE a.`type` = 'Backgrounds' AND a.user_id = :uid) AS a
|
||||
ON a.good_id = b.id""", nativeQuery = true)
|
||||
List<InventoryItem> findBackgrounds(@Param("uid") Long userId);
|
||||
|
||||
@Query(value = "SELECT p.id AS id, 0 AS textResourceId, 0 AS bodyPartId, 0 AS mediaResourceId, (case when (a.is_used > 0) then true else false end) AS isUsed, false AS isColorable, 0 AS color, false AS isLimited, '' AS date, 0 AS pollution, false AS isBodyPart, p.id AS phoneId FROM phone_icons p JOIN (SELECT a.good_id, a.is_used FROM avatar_inventory a WHERE a.`type` = 'Phones' AND a.user_id = :uid) AS a ON a.good_id = p.id", nativeQuery = true)
|
||||
@Query(value = """
|
||||
SELECT
|
||||
p.id AS id,
|
||||
0 AS textResourceId,
|
||||
0 AS bodyPartId,
|
||||
0 AS mediaResourceId,
|
||||
(case when (a.is_used > 0) then true else false end) AS isUsed,
|
||||
false AS isColorable,
|
||||
0 AS color,
|
||||
false AS isLimited,
|
||||
'' AS date,
|
||||
0 AS pollution,
|
||||
false AS isBodyPart,
|
||||
p.id AS phoneId
|
||||
FROM phone_icons p
|
||||
JOIN (SELECT a.good_id, a.is_used FROM avatar_inventory a WHERE a.`type` = 'Phones' AND a.user_id = :uid) AS a
|
||||
ON a.good_id = p.id""", nativeQuery = true)
|
||||
List<InventoryItem> findPhones(@Param("uid") Long userId);
|
||||
|
||||
@Query(value = "SELECT b.`type` AS bodyPartTypeId, b.id AS id, a.color AS color, 1 AS isBodyPart, b.id AS bodyPartId, 0 AS goodId, b.media_resource_id AS mediaResourceId, b.`type` AS layerId, 0 AS goodTypeId FROM bodyparts b JOIN (SELECT a.color, a.good_id FROM avatar_inventory a WHERE a.user_id = :uid AND a.`type` = 'BodyParts' AND a.is_used = true) AS a ON a.good_id = b.id", nativeQuery = true)
|
||||
@Query(value = """
|
||||
SELECT
|
||||
b.`type` AS bodyPartTypeId,
|
||||
b.id AS id,
|
||||
a.color AS color,
|
||||
1 AS isBodyPart,
|
||||
b.id AS bodyPartId,
|
||||
0 AS goodId,
|
||||
b.media_resource_id AS mediaResourceId,
|
||||
b.`type` AS layerId,
|
||||
0 AS goodTypeId
|
||||
FROM bodyparts b
|
||||
JOIN (SELECT a.color, a.good_id FROM avatar_inventory a WHERE a.user_id = :uid AND a.`type` = 'BodyParts' AND a.is_used = true) AS a
|
||||
ON a.good_id = b.id""", nativeQuery = true)
|
||||
List<IBodyAvatarItem> findUsedBodyPartsByUserId(@Param("uid") Long userId);
|
||||
|
||||
@Query(value = "SELECT 0 AS bodyPartTypeId, g.id AS id, 0 AS color, 0 AS isBodyPart, 0 AS bodyPartId, g.id AS goodId, g.mrid AS mediaResourceId, g.layer_id AS layerId, g.good_type_id AS goodTypeId FROM goods g JOIN (SELECT a.good_id FROM avatar_inventory a WHERE a.user_id = :uid AND a.`type` = 'Clothes' AND a.is_used = true) AS a ON a.good_id = g.id", nativeQuery = true)
|
||||
@Query(value = """
|
||||
SELECT
|
||||
0 AS bodyPartTypeId,
|
||||
g.id AS id,
|
||||
0 AS color,
|
||||
0 AS isBodyPart,
|
||||
0 AS bodyPartId,
|
||||
g.id AS goodId,
|
||||
g.mrid AS mediaResourceId,
|
||||
g.layer_id AS layerId,
|
||||
g.good_type_id AS goodTypeId
|
||||
FROM goods g
|
||||
JOIN (SELECT a.good_id FROM avatar_inventory a WHERE a.user_id = :uid AND a.`type` = 'Clothes' AND a.is_used = true) AS a
|
||||
ON a.good_id = g.id""", nativeQuery = true)
|
||||
List<IBodyAvatarItem> findUsedClothesByUserId(@Param("uid") Long userId);
|
||||
|
||||
|
||||
@Query(value = """
|
||||
SELECT
|
||||
g.magic_ability_id AS id,
|
||||
'' AS expirationDate,
|
||||
0 AS isLimited
|
||||
FROM gms g
|
||||
JOIN (SELECT a.good_id FROM avatar_inventory a WHERE a.`type` = 'Magic' AND a.user_id = :uid) a
|
||||
ON g.id = a.good_id""", nativeQuery = true)
|
||||
List<InitMagicAbility> findMagicAbilitiesByUserId(@Param("uid") Long userId);
|
||||
|
||||
@Query(value = "SELECT s FROM Smile s WHERE s.id IN (SELECT a.goodId FROM AvatarInventory a WHERE a.user.id = :uid AND a.type = 'Smile')")
|
||||
List<Smile> findSmilesByUserId(@Param("uid") Long userId);
|
||||
}
|
||||
|
@ -18,6 +18,44 @@ public interface BodyPartRepository extends JpaRepository<BodyPart, Long> {
|
||||
@Query(value = "SELECT b FROM BodyPart b WHERE b.type = :type")
|
||||
List<BodyPart> findByBodyPartType(@Param("type") BodyPartType type);
|
||||
|
||||
@Query(value = "SELECT a.id AS id, 0 AS textResourceId, a.id AS bodyPartId, a.media_resource_id AS mediaResourceId, (case when (MAX(a.is_used) > 0) then 1 else 0 end) AS isUsed, (case when (a.is_colorable > 0) then 1 else 0 end) AS isColorable, MAX(a.color) AS color, 0 AS isLimited, '' AS date, 0 AS pollution, 1 AS isBodyPart, 0 AS phoneId FROM (SELECT b.id, b.is_colorable, b.media_resource_id, b.`type`, 0 AS is_used, 0 AS color FROM bodyparts AS b UNION (SELECT b.id, b.is_colorable, b.media_resource_id, b.`type`, a.is_used, a.color FROM bodyparts AS b JOIN avatar_inventory AS a ON b.id = a.good_id WHERE a.`type` = 'BodyParts' AND a.user_id = :uid)) AS a WHERE a.`type` = :#{#type.name()} GROUP BY a.id, a.`type`, a.media_resource_id, a.is_colorable", nativeQuery = true)
|
||||
@Query(value = """
|
||||
SELECT
|
||||
a.id AS id,
|
||||
0 AS textResourceId,
|
||||
a.id AS bodyPartId,
|
||||
a.media_resource_id AS mediaResourceId,
|
||||
(case when (MAX(a.is_used) > 0) then 1 else 0 end) AS isUsed,
|
||||
(case when (a.is_colorable > 0) then 1 else 0 end) AS isColorable,
|
||||
MAX(a.color) AS color,
|
||||
0 AS isLimited,
|
||||
'' AS date,
|
||||
0 AS pollution,
|
||||
1 AS isBodyPart,
|
||||
0 AS phoneId
|
||||
FROM (
|
||||
SELECT
|
||||
b.id,
|
||||
b.is_colorable,
|
||||
b.media_resource_id,
|
||||
b.`type`,
|
||||
0 AS is_used,
|
||||
0 AS color
|
||||
FROM bodyparts AS b
|
||||
UNION (
|
||||
SELECT
|
||||
b.id,
|
||||
b.is_colorable,
|
||||
b.media_resource_id,
|
||||
b.`type`,
|
||||
a.is_used,
|
||||
a.color
|
||||
FROM bodyparts AS b
|
||||
JOIN avatar_inventory AS a
|
||||
ON b.id = a.good_id
|
||||
WHERE a.`type` = 'BodyParts' AND a.user_id = :uid
|
||||
)
|
||||
) AS a
|
||||
WHERE a.`type` = :#{#type.name()}
|
||||
GROUP BY a.id, a.`type`, a.media_resource_id, a.is_colorable""", nativeQuery = true)
|
||||
List<InventoryItem> findInventoryItems(@Param("uid") Long userId, @Param("type") BodyPartType type);
|
||||
}
|
@ -87,24 +87,11 @@ public class AvatarInventoryService {
|
||||
}
|
||||
|
||||
public List<InitMagicAbility> getMagicAbilitiesItemsByUserId(Long userId) {
|
||||
return this.inventoryRepository.findItemsByUserIdAndType(userId, AvatarInventoryType.Magic)
|
||||
.stream()
|
||||
.map(AvatarInventory::getGoodId)
|
||||
.map(id -> goodMagicRepository.findById(id))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(g -> new InitMagicAbility(g.getMagicAbilityId(), "", false)) // todo: implement expiration ability
|
||||
.collect(Collectors.toList());
|
||||
return this.inventoryRepository.findMagicAbilitiesByUserId(userId); // todo: implement expiration ability
|
||||
}
|
||||
|
||||
public List<Smile> getSmilesByUserId(Long userId) {
|
||||
return this.inventoryRepository.findItemsByUserIdAndType(userId, AvatarInventoryType.Smile)
|
||||
.stream()
|
||||
.map(AvatarInventory::getGoodId)
|
||||
.map(id -> smileService.findById(id))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
return this.inventoryRepository.findSmilesByUserId(userId);
|
||||
}
|
||||
|
||||
public List<InventoryItem> getBackgroundsByUserId(Long userId) {
|
||||
@ -158,10 +145,7 @@ public class AvatarInventoryService {
|
||||
public String getAchievementsByUserId(Long userId) {
|
||||
return this.inventoryRepository.findItemsByUserIdAndType(userId, AvatarInventoryType.Achievments)
|
||||
.stream()
|
||||
.map(a -> achievementService.findById(a.getGoodId()))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.map(a -> a.getId().toString())
|
||||
.map(a -> a.getGoodId().toString())
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user