Przeglądaj źródła

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

Li Yuan 2 lat temu
rodzic
commit
2c0fd7b1aa

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

@@ -0,0 +1,91 @@
+package com.lc.ibps.components.verification.controller;
+
+import com.lc.ibps.api.base.constants.StateEnum;
+import com.lc.ibps.cloud.entity.APIResult;
+import com.lc.ibps.cloud.provider.GenericProvider;
+import com.lc.ibps.components.verification.model.InspectionItemVO;
+import com.lc.ibps.components.verification.service.PerformanceVerificationService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+@Validated
+@Api(tags = "性能验证接口")
+@RequestMapping(value = "/pv")
+@RestController
+public class PerformanceVerificationController extends GenericProvider{
+
+    protected static final Logger logger = LoggerFactory.getLogger(PerformanceVerificationController.class);
+    @Autowired
+    private PerformanceVerificationService performanceVerificationService;
+
+
+    @PostMapping("/importExcelRecord")
+    @ApiOperation("导入检测数据")
+    public APIResult<Void> importExcelRecord(@RequestParam(value = "name") String name,
+                                             @RequestParam(value = "id") String id,
+                                             @RequestParam(value = "applyFiles") MultipartFile applyFiles
+    ) {
+        APIResult<Void> apiResult = new APIResult<>();
+        InspectionItemVO itemVO = null;
+        try {
+            itemVO = performanceVerificationService.importExcelRecord(name, id, applyFiles);
+            if (itemVO.isDataPass()) {
+                apiResult.setMessage("导入成功");
+                apiResult.setState(StateEnum.SUCCESS.getCode());
+            } else {
+                apiResult.setMessage("数据校验失败");
+                apiResult.setState(StateEnum.ERROR.getCode());
+//            apiResult.setVariables(itemVO.getErrorMessage());
+            }
+        } catch (IOException e) {
+            apiResult.setMessage("导入失败");
+            apiResult.setState(StateEnum.ERROR.getCode());
+        }
+
+
+        return apiResult;
+    }
+
+    @PostMapping("/exportExcelTemplate")
+    @ApiOperation(value = "导出数据模板", notes = "导出数据")
+    public void exportExcelTemplate(@RequestParam(value = "name") String name,
+                                    @RequestParam(value = "id") String id) {
+        ByteArrayOutputStream bos = null;
+        try {
+
+            Workbook workbook = performanceVerificationService.exportExcelTemplateExport(name, id);
+//			String rootRealPath = AppFileUtil.getRealPath("/" + AppFileUtil.TEMP_PATH); // 操作的根目录
+            String fileName = "dataTemplate_" + 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);// 导出
+
+        } catch (Exception e) {
+            logger.error("/pv/exportExcelTemplate", e);
+        } finally {
+            if (bos != null) {
+                try {
+                    bos.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+}

+ 4 - 6
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelExportReportServer.java

@@ -26,10 +26,8 @@ public class PVExcelExportReportServer extends ExcelExportServer {
             row = sheet.createRow(sheet.getLastRowNum() + 1);
             row.setHeight((short) (entity.getHeight() * 50));
             int index = 0;
-            if (item.getConfig().isConvert()) {
-                sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), index,
-                        index + 1));
-            }
+            sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), index,
+                    index + 1));
             entity.setKey("statistic");
             createStringCell(row, index++, func.getText(), getStyles(false, entity), null);
             createStringCell(row, index++, "", getStyles(false, entity), null);
@@ -77,9 +75,9 @@ public class PVExcelExportReportServer extends ExcelExportServer {
             sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), index, i));
         }
         entity.setKey(getCellStyle(func));
-        if(func == FunctionEnum.R) {
+        if (func == FunctionEnum.R) {
             createDoubleCell(row, index++, getCalcValue(func, item.getItemCalcVO()), getStyles(false, entity), null);
-        }else {
+        } else {
             createStringCell(row, index++, getCalcValue(func, item.getItemCalcVO()), getStyles(false, entity), null);
         }
         for (int j = index; j <= i; j++) {

+ 3 - 3
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVTest.java

@@ -23,11 +23,11 @@ public class PVTest {
 
         InspectionConfigVO config = new InspectionConfigVO("批内精密度", 1, 2,
                 new String[]{"高溶度(R1)", "低浓度(R2)"}, 10, LocalDate.now(), true);
-        InspectionItemVO item = new InspectionItemVO(config);
 
         File file = new File(String.format("C:/tmp/%s.xlsx", config.getName()));
         FileInputStream in = new FileInputStream(file);
 
+        InspectionItemVO item = new InspectionItemVO(config);
         item.importExcelRecord(in);
 
         System.out.println(item);
@@ -88,8 +88,8 @@ public class PVTest {
         InspectionConfigVO config4 = new InspectionConfigVO("线性范围", 1, 7,
                 new String[]{"E8", "E7", "E6", "E5", "E4", "E3", "E2"}, 3, LocalDate.now(), true);
 
-        config4.setFunc(new FunctionEnum[]{FunctionEnum.AVERAGE, FunctionEnum.TARGET, FunctionEnum.ABSDEV,FunctionEnum.RELDEV,FunctionEnum.RVALUE, FunctionEnum.LRE, FunctionEnum.R});
-        config4.setTargetValue(new double[]{8.48, 7.48, 6.48, 5.48, 4.48, 3.48, 2.48});
+        config4.setFunc(new FunctionEnum[]{FunctionEnum.AVERAGE,FunctionEnum.TARGET,FunctionEnum.LRE, FunctionEnum.R});
+        config4.setTargetValue(new double[]{8.48, 7.48, 6.48, 5.48, 4.58, 3.58, 2.58});
         InspectionItemVO item4 = new InspectionItemVO(config4);
         File file4 = new File(String.format("C:/tmp/%sdata.xlsx", config4.getName()));
         FileInputStream in4 = new FileInputStream(file4);

+ 16 - 14
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/InspectionItemVO.java

@@ -101,23 +101,25 @@ public class InspectionItemVO {
         entity.add(e1);
         ExcelExportEntity e2 = new ExcelExportEntity(DISPLAY_NUMBER, "number");
         e2.setType(BaseEntityTypeConstants.DoubleType);
-//        e2.setMergeVertical(true);
         entity.add(e2);
 
-        List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
-        ExcelExportEntity e3 = new ExcelExportEntity(DISPLAY_VALUE, "value");
-//            e3.setType(BaseEntityTypeConstants.DoubleType);
-        temp.add(e3);
-        if (config.isConvert()) {
-            ExcelExportEntity e4 = new ExcelExportEntity(DISPLAY_LOG, "log");
-//                e4.setType(BaseEntityTypeConstants.DoubleType);
-            temp.add(e4);
-        }
+
         for (int i = 0; i < config.getSpecimensNum(); i++) {
-            ExcelExportEntity excelEntity = new ExcelExportEntity(config.getSpecimensName()[i], "inspection" + i);
+            List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
 
+
+            ExcelExportEntity e3 = new ExcelExportEntity(config.getSpecimensName()[i], "value");
+            temp.add(e3);
+            ExcelExportEntity excelEntity = new ExcelExportEntity("", "inspection" + i);
             excelEntity.setList(temp);
             entity.add(excelEntity);
+            if (config.isConvert()) {
+                excelEntity.setName(config.getSpecimensName()[i]);
+                e3.setName(DISPLAY_VALUE);
+                ExcelExportEntity e4 = new ExcelExportEntity(DISPLAY_LOG, "log");
+                temp.add(e4);
+            }
+
         }
         map.put("entity", entity);
 
@@ -160,7 +162,7 @@ public class InspectionItemVO {
         List<ExcelSheetRecord> list = PVExcelUtil.importExcel(inputstream, Map.class, params);
         LocalDate startDate = config.getStartDate();
         for (ExcelSheetRecord record : list) {
-            record.convert(config,startDate.toString());
+            record.convert(config, startDate.toString());
             if (record.getErrors().size() > 0) {
                 errorMessage.put(startDate.toString(), record.getErrors());
             }
@@ -186,7 +188,7 @@ public class InspectionItemVO {
     }
 
     private void buildItemCalcVO() {
-        if(config.getTargetValue() == null) return;
+        if (config.getTargetValue() == null) return;
 
         xValue[] specimens = new xValue[config.getSpecimensNum()];
         xValue[] target = new xValue[config.getSpecimensNum()];
@@ -196,7 +198,7 @@ public class InspectionItemVO {
             specimens[i] = record.get(sName).getAverage();
             target[i] = new xValue(config.getTargetValue()[i]);
         }
-        itemCalcVO = new ItemCalcVO(specimens,target);
+        itemCalcVO = new ItemCalcVO(specimens, target);
     }
 
     public Map<String, SpecimensCalcVO> getRecord() {

+ 7 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/ItemCalcVO.java

@@ -46,7 +46,13 @@ public class ItemCalcVO {
 
     public String getLRE() {
         //y = bx + a
-        return String.format("y = %.4fx + %.4f", b.getDoub(), a.getDoub());
+        if(a.getDoub() > 0){
+            return String.format("y = %.4fx + %.4f", b.getDoub(), a.getDoub());
+        }else if(a.getDoub() <0){
+            return String.format("y = %.4fx - %.4f", b.getDoub(), -a.getDoub());
+        }else {
+            return String.format("y = %.4fx", b.getDoub());
+        }
     }
 
     public static void main(String[] args) {

+ 16 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/service/PerformanceVerificationService.java

@@ -0,0 +1,16 @@
+package com.lc.ibps.components.verification.service;
+
+import com.lc.ibps.components.verification.model.InspectionItemVO;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+
+public interface PerformanceVerificationService {
+
+    InspectionItemVO importExcelRecord(String name,
+                                       String id,
+                                       MultipartFile applyFiles) throws IOException;
+
+    Workbook exportExcelTemplateExport(String name, String id);
+}

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

@@ -0,0 +1,38 @@
+package com.lc.ibps.components.verification.service.impl;
+
+import com.lc.ibps.components.verification.model.InspectionConfigVO;
+import com.lc.ibps.components.verification.model.InspectionItemVO;
+import com.lc.ibps.components.verification.service.PerformanceVerificationService;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.time.LocalDate;
+
+@Service
+public class PerformanceVerificationServiceImpl implements PerformanceVerificationService {
+    @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());
+        return item;
+    }
+
+    @Override
+    public Workbook exportExcelTemplateExport(String name, String id) {
+        InspectionConfigVO config = getInspectionConfig(name, id);
+        InspectionItemVO item = new InspectionItemVO(config);
+        Workbook workbook = item.exportExcelTemplate();
+        return workbook;
+    }
+
+    private InspectionConfigVO getInspectionConfig(String name, String id) {
+
+        InspectionConfigVO configVO = new InspectionConfigVO("批内精密度", 1, 2,
+                new String[]{"高溶度(R1)", "低浓度(R2)"}, 10, LocalDate.now(), true);
+        return configVO;
+    }
+}