package kr.wisestone.owl.service.impl; import kr.wisestone.owl.constant.Constants; import kr.wisestone.owl.domain.*; import kr.wisestone.owl.repository.IssueTableConfigRepository; import kr.wisestone.owl.service.IssueService; import kr.wisestone.owl.service.IssueTableConfigService; import kr.wisestone.owl.service.UserService; import kr.wisestone.owl.service.WorkspaceService; import kr.wisestone.owl.util.ConvertUtil; import kr.wisestone.owl.util.MapUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Map; @Service public class IssueTableConfigServiceImpl extends AbstractServiceImpl> implements IssueTableConfigService { private static final Logger log = LoggerFactory.getLogger(IssueTableConfigServiceImpl.class); @Autowired private IssueTableConfigRepository issueTableConfigRepository; @Autowired private WorkspaceService workspaceService; @Autowired private UserService userService; @Override protected JpaRepository getRepository() { return this.issueTableConfigRepository; } Long issueId; int issueTableType = 0; //issueTableType 초기값 설정 // add 중복코드 제거 public IssueTableConfig addMultipleCode(Map params, Long issueId, int issueTableType) { String issueTableConfigs = MapUtil.getString(params, "issueTableConfigs"); IssueTableConfig issueTableConfig = this.findByUserIdAndWorkspaceIdAndIssueIdAndIssueTableType(issueId, issueTableType); //IssueTableConfig saveIssueTableType = this.findByIssueIdAndIssueTableType(issueId,issueTableType); // 아직 테이블 컬럼 설정을 하지 않았을 경우 if (issueTableConfig == null) { issueTableConfig = new IssueTableConfig(); Workspace workspace = this.workspaceService.getWorkspace(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId()); User user = this.userService.getUser(this.webAppUtil.getLoginId()); issueTableConfig.setWorkspace(workspace); issueTableConfig.setUser(user); issueTableConfig.setIssueId(issueId); issueTableConfig.setIssueTableType(issueTableType); issueTableConfig.setIssueTableConfigs(issueTableConfigs); /*}else if(saveIssueTableType == null){ issueTableConfig = new IssueTableConfig(); Workspace workspace = this.workspaceService.getWorkspace(this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId()); User user = this.userService.getUser(this.webAppUtil.getLoginId()); issueTableConfig.setWorkspace(workspace); issueTableConfig.setUser(user); issueTableConfig.setIssueId(issueId); issueTableConfig.setIssueTableType(issueTableType); issueTableConfig.setIssueTableConfigs(issueTableConfigs);*/ }else { issueTableConfig.setIssueTableConfigs(issueTableConfigs); } return this.issueTableConfigRepository.saveAndFlush(issueTableConfig); } // 이슈 테이블 컬럼 설정 정보를 저장한다. @Override @Transactional public IssueTableConfig addIssueTableConfig(Map params) { issueId = (long) -1; issueTableType = 1; return this.addMultipleCode(params, issueId, issueTableType); } // 연관 이슈 테이블 설정 정보 저장 @Override public IssueTableConfig addRelationIssueTableConfig(Map params) { issueId = MapUtil.getLong(params, "issueId"); issueTableType = 2; return this.addMultipleCode(params, issueId, issueTableType); } // 하위 이슈 테이블 설정 정보 저장 @Override public IssueTableConfig addDownIssueTableConfig(Map params) { issueId = MapUtil.getLong(params, "issueId"); issueTableType = 3; return this.addMultipleCode(params, issueId, issueTableType); } // 해당 업무 공간에서 사용자의 이슈 테이블 설정을 조회한다. @Override @Transactional(readOnly = true) public IssueTableConfig findByUserIdAndWorkspaceIdAndIssueIdAndIssueTableType(Long issueId, int issueTableType) { return this.issueTableConfigRepository.findByUserIdAndWorkspaceIdAndIssueIdAndIssueTableType(this.webAppUtil.getLoginId(), this.userService.getUser(this.webAppUtil.getLoginId()).getLastWorkspaceId(), issueId, issueTableType); } //이슈 Id와 IssueTableType 조회 @Override @Transactional(readOnly = true) public IssueTableConfig findByIssueIdAndIssueTableType(Long issueId, int issueTableType) { return this.issueTableConfigRepository.findByIssueIdAndIssueTableType(issueId, issueTableType); } // detail 중복 코드 제거 private void detailMultipleCode(Map resJsonData, Long issueId, int issueTableType) { // 해당 업무 공간에서 사용자의 이슈 검색 조건을 조회한다. IssueTableConfig issueTableConfig = this.findByUserIdAndWorkspaceIdAndIssueIdAndIssueTableType(issueId, issueTableType); if (issueTableConfig != null) { resJsonData.put(Constants.RES_KEY_CONTENTS, issueTableConfig.getIssueTableConfigs()); } else { resJsonData.put(Constants.RES_KEY_CONTENTS, ""); } } // 저장된 이슈 테이블 설정을 조회한다. @Override @Transactional(readOnly = true) public void detailIssueTableConfig(Map resJsonData) { issueId = (long) -1; issueTableType = 1; // 해당 업무 공간에서 사용자의 이슈 검색 조건을 조회한다. IssueTableConfig issueTableConfig = this.findByUserIdAndWorkspaceIdAndIssueIdAndIssueTableType(issueId, issueTableType); if (issueTableConfig != null) { resJsonData.put(Constants.RES_KEY_CONTENTS, issueTableConfig.getIssueTableConfigs()); } else { resJsonData.put(Constants.RES_KEY_CONTENTS, ""); } } // 저장된 연관 이슈 테이블 설정 조회 @Override public void detailRelationIssueTableConfig(Map params, Map resJsonData) { issueTableType = 2; issueId = MapUtil.getLong(params, "issueId"); this.detailMultipleCode(resJsonData, issueId, issueTableType); } // 저장된 하위 이슈 테이블 설정 조회 @Override public void detailDownIssueTableConfig(Map params, Map resJsonData) { issueTableType = 3; issueId = MapUtil.getLong(params, "issueId"); this.detailMultipleCode(resJsonData, issueId, issueTableType); } }