260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋
This commit is contained in:
@@ -27,13 +27,15 @@ public enum SystemEventType implements CodeEnum<Short> {
|
||||
ASSIGN_PERFORMANCE_CONFIRM((short) 1032), //공연 배정 승인
|
||||
ASSIGN_PERFORMANCE_REJECT((short) 1033), //공연 배정 거절
|
||||
ASSIGN_PERFORMANCE_FORCE((short) 1034), //강제 공연 배정
|
||||
UPLOAD_WRITTEN_ASSIGN((short) 1036),
|
||||
|
||||
VISIT_START((short) 2011), //모니터링 출발
|
||||
VISIT_END((short) 2012), //모니터링 도착
|
||||
|
||||
UPLOAD_MONITORING_REVIEW((short) 2041), //모니터링 결과보고서 업로드
|
||||
UPLOAD_LOCAL_GOV_REVIEW((short) 2042), //지자체 결과보고서 업로드
|
||||
UPDATE_WRITTEN_REVIEW((short) 2043), //지자체 결과보고서 업로드
|
||||
START_WRITTEN_REVIEW((short) 2044), // 서면 평가 시작
|
||||
END_WRITTEN_REVIEW((short) 2045), // 서면평가 종료
|
||||
|
||||
DUMMY((short) 9999);
|
||||
|
||||
|
||||
@@ -1,17 +1,34 @@
|
||||
package com.kri.gwcf.review.back.controller;
|
||||
|
||||
import static com.kri.gwcf.review.back.common.util.ExcelResponseBuilder.buildExcelResponse;
|
||||
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.gwcf.review.back.dto.assign.AssignUserCountDto;
|
||||
import com.kri.gwcf.review.back.dto.assign.MonitoringAssignSaveRequestDto;
|
||||
import com.kri.gwcf.review.back.dto.excel.ExcelUploadResultDto;
|
||||
import com.kri.gwcf.review.back.dto.kon.PerformanceApplyCountDto;
|
||||
import com.kri.gwcf.review.back.dto.monitoring.MonitoringApplyUserDto;
|
||||
import com.kri.gwcf.review.back.dto.performance.PerformanceAssignDto;
|
||||
import com.kri.gwcf.review.back.dto.systemlog.UploadContentDto;
|
||||
import com.kri.gwcf.review.back.service.AssignService;
|
||||
import com.kri.gwcf.review.back.service.common.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/assign")
|
||||
@@ -22,12 +39,116 @@ public class AssignController {
|
||||
private final AssignService assignService;
|
||||
private final SystemEventLogService systemEventLogService;
|
||||
|
||||
@Operation(summary = "사용자별 배정 건수 조회")
|
||||
@GetMapping("/users/count")
|
||||
public List<AssignUserCountDto> findAssignUserCounts() {
|
||||
return assignService.findAssignUserCounts();
|
||||
}
|
||||
|
||||
@Operation(summary = "모니터링 신청자 목록")
|
||||
@GetMapping("/monitoring/apply-users/{performanceId}")
|
||||
public List<MonitoringApplyUserDto> findMonitoringApplyUsers(
|
||||
@PathVariable Integer performanceId
|
||||
) {
|
||||
return assignService.findMonitoringApplyUsers(performanceId);
|
||||
}
|
||||
|
||||
@Operation(summary = "공연별 모니터링 신청자 수")
|
||||
@GetMapping("/monitoring/apply-users/count")
|
||||
public List<PerformanceApplyCountDto> findMonitoringApplyUsersCount() {
|
||||
return assignService.findMonitoringApplyUsersCount();
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "참여 동의")
|
||||
@PostMapping("/confirm/{userId}")
|
||||
public boolean assignConfirm(@PathVariable String userId, RequestUserContext ctx) {
|
||||
@PostMapping("/confirm/{performanceId}/{userId}")
|
||||
public String assignConfirm(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable String userId,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
//TODO: 기능 구현 필요
|
||||
systemEventLogService.writeAssignConfirmLog(userId, now, ctx.getClientIp());
|
||||
return false;
|
||||
String result = assignService.confirmMonitoringAssignByUser(performanceId, userId);
|
||||
systemEventLogService.writeAssignConfirmLog(userId, now, ctx.getClientIp(), String.valueOf(performanceId));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "모니터링 배정 저장")
|
||||
@PostMapping("/monitoring")
|
||||
public List<PerformanceAssignDto> saveMonitoringAssign(
|
||||
@RequestBody MonitoringAssignSaveRequestDto dto,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
List<PerformanceAssignDto> result =
|
||||
assignService.saveMonitoringAssign(dto.getPerformanceId(), dto.getUserIds(), ctx.getUserId(), now);
|
||||
systemEventLogService.writeAssignPerformanceRequestLog(
|
||||
ctx.getUserId(),
|
||||
now,
|
||||
ctx.getClientIp(),
|
||||
dto.getPerformanceId(),
|
||||
dto.getUserIds()
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "서면평가위원 일괄 배정 양식 다운로드")
|
||||
@PostMapping("/written/excel/template")
|
||||
public ResponseEntity<byte[]> exportUserTemplate() {
|
||||
byte[] bytes = assignService.exportAssignTemplate();
|
||||
return buildExcelResponse("user_assign_template.xlsx", bytes);
|
||||
}
|
||||
|
||||
@Operation(summary = "서면평가위원 일괄 배정(엑셀 업로드)")
|
||||
@PostMapping(value = "/written/excel/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ExcelUploadResultDto createWrittenAssignsFromExcel(
|
||||
@RequestParam("file") MultipartFile file,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
ExcelUploadResultDto result = assignService.createWrittenAssignsFromExcel(file, ctx.getUserId(), now);
|
||||
systemEventLogService.writeUploadWrittenAssignLog(
|
||||
ctx.getUserId(),
|
||||
now,
|
||||
ctx.getClientIp(),
|
||||
UploadContentDto.from(file)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "배정 확정")
|
||||
@PatchMapping("/confirm/{performanceId}/{userId}")
|
||||
public void confirmAssign(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable String userId,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
assignService.confirmAssign(performanceId, userId, true);
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
systemEventLogService.writeAssignConfirmByAdminLog(
|
||||
ctx.getUserId(),
|
||||
now,
|
||||
ctx.getClientIp(),
|
||||
performanceId,
|
||||
userId
|
||||
);
|
||||
}
|
||||
|
||||
@Operation(summary = "배정 취소")
|
||||
@PatchMapping("/cancel/{performanceId}/{userId}")
|
||||
public void cancelAssign(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable String userId,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
assignService.confirmAssign(performanceId, userId, false);
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
systemEventLogService.writeAssignCancelLog(
|
||||
ctx.getUserId(),
|
||||
now,
|
||||
ctx.getClientIp(),
|
||||
performanceId,
|
||||
userId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.kri.gwcf.review.back.controller;
|
||||
|
||||
import com.kri.gwcf.review.back.dto.common.CodeDto;
|
||||
import com.kri.gwcf.review.back.service.CodeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/code")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Code", description = "코드 API")
|
||||
public class CodeController {
|
||||
|
||||
private final CodeService codeService;
|
||||
|
||||
@Operation(summary = "코드 조회")
|
||||
@GetMapping("/{codeGroup}")
|
||||
public List<CodeDto> getCodeList(@PathVariable String codeGroup) {
|
||||
return codeService.findByCodeGroup(codeGroup);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.kri.gwcf.review.back.controller;
|
||||
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.gwcf.review.back.dto.monitoring.MonitoringGpsRequestDto;
|
||||
import com.kri.gwcf.review.back.dto.performance.PerformanceMonitoringVisitDto;
|
||||
import com.kri.gwcf.review.back.service.VisitService;
|
||||
import com.kri.gwcf.review.back.service.common.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/monitoring/visit")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Monitoring Visit", description = "모니터링 방문 API")
|
||||
public class MonitoringVisitController {
|
||||
|
||||
private final VisitService visitService;
|
||||
private final SystemEventLogService systemEventLogService;
|
||||
|
||||
@Operation(summary = "모니터링 출발 저장")
|
||||
@PostMapping("/departure/{performanceId}")
|
||||
public PerformanceMonitoringVisitDto saveDeparture(
|
||||
@PathVariable Integer performanceId,
|
||||
@RequestBody MonitoringGpsRequestDto gps,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
PerformanceMonitoringVisitDto result = visitService.saveDeparture(performanceId, gps, ctx.getUserId(), now);
|
||||
systemEventLogService.writeVisitStartLog(ctx.getUserId(), now, ctx.getClientIp(), performanceId);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "모니터링 도착 저장 + 증빙 사진 업로드")
|
||||
@PostMapping(value = "/arrival/{performanceId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public PerformanceMonitoringVisitDto saveArrival(
|
||||
@PathVariable Integer performanceId,
|
||||
@RequestPart("gps") MonitoringGpsRequestDto gps,
|
||||
@RequestPart(value = "files", required = false) List<MultipartFile> files,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
PerformanceMonitoringVisitDto result = visitService.saveArrival(performanceId, gps, files, ctx.getUserId(), now);
|
||||
int evidenceFileCount = files == null ? 0 : (int) files.stream()
|
||||
.filter(file -> file != null && !file.isEmpty())
|
||||
.count();
|
||||
systemEventLogService.writeVisitEndLog(
|
||||
ctx.getUserId(),
|
||||
now,
|
||||
ctx.getClientIp(),
|
||||
performanceId,
|
||||
evidenceFileCount
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "증빙 사진 조회")
|
||||
@GetMapping("/evidence/{performanceId}/{userId}")
|
||||
public List<PerformanceMonitoringVisitDto> findEvidence(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable String userId
|
||||
) {
|
||||
return visitService.findEvidence(performanceId, userId);
|
||||
}
|
||||
|
||||
@Operation(summary = "증빙 사진 ZIP 다운로드")
|
||||
@GetMapping("/evidence/zip/{performanceId}/{userId}")
|
||||
public ResponseEntity<byte[]> downloadEvidenceZip(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable String userId
|
||||
) {
|
||||
byte[] bytes = visitService.downloadEvidenceZip(performanceId, userId);
|
||||
String fileName = "evidence_" + performanceId + "_" + userId + ".zip";
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
ContentDisposition.attachment().filename(fileName).build().toString())
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(bytes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.kri.gwcf.review.back.controller;
|
||||
|
||||
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.gwcf.review.back.dto.performance.PerformanceReviewDto;
|
||||
import com.kri.gwcf.review.back.dto.systemlog.UploadContentDto;
|
||||
import com.kri.gwcf.review.back.service.ReviewService;
|
||||
import com.kri.gwcf.review.back.service.common.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/review")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Review", description = "평가/모니터링 API")
|
||||
public class ReviewController {
|
||||
|
||||
private final ReviewService reviewService;
|
||||
private final SystemEventLogService systemEventLogService;
|
||||
|
||||
@Operation(summary = "서면평가 시작 저장")
|
||||
@PostMapping("/start/{performanceId}")
|
||||
public PerformanceReviewDto startWrittenReview(
|
||||
@PathVariable Integer performanceId,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
PerformanceReviewDto result = reviewService.saveWrittenReviewStatus(performanceId, 1, ctx.getUserId(), now);
|
||||
systemEventLogService.writeStartWrittenReviewLog(ctx.getUserId(), now, ctx.getClientIp(), performanceId);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "서면평가 완료 저장")
|
||||
@PostMapping("/end/{performanceId}/{userId}")
|
||||
public PerformanceReviewDto endWrittenReview(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable String userId,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
PerformanceReviewDto result = reviewService.saveWrittenReviewStatus(performanceId, 10, userId, now);
|
||||
systemEventLogService.writeEndWrittenReviewLog(userId, now, ctx.getClientIp(), performanceId);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "평가/모니터링 파일 업로드")
|
||||
@PostMapping(value = "/{performanceId}/{reviewType}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public PerformanceReviewDto uploadReviewFile(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable Integer reviewType,
|
||||
@RequestParam("file") MultipartFile file,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
PerformanceReviewDto result = reviewService.uploadReviewFile(performanceId, reviewType, file, ctx.getUserId(), now);
|
||||
systemEventLogService.writeUploadReviewFileLog(
|
||||
ctx.getUserId(),
|
||||
now,
|
||||
ctx.getClientIp(),
|
||||
performanceId,
|
||||
reviewType,
|
||||
UploadContentDto.from(file)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "평가/모니터링 파일 조회")
|
||||
@GetMapping("/{performanceId}/{reviewType}")
|
||||
public PerformanceReviewDto getReviewFile(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable Integer reviewType,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return reviewService.getReviewFile(performanceId, reviewType, ctx.getUserId());
|
||||
}
|
||||
|
||||
@Operation(summary = "평가/모니터링 원본 파일 다운로드")
|
||||
@GetMapping("/download/{performanceId}/{reviewType}")
|
||||
public ResponseEntity<Resource> downloadOriginalFile(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable Integer reviewType,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return download(
|
||||
reviewService.getOriginalFileResource(performanceId, reviewType, ctx.getUserId()),
|
||||
reviewService.getOriginalFileName(performanceId, reviewType, ctx.getUserId())
|
||||
);
|
||||
}
|
||||
|
||||
@Operation(summary = "PDF 변환 파일 조회/다운로드")
|
||||
@GetMapping("/pdf/{performanceId}/{reviewType}")
|
||||
public ResponseEntity<Resource> downloadPdfOrOriginalFile(
|
||||
@PathVariable Integer performanceId,
|
||||
@PathVariable Integer reviewType,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return download(
|
||||
reviewService.getPdfOrOriginalFileResource(performanceId, reviewType, ctx.getUserId()),
|
||||
reviewService.getPdfOrOriginalFileName(performanceId, reviewType, ctx.getUserId())
|
||||
);
|
||||
}
|
||||
|
||||
private ResponseEntity<Resource> download(Resource resource, String fileName) {
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
ContentDisposition.attachment().filename(fileName).build().toString())
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(resource);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.kri.gwcf.review.back.dto.assign;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class AssignUserCountDto {
|
||||
|
||||
@Schema(description = "배정 사용자 ID")
|
||||
private String assignUser;
|
||||
|
||||
@Schema(description = "배정 건수")
|
||||
private Long assignCount;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.kri.gwcf.review.back.dto.assign;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class MonitoringAssignSaveRequestDto {
|
||||
|
||||
@Schema(description = "공연 ID")
|
||||
private Integer performanceId;
|
||||
|
||||
@Schema(description = "모니터링 요원 사용자 ID 목록")
|
||||
private List<String> userIds;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.kri.gwcf.review.back.dto.excel;
|
||||
|
||||
import com.kri.common.feature.excel.ExcelColumn;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WrittenUserAssignDto {
|
||||
|
||||
@ExcelColumn(header = "사용자 ID", order = 0, width = 11)
|
||||
@Schema(description = "사용자 ID")
|
||||
private String userId;
|
||||
|
||||
@ExcelColumn(header = "사업 연번", order = 1, width = 10)
|
||||
@Schema(description = "사업 연번")
|
||||
private String performanceId;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.kri.gwcf.review.back.dto.kon;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "KON 공연 신청 자")
|
||||
public class PerformanceApplyUserDto {
|
||||
|
||||
@Schema(description = "공연 ID")
|
||||
private String performanceId;
|
||||
|
||||
@Schema(description = "신청자 ID")
|
||||
private String userId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.kri.gwcf.review.back.dto.monitoring;
|
||||
|
||||
import com.kri.gwcf.review.back.dto.user.UserCompactDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@Schema(description = "모니터링 신청자")
|
||||
public class MonitoringApplyUserDto {
|
||||
|
||||
@Schema(description = "공연 ID")
|
||||
private Integer performanceId;
|
||||
|
||||
@Schema(description = "신청자 ID")
|
||||
private String userId;
|
||||
|
||||
@Schema(description = "서비스 DB 사용자 정보")
|
||||
private UserCompactDto user;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.kri.gwcf.review.back.dto.monitoring;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "모니터링 GPS 정보")
|
||||
public class MonitoringGpsRequestDto {
|
||||
|
||||
@Schema(description = "GPS 위도")
|
||||
private BigDecimal gpsLatitude;
|
||||
|
||||
@Schema(description = "GPS 경도")
|
||||
private BigDecimal gpsLongitude;
|
||||
|
||||
@Schema(description = "GPS 신뢰 반경(m)")
|
||||
private BigDecimal gpsAccuracyM;
|
||||
|
||||
@Schema(description = "GPS Raw Data")
|
||||
private Map<String, Object> gpsRaw;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.kri.gwcf.review.back.dto.performance;
|
||||
|
||||
import com.kri.gwcf.review.back.persistence.entity.TPerformanceMonitoringVisitEntity;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -42,6 +43,12 @@ public class PerformanceMonitoringVisitDto {
|
||||
@Schema(description = "GPS Raw Data")
|
||||
private Map<String, Object> gpsRaw;
|
||||
|
||||
@Schema(description = "등록자")
|
||||
private String regUser;
|
||||
|
||||
@Schema(description = "등록일시")
|
||||
private LocalDateTime regDate;
|
||||
|
||||
public static PerformanceMonitoringVisitDto from(TPerformanceMonitoringVisitEntity entity) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
@@ -56,6 +63,8 @@ public class PerformanceMonitoringVisitDto {
|
||||
.gpsLongitude(entity.getGpsLongitude())
|
||||
.gpsAccuracyM(entity.getGpsAccuracyM())
|
||||
.gpsRaw(entity.getGpsRaw())
|
||||
.regUser(entity.getRegUser())
|
||||
.regDate(entity.getRegDt())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ public class PerformanceReviewDto {
|
||||
@Schema(description = "평가 타입")
|
||||
private Integer reviewType;
|
||||
|
||||
@Schema(description = "등록 사용자")
|
||||
private String regUser;
|
||||
|
||||
@Schema(description = "평가 상태")
|
||||
private Integer reviewStatus;
|
||||
|
||||
@@ -42,6 +45,7 @@ public class PerformanceReviewDto {
|
||||
return PerformanceReviewDto.builder()
|
||||
.performanceId(entity.getPerformanceId())
|
||||
.reviewType(entity.getReviewType())
|
||||
.regUser(entity.getRegUser())
|
||||
.reviewStatus(entity.getReviewStatus())
|
||||
.uploadFileName(entity.getUploadFileName())
|
||||
.pdfConvert(entity.getPdfConvert())
|
||||
|
||||
@@ -85,6 +85,8 @@ public class TPerformanceMonitoringVisitEntity {
|
||||
entity.setGpsLongitude(dto.getGpsLongitude());
|
||||
entity.setGpsAccuracyM(dto.getGpsAccuracyM());
|
||||
entity.setGpsRaw(dto.getGpsRaw());
|
||||
entity.setRegUser(dto.getRegUser());
|
||||
entity.setRegDt(dto.getRegDate());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ public class TPerformanceReviewEntity {
|
||||
@Column(name = "review_status", nullable = false)
|
||||
private Integer reviewStatus;
|
||||
|
||||
@Size(max = 512)
|
||||
@NotNull
|
||||
@Column(name = "upload_file_name", nullable = false, length = 512)
|
||||
private String uploadFileName;
|
||||
@@ -39,16 +38,10 @@ public class TPerformanceReviewEntity {
|
||||
@Column(name = "is_pdf_convert", nullable = false)
|
||||
private Boolean pdfConvert;
|
||||
|
||||
@Size(max = 512)
|
||||
@NotNull
|
||||
@Column(name = "pdf_file_name", nullable = false, length = 512)
|
||||
private String pdfFileName;
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "reg_user", nullable = false, length = 32, updatable = false)
|
||||
private String regUser;
|
||||
|
||||
@NotNull
|
||||
@ColumnDefault("CURRENT_TIMESTAMP")
|
||||
@Column(name = "reg_dt", nullable = false, updatable = false)
|
||||
@@ -69,6 +62,17 @@ public class TPerformanceReviewEntity {
|
||||
return id.getReviewType();
|
||||
}
|
||||
|
||||
public String getRegUser() {
|
||||
return id == null ? null : id.getRegUser();
|
||||
}
|
||||
|
||||
public void setRegUser(String regUser) {
|
||||
if (id == null) {
|
||||
id = new TPerformanceReviewEntityId();
|
||||
}
|
||||
id.setRegUser(regUser);
|
||||
}
|
||||
|
||||
public static TPerformanceReviewEntity from(PerformanceReviewDto dto) {
|
||||
if (dto == null) {
|
||||
return null;
|
||||
@@ -78,6 +82,7 @@ public class TPerformanceReviewEntity {
|
||||
entity.setId(TPerformanceReviewEntityId.builder()
|
||||
.performanceId(dto.getPerformanceId())
|
||||
.reviewType(dto.getReviewType())
|
||||
.regUser(dto.getRegUser())
|
||||
.build());
|
||||
entity.setReviewStatus(dto.getReviewStatus());
|
||||
entity.setUploadFileName(dto.getUploadFileName());
|
||||
|
||||
@@ -86,6 +86,8 @@ public class TUserDetailEntity {
|
||||
.userDetailKey(userDetailKey)
|
||||
.build())
|
||||
.userDetailValue(userDetailValue)
|
||||
.regUser(modUser)
|
||||
.regDt(modDt)
|
||||
.modUser(modUser)
|
||||
.modDt(modDt)
|
||||
.build();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.kri.gwcf.review.back.persistence.entity.id;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -27,5 +28,8 @@ public class TPerformanceReviewEntityId implements Serializable {
|
||||
@Column(name = "review_type", nullable = false, updatable = false)
|
||||
private Integer reviewType;
|
||||
|
||||
|
||||
@Size(max = 32)
|
||||
@NotNull
|
||||
@Column(name = "reg_user", nullable = false, length = 32, updatable = false)
|
||||
private String regUser;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kri.gwcf.review.back.persistence.mapper.kon;
|
||||
|
||||
import com.kri.gwcf.review.back.dto.kon.PerformanceApplyCountDto;
|
||||
import com.kri.gwcf.review.back.dto.kon.PerformanceApplyUserDto;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -11,4 +12,9 @@ public interface KonMapper {
|
||||
List<PerformanceApplyCountDto> findPerformanceApplyCount(
|
||||
@Param("surveyType") String surveyType
|
||||
);
|
||||
|
||||
List<PerformanceApplyUserDto> findPerformanceApplyUser(
|
||||
@Param("surveyType") String surveyType,
|
||||
@Param("performanceId") String performanceId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.kri.gwcf.review.back.persistence.repository;
|
||||
|
||||
import com.kri.gwcf.review.back.persistence.entity.TPerformanceAssignEntity;
|
||||
import com.kri.gwcf.review.back.dto.assign.AssignUserCountDto;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface PerformanceAssignRepository extends JpaRepository<TPerformanceAssignEntity, Long> {
|
||||
|
||||
@@ -11,4 +13,42 @@ public interface PerformanceAssignRepository extends JpaRepository<TPerformanceA
|
||||
boolean existsByPerformanceId(Integer performanceId);
|
||||
|
||||
List<TPerformanceAssignEntity> findByPerformanceId(Integer performanceId);
|
||||
|
||||
boolean existsByPerformanceIdAndAssignUser(Integer performanceId, String assignUser);
|
||||
|
||||
boolean existsByAssignUserAndPerformanceIdNot(String assignUser, Integer performanceId);
|
||||
|
||||
long countByPerformanceIdAndAssignType(Integer performanceId, Integer assignType);
|
||||
|
||||
long countByPerformanceIdAndAssignTypeAndAssignConfirm(
|
||||
Integer performanceId,
|
||||
Integer assignType,
|
||||
Boolean assignConfirm
|
||||
);
|
||||
|
||||
List<TPerformanceAssignEntity> findByPerformanceIdAndAssignUser(
|
||||
Integer performanceId,
|
||||
String assignUser
|
||||
);
|
||||
|
||||
List<TPerformanceAssignEntity> findByPerformanceIdAndAssignUserAndAssignType(
|
||||
Integer performanceId,
|
||||
String assignUser,
|
||||
Integer assignType
|
||||
);
|
||||
|
||||
List<TPerformanceAssignEntity> findByPerformanceIdAndAssignType(
|
||||
Integer performanceId,
|
||||
Integer assignType
|
||||
);
|
||||
|
||||
@Query("""
|
||||
select new com.kri.gwcf.review.back.dto.assign.AssignUserCountDto(
|
||||
assign.assignUser,
|
||||
count(assign)
|
||||
)
|
||||
from TPerformanceAssignEntity assign
|
||||
group by assign.assignUser
|
||||
""")
|
||||
List<AssignUserCountDto> countGroupByAssignUser();
|
||||
}
|
||||
|
||||
@@ -11,4 +11,9 @@ public interface PerformanceMonitoringVisitRepository extends JpaRepository<TPer
|
||||
boolean existsByPerformanceId(Integer performanceId);
|
||||
|
||||
List<TPerformanceMonitoringVisitEntity> findByPerformanceId(Integer performanceId);
|
||||
|
||||
List<TPerformanceMonitoringVisitEntity> findByPerformanceIdAndRegUser(
|
||||
Integer performanceId,
|
||||
String regUser
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,26 @@ package com.kri.gwcf.review.back.persistence.repository;
|
||||
import com.kri.gwcf.review.back.persistence.entity.TPerformanceReviewEntity;
|
||||
import com.kri.gwcf.review.back.persistence.entity.id.TPerformanceReviewEntityId;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PerformanceReviewRepository extends JpaRepository<TPerformanceReviewEntity, TPerformanceReviewEntityId> {
|
||||
|
||||
boolean existsByRegUserOrModUser(String regUser, String modUser);
|
||||
boolean existsByIdRegUserOrModUser(String regUser, String modUser);
|
||||
|
||||
boolean existsByIdPerformanceId(Integer performanceId);
|
||||
|
||||
List<TPerformanceReviewEntity> findByIdPerformanceId(Integer performanceId);
|
||||
|
||||
Optional<TPerformanceReviewEntity> findByIdPerformanceIdAndIdReviewTypeAndIdRegUser(
|
||||
Integer performanceId,
|
||||
Integer reviewType,
|
||||
String regUser
|
||||
);
|
||||
|
||||
boolean existsByIdPerformanceIdAndIdReviewTypeAndIdRegUser(
|
||||
Integer performanceId,
|
||||
Integer reviewType,
|
||||
String regUser
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,62 @@
|
||||
package com.kri.gwcf.review.back.service;
|
||||
|
||||
import static com.kri.gwcf.review.back.common.consts.GwcfConstant.MONITORING_USER_ROLE;
|
||||
import static com.kri.gwcf.review.back.common.util.AppendCodeSheet.appendCodeSheet;
|
||||
|
||||
import com.kri.common.feature.excel.ExcelMapper;
|
||||
import com.kri.common.feature.util.NumericUtil;
|
||||
import com.kri.common.feature.util.StringUtil;
|
||||
import com.kri.gwcf.review.back.common.util.ExcelUploadResultUtil;
|
||||
import com.kri.gwcf.review.back.dto.assign.AssignUserCountDto;
|
||||
import com.kri.gwcf.review.back.dto.excel.ExcelErrorDto;
|
||||
import com.kri.gwcf.review.back.dto.excel.ExcelUploadResultDto;
|
||||
import com.kri.gwcf.review.back.dto.excel.WrittenUserAssignDto;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.gwcf.review.back.dto.kon.PerformanceApplyCountDto;
|
||||
import com.kri.gwcf.review.back.dto.kon.PerformanceApplyUserDto;
|
||||
import com.kri.gwcf.review.back.dto.monitoring.MonitoringApplyUserDto;
|
||||
import com.kri.gwcf.review.back.dto.performance.PerformanceAssignDto;
|
||||
import com.kri.gwcf.review.back.dto.user.UserCompactDto;
|
||||
import com.kri.gwcf.review.back.persistence.entity.TPerformanceAssignEntity;
|
||||
import com.kri.gwcf.review.back.persistence.entity.TUserDetailEntity;
|
||||
import com.kri.gwcf.review.back.persistence.entity.TUserEntity;
|
||||
import com.kri.gwcf.review.back.persistence.mapper.kon.KonMapper;
|
||||
import com.kri.gwcf.review.back.persistence.repository.PerformanceAssignRepository;
|
||||
import com.kri.gwcf.review.back.persistence.repository.PerformanceRepository;
|
||||
import com.kri.gwcf.review.back.persistence.repository.PerformanceReviewRepository;
|
||||
import com.kri.gwcf.review.back.persistence.repository.UserDetailRepository;
|
||||
import com.kri.gwcf.review.back.persistence.repository.UserRepository;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AssignService {
|
||||
|
||||
private final PerformanceAssignRepository performanceAssignRepository;
|
||||
private final PerformanceReviewRepository performanceReviewRepository;
|
||||
private final KonMapper konMapper;
|
||||
private final PerformanceRepository performanceRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final UserDetailRepository userDetailRepository;
|
||||
|
||||
@Value("${kon.survey-type:LIST}")
|
||||
private String surveyType;
|
||||
|
||||
public boolean hasAssignWithUser(String userId) {
|
||||
return performanceAssignRepository.existsByAssignUser(userId);
|
||||
@@ -25,4 +71,386 @@ public class AssignService {
|
||||
.map(PerformanceAssignDto::from)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<AssignUserCountDto> findAssignUserCounts() {
|
||||
return performanceAssignRepository.countGroupByAssignUser();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true, transactionManager = "konTransactionManager")
|
||||
public List<PerformanceApplyUserDto> findKonPerformanceApplyUser(Integer performanceId) {
|
||||
return konMapper.findPerformanceApplyUser(surveyType, String.valueOf(performanceId));
|
||||
}
|
||||
|
||||
public List<PerformanceApplyCountDto> findMonitoringApplyUsersCount() {
|
||||
return konMapper.findPerformanceApplyCount(surveyType);
|
||||
}
|
||||
|
||||
public List<MonitoringApplyUserDto> findMonitoringApplyUsers(Integer performanceId) {
|
||||
List<PerformanceApplyUserDto> applyUsers = findKonPerformanceApplyUser(performanceId);
|
||||
List<String> userIds = applyUsers.stream()
|
||||
.map(PerformanceApplyUserDto::getUserId)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
Map<String, TUserEntity> userMap = userRepository.findAllById(userIds).stream()
|
||||
.collect(Collectors.toMap(TUserEntity::getUserId, Function.identity()));
|
||||
|
||||
Map<String, Map<String, String>> userDetailMap = userIds.stream()
|
||||
.collect(Collectors.toMap(
|
||||
Function.identity(),
|
||||
userId -> userDetailRepository.findByIdUserId(userId).stream()
|
||||
.collect(Collectors.toMap(
|
||||
TUserDetailEntity::getUserDetailKey,
|
||||
TUserDetailEntity::getUserDetailValue
|
||||
))
|
||||
));
|
||||
|
||||
return applyUsers.stream()
|
||||
.map(applyUser -> {
|
||||
TUserEntity user = userMap.get(applyUser.getUserId());
|
||||
return MonitoringApplyUserDto.builder()
|
||||
.performanceId(performanceId)
|
||||
.userId(applyUser.getUserId())
|
||||
.user(user == null
|
||||
? null
|
||||
: UserCompactDto.from(
|
||||
user,
|
||||
userDetailMap.getOrDefault(applyUser.getUserId(), Collections.emptyMap())
|
||||
))
|
||||
.build();
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PerformanceAssignDto saveMonitoringAssign(
|
||||
Integer performanceId,
|
||||
String assignUser,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
if (performanceAssignRepository.existsByAssignUser(assignUser)) {
|
||||
throw BusinessException.conflict("ASSIGN_ALREADY_EXISTS", "이미 배정된 사용자입니다.")
|
||||
.with("performanceId", performanceId)
|
||||
.with("assignUser", assignUser);
|
||||
}
|
||||
|
||||
long currentCount = performanceAssignRepository.countByPerformanceIdAndAssignType(performanceId, 1);
|
||||
TPerformanceAssignEntity entity = new TPerformanceAssignEntity();
|
||||
entity.setPerformanceId(performanceId);
|
||||
entity.setAssignType(1);
|
||||
entity.setAssignOrder((short) (currentCount + 1));
|
||||
entity.setAssignUser(assignUser);
|
||||
entity.setAssignConfirm(false);
|
||||
entity.setRegUser(regUser);
|
||||
entity.setRegDt(regDt);
|
||||
|
||||
return PerformanceAssignDto.from(performanceAssignRepository.save(entity));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<PerformanceAssignDto> saveMonitoringAssign(
|
||||
Integer performanceId,
|
||||
List<String> assignUsers,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
if (performanceId == null) {
|
||||
throw BusinessException.badRequest("EMPTY_PERFORMANCE_ID", "공연 ID가 없습니다.");
|
||||
}
|
||||
if (!performanceRepository.existsById(performanceId)) {
|
||||
throw BusinessException.notFound("PERFORMANCE_NOT_FOUND", "존재하지 않는 공연입니다.")
|
||||
.with("performanceId", performanceId);
|
||||
}
|
||||
|
||||
List<String> normalizedAssignUsers = normalizeUserIds(assignUsers);
|
||||
if (normalizedAssignUsers.size() > 2) {
|
||||
throw BusinessException.badRequest("MONITORING_ASSIGN_LIMIT", "모니터링 요원은 최대 2명까지 배정할 수 있습니다.")
|
||||
.with("performanceId", performanceId)
|
||||
.with("assignUsers", normalizedAssignUsers);
|
||||
}
|
||||
|
||||
for (String assignUser : normalizedAssignUsers) {
|
||||
validateAssignableUser(performanceId, assignUser);
|
||||
}
|
||||
|
||||
List<TPerformanceAssignEntity> currentAssigns =
|
||||
performanceAssignRepository.findByPerformanceIdAndAssignType(performanceId, 1);
|
||||
Set<String> requestedUserSet = Set.copyOf(normalizedAssignUsers);
|
||||
List<TPerformanceAssignEntity> deleteTargets = currentAssigns.stream()
|
||||
.filter(assign -> !requestedUserSet.contains(assign.getAssignUser()))
|
||||
.toList();
|
||||
|
||||
for (TPerformanceAssignEntity deleteTarget : deleteTargets) {
|
||||
validateNoReviewBeforeAssignRemove(deleteTarget);
|
||||
}
|
||||
performanceAssignRepository.deleteAll(deleteTargets);
|
||||
|
||||
Set<String> currentUserSet = currentAssigns.stream()
|
||||
.filter(assign -> requestedUserSet.contains(assign.getAssignUser()))
|
||||
.map(TPerformanceAssignEntity::getAssignUser)
|
||||
.collect(Collectors.toSet());
|
||||
Map<String, TPerformanceAssignEntity> currentAssignMap = currentAssigns.stream()
|
||||
.filter(assign -> requestedUserSet.contains(assign.getAssignUser()))
|
||||
.collect(Collectors.toMap(
|
||||
TPerformanceAssignEntity::getAssignUser,
|
||||
Function.identity(),
|
||||
(first, second) -> first
|
||||
));
|
||||
|
||||
short assignOrder = 1;
|
||||
for (String assignUser : normalizedAssignUsers) {
|
||||
if (!currentUserSet.contains(assignUser)) {
|
||||
TPerformanceAssignEntity entity = new TPerformanceAssignEntity();
|
||||
entity.setPerformanceId(performanceId);
|
||||
entity.setAssignType(1);
|
||||
entity.setAssignOrder(assignOrder);
|
||||
entity.setAssignUser(assignUser);
|
||||
entity.setAssignConfirm(false);
|
||||
entity.setRegUser(regUser);
|
||||
entity.setRegDt(regDt);
|
||||
performanceAssignRepository.save(entity);
|
||||
} else {
|
||||
currentAssignMap.get(assignUser).setAssignOrder(assignOrder);
|
||||
}
|
||||
assignOrder++;
|
||||
}
|
||||
|
||||
return performanceAssignRepository.findByPerformanceIdAndAssignType(performanceId, 1).stream()
|
||||
.map(PerformanceAssignDto::from)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public byte[] exportAssignTemplate() {
|
||||
try (Workbook workbook =
|
||||
ExcelMapper.writeToWorkbook(Collections.emptyList(), WrittenUserAssignDto.class);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
workbook.write(out);
|
||||
return out.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw BusinessException.internalError("사용자 배정 템플릿 엑셀 생성 중 오류");
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ExcelUploadResultDto createWrittenAssignsFromExcel(
|
||||
MultipartFile file,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw BusinessException.badRequest("EMPTY_FILE", "업로드된 파일이 없습니다.");
|
||||
}
|
||||
|
||||
String fileName = file.getOriginalFilename();
|
||||
String errorFileName = fileName != null && fileName.endsWith(".xlsx")
|
||||
? fileName.substring(0, fileName.length() - 5) + "_error.xlsx"
|
||||
: fileName + "_error.xlsx";
|
||||
|
||||
List<WrittenUserAssignDto> rows;
|
||||
try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
|
||||
rows = ExcelMapper.readFromWorkbook(workbook, WrittenUserAssignDto.class);
|
||||
} catch (Exception e) {
|
||||
throw BusinessException.badRequest("INVALID_EXCEL", "엑셀 파일을 읽는 중 오류가 발생했습니다.")
|
||||
.with("fileName", fileName);
|
||||
}
|
||||
|
||||
int totalCount = rows.size();
|
||||
int successCount = 0;
|
||||
List<ExcelErrorDto> errorList = new ArrayList<>();
|
||||
Set<Integer> uploadedPerformanceIds = new java.util.HashSet<>();
|
||||
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
WrittenUserAssignDto row = rows.get(i);
|
||||
int rowNumber = i + 2;
|
||||
|
||||
List<ExcelErrorDto> rowErrors = validateWrittenAssignRow(row, rowNumber);
|
||||
if (!rowErrors.isEmpty()) {
|
||||
errorList.addAll(rowErrors);
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer performanceId = NumericUtil.parseOnlyInteger(row.getPerformanceId());
|
||||
if (!uploadedPerformanceIds.add(performanceId)) {
|
||||
errorList.add(ExcelErrorDto.of(rowNumber, "사업 연번", "하나의 사업에는 서면평가위원을 1명만 배정할 수 있습니다."));
|
||||
continue;
|
||||
}
|
||||
|
||||
List<TPerformanceAssignEntity> currentAssigns =
|
||||
performanceAssignRepository.findByPerformanceIdAndAssignType(performanceId, 2);
|
||||
boolean sameAssignExists = currentAssigns.size() == 1
|
||||
&& Objects.equals(currentAssigns.get(0).getAssignUser(), row.getUserId());
|
||||
if (!sameAssignExists && currentAssigns.stream().anyMatch(this::hasReview)) {
|
||||
errorList.add(ExcelErrorDto.of(rowNumber, "사업 연번", "리뷰가 있는 배정은 변경할 수 없습니다."));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sameAssignExists) {
|
||||
successCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
performanceAssignRepository.deleteAll(currentAssigns);
|
||||
|
||||
TPerformanceAssignEntity entity = new TPerformanceAssignEntity();
|
||||
entity.setPerformanceId(performanceId);
|
||||
entity.setAssignType(2);
|
||||
entity.setAssignOrder((short) 1);
|
||||
entity.setAssignUser(row.getUserId());
|
||||
entity.setAssignConfirm(true);
|
||||
entity.setRegUser(regUser);
|
||||
entity.setRegDt(regDt);
|
||||
performanceAssignRepository.save(entity);
|
||||
successCount++;
|
||||
}
|
||||
|
||||
int failCount = errorList.stream()
|
||||
.map(ExcelErrorDto::getRowNumber)
|
||||
.distinct()
|
||||
.toList()
|
||||
.size();
|
||||
|
||||
return ExcelUploadResultUtil.buildUploadResult(
|
||||
totalCount,
|
||||
successCount,
|
||||
failCount,
|
||||
errorList,
|
||||
ExcelErrorDto.class,
|
||||
errorFileName
|
||||
);
|
||||
}
|
||||
|
||||
private List<ExcelErrorDto> validateWrittenAssignRow(
|
||||
WrittenUserAssignDto row,
|
||||
int rowNumber
|
||||
) {
|
||||
List<ExcelErrorDto> errors = new ArrayList<>();
|
||||
Integer performanceId = NumericUtil.parseOnlyInteger(row.getPerformanceId());
|
||||
String userId = row.getUserId();
|
||||
|
||||
if (performanceId == null) {
|
||||
errors.add(ExcelErrorDto.of(rowNumber, "사업 연번", "사업 연번은 숫자여야 합니다."));
|
||||
} else if (!performanceRepository.existsById(performanceId)) {
|
||||
errors.add(ExcelErrorDto.of(rowNumber, "사업 연번", "존재하지 않는 사업 연번입니다."));
|
||||
}
|
||||
|
||||
if (StringUtil.isNullOrBlank(userId)) {
|
||||
errors.add(ExcelErrorDto.of(rowNumber, "사용자 ID", "사용자 ID가 비어 있습니다."));
|
||||
} else if (!userRepository.existsByUserId(userId)) {
|
||||
errors.add(ExcelErrorDto.of(rowNumber, "사용자 ID", "존재하지 않는 사용자 ID입니다."));
|
||||
}
|
||||
|
||||
if (StringUtil.hasText(userId)
|
||||
&& performanceId != null
|
||||
&& performanceAssignRepository.existsByAssignUserAndPerformanceIdNot(userId, performanceId)) {
|
||||
errors.add(ExcelErrorDto.of(rowNumber, "사용자 ID", "이미 다른 사업에 배정된 사용자입니다."));
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
private List<String> normalizeUserIds(List<String> userIds) {
|
||||
if (userIds == null) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return userIds.stream()
|
||||
.filter(StringUtil::hasText)
|
||||
.map(String::trim)
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
|
||||
private void validateAssignableUser(Integer performanceId, String userId) {
|
||||
if (StringUtil.isNullOrBlank(userId)) {
|
||||
throw BusinessException.badRequest("EMPTY_USER_ID", "사용자 ID가 없습니다.");
|
||||
}
|
||||
if (!userRepository.existsByUserId(userId)) {
|
||||
throw BusinessException.notFound("USER_NOT_FOUND", "존재하지 않는 사용자 ID입니다.")
|
||||
.with("userId", userId);
|
||||
}
|
||||
if (performanceAssignRepository.existsByAssignUserAndPerformanceIdNot(userId, performanceId)) {
|
||||
throw BusinessException.conflict("ASSIGN_ALREADY_EXISTS", "이미 다른 공연에 배정된 사용자입니다.")
|
||||
.with("performanceId", performanceId)
|
||||
.with("assignUser", userId);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasReview(TPerformanceAssignEntity assign) {
|
||||
return performanceReviewRepository.existsByIdPerformanceIdAndIdReviewTypeAndIdRegUser(
|
||||
assign.getPerformanceId(),
|
||||
assign.getAssignType(),
|
||||
assign.getAssignUser()
|
||||
);
|
||||
}
|
||||
|
||||
private void validateNoReviewBeforeAssignRemove(TPerformanceAssignEntity assign) {
|
||||
if (hasReview(assign)) {
|
||||
throw BusinessException.conflict("ASSIGN_HAS_REVIEW", "리뷰가 있는 배정은 해제하거나 삭제할 수 없습니다.")
|
||||
.with("performanceId", assign.getPerformanceId())
|
||||
.with("assignType", assign.getAssignType())
|
||||
.with("assignUser", assign.getAssignUser());
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String confirmMonitoringAssignByUser(Integer performanceId, String assignUser) {
|
||||
List<TPerformanceAssignEntity> assigns =
|
||||
performanceAssignRepository.findByPerformanceIdAndAssignUserAndAssignType(
|
||||
performanceId,
|
||||
assignUser,
|
||||
1
|
||||
);
|
||||
|
||||
if (assigns.isEmpty()) {
|
||||
return "승인 가능한 내용이 없습니다.";
|
||||
}
|
||||
|
||||
boolean alreadyConfirmed = assigns.stream()
|
||||
.anyMatch(assign -> Boolean.TRUE.equals(assign.getAssignConfirm()));
|
||||
if (alreadyConfirmed) {
|
||||
return "이미 승인된 내용입니다.";
|
||||
}
|
||||
|
||||
long confirmedCount = performanceAssignRepository
|
||||
.countByPerformanceIdAndAssignTypeAndAssignConfirm(performanceId, 1, true);
|
||||
if (confirmedCount >= 2) {
|
||||
return "이미 배정이 종료된 공연입니다.";
|
||||
}
|
||||
|
||||
assigns.stream()
|
||||
.filter(assign -> Boolean.FALSE.equals(assign.getAssignConfirm()))
|
||||
.forEach(assign -> assign.setAssignConfirm(true));
|
||||
|
||||
return "승인 처리 됐습니다.";
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void confirmAssign(Integer performanceId, String assignUser, boolean confirm) {
|
||||
List<TPerformanceAssignEntity> assigns =
|
||||
performanceAssignRepository.findByPerformanceIdAndAssignUser(performanceId, assignUser);
|
||||
if (assigns.isEmpty()) {
|
||||
throw BusinessException.notFound("ASSIGN_NOT_FOUND", "배정 정보를 찾을 수 없습니다.")
|
||||
.with("performanceId", performanceId)
|
||||
.with("assignUser", assignUser);
|
||||
}
|
||||
|
||||
for (TPerformanceAssignEntity assign : assigns) {
|
||||
if (!confirm && hasReview(assign)) {
|
||||
throw BusinessException.conflict("ASSIGN_HAS_REVIEW", "리뷰가 있는 배정은 해제하거나 삭제할 수 없습니다.")
|
||||
.with("performanceId", performanceId)
|
||||
.with("assignType", assign.getAssignType())
|
||||
.with("assignUser", assignUser);
|
||||
}
|
||||
if (confirm && Boolean.FALSE.equals(assign.getAssignConfirm())) {
|
||||
long confirmedCount = performanceAssignRepository
|
||||
.countByPerformanceIdAndAssignTypeAndAssignConfirm(performanceId, assign.getAssignType(), true);
|
||||
if (assign.getAssignType() == 1 && confirmedCount >= 2) {
|
||||
throw BusinessException.conflict("MONITORING_ASSIGN_CONFIRM_LIMIT", "확정된 모니터링 요원은 최대 2명입니다.")
|
||||
.with("performanceId", performanceId);
|
||||
}
|
||||
}
|
||||
assign.setAssignConfirm(confirm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,49 @@
|
||||
package com.kri.gwcf.review.back.service;
|
||||
|
||||
import com.kri.common.feature.util.StringUtil;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.gwcf.review.back.config.FileStorageProperties;
|
||||
import com.kri.gwcf.review.back.dto.performance.PerformanceReviewDto;
|
||||
import com.kri.gwcf.review.back.persistence.entity.TPerformanceReviewEntity;
|
||||
import com.kri.gwcf.review.back.persistence.entity.id.TPerformanceReviewEntityId;
|
||||
import com.kri.gwcf.review.back.persistence.repository.PerformanceReviewRepository;
|
||||
import com.kri.gwcf.review.back.service.file.AbstractFileService;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.PathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ReviewService {
|
||||
public class ReviewService extends AbstractFileService {
|
||||
|
||||
private final PerformanceReviewRepository performanceReviewRepository;
|
||||
private final FileStorageProperties fileStorageProperties;
|
||||
|
||||
@Value("${kri.file.pdf-converter-command:soffice}")
|
||||
private String pdfConverterCommand;
|
||||
|
||||
@Override
|
||||
protected Path getBaseDir() {
|
||||
return Path.of(fileStorageProperties.getReviewBaseDir())
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
}
|
||||
|
||||
public boolean hasReviewWithUser(String userId) {
|
||||
return performanceReviewRepository.existsByRegUserOrModUser(userId, userId);
|
||||
return performanceReviewRepository.existsByIdRegUserOrModUser(userId, userId);
|
||||
}
|
||||
|
||||
public boolean hasReviewWithPerformance(Integer performanceId) {
|
||||
@@ -30,4 +57,207 @@ public class ReviewService {
|
||||
Collectors.mapping(PerformanceReviewDto::from, Collectors.toList())
|
||||
));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PerformanceReviewDto saveWrittenReviewStatus(
|
||||
Integer performanceId,
|
||||
Integer reviewStatus,
|
||||
String userId,
|
||||
LocalDateTime now
|
||||
) {
|
||||
TPerformanceReviewEntity entity = performanceReviewRepository
|
||||
.findByIdPerformanceIdAndIdReviewTypeAndIdRegUser(performanceId, 2, userId)
|
||||
.orElseGet(() -> TPerformanceReviewEntity.builder()
|
||||
.id(TPerformanceReviewEntityId.builder()
|
||||
.performanceId(performanceId)
|
||||
.reviewType(2)
|
||||
.regUser(userId)
|
||||
.build())
|
||||
.uploadFileName("")
|
||||
.pdfConvert(false)
|
||||
.pdfFileName("")
|
||||
.regDt(now)
|
||||
.build());
|
||||
|
||||
entity.setReviewStatus(reviewStatus);
|
||||
if (entity.getRegUser() == null) {
|
||||
entity.setRegUser(userId);
|
||||
entity.setRegDt(now);
|
||||
} else {
|
||||
entity.setModUser(userId);
|
||||
entity.setModDt(now);
|
||||
}
|
||||
|
||||
return PerformanceReviewDto.from(performanceReviewRepository.save(entity));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PerformanceReviewDto saveMonitoringReviewStatus(
|
||||
Integer performanceId,
|
||||
Integer reviewStatus,
|
||||
String userId,
|
||||
LocalDateTime now
|
||||
) {
|
||||
TPerformanceReviewEntity entity = performanceReviewRepository
|
||||
.findByIdPerformanceIdAndIdReviewTypeAndIdRegUser(performanceId, 1, userId)
|
||||
.orElseGet(() -> TPerformanceReviewEntity.builder()
|
||||
.id(TPerformanceReviewEntityId.builder()
|
||||
.performanceId(performanceId)
|
||||
.reviewType(1)
|
||||
.regUser(userId)
|
||||
.build())
|
||||
.uploadFileName("")
|
||||
.pdfConvert(false)
|
||||
.pdfFileName("")
|
||||
.regDt(now)
|
||||
.build());
|
||||
|
||||
entity.setReviewStatus(reviewStatus);
|
||||
entity.setModUser(userId);
|
||||
entity.setModDt(now);
|
||||
|
||||
return PerformanceReviewDto.from(performanceReviewRepository.save(entity));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PerformanceReviewDto uploadReviewFile(
|
||||
Integer performanceId,
|
||||
Integer reviewType,
|
||||
MultipartFile file,
|
||||
String userId,
|
||||
LocalDateTime now
|
||||
) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw BusinessException.badRequest("EMPTY_FILE", "업로드할 파일이 없습니다.");
|
||||
}
|
||||
|
||||
try {
|
||||
Path dir = reviewDir(performanceId, reviewType);
|
||||
String uploadFileName = saveFile(dir, file);
|
||||
Path uploadPath = dir.resolve(uploadFileName).normalize();
|
||||
|
||||
String pdfFileName = convertToPdfIfPossible(uploadPath, dir);
|
||||
boolean pdfConvert = StringUtil.hasText(pdfFileName);
|
||||
|
||||
TPerformanceReviewEntity entity = performanceReviewRepository
|
||||
.findByIdPerformanceIdAndIdReviewTypeAndIdRegUser(performanceId, reviewType, userId)
|
||||
.orElseGet(() -> TPerformanceReviewEntity.builder()
|
||||
.id(TPerformanceReviewEntityId.builder()
|
||||
.performanceId(performanceId)
|
||||
.reviewType(reviewType)
|
||||
.regUser(userId)
|
||||
.build())
|
||||
.regDt(now)
|
||||
.build());
|
||||
|
||||
entity.setReviewStatus(10);
|
||||
entity.setUploadFileName(uploadFileName);
|
||||
entity.setPdfConvert(pdfConvert);
|
||||
entity.setPdfFileName(pdfFileName);
|
||||
if (entity.getRegUser() == null) {
|
||||
entity.setRegUser(userId);
|
||||
entity.setRegDt(now);
|
||||
} else {
|
||||
entity.setModUser(userId);
|
||||
entity.setModDt(now);
|
||||
}
|
||||
|
||||
return PerformanceReviewDto.from(performanceReviewRepository.save(entity));
|
||||
} catch (IOException e) {
|
||||
throw BusinessException.internalError("REVIEW_FILE_SAVE_FAILED", "평가/모니터링 파일 저장 중 오류가 발생했습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
public PerformanceReviewDto getReviewFile(Integer performanceId, Integer reviewType, String userId) {
|
||||
return PerformanceReviewDto.from(getReviewEntity(performanceId, reviewType, userId));
|
||||
}
|
||||
|
||||
public PathResource getOriginalFileResource(Integer performanceId, Integer reviewType, String userId) {
|
||||
TPerformanceReviewEntity entity = getReviewEntity(performanceId, reviewType, userId);
|
||||
return toResource(reviewDir(performanceId, reviewType).resolve(entity.getUploadFileName()));
|
||||
}
|
||||
|
||||
public String getOriginalFileName(Integer performanceId, Integer reviewType, String userId) {
|
||||
return getReviewEntity(performanceId, reviewType, userId).getUploadFileName();
|
||||
}
|
||||
|
||||
public PathResource getPdfOrOriginalFileResource(Integer performanceId, Integer reviewType, String userId) {
|
||||
TPerformanceReviewEntity entity = getReviewEntity(performanceId, reviewType, userId);
|
||||
String fileName = StringUtil.isNullOrBlank(entity.getPdfFileName())
|
||||
? entity.getUploadFileName()
|
||||
: entity.getPdfFileName();
|
||||
return toResource(reviewDir(performanceId, reviewType).resolve(fileName));
|
||||
}
|
||||
|
||||
public String getPdfOrOriginalFileName(Integer performanceId, Integer reviewType, String userId) {
|
||||
TPerformanceReviewEntity entity = getReviewEntity(performanceId, reviewType, userId);
|
||||
return StringUtil.isNullOrBlank(entity.getPdfFileName())
|
||||
? entity.getUploadFileName()
|
||||
: entity.getPdfFileName();
|
||||
}
|
||||
|
||||
private TPerformanceReviewEntity getReviewEntity(Integer performanceId, Integer reviewType, String userId) {
|
||||
return performanceReviewRepository.findByIdPerformanceIdAndIdReviewTypeAndIdRegUser(
|
||||
performanceId,
|
||||
reviewType,
|
||||
userId
|
||||
)
|
||||
.orElseThrow(() -> BusinessException.notFound("REVIEW_FILE_NOT_FOUND", "평가/모니터링 파일이 없습니다.")
|
||||
.with("performanceId", performanceId)
|
||||
.with("reviewType", reviewType)
|
||||
.with("userId", userId));
|
||||
}
|
||||
|
||||
private PathResource toResource(Path path) {
|
||||
Path normalized = path.toAbsolutePath().normalize();
|
||||
if (!Files.exists(normalized)) {
|
||||
throw BusinessException.notFound("FILE_NOT_FOUND", "파일이 없습니다.");
|
||||
}
|
||||
return new PathResource(normalized);
|
||||
}
|
||||
|
||||
private Path reviewDir(Integer performanceId, Integer reviewType) {
|
||||
return getBaseDir()
|
||||
.resolve(String.valueOf(performanceId))
|
||||
.resolve(String.valueOf(reviewType))
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
}
|
||||
|
||||
private String convertToPdfIfPossible(Path source, Path dir) {
|
||||
String extension = extractExtension(source.getFileName().toString()).toLowerCase();
|
||||
Set<String> targets = new HashSet<>(Set.of(".docx", ".hwpx", ".pptx", ".xlsx"));
|
||||
if (!targets.contains(extension)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
Process process = new ProcessBuilder(
|
||||
pdfConverterCommand,
|
||||
"--headless",
|
||||
"--convert-to",
|
||||
"pdf",
|
||||
"--outdir",
|
||||
dir.toString(),
|
||||
source.toString()
|
||||
).redirectErrorStream(true).start();
|
||||
|
||||
boolean finished = process.waitFor(60, TimeUnit.SECONDS);
|
||||
if (!finished || process.exitValue() != 0) {
|
||||
process.destroyForcibly();
|
||||
return "";
|
||||
}
|
||||
|
||||
String baseName = stripExtension(source.getFileName().toString());
|
||||
Path pdf = dir.resolve(baseName + ".pdf").normalize();
|
||||
return Files.exists(pdf) ? pdf.getFileName().toString() : "";
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private String stripExtension(String fileName) {
|
||||
int dot = fileName.lastIndexOf('.');
|
||||
return dot > 0 ? fileName.substring(0, dot) : fileName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,43 @@
|
||||
package com.kri.gwcf.review.back.service;
|
||||
|
||||
import com.kri.common.feature.util.StringUtil;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.gwcf.review.back.config.FileStorageProperties;
|
||||
import com.kri.gwcf.review.back.dto.monitoring.MonitoringGpsRequestDto;
|
||||
import com.kri.gwcf.review.back.dto.performance.PerformanceMonitoringVisitDto;
|
||||
import com.kri.gwcf.review.back.persistence.entity.TPerformanceMonitoringVisitEntity;
|
||||
import com.kri.gwcf.review.back.persistence.repository.PerformanceMonitoringVisitRepository;
|
||||
import com.kri.gwcf.review.back.service.file.AbstractFileService;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class VisitService {
|
||||
public class VisitService extends AbstractFileService {
|
||||
|
||||
private final PerformanceMonitoringVisitRepository performanceMonitoringVisitRepository;
|
||||
private final FileStorageProperties fileStorageProperties;
|
||||
private final ReviewService reviewService;
|
||||
|
||||
@Override
|
||||
protected Path getBaseDir() {
|
||||
return Path.of(fileStorageProperties.getVisitBaseDir())
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
}
|
||||
|
||||
public boolean hasVisitWithUser(String userId) {
|
||||
return performanceMonitoringVisitRepository.existsByRegUser(userId);
|
||||
@@ -30,4 +54,151 @@ public class VisitService {
|
||||
Collectors.mapping(PerformanceMonitoringVisitDto::from, Collectors.toList())
|
||||
));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PerformanceMonitoringVisitDto saveDeparture(
|
||||
Integer performanceId,
|
||||
MonitoringGpsRequestDto gps,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
validateGps(gps);
|
||||
TPerformanceMonitoringVisitEntity entity = saveVisit(
|
||||
performanceId,
|
||||
2,
|
||||
"",
|
||||
gps,
|
||||
regUser,
|
||||
regDt
|
||||
);
|
||||
reviewService.saveMonitoringReviewStatus(performanceId, 2, regUser, regDt);
|
||||
return PerformanceMonitoringVisitDto.from(entity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PerformanceMonitoringVisitDto saveArrival(
|
||||
Integer performanceId,
|
||||
MonitoringGpsRequestDto gps,
|
||||
List<MultipartFile> files,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
validateGps(gps);
|
||||
String evidenceImg = String.join("|", saveEvidenceFiles(performanceId, regUser, files));
|
||||
|
||||
TPerformanceMonitoringVisitEntity entity = saveVisit(
|
||||
performanceId,
|
||||
3,
|
||||
evidenceImg,
|
||||
gps,
|
||||
regUser,
|
||||
regDt
|
||||
);
|
||||
reviewService.saveMonitoringReviewStatus(performanceId, 3, regUser, regDt);
|
||||
return PerformanceMonitoringVisitDto.from(entity);
|
||||
}
|
||||
|
||||
public List<PerformanceMonitoringVisitDto> findEvidence(Integer performanceId, String userId) {
|
||||
return performanceMonitoringVisitRepository.findByPerformanceIdAndRegUser(performanceId, userId)
|
||||
.stream()
|
||||
.map(PerformanceMonitoringVisitDto::from)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public byte[] downloadEvidenceZip(Integer performanceId, String userId) {
|
||||
List<String> fileNames = performanceMonitoringVisitRepository
|
||||
.findByPerformanceIdAndRegUser(performanceId, userId)
|
||||
.stream()
|
||||
.flatMap(visit -> List.of(visit.getEvidenceImg().split("\\|")).stream())
|
||||
.filter(StringUtil::hasText)
|
||||
.toList();
|
||||
|
||||
try (
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(out)
|
||||
) {
|
||||
Path dir = evidenceDir(performanceId, userId);
|
||||
for (String fileName : fileNames) {
|
||||
Path file = dir.resolve(fileName).normalize();
|
||||
if (!file.startsWith(dir) || !Files.exists(file)) {
|
||||
continue;
|
||||
}
|
||||
zip.putNextEntry(new ZipEntry(fileName));
|
||||
Files.copy(file, zip);
|
||||
zip.closeEntry();
|
||||
}
|
||||
zip.finish();
|
||||
return out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw BusinessException.internalError("EVIDENCE_ZIP_FAILED", "증빙 사진 ZIP 생성 중 오류가 발생했습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private TPerformanceMonitoringVisitEntity saveVisit(
|
||||
Integer performanceId,
|
||||
Integer status,
|
||||
String evidenceImg,
|
||||
MonitoringGpsRequestDto gps,
|
||||
String regUser,
|
||||
LocalDateTime regDt
|
||||
) {
|
||||
TPerformanceMonitoringVisitEntity entity = TPerformanceMonitoringVisitEntity.builder()
|
||||
.performanceId(performanceId)
|
||||
.monitoringVisitStatus(status)
|
||||
.evidenceImg(evidenceImg)
|
||||
.gpsLatitude(gps.getGpsLatitude())
|
||||
.gpsLongitude(gps.getGpsLongitude())
|
||||
.gpsAccuracyM(gps.getGpsAccuracyM())
|
||||
.gpsRaw(gps.getGpsRaw())
|
||||
.regUser(regUser)
|
||||
.regDt(regDt)
|
||||
.build();
|
||||
|
||||
return performanceMonitoringVisitRepository.save(entity);
|
||||
}
|
||||
|
||||
private List<String> saveEvidenceFiles(
|
||||
Integer performanceId,
|
||||
String userId,
|
||||
List<MultipartFile> files
|
||||
) {
|
||||
if (files == null || files.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
try {
|
||||
Path dir = evidenceDir(performanceId, userId);
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
for (MultipartFile file : files) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String fileName = saveFile(dir, file);
|
||||
fileNames.add(fileName);
|
||||
}
|
||||
return fileNames;
|
||||
} catch (IOException e) {
|
||||
throw BusinessException.internalError("EVIDENCE_SAVE_FAILED", "증빙 사진 저장 중 오류가 발생했습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private Path evidenceDir(Integer performanceId, String userId) {
|
||||
return getBaseDir()
|
||||
.resolve(String.valueOf(performanceId))
|
||||
.resolve(userId)
|
||||
.toAbsolutePath()
|
||||
.normalize();
|
||||
}
|
||||
|
||||
private void validateGps(MonitoringGpsRequestDto gps) {
|
||||
// GPS 필수 정책을 해제해야 하면 아래 if 블록만 주석 처리.
|
||||
if (gps == null
|
||||
|| gps.getGpsLatitude() == null
|
||||
|| gps.getGpsLongitude() == null
|
||||
|| gps.getGpsAccuracyM() == null
|
||||
|| gps.getGpsRaw() == null
|
||||
|| gps.getGpsRaw().isEmpty()) {
|
||||
throw BusinessException.badRequest("EMPTY_GPS_INFO", "GPS 정보가 없습니다.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.kri.gwcf.review.back.dto.user.UserFullDto;
|
||||
import com.kri.gwcf.review.back.persistence.entity.TSysEventLogEntity;
|
||||
import com.kri.gwcf.review.back.persistence.repository.SysEventLogRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -118,15 +119,183 @@ public class SystemEventLogService {
|
||||
);
|
||||
}
|
||||
|
||||
public void writeAssignConfirmLog(String userId, LocalDateTime regDt, String clientIp) {
|
||||
public void writeAssignConfirmLog(String userId, LocalDateTime regDt, String clientIp, String performanceId) {
|
||||
writeSystemLog(
|
||||
SystemEventType.ASSIGN_PERFORMANCE_CONFIRM,
|
||||
"Assign Confirm",
|
||||
userId,
|
||||
regDt,
|
||||
clientIp,
|
||||
"userId",
|
||||
userId
|
||||
"performanceId",
|
||||
performanceId
|
||||
);
|
||||
}
|
||||
|
||||
public void writeVisitStartLog(String regId, LocalDateTime regDt, String clientIp, Integer performanceId) {
|
||||
writeSystemLog(
|
||||
SystemEventType.VISIT_START,
|
||||
"Visit Start",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
"performanceId",
|
||||
performanceId
|
||||
);
|
||||
}
|
||||
|
||||
public void writeVisitEndLog(
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
Integer performanceId,
|
||||
Integer evidenceFileCount
|
||||
) {
|
||||
saveLog(
|
||||
SystemEventType.VISIT_END,
|
||||
"Visit End",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
Map.of(
|
||||
"performanceId", performanceId,
|
||||
"evidenceFileCount", evidenceFileCount
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void writeStartWrittenReviewLog(
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
Integer performanceId
|
||||
) {
|
||||
writeSystemLog(
|
||||
SystemEventType.START_WRITTEN_REVIEW,
|
||||
"Start Written Review",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
"performanceId",
|
||||
performanceId
|
||||
);
|
||||
}
|
||||
|
||||
public void writeEndWrittenReviewLog(
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
Integer performanceId
|
||||
) {
|
||||
writeSystemLog(
|
||||
SystemEventType.END_WRITTEN_REVIEW,
|
||||
"End Written Review",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
"performanceId",
|
||||
performanceId
|
||||
);
|
||||
}
|
||||
|
||||
public void writeUploadReviewFileLog(
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
Integer performanceId,
|
||||
Integer reviewType,
|
||||
UploadContentDto content
|
||||
) {
|
||||
SystemEventType eventType = Integer.valueOf(1).equals(reviewType)
|
||||
? SystemEventType.UPLOAD_MONITORING_REVIEW
|
||||
: SystemEventType.UPLOAD_LOCAL_GOV_REVIEW;
|
||||
|
||||
saveLog(
|
||||
eventType,
|
||||
"Upload Review File",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
Map.of(
|
||||
"performanceId", performanceId,
|
||||
"reviewType", reviewType,
|
||||
"file", content
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void writeAssignPerformanceRequestLog(
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
Integer performanceId,
|
||||
List<String> assignUsers
|
||||
) {
|
||||
saveLog(
|
||||
SystemEventType.ASSIGN_PERFORMANCE_REQUEST,
|
||||
"Assign Performance Request",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
Map.of(
|
||||
"performanceId", performanceId,
|
||||
"assignUsers", assignUsers
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void writeAssignConfirmByAdminLog(
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
Integer performanceId,
|
||||
String assignUser
|
||||
) {
|
||||
saveLog(
|
||||
SystemEventType.ASSIGN_PERFORMANCE_CONFIRM,
|
||||
"Assign Confirm",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
Map.of(
|
||||
"performanceId", performanceId,
|
||||
"assignUser", assignUser
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void writeUploadWrittenAssignLog(
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
UploadContentDto content
|
||||
) {
|
||||
writeSystemLog(
|
||||
SystemEventType.UPLOAD_WRITTEN_ASSIGN,
|
||||
"Upload Written Assign",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
content
|
||||
);
|
||||
}
|
||||
|
||||
public void writeAssignCancelLog(
|
||||
String regId,
|
||||
LocalDateTime regDt,
|
||||
String clientIp,
|
||||
Integer performanceId,
|
||||
String assignUser
|
||||
) {
|
||||
saveLog(
|
||||
SystemEventType.ASSIGN_PERFORMANCE_REJECT,
|
||||
"Assign Cancel",
|
||||
regId,
|
||||
regDt,
|
||||
clientIp,
|
||||
Map.of(
|
||||
"performanceId", performanceId,
|
||||
"assignUser", assignUser
|
||||
)
|
||||
);
|
||||
}
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user