|
|
@@ -24,7 +24,9 @@ import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.date.DateUtil;
|
|
|
import com.fs.company.constant.CompanyTrafficConstants;
|
|
|
import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.domain.CompanyCompanyFsuser;
|
|
|
import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.mapper.CompanyCompanyFsuserMapper;
|
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
|
import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
import com.fs.company.mapper.CompanyUserMapper;
|
|
|
@@ -42,6 +44,7 @@ import com.fs.course.service.IFsUserCourseVideoService;
|
|
|
import com.fs.course.service.IFsVideoResourceService;
|
|
|
import com.fs.course.vo.*;
|
|
|
import com.fs.course.vo.newfs.*;
|
|
|
+import com.fs.his.config.AppConfig;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserIntegralLogs;
|
|
|
import com.fs.his.domain.FsUserWx;
|
|
|
@@ -54,6 +57,7 @@ import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.service.IFsUserWxService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
+import com.fs.im.service.OpenIMService;
|
|
|
import com.fs.qw.domain.*;
|
|
|
import com.fs.qw.mapper.*;
|
|
|
import com.fs.qw.param.FsUserCourseRedPageParam;
|
|
|
@@ -120,6 +124,11 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
private String signProjectName;
|
|
|
@Value("${isNewWxMerchant}")
|
|
|
private Boolean isNewWxMerchant;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OpenIMService openIMService;
|
|
|
+ @Autowired
|
|
|
+ private CompanyCompanyFsuserMapper companyCompanyFsuserMapper;
|
|
|
private static final Logger logger = LoggerFactory.getLogger(FsUserCourseVideoServiceImpl.class);
|
|
|
|
|
|
private static final String miniappRealLink = "/pages_course/video.html?course=";
|
|
|
@@ -3315,5 +3324,247 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
return R.ok("奖励发放成功");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R isSaveKf(FsUserCourseVideoAddKfUParam param) {
|
|
|
+ logger.info("zyp \n【判断添加客服】:{}", param);
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ if (param == null) {
|
|
|
+ return R.error("参数不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询用户
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+
|
|
|
+ // 用户不存在唤起重新授权
|
|
|
+ if (fsUser == null) {
|
|
|
+ return R.error(504, "用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fsUser.getStatus() != null && fsUser.getStatus() == 0) {
|
|
|
+ return R.error("会员被停用,无权限,请联系客服!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理群聊逻辑
|
|
|
+ if (param.getIsRoom() != null && param.getIsRoom() == 1) {
|
|
|
+// return handleGroupChatLogic(param,fsUser);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理普通外部联系人逻辑
|
|
|
+ return handleExternalContactLogic(param, fsUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理群聊逻辑
|
|
|
+ */
|
|
|
+ private R handleGroupChatLogic(FsUserCourseVideoAddKfUParam param,FsUser fsUser) {
|
|
|
+ try {
|
|
|
+ FsCourseLink courseLink = courseLinkMapper.selectFsCourseLinkByLink(param.getLink());
|
|
|
+
|
|
|
+ if (courseLink == null || StringUtils.isEmpty(courseLink.getChatId())) {
|
|
|
+ return R.error("参数有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ QwGroupChat qwGroupChat = qwGroupChatMapper.selectQwGroupChatByChatId(courseLink.getChatId());
|
|
|
+ if (qwGroupChat == null) {
|
|
|
+ logger.error("群聊不存在,chatId: {}", courseLink.getChatId());
|
|
|
+ return R.error("群聊不存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ SopUserLogsInfo sopUserLogsInfo = new SopUserLogsInfo();
|
|
|
+ sopUserLogsInfo.setChatId(courseLink.getChatId());
|
|
|
+ List<QwGroupChatUser> qwGroupChatUsers = qwGroupChatUserMapper.selectByChatId(sopUserLogsInfo);
|
|
|
+
|
|
|
+ if (qwGroupChatUsers == null || qwGroupChatUsers.isEmpty()) {
|
|
|
+ logger.error("群聊用户为空,chatId: {}", courseLink.getChatId());
|
|
|
+ return R.error("群聊用户为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ QueryWrapper<QwExternalContact> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("user_id", qwGroupChat.getOwner());
|
|
|
+
|
|
|
+ if (param.getUserId() != null) {
|
|
|
+ queryWrapper.eq("name", fsUser.getNickName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (param.getCorpId() != null) {
|
|
|
+ queryWrapper.eq("corp_id", param.getCorpId());
|
|
|
+ }
|
|
|
+
|
|
|
+ queryWrapper.eq("status", 0);
|
|
|
+
|
|
|
+ QwExternalContact qwExternalContact = qwExternalContactMapper.selectOne(queryWrapper);
|
|
|
+
|
|
|
+ if (qwExternalContact == null) {
|
|
|
+ return R.error("未查询到客户!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查客户是否在群中
|
|
|
+ boolean isInGroup = qwGroupChatUsers.stream()
|
|
|
+ .anyMatch(e -> e.getUserId() != null && e.getUserId().equals(qwExternalContact.getExternalUserId()));
|
|
|
+
|
|
|
+ if (!isInGroup) {
|
|
|
+ logger.error("客户不在群:{},里面:{}", qwGroupChat.getChatId(), qwExternalContact.getExternalUserId());
|
|
|
+ return R.error("客户不在群!");
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("外部联系人数据:{}", qwExternalContact);
|
|
|
+
|
|
|
+ // 判断外部联系人是否绑定userId
|
|
|
+ if (qwExternalContact.getFsUserId() != null) {
|
|
|
+ return handleBoundExternalContact(qwExternalContact, param, param.getQwExternalId());
|
|
|
+ } else {
|
|
|
+ return handleUnboundExternalContact(qwExternalContact, param, fsUser, param.getQwExternalId());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("处理群聊逻辑异常", e);
|
|
|
+ return R.error("处理群聊逻辑异常!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理外部联系人逻辑
|
|
|
+ */
|
|
|
+ private R handleExternalContactLogic(FsUserCourseVideoAddKfUParam param, FsUser fsUser) {
|
|
|
+ try {
|
|
|
+ Long qwExternalId = param.getQwExternalId();
|
|
|
+
|
|
|
+ if (qwExternalId == null) {
|
|
|
+ return R.error("外部联系人ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询外部联系人
|
|
|
+ QwExternalContact externalContact = qwExternalContactMapper.selectQwExternalContactById(qwExternalId);
|
|
|
+
|
|
|
+ // 如果查不出来客户信息,加好友
|
|
|
+ if (externalContact == null) {
|
|
|
+ return R.error("未查询到企微客户信息!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定公司码
|
|
|
+ addCompanyCompanyFsUser(param);
|
|
|
+
|
|
|
+ // 判断外部联系人是否绑定userId
|
|
|
+ if (externalContact.getFsUserId() != null) {
|
|
|
+ return handleBoundExternalContact(externalContact, param, qwExternalId);
|
|
|
+ } else {
|
|
|
+ return handleUnboundExternalContact(externalContact, param, fsUser, qwExternalId);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("处理外部联系人逻辑异常", e);
|
|
|
+ return R.error("系统异常,请稍后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void addCompanyCompanyFsUser(FsUserCourseVideoAddKfUParam param) {
|
|
|
+ //查询是否绑定
|
|
|
+ CompanyCompanyFsuser companyCompanyFsuser = companyCompanyFsuserMapper.getInfoByUserId(param.getUserId().toString());
|
|
|
+
|
|
|
+ if (companyCompanyFsuser!=null){
|
|
|
+ if (companyCompanyFsuser.getQwContactId() == null) {
|
|
|
+ //添加企业微信外部联系人
|
|
|
+ companyCompanyFsuser.setQwContactId(param.getQwExternalId());
|
|
|
+ companyCompanyFsuser.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ companyCompanyFsuserMapper.updateCompanyCompanyUser(companyCompanyFsuser);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //是邀请用户的课程才绑定
|
|
|
+ String json = configService.selectConfigByKey("app.config");
|
|
|
+ if (StringUtils.isNotBlank(json)) {
|
|
|
+ AppConfig config = JSONUtil.toBean(json, AppConfig.class);
|
|
|
+ if(config!=null){
|
|
|
+ List<FsUserCourseVideoVO> fsCourse = config.getFsCourse();
|
|
|
+ if (fsCourse != null && !fsCourse.isEmpty()) {
|
|
|
+ if (Objects.equals(fsCourse.get(0).getVideoId(), param.getVideoId())) {
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserById(Long.parseLong(param.getQwUserId()));
|
|
|
+ if (qwUser!=null){
|
|
|
+ //新增
|
|
|
+ CompanyCompanyFsuser insetCompanyFsUser = new CompanyCompanyFsuser();
|
|
|
+ insetCompanyFsUser.setUserId(param.getUserId());
|
|
|
+ insetCompanyFsUser.setCompanyId(qwUser.getCompanyId());
|
|
|
+ insetCompanyFsUser.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
+ insetCompanyFsUser.setQwContactId(param.getQwExternalId());
|
|
|
+ insetCompanyFsUser.setStatus(1);
|
|
|
+ insetCompanyFsUser.setCreateTime(DateUtils.getNowDate());
|
|
|
+ insetCompanyFsUser.setBindType(1); //看课绑定的
|
|
|
+ try {
|
|
|
+ companyCompanyFsuserMapper.insertCompanyCompanyUser(insetCompanyFsUser);
|
|
|
+ openIMService.checkAndImportFriendByDianBo(insetCompanyFsUser.getCompanyUserId(),insetCompanyFsUser.getUserId().toString(),StringUtils.isNotEmpty(param.getCorpId())?param.getCorpId():"",true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("新增客服绑定报错:{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理已绑定外部联系人
|
|
|
+ */
|
|
|
+ private R handleBoundExternalContact(QwExternalContact externalContact, FsUserCourseVideoAddKfUParam param,
|
|
|
+ Long qwExternalId) {
|
|
|
+ // 有客户有小程序id,但登录的小程序id和根据外部联系人id查出来的小程序id不一致
|
|
|
+ if (!externalContact.getFsUserId().equals(param.getUserId())) {
|
|
|
+ return R.error("已注册!");
|
|
|
+ }
|
|
|
+
|
|
|
+ iSopUserLogsInfoService.updateSopUserInfoByExternalId(qwExternalId, param.getUserId());
|
|
|
+
|
|
|
+ // 处理链接类型5
|
|
|
+ if (param.getLinkType() != null && param.getLinkType() == 5) {
|
|
|
+ FsCourseLink fsCourseLink = fsCourseLinkMapper.selectExpireLinkByQwExternalId(
|
|
|
+ param.getQwUserId(), param.getVideoId(), qwExternalId);
|
|
|
+ return R.error(566, "官方群发通用链接").put("courseLink", fsCourseLink);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理未绑定外部联系人
|
|
|
+ */
|
|
|
+ private R handleUnboundExternalContact(QwExternalContact externalContact, FsUserCourseVideoAddKfUParam param,
|
|
|
+ FsUser fsUser, Long qwExternalId) {
|
|
|
+ // 没绑定fsUser直接绑定fsUser
|
|
|
+ QwExternalContact contact = new QwExternalContact();
|
|
|
+ contact.setId(qwExternalId);
|
|
|
+ contact.setFsUserId(param.getUserId());
|
|
|
+
|
|
|
+ qwExternalContactMapper.updateQwExternalContact(contact);
|
|
|
+ iSopUserLogsInfoService.updateSopUserInfoByExternalId(qwExternalId, param.getUserId());
|
|
|
+
|
|
|
+ // 更新用户信息
|
|
|
+ if (fsUser != null) {
|
|
|
+ FsUser user = new FsUser();
|
|
|
+ if (fsUser.getNickName()!= null && fsUser.getNickName().contains("微信用户")) {
|
|
|
+ // 处理包含"微信用户"字样的逻辑
|
|
|
+ user.setNickName(externalContact.getName());
|
|
|
+ user.setAvatar(externalContact.getAvatar());
|
|
|
+ }
|
|
|
+ user.setUserId(fsUser.getUserId());
|
|
|
+ user.setIsAddQw(1);
|
|
|
+ fsUserMapper.updateFsUser(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理链接类型5
|
|
|
+ if (param.getLinkType() != null && param.getLinkType() == 5) {
|
|
|
+ FsCourseLink fsCourseLink = fsCourseLinkMapper.selectExpireLinkByQwExternalId(
|
|
|
+ param.getQwUserId(), param.getVideoId(), qwExternalId);
|
|
|
+ return R.error(566, "官方群发通用链接").put("courseLink", fsCourseLink);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|