-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Central-MakeUs/dev
fix: 지그재그 분류 체계에 맞춰 수정
- Loading branch information
Showing
6 changed files
with
121 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 47 additions & 45 deletions
92
.../core-infra-feign/src/main/java/com/mm/coreinfrafeign/crawler/service/CrawlerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,62 @@ | ||
package com.mm.coreinfrafeign.crawler.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.mm.coredomain.domain.Item; | ||
import com.mm.coredomain.domain.ItemCategoryType; | ||
import com.mm.coredomain.domain.ItemImage; | ||
import com.mm.coreinfrafeign.crawler.client.ZigZagCrawlerClient; | ||
import com.mm.coreinfrafeign.crawler.dto.requset.ZigZagCrawlerRequest; | ||
import com.mm.coreinfrafeign.crawler.dto.response.ZigZagCrawlerResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class CrawlerService { | ||
private final ZigZagCrawlerClient zigZagCrawlerClient; | ||
|
||
public Item getZigZagItemByCrawler(String redirectUrl) { | ||
ZigZagCrawlerResponse response = zigZagCrawlerClient.call(new ZigZagCrawlerRequest(redirectUrl)); | ||
|
||
ItemCategoryType categoryType = getCategoryType(response); | ||
|
||
Item item = Item.builder() | ||
.price(response.finalPrice()) | ||
.title(response.name()) | ||
.redirectUrl(response.pageUrl()) | ||
.categoryType(categoryType) | ||
.refund(getRefundPrice(response.finalPrice(), categoryType.getRefundPercent())) | ||
.thumbnailUrl(response.thumbnailUrl()) | ||
.build(); | ||
|
||
List<ItemImage> itemImages = response.productImageList() | ||
.stream() | ||
.map(image -> ItemImage.builder() | ||
.item(item) | ||
.url(image.url()) | ||
.build()) | ||
.toList(); | ||
|
||
item.setItemImages(itemImages); | ||
return item; | ||
} | ||
|
||
private static ItemCategoryType getCategoryType(ZigZagCrawlerResponse response) { | ||
String itemCategory = response.managedCategoryList().get(0).value(); | ||
if (itemCategory.equals("패션의류")) { | ||
itemCategory = response.managedCategoryList().get(1).value(); | ||
return ItemCategoryType.fromValueForClothes(itemCategory); | ||
} | ||
|
||
return ItemCategoryType.fromValue(itemCategory); | ||
} | ||
|
||
private Integer getRefundPrice(Integer price, Integer percent) { | ||
return price * percent / 100; | ||
} | ||
private final ZigZagCrawlerClient zigZagCrawlerClient; | ||
|
||
public Item getZigZagItemByCrawler(String redirectUrl) { | ||
ZigZagCrawlerResponse response = zigZagCrawlerClient.call(new ZigZagCrawlerRequest(redirectUrl)); | ||
|
||
ItemCategoryType categoryType = getCategoryType(response); | ||
|
||
Item item = Item.builder() | ||
.price(response.finalPrice()) | ||
.title(response.name()) | ||
.redirectUrl(response.pageUrl()) | ||
.categoryType(categoryType) | ||
.refund(getRefundPrice(response.finalPrice(), categoryType.getRefundPercent())) | ||
.thumbnailUrl(response.thumbnailUrl()) | ||
.build(); | ||
|
||
List<ItemImage> itemImages = response.productImageList() | ||
.stream() | ||
.map(image -> ItemImage.builder() | ||
.item(item) | ||
.url(image.url()) | ||
.build()) | ||
.toList(); | ||
|
||
item.setItemImages(itemImages); | ||
return item; | ||
} | ||
|
||
private static ItemCategoryType getCategoryType(ZigZagCrawlerResponse response) { | ||
String itemCategory = response.managedCategoryList().get(0).value(); | ||
if (itemCategory.equals("패션의류")) { | ||
itemCategory = response.managedCategoryList().get(2).value(); | ||
return ItemCategoryType.fromValueForClothes(itemCategory); | ||
} | ||
|
||
return ItemCategoryType.fromValue(itemCategory); | ||
} | ||
|
||
private Integer getRefundPrice(Integer price, Integer percent) { | ||
return price * percent / 100; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
insert into permission(id, name) values(1, 'ROLE_ADMIN'); | ||
insert into permission(id, name) values(2, 'ROLE_USER'); | ||
|
||
insert into member_groups(id, name) values(1, 'ADMIN_GROUP'); | ||
insert into member_groups(id, name) values(2, 'USER_GROUP'); | ||
|
||
insert into group_permission(id, member_groups_id, permission_id) values(1, 1, 1); | ||
insert into group_permission(id, member_groups_id, permission_id) values(2, 1, 2); | ||
insert into group_permission(id, member_groups_id, permission_id) values(3, 2, 2); | ||
|
||
insert into member(id, name, email, point, member_groups_id) | ||
values(1, 'test', 'test@test', 10000000, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ spring: | |
spring: | ||
config: | ||
activate: | ||
on-profile: prod | ||
on-profile: prod, stage | ||
data: | ||
redis: | ||
port: 6379 | ||
|