jiangping
2025-06-06 77946261ec663aa1fe7f6f97e550532ed879f982
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
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
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.model.*;
import com.doumee.dao.business.vo.YwFloorStatusDataVO;
import com.doumee.dao.business.vo.YwRoomContractDataVO;
import com.doumee.dao.business.vo.YwRoomStatusDataVO;
import com.doumee.service.business.YwRoomService;
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 org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 运维房源信息表Service实现
 * @author 江蹄蹄
 * @date 2024/11/19 16:07
 */
@Service
public class YwRoomServiceImpl implements YwRoomService {
 
    @Autowired
    private YwRoomMapper ywRoomMapper;
    @Autowired
    private YwBuildingMapper ywBuildingMapper;
    @Autowired
    private YwContractRoomMapper ywContractRoomMapper;
    @Autowired
    private YwContractMapper ywContractMapper;
 
    @Autowired
    private YwWorkorderMapper ywWorkorderMapper;
    @Autowired
    private YwFloorMapper ywFloorMapper;
 
 
    @Override
    public Integer create(YwRoom model) {
        if(model.getBuildingId()==null){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择正确的楼宇信息!");
        }
        YwBuilding ywBuilding = ywBuildingMapper.selectById(model.getBuildingId());
        if(ywBuilding ==null ||Constants.equalsInteger(ywBuilding.getIsdeleted(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择正确的楼宇信息!");
        }
        model.setProjectId(ywBuilding.getProjectId());
        model.setCreator(model.getLoginUserInfo().getId());
        model.setIsdeleted(Constants.ZERO);
        model.setCreateDate(new Date());
        model.setStatus(Constants.ZERO);
        model.setEditDate(model.getCreateDate());
        model.setEditor(model.getCreator());
        model.setLeaseNowStatus(Constants.ZERO);
        ywRoomMapper.insert(model);
        return model.getId();
    }
 
    @Override
    public void deleteById(Integer id, LoginUserInfo user) {
        if(ywContractRoomMapper.selectCount(new QueryWrapper<YwContractRoom>()
                .lambda().eq(YwContractRoom::getIsdeleted,Constants.ZERO)
                .eq(YwContractRoom::getRoomId,id))>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"房间信息已使用,无法进行删除!");
        };
        if(ywWorkorderMapper.selectCount(new QueryWrapper<YwWorkorder>()
                .lambda().eq(YwWorkorder::getIsdeleted,Constants.ZERO)
                .eq(YwWorkorder::getRoomId,id))>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"房间信息已使用,无法进行删除!");
        };
        YwRoom model = new YwRoom();
        model.setId(id);
        model.setEditDate(new Date());
        model.setEditor(user.getId());
        model.setIsdeleted(Constants.ONE);
        ywRoomMapper.updateById(model);
    }
 
    @Override
    public void delete(YwRoom ywRoom) {
        UpdateWrapper<YwRoom> deleteWrapper = new UpdateWrapper<>(ywRoom);
        ywRoomMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for (Integer ywProject: ids) {
            this.deleteById(ywProject,user);
        }
    }
 
    @Override
    public void updateById(YwRoom model) {
        if(model.getBuildingId()==null){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择正确的楼宇信息!");
        }
        YwBuilding ywBuilding = ywBuildingMapper.selectById(model.getBuildingId());
        if(ywBuilding ==null ||Constants.equalsInteger(ywBuilding.getIsdeleted(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择正确的楼宇信息!");
        }
        model.setProjectId(ywBuilding.getProjectId());
        model.setEditDate(new Date());
        model.setEditor(model.getLoginUserInfo().getId());
        ywRoomMapper.updateById(model);
    }
 
    @Override
    public void updateByIdInBatch(List<YwRoom> ywRooms) {
        if (CollectionUtils.isEmpty(ywRooms)) {
            return;
        }
        for (YwRoom ywRoom: ywRooms) {
            this.updateById(ywRoom);
        }
    }
 
    @Override
    public YwRoom findById(Integer id) {
        MPJLambdaWrapper<YwRoom> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(YwRoom.class )
                .selectAs(YwProject::getName,YwRoom::getProjectName)
                .selectAs(YwFloor::getName,YwRoom::getFloorName)
//                .select(" ifnull( ( select case when y1.status = 3 then now() BETWEEN y1.START_DATE and y1.BT_DATE else now() BETWEEN y1.START_DATE and y1.END_DATE END  " +
//                        "from yw_contract y1 left join yw_contract_room y2 on y1.id = y2.CONTRACT_ID and y2.TYPE = 0  " +
//                        "where y1.`STATUS` <> 4  and y2.room_id = t.id order by y1.create_date desc  limit 1  ) ,0) ",YwRoom::getLeaseStatus)
                .select(" ifnull( (  case when t.IS_INVESTMENT = 0 then 2 else t.LEASE_NOW_STATUS end  ) ,0) ",YwRoom::getLeaseStatus)
                .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::getId,id)
                .last(" limit 1 ")
        ;
        YwRoom ywRoom = ywRoomMapper.selectJoinOne(YwRoom.class,queryWrapper);
        return ywRoom;
    }
 
    @Override
    public YwRoom findOne(YwRoom ywRoom) {
        QueryWrapper<YwRoom> wrapper = new QueryWrapper<>(ywRoom);
        return ywRoomMapper.selectOne(wrapper);
    }
 
    @Override
    public List<YwRoom> findList(YwRoom ywRoom) {
        ywRoom.setIsdeleted(Constants.ZERO);
        QueryWrapper<YwRoom> wrapper = new QueryWrapper< >(ywRoom);
        return ywRoomMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<YwRoom> findPage(PageWrap<YwRoom> pageWrap) {
        IPage<YwRoom> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
         MPJLambdaWrapper<YwRoom> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(YwRoom.class )
                .selectAs(YwProject::getName,YwRoom::getProjectName)
                .selectAs(YwFloor::getName,YwRoom::getFloorName)
                .selectAs(YwBuilding::getName,YwRoom::getBuildingName)
//                .select(" ifnull( ( select case when y1.status = 3 then now() BETWEEN y1.START_DATE and y1.BT_DATE else now() BETWEEN y1.START_DATE and y1.END_DATE END  " +
//                        "from yw_contract y1 left join yw_contract_room y2 on y1.id = y2.CONTRACT_ID and y2.TYPE = 0  " +
//                        "where y1.`STATUS` <> 4  and y2.room_id = t.id order by y1.create_date desc  limit 1  ) ,0) ",YwRoom::getLeaseStatus)
                .select(" ifnull( (  case when t.IS_INVESTMENT = 0 then 2 else t.LEASE_NOW_STATUS end  ) ,0) ",YwRoom::getLeaseStatus)
                .leftJoin(YwProject.class,YwProject::getId,YwRoom::getProjectId)
                .leftJoin(YwBuilding.class,YwBuilding::getId,YwRoom::getBuildingId)
                .leftJoin(YwFloor.class,YwFloor::getId,YwRoom::getFloor);
        pageWrap.getModel().setIsdeleted(Constants.ZERO);
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.eq(YwRoom::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.eq(YwRoom::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.ge(YwRoom::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.le(YwRoom::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.eq(YwRoom::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.ge(YwRoom::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.le(YwRoom::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.eq(YwRoom::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.eq(YwRoom::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.eq(YwRoom::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.eq(YwRoom::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.eq(YwRoom::getSortnum, pageWrap.getModel().getSortnum());
        }
        if (pageWrap.getModel().getImgurl() != null) {
            queryWrapper.eq(YwRoom::getImgurl, pageWrap.getModel().getImgurl());
        }
        if (pageWrap.getModel().getCode() != null) {
            queryWrapper.eq(YwRoom::getCode, pageWrap.getModel().getCode());
        }
        if (pageWrap.getModel().getRoomNum() != null) {
            queryWrapper.eq(YwRoom::getRoomNum, pageWrap.getModel().getRoomNum());
        }
        if (pageWrap.getModel().getIsInvestment() != null) {
            queryWrapper.eq(YwRoom::getIsInvestment, pageWrap.getModel().getIsInvestment());
        }
        if (pageWrap.getModel().getArea() != null) {
            queryWrapper.eq(YwRoom::getArea, pageWrap.getModel().getArea());
        }
        if (pageWrap.getModel().getFeeArea() != null) {
            queryWrapper.eq(YwRoom::getFeeArea, pageWrap.getModel().getFeeArea());
        }
        if (pageWrap.getModel().getRentArea() != null) {
            queryWrapper.eq(YwRoom::getRentArea, pageWrap.getModel().getRentArea());
        }
        if (pageWrap.getModel().getFloor() != null) {
            queryWrapper.eq(YwRoom::getFloor, pageWrap.getModel().getFloor());
        }
        if (pageWrap.getModel().getProjectId() != null) {
            queryWrapper.eq(YwRoom::getProjectId, pageWrap.getModel().getProjectId());
        }
        if (pageWrap.getModel().getBuildingId() != null) {
            queryWrapper.eq(YwRoom::getBuildingId, pageWrap.getModel().getBuildingId());
        }
        queryWrapper.orderByAsc(YwRoom::getRoomNum);
        IPage<YwRoom> iPage = ywRoomMapper.selectJoinPage(page,YwRoom.class, queryWrapper);
//        for (YwRoom ywRoom:iPage.getRecords()) {
//            if(Constants.equalsInteger(ywRoom.getIsInvestment(),Constants.ZERO)){
//                ywRoom.setLeaseStatus(Constants.TWO);
//            }
//        }
        return PageData.from(iPage);
    }
 
    @Override
    public long count(YwRoom ywRoom) {
        QueryWrapper<YwRoom> wrapper = new QueryWrapper<>(ywRoom);
        return ywRoomMapper.selectCount(wrapper);
    }
 
 
 
    @Override
    public List<YwFloorStatusDataVO>  getRoomStatusList(YwRoom model){
        if(Objects.isNull(model)
        || (Objects.isNull(model.getBuildingId()) && Objects.isNull(model.getFloor()))){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        List<YwFloorStatusDataVO> ywFloorStatusDataVOList = new ArrayList<>();
        List<YwFloor> ywFloorList = ywFloorMapper.selectList(new QueryWrapper<YwFloor>().lambda()
                .eq(YwFloor::getIsdeleted,Constants.ZERO)
                .eq(Objects.nonNull(model.getBuildingId()),YwFloor::getBuildingId,model.getBuildingId())
                .eq(Objects.nonNull(model.getFloor()),YwFloor::getId,model.getFloor())
                .orderByAsc(YwFloor::getFloor)
        );
        List<YwRoom> ywRoomList = ywRoomMapper.selectList(new QueryWrapper<YwRoom>().lambda()
                .eq(YwRoom::getIsdeleted,Constants.ZERO)
                .eq(YwRoom::getIsInvestment,Constants.ONE)
                .eq(YwRoom::getStatus,Constants.ZERO)
                .eq(Objects.nonNull(model.getBuildingId()),YwRoom::getBuildingId,model.getBuildingId())
                .eq(Objects.nonNull(model.getFloor()),YwRoom::getFloor,model.getFloor())
                .orderByAsc(YwRoom::getSortnum)
        );
        List<YwRoomStatusDataVO> roomStatusDataList = new ArrayList<>();
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywRoomList)){
            for (YwRoom ywRoom:ywRoomList) {
                YwRoomStatusDataVO roomStatusDataVO = new YwRoomStatusDataVO();
                roomStatusDataVO.setFloorId(ywRoom.getFloor());
                roomStatusDataVO.setRoomId(ywRoom.getId());
                roomStatusDataVO.setRoomCode(ywRoom.getRoomNum());
                roomStatusDataVO.setRoomRentArea(ywRoom.getRentArea());
 
                List<YwContract> roomContractList =   ywContractMapper.selectJoinList(YwContract.class,new MPJLambdaWrapper<YwContract>()
                        .selectAll(YwContract.class)
                        .selectAs(YwCustomer::getName,YwContract::getRenterName)
                        .leftJoin(YwContractRoom.class,YwContractRoom::getContractId,YwContract::getId)
                        .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                        .eq(YwContract::getIsdeleted,Constants.ZERO)
                        .le(YwContract::getStartDate, DateUtil.getCurrDateTime())
                        .ge(YwContract::getEndDate, DateUtil.getCurrDateTime())
                        .eq(YwContractRoom::getType,Constants.ZERO)
                        .eq(YwContractRoom::getRoomId,ywRoom.getId())
                        .orderByDesc(YwContract::getStartDate)
                        .orderByDesc(YwContract::getId)
                );
                if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(roomContractList)){
                    roomStatusDataVO.setRoomStatus(Constants.ZERO);
                    //查询是否有已退租合同
                    List<YwContract> roomRentContractList =   ywContractMapper.selectJoinList(YwContract.class,new MPJLambdaWrapper<YwContract>()
                            .selectAll(YwContract.class)
                            .selectAs(YwCustomer::getName,YwContract::getRenterName)
                            .leftJoin(YwContractRoom.class,YwContractRoom::getContractId,YwContract::getId)
                            .leftJoin(YwCustomer.class,YwCustomer::getId,YwContract::getRenterId)
                            .eq(YwContract::getIsdeleted,Constants.ZERO)
                            .eq(YwContract::getStatus,Constants.FOUR)
                            .eq(YwContractRoom::getType,Constants.ZERO)
                            .eq(YwContractRoom::getRoomId,ywRoom.getId())
                            .orderByDesc(YwContract::getStartDate)
                            .orderByDesc(YwContract::getId)
                    );
                    if(CollectionUtils.isEmpty(roomRentContractList)){
                        roomStatusDataVO.setFreeDayAmount(Constants.ZERO);
                    }else{
                        YwContract ywContract = roomRentContractList.get(Constants.ZERO);
                        //查询退租日期和当前日期相差天数
                        Integer btDays = DateUtil.daysBetweenDates(new Date(),ywContract.getBtDate());
                        if(btDays>=Constants.ZERO){
                            roomStatusDataVO.setFreeDayAmount(btDays);
                        }
                    }
 
                }else{
                    YwContract ywContract = roomContractList.get(Constants.ZERO);
                    //合同状态 0待执行 1执行中 2已到期 3退租中 4已退租
                    //待执行/执行中/退租中 均属于已出租 根据具体到期时间判断是否处于即将到期 90天
                    if(Constants.equalsInteger(ywContract.getStatus(),Constants.ZERO)||Constants.equalsInteger(ywContract.getStatus(),Constants.ONE)||
                            Constants.equalsInteger(ywContract.getStatus(),Constants.THREE)){
                        roomStatusDataVO.setRoomStatus(Constants.ONE);
                        roomStatusDataVO.setCustomerName(ywContract.getRenterName());
                        if(Constants.equalsInteger(ywContract.getStatus(),Constants.THREE)){
                            if(Objects.nonNull(ywContract.getBtDate()) && DateUtil.getBetweenDays(DateUtil.getFomartDate(ywContract.getBtDate(),"yyyy-MM-dd"),DateUtil.getFomartDate(new Date(),"yyyy-MM-dd"))<=90){
                                roomStatusDataVO.setRoomStatus(Constants.TWO);
                                roomStatusDataVO.setOverData(ywContract.getBtDate());
                            }
                        }else{
                            System.out.println(DateUtil.daysBetweenDates(ywContract.getEndDate(),new Date()));
                            if(Objects.nonNull(ywContract.getEndDate())
                                    &&
                                DateUtil.daysBetweenDates(ywContract.getEndDate(),new Date())<=90){
                                roomStatusDataVO.setRoomStatus(Constants.TWO);
                                roomStatusDataVO.setOverData(ywContract.getEndDate());
                            }else{
                                roomStatusDataVO.setOverData(ywContract.getEndDate());
                            }
                        }
                    }else{
                        roomStatusDataVO.setRoomStatus(Constants.ZERO);
                        //已退租 计算退租时间
                        if(Objects.nonNull(ywContract.getBtDate())){
                            //查询退租日期和当前日期相差天数
                            Integer btDays = DateUtil.daysBetweenDates(new Date(),ywContract.getBtDate());
                            if(btDays>=Constants.ZERO){
                                roomStatusDataVO.setFreeDayAmount(btDays);
                            }
                        }
                    }
                }
                roomStatusDataList.add(roomStatusDataVO);
            }
        }
        for (YwFloor ywFloor:ywFloorList) {
            YwFloorStatusDataVO ywFloorStatusDataVO = new YwFloorStatusDataVO();
            ywFloorStatusDataVO.setFloorName(ywFloor.getName());
            ywFloorStatusDataVO.setFloorId(ywFloor.getId());
            ywFloorStatusDataVO.setFloorArea(BigDecimal.ZERO);
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(roomStatusDataList)){
                List<YwRoomStatusDataVO> floorRoomList = roomStatusDataList.stream().filter(i->Objects.nonNull(i.getFloorId())&&Constants.equalsInteger(i.getFloorId(),ywFloor.getId())).collect(Collectors.toList());
                ywFloorStatusDataVO.setYwRoomStatusDataVOList(floorRoomList);
                if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(floorRoomList)){
                    ywFloorStatusDataVO.setFloorArea(floorRoomList.stream().filter(i->Objects.nonNull(i.getRoomRentArea())).map(i->i.getRoomRentArea()).reduce(BigDecimal.ZERO,BigDecimal::add));
                }
            }
            ywFloorStatusDataVOList.add(ywFloorStatusDataVO);
        }
        return ywFloorStatusDataVOList;
    }
 
 
    @Override
    public YwRoomContractDataVO getRoomContract(YwRoom model){
        if(Objects.isNull(model)
                || (Objects.isNull(model.getBuildingId()) && Objects.isNull(model.getProjectId()))){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        YwRoomContractDataVO ywRoomContractDataVO = new YwRoomContractDataVO();
        ywRoomContractDataVO.setInvestmentRoomAmount(Constants.ZERO);
        ywRoomContractDataVO.setInvestmentArea(BigDecimal.ZERO);
        ywRoomContractDataVO.setLeaseContractAmount(Constants.ZERO);
        ywRoomContractDataVO.setLeasePrice(BigDecimal.ZERO);
        ywRoomContractDataVO.setLeaseArea(BigDecimal.ZERO);
        ywRoomContractDataVO.setLeaseRoomAmount(Constants.ZERO);
        ywRoomContractDataVO.setLeaseDayPrice(BigDecimal.ZERO);
 
        List<YwRoom> ywRoomList = ywRoomMapper.selectList(new QueryWrapper<YwRoom>().lambda()
                .eq(YwRoom::getIsdeleted,Constants.ZERO)
                .eq(YwRoom::getStatus,Constants.ZERO)
                .eq(YwRoom::getIsInvestment,Constants.ONE)
                .eq(Objects.nonNull(model.getBuildingId()),YwRoom::getBuildingId,model.getBuildingId())
                .eq(Objects.nonNull(model.getProjectId()),YwRoom::getProjectId,model.getProjectId())
                .orderByAsc(YwRoom::getSortnum)
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywRoomList)){
            return ywRoomContractDataVO;
        }
        ywRoomContractDataVO.setInvestmentRoomAmount(ywRoomList.size());
        ywRoomContractDataVO.setInvestmentArea(ywRoomList.stream().filter(i->Objects.nonNull(i.getRentArea())).map(i->i.getRentArea()).reduce(BigDecimal.ZERO,BigDecimal::add));
 
        List<YwContract> roomContractList =   ywContractMapper.selectJoinList(YwContract.class,new MPJLambdaWrapper<YwContract>()
                .selectAll(YwContract.class)
                .select(" ( select  ifnull(sum(yr.RENT_AREA),0)  from yw_contract_room y left join yw_room yr on y.room_id = yr.id  where y.type = 0 and y.CONTRACT_ID = t.id ) " , YwContract::getTotalArea)
                .select(" ( select  ifnull(sum(y.TOTLE_FEE),0)  from yw_contract_bill y   where y.CONTRACT_ID = t.id and y.type = 0 and y.COST_TYPE=0 and y.BILL_TYPE = 0  ) " , YwContract::getTotalFee)
                .eq(YwContract::getIsdeleted,Constants.ZERO)
                .in(YwContract::getStatus,Constants.ZERO,Constants.ONE,Constants.TWO,Constants.THREE)
                .apply(Objects.nonNull(model.getBuildingId()),
                        " t.id in ( select y.CONTRACT_ID from yw_contract_room y left join yw_room yr on y.room_id = yr.id  where y.type = 0 and  yr.BUILDING_ID = "+model.getBuildingId()+" ) ")
                .apply(Objects.nonNull(model.getProjectId()),
                        " t.id in ( select y.CONTRACT_ID from yw_contract_room y left join yw_room yr on y.room_id = yr.id  where y.type = 0 and  yr.PROJECT_ID = "+model.getProjectId()+" ) ")
                .orderByDesc(YwContract::getStartDate)
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(roomContractList)){
            return ywRoomContractDataVO;
        }
        //处理租赁单价 根据  合同租赁总额 /  (租赁时长 * 租赁面积)
        for (YwContract ywContract:roomContractList) {
            long contractDayAmount = DateUtil.daysBetweenDates(ywContract.getEndDate()
                    ,ywContract.getStartDate());
            if(Objects.nonNull(contractDayAmount) && Objects.nonNull(ywContract.getTotalArea()) && Objects.nonNull(ywContract.getTotalFee())){
                ywRoomContractDataVO.setLeaseDayPrice(
                        ywRoomContractDataVO.getLeaseDayPrice().add(
                            ywContract.getTotalFee().divide((ywContract.getTotalArea().multiply(new BigDecimal(Long.toString(contractDayAmount)))),2,BigDecimal.ROUND_HALF_UP)
                        )
                );
            }
        }
        ywRoomContractDataVO.setLeaseContractAmount(roomContractList.size());
        if(Objects.nonNull(ywRoomContractDataVO.getLeaseDayPrice())&&ywRoomContractDataVO.getLeaseDayPrice().compareTo(BigDecimal.ZERO)>Constants.ZERO){
            ywRoomContractDataVO.setLeasePrice(
                    ywRoomContractDataVO.getLeaseDayPrice().divide(new BigDecimal(Integer.toString(ywRoomContractDataVO.getLeaseContractAmount())),2,BigDecimal.ROUND_HALF_UP));
        }
        List<Integer> contractId = roomContractList.stream().map(i->i.getId()).collect(Collectors.toList());
        List<YwRoom> ywLeaseRoomList = ywRoomMapper.selectJoinList(YwRoom.class,new MPJLambdaWrapper<YwRoom>()
                .selectAll(YwRoom.class)
                .leftJoin(YwContractRoom.class,YwContractRoom::getRoomId,YwRoom::getId)
                .eq(YwRoom::getIsdeleted,Constants.ZERO)
                .eq(YwRoom::getIsInvestment,Constants.ONE)
                .eq(YwRoom::getStatus,Constants.ZERO)
                .eq(Objects.nonNull(model.getBuildingId()),YwRoom::getBuildingId,model.getBuildingId())
                .eq(Objects.nonNull(model.getProjectId()),YwRoom::getProjectId,model.getProjectId())
                .in(YwContractRoom::getContractId,contractId)
                .last(" group by t.id  " +
                        "ORDER BY t.sortnum ASC  ")
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywLeaseRoomList)){
            ywRoomContractDataVO.setLeaseArea(
                    ywLeaseRoomList.stream().filter(i->Objects.nonNull(i.getRentArea())).map(i->i.getRentArea()).reduce(BigDecimal.ZERO,BigDecimal::add)
            );
            ywRoomContractDataVO.setLeaseRoomAmount(ywLeaseRoomList.size());
        }
        return ywRoomContractDataVO;
    }
 
 
 
}