Browse Source

数据库配置

yingp 8 years ago
parent
commit
a61662d86f

+ 27 - 0
build.gradle

@@ -4,6 +4,8 @@ version '1.0.0'
 buildscript {
     ext {
         springBootVersion = '1.4.4.RELEASE'
+        dockerVersion = '0.12.0'
+        dockerRegistry = "10.10.100.200:5000"
     }
     repositories {
         maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
@@ -14,12 +16,15 @@ buildscript {
     }
     dependencies {
         classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+        classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:${dockerVersion}"
     }
 }
 
 apply plugin: 'idea'
 apply plugin: 'java'
+apply plugin: 'maven'
 apply plugin: 'org.springframework.boot'
+apply plugin: "com.palantir.docker"
 
 jar {
     baseName = project.name
@@ -32,6 +37,8 @@ repositories {
     mavenLocal()
     maven { url "http://repo.spring.io/libs-milestone" }
     maven { url "http://repo.spring.io/libs-release" }
+	maven { url "http://10.10.101.21:8081/artifactory/libs-release-local" }
+	maven { url "http://10.10.101.21:8081/artifactory/ext-release-local" }
     maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
     mavenCentral()
 }
@@ -50,3 +57,23 @@ dependencies {
     compile "com.alibaba:fastjson:$fastjsonVersion"
     compile "com.uas.api:b2c-erp-api:$mallApiVersion"
 }
+
+bootRun {
+    addResources = true
+}
+
+docker {
+    name "${dockerRegistry}/${project.name}:${project.version}"
+    dockerfile "${projectDir}/src/main/docker/Dockerfile"
+    files "${buildDir}/libs/${project.name}.jar"
+}.dependsOn build
+
+uploadArchives {
+    repositories {
+        mavenDeployer {
+            repository(url: "http://10.10.101.21:8081/artifactory/libs-release-local") {
+                authentication(userName: "yingp", password: "111111")
+            }
+        }
+    }
+}.dependsOn build

+ 6 - 0
src/main/docker/Dockerfile

@@ -0,0 +1,6 @@
+FROM hub.c.163.com/library/java:8-jre-alpine
+VOLUME /tmp # reate a temporary file on my host under "/var/lib/docker" and link it to the container under "/tmp".
+ADD uas_schedular.jar app.jar
+RUN sh -c "touch /app.jar" #  "touch" the jar file so that it has a file modification time (Docker creates all container files in an "unmodified" state by default). This actually isn’t important for the simple app that we wrote, but any static content (e.g. "index.html") would require the file to have a modification time.
+ENV JAVA_OPTS=""
+ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -Dspring.profiles.active=prod -Duser.timezone=GMT+08 -Djava.security.egd=file:/dev/./urandom -jar /app.jar"] # To reduce Tomcat startup time we added a system property pointing to "/dev/urandom" as a source of entropy.

+ 49 - 0
src/main/java/com/uas/erp/schedular/api/v1/SettingControllerV1.java

@@ -0,0 +1,49 @@
+package com.uas.erp.schedular.api.v1;
+
+import com.uas.erp.schedular.entity.Setting;
+import com.uas.erp.schedular.service.SettingService;
+import com.uas.erp.schedular.web.ResponseWrap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.Assert;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * Created by Pro1 on 2017/6/22.
+ */
+@RestController
+@RequestMapping(path = "/v1/setting")
+public class SettingControllerV1 {
+
+    @Autowired
+    private SettingService settingService;
+
+    /**
+     * 取配置列表
+     * @return
+     */
+    @GetMapping(path = "/list")
+    public ResponseEntity getSettings() {
+        return ResponseWrap.ok(settingService.findAll());
+    }
+
+    @GetMapping(path = "/{key}")
+    public ResponseEntity getSetting(@PathVariable("key") String key) {
+        return ResponseWrap.ok(settingService.findOne(key));
+    }
+
+    @PostMapping
+    public ResponseEntity saveSetting(Setting setting) {
+        settingService.save(setting);
+        return ResponseWrap.ok();
+    }
+
+    @DeleteMapping(path = "/{key}")
+    public ResponseEntity deleteSetting(@PathVariable("key") String key) {
+        Setting setting = settingService.findOne(key);
+        Assert.notNull(setting);
+        settingService.delete(setting);
+        return ResponseWrap.ok();
+    }
+
+}

+ 1 - 1
src/main/java/com/uas/erp/schedular/api/v1/TaskController.java → src/main/java/com/uas/erp/schedular/api/v1/TaskControllerV1.java

@@ -20,7 +20,7 @@ import java.util.List;
  */
 @RestController
 @RequestMapping(path = "/v1/task")
-public class TaskController {
+public class TaskControllerV1 {
 
     @Autowired
     private ScheduledTaskService scheduledTaskService;

+ 1 - 18
src/main/java/com/uas/erp/schedular/entity/Setting.java

@@ -16,12 +16,8 @@ public class Setting {
     @Id
     private String key;
 
-    @Column(name = "group_")
-    private String group;
-
-    private static final String default_group = "default";
-
     private String description;
+
     @Column(name = "value_")
     private String value;
 
@@ -37,7 +33,6 @@ public class Setting {
     }
 
     public Setting(String group, String key, String description, String value) {
-        this.group = StringUtils.isEmpty(group) ? default_group : group;
         Assert.notNull(key);
         this.key = key;
         this.description = StringUtils.isEmpty(description) ? key : description;
@@ -67,16 +62,4 @@ public class Setting {
     public void setValue(String value) {
         this.value = value;
     }
-
-    /**
-     * 分组
-     * @return
-     */
-    public String getGroup() {
-        return group;
-    }
-
-    public void setGroup(String group) {
-        this.group = group;
-    }
 }

+ 8 - 0
src/main/java/com/uas/erp/schedular/service/SettingService.java

@@ -20,6 +20,10 @@ public class SettingService {
         return settingRepository.findAll();
     }
 
+    public Setting findOne(String key) {
+        return settingRepository.findOne(key);
+    }
+
     public String getValue(String key) {
         Setting setting = settingRepository.findOne(key);
         return null != setting ? setting.getValue() : null;
@@ -33,4 +37,8 @@ public class SettingService {
         settingRepository.save(settings);
     }
 
+    public void delete(Setting setting) {
+        settingRepository.delete(setting);
+    }
+
 }

+ 1 - 1
src/main/resources/application.yml

@@ -29,4 +29,4 @@ spring:
 spring:
   profiles: prod
   datasource:
-    url: jdbc:h2:file:~/data/db;DB_CLOSE_ON_EXIT=FALSE
+    url: jdbc:h2:file:~/data/uas_schedular;FILE_LOCK=NO;DB_CLOSE_ON_EXIT=FALSE

+ 0 - 5
src/main/resources/init/setting.json

@@ -1,23 +1,18 @@
 [{
-  "group": "api",
   "key": "api.database.url",
   "description": "数据库服务接口地址",
   "value": "http://127.0.0.1:9002/uas_database"
 },{
-  "group": "api",
   "key": "api.uas.outer.url",
   "description": "UAS系统外网接口地址"
 },{
-  "group": "api",
   "key": "api.uas.inner.url",
   "description": "UAS系统内网接口地址"
 },{
-  "group": "api",
   "key": "api.b2b.test.url",
   "description": "优软B2B平台测试接口地址",
   "value": "http://218.17.158.219:9000/b2b_test"
 },{
-  "group": "api",
   "key": "api.b2b.url",
   "description": "优软B2B平台正式接口地址",
   "value": "http://uas.ubtob.com"