package com.bonus.material.lease.service.impl;

import com.bonus.common.biz.domain.BmFileInfo;
import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.biz.enums.OrderStatusEnum;
import com.bonus.common.biz.enums.TmTaskTypeEnum;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.device.mapper.BmFileInfoMapper;
import com.bonus.material.lease.domain.LeasePriceRecord;
import com.bonus.material.lease.domain.LeaseRecordDto;
import com.bonus.material.lease.domain.LeaseRepair;
import com.bonus.material.lease.domain.LeaseRepairRecord;
import com.bonus.material.lease.mapper.LeaseRepairRecordMapper;
import com.bonus.material.lease.service.LeaseRepairRecordService;
import com.bonus.material.order.domain.OrderDetailDto;
import com.bonus.material.order.domain.OrderInfoDto;
import com.bonus.material.order.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author ma_sh
 * @create 2024/12/2 15:34
 */
@Service
@Slf4j
public class LeaseRepairRecordServiceImpl implements LeaseRepairRecordService {

    private static final String DEVICE_NAME_ERROR = "的数量不能大于设备数量";

    @Resource
    private LeaseRepairRecordMapper mapper;

    @Resource
    private BmFileInfoMapper bmFileInfoMapper;

    @Resource
    private OrderMapper orderMapper;

    /**
     * 查询租赁需求列表
     * @param dto
     * @return
     */
    @Override
    public List<LeaseRepair> list(LeaseRepair dto) {
        List<LeaseRepair> list = mapper.list(dto);
        if (CollectionUtils.isNotEmpty(list)) {
            for (LeaseRepair leaseRepairVo : list) {
                //根据订单id去lease_repair_record表中查询是否已填写退租检修信息
                int count = mapper.selectLeaseContent(leaseRepairVo.getOrderId());
                if (count > 0) {
                    leaseRepairVo.setIsLeaseContent(1);
                } else {
                    leaseRepairVo.setIsLeaseContent(0);
                }
                if (leaseRepairVo.getOrderId() != null) {
                    LeaseRecordDto leaseRecordDto = getById(leaseRepairVo);
                    leaseRepairVo.setTotalCost(leaseRecordDto.getTotalCost());
                    leaseRepairVo.setIsChangePrice(leaseRecordDto.getIsChangePrice());
                }

            }
            if (dto.getTotalCostMin() != null && dto.getTotalCostMax() != null) {
                list = list.stream()
                        .filter(leaseRepair -> {
                            BigDecimal totalCost = leaseRepair.getTotalCost();
                            return totalCost != null && totalCost.compareTo(dto.getTotalCostMin()) >= 0 && totalCost.compareTo(dto.getTotalCostMax()) <= 0;
                        })
                        .collect(Collectors.toList());
            }
        }
        return list;
    }

    /**
     * 查询退租检修单个详情
     * @param dto
     * @return
     */
    @Override
    public LeaseRecordDto getById(LeaseRepair dto) {
        // 初始化总费用
        BigDecimal totalCost = new BigDecimal(0.00);
        LeaseRecordDto leaseRecordDto = new LeaseRecordDto();
        OrderDetailDto orderDetailDto = new OrderDetailDto();
        orderDetailDto.setOrderId(Integer.parseInt(dto.getOrderId()));
        OrderInfoDto orderInfoDto = orderMapper.getOrderDetailsById(orderDetailDto);
        if (orderInfoDto != null) {
            leaseRecordDto.setCode(orderInfoDto.getCode());
            leaseRecordDto.setMaNumber(orderInfoDto.getMaNumber());
            leaseRecordDto.setLeaseCompany(orderInfoDto.getCzcompanyName());
        }
        List<OrderDetailDto> orderDetailList = orderMapper.selectOrderDetailsByOrderId(dto.getOrderId());
        if (CollectionUtils.isNotEmpty(orderDetailList)) {
            for (OrderDetailDto detailDto : orderDetailList) {
                detailDto.setDays(detailDto.getDateDays() == null ? detailDto.getDays() : String.valueOf(detailDto.getDateDays()));
                if (detailDto.getChangeCost() != null) {
                    leaseRecordDto.setIsChangePrice(1);
                    totalCost = totalCost.add(detailDto.getChangeCost());
                } else {
                    if (detailDto.getDateDays() != null && detailDto.getDateDays() > 0
                            && detailDto.getDayLeasePrice() != null) {
                        BigDecimal newTotalPrice = detailDto.getDayLeasePrice().multiply(new BigDecimal(detailDto.getDateDays()))
                                .setScale(2, RoundingMode.HALF_UP);
                        totalCost = totalCost.add(newTotalPrice);
                        detailDto.setCosts(newTotalPrice);
                    }
                }
                if (detailDto.getReliefChangeCost() != null) {
                    totalCost.subtract(detailDto.getReliefChangeCost());
                } else if (detailDto.getReliefCost() != null) {
                    totalCost.subtract(detailDto.getReliefCost());
                }
            }
            leaseRecordDto.setOrderDetailDtoList(orderDetailList);
        }
        // 根据订单id查询订单详情
        List<LeaseRepairRecord> list = mapper.getLeaseRepairRecordList(dto);
        if (CollectionUtils.isNotEmpty(list)) {
            List<BmFileInfo> fileList = new ArrayList<>();
            for (LeaseRepairRecord leaseRepairRecord : list) {
                if (leaseRepairRecord.getRepairChangePrice() != null || leaseRepairRecord.getScrapChangePrice() != null
                        || leaseRepairRecord.getLossChangePrice() != null) {
                    leaseRecordDto.setIsChangePrice(1);
                }
                if (leaseRepairRecord.getRepairChangePrice() != null) {
                    totalCost = totalCost.add(leaseRepairRecord.getRepairChangePrice());
                } else if (leaseRepairRecord.getRepairPrice() != null) {
                    totalCost = totalCost.add(leaseRepairRecord.getRepairPrice());
                }
                if (leaseRepairRecord.getScrapChangePrice() != null) {
                    totalCost = totalCost.add(leaseRepairRecord.getScrapChangePrice());
                } else if (leaseRepairRecord.getScrapPrice() != null) {
                    totalCost = totalCost.add(leaseRepairRecord.getScrapPrice());
                }
                if (leaseRepairRecord.getLossChangePrice() != null) {
                    totalCost = totalCost.add(leaseRepairRecord.getLossChangePrice());
                } else if (leaseRepairRecord.getLossPrice() != null) {
                    totalCost = totalCost.add(leaseRepairRecord.getLossPrice());
                }
                BmFileInfo bmFileInfo = new BmFileInfo();
                bmFileInfo.setModelId(Long.valueOf(leaseRepairRecord.getMaId()));
                bmFileInfo.setTaskType(TmTaskTypeEnum.TM_TASK_ADD_REPAIR_TASK.getTaskTypeId());
                fileList.addAll(bmFileInfoMapper.selectBmFileInfoList(bmFileInfo));
                if (leaseRecordDto.getRepairRecordList() == null) {
                    leaseRecordDto.setRepairRecordList(new ArrayList<>());
                }
                if (leaseRepairRecord.getRepairPrice() != null) {
                    leaseRecordDto.getRepairRecordList().add(leaseRepairRecord);
                }
                if (leaseRecordDto.getScrapRecordList() == null) {
                    leaseRecordDto.setScrapRecordList(new ArrayList<>());
                }
                if (leaseRepairRecord.getScrapPrice() != null) {
                    leaseRecordDto.getScrapRecordList().add(leaseRepairRecord);
                }
                if (leaseRecordDto.getLossRecordList() == null) {
                    leaseRecordDto.setLossRecordList(new ArrayList<>());
                }
                if (leaseRepairRecord.getLossPrice() != null) {
                    leaseRecordDto.getLossRecordList().add(leaseRepairRecord);
                }
            }
            if (CollectionUtils.isNotEmpty(fileList)) {
                leaseRecordDto.setFileInfoList(fileList);
            }
        }
        leaseRecordDto.setTotalCost(totalCost);
        return leaseRecordDto;
    }

    /**
     * 新增退租检修
     * @param leaseRecordDto
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(LeaseRecordDto leaseRecordDto) {
        if (leaseRecordDto == null || leaseRecordDto.getOrderId() == null || leaseRecordDto.getCode() == null) {
            return AjaxResult.error(HttpCodeEnum.TO_PARAM_NULL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
        }
        Set<Integer> maIdSet = new HashSet<>();
        List<Integer> maIds_repair = new ArrayList<>();
        List<Integer> maIds_scrap = new ArrayList<>();
        List<Integer> maIds_loss = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(leaseRecordDto.getRepairRecordList())) {
            maIds_repair = leaseRecordDto.getRepairRecordList().stream().map(LeaseRepairRecord::getMaId).collect(Collectors.toList());
        }
        if (CollectionUtils.isNotEmpty(leaseRecordDto.getScrapRecordList())) {
            maIds_scrap = leaseRecordDto.getScrapRecordList().stream().map(LeaseRepairRecord::getMaId).collect(Collectors.toList());
        }
        if (CollectionUtils.isNotEmpty(leaseRecordDto.getLossRecordList())) {
            maIds_loss = leaseRecordDto.getLossRecordList().stream().map(LeaseRepairRecord::getMaId).collect(Collectors.toList());
        }
        maIdSet.addAll(maIds_repair);
        maIdSet.addAll(maIds_scrap);
        maIdSet.addAll(maIds_loss);

        LeaseRepairRecord leaseRepairRecord = createLeaseRepairRecord(leaseRecordDto);
        // 校验所有记录是否为空
//        if (isAllRecordListsEmpty(leaseRecordDto)) {
//            return insertRecord(leaseRepairRecord);
//        }
        try {
            // 处理维修、报废、丢失记录的情况
            return handleAllRecords(leaseRecordDto, new ArrayList<>(maIdSet));
        } catch (Exception e) {
            log.error("新增退租检修异常: ", e.getMessage());
            return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), e.getMessage());
        }
    }

    /**
     * 装备费用改价
     * @param leasePriceRecord
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult changePrice(LeasePriceRecord leasePriceRecord) {
        int result = 0;
        List<LeaseRepairRecord> rentPriceList = leasePriceRecord.getRentPriceList();
        List<LeaseRepairRecord> repairPriceList = leasePriceRecord.getRepairPriceList();
        List<LeaseRepairRecord> scrapPriceList = leasePriceRecord.getScrapPriceList();
        List<LeaseRepairRecord> lossPriceList = leasePriceRecord.getLossPriceList();
        //租赁费用列表不为空
        if (CollectionUtils.isNotEmpty(rentPriceList)) {
            for (LeaseRepairRecord leaseRepairRecord : rentPriceList) {
                if (leaseRepairRecord.getOrderId() == null || leaseRepairRecord.getMaId() == null ||
                        leaseRepairRecord.getChangeCost() == null) {
                    return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
                }
                leaseRepairRecord.setChangePriceUser(SecurityUtils.getUserId());
                result += mapper.updateRentPrice(leaseRepairRecord);
            }
        }
        //维修费用列表不为空
        if (CollectionUtils.isNotEmpty(repairPriceList)) {
            for (LeaseRepairRecord repairRecord : repairPriceList) {
                if (repairRecord.getOrderId() == null || repairRecord.getMaId() == null ||
                        repairRecord.getRepairChangePrice() == null) {
                    return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
                }
                repairRecord.setChangePriceUser(SecurityUtils.getUserId());
                result += mapper.updateChangePrice(repairRecord);
            }
        }
        //报废费用列表不为空
        if (CollectionUtils.isNotEmpty(scrapPriceList)) {
            for (LeaseRepairRecord scrapRecord : scrapPriceList) {
                if (scrapRecord.getOrderId() == null || scrapRecord.getMaId() == null ||
                        scrapRecord.getScrapChangePrice() == null) {
                    return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
                }
                scrapRecord.setChangePriceUser(SecurityUtils.getUserId());
                result += mapper.updateChangePrice(scrapRecord);
            }
        }
        //丢失费用列表不为空
        if (CollectionUtils.isNotEmpty(lossPriceList)) {
            for (LeaseRepairRecord lossRecord : lossPriceList) {
                if (lossRecord.getOrderId() == null || lossRecord.getMaId() == null ||
                        lossRecord.getLossChangePrice() == null) {
                    return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
                }
                lossRecord.setChangePriceUser(SecurityUtils.getUserId());
                result += mapper.updateChangePrice(lossRecord);
            }
        }
        String userName = SecurityUtils.getLoginUser().getUsername();
        result += orderMapper.updateOrderStatus(leasePriceRecord.getOrderId(), null, String.valueOf(OrderStatusEnum.ORDER_TERMINATED.getStatus()), userName, null);
        if (result > 0) {
            return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg());
        }
        return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
    }

    /**
     * 承租方费用确定
     * @param leaseRepairRecord
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult confirmPrice(LeaseRepairRecord leaseRepairRecord) {
        if (leaseRepairRecord.getOrderId() == null) {
            return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.TO_PARAM_NULL.getMsg());
        }
        leaseRepairRecord.setPriceConfirmUser(SecurityUtils.getUserId());
        //将费用确认人信息存入
        int count = mapper.getCountByOrderId(leaseRepairRecord.getOrderId());
        int result = 0;
        if (count > 0) {
            result = mapper.update(leaseRepairRecord);
        } else {
            result++; //没找到需要更新的记录，默认为是已经处理过了
        }
        //修改订单状态为已完成
        if (result > 0) {
            leaseRepairRecord.setOrderStatus(OrderStatusEnum.ORDER_FINISHED.getStatus());
            result += orderMapper.updateOrder(leaseRepairRecord);
        }
        if (result > 0) {
            return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg());
        }
        return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
    }

    /**
     * 处理维修、报废、丢失记录都有的情况
     * @param leaseRecordDto
     * @param maIdList
     * @return
     */
    private AjaxResult handleAllRecords(LeaseRecordDto leaseRecordDto, List<Integer> maIdList) {
        int result = 0;
        for (Integer maId : maIdList) {
            LeaseRepairRecord leaseRepairRecord = createLeaseRepairRecord(leaseRecordDto);
            // 获取对应的记录集合
            List<LeaseRepairRecord> repairRecordList = filterRecordsByMaId(leaseRecordDto.getRepairRecordList(), maId);
            List<LeaseRepairRecord> scrapRecordList = filterRecordsByMaId(leaseRecordDto.getScrapRecordList(), maId);
            List<LeaseRepairRecord> lossRecordList = filterRecordsByMaId(leaseRecordDto.getLossRecordList(), maId);

            // 获取数量
            int repairNum = sumRecordNum(repairRecordList, LeaseRepairRecord::getRepairNum);
            int scrapNum = sumRecordNum(scrapRecordList, LeaseRepairRecord::getScrapNum);
            int lossNum = sumRecordNum(lossRecordList, LeaseRepairRecord::getLossNum);

            // 检查数量是否合法
            if (!isValidNumber(repairRecordList, scrapRecordList, lossRecordList, repairNum, scrapNum, lossNum)) {
                return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
            }

            // 插入维修、报废、丢失记录
            result += insertRepairScrapLossRecords(repairRecordList, leaseRepairRecord);
            result += insertRepairScrapLossRecords(scrapRecordList, leaseRepairRecord);
            result += insertRepairScrapLossRecords(lossRecordList, leaseRepairRecord);

            // 插入前删掉旧的维修记录
            mapper.deleteLeaseRepairRecord(leaseRepairRecord);

            // 执行插入操作
            result += mapper.insert(leaseRepairRecord);
        }
//        LeaseRepairRecord leaseRepairRecord = new LeaseRepairRecord();
//        leaseRepairRecord.setOrderId(leaseRecordDto.getOrderId());
//        leaseRepairRecord.setOrderStatus(OrderStatusEnum.ORDER_REPAIRED.getStatus());
//        leaseRepairRecord.setMaIds(maIdList);
//        result += orderMapper.updateOrder(leaseRepairRecord);
        // 返回结果
        return result > 0 ? AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg())
                : AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
    }

    /**
     * 根据maId过滤记录
     * @param recordList
     * @param maId
     * @return
     */
    private List<LeaseRepairRecord> filterRecordsByMaId(List<LeaseRepairRecord> recordList, Integer maId) {
        return recordList.stream().filter(item -> item.getMaId().equals(maId)).collect(Collectors.toList());
    }

    /**
     * 获取数量
     * @param recordList
     * @param getNum
     * @return
     */
    private int sumRecordNum(List<LeaseRepairRecord> recordList, Function<LeaseRepairRecord, Integer> getNum) {
        return recordList.stream()
                .mapToInt(record -> Optional.ofNullable(getNum.apply(record)).orElse(0))
                .sum();
    }

    /**
     * 检查数量是否合法
     * @param repairRecordList
     * @param scrapRecordList
     * @param lossRecordList
     * @param repairNum
     * @param scrapNum
     * @param lossNum
     * @return
     */
    private boolean isValidNumber(List<LeaseRepairRecord> repairRecordList, List<LeaseRepairRecord> scrapRecordList,
                                  List<LeaseRepairRecord> lossRecordList, int repairNum, int scrapNum, int lossNum) {
        int num = getFirstValidRecordNum(repairRecordList, scrapRecordList, lossRecordList);
        if (repairNum > 0 && scrapNum == 0 && lossNum == 0 && repairNum > num) {
            throw new ServiceException(repairRecordList.get(0).getDeviceName() + DEVICE_NAME_ERROR, HttpCodeEnum.FAIL.getCode());
        }
        if (repairNum == 0 && scrapNum > 0 && lossNum == 0 && scrapNum > num) {
            throw new ServiceException(scrapRecordList.get(0).getDeviceName() + DEVICE_NAME_ERROR, HttpCodeEnum.FAIL.getCode());
        }
        if (repairNum == 0 && scrapNum == 0 && lossNum > 0 && lossNum > num) {
            throw new ServiceException(lossRecordList.get(0).getDeviceName() + DEVICE_NAME_ERROR, HttpCodeEnum.FAIL.getCode());
        }
        if (repairNum > 0 && scrapNum > 0 && lossNum == 0 && repairNum + scrapNum > num) {
            throw new ServiceException(repairRecordList.get(0).getDeviceName() + "的维修数量+报废数量不能大于设备数量", HttpCodeEnum.FAIL.getCode());
        }
        if (repairNum > 0 && scrapNum == 0 && lossNum > 0 && repairNum + lossNum > num) {
            throw new ServiceException(repairRecordList.get(0).getDeviceName() + "的维修数量+丢失数量不能大于设备数量", HttpCodeEnum.FAIL.getCode());
        }
        if (repairNum == 0 && scrapNum > 0 && lossNum > 0 && scrapNum + lossNum > num) {
            throw new ServiceException(scrapRecordList.get(0).getDeviceName() + "的报废数量+丢失数量不能大于设备数量", HttpCodeEnum.FAIL.getCode());
        }
        if (repairNum > 0 && scrapNum > 0 && lossNum > 0 && repairNum + scrapNum + lossNum > num) {
            throw new ServiceException(repairRecordList.get(0).getDeviceName() + "维修数量+报废数量+丢失数量不能大于设备数量", HttpCodeEnum.FAIL.getCode());
        }
        return true;
    }

    /**
     * 获取第一个有效的记录数量
     * @param repairRecordList
     * @param scrapRecordList
     * @param lossRecordList
     * @return
     */
    private int getFirstValidRecordNum(List<LeaseRepairRecord> repairRecordList, List<LeaseRepairRecord> scrapRecordList,
                                       List<LeaseRepairRecord> lossRecordList) {
        if (!repairRecordList.isEmpty()) {
            return sumRecordNum(repairRecordList, LeaseRepairRecord::getNum);
        } else if (!scrapRecordList.isEmpty()) {
            return sumRecordNum(scrapRecordList, LeaseRepairRecord::getNum);
        } else if (!lossRecordList.isEmpty()) {
            return sumRecordNum(lossRecordList, LeaseRepairRecord::getNum);
        }
        return 0;
    }

    /**
     * 插入维修、报废、丢失记录
     * @param recordList
     * @param leaseRepairRecord
     * @return
     */
    private int insertRepairScrapLossRecords(List<LeaseRepairRecord> recordList, LeaseRepairRecord leaseRepairRecord) {
        int result = 0;
        for (LeaseRepairRecord record : recordList) {
            leaseRepairRecord.setMaId(record.getMaId());
            leaseRepairRecord.setTypeId(record.getTypeId());
            leaseRepairRecord.setRepairNum(record.getRepairNum());
            leaseRepairRecord.setRepairPrice(record.getRepairPrice());
            leaseRepairRecord.setScrapNum(record.getScrapNum());
            leaseRepairRecord.setScrapPrice(record.getScrapPrice());
            leaseRepairRecord.setScrapReason(record.getScrapReason() != null ? record.getScrapReason() : "");
            leaseRepairRecord.setLossNum(record.getLossNum());
            leaseRepairRecord.setLossPrice(record.getLossPrice());
            if (CollectionUtils.isNotEmpty(record.getFileInfoList())) {
                for (BmFileInfo bmFileInfo : record.getFileInfoList()) {
                    bmFileInfoMapper.deleteBmFileInfoByBizInfo(bmFileInfo);
                }
                bmFileInfoMapper.insertBmFileInfos(record.getFileInfoList());
            }
            result++;
        }
        return result;
    }

    /**
     * 插入记录
     * @param leaseRepairRecord
     * @return
     */
    private AjaxResult insertRecord(LeaseRepairRecord leaseRepairRecord) {
        int result = mapper.insert(leaseRepairRecord);
        return result > 0 ? AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg()) :
                AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
    }

    /**
     * 创建维修公用类
     * @param leaseRecordDto
     * @return
     */
    private LeaseRepairRecord createLeaseRepairRecord(LeaseRecordDto leaseRecordDto) {
        LeaseRepairRecord leaseRepairRecord = new LeaseRepairRecord();
        leaseRepairRecord.setOrderId(leaseRecordDto.getOrderId());
        leaseRepairRecord.setCode(leaseRecordDto.getCode());
        leaseRepairRecord.setCreateBy(SecurityUtils.getUserId().toString());
        leaseRepairRecord.setCreateTime(DateUtils.getNowDate());
        return leaseRepairRecord;
    }

    /**
     * 判断是否所有记录列表为空
     * @param leaseRecordDto
     * @return
     */
    private boolean isAllRecordListsEmpty(LeaseRecordDto leaseRecordDto) {
        return CollectionUtils.isEmpty(leaseRecordDto.getRepairRecordList()) &&
                CollectionUtils.isEmpty(leaseRecordDto.getScrapRecordList()) &&
                CollectionUtils.isEmpty(leaseRecordDto.getLossRecordList());
    }
}
