Jelajahi Sumber

update

Signed-off-by: wangwei <wangwei@qmth.com.cn>
wangwei 7 tahun lalu
induk
melakukan
9352cd3e93

+ 4 - 16
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/OrgConfigApi.java

@@ -1,12 +1,8 @@
 package cn.com.qmth.examcloud.service.core.api;
 
-import java.util.List;
-import java.util.Map;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PutMapping;
@@ -14,6 +10,7 @@ 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.service.core.service.OrgConfigService;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -27,20 +24,13 @@ import io.swagger.annotations.ApiOperation;
 public class OrgConfigApi {
 
 	@Autowired
-	private JdbcTemplate jdbcTemplate;
+	private OrgConfigService orgConfigService;
 
 	@ApiOperation(value = "查询机构配置", notes = "查询")
 	@GetMapping("/{id}/{key}")
 	public ResponseEntity<?> getOrgConfig(@PathVariable Long id, @PathVariable String key) {
 
-		List<Map<String, Object>> dataList = jdbcTemplate
-				.queryForList(" SELECT t.value from ecs_core_org_config t where t.org_id=? and t.key=?", id, key);
-
-		String value = "";
-		if (1 == dataList.size()) {
-			Map<String, Object> map = dataList.get(0);
-			value = (String) map.get("value");
-		}
+		String value = orgConfigService.getOrgConfig(id, key);
 
 		return new ResponseEntity<>(value, HttpStatus.OK);
 	}
@@ -49,9 +39,7 @@ public class OrgConfigApi {
 	@PutMapping("/{id}/{key}")
 	public ResponseEntity<?> setOrgConfig(@PathVariable Long id, @PathVariable String key, @RequestBody String value) {
 
-		jdbcTemplate.update(
-				"INSERT INTO ecs_core_org_config (org_id,key,value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE value=?", id,
-				key, value, value);
+		orgConfigService.setOrgConfig(id, key, value);
 
 		return new ResponseEntity<>("", HttpStatus.OK);
 	}

+ 48 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgConfigService.java

@@ -0,0 +1,48 @@
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.PathVariable;
+
+@Service
+public class OrgConfigService {
+
+	@Autowired
+	private JdbcTemplate jdbcTemplate;
+
+	/**
+	 * @param id
+	 * @param key
+	 * @return
+	 */
+	public String getOrgConfig(@PathVariable Long id, @PathVariable String key) {
+
+		List<Map<String, Object>> dataList = jdbcTemplate
+				.queryForList(" SELECT t.value from ecs_core_org_config t where t.org_id=? and t.key=?", id, key);
+
+		String value = "";
+		if (1 == dataList.size()) {
+			Map<String, Object> map = dataList.get(0);
+			value = (String) map.get("value");
+		}
+
+		return value;
+	}
+
+	/**
+	 * @param orgId
+	 * @param key
+	 * @param value
+	 */
+	public void setOrgConfig(Long orgId, String key, String value) {
+
+		jdbcTemplate.update(
+				"INSERT INTO ecs_core_org_config (org_id,key,value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE value=?", orgId,
+				key, value, value);
+	}
+
+}