Kaynağa Gözat

用minibinduser做中间表,查询关注时间

QuYueTing 5 gün önce
ebeveyn
işleme
86dd2dac29

+ 20 - 12
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/CustomController.java

@@ -8,10 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.management.platform.entity.*;
 import com.management.platform.mapper.*;
-import com.management.platform.service.ContactsService;
-import com.management.platform.service.CustomService;
-import com.management.platform.service.WechatUserFollowService;
-import com.management.platform.service.WxCorpInfoService;
+import com.management.platform.service.*;
 import com.management.platform.service.impl.ExcelExportServiceImpl;
 import com.management.platform.util.HttpRespMsg;
 import org.apache.commons.lang3.StringUtils;
@@ -64,6 +61,8 @@ public class CustomController {
     private SalesOrderMapper salesOrderMapper;
     @Autowired
     private WechatUserFollowService wechatUserFollowService;
+    @Resource
+    private MiniBindUserService miniBindUserService;
 
 
     @RequestMapping("list")
@@ -217,17 +216,26 @@ public class CustomController {
                     String value = data.getInchargerName();
                     item.add(value);
                 }
-                Optional<WechatUserFollow> first = userFollows.stream().filter(u -> u.getOpenId() != null && StringUtils.isNotEmpty(data.getCustomName()) && u.getOpenId().equals(data.getCustomName())).findFirst();
-                if (first.isPresent()){
-                    LocalDateTime followTime = first.get().getFollowTime();
-                    DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-                    DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
-                    item.add(dateFormatter.format(followTime));
-                    item.add(timeFormatter.format(followTime));
-                }else {
+                String unionId = data.getCustomName();
+                MiniBindUser miniBindUser = miniBindUserService.getOne(new QueryWrapper<MiniBindUser>().eq("unionid", unionId));
+                if (miniBindUser != null) {
+                    String openId = miniBindUser.getOpenid();
+                    Optional<WechatUserFollow> first = userFollows.stream().filter(u -> u.getOpenId() != null && StringUtils.isNotEmpty(openId) && u.getOpenId().equals(openId)).findFirst();
+                    if (first.isPresent()){
+                        LocalDateTime followTime = first.get().getFollowTime();
+                        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
+                        item.add(dateFormatter.format(followTime));
+                        item.add(timeFormatter.format(followTime));
+                    }else {
+                        item.add("");
+                        item.add("");
+                    }
+                } else {
                     item.add("");
                     item.add("");
                 }
+
                 dataList.add(item);
             }
         }

+ 17 - 20
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/WechatCallbackController.java

@@ -197,22 +197,23 @@ public class WechatCallbackController {
                         .eq("openid", scanRecord.getOpenId()).eq("user_id",salesmanId));
 
                 if (miniBindUserList.isEmpty()){
-                    int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
-                    if(count==0) {
-                        Custom custom = new Custom();
-                        custom.setCustomName(openId);//用户的openId
-                        custom.setIsDelete(0);
-                        custom.setCreateTime(new Date());
-                        if (StringUtils.isNotEmpty(salesmanId)) {
-                            custom.setInchargerId(salesmanId);
-                            User user = userService.getById(salesmanId);
-                            custom.setCompanyId(user != null ? user.getCompanyId() : null);
-                            customService.save(custom);
-                            log.info("新增客户成功");
-                        }
-                    }else {
-                        log.info("已存在custom_name为"+openId+"的客户");
-                    }
+                    //此处不生成custom,只有关注了后续的订阅号才算正式关注成功
+//                    int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
+//                    if(count==0) {
+//                        Custom custom = new Custom();
+//                        custom.setCustomName(openId);//用户的openId
+//                        custom.setIsDelete(0);
+//                        custom.setCreateTime(new Date());
+//                        if (StringUtils.isNotEmpty(salesmanId)) {
+//                            custom.setInchargerId(salesmanId);
+//                            User user = userService.getById(salesmanId);
+//                            custom.setCompanyId(user != null ? user.getCompanyId() : null);
+//                            customService.save(custom);
+//                            log.info("新增客户成功");
+//                        }
+//                    }else {
+//                        log.info("已存在custom_name为"+openId+"的客户");
+//                    }
                     MiniBindUser miniBindUser = new MiniBindUser();
                     miniBindUser.setUserId(salesmanId)
                             .setOpenid(openId)
@@ -220,7 +221,6 @@ public class WechatCallbackController {
                             .setCreateTime(LocalDateTime.now());
                     miniBindUserService.save(miniBindUser);
                     log.info("用户关注服务号销售人员的二维码,绑定销售人员和用户id成功");
-
                 }
             }
         }
@@ -228,12 +228,9 @@ public class WechatCallbackController {
 
     //取消关注
     private void handleUnsubscribe(String openId) {
-
         followMapper.delete(new QueryWrapper<WechatUserFollow>().eq("open_id", openId));
-        customService.remove(new QueryWrapper<Custom>().eq("custom_name", openId));
         miniBindUserService.remove(new QueryWrapper<MiniBindUser>().eq("openid", openId));
         log.info("用户取消绑定销售人员成功");
-
     }
     
     private String successResponse(Element root) {