aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaixiliu <liukaixi@chinamobile.com>2023-10-09 10:09:35 +0800
committerKaixi LIU <liukaixi@chinamobile.com>2023-10-18 09:00:59 +0000
commit0396c0a98cde457edd6eddebf1cc0bee2950a76d (patch)
treef3b64112d48a2335479b7baeb7a90996614ae74b
parent45392ebae1ef9559951b9bf660e8aeb099bba19e (diff)
Add report export function
Issue-ID: USECASEUI-819 Change-Id: Ieb768aec1e12f63f33fa0e29cbb98399e92e5b01 Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/TimeParam.java28
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java12
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportFulfillmentInfoMapper.java6
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportMapper.java4
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java3
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java64
-rw-r--r--intentanalysis/src/main/resources/application.yaml2
-rw-r--r--intentanalysis/src/main/resources/mybatis/sql/IntentReportFulfillmentInfoMapper.xml10
-rw-r--r--intentanalysis/src/main/resources/mybatis/sql/IntentReportMapper.xml10
9 files changed, 137 insertions, 2 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/TimeParam.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/TimeParam.java
new file mode 100644
index 0000000..0291ac0
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/TimeParam.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.usecaseui.intentanalysis.bean.models;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class TimeParam {
+ private String intentId;
+ private String startDate;
+ private String endData;
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java
index d4066b6..54e7fd8 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/controller/IntentReportController.java
@@ -16,12 +16,16 @@
package org.onap.usecaseui.intentanalysis.controller;
import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
import org.onap.usecaseui.intentanalysis.bean.models.*;
import org.onap.usecaseui.intentanalysis.service.IntentReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import java.nio.charset.StandardCharsets;
+
@Log4j2
@RestController
@RequestMapping("/intentReport")
@@ -34,4 +38,12 @@ public class IntentReportController {
@PathVariable("intentId") String intentId) {
return intentReportService.getIntentReportByIntentId(intentId);
}
+
+ @PostMapping(value = "/export")
+ public ResponseEntity<byte[]> exportIntentReportByTime(@RequestBody TimeParam param) {
+ String csvData = intentReportService.exportIntentReportByTime(param);
+ byte[] bytes = StringUtils.isEmpty(csvData) ? new byte[0] : csvData.getBytes(StandardCharsets.UTF_8);
+ return ResponseEntity.ok()
+ .body(bytes);
+ }
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportFulfillmentInfoMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportFulfillmentInfoMapper.java
index 70ab632..fbcd2c0 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportFulfillmentInfoMapper.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportFulfillmentInfoMapper.java
@@ -20,7 +20,11 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
+import java.util.List;
+
@Mapper
public interface IntentReportFulfillmentInfoMapper {
- int insertIntentReportFulfillment(@Param(value = "fulfillmentInfo") FulfillmentInfo fulfillmentInfo,@Param(value = "parentId") String parentId);
+ int insertIntentReportFulfillment(@Param(value = "fulfillmentInfo") FulfillmentInfo fulfillmentInfo, @Param(value = "parentId") String parentId);
+
+ List<FulfillmentInfo> getFulfillmentInfosByParentId(@Param(value = "parentId") String parentId);
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportMapper.java
index 4290a53..e5043f9 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportMapper.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentReportMapper.java
@@ -26,4 +26,8 @@ public interface IntentReportMapper {
int insertIntentReport(@Param(value = "intentReport") IntentReport intentReport);
List<String> getIntentReportIds(@Param(value = "intentReference") String intentReference);
+
+ List<IntentReport> getIntentReportsByTime(@Param(value = "intentInstanceId") String intentInstanceId,
+ @Param(value = "startTime") String startTime,
+ @Param(value = "endTime") String endTime);
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java
index 8180bc2..bf223c3 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/IntentReportService.java
@@ -17,6 +17,7 @@
package org.onap.usecaseui.intentanalysis.service;
import org.onap.usecaseui.intentanalysis.bean.models.ServiceResult;
+import org.onap.usecaseui.intentanalysis.bean.models.TimeParam;
import java.util.List;
@@ -26,4 +27,6 @@ public interface IntentReportService {
void saveIntentReportByIntentId(String intentId);
List<String> getIntentReportIds(String intentReference);
+
+ String exportIntentReportByTime(TimeParam param);
}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java
index d4c0f88..5250ead 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentReportServiceImpl.java
@@ -17,11 +17,13 @@
package org.onap.usecaseui.intentanalysis.service.impl;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
import org.onap.usecaseui.intentanalysis.bean.models.IntentReport;
import org.onap.usecaseui.intentanalysis.bean.models.ResultHeader;
import org.onap.usecaseui.intentanalysis.bean.models.ServiceResult;
import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
+import org.onap.usecaseui.intentanalysis.bean.models.TimeParam;
import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
import org.onap.usecaseui.intentanalysis.mapper.IntentReportFulfillmentInfoMapper;
import org.onap.usecaseui.intentanalysis.mapper.IntentReportMapper;
@@ -37,6 +39,7 @@ import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.List;
+import java.util.StringJoiner;
import java.util.stream.Collectors;
import static org.onap.usecaseui.intentanalysis.common.ResponseConsts.RSEPONSE_SUCCESS;
@@ -110,6 +113,67 @@ public class IntentReportServiceImpl implements IntentReportService {
return intentReportIds;
}
+ @Override
+ public String exportIntentReportByTime(TimeParam param) {
+ if (StringUtils.isEmpty(param.getStartDate()) || StringUtils.isEmpty(param.getEndData())) {
+ log.warn("please enter the correct time");
+ return null;
+ }
+ String intentInstanceId = intentInstanceService.queryIntentInstanceId(param.getIntentId());
+ List<IntentReport> intentReports = getIntentReports(intentInstanceId, param.getStartDate(), param.getEndData());
+ if (CollectionUtils.isEmpty(intentReports)) {
+ log.error("no intent report data");
+ return null;
+ }
+ List<String> objectInstances = objectInstanceMapper.getObjectInstances(param.getIntentId());
+ intentReports.forEach(intentReport -> {
+ String intentReportId = intentReport.getIntentReportId();
+ List<FulfillmentInfo> fulfillmentInfos = intentReportFulfillmentInfoMapper.getFulfillmentInfosByParentId(intentReportId);
+ fulfillmentInfos.forEach(fulfillmentInfo -> fulfillmentInfo.setObjectInstances(objectInstances));
+ intentReport.setFulfillmentInfos(fulfillmentInfos);
+ });
+ return convertToCSV(intentReports);
+ }
+
+ public List<IntentReport> getIntentReports(String intentInstanceId, String startTime, String endTime) {
+ List<IntentReport> intentReportsByTime = intentReportMapper.getIntentReportsByTime(intentInstanceId, startTime, endTime);
+ if (CollectionUtils.isEmpty(intentReportsByTime)) {
+ log.error("no intent report data");
+ }
+ return intentReportsByTime;
+ }
+
+ private String convertToCSV(List<IntentReport> intentReportList) {
+ StringBuilder stringBuilder = new StringBuilder();
+ StringJoiner title = new StringJoiner(",");
+ title.add("intentReportId").add("intentReference")
+ .add("fulfillmentId")
+ .add("fulfillmentStatus")
+ .add("notFulfilledState")
+ .add("notFulfilledReason")
+ .add("achieveValue")
+ .add("objectInstance")
+ .add("reportTime");
+ stringBuilder.append(title).append("\n");
+ intentReportList.forEach(intentReport -> {
+ List<FulfillmentInfo> fulfillmentInfos = intentReport.getFulfillmentInfos();
+ fulfillmentInfos.forEach(fulfillmentInfo -> {
+ StringJoiner data = new StringJoiner(",");
+ data.add(intentReport.getIntentReportId())
+ .add(intentReport.getIntentReference())
+ .add(fulfillmentInfo.getFulfillmentId())
+ .add(fulfillmentInfo.getFulfillmentStatus().getDesc())
+ .add(fulfillmentInfo.getNotFulfilledState().getDesc())
+ .add(fulfillmentInfo.getNotFulfilledReason())
+ .add(fulfillmentInfo.getAchieveValue())
+ .add(fulfillmentInfo.getObjectInstances().toString())
+ .add(intentReport.getReportTime());
+ stringBuilder.append(data).append("\n");
+ });
+ });
+ return stringBuilder.toString();
+ }
+
private FulfillmentInfo getFulfillmentInfo(String intentId) {
FulfillmentInfo fulfillmentInfo = fulfillmentInfoService.getFulfillmentInfo(intentId);
log.info("fulfillmentInfo is {}", fulfillmentInfo);
diff --git a/intentanalysis/src/main/resources/application.yaml b/intentanalysis/src/main/resources/application.yaml
index 6db6b46..fca8205 100644
--- a/intentanalysis/src/main/resources/application.yaml
+++ b/intentanalysis/src/main/resources/application.yaml
@@ -4,7 +4,7 @@ server:
context-path: /api/usecaseui-intent-analysis/v1
spring:
datasource:
- url: jdbc:postgresql://${POSTGRES_IP:127.0.0.1}:${POSTGRES_PORT:5432}/${POSTGRES_DB_NAME:intentdb}
+ url: jdbc:postgresql://${POSTGRES_IP:127.0.0.1}:${POSTGRES_PORT:5432}/${POSTGRES_DB_NAME}
username: ${POSTGRES_USERNAME}
password: ${POSTGRES_PASSWORD}
driver-class-name: org.postgresql.Driver
diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentReportFulfillmentInfoMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentReportFulfillmentInfoMapper.xml
index bfe413e..c090d5a 100644
--- a/intentanalysis/src/main/resources/mybatis/sql/IntentReportFulfillmentInfoMapper.xml
+++ b/intentanalysis/src/main/resources/mybatis/sql/IntentReportFulfillmentInfoMapper.xml
@@ -8,4 +8,14 @@
insert into intent_report_fulfillment_info(parent_id,fulfillment_info_id, fulfillment_info_status, not_fulfilled_state, not_fulfilled_reason,achieve_value)
values (#{parentId},#{fulfillmentInfo.fulfillmentId}, #{fulfillmentInfo.fulfillmentStatus}, #{fulfillmentInfo.notFulfilledState}, #{fulfillmentInfo.notFulfilledReason},#{fulfillmentInfo.achieveValue})
</insert>
+ <select id="getFulfillmentInfosByParentId"
+ resultType="org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo">
+ select fulfillment_info_id fulfillmentId,
+ fulfillment_info_status fulfillmentStatus,
+ not_fulfilled_state notFulfilledState,
+ not_fulfilled_reason notFulfilledReason,
+ achieve_value achieveValue
+ from intent_report_fulfillment_info
+ where parent_id = #{parentId}
+ </select>
</mapper>
diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentReportMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentReportMapper.xml
index 078ea9b..901055e 100644
--- a/intentanalysis/src/main/resources/mybatis/sql/IntentReportMapper.xml
+++ b/intentanalysis/src/main/resources/mybatis/sql/IntentReportMapper.xml
@@ -14,4 +14,14 @@
from intent_report
where intent_reference = #{intentReference}
</select>
+
+ <select id="getIntentReportsByTime" resultType="org.onap.usecaseui.intentanalysis.bean.models.IntentReport">
+ select intent_report_id intentReportId,
+ intent_reference intentReference,
+ to_char(report_time,'yyyy-mm-dd HH24:mi:ss') reportTime
+ from intent_report
+ where report_time &gt;= to_timestamp(#{startTime},'yyyy-MM-dd HH24:mi:ss')
+ and report_time &lt; to_timestamp(#{endTime},'yyyy-MM-dd HH24:mi:ss')
+ and intent_reference = #{intentInstanceId}
+ </select>
</mapper>