|
|
@@ -1,5 +1,6 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -52,13 +53,8 @@ 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.qw.domain.QwAppMiniProgramRelation;
|
|
|
-import com.fs.qw.domain.QwCompany;
|
|
|
-import com.fs.qw.domain.QwExternalContact;
|
|
|
-import com.fs.qw.domain.QwUser;
|
|
|
-import com.fs.qw.mapper.QwAppMiniProgramRelationMapper;
|
|
|
-import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
-import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.qw.domain.*;
|
|
|
+import com.fs.qw.mapper.*;
|
|
|
import com.fs.qw.service.IQwCompanyService;
|
|
|
import com.fs.qw.service.IQwExternalContactService;
|
|
|
import com.fs.qwApi.Result.QwAddContactWayResult;
|
|
|
@@ -134,6 +130,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
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=";
|
|
|
+ private static final String appActivityLink = "/pages_course/luckybag.html?link=";
|
|
|
@Autowired
|
|
|
ICompanyService companyService;
|
|
|
@Autowired
|
|
|
@@ -257,6 +254,12 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
@Autowired
|
|
|
private WxOpenProperties openProperties;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BindPhoneRedPacketRecordMapper bindPhoneRedPacketRecordMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedPacketMapper redPacketMapper;
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -2996,6 +2999,195 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R createSqMiniLink(FsCourseLinkMiniParam param) {
|
|
|
+ try {
|
|
|
+ QwUser qwUser = qwExternalContactService.getQwUserByRedis(param.getCorpId().trim(), param.getQwUserId().trim());
|
|
|
+
|
|
|
+ if (qwUser==null||qwUser.getCompanyId()==null||qwUser.getCompanyUserId()==null){
|
|
|
+ return R.error("员工未绑定 客服公司 或 客服 请先绑定");
|
|
|
+ }
|
|
|
+
|
|
|
+ QwCompany qwCompany = iQwCompanyService.getQwCompanyByRedis(param.getCorpId());
|
|
|
+
|
|
|
+ if (qwCompany == null ) {
|
|
|
+ return R.error().put("msg","企业不存在,请联系管理员");
|
|
|
+ }
|
|
|
+ String course = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSON.parseObject(course, CourseConfig.class);
|
|
|
+ LocalDateTime sendDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ LocalDateTime expireDateTime = sendDateTime.plusDays(config.getVideoLinkExpireDate() - 1);
|
|
|
+ expireDateTime = expireDateTime.toLocalDate().atTime(23, 59, 59);
|
|
|
+ Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+
|
|
|
+ FsCourseLink link = createFsCourseLink(param.getCorpId(), new Date(), qwUser.getId(),
|
|
|
+ String.valueOf(qwUser.getCompanyUserId()), String.valueOf(qwUser.getCompanyId()), param.getExternalUserId(), 3,param.getChatId());
|
|
|
+ link.setUpdateTime(new Date());
|
|
|
+ FsCourseRealLink courseMap = new FsCourseRealLink();
|
|
|
+ BeanUtils.copyProperties(link, courseMap);
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey("phoneRedPacket.config");
|
|
|
+ Map<String, Object> luckyBagConfig = JSON.parseObject(json, Map.class);
|
|
|
+ Object miniprogramPicUrl = luckyBagConfig.get("miniprogramPicUrl");
|
|
|
+ courseMap.setQwExternalId(param.getExternalUserId());
|
|
|
+
|
|
|
+ JSONObject news = new JSONObject(true);
|
|
|
+ if(miniprogramPicUrl != null){
|
|
|
+ news.put("miniprogramPicUrl", miniprogramPicUrl.toString());
|
|
|
+ }
|
|
|
+ Long businessId = addRedPacketCollectRecord(param.getPhoneRedPacketId(), miniprogramPicUrl.toString(), qwUser, param.getFsUserId(), updateTime, String.valueOf(qwUser.getCompanyUserId()), String.valueOf(qwUser.getCompanyId()));
|
|
|
+ courseMap.setBusinessId(String.valueOf(businessId));
|
|
|
+ String realLinkFull = appActivityLink + JSON.toJSONString(courseMap);
|
|
|
+ link.setRealLink(realLinkFull);
|
|
|
+ //存短链-
|
|
|
+ fsCourseLinkMapper.insertFsCourseLink(link);
|
|
|
+ news.put("businessId", String.valueOf(businessId));
|
|
|
+ news.put("externalUserId", param.getExternalUserId());
|
|
|
+ news.put("miniprogramAppid", qwCompany.getMiniAppId());
|
|
|
+ news.put("miniprogramTitle", "手机授权");
|
|
|
+ news.put("miniprogramPage", link.getRealLink());
|
|
|
+
|
|
|
+ return R.ok().put("data",news);
|
|
|
+ } catch (BeansException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return R.error("发放授权红包失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加授权手机号红包发放记录、领取记录
|
|
|
+ *
|
|
|
+ * @param companyId
|
|
|
+ * @param qwUser
|
|
|
+ * @param sendTime
|
|
|
+ * @param companyUserId
|
|
|
+ */
|
|
|
+ private Long addRedPacketCollectRecord(Long redPacketId, String miniprogramPicUrl,
|
|
|
+ QwUser qwUser,
|
|
|
+ Long userId,
|
|
|
+ Date sendTime,
|
|
|
+ String companyUserId,
|
|
|
+ String companyId) {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(companyId) || StringUtils.isEmpty(companyUserId)) {
|
|
|
+ log.error("公司ID或用户ID为空 [companyId:{}, companyUserId:{}]", companyId, companyUserId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证授权手机号红包ID
|
|
|
+ if (redPacketId == null) {
|
|
|
+ log.error("授权手机号红包ID为空");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ RedPacket redPacket = redPacketMapper.selectRedPacketById(redPacketId);
|
|
|
+ // 查询授权手机号红包信息
|
|
|
+ if (redPacket == null) {
|
|
|
+ log.error("未找到对应的授权手机号红包信息 [luckyBagId:{}]", redPacketId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查授权手机号红包状态
|
|
|
+ if (redPacket.getStatus().equals("0")) {
|
|
|
+ log.error("授权手机号红包被禁用 [luckyBagId:{}]", redPacketId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 查询公司信息
|
|
|
+ Company company = companyMapper.selectCompanyById(Long.valueOf(companyId));
|
|
|
+ if (company == null) {
|
|
|
+ log.error("未找到对应的公司信息 [companyId:{}]", companyId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 构建授权手机号红包记录
|
|
|
+ BindPhoneRedPacketRecord bindPhoneRedPacketRecord = buildRePacketRecord(redPacketId, miniprogramPicUrl,qwUser,userId,sendTime,
|
|
|
+ companyUserId, companyId, company, redPacket);
|
|
|
+ bindPhoneRedPacketRecord.setSendTime(new Date());
|
|
|
+ // 插入记录并返回ID
|
|
|
+ int result = bindPhoneRedPacketRecordMapper.insertBindPhoneRedPacketRecord(bindPhoneRedPacketRecord);
|
|
|
+ if (result <= 0) {
|
|
|
+ log.error("授权手机号红包记录插入失败 [luckyBagId:{}]", redPacketId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回新增记录的ID
|
|
|
+ Long recordId = bindPhoneRedPacketRecord.getId();
|
|
|
+ if (recordId == null) {
|
|
|
+ log.error("授权手机号红包记录插入成功但未返回ID [luckyBagId:{}]", redPacketId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("授权手机号红包记录添加成功 [recordId:{}, luckyBagId:{}]", recordId, redPacketId);
|
|
|
+ return recordId;
|
|
|
+
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.error("ID转换失败 [companyId:{}, companyUserId:{}]", companyId, companyUserId, e);
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("ID:" + (redPacketId != null ? redPacketId : "unknown") + "-添加授权手机号红包记录失败", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建授权手机号红包记录对象
|
|
|
+ */
|
|
|
+ private BindPhoneRedPacketRecord buildRePacketRecord(Long redPacketId,String miniprogramPage,
|
|
|
+ QwUser qwUser,
|
|
|
+ Long userId,
|
|
|
+ Date sendTime,
|
|
|
+ String companyUserId,
|
|
|
+ String companyId,
|
|
|
+ Company company,
|
|
|
+ RedPacket redPacket) {
|
|
|
+ BindPhoneRedPacketRecord record = new BindPhoneRedPacketRecord();
|
|
|
+ record.setQwUserId(qwUser.getQwUserId());
|
|
|
+ record.setQwUserName(qwUser.getQwUserName());
|
|
|
+ record.setRedPacketId(redPacketId);
|
|
|
+ record.setCollectType("0");
|
|
|
+ record.setSendTime(new Date());
|
|
|
+ record.setCompanyId(Long.valueOf(companyId));
|
|
|
+ record.setUserId(userId);
|
|
|
+ if (ObjectUtil.isNotEmpty(userId)){
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserByUserId(userId);
|
|
|
+ record.setUserName(ObjectUtil.isNotEmpty(fsUser)?fsUser.getNickName():null);
|
|
|
+ }
|
|
|
+ record.setCompanyName(company.getCompanyName());
|
|
|
+ record.setCompanyUserId(Long.valueOf(companyUserId));
|
|
|
+ record.setSendLink(miniprogramPage);
|
|
|
+ record.setRewardType(2L);
|
|
|
+ record.setAmount(redPacket.getAmount());
|
|
|
+
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FsCourseLink createFsCourseLink(String corpId, Date sendTime, Long qwUserId,
|
|
|
+ String companyUserId, String companyId, Long externalId, Integer type,String chatId) {
|
|
|
+ // 手动创建 FsCourseLink 对象,避免使用 BeanUtils.copyProperties
|
|
|
+ FsCourseLink link = new FsCourseLink();
|
|
|
+ link.setCompanyId(Long.parseLong(companyId));
|
|
|
+ link.setQwUserId(qwUserId);
|
|
|
+ link.setCompanyUserId(Long.parseLong(companyUserId));
|
|
|
+ link.setCorpId(corpId);
|
|
|
+ link.setChatId(chatId);
|
|
|
+ link.setQwExternalId(externalId);
|
|
|
+ link.setLinkType(type); //小程序
|
|
|
+ link.setUNo(UUID.randomUUID().toString());
|
|
|
+ String randomString = generateRandomStringWithLock();
|
|
|
+ if (StringUtil.strIsNullOrEmpty(randomString)) {
|
|
|
+ link.setLink(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ } else {
|
|
|
+ link.setLink(randomString);
|
|
|
+ }
|
|
|
+
|
|
|
+ link.setCreateTime(sendTime);
|
|
|
+
|
|
|
+ return link;
|
|
|
+ }
|
|
|
+
|
|
|
private R executeAppReward(FsCourseSendRewardUParam param){
|
|
|
//查询可提现
|
|
|
Long userId = param.getUserId();
|