|
@@ -1,16 +1,21 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.Map.Entry;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
+import com.ym.mec.biz.dal.enums.*;
|
|
|
+import com.ym.mec.util.date.DateUtil;
|
|
|
+import com.ym.mec.util.excel.IniFileUtil;
|
|
|
+import com.ym.mec.util.excel.POIUtil;
|
|
|
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.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -24,17 +29,6 @@ import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
|
|
|
import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
|
|
|
import com.ym.mec.biz.dal.dto.PageInfoOrder;
|
|
|
import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
|
|
|
-import com.ym.mec.biz.dal.entity.Goods;
|
|
|
-import com.ym.mec.biz.dal.entity.SellOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
|
|
|
-import com.ym.mec.biz.dal.enums.AccountType;
|
|
|
-import com.ym.mec.biz.dal.enums.AuditStatusEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.GroupType;
|
|
|
-import com.ym.mec.biz.dal.enums.OrderTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.SellTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.SporadicChargeTypeEnum;
|
|
|
import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
|
|
|
import com.ym.mec.biz.service.GoodsService;
|
|
|
import com.ym.mec.biz.service.SellOrderService;
|
|
@@ -44,6 +38,7 @@ import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@Service
|
|
|
public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentRouteOrder> implements StudentPaymentRouteOrderService {
|
|
@@ -292,4 +287,126 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<StudentPaymentRouteOrder> importRouteOrder(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.ROUTE_ORDER.getMsg());
|
|
|
+ List<StudentPaymentRouteOrder> studentPaymentRouteOrders = 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);
|
|
|
+ for (String e : sheetsListMap.keySet()) {
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get(e);
|
|
|
+ List<Object> collect = sheet.stream().map(m -> m.get("交易流水号")).collect(Collectors.toList());
|
|
|
+ if(collect == null || collect.size() == 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> list = studentPaymentRouteOrderDao.countByTransNo(collect);
|
|
|
+ if(list != null && list.size() > 0){
|
|
|
+ throw new BizException("导入数据错误 重复的交易流水号:{}",list.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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("transNo")) {
|
|
|
+ if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ continue valueIsNull;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (columnValue.equals("merNo")) {
|
|
|
+ if(StringUtils.isEmpty(row.get(s).toString())){
|
|
|
+ continue valueIsNull;
|
|
|
+ }else {
|
|
|
+ objectMap.put("merNo", row.get(s));
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (columnValue.equals("organName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
+ Integer integer = organMap.get(row.get(s));
|
|
|
+ if(integer == null){
|
|
|
+ continue valueIsNull;
|
|
|
+ }else {
|
|
|
+ objectMap.put("routeOrganId", integer);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (columnValue.equals("cooperationOrganName") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
+ Integer integer = cooperationOrganMap.get(row.get(s));
|
|
|
+ if(integer != null){
|
|
|
+ objectMap.put("schoolId", integer);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (columnValue.equals("payTime") && StringUtils.isNotEmpty(row.get(s).toString())) {
|
|
|
+ String toString = row.get(s).toString();
|
|
|
+ if(StringUtils.isNotEmpty(toString)){
|
|
|
+ Date date = DateUtil.stringToDate(toString, DateUtil.DEFAULT_PATTERN);
|
|
|
+ if(date == null){
|
|
|
+ throw new BizException("导入数据错误 交易日期格式错误");
|
|
|
+ }else {
|
|
|
+ objectMap.put(columnValue, DateUtil.format(date,DateUtil.DEFAULT_PATTERN));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ objectMap.put(columnValue, row.get(s));
|
|
|
+ }
|
|
|
+ StudentPaymentRouteOrder studentPaymentRouteOrder = null;
|
|
|
+ try {
|
|
|
+ studentPaymentRouteOrder = JSONObject.parseObject(objectMap.toJSONString(),StudentPaymentRouteOrder.class);
|
|
|
+ //是否有销售金额
|
|
|
+ if(studentPaymentRouteOrder.getSaleAmount() != null && studentPaymentRouteOrder.getSaleAmount().longValue() != 0l){
|
|
|
+ String goodsIds = studentPaymentRouteOrder.getGoodsIds();
|
|
|
+ String goodsNums = studentPaymentRouteOrder.getGoodsNums();
|
|
|
+ if(StringUtils.isAllEmpty(goodsIds,goodsNums)){
|
|
|
+ throw new BizException("导入失败:有销售金额时商品编号和数量必填");
|
|
|
+ }
|
|
|
+ List<String> goodsIdList = new ArrayList(Arrays.asList(goodsIds.split(",")));
|
|
|
+ List<String> goodsNumList = new ArrayList(Arrays.asList(goodsNums.split(",")));
|
|
|
+ if(goodsIdList.size() != goodsNumList.size()){
|
|
|
+ throw new BizException("导入失败:商品编号和商品数量不一致");
|
|
|
+ }
|
|
|
+ JSONArray goodsJSON = new JSONArray();
|
|
|
+ for (int i = 0; i < goodsIdList.size(); i++) {
|
|
|
+ if(!goodsDao.findByIdAndStatus(goodsIdList.get(i), 1)){
|
|
|
+ throw new BizException("导入失败:商品编号{}不存在",goodsIdList.get(i));
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ int goodsNum = Integer.parseInt(goodsNumList.get(i));
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put(goodsIdList.get(i),goodsNum);
|
|
|
+ goodsJSON.add(jsonObject);
|
|
|
+ }catch (Exception e1){
|
|
|
+ throw new BizException("导入失败:商品数量{}填写错误",goodsNumList.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ studentPaymentRouteOrder.setGoodsJson(goodsJSON.toJSONString());
|
|
|
+ }
|
|
|
+ studentPaymentRouteOrders.add(studentPaymentRouteOrder);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new BizException("导入数据出错,请检查Excel表格");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(studentPaymentRouteOrders.size() != 0){
|
|
|
+ Map<String, List<StudentPaymentRouteOrder>> stringListMap = studentPaymentRouteOrders.stream().collect(Collectors.groupingBy(StudentPaymentRouteOrder::getOrderNo));
|
|
|
+ if(sheetsListMap.size() != studentPaymentRouteOrders.size()){
|
|
|
+ throw new BizException("导入失败:请勿录入重复的交易流水号");
|
|
|
+ }
|
|
|
+ studentPaymentOrderDao.batchInsert(studentPaymentRouteOrders);
|
|
|
+ }
|
|
|
+ return studentPaymentRouteOrders;
|
|
|
+ }
|
|
|
+
|
|
|
}
|