|
|
@@ -15,18 +15,24 @@ import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
import com.fs.course.mapper.FsUserCompanyBindMapper;
|
|
|
import com.fs.course.mapper.FsUserCourseMapper;
|
|
|
import com.fs.course.service.IFsUserCompanyBindService;
|
|
|
+import com.fs.course.vo.CourseProgressResultVO;
|
|
|
+import com.fs.course.vo.RelatedSalesResultVO;
|
|
|
+import com.fs.course.vo.RepeatCourseHistoryVO;
|
|
|
import com.fs.course.vo.UserWatchLogListVo;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
import com.fs.qw.domain.QwExternalContact;
|
|
|
import com.fs.qw.mapper.QwCompanyMapper;
|
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
+import com.fs.qw.mapper.QwUserMapper;
|
|
|
import com.fs.qw.param.UserWatchLogParam;
|
|
|
+import com.fs.qw.vo.QwOptionsVO;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
@@ -48,6 +54,7 @@ public class FsUserCompanyBindServiceImpl extends ServiceImpl<FsUserCompanyBindM
|
|
|
private QwExternalContactMapper qwExternalContactMapper;
|
|
|
private FsUserCourseMapper fsUserCourseMapper;
|
|
|
private QwCompanyMapper qwCompanyMapper;
|
|
|
+ private QwUserMapper qwUserMapper;
|
|
|
private CompanyMapper companyMapper;
|
|
|
|
|
|
/**
|
|
|
@@ -242,6 +249,108 @@ public class FsUserCompanyBindServiceImpl extends ServiceImpl<FsUserCompanyBindM
|
|
|
if(param.getExternalUserId() == null && param.getFsUserId() == null){
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
- return baseMapper.getWatchLogList(param);
|
|
|
+ List<UserWatchLogListVo> list = baseMapper.getWatchLogList(param);
|
|
|
+ // 权限判断:如果传了companyId,对无权限的主体脱敏
|
|
|
+ if (param.getCompanyId() != null && list != null) {
|
|
|
+ List<String> permittedCorpIds = getPermittedCorpIds(param.getCompanyId());
|
|
|
+ for (UserWatchLogListVo vo : list) {
|
|
|
+ boolean hasPermission = vo.getCorpId() == null || permittedCorpIds.contains(vo.getCorpId());
|
|
|
+ vo.setHasPermission(hasPermission);
|
|
|
+ if (!hasPermission) {
|
|
|
+ vo.setQwUserName("***");
|
|
|
+ vo.setCorpName("***");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RepeatCourseHistoryVO getRepeatCourseHistory(Long fsUserId, Long companyId) {
|
|
|
+ RepeatCourseHistoryVO vo = new RepeatCourseHistoryVO();
|
|
|
+
|
|
|
+ // 查询当前用户公司有权限的企微主体corpId列表
|
|
|
+ List<String> permittedCorpIds = getPermittedCorpIds(companyId);
|
|
|
+
|
|
|
+ // 1. 查询客户基本信息
|
|
|
+ QwExternalContact contact = qwExternalContactMapper.selectOne(
|
|
|
+ new QueryWrapper<QwExternalContact>()
|
|
|
+ .eq("fs_user_id", fsUserId)
|
|
|
+ .eq("status", 0)
|
|
|
+ .last("LIMIT 1")
|
|
|
+ );
|
|
|
+ if (contact != null) {
|
|
|
+ vo.setName(contact.getName());
|
|
|
+ vo.setAvatar(contact.getAvatar());
|
|
|
+ vo.setRemark(contact.getRemark());
|
|
|
+ vo.setUserRepeat(contact.getUserRepeat());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询关联销售(单条SQL + GROUP BY 优化)
|
|
|
+ List<RelatedSalesResultVO> salesResults = baseMapper.getRelatedSalesByFsUserId(fsUserId);
|
|
|
+ List<RepeatCourseHistoryVO.RelatedSalesVO> salesList = new ArrayList<>();
|
|
|
+ for (RelatedSalesResultVO r : salesResults) {
|
|
|
+ RepeatCourseHistoryVO.RelatedSalesVO s = new RepeatCourseHistoryVO.RelatedSalesVO();
|
|
|
+ boolean hasPermission = r.getCorpId() == null || permittedCorpIds.contains(r.getCorpId());
|
|
|
+ s.setHasPermission(hasPermission);
|
|
|
+ if (hasPermission) {
|
|
|
+ s.setQwUserName(r.getQwUserName());
|
|
|
+ s.setCorpName(r.getCorpName());
|
|
|
+ } else {
|
|
|
+ s.setQwUserName("***");
|
|
|
+ s.setCorpName("***");
|
|
|
+ }
|
|
|
+ s.setAddTime(r.getAddTime());
|
|
|
+ s.setStatus(r.getStatus());
|
|
|
+ salesList.add(s);
|
|
|
+ }
|
|
|
+ vo.setSalesList(salesList);
|
|
|
+
|
|
|
+ // 3. 查询课程学习进度(单条SQL + 子查询优化)
|
|
|
+ List<CourseProgressResultVO> courseResults = baseMapper.getCourseProgressByFsUserId(fsUserId);
|
|
|
+ List<RepeatCourseHistoryVO.CourseProgressVO> courseList = new ArrayList<>();
|
|
|
+ for (CourseProgressResultVO c : courseResults) {
|
|
|
+ RepeatCourseHistoryVO.CourseProgressVO cp = new RepeatCourseHistoryVO.CourseProgressVO();
|
|
|
+ cp.setCourseId(c.getCourseId());
|
|
|
+ cp.setCourseName(c.getCourseName());
|
|
|
+ cp.setTotalCount(c.getTotalCount() != null ? c.getTotalCount() : 0);
|
|
|
+ cp.setWatchedCount(c.getWatchedCount() != null ? c.getWatchedCount() : 0);
|
|
|
+ // 计算百分比
|
|
|
+ int total = cp.getTotalCount();
|
|
|
+ int watched = cp.getWatchedCount();
|
|
|
+ cp.setPercentage(total > 0 ? (watched * 100 / total) : 0);
|
|
|
+ cp.setLatestSection(c.getLatestSection());
|
|
|
+ cp.setLatestTime(c.getLatestTime());
|
|
|
+ cp.setFinished(total > 0 && watched >= total);
|
|
|
+ boolean hasPermission = c.getCorpId() == null || permittedCorpIds.contains(c.getCorpId());
|
|
|
+ cp.setHasPermission(hasPermission);
|
|
|
+ if (hasPermission) {
|
|
|
+ cp.setQwUserName(c.getQwUserName());
|
|
|
+ cp.setCorpName(c.getCorpName());
|
|
|
+ } else {
|
|
|
+ cp.setQwUserName("***");
|
|
|
+ cp.setCorpName("***");
|
|
|
+ }
|
|
|
+ courseList.add(cp);
|
|
|
+ }
|
|
|
+ vo.setCourseList(courseList);
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据运营公司ID查询有权限的企微主体corpId列表
|
|
|
+ */
|
|
|
+ private List<String> getPermittedCorpIds(Long companyId) {
|
|
|
+ List<QwOptionsVO> companyList = qwUserMapper.selectQwCompanyListOptionsVOByCompanyId(companyId);
|
|
|
+ List<String> corpIds = new ArrayList<>();
|
|
|
+ if (companyList != null) {
|
|
|
+ for (QwOptionsVO vo : companyList) {
|
|
|
+ if (vo.getDictValue() != null) {
|
|
|
+ corpIds.add(vo.getDictValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return corpIds;
|
|
|
}
|
|
|
}
|