perf: 优化主题设置后台接口

This commit is contained in:
fit2cloud-chenyw 2022-08-10 22:44:25 +08:00
parent 6d3ab3a8b4
commit 98c36ab957
2 changed files with 52 additions and 7 deletions

View File

@ -6,17 +6,17 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import io.dataease.commons.exception.DEException;
import io.dataease.commons.utils.LogUtil;
import io.dataease.i18n.Translator;
import io.dataease.plugins.config.SpringContextUtil;
import io.dataease.plugins.xpack.theme.dto.ThemeCreateRequest;
import io.dataease.plugins.xpack.theme.dto.ThemeDto;
import io.dataease.plugins.xpack.theme.dto.ThemeItem;
import io.dataease.plugins.xpack.theme.dto.ThemeRenameRequest;
import io.dataease.plugins.xpack.theme.dto.ThemeRequest;
import io.dataease.plugins.xpack.theme.service.ThemeXpackService;
import springfox.documentation.annotations.ApiIgnore;
@ -41,11 +41,10 @@ public class ThemeServer {
@RequiresPermissions("sysparam:read")
@PostMapping("/save")
public void save(@RequestPart("request") ThemeRequest request,
@RequestPart(value = "file", required = false) MultipartFile bodyFile) {
public void save(@RequestBody ThemeCreateRequest request) {
ThemeXpackService themeXpackService = SpringContextUtil.getBean(ThemeXpackService.class);
try {
themeXpackService.save(request, bodyFile);
themeXpackService.addTheme(request);
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
if (ObjectUtils.isNotEmpty(e.getMessage()) && e.getMessage().indexOf("theme_name_repeat") != -1) {
@ -56,7 +55,40 @@ public class ThemeServer {
DEException.throwException(e);
}
}
}
@PostMapping("/rename")
public void renameTheme(@RequestBody ThemeRenameRequest request) {
if (request.getId() < 3) {
throw new RuntimeException("default theme can not execute rename");
}
try {
ThemeXpackService themeXpackService = SpringContextUtil.getBean(ThemeXpackService.class);
themeXpackService.renameTheme(request);
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
if (ObjectUtils.isNotEmpty(e.getMessage()) && e.getMessage().indexOf("theme_name_repeat") != -1) {
DEException.throwException(Translator.get("theme_name_repeat"));
} else if (ObjectUtils.isNotEmpty(e.getMessage()) && e.getMessage().indexOf("theme_name_empty") != -1) {
DEException.throwException(Translator.get("theme_name_empty"));
} else {
DEException.throwException(e);
}
}
}
@PostMapping("/enableSenior/{themeId}")
public void enableSenior(@PathVariable("themeId") Integer themeId) {
ThemeXpackService themeXpackService = SpringContextUtil.getBean(ThemeXpackService.class);
themeXpackService.switchSenior(themeId);
}
@PostMapping("/activeTheme/{themeId}")
public void activeTheme(@PathVariable("themeId") Integer themeId) {
ThemeXpackService themeXpackService = SpringContextUtil.getBean(ThemeXpackService.class);
themeXpackService.switchStatus(themeId);
}
@RequiresPermissions("sysparam:read")
@ -66,4 +98,10 @@ public class ThemeServer {
themeXpackService.deleteTheme(themeId);
}
@PostMapping("/saveThemeItems")
public void saveThemeItems(@RequestBody ThemeRequest request) {
ThemeXpackService themeXpackService = SpringContextUtil.getBean(ThemeXpackService.class);
themeXpackService.saveThemeItems(request);
}
}

View File

@ -2,4 +2,11 @@ INSERT INTO `sys_menu` VALUES (700, 1, 2, 1, '系统配置', 'sys-settings', 'sy
INSERT INTO `sys_menu` VALUES (710, 700, 0, 1, '外观配置', 'sys-appearance', 'system/settings/AppearanceSetting', 2, 'sys-tools', 'appearance', b'0', b'0', b'0', 'appearance:read', NULL, NULL, NULL, NULL);
INSERT INTO `sys_menu` VALUES (730, 1, 0, 1, '数据同步表单', 'sys-task-ds-form', 'system/task/form', 11, NULL, '/task-ds-form', b'1', b'0', b'1', NULL, NULL, NULL, NULL, NULL);
UPDATE `sys_menu` set pid = 700, menu_sort = 1 where menu_id = 6 and `name` = 'system-param';
UPDATE `sys_menu` set pid = 700, menu_sort = 1 where menu_id = 6 and `name` = 'system-param';
ALTER TABLE `sys_theme`
DROP COLUMN `img`,
DROP COLUMN `img_id`,
ADD COLUMN `senior` TINYINT(1) NULL DEFAULT NULL AFTER `status`;