Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week3 #6

Open
wants to merge 4 commits into
base: week2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
readme.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies {
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}"

testImplementation 'org.springframework.batch:spring-batch-test'
implementation 'org.springframework.batch:spring-batch-test'
}

tasks.named('test') {
Expand Down
32 changes: 32 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 할일리스트

- [x] 관리자 회원
- [x] 관리자페이지
- [x] 정산데이터 생성
- [x] 건별정산처리
- [x] 전체정산처리
- [x] 정산데이터를 배치로 생성
- [x] 스프링 내장 스케쥴러를 이용해서 배치가 매달 15일 새벽 4시에 실행되도록
- [x] `@EnableScheduling` 사용
- [x] 출금신청기능(사용자기능)
- [x] 출금처리기능(관리자기능)
- [x] 결제가 된 주문품목은 정산품목으로 생성될 수 있다.
- [x] 관리자만 관리자 페이지에 접속할 수 있다.
- [x] 개발자가 회원중 임의로 1명을 골라서 관리자로 지정
- [x] authLevel을 7로 지정
- [x] 정산비율은 판매자와 멋북스가 5:5로 나눈다.
- [x] 편의상 PG 수수료는 0원으로 가정하고 진행한다.
- [x] 사용자는 본인이 보유한 예치금에 대해서 출금신청을 할 수 있다.
- [x] 신청시에는 금액과 통장, 계좌번호를 입력한다.
- [x] 관리자만 관리자페이지에서 출금신청목록을 볼 수 있다.
- [x] 출금 수수료도 없다고 가정한다.
- [x] GET /adm/home/main
- [x] GET /adm/rebate/makeData
- [x] POST /adm/rebate/makeData
- [x] GET /adm/rebate/rebateOrderItemList
- [x] POST /adm/rebate/rebate
- [x] POST /adm/rebate/rebateOne/{id}
- [x] GET /withdraw/apply
- [x] POST /withdraw/apply
- [x] GET /adm/withdraw/applyList
- [x] POST /adm/withdraw/{withdrawApplyId}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.ll.exam.final__2022_10_08;

import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootApplication
@EnableJpaAuditing
@EnableAsync
@EnableScheduling
@EnableBatchProcessing
public class Final20221008Application {

public static void main(String[] args) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/ll/exam/final__2022_10_08/app/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,27 @@ public class AppConfig {
@Getter
private static String siteBaseUrl;

@Getter
public static double wholesalePriceRate;

@Getter
public static int cancelAvailableSeconds;

@Autowired
public void setContext(ApplicationContext context) {
AppConfig.context = context;
}

@Value("${custom.rebate.wholesalePriceRate}")
public void setWholesalePriceRate(double value) {
wholesalePriceRate = value;
}

@Value("${custom.order.cancelAvailableSeconds}")
public void setCancelAvailableSeconds(String value) {
cancelAvailableSeconds = Integer.valueOf(value);
}

@Value("${spring.profiles.active:}")
public void setActiveProfile(String value) {
activeProfile = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import com.ll.exam.final__2022_10_08.app.cart.service.CartService;
import com.ll.exam.final__2022_10_08.app.member.entity.Member;
import com.ll.exam.final__2022_10_08.app.member.entity.emum.AuthLevel;
import com.ll.exam.final__2022_10_08.app.member.repository.MemberRepository;
import com.ll.exam.final__2022_10_08.app.member.service.MemberService;
import com.ll.exam.final__2022_10_08.app.order.entity.Order;
import com.ll.exam.final__2022_10_08.app.order.repository.OrderRepository;
import com.ll.exam.final__2022_10_08.app.order.service.OrderService;
import com.ll.exam.final__2022_10_08.app.post.service.PostService;
import com.ll.exam.final__2022_10_08.app.product.entity.Product;
import com.ll.exam.final__2022_10_08.app.product.service.ProductService;
import com.ll.exam.final__2022_10_08.app.withdraw.service.WithdrawService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -25,12 +28,14 @@ public class NotProdInitData {

@Bean
CommandLineRunner initData(
MemberRepository memberRepository,
MemberService memberService,
PostService postService,
ProductService productService,
CartService cartService,
OrderService orderService,
OrderRepository orderRepository
OrderRepository orderRepository,
WithdrawService withdrawService
) {
return args -> {
if (initDataDone) {
Expand All @@ -40,6 +45,10 @@ CommandLineRunner initData(
initDataDone = true;

Member member1 = memberService.join("user1", "1234", "[email protected]", null);

member1.setAuthLevel(AuthLevel.ADMIN);
memberRepository.save(member1);

Member member2 = memberService.join("user2", "1234", "[email protected]", "홍길순");

postService.write(
Expand Down Expand Up @@ -89,11 +98,11 @@ CommandLineRunner initData(

class Helper {
public Order order(Member member, List<Product> products) {
for (int i = 0; i < products.size(); i++) {
Product product = products.get(i);

cartService.addItem(member, product);
}
products
.stream()
.forEach(product -> {
cartService.addItem(member, product);
});

return orderService.createFromCart(member);
}
Expand Down Expand Up @@ -129,22 +138,27 @@ public Order order(Member member, List<Product> products) {
)
);

cartService.addItem(member1, product3);
cartService.addItem(member1, product4);

Order order4 = helper.order(member2, Arrays.asList(
Order order4 = helper.order(member1, Arrays.asList(
product3,
product4
)
);

orderService.payByRestCashOnly(order4);

orderService.refund(order4, member1);

Order order5 = helper.order(member2, Arrays.asList(
product3,
product4
product3
)
);

cartService.addItem(member1, product4);

withdrawService.apply("우리은행", "1002333203948", 50000, member1);
withdrawService.apply("수협은행", "1002333203947", 40000, member1);
withdrawService.apply("국민은행", "1002333203946", 30000, member2);
withdrawService.apply("카카오은행", "1002333203945", 20000, member2);
};
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/ll/exam/final__2022_10_08/app/base/rq/Rq.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ public static String urlWithErrorMsg(String url, String errorMsg) {
return Ut.url.modifyQueryParam(url, "errorMsg", msgWithTtl(errorMsg));
}

public String modifyQueryParam(String paramName, String paramValue) {
return Ut.url.modifyQueryParam(getCurrentUrl(), paramName, paramValue);
}

private String getCurrentUrl() {
String url = req.getRequestURI();
String queryStr = req.getQueryString();

if ( StringUtils.hasText(queryStr) ) {
url += "?" + queryStr;
}

return url;
}

public static String redirectWithMsg(String url, RsData rsData) {
return "redirect:" + urlWithMsg(url, rsData);
}
Expand Down Expand Up @@ -115,4 +130,24 @@ public boolean isLogout() {
public boolean isLogined() {
return isLogout() == false;
}

public boolean isAdmin() {
if ( isLogout() ) return false;

return memberContext.hasAuthority("ADMIN");
}

public boolean isAuthor() {
if ( isLogout() ) return false;

return memberContext.hasAuthority("AUTHOR");
}

public boolean isUsrPage() {
return isAdmPage() == false;
}

public boolean isAdmPage() {
return req.getRequestURI().startsWith("/adm");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public List<GrantedAuthority> genAuthorities() {
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("MEMBER"));

if (getAuthLevel() == AuthLevel.ADMIN) {
authorities.add(new SimpleGrantedAuthority("ADMIN"));
}

// 닉네임을 가지고 있다면 작가의 권한을 가진다.
if (StringUtils.hasText(nickname)) {
authorities.add(new SimpleGrantedAuthority("AUTHOR"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void forceAuthentication(Member member) {
public RsData<AddCashRsDataBody> addCash(Member member, long price, String eventType) {
CashLog cashLog = cashService.addCash(member, price, eventType);

long newRestCash = member.getRestCash() + cashLog.getPrice();
long newRestCash = getRestCash(member) + cashLog.getPrice();
member.setRestCash(newRestCash);
memberRepository.save(member);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@ToString(callSuper = true)
public class MyBook extends BaseEntity {
@ManyToOne(fetch = LAZY)
@ToString.Exclude
private Member owner;

@ManyToOne(fetch = LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import com.ll.exam.final__2022_10_08.app.myBook.entity.MyBook;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface MyBookRepository extends JpaRepository<MyBook, Long> {
void deleteByProductIdAndOwnerId(long productId, long ownerId);

List<MyBook> findAllByOwnerId(long ownerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ public void addOrderItem(OrderItem orderItem) {
}

public int calculatePayPrice() {
int payPrice = 0;

for (OrderItem orderItem : orderItems) {
payPrice += orderItem.getSalePrice();
}

return payPrice;
return orderItems
.stream()
.mapToInt(orderItem -> orderItem.getSalePrice())
.sum();
}

public void setCancelDone() {
Expand Down Expand Up @@ -85,19 +82,17 @@ public void setRefundDone() {
}

public int getPayPrice() {
int payPrice = 0;
for (OrderItem orderItem : orderItems) {
payPrice += orderItem.getPayPrice();
}

return payPrice;
return orderItems
.stream()
.mapToInt(orderItem -> orderItem.getPayPrice())
.sum();
}

public void makeName() {
String name = orderItems.get(0).getProduct().getSubject();

if (orderItems.size() > 1) {
name += " 외 %d곡".formatted(orderItems.size() - 1);
name += " 외 %d권".formatted(orderItems.size() - 1);
}

this.name = name;
Expand Down
Loading