251210_01_ENH: Project CRUD 구현 및 테스트 진행중

This commit is contained in:
2025-12-10 16:23:10 +09:00
parent 47ce0fffbb
commit 49f4e69372
31 changed files with 1024 additions and 35 deletions

View File

@@ -3,6 +3,8 @@ package com.kri.contact.server.common.consts;
public final class AppConstant {
private AppConstant(){}
public static final Integer EXTERNAL_USER_ROLE = 4000;
public static final Integer FIELDWORK_USER_ROLE = 9000;
public static final int OUTSOURCE_USER_ROLE = 4000;
public static final int FIELDWORK_USER_ROLE = 9000;
public static final int INSERT_RETRY_COUNT = 2;
}

View File

@@ -0,0 +1,32 @@
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 ProjectStatus implements CodeEnum<Short> {
STANDBY((short) 0), // 대기
PROGRESS((short) 1), // 진행
COMPELETE((short) 10); // 완료
private final short code;
ProjectStatus(short code) {
this.code = code;
}
@Override
@JsonValue
public Short getCode() {
return code;
}
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static ProjectStatus fromCode(Short code) {
if (code == null) return null;
for (ProjectStatus s : values()) {
if (s.code == code) return s;
}
throw new IllegalArgumentException("Unknown ProjectStatus code: " + code);
}
}

View File

@@ -0,0 +1,33 @@
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 SurveyType implements CodeEnum<Short> {
NONE((short) 0), // 없음
KON((short) 1), // KON
KIWI((short) 2), // KIWI
EXTERNAL((short) 99); // 외부
private final short code;
SurveyType(short code) {
this.code = code;
}
@Override
@JsonValue
public Short getCode() {
return code;
}
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static SurveyType fromCode(Short code) {
if (code == null) return null;
for (SurveyType s : values()) {
if (s.code == code) return s;
}
throw new IllegalArgumentException("Unknown SurveyType code: " + code);
}
}

View File

@@ -4,11 +4,13 @@ import com.kri.common.enums.CodeEnum;
public enum SystemEventType implements CodeEnum<Short> {
LOGIN((short) 11), // 로그인
LOGOUT((short) 11), // 로그인
LOGOUT((short) 11), // 로그 아웃
CREAT_PROJECT((short) 21), // 프로젝트 생성
UPDATE_PROJECT((short) 22), // 프로젝트 수정
DELETE_PROJECT((short) 23), // 프로젝트 삭제
ASSIGN_PROJECT_OUTSOURCE((short) 24), // 프로젝트 배정
ASSIGN_PROJECT_USER((short) 25), // 프로젝트 배정
CREAT_USER((short) 31), // 사용자 생성
UPDATE_USER((short) 32), // 사용자 수정

View File

@@ -0,0 +1,37 @@
package com.kri.contact.server.controller;
import com.kri.common.web.BusinessException;
import com.kri.common.webmvc.RequestUserContext;
import com.kri.contact.server.common.consts.AppConstant;
import com.kri.contact.server.service.AssignService;
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/assign")
@RequiredArgsConstructor
@Tag(name = "Assign", description = "배정 API")
public class AssignController {
private final SystemEventLogService systemEventLogService;
private final AssignService assignService;
@GetMapping("/prjct-outsource/{prjctIdx}")
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);
}
}

View File

@@ -0,0 +1,78 @@
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.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.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 java.util.List;
@RestController
@RequestMapping("/api/v1/project")
@RequiredArgsConstructor
@Tag(name = "Project", description = "프로젝트 API")
public class ProjectController {
private final SystemEventLogService systemEventLogService;
private final ProjectService projectService;
@GetMapping("/{prjctIdx}")
public ProjectInfoDto getProject(@PathVariable Long prjctIdx){
return projectService.getProject(prjctIdx);
}
@GetMapping("/top/{topCount}")
public List<ProjectInfoDto> getTopProject(
@PathVariable int topCount,
@RequestParam(required = false) String keyword,
RequestUserContext ctx
){
return projectService.getTopProject(topCount, keyword, ctx.getUserId(), ctx.getUserRole());
}
@PostMapping("/list")
public PageResponseDto<ProjectInfoDto> searchProject(
@RequestBody ProjectSearchRequestDto req,
RequestUserContext ctx
) {
return projectService.searchProject(req, ctx.getUserId(), ctx.getUserRole());
}
@GetMapping("/owner-list")
public ProjectOwnerResponseDto getOwnerList(RequestUserContext ctx){
return projectService.getOwnerList(ctx.getUserRole());
}
@PutMapping()
public ProjectInfoDto createProject(
@RequestBody ProjectCreateRequestDto req,
RequestUserContext ctx
) {
ProjectInfoDto prjctInfo = projectService.createProject(req, ctx.getUserId());
systemEventLogService.writeCreateProject(ctx.getUserId(), ctx.getClientIp(), prjctInfo.getPrjctIdx(), req);
return prjctInfo;
}
@PatchMapping()
public void updateProject(
@RequestBody ProjectInfoDto req,
RequestUserContext ctx
){
projectService.updateProject(req, ctx.getUserId());
systemEventLogService.writeUpdateProject(ctx.getUserId(), ctx.getClientIp(), req.getPrjctIdx(), req);
}
@DeleteMapping("/{prjctIdx}")
public void deleteProject(@PathVariable Long prjctIdx, RequestUserContext ctx){
projectService.deleteProject(prjctIdx, ctx.getUserId());
systemEventLogService.writeDeleteProject(ctx.getUserId(), ctx.getClientIp(), prjctIdx);
}
}

View File

@@ -1,5 +1,6 @@
package com.kri.contact.server.controller;
import com.kri.common.web.BusinessException;
import com.kri.common.webmvc.RequestUserContext;
import com.kri.contact.server.common.consts.AppConstant;
import com.kri.contact.server.dto.DataVerificationDto;
@@ -39,17 +40,22 @@ public class UserController {
@GetMapping()
public List<UserInfoDto> getUserList(RequestUserContext ctx){
//내부 직원
if(ctx.getUserRole() < AppConstant.EXTERNAL_USER_ROLE){
return userService.getUserListWithCmpn("");
String searchCmpn = ctx.getUserCmpn();
if(ctx.getUserRole() < AppConstant.OUTSOURCE_USER_ROLE){
searchCmpn = "";
}
//외주사 이상
return userService.getUserListWithCmpn(ctx.getUserCmpn());
return userService.getUserListWithCmpn(searchCmpn);
}
@GetMapping("outsource")
List<UserInfoDto> getOutsourceList(RequestUserContext ctx){
return userService.getOutsourceList();
}
@GetMapping("cmpn")
public List<String> getUserCmpnList(RequestUserContext ctx){
if(ctx.getUserRole() < AppConstant.EXTERNAL_USER_ROLE){
if(ctx.getUserRole() < AppConstant.OUTSOURCE_USER_ROLE){
return userService.getUserCmpnList();
}
@@ -73,7 +79,7 @@ public class UserController {
String regId = ctx.getUserId();
String clientIp = ctx.getClientIp();
//외주사급이 업로드로 계정을 생성하는 경우 자신의 회사명으로 고정
String forceCmpn = ctx.getUserRole() < AppConstant.EXTERNAL_USER_ROLE? "" : ctx.getUserCmpn();
String forceCmpn = ctx.getUserRole() < AppConstant.OUTSOURCE_USER_ROLE? "" : ctx.getUserCmpn();
ExcelUploadResponseDto result = userService.createUsersFromExcel(file, regId, forceCmpn);

View File

@@ -0,0 +1,28 @@
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
@AllArgsConstructor
@Schema(description = "프로젝트 생성 요청")
public class ProjectCreateRequestDto {
@Schema(description = "프로젝트 명")
private String prjctName;
@Schema(description = "인트라넷 프로젝트 코드")
private String itrntPrjctCd;
@Schema(description = "담당 그룹")
private String ownerDept;
@Schema(description = "담당 실사")
private String ownerFw;
}

View File

@@ -0,0 +1,95 @@
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 com.kri.contact.server.persistence.entity.TPrjctEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "프로젝트 정보")
public class ProjectInfoDto {
@Schema(description = "프로젝트 고유 번호")
private Long prjctIdx;
@Schema(description = "프로젝트 코드")
private String prjctCd;
@Schema(description = "프로젝트 진행 상태")
private ProjectStatus prjctStatus;
@Schema(description = "프로젝트 명")
private String prjctName;
@Schema(description = "인트라넷 프로젝트 코드")
private String itrntPrjctCd;
@Schema(description = "담당 그룹")
private String ownerDept;
@Schema(description = "담당 실사")
private String ownerFw;
@Schema(description = "설문지 타입")
private SurveyType surveyTy;
@Schema(description = "내부 설문 시스템 프로젝트 코드")
private String surveyPrjctCd;
@Schema(description = "설문 URL")
private String surveyUrl;
@Schema(description = "면접원 확인사항 여부")
private Boolean ff;
@Schema(description = "컨택 시나리오 사용 여부")
private Boolean useContactSenario;
@Schema(description = "컨택 시나리오")
private String contactSenario;
@Schema(description = "등록자", accessMode = Schema.AccessMode.READ_ONLY)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private String regUser;
@Schema(description = "등록일시", accessMode = Schema.AccessMode.READ_ONLY)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private LocalDateTime regDt;
@Schema(description = "수정자", accessMode = Schema.AccessMode.READ_ONLY)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private String modUser;
@Schema(description = "수정일시", accessMode = Schema.AccessMode.READ_ONLY)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private LocalDateTime modDt;
public static ProjectInfoDto from(TPrjctEntity entity){
return ProjectInfoDto.builder()
.prjctIdx(entity.getPrjctIdx())
.prjctCd(entity.getPrjctCd())
.prjctStatus(ProjectStatus.fromCode(entity.getPrjctStatus()))
.prjctName(entity.getPrjctNm())
.itrntPrjctCd(entity.getItrntPrjctCd())
.ownerDept(entity.getOwnerDept())
.ownerFw(entity.getOwnerFw())
.surveyTy(SurveyType.fromCode(entity.getSurveyTy()))
.surveyPrjctCd(entity.getSurveyPrjctCd())
.surveyUrl(entity.getSurveyUrl())
.ff(entity.getFf())
.useContactSenario(entity.getUseContactSenario())
.contactSenario(entity.getContactSenario())
.regUser(entity.getRegUser())
.regDt(entity.getRegDt())
.modUser(entity.getModUser())
.modDt(entity.getModDt())
.build();
}
}

View File

@@ -0,0 +1,16 @@
package com.kri.contact.server.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "프로젝트 담당들 정보")
public class ProjectOwnerResponseDto {
List<String> ownerDeptList;
List<String> ownerFwList;
}

View File

@@ -0,0 +1,21 @@
package com.kri.contact.server.dto;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class ProjectSearchRequestDto {
private String prjctText; // like 대상
private List<Short> prjctStatusList; // in (0,1,10)
private List<String> ownerDeptList; // in ('S101','P101')
private List<String> ownerFwList; // in ('jspark','jhchae')
private int pageIndex = 0; // 0-base
private int pageSize = 10;
private String sortBy = "prjctCd"; // 가변
private String sortDir = "desc"; // asc/desc
}

View File

@@ -0,0 +1,35 @@
package com.kri.contact.server.dto.common;
import lombok.Builder;
import lombok.Getter;
import org.springframework.data.domain.Page;
import java.util.List;
@Getter
@Builder
public class PageResponseDto <T> {
private List<T> content;
private long totalElements;
private int totalPages;
private int pageIndex;
private int pageSize;
private int numberOfElements;
private boolean first;
private boolean last;
private boolean empty;
public static <T> PageResponseDto<T> from(Page<T> page) {
return PageResponseDto.<T>builder()
.content(page.getContent())
.totalElements(page.getTotalElements())
.totalPages(page.getTotalPages())
.pageIndex(page.getNumber()) // ✅ 현재 페이지 index(0-base)
.pageSize(page.getSize())
.numberOfElements(page.getNumberOfElements())
.first(page.isFirst())
.last(page.isLast())
.empty(page.isEmpty())
.build();
}
}

View File

@@ -0,0 +1,12 @@
package com.kri.contact.server.dto.systemlog;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@AllArgsConstructor
public class ProjectIdxContentDto {
public Long prjctIdx;
}

View File

@@ -41,12 +41,4 @@ public class TListAssignEntity {
@ColumnDefault("CURRENT_TIMESTAMP")
@Column(name = "reg_dt")
private LocalDateTime regDt;
@Size(max = 32)
@Column(name = "exc_user", length = 32)
private String excUser;
@Column(name = "exc_dt")
private LocalDateTime excDt;
}

View File

@@ -34,7 +34,7 @@ public class TListResveEntity {
@NotNull
@ColumnDefault("0")
@Column(name = "is_cnfirm", nullable = false)
private Boolean isCnfirm = false;
private Boolean cnfirm = false;
@NotNull
@Column(name = "resve_dt", nullable = false)

View File

@@ -30,6 +30,14 @@ public class TPrjctAssignEntity {
@Column(name = "reg_dt", nullable = false)
private LocalDateTime regDt;
public static TPrjctAssignEntity create(Long prjctIdx, String userId, String regUser, LocalDateTime regDt) {
TPrjctAssignEntity e = new TPrjctAssignEntity();
e.setId(TPrjctAssignEntityId.create(prjctIdx, userId));
e.setRegUser(regUser);
e.setRegDt(regDt);
return e;
}
public Long getPrjctIdx(){
return id.getPrjctIdx();
}

View File

@@ -38,4 +38,10 @@ public class TPrjctAssignEntityId implements Serializable {
return Objects.hash(prjctIdx, userId);
}
public static TPrjctAssignEntityId create(Long prjctIdx, String userId) {
TPrjctAssignEntityId id = new TPrjctAssignEntityId();
id.setPrjctIdx(prjctIdx);
id.setUserId(userId);
return id;
}
}

View File

@@ -1,5 +1,10 @@
package com.kri.contact.server.persistence.entity;
import com.kri.common.datetime.DateTimeUtil;
import com.kri.contact.server.common.enums.ProjectStatus;
import com.kri.contact.server.common.enums.SurveyType;
import com.kri.contact.server.dto.ProjectCreateRequestDto;
import com.kri.contact.server.dto.ProjectInfoDto;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
@@ -24,9 +29,14 @@ public class TPrjctEntity {
@Column(name = "prjct_cd", nullable = false, length = 32)
private String prjctCd;
@Size(max = 64)
@NotNull
@Column(name = "prjct_nm", nullable = false, length = 64)
@ColumnDefault("0")
@Column(name = "prjct_status", nullable = false)
private Short prjctStatus = ProjectStatus.STANDBY.getCode();
@Size(max = 128)
@NotNull
@Column(name = "prjct_nm", nullable = false, length = 128)
private String prjctNm;
@Size(max = 32)
@@ -47,7 +57,7 @@ public class TPrjctEntity {
@NotNull
@ColumnDefault("0")
@Column(name = "survey_ty", nullable = false)
private Short surveyTy;
private Short surveyTy = SurveyType.NONE.getCode();
@Size(max = 32)
@Column(name = "survey_prjct_cd", length = 32)
@@ -60,12 +70,12 @@ public class TPrjctEntity {
@NotNull
@ColumnDefault("0")
@Column(name = "is_ff", nullable = false)
private Boolean isFf = false;
private Boolean ff = false;
@NotNull
@ColumnDefault("0")
@Column(name = "is_use_contact_senario", nullable = false)
private Boolean isUseContactSenario = false;
private Boolean useContactSenario = false;
@Lob
@Column(name = "contact_senario")
@@ -82,12 +92,10 @@ public class TPrjctEntity {
private LocalDateTime regDt;
@Size(max = 32)
@NotNull
@Column(name = "mod_user", nullable = false, length = 32)
@Column(name = "mod_user", length = 32)
private String modUser;
@NotNull
@Column(name = "mod_dt", nullable = false)
@Column(name = "mod_dt")
private LocalDateTime modDt;
@NotNull
@@ -101,4 +109,53 @@ public class TPrjctEntity {
@Column(name = "del_dt")
private LocalDateTime delDt;
public static TPrjctEntity fromDto(ProjectInfoDto dto){
TPrjctEntity entity = new TPrjctEntity();
entity.setPrjctCd(dto.getPrjctCd());
entity.setPrjctStatus(dto.getPrjctStatus().getCode());
entity.setPrjctNm(dto.getPrjctName());
entity.setItrntPrjctCd(dto.getItrntPrjctCd());
entity.setOwnerDept(dto.getOwnerDept());
entity.setOwnerFw(dto.getOwnerFw());
entity.setSurveyTy(dto.getSurveyTy().getCode());
entity.setSurveyPrjctCd(dto.getSurveyPrjctCd());
entity.setSurveyUrl(dto.getSurveyUrl());
entity.setFf(dto.getFf());
entity.setUseContactSenario(dto.getUseContactSenario());
entity.setContactSenario(dto.getContactSenario());
entity.setRegUser(dto.getRegUser());
entity.setRegDt(DateTimeUtil.nowKstLocalDateTime());
return entity;
}
public static TPrjctEntity create(ProjectCreateRequestDto req, String prjctCd, String regUser){
TPrjctEntity entity = new TPrjctEntity();
entity.setPrjctCd(prjctCd);
entity.setPrjctNm(req.getPrjctName());
entity.setItrntPrjctCd(req.getItrntPrjctCd());
entity.setOwnerDept(req.getOwnerDept());
entity.setOwnerFw(req.getOwnerFw());
entity.setRegUser(regUser);
entity.setRegDt(DateTimeUtil.nowKstLocalDateTime());
return entity;
}
public void updateFrom(ProjectInfoDto dto, String modUser) {
this.prjctNm = dto.getPrjctName();
this.prjctStatus = dto.getPrjctStatus().getCode();
this.ownerDept = dto.getOwnerDept();
this.ownerFw = dto.getOwnerFw();
this.surveyTy = dto.getSurveyTy().getCode();
this.surveyPrjctCd = dto.getSurveyPrjctCd();
this.surveyUrl = dto.getSurveyUrl();
this.ff = dto.getFf();
this.useContactSenario = dto.getUseContactSenario();
this.contactSenario = dto.getContactSenario();
this.modUser = modUser;
this.modDt = DateTimeUtil.nowKstLocalDateTime();
}
}

View File

@@ -1,5 +1,6 @@
package com.kri.contact.server.persistence.entity;
import com.kri.common.datetime.DateTimeUtil;
import com.kri.contact.server.common.enums.ResultCodeType;
import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId;
@@ -9,6 +10,7 @@ import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import java.time.LocalDateTime;
@@ -31,16 +33,15 @@ public class TResultCodeEntity {
private String regUser;
@NotNull
@ColumnDefault("CURRENT_TIMESTAMP")
@Column(name = "reg_dt", nullable = false)
private LocalDateTime regDt;
@Size(max = 32)
@NotNull
@Column(name = "mod_user", nullable = false, length = 32)
@Column(name = "mod_user", length = 32)
private String modUser;
@NotNull
@Column(name = "mod_dt", nullable = false)
@Column(name = "mod_dt")
private LocalDateTime modDt;
public Long getPrjctIdx(){
@@ -54,4 +55,24 @@ public class TResultCodeEntity {
public ResultCodeType getResultCd(){
return id.getResultCd();
}
public static TResultCodeEntity copyFromDefault(
TResultCodeEntity src,
Long prjctIdx,
String regUser
) {
TResultCodeEntity e = new TResultCodeEntity();
TResultCodeEntityId newId = new TResultCodeEntityId();
newId.setPrjctIdx(prjctIdx);
newId.setResultCdTy(src.getResultCdTy());
newId.setResultCd(src.getResultCd());
e.setId(newId);
e.setResultCdLbl(src.getResultCdLbl());
e.setRegUser(regUser);
e.setRegDt(DateTimeUtil.nowKstLocalDateTime());
return e;
}
}

View File

@@ -0,0 +1,21 @@
package com.kri.contact.server.persistence.query;
import org.springframework.data.domain.*;
public class ProjectSorts {
public static Sort toSort(String sortBy, String sortDir) {
String prop = switch (sortBy) {
case "prjctIdx" -> "prjctIdx";
case "prjctCd" -> "prjctCd";
case "prjctName" -> "prjctNm";
case "prjctStatus" -> "prjctStatus";
case "ownerDept" -> "ownerDept";
case "ownerFw" -> "ownerFw";
case "regDt" -> "regDt";
default -> "prjctCd"; // fallback
};
Sort.Direction dir = "asc".equalsIgnoreCase(sortDir) ? Sort.Direction.ASC : Sort.Direction.DESC;
return Sort.by(dir, prop);
}
}

View File

@@ -0,0 +1,70 @@
package com.kri.contact.server.persistence.query;
import com.kri.contact.server.persistence.entity.TPrjctAssignEntity;
import com.kri.contact.server.persistence.entity.TPrjctEntity;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.util.StringUtils;
import java.util.List;
public class ProjectSpecs {
public static Specification<TPrjctEntity> isDelFalse() {
return (root, query, cb) -> cb.equal(root.get("del"), false);
}
public static Specification<TPrjctEntity> keywordLike(String searchText) {
return (root, query, cb) -> {
if (!StringUtils.hasText(searchText)) return cb.conjunction();
String like = "%" + searchText.trim() + "%";
return cb.or(
cb.like(root.get("prjctCd"), like),
cb.like(root.get("prjctNm"), like) // 엔티티 필드명에 맞추기
);
};
}
public static Specification<TPrjctEntity> statusIn(List<Short> list) {
return (root, query, cb) -> {
if (list == null || list.isEmpty()) return cb.conjunction();
return root.get("prjctStatus").in(list);
};
}
public static Specification<TPrjctEntity> ownerDeptIn(List<String> list) {
return (root, query, cb) -> {
if (list == null || list.isEmpty()) return cb.conjunction();
return root.get("ownerDept").in(list);
};
}
public static Specification<TPrjctEntity> ownerFwIn(List<String> list) {
return (root, query, cb) -> {
if (list == null || list.isEmpty()) return cb.conjunction();
return root.get("ownerFw").in(list);
};
}
public static Specification<TPrjctEntity> assignedToUserAndNotExcluded(String userId) {
return (root, query, cb) -> {
if (userId == null || userId.isBlank()) {
return cb.disjunction(); // 외부유저인데 userId 없으면 아무것도 안 보이게(안전)
}
var sub = query.subquery(Integer.class);
Root<TPrjctAssignEntity> a = sub.from(TPrjctAssignEntity.class);
// 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);
return cb.exists(sub);
};
}
}

View File

@@ -0,0 +1,37 @@
package com.kri.contact.server.persistence.repository;
import com.kri.contact.server.persistence.entity.TPrjctAssignEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface ProjectAssignRepository extends JpaRepository<TPrjctAssignEntity, Long>, JpaSpecificationExecutor<TPrjctAssignEntity> {
@Query("""
select a.id.userId
from TPrjctAssignEntity a
join TUserEntity u on u.userId = a.id.userId
where a.id.prjctIdx = :prjctIdx
and u.del = false
and u.userRole >= :startRole
and u.userRole < :endRole
""")
List<String> findAssignUserIdByPrjctIdxAndRoleRange(Long prjctIdx, int startRole, int endRole);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query(value = """
delete from TPrjctAssignEntity a
where a.id.prjctIdx = :prjctIdx
and a.id.userId in (
select u.userId
from TUserEntity u
where 1=1
and u.userRole >= :startRole
and u.userRole < :endRole
)
""")
int deleteAssignByPrjctIdxAndRoleRange(Long prjctIdx, int startRole, int endRole);
}

View File

@@ -0,0 +1,46 @@
package com.kri.contact.server.persistence.repository;
import com.kri.contact.server.persistence.entity.TPrjctEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.LocalDateTime;
import java.util.List;
public interface ProjectRepository extends JpaRepository<TPrjctEntity, Long>, JpaSpecificationExecutor<TPrjctEntity> {
List<TPrjctEntity> findByItrntPrjctCd(String itrntPrjctCd);
TPrjctEntity findByPrjctIdxAndDelFalse(Long prjctIdx);
@Query("""
select distinct p.ownerDept
from TPrjctEntity p
where p.del = false
and (:statusList is null or p.prjctStatus in :statusList)
order by p.ownerDept
""")
List<String> findDistinctOwnerDept(List<Short> statusList);
@Query("""
select distinct p.ownerFw
from TPrjctEntity p
where p.del = false
and (:statusList is null or p.prjctStatus in :statusList)
order by p.ownerDept
""")
List<String> findDistinctOwnerFw(List<Short> statusList);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("""
update TPrjctEntity u
set u.del = true,
u.delUser = :delUser,
u.delDt = :delDt
where u.prjctIdx = :prjctIdx
and u.del = false
""")
int softDeleteByPrjctIdx(Long prjctIdx, String delUser, LocalDateTime delDt);
}

View File

@@ -0,0 +1,18 @@
package com.kri.contact.server.persistence.repository;
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface ResultCodeRepository extends JpaRepository<TResultCodeEntity, Long>, JpaSpecificationExecutor<TResultCodeEntity> {
@Query("""
select r
from TResultCodeEntity r
where r.id.prjctIdx = 0
""")
List<TResultCodeEntity> findDefault();
}

View File

@@ -19,6 +19,24 @@ public interface UserRepository extends JpaRepository<TUserEntity, Long>, JpaSpe
List<TUserEntity> findByUserCmpnAndUserRoleGreaterThanEqualAndDelFalse(String userCmpn, Integer userRoleCd);
@Query("""
select u
from TUserEntity u
where u.del = false
and u.userRole >= :startRole
and u.userRole < :endRole
""")
List<TUserEntity> findByRoleRangeAndDelFalse(int startRole, int endRole);
@Query("""
select u.userId
from TUserEntity u
where u.del = false
and u.userRole >= :startRole
and u.userRole < :endRole
""")
List<TUserEntity> findUserIdByRoleRangeAndDelFalse(int startRole, int endRole);
@Query("""
select distinct u.userCmpn
from TUserEntity u

View File

@@ -0,0 +1,57 @@
package com.kri.contact.server.service;
import com.kri.common.datetime.DateTimeUtil;
import com.kri.contact.server.common.consts.AppConstant;
import com.kri.contact.server.persistence.entity.TPrjctAssignEntity;
import com.kri.contact.server.persistence.entity.TPrjctAssignEntityId;
import com.kri.contact.server.persistence.repository.ProjectAssignRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
@Service
@RequiredArgsConstructor
public class AssignService {
private final ProjectAssignRepository projectAssignRepository;
public List<String> getPrjctOutsourceAssign(Long prjctIdx){
return projectAssignRepository.findAssignUserIdByPrjctIdxAndRoleRange(
prjctIdx,
AppConstant.OUTSOURCE_USER_ROLE,
AppConstant.OUTSOURCE_USER_ROLE + 1000
);
}
@Transactional
public void upsertPrjctOutsourceAssign(Long prjctIdx, List<String> assignUserIdList, String regUser){
projectAssignRepository.deleteAssignByPrjctIdxAndRoleRange(
prjctIdx,
AppConstant.OUTSOURCE_USER_ROLE,
AppConstant.OUTSOURCE_USER_ROLE + 1000
);
if (assignUserIdList == null || assignUserIdList.isEmpty()) {
return;
}
List<String> normalized = assignUserIdList.stream()
.filter(s -> s != null && !s.isBlank())
.map(String::trim)
.distinct()
.toList();
if (normalized.isEmpty()) return;
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
List<TPrjctAssignEntity> entities = normalized.stream()
.map(uid -> TPrjctAssignEntity.create(prjctIdx, uid, regUser, now))
.toList();
projectAssignRepository.saveAll(entities);
}
}

View File

@@ -0,0 +1,177 @@
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.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.data.domain.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Service
@RequiredArgsConstructor
public class ProjectService {
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){
String itrnt = req.getItrntPrjctCd();
for (int retry = 0; retry < AppConstant.INSERT_RETRY_COUNT; retry++) {
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;
}
}
throw BusinessException.conflict(
"PROJECT_CODE_CONFLICT",
"프로젝트 코드 생성 중 충돌이 발생했습니다. 다시 시도해주세요."
)
.with("itrntPrjctCd", itrnt);
}
public ProjectInfoDto getProject(Long prjctIdx){
return ProjectInfoDto.from(projectRepository.findByPrjctIdxAndDelFalse(prjctIdx));
}
public List<ProjectInfoDto> getTopProject(int topCount, String keyword, String userId, Integer userRole){
Specification<TPrjctEntity> spec =
ProjectSpecs.keywordLike(keyword)
.and(ProjectSpecs.isDelFalse());
if (userRole >= AppConstant.OUTSOURCE_USER_ROLE) {
if (userRole >= AppConstant.FIELDWORK_USER_ROLE) {
spec = spec.and(ProjectSpecs.statusIn(STATUS_1));
} else {
spec = spec.and(ProjectSpecs.statusIn(STATUS_0_1));
}
spec = spec.and(ProjectSpecs.assignedToUserAndNotExcluded(userId));
}
Pageable pageable = PageRequest.of(0, topCount, Sort.by(Sort.Direction.DESC, "regDt"));
return projectRepository.findAll(spec, pageable)
.getContent()
.stream()
.map(ProjectInfoDto::from) // <-- 너네 매핑 방식에 맞게 수정
.toList();
}
public PageResponseDto<ProjectInfoDto> searchProject(ProjectSearchRequestDto req, String userId, Integer userRole) {
Specification<TPrjctEntity> spec =
ProjectSpecs.keywordLike(req.getPrjctText())
.and(ProjectSpecs.isDelFalse())
.and(ProjectSpecs.statusIn(req.getPrjctStatusList()))
.and(ProjectSpecs.ownerDeptIn(req.getOwnerDeptList()))
.and(ProjectSpecs.ownerFwIn(req.getOwnerFwList()));
if (userRole >= AppConstant.OUTSOURCE_USER_ROLE) {
if (userRole >= AppConstant.FIELDWORK_USER_ROLE) {
spec = spec.and(ProjectSpecs.statusIn(STATUS_1));
} else {
spec = spec.and(ProjectSpecs.statusIn(STATUS_0_1));
}
spec = spec.and(ProjectSpecs.assignedToUserAndNotExcluded(userId));
}
Pageable pageable = PageRequest.of(
req.getPageIndex(),
req.getPageSize(),
ProjectSorts.toSort(req.getSortBy(), req.getSortDir())
);
Page<ProjectInfoDto> page = projectRepository.findAll(spec, pageable)
.map(ProjectInfoDto::from);
return PageResponseDto.from(page);
}
public ProjectOwnerResponseDto getOwnerList(Integer userRole){
ProjectOwnerResponseDto responseDto = new ProjectOwnerResponseDto();
responseDto.setOwnerDeptList(this.getOwnerDeptList(userRole));
responseDto.setOwnerFwList(this.getOwnerFwList(userRole));
return responseDto;
}
public List<String> getOwnerDeptList(Integer userRole) {
final List<Short> statusList =
(userRole < AppConstant.OUTSOURCE_USER_ROLE) ? null :
(userRole < AppConstant.FIELDWORK_USER_ROLE) ? STATUS_0_1 :
STATUS_1;
return projectRepository.findDistinctOwnerDept(statusList);
}
public List<String> getOwnerFwList(Integer userRole) {
final List<Short> statusList =
(userRole < AppConstant.OUTSOURCE_USER_ROLE) ? null :
(userRole < AppConstant.FIELDWORK_USER_ROLE) ? STATUS_0_1 :
STATUS_1;
return projectRepository.findDistinctOwnerFw(statusList);
}
@Transactional
public void updateProject(ProjectInfoDto req, String modUser){
// dirty checking 업데이트
TPrjctEntity entity = projectRepository.findById(req.getPrjctIdx())
.orElseThrow(() ->
BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
.with("prjctIdx", req.getPrjctIdx())
);
entity.updateFrom(req, modUser);
}
@Transactional
public void deleteProject(Long prjctIdx, String delUser){
int deleteCount = projectRepository.softDeleteByPrjctIdx(prjctIdx, delUser, DateTimeUtil.nowKstLocalDateTime());
if(deleteCount == 0){
throw BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
.with("prjctIdx", prjctIdx);
}
}
/***************************private************************************/
private String makePrjctCd(String itrntPrjctCd){
String prefix = itrntPrjctCd + "_";
List<TPrjctEntity> sameItrnt = projectRepository.findByItrntPrjctCd(itrntPrjctCd);
int maxSubCode = sameItrnt.stream()
.map(TPrjctEntity::getPrjctCd)
.filter(Objects::nonNull)
.filter(cd -> cd.startsWith(prefix))
.map(cd -> cd.substring(prefix.length()))
.filter(s -> s.matches("\\d+"))
.mapToInt(Integer::parseInt)
.max()
.orElse(0);
return prefix + String.format("%03d", (maxSubCode + 1));
}
}

View File

@@ -0,0 +1,29 @@
package com.kri.contact.server.service;
import com.kri.common.datetime.DateTimeUtil;
import com.kri.contact.server.persistence.entity.TResultCodeEntity;
import com.kri.contact.server.persistence.entity.TResultCodeEntityId;
import com.kri.contact.server.persistence.repository.ResultCodeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@RequiredArgsConstructor
public class ResultCodeService {
ResultCodeRepository resultCodeRepository;
@Transactional
public void copyResultCodeFromDefault(long prjctIdx, String regUser){
List<TResultCodeEntity> defaultCodeList = resultCodeRepository.findDefault();
List<TResultCodeEntity> copyCodeList = defaultCodeList.stream()
.map(src -> TResultCodeEntity.copyFromDefault(src, prjctIdx, regUser))
.toList();
resultCodeRepository.saveAll(copyCodeList);
}
}

View File

@@ -21,8 +21,8 @@ public class RoleService {
}
public List<RoleInfoDto> getRoleList(Integer roleCd){
Integer searchRoleCd = roleCd < AppConstant.EXTERNAL_USER_ROLE ?
AppConstant.EXTERNAL_USER_ROLE :
Integer searchRoleCd = roleCd < AppConstant.OUTSOURCE_USER_ROLE ?
AppConstant.OUTSOURCE_USER_ROLE :
AppConstant.FIELDWORK_USER_ROLE;
return roleRepository.findByRoleCdGreaterThanEqual(searchRoleCd).stream()

View File

@@ -1,7 +1,10 @@
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.systemlog.ProjectIdxContentDto;
import com.kri.contact.server.dto.systemlog.UploadUserContentDto;
import com.kri.contact.server.dto.systemlog.UserIdContentDto;
import com.kri.contact.server.common.enums.SystemEventType;
@@ -9,7 +12,9 @@ import com.kri.contact.server.persistence.entity.TSysEventLogEntity;
import com.kri.contact.server.persistence.repository.SystemEventLogRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import static com.kri.common.json.JsonUtil.toMap;
@@ -47,7 +52,25 @@ public class SystemEventLogService {
writeSystemLog(SystemEventType.DELETE_USER, "Delete User", null, regId, clientIp, content);
}
private <T> void writeSystemLog(
public void writeCreateProject(String regId, String clientIp, Long prjctIdx, ProjectCreateRequestDto req){
writeSystemLog(SystemEventType.CREAT_PROJECT, "Create Project", prjctIdx, regId, clientIp, req);
}
public void writeUpdateProject(String regId, String clientIp, Long prjctIdx, ProjectInfoDto req){
writeSystemLog(SystemEventType.UPDATE_PROJECT, "Update Project", prjctIdx, regId, clientIp, req);
}
public void writeDeleteProject(String regId, String clientIp, Long prjctIdx){
ProjectIdxContentDto content = new ProjectIdxContentDto(prjctIdx);
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,
String title,
Long prjctIdx,

View File

@@ -169,12 +169,24 @@ public class UserService {
.toList();
}
public List<UserInfoDto> getOutsourceList(){
List<TUserEntity> userList = userRepository.findByRoleRangeAndDelFalse(
AppConstant.OUTSOURCE_USER_ROLE,
AppConstant.OUTSOURCE_USER_ROLE + 1000
);
return userList.stream()
.map(UserInfoDto::from)
.toList();
}
public List<String> getUserCmpnList(){
return userRepository.findDistinctUserCmpnAndDelFalse();
}
@Transactional
public void updateUser(UserInfoDto dto, String modUser){
// dirty checking 업데이트
TUserEntity entity = userRepository.findByUserIdAndDelFalse(dto.getUserId())
.orElseThrow(() ->
BusinessException.notFound("USER_NOT_FOUND", "사용자를 찾을 수 없습니다.")