|
@@ -2,10 +2,7 @@ package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.biz.dal.entity.Goods;
|
|
|
-import com.ym.mec.biz.dal.enums.GoodsType;
|
|
|
-import com.ym.mec.biz.dal.enums.StockType;
|
|
|
-import com.ym.mec.biz.dal.enums.TemplateTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.YesOrNoEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.*;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
@@ -23,6 +20,7 @@ import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
@@ -33,53 +31,81 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
-public class TempBuyFreeLiveTheoryCourseServiceImpl extends BaseServiceImpl<Integer, TempBuyFreeLiveTheoryCourse> implements TempBuyFreeLiveTheoryCourseService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private TempBuyFreeLiveTheoryCourseDao tempBuyFreeLiveTheoryCourseDao;
|
|
|
+public class TempBuyFreeLiveTheoryCourseServiceImpl extends BaseServiceImpl<Integer, TempBuyFreeLiveTheoryCourse> implements TempBuyFreeLiveTheoryCourseService {
|
|
|
|
|
|
- @Override
|
|
|
- public BaseDAO<Integer, TempBuyFreeLiveTheoryCourse> getDAO() {
|
|
|
- return tempBuyFreeLiveTheoryCourseDao;
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private TempBuyFreeLiveTheoryCourseDao tempBuyFreeLiveTheoryCourseDao;
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
- public List<TempBuyFreeLiveTheoryCourse> importBuyFreeLiveTheoryCourse(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.BUY_FREE_LIVE_THEORY_COURSE.getMsg());
|
|
|
- List<TempBuyFreeLiveTheoryCourse> tempList = new ArrayList<>();
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Integer, TempBuyFreeLiveTheoryCourse> getDAO() {
|
|
|
+ return tempBuyFreeLiveTheoryCourseDao;
|
|
|
+ }
|
|
|
|
|
|
- for (String e : sheetsListMap.keySet()) {
|
|
|
- List<Map<String, Object>> sheet = sheetsListMap.get(e);
|
|
|
- valueIsNull: for (Map<String, Object> row : sheet) {
|
|
|
- if (row.size() == 0){
|
|
|
- continue;
|
|
|
- }
|
|
|
- JSONObject objectMap = new JSONObject();
|
|
|
- for (String s : row.keySet()) {
|
|
|
- if(!columns.containsKey(s)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- String columnValue = columns.get(s);
|
|
|
- if(null == row.get(s)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- objectMap.put(columnValue, row.get(s));
|
|
|
- }
|
|
|
- TempBuyFreeLiveTheoryCourse course = null;
|
|
|
- try {
|
|
|
- course = JSONObject.parseObject(objectMap.toJSONString(),TempBuyFreeLiveTheoryCourse.class);
|
|
|
- tempList.add(course);
|
|
|
- } catch (Exception ex) {
|
|
|
- throw new BizException("导入数据出错", ex);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public List<String> importBuyFreeLiveTheoryCourse(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.BUY_FREE_LIVE_THEORY_COURSE.getMsg());
|
|
|
+ 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) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
- }
|
|
|
+ TempBuyFreeLiveTheoryCourse course = null;
|
|
|
+ try {
|
|
|
+ course = JSONObject.parseObject(objectMap.toJSONString(), TempBuyFreeLiveTheoryCourse.class);
|
|
|
+ tempList.add(course);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new BizException("导入数据出错", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(errMsg)){
|
|
|
+ return errMsg;
|
|
|
+ }
|
|
|
+ //导入数据库
|
|
|
+ for (TempBuyFreeLiveTheoryCourse temp : tempList) {
|
|
|
+ if (null == temp.getId()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ TempBuyFreeLiveTheoryCourse course = tempBuyFreeLiveTheoryCourseDao.get(temp.getId());
|
|
|
+ LevelEnum byName = LevelEnum.getByName(temp.getRecommendLevel());
|
|
|
+ course.setRecommendLevel(byName.getCode());
|
|
|
+ tempBuyFreeLiveTheoryCourseDao.update(course);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|