|
@@ -6,10 +6,12 @@ import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.company.service.ICompanyConfigService;
|
|
import com.fs.company.service.ICompanyConfigService;
|
|
|
|
|
+import com.fs.config.cloud.CloudHostProper;
|
|
|
import com.fs.course.domain.FsCourseLink;
|
|
import com.fs.course.domain.FsCourseLink;
|
|
|
import com.fs.course.domain.FsCourseRealLink;
|
|
import com.fs.course.domain.FsCourseRealLink;
|
|
|
import com.fs.course.mapper.FsCourseLinkMapper;
|
|
import com.fs.course.mapper.FsCourseLinkMapper;
|
|
|
import com.fs.course.param.FsCourseLinkCreateParam;
|
|
import com.fs.course.param.FsCourseLinkCreateParam;
|
|
|
|
|
+import com.fs.course.service.impl.FsUserCourseVideoServiceImpl;
|
|
|
import com.fs.qw.domain.*;
|
|
import com.fs.qw.domain.*;
|
|
|
import com.fs.qw.mapper.QwCompanyMapper;
|
|
import com.fs.qw.mapper.QwCompanyMapper;
|
|
|
import com.fs.qw.mapper.QwGroupMsgItemMapper;
|
|
import com.fs.qw.mapper.QwGroupMsgItemMapper;
|
|
@@ -33,6 +35,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
import java.io.BufferedInputStream;
|
|
@@ -59,6 +62,8 @@ public class QwGroupMsgServiceImpl implements IQwGroupMsgService
|
|
|
private static final Logger logger = LoggerFactory.getLogger(QwGroupMsgServiceImpl.class);
|
|
private static final Logger logger = LoggerFactory.getLogger(QwGroupMsgServiceImpl.class);
|
|
|
|
|
|
|
|
private static final String miniappRealLink = "/pages_course/video.html?course=";
|
|
private static final String miniappRealLink = "/pages_course/video.html?course=";
|
|
|
|
|
+ private static final String REAL_LINK_PREFIX = "/courseH5/pages/course/learning?course=";
|
|
|
|
|
+ private static final String SHORT_LINK_PREFIX = "/courseH5/pages/course/learning?s=";
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private QwGroupMsgMapper qwGroupMsgMapper;
|
|
private QwGroupMsgMapper qwGroupMsgMapper;
|
|
@@ -106,6 +111,9 @@ public class QwGroupMsgServiceImpl implements IQwGroupMsgService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IQwCompanyService iQwCompanyService;
|
|
private IQwCompanyService iQwCompanyService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CloudHostProper cloudHostProper;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询客户群发记录主
|
|
* 查询客户群发记录主
|
|
|
*
|
|
*
|
|
@@ -711,6 +719,233 @@ public class QwGroupMsgServiceImpl implements IQwGroupMsgService
|
|
|
|
|
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R sendSidebarOfficial(QwGroupMsgParam qwGroupMsgParam) throws Exception {
|
|
|
|
|
+ QwCompany qwCompany = qwCompanyMapper.selectQwCompanyByCorpId(qwGroupMsgParam.getCorpId());
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtil.strIsNullOrEmpty(qwGroupMsgParam.getSender())){
|
|
|
|
|
+ return R.error("请选择发送对象");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //发送消息组件表
|
|
|
|
|
+ QwMsgTemplate msgTemplate=new QwMsgTemplate();
|
|
|
|
|
+
|
|
|
|
|
+ //客户群发消息的附件记录表
|
|
|
|
|
+ QwGroupMsgItem qwGroupMsgItem=new QwGroupMsgItem();
|
|
|
|
|
+
|
|
|
|
|
+ //客户群发记录主表
|
|
|
|
|
+ QwGroupMsg qwGroupMsg=new QwGroupMsg();
|
|
|
|
|
+
|
|
|
|
|
+ qwGroupMsg.setCorpId(qwGroupMsgParam.getCorpId());
|
|
|
|
|
+
|
|
|
|
|
+ //主表存/任务类型
|
|
|
|
|
+ qwGroupMsg.setChatType(qwGroupMsgParam.getChatType());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ QwUser qwUser = qwExternalContactService.getQwUserByRedis(qwGroupMsgParam.getCorpId().trim(), qwGroupMsgParam.getSender().trim());
|
|
|
|
|
+
|
|
|
|
|
+ if (qwUser==null||qwUser.getCompanyId()==null||qwUser.getCompanyUserId()==null){
|
|
|
|
|
+ return R.error("员工未绑定 销售公司 或 销售 请先绑定:"+qwGroupMsgParam.getSender()+"|"+qwGroupMsgParam.getCorpId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtil.strIsNullOrEmpty(qwCompany.getMiniAppId())){
|
|
|
|
|
+ return R.error("该主体没有绑定 小程序,请联系管理员");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String mediaId =(String)redisCache.getCacheObject("miniprogram:"+qwGroupMsgParam.getCorpId()+":"+qwGroupMsgParam.getCourseId());
|
|
|
|
|
+ if (StringUtil.strIsNullOrEmpty(mediaId)){
|
|
|
|
|
+ return R.error("该课程封面未上传 至企业微信,请联系管理员");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String linkByMiniApp = createLinkByMiniAppGeneral(new Date(), qwGroupMsgParam.getCourseId(), qwGroupMsgParam.getVideoId(), qwUser, 0L,2,null,1);
|
|
|
|
|
+
|
|
|
|
|
+ msgTemplate.setSender(qwGroupMsgParam.getSender().trim());
|
|
|
|
|
+ msgTemplate.setMiniprogramAppid(qwCompany.getMiniAppId());
|
|
|
|
|
+ msgTemplate.setMiniprogramTitle(qwGroupMsgParam.getMiniprogramTitle());
|
|
|
|
|
+ msgTemplate.setMiniprogramPicMediaId(mediaId);
|
|
|
|
|
+ msgTemplate.setMiniprogramPage(linkByMiniApp);
|
|
|
|
|
+
|
|
|
|
|
+ qwGroupMsgItem.setMsgType(3);
|
|
|
|
|
+ qwGroupMsgItem.setMiniprogramTitle(qwGroupMsgParam.getMiniprogramTitle());
|
|
|
|
|
+ qwGroupMsgItem.setMiniprogramAppid(qwCompany.getMiniAppId());
|
|
|
|
|
+ qwGroupMsgItem.setMiniprogramPicUrl(qwGroupMsgParam.getMiniprogramPicUrl());
|
|
|
|
|
+ qwGroupMsgItem.setMiniprogramPicMediaId(mediaId);
|
|
|
|
|
+ qwGroupMsgItem.setMiniprogramPage(linkByMiniApp);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //发送这条消息文本的成员集合
|
|
|
|
|
+ qwGroupMsg.setSender(qwGroupMsgParam.getSender().trim());
|
|
|
|
|
+ qwGroupMsg.setAllowSelect(qwGroupMsgParam.getAllowSelect());
|
|
|
|
|
+ qwGroupMsg.setTextContent(qwGroupMsgParam.getTextContent());
|
|
|
|
|
+ qwGroupMsg.setCreateName(qwGroupMsgParam.getCreateName());
|
|
|
|
|
+ qwGroupMsg.setGroupChatNames(qwGroupMsgParam.getGroupChatNames());
|
|
|
|
|
+ qwGroupMsg.setSelectType(qwGroupMsgParam.getSelectType());
|
|
|
|
|
+ //筛选出客户
|
|
|
|
|
+ QwCountCustomerParam qwCountCustomerParam = new QwCountCustomerParam();
|
|
|
|
|
+
|
|
|
|
|
+ ArrayList<String> userIdsList=new ArrayList<>();
|
|
|
|
|
+ userIdsList.add(qwGroupMsgParam.getSender().trim());
|
|
|
|
|
+ qwCountCustomerParam.setUserIdsSelectList(userIdsList);
|
|
|
|
|
+
|
|
|
|
|
+ qwCountCustomerParam.setSelectType(qwGroupMsgParam.getSelectType());
|
|
|
|
|
+ qwCountCustomerParam.setGender(qwGroupMsgParam.getGender());
|
|
|
|
|
+ qwCountCustomerParam.setGroupChatSelectList(qwGroupMsgParam.getGroupChatSelectList());
|
|
|
|
|
+ qwCountCustomerParam.setTimeScreenCharge(qwGroupMsgParam.getTimeScreenCharge());
|
|
|
|
|
+ qwCountCustomerParam.setTagsIdsSelectList(qwGroupMsgParam.getTagsIdsSelectList());
|
|
|
|
|
+ qwCountCustomerParam.setOutTagsIdsSelectList(qwGroupMsgParam.getOutTagsIdsSelectList());
|
|
|
|
|
+
|
|
|
|
|
+ //根据 条件 筛选出预计发送的客户id列表
|
|
|
|
|
+ ArrayList<String> customerList = qwExternalContactService.selectQwGroupMsgExpectCustomerList(qwCountCustomerParam, qwCompany.getCorpId());
|
|
|
|
|
+
|
|
|
|
|
+ qwGroupMsg.setToUserNum(customerList.size());
|
|
|
|
|
+ qwGroupMsg.setFilterCustomers(JSON.toJSONString(qwCountCustomerParam));
|
|
|
|
|
+
|
|
|
|
|
+ //客户列表
|
|
|
|
|
+ msgTemplate.setExternalUseridList(customerList);
|
|
|
|
|
+
|
|
|
|
|
+ //发送消息文本组装
|
|
|
|
|
+ //群发任务类型()
|
|
|
|
|
+ msgTemplate.setChatType(qwGroupMsgParam.getChatType());
|
|
|
|
|
+
|
|
|
|
|
+ msgTemplate.setAllowSelect(qwGroupMsgParam.getAllowSelect() == 1 ? true : false);
|
|
|
|
|
+ msgTemplate.setTextContent(qwGroupMsgParam.getTextContent());
|
|
|
|
|
+ msgTemplate.setType(qwGroupMsgParam.getMsgType());
|
|
|
|
|
+
|
|
|
|
|
+ QwAddMsgTemplateResult qwAddMsgTemplateResult = qwApiService.addMsgTemplate(msgTemplate, qwGroupMsgParam.getCorpId());
|
|
|
|
|
+
|
|
|
|
|
+ qwGroupMsg.setMsgid(qwAddMsgTemplateResult.getMsgId() == null ? null : qwAddMsgTemplateResult.getMsgId());
|
|
|
|
|
+
|
|
|
|
|
+ if (qwAddMsgTemplateResult.getErrCode() != 0 && qwAddMsgTemplateResult.getErrCode() != 41063) {
|
|
|
|
|
+
|
|
|
|
|
+ //发送失败 主表做记录
|
|
|
|
|
+ qwGroupMsg.setIsSend(0);
|
|
|
|
|
+ qwGroupMsg.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
+ //主表做记录
|
|
|
|
|
+ insertQwGroupMsgSinger(qwGroupMsg, qwGroupMsgItem, qwGroupMsgParam.getCorpId(), qwCompany.getId(), qwAddMsgTemplateResult);
|
|
|
|
|
+
|
|
|
|
|
+ logger.error("消息发送失败:" + qwAddMsgTemplateResult.getErrMsg());
|
|
|
|
|
+ return R.error("消息发送失败:" + qwAddMsgTemplateResult.getErrMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ qwGroupMsg.setFromUserNum(1);
|
|
|
|
|
+ qwGroupMsg.setIsSend(1);
|
|
|
|
|
+ qwGroupMsg.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
+
|
|
|
|
|
+ //主表做记录
|
|
|
|
|
+ int i = qwGroupMsgMapper.insertQwGroupMsg(qwGroupMsg);
|
|
|
|
|
+ if (i > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ qwGroupMsgItem.setGroupMsgId(qwGroupMsg.getId());
|
|
|
|
|
+ qwGroupMsgItem.setMsgId(qwAddMsgTemplateResult.getMsgId());
|
|
|
|
|
+ qwGroupMsgItem.setCorpId(qwGroupMsgParam.getCorpId());
|
|
|
|
|
+ qwGroupMsgItem.setCompanyId(qwCompany.getId());
|
|
|
|
|
+ //附件做记录
|
|
|
|
|
+ int i1 = qwGroupMsgItemMapper.insertQwGroupMsgItem(qwGroupMsgItem);
|
|
|
|
|
+
|
|
|
|
|
+ if (i1 <= 0) {
|
|
|
|
|
+ logger.error("录入入群发消息附件表失败");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ List<QwGroupMsgUser> qwGroupMsgUserList=new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (String excId : customerList) {
|
|
|
|
|
+
|
|
|
|
|
+ QwGroupMsgUser ext=new QwGroupMsgUser();
|
|
|
|
|
+ ext.setUserId(qwGroupMsgParam.getSender().trim());
|
|
|
|
|
+ ext.setStatus(0);
|
|
|
|
|
+ ext.setMsgId(qwAddMsgTemplateResult.getMsgId());
|
|
|
|
|
+ ext.setChatType(qwGroupMsgParam.getChatType());
|
|
|
|
|
+ ext.setCorpId(qwGroupMsgParam.getCorpId());
|
|
|
|
|
+ ext.setCompanyId(qwCompany.getId());
|
|
|
|
|
+ ext.setGroupMsgId(qwGroupMsg.getId());
|
|
|
|
|
+ ext.setExternalUserid(excId);
|
|
|
|
|
+ ext.setSendStatus(0);
|
|
|
|
|
+ ext.setSendTime(0L);
|
|
|
|
|
+ qwGroupMsgUserList.add(ext);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ boolean isSuccess = qwGroupMsgUserService.saveBatch(qwGroupMsgUserList,500);
|
|
|
|
|
+ if (!isSuccess) {
|
|
|
|
|
+ logger.error("批量录入群发成员发送任务及执行结果反馈记录表失败41063");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 插入失败的处理逻辑
|
|
|
|
|
+ logger.error("录入入群发消息主表失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String createLinkByMiniAppGeneral(Date sendTime, Long courseId, Long videoId,
|
|
|
|
|
+ QwUser qwUser, Long externalId,int type,String domainName,Integer isRoom) {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ FsCourseLink link = new FsCourseLink();
|
|
|
|
|
+ link.setCompanyId(qwUser.getCompanyId());
|
|
|
|
|
+ link.setQwUserId(qwUser.getId());
|
|
|
|
|
+ link.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
|
+ link.setVideoId(videoId);
|
|
|
|
|
+ link.setCorpId(qwUser.getCorpId());
|
|
|
|
|
+ link.setCourseId(courseId);
|
|
|
|
|
+ link.setQwExternalId(externalId);
|
|
|
|
|
+ link.setIsRoom(isRoom);
|
|
|
|
|
+ if (type == 1) {
|
|
|
|
|
+ link.setLinkType(0);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ link.setLinkType(3);
|
|
|
|
|
+ }
|
|
|
|
|
+ link.setProjectCode(cloudHostProper.getProjectCode());
|
|
|
|
|
+
|
|
|
|
|
+ String randomString = generateRandomStringWithLock();
|
|
|
|
|
+ if (StringUtil.strIsNullOrEmpty(randomString)){
|
|
|
|
|
+ link.setLink(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ link.setLink(randomString);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ link.setCreateTime(sendTime);
|
|
|
|
|
+ link.setProjectCode(cloudHostProper.getProjectCode());
|
|
|
|
|
+
|
|
|
|
|
+ FsCourseRealLink courseMap = new FsCourseRealLink();
|
|
|
|
|
+ BeanUtils.copyProperties(link,courseMap);
|
|
|
|
|
+
|
|
|
|
|
+ String courseJson = JSON.toJSONString(courseMap);
|
|
|
|
|
+
|
|
|
|
|
+ String realLinkFull = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (type == 1) {
|
|
|
|
|
+ realLinkFull = REAL_LINK_PREFIX + courseJson;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ realLinkFull = miniappRealLink + courseJson;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ link.setRealLink(realLinkFull);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 使用 Java 8 时间 API 计算过期时间
|
|
|
|
|
+ LocalDateTime sendDateTime = sendTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
|
|
+ LocalDateTime expireDateTime = sendDateTime.plusDays(0);
|
|
|
|
|
+ expireDateTime = expireDateTime.toLocalDate().atTime(23, 59, 59);
|
|
|
|
|
+ Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
+ link.setUpdateTime(updateTime);
|
|
|
|
|
+
|
|
|
|
|
+ //存短链-
|
|
|
|
|
+ fsCourseLinkMapper.insertFsCourseLink(link);
|
|
|
|
|
+
|
|
|
|
|
+ if (type==1){
|
|
|
|
|
+ return domainName + SHORT_LINK_PREFIX + link.getLink();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return link.getRealLink();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//生成小程序链接 通用链接
|
|
//生成小程序链接 通用链接
|
|
|
private String createLinkByMiniApp(Date sendTime, Long courseId, Long videoId,
|
|
private String createLinkByMiniApp(Date sendTime, Long courseId, Long videoId,
|
|
|
QwUser qwUser, Long externalId, Integer isRoom){
|
|
QwUser qwUser, Long externalId, Integer isRoom){
|