-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptInfoService.go
153 lines (139 loc) · 4.47 KB
/
scriptInfoService.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package service
import (
"fmt"
"strings"
"wleirock/data-distribute/models"
"github.com/astaxie/beego/orm"
)
// GetScriptInfoList 查询分发设置集合
func GetScriptInfoList(scriptInfo *models.ScriptInfo) []models.ScriptInfo {
o := orm.NewOrm()
var buildStr strings.Builder
buildStr.WriteString("select * from script_info where 1=1")
if scriptInfo.HospitalName != "" {
buildStr.WriteString(" and hospital_name like '%")
buildStr.WriteString(scriptInfo.HospitalName)
buildStr.WriteString("%'")
}
if scriptInfo.ScriptName != "" {
buildStr.WriteString(" and script_name='")
buildStr.WriteString(scriptInfo.ScriptName)
buildStr.WriteString("'")
}
buildStr.WriteString(" limit ? , ?")
var list []models.ScriptInfo
_, err := o.Raw(buildStr.String(), (scriptInfo.Page-1)*scriptInfo.Limit, scriptInfo.Limit).QueryRows(&list)
if err != nil {
fmt.Println(err)
return nil
}
return list
}
// GetScriptInfoTotal 查询总数
func GetScriptInfoTotal(scriptInfo *models.ScriptInfo) int {
o := orm.NewOrm()
var buildStr strings.Builder
buildStr.WriteString("select count(*) from script_info where 1=1")
if scriptInfo.HospitalName != "" {
buildStr.WriteString(" and hospital_name like '%")
buildStr.WriteString(scriptInfo.HospitalName)
buildStr.WriteString("%'")
}
if scriptInfo.ScriptName != "" {
buildStr.WriteString(" and script_name='")
buildStr.WriteString(scriptInfo.ScriptName)
buildStr.WriteString("'")
}
var totalCount int
err := o.Raw(buildStr.String()).QueryRow(&totalCount)
if err != nil {
fmt.Println(err)
return 0
}
return totalCount
}
// AddScriptInfo 保存分发设置
func AddScriptInfo(scriptInfo *models.ScriptInfo) bool {
o := orm.NewOrm()
res, err := o.Raw("insert into script_info(hospital_fk,hospital_name,data_type,script_name,description,api_ip,api_port,status) values (?,?,?,?,?,?,?,?)", scriptInfo.HospitalFk, scriptInfo.HospitalName, scriptInfo.DataType, scriptInfo.ScriptName, scriptInfo.Description, scriptInfo.ApiIp, scriptInfo.ApiPort, scriptInfo.Status).Exec()
if err != nil {
fmt.Println("SaveScriptInfo error", err)
return false
}
count, err := res.RowsAffected()
if err != nil {
fmt.Println("SaveScriptInfo error", err)
return false
}
if count > 0 {
return true
}
return false
}
// UpdateScriptInfo 更新分发设置
func UpdateScriptInfo(scriptInfo *models.ScriptInfo) bool {
o := orm.NewOrm()
res, err := o.Raw("update script_info set hospital_fk = ?,hospital_name = ?,data_type = ?,script_name = ?,description = ?,api_ip = ?,api_port = ?,status = ? where info_pk = ?", scriptInfo.HospitalFk, scriptInfo.HospitalName, scriptInfo.DataType, scriptInfo.ScriptName, scriptInfo.Description, scriptInfo.ApiIp, scriptInfo.ApiPort, scriptInfo.Status, scriptInfo.InfoPk).Exec()
if err != nil {
fmt.Println("UpdateScriptInfo error", err)
return false
}
_, err = res.RowsAffected()
if err != nil {
fmt.Println("UpdateScriptInfo error", err)
return false
}
return true
}
// GetScriptInByPk 根据主键查询
func GetScriptInByPk(infoPk int) models.ScriptInfo {
var scriptInfo models.ScriptInfo
o := orm.NewOrm()
err := o.Raw("select info_pk,hospital_fk,hospital_name,data_type,script_name,description,api_ip,api_port,status from script_info where info_pk = ?", infoPk).QueryRow(&scriptInfo)
if err != nil {
fmt.Println("GetScriptInByPk error", err)
}
return scriptInfo
}
// DeleteScriptInfo 根据主键删除分发设置
func DeleteScriptInfo(infoPk int) bool {
o := orm.NewOrm()
res, err := o.Raw("delete from script_info where info_pk = ?", infoPk).Exec()
if err != nil {
fmt.Println("DeleteScriptInfo error", err)
return false
}
_, err = res.RowsAffected()
if err != nil {
fmt.Println("DeleteScriptInfo error", err)
return false
}
return true
}
// IfSciptInfoExist 根据文件名称查看是否已存在
func IfSciptInfoExist(scriptName string) (bool, error) {
o := orm.NewOrm()
count := 0
err := o.Raw("select count(*) from script_info where script_name = ?", scriptName).QueryRow(&count)
if err != nil {
return false, err
}
if count > 0 {
return true, nil
}
return false, nil
}
// GetScriptInfoListByHosFk 根据机构ID查询
func GetScriptInfoListByHosFk(hospitalFk int, dataType string) []models.ScriptInfo {
var list []models.ScriptInfo
if hospitalFk == 0 || dataType == "" {
return list
}
o := orm.NewOrm()
_, err := o.Raw("select * from script_info where hospital_fk = ? and data_type = ?", hospitalFk, dataType).QueryRows(&list)
if err != nil {
fmt.Println(err)
return nil
}
return list
}