|
@@ -13,8 +13,10 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.rabbitmq.client.LongString;
|
|
|
import com.usky.dxtop.common.core.domain.model.LoginUser;
|
|
|
import com.usky.dxtop.common.core.page.CommonPage;
|
|
|
+import com.usky.dxtop.common.enums.BusinessType;
|
|
|
import com.usky.dxtop.common.exception.CustomException;
|
|
|
import com.usky.dxtop.common.utils.*;
|
|
|
import com.usky.dxtop.common.utils.http.HttpUtils;
|
|
@@ -43,6 +45,7 @@ import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -709,11 +712,64 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
public void addOrderListByFile(MultipartFile multipartFile){
|
|
|
+ //获取订单
|
|
|
+ List<Order> orderList = getOrderListByFile(multipartFile);
|
|
|
+ //获取用户信息
|
|
|
+ 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));
|
|
|
+ //上传订单文件
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ AtomicBoolean b = new AtomicBoolean(true);
|
|
|
+ msgLogs.forEach(msgLog -> {
|
|
|
+ try {
|
|
|
+ CorrelationData correlationData = new CorrelationData(msgLog.getId().toString());
|
|
|
+ RabbitmqUtils.getRabbitmqTemplate(RabbitmqBeenCode.CART_CHARGE_CONSUMER).convertAndSend(msgLog.getExchange(), msgLog.getRoutingKey(), msgLog.getChargeVO(),correlationData);
|
|
|
+ }catch (Exception e){
|
|
|
+ b.set(false);
|
|
|
+ log.error("---order---卡充值消息发送异常"+ e.getMessage());
|
|
|
+ }
|
|
|
+ Long orderId = Long.parseLong(StringUtils.remove(msgLog.getBusinessId(), MsgLogBusinessCode.ORDER));
|
|
|
+ Order order = orderList.stream().filter(o -> orderId.equals(o.getId())).findAny().get();
|
|
|
+ if (b.get()){
|
|
|
+ //成功修改状态支付成功
|
|
|
+ order.setOrderFlag(OrderStatus.SUCCESS.getCode());
|
|
|
+ }else {
|
|
|
+ //失败修改状态为卡充值失败
|
|
|
+ order.setOrderFlag(OrderStatus.PAYMENT_ERROR_DEBIT.getCode());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ this.updateBatchById(orderList);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("修改订单状态失败"+e.getMessage());
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取表格数据
|
|
|
+ * @param multipartFile
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public List<Order> getOrderListByFile(MultipartFile multipartFile){
|
|
|
ImportParams importParams = new ImportParams();
|
|
|
importParams.setHeadRows(1);
|
|
@@ -723,7 +779,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
OrderFileVO.class,
|
|
|
importParams
|
|
|
);
|
|
|
- if (CollectionUtils.isNotEmpty(orderFileVOS)){
|
|
|
+ if (CollectionUtils.isEmpty(orderFileVOS)){
|
|
|
throw new CustomException("表格数据为空");
|
|
|
}
|
|
|
return BeanMapperUtils.mapList(orderFileVOS,OrderFileVO.class,Order.class);
|
|
@@ -732,44 +788,91 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增强填充数据
|
|
|
+ * @param order
|
|
|
+ * @param staffList
|
|
|
+ */
|
|
|
public void 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,"请输入订单金额");
|
|
|
BigDecimal money = order.getMoney();
|
|
|
String[] str=money.toString().split("\\.");
|
|
|
- Assert.check(str[0].length() <= 10 && str[1].length() <= 2,"订单整数不能超过十位,小数不能超过两位");
|
|
|
+ if (1 == str.length){
|
|
|
+ Assert.check(str[0].length() <= 10,"订单整数不能超过十位,小数不能超过两位");
|
|
|
+ }else {
|
|
|
+ Assert.check(str[0].length() <= 10 && str[1].length() <= 2,"订单整数不能超过十位,小数不能超过两位");
|
|
|
+ }
|
|
|
Staff staff = staffList.stream().filter(s -> s.getContacts().equals(order.getUserPhone())).findAny()
|
|
|
.orElseThrow(() -> new CustomException("用户信息:" + order.getUserName() + "不存在"));
|
|
|
Assert.check(staff.getIsSuccess(),"人员"+staff.getUsername()+"未同步失败或同步失败,请手动同步人员信息");
|
|
|
+ order.setUserId(staff.getSId());
|
|
|
order.setIdentity(staff.getIdentity());
|
|
|
order.setTopRadio(staff.getProportion());
|
|
|
- double mul = Arith.mul(order.getMoney().doubleValue(), order.getTopRadio());
|
|
|
- order.setRealMoney(BigDecimal.valueOf(Arith.div(mul,1,2)));
|
|
|
+ if (null != order.getTopRadio() && 0.00 != order.getTopRadio()){
|
|
|
+ double mul = Arith.mul(order.getMoney().doubleValue(), order.getTopRadio());
|
|
|
+ order.setRealMoney(BigDecimal.valueOf(Arith.div(mul,1,2)));
|
|
|
+ }
|
|
|
order.setCard(staff.getCardId());
|
|
|
order.setPayType(OrderPayType.XJ.getPayCode());
|
|
|
order.setScene(OrderSceneCode.BACK_STAGE.getCode());
|
|
|
+ order.setOrderFlag(OrderStatus.SUCCESS.getCode());
|
|
|
+ String orderNumber = TopApiConfiger.getOrderNumber();
|
|
|
+ order.setOrderNumber(orderNumber);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public void uploadOrderExcel(MultipartFile multipartFile){
|
|
|
- List<MultipartFile> list = new ArrayList<>();
|
|
|
- list.add(multipartFile);
|
|
|
- String batchNo = sysFileService.generateBatchNo();
|
|
|
- SysFile sysFile = new SysFile();
|
|
|
- sysFile.setBatchNo(batchNo);
|
|
|
- sysFile.setFiles(list);
|
|
|
- sysFile.setUploadType(SysFileServiceImpl.FILE);
|
|
|
- sysFile.setBusinessType("订单表格");
|
|
|
- sysFile.setExpriceAt(DateUtils.addDays(new Date(), 3));
|
|
|
- List<SysFile> sysFileList = sysFileService.addFile(sysFile);
|
|
|
- long count = sysFileList.stream().filter(sysFileDTO -> !sysFileDTO.getSuccess()).count();
|
|
|
- if (count > 0) {
|
|
|
- throw new CustomException("上传文件失败");
|
|
|
+ public MsgLog enhanceMsgLog(Order order){
|
|
|
+ Long seq = System.currentTimeMillis();
|
|
|
+ ChargeVO chargeVo = new ChargeVO();
|
|
|
+ chargeVo.setAmt(order.getMoney());
|
|
|
+ if (null != order.getRealMoney() && order.getRealMoney().compareTo(BigDecimal.ZERO) != 0){
|
|
|
+ chargeVo.setAmt(order.getRealMoney());
|
|
|
}
|
|
|
- List<String> idList = sysFileList.stream().map(sf -> sf.getId().toString()).collect(Collectors.toList());
|
|
|
- boolean active = sysFileService.active(batchNo,idList);
|
|
|
- if (!active) {
|
|
|
- throw new CustomException("上传文件失败");
|
|
|
+ chargeVo.setCard(order.getCard());
|
|
|
+ chargeVo.setSeq(seq);
|
|
|
+
|
|
|
+ MsgLog msgLog = new MsgLog();
|
|
|
+ msgLog.setBusinessId(String.format("%s%s",MsgLogBusinessCode.ORDER,order.getId()));
|
|
|
+ msgLog.setExchange(RabbitmqBeenCode.CART_CHARGE_CONSUMER.getName());
|
|
|
+ msgLog.setRoutingKey(RabbitmqBeenCode.CART_CHARGE_CONSUMER.getName());
|
|
|
+ msgLog.setId(seq);
|
|
|
+ msgLog.setCreateTime(new Date());
|
|
|
+ msgLog.setMsg(JSON.toJSONString(chargeVo));
|
|
|
+ msgLog.setChargeVO(chargeVo);
|
|
|
+ return msgLog;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传文件
|
|
|
+ * @param multipartFile
|
|
|
+ */
|
|
|
+ public String uploadOrderExcel(MultipartFile multipartFile){
|
|
|
+ try {
|
|
|
+ List<MultipartFile> list = new ArrayList<>();
|
|
|
+ list.add(multipartFile);
|
|
|
+ String batchNo = sysFileService.generateBatchNo();
|
|
|
+ SysFile sysFile = new SysFile();
|
|
|
+ sysFile.setBatchNo(batchNo);
|
|
|
+ sysFile.setFiles(list);
|
|
|
+ sysFile.setUploadType(SysFileServiceImpl.FILE);
|
|
|
+ sysFile.setBusinessType("订单表格");
|
|
|
+ sysFile.setExpriceAt(DateUtils.addDays(new Date(), 3));
|
|
|
+ List<SysFile> sysFileList = sysFileService.addFile(sysFile);
|
|
|
+ long count = sysFileList.stream().filter(sysFileDTO -> !sysFileDTO.getSuccess()).count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw new CustomException("上传文件失败");
|
|
|
+ }
|
|
|
+ List<String> idList = sysFileList.stream().map(sf -> sf.getId().toString()).collect(Collectors.toList());
|
|
|
+ boolean active = sysFileService.active(batchNo,idList);
|
|
|
+ if (!active) {
|
|
|
+ throw new CustomException("上传文件失败");
|
|
|
+ }
|
|
|
+ return batchNo;
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("上传文件失败"+e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|