[BO] 임가현황, 조사원현황 엑셀 다운로드 작업 중 (1)

This commit is contained in:
kangsunlee
2025-07-04 09:56:03 +09:00
parent 38a9ca2997
commit f53cab803b
23 changed files with 692 additions and 70 deletions

View File

@@ -0,0 +1,12 @@
package app.module.admin.config.application.enums;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum UsageType {
MOBILE("모바일"),
PAPER("지류");
private final String desc;
}

View File

@@ -1,52 +1,163 @@
package app.module.admin.usecase.household.getHouseholdsStatus.adapters.web;
import app.module.admin.config.application.enums.ManagementType;
import app.module.admin.config.application.enums.UsageType;
import app.module.admin.config.application.util.AdminUtil;
import app.module.admin.config.application.util.ExcelWriterUtil;
import app.module.admin.config.application.util.model.ExcelSheetDto;
import app.module.admin.usecase.household.getHouseholdsStatus.adapters.web.model.GetHouseholdsStatusReqVO;
import app.module.admin.usecase.household.getHouseholdsStatus.ports.GetHouseholdsStatusPortIn;
import app.module.admin.usecase.household.getHouseholdsStatus.ports.application.domain.GetHouseholdsStatus;
import app.module.admin.usecase.household.getHouseholdsStatus.ports.application.domain.GetHouseholdsStatusCmd;
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.Optional;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
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;
import app.module.admin.usecase.household.getHouseholdsStatus.adapters.web.model.GetHouseholdsStatusReqVO;
import app.module.admin.usecase.household.getHouseholdsStatus.adapters.web.model.GetHouseholdsStatusResVO;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
class GetHouseholdsStatusController {
private final GetHouseholdsStatusPortIn portIn;
private final GetHouseholdsStatusPortIn portIn;
@GetMapping(path = "/api/households")
ResponseEntity<Page<GetHouseholdsStatus>> operate(
@PageableDefault(size = 10) Pageable pageable,
GetHouseholdsStatusReqVO reqVO) {
return ResponseEntity.status(HttpStatus.OK).body(
@GetMapping(path = "/api/households")
ResponseEntity<Page<GetHouseholdsStatus>> operate(@PageableDefault(size = 10) Pageable pageable,
GetHouseholdsStatusReqVO reqVO) {
return ResponseEntity.status(HttpStatus.OK).body(
portIn.operate(pageable,
new GetHouseholdsStatusCmd(
reqVO.getRecordMonth(),
reqVO.getOwnerField(),
reqVO.getOwnerValue(),
reqVO.getRegionMainCode(),
reqVO.getRegionSubCode(),
reqVO.getRegionDetailCode(),
reqVO.getIndustryLargeCode(),
reqVO.getIndustryMiddleCode(),
reqVO.getProgressType() != null ? reqVO.getProgressType().name() : null,
reqVO.getIsFirstVisited(),
reqVO.getIsSecondVisited(),
reqVO.getIsGiftSent(),
reqVO.getResearcherField(),
reqVO.getResearcherValue(),
reqVO.getIsPanel(),
AdminUtil.getLoginUserSeq(),
reqVO.getUserRole(),
reqVO.getUserRegionMainCode(),
Boolean.TRUE)));
}
portIn.operate(pageable,
new GetHouseholdsStatusCmd(
reqVO.getRecordMonth(),
reqVO.getOwnerField(),
reqVO.getOwnerValue(),
reqVO.getRegionMainCode(),
reqVO.getRegionSubCode(),
reqVO.getRegionDetailCode(),
reqVO.getIndustryLargeCode(),
reqVO.getIndustryMiddleCode(),
reqVO.getProgressType() != null ? reqVO.getProgressType().name() : null,
reqVO.getIsFirstVisited(),
reqVO.getIsSecondVisited(),
reqVO.getIsGiftSent(),
reqVO.getResearcherField(),
reqVO.getResearcherValue(),
reqVO.getIsPanel(),
AdminUtil.getLoginUserSeq(),
reqVO.getUserRole(),
reqVO.getUserRegionMainCode()
))
);
}
/**
* 임가현황 엑셀 다운로드
*
* @param reqVO 검색 조건
* @return 엑셀 파일 다운로드
*/
@GetMapping(path = "/api/households/excel")
ResponseEntity<byte[]> exportHouseholdsExcel(Pageable pageable,
GetHouseholdsStatusReqVO reqVO) {
Page<GetHouseholdsStatus> households =
portIn.operate(pageable,
new GetHouseholdsStatusCmd(
reqVO.getRecordMonth(),
reqVO.getOwnerField(),
reqVO.getOwnerValue(),
reqVO.getRegionMainCode(),
reqVO.getRegionSubCode(),
reqVO.getRegionDetailCode(),
reqVO.getIndustryLargeCode(),
reqVO.getIndustryMiddleCode(),
reqVO.getProgressType() != null ? reqVO.getProgressType().name() : null,
reqVO.getIsFirstVisited(),
reqVO.getIsSecondVisited(),
reqVO.getIsGiftSent(),
reqVO.getResearcherField(),
reqVO.getResearcherValue(),
reqVO.getIsPanel(),
AdminUtil.getLoginUserSeq(),
reqVO.getUserRole(),
reqVO.getUserRegionMainCode(),
Boolean.FALSE)); // 임가 전체 목록을 가져온다.
List<List<String>> rows = new ArrayList<>();
for(GetHouseholdsStatus item : households.getContent()) {
rows.add(List.of(
item.getHouseholdNum(),
item.getHouseholdName(),
StringUtils.defaultString(item.getOwnerAge().toString()),
StringUtils.defaultString(item.getHouseholdPhone()),
StringUtils.defaultString(item.getRegionMainName()),
StringUtils.defaultString(item.getRegionSubName()),
StringUtils.defaultString(item.getRegionDetailName()),
StringUtils.defaultString(item.getAddress()),
StringUtils.defaultString(item.getIndustryLargeName()),
StringUtils.defaultString(item.getIndustryMiddleName()),
StringUtils.defaultString(item.getIndustrySubMiddle()),
StringUtils.defaultString(item.getIndustryDetail()),
StringUtils.defaultString(item.getProgressPercent().toString()) + "%",
StringUtils.defaultString(item.getFirstVisitDate()),
StringUtils.defaultString(item.getSecondVisitDate()),
item.getIsGiftSent() ? "전달" : "미전달",
StringUtils.defaultString(item.getResearcherName()),
StringUtils.defaultString(item.getResearcherPhone()),
item.getUsageType() != null ? UsageType.valueOf(item.getUsageType()).getDesc() : "",
item.getIsPanel() ? "1. 유지" : "2. 탈락"
));
}
// 시트 1: 임가 목록
ExcelSheetDto sheet1 = new ExcelSheetDto("임가 목록",
List.of(
"임가번호",
"경영주 성명",
"연령",
"연락처",
"실사",
"지역",
"세부지역",
"전체 주소",
"업종_대분류",
"업종_중분류1",
"업종_중분류2",
"규모/세부품목",
"당월 일계부 현황",
"당월 1차 임가방문",
"당월 2차 임가방문",
"답례품 전달",
"조사원",
"조사원 연락처",
"이용 구분",
"유지여부"),
rows,
null,
Map.of(0, IndexedColors.LIGHT_YELLOW));
List<ExcelSheetDto> sheets = List.of(sheet1);
byte[] excel = ExcelWriterUtil.writeExcel(sheets);
String rawFileName = "01. 임가 목록[" + reqVO.getRecordMonth() + "]_" + 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);
}
}

View File

@@ -28,5 +28,10 @@ public class GetHouseholdsStatus {
private Boolean isGiftSent;
private String researcherName;
private String researcherPhone;
private Integer ownerAge;
private String address;
private String industrySubMiddle;
private String industryDetail;
private String usageType;
private Integer total;
}

View File

@@ -46,4 +46,6 @@ public class GetHouseholdsStatusCmd {
private String userRole;
// 로그인한 유저 실사 지역
private String userRegionMainCode;
// 페이징처리 여부
private Boolean isPaging;
}

View File

@@ -1,23 +1,128 @@
package app.module.admin.usecase.household.tab.bankAutoTransfer.getBankAutoTransferRecords.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.bankAutoTransfer.getBankAutoTransferRecords.adapters.web.model.GetAutoTransferRecordsReqVO;
import app.module.admin.usecase.household.tab.bankAutoTransfer.getBankAutoTransferRecords.ports.GetBankAutoTransferRecordsPortIn;
import app.module.admin.usecase.household.tab.bankAutoTransfer.getBankAutoTransferRecords.ports.application.domain.GetBankAutoTransferExpenseRecords;
import app.module.admin.usecase.household.tab.bankAutoTransfer.getBankAutoTransferRecords.ports.application.domain.GetBankAutoTransferIncomeRecords;
import app.module.admin.usecase.household.tab.bankAutoTransfer.getBankAutoTransferRecords.ports.application.domain.GetBankAutoTransferRecords;
import app.module.admin.usecase.household.tab.bankAutoTransfer.getBankAutoTransferRecords.ports.application.domain.GetBankAutoTransferRecordsCmd;
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.Collections;
import java.util.List;
import java.util.Map;
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.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import app.module.admin.usecase.household.tab.bankAutoTransfer.getBankAutoTransferRecords.adapters.web.model.GetAutoTransferRecordsReqVO;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
class GetBankAutoTransferRecordsController {
private final GetBankAutoTransferRecordsPortIn portIn;
private final GetHouseholdStatusPortIn getHouseholdStatusPortIn;
@GetMapping(path = "/api/household/bankAutoTransfer")
ResponseEntity<GetBankAutoTransferRecords> operate(GetAutoTransferRecordsReqVO reqVO) {
return ResponseEntity.status(HttpStatus.OK).body(portIn.operate(
new GetBankAutoTransferRecordsCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth())));
}
/**
* 은행자동이체내역 엑셀 다운로드
*
* @param reqVO 검색 조건
* @return 엑셀 파일 다운로드
*/
@GetMapping("/api/household/bankAutoTransfer/excel")
public ResponseEntity<byte[]> exportBankExcel(GetAutoTransferRecordsReqVO reqVO) {
String householdNum = "-";
String ownerName = "-";
GetHouseholdStatus householdInfo = getHouseholdStatusPortIn.operate(new GetHouseholdStatusCmd(reqVO.getHouseholdSeq())).orElse(null);
if (householdInfo != null) {
householdNum = householdInfo.getHouseholdNum();
ownerName = householdInfo.getHouseholdName();
}
GetBankAutoTransferRecords bankRecords =
portIn.operate(new GetBankAutoTransferRecordsCmd(
reqVO.getHouseholdSeq(), reqVO.getRecordMonth()));
List<List<String>> rowsIncome = new ArrayList<>();
for(GetBankAutoTransferIncomeRecords record : bankRecords.getIncomes()) {
rowsIncome.add(List.of(
householdNum, // 임가번호
ownerName, // 경영주 성명
StringUtils.defaultString(record.getCategory()), // 유형
StringUtils.defaultString(record.getIncomeCode()), // 수입 부호
StringUtils.defaultString(record.getExpenseCode()), // 지출 부호
StringUtils.defaultString(record.getCropValue()), // 재배형태 코드
StringUtils.defaultString(record.getCategoryText()), // 수입의 종류
StringUtils.defaultString(record.getTarget()), // 대상
StringUtils.defaultString(record.getSourcePurpose()), // 수입원
StringUtils.defaultString(record.getCount()), // 수량
StringUtils.defaultString(record.getUnitText()), // 단위
StringUtils.defaultString(record.getPrice().toString()))); // 현금(원)
}
// 시트 1: 수입 목록
ExcelSheetDto sheet1 = new ExcelSheetDto(
"수입",
List.of("임가번호", "경영주 성명", "유형", "수입 부호", "지출 부호", "재배형태 코드", "수입의 종류", "대상", "수입원", "수량", "단위", "현금(원)"),
rowsIncome,
Collections.singleton(11),
Map.of(0, IndexedColors.LIGHT_YELLOW)
);
List<List<String>> rowsExpense = new ArrayList<>();
for(GetBankAutoTransferExpenseRecords record : bankRecords.getExpenses()) {
rowsExpense.add(List.of(
householdNum, // 임가번호
ownerName, // 경영주 성명
StringUtils.defaultString(record.getCategory()), // 유형
StringUtils.defaultString(record.getIncomeCode()), // 수입 부호
StringUtils.defaultString(record.getExpenseCode()), // 지출 부호
StringUtils.defaultString(record.getCategoryText()), // 지출의 종류
StringUtils.defaultString(record.getSourcePurpose()), // 용도
StringUtils.defaultString(record.getCount()), // 수량
StringUtils.defaultString(record.getUnitText()), // 단위
StringUtils.defaultString(record.getPrice().toString()))); // 현금(원)
}
// 시트 2: 지출 목록
ExcelSheetDto sheet2 = new ExcelSheetDto(
"지출",
List.of("임가번호", "경영주 성명", "유형", "수입 부호", "지출 부호", "지출의 종류", "용도", "수량", "단위", "현금(원)"),
rowsExpense,
Collections.singleton(9),
Map.of(0, IndexedColors.LIGHT_YELLOW)
);
// 시트 모음
List<ExcelSheetDto> sheets = List.of(sheet1, sheet2);
byte[] excel = ExcelWriterUtil.writeExcel(sheets);
String rawFileName = "04. 은행 자동이체 내역[" + 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);
}
}

View File

@@ -11,6 +11,9 @@ import lombok.Setter;
@EqualsAndHashCode
public class GetBankAutoTransferExpenseRecords {
private Long id;
private String category;
private String incomeCode;
private String expenseCode;
private String categoryText;
private String sourcePurpose;
private String count;

View File

@@ -18,4 +18,8 @@ public class GetBankAutoTransferIncomeRecords {
private String count;
private String unitText;
private Integer price;
private String category;
private String incomeCode;
private String expenseCode;
private String cropValue;
}

View File

@@ -1,25 +1,124 @@
package app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.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.forestProduct.getForestProductsStatus.adapters.web.model.GetForestProductsStatusReqVO;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.GetForestProductsStatusPortIn;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetForestProductsStatus;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetForestProductsStatusCmd;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.ports.application.domain.GetForestProductsStatusResult;
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 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.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import app.module.admin.usecase.household.tab.forestProduct.getForestProductsStatus.adapters.web.model.GetForestProductsStatusReqVO;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
class GetForestProductsStatusController {
private final GetForestProductsStatusPortIn portIn;
@GetMapping(path = "/api/household/forestProducts")
ResponseEntity<GetForestProductsStatusResult> operate(
GetForestProductsStatusReqVO reqVO) {
return ResponseEntity.status(HttpStatus.OK)
.body(portIn.operate(
private final GetForestProductsStatusPortIn portIn;
private final GetHouseholdStatusPortIn getHouseholdStatusPortIn;
@GetMapping(path = "/api/household/forestProducts")
ResponseEntity<GetForestProductsStatusResult> operate(GetForestProductsStatusReqVO reqVO) {
return ResponseEntity.status(HttpStatus.OK).body(portIn.operate(
new GetForestProductsStatusCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth())));
}
}
/**
* 임산물현황 엑셀 다운로드
*
* @param reqVO 검색 조건
* @return 엑셀 파일 다운로드
*/
@GetMapping("/api/household/forestProduct/excel")
public ResponseEntity<byte[]> exportForestExcel(GetForestProductsStatusReqVO reqVO) {
String householdNum = "-";
String ownerName = "-";
GetHouseholdStatus householdInfo = getHouseholdStatusPortIn
.operate(new GetHouseholdStatusCmd(reqVO.getHouseholdSeq())).orElse(null);
if (householdInfo != null) {
householdNum = householdInfo.getHouseholdNum();
ownerName = householdInfo.getHouseholdName();
}
GetForestProductsStatusResult forestRecords =
portIn.operate(
new GetForestProductsStatusCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth()));
List<List<String>> rows = new ArrayList<>();
for (GetForestProductsStatus record : forestRecords.getForestProducts()) {
rows.add(List.of(
householdNum,
ownerName,
StringUtils.defaultString(record.getStreetNum()),
StringUtils.defaultString(record.getLandType()),
StringUtils.defaultString(record.getTown()),
StringUtils.defaultString(record.getAvailableArea()),
StringUtils.defaultString(record.getCropName()),
StringUtils.defaultString(record.getCropeCode()),
StringUtils.defaultString(record.getLandArea()),
StringUtils.defaultString(record.getMainYield()),
StringUtils.defaultString(record.getMainYieldUnitText()),
StringUtils.defaultString(record.getMainSaleAmount()),
StringUtils.defaultString(record.getMainSaleAmountUnitText()),
StringUtils.defaultString(record.getSubYield()),
StringUtils.defaultString(record.getSubYieldUnitText()),
StringUtils.defaultString(record.getSubSaleAmount()),
StringUtils.defaultString(record.getSubSaleAmountUnitText())
));
}
// 시트 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 = "05. 임산물 현황[" + 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);
}
}

View File

@@ -16,6 +16,7 @@ public class GetForestProductsStatus {
private String town;
private String availableArea;
private String cropName;
private String cropeCode;
private String landArea;
private String mainYield;
private String mainYieldUnitText;

View File

@@ -1,25 +1,106 @@
package app.module.admin.usecase.household.tab.householdVisit.getHouseholdVisitInfos.adapters.web;
import app.module.admin.config.application.enums.ManagementType;
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.forestProduct.getForestProductsStatus.adapters.web.model.GetForestProductsStatusReqVO;
import app.module.admin.usecase.household.tab.householdVisit.getHouseholdVisitInfos.adapters.web.model.GetHouseholdVisitInfosReqVO;
import app.module.admin.usecase.household.tab.householdVisit.getHouseholdVisitInfos.ports.GetHouseholdVisitInfosPortIn;
import app.module.admin.usecase.household.tab.householdVisit.getHouseholdVisitInfos.ports.application.domain.GetHouseholdVisitInfos;
import app.module.admin.usecase.household.tab.householdVisit.getHouseholdVisitInfos.ports.application.domain.GetHouseholdVisitInfosCmd;
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.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
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;
import app.module.admin.usecase.household.tab.householdVisit.getHouseholdVisitInfos.adapters.web.model.GetHouseholdVisitInfosReqVO;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
class GetHouseholdVisitInfosController {
private final GetHouseholdVisitInfosPortIn portIn;
@GetMapping(path = "/api/household/visitInfos")
ResponseEntity<List<GetHouseholdVisitInfos>> operate(
GetHouseholdVisitInfosReqVO reqVO) {
return ResponseEntity.status(HttpStatus.OK).body(portIn.operate(
new GetHouseholdVisitInfosCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth())));
}
private final GetHouseholdVisitInfosPortIn portIn;
private final GetHouseholdStatusPortIn getHouseholdStatusPortIn;
@GetMapping(path = "/api/household/visitInfos")
ResponseEntity<List<GetHouseholdVisitInfos>> operate(GetHouseholdVisitInfosReqVO reqVO) {
return ResponseEntity.status(HttpStatus.OK).body(portIn.operate(
new GetHouseholdVisitInfosCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth())));
}
/**
* 임가방문정보 엑셀 다운로드
*
* @param reqVO 검색 조건
* @return 엑셀 파일 다운로드
*/
@GetMapping("/api/household/visitInfos/excel")
public ResponseEntity<byte[]> exportVisitExcel(GetForestProductsStatusReqVO 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<GetHouseholdVisitInfos> visitInfos = portIn.operate(
new GetHouseholdVisitInfosCmd(reqVO.getHouseholdSeq(), reqVO.getRecordMonth()));
List<List<String>> rows = new ArrayList<>();
for (GetHouseholdVisitInfos record : visitInfos) {
rows.add(List.of(
householdNum,
ownerName,
record.getVisitDate(),
Optional.ofNullable(ManagementType.from(record.getManagementType()))
.map(ManagementType::getDesc).orElse(""),
record.getContent(),
record.getUpdatedBy() + " (" + record.getUpdatedAt() + ")",
record.getIsGiftSent() ? "전달" : "미전달"
));
}
// 시트 1: 임가방문정보 목록
ExcelSheetDto sheet1 = new ExcelSheetDto("임가방문정보",
List.of(
"임가번호",
"경영주 성명",
"방문일",
"관리분야",
"내용",
"최종 작성자",
"답례품 전달"),
rows,
Collections.singleton(11),
Map.of(0, IndexedColors.LIGHT_YELLOW));
List<ExcelSheetDto> sheets = List.of(sheet1);
byte[] excel = ExcelWriterUtil.writeExcel(sheets);
String rawFileName = "06. 임가방문정보[" + 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);
}
}

View File

@@ -14,4 +14,11 @@ public class ResearchersMappingHouseholdDto {
private String industryLargeCodeName;
private String industryMiddleCodeName;
private String panelFlag;
private Integer ownerAge;
private String address;
private String industrySubMiddle;
private String industryDetail;
private String usageType;
private String researcherName;
private String researcherPhone;
}

View File

@@ -1,11 +1,28 @@
package app.module.admin.usecase.researcher.adpaters.web;
import app.module.admin.config.application.enums.UsageType;
import app.module.admin.config.application.util.AdminUtil;
import app.module.admin.config.application.util.ExcelWriterUtil;
import app.module.admin.config.application.util.model.ExcelSheetDto;
import app.module.admin.usecase.researcher.adpaters.persistence.model.ResearchersDto;
import app.module.admin.usecase.researcher.adpaters.persistence.model.ResearchersMappingHouseholdDto;
import app.module.admin.usecase.researcher.adpaters.web.model.*;
import app.module.admin.usecase.researcher.ports.ResearcherPortIn;
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.Collections;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.data.domain.Page;
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.*;
@@ -65,4 +82,110 @@ class ResearcherApiController {
return ResponseEntity.status(HttpStatus.OK).body(researcherPortIn.updateMappingHousehold(reqVO));
}
@GetMapping(path = "/list/excel")
ResponseEntity<byte[]> exportResearchersExcel(@ModelAttribute("reqVO") ResearchersListReqVO reqVO) {
Page<ResearchersDto> researchers = researcherPortIn.list(reqVO);
List<List<String>> rows = new ArrayList<>();
for(ResearchersDto item : researchers.getContent()) {
rows.add(List.of(
StringUtils.defaultString(item.getId()),
StringUtils.defaultString(item.getName()),
StringUtils.defaultString(item.getPhone()),
StringUtils.defaultString(item.getRegionMainCodeName()),
StringUtils.defaultString(item.getAccountDisabledFlag())
));
}
// 시트 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 = "07. 조사원 목록" + "_" + 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);
}
@GetMapping(path = "/mappingHouseholdList/excel")
ResponseEntity<?> exportMappingHouseholdsExcel(@ModelAttribute ResearchersDetailReqVO reqVO) {
Page<ResearchersMappingHouseholdDto> mappingHouseholds =
researcherPortIn.mappingHouseholdList(reqVO);
List<List<String>> rows = new ArrayList<>();
for(ResearchersMappingHouseholdDto item : mappingHouseholds.getContent()) {
rows.add(List.of(
StringUtils.defaultString(item.getHouseholdNum()),
StringUtils.defaultString(item.getOwnerName()),
StringUtils.defaultString(item.getOwnerAge().toString()),
StringUtils.defaultString(item.getPhone()),
StringUtils.defaultString(item.getRegionMainCodeName()),
StringUtils.defaultString(item.getRegionSubCodeName()),
StringUtils.defaultString(item.getRegionDetailCodeName()),
StringUtils.defaultString(item.getAddress()),
StringUtils.defaultString(item.getIndustryLargeCodeName()),
StringUtils.defaultString(item.getIndustryMiddleCodeName()),
StringUtils.defaultString(item.getIndustrySubMiddle()),
StringUtils.defaultString(item.getIndustryDetail()),
StringUtils.defaultString(item.getResearcherName()),
StringUtils.defaultString(item.getResearcherPhone()),
item.getUsageType() != null ? UsageType.valueOf(item.getUsageType()).getDesc() : "",
StringUtils.defaultString(item.getPanelFlag())
));
}
// 시트 1: 임가 목록
ExcelSheetDto sheet1 = new ExcelSheetDto(
"임가 목록",
List.of(
"임가번호",
"경영주 성명",
"연령",
"연락처",
"실사",
"지역",
"세부지역",
"전체 주소",
"업종_대분류",
"업종_중분류1",
"업종_중분류2",
"규모/세부품목",
"조사원",
"조사원 연락처",
"이용 구분",
"유지여부"),
rows,
null,
Map.of(0, IndexedColors.LIGHT_YELLOW)
);
// 시트 모음
List<ExcelSheetDto> sheets = List.of(sheet1);
byte[] excel = ExcelWriterUtil.writeExcel(sheets);
String rawFileName = "08. 담당 임가 목록" + "_" + 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);
}
}

View File

@@ -10,6 +10,7 @@ public class ResearchersDetailReqVO {
private Integer size;
private Integer seq;
private String searchMonth;
private Boolean isPaging;
public Integer getPage() {
// 요청 페이지 넘버 - 초기값 `0`

View File

@@ -17,6 +17,7 @@ public class ResearchersListReqVO {
private String searchValue;
private String searchArea;
private String searchAccountDisabled;
private Boolean isPaging;
public Integer getPage() {
// 요청 페이지 넘버 - 초기값 `0`