Browse Source

Add 添加实时负荷导出

Yue 2 years ago
parent
commit
4ec02cafc8

+ 477 - 403
VB_DSM_V2.1/vbdsm-common/vbdsm-base/src/main/java/cn/vbdsm/common/utils/ExcelUtil.java

@@ -1,5 +1,10 @@
 package cn.vbdsm.common.utils;
 
+import com.alibaba.fastjson.JSONObject;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.hssf.util.HSSFColor;
+
+import javax.core.common.utils.NumberUtils;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.reflect.Field;
@@ -12,423 +17,492 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import javax.core.common.utils.NumberUtils;
-
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFCellStyle;
-import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
-import org.apache.poi.hssf.usermodel.HSSFComment;
-import org.apache.poi.hssf.usermodel.HSSFFont;
-import org.apache.poi.hssf.usermodel.HSSFPatriarch;
-import org.apache.poi.hssf.usermodel.HSSFRichTextString;
-import org.apache.poi.hssf.usermodel.HSSFRow;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.HSSFColor;
 /**
  * Excel表格操作类
+ *
+ * @param <T>
  * @author zhouzhengdong
- * @date 2015-09-01 15:01
  * @version 1.0
- * @param <T>
+ * @date 2015-09-01 15:01
  */
 public class ExcelUtil<T> {
 
-	/**
-	 * 这是一个通用的方法,利用了JAVA的反射机制,可以将放置在JAVA集合中并且符号一定条件的数据以EXCEL 的形式输出到指定IO设备上
-	 *
-	 * @param title
-	 *            表格标题名
-	 * @param headers
-	 *            表格属性列名数组
-	 * @param dataset
-	 *            需要显示的数据集合,集合中一定要放置符合javabean风格的类的对象。此方法支持的
-	 *            javabean属性的数据类型有基本数据类型及String,Date,byte[](图片数据)
-	 * @param out
-	 *            与输出设备关联的流对象,可以将EXCEL文档导出到本地文件或者网络中
-	 * @param pattern
-	 *            如果有时间数据,设定输出格式。默认为"yyy-MM-dd"
-	 */
-	@SuppressWarnings({ "deprecation", "unchecked" ,"rawtypes"})
-	public void exportExcel(String title, String[] headers,
-			Collection<T> dataset, OutputStream out, String pattern) {
-		// 声明一个工作薄
-		HSSFWorkbook workbook = new HSSFWorkbook();
-		// 生成一个表格
-		HSSFSheet sheet = workbook.createSheet(title);
-		// 设置表格默认列宽度为15个字节
+    /**
+     * 添加单元格
+     *
+     * @param row
+     * @param style
+     * @param column
+     * @param value
+     */
+    public static void addCell(HSSFRow row, HSSFCellStyle style, int column, String value) {
+        HSSFCell cell = row.createCell(column);
+        cell.setCellStyle(style);
+        cell.setCellValue(value);
+    }
+
+    /**
+     * 添加单元格
+     *
+     * @param row
+     * @param style
+     * @param column
+     * @param value
+     */
+    public static void addCell(HSSFRow row, HSSFCellStyle style, int column, double value) {
+        HSSFCell cell = row.createCell(column);
+        cell.setCellStyle(style);
+        cell.setCellValue(value);
+    }
+
+    /**
+     * 这是一个通用的方法,利用了JAVA的反射机制,可以将放置在JAVA集合中并且符号一定条件的数据以EXCEL 的形式输出到指定IO设备上
+     *
+     * @param title   表格标题名
+     * @param headers 表格属性列名数组
+     * @param dataset 需要显示的数据集合,集合中一定要放置符合javabean风格的类的对象。此方法支持的
+     *                javabean属性的数据类型有基本数据类型及String,Date,byte[](图片数据)
+     * @param out     与输出设备关联的流对象,可以将EXCEL文档导出到本地文件或者网络中
+     * @param pattern 如果有时间数据,设定输出格式。默认为"yyy-MM-dd"
+     */
+    @SuppressWarnings({"deprecation", "unchecked", "rawtypes"})
+    public void exportExcel(String title, String[] headers,
+                            Collection<T> dataset, OutputStream out, String pattern) {
+        // 声明一个工作薄
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        // 生成一个表格
+        HSSFSheet sheet = workbook.createSheet(title);
+        // 设置表格默认列宽度为15个字节
 //		sheet.setDefaultColumnWidth((short) 15);
-		// 生成一个样式
-		HSSFCellStyle style = workbook.createCellStyle();
-		// 设置这些样式
-		style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
-		style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
-		style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
-		style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
-		style.setBorderRight(HSSFCellStyle.BORDER_THIN);
-		style.setBorderTop(HSSFCellStyle.BORDER_THIN);
-		style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
-		// 生成一个字体
-		HSSFFont font = workbook.createFont();
-		font.setColor(HSSFColor.VIOLET.index);
-		font.setFontHeightInPoints((short) 12);
-		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
-		// 把字体应用到当前的样式
-		style.setFont(font);
-		// 生成并设置另一个样式
-		HSSFCellStyle style2 = workbook.createCellStyle();
-		style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
-		style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
-		style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
-		style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
-		style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
-		// 生成另一个字体
-		HSSFFont font2 = workbook.createFont();
-		font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
-		// 把字体应用到当前的样式
-		style2.setFont(font2);
+        // 生成一个样式
+        HSSFCellStyle style = workbook.createCellStyle();
+        // 设置这些样式
+        style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
+        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
+        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        // 生成一个字体
+        HSSFFont font = workbook.createFont();
+        font.setColor(HSSFColor.VIOLET.index);
+        font.setFontHeightInPoints((short) 12);
+        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+        // 把字体应用到当前的样式
+        style.setFont(font);
+        // 生成并设置另一个样式
+        HSSFCellStyle style2 = workbook.createCellStyle();
+        style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
+        style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
+        style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 生成另一个字体
+        HSSFFont font2 = workbook.createFont();
+        font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
+        // 把字体应用到当前的样式
+        style2.setFont(font2);
 
-		// 声明一个画图的顶级管理器
-		HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
-		// 定义注释的大小和位置,详见文档
-		HSSFComment comment = patriarch.createComment(new HSSFClientAnchor(0,
-				0, 0, 0, (short) 4, 2, (short) 6, 5));
-		// 设置注释内容
+        // 声明一个画图的顶级管理器
+        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+        // 定义注释的大小和位置,详见文档
+        HSSFComment comment = patriarch.createComment(new HSSFClientAnchor(0,
+                0, 0, 0, (short) 4, 2, (short) 6, 5));
+        // 设置注释内容
 //		comment.setString(new HSSFRichTextString("可以在POI中添加注释!"));
-		// 设置注释作者,当鼠标移动到单元格上是可以在状态栏中看到该内容.
+        // 设置注释作者,当鼠标移动到单元格上是可以在状态栏中看到该内容.
 //		comment.setAuthor("leno");
 
-		// 产生表格标题行
-		HSSFRow row = sheet.createRow(0);
-		for (short i = 0; i < headers.length; i++) {
-			HSSFCell cell = row.createCell(i);
-			cell.setCellStyle(style);
-			HSSFRichTextString text = new HSSFRichTextString(headers[i]);
-			cell.setCellValue(text);
-		}
+        // 产生表格标题行
+        HSSFRow row = sheet.createRow(0);
+        for (short i = 0; i < headers.length; i++) {
+            HSSFCell cell = row.createCell(i);
+            cell.setCellStyle(style);
+            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
+            cell.setCellValue(text);
+        }
+
+        // 遍历集合数据,产生数据行
+        Iterator<T> it = dataset.iterator();
+        int index = 0;
+        while (it.hasNext()) {
+            index++;
+            row = sheet.createRow(index);
+            T t = it.next();
+            // 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
+            Field[] fields = t.getClass().getDeclaredFields();
+            for (short i = 0; i < fields.length; i++) {
+                HSSFCell cell = row.createCell(i);
+                cell.setCellStyle(style2);
+                Field field = fields[i];
+                String fieldName = field.getName();
+                String getMethodName = "get"
+                        + fieldName.substring(0, 1).toUpperCase()
+                        + fieldName.substring(1);
+                try {
+                    Class tCls = t.getClass();
+                    Method getMethod = tCls.getMethod(getMethodName
+                    );
+                    Object value = getMethod.invoke(t);
+                    // 判断值的类型后进行强制类型转换
+                    String textValue = null;
+                    if (value instanceof Long) {
+                        String date = DateUtil.long2Str(Long.valueOf(value.toString()), pattern);
+                        textValue = date;
+                    } else if (value instanceof byte[]) {
+                        // 有图片时,设置行高为60px;
+                        row.setHeightInPoints(60);
+                        // 设置图片所在列宽度为80px,注意这里单位的一个换算
+                        sheet.setColumnWidth(i, (short) (35.7 * 80));
+                        byte[] bsValue = (byte[]) value;
+                        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0,
+                                1023, 255, (short) 6, index, (short) 6, index);
+                        anchor.setAnchorType(2);
+                        patriarch.createPicture(anchor, workbook.addPicture(
+                                bsValue, HSSFWorkbook.PICTURE_TYPE_JPEG));
+                    } else {
+                        // 其它数据类型都当作字符串简单处理
+                        textValue = value.toString();
+                    }
+                    // 如果不是图片数据,就利用正则表达式判断textValue是否全部由数字组成
+                    if (textValue != null) {
+                        Pattern p = Pattern.compile("^//d+(//.//d+)?$");
+                        Matcher matcher = p.matcher(textValue);
+                        if (matcher.matches()) {
+                            // 是数字当作double处理
+                            cell.setCellValue(Double.parseDouble(textValue));
+                        } else {
+                            HSSFRichTextString richString = new HSSFRichTextString(
+                                    textValue);
+                            HSSFFont font3 = workbook.createFont();
+                            font3.setColor(HSSFColor.BLUE.index);
+                            richString.applyFont(font3);
+                            cell.setCellValue(richString);
+                        }
+                    }
+                } catch (SecurityException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                } catch (NoSuchMethodException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                } catch (IllegalArgumentException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                } catch (IllegalAccessException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                } catch (InvocationTargetException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+
+        }
+        try {
+            workbook.write(out);
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+
+    /**
+     * 写入EXCEL
+     *
+     * @param headerMap 表头字段
+     * @param dataset   表格数据   (Map)
+     * @param title     标题
+     * @return
+     * @throws NoSuchMethodException
+     * @throws SecurityException
+     * @throws IllegalAccessException
+     * @throws IllegalArgumentException
+     * @throws InvocationTargetException
+     * @author tanpeng
+     */
+    public HSSFWorkbook writeExcelForMap(Map<String, String> headerMap, List<T> dataset, String title) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+        // 声明一个工作薄
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        // 生成一个表格
+        HSSFSheet sheet = workbook.createSheet(title);
+        // 设置表格默认列宽度为15个字节
+        sheet.setDefaultColumnWidth((short) 15);
+        // 生成一个样式
+        HSSFCellStyle style = workbook.createCellStyle();
+        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 生成一个字体
+        HSSFFont font = workbook.createFont();
+        //font.setColor(HSSFColor.VIOLET.index);
+        font.setFontHeightInPoints((short) 12);
+        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+
+        // 把字体应用到当前的样式
+        style.setFont(font);
+        // 生成并设置另一个样式
+        HSSFCellStyle style2 = workbook.createCellStyle();
+        //style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
+        style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
+        style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 生成另一个字体
+        HSSFFont font2 = workbook.createFont();
+        font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
+        // 把字体应用到当前的样式
+        style2.setFont(font2);
+
+        //设置表头
+        HSSFRow row = setHeader(sheet, style, headerMap);
+
+        // 遍历集合数据,产生数据行
+        int index = 0;
+        for (T t : dataset) {
+            index++;//
+            row = sheet.createRow(index);
+            row.setHeight((short) 320);
+            Map<String, Object> m = (Map<String, Object>) t;
+            int cellIndex = 0;
+            for (String key : headerMap.keySet()) {
+                HSSFCell cell = row.createCell(cellIndex);
+                //cell.setCellStyle(style2);
+                if (null != m.get(key)) {
+                    cell.setCellValue(m.get(key).toString());
+                } else {
+                    cell.setCellValue("");
+                }
+                cellIndex++;
+            }
+        }
+        return workbook;
+    }
+
+    /**
+     * 写入EXCEL
+     *
+     * @param headerMap 表头字段
+     * @param dataset   表格数据
+     * @param title     标题
+     * @return
+     * @throws NoSuchMethodException
+     * @throws SecurityException
+     * @throws IllegalAccessException
+     * @throws IllegalArgumentException
+     * @throws InvocationTargetException
+     * @author grxie
+     */
+    public HSSFWorkbook writeExcel(Map<String, String> headerMap, Collection<T> dataset, String title) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+        // 声明一个工作薄
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        // 生成一个表格
+        HSSFSheet sheet = workbook.createSheet(title);
+        // 设置表格默认列宽度为15个字节
+        sheet.setDefaultColumnWidth((short) 15);
+        // 生成一个样式
+        HSSFCellStyle style = workbook.createCellStyle();
+        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 生成一个字体
+        HSSFFont font = workbook.createFont();
+        //font.setColor(HSSFColor.VIOLET.index);
+        font.setFontHeightInPoints((short) 12);
+        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+
+        // 把字体应用到当前的样式
+        style.setFont(font);
+        // 生成并设置另一个样式
+        HSSFCellStyle style2 = workbook.createCellStyle();
+        style2.setFillForegroundColor(HSSFColor.WHITE.index);
+        style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
+        style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 生成另一个字体
+        HSSFFont font2 = workbook.createFont();
+        font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
+        // 把字体应用到当前的样式
+        style2.setFont(font2);
+
+        //设置表头
+        HSSFRow row = setHeader(sheet, style, headerMap);
+
+        // 遍历集合数据,产生数据行
+        Iterator<T> it = dataset.iterator();
+        int index = 0;
+        while (it.hasNext()) {
+            index++;//
+            row = sheet.createRow(index);
+            row.setHeight((short) 320);
+            T t = it.next();
+            JSONObject obj = JSONObject.parseObject(JSONObject.toJSONString(t));
+            // 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
+            // Field[] fields = t.getClass().getDeclaredFields();
+            int cellIndex = 0;
+            for (Map.Entry<String, String> enrty : headerMap.entrySet()) {
+                String key = enrty.getKey();
+
+                if (!obj.containsKey(key)) {//判断字段是否在列表中
+                    continue;
+                } else {
+                    cellIndex++;
+                }
+                HSSFCell cell = row.createCell(cellIndex - 1);
+                cell.setCellStyle(style2);
+                Object value = obj.get(key);
+                // 判断值的类型后进行强制类型转换
+                String textValue = "";
+                if (null != value)
+                    textValue = value.toString();
+                // 如果不是图片数据,就利用正则表达式判断textValue是否全部由数字组成
+                if (textValue != null) {
+                    Pattern p = Pattern.compile("^//d+(//.//d+)?$");
+                    Matcher matcher = p.matcher(textValue);
+                    if (matcher.matches()) {
+                        // 是数字当作double处理
+                        cell.setCellValue(NumberUtils.round(Double.parseDouble(textValue), 2));
+                    } else {
+                        HSSFRichTextString richString = new HSSFRichTextString(textValue);
+                        HSSFFont font3 = workbook.createFont();
+                        font3.setColor(HSSFColor.BLACK.index);
+                        richString.applyFont(font3);
+                        cell.setCellValue(richString);
+                    }
+                }
+            }
+        }
+        return workbook;
+    }
+
+    public HSSFWorkbook writeExcel1(Map<String, String> headerMap, Collection<T> dataset, String title) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+        // 声明一个工作薄
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        // 生成一个表格
+        HSSFSheet sheet = workbook.createSheet(title);
+        // 设置表格默认列宽度为15个字节
+        sheet.setDefaultColumnWidth((short) 15);
+        // 生成一个样式
+        HSSFCellStyle style = workbook.createCellStyle();
+        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 生成一个字体
+        HSSFFont font = workbook.createFont();
+        //font.setColor(HSSFColor.VIOLET.index);
+        font.setFontHeightInPoints((short) 12);
+        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+
+        // 把字体应用到当前的样式
+        style.setFont(font);
+        // 生成并设置另一个样式
+        HSSFCellStyle style2 = workbook.createCellStyle();
+        style2.setFillForegroundColor(HSSFColor.WHITE.index);
+        style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
+        style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
+        style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+        // 生成另一个字体
+        HSSFFont font2 = workbook.createFont();
+        font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
+        // 把字体应用到当前的样式
+        style2.setFont(font2);
+
+        //设置表头
+        HSSFRow row = setHeader(sheet, style, headerMap);
 
-		// 遍历集合数据,产生数据行
-		Iterator<T> it = dataset.iterator();
-		int index = 0;
-		while (it.hasNext()) {
-			index++;
-			row = sheet.createRow(index);
-			T t = (T) it.next();
-			// 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
-			Field[] fields = t.getClass().getDeclaredFields();
-			for (short i = 0; i < fields.length; i++) {
-				HSSFCell cell = row.createCell(i);
-				cell.setCellStyle(style2);
-				Field field = fields[i];
-				String fieldName = field.getName();
-				String getMethodName = "get"
-						+ fieldName.substring(0, 1).toUpperCase()
-						+ fieldName.substring(1);
-				try {
-					Class tCls = t.getClass();
-					Method getMethod = tCls.getMethod(getMethodName,
-							new Class[] {});
-					Object value = getMethod.invoke(t, new Object[] {});
-					// 判断值的类型后进行强制类型转换
-					String textValue = null;
-					if (value instanceof Long) {
-						String date = DateUtil.long2Str(Long.valueOf(value.toString()),pattern);
-						textValue = date;
-					} else if (value instanceof byte[]) {
-						// 有图片时,设置行高为60px;
-						row.setHeightInPoints(60);
-						// 设置图片所在列宽度为80px,注意这里单位的一个换算
-						sheet.setColumnWidth(i, (short) (35.7 * 80));
-						byte[] bsValue = (byte[]) value;
-						HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0,
-								1023, 255, (short) 6, index, (short) 6, index);
-						anchor.setAnchorType(2);
-						patriarch.createPicture(anchor, workbook.addPicture(
-								bsValue, HSSFWorkbook.PICTURE_TYPE_JPEG));
-					} else {
-						// 其它数据类型都当作字符串简单处理
-						textValue = value.toString();
-					}
-					// 如果不是图片数据,就利用正则表达式判断textValue是否全部由数字组成
-					if (textValue != null) {
-						Pattern p = Pattern.compile("^//d+(//.//d+)?$");
-						Matcher matcher = p.matcher(textValue);
-						if (matcher.matches()) {
-							// 是数字当作double处理
-							cell.setCellValue(Double.parseDouble(textValue));
-						} else {
-							HSSFRichTextString richString = new HSSFRichTextString(
-									textValue);
-							HSSFFont font3 = workbook.createFont();
-							font3.setColor(HSSFColor.BLUE.index);
-							richString.applyFont(font3);
-							cell.setCellValue(richString);
-						}
-					}
-				} catch (SecurityException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				} catch (NoSuchMethodException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				} catch (IllegalArgumentException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				} catch (IllegalAccessException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				} catch (InvocationTargetException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				} finally {
-					// 清理资源
-				}
-			}
+        // 遍历集合数据,产生数据行
+        Iterator<T> it = dataset.iterator();
+        int index = 0;
+        while (it.hasNext()) {
+            index++;//
+            row = sheet.createRow(index);
+            row.setHeight((short) 320);
+            T t = it.next();
+            // 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
+            Field[] fields = t.getClass().getDeclaredFields();
+            int cellIndex = 0;
+            for (Map.Entry<String, String> enrty : headerMap.entrySet()) {
+                String key = enrty.getKey();
+                for (short i = 0; i < fields.length; i++) {
 
-		}
-		try {
-			workbook.write(out);
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
+                    Field field = fields[i];
+                    String fieldName = field.getName();
+                    if (!key.equals(fieldName)) {//判断字段是否在列表中
+                        continue;
+                    } else {
+                        cellIndex++;
+                    }
+                    HSSFCell cell = row.createCell(cellIndex - 1);
+                    cell.setCellStyle(style2);
+                    String getMethodName = "get"
+                            + fieldName.substring(0, 1).toUpperCase()
+                            + fieldName.substring(1);
+                    Class tCls = t.getClass();
+                    Method getMethod = tCls.getMethod(getMethodName);
+                    Object value = getMethod.invoke(t);
+                    // 判断值的类型后进行强制类型转换
+                    String textValue = "";
+                    if (null != value)
+                        textValue = value.toString();
+                    // 如果不是图片数据,就利用正则表达式判断textValue是否全部由数字组成
+                    if (textValue != null) {
+                        Pattern p = Pattern.compile("^//d+(//.//d+)?$");
+                        Matcher matcher = p.matcher(textValue);
+                        if (matcher.matches()) {
+                            // 是数字当作double处理
+                            cell.setCellValue(NumberUtils.round(Double.parseDouble(textValue), 2));
+                        } else {
+                            HSSFRichTextString richString = new HSSFRichTextString(textValue);
+                            HSSFFont font3 = workbook.createFont();
+                            font3.setColor(HSSFColor.BLACK.index);
+                            richString.applyFont(font3);
+                            cell.setCellValue(richString);
+                        }
+                    }
+                }
+            }
+        }
+        return workbook;
+    }
 
-	}
-	
-	/**
-	 * 写入EXCEL
-	 * 
-	 * @author tanpeng
-	 * @param headerMap	表头字段
-	 * @param dataset	表格数据   (Map)
-	 * @param title	标题
-	 * @return
-	 * @throws NoSuchMethodException
-	 * @throws SecurityException
-	 * @throws IllegalAccessException
-	 * @throws IllegalArgumentException
-	 * @throws InvocationTargetException
-	 */
-	public HSSFWorkbook writeExcelForMap(Map<String, String> headerMap, List<T> dataset, String title) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-		// 声明一个工作薄
-		HSSFWorkbook workbook = new HSSFWorkbook();
-		// 生成一个表格
-		HSSFSheet sheet = workbook.createSheet(title);
-		// 设置表格默认列宽度为15个字节
-		sheet.setDefaultColumnWidth((short) 15);
-		// 生成一个样式
-		HSSFCellStyle style = workbook.createCellStyle();
-		style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
-		// 生成一个字体
-		HSSFFont font = workbook.createFont();
-		//font.setColor(HSSFColor.VIOLET.index);
-		font.setFontHeightInPoints((short) 12);
-		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
-		
-		// 把字体应用到当前的样式
-		style.setFont(font);
-		// 生成并设置另一个样式
-		HSSFCellStyle style2 = workbook.createCellStyle();
-		//style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
-		style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
-		style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
-		style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
-		style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
-		// 生成另一个字体
-		HSSFFont font2 = workbook.createFont();
-		font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
-		// 把字体应用到当前的样式
-		style2.setFont(font2);
-		
-		//设置表头
-		HSSFRow row = setHeader(sheet, style, headerMap);
-		
-		// 遍历集合数据,产生数据行
-		int index = 0;
-		for(T t:dataset ){
-			index++;//
-			row = sheet.createRow(index);
-			row.setHeight((short)320);
-			Map<String,Object> m = (Map<String,Object>)t;
-			int cellIndex = 0;
-			for(String key:headerMap.keySet()){
-				HSSFCell cell = row.createCell(cellIndex);
-				//cell.setCellStyle(style2);
-				if(null != m.get(key)){
-					cell.setCellValue(m.get(key).toString());
-				}else{
-					cell.setCellValue("");
-				}
-				cellIndex++;
-			}
-		}
-		return workbook;
-	}
-	
-	/**
-	 * 写入EXCEL
-	 * 
-	 * @author grxie
-	 * @param headerMap	表头字段
-	 * @param dataset	表格数据
-	 * @param title	标题
-	 * @return
-	 * @throws NoSuchMethodException
-	 * @throws SecurityException
-	 * @throws IllegalAccessException
-	 * @throws IllegalArgumentException
-	 * @throws InvocationTargetException
-	 */
-	public HSSFWorkbook writeExcel(Map<String, String> headerMap, Collection<T> dataset, String title) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-		// 声明一个工作薄
-		HSSFWorkbook workbook = new HSSFWorkbook();
-		// 生成一个表格
-		HSSFSheet sheet = workbook.createSheet(title);
-		// 设置表格默认列宽度为15个字节
-		sheet.setDefaultColumnWidth((short) 15);
-		// 生成一个样式
-		HSSFCellStyle style = workbook.createCellStyle();
-		style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
-		// 生成一个字体
-		HSSFFont font = workbook.createFont();
-		//font.setColor(HSSFColor.VIOLET.index);
-		font.setFontHeightInPoints((short) 12);
-		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
-		
-		// 把字体应用到当前的样式
-		style.setFont(font);
-		// 生成并设置另一个样式
-		HSSFCellStyle style2 = workbook.createCellStyle();
-		style2.setFillForegroundColor(HSSFColor.WHITE.index);
-		style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
-		style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
-		style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
-		style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
-		style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
-		// 生成另一个字体
-		HSSFFont font2 = workbook.createFont();
-		font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
-		// 把字体应用到当前的样式
-		style2.setFont(font2);
-		
-		//设置表头
-		HSSFRow row = setHeader(sheet, style, headerMap);
-		
-		// 遍历集合数据,产生数据行
-		Iterator<T> it = dataset.iterator();
-		int index = 0;
-		while (it.hasNext()) {
-			index++;//
-			row = sheet.createRow(index);
-			row.setHeight((short)320);
-			T t = (T) it.next();
-			// 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
-			Field[] fields = t.getClass().getDeclaredFields();
-			int cellIndex = 0;
-			for(Map.Entry<String, String> enrty:headerMap.entrySet()) {
-				String key  = enrty.getKey();
-				for (short i = 0; i < fields.length; i++) {
-					Field field = fields[i];
-					String fieldName = field.getName();
-					if(!key.equals(fieldName)) {//判断字段是否在列表中
-						continue;
-					} else {
-						cellIndex ++;
-					}
-					HSSFCell cell = row.createCell(cellIndex-1);
-					cell.setCellStyle(style2);
-					String getMethodName = "get"
-							+ fieldName.substring(0, 1).toUpperCase()
-							+ fieldName.substring(1);
-					Class tCls = t.getClass();
-					Method getMethod = tCls.getMethod(getMethodName,new Class[] {});
-					Object value = getMethod.invoke(t, new Object[] {});
-					// 判断值的类型后进行强制类型转换
-					String textValue = "";
-					if(null != value)
-						textValue = value.toString();
-					// 如果不是图片数据,就利用正则表达式判断textValue是否全部由数字组成
-					if (textValue != null) {
-						Pattern p = Pattern.compile("^//d+(//.//d+)?$");
-						Matcher matcher = p.matcher(textValue);
-						if (matcher.matches()) {
-							// 是数字当作double处理
-							cell.setCellValue(NumberUtils.round(Double.parseDouble(textValue), 2));
-						} else {
-							HSSFRichTextString richString = new HSSFRichTextString(textValue);
-							HSSFFont font3 = workbook.createFont();
-							font3.setColor(HSSFColor.BLACK.index);
-							richString.applyFont(font3);
-							cell.setCellValue(richString);
-						}
-					}
-				}
-			}
-		}
-		return workbook;
-	}
+    /**
+     * 设置表头
+     *
+     * @param sheet
+     * @param style
+     * @param headerMap
+     * @return
+     */
+    private HSSFRow setHeader(HSSFSheet sheet, HSSFCellStyle style, Map<String, String> headerMap) {
+        // 设置这些样式
+        style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
+        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
+        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
 
-	/**
-	 * 设置表头
-	 * @param sheet
-	 * @param style
-	 * @param headerMap
-	 * @return
-	 */
-	private HSSFRow setHeader(HSSFSheet sheet,HSSFCellStyle style, Map<String, String> headerMap){
-		// 设置这些样式
-		style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
-		style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
-		style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
-		style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
-		style.setBorderRight(HSSFCellStyle.BORDER_THIN);
-		style.setBorderTop(HSSFCellStyle.BORDER_THIN);
-		style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
-		
-		HSSFRow row = sheet.createRow(0);
-		row.setHeight((short)360);
-		int cursor = 0;
-		for (Map.Entry<String, String> entry : headerMap.entrySet()) {
-			HSSFCell cell = row.createCell(cursor);
-			cell.setCellStyle(style);
-			HSSFRichTextString text = new HSSFRichTextString(entry.getValue());
-			cell.setCellValue(text);
-			cursor++;
-		}
-		return row;
-	}
-	
-	/**
-	 * 添加单元格
-	 * @param row
-	 * @param style
-	 * @param column
-	 * @param value
-	 */
-	public static void addCell(HSSFRow row, HSSFCellStyle style, int column, String value){
-		HSSFCell cell = row.createCell(column);
-		cell.setCellStyle(style);
-		cell.setCellValue(value);
-	}
-	
-	/**
-	 * 添加单元格
-	 * @param row
-	 * @param style
-	 * @param column
-	 * @param value
-	 */
-	public static void addCell(HSSFRow row, HSSFCellStyle style, int column, double value){
-		HSSFCell cell = row.createCell(column);
-		cell.setCellStyle(style);
-		cell.setCellValue(value);
-	}
+        HSSFRow row = sheet.createRow(0);
+        row.setHeight((short) 360);
+        int cursor = 0;
+        for (Map.Entry<String, String> entry : headerMap.entrySet()) {
+            HSSFCell cell = row.createCell(cursor);
+            cell.setCellStyle(style);
+            HSSFRichTextString text = new HSSFRichTextString(entry.getValue());
+            cell.setCellValue(text);
+            cursor++;
+        }
+        return row;
+    }
 }

+ 388 - 374
VB_DSM_V2.1/vbdsm-web/vbdsm-powerservice/src/main/java/cn/vbdsm/powerservice/mvc/action/web/action/AnalDateFgpAction.java

@@ -1,26 +1,5 @@
 package cn.vbdsm.powerservice.mvc.action.web.action;
 
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import javax.core.common.ResultMsg;
-import javax.core.common.utils.StringUtils;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.servlet.ModelAndView;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import cn.vbdsm.common.config.I18nConfig;
 import cn.vbdsm.common.constants.CommonConstants;
 import cn.vbdsm.common.constants.SystemConstant;
@@ -29,366 +8,401 @@ import cn.vbdsm.core.mvc.action.BaseAction;
 import cn.vbdsm.powerservice.model.AnalDateFgp;
 import cn.vbdsm.powerservice.service.online.facade.IAnalDateFgpService;
 import cn.vbdsm.powerservice.service.online.facade.IReportManageService;
-import cn.vbdsm.powerservice.vo.AnalDateFgpVo;
-import cn.vbdsm.powerservice.vo.ElectricPowerDistributionVo;
-import cn.vbdsm.powerservice.vo.ElectricityCostVo;
-import cn.vbdsm.powerservice.vo.HighChartsColumnVo;
-import cn.vbdsm.powerservice.vo.ViewAnalDateFgpDataVo;
+import cn.vbdsm.powerservice.vo.*;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.core.common.ResultMsg;
+import javax.core.common.utils.StringUtils;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 
 /**
- * 
- *                  _oo8oo_
- *                 o8888888o
- *                 88" . "88
- *                 (| -_- |)
- *                 0\  =  /0
- *               ___/'==='\___
- *             .' \\|     |// '.
- *            / \\|||  :  |||// \
- *           / _||||| -:- |||||_ \
- *          |   | \\\  -  /// |   |
- *          | \_|  ''\---/''  |_/ |
- *          \  .-\__  '-'  __/-.  /
- *        ___'. .'  /--.--\  '. .'___
- *     ."" '<  '.___\_<|>_/___.'  >' "".
- *    | | :  `- \`.:`\ _ /`:.`/ -`  : | |
- *    \  \ `-.   \_ __\ /__ _/   .-` /  /
- *=====`-.____`.___ \_____/ ___.`____.-`=====
- *                  `=---=`
- *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- *             佛祖保佑         永无bug
- *             
+ * _oo8oo_
+ * o8888888o
+ * 88" . "88
+ * (| -_- |)
+ * 0\  =  /0
+ * ___/'==='\___
+ * .' \\|     |// '.
+ * / \\|||  :  |||// \
+ * / _||||| -:- |||||_ \
+ * |   | \\\  -  /// |   |
+ * | \_|  ''\---/''  |_/ |
+ * \  .-\__  '-'  __/-.  /
+ * ___'. .'  /--.--\  '. .'___
+ * ."" '<  '.___\_<|>_/___.'  >' "".
+ * | | :  `- \`.:`\ _ /`:.`/ -`  : | |
+ * \  \ `-.   \_ __\ /__ _/   .-` /  /
+ * =====`-.____`.___ \_____/ ___.`____.-`=====
+ * `=---=`
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * 佛祖保佑         永无bug
+ * <p>
  * 峰谷平尖电量与电费分析报表Action
+ *
  * @author grxie
  */
 @Controller
-@RequestMapping(value="/web/anal")
+@RequestMapping(value = "/web/anal")
 public class AnalDateFgpAction extends BaseAction {
 
-	@Autowired private IAnalDateFgpService analDateFgpService; 
-	@Autowired private IReportManageService reportManageService;
-	
-	/**
-	 * 
-	 * 监测点峰谷平电量与电费月分析
-	 * @param type	报表类型
-	 * @param monitorId	设备ID
-	 * @param name	设备名称
-	 * @param model	模型(监测点或建筑物)
-	 * @param date	日期
-	 * @param pic	报表类型
-	 * @param startDate	开始时间
-	 * @param endDate	结束时间
-	 * @param request
-	 * @param response
-	 * @return
-	 */
-	@RequestMapping(value="/getMonitorFgpAnalyze/{type}/{monitorId}.json")
-	public ModelAndView getMonitorFgpAnalyze(@PathVariable(value="type") String type, @PathVariable(value="monitorId") Long monitorId, 
-			@RequestParam(value="name") String name, @RequestParam(value="model") String model,
-			@RequestParam(value= "date",required = false) Long date, @RequestParam(value= "pic",required = false) String pic,
-			@RequestParam(value= "startDate",required = false) Long startDate, @RequestParam(value= "endDate",required = false) Long endDate,
-			HttpServletRequest request,HttpServletResponse response) {
-		ResultMsg<ViewAnalDateFgpDataVo> result = null;
-		String local = super.getLocal(request);
-		if(type.equalsIgnoreCase("day")) {//日报表
-			result = analDateFgpService.getAnalDateFgpForTerminalIdAndDay(monitorId, name, date, pic, model, true);
-		} else if(type.equalsIgnoreCase("month")) {//月报表
-			List<Long> monitorIdList = new ArrayList<Long>();
-			monitorIdList.add(monitorId);
-			result = analDateFgpService.getAnalDateFgpForTerminalIdsAndTimes(monitorIdList, name, startDate, endDate, pic, model, true, true);
-		} else if(type.equalsIgnoreCase("year")) {//年报表
-			result = analDateFgpService.getAnalDateFgpForTerminalIdAndYear(monitorId, name, date, pic, model, true);
-		}
-		
-		if(result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
-			result.setMsg(I18nConfig.getValue(local,"analdatefgp_success"));
-		else if(result.getStatus() == SystemConstant.RESULT_STATUS_FAILED)
-			result.setMsg(I18nConfig.getValue(local,"analdatefgp_fail"));
-		
-		return super.callBackForJsonp(request, response, JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 根据监测点ID列表获取峰谷平电量统计
-	 * @author grxie
-	 * @param monitorIds
-	 * @param startDate
-	 * @param endDate
-	 * @param request
-	 * @param response
-	 * @return
-	 */
-	@RequestMapping(value="/getFgpElectricStatistic.json")
-	public ModelAndView getAnalDateFgp(@RequestParam(value="monitorIds") String monitorIds,
-			@RequestParam(value= "startDate",required = false) Long startDate, 
-			@RequestParam(value= "endDate",required = false) Long endDate,
-			HttpServletRequest request,HttpServletResponse response){
-		ResultMsg<List<AnalDateFgpVo>> result = new ResultMsg<List<AnalDateFgpVo>>();
-		List<Long> monitorIdList = new ArrayList<Long>();
-		for (String id : monitorIds.split(",")) {
-			if(StringUtils.isEmpty(id))	continue;
-			monitorIdList.add(Long.valueOf(id));
-		}
-		ResultMsg<ViewAnalDateFgpDataVo> resultFgp = new ResultMsg<ViewAnalDateFgpDataVo>();
-		if(!monitorIdList.isEmpty())	
-			resultFgp = analDateFgpService.getAnalDateFgpForTerminalIdsAndTimes(monitorIdList, "", startDate, endDate, "1", CommonConstants.MONITOR_TREE_TYPE_MONITOR, true, false);
-		
-		String local = super.getLocal(request);
-		if(resultFgp.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS) {
-			result = new ResultMsg<List<AnalDateFgpVo>>(resultFgp.getStatus(), resultFgp.getData().getGridData());
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
-		} else if (resultFgp.getStatus() == SystemConstant.RESULT_STATUS_FAILED){
-			result = new ResultMsg<List<AnalDateFgpVo>>(resultFgp.getStatus());
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
-		}
-		return super.callBackForJsonp(request, response, JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 获取企业峰谷平电量与电费月份统计报表数据
-	 * @param pic
-	 * @param year
-	 * @param month
-	 * @param request
-	 * @param response
-	 * @return
-	 */
-	@RequestMapping(value="/getAnalDateFgpMonthChartDate.json")
-	public ModelAndView getAnalDateFgpMonthChartByCompany(@RequestParam(value= "pic") String pic,
-			@RequestParam(value= "year") Integer year, @RequestParam(value= "month") Integer month,
-			HttpServletRequest request,HttpServletResponse response) {
-		long companyId = super.getCompanyId(request);
-		String companyName = super.getUserInfo(request).getJSONObject("company").getString("name");
-		ResultMsg<HighChartsColumnVo> result = analDateFgpService.getAnalDateFgpChartsDataByMonth(companyId, year, month, pic, companyName); 
-		
-		String local = super.getLocal(request);
-		if(result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
-		else if(result.getStatus() == SystemConstant.RESULT_STATUS_ERROR)
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
-		
-		return super.callBackForJsonp(request, response, JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 获取企业峰谷平电量与电费月份统计表格数据
-	 * @param pic
-	 * @param year
-	 * @param month
-	 * @param request
-	 * @param response
-	 * @return
-	 */
-	@RequestMapping(value="/getAnalDateFgpMonthGridDate.json")
-	public ModelAndView getAnalDateFgpMonthGridByCompany(
-			@RequestParam(value= "year") Integer year, @RequestParam(value= "month") Integer month,
-			HttpServletRequest request,HttpServletResponse response) {
-		long companyId = super.getCompanyId(request);
-		ResultMsg<JSONObject> result = analDateFgpService.getAnalDateFgpGridDataByMonth(companyId, year, month); 
-		String local = super.getLocal(request);
-		if(result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
-		else if(result.getStatus() == SystemConstant.RESULT_STATUS_ERROR)
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
-		
-		return super.callBackForJsonp(request, response, JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 监测点峰谷平电量与电费月分析
-	 * @param request
-	 * @param response
-	 * @param monitorId 节点id
-	 * @param type	节点类型(根节点是企业:company,其他监测点节点:monitor)
-	 * @return
-	 */
-	@RequestMapping(value="/getAnalDateFgpByMonitorId/{monitorId}.json")
-	public ModelAndView getAnalDateFgpByMonitorId(HttpServletRequest request,HttpServletResponse response
-			, @PathVariable(value="monitorId") long monitorId, @RequestParam(value="type") String type, @RequestParam(value="monitorName") String monitorName) {
-		long companyId = super.getCompanyId(request);
-		
-		ResultMsg<ElectricPowerDistributionVo> result = analDateFgpService.getAnalDateFgpByMonitorId(companyId, monitorId, type, monitorName);
-		return super.callBackForJsonp(request, response, JSON.toJSONString(result.getData()));
-	}
-	
-	/**
-	 * 获取企业监测点月电量明细数据
-	 * @param monitorIds
-	 * @param year
-	 * @param month
-	 * @param request
-	 * @param response
-	 * @return
-	 */
-	@RequestMapping(value="/getAnalDateFgpMonthData.json")
-	public ModelAndView getAnalDateFgpMonthData(@RequestParam(value = "monitorIds") String monitorIds,
-			@RequestParam(value = "year", required = false) String year,
-			@RequestParam(value = "month", required = false) String month,
-			HttpServletRequest request,	HttpServletResponse response) {
-		ResultMsg<Map<String, List<AnalDateFgp>>> result = null;
-		
-		result =  analDateFgpService.getAnalDateFgpForMonth(Arrays.asList(monitorIds.split(",")), Long.valueOf(year+month));
-		
-		String local = super.getLocal(request);
-		if(result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
-		else if(result.getStatus() == SystemConstant.RESULT_STATUS_ERROR)
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
-		
-		return super.callBackForJsonp(request, response, JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 导出EXCEL
-	 * @param type
-	 * @param monitorId
-	 * @param date
-	 * @param startDate
-	 * @param endDate
-	 * @param request
-	 * @param response
-	 * @return
-	 */
-	@RequestMapping(value="/exportExcel/{type}/{monitorId}.json")
-	public void exportExcel(@PathVariable(value="type") String type, @PathVariable(value="monitorId") Long monitorId, 
-			@RequestParam(value="name") String name, 
-			@RequestParam(value= "date",required = false) Long date, @RequestParam(value="model") String model,
-			@RequestParam(value= "startDate",required = false) Long startDate, @RequestParam(value= "endDate",required = false) Long endDate,
-			@RequestParam(value="gridData") String gridData, HttpServletRequest request,HttpServletResponse response) {
-		ResultMsg<HSSFWorkbook> result = new ResultMsg<HSSFWorkbook>();
-		try{
-			super.setExportHeader(response,name+"峰谷平电费与电量报表.xls");
-			response.flushBuffer();
-			if(type.equalsIgnoreCase("day")) {
-				result = analDateFgpService.exportAnalDateFgpForTerminalIdAndDay(monitorId, name, date, model, gridData);
-			} else if(type.equalsIgnoreCase("month")) {
-				List<Long> monitorIdList = new ArrayList<Long>();
-				monitorIdList.add(monitorId);
-				result = analDateFgpService.exportAnalDateFgpForTerminalIdAndTimes(monitorIdList, name, startDate, endDate, model, gridData);
-			} else if(type.equalsIgnoreCase("year")) {
-				result = analDateFgpService.exportAnalDateFgpForTerminalIdAndYear(monitorId, name, date, model, gridData);
-			}
-			result.getData().write(response.getOutputStream());
-		} catch (Exception e){
-			e.printStackTrace();
-		}
-	}
-	
-	/**
-	 * 导出EXCEL
-	 * @param type
-	 * @param monitorId
-	 * @param date
-	 * @param startDate
-	 * @param endDate
-	 * @param request
-	 * @param response
-	 * @return
-	 */
-	@RequestMapping(value="/exportExcel/{type}.json")
-	public void exportFgpExcel(@PathVariable(value="type") String type, 
-			@RequestParam(value="name") String name, @RequestParam(value= "date",required = false) String date,
-			@RequestParam(value= "startDate",required = false) String startDate, @RequestParam(value= "endDate",required = false) String endDate,
-			@RequestParam(value="gridData") String gridData, HttpServletRequest request,HttpServletResponse response) {
-		ResultMsg<HSSFWorkbook> result = new ResultMsg<HSSFWorkbook>();
-		try{
-			String title = "";
-			InputStream template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_power_price.xls");
-			if(type.equalsIgnoreCase("day")) {
-				title = "【"+name+"】"+date+"日峰谷平电量与电费统计";
-			} else if(type.equalsIgnoreCase("month")) {
-				title = "【"+name+"】"+startDate+"到"+endDate+"峰谷平电量与电费统计";
-			} else if(type.equalsIgnoreCase("year")) {
-				title = "【"+name+"】"+date+"年峰谷平电量与电费统计";
-			}
-			result = analDateFgpService.exportAnalDateFgpPowerPrice(gridData, title, template);
-			super.setExportHeader(response,title+".xls");
-			response.flushBuffer();
-			result.getData().write(response.getOutputStream());
-		} catch (Exception e){
-			e.printStackTrace();
-		}
-	}
-	
-	/**
-	 * 导出电量统计
-	 * @param type
-	 * @param gridData
-	 * @param startDate
-	 * @param endDate
-	 * @param request
-	 * @param response
-	 */
-	@RequestMapping(value="/exportPowerStatistic/{type}.json")
-	public void exportPowerStatistic(
-			@PathVariable(value="type") String type,
-			@RequestParam(value = "columnName") String columnName,
-			@RequestParam(value="gridData") String gridData,
-			@RequestParam(value="startDate") String startDate,
-			@RequestParam(value="endDate") String endDate,
-			HttpServletRequest request,HttpServletResponse response){
-		ResultMsg<HSSFWorkbook> result = new ResultMsg<HSSFWorkbook>();
-		try{
-			String title = "";
-			InputStream template = null;
-			if("defineTime".equalsIgnoreCase(type)) {
-				title = "自定义日统计电量明细("+startDate+")";
-				result = reportManageService.exportDataToExcel(title, columnName, gridData);
-			}else{
-				if("power".equalsIgnoreCase(type)) {//峰平谷尖电量统计
-					title = "峰平谷尖电量统计("+startDate+"到"+endDate+")";
-					template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_power.xls");
-				} else if("day".equalsIgnoreCase(type)) {//日峰谷平明细
-					title = "日电量明细("+startDate+")";
-					template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_day_detail.xls");
-				} else if("month".equalsIgnoreCase(type)) {//月峰平谷尖明细
-					title = "月峰平谷尖明细("+startDate+"年"+endDate+"月)";
-					template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_month_detail.xls");
-				} else if("time".equalsIgnoreCase(type)) {//时刻电量明细
-					title = "时刻电量统计("+startDate+"到"+endDate+")";
-					template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_time.xls");
-				} else if("analmonth".equalsIgnoreCase(type)) {//月电量明细
-					title = "月电量明细("+startDate+"年"+endDate+"月)";
-					template = getClass().getClassLoader().getResourceAsStream("fgp_anal_total_month_detail.xls");
-				}
-				result = analDateFgpService.exportFgpPowerStatistic(gridData, title, template, type);
-			}
-			super.setExportHeader(response,title+".xls");
-			response.flushBuffer();
-			result.getData().write(response.getOutputStream());
-		} catch (Exception e){
-			e.printStackTrace();
-		}
-	}
-	
-	/**
-	 * 获取机构电费成本分析数据
-	 * @param type
-	 * @param date
-	 * @param request
-	 * @param response
-	 * @return
-	 */
-	@RequestMapping(value="/getElectricityCost.json")
-	public ModelAndView getElectricityCostData(@RequestParam(value="type") String type,
-			@RequestParam(value="date") Long date,
-			HttpServletRequest request,HttpServletResponse response) {
-		ResultMsg<ElectricityCostVo> result = null;
-		long companyId = super.getCompanyId(request);
-		if("1".equals(type)){//月
-			result =  analDateFgpService.getElectricityCostMonth(companyId, date);
-		} else if("2".equals(type)){//年
-			result =  analDateFgpService.getElectricityCostYear(companyId, date);
-		}
-		
-		String local = super.getLocal(request);
-		if(result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
-		else if(result.getStatus() == SystemConstant.RESULT_STATUS_ERROR)
-			result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
-		
-		return super.callBackForJsonp(request, response, JSON.toJSONString(result));
-	}
+    @Autowired
+    private IAnalDateFgpService analDateFgpService;
+    @Autowired
+    private IReportManageService reportManageService;
+
+    /**
+     * 监测点峰谷平电量与电费月分析
+     *
+     * @param type      报表类型
+     * @param monitorId 设备ID
+     * @param name      设备名称
+     * @param model     模型(监测点或建筑物)
+     * @param date      日期
+     * @param pic       报表类型
+     * @param startDate 开始时间
+     * @param endDate   结束时间
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/getMonitorFgpAnalyze/{type}/{monitorId}.json")
+    public ModelAndView getMonitorFgpAnalyze(@PathVariable(value = "type") String type, @PathVariable(value = "monitorId") Long monitorId,
+                                             @RequestParam(value = "name") String name, @RequestParam(value = "model") String model,
+                                             @RequestParam(value = "date", required = false) Long date, @RequestParam(value = "pic", required = false) String pic,
+                                             @RequestParam(value = "startDate", required = false) Long startDate, @RequestParam(value = "endDate", required = false) Long endDate,
+                                             HttpServletRequest request, HttpServletResponse response) {
+        ResultMsg<ViewAnalDateFgpDataVo> result = null;
+        String local = super.getLocal(request);
+        if (type.equalsIgnoreCase("day")) {//日报表
+            result = analDateFgpService.getAnalDateFgpForTerminalIdAndDay(monitorId, name, date, pic, model, true);
+        } else if (type.equalsIgnoreCase("month")) {//月报表
+            List<Long> monitorIdList = new ArrayList<Long>();
+            monitorIdList.add(monitorId);
+            result = analDateFgpService.getAnalDateFgpForTerminalIdsAndTimes(monitorIdList, name, startDate, endDate, pic, model, true, true);
+        } else if (type.equalsIgnoreCase("year")) {//年报表
+            result = analDateFgpService.getAnalDateFgpForTerminalIdAndYear(monitorId, name, date, pic, model, true);
+        }
+
+        if (result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
+            result.setMsg(I18nConfig.getValue(local, "analdatefgp_success"));
+        else if (result.getStatus() == SystemConstant.RESULT_STATUS_FAILED)
+            result.setMsg(I18nConfig.getValue(local, "analdatefgp_fail"));
+
+        return super.callBackForJsonp(request, response, JSON.toJSONString(result));
+    }
+
+    /**
+     * 根据监测点ID列表获取峰谷平电量统计
+     *
+     * @param monitorIds
+     * @param startDate
+     * @param endDate
+     * @param request
+     * @param response
+     * @return
+     * @author grxie
+     */
+    @RequestMapping(value = "/getFgpElectricStatistic.json")
+    public ModelAndView getAnalDateFgp(@RequestParam(value = "monitorIds") String monitorIds,
+                                       @RequestParam(value = "startDate", required = false) Long startDate,
+                                       @RequestParam(value = "endDate", required = false) Long endDate,
+                                       HttpServletRequest request, HttpServletResponse response) {
+        ResultMsg<List<AnalDateFgpVo>> result = new ResultMsg<List<AnalDateFgpVo>>();
+        List<Long> monitorIdList = new ArrayList<Long>();
+        for (String id : monitorIds.split(",")) {
+            if (StringUtils.isEmpty(id)) continue;
+            monitorIdList.add(Long.valueOf(id));
+        }
+        ResultMsg<ViewAnalDateFgpDataVo> resultFgp = new ResultMsg<ViewAnalDateFgpDataVo>();
+        if (!monitorIdList.isEmpty())
+            resultFgp = analDateFgpService.getAnalDateFgpForTerminalIdsAndTimes(monitorIdList, "", startDate, endDate, "1", CommonConstants.MONITOR_TREE_TYPE_MONITOR, true, false);
+
+        String local = super.getLocal(request);
+        if (resultFgp.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS) {
+            result = new ResultMsg<List<AnalDateFgpVo>>(resultFgp.getStatus(), resultFgp.getData().getGridData());
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
+        } else if (resultFgp.getStatus() == SystemConstant.RESULT_STATUS_FAILED) {
+            result = new ResultMsg<List<AnalDateFgpVo>>(resultFgp.getStatus());
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
+        }
+        return super.callBackForJsonp(request, response, JSON.toJSONString(result));
+    }
+
+    /**
+     * 获取企业峰谷平电量与电费月份统计报表数据
+     *
+     * @param pic
+     * @param year
+     * @param month
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/getAnalDateFgpMonthChartDate.json")
+    public ModelAndView getAnalDateFgpMonthChartByCompany(@RequestParam(value = "pic") String pic,
+                                                          @RequestParam(value = "year") Integer year, @RequestParam(value = "month") Integer month,
+                                                          HttpServletRequest request, HttpServletResponse response) {
+        long companyId = super.getCompanyId(request);
+        String companyName = super.getUserInfo(request).getJSONObject("company").getString("name");
+        ResultMsg<HighChartsColumnVo> result = analDateFgpService.getAnalDateFgpChartsDataByMonth(companyId, year, month, pic, companyName);
+
+        String local = super.getLocal(request);
+        if (result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
+        else if (result.getStatus() == SystemConstant.RESULT_STATUS_ERROR)
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
+
+        return super.callBackForJsonp(request, response, JSON.toJSONString(result));
+    }
+
+    /**
+     * 获取企业峰谷平电量与电费月份统计表格数据
+     *
+     * @param pic
+     * @param year
+     * @param month
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/getAnalDateFgpMonthGridDate.json")
+    public ModelAndView getAnalDateFgpMonthGridByCompany(
+            @RequestParam(value = "year") Integer year, @RequestParam(value = "month") Integer month,
+            HttpServletRequest request, HttpServletResponse response) {
+        long companyId = super.getCompanyId(request);
+        ResultMsg<JSONObject> result = analDateFgpService.getAnalDateFgpGridDataByMonth(companyId, year, month);
+        String local = super.getLocal(request);
+        if (result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
+        else if (result.getStatus() == SystemConstant.RESULT_STATUS_ERROR)
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
+
+        return super.callBackForJsonp(request, response, JSON.toJSONString(result));
+    }
+
+    /**
+     * 监测点峰谷平电量与电费月分析
+     *
+     * @param request
+     * @param response
+     * @param monitorId 节点id
+     * @param type      节点类型(根节点是企业:company,其他监测点节点:monitor)
+     * @return
+     */
+    @RequestMapping(value = "/getAnalDateFgpByMonitorId/{monitorId}.json")
+    public ModelAndView getAnalDateFgpByMonitorId(HttpServletRequest request, HttpServletResponse response
+            , @PathVariable(value = "monitorId") long monitorId, @RequestParam(value = "type") String type, @RequestParam(value = "monitorName") String monitorName) {
+        long companyId = super.getCompanyId(request);
+
+        ResultMsg<ElectricPowerDistributionVo> result = analDateFgpService.getAnalDateFgpByMonitorId(companyId, monitorId, type, monitorName);
+        return super.callBackForJsonp(request, response, JSON.toJSONString(result.getData()));
+    }
+
+    /**
+     * 获取企业监测点月电量明细数据
+     *
+     * @param monitorIds
+     * @param year
+     * @param month
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/getAnalDateFgpMonthData.json")
+    public ModelAndView getAnalDateFgpMonthData(@RequestParam(value = "monitorIds") String monitorIds,
+                                                @RequestParam(value = "year", required = false) String year,
+                                                @RequestParam(value = "month", required = false) String month,
+                                                HttpServletRequest request, HttpServletResponse response) {
+        ResultMsg<Map<String, List<AnalDateFgp>>> result = null;
+
+        result = analDateFgpService.getAnalDateFgpForMonth(Arrays.asList(monitorIds.split(",")), Long.valueOf(year + month));
+
+        String local = super.getLocal(request);
+        if (result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
+        else if (result.getStatus() == SystemConstant.RESULT_STATUS_ERROR)
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
+
+        return super.callBackForJsonp(request, response, JSON.toJSONString(result));
+    }
+
+    /**
+     * 导出EXCEL
+     *
+     * @param type
+     * @param monitorId
+     * @param date
+     * @param startDate
+     * @param endDate
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/exportExcel/{type}/{monitorId}.json")
+    public void exportExcel(@PathVariable(value = "type") String type, @PathVariable(value = "monitorId") Long monitorId,
+                            @RequestParam(value = "name") String name,
+                            @RequestParam(value = "date", required = false) Long date, @RequestParam(value = "model") String model,
+                            @RequestParam(value = "startDate", required = false) Long startDate, @RequestParam(value = "endDate", required = false) Long endDate,
+                            @RequestParam(value = "gridData") String gridData, HttpServletRequest request, HttpServletResponse response) {
+        ResultMsg<HSSFWorkbook> result = new ResultMsg<HSSFWorkbook>();
+        try {
+            super.setExportHeader(response, name + "峰谷平电费与电量报表.xls");
+            response.flushBuffer();
+            if (type.equalsIgnoreCase("day")) {
+                result = analDateFgpService.exportAnalDateFgpForTerminalIdAndDay(monitorId, name, date, model, gridData);
+            } else if (type.equalsIgnoreCase("month")) {
+                List<Long> monitorIdList = new ArrayList<Long>();
+                monitorIdList.add(monitorId);
+                result = analDateFgpService.exportAnalDateFgpForTerminalIdAndTimes(monitorIdList, name, startDate, endDate, model, gridData);
+            } else if (type.equalsIgnoreCase("year")) {
+                result = analDateFgpService.exportAnalDateFgpForTerminalIdAndYear(monitorId, name, date, model, gridData);
+            }
+            result.getData().write(response.getOutputStream());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 导出EXCEL
+     *
+     * @param type
+     * @param monitorId
+     * @param date
+     * @param startDate
+     * @param endDate
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/exportExcel/{type}.json")
+    public void exportFgpExcel(@PathVariable(value = "type") String type,
+                               @RequestParam(value = "name") String name, @RequestParam(value = "date", required = false) String date,
+                               @RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "endDate", required = false) String endDate,
+                               @RequestParam(value = "gridData") String gridData, HttpServletRequest request, HttpServletResponse response) {
+        ResultMsg<HSSFWorkbook> result = new ResultMsg<HSSFWorkbook>();
+        try {
+            String title = "";
+            InputStream template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_power_price.xls");
+            if (type.equalsIgnoreCase("day")) {
+                title = "【" + name + "】" + date + "日峰谷平电量与电费统计";
+            } else if (type.equalsIgnoreCase("month")) {
+                title = "【" + name + "】" + startDate + "到" + endDate + "峰谷平电量与电费统计";
+            } else if (type.equalsIgnoreCase("year")) {
+                title = "【" + name + "】" + date + "年峰谷平电量与电费统计";
+            }
+            result = analDateFgpService.exportAnalDateFgpPowerPrice(gridData, title, template);
+            super.setExportHeader(response, title + ".xls");
+            response.flushBuffer();
+            result.getData().write(response.getOutputStream());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 导出电量统计
+     *
+     * @param type
+     * @param gridData
+     * @param startDate
+     * @param endDate
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportPowerStatistic/{type}.json")
+    public void exportPowerStatistic(
+            @PathVariable(value = "type") String type,
+            @RequestParam(value = "columnName") String columnName,
+            @RequestParam(value = "gridData") String gridData,
+            @RequestParam(value = "startDate") String startDate,
+            @RequestParam(value = "endDate") String endDate,
+            HttpServletRequest request, HttpServletResponse response) {
+        ResultMsg<HSSFWorkbook> result = new ResultMsg<HSSFWorkbook>();
+        try {
+            String title = "";
+            InputStream template = null;
+            if ("defineTime".equalsIgnoreCase(type)) {
+                title = "自定义日统计电量明细(" + startDate + ")";
+                result = reportManageService.exportDataToExcel(title, columnName, gridData);
+            } else if ("onlineP".equalsIgnoreCase(type)) {
+                title = "实时负荷明细(" + startDate + ")";
+                result = reportManageService.exportDataToExcel(title, columnName, gridData);
+            } else if ("onlineI".equalsIgnoreCase(type)) {
+                title = "实时电流明细(" + startDate + ")";
+                result = reportManageService.exportDataToExcel(title, columnName, gridData);
+            } else if ("onlineU".equalsIgnoreCase(type)) {
+                title = "实时电压明细(" + startDate + ")";
+                result = reportManageService.exportDataToExcel(title, columnName, gridData);
+            } else {
+                if ("power".equalsIgnoreCase(type)) {//峰平谷尖电量统计
+                    title = "峰平谷尖电量统计(" + startDate + "到" + endDate + ")";
+                    template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_power.xls");
+                } else if ("day".equalsIgnoreCase(type)) {//日峰谷平明细
+                    title = "日电量明细(" + startDate + ")";
+                    template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_day_detail.xls");
+                } else if ("month".equalsIgnoreCase(type)) {//月峰平谷尖明细
+                    title = "月峰平谷尖明细(" + startDate + "年" + endDate + "月)";
+                    template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_month_detail.xls");
+                } else if ("time".equalsIgnoreCase(type)) {//时刻电量明细
+                    title = "时刻电量统计(" + startDate + "到" + endDate + ")";
+                    template = getClass().getClassLoader().getResourceAsStream("fgp_anal_date_time.xls");
+                } else if ("analmonth".equalsIgnoreCase(type)) {//月电量明细
+                    title = "月电量明细(" + startDate + "年" + endDate + "月)";
+                    template = getClass().getClassLoader().getResourceAsStream("fgp_anal_total_month_detail.xls");
+                }
+                result = analDateFgpService.exportFgpPowerStatistic(gridData, title, template, type);
+            }
+            super.setExportHeader(response, title + ".xls");
+            response.flushBuffer();
+            result.getData().write(response.getOutputStream());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取机构电费成本分析数据
+     *
+     * @param type
+     * @param date
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/getElectricityCost.json")
+    public ModelAndView getElectricityCostData(@RequestParam(value = "type") String type,
+                                               @RequestParam(value = "date") Long date,
+                                               HttpServletRequest request, HttpServletResponse response) {
+        ResultMsg<ElectricityCostVo> result = null;
+        long companyId = super.getCompanyId(request);
+        if ("1".equals(type)) {//月
+            result = analDateFgpService.getElectricityCostMonth(companyId, date);
+        } else if ("2".equals(type)) {//年
+            result = analDateFgpService.getElectricityCostYear(companyId, date);
+        }
+
+        String local = super.getLocal(request);
+        if (result.getStatus() == SystemConstant.RESULT_STATUS_SUCCESS)
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_SUCCESS));
+        else if (result.getStatus() == SystemConstant.RESULT_STATUS_ERROR)
+            result.setMsg(I18nConfig.getValue(local, TipsConstant.MODEL_TIPS, TipsConstant.TIPS_GET_ERROR));
+
+        return super.callBackForJsonp(request, response, JSON.toJSONString(result));
+    }
 
 }

+ 149 - 130
VB_DSM_V2.1/vbdsm-web/vbdsm-powerservice/src/main/java/cn/vbdsm/powerservice/mvc/action/web/action/OnlineDataPowerAction.java

@@ -1,9 +1,9 @@
 package cn.vbdsm.powerservice.mvc.action.web.action;
 
-import javax.core.common.ResultMsg;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import cn.vbdsm.core.mvc.action.BaseAction;
+import cn.vbdsm.powerservice.service.online.facade.IOnlineDataPowerService;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -12,116 +12,134 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.servlet.ModelAndView;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import cn.vbdsm.core.mvc.action.BaseAction;
-import cn.vbdsm.powerservice.service.online.facade.IOnlineDataPowerService;
+import javax.core.common.ResultMsg;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 /**
- * 
  * 电力实时运行图表Action
+ *
  * @author zhouzhengdong
- * @date 2015-09-25 11:36
  * @version 1.0
- *
+ * @date 2015-09-25 11:36
  */
 @Controller
 @RequestMapping("/web/online")
-public class OnlineDataPowerAction extends BaseAction{
-	
-	static Logger logger = Logger.getLogger(OnlineDataPowerAction.class) ;
-	
-	@Autowired IOnlineDataPowerService powerService;
-	
-	/**
-	 * 获取24小时整点实时电力数据
-	 * @param request
-	 * @param response
-	 * @param date 日期 yyyy-MM-dd格式
-	 * @param monitorId 采集点编号
-	 * @return
-	 */
-	@RequestMapping("/getPower/point/{date}/{monitorId}.json")
-	public ModelAndView getOnlineDataPowerData(HttpServletRequest request,HttpServletResponse response,@PathVariable("date") String date,@PathVariable("monitorId") long monitorId){
-		String local = super.getLocal(request);
-		ResultMsg<?> result = powerService.getFor24H(local, monitorId, date);
-		return super.callBackForJsonp(request, response,
-				JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 根据日期获取一天的实时电力数据
-	 * @param request
-	 * @param response
-	 * @param date 时间
-	 * @param id 采集点编号
-	 * @return
-	 */
-	@RequestMapping("/getPower/{type}/{date}/{id}.json")
-	public ModelAndView getOneDayDataForType(HttpServletRequest request,HttpServletResponse response,@PathVariable("type") String type,@PathVariable("date") String date,@PathVariable("id") long id){
-		String local = super.getLocal(request);
-		ResultMsg<?> result = powerService.getForOneDay(local, id, date,type);
-		return super.callBackForJsonp(request, response,
-				JSON.toJSONString(result));
-	}
-	
-	
-	/**
-	 * 根据日期获取一天的实时电力数据
-	 * @param request
-	 * @param response
-	 * @param date 时间
-	 * @param id 采集点编号
-	 * @return
-	 */
-	@RequestMapping("/getPower/{date}/{id}.json")
-	public ModelAndView getOneDayData(HttpServletRequest request,HttpServletResponse response,@PathVariable("date") String date,@PathVariable("id") long id){
-		String local = super.getLocal(request);
-		ResultMsg<?> result = powerService.getForOneDay(local, id, date);
-		return super.callBackForJsonp(request, response,
-				JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 根据参数获取一天的用电单元的整点负荷数据
-	 * @param request
-	 * @param response
-	 * @param date 日期
-	 * @param id 用电单元id
-	 * @return
-	 */
-	@RequestMapping("/getPower/point/powerunit/{date}/{id}.json")
-	public ModelAndView getOneDayDataOfPowerUnit24H(HttpServletRequest request,HttpServletResponse response,@PathVariable("date") String date,@PathVariable("id") long id){
-		String local = super.getLocal(request);
-		ResultMsg<?> result = powerService.getPowerUnitFor24H(local, id, date);
-		return super.callBackForJsonp(request, response,
-				JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 根据参数获取一天的用电单元的负荷曲线数据
-	 * @param request
-	 * @param response
-	 * @param date 日期
-	 * @param id 用电单元id
-	 * @return
-	 */
-	@RequestMapping("/getPower/powerunit/{date}/{id}.json")
-	public ModelAndView getOneDayDataOfPowerUnit(HttpServletRequest request,HttpServletResponse response,@PathVariable("date") String date,@PathVariable("id") long id){
-		String local = super.getLocal(request);
-		ResultMsg<?> result = powerService.getPowerUnitForOneDay(local, id, date);
-		return super.callBackForJsonp(request, response,
-				JSON.toJSONString(result));
-	}
-	
-	/**
-	 * 根据日期获取一天的实时电力数据
-	 * @param request
-	 * @param response
-	 * @param date 时间
-	 * @param monitorId 采集点编号
-	 * @return
-	 */
+public class OnlineDataPowerAction extends BaseAction {
+
+    static Logger logger = Logger.getLogger(OnlineDataPowerAction.class);
+
+    @Autowired
+    IOnlineDataPowerService powerService;
+
+    /**
+     * 获取24小时整点实时电力数据
+     *
+     * @param request
+     * @param response
+     * @param date      日期 yyyy-MM-dd格式
+     * @param monitorId 采集点编号
+     * @return
+     */
+    @RequestMapping("/getPower/point/{date}/{monitorId}.json")
+    public ModelAndView getOnlineDataPowerData(HttpServletRequest request, HttpServletResponse response, @PathVariable("date") String date, @PathVariable("monitorId") long monitorId) {
+        String local = super.getLocal(request);
+        ResultMsg<?> result = powerService.getFor24H(local, monitorId, date);
+        return super.callBackForJsonp(request, response,
+                JSON.toJSONString(result));
+    }
+
+    /**
+     * 根据日期获取一天的实时电力数据
+     *
+     * @param request
+     * @param response
+     * @param date     时间
+     * @param id       采集点编号
+     * @return
+     */
+    @RequestMapping("/getPower/{type}/{date}/{id}.json")
+    public ModelAndView getOneDayDataForType(HttpServletRequest request, HttpServletResponse response, @PathVariable("type") String type, @PathVariable("date") String date, @PathVariable("id") long id) {
+        String local = super.getLocal(request);
+        ResultMsg<?> result = powerService.getForOneDay(local, id, date, type);
+        return super.callBackForJsonp(request, response,
+                JSON.toJSONString(result));
+    }
+
+    /**
+     * 获取一些监测点某一天的数据
+     *
+     * @param date 时间
+     * @param ids  采集点编号
+     * @return
+     */
+    @RequestMapping("/getOneDayDataByIds.json")
+    public ModelAndView getOneDayDataByIds(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "date") String date, @RequestParam(value = "ids") String ids) {
+        String local = super.getLocal(request);
+        ResultMsg<?> result = powerService.getOneDayDataByIds(local, ids, date);
+        return super.callBackForJsonp(request, response,
+                JSON.toJSONString(result));
+    }
+
+    /**
+     * 根据日期获取一天的实时电力数据
+     *
+     * @param request
+     * @param response
+     * @param date     时间
+     * @param id       采集点编号
+     * @return
+     */
+    @RequestMapping("/getPower/{date}/{id}.json")
+    public ModelAndView getOneDayData(HttpServletRequest request, HttpServletResponse response, @PathVariable("date") String date, @PathVariable("id") long id) {
+        String local = super.getLocal(request);
+        ResultMsg<?> result = powerService.getForOneDay(local, id, date);
+        return super.callBackForJsonp(request, response,
+                JSON.toJSONString(result));
+    }
+
+    /**
+     * 根据参数获取一天的用电单元的整点负荷数据
+     *
+     * @param request
+     * @param response
+     * @param date     日期
+     * @param id       用电单元id
+     * @return
+     */
+    @RequestMapping("/getPower/point/powerunit/{date}/{id}.json")
+    public ModelAndView getOneDayDataOfPowerUnit24H(HttpServletRequest request, HttpServletResponse response, @PathVariable("date") String date, @PathVariable("id") long id) {
+        String local = super.getLocal(request);
+        ResultMsg<?> result = powerService.getPowerUnitFor24H(local, id, date);
+        return super.callBackForJsonp(request, response,
+                JSON.toJSONString(result));
+    }
+
+    /**
+     * 根据参数获取一天的用电单元的负荷曲线数据
+     *
+     * @param request
+     * @param response
+     * @param date     日期
+     * @param id       用电单元id
+     * @return
+     */
+    @RequestMapping("/getPower/powerunit/{date}/{id}.json")
+    public ModelAndView getOneDayDataOfPowerUnit(HttpServletRequest request, HttpServletResponse response, @PathVariable("date") String date, @PathVariable("id") long id) {
+        String local = super.getLocal(request);
+        ResultMsg<?> result = powerService.getPowerUnitForOneDay(local, id, date);
+        return super.callBackForJsonp(request, response,
+                JSON.toJSONString(result));
+    }
+
+    /**
+     * 根据日期获取一天的实时电力数据
+     * @param request
+     * @param response
+     * @param date 时间
+     * @param monitorId 采集点编号
+     * @return
+     */
 //	@RequestMapping("/affect/power/{monitorId}.json")
 //	public ModelAndView getAffectData(HttpServletRequest request,HttpServletResponse response,@PathVariable("monitorId") long monitorId,@RequestParam(value="day1",defaultValue="") String day1,@RequestParam(value="day2",defaultValue="") String day2){
 //		String local = super.getLocal(request);
@@ -132,28 +150,29 @@ public class OnlineDataPowerAction extends BaseAction{
 //				JSON.toJSONString(result));
 //	}
 //	
-	
-	
-	/**
-	 * 查询监测点负荷分布
-	 * @param request
-	 * @param response
-	 * @param terminalId
-	 * @param startDate
-	 * @param endDate
-	 * @param interval
-	 * @return
-	 */
-	@RequestMapping("getMonitorDistributionData.json")
-	public ModelAndView getAreaDistributionData(HttpServletRequest request, HttpServletResponse response,
-			@RequestParam(value="monitorId") long monitorId,
-			@RequestParam(value="startDate") String startDate, 
-			@RequestParam(value="endDate") String endDate,
-			@RequestParam(value="interval") int interval) {
-		String local = super.getLocal(request);
-		ResultMsg<?> result = powerService.getMonitorLoadData(local, monitorId, interval, startDate, endDate);
-		return super.callBackForJsonp(request, response, JSONObject.toJSONString(result));
-	}
-	
-	
+
+
+    /**
+     * 查询监测点负荷分布
+     *
+     * @param request
+     * @param response
+     * @param terminalId
+     * @param startDate
+     * @param endDate
+     * @param interval
+     * @return
+     */
+    @RequestMapping("getMonitorDistributionData.json")
+    public ModelAndView getAreaDistributionData(HttpServletRequest request, HttpServletResponse response,
+                                                @RequestParam(value = "monitorId") long monitorId,
+                                                @RequestParam(value = "startDate") String startDate,
+                                                @RequestParam(value = "endDate") String endDate,
+                                                @RequestParam(value = "interval") int interval) {
+        String local = super.getLocal(request);
+        ResultMsg<?> result = powerService.getMonitorLoadData(local, monitorId, interval, startDate, endDate);
+        return super.callBackForJsonp(request, response, JSONObject.toJSONString(result));
+    }
+
+
 }

+ 129 - 112
VB_DSM_V2.1/vbdsm-web/vbdsm-powerservice/src/main/java/cn/vbdsm/powerservice/service/online/facade/IOnlineDataPowerService.java

@@ -1,124 +1,141 @@
 package cn.vbdsm.powerservice.service.online.facade;
 
-import java.util.List;
+import cn.vbdsm.powerservice.model.OnlineDataPower;
 
 import javax.core.common.ResultMsg;
-
-import cn.vbdsm.powerservice.model.OnlineDataPower;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 电能实时运行服务接口
+ *
  * @author zhouzhengdong
- * @date 2015-08-24 15:25
  * @version 1.0
+ * @date 2015-08-24 15:25
  */
 public interface IOnlineDataPowerService {
-	
-	/**
-	 * 根据监测点编号,获取24小时整点数据
-	 * @param local
-	 * @param monitorId
-	 * @param date yyyy-MM-dd格式
-	 * @return
-	 */
-	public ResultMsg<List<OnlineDataPower>> getFor24H(String local,long monitorId, String date);
-	
-	/**
-	 * 根据时间获取单条记录
-	 * @param local
-	 * @param monitorId
-	 * @param time
-	 * @return
-	 */
-	public ResultMsg<OnlineDataPower> getOnlineDataPower(String local,long monitorId,Long time);
-	
-	/**
-	 * 获取一天的数据
-	 * @param local
-	 * @param monitorId
-	 * @param start
-	 * @param end
-	 * @return
-	 */
-	public ResultMsg<List<OnlineDataPower>> getForBetweenTime(String local,long monitorId,long start,long end);
-	
-	/**
-	 * 根据日期获取一天的实时电力数据
-	 * @param local
-	 * @param id
-	 * @param dateString
-	 * @return
-	 */
-	public ResultMsg<List<OnlineDataPower>> getForOneDay(String local,long id,String dateString,String type);
-	
-	
-	/**
-	 * 根据日期获取一天的实时电力数据
-	 * @param local
-	 * @param id
-	 * @param dateString
-	 * @return
-	 */
-	public ResultMsg<List<OnlineDataPower>> getForOneDay(String local,long id,String dateString);
-	
-	/**
-	 * 根据用电单元编号获取一天内所有监测点的总负荷数据
-	 * @param local
-	 * @param unitId
-	 * @param date
-	 * @return
-	 */
-	public ResultMsg<List<OnlineDataPower>> getPowerUnitFor24H(String local,long unitId,String date);
-	
-	/**
-	 * 根据日期获取一天的实时电力数据
-	 * @param local
-	 * @param monitorId
-	 * @param dateString
-	 * @return
-	 */
-	public ResultMsg<List<OnlineDataPower>> getPowerUnitForOneDay(String local,long unitId,String date);
-
-	/**
-	 * 根据时间区间获取实时电力数据
-	 * @param local
-	 * @param id
-	 * @param startTime
-	 * @param endTime
-	 * @return
-	 */
-	public ResultMsg<?> getSectionData(String local, long id, String startTime, String endTime);
-	
-	/**
-	 * 根据时间区间获取实时电力数据(跨天)
-	 * @param local
-	 * @param id
-	 * @param startTime
-	 * @param endTime
-	 * @return
-	 */
-	public ResultMsg<?> getManyDaySectionData(String local, long id, String startTimeFirst, String endTimeFirst, String startTimeSecond, String endTimeSecond);
-	
-	/**
-	 * 根据时间区间获取实时电力数据
-	 * @param local
-	 * @param id
-	 * @param startTime
-	 * @param endTime
-	 * @return
-	 */
-	public ResultMsg<?> getSectionDataNew(String local, long id, String startTime, String endTime, String seriesName);
-	
-	/**
-	 * 查询监测点负荷分布
-	 * @param local
-	 * @param terminalId
-	 * @param interval
-	 * @param startDate
-	 * @param endDate
-	 * @return
-	 */
-	public ResultMsg<?> getMonitorLoadData(String local, long monitorId, int interval, 
-			String startDate, String endDate);
-	
+
+    /**
+     * 根据监测点编号,获取24小时整点数据
+     *
+     * @param local
+     * @param monitorId
+     * @param date      yyyy-MM-dd格式
+     * @return
+     */
+    ResultMsg<List<OnlineDataPower>> getFor24H(String local, long monitorId, String date);
+
+    /**
+     * 根据时间获取单条记录
+     *
+     * @param local
+     * @param monitorId
+     * @param time
+     * @return
+     */
+    ResultMsg<OnlineDataPower> getOnlineDataPower(String local, long monitorId, Long time);
+
+    /**
+     * 获取一天的数据
+     *
+     * @param local
+     * @param monitorId
+     * @param start
+     * @param end
+     * @return
+     */
+    ResultMsg<List<OnlineDataPower>> getForBetweenTime(String local, long monitorId, long start, long end);
+
+    /**
+     * 根据日期获取一天的实时电力数据
+     *
+     * @param local
+     * @param id
+     * @param dateString
+     * @return
+     */
+    ResultMsg<List<OnlineDataPower>> getForOneDay(String local, long id, String dateString, String type);
+
+
+    /**
+     * 获取一些监测点某一天的数据
+     */
+    ResultMsg<Map<String, List<OnlineDataPower>>> getOneDayDataByIds(String local, String ids, String dateString);
+
+    /**
+     * 根据日期获取一天的实时电力数据
+     *
+     * @param local
+     * @param id
+     * @param dateString
+     * @return
+     */
+    ResultMsg<List<OnlineDataPower>> getForOneDay(String local, long id, String dateString);
+
+    /**
+     * 根据用电单元编号获取一天内所有监测点的总负荷数据
+     *
+     * @param local
+     * @param unitId
+     * @param date
+     * @return
+     */
+    ResultMsg<List<OnlineDataPower>> getPowerUnitFor24H(String local, long unitId, String date);
+
+    /**
+     * 根据日期获取一天的实时电力数据
+     *
+     * @param local
+     * @param monitorId
+     * @param dateString
+     * @return
+     */
+    ResultMsg<List<OnlineDataPower>> getPowerUnitForOneDay(String local, long unitId, String date);
+
+    /**
+     * 根据时间区间获取实时电力数据
+     *
+     * @param local
+     * @param id
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    ResultMsg<?> getSectionData(String local, long id, String startTime, String endTime);
+
+    /**
+     * 根据时间区间获取实时电力数据(跨天)
+     *
+     * @param local
+     * @param id
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    ResultMsg<?> getManyDaySectionData(String local, long id, String startTimeFirst, String endTimeFirst, String startTimeSecond, String endTimeSecond);
+
+    /**
+     * 根据时间区间获取实时电力数据
+     *
+     * @param local
+     * @param id
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    ResultMsg<?> getSectionDataNew(String local, long id, String startTime, String endTime, String seriesName);
+
+    /**
+     * 查询监测点负荷分布
+     *
+     * @param local
+     * @param terminalId
+     * @param interval
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    ResultMsg<?> getMonitorLoadData(String local, long monitorId, int interval,
+                                    String startDate, String endDate);
+
 }

+ 1303 - 1296
VB_DSM_V2.1/vbdsm-web/vbdsm-powerservice/src/main/java/cn/vbdsm/powerservice/service/online/impl/OnlineDataPowerService.java

@@ -1,28 +1,5 @@
 package cn.vbdsm.powerservice.service.online.impl;
 
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.text.DecimalFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.core.common.ResultMsg;
-import javax.core.common.utils.NumberUtils;
-
-import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import com.alibaba.fastjson.JSONObject;
 import cn.vbdsm.common.constants.SystemConstant;
 import cn.vbdsm.common.utils.AnalDataCtPtUtil;
 import cn.vbdsm.common.utils.DateUtil;
@@ -40,1292 +17,1322 @@ import cn.vbdsm.powerservice.service.online.facade.IOnlineDataPowerService;
 import cn.vbdsm.powerservice.vo.HighChartsColumnVo;
 import cn.vbdsm.powerservice.vo.HighChartsModuleSeries;
 import cn.vbdsm.powerservice.vo.MonitorPowerUnitVo;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.core.common.ResultMsg;
+import javax.core.common.utils.NumberUtils;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.text.DecimalFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * 电力实时运行服务
+ *
  * @author zhouzhengdong
- * @date 2015-08-21 16:38
  * @version 1.0
+ * @date 2015-08-21 16:38
  */
 @Service
-public class OnlineDataPowerService extends BaseService<OnlineDataPower> implements IOnlineDataPowerService{
-
-	static Logger logger = Logger.getLogger(OnlineDataPowerService.class);
-
-	@Autowired OrgDao orgDao;
-	@Autowired OnlineDataPowerDao onlineDataPowerDao;
-	@Autowired MonitorDao monitorDao;
-	@Autowired MonitorPowerUnitDao mpuDao; //用电单元dao
-	@Autowired CompanyOnlineDataPowerService companyOnlineDataPowerService;
-
-	/**
-	 * 监测点一天二十四小时的整点数据
-	 */
-	@Override
-	public ResultMsg<List<OnlineDataPower>> getFor24H(String local,long monitorId,String date) {
-		resultForList = checkMonitorForList(local,monitorId);
-		if(resultForList.getStatus() != SystemConstant.RESULT_PARAM_ERROR) {
-			List<OnlineDataPower> onlineDataPowerList = get24HDataForTerminalIdAndGetTime(monitor.getTerminalId(),date);//当前监测点的整点数据
-			List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
-			if(monitor.getSeeType() == EmDistributionType.virtual.value) { //虚拟节点
-				List<Monitor> subMonitors = getSubMonitors(monitor); //获取子监测点
-				Map<Long,OnlineDataPower> pMap = new HashMap<Long,OnlineDataPower>();//定义存储时间点负荷的Map
-				if(subMonitors.size() > 0) {
-					for(Monitor sub : subMonitors) {
-						List<OnlineDataPower> subMonitorOnlineDataPowerList = get24HDataForTerminalIdAndGetTime(sub.getTerminalId(),date);//子监测点的整点数据
-						for(Iterator<OnlineDataPower> it = subMonitorOnlineDataPowerList.iterator();it.hasNext();) { 
-							//处理每个时间整点的数据
-							OnlineDataPower data = it.next();
-							data.setP(data.getPa().add(data.getPb()).add(data.getPc()).abs()); //总负荷
-							data.setQ(data.getQa().add(data.getQb()).add(data.getQc())); //总无功
-							data.setPf(data.getPfa().add(data.getPfb()).add(data.getPfb()).abs());//总功率因素
-							it.remove();//移除旧的数据
-							subMonitorOnlineDataPowerList.add(data); //重新整理了总负荷
-							if(pMap.isEmpty()) {
-								pMap.put(data.getGetTime(), data);
-							} else {
-								OnlineDataPower currentP = pMap.get(data.getGetTime()); //已经存储的OnlineDataPower
-								pMap.put(data.getGetTime(), rebuildOnlineDataPower(currentP,data));//重构某个整点时间点的子监测点的总负荷,总无功,总功率因数,循环添加
-							}
-						}
-					}
-				}
-				//这里的pMap已经将所有的子检测点的总负荷处理过,迭代监测点重置总负荷
-				for(Iterator<OnlineDataPower> iterator = onlineDataPowerList.iterator();iterator.hasNext();){
-					OnlineDataPower power = iterator.next();
-					OnlineDataPower memoryPower = pMap.get(power.getGetTime());
-					power.setP(memoryPower.getP()); //重置总负荷
-					power.setQ(memoryPower.getQ()); //重置总无功
-					power.setPf(memoryPower.getPf()); //重置总功率因数
-					iterator.remove();
-					temp.add(power.rebuildOnlineDataPower(monitor,power)); //这里父监测的所有数据已被处理过
-				}
-			} else {
-				for(OnlineDataPower power : onlineDataPowerList) {
-					temp.add(power.rebuildOnlineDataPower(monitor, power));
-				}
-			}
-			resultForList.setData(temp);
-			message = getLocalMessage(local,"onlinedatapower_success");
-			resultForList.setMsg(message);
-		}
-		return resultForList;
-	}
-
-	/**
-	 * 子监测点内总负荷,总无功,总功率因素
-	 * @param power
-	 * @param currentPower
-	 * @return
-	 */
-	private OnlineDataPower rebuildOnlineDataPower(OnlineDataPower power,OnlineDataPower currentPower) {
-		power.setP(power.getP().add(currentPower.getP()).abs());
-		power.setQ(power.getQ().add(currentPower.getQ()));
-		power.setPf(power.getPf().add(currentPower.getPf()).abs());
-		return power;
-	}
-
-
-	/**
-	 * 最小监控点(没有子节点)的24时整点数据
-	 * @param terminalId
-	 * @return
-	 */
-	private List<OnlineDataPower> get24HDataForTerminalIdAndGetTime(String terminalId,String dateStr) {
-		List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
-		long start = DateUtil.str2MonitorDate(dateStr,dateStr.length());
-		dateStr = dateStr + " 00:00:00";
-		Date date = DateUtil.str2Date(dateStr, DateUtil.START_TIME_FORMAT);
-		Date endDate = DateUtil.addDays(date, 1);
-		long end = DateUtil.date2Monitortime(endDate);
-		List<OnlineDataPower> oneDayData = onlineDataPowerDao.selectByTerminalIdAndGetTime(terminalId, start, end); //取一天的数据
-		for(OnlineDataPower p : oneDayData){
-			for(int i=1;i<= DateUtil.HOUR_ONE_DAY;i++) { //循环得到24个整点时间点
-				Timestamp timestamp = DateUtil.dateAddHour(date, i);
-				Date hourDate = DateUtil.timestramp2Date(timestamp, DateUtil.TIME_24H_FORMAT);
-				String hourDateStr = DateUtil.date2Str(hourDate, DateUtil.MONITOR_DATATIME_FORMAT);
-				long datetime = Long.valueOf(hourDateStr); //每隔5分钟的时间
-				if(datetime == p.getGetTime()){
-					temp.add(p);
-				}
-			}
-		}
-		return temp;		
-	}
-
-	/**
-	 * 根据监测点获取监测点下面的所有子监测点
-	 * @param terminalId
-	 * @return
-	 */
-	private List<Monitor> getSubMonitors(Monitor monitor){
-		List<Monitor> temp = monitorDao.selectByParentId(monitor.getId()); //所有子监测点
-		return temp;
-	}
-
-	/**
-	 * 根据时间获取记录
-	 */
-	@Override
-	public ResultMsg<OnlineDataPower> getOnlineDataPower(String local,long monitorId, Long time) {
-		result = checkMonitor(local,monitorId);
-		if(result.getStatus() != SystemConstant.RESULT_PARAM_ERROR) {
-			OnlineDataPower power = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), time);
-			if(monitor.getSeeType() == EmDistributionType.virtual.value) {//虚拟监测点需要把总负荷 总无功 总功率因数加起来
-				List<Monitor> subMonitors = getSubMonitors(monitor); //获取子监测点
-				if(subMonitors.size() > 0) {
-					Map<Long,OnlineDataPower> pMap = new HashMap<Long,OnlineDataPower>();//定义存储时间点负荷的Map
-					for(Monitor sub : subMonitors) { //每个监测点当前时间的数据
-						OnlineDataPower dataPower = onlineDataPowerDao.selectByTerminalIdAndGetTime(sub.getTerminalId(), time);
-						if(pMap.isEmpty()) {
-							pMap.put(power.getGetTime(), power);
-						} else {
-							OnlineDataPower currentP = pMap.get(power.getGetTime()); //已经存储的OnlineDataPower
-							pMap.put(power.getGetTime(), rebuildOnlineDataPower(currentP,dataPower));//重构某个整点时间点的子监测点的总负荷,总无功,总功率因数,循环添加
-						}
-					}
-
-					OnlineDataPower tempPower = pMap.get(power.getGetTime());
-					power.setP(tempPower.getP().abs()); //重置总负荷
-					power.setQ(tempPower.getQ()); //重置总无功
-					power.setPf(tempPower.getPf().abs()); //重置总功率因数
-				}
-			}
-
-			power = power.rebuildOnlineDataPower(monitor,power);
-			result.setData(power);
-			message = getLocalMessage(local,"onlinedatapower_record_success");
-			result.setMsg(message);
-		}
-
-		return result;
-	}
-
-	/**
-	 * 获取时间段内的所有数据
-	 */
-	@Override
-	public ResultMsg<List<OnlineDataPower>> getForBetweenTime(String local,long monitorId,long start,long end) {
-		resultForList = checkMonitorForList(local, monitorId);
-		if(resultForList.getStatus() != SystemConstant.RESULT_PARAM_ERROR){
-			List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), start, end);//当前监测点的整点数据
-			resultForList.setData(onlineDataPowerList);
-			message = getLocalMessage(local,"onlinedatapower_success");
-			resultForList.setMsg(message);
-		}
-		return resultForList;
-	}
-
-	@Override
-	public ResultMsg<List<OnlineDataPower>> getForOneDay(String local, long id, String dateString,String type) {
-		ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
-		List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
-		//企业负荷
-		if(null != type && "company".equals(type)){
-			Org org = orgDao.selectById(id);
-			if(null == org){
-				result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
-				message = getLocalMessage(local,"monitor_error");
-			}
-			List<Monitor> monitorList = monitorDao.selectByCompanyId(id);
-
-			if(monitorList.isEmpty() || monitorList.size() < 1){
-				result.setStatus(SystemConstant.RESULT_STATUS_ERROR);
-				message = getLocalMessage(local,"monitor_error");
-			}
-			Map<String,Monitor> monitorByTerminalId = new HashMap<String,Monitor>();
-			for(Monitor m:monitorList){
-				monitorByTerminalId.put(m.getTerminalId(), m);
-			}
-			
-			List<OnlineDataPower> onlineDataPowerList = companyOnlineDataPowerService.getOnlineDataPowerByDay(local, id, dateString);
-			temp.addAll(onlineDataPowerList);
+public class OnlineDataPowerService extends BaseService<OnlineDataPower> implements IOnlineDataPowerService {
+
+    static Logger logger = Logger.getLogger(OnlineDataPowerService.class);
+
+    @Autowired
+    OrgDao orgDao;
+    @Autowired
+    OnlineDataPowerDao onlineDataPowerDao;
+    @Autowired
+    MonitorDao monitorDao;
+    @Autowired
+    MonitorPowerUnitDao mpuDao; //用电单元dao
+    @Autowired
+    CompanyOnlineDataPowerService companyOnlineDataPowerService;
+
+    /**
+     * yyyyMMddHHmmss类型的日期转为MM-dd HH:mm
+     *
+     * @param time
+     * @return
+     */
+    public static String getYmsToDefaultDate(long time) {
+        String oldTime = Long.toString(time);
+        String month = oldTime.substring(4, 6);
+        String day = oldTime.substring(6, 8);
+        String hour = oldTime.substring(8, 10);
+        String mi = oldTime.substring(10, 12);
+        return month + "月" + day + "日 " + hour + ":" + mi;
+    }
+
+    /**
+     * yyyyMMddHHmmss类型的日期转为yyyy-MM-dd
+     *
+     * @param time
+     * @return
+     */
+    public static String getDatetimeToDate(String time) {
+        String year = time.substring(0, 4);
+        String month = time.substring(4, 6);
+        String day = time.substring(6, 8);
+        return year + "-" + month + "-" + day;
+    }
+
+    /**
+     * 计算两个日期相差的天数
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static int daysBetween(String startDate, String endDate) {
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(sdf.parse(startDate));
+            long time1 = cal.getTimeInMillis();
+            cal.setTime(sdf.parse(endDate));
+            long time2 = cal.getTimeInMillis();
+            long between_days = (time2 - time1) / (1000 * 3600 * 24);
+            return Integer.parseInt(String.valueOf(between_days));
+        } catch (Exception e) {
+            return 0;
+        }
+    }
+
+    /**
+     * 监测点一天二十四小时的整点数据
+     */
+    @Override
+    public ResultMsg<List<OnlineDataPower>> getFor24H(String local, long monitorId, String date) {
+        resultForList = checkMonitorForList(local, monitorId);
+        if (resultForList.getStatus() != SystemConstant.RESULT_PARAM_ERROR) {
+            List<OnlineDataPower> onlineDataPowerList = get24HDataForTerminalIdAndGetTime(monitor.getTerminalId(), date);//当前监测点的整点数据
+            List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
+            if (monitor.getSeeType() == EmDistributionType.virtual.value) { //虚拟节点
+                List<Monitor> subMonitors = getSubMonitors(monitor); //获取子监测点
+                Map<Long, OnlineDataPower> pMap = new HashMap<Long, OnlineDataPower>();//定义存储时间点负荷的Map
+                if (subMonitors.size() > 0) {
+                    for (Monitor sub : subMonitors) {
+                        List<OnlineDataPower> subMonitorOnlineDataPowerList = get24HDataForTerminalIdAndGetTime(sub.getTerminalId(), date);//子监测点的整点数据
+                        for (Iterator<OnlineDataPower> it = subMonitorOnlineDataPowerList.iterator(); it.hasNext(); ) {
+                            //处理每个时间整点的数据
+                            OnlineDataPower data = it.next();
+                            data.setP(data.getPa().add(data.getPb()).add(data.getPc()).abs()); //总负荷
+                            data.setQ(data.getQa().add(data.getQb()).add(data.getQc())); //总无功
+                            data.setPf(data.getPfa().add(data.getPfb()).add(data.getPfb()).abs());//总功率因素
+                            it.remove();//移除旧的数据
+                            subMonitorOnlineDataPowerList.add(data); //重新整理了总负荷
+                            if (pMap.isEmpty()) {
+                                pMap.put(data.getGetTime(), data);
+                            } else {
+                                OnlineDataPower currentP = pMap.get(data.getGetTime()); //已经存储的OnlineDataPower
+                                pMap.put(data.getGetTime(), rebuildOnlineDataPower(currentP, data));//重构某个整点时间点的子监测点的总负荷,总无功,总功率因数,循环添加
+                            }
+                        }
+                    }
+                }
+                //这里的pMap已经将所有的子检测点的总负荷处理过,迭代监测点重置总负荷
+                for (Iterator<OnlineDataPower> iterator = onlineDataPowerList.iterator(); iterator.hasNext(); ) {
+                    OnlineDataPower power = iterator.next();
+                    OnlineDataPower memoryPower = pMap.get(power.getGetTime());
+                    power.setP(memoryPower.getP()); //重置总负荷
+                    power.setQ(memoryPower.getQ()); //重置总无功
+                    power.setPf(memoryPower.getPf()); //重置总功率因数
+                    iterator.remove();
+                    temp.add(power.rebuildOnlineDataPower(monitor, power)); //这里父监测的所有数据已被处理过
+                }
+            } else {
+                for (OnlineDataPower power : onlineDataPowerList) {
+                    temp.add(power.rebuildOnlineDataPower(monitor, power));
+                }
+            }
+            resultForList.setData(temp);
+            message = getLocalMessage(local, "onlinedatapower_success");
+            resultForList.setMsg(message);
+        }
+        return resultForList;
+    }
+
+    /**
+     * 子监测点内总负荷,总无功,总功率因素
+     *
+     * @param power
+     * @param currentPower
+     * @return
+     */
+    private OnlineDataPower rebuildOnlineDataPower(OnlineDataPower power, OnlineDataPower currentPower) {
+        power.setP(power.getP().add(currentPower.getP()).abs());
+        power.setQ(power.getQ().add(currentPower.getQ()));
+        power.setPf(power.getPf().add(currentPower.getPf()).abs());
+        return power;
+    }
+
+    /**
+     * 最小监控点(没有子节点)的24时整点数据
+     *
+     * @param terminalId
+     * @return
+     */
+    private List<OnlineDataPower> get24HDataForTerminalIdAndGetTime(String terminalId, String dateStr) {
+        List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
+        long start = DateUtil.str2MonitorDate(dateStr, dateStr.length());
+        dateStr = dateStr + " 00:00:00";
+        Date date = DateUtil.str2Date(dateStr, DateUtil.START_TIME_FORMAT);
+        Date endDate = DateUtil.addDays(date, 1);
+        long end = DateUtil.date2Monitortime(endDate);
+        List<OnlineDataPower> oneDayData = onlineDataPowerDao.selectByTerminalIdAndGetTime(terminalId, start, end); //取一天的数据
+        for (OnlineDataPower p : oneDayData) {
+            for (int i = 1; i <= DateUtil.HOUR_ONE_DAY; i++) { //循环得到24个整点时间点
+                Timestamp timestamp = DateUtil.dateAddHour(date, i);
+                Date hourDate = DateUtil.timestramp2Date(timestamp, DateUtil.TIME_24H_FORMAT);
+                String hourDateStr = DateUtil.date2Str(hourDate, DateUtil.MONITOR_DATATIME_FORMAT);
+                long datetime = Long.valueOf(hourDateStr); //每隔5分钟的时间
+                if (datetime == p.getGetTime()) {
+                    temp.add(p);
+                }
+            }
+        }
+        return temp;
+    }
+
+    /**
+     * 根据监测点获取监测点下面的所有子监测点
+     */
+    private List<Monitor> getSubMonitors(Monitor monitor) {
+        List<Monitor> temp = monitorDao.selectByParentId(monitor.getId()); //所有子监测点
+        return temp;
+    }
+
+    /**
+     * 根据时间获取记录
+     */
+    @Override
+    public ResultMsg<OnlineDataPower> getOnlineDataPower(String local, long monitorId, Long time) {
+        result = checkMonitor(local, monitorId);
+        if (result.getStatus() != SystemConstant.RESULT_PARAM_ERROR) {
+            OnlineDataPower power = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), time);
+            if (monitor.getSeeType() == EmDistributionType.virtual.value) {//虚拟监测点需要把总负荷 总无功 总功率因数加起来
+                List<Monitor> subMonitors = getSubMonitors(monitor); //获取子监测点
+                if (subMonitors.size() > 0) {
+                    Map<Long, OnlineDataPower> pMap = new HashMap<Long, OnlineDataPower>();//定义存储时间点负荷的Map
+                    for (Monitor sub : subMonitors) { //每个监测点当前时间的数据
+                        OnlineDataPower dataPower = onlineDataPowerDao.selectByTerminalIdAndGetTime(sub.getTerminalId(), time);
+                        if (pMap.isEmpty()) {
+                            pMap.put(power.getGetTime(), power);
+                        } else {
+                            OnlineDataPower currentP = pMap.get(power.getGetTime()); //已经存储的OnlineDataPower
+                            pMap.put(power.getGetTime(), rebuildOnlineDataPower(currentP, dataPower));//重构某个整点时间点的子监测点的总负荷,总无功,总功率因数,循环添加
+                        }
+                    }
+
+                    OnlineDataPower tempPower = pMap.get(power.getGetTime());
+                    power.setP(tempPower.getP().abs()); //重置总负荷
+                    power.setQ(tempPower.getQ()); //重置总无功
+                    power.setPf(tempPower.getPf().abs()); //重置总功率因数
+                }
+            }
+
+            power = power.rebuildOnlineDataPower(monitor, power);
+            result.setData(power);
+            message = getLocalMessage(local, "onlinedatapower_record_success");
+            result.setMsg(message);
+        }
+
+        return result;
+    }
+
+    /**
+     * 获取时间段内的所有数据
+     */
+    @Override
+    public ResultMsg<List<OnlineDataPower>> getForBetweenTime(String local, long monitorId, long start, long end) {
+        resultForList = checkMonitorForList(local, monitorId);
+        if (resultForList.getStatus() != SystemConstant.RESULT_PARAM_ERROR) {
+            List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), start, end);//当前监测点的整点数据
+            resultForList.setData(onlineDataPowerList);
+            message = getLocalMessage(local, "onlinedatapower_success");
+            resultForList.setMsg(message);
+        }
+        return resultForList;
+    }
+
+    @Override
+    public ResultMsg<List<OnlineDataPower>> getForOneDay(String local, long id, String dateString, String type) {
+        ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
+        List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
+        //企业负荷
+        if ("company".equals(type)) {
+            Org org = orgDao.selectById(id);
+            if (null == org) {
+                result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
+                message = getLocalMessage(local, "monitor_error");
+            }
+            List<Monitor> monitorList = monitorDao.selectByCompanyId(id);
+
+            if (monitorList.isEmpty() || monitorList.size() < 1) {
+                result.setStatus(SystemConstant.RESULT_STATUS_ERROR);
+                message = getLocalMessage(local, "monitor_error");
+            }
+            Map<String, Monitor> monitorByTerminalId = new HashMap<String, Monitor>();
+            for (Monitor m : monitorList) {
+                monitorByTerminalId.put(m.getTerminalId(), m);
+            }
+
+            List<OnlineDataPower> onlineDataPowerList = companyOnlineDataPowerService.getOnlineDataPowerByDay(local, id, dateString);
+            temp.addAll(onlineDataPowerList);
 			/*//ct pt
 			for(OnlineDataPower power:onlineDataPowerList) {
 				OnlineDataPower data = power.rebuildOnlineDataPower(monitorByTerminalId.get(power.getTerminalId()), power);
 				temp.add(data);
 			}*/
-		}
-		//监测点负荷
-		else{
-			Monitor monitor = monitorDao.selectById(id);
-			if(monitor != null){
-				long startTime = DateUtil.str2MonitorDate(dateString,dateString.length());
-				long endTime =  DateUtil.str2MonitorDate(dateString, 1 ,10);
-				if(monitor.getSeeType().equals(EmDistributionType.virtual.value)) { //虚拟节点
-					List<Monitor> monitorList = monitorDao.selectByParentId(id);
-					temp = buildSubMonitorOnlineDataPowerData(monitorList, startTime, endTime);
-				} else {
-					List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), startTime, endTime);//当前监测点的整点数据
-					//ct pt
-					for(OnlineDataPower power:onlineDataPowerList) {
-						OnlineDataPower data = power.rebuildOnlineDataPower(monitor, power);
-						temp.add(data);
-					}
-				}
-			} else {
-				result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
-				message = getLocalMessage(local,"monitor_error");
-			}
-		}
-		result.setData(temp);
-		message = getLocalMessage(local,"onlinedatapower_success");
-		result.setMsg(message);
-		return result;
-	}
-
-
-	@Override
-	public ResultMsg<List<OnlineDataPower>> getForOneDay(String local, long id, String dateString) {
-		ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
-		List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
-		Monitor monitor = monitorDao.selectById(id);
-		if(monitor != null){
-			long startTime = DateUtil.str2MonitorDate(dateString,dateString.length());
-			long endTime =  DateUtil.str2MonitorDate(dateString, 1 ,10);
-			if(monitor.getSeeType().equals(EmDistributionType.virtual.value)) { //虚拟节点
-				List<Monitor> monitorList = monitorDao.selectByParentId(id);
-				temp = buildSubMonitorOnlineDataPowerData(monitorList, startTime, endTime);
-			} else {
-				List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), startTime, endTime);//当前监测点的整点数据
-				//ct pt
-				for(OnlineDataPower power:onlineDataPowerList) {
-					OnlineDataPower data = power.rebuildOnlineDataPower(monitor, power);
-					temp.add(data);
-				}
-			}
-		} else {
-			result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
-			message = getLocalMessage(local,"monitor_error");
-		}
-		result.setData(temp);
-		message = getLocalMessage(local,"onlinedatapower_success");
-		result.setMsg(message);
-		return result;
-	}
-
-	/**
-	 * 构建监测点子节点数据
-	 * @param monitorId
-	 * @param today
-	 * @return
-	 */
-	private List<OnlineDataPower> buildSubMonitorOnlineDataPowerData(List<Monitor> monitorList, long startTime, long endTime){
-		List<OnlineDataPower> resultList = new ArrayList<OnlineDataPower>();
-		Map<Long,OnlineDataPower> pMap = new LinkedHashMap<Long,OnlineDataPower>();//定义存储时间点负荷的Map
-		if(monitorList.size() > 0) {
-			for(Monitor subMonitor : monitorList) {
-				List<OnlineDataPower> subList = onlineDataPowerDao.selectByTerminalIdAndGetTime(subMonitor.getTerminalId(), startTime, endTime);//子监测点的数据
-				for(OnlineDataPower data : subList) { 
-					AnalDataCtPtUtil.addCtPt(subMonitor, data);
-					if(pMap.containsKey(data.getGetTime())) {
-						OnlineDataPower current = pMap.get(data.getGetTime()); //已经存储的OnlineDataEnergy
-						pMap.put(data.getGetTime(), rebuildOnlineDataEnergy(current,data));//重构某个整点时间点的子监测点的各相电量,循环添加
-					} else {
-						pMap.put(data.getGetTime(), data);
-					}
-				}
-			}
-		}
-		
-		//这里的pMap已经将所有的子检测点的各相电量处理过,迭代监测点重置各相电量
-		for(Map.Entry<Long,OnlineDataPower> entry : pMap.entrySet()){
-			OnlineDataPower energy = new OnlineDataPower();
-			OnlineDataPower memoryEnergy = entry.getValue();
-			energy.setGetTime(entry.getKey());
-			energy.setP(memoryEnergy.getP());
-			energy.setPa(memoryEnergy.getPa());
-			energy.setPb(memoryEnergy.getPb());
-			energy.setPc(memoryEnergy.getPc());
-
-			resultList.add(energy); //这里父监测的所有数据已被处理过
-		}
-		
-		return resultList;
-	}
-	
-	/**
-	 * 子监测点内正相有功电量,正相无功电量,反相有功电量,反相无功电量相加
-	 * @param power
-	 * @param currentPower
-	 * @return
-	 */
-	private OnlineDataPower rebuildOnlineDataEnergy(OnlineDataPower energy,OnlineDataPower current) {
-		energy.setP(energy.getP().add(current.getP()));
-		energy.setPa(energy.getPa().add(current.getPa()));
-		energy.setPb(energy.getPb().add(current.getPb()));
-		energy.setPc(energy.getPc().add(current.getPc()));
-		return energy;
-	}
-	
-	@Override
-	public ResultMsg<List<OnlineDataPower>> getPowerUnitFor24H(String local,
-			long unitId, String dateStr) {
-		List<MonitorPowerUnit> monitorList = mpuDao.selectByPowerUnitId(unitId);
-		dateStr = dateStr + " 00:00:00";
-		long start = DateUtil.str2MonitorDate(dateStr,dateStr.length());
-		dateStr = dateStr + " 00:00:00";
-		Date date = DateUtil.str2Date(dateStr, DateUtil.START_TIME_FORMAT);
-		Date endDate = DateUtil.addDays(date, 1);
-		long end = DateUtil.date2Monitortime(endDate);
-		List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
-		List<Long> timeList = new ArrayList<Long>();
-		for(int i=1;i<= DateUtil.HOUR_ONE_DAY;i++) { //循环得到24个整点时间点
-			Timestamp timestamp = DateUtil.dateAddHour(date, i);
-			Date hourDate = DateUtil.timestramp2Date(timestamp, DateUtil.TIME_24H_FORMAT);
-			String hourDateStr = DateUtil.date2Str(hourDate, DateUtil.MONITOR_DATATIME_FORMAT);
-			long datetime = Long.valueOf(hourDateStr); //每隔1小时的时间
-			timeList.add(Long.parseLong(String.valueOf(datetime)));
-		}
-
-		Map<MonitorPowerUnitVo,List<OnlineDataPower>> map = new HashMap<MonitorPowerUnitVo,List<OnlineDataPower>>();
-		for(MonitorPowerUnit mpu:monitorList){
-			long monitorId = mpu.getMonitorId();
-			Monitor monitor = monitorDao.selectById(monitorId);	
-			List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), start, end);;//当前监测点的整点数据
-			MonitorPowerUnitVo vo = new MonitorPowerUnitVo();
-			vo.setMonitor(monitor);
-			vo.setScale(mpu.getScale());
-			map.put(vo, onlineDataPowerList);
-		}
-
-		for(Long getTime: timeList){
-			OnlineDataPower newPower = new OnlineDataPower();
-			newPower.setGetTime(getTime);
-			Set<MonitorPowerUnitVo> mpuSet = map.keySet();
-			Iterator<MonitorPowerUnitVo> iter = mpuSet.iterator();
-			while(iter.hasNext()){
-				MonitorPowerUnitVo mpu = iter.next();
-				Monitor monitor = mpu.getMonitor();
-				List<OnlineDataPower> onlineDataPowerList = map.get(mpu);
-				for(OnlineDataPower power:onlineDataPowerList) {
-					if(newPower.getGetTime().longValue() == power.getGetTime().longValue()) {
-						power = power.rebuildOnlineDataPower(monitor, power);//CT*PT
-						//只需要一个总负荷数据即可
-						BigDecimal powerP = power.getP().multiply(mpu.getScale()).divide(new BigDecimal(100));//按照占比
-						if(newPower.getP() == null) {
-							newPower.setP(powerP);
-						} else {
-							newPower.setP(powerP.add(newPower.getP())); //总负荷 
-						}
-						break;
-					}
-				}	
-			}
-			temp.add(newPower);
-		}
-
-		ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
-		result.setMsg(getLocalMessage(local,"onlinedatapower_success"));
-		result.setData(temp);
-		return result;
-	}
-
-	@Override
-	public ResultMsg<List<OnlineDataPower>> getPowerUnitForOneDay(String local,
-			long unitId, String dateStr) {
-		List<MonitorPowerUnit> monitorList = mpuDao.selectByPowerUnitId(unitId);
-		long start = DateUtil.str2MonitorDate(dateStr,dateStr.length());
-		dateStr = dateStr + " 00:00:00";
-		Date date = DateUtil.str2Date(dateStr, DateUtil.START_TIME_FORMAT);
-		Date endDate = DateUtil.addDays(date, 1);
-		long end = DateUtil.date2Monitortime(endDate);
-		List<Long> timeList = new ArrayList<Long>();
-		timeList.add(start);
-		//这里等到一天所有的数据时间
-		for(int i=1;i<= 288;i++) { //循环得到一天所有的时间点
-			Timestamp timestamp = DateUtil.dateAddMinute(date,i*5);
-			Date hourDate = DateUtil.timestramp2Date(timestamp, DateUtil.DEFAULT_FORMAT);
-			String hourDateStr = DateUtil.date2Str(hourDate, DateUtil.MONITOR_DATATIME_FORMAT);
-			long datetime = Long.valueOf(hourDateStr); //每隔5分钟的时间
-			timeList.add(Long.parseLong(String.valueOf(datetime)));
-		}
-		List<OnlineDataPower> powerList = new ArrayList<OnlineDataPower>();
-		Map<MonitorPowerUnitVo,List<OnlineDataPower>> map = new HashMap<MonitorPowerUnitVo,List<OnlineDataPower>>();
-		for(MonitorPowerUnit mpu:monitorList){
-			long monitorId = mpu.getMonitorId();
-			Monitor monitor = monitorDao.selectById(monitorId);	
-			List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), start, end);;//当前监测点的整点数据
-			MonitorPowerUnitVo vo = new MonitorPowerUnitVo();
-			vo.setMonitor(monitor);
-			vo.setScale(mpu.getScale());
-			map.put(vo, onlineDataPowerList);
-		}
-
-		for(Long getTime: timeList){
-			OnlineDataPower newPower = new OnlineDataPower();
-			newPower.setGetTime(getTime);
-			Set<MonitorPowerUnitVo> mpuSet = map.keySet();
-			Iterator<MonitorPowerUnitVo> iter = mpuSet.iterator();
-			while(iter.hasNext()){
-				MonitorPowerUnitVo mpu = iter.next();
-				Monitor monitor = mpu.getMonitor();
-				List<OnlineDataPower> onlineDataPowerList = map.get(mpu);
-				for(OnlineDataPower power:onlineDataPowerList) {
-					if(newPower.getGetTime().longValue() == power.getGetTime().longValue()) {
-						power = power.rebuildOnlineDataPower(monitor, power);//CT*PT
-						//只需要一个总负荷数据即可
-						BigDecimal powerP = power.getP().multiply(mpu.getScale()).divide(new BigDecimal(100));//按照占比
-						if(newPower.getP() == null) {
-							newPower.setP(powerP);
-						} else {
-							newPower.setP(powerP.add(newPower.getP())); //总负荷 
-						}
-						break;
-					}
-				}	
-			}
-			powerList.add(newPower);
-		}
-
-		ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
-		result.setMsg(getLocalMessage(local,"onlinedatapower_success"));
-		result.setData(powerList);
-
-		return result;
-	}
-
-	@Override
-	public ResultMsg<?> getSectionData(String local, long id, String startTime,
-			String endTime) {
-		ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
-		List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
-		Monitor monitor = monitorDao.selectById(id);
-		if(monitor != null){
-			long t1 = Long.parseLong(DateUtil.long2Str(Long.parseLong(startTime), DateUtil.MONITOR_DATATIME_FORMAT));
-			long t2 = Long.parseLong(DateUtil.long2Str(Long.parseLong(endTime), DateUtil.MONITOR_DATATIME_FORMAT));
-			List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), t1, t2);//当前监测点的整点数据
-			//ct pt
-			for(OnlineDataPower power:onlineDataPowerList) {
-				OnlineDataPower data = power.rebuildOnlineDataPower(monitor, power);
-				temp.add(data);
-			}
-		} else {
-			result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
-			message = getLocalMessage(local,"monitor_error");
-		}
-		result.setData(temp);
-		message = getLocalMessage(local,"onlinedatapower_success");
-		result.setMsg(message);
-		return result;
-	}
-	
- 	// string类型转换为long类型
- 	// strTime要转换的String类型的时间
- 	// formatType时间格式
- 	// strTime的时间格式和formatType的时间格式必须相同
- 	public long stringToLong(String strTime, String formatType){
-		try {
-			SimpleDateFormat formatter = new SimpleDateFormat(formatType);
-			Date date = formatter.parse(strTime);
-			if (date == null) {
-				return 0;
-			} else {
-				long currentTime = date.getTime(); // date类型转成long类型
-				return currentTime;
-			}
-		} catch (ParseException e) {
-			e.printStackTrace();
-		} 
-		return 0;
- 	}
-	
- 	//20170403000500
- 	private long formatDate(long time){
- 		String t = "" + time;
- 		String h = t.substring(8,10);
- 		String m = t.substring(10,12);
- 		String s = t.substring(12,14);
- 		
- 		String datetime = "2000-01-01 " + h + ":" + m + ":" + s;
- 		
- 		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-		try {
-			Date date = formatter.parse(datetime);
-			if (date == null) {
-				return 0;
-			} else {
-				long currentTime = date.getTime(); // date类型转成long类型
-				return currentTime;
-			}
-		} catch (ParseException e) {
-			e.printStackTrace();
-		}
-		return 0;
- 	}
-	
-	
-	@Override
-	public ResultMsg<?> getSectionDataNew(String local, long id, String startTime, String endTime, String seriesName) {
-		ResultMsg<Map<String, JSONObject>> result = new ResultMsg<Map<String, JSONObject>>(SystemConstant.RESULT_STATUS_SUCCESS);
-		Map<String, JSONObject> dataMap = new HashMap<String, JSONObject>();
-		
-		Monitor monitor = monitorDao.selectById(id);
-		if(monitor != null){
-			long t1 = Long.parseLong(DateUtil.long2Str(Long.parseLong(startTime), DateUtil.MONITOR_DATATIME_FORMAT));
-			long t2 = Long.parseLong(DateUtil.long2Str(Long.parseLong(endTime), DateUtil.MONITOR_DATATIME_FORMAT));
-			List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), t1, t2);//当前监测点的整点数据
-			
-			//组装各曲线数据
-			//总负荷曲线
-			JSONObject pJsonObj = new JSONObject();
-			pJsonObj.put("name", seriesName + ":总负荷");
-			List<Object[]> pDataList = new ArrayList<Object[]>();
-			//A相负荷曲线
-			JSONObject paJsonObj = new JSONObject();
-			paJsonObj.put("name", seriesName + ":A相负荷");
-			List<Object[]> paDataList = new ArrayList<Object[]>();
-			//B相负荷曲线
-			JSONObject pbJsonObj = new JSONObject();
-			pbJsonObj.put("name", seriesName + ":B相负荷");
-			List<Object[]> pbDataList = new ArrayList<Object[]>();
-			//C相负荷曲线
-			JSONObject pcJsonObj = new JSONObject();
-			pcJsonObj.put("name", seriesName + ":C相负荷");
-			List<Object[]> pcDataList = new ArrayList<Object[]>();
-			
-			//电压
-			//A相电压曲线
-			JSONObject uaJsonObj = new JSONObject();
-			uaJsonObj.put("name", seriesName + ":A相电压");
-			List<Object[]> uaDataList = new ArrayList<Object[]>();
-			//B相电压曲线
-			JSONObject ubJsonObj = new JSONObject();
-			ubJsonObj.put("name", seriesName + ":B相电压");
-			List<Object[]> ubDataList = new ArrayList<Object[]>();
-			//C相电压曲线
-			JSONObject ucJsonObj = new JSONObject();
-			ucJsonObj.put("name", seriesName + ":C相电压");
-			List<Object[]> ucDataList = new ArrayList<Object[]>();
-			//uab线电压曲线
-			JSONObject uabJsonObj = new JSONObject();
-			uabJsonObj.put("name", seriesName + ":UAB线电压");
-			List<Object[]> uabDataList = new ArrayList<Object[]>();
-			//ubc线电压曲线
-			JSONObject ubcJsonObj = new JSONObject();
-			ubcJsonObj.put("name", seriesName + ":UBC线电压");
-			List<Object[]> ubcDataList = new ArrayList<Object[]>();
-			//uca线电压曲线
-			JSONObject ucaJsonObj = new JSONObject();
-			ucaJsonObj.put("name", seriesName + ":UCA线电压");
-			List<Object[]> ucaDataList = new ArrayList<Object[]>();
-			
-			//电流
-			//A相电流曲线
-			JSONObject iaJsonObj = new JSONObject();
-			iaJsonObj.put("name", seriesName + ":A相电流");
-			List<Object[]> iaDataList = new ArrayList<Object[]>();
-			//B相电流曲线
-			JSONObject ibJsonObj = new JSONObject();
-			ibJsonObj.put("name", seriesName + ":B相电流");
-			List<Object[]> ibDataList = new ArrayList<Object[]>();
-			//C相电流曲线
-			JSONObject icJsonObj = new JSONObject();
-			icJsonObj.put("name", seriesName + ":C相电流");
-			List<Object[]> icDataList = new ArrayList<Object[]>();
-			//零序电流曲线
-			JSONObject izJsonObj = new JSONObject();
-			izJsonObj.put("name", seriesName + ":零线电流");
-			List<Object[]> izDataList = new ArrayList<Object[]>();
-			
-			//ct pt
-			for(OnlineDataPower power:onlineDataPowerList) {
-				OnlineDataPower data = power.rebuildOnlineDataPower(monitor, power);
-				long getTime = data.getGetTime();
-				long time = formatDate(getTime);
-				
-				BigDecimal pa = data.getPa();// A相负荷
-				BigDecimal pb = data.getPb();// B相负荷
-				BigDecimal pc = data.getPc();// C相负荷
-				BigDecimal p = data.getP();// 总负荷
-				BigDecimal ua = data.getUa();// A相电压
-				BigDecimal ub = data.getUb();// B相电压
-				BigDecimal uc = data.getUc();// C相电压
-				BigDecimal uab = data.getUab();// Uab线电压
-				BigDecimal ubc = data.getUbc();// Ubc线电压
-				BigDecimal uca = data.getUca();// Uca线电压
-				BigDecimal ia = data.getIa();// A相电流
-				BigDecimal ib = data.getIb();// B相电流
-				BigDecimal ic = data.getIc();// C相电流
-				BigDecimal iz = data.getIz();// 零序电流
-				
-				Object[] pObject = new Object[]{time, p};
-				pDataList.add(pObject);
-				
-				Object[] paObject = new Object[]{time, pa};
-				paDataList.add(paObject);
-				
-				Object[] pbObject = new Object[]{time, pb};
-				pbDataList.add(pbObject);
-				
-				Object[] pcObject = new Object[]{time, pc};
-				pcDataList.add(pcObject);
-				
-				Object[] uaObject = new Object[]{time, ua};
-				uaDataList.add(uaObject);
-				
-				Object[] ubObject = new Object[]{time, ub};
-				ubDataList.add(ubObject);
-				
-				Object[] ucObject = new Object[]{time, uc};
-				ucDataList.add(ucObject);
-				
-				Object[] uabObject = new Object[]{time, uab};
-				uabDataList.add(uabObject);
-				
-				Object[] ubcObject = new Object[]{time, ubc};
-				ubcDataList.add(ubcObject);
-				
-				Object[] ucaObject = new Object[]{time, uca};
-				ucaDataList.add(ucaObject);
-				
-				Object[] iaObject = new Object[]{time, ia};
-				iaDataList.add(iaObject);
-				
-				Object[] ibObject = new Object[]{time, ib};
-				ibDataList.add(ibObject);
-				
-				Object[] icObject = new Object[]{time, ic};
-				icDataList.add(icObject);
-				
-				Object[] izObject = new Object[]{time, iz};
-				izDataList.add(izObject);
-			}
-			pJsonObj.put("data", pDataList);
-			paJsonObj.put("data", paDataList);
-			pbJsonObj.put("data", pbDataList);
-			pcJsonObj.put("data", pcDataList);
-			
-			uaJsonObj.put("data", uaDataList);
-			ubJsonObj.put("data", ubDataList);
-			ucJsonObj.put("data", ucDataList);
-			uabJsonObj.put("data", uabDataList);
-			ubcJsonObj.put("data", ubcDataList);
-			ucaJsonObj.put("data", ucaDataList);
-			
-			iaJsonObj.put("data", iaDataList);
-			ibJsonObj.put("data", ibDataList);
-			icJsonObj.put("data", icDataList);
-			izJsonObj.put("data", izDataList);
-			
-			dataMap.put("P", pJsonObj);
-			dataMap.put("PA", paJsonObj);
-			dataMap.put("PB", pbJsonObj);
-			dataMap.put("PC", pcJsonObj);
-			
-			dataMap.put("UA", uaJsonObj);
-			dataMap.put("UB", ubJsonObj);
-			dataMap.put("UC", ucJsonObj);
-			dataMap.put("UAB", uabJsonObj);
-			dataMap.put("UBC", ubcJsonObj);
-			dataMap.put("UCA", ucaJsonObj);
-			
-			dataMap.put("IA", iaJsonObj);
-			dataMap.put("IB", ibJsonObj);
-			dataMap.put("IC", icJsonObj);
-			dataMap.put("IZ", izJsonObj);
-			
-		} else {
-			result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
-			message = getLocalMessage(local,"monitor_error");
-		}
-		result.setData(dataMap);
-		message = getLocalMessage(local,"onlinedatapower_success");
-		result.setMsg(message);
-		return result;
-	}
-	
-
-	/**
-	 * yyyyMMddHHmmss类型的日期转为MM-dd HH:mm
-	 * @param time
-	 * @return
-	 */
-	public static String getYmsToDefaultDate(long time){
-		String oldTime = Long.toString(time);
-		String month = oldTime.substring(4, 6);
-		String day = oldTime.substring(6, 8);
-		String hour = oldTime.substring(8, 10);
-		String mi = oldTime.substring(10, 12);
-		return month + "月" + day + "日 " + hour + ":" + mi;
-	}
-	
-	/**
-	 * yyyyMMddHHmmss类型的日期转为yyyy-MM-dd
-	 * @param time
-	 * @return
-	 */
-	public static String getDatetimeToDate(String time){
-		String year = time.substring(0, 4);
-		String month = time.substring(4, 6);
-		String day = time.substring(6, 8);
-		return year + "-" + month + "-" + day;
-	}
-	
-	/**
-	 * 计算两个日期相差的天数
-	 * @param startDate
-	 * @param endDate
-	 * @return
-	 */
-	public static int daysBetween(String startDate,String endDate){
-		try {
-			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
-			Calendar cal = Calendar.getInstance();
-			cal.setTime(sdf.parse(startDate));
-			long time1 = cal.getTimeInMillis();
-			cal.setTime(sdf.parse(endDate));
-			long time2 = cal.getTimeInMillis();
-			long between_days=(time2-time1)/(1000*3600*24);
-			return Integer.parseInt(String.valueOf(between_days));
-		} catch (Exception e) {
-			return 0;
-		}
+        }
+        //监测点负荷
+        else {
+            temp = buildMonitorOnlineDataByMonitorId(local, id, dateString);
+        }
+        result.setData(temp);
+        message = getLocalMessage(local, "onlinedatapower_success");
+        result.setMsg(message);
+        return result;
+    }
+
+    /**
+     * 获取一些监测点某一天的数据
+     */
+    @Override
+    public ResultMsg<Map<String, List<OnlineDataPower>>> getOneDayDataByIds(String local, String ids, String dateString) {
+        ResultMsg<Map<String, List<OnlineDataPower>>> result = new ResultMsg<Map<String, List<OnlineDataPower>>>(SystemConstant.RESULT_STATUS_SUCCESS);
+        Map<String, List<OnlineDataPower>> map = new HashMap<String, List<OnlineDataPower>>();
+        if (ids != null && !ids.isEmpty()) {
+            String[] idArr = ids.split(",");
+            for (String idStr : idArr) {
+                long id = Long.parseLong(idStr);
+                Monitor monitor = monitorDao.selectById(id);
+                List<OnlineDataPower> list = buildMonitorOnlineDataByMonitor(local, monitor, dateString);
+                map.put(idStr, list);
+            }
+        }
+        result.setData(map);
+        message = getLocalMessage(local, "onlinedatapower_success");
+        result.setMsg(message);
+        return result;
+    }
+
+    private List<OnlineDataPower> buildMonitorOnlineDataByMonitorId(String local, Long id, String dateString) {
+        Monitor monitor = monitorDao.selectById(id);
+        return buildMonitorOnlineDataByMonitor(local, monitor, dateString);
     }
 
-	@Override
-	public ResultMsg<?> getManyDaySectionData(String local, long id, String startTimeFirst, String endTimeFirst, String startTimeSecond, String endTimeSecond) {
-		ResultMsg<JSONObject> result = new ResultMsg<JSONObject>(SystemConstant.RESULT_STATUS_SUCCESS);
-		
-		String startDate = getDatetimeToDate(DateUtil.long2Str(Long.parseLong(startTimeFirst), DateUtil.MONITOR_DATATIME_FORMAT));
-		String endDate = getDatetimeToDate(DateUtil.long2Str(Long.parseLong(endTimeFirst), DateUtil.MONITOR_DATATIME_FORMAT));
-		//日期相差几天
-		int dateDiff = daysBetween(startDate, endDate);
-		
-		java.text.DateFormat dateFormat = new SimpleDateFormat("MM月dd日 HH:mm");
-		/*****************每个节点的日期、时间数据组装start*****************/
-		List<String> datetimeList = new ArrayList<String>();
-		//总节点数(每天288个点,乘以天数)
-		int count = (dateDiff+1) * 288;
-		
-		Calendar cal = Calendar.getInstance();
-		cal.setTimeInMillis(Long.parseLong(startTimeFirst));
-		String first = dateFormat.format(cal.getTime());
-		
-		Calendar cal1 = Calendar.getInstance();
-		cal1.setTimeInMillis(Long.parseLong(startTimeSecond));
-		String second = dateFormat.format(cal1.getTime());
-		
-		datetimeList.add(first + "&" + second);
-		for(int i=1; i<count; i++){
-			cal.add(Calendar.MINUTE, 5);
-			cal1.add(Calendar.MINUTE, 5);
-			
-			String first_i = dateFormat.format(cal.getTime());
-			String second_i = dateFormat.format(cal1.getTime());
-			datetimeList.add(first_i + "&" + second_i);
-		}
-		/*****************每个节点的日期、时间数据组装数据组装end*****************/
-		
-		Map<String, JSONObject> firstDataMap = new HashMap<String, JSONObject>();
-		Map<String, JSONObject> secondDataMap = new HashMap<String, JSONObject>();
-
-		//输出到页面的x轴
-		List<String> xaixss = new ArrayList<String>();
-		Monitor monitor = monitorDao.selectById(id);
-		if(monitor != null){
-			//安装前数据
-			long stf = Long.parseLong(DateUtil.long2Str(Long.parseLong(startTimeFirst), DateUtil.MONITOR_DATATIME_FORMAT));
-			long etf = Long.parseLong(DateUtil.long2Str(Long.parseLong(endTimeFirst), DateUtil.MONITOR_DATATIME_FORMAT));
-			List<OnlineDataPower> onlineDataPowerFirstList = onlineDataPowerDao.selectManyDayData(monitor.getTerminalId(), stf, etf);//当前监测点的整点数据
-			Map<String, OnlineDataPower> beforeDataMap = new HashMap<String, OnlineDataPower>();
-			for(OnlineDataPower model : onlineDataPowerFirstList){
-				String dateTime = getYmsToDefaultDate(model.getGetTime());
-				OnlineDataPower power = model.rebuildOnlineDataPower(monitor, model);
-				beforeDataMap.put(dateTime, power);
-			}
-			
-			//安装后数据
-			long sts = Long.parseLong(DateUtil.long2Str(Long.parseLong(startTimeSecond), DateUtil.MONITOR_DATATIME_FORMAT));
-			long ets = Long.parseLong(DateUtil.long2Str(Long.parseLong(endTimeSecond), DateUtil.MONITOR_DATATIME_FORMAT));
-			List<OnlineDataPower> onlineDataPowerSecondList = onlineDataPowerDao.selectManyDayData(monitor.getTerminalId(), sts, ets);//当前监测点的整点数据
-			Map<String, OnlineDataPower> afterDataMap = new HashMap<String, OnlineDataPower>();
-			for(OnlineDataPower model : onlineDataPowerSecondList){
-				String dateTime = getYmsToDefaultDate(model.getGetTime());
-				OnlineDataPower power = model.rebuildOnlineDataPower(monitor, model);
-				afterDataMap.put(dateTime, power);
-			}
-			
-
-			//组装"安装前"各曲线数据
-			//总负荷曲线
-			
-			JSONObject pJsonObj = new JSONObject();
-			pJsonObj.put("name", "安装前:总负荷");
-			List<Double> pDataList = new ArrayList<Double>();
-			//A相负荷曲线
-			JSONObject paJsonObj = new JSONObject();
-			paJsonObj.put("name", "安装前:A相负荷");
-			List<Double> paDataList = new ArrayList<Double>();
-			//B相负荷曲线
-			JSONObject pbJsonObj = new JSONObject();
-			pbJsonObj.put("name", "安装前:B相负荷");
-			List<Double> pbDataList = new ArrayList<Double>();
-			//C相负荷曲线
-			JSONObject pcJsonObj = new JSONObject();
-			pcJsonObj.put("name", "安装前:C相负荷");
-			List<Double> pcDataList = new ArrayList<Double>();
-			
-			//电压
-			//A相电压曲线
-			JSONObject uaJsonObj = new JSONObject();
-			uaJsonObj.put("name", "安装前:A相电压");
-			List<Double> uaDataList = new ArrayList<Double>();
-			//B相电压曲线
-			JSONObject ubJsonObj = new JSONObject();
-			ubJsonObj.put("name", "安装前:B相电压");
-			List<Double> ubDataList = new ArrayList<Double>();
-			//C相电压曲线
-			JSONObject ucJsonObj = new JSONObject();
-			ucJsonObj.put("name", "安装前:C相电压");
-			List<Double> ucDataList = new ArrayList<Double>();
-			//uab线电压曲线
-			JSONObject uabJsonObj = new JSONObject();
-			uabJsonObj.put("name", "安装前:UAB线电压");
-			List<Double> uabDataList = new ArrayList<Double>();
-			//ubc线电压曲线
-			JSONObject ubcJsonObj = new JSONObject();
-			ubcJsonObj.put("name", "安装前:UBC线电压");
-			List<Double> ubcDataList = new ArrayList<Double>();
-			//uca线电压曲线
-			JSONObject ucaJsonObj = new JSONObject();
-			ucaJsonObj.put("name", "安装前:UCA线电压");
-			List<Double> ucaDataList = new ArrayList<Double>();
-			
-			//电流
-			//A相电流曲线
-			JSONObject iaJsonObj = new JSONObject();
-			iaJsonObj.put("name", "安装前:A相电流");
-			List<Double> iaDataList = new ArrayList<Double>();
-			//B相电流曲线
-			JSONObject ibJsonObj = new JSONObject();
-			ibJsonObj.put("name", "安装前:B相电流");
-			List<Double> ibDataList = new ArrayList<Double>();
-			//C相电流曲线
-			JSONObject icJsonObj = new JSONObject();
-			icJsonObj.put("name", "安装前:C相电流");
-			List<Double> icDataList = new ArrayList<Double>();
-			//零序电流曲线
-			JSONObject izJsonObj = new JSONObject();
-			izJsonObj.put("name", "安装前:零线电流");
-			List<Double> izDataList = new ArrayList<Double>();
-			
-			
-			//组装"安装后"各曲线数据
-			//总负荷曲线
-			JSONObject pJsonObjAfter = new JSONObject();
-			pJsonObjAfter.put("name", "安装后:总负荷");
-			List<Double> pDataAfterList = new ArrayList<Double>();
-			//A相负荷曲线
-			JSONObject paJsonObjAfter = new JSONObject();
-			paJsonObjAfter.put("name", "安装后:A相负荷");
-			List<Double> paDataAfterList = new ArrayList<Double>();
-			//B相负荷曲线
-			JSONObject pbJsonObjAfter = new JSONObject();
-			pbJsonObjAfter.put("name", "安装后:B相负荷");
-			List<Double> pbDataAfterList = new ArrayList<Double>();
-			//C相负荷曲线
-			JSONObject pcJsonObjAfter = new JSONObject();
-			pcJsonObjAfter.put("name", "安装后:C相负荷");
-			List<Double> pcDataAfterList = new ArrayList<Double>();
-			
-			//电压
-			//A相电压曲线
-			JSONObject uaJsonObjAfter = new JSONObject();
-			uaJsonObjAfter.put("name", "安装后:A相电压");
-			List<Double> uaDataAfterList = new ArrayList<Double>();
-			//B相电压曲线
-			JSONObject ubJsonObjAfter = new JSONObject();
-			ubJsonObjAfter.put("name", "安装后:B相电压");
-			List<Double> ubDataAfterList = new ArrayList<Double>();
-			//C相电压曲线
-			JSONObject ucJsonObjAfter = new JSONObject();
-			ucJsonObjAfter.put("name", "安装后:C相电压");
-			List<Double> ucDataAfterList = new ArrayList<Double>();
-			//uab线电压曲线
-			JSONObject uabJsonObjAfter = new JSONObject();
-			uabJsonObjAfter.put("name", "安装后:UAB线电压");
-			List<Double> uabDataAfterList = new ArrayList<Double>();
-			//ubc线电压曲线
-			JSONObject ubcJsonObjAfter = new JSONObject();
-			ubcJsonObjAfter.put("name", "安装后:UBC线电压");
-			List<Double> ubcDataAfterList = new ArrayList<Double>();
-			//uca线电压曲线
-			JSONObject ucaJsonObjAfter = new JSONObject();
-			ucaJsonObjAfter.put("name", "安装后:UCA线电压");
-			List<Double> ucaDataAfterList = new ArrayList<Double>();
-			
-			//电流
-			//A相电流曲线
-			JSONObject iaJsonObjAfter = new JSONObject();
-			iaJsonObjAfter.put("name", "安装后:A相电流");
-			List<Double> iaDataAfterList = new ArrayList<Double>();
-			//B相电流曲线
-			JSONObject ibJsonObjAfter = new JSONObject();
-			ibJsonObjAfter.put("name", "安装后:B相电流");
-			List<Double> ibDataAfterList = new ArrayList<Double>();
-			//C相电流曲线
-			JSONObject icJsonObjAfter = new JSONObject();
-			icJsonObjAfter.put("name", "安装后:C相电流");
-			List<Double> icDataAfterList = new ArrayList<Double>();
-			//零序电流曲线
-			JSONObject izJsonObjAfter = new JSONObject();
-			izJsonObjAfter.put("name", "安装后:零线电流");
-			List<Double> izDataAfterList = new ArrayList<Double>();
-			
-			//遍历x轴,组装安装前后的实时电力数据
-			for(int i=0; i<datetimeList.size(); i++){
-				String dates = datetimeList.get(i);
-				String [] d = dates.split("&");
-				String start = d[0];//安装前日期 时间
-				String end = d[1];//安装后日期 时间
-				
-				//输出到页面的x轴
-				String [] f = start.split(" ");
-				String fdate = f[0];
-				String time = f[1];
-				String [] s = end.split(" ");
-				String sdate = s[0];
-				
-				String xaixs = fdate + "与" + sdate + " " + time;
-				xaixss.add(xaixs);
-				
-				//安装前的曲线数据
-				if(beforeDataMap.containsKey(start)){
-					OnlineDataPower model = beforeDataMap.get(start);
-					BigDecimal pa = model.getPa();// A相负荷
-					BigDecimal pb = model.getPb();// B相负荷
-					BigDecimal pc = model.getPc();// C相负荷
-					BigDecimal p = model.getP();// 总负荷
-					BigDecimal ua = model.getUa();// A相电压
-					BigDecimal ub = model.getUb();// B相电压
-					BigDecimal uc = model.getUc();// C相电压
-					BigDecimal uab = model.getUab();// Uab线电压
-					BigDecimal ubc = model.getUbc();// Ubc线电压
-					BigDecimal uca = model.getUca();// Uca线电压
-					BigDecimal ia = model.getIa();// A相电流
-					BigDecimal ib = model.getIb();// B相电流
-					BigDecimal ic = model.getIc();// C相电流
-					BigDecimal iz = model.getIz();// 零序电流
-					
-					pDataList.add(p.doubleValue());
-					paDataList.add(pa.doubleValue());
-					pbDataList.add(pb.doubleValue());
-					pcDataList.add(pc.doubleValue());
-					uaDataList.add(ua.doubleValue());
-					ubDataList.add(ub.doubleValue());
-					ucDataList.add(uc.doubleValue());
-					uabDataList.add(uab.doubleValue());
-					ubcDataList.add(ubc.doubleValue());
-					ucaDataList.add(uca.doubleValue());
-					iaDataList.add(ia.doubleValue());
-					ibDataList.add(ib.doubleValue());
-					icDataList.add(ic.doubleValue());
-					izDataList.add(iz.doubleValue());
-				}else{
-					pDataList.add(null);
-					paDataList.add(null);
-					pbDataList.add(null);
-					pcDataList.add(null);
-					uaDataList.add(null);
-					ubDataList.add(null);
-					ucDataList.add(null);
-					uabDataList.add(null);
-					ubcDataList.add(null);
-					ucaDataList.add(null);
-					iaDataList.add(null);
-					ibDataList.add(null);
-					icDataList.add(null);
-					izDataList.add(null);
-				}
-				
-				if(afterDataMap.containsKey(end)){//19豆75个  市场将158
-					OnlineDataPower model = afterDataMap.get(end);
-					BigDecimal pa = model.getPa();// A相负荷
-					BigDecimal pb = model.getPb();// B相负荷
-					BigDecimal pc = model.getPc();// C相负荷
-					BigDecimal p = model.getP();// 总负荷
-					BigDecimal ua = model.getUa();// A相电压
-					BigDecimal ub = model.getUb();// B相电压
-					BigDecimal uc = model.getUc();// C相电压
-					BigDecimal uab = model.getUab();// Uab线电压
-					BigDecimal ubc = model.getUbc();// Ubc线电压
-					BigDecimal uca = model.getUca();// Uca线电压
-					BigDecimal ia = model.getIa();// A相电流
-					BigDecimal ib = model.getIb();// B相电流
-					BigDecimal ic = model.getIc();// C相电流
-					BigDecimal iz = model.getIz();// 零序电流
-					
-					pDataAfterList.add(p.doubleValue());
-					paDataAfterList.add(pa.doubleValue());
-					pbDataAfterList.add(pb.doubleValue());
-					pcDataAfterList.add(pc.doubleValue());
-					uaDataAfterList.add(ua.doubleValue());
-					ubDataAfterList.add(ub.doubleValue());
-					ucDataAfterList.add(uc.doubleValue());
-					uabDataAfterList.add(uab.doubleValue());
-					ubcDataAfterList.add(ubc.doubleValue());
-					ucaDataAfterList.add(uca.doubleValue());
-					iaDataAfterList.add(ia.doubleValue());
-					ibDataAfterList.add(ib.doubleValue());
-					icDataAfterList.add(ic.doubleValue());
-					izDataAfterList.add(iz.doubleValue());
-				}else{
-					pDataAfterList.add(null);
-					paDataAfterList.add(null);
-					pbDataAfterList.add(null);
-					pcDataAfterList.add(null);
-					uaDataAfterList.add(null);
-					ubDataAfterList.add(null);
-					ucDataAfterList.add(null);
-					uabDataAfterList.add(null);
-					ubcDataAfterList.add(null);
-					ucaDataAfterList.add(null);
-					iaDataAfterList.add(null);
-					ibDataAfterList.add(null);
-					icDataAfterList.add(null);
-					izDataAfterList.add(null);
-				}
-				
-			}
-			
-			//安装前
-			pJsonObj.put("data", pDataList);
-			paJsonObj.put("data", paDataList);
-			pbJsonObj.put("data", pbDataList);
-			pcJsonObj.put("data", pcDataList);
-			uaJsonObj.put("data", uaDataList);
-			ubJsonObj.put("data", ubDataList);
-			ucJsonObj.put("data", ucDataList);
-			uabJsonObj.put("data", uabDataList);
-			ubcJsonObj.put("data", ubcDataList);
-			ucaJsonObj.put("data", ucaDataList);
-			iaJsonObj.put("data", iaDataList);
-			ibJsonObj.put("data", ibDataList);
-			icJsonObj.put("data", icDataList);
-			izJsonObj.put("data", izDataList);
-			
-			firstDataMap.put("P", pJsonObj);
-			firstDataMap.put("PA", paJsonObj);
-			firstDataMap.put("PB", pbJsonObj);
-			firstDataMap.put("PC", pcJsonObj);
-			firstDataMap.put("UA", uaJsonObj);
-			firstDataMap.put("UB", ubJsonObj);
-			firstDataMap.put("UC", ucJsonObj);
-			firstDataMap.put("UAB", uabJsonObj);
-			firstDataMap.put("UBC", ubcJsonObj);
-			firstDataMap.put("UCA", ucaJsonObj);
-			firstDataMap.put("IA", iaJsonObj);
-			firstDataMap.put("IB", ibJsonObj);
-			firstDataMap.put("IC", icJsonObj);
-			firstDataMap.put("IZ", izJsonObj);
-			
-			//安装后
-			pJsonObjAfter.put("data", pDataAfterList);
-			paJsonObjAfter.put("data", paDataAfterList);
-			pbJsonObjAfter.put("data", pbDataAfterList);
-			pcJsonObjAfter.put("data", pcDataAfterList);
-			uaJsonObjAfter.put("data", uaDataAfterList);
-			ubJsonObjAfter.put("data", ubDataAfterList);
-			ucJsonObjAfter.put("data", ucDataAfterList);
-			uabJsonObjAfter.put("data", uabDataAfterList);
-			ubcJsonObjAfter.put("data", ubcDataAfterList);
-			ucaJsonObjAfter.put("data", ucaDataAfterList);
-			iaJsonObjAfter.put("data", iaDataAfterList);
-			ibJsonObjAfter.put("data", ibDataAfterList);
-			icJsonObjAfter.put("data", icDataAfterList);
-			izJsonObjAfter.put("data", izDataAfterList);
-			
-			secondDataMap.put("P", pJsonObjAfter);
-			secondDataMap.put("PA", paJsonObjAfter);
-			secondDataMap.put("PB", pbJsonObjAfter);
-			secondDataMap.put("PC", pcJsonObjAfter);
-			secondDataMap.put("UA", uaJsonObjAfter);
-			secondDataMap.put("UB", ubJsonObjAfter);
-			secondDataMap.put("UC", ucJsonObjAfter);
-			secondDataMap.put("UAB", uabJsonObjAfter);
-			secondDataMap.put("UBC", ubcJsonObjAfter);
-			secondDataMap.put("UCA", ucaJsonObjAfter);
-			secondDataMap.put("IA", iaJsonObjAfter);
-			secondDataMap.put("IB", ibJsonObjAfter);
-			secondDataMap.put("IC", icJsonObjAfter);
-			secondDataMap.put("IZ", izJsonObjAfter);
-			
-		} else {
-			result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
-			message = getLocalMessage(local,"monitor_error");
-		}
-		
-		JSONObject jsonObject = new JSONObject();
-		jsonObject.put("xaixs", xaixss);
-		jsonObject.put("beforeData", firstDataMap);
-		jsonObject.put("afterData", secondDataMap);
-		
-		result.setData(jsonObject);
-		message = getLocalMessage(local,"onlinedatapower_success");
-		result.setMsg(message);
-		return result;
-	}
-
-	@Override
-	public ResultMsg<?> getMonitorLoadData(String local, long monitorId, int interval, String startDate, String endDate) {
-		HighChartsColumnVo columnVo;
-		try {
-			String start = startDate.replace("-", "");
-			String end = endDate.replace("-", "");
-			
-			Long startL = new Long(start + "000000");
-			Long endL = new Long(end + "235955");
-			
-			Monitor monitor = monitorDao.get(monitorId);
-			String monitorName = "";
-			String terminalId = "";
-			Double ct = 1.0;// CT变比
-			Double pt = 1.0;// PT变比
-			if(monitor != null){
-				int useCt = monitor.getUseCt();
-				int usePt = monitor.getUsePt();
-				if(useCt == 1) ct = monitor.getCt();
-				if(usePt == 1) pt = monitor.getPt();
-				monitorName = monitor.getName();
-				terminalId = monitor.getTerminalId();
-			}else{
-				return new ResultMsg<Object>(SystemConstant.RESULT_STATUS_ERROR, "图表加载出错了,请重试");
-			}
-			
-			List<Map<String, Object>> dataList = onlineDataPowerDao.selectDataByMonitorAndDate(terminalId, startL, endL);
-			
-			double minP = 999999.00;//最小负荷
-			double maxP = 0.00;//最大负荷
-			List<Double> pList = new ArrayList<Double>();
-			for(Map<String, Object> map : dataList){
-				double p = Double.parseDouble(map.get("p").toString());
-				p = p * ct *pt;
-				pList.add(p);
-				if(p < minP){
-					minP = p;
-				}
-				if(p > maxP){
-					maxP = p;
-				}
-			}
-			
-			if(minP == 999999.00)
-				minP = 0;
-			
-			//最低负荷与最高负荷之间按等份分级,数据作为x轴
-			Object[] splitP = new Object[]{};
-			//TODO 最高负荷除以等分数,如果大于1则不保留小数位,否则保留2位小数 update by zxliu 20161219
-			if(maxP / interval < 1){
-				splitP = splitDoubleNumber(interval, minP, maxP);
-			}else{
-				splitP = splitNumber(interval, minP, maxP);
-			}
-			
-			//组装柱状图表数据
-			List<HighChartsModuleSeries> series = new ArrayList<HighChartsModuleSeries>();
-			HighChartsModuleSeries moduleSeries = new HighChartsModuleSeries("区间负荷累计小时数");
-			//x轴
-			List<String> xaxis = new ArrayList<String>();
-			DecimalFormat numberFormat = new DecimalFormat("#########.##");
-			for(int i=0; i<splitP.length; i++){
-				String section = splitP[i].toString();
-				String [] sec = section.split("-");
-				double min = Double.parseDouble(sec[0]);
-				double max = Double.parseDouble(sec[1]);
-				double count = 0;
-				for(double p : pList){
-					if(p >= min && p <= max){
-						count++;
-					}
-				}
-				//负荷数据为每5分钟一次,因此将总数量除以12得到累计的小时数
-				double holdTime = NumberUtils.round(count / 12 , 2);
-				if(holdTime > 0){
-					moduleSeries.getData().add(holdTime);
-					xaxis.add(numberFormat.format(min) + "-" + numberFormat.format(max) + "(千瓦)");
-				}
-			}
-			series.add(moduleSeries);
-			
-			columnVo = new HighChartsColumnVo();
-			columnVo.setyTitle("持续小时数");
-			columnVo.setType("spline");
-			columnVo.setCategories(xaxis);
-			columnVo.setSeries(series);
-			columnVo.setTitle(monitorName + " 负荷分布状况");
-			
-			return new ResultMsg<Object>(SystemConstant.RESULT_STATUS_SUCCESS, "加载成功", columnVo);
-		} catch (Exception e) {
-			e.printStackTrace();
-			return new ResultMsg<Object>(SystemConstant.RESULT_STATUS_ERROR, "图表加载出错了,请重试");
-		}
-		
-	}
-	
-	/**
-	 * 最低负荷与最高负荷之间按等份分级
-	 * @param interval	等份
-	 * @param min	最小值
-	 * @param max	最大值
-	 * @return
-	 */
-	private Object[] splitNumber(int interval, double min, double max){
-		double le = max - min;
-		double split = le/interval;
-		int splitInt = convertNumber(split);
-		int min_m = convertNumber(min);
-		double sum = min_m;
-		List<String> list = new ArrayList<String>();
-		for(int i=0; i<interval; i++){
-			double start = sum;
-			sum += splitInt;
-			String ss = start + "-" + sum;
-			list.add(ss);
-		}
-		
-		return list.toArray();
-	}
-	
-	/**
-	 * 最低负荷与最高负荷之间按等份分级(此处保留小数位)
-	 * @param interval	等份
-	 * @param min	最小值
-	 * @param max	最大值
-	 * @return
-	 */
-	private Object[] splitDoubleNumber(int interval, double min, double max){
-		double le = max - min;
-		double split = le/interval;
-		double sum = min;
-		List<String> list = new ArrayList<String>();
-		for(int i=0; i<interval; i++){
-			double start = sum;
-			sum += split;
-			String ss = NumberUtils.round(start, 2) + "-" + NumberUtils.round(sum, 2);
-			list.add(ss);
-		}
-		
-		return list.toArray();
-	}
-	
-	/**
-	 * 对于长数字进行截取第一位补0处理
-	 * @param split
-	 * @return
-	 */
-	private int convertNumber(double split){
-		int splitInt = (int)Math.rint(split);
-		String ss = Integer.toString(splitInt);
-		String a=ss.substring(0, 1);
-		StringBuffer sb = new StringBuffer();
-		sb.append(a);
-		for(int i=0; i<ss.length()-1; i++){
-			sb.append(0);
-		}
-		String b = sb.toString();
-		
-		return Integer.parseInt(b);
-	}
+    private List<OnlineDataPower> buildMonitorOnlineDataByMonitor(String local, Monitor monitor, String dateString) {
+        List<OnlineDataPower> list = new ArrayList<OnlineDataPower>();
+        if (monitor != null) {
+            dateString = dateString.substring(0, 4) + "-" + dateString.substring(4, 6) + "-" + dateString.substring(6, 8);
+            long startTime = DateUtil.str2MonitorDate(dateString, dateString.length());
+            long endTime = DateUtil.str2MonitorDate(dateString, 1, 10);
+            if (monitor.getSeeType().equals(EmDistributionType.virtual.value)) { //虚拟节点
+                List<Monitor> monitorList = monitorDao.selectByParentId(monitor.getId());
+                list = buildSubMonitorOnlineDataPowerData(monitorList, startTime, endTime);
+            } else {
+                List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), startTime, endTime);//当前监测点的整点数据
+                //ct pt
+                for (OnlineDataPower power : onlineDataPowerList) {
+                    OnlineDataPower data = power.rebuildOnlineDataPower(monitor, power);
+                    list.add(data);
+                }
+            }
+        } else {
+            result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
+            message = getLocalMessage(local, "monitor_error");
+        }
+        return list;
+    }
+
+    @Override
+    public ResultMsg<List<OnlineDataPower>> getForOneDay(String local, long id, String dateString) {
+        ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
+        result.setData(buildMonitorOnlineDataByMonitorId(local, id, dateString));
+        message = getLocalMessage(local, "onlinedatapower_success");
+        result.setMsg(message);
+        return result;
+    }
+
+    /**
+     * 构建监测点子节点数据
+     */
+    private List<OnlineDataPower> buildSubMonitorOnlineDataPowerData(List<Monitor> monitorList, long startTime, long endTime) {
+        List<OnlineDataPower> resultList = new ArrayList<OnlineDataPower>();
+        Map<Long, OnlineDataPower> pMap = new LinkedHashMap<Long, OnlineDataPower>();//定义存储时间点负荷的Map
+        if (monitorList.size() > 0) {
+            for (Monitor subMonitor : monitorList) {
+                List<OnlineDataPower> subList = onlineDataPowerDao.selectByTerminalIdAndGetTime(subMonitor.getTerminalId(), startTime, endTime);//子监测点的数据
+                for (OnlineDataPower data : subList) {
+                    AnalDataCtPtUtil.addCtPt(subMonitor, data);
+                    if (pMap.containsKey(data.getGetTime())) {
+                        OnlineDataPower current = pMap.get(data.getGetTime()); //已经存储的OnlineDataEnergy
+                        pMap.put(data.getGetTime(), rebuildOnlineDataEnergy(current, data));//重构某个整点时间点的子监测点的各相电量,循环添加
+                    } else {
+                        pMap.put(data.getGetTime(), data);
+                    }
+                }
+            }
+        }
+
+        //这里的pMap已经将所有的子检测点的各相电量处理过,迭代监测点重置各相电量
+        for (Map.Entry<Long, OnlineDataPower> entry : pMap.entrySet()) {
+            OnlineDataPower energy = new OnlineDataPower();
+            OnlineDataPower memoryEnergy = entry.getValue();
+            energy.setGetTime(entry.getKey());
+            energy.setP(memoryEnergy.getP());
+            energy.setPa(memoryEnergy.getPa());
+            energy.setPb(memoryEnergy.getPb());
+            energy.setPc(memoryEnergy.getPc());
+
+            resultList.add(energy); //这里父监测的所有数据已被处理过
+        }
+
+        return resultList;
+    }
+
+    /**
+     * 子监测点内正相有功电量,正相无功电量,反相有功电量,反相无功电量相加
+     */
+    private OnlineDataPower rebuildOnlineDataEnergy(OnlineDataPower energy, OnlineDataPower current) {
+        energy.setP(energy.getP().add(current.getP()));
+        energy.setPa(energy.getPa().add(current.getPa()));
+        energy.setPb(energy.getPb().add(current.getPb()));
+        energy.setPc(energy.getPc().add(current.getPc()));
+        return energy;
+    }
+
+    @Override
+    public ResultMsg<List<OnlineDataPower>> getPowerUnitFor24H(String local,
+                                                               long unitId, String dateStr) {
+        List<MonitorPowerUnit> monitorList = mpuDao.selectByPowerUnitId(unitId);
+        dateStr = dateStr + " 00:00:00";
+        long start = DateUtil.str2MonitorDate(dateStr, dateStr.length());
+        dateStr = dateStr + " 00:00:00";
+        Date date = DateUtil.str2Date(dateStr, DateUtil.START_TIME_FORMAT);
+        Date endDate = DateUtil.addDays(date, 1);
+        long end = DateUtil.date2Monitortime(endDate);
+        List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
+        List<Long> timeList = new ArrayList<Long>();
+        for (int i = 1; i <= DateUtil.HOUR_ONE_DAY; i++) { //循环得到24个整点时间点
+            Timestamp timestamp = DateUtil.dateAddHour(date, i);
+            Date hourDate = DateUtil.timestramp2Date(timestamp, DateUtil.TIME_24H_FORMAT);
+            String hourDateStr = DateUtil.date2Str(hourDate, DateUtil.MONITOR_DATATIME_FORMAT);
+            long datetime = Long.valueOf(hourDateStr); //每隔1小时的时间
+            timeList.add(Long.parseLong(String.valueOf(datetime)));
+        }
+
+        Map<MonitorPowerUnitVo, List<OnlineDataPower>> map = new HashMap<MonitorPowerUnitVo, List<OnlineDataPower>>();
+        for (MonitorPowerUnit mpu : monitorList) {
+            long monitorId = mpu.getMonitorId();
+            Monitor monitor = monitorDao.selectById(monitorId);
+            List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), start, end);
+            //当前监测点的整点数据
+            MonitorPowerUnitVo vo = new MonitorPowerUnitVo();
+            vo.setMonitor(monitor);
+            vo.setScale(mpu.getScale());
+            map.put(vo, onlineDataPowerList);
+        }
+
+        for (Long getTime : timeList) {
+            OnlineDataPower newPower = new OnlineDataPower();
+            newPower.setGetTime(getTime);
+            Set<MonitorPowerUnitVo> mpuSet = map.keySet();
+            Iterator<MonitorPowerUnitVo> iter = mpuSet.iterator();
+            while (iter.hasNext()) {
+                MonitorPowerUnitVo mpu = iter.next();
+                Monitor monitor = mpu.getMonitor();
+                List<OnlineDataPower> onlineDataPowerList = map.get(mpu);
+                for (OnlineDataPower power : onlineDataPowerList) {
+                    if (newPower.getGetTime().longValue() == power.getGetTime().longValue()) {
+                        power = power.rebuildOnlineDataPower(monitor, power);//CT*PT
+                        //只需要一个总负荷数据即可
+                        BigDecimal powerP = power.getP().multiply(mpu.getScale()).divide(new BigDecimal(100));//按照占比
+                        if (newPower.getP() == null) {
+                            newPower.setP(powerP);
+                        } else {
+                            newPower.setP(powerP.add(newPower.getP())); //总负荷
+                        }
+                        break;
+                    }
+                }
+            }
+            temp.add(newPower);
+        }
+
+        ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
+        result.setMsg(getLocalMessage(local, "onlinedatapower_success"));
+        result.setData(temp);
+        return result;
+    }
+
+    @Override
+    public ResultMsg<List<OnlineDataPower>> getPowerUnitForOneDay(String local,
+                                                                  long unitId, String dateStr) {
+        List<MonitorPowerUnit> monitorList = mpuDao.selectByPowerUnitId(unitId);
+        long start = DateUtil.str2MonitorDate(dateStr, dateStr.length());
+        dateStr = dateStr + " 00:00:00";
+        Date date = DateUtil.str2Date(dateStr, DateUtil.START_TIME_FORMAT);
+        Date endDate = DateUtil.addDays(date, 1);
+        long end = DateUtil.date2Monitortime(endDate);
+        List<Long> timeList = new ArrayList<Long>();
+        timeList.add(start);
+        //这里等到一天所有的数据时间
+        for (int i = 1; i <= 288; i++) { //循环得到一天所有的时间点
+            Timestamp timestamp = DateUtil.dateAddMinute(date, i * 5);
+            Date hourDate = DateUtil.timestramp2Date(timestamp, DateUtil.DEFAULT_FORMAT);
+            String hourDateStr = DateUtil.date2Str(hourDate, DateUtil.MONITOR_DATATIME_FORMAT);
+            long datetime = Long.valueOf(hourDateStr); //每隔5分钟的时间
+            timeList.add(Long.parseLong(String.valueOf(datetime)));
+        }
+        List<OnlineDataPower> powerList = new ArrayList<OnlineDataPower>();
+        Map<MonitorPowerUnitVo, List<OnlineDataPower>> map = new HashMap<MonitorPowerUnitVo, List<OnlineDataPower>>();
+        for (MonitorPowerUnit mpu : monitorList) {
+            long monitorId = mpu.getMonitorId();
+            Monitor monitor = monitorDao.selectById(monitorId);
+            List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), start, end);
+            //当前监测点的整点数据
+            MonitorPowerUnitVo vo = new MonitorPowerUnitVo();
+            vo.setMonitor(monitor);
+            vo.setScale(mpu.getScale());
+            map.put(vo, onlineDataPowerList);
+        }
+
+        for (Long getTime : timeList) {
+            OnlineDataPower newPower = new OnlineDataPower();
+            newPower.setGetTime(getTime);
+            Set<MonitorPowerUnitVo> mpuSet = map.keySet();
+            Iterator<MonitorPowerUnitVo> iter = mpuSet.iterator();
+            while (iter.hasNext()) {
+                MonitorPowerUnitVo mpu = iter.next();
+                Monitor monitor = mpu.getMonitor();
+                List<OnlineDataPower> onlineDataPowerList = map.get(mpu);
+                for (OnlineDataPower power : onlineDataPowerList) {
+                    if (newPower.getGetTime().longValue() == power.getGetTime().longValue()) {
+                        power = power.rebuildOnlineDataPower(monitor, power);//CT*PT
+                        //只需要一个总负荷数据即可
+                        BigDecimal powerP = power.getP().multiply(mpu.getScale()).divide(new BigDecimal(100));//按照占比
+                        if (newPower.getP() == null) {
+                            newPower.setP(powerP);
+                        } else {
+                            newPower.setP(powerP.add(newPower.getP())); //总负荷
+                        }
+                        break;
+                    }
+                }
+            }
+            powerList.add(newPower);
+        }
+
+        ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
+        result.setMsg(getLocalMessage(local, "onlinedatapower_success"));
+        result.setData(powerList);
+
+        return result;
+    }
+
+    @Override
+    public ResultMsg<?> getSectionData(String local, long id, String startTime,
+                                       String endTime) {
+        ResultMsg<List<OnlineDataPower>> result = new ResultMsg<List<OnlineDataPower>>(SystemConstant.RESULT_STATUS_SUCCESS);
+        List<OnlineDataPower> temp = new ArrayList<OnlineDataPower>();
+        Monitor monitor = monitorDao.selectById(id);
+        if (monitor != null) {
+            long t1 = Long.parseLong(DateUtil.long2Str(Long.parseLong(startTime), DateUtil.MONITOR_DATATIME_FORMAT));
+            long t2 = Long.parseLong(DateUtil.long2Str(Long.parseLong(endTime), DateUtil.MONITOR_DATATIME_FORMAT));
+            List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), t1, t2);//当前监测点的整点数据
+            //ct pt
+            for (OnlineDataPower power : onlineDataPowerList) {
+                OnlineDataPower data = power.rebuildOnlineDataPower(monitor, power);
+                temp.add(data);
+            }
+        } else {
+            result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
+            message = getLocalMessage(local, "monitor_error");
+        }
+        result.setData(temp);
+        message = getLocalMessage(local, "onlinedatapower_success");
+        result.setMsg(message);
+        return result;
+    }
+
+    // string类型转换为long类型
+    // strTime要转换的String类型的时间
+    // formatType时间格式
+    // strTime的时间格式和formatType的时间格式必须相同
+    public long stringToLong(String strTime, String formatType) {
+        try {
+            SimpleDateFormat formatter = new SimpleDateFormat(formatType);
+            Date date = formatter.parse(strTime);
+            if (date == null) {
+                return 0;
+            } else {
+                long currentTime = date.getTime(); // date类型转成long类型
+                return currentTime;
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return 0;
+    }
+
+    //20170403000500
+    private long formatDate(long time) {
+        String t = "" + time;
+        String h = t.substring(8, 10);
+        String m = t.substring(10, 12);
+        String s = t.substring(12, 14);
+
+        String datetime = "2000-01-01 " + h + ":" + m + ":" + s;
+
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            Date date = formatter.parse(datetime);
+            if (date == null) {
+                return 0;
+            } else {
+                long currentTime = date.getTime(); // date类型转成long类型
+                return currentTime;
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return 0;
+    }
+
+    @Override
+    public ResultMsg<?> getSectionDataNew(String local, long id, String startTime, String endTime, String seriesName) {
+        ResultMsg<Map<String, JSONObject>> result = new ResultMsg<Map<String, JSONObject>>(SystemConstant.RESULT_STATUS_SUCCESS);
+        Map<String, JSONObject> dataMap = new HashMap<String, JSONObject>();
+
+        Monitor monitor = monitorDao.selectById(id);
+        if (monitor != null) {
+            long t1 = Long.parseLong(DateUtil.long2Str(Long.parseLong(startTime), DateUtil.MONITOR_DATATIME_FORMAT));
+            long t2 = Long.parseLong(DateUtil.long2Str(Long.parseLong(endTime), DateUtil.MONITOR_DATATIME_FORMAT));
+            List<OnlineDataPower> onlineDataPowerList = onlineDataPowerDao.selectByTerminalIdAndGetTime(monitor.getTerminalId(), t1, t2);//当前监测点的整点数据
+
+            //组装各曲线数据
+            //总负荷曲线
+            JSONObject pJsonObj = new JSONObject();
+            pJsonObj.put("name", seriesName + ":总负荷");
+            List<Object[]> pDataList = new ArrayList<Object[]>();
+            //A相负荷曲线
+            JSONObject paJsonObj = new JSONObject();
+            paJsonObj.put("name", seriesName + ":A相负荷");
+            List<Object[]> paDataList = new ArrayList<Object[]>();
+            //B相负荷曲线
+            JSONObject pbJsonObj = new JSONObject();
+            pbJsonObj.put("name", seriesName + ":B相负荷");
+            List<Object[]> pbDataList = new ArrayList<Object[]>();
+            //C相负荷曲线
+            JSONObject pcJsonObj = new JSONObject();
+            pcJsonObj.put("name", seriesName + ":C相负荷");
+            List<Object[]> pcDataList = new ArrayList<Object[]>();
+
+            //电压
+            //A相电压曲线
+            JSONObject uaJsonObj = new JSONObject();
+            uaJsonObj.put("name", seriesName + ":A相电压");
+            List<Object[]> uaDataList = new ArrayList<Object[]>();
+            //B相电压曲线
+            JSONObject ubJsonObj = new JSONObject();
+            ubJsonObj.put("name", seriesName + ":B相电压");
+            List<Object[]> ubDataList = new ArrayList<Object[]>();
+            //C相电压曲线
+            JSONObject ucJsonObj = new JSONObject();
+            ucJsonObj.put("name", seriesName + ":C相电压");
+            List<Object[]> ucDataList = new ArrayList<Object[]>();
+            //uab线电压曲线
+            JSONObject uabJsonObj = new JSONObject();
+            uabJsonObj.put("name", seriesName + ":UAB线电压");
+            List<Object[]> uabDataList = new ArrayList<Object[]>();
+            //ubc线电压曲线
+            JSONObject ubcJsonObj = new JSONObject();
+            ubcJsonObj.put("name", seriesName + ":UBC线电压");
+            List<Object[]> ubcDataList = new ArrayList<Object[]>();
+            //uca线电压曲线
+            JSONObject ucaJsonObj = new JSONObject();
+            ucaJsonObj.put("name", seriesName + ":UCA线电压");
+            List<Object[]> ucaDataList = new ArrayList<Object[]>();
+
+            //电流
+            //A相电流曲线
+            JSONObject iaJsonObj = new JSONObject();
+            iaJsonObj.put("name", seriesName + ":A相电流");
+            List<Object[]> iaDataList = new ArrayList<Object[]>();
+            //B相电流曲线
+            JSONObject ibJsonObj = new JSONObject();
+            ibJsonObj.put("name", seriesName + ":B相电流");
+            List<Object[]> ibDataList = new ArrayList<Object[]>();
+            //C相电流曲线
+            JSONObject icJsonObj = new JSONObject();
+            icJsonObj.put("name", seriesName + ":C相电流");
+            List<Object[]> icDataList = new ArrayList<Object[]>();
+            //零序电流曲线
+            JSONObject izJsonObj = new JSONObject();
+            izJsonObj.put("name", seriesName + ":零线电流");
+            List<Object[]> izDataList = new ArrayList<Object[]>();
+
+            //ct pt
+            for (OnlineDataPower power : onlineDataPowerList) {
+                OnlineDataPower data = power.rebuildOnlineDataPower(monitor, power);
+                long getTime = data.getGetTime();
+                long time = formatDate(getTime);
+
+                BigDecimal pa = data.getPa();// A相负荷
+                BigDecimal pb = data.getPb();// B相负荷
+                BigDecimal pc = data.getPc();// C相负荷
+                BigDecimal p = data.getP();// 总负荷
+                BigDecimal ua = data.getUa();// A相电压
+                BigDecimal ub = data.getUb();// B相电压
+                BigDecimal uc = data.getUc();// C相电压
+                BigDecimal uab = data.getUab();// Uab线电压
+                BigDecimal ubc = data.getUbc();// Ubc线电压
+                BigDecimal uca = data.getUca();// Uca线电压
+                BigDecimal ia = data.getIa();// A相电流
+                BigDecimal ib = data.getIb();// B相电流
+                BigDecimal ic = data.getIc();// C相电流
+                BigDecimal iz = data.getIz();// 零序电流
+
+                Object[] pObject = new Object[]{time, p};
+                pDataList.add(pObject);
+
+                Object[] paObject = new Object[]{time, pa};
+                paDataList.add(paObject);
+
+                Object[] pbObject = new Object[]{time, pb};
+                pbDataList.add(pbObject);
+
+                Object[] pcObject = new Object[]{time, pc};
+                pcDataList.add(pcObject);
+
+                Object[] uaObject = new Object[]{time, ua};
+                uaDataList.add(uaObject);
+
+                Object[] ubObject = new Object[]{time, ub};
+                ubDataList.add(ubObject);
+
+                Object[] ucObject = new Object[]{time, uc};
+                ucDataList.add(ucObject);
+
+                Object[] uabObject = new Object[]{time, uab};
+                uabDataList.add(uabObject);
+
+                Object[] ubcObject = new Object[]{time, ubc};
+                ubcDataList.add(ubcObject);
+
+                Object[] ucaObject = new Object[]{time, uca};
+                ucaDataList.add(ucaObject);
+
+                Object[] iaObject = new Object[]{time, ia};
+                iaDataList.add(iaObject);
+
+                Object[] ibObject = new Object[]{time, ib};
+                ibDataList.add(ibObject);
+
+                Object[] icObject = new Object[]{time, ic};
+                icDataList.add(icObject);
+
+                Object[] izObject = new Object[]{time, iz};
+                izDataList.add(izObject);
+            }
+            pJsonObj.put("data", pDataList);
+            paJsonObj.put("data", paDataList);
+            pbJsonObj.put("data", pbDataList);
+            pcJsonObj.put("data", pcDataList);
+
+            uaJsonObj.put("data", uaDataList);
+            ubJsonObj.put("data", ubDataList);
+            ucJsonObj.put("data", ucDataList);
+            uabJsonObj.put("data", uabDataList);
+            ubcJsonObj.put("data", ubcDataList);
+            ucaJsonObj.put("data", ucaDataList);
+
+            iaJsonObj.put("data", iaDataList);
+            ibJsonObj.put("data", ibDataList);
+            icJsonObj.put("data", icDataList);
+            izJsonObj.put("data", izDataList);
+
+            dataMap.put("P", pJsonObj);
+            dataMap.put("PA", paJsonObj);
+            dataMap.put("PB", pbJsonObj);
+            dataMap.put("PC", pcJsonObj);
+
+            dataMap.put("UA", uaJsonObj);
+            dataMap.put("UB", ubJsonObj);
+            dataMap.put("UC", ucJsonObj);
+            dataMap.put("UAB", uabJsonObj);
+            dataMap.put("UBC", ubcJsonObj);
+            dataMap.put("UCA", ucaJsonObj);
+
+            dataMap.put("IA", iaJsonObj);
+            dataMap.put("IB", ibJsonObj);
+            dataMap.put("IC", icJsonObj);
+            dataMap.put("IZ", izJsonObj);
+
+        } else {
+            result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
+            message = getLocalMessage(local, "monitor_error");
+        }
+        result.setData(dataMap);
+        message = getLocalMessage(local, "onlinedatapower_success");
+        result.setMsg(message);
+        return result;
+    }
+
+    @Override
+    public ResultMsg<?> getManyDaySectionData(String local, long id, String startTimeFirst, String endTimeFirst, String startTimeSecond, String endTimeSecond) {
+        ResultMsg<JSONObject> result = new ResultMsg<JSONObject>(SystemConstant.RESULT_STATUS_SUCCESS);
+
+        String startDate = getDatetimeToDate(DateUtil.long2Str(Long.parseLong(startTimeFirst), DateUtil.MONITOR_DATATIME_FORMAT));
+        String endDate = getDatetimeToDate(DateUtil.long2Str(Long.parseLong(endTimeFirst), DateUtil.MONITOR_DATATIME_FORMAT));
+        //日期相差几天
+        int dateDiff = daysBetween(startDate, endDate);
+
+        java.text.DateFormat dateFormat = new SimpleDateFormat("MM月dd日 HH:mm");
+        /*****************每个节点的日期、时间数据组装start*****************/
+        List<String> datetimeList = new ArrayList<String>();
+        //总节点数(每天288个点,乘以天数)
+        int count = (dateDiff + 1) * 288;
+
+        Calendar cal = Calendar.getInstance();
+        cal.setTimeInMillis(Long.parseLong(startTimeFirst));
+        String first = dateFormat.format(cal.getTime());
+
+        Calendar cal1 = Calendar.getInstance();
+        cal1.setTimeInMillis(Long.parseLong(startTimeSecond));
+        String second = dateFormat.format(cal1.getTime());
+
+        datetimeList.add(first + "&" + second);
+        for (int i = 1; i < count; i++) {
+            cal.add(Calendar.MINUTE, 5);
+            cal1.add(Calendar.MINUTE, 5);
+
+            String first_i = dateFormat.format(cal.getTime());
+            String second_i = dateFormat.format(cal1.getTime());
+            datetimeList.add(first_i + "&" + second_i);
+        }
+        /*****************每个节点的日期、时间数据组装数据组装end*****************/
+
+        Map<String, JSONObject> firstDataMap = new HashMap<String, JSONObject>();
+        Map<String, JSONObject> secondDataMap = new HashMap<String, JSONObject>();
+
+        //输出到页面的x轴
+        List<String> xaixss = new ArrayList<String>();
+        Monitor monitor = monitorDao.selectById(id);
+        if (monitor != null) {
+            //安装前数据
+            long stf = Long.parseLong(DateUtil.long2Str(Long.parseLong(startTimeFirst), DateUtil.MONITOR_DATATIME_FORMAT));
+            long etf = Long.parseLong(DateUtil.long2Str(Long.parseLong(endTimeFirst), DateUtil.MONITOR_DATATIME_FORMAT));
+            List<OnlineDataPower> onlineDataPowerFirstList = onlineDataPowerDao.selectManyDayData(monitor.getTerminalId(), stf, etf);//当前监测点的整点数据
+            Map<String, OnlineDataPower> beforeDataMap = new HashMap<String, OnlineDataPower>();
+            for (OnlineDataPower model : onlineDataPowerFirstList) {
+                String dateTime = getYmsToDefaultDate(model.getGetTime());
+                OnlineDataPower power = model.rebuildOnlineDataPower(monitor, model);
+                beforeDataMap.put(dateTime, power);
+            }
+
+            //安装后数据
+            long sts = Long.parseLong(DateUtil.long2Str(Long.parseLong(startTimeSecond), DateUtil.MONITOR_DATATIME_FORMAT));
+            long ets = Long.parseLong(DateUtil.long2Str(Long.parseLong(endTimeSecond), DateUtil.MONITOR_DATATIME_FORMAT));
+            List<OnlineDataPower> onlineDataPowerSecondList = onlineDataPowerDao.selectManyDayData(monitor.getTerminalId(), sts, ets);//当前监测点的整点数据
+            Map<String, OnlineDataPower> afterDataMap = new HashMap<String, OnlineDataPower>();
+            for (OnlineDataPower model : onlineDataPowerSecondList) {
+                String dateTime = getYmsToDefaultDate(model.getGetTime());
+                OnlineDataPower power = model.rebuildOnlineDataPower(monitor, model);
+                afterDataMap.put(dateTime, power);
+            }
+
+
+            //组装"安装前"各曲线数据
+            //总负荷曲线
+
+            JSONObject pJsonObj = new JSONObject();
+            pJsonObj.put("name", "安装前:总负荷");
+            List<Double> pDataList = new ArrayList<Double>();
+            //A相负荷曲线
+            JSONObject paJsonObj = new JSONObject();
+            paJsonObj.put("name", "安装前:A相负荷");
+            List<Double> paDataList = new ArrayList<Double>();
+            //B相负荷曲线
+            JSONObject pbJsonObj = new JSONObject();
+            pbJsonObj.put("name", "安装前:B相负荷");
+            List<Double> pbDataList = new ArrayList<Double>();
+            //C相负荷曲线
+            JSONObject pcJsonObj = new JSONObject();
+            pcJsonObj.put("name", "安装前:C相负荷");
+            List<Double> pcDataList = new ArrayList<Double>();
+
+            //电压
+            //A相电压曲线
+            JSONObject uaJsonObj = new JSONObject();
+            uaJsonObj.put("name", "安装前:A相电压");
+            List<Double> uaDataList = new ArrayList<Double>();
+            //B相电压曲线
+            JSONObject ubJsonObj = new JSONObject();
+            ubJsonObj.put("name", "安装前:B相电压");
+            List<Double> ubDataList = new ArrayList<Double>();
+            //C相电压曲线
+            JSONObject ucJsonObj = new JSONObject();
+            ucJsonObj.put("name", "安装前:C相电压");
+            List<Double> ucDataList = new ArrayList<Double>();
+            //uab线电压曲线
+            JSONObject uabJsonObj = new JSONObject();
+            uabJsonObj.put("name", "安装前:UAB线电压");
+            List<Double> uabDataList = new ArrayList<Double>();
+            //ubc线电压曲线
+            JSONObject ubcJsonObj = new JSONObject();
+            ubcJsonObj.put("name", "安装前:UBC线电压");
+            List<Double> ubcDataList = new ArrayList<Double>();
+            //uca线电压曲线
+            JSONObject ucaJsonObj = new JSONObject();
+            ucaJsonObj.put("name", "安装前:UCA线电压");
+            List<Double> ucaDataList = new ArrayList<Double>();
+
+            //电流
+            //A相电流曲线
+            JSONObject iaJsonObj = new JSONObject();
+            iaJsonObj.put("name", "安装前:A相电流");
+            List<Double> iaDataList = new ArrayList<Double>();
+            //B相电流曲线
+            JSONObject ibJsonObj = new JSONObject();
+            ibJsonObj.put("name", "安装前:B相电流");
+            List<Double> ibDataList = new ArrayList<Double>();
+            //C相电流曲线
+            JSONObject icJsonObj = new JSONObject();
+            icJsonObj.put("name", "安装前:C相电流");
+            List<Double> icDataList = new ArrayList<Double>();
+            //零序电流曲线
+            JSONObject izJsonObj = new JSONObject();
+            izJsonObj.put("name", "安装前:零线电流");
+            List<Double> izDataList = new ArrayList<Double>();
+
+
+            //组装"安装后"各曲线数据
+            //总负荷曲线
+            JSONObject pJsonObjAfter = new JSONObject();
+            pJsonObjAfter.put("name", "安装后:总负荷");
+            List<Double> pDataAfterList = new ArrayList<Double>();
+            //A相负荷曲线
+            JSONObject paJsonObjAfter = new JSONObject();
+            paJsonObjAfter.put("name", "安装后:A相负荷");
+            List<Double> paDataAfterList = new ArrayList<Double>();
+            //B相负荷曲线
+            JSONObject pbJsonObjAfter = new JSONObject();
+            pbJsonObjAfter.put("name", "安装后:B相负荷");
+            List<Double> pbDataAfterList = new ArrayList<Double>();
+            //C相负荷曲线
+            JSONObject pcJsonObjAfter = new JSONObject();
+            pcJsonObjAfter.put("name", "安装后:C相负荷");
+            List<Double> pcDataAfterList = new ArrayList<Double>();
+
+            //电压
+            //A相电压曲线
+            JSONObject uaJsonObjAfter = new JSONObject();
+            uaJsonObjAfter.put("name", "安装后:A相电压");
+            List<Double> uaDataAfterList = new ArrayList<Double>();
+            //B相电压曲线
+            JSONObject ubJsonObjAfter = new JSONObject();
+            ubJsonObjAfter.put("name", "安装后:B相电压");
+            List<Double> ubDataAfterList = new ArrayList<Double>();
+            //C相电压曲线
+            JSONObject ucJsonObjAfter = new JSONObject();
+            ucJsonObjAfter.put("name", "安装后:C相电压");
+            List<Double> ucDataAfterList = new ArrayList<Double>();
+            //uab线电压曲线
+            JSONObject uabJsonObjAfter = new JSONObject();
+            uabJsonObjAfter.put("name", "安装后:UAB线电压");
+            List<Double> uabDataAfterList = new ArrayList<Double>();
+            //ubc线电压曲线
+            JSONObject ubcJsonObjAfter = new JSONObject();
+            ubcJsonObjAfter.put("name", "安装后:UBC线电压");
+            List<Double> ubcDataAfterList = new ArrayList<Double>();
+            //uca线电压曲线
+            JSONObject ucaJsonObjAfter = new JSONObject();
+            ucaJsonObjAfter.put("name", "安装后:UCA线电压");
+            List<Double> ucaDataAfterList = new ArrayList<Double>();
+
+            //电流
+            //A相电流曲线
+            JSONObject iaJsonObjAfter = new JSONObject();
+            iaJsonObjAfter.put("name", "安装后:A相电流");
+            List<Double> iaDataAfterList = new ArrayList<Double>();
+            //B相电流曲线
+            JSONObject ibJsonObjAfter = new JSONObject();
+            ibJsonObjAfter.put("name", "安装后:B相电流");
+            List<Double> ibDataAfterList = new ArrayList<Double>();
+            //C相电流曲线
+            JSONObject icJsonObjAfter = new JSONObject();
+            icJsonObjAfter.put("name", "安装后:C相电流");
+            List<Double> icDataAfterList = new ArrayList<Double>();
+            //零序电流曲线
+            JSONObject izJsonObjAfter = new JSONObject();
+            izJsonObjAfter.put("name", "安装后:零线电流");
+            List<Double> izDataAfterList = new ArrayList<Double>();
+
+            //遍历x轴,组装安装前后的实时电力数据
+            for (int i = 0; i < datetimeList.size(); i++) {
+                String dates = datetimeList.get(i);
+                String[] d = dates.split("&");
+                String start = d[0];//安装前日期 时间
+                String end = d[1];//安装后日期 时间
+
+                //输出到页面的x轴
+                String[] f = start.split(" ");
+                String fdate = f[0];
+                String time = f[1];
+                String[] s = end.split(" ");
+                String sdate = s[0];
+
+                String xaixs = fdate + "与" + sdate + " " + time;
+                xaixss.add(xaixs);
+
+                //安装前的曲线数据
+                if (beforeDataMap.containsKey(start)) {
+                    OnlineDataPower model = beforeDataMap.get(start);
+                    BigDecimal pa = model.getPa();// A相负荷
+                    BigDecimal pb = model.getPb();// B相负荷
+                    BigDecimal pc = model.getPc();// C相负荷
+                    BigDecimal p = model.getP();// 总负荷
+                    BigDecimal ua = model.getUa();// A相电压
+                    BigDecimal ub = model.getUb();// B相电压
+                    BigDecimal uc = model.getUc();// C相电压
+                    BigDecimal uab = model.getUab();// Uab线电压
+                    BigDecimal ubc = model.getUbc();// Ubc线电压
+                    BigDecimal uca = model.getUca();// Uca线电压
+                    BigDecimal ia = model.getIa();// A相电流
+                    BigDecimal ib = model.getIb();// B相电流
+                    BigDecimal ic = model.getIc();// C相电流
+                    BigDecimal iz = model.getIz();// 零序电流
+
+                    pDataList.add(p.doubleValue());
+                    paDataList.add(pa.doubleValue());
+                    pbDataList.add(pb.doubleValue());
+                    pcDataList.add(pc.doubleValue());
+                    uaDataList.add(ua.doubleValue());
+                    ubDataList.add(ub.doubleValue());
+                    ucDataList.add(uc.doubleValue());
+                    uabDataList.add(uab.doubleValue());
+                    ubcDataList.add(ubc.doubleValue());
+                    ucaDataList.add(uca.doubleValue());
+                    iaDataList.add(ia.doubleValue());
+                    ibDataList.add(ib.doubleValue());
+                    icDataList.add(ic.doubleValue());
+                    izDataList.add(iz.doubleValue());
+                } else {
+                    pDataList.add(null);
+                    paDataList.add(null);
+                    pbDataList.add(null);
+                    pcDataList.add(null);
+                    uaDataList.add(null);
+                    ubDataList.add(null);
+                    ucDataList.add(null);
+                    uabDataList.add(null);
+                    ubcDataList.add(null);
+                    ucaDataList.add(null);
+                    iaDataList.add(null);
+                    ibDataList.add(null);
+                    icDataList.add(null);
+                    izDataList.add(null);
+                }
+
+                if (afterDataMap.containsKey(end)) {//19豆75个  市场将158
+                    OnlineDataPower model = afterDataMap.get(end);
+                    BigDecimal pa = model.getPa();// A相负荷
+                    BigDecimal pb = model.getPb();// B相负荷
+                    BigDecimal pc = model.getPc();// C相负荷
+                    BigDecimal p = model.getP();// 总负荷
+                    BigDecimal ua = model.getUa();// A相电压
+                    BigDecimal ub = model.getUb();// B相电压
+                    BigDecimal uc = model.getUc();// C相电压
+                    BigDecimal uab = model.getUab();// Uab线电压
+                    BigDecimal ubc = model.getUbc();// Ubc线电压
+                    BigDecimal uca = model.getUca();// Uca线电压
+                    BigDecimal ia = model.getIa();// A相电流
+                    BigDecimal ib = model.getIb();// B相电流
+                    BigDecimal ic = model.getIc();// C相电流
+                    BigDecimal iz = model.getIz();// 零序电流
+
+                    pDataAfterList.add(p.doubleValue());
+                    paDataAfterList.add(pa.doubleValue());
+                    pbDataAfterList.add(pb.doubleValue());
+                    pcDataAfterList.add(pc.doubleValue());
+                    uaDataAfterList.add(ua.doubleValue());
+                    ubDataAfterList.add(ub.doubleValue());
+                    ucDataAfterList.add(uc.doubleValue());
+                    uabDataAfterList.add(uab.doubleValue());
+                    ubcDataAfterList.add(ubc.doubleValue());
+                    ucaDataAfterList.add(uca.doubleValue());
+                    iaDataAfterList.add(ia.doubleValue());
+                    ibDataAfterList.add(ib.doubleValue());
+                    icDataAfterList.add(ic.doubleValue());
+                    izDataAfterList.add(iz.doubleValue());
+                } else {
+                    pDataAfterList.add(null);
+                    paDataAfterList.add(null);
+                    pbDataAfterList.add(null);
+                    pcDataAfterList.add(null);
+                    uaDataAfterList.add(null);
+                    ubDataAfterList.add(null);
+                    ucDataAfterList.add(null);
+                    uabDataAfterList.add(null);
+                    ubcDataAfterList.add(null);
+                    ucaDataAfterList.add(null);
+                    iaDataAfterList.add(null);
+                    ibDataAfterList.add(null);
+                    icDataAfterList.add(null);
+                    izDataAfterList.add(null);
+                }
+
+            }
+
+            //安装前
+            pJsonObj.put("data", pDataList);
+            paJsonObj.put("data", paDataList);
+            pbJsonObj.put("data", pbDataList);
+            pcJsonObj.put("data", pcDataList);
+            uaJsonObj.put("data", uaDataList);
+            ubJsonObj.put("data", ubDataList);
+            ucJsonObj.put("data", ucDataList);
+            uabJsonObj.put("data", uabDataList);
+            ubcJsonObj.put("data", ubcDataList);
+            ucaJsonObj.put("data", ucaDataList);
+            iaJsonObj.put("data", iaDataList);
+            ibJsonObj.put("data", ibDataList);
+            icJsonObj.put("data", icDataList);
+            izJsonObj.put("data", izDataList);
+
+            firstDataMap.put("P", pJsonObj);
+            firstDataMap.put("PA", paJsonObj);
+            firstDataMap.put("PB", pbJsonObj);
+            firstDataMap.put("PC", pcJsonObj);
+            firstDataMap.put("UA", uaJsonObj);
+            firstDataMap.put("UB", ubJsonObj);
+            firstDataMap.put("UC", ucJsonObj);
+            firstDataMap.put("UAB", uabJsonObj);
+            firstDataMap.put("UBC", ubcJsonObj);
+            firstDataMap.put("UCA", ucaJsonObj);
+            firstDataMap.put("IA", iaJsonObj);
+            firstDataMap.put("IB", ibJsonObj);
+            firstDataMap.put("IC", icJsonObj);
+            firstDataMap.put("IZ", izJsonObj);
+
+            //安装后
+            pJsonObjAfter.put("data", pDataAfterList);
+            paJsonObjAfter.put("data", paDataAfterList);
+            pbJsonObjAfter.put("data", pbDataAfterList);
+            pcJsonObjAfter.put("data", pcDataAfterList);
+            uaJsonObjAfter.put("data", uaDataAfterList);
+            ubJsonObjAfter.put("data", ubDataAfterList);
+            ucJsonObjAfter.put("data", ucDataAfterList);
+            uabJsonObjAfter.put("data", uabDataAfterList);
+            ubcJsonObjAfter.put("data", ubcDataAfterList);
+            ucaJsonObjAfter.put("data", ucaDataAfterList);
+            iaJsonObjAfter.put("data", iaDataAfterList);
+            ibJsonObjAfter.put("data", ibDataAfterList);
+            icJsonObjAfter.put("data", icDataAfterList);
+            izJsonObjAfter.put("data", izDataAfterList);
+
+            secondDataMap.put("P", pJsonObjAfter);
+            secondDataMap.put("PA", paJsonObjAfter);
+            secondDataMap.put("PB", pbJsonObjAfter);
+            secondDataMap.put("PC", pcJsonObjAfter);
+            secondDataMap.put("UA", uaJsonObjAfter);
+            secondDataMap.put("UB", ubJsonObjAfter);
+            secondDataMap.put("UC", ucJsonObjAfter);
+            secondDataMap.put("UAB", uabJsonObjAfter);
+            secondDataMap.put("UBC", ubcJsonObjAfter);
+            secondDataMap.put("UCA", ucaJsonObjAfter);
+            secondDataMap.put("IA", iaJsonObjAfter);
+            secondDataMap.put("IB", ibJsonObjAfter);
+            secondDataMap.put("IC", icJsonObjAfter);
+            secondDataMap.put("IZ", izJsonObjAfter);
+
+        } else {
+            result.setStatus(SystemConstant.RESULT_PARAM_ERROR);
+            message = getLocalMessage(local, "monitor_error");
+        }
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("xaixs", xaixss);
+        jsonObject.put("beforeData", firstDataMap);
+        jsonObject.put("afterData", secondDataMap);
+
+        result.setData(jsonObject);
+        message = getLocalMessage(local, "onlinedatapower_success");
+        result.setMsg(message);
+        return result;
+    }
+
+    @Override
+    public ResultMsg<?> getMonitorLoadData(String local, long monitorId, int interval, String startDate, String endDate) {
+        HighChartsColumnVo columnVo;
+        try {
+            String start = startDate.replace("-", "");
+            String end = endDate.replace("-", "");
+
+            Long startL = new Long(start + "000000");
+            Long endL = new Long(end + "235955");
+
+            Monitor monitor = monitorDao.get(monitorId);
+            String monitorName = "";
+            String terminalId = "";
+            Double ct = 1.0;// CT变比
+            Double pt = 1.0;// PT变比
+            if (monitor != null) {
+                int useCt = monitor.getUseCt();
+                int usePt = monitor.getUsePt();
+                if (useCt == 1) ct = monitor.getCt();
+                if (usePt == 1) pt = monitor.getPt();
+                monitorName = monitor.getName();
+                terminalId = monitor.getTerminalId();
+            } else {
+                return new ResultMsg<Object>(SystemConstant.RESULT_STATUS_ERROR, "图表加载出错了,请重试");
+            }
+
+            List<Map<String, Object>> dataList = onlineDataPowerDao.selectDataByMonitorAndDate(terminalId, startL, endL);
+
+            double minP = 999999.00;//最小负荷
+            double maxP = 0.00;//最大负荷
+            List<Double> pList = new ArrayList<Double>();
+            for (Map<String, Object> map : dataList) {
+                double p = Double.parseDouble(map.get("p").toString());
+                p = p * ct * pt;
+                pList.add(p);
+                if (p < minP) {
+                    minP = p;
+                }
+                if (p > maxP) {
+                    maxP = p;
+                }
+            }
+
+            if (minP == 999999.00)
+                minP = 0;
+
+            //最低负荷与最高负荷之间按等份分级,数据作为x轴
+            Object[] splitP = new Object[]{};
+            //TODO 最高负荷除以等分数,如果大于1则不保留小数位,否则保留2位小数 update by zxliu 20161219
+            if (maxP / interval < 1) {
+                splitP = splitDoubleNumber(interval, minP, maxP);
+            } else {
+                splitP = splitNumber(interval, minP, maxP);
+            }
+
+            //组装柱状图表数据
+            List<HighChartsModuleSeries> series = new ArrayList<HighChartsModuleSeries>();
+            HighChartsModuleSeries moduleSeries = new HighChartsModuleSeries("区间负荷累计小时数");
+            //x轴
+            List<String> xaxis = new ArrayList<String>();
+            DecimalFormat numberFormat = new DecimalFormat("#########.##");
+            for (int i = 0; i < splitP.length; i++) {
+                String section = splitP[i].toString();
+                String[] sec = section.split("-");
+                double min = Double.parseDouble(sec[0]);
+                double max = Double.parseDouble(sec[1]);
+                double count = 0;
+                for (double p : pList) {
+                    if (p >= min && p <= max) {
+                        count++;
+                    }
+                }
+                //负荷数据为每5分钟一次,因此将总数量除以12得到累计的小时数
+                double holdTime = NumberUtils.round(count / 12, 2);
+                if (holdTime > 0) {
+                    moduleSeries.getData().add(holdTime);
+                    xaxis.add(numberFormat.format(min) + "-" + numberFormat.format(max) + "(千瓦)");
+                }
+            }
+            series.add(moduleSeries);
+
+            columnVo = new HighChartsColumnVo();
+            columnVo.setyTitle("持续小时数");
+            columnVo.setType("spline");
+            columnVo.setCategories(xaxis);
+            columnVo.setSeries(series);
+            columnVo.setTitle(monitorName + " 负荷分布状况");
+
+            return new ResultMsg<Object>(SystemConstant.RESULT_STATUS_SUCCESS, "加载成功", columnVo);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResultMsg<Object>(SystemConstant.RESULT_STATUS_ERROR, "图表加载出错了,请重试");
+        }
+
+    }
+
+    /**
+     * 最低负荷与最高负荷之间按等份分级
+     *
+     * @param interval 等份
+     * @param min      最小值
+     * @param max      最大值
+     * @return
+     */
+    private Object[] splitNumber(int interval, double min, double max) {
+        double le = max - min;
+        double split = le / interval;
+        int splitInt = convertNumber(split);
+        int min_m = convertNumber(min);
+        double sum = min_m;
+        List<String> list = new ArrayList<String>();
+        for (int i = 0; i < interval; i++) {
+            double start = sum;
+            sum += splitInt;
+            String ss = start + "-" + sum;
+            list.add(ss);
+        }
+
+        return list.toArray();
+    }
+
+    /**
+     * 最低负荷与最高负荷之间按等份分级(此处保留小数位)
+     *
+     * @param interval 等份
+     * @param min      最小值
+     * @param max      最大值
+     * @return
+     */
+    private Object[] splitDoubleNumber(int interval, double min, double max) {
+        double le = max - min;
+        double split = le / interval;
+        double sum = min;
+        List<String> list = new ArrayList<String>();
+        for (int i = 0; i < interval; i++) {
+            double start = sum;
+            sum += split;
+            String ss = NumberUtils.round(start, 2) + "-" + NumberUtils.round(sum, 2);
+            list.add(ss);
+        }
+
+        return list.toArray();
+    }
+
+    /**
+     * 对于长数字进行截取第一位补0处理
+     *
+     * @param split
+     * @return
+     */
+    private int convertNumber(double split) {
+        int splitInt = (int) Math.rint(split);
+        String ss = Integer.toString(splitInt);
+        String a = ss.substring(0, 1);
+        StringBuffer sb = new StringBuffer();
+        sb.append(a);
+        for (int i = 0; i < ss.length() - 1; i++) {
+            sb.append(0);
+        }
+        String b = sb.toString();
+
+        return Integer.parseInt(b);
+    }
 
 }

+ 444 - 452
VB_DSM_V2.1/vbdsm-web/vbdsm-powerservice/src/main/java/cn/vbdsm/powerservice/service/online/impl/ReportManageServiceImpl.java

@@ -1,468 +1,460 @@
 package cn.vbdsm.powerservice.service.online.impl;
 
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import cn.vbdsm.common.constants.SystemConstant;
+import cn.vbdsm.common.utils.AnalDataCtPtUtil;
+import cn.vbdsm.common.utils.ExcelUtil;
+import cn.vbdsm.powerservice.dao.*;
+import cn.vbdsm.powerservice.model.*;
+import cn.vbdsm.powerservice.service.online.facade.IReportManageService;
+import cn.vbdsm.powerservice.vo.ReportManageDataVo;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.log4j.Logger;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 import javax.core.common.Page;
 import javax.core.common.ResultMsg;
 import javax.core.common.utils.DataUtils;
 import javax.core.common.utils.NumberUtils;
 import javax.core.common.utils.StringUtils;
-
-import org.apache.log4j.Logger;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import cn.vbdsm.common.constants.SystemConstant;
-import cn.vbdsm.common.utils.AnalDataCtPtUtil;
-import cn.vbdsm.common.utils.ExcelUtil;
-import cn.vbdsm.powerservice.dao.AnalDateAvgDao;
-import cn.vbdsm.powerservice.dao.AnalDateFgpDao;
-import cn.vbdsm.powerservice.dao.AnalDateMaxDao;
-import cn.vbdsm.powerservice.dao.AnalDateMinDao;
-import cn.vbdsm.powerservice.dao.AnalMonthAvgDao;
-import cn.vbdsm.powerservice.dao.AnalMonthMaxDao;
-import cn.vbdsm.powerservice.dao.AnalMonthMinDao;
-import cn.vbdsm.powerservice.dao.AnalYearAvgDao;
-import cn.vbdsm.powerservice.dao.AnalYearMaxDao;
-import cn.vbdsm.powerservice.dao.AnalYearMinDao;
-import cn.vbdsm.powerservice.dao.MonitorDao;
-import cn.vbdsm.powerservice.dao.ReportManageDao;
-import cn.vbdsm.powerservice.model.AnalDateAvg;
-import cn.vbdsm.powerservice.model.AnalDateFgp;
-import cn.vbdsm.powerservice.model.AnalDateMax;
-import cn.vbdsm.powerservice.model.AnalDateMin;
-import cn.vbdsm.powerservice.model.AnalMonthAvg;
-import cn.vbdsm.powerservice.model.AnalMonthMax;
-import cn.vbdsm.powerservice.model.AnalMonthMin;
-import cn.vbdsm.powerservice.model.AnalYearAvg;
-import cn.vbdsm.powerservice.model.AnalYearMax;
-import cn.vbdsm.powerservice.model.AnalYearMin;
-import cn.vbdsm.powerservice.model.Monitor;
-import cn.vbdsm.powerservice.model.ReportManage;
-import cn.vbdsm.powerservice.service.online.facade.IReportManageService;
-import cn.vbdsm.powerservice.vo.ReportManageDataVo;
+import java.math.BigDecimal;
+import java.util.*;
 
 /**
- *  
- *                  _oo8oo_
- *                 o8888888o
- *                 88" . "88
- *                 (| -_- |)
- *                 0\  =  /0
- *               ___/'==='\___
- *             .' \\|     |// '.
- *            / \\|||  :  |||// \
- *           / _||||| -:- |||||_ \
- *          |   | \\\  -  /// |   |
- *          | \_|  ''\---/''  |_/ |
- *          \  .-\__  '-'  __/-.  /
- *        ___'. .'  /--.--\  '. .'___
- *     ."" '<  '.___\_<|>_/___.'  >' "".
- *    | | :  `- \`.:`\ _ /`:.`/ -`  : | |
- *    \  \ `-.   \_ __\ /__ _/   .-` /  /
- *=====`-.____`.___ \_____/ ___.`____.-`=====
- *                  `=---=`
- *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- *             佛祖保佑         永无bug
- *             
+ * _oo8oo_
+ * o8888888o
+ * 88" . "88
+ * (| -_- |)
+ * 0\  =  /0
+ * ___/'==='\___
+ * .' \\|     |// '.
+ * / \\|||  :  |||// \
+ * / _||||| -:- |||||_ \
+ * |   | \\\  -  /// |   |
+ * | \_|  ''\---/''  |_/ |
+ * \  .-\__  '-'  __/-.  /
+ * ___'. .'  /--.--\  '. .'___
+ * ."" '<  '.___\_<|>_/___.'  >' "".
+ * | | :  `- \`.:`\ _ /`:.`/ -`  : | |
+ * \  \ `-.   \_ __\ /__ _/   .-` /  /
+ * =====`-.____`.___ \_____/ ___.`____.-`=====
+ * `=---=`
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * 佛祖保佑         永无bug
+ * <p>
  * 报表管理与定义业务逻辑实现
+ *
  * @author grxie
  */
 @Service
 public class ReportManageServiceImpl implements IReportManageService {
-	
-	private static Logger logger = Logger.getLogger(ReportManageServiceImpl.class);
-	
-	@Autowired private ReportManageDao reportManageDao;
-	
-	@Autowired private MonitorDao monitorDao;
-	@Autowired private AnalDateFgpDao analDateFgpDao;
-	
-	@Autowired private AnalDateMaxDao analDateMaxDao;
-	@Autowired private AnalDateMinDao analDateMinDao;
-	@Autowired private AnalDateAvgDao analDateAvgDao;
-
-	@Autowired private AnalMonthMaxDao analMonthMaxDao;
-	@Autowired private AnalMonthMinDao analMonthMinDao;
-	@Autowired private AnalMonthAvgDao analMonthAvgDao;
-	
-	@Autowired private AnalYearMaxDao analYearMaxDao;
-	@Autowired private AnalYearMinDao analYearMinDao;
-	@Autowired private AnalYearAvgDao analYearAvgDao;
-	
-	/**
-	 * 根据类型ID获取机构报表
-	 * @param companyId
-	 * @param classify
-	 * @return
-	 */
-	public ResultMsg<Page<ReportManage>> getAllPage(long companyId, int classify, int pageNo, int pageSize){
-		ResultMsg<Page<ReportManage>> result = null;
-		try {
-			Page<ReportManage> list = reportManageDao.getAll(companyId, classify, pageNo, pageSize);
-			result = new ResultMsg<Page<ReportManage>>(SystemConstant.RESULT_STATUS_SUCCESS, list);
-		} catch (Exception e) {
-			logger.error("获取机构分类报表出错...", e);
-			result = new  ResultMsg<Page<ReportManage>>(SystemConstant.RESULT_STATUS_ERROR);
-		}
-		return result;
-	}
-	
-	/**
-	 * 新增报表定义
-	 * @param companyId
-	 * @param classify
-	 * @param reportManage
-	 * @return
-	 */
-	public ResultMsg<ReportManage> saveOne(long companyId, int classify, ReportManage reportManage) {
-		ResultMsg<ReportManage> result = null;
-		try {
-			reportManage.setClassify(classify);
-			reportManage.setCompanyId(companyId);
-			reportManage.setCreateTime(new Date().getTime());
-			reportManage.setState(1);
-			long id = reportManageDao.saveAndReturnId(reportManage);
-			reportManage.setId((int)id);
-			result = new ResultMsg<ReportManage>(SystemConstant.RESULT_STATUS_SUCCESS, reportManage);
-		} catch (Exception e) {
-			logger.error("新增报表定义数据出错...", e);
-			result = new ResultMsg<ReportManage>(SystemConstant.RESULT_STATUS_ERROR);
-		}
-		
-		return result;
-	}
-	
-	/**
-	 * 修改报表定义
-	 * @param id
-	 * @param reportManage
-	 * @return
-	 */
-	public ResultMsg<ReportManage> modifyOne(long id, int classify, ReportManage reportManage) {
-		ResultMsg<ReportManage> result = null;
-		try {
-			ReportManage oleReportManage = reportManageDao.get(id);
-			if(null == oleReportManage) throw new Exception();
-			DataUtils.copySimpleObject(reportManage, oleReportManage);
-			reportManageDao.update(reportManage);
-			result = new ResultMsg<ReportManage>(SystemConstant.RESULT_STATUS_SUCCESS, reportManage);
-		} catch (Exception e) {
-			logger.error("修改报表定义数据出错...", e);
-			result = new ResultMsg<ReportManage>(SystemConstant.RESULT_STATUS_ERROR);
-		}
-		
-		return result;
-	}
-	
-	/**
-	 * 删除报表信息
-	 * @param id
-	 * @return
-	 */
-	public ResultMsg<Boolean> deleteOne(long id) {
-		ResultMsg<Boolean> result = null;
-		try {
-			boolean status = reportManageDao.delete(id);
-			if(status)
-				result = new ResultMsg<Boolean>(SystemConstant.RESULT_STATUS_SUCCESS, status);
-			else
-				result = new ResultMsg<Boolean>(SystemConstant.RESULT_STATUS_FAILED);
-		} catch (Exception e) {
-			logger.error("删除报表定义数据出错...", e);
-			result = new ResultMsg<Boolean>(SystemConstant.RESULT_STATUS_ERROR);
-		}
-		
-		return result;
-	}
-	
-	/**
-	 * 根据报表ID获取日报表数据
-	 * @param reportId	报表ID
-	 * @param day	日期
-	 * @return
-	 */
-	public ResultMsg<List<ReportManageDataVo>> getReportDayDataById(long reportId, long day){
-		ResultMsg<List<ReportManageDataVo>> result = null;
-		try {
-			ReportManage reportManage = reportManageDao.get(reportId);
-			if(null == reportManage) throw new Exception();
-			
-			String[] terminalIds = reportManage.getTerminalId().split(",");
-			List<String> terminalIdList = new ArrayList<String>();
-			for(String id : terminalIds){
-				if(!StringUtils.isEmpty(id)){
-					terminalIdList.add(id);
-				}
-			}
-			
-			Map<String, ReportManageDataVo> reportMap = new LinkedHashMap<String, ReportManageDataVo>();
-			if(!terminalIdList.isEmpty()){
-				List<Monitor> monitorList = monitorDao.getListByTerminalIds(terminalIdList);
-				
-				Map<String, Monitor> monitorMap = new HashMap<String, Monitor>();
-				for (Monitor monitor : monitorList) {
-					monitorMap.put(monitor.getTerminalId(), monitor);
-				}
-				
-				for (Monitor monitor : monitorList) {
-					ReportManageDataVo reportDataVo = new ReportManageDataVo();
-					reportDataVo.setMonitorName(monitor.getName());
-					reportDataVo.setTerminalId(monitor.getTerminalId());
-					reportMap.put(monitor.getTerminalId(), reportDataVo);
-				}
-				if(!StringUtils.isEmpty(reportManage.getTpe())) {
-					List<AnalDateFgp> fgpList = analDateFgpDao.selectForTerminalIdsAndDay(terminalIds, day);
-					BigDecimal totalTpe = new BigDecimal(0),totalPrice = new BigDecimal(0);
-					for (AnalDateFgp analDateFgp : fgpList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateFgp.getTerminalId()), analDateFgp, false);
-						
-						analDateFgp.setfTpe(NumberUtils.round(analDateFgp.getfTpe(), 2));
-						analDateFgp.setgTpe(NumberUtils.round(analDateFgp.getgTpe(), 2));
-						analDateFgp.setpTpe(NumberUtils.round(analDateFgp.getpTpe(), 2));
-						analDateFgp.setjTpe(NumberUtils.round(analDateFgp.getjTpe(), 2));
-						
-						DataUtils.copySimpleObject(analDateFgp, reportMap.get(analDateFgp.getTerminalId()));
-						totalTpe = (analDateFgp.getfTpe().add(analDateFgp.getgTpe()).add(analDateFgp.getpTpe()).add(analDateFgp.getjTpe()));
-						totalPrice = (analDateFgp.getfPrice().add(analDateFgp.getgTpe()).add(analDateFgp.getpTpe()).add(analDateFgp.getjTpe()));
-						reportMap.get(analDateFgp.getTerminalId()).setTotalTpe(NumberUtils.round(totalTpe, 2));
-						reportMap.get(analDateFgp.getTerminalId()).setTotalPrice(NumberUtils.round(totalPrice,2));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getMaxs())) {
-					List<AnalDateMax> maxList = analDateMaxDao.queryByDate(day, terminalIds);
-					for (AnalDateMax analDateMax : maxList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateMax.getTerminalId()), analDateMax);
-						DataUtils.copySimpleObject(analDateMax, reportMap.get(analDateMax.getTerminalId()));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getMins())) {
-					List<AnalDateMin> minList = analDateMinDao.queryByDate(day, terminalIds);
-					for (AnalDateMin analDateMin : minList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateMin.getTerminalId()), analDateMin);
-						DataUtils.copySimpleObject(analDateMin, reportMap.get(analDateMin.getTerminalId()));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getAvgs())) {
-					List<AnalDateAvg> avgList = analDateAvgDao.queryByDate(day, terminalIds);
-					for (AnalDateAvg analDateAvg : avgList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateAvg.getTerminalId()), analDateAvg);
-						DataUtils.copySimpleObject(analDateAvg, reportMap.get(analDateAvg.getTerminalId()));
-					}
-				}
-			}
-			result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_SUCCESS, new ArrayList<ReportManageDataVo>(reportMap.values()));
-		} catch (Exception e) {
-			logger.error("获取日报表数据出错...", e);
-			result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_ERROR);
-		}
-		return result;
-	}
-	
-	/**
-	 * 根据报表ID获取月报表数据
-	 * @param reportId	报表ID
-	 * @param year	年份
-	 * @param month	月份
-	 * @return
-	 */
-	public ResultMsg<List<ReportManageDataVo>> getReportMonthDataById(long reportId, long month){
-		ResultMsg<List<ReportManageDataVo>> result = null;
-		try {
-			ReportManage reportManage = reportManageDao.get(reportId);
-			if(null == reportManage) throw new Exception();
-			
-			String[] terminalIds = reportManage.getTerminalId().split(",");
-			List<String> terminalIdList = new ArrayList<String>();
-			for(String id : terminalIds){
-				if(!StringUtils.isEmpty(id)){
-					terminalIdList.add(id);
-				}
-			}
-			
-			Map<String, ReportManageDataVo> reportMap = new LinkedHashMap<String, ReportManageDataVo>();
-			if(!terminalIdList.isEmpty()){
-				List<Monitor> monitorList = monitorDao.getListByTerminalIds(terminalIdList);
-				
-				Map<String, Monitor> monitorMap = new HashMap<String, Monitor>();
-				for (Monitor monitor : monitorList) {
-					if(!StringUtils.isEmpty(monitor.getTerminalId())){
-						monitorMap.put(monitor.getTerminalId(), monitor);
-					}
-				}
-				
-				for (Monitor monitor : monitorList) {
-					ReportManageDataVo reportDataVo = new ReportManageDataVo();
-					reportDataVo.setMonitorName(monitor.getName());
-					reportDataVo.setTerminalId(monitor.getTerminalId());
-					reportMap.put(monitor.getTerminalId(), reportDataVo);
-				}
-				if(!StringUtils.isEmpty(reportManage.getTpe())) {
-					List<AnalDateFgp> fgpList = analDateFgpDao.selectForTerminalIdsAndMonth(terminalIds, month);
-					BigDecimal totalTpe = new BigDecimal(0),totalPrice = new BigDecimal(0);
-					for (AnalDateFgp analDateFgp : fgpList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateFgp.getTerminalId()), analDateFgp, false);
-						
-						analDateFgp.setfTpe(NumberUtils.round(analDateFgp.getfTpe(), 2));
-						analDateFgp.setgTpe(NumberUtils.round(analDateFgp.getgTpe(), 2));
-						analDateFgp.setpTpe(NumberUtils.round(analDateFgp.getpTpe(), 2));
-						analDateFgp.setjTpe(NumberUtils.round(analDateFgp.getjTpe(), 2));
-						
-						DataUtils.copySimpleObject(analDateFgp, reportMap.get(analDateFgp.getTerminalId()));
-						
-						totalTpe = (analDateFgp.getfTpe().add(analDateFgp.getgTpe()).add(analDateFgp.getpTpe()).add(analDateFgp.getjTpe()));
-						totalPrice = (analDateFgp.getfPrice().add(analDateFgp.getgPrice()).add(analDateFgp.getpPrice()).add(analDateFgp.getjPrice()));
-						reportMap.get(analDateFgp.getTerminalId()).setTotalTpe(NumberUtils.round(totalTpe, 2));
-						reportMap.get(analDateFgp.getTerminalId()).setTotalPrice(NumberUtils.round(totalPrice,2));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getMaxs())) {
-					List<AnalMonthMax> maxList = analMonthMaxDao.queryByDate(month, terminalIds);
-					for (AnalMonthMax analMonthMax : maxList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analMonthMax.getTerminalId()), analMonthMax);
-						DataUtils.copySimpleObject(analMonthMax, reportMap.get(analMonthMax.getTerminalId()));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getMins())) {
-					List<AnalMonthMin> minList = analMonthMinDao.queryByDate(month, terminalIds);
-					for (AnalMonthMin analMonthMin : minList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analMonthMin.getTerminalId()), analMonthMin);
-						DataUtils.copySimpleObject(analMonthMin, reportMap.get(analMonthMin.getTerminalId()));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getAvgs())) {
-					List<AnalMonthAvg> avgList = analMonthAvgDao.queryByDate(month, terminalIds);
-					for (AnalMonthAvg analMonthAvg : avgList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analMonthAvg.getTerminalId()), analMonthAvg);
-						DataUtils.copySimpleObject(analMonthAvg, reportMap.get(analMonthAvg.getTerminalId()));
-					}
-				}
-			}
-			result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_SUCCESS, new ArrayList<ReportManageDataVo>(reportMap.values()));
-		} catch (Exception e) {
-			logger.error("获取月报表数据出错...", e);
-			result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_ERROR);
-		}
-		return result;
-	}
-	
-	/**
-	 * 根据报表ID获取年报表数据
-	 * @param reportId	报表ID
-	 * @param year	年份
-	 * @return
-	 */
-	public ResultMsg<List<ReportManageDataVo>> getReportYearDataById(long reportId, long year) {
-		ResultMsg<List<ReportManageDataVo>> result = null;
-		try {
-			ReportManage reportManage = reportManageDao.get(reportId);
-			if(null == reportManage) throw new Exception();
-			
-			String[] terminalIds = reportManage.getTerminalId().split(",");
-			List<String> terminalIdList = new ArrayList<String>();
-			for(String id : terminalIds){
-				if(!StringUtils.isEmpty(id)){
-					terminalIdList.add(id);
-				}
-			}
-			
-			Map<String, ReportManageDataVo> reportMap = new LinkedHashMap<String, ReportManageDataVo>();
-			if(!terminalIdList.isEmpty()){
-				List<Monitor> monitorList = monitorDao.getListByTerminalIds(terminalIdList);
-				
-				Map<String, Monitor> monitorMap = new HashMap<String, Monitor>();
-				for (Monitor monitor : monitorList) {
-					monitorMap.put(monitor.getTerminalId(), monitor);
-				}
-				
-				for (Monitor monitor : monitorList) {
-					ReportManageDataVo reportDataVo = new ReportManageDataVo();
-					reportDataVo.setMonitorName(monitor.getName());
-					reportDataVo.setTerminalId(monitor.getTerminalId());
-					reportMap.put(monitor.getTerminalId(), reportDataVo);
-				}
-				if(!StringUtils.isEmpty(reportManage.getTpe())) {
-					List<AnalDateFgp> fgpList = analDateFgpDao.selectForTerminalIdsAndYear(terminalIds, year);
-					BigDecimal totalTpe = new BigDecimal(0),totalPrice = new BigDecimal(0);
-					for (AnalDateFgp analDateFgp : fgpList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateFgp.getTerminalId()), analDateFgp, false);
-						
-						analDateFgp.setfTpe(NumberUtils.round(analDateFgp.getfTpe(), 2));
-						analDateFgp.setgTpe(NumberUtils.round(analDateFgp.getgTpe(), 2));
-						analDateFgp.setpTpe(NumberUtils.round(analDateFgp.getpTpe(), 2));
-						analDateFgp.setjTpe(NumberUtils.round(analDateFgp.getjTpe(), 2));
-						
-						DataUtils.copySimpleObject(analDateFgp, reportMap.get(analDateFgp.getTerminalId()));
-						totalTpe = (analDateFgp.getfTpe().add(analDateFgp.getgTpe()).add(analDateFgp.getpTpe()).add(analDateFgp.getjTpe()));
-						totalPrice = (analDateFgp.getfPrice().add(analDateFgp.getgPrice()).add(analDateFgp.getpPrice()).add(analDateFgp.getjPrice()));
-						reportMap.get(analDateFgp.getTerminalId()).setTotalTpe(NumberUtils.round(totalTpe, 2));
-						reportMap.get(analDateFgp.getTerminalId()).setTotalPrice(NumberUtils.round(totalPrice,2));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getMaxs())) {
-					List<AnalYearMax> maxList = analYearMaxDao.queryByDate(terminalIds, year);
-					for (AnalYearMax analYearMax : maxList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analYearMax.getTerminalId()), analYearMax);
-						DataUtils.copySimpleObject(analYearMax, reportMap.get(analYearMax.getTerminalId()));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getMins())) {
-					List<AnalYearMin> minList = analYearMinDao.queryByDate(terminalIds, year);
-					for (AnalYearMin analYearMin : minList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analYearMin.getTerminalId()), analYearMin);
-						DataUtils.copySimpleObject(analYearMin, reportMap.get(analYearMin.getTerminalId()));
-					}
-				}
-				if(!StringUtils.isEmpty(reportManage.getAvgs())) {
-					List<AnalYearAvg> avgList = analYearAvgDao.queryByDate(terminalIds, year);
-					for (AnalYearAvg analYearAvg : avgList) {
-						AnalDataCtPtUtil.addCtPt(monitorMap.get(analYearAvg.getTerminalId()), analYearAvg);
-						DataUtils.copySimpleObject(analYearAvg, reportMap.get(analYearAvg.getTerminalId()));
-					}
-				}
-			}
-			result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_SUCCESS, new ArrayList<ReportManageDataVo>(reportMap.values()));
-		} catch (Exception e) {
-			logger.error("获取年报表数据出错...", e);
-			result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_ERROR);
-		}
-		return result;
-	}
-	
-	/**
-	 * 导出数据到Excel
-	 * @param columnName
-	 * @param gridData
-	 * @return
-	 */
-	public ResultMsg<HSSFWorkbook> exportDataToExcel(String title, String columnName, String gridData) {
-		ResultMsg<HSSFWorkbook> result = new ResultMsg<HSSFWorkbook>();
-		try {
-			Map<String, String> headerMap = new LinkedHashMap<String, String>();//获取表头
-			
-			JSONObject json = JSONObject.parseObject(columnName);
-			JSONArray columns = JSONObject.parseArray(json.getString("elements"));
-			for (Object object : columns) {
-				JSONObject column = JSONObject.parseObject(object.toString());
-				headerMap.put(column.getString("key"), column.getString("value"));
-			}
-			List<ReportManageDataVo> dataList = JSONObject.parseArray(gridData, ReportManageDataVo.class);
-			ExcelUtil<ReportManageDataVo> excel = new ExcelUtil<ReportManageDataVo>();
-			HSSFWorkbook workbook = excel.writeExcel(headerMap, dataList, title);
-			result = new ResultMsg<HSSFWorkbook>(SystemConstant.RESULT_STATUS_SUCCESS, workbook);
-		} catch (Exception e) {
-			logger.error("导出报表数据出错...", e);
-			result = new ResultMsg<HSSFWorkbook>(SystemConstant.RESULT_STATUS_ERROR);
-		}
-		return result;
-	}
+
+    private static final Logger logger = Logger.getLogger(ReportManageServiceImpl.class);
+
+    @Autowired
+    private ReportManageDao reportManageDao;
+
+    @Autowired
+    private MonitorDao monitorDao;
+    @Autowired
+    private AnalDateFgpDao analDateFgpDao;
+
+    @Autowired
+    private AnalDateMaxDao analDateMaxDao;
+    @Autowired
+    private AnalDateMinDao analDateMinDao;
+    @Autowired
+    private AnalDateAvgDao analDateAvgDao;
+
+    @Autowired
+    private AnalMonthMaxDao analMonthMaxDao;
+    @Autowired
+    private AnalMonthMinDao analMonthMinDao;
+    @Autowired
+    private AnalMonthAvgDao analMonthAvgDao;
+
+    @Autowired
+    private AnalYearMaxDao analYearMaxDao;
+    @Autowired
+    private AnalYearMinDao analYearMinDao;
+    @Autowired
+    private AnalYearAvgDao analYearAvgDao;
+
+    /**
+     * 根据类型ID获取机构报表
+     *
+     * @param companyId
+     * @param classify
+     * @return
+     */
+    public ResultMsg<Page<ReportManage>> getAllPage(long companyId, int classify, int pageNo, int pageSize) {
+        ResultMsg<Page<ReportManage>> result = null;
+        try {
+            Page<ReportManage> list = reportManageDao.getAll(companyId, classify, pageNo, pageSize);
+            result = new ResultMsg<Page<ReportManage>>(SystemConstant.RESULT_STATUS_SUCCESS, list);
+        } catch (Exception e) {
+            logger.error("获取机构分类报表出错...", e);
+            result = new ResultMsg<Page<ReportManage>>(SystemConstant.RESULT_STATUS_ERROR);
+        }
+        return result;
+    }
+
+    /**
+     * 新增报表定义
+     *
+     * @param companyId
+     * @param classify
+     * @param reportManage
+     * @return
+     */
+    public ResultMsg<ReportManage> saveOne(long companyId, int classify, ReportManage reportManage) {
+        ResultMsg<ReportManage> result = null;
+        try {
+            reportManage.setClassify(classify);
+            reportManage.setCompanyId(companyId);
+            reportManage.setCreateTime(new Date().getTime());
+            reportManage.setState(1);
+            long id = reportManageDao.saveAndReturnId(reportManage);
+            reportManage.setId((int) id);
+            result = new ResultMsg<ReportManage>(SystemConstant.RESULT_STATUS_SUCCESS, reportManage);
+        } catch (Exception e) {
+            logger.error("新增报表定义数据出错...", e);
+            result = new ResultMsg<ReportManage>(SystemConstant.RESULT_STATUS_ERROR);
+        }
+
+        return result;
+    }
+
+    /**
+     * 修改报表定义
+     *
+     * @param id
+     * @param reportManage
+     * @return
+     */
+    public ResultMsg<ReportManage> modifyOne(long id, int classify, ReportManage reportManage) {
+        ResultMsg<ReportManage> result = null;
+        try {
+            ReportManage oleReportManage = reportManageDao.get(id);
+            if (null == oleReportManage) throw new Exception();
+            DataUtils.copySimpleObject(reportManage, oleReportManage);
+            reportManageDao.update(reportManage);
+            result = new ResultMsg<ReportManage>(SystemConstant.RESULT_STATUS_SUCCESS, reportManage);
+        } catch (Exception e) {
+            logger.error("修改报表定义数据出错...", e);
+            result = new ResultMsg<ReportManage>(SystemConstant.RESULT_STATUS_ERROR);
+        }
+
+        return result;
+    }
+
+    /**
+     * 删除报表信息
+     *
+     * @param id
+     * @return
+     */
+    public ResultMsg<Boolean> deleteOne(long id) {
+        ResultMsg<Boolean> result = null;
+        try {
+            boolean status = reportManageDao.delete(id);
+            if (status)
+                result = new ResultMsg<Boolean>(SystemConstant.RESULT_STATUS_SUCCESS, status);
+            else
+                result = new ResultMsg<Boolean>(SystemConstant.RESULT_STATUS_FAILED);
+        } catch (Exception e) {
+            logger.error("删除报表定义数据出错...", e);
+            result = new ResultMsg<Boolean>(SystemConstant.RESULT_STATUS_ERROR);
+        }
+
+        return result;
+    }
+
+    /**
+     * 根据报表ID获取日报表数据
+     *
+     * @param reportId 报表ID
+     * @param day      日期
+     * @return
+     */
+    public ResultMsg<List<ReportManageDataVo>> getReportDayDataById(long reportId, long day) {
+        ResultMsg<List<ReportManageDataVo>> result = null;
+        try {
+            ReportManage reportManage = reportManageDao.get(reportId);
+            if (null == reportManage) throw new Exception();
+
+            String[] terminalIds = reportManage.getTerminalId().split(",");
+            List<String> terminalIdList = new ArrayList<String>();
+            for (String id : terminalIds) {
+                if (!StringUtils.isEmpty(id)) {
+                    terminalIdList.add(id);
+                }
+            }
+
+            Map<String, ReportManageDataVo> reportMap = new LinkedHashMap<String, ReportManageDataVo>();
+            if (!terminalIdList.isEmpty()) {
+                List<Monitor> monitorList = monitorDao.getListByTerminalIds(terminalIdList);
+
+                Map<String, Monitor> monitorMap = new HashMap<String, Monitor>();
+                for (Monitor monitor : monitorList) {
+                    monitorMap.put(monitor.getTerminalId(), monitor);
+                }
+
+                for (Monitor monitor : monitorList) {
+                    ReportManageDataVo reportDataVo = new ReportManageDataVo();
+                    reportDataVo.setMonitorName(monitor.getName());
+                    reportDataVo.setTerminalId(monitor.getTerminalId());
+                    reportMap.put(monitor.getTerminalId(), reportDataVo);
+                }
+                if (!StringUtils.isEmpty(reportManage.getTpe())) {
+                    List<AnalDateFgp> fgpList = analDateFgpDao.selectForTerminalIdsAndDay(terminalIds, day);
+                    BigDecimal totalTpe = new BigDecimal(0), totalPrice = new BigDecimal(0);
+                    for (AnalDateFgp analDateFgp : fgpList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateFgp.getTerminalId()), analDateFgp, false);
+
+                        analDateFgp.setfTpe(NumberUtils.round(analDateFgp.getfTpe(), 2));
+                        analDateFgp.setgTpe(NumberUtils.round(analDateFgp.getgTpe(), 2));
+                        analDateFgp.setpTpe(NumberUtils.round(analDateFgp.getpTpe(), 2));
+                        analDateFgp.setjTpe(NumberUtils.round(analDateFgp.getjTpe(), 2));
+
+                        DataUtils.copySimpleObject(analDateFgp, reportMap.get(analDateFgp.getTerminalId()));
+                        totalTpe = (analDateFgp.getfTpe().add(analDateFgp.getgTpe()).add(analDateFgp.getpTpe()).add(analDateFgp.getjTpe()));
+                        totalPrice = (analDateFgp.getfPrice().add(analDateFgp.getgTpe()).add(analDateFgp.getpTpe()).add(analDateFgp.getjTpe()));
+                        reportMap.get(analDateFgp.getTerminalId()).setTotalTpe(NumberUtils.round(totalTpe, 2));
+                        reportMap.get(analDateFgp.getTerminalId()).setTotalPrice(NumberUtils.round(totalPrice, 2));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getMaxs())) {
+                    List<AnalDateMax> maxList = analDateMaxDao.queryByDate(day, terminalIds);
+                    for (AnalDateMax analDateMax : maxList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateMax.getTerminalId()), analDateMax);
+                        DataUtils.copySimpleObject(analDateMax, reportMap.get(analDateMax.getTerminalId()));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getMins())) {
+                    List<AnalDateMin> minList = analDateMinDao.queryByDate(day, terminalIds);
+                    for (AnalDateMin analDateMin : minList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateMin.getTerminalId()), analDateMin);
+                        DataUtils.copySimpleObject(analDateMin, reportMap.get(analDateMin.getTerminalId()));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getAvgs())) {
+                    List<AnalDateAvg> avgList = analDateAvgDao.queryByDate(day, terminalIds);
+                    for (AnalDateAvg analDateAvg : avgList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateAvg.getTerminalId()), analDateAvg);
+                        DataUtils.copySimpleObject(analDateAvg, reportMap.get(analDateAvg.getTerminalId()));
+                    }
+                }
+            }
+            result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_SUCCESS, new ArrayList<ReportManageDataVo>(reportMap.values()));
+        } catch (Exception e) {
+            logger.error("获取日报表数据出错...", e);
+            result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_ERROR);
+        }
+        return result;
+    }
+
+    /**
+     * 根据报表ID获取月报表数据
+     *
+     * @param reportId 报表ID
+     * @param year     年份
+     * @param month    月份
+     * @return
+     */
+    public ResultMsg<List<ReportManageDataVo>> getReportMonthDataById(long reportId, long month) {
+        ResultMsg<List<ReportManageDataVo>> result = null;
+        try {
+            ReportManage reportManage = reportManageDao.get(reportId);
+            if (null == reportManage) throw new Exception();
+
+            String[] terminalIds = reportManage.getTerminalId().split(",");
+            List<String> terminalIdList = new ArrayList<String>();
+            for (String id : terminalIds) {
+                if (!StringUtils.isEmpty(id)) {
+                    terminalIdList.add(id);
+                }
+            }
+
+            Map<String, ReportManageDataVo> reportMap = new LinkedHashMap<String, ReportManageDataVo>();
+            if (!terminalIdList.isEmpty()) {
+                List<Monitor> monitorList = monitorDao.getListByTerminalIds(terminalIdList);
+
+                Map<String, Monitor> monitorMap = new HashMap<String, Monitor>();
+                for (Monitor monitor : monitorList) {
+                    if (!StringUtils.isEmpty(monitor.getTerminalId())) {
+                        monitorMap.put(monitor.getTerminalId(), monitor);
+                    }
+                }
+
+                for (Monitor monitor : monitorList) {
+                    ReportManageDataVo reportDataVo = new ReportManageDataVo();
+                    reportDataVo.setMonitorName(monitor.getName());
+                    reportDataVo.setTerminalId(monitor.getTerminalId());
+                    reportMap.put(monitor.getTerminalId(), reportDataVo);
+                }
+                if (!StringUtils.isEmpty(reportManage.getTpe())) {
+                    List<AnalDateFgp> fgpList = analDateFgpDao.selectForTerminalIdsAndMonth(terminalIds, month);
+                    BigDecimal totalTpe = new BigDecimal(0), totalPrice = new BigDecimal(0);
+                    for (AnalDateFgp analDateFgp : fgpList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateFgp.getTerminalId()), analDateFgp, false);
+
+                        analDateFgp.setfTpe(NumberUtils.round(analDateFgp.getfTpe(), 2));
+                        analDateFgp.setgTpe(NumberUtils.round(analDateFgp.getgTpe(), 2));
+                        analDateFgp.setpTpe(NumberUtils.round(analDateFgp.getpTpe(), 2));
+                        analDateFgp.setjTpe(NumberUtils.round(analDateFgp.getjTpe(), 2));
+
+                        DataUtils.copySimpleObject(analDateFgp, reportMap.get(analDateFgp.getTerminalId()));
+
+                        totalTpe = (analDateFgp.getfTpe().add(analDateFgp.getgTpe()).add(analDateFgp.getpTpe()).add(analDateFgp.getjTpe()));
+                        totalPrice = (analDateFgp.getfPrice().add(analDateFgp.getgPrice()).add(analDateFgp.getpPrice()).add(analDateFgp.getjPrice()));
+                        reportMap.get(analDateFgp.getTerminalId()).setTotalTpe(NumberUtils.round(totalTpe, 2));
+                        reportMap.get(analDateFgp.getTerminalId()).setTotalPrice(NumberUtils.round(totalPrice, 2));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getMaxs())) {
+                    List<AnalMonthMax> maxList = analMonthMaxDao.queryByDate(month, terminalIds);
+                    for (AnalMonthMax analMonthMax : maxList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analMonthMax.getTerminalId()), analMonthMax);
+                        DataUtils.copySimpleObject(analMonthMax, reportMap.get(analMonthMax.getTerminalId()));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getMins())) {
+                    List<AnalMonthMin> minList = analMonthMinDao.queryByDate(month, terminalIds);
+                    for (AnalMonthMin analMonthMin : minList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analMonthMin.getTerminalId()), analMonthMin);
+                        DataUtils.copySimpleObject(analMonthMin, reportMap.get(analMonthMin.getTerminalId()));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getAvgs())) {
+                    List<AnalMonthAvg> avgList = analMonthAvgDao.queryByDate(month, terminalIds);
+                    for (AnalMonthAvg analMonthAvg : avgList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analMonthAvg.getTerminalId()), analMonthAvg);
+                        DataUtils.copySimpleObject(analMonthAvg, reportMap.get(analMonthAvg.getTerminalId()));
+                    }
+                }
+            }
+            result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_SUCCESS, new ArrayList<ReportManageDataVo>(reportMap.values()));
+        } catch (Exception e) {
+            logger.error("获取月报表数据出错...", e);
+            result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_ERROR);
+        }
+        return result;
+    }
+
+    /**
+     * 根据报表ID获取年报表数据
+     *
+     * @param reportId 报表ID
+     * @param year     年份
+     * @return
+     */
+    public ResultMsg<List<ReportManageDataVo>> getReportYearDataById(long reportId, long year) {
+        ResultMsg<List<ReportManageDataVo>> result = null;
+        try {
+            ReportManage reportManage = reportManageDao.get(reportId);
+            if (null == reportManage) throw new Exception();
+
+            String[] terminalIds = reportManage.getTerminalId().split(",");
+            List<String> terminalIdList = new ArrayList<String>();
+            for (String id : terminalIds) {
+                if (!StringUtils.isEmpty(id)) {
+                    terminalIdList.add(id);
+                }
+            }
+
+            Map<String, ReportManageDataVo> reportMap = new LinkedHashMap<String, ReportManageDataVo>();
+            if (!terminalIdList.isEmpty()) {
+                List<Monitor> monitorList = monitorDao.getListByTerminalIds(terminalIdList);
+
+                Map<String, Monitor> monitorMap = new HashMap<String, Monitor>();
+                for (Monitor monitor : monitorList) {
+                    monitorMap.put(monitor.getTerminalId(), monitor);
+                }
+
+                for (Monitor monitor : monitorList) {
+                    ReportManageDataVo reportDataVo = new ReportManageDataVo();
+                    reportDataVo.setMonitorName(monitor.getName());
+                    reportDataVo.setTerminalId(monitor.getTerminalId());
+                    reportMap.put(monitor.getTerminalId(), reportDataVo);
+                }
+                if (!StringUtils.isEmpty(reportManage.getTpe())) {
+                    List<AnalDateFgp> fgpList = analDateFgpDao.selectForTerminalIdsAndYear(terminalIds, year);
+                    BigDecimal totalTpe = new BigDecimal(0), totalPrice = new BigDecimal(0);
+                    for (AnalDateFgp analDateFgp : fgpList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analDateFgp.getTerminalId()), analDateFgp, false);
+
+                        analDateFgp.setfTpe(NumberUtils.round(analDateFgp.getfTpe(), 2));
+                        analDateFgp.setgTpe(NumberUtils.round(analDateFgp.getgTpe(), 2));
+                        analDateFgp.setpTpe(NumberUtils.round(analDateFgp.getpTpe(), 2));
+                        analDateFgp.setjTpe(NumberUtils.round(analDateFgp.getjTpe(), 2));
+
+                        DataUtils.copySimpleObject(analDateFgp, reportMap.get(analDateFgp.getTerminalId()));
+                        totalTpe = (analDateFgp.getfTpe().add(analDateFgp.getgTpe()).add(analDateFgp.getpTpe()).add(analDateFgp.getjTpe()));
+                        totalPrice = (analDateFgp.getfPrice().add(analDateFgp.getgPrice()).add(analDateFgp.getpPrice()).add(analDateFgp.getjPrice()));
+                        reportMap.get(analDateFgp.getTerminalId()).setTotalTpe(NumberUtils.round(totalTpe, 2));
+                        reportMap.get(analDateFgp.getTerminalId()).setTotalPrice(NumberUtils.round(totalPrice, 2));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getMaxs())) {
+                    List<AnalYearMax> maxList = analYearMaxDao.queryByDate(terminalIds, year);
+                    for (AnalYearMax analYearMax : maxList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analYearMax.getTerminalId()), analYearMax);
+                        DataUtils.copySimpleObject(analYearMax, reportMap.get(analYearMax.getTerminalId()));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getMins())) {
+                    List<AnalYearMin> minList = analYearMinDao.queryByDate(terminalIds, year);
+                    for (AnalYearMin analYearMin : minList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analYearMin.getTerminalId()), analYearMin);
+                        DataUtils.copySimpleObject(analYearMin, reportMap.get(analYearMin.getTerminalId()));
+                    }
+                }
+                if (!StringUtils.isEmpty(reportManage.getAvgs())) {
+                    List<AnalYearAvg> avgList = analYearAvgDao.queryByDate(terminalIds, year);
+                    for (AnalYearAvg analYearAvg : avgList) {
+                        AnalDataCtPtUtil.addCtPt(monitorMap.get(analYearAvg.getTerminalId()), analYearAvg);
+                        DataUtils.copySimpleObject(analYearAvg, reportMap.get(analYearAvg.getTerminalId()));
+                    }
+                }
+            }
+            result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_SUCCESS, new ArrayList<ReportManageDataVo>(reportMap.values()));
+        } catch (Exception e) {
+            logger.error("获取年报表数据出错...", e);
+            result = new ResultMsg<List<ReportManageDataVo>>(SystemConstant.RESULT_STATUS_ERROR);
+        }
+        return result;
+    }
+
+    /**
+     * 导出数据到Excel
+     *
+     * @param columnName
+     * @param gridData
+     * @return
+     */
+    public ResultMsg<HSSFWorkbook> exportDataToExcel(String title, String columnName, String gridData) {
+        ResultMsg<HSSFWorkbook> result = new ResultMsg<HSSFWorkbook>();
+        try {
+            Map<String, String> headerMap = new LinkedHashMap<String, String>();//获取表头
+
+            JSONObject json = JSONObject.parseObject(columnName);
+            JSONArray columns = JSONObject.parseArray(json.getString("elements"));
+            for (Object object : columns) {
+                JSONObject column = JSONObject.parseObject(object.toString());
+                headerMap.put(column.getString("key"), column.getString("value"));
+            }
+            //List<ReportManageDataVo> dataList = JSONObject.parseArray(gridData, ReportManageDataVo.class);
+            List<Object> dataList = JSONObject.parseArray(gridData);
+            ExcelUtil<Object> excel = new ExcelUtil<Object>();
+            HSSFWorkbook workbook = excel.writeExcel(headerMap, dataList, title);
+            result = new ResultMsg<HSSFWorkbook>(SystemConstant.RESULT_STATUS_SUCCESS, workbook);
+        } catch (Exception e) {
+            logger.error("导出报表数据出错...", e);
+            result = new ResultMsg<HSSFWorkbook>(SystemConstant.RESULT_STATUS_ERROR);
+        }
+        return result;
+    }
 }