Merge branch 'household_tab' into bo_daily

This commit is contained in:
김현주
2025-07-02 14:00:43 +09:00
4 changed files with 1036 additions and 286 deletions

View File

@@ -1,14 +1,31 @@
package app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsStatus.adapters.web;
import app.module.admin.config.application.util.ExcelWriterUtil;
import app.module.admin.config.application.util.model.ExcelSheetDto;
import app.module.admin.usecase.household.getHouseholdStatus.ports.GetHouseholdStatusPortIn;
import app.module.admin.usecase.household.getHouseholdStatus.ports.application.domain.GetHouseholdStatus;
import app.module.admin.usecase.household.getHouseholdStatus.ports.application.domain.GetHouseholdStatusCmd;
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsCount.ports.GetDailyRecordsCountPortIn;
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsCount.ports.application.domain.GetDailyRecordsCount;
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsCount.ports.application.domain.GetDailyRecordsCountCmd;
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsStatus.ports.GetDailyRecordsStatusPortIn;
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsStatus.ports.application.domain.GetDailyRecordsStatus;
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsStatus.ports.application.domain.GetDailyRecordsStatusCmd;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
@@ -18,22 +35,81 @@ import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsStatus.
@RestController
@RequiredArgsConstructor
class GetDailyRecordsStatusController {
private final GetDailyRecordsStatusPortIn getDailyRecordsStatusPortIn;
private final GetDailyRecordsCountPortIn getDailyRecordsCountPortIn;
private final GetDailyRecordsStatusPortIn getDailyRecordsStatusPortIn;
private final GetDailyRecordsCountPortIn getDailyRecordsCountPortIn;
private final GetHouseholdStatusPortIn getHouseholdStatusPortIn;
@GetMapping(path = "/api/household/dailyRecordsStatus")
ResponseEntity<?> operate(
GetDailyRecordsStatusReqVO reqVO) {
@GetMapping(path = "/api/household/dailyRecordsStatus")
ResponseEntity<?> operate(GetDailyRecordsStatusReqVO reqVO) {
List<GetDailyRecordsStatus> dailyRecords =
getDailyRecordsStatusPortIn.operate(
new GetDailyRecordsStatusCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth()));
List<GetDailyRecordsStatus> dailyRecords =
getDailyRecordsStatusPortIn.operate(
new GetDailyRecordsStatusCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth()));
GetDailyRecordsCount summary =
getDailyRecordsCountPortIn.operate(
new GetDailyRecordsCountCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth())).orElse(null);
GetDailyRecordsCount summary =
getDailyRecordsCountPortIn.operate(
new GetDailyRecordsCountCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth())).orElse(null);
return ResponseEntity.status(HttpStatus.OK)
.body(new GetDailyRecordsStatusResVO(summary, dailyRecords));
}
return ResponseEntity.status(HttpStatus.OK)
.body(new GetDailyRecordsStatusResVO(summary, dailyRecords));
}
/**
* 일계부 등록 현황 엑셀 다운로드
*
* @param reqVO 검색 조건
* @return 엑셀 파일 다운로드
*/
@GetMapping("/api/household/dailyRecordsStatus/excel")
public ResponseEntity<byte[]> exportHouseholdExcel(GetDailyRecordsStatusReqVO reqVO) {
String householdNum = "-";
String ownerName = "-";
GetHouseholdStatus householdInfo = getHouseholdStatusPortIn.operate(new GetHouseholdStatusCmd(reqVO.getHouseholdSeq())).orElse(null);
if (householdInfo != null) {
householdNum = householdInfo.getHouseholdNum();
ownerName = householdInfo.getHouseholdName();
}
List<GetDailyRecordsStatus> dailyRecords =
getDailyRecordsStatusPortIn.operate(
new GetDailyRecordsStatusCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth()));
List<List<String>> rows = new ArrayList<>();
for (GetDailyRecordsStatus record : dailyRecords) {
rows.add(List.of(householdNum, ownerName,
record.getDayGroup(),
record.getAllStatusType().getDesc(),
record.getIncomeStatus(),
record.getWorkStatus(),
record.getExpenseStatus(),
record.getPowerStatus(),
record.getForestryStatus(),
record.getFarmingStatus()));
}
// 시트 1: 등록 현황 목록
ExcelSheetDto sheet1 = new ExcelSheetDto(
"일계부 등록 현황",
List.of("임가번호", "경영주 성명", "입력 날짜", "완료상태", "수입", "노동투입", "지출", "동력사용시간", "임업 자가소비량", "농업 자가소비량"),
rows,
null,
Map.of(
0, IndexedColors.LIGHT_YELLOW
)
);
// 시트 모음
List<ExcelSheetDto> sheets = List.of(sheet1);
byte[] excel = ExcelWriterUtil.writeExcel(sheets);
String rawFileName = "02. 일계부 등록 현황[" + reqVO.getRecordMonth() + "][" + householdNum + "]_" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + ".xlsx";
String encodedFileName = URLEncoder.encode(rawFileName, StandardCharsets.UTF_8).replaceAll("\\+", "%20");
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encodedFileName)
.body(excel);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -125,7 +125,7 @@
</section>
<section>
<div class="component-tab" data-active="tab1">
<div class="component-tab" data-active="none">
<div class="tab-head">
<button type="button" class="tab-label select-tab" data-tab-type="daily-record" data-tab-value="tab1">일계부 등록 현황</button>
<button type="button" class="tab-label select-tab" data-tab-type="forest-product" data-tab-value="tab2" th:unless="${activeProfile != 'local'}">임산물 현황</button>
@@ -164,8 +164,17 @@
<span class="btn-txt">목록</span>
</button>
</div>
<div class="btns-col-2 align-right" th:unless="${activeProfile != 'local'}">
<button type="button" class="btn">
<div class="btns-col-2 align-right _excelDownload" th:unless="${activeProfile != 'local'}">
<button type="button" class="btn" data-tab-type="daily-record" data-tab-value="tab1" onclick="goExcel(this)">
<span class="btn-txt">엑셀 다운로드 <i class="ico-download" aria-hidden="true"></i></span>
</button>
<button type="button" class="btn" data-tab-type="forest-product" data-tab-value="tab2" onclick="goExcel(this)">
<span class="btn-txt">엑셀 다운로드 <i class="ico-download" aria-hidden="true"></i></span>
</button>
<button type="button" class="btn" data-tab-type="bank-auto-transfer" data-tab-value="tab3" onclick="goExcel(this)">
<span class="btn-txt">엑셀 다운로드 <i class="ico-download" aria-hidden="true"></i></span>
</button>
<button type="button" class="btn" data-tab-type="household-visit" data-tab-value="tab4" onclick="goExcel(this)">
<span class="btn-txt">엑셀 다운로드 <i class="ico-download" aria-hidden="true"></i></span>
</button>
</div>
@@ -223,12 +232,32 @@
</script>
<script>
const tabStorageName = 'tabActive';
let tabActive = 'tab1';
window.onpageshow = function (event) {
if (event.persisted || (window.performance && window.performance.navigation.type == 1)) {
if (('sessionStorage' in window) && window['sessionStorage'] !== null) {
if (sessionStorage.getItem(tabStorageName)) {
tabActive = sessionStorage.getItem(tabStorageName);
}
}
} else if (event.persisted || (window.performance && window.performance.navigation.type == 2)) {
sessionStorage.removeItem(tabStorageName);
}
}
$(document).ready(() => {
getDailyRecords();
$('._excelDownload button').hide();
setTimeout(function () {
let $tab = $('.component-tab button[data-tab-value="' + tabActive + '"]');
getTabData($tab.data('tabType'), $tab.data('tabValue'));
}, 500);
});
$('.select-tab').on('click', function () {
getTabData(this.dataset.tabType);
getTabData(this.dataset.tabType, this.dataset.tabValue);
});
</script>
@@ -241,7 +270,7 @@
getTabData(selectedTab.dataset.tabType);
}
const getTabData = (tabType) => {
const getTabData = (tabType, tabValue) => {
switch (tabType) {
case 'daily-record': // 일계부 등록 현황
getDailyRecords();
@@ -256,6 +285,13 @@
getVisitInfo();
break;
}
sessionStorage.setItem(tabStorageName, tabValue);
document.querySelector('.component-tab').ui.setValue(tabValue);
$('._excelDownload button').hide();
$('._excelDownload button[data-tab-value="' + tabValue + '"]').show();
}
</script>
@@ -362,6 +398,36 @@
}
}
</script>
<script>
// 엑셀 다운로드
const goExcel = (el) => {
let url = '';
if (el.dataset.tabValue === 'tab1') {
url = $('.tab-content .daily-record-list').is(':hidden') ? '' : '/api/household/dailyRecordsStatus/excel';
} else if (el.dataset.tabValue === 'tab2') {
url = '';
} else if (el.dataset.tabValue === 'tab3') {
url = '';
} else if (el.dataset.tabValue === 'tab4') {
url = '';
}
console.log('goExcel', el.dataset.tabValue, url);
const f = document.reqForm;
const data = $(f).serializeObject();
// size 를 제거하면 전체 목록을 가져온다.
delete data.size;
if (url !== '') {
location.href = url + '?' + new URLSearchParams(data).toString();
} else {
console.warn('엑셀 다운르도 경로 없음.')
}
}
</script>
</section>
</html>