|
|
@@ -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.JSONArray;
|
|
|
@@ -9,6 +10,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fs.common.BeanCopyUtils;
|
|
|
import com.fs.common.constant.FsConstants;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
@@ -52,6 +56,7 @@ import com.fs.his.config.AppConfig;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserIntegralLogs;
|
|
|
import com.fs.his.domain.FsUserWx;
|
|
|
+import com.fs.his.mapper.FsPackageMapper;
|
|
|
import com.fs.his.mapper.FsUserIntegralLogsMapper;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.param.WxSendRedPacketParam;
|
|
|
@@ -60,22 +65,22 @@ import com.fs.his.service.IFsUserIntegralLogsService;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.service.IFsUserWxService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
+import com.fs.his.vo.FsPackageListVO;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
import com.fs.im.service.OpenIMService;
|
|
|
import com.fs.qw.domain.*;
|
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
import com.fs.qw.domain.QwExternalContact;
|
|
|
import com.fs.qw.domain.QwUser;
|
|
|
-import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
-import com.fs.qw.mapper.QwGroupChatMapper;
|
|
|
-import com.fs.qw.mapper.QwGroupChatUserMapper;
|
|
|
-import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.qw.mapper.*;
|
|
|
import com.fs.qw.param.FsUserCourseRedPageParam;
|
|
|
import com.fs.qw.service.IQwCompanyService;
|
|
|
import com.fs.qw.service.IQwExternalContactService;
|
|
|
+import com.fs.qw.vo.QwSopCourseFinishTempSetting;
|
|
|
import com.fs.qwApi.Result.QwAddContactWayResult;
|
|
|
import com.fs.qwApi.param.QwAddContactWayParam;
|
|
|
import com.fs.qwApi.service.QwApiService;
|
|
|
+import com.fs.sop.domain.QwSopLogs;
|
|
|
import com.fs.sop.domain.SopUserLogsInfo;
|
|
|
import com.fs.sop.mapper.SopUserLogsInfoMapper;
|
|
|
import com.fs.sop.service.ISopUserLogsInfoService;
|
|
|
@@ -130,6 +135,10 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
@Autowired
|
|
|
private OpenIMService openIMService;
|
|
|
@Autowired
|
|
|
+ private LuckyBagMapper luckyBagMapper;
|
|
|
+ @Autowired
|
|
|
+ private LuckyBagCollectRecordMapper luckyBagCollectRecordMapper;
|
|
|
+ @Autowired
|
|
|
private CompanyCompanyFsuserMapper companyCompanyFsuserMapper;
|
|
|
private static final Logger logger = LoggerFactory.getLogger(FsUserCourseVideoServiceImpl.class);
|
|
|
|
|
|
@@ -254,6 +263,9 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
@Autowired
|
|
|
private IFsCourseLinkService linkService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsPackageMapper fsPackageMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查询课堂视频
|
|
|
@@ -4447,6 +4459,146 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R registerQwFsUserFinish(FsUserCourseVideoAddKfUParam param) {// 查询用户
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+
|
|
|
+ // 不能反401 前端会絮乱
|
|
|
+ // 用户不存在唤起重新授权
|
|
|
+ if (fsUser == null) {
|
|
|
+ return R.error("用户不存在");
|
|
|
+ }
|
|
|
+// if (StringUtils.isNotEmpty(fsUser.getNickName())
|
|
|
+// &&fsUser.getNickName().equals("微信用户")) {
|
|
|
+// return R.error(409, "请重新登录用户!");
|
|
|
+// }
|
|
|
+ if (fsUser.getStatus() != null && fsUser.getStatus() == 0) {
|
|
|
+ return R.error("会员被停用,无权限,请联系客服!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理群聊逻辑
|
|
|
+ if (param.getChatId() != null && StringUtils.isNotEmpty(param.getChatId())) {
|
|
|
+ QwGroupChat qwGroupChat = qwGroupChatMapper.selectQwGroupChatByChatId(param.getChatId());
|
|
|
+ if (qwGroupChat == null) {
|
|
|
+ logger.error("群聊不存在,chatId: {}", param.getChatId());
|
|
|
+ return R.error("群聊不存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ SopUserLogsInfo sopUserLogsInfo = new SopUserLogsInfo();
|
|
|
+ sopUserLogsInfo.setChatId(param.getChatId());
|
|
|
+ List<QwGroupChatUser> qwGroupChatUsers = qwGroupChatUserMapper.selectByChatId(sopUserLogsInfo);
|
|
|
+
|
|
|
+ if (qwGroupChatUsers == null || qwGroupChatUsers.isEmpty()) {
|
|
|
+ logger.error("群聊用户为空,chatId: {}", param.getChatId());
|
|
|
+ return R.error("群聊用户为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ QwExternalContact qwExternalContact =
|
|
|
+ qwExternalContactMapper.selectOne(new QueryWrapper<QwExternalContact>()
|
|
|
+ .eq("user_id", qwGroupChat.getOwner())
|
|
|
+ .eq("fs_user_id", param.getUserId())
|
|
|
+ .eq("corp_id", param.getCorpId())
|
|
|
+ .eq("status",0));
|
|
|
+ if(null == qwExternalContact){
|
|
|
+ try{
|
|
|
+ //修改成通过昵称匹配
|
|
|
+ qwExternalContact =
|
|
|
+ qwExternalContactMapper.selectOne(new QueryWrapper<QwExternalContact>()
|
|
|
+ .eq("user_id", qwGroupChat.getOwner())
|
|
|
+ .eq("name", fsUser.getNickName())
|
|
|
+ .eq("corp_id", param.getCorpId())
|
|
|
+ .eq("status",0));
|
|
|
+ } catch(Exception e){
|
|
|
+ log.error("群聊用户昵称匹配异常,参数user_id:{},name:{},corp_id:{}",qwGroupChat.getOwner(),fsUser.getNickName(),param.getCorpId(),e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (qwExternalContact == null) {
|
|
|
+ return R.error("未查询到客户!");
|
|
|
+ }
|
|
|
+
|
|
|
+ QwExternalContact finalQwExternalContact = qwExternalContact;
|
|
|
+ if(qwGroupChatUsers.stream().noneMatch(e -> e.getUserId().equals(finalQwExternalContact.getExternalUserId()))){
|
|
|
+ log.error("客户不在群:{},里面:{}", qwGroupChat.getChatId(), qwExternalContact.getExternalUserId());
|
|
|
+ return R.error("客户不在群!");
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("外部联系人数据:{}", qwExternalContact);
|
|
|
+
|
|
|
+ // 如果群在里面
|
|
|
+ if (qwExternalContact.getFsUserId() != null) {
|
|
|
+ // 有客户有小程序id,但登录的小程序id和根据外部联系人id查出来的小程序id不一致
|
|
|
+// if (!qwExternalContact.getFsUserId().equals(param.getUserId())) {
|
|
|
+// logger.error("已注册,但绑定的userId,不一致param.getUserId{},qwExternalContact.getFsUserId(){}",param.getUserId(),qwExternalContact.getFsUserId());
|
|
|
+// return R.error("已注册!");
|
|
|
+// }
|
|
|
+ }else {
|
|
|
+ // 未绑定
|
|
|
+ return R.error( "客户未绑定用户");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }else {
|
|
|
+ Long qwExternalId = param.getQwExternalId();
|
|
|
+
|
|
|
+ if (qwExternalId == null) {
|
|
|
+ return R.error("外部联系人ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询外部联系人
|
|
|
+ QwExternalContact externalContact = qwExternalContactMapper.selectQwExternalContactById(qwExternalId);
|
|
|
+
|
|
|
+ // 如果查不出来客户信息,加好友
|
|
|
+ if (externalContact == null) {
|
|
|
+ return R.error("未查询到企微客户信息!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (externalContact.getFsUserId() != null) {
|
|
|
+ // 有客户有小程序id,但登录的小程序id和根据外部联系人id查出来的小程序id不一致
|
|
|
+// if (!externalContact.getFsUserId().equals(param.getUserId())) {
|
|
|
+// logger.error("已注册,但绑定的userId,不一致param.getUserId{},qwExternalContact.getFsUserId(){}",param.getUserId(),externalContact.getFsUserId());
|
|
|
+// return R.error("已注册!");
|
|
|
+// }
|
|
|
+ }else {
|
|
|
+ // 未绑定
|
|
|
+ return R.error( "客户未绑定用户");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R registerQwFsUser(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(401, "用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fsUser.getStatus() != null && fsUser.getStatus() == 0) {
|
|
|
+ return R.error("会员被停用,无权限,请联系客服!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理群聊逻辑
|
|
|
+ if (param.getChatId() != null) {
|
|
|
+ return handleGroupChatLogic(param,fsUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理普通外部联系人逻辑
|
|
|
+ return handleExternalContactLogic(param, fsUser);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public void uploadSingleTaskWithRetry(FsVideoResource videoResource,Integer type) {
|
|
|
int maxRetry = 3;
|
|
|
@@ -4556,38 +4708,156 @@ public class FsUserCourseVideoServiceImpl extends ServiceImpl<FsUserCourseVideoM
|
|
|
|
|
|
return link;
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
- public R registerQwFsUser(FsUserCourseVideoAddKfUParam param) {
|
|
|
- logger.info("zyp \n【判断添加客服】:{}", param);
|
|
|
+ public List<OptionsVO> selectVideoOptionsByCourseId(Long courseId) {
|
|
|
+ return fsUserCourseVideoMapper.selectVideoOptionsByCourseId(courseId);
|
|
|
+ }
|
|
|
|
|
|
- // 参数校验
|
|
|
- if (param == null) {
|
|
|
- return R.error("参数不能为空");
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public R createAppFd(LuckyBagCollectRecord param) {
|
|
|
|
|
|
- // 查询用户
|
|
|
- FsUser fsUser = fsUserMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ try {
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserByCompanyUserId(param.getCompanyUserId());
|
|
|
+ if (companyUser==null||companyUser.getCompanyId()==null||companyUser.getUserId()==null){
|
|
|
+ return R.error("员工不存在!");
|
|
|
+ }
|
|
|
|
|
|
- // 用户不存在唤起重新授权
|
|
|
- if (fsUser == null) {
|
|
|
- return R.error(401, "用户不存在");
|
|
|
+ Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
+ if (company == 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());
|
|
|
+
|
|
|
+ Map<String,Object> business = addLuckyBagCollectRecord(param.getLuckyBagId(),param.getUserId(),updateTime,String.valueOf(param.getCompanyUserId()),String.valueOf(param.getCompanyId()));
|
|
|
+ String json = configService.selectConfigByKey("luckyBag.config");
|
|
|
+ Map<String, Object> luckyBagConfig = JSON.parseObject(json, Map.class);
|
|
|
+ business.put("img",luckyBagConfig.get("miniprogramPicUrl"));
|
|
|
+ return R.ok().put("data",business);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return R.error("发放福袋失败!");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (fsUser.getStatus() != null && fsUser.getStatus() == 0) {
|
|
|
- return R.error("会员被停用,无权限,请联系客服!");
|
|
|
- }
|
|
|
|
|
|
- // 处理群聊逻辑
|
|
|
- if (param.getChatId() != null) {
|
|
|
- return handleGroupChatLogic(param,fsUser);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 增加福袋发放记录、领取记录
|
|
|
+ *
|
|
|
+ * @param luckyBagId
|
|
|
+ * @param userId
|
|
|
+ * @param sendTime
|
|
|
+ * @param companyUserId
|
|
|
+ * @param companyId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String,Object> addLuckyBagCollectRecord(Long luckyBagId,
|
|
|
+ Long userId,
|
|
|
+ Date sendTime,
|
|
|
+ String companyUserId,
|
|
|
+ String companyId) {
|
|
|
+ try {
|
|
|
|
|
|
- // 处理普通外部联系人逻辑
|
|
|
- return handleExternalContactLogic(param, fsUser);
|
|
|
+ if (StringUtils.isEmpty(companyId) || StringUtils.isEmpty(companyUserId)) {
|
|
|
+ log.warn("公司ID或用户ID为空 [companyId:{}, companyUserId:{}]", companyId, companyUserId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证福袋ID
|
|
|
+ if (luckyBagId == null) {
|
|
|
+ log.warn("福袋ID为空");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询福袋信息
|
|
|
+ LuckyBag luckyBag = luckyBagMapper.selectLuckyBagById(luckyBagId);
|
|
|
+ if (luckyBag == null) {
|
|
|
+ log.warn("未找到对应的福袋信息 [luckyBagId:{}]", luckyBagId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查福袋状态
|
|
|
+ if (luckyBag.getDataStatus() != null && luckyBag.getDataStatus().equals(0)) {
|
|
|
+ log.warn("福袋被禁用 [luckyBagId:{}]", luckyBagId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询公司信息
|
|
|
+ Company company = companyMapper.selectCompanyById(Long.valueOf(companyId));
|
|
|
+ if (company == null) {
|
|
|
+ log.warn("未找到对应的公司信息 [companyId:{}]", companyId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ LuckyBagCollectRecord luckyBagCollectRecord = buildLuckyBagRecord(luckyBagId,userId,sendTime,
|
|
|
+ companyUserId, companyId, company, luckyBag);
|
|
|
+
|
|
|
+ // 插入记录并返回ID
|
|
|
+ int result = luckyBagCollectRecordMapper.insertLuckyBagCollectRecord(luckyBagCollectRecord);
|
|
|
+ if (result <= 0) {
|
|
|
+ log.warn("福袋记录插入失败 [luckyBagId:{}]", luckyBagId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回新增记录的ID
|
|
|
+ Long recordId = luckyBagCollectRecord.getId();
|
|
|
+ if (recordId == null) {
|
|
|
+ log.warn("福袋记录插入成功但未返回ID [luckyBagId:{}]", luckyBagId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("福袋记录添加成功 [recordId:{}, luckyBagId:{}]", recordId, luckyBagId);
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("recordId",recordId);
|
|
|
+ map.put("luckyBag",luckyBag);
|
|
|
+ return map;
|
|
|
+
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.error("ID转换失败 [companyId:{}, companyUserId:{}]", companyId, companyUserId, e);
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("ID:" + (luckyBagId != null ? luckyBagId : "unknown") + "-添加福袋记录失败", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
- @Override
|
|
|
- public List<OptionsVO> selectVideoOptionsByCourseId(Long courseId) {
|
|
|
- return fsUserCourseVideoMapper.selectVideoOptionsByCourseId(courseId);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建福袋记录对象
|
|
|
+ */
|
|
|
+ private LuckyBagCollectRecord buildLuckyBagRecord(Long luckyBagId,
|
|
|
+ Long userId,
|
|
|
+ Date sendTime,
|
|
|
+ String companyUserId,
|
|
|
+ String companyId,
|
|
|
+ Company company,
|
|
|
+ LuckyBag luckyBag) {
|
|
|
+ LuckyBagCollectRecord record = new LuckyBagCollectRecord();
|
|
|
+ record.setLuckyBagId(luckyBagId);
|
|
|
+ record.setExpiryTime(sendTime);
|
|
|
+ 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.setRewardType(2L);
|
|
|
+
|
|
|
+ // 设置币种金额
|
|
|
+ if (luckyBag.getRewardType() != null && luckyBag.getRewardType().equals("1")) {
|
|
|
+ record.setCoinAmount(luckyBag.getAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+ return record;
|
|
|
}
|
|
|
}
|
|
|
|