Skip to content

Commit

Permalink
Merge pull request #116 from ballade0d/dev-dylan
Browse files Browse the repository at this point in the history
feat: cache for EventService#getEvents
  • Loading branch information
feellmoose authored Feb 16, 2024
2 parents cc70e53 + b294b65 commit a76fbb9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import sast.evento.common.enums.ErrorEnum;
import sast.evento.entitiy.Department;
Expand Down Expand Up @@ -56,6 +57,7 @@ public List<Department> getDepartments() {
}

@Override
@CacheEvict(value = "event")
public void putDepartment(Integer departmentId, String departmentName) {
if (departmentMapper.updateById(new Department(departmentId, departmentName)) < 1) {
throw new LocalRunTimeException(ErrorEnum.COMMON_ERROR, "update failed");
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/sast/evento/service/impl/EventServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sast.evento.common.enums.ActionState;
Expand Down Expand Up @@ -108,6 +110,7 @@ public List<EventModel> getNewest() {

// 获取活动列表(分页)
@Override
@Cacheable(value = "event", key = "#page + #size")
public PageModel<EventModel> getEvents(Integer page, Integer size) {
if (page == null || page < 0 || size == null || size < 0) {
throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR);
Expand Down Expand Up @@ -147,6 +150,7 @@ public List<EventModel> getSubscribed(String userId) {

@Transactional(rollbackFor = Exception.class)
@Override
@CacheEvict(value = "event")
public Integer addEvent(EventModel eventModel, String userId) {
Event event = new Event(eventModel);
/* 检测必需参数是否存在 */
Expand Down Expand Up @@ -204,6 +208,7 @@ public Integer addEvent(EventModel eventModel, String userId) {

@Transactional(rollbackFor = Exception.class)
@Override
@CacheEvict(value = "event")
public Boolean deleteEvent(Integer eventId) {
if (eventId == null) {
throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR);
Expand All @@ -223,6 +228,7 @@ public Boolean deleteEvent(Integer eventId) {

@Transactional(rollbackFor = Exception.class)
@Override
@CacheEvict(value = "event")
public Boolean updateEvent(EventModel eventModel) {
Event event = new Event(eventModel);

Expand Down Expand Up @@ -313,6 +319,7 @@ public Boolean updateEvent(EventModel eventModel) {
}

@Override
@CacheEvict(value = "event")
public void updateEvent(Event event) {
UpdateWrapper<Event> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", event.getId());
Expand All @@ -321,6 +328,7 @@ public void updateEvent(Event event) {


@Override
@CacheEvict(value = "event")
public Boolean cancelEvent(Integer eventId) {
if (eventId == null) {
throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import sast.evento.common.enums.ErrorEnum;
import sast.evento.entitiy.EventType;
Expand Down Expand Up @@ -51,6 +52,7 @@ public List<EventType> getAllEventType() {
}

@Override
@CacheEvict(value = "event")
public Boolean editEventType(EventType eventType) {
UpdateWrapper<EventType> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", eventType.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import sast.evento.common.enums.ErrorEnum;
import sast.evento.entitiy.Location;
Expand Down Expand Up @@ -61,6 +62,7 @@ public Boolean deleteLocation(Integer id) {
}

@Override
@CacheEvict(value = "event")
public Boolean updateLocation(Location location) {
if (location == null) {
throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import fun.feellmoose.enums.Organization;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import sast.evento.common.enums.ActionState;
Expand All @@ -15,7 +16,6 @@
import sast.evento.model.treeDataNodeDTO.TreeDataNode;
import sast.evento.service.PermissionService;
import sast.evento.service.PermissionServiceCacheAble;
import sast.sastlink.sdk.enums.Organization;

import java.util.*;
import java.util.stream.Collectors;
Expand Down

0 comments on commit a76fbb9

Please sign in to comment.