package cn.superdesk.uniorder.executor.scheduler.kafka._thirdpart.qchjc.accounting.customer.biz;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import cn.superdesk.uniorder.common.bizScene.invoice.customer.InvoiceApplyCustomerScene;
import cn.superdesk.uniorder.common.enums.accounting.AccountingOrderInvoiceApplyStatusEnum;
import cn.superdesk.uniorder.common.enums.accounting.AccountingOrderTypeDimEnum;
import cn.superdesk.uniorder.common.enums.accounting.customer.AccountingOrderCustomerAccountingStatusEnum;
import cn.superdesk.uniorder.common.enums.common.CommonServiceNoEnum;
import cn.superdesk.uniorder.common.enums.common.CommonSourceFromEnum;
import cn.superdesk.uniorder.common.enums.invoice.customer.InvoiceApplyCustomerBackAccountStatusEnum;
import cn.superdesk.uniorder.common.enums.invoice.customer.InvoiceApplyCustomerInvoiceProgressingStatusEnum;
import cn.superdesk.uniorder.common.enums.thirdpart.qchjc.QchjcCustomerInvoiceStatusEnum;
import cn.superdesk.uniorder.common.enums.thirdpart.qchjc.QchjcCustomerReceivePaymentStatusEnum;
import cn.superdesk.uniorder.common.lamda.AnLamdaUtils;
import cn.superdesk.uniorder.common.numerical.AnStringUtils;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.accounting.score.customer.AccountingScoreCustomer;
import cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApply;
import cn.superdesk.uniorder.dao.entity.order.ExpressCompany;
import cn.superdesk.uniorder.dto.param.thirdpart.qchjc.api.customer.QchjcCustomerCancelStatementParam;
import cn.superdesk.uniorder.dto.param.thirdpart.qchjc.api.customer.QchjcCustomerMakeInvoiceStatusParam;
import cn.superdesk.uniorder.dto.param.thirdpart.qchjc.api.customer.QchjcCustomerReceivePaymentStatusParam;
import cn.superdesk.uniorder.executor.scheduler.kafka._thirdpart.qchjc.BaseThirdpartQchjcHandleService;
import cn.superdesk.uniorder.executor.scheduler.kafka._thirdpart.qchjc._constants.ThirdpartQchjcTopicChannelConstants;
import cn.superdesk.uniorder.executor.scheduler.kafka._thirdpart.qchjc.dto.accounting.customer.QchjcCustomerStatementEvent;
import cn.superdesk.uniorder.executor.scheduler.kafka._thirdpart.qchjc.dto.accounting.customer.QchjcCustomerStatementEventMultipleStructVo;
import cn.superdesk.uniorder.executor.scheduler.kafka._thirdpart.qchjc.dto.accounting.customer.QchjcCustomerStatementEventSingleStructVo;
import cn.superdesk.uniorder.service.accounting.score.customer.AccountingScoreCustomerService;
import cn.superdesk.uniorder.service.invoice.customer.InvoiceApplyCustomerService;
import cn.superdesk.uniorder.service.invoice.customer.InvoiceApplyXGoodsService;
import cn.superdesk.uniorder.service.order._leaveover.ExpressCompanyService;
import cn.superdesk.uniorder.service.thirdpart.qchjc.account.QchjcCustomerStatementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2022/5/10 2:42 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/5/10 2:42 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class QchjcCustomerStatementHandleService extends BaseThirdpartQchjcHandleService {

    @Autowired
    private AccountingScoreCustomerService accountingScoreCustomerService;

    @Autowired
    private InvoiceApplyCustomerService invoiceApplyCustomerService;
    @Autowired
    private InvoiceApplyXGoodsService   invoiceApplyXGoodsService;

    @Autowired
    private ExpressCompanyService expressCompanyService;

    @Autowired
    private QchjcCustomerStatementService qchjcCustomerStatementService;

    /**
     * ~ 待回款
     *
     * @param messageKey
     * @param messageBody
     * @param now
     * @return
     */
    public int makeInvoiceStatusSyncHandle(String messageKey, String messageBody, Date now) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("集采采购单位开票状态同步处理开始 messageKey:{} messageBody:{}", messageKey, messageBody);

        QchjcCustomerStatementEvent event = JSONUtil.toBean(messageBody, QchjcCustomerStatementEvent.class);

        LoginSysUser loginSysUser = JSONUtil.toBean(event.getLoginSysUser(), LoginSysUser.class);
        Date         touchTime    = event.getTouchTime();

        String msg = event.getMsg();

        QchjcCustomerStatementEventSingleStructVo   singleStructVo   = event.getSingleStructVo();
        QchjcCustomerStatementEventMultipleStructVo multipleStructVo = event.getMultipleStructVo();


        Integer areYouOk = 0;
        // 目前为 定义项检查
        Integer checkPoint = 2;


        /**************************************** Hey bother! are you ready? start ****************************************/


        AccountingScoreCustomer accountingScoreCustomerEntity = null;
        Long                    accountingOrderId             = null;
        String                  accountingOrderSn             = null;

        if (ObjectUtil.isNotNull(singleStructVo)) {

            /****************************************  start ****************************************/

            // step01 从发票单
            Long   invoiceApplyId = singleStructVo.getInvoiceApplyId();
            String invoiceApplySn = singleStructVo.getInvoiceApplySn();

            // 得出受影响的对账单 ids
            List<Long> affectedAccountingOrderIds = invoiceApplyXGoodsService.getAffectedAccountingOrderIdsByInvoiceApplyId(invoiceApplyId);

            if (CollUtil.isEmpty(affectedAccountingOrderIds)) {
                return 0;
            }

            accountingOrderId = affectedAccountingOrderIds.get(0);

            accountingScoreCustomerEntity = accountingScoreCustomerService.findById(accountingOrderId);

            accountingOrderSn = accountingScoreCustomerEntity.getAccountingOrderSn();

        } else {

            /****************************************  start ****************************************/

            List<QchjcCustomerStatementEventSingleStructVo> items = multipleStructVo.getItems();

            // step01 从对账单
            List<String> accountingOrderSns = items
                    .stream()
                    .filter(AnLamdaUtils.distinctByKey(o -> o.getAccountingOrderSn()))
                    .map(QchjcCustomerStatementEventSingleStructVo::getAccountingOrderSn)
                    .collect(Collectors.toList());

            if (CollUtil.isEmpty(accountingOrderSns)) {
                return 0;
            }
            if (accountingOrderSns.size() > 1) {
                return 0;
            }

            accountingOrderSn = accountingOrderSns.get(0);

            accountingScoreCustomerEntity = accountingScoreCustomerService.findByAccountingOrderSn(accountingOrderSn);

            accountingOrderId = accountingScoreCustomerEntity.getId();
        }

        if (ObjectUtil.isNull(accountingScoreCustomerEntity)) {
            return 0;
        }

        /****************************************  start ****************************************/


        List<InvoiceApply> invoiceApplyCustomerEntitysExistDb = invoiceApplyCustomerService.findByAccountingOrderSn(
                accountingOrderSn,
                AccountingOrderTypeDimEnum.积分订单
        );

        /**************************************** 申请状态 start ****************************************/

        List<Integer> invoiceProgressingStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getInvoiceStatus()))
                .map(InvoiceApply::getInvoiceStatus)
                .collect(Collectors.toList());

        /**************************************** 开票状态 start ****************************************/

        List<Integer> makeInvoiceStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getMakeInvoiceStatus()))
                .map(InvoiceApply::getMakeInvoiceStatus)
                .collect(Collectors.toList());

        /**************************************** 领票状态 start ****************************************/

        List<Integer> receiveInvoiceStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getReceiveInvoiceStatus()))
                .map(InvoiceApply::getReceiveInvoiceStatus)
                .collect(Collectors.toList());

        /**************************************** 寄票状态 start ****************************************/

        List<Integer> mailTickStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getMailTickStatus()))
                .map(InvoiceApply::getMailTickStatus)
                .collect(Collectors.toList());

        /**************************************** 回款状态 start ****************************************/

        List<Integer> backAccountStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getBackAccountStatus()))
                .map(InvoiceApply::getBackAccountStatus)
                .collect(Collectors.toList());


        // 对账单的申请状态为 全部申请
        if (AccountingOrderInvoiceApplyStatusEnum.全部申请.getKey().compareTo(accountingScoreCustomerEntity.getInvoiceStatus()) == 0) {
            areYouOk = areYouOk + 1;
        }

        // 所有有效的开票申请的
        // 申请状态 均为 待回款
        if (CollUtil.isEmpty(invoiceProgressingStatusExistDb)) {
            return 0;
        } else if (invoiceProgressingStatusExistDb.size() == 1) {

            // 开票状态 唯一的情况
            InvoiceApplyCustomerInvoiceProgressingStatusEnum invoiceApplyCustomerInvoiceProgressingStatusEnum = InvoiceApplyCustomerInvoiceProgressingStatusEnum.get(invoiceProgressingStatusExistDb.get(0));

            // 意思是 唯一情况 待回款
            if (ArrayUtil.contains(
                    InvoiceApplyCustomerScene.statusV2_3_Array_InvoiceProgressingSceneOpEventQchjcCustomerStatementMakeInvoiceStatusSyncStateCheck(),
                    invoiceApplyCustomerInvoiceProgressingStatusEnum.getKey())
            ) {
                areYouOk = areYouOk + 1;
            }

        } else if (invoiceProgressingStatusExistDb.size() > 1) {
            // 意思是 不唯一情况
            return 0;
        } else {
        }

        Map<Long, ExpressCompany> snapshotExpressCompanyMap = expressCompanyService.findAllConvertKV();

        ExpressCompany expressCompany = snapshotExpressCompanyMap.get(accountingScoreCustomerEntity.getExpressCompanyId());
        if (ObjectUtil.isNull(expressCompany)) {
            expressCompany = ExpressCompany
                    .builder()
                    .id(-1L)
                    .companyName("引用异常,数据被删")
                    .build();
        }

        /**************************************** Hey bother! are you ready?   end ****************************************/

//        QchjcCustomerInvoiceStatusEnum
//        未开票("1", "未开票"),
//        已开票("2", "已开票"),
//        待开票("3", "待开票");

//        AccountingOrderInvoiceApplyStatusEnum                                        
//        未申请(0, "未申请"),                                        
//        全部申请(1, "全部申请"),                                        
//        部分申请(2, "部分申请"),                                        
//        异(3, "异"),                                        
//        寡(99, "寡"),                                        


        Map<String, String> invoiceNumberMap = new HashMap<String, String>();
        invoiceApplyCustomerEntitysExistDb.forEach(item -> {
            invoiceNumberMap.put(item.getInvoiceApplySn(), item.getInvoiceNumber());
        });

        tmpLogWithAccountingOrderSn(
                ThirdpartQchjcTopicChannelConstants.TOPIC_EVENT_CHANNEL_QCHJC_CUSTOMER_STATEMENT,
                accountingOrderSn,
                messageKey,
                messageBody,
                DateUtil.format(now, DatePattern.PURE_DATETIME_PATTERN)
        );

//        if (!CommonServiceNoEnum.企业商城_侨城汇.getServiceNo().equals(accountingScoreCustomerEntity.getServiceNo())) {
//            return 0;
//        }

        if (!CommonSourceFromEnum.企业商城_侨城汇.getSourceFromCode().equals(accountingScoreCustomerEntity.getSourceFrom())) {
            return 0;
        }

        log.info("集采采购单位对账单开票状态同步判定结果, sn: {}  , areYouOk: {}, checkPoint: {}", accountingOrderSn, areYouOk, checkPoint);
        if (areYouOk.compareTo(checkPoint) >= 0) {

            qchjcCustomerStatementService.makeInvoiceStatusSync(
                    QchjcCustomerMakeInvoiceStatusParam
                            .builder()

                            .reconciliationBuyerCode(accountingScoreCustomerEntity.getAccountingOrderSn())
                            .invoiceStatus(QchjcCustomerInvoiceStatusEnum.已开票.getStatus()) // 所有有效的开票申请的申请状态均为 待回款 时 还能有别的吗?

                            .logisticsCompany(expressCompany.getCompanyName()) // 快递公司名称
                            .logisticsNo(accountingScoreCustomerEntity.getExpressNo())
                            .logisticsCompanyType("目前没有-20220512")

                            .operatorId(AnStringUtils.getString(loginSysUser.getSysUserId()))
                            .operatorName(loginSysUser.getFullName())
                            .operatorDate(touchTime)

                            .processState(msg)

                            .invoiceNumberMap(invoiceNumberMap)

                            .build()
            );
        }


        return 0;
    }

    /**
     * ~ 已回款
     *
     * @param messageKey
     * @param messageBody
     * @param now
     * @return
     */
    public int receivePaymentStatusSyncHandle(String messageKey, String messageBody, Date now) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("集采采购单位收款状态同步处理开始 messageKey:{} messageBody:{}", messageKey, messageBody);

        QchjcCustomerStatementEvent event = JSONUtil.toBean(messageBody, QchjcCustomerStatementEvent.class);

        LoginSysUser loginSysUser = JSONUtil.toBean(event.getLoginSysUser(), LoginSysUser.class);
        Date         touchTime    = event.getTouchTime();

        String msg = event.getMsg();

        QchjcCustomerStatementEventMultipleStructVo multipleStructVo = event.getMultipleStructVo();

        List<QchjcCustomerStatementEventSingleStructVo> items = multipleStructVo.getItems();

        Integer areYouOk = 0;
        // 目前为 定义项检查
        Integer checkPoint = 3;


        /**************************************** Hey bother! are you ready? start ****************************************/

        // step01 从对账单
        List<String> accountingOrderSns = items
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getAccountingOrderSn()))
                .map(QchjcCustomerStatementEventSingleStructVo::getAccountingOrderSn)
                .collect(Collectors.toList());

        if (CollUtil.isEmpty(accountingOrderSns)) {
            return 0;
        }
        if (accountingOrderSns.size() > 1) {
            return 0;
        }

        Long   accountingOrderId = null;
        String accountingOrderSn = accountingOrderSns.get(0);

        AccountingScoreCustomer accountingScoreCustomerEntity = accountingScoreCustomerService.findByAccountingOrderSn(accountingOrderSn);

        if (ObjectUtil.isNull(accountingScoreCustomerEntity)) {
            return 0;
        }

//        if (!CommonServiceNoEnum.企业商城_侨城汇.getServiceNo().equals(accountingScoreCustomerEntity.getServiceNo())) {
//            return 0;
//        }

        if (!CommonSourceFromEnum.企业商城_侨城汇.getSourceFromCode().equals(accountingScoreCustomerEntity.getSourceFrom())) {
            return 0;
        }

        List<InvoiceApply> invoiceApplyCustomerEntitysExistDb = invoiceApplyCustomerService.findByAccountingOrderSn(
                accountingOrderSn,
                AccountingOrderTypeDimEnum.积分订单
        );

        /**************************************** 申请状态 start ****************************************/

        List<Integer> invoiceProgressingStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getInvoiceStatus()))
                .map(InvoiceApply::getInvoiceStatus)
                .collect(Collectors.toList());

        /**************************************** 开票状态 start ****************************************/

        List<Integer> makeInvoiceStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getMakeInvoiceStatus()))
                .map(InvoiceApply::getMakeInvoiceStatus)
                .collect(Collectors.toList());

        /**************************************** 领票状态 start ****************************************/

        List<Integer> receiveInvoiceStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getReceiveInvoiceStatus()))
                .map(InvoiceApply::getReceiveInvoiceStatus)
                .collect(Collectors.toList());

        /**************************************** 寄票状态 start ****************************************/

        List<Integer> mailTickStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getMailTickStatus()))
                .map(InvoiceApply::getMailTickStatus)
                .collect(Collectors.toList());

        /**************************************** 回款状态 start ****************************************/

        List<Integer> backAccountStatusExistDb = invoiceApplyCustomerEntitysExistDb
                .stream()
                .filter(AnLamdaUtils.distinctByKey(o -> o.getBackAccountStatus()))
                .map(InvoiceApply::getBackAccountStatus)
                .collect(Collectors.toList());


        /**************************************** 对账单 start ****************************************/
        // 对账单的申请状态为 全部申请
        if (AccountingOrderInvoiceApplyStatusEnum.全部申请.getKey().compareTo(accountingScoreCustomerEntity.getInvoiceStatus()) == 0) {
            areYouOk = areYouOk + 1;
        }

        /**************************************** 发票单 start ****************************************/

        // 所有有效的 开票申请
        // 申请状态 均为 已完成       <- 当前      已回款[错 如果确认回款成功，就走到终点了 已完成] 时
        // |---- 回款状态 均为 已回款
        if (CollUtil.isEmpty(invoiceProgressingStatusExistDb)) {
            return 0;
        } else if (invoiceProgressingStatusExistDb.size() == 1) {

            // 开票状态 唯一的情况
            InvoiceApplyCustomerInvoiceProgressingStatusEnum invoiceApplyCustomerInvoiceProgressingStatusEnum = InvoiceApplyCustomerInvoiceProgressingStatusEnum.get(invoiceProgressingStatusExistDb.get(0));

            // 意思是 唯一情况 已完成
            if (ArrayUtil.contains(
                    InvoiceApplyCustomerScene.statusV2_3_Array_InvoiceProgressingSceneOpEventQchjcCustomerStatementReceivePaymentStatusSyncStateCheck(),
                    invoiceApplyCustomerInvoiceProgressingStatusEnum.getKey())
            ) {
                areYouOk = areYouOk + 1;
            }

        } else if (invoiceProgressingStatusExistDb.size() > 1) {
            // 意思是 不唯一情况
            return 0;
        } else {
        }

        // 所有有效的 开票申请
        // 申请状态 均为 已完成            已回款[错 如果确认回款成功，就走到终点了 已完成] 时
        // |---- 回款状态 均为 已回款 <- 当前
        if (CollUtil.isEmpty(backAccountStatusExistDb)) {
            return 0;
        } else if (backAccountStatusExistDb.size() == 1) {

            // 开票状态 唯一的情况
            InvoiceApplyCustomerBackAccountStatusEnum invoiceApplyCustomerBackAccountStatusEnum = InvoiceApplyCustomerBackAccountStatusEnum.get(backAccountStatusExistDb.get(0));

            // 意思是 唯一情况 已回款
            if (ArrayUtil.contains(
                    InvoiceApplyCustomerScene.statusV2_3_Array_BackAccountSceneOpEventQchjcCustomerStatementReceivePaymentStatusSyncStateCheck(),
                    invoiceApplyCustomerBackAccountStatusEnum.getKey())
            ) {
                areYouOk = areYouOk + 1;
            }

        } else if (invoiceProgressingStatusExistDb.size() > 1) {
            // 意思是 不唯一情况
            return 0;
        } else {
        }

        /**************************************** Hey bother! are you ready?   end ****************************************/

//        QchjcCustomerInvoiceStatusEnum
//        未开票("1", "未开票"),
//        已开票("2", "已开票"),
//        待开票("3", "待开票");

//        AccountingOrderInvoiceApplyStatusEnum
//        未申请(0, "未申请"),
//        全部申请(1, "全部申请"),
//        部分申请(2, "部分申请"),
//        异(3, "异"),
//        寡(99, "寡"),

        tmpLogWithAccountingOrderSn(
                ThirdpartQchjcTopicChannelConstants.TOPIC_EVENT_CHANNEL_QCHJC_CUSTOMER_STATEMENT,
                accountingOrderSn,
                messageKey,
                messageBody,
                DateUtil.format(now, DatePattern.PURE_DATETIME_PATTERN)
        );

        if (!CommonServiceNoEnum.企业商城_侨城汇.getServiceNo().equals(accountingScoreCustomerEntity.getServiceNo())) {
            return 0;
        }

        log.info("集采采购单位对账单收款状态同步判定结果， sn: {}, areYouOk: {}, checkPoint: {}", accountingOrderSn, areYouOk, checkPoint);
        if (areYouOk.compareTo(checkPoint) >= 0) {

            qchjcCustomerStatementService.receivePaymentStatusSync(
                    QchjcCustomerReceivePaymentStatusParam
                            .builder()

                            .reconciliationBuyerCode(accountingScoreCustomerEntity.getAccountingOrderSn())
                            .recPaymentStatus(QchjcCustomerReceivePaymentStatusEnum.已收款.getStatus()) // 所有有效的开票申请的申请状态均为 待回款 时 还能有别的吗?

                            .operatorId(AnStringUtils.getString(loginSysUser.getSysUserId()))
                            .operatorName(loginSysUser.getFullName())
                            .operatorDate(touchTime)

                            .processState(msg)

                            .build()
            );
        }


        return 0;
    }

    /**
     * ~ 取消 作废 重开
     *
     * @param messageKey
     * @param messageBody
     * @param now
     * @return
     */
    public int statementCancelSyncHandle(String messageKey, String messageBody, Date now) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("集采采购单位对账单取消对账状态同步处理开始 messageKey:{} messageBody:{}", messageKey, messageBody);

        QchjcCustomerStatementEvent event = JSONUtil.toBean(messageBody, QchjcCustomerStatementEvent.class);

        LoginSysUser loginSysUser = JSONUtil.toBean(event.getLoginSysUser(), LoginSysUser.class);
        Date         touchTime    = event.getTouchTime();

        String msg = event.getMsg();

        QchjcCustomerStatementEventSingleStructVo singleStructVo = event.getSingleStructVo();

        Integer areYouOk = 0;
        // 目前为 定义项检查
        Integer checkPoint = 1;


        /**************************************** Hey bother! are you ready? start ****************************************/

        // step01 从对账单
        Long   accountingOrderId = singleStructVo.getAccountingOrderId();
        String accountingOrderSn = null;

        AccountingScoreCustomer accountingScoreCustomerEntity = accountingScoreCustomerService.findById(accountingOrderId);

        if (ObjectUtil.isNull(accountingScoreCustomerEntity)) {
            return 0;
        }


        accountingOrderSn = accountingScoreCustomerEntity.getAccountingOrderSn();

        // 对账单的申请状态为 全部申请
        if (AccountingOrderCustomerAccountingStatusEnum.已取消.getKey().compareTo(accountingScoreCustomerEntity.getAccountingStatus()) == 0) {
            areYouOk = areYouOk + 1;
        }

        /**************************************** Hey bother! are you ready?   end ****************************************/

        tmpLogWithAccountingOrderSn(
                ThirdpartQchjcTopicChannelConstants.TOPIC_EVENT_CHANNEL_QCHJC_CUSTOMER_STATEMENT,
                accountingOrderSn,
                messageKey,
                messageBody,
                DateUtil.format(now, DatePattern.PURE_DATETIME_PATTERN)
        );

//        if (!CommonServiceNoEnum.企业商城_侨城汇.getServiceNo().equals(accountingScoreCustomerEntity.getServiceNo())) {
//            return 0;
//        }

        if (!CommonSourceFromEnum.企业商城_侨城汇.getSourceFromCode().equals(accountingScoreCustomerEntity.getSourceFrom())) {
            return 0;
        }
        log.info("集采采购单位对账单取消对账状态判定结果，sn: {}, areYouOk: {}, checkPoint: {}", accountingOrderSn, areYouOk, checkPoint);
        if (areYouOk.compareTo(checkPoint) >= 0) {

            qchjcCustomerStatementService.statementCancelSync(
                    QchjcCustomerCancelStatementParam
                            .builder()

                            .reconciliationBuyerCode(accountingScoreCustomerEntity.getAccountingOrderSn())

                            .operatorId(AnStringUtils.getString(loginSysUser.getSysUserId()))
                            .operatorName(loginSysUser.getFullName())
                            .operatorDate(touchTime)

                            .processState(msg)

                            .build()
            );
        }

        return 0;
    }

}
