姜永辉 1 жил өмнө
parent
commit
c628124042

+ 10 - 1
src/main/java/com/dk/mdm/feign/UserFeign.java

@@ -4,6 +4,7 @@ package com.dk.mdm.feign;
 import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.common.response.ResponseResultVO;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestBody;
 
 
@@ -14,7 +15,7 @@ import java.util.Map;
  * @desc : OauthServerFeign
  * @desc : OauthServerFeign
  * @date : 2024-038-10 10:56
  * @date : 2024-038-10 10:56
  */
  */
-@FeignClient(name = Constant.OAUTH_PREFIX + Constant.SERVER  , path = "/oauth/wx", contextId = "user")
+@FeignClient(name = Constant.OAUTH_PREFIX + Constant.SERVER  + "-jyh" , path = "/oauth/wx", contextId = "user")
 public interface UserFeign {
 public interface UserFeign {
     /**
     /**
      * @desc   : 注册-创建员工的时候保存微信用户信息
      * @desc   : 注册-创建员工的时候保存微信用户信息
@@ -33,4 +34,12 @@ public interface UserFeign {
     @PostMapping({"/update_clear_openid_feign"})
     @PostMapping({"/update_clear_openid_feign"})
     ResponseResultVO<Integer> updateClearOpenidFeign(@RequestBody Map<String, Object> collectQuery) ;
     ResponseResultVO<Integer> updateClearOpenidFeign(@RequestBody Map<String, Object> collectQuery) ;
 
 
+    /**
+     * @desc   : 查询微信登录用户信息
+     * @author : 姜永辉
+     * @date   : 2023-11-02 16:27
+     */
+    @PostMapping({"/get_user/{userId}"})
+    ResponseResultVO<?> getUser(@PathVariable String userId) ;
+
 }
 }

+ 35 - 0
src/main/java/com/dk/mdm/infrastructure/config/Config.java

@@ -91,4 +91,39 @@ public class Config {
      */
      */
     @Value("${wx.del_corp_tag}")
     @Value("${wx.del_corp_tag}")
     private String delCorpTag;
     private String delCorpTag;
+    /**
+     * @desc   : 公众号发送消息的api
+     * @author : 姜永辉
+     * @date   : 2024/07/12 9:03
+     */
+    @Value("${wx.uniform_send}")
+    private String uniformSend;
+    /**
+     * @desc   : 公众号发送消息的api
+     * @author : 姜永辉
+     * @date   : 2024/07/12 9:03
+     */
+    @Value("${wx.token}")
+    private String wechatUrlToken;
+    /**
+     * @desc   : 公众号appid
+     * @author : 姜永辉
+     * @date   : 2024/07/12 9:03
+     */
+    @Value("${wx.wxPublicAccountAppId}")
+    private String wxPublicAccountAppId;
+    /**
+     * @desc   : 公众号Secret
+     * @author : 姜永辉
+     * @date   : 2024/07/12 9:03
+     */
+    @Value("${wx.wxPublicAccountAppSecret}")
+    private String wxPublicAccountAppSecret;
+    /**
+     * @desc   : templateId
+     * @author : 姜永辉
+     * @date   : 2022/09/08 11:30
+     */
+    @Value("${wx.templateId}")
+    private String templateId;
 }
 }

+ 122 - 30
src/main/java/com/dk/mdm/service/mst/CusFollowService.java

@@ -1,5 +1,6 @@
 package com.dk.mdm.service.mst;
 package com.dk.mdm.service.mst;
 
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.dk.common.exception.BaseBusinessException;
 import com.dk.common.exception.BaseBusinessException;
 import com.dk.common.infrastructure.annotaiton.Pagination;
 import com.dk.common.infrastructure.annotaiton.Pagination;
@@ -11,6 +12,9 @@ import com.dk.common.model.vo.core.StaffEntity;
 import com.dk.common.response.ResponseCodeEnum;
 import com.dk.common.response.ResponseCodeEnum;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.common.response.ResponseResultVO;
+import com.dk.common.util.HttpUtils;
+import com.dk.mdm.feign.UserFeign;
+import com.dk.mdm.infrastructure.config.Config;
 import com.dk.mdm.infrastructure.convert.mst.CusFollowConvert;
 import com.dk.mdm.infrastructure.convert.mst.CusFollowConvert;
 import com.dk.mdm.infrastructure.convert.mst.MeasureReceiptConvert;
 import com.dk.mdm.infrastructure.convert.mst.MeasureReceiptConvert;
 import com.dk.mdm.infrastructure.util.AuthUtils;
 import com.dk.mdm.infrastructure.util.AuthUtils;
@@ -29,15 +33,18 @@ import com.dk.mdm.service.common.CommonService;
 import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
+import javax.annotation.Resource;
 import java.time.LocalDate;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.*;
+import java.util.stream.IntStream;
 
 
 @Slf4j
 @Slf4j
 @Service
 @Service
@@ -89,6 +96,12 @@ public class CusFollowService extends BaseService<CusFollow> {
     private XxlJobUtils xxlJobUtils;
     private XxlJobUtils xxlJobUtils;
 
 
     @Autowired
     @Autowired
+    private Config config;
+
+    @Resource
+    private UserFeign userFeign;
+
+    @Autowired
     private MeasureReceiptConvert measureReceiptConvert;
     private MeasureReceiptConvert measureReceiptConvert;
 
 
     /**
     /**
@@ -399,42 +412,46 @@ public class CusFollowService extends BaseService<CusFollow> {
         if (followStaff != null) {
         if (followStaff != null) {
             log.info("sendFollowMessage:{}", JSONObject.toJSONString(followStaff));
             log.info("sendFollowMessage:{}", JSONObject.toJSONString(followStaff));
             Customer customer = customerMapper.selectById(new CustomerQuery().setCusId(follow.getCusId()));
             Customer customer = customerMapper.selectById(new CustomerQuery().setCusId(follow.getCusId()));
-
             if (customer != null) {
             if (customer != null) {
-                //设计师
-                StaffResponse designUser = null;
-                if (follow.getDesignStaff() != null) {
-                    designUser = staffMapper.selectById(follow.getDesignStaff());
-                }
-
-                // 添加跟进ID
-                JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(customer));
-                jsonObject.put("followId", follow.getFollowId());
-
-
                 String loginType = null;
                 String loginType = null;
-                JSONObject list = null;
-                //跟进followId先查询跟进数据
-                CusFollow e = cusFollowMapper.selectById(follow.getFollowId());
-                if (e != null) {
-                    if (Constant.BasicDataConstant.FOLLOW_STATUS_4.getValue().equals(e.getFollowStatus()) ||
-                            Constant.BasicDataConstant.FOLLOW_STATUS_5.getValue().equals(e.getFollowStatus())) {
-
-                        JSONObject followJs = JSONObject.parseObject(JSONObject.toJSONString(e));
-                        followJs.put("customerName", jsonObject.get("customerName"));
-                        followJs.put("customerPhone", jsonObject.get("customerPhone"));
-                        followJs.put("addressFull", jsonObject.get("addressFull"));
+                List<String> list = new ArrayList<>();
+                if (Constant.BasicDataConstant.FOLLOW_STATUS_4.getValue().equals(follow.getFollowStatus()) ||
+                        Constant.BasicDataConstant.FOLLOW_STATUS_5.getValue().equals(follow.getFollowStatus())) {
+                    list.add("您有客户需要跟进");
+                    loginType = "8";
 
 
-                        list = followJs;
-                        loginType = "8";
+                } else if (Constant.BasicDataConstant.FOLLOW_STATUS_6.getValue().equals(follow.getFollowStatus())) {
+                    list.add("您有客户需要量尺服务");
+                    loginType = "1";
 
 
-                    } else if (Constant.BasicDataConstant.FOLLOW_STATUS_1.getValue().equals(e.getFollowStatus()) ||
-                            Constant.BasicDataConstant.FOLLOW_STATUS_2.getValue().equals(e.getFollowStatus()) ||
-                            Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(e.getFollowStatus())) {
+                } else if (Constant.BasicDataConstant.FOLLOW_STATUS_2.getValue().equals(follow.getFollowStatus())) {
+                    list.add("您有客户邀约进店");
+                    loginType = "1";
 
 
-                        list = jsonObject;
-                        loginType = "1";
+                } else if (Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(follow.getFollowStatus())) {
+                    list.add("您有客户需要约尺服务");
+                    loginType = "1";
 
 
+                }
+                list.add(customer.getCusName());
+                list.add(customer.getCusPhone());
+                // 查询跟进人的openid和publicOpenId
+                ResponseResultVO<?> resultVO = userFeign.getUser(followStaff.getWxUserId());
+                // 如果没有成功返回,状态设置为待审
+                if (resultVO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) {
+                    log.error("客户查询异常:为空{}", follow.getCusId());
+                    return ResponseCodeEnum.SELECT_NULL.getMessage();
+                } else {
+                    Map<String, Object> user = (Map<String, Object>) resultVO.getData();
+                    if (user != null) {
+                        // 发送消息
+                        Map<String, Object> mapMessage = new HashMap<>();
+                        mapMessage.put("loginType", loginType);
+                        mapMessage.put("publicOpenId", user.get("publicOpenId"));
+                        mapMessage.put("first", "客户跟进提醒");
+                        mapMessage.put("keywordList", list);
+                        mapMessage.put("remark", "客户跟进备注");
+                        sendUniformMessage(mapMessage);
                     }
                     }
                 }
                 }
 
 
@@ -451,6 +468,81 @@ public class CusFollowService extends BaseService<CusFollow> {
     }
     }
 
 
     /**
     /**
+     * @author : sh4wmoo
+     * @date : 2021-7-20 13:49
+     * @desc : iBOSS推送公众号消息卡片
+     */
+    public ResponseResultVO sendUniformMessage(Map<String, Object> map) {
+        log.info("推送参数:{}", JSON.toJSONString(map));
+
+        // 3.获取token 231011
+        String token = this.getWxPublicAccountToken(); //this.getToken();
+        log.info("当前token:{}", token);
+        // 4.发送模板卡片 230927 地址发生变化
+        ResponseResultVO<JSONObject> res = HttpUtils.post(config.getUniformSend() + token, new HashMap<String, Object>(4) {{
+
+//            新加POST数据示例如下 240712
+            put("touser", map.get("publicOpenId") + "");
+            put("template_id", config.getTemplateId());
+            put("miniprogram", new HashMap<String, Object>(4) {{
+                put("appid", config.getAppId());
+                //用户点击公众号推送消息跳转小程序单据详情页 orderType  里面存放json字符串数据
+                //判断InvoiceParam
+                if (map.containsKey("InvoiceParam")) {
+                    put("pagepath", "pages/login/login?loginType=" + map.get("loginType").toString() + "&InvoiceParam=" + map.get("InvoiceParam").toString());
+                } else {
+                    put("pagepath", "pages/login/login?loginType=" + map.get("loginType").toString());
+                }
+            }});
+            put("data", new HashMap<String, Object>(16) {{
+                put("first", new HashMap<String, Object>(4) {{
+                    put("value", map.get("first").toString());
+                    put("color", "#173177");
+                }});
+                List<String> keywordList = (List<String>) map.get("keywordList");
+                //lambda foreach 取下标
+                IntStream.range(0, keywordList.size()).forEach(i -> {
+                    String keyIndex = "keyword" + (i + 1);
+                    put(keyIndex, new HashMap<String, Object>(4) {{
+                        put("value", keywordList.get(i));
+                        put("color", "#173177");
+                    }});
+                });
+                put("remark", new HashMap<String, Object>(4) {{
+                    put("value", map.get("remark").toString());
+                    put("color", "#173177");
+                }});
+            }});
+
+        }});
+        if (res.getCode() == ResponseCodeEnum.SUCCESS.getCode() && res.getData().getString("errcode").equals("0")) {
+            log.info("推送成功:{}");
+            return ResponseResultUtil.success();
+        } else {
+            log.error("推送失败:{}", res.getData().toJSONString());
+            return ResponseResultUtil.error(res.getData().toJSONString());
+        }
+    }
+
+    /**
+     * @author : jyh
+     * @date : 2023-10-11 16:23
+     * @desc : 调用中控服务获取公众号的token
+     */
+    public String getWxPublicAccountToken() {
+        ResponseResultVO<JSONObject> res = HttpUtils.post(config.getWechatUrlToken(),
+                new HashMap() {{
+                    put("appId", config.getWxPublicAccountAppId());
+                    put("appSecret", config.getWxPublicAccountAppSecret());
+                }});
+        if (res.getCode() == 200 && JSON.parseObject(JSON.toJSONString(res.getData())).get("code").toString().equals("200")) {
+            return JSON.parseObject(JSON.toJSONString(res.getData())).get("data").toString();
+        } else {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), res.getMessage());
+        }
+    }
+
+    /**
      * @desc : 发送跟进任务消息
      * @desc : 发送跟进任务消息
      * @author : 姜永辉
      * @author : 姜永辉
      * @date : 2022-06-30 19:24
      * @date : 2022-06-30 19:24