임가 등록/ 조사원 매팡 엑셀 파일 업로드
This commit is contained in:
@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface CreateHouseholdMapper {
|
||||
void createHousehold(CreateHouseholdOutCmd outCmd);
|
||||
Integer createHousehold(CreateHouseholdOutCmd outCmd);
|
||||
void createHouseholdHasRole(CreateHouseholdHasRoleCmd cmd);
|
||||
void createResearcherHasHousehold(CreateResearcherHasHouseholdCmd cmd);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ public class ExcelCreateHouseholdVO {
|
||||
private Integer ownerAge;
|
||||
private String tel;
|
||||
private String phone;
|
||||
private String encodedPassword;
|
||||
private String regionMainCode;
|
||||
private String regionSubCode;
|
||||
private String regionDetailCode;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.admin.usecase.household.excelUploadCreateHousehold.adapters.web.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class ExcelUploadContactVO {
|
||||
private String phone;
|
||||
private String tel;
|
||||
private String phoneLast;
|
||||
|
||||
}
|
||||
@@ -27,5 +27,5 @@ public interface ResearcherMapper {
|
||||
void deleteHouseholdResearcherMapping(@Param("researcherSeq") Integer researcherSeq, @Param("householdSeq") Integer householdSeq, @Param("deletedBy") String deletedBy);
|
||||
Integer insertHouseholdResearcherMapping(@Param("researcherSeq") Integer researcherSeq, @Param("householdSeq") Integer householdSeq, @Param("createdBy") String createdBy);
|
||||
List<GetPopupHouseholds> getPopupHouseholds(@Param("pageable") Pageable pageable, @Param("cmd") GetPopupHouseholdsCmd cmd);
|
||||
|
||||
Long selectResearcherId(@Param("id")String id);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<mapper
|
||||
namespace="app.module.admin.usecase.household.createHousehold.adapters.persistence.CreateHouseholdMapper">
|
||||
|
||||
<insert id="createHousehold">
|
||||
<update id="createHousehold">
|
||||
/* createHousehold : 임가 등록 */
|
||||
<selectKey keyProperty="seq" resultType="long" order="BEFORE">
|
||||
SELECT nextval('household_seq')
|
||||
@@ -79,7 +79,7 @@
|
||||
</if>
|
||||
<include refid="common.fields.CreateUpdateBaseValues"/>
|
||||
)
|
||||
</insert>
|
||||
</update>
|
||||
|
||||
<insert id="createHouseholdHasRole">
|
||||
/* createHouseholdHasRole : 임가 역할 등록 */
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<when test="cmd.searchField eq 'name'">
|
||||
AND a.name ILIKE '%' || #{cmd.searchValue} || '%'
|
||||
</when>
|
||||
|
||||
<when test="cmd.searchField eq 'phone'">
|
||||
AND a.phone ILIKE '%' || #{cmd.searchValue} || '%'
|
||||
</when>
|
||||
|
||||
@@ -357,4 +357,12 @@
|
||||
ORDER BY hvr.householdNum ASC
|
||||
OFFSET #{pageable.offset} ROWS FETCH NEXT #{pageable.pageSize} ROWS ONLY
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectResearcherId">
|
||||
select seq
|
||||
from admin a
|
||||
join admin_has_role ahr on ahr.admin_seq = a.seq and ahr.role_id = 'ROLE_RESEARCHER' and ahr.is_deleted = false
|
||||
where a.id = #{id} and a.is_deleted = false
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -284,6 +284,9 @@
|
||||
|
||||
<div class="component-btns bottom-btn-group" th:unless="${activeProfile != 'local'}">
|
||||
<div class="btns-row align-right">
|
||||
<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">
|
||||
<span class="btn-txt">엑셀 다운로드 <i class="ico-download ico-small" aria-hidden="true"></i></span>
|
||||
</button>
|
||||
@@ -302,6 +305,7 @@
|
||||
</form>
|
||||
|
||||
<div th:replace="common/modal-researcher-mapping :: modalFragment"></div>
|
||||
<div th:replace="households/modal/modal-excel-household :: modalFragment"></div>
|
||||
</section>
|
||||
|
||||
<section layout:fragment="script">
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{layout/layout}">
|
||||
|
||||
<div class="layer-wrap" th:fragment="modalFragment">
|
||||
<form autocomplete="off" method="get" name="reqHouseholdExcelForm">
|
||||
|
||||
<div class="component-modal mypage-wrap modal01 modal-excel-household" data-props-dimm-click="true" data-state="close">
|
||||
<div class="modal-dimm"></div>
|
||||
<div class="modal-frame">
|
||||
<div class="modal-container">
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-tit">
|
||||
임가 등록 엑셀업로드
|
||||
</h3>
|
||||
</div>
|
||||
<div class="modal-content">
|
||||
<div class="modal-content-inner">
|
||||
<label for="householdFile" class="input-file-btn">
|
||||
<input type="file" name="file" id="householdFile" accept=".xlsx, .xls">
|
||||
</label>
|
||||
<div class="component-btns bottom-btn-group">
|
||||
<div class="btns-row align-right">
|
||||
<button type="button" class="btn btn-primary" onclick="ExcelUploadHousehold();">
|
||||
<span class="btn-txt">등록</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="button" class="modal-close"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script th:inline="javascript">
|
||||
// 임가방문정보 모달창 띄우기
|
||||
const showExcelHouseholdModal = () => {
|
||||
document.querySelector(".modal-excel-household").ui.open();
|
||||
}
|
||||
|
||||
// 임가방문정보 등록
|
||||
const ExcelUploadHousehold = () => {
|
||||
event.preventDefault();
|
||||
|
||||
const fileInput = document.getElementById('householdFile');
|
||||
if (fileInput.files.length === 0) {
|
||||
alert('업로드할 엑셀 파일을 선택해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append('file', fileInput.files[0]);
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: '/api/household/excelUpload',
|
||||
data: formData,
|
||||
contentType: false, // * 중요 *
|
||||
processData: false, // * 중요 *
|
||||
enctype: 'multipart/form-data', // * 중요 *
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader(
|
||||
$("meta[name='_csrf_header']").attr("content"),
|
||||
$("meta[name='_csrf']").attr("content"));
|
||||
},
|
||||
success(res) {
|
||||
alert("총 "+res.total+"건 중에 "+res.success+"건 등록되었습니다.");
|
||||
},
|
||||
statusCode: {
|
||||
422: (res) => {
|
||||
const resJson = res.responseJSON;
|
||||
$(input).parent().find('.invalid-feedback').text(resJson.message);
|
||||
$(input).addClass('is-invalid');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</div>
|
||||
</html>
|
||||
Reference in New Issue
Block a user