From 7ac435d93858f6658248c2d4ea763ce1cfd0f012 Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Sat, 16 Jan 2021 22:52:58 +0800
Subject: [PATCH] 消息提醒

---
 /dev/null                                                                                                        |   15 ---
 zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopWxtemplateMsgAction.java                               |   18 ----
 zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/UniformMsgSentTask.java                          |   12 +-
 zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java                          |    9 +-
 zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/UniformMsgParam.java                                  |   49 ++++++++++++
 zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/messageBulderDemo/FwwcTemplateMessageBulder.java |  109 +++++++++++++++++++++++++++
 zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/GzhTemplateMessagePojo.java                           |   20 ++--
 zq-erp/src/main/resources/config/application.properties                                                          |    2 
 8 files changed, 183 insertions(+), 51 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java
index d1aeb5f..e8a589d 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysProjServicesServiceImpl.java
@@ -19,6 +19,7 @@
 import com.matrix.system.hive.pojo.MyBeauticianCount;
 import com.matrix.system.hive.service.*;
 import com.matrix.system.shopXcx.mqTask.MQTaskRouting;
+import com.matrix.system.wechart.templateMsg.UniformMsgParam;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -578,10 +579,10 @@
             projServices.setConsumeTime(new Date());
             int result=sysProjServicesDao.update(projServices);
             //发送微信公众号提醒
-            JSONObject param=new JSONObject();
-            param.put("companyId",projServices.getCompanyId());
-            param.put("serviceId",projServices.getId());
-            rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,param.toJSONString());
+            UniformMsgParam uniformMsgParam=new UniformMsgParam(projServices.getCompanyId(),UniformMsgParam.GZH_FWWC);
+            uniformMsgParam.put("serviceId",projServices.getId());
+            rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,uniformMsgParam.toJSONString());
+
             return result;
         }
     }
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopWxtemplateMsgAction.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopWxtemplateMsgAction.java
index ec600ff..4252a42 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopWxtemplateMsgAction.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/action/ShopWxtemplateMsgAction.java
@@ -81,22 +81,8 @@
     @RequestMapping(value = "/modifyShopWxtemplateMsg")
     public @ResponseBody
     AjaxResult modifyShopWxtemplateMsg(ShopWxtemplateMsg newShopWxtemplateMsg) {
-        ShopWxtemplateMsg oldShopWxtemplateMsg = WebUtil.getSessionAttribute(BEV);
-        int i = 0;
-        Map<String, Object> modifyMap = null;
-        try {
-            if (!ModelUtils.isModified(oldShopWxtemplateMsg, newShopWxtemplateMsg)) {
-                i = MatrixConstance.DML_SUCCESSS;
-            }
-            modifyMap = ModelUtils.comparePojo2Map(oldShopWxtemplateMsg, newShopWxtemplateMsg);
-        } catch (Exception e) {
-            throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopWxtemplateMsg);
-        }
-        if (modifyMap.size() > 0) {
-            modifyMap.put("id", oldShopWxtemplateMsg.getId());
-            shopWxtemplateMsgDao.updateByMap(modifyMap);
-        }
-        i = MatrixConstance.DML_SUCCESSS;
+
+        int   i = shopWxtemplateMsgDao.updateByModel(newShopWxtemplateMsg);
         WebUtil.removeSessionAttribute(BEV);
         if (i > 0) {
             return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "微信模板消息");
diff --git a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/GzhTemplateMessagePojo.java b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/GzhTemplateMessagePojo.java
index d6c6517..627d64d 100644
--- a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/GzhTemplateMessagePojo.java
+++ b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/GzhTemplateMessagePojo.java
@@ -18,11 +18,19 @@
     private  Miniprogram miniprogram;
     public static class Miniprogram{
         private  String appid;
-        private  String pagepath;
+        private  String path;
 
-        public Miniprogram(String appid, String pagepath) {
+        public Miniprogram(String appid, String path) {
             this.appid = appid;
-            this.pagepath = pagepath;
+            this.path = path;
+        }
+
+        public String getPath() {
+            return path;
+        }
+
+        public void setPath(String path) {
+            this.path = path;
         }
 
         public String getAppid() {
@@ -33,13 +41,7 @@
             this.appid = appid;
         }
 
-        public String getPagepath() {
-            return pagepath;
-        }
 
-        public void setPagepath(String pagepath) {
-            this.pagepath = pagepath;
-        }
     }
     public Map<String ,Item> data=new HashedMap();
     public static class Item{
diff --git a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/UniformMsgSentTask.java b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/UniformMsgSentTask.java
index 7094fe9..3549c4a 100644
--- a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/UniformMsgSentTask.java
+++ b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/UniformMsgSentTask.java
@@ -21,10 +21,10 @@
 import com.matrix.system.shopXcx.bean.ShopWxtemplateMsg;
 import com.matrix.system.shopXcx.dao.ShopWxtemplateMsgDao;
 import com.matrix.system.wechart.templateMsg.GzhTemplateMessagePojo;
-import com.matrix.system.wechart.templateMsg.TemplateNameConstance;
 import com.matrix.system.wechart.templateMsg.UniformMsgPojo;
 import com.rabbitmq.client.DeliverCallback;
 import com.rabbitmq.client.Delivery;
+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;
@@ -62,29 +62,29 @@
             String messages = new String(message.getBody(), "UTF-8");
             JSONObject messageJsonParam=JSONObject.parseObject(messages);
 
-            if(!messageJsonParam.containsKey("companyId")){
-                LogUtil.error("小程序消息推送参数格式异常发送模板消息需要传JSONO字符串作为格式 例如:{\"companyId\":17} companyId 是必须属性");
+            if(!messageJsonParam.containsKey("companyId")||(!messageJsonParam.containsKey("templateCode"))){
+                LogUtil.error("小程序消息推送参数格式异常发送模板消息需要传JSONO字符串作为格式 例如:{\"companyId\":17,\"templateCode\":10000} companyId 、templateCode 是必须属性");
                 return;
             }
-
             Long companyId = Long.parseLong( messageJsonParam.get("companyId").toString());
+            Integer templateCode = Integer.parseInt( messageJsonParam.get("templateCode").toString());
 
             //获取公司微信配置参数
             BusParameterSettings xcxAppId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_APPID, companyId);
             BusParameterSettings xcxSecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_SECRET, companyId);
             BusParameterSettings gzhAppid = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.GZH_APPID, companyId);
             //获取消息模板
-            ShopWxtemplateMsg template = shopWxtemplateMsgDao.selectByCode(TemplateNameConstance.GZH_YYTX,companyId);
+            ShopWxtemplateMsg template = shopWxtemplateMsgDao.selectByCode(templateCode,companyId);
             //校验参数
             if(xcxAppId==null||xcxSecret==null||gzhAppid==null||template==null){
                 LogUtil.error("小程序消息推送配置缺失xcxAppId="+xcxAppId+";xcxSecret="+xcxSecret+";gzhAppid="+gzhAppid+";template="+template);
                 return;
             }
-
             //获取模板动态构建类
             TemplateMessageBulder templateMessageBulder = (TemplateMessageBulder) GlueFactory.getInstance().loadInstance(template.getTemplateClass());
             //为模板动态类装备必要的参数
             Map<String, Object> bulderParam = new HashedMap();
+            bulderParam.put("xcxAppId", xcxAppId.getParamValue());
             bulderParam.put("gzhAppid", gzhAppid.getParamValue());
             bulderParam.put("template_id", template.getUuid());
             bulderParam.put("messageJsonParam", messageJsonParam);
diff --git a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/messageBulderDemo/FwwcTemplateMessageBulder.java b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/messageBulderDemo/FwwcTemplateMessageBulder.java
new file mode 100644
index 0000000..86b2ddc
--- /dev/null
+++ b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/Task/messageBulderDemo/FwwcTemplateMessageBulder.java
@@ -0,0 +1,109 @@
+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.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 服务完成提醒
+ */
+@Component
+public class FwwcTemplateMessageBulder 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 first="您好!您预约的";
+        for (SysBeauticianState beauticianState:beauticianStateList){
+            first+=beauticianState.getProjInfo().getName()+beauticianState.getCount()+"次,";
+        }
+        first=first.substring(0,first.length())+"服务已完成";
+        UniformMsgPojo uniformMsgPojo=new UniformMsgPojo();
+        GzhTemplateMessagePojo messagePojo=new GzhTemplateMessagePojo();
+        uniformMsgPojo.setTouser(touser);
+        messagePojo.setTemplate_id(template_id);
+        messagePojo.setAppid(gzhAppid);
+        //个性参数设置
+        messagePojo.setFirst(first,"#453454");
+        messagePojo.setKeyWord(sysShopInfo.getShopName(),"#453454");
+        messagePojo.setKeyWord(time,"#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;
+    }
+}
diff --git a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/TemplateNameConstance.java b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/TemplateNameConstance.java
deleted file mode 100644
index d66a4f3..0000000
--- a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/TemplateNameConstance.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.matrix.system.wechart.templateMsg;
-
-/**
- * 模板code定义常量
- * @author  jyy
- */
-public interface TemplateNameConstance {
-
-      /**
-       * 公众号预约提醒
-       */
-      Integer GZH_YYTX=10000;
-
-
-}
diff --git a/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/UniformMsgParam.java b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/UniformMsgParam.java
new file mode 100644
index 0000000..1db4733
--- /dev/null
+++ b/zq-erp/src/main/java/com/matrix/system/wechart/templateMsg/UniformMsgParam.java
@@ -0,0 +1,49 @@
+package com.matrix.system.wechart.templateMsg;
+
+import com.alibaba.fastjson.JSONObject;
+
+/**
+ * 统一消息参数体
+ */
+public class UniformMsgParam extends JSONObject{
+
+    /**
+     * 公众号预约提醒
+     */
+    public static final Integer GZH_YYTX = 10000;
+    /**
+     * 购买成功通知
+     */
+    public static final Integer GZH_GMCG = 10001;
+    /**
+     * 预约变更通知
+     */
+    public static final Integer GZH_YYBG = 10002;
+    /**
+     * 预约到时提醒
+     */
+    public static final Integer GZH_YYDS = 10003;
+    /**
+     * 预约成功提醒
+     */
+    public static final Integer GZH_YYCG = 10004;
+    /**
+     * 充值成功通知
+     */
+    public static final Integer GZH_CZCG = 10005;
+    /**
+     * 服务完成通知
+     */
+    public static final Integer GZH_FWWC = 10006;
+    /**
+     * 订单取消通知
+     */
+    public static final  Integer GZH_DDQX = 10007;
+
+
+    public  UniformMsgParam(Long companyId, Integer templateCode){
+        super.put("companyId",companyId);
+        super.put("templateCode",templateCode);
+    }
+
+}
diff --git a/zq-erp/src/main/resources/config/application.properties b/zq-erp/src/main/resources/config/application.properties
index 0cc9ddf..c427966 100644
--- a/zq-erp/src/main/resources/config/application.properties
+++ b/zq-erp/src/main/resources/config/application.properties
@@ -1,4 +1,4 @@
-evn=dev
+evn=ffff
 server.port=8080
 
 

--
Gitblit v1.9.1