Browse Source

微信通知

duyj 3 years ago
parent
commit
57568e5611

+ 92 - 0
suishenbang-wxportal/suishenbang-wxportal-api/src/main/java/com/dgtly/wxportal/controller/WxController.java

@@ -154,6 +154,98 @@ public class WxController extends ApiBaseController {
         return AjaxResult.success();
     }
 
+    @ApiOperation(value = "加急审批通过",
+            notes = "" )
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "params" , paramType = "body")
+    })
+    @PostMapping("sendUrgentApproveMessage")
+    public Object sendApproveMessage() {
+
+        ParameterObject obj = getParameterObject();
+        obj.checkParameterNotNull("users,chain,order,time");
+        String users = obj.getString("users");
+        String chain = obj.getString("chain");
+        String order = obj.getString("order");
+        String time = obj.getString("time");
+        String temple = configService.selectConfigByKey("wx.notification.approve.one");
+        String message = String.format(temple, chain, order, time);
+        qyWxSendMessageUtil.sendApproveProcessMessage(users, message);
+        return AjaxResult.success();
+    }
+
+    @ApiOperation(value = "小吨位审批通过",
+            notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "params", paramType = "body")
+    })
+    @PostMapping("sendSmallTonApproveMessage")
+    public Object sendSmallTonApproveMessage() {
+
+        ParameterObject obj = getParameterObject();
+        obj.checkParameterNotNull("users,chain,order,time");
+        String users = obj.getString("users");
+        String chain = obj.getString("chain");
+        String order = obj.getString("order");
+        String time = obj.getString("time");
+        String temple = configService.selectConfigByKey("wx.notification.approve.two");
+        String message = String.format(temple, chain, order, time);
+        qyWxSendMessageUtil.sendApproveProcessMessage(users, message);
+        return AjaxResult.success();
+    }
+
+    @ApiOperation(value = "订单交货通知",
+            notes = "" )
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "params" , paramType = "body")
+    })
+    @PostMapping("sendOrderDeliverMessage")
+    public Object sendOrderDeliverMessage() {
+
+        ParameterObject obj = getParameterObject();
+        obj.checkParameterNotNull("chain,order");
+        String chain = obj.getString("chain");
+        String order = obj.getString("order");
+        String temple = configService.selectConfigByKey("wx.notification.order.complete");
+        String message = String.format(temple, order);
+
+        Set<String> customerCodes = new HashSet<>();
+        customerCodes.add(chain);
+        logger.info("收到需要通知的经销商组织代码:"+chain);
+        Map<String,Map<String,Object>> maps = sysUserService.selectLoginNamesByCostumerCode(customerCodes);
+        //消息
+        if(customerCodes.size()>0){
+            qyWxSendMessageUtil.sendDeliveryMessage(customerCodes,maps,message);
+        }
+        return AjaxResult.success();
+    }
+
+    @ApiOperation(value = "TMS运单出厂通知",
+            notes = "" )
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "params" , paramType = "body")
+    })
+    @PostMapping("sendApproveTMSMessage")
+    public Object sendApproveTMSMessage() {
+
+        ParameterObject obj = getParameterObject();
+        obj.checkParameterNotNull("chain,order");
+        String chain = obj.getString("chain");
+        String order = obj.getString("order");
+        String temple = configService.selectConfigByKey("wx.notification.tms.leave.factory");
+        String message = String.format(temple, order);
+
+        Set<String> customerCodes = new HashSet<>();
+        customerCodes.add(chain);
+        logger.info("收到需要通知的经销商组织代码:"+chain);
+        Map<String,Map<String,Object>> maps = sysUserService.selectLoginNamesByCostumerCode(customerCodes);
+        //消息
+        if(customerCodes.size()>0){
+            qyWxSendMessageUtil.sendDeliveryMessage(customerCodes,maps,message);
+        }
+        return AjaxResult.success();
+    }
+
 
 //    @ApiOperation(value = "根据用户经销商组织代码 customer_code发送文本",
 //            notes = "参数:{\"XXX\":\"123,456\"}(说明:key是经销商code 值是订单编号列表)" )

+ 37 - 10
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/qywxutils/QyWxSendMessageUtil.java

@@ -2,6 +2,7 @@ package com.dgtly.wxportal.utils.qywxutils;
 
 
 import com.alibaba.fastjson.JSONObject;
+import com.dgtly.common.utils.StringUtils;
 import com.dgtly.common.utils.http.HttpUtils;
 import com.dgtly.system.service.ISysUserService;
 import com.dgtly.system.service.impl.SysConfigServiceImpl;
@@ -21,10 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * 企业微信发送信息工具类
@@ -44,9 +42,38 @@ public class QyWxSendMessageUtil {
     @Autowired
     private WxSendMessageMapper wxSendMessageMapper;
 
+    @Async
+    public void sendApproveProcessMessage(String users, String msg){
+        List<WxSendMessage> wmList = new ArrayList<>();
+        if (StringUtils.isNotEmpty(users)) {
+            Set<String> userList = new HashSet<>(Arrays.asList(users.split(",")));
+            for (String user : userList) {
+                WxSendMessage wm = new WxSendMessage();
+                QyWxTextMessage qyWxTextMessage = new QyWxTextMessage();
+                qyWxTextMessage.setTouser(user);
+                wm.setToUser(qyWxTextMessage.getTouser());
+                qyWxTextMessage.setText(msg);
+                wm.setSendText(qyWxTextMessage.getText().getContent());
+                try {
+                    sendMessage(qyWxTextMessage);
+                    wm.setIsSuccess("1");
+                    wm.setForm("1");
+                } catch (Exception e) {
+                    log.error("对" + user + "发送消息失败", e);
+                } finally {
+                    wmList.add(wm);
+                }
+            }
+        }
+        if (wmList.size() > 0) {
+            try {
+                wxSendMessageMapper.bathInsertWxSendMessage(wmList);
+            } catch (Exception e) {
 
-
-
+                log.error("发送微信信息时插入记录出错!!", e);
+            }
+        }
+    }
 
     @Async
     public void sendDeliveryMessage(Set<String> customerCodes,Map<String,Map<String,Object>> maps,String msg){
@@ -74,12 +101,12 @@ public class QyWxSendMessageUtil {
                 }
             }
         }
-        if(wmList.size()>0){
-            try{
+        if (wmList.size() > 0) {
+            try {
                 wxSendMessageMapper.bathInsertWxSendMessage(wmList);
-            }catch (Exception e){
+            } catch (Exception e) {
 
-                log.error("发送微信信息时插入记录出错!!",e);
+                log.error("发送微信信息时插入记录出错!!", e);
             }
         }
     }