Browse Source

水电站月报导出功能

zhongwei
tyty 1 year ago
parent
commit
2b61488103
  1. 38
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/CheckChartVo.java
  2. 43
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/MonPowerPercentageVo.java
  3. 23
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/TicketChartCell.java
  4. 22
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/TicketChartVo.java
  5. 6
      hzims-service/operational/pom.xml
  6. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyEmergencyServiceImpl.java
  7. 16
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java
  8. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAreaMonthReportService.java
  9. 2183
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java
  10. 627
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/JFreeUtil.java
  11. 121
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java

38
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/CheckChartVo.java

@ -0,0 +1,38 @@
package com.hnac.hzims.operational.report.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author hx
*/
@Data
@ApiModel("缺陷统计表")
public class CheckChartVo {
@ApiModelProperty(value = "场站名称")
private String deptName;
@ApiModelProperty(value = "缺陷分类")
private String checkLevel;
@ApiModelProperty(value = "本月-发现缺陷")
private Integer findShortagesMon;
@ApiModelProperty(value = "本月-消缺数")
private Integer shortagesMon;
@ApiModelProperty(value = "本年-发现缺陷")
private Integer findShortagesYear;
@ApiModelProperty(value = "本年-消缺数")
private Integer shortagesYear;
@ApiModelProperty(value = "本年-消缺率")
private Double shortagesRate;
public CheckChartVo(String deptName, String checkLevel, Integer findShortagesMon, Integer shortagesMon, Integer findShortagesYear, Integer shortagesYear, Double shortagesRate) {
this.deptName=deptName;
this.checkLevel=checkLevel;
this.findShortagesMon=findShortagesMon;
this.shortagesMon=shortagesMon;
this.findShortagesYear=findShortagesYear;
this.shortagesYear=shortagesYear;
this.shortagesRate=shortagesRate;
}
}

43
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/MonPowerPercentageVo.java

@ -0,0 +1,43 @@
package com.hnac.hzims.operational.report.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author ysj
*/
@Data
@ApiModel(value = "水电站发电量同比数据对象")
public class MonPowerPercentageVo {
@ApiModelProperty(value = "机构Id")
private Long deptId;
@ApiModelProperty(value = "机构名称")
private String deptName;
@ApiModelProperty(value = "设备名称")
private String deviceName;
@ApiModelProperty(value = "年计划发电量")
private Float planPower;
@ApiModelProperty(value = "今年发电量")
private Float powerYear;
@ApiModelProperty(value = "去年发电量")
private Float powerYearBefore;
@ApiModelProperty(value = "当月发电量")
private Float powerMon;
@ApiModelProperty(value = "上个月发电量")
private Float powerMonBefore;
@ApiModelProperty(value = "去年当月发电量")
private Float powerMonYearBefore;
@ApiModelProperty(value = "两年间:年发电量环比")
private Float powerYearPercentage;
@ApiModelProperty(value = "两年间:月发电量环比")
private Float powerMonPercentage;
@ApiModelProperty(value = "年计划完成率")
private Float planPercentage;
}

23
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/TicketChartCell.java

@ -0,0 +1,23 @@
package com.hnac.hzims.operational.report.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author hx
*/
@Data
@ApiModel("两票统计单元格")
public class TicketChartCell {
@ApiModelProperty(value = "票名")
private String ticketName;
@ApiModelProperty(value = "本月数量")
private Integer ticketMon;
@ApiModelProperty(value = "本月合格率")
private Double ticketMonPerc;
@ApiModelProperty(value = "本年数量")
private Integer ticketYear;
@ApiModelProperty(value = "本年合格率")
private Double ticketYeaPercr;
}

22
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/TicketChartVo.java

@ -0,0 +1,22 @@
package com.hnac.hzims.operational.report.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author hx
*/
@Data
@ApiModel("两票统计表")
public class TicketChartVo {
@ApiModelProperty(value = "场站名称")
private String deptName;
@ApiModelProperty(value = "数量和合格率")
private List<TicketChartCell> chartCells;
}

6
hzims-service/operational/pom.xml

@ -74,6 +74,12 @@
<artifactId>poi-ooxml-schemas</artifactId> <artifactId>poi-ooxml-schemas</artifactId>
<version>3.15</version> <version>3.15</version>
</dependency> </dependency>
<!-- 由于poi使用的poi-ooxml-schemas是ooxml-schemas的精简版,所以在was服务器上导出Excel可能会报错-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.jfree</groupId> <groupId>org.jfree</groupId>
<artifactId>jcommon</artifactId> <artifactId>jcommon</artifactId>

3
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyEmergencyServiceImpl.java

@ -80,6 +80,9 @@ public class ImsDutyEmergencyServiceImpl extends BaseServiceImpl<ImsDutyEmergenc
if (CollectionUtils.isNotEmpty(records)){ if (CollectionUtils.isNotEmpty(records)){
collect= records.stream().map(sig -> { collect= records.stream().map(sig -> {
R<User> user = userClient.userInfoById(sig.getRegistrant()); R<User> user = userClient.userInfoById(sig.getRegistrant());
if (!user.isSuccess()&&ObjectUtils.isNotEmpty(user)){
}
sig.setRegistrantName(user.getData().getName()); sig.setRegistrantName(user.getData().getName());
R<User> userR = userClient.userInfoById(sig.getChargePerson()); R<User> userR = userClient.userInfoById(sig.getChargePerson());
sig.setChargePersonName(userR.getData().getName()); sig.setChargePersonName(userR.getData().getName());

16
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AreaMonthReportController.java

@ -38,6 +38,7 @@ public class AreaMonthReportController extends BladeController {
@NotNull @NotNull
private final IAreaMonthReportService service; private final IAreaMonthReportService service;
private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key";
@ApiLog @ApiLog
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@ -113,5 +114,20 @@ public class AreaMonthReportController extends BladeController {
WordUtils.exportWord("template/demo2.docx", "F:/", "生成文件.docx", map); WordUtils.exportWord("template/demo2.docx", "F:/", "生成文件.docx", map);
return R.success("测试成功"); return R.success("测试成功");
} }
@ApiLog
@ApiOperationSupport(order = 3)
@ApiOperation("导出水电站月报")
@GetMapping("/exportHydropowerStationMonthReport")
public R exportHydropowerStationMonthReport(HttpServletResponse response, @ApiParam(value = "日期-年", required = true) Integer year,@ApiParam(value = "日期-月", required = true) Integer month,@ApiParam(value = "日期-日", required = true) Integer date,@ApiParam(value = "站点Id", required = true) Long stationId) {
HashMap<String, Object> map = new HashMap<>(4);
// map.put("personlist", list);
//word模板相对路径、word生成路径、word生成的文件名称、数据源
WordUtils.exportWord("template/demo2.docx", "F:/", "生成文件.docx", map);
service.exportHydropowerStationMonthReport(response, map,year,month,date,stationId);
return R.success("测试成功");
}
} }

3
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAreaMonthReportService.java

@ -4,6 +4,7 @@ import com.hnac.hzims.operational.main.vo.AreaMonthReportVo;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
@ -16,4 +17,6 @@ public interface IAreaMonthReportService {
R<List<AreaMonthReportVo>> getReport(String date); R<List<AreaMonthReportVo>> getReport(String date);
R export(HttpServletResponse response, String date); R export(HttpServletResponse response, String date);
R exportHydropowerStationMonthReport(HttpServletResponse response, HashMap<String, Object> map, Integer year, Integer month, Integer date,Long stationId);
} }

2183
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AreaMonthReportServiceImpl.java

File diff suppressed because it is too large Load Diff

627
hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/JFreeUtil.java

@ -3,6 +3,7 @@ package com.hnac.hzims.operational.util;
import cn.afterturn.easypoi.entity.ImageEntity; import cn.afterturn.easypoi.entity.ImageEntity;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils; import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart; import org.jfree.chart.JFreeChart;
@ -17,6 +18,8 @@ import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.chart.renderer.category.LineAndShapeRenderer; import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.DefaultPieDataset;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
import java.awt.*; import java.awt.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -57,7 +60,85 @@ public class JFreeUtil {
file.delete(); file.delete();
return buffer; return buffer;
} }
public static ImageEntity pieChartByDouble(String title, Map<String, Double> datas, int width, int height) {
//创建主题样式
StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
//设置标题字体
standardChartTheme.setExtraLargeFont(new Font("宋体", Font.BOLD, 20));
//设置图例的字体
standardChartTheme.setRegularFont(new Font("宋体", Font.PLAIN, 15));
//设置轴向的字体
standardChartTheme.setLargeFont(new Font("宋体", Font.PLAIN, 15));
//设置主题样式
ChartFactory.setChartTheme(standardChartTheme);
//根据jfree生成一个本地饼状图
DefaultPieDataset pds = new DefaultPieDataset();
datas.forEach(pds::setValue);
//图标标题、数据集合、是否显示图例标识、是否显示tooltips、是否支持超链接
JFreeChart chart = ChartFactory.createPieChart(title, pds, true, false, false);
//设置抗锯齿
chart.setTextAntiAlias(false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setNoDataMessage("暂无数据");
//忽略无值的分类
plot.setIgnoreNullValues(true);
plot.setBackgroundAlpha(0f);
//设置标签阴影颜色
plot.setShadowPaint(new Color(255, 255, 255));
//设置标签生成器(默认{0})
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}({1})/{2}"));
try {
ChartUtils.saveChartAsJPEG(new File(tempImgPath), chart, width, height);
} catch (IOException e1) {
log.error("生成饼状图失败!");
}
ImageEntity imageEntity = new ImageEntity(imgToByte(tempImgPath), width, height);
Assert.notNull(imageEntity.getData(), "生成饼状图对象失败!");
return imageEntity;
}
public static ImageEntity lineChartV2( String title,String[] monthArray,double[] value,int width, int height) {
// 创建数据
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, "A", "Ⅰ");
dataset.addValue(3.0, "A", "Ⅱ");
dataset.addValue(5.0, "A", "Ⅲ");
dataset.addValue(5.0, "A", "Ⅳ");
dataset.addValue(5.0, "B", "Ⅰ");
dataset.addValue(6.0, "B", "Ⅱ");
dataset.addValue(10.0, "B", "Ⅲ");
dataset.addValue(4.0, "B", "Ⅳ");
// 创建CategoryPlot对象
CategoryPlot plot = new CategoryPlot();
// 添加第一个数据集并渲染为line
CategoryItemRenderer lineRenderer = new LineAndShapeRenderer();
plot.setDataset(0, dataset);
plot.setRenderer(0, lineRenderer);
// 添加第二个数据集并渲染为线条bar
CategoryItemRenderer baRenderer = new BarRenderer();
plot.setDataset(1, dataset);
plot.setRenderer(1, baRenderer);
// 设置坐标轴
plot.setDomainAxis(new CategoryAxis("Time"));
plot.setRangeAxis(new NumberAxis("Value"));
// 创建JFreeChart对象
JFreeChart chart = new JFreeChart(plot);
try {
ChartUtils.saveChartAsJPEG(new File(tempImgPath2), chart, width, height);
} catch (IOException e) {
e.printStackTrace();
}
ImageEntity imageEntity = new ImageEntity(imgToByte(tempImgPath2), width, height);
Assert.notNull(imageEntity.getData(),"生成饼状图对象失败!");
return imageEntity;
}
public static ImageEntity pieChart(String title, Map<String, Integer> datas, int width, int height) { public static ImageEntity pieChart(String title, Map<String, Integer> datas, int width, int height) {
//创建主题样式 //创建主题样式
@ -179,534 +260,20 @@ public class JFreeUtil {
Assert.notNull(imageEntity.getData(),"生成饼状图对象失败!"); Assert.notNull(imageEntity.getData(),"生成饼状图对象失败!");
return imageEntity; return imageEntity;
} }
// public static ImageEntity lineChart( String title,String[] monthArray,double[] value,int width, int height) {
// //如果不使用Font,中文将显示不出来 public static void mergeCell(XWPFTable table, int beginRowIndex, int endRowIndex, int colIndex) {
// Font font = new Font("新宋体", Font.BOLD, 15); if (beginRowIndex == endRowIndex || beginRowIndex > endRowIndex) {
// // 创建数据 return;
// Map<String, Map<String, Double>> datas = new HashMap<String, Map<String, Double>>(); }
// for (int i = 0; i < monthArray.length; i++) { //合并行单元格的第一个单元格
// Map<String, Double> map = new HashMap<String, Double>(); CTVMerge startMerge = CTVMerge.Factory.newInstance();
// map.put("故障数量", value[i]); startMerge.setVal(STMerge.RESTART);
// datas.put(monthArray[i], map); //合并行单元格的第一个单元格之后的单元格
// } CTVMerge endMerge = CTVMerge.Factory.newInstance();
// JFreeChart chart = createLineChart(title, datas, "月份", "故障次数(次)", font); endMerge.setVal(STMerge.CONTINUE);
// try { table.getRow(beginRowIndex).getCell(colIndex).getCTTc().getTcPr().setVMerge(startMerge);
// ChartUtils.saveChartAsJPEG(new File(tempImgPath), chart, 800, 600); for (int i = beginRowIndex + 1; i <= endRowIndex; i++) {
// } catch (IOException e) { table.getRow(i).getCell(colIndex).getCTTc().getTcPr().setVMerge(endMerge);
// e.printStackTrace(); }
// } }
// ImageEntity imageEntity = new ImageEntity(imgToByte(), 800, 600);
// Assert.notNull(imageEntity.getData(),"生成饼状图对象失败!");
// return imageEntity;
// }
//
// public static JFreeChart createLineChart(String title, Map<String, Map<String, Double>> data, String type, String unit, Font font) {
// try {
// DefaultCategoryDataset ds = new DefaultCategoryDataset();
// Set<Map.Entry<String, Map<String, Double>>> set1 = data.entrySet();
// Iterator iterator1 = set1.iterator();
// Iterator iterator2;
// HashMap<String, Double> map;
// Set<Map.Entry<String, Double>> set2;
// Map.Entry entry1;
// Map.Entry entry2;
// while (iterator1.hasNext()) {
// entry1 = (Map.Entry) iterator1.next();
// map = (HashMap<String, Double>) entry1.getValue();
// set2 = map.entrySet();
// iterator2 = set2.iterator();
// while (iterator2.hasNext()) {
// entry2 = (Map.Entry) iterator2.next();
// ds.setValue(Double.parseDouble(entry2.getValue().toString()), entry2.getKey().toString(), entry1.getKey().toString());
// }
// }
//
// //创建折线图,折线图分水平显示和垂直显示两种
// // //2D折线图
// JFreeChart chart = ChartFactory.createLineChart(title, type, unit, ds, PlotOrientation.VERTICAL, true, true, true);
// // //3D折线图
//// JFreeChart chart2 = ChartFactory.createLineChart3D(title, type, unit, ds, PlotOrientation.VERTICAL, true, true, false);
//
// //设置整个图片的标题字体
// chart.getTitle().setFont(font);
//
// //设置提示条字体
// font = new Font("宋体", Font.BOLD, 15);
// chart.getLegend().setItemFont(font);
//
// //得到绘图区
// CategoryPlot plot = (CategoryPlot) chart.getPlot();
// //得到绘图区的域轴(横轴),设置标签的字体
// plot.getDomainAxis().setLabelFont(font);
//
// // 设置背景透明度
// plot.setBackgroundAlpha(0.1f);
// // 设置网格横线颜色
// plot.setRangeGridlinePaint(Color.gray);
// // 设置网格横线大小
// plot.setDomainGridlineStroke(new BasicStroke(0.2F));
// plot.setRangeGridlineStroke(new BasicStroke(0.2F));
//
// //设置横轴标签项字体
// plot.getDomainAxis().setTickLabelFont(font);
//
// // 生成折线图上的数字
// //绘图区域(红色矩形框的部分)
// LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) plot.getRenderer();
// lineAndShapeRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
// //设置图表上的数字可见
// lineAndShapeRenderer.setBaseItemLabelsVisible(true);
// //设置图表上的数字字体
// lineAndShapeRenderer.setBaseItemLabelFont(new Font("宋体", Font.BOLD, 15));
//
// //设置折线图拐角上的正方形
// //创建一个正方形
// Rectangle shape = new Rectangle(4, 4);
// lineAndShapeRenderer.setSeriesShape(0, shape);
// //设置拐角上图形可见
// lineAndShapeRenderer.setSeriesShapesVisible(0, true);
//
// /*// 获取显示线条的对象
// LineAndShapeRenderer lasp = (LineAndShapeRenderer) plot.getRenderer();
// // 设置拐点是否可见/是否显示拐点
// lasp.setBaseShapesVisible(true);
// // 设置拐点不同用不同的形状
// lasp.setDrawOutlines(true);
// // 设置线条是否被显示填充颜色
// lasp.setUseFillPaint(true);
// // 设置拐点颜色
// lasp.setBaseFillPaint(Color.blue);//蓝色*/
// //设置范围轴(纵轴)字体
// font = new Font("宋体", Font.BOLD, 18);
// plot.getRangeAxis().setLabelFont(font);
//// plot.setForegroundAlpha(1.0f);
// return chart;
// } catch (Exception e) {
// e.printStackTrace();
// return null;
// }
// }
//
// /**
// * 生成折线图
// * 1.解析数据<br>
// * 2.迭代数据,产出图片数据流,并添加到List<br>
// *
// * @throws IOException
// */
// public ArrayList createLineAndShapeChart(double[][] data, String[] rowKeys, String[] columnKeys, ChartEntity entity) throws IOException {
// ArrayList list = new ArrayList();
// byte[] bytes = new byte[]{};
// // 解析数据
// Map map = this.parseDataForBarPage(data, rowKeys, columnKeys);
// int pageNum = Integer.parseInt("" + map.get("pageNum"));
// // 迭代,产生图片数据流
// for (int i = 0; i < pageNum; i++) {
// bytes = createSingleLineAndShapeChart((double[][]) (map.get("data" + i)), (String[]) (map.get("rowKeys" + i)),
// (String[]) (map.get("columnKeys" + i)), entity);
// list.add(bytes);
// }
// return list;
// }
//
// /**
// * 生成单个折线图数据流
// *
// * @param data
// * @param rowKeys
// * @param columnKeys
// * @param entity
// * @return
// * @throws IOException
// */
// public byte[] createSingleLineAndShapeChart(double[][] data, String[] rowKeys, String[] columnKeys, ChartEntity entity) throws IOException {
// CategoryDataset dataset = getBarData(data, rowKeys, columnKeys);
// JFreeChart chart = createTimeXYChar(dataset, entity);
// byte[] bytes = this.createImage(chart, entity);
// return bytes;
// }
//
//
// /**
// * 生成柱状图<br>
// * 1.解析数据<br>
// * 2.迭代数据,产出图片数据流,并添加到List<br>
// *
// * @param data 数据
// * @param rowKeys 行
// * @param columnKeys 列
// * @param entity 图片配置对象
// * @return 包含多个图片数据流的List
// * @throws IOException
// */
// public ArrayList createStackedBarChart(double[][] data, String[] rowKeys, String[] columnKeys, ChartEntity entity) throws IOException {
// // 解析数据
// ArrayList list = new ArrayList();
// byte[] bytes = new byte[]{};
// Map map = this.parseDataForBarPage(data, rowKeys, columnKeys);
// int pageNum = Integer.parseInt("" + map.get("pageNum"));
// // 迭代数据,产出图片数据流,并添加到List
// for (int i = 0; i < pageNum; i++) {
// bytes = createSingleStackedBarChart((double[][]) (map.get("data" + i)), (String[]) (map.get("rowKeys" + i)),
// (String[]) (map.get("columnKeys" + i)), entity);
// list.add(bytes);
// }
// return list;
// }
//
// /**
// * 解析生成柱状图分页数据
// *
// * @param data
// * @param rowKeys
// * @param columnKeys
// * @return
// */
// private Map parseDataForBarPage(double[][] data, String[] rowKeys, String[] columnKeys) {
// Map map = new HashMap();
//
// double[][] pageData = null;
// String[] pageColumn = null;
//
// int sumColumnNum = columnKeys.length; // 总列数
// int indexNum = Config.getInt("image.export.pagesize", 10);// 分页的列数
// int pageNum = sumColumnNum % indexNum == 0 ? sumColumnNum / indexNum : sumColumnNum / indexNum + 1; // 分页数
// int rowNum = rowKeys.length;
//
// // log.debug("data.length="+data.length+"sumColumnNum="+sumColumnNum+" indexNum="+indexNum+" pageNum="+pageNum+" rowNum="+rowNum+" ");
//
// // 解析传递过来的数据
// for (int i = 0; i < pageNum; i++) {
// int columnNum = (sumColumnNum - i * indexNum) / indexNum > 0 ? indexNum : (sumColumnNum - i * indexNum) % indexNum;//当前页列数
// pageData = new double[rowNum][columnNum];
// // 取数据值
// for (int j = 0; j < rowNum; j++) {
// pageColumn = new String[columnNum];
// for (int k = 0; k < columnNum; k++) {
// pageData[j][k] = data[j][k + i * indexNum]; // 数据
// }
// }
// // 取列值
// for (int j = 0; j < columnNum; j++) {
// pageColumn[j] = columnKeys[j + i * indexNum]; // 列
// }
// // 保存数据并返回
// map.put("data" + i, pageData);
// map.put("rowKeys" + i, rowKeys);
// map.put("columnKeys" + i, pageColumn);
// }
// // 保存分页数
// map.put("pageNum", pageNum);
// return map;
// }
//
// /**
// * 解析生成折线图分页数据
// *
// * @param data
// * @param rowKeys
// * @param columnKeys
// * @return
// */
// private Map parseDataForLinePage(double[][] data, String[] rowKeys, String[] columnKeys) {
// Map map = new HashMap();
//
// double[][] pageData = null;
// String[] pageColumn = null;
//
// int sumColumnNum = columnKeys.length; // 总列数
// int indexNum = Config.getInt("image.export.pagesize", 10);// 分页的列数
// int pageNum = sumColumnNum % indexNum == 0 ? sumColumnNum / indexNum : sumColumnNum / indexNum + 1; // 分页数
// int rowNum = rowKeys.length;
//
// // log.debug("data.length="+data.length+"sumColumnNum="+sumColumnNum+" indexNum="+indexNum+" pageNum="+pageNum+" rowNum="+rowNum+" ");
//
// // 解析传递过来的数据
// for (int i = 0; i < pageNum; i++) {
// int columnNum = (sumColumnNum - i * indexNum) / indexNum > 0 ? indexNum : (sumColumnNum - i * indexNum) % indexNum;//当前页列数
// pageData = new double[rowNum][columnNum];
// // 取数据值
// for (int j = 0; j < rowNum; j++) {
// pageColumn = new String[columnNum];
// for (int k = 0; k < columnNum; k++) {
// pageData[j][k] = data[j][k + i * indexNum]; // 数据
// }
// }
// // 取列值
// for (int j = 0; j < columnNum; j++) {
// pageColumn[j] = columnKeys[j + i * indexNum]; // 列
// }
// // 保存数据并返回
// map.put("data" + i, pageData);
// map.put("rowKeys" + i, rowKeys);
// map.put("columnKeys" + i, pageColumn);
// }
// // 保存分页数
// map.put("pageNum", pageNum);
// return map;
// }
//
// /**
// * 生成单个堆栈柱状图
// *
// * @return 图片数据流
// * @throws IOException
// */
// public byte[] createSingleStackedBarChart(double[][] data, String[] rowKeys, String[] columnKeys, ChartEntity entity) throws IOException {
// CategoryDataset dataset = getBarData(data, rowKeys, columnKeys);
// JFreeChart chart = createStackedBarChart(dataset, entity);
// byte[] bytes = this.createImage(chart, entity);
// return bytes;
// }
//
// // 柱状图,折线图 数据集
// private CategoryDataset getBarData(double[][] data, String[] rowKeys,
// String[] columnKeys) {
// return DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
//
// }
//
// /**
// * 判断文件夹是否存在,如果不存在则新建
// *
// * @param chartPath
// */
// private void isChartPathExist(String chartPath) {
// File file = new File(chartPath);
// if (!file.exists()) {
// file.mkdirs();
// }
// }
//
// /**
// * 折线图
// */
// private JFreeChart createTimeXYChar(CategoryDataset xyDataset, ChartEntity entity) {
//
// JFreeChart chart = ChartFactory.createLineChart(
// entity.getTitle(),
// entity.getXname(),
// entity.getYname(),
// xyDataset,
// PlotOrientation.VERTICAL,
// true,
// true,
// false);
//
// chart.setTextAntiAlias(false);
// chart.setBackgroundPaint(Color.WHITE);
//
// CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
// // 没有数据时显示
// this.configNoData(chart, "没有查询到数据 !");
//
// // x轴 // 分类轴网格是否可见
// categoryplot.setDomainGridlinesVisible(true);
// // y轴 //数据轴网格是否可见
// categoryplot.setRangeGridlinesVisible(true);
//
// categoryplot.setRangeGridlinePaint(Color.WHITE);// 虚线色彩
//
// categoryplot.setDomainGridlinePaint(Color.WHITE);// 虚线色彩
//
// categoryplot.setBackgroundPaint(Color.lightGray);
//
//
// // 配置字体
// this.configFont(chart);
//
// // x轴设置
// CategoryAxis domainAxis = categoryplot.getDomainAxis();
//
// // 设置距离图片左端距离
// domainAxis.setLowerMargin(0.0);
// // 设置距离图片右端距离
// domainAxis.setUpperMargin(0.0);
// domainAxis.setTickLabelPaint(Color.BLUE);
// domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 横轴上的label斜显示
//
// NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
// numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// numberaxis.setAutoRangeIncludesZero(true);
//
// // 获得renderer 注意这里是下嗍造型到lineandshaperenderer!!
// LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
// lineandshaperenderer.setBaseShapesVisible(true); // series 点(即数据点)可见
// lineandshaperenderer.setBaseLinesVisible(true); // series 点(即数据点)间有连线可见
//
// // 显示折点数据
// lineandshaperenderer.setBaseItemLabelGenerator(new
// StandardCategoryItemLabelGenerator());
// lineandshaperenderer.setBaseItemLabelsVisible(true);
//
// return chart;
// }
//
// /**
// * 堆栈柱状图
// */
// private JFreeChart createStackedBarChart(CategoryDataset dataset, ChartEntity entity) {
//
// JFreeChart chart = ChartFactory.createStackedBarChart3D(
// entity.getTitle(),
// entity.getXname(),
// entity.getYname(),
// dataset,
// PlotOrientation.VERTICAL,
// true,
// false,
// false);
//
// // 没有数据配置
// this.configNoData(chart, "没有查询到数据 !");
//
// // 配置字体
// this.configFont(chart);
//
// // 配置 Renderer
// this.configBarRenderer(chart);
//
// // 其他配置
// this.configOtherForBar(chart);
//
// return chart;
// }
//
// /**
// * 配置字体
// *
// * @param chart JFreeChart 对象
// */
// private void configFont(JFreeChart chart) {
// // 配置字体
// Font xfont = new Font("宋体", Font.PLAIN, 12);// X轴
// Font yfont = new Font("宋体", Font.PLAIN, 12);// Y轴
// Font kfont = new Font("宋体", Font.PLAIN, 12);// 底部
// Font titleFont = new Font("隶书", Font.BOLD, 25); // 图片标题
// CategoryPlot plot = chart.getCategoryPlot();// 图形的绘制结构对象
//
// // 图片标题
// chart.setTitle(new TextTitle(chart.getTitle().getText(), titleFont));
//
// // 底部
// chart.getLegend().setItemFont(kfont);
//
// // X 轴
// CategoryAxis domainAxis = plot.getDomainAxis();
// domainAxis.setLabelFont(xfont);// 轴标题
// domainAxis.setTickLabelFont(xfont);// 轴数值
// domainAxis.setTickLabelPaint(Color.BLUE); // 字体颜色
// domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // 横轴上的label斜显示
//
// // Y 轴
// ValueAxis rangeAxis = plot.getRangeAxis();
// rangeAxis.setLabelFont(yfont);
// rangeAxis.setLabelPaint(Color.BLUE); // 字体颜色
// rangeAxis.setTickLabelFont(yfont);
//
// }
//
// /**
// * 配置柱状图
// *
// * @param chart
// */
// private void configBarRenderer(JFreeChart chart) {
//
// CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
// // 自定义显示柱子上的总值
// ExtendedStackedBarRenderer extendedstackedbarrenderer = new ExtendedStackedBarRenderer();
// extendedstackedbarrenderer.setBaseItemLabelsVisible(true);
// extendedstackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
// extendedstackedbarrenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
// categoryplot.setRenderer(extendedstackedbarrenderer);
//
// BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
// barrenderer.setDrawBarOutline(false);
// barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
// barrenderer.setBaseItemLabelsVisible(true);
// barrenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
// barrenderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
//
// // 柱子显示数值
// // barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}",new DecimalFormat("0.0%")));
// // barrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
// barrenderer.setItemLabelFont(new Font("Arial Unicode MS", Font.PLAIN, 9));
// barrenderer.setItemLabelsVisible(true);
//
// // 如果数值没有显示空间,设置显示格式
// // ItemLabelPosition itemLabelPositionFallback=new ItemLabelPosition(
// // ItemLabelAnchor.OUTSIDE12,TextAnchor.BASELINE_LEFT,
// // TextAnchor.HALF_ASCENT_LEFT,0D);
// // barrenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback);
// // barrenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback);
//
// categoryplot.setRenderer(barrenderer);
// }
//
// /**
// * 配置没有数据时的显示信息
// *
// * @param chart
// */
// private void configNoData(JFreeChart chart, String message) {
// CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
// // 没有数据时的显示
// categoryplot.setNoDataMessage(message);
// categoryplot.setNoDataMessageFont(new Font("黑体", Font.BOLD, 25));
// }
//
// /**
// * 其他配置
// *
// * @param chart
// */
// private void configOtherForBar(JFreeChart chart) {
//
// chart.setTextAntiAlias(false); // 图例字体清晰
//
// chart.setBackgroundPaint(Color.WHITE); // 背景颜色
//
// CategoryPlot plot = chart.getCategoryPlot();// 图形的绘制结构对象
// NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
// numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// numberaxis.setAutoRangeIncludesZero(true);
// }
//
// /**
// * 创建图片的数据流
// *
// * @param chart
// * @param entity 图片配置对象
// * @return 图片数据流
// * @throws IOException
// */
// private byte[] createImage(JFreeChart chart, ChartEntity entity) throws IOException {
// return ChartUtilities.encodeAsPNG(chart.createBufferedImage(entity.getWidth(), entity.getHeight()));
// }
//
// /**
// * 创建图片文件到硬盘
// *
// * @param chart
// * @param entity
// * @throws IOException
// */
// private void createImageFile(JFreeChart chart, ChartEntity entity) throws IOException {
// FileOutputStream fos_jpg = null;
// try {
// isChartPathExist(tempImgPath);
// String chartName = tempImgPath + entity.getFileName();
// fos_jpg = new FileOutputStream(chartName);
// ChartUtilities.writeChartAsJPEG(fos_jpg, chart, entity.getWidth(), entity.getHeight());
// } catch (Exception e) {
// e.printStackTrace();
// } finally {
// try {
// fos_jpg.close();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
} }

121
hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/TimeUtils.java

@ -1,26 +1,111 @@
package com.hnac.hzims.operational.util; package com.hnac.hzims.operational.util;
import org.springblade.core.tool.utils.DateUtil;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
public class TimeUtils { public class TimeUtils {
private static int sheet1NowRow, sheet2NowRow; private static int sheet1NowRow, sheet2NowRow;
/** /**
* 相差时数 * 相差时数
* @author ty *
* @param endDate * @param endDate
* @param nowDate * @param nowDate
* @return * @return
*/ * @author ty
public static Long getDifferTime(Date nowDate,Date endDate ) { */
long nh = 1000 * 60 * 60L; public static Long getDifferTime(Date nowDate, Date endDate) {
// 获得两个时间的毫秒时间差异 long nh = 1000 * 60 * 60L;
long diff = endDate.getTime() - nowDate.getTime(); // 获得两个时间的毫秒时间差异
// 计算差多少小时 long diff = endDate.getTime() - nowDate.getTime();
long hour = diff/ nh; // 计算差多少小时
return hour; long hour = diff / nh;
} return hour;
}
public static String getYear(Integer year) {
// 创建一个Calendar对象
Calendar calendar = Calendar.getInstance();
// 设置年份
calendar.set(Calendar.YEAR, year);
// 设置月份为1(即一月)
calendar.set(Calendar.MONTH, Calendar.JANUARY);
// 设置日期为1
calendar.set(Calendar.DATE, 1);
// 设置时间为0点0分0秒
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) + " 00:00:00";
return start;
}
public static String getYearEnd(Integer year) {
// 创建一个Calendar对象
Calendar calendar = Calendar.getInstance();
// 设置年份
calendar.set(Calendar.YEAR, year);
// 设置月份为12(即十二月)
calendar.set(Calendar.MONTH, Calendar.DECEMBER);
// 设置日期为31
calendar.set(Calendar.DATE, 31);
String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) + " 00:00:00";
return end;
}
public static String getYearEndV2(Integer year) {
// 创建一个Calendar对象
Calendar calendar = Calendar.getInstance();
// 设置年份
calendar.set(Calendar.YEAR, year);
// 设置月份为12(即十二月)
calendar.set(Calendar.MONTH, Calendar.DECEMBER);
// 设置日期为31
calendar.set(Calendar.DATE, 31);
String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) + " 23:59:59";
return end;
}
public static String getMonthStart(Integer year, Integer mon) {
// 创建一个Calendar对象
Calendar calendar = Calendar.getInstance();
// 设置年份
calendar.set(Calendar.YEAR, year);
// 设置月份
calendar.set(Calendar.MONTH,mon);
// 设置日期为1
calendar.set(Calendar.DATE, 1);
String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) + " 00:00:00";
return start;
}
public static String getMonthEnd(Integer year, Integer mon) {
// 创建一个Calendar对象
Calendar calendar = Calendar.getInstance();
// 设置年份
calendar.set(Calendar.YEAR, Integer.valueOf(year));
// 设置月份为1(即一月)
calendar.set(Calendar.MONTH, mon+1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
// 将日期对象减去一天,即为当月的最后一天
calendar.add(Calendar.DAY_OF_MONTH, -1);
String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) + " 00:00:00";
return end;
}
public static String getMonthEndV2(Integer year, Integer mon) {
// 创建一个Calendar对象
Calendar calendar = Calendar.getInstance();
// 设置年份
calendar.set(Calendar.YEAR, Integer.valueOf(year));
// 设置月份为1(即一月)
calendar.set(Calendar.MONTH, mon+1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
// 将日期对象减去一天,即为当月的最后一天
calendar.add(Calendar.DAY_OF_MONTH, -1);
String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATE) + " 23:59:59";
return end;
}
} }

Loading…
Cancel
Save