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

Develop #291

Merged
merged 12 commits into from
Jun 20, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.postgraduate.admin.application.usecase;

import com.postgraduate.batch.scheduler.JobSchedulerConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class AdminBatchUseCase {
private final JobSchedulerConfig jobSchedulerConfig;

public void startSalaryBatch() {
try {
jobSchedulerConfig.launchSalaryJob();
} catch (Exception e) {
log.error("Create Salary Batch Exception : {}", e.getStackTrace());
}
}

public void startMentoringDoneBatch() {
try {
jobSchedulerConfig.launchDoneJob();
} catch (Exception e) {
log.error("Create Salary Batch Exception : {}", e.getStackTrace());
}
}

public void startMentoringCancelBatch() {
try {
jobSchedulerConfig.launchCancelJob();
} catch (Exception e) {
log.error("Create Salary Batch Exception : {}", e.getStackTrace());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AdminWithThymeLeafController {
private final AdminMentoringUseCase adminMentoringUseCase;
private final AdminSalaryUseCase adminSalaryUseCase;
private final AdminPaymentUseCase adminPaymentUseCase;
private final AdminBatchUseCase adminBatchUseCase;
private final JwtUseCase jwtUseCase;

@GetMapping("/loginForm")
Expand Down Expand Up @@ -166,4 +167,27 @@ public String sendMessage(@RequestBody SendMessageRequest messageRequest) {
adminUserUseCase.sendMatchingMessage(messageRequest);
return "adminEmpty";
}

@GetMapping("/batch")
public String batchManage() {
return "adminBatch";
}

@PostMapping("/batch/salary")
public String startSalaryBatch() {
adminBatchUseCase.startSalaryBatch();
return "adminEmpty";
}

@PostMapping("/batch/mentoring/done")
public String startMentoringDone() {
adminBatchUseCase.startMentoringDoneBatch();
return "adminEmpty";
}

@PostMapping("/batch/mentoring/cancel")
public String startMentoringCancel() {
adminBatchUseCase.startMentoringCancelBatch();
return "adminEmpty";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CancelJobConfig {
private final CancelMentoringProcessor cancelMentoringProcessor;
private final CancelMentoringWriter cancelMentoringWriter;
private final EntityManagerFactory entityManagerFactory;
private final CancelMentoringSkipListener cancelMentoringSkipListener;

private static final int CHUNK_SIZE = 50;

Expand All @@ -54,6 +55,7 @@ public Step cancelStep() {
.faultTolerant()
.skip(Exception.class)
.skipLimit(Integer.MAX_VALUE)
.listener(cancelMentoringSkipListener)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.postgraduate.batch.cancel;

import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.global.slack.SlackErrorMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.SkipListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class CancelMentoringSkipListener implements SkipListener<Mentoring, CancelMentoring> {
private final SlackErrorMessage slackErrorMessage;

@Override
public void onSkipInRead(Throwable t) {
log.error("λ©˜ν† λ§ μžλ™ μ™„λ£Œ ItemReader Skip message : {}", t.getMessage());
}

@Override
public void onSkipInProcess(Mentoring mentoring, Throwable t) {
log.error("mentoringId : {} μžλ™ μ·¨μ†Œ μ‹€νŒ¨, message : {}", mentoring.getMentoringId(), t.getMessage());
slackErrorMessage.sendSlackMentoringError(mentoring.getMentoringId(), t);
}

@Override
public void onSkipInWrite(CancelMentoring cancelMentoring, Throwable t) {
log.error("mentoringId : {} μžλ™ μ·¨μ†Œ μ‹€νŒ¨, message : {}", cancelMentoring.mentoringId(), t.getMessage());
slackErrorMessage.sendSlackMentoringError(cancelMentoring.mentoringId(), t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ public Step createSalaryStep() {
.skip(Exception.class)
.skipLimit(Integer.MAX_VALUE)
.listener(createSalarySkipListener)
.listener(new CreateSalaryStepListener())
.build();
}

@Bean
public QueryDslZeroPagingItemReader<CreateSalary> salaryReader() {
LocalDate date = getSalaryDate().plusDays(7);
log.info("not in date : {}", date);
return new QueryDslZeroPagingItemReader<>(entityManagerFactory, CHUNK_SIZE, queryFactory ->
queryFactory.select(Projections.constructor(CreateSalary.class,
senior.seniorId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.postgraduate.batch.salary;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.*;

@Slf4j
public class CreateSalaryStepListener implements StepExecutionListener {
@Override
public void beforeStep(StepExecution stepExecution) {
log.info("createSalaryStep Start");
}

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
log.info("salary total read : {} and total write : {}", stepExecution.getReadCount(), stepExecution.getWriteCount());
return stepExecution.getExitStatus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING;

@Entity
@Table(indexes = {
@Index(name = "senior_total_info_index", columnList = "totalInfo"),
@Index(name = "senior_hit_index", columnList = "hit"),
@Index(name = "senior_field_index", columnList = "field"),
@Index(name = "senior_etc_field_index", columnList = "etcField"),
@Index(name = "senior_postgradu_index", columnList = "postgradu"),
@Index(name = "senior_etc_postgradu_index", columnList = "etcPostgradu")
})
@Builder
@AllArgsConstructor
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.postgraduate.domain.senior.domain.repository;

import com.postgraduate.domain.salary.application.dto.SeniorAndAccount;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import org.springframework.data.domain.Page;
Expand All @@ -10,10 +9,8 @@
import java.util.Optional;

public interface SeniorDslRepository {
Page<Senior> findAllBySearchSeniorWithAdmin(String search, Pageable pageable);
Optional<Senior> findBySeniorId(Long seniorId);
Optional<Senior> findByUserWithAll(User user);
List<SeniorAndAccount> findAllSeniorAndAccount();
List<Senior> findAllSenior();
Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageable pageable);
Page<Senior> findAllBySearchSenior(String search, String sort, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.postgraduate.domain.senior.domain.repository;

import com.postgraduate.domain.account.domain.entity.Account;
import com.postgraduate.domain.salary.application.dto.SeniorAndAccount;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -13,13 +12,13 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static com.postgraduate.domain.account.domain.entity.QAccount.account;
import static com.postgraduate.domain.senior.domain.entity.QSenior.senior;
import static com.postgraduate.domain.user.domain.entity.QUser.user;
import static com.querydsl.core.types.Order.ASC;
Expand All @@ -38,21 +37,36 @@ public class SeniorDslRepositoryImpl implements SeniorDslRepository{

@Override
public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable pageable) {
List<Senior> seniors = queryFactory.selectFrom(senior)
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit)
.from(senior)
.distinct()
.leftJoin(senior.user, user)
.fetchJoin()
.where(
senior.info.totalInfo.like("%" + search + "%")
.or(senior.user.nickName.like("%" + search + "%")),
senior.user.isDelete.eq(FALSE)
)
.orderBy(orderSpecifier(sort))
.orderBy(senior.user.nickName.asc()).
offset(pageable.getOffset())
.orderBy(senior.user.nickName.asc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

if (CollectionUtils.isEmpty(results)) {
return new PageImpl<>(new ArrayList<>(), pageable, 0);
}

List<Senior> seniors = queryFactory.selectFrom(senior)
.where(senior.seniorId.in(results.stream()
.map(tuple -> tuple.get(senior.seniorId))
.toList()))
.leftJoin(senior.user, user)
.fetchJoin()
.orderBy(orderSpecifier(sort))
.orderBy(senior.user.nickName.asc())
.fetch();


Long total = queryFactory.select(senior.count())
.from(senior)
.distinct()
Expand All @@ -64,7 +78,6 @@ public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable p
)
.fetchOne();


return new PageImpl<>(seniors, pageable, total);
}

Expand All @@ -78,10 +91,10 @@ private OrderSpecifier<?> orderSpecifier(String sort) {

@Override
public Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageable pageable) {
List<Senior> seniors = queryFactory.selectFrom(senior)
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit)
.from(senior)
.distinct()
.leftJoin(senior.user, user)
.fetchJoin()
.where(
fieldSpecifier(field),
postgraduSpecifier(postgradu),
Expand All @@ -93,6 +106,20 @@ public Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageabl
.limit(pageable.getPageSize())
.fetch();

if (CollectionUtils.isEmpty(results)) {
return new PageImpl<>(new ArrayList<>(), pageable, 0);
}

List<Senior> seniors = queryFactory.selectFrom(senior)
.where(senior.seniorId.in(results.stream()
.map(tuple -> tuple.get(senior.seniorId))
.toList()))
.leftJoin(senior.user, user)
.fetchJoin()
.orderBy(senior.hit.desc())
.orderBy(senior.user.nickName.asc())
.fetch();

Long total = queryFactory.select(senior.count())
.from(senior)
.distinct()
Expand Down Expand Up @@ -142,43 +169,6 @@ private BooleanExpression postgraduSpecifier(String postgradu) {
.orElse(FALSE);
}

@Override
public Page<Senior> findAllBySearchSeniorWithAdmin(String search, Pageable pageable) {
List<Senior> seniors = queryFactory.selectFrom(senior)
.where(
searchLike(search),
senior.user.isDelete.eq(FALSE)
)
.distinct()
.innerJoin(senior.user, user)
.fetchJoin()
.orderBy(senior.createdAt.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

Long total = queryFactory.select(senior.count())
.from(senior)
.where(
searchLike(search),
senior.user.isDelete.eq(FALSE)
)
.distinct()
.innerJoin(senior.user, user)
.fetchOne();

return new PageImpl<>(seniors, pageable, total);
}

private BooleanExpression searchLike(String search) {
if (StringUtils.hasText(search)) {
return senior.user.phoneNumber.contains(search)
.or(senior.user.nickName.contains(search))
.and(senior.profile.isNotNull());
}
return null;
}

@Override
public Optional<Senior> findByUserWithAll(User seniorUser) {
return ofNullable(queryFactory.selectFrom(senior)
Expand All @@ -190,31 +180,6 @@ public Optional<Senior> findByUserWithAll(User seniorUser) {
);
}

@Override
public List<SeniorAndAccount> findAllSeniorAndAccount() {
List<Senior> seniors = queryFactory.selectFrom(senior)
.where(senior.user.isDelete.isFalse())
.fetch();
List<Account> accounts = queryFactory.selectFrom(account)
.distinct()
.where(account.senior.in(seniors))
.leftJoin(account.senior, senior)
.fetchJoin()
.fetch();

return seniors.stream()
.map(senior -> {
Account account = accounts.stream()
.filter(a -> a.getSenior().getSeniorId()
.equals(senior.getSeniorId())
)
.findFirst()
.orElse(null);
return new SeniorAndAccount(senior, account);
})
.toList();
}

@Override
public List<Senior> findAllSenior() {
return queryFactory.selectFrom(senior)
Expand Down
Loading
Loading