Pārlūkot izejas kodu

微信客户的开发

dongxin 1 gadu atpakaļ
vecāks
revīzija
71b9f5b8b4

+ 1 - 1
linkwe-api/src/main/java/com/linkwechat/controller/WeCustomerUserController.java

@@ -71,7 +71,7 @@ public class WeCustomerUserController extends BaseController {
      */
     @PostMapping("/bindUser/{id}")
     @ApiOperation(value = "绑定用户",httpMethod = "POST")
-    public AjaxResult bindUser(@RequestBody String userId, @PathVariable String id) {
+    public AjaxResult bindUser( @PathVariable String id,@RequestParam String userId) {
 
         weCustomerUserService.bindUser(userId,id);
         return AjaxResult.success();

+ 32 - 2
linkwe-api/src/main/java/com/linkwechat/controller/WeUserController.java

@@ -1,14 +1,19 @@
 package com.linkwechat.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.linkwechat.common.annotation.Log;
 import com.linkwechat.common.core.controller.BaseController;
 import com.linkwechat.common.core.domain.AjaxResult;
 import com.linkwechat.common.core.page.TableDataInfo;
 import com.linkwechat.common.core.page.TableSupport;
 import com.linkwechat.common.enums.BusinessType;
+import com.linkwechat.domain.WeUser;
 import com.linkwechat.domain.customer.query.WeCuUserQuery;
 import com.linkwechat.domain.customer.vo.WeUserDetailInfoVo;
 import com.linkwechat.domain.customer.vo.WeUserVo;
+import com.linkwechat.domain.wecom.query.customer.WeCustomerQuery;
+import com.linkwechat.domain.wecom.vo.customer.WeCustomerDetailVo;
+import com.linkwechat.fegin.QwCustomerClient;
 import com.linkwechat.service.IWeUserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -33,12 +38,15 @@ public class WeUserController extends BaseController {
     @Autowired
     private IWeUserService weUserService;
 
+    @Autowired
+    private QwCustomerClient qwCustomerClient;
+
     /**
      * 查询同步用户列表(分页),索引优化用户列表,未使用默认分页
      */
     @GetMapping("/findWeUserList")
     @ApiOperation(value = "询同步用户列表(分页)",httpMethod = "GET")
-    public TableDataInfo findWeCustomerList(WeCuUserQuery weUserQuery) {
+    public TableDataInfo findWeUserList(WeCuUserQuery weUserQuery) {
         List<WeUserVo> list = weUserService.findWeUserList(weUserQuery, TableSupport.buildPageRequest());
         TableDataInfo dataTable = getDataTable(list);
         //设置总条数
@@ -49,6 +57,18 @@ public class WeUserController extends BaseController {
         return dataTable;
     }
 
+    /**
+     * 查询同步用户列表(本地生活)
+     */
+    @GetMapping("/findUserList")
+    @ApiOperation(value = "询同步用户列表",httpMethod = "GET")
+    public AjaxResult findUserList() {
+        LambdaQueryWrapper<WeUser> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(WeUser::getSource,1);
+        List<WeUser> list = weUserService.list(wrapper);
+        return AjaxResult.success(list);
+    }
+
 
     /**
      * 分配/转移
@@ -59,7 +79,7 @@ public class WeUserController extends BaseController {
     @Log(title = "分配/转出", businessType = BusinessType.UPDATE)
     @ApiOperation(value = "分配/转移",httpMethod = "POST")
     @PostMapping("/transferOwner/{id}")
-    public AjaxResult transferOwner(@PathVariable("id") Long id, @RequestBody Long userId){
+    public AjaxResult transferOwner(@PathVariable("id") Long id, @RequestParam Long userId){
 
         weUserService.transferOwner(id, userId);
         return AjaxResult.success();
@@ -78,5 +98,15 @@ public class WeUserController extends BaseController {
         );
     }
 
+    @GetMapping("/test")
+    @ApiOperation(value = "同步用户详情基础",httpMethod = "GET")
+    public AjaxResult test(){
+
+        WeCustomerQuery weCustomerQuery = new WeCustomerQuery();
+        weCustomerQuery.setExternal_userid("wmKy90DgAAiVxlyi0-UT60f-cAjiIMUQ");
+        weCustomerQuery.setCorpid("wwfe67d19509d43ec5");
+        WeCustomerDetailVo customerDetail = qwCustomerClient.getCustomerDetail(weCustomerQuery).getData();
+        return AjaxResult.success();
+    }
 
 }

+ 6 - 1
linkwe-service/src/main/java/com/linkwechat/domain/WeCustomer.java

@@ -1,7 +1,9 @@
 package com.linkwechat.domain;
 
+import com.alibaba.excel.annotation.ExcelProperty;
 import com.baomidou.mybatisplus.annotation.*;
 import com.linkwechat.common.core.domain.BaseEntity;
+import com.linkwechat.converter.CustomerTypeConverter;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -220,6 +222,9 @@ public class WeCustomer extends BaseEntity {
      */
     private Integer delFlagBa;
 
-
+    /**
+     * 客户来源 0.客群活码 1.门店活码 2.识客活码 3.拉新活码
+     */
+    private Integer source;
 
 }

+ 1 - 1
linkwe-service/src/main/java/com/linkwechat/domain/WeUser.java

@@ -97,7 +97,7 @@ public class WeUser {
     private Date lastInteractionTime;
 
     /**
-     * 添加时间
+     * 创建时间
      */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date createTime;

+ 1 - 1
linkwe-service/src/main/java/com/linkwechat/domain/customer/vo/WeCustomerUserVo.java

@@ -62,6 +62,6 @@ public class WeCustomerUserVo {
      * 最后同步绑定时间
      */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
-    private Date updateTime;
+    private Date createTime;
 
 }

+ 8 - 1
linkwe-service/src/main/java/com/linkwechat/domain/customer/vo/WeUserVo.java

@@ -81,10 +81,17 @@ public class WeUserVo {
      */
     private Integer deliveredStatus;
 
+    /**
+     * 添加时间
+     */
+    @DateTimeFormat("yyyy-MM-dd")
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date addTime;
+
     /**
      * 最近互动时间
      */
     @DateTimeFormat("yyyy-MM-dd")
     @JsonFormat(pattern = "yyyy-MM-dd")
-    private Date updateTime;
+    private Date lastInteractionTime;
 }

+ 31 - 0
linkwe-service/src/main/java/com/linkwechat/service/impl/ISxkWelcomeMsgServiceImpl.java

@@ -14,8 +14,12 @@ import com.linkwechat.common.utils.xml.XmlUtils;
 import com.linkwechat.domain.WeCorpAccount;
 import com.linkwechat.domain.WeCustomer;
 import com.linkwechat.domain.WeCustomerSeas;
+import com.linkwechat.domain.WeUser;
 import com.linkwechat.domain.wecom.callback.WeBackCustomerVo;
 import com.linkwechat.domain.wecom.callback.xml.*;
+import com.linkwechat.domain.wecom.query.customer.WeCustomerQuery;
+import com.linkwechat.domain.wecom.vo.customer.WeCustomerDetailVo;
+import com.linkwechat.fegin.QwCustomerClient;
 import com.linkwechat.mapper.WeCustomerMapper;
 import com.linkwechat.service.*;
 import lombok.extern.slf4j.Slf4j;
@@ -62,6 +66,10 @@ public class ISxkWelcomeMsgServiceImpl implements ISxkWelcomeMsgService {
     @Lazy
     private IWeCustomerService iWeCustomerService;
 
+    @Autowired
+    @Lazy
+    private IWeUserService iWeUserService;
+
     @Autowired
     private WeCustomerMapper weCustomerMapper;
 
@@ -81,6 +89,9 @@ public class ISxkWelcomeMsgServiceImpl implements ISxkWelcomeMsgService {
     @Lazy
     private IWeCustomerSeasService weCustomerSeasService;
 
+    @Autowired
+    private QwCustomerClient qwCustomerClient;
+
 
     /**
      * 业务处理
@@ -160,6 +171,26 @@ public class ISxkWelcomeMsgServiceImpl implements ISxkWelcomeMsgService {
                         log.info("不是 指定 推送消息,不推送!");
                     }
 
+                    WeCustomerQuery weCustomerQuery = new WeCustomerQuery();
+                    weCustomerQuery.setExternal_userid(addExternalContact.getExternalUserID());
+                    weCustomerQuery.setCorpid(addExternalContact.getToUserName());
+                    WeCustomerDetailVo customerDetail = qwCustomerClient.getCustomerDetail(weCustomerQuery).getData();
+                    // 通过手机更新同步用户的状态时间
+                    List<String> mobileList = customerDetail.getFollowUser().get(0).getRemarkMobiles();
+                    Date now = new Date();
+                    if (!CollectionUtils.isEmpty(mobileList)) {
+                        LambdaQueryWrapper<WeUser> wrapper = new LambdaQueryWrapper<>();
+                        wrapper.in(WeUser::getPhone, mobileList);
+                        List<WeUser> userList = iWeUserService.list(wrapper);
+                        if (!CollectionUtils.isEmpty(userList)) {
+                            for (WeUser user : userList) {
+                                user.setDeliveredStatus(1);
+                                user.setAddTime(now);
+                                user.setLastInteractionTime(now);
+                            }
+                            iWeUserService.saveOrUpdateBatch(userList);
+                        }
+                    }
                 }
                 // 同步客戶
                 log.info("回调, 拉取业务员指定客户信息开始。。。");

+ 16 - 3
linkwe-service/src/main/java/com/linkwechat/service/impl/WeCustomerServiceImpl.java

@@ -1,5 +1,6 @@
 package com.linkwechat.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.util.ArrayUtil;
@@ -119,6 +120,9 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
     @Autowired
     private IWeCustomerInfoExpandService iWeCustomerInfoExpandService;
 
+    @Autowired
+    private IWeUserService iWeUserService;
+
     @Autowired
     @Lazy
     private IWeFissionService iWeFissionService;
@@ -332,7 +336,6 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
                 weCustomer.setDelFlag(0);
                 weCustomer.setRemarkName(followInfo.getRemark());
                 weCustomer.setOtherDescr(followInfo.getDescription());
-
                 String state = weCustomer.getState() == null?"":weCustomer.getState();
 
                 if (state.startsWith(WeConstans.RENEWAL)) {
@@ -370,8 +373,18 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
                 // 手机号
                 weCustomer.setPhone(String.join(",", Optional.ofNullable(followInfo.getRemarkMobiles()).orElseGet(ArrayList::new)));
 
-
-
+                // 通过state 区分客户来源
+                if(StringUtils.isNotEmpty(weCustomer.getState())){
+                    if(weCustomer.getState().contains(WelcomeMsgTypeEnum.WE_LX_QR_CODE_PREFIX.getType())){
+                        weCustomer.setSource(3);
+                    } else if(weCustomer.getState().contains(WelcomeMsgTypeEnum.WE_QR_XKLQ_PREFIX.getType())){
+                        weCustomer.setSource(0);
+                    } else if(weCustomer.getState().contains(WelcomeMsgTypeEnum.WE_STORE_CODE_CONFIG_PREFIX.getType())){
+                        weCustomer.setSource(1);
+                    } else if(weCustomer.getState().contains(WelcomeMsgTypeEnum.WE_KNOW_CUSTOMER_CODE_PREFIX.getType())){
+                        weCustomer.setSource(2);
+                    }
+                }
                 // 设置车险标签
                 Set<String> stateSet = new TreeSet<>();
                 if (state.startsWith(WeConstans.CAR)) {

+ 5 - 5
linkwe-service/src/main/resources/mapper/wecom/WeCustomerUserMapper.xml

@@ -20,7 +20,7 @@
                 AND wcu.status = #{weCustomerUserList.status}
             </if>
         </where>
-        ORDER BY wcu.add_time desc
+        ORDER BY wcu.create_time desc
         <if test="pageDomain !=null">
             <if test="pageDomain.pageNum !=null and pageDomain.pageSize !=null">
                 limit ${pageDomain.pageSize * (pageDomain.pageNum-1)}, #{pageDomain.pageSize}
@@ -57,17 +57,17 @@
         wcu.user_code as userCode,
         wcu.wx_phone as wxPhone,
         wcu.wx_nickname as wxNickname,
-        wcu.wx_avator as wxAvatar,
+        wcu.wx_avatar as wxAvatar,
         wcu.wx_openid as wxOpenid,
         wcu.bind_time as bindTime,
-        wcu.update_time as updateTime,
-        wcu.status
+        wcu.create_time as createTime,
+        wcu.`status`
         FROM we_customer_user wcu
         WHERE
         wcu.id in
         <foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
             #{id}
         </foreach>
-        ORDER BY wcu.add_time desc
+        ORDER BY wcu.create_time desc
     </select>
 </mapper>

+ 9 - 8
linkwe-service/src/main/resources/mapper/wecom/WeUserMapper.xml

@@ -7,13 +7,13 @@
     <select id="findWeUserListIds" resultType="java.lang.String">
         SELECT wur.id FROM we_user wur
         <where>
-            <if test="weUserList.userCode != null">
+            <if test="weUserList.userCode != null and weUserList.userCode != ''">
                 AND wur.user_code=#{weUserList.userCode}
             </if>
-            <if test="weUserList.name != null">
+            <if test="weUserList.name != null and weUserList.name != ''">
                 AND wur.name=#{weUserList.name}
             </if>
-            <if test="weUserList.phone != null">
+            <if test="weUserList.phone != null and weUserList.phone != ''">
                 AND wur.phone=#{weUserList.phone}
             </if>
 
@@ -41,13 +41,13 @@
         count(0)
         FROM we_user wur
         <where>
-            <if test="weUserList.userCode != null">
+            <if test="weUserList.userCode != null and weUserList.userCode != ''">
                 AND wur.user_code=#{weUserList.userCode}
             </if>
-            <if test="weUserList.name != null">
+            <if test="weUserList.name != null and weUserList.name != ''">
                 AND wur.name=#{weUserList.name}
             </if>
-            <if test="weUserList.phone != null">
+            <if test="weUserList.phone != null and weUserList.phone != ''">
                 AND wur.phone=#{weUserList.phone}
             </if>
 
@@ -78,8 +78,9 @@
             wu.delivered_status as deliveredStatus,
             wu.type,
             wu.owner_user_id as ownerUserId,
-            wu.update_time as updateTime,
-            wu.register_time as registerTime
+            wu.register_time as registerTime,
+            wu.add_time as addTime,
+            wu.last_Interaction_time as lastInteractionTime
         FROM
             we_user wu
         WHERE