260922_01_ENH: 공지, 문의, 문의 답변, 팝업 목록 및 내용에 작성자 이름 추가 제공 #2
@@ -6,7 +6,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public record NoticeResponseDto(
|
public record NoticeResponseDto(
|
||||||
Integer noticeId, String title, String contentHtml, List<Integer> centerCds,
|
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
|
String modUser, LocalDateTime modDt, boolean viewed
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public record PopupResponseDto(
|
public record PopupResponseDto(
|
||||||
Integer popupId, String title, String contentHtml, LocalDateTime startDt,
|
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
|
LocalDateTime regDt, String modUser, LocalDateTime modDt, boolean viewed
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import java.util.List;
|
|||||||
public record QnaAnswerResponseDto(
|
public record QnaAnswerResponseDto(
|
||||||
Integer answerId, String contentHtml, List<FileResponseDto> files,
|
Integer answerId, String contentHtml, List<FileResponseDto> files,
|
||||||
boolean viewed, String viewUser, LocalDateTime viewDt,
|
boolean viewed, String viewUser, LocalDateTime viewDt,
|
||||||
String regUser, LocalDateTime regDt, String modUser, LocalDateTime modDt
|
String regUser, String regUserName, LocalDateTime regDt, String modUser, LocalDateTime modDt
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import java.util.List;
|
|||||||
public record QnaQuestionResponseDto(
|
public record QnaQuestionResponseDto(
|
||||||
Integer questionId, Integer centerCd, String centerName, String title,
|
Integer questionId, Integer centerCd, String centerName, String title,
|
||||||
String contentHtml, List<FileResponseDto> files, QnaAnswerResponseDto answer,
|
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
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public class NoticeService {
|
|||||||
private final NoticeCenterMapRepository mapRepository;
|
private final NoticeCenterMapRepository mapRepository;
|
||||||
private final NoticeFileRepository fileRepository;
|
private final NoticeFileRepository fileRepository;
|
||||||
private final NoticeViewRepository viewRepository;
|
private final NoticeViewRepository viewRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public PageResponseDto<NoticeResponseDto> list(
|
public PageResponseDto<NoticeResponseDto> list(
|
||||||
@@ -65,6 +66,8 @@ public class NoticeService {
|
|||||||
criteria.targetCenterCds(),
|
criteria.targetCenterCds(),
|
||||||
pageable);
|
pageable);
|
||||||
List<Integer> noticeIds = result.getContent().stream().map(TNoticeEntity::getId).toList();
|
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
|
Map<Integer, List<FileResponseDto>> filesByNotice = fileRepository
|
||||||
.findByNoticeIdxInOrderByNoticeIdxAscFileOrderAsc(noticeIds).stream()
|
.findByNoticeIdxInOrderByNoticeIdxAscFileOrderAsc(noticeIds).stream()
|
||||||
@@ -91,6 +94,7 @@ public class NoticeService {
|
|||||||
targetsByNotice.getOrDefault(entity.getId(), List.of()),
|
targetsByNotice.getOrDefault(entity.getId(), List.of()),
|
||||||
filesByNotice.getOrDefault(entity.getId(), List.of()),
|
filesByNotice.getOrDefault(entity.getId(), List.of()),
|
||||||
entity.getRegUser(),
|
entity.getRegUser(),
|
||||||
|
userNames.get(entity.getRegUser()),
|
||||||
entity.getRegDt(),
|
entity.getRegDt(),
|
||||||
entity.getModUser(),
|
entity.getModUser(),
|
||||||
entity.getModDt(),
|
entity.getModDt(),
|
||||||
@@ -260,7 +264,8 @@ public class NoticeService {
|
|||||||
viewed = viewRepository.existsById(id);
|
viewed = viewRepository.existsById(id);
|
||||||
}
|
}
|
||||||
return new NoticeResponseDto(entity.getId(), entity.getNoticeTitle(), entity.getNoticeContent(),
|
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) {
|
private FileResponseDto toFileDto(TNoticeFileEntity file) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class PopupService {
|
|||||||
private final PopupRepository popupRepository;
|
private final PopupRepository popupRepository;
|
||||||
private final PopupCenterMapRepository mapRepository;
|
private final PopupCenterMapRepository mapRepository;
|
||||||
private final PopupViewRepository viewRepository;
|
private final PopupViewRepository viewRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public PageResponseDto<PopupResponseDto> list(
|
public PageResponseDto<PopupResponseDto> list(
|
||||||
@@ -45,6 +46,8 @@ public class PopupService {
|
|||||||
criteria.targetCenterCds(),
|
criteria.targetCenterCds(),
|
||||||
pageable);
|
pageable);
|
||||||
List<Integer> popupIds = result.getContent().stream().map(TPopupEntity::getId).toList();
|
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()
|
Map<Integer, List<Integer>> targetsByPopup = mapRepository.findByIdPopupIdxIn(popupIds).stream()
|
||||||
.collect(Collectors.groupingBy(
|
.collect(Collectors.groupingBy(
|
||||||
value -> value.getId().getPopupIdx(),
|
value -> value.getId().getPopupIdx(),
|
||||||
@@ -58,6 +61,7 @@ public class PopupService {
|
|||||||
popup.getEndDt(),
|
popup.getEndDt(),
|
||||||
targetsByPopup.getOrDefault(popup.getId(), List.of()),
|
targetsByPopup.getOrDefault(popup.getId(), List.of()),
|
||||||
popup.getRegUser(),
|
popup.getRegUser(),
|
||||||
|
userNames.get(popup.getRegUser()),
|
||||||
popup.getRegDt(),
|
popup.getRegDt(),
|
||||||
popup.getModUser(),
|
popup.getModUser(),
|
||||||
popup.getModDt(),
|
popup.getModDt(),
|
||||||
@@ -72,6 +76,8 @@ public class PopupService {
|
|||||||
List<TPopupEntity> popups = popupRepository.findActiveVisible(
|
List<TPopupEntity> popups = popupRepository.findActiveVisible(
|
||||||
center.getCenterCd(), now, now.minusMinutes(1));
|
center.getCenterCd(), now, now.minusMinutes(1));
|
||||||
List<Integer> popupIds = popups.stream().map(TPopupEntity::getId).toList();
|
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()
|
Map<Integer, List<Integer>> targetsByPopup = mapRepository.findByIdPopupIdxIn(popupIds).stream()
|
||||||
.collect(Collectors.groupingBy(
|
.collect(Collectors.groupingBy(
|
||||||
value -> value.getId().getPopupIdx(),
|
value -> value.getId().getPopupIdx(),
|
||||||
@@ -95,6 +101,7 @@ public class PopupService {
|
|||||||
popup.getEndDt(),
|
popup.getEndDt(),
|
||||||
targetsByPopup.getOrDefault(popup.getId(), List.of()),
|
targetsByPopup.getOrDefault(popup.getId(), List.of()),
|
||||||
popup.getRegUser(),
|
popup.getRegUser(),
|
||||||
|
userNames.get(popup.getRegUser()),
|
||||||
popup.getRegDt(),
|
popup.getRegDt(),
|
||||||
popup.getModUser(),
|
popup.getModUser(),
|
||||||
popup.getModDt(),
|
popup.getModDt(),
|
||||||
@@ -175,6 +182,6 @@ public class PopupService {
|
|||||||
private PopupResponseDto toDto(TPopupEntity p, TUserEntity user) {
|
private PopupResponseDto toDto(TPopupEntity p, TUserEntity user) {
|
||||||
boolean viewed=false;
|
boolean viewed=false;
|
||||||
if (accessControlService.isCenter(user.getUserRole())) { TPopupViewEntityId id=new TPopupViewEntityId(); id.setPopupIdx(p.getId()); id.setCenterCd(user.getCenterCd()); viewed=viewRepository.existsById(id); }
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class QnaService {
|
|||||||
private final QnaQuestionFileRepository questionFileRepository;
|
private final QnaQuestionFileRepository questionFileRepository;
|
||||||
private final QnaAnswerFileRepository answerFileRepository;
|
private final QnaAnswerFileRepository answerFileRepository;
|
||||||
private final CenterRepository centerRepository;
|
private final CenterRepository centerRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public PageResponseDto<QnaQuestionResponseDto> list(
|
public PageResponseDto<QnaQuestionResponseDto> list(
|
||||||
@@ -92,6 +93,10 @@ public class QnaService {
|
|||||||
Function.identity(),
|
Function.identity(),
|
||||||
(first, second) -> second
|
(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(
|
return PageResponseDto.from(result.map(question -> new QnaQuestionResponseDto(
|
||||||
question.getId(),
|
question.getId(),
|
||||||
@@ -101,8 +106,9 @@ public class QnaService {
|
|||||||
question.getQuestionContent(),
|
question.getQuestionContent(),
|
||||||
filesByQuestion.getOrDefault(question.getId(), List.of()),
|
filesByQuestion.getOrDefault(question.getId(), List.of()),
|
||||||
answerByQuestion.containsKey(question.getId())
|
answerByQuestion.containsKey(question.getId())
|
||||||
? toAnswerSummary(answerByQuestion.get(question.getId())) : null,
|
? toAnswerSummary(answerByQuestion.get(question.getId()), userNames) : null,
|
||||||
question.getRegUser(),
|
question.getRegUser(),
|
||||||
|
userNames.get(question.getRegUser()),
|
||||||
question.getRegDt(),
|
question.getRegDt(),
|
||||||
question.getModUser(),
|
question.getModUser(),
|
||||||
question.getModDt()
|
question.getModDt()
|
||||||
@@ -267,17 +273,25 @@ public class QnaService {
|
|||||||
QnaAnswerResponseDto answer = answerRepository.findByQnaQuestionIdxAndIsDelFalse(q.getId())
|
QnaAnswerResponseDto answer = answerRepository.findByQnaQuestionIdxAndIsDelFalse(q.getId())
|
||||||
.map(value -> includeDetail ? toAnswerDto(value) : toAnswerSummary(value)).orElse(null);
|
.map(value -> includeDetail ? toAnswerDto(value) : toAnswerSummary(value)).orElse(null);
|
||||||
return new QnaQuestionResponseDto(q.getId(), q.getCenterCd(), centerName, q.getQuestionTitle(),
|
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) {
|
private QnaAnswerResponseDto toAnswerDto(TQnaAnswerEntity a) {
|
||||||
var files = answerFileRepository.findByQnaAnswerIdxOrderByFileOrderAsc(a.getId()).stream()
|
var files = answerFileRepository.findByQnaAnswerIdxOrderByFileOrderAsc(a.getId()).stream()
|
||||||
.map(v -> new FileResponseDto(v.getId(), v.getFileOrder(), v.getFileName(), v.getFileType())).toList();
|
.map(v -> new FileResponseDto(v.getId(), v.getFileOrder(), v.getFileName(), v.getFileType())).toList();
|
||||||
return new QnaAnswerResponseDto(a.getId(), a.getAnswerContent(), files, a.getIsViewAnswer(),
|
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) {
|
private QnaAnswerResponseDto toAnswerSummary(TQnaAnswerEntity a) {
|
||||||
return new QnaAnswerResponseDto(a.getId(), null, List.of(), a.getIsViewAnswer(),
|
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) {
|
private FileResponseDto toQuestionFileDto(TQnaQuestionFileEntity file) {
|
||||||
return new FileResponseDto(
|
return new FileResponseDto(
|
||||||
|
|||||||
@@ -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.dto.user.UserDto;
|
||||||
import com.kri.ksif.manage.back.persistence.entity.TUserEntity;
|
import com.kri.ksif.manage.back.persistence.entity.TUserEntity;
|
||||||
import com.kri.ksif.manage.back.persistence.repository.UserRepository;
|
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 lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -23,4 +27,15 @@ public class UserService {
|
|||||||
|
|
||||||
return UserDto.from(userEntity);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user