whyclxw
2024-12-23 93be23aaba651076443b87e662b0232dd1a03b75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
package com.whyc.service;
 
import com.whyc.bts.*;
import com.whyc.fbo.FboData;
import com.whyc.fbo.FboDataHeadStart;
import com.whyc.fbo.FboDataHeadStop;
import com.whyc.fbo.FboDataInf;
import com.whyc.mcp.*;
import com.whyc.res.RESData;
import com.whyc.res.RESDataInfo;
import com.whyc.util.ServletUtils;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class ExcelExportService {
    @Autowired
    FboDataInfService fboService;
 
    @Autowired
    private RESDataInfoService resService;
 
    @Autowired
    private TestDataInfoService testDataInfoService;
 
    @Autowired
    private BtsDisChargeService disDataService;
 
    @Autowired
    private BtsChargeDataService chargeDataService;
 
    //导出fbx
    public void exportFbx(HttpServletRequest req, HttpServletResponse resp){
 
        String curr_echart = req.getParameter("curr_echart");        //电池电流折线图
        String groupVol_echart = req.getParameter("groupVol_echart");        //组端电压折线图
        String cap_echart = req.getParameter("cap_echart");            //测试容量折线图
        //String actualCap_echart = req.getParameter("actualCap_echart");            //实际容量折线图
        String vol_echart = req.getParameter("vol_echart");            //单体电压折线图
        String tempEnvi_echart = req.getParameter("tempEnvi_echart");//环境温度折线图
        String humiEnvi_echart = req.getParameter("humiEnvi_echart");//环境湿度折线图
 
 
        String filePath = req.getParameter("filePath");
        FboDataInf fboDataInf=fboService.readFboFile(filePath);
        //从文件中获取数据
        List<FboData> list = fboDataInf.fboData;
        //图片base64后的数据
        List<byte[]> bytes = new ArrayList<>();
        try {
            if (ServletUtils.isNotNull(curr_echart)) {
                String[] url = curr_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(groupVol_echart)) {
                String[] url = groupVol_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(cap_echart)) {
                String[] url = cap_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(vol_echart)) {
                String[] url = vol_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(tempEnvi_echart)) {
                String[] url = tempEnvi_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(humiEnvi_echart)) {
                String[] url = humiEnvi_echart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //当前日期
        String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String excelName = "FBX-"+nowFormat;
 
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet("数据总表");
 
        XSSFDrawing patriarch = sheet.createDrawingPatriarch();
        int rowNumSheet = 0;
        FboDataHeadStart start = fboDataInf.fboDataStart;
        FboDataHeadStop stop = fboDataInf.fboDataStop;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("电池组名称:"+start.battNameStr);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("电池品牌:"+start.battBrandStr);
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
 
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("安装日期:"+start.batt_date_str);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("单体数量:"+start.batt_mon_num);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("标称容量:"+start.batt_std_cap+"AH");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("测试开始时间:"+formartDate(start.testStartTime,"yyyy-MM-dd HH:mm:ss"));
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("测试时长:"+stop.TestTimeLong.hms());
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("单体电压:"+start.batt_mon_vol+"V");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("正极绝缘电阻:"+list.get(list.size()-1).PosInsRes+"kΩ");
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("负极绝缘电阻:"+list.get(list.size()-1).NegInsRes+"kΩ");
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("标称内阻:"+start.batt_std_res+"mΩ");
        if(start.DataType==0xFD){
            rowNumSheet++;
            sheet.createRow(rowNumSheet);
            sheet.getRow(rowNumSheet).createCell(0).setCellValue("预估实际容量:"+list.get(list.size()-1).actualCap+"AH");
        }
        rowNumSheet+=4;
        //插入图片
        int picNum = 0;
        String[] picName = getPicName(start.DataType);
        if (picName.length==bytes.size()){
            for(int i=0;i<picName.length;i++){
                sheet.createRow(rowNumSheet-1);
                sheet.getRow(rowNumSheet-1).createCell(0).setCellValue(picName[i]);
                //rowNum++;
                XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNumSheet, (short) 10, rowNumSheet+27);
                anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
                patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1);
                picNum ++;
                rowNumSheet+=27;
            }
        }
 
        XSSFSheet sheet1 = wb.createSheet("数据");
        //抬头
        int rowNum = 0;
        sheet1.createRow(rowNum).createCell(0).setCellValue("测试数据");
        rowNum++;
        //属性栏
        String[] rowName = getRowName(start.DataType);
        XSSFRow row = sheet1.createRow(rowNum);
        for (int i=0;i<rowName.length;i++){
            row.createCell(i).setCellValue(rowName[i]);
        }
        for(int i=0;i<list.get(0).SingleVol.length;i++){
            row.createCell(rowName.length+i).setCellValue("#"+Integer.valueOf(i+1));
        }
        rowNum++;
        //数据栏
        for (int i = 0; i < list.size(); i++) {
            sheet1.createRow(rowNum);  //创建行
            FboData fbo=list.get(i);
            sheet1.getRow(rowNum).createCell(0).setCellValue(fbo.m_TestTime.hms());
            sheet1.getRow(rowNum).createCell(1).setCellValue(fbo.SumVoltage);
            sheet1.getRow(rowNum).createCell(2).setCellValue(fbo.SumCurrent);
            sheet1.getRow(rowNum).createCell(3).setCellValue(fbo.Temp_Envi);
            sheet1.getRow(rowNum).createCell(4).setCellValue(fbo.Humi_Envi);
            if (start.DataType!=0xFB){
                sheet1.getRow(rowNum).createCell(5).setCellValue(fbo.testCap);
            }
            for (int k = 0;k<list.get(0).SingleVol.length;k++){
                sheet1.getRow(rowNum).createCell(rowName.length+k).setCellValue(fbo.SingleVol[k]);
            }
            rowNum++;
        }
 
        rowNum++;
 
        try {
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")
                    + ".xlsx");
            OutputStream out = resp.getOutputStream();
            wb.write(out);
            out.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
 
    public String[] getRowName(int dateType){
        if (dateType==0xFB){
            String[] rowName = {"测试时间","总电压(V)","总电流(A)","环境温度","环境湿度"};
            return rowName;
        }else{
            String[] rowName1 = {"测试时间","总电压(V)","总电流(A)","环境温度","环境湿度","测试容量(AH)"};
            return rowName1;
        }
    }
 
    public String[] getPicName(int dateType){
        if (dateType==0xFB){
            String[] picName1 = new String[]{
                    "电池电流折线图","组端电压折线图","单体电压折线图","环境温度折线图","环境湿度折线图"
            };
            return picName1;
        }else{
            String[] picName = new String[]{
                    "电池电流折线图","组端电压折线图","测试容量折线图","单体电压折线图","环境温度折线图","环境湿度折线图"
            };
            return picName;
        }
    }
 
 
    //导出bres
    public void exportBres(HttpServletRequest req, HttpServletResponse resp){
        String volEchart = req.getParameter("vol_echart");            //单体电压折线图
        String resEchart = req.getParameter("res_echart");            //单体内阻折线图
        String tmpEchart = req.getParameter("tmp_echart");            //单体温度折线图
 
        String filePath = req.getParameter("filePath");
        //图片base64后的数据
        List<byte[]> bytes = new ArrayList<>();
        try {
            if (ServletUtils.isNotNull(volEchart)) {
                String[] url = volEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(resEchart)) {
                String[] url = resEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(tmpEchart)) {
                String[] url = tmpEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //当前日期
        String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String excelName = "BRES-"+nowFormat;
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet("数据总表");
        //图片元素
        XSSFDrawing patriarch = sheet.createDrawingPatriarch();
        int rowNumSheet = 1;
        //插入图片
        int picNum = 0;
        String[] picName =new String[]{"单体电压折线图","单体内阻折线图","单体温度折线图"};
        if (picName.length==bytes.size()){
            for(int i=0;i<picName.length;i++){
                sheet.createRow(rowNumSheet-1);
                sheet.getRow(rowNumSheet-1).createCell(0).setCellValue(picName[i]);
                //rowNum++;
                XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNumSheet, (short) 10, rowNumSheet+27);
                anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
                patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1);
                picNum ++;
                rowNumSheet+=30;
            }
        }
        //数据
        RESDataInfo resDataInfo =resService.readFileData(filePath);
        //从文件中获取数据
        List<RESData> list = resDataInfo.resDatas;
        int battNum=list.get(0).getBattSum();//单体个数
        //创建不同sheet
        createBresSheet(wb,battNum,list,1);//创建内阻数据
        createBresSheet(wb,battNum,list,2);//创建温度数据
        createBresSheet(wb,battNum,list,3);//创建电压数据
        try {
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")
                    + ".xlsx");
            OutputStream out = resp.getOutputStream();
            wb.write(out);
            out.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //bres中内阻数据/温度数据/单体电压数据放在不同的sheet中
    public void createBresSheet(XSSFWorkbook wb,int battNum,List<RESData> list,int type){
        String sheetName="";
        String testName="";
        switch (type){
            case 1:sheetName= "内阻数据";testName="测试数据(内阻)";break;
            case 2:sheetName= "温度数据";testName="测试数据(温度)";break;
            case 3:sheetName= "电压数据";testName="测试数据(电压)";break;
        }
        XSSFSheet sheet1 = wb.createSheet(sheetName);
        //抬头
        int rowNum = 0;
        sheet1.createRow(rowNum).createCell(0).setCellValue(testName);
        rowNum++;
        //属性栏
        XSSFRow row = sheet1.createRow(rowNum);
        row.createCell(0).setCellValue("测试时间");
 
        for(int i=0;i<battNum;i++){
            row.createCell(1+i).setCellValue("#"+Integer.valueOf(i+1));
        }
        rowNum++;
        float[] datas=new float[]{};
        //数据栏
        for (int i = 0; i < list.size(); i++) {
            sheet1.createRow(rowNum);  //创建行
            RESData resData= list.get(i);
            switch (type){
                case 1:datas= resData.getMonomerRes();break;
                case 2:datas= resData.getMonomerTemp();break;
                case 3:datas= resData.getMonomerVol();break;
            }
            sheet1.getRow(rowNum).createCell(0).setCellValue(formartDate(resData.getData_Time(),"yyyy-MM-dd HH:mm:ss"));
            for (int k = 0;k<battNum;k++){
                sheet1.getRow(rowNum).createCell(k+1).setCellValue(datas[k]);
            }
            rowNum++;
        }
        rowNum++;
    }
 
    /**
     * 将日期格式转换成指定的字符串格式
     * @param date    日期
     * @param str    字符串的格式
     * @return
     */
    public static String formartDate(Date date, String str){
        return new SimpleDateFormat(str).format(date);
    }
 
 
 
    //导出mch,mcp
    public void exportMcph(HttpServletRequest req, HttpServletResponse resp){
        String volEchart = req.getParameter("vol_echart");            //单体电压折线图
        String currEchart = req.getParameter("curr_echart");        //电池电流折线图
        String groupVolEchart = req.getParameter("groupVol_echart");        //组端电压折线图
        String capEchart = req.getParameter("cap_echart");            //测试容量折线图
        String filePath = req.getParameter("filePath");
        //数据
        TestDataInfo testDataInfoMcp=testDataInfoService.readFileData(filePath);
        MonitorDataInfo info = testDataInfoMcp.monitorDataInfo;//组端数据
 
        //图片base64后的数据
        List<byte[]> bytes = new ArrayList<>();
        try {
            if (ServletUtils.isNotNull(volEchart)) {
                String[] url = volEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(currEchart)) {
                String[] url = currEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(groupVolEchart)) {
                String[] url = groupVolEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(capEchart)) {
                String[] url = capEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //当前日期
        String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String excelName ="";
        int fileType=testDataInfoMcp.getFile_type();
        if(fileType==0xFA){
            excelName="MCP-"+nowFormat;
        }else{
            excelName="MCH-"+nowFormat;
        }
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet("数据总表");
        //图片元素
        XSSFDrawing patriarch = sheet.createDrawingPatriarch();
        BattParam battParam=info.battparam;//电池参数
        SYSMonitorParam sysParam=info.monitorparam;//组端参数
        SYSMonitorState sysState=info.monitorstate;//组端状态
        int rowNumSheet = 0;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("电池参数:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("标称容量(1AH):"+battParam.STD_CAP);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("标称内阻(0.001mΩ):"+battParam.STD_RES);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("单体标称电压(0.1V):"+battParam.monomerVol);
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组数:"+battParam.battGroupCount);
 
        int battNum=battParam.eachGroupBattCount;//单体个数
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("每组单体个数:"+battNum);
        rowNumSheet++;
 
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端参数:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("放电电流:"+sysParam.disCurr);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("放电容量:"+sysParam.disCap);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("放电时长:"+sysParam.disTime);
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端下限:"+sysParam.groupVol_LOW);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("单体下限:"+sysParam.monomerVol_LOW);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("下限个数:"+sysParam.monomerLowCount);
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("充电电流:"+sysParam.chrCurr);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("充电容量:"+sysParam.chrCap);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("充电时长:"+sysParam.chrTime);
        rowNumSheet++;
 
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端状态:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("启动放电的日期时间:"+formartDate(sysState.startDT.time,"yyyy-MM-dd HH:mm:ss"));
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("终止放电的日期时间:"+formartDate(sysState.stopDT.time,"yyyy-MM-dd HH:mm:ss"));
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("已测试时间(HMS):"+sysState.test_Time.testTime);
 
        rowNumSheet+=4;
        //插入图片
        int picNum = 0;
        String[] picName =new String[]{"单体电压折线图","电池电流折线图","组端电压折线图","测试容量折线图"};
        if (picName.length==bytes.size()){
            for(int i=0;i<picName.length;i++){
                sheet.createRow(rowNumSheet-1);
                sheet.getRow(rowNumSheet-1).createCell(0).setCellValue(picName[i]);
                //rowNum++;
                XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNumSheet, (short) 10, rowNumSheet+27);
                anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
                patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1);
                picNum ++;
                rowNumSheet+=30;
            }
        }
 
        //从文件中获取数据
        List<FBSData> list=testDataInfoMcp.fbsDatas;//充放电数据
        String sheetName="放电数据";
        String testName="测试数据";
        XSSFSheet sheet1 = wb.createSheet(sheetName);
        //抬头
        int rowNum = 0;
        sheet1.createRow(rowNum).createCell(0).setCellValue(testName);
        rowNum++;
 
        XSSFRow row = sheet1.createRow(rowNum);
        //属性栏
        String[] rowName =new String[]{"测试时间","在线电压","组端电压","电池电流","电池容量","电池温度"};
        for (int i=0;i<rowName.length;i++){
            row.createCell(i).setCellValue(rowName[i]);
        }
        for(int i=0;i<battNum;i++){
            row.createCell(6+i).setCellValue("#"+Integer.valueOf(i+1));
        }
        rowNum++;
        //数据栏
        for (int i = 0; i < list.size(); i++) {
            sheet1.createRow(rowNum);  //创建行
            FBSData fbsData= list.get(i);
            sheet1.getRow(rowNum).createCell(0).setCellValue(fbsData.testTime.testTime);
            sheet1.getRow(rowNum).createCell(1).setCellValue(fbsData.vcData.onlinevol[0]);
            sheet1.getRow(rowNum).createCell(2).setCellValue(fbsData.vcData.groupvol[0]);
            sheet1.getRow(rowNum).createCell(3).setCellValue(fbsData.vcData.battcurr[0]);
            sheet1.getRow(rowNum).createCell(4).setCellValue(fbsData.vcData.battcap[0]);
            sheet1.getRow(rowNum).createCell(5).setCellValue(fbsData.vcData.batttemp[0]);
            float[]  datas=fbsData.mvol.vol;
            for (int k = 0;k<battNum;k++){
                sheet1.getRow(rowNum).createCell(k+6).setCellValue(datas[k]);
            }
            rowNum++;
        }
        rowNum++;
 
        try {
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")
                    + ".xlsx");
            OutputStream out = resp.getOutputStream();
            wb.write(out);
            out.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //导出bts的放电数据bcp
    public void exportBcp(HttpServletRequest req, HttpServletResponse resp) {
        String volEchart = req.getParameter("vol_echart");            //单体电压折线图
        String currEchart = req.getParameter("curr_echart");        //电池电流折线图
        String groupVolEchart = req.getParameter("groupVol_echart");        //组端电压折线图
        String capEchart = req.getParameter("cap_echart");            //测试容量
        String filePath = req.getParameter("filePath");
        //图片base64后的数据
        List<byte[]> bytes = new ArrayList<>();
        try {
            if (ServletUtils.isNotNull(volEchart)) {
                String[] url = volEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(currEchart)) {
                String[] url = currEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(groupVolEchart)) {
                String[] url = groupVolEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(capEchart)) {
                String[] url = capEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //当前日期
        String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String excelName="BCP-"+nowFormat;
        //数据
        BTS_DisChargeData disData=disDataService.getDisData(filePath);
        BTS_BattParam btsbattParam = disData.battParam;//电池参数
        BTS_DischargeParam btsdisParam=disData.dischargeParam;//放电参数
        BTS_CapState btscapState=disData.capState;//放电时长
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet("数据总表");
        //图片元素
        XSSFDrawing patriarch = sheet.createDrawingPatriarch();
        int rowNumSheet = 0;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("电池参数:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("标称容量(1AH):"+btsbattParam.STD_CAP);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("标称内阻(0.001mΩ):"+btsbattParam.STD_RES);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("单体标称电压(0.1V):"+btsbattParam.MonomerVol);
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组数:"+btsbattParam.BattGroupCount);
 
        int battNum=btsbattParam.EachGroupBattCount;//单体个数
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("每组单体个数:"+battNum);
        rowNumSheet++;
 
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端参数:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("放电电流:"+btsdisParam.DisCurr);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("放电容量:"+btsdisParam.DisCap);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("放电时长:"+btsdisParam.DisTime);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("升压上限:"+btsdisParam.DCVolHighLimit);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("温度上限:"+btsdisParam.MonomerTmp_High);
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端下限:"+btsdisParam.GroupVol_LOW);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("单体下限:"+btsdisParam.MonomerVol_LOW);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("下限个数:"+btsdisParam.MonomerLowCount);
        rowNumSheet++;
 
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端状态:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("启动放电的日期时间:"+formartDate(btscapState.StartDT.getDateTime(),"yyyy-MM-dd HH:mm:ss"));
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("终止放电的日期时间:"+formartDate(btscapState.StopDT.getDateTime(), "yyyy-MM-dd HH:mm:ss"));
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("已测试时间(HMS):"+btscapState.Test_Time.testTime);
 
        rowNumSheet+=4;
        //插入图片
        int picNum = 0;
        String[] picName =new String[]{"单体电压折线图","电池电流折线图","组端电压折线图","测试容量折线图"};
        if (picName.length==bytes.size()){
            for(int i=0;i<picName.length;i++){
                sheet.createRow(rowNumSheet-1);
                sheet.getRow(rowNumSheet-1).createCell(0).setCellValue(picName[i]);
                //rowNum++;
                XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNumSheet, (short) 10, rowNumSheet+27);
                anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
                patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1);
                picNum ++;
                rowNumSheet+=30;
            }
        }
 
        //从文件中获取数据
        List<BTS_BattData> list=disData.fbsDatas;//放电数据
        String sheetName="放电数据";
        String testName="测试数据";
        XSSFSheet sheet1 = wb.createSheet(sheetName);
        //抬头
        int rowNum = 0;
        sheet1.createRow(rowNum).createCell(0).setCellValue(testName);
        rowNum++;
 
        XSSFRow row = sheet1.createRow(rowNum);
        //属性栏
        String[] rowName =new String[]{"测试时间","在线电压","组端电压","电池电流","电池容量","电池温度"};
        for (int i=0;i<rowName.length;i++){
            row.createCell(i).setCellValue(rowName[i]);
        }
        for(int i=0;i<battNum;i++){
            row.createCell(6+i).setCellValue("#"+Integer.valueOf(i+1));
        }
        rowNum++;
        //数据栏
        for (int i = 0; i < list.size(); i++) {
            sheet1.createRow(rowNum);  //创建行
            BTS_BattData fbsData= list.get(i);
            sheet1.getRow(rowNum).createCell(0).setCellValue(fbsData.testTime.testTime);
            sheet1.getRow(rowNum).createCell(1).setCellValue(fbsData.onlineVol);
            sheet1.getRow(rowNum).createCell(2).setCellValue(fbsData.groupVol);
            sheet1.getRow(rowNum).createCell(3).setCellValue(fbsData.battCurr);
            sheet1.getRow(rowNum).createCell(4).setCellValue(fbsData.battCap);
            sheet1.getRow(rowNum).createCell(5).setCellValue(fbsData.battTemp);
            double[]  datas=fbsData.monVol;
            for (int k = 0;k<battNum;k++){
                sheet1.getRow(rowNum).createCell(k+6).setCellValue(datas[k]);
            }
            rowNum++;
        }
        rowNum++;
 
        try {
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")
                    + ".xlsx");
            OutputStream out = resp.getOutputStream();
            wb.write(out);
            out.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    //导出bts的充电数据chr
    public void exportChr(HttpServletRequest req, HttpServletResponse resp) {
        String volEchart = req.getParameter("vol_echart");            //单体电压折线图
        String currEchart = req.getParameter("curr_echart");        //电池电流折线图
        String groupVolEchart = req.getParameter("groupVol_echart");        //组端电压折线图
        String capEchart = req.getParameter("cap_echart");            //测试容量折线图
        String filePath = req.getParameter("filePath");
        //图片base64后的数据
        List<byte[]> bytes = new ArrayList<>();
        try {
            if (ServletUtils.isNotNull(volEchart)) {
                String[] url = volEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(currEchart)) {
                String[] url = currEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(groupVolEchart)) {
                String[] url = groupVolEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
            if (ServletUtils.isNotNull(capEchart)) {
                String[] url = capEchart.split(",");
                bytes.add(new BASE64Decoder().decodeBuffer(url[1]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        //当前日期
        String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String excelName="CHR-"+nowFormat;
        //数据
        BTS_ChargeData chargeData=chargeDataService.getChrData(filePath);
        BTS_BattParam btsbattParam = chargeData.battParam;//电池参数
        BTS_ChargeParam btschargeParam=chargeData.chargeParam;//放电参数
        BTS_ChargeState btschargeState=chargeData.charState;//放电时长
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet("数据总表");
        //图片元素
        XSSFDrawing patriarch = sheet.createDrawingPatriarch();
        int rowNumSheet = 0;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("电池参数:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("标称容量(1AH):"+btsbattParam.STD_CAP);
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("标称内阻(0.001mΩ):"+btsbattParam.STD_RES);
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("单体标称电压(0.1V):"+btsbattParam.MonomerVol);
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组数:"+btsbattParam.BattGroupCount);
 
        int battNum=btsbattParam.EachGroupBattCount;//单体个数
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("每组单体个数:"+battNum);
        rowNumSheet++;
 
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端参数:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("充电电流:"+btschargeParam.ChargeCurr);
        rowNumSheet++;
 
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("组端状态:");
        rowNumSheet++;
        sheet.createRow(rowNumSheet);
        sheet.getRow(rowNumSheet).createCell(0).setCellValue("启动放电的日期时间:"+formartDate(btschargeState.StartDT.getDateTime(),"yyyy-MM-dd HH:mm:ss"));
        sheet.getRow(rowNumSheet).createCell(1).setCellValue("终止放电的日期时间:"+formartDate(btschargeState.StopDT.getDateTime(), "yyyy-MM-dd HH:mm:ss"));
        sheet.getRow(rowNumSheet).createCell(2).setCellValue("已测试时间(HMS):"+btschargeState.Test_Time.testTime);
 
        rowNumSheet+=4;
        //插入图片
        int picNum = 0;
        String[] picName =new String[]{"单体电压折线图","电池电流折线图","组端电压折线图","测试容量折线图"};
        if (picName.length==bytes.size()){
            for(int i=0;i<picName.length;i++){
                sheet.createRow(rowNumSheet-1);
                sheet.getRow(rowNumSheet-1).createCell(0).setCellValue(picName[i]);
                //rowNum++;
                XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNumSheet, (short) 10, rowNumSheet+27);
                anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
                patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1);
                picNum ++;
                rowNumSheet+=30;
            }
        }
 
        //从文件中获取数据
        List<BTS_BattData> list=chargeData.fbsDatas;//放电数据
        String sheetName="充电数据";
        String testName="测试数据";
        XSSFSheet sheet1 = wb.createSheet(sheetName);
        //抬头
        int rowNum = 0;
        sheet1.createRow(rowNum).createCell(0).setCellValue(testName);
        rowNum++;
 
        XSSFRow row = sheet1.createRow(rowNum);
        //属性栏
        String[] rowName =new String[]{"测试时间","在线电压","组端电压","电池电流","电池容量","电池温度"};
        for (int i=0;i<rowName.length;i++){
            row.createCell(i).setCellValue(rowName[i]);
        }
        for(int i=0;i<battNum;i++){
            row.createCell(6+i).setCellValue("#"+Integer.valueOf(i+1));
        }
        rowNum++;
        //数据栏
        for (int i = 0; i < list.size(); i++) {
            sheet1.createRow(rowNum);  //创建行
            BTS_BattData fbsData= list.get(i);
            sheet1.getRow(rowNum).createCell(0).setCellValue(fbsData.testTime.testTime);
            sheet1.getRow(rowNum).createCell(1).setCellValue(fbsData.onlineVol);
            sheet1.getRow(rowNum).createCell(2).setCellValue(fbsData.groupVol);
            sheet1.getRow(rowNum).createCell(3).setCellValue(fbsData.battCurr);
            sheet1.getRow(rowNum).createCell(4).setCellValue(fbsData.battCap);
            sheet1.getRow(rowNum).createCell(5).setCellValue(fbsData.battTemp);
            double[]  datas=fbsData.monVol;
            for (int k = 0;k<battNum;k++){
                sheet1.getRow(rowNum).createCell(k+6).setCellValue(datas[k]);
            }
            rowNum++;
        }
        rowNum++;
 
        try {
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")
                    + ".xlsx");
            OutputStream out = resp.getOutputStream();
            wb.write(out);
            out.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}