260212_01_DOC: 프로젝트 전체에 구글 java 스타일 적용
This commit is contained in:
@@ -1,192 +1,211 @@
|
||||
package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.web.BusinessException;
|
||||
import com.kri.common.webmvc.page.*;
|
||||
import com.kri.common.webmvc.page.PageRequestDto;
|
||||
import com.kri.common.webmvc.page.PageResponseDto;
|
||||
import com.kri.common.webmvc.page.Pageables;
|
||||
import com.kri.contact.server.common.consts.ContactConstant;
|
||||
import com.kri.contact.server.dto.*;;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctMainTmplatEntity;
|
||||
import com.kri.contact.server.dto.ProjectCreateRequestDto;
|
||||
import com.kri.contact.server.dto.ProjectInfoDto;
|
||||
import com.kri.contact.server.dto.ProjectMainTemplateUpdateRequestDto;
|
||||
import com.kri.contact.server.dto.ProjectOwnerResponseDto;
|
||||
import com.kri.contact.server.dto.ProjectSearchRequestDto;
|
||||
import com.kri.contact.server.dto.ProjectUpdateRequestDto;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctEntity;
|
||||
import com.kri.contact.server.persistence.entity.TPrjctMainTmplatEntity;
|
||||
import com.kri.contact.server.persistence.query.ProjectSpecs;
|
||||
import com.kri.contact.server.persistence.repository.ProjectMainTemplateRepository;
|
||||
import com.kri.contact.server.persistence.repository.ProjectRepository;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProjectService {
|
||||
|
||||
private final AssignService assignService;
|
||||
private final ResultCodeService resultCodeService;
|
||||
private final ProjectRepository projectRepository;
|
||||
private final ProjectMainTemplateRepository projectMainTemplateRepository;
|
||||
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);
|
||||
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);
|
||||
private final AssignService assignService;
|
||||
private final ResultCodeService resultCodeService;
|
||||
private final ProjectRepository projectRepository;
|
||||
private final ProjectMainTemplateRepository projectMainTemplateRepository;
|
||||
|
||||
@Transactional
|
||||
public ProjectInfoDto createProject(ProjectCreateRequestDto req, String regUser, LocalDateTime regDt) {
|
||||
String itrnt = req.getItrntPrjctCd();
|
||||
@Transactional
|
||||
public ProjectInfoDto createProject(ProjectCreateRequestDto req, String regUser,
|
||||
LocalDateTime regDt) {
|
||||
String itrnt = req.getItrntPrjctCd();
|
||||
|
||||
try {
|
||||
String prjctCd = this.makePrjctCd(itrnt);
|
||||
TPrjctEntity entity = TPrjctEntity.create(req, prjctCd, regUser, regDt);
|
||||
try {
|
||||
String prjctCd = this.makePrjctCd(itrnt);
|
||||
TPrjctEntity entity = TPrjctEntity.create(req, prjctCd, regUser, regDt);
|
||||
|
||||
ProjectInfoDto savedProject = ProjectInfoDto.from(projectRepository.save(entity));
|
||||
resultCodeService.copyResultCodeFromDefault(savedProject.getPrjctIdx(), regUser, regDt);
|
||||
ProjectInfoDto savedProject = ProjectInfoDto.from(projectRepository.save(entity));
|
||||
resultCodeService.copyResultCodeFromDefault(savedProject.getPrjctIdx(), regUser, regDt);
|
||||
|
||||
return savedProject;
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
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) {
|
||||
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 >= ContactConstant.OUTSOURCE_USER_ROLE) {
|
||||
if (userRole >= ContactConstant.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));
|
||||
}
|
||||
|
||||
public ProjectInfoDto getProject(Long prjctIdx) {
|
||||
return ProjectInfoDto.from(projectRepository.findByPrjctIdxAndDelFalse(prjctIdx));
|
||||
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 >= ContactConstant.OUTSOURCE_USER_ROLE) {
|
||||
if (userRole >= ContactConstant.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));
|
||||
}
|
||||
|
||||
public List<ProjectInfoDto> getTopProject(int topCount, String keyword, String userId, Integer userRole) {
|
||||
Specification<TPrjctEntity> spec =
|
||||
ProjectSpecs.keywordLike(keyword)
|
||||
.and(ProjectSpecs.isDelFalse());
|
||||
PageRequestDto pageReq = req.getPageRequest();
|
||||
Pageable pageable = Pageables.of(pageReq, TPrjctEntity.class);
|
||||
|
||||
if (userRole >= ContactConstant.OUTSOURCE_USER_ROLE) {
|
||||
if (userRole >= ContactConstant.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));
|
||||
}
|
||||
Page<ProjectInfoDto> page = projectRepository.findAll(spec, pageable)
|
||||
.map(ProjectInfoDto::from);
|
||||
|
||||
Pageable pageable = PageRequest.of(0, topCount, Sort.by(Sort.Direction.DESC, "regDt"));
|
||||
return PageResponseDto.from(page);
|
||||
}
|
||||
|
||||
return projectRepository.findAll(spec, pageable)
|
||||
.getContent()
|
||||
.stream()
|
||||
.map(ProjectInfoDto::from) // <-- 너네 매핑 방식에 맞게 수정
|
||||
.toList();
|
||||
}
|
||||
public ProjectOwnerResponseDto getOwnerList(Integer userRole) {
|
||||
ProjectOwnerResponseDto responseDto = new ProjectOwnerResponseDto();
|
||||
|
||||
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()));
|
||||
responseDto.setOwnerDeptList(this.getOwnerDeptList(userRole));
|
||||
responseDto.setOwnerFwList(this.getOwnerFwList(userRole));
|
||||
|
||||
if (userRole >= ContactConstant.OUTSOURCE_USER_ROLE) {
|
||||
if (userRole >= ContactConstant.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));
|
||||
}
|
||||
return responseDto;
|
||||
}
|
||||
|
||||
PageRequestDto pageReq = req.getPageRequest();
|
||||
Pageable pageable = Pageables.of(pageReq, TPrjctEntity.class);
|
||||
|
||||
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 < ContactConstant.OUTSOURCE_USER_ROLE) ? null :
|
||||
public List<String> getOwnerDeptList(Integer userRole) {
|
||||
final List<Short> statusList =
|
||||
(userRole < ContactConstant.OUTSOURCE_USER_ROLE) ? null :
|
||||
(userRole < ContactConstant.FIELDWORK_USER_ROLE) ? STATUS_0_1 :
|
||||
STATUS_1;
|
||||
STATUS_1;
|
||||
|
||||
return projectRepository.findDistinctOwnerDept(statusList);
|
||||
}
|
||||
return projectRepository.findDistinctOwnerDept(statusList);
|
||||
}
|
||||
|
||||
public List<String> getOwnerFwList(Integer userRole) {
|
||||
final List<Short> statusList =
|
||||
(userRole < ContactConstant.OUTSOURCE_USER_ROLE) ? null :
|
||||
public List<String> getOwnerFwList(Integer userRole) {
|
||||
final List<Short> statusList =
|
||||
(userRole < ContactConstant.OUTSOURCE_USER_ROLE) ? null :
|
||||
(userRole < ContactConstant.FIELDWORK_USER_ROLE) ? STATUS_0_1 :
|
||||
STATUS_1;
|
||||
STATUS_1;
|
||||
|
||||
return projectRepository.findDistinctOwnerFw(statusList);
|
||||
return projectRepository.findDistinctOwnerFw(statusList);
|
||||
}
|
||||
|
||||
public Long getMainTemplateIdx(Long prjctIdx, Short chnnlTy) {
|
||||
return projectMainTemplateRepository.findByIdPrjctIdxAndIdChnnlTy(prjctIdx, chnnlTy)
|
||||
.map(TPrjctMainTmplatEntity::getTmplatIdx)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProject(long prjctIdx, ProjectUpdateRequestDto req, String modUser,
|
||||
LocalDateTime modDt) {
|
||||
// dirty checking 업데이트
|
||||
TPrjctEntity entity = projectRepository.findById(prjctIdx)
|
||||
.orElseThrow(() ->
|
||||
BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
|
||||
.with("prjctIdx", prjctIdx)
|
||||
);
|
||||
|
||||
entity.updateFrom(req.getProjectInfo(), modUser, modDt);
|
||||
|
||||
assignService.upsertPrjctOutsourceAssign(prjctIdx, req.getAssignUserIdList(), modUser, modDt);
|
||||
resultCodeService.updateResultCode(prjctIdx, req.getResultCodeList(), modUser, modDt);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProjectMainTemplate(ProjectMainTemplateUpdateRequestDto req, String modUser,
|
||||
LocalDateTime modDt) {
|
||||
Short chnnlTy = req.getChnnlTy().getCode();
|
||||
projectMainTemplateRepository.deleteByIdPrjctIdxAndIdChnnlTy(req.getPrjctIdx(), chnnlTy);
|
||||
|
||||
if (req.getTmplatIdx() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
public Long getMainTemplateIdx(Long prjctIdx, Short chnnlTy) {
|
||||
return projectMainTemplateRepository.findByIdPrjctIdxAndIdChnnlTy(prjctIdx, chnnlTy)
|
||||
.map(TPrjctMainTmplatEntity::getTmplatIdx)
|
||||
.orElse(null);
|
||||
TPrjctMainTmplatEntity entity = TPrjctMainTmplatEntity.create(req, modUser, modDt);
|
||||
projectMainTemplateRepository.save(entity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteProject(Long prjctIdx, String delUser, LocalDateTime delDt) {
|
||||
int deleteCount = projectRepository.softDeleteByPrjctIdx(prjctIdx, delUser, delDt);
|
||||
|
||||
if (deleteCount == 0) {
|
||||
throw BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
|
||||
.with("prjctIdx", prjctIdx);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProject(long prjctIdx, ProjectUpdateRequestDto req, String modUser, LocalDateTime modDt) {
|
||||
// dirty checking 업데이트
|
||||
TPrjctEntity entity = projectRepository.findById(prjctIdx)
|
||||
.orElseThrow(() ->
|
||||
BusinessException.notFound("PROJECT_NOT_FOUND", "프로젝트를 찾을 수 없습니다.")
|
||||
.with("prjctIdx", prjctIdx)
|
||||
);
|
||||
/***************************private************************************/
|
||||
private String makePrjctCd(String itrntPrjctCd) {
|
||||
String prefix = itrntPrjctCd + "_";
|
||||
|
||||
entity.updateFrom(req.getProjectInfo(), modUser, modDt);
|
||||
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);
|
||||
|
||||
assignService.upsertPrjctOutsourceAssign(prjctIdx, req.getAssignUserIdList(), modUser, modDt);
|
||||
resultCodeService.updateResultCode(prjctIdx, req.getResultCodeList(), modUser, modDt);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateProjectMainTemplate(ProjectMainTemplateUpdateRequestDto req, String modUser, LocalDateTime modDt) {
|
||||
Short chnnlTy = req.getChnnlTy().getCode();
|
||||
projectMainTemplateRepository.deleteByIdPrjctIdxAndIdChnnlTy(req.getPrjctIdx(), chnnlTy);
|
||||
|
||||
if(req.getTmplatIdx() == null) return;
|
||||
|
||||
TPrjctMainTmplatEntity entity = TPrjctMainTmplatEntity.create(req, modUser, modDt);
|
||||
projectMainTemplateRepository.save(entity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteProject(Long prjctIdx, String delUser, LocalDateTime delDt) {
|
||||
int deleteCount = projectRepository.softDeleteByPrjctIdx(prjctIdx, delUser, delDt);
|
||||
|
||||
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));
|
||||
}
|
||||
return prefix + String.format("%03d", (maxSubCode + 1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user