package com.sifang.modules.customer.Service;

import com.google.gson.Gson;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.changes.dao.CustomerEntrySupplementDetailDao;
import com.sifang.modules.changes.entity.CustomerEntrySupplementDetail;
import com.sifang.modules.customer.constant.CustomerEntryConstants;
import com.sifang.modules.customer.constant.PartnerConstants;
import com.sifang.modules.customer.constant.SourceConstants;
import com.sifang.modules.customer.dao.*;
import com.sifang.modules.customer.entity.*;
import com.sifang.modules.customer.form.QueryDocumentRes;
import com.sifang.modules.partner.service.HuaRongApiService;
import com.sifang.modules.sunshine.SystemSetting.utils.BusinessException;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sunshine.SystemSetting.utils.StringUtil;
import com.sifang.modules.sys.common.UserUtils;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.common.service.BaseService;
import com.sifang.modules.sys.entity.Operator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class YueXiuProjectOperatingService extends BaseService {

    @Autowired
    private OperatingLeaseService operatingLeaseService;

    @Autowired
    private CrmCustomerIncomingApplicationDao crmCustomerIncomingApplicationDao;

    @Autowired
    private CustomerEntryMsgService msgService;

    @Autowired
    private CustomerEntryService customerEntryService;

    @Autowired
    private TenantYxBankCardDao tenantYxBankCardDao;

    @Autowired
    @Lazy
    private CustomerEntryExtraService extraService;

    @Autowired
    private ContractManagementDao contractManagementDao;

    @Autowired
    private CrmYxIncomingLogDao yxIncomingLogDao;

    @Autowired
    private YueXiuContractService yueXueContractService;

    @Autowired
    private CrmCustomerIncomingApplicationDao applicationDao;

    @Autowired
    private CustomerEntryExtraService customerEntryExtraService;

    @Autowired
    private CrmEntryCashFlowDao crmEntryCashFlowDao;

    @Autowired
    private CustomerEntrySupplementDetailDao supplementDetailDao;
    @Autowired
    @Lazy
    GuangFaManagemnetService guangFaManagemnetService;
    @Autowired
    HuaRongApiService huaRongApiService;
    @Autowired
    HuaRongManagementService huaRongManagementService;


    /**
     * 支持各合作方主动取消进件，需注意取消的进件无法再次推送，如要继续进行业务，需使用新的合作方进件序号进行新的进行，支持取消的单据状态说明如下
     * 风险审查支持取消状态为：待审批、审批拒绝、退回、撤回、审批通过且农户投放审查不为审批中或者审批通过。
     * 农户投放审查支持取消状态为：待审批、审批拒绝、撤回
     *
     * projectStatus-风险审查状态  NEW-待审批 、APPROVING - 审批中、APPROVED - 审批通过、REJECTED - 审批拒、CLOSED - 取消、APPROVED_RETURN - 退回（农户投放审查退回到风险审查）、CANCEL - 撤回（越秀业务经理撤回流程)
     * farmerSignStatus-农户投放审查状态  NEW-待审批、APPROVING-审批中、APPROVED-审批通过、REJECTED-审批拒绝、CANCEL - 撤回（越秀业务经理撤回流程）、WAITING-等待推送/补充并网及投放信息
     */
    //取消第一次进件
    @Transactional(rollbackFor = Exception.class)
    public void cancelProjectApply(String entryId,String cancelReason){
        logger.info(">>>>>>>>>>>>>cancelProjectApply  entryId:{}",entryId);
        User user= UserUtils.getUser();
        Operator operator=Operator.of(user);
        CustomerEntry entry = customerEntryService.getById(entryId);
        CrmCustomerIncomingApplication application=crmCustomerIncomingApplicationDao.getByEntryId(entryId);
        if(StringUtil.isNotBlank(application.getFarmerSignStatus()) && StringUtil.equalsAny(application.getFarmerSignStatus(),"APPROVING","APPROVED")){
            throw new IllegalArgumentException("进件状态不允许取消!");
        }
        Date date=new Date();
        application.setStatus("a");
        application.setProjectStatus("CLOSED");
        application.setCancelReason(cancelReason);
        application.setUpdateTime(date);
        application.setUpdateBy(user.getId());
        crmCustomerIncomingApplicationDao.save(application);
        entry.setApplyStatus("4");
        entry.setFirstApplyStatus(null);
        entry.setNextApplyStatus(null);
        entry.setSignStatus(CustomerEntryConstants.SIGN_STATUS_UNSTART);
        customerEntryService.saveByUpdate(entry);

        //删除对应进件的合同
        CrmCustomerContractManagement management=contractManagementDao.getContractByEntryId(entryId);
        if(management!=null){
            management.setStatus("0");
            management.setUpdateTime(date);
            contractManagementDao.save(management);
        }
        //推越秀取消进件
        operatingLeaseService.cancelProjectApply(application.getPartnersContractNumber(),cancelReason, SourceConstants.RETURN_TYPE_CANCEL);
        CrmYxIncomingProcessDao.addIncomingProcess(entry.getId(),"2","CLOSED","0","","取消");
        CrmYxIncomingProcessDao.deleteIncomingProcess(entry.getId());
        String str=StringUtil.isBlank(cancelReason)?"":"取消原因："+cancelReason;
        msgService.saveCustomerEntryMsg(user,entryId, CustomerEntryConstants.INCOMING_CANCEL,"取消第一次进件"+str);
        yxIncomingLogDao.addCrmYxIncomingLog(entry.getId(),application.getPartnersContractNumber(),"2","取消第一次进件",operator);
    }


    /**
     *  重新推送
     * @param entry  电站
     * @param type oneIncoming  重新推送第一次进件    twoIncoming 重新推送第二次进件   threeIncoming 重新推送第三次进件
     */
    @Transactional(rollbackFor = Exception.class)
    public void againPushIncoming(CustomerEntry entry,String type){
        String entryId=entry.getId();
        logger.info(">>>>>>>>>>>>>againPushIncoming  entryId:{},type:{}",entryId,type);
        User user= UserUtils.getUser();
        Operator operator=Operator.of(user);
        Gson gson=new Gson();
        if("oneIncoming".equals(type)){

            // 以下状态可更新进件信息： 1）NEW-待审批    2）REJECTED - 审批拒绝     3）APPROVED_RETURN - 退回   4）CANCEL - 撤回
            if((!StringUtil.equalsAny(entry.getFirstApplyStatus(),"NEW","REJECTED","CANCEL","APPROVED_RETURN") && PartnerConstants.PARTNER_ID_YX.equals(entry.getPartnerId()))
            || (!StringUtil.equalsAny(entry.getFirstApplyStatus(),"10","40","50") && PartnerConstants.PARTNER_ID_GF.equals(entry.getPartnerId()))
            || (!StringUtil.equalsAny(entry.getFirstApplyStatus(),"RJ","CL","NS")&& PartnerConstants.PARTNER_ID_HR.equals(entry.getPartnerId()))
            ){
                throw new IllegalArgumentException("进件状态不允许重新推送进件资料！");
            }
            CrmTenantYxBankCard card=tenantYxBankCardDao.getByIdCard(entry.getIdCode(),entry.getManagementType(),entry.getPartnerId());
            Result result = customerEntryService.accessProjectApply(entry,card,operator,null);
            logger.info(">>>>>>>>>>againPushIncoming  result:{}",gson.toJson(result));
            if (!"200".equals(result.getCode())) {
                throw new IllegalArgumentException("进件请求失败；"+result.getErrMsg());
            }
            customerEntryService.saveByUpdate(entry);
            msgService.saveCustomerEntryMsg(user,entryId, CustomerEntryConstants.INCOMING_ONE,"重新推送进件信息");
        }else if("twoIncoming".equals(type)){
            if (StringUtil.isBlank(entry.getNextApplyStatus())) {
            }
            else if((StringUtil.equalsAny(entry.getNextApplyStatus(),"APPROVING","APPROVED") && PartnerConstants.PARTNER_ID_YX.equals(entry.getPartnerId()))
                    || (StringUtil.equalsAny(entry.getNextApplyStatus(),"25","30","60")&& PartnerConstants.PARTNER_ID_GF.equals(entry.getPartnerId()))){
                throw new IllegalArgumentException("进件状态不允许重新推送完工资料！");
            }
            Result result = customerEntryService.accessProjectApplySec(entry,operator);
            logger.info(">>>>>>>>>>againPushIncoming twoIncoming result:{}",gson.toJson(result));
            if (!"200".equals(result.getCode())) {
                throw new IllegalArgumentException("农户投放审查信息同步失败；"+result.getErrMsg());
            }
            customerEntryService.saveByUpdate(entry);
            msgService.saveCustomerEntryMsg(user,entryId, CustomerEntryConstants.INCOMING_WGJJ_TG,"重新推送农户投放审查信息");
        }else if("threeIncoming".equals(type)){
            logger.info(">>>>>>>>againPushIncoming threeIncoming");

            if(StringUtil.equalsAny(entry.getNextApplyStatus(),"APPROVING","APPROVED")&& PartnerConstants.PARTNER_ID_YX.equals(entry.getPartnerId())){
                throw new IllegalArgumentException("进件状态不允许重新推送并网资料！");
            }
            try{
                //查询有没有变更记录
                CrmCustomerIncomingApplication application = applicationDao.getByEntryId(entry.getId());
                CrmAcceptingReport report = customerEntryService.getReportById(entry.getReceivingReportId());
                switch (entry.getPartnerId()){
                    case PartnerConstants.PARTNER_ID_YX:
                        CustomerEntrySupplementDetail changeRecordDetail=supplementDetailDao.getLatestChangeRecordDetail(entry.getId());
                        extraService.addIncomingApplicationSec(entry, operator, changeRecordDetail);
                        customerEntryService.saveByUpdate(entry);
                        break;
                    case PartnerConstants.PARTNER_ID_GF:
                        guangFaManagemnetService.gridIncomingApplication(entry,application,report,operator);
                        break;
                    case PartnerConstants.PARTNER_ID_HR:
                        huaRongManagementService.accessProjectApplyTwo(entry, application,operator);
                        break;
                }
            }catch (Exception e){
                logger.info(">>>>>>>>>>重新推送补充资料失败 e:",e);
                throw new IllegalArgumentException("重新推送补充资料失败！"+e.getMessage());
            }
        }
    }

    /**
     * 重新进件
     */
    public void againIncoming(String entryId){
       logger.info(">>>>>>>>>againIncoming  entryId:{}",entryId);
        CustomerEntry entry = customerEntryService.getById(entryId);
        User user= UserUtils.getUser();
        Operator operator=Operator.of(user);
        CrmCustomerIncomingApplication application=crmCustomerIncomingApplicationDao.getNoDeleteApplication(entryId);
        if(!"CLOSED".equals(application.getProjectStatus())){
             throw new IllegalArgumentException("进件状态不允许重新进件!");
        }
        Gson gson=new Gson();
        CrmTenantYxBankCard card=tenantYxBankCardDao.getByIdCard(entry.getIdCode(),entry.getManagementType(),entry.getPartnerId());
        Result result = customerEntryService.accessProjectApply(entry,card,operator,null);
        logger.info(">>>>>>>>>>againIncoming  result:{}",gson.toJson(result));
        if (!"200".equals(result.getCode())) {
            throw new IllegalArgumentException("进件请求失败；"+result.getErrMsg());
        }
        application.setIfDelete("1");
        crmCustomerIncomingApplicationDao.save(application);
        msgService.saveCustomerEntryMsg(user,entryId, CustomerEntryConstants.INCOMING_OVER_AGAIN,"重新进件");

    }

    @Transactional(rollbackFor = Exception.class)
    public void againPushIncomingTy(CustomerEntry entry,String type,String designId){
        logger.info(">>>>>>>>>>>>>againPushIncoming  entryId:{},type:{}",entry.getId(),type);
//        CustomerEntry entry = customerEntryService.getById(entryId);
        User user= UserUtils.getUser();
        Operator operator=Operator.of(user);
        Gson gson=new Gson();
        if("oneIncoming".equals(type)){
            CrmTenantYxBankCard card=tenantYxBankCardDao.getInfoByIdCard(entry.getIdCode(),entry.getPartnerId());

            Result result = customerEntryService.accessProjectApply(entry,card,operator,designId);
            logger.info(">>>>>>>>>>againPushIncoming  result:{}",gson.toJson(result));
            if (!"200".equals(result.getCode())) {
                throw new IllegalArgumentException("进件请求失败；"+result.getErrMsg());
            }
            msgService.saveCustomerEntryMsg(user,entry.getId(), CustomerEntryConstants.INCOMING_ONE,"推送进件信息");
        }else if("twoIncoming".equals(type)){
            Result result = customerEntryService.accessProjectApplySec(entry,operator);
            logger.info(">>>>>>>>>>againPushIncoming twoIncoming result:{}",gson.toJson(result));
            if (!"200".equals(result.getCode())) {
                throw new IllegalArgumentException("农户投放审查信息同步失败；"+result.getErrMsg());
            }
            msgService.saveCustomerEntryMsg(user,entry.getId(), CustomerEntryConstants.INCOMING_WGJJ_TG,"推送农户投放审查信息");
        }else if("threeIncoming".equals(type)){
            logger.info(">>>>>>>>againPushIncoming threeIncoming");
            //查询有没有变更记录
            CustomerEntrySupplementDetail changeRecordDetail=supplementDetailDao.getLatestChangeRecordDetail(entry.getId());
            extraService.addIncomingApplicationSec(entry,operator,changeRecordDetail);
        }
    }

    //获取完工后 需要查询进件状态的电站,查询进件状态 定时任务调用方法
    @Transactional(rollbackFor = Exception.class)
    public void getNeedToAskJJStatus(){
        String sql=" SELECT e.id,e.power_station_code FROM `crm_customer_entry` e WHERE e.`next_apply_status` IN('NEW','APPROVING') AND  e.apply_status>13 AND e.apply_status<18 AND e.`create_time`>='2024-03-01' ";
        List<Record> list= Db.find(sql);
        logger.info(">>>>>>>>>>getNeedToAskJJStatus  size：{}",list.size());
        for(Record record:list){
            try{
                QueryDocumentRes res=yueXueContractService.queryDocumentStatus(record.getStr("id"));
                logger.info(">>>>>>>>>>getNeedToAskJJStatus  res：{},id:{}",new Gson().toJson(res),record.getStr("id"));
                CustomerEntry entry = customerEntryService.findCustomerEntryById(record.getStr("power_station_code"));
                if(entry==null){
                    continue;
                }
                //修改合同状态
                yueXueContractService.editContractStatusAfterLook(res,res.getBusinessKey(),entry);
                //更新进件状态
                CrmCustomerIncomingApplication application=applicationDao.getByEntryId(entry.getId());
                customerEntryExtraService.updateIncomingApplicationStatus(res,entry.getPowerStationCode(),entry,application);
            }catch (Exception e){
                logger.error("getNeedToAskJJStatus e:",e);
                throw new IllegalArgumentException("获取完工后，主动查询电站进件状态失败!");
            }
        }

    }

    //获取并网验收后 需要查询进件状态的电站,查询进件状态 定时任务调用方法
    @Transactional(rollbackFor = Exception.class)
    public void getNeedToAskBWStatus(){
        String sql=" SELECT e.`power_station_code`, e.id "+
                " FROM crm_customer_entry e, crm_customer_incoming_application a " +
                " WHERE e.`partner_id` = '01' AND a.`partner_id` = e.`partner_id` " +
                "AND a.`if_delete` = '0' AND e.`id` = a.`entry_id` AND e.`merge_flag` IN ('1','2','3') " +
                "AND e.`status` IN ('7') AND e.`on_grid_flag` IN ('1','2','3','4') ";
        List<Record> list= Db.find(sql);
        logger.info(">>>>>>>>>>getNeedToAskBWStatus  size：{}",list.size());
        for(Record record:list){
            try{
                logger.info(">>>>>>>>>>record：{}",new Gson().toJson(record));
                QueryDocumentRes res=yueXueContractService.queryDocumentStatus(record.getStr("id"));
                logger.info(">>>>>>>>>>getNeedToAskBWStatus  res：{},id:{}",new Gson().toJson(res),record.getStr("id"));
                CustomerEntry entry = customerEntryService.getById(record.getStr("id"));
                if(entry==null){
                    continue;
                }
                //修改合同状态
                yueXueContractService.editContractStatusAfterLook(res,res.getBusinessKey(),entry);
                //更新进件状态
                CrmCustomerIncomingApplication application=applicationDao.getByEntryId(entry.getId());
                customerEntryExtraService.updateIncomingApplicationStatus(res,entry.getPowerStationCode(),entry,application);
            }catch (Exception e){
                logger.error("getNeedToAskBWStatus，"+ e.getMessage(),e);
            }
        }

    }
    //更新请款状态
    @Transactional(rollbackFor = Exception.class)
    public void updatePaymentStatus(){
        String sql=" SELECT id,entry_id,farmer_sign_status,payment_apply_status,payment_status FROM `crm_customer_incoming_application` WHERE if_delete='0' and  farmer_sign_status = 'APPROVED' and  payment_status is null or  payment_status != 'PAID'";
        List<Record> list= Db.find(sql);
        logger.info(">>>>>>>>>>updatePaymentStatus  size：{}",list.size());
        for(Record record:list){
            try{
                QueryDocumentRes res=yueXueContractService.queryDocumentStatus(record.getStr("entry_id"));
                logger.info(">>>>>>>>>>updatePaymentStatus  res：{},entry_id:{}",new Gson().toJson(res),record.getStr("entry_id"));
                CustomerEntry entry = customerEntryService.getById(record.getStr("entry_id"));
                if(entry==null){
                    continue;
                }
                CrmCustomerIncomingApplication application=applicationDao.getByEntryId(entry.getId());
                customerEntryExtraService.updatePaymentStatus(res,entry,application);
            }catch (Exception e){
                logger.error("updatePaymentStatus "+e.getMessage(),e);
            }
        }

    }

    //定时任务 --获取越秀合同
    @Transactional(rollbackFor = Exception.class)
    public void getYueXiuContract(){
        StringBuffer sb=new StringBuffer();
        //查询需要同步合同信息的电站
        sb.append(" SELECT id,entry_id,project_status,contract_text_status FROM `crm_customer_incoming_application` WHERE if_delete='0' AND project_status='APPROVED' AND (contract_text_status IS NULL OR contract_text_status='UNCREATED') ");
        List<Record> needToGetContractStatus=Db.find(sb.toString());
        logger.info(">>>>>>getYueXiuContract needToGetContractStatus:{}",needToGetContractStatus.size());
        for(Record record:needToGetContractStatus){
            try{
                //单据状态查询
                logger.info(">>>>>>>>>>getYueXiuContract  entry_id:{},contract_text_status:{}",record.getStr("entry_id"),record.getStr("contract_text_status"));
                QueryDocumentRes res=yueXueContractService.queryDocumentStatus(record.getStr("entry_id"));
                CustomerEntry entry = customerEntryService.getById(record.getStr("entry_id"));
                if(entry==null){
                    continue;
                }
                //修改合同状态
                CrmCustomerIncomingApplication application=applicationDao.getByEntryId(entry.getId());
                yueXueContractService.editContractStatusAfterLook(res,res.getBusinessKey(),entry);
                application.setContractTextStatus(res.getContractTextStatus());
                application.setStatus(entry.getStatus());
                applicationDao.save(application);
                customerEntryService.saveByUpdate(entry);
            }catch (Exception e){
                logger.error("getYueXiuContract "+e.getMessage(),e);
            }
        }
    }

    /**
     * 退回进件
     * ***需注意操作退回进件后会触发合同文本重签；
     * 2）支持退回进件的进件状态为：审批通过；APPROVED
     * 3）支持退回进件的农户投放审查状态为：待审批、审批拒绝、撤回；
     */
    @Transactional(rollbackFor = Exception.class)
    public void returnIncomingApplication(CustomerEntry entry,String prjCancelReason){
        String entryId = entry.getId();
        logger.info(">>>>>>returnIncomingApplication  entry:{},prjCancelReason:{}",new Gson().toJson(entry),prjCancelReason);
        User user= UserUtils.getUser();
        Operator operator=Operator.of(user);
        CrmCustomerIncomingApplication application=crmCustomerIncomingApplicationDao.getByEntryId(entryId);
        if(application==null){
            throw new IllegalArgumentException("未找到进件信息，请刷新页面!");
        }
        if(!"APPROVED".equals(application.getProjectStatus()) && (StringUtil.isNotBlank(application.getFarmerSignStatus()) && !StringUtil.equalsAny(application.getFarmerSignStatus(),"NEW","REJECTED","CANCEL"))){
            throw new IllegalArgumentException("进件状态不允许退回进件!");
        }
        String str= yxIncomingLogDao.getIncomingStatusStr(application.getProjectStatus(),application.getFarmerSignStatus());

        Date date=new Date();
        application.setStatus("4");
        application.setProjectStatus("APPROVED_RETURN");
        application.setFarmerSignStatus(null);
        /*application.setContractTextStatus(null);*/
        application.setUpdateTime(date);
        application.setUpdateBy(user.getId());
        crmCustomerIncomingApplicationDao.save(application);
        entry.setApplyStatus("4");
        entry.setFirstApplyStatus("APPROVED_RETURN");
        entry.setNextApplyStatus(null);
        customerEntryService.saveByUpdate(entry);
        try{  //退回进件
            operatingLeaseService.cancelProjectApply(application.getPartnersContractNumber(),prjCancelReason, SourceConstants.RETURN_TYPE_RETURN);
            logger.info(">>>>>>returnIncomingApplication  entryId:{}",entryId);
        }catch (Exception e){
            logger.error(">>>>>>returnIncomingApplication  e:",e);
            throw new BusinessException(e.getMessage());
        }
        /*//删除对应进件的合同
        CrmCustomerContractManagement management=contractManagementDao.getContractByEntryId(entryId);
        if(management!=null){
            management.setStatus("0");
            management.setUpdateTime(date);
            contractManagementDao.save(management);
        }*/
        CrmYxIncomingProcessDao.addIncomingProcess(entry.getId(),"2","APPROVED_RETURN","0",null,"退回");
        CrmYxIncomingProcessDao.returnIncomingProcess(entryId,"3,4,5");
        String rea=StringUtil.isBlank(prjCancelReason)?"":",原因："+prjCancelReason;
        msgService.saveCustomerEntryMsg(user,entryId, CustomerEntryConstants.INCOMING_CANCEL,"退回进件"+rea);
        yxIncomingLogDao.addCrmYxIncomingLog(entry.getId(),application.getPartnersContractNumber(),"2","退回进件,退回前状态，"+str,operator);
    }


    /**
     * 进件退回完工
     * ***需注意操作退回完工后需重新提交农户投放审批流程；
     * 2）支持退回完工的进件状态为：审批通过；
     * 3）支持退回完工的农户投放审查状态为：审批中且处于“厂商补充并网及商务信息及附件”审批节点；
     */
    @Transactional(rollbackFor = Exception.class)
    public void returnIncomingToCompletion(String entryId,String prjCancelReason){
        logger.info(">>>>>>returnIncomingToCompletion  entryId:{},prjCancelReason:{}",entryId,prjCancelReason);
        User user= UserUtils.getUser();
        Operator operator=Operator.of(user);
        CustomerEntry entry = customerEntryService.getById(entryId);
        CrmCustomerIncomingApplication application=crmCustomerIncomingApplicationDao.getByEntryId(entryId);
        if(application==null){
            throw new IllegalArgumentException("未找到进件信息，请刷新页面!");
        }
        if(!"APPROVED".equals(application.getProjectStatus()) || !"WAITING".equals(application.getFarmerSignStatus())){
            throw new IllegalArgumentException("进件状态不允许退回完工!");
        }
        String str= yxIncomingLogDao.getIncomingStatusStr("",application.getFarmerSignStatus());

        Date date=new Date();
        application.setStatus("13");
        application.setFarmerSignStatus(null);
        application.setUpdateTime(date);
        application.setUpdateBy(user.getId());
        crmCustomerIncomingApplicationDao.save(application);
        entry.setApplyStatus("13");
        entry.setNextApplyStatus(null);
        customerEntryService.saveByUpdate(entry);

        //退回完工
        operatingLeaseService.cancelProjectApply(application.getPartnersContractNumber(),prjCancelReason, SourceConstants.RETURN_TYPE_RETURN_TO_COMPLETION);
        logger.info(">>>>>>returnIncomingToCompletion  entryId:{}",entryId);
        CrmYxIncomingProcessDao.returnIncomingProcess(entryId,"4,5");
        String rea=StringUtil.isBlank(prjCancelReason)?"":",原因："+prjCancelReason;
        msgService.saveCustomerEntryMsg(user,entryId, CustomerEntryConstants.INCOMING_CANCEL,"退回完工"+rea);
        yxIncomingLogDao.addCrmYxIncomingLog(entry.getId(),application.getPartnersContractNumber(),"2","退回完工,退回前状态，"+str,operator);
    }

    public int financeGet(String dueDateFrom,String dueDateTo,String partnersContractNumber){
        List<CrmEntryCashFlow> list= operatingLeaseService.financeGet(dueDateFrom,dueDateTo,partnersContractNumber);
        logger.info(">>>>>>>financeGet  list.size:{}",list.size());
        Date date=new Date();
        int i=0;
        for(CrmEntryCashFlow flow:list){
            try {
                flow.setCreateTime(date);
                crmEntryCashFlowDao.save(flow);
            }catch (Exception e){
                logger.error("financeGet e:",e);
                continue;
            }
            i++;
        }
        return i;
    }

}
