Просмотр исходного кода

[性能验证]添加Excel文件下载

liyuan 2 лет назад
Родитель
Сommit
a7ada97860
18 измененных файлов с 776 добавлено и 20 удалено
  1. 2 1
      ibps-component-root/modules/comp-poi/src/main/java/com/lc/ibps/components/poi/excel/export/ExcelExportServer.java
  2. 2 2
      ibps-component-root/modules/comp-poi/src/main/java/com/lc/ibps/components/poi/excel/imports/ExcelImportServer.java
  3. 49 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelExportServer.java
  4. 35 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelExportStyler.java
  5. 53 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelImportServer.java
  6. 168 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelUtil.java
  7. 97 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVTest.java
  8. 67 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/ExcelRecordVO.java
  9. 67 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/InspectionConfigVO.java
  10. 78 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/InspectionItemVO.java
  11. 9 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/InspectionVO.java
  12. 60 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/RecordCalcVO.java
  13. 25 10
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/TestFuncs.java
  14. 29 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xAverage.java
  15. 3 5
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xFuncArray2Args.java
  16. 2 2
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xFuncStdevVar.java
  17. 20 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xLog10.java
  18. 10 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xValue.java

+ 2 - 1
ibps-component-root/modules/comp-poi/src/main/java/com/lc/ibps/components/poi/excel/export/ExcelExportServer.java

@@ -212,7 +212,7 @@ public class ExcelExportServer extends ExcelExportBase {
      * @param title
      * @param index
      */
-    private int createTitleRow(ExportParams title, Sheet sheet, Workbook workbook, int index,
+    protected int createTitleRow(ExportParams title, Sheet sheet, Workbook workbook, int index,
                                List<ExcelExportEntity> excelParams) {
         Row row = sheet.createRow(index);
         int rows = getRowNums(excelParams);
@@ -234,6 +234,7 @@ public class ExcelExportServer extends ExcelExportBase {
                 if (StringUtils.isNotBlank(entity.getName())) {
                     sheet.addMergedRegion(new CellRangeAddress(index, index, cellIndex,
                         cellIndex + sTitel.size() - 1));
+                    createStringCell(row, cellIndex + sTitel.size() - 1, "", titleStyle, entity);
                 }
                 for (int j = 0, size = sTitel.size(); j < size; j++) {
                     createStringCell(rows == 2 ? listRow : row, cellIndex, sTitel.get(j).getName(),

+ 2 - 2
ibps-component-root/modules/comp-poi/src/main/java/com/lc/ibps/components/poi/excel/imports/ExcelImportServer.java

@@ -120,7 +120,7 @@ public class ExcelImportServer extends ImportBaseService {
 	 * @param cell
 	 * @return
 	 */
-	private String getKeyValue(Cell cell) {
+	protected String getKeyValue(Cell cell) {
 		Object obj = PoiCellUtil.getCellValue(cell);
 		return obj == null ? null : obj.toString().trim();
 	}
@@ -301,7 +301,7 @@ public class ExcelImportServer extends ImportBaseService {
 	 * @param excelCollection
 	 * @return
 	 */
-	private Map<Integer, String> getTitleMap(Iterator<Row> rows, ImportParams params,
+	protected Map<Integer, String> getTitleMap(Iterator<Row> rows, ImportParams params,
 			List<ExcelCollectionParams> excelCollection) {
 		Map<Integer, String> titlemap = new HashMap<Integer, String>();
 		Iterator<Cell> cellTitle;

+ 49 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelExportServer.java

@@ -0,0 +1,49 @@
+package com.lc.ibps.components.verification.excel;
+
+import com.lc.ibps.components.poi.excel.entity.ExportParams;
+import com.lc.ibps.components.poi.excel.entity.params.ExcelExportEntity;
+import com.lc.ibps.components.poi.excel.export.ExcelExportServer;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+
+import java.util.List;
+
+public class PVExcelExportServer extends ExcelExportServer {
+    protected int createHeaderAndTitle(ExportParams entity, Sheet sheet, Workbook workbook,
+                                       List<ExcelExportEntity> excelParams) {
+        int rows = 0, feildWidth = getFieldLength(excelParams);
+        if (entity.getTitle() != null) {
+            rows += createHeaderRow(entity, sheet, workbook, feildWidth);
+        }
+        rows += createInspectionDateRow(entity, sheet, rows,workbook, feildWidth);
+        rows += createTitleRow(entity, sheet, workbook, rows, excelParams);
+        sheet.createFreezePane(0, rows, 0, rows);
+        return rows;
+    }
+
+    private int createInspectionDateRow(ExportParams title, Sheet sheet,int index, Workbook workbook,int feildWidth) {
+
+        Row row = sheet.createRow(index);
+        row.setHeight((short) 450);
+        CellStyle titleStyle = getExcelExportStyler().getTitleStyle(title.getColor());
+        createStringCell(row, 0, "实验日期", titleStyle, null);
+        createStringCell(row, 1, title.getSheetName(), titleStyle, null);
+        createStringCell(row, feildWidth, "", titleStyle, null);
+        CellRangeAddress region = new CellRangeAddress(index, index, 1, feildWidth);
+
+        sheet.addMergedRegion(region);
+
+        return 1;
+    }
+
+
+
+}

+ 35 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelExportStyler.java

@@ -0,0 +1,35 @@
+package com.lc.ibps.components.verification.excel;
+
+import com.lc.ibps.components.poi.excel.entity.params.ExcelExportEntity;
+import com.lc.ibps.components.poi.excel.export.styler.ExcelExportStylerBorderImpl;
+import org.apache.poi.ss.usermodel.*;
+
+public class PVExcelExportStyler extends ExcelExportStylerBorderImpl {
+
+    protected CellStyle          keyNumberStyle;
+    private short i =8;
+    public PVExcelExportStyler(Workbook workbook) {
+        super(workbook);
+        keyNumberStyle = keyNumberStyle(workbook);
+    }
+    public CellStyle getStyles(boolean noneStyler, ExcelExportEntity entity) {
+        if(entity != null && "value".equals(entity.getKey())) {
+            return keyNumberStyle;
+        }
+        return super.getStyles(noneStyler, entity);
+    }
+
+    public CellStyle keyNumberStyle(Workbook workbook) {
+        CellStyle style = workbook.createCellStyle();
+        style.setBorderLeft(BorderStyle.THIN); // 左边框
+        style.setBorderRight(BorderStyle.THIN); // 右边框
+        style.setBorderBottom(BorderStyle.THIN);
+        style.setBorderTop(BorderStyle.THIN);
+        style.setAlignment(HorizontalAlignment.CENTER);
+        style.setVerticalAlignment(VerticalAlignment.CENTER);
+        style.setDataFormat(STRING_FORMAT);
+        style.setFillForegroundColor(IndexedColors.LEMON_CHIFFON.getIndex());
+        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        return style;
+    }
+}

+ 53 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelImportServer.java

@@ -0,0 +1,53 @@
+package com.lc.ibps.components.verification.excel;
+
+import com.lc.ibps.components.poi.excel.entity.ImportParams;
+import com.lc.ibps.components.poi.excel.entity.params.ExcelCollectionParams;
+import com.lc.ibps.components.poi.excel.imports.ExcelImportServer;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class PVExcelImportServer extends ExcelImportServer {
+
+    protected Map<Integer, String> getTitleMap(Iterator<Row> rows, ImportParams params,
+                                               List<ExcelCollectionParams> excelCollection) {
+        Map<Integer, String> titlemap = new HashMap<Integer, String>();
+        Iterator<Cell> cellTitle;
+        String collectionName = null;
+        ExcelCollectionParams collectionParams = null;
+        Row row = null;
+        for (int j = 0; j < params.getHeadRows(); j++) {
+            row = rows.next();
+            if (row == null) {
+                continue;
+            }
+            cellTitle = row.cellIterator();
+            while (cellTitle.hasNext()) {
+                Cell cell = cellTitle.next();
+                String value = getKeyValue(cell);
+                value = value.replace("\n", "");
+                int i = cell.getColumnIndex();
+                // 用以支持重名导入
+                if (StringUtils.isNotEmpty(value)) {
+                    if (titlemap.containsKey(i)) {
+                        collectionName = titlemap.get(i);
+                        titlemap.put(i, collectionName + "_" + value);
+                    } else if (StringUtils.isNotEmpty(collectionName) ) {
+                        titlemap.put(i, collectionName + "_" + value);
+                    } else {
+                        collectionName = null;
+                    }
+                    if (StringUtils.isEmpty(collectionName)) {
+                        titlemap.put(i, value);
+                    }
+                }
+            }
+        }
+        return titlemap;
+    }
+}

+ 168 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelUtil.java

@@ -0,0 +1,168 @@
+package com.lc.ibps.components.verification.excel;
+
+import com.lc.ibps.components.poi.excel.entity.ExportParams;
+import com.lc.ibps.components.poi.excel.entity.ImportParams;
+import com.lc.ibps.components.poi.excel.entity.enmus.ExcelType;
+import com.lc.ibps.components.poi.excel.entity.params.ExcelExportEntity;
+import com.lc.ibps.components.poi.excel.entity.result.ExcelImportResult;
+import com.lc.ibps.components.poi.excel.export.ExcelExportServer;
+import com.lc.ibps.components.poi.excel.imports.ExcelImportServer;
+import com.lc.ibps.components.poi.exception.excel.ExcelImportException;
+import com.lc.ibps.components.poi.util.PoiCellUtil;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public class PVExcelUtil {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PVExcelUtil.class);
+    /**
+     * 根据Map创建对应的Excel
+     * @param entity
+     *            表格标题属性
+     * @param entityList
+     *            Map对象列表
+     * @param dataSet
+     *            Excel对象数据List
+     */
+    public static Workbook exportExcel(ExportParams entity, List<ExcelExportEntity> entityList,
+                                       Collection<? extends Map<?, ?>> dataSet) {
+        Workbook workbook;
+        if (ExcelType.HSSF.equals(entity.getType())) {
+            workbook = new HSSFWorkbook();
+        } else if (dataSet.size() < 10000) {
+            workbook = new XSSFWorkbook();
+        } else {
+            workbook = new SXSSFWorkbook();
+        }
+        new PVExcelExportServer().createSheetForMap(workbook, entity, entityList, dataSet);
+        return workbook;
+    }
+
+    /**
+     * 一个excel 创建多个sheet
+     *
+     * @param list
+     *            多个Map key title 对应表格Title key entity 对应表格对应实体 key data
+     *            Collection 数据
+     * @return
+     */
+    public static Workbook exportExcel(List<ExportParams> entities, List<ExcelExportEntity> entityList,
+                                       Collection<? extends Map<?, ?>> dataSet) {
+        Workbook workbook;
+        if (ExcelType.HSSF.equals(entities.get(0).getType())) {
+            workbook = new HSSFWorkbook();
+        } else if (dataSet.size() < 10000) {
+            workbook = new XSSFWorkbook();
+        } else {
+            workbook = new SXSSFWorkbook();
+        }
+        for (ExportParams entity:entities) {
+            new PVExcelExportServer().createSheetForMap(workbook, entity, entityList, new ArrayList<>(dataSet));
+        }
+
+        return workbook;
+    }
+
+
+    /**
+     * Excel 导入 数据源本地文件,不返回校验结果 导入 字 段类型 Integer,Long,Double,Date,String,Boolean
+     *
+     * @param file
+     * @param pojoClass
+     * @param params
+     * @return
+     */
+    public static <T> List<T> importExcel(File file, Class<?> pojoClass, ImportParams params) {
+        FileInputStream in = null;
+        try {
+            in = new FileInputStream(file);
+            ExcelImportResult result = new PVExcelImportServer().importExcelByIs(in, pojoClass, params);
+            Sheet sheet = result.getWorkbook().getSheetAt(0);
+            String cellValue = getCellValueByCell(sheet, 1, 1);
+            System.out.println(cellValue);
+            return result.getList();
+        } catch (ExcelImportException e) {
+            throw new ExcelImportException(e.getType(), e);
+        } catch (Exception e) {
+            LOGGER.error(e.getMessage(), e);
+            throw new ExcelImportException(e.getMessage(), e);
+        } finally {
+            IOUtils.closeQuietly(in);
+        }
+    }
+    public static String getCellValueByCell(Sheet sheet, int row, int column) {
+        Row rowData = sheet.getRow(row);
+        Cell cell = rowData.getCell(column);
+        //判断是否为null或空串
+        if (cell==null || cell.toString().trim().equals("")) {
+            return "";
+        }
+        String cellValue = "";
+        int cellType=cell.getCellType();
+        switch (cellType) {
+            case Cell.CELL_TYPE_NUMERIC: // 数字
+                short format = cell.getCellStyle().getDataFormat();
+                if (DateUtil.isCellDateFormatted(cell)) {
+                    SimpleDateFormat sdf = null;
+                    //System.out.println("cell.getCellStyle().getDataFormat()="+cell.getCellStyle().getDataFormat());
+                    if (format == 20 || format == 32) {
+                        sdf = new SimpleDateFormat("HH:mm");
+                    } else if (format == 14 || format == 31 || format == 57 || format == 58) {
+                        // 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
+                        sdf = new SimpleDateFormat("yyyy-MM-dd");
+                        double value = cell.getNumericCellValue();
+                        Date date = org.apache.poi.ss.usermodel.DateUtil
+                                .getJavaDate(value);
+                        cellValue = sdf.format(date);
+                    }else {// 日期
+                        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    }
+                    try {
+                        cellValue = sdf.format(cell.getDateCellValue());// 日期
+                    } catch (Exception e) {
+                        try {
+                            throw new Exception("exception on get date data !".concat(e.toString()));
+                        } catch (Exception e1) {
+                            e1.printStackTrace();
+                        }
+                    }finally{
+                        sdf = null;
+                    }
+                }  else {
+                    BigDecimal bd = new BigDecimal(cell.getNumericCellValue());
+                    cellValue = bd.toPlainString();// 数值 这种用BigDecimal包装再获取plainString,可以防止获取到科学计数值
+                }
+                break;
+            case Cell.CELL_TYPE_STRING: // 字符串
+                cellValue = cell.getStringCellValue();
+                break;
+            case Cell.CELL_TYPE_BOOLEAN: // Boolean
+                cellValue = cell.getBooleanCellValue()+"";;
+                break;
+            case Cell.CELL_TYPE_FORMULA: // 公式
+                cellValue = cell.getCellFormula();
+                break;
+            case Cell.CELL_TYPE_BLANK: // 空值
+                cellValue = "";
+                break;
+            case Cell.CELL_TYPE_ERROR: // 故障
+                cellValue = "ERROR VALUE";
+                break;
+            default:
+                cellValue = "UNKNOW VALUE";
+                break;
+        }
+        return cellValue;
+    }
+}

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

@@ -0,0 +1,97 @@
+package com.lc.ibps.components.verification.excel;
+
+import com.lc.ibps.components.poi.excel.ExcelImportUtil;
+import com.lc.ibps.components.poi.excel.entity.ExportParams;
+import com.lc.ibps.components.poi.excel.entity.ImportParams;
+import com.lc.ibps.components.poi.excel.entity.params.ExcelExportEntity;
+import com.lc.ibps.components.poi.excel.entity.vo.BaseEntityTypeConstants;
+import com.lc.ibps.components.poi.util.PoiPublicUtil;
+import com.lc.ibps.components.verification.excel.model.InspectionConfigVO;
+import com.lc.ibps.components.verification.excel.model.InspectionItemVO;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.util.*;
+
+public class PVTest {
+    @Test
+    public  void testExport(){
+        {
+            try {
+                List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
+                ExcelExportEntity excelentity = new ExcelExportEntity("高溶度(R1)", "inspection");
+
+                ExcelExportEntity excelentity1 = new ExcelExportEntity("低溶度(R2)", "inspection");
+                ExcelExportEntity excelentity2 = new ExcelExportEntity("中溶度(R3)", "inspection");
+
+                List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
+                ExcelExportEntity excelExportEntity = new ExcelExportEntity("样本编号", "number");
+                excelExportEntity.setType(BaseEntityTypeConstants.DoubleType);
+                temp.add(excelExportEntity);
+                ExcelExportEntity excelExportEntity1 = new ExcelExportEntity("检测浓度值", "value");
+                temp.add(excelExportEntity1);
+                excelentity.setList(temp);
+                excelentity1.setList(temp);
+                excelentity2.setList(temp);
+                entity.add(excelentity);
+                entity.add(excelentity1);
+                entity.add(excelentity2);
+                List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+                Map<String, Object> map;
+                for (int i = 1; i <= 10; i++) {
+                    map = new HashMap<String, Object>();
+                    map.put("number", i);
+                    map.put("value", "");
+
+                    List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
+                    tempList.add(map);
+                    map.put("inspection", tempList);
+
+                    list.add(map);
+                }
+                ExportParams exportParams = new ExportParams("XXX性能验证数据导入模板", "性能验证数据导入模板");
+                exportParams.setStyle(PVExcelExportStyler.class);
+                Workbook workbook = PVExcelUtil.exportExcel(exportParams, entity,
+                        list);
+                FileOutputStream fos = new FileOutputStream("D:/excel/Excel1.xls");
+                workbook.write(fos);
+                fos.close();
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @Test
+    public void mapTest() {
+
+        ImportParams params = new ImportParams();
+        params.setTitleRows(2);
+        params.setHeadRows(2);
+        long start = new Date().getTime();
+        List<Map<String, Object>> list = PVExcelUtil.importExcel(
+                new File(PoiPublicUtil.getWebRootPath("check.xls")), Map.class, params);
+        System.out.println(list.size());
+        for(Map<String, Object> d : list)
+            System.out.println(d);
+
+    }
+
+    @Test
+    public void test1() throws IOException {
+        InspectionConfigVO config = new InspectionConfigVO(5,2,
+                new String[]{"高溶度(R1)","低浓度(R2)"},10, LocalDate.now());
+        InspectionItemVO item = new InspectionItemVO(config);
+        Workbook workbook = item.exportExcel();
+        FileOutputStream fos = new FileOutputStream("D:/excel/Excel1.xlsx");
+        workbook.write(fos);
+        fos.close();
+    }
+}

+ 67 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/ExcelRecordVO.java

@@ -0,0 +1,67 @@
+package com.lc.ibps.components.verification.excel.model;
+
+import java.util.Map;
+
+/**
+ * 每个检测指标下的每天需要上传的检测数据
+ */
+public class ExcelRecordVO {
+    //标本数
+    private int specimensNum;
+    //重复次数
+    private int repeatNum;
+    //检测日期
+    private String date;
+
+    private String[] specimensName;
+
+    public ExcelRecordVO(int specimensNum, int repeatNum, String date, String[] specimensName) {
+        this.specimensNum = specimensNum;
+        this.repeatNum = repeatNum;
+        this.date = date;
+        this.specimensName = specimensName;
+    }
+
+    //样本名 : 检查数据
+    private Map<String,double[]> data;
+
+    public int getSpecimensNum() {
+        return specimensNum;
+    }
+
+    public void setSpecimensNum(int specimensNum) {
+        this.specimensNum = specimensNum;
+    }
+
+    public int getRepeatNum() {
+        return repeatNum;
+    }
+
+    public void setRepeatNum(int repeatNum) {
+        this.repeatNum = repeatNum;
+    }
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public String[] getSpecimensName() {
+        return specimensName;
+    }
+
+    public void setSpecimensName(String[] specimensName) {
+        this.specimensName = specimensName;
+    }
+
+    public Map<String, double[]> getData() {
+        return data;
+    }
+
+    public void setData(Map<String, double[]> data) {
+        this.data = data;
+    }
+}

+ 67 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/InspectionConfigVO.java

@@ -0,0 +1,67 @@
+package com.lc.ibps.components.verification.excel.model;
+
+import java.time.LocalDate;
+import java.util.Date;
+
+public class InspectionConfigVO {
+
+    //检验天数
+    private int days;
+    //标本数
+    private int specimensNum;
+    // 标本名
+    private String[] specimensName;
+    //重复次数
+    private int repeatNum;
+
+    public InspectionConfigVO(int days, int specimensNum, String[] specimensName, int repeatNum, LocalDate startDate) {
+        this.days = days;
+        this.specimensNum = specimensNum;
+        this.specimensName = specimensName;
+        this.repeatNum = repeatNum;
+        this.startDate = startDate;
+    }
+
+    private LocalDate startDate = LocalDate.now();
+
+    public int getDays() {
+
+        return days;
+    }
+
+    public void setDays(int days) {
+        this.days = days;
+    }
+
+    public int getSpecimensNum() {
+        return specimensNum;
+    }
+
+    public void setSpecimensNum(int specimensNum) {
+        this.specimensNum = specimensNum;
+    }
+
+    public String[] getSpecimensName() {
+        return specimensName;
+    }
+
+    public void setSpecimensName(String[] specimensName) {
+        this.specimensName = specimensName;
+    }
+
+    public int getRepeatNum() {
+        return repeatNum;
+    }
+
+    public void setRepeatNum(int repeatNum) {
+        this.repeatNum = repeatNum;
+    }
+
+    public LocalDate getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(LocalDate startDate) {
+        this.startDate = startDate;
+    }
+}

+ 78 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/InspectionItemVO.java

@@ -0,0 +1,78 @@
+package com.lc.ibps.components.verification.excel.model;
+
+
+import com.lc.ibps.components.poi.excel.entity.ExportParams;
+import com.lc.ibps.components.poi.excel.entity.enmus.ExcelType;
+import com.lc.ibps.components.poi.excel.entity.params.ExcelExportEntity;
+import com.lc.ibps.components.poi.excel.entity.vo.BaseEntityTypeConstants;
+import com.lc.ibps.components.verification.excel.PVExcelExportStyler;
+import com.lc.ibps.components.verification.excel.PVExcelUtil;
+import org.apache.poi.ss.usermodel.Workbook;
+
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 每个检测指标对应的数据
+ */
+public class InspectionItemVO {
+
+    private InspectionConfigVO config;
+
+    private List<ExcelRecordVO> data = new ArrayList<>();
+
+    public InspectionItemVO(InspectionConfigVO config) {
+        this.config = config;
+        LocalDate startDate = config.getStartDate();
+        for (int i = 0; i < config.getDays(); i++) {
+            data.add(new ExcelRecordVO(config.getSpecimensNum(),config.getRepeatNum(),
+                startDate.toString(),config.getSpecimensName()));
+            startDate = startDate.plusDays(1);
+        }
+    }
+
+    public Workbook exportExcel(){
+        List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();
+
+        List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>();
+        ExcelExportEntity e1 = new ExcelExportEntity("样本编号", "number");
+        e1.setType(BaseEntityTypeConstants.DoubleType);
+        temp.add(e1);
+        ExcelExportEntity e2 = new ExcelExportEntity("检测值", "value");
+        temp.add(e2);
+
+        for (int i = 0; i < config.getSpecimensNum(); i++) {
+            ExcelExportEntity excelEntity = new ExcelExportEntity(config.getSpecimensName()[i], "inspection");
+            excelEntity.setList(temp);
+            entity.add(excelEntity);
+        }
+        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+        Map<String, Object> map;
+        for (int i = 1; i <= config.getRepeatNum(); i++) {
+            map = new HashMap<String, Object>();
+            map.put("number", i);
+//            map.put("value", "");
+
+            List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>();
+            tempList.add(map);
+            map.put("inspection", tempList);
+
+            list.add(map);
+        }
+        List<ExportParams> exportParamsList = new ArrayList<ExportParams>();
+        LocalDate startDate = config.getStartDate();
+        for (int i = 0; i < config.getDays(); i++) {
+            ExportParams exportParams = new ExportParams("XXX性能验证数据导入模板", startDate.toString());
+            exportParams.setStyle(PVExcelExportStyler.class);
+            exportParamsList.add(exportParams);
+            startDate = startDate.plusDays(1);
+            exportParams.setType(ExcelType.XSSF);
+        }
+        Workbook workbook = PVExcelUtil.exportExcel(exportParamsList, entity,list);
+
+        return workbook;
+    }
+}

+ 9 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/InspectionVO.java

@@ -0,0 +1,9 @@
+package com.lc.ibps.components.verification.excel.model;
+
+import java.util.List;
+
+public class InspectionVO {
+
+
+    private List<InspectionItemVO> data;
+}

+ 60 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/model/RecordCalcVO.java

@@ -0,0 +1,60 @@
+package com.lc.ibps.components.verification.excel.model;
+
+import com.lc.ibps.components.verification.funcs.xAverage;
+import com.lc.ibps.components.verification.funcs.xFuncStdevVar;
+import com.lc.ibps.components.verification.funcs.xLog10;
+import com.lc.ibps.components.verification.funcs.xValue;
+
+/**
+ * 单列数据计算
+ */
+public class RecordCalcVO {
+
+    private xValue[] data;
+
+    private boolean isConvert = false;
+
+    private xValue[] convertedData;
+
+    private String[] validatorResult;
+
+    ////////////////////
+    private xValue average;
+    private xValue sd;
+    //sd/average
+    private xValue cv;
+
+    public RecordCalcVO(xValue[] data,boolean isConvert) {
+        this.data = data;
+        this.isConvert = isConvert;
+        if(!isConvert) convertedData = data;
+        else convert();
+    }
+
+    public xValue getAverage(){
+        if(average == null) average = xAverage.eval(convertedData);
+        return average;
+    }
+
+    public xValue getSd(){
+        if(sd == null) sd =  xFuncStdevVar.evalArgs(convertedData,xFuncStdevVar.iSTDEV);
+        return sd;
+    }
+
+    public xValue getCv(){
+        if(cv != null) return cv;
+        cv = new xValue();
+        if(getSd().isErr() || getAverage().isErr()) cv.setErrNa();
+        else cv.setVal(sd.getDoub() / average.getDoub());
+        return  cv;
+    }
+
+    private void convert(){
+        convertedData = xLog10.eval(data);
+    }
+
+    public double calcAbsoluteDeviation(double targetValue){
+        return targetValue - getAverage().getDoub();
+    }
+
+}

+ 25 - 10
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/TestFuncs.java

@@ -1,23 +1,38 @@
 package com.lc.ibps.components.verification.funcs;
 
+import org.junit.Test;
+
 public class TestFuncs {
-    public static void main(String[] args){
-        double[] cNode1 = {25.30 ,28.40 ,32.50 ,36.90 ,42.70 ,49.80 ,55.10 ,62.30 ,65.40 ,69.70 ,85.40 ,89.60 ,91.30 ,99.40 ,105.60 ,135.40 ,162.40 ,173.40 ,184.50 ,192.60 ,203.60 ,219.80 ,235.60 ,233.70 ,216.90 ,265.80 ,272.60 ,288.80 ,294.60 ,309.40 ,335.60 ,356.40 ,342.90 ,365.70 ,385.40 ,376.30 ,402.00 ,415.00 ,426.90 ,468.0};
-        double[] cNode2 = {26.40 ,29.30 ,33.50 ,35.90 ,43.10 ,50.90 ,56.80 ,63.40 ,62.70 ,72.40 ,88.10 ,90.30 ,90.60 ,98.40 ,102.70 ,130.60 ,165.90 ,170.60 ,186.50 ,199.40 ,203.50 ,220.70 ,234.90 ,236.70 ,210.90 ,270.10 ,276.40 ,290.00 ,298.00 ,310.00 ,339.00 ,354.00 ,343.00 ,369.00 ,387.00 ,372.00 ,404.00 ,416.00 ,429.00 ,470.00};
-        xFuncStdevVar stdev =new xFuncStdevVar();
-        xValue xValue1 = stdev.evalArgs(cNode1, xFuncStdevVar.iSTDEV);
-        xValue xValue2 = stdev.evalArgs(cNode2, xFuncStdevVar.iSTDEV);
+    @Test
+    public  void test(){
+        double[] cNode11 = {25.30 ,28.40 ,32.50 ,36.90 ,42.70 ,49.80 ,55.10 ,62.30 ,65.40 ,69.70 ,85.40 ,89.60 ,91.30 ,99.40 ,105.60 ,135.40 ,162.40 ,173.40 ,184.50 ,192.60 ,203.60 ,219.80 ,235.60 ,233.70 ,216.90 ,265.80 ,272.60 ,288.80 ,294.60 ,309.40 ,335.60 ,356.40 ,342.90 ,365.70 ,385.40 ,376.30 ,402.00 ,415.00 ,426.90 ,468.0};
+        double[] cNode21 = {26.40 ,29.30 ,33.50 ,35.90 ,43.10 ,50.90 ,56.80 ,63.40 ,62.70 ,72.40 ,88.10 ,90.30 ,90.60 ,98.40 ,102.70 ,130.60 ,165.90 ,170.60 ,186.50 ,199.40 ,203.50 ,220.70 ,234.90 ,236.70 ,210.90 ,270.10 ,276.40 ,290.00 ,298.00 ,310.00 ,339.00 ,354.00 ,343.00 ,369.00 ,387.00 ,372.00 ,404.00 ,416.00 ,429.00 ,470.00};
+        xValue[] cNode1 = convert(cNode11);
+        xValue[] cNode2 = convert(cNode21);
+        xValue xValue = xAverage.eval(cNode1);
+        System.out.println(xValue.getDoub());
+        xValue[] x = xLog10.eval(cNode1);
+        System.out.println(x);
+        xValue xValue1 = xFuncStdevVar.evalArgs((cNode1), xFuncStdevVar.iSTDEV);
+        xValue xValue2 = xFuncStdevVar.evalArgs((cNode2), xFuncStdevVar.iSTDEV);
         System.out.println(xValue1.getDoub());
         System.out.println(xValue2.getDoub());
 
-        xFuncArray2Args xfuncs = new xFuncArray2Args();
-        xValue b = xfuncs.evalArgs(cNode2,cNode1,  xFuncArray2Args.iSLOPE);
+        xValue b = xFuncArray2Args.evalArgs(cNode2,cNode1,  xFuncArray2Args.iSLOPE);
         System.out.println(b.getDoub());
 
-        xValue a = xfuncs.evalArgs(cNode2,cNode1,  xFuncArray2Args.iINTERCEPT);
+        xValue a = xFuncArray2Args.evalArgs(cNode2,cNode1,  xFuncArray2Args.iINTERCEPT);
         System.out.println(a.getDoub());
 
-        xValue r = xfuncs.evalArgs(cNode2,cNode1,  xFuncArray2Args.iCORREL);
+        xValue r = xFuncArray2Args.evalArgs(cNode2,cNode1,  xFuncArray2Args.iCORREL);
         System.out.println(r.getDoub());
     }
+
+    public static xValue[] convert(double[] data){
+        xValue[] c = new xValue[data.length];
+        for (int i = 0; i < data.length; i++) {
+            c[i] = new xValue(data[i]);
+        }
+        return c;
+    }
 }

+ 29 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xAverage.java

@@ -0,0 +1,29 @@
+package com.lc.ibps.components.verification.funcs;
+
+public class xAverage {
+
+
+    /** AVERAGEs n ranges. */
+    public static xValue eval(xValue[] cNod) {
+        xValue valRes = new xValue();
+        try {
+            int iCnt = 0;
+            double dSum = 0;
+            xValue val ;
+            for (int ii = cNod.length; --ii >= 0; ) {
+                val = cNod[ii];
+                dSum += val.getDoub();
+                iCnt++;
+
+            }
+            if (iCnt == 0) {
+                valRes.setErrDiv();
+            } else {
+                valRes.setVal(dSum / iCnt);
+            }
+        } catch (Exception e) {
+            valRes.setErrVal();
+        }
+        return valRes;
+    }
+}

+ 3 - 5
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xFuncArray2Args.java

@@ -1,7 +1,5 @@
 package com.lc.ibps.components.verification.funcs;
 
-import lombok.val;
-
 import java.io.Serializable;
 
 public class xFuncArray2Args implements Serializable {
@@ -21,7 +19,7 @@ public class xFuncArray2Args implements Serializable {
      * @return        true if the node has been evaluated successfully
      */
     //We may want redo this method in the future in order to make it clearer.
-    public xValue evalArgs(double[] cNod1, double[] cNod2, int iFunc) {
+    public static xValue evalArgs(xValue[] cNod1, xValue[] cNod2, int iFunc) {
         xValue valRes = new xValue();
 
 
@@ -35,8 +33,8 @@ public class xFuncArray2Args implements Serializable {
             //'boolSets' keeps track of non-doubles
             for (int ii = 0; ii < iCnt; ii++) {
                 boolSets[ii] = true;
-                dblSets[ii][0] = cNod1[ii];
-                dblSets[ii][1] = cNod2[ii];
+                dblSets[ii][0] = cNod1[ii].getDoub();
+                dblSets[ii][1] = cNod2[ii].getDoub();
             }
 
             //Here we calculate generic intermediate results

+ 2 - 2
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xFuncStdevVar.java

@@ -20,7 +20,7 @@ public class xFuncStdevVar implements Serializable {
      * @return        true if the node has been evaluated successfully
      */
     //We may want redo this method in the future in order to make it clearer.
-    public xValue evalArgs(double[] cNod, int iFunc) {
+    public static xValue evalArgs(xValue[] cNod, int iFunc) {
         xValue valRes = new xValue();
 
         double dBuff = 0;
@@ -28,7 +28,7 @@ public class xFuncStdevVar implements Serializable {
         double xx2 = 0;
         long nn = 0;
         for (int ii = 0; ii < cNod.length; ii++) {
-            dBuff = cNod[ii];
+            dBuff = cNod[ii].getDoub();
             xx += dBuff;
             xx2 += Math.pow(dBuff, 2);
             nn++;

+ 20 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xLog10.java

@@ -0,0 +1,20 @@
+package com.lc.ibps.components.verification.funcs;
+
+public class xLog10 {
+    /** Does the actual operation. */
+    public static xValue[] eval(xValue[] data) {
+        xValue[] convert = new xValue[data.length];
+        for(int i = 0 ; i< data.length; i++) {
+            if(!data[i].isDoub()){
+                convert[i] = new xValue();
+                convert[i].setErrVal();
+            }
+            if (data[i].getDoub() <= 0) {
+                convert[i] = new xValue(0);
+            } else {
+                convert[i] = new xValue(Math.log(data[i].getDoub()) / Math.log(10));
+            }
+        }
+        return convert;
+    }
+}

+ 10 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xValue.java

@@ -37,6 +37,16 @@ public class xValue implements Serializable {
     private Object valObj = null;  //Originally this was a String declaration
 
     //============SET METHOD SECTION============
+    public xValue(){}
+    public xValue(String valObj) {
+        this.iType = iSTRING;
+        this.valObj = valObj;
+    }
+    public xValue(double valDoub) {
+        this.iType = iDOUBLE;
+        this.valObj = valDoub;
+        this.valDoub = valDoub;
+    }
 
     /**
      * Stores the attributes of valX