jyy
2021-01-09 30f2f276ca35cae2bde763c58719f05c572f415b
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
package com.matrix.system.wechart.templateMsg.Task.messageBulderDemo;
 
import com.alibaba.fastjson.JSONObject;
import com.matrix.biz.bean.BizUser;
import com.matrix.biz.dao.BizUserDao;
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.SysVipInfo;
import com.matrix.system.hive.dao.SysBeauticianStateDao;
import com.matrix.system.hive.dao.SysProjServicesDao;
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 io.swagger.models.auth.In;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * 某个公司客户的定制消息模板
 */
@Component
public class DefaultTemplateMessageBulder implements TemplateMessageBulder {
 
    @Autowired
    SysProjServicesDao projServicesDao;
 
    @Autowired
    SysVipInfoDao vipInfoDao;
 
    @Autowired
    private SysBeauticianStateDao beauticianStateDao;
 
 
 
    @Override
    public Map buildMsg(Map param) {
 
        //返回参数
        Map builParam=new HashedMap();
 
 
        //获取基础公共参数
        String gzhAppid= (String) param.get("gzhAppid");
        String template_id= (String) param.get("template_id");
        //触发点传送的json参数
        JSONObject messageJsonParam= (JSONObject) param.get("messageJsonParam");
 
        Long serviceId= (Long) messageJsonParam.get("serviceId");
 
 
        //构建消息主体
        SysProjServices sysProjServices = projServicesDao.selectById(serviceId);
 
 
        //补充服务单扩展信息===============
        List<SysBeauticianState> beauticianStateList = beauticianStateDao.selectBySerIds(sysProjServices.getId());
 
        SysVipInfo vipInfo=vipInfoDao.selectById(sysProjServices.getVipId());
        String touser= vipInfo.getOpenId();
        if(StringUtils.isBlank(touser)){
            builParam.put("error","未获取到"+vipInfo.getVipName()+"用户小程序openid");
            return builParam;
        }
 
        String time= DateUtil.dateFormatStr(sysProjServices.getConsumeTime(),DateUtil.DATE_FORMAT_MM);
        List msgList=new ArrayList();
        //如果一个项目存在多个护理项目则发送多次消息
        for (SysBeauticianState beauticianState:beauticianStateList){
            UniformMsgPojo uniformMsgPojo=new UniformMsgPojo();
            GzhTemplateMessagePojo messagePojo=new GzhTemplateMessagePojo();
            uniformMsgPojo.setTouser(touser);
            messagePojo.setTemplate_id(template_id);
            messagePojo.setAppid(gzhAppid);
 
 
            //个性参数设置
            Integer suplerTimes= beauticianState.getProjUse().getSurplusCount();
            messagePojo.setFirst("尊敬的:"+vipInfo.getVipName(),"#453454");
            messagePojo.setKeyWord(beauticianState.getProjInfo().getName(),"#453454");
            messagePojo.setKeyWord(time,"#453454");
            messagePojo.setRemark("您的护理项目剩余"+suplerTimes+"次。","#453454");
            uniformMsgPojo.setMp_template_msg(messagePojo);
 
 
            msgList.add(uniformMsgPojo);
        }
 
        builParam.put("msgList",msgList);
        return builParam;
    }
}