yfh 1 ヶ月 前
コミット
3d13f3d1c9

+ 39 - 18
fs-service/src/main/java/com/fs/qw/service/impl/QwContactWayServiceImpl.java

@@ -6,6 +6,7 @@ import com.fs.common.BeanCopyUtils;
 import com.fs.common.core.domain.R;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.StringUtils;
 import com.fs.course.domain.FsCourseWatchLog;
 import com.fs.course.mapper.FsCourseWatchLogMapper;
 import com.fs.course.param.FsCourseLinkCreateParam;
@@ -104,6 +105,7 @@ public class QwContactWayServiceImpl implements IQwContactWayService
         log.info("新增企微活码corpId"+corpId);
         qwContactWay.setType(type);
         qwContactWay.setCreateTime(DateUtils.getNowDate());
+
         qwContactWayMapper.insertQwContactWay(qwContactWay);
         Long id = qwContactWay.getId();
         qwAddContactWayParam.setType(type);
@@ -368,10 +370,9 @@ public class QwContactWayServiceImpl implements IQwContactWayService
 
     }
 
-    @Override
-    public boolean sendWelcomeMsg(QwContactWay qwContactWay, String corpId, String welcomeCode,QwUser qwUser,Long qwExternalId) {
-
 
+    @Override
+    public boolean sendWelcomeMsg(QwContactWay qwContactWay, String corpId, String welcomeCode, QwUser qwUser, Long qwExternalId) {
         if (qwContactWay.getIsSpanWelcome()==1){
             String welcomeJson = qwContactWay.getWelcomeJson();
             if (welcomeJson!=null&&welcomeJson!=""){
@@ -392,9 +393,7 @@ public class QwContactWayServiceImpl implements IQwContactWayService
 
                             SendWelcomeMsgParam copy = BeanCopyUtils.copy(qwWelcomeJsonFrom, SendWelcomeMsgParam.class);
                             copy.setWelcome_code(welcomeCode);
-
                             QwResult qwResult = qwApiService.sendWelcomeMsg(copy, corpId);
-
                             if (qwResult.getErrcode()==0){
                                 return false;
                             }else {
@@ -408,23 +407,45 @@ public class QwContactWayServiceImpl implements IQwContactWayService
 
 
         }
+
         SendWelcomeMsgParam sendWelcomeMsgParam = new SendWelcomeMsgParam();
         sendWelcomeMsgParam.setWelcome_code(welcomeCode);
-        TextMessage textMessage = new TextMessage();
-        textMessage.setContent(qwContactWay.getTextContent());
-        sendWelcomeMsgParam.setText(textMessage);
-        SendWelcomeMsgParam.Attachment attachment = new SendWelcomeMsgParam.Attachment();
-        SendWelcomeMsgParam.Attachment.ImageAttachment imageAttachment = new SendWelcomeMsgParam.Attachment.ImageAttachment();
-        imageAttachment.setPic_url(qwContactWay.getImagePicUrl());
-        attachment.setMsgtype("image");
-        attachment.setImage(imageAttachment);
-        sendWelcomeMsgParam.setAttachments(Arrays.asList(attachment));
+
+        // 构建文本消息
+        if (StringUtils.isNotBlank(qwContactWay.getTextContent())) {
+            TextMessage textMessage = new TextMessage();
+            textMessage.setContent(qwContactWay.getTextContent());
+            sendWelcomeMsgParam.setText(textMessage);
+        }
+
+        // 构建图片附件 - 修正结构
+        List<SendWelcomeMsgParam.Attachment> attachments = new ArrayList<>();
+
+        if (StringUtils.isNotBlank(qwContactWay.getImagePicUrl())) {
+            SendWelcomeMsgParam.Attachment imageAttachment = new SendWelcomeMsgParam.Attachment();
+            imageAttachment.setMsgtype("image");
+
+            // 创建图片内容对象
+            SendWelcomeMsgParam.Attachment.ImageAttachment imageContent = new SendWelcomeMsgParam.Attachment.ImageAttachment();
+            imageContent.setPic_url(qwContactWay.getImagePicUrl());
+            imageAttachment.setImage(imageContent);
+
+            attachments.add(imageAttachment);
+        }
+
+        if (!attachments.isEmpty()) {
+            sendWelcomeMsgParam.setAttachments(attachments);
+        }
+
+        // 发送请求
         QwResult qwResult = qwApiService.sendWelcomeMsg(sendWelcomeMsgParam, corpId);
-        if (qwResult.getErrcode()==0){
-            return false;
-        }else {
-            return true;
+
+        if ("levent".equals(qwUser.getQwUserId())) {
+            log.debug("发送结果: {}", qwResult);
         }
+
+        // 修正返回值逻辑 - 0表示成功
+        return qwResult.getErrcode() == 0;
     }
 
     public List<QwWelcomeJsonFrom.Attachment> attachmentsTools( List<QwWelcomeJsonFrom.Attachment> attachments,

+ 30 - 6
fs-service/src/main/java/com/fs/qw/service/impl/QwExternalContactServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONException;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.ad.enums.AdUploadType;
@@ -1058,6 +1059,8 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                     } else {
                         qwExternalContactMapper.insertQwExternalContact(qwExternalContact);
                     }
+
+                    logger.info("成功同步一个用户");
                 }
 
             }else {
@@ -2176,8 +2179,8 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 
     @Override
     public QwUser getQwUserByRedisForId(String qwUserId) {
-        if(qwUserId==null|| !qwUserId.isEmpty()){
-            return  null;
+        if(StringUtils.isEmpty(qwUserId)){
+            return null;
         }
         String redisKey = "qwUserRdById:" + qwUserId;
 
@@ -2306,7 +2309,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                                     }
                                 }
                             }
-                            if (qwContactWay.getIsSpanWelcome() == 1 && isClose) {
+                            if (qwContactWay.getIsWelcome() == 1 && isClose) {
                                 isSend = qwContactWayService.sendWelcomeMsg(qwContactWay, corpId, welcomeCode,qwUser,contact.getId());
                             }
                         }
@@ -2345,7 +2348,6 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
                                 LocalTime start = LocalTime.parse(schedule.getStartTime());
                                 LocalTime end = LocalTime.parse(schedule.getEndTime().equals("24:00") ? "23:59:59" : schedule.getEndTime());
                                 if (!now.isBefore(start) && !now.isAfter(end)) {
-
                                     TextMessage textMessage = new TextMessage();
                                     textMessage.setContent(schedule.getWelcomeText());
                                     sendWelcomeMsgParam.setText(textMessage);
@@ -2448,6 +2450,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 
                     if (wayLogs==null){
 
+
                         QwAppContactWayLogs qwAppContactWayLogs = new QwAppContactWayLogs();
                         qwAppContactWayLogs.setAppWayId(qwAppContactWay.getId());
                         qwAppContactWayLogs.setUserId(qwAppContactWay.getUserId());
@@ -4258,7 +4261,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 
         //客户删除销售-找这个销售的sop任务中所有的营期里有没有这个客户,删了(暂时不要删-这种流失的有些一样能发消息)
 //        sopUserLogsInfoMapper.deleteByQwUserIdAndCorpIdToContactId(userID,corpId, externalUserID);
-        logger.error("客户删除销售-"+"|"+externalUserID+"|"+userID+"|"+corpId);
+//        logger.error("客户删除销售-"+"|"+externalUserID+"|"+userID+"|"+corpId);
 
         QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalContactUserIdAndExternalIdAndCompanyId(externalUserID, userID, corpId);
         if (qwExternalContact != null) {
@@ -4890,7 +4893,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
         for (QwOptionsVO qwOptionsVO : qwOptionsVOS) {
             String corpId = qwOptionsVO.getCorpId();
 //            System.out.println("同步的"+corpId);
-//            logger.info("同步的"+corpId);
+            logger.info("同步的"+corpId);
             executor.execute(() ->  qwExternalContactSyncByCorpId(corpId));
         }
         executor.shutdown();
@@ -5832,6 +5835,27 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
         return qwExternalContactMapper.selectQwUserDelLossList(param);
     }
 
+    @Override
+    public void updateQwExternalContactStatusById(QwExternalContact qwExternalContact) {
+        qwExternalContactMapper.updateQwExternalContactStatusById(qwExternalContact);
+    }
+
+    @Override
+    public R getRepeat(RepeatParam param) {
+        List<QwExternalContact> list = qwExternalContactMapper.selectList(new QueryWrapper<QwExternalContact>().eq("external_user_id", param.getExternalUserId()));
+        if(list.isEmpty()) return R.error("未找到外部联系人");
+        QwExternalContact qwExternalContact = list.get(0);
+        List<QwExternalContact> qwExternalContacts = qwExternalContactMapper.selectList(new QueryWrapper<QwExternalContact>().eq("repeat_no", qwExternalContact.getRepeatNo()));
+        List<String> userIdList = PubFun.listToNewList(qwExternalContacts, QwExternalContact::getUserId);
+        List<QwUser> qwUsers = qwUserMapper.selectList(new QueryWrapper<QwUser>().in("qw_user_id", userIdList).eq("corp_id", qwExternalContact.getCorpId()));
+        List<String> companyIds = PubFun.listToNewList(qwUsers, QwUser::getCorpId);
+        List<QwCompany> companyList = qwCompanyMapper.selectByCorpIds(companyIds);
+        Map<String, QwCompany> companyMap = PubFun.listToMapByGroupObject(companyList, QwCompany::getCorpId);
+        QwCompany qwCompany = new QwCompany();
+        qwCompany.setCorpName("未找到主题");
+        return R.ok().put("data", qwUsers.stream().map(e -> QwUserVO.builder().qwUserId(e.getQwUserId()).qwUserName(e.getQwUserName()).companyName(companyMap.getOrDefault(e.getCorpId(), qwCompany).getCorpName()).build()));
+    }
+
 
     public Boolean getSopAiChatByRedis(String qwUserId,String corpId,String externalUserId){