| | |
| | | package kr.wisestone.owl.service.impl; |
| | | |
| | | import kr.wisestone.owl.constant.MsgConstants; |
| | | import kr.wisestone.owl.domain.*; |
| | | import kr.wisestone.owl.domain.enumType.IssueHistoryType; |
| | | import kr.wisestone.owl.exception.OwlRuntimeException; |
| | | import kr.wisestone.owl.mapper.IssueIspMapper; |
| | | import kr.wisestone.owl.repository.IssueIspRepository; |
| | | import kr.wisestone.owl.service.*; |
| | | import kr.wisestone.owl.util.ConvertUtil; |
| | | import kr.wisestone.owl.util.MapUtil; |
| | | import kr.wisestone.owl.web.condition.IssueCondition; |
| | | import kr.wisestone.owl.web.form.IspFieldForm; |
| | | import kr.wisestone.owl.web.form.IssueForm; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private IspFieldService ispFieldService; |
| | | |
| | | @Autowired |
| | | private IssueService issueService; |
| | | |
| | | @Autowired |
| | | private IssueHistoryService issueHistoryService; |
| | | |
| | | @Autowired |
| | |
| | | return this.issueIspRepository; |
| | | } |
| | | |
| | | /** |
| | | * 새로운 ISP 직접 추가 |
| | | * @param issueForm IssueForm |
| | | * @param issue Issue |
| | | */ |
| | | private void CreateIspField(IssueForm issueForm, Issue issue, StringBuilder sb) { |
| | | //코드 유효성 체크 |
| | | this.verifyCode(issueForm); |
| | | |
| | | // issueIsp 필드 폼 만들기 |
| | | IspFieldForm ispFieldForm = new IspFieldForm(); |
| | | ispFieldForm.setName(issueForm.getIspName()); |
| | | ispFieldForm.setCode(issueForm.getIspCode()); |
| | | ispFieldForm.setEmail(issueForm.getIspEmail()); |
| | | ispFieldForm.setUrl(issueForm.getIspUrl()); |
| | | ispFieldForm.setManager(issueForm.getIspManager()); |
| | | ispFieldForm.setTel(issueForm.getIspTel()); |
| | | ispFieldForm.setMemo(issueForm.getIspMemo()); |
| | | |
| | | IssueIsp newIssueIsp = CreateIssueIsp(ispFieldForm, issue); |
| | | IspField ispField = new IspField(); |
| | | |
| | | // 사용자가 직접 입력시에 ISP 목록에 추가 |
| | | if (newIssueIsp.getIspField() == null) { |
| | | IssueIsp oldIssueIsp = this.issueIspRepository.findByIssueId(issue.getId()); |
| | | ispField = this.ispFieldService.add(ispFieldForm); |
| | | ispFieldForm.setId(ispField.getId()); |
| | | if (oldIssueIsp != null) { |
| | | issueHistoryService.detectIssueIsp(IssueHistoryType.MODIFY, null, ispFieldForm, oldIssueIsp, sb); |
| | | this.issueIspRepository.deleteById(oldIssueIsp.getId()); |
| | | } else { |
| | | newIssueIsp.setIspField(ispField); |
| | | issueHistoryService.detectIssueIsp(IssueHistoryType.ADD, null, ispFieldForm, newIssueIsp, sb); |
| | | } |
| | | } |
| | | this.issueIspRepository.saveAndFlush(newIssueIsp); |
| | | } |
| | | |
| | | /** |
| | | * 이슈 ISP 만들기 |
| | | * @param ispFieldForm IspFieldForm |
| | | * @param issue 이슈 |
| | | * @return IssueIsp |
| | | */ |
| | | private IssueIsp CreateIssueIsp(IspFieldForm ispFieldForm, Issue issue) { |
| | | IssueIsp issueIsp = ConvertUtil.copyProperties(ispFieldForm, IssueIsp.class, "id"); |
| | | issueIsp.setIssue(issue); |
| | | if (ispFieldForm.getId() != null && ispFieldForm.getId() != -1) { |
| | | IspField ispField = this.ispFieldService.getIsp(ispFieldForm.getId()); |
| | | issueIsp.setIspField(ispField); |
| | | } |
| | | |
| | | return issueIsp; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 이슈 ISP 만들기 |
| | | * @param ispFieldMap Map<String, Object> IspFieldForm map |
| | | * @param issue 이슈 |
| | | * @return IssueIsp CreateIssueIsp |
| | | */ |
| | | private IssueIsp CreateIssueIsp(Map<String, Object> ispFieldMap, Issue issue) { |
| | | IspFieldForm ispFieldForm = ConvertUtil.convertMapToClass(ispFieldMap, IspFieldForm.class); |
| | | ispFieldForm.setId(MapUtil.getLong(ispFieldMap, "ispId")); |
| | | return CreateIssueIsp(ispFieldForm, issue); |
| | | } |
| | | |
| | | /** |
| | | * 코드 유효성 검사 |
| | | * @param param Map<String, Object> |
| | | */ |
| | | private void verifyCode(Map<String, Object> param) { |
| | | if (param != null) { |
| | | if (MapUtil.getString(param, "code") == null || Objects.equals(MapUtil.getString(param, "code"), "")) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.ISP_CODE_NOT_ENTER)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 코드 유효성 검사 |
| | | * @param issueForm IssueForm |
| | | */ |
| | | private void verifyCode(IssueForm issueForm) { |
| | | if (issueForm != null) { |
| | | if (issueForm.getIspCode() == null || issueForm.getIspCode().equals("")) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.ISP_CODE_NOT_ENTER)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 이슈에서 사용되는 업체 값을 업데이트한다. |
| | | @Override |
| | | @Transactional |
| | | public void modifyIssueIspField(Issue issue, List<Map<String, Object>> issueIspFields) { |
| | | public void modifyIssueIspField(Issue issue, IssueForm issueForm, StringBuilder sb) { |
| | | if (issue != null) { |
| | | IssueIsp issueIsp = this.issueIspRepository.findByIssueId(issue.getId()); |
| | | List<Map<String, Object>> issueIspFields = issueForm.getIssueIspFields(); |
| | | |
| | | if (issueIspFields != null && issueIspFields.size() > 0) { |
| | | Map<String, Object> param = issueIspFields.get(0); |
| | | |
| | | if (param != null && param.get("ispId") != null && param.get("ispId") != "") { |
| | | IspField ispField = this.ispFieldService.getIsp(MapUtil.getLong(param, "ispId")); |
| | | this.verifyCode(param); //코드 유효성 체크 |
| | | |
| | | Set<IssueIsp> issueIsps = issue.getIssueIspFields(); |
| | | IssueIsp issueIsp = new IssueIsp(); |
| | | if (issueIsp != null) {//수정 시 |
| | | // 변경 이력 남기고 issueIsp에 set해주기 |
| | | issueHistoryService.detectIssueIsp(IssueHistoryType.MODIFY, param, null, issueIsp, sb); |
| | | |
| | | if (issueIsps != null && issueIsps.size() > 0) {//수정 할 경우 |
| | | issueIsp = issueIsps.iterator().next(); |
| | | // 변경 이력 |
| | | StringBuilder sb = new StringBuilder(); |
| | | issueHistoryService.detectIssueIsp(IssueHistoryType.MODIFY, param, issueIsp, sb); |
| | | issueHistoryService.addIssueHistory(issue, IssueHistoryType.MODIFY, sb.toString()); |
| | | issueIsp.setName(MapUtil.getString(param, "name")); |
| | | issueIsp.setEmail(MapUtil.getString(param, "email")); |
| | | issueIsp.setCode(MapUtil.getString(param, "code")); |
| | | issueIsp.setUrl(MapUtil.getString(param, "url")); |
| | | issueIsp.setManager(MapUtil.getString(param, "manager")); |
| | | issueIsp.setTel(MapUtil.getString(param, "tel")); |
| | | issueIsp.setMemo(MapUtil.getString(param, "memo")); |
| | | |
| | | issueIsp.setIspField(ispField); |
| | | issueIsp.setName(MapUtil.getString(param, "name")); |
| | | issueIsp.setEmail(MapUtil.getString(param, "email")); |
| | | issueIsp.setCode(MapUtil.getString(param, "code")); |
| | | issueIsp.setUrl(MapUtil.getString(param, "url")); |
| | | issueIsp.setManager(MapUtil.getString(param, "manager")); |
| | | issueIsp.setTel(MapUtil.getString(param, "tel")); |
| | | issueIsp.setMemo(MapUtil.getString(param, "memo")); |
| | | } else {//추가 할 경우 |
| | | issueIsp = ConvertUtil.convertMapToClass(param, IssueIsp.class); |
| | | issueIsp.setIssue(issue); |
| | | if (ispField != null) { |
| | | issueIsp.setIspField(ispField); |
| | | } |
| | | // 추가 이력 |
| | | StringBuilder sb = new StringBuilder(); |
| | | issueHistoryService.detectIssueIsp(IssueHistoryType.ADD, param, issueIsp, sb); |
| | | issueHistoryService.addIssueHistory(issue, IssueHistoryType.MODIFY, sb.toString()); |
| | | } |
| | | this.issueIspRepository.saveAndFlush(issueIsp); |
| | | }else { |
| | | this.issueIspRepository.deleteById(MapUtil.getLong(param, "id")); |
| | | |
| | | } else { //추가 시 |
| | | IssueIsp newIssueIsp = CreateIssueIsp(param, issue); |
| | | // 추가 이력 |
| | | issueHistoryService.detectIssueIsp(IssueHistoryType.ADD, param, null, newIssueIsp, sb); |
| | | this.issueIspRepository.saveAndFlush(newIssueIsp); |
| | | } |
| | | |
| | | } else if (issueForm.getIspName() != null && !issueForm.getIspName().equals("")) { |
| | | //ISP정보 직접 추가 |
| | | CreateIspField(issueForm, issue, sb); |
| | | } else { |
| | | this.issueIspRepository.deleteByIssueId(issue.getId()); |
| | | this.issueIspRepository.flush(); |
| | | |
| | | if (issueIsp != null) { |
| | | issueHistoryService.detectIssueIsp(IssueHistoryType.DELETE, null, null, issueIsp, sb); |
| | | } |
| | | } |
| | | //issueHistoryService.addIssueHistory(issue, IssueHistoryType.MODIFY, sb.toString()); |
| | | } |
| | | } |
| | | |