fix: 优化推送消息逻辑
This commit is contained in:
parent
dfca986d97
commit
9bf01de0bb
@ -14,56 +14,56 @@ import io.swagger.v3.oas.models.info.Contact;
|
|||||||
public class SwaggerConfig {
|
public class SwaggerConfig {
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public OpenAPI projectOpenAPI() {
|
|
||||||
return new OpenAPI()
|
|
||||||
.info(new Info()
|
|
||||||
.title("项目API 接口文档")
|
|
||||||
.version("3.0")
|
|
||||||
.description("")
|
|
||||||
.contact(new Contact().name("郑顺利").email("13910913995@163.com"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// @Bean
|
// @Bean
|
||||||
// public OpenAPI projectOpenAPI() {
|
// public OpenAPI projectOpenAPI() {
|
||||||
// // 1. 定义第一个 Header:token
|
|
||||||
// SecurityScheme tokenScheme = new SecurityScheme()
|
|
||||||
// .type(SecurityScheme.Type.APIKEY)
|
|
||||||
// .in(SecurityScheme.In.HEADER)
|
|
||||||
// .name("token")
|
|
||||||
// .description("用户认证 Token");
|
|
||||||
//
|
|
||||||
// // 2. 定义第二个 Header:租户ID(示例)
|
|
||||||
// SecurityScheme tenantScheme = new SecurityScheme()
|
|
||||||
// .type(SecurityScheme.Type.APIKEY)
|
|
||||||
// .in(SecurityScheme.In.HEADER)
|
|
||||||
// .name("Tenant_Id")
|
|
||||||
// .description("租户标识");
|
|
||||||
//
|
|
||||||
// // 3. 将两个安全方案注册到 Components
|
|
||||||
// Components components = new Components()
|
|
||||||
// .addSecuritySchemes("tokenAuth", tokenScheme)
|
|
||||||
// .addSecuritySchemes("tenantAuth", tenantScheme);
|
|
||||||
//
|
|
||||||
// // 4. 创建 SecurityRequirement,同时要求两个 Header 都必须提供
|
|
||||||
// SecurityRequirement securityRequirement = new SecurityRequirement()
|
|
||||||
// .addList("tokenAuth") // 引用 token 方案
|
|
||||||
// .addList("tenantAuth"); // 引用 tenant 方案
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// return new OpenAPI()
|
// return new OpenAPI()
|
||||||
// .info(new Info()
|
// .info(new Info()
|
||||||
// .title("项目API 接口文档")
|
// .title("项目API 接口文档")
|
||||||
// .version("3.0")
|
// .version("3.0")
|
||||||
// .description("")
|
// .description("")
|
||||||
// .contact(new Contact().name("郑顺利").email("13910913995@163.com"))
|
// .contact(new Contact().name("郑顺利").email("13910913995@163.com"))
|
||||||
// )
|
// );
|
||||||
// .components(components)
|
|
||||||
// .addSecurityItem(securityRequirement); // 一次性添加
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI projectOpenAPI() {
|
||||||
|
// 1. 定义第一个 Header:token
|
||||||
|
SecurityScheme tokenScheme = new SecurityScheme()
|
||||||
|
.type(SecurityScheme.Type.APIKEY)
|
||||||
|
.in(SecurityScheme.In.HEADER)
|
||||||
|
.name("token")
|
||||||
|
.description("用户认证 Token");
|
||||||
|
|
||||||
|
// 2. 定义第二个 Header:租户ID(示例)
|
||||||
|
SecurityScheme tenantScheme = new SecurityScheme()
|
||||||
|
.type(SecurityScheme.Type.APIKEY)
|
||||||
|
.in(SecurityScheme.In.HEADER)
|
||||||
|
.name("Tenant_Id")
|
||||||
|
.description("租户标识");
|
||||||
|
|
||||||
|
// 3. 将两个安全方案注册到 Components
|
||||||
|
Components components = new Components()
|
||||||
|
.addSecuritySchemes("tokenAuth", tokenScheme)
|
||||||
|
.addSecuritySchemes("tenantAuth", tenantScheme);
|
||||||
|
|
||||||
|
// 4. 创建 SecurityRequirement,同时要求两个 Header 都必须提供
|
||||||
|
SecurityRequirement securityRequirement = new SecurityRequirement()
|
||||||
|
.addList("tokenAuth") // 引用 token 方案
|
||||||
|
.addList("tenantAuth"); // 引用 tenant 方案
|
||||||
|
|
||||||
|
|
||||||
|
return new OpenAPI()
|
||||||
|
.info(new Info()
|
||||||
|
.title("项目API 接口文档")
|
||||||
|
.version("3.0")
|
||||||
|
.description("")
|
||||||
|
.contact(new Contact().name("郑顺利").email("13910913995@163.com"))
|
||||||
|
)
|
||||||
|
.components(components)
|
||||||
|
.addSecurityItem(securityRequirement); // 一次性添加
|
||||||
|
}
|
||||||
|
|
||||||
// @Bean
|
// @Bean
|
||||||
// public GroupedOpenApi groupPlatformApi() {
|
// public GroupedOpenApi groupPlatformApi() {
|
||||||
// return GroupedOpenApi.builder()
|
// return GroupedOpenApi.builder()
|
||||||
|
|||||||
@ -74,6 +74,13 @@ public class PushConfigController {
|
|||||||
return pushConfigService.setPushConfigStatus(id, status) ? ResponseResult.success() : ResponseResult.error("设置失败");
|
return pushConfigService.setPushConfigStatus(id, status) ? ResponseResult.success() : ResponseResult.error("设置失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Log(module = "推送配置", value = "设置短信推送开关")
|
||||||
|
@Operation(summary = "设置短信推送开关")
|
||||||
|
@PostMapping("/setPushConfigSmsSwitch")
|
||||||
|
public ResponseResult setPushConfigSmsSwitch(@RequestParam String id, @RequestParam Integer isSms) {
|
||||||
|
return pushConfigService.setPushConfigSmsSwitch(id, isSms) ? ResponseResult.success() : ResponseResult.error("设置失败");
|
||||||
|
}
|
||||||
|
|
||||||
@Log(module = "推送配置", value = "保存推送目标")
|
@Log(module = "推送配置", value = "保存推送目标")
|
||||||
@Operation(summary = "保存推送目标")
|
@Operation(summary = "保存推送目标")
|
||||||
@PostMapping("/savePushTargets")
|
@PostMapping("/savePushTargets")
|
||||||
|
|||||||
@ -27,6 +27,8 @@ public interface IPushConfigService extends IService<PushConfig> {
|
|||||||
|
|
||||||
boolean setPushConfigStatus(String id, Integer status);
|
boolean setPushConfigStatus(String id, Integer status);
|
||||||
|
|
||||||
|
boolean setPushConfigSmsSwitch(String id, Integer isSms);
|
||||||
|
|
||||||
boolean savePushTargets(PushConfigTargetRequest request);
|
boolean savePushTargets(PushConfigTargetRequest request);
|
||||||
|
|
||||||
List<PushConfigTargetVo> getPushTargets(String configId);
|
List<PushConfigTargetVo> getPushTargets(String configId);
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import org.quartz.CronExpression;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -93,11 +94,7 @@ public class PushConfigServiceImpl extends ServiceImpl<PushConfigMapper, PushCon
|
|||||||
pushConfig.setIsSms(pushConfig.getIsSms() == null ? 0 : pushConfig.getIsSms());
|
pushConfig.setIsSms(pushConfig.getIsSms() == null ? 0 : pushConfig.getIsSms());
|
||||||
pushConfig.setPushCount(pushConfig.getPushCount() == null ? 0L : pushConfig.getPushCount());
|
pushConfig.setPushCount(pushConfig.getPushCount() == null ? 0L : pushConfig.getPushCount());
|
||||||
pushConfig.setDailyPushCount(pushConfig.getDailyPushCount() == null ? 0L : pushConfig.getDailyPushCount());
|
pushConfig.setDailyPushCount(pushConfig.getDailyPushCount() == null ? 0L : pushConfig.getDailyPushCount());
|
||||||
boolean saved = this.save(pushConfig);
|
return this.save(pushConfig);
|
||||||
if (saved) {
|
|
||||||
syncQuartzJob(pushConfig);
|
|
||||||
}
|
|
||||||
return saved;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -112,8 +109,8 @@ public class PushConfigServiceImpl extends ServiceImpl<PushConfigMapper, PushCon
|
|||||||
dbConfig.setMessageType(pushConfig.getMessageType());
|
dbConfig.setMessageType(pushConfig.getMessageType());
|
||||||
dbConfig.setCronExpression(pushConfig.getCronExpression());
|
dbConfig.setCronExpression(pushConfig.getCronExpression());
|
||||||
dbConfig.setTargetType(pushConfig.getTargetType());
|
dbConfig.setTargetType(pushConfig.getTargetType());
|
||||||
dbConfig.setIsSms(pushConfig.getIsSms() == null ? 0 : pushConfig.getIsSms());
|
// dbConfig.setIsSms(pushConfig.getIsSms() == null ? 0 : pushConfig.getIsSms());
|
||||||
dbConfig.setStatus(pushConfig.getStatus() == null ? dbConfig.getStatus() : pushConfig.getStatus());
|
// dbConfig.setStatus(pushConfig.getStatus() == null ? dbConfig.getStatus() : pushConfig.getStatus());
|
||||||
dbConfig.setUpdatedAt(new Date());
|
dbConfig.setUpdatedAt(new Date());
|
||||||
dbConfig.setModifyTime(new Date());
|
dbConfig.setModifyTime(new Date());
|
||||||
dbConfig.setModifyUser(currentUserIdOrSystem());
|
dbConfig.setModifyUser(currentUserIdOrSystem());
|
||||||
@ -122,7 +119,7 @@ public class PushConfigServiceImpl extends ServiceImpl<PushConfigMapper, PushCon
|
|||||||
if (Objects.equals(dbConfig.getTargetType(), 1)) {
|
if (Objects.equals(dbConfig.getTargetType(), 1)) {
|
||||||
softDeleteTargets(dbConfig.getId(), currentUserIdOrSystem(), new Date());
|
softDeleteTargets(dbConfig.getId(), currentUserIdOrSystem(), new Date());
|
||||||
}
|
}
|
||||||
syncQuartzJob(dbConfig);
|
// refreshQuartzJobIfExists(dbConfig);
|
||||||
}
|
}
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
@ -162,12 +159,36 @@ public class PushConfigServiceImpl extends ServiceImpl<PushConfigMapper, PushCon
|
|||||||
}
|
}
|
||||||
PushConfig config = getAvailableConfig(id);
|
PushConfig config = getAvailableConfig(id);
|
||||||
config.setStatus(status);
|
config.setStatus(status);
|
||||||
|
if (Objects.equals(status, 0)) {
|
||||||
|
config.setIsSms(0);
|
||||||
|
}
|
||||||
|
config.setUpdatedAt(new Date());
|
||||||
|
config.setModifyTime(new Date());
|
||||||
|
config.setModifyUser(currentUserIdOrSystem());
|
||||||
|
boolean updated = this.updateById(config);
|
||||||
|
// if (updated) {
|
||||||
|
// syncQuartzJobBySwitch(config);
|
||||||
|
// }
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean setPushConfigSmsSwitch(String id, Integer isSms) {
|
||||||
|
if (StrUtil.isBlank(id) || isSms == null) {
|
||||||
|
throw new BizException("参数不能为空.");
|
||||||
|
}
|
||||||
|
if (!Objects.equals(isSms, 0) && !Objects.equals(isSms, 1)) {
|
||||||
|
throw new BizException("短信推送开关值不正确.");
|
||||||
|
}
|
||||||
|
PushConfig config = getAvailableConfig(id);
|
||||||
|
config.setIsSms(isSms);
|
||||||
config.setUpdatedAt(new Date());
|
config.setUpdatedAt(new Date());
|
||||||
config.setModifyTime(new Date());
|
config.setModifyTime(new Date());
|
||||||
config.setModifyUser(currentUserIdOrSystem());
|
config.setModifyUser(currentUserIdOrSystem());
|
||||||
boolean updated = this.updateById(config);
|
boolean updated = this.updateById(config);
|
||||||
if (updated) {
|
if (updated) {
|
||||||
syncQuartzJob(config);
|
syncQuartzJobBySwitch(config);
|
||||||
}
|
}
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
@ -389,7 +410,8 @@ public class PushConfigServiceImpl extends ServiceImpl<PushConfigMapper, PushCon
|
|||||||
quartzJob.setDescription("推送配置定时任务-" + config.getMessageType());
|
quartzJob.setDescription("推送配置定时任务-" + config.getMessageType());
|
||||||
quartzJob.setStatus(Objects.equals(config.getStatus(), 1) ? "1" : "0");
|
quartzJob.setStatus(Objects.equals(config.getStatus(), 1) ? "1" : "0");
|
||||||
quartzJob.setLastmodifier(currentUsernameOrSystem());
|
quartzJob.setLastmodifier(currentUsernameOrSystem());
|
||||||
quartzJob.setLastmodifydate(new java.sql.Timestamp(now.getTime()));
|
quartzJob.setLastmodifydate(new Timestamp(now.getTime()));
|
||||||
|
quartzJob.setOrderno(0);
|
||||||
if (StrUtil.isBlank(quartzJob.getId())) {
|
if (StrUtil.isBlank(quartzJob.getId())) {
|
||||||
quartzJobService.save(quartzJob);
|
quartzJobService.save(quartzJob);
|
||||||
quartzManage.addJob(quartzJob);
|
quartzManage.addJob(quartzJob);
|
||||||
@ -399,6 +421,32 @@ public class PushConfigServiceImpl extends ServiceImpl<PushConfigMapper, PushCon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void refreshQuartzJobIfExists(PushConfig config) {
|
||||||
|
QuartzJob quartzJob = getPushQuartzJob(config.getId());
|
||||||
|
if (quartzJob == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (canCreateQuartzJob(config)) {
|
||||||
|
syncQuartzJob(config);
|
||||||
|
} else {
|
||||||
|
deleteQuartzJob(config.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncQuartzJobBySwitch(PushConfig config) {
|
||||||
|
if (canCreateQuartzJob(config)) {
|
||||||
|
syncQuartzJob(config);
|
||||||
|
} else {
|
||||||
|
deleteQuartzJob(config.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canCreateQuartzJob(PushConfig config) {
|
||||||
|
return config != null
|
||||||
|
&& Objects.equals(config.getStatus(), 1)
|
||||||
|
&& Objects.equals(config.getIsSms(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
private void deleteQuartzJob(String configId) {
|
private void deleteQuartzJob(String configId) {
|
||||||
QuartzJob quartzJob = getPushQuartzJob(configId);
|
QuartzJob quartzJob = getPushQuartzJob(configId);
|
||||||
if (quartzJob != null) {
|
if (quartzJob != null) {
|
||||||
@ -411,7 +459,7 @@ public class PushConfigServiceImpl extends ServiceImpl<PushConfigMapper, PushCon
|
|||||||
List<QuartzJob> list = quartzJobService.list(new LambdaQueryWrapper<QuartzJob>()
|
List<QuartzJob> list = quartzJobService.list(new LambdaQueryWrapper<QuartzJob>()
|
||||||
.eq(QuartzJob::getCustom1, QUARTZ_BIZ_TYPE)
|
.eq(QuartzJob::getCustom1, QUARTZ_BIZ_TYPE)
|
||||||
.eq(QuartzJob::getCustom2, configId));
|
.eq(QuartzJob::getCustom2, configId));
|
||||||
return list.isEmpty() ? null : list.get(0);
|
return list.isEmpty() ? null : list.getFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PushTargetUserVo> resolveTargets(PushConfig config) {
|
private List<PushTargetUserVo> resolveTargets(PushConfig config) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user