BusinessNoticeBiz.java 10.3 KB
package com.cjs.cms.biz.user;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cjs.cms.dao.user.BusinessNoticeDao;
import com.cjs.cms.dao.user.WeixinDao;
import com.cjs.cms.model.user.BusinessNoticeInfo;
import com.cjs.cms.model.user.WxUserInfo;
import com.cjs.cms.util.lang.DateEnum;
import com.cjs.cms.util.lang.DateUtil;
import com.cjs.cms.util.web.SendMessageUtil;

/**
 * 微信业务通知
 * @author kongmingke
 *
 */
@Service
public class BusinessNoticeBiz {
    @Autowired
    private BusinessNoticeDao noticeDao;
    @Autowired
    private WeixinDao         weixinDao;
    @Autowired
    private SendMessageUtil   sendMsg;
    @Autowired
    private WeiXinBiz         weiXinBiz;
    Logger                    log = LogManager.getLogger();

    /**
     * 托管鉴定发送微信通知
     */
    public void sendNotice() {
        List<Map<String, Object>> noticeInfos = noticeDao.queryNotice();
        if (noticeInfos != null && noticeInfos.size() > 0) {
            for (Map<String, Object> map : noticeInfos) {
                //添加鉴定通知信息表
                BusinessNoticeInfo info = new BusinessNoticeInfo();
                WxUserInfo wxUserInfo = weixinDao.queryByUserId(map.get("FUND_ACCOUNT").toString());
                if (wxUserInfo != null) {
                    try {
                        Map<String, String> noticeInfo = new HashMap<String, String>();
                        noticeInfo.put("openId", wxUserInfo.getOpenId());
                        noticeInfo.put("applyNo", map.get("APPLY_NO").toString());
                        noticeInfo.put("applyCount", map.get("APPLY_COUNT").toString());
                        noticeInfo.put("approvalCount", map.get("APPROVAL_COUNT").toString());
                        noticeInfo.put("backAmount", map.get("BACK_AMOUNT").toString());
                        weiXinBiz.postTemplate(noticeInfo,
                            "/template/trustapplyInfo?openId={openId}&applyNo={applyNo}&applyCount={applyCount}&approvalCount={approvalCount}&backAmount={backAmount}");
                        info.setNoticeType("0");
                        info.setNoticeStatus("1");
                        info.setNoticeContent("您好,您托管的藏品已鉴评完毕!预约号:" + map.get("APPLY_NO") + ",交付数量:"
                                              + map.get("APPLY_COUNT") + ",通过数量:"
                                              + map.get("APPROVAL_COUNT") + ",未通过数量:"
                                              + map.get("BACK_AMOUNT")
                                              + ",详情可登录官网进行查询。官网地址:www.zhao.com");
                    } catch (Exception e) {
                        info.setNoticeStatus("0");
                        log.error("", e);
                    }

                } else {
                    int result = sendMsg.send(map.get("TELPHONE")
                        .toString(), "您托管的" + map.get("OTC_NAME")
                                     + "已鉴评完毕,即日起关注官方微信或登陆官网会员中心查看详情。如有疑问详询4009690800");
                    info.setNoticeType("1");
                    info.setNoticeStatus("1");
                    info.setNoticeContent("您托管的" + map.get("OTC_NAME")
                                          + "已鉴评完毕,即日起关注官方微信或登陆官网会员中心查看详情。如有疑问详询4009690800");
                }

                info.setBusinessKey(map.get("APPLY_NO").toString());
                info.setBusinessType("10");
                info.setNoticeDate(
                    Integer.parseInt(DateUtil.parseDate(new Date(), DateEnum.UNSIGNED_DATE)));
                info.setNoticeTime(
                    Integer.parseInt(DateUtil.parseDate(new Date(), DateEnum.UNSIGNED_TIME)));
                try {
                    noticeDao.insertNotice(info);
                } catch (Exception e) {
                    log.error("", e);
                }

            }
        }
    }

    /**
     * 出金发送微信通知
     */
    public void outNotice() {
        //出金
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("businessFlag", 2042);
        params.put("businessType", "12");
        List<Map<String, Object>> outInfos = noticeDao.queryOutOrPay(params);
        if (outInfos != null && outInfos.size() > 0) {
            for (Map<String, Object> map : outInfos) {
                //添加鉴定通知信息表
                BusinessNoticeInfo info = new BusinessNoticeInfo();
                log.info(map);
                log.info("当前出金用户账号" + map.get("CLIENT_ID").toString());
                WxUserInfo wxUserInfo = weixinDao.queryByUserId(map.get("CLIENT_ID").toString());
                log.info("微信绑定用户账号" + wxUserInfo);
                if (wxUserInfo != null) {
                    log.info("微信用户已绑定");
                    try {
                        Map<String, String> noticeInfo = new HashMap<String, String>();
                        noticeInfo.put("openId", wxUserInfo.getOpenId());
                        noticeInfo.put("userId", map.get("CLIENT_ID").toString());
                        noticeInfo.put("occurBalance", map.get("OCCUR_BALANCE").toString());
                        noticeInfo.put("postBalance", map.get("POST_BALANCE").toString());
                        weiXinBiz.postTemplate(noticeInfo,
                            "/template/outInfo?openId={openId}&userId={userId}&occurBalance={occurBalance}&postBalance={postBalance}");
                        log.info("出金微信模板发送成功");
                        info.setNoticeType("0");
                        info.setNoticeStatus("1");
                        info.setNoticeContent("您好,您的出金已受理!出金账号:" + map.get("CLIENT_ID") + ",出金金额:"
                                              + map.get("OCCUR_BALANCE") + ",账户余额:"
                                              + map.get("POST_BALANCE")
                                              + ",提现金额会在第二个工作日下午14点前到账,请注意查看!");
                    } catch (Exception e) {
                        info.setNoticeStatus("0");
                        log.error("", e);
                    }

                    info.setBusinessKey(map.get("POSITION_STR").toString());
                    info.setBusinessType("12");
                    info.setNoticeDate(
                        Integer.parseInt(DateUtil.parseDate(new Date(), DateEnum.UNSIGNED_DATE)));
                    info.setNoticeTime(
                        Integer.parseInt(DateUtil.parseDate(new Date(), DateEnum.UNSIGNED_TIME)));
                    try {
                        noticeDao.insertNotice(info);
                    } catch (Exception e) {
                        log.error("", e);
                    }

                }

                /*else {
                    int result = sendMsg.send(map.get("TELPHONE").toString(),
                        "您的出金已经受理,即日起关注官方微信或登陆官网会员中心查看详情。如有疑问详询4009690800");
                    info.setNoticeType("1");
                    info.setNoticeStatus("1");
                    info.setNoticeContent("您的出金已经受理,即日起关注官方微信或登陆官网会员中心查看详情。如有疑问详询4009690800");
                }*/

            }
        }
    }

    /**
     * 入金发送微信通知
     */
    public void payNotice() {

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("businessFlag", 2041);
        params.put("businessType", "11");
        List<Map<String, Object>> payInfos = noticeDao.queryOutOrPay(params);
        if (payInfos != null && payInfos.size() > 0) {
            for (Map<String, Object> map : payInfos) {
                //添加微信通知信息表
                BusinessNoticeInfo info = new BusinessNoticeInfo();
                WxUserInfo wxUserInfo = weixinDao.queryByUserId(map.get("CLIENT_ID").toString());
                if (wxUserInfo != null) {
                    try {
                        Map<String, String> noticeInfo = new HashMap<String, String>();
                        noticeInfo.put("openId", wxUserInfo.getOpenId());
                        noticeInfo.put("userId", map.get("CLIENT_ID").toString());
                        noticeInfo.put("occurBalance", map.get("OCCUR_BALANCE").toString());
                        noticeInfo.put("postBalance", map.get("POST_BALANCE").toString());
                        weiXinBiz.postTemplate(noticeInfo,
                            "/template/paySave?openId={openId}&userId={userId}&occurBalance={occurBalance}&postBalance={postBalance}");
                        info.setNoticeType("0");
                        info.setNoticeStatus("1");
                        info.setNoticeContent("您好,您的入金已成功!入金账号:" + map.get("CLIENT_ID") + ",入金金额:"
                                              + map.get("OCCUR_BALANCE") + ",账户余额:"
                                              + map.get("POST_BALANCE")
                                              + ",详情可登录官网或者客户单进行查询。官网地址:www.zhao.com!");
                    } catch (Exception e) {
                        info.setNoticeStatus("0");
                        log.error("", e);
                    }

                    info.setBusinessKey(map.get("POSITION_STR").toString());
                    info.setBusinessType("11");
                    info.setNoticeDate(
                        Integer.parseInt(DateUtil.parseDate(new Date(), DateEnum.UNSIGNED_DATE)));
                    info.setNoticeTime(
                        Integer.parseInt(DateUtil.parseDate(new Date(), DateEnum.UNSIGNED_TIME)));
                    try {
                        noticeDao.insertNotice(info);
                    } catch (Exception e) {
                        log.error("", e);
                    }

                }

            }
        }
    }
}