Przeglądaj źródła

[性能验证][task-1447] 后端接口实现

Li Yuan 2 lat temu
rodzic
commit
c6d38498d4

+ 15 - 5
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/controller/PerformanceVerificationController.java

@@ -60,9 +60,10 @@ public class PerformanceVerificationController extends GenericProvider{
 
     @PostMapping("/exportExcelTemplate")
     @ApiOperation(value = "导出数据模板", notes = "导出数据模板")
-    public void exportExcelTemplate(@RequestParam(value = "name") String name,
+    public  APIResult<Void> exportExcelTemplate(@RequestParam(value = "name") String name,
                                     @RequestParam(value = "id") String id) {
         ByteArrayOutputStream bos = null;
+        APIResult<Void> apiResult = new APIResult<>();
         try {
 
             Workbook workbook = performanceVerificationService.exportExcelTemplateExport(name, id);
@@ -73,9 +74,12 @@ public class PerformanceVerificationController extends GenericProvider{
             workbook.write(bos);
             byte[] barray = bos.toByteArray();
             com.lc.ibps.base.web.util.RequestUtil.downLoadFileByByte(this.getRequest(), this.getResponse(), barray, fileName);// 导出
-
+            apiResult.setMessage("导出成功");
+            apiResult.setState(StateEnum.SUCCESS.getCode());
         } catch (Exception e) {
             logger.error("/pv/exportExcelTemplate", e);
+            apiResult.setMessage("导出失败");
+            apiResult.setState(StateEnum.ERROR.getCode());
         } finally {
             if (bos != null) {
                 try {
@@ -85,25 +89,30 @@ public class PerformanceVerificationController extends GenericProvider{
                 }
             }
         }
+        return apiResult;
     }
     @PostMapping("/exportExcelReport")
     @ApiOperation(value = "导出数据报告", notes = "导出数据报告")
-    public void exportExcelReport(@RequestParam(value = "name") String name,
+    public  APIResult<Void> exportExcelReport(@RequestParam(value = "name") String name,
                                @RequestParam(value = "id") String id) {
         ByteArrayOutputStream bos = null;
+        APIResult<Void> apiResult = new APIResult<>();
         try {
 
             Workbook workbook = performanceVerificationService.exportExcelReport(name, id);
 //			String rootRealPath = AppFileUtil.getRealPath("/" + AppFileUtil.TEMP_PATH); // 操作的根目录
-            String fileName = "dataTemplate_" + name + (workbook instanceof HSSFWorkbook ? ".xls" : ".xlsx");
+            String fileName = "dataReport_" + name + (workbook instanceof HSSFWorkbook ? ".xls" : ".xlsx");
 //			FileUtil.writeFile(rootRealPath + File.separator + fileName + (workbook instanceof HSSFWorkbook ? ".xls" : ".xlsx"), workbook);
             bos = new ByteArrayOutputStream();
             workbook.write(bos);
             byte[] barray = bos.toByteArray();
             com.lc.ibps.base.web.util.RequestUtil.downLoadFileByByte(this.getRequest(), this.getResponse(), barray, fileName);// 导出
-
+            apiResult.setMessage("导出成功");
+            apiResult.setState(StateEnum.SUCCESS.getCode());
         } catch (Exception e) {
             logger.error("/pv/exportExcelReport", e);
+            apiResult.setMessage("导出失败");
+            apiResult.setState(StateEnum.ERROR.getCode());
         } finally {
             if (bos != null) {
                 try {
@@ -113,5 +122,6 @@ public class PerformanceVerificationController extends GenericProvider{
                 }
             }
         }
+        return apiResult;
     }
 }

+ 11 - 5
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/service/impl/PerformanceVerificationServiceImpl.java

@@ -11,15 +11,21 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.time.LocalDate;
+import java.util.HashMap;
+import java.util.Map;
 
 @Service
 public class PerformanceVerificationServiceImpl implements PerformanceVerificationService {
+
+    //todo:
+    private Map<String,InspectionItemVO> data = new HashMap<>();
     @Override
     public InspectionItemVO importExcelRecord(String name, String id, MultipartFile applyFiles) throws IOException {
 
         InspectionConfigVO config = getInspectionConfig(name, id);
         InspectionItemVO item = new InspectionItemVO(config);
         item.importExcelRecord(applyFiles.getInputStream());
+        data.put(id+name,item);
         return item;
     }
 
@@ -33,9 +39,9 @@ public class PerformanceVerificationServiceImpl implements PerformanceVerificati
 
     @Override
     public Workbook exportExcelReport(String name, String id) {
-        InspectionConfigVO config = getInspectionConfig(name, id);
         InspectionVO inspectionVO = new InspectionVO();
-        InspectionItemVO item = new InspectionItemVO(config);
+        InspectionItemVO item = data.get(id+name);
+        if(item == null) throw new RuntimeException("can't find this config");
         inspectionVO.getItem().add(item);
         Workbook workbook = inspectionVO.exportExcelReport(StringUtils.isNotBlank(name));
         return workbook;
@@ -43,8 +49,8 @@ public class PerformanceVerificationServiceImpl implements PerformanceVerificati
 
     private InspectionConfigVO getInspectionConfig(String name, String id) {
 
-        InspectionConfigVO configVO = new InspectionConfigVO("批内精密度", 1, 2,
-                new String[]{"高溶度(R1)", "低浓度(R2)"}, 10, LocalDate.now(), true);
-        return configVO;
+        InspectionConfigVO config = new InspectionConfigVO("线性范围", 1, 7,
+                new String[]{"E8", "E7", "E6", "E5", "E4", "E3", "E2"}, 3, LocalDate.now(), true);
+        return config;
     }
 }