|
|
@@ -1,5 +1,9 @@
|
|
|
package com.xuekairui.invite.service;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.xuekairui.common.BusinessException;
|
|
|
+import com.xuekairui.common.ErrorCode;
|
|
|
import com.xuekairui.invite.dto.InviteConfigRequest;
|
|
|
import com.xuekairui.invite.entity.InviteConfig;
|
|
|
import com.xuekairui.invite.mapper.InviteConfigMapper;
|
|
|
@@ -49,11 +53,86 @@ public class InviteConfigService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新邀请配置
|
|
|
+ * 更新当前生效的邀请配置(无则自动创建)
|
|
|
*/
|
|
|
public InviteConfig updateConfig(InviteConfigRequest request) {
|
|
|
InviteConfig config = getActiveConfig();
|
|
|
+ buildConfigFromRequest(config, request);
|
|
|
|
|
|
+ if (config.getId() != null) {
|
|
|
+ inviteConfigMapper.updateById(config);
|
|
|
+ } else {
|
|
|
+ inviteConfigMapper.insert(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("邀请配置已更新: rewardType={}, rewardMonths={}, appDownloadUrl={}, miniappPath={}",
|
|
|
+ config.getRewardType(), config.getRewardMonths(), config.getAppDownloadUrl(), config.getMiniappPath());
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页获取配置列表(运营查看)
|
|
|
+ */
|
|
|
+ public Page<InviteConfig> listConfigs(Integer page, Integer size) {
|
|
|
+ int pageNo = page != null && page > 0 ? page : 1;
|
|
|
+ int pageSize = Math.min(size != null && size > 0 ? size : 20, 50);
|
|
|
+ Page<InviteConfig> pageParam = new Page<>(pageNo, pageSize);
|
|
|
+ LambdaQueryWrapper<InviteConfig> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.orderByDesc(InviteConfig::getCreateTime);
|
|
|
+ return inviteConfigMapper.selectPage(pageParam, wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ID获取配置
|
|
|
+ */
|
|
|
+ public InviteConfig getById(Long id) {
|
|
|
+ InviteConfig config = inviteConfigMapper.selectById(id);
|
|
|
+ if (config == null) {
|
|
|
+ throw new BusinessException(ErrorCode.NOT_FOUND, "邀请配置不存在");
|
|
|
+ }
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建新的邀请配置
|
|
|
+ */
|
|
|
+ public InviteConfig createConfig(InviteConfigRequest request) {
|
|
|
+ InviteConfig config = buildConfigFromRequest(new InviteConfig(), request);
|
|
|
+ inviteConfigMapper.insert(config);
|
|
|
+ log.info("创建邀请配置: id={}, rewardType={}, rewardMonths={}", config.getId(), config.getRewardType(), config.getRewardMonths());
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新指定ID的邀请配置
|
|
|
+ */
|
|
|
+ public InviteConfig updateConfig(Long id, InviteConfigRequest request) {
|
|
|
+ InviteConfig config = inviteConfigMapper.selectById(id);
|
|
|
+ if (config == null) {
|
|
|
+ throw new BusinessException(ErrorCode.NOT_FOUND, "邀请配置不存在");
|
|
|
+ }
|
|
|
+ buildConfigFromRequest(config, request);
|
|
|
+ inviteConfigMapper.updateById(config);
|
|
|
+ log.info("更新邀请配置: id={}, rewardType={}, rewardMonths={}", config.getId(), config.getRewardType(), config.getRewardMonths());
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除邀请配置
|
|
|
+ */
|
|
|
+ public void deleteConfig(Long id) {
|
|
|
+ InviteConfig config = inviteConfigMapper.selectById(id);
|
|
|
+ if (config == null) {
|
|
|
+ throw new BusinessException(ErrorCode.NOT_FOUND, "邀请配置不存在");
|
|
|
+ }
|
|
|
+ inviteConfigMapper.deleteById(id);
|
|
|
+ log.info("删除邀请配置: id={}", id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将请求参数填充到配置实体
|
|
|
+ */
|
|
|
+ private InviteConfig buildConfigFromRequest(InviteConfig config, InviteConfigRequest request) {
|
|
|
if (request.getRewardCrawlerCount() != null) {
|
|
|
config.setRewardCrawlerCount(request.getRewardCrawlerCount());
|
|
|
}
|
|
|
@@ -75,7 +154,6 @@ public class InviteConfigService {
|
|
|
if (request.getMaxTotalInvites() != null) {
|
|
|
config.setMaxTotalInvites(request.getMaxTotalInvites());
|
|
|
}
|
|
|
- // 多渠道配置
|
|
|
if (request.getAppDownloadUrl() != null) {
|
|
|
config.setAppDownloadUrl(request.getAppDownloadUrl());
|
|
|
}
|
|
|
@@ -94,7 +172,6 @@ public class InviteConfigService {
|
|
|
if (request.getFeishuAppId() != null) {
|
|
|
config.setFeishuAppId(request.getFeishuAppId());
|
|
|
}
|
|
|
- // 落地页配置
|
|
|
if (request.getLandingTitle() != null) {
|
|
|
config.setLandingTitle(request.getLandingTitle());
|
|
|
}
|
|
|
@@ -110,7 +187,6 @@ public class InviteConfigService {
|
|
|
if (request.getRemark() != null) {
|
|
|
config.setRemark(request.getRemark());
|
|
|
}
|
|
|
- // 文案模板配置
|
|
|
if (request.getShareTitleTemplate() != null) {
|
|
|
config.setShareTitleTemplate(request.getShareTitleTemplate());
|
|
|
}
|
|
|
@@ -144,22 +220,6 @@ public class InviteConfigService {
|
|
|
if (request.getInstructionDefault() != null) {
|
|
|
config.setInstructionDefault(request.getInstructionDefault());
|
|
|
}
|
|
|
-
|
|
|
- if (config.getId() != null) {
|
|
|
- inviteConfigMapper.updateById(config);
|
|
|
- } else {
|
|
|
- inviteConfigMapper.insert(config);
|
|
|
- }
|
|
|
-
|
|
|
- log.info("邀请配置已更新: rewardType={}, rewardMonths={}, appDownloadUrl={}, miniappPath={}",
|
|
|
- config.getRewardType(), config.getRewardMonths(), config.getAppDownloadUrl(), config.getMiniappPath());
|
|
|
return config;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取配置列表(运营查看)
|
|
|
- */
|
|
|
- public List<InviteConfig> listConfigs() {
|
|
|
- return inviteConfigMapper.selectList(null);
|
|
|
- }
|
|
|
}
|