Merge branch 'main-design-layout' of https://git.eactive.synology.me:8090/kjb-eapim/eapim-portal into main-design-layout
This commit is contained in:
@@ -9,12 +9,8 @@ public final class Constants {
|
||||
|
||||
public static final String APIM_FOR_OBP_KEY = "x-obp-trust-system";
|
||||
|
||||
public static final String APIM_FOR_OBP_VALUE = "APIMPT-0002-QVBJTVBULTAwMDI=";
|
||||
|
||||
public static final String APIM_CODE_FOR_OBP_KEY = "x-obp-partnercode";
|
||||
|
||||
public static final String APIM_CODE_FOR_OBP_VALUE = "100001-01";
|
||||
|
||||
public static final String SMS_URL = "/api/messaging/sms";
|
||||
|
||||
public static final String COMMISSION_URL = "/api/billing/billing/findBillingForCondition";
|
||||
|
||||
+45
-31
@@ -6,6 +6,7 @@ import com.eactive.apim.portal.apps.commission.dto.CommissionSearch;
|
||||
import com.eactive.apim.portal.apps.commission.exception.ErrorUtil;
|
||||
import com.eactive.apim.portal.apps.commission.service.ExternalService;
|
||||
import com.eactive.apim.portal.common.util.SecurityUtil;
|
||||
import com.eactive.apim.portal.portalproperty.service.PortalPropertyService;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.ArrayList;
|
||||
@@ -16,7 +17,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -38,14 +38,7 @@ public class CommissionController {
|
||||
private final Logger log = LoggerFactory.getLogger(CommissionController.class);
|
||||
|
||||
private final ExternalService externalService;
|
||||
|
||||
@Value("${obm-url:http://localhost:8080}")
|
||||
private String obmUrl;
|
||||
|
||||
@Value("${provider-code:100001-01}")
|
||||
private String providerCode;
|
||||
|
||||
// ==================== View Controllers ====================
|
||||
private final PortalPropertyService portalPropertyService;
|
||||
|
||||
@GetMapping("/manage")
|
||||
public String commissionManagePage(Model model) {
|
||||
@@ -66,11 +59,10 @@ public class CommissionController {
|
||||
search.setYear(year);
|
||||
search.setMonth(month);
|
||||
|
||||
search.setProvider(providerCode);
|
||||
|
||||
if (!StringUtils.isEmpty(search.getPartnerCode())) {
|
||||
try {
|
||||
String url = obmUrl + Constants.COMMISSION_URL;
|
||||
String obmUrl = portalPropertyService.getPortalPropertiesAsMap("Portal").getOrDefault("obp.obm.url", "");
|
||||
String url = obmUrl + Constants.COMMISSION_PRINT_URL;
|
||||
String result = externalService.getResponseHttpPost(url, toJson(search));
|
||||
HashMap<String, Object> returnObj = new ObjectMapper().readValue(result, HashMap.class);
|
||||
|
||||
@@ -85,10 +77,10 @@ public class CommissionController {
|
||||
search.setPartnerCode("000002-02");
|
||||
String togetherResult = externalService.getResponseHttpPost(url, toJson(search));
|
||||
|
||||
HashMap<String, Object> togetherLendingReturnObj = new ObjectMapper().readValue(togetherResult, HashMap.class);
|
||||
HashMap togetherLendingReturnObj = new ObjectMapper().readValue(togetherResult, HashMap.class);
|
||||
log.debug("togetherLendingReturnObj : " + togetherLendingReturnObj.toString());
|
||||
if (!StringUtils.isEmpty(togetherLendingReturnObj.get("error"))) {
|
||||
HashMap<String, Object> error = (HashMap) togetherLendingReturnObj.get("error");
|
||||
HashMap error = (HashMap) togetherLendingReturnObj.get("error");
|
||||
model.addAttribute("error", error.get("message").toString());
|
||||
return "apps/commission/commissionPrint";
|
||||
}
|
||||
@@ -119,11 +111,11 @@ public class CommissionController {
|
||||
@PostMapping()
|
||||
public ResponseEntity<?> list(@RequestBody CommissionSearch search) {
|
||||
CommissionDTO commissionDTO = null;
|
||||
search.setProvider(providerCode);
|
||||
search.setPartnerCode(SecurityUtil.getUserOrg().getOrgCode());
|
||||
|
||||
if (!StringUtils.isEmpty(search.getPartnerCode())) {
|
||||
try {
|
||||
String obmUrl = portalPropertyService.getPortalPropertiesAsMap("Portal").getOrDefault("obp.obm.url", "");
|
||||
String url = obmUrl + Constants.COMMISSION_URL;
|
||||
String result = externalService.getResponseHttpPost(url, toJson(search));
|
||||
HashMap<String, Object> returnObj = new ObjectMapper().readValue(result, HashMap.class);
|
||||
@@ -170,6 +162,28 @@ public class CommissionController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely parse double value from HashMap
|
||||
* Handles both numeric types and string representations
|
||||
*/
|
||||
private double safeGetDouble(HashMap<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
if (value == null) {
|
||||
return 0.0;
|
||||
}
|
||||
try {
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).doubleValue();
|
||||
} else if (value instanceof String) {
|
||||
return Double.parseDouble((String) value);
|
||||
}
|
||||
return 0.0;
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("Failed to parse double value for key: {} with value: {}", key, value);
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, Object> mergeCommissionData(HashMap<String, Object> o1, HashMap<String, Object> o2) {
|
||||
|
||||
HashMap<String, Object> mergeMap = new HashMap<String, Object>();
|
||||
@@ -182,22 +196,22 @@ public class CommissionController {
|
||||
} else {
|
||||
resultStatus = o2Status;
|
||||
}
|
||||
double apiTotalValueSum = MapUtils.getDouble(o1, "apiTotalValueSum") + MapUtils.getDouble(o2, "apiTotalValueSum");
|
||||
double apiSum = MapUtils.getDouble(o1, "apiSum") + MapUtils.getDouble(o2, "apiSum");
|
||||
double apiTotalValueSum2 = MapUtils.getDouble(o1, "apiTotalValueSum2") + MapUtils.getDouble(o2, "apiTotalValueSum2");
|
||||
double apiSum2 = MapUtils.getDouble(o1, "apiSum2") + MapUtils.getDouble(o2, "apiSum2");
|
||||
double productTotalValueCountSum = MapUtils.getDouble(o1, "productTotalValueCountSum") + MapUtils.getDouble(o2, "productTotalValueCountSum");
|
||||
double productTotalValueAmountSum = MapUtils.getDouble(o1, "productTotalValueAmountSum") + MapUtils.getDouble(o2, "productTotalValueAmountSum");
|
||||
double productSum = MapUtils.getDouble(o1, "productSum") + MapUtils.getDouble(o2, "productSum");
|
||||
double productTotalValueCountSum2 = MapUtils.getDouble(o1, "productTotalValueCountSum2") + MapUtils.getDouble(o2, "productTotalValueCountSum2");
|
||||
double productTotalValueAmountSum2 = MapUtils.getDouble(o1, "productTotalValueAmountSum2") + MapUtils.getDouble(o2, "productTotalValueAmountSum2");
|
||||
double productSum2 = MapUtils.getDouble(o1, "productSum2") + MapUtils.getDouble(o2, "productSum2");
|
||||
double totalValueCountSum = MapUtils.getDouble(o1, "totalValueCountSum") + MapUtils.getDouble(o2, "totalValueCountSum");
|
||||
double totalValueCountSum2 = MapUtils.getDouble(o1, "totalValueCountSum2") + MapUtils.getDouble(o2, "totalValueCountSum2");
|
||||
double totalValueAmountSum = MapUtils.getDouble(o1, "totalValueAmountSum") + MapUtils.getDouble(o2, "totalValueAmountSum");
|
||||
double totalValueAmountSum2 = MapUtils.getDouble(o1, "totalValueAmountSum2") + MapUtils.getDouble(o2, "totalValueAmountSum2");
|
||||
double sum = MapUtils.getDouble(o1, "sum") + MapUtils.getDouble(o2, "sum");
|
||||
double sum2 = MapUtils.getDouble(o1, "sum2") + MapUtils.getDouble(o2, "sum2");
|
||||
double apiTotalValueSum = safeGetDouble(o1, "apiTotalValueSum") + safeGetDouble(o2, "apiTotalValueSum");
|
||||
double apiSum = safeGetDouble(o1, "apiSum") + safeGetDouble(o2, "apiSum");
|
||||
double apiTotalValueSum2 = safeGetDouble(o1, "apiTotalValueSum2") + safeGetDouble(o2, "apiTotalValueSum2");
|
||||
double apiSum2 = safeGetDouble(o1, "apiSum2") + safeGetDouble(o2, "apiSum2");
|
||||
double productTotalValueCountSum = safeGetDouble(o1, "productTotalValueCountSum") + safeGetDouble(o2, "productTotalValueCountSum");
|
||||
double productTotalValueAmountSum = safeGetDouble(o1, "productTotalValueAmountSum") + safeGetDouble(o2, "productTotalValueAmountSum");
|
||||
double productSum = safeGetDouble(o1, "productSum") + safeGetDouble(o2, "productSum");
|
||||
double productTotalValueCountSum2 = safeGetDouble(o1, "productTotalValueCountSum2") + safeGetDouble(o2, "productTotalValueCountSum2");
|
||||
double productTotalValueAmountSum2 = safeGetDouble(o1, "productTotalValueAmountSum2") + safeGetDouble(o2, "productTotalValueAmountSum2");
|
||||
double productSum2 = safeGetDouble(o1, "productSum2") + safeGetDouble(o2, "productSum2");
|
||||
double totalValueCountSum = safeGetDouble(o1, "totalValueCountSum") + safeGetDouble(o2, "totalValueCountSum");
|
||||
double totalValueCountSum2 = safeGetDouble(o1, "totalValueCountSum2") + safeGetDouble(o2, "totalValueCountSum2");
|
||||
double totalValueAmountSum = safeGetDouble(o1, "totalValueAmountSum") + safeGetDouble(o2, "totalValueAmountSum");
|
||||
double totalValueAmountSum2 = safeGetDouble(o1, "totalValueAmountSum2") + safeGetDouble(o2, "totalValueAmountSum2");
|
||||
double sum = safeGetDouble(o1, "sum") + safeGetDouble(o2, "sum");
|
||||
double sum2 = safeGetDouble(o1, "sum2") + safeGetDouble(o2, "sum2");
|
||||
|
||||
List<Map> o1List = (ArrayList) o1.get("list");
|
||||
List<Map> o2pList = (ArrayList) o2.get("list");
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.eactive.apim.portal.apps.commission.dto;
|
||||
|
||||
import com.eactive.apim.portal.portalorg.entity.PortalOrg;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -15,7 +14,4 @@ public class CommissionSearch {
|
||||
|
||||
private String partnerCode;
|
||||
|
||||
private PortalOrg organization;
|
||||
|
||||
private String provider;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.eactive.apim.portal.apps.commission.service;
|
||||
|
||||
import com.eactive.apim.portal.apps.commission.constant.Constants;
|
||||
import com.eactive.apim.portal.portalproperty.service.PortalPropertyService;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@@ -22,16 +25,13 @@ import org.springframework.web.client.RestTemplate;
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
public class ExternalService {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ExternalService.class);
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
@Inject
|
||||
public ExternalService(RestTemplate restTemplate) {
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
private final PortalPropertyService portalPropertyService;
|
||||
|
||||
/**
|
||||
* HTTP POST 요청을 통해 외부 API를 호출하고 응답을 받습니다.
|
||||
@@ -42,11 +42,14 @@ public class ExternalService {
|
||||
*/
|
||||
public String getResponseHttpPost(String url, String payload) {
|
||||
try {
|
||||
|
||||
Map<String, String> portalProperties = portalPropertyService.getPortalPropertiesAsMap("Portal");
|
||||
|
||||
// HTTP 헤더 설정
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set(Constants.APIM_FOR_OBP_KEY, Constants.APIM_FOR_OBP_VALUE);
|
||||
headers.set(Constants.APIM_CODE_FOR_OBP_KEY, Constants.APIM_CODE_FOR_OBP_VALUE);
|
||||
headers.set(Constants.APIM_FOR_OBP_KEY, portalProperties.getOrDefault("obp.api_key","APIMPT-0002-QVBJTVBULTAwMDI="));
|
||||
headers.set(Constants.APIM_CODE_FOR_OBP_KEY, portalProperties.getOrDefault("obp.partner_code","100001-01"));
|
||||
|
||||
// HTTP 요청 엔티티 생성 (헤더 + 본문)
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(payload, headers);
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.eactive.apim.portal.apps.community.partnership.controller;
|
||||
|
||||
import com.eactive.apim.portal.apps.community.partnership.dto.PartnershipApplicationDTO;
|
||||
import com.eactive.apim.portal.apps.community.partnership.service.PartnershipApplicationFacade;
|
||||
import com.eactive.apim.portal.common.util.SecurityUtil;
|
||||
import java.io.IOException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/partnership")
|
||||
public class PartnershipApplicationController {
|
||||
|
||||
private final PartnershipApplicationFacade partnershipApplicationFacade;
|
||||
|
||||
@Autowired
|
||||
public PartnershipApplicationController(PartnershipApplicationFacade partnershipApplicationFacade){
|
||||
this.partnershipApplicationFacade = partnershipApplicationFacade;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping
|
||||
public String newPartnershipApplicationForm(Model model, HttpServletRequest request) {
|
||||
if (!SecurityUtil.isAuthenticated()) {
|
||||
return "redirect:/login?redirect=/partnership";
|
||||
}
|
||||
|
||||
String referer = request.getHeader("Referer");
|
||||
if(referer != null && !referer.contains("/partnership")) {
|
||||
request.getSession().setAttribute("previousPage", referer);
|
||||
}
|
||||
|
||||
model.addAttribute("partnership", new PartnershipApplicationDTO());
|
||||
return "apps/community/mainPartnershipForm";
|
||||
}
|
||||
|
||||
|
||||
@PostMapping
|
||||
public String createPartnershipApplication(@Valid @ModelAttribute PartnershipApplicationDTO partnershipApplicationDTO,
|
||||
BindingResult bindingResult, HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes) throws IOException {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "apps/community/mainPartnershipForm";
|
||||
}
|
||||
|
||||
partnershipApplicationFacade.createPartnershipApplication(partnershipApplicationDTO);
|
||||
|
||||
// 성공 메시지 추가
|
||||
redirectAttributes.addFlashAttribute("success", "사업제휴신청이 완료되었습니다.");
|
||||
|
||||
httpServletRequest.getSession().removeAttribute("previousPage");
|
||||
return "redirect:/partnership";
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.eactive.apim.portal.apps.community.partnership.dto;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PartnershipApplicationDTO {
|
||||
|
||||
@Size(max = 255, message = "제목은 255자를 초과할 수 없습니다.")
|
||||
private String bizSubject;
|
||||
|
||||
private String bizDetail;
|
||||
|
||||
/**
|
||||
* 첨부파일ID
|
||||
*/
|
||||
private String fileId;
|
||||
|
||||
private List<MultipartFile> files;
|
||||
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.eactive.apim.portal.apps.community.partnership.mapper;
|
||||
|
||||
|
||||
import com.eactive.apim.portal.apps.community.partnership.dto.PartnershipApplicationDTO;
|
||||
import com.eactive.apim.portal.common.mapper.CommonMapper;
|
||||
import com.eactive.apim.portal.partnershipapplication.entity.PartnershipApplication;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Mapper(componentModel = "spring",
|
||||
uses = {CommonMapper.class},
|
||||
unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Component
|
||||
|
||||
public interface PartnershipApplicationMapper {
|
||||
|
||||
PartnershipApplication toEntity(PartnershipApplicationDTO dto);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.eactive.apim.portal.apps.community.partnership.repository;
|
||||
|
||||
import com.eactive.apim.portal.partnershipapplication.entity.PartnershipApplication;
|
||||
import com.eactive.eai.rms.data.EMSDataSource;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@EMSDataSource
|
||||
public interface PartnershipApplicationRepository extends JpaRepository<PartnershipApplication, String>, JpaSpecificationExecutor<PartnershipApplication> {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.eactive.apim.portal.apps.community.partnership.service;
|
||||
|
||||
import com.eactive.apim.portal.apps.community.partnership.dto.PartnershipApplicationDTO;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface PartnershipApplicationFacade {
|
||||
|
||||
void createPartnershipApplication(PartnershipApplicationDTO partnershipApplicationDTO) throws IOException;
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.eactive.apim.portal.apps.community.partnership.service;
|
||||
|
||||
import com.eactive.apim.portal.apps.community.partnership.dto.PartnershipApplicationDTO;
|
||||
import com.eactive.apim.portal.apps.community.partnership.mapper.PartnershipApplicationMapper;
|
||||
import com.eactive.apim.portal.file.entity.FileInfo;
|
||||
import com.eactive.apim.portal.file.service.FileService;
|
||||
import com.eactive.apim.portal.file.service.FileTypeContext;
|
||||
import com.eactive.apim.portal.partnershipapplication.entity.PartnershipApplication;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PartnershipApplicationFacadeImpl implements PartnershipApplicationFacade {
|
||||
|
||||
private final PartnershipApplicationService partnershipApplicationService;
|
||||
private final PartnershipApplicationMapper partnershipApplicationMapper;
|
||||
private final FileService fileService;
|
||||
|
||||
|
||||
@Override
|
||||
public void createPartnershipApplication(PartnershipApplicationDTO partnershipApplicationDTO) throws IOException {
|
||||
|
||||
FileInfo file = null;
|
||||
if (!partnershipApplicationDTO.getFiles().isEmpty()) {
|
||||
FileTypeContext.setFileType("business");
|
||||
file = fileService.createFile(partnershipApplicationDTO.getFiles());
|
||||
}
|
||||
PartnershipApplication partnershipApplication = partnershipApplicationMapper.toEntity(partnershipApplicationDTO);
|
||||
if (file != null) {
|
||||
partnershipApplication.setFileId(file.getFileId());
|
||||
}
|
||||
partnershipApplicationService.createPartnershipApplication(partnershipApplication);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.eactive.apim.portal.apps.community.partnership.service;
|
||||
|
||||
import com.eactive.apim.portal.apps.community.partnership.repository.PartnershipApplicationRepository;
|
||||
import com.eactive.apim.portal.partnershipapplication.entity.PartnershipApplication;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class PartnershipApplicationService {
|
||||
|
||||
private final PartnershipApplicationRepository partnershipApplicationRepository;
|
||||
|
||||
@Autowired
|
||||
public PartnershipApplicationService(PartnershipApplicationRepository partnershipApplicationRepository) {
|
||||
this.partnershipApplicationRepository = partnershipApplicationRepository;
|
||||
}
|
||||
|
||||
public void createPartnershipApplication(PartnershipApplication partnershipApplication) {
|
||||
partnershipApplicationRepository.save(partnershipApplication);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.eactive.apim.portal.apps.community.notice.service.PortalNoticeFacade;
|
||||
import com.eactive.apim.portal.apps.main.service.MainApiFacade;
|
||||
import com.eactive.apim.portal.common.util.SecurityUtil;
|
||||
|
||||
import com.eactive.apim.portal.portalproperty.service.PortalPropertyService;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -25,13 +26,12 @@ public class IndexController {
|
||||
|
||||
private final ApiSearchFacade apiSearchFacade;
|
||||
private final MainApiFacade mainApiFacade;
|
||||
private final PortalNoticeFacade portalNoticeFacade;
|
||||
private final PortalPropertyService portalPropertyService;
|
||||
|
||||
/**
|
||||
* 메인 페이지 API는 Portal Property 에 main.service.list 에 등록된 그룹을 기준으로 API를 조회함.
|
||||
* 프로퍼티에 등록되어 있어도 어드민의 그룹 표시 설정이 N이면 표시 되지 않음.
|
||||
* 어드민의 API 스펙의 표시 설정이 N이면 표시되지 않음.
|
||||
* 그룹 또는 권한이 지정된 경우, 해당사용자의 권한 또는 기관이 일치해야 표시됨.
|
||||
* 어드민의 API 스펙의 표시 설정이 N이면 표시되지 않음. 그룹 또는 권한이 지정된 경우, 해당사용자의 권한 또는 기관이 일치해야 표시됨.
|
||||
* <p>
|
||||
* 검색어는 Portal Property 또는 메인 관리 화면에 main.keyword.list 에 등록된 내용이 표시 됨.
|
||||
*
|
||||
@@ -40,23 +40,8 @@ public class IndexController {
|
||||
*/
|
||||
@GetMapping("/")
|
||||
public String index(Model model) {
|
||||
// Step 1: Fetch and sort API services
|
||||
List<ApiServiceDTO> apiServices = getSortedApiServices(null);
|
||||
|
||||
// Step 2: Create a map of API ID to ApiServiceDTO for icon mapping
|
||||
Map<String, ApiServiceDTO> mainIconsMap = createMainIconsMap(apiServices);
|
||||
|
||||
// Step 3: Merge all API lists from apiServices
|
||||
List<ApiServiceApiDTO> allApis = getAllApis(apiServices);
|
||||
|
||||
// Step 4: Enrich API spec info DTOs with main icon and service info
|
||||
List<ApiSpecInfoDto> apiSpecInfoDtos = enrichApiSpecInfo(apiServices, allApis, mainIconsMap);
|
||||
|
||||
// Step 5: Calculate total API count
|
||||
int totalApiCount = calculateTotalApiCount(apiServices);
|
||||
|
||||
// Step 6: Fetch portal notices and hashtags
|
||||
List<PortalNoticeDTO> portalNotices = portalNoticeFacade.getLatestNotices();
|
||||
List<ApiServiceDTO> services = mainApiFacade.getOpenApiServices();
|
||||
List<String> hashTags = mainApiFacade.getHashTags();
|
||||
|
||||
ApiGroupSearch search = new ApiGroupSearch();
|
||||
@@ -64,107 +49,19 @@ public class IndexController {
|
||||
|
||||
int selectedApiCount = (int) searchResult.get("selectedApiCount");
|
||||
|
||||
// 서비스 이용 수
|
||||
int serviceCount = ((List<?>) searchResult.get("services")).size();
|
||||
|
||||
// 승인된 기업 건수
|
||||
int approvedOrgCount = mainApiFacade.getApprovedOrgCount();
|
||||
|
||||
// Step 7: Add attributes to model
|
||||
addAttributesToModel(model, apiServices, apiSearchFacade.sortApisByService(apiSpecInfoDtos, apiServices), totalApiCount, portalNotices, hashTags, serviceCount, approvedOrgCount, selectedApiCount);
|
||||
addAttributesToModel(model, services, hashTags, serviceCount, approvedOrgCount, selectedApiCount);
|
||||
|
||||
return "apps/main/index";
|
||||
}
|
||||
|
||||
private List<ApiServiceDTO> getSortedApiServices(String apiId) {
|
||||
List<ApiServiceDTO> apiServices = mainApiFacade.getOpenApiServices(apiId);
|
||||
apiServices.sort(Comparator.comparing(ApiServiceDTO::getDisplayOrder));
|
||||
return apiServices;
|
||||
}
|
||||
|
||||
private Map<String, ApiServiceDTO> createMainIconsMap(List<ApiServiceDTO> apiServices) {
|
||||
Map<String, ApiServiceDTO> mainIconsMap = new HashMap<>();
|
||||
apiServices.forEach(service ->
|
||||
service.getApiGroupApiList().forEach(api ->
|
||||
mainIconsMap.put(api.getApiId(), service)
|
||||
)
|
||||
);
|
||||
return mainIconsMap;
|
||||
}
|
||||
|
||||
private List<ApiServiceApiDTO> getAllApis(List<ApiServiceDTO> apiServices) {
|
||||
return apiServices.stream()
|
||||
.flatMap(service -> service.getApiGroupApiList().stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<ApiSpecInfoDto> enrichApiSpecInfo(List<ApiServiceDTO> services, List<ApiServiceApiDTO> allApis, Map<String, ApiServiceDTO> mainIconsMap) {
|
||||
List<String> apiIds = allApis.stream().map(ApiServiceApiDTO::getApiId).collect(Collectors.toList());
|
||||
List<ApiSpecInfoDto> apiSpecInfoDtos = mainApiFacade.getOpenApis(apiIds);
|
||||
apiSpecInfoDtos.forEach(spec -> {
|
||||
ApiServiceDTO serviceDTO = mainIconsMap.get(spec.getApiId());
|
||||
if (serviceDTO != null) {
|
||||
spec.setMainIcon(serviceDTO.getMainIcon());
|
||||
spec.setService(serviceDTO.getGroupName());
|
||||
}
|
||||
});
|
||||
|
||||
boolean isAuthenticated = SecurityUtil.isAuthenticated();
|
||||
String roleCode;
|
||||
String org;
|
||||
|
||||
if (isAuthenticated) {
|
||||
roleCode = SecurityUtil.getPortalAuthenticatedUser().getRoleCode().toString();
|
||||
org = SecurityUtil.getUserOrg().getId();
|
||||
} else {
|
||||
roleCode = null;
|
||||
org = null;
|
||||
}
|
||||
|
||||
List<ApiSpecInfoDto> filteredApiSpecInfoDtos = apiSpecInfoDtos.stream()
|
||||
.filter(spec -> {
|
||||
if (!isAuthenticated) {
|
||||
return spec.getDisplayOrg() == null && spec.getDisplayRoleCode() == null;
|
||||
}
|
||||
boolean orgMatch = false;
|
||||
if (org != null) {
|
||||
orgMatch = spec.getDisplayOrg() == null || spec.getDisplayOrg().isEmpty() || spec.getDisplayOrg().contains(org);
|
||||
}
|
||||
boolean roleMatch = spec.getDisplayRoleCode() == null || spec.getDisplayRoleCode().isEmpty() || spec.getDisplayRoleCode().contains(roleCode);
|
||||
return orgMatch || roleMatch;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Set<String> filteredApiIds = filteredApiSpecInfoDtos.stream()
|
||||
.map(ApiSpecInfoDto::getApiId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
services.forEach(service -> {
|
||||
if (service.getApiGroupApiList() != null) {
|
||||
List<ApiServiceApiDTO> filteredApiList = service.getApiGroupApiList().stream()
|
||||
.filter(api -> filteredApiIds.contains(api.getApiId()))
|
||||
.collect(Collectors.toList());
|
||||
service.setApiGroupApiList(filteredApiList);
|
||||
}
|
||||
});
|
||||
|
||||
return filteredApiSpecInfoDtos.stream().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private int calculateTotalApiCount(List<ApiServiceDTO> apiServices) {
|
||||
return apiServices.stream()
|
||||
.mapToInt(service -> service.getApiGroupApiList().size())
|
||||
.sum();
|
||||
}
|
||||
|
||||
private void addAttributesToModel(Model model, List<ApiServiceDTO> apiServices,
|
||||
List<ApiSpecInfoDto> apiSpecInfoDtos, int totalApiCount,
|
||||
List<PortalNoticeDTO> portalNotices, List<String> hashTags, int serviceCount, int approvedOrgCount, int selectedApiCount) {
|
||||
private void addAttributesToModel(Model model, List<ApiServiceDTO> apiServices, List<String> hashTags, int serviceCount, int approvedOrgCount, int selectedApiCount) {
|
||||
|
||||
model.addAttribute("services", apiServices);
|
||||
model.addAttribute("apis", apiSpecInfoDtos);
|
||||
model.addAttribute("totalApiCount", totalApiCount);
|
||||
model.addAttribute("portalNotices", portalNotices);
|
||||
model.addAttribute("hashtags", hashTags);
|
||||
|
||||
model.addAttribute("serviceCount", serviceCount);
|
||||
@@ -172,15 +69,4 @@ public class IndexController {
|
||||
model.addAttribute("selectedApiCount", selectedApiCount);
|
||||
}
|
||||
|
||||
@GetMapping("/api_fragments")
|
||||
public String getApiFragments(@RequestParam(value = "id", required = false) String id, Model model) {
|
||||
List<ApiServiceDTO> apiServices = getSortedApiServices(id);
|
||||
Map<String, ApiServiceDTO> mainIconsMap = createMainIconsMap(apiServices);
|
||||
List<ApiServiceApiDTO> allApis = getAllApis(apiServices);
|
||||
List<ApiSpecInfoDto> apiSpecInfoDtos = enrichApiSpecInfo(apiServices, allApis, mainIconsMap);
|
||||
model.addAttribute("apis", apiSpecInfoDtos);
|
||||
return "apps/main/apiListFragment :: apiListFragment";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,17 +7,13 @@ import com.eactive.apim.portal.apps.apiservice.dto.ApiServiceDTO;
|
||||
import com.eactive.apim.portal.apps.apiservice.service.ApiServiceService;
|
||||
import com.eactive.apim.portal.apps.user.service.PortalOrgService;
|
||||
import com.eactive.apim.portal.portalproperty.service.PortalPropertyService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Transactional
|
||||
@Service
|
||||
@@ -34,17 +30,13 @@ public class MainApiFacade {
|
||||
return portalOrgService.getActiveApprovedOrgCount();
|
||||
}
|
||||
|
||||
public List<ApiServiceDTO> getOpenApiServices(String serviceId) {
|
||||
public List<ApiServiceDTO> getOpenApiServices() {
|
||||
ApiGroupSearch search = new ApiGroupSearch();
|
||||
|
||||
Map<String, String> property = portalPropertyService.getPortalPropertiesAsMap(PORTAL_PROPERTY);
|
||||
String services = property.getOrDefault("main.service.list", "");
|
||||
|
||||
if (StringUtils.hasText(serviceId) && services.contains(serviceId)) {
|
||||
search.setGroupIds(Collections.singletonList(serviceId));
|
||||
} else {
|
||||
search.setGroupIds(Arrays.asList(services.split(",")));
|
||||
}
|
||||
search.setGroupIds(Arrays.asList(services.replace(" ", "").split(",")));
|
||||
|
||||
return apiServiceService.searchApiGroups(search);
|
||||
}
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
package com.eactive.apim.portal.apps.proxy;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/_proxy") // /proxy 대신 /_proxy 사용
|
||||
@Slf4j
|
||||
public class ApimProxyController {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final ProxyProperties proxyProperties;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final MediaType JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
public ApimProxyController(
|
||||
RestTemplateBuilder restTemplateBuilder,
|
||||
ProxyProperties proxyProperties,
|
||||
ObjectMapper objectMapper) {
|
||||
this.proxyProperties = proxyProperties;
|
||||
this.objectMapper = objectMapper;
|
||||
this.restTemplate = restTemplateBuilder
|
||||
.setConnectTimeout(Duration.ofMillis(proxyProperties.getTimeout().getConnect()))
|
||||
.setReadTimeout(Duration.ofMillis(proxyProperties.getTimeout().getRead()))
|
||||
.build();
|
||||
}
|
||||
|
||||
private ResponseEntity<String> createJsonResponse(HttpStatus status, String message) {
|
||||
ObjectNode jsonResponse = objectMapper.createObjectNode()
|
||||
.put("status", status.value())
|
||||
.put("message", message);
|
||||
return ResponseEntity
|
||||
.status(status)
|
||||
.contentType(JSON_UTF8)
|
||||
.body(jsonResponse.toString());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/**")
|
||||
public ResponseEntity<String> proxyRequest(
|
||||
HttpServletRequest request,
|
||||
@RequestBody(required = false) String body,
|
||||
@RequestHeader HttpHeaders headers) {
|
||||
|
||||
String targetKey = headers.getFirst("target_host");
|
||||
if (targetKey == null || targetKey.trim().isEmpty()) {
|
||||
log.error("Missing or empty target_host header");
|
||||
return createJsonResponse(HttpStatus.BAD_REQUEST, "Error: target_host header is required");
|
||||
}
|
||||
|
||||
String targetUrl = proxyProperties.getTargets().get(targetKey.trim().toLowerCase());
|
||||
if (targetUrl == null) {
|
||||
log.error("Invalid target_host: {}. Available targets: {}",
|
||||
targetKey, proxyProperties.getTargets().keySet());
|
||||
return createJsonResponse(HttpStatus.BAD_REQUEST,
|
||||
"Error: Invalid target_host. Must be one of: " +
|
||||
String.join(", ", proxyProperties.getTargets().keySet()));
|
||||
}
|
||||
|
||||
try {
|
||||
String requestUrl = request.getRequestURI().replace("/_proxy", "");
|
||||
URI uri = UriComponentsBuilder
|
||||
.fromHttpUrl(targetUrl + requestUrl)
|
||||
.query(request.getQueryString())
|
||||
.build()
|
||||
.toUri();
|
||||
|
||||
HttpMethod method = HttpMethod.valueOf(request.getMethod());
|
||||
|
||||
HttpHeaders proxyHeaders = new HttpHeaders();
|
||||
headers.forEach((key, value) -> {
|
||||
if (!key.equalsIgnoreCase("host") &&
|
||||
!key.equalsIgnoreCase("target_host")) {
|
||||
proxyHeaders.addAll(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
HttpEntity<String> httpEntity = new HttpEntity<>(body, proxyHeaders);
|
||||
|
||||
log.debug("Forwarding request to: {} ({})", targetKey, uri);
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
uri,
|
||||
method,
|
||||
httpEntity,
|
||||
String.class
|
||||
);
|
||||
log.debug("Received response status: {}", response.getStatusCode());
|
||||
|
||||
// Create JSON response with the original response data
|
||||
ObjectNode jsonResponse = objectMapper.createObjectNode()
|
||||
.put("status", response.getStatusCode().value());
|
||||
|
||||
// Try to parse the response body as JSON, if it fails, include it as a string
|
||||
try {
|
||||
jsonResponse.set("data", objectMapper.readTree(response.getBody()));
|
||||
} catch (Exception e) {
|
||||
jsonResponse.put("data", response.getBody());
|
||||
}
|
||||
|
||||
return ResponseEntity
|
||||
.status(response.getStatusCode())
|
||||
.contentType(JSON_UTF8)
|
||||
.body(jsonResponse.toString());
|
||||
|
||||
} catch (HttpStatusCodeException e) {
|
||||
log.error("Target server returned error: {} for host: {}", e.getStatusCode(), targetKey);
|
||||
ObjectNode jsonResponse = objectMapper.createObjectNode()
|
||||
.put("status", e.getStatusCode().value());
|
||||
|
||||
// Try to parse the error response body as JSON, if it fails, include it as a string
|
||||
try {
|
||||
jsonResponse.set("data", objectMapper.readTree(e.getResponseBodyAsString()));
|
||||
} catch (Exception ex) {
|
||||
jsonResponse.put("data", e.getResponseBodyAsString());
|
||||
}
|
||||
|
||||
return ResponseEntity
|
||||
.status(e.getStatusCode())
|
||||
.contentType(JSON_UTF8)
|
||||
.body(jsonResponse.toString());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error during proxy request to: {}", targetKey, e);
|
||||
return createJsonResponse(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.eactive.apim.portal.apps.proxy;
|
||||
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "proxy")
|
||||
@Getter
|
||||
@Setter
|
||||
public class ProxyProperties {
|
||||
private Map<String, String> targets;
|
||||
private Timeout timeout = new Timeout();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class Timeout {
|
||||
private int connect = 5000;
|
||||
private int read = 5000;
|
||||
}
|
||||
}
|
||||
@@ -49,9 +49,11 @@ public final class SecurityUtil {
|
||||
|
||||
public static PortalOrgDTO getUserOrg() {
|
||||
PortalOrgDTO portalOrgDTO = new PortalOrgDTO();
|
||||
if (Objects.requireNonNull(getPortalAuthenticatedUser()).getPortalOrg() != null) {
|
||||
portalOrgDTO.setOrgName(getPortalAuthenticatedUser().getPortalOrg().getOrgName());
|
||||
portalOrgDTO.setId(getPortalAuthenticatedUser().getPortalOrg().getId());
|
||||
PortalAuthenticatedUser portalAuthenticatedUser = getPortalAuthenticatedUser();
|
||||
if (Objects.requireNonNull(portalAuthenticatedUser).getPortalOrg() != null) {
|
||||
portalOrgDTO.setOrgName(portalAuthenticatedUser.getPortalOrg().getOrgName());
|
||||
portalOrgDTO.setId(portalAuthenticatedUser.getPortalOrg().getId());
|
||||
portalOrgDTO.setOrgCode(portalAuthenticatedUser.getPortalOrg().getOrgCode());
|
||||
}
|
||||
|
||||
return portalOrgDTO;
|
||||
|
||||
Reference in New Issue
Block a user