|
|
|
|
@@ -8,31 +8,35 @@ import app.module.admin.usecase.household.createHousehold.ports.application.doma
|
|
|
|
|
import app.module.admin.usecase.household.createHousehold.ports.application.domain.CreateHouseholdOutCmd;
|
|
|
|
|
import app.module.admin.usecase.household.createHousehold.ports.application.domain.CreateResearcherHasHouseholdCmd;
|
|
|
|
|
import app.module.admin.usecase.household.excelUploadCreateHousehold.adapters.web.model.ExcelCreateHouseholdVO;
|
|
|
|
|
import app.module.admin.usecase.household.excelUploadCreateHousehold.adapters.web.model.ExcelUploadContactVO;
|
|
|
|
|
import app.module.admin.usecase.household.excelUploadCreateHousehold.adapters.web.model.ExcelUploadResultVO;
|
|
|
|
|
import app.module.admin.usecase.household.excelUploadCreateHousehold.ports.ExcelUploadCreateHouseholdPortOut;
|
|
|
|
|
import app.module.admin.usecase.researcher.adpaters.persistence.ResearcherMapper;
|
|
|
|
|
import app.module.core.config.application.util.AuditUtil;
|
|
|
|
|
import app.module.core.usecase.admin.excelSaveAdmin.adapters.persistence.model.ExcelAdminCreateVO;
|
|
|
|
|
import app.module.core.usecase.admin.saveAdmin.adapters.persistence.model.SaveAdminHasRoleParam;
|
|
|
|
|
import app.module.core.usecase.admin.saveAdmin.ports.application.domain.SaveAdminCmd;
|
|
|
|
|
import app.module.core.usecase.uicode.list.adapters.persistence.UICodeListMapper;
|
|
|
|
|
import app.module.core.usecase.uicode.list.ports.application.domain.UICodeElement;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Repository
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut {
|
|
|
|
|
private final CreateHouseholdMapper createHouseholdMapper;
|
|
|
|
|
private final CheckHouseholdNumMapper checkHouseholdNumMapper;
|
|
|
|
|
private final UICodeListMapper uiCodeListMapper;
|
|
|
|
|
private final BCryptPasswordEncoder passwordEncoder;
|
|
|
|
|
private final ResearcherMapper researcherMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
@@ -44,7 +48,7 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
|
|
|
|
|
|
|
|
|
List<UICodeElement> RegionMainCodeList = uiCodeListMapper.findByParentId("code.region.main");
|
|
|
|
|
List<UICodeElement> RegionSubCodeList = uiCodeListMapper.findByParentId("code.region.sub");
|
|
|
|
|
List<UICodeElement> RegionDetailCodeList = uiCodeListMapper.findByParentId("code.region.detail");
|
|
|
|
|
List<UICodeElement> RegionDetailCodeList = uiCodeListMapper.findByLikeId("code.region.detail");
|
|
|
|
|
List<UICodeElement> IndustryLargeCodeList = uiCodeListMapper.findByParentId("code.industry.large");
|
|
|
|
|
List<UICodeElement> IndustryMiddleCodeList = uiCodeListMapper.findByParentId("code.industry.middle");
|
|
|
|
|
|
|
|
|
|
@@ -53,32 +57,31 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
|
|
|
|
Row row = sheet.getRow(i);
|
|
|
|
|
if (row == null) continue;
|
|
|
|
|
|
|
|
|
|
ExcelCreateHouseholdVO household = new ExcelCreateHouseholdVO();
|
|
|
|
|
household.setHouseholdNum(getCellValue(row.getCell(0))); // 임가번호
|
|
|
|
|
household.setOwnerName(getCellValue(row.getCell(1))); // 경영주명
|
|
|
|
|
household.setOwnerAge(getCellNumberValue(row.getCell(2))); // 연령
|
|
|
|
|
|
|
|
|
|
//연락처 는 또 따로 해줘야댐,,,
|
|
|
|
|
household.setTel(getDivisionContact(row.getCell(3),"tel")); // 가구 연락처
|
|
|
|
|
household.setPhone(getDivisionContact(row.getCell(3),"phone")); // 연락처
|
|
|
|
|
|
|
|
|
|
//비밀번호도 넣어줘야됨,,,
|
|
|
|
|
|
|
|
|
|
household.setRegionMainCode(getRegionMainCode(row.getCell(4),RegionMainCodeList)); // 실사
|
|
|
|
|
household.setRegionSubCode(getUiCode(row.getCell(5),RegionSubCodeList,"code.region.sub")); // 지역
|
|
|
|
|
household.setRegionDetailCode(getUiCode(row.getCell(6),RegionDetailCodeList,"code.region.detail")); // 세부지역
|
|
|
|
|
household.setAddress(getCellValue(row.getCell(7))); // 전체주소
|
|
|
|
|
household.setIndustryLargeCode(getUiCode(row.getCell(8),IndustryLargeCodeList,"code.industry.large")); // 업종 대분류
|
|
|
|
|
household.setIndustryMiddleCode(getUiCode(row.getCell(9),IndustryMiddleCodeList,"code.industry.middle")); // 업종 중분류
|
|
|
|
|
household.setIndustrySubMiddle(getCellValue(row.getCell(10))); // 업종 중분류2
|
|
|
|
|
household.setIndustryDetail(getCellValue(row.getCell(11))); // 규모 / 세부품목
|
|
|
|
|
// household.setResearcherSeq(getCellNumberValue(row.getCell(12))); // 조사원
|
|
|
|
|
//household.setIsPanel(getCellValue(row.getCell(13))); // 유지여부
|
|
|
|
|
CheckHouseholdNum checkHouseholdNum = checkHouseholdNumMapper.checkHouseholdNum(new CheckHouseholdNumCmd(getCellValue(row.getCell(0)))).orElse(null);
|
|
|
|
|
ExcelUploadContactVO contactVO = getDivisionContact(row.getCell(3));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Optional<CheckHouseholdNum> checkHouseholdNum = checkHouseholdNumMapper.checkHouseholdNum(new CheckHouseholdNumCmd(household.getHouseholdNum()));
|
|
|
|
|
if(!checkHouseholdNum.getIsDuplicated() && contactVO != null) {
|
|
|
|
|
|
|
|
|
|
ExcelCreateHouseholdVO household = new ExcelCreateHouseholdVO();
|
|
|
|
|
household.setHouseholdNum(getCellValue(row.getCell(0))); // 임가번호
|
|
|
|
|
household.setOwnerName(getCellValue(row.getCell(1))); // 경영주명
|
|
|
|
|
household.setOwnerAge(getCellNumberValue(row.getCell(2))); // 연령
|
|
|
|
|
household.setTel(contactVO.getTel()); // 가구 연락처
|
|
|
|
|
household.setPhone(contactVO.getPhone()); // 연락처
|
|
|
|
|
household.setEncodedPassword(passwordEncoder.encode(contactVO.getPhoneLast())); // 비밀번호
|
|
|
|
|
household.setRegionMainCode(getUiCode(row.getCell(4),RegionMainCodeList,"code.region.main")); // 실사
|
|
|
|
|
household.setRegionSubCode(getUiCode(row.getCell(5),RegionSubCodeList,"code.region.sub")); // 지역
|
|
|
|
|
household.setRegionDetailCode(getUiCode(row.getCell(6),RegionDetailCodeList,"code.region.detail")); // 세부지역
|
|
|
|
|
household.setAddress(getCellValue(row.getCell(7))); // 전체주소
|
|
|
|
|
household.setIndustryLargeCode(getUiCode(row.getCell(8),IndustryLargeCodeList,"code.industry.large")); // 업종 대분류
|
|
|
|
|
household.setIndustryMiddleCode(getUiCode(row.getCell(9),IndustryMiddleCodeList,"code.industry.middle")); // 업종 중분류
|
|
|
|
|
household.setIndustrySubMiddle(getCellValue(row.getCell(10))); // 업종 중분류2
|
|
|
|
|
household.setIndustryDetail(getCellValue(row.getCell(11))); // 규모 / 세부품목
|
|
|
|
|
household.setResearcherSeq(getResearcherSeq(row.getCell(12))); // 조사원
|
|
|
|
|
household.setIsPanel(getIsPanel(row.getCell(13))); // 유지여부
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(checkHouseholdNum.isEmpty()) {
|
|
|
|
|
CreateHouseholdOutCmd cmd = new CreateHouseholdOutCmd(
|
|
|
|
|
null,
|
|
|
|
|
household.getHouseholdNum(),
|
|
|
|
|
@@ -86,7 +89,7 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
|
|
|
|
household.getOwnerAge(),
|
|
|
|
|
household.getTel(),
|
|
|
|
|
household.getPhone(),
|
|
|
|
|
household.getPhone(),//패스워드
|
|
|
|
|
household.getEncodedPassword(),
|
|
|
|
|
household.getRegionMainCode(),
|
|
|
|
|
household.getRegionSubCode(),
|
|
|
|
|
household.getRegionDetailCode(),
|
|
|
|
|
@@ -98,10 +101,10 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
|
|
|
|
household.getResearcherSeq(),
|
|
|
|
|
household.getIsPanel(),
|
|
|
|
|
null,
|
|
|
|
|
List.of("ROLE_HOUSEHOLD")
|
|
|
|
|
List.of("ROLE_GENERAL")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
createHouseholdMapper.createHousehold(AuditUtil.create(cmd));
|
|
|
|
|
success += createHouseholdMapper.createHousehold(AuditUtil.create(cmd));
|
|
|
|
|
|
|
|
|
|
if(cmd.getRoleIds() != null && !cmd.getRoleIds().isEmpty()) {
|
|
|
|
|
createHouseholdMapper.createHouseholdHasRole(AuditUtil.create(new CreateHouseholdHasRoleCmd(cmd.getSeq(), cmd.getRoleIds())));
|
|
|
|
|
@@ -145,24 +148,35 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
|
|
|
|
.map(UICodeElement::getId).orElse("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getRegionMainCode(Cell cell,List<UICodeElement> uiCodeElementList){
|
|
|
|
|
if (cell == null) return "";
|
|
|
|
|
return uiCodeElementList.stream().filter(code -> code.getCodeText().equals(cell.getStringCellValue().trim()))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.map(UICodeElement::getId).orElse("");
|
|
|
|
|
private ExcelUploadContactVO getDivisionContact(Cell cell){
|
|
|
|
|
if (cell == null) return null;
|
|
|
|
|
|
|
|
|
|
String[] contact = cell.getStringCellValue().trim().split("-");
|
|
|
|
|
|
|
|
|
|
ExcelUploadContactVO contactVO = new ExcelUploadContactVO();
|
|
|
|
|
|
|
|
|
|
if(contact[2].length() == 4) {
|
|
|
|
|
if (contact[0].equals("010") || contact[0].equals("011")) {
|
|
|
|
|
contactVO.setPhone(getCellValue(cell));
|
|
|
|
|
contactVO.setPhoneLast(contact[2]);
|
|
|
|
|
} else {
|
|
|
|
|
contactVO.setTel(getCellValue(cell));
|
|
|
|
|
contactVO.setPhoneLast(contact[2]);
|
|
|
|
|
}
|
|
|
|
|
return contactVO;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getDivisionContact(Cell cell,String division){
|
|
|
|
|
if (cell == null) return "";
|
|
|
|
|
String[] divisionContent = cell.getStringCellValue().split("-");
|
|
|
|
|
private Boolean getIsPanel(Cell cell){
|
|
|
|
|
if (cell == null) return null;
|
|
|
|
|
String[] isPanel = cell.getStringCellValue().trim().split("\\.");
|
|
|
|
|
return "1".equals(isPanel[0]) || "유지".equals(isPanel[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( division.equals("phone") && ( divisionContent[0].equals("010") || divisionContent[0].equals("011") ) ){
|
|
|
|
|
return cell.getStringCellValue();
|
|
|
|
|
}else if(division.equals("tel")){
|
|
|
|
|
return cell.getStringCellValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
private Long getResearcherSeq(Cell cell){
|
|
|
|
|
if (cell == null) return null;
|
|
|
|
|
return researcherMapper.selectResearcherId(cell.getStringCellValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|