Skip to content

Commit

Permalink
feat: 优化更新执行的预约分钟
Browse files Browse the repository at this point in the history
  • Loading branch information
oddfar committed Feb 21, 2024
1 parent 0c7de21 commit 798bc3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.oddfar.campus.common.core.BaseMapperX;
import com.oddfar.campus.common.core.LambdaQueryWrapperX;
import com.oddfar.campus.common.domain.PageResult;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

Expand Down Expand Up @@ -66,8 +66,14 @@ default List<IUser> selectReservationUserByMinute(int minute) {
);
}

@Select("UPDATE i_user SET `minute` = (SELECT FLOOR(RAND() * 50 + 1)) WHERE random_minute = \"0\"")
@Update("UPDATE i_user SET `minute` = (SELECT FLOOR(RAND() * 50 + 1)) WHERE random_minute = \"0\"")
void updateUserMinuteBatch();

@Update("SET @row_number = 0;\n" +
"UPDATE i_user\n" +
"SET `minute` = (@row_number := @row_number + 1) % 50 + 1\n" +
"ORDER BY RAND();")
void updateUserMinuteEven();

int deleteIUser(Long[] iUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ public int updateIUser(IUser iUser) {
@Override
@Async
public void updateUserMinuteBatch() {
iUserMapper.updateUserMinuteBatch();
Long userCount = iUserMapper.selectCount();
if (userCount > 60) {
iUserMapper.updateUserMinuteEven();
}else {
iUserMapper.updateUserMinuteBatch();
}
}

@Override
Expand Down

0 comments on commit 798bc3a

Please sign in to comment.