Переглянути джерело

通过将配置项存数据库

guo00guo 4 роки тому
батько
коміт
f51dc49657

+ 3 - 7
core/src/main/java/com/mooctest/crowd/domain/dao/ConfigurationDao.java

@@ -1,17 +1,13 @@
 package com.mooctest.crowd.domain.dao;
 
-import com.mooctest.crowd.domain.model.ExpertPO;
-import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import com.mooctest.crowd.domain.model.ConfigurationPO;
 import org.springframework.data.repository.CrudRepository;
 
 import javax.transaction.Transactional;
 import java.util.List;
-import java.util.Optional;
 
 @Transactional
-public interface ExpertDao extends CrudRepository<ExpertPO, Long>, JpaSpecificationExecutor<ExpertPO> {
+public interface ConfigurationDao extends CrudRepository<ConfigurationPO, Long> {
 
-    Optional<ExpertPO> findById(Long id);
-
-    List<ExpertPO> findAll();
+    List<ConfigurationPO> findAll();
 }

+ 2 - 12
core/src/main/java/com/mooctest/crowd/domain/domainobject/Configuration.java

@@ -1,23 +1,13 @@
-package com.mooctest.crowd.domain.model;
+package com.mooctest.crowd.domain.domainobject;
 
 import lombok.Data;
 
-import javax.persistence.*;
-
 /**
  * @author guochao
  */
 @Data
-@Entity(name = "configuration")
-public class ConfigurationPO {
-    @Id
-    @Column(name = "CF_ID")
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
+public class Configuration {
     private Long id;
-
-    @Column(name = "CF_NAME")
     private String name;
-
-    @Column(name = "CF_VALUE")
     private String value;
 }

+ 6 - 14
core/src/main/java/com/mooctest/crowd/domain/model/ConfigurationPO.java

@@ -6,26 +6,18 @@ import javax.persistence.*;
 
 /**
  * @author guochao
- * @date 2019/7/6 17:54
  */
 @Data
-@Entity(name = "expert")
-public class ExpertPO {
+@Entity(name = "configuration")
+public class ConfigurationPO {
     @Id
-    @Column(name = "E_ID")
+    @Column(name = "CF_ID")
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     private Long id;
 
-    @Column(name = "E_NAME")
+    @Column(name = "CF_NAME")
     private String name;
 
-    @Column(name = "E_PHOTO")
-    private String photo;
-
-    @Column(name = "E_TITLE")
-    private String title;
-
-    @Column(name = "E_INTRODUCTION")
-    private String introduction;
-    
+    @Column(name = "CF_VALUE")
+    private String value;
 }

+ 8 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/CommonRepo.java

@@ -63,6 +63,9 @@ public class CommonRepo {
     @Autowired
     private CrowdTestProjectDao crowdTestProjectDao;
 
+    @Autowired
+    private ConfigurationDao configurationDao;
+
     public List<TestType> getAllTestType() {
         return testTypeDao.findAll().stream().map(testTypePO -> Converter.convert(TestType.class, testTypePO)).collect(Collectors.toList());
     }
@@ -314,4 +317,9 @@ public class CommonRepo {
         }
         return testTypePO.get().getCode();
     }
+
+    public Map<String, String> getConfigurationList() {
+        Map<String, String> configurationMap = configurationDao.findAll().stream().collect(Collectors.toMap(configurationPO -> configurationPO.getName(), configurationPO -> configurationPO.getValue()));
+        return configurationMap;
+    }
 }

+ 0 - 42
core/src/main/resources/application.yml

@@ -1,42 +0,0 @@
-spring:
-  cache:
-    guava:
-      spec: expireAfterWrite=30s
-  datasource:
-#    type: com.alibaba.druid.pool.DruidDataSource
-#    druid:
-#      initial-size: 5
-#      max-active: 20
-    driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://101.37.175.111:3306/crowd-test-service?useSSL=false&useUnicode=yes&characterEncoding=UTF-8
-    username: mooctest
-    password: secr3t!
-    initialPoolSize: 5
-      # Keep the connection alive if idle for a long time (needed in production)
-    testWhileIdle: true
-    validationQuery: SELECT 1
-
-    minPoolSize: 5
-    maxPoolSize: 1000
-  # Show or not log for each sql query
-  jpa:
-    show-sql: true
-  # Hibernate ddl auto (create, create-drop, update)
-  hibernate:
-    ddl-auto: validate
-    #hbm2ddl.auto: update
-    # Naming strategy
-    naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
-  # The SQL dialect makes Hibernate generate better SQL for the chosen database
-  properties.hibernate.dialect: org.hibernate.dialect.MySQL5Dialect
-
-role-list:
-  general-user: 1
-  evaluation-agency: 2
-  regional-manager: 3
-  system-administrator: 4
-  enterprise-user: 5
-
-
-#swagger:
-#  enable: true

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
site/src/main/java/com/mooctest/crowd/site/controller/CommonController.java


+ 13 - 2
site/src/main/java/com/mooctest/crowd/site/data/vo/ConfigurationVO.java

@@ -1,13 +1,24 @@
-package com.mooctest.crowd.domain.domainobject;
+package com.mooctest.crowd.site.data.vo;
 
+import com.mooctest.crowd.domain.domainobject.Configuration;
 import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
 
 /**
  * @author guochao
  */
 @Data
-public class Configuration {
+@NoArgsConstructor
+public class ConfigurationVO implements Serializable{
     private Long id;
     private String name;
     private String value;
+
+    public ConfigurationVO(Configuration configuration){
+        id = configuration.getId();
+        name = configuration.getName();
+        value = configuration.getValue();
+    }
 }

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/service/CommonService.java

@@ -56,4 +56,6 @@ public interface CommonService {
     List<HashMap<String, Long>> getStatisticsCount();
 
     List<Map.Entry<String, Long>> getAgencyProjectCount();
+
+    Map<String, String> getConfigurationList();
 }

+ 6 - 0
site/src/main/java/com/mooctest/crowd/site/service/impl/CommonServiceImpl.java

@@ -318,6 +318,12 @@ public class CommonServiceImpl implements CommonService {
         return resultList.stream().filter(result -> !result.getValue().equals(0L)).collect(Collectors.toList());
     }
 
+    @Override
+    public Map<String, String> getConfigurationList() {
+        return commonRepo.getConfigurationList();
+
+    }
+
     Pageable getPageable(SearchConditionVO searchConditionVO) {
         int activePage = searchConditionVO.getActivePage() == 0 ? 1 : searchConditionVO.getActivePage();
         Sort sort = new Sort(Sort.Direction.DESC, "id");

+ 74 - 17
site/src/main/resources/application.yml

@@ -1,6 +1,6 @@
 spring:
   profiles:
-     active: private
+    active: private-cloud-localhost
   cache:
     guava:
       spec: expireAfterWrite=30s
@@ -40,22 +40,79 @@ green:
 
 ---
 spring:
-  profiles: private
+  profiles: private-cloud
   datasource:
-    url: jdbc:mysql://101.37.175.111:3306/crowd-test-service-private?useSSL=false&useUnicode=yes&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
-    username: mooctest
-    password: secr3t!
+    url: jdbc:mysql://mysql:3306/crowd-test-service?useSSL=false&useUnicode=yes&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
+    username: root
+    password: Customs2019
+  #  redis:
+  #    host: redis
+  #    port: 6379
+  #    #    password: '#2019@callforttest@!'
+  #    jedis:
+  #      pool:
+  #        max-active: 8
+  #        max-idle: 8
+  #        max-wait: -1
+  #        min-idle: 0
+  #    database: 0
+
   redis:
-    host: 59.42.10.53
-    pool: 6379
-    password: '#2019@callforttest@!'
-    jedis:
-      pool:
-        max-active: 8
-        max-idle: 8
-        max-wait: -1
-        min-idle: 0
-    database: 6
+    host: redis
+    password:
+    pool:
+      max-active: 8
+      max-idle: 8
+      max-wait: -1
+      min-idle: 0
+    port: 6379
+
+feature:
+  client:
+    oss: false
+
+file:
+  save:
+    path: /var/www/
+
+user:
+  service:
+    baseUrl: http://crowd_user:8081
+#    baseUrl: http://59.42.10.53:8081
+
+website:
+  domain: 127.0.0.1
+
+
+
+---
+spring:
+  profiles: private-cloud-localhost
+  datasource:
+    url: jdbc:mysql://127.0.0.1:3306/crowd-test-service?useSSL=false&useUnicode=yes&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
+    username: root
+    password: Customs2019
+  #  redis:
+  #    host: redis
+  #    port: 6379
+  #    #    password: '#2019@callforttest@!'
+  #    jedis:
+  #      pool:
+  #        max-active: 8
+  #        max-idle: 8
+  #        max-wait: -1
+  #        min-idle: 0
+  #    database: 0
+
+  redis:
+    host: 127.0.0.1
+    password:
+    pool:
+      max-active: 8
+      max-idle: 8
+      max-wait: -1
+      min-idle: 0
+    port: 6379
 
 feature:
   client:
@@ -71,7 +128,7 @@ user:
 #    baseUrl: http://59.42.10.53:8081
 
 website:
-  domain: mooctest.net
+  domain: 127.0.0.1
 
 ---
 spring:
@@ -98,7 +155,7 @@ feature:
 
 user:
   service:
-#    baseUrl: http://127.0.0.1:8081
+    #    baseUrl: http://127.0.0.1:8081
     baseUrl: http://59.42.10.53:8081
 
 website:

+ 39 - 39
site/src/test/java/com/mooctest/crowd/site/SiteApplicationTests.java

@@ -1,39 +1,39 @@
-package com.mooctest.crowd.site;
-
-import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
-import com.mooctest.crowd.domain.model.CrowdTestProjectPO;
-import com.mooctest.crowd.site.service.AgencyService;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import java.util.Optional;
-
-@RunWith(SpringRunner.class)
-@SpringBootTest
-public class SiteApplicationTests {
-    @Autowired
-    private CrowdTestProjectDao  crowdTestProjectDao;
-
-    @Test
-    public  void test(){
-        Optional<CrowdTestProjectPO> crowdTestProjectPO=crowdTestProjectDao.findById(223l);
-         CrowdTestProjectPO crowdTestProjectPO1=crowdTestProjectPO.get();
-         crowdTestProjectPO1.setStatus(5);
-         crowdTestProjectDao.save(crowdTestProjectPO1);
-
-
-
-
-
-    }
-
-
-
-
-
-
-
-}
+//package com.mooctest.crowd.site;
+//
+//import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
+//import com.mooctest.crowd.domain.model.CrowdTestProjectPO;
+//import com.mooctest.crowd.site.service.AgencyService;
+//import org.junit.Test;
+//import org.junit.runner.RunWith;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.boot.test.context.SpringBootTest;
+//import org.springframework.test.context.junit4.SpringRunner;
+//
+//import java.util.Optional;
+//
+//@RunWith(SpringRunner.class)
+//@SpringBootTest
+//public class SiteApplicationTests {
+//    @Autowired
+//    private CrowdTestProjectDao  crowdTestProjectDao;
+//
+//    @Test
+//    public  void test(){
+//        Optional<CrowdTestProjectPO> crowdTestProjectPO=crowdTestProjectDao.findById(223l);
+//         CrowdTestProjectPO crowdTestProjectPO1=crowdTestProjectPO.get();
+//         crowdTestProjectPO1.setStatus(5);
+//         crowdTestProjectDao.save(crowdTestProjectPO1);
+//
+//
+//
+//
+//
+//    }
+//
+//
+//
+//
+//
+//
+//
+//}

Деякі файли не було показано, через те що забагато файлів було змінено