diff --git a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/controller/ServiceController.java b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/controller/ServiceController.java index d10c6c6..cc530c2 100644 --- a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/controller/ServiceController.java +++ b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/controller/ServiceController.java @@ -93,6 +93,8 @@ public class ServiceController { InterfaceUtils.postForm(UrlUtil.getServiceGoUrl(),"/api/orders/orderForPay",orderForPay); + shopService.refreshShopSubscriptionStatus(Long.parseLong(shopId)); + return R.ok(); } diff --git a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/dll/DllInitializer.java b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/dll/DllInitializer.java index 83ddfbf..9de7e1d 100644 --- a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/dll/DllInitializer.java +++ b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/dll/DllInitializer.java @@ -10,15 +10,15 @@ public class DllInitializer { @PostConstruct public void init() { - try { - System.out.println("正在加载 erp DLL库"); - ErpSimpleDllLoader.loadDLL(); - initialized = true; - System.out.println("erp DLL 库加载成功"); - } catch (Exception e) { - System.err.println("Native 库加载失败: " + e.getMessage()); - throw new RuntimeException("Native 库加载失败", e); - } +// try { +// System.out.println("正在加载 erp DLL库"); +// ErpSimpleDllLoader.loadDLL(); +// initialized = true; +// System.out.println("erp DLL 库加载成功"); +// } catch (Exception e) { +// System.err.println("Native 库加载失败: " + e.getMessage()); +// throw new RuntimeException("Native 库加载失败", e); +// } } public static boolean isInitialized() { diff --git a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/IShopService.java b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/IShopService.java index 774c9fe..4467585 100644 --- a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/IShopService.java +++ b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/IShopService.java @@ -103,6 +103,11 @@ public interface IShopService { */ Boolean updateByBo(ShopBo bo); + /** + * 订阅支付成功后刷新店铺订阅到期时间 + */ + void refreshShopSubscriptionStatus(Long shopId); + /** * 校验并批量删除店铺主表信息 * diff --git a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/impl/ShopServiceImpl.java b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/impl/ShopServiceImpl.java index 04588dd..39c61f5 100644 --- a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/impl/ShopServiceImpl.java +++ b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/impl/ShopServiceImpl.java @@ -209,55 +209,20 @@ public class ShopServiceImpl implements IShopService { if (shopVo.getExpirationTime() != null && currentTime > shopVo.getExpirationTime().getTime() && shopVo.getShopType().equals("1")) { - // 如果当前时间超过到期时间则修改店铺授权状态 shopVo.setShopAuthorize("2"); - // 修改数据库 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setIsExpiration("2"); - updateByBo(shopBo); + shopVo.setIsExpiration("2"); + updateShopSubscribeStatusQuietly(shopVo.getId(), null, "2", null); } else if(!shopVo.getShopType().equals("1")){ - if(shopVo.getExpirationTime() != null - && currentTime > shopVo.getExpirationTime().getTime()){ + if (!isTaobaoShopType(shopVo.getShopType()) + && shopVo.getExpirationTime() != null + && currentTime > shopVo.getExpirationTime().getTime()) { // 如果当前时间超过到期时间则修改店铺授权状态 shopVo.setShopAuthorize("2"); - // 修改数据库 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setIsExpiration("2"); - updateByBo(shopBo); - } - //校验是否过期 - String result2 = InterfaceUtils.getInterface(UrlUtil.getServiceGoUrl(),"/api/user/getKfzUserRecbusiness?userId="+shopVo.getId()); - Map resultMap = JSONObject.parseObject(result2, Map.class); - if(resultMap.get("message").equals("success")){ - //成功 - Map data = (Map) resultMap.get("data"); -// shopVo.setExpirationTime(new Date((Long) data.get("expirationDate"))); - shopVo.setShopExpirationTime(new Date((Long) data.get("expirationDate"))); - if(!(Boolean) data.get("isVip")){ - //过期,修改店铺设置 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setIsExpiration("2"); - updateByBo(shopBo); - } else { - //已过期,续费后修改店铺设置 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setIsExpiration("1"); - updateByBo(shopBo); - } - }else{ - if(StringUtils.isEmpty(shopVo.getIsExpiration())){ - //为空赋值0 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setIsExpiration("0"); - updateByBo(shopBo); - } + shopVo.setIsExpiration("2"); + updateShopSubscribeStatusQuietly(shopVo.getId(), "2", "2", null); } + syncShopSubscriptionStatus(shopVo); } } @@ -326,48 +291,18 @@ public class ShopServiceImpl implements IShopService { && !shopVo.getShopAuthorize().equals("2") && shopVo.getShopType().equals("1")) { // 如果当前时间超过到期时间则修改店铺授权状态 shopVo.setShopAuthorize("2"); - // 修改数据库 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setShopAuthorize("2"); - updateByBo(shopBo); + updateShopSubscribeStatusQuietly(shopVo.getId(), "2", null, null); } else if(!shopVo.getShopType().equals("1")){ - if(shopVo.getExpirationTime() != null - && currentTime > shopVo.getExpirationTime().getTime() - &&shopVo.getShopType().equals("5")){ + if (!isTaobaoShopType(shopVo.getShopType()) + && shopVo.getExpirationTime() != null + && currentTime > shopVo.getExpirationTime().getTime() + && shopVo.getShopType().equals("5")) { // 如果当前时间超过到期时间则修改店铺授权状态 shopVo.setShopAuthorize("2"); - // 修改数据库 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setShopAuthorize("2"); - updateByBo(shopBo); - } - //校验是否过期 - String result2 = InterfaceUtils.getInterface(UrlUtil.getServiceGoUrl(),"/api/user/getKfzUserRecbusiness?userId="+shopVo.getId()); - Map resultMap = JSONObject.parseObject(result2, Map.class); - if(resultMap.get("message").equals("success")){ - //成功 - Map data = (Map) resultMap.get("data"); -// shopVo.setExpirationTime(new Date((Long) data.get("expirationDate"))); - shopVo.setShopExpirationTime(new Date((Long) data.get("expirationDate"))); - if(!(Boolean) data.get("isVip")){ - //过期,修改店铺设置 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setIsExpiration("2"); - updateByBo(shopBo); - } - }else{ - if(StringUtils.isEmpty(shopVo.getIsExpiration())){ - //为空赋值0 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setIsExpiration("0"); - updateByBo(shopBo); - } + updateShopSubscribeStatusQuietly(shopVo.getId(), "2", null, null); } + syncShopSubscriptionStatus(shopVo); } } @@ -406,11 +341,7 @@ public class ShopServiceImpl implements IShopService { shopVo.setShopExpirationTime(new Date((Long) data.get("expirationDate"))); shopList.add(shopVo); }else{ - //过期,修改店铺设置 - ShopBo shopBo = new ShopBo(); - shopBo.setId(shopVo.getId()); - shopBo.setIsExpiration("2"); - updateByBo(shopBo); + updateShopSubscribeStatusQuietly(shopVo.getId(), null, "2", null); } } } @@ -453,9 +384,7 @@ public class ShopServiceImpl implements IShopService { bo.setIsSynOrder(1); bo.setUpdateTime(DateUtils.getNowDate()); bo.setUpdateBy(LoginHelper.getUserId()); - if(StringUtils.isEmpty(bo.getShopAuthorize())){ - bo.setShopAuthorize("0"); - } + applyManualAuthorizeStatus(bo); bo.setAddTime(DateUtils.getNowDate()); if (StringUtils.isEmpty(bo.getShopGroup())) { bo.setShopGroup("默认分组"); @@ -547,6 +476,7 @@ public class ShopServiceImpl implements IShopService { */ @Override public Boolean updateByBo(ShopBo bo) { + applyManualAuthorizeStatus(bo); Shop update = MapstructUtils.convert(bo, Shop.class); validEntityBeforeSave(update); boolean flag = baseMapper.updateById(update) > 0; @@ -573,8 +503,7 @@ public class ShopServiceImpl implements IShopService { String response = HttpUtils.sendPost(url, headers, jsonBody); System.out.println("调用updateShopHandler接口成功,响应: " + response); } catch (Exception e) { - System.err.println("调用updateShopHandler接口失败: " + e.getMessage()); - e.printStackTrace(); + log.warn("调用updateShopHandler接口失败, shopId={}: {}", bo.getId(), e.getMessage()); } // insertShopIntoRedis(bo); @@ -589,6 +518,123 @@ public class ShopServiceImpl implements IShopService { // TODO 做一些数据校验,如唯一约束 } + private static final String PERMANENT_EXPIRATION_TIME = "2099-12-31 12:00:00"; + + /** 淘宝店铺类型 */ + private static final String TB_SHOP_TYPE = "6"; + + /** + * 淘宝店铺:新增/修改 Token+UserID,默认永久授权,订阅默认未开通 + */ + private void applyManualAuthorizeStatus(ShopBo bo) { + if (!isTaobaoShopType(bo.getShopType())) { + if (bo.getId() == null && StringUtils.isEmpty(bo.getShopAuthorize())) { + bo.setShopAuthorize("0"); + } + return; + } + if (bo.getId() == null) { + bo.setShopAuthorize("1"); + if (bo.getExpirationTime() == null) { + bo.setExpirationTime(DateUtils.parseDate(PERMANENT_EXPIRATION_TIME)); + } + bo.setIsExpiration("0"); + return; + } + if (StringUtils.isNotBlank(bo.getToken()) && bo.getMallId() != null) { + bo.setShopAuthorize("1"); + } + } + + private boolean isTaobaoShopType(String shopType) { + return TB_SHOP_TYPE.equals(shopType); + } + + /** + * 列表查询同步订阅状态时仅更新数据库,不触发 Redis 同步 + */ + private void updateShopSubscribeStatusQuietly(Long shopId, String shopAuthorize, String isExpiration, Date shopExpirationTime) { + if (shopId == null) { + return; + } + LambdaUpdateChainWrapper update = new LambdaUpdateChainWrapper<>(baseMapper); + update.eq(Shop::getId, shopId); + boolean hasField = false; + if (StringUtils.isNotBlank(shopAuthorize)) { + update.set(Shop::getShopAuthorize, shopAuthorize); + hasField = true; + } + if (StringUtils.isNotBlank(isExpiration)) { + update.set(Shop::getIsExpiration, isExpiration); + hasField = true; + } + if (shopExpirationTime != null) { + update.set(Shop::getShopExpirationTime, shopExpirationTime); + hasField = true; + } + if (hasField) { + update.update(); + } + } + + private Date parseExpirationDate(Object expirationDate) { + if (expirationDate == null) { + return null; + } + if (expirationDate instanceof Date) { + return (Date) expirationDate; + } + if (expirationDate instanceof Number) { + return new Date(((Number) expirationDate).longValue()); + } + if (expirationDate instanceof String && StringUtils.isNotBlank((String) expirationDate)) { + return new Date(Long.parseLong((String) expirationDate)); + } + return null; + } + + /** + * 同步孔夫子/闲鱼/淘宝等店铺的订阅状态(统一走 Go 接口) + */ + private void syncShopSubscriptionStatus(ShopVo shopVo) { + String result2 = InterfaceUtils.getInterface(UrlUtil.getServiceGoUrl(), + "/api/user/getKfzUserRecbusiness?userId=" + shopVo.getId()); + Map resultMap = JSONObject.parseObject(result2, Map.class); + if (resultMap != null && "success".equals(String.valueOf(resultMap.get("message")))) { + Map data = (Map) resultMap.get("data"); + if (data != null) { + Date expiration = parseExpirationDate(data.get("expirationDate")); + String targetStatus = Boolean.TRUE.equals(data.get("isVip")) ? "1" : "2"; + Date dbExpiration = shopVo.getShopExpirationTime(); + boolean statusChanged = !targetStatus.equals(shopVo.getIsExpiration()); + boolean expirationChanged = expiration != null + && (dbExpiration == null || expiration.getTime() != dbExpiration.getTime()); + if (statusChanged || expirationChanged) { + updateShopSubscribeStatusQuietly(shopVo.getId(), null, + statusChanged ? targetStatus : shopVo.getIsExpiration(), expiration); + } + if (expiration != null) { + shopVo.setShopExpirationTime(expiration); + } + shopVo.setIsExpiration(targetStatus); + } + } else if (StringUtils.isEmpty(shopVo.getIsExpiration())) { + updateShopSubscribeStatusQuietly(shopVo.getId(), null, "0", null); + shopVo.setIsExpiration("0"); + } + } + + @Override + public void refreshShopSubscriptionStatus(Long shopId) { + if (shopId == null) { + return; + } + ShopVo shopVo = queryById(shopId); + if (shopVo != null && !"1".equals(shopVo.getShopType())) { + syncShopSubscriptionStatus(shopVo); + } + } + /** * 校验并批量删除店铺主表信息 * diff --git a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/impl/UserRechargeServiceImpl.java b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/impl/UserRechargeServiceImpl.java index bdebbb0..c5b9383 100644 --- a/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/impl/UserRechargeServiceImpl.java +++ b/ruoyi-modules/ruoyi-zhishu/src/main/java/org/dromara/zhishu/service/impl/UserRechargeServiceImpl.java @@ -222,6 +222,9 @@ public class UserRechargeServiceImpl implements IUserRechargeService { case 1: logTxt = "孔夫子店铺订阅;"; break; + case 2: + logTxt = "淘宝店铺订阅;"; + break; case 3: logTxt = "闲鱼店铺订阅;"; break;