张保健 4 years ago
parent
commit
b130e19561
5 changed files with 330 additions and 82 deletions
  1. 84 0
      controllers/sync.go
  2. 18 0
      models/src_data.go
  3. 205 79
      models/sz/target_data.go
  4. 7 3
      service/city_data_uoload_service.go
  5. 16 0
      service/db.go

+ 84 - 0
controllers/sync.go View File

@@ -0,0 +1,84 @@
1
+package controllers
2
+
3
+import (
4
+	"github.com/jinzhu/gorm"
5
+	"Data_Upload_Api/models/sz"
6
+	"github.com/astaxie/beego"
7
+	"Data_Upload_Api/service"
8
+	"Data_Upload_Api/enums"
9
+	"Data_Upload_Api/utils"
10
+	"strconv"
11
+	"time"
12
+	_"strings"
13
+)
14
+
15
+type SyncController struct {
16
+	BaseAPIController
17
+}
18
+
19
+func (c *SyncController)SyncToSZIC() {
20
+	// 第一步:到上报配置表中找到深圳需要上报的机构
21
+	sz_province, _ := beego.AppConfig.Int64("sz_province")
22
+	sz_city, _ := beego.AppConfig.Int64("sz_city")
23
+	configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
24
+	for _, org := range configs {
25
+		// 第二步:跟进配置,创建数据库连接
26
+		if (len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0) {
27
+			orgDb,err := service.CreateDB(org.DbHost,org.DbPort,org.DbUser,org.DbPass,org.DbName)
28
+			if err != nil {
29
+				utils.ErrorLog("创建数据库连接失败:%v", err)
30
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
31
+				return
32
+			}
33
+			// 第三步:开始同步数据
34
+			c.SyncHospital(orgDb,org.OrgId,org.HospitalId,org.InstType,org.DepartmentName)
35
+
36
+			// 第四步:关闭数据库连接
37
+			service.CloseDB(orgDb)
38
+		}
39
+	}
40
+}
41
+
42
+// 同步医院信息
43
+func (c *SyncController)SyncHospital(rdb *gorm.DB,org_id int64,hospital_id int64,inst_type int64,department_name string) {
44
+	// 第一步:根据机构id获取上次同步时间
45
+	syncLastInfo,_ := service.GetSyncTimeByOrgId(org_id,1)
46
+	var sync_time int64
47
+	if syncLastInfo.ID > 0 {
48
+		sync_time = syncLastInfo.SyncTime
49
+	} else {
50
+		sync_time = 0
51
+	}
52
+
53
+	// 第二步:跟进上次同步时间找出这个时间段内增加的数据
54
+	org, _ := service.FindOrgData(org_id,sync_time)
55
+	if org.ID > 0 {
56
+		hospital := &sz.TempHdHospital{
57
+			HospitalId:     strconv.FormatInt(hospital_id, 10),
58
+			InstType:       strconv.FormatInt(inst_type, 10),
59
+			DepartMentName:	department_name,
60
+			AuthorizedBeds: int64(len(org.DeviceNumber)),
61
+			CreateTime:     time.Now(),
62
+			UpdateTime:     time.Now(),
63
+			Sjscsj:         time.Now(),
64
+			Xgbz:           0,
65
+		}
66
+		err := service.CreateOrgRecord(hospital)
67
+		if err == nil {
68
+			// 第三步:同步成功后,添加同步记录
69
+			upload := &sz.DataUpload{
70
+				SyncType:   		1,
71
+				OrgId:        		org_id,
72
+				SyncTime:   		time.Now().Unix(),
73
+				sync_result_type: 	1,
74
+				CreateTime:   		time.Now().Unix(),
75
+				UpdateTime:   		time.Now().Unix()
76
+			}
77
+			err := service.CreateUploadRecord(upload)
78
+			if err != nil {
79
+				utils.ErrorLog("%v", err)
80
+			}
81
+		}
82
+	}
83
+}
84
+

+ 18 - 0
models/src_data.go View File

@@ -1,5 +1,23 @@
1 1
 package models
2 2
 
3
+type XTSyncInfo struct {
4
+	ID             	int64 `gorm:"column:id" json:"id" form:"id"`
5
+	OrgId       	int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
6
+	SyncType       	int64 `gorm:"column:sync_type" json:"sync_type" form:"sync_type"`
7
+	SyncTime       	int64 `gorm:"column:sync_time" json:"sync_time" form:"sync_time"`
8
+	SyncResultType  int	  `gorm:"column:sync_result_type" json:"sync_result_type" form:"sync_result_type"`
9
+	SyncRsultRemark string `gorm:"column:sync_result_remark" json:"sync_result_remark" form:"sync_result_remark"`
10
+	SyncTotalNum    int64 `gorm:"column:sync_total_num" json:"sync_total_num" form:"sync_total_num"`
11
+	SyncSuccessNum  int64 `gorm:"column:sync_success_num" json:"sync_success_num" form:"sync_success_num"`
12
+	SyncInfo      	string `gorm:"column:sync_info" json:"sync_info" form:"sync_info"`
13
+	CreateTime      int64 `gorm:"column:create_time" json:"create_time" form:"create_time"`
14
+	UpdateTime    	int64 `gorm:"column:update_time" json:"update_time" form:"update_time"`
15
+}
16
+
17
+func (XTSyncInfo) TableName() string {
18
+	return "xt_sync_info"
19
+}
20
+
3 21
 type UserOrg struct {
4 22
 	ID              int64           `gorm:"column:id" json:"id"`
5 23
 	Creator         int64           `gorm:"column:creator" json:"creator"`

+ 205 - 79
models/sz/target_data.go View File

@@ -4,84 +4,198 @@ import "time"
4 4
 
5 5
 type TempHdHospital struct {
6 6
 	ID             int64     `gorm:"column:id" json:"id"`
7
-	HospitalId     string    `gorm:"column:hospital_id" json:"hospital_id"`
8
-	InstType       string    `gorm:"column:inst_type" json:"inst_type"`
9
-	DepartMentName string    `gorm:"column:depart_ment_name" json:"depart_ment_name"`
10
-	AuthorizedBeds int64     `gorm:"column:authorized_beds" json:"authorized_beds"`
11
-	CreateTime     time.Time `gorm:"column:create_time" json:"create_time"`
12
-	UpdateTime     time.Time `gorm:"column:update_time" json:"update_time"`
13
-	Sjscsj         time.Time `gorm:"column:sjscsj" json:"sjscsj"`
14
-	Mj             string    `gorm:"column:mj" json:"mj"`
15
-	Xgbz           int64     `gorm:"column:xgbz" json:"xgbz"`
16
-	Ylyl1          string    `gorm:"column:ylyl1" json:"ylyl1"`
17
-	Ylyl2          string    `gorm:"column:ylyl2" json:"ylyl2"`
7
+	HospitalId     string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
8
+	InstType       string    `gorm:"column:INST_TYPE" json:"INST_TYPE"`
9
+	DepartMentName string    `gorm:"column:DEPARTMENT_NAME" json:"DEPARTMENT_NAME"`
10
+	AuthorizedBeds int64     `gorm:"column:AUTHORIZED_BEDS" json:"AUTHORIZED_BEDS"`
11
+	CreateTime     time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
12
+	UpdateTime     time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
13
+	Sjscsj         time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
14
+	Mj             string    `gorm:"column:MJ" json:"MJ"`
15
+	Xgbz           int64     `gorm:"column:XGBZ" json:"XGBZ"`
16
+	Ylyl1          string    `gorm:"column:YLYL1" json:"YLYL1"`
17
+	Ylyl2          string    `gorm:"column:YLYL2" json:"YLYL2"`
18 18
 }
19 19
 
20 20
 func (TempHdHospital) TableName() string {
21
-	return "temp_hd_hospital"
21
+	return "t_hd_hospital"
22 22
 }
23 23
 
24 24
 type TempHdStaff struct {
25 25
 	ID                           int64     `gorm:"column:id" json:"id"`
26
-	HospitalId                   string    `gorm:"column:hospital_id" json:"hospital_id"`
27
-	StaffId                      string    `gorm:"column:staff_id" json:"staff_id"`
28
-	IdType                       string    `gorm:"column:id_type" json:"id_type"`
29
-	IdNo                         string    `gorm:"column:id_no" json:"id_no"`
30
-	StaffName                    string    `gorm:"column:staff_name" json:"staff_name"`
31
-	Position                     string    `gorm:"column:position" json:"position"`
32
-	TrainingName                 string    `gorm:"column:training_name" json:"training_name"`
33
-	PracticeCertificate          string    `gorm:"column:practice_certificate" json:"practice_certificate"`
34
-	PracticeCertificateNo        string    `gorm:"column:practice_certificate_no" json:"practice_certificate_no"`
35
-	QualificationCertificate     string    `gorm:"column:qualification_certificate" json:"qualification_certificate"`
36
-	QualificationType            string    `gorm:"column:qualification_type" json:"qualification_type"`
37
-	DiplomaFile                  string    `gorm:"column:diploma_file" json:"diploma_file"`
38
-	DegreeCertificateFile        string    `gorm:"column:degree_certificate_file" json:"degree_certificate_file"`
39
-	TrainingCertificateFile      string    `gorm:"column:training_certificate_file" json:"training_certificate_file"`
40
-	PracticeCertificateFile      string    `gorm:"column:practice_certificate_file" json:"practice_certificate_file"`
41
-	QualificationCertificateFile string    `gorm:"column:qualification_certificate_file" json:"qualification_certificate_file"`
42
-	Xgbz                         string    `gorm:"column:xgbz" json:"xgbz"`
43
-	TrainingDate                 time.Time `gorm:"column:training_date" json:"training_date"`
44
-	InDate                       time.Time `gorm:"column:in_date" json:"in_date"`
45
-	OutDate                      time.Time `gorm:"column:out_date" json:"out_date"`
46
-	CreateTime                   time.Time `gorm:"column:create_time" json:"create_time"`
47
-	UpdateTime                   time.Time `gorm:"column:update_time" json:"update_time"`
48
-	Sjscsj                       time.Time `gorm:"column:sjscsj" json:"sjscsj"`
49
-	Mj                           string    `gorm:"column:mj" json:"mj"`
50
-	Ylyl1                        string    `gorm:"column:ylyl1" json:"ylyl1"`
51
-	Ylyl2                        string    `gorm:"column:ylyl2" json:"ylyl2"`
52
-	PermanentType                string    `gorm:"column:permanent_type" json:"permanent_type"`
26
+	HospitalId                   string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
27
+	StaffId                      string    `gorm:"column:STAFF_ID" json:"STAFF_ID"`
28
+	IdType                       string    `gorm:"column:ID_TYPE" json:"ID_TYPE"`
29
+	IdNo                         string    `gorm:"column:ID_NO" json:"ID_NO"`
30
+	StaffName                    string    `gorm:"column:STAFF_NAME" json:"STAFF_NAME"`
31
+	Position                     string    `gorm:"column:POSITION" json:"POSITION"`
32
+	TrainingName                 string    `gorm:"column:TRAINING_NAME" json:"TRAINING_NAME"`
33
+	PracticeCertificate          string    `gorm:"column:PRACTICE_CERTIFICATE" json:"PRACTICE_CERTIFICATE"`
34
+	PracticeCertificateNo        string    `gorm:"column:PRACTICE_CERTIFICATE_NO" json:"PRACTICE_CERTIFICATE_NO"`
35
+	QualificationCertificate     string    `gorm:"column:QUALIFICATION_CERTIFICATE" json:"QUALIFICATION_CERTIFICATE"`
36
+	QualificationType            string    `gorm:"column:QUALIFICATION_TYPE" json:"QUALIFICATION_TYPE"`
37
+	PermanentType                string    `gorm:"column:PERMANENT_TYPE" json:"PERMANENT_TYPE"`
38
+	DiplomaFile                  string    `gorm:"column:DIPLOMA_FILE" json:"DIPLOMA_FILE"`
39
+	DegreeCertificateFile        string    `gorm:"column:DEGREE_CERTIFICATE_FILE" json:"DEGREE_CERTIFICATE_FILE"`
40
+	TrainingCertificateFile      string    `gorm:"column:TRAINING_CERTIFICATE_FILE" json:"TRAINING_CERTIFICATE_FILE"`
41
+	PracticeCertificateFile      string    `gorm:"column:PRACTICE_CERTIFICATE_FILE" json:"PRACTICE_CERTIFICATE_FILE"`
42
+	QualificationCertificateFile string    `gorm:"column:QUALIFICATION_CERTIFICATE_FILE" json:"QUALIFICATION_CERTIFICATE_FILE"`
43
+	Xgbz                         string    `gorm:"column:XGBZ" json:"XGBZ"`
44
+	TrainingDate                 time.Time `gorm:"column:TRAINING_DATE" json:"TRAINING_DATE"`
45
+	InDate                       time.Time `gorm:"column:IN_DATE" json:"IN_DATE"`
46
+	OutDate                      time.Time `gorm:"column:OUT_DATE" json:"OUT_DATE"`
47
+	CreateTime                   time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
48
+	UpdateTime                   time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
49
+	Sjscsj                       time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
50
+	Mj                           string    `gorm:"column:MJ" json:"MJ"`
51
+	Ylyl1                        string    `gorm:"column:YLYL1" json:"YLYL1"`
52
+	Ylyl2                        string    `gorm:"column:YLYL2" json:"YLYL2"`
53
+	
53 54
 }
54 55
 
55 56
 func (TempHdStaff) TableName() string {
56
-	return "temp_hd_staff"
57
+	return "t_hd_staff"
58
+}
59
+
60
+type TempHdLayout struct {
61
+	ID             	int64     `gorm:"column:id" json:"id"`
62
+	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
63
+	PartitionName   string    `gorm:"column:PARTITION_NAME" json:"PARTITION_NAME"`
64
+	PartitionImg 	string    `gorm:"column:PARTITION_IMG" json:"PARTITION_IMG"`
65
+	FunctionArea 	string    `gorm:"column:FUNCTION_AREA" json:"FUNCTION_AREA"`
66
+	Xgbz           	int64     `gorm:"column:XGBZ" json:"XGBZ"`
67
+	CreateTime     time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
68
+	Sjscsj         time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
69
+	Mj             string    `gorm:"column:MJ" json:"MJ"`
70
+	Ylyl1          string    `gorm:"column:YLYL1" json:"YLYL1"`
71
+	Ylyl2          string    `gorm:"column:YLYL2" json:"YLYL2"`
57 72
 }
58 73
 
74
+func (TempHdLayout) TableName() string {
75
+	return "t_hd_layout"
76
+}
77
+
78
+
59 79
 type TempHdDm struct {
60 80
 	ID             int64     `gorm:"column:id" json:"id"`
61
-	HospitalId     string    `gorm:"column:hospital_id" json:"hospital_id"`
62
-	EquipmentId    string    `gorm:"column:equipment_id" json:"equipment_id"`
63
-	SickbedNo      string    `gorm:"column:sickbed_no" json:"sickbed_no"`
64
-	EquipmentBrand string    `gorm:"column:equipment_brand" json:"equipment_brand"`
65
-	EnableTime     time.Time `gorm:"column:enable_time" json:"enable_time"`
66
-	DiscardedTime  time.Time `gorm:"column:discarded_time" json:"discarded_time"`
67
-	Status         string    `gorm:"column:status" json:"status"`
68
-	EquipmentType  string    `gorm:"column:equipment_type" json:"equipment_type"`
69
-	Temperature    string    `gorm:"column:temperature" json:"temperature"`
70
-	Pressure       string    `gorm:"column:pressure" json:"pressure"`
71
-	PressureUnit   string    `gorm:"column:pressure_unit" json:"pressure_unit"`
72
-	WorkingVoltage string    `gorm:"column:working_voltage" json:"working_voltage"`
73
-	Xgbz           string    `gorm:"column:xgbz" json:"xgbz"`
74
-	Bbp            string    `gorm:"column:bbp" json:"bbp"`
75
-	CreateTime     time.Time `gorm:"column:create_time" json:"create_time"`
76
-	UpdateTime     time.Time `gorm:"column:update_time" json:"update_time"`
77
-	Sjscsj         time.Time `gorm:"column:sjscsj" json:"sjscsj"`
78
-	Mj             string    `gorm:"column:mj" json:"mj"`
79
-	Ylyl1          string    `gorm:"column:ylyl1" json:"ylyl1"`
80
-	Ylyl2          string    `gorm:"column:ylyl2" json:"ylyl2"`
81
+	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
82
+	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
83
+	SickbedNo      	string    `gorm:"column:SICKBED_NO" json:"SICKBED_NO"`
84
+	EquipmentBrand 	string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
85
+	EquipmentModel 	string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
86
+	EnableTime     	time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
87
+	DiscardedTime  	time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
88
+	Status         	string    `gorm:"column:STATUS" json:"STATUS"`
89
+	EquipmentType  	string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
90
+	Temperature    	string    `gorm:"column:TEMPERATURE" json:"TEMPERATURE"`
91
+	Humidity   		string    `gorm:"column:HUMIDITY" json:"HUMIDITY"`
92
+	Pressure       	string    `gorm:"column:PRESSURE" json:"PRESSURE"`
93
+	PressureUnit   	string    `gorm:"column:PRESSURE_UNIT" json:"PRESSURE_UNIT"`
94
+	WorkingVoltage 	string    `gorm:"column:WORKING_VOLTAGE" json:"WORKING_VOLTAGE"`
95
+	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
96
+	Bbp            	string    `gorm:"column:BBP" json:"BBP"`
97
+	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
98
+	UpdateTime     	time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
99
+	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
100
+	Mj            	string    `gorm:"column:MJ" json:"MJ"`
101
+	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
102
+	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
81 103
 }
82 104
 
83 105
 func (TempHdDm) TableName() string {
84
-	return "temp_hd_dm"
106
+	return "t_hd_dm"
107
+}
108
+
109
+type TempHdWm struct {
110
+	ID             int64     `gorm:"column:id" json:"id"`
111
+	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
112
+	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
113
+	EquipmentBrand 	string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
114
+	EquipmentModel 	string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
115
+	EnableTime     	time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
116
+	DiscardedTime  	time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
117
+	EquipmentType  	string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
118
+	Temperature    	string    `gorm:"column:TEMPERATURE" json:"TEMPERATURE"`
119
+	Humidity   		string    `gorm:"column:HUMIDITY" json:"HUMIDITY"`
120
+	Pressure       	string    `gorm:"column:PRESSURE" json:"PRESSURE"`
121
+	PressureUnit   	string    `gorm:"column:PRESSURE_UNIT" json:"PRESSURE_UNIT"`
122
+	QualityStandard string    `gorm:"column:QUALITY_STANDARD" json:"QUALITY_STANDARD"`
123
+	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
124
+	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
125
+	UpdateTime     	time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
126
+	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
127
+	Mj            	string    `gorm:"column:MJ" json:"MJ"`
128
+	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
129
+	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
130
+}
131
+
132
+func (TempHdWm) TableName() string {
133
+	return "t_hd_wm"
134
+}
135
+
136
+type TempHdMaintain struct {
137
+	ID             	int64     `gorm:"column:id" json:"id"`
138
+	SN				string    `gorm:"column:SN" json:"SN"`
139
+	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
140
+	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
141
+	EquipmentType  	string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
142
+	RepairTime    	time.Time `gorm:"column:REPAIR_TIME" json:"REPAIR_TIME"`
143
+	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
144
+	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
145
+	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
146
+	Mj            	string    `gorm:"column:MJ" json:"MJ"`
147
+	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
148
+	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
149
+}
150
+
151
+func (TempHdMaintain) TableName() string {
152
+	return "t_hd_maintain"
153
+}
154
+
155
+type TempHdDisinfectMethod struct {
156
+	ID             	int64     `gorm:"column:id" json:"id"`
157
+	SN				string    `gorm:"column:SN" json:"SN"`
158
+	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
159
+	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
160
+	EquipmentType  	string    `gorm:"column:EQUIPMENT_TYPE" json:"EQUIPMENT_TYPE"`
161
+	EquipmentModel 	string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
162
+	DisinfectMethod	string    `gorm:"column:DISINFECT_METHOD" json:"DISINFECT_METHOD"`
163
+	Disinfector		string    `gorm:"column:DISINFECTOR" json:"DISINFECTOR"`
164
+	Concentration	string    `gorm:"column:CONCENTRATION" json:"CONCENTRATION"`
165
+	Frequency		string    `gorm:"column:FREQUENCY" json:"FREQUENCY"`
166
+	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
167
+	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
168
+	UpdateTime     	time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
169
+	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
170
+	Mj            	string    `gorm:"column:MJ" json:"MJ"`
171
+	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
172
+	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
173
+}
174
+
175
+func (TempHdDisinfectMethod) TableName() string {
176
+	return "t_hd_disinfect_method"
177
+}
178
+
179
+type TempHdOtherMachine struct {
180
+	ID             int64     `gorm:"column:id" json:"id"`
181
+	HospitalId     	string    `gorm:"column:HOSPITAL_ID" json:"HOSPITAL_ID"`
182
+	EquipmentId    	string    `gorm:"column:EQUIPMENT_ID" json:"EQUIPMENT_ID"`
183
+	EquipmentBrand 	string    `gorm:"column:EQUIPMENT_BRAND" json:"EQUIPMENT_BRAND"`
184
+	EquipmentModel 	string    `gorm:"column:EQUIPMENT_MODEL" json:"EQUIPMENT_MODEL"`
185
+	EnableTime     	time.Time `gorm:"column:ENABLE_TIME" json:"ENABLE_TIME"`
186
+	DiscardedTime  	time.Time `gorm:"column:DISCARDED_TIME" json:"DISCARDED_TIME"`
187
+	Status         	string    `gorm:"column:STATUS" json:"STATUS"`
188
+	Xgbz           	string    `gorm:"column:XGBZ" json:"XGBZ"`
189
+	CreateTime     	time.Time `gorm:"column:CREATE_TIME" json:"CREATE_TIME"`
190
+	UpdateTime     	time.Time `gorm:"column:UPDATE_TIME" json:"UPDATE_TIME"`
191
+	Sjscsj         	time.Time `gorm:"column:SJSCSJ" json:"SJSCSJ"`
192
+	Mj            	string    `gorm:"column:MJ" json:"MJ"`
193
+	Ylyl1          	string    `gorm:"column:YLYL1" json:"YLYL1"`
194
+	Ylyl2          	string    `gorm:"column:YLYL2" json:"YLYL2"`
195
+}
196
+
197
+func (TempHdOtherMachine) TableName() string {
198
+	return "t_hd_other_machine"
85 199
 }
86 200
 
87 201
 type TempHdPatient struct {
@@ -254,13 +368,17 @@ func (TempHdOuthospital) TableName() string {
254 368
 }
255 369
 
256 370
 type DataUpload struct {
257
-	ID           int64 `gorm:"column:id" json:"id"`
258
-	ModuleType   int64 `gorm:"column:module_type" json:"module_type"`
259
-	OrgId        int64 `gorm:"column:org_id" json:"org_id"`
260
-	UploadDate   int64 `gorm:"column:upload_date" json:"upload_date"`
261
-	UploadStatus int64 `gorm:"column:upload_status" json:"upload_status"`
262
-	ReturnStatus int64 `gorm:"column:return_status" json:"return_status"`
263
-	UploadType   int64 `gorm:"column:upload_type" json:"upload_type"`
371
+	ID             	int64 `gorm:"column:id" json:"id" form:"id"`
372
+	OrgId       	int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
373
+	SyncType       	int64 `gorm:"column:sync_type" json:"sync_type" form:"sync_type"`
374
+	SyncTime       	int64 `gorm:"column:sync_time" json:"sync_time" form:"sync_time"`
375
+	SyncResultType  int	  `gorm:"column:sync_result_type" json:"sync_result_type" form:"sync_result_type"`
376
+	SyncRsultRemark string `gorm:"column:sync_result_remark" json:"sync_result_remark" form:"sync_result_remark"`
377
+	SyncTotalNum    int64 `gorm:"column:sync_total_num" json:"sync_total_num" form:"sync_total_num"`
378
+	SyncSuccessNum  int64 `gorm:"column:sync_success_num" json:"sync_success_num" form:"sync_success_num"`
379
+	SyncInfo      	string `gorm:"column:sync_info" json:"sync_info" form:"sync_info"`
380
+	CreateTime      int64 `gorm:"column:create_time" json:"create_time" form:"create_time"`
381
+	UpdateTime    	int64 `gorm:"column:update_time" json:"update_time" form:"update_time"`
264 382
 }
265 383
 
266 384
 func (DataUpload) TableName() string {
@@ -268,17 +386,25 @@ func (DataUpload) TableName() string {
268 386
 }
269 387
 
270 388
 type DataUploadConfig struct {
271
-	ID             int64  `gorm:"column:id" json:"id"`
272
-	OrgId          int64  `gorm:"column:org_id" json:"org_id"`
273
-	ProvinceId     int64  `gorm:"column:province_id" json:"province_id"`
274
-	CityId         int64  `gorm:"column:city_id" json:"city_id"`
275
-	GatewayAddress string `gorm:"column:gateway_address" json:"gateway_address"`
276
-	AppId          string `gorm:"column:app_id" json:"app_id"`
277
-	Key            string `gorm:"column:key" json:"key"`
278
-	Status         int64  `gorm:"column:status" json:"status"`
279
-	CreateTime     int64  `gorm:"column:create_time" json:"create_time"`
280
-	ModifyTime     int64  `gorm:"column:modify_time" json:"modify_time"`
281
-	TimeQuantum    int64  `gorm:"column:time_quantum" json:"time_quantum"`
389
+	ID             	int64  `gorm:"column:id" json:"id"`
390
+	OrgId          	int64  `gorm:"column:org_id" json:"org_id"`
391
+	ProvinceId     	int64  `gorm:"column:province_id" json:"province_id"`
392
+	CityId         	int64  `gorm:"column:city_id" json:"city_id"`
393
+	GatewayAddress 	string `gorm:"column:gateway_address" json:"gateway_address"`
394
+	AppId          	string `gorm:"column:app_id" json:"app_id"`
395
+	Key            	string `gorm:"column:key" json:"key"`
396
+	Status         	int64  `gorm:"column:status" json:"status"`
397
+	CreateTime     	int64  `gorm:"column:create_time" json:"create_time"`
398
+	ModifyTime     	int64  `gorm:"column:modify_time" json:"modify_time"`
399
+	TimeQuantum    	int64  `gorm:"column:time_quantum" json:"time_quantum"`
400
+	DepartmentName  string `gorm:"column:department_name" json:"department_name"`
401
+	HospitalId 		int64  `gorm:"column:hospital_id" json:"hospital_id"`
402
+	InstType    	int64  `gorm:"column:inst_type" json:"inst_type"`
403
+	DbHost			string `gorm:"column:db_host" json:"db_host"`
404
+	DbPort			string `gorm:"column:db_port" json:"db_port"`
405
+	DbUser			string `gorm:"column:db_user" json:"db_user"`
406
+	DbPass			string `gorm:"column:db_pass" json:"db_pass"`
407
+	DbName			string `gorm:"column:db_name" json:"db_name"`
282 408
 }
283 409
 
284 410
 func (DataUploadConfig) TableName() string {

+ 7 - 3
service/city_data_uoload_service.go View File

@@ -10,8 +10,12 @@ import (
10 10
 	"strings"
11 11
 )
12 12
 
13
-func FindAllDataUploadConfigOrgInfo(province_id int64, city_id int64, config_type int64) (data []*sz.DataUploadConfig, err error) {
13
+func GetSyncTimeByOrgId(org_id int64,sync_type int64) (sync_info models.XTSyncInfo,err error) {
14
+	err = readDb.Model(&models.XTSyncInfo{}).Where("org_id = ? and sync_type = ? ", org_id,sync_type).Last(&sync_info).Error
15
+	return
16
+}
14 17
 
18
+func FindAllDataUploadConfigOrgInfo(province_id int64, city_id int64, config_type int64) (data []*sz.DataUploadConfig, err error) {
15 19
 	err = readDb.Model(&sz.DataUploadConfig{}).Where("status = 1 AND province_id = ? AND city_id = ? AND config_type = ?", province_id, city_id, config_type).Find(&data).Error
16 20
 	return
17 21
 }
@@ -21,8 +25,8 @@ func FindDataUploadOrgInfo(org_id int64, module_type int64) (data sz.DataUpload,
21 25
 	return
22 26
 }
23 27
 
24
-func FindOrgData(org_id int64) (org models.UserOrg, err error) {
25
-	err = readUserDb.Model(&models.UserOrg{}).Where("status = 1 AND id = ?", org_id).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
28
+func FindOrgData(org_id int64,sync_time int64) (org models.UserOrg, err error) {
29
+	err = readUserDb.Model(&models.UserOrg{}).Where("status = 1 AND id = ? AND ctime > ?", org_id,sync_time).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
26 30
 		return readDb.Where("status = 1")
27 31
 	}).Find(&org).Error
28 32
 	return

+ 16 - 0
service/db.go View File

@@ -30,6 +30,22 @@ var writeUserDb *gorm.DB
30 30
 
31 31
 var err error
32 32
 
33
+func CreateDB(Host string,Port string,User string,Pass string,Name string) (rsdDb *gorm.DB,err error){
34
+	rdb := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", User, Pass, Host, Port, Name)
35
+	rsdDb, err = gorm.Open("mysql", rdb)
36
+	if err != nil {
37
+		//beego.Error(err)
38
+	}
39
+	rsdDb.DB().SetMaxIdleConns(5)
40
+	rsdDb.DB().SetMaxOpenConns(20)
41
+	rsdDb.LogMode(true)
42
+	return 
43
+}
44
+
45
+func CloseDB(DB *gorm.DB) {
46
+	DB.Close()
47
+}
48
+
33 49
 func ConnectDB() {
34 50
 	readHost := beego.AppConfig.String("readmysqlhost")
35 51
 	readPort := beego.AppConfig.String("readmysqlport")