Преглед изворни кода

优化用户取消订单接口,将循环调用数据库的功能优化

liu пре 2 месеци
родитељ
комит
cca709b0c6

+ 99 - 85
src/main/java/com/sqx/modules/errand/service/impl/TbIndentServiceImpl.java

@@ -101,6 +101,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Random;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -349,7 +350,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         tbIndent.setShopId(order.getShopId());
         baseMapper.insert(tbIndent);
 
-        log.info("订单类型:"+order.getOrderType()+",跑腿订单状态:"+tbIndent.getIndentState());
+        log.info("订单类型:" + order.getOrderType() + ",跑腿订单状态:" + tbIndent.getIndentState());
         if (order.getOrderType() == 2 && !"11".equals(tbIndent.getIndentState())) {
             //            创建快跑者订单
             log.info("第一次创建快跑者订单");
@@ -390,7 +391,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
     }
 
 
-    public String creatSpeedRunnerOrder(TbOrder tbOrder){
+    public String creatSpeedRunnerOrder(TbOrder tbOrder) {
 //               获取店铺信息
         GoodsShop goodsShop = goodsShopService.getById(tbOrder.getShopId());
 //               获取餐品信息
@@ -413,7 +414,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         Address address = addressService.getById(tbOrder.getAddressId());
 
         JSONObject body = new JSONObject();
-        String shopId = tbOrder.getShopId()+"";
+        String shopId = tbOrder.getShopId() + "";
         if (ObjectUtils.isNotEmpty(shopId)) {
             try {
                 shopId = URLEncoder.encode(shopId, "UTF-8");
@@ -457,7 +458,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         body.put("shop_address", detailedAddress);
 
 
-        String shopTag  =goodsShop.getShopLng() + "," + goodsShop.getShopLat();
+        String shopTag = goodsShop.getShopLng() + "," + goodsShop.getShopLat();
         if (ObjectUtils.isNotEmpty(detailedAddress)) {
             try {
                 shopTag = URLEncoder.encode(shopTag, "UTF-8");
@@ -472,7 +473,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         String orderContent = stringBuilder.toString();
         if (ObjectUtils.isNotEmpty(orderContent)) {
             try {
-                orderContent=orderContent.replaceAll("\\t", " ");
+                orderContent = orderContent.replaceAll("\\t", " ");
                 orderContent = URLEncoder.encode(orderContent, "UTF-8");
 //                orderContent=orderContent.replaceAll("🦆","");
 //                orderContent=orderContent.replaceAll("(双拼)","");
@@ -487,8 +488,8 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         String remark = tbOrder.getRemark();
         if (ObjectUtils.isNotEmpty(remark)) {
             try {
-                remark=remark.replaceAll("\\r\\n|\\n|\\r", " ");
-                remark=remark.replaceAll("\\\\", " ");
+                remark = remark.replaceAll("\\r\\n|\\n|\\r", " ");
+                remark = remark.replaceAll("\\\\", " ");
                 remark = URLEncoder.encode(remark, "UTF-8");
             } catch (UnsupportedEncodingException e) {
                 throw new RuntimeException(e);
@@ -500,7 +501,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         String orderSequence = tbOrder.getOrderSequence();
         if (ObjectUtils.isNotEmpty(orderSequence)) {
             try {
-                orderSequence =URLEncoder.encode(orderSequence, "UTF-8");
+                orderSequence = URLEncoder.encode(orderSequence, "UTF-8");
             } catch (UnsupportedEncodingException e) {
                 throw new RuntimeException(e);
             }
@@ -508,7 +509,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         body.put("order_mark", orderSequence);
 
 
-        body.put("order_from", shopName+ "#" + orderSequence);
+        body.put("order_from", shopName + "#" + orderSequence);
 
 
         String payTime = tbOrder.getPayTime();
@@ -525,7 +526,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         String userName = address.getUserName();
         if (ObjectUtils.isNotEmpty(userName)) {
             try {
-                userName=userName.replaceAll("\\r\\n|\\n|\\r", " ");
+                userName = userName.replaceAll("\\r\\n|\\n|\\r", " ");
                 userName = URLEncoder.encode(userName, "UTF-8");
             } catch (UnsupportedEncodingException e) {
                 throw new RuntimeException(e);
@@ -558,7 +559,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         body.put("customer_address", addressDetail);
 
 
-        String customerTag=address.getLng() + "," + address.getLat();
+        String customerTag = address.getLng() + "," + address.getLat();
         if (ObjectUtils.isNotEmpty(customerTag)) {
             try {
                 customerTag = URLEncoder.encode(customerTag, "UTF-8");
@@ -587,7 +588,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 throw new RuntimeException(e);
             }
         }
-        body.put("order_price",payMoney);
+        body.put("order_price", payMoney);
         body.put("pay_status", 0);
 
         log.info("body信息:" + body);
@@ -598,22 +599,22 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         long currentTimeMillis = System.currentTimeMillis();
         long currentTimeSeconds = currentTimeMillis / 1000;
         String timestamp = String.valueOf(currentTimeSeconds);
-        log.info("timestamp: "+timestamp);
+        log.info("timestamp: " + timestamp);
 //               唯一标识符
 //        String ticket = "83f0ff99-7c8e-47e8-8802-bd3754414a52";
-        String ticket=commonInfoService.findOne(449).getValue();
+        String ticket = commonInfoService.findOne(449).getValue();
 //               团队token
 //        String teamToken = "Q444DMV4LT8WSGRW";
-        String teamToken=commonInfoService.findOne(448).getValue();
+        String teamToken = commonInfoService.findOne(448).getValue();
 //               开发者中心的开发密钥
 //        String devKey = "31RRHA4O165VFN9W2DAPDYDH8N83BT12";
-        String devKey=commonInfoService.findOne(447).getValue();
+        String devKey = commonInfoService.findOne(447).getValue();
         //              签名密钥
-        String devSecret=commonInfoService.findOne(450).getValue();
+        String devSecret = commonInfoService.findOne(450).getValue();
 
         JSONObject body2 = new JSONObject();
 //        String shopId = tbOrder.getShopId()+"";
-        body2.put("shop_id", tbOrder.getShopId()+"");
+        body2.put("shop_id", tbOrder.getShopId() + "");
 
 //        String shopName = goodsShop.getShopName();
         body2.put("shop_name", goodsShop.getShopName());
@@ -632,7 +633,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 //        将+变成-
         String orderContent2 = stringBuilder.toString();
         if (ObjectUtils.isNotEmpty(orderContent2)) {
-            orderContent2=orderContent2.replaceAll("\\t", " ");
+            orderContent2 = orderContent2.replaceAll("\\t", " ");
         }
 
         body2.put("order_content", orderContent2);
@@ -640,8 +641,8 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 
         String remark2 = tbOrder.getRemark();
         if (ObjectUtils.isNotEmpty(remark2)) {
-            remark2=remark2.replaceAll("\\r\\n|\\n|\\r", " ");
-            remark2=remark2.replaceAll("\\\\", " ");
+            remark2 = remark2.replaceAll("\\r\\n|\\n|\\r", " ");
+            remark2 = remark2.replaceAll("\\\\", " ");
             // 方法2:使用Java 8+的\\R正则表达式;
         }
         body2.put("order_note", remark2);
@@ -650,7 +651,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         body2.put("order_mark", tbOrder.getOrderSequence());
 
 
-        body2.put("order_from", goodsShop.getShopName()+ "#" + tbOrder.getOrderSequence());
+        body2.put("order_from", goodsShop.getShopName() + "#" + tbOrder.getOrderSequence());
 
 
 //        String payTime = tbOrder.getPayTime();
@@ -661,7 +662,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 //        String userName = address.getUserName();
         String userName1 = address.getUserName();
         if (ObjectUtils.isNotEmpty(userName1)) {
-            userName1=userName1.replaceAll("\\r\\n|\\n|\\r", " ");
+            userName1 = userName1.replaceAll("\\r\\n|\\n|\\r", " ");
         }
         body2.put("customer_name", userName1);
 
@@ -683,12 +684,12 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         body2.put("order_no", tbOrder.getOrderNumber());
 
 //        String payMoney = tbOrder.getPayMoney().toPlainString();
-        body2.put("order_price",tbOrder.getPayMoney().toPlainString());
+        body2.put("order_price", tbOrder.getPayMoney().toPlainString());
         body2.put("pay_status", 0);
         log.info("body2信息:" + body2);
 //               获取签名
-        String sign = SignUtil.getSign(body2.toString(), devKey, teamToken, ticket, currentTimeSeconds, 1,devSecret);
-        String responseBody="";
+        String sign = SignUtil.getSign(body2.toString(), devKey, teamToken, ticket, currentTimeSeconds, 1, devSecret);
+        String responseBody = "";
         try {
             log.info("创建快跑者订单");
             CloseableHttpClient client = HttpClients.createDefault();
@@ -700,20 +701,20 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             entity.setContentType("application/x-www-form-urlencoded"); // 设置Content-Type为application/x-www-form-urlencoded,但不是必须的,HttpClient会自动设置。
             httpPost.setEntity(entity);
             responseBody = EntityUtils.toString(client.execute(httpPost).getEntity());
-            log.info("创建结果:"+responseBody);
-        }catch (Exception e){
+            log.info("创建结果:" + responseBody);
+        } catch (Exception e) {
             e.printStackTrace();
 //            throw new RuntimeException("responseBody");
         }
         return responseBody;
     }
 
-    public String getOrderTradeNo(String responseBody){
+    public String getOrderTradeNo(String responseBody) {
         com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(responseBody);
         Integer code = jsonObject.getInteger("code");
-        String tradeNo="";
+        String tradeNo = "";
         if (ObjectUtils.isNotEmpty(code)) {
-            if (code==200) {
+            if (code == 200) {
                 JSONObject data = jsonObject.getJSONObject("data");
                 tradeNo = data.getString("trade_no");
             }
@@ -1120,7 +1121,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                     //获取站点内容
                     RiderStation station = riderStationService.stationById(userEntity1.getRiderStationId());
                     log.error("第一次接单station1:" + new Gson().toJson(station));
-                    if(station != null){
+                    if (station != null) {
                         log.error("第一次接单station2:" + new Gson().toJson(station));
                         tr.setStationName(station.getStationName());
                         log.error("第一次接单station3:" + new Gson().toJson(tr));
@@ -1143,7 +1144,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                     //获取站点内容
                     RiderStation station = riderStationService.stationById(userEntity1.getRiderStationId());
                     log.error("第一次接单station:" + new Gson().toJson(station));
-                    if(station != null){
+                    if (station != null) {
                         log.error("第一次接单station2:" + new Gson().toJson(station));
                         tr.setStationName(station.getStationName());
                         log.error("第一次接单station3:" + new Gson().toJson(tr));
@@ -1153,7 +1154,6 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 }
 
 
-
             } finally {
                 lock.unlock();
             }
@@ -1284,7 +1284,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             tr.setOrderId(tbIndent.getOrderId());
             tr.setReceveTime(receiveTimeStr);
             RiderStation station = riderStationService.stationById(riderUser.getRiderStationId());  // 获取站点内容
-            if(station != null){
+            if (station != null) {
                 tr.setStationName(station.getStationName());
             }
             tr.setDeleteFlag(0);
@@ -1439,17 +1439,17 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         // 获取待转单
         TbIndent indent = getTransferOrder(userId, transferOrderDTO);
         UserEntity indentuserEntity = userService.selectUserById(indent.getRiderUserId());
-        if(indentuserEntity == null){
+        if (indentuserEntity == null) {
             throw new SqxException("订单骑手已失效,无法发起转单!");
         }
 
         // 获取新的骑手
         UserEntity userEntity = getNewRicher(userId, transferOrderDTO);
-        if(userEntity == null){
+        if (userEntity == null) {
             throw new SqxException("被转单骑手已失效,无法发起转单!");
         }
 
-        if(userEntity.getRiderStationId().intValue() != indentuserEntity.getRiderStationId().intValue()){
+        if (userEntity.getRiderStationId().intValue() != indentuserEntity.getRiderStationId().intValue()) {
             throw new SqxException("无法选择其他站点骑手进行转单操作!");
         }
 
@@ -1467,9 +1467,9 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         tr.setReceveTime(format);
         tr.setStationName(userEntity.getStationName());
         tr.setDeleteFlag(0);
-        log.info("测试是否进入转单4,tr:"+ new Gson().toJson(tr));
+        log.info("测试是否进入转单4,tr:" + new Gson().toJson(tr));
         int insertCount = transferRecordDao.insert(tr);
-        log.info("测试是否进入转单5,insertCount:"+insertCount);
+        log.info("测试是否进入转单5,insertCount:" + insertCount);
         // 消息通知
         noticeAfterTransfer(indent);
     }
@@ -1584,8 +1584,8 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 
                 // 发送短信并记录短信发送记录
                 TbIndentSmsSendLog tbIndentSmsSendLog = smsSendLogService.getSendSuccessByOrderId(indentOrder.getIndentId());
-                if(tbIndentSmsSendLog != null){
-                    log.error("外卖跑腿订单id【{}】短信已发送成功,短信id【{}】",tbIndentSmsSendLog.getOrderId(),tbIndentSmsSendLog.getId());
+                if (tbIndentSmsSendLog != null) {
+                    log.error("外卖跑腿订单id【{}】短信已发送成功,短信id【{}】", tbIndentSmsSendLog.getOrderId(), tbIndentSmsSendLog.getId());
                     return;
                 }
                 SmsSendResult smsSendResult = smsTemplateService.sendSms(smsTemplateId, riderUser, userPhone);
@@ -1632,24 +1632,25 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 
 //            撤销快跑者订单
             TbOrder tbOrder = appOrderService.getOne(new QueryWrapper<TbOrder>().eq("order_number", indentNumber));
-            if (ObjectUtils.isNotEmpty(tbOrder)&&ObjectUtils.isNotEmpty(tbOrder.getTradeNo())) {
-                log.info("第一次撤销快跑者订单:"+tbOrder.getTradeNo());
+            if (ObjectUtils.isNotEmpty(tbOrder) && ObjectUtils.isNotEmpty(tbOrder.getTradeNo())) {
+                log.info("第一次撤销快跑者订单:" + tbOrder.getTradeNo());
                 String responseBody = cancelSpeedRunnerOrder(tbOrder.getTradeNo());
                 if (ObjectUtils.isNotEmpty(responseBody)) {
                     JSONObject jsonObject = JSONObject.parseObject(responseBody);
                     Integer code = jsonObject.getInteger("code");
-                    if (code!=200) {
-                        log.info("第二次撤销快跑者订单:"+tbOrder.getTradeNo());
+                    if (code != 200) {
+                        log.info("第二次撤销快跑者订单:" + tbOrder.getTradeNo());
                         String responseBody2 = cancelSpeedRunnerOrder(tbOrder.getTradeNo());
                     }
-                }else {
-                    log.info("第一次撤销结果为空,第二次撤销快跑者订单:"+tbOrder.getTradeNo());
+                } else {
+                    log.info("第一次撤销结果为空,第二次撤销快跑者订单:" + tbOrder.getTradeNo());
                     String responseBody2 = cancelSpeedRunnerOrder(tbOrder.getTradeNo());
                 }
             }
         }
     }
-    public String cancelSpeedRunnerOrder(String tradeNo){
+
+    public String cancelSpeedRunnerOrder(String tradeNo) {
 
         com.alibaba.fastjson.JSONObject body = new com.alibaba.fastjson.JSONObject();
         body.put("trade_no", tradeNo);
@@ -1664,19 +1665,19 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         String timestamp = String.valueOf(currentTimeSeconds);
 //               唯一标识符
 //        String ticket = "83f0ff99-7c8e-47e8-8802-bd3754414a52";
-        String ticket=commonInfoService.findOne(449).getValue();
+        String ticket = commonInfoService.findOne(449).getValue();
 //               团队token
 //        String teamToken = "Q444DMV4LT8WSGRW";
-        String teamToken=commonInfoService.findOne(448).getValue();
+        String teamToken = commonInfoService.findOne(448).getValue();
 //               开发者中心的开发密钥
 //        String devKey = "31RRHA4O165VFN9W2DAPDYDH8N83BT12";
-        String devKey=commonInfoService.findOne(447).getValue();
+        String devKey = commonInfoService.findOne(447).getValue();
         //              签名密钥
-        String devSecret=commonInfoService.findOne(450).getValue();
+        String devSecret = commonInfoService.findOne(450).getValue();
 
 //               获取签名
-        String sign = com.sqx.common.utils.SignUtil.getSign(body.toString(), devKey, teamToken, ticket, currentTimeSeconds, 1,devSecret);
-        String responseBody="";
+        String sign = com.sqx.common.utils.SignUtil.getSign(body.toString(), devKey, teamToken, ticket, currentTimeSeconds, 1, devSecret);
+        String responseBody = "";
         try {
             log.info("撤销快跑者订单");
             CloseableHttpClient client = HttpClients.createDefault();
@@ -1687,12 +1688,13 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             entity.setContentType("application/x-www-form-urlencoded"); // 设置Content-Type为application/x-www-form-urlencoded,但不是必须的,HttpClient会自动设置。
             httpPost.setEntity(entity);
             responseBody = EntityUtils.toString(client.execute(httpPost).getEntity());
-            log.info("撤销结果:"+responseBody);
-        }catch (Exception e){
+            log.info("撤销结果:" + responseBody);
+        } catch (Exception e) {
             e.printStackTrace();
         }
         return responseBody;
     }
+
     @Override
     public Result finalizeOrder(Long userId, TbIndent indentOrder) {
         if (ObjectUtil.isNull(indentOrder)) {
@@ -1703,7 +1705,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         if (!Objects.equals(indentOrder.getRiderUserId(), userId)) {
 //            不为本人则需要调用转单接口
             log.info("不为接单本人,需转单");
-            log.info("当前骑手id:"+indentOrder.getRiderUserId()+",需要更换的骑手id:"+userId);
+            log.info("当前骑手id:" + indentOrder.getRiderUserId() + ",需要更换的骑手id:" + userId);
             UserEntity userEntity = userService.getById(userId);
             indentOrder.setRiderUserId(userEntity.getUserId());
             indentOrder.setIsRider(1);
@@ -1718,9 +1720,9 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             tr.setReceveTime(format);
             tr.setStationName(userEntity.getStationName());
             tr.setDeleteFlag(0);
-            log.info("测试是否进入转单4,tr:"+ new Gson().toJson(tr));
+            log.info("测试是否进入转单4,tr:" + new Gson().toJson(tr));
             int insertCount = transferRecordDao.insert(tr);
-            log.info("测试是否进入转单5,insertCount:"+insertCount);
+            log.info("测试是否进入转单5,insertCount:" + insertCount);
 //            throw new SqxException("不能完成非本人订单!");
         }
 
@@ -1848,7 +1850,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             status = transactionManager.getTransaction(new DefaultTransactionDefinition());
             // 如果是外卖订单
             if (ObjectUtil.equal(indentOrder.getIndentType(), "5")) {
-                 handTakeoutOrder(indentOrder, userId, deliveryDTO);
+                handTakeoutOrder(indentOrder, userId, deliveryDTO);
             }
 
             Result result = finshOrder(userId, indentNumber, deliveryDTO.getItemCode());
@@ -1908,11 +1910,11 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             return;
         }
 
-        TbIndentSmsSendLog tbIndentSmsSendLog=smsSendLogService.getSendSuccessByOrderId(indentOrder.getIndentId());
+        TbIndentSmsSendLog tbIndentSmsSendLog = smsSendLogService.getSendSuccessByOrderId(indentOrder.getIndentId());
 
         // 有发送成功记录则不再发送
-        if(tbIndentSmsSendLog!=null){
-            log.error("外卖跑腿订单【{}】短信已发送成功,短信id【{}】", deliveryDTO.getIndentNumber(),tbIndentSmsSendLog.getId());
+        if (tbIndentSmsSendLog != null) {
+            log.error("外卖跑腿订单【{}】短信已发送成功,短信id【{}】", deliveryDTO.getIndentNumber(), tbIndentSmsSendLog.getId());
             return;
         }
         // 发送短信并记录短信发送记录
@@ -2092,7 +2094,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 
     @Override
     public Result taskAnalysis(DataCenterQuery oldQuery, String indentState) {
-        DataCenterQuery query=DateUtils.dateStrEndTime(oldQuery);
+        DataCenterQuery query = DateUtils.dateStrEndTime(oldQuery);
         HashMap hashMap = new HashMap();
         //发单总金额
         BigDecimal billMoney = tbIndentDao.billMoney(query);
@@ -2116,7 +2118,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
     @Override
     public Result selectOrderByStatus(DataCenterQuery oldQuery) {
         HashMap hashMap = new HashMap();
-        DataCenterQuery query=DateUtils.dateStrEndTime(oldQuery);
+        DataCenterQuery query = DateUtils.dateStrEndTime(oldQuery);
         //全部
         int i = tbIndentDao.selectOrderByStatus(query, null);
         // 付款
@@ -2145,7 +2147,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
     @Override
     public List<TbIndent> findIndentsByIds(List<Long> ids) {
         QueryWrapper<TbIndent> queryWrapper = new QueryWrapper<>();
-        queryWrapper.in("indent_id",ids);
+        queryWrapper.in("indent_id", ids);
         List<TbIndent> result = baseMapper.selectList(queryWrapper);
         return result;
     }
@@ -2237,10 +2239,10 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 errandRedPacket.setDeleteFlag("0");
                 errandRedPacket.setCreateTime(date);
                 errandRedPackets.add(errandRedPacket);
- //               userDao.addRedPacket(userId, redPacket.getRedPacketType(), redPacket.getMinimumAmount(), redPacketAmount, redPacket.getRedPacketTitle(), expirationTime, createTime);
+                //               userDao.addRedPacket(userId, redPacket.getRedPacketType(), redPacket.getMinimumAmount(), redPacketAmount, redPacket.getRedPacketTitle(), expirationTime, createTime);
             }
             // 批量插入
-            if (errandRedPackets.size()>0) {
+            if (errandRedPackets.size() > 0) {
                 userDao.batchAddRedPacket(errandRedPackets);
             }
             //修改用户为非新用户
@@ -2316,24 +2318,36 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             messageService.save(messageInfo1);
 
             List<OrderGoods> orderGoodsList = orderGoodsDao.selectList(new QueryWrapper<OrderGoods>().eq("order_id", indent1.getOrderId()));
-            for (int a = 0; a < orderGoodsList.size(); a++) {
-                OrderGoods orderGoods = orderGoodsList.get(a);
-                Integer goodsNum = orderGoods.getGoodsNum();
-                Long goodsId = orderGoodsList.get(a).getGoodsId();
-                GoodsShopRelevancy goodsShopRelevancy = goodsShopRelevancyDao.selectOne(new QueryWrapper<GoodsShopRelevancy>()
-                        .eq("shop_id", order.getShopId()).eq("goods_id", goodsId));
-                GoodsShopRelevancy goodsShopRelevancy1 = new GoodsShopRelevancy();
-                goodsShopRelevancy1.setId(goodsShopRelevancy.getId());
-                goodsShopRelevancy1.setSales(goodsShopRelevancy.getSales() - goodsNum);//加销量
-                goodsShopRelevancy1.setInventory(goodsShopRelevancy.getInventory() + goodsNum);//减库存
-                goodsShopRelevancyDao.updateById(goodsShopRelevancy1);
+            List<Long> goodsIdList = orderGoodsList.stream().map(OrderGoods::getGoodsId).collect(Collectors.toList());
+            if (goodsIdList.size() > 0) {
+                List<GoodsShopRelevancy> goodsShopRelevancies = goodsShopRelevancyDao.selectList(new QueryWrapper<GoodsShopRelevancy>()
+                        .eq("shop_id", order.getShopId())
+                        .in("goods_id", goodsIdList)
+                );
+                Map<Long, GoodsShopRelevancy> map = goodsShopRelevancies.stream().collect(Collectors.toMap(
+                        GoodsShopRelevancy::getGoodsId,
+                        goodsShopRelevancy -> goodsShopRelevancy
+                ));
+
+                for (int a = 0; a < orderGoodsList.size(); a++) {
+                    OrderGoods orderGoods = orderGoodsList.get(a);
+                    Integer goodsNum = orderGoods.getGoodsNum();
+                    Long goodsId = orderGoodsList.get(a).getGoodsId();
+//                GoodsShopRelevancy goodsShopRelevancy = goodsShopRelevancyDao.selectOne(new QueryWrapper<GoodsShopRelevancy>()
+//                        .eq("shop_id", order.getShopId()).eq("goods_id", goodsId));
+                    GoodsShopRelevancy goodsShopRelevancy = map.get(goodsId);
+                    GoodsShopRelevancy goodsShopRelevancy1 = new GoodsShopRelevancy();
+                    goodsShopRelevancy1.setId(goodsShopRelevancy.getId());
+                    goodsShopRelevancy1.setSales(goodsShopRelevancy.getSales() - goodsNum);//加销量
+                    goodsShopRelevancy1.setInventory(goodsShopRelevancy.getInventory() + goodsNum);//减库存
+                    goodsShopRelevancyDao.updateById(goodsShopRelevancy1);
 //                goodsShopDao.updateShopSales(2, goodsNum, goodsShopRelevancy.getShopId()); //减销量
-            }
+                }
 
 //            goodsShopDao.updateShopSales(2, 1, indent1.getShopId());
+            }
         }
 
-
         return Result.success().put("data", indent1);
     }
 
@@ -2343,7 +2357,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
      * @param indent
      */
     @Override
-    public void noticeAfterTransfer(TbIndent indent,queryRiderVo user) {
+    public void noticeAfterTransfer(TbIndent indent, queryRiderVo user) {
         CommonInfo one = commonInfoService.findOne(335);
         List<String> msgList = new ArrayList<>();
         msgList.add(0, indent.getIndentNumber());
@@ -2493,7 +2507,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 
         //获取站点内容
         RiderStation station = riderStationService.stationById(userEntity.getRiderStationId());
-        if(station != null){
+        if (station != null) {
             userEntity.setStationName(station.getStationName());
         }
 
@@ -2503,7 +2517,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
     /**
      * 获取新骑手
      *
-     * @param riderUserId    被转单骑手id
+     * @param riderUserId 被转单骑手id
      * @return 新骑手
      */
     @Override

+ 1 - 1
src/test/java/OrderTest.java

@@ -325,7 +325,7 @@ public class OrderTest {
         RhtQrcodePayApi qrcodePay = new RhtQrcodePayApi(wechatMchConfig.getMchId(), wechatMchConfig.getMchKey(), "https://api.ekbuyclub.com");
 
         String orderNumberStr =
-                "118702260413005915377980"
+                "118702260319005697176220"
                 ;
         for (String orderNumber : orderNumberStr.split(",")) {
             QrcodeQueryRequestBean qqrb = new QrcodeQueryRequestBean();