|
@@ -3,8 +3,10 @@ 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.HumanCost;
|
|
|
import com.ym.mec.biz.dal.entity.TempLiveTeacherCard;
|
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
|
+import com.ym.mec.biz.service.HumanCostService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
@@ -29,6 +31,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -42,6 +45,9 @@ public class TempBuyFreeLiveTheoryCourseServiceImpl extends BaseServiceImpl<Inte
|
|
|
@Resource
|
|
|
private TempLiveTeacherCardDao tempLiveTeacherCardDao;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private HumanCostService humanCostService;
|
|
|
+
|
|
|
@Override
|
|
|
public BaseDAO<Integer, TempBuyFreeLiveTheoryCourse> getDAO() {
|
|
|
return tempBuyFreeLiveTheoryCourseDao;
|
|
@@ -56,46 +62,50 @@ public class TempBuyFreeLiveTheoryCourseServiceImpl extends BaseServiceImpl<Inte
|
|
|
List<TempBuyFreeLiveTheoryCourse> tempList = new ArrayList<>();
|
|
|
|
|
|
List<String> errMsg = new ArrayList();
|
|
|
- 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)) {
|
|
|
+ for (String sheetName : sheetsListMap.keySet()) {
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get(sheetName);
|
|
|
+ for (int i = 0; i < sheet.size(); i++) {
|
|
|
+ Map<String, Object> row = sheet.get(i);
|
|
|
+ if (row.size() == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (null == row.get(s)) {
|
|
|
- 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);
|
|
|
}
|
|
|
- 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);
|
|
|
- }
|
|
|
|
|
|
- try {
|
|
|
- TempBuyFreeLiveTheoryCourse 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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get("Sheet0");
|
|
|
+
|
|
|
+
|
|
|
if (!CollectionUtils.isEmpty(errMsg)) {
|
|
|
return errMsg;
|
|
|
}
|
|
@@ -187,6 +197,78 @@ public class TempBuyFreeLiveTheoryCourseServiceImpl extends BaseServiceImpl<Inte
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<String> importHumanCost(MultipartFile file) 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.ADDITIONAL_IMPORT.getMsg());
|
|
|
+ Integer tenantId = TenantContextHolder.getTenantId();
|
|
|
+ Map<String, Integer> organMap = getMap("organization", "name_", "id_", true,tenantId, String.class, Integer.class);
|
|
|
+ List<HumanCost> humanCosts = new ArrayList<>();
|
|
|
+ List<String> errMsg = new ArrayList();
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (String sheetName : sheetsListMap.keySet()) {
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get(sheetName);
|
|
|
+ for (int i = 0; i < sheet.size(); i++) {
|
|
|
+ int rowNum = i + 2;
|
|
|
+ Map<String, Object> row = sheet.get(i);
|
|
|
+ if (row.size() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject objectMap = new JSONObject();
|
|
|
+ valueIsNull: for (String s : row.keySet()) {
|
|
|
+ String columnValue = columns.get(s);
|
|
|
+ if (StringUtils.isEmpty(columnValue)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (null == row.get(s)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (columnValue.equals("organName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
+ Integer integer = organMap.get(row.get(s));
|
|
|
+ if (integer == null) {
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:分部名称不存在;");
|
|
|
+ continue valueIsNull;
|
|
|
+ } else {
|
|
|
+ objectMap.put("organId", integer);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (columnValue.equals("humanCostType")) {
|
|
|
+ if (StringUtils.isEmpty(row.get(s).toString())) {
|
|
|
+ sb.append("第" + rowNum).append("行数据导入失败:收支类型不存在;");
|
|
|
+ continue valueIsNull;
|
|
|
+ } else {
|
|
|
+ for (HumanCostTypeEnum costTypeEnum : HumanCostTypeEnum.values()) {
|
|
|
+ if (costTypeEnum.getMsg().equals(row.get(s).toString())) {
|
|
|
+ objectMap.put(columnValue, costTypeEnum);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ objectMap.put(columnValue, row.get(s));
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ HumanCost cost = JSONObject.parseObject(objectMap.toJSONString(), HumanCost.class);
|
|
|
+ humanCosts.add(cost);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new BizException("导入数据出错", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(errMsg)) {
|
|
|
+ return errMsg;
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(humanCosts)){
|
|
|
+ humanCostService.saveBatch(humanCosts);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private String getMusicContent(String musicContent) {
|
|
|
if (StringUtils.isEmpty(musicContent)) {
|
|
|
return null;
|