jyy
2021-01-26 ab2879bbcb846256cc182198b9c04e50fbc276c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
 
/**
 * 预约成功提醒
 */
@Component
public class YycgTemplateMessageBulder 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()+"店的预约已经成功,期待您的光临","#453454");
        messagePojo.setKeyWord(time,"#453454");
        messagePojo.setKeyWord(staffName,"#453454");
        messagePojo.setKeyWord(projectInfo,"#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;
    }
}