package com.hzs.member.account.provider;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzs.common.core.constant.msg.ConfigMsgConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.domain.member.business.SignOnlineInfoVo;
import com.hzs.common.domain.member.detail.CuMemberAchieveLog;
import com.hzs.common.domain.member.detail.CuMemberServiceLog;
import com.hzs.common.domain.member.detail.CuMemberServiceLogExt;
import com.hzs.common.domain.member.empty.CuMemberEmpty;
import com.hzs.common.domain.member.empty.CuMemberEmptyLog;
import com.hzs.common.domain.system.base.BdCountry;
import com.hzs.common.domain.system.config.BdAwards;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.util.TransactionUtils;
import com.hzs.member.base.service.ICuMemberAchieveLogService;
import com.hzs.member.base.service.ICuMemberService;
import com.hzs.member.detail.service.ICuMemberServiceLogService;
import com.hzs.member.empty.service.ICuMemberEmptyLogService;
import com.hzs.member.empty.service.ICuMemberEmptyService;
import com.hzs.member.empty.service.IMemberEmptyService;
import com.hzs.member.handlebusiness.ICuHandleBusinessServiceApi;
import com.hzs.member.handlebusiness.dto.AnalysisBusinessAppealParam;
import com.hzs.member.handlebusiness.dto.MemberEmptyDTO;
import com.hzs.member.handlebusiness.service.ICuHandleBusinessService;
import com.hzs.sale.order.ISaOrderServiceApi;
import com.hzs.system.base.ICountryServiceApi;
import com.hzs.system.config.IAwardsServiceApi;
import com.hzs.system.config.IGradeServiceApi;
import com.hzs.system.config.dto.GradeDTO;
import com.hzs.system.sys.dto.ApprovalBusinessResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * 会员业务处理
 */
@Slf4j
@DubboService
public class ICuHandleBusinessServiceProvider implements ICuHandleBusinessServiceApi {

    @Autowired
    private ICuMemberServiceLogService iCuMemberServiceLogService;
    @Autowired
    private ICuHandleBusinessService handleBusinessService;
    @Autowired
    private ICuMemberService cuMemberService;
    @Autowired
    private IMemberEmptyService iMemberEmptyService;
    @Autowired
    private ICuMemberEmptyService iCuMemberEmptyService;
    @Autowired
    private ICuMemberEmptyLogService iCuMemberEmptyLogService;
    @Autowired
    private ICuMemberAchieveLogService iCuMemberAchieveLogService;
    @Autowired
    private ICuMemberAchieveLogService cuMemberAchieveLogService;

    @DubboReference
    IGradeServiceApi gradeServiceApi;
    @DubboReference
    IAwardsServiceApi awardsServiceApi;
    @DubboReference
    ICountryServiceApi countryServiceApi;
    @DubboReference
    ISaOrderServiceApi orderServiceApi;

    /**
     * 解析业务诉求信息
     *
     * @param param 业务信息
     * @return R
     */
    @Override
    public R analysisBusinessAppeal(AnalysisBusinessAppealParam param) {
        // 国家
        Integer pkCountry = param.getPkCountry();
        // 业务类型
        Integer editType = param.getEditType();

        if (editType.equals(EApprovalBusiness.EMPTY_ORDER.getValue())) {
            // 空单注册处理
            return R.ok(this.handMemberEmpty(param, pkCountry));
        }

        List<SignOnlineInfoVo> resultList = new ArrayList<>();

        CuMemberServiceLog cuMemberServiceLog = new CuMemberServiceLog();
        if (StringUtils.isNotBlank(param.getOrderNumber())) {
            cuMemberServiceLog.setOrderNumber(param.getOrderNumber());
        }
        if (StringUtils.isNotBlank(param.getBusinessNo())) {
            cuMemberServiceLog.setBusinessNo(param.getBusinessNo());
        }
        cuMemberServiceLog.setEditType(param.getEditType());
        List<CuMemberServiceLogExt> list = iCuMemberServiceLogService.selectByServiceLogList(cuMemberServiceLog);

        for (CuMemberServiceLogExt memberServiceLog : list) {
            // 变更前
            String oldValue = memberServiceLog.getOldValue();
            // 变更后
            String newValue = memberServiceLog.getNewValue();
            if (memberServiceLog.getEditType() == EApprovalBusiness.CU_MEMBER_PLACE_PARENT.getValue()) {
                boolean isJson = JSONUtil.isJson(oldValue);
                String oldJson = "";
                String newJson = "";
                if (isJson) {
                    cn.hutool.json.JSONObject oldJsonObj = JSONUtil.parseObj(oldValue);
                    oldJson = oldJsonObj.getStr("placeMemberCode");
                }
                boolean isNewJson = JSONUtil.isJson(newValue);
                String placeDeptStr = "";
                if (isNewJson) {
                    cn.hutool.json.JSONObject newJsonObj = JSONUtil.parseObj(newValue);
                    String placeMemberCode = newJsonObj.getStr("placeMemberCode");
                    Integer placeDept = newJsonObj.getInt("placeDept");
                    placeDeptStr = EPlaceDept.getEPlaceDept(placeDept);
                    newJson = placeMemberCode;
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldJson, newJson, memberServiceLog.getEditType());
                signOnlineInfoVo.setEditNewPlaceDeptStr(placeDeptStr);
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.CHANGE_NAME.getValue() ||
                    memberServiceLog.getEditType() == EApprovalBusiness.CHANGE_PHONE.getValue() ||
                    memberServiceLog.getEditType() == EApprovalBusiness.CU_MEMBER_PARENT.getValue() ||
                    memberServiceLog.getEditType() == EApprovalBusiness.ORDER_CHANGE_ADDRESS.getValue() ||
                    memberServiceLog.getEditType() == EApprovalBusiness.CHANGE_MEMBER_CODE.getValue()

            ) {
                // 修改姓名 手机  直推 安置  登录密码 支付密码 修改会员编号
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldValue, newValue, memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.CHANGE_REGISTER_GRADE.getValue() ||
                    memberServiceLog.getEditType() == EApprovalBusiness.CHANGE_SETTLEMENT_GRADE.getValue()
            ) {
                // 修改等级
                String oldLabel = null;
                if (StringUtils.isNotBlank(oldValue)) {
                    R<GradeDTO> gradeDTOR = gradeServiceApi.queryGradeConfigByCondition(pkCountry, Integer.parseInt(oldValue));
                    oldLabel = gradeDTOR.getData().getGradeName();
                }
                String newLabel = null;
                if (StringUtils.isNotBlank(newValue)) {
                    R<GradeDTO> gradeDTOR = gradeServiceApi.queryGradeConfigByCondition(pkCountry, Integer.parseInt(newValue));
                    newLabel = gradeDTOR.getData().getGradeName();
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.RESET_BANK.getValue()) {
                // 重置银行卡
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), null, "-", memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.CHANGE_AWARDS.getValue()
            ) {
                // 修改真实奖衔
                String oldLabel = null;
                String newLabel = null;

                // 奖衔配置列表
                R<List<BdAwards>> awardsList = awardsServiceApi.queryAwards(param.getPkCountry());
                for (BdAwards data : awardsList.getData()) {
                    if (data.getPkId() == Integer.parseInt(oldValue)) {
                        oldLabel = data.getAwardsName();
                    }
                    if (data.getPkId() == Integer.parseInt(newValue)) {
                        newLabel = data.getAwardsName();
                    }
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());
                if (StringUtils.isNotNull(memberServiceLog.getEndValidityDate())) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(memberServiceLog.getEndValidityDate());
                    LocalDateTime dateTime = LocalDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault());
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                    signOnlineInfoVo.setEndValidityDate(dateTime.format(formatter));
                }
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.CHANGE_MAX_AWARDS.getValue()
            ) {
                // 修改真实奖衔
                String oldLabel = null;
                String newLabel = null;

                // 奖衔配置列表
                R<List<BdAwards>> awardsList = awardsServiceApi.queryAwards(param.getPkCountry());
                for (BdAwards data : awardsList.getData()) {
                    if (oldValue != null) {
                        if (data.getPkId() == Integer.parseInt(oldValue)) {
                            oldLabel = data.getAwardsName();
                        }
                    }

                    if (data.getPkId() == Integer.parseInt(newValue)) {
                        newLabel = data.getAwardsName();
                    }
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.RESET_LOGIN_PASSWORD.getValue()) {
                // 重置会员密码
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), "-", "-", memberServiceLog.getEditType());
                // 重置密码 对应枚举 EResetPassword
                //     signOnlineInfoVo.setExpandType(memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.CHANGE_NATURAL_COUNTRY.getValue()
                    || memberServiceLog.getEditType() == EApprovalBusiness.UPDATE_SETTLE_COUNTRY.getValue()) {
                // 修改自然国家
                // 查询国家
                R<Map<Integer, BdCountry>> countryAllMap = countryServiceApi.getAllCountryMap();

                BdCountry oldCountry = countryAllMap.getData().get(Integer.parseInt(oldValue));
                BdCountry newCountry = countryAllMap.getData().get(Integer.parseInt(newValue));
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldCountry.getName(), newCountry.getName(), memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.SIGN_IN_STATE.getValue()) {
                // 修改登录状态
                String oldLabel = null;
                if (StringUtils.isNotBlank(oldValue)) {
                    oldLabel = EAccountStatus.getEAccountStatus(Integer.parseInt(oldValue)).getLabel();
                }
                String newLabel = null;
                if (StringUtils.isNotBlank(newValue)) {
                    newLabel = EAccountStatus.getEAccountStatus(Integer.parseInt(newValue)).getLabel();
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.PROFIT_STATE.getValue()) {
                // 修改收益状态
                String oldLabel = null;
                if (StringUtils.isNotBlank(oldValue)) {
                    oldLabel = EProfitState.getEnumByValue(Integer.parseInt(oldValue)).getLabel();
                }
                String newLabel = null;
                if (StringUtils.isNotBlank(newValue)) {
                    newLabel = EProfitState.getEnumByValue(Integer.parseInt(newValue)).getLabel();
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.WALLET_STATE.getValue()) {
                // 修改钱包状态
                List<String> oldLabelList = new ArrayList<>();
                if (StringUtils.isNotBlank(oldValue)) {
                    for (String s : oldValue.split(",")) {
                        oldLabelList.add(EMemberAccount.getEnumByValue(Integer.parseInt(s)).getLabel());
                    }
                }
                List<String> newLabelList = new ArrayList<>();
                if (StringUtils.isNotBlank(newValue)) {
                    for (String s : newValue.split(",")) {
                        newLabelList.add(EMemberAccount.getEnumByValue(Integer.parseInt(s)).getLabel());
                    }
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), StringUtils.join(oldLabelList, ","), StringUtils.join(newLabelList, ","), memberServiceLog.getEditType().intValue());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.REGISTER_POWER_STATE.getValue()) {
                // 注册权限状态
                String oldLabel = null;
                if (StringUtils.isNotBlank(oldValue)) {
                    oldLabel = ERegistrationAuthority.getEnumByValue(Integer.parseInt(oldValue)).getLabel();
                }
                String newLabel = null;
                if (StringUtils.isNotBlank(newValue)) {
                    newLabel = ERegistrationAuthority.getEnumByValue(Integer.parseInt(newValue)).getLabel();
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.FREE_ASSESSMENT_STATE.getValue()) {
                // 修改免考状态
                List<String> oldLabelList = new ArrayList<>();
                if (StringUtils.isNotBlank(oldValue)) {
                    for (String s : oldValue.split(",")) {
                        oldLabelList.add(EFreeAssessmentState.getEnumByValue(Integer.parseInt(s)).getLabel());
                    }
                }
                List<String> newLabelList = new ArrayList<>();
                if (StringUtils.isNotBlank(newValue)) {
                    for (String s : newValue.split(",")) {
                        newLabelList.add(EFreeAssessmentState.getEnumByValue(Integer.parseInt(s)).getLabel());
                    }
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), StringUtils.join(oldLabelList, ","), StringUtils.join(newLabelList, ","), memberServiceLog.getEditType().intValue());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.REAL_NAME_AUTHENTICATION.getValue()) {
                // 实名认证
                String oldLabel = null;
                if (StringUtils.isNotBlank(oldValue)) {
                    for (ECertifiedType value : ECertifiedType.values()) {
                        if (value.getValue().equals(oldValue)) {
                            oldLabel = value.getLabel();
                        }
                    }
                }
                String newLabel = null;
                if (StringUtils.isNotBlank(newValue)) {
                    for (ECertifiedType value : ECertifiedType.values()) {
                        if (value.getValue().equals(newValue)) {
                            newLabel = value.getLabel();
                        }
                    }
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());

                signOnlineInfoVo.setSignSource(ESignSource.MANAGE.getValue());
                resultList.add(signOnlineInfoVo);
            } else if (memberServiceLog.getEditType() == EApprovalBusiness.IS_REGION.getValue()) {
                // 是否收益区域
                String oldLabel = null;
                if (StringUtils.isNotBlank(oldValue)) {
                    oldLabel = EDealerYesNo.getLabelByIntValue(Integer.parseInt(oldValue));
                }
                String newLabel = null;
                if (StringUtils.isNotBlank(newValue)) {
                    newLabel = EDealerYesNo.getLabelByIntValue(Integer.parseInt(newValue));
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);

            } else if (memberServiceLog.getEditType() == EApprovalBusiness.IS_ACTIVATE.getValue()) {
                // 是否激活
                String oldLabel = null;
                if (StringUtils.isNotBlank(oldValue)) {
                    oldLabel = EDealerYesNo.getLabelByIntValue(Integer.parseInt(oldValue));
                }
                String newLabel = null;
                if (StringUtils.isNotBlank(newValue)) {
                    newLabel = EDealerYesNo.getLabelByIntValue(Integer.parseInt(newValue));
                }
                SignOnlineInfoVo signOnlineInfoVo = paddingSignOnlineInfoVo(memberServiceLog.getMemberName(), memberServiceLog.getMemberCode(), oldLabel, newLabel, memberServiceLog.getEditType());
                resultList.add(signOnlineInfoVo);
            }

        }
        return R.ok(resultList);
    }

    /**
     * 设置子项
     *
     * @param memberName
     * @param memberCode
     * @param oldValue
     * @param newValue
     * @param approvalBusinessType
     * @return
     */
    private SignOnlineInfoVo paddingSignOnlineInfoVo(String memberName,
                                                     String memberCode, String oldValue, String newValue, Integer approvalBusinessType) {
        SignOnlineInfoVo signOnlineInfoVo = new SignOnlineInfoVo();
        signOnlineInfoVo.setMemberName(memberName);
        signOnlineInfoVo.setMemberCode(memberCode);
        signOnlineInfoVo.setOldValue(oldValue);
        signOnlineInfoVo.setNewValue(newValue);
        signOnlineInfoVo.setApprovalBusinessType(approvalBusinessType);
        return signOnlineInfoVo;
    }

    /**
     * 在线签呈 （审批状态） 同意/驳回
     */
    @Override
    public R<?> signForApproval(ApprovalBusinessResultDTO resultDTO) {
        try {
            String str;
            switch (resultDTO.getEApprovalBusiness()) {
                case CHANGE_MEMBER_CODE:
                case MEMBER_ACHIEVE:
                case POLICY_CURRENCY_YES_NO:
                case DEL_POLICY_CURRENCY_YES_NO:
                case UPDATE_SETTLE_COUNTRY:
                case AWARDS_CONTROL_SAVE:
                case AWARDS_CONTROL_MODIFY:
                case AWARDS_CONTROL_DELETE:
                case CU_MEMBER_PARENT:
                case CU_MEMBER_PLACE_PARENT:
                case ZERO_ELEMENT_REVOKE:
                case EMPTY_ORDER:
                    // 空单注册
                    if (EApproveOperation.AGREE.getValue() == resultDTO.getApproveOperation()) {
                        // 通过
                        str = iMemberEmptyService.approvalAgree(resultDTO, SecurityUtils.getSystemType());
                    } else {
                        // 驳回
                        str = iMemberEmptyService.approvalReject(resultDTO);
                    }
                    break;
                default:
                    return handleBusinessService.signForApprovalExamine(resultDTO);
            }
            // 处理返回
            if (null == str) {
                return R.ok();
            }
            return R.fail(str);
        } catch (Exception e) {
            log.error("会员业务签呈回调处理异常. dto: {}", resultDTO, e);
            return R.fail(e.getMessage());
        }
    }


    /**
     * @description: 特殊业务处理
     * @author: zhang jing
     * @date: 2023/5/16 20:06
     * @param: [resultDTO]
     * @return: com.hzs.common.core.domain.R
     **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String auditProcess(ApprovalBusinessResultDTO resultDTO) {
        try {
            // 查询订单修改记录
            LambdaQueryWrapper<CuMemberServiceLog> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(CuMemberServiceLog::getBusinessNo, resultDTO.getBusinessCode());
            List<CuMemberServiceLog> cuMemberServiceLogList = iCuMemberServiceLogService.list(queryWrapper);
            //校验注水业绩
            if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.MEMBER_ACHIEVE.getValue()) {
                // TODO  注水业绩在这拦住了 其他的校验
                LambdaQueryWrapper<CuMemberAchieveLog> queryWrapper1 = new LambdaQueryWrapper<>();
                queryWrapper1.eq(CuMemberAchieveLog::getBusinessNo, resultDTO.getBusinessCode());
                queryWrapper1.eq(CuMemberAchieveLog::getApproveStatus, EApproveStatus.ALREADY_SUBMIT.getValue());
                List<CuMemberAchieveLog> malList = iCuMemberAchieveLogService.list(queryWrapper1);
                if (CollectionUtils.isEmpty(cuMemberServiceLogList) && CollectionUtils.isEmpty(malList)) {
                    log.info("特殊业务：签呈不存在");
                    return TransactionUtils.getContent(ConfigMsgConstants.PETITION_ABSENT_ERROR);
                }
            }

            if (!CollectionUtils.isEmpty(cuMemberServiceLogList)) {
                CuMemberServiceLog cuMemberServiceLog = cuMemberServiceLogList.get(0);
                if (EApproveStatus.ALREADY_SUBMIT.getValue() != cuMemberServiceLog.getApproveStatus()) {
                    log.info("特殊业务:签呈已审核");
                    return TransactionUtils.getContent(ConfigMsgConstants.PETITION_AUDITED_ERROR);
                }
            }
            //修改会员编号
            if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.CHANGE_MEMBER_CODE.getValue()) {
                //审核通过
                if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.FINISH.getValue()) {
                    cuMemberService.updateCodeByBusinessNo(resultDTO);
                    return null;
                } else if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.REJECTED.getValue()) {
                    cuMemberService.updateCodeReject(resultDTO);
                    return null;
                }
                //注水业绩
            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.MEMBER_ACHIEVE.getValue()) {
                cuMemberAchieveLogService.toExamine(resultDTO);
                return null;
            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.POLICY_CURRENCY_YES_NO.getValue()) {
                //修改政策币
                cuMemberService.upPolicyCurrencyProcess(resultDTO);
                return null;
            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.DEL_POLICY_CURRENCY_YES_NO.getValue()) {
                //删除政策币
                cuMemberService.delPolicyCurrencyProcess(resultDTO);
                return null;
            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.ZERO_ELEMENT_REVOKE.getValue()) {
                //零元撤单
                cuMemberService.zeroByBusinessNo(resultDTO);
                return null;
            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.UPDATE_SETTLE_COUNTRY.getValue()) {
                //审核通过
                if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.FINISH.getValue()) {
                    cuMemberService.updateSettleCountryAdopt(resultDTO);
                    return null;
                } else if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.REJECTED.getValue()) {
                    cuMemberService.updateSettleCountryReject(resultDTO);
                    return null;
                }
            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.EMPTY_ORDER.getValue()) {
                // 审核通过  空单注册
                if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.FINISH.getValue()) {
                    orderServiceApi.regEmptyOrderApproved(resultDTO);
                    return null;
                } else if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.REJECTED.getValue()) {
                    // 驳回
                    orderServiceApi.regEmptyOrderReject(resultDTO);
                    return null;
                }
            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.AWARDS_CONTROL_SAVE.getValue() ||
                    resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.AWARDS_CONTROL_MODIFY.getValue() ||
                    resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.AWARDS_CONTROL_DELETE.getValue()
            ) {
                cuMemberService.awardsControlPetition(resultDTO);
                return null;
            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.CU_MEMBER_PARENT.getValue()) {
                // 修改直推
                if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.FINISH.getValue()) {
                    cuMemberService.updateParentByBusinessNo(resultDTO);
                    return null;
                } else if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.REJECTED.getValue()) {
                    // 驳回
                    cuMemberService.updateParentByBusinessNoReject(resultDTO);
                    return null;
                }

            } else if (resultDTO.getEApprovalBusiness().getValue() == EApprovalBusiness.CU_MEMBER_PLACE_PARENT.getValue()) {
                // 修改安置
                if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.FINISH.getValue()) {
                    // 通过
                    cuMemberService.updatePlaceParentByBusinessNo(resultDTO);
                    return null;
                } else if (resultDTO.getEApproveStatus().getValue() == EApproveStatus.REJECTED.getValue()) {
                    // 驳回
                    cuMemberService.updatePlaceParentByBusinessNoReject(resultDTO);
                    return null;
                }
            }
        } catch (Exception e) {
            //异常时，审批流程事务回滚
            log.error("审核状态为： {} 的审核出错", resultDTO.getEApprovalBusiness().getValue(), e);
            return TransactionUtils.getContent(ConfigMsgConstants.MEMBER_UPDATE_CODE_ERROR);
        }
        return null;
    }

    /**
     * 处理空单注册数据
     *
     * @param param     处理参数
     * @param pkCountry 所属国家
     * @return
     */
    private MemberEmptyDTO handMemberEmpty(AnalysisBusinessAppealParam param, Integer pkCountry) {
        LambdaQueryWrapper<CuMemberEmptyLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CuMemberEmptyLog::getBusinessCode, param.getBusinessNo());
        queryWrapper.eq(CuMemberEmptyLog::getPkCountry, pkCountry);
        CuMemberEmptyLog cuMemberEmptyLog = iCuMemberEmptyLogService.getOne(queryWrapper);
        // 空单批次数据
        CuMemberEmpty cuMemberEmpty = iCuMemberEmptyService.getById(cuMemberEmptyLog.getPkMemberEmpty());

        return MemberEmptyDTO.builder()
                .pkMemberEmpty(cuMemberEmpty.getPkId())
                .businessCode(cuMemberEmpty.getBusinessCode())
                .remark(cuMemberEmpty.getRemark())
                .creationTime(cuMemberEmpty.getCreationTime())
                .build();
    }

}
