njs 1 год назад
Родитель
Сommit
5d8b892955

+ 14 - 0
suishenbang-quartz/src/main/java/com/dgtly/quartz/task/RyTask.java

@@ -5,6 +5,7 @@ import com.dgtly.sync.service.AnalysisDiyCustomerComponent;
 import com.dgtly.sync.service.HanaOrderComponent;
 import com.dgtly.sync.service.RelationCustomerOnlineComponent;
 import com.dgtly.system.service.ISysUserOrderAuthorService;
+import com.dgtly.wxportal.service.IWxSendMessageService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -27,6 +28,8 @@ public class RyTask
     private RelationCustomerOnlineComponent relationCustomerOnlineComponent;
     @Autowired
     private ISysUserOrderAuthorService sysUserOrderAuthorService;
+    @Autowired
+    private IWxSendMessageService wxSendMessageService;
 
 //    private static RyTask ryTask;
 //    @PostConstruct
@@ -132,4 +135,15 @@ public class RyTask
     public void customersStart(){
         sysUserOrderAuthorService.customersStart();
     }
+
+    /**
+     * @description: 自提未提货企微消息通知提醒
+     * @param:
+     * @return:
+     * @author: njs
+     * @date: 2023/5/15 11:29
+     */
+    public void sendWxTmsMessage(){
+        wxSendMessageService.sendWxTmsMessage();
+    }
 }

+ 11 - 0
suishenbang-system/src/main/java/com/dgtly/system/mapper/SysBatchSignForMapper.java

@@ -3,6 +3,7 @@ package com.dgtly.system.mapper;
 
 import com.dgtly.system.domain.DeliverOrderBase;
 import com.dgtly.system.domain.TmsLogisticsStatus;
+import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -29,4 +30,14 @@ public interface SysBatchSignForMapper {
     List<TmsLogisticsStatus> selectByDelivery();
 
     void updateBatchTmsStatus(@Param("list") List<TmsLogisticsStatus> list);
+
+    /**
+     * @description: 查询45天内的自提单未去提货的
+     * @param: []
+     * @return: java.util.List<com.dgtly.system.domain.TmsLogisticsStatus>
+     * @author: njs
+     * @date: 2023/5/15 17:01
+     */
+    @MapKey("customerCode")
+    Map<String,Map<String,Object>>  selectDeliverySelf();
 }

+ 10 - 0
suishenbang-system/src/main/java/com/dgtly/system/mapper/SysUserMapper.java

@@ -193,6 +193,16 @@ public interface SysUserMapper
      */
     @MapKey("customer_code")
     Map<String,Map<String,Object>> selectLoginNamesByCostumerCode(String[] customerCodes);
+    /**
+     * @description: 自提专用根据经销编码查询销售员,老板,财务,仓管等登录名
+     * @param: [customerCodes]
+     * @return: java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>
+     * @author: njs     
+     * @date: 2023/5/15 14:30
+     */
+    @MapKey("customer_code")
+    Map<String,Map<String,Object>>  selectLoginNamesByOrgCodeSelf(String customerCode);
+    String selectLoginNameByCustomerCode(String customerId);
     @MapKey("customer_code")
     Map<String,Map<String,Object>> selectLoginNamesByCustomerModelVO(@Param("customerCode") String customerCode,@Param("customerType") String customerType);
 

+ 11 - 0
suishenbang-system/src/main/resources/mapper/system/SysBatchSignForMapper.xml

@@ -128,4 +128,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
       and is_delete=0 and  create_time between now() - interval 100 day and now()
     </select>
 
+    <select id="selectDeliverySelf" resultType="java.util.Map" parameterType="String">
+        select  customer_code customerCode,GROUP_CONCAT(delivery_number SEPARATOR ',') deliveryNumber
+        from tms_logistics_status
+        where 1=1
+          and is_delete=0
+          and arrival_goods_time IS NULL
+          AND self_pick_time BETWEEN DATE_SUB( NOW(), INTERVAL 45 DAY ) AND NOW()
+        group by customer_code
+    </select>
+
+
 </mapper>

+ 25 - 2
suishenbang-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -487,7 +487,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 
 	<select id="selectLoginNamesByCostumerCode" resultType="java.util.Map" parameterType="String">
-		select DISTINCT sue.org_code customer_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user  su
+		select  sue.org_code customer_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user  su
 		left join sys_user_ext sue on sue.user_id = su.user_id
 		where sue.org_code in
 		<foreach collection="array" item="customerCode" open="(" separator="," close=")">
@@ -497,6 +497,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		GROUP BY sue.org_code
 	</select>
 
+	<select id="selectLoginNamesByOrgCodeSelf" resultType="java.util.Map" parameterType="String">
+		select  sue.org_code customer_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user  su
+		left join sys_user_ext sue on sue.user_id = su.user_id
+		where 1=1
+		and sue.org_code =#{customerCode}
+		and sue.is_customer_manager in ('1','2','3')
+		and  sue.is_customer_manager != 0
+		GROUP BY sue.org_code
+	</select>
+
+	<select id="selectLoginNameByCustomerCode" resultType="java.lang.String">
+		SELECT
+			u.login_name
+		FROM
+			order_sales_sum_tuc_customer c
+				LEFT JOIN sys_user_ext e ON e.sap_employee_id = c.emp_id
+				LEFT JOIN sys_user u ON u.user_id = e.user_id
+		WHERE
+			c.customer_id =#{customerId}
+		GROUP BY
+			u.user_id limit 1
+	</select>
+
 	<select id="selectLoginNamesByCustomerModelVO" resultType="java.util.Map" parameterType="String">
 		select DISTINCT sue.org_code customer_code,GROUP_CONCAT(su.login_name SEPARATOR '|') touser from sys_user  su
 		left join sys_user_ext sue on sue.user_id = su.user_id
@@ -552,7 +575,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 
 	<select id="getCustomNameByCode" resultType="java.lang.String" >
-		select customer_name  from order_sales_customer where customer_id=#{code} limit 1
+		select customer_name  from order_sales_sum_tuc_customer where customer_id=#{code} limit 1
 	</select>
 
 	<select id="selectSyncDateUser" resultType="java.lang.String" >

+ 1 - 6
suishenbang-wxportal/suishenbang-wxportal-api/src/main/java/com/dgtly/wxportal/controller/WxController.java

@@ -532,18 +532,13 @@ public class WxController extends ApiBaseController {
         String chain = obj.getString("chain");
         String order = obj.getString("order");
         String temple = configService.selectConfigByKey("wx.notification.tms.self");
-
-
-        String templeDetail = configService.selectConfigByKey("wx.notification.order.detail");
-
-
         String orderFormat = null;
         String[] orderArrays = order.split(",");
         String customerName = sysUserService.getCustomNameByCode(chain);
         List<String> strList = new ArrayList<>();
         for (int i = 0; i < orderArrays.length; i++) {
             String orderStr = orderArrays[i];
-            String messageDetail = String.format(templeDetail, orderStr, customerName);
+            String messageDetail = String.format(temple, orderStr, customerName);
             strList.add(messageDetail);
         }
         orderFormat = strList.stream().collect(Collectors.joining(","));

+ 9 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/IWxSendMessageService.java

@@ -58,4 +58,13 @@ public interface IWxSendMessageService
      * @return 结果
      */
     public int deleteWxSendMessageById(Long id);
+
+    /**
+     * @description: 自提未提货企微消息通知
+     * @param:
+     * @return:
+     * @author: njs
+     * @date: 2023/5/15 11:27
+     */
+     void sendWxTmsMessage();
 }

+ 65 - 3
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/service/impl/WxSendMessageServiceImpl.java

@@ -1,7 +1,14 @@
 package com.dgtly.wxportal.service.impl;
 
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
 import com.dgtly.common.utils.DateUtils;
+import com.dgtly.system.mapper.SysBatchSignForMapper;
+import com.dgtly.system.mapper.SysUserMapper;
+import com.dgtly.system.service.ISysConfigService;
+import com.dgtly.wxportal.utils.qywxutils.QyWxSendMessageUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.dgtly.wxportal.mapper.WxSendMessageMapper;
@@ -16,11 +23,18 @@ import com.dgtly.common.core.text.Convert;
  * @date 2020-09-02
  */
 @Service
-public class WxSendMessageServiceImpl implements IWxSendMessageService 
+public class WxSendMessageServiceImpl implements IWxSendMessageService
 {
     @Autowired
     private WxSendMessageMapper wxSendMessageMapper;
-
+    @Autowired
+    private QyWxSendMessageUtil qyWxSendMessageUtil;
+    @Autowired
+    private SysUserMapper userMapper;
+    @Autowired
+    private ISysConfigService configService;
+    @Autowired
+    private SysBatchSignForMapper batchSignForMapper;
     /**
      * 查询企业微信发送消息历史记录
      * 
@@ -94,4 +108,52 @@ public class WxSendMessageServiceImpl implements IWxSendMessageService
     {
         return wxSendMessageMapper.deleteWxSendMessageById(id);
     }
+
+    /**
+     * @description: 自提未提货企微消息通知
+     * @param:
+     * @return:
+     * @author: njs
+     * @date: 2023/5/15 11:27
+     */
+    @Override
+    public  void sendWxTmsMessage() {
+        Map<String, Map<String, Object>> tmsMap =  batchSignForMapper.selectDeliverySelf();
+        if(tmsMap !=null && tmsMap.size()>0){
+            //自提提货通知
+            String temple = configService.selectConfigByKey("wx.notification.self.factory");
+            for (String customerId:tmsMap.keySet()
+                 ) {
+                String user =null;
+                String deliverNumber =null;
+                String orderFormat =null;
+                String customerName = userMapper.getCustomNameByCode(customerId);
+                Map<String, Map<String,Object>> maps = userMapper.selectLoginNamesByOrgCodeSelf(customerId);
+                Iterator<Map.Entry<String, Object>> iterator = tmsMap.get(customerId).entrySet().iterator();
+                while (iterator.hasNext()){
+                    Map.Entry<String, Object> next = iterator.next();
+                    if(next.getKey().equals("deliveryNumber")){
+                       if(deliverNumber !=null){
+                           deliverNumber = deliverNumber+","+next.getValue().toString();
+                       }else{
+                           deliverNumber=next.getValue().toString();
+                       }
+                    }
+                }
+                String empName=userMapper.selectLoginNameByCustomerCode(customerId);
+                if(empName !=null){
+                    user=maps.get(customerId).get("touser").toString()+"|"+empName;
+                }else{
+                    user=maps.get(customerId).get("touser").toString();
+                }
+                String CustomerName=customerName+"("+customerId+")";
+                String messageDetail = String.format(temple, CustomerName,deliverNumber);
+                //消息
+                if(user !=null){
+                    qyWxSendMessageUtil.sendMsgSelfToCustomer(user,messageDetail, "48");
+                }
+            }
+        }
+
+    }
 }

+ 30 - 1
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/qywxutils/QyWxSendMessageUtil.java

@@ -88,10 +88,10 @@ public class QyWxSendMessageUtil {
                     wm.setToUser(qyWxTextMessage.getTouser());
                     qyWxTextMessage.setText(msg);
                     wm.setSendText(qyWxTextMessage.getText().getContent());
+                    wm.setForm(form);
                     try{
                         sendMessage(qyWxTextMessage);
                         wm.setIsSuccess("1");
-                        wm.setForm(form);
                     }catch (Exception e){
                         log.error("对"+maps.get(code).get("touser")+"发送消息失败",e);
                     }finally {
@@ -371,4 +371,33 @@ public class QyWxSendMessageUtil {
 
     }
 
+
+    @Async
+    public void sendMsgSelfToCustomer(String user,String msg, String form){
+        List<WxSendMessage> wmList = new ArrayList<>();
+                    WxSendMessage wm= new WxSendMessage();
+                    QyWxTextMessage qyWxTextMessage = new QyWxTextMessage();
+                    qyWxTextMessage.setTouser(user);
+                    wm.setToUser(qyWxTextMessage.getTouser());
+                    qyWxTextMessage.setText(msg);
+                    wm.setSendText(qyWxTextMessage.getText().getContent());
+                    wm.setForm(form);
+                    try{
+                        sendMessage(qyWxTextMessage);
+                        wm.setIsSuccess("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);
+                        }
+                    }
+    }
+
 }