|
|
|
@ -1,28 +1,22 @@
|
|
|
|
|
package com.tz.platform.competitiion.pc.biz;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
|
import com.alibaba.excel.enums.CellExtraTypeEnum;
|
|
|
|
|
import com.alibaba.excel.read.listener.PageReadListener;
|
|
|
|
|
import com.tz.platform.common.core.base.Result;
|
|
|
|
|
import com.tz.platform.common.core.bo.MemberImport;
|
|
|
|
|
import com.tz.platform.common.core.bo.MemberInfo;
|
|
|
|
|
import com.tz.platform.competitiion.pc.bo.PersonImport;
|
|
|
|
|
import com.tz.platform.competitiion.pc.bo.TeamImport;
|
|
|
|
|
import com.tz.platform.competitiion.pc.bo.TeamInfo;
|
|
|
|
|
import com.tz.platform.competitiion.pc.helper.ExcelAnalysisHelper;
|
|
|
|
|
import com.tz.platform.competitiion.pc.helper.UploadDataListener;
|
|
|
|
|
import com.tz.platform.competitiion.pc.vo.ImportTeamMemberVO;
|
|
|
|
|
import com.tz.platform.entity.Competition;
|
|
|
|
|
import com.tz.platform.entity.CompetitionMember;
|
|
|
|
|
import com.tz.platform.entity.CompetitionTeam;
|
|
|
|
|
import com.tz.platform.feign.IFeignProvince;
|
|
|
|
|
import com.tz.platform.feign.IFeignStudentLevel;
|
|
|
|
|
import com.tz.platform.entity.User;
|
|
|
|
|
import com.tz.platform.feign.user.IFeignUser;
|
|
|
|
|
import com.tz.platform.feign.vo.ProvinceVO;
|
|
|
|
|
import com.tz.platform.feign.vo.StudentLevelVo;
|
|
|
|
|
import com.tz.platform.repository.CompetitionDao;
|
|
|
|
|
import com.tz.platform.repository.CompetitionMemberDao;
|
|
|
|
|
import com.tz.platform.repository.CompetitionTeamDao;
|
|
|
|
|
import com.tz.platform.repository.UserDao;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
@ -33,6 +27,7 @@ import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
@ -43,7 +38,8 @@ public class TeamMemberImportBiz {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IFeignUser user;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserDao userDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CompetitionTeamDao teamDao;
|
|
|
|
@ -52,7 +48,96 @@ public class TeamMemberImportBiz {
|
|
|
|
|
private CompetitionMemberDao memberDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CompetitionDao competitionDao;
|
|
|
|
|
CompetitionDao competitionDao;
|
|
|
|
|
|
|
|
|
|
public Result<String> uploadPersonExcel(MultipartFile file, Long competitionId, Integer stageId, Long userId) {
|
|
|
|
|
if (file == null) {
|
|
|
|
|
return Result.error("请上传文件");
|
|
|
|
|
}
|
|
|
|
|
if (competitionId == null || stageId == null) {
|
|
|
|
|
return Result.error("大赛或赛段不能为空");
|
|
|
|
|
}
|
|
|
|
|
ExcelAnalysisHelper<PersonImport> excelAnalysisHelper = new ExcelAnalysisHelper<>();
|
|
|
|
|
List<PersonImport> personList = null;
|
|
|
|
|
try {
|
|
|
|
|
personList = excelAnalysisHelper.getList(file.getInputStream(), PersonImport.class, 0, 1); //表格数据转换成list
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> collect = personList.stream().map(p -> p.getStudentNo()).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
List<User> allStu = userDao.findAllByStudentNoIn(collect);
|
|
|
|
|
if (allStu.isEmpty()){
|
|
|
|
|
return Result.error("表中用户不存在");
|
|
|
|
|
}
|
|
|
|
|
// 对personList进行分组,以studentNo和schoolName作为key
|
|
|
|
|
Map<String, List<PersonImport>> groupedByStudentNoAndSchoolName = personList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(personImport -> {
|
|
|
|
|
String studentNo = StringUtils.trimAllWhitespace(filter(personImport.getStudentNo()));
|
|
|
|
|
String schoolName = StringUtils.trimAllWhitespace(filter(personImport.getSchoolName()));
|
|
|
|
|
return studentNo + "_" + schoolName;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// 过滤掉studentNo和schoolName同时重复的数据
|
|
|
|
|
List<PersonImport> filteredPersonImports = groupedByStudentNoAndSchoolName.values().stream()
|
|
|
|
|
.filter(list -> list.size() == 1)
|
|
|
|
|
.flatMap(List::stream)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
//找出数据库表和导入表格匹配的用户数据
|
|
|
|
|
List<PersonImport> matchedPersonImports = filteredPersonImports.stream()
|
|
|
|
|
.filter(personImport -> {
|
|
|
|
|
String studentNo = StringUtils.trimAllWhitespace(filter(personImport.getStudentNo()));
|
|
|
|
|
String name = StringUtils.trimAllWhitespace(filter(personImport.getName()));
|
|
|
|
|
String className = StringUtils.trimAllWhitespace(filter(personImport.getClassName()));
|
|
|
|
|
String schoolName = StringUtils.trimAllWhitespace(filter(personImport.getSchoolName()));
|
|
|
|
|
|
|
|
|
|
return allStu.stream()
|
|
|
|
|
.anyMatch(user -> user.getStudentNo().toString().equals(studentNo)
|
|
|
|
|
&& user.getName().equals(name)
|
|
|
|
|
&& user.getClassName().equals(className)
|
|
|
|
|
&& user.getSchool().equals(schoolName));
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
//将过滤后的数据复制到对应的对象
|
|
|
|
|
List<CompetitionMember> competitionMembers = matchedPersonImports.stream()
|
|
|
|
|
.map(matchedPersonImport -> {
|
|
|
|
|
CompetitionMember competitionMember = new CompetitionMember();
|
|
|
|
|
competitionMember.setStageId(stageId);
|
|
|
|
|
competitionMember.setTeamId(0); // 个人赛
|
|
|
|
|
competitionMember.setTeamName("个人赛");
|
|
|
|
|
// 寻找匹配的 User 对象,并设置对应的 userId
|
|
|
|
|
allStu.stream()
|
|
|
|
|
.filter(user -> user.getStudentNo().toString().equals(StringUtils.trimAllWhitespace(filter(matchedPersonImport.getStudentNo())))
|
|
|
|
|
&& user.getName().equals(StringUtils.trimAllWhitespace(filter(matchedPersonImport.getName())))
|
|
|
|
|
&& user.getClassName().equals(StringUtils.trimAllWhitespace(filter(matchedPersonImport.getClassName())))
|
|
|
|
|
&& user.getSchool().equals(StringUtils.trimAllWhitespace(filter(matchedPersonImport.getSchoolName()))))
|
|
|
|
|
.findFirst().ifPresent(matchedUser -> {
|
|
|
|
|
competitionMember.setUserId(matchedUser.getId());
|
|
|
|
|
competitionMember.setClassId(matchedUser.getClassId());
|
|
|
|
|
});
|
|
|
|
|
competitionMember.setSchool(matchedPersonImport.getSchoolName());
|
|
|
|
|
competitionMember.setClassName(matchedPersonImport.getClassName());
|
|
|
|
|
competitionMember.setName(matchedPersonImport.getName());
|
|
|
|
|
competitionMember.setStudentNo(matchedPersonImport.getStudentNo());
|
|
|
|
|
competitionMember.setCompetitionId(competitionId);
|
|
|
|
|
return competitionMember;
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
//批量新增入库
|
|
|
|
|
List<CompetitionMember> newMembers = competitionMembers.stream()
|
|
|
|
|
.filter(member -> memberDao.findByCompetitionIdAndStudentNoAndSchool(competitionId,member.getStudentNo(), member.getSchool()).isEmpty())
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if (!newMembers.isEmpty()) {
|
|
|
|
|
memberDao.saveAll(newMembers);
|
|
|
|
|
updatePeopleCount(competitionId);
|
|
|
|
|
return Result.success("success");
|
|
|
|
|
} else {
|
|
|
|
|
return Result.success("No new members to save.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result<String> teamImport(MultipartFile file, Long userNo, Long competitionId, Integer stageId) {
|
|
|
|
|
if (competitionId == null || stageId == null) {
|
|
|
|
@ -62,7 +147,8 @@ public class TeamMemberImportBiz {
|
|
|
|
|
List<TeamImport> teamList = null;
|
|
|
|
|
try {
|
|
|
|
|
teamList = excelAnalysisHelper.getList(file.getInputStream(), TeamImport.class, 0, 1);
|
|
|
|
|
} catch (IOException e) {e.printStackTrace();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
List<MemberImport> neesSave = new ArrayList<>();
|
|
|
|
@ -377,4 +463,5 @@ public class TeamMemberImportBiz {
|
|
|
|
|
// });
|
|
|
|
|
// System.out.println("团队总数:"+temamList.size()+" 团队成员数量:"+teamList.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|