cl
2024-01-19 e0fac38b26845f25de479783e0c76cf12a5311e0
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
package cn.stylefeng.guns.modular.om.productionOrdeInfo.controller;
 
import cn.afterturn.easypoi.entity.vo.MapExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.view.PoiBaseView;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.bs.locationInfo.entity.LocationInfo;
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
import cn.stylefeng.guns.modular.bs.materialInfo.entity.MaterialInfo;
import cn.stylefeng.guns.modular.bs.materialInfo.service.MaterialInfoService;
import cn.stylefeng.guns.modular.cm.passingStationCollection.entity.PassingStationCollection;
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.result.PassingStationCollectionResult;
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.entity.ProductionOrdeInfo;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.sys.modular.system.entity.Dict;
import cn.stylefeng.guns.sys.modular.system.service.DictService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.models.auth.In;
import lombok.SneakyThrows;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
 
 
/**
 * 生产工单控制器
 *
 * @author cl
 * @Date 2022-10-25 14:04:47
 */
@Controller
@RequestMapping("/productionOrdeInfo")
public class ProductionOrdeInfoController extends BaseController {
 
    private String PREFIX = "modular/om/productionOrdeInfo";
 
    @Autowired
    private ProductionOrdeInfoService productionOrdeInfoService;
 
    @Autowired
    private DictService dictService;
 
    /**
     * 跳转到主页面
     *
     * @author cl
     * @Date 2022-10-25
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/productionOrdeInfo.html";
    }
 
    /**
     * 新增页面
     *
     * @author cl
     * @Date 2022-10-25
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/productionOrdeInfo_add.html";
    }
 
    /**
     * 编辑页面
     *
     * @author cl
     * @Date 2022-10-25
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/productionOrdeInfo_edit.html";
    }
 
    @RequestMapping("/materialList")
    public String materialList() {
        return PREFIX + "/materialList.html";
    }
 
    @RequestMapping("/materialLists")
    public String materialLists() {
        return PREFIX + "/materialLists.html";
    }
 
    @RequestMapping("/customInfo")
    public String customInfo() {
        return PREFIX + "/customInfo.html";
    }
 
    /**
     * 新增接口
     *
     * @author cl
     * @Date 2022-10-25
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ProductionOrdeInfoParam productionOrdeInfoParam) {
        this.productionOrdeInfoService.add(productionOrdeInfoParam);
        return ResponseData.success();
    }
 
    /**
     * 编辑接口
     *
     * @author cl
     * @Date 2022-10-25
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ProductionOrdeInfoParam productionOrdeInfoParam) {
        if(productionOrdeInfoParam.getFlag()!=null){
            productionOrdeInfoParam.setActualStartTime(new Date());
        }
        this.productionOrdeInfoService.update(productionOrdeInfoParam);
        this.productionOrdeInfoService.saveOrderBatchInfo(productionOrdeInfoParam);
        return ResponseData.success();
    }
 
    /**
     * 编辑接口
     *
     * @author cl
     * @Date 2022-10-25
     */
    @RequestMapping("/editItemAll")
    @ResponseBody
    public ResponseData editItemAll(@RequestBody List<ProductionOrdeInfoParam> list) {
        for(int i=0;i<list.size();i++){
            ProductionOrdeInfoParam productionOrdeInfoParam = list.get(i);
            this.productionOrdeInfoService.update(productionOrdeInfoParam);
        }
 
        return ResponseData.success();
    }
 
    /**
     * 删除接口
     *
     * @author cl
     * @Date 2022-10-25
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ProductionOrdeInfoParam productionOrdeInfoParam) {
        this.productionOrdeInfoService.delete(productionOrdeInfoParam);
        return ResponseData.success();
    }
 
    /**
     * 查看详情接口
     *
     * @author cl
     * @Date 2022-10-25
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ProductionOrdeInfoParam productionOrdeInfoParam) {
        ProductionOrdeInfo detail = this.productionOrdeInfoService.getById(productionOrdeInfoParam.getId());
        return ResponseData.success(detail);
    }
 
    /**
     * 查询列表
     *
     * @author cl
     * @Date 2022-10-25
     */
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/list")
    public LayuiPageInfo list(ProductionOrdeInfoParam productionOrdeInfoParam) {
        return this.productionOrdeInfoService.findPageBySpec(productionOrdeInfoParam);
    }
 
    @ResponseBody
    @RequestMapping("/orderCount")
    public ResponseData orderCount(ProductionOrdeInfoParam productionOrdeInfoParam) {
        int orderStatus = productionOrdeInfoService.count(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", productionOrdeInfoParam.getOrderStatus()));
        return ResponseData.success(orderStatus);
    }
 
    /**
     * 大屏列表接口
     * @param productionOrdeInfoParam
     * @return
     */
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/largeScreenList")
    public List largeScreenList(ProductionOrdeInfoParam productionOrdeInfoParam) {
        ArrayList arrayList = new ArrayList();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//        productionOrdeInfoParam.setOrderStatus("3");
        LayuiPageInfo pageBySpec = this.productionOrdeInfoService.findPageBySpec(productionOrdeInfoParam);
        List<ProductionOrdeInfoResult> result = pageBySpec.getData();
        for (ProductionOrdeInfoResult productionOrdeInfoResult : result) {
            ArrayList resultList = new ArrayList();
            resultList.add(productionOrdeInfoResult.getWorkOrderNo());
            resultList.add(productionOrdeInfoResult.getMaterialCode());
            resultList.add(productionOrdeInfoResult.getProductionLine());
            resultList.add(productionOrdeInfoResult.getPlanQty());
            resultList.add(productionOrdeInfoResult.getActualQty());
            resultList.add(format.format(productionOrdeInfoResult.getCreateTime()));
            arrayList.add(resultList);
        }
        return arrayList;
    }
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/largeScreenList1")
    public List largeScreenList1(ProductionOrdeInfoParam productionOrdeInfoParam) {
        ArrayList arrayList = new ArrayList();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        List<ProductionOrdeInfoResult> list = this.productionOrdeInfoService.getListMonth();
        for (ProductionOrdeInfoResult productionOrdeInfoResult : list) {
            ArrayList resultList = new ArrayList();
            resultList.add(productionOrdeInfoResult.getWorkOrderNo());
            resultList.add(productionOrdeInfoResult.getMaterialCode());
            resultList.add(productionOrdeInfoResult.getPlanQty());
            resultList.add(productionOrdeInfoResult.getActualQty());
            resultList.add(format.format(productionOrdeInfoResult.getCreateTime()));
            arrayList.add(resultList);
        }
        return arrayList;
    }
 
    /**
     * 大屏产线接口
     * @return
     */
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/lineFinishQty")
    public ResponseData lineFinishQty() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        List resultList = new ArrayList();
        List<ProductionOrdeInfoResult> list = this.productionOrdeInfoService.lineFinishQty();
        for (ProductionOrdeInfoResult productionOrdeInfo : list) {
            Map map = new HashMap();
            map.put("name",format.format(productionOrdeInfo.getActualStartTime()));
            map.put("value",productionOrdeInfo.getActualQty());
            resultList.add(map);
        }
        return ResponseData.success(resultList);
    }
 
    /**
     * 大屏车间工单信息接口
     * @return
     */
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/workshopOrderDetail")
    public ResponseData workshopOrderDetail(ProductionOrdeInfoParam productionOrdeInfoParam) {
//        NumberFormat numberFormat = NumberFormat.getInstance();
//        numberFormat.setMaximumFractionDigits(2);
//        ProductionOrdeInfo one = productionOrdeInfoService.getOne(new QueryWrapper<ProductionOrdeInfo>()
//                .select("SUM\n" +
//                        "\t( plan_qty ) AS planQty,\n" +
//                        "\tSUM ( actual_qty ) AS actualQty,\n" +
//                        "\tSUM ( scrap_qty ) AS scrapQty ")
//        );
//        //计划
//        Integer plqnQty = one.getPlanQty();
//        //完成
//        Integer actualQty = one.getActualQty();
//        //报废
//        Integer scrapQty = one.getScrapQty();
//        //合格数量
//        Integer paseQty = actualQty-scrapQty;
//
//        Map map = new HashMap<String,String>();
//        map.put("produceQty",plqnQty);
//        map.put("finishQty",actualQty);
//        map.put("paseQty",paseQty);
//        map.put("noPaseQty",scrapQty);
//        map.put("CompletionRate",numberFormat.format((float) actualQty / (float) plqnQty * 100));
//        map.put("PassRate",numberFormat.format((float) paseQty / (float) actualQty * 100));
//        map.put("surplusQty",plqnQty-actualQty);
//        return ResponseData.success(map);
        ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
        param.setOrderStatus("3");
        ProductionOrdeInfoResult one = new ProductionOrdeInfoResult();
        NumberFormat numberFormat = NumberFormat.getInstance();
        numberFormat.setMaximumFractionDigits(2);
        List<ProductionOrdeInfoResult> listMonth = productionOrdeInfoService.getListMonth();
        List<ProductionOrdeInfoResult> listBySpec = productionOrdeInfoService.findListBySpec(param);
        if(listBySpec.size() == 0){
            ToolUtil.copyProperties(listMonth.get(0), one);
        }else {
            ToolUtil.copyProperties(listBySpec.get(0), one);
        }
        if(one.getActualQty() == null){
            one.setActualQty(0);
        }
        if(one.getScrapQty() == null){
            one.setScrapQty(0);
        }
        //计划
        Integer plqnQty = one.getPlanQty();
        //完成
        Integer actualQty = one.getActualQty();
        //报废
        Integer scrapQty = one.getScrapQty();
        //合格数量
        Integer paseQty = actualQty-scrapQty;
 
        Map map = new HashMap<String,String>();
        map.put("produceQty",one.getPlanQty());
        map.put("finishQty",one.getActualQty());
        map.put("paseQty",paseQty);
        map.put("noPaseQty",scrapQty);
        map.put("CompletionRate",numberFormat.format((float) actualQty / (float) plqnQty * 100));
        String format = numberFormat.format((float) paseQty / (float) actualQty * 100);
        if(format.equals("�")){
            map.put("PassRate","0");
        }else {
            map.put("PassRate",format);
        }
        map.put("surplusQty",plqnQty-actualQty);
        return ResponseData.success(map);
    }
 
    /**
     * 大屏车间工单信息接口
     * @return
     */
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/reportLineList")
    public ResponseData reportLineList(ProductionOrdeInfoParam productionOrdeInfoParam) {
        Map map = new HashMap<String,String>();
        return ResponseData.success(map);
    }
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/lineChart")
    public ResponseData lineChart(ProductionOrdeInfoParam productionOrdeInfoParam) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = new ArrayList();
        List<Integer> planQtyList = new ArrayList();
        List<Integer> actualQtyList = new ArrayList();
        Map map = new HashMap<String,String>();
        List<ProductionOrdeInfoResult> ColumnarDateList = productionOrdeInfoService.getColumnarDate();
        for (ProductionOrdeInfoResult result : ColumnarDateList) {
            String s = format.format(result.getActualStartTime());
            QueryWrapper<ProductionOrdeInfo> queryWrapper = new QueryWrapper<ProductionOrdeInfo>();
            queryWrapper.select("SUM(plan_qty) as planQty,SUM(actual_qty) as actualQty");
            queryWrapper.apply("CONVERT ( VARCHAR ( 100 ), actual_start_time, 23 ) = {0}",s);
            ProductionOrdeInfo one = productionOrdeInfoService.getOne(queryWrapper);
            if(one!=null){
                if(one.getPlanQty()!=null){
                    planQtyList.add(one.getPlanQty());
                }else {
                    planQtyList.add(0);
                }
                if(one.getActualQty()!=null){
                    actualQtyList.add(one.getActualQty());
                }else {
                    actualQtyList.add(0);
                }
            }else {
                planQtyList.add(0);
                actualQtyList.add(0);
            }
            list.add(s);
        }
 
        map.put("category",list);
        map.put("lineData",planQtyList);
        map.put("barData",actualQtyList);
        return ResponseData.success(map);
    }
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/findOrdrList")
    public ResponseData findOrdrList(ProductionOrdeInfoParam productionOrdeInfoParam) {
        ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
        param.setProductionLine("");//产线
        param.setOrderStatus("3");//工单状态
        List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
        return ResponseData.success(list);
    }
 
    /**
     * 下载excel导入模板
     *
     * @author liwenya
     * @Date 2021年7月9日 17点01分
     */
    @RequestMapping("/downloadExcelTemplate")
    public void downloadExcelTemplate(ModelMap modelMap, HttpServletRequest request,
                                      HttpServletResponse response) {
        //初始化表头
        List<ExcelExportEntity> entity = new ArrayList<>();
        entity.add(new ExcelExportEntity("生产工单号", "workOrderNo"));
        entity.add(new ExcelExportEntity("物料编号", "materialCode"));
        entity.add(new ExcelExportEntity("物料描述", "materialName"));
 
        entity.add(new ExcelExportEntity("软件版本编码", "softwareVersionCode"));
        entity.add(new ExcelExportEntity("生产基地编码", "productCompanyCode"));
 
        entity.add(new ExcelExportEntity("计划数量", "planQty"));
        entity.add(new ExcelExportEntity("计划开始时间", "planStartTime"));
        entity.add(new ExcelExportEntity("计划结束时间", "planEndTime"));
 
        ExportParams params = new ExportParams("生产工单模板", "生产工单", ExcelType.XSSF);
        modelMap.put(MapExcelConstants.MAP_LIST, new ArrayList<>());
        modelMap.put(MapExcelConstants.ENTITY_LIST, entity);
        modelMap.put(MapExcelConstants.PARAMS, params);
        modelMap.put(MapExcelConstants.FILE_NAME, "生产工单");
        PoiBaseView.render(modelMap, request, response, MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW);
    }
 
    /**
     * 导入Excel
     *
     * @author cl
     * @Date 2022-10-25
     */
    @SneakyThrows
    @RequestMapping("/uploadExcel")
    @ResponseBody
    public ResponseData exportIn(@RequestPart("file") MultipartFile file, HttpServletRequest request){
        List<ProductionOrdeInfo> list = new ArrayList<>();
 
        //定义工作簿
        XSSFWorkbook sheets = null;
        try{
            sheets = new XSSFWorkbook(file.getInputStream());
            //获取sheet
            XSSFSheet sheet = sheets.getSheet(sheets.getSheetName(0));
            int rows = sheet.getPhysicalNumberOfRows();
            for(int i = 2; i < rows; i++){
                //获取列数
                XSSFRow row = sheet.getRow(i);
                ProductionOrdeInfo orderInfo = new ProductionOrdeInfo();
 
                orderInfo.setWorkOrderNo(getCellValue(row.getCell(0)));//工单编码
                orderInfo.setMaterialCode(getCellValue(row.getCell(1)));//物料编号
                orderInfo.setMaterialName(getCellValue(row.getCell(2)));//物料描述
 
                orderInfo.setSoftwareVersionCode(getCellValue(row.getCell(3)));//软件版本编码
                orderInfo.setProductCompanyCode(getCellValue(row.getCell(4)));//生产基地编码
 
 
                Cell planQty = row.getCell(5);//计划数量
                if(!Objects.equals(planQty, null) && !Objects.equals(planQty.toString(),"")){
                    double d = planQty.getNumericCellValue();
                    orderInfo.setPlanQty((int) d);
                }
 
                Cell planStartTime = row.getCell(6);//计划开始时间
                if(HSSFDateUtil.isCellDateFormatted(planStartTime)){
                    Date d = planStartTime.getDateCellValue();
                    orderInfo.setPlanStartTime(d);
                }
 
                Cell planEndTime = row.getCell(7);//计划结束时间
                if(HSSFDateUtil.isCellDateFormatted(planEndTime)){
                    Date d = planEndTime.getDateCellValue();
                    orderInfo.setPlanEndTime(d);
                }
                list.add(orderInfo);
            }
 
            for(ProductionOrdeInfo obj : list){
                productionOrdeInfoService.save(obj);
            }
            return ResponseData.success("上传成功");
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseData.error("上传失败");
        }
    }
 
 
    /**
     * 获得Hsscell内容
     *
     * @param cell
     * @return
     */
    public String getCellValue(XSSFCell cell) {
        String value = "";
        if (cell != null) {
            switch (cell.getCellType()) {
                case HSSFCell.CELL_TYPE_FORMULA:
                    break;
                case HSSFCell.CELL_TYPE_NUMERIC:
                    DecimalFormat df = new DecimalFormat("0");
                    value = df.format(cell.getNumericCellValue());
                    break;
                case HSSFCell.CELL_TYPE_STRING:
                    value = cell.getStringCellValue().trim();
                    break;
                default:
                    value = "";
                    break;
            }
        }
        return value.trim();
    }
 
    @Autowired
    MaterialInfoService materialInfoService;
 
    @Autowired
    PassingStationCollectionService passingStationCollectionService;
 
    @Autowired
    LocationInfoService locationInfoService;
 
    /**
     * 大屏车间工单信息接口
     * @return
     */
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/topData")
    public ResponseData topData(ProductionOrdeInfoParam productionOrdeInfoParam) {
        Map map = new HashMap<String,String>();
        ProductionOrdeInfo result = null;
        //但前工单
        List<ProductionOrdeInfo> orderStatus = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", "3"));
        if(productionOrdeInfoParam.getWorkOrderNo() != null && !productionOrdeInfoParam.getWorkOrderNo().equals("")){
            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", productionOrdeInfoParam.getWorkOrderNo()));
            result = workOrderNo.get(0);
        }else if(orderStatus.size()!=0){
            result = orderStatus.get(0);
        }else {
            List<ProductionOrdeInfoResult> results = productionOrdeInfoService.orderDescListFive();
            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", results.get(0).getWorkOrderNo()));
            result = workOrderNo.get(0);
        }
        //产品
        List<MaterialInfo> materialCode = materialInfoService.list(new QueryWrapper<MaterialInfo>().eq("material_code", result.getMaterialCode()));
        Integer planQty = result.getPlanQty();
        Integer actualQty = result.getActualQty();
        Date date2 = new Date(); // 第二个日期
        long diffInMillis =result.getPlanEndTime().getTime() - date2.getTime(); //计算两个日期的毫秒差
        long diffInHours = diffInMillis / (60 * 60 * 1000); // 将毫秒差转换为小时差
        List<PassingStationCollection> list = passingStationCollectionService.list(new QueryWrapper<PassingStationCollection>()
                .eq("out_rs_sign", "2")
                .eq("work_order_no", result.getWorkOrderNo())
                .eq("location_code", "OP1060")
        );
        Integer NgNumber = list.size();
        map.put("workOrderNo",result.getWorkOrderNo());
        map.put("planQty",planQty);
        map.put("actualQty",actualQty);
        map.put("materialName",materialCode.get(0).getMaterialName());
        map.put("completionRate",Math.round((float) actualQty / planQty * 100));
        map.put("remainder",diffInHours);
        map.put("NgNumber",NgNumber);
        if(list.size() == 0){
            map.put("passRate","100");
        }else {
            map.put("passRate",Math.round((float) NgNumber / actualQty * 100));
        }
        return ResponseData.success(map);
    }
 
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/centerLeftData")
    public ResponseData centerLeftData(ProductionOrdeInfoParam productionOrdeInfoParam) {
        Map map = new HashMap<String,String>();
        List categoryList = new ArrayList();
        List lineDataList = new ArrayList();
        List barDataList = new ArrayList();
        List percentageList = new ArrayList();
        percentageList.add(0);
 
        ProductionOrdeInfo result = null;
        //但前工单
        List<ProductionOrdeInfo> orderStatus = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", "3"));
        if(productionOrdeInfoParam.getWorkOrderNo() != null && !productionOrdeInfoParam.getWorkOrderNo().equals("")){
            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", productionOrdeInfoParam.getWorkOrderNo()));
            result = workOrderNo.get(0);
        }else if(orderStatus.size()!=0){
            result = orderStatus.get(0);
        }else {
            List<ProductionOrdeInfoResult> results = productionOrdeInfoService.orderDescListFive();
            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", results.get(0).getWorkOrderNo()));
            result = workOrderNo.get(0);
        }
        List<PassingStationCollectionResult> resultList = passingStationCollectionService.centerLeftData(productionOrdeInfoParam.getWorkOrderNo());
        int unQuantity = passingStationCollectionService.getUnqualifiedQuantity(productionOrdeInfoParam.getWorkOrderNo());
        int variableInt = 0;
        if(unQuantity == 0){
            map.put("category",getLocationList());
            map.put("barData",getZeroList());
            map.put("percentage",getPercentageList());
 
        }else {
            for (int i = 0; i < resultList.size(); i++) {
                categoryList.add(resultList.get(i).getLocationCode());
                barDataList.add(resultList.get(i).getNum());
                variableInt+=Integer.valueOf(resultList.get(i).getNum());
                percentageList.add(Math.round((float) variableInt / unQuantity * 100));
            }
            map.put("category",categoryList);
            map.put("barData",barDataList);
            map.put("lineData",lineDataList);
            map.put("percentage",percentageList);
        }
        return ResponseData.success(map);
//        Map map = new HashMap<String,String>();
//        List categoryList = new ArrayList();
//        List lineDataList = new ArrayList();
//        List barDataList = new ArrayList();
//
//        ProductionOrdeInfo result = null;
//        //但前工单
//        List<ProductionOrdeInfo> orderStatus = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", "3"));
//        if(productionOrdeInfoParam.getWorkOrderNo() != null && !productionOrdeInfoParam.getWorkOrderNo().equals("")){
//            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", productionOrdeInfoParam.getWorkOrderNo()));
//            result = workOrderNo.get(0);
//        }else if(orderStatus.size()!=0){
//            result = orderStatus.get(0);
//        }else {
//            List<ProductionOrdeInfoResult> results = productionOrdeInfoService.orderDescListFive();
//            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", results.get(0).getWorkOrderNo()));
//            result = workOrderNo.get(0);
//        }
//        for (String o : getLocationList()) {
//            List<PassingStationCollection> list = passingStationCollectionService.list(new QueryWrapper<PassingStationCollection>()
//                    .eq("location_code", o)
//                    .eq("out_rs_sign", "2")
//                    .eq("work_order_no",result.getWorkOrderNo())
//            );
//            List<PassingStationCollection> lineList = passingStationCollectionService.list(new QueryWrapper<PassingStationCollection>()
//                    .eq("location_code", o)
//                    .eq("work_order_no",result.getWorkOrderNo())
//            );
//            categoryList.add(o);
//            barDataList.add(list.size());
//            lineDataList.add(lineList.size());
//        }
//        map.put("category",categoryList);
//        map.put("barData",barDataList);
//        map.put("lineData",lineDataList);
//
//        return ResponseData.success(map);
    }
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/bottomData")
    public ResponseData bottomData(ProductionOrdeInfoParam productionOrdeInfoParam) {
        Map map = new HashMap<String,String>();
        List unqualifiedList = new ArrayList();
        List qualifiedList = new ArrayList();
        List passRate = new ArrayList();
//        List<ProductionOrdeInfo> orderStatus = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", "3"));
//        ProductionOrdeInfo result = orderStatus.get(0);
        ProductionOrdeInfo result = null;
        //但前工单
        List<ProductionOrdeInfo> orderStatus = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", "3"));
        if(productionOrdeInfoParam.getWorkOrderNo() != null && !productionOrdeInfoParam.getWorkOrderNo().equals("")){
            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", productionOrdeInfoParam.getWorkOrderNo()));
            result = workOrderNo.get(0);
        }else if(orderStatus.size()!=0){
            result = orderStatus.get(0);
        }else {
            List<ProductionOrdeInfoResult> results = productionOrdeInfoService.orderDescListFive();
            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", results.get(0).getWorkOrderNo()));
            result = workOrderNo.get(0);
        }
        for (String o : getLocationList()) {
            List<PassingStationCollection> list = passingStationCollectionService.list(new QueryWrapper<PassingStationCollection>()
                    .eq("location_code", o)
                    .eq("out_rs_sign", "2")
                    .eq("work_order_no",result.getWorkOrderNo())
            );
            List<PassingStationCollection> list1 = passingStationCollectionService.list(new QueryWrapper<PassingStationCollection>()
                    .eq("location_code", o)
                    .eq("work_order_no",result.getWorkOrderNo())
            );
            Integer unqualified = list.size();
            Integer qualified = list1.size()-list.size();
            unqualifiedList.add(unqualified);
            qualifiedList.add(qualified);
            if(unqualified == 0){
                passRate.add(100);
            }else {
                passRate.add(Math.round((float) qualified / result.getActualQty() * 100));
            }
        }
        map.put("unqualifiedList",unqualifiedList);
        map.put("qualifiedList",qualifiedList);
        map.put("passRate",passRate);
        return ResponseData.success(map);
    }
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/centerRightData")
    public ResponseData centerRightData(ProductionOrdeInfoParam productionOrdeInfoParam) {
//        List<ProductionOrdeInfo> orderStatus = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", "3"));
//        ProductionOrdeInfo result = orderStatus.get(0);
        ProductionOrdeInfo result = null;
        //但前工单
        List<ProductionOrdeInfo> orderStatus = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", "3"));
        if(productionOrdeInfoParam.getWorkOrderNo() != null && !productionOrdeInfoParam.getWorkOrderNo().equals("")){
            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", productionOrdeInfoParam.getWorkOrderNo()));
            result = workOrderNo.get(0);
        }else if(orderStatus.size()!=0){
            result = orderStatus.get(0);
        }else {
            List<ProductionOrdeInfoResult> results = productionOrdeInfoService.orderDescListFive();
            List<ProductionOrdeInfo> workOrderNo = productionOrdeInfoService.list(new QueryWrapper<ProductionOrdeInfo>().eq("work_order_no", results.get(0).getWorkOrderNo()));
            result = workOrderNo.get(0);
        }
        Integer targetNumber = 70;
        List resultList = new ArrayList();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String format1 = format.format(new Date());
        String paramPrefix = format1+" ";
        for (String s : getCenterRightSpit()) {
            List itemList = new ArrayList();
            int outTotal = passingStationCollectionService.bigCenterRightTable(paramPrefix+s+":00",paramPrefix+s.substring(0,1)+":59:59",null,result.getWorkOrderNo());
            int i = passingStationCollectionService.bigCenterRightTable(paramPrefix+s+":00",paramPrefix+s.substring(0,1)+":59:59","1",result.getWorkOrderNo());
            if(outTotal<targetNumber){
                itemList.add(boldText(s));
                itemList.add(boldText(targetNumber.toString()));
                itemList.add(boldText(String.valueOf(outTotal)));
                itemList.add(boldText(String.valueOf(targetNumber-outTotal)));
                itemList.add(boldText(Math.round((float) i / outTotal * 100)+"%"));
            }else {
                itemList.add(s);
                itemList.add(targetNumber);
                itemList.add(outTotal);
                itemList.add(targetNumber-outTotal);
                itemList.add(Math.round((float) i / outTotal * 100)+"%");
            }
           resultList.add(itemList);
        }
        return ResponseData.success(resultList);
    }
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/orderDescListFive")
    public ResponseData orderDescListFive() {
        List list = new ArrayList();
        List<ProductionOrdeInfoResult> results = productionOrdeInfoService.orderDescListFive();
        for (ProductionOrdeInfoResult result : results) {
            Map itemMap = new HashMap();
            itemMap.put("value",result.getWorkOrderNo());
            itemMap.put("label",result.getWorkOrderNo());
            list.add(itemMap);
        }
        return ResponseData.success(list);
    }
 
    public static List<String> getLocationList(){
        List<String> locationList = new ArrayList<>();
        locationList.add("OP070");
        locationList.add("OP100");
        locationList.add("OP140");
        locationList.add("OP150");
        locationList.add("EOP080");
        locationList.add("EOP090");
        return locationList;
    }
 
    public static List<String> getZeroList(){
        List<String> locationList = new ArrayList<>();
        locationList.add("0");
        locationList.add("0");
        locationList.add("0");
        locationList.add("0");
        locationList.add("0");
        locationList.add("0");
        return locationList;
    }
 
    public static List<String> getPercentageList(){
        List<String> locationList = new ArrayList<>();
        locationList.add("100");
        locationList.add("100");
        locationList.add("100");
        locationList.add("100");
        locationList.add("100");
        locationList.add("100");
        return locationList;
    }
 
 
    public static List<String> getCenterRightSpit(){
        List<String> locationList = new ArrayList<>();
        locationList.add("8:00");
        locationList.add("9:00");
        locationList.add("10:00");
        locationList.add("11:00");
        locationList.add("12:00");
        locationList.add("13:00");
        locationList.add("14:00");
        locationList.add("15:00");
        locationList.add("16:00");
        locationList.add("17:00");
        return locationList;
    }
 
    public static String boldText(String param){
        return "<span style='font-size: 20px' class='colorRed'>"+param+"</span>";
    }
 
}