Commit 7fd2781b authored by 赵啸非's avatar 赵啸非

添加主题缓存

parent f92de300
package com.mortals.xhx.module.site.web; package com.mortals.xhx.module.site.web;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
...@@ -19,8 +20,10 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -19,8 +20,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.site.model.SiteThemeEntity; import com.mortals.xhx.module.site.model.SiteThemeEntity;
import com.mortals.xhx.module.site.service.SiteThemeService; import com.mortals.xhx.module.site.service.SiteThemeService;
...@@ -29,26 +32,28 @@ import com.mortals.framework.util.StringUtils; ...@@ -29,26 +32,28 @@ import com.mortals.framework.util.StringUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*; import static com.mortals.framework.ap.SysConstains.*;
/** /**
* * 主题
* 主题 *
* * @author zxfei
* @author zxfei * @date 2022-11-23
* @date 2022-11-23 */
*/
@RestController @RestController
@RequestMapping("site/theme") @RequestMapping("site/theme")
public class SiteThemeController extends BaseCRUDJsonBodyMappingController<SiteThemeService,SiteThemeEntity,Long> { public class SiteThemeController extends BaseCRUDJsonBodyMappingController<SiteThemeService, SiteThemeEntity, Long> {
@Autowired @Autowired
private ICacheService cacheService; private ICacheService cacheService;
public SiteThemeController(){ public SiteThemeController() {
super.setModuleDesc( "主题"); super.setModuleDesc("主题");
} }
@Override @Override
...@@ -64,17 +69,34 @@ public class SiteThemeController extends BaseCRUDJsonBodyMappingController<SiteT ...@@ -64,17 +69,34 @@ public class SiteThemeController extends BaseCRUDJsonBodyMappingController<SiteT
@UnAuth @UnAuth
public String getThemeCacheBySite(@RequestBody SiteThemeEntity site) { public String getThemeCacheBySite(@RequestBody SiteThemeEntity site) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
List<SiteThemeEntity> siteThemeList = new ArrayList<>();
String busiDesc = "根据站点id获取当前站点主题列表" + this.getModuleDesc(); String busiDesc = "根据站点id获取当前站点主题列表" + this.getModuleDesc();
try { try {
if(ObjectUtils.isEmpty(site.getSiteId())) throw new AppException("站点id不能为空!"); if (ObjectUtils.isEmpty(site.getSiteId())) throw new AppException("站点id不能为空!");
if(ObjectUtils.isEmpty(site.getUserType())) throw new AppException("服务类型不能为空!"); //if(ObjectUtils.isEmpty(site.getUserType())) throw new AppException("服务类型不能为空!");
String jsonstr = cacheService.hget(RedisCacheKeys.getSiteUserTypeThemeCodeKey() + site.getSiteId(), site.getUserType(), String.class); if (ObjectUtils.isEmpty(site.getUserType())) {
List<SiteThemeEntity> siteThemeEntities = JSON.parseObject(jsonstr, new TypeReference<List<SiteThemeEntity>>() {}); //合并多个
if(ObjectUtils.isEmpty(siteThemeEntities)){ for (int i = 1; i <= 3; i++) {
jsonObject.put(KEY_RESULT_DATA, new ArrayList<SiteThemeEntity>()); String jsonstr = cacheService.hget(RedisCacheKeys.getSiteUserTypeThemeCodeKey() + site.getSiteId(), String.valueOf(i), String.class);
}else{ if (!ObjectUtils.isEmpty(jsonstr)) {
jsonObject.put(KEY_RESULT_DATA, siteThemeEntities); List<SiteThemeEntity> siteThemeEntities = JSON.parseObject(jsonstr, new TypeReference<List<SiteThemeEntity>>() {
});
if (!ObjectUtils.isEmpty(siteThemeEntities)) {
siteThemeList.addAll(siteThemeEntities);
}
}
}
} else {
String jsonstr = cacheService.hget(RedisCacheKeys.getSiteUserTypeThemeCodeKey() + site.getSiteId(), site.getUserType(), String.class);
if (!ObjectUtils.isEmpty(jsonstr)) {
List<SiteThemeEntity> siteThemeEntities = JSON.parseObject(jsonstr, new TypeReference<List<SiteThemeEntity>>() {
});
if (!ObjectUtils.isEmpty(siteThemeEntities)) {
siteThemeList.addAll(siteThemeEntities);
}
}
} }
jsonObject.put(KEY_RESULT_DATA, siteThemeList);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
jsonObject.put(KEY_RESULT_MSG, "根据站点id获取当前站点主题列表成功!"); jsonObject.put(KEY_RESULT_MSG, "根据站点id获取当前站点主题列表成功!");
recordSysLog(request, busiDesc + " 【成功】"); recordSysLog(request, busiDesc + " 【成功】");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment