[BO] 임가현황 등록 상세(수입, 지출) 엑셀다운로드
This commit is contained in:
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,7 @@ import lombok.Setter;
|
||||
@EqualsAndHashCode
|
||||
public class GetDailyRecordStatusDetailReqVO {
|
||||
private Long recordSeq;
|
||||
|
||||
private String recordMonth;
|
||||
private Long householdSeq;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,15 @@ import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetDailyExpenseRecords {
|
||||
private Long id;
|
||||
private String inputType;
|
||||
private String category;
|
||||
private String incomeMark;
|
||||
private String expenseMark;
|
||||
private Boolean isCredit;
|
||||
private String expenseKind;
|
||||
private String expenseKindMark;
|
||||
private String sourcePurpose;
|
||||
private String quantity;
|
||||
private String unitCode;
|
||||
@@ -22,4 +24,6 @@ public class GetDailyExpenseRecords {
|
||||
private String estimatedValue;
|
||||
private String updatedBy;
|
||||
private String updatedAt;
|
||||
private String startDay;
|
||||
private String endDay;
|
||||
}
|
||||
|
||||
@@ -8,15 +8,18 @@ import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetDailyIncomeRecords {
|
||||
private Long id;
|
||||
private String inputType;
|
||||
private String category;
|
||||
private String incomeMark;
|
||||
private String expenseMark;
|
||||
private Boolean isCredit;
|
||||
private String cropCode;
|
||||
private String cropValue;
|
||||
private String cropText;
|
||||
private String incomeKind;
|
||||
private String incomeKindMark;
|
||||
private String sourcePurpose;
|
||||
private BigDecimal quantity;
|
||||
private String unitCode;
|
||||
@@ -25,4 +28,6 @@ public class GetDailyIncomeRecords {
|
||||
private String estimatedValue;
|
||||
private String updatedBy;
|
||||
private String updatedAt;
|
||||
private String startDay;
|
||||
private String endDay;
|
||||
}
|
||||
|
||||
@@ -10,5 +10,16 @@ import lombok.Setter;
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetDailyRecordStatusCmd {
|
||||
public GetDailyRecordStatusCmd(Long recordSeq) {
|
||||
this.recordSeq = recordSeq;
|
||||
}
|
||||
|
||||
public GetDailyRecordStatusCmd(String recordMonth, Long householdSeq) {
|
||||
this.recordMonth = recordMonth;
|
||||
this.householdSeq = householdSeq;
|
||||
}
|
||||
|
||||
private Long recordSeq;
|
||||
private Long householdSeq;
|
||||
private String recordMonth;
|
||||
}
|
||||
|
||||
@@ -23,10 +23,15 @@
|
||||
/* getDailyIncomeRecords : 일계부 등록 현황 상세 수입 조회 */
|
||||
SELECT di.id, /* 수입 id */
|
||||
di.input_type, /* 입력구분 */
|
||||
di.category,
|
||||
di.income_mark,
|
||||
di.expense_mark,
|
||||
di.is_credit, /* 외상판매여부 */
|
||||
di.crop_code, /* 재배형태 코드 */
|
||||
ui_crop.code_value AS crop_value, /* 재배형태 코드 값 */
|
||||
ui_crop.code_text AS crop_text, /* 재배형태 코드 텍스트 */
|
||||
di.income_kind, /* 수입의 종류 */
|
||||
di.income_kind_mark,
|
||||
di.source_purpose, /* 수입원(용도) */
|
||||
di.quantity, /* 수량 */
|
||||
di.unit_code, /* 단위 코드 */
|
||||
@@ -39,6 +44,10 @@
|
||||
di.estimated_value, /* 현물평가액 */
|
||||
di.updated_by, /* 최종수정자 */
|
||||
TO_CHAR(di.updated_at, 'YYYY-MM-DD HH24:MI') AS updated_at /* 최종수정날짜 */
|
||||
<if test="recordSeq == null">
|
||||
, ddg.start_day
|
||||
, ddg.end_day
|
||||
</if>
|
||||
FROM daily_income di
|
||||
LEFT JOIN uicode ui_crop
|
||||
ON ui_crop.parent_id = 'code.record.crop'
|
||||
@@ -46,9 +55,21 @@
|
||||
LEFT JOIN uicode ui_unit
|
||||
ON ui_unit.parent_id = 'code.record.unit'
|
||||
AND ui_unit.id = di.unit_code
|
||||
WHERE di.daily_record_seq = #{recordSeq}
|
||||
AND di.is_deleted = false
|
||||
<if test="recordSeq == null">
|
||||
INNER JOIN daily_record dr
|
||||
ON dr.id = di.daily_record_seq
|
||||
AND dr.is_deleted = false AND dr.household_seq = #{householdSeq} AND dr.record_month = #{recordMonth}
|
||||
LEFT JOIN daily_day_group ddg
|
||||
ON ddg.group_no = dr.day_group_no
|
||||
</if>
|
||||
WHERE di.is_deleted = false
|
||||
<if test="recordSeq != null">
|
||||
AND di.daily_record_seq = #{recordSeq}
|
||||
ORDER BY di.created_at
|
||||
</if>
|
||||
<if test="recordSeq == null">
|
||||
ORDER BY ddg.start_day asc, di.created_at asc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getDailyWorkRecords"
|
||||
@@ -98,8 +119,12 @@
|
||||
/* getDailyExpenseRecords : 일계부 등록 현황 상세 지출 조회 */
|
||||
SELECT de.id, /* 지출 id */
|
||||
de.input_type, /* 입력구분 */
|
||||
de.category,
|
||||
de.income_mark,
|
||||
de.expense_mark,
|
||||
de.is_credit, /* 외상판매여부 */
|
||||
de.expense_kind, /* 지출 종류 */
|
||||
de.expense_kind_mark,
|
||||
de.source_purpose, /* 지출원(용도) */
|
||||
de.quantity, /* 수량 */
|
||||
de.unit_code, /* 단위 */
|
||||
@@ -112,13 +137,29 @@
|
||||
de.estimated_value, /* 현물평가액 */
|
||||
de.updated_by, /* 최종수정자 */
|
||||
TO_CHAR(de.updated_at, 'YYYY-MM-DD HH24:MI') AS updated_at /* 최종수정날짜 */
|
||||
<if test="recordSeq == null">
|
||||
, ddg.start_day
|
||||
, ddg.end_day
|
||||
</if>
|
||||
FROM daily_expense de
|
||||
LEFT JOIN uicode ui_unit
|
||||
ON ui_unit.parent_id = 'code.record.unit'
|
||||
AND ui_unit.id = de.unit_code
|
||||
WHERE de.daily_record_seq = #{recordSeq}
|
||||
AND de.is_deleted = false
|
||||
<if test="recordSeq == null">
|
||||
INNER JOIN daily_record dr
|
||||
ON dr.id = de.daily_record_seq
|
||||
AND dr.is_deleted = false AND dr.household_seq = #{householdSeq} AND dr.record_month = #{recordMonth}
|
||||
LEFT JOIN daily_day_group ddg
|
||||
ON ddg.group_no = dr.day_group_no
|
||||
</if>
|
||||
WHERE de.is_deleted = false
|
||||
<if test="recordSeq != null">
|
||||
AND de.daily_record_seq = #{recordSeq}
|
||||
ORDER BY de.created_at
|
||||
</if>
|
||||
<if test="recordSeq == null">
|
||||
ORDER BY ddg.start_day asc, de.created_at asc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getDailyPowerRecords"
|
||||
|
||||
@@ -404,7 +404,7 @@
|
||||
const goExcel = (el) => {
|
||||
let url = '';
|
||||
if (el.dataset.tabValue === 'tab1') {
|
||||
url = $('.tab-content .daily-record-list').is(':hidden') ? '' : '/api/household/dailyRecordsStatus/excel';
|
||||
url = $('.tab-content .daily-record-list').is(':hidden') ? '/api/household/dailyRecordStatus/excel' : '/api/household/dailyRecordsStatus/excel';
|
||||
} else if (el.dataset.tabValue === 'tab2') {
|
||||
url = '';
|
||||
} else if (el.dataset.tabValue === 'tab3') {
|
||||
|
||||
Reference in New Issue
Block a user