| package com.matrix.system.wechart.templateMsg.Task.messageBulderDemo; | 
|   | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.matrix.core.tools.DateUtil; | 
| import com.matrix.core.tools.StringUtils; | 
| import com.matrix.system.hive.bean.SysBeauticianState; | 
| import com.matrix.system.hive.bean.SysProjServices; | 
| import com.matrix.system.hive.bean.SysShopInfo; | 
| import com.matrix.system.hive.bean.SysVipInfo; | 
| import com.matrix.system.hive.dao.SysBeauticianStateDao; | 
| import com.matrix.system.hive.dao.SysProjServicesDao; | 
| import com.matrix.system.hive.dao.SysShopInfoDao; | 
| import com.matrix.system.hive.dao.SysVipInfoDao; | 
| import com.matrix.system.wechart.templateMsg.GzhTemplateMessagePojo; | 
| import com.matrix.system.wechart.templateMsg.Task.TemplateMessageBulder; | 
| import com.matrix.system.wechart.templateMsg.UniformMsgPojo; | 
| import org.apache.commons.collections.CollectionUtils; | 
| import org.apache.commons.collections.map.HashedMap; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Component; | 
|   | 
| import java.util.*; | 
|   | 
| /** | 
|  * 预约到时提醒 | 
|  */ | 
| @Component | 
| public class YydsTemplateMessageBulder implements TemplateMessageBulder { | 
|   | 
|     @Autowired | 
|     SysProjServicesDao projServicesDao; | 
|   | 
|     @Autowired | 
|     SysVipInfoDao vipInfoDao; | 
|   | 
|     @Autowired | 
|     private SysBeauticianStateDao beauticianStateDao; | 
|   | 
|     @Autowired | 
|     private SysShopInfoDao shopInfoDao; | 
|   | 
|   | 
|   | 
|     @Override | 
|     public Map buildMsg(Map param) { | 
|   | 
|         //返回参数 | 
|         Map builParam=new HashedMap(); | 
|         //获取基础公共参数 | 
|         String gzhAppid= (String) param.get("gzhAppid"); | 
|         String template_id= (String) param.get("template_id"); | 
|         String xcxAppId= (String) param.get("xcxAppId"); | 
|         //模板消息列表 | 
|         List msgList=new ArrayList(); | 
|   | 
|         //触发点传送的json参数 | 
|         JSONObject messageJsonParam= (JSONObject) param.get("messageJsonParam"); | 
|         //构建消息主体 | 
|         Long serviceId= (Long) messageJsonParam.get("serviceId"); | 
|         SysProjServices sysProjServices = projServicesDao.selectById(serviceId); | 
|   | 
|   | 
|         //校验客户openId (必须) | 
|         SysVipInfo vipInfo=vipInfoDao.selectById(sysProjServices.getVipId()); | 
|         String touser= vipInfo.getOpenId(); | 
|         if(StringUtils.isBlank(touser)){ | 
|             builParam.put("error","未获取到"+vipInfo.getVipName()+"用户小程序openid"); | 
|             return builParam; | 
|         } | 
|   | 
|   | 
|         //自定义信息区START========================================================================================================= | 
|         SysShopInfo sysShopInfo = shopInfoDao.selectById(sysProjServices.getShopId()); | 
|         List<SysBeauticianState> beauticianStateList = beauticianStateDao.selectBySerIds(sysProjServices.getId()); | 
|         String time= DateUtil.dateFormatStr(sysProjServices.getConsumeTime(),DateUtil.DATE_FORMAT_MM); | 
|   | 
|         //如果一个项目存在多个护理项目则发送多次消息 | 
|         String projectInfo=""; | 
|         Set<String> staffNames=new HashSet<>(); | 
|         for (SysBeauticianState beauticianState:beauticianStateList){ | 
|             projectInfo+=beauticianState.getProjInfo().getName()+beauticianState.getCount()+"次,"; | 
|             staffNames.add(beauticianState.getBeautiStaffInfo().getSuName()); | 
|         } | 
|         projectInfo=projectInfo.substring(0,projectInfo.length()-1); | 
|         String staffName=StringUtils.collToStr(staffNames,","); | 
|         UniformMsgPojo uniformMsgPojo=new UniformMsgPojo(); | 
|         GzhTemplateMessagePojo messagePojo=new GzhTemplateMessagePojo(); | 
|         uniformMsgPojo.setTouser(touser); | 
|         messagePojo.setTemplate_id(template_id); | 
|         messagePojo.setAppid(gzhAppid); | 
|         //个性参数设置 | 
|         messagePojo.setFirst("您好!您在"+sysShopInfo.getShopName()+"店的预约将在1小时后开始,请准时到店。","#453454"); | 
|         messagePojo.setKeyWord(time,"#453454"); | 
|   | 
|         messagePojo.setKeyWord(sysShopInfo.getShopName(),"#453454"); | 
|         messagePojo.setKeyWord(sysShopInfo.getShopAddr(),"#453454"); | 
|         messagePojo.setKeyWord(projectInfo,"#453454"); | 
|         messagePojo.setKeyWord(staffName,"#453454"); | 
|   | 
|         messagePojo.setRemark("请记得准时前往,点击【详情】可查询服务详情。","#453454"); | 
|   | 
|         //小程序配置 | 
|         GzhTemplateMessagePojo.Miniprogram miniprogram=new GzhTemplateMessagePojo.Miniprogram(xcxAppId, | 
|                 "pages/yuyue/showYyInfo?id="+serviceId); | 
|         messagePojo.setMiniprogram(miniprogram); | 
|   | 
|   | 
|         uniformMsgPojo.setMp_template_msg(messagePojo); | 
|         //自定义信息区END========================================================================================================= | 
|   | 
|         //返回调用者使用的参数(必须) | 
|         msgList.add(uniformMsgPojo); | 
|         builParam.put("msgList",msgList); | 
|         return builParam; | 
|     } | 
| } |