浏览代码

新建生产数据源选择类型

zhuoning 4 年之前
父节点
当前提交
3caa653509

+ 39 - 14
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/controller/IndexParameterController.java

@@ -1,12 +1,11 @@
 package com.huimv.production.controller;
 
+import com.huimv.common.result.ResultCode;
 import com.huimv.production.domain.IndexParameterEntity;
 import com.huimv.production.result.Result;
 import com.huimv.production.service.IndexParameterService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -24,31 +23,57 @@ public class IndexParameterController {
     private IndexParameterService parameterService;
 
     @RequestMapping("/add")
-    public Result add(IndexParameterEntity parameterEntity){
+    public Result add(IndexParameterEntity parameterEntity) {
         return parameterService.add(parameterEntity);
     }
 
     @RequestMapping("/remove")
-    public Result add(Integer[] ids){
+    public Result add(Integer[] ids) {
         return parameterService.remove(ids);
     }
 
     @RequestMapping("/update")
-    public Result update(IndexParameterEntity parameterEntity){
+    public Result update(IndexParameterEntity parameterEntity) {
         return parameterService.update(parameterEntity);
     }
 
-   /* @RequestMapping("/findAll")
-    public Result findAll(){
+    /* @RequestMapping("/findAll")
+     public Result findAll(){
+         return parameterService.findAll();
+     }*/
+    @RequestMapping("/findAll")
+    public Result findAll() {
         return parameterService.findAll();
-    }*/
-   @RequestMapping("/findAll")
-   public Result findAll(){
-       return parameterService.findAll();
-   }
-
+    }
 
+    /**
+     * @Method : setDatasourceType
+     * @Description : 设置数据源类型
+     * @Params : [datasourceType]
+     * @Return : com.huimv.production.result.Result
+     * @Author : ZhuoNing
+     * @Date : 2021/5/22
+     * @Time : 14:11
+     */
+    @RequestMapping(value = "/setDatasourceType", method = RequestMethod.POST)
+    public Result setDatasourceType(@RequestParam(value = "datasourceType") String datasourceType) {
+        return parameterService.setDatasourceType(datasourceType);
+    }
 
+    /**
+     * @Method      : getDatasourceType
+     * @Description : 读取数据源类型
+     * @Params      : []
+     * @Return      : com.huimv.production.result.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/22       
+     * @Time        : 16:22
+     */
+    @RequestMapping(value = "/getDatasourceType", method = RequestMethod.GET)
+    public Result getDatasourceType(){
+        return parameterService.getDatasourceType();
+    }
 
 
 }

+ 55 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/domain/ConfigEntity.java

@@ -0,0 +1,55 @@
+package com.huimv.production.domain;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Entity
+@Table(name = "config")
+public class ConfigEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "property_key")
+    private String key;
+
+    @Column(name = "property_value")
+    private String value;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    @Override
+    public String toString() {
+        return "ConfigEntity{" +
+                "id=" + id + '\'' +
+                "key=" + key + '\'' +
+                "value=" + value + '\'' +
+                '}';
+    }
+}

+ 92 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/domain/IndexParameter2Entity.java

@@ -0,0 +1,92 @@
+package com.huimv.production.domain;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "index_parameter2")
+public class IndexParameter2Entity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "name")
+    private String name;
+
+    @Column(name = "data")
+    private String data;
+
+    @Column(name = "create_time", nullable = false)
+    private Timestamp createTime;
+
+    @Column(name = "update_time")
+    private Timestamp updateTime;
+
+    @Column(name = "check_parameter")
+    private Integer checkParameter;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setCreateTime(Timestamp createTime) {
+        this.createTime = createTime;
+    }
+
+    public Timestamp getCreateTime() {
+        return createTime;
+    }
+
+    public void setUpdateTime(Timestamp updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public Timestamp getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setCheckParameter(Integer checkParameter) {
+        this.checkParameter = checkParameter;
+    }
+
+    public Integer getCheckParameter() {
+        return checkParameter;
+    }
+
+    @Override
+    public String toString() {
+        return "IndexParameter2Entity{" +
+                "id=" + id + '\'' +
+                "name=" + name + '\'' +
+                "data=" + data + '\'' +
+                "createTime=" + createTime + '\'' +
+                "updateTime=" + updateTime + '\'' +
+                "checkParameter=" + checkParameter + '\'' +
+                '}';
+    }
+}

+ 9 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/repo/ConfigEntityRepository.java

@@ -0,0 +1,9 @@
+package com.huimv.production.repo;
+
+import com.huimv.production.domain.ConfigEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface ConfigEntityRepository extends JpaRepository<ConfigEntity, Integer>, JpaSpecificationExecutor<ConfigEntity> {
+
+}

+ 9 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/repo/IndexParameter2Repo.java

@@ -0,0 +1,9 @@
+package com.huimv.production.repo;
+
+import com.huimv.production.domain.IndexParameter2Entity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface IndexParameter2Repo extends JpaRepository<IndexParameter2Entity, Integer>, JpaSpecificationExecutor<IndexParameter2Entity> {
+
+}

+ 4 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/service/IndexParameterService.java

@@ -22,4 +22,8 @@ public interface IndexParameterService {
 
     //Result findAll();
     Result findAll();
+
+    Result setDatasourceType(String datasourceType);
+
+    Result getDatasourceType();
 }

+ 53 - 6
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/service/impl/IndexParameterServiceImpl.java

@@ -1,17 +1,17 @@
 package com.huimv.production.service.impl;
 
+import com.huimv.production.domain.ConfigEntity;
 import com.huimv.production.domain.IndexParameterEntity;
+import com.huimv.production.repo.ConfigEntityRepository;
 import com.huimv.production.repo.IndexParameterEntityRepository;
 import com.huimv.production.result.Result;
 import com.huimv.production.result.ResultStatus;
 import com.huimv.production.service.IndexParameterService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @Project : huimv.shiwan
@@ -24,6 +24,8 @@ import java.util.Map;
 public class IndexParameterServiceImpl implements IndexParameterService {
     @Autowired
     private IndexParameterEntityRepository parameterEntityRepository;
+    @Autowired
+    private ConfigEntityRepository configRepo;
 
     @Override
     public Result add(IndexParameterEntity parameterEntity) {
@@ -70,7 +72,6 @@ public class IndexParameterServiceImpl implements IndexParameterService {
         }catch (Exception e){
             return new Result(10001,"修改失败");
         }
-
     }
 
     @Override
@@ -82,8 +83,54 @@ public class IndexParameterServiceImpl implements IndexParameterService {
         }
     }
 
+    /**
+     * @Method      : setDatasourceType
+     * @Description : 
+     * @Params      : [datasourceType]
+     * @Return      : com.huimv.production.result.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/5/22       
+     * @Time        : 16:04
+     */
+    @Override
+    public Result setDatasourceType(String datasourceType){
+        // 先查询记录是否存在,存在就修改,不存在就添加
+        ConfigEntity configEntity = new ConfigEntity();
+        configEntity.setKey("datasourceType");;
+        Example<ConfigEntity> example = Example.of(configEntity);
+        Optional<ConfigEntity> configOptional = configRepo.findOne(example);
+        if(configOptional.isPresent()){
+            ConfigEntity configData = configOptional.get();
+            configData.setValue(datasourceType);
+            configRepo.saveAndFlush(configData);
+        }else{
+            ConfigEntity addConfigData = new ConfigEntity();
+            addConfigData.setKey("datasourceType");
+            addConfigData.setValue(datasourceType);
+            configRepo.saveAndFlush(addConfigData);
+        }
+        return new Result(10000,"设置成功");
+    }
 
-
+    @Override
+    public Result getDatasourceType() {
+        String datasourceTypeVal = "true";
+        ConfigEntity configEntity = new ConfigEntity();
+        configEntity.setKey("datasourceType");;
+        Example<ConfigEntity> example = Example.of(configEntity);
+        Optional<ConfigEntity> configOptional = configRepo.findOne(example);
+        if(configOptional.isPresent()){
+            ConfigEntity configData = configOptional.get();
+            datasourceTypeVal = configData.getValue();
+        }else{
+            ConfigEntity addConfigData = new ConfigEntity();
+            addConfigData.setKey("datasourceType");
+            addConfigData.setValue(datasourceTypeVal);
+            configRepo.saveAndFlush(addConfigData);
+        }
+        return new Result(10000,"设置成功",datasourceTypeVal);
+    }
 
   /*  @Override
     public Result findAll() {

+ 5 - 2
huimv-ql-farm/huimv-ql-production/src/main/resources/application.properties

@@ -1,4 +1,7 @@
-#spring.profiles.active=ycg
+spring.profiles.active=ycg
 #spring.profiles.active=wuyi
-spring.profiles.active=haiyan
+#spring.profiles.active=haiyan
 #spring.profiles.active=wjj
+
+# 生产数据源配置(本地填报数据true/远程数据false)
+#production.datasource.type=true