Skip to content

Commit

Permalink
fix 修复当带时间查询活动列表(筛选)的接口时,按照的是id排序而不是活动开始时间排序的问题。格式化代码。
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiden2014 committed Dec 13, 2023
1 parent a79df47 commit 7ca14f7
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 61 deletions.
18 changes: 9 additions & 9 deletions src/main/java/sast/evento/common/enums/ErrorEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sast/evento/config/ActionRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
@Slf4j
@Component
public class ActionRegister implements BeanFactoryAware, CommandLineRunner {
public ListableBeanFactory beanFactory;
public static Map<String, Action> actionName2action = new HashMap<>();
public static Set<String> actionNameSet;
public ListableBeanFactory beanFactory;

@Override
public void setBeanFactory(@NonNull BeanFactory beanFactory) throws BeansException {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sast/evento/config/SchedulerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
4 changes: 0 additions & 4 deletions src/main/java/sast/evento/mapper/FeedbackMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sast/evento/mapper/LocationMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface LocationMapper extends BaseMapper<Location> {
// 结果为以空格分割的完整字符串,例:“中国 江苏省 南京市 栖霞区 南邮”
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);
}
2 changes: 1 addition & 1 deletion src/main/java/sast/evento/mapper/UserMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

@Mapper
public interface UserMapper extends BaseMapper<User> {
void bindStudentId(@Param("userId") String userId,@Param("studentId") String studentId);
void bindStudentId(@Param("userId") String userId, @Param("studentId") String studentId);
}
5 changes: 0 additions & 5 deletions src/main/java/sast/evento/model/UserModel.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package sast.evento.model.treeDataNodeDTO;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -13,7 +12,7 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SemiTreeDataNode extends AbstractTreeDataNode{
public class SemiTreeDataNode extends AbstractTreeDataNode {

private String label;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.List;

public interface TreeDataNode {
void addChildren(TreeDataNode node);
void addChildren(List<TreeDataNode> nodes);
void addChildren(TreeDataNode node);

void addChildren(List<TreeDataNode> nodes);

}
25 changes: 10 additions & 15 deletions src/main/java/sast/evento/service/impl/EventServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ public List<EventModel> 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));
}

Expand Down Expand Up @@ -390,23 +388,22 @@ private void addEventStateSchedule(Event event) {
@Override
public List<EventModel> postForEvents(List<Integer> typeId, List<Integer> departmentId, String time) {
String today = timeUtil.getTime();
List<Date> date = timeUtil.getDateOfMonday(today);
// 如果time不为空,则将date起始日期改为time所设置的日期,结束日期设为无限大,获取的不是Date最大时间而是MySQL中datetime最大时间
List<Date> 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));
}

// 获取已报名的活动列表(本周和未来的活动)
Expand All @@ -420,9 +417,7 @@ public List<EventModel> 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));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sast/evento/utils/CosUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(".");
Expand Down Expand Up @@ -102,7 +102,7 @@ public static List<String> changeKey2URL(List<String> keys) {
.toList();
}

public static String changeKey2URL(String key){
public static String changeKey2URL(String key) {
return "https://" + bucketName + ".cos." + COS_REGION + ".myqcloud.com/" + key;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/sast/evento/utils/JwtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/sast/evento/utils/MD5Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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);
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/sast/evento/utils/SchedulerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.quartz.impl.triggers.CronTriggerImpl;
import org.springframework.lang.Nullable;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sast/evento/utils/TicketUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/sast/evento/utils/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
@Component
public class TimeUtil {
// 结束日期设为无限大,获取的不是Date最大时间而是MySQL中datetime最大时间
public final Date FINAL_DATE = validTime("9999-12-31").getTime();

/**
* @param time String类型
Expand Down Expand Up @@ -68,7 +70,7 @@ public List<Date> 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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/mapper/eventModelMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<include refid="selectFrom"/>
WHERE
<include refid="byTime"/>
ORDER BY e.gmt_event_start DESC
</select>

<!-- 根据departmentId和time选出活动列表 -->
Expand All @@ -174,6 +175,7 @@
<include refid="byTime"/>
AND
<include refid="byDepartmentId"/>
ORDER BY e.gmt_event_start DESC
</select>

<!-- 根据typeId和time选出活动列表 -->
Expand All @@ -183,6 +185,7 @@
<include refid="byTypeId"/>
AND
<include refid="byTime"/>
ORDER BY e.gmt_event_start DESC
</select>

<!-- 根据三个筛选条件选出活动列表 -->
Expand All @@ -194,6 +197,7 @@
<include refid="byTypeId"/>
AND
<include refid="byDepartmentId"/>
ORDER BY e.gmt_event_start DESC
</select>

<!-- 获取已订阅的活动列表(本周和未来的活动)-->
Expand Down

0 comments on commit 7ca14f7

Please sign in to comment.