|
|
@@ -1,32 +1,46 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+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;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SellOrderDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
|
|
|
+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.*;
|
|
|
import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
|
|
|
import com.ym.mec.biz.service.GoodsService;
|
|
|
import com.ym.mec.biz.service.SellOrderService;
|
|
|
import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
+import com.ym.mec.common.page.PageInfo;
|
|
|
+import com.ym.mec.common.page.QueryInfo;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
-import org.apache.ibatis.javassist.expr.NewArray;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Isolation;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@Service
|
|
|
public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentRouteOrder> implements StudentPaymentRouteOrderService {
|
|
|
@@ -54,6 +68,26 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public PageInfo<StudentPaymentRouteOrder> queryAuditList(QueryInfo queryInfo) {
|
|
|
+ PageInfo<StudentPaymentRouteOrder> pageInfo = new PageInfo<StudentPaymentRouteOrder>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ MapUtil.populateMap(params, queryInfo);
|
|
|
+
|
|
|
+ List<StudentPaymentRouteOrder> dataList = null;
|
|
|
+ int count = studentPaymentRouteOrderDao.queryAuditCount(params);
|
|
|
+ if (count > 0) {
|
|
|
+ pageInfo.setTotal(count);
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
+ dataList = studentPaymentRouteOrderDao.queryAuditPage(params);
|
|
|
+ }
|
|
|
+ if (count == 0) {
|
|
|
+ dataList = new ArrayList<StudentPaymentRouteOrder>();
|
|
|
+ }
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public PageInfoOrder<StudentPaymentRouteOrderDto> OrderQueryPage(StudentPaymentOrderQueryInfo queryInfo) {
|
|
|
PageInfoOrder<StudentPaymentRouteOrderDto> pageInfo = new PageInfoOrder<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
@@ -88,107 +122,163 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
- public StudentPaymentRouteOrderDto addOutOrder(StudentPaymentRouteOrderDto studentPaymentRouteOrderDto) {
|
|
|
+ public StudentPaymentRouteOrder addOutOrder(StudentPaymentRouteOrder studentPaymentRouteOrder) {
|
|
|
Date nowDate = new Date();
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
- studentPaymentRouteOrderDto.setType(OrderTypeEnum.OUTORDER);
|
|
|
- studentPaymentRouteOrderDto.setMerNos(studentPaymentRouteOrderDto.getMerNo());
|
|
|
- studentPaymentRouteOrderDto.setOrderNo(orderNo);
|
|
|
- studentPaymentRouteOrderDto.setGroupType(GroupType.OUTORDER);
|
|
|
- studentPaymentRouteOrderDto.setRouteOrganId(studentPaymentRouteOrderDto.getOrganId());
|
|
|
- studentPaymentRouteOrderDto.setExpectAmount(studentPaymentRouteOrderDto.getActualAmount());
|
|
|
- studentPaymentRouteOrderDto.setStatus(DealStatusEnum.SUCCESS);
|
|
|
- studentPaymentRouteOrderDto.setCreateTime(studentPaymentRouteOrderDto.getPayTime());
|
|
|
- studentPaymentRouteOrderDto.setUpdateTime(nowDate);
|
|
|
-
|
|
|
- studentPaymentRouteOrderDao.insertOrder(studentPaymentRouteOrderDto);
|
|
|
- StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
|
|
|
studentPaymentRouteOrder.setOrderNo(orderNo);
|
|
|
- studentPaymentRouteOrder.setMerNo(studentPaymentRouteOrderDto.getMerNo());
|
|
|
- studentPaymentRouteOrder.setRouteOrganId(studentPaymentRouteOrderDto.getOrganId());
|
|
|
- studentPaymentRouteOrder.setRouteAmount(studentPaymentRouteOrderDto.getActualAmount());
|
|
|
+ studentPaymentRouteOrder.setAuditStatus(AuditStatusEnum.ING);
|
|
|
+ studentPaymentRouteOrder.setCreateTime(nowDate);
|
|
|
+ studentPaymentRouteOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentRouteOrder.setRouteAmount(studentPaymentRouteOrder.getSaleAmount().add(studentPaymentRouteOrder.getServiceAmount()));
|
|
|
studentPaymentRouteOrder.setRouteBalanceAmount(BigDecimal.ZERO);
|
|
|
studentPaymentRouteOrder.setFeeFlag("N");
|
|
|
+
|
|
|
studentPaymentRouteOrderDao.insert(studentPaymentRouteOrder);
|
|
|
-
|
|
|
- if (studentPaymentRouteOrderDto.getGoodies() != null && studentPaymentRouteOrderDto.getGoodies().size() > 0) {
|
|
|
- BigDecimal hasRouteAmount = BigDecimal.ZERO;
|
|
|
- BigDecimal goodsTotalPrice = BigDecimal.ZERO;
|
|
|
-
|
|
|
- List<Integer> goodsIdList = new ArrayList<>();
|
|
|
- for (Map.Entry<Integer, Integer> goodsMap : studentPaymentRouteOrderDto.getGoodies().entrySet()) {
|
|
|
- Goods goods = goodsDao.get(goodsMap.getKey());
|
|
|
- goodsTotalPrice = goodsTotalPrice.add(goods.getGroupPurchasePrice().multiply(new BigDecimal(goodsMap.getValue())));
|
|
|
- for (int i = 0; i < goodsMap.getValue(); i++) {
|
|
|
- goodsIdList.add(goodsMap.getKey());
|
|
|
- }
|
|
|
- }
|
|
|
- List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
|
|
|
-
|
|
|
- int i = 1;
|
|
|
- for (Map.Entry<Integer, Integer> goodsMap : studentPaymentRouteOrderDto.getGoodies().entrySet()) {
|
|
|
- Goods goods = goodsDao.get(goodsMap.getKey());
|
|
|
-
|
|
|
- BigDecimal actualAmount = BigDecimal.ZERO;
|
|
|
- if (goodsTotalPrice.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
- actualAmount = studentPaymentRouteOrderDto.getGoodsAmount().multiply(goods.getGroupPurchasePrice().multiply(new BigDecimal(goodsMap.getValue()))).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- }
|
|
|
- if (i == studentPaymentRouteOrderDto.getGoodies().size()) {
|
|
|
- actualAmount = studentPaymentRouteOrderDto.getGoodsAmount().subtract(hasRouteAmount);
|
|
|
- }
|
|
|
- hasRouteAmount = hasRouteAmount.add(actualAmount);
|
|
|
- i++;
|
|
|
-
|
|
|
- int complementNum = goods.getComplementGoodsIdList() == null ? 1 : goods.getComplementGoodsIdList().split(",").length;
|
|
|
- int goodsNum = goodsMap.getValue() * complementNum;
|
|
|
- BigDecimal complementPrice = goods.getGroupPurchasePrice().multiply(new BigDecimal(goodsMap.getValue()));
|
|
|
- Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
|
|
|
- complementGoodsPrice.put(goods.getId(), goods.getGroupPurchasePrice());
|
|
|
- if (goods.getComplementGoodsIdList() != null) {
|
|
|
- List<Goods> complementGoodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
|
|
|
- complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
|
|
|
- complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(goodsMap.getValue()));
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
|
|
|
- for (SellOrder sellOrder : sellOrderList) {
|
|
|
- if (!goodsMap.getKey().equals(sellOrder.getParentGoodsId()) && !goodsMap.getKey().equals(sellOrder.getGoodsId())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
|
|
|
- if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(actualAmount).divide(complementPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- }
|
|
|
- goodsNum = goodsNum - sellOrder.getNum();
|
|
|
- if (goodsNum <= 0) {
|
|
|
- sellOrderActualAmount = actualAmount.subtract(hasRouteSellOrderActualAmount);
|
|
|
- }
|
|
|
- hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
|
|
|
-
|
|
|
- sellOrder.setSellTime(studentPaymentRouteOrderDto.getPayTime());
|
|
|
- sellOrder.setOrganId(studentPaymentRouteOrderDto.getOrganId());
|
|
|
- sellOrder.setCooperationOrganId(studentPaymentRouteOrderDto.getSchoolId());
|
|
|
- sellOrder.setTransNo(studentPaymentRouteOrderDto.getTransNo());
|
|
|
- sellOrder.setOrderId(studentPaymentRouteOrderDto.getId());
|
|
|
- sellOrder.setOrderNo(orderNo);
|
|
|
- sellOrder.setActualAmount(sellOrderActualAmount);
|
|
|
- sellOrder.setBalanceAmount(BigDecimal.ZERO);
|
|
|
- sellOrder.setExpectAmount(sellOrderActualAmount);
|
|
|
- sellOrder.setUserId(studentPaymentRouteOrderDto.getUserId());
|
|
|
- sellOrder.setPaymentChannel(studentPaymentRouteOrderDto.getPaymentChannel());
|
|
|
- sellOrder.setMerNo(studentPaymentRouteOrderDto.getMerNos());
|
|
|
- sellOrder.setSellTime(studentPaymentRouteOrderDto.getCreateTime());
|
|
|
- sellOrder.setCreateIme(nowDate);
|
|
|
- sellOrder.setUpdateTime(nowDate);
|
|
|
- sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
|
|
|
- }
|
|
|
- }
|
|
|
- sellOrderDao.batchInsert(sellOrderList);
|
|
|
- }
|
|
|
- return studentPaymentRouteOrderDto;
|
|
|
+
|
|
|
+ return studentPaymentRouteOrder;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public StudentPaymentRouteOrder updateOutOrder(StudentPaymentRouteOrder studentPaymentRouteOrder) {
|
|
|
+ Date nowDate = new Date();
|
|
|
+ studentPaymentRouteOrder.setAuditStatus(AuditStatusEnum.ING);
|
|
|
+ studentPaymentRouteOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentRouteOrder.setRouteAmount(studentPaymentRouteOrder.getSaleAmount().add(studentPaymentRouteOrder.getServiceAmount()));
|
|
|
+ studentPaymentRouteOrder.setRouteBalanceAmount(BigDecimal.ZERO);
|
|
|
+ studentPaymentRouteOrder.setFeeFlag("N");
|
|
|
+
|
|
|
+ studentPaymentRouteOrderDao.update(studentPaymentRouteOrder);
|
|
|
+
|
|
|
+ return studentPaymentRouteOrder;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public boolean auditOutOrder(Long studentPaymentRouteOrderId, AuditStatusEnum auditStatus, String memo, Integer operatorId) {
|
|
|
+ StudentPaymentRouteOrder studentPaymentRouteOrder = studentPaymentRouteOrderDao.get(studentPaymentRouteOrderId);
|
|
|
+ if(studentPaymentRouteOrder == null){
|
|
|
+ throw new BizException("查询订单信息失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(studentPaymentRouteOrder.getAuditStatus() != AuditStatusEnum.ING){
|
|
|
+ throw new BizException("只有“审核中”的订单才能审核");
|
|
|
+ }
|
|
|
+
|
|
|
+ Date nowDate = new Date();
|
|
|
+
|
|
|
+ studentPaymentRouteOrder.setUpdateBy(operatorId);
|
|
|
+ studentPaymentRouteOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentRouteOrder.setMemo(memo);
|
|
|
+ studentPaymentRouteOrder.setAuditStatus(auditStatus);
|
|
|
+
|
|
|
+ studentPaymentRouteOrderDao.update(studentPaymentRouteOrder);
|
|
|
+
|
|
|
+ if(auditStatus == AuditStatusEnum.PASS){
|
|
|
+ StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
+ studentPaymentOrder.setActualAmount(studentPaymentRouteOrder.getRouteAmount());
|
|
|
+ studentPaymentOrder.setMusicGroupId(studentPaymentRouteOrder.getSchoolId()+ "");
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.OUTORDER);
|
|
|
+ studentPaymentOrder.setMerNos(studentPaymentRouteOrder.getMerNo());
|
|
|
+ studentPaymentOrder.setOrderNo(studentPaymentRouteOrder.getOrderNo());
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.OUTORDER);
|
|
|
+ studentPaymentOrder.setOrganId(studentPaymentRouteOrder.getRouteOrganId());
|
|
|
+ studentPaymentOrder.setExpectAmount(studentPaymentRouteOrder.getRouteAmount());
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ studentPaymentOrder.setCreateTime(studentPaymentRouteOrder.getPayTime());
|
|
|
+ studentPaymentOrder.setUpdateTime(nowDate);
|
|
|
+ studentPaymentOrder.setMemo(studentPaymentRouteOrder.getMemo());
|
|
|
+ studentPaymentOrder.setUserId(studentPaymentRouteOrder.getUserId());
|
|
|
+ studentPaymentOrder.setPayTime(studentPaymentRouteOrder.getPayTime());
|
|
|
+
|
|
|
+ studentPaymentRouteOrderDao.insertOrder(studentPaymentOrder);
|
|
|
+
|
|
|
+ if (StringUtils.isNoneBlank(studentPaymentRouteOrder.getGoodsJson())) {
|
|
|
+ BigDecimal hasRouteAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal goodsTotalPrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ List<Integer> goodsIdList = new ArrayList<>();
|
|
|
+ JSONObject jsonObj = JSON.parseObject(studentPaymentRouteOrder.getGoodsJson());
|
|
|
+ for (Entry<String, Object> goodsMap : jsonObj.entrySet()) {
|
|
|
+ Integer goodsId = Integer.parseInt(goodsMap.getKey());
|
|
|
+ Integer nums = Integer.parseInt(goodsMap.getValue().toString());
|
|
|
+ Goods goods = goodsDao.get(goodsId);
|
|
|
+ goodsTotalPrice = goodsTotalPrice.add(goods.getGroupPurchasePrice().multiply(new BigDecimal(nums)));
|
|
|
+ for (int i = 0; i < nums; i++) {
|
|
|
+ goodsIdList.add(goodsId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
|
|
|
+
|
|
|
+ int i = 1;
|
|
|
+ for (Entry<String, Object> goodsMap : jsonObj.entrySet()) {
|
|
|
+ Integer goodsId = Integer.parseInt(goodsMap.getKey());
|
|
|
+ Integer nums = Integer.parseInt(goodsMap.getValue().toString());
|
|
|
+ Goods goods = goodsDao.get(goodsId);
|
|
|
+
|
|
|
+ BigDecimal actualAmount = BigDecimal.ZERO;
|
|
|
+ if (goodsTotalPrice.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ actualAmount = studentPaymentRouteOrder.getSaleAmount().multiply(goods.getGroupPurchasePrice().multiply(new BigDecimal(nums))).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ if (i == jsonObj.entrySet().size()) {
|
|
|
+ actualAmount = studentPaymentRouteOrder.getSaleAmount().subtract(hasRouteAmount);
|
|
|
+ }
|
|
|
+ hasRouteAmount = hasRouteAmount.add(actualAmount);
|
|
|
+ i++;
|
|
|
+
|
|
|
+ int complementNum = goods.getComplementGoodsIdList() == null ? 1 : goods.getComplementGoodsIdList().split(",").length;
|
|
|
+ int goodsNum = nums * complementNum;
|
|
|
+ BigDecimal complementPrice = goods.getGroupPurchasePrice().multiply(new BigDecimal(nums));
|
|
|
+ Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
|
|
|
+ complementGoodsPrice.put(goods.getId(), goods.getGroupPurchasePrice());
|
|
|
+ if (goods.getComplementGoodsIdList() != null) {
|
|
|
+ List<Goods> complementGoodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
|
|
|
+ complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
|
|
|
+ complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(nums));
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
|
|
|
+ for (SellOrder sellOrder : sellOrderList) {
|
|
|
+ if (!goodsMap.getKey().equals(sellOrder.getParentGoodsId()) && !goodsMap.getKey().equals(sellOrder.getGoodsId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
|
|
|
+ if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(actualAmount).divide(complementPrice, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ goodsNum = goodsNum - sellOrder.getNum();
|
|
|
+ if (goodsNum <= 0) {
|
|
|
+ sellOrderActualAmount = actualAmount.subtract(hasRouteSellOrderActualAmount);
|
|
|
+ }
|
|
|
+ hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
|
|
|
+
|
|
|
+ sellOrder.setSellTime(studentPaymentRouteOrder.getPayTime());
|
|
|
+ sellOrder.setOrganId(studentPaymentRouteOrder.getRouteOrganId());
|
|
|
+ sellOrder.setCooperationOrganId(studentPaymentRouteOrder.getSchoolId());
|
|
|
+ sellOrder.setTransNo(studentPaymentRouteOrder.getTransNo());
|
|
|
+ sellOrder.setOrderId(studentPaymentOrder.getId());
|
|
|
+ sellOrder.setOrderNo(studentPaymentRouteOrder.getOrderNo());
|
|
|
+ sellOrder.setActualAmount(sellOrderActualAmount);
|
|
|
+ sellOrder.setBalanceAmount(BigDecimal.ZERO);
|
|
|
+ sellOrder.setExpectAmount(sellOrderActualAmount);
|
|
|
+ sellOrder.setUserId(studentPaymentRouteOrder.getUserId());
|
|
|
+ sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
+ sellOrder.setMerNo(studentPaymentRouteOrder.getMerNo());
|
|
|
+ sellOrder.setSellTime(studentPaymentRouteOrder.getCreateTime());
|
|
|
+ sellOrder.setCreateIme(nowDate);
|
|
|
+ sellOrder.setUpdateTime(nowDate);
|
|
|
+ sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sellOrderDao.batchInsert(sellOrderList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public StudentPaymentRouteOrder addRouteOrder(String orderNo, Integer routeOrganId, BigDecimal routeBalanceAmount) {
|
|
|
StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
|
|
|
studentPaymentRouteOrder.setOrderNo(orderNo);
|
|
|
@@ -219,4 +309,125 @@ 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 = JSONObject.parseObject(objectMap.toJSONString(),StudentPaymentRouteOrder.class);
|
|
|
+ //是否有销售金额
|
|
|
+ if(studentPaymentRouteOrder.getSaleAmount() != null && studentPaymentRouteOrder.getSaleAmount().longValue() != 0l){
|
|
|
+ String goodsIds = studentPaymentRouteOrder.getGoodsIds();
|
|
|
+ String goodsNums = studentPaymentRouteOrder.getGoodsNums();
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(goodsNums)){
|
|
|
+ throw new BizException("导入失败:有销售金额时商品数量必填");
|
|
|
+ }
|
|
|
+ if(StringUtils.isEmpty(goodsIds)){
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(studentPaymentRouteOrders.size() > 0){
|
|
|
+ Map<String, List<StudentPaymentRouteOrder>> stringListMap = studentPaymentRouteOrders.stream().collect(Collectors.groupingBy(StudentPaymentRouteOrder::getTransNo));
|
|
|
+ if(stringListMap.size() != studentPaymentRouteOrders.size()){
|
|
|
+ throw new BizException("导入失败:请勿录入重复的交易流水号");
|
|
|
+ }
|
|
|
+ studentPaymentRouteOrderDao.batchAdd(studentPaymentRouteOrders);
|
|
|
+ }
|
|
|
+ return studentPaymentRouteOrders;
|
|
|
+ }
|
|
|
+
|
|
|
}
|