浏览代码

数据源配置

CzRger 1 年之前
父节点
当前提交
46e5a10541

+ 7 - 1
ship-test/control/ship-filter-control.js

@@ -1,12 +1,18 @@
 import SourceService from "../service/source-service.js";
 import ApiResult from "../config/api.js";
 import ParamsService from "../service/params-service.js";
+import ParamsDictService from "../service/params-dict-service.js";
 const ShipFilterControl = {
   getConfig: async (req, res) => {
     try {
       const sourceData = await SourceService.list({orderByColumn: 'sort', isAsc: false})
       for (const source of sourceData) {
-        source.params = await ParamsService.list({sourceId: source.id})
+        const paramsData = await ParamsService.list({sourceId: source.id})
+        for (const params of paramsData) {
+          const dictData = await ParamsDictService.list({paramsId: params.id})
+          params.dict = dictData
+        }
+        source.params = paramsData
       }
       res.send(new ApiResult().success(sourceData))
     } catch (e) {

+ 4 - 0
ship-test/entity/source-entity.js

@@ -9,5 +9,9 @@ export default class SourceEntity {
     this.remark = isValue(obj?.remark) ? obj.remark : null
     this.createTime = isValue(obj?.createTime) ? YMDHms(obj.createTime) : null
     this.updateTime = isValue(obj?.updateTime) ? YMDHms(obj.updateTime) : null
+    this.tileUrl = isValue(obj?.tileUrl) ? obj.tileUrl : null
+    this.tileName = isValue(obj?.tileName) ? obj.tileName : null
+    this.wsUrl = isValue(obj?.wsUrl) ? obj.wsUrl : null
+    this.wsDataFlag = isValue(obj?.wsDataFlag) ? obj.wsDataFlag : null
   }
 }

+ 17 - 17
ship-test/service/params-dict-service.js

@@ -102,8 +102,15 @@ const ParamsDictService = {
   add: (form) => {
     return new Promise(async (resolve, reject) => {
       try {
-        const sql = 'INSERT INTO ship_test_params_dict (params_id, name, remark, sort, cql) VALUES (?, ?, ?, ?, ?)'
         const paramsDictEntity = new ParamsDictEntity(form)
+        const values = [
+          ['params_id', paramsDictEntity.paramsId],
+          ['name', paramsDictEntity.name],
+          ['remark', paramsDictEntity.remark],
+          ['sort', paramsDictEntity.sort],
+          ['cql', paramsDictEntity.cql],
+        ]
+        const sql = `INSERT INTO ship_test_params_dict (${values.map(v => v[0]).join(',')}) VALUES (${values.map(v => '?').join(',')})`
         if (!isValue(paramsDictEntity.paramsId)) {
           reject('参数ID不可为空')
         }
@@ -115,14 +122,7 @@ const ParamsDictService = {
           reject('已存在相同名称!')
           return
         }
-        const values = [
-          paramsDictEntity.paramsId,
-          paramsDictEntity.name,
-          paramsDictEntity.remark,
-          paramsDictEntity.sort,
-          paramsDictEntity.cql,
-        ]
-        const result = await sqlHandle(sql, values)
+        const result = await sqlHandle(sql, values.map(v => v[1]))
         resolve(result.insertId)
       } catch (e) {
         reject(e.sqlMessage)
@@ -132,8 +132,14 @@ const ParamsDictService = {
   edit: (form) => {
     return new Promise(async (resolve, reject) => {
       try {
-        let sql = 'UPDATE ship_test_params_dict SET name = ?, remark = ?, sort = ?, cql = ?'
         const paramsDictEntity = new ParamsDictEntity(form)
+        const values = [
+          ['name', paramsDictEntity.name],
+          ['remark', paramsDictEntity.remark],
+          ['sort', paramsDictEntity.sort],
+          ['cql', paramsDictEntity.cql],
+        ]
+        let sql = `UPDATE ship_test_params_dict SET ${values.map(v => `${v[0]} = ?`).join(',')}`
         if (!isValue(paramsDictEntity.id)) {
           reject('id不可为空!')
           return
@@ -148,13 +154,7 @@ const ParamsDictService = {
           reject('已存在相同名称!')
           return
         }
-        const values = [
-          paramsDictEntity.name,
-          paramsDictEntity.remark,
-          paramsDictEntity.sort,
-          paramsDictEntity.cql,
-        ]
-        const result = await sqlHandle(sql, values)
+        const result = await sqlHandle(sql, values.map(v => v[1]))
         resolve(paramsDictEntity.id)
       } catch (e) {
         reject(e.sqlMessage)

+ 15 - 15
ship-test/service/params-service.js

@@ -102,8 +102,14 @@ const ParamsService = {
   add: (form) => {
     return new Promise(async (resolve, reject) => {
       try {
-        const sql = 'INSERT INTO ship_test_params (source_id, name, remark, sort) VALUES (?, ?, ?, ?)'
         const paramsEntity = new ParamsEntity(form)
+        const values = [
+          ['source_id', paramsEntity.sourceId],
+          ['name', paramsEntity.name],
+          ['remark', paramsEntity.remark],
+          ['sort', paramsEntity.sort],
+        ]
+        const sql = `INSERT INTO ship_test_params (${values.map(v => v[0]).join(',')}) VALUES (${values.map(v => '?').join(',')})`
         if (!isValue(paramsEntity.sourceId)) {
           reject('数据源ID不可为空')
         }
@@ -112,13 +118,7 @@ const ParamsService = {
           reject('已存在相同名称!')
           return
         }
-        const values = [
-          paramsEntity.sourceId,
-          paramsEntity.name,
-          paramsEntity.remark,
-          paramsEntity.sort,
-        ]
-        const result = await sqlHandle(sql, values)
+        const result = await sqlHandle(sql, values.map(v => v[1]))
         resolve(result.insertId)
       } catch (e) {
         reject(e.sqlMessage)
@@ -128,8 +128,13 @@ const ParamsService = {
   edit: (form) => {
     return new Promise(async (resolve, reject) => {
       try {
-        let sql = 'UPDATE ship_test_params SET name = ?, remark = ?, sort = ?'
         const paramsEntity = new ParamsEntity(form)
+        const values = [
+          ['name', paramsEntity.name],
+          ['remark', paramsEntity.remark],
+          ['sort', paramsEntity.sort],
+        ]
+        let sql = `UPDATE ship_test_params SET ${values.map(v => `${v[0]} = ?`).join(',')}`
         if (!isValue(paramsEntity.id)) {
           reject('id不可为空!')
           return
@@ -141,12 +146,7 @@ const ParamsService = {
           reject('已存在相同名称!')
           return
         }
-        const values = [
-          paramsEntity.name,
-          paramsEntity.remark,
-          paramsEntity.sort,
-        ]
-        const result = await sqlHandle(sql, values)
+        const result = await sqlHandle(sql, values.map(v => v[1]))
         resolve(paramsEntity.id)
       } catch (e) {
         reject(e.sqlMessage)

+ 22 - 14
ship-test/service/source-service.js

@@ -92,19 +92,23 @@ const SourceService = {
   add: (form) => {
     return new Promise(async (resolve, reject) => {
       try {
-        const sql = 'INSERT INTO ship_test_source (name, remark, sort) VALUES (?, ?, ?)'
         const sourceEntity = new SourceEntity(form)
+        const values = [
+          ['name', sourceEntity.name],
+          ['remark', sourceEntity.remark],
+          ['sort', sourceEntity.sort],
+          ['tile_url', sourceEntity.tileUrl],
+          ['tile_name', sourceEntity.tileName],
+          ['ws_url', sourceEntity.wsUrl],
+          ['ws_data_flag', sourceEntity.wsDataFlag],
+        ]
+        const sql = `INSERT INTO ship_test_source (${values.map(v => v[0]).join(',')}) VALUES (${values.map(v => '?').join(',')})`
         const sameValid = await SourceService.queryBy({name: sourceEntity.name})
         if (sameValid.length > 0) {
           reject('已存在相同名称!')
           return
         }
-        const values = [
-          sourceEntity.name,
-          sourceEntity.remark,
-          sourceEntity.sort,
-        ]
-        const result = await sqlHandle(sql, values)
+        const result = await sqlHandle(sql, values.map(v => v[1]))
         resolve(result.insertId)
       } catch (e) {
         reject(e.sqlMessage)
@@ -114,8 +118,17 @@ const SourceService = {
   edit: (form) => {
     return new Promise(async (resolve, reject) => {
       try {
-        let sql = 'UPDATE ship_test_source SET name = ?, remark = ?, sort = ?'
         const sourceEntity = new SourceEntity(form)
+        const values = [
+          ['name', sourceEntity.name],
+          ['remark', sourceEntity.remark],
+          ['sort', sourceEntity.sort],
+          ['tile_url', sourceEntity.tileUrl],
+          ['tile_name', sourceEntity.tileName],
+          ['ws_url', sourceEntity.wsUrl],
+          ['ws_data_flag', sourceEntity.wsDataFlag],
+        ]
+        let sql = `UPDATE ship_test_source SET ${values.map(v => `${v[0]} = ?`).join(',')}`
         if (!isValue(sourceEntity.id)) {
           reject('id不可为空!')
           return
@@ -127,12 +140,7 @@ const SourceService = {
           reject('已存在相同名称!')
           return
         }
-        const values = [
-          sourceEntity.name,
-          sourceEntity.remark,
-          sourceEntity.sort,
-        ]
-        const result = await sqlHandle(sql, values)
+        const result = await sqlHandle(sql, values.map(v => v[1]))
         resolve(sourceEntity.id)
       } catch (e) {
         reject(e.sqlMessage)