瀏覽代碼

init from phab

xielq 5 年之前
父節點
當前提交
287f589753
共有 40 個文件被更改,包括 1993 次插入0 次删除
  1. 6 0
      README.md
  2. 47 0
      build.gradle
  3. 2 0
      gradle.properties
  4. 21 0
      gradle/dependencies.gradle
  5. 9 0
      gradle/tasks.gradle
  6. 2 0
      settings.gradle
  7. 6 0
      src/main/docker/Dockerfile
  8. 16 0
      src/main/java/com/uas/erp/manage/server/UasManageServerApplication.java
  9. 30 0
      src/main/java/com/uas/erp/manage/server/api/v1/ArtifactController.java
  10. 70 0
      src/main/java/com/uas/erp/manage/server/api/v1/ClientController.java
  11. 46 0
      src/main/java/com/uas/erp/manage/server/api/v1/DeployController.java
  12. 11 0
      src/main/java/com/uas/erp/manage/server/config/AppConfig.java
  13. 23 0
      src/main/java/com/uas/erp/manage/server/config/ExceptionConfig.java
  14. 62 0
      src/main/java/com/uas/erp/manage/server/config/WebMvcConfig.java
  15. 135 0
      src/main/java/com/uas/erp/manage/server/config/WebSecurityConfig.java
  16. 94 0
      src/main/java/com/uas/erp/manage/server/domain/ClientContainerInfo.java
  17. 116 0
      src/main/java/com/uas/erp/manage/server/domain/ClientInfo.java
  18. 92 0
      src/main/java/com/uas/erp/manage/server/domain/ClientProjectInfo.java
  19. 57 0
      src/main/java/com/uas/erp/manage/server/domain/ProjectVersion.java
  20. 76 0
      src/main/java/com/uas/erp/manage/server/entity/Client.java
  21. 103 0
      src/main/java/com/uas/erp/manage/server/entity/ClientContainer.java
  22. 103 0
      src/main/java/com/uas/erp/manage/server/entity/ClientProject.java
  23. 74 0
      src/main/java/com/uas/erp/manage/server/entity/ClientProjectDeployTask.java
  24. 109 0
      src/main/java/com/uas/erp/manage/server/entity/ClientProjectDeployTaskItem.java
  25. 27 0
      src/main/java/com/uas/erp/manage/server/repository/ClientContainerRepository.java
  26. 17 0
      src/main/java/com/uas/erp/manage/server/repository/ClientProjectDeployTaskItemRepository.java
  27. 12 0
      src/main/java/com/uas/erp/manage/server/repository/ClientProjectDeployTaskRepository.java
  28. 24 0
      src/main/java/com/uas/erp/manage/server/repository/ClientProjectRepository.java
  29. 15 0
      src/main/java/com/uas/erp/manage/server/repository/ClientRepository.java
  30. 34 0
      src/main/java/com/uas/erp/manage/server/service/ArtifactService.java
  31. 45 0
      src/main/java/com/uas/erp/manage/server/service/ClientContainerService.java
  32. 50 0
      src/main/java/com/uas/erp/manage/server/service/ClientProjectDeployTaskService.java
  33. 109 0
      src/main/java/com/uas/erp/manage/server/service/ClientProjectService.java
  34. 55 0
      src/main/java/com/uas/erp/manage/server/service/ClientService.java
  35. 43 0
      src/main/java/com/uas/erp/manage/server/util/IpUtils.java
  36. 26 0
      src/main/java/com/uas/erp/manage/server/util/RestUtils.java
  37. 97 0
      src/main/java/com/uas/erp/manage/server/web/ResponseWrap.java
  38. 52 0
      src/main/java/com/uas/erp/manage/server/web/RestPage.java
  39. 47 0
      src/main/java/com/uas/erp/manage/server/web/ResultWrap.java
  40. 30 0
      src/main/resources/application.yml

+ 6 - 0
README.md

@@ -0,0 +1,6 @@
+# UAS管理中心
+
+> 功能
+* 提供REST接口供uas-manage-client获取最新设置
+* 提供REST接口供uas-manage-client发送客户端数据
+* 提供REST接口供uas-manage-server-web终端操作

+ 47 - 0
build.gradle

@@ -0,0 +1,47 @@
+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/" }
+        maven { url "https://plugins.gradle.org/m2/" }
+        maven { url 'http://10.10.101.21:8081/artifactory/plugins-release' }
+        mavenCentral()
+        jcenter()
+    }
+    dependencies {
+        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+        classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:${dockerVersion}"
+    }
+}
+
+group 'com.uas.erp'
+version '1.0.0'
+
+apply plugin: 'java'
+apply plugin: "com.palantir.docker"
+apply plugin: "org.springframework.boot"
+
+apply from: "$rootDir/gradle/tasks.gradle"
+apply from: "$rootDir/gradle/dependencies.gradle"
+
+jar {
+    baseName = project.name
+    version = ''
+}
+
+allprojects {
+    sourceCompatibility = 1.7
+}
+
+dependencies {
+    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
+    compile "org.springframework.boot:spring-boot-starter-web"
+    compile "org.springframework.boot:spring-boot-starter-security"
+    compile "org.springframework.session:spring-session"
+    testCompile 'org.springframework.boot:spring-boot-starter-test'
+    compile 'mysql:mysql-connector-java'
+    compile "com.alibaba:fastjson:$fastjsonVersion"
+}

+ 2 - 0
gradle.properties

@@ -0,0 +1,2 @@
+org.gradle.jvmargs=-Xmx1024m
+fastjsonVersion=1.2.14

+ 21 - 0
gradle/dependencies.gradle

@@ -0,0 +1,21 @@
+repositories {
+    mavenLocal()
+    maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
+    maven { url "http://maven.springframework.org/release" }
+    maven {
+        url 'http://10.10.101.21:8081/artifactory/libs-release'
+    }
+    maven {
+        url 'http://10.10.101.21:8081/artifactory/libs-snapshot'
+    }
+    maven {
+        url 'http://10.10.101.21:8081/artifactory/plugins-snapshot'
+    }
+    mavenCentral()
+}
+
+dependencyManagement {
+    imports {
+        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
+    }
+}

+ 9 - 0
gradle/tasks.gradle

@@ -0,0 +1,9 @@
+bootRun {
+    addResources = true
+}
+
+docker {
+    name "${dockerRegistry}/${project.name}:${project.version}"
+    dockerfile "${projectDir}/src/main/docker/Dockerfile"
+    files "${buildDir}/libs/${project.name}.jar"
+}.dependsOn build

+ 2 - 0
settings.gradle

@@ -0,0 +1,2 @@
+rootProject.name = 'uas-manage-server'
+

+ 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-manage-server.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 -Duser.timezone=GMT+08 -Djava.security.egd=file:/dev/./urandom -jar /app.jar --spring.profiles.active=prod"] # To reduce Tomcat startup time we added a system property pointing to "/dev/urandom" as a source of entropy.

+ 16 - 0
src/main/java/com/uas/erp/manage/server/UasManageServerApplication.java

@@ -0,0 +1,16 @@
+package com.uas.erp.manage.server;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@SpringBootApplication
+public class UasManageServerApplication {
+
+    public static void main(String[] args) {
+        new SpringApplicationBuilder(UasManageServerApplication.class).web(true).run(args);
+    }
+
+}

+ 30 - 0
src/main/java/com/uas/erp/manage/server/api/v1/ArtifactController.java

@@ -0,0 +1,30 @@
+package com.uas.erp.manage.server.api.v1;
+
+import com.uas.erp.manage.server.service.ArtifactService;
+import com.uas.erp.manage.server.web.ResponseWrap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@RestController
+@RequestMapping(path = "/v1/program/artifact")
+public class ArtifactController {
+
+    @Autowired
+    private ArtifactService artifactService;
+
+    @GetMapping(path = "/versions")
+    public ResponseEntity getArtifactVersions(String groupId, String artifactId,
+                                              @PageableDefault(size = 15, page = 0, sort = { "version" }, direction = Sort.Direction.DESC) Pageable pageable) {
+        return ResponseWrap.ok(artifactService.getVersions(groupId, artifactId, pageable));
+    }
+
+}

+ 70 - 0
src/main/java/com/uas/erp/manage/server/api/v1/ClientController.java

@@ -0,0 +1,70 @@
+package com.uas.erp.manage.server.api.v1;
+
+import com.uas.erp.manage.server.domain.ClientInfo;
+import com.uas.erp.manage.server.entity.Client;
+import com.uas.erp.manage.server.service.ClientProjectService;
+import com.uas.erp.manage.server.service.ClientContainerService;
+import com.uas.erp.manage.server.service.ClientService;
+import com.uas.erp.manage.server.util.IpUtils;
+import com.uas.erp.manage.server.web.ResponseWrap;
+import org.apache.catalina.servlet4preview.http.HttpServletRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.Assert;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Date;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@RestController
+@RequestMapping(path = "/v1/client")
+public class ClientController {
+
+    @Autowired
+    private ClientService clientService;
+
+    @Autowired
+    private ClientProjectService clientProjectService;
+
+    @Autowired
+    private ClientContainerService clientContainerService;
+
+    @GetMapping(path = "/list")
+    public ResponseEntity getClients(@PageableDefault(size = 15, page = 0, sort = { "name" }) Pageable pageable) {
+        return ResponseWrap.ok(clientService.getClients(pageable));
+    }
+
+    @GetMapping(path = "/{clientId}/projects")
+    public ResponseEntity getClientProjects(@PathVariable("clientId") long clientId) {
+        return ResponseWrap.ok(clientProjectService.findByClient(clientId));
+    }
+
+    @GetMapping(path = "/project/list")
+    public ResponseEntity getClientProjects(@PageableDefault(size = 15, page = 0, sort = { "description" }) Pageable pageable, String description) {
+        return ResponseWrap.ok(clientProjectService.findByDescription(pageable, description));
+    }
+
+    /**
+     * 这个接口给客户端主动发起将信息记录到中心
+     * @param request
+     * @param info
+     * @return
+     */
+    @PostMapping(path = "/info")
+    public ResponseEntity saveClientInfo(HttpServletRequest request, @RequestBody ClientInfo info) {
+        Assert.notNull(info.getClientId());
+        Assert.notNull(info.getName());
+        info.setIp(IpUtils.getIpAddr(request));
+        info.setLastConnectTime(new Date().getTime());
+        Client client = clientService.safetySave(info.getClient());
+        clientProjectService.safetySave(info.getClientProjects(client));
+        clientContainerService.safetySave(info.getClientContainers(client));
+        return ResponseWrap.ok();
+    }
+
+}

+ 46 - 0
src/main/java/com/uas/erp/manage/server/api/v1/DeployController.java

@@ -0,0 +1,46 @@
+package com.uas.erp.manage.server.api.v1;
+
+import com.uas.erp.manage.server.entity.ClientProjectDeployTask;
+import com.uas.erp.manage.server.service.ArtifactService;
+import com.uas.erp.manage.server.service.ClientProjectDeployTaskService;
+import com.uas.erp.manage.server.web.ResponseWrap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@RestController
+@RequestMapping(path = "/v1/program/deploy")
+public class DeployController {
+
+    @Autowired
+    private ClientProjectDeployTaskService clientProjectDeployTaskService;
+
+    @Autowired
+    private ArtifactService artifactService;
+
+    @PostMapping
+    public ResponseEntity addDeployTask(ClientProjectDeployTask task) {
+        if (null == task.getCreateTime()) {
+            task.setCreateTime(System.currentTimeMillis());
+        }
+        if (null == task.getVersion()) {
+            task.setVersion(artifactService.getLastVersion(task.getGroupId(), task.getArtifactId()));
+        }
+        clientProjectDeployTaskService.saveTask(task);
+        return ResponseWrap.ok();
+    }
+
+    @GetMapping(path = "/list")
+    public ResponseEntity getDeployTasks() {
+        return ResponseWrap.ok(clientProjectDeployTaskService.findTasks());
+    }
+
+    @GetMapping(path = "/{taskId}/result")
+    public ResponseEntity getDeployTasketails(@PathVariable("taskId") long taskId) {
+        return ResponseWrap.ok(clientProjectDeployTaskService.findTaskDetails(taskId));
+    }
+
+}

+ 11 - 0
src/main/java/com/uas/erp/manage/server/config/AppConfig.java

@@ -0,0 +1,11 @@
+package com.uas.erp.manage.server.config;
+
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Created by Pro1 on 2017/6/17.
+ */
+@Configuration
+public class AppConfig {
+
+}

+ 23 - 0
src/main/java/com/uas/erp/manage/server/config/ExceptionConfig.java

@@ -0,0 +1,23 @@
+package com.uas.erp.manage.server.config;
+
+import com.uas.erp.manage.server.web.ResponseWrap;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Created by Pro1 on 2017/6/22.
+ */
+@ControllerAdvice
+public class ExceptionConfig {
+
+    @ExceptionHandler(value = Exception.class)
+    @ResponseBody
+    public ResponseEntity defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
+        return ResponseWrap.badRequest(e.getMessage());
+    }
+
+}

+ 62 - 0
src/main/java/com/uas/erp/manage/server/config/WebMvcConfig.java

@@ -0,0 +1,62 @@
+package com.uas.erp.manage.server.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.servlet.LocaleResolver;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
+import org.springframework.web.servlet.i18n.SessionLocaleResolver;
+
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Created by Pro1 on 2017/6/21.
+ */
+@Configuration
+public class WebMvcConfig extends WebMvcConfigurerAdapter {
+
+    @Bean
+    public LocaleResolver localeResolver() {
+        SessionLocaleResolver slr = new SessionLocaleResolver();
+        slr.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
+        return slr;
+    }
+
+    @Bean
+    public LocaleChangeInterceptor localeChangeInterceptor() {
+        LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
+        lci.setParamName("lang");
+        return lci;
+    }
+
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        registry.addInterceptor(localeChangeInterceptor());
+    }
+
+    @Bean
+    public HttpMessageConverter<String> responseBodyConverter() {
+        StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
+        return converter;
+    }
+
+    @Override
+    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
+        super.configureMessageConverters(converters);
+        converters.add(responseBodyConverter());
+    }
+
+    @Bean
+    public RestTemplate restTemplate() {
+        RestTemplate restTemplate = new RestTemplate();
+        restTemplate.getMessageConverters().add(0, responseBodyConverter());
+        return restTemplate;
+    }
+
+}

+ 135 - 0
src/main/java/com/uas/erp/manage/server/config/WebSecurityConfig.java

@@ -0,0 +1,135 @@
+package com.uas.erp.manage.server.config;
+
+import com.uas.erp.manage.server.web.ResponseWrap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.MessageSource;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.i18n.LocaleContextHolder;
+import org.springframework.http.HttpStatus;
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.security.web.access.channel.ChannelProcessingFilter;
+import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+import org.springframework.security.web.util.matcher.AnyRequestMatcher;
+import org.springframework.session.ExpiringSession;
+import org.springframework.session.MapSessionRepository;
+import org.springframework.session.SessionRepository;
+import org.springframework.session.web.http.HeaderHttpSessionStrategy;
+import org.springframework.session.web.http.SessionRepositoryFilter;
+import org.springframework.ui.ModelMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Created by Pro1 on 2017/6/20.
+ */
+@Configuration
+@EnableWebSecurity
+public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
+
+    @Autowired
+    private MessageSource messageSource;
+
+    @Bean
+    public SessionRepository<ExpiringSession> sessionRepository() {
+        return new MapSessionRepository();
+    }
+
+    @Bean
+    public SessionRepositoryFilter<ExpiringSession> sessionRepositoryFilter() {
+        SessionRepositoryFilter<ExpiringSession> sessionRepositoryFilter = new SessionRepositoryFilter<ExpiringSession>(
+                sessionRepository());
+        sessionRepositoryFilter.setHttpSessionStrategy(new HeaderHttpSessionStrategy());
+        return sessionRepositoryFilter;
+    }
+
+    @Override
+    public void configure(WebSecurity web) throws Exception {
+        web.ignoring().antMatchers("/resources/**", "/static/**", "/public/**");
+    }
+
+    @Override
+    public void configure(HttpSecurity http) throws Exception {
+        http.authorizeRequests()
+                .antMatchers("/", "/v1/client/info")
+                .permitAll()
+                .anyRequest()
+                .authenticated()
+                .and()
+                .formLogin()
+                .loginProcessingUrl("/login")
+                .successHandler(authenticationSuccessHandler())
+                .failureHandler(authenticationFailureHandler())
+                .and()
+                .exceptionHandling()
+                .defaultAuthenticationEntryPointFor(jsonAuthenticationEntryPoint(), AnyRequestMatcher.INSTANCE)
+                .and()
+                .logout()
+                .logoutUrl("/logout")
+                .and()
+                .addFilterBefore(sessionRepositoryFilter(), ChannelProcessingFilter.class)
+                .csrf()
+                .disable()
+                .sessionManagement()
+                .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
+    }
+
+    /**
+     * 登录成功时
+     * @return
+     */
+    @Bean
+    public AuthenticationSuccessHandler authenticationSuccessHandler() {
+        return new AuthenticationSuccessHandler() {
+            @Override
+            public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
+                // 客户端保存token,后续每次请求header里面加x-auth-token进行身份验证
+                ResponseWrap.ok(response, new ModelMap("token", request.getSession().getId()));
+            }
+        };
+    }
+
+    /**
+     * 登录失败时
+     * @return
+     */
+    @Bean
+    public AuthenticationFailureHandler authenticationFailureHandler() {
+        return new AuthenticationFailureHandler() {
+            public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
+                ResponseWrap.badRequest(response, messageSource.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", null, LocaleContextHolder.getLocale()));
+            }
+        };
+    }
+
+    /**
+     * 身份信息验证失败时
+     * @return
+     */
+    @Bean
+    public AuthenticationEntryPoint jsonAuthenticationEntryPoint() {
+        return new AuthenticationEntryPoint() {
+            @Override
+            public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
+                ResponseWrap.badRequest(response, HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
+            }
+        };
+    }
+
+    @Autowired
+    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
+        auth.inMemoryAuthentication().withUser("admin").password("select").roles("ADMIN");
+    }
+}

+ 94 - 0
src/main/java/com/uas/erp/manage/server/domain/ClientContainerInfo.java

@@ -0,0 +1,94 @@
+package com.uas.erp.manage.server.domain;
+
+import com.uas.erp.manage.server.entity.Client;
+import com.uas.erp.manage.server.entity.ClientContainer;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+public class ClientContainerInfo {
+
+    private Long containerId;
+
+    private String type;
+
+    private String host;
+
+    private String home;
+
+    private Integer port;
+
+    private String description;
+
+    private String status;
+
+    public Long getContainerId() {
+        return containerId;
+    }
+
+    public void setContainerId(Long containerId) {
+        this.containerId = containerId;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public String getHome() {
+        return home;
+    }
+
+    public void setHome(String home) {
+        this.home = home;
+    }
+
+    public Integer getPort() {
+        return port;
+    }
+
+    public void setPort(Integer port) {
+        this.port = port;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public ClientContainer getClientContainer(Client client) {
+        ClientContainer container = new ClientContainer();
+        container.setDescription(this.description);
+        container.setClientId(client.getId());
+        container.setContainerId(this.containerId);
+        container.setHome(this.home);
+        container.setHost(this.host);
+        container.setPort(this.port);
+        container.setType(this.type);
+        container.setStatus(this.status);
+        return container;
+    }
+
+}

+ 116 - 0
src/main/java/com/uas/erp/manage/server/domain/ClientInfo.java

@@ -0,0 +1,116 @@
+package com.uas.erp.manage.server.domain;
+
+import com.uas.erp.manage.server.entity.Client;
+import com.uas.erp.manage.server.entity.ClientContainer;
+import com.uas.erp.manage.server.entity.ClientProject;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+public class ClientInfo {
+
+    private String clientId;
+
+    private String name;
+
+    private String ip;
+
+    private String basePath;
+
+    private Long lastConnectTime;
+
+    private List<ClientContainerInfo> containers;
+
+    private List<ClientProjectInfo> projects;
+
+    public String getClientId() {
+        return clientId;
+    }
+
+    public void setClientId(String clientId) {
+        this.clientId = clientId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    public String getBasePath() {
+        return basePath;
+    }
+
+    public void setBasePath(String basePath) {
+        this.basePath = basePath;
+    }
+
+    public Long getLastConnectTime() {
+        return lastConnectTime;
+    }
+
+    public void setLastConnectTime(Long lastConnectTime) {
+        this.lastConnectTime = lastConnectTime;
+    }
+
+    public List<ClientProjectInfo> getProjects() {
+        return projects;
+    }
+
+    public void setProjects(List<ClientProjectInfo> projects) {
+        this.projects = projects;
+    }
+
+    public List<ClientContainerInfo> getContainers() {
+        return containers;
+    }
+
+    public void setContainers(List<ClientContainerInfo> containers) {
+        this.containers = containers;
+    }
+
+    public Client getClient() {
+        Client client = new Client();
+        client.setClientId(this.clientId);
+        client.setLastConnectTime(this.lastConnectTime);
+        client.setIp(this.ip);
+        client.setBasePath(this.basePath);
+        client.setName(this.name);
+        return client;
+    }
+
+    public List<ClientProject> getClientProjects(Client client) {
+        List<ClientProject> projects = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(this.projects)) {
+            for (ClientProjectInfo info:this.projects) {
+                projects.add(info.getClientProject(client));
+            }
+        }
+        return projects;
+    }
+
+    public List<ClientContainer> getClientContainers(Client client) {
+        List<ClientContainer> containers = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(this.containers)) {
+            for (ClientContainerInfo info:this.containers) {
+                containers.add(info.getClientContainer(client));
+            }
+        }
+        return containers;
+    }
+
+}

+ 92 - 0
src/main/java/com/uas/erp/manage/server/domain/ClientProjectInfo.java

@@ -0,0 +1,92 @@
+package com.uas.erp.manage.server.domain;
+
+import com.uas.erp.manage.server.entity.Client;
+import com.uas.erp.manage.server.entity.ClientProject;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+public class ClientProjectInfo {
+
+    private Long projectId;
+
+    private String groupId;
+
+    private String artifactId;
+
+    private String description;
+
+    private String contextName;
+
+    private String deployVersion;
+
+    private Long deployTime;
+
+    public Long getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(Long projectId) {
+        this.projectId = projectId;
+    }
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getContextName() {
+        return contextName;
+    }
+
+    public void setContextName(String contextName) {
+        this.contextName = contextName;
+    }
+
+    public String getDeployVersion() {
+        return deployVersion;
+    }
+
+    public void setDeployVersion(String deployVersion) {
+        this.deployVersion = deployVersion;
+    }
+
+    public Long getDeployTime() {
+        return deployTime;
+    }
+
+    public void setDeployTime(Long deployTime) {
+        this.deployTime = deployTime;
+    }
+
+    public ClientProject getClientProject(Client client) {
+        ClientProject project = new ClientProject();
+        project.setDescription(this.getDescription());
+        project.setArtifactId(this.getArtifactId());
+        project.setGroupId(this.getGroupId());
+        project.setProjectId(this.getProjectId());
+        project.setClientId(client.getId());
+        project.setDeployVersion(this.getDeployVersion());
+        project.setDeployTime(this.getDeployTime());
+        return project;
+    }
+}

+ 57 - 0
src/main/java/com/uas/erp/manage/server/domain/ProjectVersion.java

@@ -0,0 +1,57 @@
+package com.uas.erp.manage.server.domain;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+public class ProjectVersion {
+
+    private String groupId;
+
+    private String artifactId;
+
+    private String version;
+
+    private Long versionTime;
+
+    private Long createTime;
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public Long getVersionTime() {
+        return versionTime;
+    }
+
+    public void setVersionTime(Long versionTime) {
+        this.versionTime = versionTime;
+    }
+
+    public Long getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Long createTime) {
+        this.createTime = createTime;
+    }
+}

+ 76 - 0
src/main/java/com/uas/erp/manage/server/entity/Client.java

@@ -0,0 +1,76 @@
+package com.uas.erp.manage.server.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Entity
+public class Client {
+
+    @Id
+    @GeneratedValue
+    private Long id;
+
+    @Column(unique = true)
+    private String clientId;
+
+    private String name;
+
+    private String ip;
+
+    private String basePath;
+
+    private Long lastConnectTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getClientId() {
+        return clientId;
+    }
+
+    public void setClientId(String clientId) {
+        this.clientId = clientId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    public String getBasePath() {
+        return basePath;
+    }
+
+    public void setBasePath(String basePath) {
+        this.basePath = basePath;
+    }
+
+    public Long getLastConnectTime() {
+        return lastConnectTime;
+    }
+
+    public void setLastConnectTime(Long lastConnectTime) {
+        this.lastConnectTime = lastConnectTime;
+    }
+}

+ 103 - 0
src/main/java/com/uas/erp/manage/server/entity/ClientContainer.java

@@ -0,0 +1,103 @@
+package com.uas.erp.manage.server.entity;
+
+import javax.persistence.*;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Entity
+@Table(indexes = {@Index(columnList = "clientId,containerId", unique = true)})
+public class ClientContainer {
+
+    @Id
+    @GeneratedValue
+    private Long id;
+
+    private Long clientId;
+
+    private Long containerId;
+
+    private String type;
+
+    private String host;
+
+    private String home;
+
+    private Integer port;
+
+    private String description;
+
+    private String status;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getClientId() {
+        return clientId;
+    }
+
+    public void setClientId(Long clientId) {
+        this.clientId = clientId;
+    }
+
+    public Long getContainerId() {
+        return containerId;
+    }
+
+    public void setContainerId(Long containerId) {
+        this.containerId = containerId;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public String getHome() {
+        return home;
+    }
+
+    public void setHome(String home) {
+        this.home = home;
+    }
+
+    public Integer getPort() {
+        return port;
+    }
+
+    public void setPort(Integer port) {
+        this.port = port;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+}

+ 103 - 0
src/main/java/com/uas/erp/manage/server/entity/ClientProject.java

@@ -0,0 +1,103 @@
+package com.uas.erp.manage.server.entity;
+
+import javax.persistence.*;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Entity
+@Table(indexes = {@Index(columnList = "clientId,projectId", unique = true)})
+public class ClientProject {
+
+    @Id
+    @GeneratedValue
+    private Long id;
+
+    private Long clientId;
+
+    private Long projectId;
+
+    private String groupId;
+
+    private String artifactId;
+
+    private String description;
+
+    private String contextName;
+
+    private String deployVersion;
+
+    private Long deployTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getClientId() {
+        return clientId;
+    }
+
+    public void setClientId(Long clientId) {
+        this.clientId = clientId;
+    }
+
+    public Long getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(Long projectId) {
+        this.projectId = projectId;
+    }
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getContextName() {
+        return contextName;
+    }
+
+    public void setContextName(String contextName) {
+        this.contextName = contextName;
+    }
+
+    public String getDeployVersion() {
+        return deployVersion;
+    }
+
+    public void setDeployVersion(String deployVersion) {
+        this.deployVersion = deployVersion;
+    }
+
+    public Long getDeployTime() {
+        return deployTime;
+    }
+
+    public void setDeployTime(Long deployTime) {
+        this.deployTime = deployTime;
+    }
+}

+ 74 - 0
src/main/java/com/uas/erp/manage/server/entity/ClientProjectDeployTask.java

@@ -0,0 +1,74 @@
+package com.uas.erp.manage.server.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Entity
+public class ClientProjectDeployTask {
+
+    @Id
+    @GeneratedValue
+    private Long id;
+
+    private Long createTime;
+
+    private String groupId;
+
+    private String artifactId;
+
+    private String version;
+
+    public ClientProjectDeployTask() {
+    }
+
+    public ClientProjectDeployTask(String groupId, String artifactId, String version) {
+        this.groupId = groupId;
+        this.artifactId = artifactId;
+        this.version = version;
+        this.createTime = System.currentTimeMillis();
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Long createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+}

+ 109 - 0
src/main/java/com/uas/erp/manage/server/entity/ClientProjectDeployTaskItem.java

@@ -0,0 +1,109 @@
+package com.uas.erp.manage.server.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Entity
+public class ClientProjectDeployTaskItem {
+
+    @Id
+    @GeneratedValue
+    private Long id;
+
+    private Long clientProjectId;
+
+    private Long taskId;
+
+    private Long startTime;
+
+    private Long endTime;
+
+    private String message;
+
+    private boolean success;
+
+    private String status;
+
+    public ClientProjectDeployTaskItem() {
+        this.status = Status.READY.name();
+    }
+
+    public ClientProjectDeployTaskItem(ClientProjectDeployTask task, ClientProject project) {
+        this();
+        this.clientProjectId = project.getId();
+        this.taskId = task.getId();
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getClientProjectId() {
+        return clientProjectId;
+    }
+
+    public void setClientProjectId(Long clientProjectId) {
+        this.clientProjectId = clientProjectId;
+    }
+
+    public Long getTaskId() {
+        return taskId;
+    }
+
+    public void setTaskId(Long taskId) {
+        this.taskId = taskId;
+    }
+
+    public Long getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Long startTime) {
+        this.startTime = startTime;
+    }
+
+    public Long getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Long endTime) {
+        this.endTime = endTime;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public boolean isSuccess() {
+        return success;
+    }
+
+    public void setSuccess(boolean success) {
+        this.success = success;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public static enum Status {
+        READY,RUNNING,FINISHED
+    }
+
+}

+ 27 - 0
src/main/java/com/uas/erp/manage/server/repository/ClientContainerRepository.java

@@ -0,0 +1,27 @@
+package com.uas.erp.manage.server.repository;
+
+import com.uas.erp.manage.server.entity.ClientContainer;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Repository
+public interface ClientContainerRepository extends JpaRepository<ClientContainer, Long> {
+
+    List<ClientContainer> findByClientId(long clientId);
+
+    ClientContainer findByClientIdAndContainerId(long clientId, long containerId);
+
+    @Modifying
+    @Transactional
+    @Query("delete from ClientContainer c where c.clientId = ?1 and c.containerId not in (?2)")
+    void deleteByClientIdNotInContainerIds(long clientId,  List<Long> containerIds);
+
+}

+ 17 - 0
src/main/java/com/uas/erp/manage/server/repository/ClientProjectDeployTaskItemRepository.java

@@ -0,0 +1,17 @@
+package com.uas.erp.manage.server.repository;
+
+import com.uas.erp.manage.server.entity.ClientProjectDeployTaskItem;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Repository
+public interface ClientProjectDeployTaskItemRepository extends JpaRepository<ClientProjectDeployTaskItem, Long>{
+
+    List<ClientProjectDeployTaskItem> findByTaskId(long taskId);
+
+}

+ 12 - 0
src/main/java/com/uas/erp/manage/server/repository/ClientProjectDeployTaskRepository.java

@@ -0,0 +1,12 @@
+package com.uas.erp.manage.server.repository;
+
+import com.uas.erp.manage.server.entity.ClientProjectDeployTask;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Repository
+public interface ClientProjectDeployTaskRepository extends JpaRepository<ClientProjectDeployTask, Long>{
+}

+ 24 - 0
src/main/java/com/uas/erp/manage/server/repository/ClientProjectRepository.java

@@ -0,0 +1,24 @@
+package com.uas.erp.manage.server.repository;
+
+import com.uas.erp.manage.server.entity.ClientProject;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Repository
+public interface ClientProjectRepository extends JpaRepository<ClientProject, Long>, JpaSpecificationExecutor<ClientProject>{
+
+    List<ClientProject> findByClientId(long clientId);
+
+    List<ClientProject> findByClientIdAndGroupIdAndArtifactId(long clientId, String groupId, String artifactId);
+
+    List<ClientProject> findByGroupIdAndArtifactId(String groupId, String artifactId);
+
+    ClientProject findByClientIdAndProjectId(long clientId, long projectId);
+
+}

+ 15 - 0
src/main/java/com/uas/erp/manage/server/repository/ClientRepository.java

@@ -0,0 +1,15 @@
+package com.uas.erp.manage.server.repository;
+
+import com.uas.erp.manage.server.entity.Client;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Repository
+public interface ClientRepository extends JpaRepository<Client, Long> {
+
+    Client findByClientId(String clientId);
+
+}

+ 34 - 0
src/main/java/com/uas/erp/manage/server/service/ArtifactService.java

@@ -0,0 +1,34 @@
+package com.uas.erp.manage.server.service;
+
+import com.uas.erp.manage.server.domain.ProjectVersion;
+import com.uas.erp.manage.server.util.RestUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Service
+public class ArtifactService {
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @Value("${repository.url}")
+    private String repositoryUrl;
+
+    public Page<ProjectVersion> getVersions(String groupId, String artifactId, Pageable pageable) {
+        return RestUtils.getForPage(restTemplate, repositoryUrl + "/version/list?groupId={groupId}&artifactId={artifactId}",
+                pageable, groupId, artifactId);
+    }
+
+    public String getLastVersion(String groupId, String artifactId) {
+        return restTemplate.getForObject(repositoryUrl + "/version?groupId={groupId}&artifactId={artifactId}", String.class,
+                groupId, artifactId);
+    }
+
+}

+ 45 - 0
src/main/java/com/uas/erp/manage/server/service/ClientContainerService.java

@@ -0,0 +1,45 @@
+package com.uas.erp.manage.server.service;
+
+import com.uas.erp.manage.server.repository.ClientContainerRepository;
+import com.uas.erp.manage.server.entity.ClientContainer;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Service
+public class ClientContainerService {
+
+    @Autowired
+    private ClientContainerRepository clientContainerRepository;
+
+    public List<ClientContainer> findByClient(long clientId) {
+        return clientContainerRepository.findByClientId(clientId);
+    }
+
+    public ClientContainer safetySave(ClientContainer container) {
+        ClientContainer oldOne = clientContainerRepository.findByClientIdAndContainerId(container.getClientId(), container.getContainerId());
+        if (null != oldOne) {
+            container.setId(oldOne.getId());
+        }
+        return clientContainerRepository.save(oldOne);
+    }
+
+    public void safetySave(List<ClientContainer> containers) {
+        if (!CollectionUtils.isEmpty(containers)) {
+            List<Long> containerIds = new ArrayList<Long>();
+            for (ClientContainer container : containers) {
+                container = safetySave(container);
+                containerIds.add(container.getContainerId());
+            }
+            containers = findByClient(containers.get(0).getId());
+            clientContainerRepository.deleteByClientIdNotInContainerIds(containers.get(0).getId(), containerIds);
+        }
+    }
+
+}

+ 50 - 0
src/main/java/com/uas/erp/manage/server/service/ClientProjectDeployTaskService.java

@@ -0,0 +1,50 @@
+package com.uas.erp.manage.server.service;
+
+import com.uas.erp.manage.server.entity.ClientProject;
+import com.uas.erp.manage.server.entity.ClientProjectDeployTask;
+import com.uas.erp.manage.server.entity.ClientProjectDeployTaskItem;
+import com.uas.erp.manage.server.repository.ClientProjectDeployTaskItemRepository;
+import com.uas.erp.manage.server.repository.ClientProjectDeployTaskRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Service
+public class ClientProjectDeployTaskService {
+
+    @Autowired
+    private ClientProjectDeployTaskRepository clientProjectDeployTaskRepository;
+
+    @Autowired
+    private ClientProjectDeployTaskItemRepository clientProjectDeployTaskItemRepository;
+
+    @Autowired
+    private ClientService clientService;
+
+    @Autowired
+    private ClientProjectService clientProjectService;
+
+    public void saveTask(ClientProjectDeployTask task) {
+        task = clientProjectDeployTaskRepository.save(task);
+        List<ClientProject> projects = clientProjectService.findByGroupIdAndArtifactId(task.getGroupId(), task.getArtifactId());
+        if (!CollectionUtils.isEmpty(projects)) {
+            for (ClientProject project:projects) {
+                clientProjectService.runDeployTask(project, task);
+            }
+        }
+    }
+
+    public List<ClientProjectDeployTask> findTasks() {
+        return clientProjectDeployTaskRepository.findAll();
+    }
+
+    public List<ClientProjectDeployTaskItem> findTaskDetails(long taskId) {
+        return clientProjectDeployTaskItemRepository.findByTaskId(taskId);
+    }
+
+}

+ 109 - 0
src/main/java/com/uas/erp/manage/server/service/ClientProjectService.java

@@ -0,0 +1,109 @@
+package com.uas.erp.manage.server.service;
+
+import com.uas.erp.manage.server.entity.Client;
+import com.uas.erp.manage.server.entity.ClientProject;
+import com.uas.erp.manage.server.entity.ClientProjectDeployTask;
+import com.uas.erp.manage.server.entity.ClientProjectDeployTaskItem;
+import com.uas.erp.manage.server.repository.ClientProjectDeployTaskItemRepository;
+import com.uas.erp.manage.server.repository.ClientProjectRepository;
+import com.uas.erp.manage.server.web.ResultWrap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.client.RestTemplate;
+
+import javax.persistence.criteria.*;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Service
+public class ClientProjectService {
+
+    @Autowired
+    private ClientService clientService;
+
+    @Autowired
+    private ClientProjectRepository clientProjectRepository;
+
+    @Autowired
+    private ClientProjectDeployTaskItemRepository clientProjectDeployTaskItemRepository;
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    public List<ClientProject> findByClient(long clientId) {
+        return clientProjectRepository.findByClientId(clientId);
+    }
+
+    public List<ClientProject> findByGroupIdAndArtifactId(String groupId, String artifactId) {
+        return clientProjectRepository.findByGroupIdAndArtifactId(groupId, artifactId);
+    }
+
+    public List<ClientProject> findByClientIdAndGroupIdAndArtifactId(long clientId, String groupId, String artifactId) {
+        return clientProjectRepository.findByClientIdAndGroupIdAndArtifactId(clientId, groupId, artifactId);
+    }
+
+    /**
+     * 分页查询
+     * @param pageable
+     * @return
+     */
+    public Page<ClientProject> findByDescription(Pageable pageable, final String description) {
+        return clientProjectRepository.findAll(new Specification<ClientProject>() {
+            @Override
+            public Predicate toPredicate(Root<ClientProject> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
+                Path<String> desc = root.get("description");
+                return criteriaBuilder.like(desc, "%" + description + "%");
+            }
+        }, pageable);
+    }
+
+    public void safetySave(ClientProject project) {
+        ClientProject oldOne = clientProjectRepository.findByClientIdAndProjectId(project.getClientId(), project.getProjectId());
+        if (null != oldOne) {
+            project.setId(oldOne.getId());
+        }
+        clientProjectRepository.save(project);
+    }
+
+    public void safetySave(List<ClientProject> projects) {
+        if (!CollectionUtils.isEmpty(projects))
+            for (ClientProject project:projects) {
+                safetySave(project);
+            }
+    }
+
+    @Async
+    public void runDeployTask(ClientProject project, ClientProjectDeployTask task) {
+        Client client = clientService.getClient(project.getClientId());
+        ClientProjectDeployTaskItem taskItem = new ClientProjectDeployTaskItem(task, project);
+        taskItem = clientProjectDeployTaskItemRepository.save(taskItem);
+        taskItem.setStartTime(new Date().getTime());
+        taskItem.setStatus(ClientProjectDeployTaskItem.Status.RUNNING.name());
+        taskItem = clientProjectDeployTaskItemRepository.save(taskItem);
+        try {
+            ResultWrap<String> result = restTemplate.getForObject(client.getBasePath() + "/v1/project/{projectId}/deploy",
+                    ResultWrap.class, project.getProjectId());
+            if (result.isSuccess()) {
+                taskItem.setSuccess(true);
+            } else {
+                taskItem.setMessage(result.getMessage());
+            }
+        } catch (Exception e) {
+            taskItem.setSuccess(false);
+            taskItem.setMessage(e.getMessage());
+        } finally {
+            taskItem.setStatus(ClientProjectDeployTaskItem.Status.FINISHED.name());
+            taskItem.setEndTime(new Date().getTime());
+            clientProjectDeployTaskItemRepository.save(taskItem);
+        }
+    }
+
+}

+ 55 - 0
src/main/java/com/uas/erp/manage/server/service/ClientService.java

@@ -0,0 +1,55 @@
+package com.uas.erp.manage.server.service;
+
+import com.uas.erp.manage.server.entity.Client;
+import com.uas.erp.manage.server.repository.ClientRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+@Service
+public class ClientService {
+
+    @Autowired
+    private ClientRepository clientRepository;
+
+    public Client getClient(long id) {
+        return clientRepository.findOne(id);
+    }
+
+    /**
+     * 分页查询
+     * @param pageable
+     * @return
+     */
+    public Page<Client> getClients(Pageable pageable) {
+        return clientRepository.findAll(pageable);
+    }
+
+    /**
+     * 查找全部
+     * @return
+     */
+    public List<Client> getClients() {
+        return clientRepository.findAll();
+    }
+
+    /**
+     * 保存
+     * @param client
+     * @return
+     */
+    public Client safetySave(Client client) {
+        Client oldOne = clientRepository.findByClientId(client.getClientId());
+        if (null != oldOne) {
+            client.setId(oldOne.getId());
+        }
+        return clientRepository.save(client);
+    }
+
+}

+ 43 - 0
src/main/java/com/uas/erp/manage/server/util/IpUtils.java

@@ -0,0 +1,43 @@
+package com.uas.erp.manage.server.util;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+public class IpUtils {
+
+    public static String getIpAddr(HttpServletRequest request) {
+        String ip = request.getHeader("x-forwarded-for");
+        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("Proxy-Client-IP");
+        }
+        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("x-host");
+        }
+        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("WL-Proxy-Client-IP");
+        }
+        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getRemoteAddr();
+            if(ip.equals("127.0.0.1")){
+                InetAddress inet = null;
+                try {
+                    inet = InetAddress.getLocalHost();
+                } catch (UnknownHostException e) {
+                    e.printStackTrace();
+                }
+                ip= inet.getHostAddress();
+            }
+        }
+        if (ip != null && ip.length() > 15){
+            if (ip.indexOf(",")>0){
+                ip = ip.substring(0,ip.indexOf(","));
+            }
+        }
+        return ip;
+    }
+
+}

+ 26 - 0
src/main/java/com/uas/erp/manage/server/util/RestUtils.java

@@ -0,0 +1,26 @@
+package com.uas.erp.manage.server.util;
+
+import com.uas.erp.manage.server.web.RestPage;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Created by Pro1 on 2017/7/20.
+ */
+public class RestUtils {
+
+    public static <T> Page<T> getForPage(RestTemplate restTemplate, String uri, Pageable pageable, Object...vars) {
+        ParameterizedTypeReference<RestPage<T>> responseType = new ParameterizedTypeReference<RestPage<T>>(){};
+        StringBuffer pageUri = new StringBuffer(uri);
+        pageUri.append(uri.contains("?") ? "&" : "?").append("page=").append(pageable.getPageNumber());
+        pageUri.append("&size=").append(pageable.getPageSize());
+//        pageUri.append("&sort=").append(pageable.getSort().toString());
+        ResponseEntity<RestPage<T>> result = restTemplate.exchange(pageUri.toString(), HttpMethod.GET, null, responseType, vars);
+        return result.getBody().getPage();
+    }
+
+}

+ 97 - 0
src/main/java/com/uas/erp/manage/server/web/ResponseWrap.java

@@ -0,0 +1,97 @@
+package com.uas.erp.manage.server.web;
+
+import com.alibaba.fastjson.JSON;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.ui.ModelMap;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * Created by Pro1 on 2017/6/20.
+ */
+public class ResponseWrap {
+
+    private static final String successParam = "success";
+
+    private static final String responseCodeParam = "code";
+
+    private static final String responseMessageParam = "message";
+
+    private static final String responseContentParam = "content";
+
+    public static ModelMap success() {
+        return new ModelMap(successParam, true);
+    }
+
+    public static <T> ModelMap success(T content) {
+        return success().addAttribute(responseContentParam, content);
+    }
+
+    public static ModelMap error() {
+        return new ModelMap(successParam, false);
+    }
+
+    public static ModelMap error(String message) {
+        return error().addAttribute(responseMessageParam, message);
+    }
+
+    public static <T> ModelMap error(int code) {
+        return error().addAttribute(responseCodeParam, code);
+    }
+
+    public static <T> ModelMap error(int code, String message) {
+        return error(code).addAttribute(responseMessageParam, message);
+    }
+
+    public static ResponseEntity ok() {
+        return ResponseEntity.ok(success());
+    }
+
+    public static <T> ResponseEntity ok(T content) {
+        return ResponseEntity.ok(success(content));
+    }
+
+    public static <T> void ok(HttpServletResponse response, T content) throws IOException{
+        response.setStatus(HttpStatus.OK.value());
+        response.setContentType(MediaType.APPLICATION_JSON_UTF8.toString());
+        PrintWriter printWriter = response.getWriter();
+        printWriter.append(JSON.toJSONString(success(content)));
+        printWriter.flush();
+        printWriter.close();
+    }
+
+    public static <T> void ok(HttpServletResponse response) throws IOException {
+        ok(response, null);
+    }
+
+    public static ResponseEntity badRequest() {
+        // do not use ResponseEntity.badRequest()
+        return ResponseEntity.ok(error());
+    }
+
+    public static <T> ResponseEntity badRequest(String message) {
+        return ResponseEntity.ok(error(message));
+    }
+
+    public static <T> void badRequest(HttpServletResponse response, int code, String message) throws IOException{
+        response.setStatus(HttpStatus.OK.value());
+        response.setContentType(MediaType.APPLICATION_JSON_UTF8.toString());
+        PrintWriter printWriter = response.getWriter();
+        printWriter.append(JSON.toJSONString(error(code, message)));
+        printWriter.flush();
+        printWriter.close();
+    }
+
+    public static <T> void badRequest(HttpServletResponse response, String message) throws IOException {
+        badRequest(response, HttpStatus.BAD_REQUEST.value(), message);
+    }
+
+    public static <T> void badRequest(HttpServletResponse response) throws IOException {
+        badRequest(response, HttpStatus.BAD_REQUEST.value(), null);
+    }
+
+}

+ 52 - 0
src/main/java/com/uas/erp/manage/server/web/RestPage.java

@@ -0,0 +1,52 @@
+package com.uas.erp.manage.server.web;
+
+import org.springframework.data.domain.*;
+
+import java.util.List;
+
+/**
+ * Created by Pro1 on 2017/7/20.
+ */
+public class RestPage<T>{
+
+    private int number;
+    private int size;
+    private int totalElements;
+    private List<T> content;
+
+    public List<T> getContent() {
+        return content;
+    }
+
+    public void setContent(List<T> content) {
+        this.content = content;
+    }
+
+    public int getNumber() {
+        return number;
+    }
+
+    public void setNumber(int number) {
+        this.number = number;
+    }
+
+    public int getSize() {
+        return size;
+    }
+
+    public void setSize(int size) {
+        this.size = size;
+    }
+
+    public int getTotalElements() {
+        return totalElements;
+    }
+
+    public void setTotalElements(int totalElements) {
+        this.totalElements = totalElements;
+    }
+
+    public Page<T> getPage() {
+        return new PageImpl<T>(this.content, new PageRequest(this.number, this.size), this.totalElements);
+    }
+}

+ 47 - 0
src/main/java/com/uas/erp/manage/server/web/ResultWrap.java

@@ -0,0 +1,47 @@
+package com.uas.erp.manage.server.web;
+
+/**
+ * Created by Pro1 on 2017/6/23.
+ */
+public class ResultWrap<T> {
+
+    private boolean success;
+
+    private Integer code;
+
+    private String message;
+
+    private T content;
+
+    public boolean isSuccess() {
+        return success;
+    }
+
+    public void setSuccess(boolean success) {
+        this.success = success;
+    }
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public void setCode(Integer code) {
+        this.code = code;
+    }
+
+    public T getContent() {
+        return content;
+    }
+
+    public void setContent(T content) {
+        this.content = content;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+}

+ 30 - 0
src/main/resources/application.yml

@@ -0,0 +1,30 @@
+server:
+  port: 23001
+  contextPath: /uas_manage_server
+  tomcat:
+    uri-encoding: UTF-8
+spring:
+  application:
+    name: uas-manage-server
+  http:
+    encoding:
+      force: true
+      charset: utf-8
+      enabled: true
+  messages:
+    basename: i18n/messages
+  datasource:
+    url: jdbc:mysql://10.10.100.18:3306/uas_manage_server?characterEncoding=utf-8
+    username: root
+    password: select
+    driverClassName: com.mysql.jdbc.Driver
+  jpa:
+    database: MYSQL
+    show-sql: false
+    hibernate:
+      ddl-auto: update
+      naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
+      dialect: org.hibernate.dialect.MySQL5Dialect
+
+repository:
+  url: http://10.10.100.23:23000/v1