Sfoglia il codice sorgente

第三方接口调整提交代码

liuchengsen 1 mese fa
parent
commit
c9e9e71949

+ 5 - 5
zhijiayun-activity/src/main/java/com/xuekairui/activity/mapper/CheckInPeriodMapper.java

@@ -11,11 +11,11 @@ import java.time.LocalDate;
 @Mapper
 public interface CheckInPeriodMapper extends BaseMapper<CheckInPeriod> {
 
-    /** 查询包含指定日期的进行中周期 */
-    @Select("SELECT * FROM t_checkin_period WHERE start_date <= #{date} AND end_date >= #{date} AND status = 'ACTIVE' ORDER BY start_date DESC LIMIT 1")
+    /** 查询包含指定日期的进行中周期(按日期动态判断,不依赖静态 status) */
+    @Select("SELECT * FROM t_checkin_period WHERE start_date <= #{date} AND end_date >= #{date} ORDER BY start_date DESC LIMIT 1")
     CheckInPeriod findActiveByDate(@Param("date") LocalDate date);
 
-    /** 查询最近一个已结束的周期(已结束但可能未发奖) */
-    @Select("SELECT * FROM t_checkin_period WHERE end_date < #{date} AND status = 'CLOSED' ORDER BY end_date DESC LIMIT 1")
+    /** 查询最近一个已结束的周期(按日期动态判断,不依赖静态 status) */
+    @Select("SELECT * FROM t_checkin_period WHERE end_date < #{date} ORDER BY end_date DESC LIMIT 1")
     CheckInPeriod findLastClosedByDate(@Param("date") LocalDate date);
-}
+}

+ 32 - 12
zhijiayun-activity/src/main/java/com/xuekairui/activity/service/CheckInConfigService.java

@@ -95,10 +95,13 @@ public class CheckInConfigService {
         checkinConfigMapper.updateById(config);
 
         boolean active = request.getEnabled() != null && request.getEnabled() == 1;
-        if (active && (timeChanged || modeChanged)) {
-            regeneratePeriods(config);
-        } else if (active && rewardChanged) {
-            updatePendingPeriodsConfig(config);
+        if (active) {
+            if (timeChanged || modeChanged) {
+                regeneratePeriods(config);
+                updatePendingPeriodsConfig(config);
+            } else if (rewardChanged) {
+                updatePendingPeriodsConfig(config);
+            }
         }
 
         log.info("签到全局配置已更新: enabled={}, cycleMode={}, requiredDays={}, rewardDays={}",
@@ -117,11 +120,12 @@ public class CheckInConfigService {
             return;
         }
         
+        LocalDate today = LocalDate.now();
         com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CheckInPeriod> deleteWrapper =
                 new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
-        deleteWrapper.eq(CheckInPeriod::getStatus, "PENDING");
+        deleteWrapper.gt(CheckInPeriod::getStartDate, today);
         int deleted = periodMapper.delete(deleteWrapper);
-        log.info("已删除{}个PENDING周期", deleted);
+        log.info("已删除{}个未开始周期", deleted);
         
         LocalDate activityStart = config.getStartTime().toLocalDate();
         LocalDate activityEnd = config.getEndTime().toLocalDate();
@@ -138,7 +142,8 @@ public class CheckInConfigService {
     public void updatePendingPeriodsConfig(CheckInConfig config) {
         com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CheckInPeriod> wrapper =
                 new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
-        wrapper.in(CheckInPeriod::getStatus, "PENDING", "ACTIVE");
+        LocalDate today = LocalDate.now();
+        wrapper.ge(CheckInPeriod::getEndDate, today);
         List<CheckInPeriod> pendingPeriods = periodMapper.selectList(wrapper);
         if (pendingPeriods.isEmpty()) {
             return;
@@ -148,9 +153,10 @@ public class CheckInConfigService {
             period.setRewardMode(orDefault(config.getRewardMode(), "CUMULATIVE"));
             period.setRewardDays(config.getRewardDays());
             period.setRewardLevel(orDefault(config.getRewardLevel(), "PRO"));
+            period.setStatus(determineStatus(period.getStartDate(), period.getEndDate()));
             periodMapper.updateById(period);
         }
-        log.info("已同步{}个PENDING/ACTIVE周期的区分信息", pendingPeriods.size());
+        log.info("已同步{}个未结束周期的区分信息", pendingPeriods.size());
     }
     
     /**
@@ -209,7 +215,9 @@ public class CheckInConfigService {
      * 判断活动是否进行中(enabled=1 且在活动时间范围内)
      */
     public boolean isActive(CheckInConfig config) {
-        if (config.getEnabled() == null || config.getEnabled() != 1) return false;
+        if (config.getEnabled() == null || config.getEnabled() != 1) {
+            return false;
+        }
         LocalDateTime now = LocalDateTime.now();
         return !isBeforeStart(config, now) && !isAfterEnd(config, now);
     }
@@ -230,7 +238,15 @@ public class CheckInConfigService {
         com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CheckInPeriod> wrapper =
                 new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
         wrapper.orderByAsc(CheckInPeriod::getStartDate);
-        return periodMapper.selectList(wrapper);
+        List<CheckInPeriod> periods = periodMapper.selectList(wrapper);
+        for (CheckInPeriod period : periods) {
+            String dynamicStatus = determineStatus(period.getStartDate(), period.getEndDate());
+            if (!dynamicStatus.equals(period.getStatus())) {
+                period.setStatus(dynamicStatus);
+                periodMapper.updateById(period);
+            }
+        }
+        return periods;
     }
 
     @Transactional
@@ -289,8 +305,12 @@ public class CheckInConfigService {
     /** 根据日期自动判断周期状态 */
     private String determineStatus(LocalDate start, LocalDate end) {
         LocalDate today = LocalDate.now();
-        if (today.isBefore(start)) return "PENDING";
-        if (today.isAfter(end)) return "CLOSED";
+        if (today.isBefore(start)) {
+            return "PENDING";
+        }
+        if (today.isAfter(end)) {
+            return "CLOSED";
+        }
         return "ACTIVE";
     }
 

+ 2 - 2
zhijiayun-gateway/src/main/resources/application.yml

@@ -46,13 +46,13 @@ wechat:
 # 以下 yml 配置仅用于数据库无匹配记录时的兜底,正式使用请通过运营端管理
 external-system:
   miniapp:
-    base-url: ${EXTERNAL_MINIAPP_API_URL:}
+    base-url: ${EXTERNAL_MINIAPP_API_URL:https://api.kailin.com.cn}
     api-key: ${EXTERNAL_MINIAPP_API_KEY:a3f8c21e67b94d0e5f1a6c8d3b9e2071}
     connect-timeout: 5000
     read-timeout: 10000
   # 第三方"智价云药店版"店铺资源同步接口(审核入驻信息通过后推送客户信息)
   shop-resource:
-    base-url: ${EXTERNAL_SHOP_RESOURCE_API_URL:}
+    base-url: ${EXTERNAL_SHOP_RESOURCE_API_URL:https://api.kailin.com.cn}
     app-id: ${EXTERNAL_SHOP_RESOURCE_APP_ID:wx246605ec671bf08d}
     connect-timeout: 5000
     read-timeout: 10000

+ 51 - 0
zhijiayun-user/src/main/java/com/xuekairui/user/service/AuthService.java

@@ -938,6 +938,13 @@ public class AuthService {
     }
 
     private void syncBusinessLicense(SyncInfoRequest request, Long userId) {
+        // 先更新用户基本信息(非空即覆盖),确保入驻信息同步时用户信息也一并保存
+        User user = userMapper.selectById(userId);
+        if (user != null) {
+            applySyncInfoUserFields(user, request);
+            userMapper.updateById(user);
+        }
+
         String storeName = (request.getStoreName() != null && !request.getStoreName().isBlank())
                 ? request.getStoreName() : request.getPharmacyName();
 
@@ -1078,6 +1085,50 @@ public class AuthService {
         }
     }
 
+    /**
+     * 将 SyncInfoRequest 中的用户字段覆盖到本地 User 记录(非空即覆盖)
+     */
+    private void applySyncInfoUserFields(User user, SyncInfoRequest req) {
+        if (isNotBlank(req.getUsername())) {
+            user.setUserName(req.getUsername());
+        }
+        if (isNotBlank(req.getNickname())) {
+            user.setNickname(req.getNickname());
+        } else if (isNotBlank(req.getUsername())) {
+            user.setNickname(req.getUsername());
+        }
+        if (isNotBlank(req.getPharmacyName())) {
+            user.setPharmacyName(req.getPharmacyName());
+        }
+        if (isNotBlank(req.getProvince())) {
+            user.setProvince(req.getProvince());
+        }
+        if (isNotBlank(req.getCity())) {
+            user.setCity(req.getCity());
+        }
+        if (isNotBlank(req.getDistrict())) {
+            user.setDistrict(req.getDistrict());
+        }
+        if (isNotBlank(req.getPharmacyAddress())) {
+            user.setPharmacyAddress(req.getPharmacyAddress());
+        }
+        if (isNotBlank(req.getContactPerson())) {
+            user.setContactPerson(req.getContactPerson());
+        }
+        if (isNotBlank(req.getContactPhone())) {
+            user.setContactPhone(req.getContactPhone());
+        }
+        if (isNotBlank(req.getBusinessLicenseNo())) {
+            user.setBusinessLicenseNo(req.getBusinessLicenseNo());
+        }
+        if (isNotBlank(req.getOpenId())) {
+            user.setWechatMiniOpenId(req.getOpenId());
+        }
+        if (isNotBlank(req.getUnionId())) {
+            user.setWechatUnionId(req.getUnionId());
+        }
+    }
+
     /**
      * 首次入驻审核通过:赠送30天高级会员 + 推送Redis事件供活动模块消费
      * <p>与 BusinessLicenseService.approve() 的奖励逻辑保持一致。

+ 12 - 5
zhijiayun-user/src/main/java/com/xuekairui/user/service/BusinessLicenseService.java

@@ -557,8 +557,15 @@ public class BusinessLicenseService {
                 license.setExternalId(result.getUserId());
                 license.setStatus(1);
                 businessLicenseMapper.updateById(license);
-                log.info("同步客户入驻信息到第三方成功: licenseId={}, externalUserId={}, newUser={}",
-                        license.getId(), result.getUserId(), result.getNewUser());
+                log.info("同步客户入驻信息到第三方成功: licenseId={}, phone={}, storeName={}, terminalType={}, reviewStatus={}, externalUserId={}, newUser={}, accessToken={}",
+                        license.getId(),
+                        phone != null ? phone : "UNKNOWN",
+                        storeName,
+                        license.getTerminalType(),
+                        license.getReviewStatus(),
+                        result.getUserId(),
+                        result.getNewUser(),
+                        result.getAccessToken() != null ? "***" : null);
 
                 auditLogService.logSuccess(
                         0L,
@@ -911,9 +918,9 @@ public class BusinessLicenseService {
         if (license == null) {
             throw new BusinessException(ErrorCode.NOT_FOUND, "入驻信息记录不存在");
         }
-        if (!LicenseStatus.PENDING.name().equals(license.getReviewStatus())) {
-            throw new BusinessException(ErrorCode.BAD_REQUEST, "该入驻信息已审核,无法重复操作");
-        }
+//        if (!LicenseStatus.PENDING.name().equals(license.getReviewStatus())) {
+//            throw new BusinessException(ErrorCode.BAD_REQUEST, "该入驻信息已审核,无法重复操作");
+//        }
         return license;
     }