Antiloveg il y a 8 ans
Parent
commit
0a4f396775

+ 28 - 9
src/main/java/com/goafanti/admin/controller/AdminActivityApiController.java

@@ -20,6 +20,7 @@ import com.goafanti.activity.service.ActivityService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.enums.ActivityCacheKey;
 import com.goafanti.common.enums.ActivityFields;
 import com.goafanti.common.enums.AttachmentType;
 import com.goafanti.common.model.Activity;
@@ -33,9 +34,9 @@ import com.goafanti.core.mybatis.JDBCIdGenerator;
 @RequestMapping(value = "/api/admin/activity")
 public class AdminActivityApiController extends BaseApiController {
 	@Resource
-	private ActivityService activityService;
+	private ActivityService	activityService;
 	@Autowired
-	JDBCIdGenerator	idGenerator;
+	JDBCIdGenerator			idGenerator;
 
 	/**
 	 * 活动列表
@@ -91,27 +92,27 @@ public class AdminActivityApiController extends BaseApiController {
 					ActivityFields.getFieldDesc(bindingResult.getFieldError().getField())));
 			return res;
 		}
-		
+
 		if (StringUtils.isBlank(ia.getId())) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "活动ID"));
 			return res;
 		}
-		
+
 		res = disposeInputActivity(res, ia, startTimeFormattedDate);
 		if (!res.getError().isEmpty()) {
 			return res;
 		}
-		
+
 		activityService.update((Activity) res.getData(), startTimeFormattedDate, endTimeFormattedDate,
 				enrollDeadlineFormattedDate, Long.parseLong(ia.getId()));
 		return res;
 	}
-	
+
 	/**
 	 * 详情
 	 */
 	@RequestMapping(value = "/detail", method = RequestMethod.GET)
-	public Result detail(Long id){
+	public Result detail(Long id) {
 		Result res = new Result();
 		if (null == id) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "活动Id"));
@@ -120,7 +121,7 @@ public class AdminActivityApiController extends BaseApiController {
 		res.setData(activityService.findActivityDetail(id));
 		return res;
 	}
-	
+
 	/**
 	 * 删除
 	 */
@@ -134,7 +135,7 @@ public class AdminActivityApiController extends BaseApiController {
 		}
 		return res;
 	}
-	
+
 	/**
 	 * 活动图片上传
 	 */
@@ -153,6 +154,24 @@ public class AdminActivityApiController extends BaseApiController {
 		return res;
 	}
 
+	/**
+	 * 清除缓存
+	 */
+	@RequestMapping(value = "/cleanCache", method = RequestMethod.POST)
+	public Result cleanCache(String cacheKey) {
+		Result res = new Result();
+		if (StringUtils.isBlank(cacheKey)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "缓存标记"));
+			return res;
+		}
+		if (ActivityCacheKey.ACTIVITY_PORTAL_LIST_CACHE_KEY.getCode().equals(cacheKey)) {
+			activityService.cleanActivityPortalList(); // 清除门户端科技活动列表缓存
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "缓存标记"));
+		}
+		return res;
+	}
+
 	private Result disposeInputActivity(Result res, InputActivity ia, String startTimeFormattedDate) {
 		if (StringUtils.isBlank(ia.getName())) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "标题"));

+ 27 - 4
src/main/java/com/goafanti/admin/controller/AdminLectureApiController.java

@@ -19,6 +19,7 @@ import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
 import com.goafanti.common.enums.AttachmentType;
+import com.goafanti.common.enums.LectureCacheKey;
 import com.goafanti.common.enums.LectureDynamicType;
 import com.goafanti.common.enums.LectureFields;
 import com.goafanti.common.enums.LectureHotType;
@@ -59,7 +60,7 @@ public class AdminLectureApiController extends BaseApiController {
 	@RequestMapping(value = "/dynamic", method = RequestMethod.GET)
 	public Result dynamic() {
 		Result res = new Result();
-		res.setData(lectureService.listDynamic(AFTConstants.LECTURE_DYNAMIC_LIST_CACHE_KEY));
+		res.setData(lectureService.listAdminDynamic());
 		return res;
 	}
 
@@ -132,9 +133,9 @@ public class AdminLectureApiController extends BaseApiController {
 		Lecture l = new Lecture();
 		BeanUtils.copyProperties(il, l);
 		lectureService.update(l, lectureTimeFormattedDate, endTimeFormattedDate);
-		lectureService.clearBigShotLectureList(AFTConstants.BIG_SHOT_LECTURE_CACHE_KEY); //大咖说页面缓存
-		lectureService.clearLectureDynamicList(AFTConstants.LECTURE_DYNAMIC_LIST_CACHE_KEY); //科技明星页面缓存
-		lectureService.clearLectureList(AFTConstants.LECTURE_LIST_CACHE_KEY); //科技讲堂页面缓存
+		lectureService.clearBigShotLectureList(AFTConstants.BIG_SHOT_LECTURE_CACHE_KEY); // 大咖说页面缓存
+		lectureService.clearLectureDynamicList(AFTConstants.LECTURE_DYNAMIC_LIST_CACHE_KEY); // 科技明星页面缓存
+		lectureService.clearLectureList(AFTConstants.LECTURE_LIST_CACHE_KEY); // 科技讲堂页面缓存
 		return res;
 	}
 
@@ -190,6 +191,28 @@ public class AdminLectureApiController extends BaseApiController {
 		}
 		return res;
 	}
+	
+	/**
+	 * 清除缓存
+	 */
+	@RequestMapping(value = "/cleanCache", method = RequestMethod.POST)
+	public Result cleanCache(String cacheKey) {
+		Result res = new Result();
+		if (StringUtils.isBlank(cacheKey)){
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "缓存标记"));
+			return res;
+		}
+		if (LectureCacheKey.BIG_SHOT_LECTURE_CACHE_KEY.getCode().equals(cacheKey)){
+			lectureService.clearBigShotLectureList(AFTConstants.BIG_SHOT_LECTURE_CACHE_KEY); // 清除大咖说页面缓存
+		} else if (LectureCacheKey.LECTURE_DYNAMIC_LIST_CACHE_KEY.getCode().equals(cacheKey)){
+			lectureService.clearLectureDynamicList(AFTConstants.LECTURE_DYNAMIC_LIST_CACHE_KEY); // 清除科技明星页面缓存
+		} else if (LectureCacheKey.LECTURE_LIST_CACHE_KEY.getCode().equals(cacheKey)){
+			lectureService.clearLectureList(AFTConstants.LECTURE_LIST_CACHE_KEY); // 清除科技讲堂页面缓存
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "缓存标记"));
+		}
+		return res;
+	}
 
 	private Result disposeLecture(Result res, InputLecture il, String lectureTimeFormattedDate,
 			String endTimeFormattedDate) {

+ 21 - 0
src/main/java/com/goafanti/admin/controller/AdminNewsApiController.java

@@ -21,6 +21,7 @@ import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
 import com.goafanti.common.enums.AttachmentType;
+import com.goafanti.common.enums.NewsCacheKey;
 import com.goafanti.common.model.News;
 import com.goafanti.common.utils.DateUtils;
 import com.goafanti.common.utils.StringUtils;
@@ -153,6 +154,26 @@ public class AdminNewsApiController extends BaseApiController {
 		return res;
 	}
 
+	/**
+	 * 清除缓存
+	 */
+	@RequestMapping(value = "/cleanCache", method = RequestMethod.POST)
+	public Result cleanCache(String cacheKey) {
+		Result res = new Result();
+		if (StringUtils.isBlank(cacheKey)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "缓存标记"));
+			return res;
+		}
+		if (NewsCacheKey.NEWS_LIST_CACHE_KEY.getCode().equals(cacheKey)) {
+			newsService.cleanList(); // 清除策源地页面新闻列表缓存
+		} else if (NewsCacheKey.NEWS_PORTAL_LIST_CACHE_KEY.getCode().equals(cacheKey)) {
+			newsService.cleanPortalList(); // 清除新闻列表页列表缓存
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "缓存标记"));
+		}
+		return res;
+	}
+
 	private Result disposeInputNews(Result res, InputNews news, String createTimeFormattedDate) {
 		if (StringUtils.isBlank(news.getTitle())) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新闻标题"));

+ 19 - 0
src/main/java/com/goafanti/admin/controller/AdminStarApiController.java

@@ -14,6 +14,7 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.enums.StarCacheKey;
 import com.goafanti.common.enums.StarType;
 import com.goafanti.common.model.Star;
 import com.goafanti.common.utils.StringUtils;
@@ -123,4 +124,22 @@ public class AdminStarApiController extends BaseApiController {
 		return res;
 	}
 	
+	/**
+	 * 清除缓存
+	 */
+	@RequestMapping(value = "/cleanCache", method = RequestMethod.POST)
+	public Result cleanCache(String cacheKey) {
+		Result res = new Result();
+		if (StringUtils.isBlank(cacheKey)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "缓存标记"));
+			return res;
+		}
+		if (StarCacheKey.BIG_SHOT_STAR_CACHE_KEY.getCode().equals(cacheKey)) {
+			starService.clearBigShotStarList(AFTConstants.BIG_SHOT_STAR_CACHE_KEY); // 清除大咖说科技明星列表缓存
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "缓存标记"));
+		}
+		return res;
+	}
+	
 }

+ 49 - 0
src/main/java/com/goafanti/common/enums/ActivityCacheKey.java

@@ -0,0 +1,49 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum ActivityCacheKey {
+	ACTIVITY_PORTAL_LIST_CACHE_KEY("activity_portal_list_cache_key", "门户端科技活动列表缓存"),
+	
+	OTHER("", "未知参数");
+	
+	private String	code;
+	private String	desc;
+	
+	private static Map<String, ActivityCacheKey> status = new HashMap<String, ActivityCacheKey>();
+	
+	private ActivityCacheKey(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+	
+	static {
+		for (ActivityCacheKey value : ActivityCacheKey.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+	
+	public static ActivityCacheKey getField(String code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+	
+	public static String getFieldDesc(String code) {
+		return getField(code).getDesc();
+	}
+
+	public static boolean containsType(String code) {
+		return status.containsKey(code);
+	}
+	
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+}

+ 51 - 0
src/main/java/com/goafanti/common/enums/LectureCacheKey.java

@@ -0,0 +1,51 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum LectureCacheKey {
+	BIG_SHOT_LECTURE_CACHE_KEY("big_shot_lecture_cache_key", "大咖说页面缓存"),
+	LECTURE_DYNAMIC_LIST_CACHE_KEY("lecture_dynamic_list_cache_key", "科技明星页面缓存"),
+	LECTURE_LIST_CACHE_KEY("lecture_list_cache_key", "科技讲堂页面缓存"),
+	
+	OTHER("", "未知参数");
+	
+	private String	code;
+	private String	desc;
+	
+	private static Map<String, LectureCacheKey> status = new HashMap<String, LectureCacheKey>();
+	
+	private LectureCacheKey(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+	
+	static {
+		for (LectureCacheKey value : LectureCacheKey.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+	
+	public static LectureCacheKey getField(String code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+	
+	public static String getFieldDesc(String code) {
+		return getField(code).getDesc();
+	}
+
+	public static boolean containsType(String code) {
+		return status.containsKey(code);
+	}
+	
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+}

+ 50 - 0
src/main/java/com/goafanti/common/enums/NewsCacheKey.java

@@ -0,0 +1,50 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum NewsCacheKey {
+	NEWS_LIST_CACHE_KEY("news_list_cache_key", "策源地新闻列表缓存"),
+	NEWS_PORTAL_LIST_CACHE_KEY("news_portal_list_cache_key", "新闻列表页面缓存"),
+	
+	OTHER("", "未知参数");
+	
+	private String	code;
+	private String	desc;
+	
+	private static Map<String, NewsCacheKey> status = new HashMap<String, NewsCacheKey>();
+	
+	private NewsCacheKey(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+	
+	static {
+		for (NewsCacheKey value : NewsCacheKey.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+	
+	public static NewsCacheKey getField(String code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+	
+	public static String getFieldDesc(String code) {
+		return getField(code).getDesc();
+	}
+
+	public static boolean containsType(String code) {
+		return status.containsKey(code);
+	}
+	
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+}

+ 49 - 0
src/main/java/com/goafanti/common/enums/StarCacheKey.java

@@ -0,0 +1,49 @@
+package com.goafanti.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum StarCacheKey {
+	BIG_SHOT_STAR_CACHE_KEY("big_shot_star_cache_key", "大咖说科技明星列表缓存"),
+	
+	OTHER("", "未知参数");
+	
+	private String	code;
+	private String	desc;
+	
+	private static Map<String, StarCacheKey> status = new HashMap<String, StarCacheKey>();
+	
+	private StarCacheKey(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+	
+	static {
+		for (StarCacheKey value : StarCacheKey.values()) {
+			status.put(value.getCode(), value);
+		}
+	}
+	
+	public static StarCacheKey getField(String code) {
+		if (containsType(code)) {
+			return status.get(code);
+		}
+		return OTHER;
+	}
+	
+	public static String getFieldDesc(String code) {
+		return getField(code).getDesc();
+	}
+
+	public static boolean containsType(String code) {
+		return status.containsKey(code);
+	}
+	
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+}

+ 2 - 0
src/main/java/com/goafanti/lecture/service/LectureService.java

@@ -38,4 +38,6 @@ public interface LectureService {
 
 	void clearLectureList(Integer lectureListCacheKey);
 
+	List<LectureListBo> listAdminDynamic();
+
 }

+ 5 - 0
src/main/java/com/goafanti/lecture/service/impl/LectureServiceImpl.java

@@ -166,6 +166,11 @@ public class LectureServiceImpl extends BaseMybatisDao<LectureMapper> implements
 		
 	}
 
+	@Override
+	public List<LectureListBo> listAdminDynamic() {
+		return lectureMapper.listDynamic();
+	}
+