whyclxw
3 天以前 29aed8c1fde9c1fc6d248ba8028914e038442306
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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.BomAcceptanceMapper;
import com.whyc.pojo.BOMFeedback;
import com.whyc.pojo.BomAcceptance;
import com.whyc.pojo.DefectiveProducts;
import com.whyc.pojo.ProductHistory;
import com.whyc.util.ActionUtil;
import com.whyc.util.CommonUtil;
import com.whyc.util.FileUtil;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import static com.whyc.util.ActionUtil.createFilefolderIFNotExist;
 
@Service
public class BomAcceptanceService {
    @Autowired(required = false)
    private BomAcceptanceMapper mapper;
 
    //上传产品验收信息
    public Response uploadBomAcceptance(MultipartFile fileLeft, MultipartFile fileRight, MultipartFile fileFront, MultipartFile fileBack
            ,MultipartFile agreement,MultipartFile bomManual,MultipartFile testReport
            ,MultipartFile icdFile,MultipartFile cadPicpart,MultipartFile namePlate
            , List<MultipartFile> multipartFileList,List<MultipartFile> installCasePics
            , BomAcceptance bomAcceptance) throws IOException {
        Date date = new Date();
        bomAcceptance.setCreateTime(date);
        long time = date.getTime();
        String rootFile = CommonUtil.getRootFile();
        //配件存储
        if(multipartFileList!=null && multipartFileList.size()!=0){
            String spareDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "spare" + File.separator;
            String spareDir = rootFile + spareDirSuffix;
            File fileDir = new File(spareDir);
            if (!fileDir.exists()) {
                fileDir.mkdirs();
            }
            for (int i = 0; i < multipartFileList.size(); i++) {
                MultipartFile multipartFile = multipartFileList.get(i);
                //存储文件
                String originalFilename = multipartFile.getOriginalFilename();
                String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
                String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
                String sparePath = spareDir + fileName + suffix;
                File file = new File(sparePath);
                multipartFile.transferTo(file);
            }
            bomAcceptance.setSparePicpart(spareDirSuffix);
        }
        //现场安装案例照片
        if(installCasePics!=null && installCasePics.size()!=0){
            String installCasePicDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "install" + File.separator;
            String installCasePicDir = rootFile + installCasePicDirSuffix;
            File fileDir = new File(installCasePicDir);
            if (!fileDir.exists()) {
                fileDir.mkdirs();
            }
            for (int i = 0; i < installCasePics.size(); i++) {
                MultipartFile multipartFile = installCasePics.get(i);
                //存储文件
                String originalFilename = multipartFile.getOriginalFilename();
                String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
                String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
                String sparePath = installCasePicDir + fileName + suffix;
                File file = new File(sparePath);
                multipartFile.transferTo(file);
            }
            bomAcceptance.setInstallPic(installCasePicDirSuffix);
        }
 
        String devDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "dev" + File.separator;
        String devDir = rootFile + devDirSuffix;
        //左视图
        if(fileLeft!=null){
            //存储文件
            String originalFilename = fileLeft.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            fileLeft.transferTo(new File(path));
            bomAcceptance.setDevPicleft("doc_file" + File.separator + devDirSuffix+originalFilename);
        }
        //右视图
        if(fileRight!=null){
            //存储文件
            String originalFilename = fileRight.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            fileRight.transferTo(new File(path));
            bomAcceptance.setDevPicright("doc_file" + File.separator + devDirSuffix+originalFilename);
        }
        //正面图
        if(fileFront!=null){
            //存储文件
            String originalFilename = fileFront.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            fileFront.transferTo(new File(path));
            bomAcceptance.setDevPicfront("doc_file" + File.separator + devDirSuffix+originalFilename);
        }
        //后面图
        if(fileBack!=null){
            //存储文件
            String originalFilename = fileBack.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            fileBack.transferTo(new File(path));
            bomAcceptance.setDevPicback("doc_file" + File.separator + devDirSuffix+originalFilename);
        }
        String agreeDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "agree" + File.separator;
        String agreeDir = rootFile + agreeDirSuffix;
        //协议
        if(agreement!=null){
            //存储文件
            String originalFilename = agreement.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = agreeDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            agreement.transferTo(new File(path));
            bomAcceptance.setBomAgreement("doc_file" + File.separator + agreeDirSuffix+originalFilename);
        }
        String bomManualDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "bomManual" + File.separator;
        String bomManualDir = rootFile + bomManualDirSuffix;
        //说明书(文件)
        if(bomManual!=null){
            //存储文件
            String originalFilename = bomManual.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = bomManualDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            bomManual.transferTo(new File(path));
            bomAcceptance.setBomManual("doc_file" + File.separator + bomManualDirSuffix+originalFilename);
        }
        String testReportDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "testReport" + File.separator;
        String testReportDir = rootFile + testReportDirSuffix;
        //检测报告(文件)
        if(testReport!=null){
            //存储文件
            String originalFilename = testReport.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = testReportDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            testReport.transferTo(new File(path));
            bomAcceptance.setTestReport("doc_file" + File.separator + testReportDirSuffix+originalFilename);
        }
        String icdFileDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "icdFile" + File.separator;
        String icdFileDir = rootFile + icdFileDirSuffix;
        //ICD文件
        if(icdFile!=null){
            //存储文件
            String originalFilename = icdFile.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = icdFileDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            icdFile.transferTo(new File(path));
            bomAcceptance.setIcdFile("doc_file" + File.separator + icdFileDirSuffix+originalFilename);
        }
        String cadPicpartDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "cadPicpart" + File.separator;
        String cadPicpartDir = rootFile + cadPicpartDirSuffix;
        //施工图纸(文件)
        if(cadPicpart!=null){
            //存储文件
            String originalFilename = cadPicpart.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = cadPicpartDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            cadPicpart.transferTo(new File(path));
            bomAcceptance.setCadPicpart("doc_file" + File.separator + cadPicpartDirSuffix+originalFilename);
        }
        String namePlateDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "namePlate" + File.separator;
        String namePlateDir = rootFile + namePlateDirSuffix;
        //铭牌信息(文件)
        if(namePlate!=null){
            //存储文件
            String originalFilename = namePlate.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = namePlateDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            namePlate.transferTo(new File(path));
            bomAcceptance.setNamePlate("doc_file" + File.separator + namePlateDirSuffix+originalFilename);
        }
        mapper.insert(bomAcceptance);
        return new Response().set(1,true,"上传成功");
    }
    //查询产品验收信息
    public Response getBomAcceptance(BomAcceptance bomAcceptance, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        if(bomAcceptance.getDirectName()!=null){
            wrapper.like("direct_name",bomAcceptance.getDirectName());
        }
        if(bomAcceptance.getBomSeries()!=null){
            wrapper.like("bom_series",bomAcceptance.getBomSeries());
        }
        if(bomAcceptance.getBomModel()!=null){
            wrapper.like("bom_model",bomAcceptance.getBomModel());
        }
        if(bomAcceptance.getBomVersion()!=null){
            wrapper.like("bom_version",bomAcceptance.getBomVersion());
        }
        if(bomAcceptance.getCreateTime()!=null){
            wrapper.ge("create_time",bomAcceptance.getCreateTime());
        }
        if(bomAcceptance.getCreateTime1()!=null){
            wrapper.le("create_time",bomAcceptance.getCreateTime1());
        }
        wrapper.orderByDesc("create_time");
        List<BomAcceptance> list = mapper.selectList(wrapper);
        String rootFile = CommonUtil.getRootFile();//主路径
        if(list!=null&&list.size()>0){
            for (BomAcceptance acceptance:list) {
                String sparefilePath=rootFile+acceptance.getSparePicpart();
                acceptance.setSparePicpart("doc_file"+File.separator+acceptance.getSparePicpart());
                //获取文件夹下所有的图片名
                acceptance.setNameList(FileUtil.getFileNameWithOutDirectory(sparefilePath));
 
                String installfilePath=rootFile+acceptance.getInstallPic();
                acceptance.setInstallPic("doc_file"+File.separator+acceptance.getInstallPic());
                //获取文件夹下所有的图片名
                acceptance.setInstallList(FileUtil.getFileNameWithOutDirectory(installfilePath));
            }
        }
        PageInfo  pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"查询产品验收信息");
    }
    //删除产品验收信息
    public Response delBomAcceptance(int num) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("num",num);
        int bl=mapper.delete(wrapper);
        return new Response().setII(1,bl>0,bl,"删除产品验收信息");
    }
   //编辑产品验收信息
    public Response updateBomAcceptance(BomAcceptance bomAcceptance) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("num",bomAcceptance.getNum());
        if(bomAcceptance.getDirectName()!=null){
            wrapper.set("direct_name",bomAcceptance.getDirectName());
        }
        if(bomAcceptance.getBomSeries()!=null){
            wrapper.set("bom_series",bomAcceptance.getBomSeries());
        }
        if(bomAcceptance.getBomModel()!=null){
            wrapper.set("bom_model",bomAcceptance.getBomModel());
        }
        if(bomAcceptance.getDevParam()!=null){
            wrapper.set("dev_param",bomAcceptance.getDevParam());
        }
        if(bomAcceptance.getStandParam()!=null){
            wrapper.set("stand_param",bomAcceptance.getStandParam());
        }
        if(bomAcceptance.getBomSize()!=null){
            wrapper.set("bom_size",bomAcceptance.getBomSize());
        }
        if(bomAcceptance.getDevWeight()!=null){
            wrapper.set("dev_weight",bomAcceptance.getDevWeight());
        }
        if(bomAcceptance.getDevWeightAll()!=null){
            wrapper.set("dev_weight_all",bomAcceptance.getDevWeightAll());
        }
        if(bomAcceptance.getSparePartmodel()!=null){
            wrapper.set("spare_partmodel",bomAcceptance.getSparePartmodel());
        }
        if(bomAcceptance.getBomVersion()!=null){
            wrapper.set("bom_version",bomAcceptance.getBomVersion());
        }
 
        mapper.update(null,wrapper);
        return new Response().set(1,true,"编辑成功");
    }
   //删除图
    public void delPic(int num, int picNum,String picUrl,String newPicUrl) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("num",num);
        if(picNum==1){
            wrapper.set("dev_picleft",newPicUrl);
        }
        if(picNum==2){
            wrapper.set("dev_picright",newPicUrl);
        }
        if(picNum==3){
            wrapper.set("dev_picfront",newPicUrl);
        }
        if(picNum==4){
            wrapper.set("dev_picback",newPicUrl);
        }
        if(picNum==5){
            wrapper.set("spare_picpart",newPicUrl);
        }
        if(picNum==6){
            wrapper.set("bom_agreement",newPicUrl);
        }
        if(picNum==7){
            wrapper.set("bom_manual",newPicUrl);
        }
        if(picNum==8){
            wrapper.set("test_report",newPicUrl);
        }
        if(picNum==9){
            wrapper.set("icd_file",newPicUrl);
        }
        if(picNum==10){
            wrapper.set("cad_picpart",newPicUrl);
        }
        if(picNum==11){
            wrapper.set("name_plate",newPicUrl);
        }
        if(picNum==12){
            wrapper.set("install_pic",newPicUrl);
        }
        int flag=mapper.update(null,wrapper);
        if(flag>0&&picUrl.length()>0){
            String rootFile = CommonUtil.getRootFile();//主路径
            picUrl=picUrl.replace("doc_file","");
            //删除图片
            FileUtil.deleteFile(new File(rootFile+picUrl));
        }
    }
    //编辑单个图片上传
    public Response updateDevPic(MultipartFile filePic, int num,int picNum) throws IOException {
        Date date = new Date();
        long time = date.getTime();
        String rootFile = CommonUtil.getRootFile();
        String devDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "dev" + File.separator;
        String devDir = rootFile + devDirSuffix;
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("num",num);
        wrapper.last("limit 1");
        BomAcceptance bomAcceptance=mapper.selectOne(wrapper);
        String picUrl="";
        if(picNum==1){
            picUrl=bomAcceptance.getDevPicleft();
        }
        if(picNum==2){
            picUrl=bomAcceptance.getDevPicright();
        }
        if(picNum==3){
            picUrl=bomAcceptance.getDevPicfront();
        }
        if(picNum==4){
            picUrl=bomAcceptance.getDevPicback();
        }
        if(picNum==6){
            picUrl=bomAcceptance.getBomAgreement();
        }
        if(picNum==7){
            picUrl=bomAcceptance.getBomManual();
        }
        if(picNum==8){
            picUrl=bomAcceptance.getTestReport();
        }
        if(picNum==9){
            picUrl=bomAcceptance.getIcdFile();
        }
        if(picNum==10){
            picUrl=bomAcceptance.getCadPicpart();
        }
        if(picNum==11){
            picUrl=bomAcceptance.getNamePlate();
        }
        if(filePic!=null){
            //存储文件
            String originalFilename = filePic.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            filePic.transferTo(new File(path));
            String devFile="doc_file" + File.separator + devDirSuffix+originalFilename;
            //删除旧的
            delPic(num,picNum,picUrl,devFile);
            return new Response().set(1,true,"上传新图片成功");
        }else{
            return new Response().set(1,false,"图片不存在");
        }
    }
    //编辑多个图片上传
    public Response updatePartPic(List<MultipartFile> multipartFileList, int num) throws IOException {
        String rootFile = CommonUtil.getRootFile();
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("num",num);
        wrapper.last("limit 1");
        BomAcceptance bomAcceptance=mapper.selectOne(wrapper);
        String picUrl=bomAcceptance.getSparePicpart();
        //配件存储
        if(multipartFileList!=null && multipartFileList.size()!=0){
            for (int i = 0; i < multipartFileList.size(); i++) {
                MultipartFile multipartFile = multipartFileList.get(i);
                //存储文件
                String originalFilename = multipartFile.getOriginalFilename();
                String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
                String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
                String sparePath = rootFile+picUrl + fileName + suffix;
                File file = new File(sparePath);
                multipartFile.transferTo(file);
            }
            return new Response().set(1,true,"上传成功");
        }else{
            return new Response().set(1,false,"图片不存在");
        }
    }
    //编辑现场安装图片多个图片上传
    public Response updateInstallPic(List<MultipartFile> multipartFileList, int num) throws IOException {
        String rootFile = CommonUtil.getRootFile();
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("num",num);
        wrapper.last("limit 1");
        BomAcceptance bomAcceptance=mapper.selectOne(wrapper);
        String picUrl=bomAcceptance.getInstallPic();
        //配件存储
        if(multipartFileList!=null && multipartFileList.size()!=0){
            for (int i = 0; i < multipartFileList.size(); i++) {
                MultipartFile multipartFile = multipartFileList.get(i);
                //存储文件
                String originalFilename = multipartFile.getOriginalFilename();
                String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
                String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
                String installPath = rootFile+picUrl + fileName + suffix;
                File file = new File(installPath);
                multipartFile.transferTo(file);
            }
            return new Response().set(1,true,"上传成功");
        }else{
            return new Response().set(1,false,"图片不存在");
        }
    }
 
    //导出产品验收信息
    public void downloadBomAcceptance(HttpServletRequest req, HttpServletResponse resp, int num) {
        //读取产品信息
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("num",num);
        wrapper.last("limit 1");
        BomAcceptance bomAcceptance=mapper.selectOne(wrapper);
        //生成excel
        creatBomAcceptanceExcel(resp,bomAcceptance);
    }
    //生成excel
    private void creatBomAcceptanceExcel( HttpServletResponse resp, BomAcceptance bomAcceptance) {
        String rootFile = CommonUtil.getRootFile();
        List<String> sparePicList=new ArrayList<>();
        if(bomAcceptance.getSparePicpart()!=null||!bomAcceptance.getSparePicpart().isEmpty()){
            String filePath=rootFile+bomAcceptance.getSparePicpart();
            //获取文件夹下所有的图片名
            sparePicList=FileUtil.getFileNameWithOutDirectory(filePath);
        }
        List<String> installPicList=new ArrayList<>();
        if(bomAcceptance.getInstallPic()!=null||!bomAcceptance.getInstallPic().isEmpty()){
            String filePath=rootFile+bomAcceptance.getInstallPic();
            //获取文件夹下所有的图片名
            installPicList=FileUtil.getFileNameWithOutDirectory(filePath);
        }
 
        String devRoot=rootFile.replace("doc_file", "");
        List<String> devPicList=new ArrayList<>();
        devPicList.add(bomAcceptance.getDevPicleft());
        devPicList.add(bomAcceptance.getDevPicfront());
        devPicList.add(bomAcceptance.getDevPicright());
        devPicList.add(bomAcceptance.getDevPicback());
 
        String fileName="产品验收信息记录";
        //创建单个sheet
        HSSFWorkbook wb = new HSSFWorkbook();
        //字体格式-加粗
        HSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
 
        cellStyle.setBorderBottom(BorderStyle.THICK);
        cellStyle.setBorderLeft(BorderStyle.THICK);
        cellStyle.setBorderRight(BorderStyle.THICK);
        cellStyle.setBorderTop(BorderStyle.THICK);
 
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);
        HSSFSheet sheet = wb.createSheet("产品验收信息记录");
        sheet.setColumnWidth(0,10000);
        if(sparePicList!=null&&sparePicList.size()>0){
             int length = sparePicList.size();
             length=length>5?length:4;
             for (int i = 1; i < length+1; i++){
                 sheet.setColumnWidth(i,5000);
             }
        }
        sheet.setDefaultRowHeight((short)(1000));
        //图片元素
        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        int rowNum=0;
        HSSFRow row=sheet.createRow(rowNum);
        HSSFCell cell=row.createCell(0);
        cell.setCellValue("产品验收信息记录表");
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(0,0,0,1));
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("研发负责人");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getDirectName());
        cell.setCellStyle(cellStyle);
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("产品系列");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getBomSeries());
        cell.setCellStyle(cellStyle);
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("产品型号");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getBomModel());
        cell.setCellStyle(cellStyle);
 
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("产品版本号");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getBomVersion());
        cell.setCellStyle(cellStyle);
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("技术指标");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getDevParam());
        cell.setCellStyle(cellStyle);
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("技术指标");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getStandParam());
        cell.setCellStyle(cellStyle);
        sheet.addMergedRegion(new CellRangeAddress(4,5,0,0));
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("长x宽x高(mm)");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getBomSize());
        cell.setCellStyle(cellStyle);
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("主机净重(KG)");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getDevWeight());
        cell.setCellStyle(cellStyle);
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("整机全重(含包装箱,配件)(KG)");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getDevWeightAll());
        cell.setCellStyle(cellStyle);
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("主机照片(左侧图,正面图,右侧图,后面图)");
        cell.setCellStyle(cellStyle);
        if(devPicList!=null&&devPicList.size()>0){
            ByteArrayOutputStream byteArrayOut = null;
            for(int i=0;i<devPicList.size();i++){
                String picUrl=devPicList.get(i);
                if(picUrl.length()==0){
                    continue;
                }
                try {
                    byteArrayOut = new ByteArrayOutputStream();
                    String path=devRoot+File.separator+picUrl;
                    BufferedImage bufferImg = ImageIO.read(new FileInputStream(new File(path)));
                    ImageIO.write(bufferImg, "png", byteArrayOut);
                    //anchor主要用于设置图片的属性
                    HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) (i+1), rowNum, (short) (i+1), rowNum);
                    anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
                    //插入图片
                    patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    if (byteArrayOut != null) {
                        try {
                            byteArrayOut.close();
                        } catch (IOException e) {
                            System.out.println("关闭ByteArrayOutputStream失败");
                        }
                    }
                }
            }
        }
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("配件照片");
        cell.setCellStyle(cellStyle);
        if(sparePicList!=null&&sparePicList.size()>0){
            ByteArrayOutputStream byteArrayOut = null;
            for(int i=0;i<sparePicList.size();i++){
                String picUrl=sparePicList.get(i);
                try {
                    byteArrayOut = new ByteArrayOutputStream();
                    String path=rootFile+File.separator+bomAcceptance.getSparePicpart()+File.separator+picUrl;
                    BufferedImage bufferImg = ImageIO.read(new FileInputStream(new File(path)));
                    ImageIO.write(bufferImg, "png", byteArrayOut);
                    //anchor主要用于设置图片的属性
                    HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) (i+1), rowNum, (short) (i+1), rowNum);
                    anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
                    //插入图片
                    patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    if (byteArrayOut != null) {
                        try {
                            byteArrayOut.close();
                        } catch (IOException e) {
                            System.out.println("关闭ByteArrayOutputStream失败");
                        }
                    }
                }
            }
        }
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("配件型号规格");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        cell.setCellValue(bomAcceptance.getSparePartmodel());
        cell.setCellStyle(cellStyle);
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("端口协议文本");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        if(bomAcceptance.getBomAgreement()!=null&&bomAcceptance.getBomAgreement().length()>0){
            String agreement=bomAcceptance.getBomAgreement();
            String agreementName = agreement.substring(agreement.lastIndexOf(File.separator)+1);
            agreementName = agreementName.substring(0,agreementName.lastIndexOf("."));
            cell.setCellValue(agreementName);
            cell.setCellStyle(cellStyle);
        }
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("说明书");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        if(bomAcceptance.getBomManual()!=null&&bomAcceptance.getBomManual().length()>0){
            String bomManual=bomAcceptance.getBomManual();
            String bomManualName = bomManual.substring(bomManual.lastIndexOf(File.separator)+1);
            bomManualName = bomManualName.substring(0,bomManualName.lastIndexOf("."));
            cell.setCellValue(bomManualName);
            cell.setCellStyle(cellStyle);
        }
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("检测报告");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        if(bomAcceptance.getTestReport()!=null&&bomAcceptance.getTestReport().length()>0){
            String testReport=bomAcceptance.getTestReport();
            String testReportName = testReport.substring(testReport.lastIndexOf(File.separator)+1);
            testReportName = testReportName.substring(0,testReportName.lastIndexOf("."));
            cell.setCellValue(testReportName);
            cell.setCellStyle(cellStyle);
        }
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("ICD文件");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        if(bomAcceptance.getIcdFile()!=null&&bomAcceptance.getIcdFile().length()>0){
            String icdFile=bomAcceptance.getTestReport();
            String icdFileName = icdFile.substring(icdFile.lastIndexOf(File.separator)+1);
            icdFileName = icdFileName.substring(0,icdFileName.lastIndexOf("."));
            cell.setCellValue(icdFileName);
            cell.setCellStyle(cellStyle);
        }
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("施工图纸");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        if(bomAcceptance.getCadPicpart()!=null&&bomAcceptance.getCadPicpart().length()>0){
            String cadPicpart=bomAcceptance.getCadPicpart();
            String cadPicpartName = cadPicpart.substring(cadPicpart.lastIndexOf(File.separator)+1);
            cadPicpartName = cadPicpartName.substring(0,cadPicpartName.lastIndexOf("."));
            cell.setCellValue(cadPicpartName);
            cell.setCellStyle(cellStyle);
        }
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("铭牌信息");
        cell.setCellStyle(cellStyle);
        cell=row.createCell(1);
        if(bomAcceptance.getNamePlate()!=null&&bomAcceptance.getNamePlate().length()>0){
            String namePlate=bomAcceptance.getNamePlate();
            String namePlateName = namePlate.substring(namePlate.lastIndexOf(File.separator)+1);
            namePlateName = namePlateName.substring(0,namePlateName.lastIndexOf("."));
            cell.setCellValue(namePlateName);
            cell.setCellStyle(cellStyle);
        }
 
        rowNum++;
        row=sheet.createRow(rowNum);
        cell=row.createCell(0);
        cell.setCellValue("现场安装案例照片");
        cell.setCellStyle(cellStyle);
        if(installPicList!=null&&installPicList.size()>0){
            ByteArrayOutputStream byteArrayOut = null;
            for(int i=0;i<installPicList.size();i++){
                String picUrl=installPicList.get(i);
                try {
                    byteArrayOut = new ByteArrayOutputStream();
                    String path=rootFile+File.separator+bomAcceptance.getInstallPic()+File.separator+picUrl;
                    BufferedImage bufferImg = ImageIO.read(new FileInputStream(new File(path)));
                    ImageIO.write(bufferImg, "png", byteArrayOut);
                    //anchor主要用于设置图片的属性
                    HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) (i+1), rowNum, (short) (i+1), rowNum);
                    anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
                    //插入图片
                    patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    if (byteArrayOut != null) {
                        try {
                            byteArrayOut.close();
                        } catch (IOException e) {
                            System.out.println("关闭ByteArrayOutputStream失败");
                        }
                    }
                }
            }
        }
 
        //将文件存到指定位置
        OutputStream os = null;
        try {
            os = resp.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode (fileName+ ".xls", "utf-8"));
            resp.setCharacterEncoding("UTF-8");
            //不保存缓存信息与response.reset同样效果
            resp.addHeader("Pragma", "no-cache");
            resp.addHeader("Cache-Control", "no-cache");
            wb.write(os);
            os.flush();
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //跳转详情
    public Response getBomAcceptanceByNum(int num) {
        String rootFile = CommonUtil.getRootFile();
        //读取产品信息
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("num",num);
        wrapper.last("limit 1");
        BomAcceptance bomAcceptance=mapper.selectOne(wrapper);
        String sparefilePath=rootFile+bomAcceptance.getSparePicpart();
        bomAcceptance.setSparePicpart("doc_file"+File.separator+bomAcceptance.getSparePicpart());
        //获取文件夹下所有的图片名
        bomAcceptance.setNameList(FileUtil.getFileNameWithOutDirectory(sparefilePath));
 
        String installfilePath=rootFile+bomAcceptance.getInstallPic();
        bomAcceptance.setInstallPic("doc_file"+File.separator+bomAcceptance.getInstallPic());
        //获取文件夹下所有的图片名
        bomAcceptance.setInstallList(FileUtil.getFileNameWithOutDirectory(installfilePath));
        return new Response().set(1,bomAcceptance,"跳转详情");
    }
 
}