diff --git a/pom.xml b/pom.xml index 6391d0c..54b97a8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,8 +5,8 @@ org.springframework.boot spring-boot-starter-parent - 3.1.1 - + 3.3.0 + sast.evento SAST-Evento @@ -14,55 +14,52 @@ SAST-Evento-Backend SAST-Evento-Backend - 17 + 21 + - org.springframework.boot - spring-boot-starter-web + fun.feellmoose + sast-link-SDK + 0.1.2 + - org.springframework.boot - spring-boot-starter-aop + com.auth0 + java-jwt + 3.4.0 + - org.springframework.boot - spring-boot-starter-cache + com.baomidou + mybatis-plus-boot-starter + 3.5.3.1 - - + - fun.feellmoose - sast-link-SDK - 0.1.2 + org.mybatis + mybatis-spring + 3.0.3 - - + - org.springframework.boot - spring-boot-starter-quartz + com.qcloud + cos_api + 5.6.213 org.springframework.boot - spring-boot-starter-test - test + spring-boot-starter-web - org.springframework.boot - spring-boot-starter-data-redis - - - com.baomidou - mybatis-plus-boot-starter - 3.5.3.1 + spring-boot-starter-cache - mysql - mysql-connector-java - 8.0.33 + org.springframework.boot + spring-boot-starter-data-redis @@ -70,39 +67,20 @@ lombok true - - - com.auth0 - java-jwt - 3.4.0 + com.mysql + mysql-connector-j + runtime - - - com.qcloud - cos_api - 5.6.155 + org.springframework.boot + spring-boot-starter-test + test - - - - alimaven - https://maven.aliyun.com/repository/public - - - - - - alimaven - https://maven.aliyun.com/repository/public - - - diff --git a/src/main/java/sast/evento/annotation/DefaultActionState.java b/src/main/java/sast/evento/annotation/DefaultActionState.java index d3b9d6a..fe3319e 100644 --- a/src/main/java/sast/evento/annotation/DefaultActionState.java +++ b/src/main/java/sast/evento/annotation/DefaultActionState.java @@ -7,10 +7,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Require Authorization. + * Default action state of an event. + */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface DefaultActionState { - /* 添加注释后,默认为管理员操作 */ ActionState value() default ActionState.ADMIN; String group() default "default"; } diff --git a/src/main/java/sast/evento/annotation/EventId.java b/src/main/java/sast/evento/annotation/EventId.java index 2a38b90..0bdef9d 100644 --- a/src/main/java/sast/evento/annotation/EventId.java +++ b/src/main/java/sast/evento/annotation/EventId.java @@ -4,6 +4,10 @@ import java.lang.annotation.*; +/** + * Require Authorization. + * Description which param is needed for event check. + */ @Target({ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented diff --git a/src/main/java/sast/evento/annotation/OperateLog.java b/src/main/java/sast/evento/annotation/Operation.java similarity index 86% rename from src/main/java/sast/evento/annotation/OperateLog.java rename to src/main/java/sast/evento/annotation/Operation.java index 27eb991..5c98844 100644 --- a/src/main/java/sast/evento/annotation/OperateLog.java +++ b/src/main/java/sast/evento/annotation/Operation.java @@ -8,12 +8,11 @@ import java.lang.annotation.Target; /** - * @author: NicoAsuka - * @date: 4/29/23 + * Describe operation of API. */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) -public @interface OperateLog { +public @interface Operation { @AliasFor(attribute = "description") String value() default ""; diff --git a/src/main/java/sast/evento/aop/OperateLogAspect.java b/src/main/java/sast/evento/aop/OperateLogAspect.java deleted file mode 100644 index 203b02e..0000000 --- a/src/main/java/sast/evento/aop/OperateLogAspect.java +++ /dev/null @@ -1,97 +0,0 @@ -package sast.evento.aop; - -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.Signature; -import org.aspectj.lang.annotation.AfterThrowing; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Pointcut; -import org.aspectj.lang.reflect.MethodSignature; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; -import sast.evento.annotation.OperateLog; -import sast.evento.interceptor.LogInterceptor; - -import java.lang.reflect.Field; -import java.util.*; - -/** - * @author: NicoAsuka - * @date: 4/29/23 - */ -@Aspect -@Component -@Slf4j -public class OperateLogAspect { - private final static Set EXCLUDE_SET; - - static { - EXCLUDE_SET = new HashSet<>(); - EXCLUDE_SET.add("password"); - } - - @Pointcut("@annotation(sast.evento.annotation.OperateLog)") - public void operateLog() { - } - - @Around("operateLog() && @annotation(anno)") - public Object aroundMethod(ProceedingJoinPoint proceedingPoint, OperateLog anno) throws Throwable { - Optional.ofNullable(LogInterceptor.logHolder.get()).ifPresent( - traceLog -> log.info(traceLog - .setDescription(anno.value()) - .setFinishTime(System.currentTimeMillis()) - .toLogFormat(true)) - ); - return proceedingPoint.proceed(); - } - - - @AfterThrowing(pointcut = "operateLog()&&@annotation(anno)", throwing = "exception") - public void throwHandler(JoinPoint joinPoint, OperateLog anno, Throwable exception) { - Signature sg = joinPoint.getSignature(); - Field[] declaredFields1 = sg.getDeclaringType().getDeclaredFields(); - // 获取当前抛出异常类使用@Resource注入的bean - List classList = Arrays.stream(declaredFields1) - .filter(field -> field.getAnnotation(Resource.class) != null) - .map(Field::getType) - .map(Class::getSimpleName).toList(); - HashSet classSet = new HashSet<>(classList); - - MethodSignature signature = (MethodSignature) joinPoint.getSignature(); - // 获取当前抛出异常的方法名称和类 - String eleMethodName = signature.getMethod().getName(); - String typeName = signature.getDeclaringTypeName(); - - // 获取抛出异常的stackTrace - StackTraceElement[] stackTrace = exception.getStackTrace(); - // 拿到需要的stackTrace,只拿以下两种 stackTrace - // 注入的bean和controller方法 - List stackTraceList = Arrays.stream(stackTrace).filter(ele -> { - if (eleMethodName.equals(ele.getMethodName()) && typeName.equals(ele.getClassName())) - return true; - if (ele.getFileName() != null) - return classSet.stream().anyMatch(ele.getFileName()::contains); - return false; - } - ).toList(); - // 格式处理 - ArrayList errMsg = new ArrayList<>(); - for (StackTraceElement ele : stackTraceList) { - String fileName = ele.getFileName(); - String methodName = ele.getMethodName(); - int lineNumber = ele.getLineNumber(); - String errTrace = fileName + " | " + methodName + " | line:" + lineNumber + " | " + exception.getLocalizedMessage(); - errMsg.add(errTrace); - } - Optional.ofNullable(LogInterceptor.logHolder.get()).ifPresent( - traceLog -> log.error(traceLog - .setDescription(anno.value()) - .setFinishTime(System.currentTimeMillis()) - .setStackTrace(StringUtils.collectionToCommaDelimitedString(errMsg)) - .toLogFormat(false)) - ); - } -} diff --git a/src/main/java/sast/evento/common/Constants.java b/src/main/java/sast/evento/common/Constants.java new file mode 100644 index 0000000..c4dbf9d --- /dev/null +++ b/src/main/java/sast/evento/common/Constants.java @@ -0,0 +1,8 @@ +package sast.evento.common; + +/** + * Constants + */ +public interface Constants { + +} diff --git a/src/main/java/sast/evento/common/constant/Constant.java b/src/main/java/sast/evento/common/constant/Constant.java deleted file mode 100644 index 9e30007..0000000 --- a/src/main/java/sast/evento/common/constant/Constant.java +++ /dev/null @@ -1,14 +0,0 @@ -package sast.evento.common.constant; - -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/31 21:53 - */ -// todo 待删除 -public class Constant { - public static final String wxStableTokenURL = "https://api.weixin.qq.com/cgi-bin/stable_token"; - public static final String wxSubscribeURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={access_token}"; - - -} diff --git a/src/main/java/sast/evento/common/enums/ErrorEnum.java b/src/main/java/sast/evento/common/enums/ErrorEnum.java index 80f4f8c..c71ccc5 100644 --- a/src/main/java/sast/evento/common/enums/ErrorEnum.java +++ b/src/main/java/sast/evento/common/enums/ErrorEnum.java @@ -4,9 +4,7 @@ import lombok.Getter; /** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/12 22:04 + * Error enum hold errMsg to FrontEnd */ @Getter @AllArgsConstructor diff --git a/src/main/java/sast/evento/common/enums/EventState.java b/src/main/java/sast/evento/common/enums/EventState.java index da7119a..8fad601 100644 --- a/src/main/java/sast/evento/common/enums/EventState.java +++ b/src/main/java/sast/evento/common/enums/EventState.java @@ -1,6 +1,8 @@ package sast.evento.common.enums; +import com.baomidou.mybatisplus.annotation.EnumValue; import com.fasterxml.jackson.annotation.JsonValue; +import sast.evento.annotation.EventId; import sast.evento.exception.LocalRunTimeException; import java.util.Arrays; @@ -11,6 +13,8 @@ public enum EventState { IN_PROGRESS(3, "进行中"), CANCELED(4, "已取消"), ENDED(5, "已结束"); + + @EnumValue private final Integer state; private final String description; diff --git a/src/main/java/sast/evento/common/enums/Platform.java b/src/main/java/sast/evento/common/enums/Platform.java deleted file mode 100644 index 121e5d0..0000000 --- a/src/main/java/sast/evento/common/enums/Platform.java +++ /dev/null @@ -1,7 +0,0 @@ -package sast.evento.common.enums; - -public enum Platform { - WeChat, - SastLink, - -} diff --git a/src/main/java/sast/evento/common/typehandler/EventStateTypeHandler.java b/src/main/java/sast/evento/common/typehandler/EventStateTypeHandler.java deleted file mode 100644 index 8d66239..0000000 --- a/src/main/java/sast/evento/common/typehandler/EventStateTypeHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -package sast.evento.common.typehandler; - -import org.apache.ibatis.type.BaseTypeHandler; -import org.apache.ibatis.type.JdbcType; -import sast.evento.common.enums.EventState; - -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/24 20:53 - */ -public class EventStateTypeHandler extends BaseTypeHandler { - @Override - public void setNonNullParameter(PreparedStatement preparedStatement, int i, EventState eventState, JdbcType jdbcType) throws SQLException { - preparedStatement.setInt(i, eventState.getState()); - } - - @Override - public EventState getNullableResult(ResultSet resultSet, String s) throws SQLException { - return EventState.getEventState(resultSet.getInt(s)); - } - - @Override - public EventState getNullableResult(ResultSet resultSet, int i) throws SQLException { - return EventState.getEventState(resultSet.getInt(i)); - } - - @Override - public EventState getNullableResult(CallableStatement callableStatement, int i) throws SQLException { - return EventState.getEventState(callableStatement.getInt(i)); - } -} diff --git a/src/main/java/sast/evento/common/typehandler/FeedbackScoreTypeHandler.java b/src/main/java/sast/evento/common/typehandler/FeedbackScoreTypeHandler.java index b3b5358..e02f6d2 100644 --- a/src/main/java/sast/evento/common/typehandler/FeedbackScoreTypeHandler.java +++ b/src/main/java/sast/evento/common/typehandler/FeedbackScoreTypeHandler.java @@ -9,10 +9,12 @@ import java.sql.SQLException; /** - * @author Aiden - * @date 2023/12/31 14:50 + * Type convertor for mybatis-plus */ public class FeedbackScoreTypeHandler extends BaseTypeHandler { + + //TODO logic should not be here + @Override public void setNonNullParameter(PreparedStatement preparedStatement, int i, Double aDouble, JdbcType jdbcType) throws SQLException { preparedStatement.setDouble(i, aDouble * 10); diff --git a/src/main/java/sast/evento/common/typehandler/OrganizationTypeHandler.java b/src/main/java/sast/evento/common/typehandler/OrganizationTypeHandler.java index ec72730..c74ec9c 100644 --- a/src/main/java/sast/evento/common/typehandler/OrganizationTypeHandler.java +++ b/src/main/java/sast/evento/common/typehandler/OrganizationTypeHandler.java @@ -9,6 +9,10 @@ import java.sql.ResultSet; import java.sql.SQLException; + +/** + * Type convertor for mybatis-plus + */ public class OrganizationTypeHandler extends BaseTypeHandler { @Override diff --git a/src/main/java/sast/evento/config/ActionRegister.java b/src/main/java/sast/evento/config/ActionRegister.java index 8f40d25..2b36c51 100644 --- a/src/main/java/sast/evento/config/ActionRegister.java +++ b/src/main/java/sast/evento/config/ActionRegister.java @@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import sast.evento.annotation.DefaultActionState; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ErrorEnum; import sast.evento.exception.LocalRunTimeException; import sast.evento.model.Action; @@ -50,7 +50,7 @@ public void run(String... args) { for (Class c : set) { Method[] declaredMethods = c.getDeclaredMethods(); for (Method m : declaredMethods) { - OperateLog ano = AnnotatedElementUtils.findMergedAnnotation(m, OperateLog.class); + Operation ano = AnnotatedElementUtils.findMergedAnnotation(m, Operation.class); RequestMapping r = AnnotatedElementUtils.findMergedAnnotation(m, RequestMapping.class); DefaultActionState d = AnnotatedElementUtils.findMergedAnnotation(m, DefaultActionState.class); if (r == null) { diff --git a/src/main/java/sast/evento/config/InterceptorConfig.java b/src/main/java/sast/evento/config/InterceptorConfig.java index 76c108b..e5a4a7b 100644 --- a/src/main/java/sast/evento/config/InterceptorConfig.java +++ b/src/main/java/sast/evento/config/InterceptorConfig.java @@ -5,7 +5,6 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import sast.evento.interceptor.HttpInterceptor; -import sast.evento.interceptor.LogInterceptor; /** * @author: NicoAsuka @@ -13,8 +12,7 @@ */ @Configuration public class InterceptorConfig implements WebMvcConfigurer { - @Resource - private LogInterceptor logInterceptor; + @Resource private HttpInterceptor httpInterceptor; @@ -22,8 +20,6 @@ public class InterceptorConfig implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(httpInterceptor) .addPathPatterns("/**"); - registry.addInterceptor(logInterceptor) - .addPathPatterns("/**"); } diff --git a/src/main/java/sast/evento/config/QuartzConfig.java b/src/main/java/sast/evento/config/QuartzConfig.java deleted file mode 100644 index 72f9900..0000000 --- a/src/main/java/sast/evento/config/QuartzConfig.java +++ /dev/null @@ -1,60 +0,0 @@ -package sast.evento.config; - -import com.zaxxer.hikari.HikariDataSource; -import org.quartz.impl.StdSchedulerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.autoconfigure.quartz.JobStoreType; -import org.springframework.boot.autoconfigure.quartz.QuartzProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.scheduling.quartz.SchedulerFactoryBean; - -import java.util.Properties; - -@Configuration -public class QuartzConfig { - - @Value("${spring.quartz.datasource.url}") - private String url; - @Value("${spring.quartz.datasource.username}") - private String username; - @Value("${spring.quartz.datasource.password}") - private String password; - @Value("${spring.quartz.datasource.driver-class-name}") - private String driverClassName; - @Value("${spring.quartz.datasource.name}") - private String name; - - @Bean(name = "schedulerFactoryBean") - public SchedulerFactoryBean schedulerFactoryBean() { - SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); - schedulerFactoryBean.setDataSource(quartzDataSource()); - schedulerFactoryBean.setTransactionManager(quartzDataSourceTransactionManager()); - schedulerFactoryBean.setAutoStartup(true); - schedulerFactoryBean.setSchedulerName("quartzScheduler"); - schedulerFactoryBean.setSchedulerFactoryClass(StdSchedulerFactory.class); - schedulerFactoryBean.setOverwriteExistingJobs(true); - schedulerFactoryBean.setExposeSchedulerInRepository(true); - return schedulerFactoryBean; - } - - private HikariDataSource quartzDataSource() { - DataSourceProperties dataSourceProperties = new DataSourceProperties(); - dataSourceProperties.setUrl(url); - dataSourceProperties.setUsername(username); - dataSourceProperties.setPassword(password); - dataSourceProperties.setDriverClassName(driverClassName); - dataSourceProperties.setName(name); - return dataSourceProperties.initializeDataSourceBuilder() - .type(HikariDataSource.class) - .build(); - } - - private DataSourceTransactionManager quartzDataSourceTransactionManager() { - return new DataSourceTransactionManager(quartzDataSource()); - } - -} diff --git a/src/main/java/sast/evento/controller/AdminController.java b/src/main/java/sast/evento/controller/AdminController.java index 6fc4329..8fcfb85 100644 --- a/src/main/java/sast/evento/controller/AdminController.java +++ b/src/main/java/sast/evento/controller/AdminController.java @@ -3,7 +3,7 @@ import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.*; import sast.evento.annotation.DefaultActionState; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.common.enums.ErrorEnum; import sast.evento.entitiy.Department; @@ -19,62 +19,66 @@ @RestController @RequestMapping("/admin") -public class AdminController { +class AdminController { @Resource - private EventTypeService eventTypeService; + EventTypeService eventTypeService; @Resource - private LocationService locationService; + LocationService locationService; @Resource - private DepartmentService departmentService; + DepartmentService departmentService; /** * 添加活动地点 + * * @param location 活动地点 * @return 活动地点id */ - @OperateLog("添加活动地点") - @DefaultActionState(value = ActionState.ADMIN,group = "location") + @Operation("添加活动地点") + @DefaultActionState(value = ActionState.ADMIN, group = "location") @PostMapping("/location") - public String addLocation(@RequestBody Location location) { + String addLocation(@RequestBody Location location) { if (location.getId() != null) throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR, "id should be null."); return locationService.addLocation(location).toString(); } /** * 删除活动地点 + * * @param locationId 活动地点id * @return 是否成功 */ - @OperateLog("删除活动地点") - @DefaultActionState(value = ActionState.ADMIN,group = "location") + @Operation("删除活动地点") + @DefaultActionState(value = ActionState.ADMIN, group = "location") @DeleteMapping("/location") - public String deleteLocation(@RequestParam Integer locationId) { + String deleteLocation(@RequestParam Integer locationId) { return locationService.deleteLocation(locationId).toString(); } /** * 获取活动地点 + * * @return 活动地点列表 */ - @OperateLog("获取活动地点") - @DefaultActionState(value = ActionState.ADMIN,group = "location") + @Operation("获取活动地点") + @DefaultActionState(value = ActionState.ADMIN, group = "location") @GetMapping("/locations") - public List getLocations() { + List getLocations() { /* 以树状结构返回 */ return locationService.getLocations(); } /** * 修改活动地点 + * * @param locationId 活动地点id - * @param location 活动地点 + * @param location 活动地点 * @return 是否成功 */ - @OperateLog("修改活动地点") + @Operation("修改活动地点") @DefaultActionState(ActionState.INVISIBLE) @PutMapping("/location") - public String updateLocation(@RequestParam Integer locationId, - @RequestBody Location location) { + String updateLocation(@RequestParam Integer locationId, + @RequestBody Location location) { if (!location.getId().equals(locationId)) throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR, "invalid id"); /* 比较复杂,谨慎修改 */ return locationService.updateLocation(location).toString(); @@ -88,92 +92,96 @@ public String updateLocation(@RequestParam Integer locationId, * @param locationName 活动名称 * @return ok */ - @OperateLog("修改活动地点名称") - @DefaultActionState(value = ActionState.ADMIN,group = "location") + @Operation("修改活动地点名称") + @DefaultActionState(value = ActionState.ADMIN, group = "location") @PatchMapping("/location") - public String updateLocationName(@RequestParam Integer id, - @RequestParam String locationName) { + String updateLocationName(@RequestParam Integer id, + @RequestParam String locationName) { locationService.updateLocationName(id, locationName); return "ok"; } /** * 添加活动类型 + * * @param type 活动类型 * @return 活动类型id */ - @OperateLog("添加活动类型") - @DefaultActionState(value = ActionState.ADMIN,group = "type") + @Operation("添加活动类型") + @DefaultActionState(value = ActionState.ADMIN, group = "type") @PostMapping("/type") - public String addType(@RequestBody EventType type) { + String addType(@RequestBody EventType type) { if (type.getId() != null) throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR, "id should be null"); return eventTypeService.addEventType(type).toString(); } /** * 删除活动类型 + * * @param typeId 活动类型id * @return 是否成功 */ - @OperateLog("删除活动类型") - @DefaultActionState(value = ActionState.ADMIN,group = "type") + @Operation("删除活动类型") + @DefaultActionState(value = ActionState.ADMIN, group = "type") @DeleteMapping("/type") - public String deleteType(@RequestParam Integer typeId) { + String deleteType(@RequestParam Integer typeId) { return eventTypeService.deleteEventType(typeId).toString(); } /** * 获取活动类型 + * * @return 活动类型列表 */ - @OperateLog("获取活动类型") - @DefaultActionState(value = ActionState.ADMIN,group = "type") + @Operation("获取活动类型") + @DefaultActionState(value = ActionState.ADMIN, group = "type") @GetMapping("/types") - public List getTypes() { + List getTypes() { return eventTypeService.getAllEventType(); } /** * 修改活动类型 + * * @param type 活动类型 * @return 是否成功 */ - @OperateLog("修改活动类型") - @DefaultActionState(value = ActionState.ADMIN,group = "type") + @Operation("修改活动类型") + @DefaultActionState(value = ActionState.ADMIN, group = "type") @PutMapping("/type") - public String updateType(@RequestBody EventType type) { + String updateType(@RequestBody EventType type) { if (type == null || type.getId() == null) throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR); return eventTypeService.editEventType(type).toString(); } - @OperateLog("添加组织部门") - @DefaultActionState(value = ActionState.ADMIN,group = "department") + @Operation("添加组织部门") + @DefaultActionState(value = ActionState.ADMIN, group = "department") @PostMapping("/department") - public Integer addDepartment(@RequestParam String departmentName){ + Integer addDepartment(@RequestParam String departmentName) { return departmentService.addDepartment(departmentName); } - @OperateLog("删除部门") - @DefaultActionState(value = ActionState.ADMIN,group = "department") + @Operation("删除部门") + @DefaultActionState(value = ActionState.ADMIN, group = "department") @DeleteMapping("/department") - public String deleteDepartment(@RequestParam Integer departmentId){ + String deleteDepartment(@RequestParam Integer departmentId) { departmentService.deleteDepartment(departmentId); return "ok"; } - @OperateLog("获取全部组织部门") - @DefaultActionState(value = ActionState.ADMIN,group = "department") + @Operation("获取全部组织部门") + @DefaultActionState(value = ActionState.ADMIN, group = "department") @GetMapping("/departments") - public List getDepartments(){ + List getDepartments() { return departmentService.getDepartments(); } - @OperateLog("修改组织部门名称") - @DefaultActionState(value = ActionState.ADMIN,group = "department") + @Operation("修改组织部门名称") + @DefaultActionState(value = ActionState.ADMIN, group = "department") @PutMapping("/department") - public void putDepartment(@RequestParam Integer departmentId, - @RequestParam String departmentName){ - departmentService.putDepartment(departmentId,departmentName); + void putDepartment(@RequestParam Integer departmentId, + @RequestParam String departmentName) { + departmentService.putDepartment(departmentId, departmentName); } diff --git a/src/main/java/sast/evento/controller/CheckInController.java b/src/main/java/sast/evento/controller/CheckInController.java index 67eb21b..a784f6c 100644 --- a/src/main/java/sast/evento/controller/CheckInController.java +++ b/src/main/java/sast/evento/controller/CheckInController.java @@ -5,10 +5,9 @@ import org.springframework.web.bind.annotation.*; import sast.evento.annotation.DefaultActionState; import sast.evento.annotation.EventId; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.common.enums.ErrorEnum; -import sast.evento.entitiy.User; import sast.evento.exception.LocalRunTimeException; import sast.evento.interceptor.HttpInterceptor; import sast.evento.model.UserModel; @@ -28,7 +27,7 @@ public class CheckInController { @Resource private CodeService codeService; /* 由后端生成部分信息置于二维码,userId需要前端填充 */ - @OperateLog("签到") + @Operation("签到") @DefaultActionState(ActionState.LOGIN)/* 这里为public,eventId注解没什么用 */ @GetMapping("/checkIn") @ResponseBody @@ -42,7 +41,7 @@ public String CheckIn(@RequestParam String code) { return participateService.participate(user.getId(),eventId,true); } - @OperateLog("生成活动签到二维码的验证码") + @Operation("生成活动签到二维码的验证码") @DefaultActionState(ActionState.ADMIN)/* 这里为admin,eventId注解没什么用 */ @GetMapping("/authcode") @ResponseBody diff --git a/src/main/java/sast/evento/controller/EventController.java b/src/main/java/sast/evento/controller/EventController.java index 3e1be90..d269d56 100644 --- a/src/main/java/sast/evento/controller/EventController.java +++ b/src/main/java/sast/evento/controller/EventController.java @@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.*; import sast.evento.annotation.DefaultActionState; import sast.evento.annotation.EventId; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.common.enums.ErrorEnum; import sast.evento.entitiy.Department; @@ -29,7 +29,7 @@ public class EventController { @Resource private DepartmentService departmentService; - @OperateLog("查看正在进行活动列表") + @Operation("查看正在进行活动列表") @DefaultActionState(ActionState.PUBLIC) @GetMapping("/conducting") public List getConducting() { @@ -37,14 +37,14 @@ public List getConducting() { } - @OperateLog("查看最新活动列表") + @Operation("查看最新活动列表") @DefaultActionState(ActionState.PUBLIC) @GetMapping("/newest") public List getNewest() { return eventService.getNewest(); } - @OperateLog("查看用户历史活动列表") + @Operation("查看用户历史活动列表") @DefaultActionState(ActionState.LOGIN) @GetMapping("/history") public List getHistory() { @@ -58,7 +58,7 @@ public List getHistory() { * @param eventId 活动id * @return 是否成功 */ - @OperateLog("删除活动") + @Operation("删除活动") @DefaultActionState(value = ActionState.MANAGER, group = "event") @DeleteMapping("/info") public String deleteEvent(@RequestParam @EventId Integer eventId) { @@ -66,7 +66,7 @@ public String deleteEvent(@RequestParam @EventId Integer eventId) { } - @OperateLog("获取活动详情") + @Operation("获取活动详情") @DefaultActionState(ActionState.PUBLIC)/* 这里为public,eventId注解没什么用 */ @GetMapping("/info") public EventModel getEvent(@RequestParam @EventId Integer eventId) { @@ -80,7 +80,7 @@ public EventModel getEvent(@RequestParam @EventId Integer eventId) { * @param event 活动信息 * @return 是否成功 */ - @OperateLog("取消活动") + @Operation("取消活动") @DefaultActionState(value = ActionState.MANAGER, group = "event") @PatchMapping("/info") public String cancelEvent(@RequestParam @EventId Integer eventId, @@ -95,7 +95,7 @@ public String cancelEvent(@RequestParam @EventId Integer eventId, * @param eventModel 活动信息 * @return 活动id */ - @OperateLog("发起活动") + @Operation("发起活动") @DefaultActionState(value = ActionState.ADMIN, group = "event") @PostMapping("/info") public String addEvent(@RequestBody EventModel eventModel) { @@ -111,7 +111,7 @@ public String addEvent(@RequestBody EventModel eventModel) { * @param eventModel 活动信息 * @return 是否成功 */ - @OperateLog("修改活动") + @Operation("修改活动") @DefaultActionState(value = ActionState.MANAGER, group = "event") @PutMapping("/info") public String putEvent(@RequestParam @EventId Integer eventId, @@ -120,7 +120,7 @@ public String putEvent(@RequestParam @EventId Integer eventId, return eventService.updateEvent(eventModel).toString(); } - @OperateLog("获取活动列表") + @Operation("获取活动列表") @DefaultActionState(ActionState.PUBLIC) @GetMapping("/list") public PageModel getEvents(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @@ -128,7 +128,7 @@ public PageModel getEvents(@RequestParam(value = "page", required = return eventService.getEvents(page, size); } - @OperateLog("筛选获取课表") + @Operation("筛选获取课表") @DefaultActionState(ActionState.PUBLIC) @PostMapping("/list") public List postForEvents(@RequestParam(required = false) List typeId, @@ -137,7 +137,7 @@ public List postForEvents(@RequestParam(required = false) List getDepartmentsWithFilter() { diff --git a/src/main/java/sast/evento/controller/FeedbackController.java b/src/main/java/sast/evento/controller/FeedbackController.java index 9028873..270fc95 100644 --- a/src/main/java/sast/evento/controller/FeedbackController.java +++ b/src/main/java/sast/evento/controller/FeedbackController.java @@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.*; import sast.evento.annotation.DefaultActionState; import sast.evento.annotation.EventId; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.interceptor.HttpInterceptor; import sast.evento.model.*; @@ -23,7 +23,7 @@ public class FeedbackController { * @return FeedbacksDTO * @author Aiden */ - @OperateLog("获取某活动反馈详情") + @Operation("获取某活动反馈详情") @DefaultActionState(value = ActionState.ADMIN, group = "feedback") @GetMapping("/event") public FeedbacksDTO getFeedback(@RequestParam @EventId Integer eventId) { @@ -36,7 +36,7 @@ public FeedbacksDTO getFeedback(@RequestParam @EventId Integer eventId) { * @return List> * @author Aiden */ - @OperateLog("获取活动及其反馈数量列表") + @Operation("获取活动及其反馈数量列表") @DefaultActionState(value = ActionState.ADMIN, group = "feedback") @GetMapping("/num") public PageModel getFeedbackEvents( @@ -45,7 +45,7 @@ public PageModel getFeedbackEvents( return feedBackService.getFeedbackEvents(page, size); } - @OperateLog("用户添加反馈") + @Operation("用户添加反馈") @DefaultActionState(ActionState.LOGIN) @PostMapping("/info") public String addFeedback(@RequestParam(required = false) String content, @@ -55,7 +55,7 @@ public String addFeedback(@RequestParam(required = false) String content, return feedBackService.addFeedback(user.getId(), content, score, eventId); } - @OperateLog("用户自己的获取反馈列表") + @Operation("用户自己的获取反馈列表") @DefaultActionState(ActionState.LOGIN) @GetMapping("/user/list") public List getListByUserId() { @@ -64,7 +64,7 @@ public List getListByUserId() { } // 如果返回的是 null,那么表示用户没有反馈这个活动。 - @OperateLog("用户获取自己写的某活动的反馈详情(可判断是否反馈)") + @Operation("用户获取自己写的某活动的反馈详情(可判断是否反馈)") @DefaultActionState(ActionState.LOGIN) @GetMapping("/user/info") public FeedbackModel getUserFeedback(@RequestParam Integer eventId) { @@ -74,7 +74,7 @@ public FeedbackModel getUserFeedback(@RequestParam Integer eventId) { // 如果传进来的 content 为空,则清空数据库的 content 字段。(考虑到有人可能想清空反馈内容,所以这样设计) // score 为五分制,一位小数。如果传进来的为空,则不做修改。 - @OperateLog("用户修改反馈") + @Operation("用户修改反馈") @DefaultActionState(ActionState.LOGIN) @PatchMapping("/info") public String patchFeedback(@RequestParam(required = false) String content, @@ -84,7 +84,7 @@ public String patchFeedback(@RequestParam(required = false) String content, return feedBackService.patchFeedback(user.getId(), feedbackId, content, score); } - @OperateLog("用户删除反馈") + @Operation("用户删除反馈") @DefaultActionState(ActionState.LOGIN) @DeleteMapping("/info") public String deleteFeedback(@RequestParam Integer feedbackId) { @@ -92,7 +92,7 @@ public String deleteFeedback(@RequestParam Integer feedbackId) { return feedBackService.deleteFeedback(user.getId(), feedbackId); } - @OperateLog("获取活动反馈列表(该活动的所有人的反馈)") + @Operation("获取活动反馈列表(该活动的所有人的反馈)") @DefaultActionState(ActionState.LOGIN) @GetMapping("/list") public List getListByEventId(@RequestParam Integer eventId) { diff --git a/src/main/java/sast/evento/controller/LoginController.java b/src/main/java/sast/evento/controller/LoginController.java index a9af5a2..51549a9 100644 --- a/src/main/java/sast/evento/controller/LoginController.java +++ b/src/main/java/sast/evento/controller/LoginController.java @@ -4,7 +4,7 @@ import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.*; import sast.evento.annotation.DefaultActionState; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.common.enums.ErrorEnum; import sast.evento.exception.LocalRunTimeException; @@ -32,7 +32,7 @@ public class LoginController { * @param type web端或客户端 * @return Map */ - @OperateLog("link登录") + @Operation("link登录") @PostMapping("/login/link") @DefaultActionState(ActionState.PUBLIC) public Map linkLogin(@RequestParam String code, @@ -52,7 +52,7 @@ public Map linkLogin(@RequestParam String code, * 获取授权给新设备登录的ticket * @return Map */ - @OperateLog("获取ticket") + @Operation("获取ticket") @PostMapping("/login/ticket/get") @DefaultActionState(ActionState.PUBLIC) public Map getTicket(@RequestParam(required = false) String ticket){ @@ -64,7 +64,7 @@ public Map getTicket(@RequestParam(required = false) String tick * @param ticket 登录令牌 * @return ok */ - @OperateLog("检查ticket并登录") + @Operation("检查ticket并登录") @PostMapping("/login/ticket") @DefaultActionState(ActionState.LOGIN) public String loginByTicket(@RequestParam String ticket){ @@ -78,7 +78,7 @@ public String loginByTicket(@RequestParam String ticket){ * @param password 密码 * @return Map */ - @OperateLog("绑定密码") + @Operation("绑定密码") @PostMapping("/bind/password") @DefaultActionState(ActionState.LOGIN) public String bindPassword(@RequestParam String password) { @@ -93,7 +93,7 @@ public String bindPassword(@RequestParam String password) { * @param password 密码 * @return Map */ - @OperateLog("密码登录") + @Operation("密码登录") @PostMapping("/login/password") @DefaultActionState(ActionState.PUBLIC) public Map loginByPassword(@RequestParam String studentId, @RequestParam String password) { @@ -104,7 +104,7 @@ public Map loginByPassword(@RequestParam String studentId, @Requ * 登出 * @return ok */ - @OperateLog("登出") + @Operation("登出") @GetMapping("/logout") @DefaultActionState(ActionState.LOGIN) public String logout() { diff --git a/src/main/java/sast/evento/controller/PermissionController.java b/src/main/java/sast/evento/controller/PermissionController.java index 00deb19..5f20df0 100644 --- a/src/main/java/sast/evento/controller/PermissionController.java +++ b/src/main/java/sast/evento/controller/PermissionController.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.*; import sast.evento.annotation.DefaultActionState; import sast.evento.annotation.EventId; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.common.enums.ErrorEnum; import sast.evento.entitiy.User; @@ -29,7 +29,7 @@ public class PermissionController { @Resource private UserService userService; - @OperateLog("获取所有后台管理权限") + @Operation("获取所有后台管理权限") @DefaultActionState(ActionState.INVISIBLE) @GetMapping("/admin/all") public List getAllAdminPermissions() { @@ -37,28 +37,28 @@ public List getAllAdminPermissions() { } - @OperateLog("获取所有后台管理权限") + @Operation("获取所有后台管理权限") @DefaultActionState(value = ActionState.ADMIN, group = "permission") @GetMapping("/admin/treeData") public List getAllAdminPermissionsAsTree() { return permissionService.getAllAdminPermissionsAsTree(); } - @OperateLog("获取所有活动管理权限") + @Operation("获取所有活动管理权限") @DefaultActionState(ActionState.INVISIBLE) @GetMapping("/manager/all") public List getAllManagerPermissions(@RequestParam @EventId Integer eventId) { return permissionService.getAllManagerPermissions(); } - @OperateLog("获取所有活动管理权限") + @Operation("获取所有活动管理权限") @DefaultActionState(value = ActionState.MANAGER, group = "permission") @GetMapping("/manager/treeData") public List getAllManagerPermissionsAsTree(@RequestParam @EventId Integer eventId) { return permissionService.getAllManagerPermissionsAsTree(); } - @OperateLog("删除后台管理者") + @Operation("删除后台管理者") @DefaultActionState(value = ActionState.ADMIN, group = "permission") @DeleteMapping("/admin") public String deleteAdmin(@RequestParam(required = false) String userId, @@ -68,7 +68,7 @@ public String deleteAdmin(@RequestParam(required = false) String userId, return "ok"; } - @OperateLog("获取后台管理者列表") + @Operation("获取后台管理者列表") @DefaultActionState(value = ActionState.ADMIN, group = "permission") @GetMapping("/admins") public Map getAdmins(@RequestParam(required = false,defaultValue = "1")Integer current, @@ -77,7 +77,7 @@ public Map getAdmins(@RequestParam(required = false,defaultValue return Map.of("users", userPage.getRecords(), "total", userPage.getTotal()); } - @OperateLog("添加后台管理者") + @Operation("添加后台管理者") @DefaultActionState(value = ActionState.ADMIN, group = "permission") @PostMapping("/admin") public String addAdmin(@RequestParam List methodNames, @@ -88,7 +88,7 @@ public String addAdmin(@RequestParam List methodNames, return "ok"; } - @OperateLog("编辑后台管理者权限") + @Operation("编辑后台管理者权限") @DefaultActionState(value = ActionState.ADMIN, group = "permission") @PutMapping("/admin") public String putAdmin(@RequestParam List methodNames, @@ -99,7 +99,7 @@ public String putAdmin(@RequestParam List methodNames, return "ok"; } - @OperateLog("获取用户具有后台管理权限") + @Operation("获取用户具有后台管理权限") @DefaultActionState(ActionState.INVISIBLE) @GetMapping("/admin/user") public List getUserAdminPermissions(@RequestParam(required = false) String userId, @@ -108,7 +108,7 @@ public List getUserAdminPermissions(@RequestParam(required = false) Stri return permissionService.getUserAdminPermissions(userId); } - @OperateLog("获取用户具有的后台管理权限") + @Operation("获取用户具有的后台管理权限") @DefaultActionState(value = ActionState.ADMIN, group = "permission") @GetMapping("/admin/user/list") public List getUserAdminPermissAsList(@RequestParam(required = false) String userId, @@ -117,7 +117,7 @@ public List getUserAdminPermissAsList(@RequestParam(required = false) St return permissionService.getUserAdminPermissAsList(userId); } - @OperateLog("获取用户对某活动管理权限") + @Operation("获取用户对某活动管理权限") @DefaultActionState(ActionState.INVISIBLE) @GetMapping("/event/manager/user") public List getUserManagerPermissions(@RequestParam @EventId Integer eventId, @@ -128,7 +128,7 @@ public List getUserManagerPermissions(@RequestParam @EventId Integer eve return permissionService.getUserManagerPermissions(eventId, userId); } - @OperateLog("获取用户对某活动管理的权限") + @Operation("获取用户对某活动管理的权限") @DefaultActionState(value = ActionState.MANAGER, group = "permission") @GetMapping("/event/manager/user/list") public List getUserManagerPermissAsList(@RequestParam @EventId Integer eventId, @@ -139,7 +139,7 @@ public List getUserManagerPermissAsList(@RequestParam @EventId Integer e return permissionService.getUserManagerPermissAsList(eventId, userId); } - @OperateLog("删除活动管理者") + @Operation("删除活动管理者") @DefaultActionState(value = ActionState.MANAGER, group = "permission") @DeleteMapping(value = "/event/manager") public String deleteManager(@RequestParam @EventId Integer eventId, @@ -151,7 +151,7 @@ public String deleteManager(@RequestParam @EventId Integer eventId, return "ok"; } - @OperateLog("编辑活动管理者权限") + @Operation("编辑活动管理者权限") @DefaultActionState(value = ActionState.MANAGER, group = "permission") @PutMapping(value = "/event/manager") public String putManager(@RequestParam List methodNames, @@ -164,7 +164,7 @@ public String putManager(@RequestParam List methodNames, return "ok"; } - @OperateLog("添加活动管理者") + @Operation("添加活动管理者") @DefaultActionState(value = ActionState.MANAGER, group = "permission") @PostMapping(value = "/event/manager") public String addManager(@RequestParam List methodNames, @@ -177,7 +177,7 @@ public String addManager(@RequestParam List methodNames, return "ok"; } - @OperateLog("获取活动管理者列表") + @Operation("获取活动管理者列表") @DefaultActionState(ActionState.LOGIN) @GetMapping(value = "/event/managers") public Map getManagers(@RequestParam @EventId Integer eventId, @@ -188,7 +188,7 @@ public Map getManagers(@RequestParam @EventId Integer eventId, return Map.of("users", userPage.getRecords(), "total", userPage.getTotal()); } - @OperateLog("获取用户具有哪些活动的管理权限") + @Operation("获取用户具有哪些活动的管理权限") @DefaultActionState(ActionState.LOGIN) @GetMapping(value = "/manager/events") public List getManageEvent(@RequestParam(required = false) String userId, @@ -197,7 +197,7 @@ public List getManageEvent(@RequestParam(required = false) String userI return permissionService.getManageEvent(userId); } - @OperateLog("获取用户自身后台管理权限用于条件渲染") + @Operation("获取用户自身后台管理权限用于条件渲染") @DefaultActionState(ActionState.LOGIN) @GetMapping(value = "/admin/self") public List getSelfAdminPermission() { @@ -205,7 +205,7 @@ public List getSelfAdminPermission() { return permissionService.getUserAdminPermissAsList(user.getId()); } - @OperateLog("获取用户自身活动管理权限用于条件渲染") + @Operation("获取用户自身活动管理权限用于条件渲染") @DefaultActionState(ActionState.LOGIN) @GetMapping(value = "/event/manager/self") public List getSelfManagerPermission(@RequestParam @EventId Integer eventId) { @@ -214,7 +214,7 @@ public List getSelfManagerPermission(@RequestParam @EventId Integer even return permissionService.getUserManagerPermissAsList(eventId, user.getId()); } - @OperateLog("分页查询所有用户") + @Operation("分页查询所有用户") @DefaultActionState(ActionState.ADMIN) @GetMapping(value = "/users") public Map getUsers(@RequestParam(required = false,defaultValue = "1")Integer current, @@ -223,7 +223,7 @@ public Map getUsers(@RequestParam(required = false,defaultValue return Map.of("users", userPage.getRecords(), "total", userPage.getTotal()); } - @OperateLog("模糊查询用户") + @Operation("模糊查询用户") @DefaultActionState(ActionState.ADMIN) @GetMapping(value = "/users/search") public Map searchUsers(@RequestParam String keyword, diff --git a/src/main/java/sast/evento/controller/PictureController.java b/src/main/java/sast/evento/controller/PictureController.java index 6447799..26fa3e6 100644 --- a/src/main/java/sast/evento/controller/PictureController.java +++ b/src/main/java/sast/evento/controller/PictureController.java @@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import sast.evento.annotation.DefaultActionState; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.common.enums.ErrorEnum; import sast.evento.exception.LocalRunTimeException; @@ -26,7 +26,7 @@ public class PictureController { @Resource private ImageService imageService; - @OperateLog("获取图片url列表") + @Operation("获取图片url列表") @DefaultActionState(value = ActionState.ADMIN, group = "picture") @GetMapping("/list") public Map getUrls(@RequestParam(defaultValue = "") String dir, @@ -35,7 +35,7 @@ public Map getUrls(@RequestParam(defaultValue = "") String dir, return imageService.getPictures(num, size, dir); } - @OperateLog("添加图片") + @Operation("添加图片") @DefaultActionState(value = ActionState.ADMIN, group = "picture") @PostMapping("/info") public String addPicture(@RequestParam(defaultValue = "") String dir, @@ -47,7 +47,7 @@ public String addPicture(@RequestParam(defaultValue = "") String dir, return imageService.upload(picture, user, dir); } - @OperateLog("删除图片") + @Operation("删除图片") @DefaultActionState(value = ActionState.ADMIN, group = "picture") @DeleteMapping("/info") public String deletePicture(@RequestParam(defaultValue = "") String dir, @@ -59,7 +59,7 @@ public String deletePicture(@RequestParam(defaultValue = "") String dir, return "ok"; } - @OperateLog("获取图片目录") + @Operation("获取图片目录") @DefaultActionState(value = ActionState.ADMIN, group = "picture") @GetMapping("/dir") public List getDir() { diff --git a/src/main/java/sast/evento/controller/SlideController.java b/src/main/java/sast/evento/controller/SlideController.java index aec6e4f..154cc7b 100644 --- a/src/main/java/sast/evento/controller/SlideController.java +++ b/src/main/java/sast/evento/controller/SlideController.java @@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.*; import sast.evento.annotation.DefaultActionState; import sast.evento.annotation.EventId; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.common.enums.ErrorEnum; import sast.evento.entitiy.Slide; @@ -20,7 +20,7 @@ public class SlideController { @Resource private SlideService slideService; - @OperateLog("获取活动幻灯片列表") + @Operation("获取活动幻灯片列表") @DefaultActionState(ActionState.PUBLIC) @GetMapping("/event/list") public List getEventSlides(@RequestParam @EventId Integer eventId) { @@ -29,7 +29,7 @@ public List getEventSlides(@RequestParam @EventId Integer eventId) { return slideService.getEventSlides(eventId); } - @OperateLog("获取首页幻灯片列表") + @Operation("获取首页幻灯片列表") @DefaultActionState(ActionState.PUBLIC) @GetMapping("/home/list") public SlidePageModel getHomeSlides(@RequestParam(defaultValue = "1", required = false) Integer current, @@ -38,7 +38,7 @@ public SlidePageModel getHomeSlides(@RequestParam(defaultValue = "1", required = return slideService.getHomeSlides(current, size); } - @OperateLog("添加活动幻灯片") + @Operation("添加活动幻灯片") @DefaultActionState(value = ActionState.MANAGER,group = "slide") @PostMapping("/event/info") public Integer addEventSlide(@RequestParam @EventId Integer eventId, @@ -49,7 +49,7 @@ public Integer addEventSlide(@RequestParam @EventId Integer eventId, return slideService.addEventSlide(eventId, url, link, title); } - @OperateLog("删除活动幻灯片") + @Operation("删除活动幻灯片") @DefaultActionState(value = ActionState.MANAGER,group = "slide") @DeleteMapping("/event/info") public String deleteEventSlide(@RequestParam @EventId Integer eventId, @@ -59,7 +59,7 @@ public String deleteEventSlide(@RequestParam @EventId Integer eventId, return "ok"; } - @OperateLog("编辑活动幻灯片") + @Operation("编辑活动幻灯片") @DefaultActionState(value = ActionState.MANAGER,group = "slide") @PatchMapping("/event/info") public String patchEventSlide(@RequestParam @EventId Integer eventId, @@ -72,7 +72,7 @@ public String patchEventSlide(@RequestParam @EventId Integer eventId, return "ok"; } - @OperateLog("添加首页幻灯片") + @Operation("添加首页幻灯片") @DefaultActionState(value = ActionState.ADMIN,group = "slide") @PostMapping("/home/info") public Integer addHomeSlide(@RequestParam String url, @@ -81,7 +81,7 @@ public Integer addHomeSlide(@RequestParam String url, return slideService.addHomeSlide(url, link, title); } - @OperateLog("删除首页幻灯片") + @Operation("删除首页幻灯片") @DefaultActionState(value = ActionState.ADMIN,group = "slide") @DeleteMapping("/home/info") public String deleteHomeSlide(@RequestParam Integer slideId) { @@ -89,7 +89,7 @@ public String deleteHomeSlide(@RequestParam Integer slideId) { return "ok"; } - @OperateLog("编辑首页幻灯片") + @Operation("编辑首页幻灯片") @DefaultActionState(value = ActionState.ADMIN,group = "slide") @PatchMapping("/home/info") public String patchHomeSlide(@RequestParam Integer slideId, diff --git a/src/main/java/sast/evento/controller/TestController.java b/src/main/java/sast/evento/controller/TestController.java index 67737ba..c3aed50 100644 --- a/src/main/java/sast/evento/controller/TestController.java +++ b/src/main/java/sast/evento/controller/TestController.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import sast.evento.annotation.DefaultActionState; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.common.enums.ErrorEnum; import sast.evento.entitiy.Event; @@ -52,7 +52,7 @@ public class TestController { private EventMapper eventMapper; - @OperateLog("link登录") + @Operation("link登录") @DefaultActionState(ActionState.PUBLIC) @PostMapping("/linklogin") public String linkLogin(@RequestParam Integer type, @@ -75,7 +75,7 @@ public String linkLogin(@RequestParam Integer type, } } - @OperateLog("addPermissionForTest") + @Operation("addPermissionForTest") @DefaultActionState(ActionState.LOGIN) @PostMapping("/permission") @Transactional diff --git a/src/main/java/sast/evento/controller/UserController.java b/src/main/java/sast/evento/controller/UserController.java index c905c6f..288a835 100644 --- a/src/main/java/sast/evento/controller/UserController.java +++ b/src/main/java/sast/evento/controller/UserController.java @@ -3,7 +3,7 @@ import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.*; import sast.evento.annotation.DefaultActionState; -import sast.evento.annotation.OperateLog; +import sast.evento.annotation.Operation; import sast.evento.common.enums.ActionState; import sast.evento.entitiy.Department; import sast.evento.entitiy.Participate; @@ -30,7 +30,7 @@ public class UserController { @Resource private DepartmentService departmentService; - @OperateLog("获取个人信息") + @Operation("获取个人信息") @DefaultActionState(ActionState.LOGIN) @GetMapping("/info") public User getUser() { @@ -38,7 +38,7 @@ public User getUser() { return userService.getUserById(user.getId()); } - @OperateLog("更改个人信息") + @Operation("更改个人信息") @DefaultActionState(ActionState.LOGIN) @PutMapping("/info") public String putUser(@RequestBody User user) { @@ -48,7 +48,7 @@ public String putUser(@RequestBody User user) { return "ok"; } - @OperateLog("订阅活动或取消订阅") + @Operation("订阅活动或取消订阅") @DefaultActionState(ActionState.LOGIN) @GetMapping("/subscribe") public String subscribe(@RequestParam Integer eventId, @@ -58,7 +58,7 @@ public String subscribe(@RequestParam Integer eventId, } // 本周和未来的活动 - @OperateLog("获取已订阅的活动列表") + @Operation("获取已订阅的活动列表") @DefaultActionState(ActionState.LOGIN) @GetMapping("/subscribed") public List getSubscribed() { @@ -66,7 +66,7 @@ public List getSubscribed() { return eventService.getSubscribed(user.getId()); } - @OperateLog("报名活动") + @Operation("报名活动") @DefaultActionState(ActionState.LOGIN) @GetMapping("/register") public String register(@RequestParam Integer eventId, @@ -76,7 +76,7 @@ public String register(@RequestParam Integer eventId, } // 本周和未来的活动 - @OperateLog("获取已报名的活动列表") + @Operation("获取已报名的活动列表") @DefaultActionState(ActionState.LOGIN) @GetMapping("/registered") public List getRegistered() { @@ -86,7 +86,7 @@ public List getRegistered() { // 查询用户自己是否报名、订阅、参加(即签到)活动 // 若无结果,则表示用户没有报名、没有订阅、更没有签到。 - @OperateLog("获取个人的活动的状态") + @Operation("获取个人的活动的状态") @DefaultActionState(ActionState.LOGIN) @GetMapping("/participate") public Participate getParticipation(@RequestParam Integer eventId) { @@ -94,7 +94,7 @@ public Participate getParticipation(@RequestParam Integer eventId) { return participateService.getParticipation(user.getId(), eventId); } - @OperateLog("订阅组别或取消订阅") + @Operation("订阅组别或取消订阅") @DefaultActionState(ActionState.LOGIN) @GetMapping("/subscribe/department") public String subscribeDepartment(@RequestParam Integer departmentId, @@ -104,7 +104,7 @@ public String subscribeDepartment(@RequestParam Integer departmentId, return "ok"; } - @OperateLog("获取个人订阅的组别") + @Operation("获取个人订阅的组别") @DefaultActionState(ActionState.LOGIN) @GetMapping("/subscribe/departments") public List getSubscribeDepartment() { diff --git a/src/main/java/sast/evento/entitiy/Event.java b/src/main/java/sast/evento/entitiy/Event.java index 7b065e8..b944257 100644 --- a/src/main/java/sast/evento/entitiy/Event.java +++ b/src/main/java/sast/evento/entitiy/Event.java @@ -9,7 +9,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import sast.evento.common.enums.EventState; -import sast.evento.common.typehandler.EventStateTypeHandler; import sast.evento.model.EventModel; import java.util.Date; @@ -53,7 +52,6 @@ public class Event { private String tag; - @TableField(typeHandler = EventStateTypeHandler.class) private EventState state; public Event(EventModel eventModel) { diff --git a/src/main/java/sast/evento/exception/LocalExceptionHandler.java b/src/main/java/sast/evento/exception/LocalExceptionHandler.java index 4680032..c2eebe1 100644 --- a/src/main/java/sast/evento/exception/LocalExceptionHandler.java +++ b/src/main/java/sast/evento/exception/LocalExceptionHandler.java @@ -20,6 +20,7 @@ @RestControllerAdvice public class LocalExceptionHandler { + //TODO enhance here @ExceptionHandler(LocalRunTimeException.class) public GlobalResponse localException(LocalRunTimeException e) { if (e == null) { @@ -35,6 +36,7 @@ public GlobalResponse localException(LocalRunTimeException e) { return GlobalResponse.failure(errorEnum); } + //TODO inner exception should be handled @ExceptionHandler(MethodArgumentNotValidException.class) public GlobalResponse handlerValidationException(MethodArgumentNotValidException e) { String messages = e.getBindingResult().getAllErrors().stream() @@ -43,18 +45,21 @@ public GlobalResponse handlerValidationException(MethodArgumentNotValidEx return GlobalResponse.failure(messages); } + //TODO inner exception should be handled @ExceptionHandler(MissingServletRequestParameterException.class) public GlobalResponse handlerMissingServletRequestParameterException(MissingServletRequestParameterException e) { ErrorEnum error = ErrorEnum.PARAM_ERROR; return GlobalResponse.failure(error,error.getErrMsg() + ", "+e.getParameterName()+" should not be null"); } + //TODO inner exception should be handled @ExceptionHandler(SQLIntegrityConstraintViolationException.class) public GlobalResponse handlerSQLIntegrityConstraintViolationException(SQLIntegrityConstraintViolationException e) { ErrorEnum error = ErrorEnum.PARAM_ERROR; return GlobalResponse.failure(error,error.getErrMsg() + ", id out of range or key information repeated"); } + //TODO inner exception should be handled @ExceptionHandler(HttpServerErrorException.class) public GlobalResponse handlerHttpServerErrorException(HttpServerErrorException e) { return GlobalResponse.failure(e); diff --git a/src/main/java/sast/evento/interceptor/HttpInterceptor.java b/src/main/java/sast/evento/interceptor/HttpInterceptor.java index c42978d..6951762 100644 --- a/src/main/java/sast/evento/interceptor/HttpInterceptor.java +++ b/src/main/java/sast/evento/interceptor/HttpInterceptor.java @@ -4,6 +4,7 @@ import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.springframework.context.annotation.Lazy; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.http.HttpStatus; import org.springframework.lang.NonNull; @@ -40,8 +41,10 @@ @Component public class HttpInterceptor implements HandlerInterceptor { public static ThreadLocal userHolder = new ThreadLocal<>(); + @Lazy @Resource private LoginService loginService; + @Lazy @Resource private PermissionService permissionService; @Resource diff --git a/src/main/java/sast/evento/interceptor/LogInterceptor.java b/src/main/java/sast/evento/interceptor/LogInterceptor.java deleted file mode 100644 index a044dcd..0000000 --- a/src/main/java/sast/evento/interceptor/LogInterceptor.java +++ /dev/null @@ -1,51 +0,0 @@ -package sast.evento.interceptor; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.slf4j.MDC; -import org.springframework.lang.Nullable; -import org.springframework.stereotype.Component; -import org.springframework.web.method.HandlerMethod; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; -import sast.evento.annotation.OperateLog; -import sast.evento.config.ActionRegister; -import sast.evento.model.TraceLog; - -import java.lang.reflect.Method; -import java.util.UUID; - -/** - * @Title LogInterceptor - * @Description 为该请求线程配置日志 - * @Author feelMoose - * @Date 2023/7/14 16:20 - */ - -@Component -public class LogInterceptor implements HandlerInterceptor { - public static ThreadLocal logHolder = new ThreadLocal<>(); - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - if (handler instanceof ResourceHttpRequestHandler) { - return true; - } - Method method = ((HandlerMethod) handler).getMethod(); - MDC.put("TRACE_ID", UUID.randomUUID().toString()); - TraceLog preTraceLog = new TraceLog(); - preTraceLog.setUri(request.getRequestURI()); - preTraceLog.setMethod(request.getMethod()); - preTraceLog.setDescription(ActionRegister.actionName2action.get(method.getName()).getDescription()); - preTraceLog.setStartTime(System.currentTimeMillis()); - logHolder.set(preTraceLog); - return true; - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, - Object handler, @Nullable Exception ex) { - logHolder.remove(); - MDC.clear(); - } -} diff --git a/src/main/java/sast/evento/job/EventStateUpdateJob.java b/src/main/java/sast/evento/job/EventStateUpdateJob.java deleted file mode 100644 index 500288d..0000000 --- a/src/main/java/sast/evento/job/EventStateUpdateJob.java +++ /dev/null @@ -1,34 +0,0 @@ -package sast.evento.job; - -import lombok.extern.slf4j.Slf4j; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import sast.evento.common.enums.EventState; -import sast.evento.entitiy.Event; -import sast.evento.service.EventService; -import sast.evento.service.impl.EventServiceImpl; -import sast.evento.utils.SpringContextUtil; - -/** - * @Author: Love98 - * @Date: 8/26/2023 8:57 PM - */ -@Slf4j -public class EventStateUpdateJob implements Job { - @Override - public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { - log.info("Event state update task start"); - - Integer eventId = jobExecutionContext.getMergedJobDataMap().getInt("eventId"); - int state = jobExecutionContext.getMergedJobDataMap().getInt("state"); - - Event event = new Event(); - event.setId(eventId); - event.setState(EventState.getEventState(state)); - EventService eventService = SpringContextUtil.getBean(EventServiceImpl.class); - eventService.updateEvent(event); - - log.info("Event state update task end"); - } -} diff --git a/src/main/java/sast/evento/job/WxSubscribeJob.java b/src/main/java/sast/evento/job/WxSubscribeJob.java deleted file mode 100644 index 37bb9d1..0000000 --- a/src/main/java/sast/evento/job/WxSubscribeJob.java +++ /dev/null @@ -1,70 +0,0 @@ -package sast.evento.job; - - -import lombok.extern.slf4j.Slf4j; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import sast.evento.entitiy.Department; -import sast.evento.entitiy.UserDepartmentSubscribe; -import sast.evento.mapper.ParticipateMapper; -import sast.evento.model.wxServiceDTO.AccessTokenResponse; -import sast.evento.service.DepartmentService; -import sast.evento.service.EventService; -import sast.evento.service.WxService; -import sast.evento.service.impl.SubscribeMessageServiceImpl; -import sast.evento.service.impl.WxServiceImpl; -import sast.evento.utils.SpringContextUtil; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - - -/** - * @projectName: Test - * @author: feelMoose - * @date: 2023/7/26 22:11 - */ - -// 定时任务 -@Slf4j -public class WxSubscribeJob implements Job { - - @Override - public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { - if (SubscribeMessageServiceImpl.getIsOpen()) { - log.info("Wx subscribe task start"); - - Integer eventId = jobExecutionContext.getMergedJobDataMap().getInt("eventId"); - DepartmentService departmentService = SpringContextUtil.getBean(DepartmentService.class); - ParticipateMapper participateMapperBean = SpringContextUtil.getBean(ParticipateMapper.class); - EventService eventService = SpringContextUtil.getBean(EventService.class); - WxService wxService = SpringContextUtil.getBean(WxServiceImpl.class); - - Set openIds = new HashSet<>(participateMapperBean.selectSubscribeOpenIds(eventId)); - List departmentIds = eventService.getEvent(eventId).getDepartments().stream() - .map(Department::getId).toList(); - Set subscribeDepartmentOpenIds = departmentService.getSubscribeDepartmentUser(departmentIds) - .stream().map(UserDepartmentSubscribe::getOpenId).collect(Collectors.toSet()); - openIds.addAll(subscribeDepartmentOpenIds); - - /* 任意时刻发起调用获取到的 access_token 有效期至少为 5 分钟 */ - AccessTokenResponse accessTokenResponse = wxService.getStableToken(); - long date = System.currentTimeMillis() + accessTokenResponse.getExpires_in(); - for (String openId : openIds) { - if (System.currentTimeMillis() > date) { - accessTokenResponse = wxService.getStableToken(); - date = System.currentTimeMillis() + accessTokenResponse.getExpires_in(); - } - wxService.seedSubscribeMessage(eventId, accessTokenResponse.getAccess_token(), openId); - } - - log.info("Wx subscribe task end"); - - - } - } -} - diff --git a/src/main/java/sast/evento/model/wxServiceDTO/AccessTokenRequest.java b/src/main/java/sast/evento/model/wxServiceDTO/AccessTokenRequest.java deleted file mode 100644 index b633e82..0000000 --- a/src/main/java/sast/evento/model/wxServiceDTO/AccessTokenRequest.java +++ /dev/null @@ -1,25 +0,0 @@ -package sast.evento.model.wxServiceDTO; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/28 16:44 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class AccessTokenRequest { - - private String grant_type = "client_credential"; - - private String appid; - - private String secret; - -} diff --git a/src/main/java/sast/evento/model/wxServiceDTO/AccessTokenResponse.java b/src/main/java/sast/evento/model/wxServiceDTO/AccessTokenResponse.java deleted file mode 100644 index 315c10d..0000000 --- a/src/main/java/sast/evento/model/wxServiceDTO/AccessTokenResponse.java +++ /dev/null @@ -1,21 +0,0 @@ -package sast.evento.model.wxServiceDTO; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/28 16:44 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class AccessTokenResponse { - - private String access_token; - - /* 任意时刻发起调用获取到的 stable_token 有效期至少为 5 分钟 */ - private Integer expires_in; -} diff --git a/src/main/java/sast/evento/model/wxServiceDTO/JsCodeSessionResponse.java b/src/main/java/sast/evento/model/wxServiceDTO/JsCodeSessionResponse.java deleted file mode 100644 index f25f953..0000000 --- a/src/main/java/sast/evento/model/wxServiceDTO/JsCodeSessionResponse.java +++ /dev/null @@ -1,16 +0,0 @@ -package sast.evento.model.wxServiceDTO; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class JsCodeSessionResponse { - private String session_key; - private String unionid; - private String errmsg; - private String openid; - private Integer errcode; -} diff --git a/src/main/java/sast/evento/model/wxServiceDTO/StableTokenRequest.java b/src/main/java/sast/evento/model/wxServiceDTO/StableTokenRequest.java deleted file mode 100644 index 1b128f2..0000000 --- a/src/main/java/sast/evento/model/wxServiceDTO/StableTokenRequest.java +++ /dev/null @@ -1,26 +0,0 @@ -package sast.evento.model.wxServiceDTO; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/28 16:44 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class StableTokenRequest { - - private String grant_type = "client_credential"; - - private String appid; - - private String secret; - - private Boolean force_refresh = false; -} diff --git a/src/main/java/sast/evento/model/wxServiceDTO/WxSubscribeRequest.java b/src/main/java/sast/evento/model/wxServiceDTO/WxSubscribeRequest.java deleted file mode 100644 index 99f2ba4..0000000 --- a/src/main/java/sast/evento/model/wxServiceDTO/WxSubscribeRequest.java +++ /dev/null @@ -1,44 +0,0 @@ -package sast.evento.model.wxServiceDTO; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -import java.util.HashMap; -import java.util.Map; - -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/28 16:46 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@Accessors(chain = true) -public class WxSubscribeRequest { - private String template_id; - private String page; - private String touser;//openId - private Map data; - private String miniprogram_state = "developer";//formal - private String lang = "zh_CN"; - - @JsonIgnore - public static Map getData(Map dataMap) { - return dataMap.entrySet().stream() - .collect( - HashMap::new, - (map, entry) -> map.put(entry.getKey(), new WxDataNode(entry.getValue())), - Map::putAll - ); - } - - @Data - @AllArgsConstructor - public static class WxDataNode { - String value; - } -} diff --git a/src/main/java/sast/evento/model/wxServiceDTO/WxSubscribeResponse.java b/src/main/java/sast/evento/model/wxServiceDTO/WxSubscribeResponse.java deleted file mode 100644 index fdc04db..0000000 --- a/src/main/java/sast/evento/model/wxServiceDTO/WxSubscribeResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package sast.evento.model.wxServiceDTO; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/28 16:47 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class WxSubscribeResponse { - - private String errcode; - - private String errmsg; - - @Override - public String toString() { - return "response{" + - "errcode='" + errcode + '\'' + - ", errmsg='" + errmsg + '\'' + - '}'; - } -} diff --git a/src/main/java/sast/evento/service/WxService.java b/src/main/java/sast/evento/service/WxService.java deleted file mode 100644 index 7b948c1..0000000 --- a/src/main/java/sast/evento/service/WxService.java +++ /dev/null @@ -1,28 +0,0 @@ -package sast.evento.service; - -import sast.evento.model.wxServiceDTO.AccessTokenResponse; -import sast.evento.model.wxServiceDTO.JsCodeSessionResponse; -import sast.evento.model.wxServiceDTO.WxSubscribeResponse; - -// todo 待删除 - -public interface WxService { - - - /** - * 获取稳定token - * @return - */ - AccessTokenResponse getStableToken(); - - /** - * 发送微信订阅消息 - * @param eventId - * @param access_token - * @param openId - * @return - */ - WxSubscribeResponse seedSubscribeMessage(Integer eventId, String access_token, String openId); - - -} diff --git a/src/main/java/sast/evento/service/impl/EventStateScheduleServiceImpl.java b/src/main/java/sast/evento/service/impl/EventStateScheduleServiceImpl.java index 200383e..109643b 100644 --- a/src/main/java/sast/evento/service/impl/EventStateScheduleServiceImpl.java +++ b/src/main/java/sast/evento/service/impl/EventStateScheduleServiceImpl.java @@ -1,95 +1,35 @@ package sast.evento.service.impl; -import jakarta.annotation.Resource; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.quartz.JobDataMap; import org.springframework.stereotype.Service; -import sast.evento.common.enums.ErrorEnum; -import sast.evento.exception.LocalRunTimeException; -import sast.evento.job.EventStateUpdateJob; import sast.evento.service.EventStateScheduleService; -import sast.evento.utils.SchedulerService; import java.util.Date; -/** - * @Author: Love98 - * @Date: 8/26/2023 8:29 PM - */ + @Slf4j @Service public class EventStateScheduleServiceImpl implements EventStateScheduleService { - @Resource - private SchedulerService schedulerService; - private static final String notStartStateJobGroupName = "update_not_start_state_job_group"; - private static final String checkingInStateJobGroupName = "update_checking_in_state_job_group"; - private static final String inProgressStateJobGroupName = "update_in_process_state_job_group"; - private static final String endedStateJobGroupName = "update_ended_state_job_group"; - - private static final String notStartStateTriggerGroupName = "update_not_start_state_trigger_group"; - private static final String checkingInStateTriggerGroupName = "update_checking_in_state_trigger_group"; - private static final String inProgressStateTriggerGroupName = "update_in_process_state_trigger_group"; - private static final String endedStateTriggerGroupName = "update_ended_state_trigger_group"; - @SneakyThrows public void scheduleJob(Integer eventId, Date startTime, Integer state) { - log.info("scheduleJob: eventId: {}, startTime: {}, state: {}", eventId, startTime, state); - JobDataMap jobDataMap = new JobDataMap(); - jobDataMap.put("eventId", eventId); - String stringEventId = String.valueOf(eventId); - jobDataMap.put("state", state); - switch (state) { - case 1 -> - schedulerService.addJob(stringEventId, notStartStateJobGroupName, stringEventId, notStartStateTriggerGroupName, EventStateUpdateJob.class, jobDataMap, startTime); - case 2 -> - schedulerService.addJob(stringEventId, checkingInStateJobGroupName, stringEventId, checkingInStateTriggerGroupName, EventStateUpdateJob.class, jobDataMap, startTime); - case 3 -> - schedulerService.addJob(stringEventId, inProgressStateJobGroupName, stringEventId, inProgressStateTriggerGroupName, EventStateUpdateJob.class, jobDataMap, startTime); - case 5 -> - schedulerService.addJob(stringEventId, endedStateJobGroupName, stringEventId, endedStateTriggerGroupName, EventStateUpdateJob.class, jobDataMap, startTime); - default -> throw new LocalRunTimeException(ErrorEnum.SCHEDULER_ERROR); - } + } @SneakyThrows public void removeJob(Integer eventId, Integer state) { - String stringEventId = String.valueOf(eventId); - switch (state) { - case 1 -> - schedulerService.removeJob(stringEventId, notStartStateJobGroupName, stringEventId, notStartStateTriggerGroupName); - case 2 -> - schedulerService.removeJob(stringEventId, checkingInStateJobGroupName, stringEventId, checkingInStateTriggerGroupName); - case 3 -> - schedulerService.removeJob(stringEventId, inProgressStateJobGroupName, stringEventId, inProgressStateTriggerGroupName); - case 5 -> - schedulerService.removeJob(stringEventId, endedStateJobGroupName, stringEventId, endedStateTriggerGroupName); - default -> throw new LocalRunTimeException(ErrorEnum.SCHEDULER_ERROR); - } + } @SneakyThrows public void removeJobs(Integer eventId) { - String stringEventId = String.valueOf(eventId); - schedulerService.removeJob(stringEventId, notStartStateJobGroupName, stringEventId, notStartStateTriggerGroupName); - schedulerService.removeJob(stringEventId, checkingInStateJobGroupName, stringEventId, checkingInStateTriggerGroupName); - schedulerService.removeJob(stringEventId, inProgressStateJobGroupName, stringEventId, inProgressStateTriggerGroupName); - schedulerService.removeJob(stringEventId, endedStateJobGroupName, stringEventId, endedStateTriggerGroupName); + } @SneakyThrows public void updateJob(Integer eventId, Date startTime, Integer state) { - String stringEventId = String.valueOf(eventId); - if (!switch (state) { - case 1 -> schedulerService.resetJobTrigger(stringEventId, notStartStateTriggerGroupName, startTime); - case 2 -> schedulerService.resetJobTrigger(stringEventId, checkingInStateTriggerGroupName, startTime); - case 3 -> schedulerService.resetJobTrigger(stringEventId, inProgressStateTriggerGroupName, startTime); - case 5 -> schedulerService.resetJobTrigger(stringEventId, endedStateTriggerGroupName, startTime); - default -> throw new LocalRunTimeException(ErrorEnum.SCHEDULER_ERROR); - }) { - scheduleJob(eventId, startTime, state); - } + } } diff --git a/src/main/java/sast/evento/service/impl/LoginServiceImpl.java b/src/main/java/sast/evento/service/impl/LoginServiceImpl.java index 1875272..329e328 100644 --- a/src/main/java/sast/evento/service/impl/LoginServiceImpl.java +++ b/src/main/java/sast/evento/service/impl/LoginServiceImpl.java @@ -17,9 +17,7 @@ import sast.evento.mapper.UserMapper; import sast.evento.mapper.UserPasswordMapper; import sast.evento.model.UserModel; -import sast.evento.model.wxServiceDTO.JsCodeSessionResponse; import sast.evento.service.LoginService; -import sast.evento.service.WxService; import sast.evento.utils.*; @@ -29,14 +27,8 @@ import static sast.evento.utils.JwtUtil.TOKEN; -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/14 14:12 - */ @Service public class LoginServiceImpl implements LoginService { - /* 带缓存的SastLink登录服务 */ @Resource private SastLinkService sastLinkService; @Resource @@ -47,8 +39,6 @@ public class LoginServiceImpl implements LoginService { private UserMapper userMapper; @Resource private UserPasswordMapper userPasswordMapper; - @Resource // todo 待删除 - private WxService wxService; @Resource private JwtUtil jwtUtil; @Resource diff --git a/src/main/java/sast/evento/service/impl/SubscribeMessageServiceImpl.java b/src/main/java/sast/evento/service/impl/SubscribeMessageServiceImpl.java deleted file mode 100644 index 7aea5af..0000000 --- a/src/main/java/sast/evento/service/impl/SubscribeMessageServiceImpl.java +++ /dev/null @@ -1,100 +0,0 @@ -package sast.evento.service.impl; - - -import jakarta.annotation.Resource; -import lombok.Getter; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.quartz.JobDataMap; -import org.springframework.stereotype.Service; -import sast.evento.common.enums.ErrorEnum; -import sast.evento.exception.LocalRunTimeException; -import sast.evento.job.WxSubscribeJob; -import sast.evento.service.SubscribeMessageService; -import sast.evento.utils.SchedulerService; - -import java.text.SimpleDateFormat; -import java.util.Date; - -import static sast.evento.utils.SchedulerService.simpleDateFormatPattern; - -/** - * @projectName: Test - * @author: feelMoose - * @date: 2023/7/26 16:27 - */ - -@Slf4j -@Service -public class SubscribeMessageServiceImpl implements SubscribeMessageService { - /* 可以定时发送消息的微信订阅消息服务 */ - - /* 流程如下: - * 创建活动时创建定时任务 - * 修改活动时修改定时任务时间 - * 取消活动或删除活动时删除定时任务 - * - * 定时任务会在startTime开始读取数据库中订阅某活动的用户(只允许从微信订阅,一定有openId) - * 并获取微信stable_access_token,根据模板id和一定的格式发送消息 - * - * 可以选择是否开启这一功能 - */ - private static final String jobGroupName = "job_wx_subscribe"; - private static final String triggerGroupName = "trigger_wx_subscribe"; - @Getter - private static Boolean isOpen = true; - @Resource - private SchedulerService schedulerService; - - /* 开启任务 */ - public void open() { - isOpen = true; - } - - /* 关闭任务 */ - public void close() { - isOpen = false; - } - - /* 查看任务是否关闭 */ - @SneakyThrows - public Boolean isClose() { - return (!isOpen) || schedulerService.isShutdown(); - } - - /* 添加定时读取并发送活动提醒任务 */ - @SneakyThrows - public void addWxSubScribeJob(Integer eventId, Date startTime) { - if (isClose()) { - throw new LocalRunTimeException(ErrorEnum.WX_SUBSCRIBE_ERROR, "Wx subscribe message service is close"); - } - String cron = new SimpleDateFormat(simpleDateFormatPattern).format(startTime); - JobDataMap jobDataMap = new JobDataMap(); - jobDataMap.put("eventId", eventId); - String stringEventId = String.valueOf(eventId); - schedulerService.addJob(stringEventId, jobGroupName, stringEventId, triggerGroupName, WxSubscribeJob.class, jobDataMap, cron); - } - - /* 更新任务时间 */ - @SneakyThrows - public void updateWxSubScribeJob(Integer eventId, Date startTime) { - if (isClose()) { - throw new LocalRunTimeException(ErrorEnum.WX_SUBSCRIBE_ERROR, "Wx subscribe message service is close"); - } - String cron = new SimpleDateFormat(simpleDateFormatPattern).format(startTime); - if (!schedulerService.resetJobTrigger(String.valueOf(eventId), triggerGroupName, cron)) { - addWxSubScribeJob(eventId, startTime); - } - } - - /* 删除任务 */ - @SneakyThrows - public void removeWxSubScribeJob(Integer eventId) { - if (isClose()) { - throw new LocalRunTimeException(ErrorEnum.WX_SUBSCRIBE_ERROR, "Wx subscribe message service is close."); - } - String stringEventId = String.valueOf(eventId); - schedulerService.removeJob(stringEventId, jobGroupName, stringEventId, triggerGroupName); - } - -} diff --git a/src/main/java/sast/evento/service/impl/WxServiceImpl.java b/src/main/java/sast/evento/service/impl/WxServiceImpl.java deleted file mode 100644 index ca14ccd..0000000 --- a/src/main/java/sast/evento/service/impl/WxServiceImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -package sast.evento.service.impl; - - -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; -import sast.evento.common.constant.Constant; -import sast.evento.common.enums.ErrorEnum; -import sast.evento.exception.LocalRunTimeException; -import sast.evento.model.wxServiceDTO.*; -import sast.evento.service.WxService; -import sast.evento.utils.JsonUtil; - -import java.util.HashMap; -import java.util.Map; - - -/** - * @projectName: sast-evento-backend - * @author: feelMoose - * @date: 2023/7/28 17:45 - */ -@Service -@Slf4j -public class WxServiceImpl implements WxService { - /* 基础微信相关服务 */ - - @Value("${wx.templateId}") - public String template_id; - @Value("${wx.secret}") - public String secret; - @Value("${wx.appid}") - public String appid; - @Value("${wx.TokenRetryTimes}") - public int retryTimes; - - @Resource - private RestTemplate restTemplate; - - @Override - /* 获取stable_token,无需手动刷新,有效时间最少为5分钟 */ - public AccessTokenResponse getStableToken() { - StableTokenRequest request = new StableTokenRequest() - .setAppid(appid) - .setSecret(secret); - int times = 0; - AccessTokenResponse response = null; - while (times < retryTimes) { - response = restTemplate.postForObject(Constant.wxStableTokenURL, request, AccessTokenResponse.class); - if (response != null && !response.getAccess_token().isEmpty()) { - return response; - } - times++; - } - throw new LocalRunTimeException(ErrorEnum.WX_SERVICE_ERROR, "response or access_token is empty"); - } - - - @Override - /* 发送wx模板消息内容 */ - public WxSubscribeResponse seedSubscribeMessage(Integer eventId, String access_token, String openId) { - Map dataMap = new HashMap<>(); - dataMap.put("", "");//todo 与模板对接放入信息,类型为String - - WxSubscribeRequest wxSubscribeRequest = new WxSubscribeRequest() - .setTemplate_id(template_id) - .setPage(null)//点击跳转小程序页面: "index?foo=bar" - .setData(WxSubscribeRequest.getData(dataMap)) - .setTouser(openId); - Map wxSubscribeVariables = new HashMap<>(); - wxSubscribeVariables.put("access_token", access_token); - WxSubscribeResponse response = restTemplate.postForObject(Constant.wxSubscribeURL, wxSubscribeRequest, WxSubscribeResponse.class, wxSubscribeVariables); - if (response == null || !response.getErrcode().equals("0")) { - throw new LocalRunTimeException(ErrorEnum.WX_SUBSCRIBE_ERROR, "Seed message failed, return: " + response); - } - return response; - } - - -} diff --git a/src/main/java/sast/evento/utils/SchedulerService.java b/src/main/java/sast/evento/utils/SchedulerService.java deleted file mode 100644 index c4bc364..0000000 --- a/src/main/java/sast/evento/utils/SchedulerService.java +++ /dev/null @@ -1,219 +0,0 @@ -package sast.evento.utils; - -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.quartz.*; -import org.quartz.impl.StdScheduler; -import org.quartz.impl.StdSchedulerFactory; -import org.quartz.impl.matchers.KeyMatcher; -import org.quartz.impl.triggers.CronTriggerImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.lang.Nullable; -import org.springframework.scheduling.quartz.SchedulerFactoryBean; -import org.springframework.stereotype.Component; - -import java.util.Date; - -/** - * @projectName: Test - * @author: feelMoose - * @date: 2023/7/26 22:35 - */ -@Slf4j -@Component -public class SchedulerService { - public static final String simpleDateFormatPattern = "ss mm HH dd MM ? yyyy"; - @Resource - private StdScheduler schedulerFactoryBean; - - public Scheduler getScheduler() { - return this.schedulerFactoryBean; - } - - public void addJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName, Class jobClass, @Nullable JobDataMap jobDataMap, String cron) throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - if (!scheduler.isStarted()) { - throw new RuntimeException("Please contact admin to start the scheduler first."); - } - JobDetail jobDetail = JobBuilder.newJob(jobClass) - .withIdentity(jobName, jobGroupName) - .setJobData(jobDataMap) - .build(); - CronTrigger trigger = TriggerBuilder.newTrigger() - .withIdentity(triggerName, triggerGroupName) - .startNow() - .withSchedule(CronScheduleBuilder.cronSchedule(cron)) - .build(); - scheduler.scheduleJob(jobDetail, trigger); - } - - public void addRepeatJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName, Class jobClass, @Nullable JobDataMap jobDataMap, String cron, Date start, Date end) throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - if (!scheduler.isStarted()) { - throw new RuntimeException("Please contact admin to start the scheduler first."); - } - JobDetail jobDetail = JobBuilder.newJob(jobClass) - .withIdentity(jobName, jobGroupName) - .setJobData(jobDataMap) - .build(); - CronTrigger trigger = TriggerBuilder.newTrigger() - .withIdentity(triggerName, triggerGroupName) - .startAt(start) - .endAt(end) - .withSchedule(CronScheduleBuilder.cronSchedule(cron)) - .build(); - scheduler.scheduleJob(jobDetail, trigger); - } - - public void addJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName, Class jobClass, @Nullable JobDataMap jobDataMap, Date date) throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - if (!scheduler.isStarted()) { - throw new RuntimeException("Please contact admin to start the scheduler first."); - } - log.info(""" - - jobName: {} - jobGroup: {} - triggerName: {} - triggerGroupName: {}""", jobName, jobGroupName, triggerName, triggerGroupName); - - JobDetail jobDetail = JobBuilder.newJob(jobClass) - .withIdentity(jobName, jobGroupName) - .setJobData(jobDataMap) - .build(); - SimpleTrigger simpleTrigger = (SimpleTrigger) TriggerBuilder.newTrigger() - .withIdentity(triggerName, triggerGroupName) - .startAt(date) - .build(); - scheduler.scheduleJob(jobDetail, simpleTrigger); - } - - - public Boolean resetJobTrigger(String triggerName, String triggerGroupName, String cron) throws Exception { - Scheduler scheduler = this.getScheduler(); - TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroupName); - CronTriggerImpl trigger = (CronTriggerImpl) scheduler.getTrigger(triggerKey); - if (trigger == null) { - log.error("resetRepeatJobFailed:" + triggerGroupName + ":" + triggerName); - return false; - } - - if (!trigger.getCronExpression().equalsIgnoreCase(cron)) { - trigger.setCronExpression(cron); - scheduler.rescheduleJob(triggerKey, trigger); - } - return true; - } - - public Boolean resetJobTrigger(String triggerName, String triggerGroupName, Date date) throws Exception { - Scheduler scheduler = this.getScheduler(); - TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroupName); - SimpleTrigger trigger = (SimpleTrigger) scheduler.getTrigger(triggerKey); - if (trigger == null) { - log.error("resetRepeatJobFailed:" + triggerGroupName + ":" + triggerName); - return false; - } - - if (!trigger.getStartTime().equals(date)) { - SimpleTrigger simpleTrigger = (SimpleTrigger) TriggerBuilder.newTrigger() - .withIdentity(triggerKey) - .startAt(date) - .build(); - scheduler.rescheduleJob(triggerKey, simpleTrigger); - } - return true; - } - - public Boolean resetRepeatJob(String triggerName, String triggerGroupName, String cron, Date start, Date end) throws Exception { - Scheduler scheduler = this.getScheduler(); - TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroupName); - CronTriggerImpl trigger = (CronTriggerImpl) scheduler.getTrigger(triggerKey); - if (trigger == null) { - log.error("resetRepeatJobFailed:" + triggerGroupName + ":" + triggerName); - return false; - } - - if (!trigger.getCronExpression().equalsIgnoreCase(cron)) { - trigger.setCronExpression(cron); - } - if (start != null) { - trigger.setStartTime(start); - } - if (end != null) { - trigger.setEndTime(end); - } - scheduler.rescheduleJob(triggerKey, trigger); - return true; - } - - public void addJobListener(String jobName, String jobGroup, JobListener listener) throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - JobKey jobKey = new JobKey(jobName, jobGroup); - Matcher matcher = KeyMatcher.keyEquals(jobKey); - scheduler.getListenerManager().addJobListener(listener, matcher); - } - - public void removeJobListener(String name, String jobName, String jobGroup) throws SchedulerException { - JobKey jobKey = new JobKey(jobName, jobGroup); - Matcher matcher = KeyMatcher.keyEquals(jobKey); - Scheduler scheduler = this.getScheduler(); - scheduler.getListenerManager().removeJobListenerMatcher(name, matcher); - } - - public void addTriggerListener(String triggerName, String triggerGroup, TriggerListener listener) throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroup); - Matcher matcher = KeyMatcher.keyEquals(triggerKey); - scheduler.getListenerManager().addTriggerListener(listener, matcher); - } - - public void removeTriggerListener(String name, String triggerName, String triggerGroup) throws SchedulerException { - TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroup); - Matcher matcher = KeyMatcher.keyEquals(triggerKey); - Scheduler scheduler = this.getScheduler(); - scheduler.getListenerManager().removeTriggerListenerMatcher(name, matcher); - } - - public void removeJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName) throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - if (!isJobExist(jobName, jobGroupName, triggerName, triggerGroupName)) { - log.info("Job: {} is not exist.", jobName); - return; - } - TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroupName); - scheduler.pauseTrigger(triggerKey); - scheduler.unscheduleJob(triggerKey); - scheduler.deleteJob(new JobKey(jobName, jobGroupName)); - } - - public Boolean isJobExist(String jobName, String jobGroupName, String triggerName, String triggerGroupName) throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - return scheduler.checkExists(new JobKey(jobName, jobGroupName)) && scheduler.checkExists(new TriggerKey(triggerName, triggerGroupName)); - } - - public void shutdownScheduler() throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - if (!scheduler.isShutdown()) { - scheduler.shutdown(); - log.info("Scheduler shut down."); - } else { - log.info("Scheduler has shut down."); - } - } - - - public void startScheduler() throws SchedulerException { - Scheduler scheduler = this.getScheduler(); - if (!scheduler.isStarted()) { - scheduler.start(); - log.info("Scheduler start."); - } else { - log.warn("Scheduler has start."); - } - } - - public Boolean isShutdown() throws SchedulerException { - return this.getScheduler().isShutdown(); - } - -} \ No newline at end of file diff --git a/src/test/java/sast/evento/SastEventoBackendApplicationTests.java b/src/test/java/sast/evento/SastEventoBackendApplicationTests.java index 10343e2..001abb3 100644 --- a/src/test/java/sast/evento/SastEventoBackendApplicationTests.java +++ b/src/test/java/sast/evento/SastEventoBackendApplicationTests.java @@ -3,25 +3,18 @@ import jakarta.annotation.Resource; import lombok.SneakyThrows; import org.junit.jupiter.api.Test; -import org.quartz.*; -import org.quartz.impl.StdSchedulerFactory; import org.springframework.boot.test.context.SpringBootTest; -import sast.evento.job.EventStateUpdateJob; import sast.evento.mapper.SubscribeDepartmentMapper; import sast.evento.service.EventStateScheduleService; import sast.evento.service.LocationService; import sast.evento.service.LoginService; import sast.evento.utils.JsonUtil; import sast.evento.utils.RedisUtil; -import sast.evento.utils.SchedulerService; -import sast.sastlink.sdk.service.SastLinkService; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Date; import java.util.List; -import static sast.evento.utils.SchedulerService.simpleDateFormatPattern; @SpringBootTest class SastEventoBackendApplicationTests { @@ -30,13 +23,9 @@ class SastEventoBackendApplicationTests { @Resource private RedisUtil redisUtil; - @Resource - private SchedulerService schedulerService; @Resource private LocationService locationService; - @Resource - private SastLinkService sastLinkService; @Resource private SubscribeDepartmentMapper subscribeDepartmentMapper; @@ -44,75 +33,6 @@ class SastEventoBackendApplicationTests { @Resource private EventStateScheduleService eventStateScheduleService; - @SneakyThrows - @Test - void eventSSTest() { - String dateStr = "2023-09-05 22:25:59"; - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try { - schedulerService.startScheduler(); - eventStateScheduleService.scheduleJob(47, dateFormat.parse(dateStr), 2); - Thread.sleep(1000); - eventStateScheduleService.scheduleJob(46, dateFormat.parse(dateStr), 3); - Thread.sleep(60000); - } catch (ParseException | InterruptedException e) { - throw new RuntimeException(e); - } - } - - @Test - void cronTest() { - String dateStr = "2023-09-04 12:16:10"; - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try { - System.out.println(new SimpleDateFormat(simpleDateFormatPattern).format(dateFormat.parse(dateStr))); - } catch (ParseException e) { - throw new RuntimeException(e); - } - } - - @Test - void oneTimeJobTest() throws SchedulerException { - for (int i = 2; i < 43; i++) { - Date date = new Date(); - date.setTime(date.getTime() + 5000000); - JobDataMap jobDataMapForUtil = new JobDataMap(); - jobDataMapForUtil.put("eventId", i); - jobDataMapForUtil.put("state", 3); - schedulerService.startScheduler(); - schedulerService.addJob(String.valueOf(i), "update_not_start_state_job_group", String.valueOf(i), "update_not_start_state_trigger_group", EventStateUpdateJob.class, jobDataMapForUtil, date); - } - try { - Thread.sleep(70000); - } catch (Exception e) { - System.out.println(e.getMessage()); - throw new RuntimeException(e); - } - } - - @Test - void oneTimeJobDirectAddingTest() throws SchedulerException { - Date date = new Date(); - date.setTime(date.getTime() + 50000); - JobDataMap jobDataMapForDirect = new JobDataMap(); - jobDataMapForDirect.put("eventId", 37); - jobDataMapForDirect.put("state", 2); -// Scheduler scheduler = schedulerService.getScheduler(); -// scheduler.start(); - JobDetail jobDetail = JobBuilder.newJob(EventStateUpdateJob.class) - .withIdentity("44", "update_not_start_state_job_group") - .setJobData(jobDataMapForDirect) - .build(); - SimpleTrigger simpleTrigger = (SimpleTrigger) TriggerBuilder.newTrigger() - .withIdentity("44", "update_not_start_state_trigger_group") - .startAt(date) - .build(); - try { - Thread.sleep(6000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } @Test void RedisTest() { @@ -129,36 +49,4 @@ void subscribeDepartmentMapperTest() { System.out.println(subscribeDepartmentMapper.selectSubscribeDepartmentUser(List.of(1, 10, 2, 3, 4))); } - void combineTest() throws SchedulerException { - Date date = new Date(); - date.setTime(date.getTime() + 5000); - JobDataMap jobDataMapForUtil = new JobDataMap(); - jobDataMapForUtil.put("eventId", 56); - jobDataMapForUtil.put("state", 3); -// schedulerService.startScheduler(); - schedulerService.addJob("44", "update_not_start_state_job_group", "44", "update_not_start_state_trigger_group", EventStateUpdateJob.class, jobDataMapForUtil, date); - JobDataMap jobDataMapForDirect = new JobDataMap(); - jobDataMapForDirect.put("eventId", 57); - jobDataMapForDirect.put("state", 2); - System.out.println("Util HashCode: " + schedulerService.getScheduler().hashCode()); - Scheduler scheduler = new StdSchedulerFactory().getScheduler(); - System.out.println("Direct HashCode: " + scheduler.hashCode()); - scheduler.start(); -// Scheduler scheduler = schedulerService.getScheduler(); -// scheduler.start(); - JobDetail jobDetail = JobBuilder.newJob(EventStateUpdateJob.class) - .withIdentity("37", "update_not_start_state_job_group") - .setJobData(jobDataMapForDirect) - .build(); - SimpleTrigger simpleTrigger = (SimpleTrigger) TriggerBuilder.newTrigger() - .withIdentity("37", "update_not_start_state_trigger_group") - .startAt(date) - .build(); - scheduler.scheduleJob(jobDetail, simpleTrigger); - try { - Thread.sleep(6000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } }