|
@@ -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)
|