[spring] 주간 매출!!!!! 차트 출력하기 (echart)
by mini_min[spring] 주간 매출!!!!! 출력하기 (echart)
✔️ 주간 매출 출력하기
: 감격...ㅠㅠ 동생이 많이 도와줘서 많이 이해했다! ㅠㅠ
echart 에 넘긴다는 것 자체가 생소해서... 더 좋은 방법으로 코드를 짤 수 있겠지만, 일단 죽이되든 밥이되든 짜보자! 라는 생각으로 코드를 짰는데 더 깔끔한 코드도 있을 것이다.
1) 데이터를 넘겨줄 map 객체 (model) + ProductOrder 로 매출일/매출금액 데이터를 저장하는 List 객체
Map<String, Object> model = new HashMap<>();
List<ProductOrder> listMoney = service.listMoney();
2) 주간 일정을 출력할 Date + 주간 일정 날짜를 받을 List 객체 생성
배열 gg 는 나중에 payment 를 출력할 배열이고 for 문을 돌리는 동안 0으로 초기화한다.
이후 매출일/매출금액이 저장된 List 객체를 for 문으로 돌린다. 주간 일정 날짜와 매출일이 일치하면, payment 를 담을 gg 배열에 값을 저장한다.
List<String> weekList = new ArrayList<>();
int[] gg = new int[7];
for(int i=0; i<7; i++) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -i);
gg[i] = 0;
String weekDate = simpleDateFormat.format(cal.getTime());
weekList.add(weekDate);
}
for(int j=0; j<listMoney.size(); j++) {
String od = listMoney.get(j).getOrderDate();
int idx = weekList.indexOf(od);
gg[idx] = listMoney.get(j).getPayment();
}
3) List<Map<String, Object>> list = new ArrayList<>(); List 객체에 type 과 data 를 가진 map 객체를 추가하고 model 객체에 추가해서 return 하면 끝!
'Spring' 카테고리의 다른 글
[spring] security-context 스프링 시큐리티 설정 (접근권한, 로그인) (0) | 2022.12.05 |
---|---|
[spring] 쪽지보내기 , 메일 보내기 Controller,ServiceImpl (0) | 2022.12.05 |
[spring] XML 파싱, JSON 파싱 ⭐⭐ (1) | 2022.11.30 |
[spring] localStorage 사용법! (0) | 2022.11.29 |
[spring] 최근 본 게시글 보기 (0) | 2022.11.29 |
블로그의 정보
개발자 미니민의 개발로그
mini_min