Skip to content

Commit

Permalink
优化:删除旧的项目配置代码
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYuYang01 committed Nov 28, 2024
1 parent 51df291 commit 2599187
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 424 deletions.
15 changes: 11 additions & 4 deletions blog/src/main/java/liuyuyang/net/controller/ConfigController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,31 @@
import javax.annotation.Resource;
import java.util.Map;

@Api(tags = "项目配置123")
@Api(tags = "项目配置")
@RestController
@RequestMapping("/config")
@Transactional
public class ConfigController {
@Resource
private ConfigService configService;

@GetMapping("/{group}")
@ApiOperation("获取项目配置")
@GetMapping("/{name}")
@ApiOperation("获取指定项目配置")
@ApiOperationSupport(author = "刘宇阳 | liuyuyang1024@yeah.net", order = 1)
public Result get(@PathVariable("name") String name) {
return Result.success(configService.get(name));
}

@GetMapping("/list/{group}")
@ApiOperation("获取项目配置列表")
@ApiOperationSupport(author = "刘宇阳 | liuyuyang1024@yeah.net", order = 2)
public Result list(@PathVariable("group") String group) {
return Result.success(configService.list(group));
}

@PatchMapping("/{group}")
@ApiOperation("修改项目配置")
@ApiOperationSupport(author = "刘宇阳 | liuyuyang1024@yeah.net", order = 2)
@ApiOperationSupport(author = "刘宇阳 | liuyuyang1024@yeah.net", order = 3)
public Result edit(@PathVariable("group") String group, @RequestBody Map<String, String> config) {
configService.edit(group, config);
return Result.success();
Expand Down
108 changes: 0 additions & 108 deletions blog/src/main/java/liuyuyang/net/controller/ProjectController.java

This file was deleted.

10 changes: 0 additions & 10 deletions blog/src/main/java/liuyuyang/net/mapper/ProjectMapper.java

This file was deleted.

4 changes: 2 additions & 2 deletions blog/src/main/java/liuyuyang/net/service/ConfigService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package liuyuyang.net.service;

import com.baomidou.mybatisplus.extension.service.IService;
import liuyuyang.net.dto.project.SystemDTO;
import liuyuyang.net.model.Config;

import java.util.Map;

public interface ConfigService extends IService<Config> {
Object get(String name);
Map list(String group);
void edit(String group, Map<String, String> config);
SystemDTO getSystemInfo();
Map getSystemInfo();
}
9 changes: 0 additions & 9 deletions blog/src/main/java/liuyuyang/net/service/ProjectService.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
import liuyuyang.net.execption.CustomException;
import liuyuyang.net.mapper.ArticleMapper;
import liuyuyang.net.mapper.CommentMapper;
import liuyuyang.net.mapper.ProjectMapper;
import liuyuyang.net.model.Article;
import liuyuyang.net.model.Comment;
import liuyuyang.net.model.Project;
import liuyuyang.net.service.CommentService;
import liuyuyang.net.service.ConfigService;
import liuyuyang.net.utils.EmailUtils;
import liuyuyang.net.utils.YuYangUtils;
import liuyuyang.net.vo.PageVo;
import liuyuyang.net.vo.comment.CommentFilterVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.TemplateEngine;
Expand All @@ -42,7 +40,7 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
@Resource
private ArticleMapper articleMapper;
@Resource
private ProjectMapper projectMapper;
private ConfigService configService;

@Override
public void add(Comment comment) throws Exception {
Expand Down Expand Up @@ -75,9 +73,9 @@ public void add(Comment comment) throws Exception {
context.setVariable("content", content.toString());

// 获取url
Project config = projectMapper.selectById(1);
String url = String.format("%s/article/%d", config.getUrl(), comment.getArticleId());
context.setVariable("url", url);
String url = (String) configService.get("url");
String path = String.format("%s/article/%d", url, comment.getArticleId());
context.setVariable("url", path);

String template = templateEngine.process("comment_email", context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import liuyuyang.net.dto.project.SystemDTO;
import liuyuyang.net.execption.CustomException;
import liuyuyang.net.mapper.ConfigMapper;
import liuyuyang.net.model.Config;
Expand All @@ -25,6 +24,11 @@ public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> impleme
@Resource
private ConfigMapper configMapper;

@Override
public Object get(String name){
return configMapper.selectOne(new LambdaQueryWrapper<Config>().eq(Config::getName, name)).getValue();
}

@Override
public Map<String, Object> list(String group) {
List<Config> list;
Expand All @@ -43,14 +47,7 @@ public Map<String, Object> list(String group) {
wrapper.eq(Config::getGroup, "layout");
break;
case "system":
SystemDTO systemInfo = getSystemInfo();
result = new HashMap<>();
result.put("osName", systemInfo.getOsName());
result.put("osVersion", systemInfo.getOsVersion());
result.put("totalMemory", systemInfo.getTotalMemory());
result.put("availableMemory", systemInfo.getAvailableMemory());
result.put("memoryUsage", systemInfo.getMemoryUsage());
return result;
return getSystemInfo();
default:
throw new CustomException(400, "未知的分组");
}
Expand All @@ -65,22 +62,6 @@ public Map<String, Object> list(String group) {
public void edit(String group, Map<String, String> data) {
System.out.println(data);

// switch (group) {
// case "layout":
// for (Map.Entry<String, String> entry : data.entrySet()) {
// String name = entry.getKey();
// String value = entry.getValue();
//
// LambdaQueryWrapper<Config> wrapper = new LambdaQueryWrapper<>();
// wrapper.eq(Config::getName, name);
// Config config = new Config();
// config.setValue(value);
// configMapper.update(config, wrapper);
// }
//
// break;
// }

for (Map.Entry<String, String> entry : data.entrySet()) {
String name = entry.getKey();
String value = entry.getValue();
Expand All @@ -94,7 +75,7 @@ public void edit(String group, Map<String, String> data) {
}

@Override
public SystemDTO getSystemInfo() {
public Map getSystemInfo() {
SystemInfo systemInfo = new SystemInfo();

// 获取操作系统信息
Expand All @@ -113,13 +94,13 @@ public SystemDTO getSystemInfo() {
// 内存使用率
double memoryUsage = (double) (totalMemory - availableMemory) / totalMemory * 100;

SystemDTO data = new SystemDTO();
data.setOsName(osName);
data.setOsVersion(osVersion);
data.setTotalMemory((int) (totalMemory / (1024.0 * 1024 * 1024)));
data.setAvailableMemory((int) (availableMemory / (1024.0 * 1024 * 1024)));
data.setMemoryUsage(Float.valueOf(String.format("%.2f", memoryUsage)));
Map<String, Object> result = new HashMap<>();
result.put("osName", osName);
result.put("osVersion", osVersion);
result.put("totalMemory", (int) (totalMemory / (1024.0 * 1024 * 1024)));
result.put("availableMemory", (int) (availableMemory / (1024.0 * 1024 * 1024)));
result.put("memoryUsage", Float.valueOf(String.format("%.2f", memoryUsage)));

return data;
return result;
}
}

This file was deleted.

10 changes: 0 additions & 10 deletions model/src/main/java/liuyuyang/net/dto/project/OtherDTO.java

This file was deleted.

Loading

0 comments on commit 2599187

Please sign in to comment.