WANG 6 vuotta sitten
vanhempi
commit
bfff92ad5b

+ 36 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/SysConfigController.java

@@ -0,0 +1,36 @@
+package cn.com.qmth.examcloud.core.basic.api.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.service.SysConfigService;
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年12月3日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Transactional
+@RestController
+@RequestMapping("${$rmp.ctr.basic}/sysConfig")
+public class SysConfigController extends ControllerSupport {
+
+	@Autowired
+	SysConfigService sysConfigService;
+
+	@ApiOperation(value = "查询所有应用")
+	@GetMapping("{key}")
+	public Object get(@PathVariable String key) {
+		Object object = sysConfigService.get(key);
+		return object;
+	}
+
+}

+ 76 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/SysConfigCloudServiceProvider.java

@@ -0,0 +1,76 @@
+package cn.com.qmth.examcloud.core.basic.api.provider;
+
+import java.util.Date;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+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.RestController;
+
+import cn.com.qmth.examcloud.commons.base.util.DateUtil;
+import cn.com.qmth.examcloud.commons.base.util.DateUtil.DatePatterns;
+import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.api.SysConfigCloudService;
+import cn.com.qmth.examcloud.core.basic.api.request.GetSysConfigReq;
+import cn.com.qmth.examcloud.core.basic.api.request.SetSysConfigReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetSysConfigResp;
+import cn.com.qmth.examcloud.core.basic.api.response.SetSysConfigResp;
+import cn.com.qmth.examcloud.core.basic.service.SysConfigService;
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年12月3日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Transactional
+@RestController
+@RequestMapping("${$rmp.cloud.basic}" + "sysConfig")
+public class SysConfigCloudServiceProvider extends ControllerSupport
+		implements
+			SysConfigCloudService {
+
+	private static final long serialVersionUID = 2299432976949405946L;
+
+	@Autowired
+	SysConfigService sysConfigService;
+
+	@ApiOperation(value = "设置配置")
+	@PostMapping("setSysConfig")
+	@Override
+	public SetSysConfigResp setSysConfig(@RequestBody SetSysConfigReq req) {
+		String key = req.getKey();
+		String value = req.getValue();
+		sysConfigService.set(key, value);
+
+		SetSysConfigResp resp = new SetSysConfigResp();
+		resp.setKey(key);
+		resp.setValue(value);
+		return resp;
+	}
+
+	@ApiOperation(value = "获取配置")
+	@PostMapping("getSysConfig")
+	@Override
+	public GetSysConfigResp getSysConfig(@RequestBody GetSysConfigReq req) {
+		String key = req.getKey();
+		Object value = sysConfigService.get(key);
+
+		String strValue = null;
+		if (value instanceof Date) {
+			strValue = DateUtil.format((Date) value, DatePatterns.ISO);
+		} else {
+			strValue = String.valueOf(value);
+		}
+
+		GetSysConfigResp resp = new GetSysConfigResp();
+		resp.setKey(key);
+		resp.setValue(strValue);
+		return resp;
+	}
+
+}