|
@@ -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;
|
|
@@ -216,20 +219,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 +239,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() {
|