Skip to content
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
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation 'ch.qos.logback:logback-classic:1.5.13'
implementation 'ch.qos.logback:logback-core:1.5.13'

implementation group: 'org.bgee.log4jdbc-log4j2', name: 'log4jdbc-log4j2-jdbc4.1', version: '1.16'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'com.github.ben-manes.caffeine:caffeine'

}

Expand Down
Binary file removed ch.qos.logback.core.util.COWArrayList.class
Binary file not shown.
Binary file not shown.
Binary file removed com.WealthTracker.demo.DemoApplication.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed com.WealthTracker.demo.domain.user.entity.User.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed com.WealthTracker.demo.global.util.JwtUtil.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed com.google.gson.Gson.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed com.google.gson.internal.bind.TypeAdapters.class
Binary file not shown.
Binary file removed com.zaxxer.hikari.util.FastList.class
Binary file not shown.
Binary file not shown.
Binary file removed io.github.classgraph.ResourceList.class
Binary file not shown.
Binary file removed io.jsonwebtoken.impl.JwtMap.class
Binary file not shown.
Binary file removed io.jsonwebtoken.io.Base64Decoder.class
Binary file not shown.
Binary file removed io.jsonwebtoken.io.ExceptionPropagatingDecoder.class
Binary file not shown.
Binary file removed io.jsonwebtoken.security.Keys.class
Binary file not shown.
Binary file removed java.lang.reflect.Method.class
Binary file not shown.
Binary file removed kotlin.collections.AbstractCollection.class
Binary file not shown.
Binary file not shown.
Binary file removed org.apache.catalina.util.ParameterMap.class
Binary file not shown.
Binary file removed org.apache.commons.logging.LogFactory.class
Binary file not shown.
Binary file not shown.
Binary file removed org.hibernate.collection.spi.PersistentBag.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed org.springframework.core.OverridingClassLoader.class
Binary file not shown.
Binary file removed org.springframework.http.HttpHeaders.class
Binary file not shown.
Binary file removed org.springframework.http.HttpLogging.class
Binary file not shown.
Binary file removed org.springframework.http.ReadOnlyHttpHeaders.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed org.springframework.util.Assert.class
Binary file not shown.
Binary file removed org.springframework.util.CollectionUtils.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed org.springframework.util.MimeType.class
Binary file not shown.
Binary file removed org.springframework.util.MultiValueMapAdapter.class
Binary file not shown.
Binary file not shown.
Binary file removed org.springframework.web.client.RestTemplate.class
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/com/WealthTracker/demo/DemoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
@EnableCaching
public class DemoApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ResponseEntity<List<ExpendResponseDTO>> recentExpend(@RequestHeader("Auth
@ApiResponse(responseCode = "500", description = "서버 오류", content = {@Content(mediaType = "string")})
})
@GetMapping("/expend/graph")
public ResponseEntity<List<ExpendDateResponseDTO>> amountByWeek(@RequestHeader("Authorization") String token){
public ResponseEntity<List<ExpendWeekCompareDTO>> amountByWeek(@RequestHeader("Authorization") String token){
return new ResponseEntity<>(expendService.getAmountByWeek(token),HttpStatusCode.valueOf(SuccessCode.SUCCESS_RESPOND_EXPEND.getStatus()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.WealthTracker.demo.domain.expend.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
public class ExpendDateResponseDTO {
//달 반환
private int month;
Expand All @@ -17,8 +15,8 @@ public class ExpendDateResponseDTO {
private int weekNum;

//이번달 같은주 지출 총 합계
private int thisWeekTotalCost;
private int thisMonthTotalCost;

//저번달 같은 주 지출 총 합계
private int lastWeekTotalCost;
private int prevMonthTotalCost;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.WealthTracker.demo.domain.expend.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
Expand All @@ -8,6 +9,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@Builder
@AllArgsConstructor
Expand All @@ -16,9 +19,8 @@
public class ExpendRequestDTO {
//날짜
@NotNull
@Size(min = 10,max = 10,message = "날짜는 반드시 yyyy-MM-dd 형식으로 입력")
@Pattern(regexp = "\\d{4}-\\d{2}-\\d{2}")
private String expendDate;
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime expendDate;
//금액
@NotNull
@Size(min = 1,message = "수입 금액은 1자리 이상 입력.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.WealthTracker.demo.domain.expend.dto;
public interface ExpendWeekCompareDTO {
Integer getWeekNum();
Long getThisMonthTotalCost();
Long getPrevMonthTotalCost();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
@Builder(toBuilder = true)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "expend")
@Table(name = "expend",indexes={
@Index(name="idx_expend_date_user_id",columnList="expendDate, userId",unique=true)
})
public class Expend {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.WealthTracker.demo.domain.expend.repository;

import com.WealthTracker.demo.domain.expend.dto.ExpendDateResponseDTO;
import com.WealthTracker.demo.domain.expend.dto.ExpendWeekCompareDTO;
import com.WealthTracker.demo.domain.expend.entity.Expend;
import com.WealthTracker.demo.domain.user.entity.User;
import com.WealthTracker.demo.domain.category.enums.Category_Expend;
import io.micrometer.core.annotation.Timed;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
Expand All @@ -24,50 +28,93 @@ public interface ExpendRepository extends JpaRepository<Expend, Long> {

//날짜로 최신순 정렬하여 5개 가져오기
@Query("select e from Expend e where e.user = :user " +
"order by e.expendDate desc")
Optional<List<Expend>> findRecentExpend(Pageable pageable,User user);
"order by e.expendDate desc")
Optional<List<Expend>> findRecentExpend(Pageable pageable, User user);

//이번 달 최신 지출 내역 2개
@Query("SELECT e FROM Expend e WHERE e.categoryExpend.categoryName = :category AND e.user = :user "+
"and month (e.expendDate) = month (current_date) "+
"and year (e.expendDate) = year (current_date) "+
" ORDER BY e.expendDate DESC")
@Query("SELECT e FROM Expend e WHERE e.categoryExpend.categoryName = :category AND e.user = :user " +
"and month (e.expendDate) = month (current_date) " +
"and year (e.expendDate) = year (current_date) " +
" ORDER BY e.expendDate DESC")
List<Expend> findRecentExpend(User user, Category_Expend category, Pageable pageable);

//이번 달 주차별 지출 총액 리턴
@Query("select CAST(FLOOR(DAY(e.expendDate)-1)/7 + 1 AS INTEGER) AS weekNum, " +
" SUM(e.cost) AS totalCost " +
"from Expend e " +
"where e.user = :user " +
" and MONTH(e.expendDate) = MONTH(CURRENT_DATE) " +
"group by CAST((FLOOR(DAY(e.expendDate) - 1) / 7) + 1 AS INTEGER)"
" SUM(e.cost) AS totalCost " +
"from Expend e " +
"where e.user = :user " +
" and MONTH(e.expendDate) = MONTH(CURRENT_DATE) " +
"group by CAST((FLOOR(DAY(e.expendDate) - 1) / 7) + 1 AS INTEGER)"
)
List<Object[]> getTotalExpendThisMonth(@Param("user") User user);

//저번 달 주차별 지출 총액 리턴
@Query("select CAST(FLOOR(DAY(e.expendDate)-1)/7 + 1 AS INTEGER) AS weekNum, " +
" SUM(e.cost) AS totalCost " +
"from Expend e " +
"where e.user = :user " +
" and MONTH(e.expendDate) = MONTH(CURRENT_DATE) - 1 " +
"group by CAST((FLOOR(DAY(e.expendDate) - 1) / 7) + 1 AS INTEGER)"
" SUM(e.cost) AS totalCost " +
"from Expend e " +
"where e.user = :user " +
" and MONTH(e.expendDate) = MONTH(CURRENT_DATE) - 1 " +
"group by CAST((FLOOR(DAY(e.expendDate) - 1) / 7) + 1 AS INTEGER)"
)
List<Object[]> getTotalExpendLastMonth(@Param("user") User user);


@Query(value = """
SELECT
weekNum,
SUM(CASE WHEN monthType = 'this' THEN totalCost ELSE 0 END) AS thisMonthTotalCost,
SUM(CASE WHEN monthType = 'prev' THEN totalCost ELSE 0 END) AS prevMonthTotalCost
FROM (
(
SELECT
WEEK(e.expendDate, 2)
- WEEK(DATE_SUB(e.expendDate, INTERVAL DAYOFMONTH(e.expendDate)-1 DAY), 2) + 1 AS weekNum,
SUM(e.cost) AS totalCost,
'this' AS monthType
FROM expend e
WHERE e.userId = :userId
AND YEAR(e.expendDate) = YEAR(CURRENT_DATE)
AND MONTH(e.expendDate) = MONTH(CURRENT_DATE)
GROUP BY WEEK(e.expendDate, 2)
- WEEK(DATE_SUB(e.expendDate, INTERVAL DAYOFMONTH(e.expendDate)-1 DAY), 2) + 1
)
UNION ALL
(
SELECT
WEEK(e.expendDate, 2)
- WEEK(DATE_SUB(e.expendDate, INTERVAL DAYOFMONTH(e.expendDate)-1 DAY), 2) + 1 AS weekNum,
SUM(e.cost) AS totalCost,
'prev' AS monthType
FROM expend e
WHERE e.userId = :userId
AND (
(MONTH(CURRENT_DATE) = 1 AND MONTH(e.expendDate) = 12 AND YEAR(e.expendDate) = YEAR(CURRENT_DATE) - 1)
OR (MONTH(CURRENT_DATE) != 1 AND MONTH(e.expendDate) = MONTH(CURRENT_DATE) - 1 AND YEAR(e.expendDate) = YEAR(CURRENT_DATE))
)
GROUP BY WEEK(e.expendDate, 2)
- WEEK(DATE_SUB(e.expendDate, INTERVAL DAYOFMONTH(e.expendDate)-1 DAY), 2) + 1
)
) AS union_table
GROUP BY weekNum
ORDER BY weekNum ASC
""", nativeQuery = true)
List<ExpendWeekCompareDTO> getExpendWeekCompare(@Param("userId") Long userId);

//지출내역 삭제
void deleteById(Long expendId);

//월별 지출내역 리스트 반환 - 날짜는 상관없음
@Query("select e from Expend e "+
"where e.user = :user and MONTH(e.expendDate) = :month "+
"order by e.expendDate desc")
@Query("select e from Expend e " +
"where e.user = :user and MONTH(e.expendDate) = :month " +
"order by e.expendDate desc")
@Timed(value = "repository.findAllByExpendDate", description = "Time spent on repository#findAllByExpendDate")
List<Expend>findAllByExpendDate(@Param("user")User user, @Param("month")int month);
List<Expend> findAllByExpendDate(@Param("user") User user, @Param("month") int month);

//카테고리에 따른 지출 합계
@Query("SELECT COALESCE(SUM(e.cost), 0) FROM Expend e " +
"WHERE e.user = :user " +
"AND e.categoryExpend.categoryName = :categoryName " +
"AND e.expendDate BETWEEN :weekStart AND :weekEnd")
"WHERE e.user = :user " +
"AND e.categoryExpend.categoryName = :categoryName " +
"AND e.expendDate BETWEEN :weekStart AND :weekEnd")
Long amountByCategory(
@Param("user") User user,
@Param("categoryName") Category_Expend categoryName,
Expand All @@ -81,35 +128,35 @@ Long amountByCategory(


//이번 달카테고리별 지출 총액 가져오기
@Query("select coalesce(sum (e.cost),0) from Expend e "+
"where e.user =:user "+
"and e.categoryExpend.categoryName= :categoryName " +
"and month (e.expendDate) = month (current_date) "+
"and year (e.expendDate) = year (current_date)"
)
Long thisMonthAmountByCategory(@Param("user")User user,@Param("categoryName") Category_Expend categoryName);
@Query("select coalesce(sum (e.cost),0) from Expend e " +
"where e.user =:user " +
"and e.categoryExpend.categoryName= :categoryName " +
"and month (e.expendDate) = month (current_date) " +
"and year (e.expendDate) = year (current_date)"
)
Long thisMonthAmountByCategory(@Param("user") User user, @Param("categoryName") Category_Expend categoryName);

//저번 달 카테고리별 지출 총액 가져오기
@Query("select coalesce(sum (e.cost),0) from Expend e "+
"where e.user =:user "+
"and e.categoryExpend.categoryName = :categoryName " +
"and month (e.expendDate) = month (current_date) - 1 "+
"and year (e.expendDate) = year (current_date ) "+
"or (month (current_date ) = 1 and month (e.expendDate) = 12 and year(e.expendDate) = year (current_date) - 1)"
@Query("select coalesce(sum (e.cost),0) from Expend e " +
"where e.user =:user " +
"and e.categoryExpend.categoryName = :categoryName " +
"and month (e.expendDate) = month (current_date) - 1 " +
"and year (e.expendDate) = year (current_date ) " +
"or (month (current_date ) = 1 and month (e.expendDate) = 12 and year(e.expendDate) = year (current_date) - 1)"
)
Long prevMonthAmountByCategory(@Param("user")User user,@Param("categoryName") Category_Expend categoryName);
Long prevMonthAmountByCategory(@Param("user") User user, @Param("categoryName") Category_Expend categoryName);


//2주단위로 일별 총지출 금액
@Query("select coalesce( sum (e.cost) , 0), e.expendDate from Expend e "+
"where e.expendDate between :startDate and :endDate "+
"and e.user = :user "+
"group by e.expendDate "+
"order by e.expendDate")
List<Object[]> findExpendTotalByDateRange(@Param("user")User user,@Param("startDate")LocalDateTime startDate,@Param("endDate")LocalDateTime endDate);
@Query("select coalesce( sum (e.cost) , 0), e.expendDate from Expend e " +
"where e.expendDate between :startDate and :endDate " +
"and e.user = :user " +
"group by e.expendDate " +
"order by e.expendDate")
List<Object[]> findExpendTotalByDateRange(@Param("user") User user, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);

//최근 수정 날짜
@Query("select max(e.updateDate) from Expend e where e.user = :user")
LocalDateTime findLatestUpdateDate(@Param("user")User user);
LocalDateTime findLatestUpdateDate(@Param("user") User user);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface ExpendService {
//최근 지출 내역 불러오기-5개
List<ExpendResponseDTO> getRecentExpend(String token);
//그래프를 위한 같은 주 저번달, 이번 달 지출 총액 불러오기
List<ExpendDateResponseDTO> getAmountByWeek(String token);
List<ExpendWeekCompareDTO> getAmountByWeek(String token);

//이번 비용 내역
List<ExpendCategoryAmountDTO> getAmountByMonth(String token);
Expand Down
Loading
Loading