|  | @@ -12,6 +12,7 @@ import com.fs.common.core.redis.RedisCache;
 | 
	
		
			
				|  |  |  import com.fs.common.utils.PubFun;
 | 
	
		
			
				|  |  |  import com.fs.common.utils.StringUtils;
 | 
	
		
			
				|  |  |  import com.fs.company.service.ICompanyConfigService;
 | 
	
		
			
				|  |  | +import com.fs.course.config.CourseConfig;
 | 
	
		
			
				|  |  |  import com.fs.course.domain.FsCourseSop;
 | 
	
		
			
				|  |  |  import com.fs.course.domain.FsCourseSopLogs;
 | 
	
		
			
				|  |  |  import com.fs.course.domain.FsCourseWatchLog;
 | 
	
	
		
			
				|  | @@ -90,6 +91,7 @@ import java.util.stream.Stream;
 | 
	
		
			
				|  |  |  public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactMapper, QwExternalContact> implements IQwExternalContactService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private static final String miniappRealLink = "/pages_course/video.html?course=";
 | 
	
		
			
				|  |  | +    private static final String registerLink = "/registerCourse/pages/index?qwExternalId=";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private QwExternalContactMapper qwExternalContactMapper;
 | 
	
	
		
			
				|  | @@ -133,6 +135,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private FsCourseLinkMapper fsCourseLinkMapper;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      QwAutoTagsMapper qwAutoTagsMapper;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
	
		
			
				|  | @@ -1207,6 +1210,11 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 | 
	
		
			
				|  |  |          QwContactWay wayId = null;
 | 
	
		
			
				|  |  |          SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("qw.config");
 | 
	
		
			
				|  |  |          QwConfig qwConfig = JSON.parseObject(sysConfig.getConfigValue(), QwConfig.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//        String json = sysConfigService.selectConfigByKey("course.config");
 | 
	
		
			
				|  |  | +//        QwConfig qwConfig = JSON.parseObject(json, QwConfig.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //先入客户
 | 
	
		
			
				|  |  |          QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalByExternalIdAndCompanyIdToIdAndFs(externalUserID, userID, corpId);
 | 
	
		
			
				|  |  |          boolean isNewQwExternalContact = qwExternalContact == null ? true : false;
 | 
	
	
		
			
				|  | @@ -1779,17 +1787,17 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 | 
	
		
			
				|  |  |              qwSopAutoByTags.setTagsIdsSelectList(combinedTagsList);
 | 
	
		
			
				|  |  |              qwSopAutoByTags.setSendType(2);
 | 
	
		
			
				|  |  |              List<QwSopRuleTimeVO> qwSopRuleTimeVOS = qwSopMapper.selectQwSopAutoByTagsByForeach(qwSopAutoByTags);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  | +                log.info("SOP任务:{}", qwSopRuleTimeVOS.size());
 | 
	
		
			
				|  |  |                  if (qwSopRuleTimeVOS != null && !qwSopRuleTimeVOS.isEmpty()) {
 | 
	
		
			
				|  |  |                      //SOP规则
 | 
	
		
			
				|  |  |                      qwSopRuleTimeTools(qwSopRuleTimeVOS, userID, qwUser, corpId, externalUserID, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  //aiSop任务
 | 
	
		
			
				|  |  | -//                List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 | 
	
		
			
				|  |  | -//                if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()){
 | 
	
		
			
				|  |  | -//                    qwAiSopRuleTimeTools(qwSopAiRuleTimeVOS,userID,qwUser,corpId,externalUserID,externalContact.getName(),contact);
 | 
	
		
			
				|  |  | -//                }
 | 
	
		
			
				|  |  | +                List<QwSopRuleTimeVO> qwSopAiRuleTimeVOS = qwSopMapper.selectQwAiSopAutoByTagsByForeach(qwSopAutoByTags);
 | 
	
		
			
				|  |  | +                if (qwSopAiRuleTimeVOS != null && !qwSopAiRuleTimeVOS.isEmpty()){
 | 
	
		
			
				|  |  | +                    qwAiSopRuleTimeTools(qwSopAiRuleTimeVOS,userID,qwUser,corpId,externalUserID,externalContact.getName(),contact);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              } catch (Exception e) {
 | 
	
		
			
				|  |  |                  logger.error("符合的标签-加入营期或新客对话 失败:" + qwSopAutoByTags + "|" + qwUser.getQwUserId() + "|" + externalUserID + "|" + e);
 | 
	
	
		
			
				|  | @@ -2252,13 +2260,14 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 | 
	
		
			
				|  |  |          SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("qw.config");
 | 
	
		
			
				|  |  |          List<SopUserLogsInfo> sopUserLogsInfos = sopUserLogsInfoMapper.repeatProject(PubFun.listToNewList(qwSopRuleTimeVOS, QwSopRuleTimeVO::getProject), externalUserID);
 | 
	
		
			
				|  |  |          Map<Integer, List<String>> collect = sopUserLogsInfos.stream().collect(Collectors.groupingBy(SopUserLogsInfo::getProject, Collectors.mapping(SopUserLogsInfo::getSopId, Collectors.toList())));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +        log.info("进入生成营期");
 | 
	
		
			
				|  |  |          // sop任务
 | 
	
		
			
				|  |  |          qwSopRuleTimeVOS.forEach(ruleTimeVO -> {
 | 
	
		
			
				|  |  |              if(sysConfig != null){
 | 
	
		
			
				|  |  |                  QwConfig qwConfig = JSON.parseObject(sysConfig.getConfigValue(), QwConfig.class);
 | 
	
		
			
				|  |  |                  if(qwConfig.isProject()){
 | 
	
		
			
				|  |  |                      List<String> sopIdList = collect.get(ruleTimeVO.getProject());
 | 
	
		
			
				|  |  | +                    log.info("是否多个项目:{}", sopIdList);
 | 
	
		
			
				|  |  |                      if(sopIdList.isEmpty()) return;
 | 
	
		
			
				|  |  |                      if(sopIdList.contains(ruleTimeVO.getId())) return;
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -2632,6 +2641,9 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 | 
	
		
			
				|  |  |              return attachments;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        String json = sysConfigService.selectConfigByKey("course.config");
 | 
	
		
			
				|  |  | +        CourseConfig config = JSON.parseObject(json, CourseConfig.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          attachments.forEach(att -> {
 | 
	
		
			
				|  |  |              // 生成短链的条件判断
 | 
	
		
			
				|  |  |              if ("link".equals(att.getMsgtype())
 | 
	
	
		
			
				|  | @@ -2639,30 +2651,41 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 | 
	
		
			
				|  |  |                      && !StringUtil.strIsNullOrEmpty(att.getLink().getVideoId())) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  try {
 | 
	
		
			
				|  |  | -                    FsCourseLinkCreateParam param = new FsCourseLinkCreateParam();
 | 
	
		
			
				|  |  | -                    param.setVideoId(Long.valueOf(att.getLink().getVideoId()));
 | 
	
		
			
				|  |  | -                    param.setQwUserId(String.valueOf(qwUser.getId()));
 | 
	
		
			
				|  |  | -                    param.setDays(att.getLink().getExpiresDays());
 | 
	
		
			
				|  |  | -                    param.setCorpId(corpId);
 | 
	
		
			
				|  |  | -                    param.setCourseId(Long.valueOf(att.getLink().getCourseId()));
 | 
	
		
			
				|  |  | -                    param.setCompanyUserId(qwUser.getCompanyUserId());
 | 
	
		
			
				|  |  | -                    param.setCompanyId(qwUser.getCompanyId());
 | 
	
		
			
				|  |  | -                    param.setQwExternalId(qwExternalId);
 | 
	
		
			
				|  |  | -                    param.setSendTime(new Date());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    // 调用服务生成短链
 | 
	
		
			
				|  |  | -                    R linkUrl = iFsCourseLinkService.createLinkUrlWc(param);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    if (linkUrl != null && linkUrl.get("url") != null) {
 | 
	
		
			
				|  |  | -                        att.getLink().setUrl(linkUrl.get("url").toString());
 | 
	
		
			
				|  |  | +                    //发课程
 | 
	
		
			
				|  |  | +                    if (att.getLink().getIsFixed()==0){
 | 
	
		
			
				|  |  | +                        FsCourseLinkCreateParam param = new FsCourseLinkCreateParam();
 | 
	
		
			
				|  |  | +                        param.setVideoId(Long.valueOf(att.getLink().getVideoId()));
 | 
	
		
			
				|  |  | +                        param.setQwUserId(String.valueOf(qwUser.getId()));
 | 
	
		
			
				|  |  | +                        param.setDays(att.getLink().getExpiresDays());
 | 
	
		
			
				|  |  | +                        param.setCorpId(corpId);
 | 
	
		
			
				|  |  | +                        param.setCourseId(Long.valueOf(att.getLink().getCourseId()));
 | 
	
		
			
				|  |  | +                        param.setCompanyUserId(qwUser.getCompanyUserId());
 | 
	
		
			
				|  |  | +                        param.setCompanyId(qwUser.getCompanyId());
 | 
	
		
			
				|  |  | +                        param.setQwExternalId(qwExternalId);
 | 
	
		
			
				|  |  | +                        param.setSendTime(new Date());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        // 调用服务生成短链
 | 
	
		
			
				|  |  | +                        R linkUrl = iFsCourseLinkService.createLinkUrlWc(param);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        if (linkUrl != null && linkUrl.get("url") != null) {
 | 
	
		
			
				|  |  | +                            att.getLink().setUrl(linkUrl.get("url").toString());
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        //生成观看记录
 | 
	
		
			
				|  |  | +                        addWatchLogIfNeeded(Integer.valueOf(att.getLink().getVideoId()),
 | 
	
		
			
				|  |  | +                                Integer.valueOf(att.getLink().getCourseId()),
 | 
	
		
			
				|  |  | +                                String.valueOf(qwUser.getId()),
 | 
	
		
			
				|  |  | +                                String.valueOf(qwUser.getCompanyUserId()),
 | 
	
		
			
				|  |  | +                                String.valueOf(qwUser.getCompanyId()),
 | 
	
		
			
				|  |  | +                                String.valueOf(qwExternalId));
 | 
	
		
			
				|  |  | +                    }else if (att.getLink().getIsFixed()==1){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        if (config != null) {
 | 
	
		
			
				|  |  | +                            att.getLink().setUrl(config.getRegisterDomainName()+registerLink+qwExternalId);
 | 
	
		
			
				|  |  | +                        }else {
 | 
	
		
			
				|  |  | +                            logger.error("企业配置信息为空:发送注册链接失败");
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    //生成观看记录
 | 
	
		
			
				|  |  | -                    addWatchLogIfNeeded(Integer.valueOf(att.getLink().getVideoId()),
 | 
	
		
			
				|  |  | -                            Integer.valueOf(att.getLink().getCourseId()),
 | 
	
		
			
				|  |  | -                            String.valueOf(qwUser.getId()),
 | 
	
		
			
				|  |  | -                            String.valueOf(qwUser.getCompanyUserId()),
 | 
	
		
			
				|  |  | -                            String.valueOf(qwUser.getCompanyId()),
 | 
	
		
			
				|  |  | -                            String.valueOf(qwExternalId));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  } catch (Exception e) {
 | 
	
		
			
				|  |  |                      logger.error("欢迎语生成短链失败:", e);
 | 
	
	
		
			
				|  | @@ -3914,7 +3937,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 | 
	
		
			
				|  |  |                                              qwSopAutoByTags.setSendType(2);
 | 
	
		
			
				|  |  |                                              List<QwSopRuleTimeVO> qwSopRuleTimeVOS = qwSopMapper.selectQwSopAutoByTagsByForeach(qwSopAutoByTags);
 | 
	
		
			
				|  |  |                                              logger.info("分时段里符合的标签-自动SOP条件:" + qwSopAutoByTags + "|" + qwUser.getQwUserId() + "|" + ext);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +                                            log.info("qwSopRuleTimeVOS:{}", qwSopRuleTimeVOS);
 | 
	
		
			
				|  |  |                                              if (qwSopRuleTimeVOS != null && !qwSopRuleTimeVOS.isEmpty()) {
 | 
	
		
			
				|  |  |                                                  //SOP规则
 | 
	
		
			
				|  |  |                                                  qwSopRuleTimeTools(qwSopRuleTimeVOS, qwUserId, qwUser, corpId, ext, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
 | 
	
	
		
			
				|  | @@ -4200,7 +4223,7 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
 | 
	
		
			
				|  |  |                                                  qwSopAutoByTags.setSendType(2);
 | 
	
		
			
				|  |  |                                                  List<QwSopRuleTimeVO> qwSopRuleTimeVOS = qwSopMapper.selectQwSopAutoByTagsByForeach(qwSopAutoByTags);
 | 
	
		
			
				|  |  |                                                  logger.info("分时段里符合的标签-自动SOP条件:" + qwSopAutoByTags + "|" + qwUser.getQwUserId() + "|" + ext);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +                                                log.info("qwSopRuleTimeVOS:{}", qwSopRuleTimeVOS);
 | 
	
		
			
				|  |  |                                                  if (qwSopRuleTimeVOS != null && !qwSopRuleTimeVOS.isEmpty()) {
 | 
	
		
			
				|  |  |                                                      //SOP规则
 | 
	
		
			
				|  |  |                                                      qwSopRuleTimeTools(qwSopRuleTimeVOS, qwUserId, qwUser, corpId, ext, externalContact.getName(), contact, currentDate, localTime, combinedTagsList);
 |