jiazx0107@163.com
2023-06-23 7b5c179e17c9a106dcce3b2b0574af833cf97132
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
package com.ld.igds.inout.manager;
 
import com.bstek.bdf2.core.model.DefaultDept;
import com.ld.igds.check.dto.CheckItemData;
import com.ld.igds.check.service.CoreCheckStandardService;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.constant.FoodVariety;
import com.ld.igds.inout.InoutBill;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.inout.dto.InoutData;
import com.ld.igds.inout.dto.InoutRecordItemData;
import com.ld.igds.inout.dto.InoutRecordItemParam;
import com.ld.igds.inout.dto.WeightBill;
import com.ld.igds.inout.service.InoutRecordItemService;
import com.ld.igds.m.dto.NoticeDto;
import com.ld.igds.m.service.HInoutNoticeService;
import com.ld.igds.models.Depot;
import com.ld.igds.models.InoutSettle;
import com.ld.igds.sys.service.SysDeptService;
import com.ld.igds.util.MoneyUtil;
import com.ld.igds.util.NumberUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
 
@Component
public class InoutReportManager {
 
    @Autowired
    private CoreCommonService commonService;
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private CoreCheckStandardService checkStandardService;
    @Autowired
    private InoutRecordItemService inoutRecordItemService;
    @Autowired
    private HInoutNoticeService noticeService;
 
    /**
     * 获取入库过磅单数据信息
     *
     * @param data
     * @return
     */
    public String inWeightBill(InoutData data) {
 
        // 获取表单数据
        WeightBill bill = this.createBillData(data, "入库划码单");
 
        // 调整模版数据并返回
        String htmlStr = InoutBill.IN_WEIGHT_DEFAULT;
 
        // 义乌专用
        if ("5013".equals(data.getCompanyId())) {
            htmlStr = InoutBill.IN_WEIGHT_5013;
        }
 
        // 大湾区专用
        if ("5016".equals(data.getCompanyId())) {
            htmlStr = InoutBill.IN_WEIGHT_5016;
        }
 
        // 上海嘉定使用
        if ("5303".equals(data.getCompanyId())) {
            htmlStr = InoutBill.IN_WEIGHT_5303;
        }
 
        // 青神县粮库使用
        if ("5308".equals(data.getCompanyId())) {
            htmlStr = InoutBill.IN_WEIGHT_5308;
        }
 
        // 潮阳储备库使用
        if ("5317".equals(data.getCompanyId())) {
            htmlStr = InoutBill.IN_WEIGHT_5317;
        }
 
        // 徐闻储备库使用
        if ("5322".equals(data.getCompanyId())) {
            htmlStr = InoutBill.IN_WEIGHT_5322;
        }
 
        htmlStr = htmlStr.replace("billTitle", bill.getBillTitle());
 
        htmlStr = htmlStr.replace("registerTime", bill.getRegisterTime());
        htmlStr = htmlStr.replace("completeTime", bill.getCompleteTime());
        htmlStr = htmlStr.replace("fullTime", bill.getFullTime());
        htmlStr = htmlStr.replace("emptyTime", bill.getEmptyTime());
        htmlStr = htmlStr.replace("serId", bill.getSerId());
        htmlStr = htmlStr.replace("specType", bill.getSpecType());
 
        htmlStr = htmlStr.replace("customerName", bill.getCustomerName());
        htmlStr = htmlStr.replace("deptName", bill.getUnitName());
 
        htmlStr = htmlStr.replace("driverName", bill.getDriverName());
        htmlStr = htmlStr.replace("userNumberId", bill.getUserId());
        htmlStr = htmlStr.replace("userContact", bill.getUserContact());
        htmlStr = htmlStr.replace("userAddress", bill.getUserAddress());
        htmlStr = htmlStr.replace("foodVariety", bill.getFoodVariety());
        htmlStr = htmlStr.replace("depotName", bill.getDepotName());
        htmlStr = htmlStr.replace("foodLocation", bill.getFoodLocation());
 
        htmlStr = htmlStr.replace("plateNum", bill.getPlateNum());
        htmlStr = htmlStr.replace("fullWeight",
                new DecimalFormat("0").format(bill.getFullWeight()));
        htmlStr = htmlStr.replace("emptyWeight",
                new DecimalFormat("0").format(bill.getEmptyWeight()));
        htmlStr = htmlStr.replace("netWeight",
                new DecimalFormat("0").format(bill.getNetWeight()));
 
        htmlStr = htmlStr.replace("deImpurity", bill.getDeImpurity() + "");
        htmlStr = htmlStr.replace("deWet", bill.getDeWet() + "");
        htmlStr = htmlStr.replace("deSum", bill.getDeSum() + "");
        htmlStr = htmlStr.replace("settleWeight",
                new DecimalFormat("0").format(bill.getSettleWeight()));
 
        htmlStr = htmlStr.replace("deHandle", bill.getDeHandle() + "");
        htmlStr = htmlStr.replace("deOther", bill.getDeOther() + "");
        htmlStr = htmlStr.replace("price", bill.getPrice());
        htmlStr = htmlStr.replace("settleMoney", bill.getSettleMoney() + "");
        htmlStr = htmlStr.replace("wet", bill.getWet() + "");
        htmlStr = htmlStr.replace("impurity", bill.getImpurity() + "");
 
        htmlStr = htmlStr.replace("remark", bill.getRemark());
        htmlStr = htmlStr.replace("moneyName", bill.getMoneyName());
 
        htmlStr = htmlStr.replace("handleUser", bill.getHandleUser());
 
        return htmlStr;
    }
 
    /**
     * 获取出库过磅单
     *
     * @param data
     * @return
     */
    public String outWeightBill(InoutData data) {
        // 获取表单数据
        WeightBill bill = this.createBillData(data, "出库称重单");
 
        //默认模版
        String htmlStr = InoutBill.OUT_WEIGHT_DEFAULT;
 
        // 义乌专用
        if ("5013".equals(data.getCompanyId())) {
            htmlStr = InoutBill.OUT_WEIGHT_5013;
        }
 
        // 大湾区专用
        if ("5016".equals(data.getCompanyId())) {
            htmlStr = InoutBill.OUT_WEIGHT_5016;
        }
 
        // 上海嘉定粮库使用
        if ("5303".equals(data.getCompanyId())) {
            htmlStr = InoutBill.OUT_WEIGHT_5303;
        }
 
        // 青神县粮库使用
        if ("5308".equals(data.getCompanyId())) {
            htmlStr = InoutBill.OUT_WEIGHT_5308;
        }
 
        // 潮阳储备库使用
        if ("5317".equals(data.getCompanyId())) {
            htmlStr = InoutBill.OUT_WEIGHT_5317;
        }
 
        // 徐闻储备库使用
        if ("5322".equals(data.getCompanyId())) {
            htmlStr = InoutBill.OUT_WEIGHT_5322;
        }
 
        htmlStr = htmlStr.replace("billTitle", bill.getBillTitle());
 
        htmlStr = htmlStr.replace("registerTime", bill.getRegisterTime());
        htmlStr = htmlStr.replace("completeTime", bill.getCompleteTime());
        htmlStr = htmlStr.replace("fullTime", bill.getFullTime());
        htmlStr = htmlStr.replace("emptyTime", bill.getEmptyTime());
        htmlStr = htmlStr.replace("serId", bill.getSerId());
        htmlStr = htmlStr.replace("specType", bill.getSpecType());
 
        htmlStr = htmlStr.replace("customerName", bill.getCustomerName());
        htmlStr = htmlStr.replace("deptName", bill.getUnitName());
 
        htmlStr = htmlStr.replace("driverName", bill.getDriverName());
        htmlStr = htmlStr.replace("userNumberId", bill.getUserId());
        htmlStr = htmlStr.replace("userContact", bill.getUserContact());
        htmlStr = htmlStr.replace("userAddress", bill.getUserAddress());
        htmlStr = htmlStr.replace("foodVariety", bill.getFoodVariety());
        htmlStr = htmlStr.replace("depotName", bill.getDepotName());
        htmlStr = htmlStr.replace("foodLocation", bill.getFoodLocation());
 
        htmlStr = htmlStr.replace("plateNum", bill.getPlateNum());
        htmlStr = htmlStr.replace("fullWeight",
                new DecimalFormat("0").format(bill.getFullWeight()));
        htmlStr = htmlStr.replace("emptyWeight",
                new DecimalFormat("0").format(bill.getEmptyWeight()));
        htmlStr = htmlStr.replace("netWeight",
                new DecimalFormat("0").format(bill.getNetWeight()));
 
        htmlStr = htmlStr.replace("remark", bill.getRemark());
        htmlStr = htmlStr.replace("deWet", bill.getDeWet() + "");
        htmlStr = htmlStr.replace("settleWeight",
                new DecimalFormat("0").format(bill.getSettleWeight()));
 
        htmlStr = htmlStr.replace("handleUser", bill.getHandleUser());
        htmlStr = htmlStr.replace("deSum", bill.getDeSum() + "");
 
        htmlStr = htmlStr.replace("price", bill.getPrice());
        htmlStr = htmlStr.replace("settleMoney", bill.getSettleMoney() + "");
        htmlStr = htmlStr.replace("wet", bill.getWet() + "");
        htmlStr = htmlStr.replace("impurity", bill.getImpurity() + "");
 
        return htmlStr;
    }
 
    /**
     * 封装过磅单数据
     *
     * @param data
     * @param billTitle
     * @return
     */
    private WeightBill createBillData(InoutData data, String billTitle) {
        WeightBill bill = new WeightBill();
 
        if ("5016".equals(data.getCompanyId())) {
            billTitle = "称重计量单";
        }
        DefaultDept dept = sysDeptService.getCacheDept(data.getCompanyId(),
                data.getDeptId());
        if (null != dept && StringUtils.isNotEmpty(dept.getName())) {
            billTitle = dept.getName() + billTitle;
            bill.setDeptId(dept.getId());
            bill.setUnitName(dept.getName());
        }
        bill.setBillTitle(billTitle);
        bill.setCompanyId(data.getCompanyId() == null ? "" : data
                .getCompanyId());
        if (null == data.getRegisterTime()) {
            data.setRegisterTime(new Date());
        }
        bill.setRegisterTime(DateFormatUtils.format(data.getRegisterTime(),
                "yyyy-MM-dd HH:mm"));
 
        if (null == data.getCompleteTime()) {
            data.setCompleteTime(new Date());
        }
        bill.setCompleteTime(DateFormatUtils.format(data.getCompleteTime(),
                "yyyy-MM-dd HH:mm"));
        bill.setEmptyTime(DateFormatUtils.format(data.getEmptyWeightTime(),
                "yyyy-MM-dd HH:mm:ss"));
        bill.setFullTime(DateFormatUtils.format(data.getFullWeightTime(),
                "yyyy-MM-dd HH:mm:ss"));
        bill.setSerId(data.getId());
//        bill.setSpecType(StringUtils.isEmpty(data.getSpecType())?"散粮":data.getSpecType());
        if ("5016".equals(data.getCompanyId())) {
            bill.setCompleteTime(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
            bill.setSerId(data.getId().substring(2));
 
        }
 
        //客户信息
       // bill.setCustomerId(data.getCustomerId() == null ? "" : data.getCustomerId());
        bill.setCustomerName(data.getCustomerName() == null ? "" : data.getCustomerName());
        bill.setUserId(data.getUserId() == null ? "" : data.getUserId());
        bill.setUserAddress(data.getUserAddress() == null ? "" : data.getUserAddress());
        bill.setUserContact(data.getUserContact() == null ? "" : data.getUserContact());
 
        //从通知单中获取收发货单位信息
        NoticeDto noticeDto = noticeService.queryNoticeById(data.getNoticeId(), data.getType());
        if(null != noticeDto && StringUtils.isNotEmpty(noticeDto.getUnitName())){
            bill.setUnitName(noticeDto.getUnitName());
        }
 
        bill.setDriverName(data.getUserName() == null ? "" : data.getUserName());
 
        // 获取仓库信息
        Depot depot = commonService.getCacheDepot(data.getCompanyId(),
                data.getDepotId());
        if (depot != null) {
            bill.setDepotName(depot.getName() == null ? "" : depot.getName());
            bill.setHandleUser(depot.getStoreKeeperName() == null ? "" : depot
                    .getStoreKeeperName());
        }
 
        bill.setFoodVariety(FoodVariety.getMsg(data.getFoodVariety()));
        bill.setFoodLocation(data.getFoodLocation() == null ? "" : data
                .getFoodLocation());
        bill.setPlateNum(data.getPlateNum());
 
        bill.setFullWeight(data.getFullWeight());
        bill.setEmptyWeight(data.getEmptyWeight());
        bill.setNetWeight(data.getNetWeight());
 
//        bill.setDeWet(data.getDeWet());
//        bill.setDeImpurity(data.getDeImpurity());
//        bill.setDeHandle(data.getDeHandle());
//        bill.setDeOther(data.getDeOther());
//        bill.setDeSum(data.getDeSum() == null ? 0.0 :data.getDeSum());
 
        bill.setSettleWeight(data.getSettleWeight());
//        if(data.getWet() != null && data.getWet() > 0){
//            bill.setWet(data.getWet() +"");
//        }
//        if(data.getImpurity() != null && data.getImpurity() > 0){
//            bill.setImpurity(data.getImpurity()+"");
//        }
 
        bill.setPrice(data.getPrice()== null ? "" :data.getPrice() + "");
        if(data.getSettleMoney() <= 0){
            if(null != data.getPrice() && null != data.getRecordWeight()){
                data.setSettleMoney(NumberUtil.keepPrecision(data.getPrice()*data.getRecordWeight(),2));
            }
        }
        bill.setSettleMoney(data.getSettleMoney()== null ? "" :data.getSettleMoney()+"");
        bill.setRemark(data.getRemarks() == null ? "" : data.getRemarks());
 
        return bill;
    }
 
    /**
     * 获取入库验检单
     *
     * @param data
     * @return
     */
    public String inCheckBill(InoutData data) {
 
        // 获取化验数据
        List<CheckItemData> checkLst = data.getCheckItems();
        if (null == checkLst)
            checkStandardService.getCheckItemById(data.getCheckId(),
                    data.getCompanyId());
 
        if (checkLst == null || checkLst.size() < 1) {
            return "无化验数据,不打印!";
        }
 
        // 调整模版数据并返回
        String htmlStr = InoutBill.IN_CHECK_DEFAULT;
 
        DefaultDept dept = sysDeptService.getCacheDept(data.getCompanyId(),
                data.getDeptId());
 
        htmlStr = htmlStr.replace("billTitle",
                (dept == null ? "入库化验单" : dept.getName() + "入库化验单"));
 
        // 替换基础数据
        String time = DateFormatUtils.format(data.getRegisterTime(),
                "yyyy-MM-dd");
        htmlStr = htmlStr.replace("time", time);
        htmlStr = htmlStr.replace("customerName", data.getCustomerName());
        htmlStr = htmlStr.replace("serId", data.getId());
        htmlStr = htmlStr.replace("foodVariety", FoodVariety.getMsg(data.getFoodVariety()));
        htmlStr = htmlStr.replace("plateNum", data.getPlateNum());
        htmlStr = htmlStr.replace("userName", data.getUserName());
        htmlStr = htmlStr.replace("foodYear", data.getFoodYear() == null ? "/" : data.getFoodYear());
        Depot depot = commonService.getCacheDepot(data.getCompanyId(), data.getDepotId());
        htmlStr = htmlStr.replace("depotName", depot == null ? "/" : depot.getName());
        htmlStr = htmlStr.replace("checkUser", data.getCheckUser() == null ? "/" : data.getCheckUser());
 
        Map<String, String> checkBillItems = getCheckBillItems();
        // 遍历化验结果,存入map集合中
        String key;
        for (CheckItemData item : checkLst) {
            key = item.getStandardId() + "_ST";
           // checkBillItems.put(key, item.getStandardValue());
            key = item.getStandardId() + "_VAL";
            checkBillItems.put(key, item.getValue());
        }
 
        // 遍历map集合,替换化验单中化验值
        String value;
        for (String str : checkBillItems.keySet()) {
            value = checkBillItems.get(str);
            if (StringUtils.isNotEmpty(value)) {
                htmlStr = htmlStr.replace(str, value);
            } else {
                htmlStr = htmlStr.replace(str, "-");
            }
        }
 
        return htmlStr;
    }
 
    /**
     * 封装化验项
     *
     * @return
     */
    private Map<String, String> getCheckBillItems() {
        Map<String, String> map = new HashMap<>();
        map.put("C03_ST", "");
        map.put("C03_VAL", "");
        map.put("C01_ST", "");
        map.put("C01_VAL", "");
        map.put("C02_ST", "");
        map.put("C02_VAL", "");
        map.put("C09_ST", "");
        map.put("C09_VAL", "");
        map.put("C22_ST", "");
        map.put("C22_VAL", "");
        map.put("C23_ST", "");
        map.put("C23_VAL", "");
        map.put("C10_ST", "");
        map.put("C10_VAL", "");
        map.put("C04_ST", "");
        map.put("C04_VAL", "");
        map.put("C24_ST", "");
        map.put("C24_VAL", "");
        map.put("C08_ST", "");
        map.put("C08_VAL", "");
        map.put("C12_ST", "");
        map.put("C12_VAL", "");
        map.put("C25_ST", "");
        map.put("C25_VAL", "");
        map.put("C14_ST", "");
        map.put("C14_VAL", "");
        map.put("C29_ST", "");
        map.put("C29_VAL", "");
        map.put("C11_ST", "");
        map.put("C11_VAL", "");
        map.put("C27_ST", "");
        map.put("C27_VAL", "");
        map.put("C28_ST", "");
        map.put("C28_VAL", "");
        map.put("C30_ST", "");
        map.put("C30_VAL", "");
        map.put("C31_ST", "");
        map.put("C31_VAL", "");
        return map;
    }
 
    /**
     * 获取入库结算单
     *
     * @param data
     * @return
     */
    public String inSettleBill(InoutData data, InoutSettle settle) {
 
        if (null != data) {
          //  settle.setCompleteTime(data.getCompleteTime());
            settle.setDepotId(data.getDepotId());
            settle.setDeptId(data.getDeptId());
//            settle.setUserName(data.getUserName());
//            settle.setPlateNum(data.getPlateNum());
//            settle.setFoodLevel(data.getFoodLevel());
//            settle.setFoodVariety(data.getFoodVariety());
        }
 
        // 调整模版数据并返回
        String htmlStr = InoutBill.IN_SETTLE_DEFAULT;
 
        DefaultDept dept = sysDeptService.getCacheDept(settle.getCompanyId(),
                settle.getDeptId());
 
        htmlStr = htmlStr.replace("billTitle",
                (dept == null ? "入库结算单" : dept.getName() + "入库结算单"));
 
        String time = DateFormatUtils.format(
                settle.getPayTime() == null ? new Date() : settle.getPayTime(),
                "yyyy-MM-dd HH:mm");
        htmlStr = htmlStr.replace("payTime", time);
        htmlStr = htmlStr.replace("serId", settle.getId());
 
//        htmlStr = htmlStr.replace(
//                "customerName",
//                settle.getCustomerName() == null ? "" : settle
//                        .getCustomerName());
        htmlStr = htmlStr.replace("deptName",
                dept == null ? "" : dept.getName());
 
        htmlStr = htmlStr.replace("bank", settle.getBank() == null ? ""
                : settle.getBank());
//        htmlStr = htmlStr.replace("fullWeight",
//                new DecimalFormat("0").format(settle.getFullWeight()));
//        htmlStr = htmlStr.replace("emptyWeight",
//                new DecimalFormat("0").format(settle.getEmptyWeight()));
 
        htmlStr = htmlStr.replace("banNum", settle.getBankNum() == null ? ""
                : settle.getBankNum());
//        htmlStr = htmlStr.replace("netWeight",
//                new DecimalFormat("0").format(settle.getNetWeight()));
//        htmlStr = htmlStr.replace("deSum",
//                new DecimalFormat("0").format(settle.getDeSum()));
 
        // 获取仓库信息
        Depot depot = commonService.getCacheDepot(settle.getCompanyId(),
                settle.getDepotId());
 
        htmlStr = htmlStr.replace("depotName",
                depot == null ? "" : depot.getName());
//        htmlStr = htmlStr.replace("foodVariety",
//                FoodVariety.getMsg(settle.getFoodVariety()));
        htmlStr = htmlStr.replace("payPrice", settle.getPayPrice() + "");
        htmlStr = htmlStr.replace("settleWeight",
                new DecimalFormat("0").format(settle.getSettleWeight()));
 
        if (null == depot) {
            htmlStr = htmlStr.replace("keeperName", "");
        } else {
            htmlStr = htmlStr.replace(
                    "keeperName",
                    depot.getStoreKeeperName() == null ? "" : depot
                            .getStoreKeeperName());
        }
//        htmlStr = htmlStr.replace("driverName", settle.getUserName() + "");
//        htmlStr = htmlStr.replace("otherSum", settle.getOtherSum() + "");
        htmlStr = htmlStr.replace("paySum", settle.getPaySum() + "");
 
        htmlStr = htmlStr.replace("remark", settle.getRemarks() == null ? ""
                : settle.getRemarks());
        htmlStr = htmlStr.replace("moneyName",
                MoneyUtil.formatToCN(new BigDecimal(settle.getPaySum())));
 
        return htmlStr;
    }
 
    /**
     * 获取船运过磅单数据信息
     *
     * @param data
     * @return
     */
    public String shipWeightBill(InoutData data) {
 
        //获取船运子表信息
        InoutRecordItemParam param = new InoutRecordItemParam();
        param.setRecordId(data.getId());
        param.setType(data.getType());
        List<InoutRecordItemData> list = inoutRecordItemService.listInoutItem(param);
        if (null == list || list.isEmpty()) {
            return "未获取到船运车辆信息,不打印!";
        }
 
        //调整模版数据并返回
        String htmlStr = InoutBill.SHIP_WEIGHT_DEFAULT;
 
        DefaultDept dept = sysDeptService.getCacheDept(data.getCompanyId(), data.getDeptId());
 
        htmlStr = htmlStr.replace("billTitle", (dept == null ? "船运过磅单" : dept.getName() + "船运过磅单"));
 
        htmlStr = htmlStr.replace("registerTime", data.getRegisterTime() == null ? "" : DateFormatUtils.format(data.getRegisterTime(), "yyyy-MM-dd HH:mm"));
        htmlStr = htmlStr.replace("completeTime", data.getCompleteTime() == null ? "" : DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd HH:mm"));
        htmlStr = htmlStr.replace("serId", data.getId());
 
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            htmlStr = htmlStr.replace("customerName", data.getCustomerName());
            htmlStr = htmlStr.replace("deptName", dept.getName());
        }
        if (InoutConstant.TYPE_OUT.equals(data.getType())) {
            htmlStr = htmlStr.replace("customerName", dept.getName());
            htmlStr = htmlStr.replace("deptName", data.getCustomerName());
        }
 
        htmlStr = htmlStr.replace("plateNum", data.getPlateNum());
        // 获取仓库信息
        Depot depot = commonService.getCacheDepot(data.getCompanyId(), data.getDepotId());
        htmlStr = htmlStr.replace("depotName", depot == null ? "" : depot.getName());
        htmlStr = htmlStr.replace("handleUser", depot == null ? "" : (depot.getStoreKeeperName() == null ? "" : depot.getStoreKeeperName()));
        htmlStr = htmlStr.replace("foodVariety", FoodVariety.getMsg(data.getFoodVariety()));
        htmlStr = htmlStr.replace("foodLocation", StringUtils.isEmpty(data.getFoodLocation()) ? "" : data.getFoodLocation());
 
        for (int i = 30; i >= 1; i--) {
 
            if (i <= list.size()) {
                htmlStr = htmlStr.replace("carNum" + i, list.get(i - 1).getCarNum());
                htmlStr = htmlStr.replace("full" + i, new DecimalFormat("0").format(list.get(i - 1).getFullWeight()));
                htmlStr = htmlStr.replace("empty" + i, new DecimalFormat("0").format(list.get(i - 1).getEmptyWeight()));
                htmlStr = htmlStr.replace("number" + i, new DecimalFormat("0").format(list.get(i - 1).getSettleWeight()));
            } else {
                htmlStr = htmlStr.replace("carNum" + i, "");
                htmlStr = htmlStr.replace("full" + i, "");
                htmlStr = htmlStr.replace("empty" + i, "");
                htmlStr = htmlStr.replace("number" + i, "");
            }
        }
 
        htmlStr = htmlStr.replace("remarks", data.getRemarks() == null ? "" : data.getRemarks());
        htmlStr = htmlStr.replace("fullWeight", new DecimalFormat("0").format(data.getFullWeight()));
        htmlStr = htmlStr.replace("emptyWeight", new DecimalFormat("0").format(data.getEmptyWeight()));
        htmlStr = htmlStr.replace("settleWeight", new DecimalFormat("0").format(data.getSettleWeight()));
 
        return htmlStr;
    }
 
    /**
     * 获取船运过磅单数据信息
     *
     * @param data
     * @return
     */
    public List<String> shipWeightBill2(InoutData data) {
 
        //获取船运子表信息
        InoutRecordItemParam param = new InoutRecordItemParam();
        param.setRecordId(data.getId());
        param.setType(data.getType());
        List<InoutRecordItemData> list = inoutRecordItemService.listInoutItem(param);
        List<String> result = new ArrayList<>();
        if (null == list || list.isEmpty()) {
            result.add("未获取到船运车辆信息,不打印!");
            return result;
        }
 
        String htmlStr;
        if(list.size() <= 30){
            //只有一页时
            htmlStr = getShipBill(data, list, true,0);
            result.add(htmlStr);
        }else {
            //有多页时
            int page = list.size()/30 + 1;
            for (int i = 1; i <= page; i++) {
                if(i == page){
                    htmlStr = getShipBill(data, list.subList((i-1)*30, list.size()),true, i);
                }else {
                    htmlStr = getShipBill(data, list.subList((i-1)*30, i*30),false, i);
                }
                result.add(htmlStr);
            }
        }
 
        return result;
    }
 
    /**
     * 获取船运打印模板数据
     * @param data    流水信息
     * @param list    车辆信息,数量不大于30
     * @param moreTag 结算标签,true-代表结算页;false-不是结算页
     * @param pageNum 页码
     * @return
     */
    public String getShipBill(InoutData data, List<InoutRecordItemData> list, boolean moreTag, int pageNum) {
 
        //调整模版数据并返回
        String htmlStr = InoutBill.SHIP_WEIGHT_DEFAULT_MORE;
        if(moreTag){
            htmlStr = InoutBill.SHIP_WEIGHT_DEFAULT;
        }
 
        DefaultDept dept = sysDeptService.getCacheDept(data.getCompanyId(), data.getDeptId());
 
        //表头
        String billTitle = (dept == null ? "船运过磅单" : dept.getName() + "船运过磅单");
        if(0 != pageNum){
            billTitle += " - 第" + pageNum + "页";
        }
        htmlStr = htmlStr.replace("billTitle", billTitle);
 
        htmlStr = htmlStr.replace("registerTime", data.getRegisterTime() == null ? "" : DateFormatUtils.format(data.getRegisterTime(), "yyyy-MM-dd HH:mm"));
        htmlStr = htmlStr.replace("completeTime", data.getCompleteTime() == null ? "" : DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd HH:mm"));
        htmlStr = htmlStr.replace("serId", data.getId());
 
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            htmlStr = htmlStr.replace("customerName", data.getCustomerName());
            htmlStr = htmlStr.replace("deptName", dept.getName());
        }
        if (InoutConstant.TYPE_OUT.equals(data.getType())) {
            htmlStr = htmlStr.replace("customerName", dept.getName());
            htmlStr = htmlStr.replace("deptName", data.getCustomerName());
        }
 
        htmlStr = htmlStr.replace("plateNum", data.getPlateNum());
        // 获取仓库信息
        Depot depot = commonService.getCacheDepot(data.getCompanyId(), data.getDepotId());
        htmlStr = htmlStr.replace("depotName", depot == null ? "" : depot.getName());
        htmlStr = htmlStr.replace("foodVariety", FoodVariety.getMsg(data.getFoodVariety()));
        htmlStr = htmlStr.replace("foodLocation", StringUtils.isEmpty(data.getFoodLocation()) ? "" : data.getFoodLocation());
 
        //必须倒序
        for (int i = 30; i >= 1; i--) {
            if (i <= list.size()) {
                htmlStr = htmlStr.replace("carNum" + i, list.get(i - 1).getCarNum());
                htmlStr = htmlStr.replace("full" + i, new DecimalFormat("0").format(list.get(i - 1).getFullWeight()));
                htmlStr = htmlStr.replace("empty" + i, new DecimalFormat("0").format(list.get(i - 1).getEmptyWeight()));
                htmlStr = htmlStr.replace("number" + i, new DecimalFormat("0").format(list.get(i - 1).getSettleWeight()));
            } else {
                htmlStr = htmlStr.replace("carNum" + i, "");
                htmlStr = htmlStr.replace("full" + i, "");
                htmlStr = htmlStr.replace("empty" + i, "");
                htmlStr = htmlStr.replace("number" + i, "");
            }
        }
 
        //添加结算信息
        if(moreTag){
            htmlStr = htmlStr.replace("handleUser", depot == null ? "" : (depot.getStoreKeeperName() == null ? "" : depot.getStoreKeeperName()));
            htmlStr = htmlStr.replace("remarks", data.getRemarks() == null ? "" : data.getRemarks());
            htmlStr = htmlStr.replace("fullWeight", new DecimalFormat("0").format(data.getFullWeight()));
            htmlStr = htmlStr.replace("emptyWeight", new DecimalFormat("0").format(data.getEmptyWeight()));
            htmlStr = htmlStr.replace("settleWeight", new DecimalFormat("0").format(data.getSettleWeight()));
        }
 
        return htmlStr;
    }
 
    public static void main(String[] args) {
        List<String> result = new ArrayList<>();
        result.add("1");
        result.add("2");
        result.add("3");
        result.add("4");
        result.add("5");
        result.add("6");
        result.add("7");
        result.add("8");
        System.out.println(result);
        List<String> strings1 = result.subList(0, 3);
        System.out.println(strings1);
        List<String> strings2 = result.subList(3, 6);
        System.out.println(strings2);
        List<String> strings3 = result.subList(6, 8);
        System.out.println(strings3);
    }
}