diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/param/ReportQueryParam.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/param/ReportQueryParam.java index 1d23b33dc..c68aa4c47 100644 --- a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/param/ReportQueryParam.java +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/param/ReportQueryParam.java @@ -27,4 +27,10 @@ public class ReportQueryParam { @NotBlank(message = "结束时间不可为空") private String endTime; + @ApiModelProperty(name = "b",value = "判断时间是否是当天(true 当天 false不是当天)") + private Boolean b ; + + @ApiModelProperty(name = "lineId",value = "95条数取值") + private double count; + } diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/DataI.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/DataI.java new file mode 100644 index 000000000..1a5cc50af --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/DataI.java @@ -0,0 +1,81 @@ +package com.njcn.harmonic.pojo.po.report; + +import lombok.Data; +import org.influxdb.annotation.Column; +import org.influxdb.annotation.Measurement; + +import java.time.Instant; + +/** + * data_v influxDB别名映射表 + * + * @author qijian + * @version 1.0.0 + * @createTime 2022/10/27 15:27 + */ +@Data +@Measurement(name = "data_i") +public class DataI { + + @Column(name = "time") + private Instant time; + + @Column(name = "phasic_type") + private String phaseType; + + @Column(name = "value_type") + private String valueType; + + @Column(name = "rms") + private Double rms; + + @Column(name = "line_id") + private String lineId; + + @Column(name = "freq_max") + private Double frepMAX; + + @Column(name = "freq_min") + private Double frepMIN; + + @Column(name = "rms_max") + private Double rmsMAX; + + @Column(name = "rms_min") + private Double rmsMIN; + + @Column(name = "rms_lvr_max") + private Double rmsLvrMAX; + + @Column(name = "rms_lvr_min") + private Double rmsLvrMIN; + + @Column(name = "v_thd_max") + private Double vThdMAX; + + @Column(name = "v_thd_min") + private Double vThdMIN; + + @Column(name = "v_unbalance_max") + private Double vUnbalanceMAX; + + @Column(name = "v_unbalance_min") + private Double vUnbalanceMIN; + + @Column(name = "freq_count") + private Integer freqCount; + + @Column(name = "rms_count") + private Integer rmsCount; + + @Column(name = "rms_lvr_count") + private Integer rmsLvrCount; + + @Column(name = "v_thd_count") + private Integer vThdCount; + + @Column(name = "v_unbalance_count") + private Integer vUnbalanceCount; + + +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/EnumPass.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/EnumPass.java new file mode 100644 index 000000000..1c6171ee7 --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/EnumPass.java @@ -0,0 +1,35 @@ +package com.njcn.harmonic.pojo.po.report; + +public enum EnumPass { + MAX(1, "使用最大值与国标限值比较,判断指标是否合格"), + MIN(2, "使用最小值与国标限值比较,判断指标是否合格"), + MEAN(3, "使用平均值与国标限值比较,判断指标是否合格"), + CP95(4, "使用CP95值与国标限值比较,判断指标是否合格"), + DEFAULT(5, "不作比较"), + PASS(0, "合格"), + FPYVALUE(98, "合格率限值"), + FPYV(1, "UHARM_0_OVERTIME"), + FPYI(2, "IHARM_0_OVERTIME"), + FPYVOLTAGE(3, "VOLTAGE_DEV_OVERTIME"), + FPYTHREE(4, "UBALANCE_OVERTIME"), + FPYTHDV(5, "UABERRANCE_OVERTIME"), + FPYRATE(6, "FREQ_DEV_OVERTIME"), + FPYFLICKER(7, "FLICKER_OVERTIME"), + NOPASS(-1, "不合格"); + + private Integer code; + private String describe; + + EnumPass(Integer code, String describe) { + this.code = code; + this.describe = describe; + } + + public Integer getCode() { + return code; + } + + public String getDescribe() { + return describe; + } +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/OverLimitInfo.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/OverLimitInfo.java new file mode 100644 index 000000000..21b73c54e --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/OverLimitInfo.java @@ -0,0 +1,20 @@ +package com.njcn.harmonic.pojo.po.report; + + +import com.njcn.device.pq.pojo.po.Overlimit; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class OverLimitInfo implements Serializable { + private static final long serialVersionUID = 7466469972886414616L; + private List overLimitRate; + private Double count; + private Double pltCount; + private Double pstCount; + private List list; + private String mode; + +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/Pass.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/Pass.java new file mode 100644 index 000000000..90817a2e2 --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/Pass.java @@ -0,0 +1,24 @@ +package com.njcn.harmonic.pojo.po.report; + +import lombok.Data; + +/** + * @author wr + * @description + * @date 2023/4/12 11:40 + */ +@Data +public class Pass { + private Float overLimit; + private Integer code; + + public Pass(Float overLimit) { + this.code = EnumPass.DEFAULT.getCode(); + this.overLimit = overLimit; + } + + public Pass(Float overLimit, Integer code) { + this.overLimit = overLimit; + this.code = code; + } +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/ReportTarget.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/ReportTarget.java new file mode 100644 index 000000000..54ab783be --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/po/report/ReportTarget.java @@ -0,0 +1,17 @@ +package com.njcn.harmonic.pojo.po.report; + +import com.njcn.harmonic.pojo.vo.ReportValue; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +@Data +public class ReportTarget implements Serializable { + + private static final long serialVersionUID = -6931764660060228127L; + private List list; + private Float overLimit; //指标的国标限值 + private Integer pass; + + +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/vo/ReportValue.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/vo/ReportValue.java new file mode 100644 index 000000000..284e2164b --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/vo/ReportValue.java @@ -0,0 +1,77 @@ +package com.njcn.harmonic.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author wr + * @description + * @date 2023/4/10 15:36 + */ +@NoArgsConstructor +public class ReportValue implements Serializable { + + private String phaseType; //A(AB)相,B(BC)相,C(CA)相,T总功 + private Float fmaxValue; //最大值 + private Float minValue; //最小值 + private Float meanValue; //平均值 + private Float cp95Value; //CP95值 + + public String getPhaseType() { + return phaseType; + } + + public Float getFmaxValue() { + return fmaxValue; + } + + public Float getMinValue() { + return minValue; + } + + public Float getMeanValue() { + return meanValue; + } + + public Float getCp95Value() { + return cp95Value; + } + + public void setPhaseType(String phaseType) { + this.phaseType = phaseType; + } + + public void setFmaxValue(Float fmaxValue) { + this.fmaxValue = transData(fmaxValue); + } + + public void setMinValue(Float minValue) { + this.minValue = transData(minValue); + } + + public void setMeanValue(Float meanValue) { + this.meanValue = transData(meanValue); + } + + public void setCp95Value(Float cp95Value) { + this.cp95Value = transData(cp95Value); + } + + public ReportValue(String phaseType, Float maxValue, Float minValue, Float meanValue, Float cp95Value) { + this.phaseType = phaseType; + this.fmaxValue = transData(maxValue); + this.minValue = transData(minValue); + this.meanValue = transData(meanValue); + this.cp95Value = transData(cp95Value); + } + private Float transData(Float f) { + if (f == null) { + return f; + } + float f1 = (float) (Math.round(f.floatValue() * 100)) / 100; + return new Float(f1); + } +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/ClearPathUtil.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/ClearPathUtil.java new file mode 100644 index 000000000..b21898e7b --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/ClearPathUtil.java @@ -0,0 +1,141 @@ +package com.njcn.harmonic.utils; + +/** + * @author hongawen + * @date: 2020/8/20 13:36 + */ +public class ClearPathUtil { + + /** + * 针对漏洞,新增的特殊字符替换的扫描方法 + */ + public static String cleanString(String str) { + if (str == null){ + return null; + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < str.length(); ++i) { + sb.append(cleanChar(str.charAt(i))); + } + return sb.toString(); + } + + private static char cleanChar(char ch) { + + // 0 - 9 + for (int i = 48; i < 58; ++i) { + if (ch == i) { + return (char) i; + } + } + + // 'A' - 'Z' + for (int i = 65; i < 91; ++i) { + if (ch == i) { + return (char) i; + } + } + + // 'a' - 'z' + for (int i = 97; i < 123; ++i) { + if (ch == i) { + return (char) i; + } + } + + // other valid characters + switch (ch) { + case '/': + return '/'; + case '.': + return '.'; + case '-': + return '-'; + case '_': + return '_'; + case ',': + return ','; + case ' ': + return ' '; + case '!': + return '!'; + case '@': + return '@'; + case '#': + return '#'; + case '$': + return '$'; + case '%': + return '%'; + case '^': + return '^'; + case '&': + return '&'; + case '*': + return '*'; + case '(': + return '('; + case ')': + return ')'; + case '+': + return '+'; + case '=': + return '='; + case ':': + return ':'; + case ';': + return ';'; + case '?': + return '?'; + case '"': + return '"'; + case '<': + return '<'; + case '>': + return '>'; + case '`': + return '`'; + case '\\': + return '/'; + case 'I': + return 'I'; + case 'Ⅱ': + return 'Ⅱ'; + case 'Ⅲ': + return 'Ⅲ'; + case 'Ⅳ': + return 'Ⅳ'; + case 'Ⅴ': + return 'Ⅴ'; + case 'Ⅵ': + return 'Ⅵ'; + case 'Ⅶ': + return 'Ⅶ'; + case 'Ⅷ': + return 'Ⅷ'; + case 'Ⅸ': + return 'Ⅸ'; + + case 'V': + return 'V'; + case 'X': + return 'X'; + case 'Ⅹ': + return 'Ⅹ'; + } + if (isChineseChar(ch)){ + return ch; + } + return '%'; + } + + // 根据Unicode编码判断中文汉字和符号 + private static boolean isChineseChar(char c) { + Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); + return ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS + || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B + || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS + || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION; + } + +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/CustomXWPFDocument.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/CustomXWPFDocument.java new file mode 100644 index 000000000..b39b65f1e --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/CustomXWPFDocument.java @@ -0,0 +1,83 @@ +package com.njcn.harmonic.utils; + +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlToken; +import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D; +import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline; + +import java.io.IOException; +import java.io.InputStream; + +@Slf4j +public class CustomXWPFDocument extends XWPFDocument { + // 日志记录 + public CustomXWPFDocument(InputStream in) throws IOException { + super(in); + } + + public CustomXWPFDocument() { + super(); + } + + public CustomXWPFDocument(OPCPackage pkg) throws IOException { + super(pkg); + } + + /** + * @param id + * @param width + * 宽 + * @param height + * 高 + * @param paragraph + * 段落 + */ + public void createPicture(int id, int width, int height,String blipId, XWPFParagraph paragraph) { + final int EMU = 9525; + width *= EMU; + height *= EMU; +// String blipId = getAllPictures().get(id).getPackageRelationship().getId(); + CTInline inline = paragraph.createRun().getCTR().addNewDrawing().addNewInline(); + String picXml = "" + "" + + " " + + " " + + " " + " " + + " " + " " + " " + + " " + + " " + " " + " " + + " " + " " + " " + + " " + " " + " " + " " + + " " + " " + " " + + " " + " " + ""; + + inline.addNewGraphic().addNewGraphicData(); + XmlToken xmlToken = null; + try { + xmlToken = XmlToken.Factory.parse(picXml); + } catch (XmlException xe) { + log.error("生成报表发生异常,异常是"+xe.getMessage()); + } + inline.set(xmlToken); + + inline.setDistT(0); + inline.setDistB(0); + inline.setDistL(0); + inline.setDistR(0); + + CTPositiveSize2D extent = inline.addNewExtent(); + extent.setCx(width); + extent.setCy(height); + + CTNonVisualDrawingProps docPr = inline.addNewDocPr(); + docPr.setId(id); + docPr.setName("图片" + id); + docPr.setDescr("测试"); + } +} \ No newline at end of file diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/PubUtils.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/PubUtils.java new file mode 100644 index 000000000..3ca5d7702 --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/PubUtils.java @@ -0,0 +1,88 @@ +package com.njcn.harmonic.utils; + +import lombok.extern.slf4j.Slf4j; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.Socket; +import java.util.Properties; + +/** + * @author wr + * @description + * @date 2023/4/10 17:39 + */ +@Slf4j +public class PubUtils { + public static boolean createFile(String destFileName) { + File file = new File(destFileName); + if (file.exists()) { + log.warn("创建单个文件" + destFileName + "失败,目标文件已存在!"); + return false; + } + if (destFileName.endsWith(File.separator)) { + log.warn("创建单个文件" + destFileName + "失败,目标文件不能为目录!"); + return false; + } + //判断目标文件所在的目录是否存在 + if (!file.getParentFile().exists()) { + //如果目标文件所在的目录不存在,则创建父目录 + log.warn("目标文件所在目录不存在,准备创建它!"); + if (!file.getParentFile().mkdirs()) { + log.warn("创建目标文件所在目录失败!"); + return false; + } + } + //创建目标文件 + try { + if (file.createNewFile()) { + log.warn("创建单个文件" + destFileName + "成功!"); + return true; + } else { + log.warn("创建单个文件" + destFileName + "失败!"); + return false; + } + } catch (IOException e) { + log.warn("创建单个文件" + destFileName + "失败!" + e.getMessage()); + return false; + } + } + + /** + * 读取配置文件 + * + * @param cl 类名字 + * @param strPropertiesName 配置文件名称 + */ + public static Properties readProperties(ClassLoader cl, String strPropertiesName) { + Properties pros = new Properties(); + InputStream in = null; + try { + in = cl.getResourceAsStream(strPropertiesName); + pros.load(in); + } catch (Exception e) { + log.error("读取配置文件失败失败:" + e.getMessage()); + } finally { + if (in != null) { + PubUtils.safeClose(in, "安全关闭读取配置文件失败,异常为:"); + } + } + return pros; + } + + /** + * 安全关闭InputStream + * + * @param s + */ + public static void safeClose(InputStream s, String strError) { + if (s != null) { + try { + s.close(); + } catch (IOException e) { + log.error(strError + e.toString()); + } + } + } +} diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/WordUtil2.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/WordUtil2.java new file mode 100644 index 000000000..a3c08f89a --- /dev/null +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/utils/WordUtil2.java @@ -0,0 +1,360 @@ +package com.njcn.harmonic.utils; + +import org.apache.poi.xwpf.usermodel.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.*; +import java.net.URLEncoder; +import java.util.*; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public class WordUtil2 { + // 日志记录 + private static final Logger logger = LoggerFactory.getLogger(WordUtil2.class); + + public void getWord(String path, Map params, String fileName, HttpServletResponse response, HttpSession session) + throws Exception { + path = ClearPathUtil.cleanString(path); + File file = new File(path); + InputStream inStream = null; + CustomXWPFDocument doc = null; + //读取报告模板 + try { + inStream = new FileInputStream(file); + doc = new CustomXWPFDocument(inStream); + this.replaceInTable(doc, params); // 替换表格里面的变量 + this.replaceInPara(doc, params); // 替换文本里面的变量 + } catch (IOException e) { + logger.error("获取报告模板异常,原因为:" + e.toString()); + } finally { + if (null != inStream) { + inStream.close(); + } + } +// //读取配置文件 +// Properties pros = PubUtils.readProperties(getClass().getClassLoader(), "java.properties"); +// String tmpPath = pros.get("TMP_PATH").toString() +File.separator+ "offlinereoprt"; +// tmpPath= ClearPathUtil.cleanString(tmpPath); +// OutputStream os = null; +// File tmpfile = new File(tmpPath); +// if(!tmpfile.exists()){ +// tmpfile.mkdir(); +// } +// tmpPath = tmpPath +File.separator+ fileName; +// tmpPath= ClearPathUtil.cleanString(tmpPath); +// File tmp = new File(tmpPath); +// if(tmp.exists()){ +// tmp.delete(); +// } +// PubUtils.createFile(tmpPath); + try { +// os = new FileOutputStream(tmpPath); +// if (doc != null) { +// doc.write(os); +// } + ServletOutputStream outputStream = response.getOutputStream(); + response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); + response.setContentType("application/octet-stream;charset=UTF-8"); + doc.write(outputStream); + outputStream.close(); + +// session.setAttribute("tmpPath", tmpPath); +// session.setAttribute("fileName", fileName); + } catch (Exception e) { + session.setAttribute("tmpPath", ""); + session.setAttribute("fileName", ""); + logger.error("输出稳态报告异常,原因为:" + e.toString()); + } finally { +// if (os != null) { +// os.close(); +// } + if (doc != null) { + doc.close(); + } + } + } + + /** + * 替换段落里面的变量 + * + * @param doc 要替换的文档 + * @param params 参数 + */ + private void replaceInPara(CustomXWPFDocument doc, Map params) { + Iterator iterator = doc.getParagraphsIterator(); + List paragraphList = new ArrayList<>(); + XWPFParagraph para; + while (iterator.hasNext()) { + para = iterator.next(); + paragraphList.add(para); + } + processParagraphs(paragraphList, params, doc); + } + + private void replaceInTable(CustomXWPFDocument doc, Map params) { + Iterator it = doc.getTablesIterator(); + while (it.hasNext()) { + XWPFTable table = it.next(); + List rows = table.getRows(); + for (XWPFTableRow row : rows) { + List cells = row.getTableCells(); + for (XWPFTableCell cell : cells) { + List paragraphListTable = cell.getParagraphs(); + processParagraphs(paragraphListTable, params, doc); + } + } + } + } + + public static void processParagraphs(List paragraphList, Map param, + CustomXWPFDocument doc) { + if (paragraphList != null && paragraphList.size() > 0) { + for (XWPFParagraph paragraph : paragraphList) { + List runs = paragraph.getRuns(); + if (runs.size() > 0) { + for (XWPFRun run : runs) { + String bflag = ""; + String text = run.getText(0); + if (text != null) { + boolean isSetText = false; + for (Entry entry : param.entrySet()) { + String key = entry.getKey(); + if (text.indexOf(key) != -1) { + isSetText = true; + Object value = entry.getValue(); + if (value instanceof String) {// 文本替换 + text = text.replace(key, value.toString()); + } else if (value instanceof Map) {// 图片替换 + text = text.replace(key, ""); + Map pic = (Map) value; + int width = Integer.parseInt(pic.get("width").toString()); + int height = Integer.parseInt(pic.get("height").toString()); + int picType = getPictureType(pic.get("type").toString()); + byte[] byteArray = (byte[]) pic.get("content"); + ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteArray); + try { + String s = doc.addPictureData(byteInputStream, picType); + + doc.createPicture(doc.getAllPictures().size() - 1, width, height, + s,paragraph); + bflag = "break"; + } catch (Exception e) { + logger.error("文本替换发生异常,异常是" + e.getMessage()); + } + } + } + } + if (isSetText) { + run.setText(text, 0); + } + } + if (bflag == "break") { + break; + } + } + } + } + } + } + + /** + * 替换段落里面的变量 + * + * @param para 要替换的段落 + * @param params 参数 + */ + private void replaceInPara(XWPFParagraph para, Map params, CustomXWPFDocument doc) { + List runs; + Matcher matcher; + // if (this.matcher(para.getParagraphText()).find()) { + runs = para.getRuns(); + int start = -1; + int end = -1; + String str = ""; + for (int i = 0; i < runs.size(); i++) { + XWPFRun run = runs.get(i); + String runText = run.toString(); + if ('$' == runText.charAt(0) && '{' == runText.charAt(1)) { + start = i; + } + if ((start != -1)) { + str += runText; + } + if ('}' == runText.charAt(runText.length() - 1)) { + if (start != -1) { + end = i; + break; + } + } + } + + for (int i = start; i <= end; i++) { + para.removeRun(i); + i--; + end--; + } + + for (Entry entry : params.entrySet()) { + String key = entry.getKey(); + if (str.indexOf(key) != -1) { + Object value = entry.getValue(); + if (value instanceof String) { + str = str.replace(key, value.toString()); + para.createRun().setText(str, 0); + break; + } else if (value instanceof Map) { + str = str.replace(key, ""); + Map pic = (Map) value; + int width = Integer.parseInt(pic.get("width").toString()); + int height = Integer.parseInt(pic.get("height").toString()); + int picType = getPictureType(pic.get("type").toString()); + byte[] byteArray = (byte[]) pic.get("content"); + ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteArray); + try { + // int ind = doc.addPicture(byteInputStream,picType); + // doc.createPicture(ind, width , height,para); + String s = doc.addPictureData(byteInputStream, picType); + doc.createPicture(doc.getAllPictures().size() - 1, width, height,s, para); + para.createRun().setText(str, 0); + break; + } catch (Exception e) { + logger.error("文件替换发生异常,异常是" + e.getMessage()); + } + } + } + } + // } + } + + /** + * 为表格插入数据,行数不够添加新行 + * + * @param table 需要插入数据的表格 + * @param tableList 插入数据集合 + */ + private static void insertTable(XWPFTable table, List tableList) { + // 创建行,根据需要插入的数据添加新行,不处理表头 + for (int i = 0; i < tableList.size(); i++) { + XWPFTableRow row = table.createRow(); + } + // 遍历表格插入数据 + List rows = table.getRows(); + int length = table.getRows().size(); + for (int i = 1; i < length - 1; i++) { + XWPFTableRow newRow = table.getRow(i); + List cells = newRow.getTableCells(); + for (int j = 0; j < cells.size(); j++) { + XWPFTableCell cell = cells.get(j); + String s = tableList.get(i - 1)[j]; + cell.setText(s); + } + } + } + + /** + * 替换表格里面的变量 + * + * @param doc 要替换的文档 + * @param params 参数 + */ + private void replaceInTable(CustomXWPFDocument doc, Map params, List tableList) { + Iterator iterator = doc.getTablesIterator(); + XWPFTable table; + List rows; + List cells; + List paras; + while (iterator.hasNext()) { + table = iterator.next(); + if (table.getRows().size() > 1) { + // 判断表格是需要替换还是需要插入,判断逻辑有$为替换,表格无$为插入 + if (this.matcher(table.getText()).find()) { + rows = table.getRows(); + for (XWPFTableRow row : rows) { + cells = row.getTableCells(); + for (XWPFTableCell cell : cells) { + paras = cell.getParagraphs(); + for (XWPFParagraph para : paras) { + this.replaceInPara(para, params, doc); + } + } + } + } else { + insertTable(table, tableList); // 插入数据 + } + } + } + } + + /** + * 正则匹配字符串 + * + * @param str + * @return + */ + private Matcher matcher(String str) { + Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}", Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(str); + return matcher; + } + + /** + * 根据图片类型,取得对应的图片类型代码 + * + * @param picType + * @return int + */ + private static int getPictureType(String picType) { + int res = CustomXWPFDocument.PICTURE_TYPE_PICT; + if (picType != null) { + if (picType.equalsIgnoreCase("image/png")) { + res = CustomXWPFDocument.PICTURE_TYPE_PNG; + } else if (picType.equalsIgnoreCase("image/dib")) { + res = CustomXWPFDocument.PICTURE_TYPE_DIB; + } else if (picType.equalsIgnoreCase("image/emf")) { + res = CustomXWPFDocument.PICTURE_TYPE_EMF; + } else if (picType.equalsIgnoreCase("image/jpg") || picType.equalsIgnoreCase("image/jpeg")) { + res = CustomXWPFDocument.PICTURE_TYPE_JPEG; + } else if (picType.equalsIgnoreCase("image/wmf")) { + res = CustomXWPFDocument.PICTURE_TYPE_WMF; + } + } + return res; + } + + /** + * 关闭输入流 + * + * @param is + */ + private void close(InputStream is) { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + logger.error("关闭输入流发生异常,异常是" + e.getMessage()); + } + } + } + + /** + * 关闭输出流 + * + * @param os + */ + private void close(OutputStream os) { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + logger.error("关闭输出流发生异常,异常是" + e.getMessage()); + } + } + } +} diff --git a/pqs-harmonic/harmonic-boot/pom.xml b/pqs-harmonic/harmonic-boot/pom.xml index f107874a8..50cfdd39d 100644 --- a/pqs-harmonic/harmonic-boot/pom.xml +++ b/pqs-harmonic/harmonic-boot/pom.xml @@ -95,6 +95,16 @@ harmonicboot + + org.apache.maven.plugins + maven-resources-plugin + + UTF-8 + + docx + + + org.apache.maven.plugins maven-compiler-plugin diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/ExportModelController.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/ExportModelController.java new file mode 100644 index 000000000..ef4d8e3a8 --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/ExportModelController.java @@ -0,0 +1,1536 @@ +package com.njcn.harmonic.controller; + + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.utils.PubUtils; +import com.njcn.device.pms.api.MonitorClient; +import com.njcn.device.pms.pojo.po.Monitor; +import com.njcn.device.pq.api.LineFeignClient; +import com.njcn.device.pq.pojo.po.Overlimit; +import com.njcn.device.pq.pojo.vo.LineDetailDataVO; +import com.njcn.event.enums.EventResponseEnum; +import com.njcn.harmonic.pojo.param.ReportQueryParam; +import com.njcn.harmonic.pojo.po.report.EnumPass; +import com.njcn.harmonic.pojo.po.report.OverLimitInfo; +import com.njcn.harmonic.pojo.po.report.Pass; +import com.njcn.harmonic.pojo.po.report.ReportTarget; +import com.njcn.harmonic.pojo.vo.ReportValue; +import com.njcn.harmonic.service.ReportService; +import com.njcn.harmonic.utils.WordUtil2; +import com.njcn.system.api.DicDataFeignClient; +import com.njcn.system.api.ThemeFeignClient; +import com.njcn.system.pojo.po.Theme; +import com.njcn.web.controller.BaseController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import sun.misc.BASE64Encoder; + +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.*; + + +@Slf4j +@RestController +@RequestMapping("/exportmodel") +@Api(tags = "word报告") +@AllArgsConstructor +public class ExportModelController extends BaseController { + + + + // 非谐波数据 + List listVirtual; + List listPower; + List listFlicker; + List listDistortion; + List listVdeviation; + List listFrequency; + List listThreephase; + // 谐波电压数据 + List listVoltageRate; + // 谐波电流数据 + List listICurrent; + + + private final LineFeignClient lineFeignClient; + private final MonitorClient monitorClient; + private final DicDataFeignClient dicDataFeignClient; + private final ThemeFeignClient themeFeignClient; + private final ReportService reportService; + + @PostMapping("/exportModel") + @ApiOperation("word报告") + public String exportworld(HttpSession session, HttpServletResponse response, + String startTime, String endTime, Integer type, String lineIndex, + String name, String reportNumber, String crmName, + MultipartFile file) throws IOException { + + //获取监测点信息 + String bdname = ""; + Integer pttype = 0; + String areaName = ""; + String atype = ""; + String btype = ""; + String ctype = ""; + LineDetailDataVO lineDto = new LineDetailDataVO(); + if (type == 0) { + lineDto = lineFeignClient.getLineDetailData(lineIndex).getData(); + if (ObjectUtil.isNull(lineDto)) { + throw new BusinessException(EventResponseEnum.NOT_FOUND); + } + bdname = lineDto.getBdName(); + areaName = lineDto.getAreaName(); + pttype = PubUtils.ptTypeName(lineDto.getPtType()); + } else { + List monitorList = monitorClient.getMonitorList(Arrays.asList(lineIndex)).getData(); + if (ObjectUtil.isNull(monitorList)) { + throw new BusinessException(EventResponseEnum.NOT_FOUND); + } + Monitor monitor = monitorList.get(0); + bdname = monitor.getPowerrName(); + areaName = monitor.getOrgName(); + String terminalWiringMethod = dicDataFeignClient.getDicDataById(monitor.getTerminalWiringMethod()).getData().getName(); + pttype = PubUtils.ptTypeName(terminalWiringMethod); + lineDto.setPt(monitor.getPt1() + "/" + monitor.getPt2()); + lineDto.setCt(monitor.getCt1() + "/" + monitor.getCt2()); + //基准容量 + lineDto.setStandardCapacity(monitor.getStandShortCapacity()); + //短路容量 + lineDto.setShortCapacity(monitor.getMinShortCircuitCapacity()); + //协议容量 + lineDto.setDealCapacity(monitor.getUserAgreementCapacity()); + //设备容量 + lineDto.setDevCapacity(monitor.getPowerSupplyEqCapacity()); + //电压等级 + lineDto.setScale(dicDataFeignClient.getDicDataById(monitor.getVoltageLevel()).getData().getName()); + + } + if (pttype == 0) { + atype = "A相"; + btype = "B相"; + ctype = "C相"; + } else if (pttype == 1) { + atype = "AB相"; + btype = "BC相"; + ctype = "CA相"; + } else if (pttype == 2) { + atype = "AB相"; + btype = "BC相"; + ctype = "-"; + + } + DateTime startDate = DateUtil.beginOfDay(DateUtil.parse(startTime)); + DateTime endDate = DateUtil.endOfDay(DateUtil.parse(endTime)); + long day = DateUtil.betweenDay(startDate, endDate, false); + //通用查询条件 + ReportQueryParam param = new ReportQueryParam(); + param.setLineId(lineIndex); + param.setStartTime(DateUtil.format(startDate, "yyyy-MM-dd HH:mm:ss")); + param.setEndTime(DateUtil.format(endDate, "yyyy-MM-dd HH:mm:ss")); + param.setB(day == 0); + + //限值 + OverLimitInfo overLimitData = reportService.getOverLimitData(param); + Overlimit overLimit; + if (type == 0) { + overLimit = lineFeignClient.getOverLimitData(param.getLineId()).getData(); + } else { + overLimit = monitorClient.getOverLimitData(param.getLineId()).getData(); + } + param.setCount(overLimitData.getCount()); + overLimitData.setOverLimitRate(Arrays.asList(overLimit)); + + + if (0 == overLimitData.getOverLimitRate().size()) { + return "datafail"; + } + + String rtfPath = ""; + String picPath = "file/default.jpg"; + boolean flagPath = false; + + Theme theme = themeFeignClient.getTheme().getData(); + if (theme.getRemark().equals("国网")) { + rtfPath = "file/reportModelGW.docx"; + } else if (theme.getRemark().equals("南网")) { + rtfPath = "file/reportModelNW.docx"; + } else if (theme.getRemark().equals("灿能")) { + rtfPath = "file/reportModelCN.docx"; + } else { + rtfPath = "file/reportModel.docx"; + } + + try { + rtfPath = getClass().getClassLoader().getResource(rtfPath).getPath(); + picPath = getClass().getClassLoader().getResource(picPath).getPath(); + rtfPath = rtfPath.replaceAll("%20", " "); + picPath = picPath.replaceAll("%20", " "); + } catch (Exception e1) { + log.info("获取报表发生异常,异常是" + e1.getMessage()); + } + File tmpfile = new File(rtfPath); + if (!tmpfile.exists()) { + return "pathfail"; + } + + InputStream ins = null; + try { + ins = new FileInputStream(rtfPath); + if (null != ins) { + flagPath = true; + } + } catch (FileNotFoundException e) { + flagPath = false; + return "readerror"; + } finally { + if (ins != null) { + ins.close(); + } + } + + Map reportmap = new HashMap();// 报告Map + + reportmap.put("$atype$", atype); + reportmap.put("$btype$", btype); + reportmap.put("$ctype$", ctype); + + Map header = new HashMap(); + if (ObjectUtil.isNotEmpty(file)) { + byte[] bytes = file.getBytes(); + +// byte[] image = (byte[]) session.getAttribute("image"); +// String contentType = (String) session.getAttribute("contentType"); + header.put("width", 400); + header.put("height", 250); + header.put("type", file.getContentType()); + header.put("content", bytes); + } else { + InputStream inStream = null; + byte[] data = null; + try { + inStream = new FileInputStream(new File(picPath)); + data = new byte[inStream.available()]; + inStream.read(data); + } catch (FileNotFoundException e) { + log.info("读取报表信息失败:" + e.getMessage()); + } finally { + if (inStream != null) { + inStream.close(); + } + } + String contentType = "application/x-jpg"; + header.put("width", 400); + header.put("height", 250); + header.put("type", contentType); + header.put("content", data); + } + + reportmap.put("$image$", header); + + getVirtualData(param); + ReportValue voltage1 = (ReportValue) this.listVirtual.get(0).getList().get(0);// 电压幅值 + ReportValue voltage2 = (ReportValue) this.listVirtual.get(0).getList().get(1);// 电压幅值 + ReportValue voltage3 = (ReportValue) this.listVirtual.get(0).getList().get(2);// 电压幅值 + ReportValue current1 = (ReportValue) this.listVirtual.get(1).getList().get(0);// 电流幅值 + ReportValue current2 = (ReportValue) this.listVirtual.get(1).getList().get(1);// 电流幅值 + ReportValue current3 = (ReportValue) this.listVirtual.get(1).getList().get(2);// 电流幅值 + + String strLineBaseName = String.format("%s%s", new String[]{bdname + "_", name}); + String strAnalysis = "";// 分析建议 + String strError = "";// 报表错误 + + /************************************************************** + **** 基波电压/电流有效值表格 + ************************************** + ************************************** + * 一、用基波电压和基波电流做是否有值的判断, 判断策略为所有的基波电压和基波电流都为空 + * ************************************* + * ************************************* 二、基本数据判断 + * ①、(最大值>=最小值、平均值、95%概率值) ②、(平均值>=最小值) ③、(95%概率值>=最小值) + ***************************************************************/ + String strBaseVIResult = ""; + // 基波电压最大值 + + reportmap.put("$B" + "V0" + "X" + "_A$", judgeNull(voltage1.getFmaxValue())); + + reportmap.put("$B" + "V0" + "X" + "_B$", judgeNull(voltage2.getFmaxValue())); + reportmap.put("$B" + "V0" + "X" + "_C$", judgeNull(voltage3.getFmaxValue())); + + // 基波电流最大值 + reportmap.put("$B" + "I0" + "X" + "_A$", judgeNull(current1.getFmaxValue())); + reportmap.put("$B" + "I0" + "X" + "_B$", judgeNull(current2.getFmaxValue())); + reportmap.put("$B" + "I0" + "X" + "_C$", judgeNull(current3.getFmaxValue())); + + /************************************************************** + **** 三张大表基础数据幅值 + ***************************************************************/ + // 基波电压最大值 + reportmap.put("$C" + "V0" + "X" + "_A$", judgeNull(voltage1.getFmaxValue())); + reportmap.put("$C" + "V0" + "X" + "_B$", judgeNull(voltage2.getFmaxValue())); + reportmap.put("$C" + "V0" + "X" + "_C$", judgeNull(voltage3.getFmaxValue())); + + // 基波电流最大值 + reportmap.put("$C" + "I0" + "X" + "_A$", judgeNull(current1.getFmaxValue())); + reportmap.put("$C" + "I0" + "X" + "_B$", judgeNull(current2.getFmaxValue())); + reportmap.put("$C" + "I0" + "X" + "_C$", judgeNull(current3.getFmaxValue())); + + // 基波电压最小值 + reportmap.put("$B" + "V0" + "N" + "_A$", judgeNull(voltage1.getMinValue())); + reportmap.put("$B" + "V0" + "N" + "_B$", judgeNull(voltage2.getMinValue())); + reportmap.put("$B" + "V0" + "N" + "_C$", judgeNull(voltage3.getMinValue())); + + // 基波电流最小值 + reportmap.put("$B" + "I0" + "N" + "_A$", judgeNull(current1.getMinValue())); + reportmap.put("$B" + "I0" + "N" + "_B$", judgeNull(current2.getMinValue())); + reportmap.put("$B" + "I0" + "N" + "_C$", judgeNull(current3.getMinValue())); + + /************************************************************** + **** 三张大表基础数据幅值 + ***************************************************************/ + // 基波电压最小值 + reportmap.put("$C" + "V0" + "N" + "_A$", judgeNull(voltage1.getMinValue())); + reportmap.put("$C" + "V0" + "N" + "_B$", judgeNull(voltage2.getMinValue())); + reportmap.put("$C" + "V0" + "N" + "_C$", judgeNull(voltage3.getMinValue())); + + // 基波电流最小值 + reportmap.put("$C" + "I0" + "N" + "_A$", judgeNull(current1.getMinValue())); + reportmap.put("$C" + "I0" + "N" + "_B$", judgeNull(current2.getMinValue())); + reportmap.put("$C" + "I0" + "N" + "_C$", judgeNull(current3.getMinValue())); + + // 基波电压平均值 + reportmap.put("$B" + "V0" + "E" + "_A$", judgeNull(voltage1.getMeanValue())); + reportmap.put("$B" + "V0" + "E" + "_B$", judgeNull(voltage2.getMeanValue())); + reportmap.put("$B" + "V0" + "E" + "_C$", judgeNull(voltage3.getMeanValue())); + + // 基波电流平均值 + reportmap.put("$B" + "I0" + "E" + "_A$", judgeNull(current1.getMeanValue())); + reportmap.put("$B" + "I0" + "E" + "_B$", judgeNull(current2.getMeanValue())); + reportmap.put("$B" + "I0" + "E" + "_C$", judgeNull(current3.getMeanValue())); + + /************************************************************** + **** 三张大表基础数据幅值 + ***************************************************************/ + // 基波电压平均值 + reportmap.put("$C" + "V0" + "E" + "_A$", judgeNull(voltage1.getMeanValue())); + reportmap.put("$C" + "V0" + "E" + "_B$", judgeNull(voltage2.getMeanValue())); + reportmap.put("$C" + "V0" + "E" + "_C$", judgeNull(voltage3.getMeanValue())); + + // 基波电流平均值 + reportmap.put("$C" + "I0" + "E" + "_A$", judgeNull(current1.getMeanValue())); + reportmap.put("$C" + "I0" + "E" + "_B$", judgeNull(current2.getMeanValue())); + reportmap.put("$C" + "I0" + "E" + "_C$", judgeNull(current3.getMeanValue())); + + // 基波电压cp95值 + reportmap.put("$B" + "V0" + "%" + "_A$", judgeNull(voltage1.getCp95Value())); + reportmap.put("$B" + "V0" + "%" + "_B$", judgeNull(voltage2.getCp95Value())); + reportmap.put("$B" + "V0" + "%" + "_C$", judgeNull(voltage3.getCp95Value())); + + // 基波电流cp95值 + reportmap.put("$B" + "I0" + "%" + "_A$", judgeNull(current1.getCp95Value())); + reportmap.put("$B" + "I0" + "%" + "_B$", judgeNull(current2.getCp95Value())); + reportmap.put("$B" + "I0" + "%" + "_C$", judgeNull(current3.getCp95Value())); + + /************************************************************** + **** 三张大表基础数据幅值 + ***************************************************************/ + // 基波电压cp95值 + reportmap.put("$C" + "V0" + "%" + "_A$", judgeNull(voltage1.getCp95Value())); + reportmap.put("$C" + "V0" + "%" + "_B$", judgeNull(voltage2.getCp95Value())); + reportmap.put("$C" + "V0" + "%" + "_C$", judgeNull(voltage3.getCp95Value())); + + // 基波电流cp95值 + reportmap.put("$C" + "I0" + "%" + "_A$", judgeNull(current1.getCp95Value())); + reportmap.put("$C" + "I0" + "%" + "_B$", judgeNull(current2.getCp95Value())); + reportmap.put("$C" + "I0" + "%" + "_C$", judgeNull(current3.getCp95Value())); + + // 遍历map中的值 + int iCount = 0; + // 判断所取的基波电压、基波电流值是否为null + for (Object value : reportmap.values()) { + if (value == null) + iCount++; + } + // 假如所有的数据都为null,则返回(所选的时间段内未找到数据) + if (iCount == reportmap.size()) + return "exportworld";// 未找到数据 + + // 基本数据判断 + for (int i = 0; i < 3; i++) { + String tmpstrMap = "A"; + switch (i) { + case 0: + tmpstrMap = "A"; + break; + case 1: + tmpstrMap = "B"; + break; + case 2: + tmpstrMap = "C"; + break; + } + try { + // 基波电压 + Double vmaxValue = Double.parseDouble(reportmap.get("$BV0X_" + tmpstrMap + "$").toString()); + Double vminValue = Double.parseDouble(reportmap.get("$BV0N_" + tmpstrMap + "$").toString()); + Double vaveValue = Double.parseDouble(reportmap.get("$BV0E_" + tmpstrMap + "$").toString()); + Double vcp95Value = Double.parseDouble(reportmap.get("$BV0%_" + tmpstrMap + "$").toString()); + // 基波电流 + Double imaxValue = Double.parseDouble(reportmap.get("$BI0X_" + tmpstrMap + "$").toString()); + Double iminValue = Double.parseDouble(reportmap.get("$BI0N_" + tmpstrMap + "$").toString()); + Double iaveValue = Double.parseDouble(reportmap.get("$BI0E_" + tmpstrMap + "$").toString()); + Double icp95Value = Double.parseDouble(reportmap.get("$BI0%_" + tmpstrMap + "$").toString()); + + if (!(vmaxValue >= vminValue && vmaxValue >= vaveValue && vmaxValue >= vcp95Value)) { + strBaseVIResult += "注意:从上表中可以看出" + strLineBaseName + + "基波电压/电流数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + break; + } else if (vaveValue < vminValue) { + strBaseVIResult += "注意:从上表中可以看出" + strLineBaseName + + "基波电压/电流数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + break; + } else if (vcp95Value < vminValue) { + strBaseVIResult += "注意:从上表中可以看出" + strLineBaseName + + "基波电压/电流数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + break; + } else if (!(imaxValue >= iminValue && imaxValue >= iaveValue && imaxValue >= icp95Value)) { + strBaseVIResult += "注意:从上表中可以看出" + strLineBaseName + + "基波电压/电流数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + break; + } else if (iaveValue < iminValue) { + strBaseVIResult += "注意:从上表中可以看出" + strLineBaseName + + "基波电压/电流数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + break; + } else if (icp95Value < iminValue) { + strBaseVIResult += "注意:从上表中可以看出" + strLineBaseName + + "基波电压/电流数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + break; + } + } catch (Exception e) { + strBaseVIResult += "注意:从上表中可以看出" + strLineBaseName + "基波电压/电流数据存在异常(不是数值类型)。"; + break; + } + } + reportmap.put("$BaseVIResult$", strBaseVIResult); + if (!"".equals(strBaseVIResult)) + strError += strBaseVIResult; + + /************************************************************** + **** 所选的时间段内有数据存在则进行其他加载 + ***************************************************************/ + +// Depts dep = R.getCurrentDept(); +// String detpName = dep.getArea(); + reportmap.put("$detpName$", areaName); // 区域名称 + // 获取报告生成时间 + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");// 报告时分秒格式 + String strTime = String.format("%s——%s。", + new String[]{DateUtil.format(startDate, "yyyy年MM月dd日 HH时mm分ss秒"), + DateUtil.format(endDate, "yyyy年MM月dd日 HH时mm分ss秒")}); + reportmap.put("$number$", reportNumber); // 报告编号 + reportmap.put("$titlePoint$", crmName); // 客户名称 + + reportmap.put("$TitleTime$", formatter.format(currentTime)); // 报告生成时间 + reportmap.put("$ReportTitle$", + String.format("对该地区%s电能质量在线监测数据进行分析, 以判断电能质量指标是否满足国标。", new String[]{strLineBaseName}));// 报告标题 + reportmap.put("$ReportTime$", strTime);// 报告分析时间段 + reportmap.put("$RunBaseName$", String.format("以下将对%s电能质量统计数据进行分析,数据包括基波电压/电流、谐波电压/电流、电压偏差、三相电压不平衡度、电压闪变、频率偏差。", + new String[]{strLineBaseName}));// 运行数据分析 + reportmap.put("$BaseVITable$", String.format("报告分析时间段内%s的基波电压/电流分钟统计数据见下表。", new String[]{strLineBaseName}));// 基波电压和电流 + reportmap.put("$VDTable$", String.format("报告分析时间段内%s的电压偏差统计数据见下表。", new String[]{strLineBaseName}));// 供电电压偏差 + reportmap.put("$FRETable$", String.format("报告分析时间段内%s的频率偏差统计数据见下表。", new String[]{strLineBaseName}));// 频率偏差 + reportmap.put("$THETable$", String.format("报告分析时间段内%s的三相电压不平衡度统计数据见下表。", new String[]{strLineBaseName}));// 三相电压不平衡度 + reportmap.put("$PLTTable$", String.format("报告分析时间段内%s的闪变统计数据见下表。", new String[]{strLineBaseName}));// 闪变 + reportmap.put("$RVTable$", + String.format("报告分析时间段内%s的2-25次谐波电压含有率CP95概率值统计数据见下表。", new String[]{strLineBaseName}));// 谐波电压 + reportmap.put("$RITable$", + String.format("报告分析时间段内%s的2-25次谐波电流幅值CP95概率值统计数据见下表。", new String[]{strLineBaseName}));// 谐波电流 + + reportmap.put("$LineName1$", name);// 监测点名称1 + reportmap.put("$LineName2$", name);// 监测点名称2 + reportmap.put("$LineName3$", name);// 监测点名称3 + reportmap.put("$LineName4$", name);// 监测点名称4 + reportmap.put("$LineName5$", name);// 监测点名称5 + + /********************** + **** 数据获取 + ***********************/ + + getPowerData(param); + getFlicker(param, overLimit); + getVdeviation(param, overLimit); + getDistortion(param, overLimit); + getFre(param, overLimit); + getThreePhase(param, overLimit); + getVoltageRate(param, overLimit); + getCurrentRate(param, overLimit); + + ReportValue pst1 = (ReportValue) this.listFlicker.get(0).getList().get(0);// 短闪 + ReportValue pst2 = (ReportValue) this.listFlicker.get(0).getList().get(1);// 短闪 + ReportValue pst3 = (ReportValue) this.listFlicker.get(0).getList().get(2);// 短闪 + ReportValue plt1 = (ReportValue) this.listFlicker.get(1).getList().get(0);// 长闪 + ReportValue plt2 = (ReportValue) this.listFlicker.get(1).getList().get(1);// 长闪 + ReportValue plt3 = (ReportValue) this.listFlicker.get(1).getList().get(2);// 长闪 + + reportmap.put("$LineBase$", String.format("%s%s,CT变比为:%s,PT变比为:%s。", + new String[]{bdname, name, lineDto.getCt(), lineDto.getPt()}));// 监测点基本信息 + + /************************************************************** + **** 三张大表基础数据幅值 + ***************************************************************/ + reportmap.put("$CI_JCD$", bdname); + reportmap.put("$bdTitle$", bdname); + + reportmap.put("$CI_Time$", strTime); + reportmap.put("$CI_JCXL$", name); + reportmap.put("$CI_PT$", lineDto.getPt()); + reportmap.put("$CI_DYDJ$", lineDto.getScale()); + reportmap.put("$CI_CT$", lineDto.getCt()); + reportmap.put("$CI_JZRL$", String.valueOf(lineDto.getStandardCapacity())); + reportmap.put("$CI_DLRL$", String.valueOf(lineDto.getShortCapacity())); + reportmap.put("$CI_XYRL$", String.valueOf(lineDto.getDealCapacity())); + reportmap.put("$CI_SBRL$", String.valueOf(lineDto.getDevCapacity())); + + reportmap.put("$CV_JCD$", bdname); + reportmap.put("$CV_Time$", strTime); + reportmap.put("$CV_JCXL$", name); + reportmap.put("$CV_PT$", lineDto.getPt()); + reportmap.put("$CV_DYDJ$", lineDto.getScale()); + reportmap.put("$CV_CT$", lineDto.getCt()); + reportmap.put("$CV_JZRL$", String.valueOf(lineDto.getStandardCapacity())); + reportmap.put("$CV_DLRL$", String.valueOf(lineDto.getShortCapacity())); + reportmap.put("$CV_XYRL$", String.valueOf(lineDto.getDealCapacity())); + reportmap.put("$CV_SBRL$", String.valueOf(lineDto.getDevCapacity())); + + reportmap.put("$FV_JCD$", bdname); + reportmap.put("$FV_Time$", strTime); + reportmap.put("$FV_JCXL$", name); + reportmap.put("$FV_PT$", lineDto.getPt()); + reportmap.put("$FV_DYDJ$", lineDto.getScale()); + reportmap.put("$FV_CT$", lineDto.getCt()); + reportmap.put("$FV_JZRL$", String.valueOf(lineDto.getStandardCapacity())); + reportmap.put("$FV_DLRL$", String.valueOf(lineDto.getShortCapacity())); + reportmap.put("$FV_XYRL$", String.valueOf(lineDto.getDealCapacity())); + reportmap.put("$FV_SBRL$", String.valueOf(lineDto.getDevCapacity())); + + Double maxValue = 0.00; + Double minValue = 0.00; + Double aveValue = 0.00; + Double cp95Value = 0.00; + Double cp95ValueA = 0.00; + Double cp95ValueB = 0.00; + Double cp95ValueC = 0.00; + Double limit = 0.00; + /************************************************************** + **** 电压偏差(上偏差和下偏差) + ***************************************************************/ + ReportValue vdeviation1 = (ReportValue) this.listVdeviation.get(0).getList().get(0); + ReportValue vdeviation2 = (ReportValue) this.listVdeviation.get(0).getList().get(1); + ReportValue vdeviation3 = (ReportValue) this.listVdeviation.get(0).getList().get(2); + String vdeviationLimit = judgeNull(this.listVdeviation.get(0).getOverLimit());// 获取电压上下偏差的国标限值 + reportmap.put("$VD_L$", vdeviationLimit); + String strResultVdeviationdata = ""; + String tmpstrResultVdeviationdata = ""; + String strResultVdeviationdataValue = ""; + // 获取电压偏差 + String tmpstrMap = ""; + reportmap.put("$VDTX_A$", judgeNull(vdeviation1.getFmaxValue())); + reportmap.put("$VDTN_A$", judgeNull(vdeviation1.getMinValue())); + reportmap.put("$VDTE_A$", judgeNull(vdeviation1.getMeanValue())); + reportmap.put("$VDT%_A$", judgeNull(vdeviation1.getCp95Value())); + reportmap.put("$VDTX_B$", judgeNull(vdeviation2.getFmaxValue())); + reportmap.put("$VDTN_B$", judgeNull(vdeviation2.getMinValue())); + reportmap.put("$VDTE_B$", judgeNull(vdeviation2.getMeanValue())); + reportmap.put("$VDT%_B$", judgeNull(vdeviation2.getCp95Value())); + if (pttype != 2) { + reportmap.put("$VDTX_C$", judgeNull(vdeviation3.getFmaxValue())); + reportmap.put("$VDTN_C$", judgeNull(vdeviation3.getMinValue())); + reportmap.put("$VDTE_C$", judgeNull(vdeviation3.getMeanValue())); + reportmap.put("$VDT%_C$", judgeNull(vdeviation3.getCp95Value())); + } else { + reportmap.put("$VDTX_C$", "-"); + reportmap.put("$VDTN_C$", "-"); + reportmap.put("$VDTE_C$", "-"); + reportmap.put("$VDT%_C$", "-"); + } + + // 值错误判断 + try { + maxValue = Math.abs(Double.parseDouble(vdeviation1.getFmaxValue().toString())); + minValue = Math.abs(Double.parseDouble(vdeviation1.getMinValue().toString())); + aveValue = Math.abs(Double.parseDouble(vdeviation1.getMeanValue().toString())); + cp95Value = Math.abs(Double.parseDouble(vdeviation1.getCp95Value().toString())); + limit = Math.abs(Double.parseDouble(vdeviationLimit)); + } catch (Exception e) { + strResultVdeviationdataValue += "注意:从上表中可以看出" + strLineBaseName + "电压偏差数据存在异常(不是数值类型)。"; + } + + if ("".equals(strResultVdeviationdataValue)) { + if (!(maxValue >= minValue && maxValue >= aveValue && maxValue >= cp95Value)) { + strResultVdeviationdataValue += "注意:从上表中可以看出" + strLineBaseName + + "电压偏差数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } else if (aveValue < minValue) { + strResultVdeviationdataValue += "注意:从上表中可以看出" + strLineBaseName + + "电压偏差数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } else if (cp95Value < minValue) { + strResultVdeviationdataValue += "注意:从上表中可以看出" + strLineBaseName + + "电压偏差数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } + } + // 限值判断 + if (maxValue > limit) { + if (!"".equals(tmpstrResultVdeviationdata)) + tmpstrResultVdeviationdata += "、"; + tmpstrResultVdeviationdata += tmpstrMap + "相"; + } + + // 假如为空则所有的都满足 + if ("".equals(tmpstrResultVdeviationdata)) { + strResultVdeviationdata += "从上表中可以看出" + strLineBaseName + "A、B、C三相电压偏差满足国标限值(10%)的要求。"; + } else { + strAnalysis += tmpstrResultVdeviationdata + "电压偏差不满足国标限值(10%)的要求。"; + strResultVdeviationdata += "从上表中可以看出" + strLineBaseName + tmpstrResultVdeviationdata + + "电压偏差不满足国标限值(10%)的要求。"; + } + + reportmap.put("$ResultVdeviationdata$", strResultVdeviationdata); + reportmap.put("$ResultVdeviationdataValue$", strResultVdeviationdataValue); + strError += strResultVdeviationdataValue; + + /************************************************************** + **** 频率偏差 + ***************************************************************/ + ReportValue valueOfFreValue = (ReportValue) this.listFrequency.get(1).getList().get(0); + String valueOfFreLimit = judgeNull(this.listFrequency.get(1).getOverLimit());// 获取频率偏差国标限值 + reportmap.put("$FRE_L$", valueOfFreLimit); + String strResultFre = ""; + String tmpstrResultFre = ""; + String strResultFreValue = ""; + + reportmap.put("$FREX$", judgeNull(valueOfFreValue.getFmaxValue())); + reportmap.put("$FREN$", judgeNull(valueOfFreValue.getMinValue())); + reportmap.put("$FREE$", judgeNull(valueOfFreValue.getMeanValue())); + reportmap.put("$FRE%$", judgeNull(valueOfFreValue.getCp95Value())); + + /************************************ + **** 三张大表取值 + **************************************/ + reportmap.put("$FV0L$", valueOfFreLimit); + reportmap.put("$FV0X$", judgeNull(valueOfFreValue.getFmaxValue())); + reportmap.put("$FV0N$", judgeNull(valueOfFreValue.getMinValue())); + reportmap.put("$FV0E$", judgeNull(valueOfFreValue.getMeanValue())); + reportmap.put("$FV0%$", judgeNull(valueOfFreValue.getCp95Value())); + + try { + maxValue = Math.abs(Double.parseDouble(valueOfFreValue.getFmaxValue().toString())); + minValue = Math.abs(Double.parseDouble(valueOfFreValue.getMinValue().toString())); + aveValue = Math.abs(Double.parseDouble(valueOfFreValue.getMeanValue().toString())); + cp95Value = Math.abs(Double.parseDouble(valueOfFreValue.getCp95Value().toString())); + limit = Math.abs(Double.parseDouble(valueOfFreLimit)); + } catch (Exception e) { + strResultFreValue += "注意:从上表中可以看出" + strLineBaseName + "频率偏差数据存在异常(不是数值类型)。"; + } + + if (maxValue > limit) { + tmpstrResultFre += "最大值为:" + valueOfFreValue.getFmaxValue().toString() + "Hz"; + } + if (minValue > limit) { + tmpstrResultFre += "最小值为:" + valueOfFreValue.getMinValue().toString() + "Hz"; + } + if (aveValue > limit) { + tmpstrResultFre += "平均值为:" + valueOfFreValue.getMeanValue().toString() + "Hz"; + } + if (cp95Value > limit) { + tmpstrResultFre += "95%概率值为:" + valueOfFreValue.getCp95Value().toString() + "Hz"; + } + + if (!(maxValue >= minValue && maxValue >= aveValue && maxValue >= cp95Value)) { + strResultFreValue += "注意:从上表中可以看出" + strLineBaseName + + "频率偏差数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } else if (aveValue < minValue) { + strResultFreValue += "注意:从上表中可以看出" + strLineBaseName + + "频率偏差数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } else if (cp95Value < minValue) { + strResultFreValue += "注意:从上表中可以看出" + strLineBaseName + + "频率偏差数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } + + if ("".equals(tmpstrResultFre)) { + reportmap.put("$FV0R$", "合格");// 三张大表取值 + strResultFre += "从上表中可以看出" + strLineBaseName + "频率偏差均满足国标限值(±" + valueOfFreLimit + "Hz)的要求。"; + } else { + reportmap.put("$FV0R$", "不合格");// 三张大表取值 + strAnalysis += tmpstrResultFre + ",均不满足国标限值(±" + valueOfFreLimit + "Hz)的要求。"; + strResultFre += "从上表中可以看出" + strLineBaseName + "频率偏差" + tmpstrResultFre + ",均不满足国标限值(±" + valueOfFreLimit + + "Hz)的要求。"; + } + + reportmap.put("$ResultFre$", strResultFre); + reportmap.put("$ResultFreValue$", strResultFreValue); + strError += strResultFreValue; + + /************************************************************** + **** 三相电压不平衡度 + ***************************************************************/ + ReportValue valueOfThree = (ReportValue) this.listThreephase.get(0).getList().get(0); + String valueOfThreeLimit = judgeNull(this.listThreephase.get(0).getOverLimit());// 获取三相电压不平衡度国标限值 + reportmap.put("$THE_L$", valueOfThreeLimit); + String strResultThree = ""; + String tmpstrResultThree = ""; + String strResultThreeValue = ""; + reportmap.put("$THEX$", judgeNull(valueOfThree.getFmaxValue())); + reportmap.put("$THEN$", judgeNull(valueOfThree.getMinValue())); + reportmap.put("$THEE$", judgeNull(valueOfThree.getMeanValue())); + reportmap.put("$THE%$", judgeNull(valueOfThree.getCp95Value())); + + /************************************ + **** 三张大表取值 + **************************************/ + reportmap.put("$TV0L$", valueOfThreeLimit); + reportmap.put("$TV0X$", judgeNull(valueOfThree.getFmaxValue())); + reportmap.put("$TV0N$", judgeNull(valueOfThree.getMinValue())); + reportmap.put("$TV0E$", judgeNull(valueOfThree.getMeanValue())); + reportmap.put("$TV0%$", judgeNull(valueOfThree.getCp95Value())); + + try { + maxValue = Double.parseDouble(valueOfThree.getFmaxValue().toString()); + minValue = Double.parseDouble(valueOfThree.getMinValue().toString()); + aveValue = Double.parseDouble(valueOfThree.getMeanValue().toString()); + cp95Value = Double.parseDouble(valueOfThree.getCp95Value().toString()); + limit = Double.parseDouble(valueOfThreeLimit); + } catch (Exception e) { + strResultThreeValue += "注意:从上表中可以看出" + strLineBaseName + "三相电压不平衡度数据存在异常(不是数值类型)。"; + } + if (cp95Value > limit) { + reportmap.put("$TV0R$", "不合格");// 三张大表取值 + tmpstrResultThree += "三相电压不平衡度95%概率值为:" + valueOfThree.getCp95Value().toString(); + } else { + reportmap.put("$TV0R$", "合格");// 三张大表取值 + } + + if (!(maxValue >= minValue && maxValue >= aveValue && maxValue >= cp95Value)) { + strResultThreeValue += "注意:从上表中可以看出" + strLineBaseName + + "三相电压不平衡度数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } else if (aveValue < minValue) { + strResultThreeValue += "注意:从上表中可以看出" + strLineBaseName + + "三相电压不平衡度数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } else if (cp95Value < minValue) { + strResultThreeValue += "注意:从上表中可以看出" + strLineBaseName + + "三相电压不平衡度数据存在异常( 1、最大值>=最小值、平均值、95%概率值;2、平均值>=最小值;3、95%概率值>=最小值)。"; + } + + if ("".equals(tmpstrResultThree)) { + strResultThree += "三相电压不平衡度根据国标标准测量结果以95%概率值作为判断是否合格的依据,从上表中可以看出" + strLineBaseName + tmpstrResultThree + + ",满足国标限值(" + valueOfThreeLimit + "%)的要求。"; + } else { + strAnalysis += tmpstrResultThree + ",不满足国标限值(" + valueOfThreeLimit + "%)的要求。"; + strResultThree += "三相电压不平衡度根据国标标准测量结果以95%概率值作为判断是否合格的依据,从上表中可以看出" + strLineBaseName + tmpstrResultThree + + ",不满足国标限值(" + valueOfThreeLimit + "%)的要求。"; + } + + reportmap.put("$ResultThree$", strResultThree); + reportmap.put("$ResultThreeValue$", strResultThreeValue); + strError += strResultThreeValue; + + /************************************************************** + **** 电压闪变 + ***************************************************************/ + String valueOfFlickerLimit = judgeNull(this.listFlicker.get(1).getOverLimit());// 获取电压长时闪变的限值 + reportmap.put("$PLT_L$", valueOfFlickerLimit); + String strResultFlicker = ""; + String tmpstrResultFlicker = ""; + String strResultFlickerValue = ""; + String strPhase = "";// 相别,A、B、C + String strType = "";// 长闪还是短闪;S:短闪;L:长闪 + String strValueType = "";// 值类型,最大,最小,平均,95%概率值 + try { + if (Double.parseDouble(plt1.getFmaxValue().toString()) > Double.parseDouble(valueOfFlickerLimit)) { + if (!"".equals(tmpstrResultFlicker)) + tmpstrResultFlicker += ","; + tmpstrResultFlicker += atype + "最大值为:" + plt1.getFmaxValue().toString(); + reportmap.put("$" + "L" + "V0R_" + "A" + "$", "不合格"); + } else { + reportmap.put("$" + "L" + "V0R_" + "A" + "$", "合格"); + } + + if (Double.parseDouble(plt2.getFmaxValue().toString()) > Double.parseDouble(valueOfFlickerLimit)) { + if (!"".equals(tmpstrResultFlicker)) + tmpstrResultFlicker += ","; + tmpstrResultFlicker += btype + "最大值为:" + plt2.getFmaxValue().toString(); + reportmap.put("$" + "L" + "V0R_" + "B" + "$", "不合格"); + } else { + reportmap.put("$" + "L" + "V0R_" + "B" + "$", "合格"); + } + + if (Double.parseDouble(plt3.getFmaxValue().toString()) > Double.parseDouble(valueOfFlickerLimit) && pttype != 2) { + if (!"".equals(tmpstrResultFlicker)) + tmpstrResultFlicker += ","; + tmpstrResultFlicker += ctype + "最大值为:" + plt3.getFmaxValue().toString(); + reportmap.put("$" + "L" + "V0R_" + "C" + "$", "不合格"); + } else { + reportmap.put("$" + "L" + "V0R_" + "C" + "$", "合格"); + } + } catch (Exception e) { + if ("".equals(strResultFlickerValue)) + strResultFlickerValue += "注意:从上表中可以看出" + strLineBaseName + "长时闪变数据存在异常(不是数值类型)。"; + } + + reportmap.put("$PSTX_A$", judgeNull(pst1.getFmaxValue())); + reportmap.put("$PSTN_A$", judgeNull(pst1.getMinValue())); + reportmap.put("$PSTE_A$", judgeNull(pst1.getMeanValue())); + reportmap.put("$PST%_A$", judgeNull(pst1.getCp95Value())); + reportmap.put("$PSTX_B$", judgeNull(pst2.getFmaxValue())); + reportmap.put("$PSTN_B$", judgeNull(pst2.getMinValue())); + reportmap.put("$PSTE_B$", judgeNull(pst2.getMeanValue())); + reportmap.put("$PST%_B$", judgeNull(pst2.getCp95Value())); + if (pttype != 2) { + reportmap.put("$PSTX_C$", judgeNull(pst3.getFmaxValue())); + reportmap.put("$PSTN_C$", judgeNull(pst3.getMinValue())); + reportmap.put("$PSTE_C$", judgeNull(pst3.getMeanValue())); + reportmap.put("$PST%_C$", judgeNull(pst3.getCp95Value())); + } else { + reportmap.put("$PSTX_C$", "-"); + reportmap.put("$PSTN_C$", "-"); + reportmap.put("$PSTE_C$", "-"); + reportmap.put("$PST%_C$", "-"); + } + + reportmap.put("$PLTX_A$", judgeNull(plt1.getFmaxValue())); + reportmap.put("$PLTN_A$", judgeNull(plt1.getMinValue())); + reportmap.put("$PLTE_A$", judgeNull(plt1.getMeanValue())); + reportmap.put("$PLT%_A$", judgeNull(plt1.getCp95Value())); + reportmap.put("$PLTX_B$", judgeNull(plt2.getFmaxValue())); + reportmap.put("$PLTN_B$", judgeNull(plt2.getMinValue())); + reportmap.put("$PLTE_B$", judgeNull(plt2.getMeanValue())); + reportmap.put("$PLT%_B$", judgeNull(plt2.getCp95Value())); + if (pttype != 2) { + reportmap.put("$PLTX_C$", judgeNull(plt3.getFmaxValue())); + reportmap.put("$PLTN_C$", judgeNull(plt3.getMinValue())); + reportmap.put("$PLTE_C$", judgeNull(plt3.getMeanValue())); + reportmap.put("$PLT%_C$", judgeNull(plt3.getCp95Value())); + } else { + reportmap.put("$PLTX_C$", "-"); + reportmap.put("$PLTN_C$", "-"); + reportmap.put("$PLTE_C$", "-"); + reportmap.put("$PLT%_C$", "-"); + } + reportmap.put("$PLT_L$", valueOfFlickerLimit); + + /************************************ + **** 三张大表取值 + **************************************/ + reportmap.put("$" + "L" + "V0" + "X" + "_" + "A" + "$", judgeNull(plt1.getFmaxValue())); + reportmap.put("$" + "L" + "V0" + "E" + "_" + "A" + "$", judgeNull(plt1.getMeanValue())); + reportmap.put("$" + "L" + "V0" + "N" + "_" + "A" + "$", judgeNull(plt1.getMinValue())); + reportmap.put("$" + "L" + "V0" + "%" + "_" + "A" + "$", judgeNull(plt1.getCp95Value())); + reportmap.put("$" + "L" + "V0" + "X" + "_" + "B" + "$", judgeNull(plt2.getFmaxValue())); + reportmap.put("$" + "L" + "V0" + "E" + "_" + "B" + "$", judgeNull(plt2.getMeanValue())); + reportmap.put("$" + "L" + "V0" + "N" + "_" + "B" + "$", judgeNull(plt2.getMinValue())); + reportmap.put("$" + "L" + "V0" + "%" + "_" + "B" + "$", judgeNull(plt2.getCp95Value())); + reportmap.put("$" + "L" + "V0" + "X" + "_" + "C" + "$", judgeNull(plt3.getFmaxValue())); + reportmap.put("$" + "L" + "V0" + "E" + "_" + "C" + "$", judgeNull(plt3.getMeanValue())); + reportmap.put("$" + "L" + "V0" + "N" + "_" + "C" + "$", judgeNull(plt3.getMinValue())); + reportmap.put("$" + "L" + "V0" + "%" + "_" + "C" + "$", judgeNull(plt3.getCp95Value())); + reportmap.put("$LV0%_L$", valueOfFlickerLimit); + + reportmap.put("$" + "S" + "V0" + "X" + "_" + "A" + "$", judgeNull(pst1.getFmaxValue())); + reportmap.put("$" + "S" + "V0" + "E" + "_" + "A" + "$", judgeNull(pst1.getMeanValue())); + reportmap.put("$" + "S" + "V0" + "N" + "_" + "A" + "$", judgeNull(pst1.getMinValue())); + reportmap.put("$" + "S" + "V0" + "%" + "_" + "A" + "$", judgeNull(pst1.getCp95Value())); + reportmap.put("$" + "S" + "V0" + "X" + "_" + "B" + "$", judgeNull(pst2.getFmaxValue())); + reportmap.put("$" + "S" + "V0" + "E" + "_" + "B" + "$", judgeNull(pst2.getMeanValue())); + reportmap.put("$" + "S" + "V0" + "N" + "_" + "B" + "$", judgeNull(pst2.getMinValue())); + reportmap.put("$" + "S" + "V0" + "%" + "_" + "B" + "$", judgeNull(pst2.getCp95Value())); + reportmap.put("$" + "S" + "V0" + "X" + "_" + "C" + "$", judgeNull(pst3.getFmaxValue())); + reportmap.put("$" + "S" + "V0" + "E" + "_" + "C" + "$", judgeNull(pst3.getMeanValue())); + reportmap.put("$" + "S" + "V0" + "N" + "_" + "C" + "$", judgeNull(pst3.getMinValue())); + reportmap.put("$" + "S" + "V0" + "%" + "_" + "C" + "$", judgeNull(pst3.getCp95Value())); + + if ("".equals(tmpstrResultFlicker)) { + strResultFlicker += "电压长时闪变根据国标标准测量结果以最大值、最小值、95%概率值作为判断是否合格的依据,从上表中可以看出" + strLineBaseName + "长时闪变" + + tmpstrResultFlicker + ",其满足国标限值(" + valueOfFlickerLimit + ")的要求。"; + } else { + strAnalysis += "长时闪变" + tmpstrResultFlicker + ",其不满足国标限值(" + valueOfFlickerLimit + ")的要求。"; + strResultFlicker += "电压长时闪变根据国标标准测量结果以最大值、最小值、95%概率值作为判断是否合格的依据,从上表中可以看出" + strLineBaseName + "长时闪变" + + tmpstrResultFlicker + ",其不满足国标限值(" + valueOfFlickerLimit + ")的要求。"; + } + + reportmap.put("$ResultFlicker$", strResultFlicker); + reportmap.put("$ResultFlickerValue$", strResultFlickerValue); + strError += strResultFlickerValue; + + /************************************************************** + **** 电压含有率 + ***************************************************************/ + String strResultVoltageRate = ""; + String tmpstrResultVoltageRate = ""; + String strResultVoltageRateValue = ""; + String strCurrentA, strCurrentB, strCurrentC, strLimit; + // 获取25次谐波 + for (int i = 1; i < 25; i++) { + String strMap = "$RV"; + String strCurrentRate = strMap + (i + 1) + "%"; + + // 基波电压含有率 + strCurrentA = judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(0)).getCp95Value()); + strCurrentB = judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(1)).getCp95Value()); + strCurrentC = judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(2)).getCp95Value()); + strLimit = judgeNull(this.listVoltageRate.get(i).getOverLimit()); + + reportmap.put(strCurrentRate + "_A$", strCurrentA); + reportmap.put(strCurrentRate + "_B$", strCurrentB); + if (pttype != 2) { + reportmap.put(strCurrentRate + "_C$", strCurrentC); + } else { + reportmap.put(strCurrentRate + "_C$", "-"); + } + reportmap.put(strCurrentRate + "_L$", strLimit); + + /************************************ + **** 三张大表取值 + **************************************/ + reportmap.put("$CV" + (i + 1) + "X_A$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(0)).getFmaxValue())); + reportmap.put("$CV" + (i + 1) + "X_B$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(1)).getFmaxValue())); + + reportmap.put("$CV" + (i + 1) + "N_A$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(0)).getMinValue())); + reportmap.put("$CV" + (i + 1) + "N_B$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(1)).getMinValue())); + + reportmap.put("$CV" + (i + 1) + "E_A$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(0)).getMeanValue())); + reportmap.put("$CV" + (i + 1) + "E_B$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(1)).getMeanValue())); + + if (pttype != 2) { + reportmap.put("$CV" + (i + 1) + "X_C$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(2)).getFmaxValue())); + reportmap.put("$CV" + (i + 1) + "N_C$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(2)).getMinValue())); + reportmap.put("$CV" + (i + 1) + "E_C$", + judgeNull(((ReportValue) this.listVoltageRate.get(i).getList().get(2)).getMeanValue())); + reportmap.put("$CV" + (i + 1) + "%_C$", strCurrentC); + } else { + reportmap.put("$CV" + (i + 1) + "X_C$", "-"); + reportmap.put("$CV" + (i + 1) + "N_C$", "-"); + reportmap.put("$CV" + (i + 1) + "E_C$", "-"); + reportmap.put("$CV" + (i + 1) + "%_C$", "-"); + } + + reportmap.put("$CV" + (i + 1) + "%_A$", strCurrentA); + reportmap.put("$CV" + (i + 1) + "%_B$", strCurrentB); + reportmap.put("$CV" + (i + 1) + "L$", strLimit); + + try { + maxValue = Double.parseDouble(strCurrentA); + minValue = Double.parseDouble(strCurrentB); + aveValue = Double.parseDouble(strCurrentC); + limit = Double.parseDouble(strLimit); + } catch (Exception e) { + strResultVoltageRateValue += "注意:从上表中可以看出" + strLineBaseName + "谐波电压含有率95%概率值数据存在异常(不是数值类型)。"; + } + + String tmpstrResult = ""; + if (maxValue > limit) { + if (!"".equals(tmpstrResult)) + tmpstrResult += "、"; + tmpstrResult += "A"; + reportmap.put("$CV" + (i + 1) + "R_A$", "不合格");// 三张大表取值 + } else + reportmap.put("$CV" + (i + 1) + "R_A$", "合格");// 三张大表取值 + if (minValue > limit) { + if (!"".equals(tmpstrResult)) + tmpstrResult += "、"; + tmpstrResult += "B"; + reportmap.put("$CV" + (i + 1) + "R_B$", "不合格");// 三张大表取值 + } else + reportmap.put("$CV" + (i + 1) + "R_B$", "合格");// 三张大表取值 + if (aveValue > limit) { + if (!"".equals(tmpstrResult)) + tmpstrResult += "、"; + tmpstrResult += "C"; + reportmap.put("$CV" + (i + 1) + "R_C$", "不合格");// 三张大表取值 + } else + reportmap.put("$CV" + (i + 1) + "R_C$", "合格");// 三张大表取值 + // 判断单个结论是否存在 + if (!"".equals(tmpstrResult)) { + tmpstrResultVoltageRate += (i + 1) + "次谐波电压含有率95%概率值" + tmpstrResult + ";"; + } + } + + // 假如为空则所有的都满足 + if ("".equals(tmpstrResultVoltageRate)) { + strResultVoltageRate += "从上表中可以看出" + strLineBaseName + "2-25次谐波电压含有率95%概率值均满足国标限值要求。"; + } else { + strAnalysis += tmpstrResultVoltageRate + "2-25次谐波电压含有率95%概率值均不满足国标限值要求。"; + strResultVoltageRate += "从上表中可以看出" + strLineBaseName + tmpstrResultVoltageRate + "均不满足国标限值要求。"; + } + + /************************************************************** + **** 电压总谐波畸变率(THD) + ***************************************************************/ + ReportValue distortion1 = (ReportValue) this.listDistortion.get(0).getList().get(0); + ReportValue distortion2 = (ReportValue) this.listDistortion.get(0).getList().get(1); + ReportValue distortion3 = (ReportValue) this.listDistortion.get(0).getList().get(2); + String distortionLimit = judgeNull(this.listDistortion.get(0).getOverLimit()); + reportmap.put("$DV0%_L$", distortionLimit); + + String strResultDistortion = ""; + String tmpstrResultDistortion = ""; + String strResultDistortionValue = ""; + + reportmap.put("$DV0%_A$", judgeNull(distortion1.getCp95Value())); + reportmap.put("$DV0%_B$", judgeNull(distortion2.getCp95Value())); + reportmap.put("$DV0%_C$", judgeNull(distortion3.getCp95Value())); + + /************************************ + **** 三张大表取值 + **************************************/ + reportmap.put("$TV0X_L$", distortionLimit); + reportmap.put("$TV0X_A$", judgeNull(distortion1.getFmaxValue())); + reportmap.put("$TV0E_A$", judgeNull(distortion1.getMeanValue())); + reportmap.put("$TV0N_A$", judgeNull(distortion1.getMinValue())); + reportmap.put("$TV0%_A$", judgeNull(distortion1.getCp95Value())); + + reportmap.put("$TV0X_B$", judgeNull(distortion2.getFmaxValue())); + reportmap.put("$TV0E_B$", judgeNull(distortion2.getMeanValue())); + reportmap.put("$TV0N_B$", judgeNull(distortion2.getMinValue())); + reportmap.put("$TV0%_B$", judgeNull(distortion2.getCp95Value())); + + reportmap.put("$TV0X_C$", judgeNull(distortion3.getFmaxValue())); + reportmap.put("$TV0E_C$", judgeNull(distortion3.getMeanValue())); + reportmap.put("$TV0N_C$", judgeNull(distortion3.getMinValue())); + reportmap.put("$TV0%_C$", judgeNull(distortion3.getCp95Value())); + + // 值错误判断 + try { + cp95ValueA = Math.abs(Double.parseDouble(distortion1.getCp95Value().toString())); + cp95ValueB = Math.abs(Double.parseDouble(distortion2.getCp95Value().toString())); + cp95ValueC = Math.abs(Double.parseDouble(distortion3.getCp95Value().toString())); + limit = Math.abs(Double.parseDouble(distortionLimit)); + } catch (Exception e) { + strResultDistortionValue += "注意:从上表中可以看出" + strLineBaseName + "电压总谐波畸变率(THD)数据存在异常(不是数值类型)。"; + } + // 限值判断 + if (cp95ValueA > limit) { + if (!"".equals(tmpstrResultDistortion)) + tmpstrResultDistortion += "、"; + tmpstrResultDistortion += atype; + reportmap.put("$TV0R_A$", "不合格");// 三张大表取值 + } else { + reportmap.put("$TV0R_A$", "合格");// 三张大表取值 + } + if (cp95ValueB > limit) { + if (!"".equals(tmpstrResultDistortion)) + tmpstrResultDistortion += "、"; + tmpstrResultDistortion += btype; + reportmap.put("$TV0R_B$", "不合格");// 三张大表取值 + } else { + reportmap.put("$TV0R_B$", "合格");// 三张大表取值 + } + if (cp95ValueC > limit && pttype != 2) { + if (!"".equals(tmpstrResultDistortion)) + tmpstrResultDistortion += "、"; + tmpstrResultDistortion += ctype; + reportmap.put("$TV0R_C$", "不合格");// 三张大表取值 + } else { + reportmap.put("$TV0R_C$", "合格");// 三张大表取值 + } + + // 假如为空则所有的都满足 + if ("".equals(tmpstrResultDistortion)) { + strResultDistortion += "电压总谐波畸变率(THD)95%概率值均满足国标限值要求。"; + } else { + strAnalysis += "电压总谐波畸变率(THD)95%概率值" + tmpstrResultDistortion + "均不满足国标限值要求。"; + strResultDistortion += "电压总谐波畸变率(THD)95%概率值" + tmpstrResultDistortion + "均不满足国标限值要求。"; + } + reportmap.put("$ResultVoltageRate$", strResultVoltageRate + strResultDistortion); + reportmap.put("$ResultVoltageRateValue$", strResultVoltageRateValue + strResultDistortionValue); + strError += strResultVoltageRateValue + strResultDistortionValue; + + /************************************************************** + **** 谐波电流幅值 + ***************************************************************/ + String strResultCurrent = ""; + String tmpstrResultCurrent = ""; + String strResultCurrentValue = ""; + // 获取25次谐波 + for (int i = 1; i < 25; i++) { + String strMap = "$RI"; + String strCurrent = strMap + (i + 1) + "%"; + + // 基波电压含有率 + strCurrentA = judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(0)).getCp95Value()); + strCurrentB = judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(1)).getCp95Value()); + strCurrentC = judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(2)).getCp95Value()); + strLimit = judgeNull(this.listICurrent.get(i).getOverLimit()); + + reportmap.put(strCurrent + "_A$", strCurrentA); + reportmap.put(strCurrent + "_B$", strCurrentB); + reportmap.put(strCurrent + "_C$", strCurrentC); + reportmap.put(strCurrent + "_L$", strLimit); + + /************************************ + **** 三张大表取值 + **************************************/ + reportmap.put("$CI" + (i + 1) + "X_A$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(0)).getFmaxValue())); + reportmap.put("$CI" + (i + 1) + "X_B$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(1)).getFmaxValue())); + reportmap.put("$CI" + (i + 1) + "X_C$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(2)).getFmaxValue())); + + reportmap.put("$CI" + (i + 1) + "N_A$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(0)).getMinValue())); + reportmap.put("$CI" + (i + 1) + "N_B$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(1)).getMinValue())); + reportmap.put("$CI" + (i + 1) + "N_C$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(2)).getMinValue())); + + reportmap.put("$CI" + (i + 1) + "E_A$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(0)).getMeanValue())); + reportmap.put("$CI" + (i + 1) + "E_B$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(1)).getMeanValue())); + reportmap.put("$CI" + (i + 1) + "E_C$", judgeNull(((ReportValue) this.listICurrent.get(i).getList().get(2)).getMeanValue())); + + reportmap.put("$CI" + (i + 1) + "%_A$", strCurrentA); + reportmap.put("$CI" + (i + 1) + "%_B$", strCurrentB); + reportmap.put("$CI" + (i + 1) + "%_C$", strCurrentC); + reportmap.put("$CI" + (i + 1) + "L$", strLimit); + + try { + maxValue = Double.parseDouble(strCurrentA); + minValue = Double.parseDouble(strCurrentB); + aveValue = Double.parseDouble(strCurrentC); + limit = Double.parseDouble(strLimit); + } catch (Exception e) { + strResultCurrentValue += "注意:从上表中可以看出" + strLineBaseName + "谐波电流幅值95%概率值数据存在异常(不是数值类型)。"; + } + + String tmpstrResult = ""; + if (maxValue > limit) { + if (!"".equals(tmpstrResult)) + tmpstrResult += "、"; + tmpstrResult += "A"; + reportmap.put("$CI" + (i + 1) + "R_A$", "不合格");// 三张大表取值 + } else + reportmap.put("$CI" + (i + 1) + "R_A$", "合格");// 三张大表取值 + if (minValue > limit) { + if (!"".equals(tmpstrResult)) + tmpstrResult += "、"; + tmpstrResult += "B"; + reportmap.put("$CI" + (i + 1) + "R_B$", "不合格");// 三张大表取值 + } else + reportmap.put("$CI" + (i + 1) + "R_B$", "合格");// 三张大表取值 + if (aveValue > limit) { + if (!"".equals(tmpstrResult)) + tmpstrResult += "、"; + tmpstrResult += "C"; + reportmap.put("$CI" + (i + 1) + "R_C$", "不合格");// 三张大表取值 + } else + reportmap.put("$CI" + (i + 1) + "R_C$", "合格");// 三张大表取值 + // 判断单个结论是否存在 + if (!"".equals(tmpstrResult)) { + tmpstrResultCurrent += (i + 1) + "次谐波电流幅值95%概率值" + tmpstrResult + ";"; + } + } + + // 假如为空则所有的都满足 + if ("".equals(tmpstrResultCurrent)) { + strResultCurrent += "从上表中可以看出" + strLineBaseName + "2-25次谐波电流幅值95%概率值均满足国标限值要求。"; + } else { + strAnalysis += tmpstrResultCurrent + "均不满足国标限值要求。"; + strResultCurrent += "从上表中可以看出" + strLineBaseName + tmpstrResultCurrent + "均不满足国标限值要求。"; + } + + reportmap.put("$ResultCurrent$", strResultCurrent); + reportmap.put("$ResultCurrentValue$", strResultCurrentValue); + strError += strResultCurrentValue; + + // 测试结果填写 + reportmap.put("$ResultTitle$", String.format("通过对(%s——%s)时间段内%s电能质量统计数据分析后得出以下结论:", + new String[]{DateUtil.format(startDate, "yyyy年MM月dd日 HH时mm分ss秒"), + DateUtil.format(endDate, "yyyy年MM月dd日 HH时mm分ss秒"),strLineBaseName}));// 结论标题 + reportmap.put("$Result_VD$", String.format("(1)电压偏差:%s", new String[]{strResultVdeviationdata}));// 电压偏差 + reportmap.put("$Result_FRE$", String.format("(2)频率偏差:%s", new String[]{strResultFre}));// 频率偏差 + reportmap.put("$Result_THE$", String.format("(3)三相电压不平衡度:%s", new String[]{strResultThree}));// 三相电压不平衡度 + reportmap.put("$Result_FIC$", String.format("(4)电压长时闪变:%s", new String[]{strResultFlicker}));// 电压长时闪变 + reportmap.put("$Result_VOL$", String.format("(5)谐波电压:%s", new String[]{strResultVoltageRate}));// 谐波电压 + reportmap.put("$Result_CUR$", String.format("(6)谐波电流:%s", new String[]{strResultCurrent}));// 谐波电流 + // 分析建议填写 + if (!"".equals(strAnalysis) || !"".equals(strError)) { + reportmap.put("$Analysis$", "根据统计数据结果分析,监测点为:" + name + "," + strAnalysis + strError);// 分析建议 + } else { + reportmap.put("$Analysis$", "根据统计数据结果分析,监测点为:" + name + ",电能质量数据满足国标限值要求。");// 分析建议 + } + + /************************************ + **** 三张大表取值 有功:0-11 无功:12-23 视在:24-31 基波有功汇总:32-35 基波无功汇总:36-39 + * 基波视在汇总:40-43 功率因数:44-46 + **************************************/ + ReportValue powerDto1 = (ReportValue) this.listPower.get(0).getList().get(3); + ReportValue powerDto2 = (ReportValue) this.listPower.get(1).getList().get(3); + ReportValue powerDto3 = (ReportValue) this.listPower.get(2).getList().get(3); + ReportValue powerDto4 = (ReportValue) this.listPower.get(3).getList().get(3); + reportmap.put("$BF0X$", judgeNull(powerDto1.getFmaxValue())); + reportmap.put("$BF0N$", judgeNull(powerDto1.getMinValue())); + reportmap.put("$BF0E$", judgeNull(powerDto1.getMeanValue())); + + reportmap.put("$NF0X$", judgeNull(powerDto2.getFmaxValue())); + reportmap.put("$NF0N$", judgeNull(powerDto2.getMinValue())); + reportmap.put("$NF0E$", judgeNull(powerDto2.getMeanValue())); + + reportmap.put("$SF0X$", judgeNull(powerDto3.getFmaxValue())); + reportmap.put("$SF0N$", judgeNull(powerDto3.getMinValue())); + reportmap.put("$SF0E$", judgeNull(powerDto3.getMeanValue())); + + reportmap.put("$YF0X$", judgeNull(powerDto4.getFmaxValue())); + reportmap.put("$YF0N$", judgeNull(powerDto4.getMinValue())); + reportmap.put("$YF0E$", judgeNull(powerDto4.getMeanValue())); + formatter = new SimpleDateFormat("yyyyMMddHHmmss");// 报告时分秒格式 + + WordUtil2 oRTF = new WordUtil2(); + try { + oRTF.getWord(rtfPath, reportmap, name + formatter.format(currentTime) + ".docx", response, session); + } catch (Exception e) { + log.error("获取报告发生异常,异常是" + e.getMessage()); + } + + return "success"; + } + + /** + * 解析base64,返回图片所在路径 + * + * @param base64Info + * @return + */ + @SuppressWarnings("restriction") + private String decodeBase64(byte[] base64Info) { + if (base64Info.length == 0) { + return null; + } + BASE64Encoder decoder = new BASE64Encoder(); + + return decoder.encode(base64Info); + } + + private void transformData(List list, List listValue, List listOverlimit, boolean... b) { + int offset = b[0] ? 3 : 1; + offset = (b.length == 2 && !b[1]) ? 4 : offset; + int i = 0; + + for (int index = 0; index < listValue.size(); index += offset) { + if (i == listOverlimit.size()) { + break; + } + ReportTarget reportTarget = new ReportTarget(); + reportTarget.setList(listValue.subList(index, index + offset)); + Float overLimit = listOverlimit.get(i).getOverLimit(); + reportTarget.setOverLimit(overLimit); + + switch (listOverlimit.get(i).getCode()) { + case 1: + for (int k = 0; k < reportTarget.getList().size(); k++) { + if (null == reportTarget.getList().get(k).getFmaxValue()) { + break; + } else if (reportTarget.getList().get(k).getFmaxValue().floatValue() > overLimit.floatValue()) { + reportTarget.setPass(EnumPass.NOPASS.getCode()); + break; + } else { + reportTarget.setPass(EnumPass.PASS.getCode()); + } + } + break; + case 2: + for (int k = 0; k < reportTarget.getList().size(); k++) { + if (null == reportTarget.getList().get(k).getMinValue()) { + break; + } else if (reportTarget.getList().get(k).getMinValue().floatValue() > overLimit.floatValue()) { + reportTarget.setPass(EnumPass.NOPASS.getCode()); + break; + } else { + reportTarget.setPass(EnumPass.PASS.getCode()); + } + } + break; + case 3: + for (int k = 0; k < reportTarget.getList().size(); k++) { + if (null == reportTarget.getList().get(k).getMeanValue()) { + break; + } else if (reportTarget.getList().get(k).getMeanValue().floatValue() > overLimit.floatValue()) { + reportTarget.setPass(EnumPass.NOPASS.getCode()); + break; + } else { + reportTarget.setPass(EnumPass.PASS.getCode()); + } + } + break; + case 4: + for (int k = 0; k < reportTarget.getList().size(); k++) { + if (null == reportTarget.getList().get(k).getCp95Value()) { + break; + } else if (reportTarget.getList().get(k).getCp95Value().floatValue() > overLimit.floatValue()) { + reportTarget.setPass(EnumPass.NOPASS.getCode()); + break; + } else { + reportTarget.setPass(EnumPass.PASS.getCode()); + } + } + break; + default: + break; + } + + i++; + list.add(reportTarget); + } + } + + // 基波幅值 + public void getVirtualData(ReportQueryParam param) { + + List listVirtual = reportService.getVirtualData(param); + + List list = new ArrayList<>(); + + for (int i = 0; i < 3; i++) { + Pass pass = new Pass(null); + list.add(pass); + } + + this.listVirtual = new ArrayList<>(); + + transformData(this.listVirtual, listVirtual, list, true); + + + } + + // 功率 + public void getPowerData(ReportQueryParam param) { + List listPower = reportService.getPowerData(param); + + List list = new ArrayList<>(); + + for (int i = 0; i < 4; i++) { + Pass pass = new Pass(null); + list.add(pass); + } + this.listPower = new ArrayList<>(); + transformData(this.listPower, listPower, list, true, false); + } + + // 闪变 + public void getFlicker(ReportQueryParam param, Overlimit overLimit) { + List listFlicker = reportService.getFlickerData(param); + List list = new ArrayList<>(); + for (int i = 0; i < 2; i++) { + Pass pass; + if (i == 1) { + pass = new Pass(overLimit.getFlicker(), EnumPass.MAX.getCode()); + } else { + pass = new Pass(null); + } + list.add(pass); + } + this.listFlicker = new ArrayList<>(); + transformData(this.listFlicker, listFlicker, list, true); + } + + // 电压偏差 + public void getVdeviation(ReportQueryParam param, Overlimit overLimit) { + List listVdeviation = reportService.getVdeviation(param); + List list = new ArrayList<>(); + for (int i = 0; i < 2; i++) { + Pass pass; + pass = new Pass(overLimit.getVoltageDev(), EnumPass.MAX.getCode()); + list.add(pass); + } + this.listVdeviation = new ArrayList<>(); + transformData(this.listVdeviation, listVdeviation, list, true); + } + + // 畸变率 + public void getDistortion(ReportQueryParam param, Overlimit overLimit) { + List listDistortion = reportService.getDistortionData(param); + List list = new ArrayList<>(); + for (int i = 0; i < 2; i++) { + Pass pass; + + if (i == 0) { + pass = new Pass(overLimit.getUaberrance(), EnumPass.MAX.getCode()); + } else { + pass = new Pass(null); + } + + list.add(pass); + } + this.listDistortion = new ArrayList<>(); + transformData(this.listDistortion, listDistortion, list, true); + } + + // 频率 + public void getFre(ReportQueryParam param, Overlimit overLimit) { + List listFrequency = reportService.getFrequencyData(param); + + List list = new ArrayList<>(); + + for (int i = 0; i < 2; i++) { + Pass pass; + if (i == 1) { + pass = new Pass(overLimit.getFreqDev(), EnumPass.MAX.getCode()); + } else { + pass = new Pass(null); + } + list.add(pass); + } + + this.listFrequency = new ArrayList<>(); + transformData(this.listFrequency, listFrequency, list, false); + } + + + // 三相不平衡 + public void getThreePhase(ReportQueryParam param, Overlimit overLimit) { + List listThreephase = reportService.getThreephase(param); + + List list = new ArrayList<>(); + + for (int i = 0; i < 8; i++) { + Pass pass; + + if (i == 0) { + pass = new Pass(overLimit.getUbalance(), EnumPass.CP95.getCode()); + } else { + pass = new Pass(null); + } + + list.add(pass); + } + + this.listThreephase = new ArrayList<>(); + transformData(this.listThreephase, listThreephase, list, false); + } + + + // 谐波电流 + public void getCurrentRate(ReportQueryParam param, Overlimit overLimit) { + List listICurrent = reportService.getICurrent(param); + + List list = new ArrayList<>(); + List iHarmList = getIHarmList(overLimit); + for (int i = 0; i < 50; i++) { + Pass pass; + if (i 0) { + pass = new Pass(iHarmList.get(i - 1), + EnumPass.CP95.getCode()); + } else { + pass = new Pass(null); + } + list.add(pass); + } + + this.listICurrent = new ArrayList<>(); + transformData(this.listICurrent, listICurrent, list, true); + } + // 谐波电压 + public void getVoltageRate(ReportQueryParam param, Overlimit overLimit) { + List listVoltageRate = reportService.getVoltageRate(param); + + List list = new ArrayList<>(); + List vHarmList = getVHarmList(overLimit); + for (int i = 0; i < 51; i++) { + Pass pass; + + if (i == 0) { + pass = new Pass(null); + } else if (i == 50) { + pass = new Pass(overLimit.getUaberrance(), EnumPass.MAX.getCode()); + } else if (i < vHarmList.size() + 1) { + pass = new Pass(vHarmList.get(i - 1), + EnumPass.CP95.getCode()); + } else { + pass = new Pass(null); + } + + list.add(pass); + } + + this.listVoltageRate = new ArrayList<>(); + transformData(this.listVoltageRate, listVoltageRate, list, true); + } + public String judgeNull(Float result) { + return (result == null) ? "/" : result.toString(); + } + + /** + * 谐波电流限值 + * @param overLimit + * @return + */ + public List getIHarmList(Overlimit overLimit) { + List list = new ArrayList<>(); + list.add(overLimit.getIharm2()); + list.add(overLimit.getIharm3()); + list.add(overLimit.getIharm4()); + list.add(overLimit.getIharm5()); + list.add(overLimit.getIharm6()); + list.add(overLimit.getIharm7()); + list.add(overLimit.getIharm8()); + list.add(overLimit.getIharm9()); + list.add(overLimit.getIharm10()); + list.add(overLimit.getIharm11()); + list.add(overLimit.getIharm12()); + list.add(overLimit.getIharm13()); + list.add(overLimit.getIharm14()); + list.add(overLimit.getIharm15()); + list.add(overLimit.getIharm16()); + list.add(overLimit.getIharm17()); + list.add(overLimit.getIharm18()); + list.add(overLimit.getIharm19()); + list.add(overLimit.getIharm20()); + list.add(overLimit.getIharm21()); + list.add(overLimit.getIharm22()); + list.add(overLimit.getIharm23()); + list.add(overLimit.getIharm24()); + list.add(overLimit.getIharm25()); + return list; + } + + /** + * 谐波电压限值 + * @return + */ + public List getVHarmList(Overlimit overLimit) { + List list = new ArrayList<>(); + list.add(overLimit.getUharm2()); + list.add(overLimit.getUharm3()); + list.add(overLimit.getUharm4()); + list.add(overLimit.getUharm5()); + list.add(overLimit.getUharm6()); + list.add(overLimit.getUharm7()); + list.add(overLimit.getUharm8()); + list.add(overLimit.getUharm9()); + list.add(overLimit.getUharm10()); + list.add(overLimit.getUharm11()); + list.add(overLimit.getUharm12()); + list.add(overLimit.getUharm13()); + list.add(overLimit.getUharm14()); + list.add(overLimit.getUharm15()); + list.add(overLimit.getUharm16()); + list.add(overLimit.getUharm17()); + list.add(overLimit.getUharm18()); + list.add(overLimit.getUharm19()); + list.add(overLimit.getUharm20()); + list.add(overLimit.getUharm21()); + list.add(overLimit.getUharm22()); + list.add(overLimit.getUharm23()); + list.add(overLimit.getUharm24()); + list.add(overLimit.getUharm25()); + return list; + } +} diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/RStatDataIDMapper.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/RStatDataIDMapper.java new file mode 100644 index 000000000..9ddcf978e --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/RStatDataIDMapper.java @@ -0,0 +1,16 @@ +package com.njcn.harmonic.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.harmonic.pojo.po.day.RStatDataIDPO; + +/** + *

+ * Mapper 接口 + *

+ * + * @author wr + * @since 2023-04-17 + */ +public interface RStatDataIDMapper extends BaseMapper { + +} diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/ReportMapper.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/ReportMapper.java new file mode 100644 index 000000000..15047c89b --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/ReportMapper.java @@ -0,0 +1,130 @@ +package com.njcn.harmonic.mapper; + +import com.njcn.harmonic.pojo.param.ReportQueryParam; +import com.njcn.harmonic.pojo.vo.ReportValue; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 谐波报告查询 + */ +public interface ReportMapper { + /** + * 获取电流有效值 + * @return + */ + List getVirtualDataI(@Param("param") ReportQueryParam param); + + /** + * 获取电压有效值 + * @return + */ + List getVirtualDataV(@Param("param") ReportQueryParam param); + + /** + * CP95条数 + * @param param + * @return + */ + Integer getTotalCP95Day(@Param("param")ReportQueryParam param); + /** + * CP95条数 + * @param param + * @return + */ + Integer getTotalPltCP95Day(@Param("param")ReportQueryParam param); + /** + * CP95条数 + * @param param + * @return + */ + Integer getTotalPstCP95Day(@Param("param")ReportQueryParam param); + + + List getVVirtualData(@Param("param")ReportQueryParam param); + + /** + * 获取有功功率 + * @param param + * @return + */ + List getPowerP(@Param("param")ReportQueryParam param); + + /** + * 无功功率 + * @param param + * @return + */ + List getPowerQ(@Param("param")ReportQueryParam param); + + /** + * 视在功率 + * @param param + * @return + */ + List getPowerS(@Param("param")ReportQueryParam param); + + /** + * 功率因数 + * @param param + * @return + */ + List getPF(@Param("param")ReportQueryParam param); + + /** + * 短时闪变 + * @param param + * @return + */ + List getFlickerData(@Param("param")ReportQueryParam param); + + /** + * 长时闪变 + * @param param + * @return + */ + List getLFlickerData(@Param("param")ReportQueryParam param); + + /** + * 电压负偏差 + * @param param + * @return + */ + List getUVdeviationData(@Param("param")ReportQueryParam param); + + /** + * 电压正偏差 + * @param param + * @return + */ + List getLVdeviationData(@Param("param")ReportQueryParam param); + + /** + * 获取电压畸变率 + * @param param + * @return + */ + List getDistortionDataV(@Param("param")ReportQueryParam param); + + /** + * 获取电流畸变率 + * @param param + * @return + */ + List getDistortionDataI(@Param("param")ReportQueryParam param); + + /** + *频率 + * @param param + * @return + */ + List getFrequencyData(@Param("param")ReportQueryParam param); + + /** + * + * @param param + * @return + */ + List getDEVFrequencyData(@Param("param")ReportQueryParam param); +} diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/mapping/RStatDataIDMapper.xml b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/mapping/RStatDataIDMapper.xml new file mode 100644 index 000000000..5cbe60639 --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/mapping/RStatDataIDMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/mapping/ReportMapper.xml b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/mapping/ReportMapper.xml new file mode 100644 index 000000000..8ea2a3998 --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/mapper/mapping/ReportMapper.xml @@ -0,0 +1,905 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/ReportService.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/ReportService.java new file mode 100644 index 000000000..67795d509 --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/ReportService.java @@ -0,0 +1,83 @@ +package com.njcn.harmonic.service; + +import com.njcn.harmonic.pojo.param.ReportQueryParam; +import com.njcn.harmonic.pojo.po.report.OverLimitInfo; +import com.njcn.harmonic.pojo.vo.ReportValue; + +import java.util.List; + +/** + * 谐波报告 + */ +public interface ReportService { + + /** + * + * @param param + * @return + */ + OverLimitInfo getOverLimitData(ReportQueryParam param); + + /** + * 基波增幅 + * @param param + * @return + */ + List getVirtualData(ReportQueryParam param); + + /** + * 功率 + * @param param + * @return + */ + List getPowerData(ReportQueryParam param); + + /** + * 闪变 + * @param param + * @return + */ + List getFlickerData(ReportQueryParam param); + + /** + * 电压偏差 + * @param param + * @return + */ + List getVdeviation(ReportQueryParam param); + + /** + * 畸变率 + * @param param + * @return + */ + List getDistortionData(ReportQueryParam param); + + /** + * 频率 + * @param param + * @return + */ + List getFrequencyData(ReportQueryParam param); + + /** + * 三相不平衡 + * @param param + * @return + */ + List getThreephase(ReportQueryParam param); + + /** + * 谐波电流 + * @param param + * @return + */ + List getICurrent(ReportQueryParam param); + + /** + * 谐波电压 + * @param param + * @return + */ + List getVoltageRate(ReportQueryParam param); +} diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/RegroupData.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/RegroupData.java new file mode 100644 index 000000000..829a0639e --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/RegroupData.java @@ -0,0 +1,44 @@ +package com.njcn.harmonic.service.impl; + +import com.njcn.harmonic.pojo.vo.ReportValue; + +import java.util.List; + +public class RegroupData { + public static void regroupData(List list, boolean... b) { + if (1 == b.length || (2 == b.length && b[1] == false)) { + if (0 < list.size()) { + return; + } + } + + Float value = null; + int length = b[0] ? 3 : 1; + + length = (b.length == 2 && !b[1]) ? 4 : length; + + for (int i = 0; i < length; i++) { + String str = null; + + if (b[0]) { + switch (i) { + case 0: + str = "A"; + break; + case 1: + str = "B"; + break; + case 2: + str = "C"; + break; + case 3: + str = "T"; + break; + } + } + + ReportValue reportValue = new ReportValue(str, value, value, value, value); + list.add(reportValue); + } + } +} diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/ReportServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/ReportServiceImpl.java new file mode 100644 index 000000000..b7e64433a --- /dev/null +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/ReportServiceImpl.java @@ -0,0 +1,484 @@ +package com.njcn.harmonic.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.njcn.harmonic.mapper.RStatDataIDMapper; +import com.njcn.harmonic.mapper.ReportMapper; +import com.njcn.harmonic.pojo.po.RStatDataVD; +import com.njcn.harmonic.pojo.po.day.RStatDataIDPO; +import com.njcn.harmonic.pojo.param.ReportQueryParam; +import com.njcn.harmonic.pojo.po.report.OverLimitInfo; +import com.njcn.harmonic.pojo.vo.ReportValue; +import com.njcn.harmonic.service.IRStatDataVDService; +import com.njcn.harmonic.service.ReportService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +@Service +@AllArgsConstructor +public class ReportServiceImpl implements ReportService { + + private final ReportMapper reportMapper; + private final IRStatDataVDService statDataVDService; + private final RStatDataIDMapper rStatDataIDMapper; + + @Override + public OverLimitInfo getOverLimitData(ReportQueryParam param) { + + + OverLimitInfo overLimitInfo = new OverLimitInfo(); + + //查询时间段内共有多少条记录,并*0.95取整处理,用来计算CP95值 降序*0.05进一位计算 + double count = 0; + double pstCount = 0; + double pltCount = 0; + if (param.getB()) { + count = Math.ceil(1); + pltCount = Math.ceil(1); + pstCount = Math.ceil(1); + } else { + count = Math.ceil(reportMapper.getTotalCP95Day(param).intValue() * 0.05); + pltCount = Math.ceil(reportMapper.getTotalPltCP95Day(param).intValue() * 0.05); + pstCount = Math.ceil(reportMapper.getTotalPstCP95Day(param).intValue() * 0.05); + } + overLimitInfo.setCount(count); + overLimitInfo.setPltCount(pltCount); + overLimitInfo.setPstCount(pstCount); + return overLimitInfo; + } + + @Override + public List getVirtualData(ReportQueryParam param) { + List list = new ArrayList<>(); + + // 获取电流有效值 + List listI = reportMapper.getVirtualDataI(param); + //获取电压有效值 + List listV = reportMapper.getVirtualDataV(param); + //获取线电压有效值 + List listVV = reportMapper.getVVirtualData(param); + + RegroupData.regroupData(listV, true); + RegroupData.regroupData(listI, true); + RegroupData.regroupData(listVV, true); + list.addAll(listV); + list.addAll(listI); + list.addAll(listVV); + + return list; + } + + @Override + public List getPowerData(ReportQueryParam param) { + List list = new ArrayList<>(); + //获取有功功率 + List listP = reportMapper.getPowerP(param); + //获取无功功率 + List listQ = reportMapper.getPowerQ(param); + //获取视在功率 + List listS = reportMapper.getPowerS(param); + //获取功率因数 + List listF = reportMapper.getPF(param); + + RegroupData.regroupData(listP, true, false); + RegroupData.regroupData(listQ, true, false); + RegroupData.regroupData(listS, true, false); + RegroupData.regroupData(listF, true, false); + list.addAll(listP); + list.addAll(listQ); + list.addAll(listS); + list.addAll(listF); + return list; + } + + @Override + public List getFlickerData(ReportQueryParam param) { + List list = new ArrayList<>(); + + //短时闪变 + List listFlicker = reportMapper.getFlickerData(param); + //长时闪变 + List listLFlicker = reportMapper.getLFlickerData(param); + + RegroupData.regroupData(listFlicker, true); + RegroupData.regroupData(listLFlicker, true); + list.addAll(listFlicker); + list.addAll(listLFlicker); + + return list; + } + + @Override + public List getVdeviation(ReportQueryParam param) { + List list = new ArrayList<>(); + + //获取电压偏差 + List listU = reportMapper.getUVdeviationData(param); + List listL = reportMapper.getLVdeviationData(param); + + RegroupData.regroupData(listU, true); + RegroupData.regroupData(listL, true); + list.addAll(listU); + list.addAll(listL); + return list; + } + + @Override + public List getDistortionData(ReportQueryParam param) { + List list = new ArrayList<>(); + //获取电压畸变率 + List listU = reportMapper.getDistortionDataV(param); + //获取电流畸变率 + List listI = reportMapper.getDistortionDataI(param); + + //添加之前判断数据库是否有数据,如果没有数据模拟数据添加到集合中 + RegroupData.regroupData(listU, true); + RegroupData.regroupData(listI, true); + list.addAll(listU); + list.addAll(listI); + + return list; + } + + @Override + public List getFrequencyData(ReportQueryParam param) { + List list = new ArrayList<>(); + + List listFre = reportMapper.getFrequencyData(param); + List listFreDEV = reportMapper.getDEVFrequencyData(param); + + + RegroupData.regroupData(listFre, true); + RegroupData.regroupData(listFreDEV, true); + list.addAll(listFre); + list.addAll(listFreDEV); + return list; + } + + @Override + public List getThreephase(ReportQueryParam param) { + List list = new ArrayList<>(); + //电压三相不平衡度 + List listV = dataV(param, Arrays.asList("T"),1, 5,true,0); + //电流三相不平衡度 + List listI = dataI(param, Arrays.asList("T"),1, 5,true,0); + + if (CollUtil.isNotEmpty(listV)) { + list.addAll(listV); + } else { + regroupData(list); + } + + if (CollUtil.isNotEmpty(listI)) { + list.addAll(listI); + } else { + regroupData(list); + } + return list; + } + + @Override + public List getICurrent(ReportQueryParam param) { + List list = new ArrayList<>(); + + //获取电流幅值,包含基波 + List listI = dataI(param, Arrays.asList("A","B","C"),1, 51,false,0); + if (CollUtil.isEmpty(listI)) { + for (int i = 0; i < 50; i++) { + RegroupData.regroupData(list, true, true); + } + } else { + list.addAll(listI); + } + return list; + } + + @Override + public List getVoltageRate(ReportQueryParam param) { + List list = new ArrayList<>(); + + //获取基波电压幅值,单位kV + List listV = dataV(param, Arrays.asList("A","B","C"),0, 1,true,5); + + if (CollUtil.isEmpty(listV)) { + RegroupData.regroupData(list, true, true); + } else { + list.addAll(listV); + } + + //获取电压含有率,不包含基波 + List listRate = dataV(param, Arrays.asList("A","B","C"),2, 51,false,1); + + if (CollUtil.isEmpty(listRate)) { + for (int i = 0; i < 49; i++) { + RegroupData.regroupData(list, true, true); + } + } else { + list.addAll(listRate); + } + + //获取电压畸变率 + List listU = reportMapper.getDistortionDataV(param); + RegroupData.regroupData(listU, true); + list.addAll(listU); + return list; + } + + private void regroupData(List list) { + for (int i = 0; i < 4; i++) { + List list1 = new ArrayList<>(); + RegroupData.regroupData(list1, false); + list.addAll(list1); + } + } + + /** + * 电压信息 + * @param param 查询条件 + * @param valueTypes 区分类别 例如"A","B","C" + * @param num 循环开始 + * @param size 循环结束 + * @param fly 否是启用获取属性电压 + * @param index 获取属性位置名称 + * @return + */ + private List dataV(ReportQueryParam param,List valueTypes,Integer num,Integer size,Boolean fly,Integer index){ + List rStatDataVDS = statDataVDService.list(new LambdaQueryWrapper() + .eq(RStatDataVD::getLineId, param.getLineId()) + .in(CollUtil.isNotEmpty(valueTypes),RStatDataVD::getPhasicType,valueTypes) + .ge(StrUtil.isNotBlank(param.getStartTime()), RStatDataVD::getTime, DateUtil.beginOfDay(DateUtil.parse(param.getStartTime()))) + .le(StrUtil.isNotBlank(param.getEndTime()), RStatDataVD::getTime, DateUtil.endOfDay(DateUtil.parse(param.getEndTime()))) + ); + String max = "MAX"; + String avg = "AVG"; + String min = "MIN"; + String cp95 = "CP95"; + List a = new ArrayList<>(); + Map> collect = rStatDataVDS.stream().collect(Collectors.groupingBy(RStatDataVD::getPhasicType)); + collect.forEach((key, value) -> { + Map> valueTypeMap = value.stream().collect(Collectors.groupingBy(RStatDataVD::getValueType)); + + for (int i = num; i < size; i++) { + ReportValue reportValue = new ReportValue(); + String attribute=""; + if(fly){ + if (index==0){ + attribute = attributeV(i); + }else{ + attribute = attributeV(index); + } + }else{ + attribute = "v"+i; + } + + if (valueTypeMap.containsKey(max)) { + List aa = reflectDataV(valueTypeMap.get(max), max,attribute); + reportValue.setPhaseType(key); + Float maxNum = aa.stream().distinct().max(Float::compareTo).get(); + reportValue.setFmaxValue(maxNum); + } + if (valueTypeMap.containsKey(avg)) { + List aa = reflectDataV(valueTypeMap.get(avg), avg,attribute); + reportValue.setPhaseType(key); + Double avgNum = aa.stream().distinct().collect(Collectors.averagingDouble(Float::doubleValue)); + reportValue.setMeanValue(avgNum.floatValue()); + } + if (valueTypeMap.containsKey(min)) { + List aa = reflectDataV(valueTypeMap.get(min), min,attribute); + reportValue.setPhaseType(key); + double minNum = aa.stream().distinct().min(Float::compareTo).get(); + reportValue.setMinValue((float) minNum); + } + if (valueTypeMap.containsKey(cp95)) { + List aa = reflectDataV(valueTypeMap.get(cp95), cp95,attribute); + reportValue.setPhaseType(key); + List cp95Num = aa.stream().distinct().sorted(Comparator.comparing(Float::doubleValue).reversed()).collect(Collectors.toList()); + reportValue.setCp95Value(cp95Num.get(0).floatValue()); + } + a.add(reportValue); + } + }); + return a; + } + + /** + * 电压反射取属性值 + * + * @param value + * @param name + * @return + */ + private List reflectDataV(List value, String name,String attribute) { + Field field = null; + try { + field = RStatDataVD.class.getDeclaredField(attribute); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + field.setAccessible(true); + + Field finalField = field; + return value.stream().filter(x -> x.getValueType().equals(name)).map(temp -> { + BigDecimal o = null; + try { + o = (BigDecimal) finalField.get(temp); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + return o.floatValue(); + }).collect(Collectors.toList()); + } + + /** + * 电流信息 + * @param param + * @return + */ + private List dataI(ReportQueryParam param,List valueTypes,Integer num,Integer size,Boolean fly,Integer index){ + List rStatDataVDS = rStatDataIDMapper.selectList(new LambdaQueryWrapper() + .eq(RStatDataIDPO::getLineId, param.getLineId()) + .in(CollUtil.isNotEmpty(valueTypes),RStatDataIDPO::getPhaseType,valueTypes) + .ge(StrUtil.isNotBlank(param.getStartTime()), RStatDataIDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(param.getStartTime()))) + .le(StrUtil.isNotBlank(param.getEndTime()), RStatDataIDPO::getTime, DateUtil.endOfDay(DateUtil.parse(param.getEndTime()))) + ); + String max = "MAX"; + String avg = "AVG"; + String min = "MIN"; + String cp95 = "CP95"; + List a = new ArrayList<>(); + Map> collect = rStatDataVDS.stream().collect(Collectors.groupingBy(RStatDataIDPO::getPhaseType)); + collect.forEach((key, value) -> { + Map> valueTypeMap = value.stream().collect(Collectors.groupingBy(RStatDataIDPO::getValueType)); + + for (int i = num; i < size; i++) { + ReportValue reportValue = new ReportValue(); + String attribute=""; + if(fly){ + if (index==0){ + attribute = attributeI(i); + }else{ + attribute = attributeI(index); + } + }else{ + attribute = "i"+i; + } + if (valueTypeMap.containsKey(max)) { + List aa = reflectDataI(valueTypeMap.get(max), max,attribute); + reportValue.setPhaseType(key); + Float maxNum = aa.stream().distinct().max(Float::compareTo).get(); + reportValue.setFmaxValue(maxNum); + } + if (valueTypeMap.containsKey(avg)) { + List aa = reflectDataI(valueTypeMap.get(avg), avg,attribute); + reportValue.setPhaseType(key); + Double avgNum = aa.stream().distinct().collect(Collectors.averagingDouble(Float::doubleValue)); + reportValue.setMeanValue(avgNum.floatValue()); + } + if (valueTypeMap.containsKey(min)) { + List aa = reflectDataI(valueTypeMap.get(min), min,attribute); + reportValue.setPhaseType(key); + double minNum = aa.stream().distinct().min(Float::compareTo).get(); + reportValue.setMinValue((float) minNum); + } + if (valueTypeMap.containsKey(cp95)) { + List aa = reflectDataI(valueTypeMap.get(cp95), cp95,attribute); + reportValue.setPhaseType(key); + List cp95Num = aa.stream().distinct().sorted(Comparator.comparing(Float::doubleValue).reversed()).collect(Collectors.toList()); + reportValue.setCp95Value(cp95Num.get(0).floatValue()); + } + a.add(reportValue); + } + }); + return a; + } + + /** + * 电流反射取属性值 + * + * @param value + * @param name + * @return + */ + private List reflectDataI(List value, String name, String attribute) { + Field field = null; + try { + field = RStatDataIDPO.class.getDeclaredField(attribute); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + field.setAccessible(true); + Field finalField = field; + return value.stream().filter(x -> x.getValueType().equals(name)).map(temp -> { + Double o = null; + try { + o = (Double) finalField.get(temp); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + return o.floatValue(); + }).collect(Collectors.toList()); + } + + /** + * 获取属性电压 + * @param i + * @return + */ + private String attributeV(Integer i) { + String str=null; + switch (i) { + case 1: + str = "vUnbalance"; + break; + case 2: + str = "vPos"; + break; + case 3: + str = "vNeg"; + break; + case 4: + str = "vZero"; + break; + case 5: + str = "v1"; + break; + default: + break; + } + return str; + } + /** + * 获取属性电流 + * @param i + * @return + */ + private String attributeI(Integer i) { + String str=null; + switch (i) { + case 1: + str = "iUnbalance"; + break; + case 2: + str = "iPos"; + break; + case 3: + str = "iNeg"; + break; + case 4: + str = "iZero"; + break; + default: + break; + } + return str; + } +} diff --git a/pqs-harmonic/harmonic-boot/src/main/resources/file/default.jpg b/pqs-harmonic/harmonic-boot/src/main/resources/file/default.jpg new file mode 100644 index 000000000..0cb20c96c Binary files /dev/null and b/pqs-harmonic/harmonic-boot/src/main/resources/file/default.jpg differ diff --git a/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModel.docx b/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModel.docx new file mode 100644 index 000000000..5039b2457 Binary files /dev/null and b/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModel.docx differ diff --git a/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelCN.docx b/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelCN.docx new file mode 100644 index 000000000..c2cee8df6 Binary files /dev/null and b/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelCN.docx differ diff --git a/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelGW.docx b/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelGW.docx new file mode 100644 index 000000000..bc8453ca1 Binary files /dev/null and b/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelGW.docx differ diff --git a/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelNW.docx b/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelNW.docx new file mode 100644 index 000000000..533f86ad8 Binary files /dev/null and b/pqs-harmonic/harmonic-boot/src/main/resources/file/reportModelNW.docx differ