Merge pull request '260929_01_ENH: 설문 응답 결과 수정에 대한 기능누락 수정' (#28) from develop into master
Reviewed-on: #28
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.kri.contact.server.dto.list;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "설문 결과 수정 내용")
|
||||
public class ListSurveyResultUpdateDto {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "프로젝트 설문 고유번호")
|
||||
private Long prjctSurveyIdx;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "설문 결과 코드")
|
||||
private Integer resultCd;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -25,6 +26,9 @@ public class ListUpdateRequestDto {
|
||||
@Schema(description = "리스트 결과 코드 수정내용")
|
||||
private Map<ResultCodeType, Integer> updateResultCodes;
|
||||
|
||||
@Schema(description = "설문별 결과 코드 수정 내용")
|
||||
private List<@NotNull @Valid ListSurveyResultUpdateDto> updateSurveyResultCodes;
|
||||
|
||||
@Valid
|
||||
@NotNull
|
||||
@Schema(description = "리스트 필터")
|
||||
|
||||
@@ -162,28 +162,34 @@ public class ListUpdateJdbcSupport {
|
||||
insert into t_list_event_hist (
|
||||
event_ty,
|
||||
prjct_idx,
|
||||
prjct_survey_idx,
|
||||
sid,
|
||||
result_cd,
|
||||
meta_data,
|
||||
memo,
|
||||
reg_user,
|
||||
reg_dt
|
||||
) values (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""";
|
||||
|
||||
batchUpdate(rows, batchSize, sql, (ps, row) -> {
|
||||
ps.setShort(1, row.eventTy());
|
||||
ps.setLong(2, row.prjctIdx());
|
||||
ps.setString(3, row.sid());
|
||||
ps.setInt(4, row.resultCd());
|
||||
if (row.metaData() == null) {
|
||||
ps.setNull(5, Types.VARCHAR);
|
||||
if (row.prjctSurveyIdx() == null) {
|
||||
ps.setNull(3, Types.INTEGER);
|
||||
} else {
|
||||
ps.setString(5, row.metaData());
|
||||
ps.setLong(3, row.prjctSurveyIdx());
|
||||
}
|
||||
ps.setString(6, row.memo());
|
||||
ps.setString(7, row.regUser());
|
||||
ps.setTimestamp(8, Timestamp.valueOf(row.regDt()));
|
||||
ps.setString(4, row.sid());
|
||||
ps.setInt(5, row.resultCd());
|
||||
if (row.metaData() == null) {
|
||||
ps.setNull(6, Types.VARCHAR);
|
||||
} else {
|
||||
ps.setString(6, row.metaData());
|
||||
}
|
||||
ps.setString(7, row.memo());
|
||||
ps.setString(8, row.regUser());
|
||||
ps.setTimestamp(9, Timestamp.valueOf(row.regDt()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -255,6 +261,7 @@ public class ListUpdateJdbcSupport {
|
||||
public record ListEventHistInsertRow(
|
||||
Short eventTy,
|
||||
Long prjctIdx,
|
||||
Long prjctSurveyIdx,
|
||||
String sid,
|
||||
Integer resultCd,
|
||||
String metaData,
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.kri.contact.server.dto.list.ListEventHistSurveyMetaDto;
|
||||
import com.kri.contact.server.dto.list.ListEventHistSurveyMetaDto.SurveySnapshot;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
||||
import com.kri.contact.server.dto.list.ListSurveyResultUpdateDto;
|
||||
import com.kri.contact.server.dto.list.ListUpdateRequestDto;
|
||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||
import com.kri.contact.server.persistence.entity.TListHeaderEntity;
|
||||
@@ -90,10 +91,9 @@ public class ListUpdateService {
|
||||
|
||||
Map<Integer, String> updateContents = request.getUpdateContents();
|
||||
Map<ResultCodeType, Integer> updateResultCodes = request.getUpdateResultCodes();
|
||||
if (isEmpty(updateContents) && isEmpty(updateResultCodes)) {
|
||||
return 0;
|
||||
}
|
||||
List<ListSurveyResultUpdateDto> updateSurveyResultCodes = request.getUpdateSurveyResultCodes();
|
||||
validateResultCodes(prjctIdx, updateResultCodes);
|
||||
validateSurveyResultCodes(prjctIdx, updateSurveyResultCodes);
|
||||
|
||||
Set<String> sids = resolveTargetSids(prjctIdx, request.getListFilter());
|
||||
if (sids.isEmpty()) {
|
||||
@@ -142,6 +142,9 @@ public class ListUpdateService {
|
||||
if (!isEmpty(updateResultCodes)) {
|
||||
insertResultCodeHistories(prjctIdx, sids, updateResultCodes, regUser, regDt);
|
||||
}
|
||||
if (updateSurveyResultCodes != null && !updateSurveyResultCodes.isEmpty()) {
|
||||
insertSurveyResultCodeHistories(prjctIdx, sids, updateSurveyResultCodes, regUser, regDt);
|
||||
}
|
||||
|
||||
return totalUpdatedCount;
|
||||
}
|
||||
@@ -219,7 +222,8 @@ public class ListUpdateService {
|
||||
private void validateListUpdateRequest(ListUpdateRequestDto request){
|
||||
if(
|
||||
CollectionUtil.isEmpty(request.getUpdateContents()) &&
|
||||
CollectionUtil.isEmpty(request.getUpdateResultCodes())
|
||||
CollectionUtil.isEmpty(request.getUpdateResultCodes()) &&
|
||||
CollectionUtil.isEmpty(request.getUpdateSurveyResultCodes())
|
||||
){
|
||||
throw BusinessException.badRequest("EMPTY_UPDATE_CONTENT","리스트 수정내용이 없습니다.");
|
||||
}
|
||||
@@ -243,6 +247,36 @@ public class ListUpdateService {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateSurveyResultCodes(
|
||||
Long prjctIdx,
|
||||
List<ListSurveyResultUpdateDto> surveyResultCodes
|
||||
) {
|
||||
if (surveyResultCodes == null || surveyResultCodes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<Long> surveyIds = new LinkedHashSet<>();
|
||||
for (ListSurveyResultUpdateDto update : surveyResultCodes) {
|
||||
if (update == null || update.getPrjctSurveyIdx() == null || update.getResultCd() == null) {
|
||||
throw BusinessException.badRequest("INVALID_SURVEY_RESULT_UPDATE", "설문 결과 수정 내용이 올바르지 않습니다.");
|
||||
}
|
||||
Long surveyId = update.getPrjctSurveyIdx();
|
||||
if (!surveyIds.add(surveyId)) {
|
||||
throw BusinessException.badRequest("DUPLICATE_SURVEY_RESULT_UPDATE", "같은 설문의 결과가 중복 지정되었습니다.");
|
||||
}
|
||||
TPrjctSurveyEntity survey = projectSurveyRepository.findById(surveyId)
|
||||
.filter(found -> Objects.equals(found.getPrjctIdx(), prjctIdx))
|
||||
.orElseThrow(() -> BusinessException.badRequest(
|
||||
"PROJECT_SURVEY_NOT_FOUND", "프로젝트 설문을 찾을 수 없습니다."
|
||||
).with("prjctSurveyIdx", surveyId));
|
||||
Integer resultCd = update.getResultCd();
|
||||
if (resultCd < Short.MIN_VALUE || resultCd > Short.MAX_VALUE) {
|
||||
throw BusinessException.badRequest("RESULT_CODE_NOT_FOUND", "존재하지 않는 결과 코드입니다.");
|
||||
}
|
||||
resultCodeService.validateResultCodeExists(
|
||||
survey.getPrjctIdx(), ResultCodeType.SURVEY, resultCd.shortValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void insertResultCodeHistories(
|
||||
Long prjctIdx,
|
||||
Collection<String> sids,
|
||||
@@ -256,6 +290,7 @@ public class ListUpdateService {
|
||||
rows.add(new ListEventHistInsertRow(
|
||||
entry.getKey().getCode(),
|
||||
prjctIdx,
|
||||
null,
|
||||
sid,
|
||||
entry.getValue(),
|
||||
null,
|
||||
@@ -268,6 +303,32 @@ public class ListUpdateService {
|
||||
listUpdateJdbcSupport.batchInsertListEventHist(rows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
private void insertSurveyResultCodeHistories(
|
||||
Long prjctIdx,
|
||||
Collection<String> sids,
|
||||
List<ListSurveyResultUpdateDto> surveyResultCodes,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
List<ListEventHistInsertRow> rows = new ArrayList<>();
|
||||
for (String sid : sids) {
|
||||
for (ListSurveyResultUpdateDto update : surveyResultCodes) {
|
||||
rows.add(new ListEventHistInsertRow(
|
||||
ResultCodeType.SURVEY.getCode(),
|
||||
prjctIdx,
|
||||
update.getPrjctSurveyIdx(),
|
||||
sid,
|
||||
update.getResultCd(),
|
||||
null,
|
||||
"",
|
||||
regUser,
|
||||
regDt
|
||||
));
|
||||
}
|
||||
}
|
||||
listUpdateJdbcSupport.batchInsertListEventHist(rows, ContactConstant.INSERT_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
private void validateEventHistoryTarget(Long prjctIdx, String sid) {
|
||||
if (!listRepository.existsByIdPrjctIdxAndIdSid(prjctIdx, sid)) {
|
||||
throw BusinessException.badRequest("LIST_NOT_FOUND", "이력을 추가할 리스트를 찾을 수 없습니다.");
|
||||
|
||||
@@ -14,7 +14,8 @@ kri:
|
||||
spring:
|
||||
datasource:
|
||||
#public 도메인
|
||||
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/test_kri_contact?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||
#url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/test_kri_contact?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/kri_contact?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||
username: kri_contact
|
||||
password: contact#51304
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
Reference in New Issue
Block a user