|
@@ -1,7 +1,9 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ym.mec.biz.dal.dao.TempLiveTeacherCardDao;
|
|
|
import com.ym.mec.biz.dal.entity.Goods;
|
|
|
+import com.ym.mec.biz.dal.entity.TempLiveTeacherCard;
|
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
@@ -23,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
@@ -36,6 +39,9 @@ public class TempBuyFreeLiveTheoryCourseServiceImpl extends BaseServiceImpl<Inte
|
|
|
@Autowired
|
|
|
private TempBuyFreeLiveTheoryCourseDao tempBuyFreeLiveTheoryCourseDao;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TempLiveTeacherCardDao tempLiveTeacherCardDao;
|
|
|
+
|
|
|
@Override
|
|
|
public BaseDAO<Integer, TempBuyFreeLiveTheoryCourse> getDAO() {
|
|
|
return tempBuyFreeLiveTheoryCourseDao;
|
|
@@ -50,50 +56,47 @@ public class TempBuyFreeLiveTheoryCourseServiceImpl extends BaseServiceImpl<Inte
|
|
|
List<TempBuyFreeLiveTheoryCourse> tempList = new ArrayList<>();
|
|
|
|
|
|
List<String> errMsg = new ArrayList();
|
|
|
- for (String e : sheetsListMap.keySet()) {
|
|
|
- List<Map<String, Object>> sheet = sheetsListMap.get(e);
|
|
|
- valueIsNull:
|
|
|
- for (int i = 0; i < sheet.size(); i++) {
|
|
|
- Map<String, Object> row = sheet.get(i);
|
|
|
- if (row.size() == 0) {
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get("Sheet0");
|
|
|
+
|
|
|
+ for (int i = 0; i < sheet.size(); i++) {
|
|
|
+ Map<String, Object> row = sheet.get(i);
|
|
|
+ if (row.size() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject objectMap = new JSONObject();
|
|
|
+ for (String s : row.keySet()) {
|
|
|
+ String columnValue = columns.get(s);
|
|
|
+ if (StringUtils.isEmpty(columnValue)) {
|
|
|
continue;
|
|
|
}
|
|
|
- JSONObject objectMap = new JSONObject();
|
|
|
- for (String s : row.keySet()) {
|
|
|
- String columnValue = columns.get(s);
|
|
|
- if (StringUtils.isEmpty(columnValue)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (null == row.get(s)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- objectMap.put(columnValue, row.get(s));
|
|
|
- }
|
|
|
- String err = "";
|
|
|
- //校验
|
|
|
- Integer tempId = objectMap.getInteger("id");
|
|
|
- if (null == tempId) {
|
|
|
- err += "ID不能为空/";
|
|
|
- }
|
|
|
- String recommendLevel = objectMap.getString("recommendLevel");
|
|
|
- if (StringUtils.isNotEmpty(recommendLevel) && null == LevelEnum.getByName(recommendLevel.trim())) {
|
|
|
- err += "老师推荐级别列,数据异常(可选值:初级 中级 高级)/";
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(err)) {
|
|
|
- err = "第" + (i + 1) + "行数据异常:" +err.substring(0, err.length() - 1);
|
|
|
- errMsg.add(err);
|
|
|
+ if (null == row.get(s)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+ objectMap.put(columnValue, row.get(s));
|
|
|
+ }
|
|
|
+ String err = "";
|
|
|
+ //校验
|
|
|
+ Integer tempId = objectMap.getInteger("id");
|
|
|
+ if (null == tempId) {
|
|
|
+ err += "ID不能为空/";
|
|
|
+ }
|
|
|
+ String recommendLevel = objectMap.getString("recommendLevel");
|
|
|
+ if (StringUtils.isNotEmpty(recommendLevel) && null == LevelEnum.getByName(recommendLevel.trim())) {
|
|
|
+ err += "老师推荐级别列,数据异常(可选值:初级 中级 高级)/";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(err)) {
|
|
|
+ err = "第" + (i + 1) + "行数据异常:" + err.substring(0, err.length() - 1);
|
|
|
+ errMsg.add(err);
|
|
|
+ }
|
|
|
|
|
|
- TempBuyFreeLiveTheoryCourse course = null;
|
|
|
- try {
|
|
|
- course = JSONObject.parseObject(objectMap.toJSONString(), TempBuyFreeLiveTheoryCourse.class);
|
|
|
- tempList.add(course);
|
|
|
- } catch (Exception ex) {
|
|
|
- throw new BizException("导入数据出错", ex);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ TempBuyFreeLiveTheoryCourse course = JSONObject.parseObject(objectMap.toJSONString(), TempBuyFreeLiveTheoryCourse.class);
|
|
|
+ tempList.add(course);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new BizException("导入数据出错", ex);
|
|
|
}
|
|
|
}
|
|
|
- if(!CollectionUtils.isEmpty(errMsg)){
|
|
|
+ if (!CollectionUtils.isEmpty(errMsg)) {
|
|
|
return errMsg;
|
|
|
}
|
|
|
//导入数据库
|
|
@@ -108,4 +111,77 @@ public class TempBuyFreeLiveTheoryCourseServiceImpl extends BaseServiceImpl<Inte
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public List<String> importLiveTeacherCard(MultipartFile file, Integer id) throws Exception {
|
|
|
+ Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(new ByteArrayInputStream(file.getBytes()), 2, file.getOriginalFilename());
|
|
|
+ InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
+ Map<String, String> columns = IniFileUtil.readIniFile(inputStream, TemplateTypeEnum.LIVE_TEACHER_CARD.getMsg());
|
|
|
+ List<TempLiveTeacherCard> tempList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<String> errMsg = new ArrayList();
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get(0);
|
|
|
+ for (int i = 0; i < sheet.size(); i++) {
|
|
|
+ Map<String, Object> row = sheet.get(i);
|
|
|
+ if (row.size() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject objectMap = new JSONObject();
|
|
|
+ for (String s : row.keySet()) {
|
|
|
+ String columnValue = columns.get(s);
|
|
|
+ if (StringUtils.isEmpty(columnValue)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (null == row.get(s)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ objectMap.put(columnValue, row.get(s));
|
|
|
+ }
|
|
|
+ String err = "";
|
|
|
+ //校验
|
|
|
+ Integer subjectId = objectMap.getInteger("subjectId");
|
|
|
+ if (null == subjectId) {
|
|
|
+ err += "声部id不能为空/";
|
|
|
+ }
|
|
|
+ String level = objectMap.getString("level");
|
|
|
+ if (StringUtils.isNotEmpty(level) && null == LevelEnum.getByName(level.trim())) {
|
|
|
+ err += "老师推荐级别列,数据异常(可选值:初级 中级 高级)/";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(err)) {
|
|
|
+ err = "第" + (i + 1) + "行数据异常:" + err.substring(0, err.length() - 1);
|
|
|
+ errMsg.add(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ TempLiveTeacherCard course = JSONObject.parseObject(objectMap.toJSONString(), TempLiveTeacherCard.class);
|
|
|
+ tempList.add(course);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new BizException("导入数据出错", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(errMsg)) {
|
|
|
+ return errMsg;
|
|
|
+ }
|
|
|
+ //导入数据库
|
|
|
+ for (TempLiveTeacherCard temp : tempList) {
|
|
|
+ if (null == temp.getId()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ LevelEnum byName = LevelEnum.getByName(temp.getLevel());
|
|
|
+ if(null == byName){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ TempLiveTeacherCard card = tempLiveTeacherCardDao.getBySubjectIdAndLevel(temp.getSubjectId(), byName.getCode());
|
|
|
+ if (null == card) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ card.setUsername(temp.getUsername());
|
|
|
+ card.setAvatar(temp.getAvatar());
|
|
|
+ card.setIntroduction(temp.getIntroduction());
|
|
|
+ card.setMusicNames(temp.getMusicNames());
|
|
|
+ tempLiveTeacherCardDao.update(card);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|