|
@@ -10,38 +10,53 @@ import com.keao.edu.common.service.impl.BaseServiceImpl;
|
|
|
import com.keao.edu.common.tenant.TenantContextHolder;
|
|
|
import com.keao.edu.user.dao.ExamRegistrationDao;
|
|
|
import com.keao.edu.user.dao.ExamSongDao;
|
|
|
+import com.keao.edu.user.dao.SubjectDao;
|
|
|
import com.keao.edu.user.entity.ExamSong;
|
|
|
+import com.keao.edu.user.entity.Subject;
|
|
|
+import com.keao.edu.user.entity.Teacher;
|
|
|
+import com.keao.edu.user.enums.SongTypeEnum;
|
|
|
+import com.keao.edu.user.enums.TeacherSettlementTypeEnum;
|
|
|
import com.keao.edu.user.page.ExamSongQueryInfo;
|
|
|
import com.keao.edu.user.service.ExamSongService;
|
|
|
import com.keao.edu.util.collection.MapUtil;
|
|
|
+import com.keao.edu.util.excel.POIUtil;
|
|
|
+import com.keao.edu.util.iniFile.IniFileEntity;
|
|
|
+import com.keao.edu.util.iniFile.IniFileUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> implements ExamSongService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ExamSongDao examSongDao;
|
|
|
- @Autowired
|
|
|
- private ExamRegistrationDao examRegistrationDao;
|
|
|
- @Autowired
|
|
|
- private SysUserFeignService sysUserFeignService;
|
|
|
|
|
|
- @Override
|
|
|
- public BaseDAO<Integer, ExamSong> getDAO() {
|
|
|
- return examSongDao;
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private ExamSongDao examSongDao;
|
|
|
+ @Autowired
|
|
|
+ private ExamRegistrationDao examRegistrationDao;
|
|
|
+ @Autowired
|
|
|
+ private SysUserFeignService sysUserFeignService;
|
|
|
+ @Autowired
|
|
|
+ private SubjectDao subjectDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Integer, ExamSong> getDAO() {
|
|
|
+ return examSongDao;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public long insert(ExamSong examSong) {
|
|
|
- if(StringUtils.isBlank(examSong.getSubjectList())){
|
|
|
+ if (StringUtils.isBlank(examSong.getSubjectList())) {
|
|
|
throw new BizException("请选择专业");
|
|
|
}
|
|
|
- if(Objects.isNull(examSong.getType())){
|
|
|
- throw new BizException("请选择曲库类别");
|
|
|
+ if (Objects.isNull(examSong.getType())) {
|
|
|
+ throw new BizException("请选择曲库类别");
|
|
|
}
|
|
|
// List<ExamSong> existsExamSongs = examSongDao.getWithLevelAndType(examSong.getTenantId(), examSong.getLevelList(), examSong.getType());
|
|
|
// if(!CollectionUtils.isEmpty(existsExamSongs)){
|
|
@@ -69,8 +84,8 @@ public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> impl
|
|
|
|
|
|
@Override
|
|
|
public List<ExamSong> getWithSubject(Integer subjectId) {
|
|
|
- if(Objects.isNull(subjectId)){
|
|
|
- throw new BizException("请选择专业");
|
|
|
+ if (Objects.isNull(subjectId)) {
|
|
|
+ throw new BizException("请选择专业");
|
|
|
}
|
|
|
return examSongDao.getWithSubject(subjectId, TenantContextHolder.getTenantId());
|
|
|
}
|
|
@@ -78,10 +93,10 @@ public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> impl
|
|
|
@Override
|
|
|
public PageInfo<ExamSong> querySongPage(ExamSongQueryInfo queryInfo) {
|
|
|
PageInfo<ExamSong> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
- //获取学员所在机构
|
|
|
+ //获取学员所在机构
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
List<Integer> tenantIds = examRegistrationDao.queryStudentTenantId(sysUser.getId());
|
|
|
- if(tenantIds == null || tenantIds.size() == 0){
|
|
|
+ if (tenantIds == null || tenantIds.size() == 0) {
|
|
|
return pageInfo;
|
|
|
}
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
@@ -98,4 +113,74 @@ public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> impl
|
|
|
pageInfo.setRows(dataList);
|
|
|
return pageInfo;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<ExamSong> importExamSong(MultipartFile file, String tenantId) throws Exception {
|
|
|
+ Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(file.getInputStream(), 2, file.getOriginalFilename());
|
|
|
+ InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
+ List<IniFileEntity> columns = IniFileUtil.readIniFile(inputStream).get("examSong");
|
|
|
+ List<Subject> subSubjects = subjectDao.findSubSubjects();
|
|
|
+ List<ExamSong> examSongs = new ArrayList<>();
|
|
|
+ sheetsListMap.keySet().forEach(e -> {
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get(e);
|
|
|
+ for (Map<String, Object> row : sheet) {
|
|
|
+ Map<String, Object> objectMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (String s : row.keySet()) {
|
|
|
+ for (IniFileEntity column : columns) {
|
|
|
+ if (!s.equals(column.getKey())) continue;
|
|
|
+ objectMap.put(column.getValue(), row.get(s));
|
|
|
+ if (column.getValue().equals("levelList")) {
|
|
|
+ int i = Integer.parseInt(row.get(s).toString());
|
|
|
+ if (i <= 0 || i > 10) {
|
|
|
+ throw new BizException("曲目级别只能填1-10的数字");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (column.getValue().equals("subjectList")) {
|
|
|
+ if (row.get(s) == null) {
|
|
|
+ throw new BizException("专业不能为空");
|
|
|
+ }
|
|
|
+ String[] subjects = row.get(s).toString().split(",");
|
|
|
+ String subjectIds = "";
|
|
|
+ for (String subject : subjects) {
|
|
|
+ boolean has = false;
|
|
|
+ for (Subject subSubject : subSubjects) {
|
|
|
+ if (subject.equals(subSubject.getName())) {
|
|
|
+ has = true;
|
|
|
+ subjectIds = subjectIds + "," + subSubject.getId();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!has) {
|
|
|
+ throw new BizException(subject + "专业不存在,请核查");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ objectMap.put("subjectList", subjectIds.substring(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (column.getValue().equals("type")) {
|
|
|
+ for (SongTypeEnum songType : SongTypeEnum.values()) {
|
|
|
+ if (songType.getMsg().equals(row.get(s).toString())) {
|
|
|
+ objectMap.put("type", songType);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamSong examSong = null;
|
|
|
+ try {
|
|
|
+ examSong = MapUtil.mapToJavaBean(ExamSong.class, objectMap);
|
|
|
+ examSong.setTenantId(tenantId);
|
|
|
+ examSongs.add(examSong);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new BizException("导入数据出错");
|
|
|
+ }
|
|
|
+ this.insert(examSong);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return examSongs;
|
|
|
+ }
|
|
|
}
|