|
@@ -1,17 +1,32 @@
|
|
package com.huimv.video.service.impl;
|
|
package com.huimv.video.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
import com.huimv.video.domain.*;
|
|
import com.huimv.video.domain.*;
|
|
import com.huimv.video.repo.*;
|
|
import com.huimv.video.repo.*;
|
|
import com.huimv.video.result.Result;
|
|
import com.huimv.video.result.Result;
|
|
import com.huimv.video.service.AllDataService;
|
|
import com.huimv.video.service.AllDataService;
|
|
|
|
+import com.spire.xls.*;
|
|
|
|
+import com.spire.xls.charts.ChartSerie;
|
|
|
|
+import com.spire.xls.charts.ChartSeries;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
|
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
|
+import org.springframework.core.io.support.ResourcePatternResolver;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.awt.*;
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Project : huimv.shiwan
|
|
* @Project : huimv.shiwan
|
|
@@ -22,87 +37,284 @@ import java.util.Map;
|
|
**/
|
|
**/
|
|
@Service
|
|
@Service
|
|
public class AllDataServiceImpl implements AllDataService {
|
|
public class AllDataServiceImpl implements AllDataService {
|
|
- @Autowired
|
|
|
|
- private DaZsdaEntityRepository zsdaEntityRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private DaLqdaEntityRepository lqdaEntityRepo;
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private SjHkAqRepository aqRepository;
|
|
|
|
- @Autowired
|
|
|
|
- private SjHkSdRepository sdRepository;
|
|
|
|
- @Autowired
|
|
|
|
- private SjHkWdRepository wdRepository;
|
|
|
|
|
|
+ private SjDlRepo dlRepo;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
- private SjHkSlRepository slRepository;
|
|
|
|
|
|
+ private SjSlRepo slRepo;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
- private SjHkDlRepository dlRepository;
|
|
|
|
|
|
+ private SjPhRepo phRepo;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
- private SjHkPhRepository phRepository;
|
|
|
|
|
|
+ private SjSyRepo syRepo;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @DS("slave")
|
|
|
|
- public Result getZsda() {
|
|
|
|
- Integer mcid = 39;
|
|
|
|
- //--读取所有猪舍
|
|
|
|
- List<DaZsdaEntity> zsdsList = zsdaEntityRepo.getAllZs(mcid);
|
|
|
|
-
|
|
|
|
- List zsidList = new ArrayList();
|
|
|
|
- for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
|
- zsidList.add(zsdaEntity.getID());
|
|
|
|
|
|
+ @DS("thired")
|
|
|
|
+ public Result findByZSID(Integer zsid,String lqid) {
|
|
|
|
+ String JQID ;
|
|
|
|
+
|
|
|
|
+ switch (zsid){
|
|
|
|
+ case 367:
|
|
|
|
+ JQID = "00000481";
|
|
|
|
+ break;
|
|
|
|
+ case 378:
|
|
|
|
+ JQID = "00000488";
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ JQID = "00000489";
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
- //--读取所有栏期
|
|
|
|
- List<DaLqdaEntity> lqdaEntityList = lqdaEntityRepo.getLqid(zsidList);
|
|
|
|
|
|
+ Date date = DateUtil.date();
|
|
|
|
+ DateTime dateTime = DateUtil.beginOfDay(date);
|
|
|
|
+ Map endMap = new HashMap();
|
|
|
|
|
|
|
|
|
|
- List<Map> zsxx = new ArrayList();
|
|
|
|
- Map map = new HashMap();
|
|
|
|
- for (DaZsdaEntity zsdaEntity : zsdsList) {
|
|
|
|
- int zsid = zsdaEntity.getID();
|
|
|
|
|
|
|
|
|
|
+ Map dlMap = initMap();
|
|
|
|
+ List<SjDl> allByJQIDAndSCSJBetween = dlRepo.findAllByJQIDAndSCSJBetween(JQID, dateTime, date);
|
|
|
|
+ for (SjDl o : allByJQIDAndSCSJBetween) {
|
|
|
|
+ Integer x = Integer.parseInt((o.getSCSJ()+"").substring(11,13));
|
|
|
|
+ String str ;
|
|
|
|
+ if (x <10){
|
|
|
|
+ str = "0"+x+":00";
|
|
|
|
+ }else {
|
|
|
|
+ str = x+":00";
|
|
|
|
+ }
|
|
|
|
+ dlMap.put(str,o.getDQDL());
|
|
|
|
+ }
|
|
|
|
+ endMap.put("dl",dlMap);
|
|
|
|
|
|
- map.put("zsid", zsid);
|
|
|
|
- map.put("zsmc", zsdaEntity.getZSMC());
|
|
|
|
- List<Integer> lqidList = new ArrayList();
|
|
|
|
- for (DaLqdaEntity lqdaEntity : lqdaEntityList) {
|
|
|
|
- if (lqdaEntity.getZSID() == zsid) {
|
|
|
|
- Integer lqid = lqdaEntity.getID();
|
|
|
|
- map.put("lqid", lqid);
|
|
|
|
- lqidList.add(lqid);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ Map slMap = initMap();
|
|
|
|
+ List<SjSl> allByJQIDAndSCSJBetween1 = slRepo.findAllByJQIDAndSCSJBetween(JQID, dateTime, date);
|
|
|
|
+ for (SjSl o : allByJQIDAndSCSJBetween1) {
|
|
|
|
+ Integer x = Integer.parseInt((o.getSCSJ()+"").substring(11,13));
|
|
|
|
+ String str ;
|
|
|
|
+ if (x <10){
|
|
|
|
+ str = "0"+x+":00";
|
|
|
|
+ }else {
|
|
|
|
+ str = x+":00";
|
|
}
|
|
}
|
|
|
|
+ slMap.put(str,o.getDQSL());
|
|
|
|
+ }
|
|
|
|
+ endMap.put("sl",slMap);
|
|
|
|
|
|
|
|
+ Map phMap = initMap();
|
|
|
|
+ List<SjPh> allByJQIDAndSCSJBetween2 = phRepo.findAllByJQIDAndSCSJBetween(JQID, dateTime, date);
|
|
|
|
+ for (SjPh o : allByJQIDAndSCSJBetween2) {
|
|
|
|
+ Integer x = Integer.parseInt((o.getSCSJ()+"").substring(11,13));
|
|
|
|
+ String str ;
|
|
|
|
+ if (x <10){
|
|
|
|
+ str = "0"+x+":00";
|
|
|
|
+ }else {
|
|
|
|
+ str = x+":00";
|
|
|
|
+ }
|
|
|
|
+ phMap.put(str,o.getDQPH());
|
|
|
|
+ }
|
|
|
|
+ endMap.put("ph",phMap);
|
|
|
|
|
|
- for (Integer lqid : lqidList) {
|
|
|
|
- List<SjHkAq> byLqidOrderById = aqRepository.findByLqidOrderById(lqid);
|
|
|
|
- if ( byLqidOrderById.size()> 0){
|
|
|
|
- map.put("aq",byLqidOrderById.get(0).getDqaq()) ;
|
|
|
|
- }else{
|
|
|
|
- map.put("aq",null) ;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- List<SjHkWd> byLqidOrderById1 = wdRepository.findByLqidOrderById(lqid);
|
|
|
|
- if ( byLqidOrderById1.size()> 0){
|
|
|
|
- map.put("wd",byLqidOrderById1.get(0).getDqwd()) ;
|
|
|
|
- }else{
|
|
|
|
- map.put("wd",null) ;
|
|
|
|
- }
|
|
|
|
|
|
+ Map syMap = initMap();
|
|
|
|
+ List<SjSy> allByJQIDAndSCSJBetween3 = syRepo.findAllByJQIDAndSCSJBetween(JQID, dateTime, date);
|
|
|
|
+ for (SjSy o : allByJQIDAndSCSJBetween3) {
|
|
|
|
+ Integer x = Integer.parseInt((o.getSCSJ()+"").substring(11,13));
|
|
|
|
+ String str ;
|
|
|
|
+ if (x <10){
|
|
|
|
+ str = "0"+x+":00";
|
|
|
|
+ }else {
|
|
|
|
+ str = x+":00";
|
|
|
|
+ }
|
|
|
|
+ syMap.put(str,o.getDQSY());
|
|
|
|
+ }
|
|
|
|
+ endMap.put("sy",syMap);
|
|
|
|
+ endMap.put("zsid",zsid);
|
|
|
|
+ endMap.put("lqid",lqid);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return new Result(10000,"成功",endMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @DS("thired")
|
|
|
|
+ public Result findAll(String startTime, String endTime, HttpServletResponse response) {
|
|
|
|
+ //367 一栋全控 00000481
|
|
|
|
+ //378 二栋 00000488
|
|
|
|
+ //379 三栋 00000489
|
|
|
|
+ Date startDate = DateUtil.parse(startTime);
|
|
|
|
+ Date endDate = DateUtil.parse(endTime);
|
|
|
|
+
|
|
|
|
+ Double sl1result = 0.0;
|
|
|
|
+ List<SjSl> slList1 = slRepo.findAllByJQIDAndSCSJBetween("00000481", startDate, endDate);
|
|
|
|
+ if (slList1 != null && slList1.size()>0){
|
|
|
|
+ sl1result = slList1.get(slList1.size() - 1).getDQSL().subtract(slList1.get(0).getDQSL()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Double dl1result = 0.0;
|
|
|
|
+ List<SjDl> dlList1 = dlRepo.findAllByJQIDAndSCSJBetween("00000481", startDate, endDate);
|
|
|
|
+ if (dlList1 != null &&dlList1.size()>0){
|
|
|
|
+ dl1result = dlList1.get(dlList1.size() - 1).getDQDL().subtract(dlList1.get(0).getDQDL()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Double sl2result = 0.0;
|
|
|
|
+ List<SjSl> slList2 = slRepo.findAllByJQIDAndSCSJBetween("00000488", startDate, endDate);
|
|
|
|
+ if (slList2 != null &&slList2.size()>0){
|
|
|
|
+ sl2result = slList2.get(slList2.size() - 1).getDQSL().subtract(slList2.get(0).getDQSL()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Double dl2result = 0.0;
|
|
|
|
+ List<SjDl> dlList2 = dlRepo.findAllByJQIDAndSCSJBetween("00000488", startDate, endDate);
|
|
|
|
+ if (dlList2 != null &&dlList2.size() >0 ){
|
|
|
|
+ dl2result = dlList2.get(dlList2.size() - 1).getDQDL().subtract(dlList2.get(0).getDQDL()).doubleValue();
|
|
|
|
+ }
|
|
|
|
|
|
- List<SjHkSd> byLqidOrderById2 = sdRepository.findByLqidOrderById(lqid);
|
|
|
|
- if ( byLqidOrderById2.size()> 0){
|
|
|
|
- map.put("sd",byLqidOrderById2.get(0).getDqsd()) ;
|
|
|
|
- }else{
|
|
|
|
- map.put("sd",null) ;
|
|
|
|
|
|
+
|
|
|
|
+ Double sl3result = 0.0;
|
|
|
|
+ List<SjSl> slList3 = slRepo.findAllByJQIDAndSCSJBetween("00000489", startDate, endDate);
|
|
|
|
+ if (slList3 != null &&slList3.size()>0){
|
|
|
|
+ sl3result= slList3.get(slList3.size() - 1).getDQSL().subtract(slList3.get(0).getDQSL()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Double dl3result = 0.0;
|
|
|
|
+ List<SjDl> dlList3 = dlRepo.findAllByJQIDAndSCSJBetween("00000489", startDate, endDate);
|
|
|
|
+ if (dlList3 != null &&dlList3.size()>0){
|
|
|
|
+ dl3result = dlList3.get(dlList3.size() - 1).getDQDL().subtract(dlList3.get(0).getDQDL()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Workbook workbook = new Workbook();
|
|
|
|
+
|
|
|
|
+ //获取第一个工作表
|
|
|
|
+ Worksheet sheet = workbook.getWorksheets().get(0);
|
|
|
|
+
|
|
|
|
+ //将图表数据写入工作表
|
|
|
|
+ sheet.getCellRange("A1").setValue("栋舍");
|
|
|
|
+ sheet.getCellRange("A2").setValue("一栋全控");
|
|
|
|
+ sheet.getCellRange("A3").setValue("二栋全控");
|
|
|
|
+ sheet.getCellRange("A4").setValue("三栋全控");
|
|
|
|
+ sheet.getCellRange("B1").setValue("用水量");
|
|
|
|
+ sheet.getCellRange("B2").setNumberValue(sl1result);
|
|
|
|
+ sheet.getCellRange("B3").setNumberValue(sl2result);
|
|
|
|
+ sheet.getCellRange("B4").setNumberValue(sl3result);
|
|
|
|
+
|
|
|
|
+ sheet.getCellRange("C1").setValue("用电量");
|
|
|
|
+ sheet.getCellRange("C2").setNumberValue(dl1result);
|
|
|
|
+ sheet.getCellRange("C3").setNumberValue(dl2result);
|
|
|
|
+ sheet.getCellRange("C4").setNumberValue(dl3result);
|
|
|
|
+
|
|
|
|
+ //设置单元格样式
|
|
|
|
+ sheet.getCellRange("A1:C1").setRowHeight(15);
|
|
|
|
+ sheet.getCellRange("A1:C1").getCellStyle().setColor(Color.darkGray);
|
|
|
|
+ sheet.getCellRange("A1:C1").getCellStyle().getExcelFont().setColor(Color.white);
|
|
|
|
+ sheet.getCellRange("A1:C1").getCellStyle().setVerticalAlignment(VerticalAlignType.Center);
|
|
|
|
+ sheet.getCellRange("A1:C1").getCellStyle().setHorizontalAlignment(HorizontalAlignType.Center);
|
|
|
|
+ sheet.autoFitColumn(1);
|
|
|
|
+
|
|
|
|
+ //添加柱形图
|
|
|
|
+ Chart chart =sheet.getCharts().add(ExcelChartType.ColumnClustered);
|
|
|
|
+
|
|
|
|
+ //设置图表数据区域
|
|
|
|
+ chart.setDataRange(sheet.getCellRange("A1:C5"));
|
|
|
|
+ chart.setSeriesDataFromRange(false);
|
|
|
|
+
|
|
|
|
+//设置图表位置
|
|
|
|
+ chart.setLeftColumn(5);
|
|
|
|
+ chart.setTopRow(1);
|
|
|
|
+ chart.setRightColumn(14);
|
|
|
|
+ chart.setBottomRow(21);
|
|
|
|
+
|
|
|
|
+//设置图表标题
|
|
|
|
+
|
|
|
|
+ chart.setChartTitle(startTime.substring(5,10)+ " 到 " + endTime.substring(0,10) + " 水电统计图");
|
|
|
|
+ chart.getChartTitleArea().isBold(true);
|
|
|
|
+ chart.getChartTitleArea().setSize(12);
|
|
|
|
+
|
|
|
|
+//设置x,y轴的名称
|
|
|
|
+ chart.getPrimaryCategoryAxis().setTitle("栋舍");
|
|
|
|
+ chart.getPrimaryCategoryAxis().getFont().isBold(true);
|
|
|
|
+ chart.getPrimaryCategoryAxis().getTitleArea().isBold(true);
|
|
|
|
+ chart.getPrimaryValueAxis().setTitle("数值");
|
|
|
|
+ chart.getPrimaryValueAxis().hasMajorGridLines(false);
|
|
|
|
+ chart.getPrimaryValueAxis().getTitleArea().isBold(true);
|
|
|
|
+ chart.getPrimaryValueAxis().getTitleArea().setTextRotationAngle(90);
|
|
|
|
+
|
|
|
|
+//设置系列颜色、重叠、宽度和数字标签
|
|
|
|
+ ChartSeries series = chart.getSeries();
|
|
|
|
+ for (int i = 0 ; i < series.size() ; i++) {
|
|
|
|
+ ChartSerie cs = series.get(i);
|
|
|
|
+ cs.getFormat().getOptions().isVaryColor(true);
|
|
|
|
+ cs.getFormat().getOptions().setOverlap(-50);
|
|
|
|
+ cs.getFormat().getOptions().setGapWidth(350);
|
|
|
|
+ cs.getDataPoints().getDefaultDataPoint().getDataLabels().hasValue(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //设置图例位置
|
|
|
|
+ chart.getLegend().setPosition(LegendPositionType.Top);
|
|
|
|
+
|
|
|
|
+ //保存文档
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String fileName = System.currentTimeMillis()+".xls";
|
|
|
|
+ response.setContentType("application/vnd.ms-excel"); //"application/vnd.ms-excel;charset=utf-8" application/force-download
|
|
|
|
+ response.reset();
|
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
|
+ ServletOutputStream outputStream = null;
|
|
|
|
+ // try {
|
|
|
|
+ try {
|
|
|
|
+ response.addHeader("Content-Disposition","attachment;fileName=" + new String(fileName.getBytes("UTF-8"),"iso-8859-1"));
|
|
|
|
+
|
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
|
+
|
|
|
|
+ workbook.saveToStream(outputStream);
|
|
|
|
+
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally {
|
|
|
|
+ if (outputStream != null){
|
|
|
|
+ try {
|
|
|
|
+ outputStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- zsxx.add(map);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//
|
|
|
|
+
|
|
|
|
|
|
- return new Result(10000,"成功",zsxx);
|
|
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Map initMap (){
|
|
|
|
+ Map map = new TreeMap<String ,Object>(new Comparator<String>() {
|
|
|
|
+ @Override
|
|
|
|
+ public int compare(String s, String t1) {
|
|
|
|
+ return s.compareTo(t1);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ for (int i = 0; i< 24 ;i++){
|
|
|
|
+ String x ;
|
|
|
|
+ if (i <10){
|
|
|
|
+ x = "0"+i;
|
|
|
|
+ }else {
|
|
|
|
+ x =i+"";
|
|
|
|
+ }
|
|
|
|
+ map.put(x+":00",0);
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
}
|
|
}
|
|
}
|
|
}
|