瀏覽代碼

1.提交企业微信回复默认文本

jzp 2 月之前
父節點
當前提交
f4890ebc0a

+ 11 - 0
fs-company/src/main/java/com/fs/company/controller/company/CompanyUserController.java

@@ -570,6 +570,17 @@ public class CompanyUserController extends BaseController
             return AjaxResult.error("操作失败");
         }
     }
+
+    @Log(title = "设置客户第一次开口返回的文字", businessType = BusinessType.UPDATE)
+    @PutMapping("/bindCompanyUserReplyTxt")
+    public AjaxResult bindCompanyUserReplyTxt(@RequestParam String replyText, @RequestBody List<Long> userIds) {
+        Boolean r = companyUserService.bindCompanyUserReplyTxt(replyText, userIds);
+        if (r) {
+            return AjaxResult.success();
+        } else {
+            return AjaxResult.error("操作失败");
+        }
+    }
     @PostMapping("/common/uploadOSS")
     public R uploadOSS(@RequestParam("file") MultipartFile file,
                        @RequestParam("userId") String userId) throws Exception {

+ 70 - 28
fs-qw-api-msg/src/main/java/com/fs/app/controller/QwMsgController.java

@@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSON;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.uuid.IdUtils;
+import com.fs.company.domain.CompanyUser;
+import com.fs.company.mapper.CompanyUserMapper;
 import com.fs.fastGpt.domain.FastGptRole;
 import com.fs.fastGpt.service.AiHookService;
 import com.fs.fastGpt.service.IFastGptRoleService;
@@ -79,6 +81,9 @@ public class QwMsgController {
     @Autowired
     private QwExternalContactInfoMapper qwExternalContactInfoMapper;
 
+    @Autowired
+    private CompanyUserMapper companyUserMapper;
+
     @GetMapping("/sendExpressInfo/{orderId}")
     public R sendExpressInfo(@PathVariable Long orderId){
         String isSend = redisCache.getCacheObject("fs:express:info:send:" +orderId);
@@ -350,6 +355,20 @@ public class QwMsgController {
 
                     if (2000000000000000L-receiver>0){
                         log.info("id:{}, 客户发送", id);
+                        QwUser user = qwUserMapper.selectQwUserById(id);
+                        if(user != null){
+                            Long userId = user.getId();
+                            CompanyUser companyUser = companyUserMapper.selectCompanyUserByQwUserId(userId);
+                            if(companyUser != null && companyUser.getReplyText() != null){
+                                String extId1 = getExtId(wxWorkMessageDTO.getSender(), user.getUid(), user.getServerId());
+                                QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalContactByExternalUserIdAndQwUserId(extId1, user.getCorpId(),user.getQwUserId());
+                                //用户是未回复状态
+                                if(qwExternalContact != null && qwExternalContact.getIsReply() == 0){
+                                    qwExternalContactMapper.updateQwExternalContactIsRePlyById(qwExternalContact.getId());
+                                    sendAiTxtMsg(companyUser.getReplyText(),sender,user.getUid(),serverId);
+                                }
+                            }
+                        }
                         aiHookService.qwHookNotifyAiReply(id,sender,content,wxWorkMsgResp.getUuid(),wxWorkMessageDTO.getMsgtype());
                     }else {
                         log.info("销售发送");
@@ -398,37 +417,36 @@ public class QwMsgController {
                                 totalSeconds = hours * 3600L + minutes * 60L + seconds;
                                 log.info("id:{}, 总通话秒数: " + totalSeconds, id);
                             }
-                        }
-                        try {
-                            QwUser user = qwUserMapper.selectQwUserById(id);
-                            if (user.getFastGptRoleId()!=null&&user.getFastGptRoleId()!=0){
-                                //获取当前用户的external_user_id
-                                String extId1 = getExtId(wxWorkMessageDTO.getReceiver(), user.getUid(), user.getServerId());
-                                QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalContactByExternalUserIdAndQwUserId(extId1, user.getCorpId(),user.getQwUserId());
-                                Long id1 = qwExternalContact.getId();
-                                QwExternalContactInfo info = qwExternalContactInfoMapper.selectQwExternalContactInfoByExternalContactId(id1);
-                                if(info == null){
-                                    info = new QwExternalContactInfo();
-                                    info.setTalk("非首次交流");
-                                    info.setExternalContactId(id1);
-                                    info.setCreateTime(new Date());
-                                    qwExternalContactInfoMapper.insertQwExternalContactInfo(info);
-                                    //去除新客对话
-                                    aiHookService.cleanNewUserDialogue(user, qwExternalContact);
-
-                                    //发送宣导语音和视频
-                                    aiHookService.sendVideoAndVoice(wxWorkMessageDTO.getSender(), wxWorkMsgResp.getUuid(), user);
-                                }else{
-                                    //将交流状态改为非首次交流
-                                    qwExternalContactInfoMapper.updateQwExternalContactInfoByExtId(id1);
-                                    //去除新客对话
-                                    aiHookService.cleanNewUserDialogue(user, qwExternalContact);
+                            try {
+                                QwUser user = qwUserMapper.selectQwUserById(id);
+                                if (user.getFastGptRoleId()!=null&&user.getFastGptRoleId()!=0){
+                                    //获取当前用户的external_user_id
+                                    String extId1 = getExtId(extId, user.getUid(), user.getServerId());
+                                    QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalContactByExternalUserIdAndQwUserId(extId1, user.getCorpId(),user.getQwUserId());
+                                    Long id1 = qwExternalContact.getId();
+                                    QwExternalContactInfo info = qwExternalContactInfoMapper.selectQwExternalContactInfoByExternalContactId(id1);
+                                    if(info == null){
+                                        info = new QwExternalContactInfo();
+                                        info.setTalk("非首次交流");
+                                        info.setExternalContactId(id1);
+                                        info.setCreateTime(new Date());
+                                        qwExternalContactInfoMapper.insertQwExternalContactInfo(info);
+                                        //去除新客对话
+                                        aiHookService.cleanNewUserDialogue(user, qwExternalContact);
+
+                                        //发送宣导语音和视频
+                                        aiHookService.sendVideoAndVoice(extId, wxWorkMsgResp.getUuid(), user);
+                                    }else{
+                                        //将交流状态改为非首次交流
+                                        qwExternalContactInfoMapper.updateQwExternalContactInfoByExtId(id1);
+                                        //去除新客对话
+                                        aiHookService.cleanNewUserDialogue(user, qwExternalContact);
+                                    }
                                 }
+                            } catch (Exception e) {
+                                log.error("id:{}, 处理通话后的视频语音", id, e);
                             }
-                        } catch (Exception e) {
-                            log.error("id:{}, 处理通话后的视频语音", id, e);
                         }
-
                     } else if (recordType==2){
                         log.info("id:{}, 通话挂断", id);
                     }else if (recordType==3){
@@ -450,6 +468,30 @@ public class QwMsgController {
         return map;
     }
 
+
+    /**
+     * 发送固定的文字
+     * @param content
+     * @param sendId
+     * @param uuid
+     * @param serverId
+     */
+    private void sendAiTxtMsg(String content, Long sendId , String uuid,Long serverId) {
+        if (content == null || content.trim().isEmpty()){
+            System.out.println("输出为空格");
+            return;
+        }
+        WxWorkSendTextMsgDTO wxWorkSendTextMsgDTO = new WxWorkSendTextMsgDTO();
+        wxWorkSendTextMsgDTO.setSend_userid(sendId);
+        wxWorkSendTextMsgDTO.setUuid(uuid);
+        wxWorkSendTextMsgDTO.setContent(content);
+        wxWorkSendTextMsgDTO.setIsRoom(false);
+        WxWorkResponseDTO<WxWorkSendTextMsgRespDTO> wxWorkSendTextMsgRespDTOWxWorkResponseDTO = wxWorkService.SendTextMsg(wxWorkSendTextMsgDTO,serverId);
+        WxWorkSendTextMsgRespDTO data = wxWorkSendTextMsgRespDTOWxWorkResponseDTO.getData();
+
+
+    }
+
     String getExtId(Long id,String uid,Long serverId){
         WxWorkVid2UserIdDTO wxWorkVid2UserIdDTO = new WxWorkVid2UserIdDTO();
         wxWorkVid2UserIdDTO.setUser_id(Arrays.asList(id));

+ 2 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyUser.java

@@ -153,6 +153,8 @@ public class CompanyUser extends BaseEntity
 
     private String imNickName;
 
+    private String replyText;
+
     public String getImNickName() {
         return imNickName;
     }

+ 4 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyUserMapper.java

@@ -322,4 +322,8 @@ public interface CompanyUserMapper
 
 
     List<String> selectCompanyUserNameByIdsList(@Param("companyUserIDs")List<Long> companyUserID);
+
+    CompanyUser selectCompanyUserByQwUserId(@Param("qwUserId") Long userId);
+
+    Boolean bindCompanyUserReplyTxt(@Param("replyText") String replyText,@Param("userIds") List<Long> userIds);
 }

+ 2 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyUserService.java

@@ -244,4 +244,6 @@ public interface ICompanyUserService {
     R unBindDoctor(Long userId);
 
     R getBindInfo(Long companyUserId);
+
+    Boolean bindCompanyUserReplyTxt(String replyText, List<Long> userIds);
 }

+ 10 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyUserServiceImpl.java

@@ -1058,4 +1058,14 @@ public class CompanyUserServiceImpl implements ICompanyUserService
         }
         return R.error();
     }
+
+    @Override
+    public Boolean bindCompanyUserReplyTxt(String replyText, List<Long> userIds) {
+        try {
+            companyUserMapper.bindCompanyUserReplyTxt(replyText, userIds);
+        } catch (RuntimeException e) {
+            throw new ServiceException("操作异常");
+        }
+        return true;
+    }
 }

+ 2 - 0
fs-service/src/main/java/com/fs/company/vo/CompanyUserQwListVO.java

@@ -117,6 +117,8 @@ public class CompanyUserQwListVO extends BaseEntity {
     private Integer qwStatus;
     private String addressId;
 
+    private String replyText;
+
     /**
      * 发送延时时间
      */

+ 14 - 0
fs-service/src/main/resources/mapper/company/CompanyUserMapper.xml

@@ -44,6 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="isAllowedAllRegister"    column="is_allowed_all_register"    />
         <result property="isAllowedEveryoneView"    column="is_allowed_everyone_view"    />
         <result property="doctorId"    column="doctor_id"    />
+        <result property="replyText"    column="reply_text"    />
         <result property="createOpen"    column="create_open"    />
         <association property="dept"    column="dept_id" javaType="CompanyDept" resultMap="deptResult" />
         <collection  property="roles"   javaType="java.util.List"        resultMap="RoleResult" />
@@ -578,6 +579,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{userId}
         </foreach>
     </update>
+    <update id="bindCompanyUserReplyTxt" parameterType="Long">
+        update company_user
+        set reply_text = #{replyText} where user_id in
+        <foreach item="userId" collection="userIds" open="(" separator="," close=")">
+            #{userId}
+        </foreach>
+    </update>
 
 
     <select id="selectCompanyUserNameByIdsList" resultType="java.lang.String">
@@ -586,5 +594,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </select>
+    <select id="selectCompanyUserByQwUserId" resultType="com.fs.company.domain.CompanyUser">
+        SELECT * FROM company_user
+        WHERE FIND_IN_SET(#{qwUserId}, qw_user_id) > 0
+        order by create_time desc
+        limit 1
+    </select>
 
 </mapper>