private MemberCashvalue updateMemberCashValueData(
      Member member, MemberCashValuePaymentDto memberCashValuePaymentDto)
      throws GTACommonException {
    MemberCashvalue memberCashvalue = null;
    Long customerId = member.getCustomerId();
    String memberType = member.getMemberType();
    if (!StringUtils.isEmpty(memberType)) {
      if ((Constant.memberType.IDM.toString().equalsIgnoreCase(memberType)
              || Constant.memberType.CDM.toString().equalsIgnoreCase(memberType))
          && (null != member.getSuperiorMemberId() && member.getSuperiorMemberId() > 0)) {
        MemberLimitRule memberLimitRuleTRN =
            memberLimitRuleDao.getMemberLimitRule(customerId, LimitType.TRN.name());
        if (null != memberLimitRuleTRN) {
          BigDecimal numValue = memberLimitRuleTRN.getNumValue();
          if (limitUnit.EACH.name().equals(memberLimitRuleTRN.getLimitUnit())) {
            if (memberCashValuePaymentDto.getTotalAmount().compareTo(numValue) > 0)
              throw new GTACommonException(GTAError.MemberError.PAYMENTAMOUNT_EXCEEDS_PERPAYMENT);
          }
        }
        memberCashvalue = memberCashValueDao.getMemberCashvalueById(member.getSuperiorMemberId());
        customerId = member.getSuperiorMemberId();
      } else {
        memberCashvalue = memberCashValueDao.getMemberCashvalueById(customerId);
      }
    }

    if (memberCashvalue == null) {
      memberCashvalue = new MemberCashvalue();
      memberCashvalue.setCustomerId(customerId);
      memberCashvalue.setAvailableBalance(BigDecimal.ZERO);
      memberCashvalue.setInitialValue(BigDecimal.ZERO);
      memberCashvalue.setInitialDate(new Date());
    }
    if (memberCashvalue.getAvailableBalance().compareTo(memberCashValuePaymentDto.getTotalAmount())
        <= 0) {
      MemberLimitRule memberLimitRuleCR =
          memberLimitRuleDao.getMemberLimitRule(customerId, LimitType.CR.name());
      if (null != memberLimitRuleCR) {
        BigDecimal numValue = memberLimitRuleCR.getNumValue();
        if (((memberCashvalue
                        .getAvailableBalance()
                        .subtract(memberCashValuePaymentDto.getTotalAmount()))
                    .negate())
                .compareTo(numValue)
            > 0) {
          throw new GTACommonException(GTAError.MemberError.PAYMENTAMOUNT_EXCEEDS_CREDITLIMIT);
        }
      } else {
        throw new GTACommonException(GTAError.MemberError.MEMBER_INSUFFICIENT_BALANCE);
      }
    }
    memberCashvalue.setAvailableBalance(
        memberCashvalue.getAvailableBalance().subtract(memberCashValuePaymentDto.getTotalAmount()));
    memberCashValueDao.saveOrUpdate(memberCashvalue);
    return memberCashvalue;
  }
  @Override
  @Transactional
  public MemberCashvalue getMemberCashvalueByVirtualAccNo(String virtualAccNo) throws Exception {

    if (CommUtil.nvl(virtualAccNo).length() == 0) return null;
    return memberCashValueDao.getByVirtualAccNo(virtualAccNo);
  }
 @Override
 @Transactional
 public MemberCashvalue getMemberCashvalueById(Long customerId) throws Exception {
   return memberCashValueDao.getMemberCashvalueById(customerId);
 }
 @Transactional
 public MemberCashvalue getMemberCashvalueByCustomerId(Long CustomerId) throws Exception {
   return memberCashValueDao.getByCustomerId(CustomerId);
 }
 @Override
 @Transactional
 public boolean modifyMemberCashvalue(MemberCashvalue memberCashValue) throws Exception {
   return memberCashValueDao.updateMemberCashValue(memberCashValue);
 }