|
|
|
|
@@ -1,27 +1,164 @@
|
|
|
|
|
package app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordStatusDetail.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.getDailyRecordStatusDetail.adapters.web.model.GetDailyRecordStatusDetailReqVO;
|
|
|
|
|
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordStatusDetail.ports.GetDailyRecordStatusDetailPortIn;
|
|
|
|
|
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordStatusDetail.ports.application.domain.GetDailyExpenseRecords;
|
|
|
|
|
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordStatusDetail.ports.application.domain.GetDailyIncomeRecords;
|
|
|
|
|
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordStatusDetail.ports.application.domain.GetDailyRecordStatusDetail;
|
|
|
|
|
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordStatusDetail.ports.application.domain.GetDailyRecordStatusCmd;
|
|
|
|
|
import app.module.admin.usecase.household.tab.dailyRecord.getDailyRecordsStatus.adapters.web.model.GetDailyRecordsStatusReqVO;
|
|
|
|
|
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 lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
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.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
class GetDailyRecordStatusDetailController {
|
|
|
|
|
private final GetDailyRecordStatusDetailPortIn portIn;
|
|
|
|
|
private final GetDailyRecordStatusDetailPortIn portIn;
|
|
|
|
|
private final GetHouseholdStatusPortIn getHouseholdStatusPortIn;
|
|
|
|
|
|
|
|
|
|
@GetMapping(path = "/api/household/dailyRecordStatus")
|
|
|
|
|
ResponseEntity<GetDailyRecordStatusDetail> operate(
|
|
|
|
|
GetDailyRecordStatusDetailReqVO reqVO) {
|
|
|
|
|
@GetMapping(path = "/api/household/dailyRecordStatus")
|
|
|
|
|
ResponseEntity<GetDailyRecordStatusDetail> operate(
|
|
|
|
|
GetDailyRecordStatusDetailReqVO reqVO) {
|
|
|
|
|
|
|
|
|
|
GetDailyRecordStatusDetail recordView =
|
|
|
|
|
portIn.operate(new GetDailyRecordStatusCmd(reqVO.getRecordSeq())).orElse(null);
|
|
|
|
|
GetDailyRecordStatusDetail recordView =
|
|
|
|
|
portIn.operate(new GetDailyRecordStatusCmd(reqVO.getRecordSeq())).orElse(null);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(recordView);
|
|
|
|
|
}
|
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(recordView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 일계부 상세 현황 엑셀 다운로드
|
|
|
|
|
*
|
|
|
|
|
* @param reqVO 검색 조건
|
|
|
|
|
* @return 엑셀 파일 다운로드
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/api/household/dailyRecordStatus/excel")
|
|
|
|
|
public ResponseEntity<byte[]> exportHouseholdExcel(GetDailyRecordStatusDetailReqVO reqVO) {
|
|
|
|
|
|
|
|
|
|
String householdNum = "-";
|
|
|
|
|
String ownerName = "-";
|
|
|
|
|
GetHouseholdStatus householdInfo = getHouseholdStatusPortIn.operate(new GetHouseholdStatusCmd(reqVO.getHouseholdSeq())).orElse(null);
|
|
|
|
|
if (householdInfo != null) {
|
|
|
|
|
householdNum = householdInfo.getHouseholdNum();
|
|
|
|
|
ownerName = householdInfo.getHouseholdName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetDailyRecordStatusDetail recordView =
|
|
|
|
|
portIn.operate(new GetDailyRecordStatusCmd(reqVO.getRecordMonth(), reqVO.getHouseholdSeq())).orElse(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 시트 1: 등록 현황 목록
|
|
|
|
|
ExcelSheetDto sheet1 = this.getIncomeSheet(recordView, householdNum, ownerName);
|
|
|
|
|
ExcelSheetDto sheet2 = this.getExpenseSheet(recordView, householdNum, ownerName);
|
|
|
|
|
|
|
|
|
|
// 시트 모음
|
|
|
|
|
List<ExcelSheetDto> sheets = List.of(sheet1, sheet2);
|
|
|
|
|
|
|
|
|
|
byte[] excel = ExcelWriterUtil.writeExcel(sheets);
|
|
|
|
|
|
|
|
|
|
String rawFileName = "03. 일계부 등록 내용[" + 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ExcelSheetDto getIncomeSheet(GetDailyRecordStatusDetail recordView, String householdNum, String ownerName) {
|
|
|
|
|
List<List<String>> rows = new ArrayList<>();
|
|
|
|
|
if (recordView != null && !recordView.getIncomes().isEmpty()) {
|
|
|
|
|
for (GetDailyIncomeRecords record : recordView.getIncomes()) {
|
|
|
|
|
List<String> row = new ArrayList<>(List.of(householdNum, ownerName,
|
|
|
|
|
record.getStartDay(),
|
|
|
|
|
record.getEndDay(),
|
|
|
|
|
StringUtils.defaultString(record.getCategory()),
|
|
|
|
|
StringUtils.defaultString(record.getIncomeMark()),
|
|
|
|
|
StringUtils.defaultString(record.getExpenseMark())));
|
|
|
|
|
|
|
|
|
|
row.add(StringUtils.defaultString(record.getCropValue()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getIncomeKind()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getIncomeKindMark()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getSourcePurpose()));
|
|
|
|
|
row.add(record.getQuantity() != null ? StringUtils.defaultString(record.getQuantity().toString()) : "");
|
|
|
|
|
row.add(StringUtils.defaultString(record.getUnitText()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getPrice()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getEstimatedValue()));
|
|
|
|
|
|
|
|
|
|
rows.add(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new ExcelSheetDto(
|
|
|
|
|
"수입",
|
|
|
|
|
List.of("임가번호", "경영주 성명", "날", "짜", "유형", "수입 부호", "지출 부호", "재배형태 코드", "수입의 종류", "종류 부호", "수입원", "수량", "단위", "현금(원)", "현물(평가액)"),
|
|
|
|
|
rows,
|
|
|
|
|
Set.of(11, 13, 14),
|
|
|
|
|
Map.of(
|
|
|
|
|
0, IndexedColors.LIGHT_YELLOW,
|
|
|
|
|
2, IndexedColors.LIGHT_TURQUOISE,
|
|
|
|
|
3, IndexedColors.LIGHT_TURQUOISE
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ExcelSheetDto getExpenseSheet(GetDailyRecordStatusDetail recordView, String householdNum, String ownerName) {
|
|
|
|
|
List<List<String>> rows = new ArrayList<>();
|
|
|
|
|
if (recordView != null && !recordView.getExpenses().isEmpty()) {
|
|
|
|
|
for (GetDailyExpenseRecords record : recordView.getExpenses()) {
|
|
|
|
|
List<String> row = new ArrayList<>(List.of(householdNum, ownerName,
|
|
|
|
|
record.getStartDay(),
|
|
|
|
|
record.getEndDay(),
|
|
|
|
|
StringUtils.defaultString(record.getCategory()),
|
|
|
|
|
StringUtils.defaultString(record.getIncomeMark()),
|
|
|
|
|
StringUtils.defaultString(record.getExpenseMark())));
|
|
|
|
|
|
|
|
|
|
row.add(StringUtils.defaultString(record.getExpenseKind()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getExpenseKindMark()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getSourcePurpose()));
|
|
|
|
|
row.add(record.getQuantity() != null ? StringUtils.defaultString(record.getQuantity().toString()) : "");
|
|
|
|
|
row.add(StringUtils.defaultString(record.getUnitText()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getPrice()));
|
|
|
|
|
row.add(StringUtils.defaultString(record.getEstimatedValue()));
|
|
|
|
|
|
|
|
|
|
rows.add(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new ExcelSheetDto(
|
|
|
|
|
"지출",
|
|
|
|
|
List.of("임가번호", "경영주 성명", "날", "짜", "유형", "수입 부호", "지출 부호", "지출의 종류", "종류 부호", "용도", "수량", "단위", "현금(원)", "현물(평가액)"),
|
|
|
|
|
rows,
|
|
|
|
|
Set.of(10, 12, 13),
|
|
|
|
|
Map.of(
|
|
|
|
|
0, IndexedColors.LIGHT_YELLOW,
|
|
|
|
|
2, IndexedColors.LIGHT_TURQUOISE,
|
|
|
|
|
3, IndexedColors.LIGHT_TURQUOISE
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|