From 2add95d1129aa8929d65dd065aea22e3e3fc7ccc Mon Sep 17 00:00:00 2001 From: zhou-hao Date: Thu, 9 Apr 2020 10:39:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=B3=BB=E7=BB=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/entity/SystemConfigEntity.java | 36 +++++++++++++++ .../auth/web/SystemConfigController.java | 45 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/entity/SystemConfigEntity.java create mode 100644 jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/web/SystemConfigController.java diff --git a/jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/entity/SystemConfigEntity.java b/jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/entity/SystemConfigEntity.java new file mode 100644 index 00000000..eb5ab4bd --- /dev/null +++ b/jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/entity/SystemConfigEntity.java @@ -0,0 +1,36 @@ +package org.jetlinks.community.auth.entity; + +import lombok.*; +import org.hswebframework.ezorm.rdb.mapping.annotation.ColumnType; +import org.hswebframework.ezorm.rdb.mapping.annotation.JsonCodec; +import org.hswebframework.web.api.crud.entity.GenericEntity; + +import javax.persistence.Column; +import javax.persistence.Table; +import java.sql.JDBCType; +import java.util.Map; + +@Getter +@Setter +@Table(name = "s_system_conf") +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SystemConfigEntity extends GenericEntity { + + /** + * 前端配置 + */ + @Column + @ColumnType(jdbcType = JDBCType.CLOB) + @JsonCodec + private Map frontConfig; + + public static SystemConfigEntity front(String id,Map front){ + SystemConfigEntity entity=new SystemConfigEntity(); + entity.setId(id); + entity.setFrontConfig(front); + return entity; + } + +} diff --git a/jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/web/SystemConfigController.java b/jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/web/SystemConfigController.java new file mode 100644 index 00000000..be86008f --- /dev/null +++ b/jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/web/SystemConfigController.java @@ -0,0 +1,45 @@ +package org.jetlinks.community.auth.web; + +import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository; +import org.hswebframework.web.authorization.annotation.Authorize; +import org.hswebframework.web.authorization.annotation.QueryAction; +import org.hswebframework.web.authorization.annotation.Resource; +import org.hswebframework.web.authorization.annotation.SaveAction; +import org.jetlinks.community.auth.entity.SystemConfigEntity; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +import java.util.Collections; +import java.util.Map; + +@RequestMapping("/system/config") +@RestController +@Resource(id = "system-config", name = "系统配置") +public class SystemConfigController { + + private final ReactiveRepository repository; + + public SystemConfigController(ReactiveRepository repository) { + this.repository = repository; + } + + @GetMapping("/front") + @QueryAction + @Authorize(ignore = true) + public Mono> getFrontConfig() { + return repository.findById("default") + .map(SystemConfigEntity::getFrontConfig) + .defaultIfEmpty(Collections.emptyMap()); + } + + @PostMapping("/front") + @QueryAction + @SaveAction + public Mono saveFrontConfig(@RequestBody Mono> config) { + return config + .map(front -> SystemConfigEntity.front("default", front)) + .as(repository::save) + .then(); + } + +}