|
|
@@ -0,0 +1,158 @@
|
|
|
+package com.fs.live.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.utils.CloudHostUtils;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
+import com.fs.course.config.CourseConfig;
|
|
|
+import com.fs.course.domain.FsCourseLink;
|
|
|
+import com.fs.course.mapper.FsCourseLinkMapper;
|
|
|
+import com.fs.course.service.impl.FsUserCourseServiceImpl;
|
|
|
+import com.fs.live.domain.Live;
|
|
|
+import com.fs.live.param.FsLiveSortLinkParam;
|
|
|
+import com.fs.live.service.ILiveService;
|
|
|
+import com.fs.live.service.ILiveSortLinkService;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.fs.voice.utils.StringUtil;
|
|
|
+
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import static com.fs.course.utils.LinkUtil.generateRandomStringWithLock;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 直播短链 Service 实现
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class LiveSortLinkServiceImpl implements ILiveSortLinkService {
|
|
|
+
|
|
|
+ private static final String APP_LIVE_REAL_LINK =
|
|
|
+ "/pages_live/living?liveId=%s&companyId=%s&companyUserId=%s";
|
|
|
+ private static final String APP_LIVE_SHORT_LINK = "/courseH5/pages_live/living?s=";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+ @Autowired
|
|
|
+ private FsCourseLinkMapper fsCourseLinkMapper;
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private ILiveService liveService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R createLiveSortLink(FsLiveSortLinkParam param) {
|
|
|
+ if (param.getLiveId() == null) {
|
|
|
+ return R.error("直播间id不能为空");
|
|
|
+ }
|
|
|
+ Live live = liveService.selectLiveByLiveId(param.getLiveId());
|
|
|
+ if (live == null) {
|
|
|
+ return R.error("直播间不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
+
|
|
|
+ FsCourseLink link = new FsCourseLink();
|
|
|
+ link.setCompanyId(param.getCompanyId());
|
|
|
+ link.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ link.setLiveId(param.getLiveId());
|
|
|
+ link.setCorpId(param.getCorpId());
|
|
|
+ link.setLinkType(0);
|
|
|
+ link.setIsRoom(0);
|
|
|
+ String random = generateRandomStringWithLock();
|
|
|
+ if (StringUtil.strIsNullOrEmpty(random)) {
|
|
|
+ link.setLink(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ } else {
|
|
|
+ link.setLink(random);
|
|
|
+ }
|
|
|
+ link.setCreateTime(new Date());
|
|
|
+
|
|
|
+ String realLinkPath = String.format(APP_LIVE_REAL_LINK,
|
|
|
+ param.getLiveId(), param.getCompanyId(), param.getCompanyUserId());
|
|
|
+ link.setRealLink(realLinkPath);
|
|
|
+ link.setUpdateTime(getExpireTime(param.getEffectiveDuration(), config, link.getCreateTime()).getTime());
|
|
|
+
|
|
|
+ int i = fsCourseLinkMapper.insertFsCourseLink(link);
|
|
|
+ if (i <= 0) {
|
|
|
+ return R.error("生成链接失败!");
|
|
|
+ }
|
|
|
+ String domainName = getDomainName(param.getCompanyUserId(), config);
|
|
|
+ String sortLink = domainName + realLinkPath;
|
|
|
+ return R.ok().put("url", sortLink).put("link", random).put("linkId", link.getLinkId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R createAppLiveSortLink(FsLiveSortLinkParam param) {
|
|
|
+ if (param.getLiveId() == null) {
|
|
|
+ return R.error("直播间id不能为空");
|
|
|
+ }
|
|
|
+ Live live = liveService.selectLiveByLiveId(param.getLiveId());
|
|
|
+ if (live == null) {
|
|
|
+ return R.error("直播间不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
+ String random = FsUserCourseServiceImpl.generateRandomString();
|
|
|
+
|
|
|
+ FsCourseLink link = new FsCourseLink();
|
|
|
+ link.setCompanyId(param.getCompanyId());
|
|
|
+ link.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ link.setLiveId(param.getLiveId());
|
|
|
+ link.setCorpId(param.getCorpId());
|
|
|
+ link.setLinkType(0);
|
|
|
+ link.setIsRoom(0);
|
|
|
+ link.setLink(random);
|
|
|
+
|
|
|
+ String realLinkPath = String.format(APP_LIVE_REAL_LINK,
|
|
|
+ param.getLiveId(), param.getCompanyId(), param.getCompanyUserId());
|
|
|
+ link.setRealLink(realLinkPath);
|
|
|
+ link.setCreateTime(new Date());
|
|
|
+ link.setUpdateTime(getExpireTime(param.getEffectiveDuration(), config, link.getCreateTime()).getTime());
|
|
|
+
|
|
|
+ int i = fsCourseLinkMapper.insertFsCourseLink(link);
|
|
|
+ if (i > 0) {
|
|
|
+ String domainName = getDomainName(param.getCompanyUserId(), config);
|
|
|
+ if (CloudHostUtils.hasCloudHostName("中康", "蒙牛", "鸿森堂", "北京卓美")) {
|
|
|
+ String sortLink = domainName + realLinkPath;
|
|
|
+ return R.ok().put("url", sortLink).put("link", random).put("linkId", link.getLinkId());
|
|
|
+ }
|
|
|
+ String sortLink = domainName + APP_LIVE_SHORT_LINK + link.getLink();
|
|
|
+ return R.ok().put("url", sortLink).put("link", random).put("linkId", link.getLinkId());
|
|
|
+ }
|
|
|
+ return R.error("生成链接失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getDomainName(Long companyUserId, CourseConfig config) {
|
|
|
+ String domainName = companyUserMapper.selectDomainByUserId(companyUserId);
|
|
|
+ if (StringUtils.isEmpty(domainName)) {
|
|
|
+ domainName = config.getRealLinkDomainName();
|
|
|
+ }
|
|
|
+ return domainName;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Calendar getExpireTime(Integer effectiveDuration, CourseConfig config, Date createTime) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ if (effectiveDuration == null || effectiveDuration == 0) {
|
|
|
+ Integer expireDays = config.getVideoLinkExpireDate() != null ? config.getVideoLinkExpireDate() : 1;
|
|
|
+ calendar.setTime(createTime);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, expireDays);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ } else {
|
|
|
+ calendar.setTime(createTime);
|
|
|
+ calendar.add(Calendar.MINUTE, effectiveDuration);
|
|
|
+ }
|
|
|
+ return calendar;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|