|
@@ -18,6 +18,8 @@ import com.fs.common.core.page.TableDataInfo;
|
|
|
import com.fs.common.enums.BusinessType;
|
|
import com.fs.common.enums.BusinessType;
|
|
|
import com.fs.common.utils.ServletUtils;
|
|
import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.bean.BeanUtils;
|
|
import com.fs.common.utils.bean.BeanUtils;
|
|
|
|
|
+import com.fs.common.utils.spring.SpringUtils;
|
|
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
import com.fs.course.enums.MiniProgramAgreementEnum;
|
|
import com.fs.course.enums.MiniProgramAgreementEnum;
|
|
@@ -34,17 +36,20 @@ import com.fs.his.service.MiniProgramAgreementService;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/course/playSourceConfig")
|
|
@RequestMapping("/course/playSourceConfig")
|
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
|
|
|
+@Slf4j
|
|
|
public class FsCoursePlaySourceConfigController extends BaseController {
|
|
public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
|
|
|
|
|
private final IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
|
|
private final IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
|
|
@@ -135,6 +140,10 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
config.setCreateTime(LocalDateTime.now());
|
|
config.setCreateTime(LocalDateTime.now());
|
|
|
config.setUpdateTime(LocalDateTime.now());
|
|
config.setUpdateTime(LocalDateTime.now());
|
|
|
fsCoursePlaySourceConfigService.save(config);
|
|
fsCoursePlaySourceConfigService.save(config);
|
|
|
|
|
+
|
|
|
|
|
+ // 新增配置后直接更新 Redis 缓存
|
|
|
|
|
+ refreshRedisCache(config);
|
|
|
|
|
+
|
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -169,6 +178,10 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
applyCompanyIds(param.getCompanyId(), param.getCompanyIds(), config);
|
|
applyCompanyIds(param.getCompanyId(), param.getCompanyIds(), config);
|
|
|
|
|
|
|
|
fsCoursePlaySourceConfigService.updateById(config);
|
|
fsCoursePlaySourceConfigService.updateById(config);
|
|
|
|
|
+
|
|
|
|
|
+ // 修改配置后直接更新 Redis 缓存
|
|
|
|
|
+ refreshRedisCache(config);
|
|
|
|
|
+
|
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -348,6 +361,26 @@ public class FsCoursePlaySourceConfigController extends BaseController {
|
|
|
return AjaxResult.success(result);
|
|
return AjaxResult.success(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 小程序配置 Redis 缓存 key 前缀(与 WxMaConfiguration 保持一致)
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final String MINIPROGRAM_CONFIG_CACHE_KEY = "miniprogram:config:";
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新 Redis 中的小程序配置缓存,随机 6-8 小时过期
|
|
|
|
|
+ */
|
|
|
|
|
+ private static void refreshRedisCache(FsCoursePlaySourceConfig config) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
|
|
|
|
|
+ String redisKey = MINIPROGRAM_CONFIG_CACHE_KEY + config.getAppid();
|
|
|
|
|
+ int hours = new Random().nextInt(3) + 6;
|
|
|
|
|
+ redisCache.setCacheObject(redisKey, config, hours, TimeUnit.HOURS);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // Redis 异常不影响主流程,缓存会在下次读取时自动回源 DB
|
|
|
|
|
+ log.warn("更新小程序配置Redis缓存失败,appId: {}", config.getAppid(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private static void applyCompanyIds(Long companyId, List<Long> companyIds, FsCoursePlaySourceConfig config) {
|
|
private static void applyCompanyIds(Long companyId, List<Long> companyIds, FsCoursePlaySourceConfig config) {
|
|
|
List<Long> ids = new ArrayList<>();
|
|
List<Long> ids = new ArrayList<>();
|
|
|
if (companyIds != null) {
|
|
if (companyIds != null) {
|