k94314517
2025-03-26 e87b711cc267567d8374315dc99ef9780cb25dd8
server/visits/dmvisit_service/src/main/java/com/doumee/core/wx/wxPlat/WxPlatNotice.java
@@ -1,25 +1,16 @@
package com.doumee.core.wx.wxPlat;
import cn.emay.sdk.util.json.gson.JsonObject;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Http;
import com.doumee.core.utils.HttpsUtil;
import com.doumee.dao.business.VisitsMapper;
import com.doumee.dao.business.WxNoticeConfigMapper;
import com.doumee.dao.business.model.*;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@@ -101,10 +92,10 @@
                        wxUrlParams = Constants.WxUrlParams.VISIT_RECORD_USER;
                    }
                }
                String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        wxUrlParams
                        ,visits.getId().toString());
                String jumpUrl = systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url);
                
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
@@ -134,6 +125,7 @@
                    paramMap.put("touser", openId);
                    paramMap.put("data", dataMap);
                    String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                    log.warn("·==++--·推送微信模板信息跳转地址:{}·--++==·", jumpUrl);
                    if(StringUtils.isBlank(response)){
                        log.warn("·==++--·推送微信模板信息:{}·--++==·", "失败");
                    }else{
@@ -166,9 +158,9 @@
                if(Objects.isNull(wxNoticeConfig)){
                    return;
                }
                String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        Constants.WxUrlParams.HIDDEN_DANGER,hiddenDanger.getId().toString());
                String jumpUrl = systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url);
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
@@ -233,9 +225,9 @@
                if(Objects.isNull(wxNoticeConfig)){
                    return;
                }
                String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        Constants.WxUrlParams.HIDDEN_DANGER,hiddenDanger.getId().toString());
                String jumpUrl = systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url);
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
@@ -253,7 +245,7 @@
                thing13.put("value",Constants.equalsInteger(hiddenDanger.getStatus(),Constants.ONE)?"隐患已整改":"隐患已退回");
                //提交人
                Map<String, Object> thing10 = new HashMap<String,Object>();
                thing10.put("value",hiddenDanger.getCheckorName());
                thing10.put("value",hiddenDanger.getMemberName());
                //通知时间
                Map<String, Object> time16 = new HashMap<String,Object>();
                time16.put("value", DateUtil.getFomartDate(hiddenDanger.getDealTime(),"yyyy年MM月dd日 HH:mm:ss") );
@@ -304,9 +296,8 @@
                if(Objects.isNull(wxNoticeConfig)){
                    return;
                }
                String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        Constants.WxUrlParams.CAR_USE,carUseBook.getId().toString());
                String jumpUrl = systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url);
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
@@ -353,6 +344,7 @@
                    paramMap.put("touser", openId);
                    paramMap.put("data", dataMap);
                    String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                    log.warn("·==++--·推送微信模板信息:{}", jumpUrl);
                    if(StringUtils.isBlank(response)){
                        log.warn("·==++--·推送微信模板信息:{}·--++==·", "失败");
                    }else{
@@ -376,8 +368,8 @@
     * @param openIds
     * @param sendType 0=申请人;1=审批人
     */
    public void  sendPlatformBookTemplateNotice(SystemDictDataBiz systemDictDataBiz,WxNoticeConfigMapper wxNoticeConfigMapper, PlatformBooks platformBooks, String objCode,String token,
                                       List<String> openIds,Integer sendType){
    public void  sendPlatformBookTemplateNotice(SystemDictDataBiz systemDictDataBiz, WxNoticeConfigMapper wxNoticeConfigMapper, PlatformBooks platformBooks, String objCode, String token,
                                                List<String> openIds, Integer sendType){
        try{
            if(CollectionUtils.isNotEmpty(openIds)){
                WxNoticeConfig wxNoticeConfig =  wxNoticeConfigMapper.selectOne(new QueryWrapper<WxNoticeConfig>().lambda().eq(WxNoticeConfig::getObjType,WxPlatConstants.platformBook)
@@ -392,10 +384,8 @@
                if(!objCode.equals(WxPlatConstants.platformBookContent.platformBookUpload)){
                    wxUrlParams = Constants.WxUrlParams.PLATFORM_BOOK;
                }
                String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        wxUrlParams,platformBooks.getId().toString());
                String jumpUrl = systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url);
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
                Map<String, Object> paramMap = new HashMap<String, Object>();
@@ -438,6 +428,7 @@
                    paramMap.put("touser", openId);
                    paramMap.put("data", dataMap);
                    String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                    log.warn("·==++--·推送微信模板信息:{}", JSONObject.toJSONString(paramMap));
                    if(StringUtils.isBlank(response)){
                        log.warn("·==++--·推送微信模板信息:{}·--++==·", "失败");
                    }else{
@@ -473,9 +464,8 @@
                    return;
                }
                String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        Constants.WxUrlParams.PLATFORM_JOB_DRIVER,platformJob.getId().toString());
                String jumpUrl = systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url);
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
@@ -527,7 +517,7 @@
                                       List<String> openIds){
        try{
            if(CollectionUtils.isNotEmpty(openIds)){
                WxNoticeConfig wxNoticeConfig =  wxNoticeConfigMapper.selectOne(new QueryWrapper<WxNoticeConfig>().lambda().eq(WxNoticeConfig::getObjType,WxPlatConstants.visit)
                WxNoticeConfig wxNoticeConfig =  wxNoticeConfigMapper.selectOne(new QueryWrapper<WxNoticeConfig>().lambda().eq(WxNoticeConfig::getObjType,WxPlatConstants.platformJob)
                        .eq(WxNoticeConfig::getObjCode,objCode)
                        .eq(WxNoticeConfig::getStatus, Constants.ZERO)
                        .last(" limit 1")
@@ -536,9 +526,8 @@
                    return;
                }
                String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        Constants.WxUrlParams.PLATFORM_JOB_DRIVER,platformJob.getId().toString());
                String jumpUrl = systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url);
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
@@ -597,9 +586,8 @@
                    return;
                }
                String url = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        Constants.WxUrlParams.PLATFORM_JOB_DRIVER,platformJob.getId().toString());
                String jumpUrl = systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.SIGN_IN_QRCODE_PREFIX).getCode().replace( "${param}", url);
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
@@ -613,14 +601,14 @@
                Map<String, Object> car_number3 = new HashMap<String,Object>();
                car_number3.put("value",platformJob.getCarCodeFront());
                //月台号
                Map<String, Object> character_string7 = new HashMap<String,Object>();
                character_string7.put("value", "A001");
                Map<String, Object> thing9 = new HashMap<String,Object>();
                thing9.put("value", platformJob.getPlatformName());
                //时间
                Map<String, Object> time4 = new HashMap<String,Object>();
                time4.put("value", DateUtil.getFomartDate(new Date(),"yyyy年MM月dd日 HH:mm:ss") );
                dataMap.put("const6",const6);
                dataMap.put("car_number3",car_number3);
                dataMap.put("character_string7",character_string7);
                dataMap.put("thing9",thing9);
                dataMap.put("time4",time4);
                for (String openId:openIds) {
                    paramMap.clear();
@@ -629,23 +617,150 @@
                    paramMap.put("touser", openId);
                    paramMap.put("data", dataMap);
                    String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                    log.warn("·==++--·推送微信模板信息内容:{}", JSONObject.toJSONString(paramMap));
                    log.error("·==++--·推送微信模板信息内容:{}", JSONObject.toJSONString(paramMap));
                    if(StringUtils.isBlank(response)){
                        log.warn("·==++--·推送微信模板信息:{}·--++==·", "失败");
                        log.error("·==++--·推送微信模板信息:{}·--++==·", "失败");
                    }else{
                        JSONObject json = JSONObject.parseObject(response);
                        log.warn("·==++--·推送微信模板信息:{}·--++==·", Constants.equalsInteger(json.getInteger("errcode"),Constants.ZERO)?"成功":"失败"+json.getString("errmsg"));
                        log.error("·==++--·推送微信模板信息:{}·--++==·", Constants.equalsInteger(json.getInteger("errcode"),Constants.ZERO)?"成功":"失败"+json.getString("errmsg"));
                    }
                }
            }
        }catch (Exception e){
        }
    }
    /**
     * 月台签到通知
     * @param wxNoticeConfigMapper
     * @param platformJob
     * @param objCode
     * @param token
     * @param openIds
     */
    public void  sendPlatformJobSignNotice(WxNoticeConfigMapper wxNoticeConfigMapper, PlatformJob platformJob, String objCode,String token,
                                               List<String> openIds){
        try{
            if(CollectionUtils.isNotEmpty(openIds)){
                WxNoticeConfig wxNoticeConfig =  wxNoticeConfigMapper.selectOne(new QueryWrapper<WxNoticeConfig>().lambda().eq(WxNoticeConfig::getObjType,WxPlatConstants.platformJob)
                        .eq(WxNoticeConfig::getObjCode,objCode)
                        .eq(WxNoticeConfig::getStatus, Constants.ZERO)
                        .last(" limit 1")
                );
                if(Objects.isNull(wxNoticeConfig)){
                    return;
                }
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
                Map<String, Object> paramMap = new HashMap<String, Object>();
                //消息主题显示相关map
                Map<String, Object> dataMap = new HashMap<String, Object>();
                //车牌号
                Map<String, Object> car_number1 = new HashMap<String,Object>();
                car_number1.put("value",platformJob.getCarCodeFront());
                //司机姓名
                Map<String, Object> thing2 = new HashMap<String,Object>();
                thing2.put("value",platformJob.getDriverName());
                //签到时间
                Map<String, Object> time5 = new HashMap<String,Object>();
                time5.put("value", DateUtil.getFomartDate(platformJob.getSignDate(),"yyyy年MM月dd日 HH:mm:ss"));
                dataMap.put("car_number1",car_number1);
                dataMap.put("thing2",thing2);
                dataMap.put("time5",time5);
                for (String openId:openIds) {
                    paramMap.clear();
                    paramMap.put("template_id", wxNoticeConfig.getTempId());
                    paramMap.put("touser", openId);
                    paramMap.put("data", dataMap);
                    String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                    log.error("·==++--·推送微信模板信息内容:{}", JSONObject.toJSONString(paramMap));
                    if(StringUtils.isBlank(response)){
                        log.error("·==++--·推送微信模板信息:{}·--++==·", "失败");
                    }else{
                        JSONObject json = JSONObject.parseObject(response);
                        log.error("·==++--·推送微信模板信息:{}·--++==·", Constants.equalsInteger(json.getInteger("errcode"),Constants.ZERO)?"成功":"失败"+json.getString("errmsg"));
                    }
                }
            }
        }catch (Exception e){
        }
    }
    public void  sendUnFinishNotice(WxNoticeConfigMapper wxNoticeConfigMapper,Integer unFinishNum,String objCode,String token,
                                           List<String> openIds){
        try{
            if(CollectionUtils.isNotEmpty(openIds)){
                WxNoticeConfig wxNoticeConfig =  wxNoticeConfigMapper.selectOne(new QueryWrapper<WxNoticeConfig>().lambda().eq(WxNoticeConfig::getObjType,WxPlatConstants.platformJob)
                        .eq(WxNoticeConfig::getObjCode,objCode)
                        .eq(WxNoticeConfig::getStatus, Constants.ZERO)
                        .last(" limit 1")
                );
                if(Objects.isNull(wxNoticeConfig)){
                    return;
                }
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                //整体参数map
                Map<String, Object> paramMap = new HashMap<String, Object>();
                //消息主题显示相关map
                Map<String, Object> dataMap = new HashMap<String, Object>();
                //车牌号
                Map<String, Object> const1 = new HashMap<String,Object>();
                const1.put("value","作业任务未完成");
                //司机姓名
                Map<String, Object> thing2 = new HashMap<String,Object>();
                thing2.put("value",unFinishNum+"个");
                //签到时间
                Map<String, Object> time3 = new HashMap<String,Object>();
                time3.put("value", DateUtil.getFomartDate(new Date(),"yyyy年MM月dd日 HH:mm:ss"));
                dataMap.put("const1",const1);
                dataMap.put("thing2",thing2);
                dataMap.put("time3",time3);
                for (String openId:openIds) {
                    paramMap.clear();
                    paramMap.put("template_id", wxNoticeConfig.getTempId());
                    paramMap.put("touser", openId);
                    paramMap.put("data", dataMap);
                    String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                    log.error("·==++--·推送微信模板信息内容:{}", JSONObject.toJSONString(paramMap));
                    if(StringUtils.isBlank(response)){
                        log.error("·==++--·推送微信模板信息:{}·--++==·", "失败");
                    }else{
                        JSONObject json = JSONObject.parseObject(response);
                        log.error("·==++--·推送微信模板信息:{}·--++==·", Constants.equalsInteger(json.getInteger("errcode"),Constants.ZERO)?"成功":"失败"+json.getString("errmsg"));
                    }
                }
            }
        }catch (Exception e){
        }
    }
    public void  sendMeetTemplateNotice(SystemDictDataBiz systemDictDataBiz,SmsEmail smsEmail,String token){
        try{
                String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                        Constants.WxUrlParams.MEETING,smsEmail.getObjId().toString());
                String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
                JSONObject jsonObject = JSONObject.parseObject(smsEmail.getContent());
                jsonObject.put("url",jumpUrl);
                String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(jsonObject));
                log.warn("·==++--·推送微信模板信息内容:{}", JSONObject.toJSONString(jsonObject));
                if(StringUtils.isBlank(response)){
                    log.warn("·==++--·推送微信模板信息:{}·--++==·", "失败");
                }else{
                    JSONObject json = JSONObject.parseObject(response);
                    log.warn("·==++--·推送微信模板信息:{}·--++==·", Constants.equalsInteger(json.getInteger("errcode"),Constants.ZERO)?"成功":"失败"+json.getString("errmsg"));
                }
        }catch (Exception e){
        }
    }
}