修正快捷链接错误

修正部分IdUtils.validate调用结果判断错误
This commit is contained in:
liweiyi 2025-02-12 17:07:54 +08:00
parent 3055676cf8
commit 0e7b319498
22 changed files with 310 additions and 282 deletions

View File

@ -30,6 +30,8 @@ import com.chestnut.contentcore.fixed.dict.ContentAttribute;
import com.chestnut.contentcore.fixed.dict.ContentStatus; import com.chestnut.contentcore.fixed.dict.ContentStatus;
import com.chestnut.contentcore.service.ICatalogService; import com.chestnut.contentcore.service.ICatalogService;
import com.chestnut.contentcore.service.IContentService; import com.chestnut.contentcore.service.IContentService;
import com.chestnut.contentcore.template.tag.CmsCatalogTag;
import com.chestnut.contentcore.template.tag.CmsContentTag;
import com.chestnut.contentcore.util.CatalogUtils; import com.chestnut.contentcore.util.CatalogUtils;
import com.chestnut.contentcore.util.InternalUrlUtils; import com.chestnut.contentcore.util.InternalUrlUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -72,21 +74,21 @@ public class ArticleApiController extends BaseRestController {
@RequestParam(value = "preview", required = false, defaultValue = "false") Boolean preview, @RequestParam(value = "preview", required = false, defaultValue = "false") Boolean preview,
@RequestParam(value = "text", required = false, defaultValue = "false") Boolean text @RequestParam(value = "text", required = false, defaultValue = "false") Boolean text
) { ) {
if (!"Root".equalsIgnoreCase(level) && !IdUtils.validate(catalogId)) { if (!CmsCatalogTag.CatalogTagLevel.isRoot(level) && !IdUtils.validate(catalogId)) {
return R.fail("The parameter cid is required where lv is `Root`."); return R.fail("The parameter cid is required where lv is `Root`.");
} }
LambdaQueryWrapper<CmsContent> q = new LambdaQueryWrapper<>(); LambdaQueryWrapper<CmsContent> q = new LambdaQueryWrapper<>();
q.eq(CmsContent::getSiteId, siteId).eq(CmsContent::getStatus, ContentStatus.PUBLISHED); q.eq(CmsContent::getSiteId, siteId).eq(CmsContent::getStatus, ContentStatus.PUBLISHED);
if (!"Root".equalsIgnoreCase(level)) { if (!CmsCatalogTag.CatalogTagLevel.isRoot(level)) {
CmsCatalog catalog = this.catalogService.getCatalog(catalogId); CmsCatalog catalog = this.catalogService.getCatalog(catalogId);
if (Objects.isNull(catalog)) { if (Objects.isNull(catalog)) {
return R.fail("Catalog not found: " + catalogId); return R.fail("Catalog not found: " + catalogId);
} }
if ("Current".equalsIgnoreCase(level)) { if (CmsCatalogTag.CatalogTagLevel.isCurrent(level)) {
q.eq(CmsContent::getCatalogId, catalog.getCatalogId()); q.eq(CmsContent::getCatalogId, catalog.getCatalogId());
} else if ("Child".equalsIgnoreCase(level)) { } else if (CmsCatalogTag.CatalogTagLevel.isChild(level)) {
q.likeRight(CmsContent::getCatalogAncestors, catalog.getAncestors() + CatalogUtils.ANCESTORS_SPLITER); q.likeRight(CmsContent::getCatalogAncestors, catalog.getAncestors() + CatalogUtils.ANCESTORS_SPLITER);
} else if ("CurrentAndChild".equalsIgnoreCase(level)) { } else if (CmsCatalogTag.CatalogTagLevel.isCurrentAndChild(level)) {
q.likeRight(CmsContent::getCatalogAncestors, catalog.getAncestors()); q.likeRight(CmsContent::getCatalogAncestors, catalog.getAncestors());
} }
} }
@ -102,7 +104,7 @@ public class ArticleApiController extends BaseRestController {
q.apply(bit > 0, "attributes&{0}<>{1}", attrTotal, bit); q.apply(bit > 0, "attributes&{0}<>{1}", attrTotal, bit);
} }
} }
if ("Recent".equalsIgnoreCase(sortType)) { if (CmsContentTag.SortTagAttr.isRecent(sortType)) {
q.orderByDesc(CmsContent::getPublishDate); q.orderByDesc(CmsContent::getPublishDate);
} else { } else {
q.orderByDesc(Arrays.asList(CmsContent::getTopFlag, CmsContent::getSortFlag)); q.orderByDesc(Arrays.asList(CmsContent::getTopFlag, CmsContent::getSortFlag));

View File

@ -39,7 +39,7 @@ import java.util.List;
public class CmsArticleDetailDAO extends BackupServiceImpl<CmsArticleDetailMapper, CmsArticleDetail, BCmsArticleDetailMapper, BCmsArticleDetail> { public class CmsArticleDetailDAO extends BackupServiceImpl<CmsArticleDetailMapper, CmsArticleDetail, BCmsArticleDetailMapper, BCmsArticleDetail> {
public long countBySiteId(Long siteId) { public long countBySiteId(Long siteId) {
if (IdUtils.validate(siteId)) { if (!IdUtils.validate(siteId)) {
return 0; return 0;
} }
return this.count(new LambdaQueryWrapper<CmsArticleDetail>() return this.count(new LambdaQueryWrapper<CmsArticleDetail>()
@ -47,7 +47,7 @@ public class CmsArticleDetailDAO extends BackupServiceImpl<CmsArticleDetailMappe
} }
public Page<CmsArticleDetail> pageBySiteId(Page<CmsArticleDetail> page, Long siteId, List<SFunction<CmsArticleDetail, ?>> columns) { public Page<CmsArticleDetail> pageBySiteId(Page<CmsArticleDetail> page, Long siteId, List<SFunction<CmsArticleDetail, ?>> columns) {
if (IdUtils.validate(siteId)) { if (!IdUtils.validate(siteId)) {
return page; return page;
} }
LambdaQueryWrapper<CmsArticleDetail> q = new LambdaQueryWrapper<CmsArticleDetail>() LambdaQueryWrapper<CmsArticleDetail> q = new LambdaQueryWrapper<CmsArticleDetail>()
@ -57,7 +57,7 @@ public class CmsArticleDetailDAO extends BackupServiceImpl<CmsArticleDetailMappe
} }
public long countBackupBySiteId(Long siteId) { public long countBackupBySiteId(Long siteId) {
if (IdUtils.validate(siteId)) { if (!IdUtils.validate(siteId)) {
return 0; return 0;
} }
return this.getBackupMapper().selectCount(new LambdaQueryWrapper<BCmsArticleDetail>() return this.getBackupMapper().selectCount(new LambdaQueryWrapper<BCmsArticleDetail>()
@ -65,7 +65,7 @@ public class CmsArticleDetailDAO extends BackupServiceImpl<CmsArticleDetailMappe
} }
public Page<BCmsArticleDetail> pageBackupBySiteId(Page<BCmsArticleDetail> page, Long siteId, List<SFunction<BCmsArticleDetail, ?>> columns) { public Page<BCmsArticleDetail> pageBackupBySiteId(Page<BCmsArticleDetail> page, Long siteId, List<SFunction<BCmsArticleDetail, ?>> columns) {
if (IdUtils.validate(siteId)) { if (!IdUtils.validate(siteId)) {
return page; return page;
} }
return this.getBackupMapper().selectPage(page, new LambdaQueryWrapper<BCmsArticleDetail>() return this.getBackupMapper().selectPage(page, new LambdaQueryWrapper<BCmsArticleDetail>()

View File

@ -52,7 +52,7 @@ public class CmsContentDAO extends BackupServiceImpl<CmsContentMapper, CmsConten
} }
public long countBySiteId(Long siteId) { public long countBySiteId(Long siteId) {
if (IdUtils.validate(siteId)) { if (!IdUtils.validate(siteId)) {
return 0; return 0;
} }
return this.count(new LambdaQueryWrapper<CmsContent>() return this.count(new LambdaQueryWrapper<CmsContent>()
@ -60,7 +60,7 @@ public class CmsContentDAO extends BackupServiceImpl<CmsContentMapper, CmsConten
} }
public Page<CmsContent> pageBySiteId(Page<CmsContent> page, Long siteId, List<SFunction<CmsContent, ?>> columns) { public Page<CmsContent> pageBySiteId(Page<CmsContent> page, Long siteId, List<SFunction<CmsContent, ?>> columns) {
if (IdUtils.validate(siteId)) { if (!IdUtils.validate(siteId)) {
return page; return page;
} }
LambdaQueryWrapper<CmsContent> q = new LambdaQueryWrapper<CmsContent>() LambdaQueryWrapper<CmsContent> q = new LambdaQueryWrapper<CmsContent>()
@ -70,7 +70,7 @@ public class CmsContentDAO extends BackupServiceImpl<CmsContentMapper, CmsConten
} }
public long countBackupBySiteId(Long siteId) { public long countBackupBySiteId(Long siteId) {
if (IdUtils.validate(siteId)) { if (!IdUtils.validate(siteId)) {
return 0; return 0;
} }
return this.getBackupMapper().selectCount(new LambdaQueryWrapper<BCmsContent>() return this.getBackupMapper().selectCount(new LambdaQueryWrapper<BCmsContent>()
@ -78,7 +78,7 @@ public class CmsContentDAO extends BackupServiceImpl<CmsContentMapper, CmsConten
} }
public Page<BCmsContent> pageBackupBySiteId(Page<BCmsContent> page, Long siteId, List<SFunction<BCmsContent, ?>> columns) { public Page<BCmsContent> pageBackupBySiteId(Page<BCmsContent> page, Long siteId, List<SFunction<BCmsContent, ?>> columns) {
if (IdUtils.validate(siteId)) { if (!IdUtils.validate(siteId)) {
return page; return page;
} }
return this.getBackupMapper().selectPage(page, new LambdaQueryWrapper<BCmsContent>() return this.getBackupMapper().selectPage(page, new LambdaQueryWrapper<BCmsContent>()

View File

@ -137,7 +137,7 @@ public class CmsCatalogTag extends AbstractListTag {
return DESC; return DESC;
} }
private enum CatalogTagLevel { public enum CatalogTagLevel {
Root(ATTR_OPTION_LEVEL_ROOT), Root(ATTR_OPTION_LEVEL_ROOT),
Current(ATTR_OPTION_LEVEL_CURRENT), Current(ATTR_OPTION_LEVEL_CURRENT),
Child(ATTR_OPTION_LEVEL_CHILD), Child(ATTR_OPTION_LEVEL_CHILD),
@ -150,27 +150,27 @@ public class CmsCatalogTag extends AbstractListTag {
this.desc = desc; this.desc = desc;
} }
static boolean isRoot(String level) { public static boolean isRoot(String level) {
return Root.name().equalsIgnoreCase(level); return Root.name().equalsIgnoreCase(level);
} }
static boolean isCurrent(String level) { public static boolean isCurrent(String level) {
return Current.name().equalsIgnoreCase(level); return Current.name().equalsIgnoreCase(level);
} }
static boolean isChild(String level) { public static boolean isChild(String level) {
return Child.name().equalsIgnoreCase(level); return Child.name().equalsIgnoreCase(level);
} }
static boolean isCurrentAndChild(String level) { public static boolean isCurrentAndChild(String level) {
return CurrentAndChild.name().equalsIgnoreCase(level); return CurrentAndChild.name().equalsIgnoreCase(level);
} }
static boolean isSelf(String level) { public static boolean isSelf(String level) {
return Self.name().equalsIgnoreCase(level); return Self.name().equalsIgnoreCase(level);
} }
static List<TagAttrOption> toTagAttrOptions() { public static List<TagAttrOption> toTagAttrOptions() {
return List.of( return List.of(
new TagAttrOption(Root.name(), Root.desc), new TagAttrOption(Root.name(), Root.desc),
new TagAttrOption(Current.name(), Current.desc), new TagAttrOption(Current.name(), Current.desc),

View File

@ -63,7 +63,7 @@ public class CmsContentRelaTag extends AbstractListTag {
public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex) public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex)
throws TemplateException { throws TemplateException {
long contentId = MapUtils.getLongValue(attrs, ATTR_CONTENT_ID); long contentId = MapUtils.getLongValue(attrs, ATTR_CONTENT_ID);
if (IdUtils.validate(contentId)) { if (!IdUtils.validate(contentId)) {
throw new TemplateException("Invalid content id: " + contentId, env); throw new TemplateException("Invalid content id: " + contentId, env);
} }
TemplateContext context = FreeMarkerUtils.getTemplateContext(env); TemplateContext context = FreeMarkerUtils.getTemplateContext(env);

View File

@ -220,7 +220,7 @@ public class CmsContentTag extends AbstractListTag {
} }
} }
enum SortTagAttr { public enum SortTagAttr {
Recent(ATTR_OPTION_SORT_RECENT), Recent(ATTR_OPTION_SORT_RECENT),
Views(ATTR_OPTION_SORT_VIEWS), Views(ATTR_OPTION_SORT_VIEWS),
Default(ATTR_OPTION_SORT_DEFAULT); Default(ATTR_OPTION_SORT_DEFAULT);

View File

@ -68,7 +68,7 @@ public class CmsXModelDataTag extends AbstractTag {
public Map<String, TemplateModel> execute0(Environment env, Map<String, String> attrs) public Map<String, TemplateModel> execute0(Environment env, Map<String, String> attrs)
throws TemplateException { throws TemplateException {
long modelId = MapUtils.getLongValue(attrs, ATTR_MODEL_ID); long modelId = MapUtils.getLongValue(attrs, ATTR_MODEL_ID);
if (IdUtils.validate(modelId)) { if (!IdUtils.validate(modelId)) {
throw new InvalidTagAttrValueException(getTagName(), ATTR_MODEL_ID, String.valueOf(modelId), env); throw new InvalidTagAttrValueException(getTagName(), ATTR_MODEL_ID, String.valueOf(modelId), env);
} }
String dataType = MapUtils.getString(attrs, ATTR_DATA_TYPE); String dataType = MapUtils.getString(attrs, ATTR_DATA_TYPE);

View File

@ -63,7 +63,7 @@ public class CmsXModelFieldTag extends AbstractListTag {
@Override @Override
public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex) throws TemplateException { public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex) throws TemplateException {
long modelId = MapUtils.getLongValue(attrs, ATTR_MODEL_ID); long modelId = MapUtils.getLongValue(attrs, ATTR_MODEL_ID);
if (IdUtils.validate(modelId)) { if (!IdUtils.validate(modelId)) {
throw new InvalidTagAttrValueException(getTagName(), ATTR_MODEL_ID, String.valueOf(modelId), env); throw new InvalidTagAttrValueException(getTagName(), ATTR_MODEL_ID, String.valueOf(modelId), env);
} }
XModel xmodel = this.modelService.getById(modelId); XModel xmodel = this.modelService.getById(modelId);

View File

@ -67,7 +67,7 @@ public class CmsImageTag extends AbstractListTag {
public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex) public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex)
throws TemplateException { throws TemplateException {
long contentId = MapUtils.getLongValue(attrs, ATTR_CONTENT_ID, 0); long contentId = MapUtils.getLongValue(attrs, ATTR_CONTENT_ID, 0);
if (IdUtils.validate(contentId)) { if (!IdUtils.validate(contentId)) {
throw new InvalidTagAttrValueException(getTagName(), ATTR_CONTENT_ID, String.valueOf(contentId), env); throw new InvalidTagAttrValueException(getTagName(), ATTR_CONTENT_ID, String.valueOf(contentId), env);
} }
CmsContent c = this.contentService.dao().getById(contentId); CmsContent c = this.contentService.dao().getById(contentId);

View File

@ -67,7 +67,7 @@ public class CmsAudioTag extends AbstractListTag {
public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex) public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex)
throws TemplateException { throws TemplateException {
long contentId = MapUtils.getLongValue(attrs, ATTR_CONTENT_ID, 0); long contentId = MapUtils.getLongValue(attrs, ATTR_CONTENT_ID, 0);
if (IdUtils.validate(contentId)) { if (!IdUtils.validate(contentId)) {
throw new InvalidTagAttrValueException(getTagName(), ATTR_CONTENT_ID, String.valueOf(contentId), env); throw new InvalidTagAttrValueException(getTagName(), ATTR_CONTENT_ID, String.valueOf(contentId), env);
} }
CmsContent c = this.contentService.dao().getById(contentId); CmsContent c = this.contentService.dao().getById(contentId);

View File

@ -67,7 +67,7 @@ public class CmsVideoTag extends AbstractListTag {
public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex) public TagPageData prepareData(Environment env, Map<String, String> attrs, boolean page, int size, int pageIndex)
throws TemplateException { throws TemplateException {
long contentId = MapUtils.getLongValue(attrs, ATTR_CONTENT_ID, 0); long contentId = MapUtils.getLongValue(attrs, ATTR_CONTENT_ID, 0);
if (IdUtils.validate(contentId)) { if (!IdUtils.validate(contentId)) {
throw new InvalidTagAttrValueException(getTagName(), ATTR_CONTENT_ID, String.valueOf(contentId), env); throw new InvalidTagAttrValueException(getTagName(), ATTR_CONTENT_ID, String.valueOf(contentId), env);
} }
CmsContent c = this.contentService.dao().getById(contentId); CmsContent c = this.contentService.dao().getById(contentId);

View File

@ -85,7 +85,12 @@ public enum CommonErrorCode implements ErrorCode {
/** /**
* 任务{0}正在运行中 * 任务{0}正在运行中
*/ */
ASYNC_TASK_RUNNING; ASYNC_TASK_RUNNING,
/**
* 上传文件不能为空
*/
UPLOAD_FILE_EMPTY;
@Override @Override
public String value() { public String value() {

View File

@ -40,5 +40,5 @@ public @interface I18nField {
* 可使用占位符来获取当前对象其他字段属性值例如实体类的ID字段值可使用#{fieldName}大括号内是字段名会被替换为指定字段的值 * 可使用占位符来获取当前对象其他字段属性值例如实体类的ID字段值可使用#{fieldName}大括号内是字段名会被替换为指定字段的值
* </p> * </p>
*/ */
public String value() default StringUtils.EMPTY; String value() default StringUtils.EMPTY;
} }

View File

@ -83,7 +83,7 @@ public class IdUtils {
* @return * @return
*/ */
public static boolean validate(List<Long> ids, boolean removeInvalidId) { public static boolean validate(List<Long> ids, boolean removeInvalidId) {
if (ids == null || ids.size() == 0) { if (ids == null || ids.isEmpty()) {
return false; return false;
} }
for (Iterator<Long> iterator = ids.iterator(); iterator.hasNext();) { for (Iterator<Long> iterator = ids.iterator(); iterator.hasNext();) {
@ -96,7 +96,7 @@ public class IdUtils {
} }
} }
} }
return ids.size() > 0; return !ids.isEmpty();
} }
public static boolean validate(List<Long> ids) { public static boolean validate(List<Long> ids) {

View File

@ -15,5 +15,6 @@ ERRCODE.COMMON.FIXED_DICT_NOT_ALLOW_ADD=此系统固定字典类型不能添加
ERRCODE.COMMON.FIXED_CONFIG_DEL=系统固定配置参数[{0}]不能删除 ERRCODE.COMMON.FIXED_CONFIG_DEL=系统固定配置参数[{0}]不能删除
ERRCODE.COMMON.FIXED_CONFIG_UPDATE=系统固定配置参数[{0}]不能修改键名 ERRCODE.COMMON.FIXED_CONFIG_UPDATE=系统固定配置参数[{0}]不能修改键名
ERRCODE.COMMON.ASYNC_TASK_RUNNING=任务“{0}”正在运行中 ERRCODE.COMMON.ASYNC_TASK_RUNNING=任务“{0}”正在运行中
ERRCODE.COMMON.UPLOAD_FILE_EMPTY=上传文件不能为空
AsyncTask.SuccessMsg=任务执行成功 AsyncTask.SuccessMsg=任务执行成功

View File

@ -15,5 +15,6 @@ ERRCODE.COMMON.FIXED_DICT_NOT_ALLOW_ADD=The fixed dict not allow to add data ite
ERRCODE.COMMON.FIXED_CONFIG_DEL=The fixed config "{0}" cannot be delete. ERRCODE.COMMON.FIXED_CONFIG_DEL=The fixed config "{0}" cannot be delete.
ERRCODE.COMMON.FIXED_CONFIG_UPDATE=The fixed config "{0}" cannot modify key. ERRCODE.COMMON.FIXED_CONFIG_UPDATE=The fixed config "{0}" cannot modify key.
ERRCODE.COMMON.ASYNC_TASK_RUNNING=The task "{0}" is running. ERRCODE.COMMON.ASYNC_TASK_RUNNING=The task "{0}" is running.
ERRCODE.COMMON.UPLOAD_FILE_EMPTY=Upload file cannot be empty.
AsyncTask.SuccessMsg=Task completed. AsyncTask.SuccessMsg=Task completed.

View File

@ -15,5 +15,6 @@ ERRCODE.COMMON.FIXED_DICT_NOT_ALLOW_ADD=此系統固定字典類型不能添加
ERRCODE.COMMON.FIXED_CONFIG_DEL=系統固定配置參數[{0}]不能刪除 ERRCODE.COMMON.FIXED_CONFIG_DEL=系統固定配置參數[{0}]不能刪除
ERRCODE.COMMON.FIXED_CONFIG_UPDATE=系統固定配置參數[{0}]不能修改鍵名 ERRCODE.COMMON.FIXED_CONFIG_UPDATE=系統固定配置參數[{0}]不能修改鍵名
ERRCODE.COMMON.ASYNC_TASK_RUNNING=任務“{0}”正在運行中 ERRCODE.COMMON.ASYNC_TASK_RUNNING=任務“{0}”正在運行中
ERRCODE.COMMON.UPLOAD_FILE_EMPTY=上傳文件不能為空
AsyncTask.SuccessMsg=任務執行成功 AsyncTask.SuccessMsg=任務執行成功

View File

@ -20,6 +20,7 @@ import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chestnut.common.domain.R; import com.chestnut.common.domain.R;
import com.chestnut.common.i18n.I18nUtils;
import com.chestnut.common.utils.DateUtils; import com.chestnut.common.utils.DateUtils;
import com.chestnut.common.utils.StringUtils; import com.chestnut.common.utils.StringUtils;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@ -114,7 +115,7 @@ public class BaseRestController {
public record SelectOption(String value, String label) {} public record SelectOption(String value, String label) {}
protected <T> R<List<SelectOption>> bindSelectOptions(Collection<T> list, Function<T, String> valueGetter, Function<T, String> labelGetter) { protected <T> R<List<SelectOption>> bindSelectOptions(Collection<T> list, Function<T, String> valueGetter, Function<T, String> labelGetter) {
List<SelectOption> options = list.stream().map(item -> { List<SelectOption> options = list.stream().map(item -> {
return new SelectOption(valueGetter.apply(item), labelGetter.apply(item)); return new SelectOption(valueGetter.apply(item), I18nUtils.get(labelGetter.apply(item)));
}).toList(); }).toList();
return R.ok(options); return R.ok(options);
} }

View File

@ -15,27 +15,26 @@
*/ */
package com.chestnut.common.staticize.config; package com.chestnut.common.staticize.config;
import java.io.File; import com.chestnut.common.staticize.config.properties.FreeMarkerProperties;
import java.io.IOException; import com.chestnut.common.utils.SpringUtils;
import java.util.List; import com.chestnut.common.utils.StringUtils;
import java.util.Objects; import com.chestnut.common.utils.file.FileExUtils;
import java.util.Properties; import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MruCacheStorage;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.chestnut.common.staticize.config.properties.FreeMarkerProperties; import java.io.File;
import com.chestnut.common.utils.SpringUtils; import java.io.IOException;
import com.chestnut.common.utils.StringUtils; import java.util.List;
import com.chestnut.common.utils.file.FileExUtils; import java.util.Objects;
import java.util.Properties;
import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MruCacheStorage;
import freemarker.cache.MultiTemplateLoader;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
@Configuration @Configuration
@EnableConfigurationProperties(FreeMarkerProperties.class) @EnableConfigurationProperties(FreeMarkerProperties.class)
@ -51,19 +50,18 @@ public class FreeMarkerConfig {
* @param properties * @param properties
* @param fileTemplateLoader * @param fileTemplateLoader
* @return * @return
* @throws IOException
* @throws TemplateException * @throws TemplateException
*/ */
@Bean("staticizeConfiguration") @Bean("staticizeConfiguration")
@ConditionalOnMissingBean(freemarker.template.Configuration.class) @ConditionalOnMissingBean(freemarker.template.Configuration.class)
freemarker.template.Configuration staticizeFreeMarkerConfiguration(final FreeMarkerProperties properties, freemarker.template.Configuration staticizeFreeMarkerConfiguration(final FreeMarkerProperties properties,
final List<FileTemplateLoader> fileTemplateLoaders) throws IOException, TemplateException { final List<TemplateLoader> templateLoaders) throws TemplateException {
freemarker.template.Configuration cfg = new freemarker.template.Configuration( freemarker.template.Configuration cfg = new freemarker.template.Configuration(
freemarker.template.Configuration.VERSION_2_3_31); freemarker.template.Configuration.VERSION_2_3_31);
cfg.setDefaultEncoding(properties.getDefaultEncoding()); cfg.setDefaultEncoding(properties.getDefaultEncoding());
// 模板加载路径 // 模板加载路径
MultiTemplateLoader multiTemplateLoader = new MultiTemplateLoader( MultiTemplateLoader multiTemplateLoader = new MultiTemplateLoader(
fileTemplateLoaders.toArray(FileTemplateLoader[]::new)); templateLoaders.toArray(TemplateLoader[]::new));
cfg.setTemplateLoader(multiTemplateLoader); cfg.setTemplateLoader(multiTemplateLoader);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
// 默认模板缓存策略Most recently use cache. // 默认模板缓存策略Most recently use cache.

View File

@ -27,6 +27,7 @@ import com.chestnut.common.security.domain.LoginUser;
import com.chestnut.common.security.web.BaseRestController; import com.chestnut.common.security.web.BaseRestController;
import com.chestnut.common.utils.Assert; import com.chestnut.common.utils.Assert;
import com.chestnut.common.utils.IP2RegionUtils; import com.chestnut.common.utils.IP2RegionUtils;
import com.chestnut.common.utils.IdUtils;
import com.chestnut.common.utils.StringUtils; import com.chestnut.common.utils.StringUtils;
import com.chestnut.system.annotation.IgnoreDemoMode; import com.chestnut.system.annotation.IgnoreDemoMode;
import com.chestnut.system.config.SystemConfig; import com.chestnut.system.config.SystemConfig;
@ -46,6 +47,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -173,19 +175,36 @@ public class SysProfileController extends BaseRestController {
public R<?> getHomeShortcuts() { public R<?> getHomeShortcuts() {
SysUser user = this.userService.getById(StpAdminUtil.getLoginIdAsLong()); SysUser user = this.userService.getById(StpAdminUtil.getLoginIdAsLong());
List<Long> menuIds = ShortcutUserPreference.getValue(user.getPreferences()); List<Long> menuIds = ShortcutUserPreference.getValue(user.getPreferences());
List<SysMenu> menus = this.menuService.lambdaQuery().eq(SysMenu::getMenuType, MenuType.Menu.value()) List<SysMenu> allMenus = this.menuService.lambdaQuery().list();
.in(menuIds.size() > 0, SysMenu::getMenuId, menuIds).last("limit 8").list();
List<SysMenu> shortcuts = allMenus.stream().filter(m -> menuIds.contains(m.getMenuId())).toList();
List<String> menuPerms = StpAdminUtil.getLoginUser().getPermissions(); List<String> menuPerms = StpAdminUtil.getLoginUser().getPermissions();
if (!menuPerms.contains(ISysPermissionService.ALL_PERMISSION)) { if (!menuPerms.contains(ISysPermissionService.ALL_PERMISSION)) {
menus = menus.stream().filter(m -> { shortcuts = shortcuts.stream().filter(m -> {
return StringUtils.isEmpty(m.getPerms()) || menuPerms.contains(m.getPerms()); return StringUtils.isEmpty(m.getPerms()) || menuPerms.contains(m.getPerms());
}).toList(); }).toList();
} }
I18nUtils.replaceI18nFields(menus, LocaleContextHolder.getLocale()); shortcuts.forEach(shortcut -> {
List<ShortcutVO> result = menus.stream() List<String> paths = new ArrayList<>();
generateMenuRoute(shortcut, allMenus, paths);
shortcut.setPath(String.join("/", paths));
});
I18nUtils.replaceI18nFields(shortcuts, LocaleContextHolder.getLocale());
List<ShortcutVO> result = shortcuts.stream()
.sorted(Comparator.comparingInt(m -> menuIds.indexOf(m.getMenuId()))) .sorted(Comparator.comparingInt(m -> menuIds.indexOf(m.getMenuId())))
.map(m -> new ShortcutVO(m.getMenuName(), m.getIcon(), StringUtils.capitalize(m.getPath()))).toList(); .map(m -> new ShortcutVO(m.getMenuName(), m.getIcon(), m.getPath())).toList();
return R.ok(result); return R.ok(result);
} }
private void generateMenuRoute(SysMenu menu, List<SysMenu> menus, List<String> paths) {
paths.add(0, menu.getPath());
if (IdUtils.validate(menu.getParentId())) {
menus.forEach(m -> {
if (m.getMenuId().equals(menu.getParentId())) {
generateMenuRoute(m, menus, paths);
}
});
}
}
} }

View File

@ -15,13 +15,13 @@
*/ */
package com.chestnut.system.service; package com.chestnut.system.service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.chestnut.common.domain.TreeNode; import com.chestnut.common.domain.TreeNode;
import com.chestnut.system.domain.SysMenu; import com.chestnut.system.domain.SysMenu;
import com.chestnut.system.domain.vo.RouterVO; import com.chestnut.system.domain.vo.RouterVO;
import java.util.List;
/** /**
* 菜单 业务层 * 菜单 业务层
* *
@ -37,7 +37,7 @@ public interface ISysMenuService extends IService<SysMenu> {
* 菜单列表 * 菜单列表
* @return 路由列表 * @return 路由列表
*/ */
public List<RouterVO> buildRouters(List<SysMenu> menus); List<RouterVO> buildRouters(List<SysMenu> menus);
/** /**
* 构建前端所需要树结构 * 构建前端所需要树结构
@ -46,7 +46,7 @@ public interface ISysMenuService extends IService<SysMenu> {
* 菜单列表 * 菜单列表
* @return 树结构列表 * @return 树结构列表
*/ */
public List<SysMenu> buildMenuTree(List<SysMenu> menus); List<SysMenu> buildMenuTree(List<SysMenu> menus);
/** /**
* 构建前端所需要下拉树结构 * 构建前端所需要下拉树结构
@ -55,7 +55,7 @@ public interface ISysMenuService extends IService<SysMenu> {
* 菜单列表 * 菜单列表
* @return 下拉树结构列表 * @return 下拉树结构列表
*/ */
public List<TreeNode<Long>> buildMenuTreeSelect(List<SysMenu> menus); List<TreeNode<Long>> buildMenuTreeSelect(List<SysMenu> menus);
/** /**
* 新增保存菜单信息 * 新增保存菜单信息
@ -64,7 +64,7 @@ public interface ISysMenuService extends IService<SysMenu> {
* 菜单信息 * 菜单信息
* @return 结果 * @return 结果
*/ */
public void insertMenu(SysMenu menu); void insertMenu(SysMenu menu);
/** /**
* 修改保存菜单信息 * 修改保存菜单信息
@ -73,7 +73,7 @@ public interface ISysMenuService extends IService<SysMenu> {
* 菜单信息 * 菜单信息
* @return 结果 * @return 结果
*/ */
public void updateMenu(SysMenu menu); void updateMenu(SysMenu menu);
/** /**
* 删除菜单管理信息 * 删除菜单管理信息
@ -82,7 +82,7 @@ public interface ISysMenuService extends IService<SysMenu> {
* 菜单ID * 菜单ID
* @return 结果 * @return 结果
*/ */
public void deleteMenuById(Long menuId); void deleteMenuById(Long menuId);
List<SysMenu> getChildPerms(List<SysMenu> list, int parentId); List<SysMenu> getChildPerms(List<SysMenu> list, int parentId);
} }

View File

@ -38,7 +38,7 @@ export default {
}) })
}, },
handleShortcutRedirect(router) { handleShortcutRedirect(router) {
this.$router.push({ name: router }) this.$router.push({ path: router })
} }
} }
}; };