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

import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.JsonUtil;
import com.yoho.msgcenter.sdk.dto.MessageCenterEvent;
import com.yoho.msgcenter.sdk.handler.IMsgCenterHandler;
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.Arrays;

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

    @Autowired
    private IMsgCenterHandler msgHandler;

    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;
        }
        try {
            MessageCenterEvent centerEvent = new MessageCenterEvent();
            centerEvent.setBusinessLine("yohobuy");
            centerEvent.setUserType("UID");
            centerEvent.setUserList(Arrays.asList(Integer.toString(uid)));
            JSONObject params = new JSONObject();
            String timeStr = DateUtil.long2DateStr(Long.valueOf(time) * 1000, DateUtil.DATE_TIME_FORMAT);
            if (type == 1) {
                //预估佣金提醒
                centerEvent.setSendScene("YZ_ESTIMATE_SETTLE");
                params.put("orderAmount", amount);
                params.put("nowTime", timeStr);
            }
            if (type == 2) {
                //提现打款提醒
                centerEvent.setSendScene("YZ_CRASH_ACCOUNT");
                params.put("orderAmount", amount);
                params.put("crashTime", timeStr);
            }
            if (type == 3) {
                //可结算提醒
                centerEvent.setSendScene("YZ_COMMISSION_SETTLE");
                params.put("orderAmount", amount);
                params.put("crashTime", timeStr);
            }
            if (type == 4) {
                //申请成功提醒
                centerEvent.setSendScene("YZ_JOIN_SUCCESS");
                params.put("passTime", timeStr);
            }
            centerEvent.setParams(params);
            msgHandler.send(centerEvent);
            log.info("sendMessage end,uid is {},type is {},time is {},amount is {},centerEvent is {}.",uid,type,timeStr,amount, JsonUtil.objectToJSON(centerEvent));
        } catch (Exception e) {
            log.error("sendMessage error,e is {}.",e);
        }
    }
}