deason 1 năm trước cách đây
mục cha
commit
165591f6b6

+ 5 - 5
src/main/java/com/qmth/exam/reserve/cache/impl/CategoryCacheService.java

@@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.qmth.exam.reserve.bean.category.CategoryCacheBean;
 import com.qmth.exam.reserve.cache.CacheConstants;
 import com.qmth.exam.reserve.cache.RedisClient;
+import com.qmth.exam.reserve.dao.CategoryDao;
 import com.qmth.exam.reserve.entity.CategoryEntity;
-import com.qmth.exam.reserve.service.CategoryService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +22,7 @@ public class CategoryCacheService implements CacheConstants {
     private RedisClient redisClient;
 
     @Autowired
-    private CategoryService categoryService;
+    private CategoryDao categoryDao;
 
     /**
      * 获取某个分类缓存
@@ -45,8 +45,8 @@ public class CategoryCacheService implements CacheConstants {
         return value;
     }
 
-    public void clearCategoryByIdCache(Long orgId) {
-        String cacheKey = String.format(CACHE_CATEGORY, orgId);
+    public void clearCategoryByIdCache(Long categoryId) {
+        String cacheKey = String.format(CACHE_CATEGORY, categoryId);
         redisClient.delete(cacheKey);
         log.warn("清理缓存!cacheKey:{}", cacheKey);
     }
@@ -56,7 +56,7 @@ public class CategoryCacheService implements CacheConstants {
         wrapper.select(CategoryEntity::getId, CategoryEntity::getCode, CategoryEntity::getName,
                 CategoryEntity::getLevel, CategoryEntity::getEnable, CategoryEntity::getParentId);
         wrapper.eq(CategoryEntity::getId, categoryId);
-        CategoryEntity category = categoryService.getOne(wrapper);
+        CategoryEntity category = categoryDao.selectOne(wrapper);
         if (category == null) {
             return null;
         }

+ 12 - 7
src/main/java/com/qmth/exam/reserve/service/impl/CategoryServiceImpl.java

@@ -6,12 +6,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.collection.PageResult;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
+import com.qmth.exam.reserve.bean.category.CategoryCacheBean;
 import com.qmth.exam.reserve.bean.category.CategoryInfo;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
 import com.qmth.exam.reserve.bean.teaching.TeachingReq;
 import com.qmth.exam.reserve.bean.teaching.TeachingVO;
 import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
+import com.qmth.exam.reserve.cache.impl.CategoryCacheService;
 import com.qmth.exam.reserve.dao.CategoryDao;
 import com.qmth.exam.reserve.entity.CategoryEntity;
 import com.qmth.exam.reserve.enums.CategoryLevel;
@@ -31,6 +33,9 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
     @Autowired
     private ApplyTaskCacheService applyTaskCacheService;
 
+    @Autowired
+    private CategoryCacheService categoryCacheService;
+
     @Override
     public List<CategoryVO> listTeaching(LoginUser user) {
         QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
@@ -78,16 +83,16 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
         if (curApplyTask.getSelfApplyEndTime() > System.currentTimeMillis()) {
             // 自主预约截止时间 之前,只能预约本教学点下的考点
 
-            CategoryEntity curEntity = this.getById(student.getCategoryId());
-            if (curEntity == null) {
+            CategoryCacheBean curCategory = categoryCacheService.getCategoryById(student.getCategoryId());
+            if (curCategory == null) {
                 return list;
             }
 
             CategoryInfo curInfo = new CategoryInfo();
-            curInfo.setId(curEntity.getId());
-            curInfo.setName(curEntity.getName());
-            curInfo.setLevel(curEntity.getLevel());
-            curInfo.setParentId(curEntity.getParentId());
+            curInfo.setId(curCategory.getId());
+            curInfo.setName(curCategory.getName());
+            curInfo.setLevel(curCategory.getLevel());
+            curInfo.setParentId(curCategory.getParentId());
             curInfo.setSubNodes(new ArrayList<>());
 
             // 根节点
@@ -154,7 +159,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
             return cur;
         }
 
-        CategoryEntity parent = this.getById(cur.getParentId());
+        CategoryCacheBean parent = categoryCacheService.getCategoryById(cur.getParentId());
         if (parent == null) {
             return cur;
         }

+ 4 - 7
src/main/java/com/qmth/exam/reserve/service/impl/StudentServiceImpl.java

@@ -4,12 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.category.CategoryCacheBean;
 import com.qmth.exam.reserve.bean.student.StudentInfo;
 import com.qmth.exam.reserve.bean.student.WechatBindReq;
+import com.qmth.exam.reserve.cache.impl.CategoryCacheService;
 import com.qmth.exam.reserve.dao.StudentDao;
-import com.qmth.exam.reserve.entity.CategoryEntity;
 import com.qmth.exam.reserve.entity.StudentEntity;
-import com.qmth.exam.reserve.service.CategoryService;
 import com.qmth.exam.reserve.service.StudentService;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -26,7 +26,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
     private static final Logger log = LoggerFactory.getLogger(StudentServiceImpl.class);
 
     @Autowired
-    private CategoryService categoryService;
+    private CategoryCacheService categoryCacheService;
 
     @Override
     public StudentEntity findByStudentCode(Long applyTaskId, String studentCode) {
@@ -103,10 +103,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
         info.setApplyTaskId(entity.getApplyTaskId());
         info.setCategoryId(entity.getCategoryId());
 
-        LambdaQueryWrapper<CategoryEntity> wrapper = new LambdaQueryWrapper<>();
-        wrapper.select(CategoryEntity::getName);// 只查询name等字段
-        wrapper.eq(CategoryEntity::getId, entity.getCategoryId());
-        CategoryEntity category = categoryService.getOne(wrapper);
+        CategoryCacheBean category = categoryCacheService.getCategoryById(entity.getCategoryId());
         if (category != null) {
             info.setCategoryName(category.getName());
         }