SendMessageHelper.java 2.91 KB
package com.yoho.unions.helper;

import com.yoho.message.sdk.common.model.SendMessageRspBo;
import com.yoho.message.sdk.service.product.ISendProductMessage;
import com.yoho.unions.common.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 *  公众号消息推送
 * Created by mingdan.ge on 2018/9/19.
 */
@Component
public class SendMessageHelper {
    static Logger log = LoggerFactory.getLogger(SendMessageHelper.class);

    @Autowired
    ISendProductMessage iSendProductMessage;

    //模版ID
//    static Map<Integer, String> keyMap = new HashMap<Integer, String>(){{
//        put(1,"AyIBF3VgCkk4V4s4NIuNmjcIe5IUeufmlMXv0oxcj74");//每日新产生佣金提醒
//        put(2,"9nUlr41s8vvOgKZ-xA5_VV_Gqs-868_KxdRzDziYTa4");//提现打款提醒
//        put(3,"IE7sO6J-r1iEd-G6dmuFaN64Qnk9lqJFmsBpO1YACWs");//可结算提醒
//        put(4,"QtoMH65mEHuDYMAtNKLSrIxQKqNNdDLDl_dMOY1cHhw");//申请成功提醒
//    }};

    public void sendMessage(int uid, int type, int time, BigDecimal amount) {
        log.info("sendMessage enter,uid is {},type is {},time is {},amount is {}.",uid,type,time,amount);
        if (type < 1 || type > 4) {
            log.info("sendMessage end,type error,uid is {},type is {},time is {},amount is {}.",uid,type,time,amount);
            return;
        }
//        String key = keyMap.get(type);
//        if (key == null) {
//            log.info("sendMessage end,type error,uid is {},type is {},time is {},amount is {}.",uid,type,time,amount);
//            return;
//        }
        try {
            String timeStr = DateUtil.long2DateStr(time * 1000, DateUtil.DATE_TIME_FORMAT);
            System.out.println(timeStr);
            SendMessageRspBo sendMessageRspBo=null;
            if (type == 1) {
                //预估佣金提醒
                sendMessageRspBo=iSendProductMessage.estimateNotice(Integer.toString(uid), amount.toString(),timeStr );
            }
            if (type == 2) {
                //提现打款提醒
                sendMessageRspBo=iSendProductMessage.cashAccountNotice(Integer.toString(uid), amount.toString(), timeStr);
            }
            if (type == 3) {
                //可结算提醒
                sendMessageRspBo=iSendProductMessage.commissionNotice(Integer.toString(uid), amount.toString(), timeStr);
            }
            if (type == 4) {
                //申请成功提醒
                sendMessageRspBo=iSendProductMessage.joinSuccessNotice(Integer.toString(uid), timeStr);
            }
            log.info("sendMessage enter,uid is {},type is {},time is {},amount is {},sendMessageRspBo is {}.",uid,type,time,sendMessageRspBo);
        } catch (Exception e) {
            log.error("sendMessage error,e is {}.",e);
        }
    }
}