|
@@ -32,10 +32,12 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import ma.glasnost.orika.MapperFacade;
|
|
|
import ma.glasnost.orika.MapperFactory;
|
|
|
import ma.glasnost.orika.impl.DefaultMapperFactory;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
|
import org.springframework.aop.framework.AopContext;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -46,6 +48,8 @@ import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.function.Consumer;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -713,30 +717,71 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void addOrderListByFile(MultipartFile multipartFile){
|
|
|
+ public List<OrderFileVO> addOrderListByFile(MultipartFile multipartFile){
|
|
|
//获取订单
|
|
|
- List<Order> orderList = getOrderListByFile(multipartFile);
|
|
|
+ List<Order> fileOrderList = getOrderListByFile(multipartFile);
|
|
|
+ //需要支付的订单
|
|
|
+ List<Order> orderList = new ArrayList<>();
|
|
|
+ //重复订单
|
|
|
+ List<OrderFileVO> list = new ArrayList<>();
|
|
|
+ getGroupByOrderList(fileOrderList,orderGroup ->{
|
|
|
+ if (orderGroup.size() == 1){
|
|
|
+ orderList.addAll(orderGroup);
|
|
|
+ }else {
|
|
|
+ orderGroup.forEach(order -> {
|
|
|
+ list.add(getNoPayOrder(order,"该用户重复不进行充值"));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (CollectionUtils.isEmpty(orderList)){
|
|
|
+ throw new CustomException("表格都是重复数据,请检查订单");
|
|
|
+ }
|
|
|
//获取用户信息
|
|
|
List<Staff> staffList = staffService.selectStaffByPhoneList(orderList.stream().map(Order::getUserPhone).collect(Collectors.toList()));
|
|
|
if (CollectionUtils.isEmpty(staffList)){
|
|
|
throw new CustomException("获取到的用户信息为空,请检查表格信息");
|
|
|
}
|
|
|
- //填充订单信息做校验
|
|
|
- orderList.forEach(order -> enhanceOrder(order,staffList));
|
|
|
+ //填充订单信息做校验/删除离职订单
|
|
|
+ Iterator<Order> iterator = orderList.iterator();
|
|
|
+ while (iterator.hasNext()){
|
|
|
+ Order nextOrder = iterator.next();
|
|
|
+ if (!enhanceOrder(nextOrder,staffList)){
|
|
|
+ list.add(getNoPayOrder(nextOrder,"该用户已离职不进行充值"));
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
//上传订单文件
|
|
|
String batchNo = uploadOrderExcel(multipartFile);
|
|
|
List<MsgLog> msgLogs;
|
|
|
- try {
|
|
|
- //批量添加订单
|
|
|
- this.saveBatch(orderList);
|
|
|
- //生成消息日志
|
|
|
- msgLogs = orderList.stream().map(this::enhanceMsgLog).collect(Collectors.toList());
|
|
|
- //批量添加消息日志
|
|
|
- msgLogService.saveBatch(msgLogs);
|
|
|
- }catch (Exception e){
|
|
|
- sysFileService.removeByBatchNo(batchNo);
|
|
|
- throw new CustomException("数据库异常请联系管理员,异常信息"+e.getMessage());
|
|
|
+ if (CollectionUtils.isNotEmpty(orderList)){
|
|
|
+ try {
|
|
|
+ //批量添加订单
|
|
|
+ this.saveBatch(orderList);
|
|
|
+ //生成消息日志
|
|
|
+ msgLogs = orderList.stream().map(this::enhanceMsgLog).collect(Collectors.toList());
|
|
|
+ //批量添加消息日志
|
|
|
+ msgLogService.saveBatch(msgLogs);
|
|
|
+ }catch (Exception e){
|
|
|
+ sysFileService.removeByBatchNo(batchNo);
|
|
|
+ throw new CustomException("数据库异常请联系管理员,异常信息"+e.getMessage());
|
|
|
+ }
|
|
|
+ this.sendMessage(orderList,msgLogs);
|
|
|
+ try {
|
|
|
+ this.updateBatchById(orderList);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("修改订单状态失败"+e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 发送消息
|
|
|
+ * @param orderList
|
|
|
+ * @param msgLogs
|
|
|
+ */
|
|
|
+ public void sendMessage(List<Order> orderList,List<MsgLog> msgLogs){
|
|
|
AtomicBoolean b = new AtomicBoolean(true);
|
|
|
msgLogs.forEach(msgLog -> {
|
|
|
try {
|
|
@@ -756,12 +801,33 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
order.setOrderFlag(OrderStatus.PAYMENT_ERROR_DEBIT.getCode());
|
|
|
}
|
|
|
});
|
|
|
- try {
|
|
|
- this.updateBatchById(orderList);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("修改订单状态失败"+e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分组订单
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void getGroupByOrderList(List<Order> list, Consumer<List<Order>> consumer){
|
|
|
+ Map<String, List<Order>> collect = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(o -> o.getUserName() + "_" + o.getUserPhone()));
|
|
|
+ for (String key:collect.keySet()) {
|
|
|
+ consumer.accept(collect.get(key));
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成不需要支付的订单
|
|
|
+ * @param order
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public OrderFileVO getNoPayOrder(Order order,String errorMessage){
|
|
|
+ OrderFileVO orderFileVO = BeanMapperUtils.map(order, OrderFileVO.class);
|
|
|
+ orderFileVO.setErrorMessage(errorMessage);
|
|
|
+ return orderFileVO;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -794,7 +860,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
* @param order
|
|
|
* @param staffList
|
|
|
*/
|
|
|
- public void enhanceOrder(Order order,List<Staff> staffList){
|
|
|
+ public boolean enhanceOrder(Order order,List<Staff> staffList){
|
|
|
Assert.check(StringUtils.isNotBlank(order.getUserName()),"用户名称不能为空");
|
|
|
Assert.check(StringUtils.isNotBlank(order.getUserPhone()),"用户手机号不能为空");
|
|
|
Assert.check(null != order.getMoney() && order.getMoney().compareTo(BigDecimal.ZERO) != 0,"请输入订单金额");
|
|
@@ -807,7 +873,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
Staff staff = staffList.stream().filter(s -> s.getContacts().equals(order.getUserPhone())).findAny()
|
|
|
.orElseThrow(() -> new CustomException("用户信息:" + order.getUserName() + "不存在"));
|
|
|
- Assert.check(staff.getIsSuccess(),"人员"+staff.getUsername()+"未同步失败或同步失败,请手动同步人员信息");
|
|
|
+ if (0L == staff.getStatus()){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Assert.check(staff.getIsSuccess(),"人员:"+staff.getName()+"未同步或者同步失败,请手动同步人员信息");
|
|
|
order.setUserId(staff.getSId());
|
|
|
order.setIdentity(staff.getIdentity());
|
|
|
order.setTopRadio(staff.getProportion());
|
|
@@ -821,9 +890,15 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
order.setOrderFlag(OrderStatus.SUCCESS.getCode());
|
|
|
String orderNumber = TopApiConfiger.getOrderNumber();
|
|
|
order.setOrderNumber(orderNumber);
|
|
|
-
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增强消息日志
|
|
|
+ * @param order
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public MsgLog enhanceMsgLog(Order order){
|
|
|
Long seq = System.currentTimeMillis();
|
|
|
ChargeVO chargeVo = new ChargeVO();
|