From 7ca14f76a6573b97619d33b8fc3b2b090d9f9504 Mon Sep 17 00:00:00 2001 From: Aiden2014 Date: Wed, 13 Dec 2023 22:07:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E5=BD=93=E5=B8=A6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=9F=A5=E8=AF=A2=E6=B4=BB=E5=8A=A8=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=88=E7=AD=9B=E9=80=89=EF=BC=89=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=97=B6=EF=BC=8C=E6=8C=89=E7=85=A7=E7=9A=84=E6=98=AF?= =?UTF-8?q?id=E6=8E=92=E5=BA=8F=E8=80=8C=E4=B8=8D=E6=98=AF=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E5=BC=80=E5=A7=8B=E6=97=B6=E9=97=B4=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sast/evento/common/enums/ErrorEnum.java | 18 ++++++------- .../sast/evento/config/ActionRegister.java | 4 +-- .../sast/evento/config/SchedulerConfig.java | 2 +- .../sast/evento/mapper/FeedbackMapper.java | 4 --- .../sast/evento/mapper/LocationMapper.java | 2 +- .../java/sast/evento/mapper/UserMapper.java | 2 +- .../java/sast/evento/model/UserModel.java | 5 ---- .../treeDataNodeDTO/SemiTreeDataNode.java | 3 +-- .../model/treeDataNodeDTO/TreeDataNode.java | 5 ++-- .../evento/service/impl/EventServiceImpl.java | 25 ++++++++----------- src/main/java/sast/evento/utils/CosUtil.java | 4 +-- src/main/java/sast/evento/utils/JwtUtil.java | 6 ++--- src/main/java/sast/evento/utils/MD5Util.java | 8 +++--- .../java/sast/evento/utils/SchedulerUtil.java | 13 +++++----- .../java/sast/evento/utils/TicketUtil.java | 4 +-- src/main/java/sast/evento/utils/TimeUtil.java | 4 ++- .../resources/mapper/eventModelMapper.xml | 4 +++ 17 files changed, 52 insertions(+), 61 deletions(-) diff --git a/src/main/java/sast/evento/common/enums/ErrorEnum.java b/src/main/java/sast/evento/common/enums/ErrorEnum.java index faba2a4..b0d535e 100644 --- a/src/main/java/sast/evento/common/enums/ErrorEnum.java +++ b/src/main/java/sast/evento/common/enums/ErrorEnum.java @@ -23,22 +23,22 @@ public enum ErrorEnum { /* 数据不存在 */ EVENT_TYPE_NOT_EXIST(1006, "eventType not exist"), LOCATION_NOT_EXIST(1007, "location not exist"), - EVENT_NOT_EXIST(1008,"event not exist"), + EVENT_NOT_EXIST(1008, "event not exist"), /* 登录异常 */ - LOGIN_ERROR(1009,"login failed"), - LOGIN_EXPIRE(1010,"login expired"), - NOT_REGISTER(1011,"user info not exist please register first"), + LOGIN_ERROR(1009, "login failed"), + LOGIN_EXPIRE(1010, "login expired"), + NOT_REGISTER(1011, "user info not exist please register first"), /* 其他服务错误 */ WX_SERVICE_ERROR(10001, "wx service error"), WX_SUBSCRIBE_ERROR(10001, "wx subscribe error"), SCHEDULER_ERROR(10002, "scheduler error"), QRCODE_ERROR(10003, "qr code generation error"), - COS_SERVICE_ERROR(10004,"cos service error"), - SAST_LINK_SERVICE_ERROR(10005,"sast link service error"), - STUDENT_NOT_BIND(10006,"bind studentId first"), - STUDENT_HAS_BEEN_BIND(10007,"studentId has been bind"), - ACCOUNT_HAS_BEEN_BIND(10008,"account has been bind"), + COS_SERVICE_ERROR(10004, "cos service error"), + SAST_LINK_SERVICE_ERROR(10005, "sast link service error"), + STUDENT_NOT_BIND(10006, "bind studentId first"), + STUDENT_HAS_BEEN_BIND(10007, "studentId has been bind"), + ACCOUNT_HAS_BEEN_BIND(10008, "account has been bind"), /* 时间格式错误 */ TIME_ERROR(20001, "time format error"); private final Integer errCode; diff --git a/src/main/java/sast/evento/config/ActionRegister.java b/src/main/java/sast/evento/config/ActionRegister.java index 107f9ec..8f40d25 100644 --- a/src/main/java/sast/evento/config/ActionRegister.java +++ b/src/main/java/sast/evento/config/ActionRegister.java @@ -32,9 +32,9 @@ @Slf4j @Component public class ActionRegister implements BeanFactoryAware, CommandLineRunner { - public ListableBeanFactory beanFactory; public static Map actionName2action = new HashMap<>(); public static Set actionNameSet; + public ListableBeanFactory beanFactory; @Override public void setBeanFactory(@NonNull BeanFactory beanFactory) throws BeansException { @@ -64,7 +64,7 @@ public void run(String... args) { } String methodName = m.getName(); - actionName2action.put(methodName, new Action(m.getName(), d.group(), d.value(),ano.value())); + actionName2action.put(methodName, new Action(m.getName(), d.group(), d.value(), ano.value())); } } actionNameSet = actionName2action.keySet(); diff --git a/src/main/java/sast/evento/config/SchedulerConfig.java b/src/main/java/sast/evento/config/SchedulerConfig.java index 6844f7d..9470433 100644 --- a/src/main/java/sast/evento/config/SchedulerConfig.java +++ b/src/main/java/sast/evento/config/SchedulerConfig.java @@ -22,7 +22,7 @@ public void onApplicationEvent(ContextRefreshedEvent event) { log.info("Start Scheduler"); SchedulerUtil.startScheduler(); } catch (SchedulerException e) { - throw new LocalRunTimeException(ErrorEnum.SCHEDULER_ERROR,"error start"); + throw new LocalRunTimeException(ErrorEnum.SCHEDULER_ERROR, "error start"); } } } diff --git a/src/main/java/sast/evento/mapper/FeedbackMapper.java b/src/main/java/sast/evento/mapper/FeedbackMapper.java index b65e47b..e2f907e 100644 --- a/src/main/java/sast/evento/mapper/FeedbackMapper.java +++ b/src/main/java/sast/evento/mapper/FeedbackMapper.java @@ -6,10 +6,6 @@ import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import sast.evento.entitiy.Feedback; - -import java.util.List; -import java.util.Map; - import sast.evento.model.FeedbackNumModel; import sast.evento.model.FeedbacksDTO; import sast.evento.model.PageModel; diff --git a/src/main/java/sast/evento/mapper/LocationMapper.java b/src/main/java/sast/evento/mapper/LocationMapper.java index d1ec713..0668e8f 100644 --- a/src/main/java/sast/evento/mapper/LocationMapper.java +++ b/src/main/java/sast/evento/mapper/LocationMapper.java @@ -14,5 +14,5 @@ public interface LocationMapper extends BaseMapper { // 结果为以空格分割的完整字符串,例:“中国 江苏省 南京市 栖霞区 南邮” String getLocationName(@Param("locationId") Integer locationId); - void updateLocationName(@Param("id") Integer id,@Param("location_name")String locationName); + void updateLocationName(@Param("id") Integer id, @Param("location_name") String locationName); } diff --git a/src/main/java/sast/evento/mapper/UserMapper.java b/src/main/java/sast/evento/mapper/UserMapper.java index 24f03c0..38cc75c 100644 --- a/src/main/java/sast/evento/mapper/UserMapper.java +++ b/src/main/java/sast/evento/mapper/UserMapper.java @@ -7,5 +7,5 @@ @Mapper public interface UserMapper extends BaseMapper { - void bindStudentId(@Param("userId") String userId,@Param("studentId") String studentId); + void bindStudentId(@Param("userId") String userId, @Param("studentId") String studentId); } diff --git a/src/main/java/sast/evento/model/UserModel.java b/src/main/java/sast/evento/model/UserModel.java index 1934216..7d409f6 100644 --- a/src/main/java/sast/evento/model/UserModel.java +++ b/src/main/java/sast/evento/model/UserModel.java @@ -1,10 +1,5 @@ package sast.evento.model; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.fasterxml.jackson.annotation.JsonAlias; -import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/sast/evento/model/treeDataNodeDTO/SemiTreeDataNode.java b/src/main/java/sast/evento/model/treeDataNodeDTO/SemiTreeDataNode.java index 735528e..db8751b 100644 --- a/src/main/java/sast/evento/model/treeDataNodeDTO/SemiTreeDataNode.java +++ b/src/main/java/sast/evento/model/treeDataNodeDTO/SemiTreeDataNode.java @@ -1,6 +1,5 @@ package sast.evento.model.treeDataNodeDTO; -import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -13,7 +12,7 @@ @Data @AllArgsConstructor @NoArgsConstructor -public class SemiTreeDataNode extends AbstractTreeDataNode{ +public class SemiTreeDataNode extends AbstractTreeDataNode { private String label; diff --git a/src/main/java/sast/evento/model/treeDataNodeDTO/TreeDataNode.java b/src/main/java/sast/evento/model/treeDataNodeDTO/TreeDataNode.java index 4398e9d..2efc749 100644 --- a/src/main/java/sast/evento/model/treeDataNodeDTO/TreeDataNode.java +++ b/src/main/java/sast/evento/model/treeDataNodeDTO/TreeDataNode.java @@ -3,7 +3,8 @@ import java.util.List; public interface TreeDataNode { - void addChildren(TreeDataNode node); - void addChildren(List nodes); + void addChildren(TreeDataNode node); + + void addChildren(List nodes); } diff --git a/src/main/java/sast/evento/service/impl/EventServiceImpl.java b/src/main/java/sast/evento/service/impl/EventServiceImpl.java index 2b5c692..0000137 100644 --- a/src/main/java/sast/evento/service/impl/EventServiceImpl.java +++ b/src/main/java/sast/evento/service/impl/EventServiceImpl.java @@ -138,9 +138,7 @@ public List getSubscribed(String userId) { if(dates == null || dates.isEmpty()) { throw new LocalRunTimeException(ErrorEnum.TIME_ERROR); } - // 结束日期设为无限大,获取的不是Date最大时间而是MySQL中datetime最大时间 - final Date FINAL_DATE = timeUtil.validTime("9999-12-31").getTime(); - dates.set(1, FINAL_DATE); + dates.set(1, timeUtil.FINAL_DATE); return eventModelMapper.getSubscribed(userId, dates.get(0), dates.get(1)); } @@ -390,23 +388,22 @@ private void addEventStateSchedule(Event event) { @Override public List postForEvents(List typeId, List departmentId, String time) { String today = timeUtil.getTime(); - List date = timeUtil.getDateOfMonday(today); - // 如果time不为空,则将date起始日期改为time所设置的日期,结束日期设为无限大,获取的不是Date最大时间而是MySQL中datetime最大时间 + List dates = timeUtil.getDateOfMonday(today); + // 如果time不为空,则将dates起始日期改为time所设置的日期 if (!time.isEmpty()) { - date.set(0,timeUtil.validTime(time).getTime()); - final Date FINAL_DATE = timeUtil.validTime("9999-12-31").getTime(); - date.set(1,FINAL_DATE); + dates.set(0,timeUtil.validTime(time).getTime()); + dates.set(1,timeUtil.FINAL_DATE); } if (typeId.isEmpty()) { if (departmentId.isEmpty()) { - return eventModelMapper.getEventByTime(date.get(0), date.get(1)); + return eventModelMapper.getEventByTime(dates.get(0), dates.get(1)); } - return eventModelMapper.getEventByDepartmentIdAndTime(departmentId, date.get(0), date.get(1)); + return eventModelMapper.getEventByDepartmentIdAndTime(departmentId, dates.get(0), dates.get(1)); } if (departmentId.isEmpty()) { - return eventModelMapper.getEventByTypeIdAndTime(typeId, date.get(0), date.get(1)); + return eventModelMapper.getEventByTypeIdAndTime(typeId, dates.get(0), dates.get(1)); } - return eventModelMapper.postForEventsByAll(typeId, departmentId, date.get(0), date.get(1)); + return eventModelMapper.postForEventsByAll(typeId, departmentId, dates.get(0), dates.get(1)); } // 获取已报名的活动列表(本周和未来的活动) @@ -420,9 +417,7 @@ public List getRegistered(String userId) { if(dates == null || dates.isEmpty()) { throw new LocalRunTimeException(ErrorEnum.TIME_ERROR); } - // 结束日期设为无限大,获取的不是Date最大时间而是MySQL中datetime最大时间 - final Date FINAL_DATE = timeUtil.validTime("9999-12-31").getTime(); - dates.set(1, FINAL_DATE); + dates.set(1, timeUtil.FINAL_DATE); return eventModelMapper.getRegistered(userId, dates.get(0), dates.get(1)); } diff --git a/src/main/java/sast/evento/utils/CosUtil.java b/src/main/java/sast/evento/utils/CosUtil.java index 1130d2c..4e1dcc7 100644 --- a/src/main/java/sast/evento/utils/CosUtil.java +++ b/src/main/java/sast/evento/utils/CosUtil.java @@ -44,7 +44,7 @@ public static String upload(MultipartFile file, String dir) throws IOException, if (originalFileName == null || originalFileName.isEmpty()) { throw new IllegalArgumentException("name of upload file is empty."); } - if(!originalFileName.contains(".")){ + if (!originalFileName.contains(".")) { throw new IllegalArgumentException("error originalFileName"); } int idx = originalFileName.lastIndexOf("."); @@ -102,7 +102,7 @@ public static List changeKey2URL(List keys) { .toList(); } - public static String changeKey2URL(String key){ + public static String changeKey2URL(String key) { return "https://" + bucketName + ".cos." + COS_REGION + ".myqcloud.com/" + key; } diff --git a/src/main/java/sast/evento/utils/JwtUtil.java b/src/main/java/sast/evento/utils/JwtUtil.java index 862a237..053d5af 100644 --- a/src/main/java/sast/evento/utils/JwtUtil.java +++ b/src/main/java/sast/evento/utils/JwtUtil.java @@ -19,12 +19,12 @@ @Component public class JwtUtil { + public static final String TOKEN = "token:"; private final RedisUtil redisUtil; - @Value("${jwt.secret}") - private String secret; @Value("${jwt.expiration}") public Integer expiration; - public static final String TOKEN = "token:"; + @Value("${jwt.secret}") + private String secret; public JwtUtil(RedisUtil redisUtil) { diff --git a/src/main/java/sast/evento/utils/MD5Util.java b/src/main/java/sast/evento/utils/MD5Util.java index 6759255..f2ca3f1 100644 --- a/src/main/java/sast/evento/utils/MD5Util.java +++ b/src/main/java/sast/evento/utils/MD5Util.java @@ -12,11 +12,11 @@ public class MD5Util { private static final String HEX_DIGITS[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; - public static String md5Encode(String origin,String salt) { + public static String md5Encode(String origin, String salt) { String resultString = null; try { - resultString = salt+origin; + resultString = salt + origin; MessageDigest md = MessageDigest.getInstance("MD5"); resultString = byteArrayToHexString(md.digest(resultString .getBytes(UTF_8))); @@ -26,11 +26,11 @@ public static String md5Encode(String origin,String salt) { return resultString; } - public static String getSalt(Integer size){ + public static String getSalt(Integer size) { char[] chars = ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + "1234567890!@#$%^&*()_+").toCharArray(); StringBuilder sb = new StringBuilder(); - for(int i = 0; i < size; i++){ + for (int i = 0; i < size; i++) { //Random().nextInt()返回值为[0,n) char aChar = chars[ThreadLocalRandom.current().nextInt(chars.length)]; sb.append(aChar); diff --git a/src/main/java/sast/evento/utils/SchedulerUtil.java b/src/main/java/sast/evento/utils/SchedulerUtil.java index 03dbea1..5baa6a5 100644 --- a/src/main/java/sast/evento/utils/SchedulerUtil.java +++ b/src/main/java/sast/evento/utils/SchedulerUtil.java @@ -7,7 +7,6 @@ import org.quartz.impl.triggers.CronTriggerImpl; import org.springframework.lang.Nullable; -import java.text.SimpleDateFormat; import java.util.Date; /** @@ -86,8 +85,8 @@ public static Boolean resetJobTrigger(String triggerName, String triggerGroupNam Scheduler scheduler = getScheduler(); TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroupName); CronTriggerImpl trigger = (CronTriggerImpl) scheduler.getTrigger(triggerKey); - if(trigger == null){ - log.error("resetRepeatJobFailed:"+triggerGroupName+":"+triggerName); + if (trigger == null) { + log.error("resetRepeatJobFailed:" + triggerGroupName + ":" + triggerName); return false; } @@ -102,8 +101,8 @@ public static Boolean resetJobTrigger(String triggerName, String triggerGroupNam Scheduler scheduler = getScheduler(); TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroupName); SimpleTrigger trigger = (SimpleTrigger) scheduler.getTrigger(triggerKey); - if(trigger == null){ - log.error("resetRepeatJobFailed:"+triggerGroupName+":"+triggerName); + if (trigger == null) { + log.error("resetRepeatJobFailed:" + triggerGroupName + ":" + triggerName); return false; } @@ -121,8 +120,8 @@ public static Boolean resetRepeatJob(String triggerName, String triggerGroupName Scheduler scheduler = getScheduler(); TriggerKey triggerKey = new TriggerKey(triggerName, triggerGroupName); CronTriggerImpl trigger = (CronTriggerImpl) scheduler.getTrigger(triggerKey); - if(trigger == null){ - log.error("resetRepeatJobFailed:"+triggerGroupName+":"+triggerName); + if (trigger == null) { + log.error("resetRepeatJobFailed:" + triggerGroupName + ":" + triggerName); return false; } diff --git a/src/main/java/sast/evento/utils/TicketUtil.java b/src/main/java/sast/evento/utils/TicketUtil.java index 6788496..5cf0783 100644 --- a/src/main/java/sast/evento/utils/TicketUtil.java +++ b/src/main/java/sast/evento/utils/TicketUtil.java @@ -18,10 +18,10 @@ public static String generateTicket(String key) { } - public static String[] getInfoFromTicket(String ticket){ + public static String[] getInfoFromTicket(String ticket) { int p1 = ticket.indexOf(':'); int p2 = ticket.lastIndexOf(':'); - return new String[]{ticket.substring(0,p1),ticket.substring(p1+2,p2-1),ticket.substring(p1+1)}; + return new String[]{ticket.substring(0, p1), ticket.substring(p1 + 2, p2 - 1), ticket.substring(p1 + 1)}; } public static String generateRandomStr() { diff --git a/src/main/java/sast/evento/utils/TimeUtil.java b/src/main/java/sast/evento/utils/TimeUtil.java index f40c85d..154bfb8 100644 --- a/src/main/java/sast/evento/utils/TimeUtil.java +++ b/src/main/java/sast/evento/utils/TimeUtil.java @@ -17,6 +17,8 @@ */ @Component public class TimeUtil { + // 结束日期设为无限大,获取的不是Date最大时间而是MySQL中datetime最大时间 + public final Date FINAL_DATE = validTime("9999-12-31").getTime(); /** * @param time String类型 @@ -68,7 +70,7 @@ public List getDateOfMonday(String time) { * @return String 获取当前yyyy-MM-dd格式的日期 * @author Aiden */ - public String getTime(){ + public String getTime() { Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); return dateFormat.format(date); diff --git a/src/main/resources/mapper/eventModelMapper.xml b/src/main/resources/mapper/eventModelMapper.xml index 21c7dfe..ee6529b 100644 --- a/src/main/resources/mapper/eventModelMapper.xml +++ b/src/main/resources/mapper/eventModelMapper.xml @@ -165,6 +165,7 @@ WHERE + ORDER BY e.gmt_event_start DESC @@ -174,6 +175,7 @@ AND + ORDER BY e.gmt_event_start DESC @@ -183,6 +185,7 @@ AND + ORDER BY e.gmt_event_start DESC @@ -194,6 +197,7 @@ AND + ORDER BY e.gmt_event_start DESC