Explorar o código

Merge remote-tracking branch 'origin/master_saas' into master_saas

zouxuan %!s(int64=3) %!d(string=hai) anos
pai
achega
c235eb0da7

+ 54 - 14
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveRoomPurviewServiceImpl.java

@@ -11,9 +11,11 @@ import com.ym.mec.biz.dal.dto.SysUserDto;
 import com.ym.mec.biz.dal.entity.ImGroup;
 import com.ym.mec.biz.dal.entity.ImLiveBroadcastRoom;
 import com.ym.mec.biz.dal.entity.ImLiveRoomPurview;
+import com.ym.mec.biz.dal.entity.Student;
 import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
 import com.ym.mec.biz.service.ImLiveBroadcastRoomService;
 import com.ym.mec.biz.service.ImLiveRoomPurviewService;
+import com.ym.mec.biz.service.StudentService;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
@@ -27,7 +29,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
-import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -49,6 +50,8 @@ public class ImLiveRoomPurviewServiceImpl extends ServiceImpl<ImLiveRoomPurviewD
     private final static Logger log = LoggerFactory.getLogger(ImLiveRoomPurviewServiceImpl.class);
 
     @Autowired
+    private StudentService studentService;
+    @Autowired
     private SysUserFeignService sysUserFeignService;
     @Autowired
     private ImLiveBroadcastRoomService imLiveBroadcastRoomService;
@@ -72,6 +75,8 @@ public class ImLiveRoomPurviewServiceImpl extends ServiceImpl<ImLiveRoomPurviewD
     public void addByCondition(Map<String, Object> param) {
         String roomUid = WrapperUtil.toStr(param, "roomUid", "房间uid不能为空");
         param.put("tenantId", TenantContextHolder.getTenantId());
+        //必需有一个参数条件,要不然数据太多了
+        this.checkParam(param, "search", "subjectId", "organIds", "groupIds", "teamIds", "schoolIds");
         //根据条件查询学员
         List<SysUserDto> studentList = baseMapper.selectRoomPurviewStudent(param);
         if (CollectionUtils.isEmpty(studentList)) {
@@ -83,6 +88,25 @@ public class ImLiveRoomPurviewServiceImpl extends ServiceImpl<ImLiveRoomPurviewD
     }
 
     /**
+     * 校验条件,必需有一个参数条件
+     *
+     * @param param 参数
+     * @param keys  参数key
+     */
+    private void checkParam(Map<String, Object> param, String... keys) {
+        String checkVal = null;
+        for (String key : keys) {
+            String val = WrapperUtil.toStr(param, key);
+            if (StringUtils.isNotBlank(val)) {
+                checkVal = val;
+            }
+        }
+        if(StringUtils.isBlank(checkVal)){
+            throw new BizException("必需要有一个查询条件");
+        }
+    }
+
+    /**
      * 指定多个学员id添加观看权限数据
      *
      * @param ids     bizId
@@ -216,20 +240,17 @@ public class ImLiveRoomPurviewServiceImpl extends ServiceImpl<ImLiveRoomPurviewD
                 new ByteArrayInputStream(file.getBytes()), 0, file.getOriginalFilename());
         InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
         Map<String, String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.LIVE_ROOM_PURVIEW_USER.getMsg());
-        List<ImLiveRoomPurview> purviewList = new ArrayList<>();
+        List<Integer> userIdList = new ArrayList<>();
+        Map<Integer, Object> userIdMap = new HashMap<>();
         Integer id = getSysUser().getId();
         Date now = new Date();
+        Integer tenantId = TenantContextHolder.getTenantId();
         for (String e : sheetsListMap.keySet()) {
             List<Map<String, Object>> sheet = sheetsListMap.get(e);
             for (Map<String, Object> row : sheet) {
                 if (row.size() == 0) {
                     continue;
                 }
-                ImLiveRoomPurview obj = new ImLiveRoomPurview();
-                obj.setRoomUid(roomUid);
-                obj.setType("STUDENT");
-                obj.setCreatedBy(id);
-                obj.setCreatedTime(now);
                 for (String s : row.keySet()) {
                     if (!columns.containsKey(s)) {
                         continue;
@@ -239,21 +260,40 @@ public class ImLiveRoomPurviewServiceImpl extends ServiceImpl<ImLiveRoomPurviewD
                             log.error("导入异常:{}不可为空", s);
                             continue;
                         }
-                        obj.setUserId(Integer.valueOf(row.get(s).toString()));
+                        Integer userId = Integer.valueOf(row.get(s).toString());
+                        if (Objects.nonNull(userIdMap.get(userId))) {
+                            continue;
+                        }
+                        Student student = studentService.get(userId);
+                        if (Objects.isNull(student)) {
+                            throw new BizException("导入异常:编号 " + userId + " 的用户不存在");
+                        }
+                        if (!Objects.equals(student.getTenantId(), tenantId)) {
+                            throw new BizException("导入异常:编号 " + userId + " 的用户不是该机构的学员");
+                        }
+                        userIdList.add(userId);
+                        userIdMap.put(userId, userId);
                     }
                 }
-                purviewList.add(obj);
             }
         }
         try {
-            baseMapper.insertBatch(purviewList);
-        } catch (DuplicateKeyException dupKeyEx) {
-            log.error("数据导入重复: " + dupKeyEx.getCause());
-            throw new BizException("数据重复:" + dupKeyEx.getCause());
+            userIdList = userIdList.stream().distinct().collect(Collectors.toList());
+            List<ImLiveRoomPurview> purviewList = userIdList.stream()
+                    .map(userId -> {
+                        ImLiveRoomPurview obj = new ImLiveRoomPurview();
+                        obj.setUserId(userId);
+                        obj.setRoomUid(roomUid);
+                        obj.setType("STUDENT");
+                        obj.setCreatedBy(id);
+                        obj.setCreatedTime(now);
+                        return obj;
+                    }).collect(Collectors.toList());
+            Lists.partition(purviewList, 100).forEach(list -> baseMapper.insertBatch(list));
         } catch (Exception ex) {
             throw new BizException("导入数据出错:" + ex, ex);
         }
-        return "成功导入 " + purviewList.size() + "条";
+        return "成功导入 " + userIdList.size() + "条";
     }
 
     private SysUser getSysUser() {

+ 1 - 1
mec-web/src/main/resources/columnMapper.ini

@@ -78,5 +78,5 @@ ID = id
 头像地址 = avatar
 
 [直播间用户观看权限表]
-编号 = userId
+学员编号 = userId
 名称 = userName