金币系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.6 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. package com.example.demo.serviceImpl;
  2. import com.example.demo.domain.entity.Activity;
  3. import com.example.demo.mapper.ActivityMapper;
  4. import com.example.demo.sevice.ActivityService;
  5. import com.github.pagehelper.PageHelper;
  6. import lombok.RequiredArgsConstructor;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.cache.annotation.CacheConfig;
  9. import org.springframework.cache.annotation.CacheEvict;
  10. import org.springframework.cache.annotation.Cacheable;
  11. import org.springframework.stereotype.Service;
  12. import com.github.pagehelper.PageInfo;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import java.util.Date;
  15. import java.util.List;
  16. @Service
  17. @Transactional
  18. @RequiredArgsConstructor
  19. @CacheConfig(cacheNames = "activity")
  20. public class ActivityServiceImpl implements ActivityService {
  21. @Autowired
  22. ActivityMapper activityMapper;
  23. @Override
  24. @CacheEvict(value = {"activity"}, allEntries = true)
  25. public int add(Activity activity) {
  26. return activityMapper.add(activity);
  27. }
  28. @CacheEvict(value = "activity",allEntries = true)
  29. @Override
  30. public int edit(Activity activity) {
  31. activity.setActivityFlag(0);
  32. return activityMapper.edit(activity);
  33. }
  34. @Override
  35. public List<Activity> search(Activity activity) {
  36. return activityMapper.select(activity);
  37. }
  38. @Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #activity.hashCode() ")
  39. @Override
  40. public PageInfo<Activity> searchForPage(Integer pageNum, Integer pageSize, Activity activity) {
  41. // PageHelper.startPage(pageNum, pageSize);
  42. // List<Activity> list = activityMapper.select(activity);
  43. // return new PageInfo<>(list);
  44. PageHelper.startPage(pageNum, pageSize);
  45. List<Activity> list = activityMapper.select(activity);
  46. Date nowDate = new Date();
  47. list.forEach(activity1 -> {
  48. // 假设 getStartTime() 和 getEndTime() 返回的是 java.util.Date 类型
  49. Date startTime = activity1.getStartTime();
  50. Date endTime = activity1.getEndTime();
  51. // 使用 Date 类的 before 和 after 方法进行比较
  52. if (nowDate.before(startTime)) {
  53. activity1.setStatus(0); // 设置状态为 0
  54. } else if (nowDate.after(endTime)) {
  55. activity1.setStatus(2); // 设置状态为 2
  56. } else {
  57. activity1.setStatus(1); // 设置状态为 1
  58. }
  59. // 保存修改后的对象
  60. activityMapper.edit(activity1);
  61. });
  62. return new PageInfo<>(list);
  63. }
  64. }
  65. // @Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #activity.hashCode() ")
  66. // @Override
  67. // public PageInfo<Activity> searchForPage(Integer pageNum, Integer pageSize, Activity activity) {
  68. // PageHelper.startPage(pageNum, pageSize);
  69. // List<Activity> list = activityMapper.select(activity);
  70. // LocalDateTime nowDate = LocalDateTime.now();
  71. //
  72. // for (Activity activity1 : list) {
  73. // Date startTime = activity1.getStartTime();
  74. // Date endTime = activity1.getEndTime();
  75. //
  76. // if (nowDate.isBefore(startTime)) {
  77. // activity1.setStatus(0); // 设置状态为 0
  78. // } else if (nowDate.isAfter(endTime)) {
  79. // activity1.setStatus(2); // 设置状态为 2
  80. // } else {
  81. // activity1.setStatus(1); // 设置状态为 1
  82. // }
  83. //
  84. // // 保存修改后的对象
  85. // activityMapper.edit(activity1);
  86. // }
  87. //
  88. // // 返回分页信息
  89. // return new PageInfo<>(list);
  90. // }
  91. //}