//package com.crm.pay.service.impl.base;
//
//import com.crm.pay.dao.repository.CustomInfoRepository;
//import com.crm.pay.dao.repository.UserInfoRepository;
//import com.crm.pay.service.SysConfigService;
//import com.crm.rely.backend.core.constant.*;
//import com.crm.rely.backend.core.entity.system.email.SysEmailSendEntity;
//import com.crm.rely.backend.core.pojo.table.*;
//import com.crm.rely.backend.core.exception.ServiceException;
//import com.crm.rely.backend.service.EmailService;
//import com.crm.rely.backend.util.DateUtil;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.math.BigDecimal;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Map;
//
//public class BaseFinanceWithdrawSendEmailServiceImpl {
//    @Autowired
//    private SysConfigService sysConfigService;
//    @Autowired
//    private CustomInfoRepository customInfoRepository;
//    @Autowired
//    private UserInfoRepository userInfoRepository;
//    @Autowired
//    private EmailService emailService;
//
//    protected void sendWithdrawEmail(FinanceWithdrawTable financeWithdrawTable, String templateName) throws ServiceException {
//
//        sendWithdrawEmail(templateName,
//                financeWithdrawTable.getPlatform(),
//                financeWithdrawTable.getLogin(),
//                financeWithdrawTable.getAmount(),
//                financeWithdrawTable.getCurrency(),
//                financeWithdrawTable.getTransformAmount(),
//                financeWithdrawTable.getSerial(),
//                financeWithdrawTable.getAddTime(),
//                financeWithdrawTable.getCustomId(),
//                financeWithdrawTable.getBankUname(),
//                financeWithdrawTable.getBankName(),
//                financeWithdrawTable.getBankCardNum(),
//                financeWithdrawTable.getBankBranchName(),
//                financeWithdrawTable.getName(),
//                financeWithdrawTable.getTransformCurrency(),
//                financeWithdrawTable.getAddress(),
//                financeWithdrawTable.getMessage(),
//                financeWithdrawTable.getBankAddr(),
//                financeWithdrawTable.getSwiftCode(),
//                financeWithdrawTable.getCustomBankCode(),
//                financeWithdrawTable.getRemitChannelName());
//    }
//
//    protected void sendWithdrawEmail(FinanceAgentWithdrawTable financeAgentWithdrawTable, String templateName) throws ServiceException {
//
//        sendWithdrawEmail(templateName,
//                financeAgentWithdrawTable.getPlatform(),
//                financeAgentWithdrawTable.getLogin(),
//                financeAgentWithdrawTable.getAmount(),
//                financeAgentWithdrawTable.getCurrency(),
//                financeAgentWithdrawTable.getTransformAmount(),
//                financeAgentWithdrawTable.getSerial(),
//                financeAgentWithdrawTable.getAddTime(),
//                financeAgentWithdrawTable.getCustomId(),
//                financeAgentWithdrawTable.getBankUname(),
//                financeAgentWithdrawTable.getBankName(),
//                financeAgentWithdrawTable.getBankCardNum(),
//                financeAgentWithdrawTable.getBankBranchName(),
//                financeAgentWithdrawTable.getName(),
//                financeAgentWithdrawTable.getTransformCurrency(),
//                financeAgentWithdrawTable.getAddress(),
//                financeAgentWithdrawTable.getMessage(),
//                financeAgentWithdrawTable.getBankAddr(),
//                financeAgentWithdrawTable.getSwiftCode(),
//                financeAgentWithdrawTable.getCustomBankCode(),
//                financeAgentWithdrawTable.getRemitChannelName());
//    }
//
//    private void sendWithdrawEmail(String templateName,
//                                   String platform,
//                                   Long login,
//                                   BigDecimal amount,
//                                   String currency,
//                                   BigDecimal transformAmount,
//                                   String serial,
//                                   Date addTime,
//                                   Long customId,
//                                   String bankUname,
//                                   String bankName,
//                                   String bankCardNum,
//                                   String bankBranchName,
//                                   String name,
//                                   String transformCurrency,
//                                   String address,
//                                   String message,
//                                   String bankAddr,
//                                   String swiftCode,
//                                   String customBankCode,
//                                   String walletPlatform) throws ServiceException {
//        Map<String, String> map = new HashMap<>(20);
//
//        map.put(MapConstants.PLATFORM, platform);
//        map.put(MapConstants.LOGIN, login + "");
//        map.put(MapConstants.WITHDRAW_AMOUNT, amount == null ? "" : String.format("%.2f", amount.doubleValue()));
//        map.put(MapConstants.CURRENCY_TYPE, currency);
//        map.put(MapConstants.TRANSFORM_AMOUNT, transformAmount == null ? "" : String.format("%.2f", transformAmount.doubleValue()));
//        map.put(MapConstants.SERIAL, serial);
//        map.put(MapConstants.APPLY_TIME, DateUtil.formatTime(addTime));
//        map.put(MapConstants.DATE_TIME, DateUtil.formatTime(new Date()));
//
//        SysConfigTable sysConfigTable = sysConfigService.getByCode(ConfigConstants.FINANCE_WITHDRAW_EMAIL_NOTICE);
//        if (sysConfigTable == null) {
//            throw new ServiceException(Constants.SYSTEM_ERROR);
//        }
//        String users = sysConfigTable.getValue();
//
//        if (users == null) {
//            throw new ServiceException(Constants.SYSTEM_ERROR);
//        }
//
//        CustomInfoTable customInfoTable = customInfoRepository.getFirstById(customId);
//        if (customInfoTable == null) {
//            throw new ServiceException(Constants.USER_NOT_EXIST_ERROR);
//        }
//        UserInfoTable userInfoTable = null;
//        if (customInfoTable.getAgentId() != null) {
//            userInfoTable = userInfoRepository.getFirstById(customInfoTable.getIbId());
//        }
//
//        if (userInfoTable != null) {
//            map.put(MapConstants.P_IB_NO, userInfoTable.getIbNo());
//        } else {
//            map.put(MapConstants.P_IB_NO, "--");
//        }
//
//        if (SystemEmailCodeConstants.FINANCE_WITHDRAW_BANK_NOTICE_NAME.equals(templateName)) {
//            map.put(MapConstants.BANK_UNAME, bankUname);
//            map.put(MapConstants.BANK_NAME, bankName);
//            map.put(MapConstants.BANK_CARD_NUM, bankCardNum);
//            map.put(MapConstants.BANK_BRANCH_NAME, bankBranchName);
//        } else if (SystemEmailCodeConstants.FINANCE_WITHDRAW_DIGITAL_NOTICE_NAME.equals(templateName)) {
//            map.put(MapConstants.NAME, name);
//            map.put(MapConstants.WITHDRAW_TRANSFORM_CURRENCY, transformCurrency);
//            map.put(MapConstants.DIGITAL_ADDRESS, address);
//            map.put(MapConstants.DIGITAL_MESSAGE, message);
//        } else if (SystemEmailCodeConstants.FINANCE_WITHDRAW_BANK_TELEGRAPHIC_NOTICE_NAME.equals(templateName)) {
//            map.put(MapConstants.BANK_UNAME, bankUname);
//            map.put(MapConstants.BANK_NAME, bankName);
//            map.put(MapConstants.BANK_CARD_NUM, bankCardNum);
//            map.put(MapConstants.BANK_ADDR, bankAddr);
//            map.put(MapConstants.SWIFT_CODE, swiftCode);
//            map.put(MapConstants.BANK_CODE, customBankCode);
//        } else if (SystemEmailCodeConstants.FINANCE_WITHDRAW_WALLET_NOTICE_NAME.equals(templateName)) {
//            map.put(MapConstants.NAME, name);
//            map.put(MapConstants.WITHDRAW_TRANSFORM_CURRENCY, transformCurrency);
//            map.put(MapConstants.WALLET_PLATFORM, walletPlatform);
//            map.put(MapConstants.WALLET_ADDRESS, address);
//            map.put(MapConstants.WALLET_MESSAGE, message);
//        }
//
//        SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
//        sysEmailSendEntity.setSubject("CWG WITHDRAW");
//        sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.FINANCE_WITHDRAW_NOTICE);
//        sysEmailSendEntity.setMap(map);
//        sysEmailSendEntity.setTemplateName(templateName);
//        sysEmailSendEntity.setUsers(users);
//        try {
//            emailService.sendEmail(sysEmailSendEntity);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//
//}
