package com.caliverse.admin.dynamodb.service; import com.caliverse.admin.domain.datacomponent.MetaDataHandler; import com.caliverse.admin.domain.entity.EFilterOperator; import com.caliverse.admin.domain.entity.ITEMLARGETYPE; import com.caliverse.admin.domain.response.UsersResponse; import com.caliverse.admin.dynamodb.domain.atrrib.ItemAttrib; import com.caliverse.admin.dynamodb.domain.doc.ItemDoc; import com.caliverse.admin.dynamodb.dto.PageResult; import com.caliverse.admin.dynamodb.entity.KeyParam; import com.caliverse.admin.dynamodb.repository.*; import com.caliverse.admin.global.common.annotation.DynamoDBTransaction; import com.caliverse.admin.global.common.constants.DynamoDBConstants; import com.caliverse.admin.global.common.utils.CommonUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Slf4j @Service @RequiredArgsConstructor public class DynamodbItemService { private final ItemRepository itemRepository; private final MetaDataHandler metaDataHandler; public PageResult getItems(String guid, KeyParam pageKey){ Map pagingKey = null; if(pageKey != null){ pagingKey = new HashMap<>(); pagingKey.put(DynamoDBConstants.PK_KEY_NAME, AttributeValue.builder().s(pageKey.getPk()).build()); pagingKey.put(DynamoDBConstants.SK_KEY_NAME, AttributeValue.builder().s(pageKey.getSk()).build()); } PageResult itemList = itemRepository.getItemListWithPaging(guid, "","",null, "", pagingKey, false); return itemList; } public UsersResponse.InventoryInfo getInvenItems(String guid){ List clothList = new ArrayList<>(); List propList = new ArrayList<>(); List beautyList = new ArrayList<>(); List tattooList = new ArrayList<>(); List currencyList = new ArrayList<>(); List etcList = new ArrayList<>(); Map pageKey = null; do { PageResult itemList = itemRepository.getItemListWithPaging(guid, "", DynamoDBConstants.ATTRIB_ITEM, EFilterOperator.CONTAINS,"\"equiped_inven_type\":0", pageKey, false); itemList.getItems().forEach(item -> { ItemAttrib attrib = CommonUtils.stringByObject(item.getAttribValue(), ItemAttrib.class); int item_id = attrib.getItemMetaId(); String item_name = metaDataHandler.getTextStringData(metaDataHandler.getMetaItemNameData(item_id)); String item_type = metaDataHandler.getMetaItemLargeTypeData(item_id); UsersResponse.Item inventory = UsersResponse.Item.builder() .itemId(item_id) .itemName(item_name) .count(attrib.getItemStackCount()) .itemGuid(attrib.getItemGuid()) .build(); if(item_type.isEmpty()) { etcList.add(inventory); }else{ switch (ITEMLARGETYPE.valueOf(item_type)){ case CLOTH -> clothList.add(inventory); case PROP -> propList.add(inventory); case BEAUTY -> beautyList.add(inventory); case TATTOO -> tattooList.add(inventory); case CURRENCY -> currencyList.add(inventory); default -> etcList.add(inventory); }} }); pageKey = itemList.getLastEvaluatedKey(); } while (pageKey != null); return UsersResponse.InventoryInfo.builder() .cloth(clothList) .prop(propList) .beauty(beautyList) .tattoo(tattooList) .currency(currencyList) .etc(etcList) .build(); } @DynamoDBTransaction public void updateItemStack(String guid, String itemGuid, int stackCount){ itemRepository.updateItemStack(guid, itemGuid, stackCount); } @DynamoDBTransaction public void deleteItem(String guid, String itemGuid){ itemRepository.deleteItem(guid, itemGuid); } }