251212_01_ENH : 프로젝트 정보 저장 api연동 테스트 완료
This commit is contained in:
@@ -28,6 +28,7 @@ kri:
|
||||
- /swagger-ui/**
|
||||
- /ping
|
||||
- /api/v1/auth/login
|
||||
- /contact-senario/**
|
||||
|
||||
swagger:
|
||||
enabled: true
|
||||
@@ -36,6 +37,12 @@ kri:
|
||||
version: "v1.0.0"
|
||||
base-package: "com.kri.contact.server"
|
||||
|
||||
contact-senario:
|
||||
upload-base-dir: ./upload-file/contact-senario
|
||||
public-base-url: /contact-senario
|
||||
temp-expire-hours: 24
|
||||
temp-cleanup-cron: "0 0 0 * * *" # 매일 00:00(초 분 시 일 월 요일)
|
||||
|
||||
common:
|
||||
web:
|
||||
enabled: true # 공통 Web 구성 사용 여부 (기본 true)
|
||||
@@ -44,4 +51,4 @@ common:
|
||||
redis:
|
||||
enabled: false # RedisQueueHelper 사용 시 true
|
||||
scheduling:
|
||||
enabled: false # @Scheduled 사용 시 true
|
||||
enabled: true # @Scheduled 사용 시 true
|
||||
@@ -37,18 +37,20 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "com.kri.common:starter:beta.1.0.32"
|
||||
implementation "com.kri.common:starter:beta.1.0.33"
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.11"
|
||||
|
||||
//Jsoup (HTML 파싱용)
|
||||
implementation 'org.jsoup:jsoup:1.17.2'
|
||||
|
||||
//JPA
|
||||
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
|
||||
//MySQL
|
||||
runtimeOnly "com.mysql:mysql-connector-j"
|
||||
|
||||
// QueryDSL JPA
|
||||
implementation "com.querydsl:querydsl-jpa:5.0.0:jakarta"
|
||||
|
||||
|
||||
@@ -5,6 +5,4 @@ public final class AppConstant {
|
||||
|
||||
public static final int OUTSOURCE_USER_ROLE = 4000;
|
||||
public static final int FIELDWORK_USER_ROLE = 9000;
|
||||
|
||||
public static final int INSERT_RETRY_COUNT = 2;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.kri.contact.server.common.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.kri.common.enums.CodeEnum;
|
||||
|
||||
public enum ResultCodeType implements CodeEnum<Short> {
|
||||
@@ -15,7 +17,17 @@ public enum ResultCodeType implements CodeEnum<Short> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public Short getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static ResultCodeType fromCode(Short code) {
|
||||
if (code == null) return null;
|
||||
for (ResultCodeType s : values()) {
|
||||
if (s.code == code) return s;
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ResultCodeType code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,7 @@ public enum SystemEventType implements CodeEnum<Short> {
|
||||
CREAT_PROJECT((short) 21), // 프로젝트 생성
|
||||
UPDATE_PROJECT((short) 22), // 프로젝트 수정
|
||||
DELETE_PROJECT((short) 23), // 프로젝트 삭제
|
||||
ASSIGN_PROJECT_OUTSOURCE((short) 24), // 프로젝트 배정
|
||||
ASSIGN_PROJECT_USER((short) 25), // 프로젝트 배정
|
||||
ASSIGN_PROJECT_USER((short) 24), // 프로젝트 배정
|
||||
|
||||
CREAT_USER((short) 31), // 사용자 생성
|
||||
UPDATE_USER((short) 32), // 사용자 수정
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.kri.contact.server.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebResourceConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${kri.contact-senario.upload-base-dir}")
|
||||
private String uploadBaseDir;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// /contact-senario/** → /data/upload-file/contact-senario/** 매핑
|
||||
registry.addResourceHandler("/contact-senario/**")
|
||||
.addResourceLocations("file:" + uploadBaseDir + "/");
|
||||
}
|
||||
}
|
||||
@@ -24,14 +24,4 @@ public class AssignController {
|
||||
public List<String> getPrjctOutsourceAssign(@PathVariable Long prjctIdx, RequestUserContext ctx){
|
||||
return assignService.getPrjctOutsourceAssign(prjctIdx);
|
||||
}
|
||||
|
||||
@PutMapping("/prjct-outsource/{prjctIdx}")
|
||||
public void upsertPrjctOutsourceAssign(
|
||||
@PathVariable Long prjctIdx,
|
||||
@RequestBody List<String> assignUserIdList,
|
||||
RequestUserContext ctx
|
||||
){
|
||||
assignService.upsertPrjctOutsourceAssign(prjctIdx, assignUserIdList, ctx.getUserId());
|
||||
systemEventLogService.writeAssignProjectOutsource(ctx.getUserId(), ctx.getClientIp(), prjctIdx, assignUserIdList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.contact.server.dto.ProjectOwnerResponseDto;
|
||||
import com.kri.contact.server.dto.*;
|
||||
import com.kri.contact.server.dto.common.PageResponseDto;
|
||||
import com.kri.contact.server.dto.ProjectCreateRequestDto;
|
||||
import com.kri.contact.server.dto.ProjectInfoDto;
|
||||
import com.kri.contact.server.dto.ProjectSearchRequestDto;
|
||||
import com.kri.contact.server.service.FileService;
|
||||
import com.kri.contact.server.service.ProjectService;
|
||||
import com.kri.contact.server.service.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,6 +21,7 @@ public class ProjectController {
|
||||
|
||||
private final SystemEventLogService systemEventLogService;
|
||||
private final ProjectService projectService;
|
||||
private final FileService fileService;
|
||||
|
||||
@GetMapping("/{prjctIdx}")
|
||||
public ProjectInfoDto getProject(@PathVariable Long prjctIdx){
|
||||
@@ -61,13 +61,26 @@ public class ProjectController {
|
||||
return prjctInfo;
|
||||
}
|
||||
|
||||
@PatchMapping()
|
||||
@PutMapping("/senario-image/{prjctCd}")
|
||||
public String uploadContactSenarioImage(@PathVariable String prjctCd, @RequestParam("file") MultipartFile file){
|
||||
return fileService.storeTempFile(prjctCd, file);
|
||||
}
|
||||
|
||||
@PatchMapping("/{prjctIdx}")
|
||||
public void updateProject(
|
||||
@RequestBody ProjectInfoDto req,
|
||||
@PathVariable long prjctIdx,
|
||||
@RequestBody ProjectUpdateRequestDto req,
|
||||
RequestUserContext ctx
|
||||
){
|
||||
projectService.updateProject(req, ctx.getUserId());
|
||||
systemEventLogService.writeUpdateProject(ctx.getUserId(), ctx.getClientIp(), req.getPrjctIdx(), req);
|
||||
String newHtml = fileService.syncOnSave(
|
||||
req.getProjectInfo().getPrjctCd(),
|
||||
req.getProjectInfo().getContactSenario()
|
||||
);
|
||||
req.getProjectInfo().setContactSenario(newHtml);
|
||||
|
||||
projectService.updateProject(prjctIdx, req, ctx.getUserId());
|
||||
|
||||
systemEventLogService.writeUpdateProject(ctx.getUserId(), ctx.getClientIp(), prjctIdx, req);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{prjctIdx}")
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.webmvc.RequestUserContext;
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.dto.ResultCodeDto;
|
||||
import com.kri.contact.server.service.ResultCodeService;
|
||||
import com.kri.contact.server.service.SystemEventLogService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/result-code")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Result Code", description = "결과 코드 API")
|
||||
public class ResultCodeController {
|
||||
|
||||
private final SystemEventLogService systemEventLogService;
|
||||
private final ResultCodeService resultCodeService;
|
||||
|
||||
@GetMapping("/{prjctIdx}")
|
||||
public List<ResultCodeDto> getResultCodeList(
|
||||
@PathVariable long prjctIdx,
|
||||
@RequestParam(required = false) ResultCodeType resultCdTy
|
||||
){
|
||||
return resultCodeService.getResultCode(prjctIdx, resultCdTy);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
package com.kri.contact.server.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.kri.contact.server.common.enums.ProjectStatus;
|
||||
import com.kri.contact.server.common.enums.SurveyType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
|
||||
@@ -11,6 +11,8 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "프로젝트 담당들 정보")
|
||||
public class ProjectOwnerResponseDto {
|
||||
@Schema(description = "담당 연구 부서")
|
||||
List<String> ownerDeptList;
|
||||
@Schema(description = "담당 실사 인원")
|
||||
List<String> ownerFwList;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kri.contact.server.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -7,15 +8,24 @@ import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "프로젝트 검색 조건")
|
||||
public class ProjectSearchRequestDto {
|
||||
@Schema(description = "검색 텍스트")
|
||||
private String prjctText; // like 대상
|
||||
@Schema(description = "프로젝트 상태 리스트")
|
||||
private List<Short> prjctStatusList; // in (0,1,10)
|
||||
@Schema(description = "담당 부서 리스트")
|
||||
private List<String> ownerDeptList; // in ('S101','P101')
|
||||
@Schema(description = "담당 실사 리스트")
|
||||
private List<String> ownerFwList; // in ('jspark','jhchae')
|
||||
|
||||
@Schema(description = "페이지 번호")
|
||||
private int pageIndex = 0; // 0-base
|
||||
@Schema(description = "페이지 크기")
|
||||
private int pageSize = 10;
|
||||
|
||||
private String sortBy = "prjctCd"; // 가변
|
||||
@Schema(description = "정렬 기준")
|
||||
private String sortBy = "prjctIdx"; // 가변
|
||||
@Schema(description = "오름차순/내림차순")
|
||||
private String sortDir = "desc"; // asc/desc
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.kri.contact.server.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "프로젝트 수정 요청")
|
||||
public class ProjectUpdateRequestDto {
|
||||
@Schema(description = "프로젝트 정보")
|
||||
private ProjectInfoDto projectInfo;
|
||||
|
||||
@Schema(description = "프로젝트 수정 되야 할 결과코드")
|
||||
private List<ResultCodeDto> resultCodeList;
|
||||
|
||||
@Schema(description = "배정될 외주 업체 목록")
|
||||
private List<String> assignUserIdList;
|
||||
}
|
||||
41
src/main/java/com/kri/contact/server/dto/ResultCodeDto.java
Normal file
41
src/main/java/com/kri/contact/server/dto/ResultCodeDto.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.kri.contact.server.dto;
|
||||
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@Schema(description = "결과 코드")
|
||||
public class ResultCodeDto {
|
||||
@Schema(description = "결과 코드 고유 키")
|
||||
private String resultCdUUID;
|
||||
|
||||
@Schema(description = "프로젝트 인덱스")
|
||||
private Long prjctIdx;
|
||||
|
||||
@Schema(description = "결과 코드 타입")
|
||||
private ResultCodeType resultCdTy;
|
||||
|
||||
@Schema(description = "결과 코드")
|
||||
private Short resultCd;
|
||||
|
||||
@Schema(description = "결과 코드 라벨")
|
||||
private String resultCdLbl;
|
||||
|
||||
public static ResultCodeDto from(TResultCodeEntity entity){
|
||||
return ResultCodeDto.builder()
|
||||
.resultCdUUID(UUID.randomUUID().toString())
|
||||
.prjctIdx(entity.getPrjctIdx())
|
||||
.resultCdTy(entity.getResultCdTy())
|
||||
.resultCd(entity.getResultCd())
|
||||
.resultCdLbl(entity.getResultCdLbl())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.kri.contact.server.persistence.entity;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.dto.ResultCodeDto;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -37,22 +38,15 @@ public class TResultCodeEntity {
|
||||
@Column(name = "reg_dt", nullable = false)
|
||||
private LocalDateTime regDt;
|
||||
|
||||
@Size(max = 32)
|
||||
@Column(name = "mod_user", length = 32)
|
||||
private String modUser;
|
||||
|
||||
@Column(name = "mod_dt")
|
||||
private LocalDateTime modDt;
|
||||
|
||||
public Long getPrjctIdx(){
|
||||
return id.getPrjctIdx();
|
||||
}
|
||||
|
||||
public Short getResultCdTy(){
|
||||
public ResultCodeType getResultCdTy(){
|
||||
return id.getResultCdTy();
|
||||
}
|
||||
|
||||
public ResultCodeType getResultCd(){
|
||||
public Short getResultCd(){
|
||||
return id.getResultCd();
|
||||
}
|
||||
|
||||
@@ -75,4 +69,21 @@ public class TResultCodeEntity {
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
public static TResultCodeEntity fromDto(Long prjctIdx, ResultCodeType resultCdTy,ResultCodeDto req, String regUser) {
|
||||
TResultCodeEntity entity = new TResultCodeEntity();
|
||||
|
||||
TResultCodeEntityId id = new TResultCodeEntityId();
|
||||
id.setPrjctIdx(prjctIdx);
|
||||
id.setResultCdTy(resultCdTy);
|
||||
id.setResultCd(req.getResultCd());
|
||||
entity.setId(id);
|
||||
|
||||
entity.setResultCdLbl(req.getResultCdLbl());
|
||||
|
||||
entity.setRegUser(regUser);
|
||||
entity.setRegDt(DateTimeUtil.nowKstLocalDateTime());
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,12 @@ public class TResultCodeEntityId implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Column(name = "result_cd_ty", nullable = false)
|
||||
private Short resultCdTy;
|
||||
@Convert(converter = ResultCodeTypeConverter.class)
|
||||
private ResultCodeType resultCdTy;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "result_cd", nullable = false)
|
||||
@Convert(converter = ResultCodeTypeConverter.class)
|
||||
private ResultCodeType resultCd;
|
||||
private Short resultCd;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
@@ -60,9 +60,8 @@ public class ProjectSpecs {
|
||||
// exists (select 1 from t_prjct_assign a where a.prjct_idx = root.prjctIdx and a.userId = ? and a.excDt is null)
|
||||
Predicate p1 = cb.equal(a.get("id").get("prjctIdx"), root.get("prjctIdx"));
|
||||
Predicate p2 = cb.equal(a.get("id").get("userId"), userId);
|
||||
Predicate p3 = cb.isNull(a.get("excDt"));
|
||||
|
||||
sub.select(cb.literal(1)).where(p1, p2, p3);
|
||||
sub.select(cb.literal(1)).where(p1, p2);
|
||||
|
||||
return cb.exists(sub);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kri.contact.server.persistence.repository;
|
||||
|
||||
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
@@ -15,4 +16,12 @@ public interface ResultCodeRepository extends JpaRepository<TResultCodeEntity, L
|
||||
where r.id.prjctIdx = 0
|
||||
""")
|
||||
List<TResultCodeEntity> findDefault();
|
||||
|
||||
List<TResultCodeEntity> findByIdPrjctIdx(Long prjctIdx);
|
||||
|
||||
List<TResultCodeEntity> findByIdPrjctIdxAndIdResultCdTy(Long prjctIdx, Short resultCdTy);
|
||||
|
||||
long deleteByIdPrjctIdx(Long prjctIdx);
|
||||
|
||||
long deleteByIdPrjctIdxAndIdResultCdTy(Long prjctIdx, ResultCodeType resultCdTy);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.kri.contact.server.scheduler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TempFileCleanupScheduler {
|
||||
|
||||
private final Path uploadBaseDir;
|
||||
private final Duration expireDuration;
|
||||
|
||||
public TempFileCleanupScheduler(
|
||||
@Value("${kri.contact-senario.upload-base-dir}") String uploadBaseDirStr,
|
||||
@Value("${kri.contact-senario.temp-expire-hours:24}") long expireHours
|
||||
) {
|
||||
this.uploadBaseDir = Paths.get(uploadBaseDirStr);
|
||||
this.expireDuration = Duration.ofHours(expireHours);
|
||||
}
|
||||
|
||||
/**
|
||||
* 매일 자정(00:00)에 실행.
|
||||
* 필요하면 application.yml 에서 kri.contact-senario.temp-cleanup-cron 으로 변경 가능.
|
||||
*/
|
||||
@Scheduled(cron = "${kri.contact-senario.temp-cleanup-cron:0 0 0 * * *}")
|
||||
public void cleanupOldTempFiles() {
|
||||
if (!Files.isDirectory(uploadBaseDir)) {
|
||||
log.warn("[TempCleanup] uploadBaseDir({}) 가 디렉토리가 아닙니다.", uploadBaseDir);
|
||||
return;
|
||||
}
|
||||
|
||||
Instant now = Instant.now();
|
||||
Instant threshold = now.minus(expireDuration);
|
||||
|
||||
log.info("[TempCleanup] 시작 - baseDir={}, threshold={}", uploadBaseDir, threshold);
|
||||
|
||||
try (DirectoryStream<Path> projectDirs = Files.newDirectoryStream(uploadBaseDir)) {
|
||||
for (Path projectDir : projectDirs) {
|
||||
if (!Files.isDirectory(projectDir)) {
|
||||
continue;
|
||||
}
|
||||
Path tempDir = projectDir.resolve("Temp"); // {prjctCd}/Temp
|
||||
if (!Files.isDirectory(tempDir)) {
|
||||
continue;
|
||||
}
|
||||
cleanupTempDir(tempDir, threshold);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("[TempCleanup] baseDir 스캔 중 오류 - baseDir={}", uploadBaseDir, e);
|
||||
}
|
||||
|
||||
log.info("[TempCleanup] 종료");
|
||||
}
|
||||
|
||||
private void cleanupTempDir(Path tempDir, Instant threshold) {
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(tempDir)) {
|
||||
for (Path file : stream) {
|
||||
if (!Files.isRegularFile(file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
BasicFileAttributes attrs =
|
||||
Files.readAttributes(file, BasicFileAttributes.class);
|
||||
|
||||
// 생성 시간(지원 안 하면 마지막 수정 시간)을 기준으로 비교
|
||||
Instant created = attrs.creationTime() != null
|
||||
? attrs.creationTime().toInstant()
|
||||
: attrs.lastModifiedTime().toInstant();
|
||||
|
||||
if (created.isBefore(threshold)) {
|
||||
Files.deleteIfExists(file);
|
||||
log.debug("[TempCleanup] 삭제: {} (created={})", file, created);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
log.warn("[TempCleanup] 파일 삭제 실패: {}", file, ex);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.warn("[TempCleanup] temp 디렉토리 스캔 실패: {}", tempDir, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
166
src/main/java/com/kri/contact/server/service/FileService.java
Normal file
166
src/main/java/com/kri/contact/server/service/FileService.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.file.FileUtil;
|
||||
import com.kri.common.web.BusinessException;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class FileService {
|
||||
private static final Logger log = LoggerFactory.getLogger(FileService.class);
|
||||
private final Path uploadBaseDir; // ex) /data/upload-file/contact-senario
|
||||
private final String publicBaseUrlPrefix; // ex) /upload-file/contact-senario
|
||||
|
||||
public FileService(
|
||||
@Value("${kri.contact-senario.upload-base-dir}") String uploadBaseDir,
|
||||
@Value("${kri.contact-senario.public-base-url}") String publicBaseUrlPrefix
|
||||
) {
|
||||
this.uploadBaseDir = Paths.get(uploadBaseDir).toAbsolutePath().normalize();
|
||||
this.publicBaseUrlPrefix = publicBaseUrlPrefix.endsWith("/")
|
||||
? publicBaseUrlPrefix.substring(0, publicBaseUrlPrefix.length() - 1)
|
||||
: publicBaseUrlPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temp에 파일 저장 후, public URL 반환
|
||||
*/
|
||||
public String storeTempFile(String prjctCd, MultipartFile file) {
|
||||
try {
|
||||
String original = Optional.ofNullable(file.getOriginalFilename()).orElse("file");
|
||||
String ext = "";
|
||||
|
||||
int dot = original.lastIndexOf('.');
|
||||
if (dot > 0 && dot < original.length() - 1) {
|
||||
ext = original.substring(dot);
|
||||
}
|
||||
|
||||
String newName = UUID.randomUUID().toString().replace("-", "") + ext;
|
||||
|
||||
Path tempDir = getTempDir(prjctCd);
|
||||
Files.createDirectories(tempDir);
|
||||
|
||||
Path target = tempDir.resolve(newName);
|
||||
file.transferTo(target.toFile());
|
||||
|
||||
// 브라우저에서 사용할 URL
|
||||
return publicBaseUrlPrefix + "/" + prjctCd + "/Temp/" + newName;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("파일 저장 실패", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 컨택 시나리오 저장 시:
|
||||
* 1) HTML 내 Temp 이미지 -> Asset으로 이동 & src 수정
|
||||
* 2) Asset 디렉토리에서 더 이상 사용되지 않는 파일 삭제
|
||||
* 3) 정리된 HTML 반환
|
||||
*/
|
||||
public String syncOnSave(String prjctCd, String rawHtml) {
|
||||
if (rawHtml == null) rawHtml = "";
|
||||
|
||||
String returnHtml = rawHtml;
|
||||
try{
|
||||
|
||||
|
||||
// body fragment로 파싱 (KriEditor가 body 없이 <p>...</p> 형태 저장하므로)
|
||||
Document doc = Jsoup.parseBodyFragment(rawHtml);
|
||||
Elements imgs = doc.select("img[src]");
|
||||
|
||||
Set<String> assetFileNamesToKeep = new HashSet<>();
|
||||
|
||||
for (Element img : imgs) {
|
||||
String src = img.attr("src");
|
||||
if (src == null || src.isBlank()) continue;
|
||||
if (!src.contains("/" + prjctCd + "/")) continue;
|
||||
|
||||
if (src.contains("/" + prjctCd + "/Temp/")) {
|
||||
// Temp → Asset 이동
|
||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||
moveTempToAsset(prjctCd, fileName);
|
||||
|
||||
String assetSrc = src.replace("/Temp/", "/Asset/");
|
||||
img.attr("src", assetSrc);
|
||||
|
||||
assetFileNamesToKeep.add(fileName);
|
||||
} else if (src.contains("/" + prjctCd + "/Asset/")) {
|
||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||
assetFileNamesToKeep.add(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
// Asset 디렉토리 정리 (본문에 없는 파일 삭제)
|
||||
cleanupAssetDir(prjctCd, assetFileNamesToKeep);
|
||||
|
||||
// body 안의 HTML만 반환 (불필요한 <html><body> wrapper 제거)
|
||||
returnHtml = doc.body().html();
|
||||
}
|
||||
catch (IOException e){
|
||||
log.warn("temp 파일 이동 실패: {}", rawHtml, e);
|
||||
}
|
||||
|
||||
return returnHtml;
|
||||
}
|
||||
|
||||
/***************************private************************************/
|
||||
private String normalizeBaseUrl(String url) {
|
||||
if (url.endsWith("/")) {
|
||||
return url.substring(0, url.length() - 1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private Path getTempDir(String prjctCd) {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Temp");
|
||||
}
|
||||
|
||||
private Path getAssetDir(String prjctCd) {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Asset");
|
||||
}
|
||||
|
||||
private void moveTempToAsset(String prjctCd, String fileName) throws IOException {
|
||||
if (fileName == null || fileName.isBlank()) return;
|
||||
|
||||
Path tempDir = getTempDir(prjctCd);
|
||||
Path assetDir = getAssetDir(prjctCd);
|
||||
Files.createDirectories(assetDir);
|
||||
|
||||
Path source = tempDir.resolve(fileName).normalize();
|
||||
Path target = assetDir.resolve(fileName).normalize();
|
||||
|
||||
if (!source.startsWith(tempDir) || !target.startsWith(assetDir)) {
|
||||
// 안전 체크
|
||||
return;
|
||||
}
|
||||
if (!Files.exists(source)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
private void cleanupAssetDir(String prjctCd, Set<String> keepFileNames) throws IOException {
|
||||
Path assetDir = getAssetDir(prjctCd);
|
||||
if (!Files.exists(assetDir)) return;
|
||||
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(assetDir)) {
|
||||
for (Path path : stream) {
|
||||
if (!Files.isRegularFile(path)) continue;
|
||||
String fileName = path.getFileName().toString();
|
||||
if (!keepFileNames.contains(fileName)) {
|
||||
Files.deleteIfExists(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,13 @@ package com.kri.contact.server.service;
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.web.BusinessException;
|
||||
import com.kri.contact.server.common.consts.AppConstant;
|
||||
import com.kri.contact.server.dto.ProjectOwnerResponseDto;
|
||||
import com.kri.contact.server.dto.*;
|
||||
import com.kri.contact.server.dto.common.PageResponseDto;
|
||||
import com.kri.contact.server.dto.ProjectCreateRequestDto;
|
||||
import com.kri.contact.server.dto.ProjectInfoDto;
|
||||
import com.kri.contact.server.dto.ProjectSearchRequestDto;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctEntity;
|
||||
import com.kri.contact.server.persistence.query.ProjectSorts;
|
||||
import com.kri.contact.server.persistence.query.ProjectSpecs;
|
||||
import com.kri.contact.server.persistence.repository.ProjectRepository;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
@@ -24,32 +22,30 @@ import java.util.*;
|
||||
@RequiredArgsConstructor
|
||||
public class ProjectService {
|
||||
|
||||
private final AssignService assignService;
|
||||
private final ResultCodeService resultCodeService;
|
||||
private final ProjectRepository projectRepository;
|
||||
private static final List<Short> STATUS_0_1 = List.of((short) 0, (short) 1);
|
||||
private static final List<Short> STATUS_1 = List.of((short) 1);
|
||||
|
||||
@Transactional
|
||||
public ProjectInfoDto createProject(ProjectCreateRequestDto req, String regUser){
|
||||
public ProjectInfoDto createProject(ProjectCreateRequestDto req, String regUser) {
|
||||
String itrnt = req.getItrntPrjctCd();
|
||||
|
||||
for (int retry = 0; retry < AppConstant.INSERT_RETRY_COUNT; retry++) {
|
||||
try {
|
||||
String prjctCd = this.makePrjctCd(itrnt);
|
||||
TPrjctEntity entity = TPrjctEntity.create(req, prjctCd, regUser);
|
||||
|
||||
try {
|
||||
return ProjectInfoDto.from(
|
||||
projectRepository.save(entity)
|
||||
);
|
||||
} catch (org.springframework.dao.DataIntegrityViolationException e) {
|
||||
if (retry == (AppConstant.INSERT_RETRY_COUNT - 1)) throw e;
|
||||
}
|
||||
}
|
||||
ProjectInfoDto savedProject = ProjectInfoDto.from(projectRepository.save(entity));
|
||||
resultCodeService.copyResultCodeFromDefault(savedProject.getPrjctIdx(), regUser);
|
||||
|
||||
throw BusinessException.conflict(
|
||||
"PROJECT_CODE_CONFLICT",
|
||||
"프로젝트 코드 생성 중 충돌이 발생했습니다. 다시 시도해주세요."
|
||||
)
|
||||
.with("itrntPrjctCd", itrnt);
|
||||
return savedProject;
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
throw BusinessException.conflict(
|
||||
"PROJECT_CODE_CONFLICT",
|
||||
"프로젝트 코드 생성 중 충돌이 발생했습니다. 다시 시도해주세요."
|
||||
).with("itrntPrjctCd", itrnt);
|
||||
}
|
||||
}
|
||||
|
||||
public ProjectInfoDto getProject(Long prjctIdx){
|
||||
@@ -136,15 +132,18 @@ public class ProjectService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProject(ProjectInfoDto req, String modUser){
|
||||
public void updateProject(long prjctIdx, ProjectUpdateRequestDto req, String modUser){
|
||||
// dirty checking 업데이트
|
||||
TPrjctEntity entity = projectRepository.findById(req.getPrjctIdx())
|
||||
TPrjctEntity entity = projectRepository.findById(prjctIdx)
|
||||
.orElseThrow(() ->
|
||||
BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
|
||||
.with("prjctIdx", req.getPrjctIdx())
|
||||
.with("prjctIdx", prjctIdx)
|
||||
);
|
||||
|
||||
entity.updateFrom(req, modUser);
|
||||
entity.updateFrom(req.getProjectInfo(), modUser);
|
||||
|
||||
assignService.upsertPrjctOutsourceAssign(prjctIdx, req.getAssignUserIdList(), modUser);
|
||||
resultCodeService.updateResultCode(prjctIdx, req.getResultCodeList(), modUser);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.web.BusinessException;
|
||||
import com.kri.contact.server.common.enums.ResultCodeType;
|
||||
import com.kri.contact.server.dto.ResultCodeDto;
|
||||
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
|
||||
import com.kri.contact.server.persistence.entity.TResultCodeEntityId;
|
||||
import com.kri.contact.server.persistence.repository.ResultCodeRepository;
|
||||
@@ -9,14 +12,15 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ResultCodeService {
|
||||
|
||||
ResultCodeRepository resultCodeRepository;
|
||||
private final ResultCodeRepository resultCodeRepository;
|
||||
|
||||
@Transactional
|
||||
public void copyResultCodeFromDefault(long prjctIdx, String regUser){
|
||||
List<TResultCodeEntity> defaultCodeList = resultCodeRepository.findDefault();
|
||||
|
||||
@@ -26,4 +30,40 @@ public class ResultCodeService {
|
||||
|
||||
resultCodeRepository.saveAll(copyCodeList);
|
||||
}
|
||||
|
||||
public List<ResultCodeDto> getResultCode(long prjctIdx, ResultCodeType resultCdTy){
|
||||
if (resultCdTy == null) {
|
||||
return resultCodeRepository.findByIdPrjctIdx(prjctIdx).stream()
|
||||
.map(ResultCodeDto::from)
|
||||
.toList();
|
||||
} else {
|
||||
return resultCodeRepository.findByIdPrjctIdxAndIdResultCdTy(prjctIdx, resultCdTy.getCode()).stream()
|
||||
.map(ResultCodeDto::from)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateResultCode(long prjctIdx, List<ResultCodeDto> resultCodeDtoList, String modUser){
|
||||
if (resultCodeDtoList != null && !resultCodeDtoList.isEmpty()) {
|
||||
Map<ResultCodeType, List<ResultCodeDto>> dtoGroupByType = resultCodeDtoList.stream()
|
||||
.filter(dto -> dto.getResultCdTy() != null)
|
||||
.collect(Collectors.groupingBy(ResultCodeDto::getResultCdTy));
|
||||
|
||||
dtoGroupByType.forEach((resultCdTy, dtos) ->
|
||||
replaceResultCodes(prjctIdx, resultCdTy, dtos, modUser)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************private************************************/
|
||||
private void replaceResultCodes(long prjctIdx, ResultCodeType resultCdTy, List<ResultCodeDto> dtos, String userId) {
|
||||
resultCodeRepository.deleteByIdPrjctIdxAndIdResultCdTy(prjctIdx, resultCdTy);
|
||||
|
||||
List<TResultCodeEntity> entities = dtos.stream()
|
||||
.map(dto -> TResultCodeEntity.fromDto(prjctIdx, resultCdTy, dto, userId))
|
||||
.toList();
|
||||
|
||||
resultCodeRepository.saveAll(entities);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.contact.server.dto.ProjectCreateRequestDto;
|
||||
import com.kri.contact.server.dto.ProjectInfoDto;
|
||||
import com.kri.contact.server.dto.UserInfoDto;
|
||||
import com.kri.contact.server.dto.*;
|
||||
import com.kri.contact.server.dto.systemlog.ProjectIdxContentDto;
|
||||
import com.kri.contact.server.dto.systemlog.UploadUserContentDto;
|
||||
import com.kri.contact.server.dto.systemlog.UserIdContentDto;
|
||||
@@ -56,7 +54,7 @@ public class SystemEventLogService {
|
||||
writeSystemLog(SystemEventType.CREAT_PROJECT, "Create Project", prjctIdx, regId, clientIp, req);
|
||||
}
|
||||
|
||||
public void writeUpdateProject(String regId, String clientIp, Long prjctIdx, ProjectInfoDto req){
|
||||
public void writeUpdateProject(String regId, String clientIp, Long prjctIdx, ProjectUpdateRequestDto req){
|
||||
writeSystemLog(SystemEventType.UPDATE_PROJECT, "Update Project", prjctIdx, regId, clientIp, req);
|
||||
}
|
||||
|
||||
@@ -65,10 +63,6 @@ public class SystemEventLogService {
|
||||
writeSystemLog(SystemEventType.DELETE_PROJECT, "Delete Project", prjctIdx, regId, clientIp, content);
|
||||
}
|
||||
|
||||
public void writeAssignProjectOutsource(String regId, String clientIp, Long prjctIdx, List<String> assignUserIdList){
|
||||
writeSystemLog(SystemEventType.ASSIGN_PROJECT_OUTSOURCE, "Assign Project Outsource User", prjctIdx, regId, clientIp, assignUserIdList);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected <T> void writeSystemLog(
|
||||
SystemEventType eventType,
|
||||
|
||||
Reference in New Issue
Block a user