260929_01_ENH: 설문 응답 결과 수정에 대한 기능누락 수정
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -25,6 +26,9 @@ public class ListUpdateRequestDto {
|
|||||||
@Schema(description = "리스트 결과 코드 수정내용")
|
@Schema(description = "리스트 결과 코드 수정내용")
|
||||||
private Map<ResultCodeType, Integer> updateResultCodes;
|
private Map<ResultCodeType, Integer> updateResultCodes;
|
||||||
|
|
||||||
|
@Schema(description = "설문별 결과 코드 수정 내용")
|
||||||
|
private List<@NotNull @Valid ListSurveyResultUpdateDto> updateSurveyResultCodes;
|
||||||
|
|
||||||
@Valid
|
@Valid
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "리스트 필터")
|
@Schema(description = "리스트 필터")
|
||||||
|
|||||||
@@ -162,28 +162,34 @@ public class ListUpdateJdbcSupport {
|
|||||||
insert into t_list_event_hist (
|
insert into t_list_event_hist (
|
||||||
event_ty,
|
event_ty,
|
||||||
prjct_idx,
|
prjct_idx,
|
||||||
|
prjct_survey_idx,
|
||||||
sid,
|
sid,
|
||||||
result_cd,
|
result_cd,
|
||||||
meta_data,
|
meta_data,
|
||||||
memo,
|
memo,
|
||||||
reg_user,
|
reg_user,
|
||||||
reg_dt
|
reg_dt
|
||||||
) values (?, ?, ?, ?, ?, ?, ?, ?)
|
) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
""";
|
""";
|
||||||
|
|
||||||
batchUpdate(rows, batchSize, sql, (ps, row) -> {
|
batchUpdate(rows, batchSize, sql, (ps, row) -> {
|
||||||
ps.setShort(1, row.eventTy());
|
ps.setShort(1, row.eventTy());
|
||||||
ps.setLong(2, row.prjctIdx());
|
ps.setLong(2, row.prjctIdx());
|
||||||
ps.setString(3, row.sid());
|
if (row.prjctSurveyIdx() == null) {
|
||||||
ps.setInt(4, row.resultCd());
|
ps.setNull(3, Types.INTEGER);
|
||||||
if (row.metaData() == null) {
|
|
||||||
ps.setNull(5, Types.VARCHAR);
|
|
||||||
} else {
|
} else {
|
||||||
ps.setString(5, row.metaData());
|
ps.setLong(3, row.prjctSurveyIdx());
|
||||||
}
|
}
|
||||||
ps.setString(6, row.memo());
|
ps.setString(4, row.sid());
|
||||||
ps.setString(7, row.regUser());
|
ps.setInt(5, row.resultCd());
|
||||||
ps.setTimestamp(8, Timestamp.valueOf(row.regDt()));
|
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(
|
public record ListEventHistInsertRow(
|
||||||
Short eventTy,
|
Short eventTy,
|
||||||
Long prjctIdx,
|
Long prjctIdx,
|
||||||
|
Long prjctSurveyIdx,
|
||||||
String sid,
|
String sid,
|
||||||
Integer resultCd,
|
Integer resultCd,
|
||||||
String metaData,
|
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.ListEventHistSurveyMetaDto.SurveySnapshot;
|
||||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||||
import com.kri.contact.server.dto.list.ListHeaderDto;
|
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.dto.list.ListUpdateRequestDto;
|
||||||
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
import com.kri.contact.server.persistence.entity.TListEventHistEntity;
|
||||||
import com.kri.contact.server.persistence.entity.TListHeaderEntity;
|
import com.kri.contact.server.persistence.entity.TListHeaderEntity;
|
||||||
@@ -90,10 +91,9 @@ public class ListUpdateService {
|
|||||||
|
|
||||||
Map<Integer, String> updateContents = request.getUpdateContents();
|
Map<Integer, String> updateContents = request.getUpdateContents();
|
||||||
Map<ResultCodeType, Integer> updateResultCodes = request.getUpdateResultCodes();
|
Map<ResultCodeType, Integer> updateResultCodes = request.getUpdateResultCodes();
|
||||||
if (isEmpty(updateContents) && isEmpty(updateResultCodes)) {
|
List<ListSurveyResultUpdateDto> updateSurveyResultCodes = request.getUpdateSurveyResultCodes();
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
validateResultCodes(prjctIdx, updateResultCodes);
|
validateResultCodes(prjctIdx, updateResultCodes);
|
||||||
|
validateSurveyResultCodes(prjctIdx, updateSurveyResultCodes);
|
||||||
|
|
||||||
Set<String> sids = resolveTargetSids(prjctIdx, request.getListFilter());
|
Set<String> sids = resolveTargetSids(prjctIdx, request.getListFilter());
|
||||||
if (sids.isEmpty()) {
|
if (sids.isEmpty()) {
|
||||||
@@ -142,6 +142,9 @@ public class ListUpdateService {
|
|||||||
if (!isEmpty(updateResultCodes)) {
|
if (!isEmpty(updateResultCodes)) {
|
||||||
insertResultCodeHistories(prjctIdx, sids, updateResultCodes, regUser, regDt);
|
insertResultCodeHistories(prjctIdx, sids, updateResultCodes, regUser, regDt);
|
||||||
}
|
}
|
||||||
|
if (updateSurveyResultCodes != null && !updateSurveyResultCodes.isEmpty()) {
|
||||||
|
insertSurveyResultCodeHistories(prjctIdx, sids, updateSurveyResultCodes, regUser, regDt);
|
||||||
|
}
|
||||||
|
|
||||||
return totalUpdatedCount;
|
return totalUpdatedCount;
|
||||||
}
|
}
|
||||||
@@ -219,7 +222,8 @@ public class ListUpdateService {
|
|||||||
private void validateListUpdateRequest(ListUpdateRequestDto request){
|
private void validateListUpdateRequest(ListUpdateRequestDto request){
|
||||||
if(
|
if(
|
||||||
CollectionUtil.isEmpty(request.getUpdateContents()) &&
|
CollectionUtil.isEmpty(request.getUpdateContents()) &&
|
||||||
CollectionUtil.isEmpty(request.getUpdateResultCodes())
|
CollectionUtil.isEmpty(request.getUpdateResultCodes()) &&
|
||||||
|
CollectionUtil.isEmpty(request.getUpdateSurveyResultCodes())
|
||||||
){
|
){
|
||||||
throw BusinessException.badRequest("EMPTY_UPDATE_CONTENT","리스트 수정내용이 없습니다.");
|
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(
|
private void insertResultCodeHistories(
|
||||||
Long prjctIdx,
|
Long prjctIdx,
|
||||||
Collection<String> sids,
|
Collection<String> sids,
|
||||||
@@ -256,6 +290,7 @@ public class ListUpdateService {
|
|||||||
rows.add(new ListEventHistInsertRow(
|
rows.add(new ListEventHistInsertRow(
|
||||||
entry.getKey().getCode(),
|
entry.getKey().getCode(),
|
||||||
prjctIdx,
|
prjctIdx,
|
||||||
|
null,
|
||||||
sid,
|
sid,
|
||||||
entry.getValue(),
|
entry.getValue(),
|
||||||
null,
|
null,
|
||||||
@@ -268,6 +303,32 @@ public class ListUpdateService {
|
|||||||
listUpdateJdbcSupport.batchInsertListEventHist(rows, ContactConstant.INSERT_CHUNK_SIZE);
|
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) {
|
private void validateEventHistoryTarget(Long prjctIdx, String sid) {
|
||||||
if (!listRepository.existsByIdPrjctIdxAndIdSid(prjctIdx, sid)) {
|
if (!listRepository.existsByIdPrjctIdxAndIdSid(prjctIdx, sid)) {
|
||||||
throw BusinessException.badRequest("LIST_NOT_FOUND", "이력을 추가할 리스트를 찾을 수 없습니다.");
|
throw BusinessException.badRequest("LIST_NOT_FOUND", "이력을 추가할 리스트를 찾을 수 없습니다.");
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ kri:
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
#public 도메인
|
#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
|
username: kri_contact
|
||||||
password: contact#51304
|
password: contact#51304
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
|||||||
Reference in New Issue
Block a user