Merge branch 'bo_household_researcher_excel' into 'dev'

Bo household researcher excel

See merge request korea-research/korea-research!79
This commit is contained in:
이강선 매니저/ST
2025-07-04 01:41:55 +00:00
24 changed files with 751 additions and 73 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,109 @@
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,
2, IndexedColors.LIGHT_TURQUOISE
));
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

@@ -15,5 +15,6 @@ public class ResearchersHouseholdVisitDto {
private ManagementType managementType;
private String content;
private String isGiftSentFlag;
private LocalDateTime createdAt;
private String updatedAt;
private String updatedBy;
}

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,29 @@
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.ResearchersHouseholdVisitDto;
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 +83,160 @@ 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<byte[]> 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);
}
@GetMapping(path = "/visitHousehold/list/excel")
ResponseEntity<byte[]> exportVisitHouseholdExcel(@ModelAttribute ResearchersDetailReqVO reqVO) {
List<ResearchersHouseholdVisitDto> visitInfos = researcherPortIn.visitHouseholdList(reqVO);
List<List<String>> rows = new ArrayList<>();
for(ResearchersHouseholdVisitDto item : visitInfos) {
rows.add(List.of(
StringUtils.defaultString(item.getHouseholdNum()),
StringUtils.defaultString(item.getOwnerName()),
StringUtils.defaultString(item.getVisitDate()),
item.getManagementType() != null ? item.getManagementType().getDesc() : "",
StringUtils.defaultString(item.getContent()),
item.getUpdatedBy() + " (" + item.getUpdatedAt() + ")",
StringUtils.defaultString(item.getIsGiftSentFlag())
));
}
// 시트 1: 임가방문정보
ExcelSheetDto sheet1 = new ExcelSheetDto(
"임가방문정보",
List.of(
"임가번호",
"경영주 성명",
"방문일",
"관리분야",
"내용",
"최종 작성자",
"답례품 전달"),
rows,
null,
Map.of(
0, IndexedColors.LIGHT_YELLOW,
2, IndexedColors.LIGHT_TURQUOISE
));
// 시트 모음
List<ExcelSheetDto> sheets = List.of(sheet1);
byte[] excel = ExcelWriterUtil.writeExcel(sheets);
String rawFileName = "06. 임가방문정보" + "_" + 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`

View File

@@ -26,7 +26,11 @@
THEN bat.unit
ELSE ui_unit.code_text
END AS unitText, /* 단위 */
bat.price AS price /* 현금(원) */
bat.price AS price, /* 현금(원) */
bat.category, /* 유형(엑셀용) */
bat.income_code, /* 수입부호(엑셀용) */
bat.expense_code, /* 지출부호(엑셀용) */
ui_crop.code_value AS cropValue /* 재배형태코드(엑셀용) */
FROM bank_auto_transfer bat
LEFT JOIN uicode ui_crop
ON ui_crop.parent_id = 'code.record.crop'
@@ -51,6 +55,9 @@
resultType="app.module.admin.usecase.household.tab.bankAutoTransfer.getBankAutoTransferRecords.ports.application.domain.GetBankAutoTransferExpenseRecords">
/* getBankAutoTransferExpenseRecords : 은행자동이체 (지출) 내역 목록 조회 */
SELECT bat.id, /* 지출 id */
bat.category, /* 유형(엑셀용) */
bat.income_code, /* 수입부호(엑셀용) */
bat.expense_code, /* 지출부호(엑셀용) */
CASE
WHEN ui_category.id = 'code.bank.input.self'
THEN bat.transfer_category

View File

@@ -23,6 +23,7 @@
df.town, /* 읍면동 */
df.available_area, /* 가능면적 */
df.crop_name, /* 재배작물명 */
df.crop_code, /* 작물부호 */
df.land_area, /* 면적 */
df.main_yield, /* 주생산물 수확량 */
CASE

View File

@@ -72,7 +72,12 @@
vs.second_visit_date AS secondVisitDate,
COALESCE(vs.is_gift_sent, false) AS isGiftSent,
r.researcher_name AS researcherName,
r.researcher_phone AS researcherPhone
r.researcher_phone AS researcherPhone,
h.owner_age, /* 엑셀용 */
h.address, /* 엑셀용 */
h.industry_sub_middle, /* 엑셀용 */
h.industry_detail, /* 엑셀용 */
h.usage_type /* 엑셀용 */
FROM v_household_with_code h
CROSS JOIN total_days td
LEFT JOIN daily_progress dp ON h.seq = dp.household_seq
@@ -224,6 +229,9 @@
</if>
ORDER BY hvr.householdNum ASC
OFFSET #{pageable.offset} ROWS FETCH NEXT #{pageable.pageSize} ROWS ONLY
<if test="cmd.isPaging">
OFFSET #{pageable.offset} ROWS FETCH NEXT #{pageable.pageSize} ROWS ONLY
</if>
</select>
</mapper>

View File

@@ -35,7 +35,10 @@
and a.account_disabled = #{searchAccountDisabled}
</if>
group by a.seq
LIMIT #{size} OFFSET #{page}*#{size}
<if test="isPaging">
LIMIT #{size} OFFSET #{page}*#{size}
</if>
</select>
<select id="countAll" parameterType="app.module.admin.usecase.researcher.adpaters.web.model.ResearchersListReqVO" resultType="long">
@@ -92,9 +95,17 @@
rd.code_text AS region_detail_code_name,
il.code_text AS industry_large_code_name,
im.code_text AS industry_middle_code_name,
case h.is_panel when false then '유지' when true then '탈락' end panel_flag
case h.is_panel when false then '유지' when true then '탈락' end panel_flag,
h.owner_age,
h.address,
h.industry_sub_middle,
h.industry_detail,
h.usage_type,
a.name AS researcherName,
a.phone AS researcherPhone
from household h
join researcher_has_household rhh ON h.seq = rhh.household_seq and rhh.is_deleted = false
join admin a ON a.seq = rhh.admin_seq and a.is_deleted = false
left join uicode rm ON rm.parent_id = 'code.region.main' AND rm.id = h.region_main_code
left join uicode rs ON rs.parent_id = 'code.region.sub' AND rs.id = h.region_sub_code
left join uicode rd ON rd.id = h.region_detail_code
@@ -104,7 +115,10 @@
<if test="seq > 0">
and rhh.admin_seq = #{seq}
</if>
LIMIT #{size} OFFSET #{page}*#{size}
<if test="isPaging">
LIMIT #{size} OFFSET #{page}*#{size}
</if>
</select>
<select id="mappingHouseholdListCountAll">
@@ -130,7 +144,8 @@
rhv.content,
rhv.management_type,
case rhv.is_gift_sent when true then '전달완료' when false then '-' end is_gift_sent_flag,
rhv.created_at
TO_CHAR(rhv.updated_at, 'YYYY-MM-DD HH24:MI') AS updated_at,
rhv.updated_by
from household_visit rhv
join household h on rhv.household_seq = h.seq
join researcher_has_household rhh on rhh.household_seq = h.seq and rhh.is_deleted = false

View File

@@ -275,7 +275,7 @@
<button type="button" class="btn" onclick="showExcelHouseholdModal();">
<span class="btn-txt">엑셀 업로드 <i class="ico-download ico-small" aria-hidden="true"></i></span>
</button>
<button type="button" class="btn">
<button type="button" class="btn" onclick="goExcel();">
<span class="btn-txt">엑셀 다운로드 <i class="ico-download ico-small" aria-hidden="true"></i></span>
</button>
<!-- 관리자만 노출 -->
@@ -484,6 +484,24 @@
}
</script>
<script>
// 엑셀 다운로드
const goExcel = () => {
const url = '/api/households/excel';
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>
<script>
// 체크박스 전체 선택
document.getElementById('checkedAll').addEventListener('change', function () {

View File

@@ -436,11 +436,11 @@
if (el.dataset.tabValue === 'tab1') {
url = $('.tab-content .daily-record-list').is(':hidden') ? '/api/household/dailyRecordStatus/excel' : '/api/household/dailyRecordsStatus/excel';
} else if (el.dataset.tabValue === 'tab2') {
url = '';
url = $('.tab-content .forest-product').is(':hidden') ? '' : '/api/household/forestProduct/excel';
} else if (el.dataset.tabValue === 'tab3') {
url = '';
url = $('.tab-content .bank-auto-transfer').is(':hidden') ? '' : '/api/household/bankAutoTransfer/excel';
} else if (el.dataset.tabValue === 'tab4') {
url = '';
url = $('.tab-content .household-visit').is(':hidden') ? '' : '/api/household/visitInfos/excel';
}
console.log('goExcel', el.dataset.tabValue, url);

View File

@@ -51,6 +51,7 @@
<section>
<form autocomplete="off" method="get" name="householdReqForm" th:object="${reqVO}">
<input type="hidden" name="currentMonth" th:value="${currentMonth}">
<input type="hidden" name="isPaging">
<div class="component-tab" data-active="tab1">
<div class="tab-head">
@@ -167,12 +168,9 @@
</button>
</div>
<div class="btns-col-2 align-right" th:unless="${activeProfile != 'local'}">
<button type="button" class="btn">
<button type="button" class="btn" onclick="goExcel();">
<span class="btn-txt">엑셀 다운로드 <i class="ico-download" aria-hidden="true"></i></span>
</button>
<button type="button" class="btn">
<span class="btn-txt">인쇄 <i class="ico-print" aria-hidden="true"></i></span>
</button>
</div>
</div>
</div>
@@ -210,6 +208,7 @@
const getHouseholdList = (pageNo) => {
const f = document.householdReqForm;
f.page.value = pageNo;
f.isPaging.value = true;
let dataOj = $(f).serializeObject();
ajaxUtil._ajaxMethod(
'/api/researcher/mappingHouseholdList',
@@ -331,7 +330,7 @@
<td>${ct.visitDate}</td>
<td>${ct.managementType}</td>
<td>${ct.content}</td>
<td>${ct.createdAt}</td>
<td>${ct.updatedAt}</td>
<td>${ct.isGiftSentFlag}</td>
</tr>
`
@@ -356,15 +355,29 @@
);
}
function goExcel() {
const selectedTab = document.querySelector('.tab-label[aria-selected="true"]');
let url = '';
if (selectedTab.dataset.tabValue === 'tab1') {
url = '/api/researcher/mappingHouseholdList/excel';
} else if (selectedTab.dataset.tabValue === 'tab2') {
url = '/api/researcher/visitHousehold/list/excel';
}
const f = document.householdReqForm;
f.isPaging.value = false;
const data = $(f).serializeObject();
// size 를 제거하면 전체 목록을 가져온다.
delete data.size;
location.href = '/admin/researchers/excel?' + new URLSearchParams(data).toString();
if (url !== '') {
location.href = url + '?' + new URLSearchParams(data).toString();
} else {
console.warn('엑셀 다운르도 경로 없음.')
}
}
// 체크박스 선택/해제

View File

@@ -9,6 +9,8 @@
<!-- hidden parameters -->
<input name="sort" th:field="*{sort}" type="hidden"/>
<input name="page" th:field="*{page}" type="hidden"/>
<input name="isPaging" type="hidden"/>
<div class="input-group">
<div class="input-label">
<p class="label-txt">
@@ -108,6 +110,7 @@
const getResearchers = (pageNo) => {
const f = document.reqForm;
f.page.value = pageNo;
f.isPaging.value = true;
let dataOj = $(f).serializeObject();
@@ -191,12 +194,14 @@
function goExcel() {
const f = document.reqForm;
f.isPaging.value = false;
const data = $(f).serializeObject();
// size 를 제거하면 전체 목록을 가져온다.
delete data.size;
location.href = '/admin/researchers/excel?' + new URLSearchParams(data).toString();
location.href = '/api/researcher/list/excel?' + new URLSearchParams(data).toString();
}
// 체크박스 선택/해제

View File

@@ -43,7 +43,8 @@ SELECT
h.industry_sub_middle,
h.industry_detail,
h.is_panel,
h.memo
h.memo,
h.usage_type
FROM household h
LEFT JOIN uicode main ON h.region_main_code = main.id
LEFT JOIN v_uicode_view_name sub ON h.region_sub_code = sub.id