package cn.ezhizao.project.business.collection.service.impl;

import cn.ezhizao.common.exception.ServiceException;
import cn.ezhizao.common.utils.StringUtils;
import cn.ezhizao.common.utils.uuid.SnowflakeIdWorker;
import cn.ezhizao.project.business.collection.domain.BizCollection;
import cn.ezhizao.project.business.collection.domain.BizCollectionDetail;
import cn.ezhizao.project.business.collection.domain.CollectionExcelLoopModel;
import cn.ezhizao.project.business.collection.domain.CollectionExcelOnceModel;
import cn.ezhizao.project.business.collection.domain.vo.ReqStatisticsVo;
import cn.ezhizao.project.business.collection.domain.vo.ResStatisticsVo;
import cn.ezhizao.project.business.collection.mapper.BizCollectionDetailMapper;
import cn.ezhizao.project.business.collection.mapper.BizCollectionMapper;
import cn.ezhizao.project.business.collection.service.IBizCollectionService;
import cn.ezhizao.project.business.company.domain.BizCompany;
import cn.ezhizao.project.business.company.service.IBizCompanyService;
import cn.ezhizao.project.business.invoice.domain.BizInvoice;
import cn.ezhizao.project.business.order.domain.BizArchiveInput;
import cn.ezhizao.project.business.order.domain.BizArchiveInputDetail;
import cn.ezhizao.project.business.order.service.IBizArchiveInputDetailService;
import cn.ezhizao.project.business.order.service.IBizArchiveInputService;
import cn.ezhizao.project.system.service.ISysUserService;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cn.ezhizao.common.utils.SecurityUtils.getUserId;

/**
 * @author 朱汕
 */

@Service
public class BizCollectionServiceImpl extends ServiceImpl<BizCollectionMapper, BizCollection> implements IBizCollectionService {

    @Resource
    BizCollectionMapper collectionDao;
    @Resource
    BizCollectionDetailMapper collectionDetailMapper;
    @Resource
    IBizArchiveInputService archiveInputService;
    @Resource
    IBizArchiveInputDetailService archiveInputDetailService;
    @Resource
    IBizCompanyService companyService;
    @Resource
    SnowflakeIdWorker snowflakeIdWorker;
    @Resource
    ISysUserService userService;

    @Override
    public List<BizCollection> getList(Map<String,Object> conditions) {
        return collectionDao.getList(conditions);
    }

    @Override
    public List<BizCollection> getListByBean(BizCollection collection) {
        return collectionDao.getList(collection);
    }

    @Override
    public int getTotal(Map<String,Object> conditions) {
        return collectionDao.getTotal(conditions);
    }

    @Override
    public boolean removeBatchByIds(List<Long> ids) {
        boolean result = super.removeBatchByIds(ids);
        QueryWrapper<BizCollectionDetail> detailQueryWrapper = new QueryWrapper<>();
        detailQueryWrapper.in("collection_id", ids);
        result = result && collectionDetailMapper.delete(detailQueryWrapper) > 0;
        return result;
    }

    @Override
    public String importLoop(List<CollectionExcelLoopModel> collects, Long userId, long tenantId) {

        if (StringUtils.isNull(collects) || collects.size() == 0) {
            throw new ServiceException("导入数据不能为空！");
        }
        List<BizCompany> companies = companyService.query().eq("tenant_id", tenantId).list();
        List<BizCollection> collections = new ArrayList<>();
        List<BizCollectionDetail> details = new ArrayList<>();
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (CollectionExcelLoopModel item: collects) {
            // 获取合同信息
            BizArchiveInput archiveInput = archiveInputService.query().eq("contract_no", item.getContractNo()).eq("from_id",0).eq("service_type",1).eq("tenant_id", tenantId).list().stream().findFirst().orElse(null);
            if (archiveInput == null) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 不存在或不是循环合同");
                continue;
            }
            if(null == item.getAmount()){
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 收款金额不能为空");
                continue;
            }
            if(null == item.getContractAmount()){
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 合同总金额不能为空");
                continue;
            }
            if(archiveInput.getTrueAmount().subtract(item.getContractAmount()).compareTo(BigDecimal.ZERO) != 0){
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append("合同总金额不一致");
                continue;
            }
            BizCompany company = companies.stream().filter(v -> v.getName().equals(item.getCompanyName())).findFirst().orElse(null);
            if (company == null) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、客户 ").append(item.getCompanyName()).append(" 不存在");
                continue;
            }
            if (!archiveInput.getCompanyId().equals(company.getId())) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的客户不是").append(item.getCompanyName());
                continue;
            }
            List<BizArchiveInputDetail> contractDetails = archiveInputDetailService.query().eq("contract_id", archiveInput.getId()).list();
            // 判断明细信息是否和导入信息相符
            // 不相符添加 failureNum 并转到下一条。
            if (item.getKeepAccountAmount() != null && item.getKeepAccountAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(1L))) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有记账报税任务");
                continue;
            }
            if (item.getSecurityAmount() != null && item.getSecurityAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(2L))) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有社保代缴任务");
                continue;
            }
            if (item.getHousingFundAmount() != null && item.getHousingFundAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(3L))) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有公积金代缴任务");
                continue;
            }
            if (item.getReturnTaxAmount() != null && item.getReturnTaxAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(4L))) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有返税申报任务");
                continue;
            }
            //查询收款记录
            LambdaQueryWrapper<BizCollection> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(BizCollection::getContractId, archiveInput.getId());
            wrapper.and(con -> con.eq(BizCollection::getStatus, 0).or().eq(BizCollection::getStatus, 1));
            List<BizCollection> collected = this.list(wrapper);
            BigDecimal collectedAmount = BigDecimal.valueOf(collected.stream().mapToDouble(v -> v.getArriveAmount().doubleValue()).sum());
            if(null == item.getAmount() ||  null == archiveInput.getTrueAmount() ||item.getAmount().subtract(archiveInput.getTrueAmount().subtract(collectedAmount)).compareTo(BigDecimal.ZERO) >0){
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("现系统内收款加上excel表内收款金额已超出合同收款总金额");
                continue;
            }

            BizCollection bizCollection = new BizCollection();
            bizCollection.setId(snowflakeIdWorker.nextId());
            bizCollection.setContractId(archiveInput.getId());
            bizCollection.setFlowNo(String.valueOf(snowflakeIdWorker.nextId()));
            bizCollection.setApplierId(getUserId());
            //实际付款时间默认未当前时间
            bizCollection.setActuallyDate(DateTime.now().toTimestamp());
            bizCollection.setContractNo(archiveInput.getContractNo());
            bizCollection.setCompanyId(archiveInput.getCompanyId());
//            bizCollection.setSubsidiaryBankAccount(item.getSubsidiaryBankAccount());
//            bizCollection.setSubsidiaryName(item.getSubsidiaryName());
//            bizCollection.setSubsidiaryBankName(item.getSubsidiaryBankName());
            bizCollection.setAmount(item.getContractAmount());
            bizCollection.setArriveAmount(item.getAmount());
//            bizCollection.setArriveDate(DateTime.of(item.getArriveDate()).toTimestamp());
            bizCollection.setVerifyStatus(1);
            bizCollection.setStatus((byte)1);
            bizCollection.setArriveStatus((byte)1);
            bizCollection.setVerifyDate(DateTime.now().toTimestamp());
//            bizCollection.setArriveTime(DateTime.of(item.getArriveTime()).toString("HH:mm"));
            bizCollection.setTenantId(tenantId);
//            SysUser user = userService.selectUserByUserNameAndTenantId(item.getSignerName(), String.valueOf(tenantId));
//            if (user == null) {
//                failureNum++;
//                failureMsg.append("<br/>").append(failureNum).append("、员工 ").append(item.getSignerName()).append(" 不存在");
//                continue;
//            }
//            bizCollection.setApplierId(user.getUserId());
            BigDecimal detailSum = BigDecimal.valueOf(contractDetails.stream().mapToDouble(v -> v.getAmount().doubleValue()).sum()).setScale(2, RoundingMode.HALF_UP);
            BigDecimal remain = BigDecimal.ZERO;
            for(int i = 0; i < contractDetails.size() ; i++) {
                BizArchiveInputDetail l = contractDetails.get(i);
                BizCollectionDetail detail = new BizCollectionDetail();
                detail.setCollectionId(bizCollection.getId());
                detail.setAmount(l.getAmount());
                detail.setTaskTypeId(l.getTaskTypeId());
                detail.setContractDetailId(l.getId());
                detail.setContractId(l.getContractId());
                detail.setTenantId(tenantId);
                detail.setCompanyId(company.getId());
                detail.setTaskTypeId(l.getTaskTypeId());
                if (i == contractDetails.size() - 1) {
                    detail.setArriveAmount(item.getAmount().subtract(remain));
                } else {
                    detail.setArriveAmount(item.getAmount().divide(detailSum, 4, RoundingMode.HALF_UP).multiply(l.getAmount()).setScale(2, RoundingMode.HALF_UP));
                    remain = remain.add(detail.getArriveAmount());
//                    remain = item.getC
                }
                details.add(detail);
            }
//            contractDetails.forEach(l -> {
//                BizCollectionDetail detail = new BizCollectionDetail();
//                detail.setCollectionId(bizCollection.getId());
//                detail.setAmount(l.getAmount());
//                if (l.getTaskTypeId().equals(1L)) {
//                    detail.setArriveAmount(item.getKeepAccountAmount());
//                }
//                if (l.getTaskTypeId().equals(2L)) {
//                    detail.setArriveAmount(item.getSecurityAmount());
//                }
//                if (l.getTaskTypeId().equals(3L)) {
//                    detail.setArriveAmount(item.getHousingFundAmount());
//                }
//                if (l.getTaskTypeId().equals(4L)) {
//                    detail.setArriveAmount(item.getReturnTaxAmount());
//                }
//                detail.setContractDetailId(l.getId());
//                detail.setContractId(l.getContractId());
//                detail.setTenantId(tenantId);
//                detail.setcompanyId(company.getId());
//                detail.setTaskTypeId(l.getTaskTypeId());
//                details.add(detail);
//            });
//            BigDecimal amount = BigDecimal.ZERO;
//            amount = amount.add(item.getKeepAccountAmount() == null ? BigDecimal.ZERO : item.getKeepAccountAmount());
//            amount = amount.add(item.getSecurityAmount() == null ? BigDecimal.ZERO : item.getSecurityAmount());
//            amount = amount.add(item.getHousingFundAmount() == null ? BigDecimal.ZERO : item.getHousingFundAmount());
//            amount = amount.add(item.getReturnTaxAmount() == null ? BigDecimal.ZERO :item.getReturnTaxAmount());
//            bizCollection.setAmount(amount);
            collections.add(bizCollection);
            successNum++;
            successMsg.append("<br/>").append(successNum).append("、收款 ").append(item.getContractNo()).append(" 导入成功");
        }
        super.saveBatch(collections);
        details.forEach(collectionDetailMapper::insert);

        if (failureNum > 0) {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
            throw new ServiceException(failureMsg.toString());
        } else {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    @Override
    public String importOnce(List<CollectionExcelOnceModel> collects, Long userId, long tenantId) {
        if (StringUtils.isNull(collects) || collects.size() == 0) {
            throw new ServiceException("导入数据不能为空！");
        }
        List<BizCompany> companies = companyService.query().eq("tenant_id", tenantId).list();
        List<BizCollection> collections = new ArrayList<>();
        List<BizCollectionDetail> details = new ArrayList<>();
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (CollectionExcelOnceModel item: collects) {
            // 获取合同信息
            BizArchiveInput archiveInput = archiveInputService.query().eq("contract_no", item.getContractNo()).eq("from_id",0).eq("service_type",2).eq("tenant_id", tenantId).list().stream().findFirst().orElse(null);

            if (archiveInput == null) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 不存在或不是单次合同");
                continue;
            }
            if(null == item.getAmount()){
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 收款金额不能为空");
                continue;
            }
            if(null == item.getContractAmount()){
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 合同总金额不能为空");
                continue;
            }
            if(archiveInput.getTrueAmount().subtract(item.getContractAmount()).compareTo(BigDecimal.ZERO) != 0){
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append("合同总金额不一致");
                continue;
            }
            BizCompany company = companies.stream().filter(v -> v.getName().equals(item.getCompanyName())).findFirst().orElse(null);
            if (company == null) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、客户 ").append(item.getCompanyName()).append(" 不存在");
                continue;
            }
            if (!archiveInput.getCompanyId().equals(company.getId())) {
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的客户不是").append(item.getCompanyName());
                continue;
            }

            List<BizArchiveInputDetail> contractDetails = archiveInputDetailService.query().eq("contract_id", archiveInput.getId()).list();
            // 判断明细信息是否和导入信息相符
            // 不相符添加 failureNum 并转到下一条。
//            if (item.getRegisterAmount() != null && item.getRegisterAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(5L))) {
//                failureNum++;
//                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有注册任务");
//                continue;
//            }
//            if (item.getAlterAmount() != null && item.getAlterAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(6L))) {
//                failureNum++;
//                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有变更任务").append(item.getCompanyName());
//                continue;
//            }
//            if (item.getLogoutAmount() != null && item.getLogoutAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(7L))) {
//                failureNum++;
//                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有注销任务");
//                continue;
//            }
//            if (item.getQualifiedAmount() != null && item.getQualifiedAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(8L))) {
//                failureNum++;
//                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有资质任务");
//                continue;
//            }
//            if (item.getOtherAmount() != null && item.getOtherAmount().compareTo(BigDecimal.ZERO) > 0 && contractDetails.stream().noneMatch(v -> v.getTaskTypeId().equals(8L))) {
//                failureNum++;
//                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有其他任务");
//                continue;
//            }
            LambdaQueryWrapper<BizCollection> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(BizCollection::getContractId, archiveInput.getId());
            wrapper.eq(BizCollection::getDeleted, 0);
            wrapper.and(b -> b.eq(BizCollection::getStatus, 0).or().eq(BizCollection::getStatus, 1));

            List<BizCollection> collected = this.list(wrapper);
            BigDecimal collectedAmount = BigDecimal.valueOf(collected.stream().mapToDouble(v -> v.getArriveAmount().doubleValue()).sum());

            if(null == item.getAmount() || null == archiveInput.getTrueAmount()  ||item.getAmount().subtract(archiveInput.getTrueAmount().subtract(collectedAmount)).compareTo(BigDecimal.ZERO) >0){
                failureNum++;
                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("现系统内收款加上excel表内收款金额已超出合同收款总金额");
                continue;
            }



            BizCollection bizCollection = new BizCollection();
            bizCollection.setId(snowflakeIdWorker.nextId());
            bizCollection.setContractId(archiveInput.getId());
            bizCollection.setApplierId(getUserId());
            //实际付款时间默认未当前时间
            bizCollection.setActuallyDate(DateTime.now().toTimestamp());
            bizCollection.setFlowNo(String.valueOf(snowflakeIdWorker.nextId()));
            bizCollection.setContractNo(archiveInput.getContractNo());
            bizCollection.setCompanyId(archiveInput.getCompanyId());
//            bizCollection.setSubsidiaryBankAccount(item.getSubsidiaryBankAccount());
//            bizCollection.setSubsidiaryName(item.getSubsidiaryName());
//            bizCollection.setSubsidiaryBankName(item.getSubsidiaryBankName());
            bizCollection.setArriveAmount(item.getAmount());
//            bizCollection.setArriveDate(DateTime.of(item.getArriveDate()).toTimestamp());;
//            bizCollection.setFormDate(DateTime.of(item.getFormDate()).toTimestamp());
            bizCollection.setVerifyStatus(1);
            bizCollection.setStatus((byte)1);
            bizCollection.setArriveStatus((byte)1);
            bizCollection.setVerifyDate(DateTime.now().toTimestamp());
//            bizCollection.setArriveTime(DateTime.of(item.getArriveTime()).toString("HH:mm"));
            bizCollection.setTenantId(tenantId);
//            SysUser user = userService.selectUserByUserNameAndTenantId(item.getSignerName(), String.valueOf(tenantId));
//            if (user == null) {
//                failureNum++;
//                failureMsg.append("<br/>").append(failureNum).append("、员工 ").append(item.getSignerName()).append(" 不存在");
//                continue;
//            }
//            bizCollection.setApplierId(user.getUserId());
            contractDetails.forEach(l -> {
                BizCollectionDetail detail = new BizCollectionDetail();
                detail.setCollectionId(bizCollection.getId());
                detail.setAmount(l.getAmount());
//                if (l.getTaskTypeId().equals(5L)) {
//                    detail.setArriveAmount(item.getRegisterAmount());
//                }
//                if (l.getTaskTypeId().equals(6L)) {
//                    detail.setArriveAmount(item.getAlterAmount());
//                }
//                if (l.getTaskTypeId().equals(7L)) {
//                    detail.setArriveAmount(item.getLogoutAmount());
//                }
//                if (l.getTaskTypeId().equals(8L)) {
//                    detail.setArriveAmount(item.getQualifiedAmount());
//                }
//                if (l.getTaskTypeId().equals(9L)) {
//                    detail.setArriveAmount(item.getOtherAmount());
//                }
                detail.setArriveAmount(item.getAmount());
                detail.setContractDetailId(l.getId());
                detail.setContractId(l.getContractId());
                detail.setTenantId(tenantId);
                detail.setCompanyId(company.getId());
                detail.setTaskTypeId(l.getTaskTypeId());
                details.add(detail);
            });
            BigDecimal amount = BigDecimal.ZERO;
            amount = amount.add(item.getRegisterAmount() == null ? BigDecimal.ZERO : item.getRegisterAmount());
            amount = amount.add(item.getAlterAmount() == null ? BigDecimal.ZERO : item.getAlterAmount());
            amount = amount.add(item.getLogoutAmount() == null ? BigDecimal.ZERO : item.getLogoutAmount());
            amount = amount.add(item.getQualifiedAmount() == null ? BigDecimal.ZERO :item.getQualifiedAmount());
            amount = amount.add(item.getOtherAmount() == null ? BigDecimal.ZERO : item.getOtherAmount());
            bizCollection.setAmount(amount);
            collections.add(bizCollection);
            successNum++;
            successMsg.append("<br/>").append(successNum).append("、收款 ").append(item.getContractNo()).append(" 导入成功");
        }
        super.saveBatch(collections);
        details.forEach(collectionDetailMapper::insert);

        if (failureNum > 0) {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
            throw new ServiceException(failureMsg.toString());
        } else {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    @Override
    public boolean removeCollectionBatchByIds(List<Long> ids) {
        // 判断是否已审核
        if (this.query().in("id", ids).eq("status", 1).count() > 0) {
            throw new ServiceException("只能删除未审核的数据。");
        } else if (this.query().in("id", ids).eq("status", 2).count() > 0) {
            throw new ServiceException("只能删除未审核的数据。");
        } else {
            List<BizCollection> collections = this.query().in("id", ids).list();

            // 未审核的删掉 包括明细
            super.removeBatchByIds(ids);
            collectionDetailMapper.remove(ids);

            //修改收款状态
            for (BizCollection collection : collections) {
                //查询合同信息
                BizArchiveInput archiveInput = archiveInputService.getById(collection.getContractId());
                //查询收款信息
                Map<String, Object> map = new HashMap<>();
                map.put("contractId", collection.getContractId());
                List<BizCollection> list= this.getList(map);
                if (list.size() > 0) {
                    //如过存在收款信息
                    //查看最新的收款状态
                    if(list.get(0).getStatus()==0){
                        //收款待审核
                        archiveInput.setCollectionStatus((byte) 1);
                    }else if(list.get(0).getStatus()==1){
                        //已收款
                        archiveInput.setCollectionStatus((byte) 2);
                    }else if(list.get(0).getStatus()==2){
                        //已驳回
                        archiveInput.setCollectionStatus((byte) 3);
                    }
                    archiveInputService.updateById(archiveInput);
                }else{
                    //如过不存在收款信息
                    //收款信息改为未收款
                    archiveInput.setCollectionStatus((byte) 0);
                    archiveInputService.updateById(archiveInput);
                }
            }

        }
        return true;
    }

    @Override
    public List<ResStatisticsVo> statistics(ReqStatisticsVo conditions) {
        return collectionDao.statistics(conditions);
    }

    @Override
    public List<ResStatisticsVo> getByContractIn(ReqStatisticsVo conditions) {
        return collectionDao.getByContractIn(conditions);
    }

    @Override
    public List<ResStatisticsVo> getByContractOut(ReqStatisticsVo conditions) {
        return collectionDao.getByContractOut(conditions);
    }
}
