package org.dromara.payment.invoice.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.dromara.common.core.enums.BusRole;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.payment.bill.domain.MerBill;
import org.dromara.payment.bill.domain.bo.MerBillDetailBo;
import org.dromara.payment.bill.mapper.MerBillMapper;
import org.dromara.payment.channel.domain.BusChannelFlows;
import org.dromara.payment.channel.domain.vo.BusChannelFlowsVo;
import org.dromara.payment.channel.mapper.BusChannelFlowsMapper;
import org.dromara.payment.channel.service.IBusChannelAccountService;
import org.dromara.payment.invoice.domain.MerInvoiceAddress;
import org.dromara.payment.invoice.domain.MerInvoiceBill;
import org.dromara.payment.invoice.domain.MerInvoiceDetail;
import org.dromara.payment.invoice.domain.bo.MerInvoiceBillBo;
import org.dromara.payment.invoice.domain.bo.MerInvoiceDetailBo;
import org.dromara.payment.invoice.domain.bo.UploadInvoiceBo;
import org.dromara.payment.invoice.domain.vo.MerInvoiceBillVo;
import org.dromara.payment.invoice.mapper.MerInvoiceAddressMapper;
import org.dromara.payment.invoice.mapper.MerInvoiceBillMapper;
import org.dromara.payment.invoice.mapper.MerInvoiceDetailMapper;
import org.dromara.payment.merchant.domain.BusMerchant;
import org.dromara.payment.merchant.mapper.BusMerchantMapper;
import org.dromara.payment.operator.domain.BusOperatorFlows;
import org.dromara.payment.operator.domain.vo.BusOperatorFlowsVo;
import org.dromara.payment.operator.mapper.BusOperatorFlowsMapper;
import org.dromara.payment.operator.service.IBusOperatorAccountService;
import org.dromara.payment.sys.domain.SysSyd;
import org.dromara.payment.sys.domain.SysSydAccount;
import org.dromara.payment.sys.domain.SysSydFlows;
import org.dromara.payment.sys.domain.vo.SysSydFlowsVo;
import org.dromara.payment.sys.mapper.SysSydAccountMapper;
import org.dromara.payment.sys.mapper.SysSydFlowsMapper;
import org.dromara.payment.sys.mapper.SysSydMapper;
import org.dromara.payment.sys.service.ISysSydAccountService;
import org.dromara.payment.thirdPlatform.base.domain.SysThirdPlatform;
import org.dromara.payment.thirdPlatform.base.mapper.SysThirdPlatformMapper;
import org.dromara.payment.thirdPlatform.xinyujian.service.IXyjService;
import org.springframework.stereotype.Service;
import org.dromara.payment.invoice.domain.bo.MerInvoiceBo;
import org.dromara.payment.invoice.domain.vo.MerInvoiceVo;
import org.dromara.payment.invoice.domain.MerInvoice;
import org.dromara.payment.invoice.mapper.MerInvoiceMapper;
import org.dromara.payment.invoice.service.IMerInvoiceService;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 商户发票记录Service业务层处理
 *
 * @author LionLi
 * @date 2024-05-06
 */
@RequiredArgsConstructor
@Service
public class MerInvoiceServiceImpl implements IMerInvoiceService {

    private final MerInvoiceMapper baseMapper;

    private final MerInvoiceBillMapper invoiceBillMapper;

    private final MerBillMapper billMapper;

    private final MerInvoiceDetailMapper invoiceDetailMapper;

    private final SysSydFlowsMapper sydFlowsMapper;

    private final ISysSydAccountService sydAccountService;

    private final BusOperatorFlowsMapper operatorFlowsMapper;

    private final IBusOperatorAccountService operatorAccountService;

    private final BusChannelFlowsMapper channelFlowsMapper;

    private final IBusChannelAccountService channelAccountService;

    private final MerInvoiceAddressMapper    merInvoiceAddressMapper;

    private final SysSydMapper sydMapper;

    private final IXyjService xyjService;

    private final BusMerchantMapper merchantMapper;

    private final SysThirdPlatformMapper sysThirdPlatformMapper;
    /**
     * 查询商户发票记录
     */
    @Override
    public MerInvoiceVo queryById(Long id){
        MerInvoiceBo invoiceBo = new MerInvoiceBo();
        invoiceBo.setId(id);
        MerInvoiceVo rtn = this.baseMapper.selectInvInfo(invoiceBo);
        if(rtn != null) {
            rtn.setDetails(invoiceDetailMapper.selectVoList(new LambdaQueryWrapper<MerInvoiceDetail>().eq(MerInvoiceDetail::getInvId, id)));
        }
        return rtn;
    }

    /**
     * 查询商户发票记录
     */
    @Override
    public MerInvoiceVo queryByNo(String no){
        MerInvoiceBo invoiceBo = new MerInvoiceBo();
        invoiceBo.setNo(no);
        MerInvoiceVo rtn = this.baseMapper.selectInvInfo(invoiceBo);
        if(rtn != null) {
            rtn.setDetails(invoiceDetailMapper.selectVoList(new LambdaQueryWrapper<MerInvoiceDetail>().eq(MerInvoiceDetail::getInvId, rtn.getId())));
        }
        return rtn;
    }

    /**
     * 查询商户发票记录列表
     */
    @Override
    public TableDataInfo<MerInvoiceVo> queryPageList(MerInvoiceBo bo, PageQuery pageQuery) {
        QueryWrapper<MerInvoice> lqw = buildQueryWrapper(bo);
        Page<MerInvoiceVo> result = baseMapper.queryPageList(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询商户发票记录列表
     */
    @Override
    public List<MerInvoiceVo> queryList(MerInvoiceBo bo) {
        QueryWrapper<MerInvoice> lqw = buildQueryWrapper(bo);
        return baseMapper.queryList(lqw);
    }

    private QueryWrapper<MerInvoice> buildQueryWrapper(MerInvoiceBo bo) {
        Map<String, Object> params = bo.getParams();
        QueryWrapper<MerInvoice> lqw = new QueryWrapper<>();
        lqw.eq(StringUtils.isNotBlank(bo.getNo()), "t.no", bo.getNo());
        lqw.eq(StringUtils.isNotBlank(bo.getHeader()), "t.header", bo.getHeader());
        lqw.eq(bo.getType() != null, "t.type", bo.getType());
        lqw.eq(StringUtils.isNotBlank(bo.getCreditCode()), "t.credit_code", bo.getCreditCode());
        lqw.eq(StringUtils.isNotBlank(bo.getBankAddress()), "t.bank_address", bo.getBankAddress());
        lqw.eq(StringUtils.isNotBlank(bo.getBankCard()), "t.bank_card", bo.getBankCard());
        lqw.eq(StringUtils.isNotBlank(bo.getCategory()), "t.category", bo.getCategory());
        lqw.eq(bo.getInvNum() != null, "t.inv_num", bo.getInvNum());
        lqw.eq(bo.getInvAmount() != null, "t.inv_amount", bo.getInvAmount());
        lqw.eq(bo.getAddId() != null, "t.add_id", bo.getAddId());
        lqw.like(StringUtils.isNotBlank(bo.getAddName()), "t.add_name", bo.getAddName());
        lqw.eq(StringUtils.isNotBlank(bo.getAddPhone()), "t.add_phone", bo.getAddPhone());
        lqw.eq(StringUtils.isNotBlank(bo.getAddAddress()), "t.add_address", bo.getAddAddress());
        lqw.eq(StringUtils.isNotBlank(bo.getAddEmail()), "t.add_email", bo.getAddEmail());
        lqw.eq(bo.getIogisticsStatus() != null, "t.iogistics_status", bo.getIogisticsStatus());
        lqw.eq(bo.getIogisticsTime() != null, "t.iogistics_time", bo.getIogisticsTime());
        lqw.eq(StringUtils.isNotBlank(bo.getIogisticsBy()), "t.iogistics_by", bo.getIogisticsBy());
        lqw.eq(StringUtils.isNotBlank(bo.getIogisticsCompany()), "t.iogistics_company", bo.getIogisticsCompany());
        lqw.eq(StringUtils.isNotBlank(bo.getIogisticsNo()), "t.iogistics_no", bo.getIogisticsNo());
        lqw.eq(bo.getStatus() != null, "t.status", bo.getStatus());
        lqw.eq(bo.getAddTime() != null, "t.add_time", bo.getAddTime());
        lqw.eq(StringUtils.isNotBlank(bo.getAddBy()), "t.add_by", bo.getAddBy());
        lqw.eq(bo.getCancelTime() != null, "t.cancel_time", bo.getCancelTime());
        lqw.eq(StringUtils.isNotBlank(bo.getCancelBy()), "t.cancel_by", bo.getCancelBy());
        lqw.eq(StringUtils.isNotBlank(bo.getCancelReason()), "t.cancel_reason", bo.getCancelReason());
        lqw.eq(StringUtils.isNotBlank(bo.getInvRemark()), "t.inv_remark", bo.getInvRemark());
        lqw.eq(StringUtils.isNotBlank(bo.getDwzcdz()), "t.dwzcdz", bo.getDwzcdz());
        lqw.eq(StringUtils.isNotBlank(bo.getDwdh()), "t.dwdh", bo.getDwdh());
        lqw.eq(bo.getSydId() != null, "t.syd_id", bo.getSydId());
        lqw.eq(StringUtils.isNotBlank(bo.getSydNo()), "t.syd_no", bo.getSydNo());
        lqw.eq(StringUtils.isNotBlank(bo.getOpNo()), "t.op_no", bo.getOpNo());
        lqw.eq(bo.getOpId() != null, "t.op_id", bo.getOpId());
        lqw.eq(bo.getChannelId() != null, "t.channel_id", bo.getChannelId());
        lqw.eq(StringUtils.isNotBlank(bo.getChannelNo()), "t.channel_no", bo.getChannelNo());
        lqw.eq(StringUtils.isNotBlank(bo.getChannelCode()), "t.channel_code", bo.getChannelCode());
        lqw.eq(bo.getMerId() != null, "t.mer_id", bo.getMerId());
        lqw.eq(StringUtils.isNotBlank(bo.getMerNo()), "t.mer_no", bo.getMerNo());
        lqw.eq(bo.getBusType() != null, "t.bus_type", bo.getBusType());
        lqw.eq(bo.getIogisticsReceivingTime() != null, "t.iogistics_receiving_time", bo.getIogisticsReceivingTime());
        lqw.eq(StringUtils.isNotBlank(bo.getIogisticsReceivingBy()), "t.iogistics_receiving_by", bo.getIogisticsReceivingBy());
        if(StringUtils.isNotBlank(bo.getParams().get("begin_time")) && StringUtils.isNotBlank(bo.getParams().get("end_time"))){
            lqw.between("t.add_time",bo.getParams().get("begin_time")+" 00:00:00",bo.getParams().get("end_time")+" 23:59:59");
        }
        if(StringUtils.isNotBlank(bo.getParams().get("syd_name"))){
            lqw.like("t2.gsmc",bo.getParams().get("syd_name"));
        }
        if(StringUtils.isNotBlank(bo.getParams().get("mer_name"))){
            lqw.like("t1.name",bo.getParams().get("mer_name"));
        }
        if(StringUtils.isNotBlank(params.get("channel_no"))){
            lqw.likeRight("t.channel_no",params.get("channel_no"));
        }
        return lqw;
    }

    /**
     * 新增商户发票记录
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insertByBo(MerInvoiceBo bo) {
        MerInvoice add = MapstructUtils.convert(bo, MerInvoice.class);
        validEntityBeforeSave(add);
        add.setNo("T"+ DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSSSSS)+ RandomUtil.randomNumbers(5));
        add.setAddTime(new Date());
        add.setInvAmount(0l);
        add.setStatus(5);//开票中
        List<MerInvoiceBill> bills = new ArrayList<>();
        List<Long> billIds = new ArrayList<>();
        for (MerInvoiceBillBo bill:bo.getBills()
        ) {
            MerInvoiceBill b = MapstructUtils.convert(bill,MerInvoiceBill.class);
            b.setSydId(add.getSydId());
            b.setSydNo(add.getSydNo());
            b.setOpId(add.getOpId());
            b.setOpNo(add.getOpNo());
            b.setChannelId(add.getChannelId());
            b.setChannelNo(add.getChannelNo());
            b.setChannelCode(add.getChannelCode());
            b.setMerId(add.getMerId());
            b.setMerNo(add.getMerNo());
            add.setInvAmount(add.getInvAmount()+b.getInvAmount());
            bills.add(b);
            billIds.add(b.getBillId());
        }
        //发起了申请
        if(billMapper.update(new LambdaUpdateWrapper<MerBill>().in(MerBill::getId,billIds)
            .eq(MerBill::getIsInvoice,0)
            .set(MerBill::getIsInvoice,2)) != billIds.size()){
            throw new ServiceException("不允许重复申请，申请失败");
        }

        this.merInvoiceAddressMapper.update(new LambdaUpdateWrapper<MerInvoiceAddress>().eq(MerInvoiceAddress::getMerId,add.getMerId())
            .set(MerInvoiceAddress::getName,add.getAddName()).set(MerInvoiceAddress::getPhone,add.getAddPhone())
            .set(MerInvoiceAddress::getAddress,add.getAddAddress()));
        SysSyd sysSyd = sydMapper.selectSysSydById(add.getSydId());
        BusMerchant busMerchant = merchantMapper.selectById(add.getMerId());
        boolean flag;

        SysThirdPlatform sysThirdPlatform = sysThirdPlatformMapper.selectThirdAppInfo(sysSyd.getThreeId());


        if(Objects.nonNull(sysThirdPlatform) && sysThirdPlatform.getPlatformName().equals("薪遇见")){
            flag = xyjService.applyInvoice(busMerchant,sysSyd,add);
        }else{
            flag = baseMapper.insert(add) > 0;
        }

        if (flag) {
            bills = bills.stream().peek(b -> b.setInvId(add.getId())).collect(Collectors.toList());
            invoiceBillMapper.insertBatch(bills);
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改商户发票记录
     */
    @Override
    public Boolean updateByBo(MerInvoiceBo bo) {
        MerInvoice update = MapstructUtils.convert(bo, MerInvoice.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(MerInvoice entity){
        //TODO 做一些数据校验,如唯一约束

    }

    /**
     * 批量删除商户发票记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean reject(MerInvoiceBo bo) {
        MerInvoice update = MapstructUtils.convert(bo, MerInvoice.class);
        update.setCancelTime(new Date());
        update.setStatus(4);//驳回
        if(baseMapper.update(update,new LambdaQueryWrapper<MerInvoice>().eq(MerInvoice::getId,bo.getId())
            .eq(MerInvoice::getStatus,5)) == 0){
            throw new ServiceException("不允许重复驳回，驳回失败");
        }
        invoiceBillMapper.updateInvoiceStatus(bo.getId(),2,0);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean uploadInvoice(UploadInvoiceBo bo) {
        MerInvoiceVo vo = baseMapper.selectVoById(bo.getId());
        if(vo == null){
            throw new ServiceException("发票申请不存在，提交失败");
        }
        if(vo.getStatus() != 5){
            throw new ServiceException("发票已上传，提交失败");
        }
        List<MerInvoiceDetail> details = new ArrayList<>();
        long invAmount = 0;//开票金额（分）
        for (MerInvoiceDetailBo d:bo.getDetails()
             ) {
            MerInvoiceDetail detail = MapstructUtils.convert(d,MerInvoiceDetail.class);
            detail.setInvId(bo.getId());
            detail.setInvNo(vo.getNo());
            detail.setAddBy(bo.getAddBy());
            detail.setAddTime(new Date());
            invAmount += detail.getInvAmount();
            details.add(detail);
        }
        if(vo.getInvAmount() != invAmount){
            throw new ServiceException("发票申请金额与开票金额不一致,请核对后提交!");
        }
        if(baseMapper.update(new LambdaUpdateWrapper<MerInvoice>().eq(MerInvoice::getId,bo.getId())
            .eq(MerInvoice::getStatus,5)
            .set(MerInvoice::getStatus,2)
            .set(MerInvoice::getInvNum,details.size())) == 0){
            throw new ServiceException("重复操作，提交失败");
        }
        invoiceDetailMapper.insertBatch(details);
        invoiceBillMapper.updateInvoiceStatus(bo.getId(),2,1);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean editIogistics(MerInvoiceBo bo) {
        MerInvoiceVo vo = baseMapper.selectVoById(bo.getId());
        if(vo == null){
            throw new ServiceException("发票申请不存在，提交失败");
        }
        if(vo.getStatus() != 2){
            throw new ServiceException("发票还未开出，提交失败");
        }
        MerInvoice updater = MapstructUtils.convert(bo,MerInvoice.class);
        if(vo.getIogisticsTime() == null){
            updater.setIogisticsTime(new Date());
            updater.setIogisticsStatus(2);
        }
        baseMapper.updateById(updater);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean receivingIogistics(long invId,String oper) {
        MerInvoiceVo vo = baseMapper.selectVoById(invId);
        if(vo == null){
            throw new ServiceException("发票申请不存在，提交失败");
        }
        if(vo.getIogisticsStatus() != 2){
            throw new ServiceException("发票已签收或未到签收节点，提交失败");
        }
        MerInvoice updater = new MerInvoice();
        updater.setId(invId);
        updater.setIogisticsReceivingBy(oper);
        updater.setIogisticsReceivingTime(new Date());
        updater.setIogisticsStatus(3);
        if("系统".equals(oper)){
            updater.setRemark("自动签收发票");
        }
        if(baseMapper.update(updater,new LambdaQueryWrapper<MerInvoice>().eq(MerInvoice::getId,invId)
            .eq(MerInvoice::getIogisticsStatus,2)) == 0){
            throw new ServiceException("重复操作，签收失败");
        }
        //解除冻结服务商的服务费
        List<SysSydFlowsVo> flows = invoiceBillMapper.selectFrozenSydFlows(invId);
        if(flows.size() > 0) {
            List<SysSydFlows> newFlows = new ArrayList<>();
            //解除冻结的金额（分）,key:账户id_结算通道
            Map<String, SysSydAccount> moneyMap = new HashMap<>();
            for (SysSydFlowsVo flow :
                flows) {
                SysSydFlows ssf = new SysSydFlows(0, flow.getSydId(), 7, flow.getChannel(), flow.getBusNo(), flow.getBankNo(), Math.abs(flow.getMoney()), new Date(), oper, "资金解冻", flow.getBillNo(), flow.getBillId(), null, "UF" + IdUtil.getSnowflakeNextIdStr(), 6, 2, flow.getPayerType(), flow.getPayerId(), flow.getPayerName(), flow.getPayerAcc(), flow.getPayerAccId(), null, null, null, null, null, "解冻成功", 0);
                String key = ssf.getPayerAccId() + "_" + ssf.getChannel();
                if(!moneyMap.containsKey(key)){
                    SysSydAccount acc = new SysSydAccount();
                    acc.setAccId(ssf.getPayerAccId());
                    acc.setFrozen(0l);
                    acc.setBankType(ssf.getChannel());
                    moneyMap.put(key,acc);
                }
                moneyMap.get(key).setFrozen(moneyMap.get(key).getFrozen()+ssf.getMoney());
                newFlows.add(ssf);
            }
            moneyMap.forEach((key,value)->{
                if (sydAccountService.updateFrozenByAccId(value.getAccId().intValue(), -value.getFrozen()) == 0) {
                    throw new ServiceException("服务商资金解冻时，" + value.getBankType() + "账户冻结金额不足");
                }
            });
            sydFlowsMapper.insertAll(newFlows);
        }
        //解除冻结运营商的服务费
        List<BusOperatorFlowsVo> opflows = invoiceBillMapper.selectFrozenOpFlows(invId);
        if(opflows.size() > 0) {
            List<BusOperatorFlows> newFlows = new ArrayList<>();
            //解除冻结的金额（分）,key:账户id_结算通道
            Map<String, SysSydAccount> moneyMap = new HashMap<>();
            for (BusOperatorFlowsVo flow :
                opflows) {
                BusOperatorFlows ssf = new BusOperatorFlows(0,flow.getOpId(),9,flow.getChannel(),null,null,Math.abs(flow.getMoney()),new Date(),flow.getAddBy(),"资金解冻",flow.getBillNo(),flow.getBillId(),flow.getBillDetailId(),"UF"+IdUtil.getSnowflakeNextIdStr(),6,2,flow.getPayeeType(),flow.getPayerId(),flow.getPayerName(),flow.getPayerAcc(),flow.getPayerAccId(),null,null,null,null,null,"解冻成功",0);
                String key = ssf.getPayerAccId() + "_" + ssf.getChannel();
                if(!moneyMap.containsKey(key)){
                    SysSydAccount acc = new SysSydAccount();
                    acc.setAccId(ssf.getPayerAccId());
                    acc.setFrozen(0l);
                    acc.setBankType(ssf.getChannel());
                    moneyMap.put(key,acc);
                }
                moneyMap.get(key).setFrozen(moneyMap.get(key).getFrozen()+ssf.getMoney());
                newFlows.add(ssf);
            }
            moneyMap.forEach((key,value)->{
                if (operatorAccountService.updateFrozenByAccId(value.getAccId().intValue(), -value.getFrozen()) == 0) {
                    throw new ServiceException("运营商资金解冻时，" + value.getBankType() + "账户冻结金额不足");
                }
            });
            operatorFlowsMapper.insertBatch(newFlows);
        }
        //解除冻结代理商的服务费
        List<BusChannelFlowsVo> chflows = invoiceBillMapper.selectFrozenChannelFlows(invId);
        if(chflows.size() > 0) {
            List<BusChannelFlows> newFlows = new ArrayList<>();
            //解除冻结的金额（分）,key:账户id
            Map<String, SysSydAccount> moneyMap = new HashMap<>();
            for (BusChannelFlowsVo flow :
                chflows) {
                BusChannelFlows ssf = new BusChannelFlows(0,flow.getChannelId(),11,null,Math.abs(flow.getMoney()),new Date(),flow.getAddBy(),"资金解冻",flow.getBillNo(),flow.getBillId(),flow.getBillDetailId(),6, flow.getPayerType(), flow.getPayerId(),flow.getPayerName(),flow.getPayerAcc(),flow.getPayerAccId(),null, null,null,null,null,"解冻成功");
                String key = ssf.getPayerId()+"";
                if(!moneyMap.containsKey(key)){
                    SysSydAccount acc = new SysSydAccount();
                    acc.setAccId(ssf.getPayerId());
                    acc.setFrozen(0l);
                    moneyMap.put(key,acc);
                }
                moneyMap.get(key).setFrozen(moneyMap.get(key).getFrozen()+ssf.getMoney());
                newFlows.add(ssf);
            }
            moneyMap.forEach((key,value)->{
                if (channelAccountService.updateFrozen(value.getAccId(), -value.getFrozen()) == 0) {
                    throw new ServiceException("代理商资金解冻时，" + value.getBankType() + "账户冻结金额不足");
                }
            });
            channelFlowsMapper.insertBatch(newFlows);
        }
        return true;
    }
}
