From 35a3abd032f4eb15c6e0fbc2bf638e0721f75aff Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Tue, 14 Nov 2023 23:30:40 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20=EC=9D=BC=EC=9A=94=EC=9D=BC=20?= =?UTF-8?q?=EB=B0=A4=20=EB=B0=98=EB=B3=B5=EB=AF=B8=EC=85=98=20=EB=A7=88?= =?UTF-8?q?=EA=B0=90=20=EB=A3=A8=ED=8B=B4=20=EB=B0=B0=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/RepeatMissionEnd.java | 94 +++++++++++++++++++ .../domain/mission/domain/entity/Mission.java | 4 + .../service/MissionArchiveDeleteUseCase.java | 5 +- .../service/MissionStateUseCase.java | 17 ++++ .../MissionStateCustomRepository.java | 1 + .../MissionStateCustomRepositoryImpl.java | 11 +++ .../service/MissionStateDeleteService.java | 6 ++ 7 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java b/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java new file mode 100644 index 00000000..811b051f --- /dev/null +++ b/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java @@ -0,0 +1,94 @@ +package com.moing.backend.domain.mission.application.service; + +import com.moing.backend.domain.mission.domain.entity.Mission; +import com.moing.backend.domain.missionState.application.service.MissionStateUseCase; +import com.moing.backend.domain.teamScore.application.service.TeamScoreLogicUseCase; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +import org.springframework.batch.core.configuration.annotation.JobScope; +import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.configuration.annotation.StepScope; +import org.springframework.batch.item.ItemProcessor; +import org.springframework.batch.item.database.JpaItemWriter; +import org.springframework.batch.item.database.JpaPagingItemReader; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.persistence.EntityManagerFactory; + +@Slf4j +@RequiredArgsConstructor +@Configuration +public class RepeatMissionEnd { + + public static final String JOB_NAME = "makeMissionEnd"; + + private final EntityManagerFactory entityManagerFactory; + private final StepBuilderFactory stepBuilderFactory; + private final JobBuilderFactory jobBuilderFactory; + + private final MissionStateUseCase missionStateUseCase; + private final TeamScoreLogicUseCase teamScoreLogicUseCase; + + private final int chunkSize = 10; + + @Bean + public Job payPagingJob() { + return jobBuilderFactory.get(JOB_NAME) + .start(payPagingStep()) + .build(); + } + + @Bean + @JobScope + public Step payPagingStep() { + return stepBuilderFactory.get("makeMissionEndStep") + .chunk(chunkSize) + .reader(payPagingReader()) + .processor(payPagingProcessor()) + .writer(writer()) + .build(); + } + + @Bean + @StepScope + public JpaPagingItemReader payPagingReader() { + + JpaPagingItemReader reader = new JpaPagingItemReader() { + @Override + public int getPage() { + return 0; + } + }; + + reader.setQueryString("SELECT m FROM Mission m WHERE m.status = 'ONGOING' AND m.type = 'REPEAT'"); + reader.setPageSize(chunkSize); + reader.setEntityManagerFactory(entityManagerFactory); + reader.setName("payPagingReader"); + + return reader; + } + + // sundayRepeatMissionRoutine() + @Bean + @StepScope + public ItemProcessor payPagingProcessor() { + return mission -> { + teamScoreLogicUseCase.updateTeamScore(mission.getId()); + missionStateUseCase.deleteAllMissionState(mission.getId()); + mission.makeEnd(); + return mission; + }; + } + + @Bean + @StepScope + public JpaItemWriter writer() { + JpaItemWriter writer = new JpaItemWriter<>(); + writer.setEntityManagerFactory(entityManagerFactory); + return writer; + } +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/mission/domain/entity/Mission.java b/src/main/java/com/moing/backend/domain/mission/domain/entity/Mission.java index 66177310..df199e4a 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/entity/Mission.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/entity/Mission.java @@ -84,4 +84,8 @@ public void setTeam(Team team) { public void updateStatus(MissionStatus missionStatus) { this.status = missionStatus; } + + public void makeEnd() { + this.status = MissionStatus.END; + } } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java index 1ac31cec..d4df05e9 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java @@ -58,10 +58,8 @@ public Long deleteArchive(String userSocialId, Long missionId) { Mission mission = missionQueryService.findMissionById(missionId); Team team = mission.getTeam(); - // 사진 제출 했다면, + // 사진 제출 했다면, s3 삭제 로직 if (mission.getWay() == MissionWay.PHOTO && missionArchiveQueryService.isDone(memberId, missionId)) { - //s3삭제 - } @@ -70,6 +68,7 @@ public Long deleteArchive(String userSocialId, Long missionId) { MissionState missionState = missionStateQueryService.findMissionState(member, mission); missionStateDeleteService.deleteMissionState(missionState); + return deleteArchive.getId(); } diff --git a/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java b/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java index 41849b62..f3405ce6 100644 --- a/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java @@ -6,6 +6,8 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionType; import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; +import com.moing.backend.domain.missionState.domain.entity.MissionState; +import com.moing.backend.domain.missionState.domain.service.MissionStateDeleteService; import com.moing.backend.domain.missionState.domain.service.MissionStateQueryService; import com.moing.backend.domain.missionState.domain.service.MissionStateSaveService; import com.moing.backend.domain.team.domain.entity.Team; @@ -14,6 +16,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + @Slf4j @Service @Transactional @@ -26,6 +31,7 @@ public class MissionStateUseCase { private final MissionQueryService missionQueryService; private final MissionStateQueryService missionStateQueryService; private final MissionStateSaveService missionStateSaveService; + private final MissionStateDeleteService missionStateDeleteService; private final TeamScoreLogicUseCase teamScoreLogicUseCase; @@ -80,7 +86,18 @@ public void updateMissionState(Member member, Mission mission, MissionArchive mi public void deleteMissionState(Member member, Mission mission, MissionArchive missionArchive) { + MissionState missionState = missionStateQueryService.findMissionState(member, mission); + missionStateDeleteService.deleteMissionState(missionState); + + } + + public void missionStateReset(List missionIds) { + List missionStates = missionStateQueryService.findByMissionId(missionIds); + missionStateDeleteService.deleteMissionState(missionStates); + } + public void deleteAllMissionState(Long missionId) { + missionStateDeleteService.deleteMissionStateByMission(missionId); } diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepository.java b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepository.java index 6a9e996d..01166d64 100644 --- a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepository.java @@ -14,6 +14,7 @@ public interface MissionStateCustomRepository { int getCountsByMissionId(Long missionId) ; List findByMissionId(List missionId); + List findByMissionId(Long missionId); Optional> findFinishMission(); diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java index d6ef72e7..a8aebddd 100644 --- a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java @@ -45,6 +45,17 @@ public List findByMissionId(List missionId) { missionState.mission.id.in(missionId) ).fetch(); + } + @Override + public List findByMissionId(Long missionId) { + + return queryFactory + .select(missionState) + .from(missionState) + .where( + missionState.mission.id.in(missionId) + ).fetch(); + } @Override diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateDeleteService.java b/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateDeleteService.java index eb679fb6..b99aa8b0 100644 --- a/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateDeleteService.java +++ b/src/main/java/com/moing/backend/domain/missionState/domain/service/MissionStateDeleteService.java @@ -23,4 +23,10 @@ public void deleteMissionState(MissionState missionStates) { missionStateRepository.delete(missionStates); } + + public void deleteMissionStateByMission(Long missionId) { + + List missionStates = missionStateRepository.findByMissionId(missionId); + missionStateRepository.deleteAll(missionStates); + } } From f126420ac6d5a5e335ab3b2283d1ffbe621c6408 Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Thu, 16 Nov 2023 22:15:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20:=20=EB=AF=B8=EC=85=98=20=EB=B3=B4?= =?UTF-8?q?=EB=93=9C=20=EB=A6=AC=ED=84=B4=EA=B0=92=20=EC=B6=94=EA=B0=80(mi?= =?UTF-8?q?ssionStatus:wait)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/RepeatMissionBoardRes.java | 18 +- .../application/service/RepeatMissionEnd.java | 188 +++++++++--------- .../MissionArchiveCustomRepositoryImpl.java | 10 +- .../MissionBoardControllerTest.java | 8 +- 4 files changed, 120 insertions(+), 104 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java index 3cff40f6..0caa23dc 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java +++ b/src/main/java/com/moing/backend/domain/mission/application/dto/res/RepeatMissionBoardRes.java @@ -6,7 +6,7 @@ @Getter @Setter -//@Builder +@Builder public class RepeatMissionBoardRes { private Long missionId; private String title; @@ -16,18 +16,19 @@ public class RepeatMissionBoardRes { private Long done; private int number; private String way; + private String status; - public RepeatMissionBoardRes(Long missionId, String title, Long done,int number,String way) { + public RepeatMissionBoardRes(Long missionId, String title, Long done,int number,String way,String status) { this.missionId = missionId; this.title = title; this.dueTo="False"; this.number = number; this.done = done; this.way = way; + this.status = status; } - @Builder public RepeatMissionBoardRes(Long missionId, String title, String dueTo, Long done, int number,String way) { this.missionId = missionId; this.title = title; @@ -36,4 +37,15 @@ public RepeatMissionBoardRes(Long missionId, String title, String dueTo, Long do this.number = number; this.way = way; } + + @Builder + public RepeatMissionBoardRes(Long missionId, String title, String dueTo, Long done, int number, String way, String status) { + this.missionId = missionId; + this.title = title; + this.dueTo = dueTo; + this.done = done; + this.number = number; + this.way = way; + this.status = status; + } } diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java b/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java index 811b051f..114a2e95 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/RepeatMissionEnd.java @@ -1,94 +1,94 @@ -package com.moing.backend.domain.mission.application.service; - -import com.moing.backend.domain.mission.domain.entity.Mission; -import com.moing.backend.domain.missionState.application.service.MissionStateUseCase; -import com.moing.backend.domain.teamScore.application.service.TeamScoreLogicUseCase; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.Step; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.JobScope; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepScope; -import org.springframework.batch.item.ItemProcessor; -import org.springframework.batch.item.database.JpaItemWriter; -import org.springframework.batch.item.database.JpaPagingItemReader; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.persistence.EntityManagerFactory; - -@Slf4j -@RequiredArgsConstructor -@Configuration -public class RepeatMissionEnd { - - public static final String JOB_NAME = "makeMissionEnd"; - - private final EntityManagerFactory entityManagerFactory; - private final StepBuilderFactory stepBuilderFactory; - private final JobBuilderFactory jobBuilderFactory; - - private final MissionStateUseCase missionStateUseCase; - private final TeamScoreLogicUseCase teamScoreLogicUseCase; - - private final int chunkSize = 10; - - @Bean - public Job payPagingJob() { - return jobBuilderFactory.get(JOB_NAME) - .start(payPagingStep()) - .build(); - } - - @Bean - @JobScope - public Step payPagingStep() { - return stepBuilderFactory.get("makeMissionEndStep") - .chunk(chunkSize) - .reader(payPagingReader()) - .processor(payPagingProcessor()) - .writer(writer()) - .build(); - } - - @Bean - @StepScope - public JpaPagingItemReader payPagingReader() { - - JpaPagingItemReader reader = new JpaPagingItemReader() { - @Override - public int getPage() { - return 0; - } - }; - - reader.setQueryString("SELECT m FROM Mission m WHERE m.status = 'ONGOING' AND m.type = 'REPEAT'"); - reader.setPageSize(chunkSize); - reader.setEntityManagerFactory(entityManagerFactory); - reader.setName("payPagingReader"); - - return reader; - } - - // sundayRepeatMissionRoutine() - @Bean - @StepScope - public ItemProcessor payPagingProcessor() { - return mission -> { - teamScoreLogicUseCase.updateTeamScore(mission.getId()); - missionStateUseCase.deleteAllMissionState(mission.getId()); - mission.makeEnd(); - return mission; - }; - } - - @Bean - @StepScope - public JpaItemWriter writer() { - JpaItemWriter writer = new JpaItemWriter<>(); - writer.setEntityManagerFactory(entityManagerFactory); - return writer; - } -} \ No newline at end of file +//package com.moing.backend.domain.mission.application.service; +// +//import com.moing.backend.domain.mission.domain.entity.Mission; +//import com.moing.backend.domain.missionState.application.service.MissionStateUseCase; +//import com.moing.backend.domain.teamScore.application.service.TeamScoreLogicUseCase; +//import lombok.RequiredArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.batch.core.Job; +//import org.springframework.batch.core.Step; +//import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +//import org.springframework.batch.core.configuration.annotation.JobScope; +//import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +//import org.springframework.batch.core.configuration.annotation.StepScope; +//import org.springframework.batch.item.ItemProcessor; +//import org.springframework.batch.item.database.JpaItemWriter; +//import org.springframework.batch.item.database.JpaPagingItemReader; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +//import javax.persistence.EntityManagerFactory; +// +//@Slf4j +//@RequiredArgsConstructor +//@Configuration +//public class RepeatMissionEnd { +// +// public static final String JOB_NAME = "makeMissionEnd"; +// +// private final EntityManagerFactory entityManagerFactory; +// private final StepBuilderFactory stepBuilderFactory; +// private final JobBuilderFactory jobBuilderFactory; +// +// private final MissionStateUseCase missionStateUseCase; +// private final TeamScoreLogicUseCase teamScoreLogicUseCase; +// +// private final int chunkSize = 10; +// +// @Bean +// public Job payPagingJob() { +// return jobBuilderFactory.get(JOB_NAME) +// .start(payPagingStep()) +// .build(); +// } +// +// @Bean +// @JobScope +// public Step payPagingStep() { +// return stepBuilderFactory.get("makeMissionEndStep") +// .chunk(chunkSize) +// .reader(payPagingReader()) +// .processor(payPagingProcessor()) +// .writer(writer()) +// .build(); +// } +// +// @Bean +// @StepScope +// public JpaPagingItemReader payPagingReader() { +// +// JpaPagingItemReader reader = new JpaPagingItemReader() { +// @Override +// public int getPage() { +// return 0; +// } +// }; +// +// reader.setQueryString("SELECT m FROM Mission m WHERE m.status = 'ONGOING' AND m.type = 'REPEAT'"); +// reader.setPageSize(chunkSize); +// reader.setEntityManagerFactory(entityManagerFactory); +// reader.setName("payPagingReader"); +// +// return reader; +// } +// +// // sundayRepeatMissionRoutine() +// @Bean +// @StepScope +// public ItemProcessor payPagingProcessor() { +// return mission -> { +// teamScoreLogicUseCase.updateTeamScore(mission.getId()); +// missionStateUseCase.deleteAllMissionState(mission.getId()); +// mission.makeEnd(); +// return mission; +// }; +// } +// +// @Bean +// @StepScope +// public JpaItemWriter writer() { +// JpaItemWriter writer = new JpaItemWriter<>(); +// writer.setEntityManagerFactory(entityManagerFactory); +// return writer; +// } +//} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index efa04b7f..f9781c43 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -43,13 +43,12 @@ public MissionArchiveCustomRepositoryImpl(EntityManager em) { public Optional> findSingleMissionInComplete(Long memberId, Long teamId, MissionStatus status, OrderCondition orderCondition) { OrderSpecifier[] orderSpecifiers = createOrderSpecifier(orderCondition); - String missionArchiveStatus = "INCOMPLETE"; return Optional.ofNullable(queryFactory .select(Projections.constructor(SingleMissionBoardRes.class, mission.id, mission.dueTo.stringValue(), mission.title, - Expressions.constant(missionArchiveStatus), + mission.status.stringValue(), mission.type.stringValue() )) .from(mission) @@ -64,10 +63,12 @@ public Optional> findSingleMissionInComplete(Long me .or(missionState.mission.status.eq(MissionStatus.ONGOING)) )), mission.type.eq(MissionType.ONCE), + mission.status.eq(MissionStatus.ONGOING).or(mission.status.eq(MissionStatus.WAIT)), mission.team.teamId.eq(teamId)) .orderBy(orderSpecifiers).fetch()); + } @Override public Optional> findSingleMissionComplete(Long memberId, Long teamId, MissionStatus status, @@ -176,7 +177,8 @@ public Optional> findRepeatMissionArchivesByMemberId mission.title, missionArchive.count.max().coalesce(0L).as("done"), mission.number, - mission.way.stringValue() + mission.way.stringValue(), + mission.status.stringValue() )) .from(mission) .leftJoin(mission.missionArchiveList,missionArchive) @@ -184,7 +186,7 @@ public Optional> findRepeatMissionArchivesByMemberId .where( mission.team.teamId.eq(teamId), mission.type.eq(MissionType.REPEAT), - mission.status.eq(MissionStatus.ONGOING) + mission.status.eq(MissionStatus.ONGOING).or(mission.status.eq(MissionStatus.WAIT)) ) .groupBy(mission) .fetch()); diff --git a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java index 91fae242..5065dcac 100644 --- a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java +++ b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionBoardControllerTest.java @@ -42,7 +42,7 @@ public class MissionBoardControllerTest extends CommonControllerTest { .missionId(1L) .dueTo("2023-09-03T21:32:33.888") .title("Mission title") - .status("SKIP/COMPLETE") + .status("WAIT/ONGOING/SKIP/COMPLETE") .missionType("ONCE/REPEAT") .build()); @@ -94,7 +94,8 @@ public class MissionBoardControllerTest extends CommonControllerTest { .dueTo("True/False") .done(1L) .number(3) - .way("TEXT/PHOTO/LINK") + .way("TEXT/PHOTO/LINK") + .status("WAIT/ONGOING/SKIP/COMPLETE") .build()); given(missionArchiveBoardUseCase.getActiveRepeatMissions(any(),any())).willReturn(output); @@ -127,7 +128,8 @@ public class MissionBoardControllerTest extends CommonControllerTest { fieldWithPath("data[].dueTo").description("내일 리셋 상태 리턴, 일요일이면 true[True/False]"), fieldWithPath("data[].number").description("전체 횟수"), fieldWithPath("data[].done").description("인증한 횟수"), - fieldWithPath("data[].way").description("인증 방법") + fieldWithPath("data[].way").description("인증 방법"), + fieldWithPath("data[].status").description("인증 상태") ) )