|  |  |  | 
|---|
|  |  |  | package com.doumee.core.wx.wxPlat; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.dao.business.WxNoticeConfigMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Visits; | 
|---|
|  |  |  | import com.doumee.dao.business.model.WxNoticeConfig; | 
|---|
|  |  |  | 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.WxMpTemplateMessage; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 微信公众号通知 | 
|---|
|  |  |  | 
|---|
|  |  |  | this.wxMpService = wxMpService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 访客记录审批业务通知 | 
|---|
|  |  |  | * 访客业务通知接口 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Boolean  sendVisitAuditTemplateNotice(Visits visits,String prefix,String tempId){ | 
|---|
|  |  |  | if(StringUtils.isBlank(visits.getOpenid())){ | 
|---|
|  |  |  | 
|---|
|  |  |  | .templateId(tempId) | 
|---|
|  |  |  | .url(prefix + visits.getId()) | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String thing1 = "待审批"; | 
|---|
|  |  |  | if(visits.getStatus()==2){ | 
|---|
|  |  |  | thing1 = "审核通过"; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 访客业务通知 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void  sendVisitTemplateNotice(WxNoticeConfigMapper wxNoticeConfigMapper,Visits visits,String objCode, String prefix, String tempId, List<String> openIds){ | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(openIds)){ | 
|---|
|  |  |  | WxNoticeConfig wxNoticeConfig =  wxNoticeConfigMapper.selectOne(new QueryWrapper<WxNoticeConfig>().lambda().eq(WxNoticeConfig::getObjType,WxPlatConstants.visit) | 
|---|
|  |  |  | .eq(WxNoticeConfig::getObjCode,objCode) | 
|---|
|  |  |  | .eq(WxNoticeConfig::getStatus, Constants.ZERO) | 
|---|
|  |  |  | .last(" limit 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.isNull(wxNoticeConfig)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WxMpTemplateMessage templateMessage =  WxMpTemplateMessage.builder() | 
|---|
|  |  |  | .toUser(visits.getOpenid()) | 
|---|
|  |  |  | .templateId(tempId) | 
|---|
|  |  |  | .url(prefix + visits.getId()) | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | templateMessage.addData(new WxMpTemplateData("thing1", visits.getName())) | 
|---|
|  |  |  | .addData(new WxMpTemplateData("car_number7", StringUtils.isBlank(visits.getCarNos())?visits.getCarNos():"-")) | 
|---|
|  |  |  | .addData(new WxMpTemplateData("character_string6", Constants.equalsInteger(visits.getMemberNum(),Constants.ZERO)?Constants.ONE+"":visits.getMemberNum().toString())) | 
|---|
|  |  |  | .addData(new WxMpTemplateData("const9", wxNoticeConfig.getTitile())) | 
|---|
|  |  |  | .addData(new WxMpTemplateData("thing4", visits.getReason())) | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | String msgId = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | for (String openId:openIds) { | 
|---|
|  |  |  | templateMessage.setToUser(openId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 发送模板消息 | 
|---|
|  |  |  | msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage); | 
|---|
|  |  |  | } catch (WxErrorException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.warn("·==++--·推送微信模板信息:{}·--++==·", msgId != null ? "成功" : "失败"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|