|
@@ -0,0 +1,118 @@
|
|
|
+package com.ym.mec.biz.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ym.mec.biz.dal.dao.FinancialExpenditureDao;
|
|
|
+import com.ym.mec.biz.dal.entity.FinancialExpenditure;
|
|
|
+import com.ym.mec.biz.service.FinancialExpenditureService;
|
|
|
+import com.ym.mec.common.dal.BaseDAO;
|
|
|
+import com.ym.mec.common.exception.BizException;
|
|
|
+import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
+import com.ym.mec.util.excel.IniFileUtil;
|
|
|
+import com.ym.mec.util.excel.POIUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+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.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, FinancialExpenditure> implements FinancialExpenditureService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FinancialExpenditureDao financialExpenditureDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Long, FinancialExpenditure> getDAO() {
|
|
|
+ return financialExpenditureDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(FinancialExpenditureServiceImpl.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<FinancialExpenditure> importFinancialExpenditure(MultipartFile file) throws IOException {
|
|
|
+ Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(file.getInputStream(), 2, file.getOriginalFilename());
|
|
|
+ String fileName = file.getOriginalFilename().split("\\.")[0];
|
|
|
+ InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
|
|
|
+ Map<String,String> columns = IniFileUtil.readIniFile(inputStream,fileName);
|
|
|
+ List<FinancialExpenditure> financialExpenditures = new ArrayList<>();
|
|
|
+ Map<String, Integer> organMap = getMap("organization", "name_", "id_", true, String.class, Integer.class);
|
|
|
+ Map<String, Integer> cooperationOrganMap = getMap("cooperation_organ", "name_", "id_", true, String.class, Integer.class);
|
|
|
+ Map<String, Integer> phoneMap = getMap("sys_user", "phone_", "id_", true, String.class, Integer.class);
|
|
|
+ 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 (columnValue.equals("phone")) {
|
|
|
+ if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ LOGGER.error("商品导入异常:手机号不可为空 param:{}",objectMap);
|
|
|
+ continue valueIsNull;
|
|
|
+ }else {
|
|
|
+ Integer integer = phoneMap.get(row.get(s));
|
|
|
+ if(integer == null){
|
|
|
+ LOGGER.error("商品导入异常:手机号校验失败 param:{}",objectMap);
|
|
|
+ continue valueIsNull;
|
|
|
+ }else {
|
|
|
+ objectMap.put("applyUserId", integer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (columnValue.equals("amount")) {
|
|
|
+ if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ LOGGER.error("商品导入异常:费用不可为空 param:{}",objectMap);
|
|
|
+ continue valueIsNull;
|
|
|
+ }else {
|
|
|
+ objectMap.put("amount", row.get(s));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (columnValue.equals("organName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
+ Integer integer = organMap.get(row.get(s));
|
|
|
+ if(integer == null){
|
|
|
+ LOGGER.error("商品导入异常:分部校验失败 param:{}",objectMap);
|
|
|
+ }else {
|
|
|
+ objectMap.put("organId", integer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (columnValue.equals("cooperationOrganName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
+ Integer integer = cooperationOrganMap.get(row.get(s));
|
|
|
+ if(integer == null){
|
|
|
+ LOGGER.error("商品导入异常:合作单位校验失败 param:{}",objectMap);
|
|
|
+ }else {
|
|
|
+ objectMap.put("cooperationOrganId", integer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ objectMap.put(columnValue, row.get(s));
|
|
|
+ }
|
|
|
+ FinancialExpenditure financialExpenditure = null;
|
|
|
+ try {
|
|
|
+ financialExpenditure = JSONObject.parseObject(objectMap.toJSONString(),FinancialExpenditure.class);
|
|
|
+ financialExpenditures.add(financialExpenditure);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new BizException("导入数据出错");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(financialExpenditures.size() != 0){
|
|
|
+ financialExpenditureDao.batchInsert(financialExpenditures);
|
|
|
+ }
|
|
|
+ return financialExpenditures;
|
|
|
+ }
|
|
|
+}
|