Bladeren bron

空指针和bug

xw 3 dagen geleden
bovenliggende
commit
35a02dd0f5

+ 29 - 20
fs-service/src/main/java/com/fs/his/service/impl/FsIntegralOrderServiceImpl.java

@@ -43,6 +43,7 @@ import com.fs.his.param.*;
 import com.fs.his.service.*;
 import com.fs.his.utils.ConfigUtil;
 import com.fs.his.utils.PhoneUtil;
+import com.fs.his.utils.RedisCacheUtil;
 import com.fs.his.vo.*;
 import com.fs.qw.domain.QwUser;
 import com.fs.qw.mapper.QwUserMapper;
@@ -163,7 +164,7 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
     private IFsUserAddressService fsUserAddressService;
 
     @Autowired
-    private com.fs.his.utils.RedisCacheUtil redisCacheUtil;
+    private RedisCacheUtil redisCacheUtil;
     /**
      * 查询积分商品订单
      *
@@ -487,7 +488,14 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
         // 清除商品列表缓存
         redisCacheUtil.delRedisKey("getIntegralGoodsList");
 
-        return createOrder(user, address, totalIntegral, totalCash, goodsItem, null);
+        // 创建订单
+        R result = createOrder(user, address, totalIntegral, totalCash, goodsItem, null);
+
+        // 订单创建成功后,删除购物车中已下单的商品
+        if (result.get("code").equals(200)) {
+            cartService.delCartByIds(user.getUserId(), param.getIds());
+        }
+        return result;
     }
 
     @Override
@@ -579,8 +587,9 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
     public R cannelOrder(Long orderId) {
         // 取消订单
         FsIntegralOrder order = fsIntegralOrderMapper.selectFsIntegralOrderByOrderId(orderId);
-        if (!order.getStatus().equals(4)){
-            return R.error("非法操作");
+        // 允许取消待支付(4)和待发货(1)的订单
+        if (!order.getStatus().equals(4) && !order.getStatus().equals(1)){
+            return R.error("非法操作,只能取消待支付或待发货的订单");
         }
 
         order.setStatus(5);
@@ -593,32 +602,32 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService
                 fsIntegralGoodsMapper.addStock(goods.getGoodsId(), Objects.isNull(goods.getNum()) ? 1 : goods.getNum());
                 // 清除商品缓存
                 redisCacheUtil.delSpringCacheKey("getIntegralGoodsById", goods.getGoodsId());
-                log.info("取消订单还原库存,清除商品缓存, goodsId: {}", goods.getGoodsId());
             });
         } else {
             FsIntegralGoods integralGoods = JSONUtil.toBean(order.getItemJson(), FsIntegralGoods.class);
             fsIntegralGoodsMapper.addStock(integralGoods.getGoodsId(), Objects.isNull(integralGoods.getNum()) ? 1 : integralGoods.getNum());
             // 清除商品缓存
             redisCacheUtil.delSpringCacheKey("getIntegralGoodsById", integralGoods.getGoodsId());
-            log.info("取消订单还原库存,清除商品缓存, goodsId: {}", integralGoods.getGoodsId());
         }
         // 清除商品列表缓存
         redisCacheUtil.delRedisKey("getIntegralGoodsList");
 
-        // 还原积分
-        FsUser user=fsUserMapper.selectFsUserByUserId(order.getUserId());
-        FsUser userMap=new FsUser();
-        userMap.setUserId(user.getUserId());
-        userMap.setIntegral(user.getIntegral() + Long.parseLong(order.getIntegral()));
-        fsUserMapper.updateFsUser(userMap);
-        FsUserIntegralLogs logs = new FsUserIntegralLogs();
-        logs.setIntegral(Long.parseLong(order.getIntegral()));
-        logs.setUserId(order.getUserId());
-        logs.setBalance(userMap.getIntegral());
-        logs.setLogType(5);
-        logs.setBusinessId(order.getOrderId().toString());
-        logs.setCreateTime(new Date());
-        fsUserIntegralLogsMapper.insertFsUserIntegralLogs(logs);
+        // 还原积分(只有当订单消耗了积分时才退还)
+        if (StringUtils.isNotEmpty(order.getIntegral()) && Long.parseLong(order.getIntegral()) > 0) {
+            FsUser user=fsUserMapper.selectFsUserByUserId(order.getUserId());
+            FsUser userMap=new FsUser();
+            userMap.setUserId(user.getUserId());
+            userMap.setIntegral(user.getIntegral() + Long.parseLong(order.getIntegral()));
+            fsUserMapper.updateFsUser(userMap);
+            FsUserIntegralLogs logs = new FsUserIntegralLogs();
+            logs.setIntegral(Long.parseLong(order.getIntegral()));
+            logs.setUserId(order.getUserId());
+            logs.setBalance(userMap.getIntegral());
+            logs.setLogType(5);
+            logs.setBusinessId(order.getOrderId().toString());
+            logs.setCreateTime(new Date());
+            fsUserIntegralLogsMapper.insertFsUserIntegralLogs(logs);
+        }
 
         return R.ok();
     }

+ 10 - 1
fs-service/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -940,9 +940,18 @@ public class LiveServiceImpl implements ILiveService
         }
 
         SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("living.config");
+        if (sysConfig == null || StringUtils.isEmpty(sysConfig.getConfigValue())) {
+            log.error("直播配置不存在或为空, liveId: {}", live.getLiveId());
+            return R.error("直播配置不存在,请联系管理员配置");
+        }
         Map<String, String> livingConfigMap = JSON.parseObject(sysConfig.getConfigValue(), Map.class);
         if (livingConfigMap == null || livingConfigMap.isEmpty()) {
-            return R.error("缺失直播配置");
+            log.error("直播配置解析失败, liveId: {}, configValue: {}", live.getLiveId(), sysConfig.getConfigValue());
+            return R.error("直播配置解析失败");
+        }
+        if (StringUtils.isEmpty(livingConfigMap.get("domain")) || StringUtils.isEmpty(livingConfigMap.get("app"))) {
+            log.error("直播配置缺少必要参数, liveId: {}, configMap: {}", live.getLiveId(), livingConfigMap);
+            return R.error("直播配置缺少必要参数(domain/app)");
         }
         String rtmpPushUrl = generateRtmpPushUrl(livingConfigMap.get("domain"), livingConfigMap.get("app"), exist.getLiveId().toString());
         String hlvPlayUrl = generateHlvPlayUrl(livingConfigMap.get("http"), livingConfigMap.get("app"), exist.getLiveId().toString());