260922_01_ENH: 공지, 문의, 문의 답변, 팝업 목록 및 내용에 작성자 이름 추가 제공 #2

Merged
gitadmin merged 1 commits from develop into master 2026-09-22 17:00:26 +09:00
8 changed files with 51 additions and 10 deletions

View File

@@ -6,7 +6,7 @@ import java.util.List;
public record NoticeResponseDto(
Integer noticeId, String title, String contentHtml, List<Integer> centerCds,
List<FileResponseDto> files, String regUser, LocalDateTime regDt,
List<FileResponseDto> files, String regUser, String regUserName, LocalDateTime regDt,
String modUser, LocalDateTime modDt, boolean viewed
) {
}

View File

@@ -5,7 +5,7 @@ import java.util.List;
public record PopupResponseDto(
Integer popupId, String title, String contentHtml, LocalDateTime startDt,
LocalDateTime endDt, List<Integer> centerCds, String regUser,
LocalDateTime endDt, List<Integer> centerCds, String regUser, String regUserName,
LocalDateTime regDt, String modUser, LocalDateTime modDt, boolean viewed
) {
}

View File

@@ -7,6 +7,6 @@ import java.util.List;
public record QnaAnswerResponseDto(
Integer answerId, String contentHtml, List<FileResponseDto> files,
boolean viewed, String viewUser, LocalDateTime viewDt,
String regUser, LocalDateTime regDt, String modUser, LocalDateTime modDt
String regUser, String regUserName, LocalDateTime regDt, String modUser, LocalDateTime modDt
) {
}

View File

@@ -7,6 +7,6 @@ import java.util.List;
public record QnaQuestionResponseDto(
Integer questionId, Integer centerCd, String centerName, String title,
String contentHtml, List<FileResponseDto> files, QnaAnswerResponseDto answer,
String regUser, LocalDateTime regDt, String modUser, LocalDateTime modDt
String regUser, String regUserName, LocalDateTime regDt, String modUser, LocalDateTime modDt
) {
}

View File

@@ -46,6 +46,7 @@ public class NoticeService {
private final NoticeCenterMapRepository mapRepository;
private final NoticeFileRepository fileRepository;
private final NoticeViewRepository viewRepository;
private final UserService userService;
@Transactional(readOnly = true)
public PageResponseDto<NoticeResponseDto> list(
@@ -65,6 +66,8 @@ public class NoticeService {
criteria.targetCenterCds(),
pageable);
List<Integer> noticeIds = result.getContent().stream().map(TNoticeEntity::getId).toList();
Map<String, String> userNames = userService.findNames(result.getContent().stream()
.map(TNoticeEntity::getRegUser).toList());
Map<Integer, List<FileResponseDto>> filesByNotice = fileRepository
.findByNoticeIdxInOrderByNoticeIdxAscFileOrderAsc(noticeIds).stream()
@@ -91,6 +94,7 @@ public class NoticeService {
targetsByNotice.getOrDefault(entity.getId(), List.of()),
filesByNotice.getOrDefault(entity.getId(), List.of()),
entity.getRegUser(),
userNames.get(entity.getRegUser()),
entity.getRegDt(),
entity.getModUser(),
entity.getModDt(),
@@ -260,7 +264,8 @@ public class NoticeService {
viewed = viewRepository.existsById(id);
}
return new NoticeResponseDto(entity.getId(), entity.getNoticeTitle(), entity.getNoticeContent(),
targets(entity.getId()), files, entity.getRegUser(), entity.getRegDt(), entity.getModUser(), entity.getModDt(), viewed);
targets(entity.getId()), files, entity.getRegUser(), userService.findName(entity.getRegUser()),
entity.getRegDt(), entity.getModUser(), entity.getModDt(), viewed);
}
private FileResponseDto toFileDto(TNoticeFileEntity file) {

View File

@@ -30,6 +30,7 @@ public class PopupService {
private final PopupRepository popupRepository;
private final PopupCenterMapRepository mapRepository;
private final PopupViewRepository viewRepository;
private final UserService userService;
@Transactional(readOnly = true)
public PageResponseDto<PopupResponseDto> list(
@@ -45,6 +46,8 @@ public class PopupService {
criteria.targetCenterCds(),
pageable);
List<Integer> popupIds = result.getContent().stream().map(TPopupEntity::getId).toList();
Map<String, String> userNames = userService.findNames(result.getContent().stream()
.map(TPopupEntity::getRegUser).toList());
Map<Integer, List<Integer>> targetsByPopup = mapRepository.findByIdPopupIdxIn(popupIds).stream()
.collect(Collectors.groupingBy(
value -> value.getId().getPopupIdx(),
@@ -58,6 +61,7 @@ public class PopupService {
popup.getEndDt(),
targetsByPopup.getOrDefault(popup.getId(), List.of()),
popup.getRegUser(),
userNames.get(popup.getRegUser()),
popup.getRegDt(),
popup.getModUser(),
popup.getModDt(),
@@ -72,6 +76,8 @@ public class PopupService {
List<TPopupEntity> popups = popupRepository.findActiveVisible(
center.getCenterCd(), now, now.minusMinutes(1));
List<Integer> popupIds = popups.stream().map(TPopupEntity::getId).toList();
Map<String, String> userNames = userService.findNames(popups.stream()
.map(TPopupEntity::getRegUser).toList());
Map<Integer, List<Integer>> targetsByPopup = mapRepository.findByIdPopupIdxIn(popupIds).stream()
.collect(Collectors.groupingBy(
value -> value.getId().getPopupIdx(),
@@ -95,6 +101,7 @@ public class PopupService {
popup.getEndDt(),
targetsByPopup.getOrDefault(popup.getId(), List.of()),
popup.getRegUser(),
userNames.get(popup.getRegUser()),
popup.getRegDt(),
popup.getModUser(),
popup.getModDt(),
@@ -175,6 +182,6 @@ public class PopupService {
private PopupResponseDto toDto(TPopupEntity p, TUserEntity user) {
boolean viewed=false;
if (accessControlService.isCenter(user.getUserRole())) { TPopupViewEntityId id=new TPopupViewEntityId(); id.setPopupIdx(p.getId()); id.setCenterCd(user.getCenterCd()); viewed=viewRepository.existsById(id); }
return new PopupResponseDto(p.getId(),p.getPopupTitle(),p.getPopupContent(),p.getStartDt(),p.getEndDt(),targets(p.getId()),p.getRegUser(),p.getRegDt(),p.getModUser(),p.getModDt(),viewed);
return new PopupResponseDto(p.getId(),p.getPopupTitle(),p.getPopupContent(),p.getStartDt(),p.getEndDt(),targets(p.getId()),p.getRegUser(),userService.findName(p.getRegUser()),p.getRegDt(),p.getModUser(),p.getModDt(),viewed);
}
}

View File

@@ -40,6 +40,7 @@ public class QnaService {
private final QnaQuestionFileRepository questionFileRepository;
private final QnaAnswerFileRepository answerFileRepository;
private final CenterRepository centerRepository;
private final UserService userService;
@Transactional(readOnly = true)
public PageResponseDto<QnaQuestionResponseDto> list(
@@ -92,6 +93,10 @@ public class QnaService {
Function.identity(),
(first, second) -> second
));
Set<String> regUsers = result.getContent().stream()
.map(TQnaQuestionEntity::getRegUser).collect(Collectors.toSet());
answerByQuestion.values().stream().map(TQnaAnswerEntity::getRegUser).forEach(regUsers::add);
Map<String, String> userNames = userService.findNames(regUsers);
return PageResponseDto.from(result.map(question -> new QnaQuestionResponseDto(
question.getId(),
@@ -101,8 +106,9 @@ public class QnaService {
question.getQuestionContent(),
filesByQuestion.getOrDefault(question.getId(), List.of()),
answerByQuestion.containsKey(question.getId())
? toAnswerSummary(answerByQuestion.get(question.getId())) : null,
? toAnswerSummary(answerByQuestion.get(question.getId()), userNames) : null,
question.getRegUser(),
userNames.get(question.getRegUser()),
question.getRegDt(),
question.getModUser(),
question.getModDt()
@@ -267,17 +273,25 @@ public class QnaService {
QnaAnswerResponseDto answer = answerRepository.findByQnaQuestionIdxAndIsDelFalse(q.getId())
.map(value -> includeDetail ? toAnswerDto(value) : toAnswerSummary(value)).orElse(null);
return new QnaQuestionResponseDto(q.getId(), q.getCenterCd(), centerName, q.getQuestionTitle(),
q.getQuestionContent(), files, answer, q.getRegUser(), q.getRegDt(), q.getModUser(), q.getModDt());
q.getQuestionContent(), files, answer, q.getRegUser(), userService.findName(q.getRegUser()),
q.getRegDt(), q.getModUser(), q.getModDt());
}
private QnaAnswerResponseDto toAnswerDto(TQnaAnswerEntity a) {
var files = answerFileRepository.findByQnaAnswerIdxOrderByFileOrderAsc(a.getId()).stream()
.map(v -> new FileResponseDto(v.getId(), v.getFileOrder(), v.getFileName(), v.getFileType())).toList();
return new QnaAnswerResponseDto(a.getId(), a.getAnswerContent(), files, a.getIsViewAnswer(),
a.getViewUser(), a.getViewDt(), a.getRegUser(), a.getRegDt(), a.getModUser(), a.getModDt());
a.getViewUser(), a.getViewDt(), a.getRegUser(), userService.findName(a.getRegUser()),
a.getRegDt(), a.getModUser(), a.getModDt());
}
private QnaAnswerResponseDto toAnswerSummary(TQnaAnswerEntity a) {
return new QnaAnswerResponseDto(a.getId(), null, List.of(), a.getIsViewAnswer(),
a.getViewUser(), a.getViewDt(), a.getRegUser(), a.getRegDt(), a.getModUser(), a.getModDt());
a.getViewUser(), a.getViewDt(), a.getRegUser(), userService.findName(a.getRegUser()),
a.getRegDt(), a.getModUser(), a.getModDt());
}
private QnaAnswerResponseDto toAnswerSummary(TQnaAnswerEntity a, Map<String, String> userNames) {
return new QnaAnswerResponseDto(a.getId(), null, List.of(), a.getIsViewAnswer(),
a.getViewUser(), a.getViewDt(), a.getRegUser(), userNames.get(a.getRegUser()),
a.getRegDt(), a.getModUser(), a.getModDt());
}
private FileResponseDto toQuestionFileDto(TQnaQuestionFileEntity file) {
return new FileResponseDto(

View File

@@ -5,6 +5,10 @@ import com.kri.ksif.manage.back.dto.auth.LoginRequestDto;
import com.kri.ksif.manage.back.dto.user.UserDto;
import com.kri.ksif.manage.back.persistence.entity.TUserEntity;
import com.kri.ksif.manage.back.persistence.repository.UserRepository;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -23,4 +27,15 @@ public class UserService {
return UserDto.from(userEntity);
}
public String findName(String userId) {
if (userId == null) return null;
return userRepository.findById(userId).map(TUserEntity::getUserName).orElse(null);
}
public Map<String, String> findNames(Collection<String> userIds) {
var ids = userIds.stream().filter(Objects::nonNull).collect(Collectors.toSet());
return userRepository.findAllById(ids).stream()
.collect(Collectors.toMap(TUserEntity::getUserId, TUserEntity::getUserName));
}
}