Ver código fonte

企微发消息,信用有关的sendCreditMessage

njs 2 anos atrás
pai
commit
ff2221188b

+ 52 - 9
suishenbang-api/src/test/java/test/MyTest.java

@@ -3,7 +3,6 @@ package test;
 
 import com.dgtly.ApiApplication;
 import com.dgtly.system.domain.SysUser;
-import com.dgtly.system.mapper.SysUserMapper;
 import com.dgtly.system.service.ISysUserService;
 import com.dgtly.system.service.impl.SysUserServiceImpl;
 import com.dgtly.wxportal.config.ESignConfig;
@@ -18,12 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import java.io.*;
-import java.net.URL;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest(classes=ApiApplication.class)
@@ -47,11 +41,60 @@ public class MyTest {
     private SysUserServiceImpl sysUserService;
     @Test
     public void test() throws Exception {
-        Set<String> s = new LinkedHashSet<>();
+      /*  Set<String> s = new LinkedHashSet<>();
         s.add("0110065150");
         s.add("0110017419");
         Map<String,Map<String,Object>> map =  sysUserService.selectLoginNamesByCostumerCode(s);
-        System.out.println("1111111111");
+        System.out.println("1111111111");*/
+        Map<String,Map<String,Object>> map=new HashMap<>();
+        Map map1 = new HashMap();
+
+        map1.put("one", "一");
+
+        map1.put("two", "二");
+
+        map1.put("three", "三");
+
+        Map map2 = new HashMap();
+
+        map2.put("ten", "十");
+
+        map2.put("nine", "九");
+
+        map2.put("eight", "八");
+        map.putAll(map1);
+        for (Map.Entry entry : map.entrySet()) {
+
+            System.out.println("11111"+entry.getKey() + ":" + entry.getValue());
+
+        }
+        map.putAll(map2);
+        for (Map.Entry entry : map.entrySet()) {
+
+            System.out.println("22222"+entry.getKey() + ":" + entry.getValue());
+
+        }
+        Set<SysUser> orgCodeSet =new HashSet<>();
+        SysUser u=new SysUser();
+        u.setUserId(1L);
+        u.setIsSync("0");
+        u.setLoginName("张三");
+        orgCodeSet.add(u);
+        SysUser u2=new SysUser();
+        u2.setUserId(2L);
+        u2.setIsSync("1");
+        u2.setLoginName("李四");
+        orgCodeSet.add(u2);
+        Set<String> customerId=new HashSet<>();
+        //需要发送的组织凑的
+        for (SysUser user:orgCodeSet
+             ) {
+            customerId.add(user.getLoginName());
+        }
+
+
+        System.out.println("3333"+customerId);
+
 
         //创建文件
         /*SysUser user = new SysUser();

+ 76 - 0
suishenbang-system/src/main/java/com/dgtly/system/domain/CustomerModelVO.java

@@ -0,0 +1,76 @@
+package com.dgtly.system.domain;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+
+/**
+ * 经销商id,type对象
+ *
+ * @author njs
+ * @date 2022-08-30
+ */
+@Data
+public class CustomerModelVO implements Serializable {
+
+    private String customerId;
+    private String customerType;
+
+   /* public CustomerModelVO(String obInfo) {
+        String[] values=obInfo.split("-");
+        this.customerId=values[0];
+        this.customerType=values[1];
+    }
+
+    @Override
+    @JsonValue
+    public String toString(){
+        return this.customerId + "-" + this.customerType;
+    }
+
+    @Override
+    public int hashCode() {
+        int hashCode = (customerId + "-" + customerType).hashCode();
+        return hashCode;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        final CustomerModelVO entityDto = (CustomerModelVO) obj;
+        if (this == entityDto) {
+            return true;
+        } else {
+            if (customerId==null && customerType==null) {
+                if (customerId == entityDto.getCustomerId() && customerType == entityDto.getCustomerType()) {
+                    return true;
+                }
+            }
+            if (customerId==null && customerType!=null){
+                if (customerId== entityDto.getCustomerId() && customerType.equals(entityDto.getCustomerType())){
+                    return true;
+                }
+            }
+            if (customerId!=null && customerType==null){
+                if (customerId.equals(entityDto.getCustomerId()) && customerType == entityDto.getCustomerType()){
+                    return true;
+                }
+            }
+            if (customerId!=null&&customerType!=null){
+                if (customerId.equals(entityDto.getCustomerId())&&customerType.equals(entityDto.getCustomerType())){
+                    return true;
+                }
+            }
+            return false;
+        }
+    }*/
+}
+
+
+

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

@@ -182,6 +182,8 @@ public interface SysUserMapper
      */
     @MapKey("customer_code")
     Map<String,Map<String,Object>> selectLoginNamesByCostumerCode(String[] customerCodes);
+    @MapKey("customer_code")
+    Map<String,Map<String,Object>> selectLoginNamesByCustomerModelVO(@Param("customerCode") String customerCode,@Param("customerType") String customerType);
 
     /**
      * 根据销售组织代码 获取所属的用户登陆名称

+ 5 - 0
suishenbang-system/src/main/java/com/dgtly/system/service/ISysUserService.java

@@ -1,12 +1,15 @@
 package com.dgtly.system.service;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import com.dgtly.common.exception.BusinessException;
+import com.dgtly.system.domain.CustomerModelVO;
 import com.dgtly.system.domain.SysUser;
 
+
 /**
  * 用户 业务层
  * 
@@ -240,6 +243,8 @@ public interface ISysUserService
      */
     Map<String,Map<String,Object>> selectLoginNamesByCostumerCode(Set<String> customerCodes);
 
+    Map<String,Map<String,Object>> selectLoginNamesByCostumerVoCode(Collection<CustomerModelVO> customerCodes);
+
     /**
      * 根据销售的 员工号获取登陆敏成set
      * @param employeeSet

+ 15 - 4
suishenbang-system/src/main/java/com/dgtly/system/service/impl/SysUserServiceImpl.java

@@ -1,9 +1,6 @@
 package com.dgtly.system.service.impl;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import com.dgtly.system.domain.*;
 import com.dgtly.system.mapper.*;
@@ -605,6 +602,20 @@ public class SysUserServiceImpl implements ISysUserService
         String[] a = new String[customerCodes.size()];
         a = customerCodes.toArray(a);
         return userMapper.selectLoginNamesByCostumerCode(a);
+
+    }
+
+    @Override
+    public Map<String, Map<String, Object>> selectLoginNamesByCostumerVoCode(Collection<CustomerModelVO> customerCodes) {
+        Map<String,Map<String,Object>> map=new HashMap<>();
+        Iterator<CustomerModelVO> it = customerCodes.iterator();
+        while (it.hasNext()) {
+            CustomerModelVO entry = it.next();
+            Map<String,Map<String,Object>> customermap=new HashMap<>();
+            customermap=userMapper.selectLoginNamesByCustomerModelVO(entry.getCustomerId(),entry.getCustomerType());
+            map.putAll(customermap);
+        }
+        return map;
     }
 
     @Override

+ 1 - 1
suishenbang-system/src/main/resources/mapper/system/AssRelcustomerinfoMapper.xml

@@ -251,7 +251,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if> LIMIT 1
     </select>
     <select id="selectCustomerNameAndCode" resultMap="AssRelcustomerinfoResult">
-        select  mainkunnr as mainkunnr,mainmainname1name1 as  FROM `ass_relcustomerinfo`
+        select  mainkunnr as mainkunnr,mainname1 as  mainname1 FROM `ass_relcustomerinfo`
         UNION select  kunnr as mainkunnr,name1 as mainname1 FROM `ass_relcustomerinfo`
     </select>
 </mapper>

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

@@ -417,7 +417,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 
 
-	<select id="selectLoginNamesByCostumerCode" resultType="Map" parameterType="String">
+	<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
 		left join sys_user_ext sue on sue.user_id = su.user_id
 		where sue.org_code in
@@ -427,7 +427,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		and sue.is_customer_manager != 0
 		GROUP BY sue.org_code
 	</select>
-	<select id="selectLoginNamesByCostumerCode1" resultType="Map" parameterType="String">
+
+	<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
+		where 1=1
+		<if test="customerCode !=null and customerCode !='' ">
+			and sue.org_code =#{customerCode}
+		</if>
+		<if test="customerType !=null and customerType !='' and customerType =='D9' ">
+			and sue.identity in ('1')
+		</if>
+		<if test="customerType !=null and customerType !='' and customerType =='Y9' ">
+			and sue.identity in ('2')
+		</if>
+		and sue.is_customer_manager != 0
+		GROUP BY sue.org_code
+	</select>
+
+	<select id="selectLoginNamesByCostumerCode1" 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
 		where sue.org_code in

+ 2 - 1
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/domain/SendOrderNoticeTaskModelCredit.java

@@ -1,5 +1,6 @@
 package com.dgtly.wxportal.domain;
 
+import com.dgtly.system.domain.CustomerModelVO;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -16,7 +17,7 @@ public class SendOrderNoticeTaskModelCredit implements Serializable {
     /**
      * 经销商-订单个数
      */
-    private Map<String,Integer> customerMap = new HashMap<>();
+    private Map<String,CustomerModelVO> customerMap = new HashMap<>();
 
     /**
      * 销售员-经销商

+ 9 - 8
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/qywxutils/QyWxSendMessageUtil.java

@@ -4,6 +4,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.domain.CustomerModelVO;
 import com.dgtly.system.service.ISysUserService;
 import com.dgtly.system.service.impl.SysConfigServiceImpl;
 import com.dgtly.wxportal.domain.SendOrderNoticeTaskModel;
@@ -170,26 +171,27 @@ public class QyWxSendMessageUtil {
         if(credit.getCustomerMap()!=null&&credit.getCustomerMap().size()>0){
             try{
                 //需要发送的组织codeset列表
-                Set<String> orgCodeSet = credit.getCustomerMap().keySet();
+                Collection<CustomerModelVO> orgCodeSet = credit.getCustomerMap().values();
+                Set<String> customerId=new HashSet<>();
                 //需要发送的组织凑的
-
-                Map<String,Map<String,Object>> orgCodeTouser = sysUserService.selectLoginNamesByCostumerCode(orgCodeSet);
+                for (CustomerModelVO customerModelVO:orgCodeSet
+                     ) {
+                    customerId.add(customerModelVO.getCustomerId());
+                }
+                Map<String,Map<String,Object>> orgCodeTouser = sysUserService.selectLoginNamesByCostumerVoCode(orgCodeSet);
                 String conKey = "";
                 String form="";
                 if(type==0){
-                    log.info("发送经销商过信用");
                     conKey ="wx.notification.credit.customer";
                     form="3";
                 }else {
-                    log.info("发送经销商未过信用");
                     conKey ="wx.notification.nocredit.customer";
                     form="7";
                 }
                 String temple =configService.selectConfigByKey(conKey);
                 BatchSendGetToUser<String> getToUser = new CreditGetToUser<>(orgCodeTouser);
                 BatchSendGetSendMessage getText = new CreditGetSendMessageCus(temple,credit.getCustomerMap());
-
-                BatchSendQyWxMessage batchSendQyWxMessage = new BatchSendCustomerCreditMessage<String,Map<String,Object>>(orgCodeSet,getToUser,getText);
+                BatchSendQyWxMessage batchSendQyWxMessage = new BatchSendCustomerCreditMessage<String,Map<String,Object>>(customerId,getToUser,getText);
                 List<QyWxBaseMessage> messageList = batchSendQyWxMessage.getMessageList();
                 int success =  batchSendMessage(messageList,form);
                 log.info("批量发送信息,成功:"+success+"条,总共:"+messageList.size());
@@ -360,7 +362,6 @@ public class QyWxSendMessageUtil {
         String url = QyWxServiceUrl.SEND_MESSAGE_URL.getformatUrl(qyWxAccessTokenUtil.getAccessToken());
         String result =  HttpUtils.sendJsonPost(url,message);
         JSONObject json = JSONObject.parseObject(result);
-
         Integer errcode = json.getInteger("errcode");
         if(errcode!=0){
             throw new QyWeixinException(errcode,url);