jiangping
2025-06-06 c5109dd484be07f6c49a3c4c4df7ae79b89f4fb0
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
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
package com.doumee.service.business.impl;
 
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.excel.ExcelReplaceCommon;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.*;
import com.doumee.dao.business.dto.YwSmsEmailBillCallDTO;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.vo.YwContractBillCallDataVO;
import com.doumee.dao.business.vo.YwContractBillDataVO;
import com.doumee.dao.system.MultifileMapper;
import com.doumee.dao.system.model.Multifile;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.YwContractBillService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 运维合同账单信息表Service实现
 * @author 江蹄蹄
 * @date 2024/11/19 16:07
 */
@Service
public class YwContractBillServiceImpl implements YwContractBillService {
 
    @Autowired
    private YwContractBillMapper ywContractBillMapper;
 
    @Autowired
    private YwContractRoomMapper ywContractRoomMapper;
 
    @Autowired
    private MultifileMapper multifileMapper;
 
    @Autowired
    private YwContractRevenueMapper ywContractRevenueMapper;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Autowired
    private YwContractMapper ywContractMapper;
 
    @Autowired
    private YwAccountMapper ywAccountMapper;
 
    @Autowired
    private MemberMapper memberMapper;
 
    @Autowired
    private YwTempConfigMapper ywTempConfigMapper;
 
 
    @Value("${zip_file_path}")
    private String zipFilePath;
 
    @Override
    public Integer create(YwContractBill ywContractBill) {
        if(Objects.isNull(ywContractBill)
                || Objects.isNull(ywContractBill.getContractId())
                || Objects.isNull(ywContractBill.getTotleFee())
                || Objects.isNull(ywContractBill.getPlanPayDate())
                || Objects.isNull(ywContractBill.getCostType())
                || Objects.isNull(ywContractBill.getBillType())
                || Objects.isNull(ywContractBill.getCompanyId())
                || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywContractBill.getYwContractRoomList())
                || Objects.isNull(ywContractBill.getFeeType())
                || (Constants.equalsInteger(ywContractBill.getFeeType(),Constants.ZERO)&& (Objects.isNull(ywContractBill.getStartDate())
                || Objects.isNull(ywContractBill.getEndDate())))
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        YwContract ywContract = ywContractMapper.selectById(ywContractBill.getContractId());
        if(Objects.isNull(ywContract)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(Constants.equalsInteger(ywContract.getStatus(),Constants.THREE)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"合同状态已流转,无法进行该操作");
        }
 
        LoginUserInfo loginUserInfo = ywContractBill.getLoginUserInfo();
        ywContractBill.setReceivableFee(ywContractBill.getTotleFee());
        ywContractBill.setCreateDate(new Date());
        ywContractBill.setCreator(loginUserInfo.getId());
        ywContractBill.setIsdeleted(Constants.ZERO);
        ywContractBill.setType(Constants.ONE);
        ywContractBill.setStatus(Constants.ZERO);
        if(Constants.equalsInteger(ywContractBill.getBillType(),Constants.ZERO)){
            ywContractBill.setPayStatus(Constants.ZERO);
        }else{
            ywContractBill.setPayStatus(Constants.THREE);
        }
 
        if(Constants.equalsInteger(ywContractBill.getFeeType(),Constants.ONE)){
            ywContractBill.setStartDate(ywContractBill.getPlanPayDate());
            ywContractBill.setEndDate(ywContractBill.getPlanPayDate());
        }
        //查询合同下的最大的序号
        List<YwContractBill> ywContractBillList = ywContractBillMapper.selectList(new QueryWrapper<YwContractBill>()
                .lambda().eq(YwContractBill::getContractId,ywContract.getId())
                .in(YwContractBill::getCostType,Constants.ZERO,Constants.SIX,Constants.FOUR,Constants.FIVE,7)
                .orderByDesc(YwContractBill::getId));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBillList)){
            ywContractBill.setSortnum(ywContractBillList.size() + 1 );
        }else{
            ywContractBill.setSortnum(0);
        }
        ywContractBillMapper.insert(ywContractBill);
 
        //房源数据
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBill.getYwContractRoomList())){
            for (YwContractRoom ywContractRoom:ywContractBill.getYwContractRoomList()) {
                if(Objects.isNull(ywContractRoom)
                || Objects.isNull(ywContractRoom.getRoomId())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请选择房源数据");
                }
                ywContractRoom.setCreateDate(new Date());
                ywContractRoom.setCreator(loginUserInfo.getId());
                ywContractRoom.setIsdeleted(Constants.ZERO);
                ywContractRoom.setContractId(ywContractBill.getId());
                ywContractRoom.setType(Constants.ONE);
            }
            ywContractRoomMapper.insert(ywContractBill.getYwContractRoomList());
        }
 
        //附件数据
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBill.getMultifileList())){
            for (Multifile multifile:ywContractBill.getMultifileList()) {
                if(Objects.isNull(multifile)
                || StringUtils.isBlank(multifile.getFileurl())
                || StringUtils.isBlank(multifile.getName())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"附件信息错误");
                }
                multifile.setCreator(loginUserInfo.getId());
                multifile.setCreateDate(new Date());
                multifile.setIsdeleted(Constants.ZERO);
                multifile.setObjType(Constants.MultiFile.FN_CONTRACT_BILL_FILE.getKey());
                multifile.setObjId(ywContractBill.getId());
            }
            multifileMapper.insert(ywContractBill.getMultifileList());
        }
 
        return ywContractBill.getId();
    }
 
    @Override
    public void deleteById(Integer id, LoginUserInfo user) {
        ywContractBillMapper.deleteById(id);
    }
 
    @Override
    public void delete(YwContractBill ywContractBill) {
        UpdateWrapper<YwContractBill> deleteWrapper = new UpdateWrapper<>(ywContractBill);
        ywContractBillMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        ywContractBillMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(YwContractBill ywContractBill) {
        ywContractBillMapper.updateById(ywContractBill);
    }
 
    @Override
    public void updateByIdInBatch(List<YwContractBill> ywContractBills) {
        if (CollectionUtils.isEmpty(ywContractBills)) {
            return;
        }
        for (YwContractBill ywContractBill: ywContractBills) {
            this.updateById(ywContractBill);
        }
    }
 
    @Override
    public YwContractBill findById(Integer id) {
        return ywContractBillMapper.selectById(id);
    }
 
 
    @Override
    public YwContractBill getDetail(Integer id) {
        YwContractBill ywContractBill = ywContractBillMapper.selectJoinOne(YwContractBill.class,
                new MPJLambdaWrapper<YwContractBill>().selectAll(YwContractBill.class)
                        //.select(" ( select ifnull(sum(case when yw.REVENUE_TYPE = 0 then yw.ACT_RECEIVABLE_FEE  else  -yw.ACT_RECEIVABLE_FEE end),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                        .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                        .selectAs(YwContract::getCode,YwContractBill::getContractCode)
                        .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                        .selectAs(Company::getId,YwContractBill::getCompanyId)
                        .selectAs(Company::getName,YwContractBill::getCompanyName)
                        .selectAs(SystemUser::getRealname,YwContractBill::getRealname)
                        .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                        .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                        .leftJoin(Company.class,Company::getId,YwContract::getCompanyId)
                        .leftJoin(SystemUser.class,SystemUser::getId,YwContractBill::getCreator)
                        .eq(YwContractBill::getIsdeleted,Constants.ZERO)
                        .eq(YwContractBill::getId,id));
        if(Objects.isNull(ywContractBill)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        ywContractBill.setNeedReceivableFee(
                ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
        );
 
        if(Constants.equalsInteger(ywContractBill.getStatus(),Constants.ZERO)
                && (Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.ZERO)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.TWO)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.THREE)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.FOUR))
                && Utils.Date.getEnd(ywContractBill.getPlanPayDate()).getTime() < System.currentTimeMillis()){
            ywContractBill.setIsOverdue(Constants.ONE);
        }else{
            ywContractBill.setIsOverdue(Constants.ZERO);
        }
 
        //房源数据
        ywContractBill.setYwContractRoomList(
                ywContractRoomMapper.selectJoinList(YwContractRoom.class,new MPJLambdaWrapper<YwContractRoom>()
                .selectAll(YwContractRoom.class)
                .selectAs(YwProject::getName,YwRoom::getProjectName)
                .selectAs(YwFloor::getName,YwRoom::getFloorName)
                .selectAs(YwBuilding::getName,YwRoom::getBuildingName)
                .selectAs(YwRoom::getRoomNum,YwContractRoom::getRoomName)
                .selectAs(YwRoom::getRentArea,YwContractRoom::getArea)
                .leftJoin(YwRoom.class,YwRoom::getId,YwContractRoom::getRoomId)
                .leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor)
                .leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId)
                .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ONE),YwContractRoom::getContractId,id)
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ONE),YwContractRoom::getType,Constants.ONE)
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO) || Constants.equalsInteger(ywContractBill.getType(),Constants.TWO),YwContractRoom::getContractId,ywContractBill.getContractId())
                .eq(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO)| Constants.equalsInteger(ywContractBill.getType(),Constants.TWO),YwContractRoom::getType,Constants.ZERO)
        ));
 
        //收支记录
        ywContractBill.setYwContractRevenueList(
                ywContractRevenueMapper.selectJoinList(YwContractRevenue.class,new MPJLambdaWrapper<YwContractRevenue>()
                    .selectAll(YwContractRevenue.class)
                    .selectAs(YwCustomer::getName,YwContractRevenue::getCustomerName)
                    .leftJoin(YwContract.class,YwContract::getId,YwContractRevenue::getContractId)
                    .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                    .eq(YwContractRevenue::getStatus,Constants.ZERO)
                    .eq(YwContractRevenue::getBillId,ywContractBill.getId())
                    .orderByDesc(YwContractRevenue::getId)
                )
        );
 
        //附件数据
        List<Multifile> multifileList = multifileMapper.selectJoinList(Multifile.class,new MPJLambdaWrapper<Multifile>()
                        .selectAll(Multifile.class)
                        .selectAs(SystemUser::getRealname,Multifile::getUserName)
                        .leftJoin(SystemUser.class,SystemUser::getId,Multifile::getCreator)
                .eq(Multifile::getObjId,id)
                .eq(Multifile::getIsdeleted,Constants.ZERO)
                .eq(Multifile::getObjType,Constants.MultiFile.FN_CONTRACT_BILL_FILE.getKey()));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){
            String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode()
                    +systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_CONTRACT_BILL).getCode();
            for (Multifile multifile:multifileList) {
                if(StringUtils.isNotBlank(multifile.getFileurl())){
                    multifile.setFileurlFull(path + multifile.getFileurl());
                }
            }
            ywContractBill.setMultifileList(multifileList);
        }
        return ywContractBill;
    }
 
    @Override
    public YwContractBill findOne(YwContractBill ywContractBill) {
        QueryWrapper<YwContractBill> wrapper = new QueryWrapper<>(ywContractBill);
        return ywContractBillMapper.selectOne(wrapper);
    }
 
    @Override
    public List<YwContractBill> findList(YwContractBill ywContractBill) {
        QueryWrapper<YwContractBill> wrapper = new QueryWrapper<>(ywContractBill);
        return ywContractBillMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<YwContractBill> findPage(PageWrap<YwContractBill> pageWrap) {
        IPage<YwContractBill> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwContractBill> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        YwContractBill model = pageWrap.getModel();
        IPage<YwContractBill> iPage = ywContractBillMapper.selectJoinPage(page,YwContractBill.class,
            queryWrapper.selectAll(YwContractBill.class)
                    .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                    .selectAs(YwContract::getCode,YwContractBill::getContractCode)
                    .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                    .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                    .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                    .eq(YwContractBill::getIsdeleted,Constants.ZERO)
                    .like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getCustomerName()),
                            YwCustomer::getName,model.getCustomerName())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getStatus()),
                            YwContractBill::getStatus,model.getStatus())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getBillType()),
                            YwContractBill::getBillType,model.getBillType())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getPayStatus()),
                            YwContractBill::getPayStatus,model.getPayStatus())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getType()),
                            YwContractBill::getType,model.getType())
                    .le(Objects.nonNull(model)&&Objects.nonNull(model.getIsOverdue())&&Constants.equalsInteger(model.getIsOverdue(),Constants.ONE),
                            YwContractBill::getPlanPayDate, DateUtil.getCurrDateTime())
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getIsOverdue())&&Constants.equalsInteger(model.getIsOverdue(),Constants.ONE),
                            YwContractBill::getStatus, Constants.ZERO)
                    .eq(Objects.nonNull(model)&&Objects.nonNull(model.getContractId()),
                            YwContractBill::getContractId,model.getContractId())
                    .like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getContractCode()),
                            YwContract::getCode,model.getContractCode())
                .ge(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateStart()),YwContractBill::getPlanPayDate, Utils.Date.getStart(model.getPlanPayDateStart()))
                .le(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateEnd()),YwContractBill::getPlanPayDate, Utils.Date.getEnd(model.getPlanPayDateEnd()))
                    .orderByDesc(YwContractBill::getId));
 
        this.dealRoomDetail(iPage.getRecords());
        for (YwContractBill ywContractBill:iPage.getRecords()) {
            //需收金额
            ywContractBill.setNeedReceivableFee(
                    ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
            );
            //是否逾期
            if(Constants.equalsInteger(ywContractBill.getStatus(),Constants.ZERO)
                && (Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.ZERO)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.TWO)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.THREE)
                || Constants.equalsInteger(ywContractBill.getPayStatus(),Constants.FOUR))
            && Utils.Date.getEnd(ywContractBill.getPlanPayDate()).getTime() < System.currentTimeMillis()){
                ywContractBill.setIsOverdue(Constants.ONE);
            }else{
                ywContractBill.setIsOverdue(Constants.ZERO);
            }
            //楼宇名称
            List<YwContractRoom> ywContractRoomList = ywContractBill.getYwContractRoomList();
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractRoomList)){
                StringBuilder roomPathName = new StringBuilder();
                for (YwContractRoom ywContractRoom:ywContractRoomList) {
                    if(StringUtils.isNotBlank(ywContractRoom.getProjectName())){
                        roomPathName.append(ywContractRoom.getProjectName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getBuildingName())){
                        roomPathName.append(ywContractRoom.getBuildingName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getFloorName())){
                        roomPathName.append(ywContractRoom.getFloorName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getRoomName())){
                        roomPathName.append(ywContractRoom.getRoomName());
                    }
                    if(StringUtils.isNotBlank(roomPathName)){
                        roomPathName.append(";");
                    }
                }
                ywContractBill.setRoomPathName(roomPathName.toString());
            }
        }
 
        return PageData.from(iPage);
    }
 
    /**
     * 逾期账单
     * @param pageWrap
     * @return
     */
    @Override
    public PageData<YwContractBill> findPageForOverdue(PageWrap<YwContractBill> pageWrap) {
        IPage<YwContractBill> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwContractBill> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        YwContractBill model = pageWrap.getModel();
        IPage<YwContractBill> iPage = ywContractBillMapper.selectJoinPage(page,YwContractBill.class,
                queryWrapper.selectAll(YwContractBill.class)
                        .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                        .select(" ifnull((select s.status  from sms_email s where s.OBJ_ID = t.id and s.OBJ_TYPE = 2 order by s.CREATE_DATE desc  limit 1 ),0)  ",YwContractBill::getIsSendEmail)
                        .select(" ifnull((select s.status  from sms_email s where s.OBJ_ID = t.id and s.OBJ_TYPE = 1 order by s.CREATE_DATE desc  limit 1 ),0)  ",YwContractBill::getIsSendSms)
                        .selectAs(YwContract::getCode,YwContractBill::getContractCode)
                        .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                        .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                        .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                        .eq(YwContractBill::getIsdeleted,Constants.ZERO)
                        .like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getCustomerName()),
                                YwCustomer::getName,model.getCustomerName())
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getStatus()),
                                YwContractBill::getStatus,model.getStatus())
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getBillType()),
                                YwContractBill::getBillType,model.getBillType())
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getPayStatus()),
                                YwContractBill::getPayStatus,model.getPayStatus())
                        .in(YwContractBill::getPayStatus,Constants.ZERO,Constants.TWO,Constants.THREE)
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getType()),
                                YwContractBill::getType,model.getType())
                        .le(Objects.nonNull(model)&&Objects.nonNull(model.getIsOverdue())&&Constants.equalsInteger(model.getIsOverdue(),Constants.ONE),
                                YwContractBill::getPlanPayDate, DateUtil.getCurrDateTime())
                        .lt(YwContractBill::getPlanPayDate, DateUtil.getDate(new Date(),"yyyy-MM-dd"))
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getIsOverdue())&&Constants.equalsInteger(model.getIsOverdue(),Constants.ONE),
                                YwContractBill::getStatus, Constants.ZERO)
                        .ge(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateStart()),YwContractBill::getPlanPayDate, Utils.Date.getStart(model.getPlanPayDateStart()))
                        .le(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateEnd()),YwContractBill::getPlanPayDate, Utils.Date.getEnd(model.getPlanPayDateEnd()))
                        .orderByDesc(YwContractBill::getId));
        this.dealRoomDetail(iPage.getRecords());
        for (YwContractBill ywContractBill:iPage.getRecords()) {
            //需收金额
            ywContractBill.setNeedReceivableFee(
                    ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
            );
            //楼宇名称
            List<YwContractRoom> ywContractRoomList = ywContractBill.getYwContractRoomList();
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractRoomList)){
                StringBuilder roomPathName = new StringBuilder();
                for (YwContractRoom ywContractRoom:ywContractRoomList) {
                    if(StringUtils.isNotBlank(ywContractRoom.getProjectName())){
                        roomPathName.append(ywContractRoom.getProjectName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getBuildingName())){
                        roomPathName.append(ywContractRoom.getBuildingName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getFloorName())){
                        roomPathName.append(ywContractRoom.getFloorName()+"/");
                    }
                    if(StringUtils.isNotBlank(ywContractRoom.getRoomName())){
                        roomPathName.append(ywContractRoom.getRoomName());
                    }
                    if(StringUtils.isNotBlank(roomPathName)){
                        roomPathName.append(";");
                    }
                }
                ywContractBill.setRoomPathName(roomPathName.toString());
            }
        }
 
        return PageData.from(iPage);
    }
 
    public void dealRoomDetail(List<YwContractBill> ywContractBillList){
        //查询账单下的楼宇数据
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBillList)){
            //获取所有数据
            List<Integer> billIdList = ywContractBillList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)).map(i->i.getId()).collect(Collectors.toList());
            List<Integer> contractIdList = ywContractBillList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.ZERO)||Constants.equalsInteger(i.getType(),Constants.TWO)).map(i->i.getContractId()).collect(Collectors.toList());
            List<YwContractRoom> ywContractRoomList  = new ArrayList<>();
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(billIdList)){
                ywContractRoomList.addAll( ywContractRoomMapper.selectJoinList(YwContractRoom.class,new MPJLambdaWrapper<YwContractRoom>()
                        .selectAll(YwContractRoom.class)
                        .selectAs(YwProject::getName,YwRoom::getProjectName)
                        .selectAs(YwFloor::getName,YwRoom::getFloorName)
                        .selectAs(YwBuilding::getName,YwRoom::getBuildingName)
                        .selectAs(YwRoom::getRoomNum,YwContractRoom::getRoomName)
                        .leftJoin(YwRoom.class,YwRoom::getId,YwContractRoom::getRoomId)
                        .leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor)
                        .leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId)
                        .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
                        .in(YwContractRoom::getContractId,billIdList)
                        .eq(YwContractRoom::getType,Constants.ONE)
                ));
 
            }
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(contractIdList)){
                ywContractRoomList.addAll( ywContractRoomMapper.selectJoinList(YwContractRoom.class,new MPJLambdaWrapper<YwContractRoom>()
                        .selectAll(YwContractRoom.class)
                        .selectAs(YwProject::getName,YwRoom::getProjectName)
                        .selectAs(YwFloor::getName,YwRoom::getFloorName)
                        .selectAs(YwBuilding::getName,YwRoom::getBuildingName)
                        .selectAs(YwRoom::getRoomNum,YwContractRoom::getRoomName)
                        .leftJoin(YwRoom.class,YwRoom::getId,YwContractRoom::getRoomId)
                        .leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor)
                        .leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId)
                        .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
                        .in(YwContractRoom::getContractId,contractIdList)
                        .eq(YwContractRoom::getType,Constants.ZERO)
                ));
            }
 
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractRoomList)){
                for (YwContractBill ywContractBill:ywContractBillList) {
                    if(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO) || Constants.equalsInteger(ywContractBill.getType(),Constants.TWO)){
                        ywContractBill.setYwContractRoomList(
                                ywContractRoomList.stream().filter(i->(Constants.equalsInteger(i.getType(),Constants.TWO)||Constants.equalsInteger(i.getType(),Constants.ZERO))&&Constants.equalsInteger(i.getContractId(),ywContractBill.getContractId())).collect(Collectors.toList())
                        );
                    }else{
                        ywContractBill.setYwContractRoomList(
                                ywContractRoomList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)&&Constants.equalsInteger(i.getContractId(),ywContractBill.getId())).collect(Collectors.toList())
                        );
                    }
 
                }
            }
 
        }
    }
 
 
    @Override
    public long count(YwContractBill ywContractBill) {
        QueryWrapper<YwContractBill> wrapper = new QueryWrapper<>(ywContractBill);
        return ywContractBillMapper.selectCount(wrapper);
    }
 
 
 
    @Override
    public void dealDayBillCode(){
        List<YwContractBill> ywContractBillList = ywContractBillMapper.selectJoinList(YwContractBill.class,
                new MPJLambdaWrapper<YwContractBill>()
                        .selectAll(YwContractBill.class)
                        .select(" DATE(CREATE_DATE)  as codeDate")
                        .isNull(YwContractBill::getCode)
                        .orderByAsc(YwContractBill::getId)
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBillList)){
            List<String> codeDateList = ywContractBillList.stream().map(i->i.getCodeDate()).collect(Collectors.toList());
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(codeDateList)){
                Set<String> codeDateSet = new HashSet<String>(codeDateList);
                for (String codeDate:codeDateSet) {
                    //获取当前日期的数据
                    List<YwContractBill> codeDateBillList =
                            ywContractBillList.stream().filter(i->StringUtils.isNotBlank(i.getCodeDate()) && i.getCodeDate().equals(codeDate)).collect(Collectors.toList());
                    if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(codeDateBillList)){
                        continue;
                    }
                    //查询最大的单号
                    YwContractBill ywContractBill = ywContractBillMapper.selectOne(new QueryWrapper<YwContractBill>().lambda()
                            .isNotNull(YwContractBill::getCode)
                            .apply(" CREATE_DATE like '"+codeDate+"%' ")
                            .orderByDesc(YwContractBill::getId)
                            .last(" limit  1 ")
                    );
                    Integer maxCode = Constants.ZERO;
                    if(Objects.nonNull(ywContractBill)){
                        maxCode = Integer.valueOf(ywContractBill.getCode().replace(("ZD"+codeDate+"-"),""));
                    }
                    for (YwContractBill contractBill:codeDateBillList) {
                        maxCode = maxCode + 1;
                        contractBill.setCode("ZD" + codeDate + "-" + StringUtils.leftPad(maxCode.toString() , 4,"0"));
                        ywContractBillMapper.update(null, new UpdateWrapper<YwContractBill>().lambda().set(YwContractBill::getCode,contractBill.getCode())
                                .eq(YwContractBill::getId,contractBill.getId()));
                    }
                }
            }
        }
    }
 
 
    @Override
    public List<YwContractBill> getCanBackBill(YwContractBill model) {
        List<YwContractBill> list = ywContractBillMapper.selectJoinList(YwContractBill.class,
                new MPJLambdaWrapper<YwContractBill>().selectAll(YwContractBill.class)
//                        .select(" ( select ifnull(sum(case when yw.REVENUE_TYPE = 0 then yw.ACT_RECEIVABLE_FEE  else  -yw.ACT_RECEIVABLE_FEE end),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                        .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                        .selectAs(YwContract::getCode,YwContractBill::getContractCode)
                        .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                        .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                        .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                        .eq(YwContractBill::getIsdeleted,Constants.ZERO)
                        .in(YwContractBill::getCostType,Constants.ZERO,Constants.ONE,Constants.FOUR,Constants.FIVE,7)
                        .eq(Objects.nonNull(model)&&Objects.nonNull(model.getContractId()),
                                YwContractBill::getContractId,model.getContractId())
                        .and(Objects.nonNull(model)&&Objects.nonNull(model.getPlanPayDateEnd()),
                                i->i.le(YwContractBill::getStartDate, Utils.Date.getEnd(model.getPlanPayDateEnd())).or()
                        .in(YwContractBill::getPayStatus,Constants.ONE,Constants.TWO) ))
                ;
 
        for (YwContractBill ywContractBill:list) {
            ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee()));
        }
        return list;
    }
 
 
    @Override
    public YwContractBillDataVO getWaitDealList(Integer contractId){
        YwContractBillDataVO ywContractBillDataVO = new YwContractBillDataVO();
        ywContractBillDataVO.setInAmount(Constants.ZERO);
        ywContractBillDataVO.setInFee(BigDecimal.ZERO);
        ywContractBillDataVO.setPayAmount(Constants.ZERO);
        ywContractBillDataVO.setPayFee(BigDecimal.ZERO);
        MPJLambdaWrapper<YwContractBill> queryWrapper = new MPJLambdaWrapper<YwContractBill>();
        queryWrapper.selectAll(YwContractBill.class)
            .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
            .selectAs(YwContract::getCode,YwContractBill::getContractCode)
            .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
            .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
            .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
            .eq(YwContractBill::getIsdeleted,Constants.ZERO)
            .eq(YwContractBill::getStatus,Constants.ZERO)
            .in(YwContractBill::getPayStatus,Constants.ZERO,Constants.TWO,Constants.THREE,Constants.FOUR)
            .eq(YwContractBill::getContractId,contractId)
            .orderByDesc(YwContractBill::getId);
        List<YwContractBill> list = ywContractBillMapper.selectJoinList(YwContractBill.class,queryWrapper);
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){
            for (YwContractBill ywContractBill:list) {
                //需收金额
                ywContractBill.setNeedReceivableFee(
                        ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())
                );
                //收款账单
                if(Constants.equalsInteger(ywContractBill.getBillType(),Constants.ZERO)){
                    //应收金额 小于 实收金额 多收金额  应该是退款
                     if(ywContractBill.getNeedReceivableFee().compareTo(BigDecimal.ZERO)<Constants.ZERO){
                         ywContractBillDataVO.setPayAmount(ywContractBillDataVO.getPayAmount()+1);
                         ywContractBillDataVO.setPayFee(ywContractBillDataVO.getPayFee().add(ywContractBill.getNeedReceivableFee().abs()));
                     }else if(ywContractBill.getNeedReceivableFee().compareTo(BigDecimal.ZERO)>Constants.ZERO){
                         ywContractBillDataVO.setInAmount(ywContractBillDataVO.getInAmount()+1);
                         ywContractBillDataVO.setInFee(ywContractBillDataVO.getInFee().add(ywContractBill.getNeedReceivableFee().abs()));
                     }
                }else{
                    //付款账单
                    //应付金额 小于 实付金额 应该是付款款
                    if(ywContractBill.getNeedReceivableFee().compareTo(BigDecimal.ZERO)<Constants.ZERO){
                        ywContractBillDataVO.setPayAmount(ywContractBillDataVO.getPayAmount()+1);
                        ywContractBillDataVO.setPayFee(ywContractBillDataVO.getPayFee().add(ywContractBill.getNeedReceivableFee().abs()));
                    }else{
                        ywContractBillDataVO.setInAmount(ywContractBillDataVO.getInAmount()+1);
                        ywContractBillDataVO.setInFee(ywContractBillDataVO.getInFee().add(ywContractBill.getNeedReceivableFee().abs()));
                    }
                }
            }
            ywContractBillDataVO.setYwContractBillList(list);
        }
 
        return ywContractBillDataVO;
    }
 
 
 
 
    @Override
    public List<YwContractBillCallDataVO> getNoticeCustomerData(List<Integer> billIds){
        List<YwContractBillCallDataVO> ywContractBillCallDataVOList = new ArrayList<>();
        List<YwContractBill> ywContractBillList = ywContractBillMapper.selectJoinList(YwContractBill.class,new MPJLambdaWrapper<YwContractBill>()
                .selectAll(YwContractBill.class)
                .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                .selectAs(YwCustomer::getUserId,YwContractBill::getCustomerUserId)
                .selectAs(YwCustomer::getId,YwContractBill::getCustomerId)
                .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                .in(YwContractBill::getId,billIds)
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywContractBillList) ||
            !Constants.equalsInteger(billIds.size(),ywContractBillList.size())
        ){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"账单数据错误,请刷新重试");
        }
        this.dealRoomDetail(ywContractBillList);
        for (YwContractBill ywContractBill:ywContractBillList) {
            YwContractBillCallDataVO ywContractBillCallDataVO = new YwContractBillCallDataVO();
            ywContractBillCallDataVO.setBillId(ywContractBill.getId());
            ywContractBillCallDataVO.setCustomerName(ywContractBill.getCustomerName());
            ywContractBillCallDataVO.setUserId(ywContractBill.getCustomerUserId());
            //查询客户下的所有人员
            ywContractBillCallDataVO.setMemberList(
                memberMapper.selectList(new QueryWrapper<Member>().lambda().eq(Member::getCustomerId,ywContractBill.getCustomerId())
                        .eq(Member::getIsdeleted,Constants.ZERO))
            );
            ywContractBillCallDataVOList.add(ywContractBillCallDataVO);
        }
        return ywContractBillCallDataVOList;
    }
 
 
    @Override
    public void downloadCallFeeDoc(List<Integer> billIds, LoginUserInfo loginUserInfo,HttpServletResponse response){
        try {
            List<YwContractBill> ywContractBillList = ywContractBillMapper.selectJoinList(YwContractBill.class,new MPJLambdaWrapper<YwContractBill>()
                    .selectAll(YwContractBill.class)
                    .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                    .selectAs(YwCustomer::getUserId,YwContractBill::getCustomerUserId)
                    .selectAs(YwCustomer::getId,YwContractBill::getCustomerId)
                    .selectAs(YwContractDetail::getPrice,YwContractBill::getPrice)
                    .selectAs(YwContract::getCompanyId,YwContractBill::getCompanyId)
                    .selectAs(YwContractDetail::getCircleType,YwContractBill::getCircleType)
                    .selectAs(YwContractDetail::getType,YwContractBill::getDetailType)
                    .selectAs(YwContract::getZlPayType,YwContractBill::getZlPayType)
                    .selectAs(YwContract::getWyPayType,YwContractBill::getWyPayType)
                    .select(" ( select ifnull(sum(y.rent_area),0) from yw_room y left join yw_contract_room yr on y.id = yr.room_id where yr.contract_id = t.contract_id and y.IS_INVESTMENT = 1 and yr.type = 0 )  " , YwContractBill::getTotalArea)
                    .select(" ( select ifnull( sum( CASE WHEN t.bill_type = 0 and yw.REVENUE_TYPE = 0 THEN yw.ACT_RECEIVABLE_FEE when  t.bill_type = 0 and yw.REVENUE_TYPE = 1 then -yw.ACT_RECEIVABLE_FEE  when t.bill_type = 1 and yw.REVENUE_TYPE = 0 then -yw.ACT_RECEIVABLE_FEE else  yw.ACT_RECEIVABLE_FEE END),0) from  yw_contract_revenue yw where yw.bill_id = t.id and yw.status = 0 and yw.isdeleted = 0 ) as  actReceivableFee  ")
                    .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                    .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                    .leftJoin(YwContractDetail.class,YwContractDetail::getId,YwContractBill::getDetailId)
                    .in(YwContractBill::getId,billIds)
            );
            this.dealRoomDetail(ywContractBillList);
            List<YwTempConfig> ywTempConfigList = ywTempConfigMapper.selectList(new QueryWrapper<YwTempConfig>().lambda().eq(YwTempConfig::getIsdeleted,Constants.ZERO));
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywTempConfigList)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到模板配置项,请联系管理员");
            }
            List<YwTempConfig> tempList = ywTempConfigList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.FOUR)||
                    Constants.equalsInteger(i.getType(),Constants.FIVE)||
                    Constants.equalsInteger(i.getType(),Constants.SIX)).collect(Collectors.toList());
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(tempList)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到模板配置项,请联系管理员");
            }
            List<File> fileList = new ArrayList<>();
            for (YwContractBill ywContractBill:ywContractBillList) {
                List<YwTempConfig> dealList = this.dealTempData(tempList,ywContractBill,loginUserInfo);
                String fileName =  "催费通知单_" +ywContractBill.getCode() +"_" + System.currentTimeMillis()+".docx";
                YwTempConfig ywTempConfig = new YwTempConfig();
                if(Constants.equalsInteger(ywContractBill.getType(),Constants.ZERO)){
                    Optional<YwTempConfig> optional = ywTempConfigList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.TWO)).findAny();
                    if (optional.isPresent()) {
                        ywTempConfig = optional.get();
                    }
                }else{
                    Optional<YwTempConfig> optional = ywTempConfigList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.THREE)).findAny();
                    if (optional.isPresent()) {
                        ywTempConfig = optional.get();
                    }
                }
                if(Objects.isNull(ywTempConfig)){
                    throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"模板信息异常,请联系管理员");
                }
                String path = ExcelReplaceCommon.modifyWordTemplate(ywTempConfig.getUrl(),dealList,fileName,zipFilePath);
                File f = new File(path);
                if(f !=null && f.isFile()){
                    fileList.add(f);
                }
                if(fileList == null || fileList.size() == 0){
                    throw  new BusinessException(ResponseStatus.DATA_EMPTY);
                }
            }
            String fileName =  "催费通知单-" +System.currentTimeMillis();
            String encodeFileName = URLEncoder.encode(fileName, Charset.forName("UTF-8").toString())+".zip";
            response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
            response.setContentType("application/octet-stream");
            response.setHeader("eva-opera-type", "download");
            response.setHeader("eva-download-filename", encodeFileName);
            Constants.packFilesToZip(fileList,response.getOutputStream());
        } catch (Exception e) {
            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
        }
    }
 
 
    public List<YwTempConfig> dealTempData(List<YwTempConfig> ywTempConfigList , YwContractBill ywContractBill, LoginUserInfo loginUserInfo){
        //查询收支账号数据
        YwAccount ywAccount = ywAccountMapper.selectOne(new QueryWrapper<YwAccount>().lambda().eq(YwAccount::getIsdeleted,Constants.ZERO).eq(YwAccount::getStatus,Constants.ZERO).eq(YwAccount::getCompanyId,ywContractBill.getCompanyId())
                        .orderByDesc(YwAccount::getId)
                .last(" limit 1 "));
 
        List<YwTempConfig> dealList = new ArrayList<>();
        for (YwTempConfig y:ywTempConfigList) {
            if(y.getTitle().equals("${费用名称}")&&Objects.nonNull(ywContractBill.getCostType())){
                //费用类型:0=租赁费;1=物业费;2=租赁押金;3=物业押金;4=水电费;5=杂项费;6=其他; 7=保证金
                if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.ZERO)){
                    y.setUrl("租赁费");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.ONE)){
                    y.setUrl("物业费");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.TWO)){
                    y.setUrl("租赁押金");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.THREE)){
                    y.setUrl("物业押金");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.FOUR)){
                    y.setUrl("水电费");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.FIVE)){
                    y.setUrl("杂项费");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.SIX)){
                    y.setUrl("其他");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.SEVEN)){
                    y.setUrl("保证金");
                }
            }else if(y.getTitle().equals("${计费周期}")&&Objects.nonNull(ywContractBill.getDetailType())){
                if(Constants.equalsInteger(ywContractBill.getDetailType(),Constants.ZERO)){
                    //租赁支付方式 0=一次性付款;1=每三个月一付;2=六个月一付;3=一年一付
                    if(Objects.nonNull(ywContractBill.getZlPayType())){
                        if(Constants.equalsInteger(ywContractBill.getZlPayType(),Constants.ZERO)){
                            y.setUrl("一次性付款");
                        }else if(Constants.equalsInteger(ywContractBill.getZlPayType(),Constants.ONE)){
                            y.setUrl("每三个月一付");
                        }else if(Constants.equalsInteger(ywContractBill.getZlPayType(),Constants.TWO)){
                            y.setUrl("六个月一付");
                        }else if(Constants.equalsInteger(ywContractBill.getZlPayType(),Constants.THREE)){
                            y.setUrl("一年一付");
                        }
                    }
                }else{
                    //物业支付方式 0=一次性付款;1=每三个月一付;2=六个月一付;3=一年一付
                    if(Objects.nonNull(ywContractBill.getWyPayType())){
                        if(Constants.equalsInteger(ywContractBill.getWyPayType(),Constants.ZERO)){
                            y.setUrl("一次性付款");
                        }else if(Constants.equalsInteger(ywContractBill.getWyPayType(),Constants.ONE)){
                            y.setUrl("每三个月一付");
                        }else if(Constants.equalsInteger(ywContractBill.getWyPayType(),Constants.TWO)){
                            y.setUrl("六个月一付");
                        }else if(Constants.equalsInteger(ywContractBill.getWyPayType(),Constants.THREE)){
                            y.setUrl("一年一付");
                        }
                    }
                }
            }else if(y.getTitle().equals("${单价}")&&Objects.nonNull(ywContractBill.getPrice())){
                y.setUrl(ywContractBill.getPrice().toString());
            }else if(y.getTitle().equals("${单位}")&&Objects.nonNull(ywContractBill.getCircleType())){
                //付款周期类型 0=元每平米天;1=元每平米月;2=元每平米年;3=元每天;4=元每月;5=元每年;6=元每场;
                if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.ZERO)){
                    y.setUrl("元每平米天");
                }else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.ONE)){
                    y.setUrl("元每平米月");
                }else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.TWO)){
                    y.setUrl("元每平米年");
                } else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.THREE)){
                    y.setUrl("元每天");
                } else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.FOUR)){
                    y.setUrl("元每月");
                } else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.FIVE)){
                    y.setUrl("元每年");
                } else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.SIX)){
                    y.setUrl("元每场");
                }
            }else if(y.getTitle().equals("${应收日期}")&&Objects.nonNull(ywContractBill.getPlanPayDate())){
                y.setUrl(DateUtil.formatDate(ywContractBill.getPlanPayDate(),"yyyy-MM-dd"));
            }else if(y.getTitle().equals("${应收金额}")&&Objects.nonNull(ywContractBill.getReceivableFee())){
                y.setUrl((ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())).setScale(2).toString());
            }else if(y.getTitle().equals("${账单备注}")){
                if(StringUtils.isNotBlank(ywContractBill.getRemark())){
                    y.setUrl(ywContractBill.getRemark());
                }else{
                    y.setUrl("");
                }
            }else if(y.getTitle().equals("${租客名称}")&&StringUtils.isNotBlank(ywContractBill.getCustomerName())){
                y.setUrl(ywContractBill.getCustomerName());
            }else if(y.getTitle().equals("${房间信息}")){
                if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBill.getYwContractRoomList())){
                    StringBuilder roomPathName = new StringBuilder();
                    for (YwContractRoom ywContractRoom:ywContractBill.getYwContractRoomList()) {
                        if(StringUtils.isNotBlank(ywContractRoom.getProjectName())){
                            roomPathName.append(ywContractRoom.getProjectName()+"/");
                        }
                        if(StringUtils.isNotBlank(ywContractRoom.getBuildingName())){
                            roomPathName.append(ywContractRoom.getBuildingName()+"/");
                        }
                        if(StringUtils.isNotBlank(ywContractRoom.getFloorName())){
                            roomPathName.append(ywContractRoom.getFloorName()+"/");
                        }
                        if(StringUtils.isNotBlank(ywContractRoom.getRoomName())){
                            roomPathName.append(ywContractRoom.getRoomName());
                        }
                        if(StringUtils.isNotBlank(roomPathName)){
                            roomPathName.append(";");
                        }
                    }
                    y.setUrl(roomPathName.toString());
                }
            }else if(y.getTitle().equals("${租赁面积}")&&Objects.nonNull(ywContractBill.getTotalArea())){
                y.setUrl(ywContractBill.getTotalArea().toString());
            }else if(y.getTitle().equals("${所属公司账户名称}")){
                if(Objects.nonNull(ywAccount)&&StringUtils.isNotBlank(ywAccount.getName())){
                    y.setUrl(ywAccount.getName());
                }else{
                    y.setUrl("-");
                }
            }else if(y.getTitle().equals("${所属公司银行账号}")){
                y.setUrl("所属公司银行账号");
                if(Objects.nonNull(ywAccount)&&StringUtils.isNotBlank(ywAccount.getName())){
                    y.setUrl(ywAccount.getName());
                }else{
                    y.setUrl("-");
                }
            }else if(y.getTitle().equals("${所属公司开户银行}")){
                if(Objects.nonNull(ywAccount)&&StringUtils.isNotBlank(ywAccount.getBankNo())){
                    y.setUrl(ywAccount.getBankNo());
                }else{
                    y.setUrl("-");
                }
            }else if(y.getTitle().equals("${通知单生成日期}")){
                y.setUrl(DateUtil.formatDate(new Date(),"yyyy-MM-dd"));
            }else if(y.getTitle().equals("${制表人名称}")){
                y.setUrl(loginUserInfo.getRealname());
            }
            dealList.add(y);
        }
        return dealList;
    }
 
 
    @Override
    public void sendSmsEmail(List<YwSmsEmailBillCallDTO> ywSmsEmailBillCallDTOList,SmsEmailServiceImpl smsEmailService,LoginUserInfo loginUserInfo){
        if(CollectionUtils.isEmpty(ywSmsEmailBillCallDTOList)){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        List<YwTempConfig> ywTempConfigList = ywTempConfigMapper.selectList(new QueryWrapper<YwTempConfig>().lambda().eq(YwTempConfig::getIsdeleted,Constants.ZERO));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywTempConfigList)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到模板配置项,请联系管理员");
        }
        List<YwTempConfig> tempList = ywTempConfigList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.FOUR)||
                Constants.equalsInteger(i.getType(),Constants.FIVE)||
                Constants.equalsInteger(i.getType(),Constants.SIX)).collect(Collectors.toList());
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(tempList)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到模板配置项,请联系管理员");
        }
        Optional<YwTempConfig> smsTempConfigOptional = ywTempConfigList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.ZERO)).findAny();
        Optional<YwTempConfig> emailTempConfigOptional = ywTempConfigList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)).findAny();
        for (YwSmsEmailBillCallDTO ywSmsEmailBillCallDTO:ywSmsEmailBillCallDTOList) {
            if(Objects.isNull(ywSmsEmailBillCallDTO)
                    || Objects.isNull(ywSmsEmailBillCallDTO.getBillId())
                    || Objects.isNull(ywSmsEmailBillCallDTO.getUserId())
                    ||Objects.isNull(ywSmsEmailBillCallDTO.getSendEmail())
                    || Objects.isNull(ywSmsEmailBillCallDTO.getSendSms())
            ){
                throw new BusinessException(ResponseStatus.BAD_REQUEST);
            }
 
            YwContractBill ywContractBill = ywContractBillMapper.selectJoinOne(YwContractBill.class,new MPJLambdaWrapper<YwContractBill>()
                    .selectAll(YwContractBill.class)
                    .selectAs(YwCustomer::getName,YwContractBill::getCustomerName)
                    .selectAs(YwCustomer::getUserId,YwContractBill::getCustomerUserId)
                    .selectAs(YwCustomer::getId,YwContractBill::getCustomerId)
                    .selectAs(YwContractDetail::getPrice,YwContractBill::getPrice)
                    .selectAs(YwContract::getCompanyId,YwContractBill::getCompanyId)
                    .selectAs(YwContractDetail::getCircleType,YwContractBill::getCircleType)
                    .selectAs(YwContractDetail::getType,YwContractBill::getDetailType)
                    .selectAs(YwContract::getZlPayType,YwContractBill::getZlPayType)
                    .selectAs(YwContract::getWyPayType,YwContractBill::getWyPayType)
                    .select(" ( select ifnull(sum(y.rent_area),0) from yw_room y left join yw_contract_room yr on y.id = yr.room_id where yr.contract_id = t.contract_id and y.IS_INVESTMENT = 1 and yr.type = 0 )  " , YwContractBill::getTotalArea)
                    .leftJoin(YwContract.class,YwContract::getId,YwContractBill::getContractId)
                    .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                    .leftJoin(YwContractDetail.class,YwContractDetail::getId,YwContractBill::getDetailId)
                    .eq(YwContractBill::getId,ywSmsEmailBillCallDTO.getBillId())
                    .last( "limit 1" )
            );
 
            List<YwContractBill> ywContractBillList = new ArrayList<>();
            ywContractBillList.add(ywContractBill);
            this.dealRoomDetail(ywContractBillList);
 
//            this.dealTempData(tempList,ywContractBill,loginUserInfo);
            Member member = memberMapper.selectById(ywSmsEmailBillCallDTO.getUserId());
            if(Objects.isNull(member)){
                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"存在未查询到的人员信息");
            }
            if(Objects.nonNull(member)){
                if(Constants.equalsInteger(ywSmsEmailBillCallDTO.getSendSms(),Constants.ONE) && StringUtils.isNotBlank(member.getPhone())
                 && smsTempConfigOptional.isPresent()){
                    String content = this.dealTempSmsEmailData(smsTempConfigOptional.get().getTitle(),tempList,ywContractBill,loginUserInfo);
                    smsEmailService.sendBillSms(content,member.getPhone(),ywContractBill.getId());
                }
                if(Constants.equalsInteger(ywSmsEmailBillCallDTO.getSendEmail(),Constants.ONE) && StringUtils.isNotBlank(member.getEmail())
                        && emailTempConfigOptional.isPresent()){
                    String content = this.dealTempSmsEmailData(emailTempConfigOptional.get().getTitle(),tempList,ywContractBill,loginUserInfo);
                    smsEmailService.sendEmail(member.getEmail(),content,ywContractBill.getId());
                }
            }
        }
    }
 
 
    public String  dealTempSmsEmailData(String tempStr,List<YwTempConfig> ywTempConfigList , YwContractBill ywContractBill, LoginUserInfo loginUserInfo){
        //查询收支账号数据
        YwAccount ywAccount = ywAccountMapper.selectOne(new QueryWrapper<YwAccount>().lambda().eq(YwAccount::getIsdeleted,Constants.ZERO).eq(YwAccount::getStatus,Constants.ZERO).eq(YwAccount::getCompanyId,ywContractBill.getCompanyId())
                .orderByDesc(YwAccount::getId)
                .last(" limit 1 ")); 
        for (YwTempConfig y:ywTempConfigList) {
            if(y.getTitle().equals("${费用名称}")&&Objects.nonNull(ywContractBill.getCostType())){
                //费用类型:0=租赁费;1=物业费;2=租赁押金;3=物业押金;4=水电费;5=杂项费;6=其他; 7=保证金
                if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.ZERO)){
                    tempStr = tempStr.replace("${费用名称}","租赁费");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.ONE)){
                    tempStr = tempStr.replace("${费用名称}","物业费");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.TWO)){
                    tempStr = tempStr.replace("${费用名称}","租赁押金");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.THREE)){
                  tempStr =   tempStr.replace("${费用名称}","物业押金");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.FOUR)){
                  tempStr =   tempStr.replace("${费用名称}","水电费");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.FIVE)){
                  tempStr =   tempStr.replace("${费用名称}","杂项费");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.SIX)){
                  tempStr =   tempStr.replace("${费用名称}","其他");
                }else if(Constants.equalsInteger(ywContractBill.getCostType(),Constants.SEVEN)){
                  tempStr =   tempStr.replace("${费用名称}","保证金");
                }
            }else if(y.getTitle().equals("${计费周期}")){
                if(Objects.nonNull(ywContractBill.getDetailType())){
                    if(Constants.equalsInteger(ywContractBill.getDetailType(),Constants.ZERO)){
                        //租赁支付方式 0=一次性付款;1=每三个月一付;2=六个月一付;3=一年一付
                        if(Objects.nonNull(ywContractBill.getZlPayType())){
                            if(Constants.equalsInteger(ywContractBill.getZlPayType(),Constants.ZERO)){
                                tempStr = tempStr.replace("${计费周期}","一次性付款");
                            }else if(Constants.equalsInteger(ywContractBill.getZlPayType(),Constants.ONE)){
                                tempStr = tempStr.replace("${计费周期}","每三个月一付");
                            }else if(Constants.equalsInteger(ywContractBill.getZlPayType(),Constants.TWO)){
                                tempStr = tempStr.replace("${计费周期}","六个月一付");
                            }else if(Constants.equalsInteger(ywContractBill.getZlPayType(),Constants.THREE)){
                                tempStr = tempStr.replace("${计费周期}","一年一付");
                            }
                        }
                    }else{
                        //物业支付方式 0=一次性付款;1=每三个月一付;2=六个月一付;3=一年一付
                        if(Objects.nonNull(ywContractBill.getWyPayType())){
                            if(Constants.equalsInteger(ywContractBill.getWyPayType(),Constants.ZERO)){
                                tempStr = tempStr.replace("${计费周期}","一次性付款");
                            }else if(Constants.equalsInteger(ywContractBill.getWyPayType(),Constants.ONE)){
                                tempStr = tempStr.replace("${计费周期}","每三个月一付");
                            }else if(Constants.equalsInteger(ywContractBill.getWyPayType(),Constants.TWO)){
                                tempStr = tempStr.replace("${计费周期}","六个月一付");
                            }else if(Constants.equalsInteger(ywContractBill.getWyPayType(),Constants.THREE)){
                                tempStr.replace("${计费周期}","一年一付");
                            }
                        }
                    }
                }else{
                    tempStr = tempStr.replace("${计费周期}","");
                }
 
            }else if(y.getTitle().equals("${单价}")&&Objects.nonNull(ywContractBill.getPrice())){
                tempStr = tempStr.replace("${单价}",ywContractBill.getPrice().setScale(2).toString());
            }else if(y.getTitle().equals("${单位}")&&Objects.nonNull(ywContractBill.getCircleType())){
                //付款周期类型 0=元每平米天;1=元每平米月;2=元每平米年;3=元每天;4=元每月;5=元每年;6=元每场;
                if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.ZERO)){
                  tempStr =   tempStr.replace("${单位}","元每平米天");
                }else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.ONE)){
                  tempStr =   tempStr.replace("${单位}","元每平米月");
                }else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.TWO)){
                  tempStr =   tempStr.replace("${单位}","元每平米年");
                } else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.THREE)){
                  tempStr =   tempStr.replace("${单位}","元每天");
                } else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.FOUR)){
                  tempStr =   tempStr.replace("${单位}","元每月");
                } else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.FIVE)){
                  tempStr =   tempStr.replace("${单位}","元每年");
                } else if(Constants.equalsInteger(ywContractBill.getCircleType(),Constants.SIX)){
                  tempStr =   tempStr.replace("${单位}","元每场");
                }
            }else if(y.getTitle().equals("${应收日期}")&&Objects.nonNull(ywContractBill.getPlanPayDate())){
                tempStr = tempStr.replace("${应收日期}",DateUtil.formatDate(ywContractBill.getPlanPayDate(),"yyyy-MM-dd"));
            }else if(y.getTitle().equals("${应收金额}")&&Objects.nonNull(ywContractBill.getReceivableFee())){
                tempStr = tempStr.replace("${应收金额}",(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee())).setScale(2).toString());
            }else if(y.getTitle().equals("${账单备注}")){
                if(StringUtils.isNotBlank(ywContractBill.getRemark())){
                  tempStr =   tempStr.replace("${账单备注}",ywContractBill.getRemark());
                }else{
                  tempStr =   tempStr.replace("${账单备注}","");
                }
            }else if(y.getTitle().equals("${租客名称}")&&StringUtils.isNotBlank(ywContractBill.getCustomerName())){
                tempStr = tempStr.replace("${租客名称}",ywContractBill.getCustomerName());
            }else if(y.getTitle().equals("${房间信息}")){
                if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywContractBill.getYwContractRoomList())){
                    StringBuilder roomPathName = new StringBuilder();
                    for (YwContractRoom ywContractRoom:ywContractBill.getYwContractRoomList()) {
                        if(StringUtils.isNotBlank(ywContractRoom.getProjectName())){
                            roomPathName.append(ywContractRoom.getProjectName()+"/");
                        }
                        if(StringUtils.isNotBlank(ywContractRoom.getBuildingName())){
                            roomPathName.append(ywContractRoom.getBuildingName()+"/");
                        }
                        if(StringUtils.isNotBlank(ywContractRoom.getFloorName())){
                            roomPathName.append(ywContractRoom.getFloorName()+"/");
                        }
                        if(StringUtils.isNotBlank(ywContractRoom.getRoomName())){
                            roomPathName.append(ywContractRoom.getRoomName());
                        }
                        if(StringUtils.isNotBlank(roomPathName)){
                            roomPathName.append(";");
                        }
                    }
                    tempStr = tempStr.replace("${房间信息}",roomPathName.toString());
                }
            }else if(y.getTitle().equals("${租赁面积}")&&Objects.nonNull(ywContractBill.getTotalArea())){
                tempStr.replace("${租赁面积}",ywContractBill.getTotalArea().toString());
            }else if(y.getTitle().equals("${所属公司账户名称}")){
                if(Objects.nonNull(ywAccount)&&StringUtils.isNotBlank(ywAccount.getName())){
                  tempStr =   tempStr.replace("${所属公司账户名称}",ywAccount.getName());
                }else{
                  tempStr =   tempStr.replace("${所属公司账户名称}","-");
                }
            }else if(y.getTitle().equals("${所属公司银行账号}")){ 
                if(Objects.nonNull(ywAccount)&&StringUtils.isNotBlank(ywAccount.getName())){
                  tempStr =   tempStr.replace("${所属公司银行账号}",ywAccount.getName());
                }else{
                  tempStr =   tempStr.replace("${所属公司银行账号}","-");
                }
            }else if(y.getTitle().equals("${所属公司开户银行}")){
                if(Objects.nonNull(ywAccount)&&StringUtils.isNotBlank(ywAccount.getBankNo())){
                  tempStr =   tempStr.replace("${所属公司开户银行}",ywAccount.getBankNo());
                }else{
                  tempStr =   tempStr.replace("${所属公司开户银行}","-");
                }
            }else if(y.getTitle().equals("${通知单生成日期}")){
                tempStr = tempStr.replace("${通知单生成日期}",DateUtil.formatDate(new Date(),"yyyy-MM-dd"));
            }else if(y.getTitle().equals("${制表人名称}")){
                tempStr = tempStr.replace("${制表人名称}",loginUserInfo.getRealname());
            } 
        }
        return tempStr;
    }
 
 
 
}