|
@@ -0,0 +1,235 @@
|
|
|
|
+package com.simuwang.daq.components;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
+import com.simuwang.base.pojo.dto.report.*;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
|
|
+public class PythonReportConverter {
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ public static <T extends ReportData> PythonResult<T> convert(JSONObject jsonObject, Integer type) {
|
|
|
|
+ PythonResult<T> result = new PythonResult<>();
|
|
|
|
+ if (jsonObject == null) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ result.setMsg(jsonObject.getStr("msg"));
|
|
|
|
+ result.setStatus(jsonObject.getInt("status"));
|
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
+ if (data == null || data.isEmpty()) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ T reportData;
|
|
|
|
+ if (Objects.equals(2, type) || Objects.equals(1, type)) {
|
|
|
|
+ reportData = (T) convertQuarterly(data);
|
|
|
|
+ } else {
|
|
|
|
+ reportData = (T) convertMonthly(data);
|
|
|
|
+ }
|
|
|
|
+ result.setData(reportData);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static MonthlyReportData convertMonthly(JSONObject jsonObject) {
|
|
|
|
+ MonthlyReportData reportData = new MonthlyReportData();
|
|
|
|
+ reportData.setBaseInfo(convertBaseInfo(jsonObject));
|
|
|
|
+ reportData.setFundInfo(convertFundInfo(jsonObject));
|
|
|
|
+ reportData.setNetReport(convertNetReport(jsonObject));
|
|
|
|
+ return reportData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static QuarterlyReportData convertQuarterly(JSONObject jsonObject) {
|
|
|
|
+ QuarterlyReportData reportData = new QuarterlyReportData();
|
|
|
|
+ reportData.setBaseInfo(convertBaseInfo(jsonObject));
|
|
|
|
+ reportData.setFundInfo(convertFundInfo(jsonObject));
|
|
|
|
+ reportData.setAssetAllocation(convertAssetAllocation(jsonObject));
|
|
|
|
+ reportData.setFinancialIndicators(convertFinancialIndicator(jsonObject));
|
|
|
|
+ reportData.setInvestmentIndustry(convertInvestmentIndustry(jsonObject));
|
|
|
|
+ reportData.setShareChange(convertShareChange(jsonObject));
|
|
|
|
+ return reportData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static ReportBaseInfoDTO convertBaseInfo(JSONObject jsonObject) {
|
|
|
|
+ ReportBaseInfoDTO baseInfo = new ReportBaseInfoDTO();
|
|
|
|
+ if (jsonObject == null || !jsonObject.containsKey("base_info")) {
|
|
|
|
+ return baseInfo;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("base_info");
|
|
|
|
+ JSONObject obj = jsonArray.getJSONObject(0);
|
|
|
|
+ if (obj == null || obj.isEmpty()) {
|
|
|
|
+ return baseInfo;
|
|
|
|
+ }
|
|
|
|
+ baseInfo.setFileId(obj.getInt("file_id"));
|
|
|
|
+ baseInfo.setReportName(obj.getStr("report_name"));
|
|
|
|
+ baseInfo.setReportType(obj.getStr("report_type"));
|
|
|
|
+ baseInfo.setReportDate(obj.getStr("report_date"));
|
|
|
|
+ return baseInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static ReportFundInfoDTO convertFundInfo(JSONObject jsonObject) {
|
|
|
|
+ ReportFundInfoDTO dto = new ReportFundInfoDTO();
|
|
|
|
+ if (jsonObject == null || !jsonObject.containsKey("fund_info")) {
|
|
|
|
+ return dto;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("fund_info");
|
|
|
|
+ JSONObject obj = jsonArray.getJSONObject(0);
|
|
|
|
+ if (obj == null || obj.isEmpty()) {
|
|
|
|
+ return dto;
|
|
|
|
+ }
|
|
|
|
+ dto.setFileId(obj.getInt("file_id"));
|
|
|
|
+ dto.setAdvisorName(obj.getStr("advisor_name"));
|
|
|
|
+ dto.setCustodianName(obj.getStr("custodian_name"));
|
|
|
|
+ dto.setFundManager(obj.getStr("fund_manager"));
|
|
|
|
+ dto.setFundName(obj.getStr("fund_name"));
|
|
|
|
+ dto.setFundStrategyDescription(obj.getStr("fund_strategy_description"));
|
|
|
|
+ dto.setInceptionDate(obj.getStr("inception_date"));
|
|
|
|
+ dto.setIndustryTrend(obj.getStr("industry_trend"));
|
|
|
|
+ dto.setInvestmentObjective(obj.getStr("investment_objective"));
|
|
|
|
+ dto.setLeverage(obj.getBigDecimal("leverage"));
|
|
|
|
+ dto.setLeverageNote(obj.getStr("leverage_note"));
|
|
|
|
+ dto.setOperationType(obj.getStr("operation_type"));
|
|
|
|
+ dto.setRegisterNumber(obj.getStr("register_number"));
|
|
|
|
+ dto.setRiskReturnDesc(obj.getStr("risk_return_desc"));
|
|
|
|
+ dto.setSecondaryBenchmark(obj.getStr("secondary_benchmark"));
|
|
|
|
+ dto.setTrustName(obj.getStr("trust_name"));
|
|
|
|
+ dto.setDueDate(obj.getStr("due_date"));
|
|
|
|
+ dto.setIsReviewed(obj.getStr("is_reviewed"));
|
|
|
|
+ return dto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static List<ReportNetReportDTO> convertNetReport(JSONObject jsonObject) {
|
|
|
|
+ List<ReportNetReportDTO> dtos = ListUtil.list(false);
|
|
|
|
+ if (jsonObject == null || !jsonObject.containsKey("new_report")) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("new_report");
|
|
|
|
+ if (CollUtil.isEmpty(jsonArray)) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ for (Object o : jsonArray) {
|
|
|
|
+ JSONObject obj = JSONUtil.parseObj(o);
|
|
|
|
+ ReportNetReportDTO dto = new ReportNetReportDTO();
|
|
|
|
+ if (obj == null || obj.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ dto.setFileId(obj.getInt("file_id"));
|
|
|
|
+ dto.setValuationDate(obj.getStr("valuation_date"));
|
|
|
|
+ dto.setFundAssetSize(obj.getBigDecimal("fund_asset_size"));
|
|
|
|
+ dto.setEndTotalShares(obj.getBigDecimal("end_total_shares"));
|
|
|
|
+ dto.setCumulativeNav(obj.getBigDecimal("cumulative_nav"));
|
|
|
|
+ dto.setNav(obj.getBigDecimal("nav"));
|
|
|
|
+ dtos.add(dto);
|
|
|
|
+ }
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static List<ReportShareChangeDTO> convertShareChange(JSONObject jsonObject) {
|
|
|
|
+ List<ReportShareChangeDTO> dtos = ListUtil.list(false);
|
|
|
|
+ if (jsonObject == null || !jsonObject.containsKey("share_change")) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("share_change");
|
|
|
|
+ if (CollUtil.isEmpty(jsonArray)) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ for (Object o : jsonArray) {
|
|
|
|
+ JSONObject obj = JSONUtil.parseObj(o);
|
|
|
|
+ ReportShareChangeDTO dto = new ReportShareChangeDTO();
|
|
|
|
+ if (obj == null || obj.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ dto.setFileId(obj.getInt("file_id"));
|
|
|
|
+ dto.setLevel(obj.getStr("level"));
|
|
|
|
+ dto.setInitTotalShares(obj.getBigDecimal("init_total_shares"));
|
|
|
|
+ dto.setRedemption(obj.getBigDecimal("redemption"));
|
|
|
|
+ dto.setSharePerAsset(obj.getBigDecimal("share_per_asset"));
|
|
|
|
+ dto.setSubscription(obj.getBigDecimal("subscription"));
|
|
|
|
+ dto.setSplit(obj.getBigDecimal("split"));
|
|
|
|
+ dtos.add(dto);
|
|
|
|
+ }
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static List<ReportAssetAllocationDTO> convertAssetAllocation(JSONObject jsonObject) {
|
|
|
|
+ List<ReportAssetAllocationDTO> dtos = ListUtil.list(false);
|
|
|
|
+ if (jsonObject == null || !jsonObject.containsKey("asset_allocation")) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("asset_allocation");
|
|
|
|
+ if (CollUtil.isEmpty(jsonArray)) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ for (Object o : jsonArray) {
|
|
|
|
+ JSONObject obj = JSONUtil.parseObj(o);
|
|
|
|
+ ReportAssetAllocationDTO dto = new ReportAssetAllocationDTO();
|
|
|
|
+ if (obj == null || obj.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ dto.setFileId(obj.getInt("file_id"));
|
|
|
|
+ dto.setAssetType(obj.getStr("asset_type"));
|
|
|
|
+ dto.setColumnName(obj.getStr("column_name"));
|
|
|
|
+ dto.setMarketValue(obj.getBigDecimal("market_value"));
|
|
|
|
+ dto.setRemark(obj.getStr("remark"));
|
|
|
|
+ dtos.add(dto);
|
|
|
|
+ }
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static List<ReportFinancialIndicatorDTO> convertFinancialIndicator(JSONObject jsonObject) {
|
|
|
|
+ List<ReportFinancialIndicatorDTO> dtos = ListUtil.list(false);
|
|
|
|
+ if (jsonObject == null || !jsonObject.containsKey("financial_indicator")) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("financial_indicator");
|
|
|
|
+ if (CollUtil.isEmpty(jsonArray)) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ for (Object o : jsonArray) {
|
|
|
|
+ JSONObject obj = JSONUtil.parseObj(o);
|
|
|
|
+ ReportFinancialIndicatorDTO dto = new ReportFinancialIndicatorDTO();
|
|
|
|
+ if (obj == null || obj.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ dto.setFileId(obj.getInt("file_id"));
|
|
|
|
+ dto.setLevel(obj.getStr("level"));
|
|
|
|
+ dto.setEndDate(obj.getInt("end_date"));
|
|
|
|
+ dto.setFundAssetSize(obj.getBigDecimal("fund_asset_aize"));
|
|
|
|
+ dto.setNav(obj.getBigDecimal("nav"));
|
|
|
|
+ dto.setProfit(obj.getBigDecimal("profit"));
|
|
|
|
+ dto.setRealizedIncome(obj.getBigDecimal("realized_income"));
|
|
|
|
+ dtos.add(dto);
|
|
|
|
+ }
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static List<ReportInvestmentIndustryDTO> convertInvestmentIndustry(JSONObject jsonObject) {
|
|
|
|
+ List<ReportInvestmentIndustryDTO> dtos = ListUtil.list(false);
|
|
|
|
+ if (jsonObject == null || !jsonObject.containsKey("investment_industry")) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("investment_industry");
|
|
|
|
+ if (CollUtil.isEmpty(jsonArray)) {
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+ for (Object o : jsonArray) {
|
|
|
|
+ JSONObject obj = JSONUtil.parseObj(o);
|
|
|
|
+ ReportInvestmentIndustryDTO dto = new ReportInvestmentIndustryDTO();
|
|
|
|
+ if (obj == null || obj.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ dto.setFileId(obj.getInt("file_id"));
|
|
|
|
+ dto.setIndustryCode(obj.getStr("industry_code"));
|
|
|
|
+ dto.setIndustryName(obj.getStr("industry_name"));
|
|
|
|
+ dto.setInvestType(obj.getInt("invest_type"));
|
|
|
|
+ dto.setIsbCode(obj.getStr("isb_code"));
|
|
|
|
+ dto.setMarketValue(obj.getBigDecimal("market_value"));
|
|
|
|
+ dto.setRatio(obj.getBigDecimal("ratio"));
|
|
|
|
+ dtos.add(dto);
|
|
|
|
+ }
|
|
|
|
+ return dtos;
|
|
|
|
+ }
|
|
|
|
+}
|