增加系统配置

This commit is contained in:
none 2023-03-09 16:19:43 +08:00
parent ddc4693b10
commit c85467f62f
6 changed files with 86 additions and 6 deletions

View File

@ -1,8 +1,14 @@
package xyz.playedu.api.controller.backend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.playedu.api.domain.AppConfig;
import xyz.playedu.api.request.backend.AppConfigRequest;
import xyz.playedu.api.service.AppConfigService;
import xyz.playedu.api.types.JsonResponse;
import java.util.List;
/**
* @Author 杭州白书科技有限公司
* @create 2023/3/9 11:14
@ -11,13 +17,18 @@ import xyz.playedu.api.types.JsonResponse;
@RequestMapping("/backend/v1/app-config")
public class AppConfigController {
@Autowired
private AppConfigService configService;
@GetMapping("/index")
public JsonResponse index() {
return JsonResponse.data(null);
List<AppConfig> configs = configService.allShow();
return JsonResponse.data(configs);
}
@PutMapping("/index")
public JsonResponse save() {
public JsonResponse save(@RequestBody AppConfigRequest req) {
configService.saveFromMap(req.getData());
return JsonResponse.data(null);
}

View File

@ -43,6 +43,12 @@ public class DepartmentController {
return JsonResponse.data(data);
}
@GetMapping("/departments")
public JsonResponse index(@RequestParam(name = "parent_id", defaultValue = "0") Integer parentId) {
List<Department> departments = departmentService.listByParentId(parentId);
return JsonResponse.data(departments);
}
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_CUD)
@GetMapping("/create")
public JsonResponse create() {

View File

@ -41,6 +41,12 @@ public class ResourceCategoryController {
return JsonResponse.data(data);
}
@GetMapping("/categories")
public JsonResponse index(@RequestParam(name = "parent_id", defaultValue = "0") Integer parentId) {
List<ResourceCategory> categories = categoryService.listByParentId(parentId);
return JsonResponse.data(categories);
}
@GetMapping("/create")
public JsonResponse create() {
Map<Integer, List<ResourceCategory>> categories = categoryService.all().stream().collect(Collectors.groupingBy(ResourceCategory::getParentId));

View File

@ -0,0 +1,16 @@
package xyz.playedu.api.request.backend;
import lombok.Data;
import java.util.HashMap;
/**
* @Author 杭州白书科技有限公司
* @create 2023/3/9 16:13
*/
@Data
public class AppConfigRequest {
private HashMap<String, String> data;
}

View File

@ -3,15 +3,21 @@ package xyz.playedu.api.service;
import xyz.playedu.api.domain.AppConfig;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author tengteng
* @description 针对表app_config的数据库操作Service
* @createDate 2023-03-09 11:13:33
*/
* @author tengteng
* @description 针对表app_config的数据库操作Service
* @createDate 2023-03-09 11:13:33
*/
public interface AppConfigService extends IService<AppConfig> {
Map<String, Long> allKeys();
List<AppConfig> allShow();
void saveFromMap(HashMap<String, String> data);
}

View File

@ -6,6 +6,9 @@ import xyz.playedu.api.service.AppConfigService;
import xyz.playedu.api.mapper.AppConfigMapper;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -22,6 +25,38 @@ public class AppConfigServiceImpl extends ServiceImpl<AppConfigMapper, AppConfig
public Map<String, Long> allKeys() {
return list().stream().collect(Collectors.toMap(AppConfig::getKeyName, AppConfig::getId));
}
@Override
public List<AppConfig> allShow() {
return list(query().getWrapper().eq("is_hidden", 0));
}
@Override
public void saveFromMap(HashMap<String, String> data) {
Map<String, AppConfig> configs = list(query().getWrapper().in("key_name", data.keySet())).stream().collect(Collectors.toMap(AppConfig::getKeyName, e -> e));
List<AppConfig> list = new ArrayList<>();
data.forEach((keyNameValue, keyValueValue) -> {
if ("******".equals(keyNameValue)) {//私密信息默认place
return;
}
AppConfig configItem = configs.get(keyNameValue);
if (configItem == null) {//不存在的配置
return;
}
if (keyValueValue.equals(configItem.getKeyValue())) {//没有变化
return;
}
list.add(new AppConfig() {{
setId(configItem.getId());
setKeyValue(keyValueValue);
}});
});
if (list.size() > 0) {
updateBatchById(list);
}
}
}