Procházet zdrojové kódy

支付信息缓存提交

yjwang před 1 týdnem
rodič
revize
6736b87381

+ 68 - 0
fs-user-app/src/main/java/com/fs/app/controller/store/StoreOrderScrmController.java

@@ -21,6 +21,7 @@ import com.fs.common.utils.*;
 import com.fs.common.utils.ip.IpUtils;
 import com.fs.core.config.WxMaConfiguration;
 import com.fs.erp.service.IErpOrderService;
+import com.fs.factory.SnowflakeFactory;
 import com.fs.his.domain.FsStoreOrderScrmComment;
 import com.fs.his.domain.FsUser;
 import com.fs.his.service.IFsStoreOrderScrmCommentService;
@@ -40,6 +41,7 @@ import com.fs.hisStore.vo.FsStoreOrderGroupStoreVO;
 import com.fs.hisStore.vo.FsStoreOrderItemVO;
 import com.fs.hospital580.entity.Hospital580PrescriptionScrmEntity;
 import com.fs.hospital580.service.Hospital580PrescriptionScrmService;
+import com.fs.hospital580.vo.CacheOpenInformationVo;
 import com.fs.huifuPay.domain.HuiFuCreateOrder;
 import com.fs.huifuPay.domain.HuifuCreateOrderResult;
 import com.fs.huifuPay.service.HuiFuService;
@@ -47,6 +49,7 @@ import com.fs.pay.pay.dto.OrderQueryDTO;
 import com.fs.pay.service.IPayService;
 import com.fs.store.config.StoreConfig;
 import com.fs.system.service.ISysConfigService;
+import com.fs.utils.TwelveDigitSnowflake;
 import com.fs.wx.miniapp.config.WxMaProperties;
 import com.fs.ybPay.domain.OrderResult;
 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
@@ -150,6 +153,11 @@ public class StoreOrderScrmController extends AppBaseController {
     @Autowired
     private FsStoreVerifyCodeScrmMapper verifyCodeScrmMapper;
 
+    @Autowired
+    private SnowflakeFactory snowflakeFactory;
+
+    private static final String CACHE_KEY_PREFIX = "cacheSquareInformation";
+
     //TODO 应该没用到
     private IErpOrderService getErpService(){
         //判断是否开启erp
@@ -1595,4 +1603,64 @@ public class StoreOrderScrmController extends AppBaseController {
         }
         return orderService.orderPrescription(orderId,Long.parseLong(getUserId()),type);
     }
+
+    @ApiOperation(value = "销售制单分享-缓存支付信息")
+    @Login
+    @PostMapping("/cachePayInfo")
+    public R cachePayInfo(@RequestBody Map<String, Object> vo) {
+        TwelveDigitSnowflake snowflake = snowflakeFactory.getSnowflake();
+        String key = String.valueOf(snowflake.nextId());
+        //缓存支付信息-6小时
+        String redisKey = buildCacheKey(key, "payInfo",Long.parseLong(vo.get("userId").toString()));
+        redisCache.setCacheObject(redisKey, JSON.toJSONString(vo), 6, TimeUnit.HOURS);
+        return R.ok().put("dataKey", key);
+    }
+
+    @ApiOperation(value = "销售制单分享-存支付信息")
+    @Login
+    @PostMapping("/selectPayInfo")
+    public R selectOpenInformation(@RequestBody Map<String, Object> vo) {
+        String dataKey = String.valueOf(vo.get("dataKey")) ;
+        String userId = String.valueOf(vo.get("userId"));
+
+        log.debug("获取支付信息: orderKey={}, companyUserId={}", dataKey, userId);
+
+        String redisKey = buildCacheKey(dataKey, "payInfo", Long.valueOf(userId));
+        String cacheData = redisCache.getCacheObject(redisKey);
+
+        if (cacheData == null) {
+            log.warn("缓存未找到: key={}", redisKey);
+            return R.error("未找到对应的支付信息");
+        }
+
+        // 返回原始的 Map 数据
+        Map<String, Object> information = JSON.parseObject(cacheData, new TypeReference<Map<String, Object>>(){});
+        return R.ok().put("data", information);
+    }
+
+    /**
+     * 构建缓存key
+     */
+    private String buildCacheKey(String dataKey, String type, Long companyUserId) {
+        StringBuilder keyBuilder = new StringBuilder(CACHE_KEY_PREFIX);
+        keyBuilder.append(":");
+        if (type != null) {
+            keyBuilder.append(type);
+        } else {
+            keyBuilder.append("-");
+        }
+        keyBuilder.append(":");
+        if (companyUserId != null) {
+            keyBuilder.append(companyUserId);
+        } else {
+            keyBuilder.append("-");
+        }
+        keyBuilder.append(":");
+        if (StringUtils.isNotBlank(dataKey)) {
+            keyBuilder.append(dataKey.trim());
+        } else {
+            keyBuilder.append("-");
+        }
+        return keyBuilder.toString();
+    }
 }