From 6bd7d8d56d0671e1251e6ae6eef9a16ea5ce2253 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 05 十二月 2024 18:48:42 +0800
Subject: [PATCH] 开发更新

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractServiceImpl.java |  257 +++++++++++++++++++++++++++++----------------------
 1 files changed, 147 insertions(+), 110 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractServiceImpl.java
index 94da9a9..0b19f67 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwContractServiceImpl.java
@@ -189,7 +189,7 @@
             if(!(model.getZlFreeEndDate()==null &&  model.getZlFreeStartDate()==null) && (
                     (model.getZlFreeEndDate()!=null &&  model.getZlFreeStartDate()==null)
                             ||(model.getZlFreeEndDate()==null &&  model.getZlFreeStartDate()!=null)
-                            ||model.getZlFreeEndDate().getTime()< model.getZlFreeStartDate().getTime())
+                            ||model.getZlFreeEndDate().getTime()<= model.getZlFreeStartDate().getTime())
             ){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇烽�夋嫨姝g‘鐨勭璧佹潯娆惧厤绉熸湡淇℃伅锛�");
             }
@@ -242,7 +242,7 @@
                 ){
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇锋寜椤甸潰瑕佹眰濉啓鐗╀笟鏉℃淇℃伅!");
                 }
-                if(d.getEndDate().getTime()< d.getStartDate().getTime()){
+                if(d.getEndDate().getTime()<= d.getStartDate().getTime()){
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鐗╀笟鏉℃鏈夋晥鏈熺粨鏉熸椂闂翠笉寰楁棭浜庡紑濮嬫椂闂达紒");
                 }
                 if(!Constants.equalsInteger(model.getWyPayType(),Constants.ZERO) &&
@@ -303,7 +303,7 @@
         BigDecimal fee = Constants.formatBigdecimal(model.getBtFee());
         String str = "閫�绉熸憳瑕侊細鍓╀綑鏈粨娓呰处鍗晎param1}浠斤紝鍏抽棴璐﹀崟{param2}浠姐�愰��绉熸棩{param3}锛岄��绉熻垂鐢ㄥ悎璁¢渶{param4}{param5}鍏冦�傘��";
         str = str.replace("{param1}",model.getBtWaitBill()+"")
-                .replace("{param2}",Integer.toString(model.getBtCLoseBill()))
+                .replace("{param2}",model.getBtCLoseBill()+"")
                 .replace("{param3}",DateUtil.getDateLongSlash(model.getBtDate()))
                 .replace("{param4}",fee.compareTo(new BigDecimal(0)) >=0?"鏀�":"浠�")
                 .replace("{param5}",(fee.compareTo(new BigDecimal(0)) >=0?
@@ -353,6 +353,9 @@
         update.setBtFee(param.getBtFee());
         update.setBtRemark(getbackRentRemarkByParam(param));
         ywContractMapper.updateById(update);
+//        if(1==1){
+//            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
+//        }
         dealLogBiz(param,Constants.YwLogType.CONTRACT_BACK, param.getLoginUserInfo().getRealname(),getbackRentLogByParam(param));
         return param.getId();
     }
@@ -480,17 +483,12 @@
                 totalBackFee = totalBackFee.add(fee);//绱閫�娆鹃噾棰�
             }
         }
-        List<YwContractBill> ywContractBillList = ywContractBillMapper.selectList(new QueryWrapper<YwContractBill>()
-                .lambda().eq(YwContractBill::getContractId,param.getId()).orderByDesc(YwContractBill::getId));
-        Integer sortNum = ywContractBillList.size();
         if(param.getAddBillList()!=null && param.getAddBillList().size()>0){
             for(YwContractBill addBill : param.getAddBillList()){
-                sortNum = sortNum + 1 ;
                 addBill.setIsdeleted(Constants.ZERO);
                 addBill.setContractId(param.getId());
                 addBill.setType(Constants.ONE);
                 addBill.setStatus(Constants.ZERO);
-                addBill.setTotleFee(addBill.getReceivableFee());
                 if(Constants.equalsInteger(addBill.getFeeType(),Constants.ONE)){
                     addBill.setStartDate(addBill.getPlanPayDate());
                     addBill.setEndDate(addBill.getPlanPayDate());
@@ -506,8 +504,6 @@
                     addBill.setBtFee(Constants.formatBigdecimal(addBill.getActReceivableFee()).multiply(new BigDecimal(-1)));
                 }
                 totalBackFee = totalBackFee.add(Constants.formatBigdecimal(addBill.getBtFee()));
-                addBill.setCreator(param.getEditor());
-                addBill.setCreateDate(param.getEditDate());
                 addBill.setEditDate(param.getEditDate());
                 addBill.setEditor(param.getEditor());
                 addBill.setBtActDate(param.getBtActDate());
@@ -516,7 +512,6 @@
                 addBill.setBtUserId(param.getBtUserId());
                 addBill.setBtSignDate(param.getBtSignDate());
                 addBill.setBtType(param.getBtType());
-                addBill.setSortnum(sortNum );
                 newBills.add(addBill);
             }
             ywContractBillMapper.insert(param.getAddBillList());//鎵归噺鎻掑叆鏁版嵁
@@ -535,18 +530,12 @@
                         yjBill.setEditDate(param.getEditDate());
                         yjBill.setEditor(param.getEditor());
                         yjBill.setReceivableFee(BigDecimal.ZERO);
-                        if(bill.getActReceivableFee().compareTo(BigDecimal.ZERO)==Constants.ZERO){
-                            yjBill.setPayStatus(Constants.FIVE);
-                            yjBill.setStatus(Constants.ONE);
-                        }else{
-                            yjBill.setPayStatus(Constants.FOUR);
-                            yjNoBills ++;
-                        }
+                        yjBill.setPayStatus(Constants.FOUR);
                         yjBill.setPlanPayDate(canBill.getPlanPayDate());
                         ywContractBillMapper.updateById(yjBill);
                     }
                 }
-
+                yjNoBills ++;
             }
         }
         param.setBtWaitBill(canBills.size() + newBills.size()+yjNoBills);//鏈竻绠楃殑璐﹀崟鏁伴噺
@@ -701,15 +690,12 @@
         }
         int num =1;
         for(int i=0;i<billList1.size();i++){
-            if(Constants.equalsInteger( billList1.get(i).getCostType(),Constants.ZERO)){
-                billList1.get(i).setSortnum(num++);
-            }
+            billList1.get(i).setSortnum(num);
+            num++;
         }
-        num =1;
         for(int i=0;i<billList2.size();i++){
-            if(Constants.equalsInteger( billList2.get(i).getCostType(),Constants.ONE)){
-                billList2.get(i).setSortnum(num++);
-            }
+            billList2.get(i).setSortnum(num);
+            num++;
         }
         if(model.getId()!=null){
             ywContractBillMapper.insert(billList1);
@@ -926,7 +912,6 @@
             bill.setTotleFee(getTotalFeeByStartEnd(model,d,bill,freeStart,freeEnd));
             bill.setReceivableFee(bill.getTotleFee());
             bill.setBillType(Constants.ZERO);
-            bill.setCompanyId(model.getCompanyId());
             list.add(bill);
         }
         return list;
@@ -1046,7 +1031,7 @@
             if(!(model.getZlFreeEndDate()==null &&  model.getZlFreeStartDate()==null) && (
                         (model.getZlFreeEndDate()!=null &&  model.getZlFreeStartDate()==null)
                         ||(model.getZlFreeEndDate()==null &&  model.getZlFreeStartDate()!=null)
-                        ||model.getZlFreeEndDate().getTime()< model.getZlFreeStartDate().getTime())
+                        ||model.getZlFreeEndDate().getTime()<= model.getZlFreeStartDate().getTime())
                   ){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇烽�夋嫨姝g‘鐨勭璧佹潯娆惧厤绉熸湡淇℃伅锛�");
             }
@@ -1075,7 +1060,7 @@
                         Constants.equalsInteger(d.getCircleType(),Constants.SIX)){
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绉熻祦鏉℃鍙湁閫夋嫨涓�娆℃�т粯娆炬椂锛屾墠鑳介�夋嫨璇ユ寜姣忓満鏀惰垂锛�");
                 }
-                if(model.getZlFirstPrice() == null){//棣栨湡淇℃伅
+                if(model.getZlFirstCircle() == null){//棣栨湡淇℃伅
                     model.setZlFirstPrice(d.getPrice());
                     model.setZlFirstCircle(d.getCircleType());
                 }
@@ -1124,7 +1109,7 @@
                         Constants.equalsInteger(d.getCircleType(),Constants.SIX)){
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鐗╀笟鏉℃鍙湁閫夋嫨涓�娆℃�т粯娆炬椂锛屾墠鑳介�夋嫨璇ユ寜姣忓満鏀惰垂锛�");
                 }
-                if(model.getWyFirstPrice() == null){
+                if(model.getWyFirstCircle() == null){
                     //棣栨湡淇℃伅
                     model.setWyFirstPrice(d.getPrice());
                     model.setWyFirstCircle(d.getCircleType());
@@ -1225,108 +1210,160 @@
     }
     @Override
     public YwContract findById(Integer id) {
+
+        YwContract model =queryDetailInfoById(id);
+        //鏌ヨ鎿嶄綔鏃ュ織璁板綍
+        YwWorkorderLog log = new YwWorkorderLog();
+        log.setJobId(model.getId());
+        log.setIsdeleted(Constants.ZERO);
+        model.setLogList(ywWorkorderLogMapper.selectList(new QueryWrapper<YwWorkorderLog>(log)
+                .lambda()
+                .in(YwWorkorderLog::getObjType,Constants.YwLogType.CONTRACT_BACK.getKey()
+                        ,Constants.YwLogType.CONTRACT_CREATE.getKey()
+                        ,Constants.YwLogType.CONTRACT_UPDATE.getKey())
+                .orderByAsc(YwWorkorderLog::getCreateDate)));
+
+        //鏌ヨ璐﹀崟闆嗗悎
+        queryBillListByModel(model,new Date());
+        return model;
+    }
+    private YwContract queryDetailInfoById(Integer id) {
         MPJLambdaWrapper<YwContract> queryWrapper = new MPJLambdaWrapper<>();
-        queryWrapper.selectAll(YwContract.class )
-                .selectAs(Company::getName,YwContract::getCompanyName )
-                .selectAs(SystemUser::getRealname,YwContract::getUserName )
-                .selectAs(YwCustomer::getName,YwContract::getRenterName )
-                .selectAs(YwProject::getName,YwContract::getProjectName )
-                .select("t3.realname",YwContract::getCreatorName )
-                .select("(select sum(r.area) from yw_contract_room cr left join yw_room r on r.id = cr.room_id where r.isdeleted=0 and cr.contract_id =t.id)",YwContract::getTotalArea )
-                .leftJoin(Company.class,Company::getId,YwContract::getCompanyId)
-                .leftJoin(SystemUser.class,SystemUser::getId,YwContract::getUserId)
-                .leftJoin(SystemUser.class,SystemUser::getId,YwContract::getCreator)
-                .leftJoin(YwProject.class,YwProject::getId,YwContract::getProjectId)
-                .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
-                .eq( YwContract::getId,id);
-        YwContract model = ywContractMapper.selectJoinOne(YwContract.class,queryWrapper);
-        if(model != null){
+        queryWrapper.selectAll(YwContract.class)
+                .selectAs(Company::getName, YwContract::getCompanyName)
+                .selectAs(SystemUser::getRealname, YwContract::getUserName)
+                .selectAs(YwCustomer::getName, YwContract::getRenterName)
+                .selectAs(YwProject::getName, YwContract::getProjectName)
+                .select("t3.realname", YwContract::getCreatorName)
+                .select("(select sum(r.area) from yw_contract_room cr left join yw_room r on r.id = cr.room_id where r.isdeleted=0 and cr.contract_id =t.id)", YwContract::getTotalArea)
+                .leftJoin(Company.class, Company::getId, YwContract::getCompanyId)
+                .leftJoin(SystemUser.class, SystemUser::getId, YwContract::getUserId)
+                .leftJoin(SystemUser.class, SystemUser::getId, YwContract::getCreator)
+                .leftJoin(YwProject.class, YwProject::getId, YwContract::getProjectId)
+                .leftJoin(YwCustomer.class, YwCustomer::getId, YwContract::getRenterId)
+                .eq(YwContract::getId, id);
+        YwContract model = ywContractMapper.selectJoinOne(YwContract.class, queryWrapper);
+        if (model == null) {
+                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
             //鍚堝悓闄勪欢
             initFiles(model);
             //鏌ヨ鎴挎簮淇℃伅鏁版嵁
             MPJLambdaWrapper<YwRoom> rw = new MPJLambdaWrapper<>();
-            rw.selectAll(YwRoom.class )
-                    .selectAs(YwProject::getName,YwRoom::getProjectName)
-                    .selectAs(YwFloor::getName,YwRoom::getFloorName)
-                    .selectAs(YwBuilding::getName,YwRoom::getBuildingName)
-                    .leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId)
-                    .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
-                    .leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor)
-                    .eq(YwRoom::getIsdeleted,Constants.ZERO)
-                    .exists("(select a.id from yw_contract_room a where a.isdeleted=0 and a.type=0 and a.room_id=t.id and a.contract_id="+model.getId()+")");
-            model.setRoomList(roomMapper.selectJoinList(YwRoom.class,rw));
+            rw.selectAll(YwRoom.class)
+                    .selectAs(YwProject::getName, YwRoom::getProjectName)
+                    .selectAs(YwFloor::getName, YwRoom::getFloorName)
+                    .selectAs(YwBuilding::getName, YwRoom::getBuildingName)
+                    .leftJoin(YwProject.class, YwProject::getId, YwRoom::getProjectId)
+                    .leftJoin(YwBuilding.class, YwBuilding::getId, YwRoom::getBuildingId)
+                    .leftJoin(YwFloor.class, YwFloor::getId, YwRoom::getFloor)
+                    .eq(YwRoom::getIsdeleted, Constants.ZERO)
+                    .exists("(select a.id from yw_contract_room a where a.isdeleted=0 and a.type=0 and a.room_id=t.id and a.contract_id=" + model.getId() + ")");
+            model.setRoomList(roomMapper.selectJoinList(YwRoom.class, rw));
             model.setWyFirstCircleStr(Constants.getUnitTypeByNum(model.getWyFirstCircle()));
             model.setZlFirstCircleStr(Constants.getUnitTypeByNum(model.getZlFirstCircle()));
             //鏌ヨ绉熻硟鏉℃淇℃伅
             MPJLambdaWrapper<YwContractDetail> dw = new MPJLambdaWrapper<>();
-            dw.selectAll(YwContractDetail.class )
-                    .eq(YwContractDetail::getIsdeleted,Constants.ZERO)
-                    .eq(YwContractDetail::getContractId,model.getId())
-                    .in(YwContractDetail::getType,Constants.ZERO,Constants.TWO)
+            dw.selectAll(YwContractDetail.class)
+                    .eq(YwContractDetail::getIsdeleted, Constants.ZERO)
+                    .eq(YwContractDetail::getContractId, model.getId())
+                    .in(YwContractDetail::getType, Constants.ZERO, Constants.TWO)
                     .orderByAsc(YwContractDetail::getSortnum);
-            model.setZlDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class,dw));
+            model.setZlDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class, dw));
             //鏌ヨ鐗╂キ鏉℃淇℃伅
             dw = new MPJLambdaWrapper<>();
-            dw.selectAll(YwContractDetail.class )
-                    .eq(YwContractDetail::getIsdeleted,Constants.ZERO)
-                    .eq(YwContractDetail::getContractId,model.getId())
-                    .in(YwContractDetail::getType,Constants.ONE,Constants.THREE)
+            dw.selectAll(YwContractDetail.class)
+                    .eq(YwContractDetail::getIsdeleted, Constants.ZERO)
+                    .eq(YwContractDetail::getContractId, model.getId())
+                    .in(YwContractDetail::getType, Constants.ONE, Constants.THREE)
                     .orderByAsc(YwContractDetail::getSortnum);
-            model.setWyDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class,dw));
+            model.setWyDetailList(ywContractDetailMapper.selectJoinList(YwContractDetail.class, dw));
 
-            //鏌ヨ鎿嶄綔鏃ュ織璁板綍
-            YwWorkorderLog log = new YwWorkorderLog();
-            log.setJobId(model.getId());
-            log.setIsdeleted(Constants.ZERO);
-            model.setLogList(ywWorkorderLogMapper.selectList(new QueryWrapper<YwWorkorderLog>(log)
-                    .lambda()
-                    .in(YwWorkorderLog::getObjType,Constants.YwLogType.CONTRACT_BACK.getKey()
-                            ,Constants.YwLogType.CONTRACT_CREATE.getKey()
-                            ,Constants.YwLogType.CONTRACT_UPDATE.getKey())
-                    .orderByAsc(YwWorkorderLog::getCreateDate)));
+        return model;
+    }
 
-            //鏌ヨ璐﹀崟闆嗗悎
-            model.setBillList(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  ")
-                            .eq(  YwContractBill::getContractId,model.getId())
-                            .eq(YwContractBill::getIsdeleted,Constants.ZERO)
-                            .orderByAsc(YwContractBill::getSortnum,YwContractBill::getCreateDate)));
+   @Override
+    public YwContract findForBills(YwContract param) {
+        YwContract model = queryDetailInfoById(param.getId());
+        queryBillListByModel(model,param.getBtDate());
+        return model;
 
-            for (YwContractBill ywContractBill:model.getBillList()) {
-                ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee()));
+    }
+    private void queryBillListByModel(YwContract model,Date date) {
+        if(date ==null){
+            date = new Date();
+        }
+        //鏌ヨ璐﹀崟闆嗗悎
+        model.setBillList(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  ")
+                .eq(  YwContractBill::getContractId,model.getId())
+                .eq(YwContractBill::getIsdeleted,Constants.ZERO)
+                .orderByAsc(YwContractBill::getSortnum,YwContractBill::getCreateDate)));
+        for (YwContractBill ywContractBill:model.getBillList()) {
+            ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee());
+//            ywContractBill.setNeedReceivableFee(ywContractBill.getReceivableFee().subtract(ywContractBill.getActReceivableFee()));
+        }
+        model.setCanBackRentBills(new ArrayList<>());
+        long nowStart = Utils.Date.getStart(date).getTime();
+        long nowEnd = Utils.Date.getEnd(date).getTime();
+        if(model.getBillList()!=null && model.getBillList().size()>0){
+            for(YwContractBill bill: model.getBillList()){
+                //浠樻鐘舵�侊細0=寰呮敹娆撅紱1=宸茬粨娓咃紱2=閮ㄥ垎缁撴竻锛�3=寰呬粯娆撅紱4=寰呴��娆撅紱5=宸插叧闂�
+                if(Constants.equalsInteger(bill.getPayStatus(),Constants.ZERO)
+                        ||Constants.equalsInteger(bill.getPayStatus(),Constants.THREE)){
+                    if(bill.getStartDate().getTime()>nowEnd){
+                        //濡傛灉杩樻病寮�濮嬶紝璐﹀崟鐩存帴鍏抽棴
+                        continue;
+                    }
+                    model.getCanBackRentBills().add(bill);
+                }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){
+                    if(bill.getEndDate().getTime()<nowStart){
+                        //濡傛灉宸茬粨娓咃紝璐﹀崟鐩存帴鍏抽棴
+                        continue;
+                    }
+                    model.getCanBackRentBills().add(bill);
+                }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.TWO) ){
+                    model.getCanBackRentBills().add(bill);
+                }
             }
-
-            model.setCanBackRentBills(new ArrayList<>());
-            long nowStart = Utils.Date.getStart(new Date()).getTime();
-            long nowEnd = Utils.Date.getEnd(new Date()).getTime();
-            if(model.getBillList()!=null && model.getBillList().size()>0){
-                for(YwContractBill bill: model.getBillList()){
-                    //浠樻鐘舵�侊細0=寰呮敹娆撅紱1=宸茬粨娓咃紱2=閮ㄥ垎缁撴竻锛�3=寰呬粯娆撅紱4=寰呴��娆撅紱5=宸插叧闂�
-                    if(Constants.equalsInteger(bill.getPayStatus(),Constants.ZERO)
-                            ||Constants.equalsInteger(bill.getPayStatus(),Constants.THREE)){
-                        if(bill.getStartDate().getTime()>nowEnd){
-                            //濡傛灉杩樻病寮�濮嬶紝璐﹀崟鐩存帴鍏抽棴
-                            continue;
-                        }
-                        model.getCanBackRentBills().add(bill);
-
-                    }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.ONE) ){
-                        if(bill.getEndDate().getTime()<nowStart){
-                            //濡傛灉宸茬粨娓咃紝璐﹀崟鐩存帴鍏抽棴
-                            continue;
-                        }
-                        model.getCanBackRentBills().add(bill);
-                    }else  if(Constants.equalsInteger(bill.getPayStatus(),Constants.TWO) ){
-                        model.getCanBackRentBills().add(bill);
+            for(YwContractBill bill : model.getCanBackRentBills()){
+                YwContractDetail detail = null;
+                if(Constants.equalsInteger(bill.getCostType(),Constants.ZERO)){
+                    detail = getDetailByIdFromList(bill.getDetailId(),model.getZlDetailList());
+                    if(detail!=null&& bill.getStartDate()!=null && bill.getEndDate()!=null
+                            &&(date.getTime() <= bill.getStartDate().getTime() || (date.getTime() >= bill.getStartDate().getTime() && date.getTime()<= bill.getEndDate().getTime()))){
+                        Date odate = bill.getEndDate();
+                        bill.setEndDate(date);
+                        BigDecimal actFee = getTotalFeeByStartEnd(model,detail,bill,model.getZlFreeStartDate(),model.getZlFreeEndDate());
+                        bill.setEndDate(odate);
+                        bill.setNeedReceivableFee(actFee);
+                    }
+                }else if(Constants.equalsInteger(bill.getCostType(),Constants.ONE)){
+                    detail = getDetailByIdFromList(bill.getDetailId(),model.getWyDetailList());
+                    if(detail!=null&& bill.getStartDate()!=null && bill.getEndDate()!=null
+                            &&(date.getTime() <= bill.getStartDate().getTime() || (date.getTime() >= bill.getStartDate().getTime() && date.getTime()<= bill.getEndDate().getTime()))){
+                        Date odate = bill.getEndDate();
+                        bill.setEndDate(date);
+                        BigDecimal actFee = getTotalFeeByStartEnd(model,detail,bill,model.getWyFreeStartDate(),model.getWyFreeEndDate());
+                        bill.setEndDate(odate);
+                        bill.setNeedReceivableFee(actFee);
                     }
                 }
             }
-
         }
+    }
 
-        return model;
+    private YwContractDetail getDetailByIdFromList(Integer detailId, List<YwContractDetail> list) {
+        if(list!=null){
+            for(YwContractDetail d : list){
+                if(Constants.equalsInteger(detailId,d.getId())){
+                    return d;
+                }
+            }
+        }
+        return  null;
     }
 
     @Override

--
Gitblit v1.9.3