Skip to content

Commit

Permalink
Merge pull request #45 from FTHON-6TEAM/feat/staticitsandchallenge
Browse files Browse the repository at this point in the history
Feat/staticitsandchallenge
  • Loading branch information
rhkdgur authored Sep 13, 2024
2 parents 00d302b + 5ee4972 commit 60671fe
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.util.List;
Expand Down Expand Up @@ -125,8 +126,10 @@ public ResponseEntity<?> deleteChallenge(@RequestParam("idx") Long idx) throws E
})
@PostMapping(value = "/challenge/apply/item/ins",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> insertChallengeApplyItem(
final @Valid @RequestPart ChallengeUserItemCreateRequest challengeUserItemCreateRequest) throws Exception {

final @Valid @RequestPart ChallengeUserItemCreateRequest challengeUserItemCreateRequest,
final @RequestPart(value = "_file", required = false) MultipartFile multipartFile
) throws Exception {

ChallengeUserItemDto dto = ChallengeUserItemDto.createOf(challengeUserItemCreateRequest);
challengeApplyService.insertChallengeApplyItem(dto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
* packageName : com.challenger.challengerbe.modules.challenge.controller
Expand Down Expand Up @@ -78,6 +79,7 @@ public ChallengeWithItemListResponse selectChallengeView(@Parameter(hidden = tru
})
@PostMapping(value="/challenge/ins", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> insertChallenge(final @Valid @RequestPart ChallengeCreateRequest challengeCreateRequest,
final @RequestPart(value = "_file", required = false) MultipartFile multipartFile,
@AuthInfo String token) throws Exception {
ChallengeDto challengeDto = ChallengeDto.createof(challengeCreateRequest);
challengeDto.setIdk(token);
Expand All @@ -99,6 +101,7 @@ public ResponseEntity<?> insertChallenge(final @Valid @RequestPart ChallengeCrea
})
@PutMapping(value="/challenge/upd", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> updateChallenge(final @Valid @RequestPart ChallengeUpdateRequest challengeUpdateRequest,
final @RequestPart(value = "_file", required = false) MultipartFile multipartFile,
@Parameter(hidden = true) @AuthInfo String token) throws Exception {

ChallengeDto challengeDto = ChallengeDto.updateOf(challengeUpdateRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@AllArgsConstructor
public class ChallengeUserItemDto implements CmsFileSupport<CmsFileDto> {

private Long idx;
private Long idx = 0L;

private Long challengeUserIdx;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,33 @@ public class ChallengeStatisticsController {

@Operation(summary = "챌린지 참여율 통계 (월별)")
@Parameter(name = "code" , description = "키워드 default는 공백입니다.")
@GetMapping("/challenge/join/month/statistics")
@GetMapping("/challenge/statistics/month/join")
public ChalendarMonthResponse selectChallengeJoinMonthStatistics(@Parameter(hidden = true) ChallengeDefaultDto searchDto,
@Parameter(hidden = true) @AuthInfo String token) throws Exception {

searchDto.setIdk(token == null ? "" : token);
return challengeStatisticsService.selectChallengeJoinStatisticsMonthList(searchDto);
}


@Operation(summary = "챌린지 참여중 성공률 통계 (월별)")
@Parameter(name = "code" , description = "키워드 default는 공백입니다.")
@GetMapping("/challenge/statistics/month/success")
public ChalendarMonthResponse selectChallengeSuccessMonthStatistics(@Parameter(hidden = true) ChallengeDefaultDto searchDto,
@Parameter(hidden = true) @AuthInfo String token) throws Exception {

searchDto.setIdk(token == null ? "" : token);
return challengeStatisticsService.selectChallengeSuccessStatisticsMonthList(searchDto);
}


@Operation(summary = "챌린지 참여중 실패률 통계 (월별)")
@Parameter(name = "code" , description = "키워드 default는 공백입니다.")
@GetMapping("/challenge/statistics/month/fail")
public ChalendarMonthResponse selectChallengeFailMonthStatistics(@Parameter(hidden = true) ChallengeDefaultDto searchDto,
@Parameter(hidden = true) @AuthInfo String token) throws Exception {

searchDto.setIdk(token == null ? "" : token);
return challengeStatisticsService.selectChallengeFailStatisticsMonthList(searchDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,20 @@ public interface ChallengeStatisticsRepository {
*/
ChalendarMonthResponse selectChallengeJoinStatisticsMonthList(ChallengeDefaultDto searchDto) throws Exception;

/**
* 챌린지 성공 월별 조회
* @param searchDto
* @return
* @throws Exception
*/
ChalendarMonthResponse selectChallengeSuccessStatisticsMonthList(ChallengeDefaultDto searchDto) throws Exception;

/**
* 챌린지 실패 월별 조회
* @param searchDto
* @return
* @throws Exception
*/
ChalendarMonthResponse selectChallengeFailStatisticsMonthList(ChallengeDefaultDto searchDto) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ public ChalendarMonthResponse selectChallengeJoinStatisticsMonthList(ChallengeDe

StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
sql.append("MAX(CASE WHEN m = 1 THEN av ELSE 0 END) AS month1,");
sql.append("MAX(CASE WHEN m = 2 THEN av ELSE 0 END) AS month2,");
sql.append("MAX(CASE WHEN m = 3 THEN av ELSE 0 END) AS month3,");
sql.append("MAX(CASE WHEN m = 4 THEN av ELSE 0 END) AS month4,");
sql.append("MAX(CASE WHEN m = 5 THEN av ELSE 0 END) AS month5,");
sql.append("MAX(CASE WHEN m = 6 THEN av ELSE 0 END) AS month6,");
sql.append("MAX(CASE WHEN m = 7 THEN av ELSE 0 END) AS month7,");
sql.append("MAX(CASE WHEN m = 8 THEN av ELSE 0 END) AS month8,");
sql.append("MAX(CASE WHEN m = 9 THEN av ELSE 0 END) AS month9,");
sql.append("MAX(CASE WHEN m = 10 THEN av ELSE 0 END) AS month10,");
sql.append("MAX(CASE WHEN m = 11 THEN av ELSE 0 END) AS month11,");
sql.append("MAX(CASE WHEN m = 12 THEN av ELSE 0 END) AS month12 ")
sql.append("IFNULL(MAX(CASE WHEN m = 1 THEN av ELSE 0 END),0) AS month1,");
sql.append("IFNULL(MAX(CASE WHEN m = 2 THEN av ELSE 0 END),0) AS month2,");
sql.append("IFNULL(MAX(CASE WHEN m = 3 THEN av ELSE 0 END),0) AS month3,");
sql.append("IFNULL(MAX(CASE WHEN m = 4 THEN av ELSE 0 END),0) AS month4,");
sql.append("IFNULL(MAX(CASE WHEN m = 5 THEN av ELSE 0 END),0) AS month5,");
sql.append("IFNULL(MAX(CASE WHEN m = 6 THEN av ELSE 0 END),0) AS month6,");
sql.append("IFNULL(MAX(CASE WHEN m = 7 THEN av ELSE 0 END),0) AS month7,");
sql.append("IFNULL(MAX(CASE WHEN m = 8 THEN av ELSE 0 END),0) AS month8,");
sql.append("IFNULL(MAX(CASE WHEN m = 9 THEN av ELSE 0 END),0) AS month9,");
sql.append("IFNULL(MAX(CASE WHEN m = 10 THEN av ELSE 0 END),0) AS month10,");
sql.append("IFNULL(MAX(CASE WHEN m = 11 THEN av ELSE 0 END),0) AS month11,");
sql.append("IFNULL(MAX(CASE WHEN m = 12 THEN av ELSE 0 END),0) AS month12 ")
.append("FROM ( ");
sql.append("SELECT m, ROUND(AVG(av)) av, COUNT(*) c FROM ( " );
sql.append("SELECT T.idx, T.challenge_idx, T.cnt, T.dcnt, ROUND(((T.cnt / T.dcnt) * 100)) av , T.m FROM ( ");
sql.append("SELECT a.*, b.cnt, DATEDIFF(c.end_date,c.start_date) dcnt, MONTH(c.start_date) m FROM challenge_user a ");
sql.append("LEFT JOIN ( SELECT challenge_user_idx, COUNT(*) cnt FROM challenge_user_item WHERE complete_yn = 'Y' ");
sql.append("GROUP BY challenge_user_idx ) b ON a.idx = b.challenge_user_idx ");
sql.append("LEFT JOIN ( SELECT challenge_user_idx,COUNT(*) cnt FROM ( select challenge_user_idx, complete_date FROM challenge_user_item ");
sql.append(" WHERE complete_yn = 'Y' GROUP BY complete_date,challenge_user_idx ORDER BY complete_date asc )a GROUP BY challenge_user_idx ) b ON a.idx = b.challenge_user_idx ");
sql.append("JOIN ( SELECT start_date, end_date, idx FROM challenge ) c ON a.challenge_idx = c.idx ");
sql.append("WHERE 1=1 ");
if(StringUtils.isBlank(searchDto.getIdk())) {
Expand All @@ -66,4 +66,76 @@ public ChalendarMonthResponse selectChallengeJoinStatisticsMonthList(ChallengeDe
JpaResultMapper jpaResultMapper = new JpaResultMapper();
return jpaResultMapper.uniqueResult(entityManager.createNativeQuery(sql.toString()), ChalendarMonthResponse.class);
}

@Override
public ChalendarMonthResponse selectChallengeSuccessStatisticsMonthList(ChallengeDefaultDto searchDto) throws Exception {
StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
sql.append("IFNULL(MAX(CASE WHEN m = 1 THEN av ELSE 0 END),0) AS month1,");
sql.append("IFNULL(MAX(CASE WHEN m = 2 THEN av ELSE 0 END),0) AS month2,");
sql.append("IFNULL(MAX(CASE WHEN m = 3 THEN av ELSE 0 END),0) AS month3,");
sql.append("IFNULL(MAX(CASE WHEN m = 4 THEN av ELSE 0 END),0) AS month4,");
sql.append("IFNULL(MAX(CASE WHEN m = 5 THEN av ELSE 0 END),0) AS month5,");
sql.append("IFNULL(MAX(CASE WHEN m = 6 THEN av ELSE 0 END),0) AS month6,");
sql.append("IFNULL(MAX(CASE WHEN m = 7 THEN av ELSE 0 END),0) AS month7,");
sql.append("IFNULL(MAX(CASE WHEN m = 8 THEN av ELSE 0 END),0) AS month8,");
sql.append("IFNULL(MAX(CASE WHEN m = 9 THEN av ELSE 0 END),0) AS month9,");
sql.append("IFNULL(MAX(CASE WHEN m = 10 THEN av ELSE 0 END),0) AS month10,");
sql.append("IFNULL(MAX(CASE WHEN m = 11 THEN av ELSE 0 END),0) AS month11,");
sql.append("IFNULL(MAX(CASE WHEN m = 12 THEN av ELSE 0 END),0) AS month12 ")
.append("FROM ( ");
sql.append("SELECT m, ROUND(AVG(av)) av FROM ( SELECT m , ROUND(((cnt / dcnt) * 100 )) av FROM ( " );
sql.append("SELECT m, dcnt, count(*) cnt FROM ( ");
sql.append("SELECT a.*, DATEDIFF(c.end_date,c.start_date) dcnt, MONTH(c.start_date) m FROM challenge_user a ");
sql.append("LEFT JOIN ( SELECT challenge_user_idx, complete_date, count(*) cnt FROM challenge_user_item where complete_yn = 'Y' GROUP BY challenge_user_idx, complete_date ");
sql.append(") b ON a.idx = b.challenge_user_idx ");
sql.append("JOIN ( SELECT start_date, end_date, idx , success_cnt FROM challenge ) c ON a.challenge_idx = c.idx ");
sql.append("WHERE 1=1 and b.cnt >= c.success_cnt ");
if(StringUtils.isBlank(searchDto.getIdk())) {
sql.append("and idk = '").append(searchDto.getIdk()).append("' ");
}
if(!StringUtils.isBlank(searchDto.getCode())){
sql.append("and code = '").append(searchDto.getCode()).append("' ");
}
sql.append(")T GROUP BY m, dcnt )TT )TTT GROUP BY m ) TTTT ");

JpaResultMapper jpaResultMapper = new JpaResultMapper();
return jpaResultMapper.uniqueResult(entityManager.createNativeQuery(sql.toString()), ChalendarMonthResponse.class);
}

@Override
public ChalendarMonthResponse selectChallengeFailStatisticsMonthList(ChallengeDefaultDto searchDto) throws Exception {
StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
sql.append("IFNULL(MAX(CASE WHEN m = 1 THEN av ELSE 0 END),0) AS month1,");
sql.append("IFNULL(MAX(CASE WHEN m = 2 THEN av ELSE 0 END),0) AS month2,");
sql.append("IFNULL(MAX(CASE WHEN m = 3 THEN av ELSE 0 END),0) AS month3,");
sql.append("IFNULL(MAX(CASE WHEN m = 4 THEN av ELSE 0 END),0) AS month4,");
sql.append("IFNULL(MAX(CASE WHEN m = 5 THEN av ELSE 0 END),0) AS month5,");
sql.append("IFNULL(MAX(CASE WHEN m = 6 THEN av ELSE 0 END),0) AS month6,");
sql.append("IFNULL(MAX(CASE WHEN m = 7 THEN av ELSE 0 END),0) AS month7,");
sql.append("IFNULL(MAX(CASE WHEN m = 8 THEN av ELSE 0 END),0) AS month8,");
sql.append("IFNULL(MAX(CASE WHEN m = 9 THEN av ELSE 0 END),0) AS month9,");
sql.append("IFNULL(MAX(CASE WHEN m = 10 THEN av ELSE 0 END),0) AS month10,");
sql.append("IFNULL(MAX(CASE WHEN m = 11 THEN av ELSE 0 END),0) AS month11,");
sql.append("IFNULL(MAX(CASE WHEN m = 12 THEN av ELSE 0 END),0) AS month12 ")
.append("FROM ( ");
sql.append("SELECT m, ROUND(AVG(av)) av FROM ( SELECT m , ROUND(((cnt / dcnt) * 100 )) av FROM ( " );
sql.append("SELECT m, dcnt, count(*) cnt FROM ( ");
sql.append("SELECT a.*, DATEDIFF(c.end_date,c.start_date) dcnt, MONTH(c.start_date) m FROM challenge_user a ");
sql.append("LEFT JOIN ( SELECT challenge_user_idx, complete_date, count(*) cnt FROM challenge_user_item where complete_yn = 'Y' GROUP BY challenge_user_idx, complete_date ");
sql.append(") b ON a.idx = b.challenge_user_idx ");
sql.append("JOIN ( SELECT start_date, end_date, idx , success_cnt FROM challenge ) c ON a.challenge_idx = c.idx ");
sql.append("WHERE 1=1 and b.cnt < c.success_cnt ");
if(StringUtils.isBlank(searchDto.getIdk())) {
sql.append("and idk = '").append(searchDto.getIdk()).append("' ");
}
if(!StringUtils.isBlank(searchDto.getCode())){
sql.append("and code = '").append(searchDto.getCode()).append("' ");
}
sql.append(")T GROUP BY m, dcnt )TT )TTT GROUP BY m ) TTTT ");

JpaResultMapper jpaResultMapper = new JpaResultMapper();
return jpaResultMapper.uniqueResult(entityManager.createNativeQuery(sql.toString()), ChalendarMonthResponse.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ChallengeStatisticsService {

private final ChallengeStatisticsRepository challengeStatisticsRepository;
Expand All @@ -36,5 +37,25 @@ public class ChallengeStatisticsService {
public ChalendarMonthResponse selectChallengeJoinStatisticsMonthList(ChallengeDefaultDto searchDto) throws Exception {
return challengeStatisticsRepository.selectChallengeJoinStatisticsMonthList(searchDto);
}

/**
* 월별 참여 중 성공률 통계 자료
* @param searchDto
* @return
* @throws Exception
*/
public ChalendarMonthResponse selectChallengeSuccessStatisticsMonthList(ChallengeDefaultDto searchDto) throws Exception {
return challengeStatisticsRepository.selectChallengeSuccessStatisticsMonthList(searchDto);
}

/**
* 월별 참여 중 실패율 통계 자료
* @param searchDto
* @return
* @throws Exception
*/
public ChalendarMonthResponse selectChallengeFailStatisticsMonthList(ChallengeDefaultDto searchDto) throws Exception {
return challengeStatisticsRepository.selectChallengeFailStatisticsMonthList(searchDto);
}

}

0 comments on commit 60671fe

Please sign in to comment.