Bläddra i källkod

11月9日库存管理

XMLWAN 2 år sedan
förälder
incheckning
a63a350c81

+ 0 - 414
controllers/service/admin_service.go Visa fil

@@ -1,414 +0,0 @@
1
-// 统计后台的 service
2
-
3
-package service
4
-
5
-import (
6
-	"XT_New/models"
7
-	"XT_New/models/admin_models"
8
-	"time"
9
-
10
-	"github.com/jinzhu/gorm"
11
-)
12
-
13
-func GetAdminAccount(account string, password string) (*admin_models.AdminAccount, error) {
14
-	var model admin_models.AdminAccount
15
-	err := readUserDb.Where("account = ? AND pwd = ? AND status = 1", account, password).First(&model).Error
16
-	if err != nil {
17
-		if err == gorm.ErrRecordNotFound {
18
-			return nil, nil
19
-		}
20
-		return nil, err
21
-	}
22
-	return &model, nil
23
-}
24
-
25
-// 获取总机构数
26
-func GetTotalOrgCount() (int, error) {
27
-	var count int
28
-	err := readUserDb.Model(&models.Org{}).Where("status <> 0").Count(&count).Error
29
-	if err != nil {
30
-		return 0, err
31
-	}
32
-	return count, nil
33
-
34
-}
35
-
36
-// 获取一段时间内注册的机构数量
37
-func GetRegistedOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
38
-	var count int
39
-	err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Count(&count).Error
40
-	if err != nil {
41
-		return 0, err
42
-	}
43
-	return count, nil
44
-}
45
-
46
-// 获取一段时间内注册的机构
47
-func GetRegistedOrgsFromDayToDay(from time.Time, to time.Time) ([]*models.Org, error) {
48
-	var orgs []*models.Org
49
-	err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Find(&orgs).Error
50
-	if err != nil {
51
-		return nil, err
52
-	}
53
-	return orgs, nil
54
-}
55
-
56
-// 获取一段时间内的活跃机构数
57
-func GetActiveOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
58
-	var count int
59
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Rows()
60
-	if err != nil {
61
-		return 0, err
62
-	}
63
-	if rows.Next() {
64
-		rows.Scan(&count)
65
-	}
66
-	return count, nil
67
-}
68
-
69
-type ActiveOrgListVM struct {
70
-	models.Org
71
-	ActiveTime int64 `gorm:"column:active_time" json:"active_time"`
72
-}
73
-
74
-// 获取一段时间内的活跃机构
75
-func GetActiveOrgsFromDayToDay(from time.Time, to time.Time) ([]*ActiveOrgListVM, error) {
76
-	var orgs []*ActiveOrgListVM
77
-	err := readUserDb.Raw("select * from (select log.org_id, org.*, log.ctime as active_time from sgj_user_admin_login_log as log left join sgj_user_org as org on log.org_id = org.id where log.ctime >= ? AND log.ctime <= ? AND org.status <> 0 order by log.ctime desc) as t group by t.org_id;", from.Unix(), to.Unix()).Scan(&orgs).Error
78
-	if err != nil {
79
-		return nil, err
80
-	}
81
-	return orgs, nil
82
-}
83
-
84
-// 获取一段时间内的活跃账户数
85
-func GetActiveAdminUserCountFromDayToDay(from time.Time, to time.Time) (int, error) {
86
-	var count int
87
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ? AND operate_type = 1", from.Unix(), to.Unix()).Rows()
88
-	if err != nil {
89
-		return 0, err
90
-	}
91
-	if rows.Next() {
92
-		rows.Scan(&count)
93
-	}
94
-	return count, nil
95
-}
96
-
97
-type ActiveAdminUserListVM struct {
98
-	models.App_Role
99
-	OrgName    string `gorm:"column:org_name" json:"org_name"`
100
-	ActiveTime int64  `gorm:"column:active_time" json:"active_time"`
101
-}
102
-
103
-// 获取一段时间内的活跃账户
104
-func GetActiveAdminUsersFromDayToDay(from time.Time, to time.Time) ([]*ActiveAdminUserListVM, error) {
105
-	var users []*ActiveAdminUserListVM
106
-	err := readUserDb.Raw("select * from (select log.admin_user_id as uid, admin.*, org.org_name, log.ctime as active_time from sgj_user_admin_login_log as log left join sgj_user_admin_role as admin on log.admin_user_id = admin.admin_user_id left join sgj_user_org as org on log.org_id = org.id where log.ctime >= ? AND log.ctime <= ? AND log.operate_type = 1 AND admin.status > 0 order by log.ctime desc) as t group by t.uid;", from.Unix(), to.Unix()).Scan(&users).Error
107
-	if err != nil {
108
-		return nil, err
109
-	}
110
-	return users, nil
111
-}
112
-
113
-// 获取即将到期机构数
114
-func GetWillExpireOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
115
-	var count int
116
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_serve_subscibe WHERE period_end >= ? AND period_end <= ? AND state <> 9 GROUP BY org_id;", from.Unix(), to.Unix()).Rows()
117
-	if err != nil {
118
-		return 0, err
119
-	}
120
-	if rows.Next() {
121
-		rows.Scan(&count)
122
-	}
123
-	return count, nil
124
-}
125
-
126
-// 获取已到期机构数
127
-func GetDidExpiredOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
128
-	var count int
129
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_serve_subscibe WHERE period_end >= ? AND period_end <= ? AND state <> 9 GROUP BY org_id;", from.Unix(), to.Unix()).Rows()
130
-	if err != nil {
131
-		return 0, err
132
-	}
133
-	if rows.Next() {
134
-		rows.Scan(&count)
135
-	}
136
-	return count, nil
137
-}
138
-
139
-type ExpireOrgListVM struct {
140
-	OrgID      int64  `gorm:"column:org_id" json:"org_id"`
141
-	OrgName    string `gorm:"column:org_name" json:"org_name"`
142
-	PeriodEnd  int64  `gorm:"column:period_end" json:"period_end"`
143
-	Telephone  string `gorm:"column:telephone" json:"telephone"`
144
-	ExpireDays int    `gorm:"-" json:"expire_days"`
145
-}
146
-
147
-// 获取即将到期机构
148
-func GetWillExpireOrgsFromDayToDay(from time.Time, to time.Time) ([]*ExpireOrgListVM, error) {
149
-	var vms []*ExpireOrgListVM
150
-	err := readUserDb.Raw("select s_o.org_id, s_o.period_end, o.org_name, o.telephone from (select ss.* from (select s.org_id as org_id, s.id as sid, s.period_end from sgj_serve_subscibe as s where s.period_end <= ? AND s.period_end >= ? AND s.state <> 9 order by s.id desc) as ss group by ss.org_id) as s_o left join sgj_user_org as o on o.id = s_o.org_id", to.Unix(), from.Unix()).Scan(&vms).Error
151
-	if err != nil {
152
-		return nil, err
153
-	}
154
-	for _, vm := range vms {
155
-		vm.ExpireDays = time.Unix(vm.PeriodEnd, 0).Day() - from.Day()
156
-	}
157
-	return vms, nil
158
-}
159
-
160
-// 获取已到期机构
161
-func GetDidExpireOrgsFromDayToDay(from time.Time, to time.Time) ([]*ExpireOrgListVM, error) {
162
-	var vms []*ExpireOrgListVM
163
-	err := readUserDb.Raw("select s_o.org_id, s_o.period_end, o.org_name, o.telephone from (select ss.* from (select s.org_id as org_id, s.id as sid, s.period_end from sgj_serve_subscibe as s where s.period_end >= ? AND s.period_end <= ? AND s.state <> 9 order by s.id desc) as ss group by ss.org_id) as s_o left join sgj_user_org as o on o.id = s_o.org_id", from.Unix(), to.Unix()).Scan(&vms).Error
164
-	if err != nil {
165
-		return nil, err
166
-	}
167
-	for _, vm := range vms {
168
-		vm.ExpireDays = to.Day() - time.Unix(vm.PeriodEnd, 0).Day()
169
-	}
170
-	return vms, nil
171
-}
172
-
173
-// 获取一段时间内的透析次数
174
-func GetDialysisTimesFromDayToDay(from time.Time, to time.Time) (int, error) {
175
-	var count int
176
-	err := readDb.Model(&models.DialysisOrder{}).Where("status > 0 AND dialysis_date >= ? AND dialysis_date <= ?", from.Unix(), to.Unix()).Count(&count).Error
177
-	if err != nil {
178
-		return 0, err
179
-	}
180
-	return count, nil
181
-}
182
-
183
-// 获取一段时间内的监控次数
184
-func GetMonitoringTimesFromDayToDay(from time.Time, to time.Time) (int, error) {
185
-	var count int
186
-	err := readDb.Model(&models.MonitoringRecord{}).Where("status > 0 AND monitoring_date >= ? AND monitoring_date <= ?", from.Unix(), to.Unix()).Count(&count).Error
187
-	if err != nil {
188
-		return 0, err
189
-	}
190
-	return count, nil
191
-}
192
-
193
-// 获取一段时间内新增病人数量
194
-func GetNewPatientCountFromDayToDay(from time.Time, to time.Time) (int, error) {
195
-	var count int
196
-	err := readDb.Model(&models.Patients{}).Where("status > 0 AND created_time >= ? AND created_time <= ?", from.Unix(), to.Unix()).Count(&count).Error
197
-	if err != nil {
198
-		return 0, err
199
-	}
200
-	return count, nil
201
-}
202
-
203
-// 获取病人性别分布
204
-func GetPatientGenderDistribution() (int, int, int, error) {
205
-	var maleCount, femaleCount, unknowGenderCount int
206
-	rows, err := readDb.Raw("SELECT count(id), gender FROM xt_patients WHERE (status > 0) group by gender;").Rows()
207
-	if err != nil {
208
-		return 0, 0, 0, err
209
-	}
210
-	for rows.Next() {
211
-		var gender, count int
212
-		rows.Scan(&count, &gender)
213
-		if gender == 1 {
214
-			maleCount = count
215
-		} else if gender == 2 {
216
-			femaleCount = count
217
-		} else {
218
-			unknowGenderCount = count
219
-		}
220
-	}
221
-	return maleCount, femaleCount, unknowGenderCount, nil
222
-}
223
-
224
-// 获取某种传染病的病人数,diseaseType = 0时为没有传染病
225
-// 1乙肝 2丙肝 3艾滋病 4肺结核 5梅毒
226
-func GetInfectiousDiseasePatientCount(diseaseType int) (int, error) {
227
-	if diseaseType == 0 {
228
-		var count int
229
-		rows, err := readDb.Raw("select count(p.id) from xt_patients as p where id not in (select p_d.patient_id from xt_patients_infectious_diseases as p_d where status = 1 group by p_d.patient_id) and status = 1;").Rows()
230
-		if err != nil {
231
-			return 0, err
232
-		}
233
-		if rows.Next() {
234
-			rows.Scan(&count)
235
-		}
236
-		return count, nil
237
-
238
-	} else {
239
-		var count int
240
-		rows, err := readDb.Raw("select count(distinct patient_id) from xt_patients_infectious_diseases where status = 1 and disease_id = ?;", diseaseType).Rows()
241
-		if err != nil {
242
-			return 0, err
243
-		}
244
-		if rows.Next() {
245
-			rows.Scan(&count)
246
-		}
247
-		return count, nil
248
-	}
249
-}
250
-
251
-// 获取患者年龄分布
252
-func GetPatientAgeDistribution() ([]*PatientAgeCountStruct, error) {
253
-	var counts []*PatientAgeCountStruct
254
-	err := readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM (
255
-		SELECT
256
-			CASE
257
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d'))<10 THEN '10'
258
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=10 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<20 THEN '20'
259
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=20 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<30 THEN '30'
260
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=30 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<40 THEN '40'
261
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=40 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<50 THEN '50'
262
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=50 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<60 THEN '60'
263
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=60 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<70 THEN '70'
264
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=70 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<80 THEN '80'
265
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=80 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<90 THEN '90'
266
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=90 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<100 THEN '100'
267
-				ELSE '-1'
268
-			END
269
-		AS nnd FROM xt_patients where status=1
270
-	) a GROUP BY nnd;`).Scan(&counts).Error
271
-	if err != nil {
272
-		return nil, err
273
-	}
274
-	return counts, nil
275
-}
276
-
277
-func GetAdminUserElectronicSignatureTwo(userid int64) (*models.AdminUserElectronicSignature, error) {
278
-	var es models.AdminUserElectronicSignature
279
-	err := readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("creator=? and status=1", userid).First(&es).Error
280
-
281
-	if err == gorm.ErrRecordNotFound {
282
-		return nil, nil
283
-	}
284
-	if err != nil {
285
-		return nil, err
286
-	}
287
-	return &es, nil
288
-}
289
-
290
-func GetAdminUserElectronicSignature(orgID int64, appID int64, userID int64) (*models.AdminUserElectronicSignature, error) {
291
-	var es models.AdminUserElectronicSignature
292
-	err := readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id=? and creator=? and status=1", orgID, appID, userID).First(&es).Error
293
-
294
-	if err == gorm.ErrRecordNotFound {
295
-		return nil, nil
296
-	}
297
-	if err != nil {
298
-		return nil, err
299
-	}
300
-	return &es, nil
301
-}
302
-
303
-func GetPatientSignature(orgID int64, patientid int64, dialysis_date int64) (*models.DialysisOrder, error) {
304
-	var es models.DialysisOrder
305
-	err := XTReadDB().Model(&models.DialysisOrder{}).Where("user_org_id=? and patient_id=? and dialysis_date=? and status=1", orgID, patientid, dialysis_date).First(&es).Error
306
-
307
-	if err == gorm.ErrRecordNotFound {
308
-		return nil, nil
309
-	}
310
-	if err != nil {
311
-		return nil, err
312
-	}
313
-	return &es, nil
314
-}
315
-
316
-func GetPatinentHead(orgid int64, appid int64, userid int64) (*models.SgjUserAdminPatientHead, error) {
317
-	var es models.SgjUserAdminPatientHead
318
-	err := readUserDb.Model(&models.SgjUserAdminPatientHead{}).Where("org_id = ? and app_id = ? and creator=? and status =1", orgid, appid, userid).First(&es).Error
319
-	if err == gorm.ErrRecordNotFound {
320
-		return nil, nil
321
-	}
322
-	if err != nil {
323
-		return nil, err
324
-	}
325
-	return &es, nil
326
-}
327
-
328
-func CreateAdminUserElectronicSignature(es *models.AdminUserElectronicSignature) error {
329
-	err := writeUserDb.Create(es).Error
330
-	return err
331
-}
332
-
333
-func SaveAdminUserElectronicSignature(es *models.AdminUserElectronicSignature) error {
334
-	err := writeUserDb.Save(es).Error
335
-	return err
336
-}
337
-
338
-func CreateAdminUserHead(es *models.SgjUserAdminPatientHead) error {
339
-	err := writeUserDb.Create(es).Error
340
-	return err
341
-}
342
-func SaveAdminUserHead(es *models.SgjUserAdminPatientHead) error {
343
-	err := writeUserDb.Create(es).Error
344
-	return err
345
-}
346
-
347
-func GetAdminUserSpecialPermission(orgID int64, appID int64, adminUserID int64, permissionType models.SpecialPermissionType) (*models.AdminUserSpecialPermission, error) {
348
-	var record models.AdminUserSpecialPermission
349
-	err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND admin_user_id = ? AND permission = ? AND status = 1", orgID, appID, adminUserID, permissionType).First(&record).Error
350
-	if err != nil {
351
-		if err == gorm.ErrRecordNotFound {
352
-			return nil, nil
353
-		} else {
354
-			return nil, err
355
-		}
356
-	}
357
-	return &record, nil
358
-}
359
-
360
-func SaveAdminUserSpecialPermission(permission *models.AdminUserSpecialPermission) error {
361
-	err := writeDb.Save(permission).Error
362
-	return err
363
-}
364
-
365
-func GetAllValidAdminUsersWithSpecialPermission(orgID int64, appID int64, permissionType models.SpecialPermissionType) ([]*models.AdminUserSpecialPermission, error) {
366
-	var records []*models.AdminUserSpecialPermission
367
-	err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND permission = ? AND status = 1", orgID, appID, permissionType).Find(&records).Error
368
-	if err != nil {
369
-		return nil, err
370
-	}
371
-	return records, nil
372
-}
373
-
374
-func GetAllSpecialPermissionAdminUsersWithoutStatus(orgID int64, appID int64, permissionType models.SpecialPermissionType) ([]*models.AdminUserSpecialPermission, error) {
375
-	var records []*models.AdminUserSpecialPermission
376
-	err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND permission = ?", orgID, appID, permissionType).Find(&records).Error
377
-	if err != nil {
378
-		return nil, err
379
-	}
380
-	return records, nil
381
-}
382
-
383
-func CancelAllSpecialPermissionAdminUsers(orgID int64, appID int64, permissionType models.SpecialPermissionType) error {
384
-	tx := writeDb.Begin()
385
-	updateTime := time.Now().Unix()
386
-	err := tx.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND status = 1 AND permission = ?", orgID, appID, permissionType).Updates(map[string]interface{}{"status": 0, "mtime": updateTime}).Error
387
-	if err != nil {
388
-		tx.Rollback()
389
-		return err
390
-	}
391
-	tx.Commit()
392
-	return nil
393
-}
394
-
395
-func BatchSaveSpecialPermissionAdminUsers(users []*models.AdminUserSpecialPermission) error {
396
-	tx := writeDb.Begin()
397
-	for _, user := range users {
398
-		tx.Save(user)
399
-	}
400
-	return tx.Commit().Error
401
-}
402
-
403
-func ModifyAdminUserName(name string, id int64) error {
404
-	tx := writeUserDb.Begin()
405
-	updateTime := time.Now().Unix()
406
-	err := tx.Model(&models.AdminUser{}).Where("id = ?", id).Updates(map[string]interface{}{"name": name, "mtime": updateTime}).Error
407
-	if err != nil {
408
-		tx.Rollback()
409
-		return err
410
-	}
411
-	tx.Commit()
412
-	return nil
413
-
414
-}

+ 0 - 458
controllers/service/app_version.go Visa fil

@@ -1,458 +0,0 @@
1
-package service
2
-
3
-import (
4
-	"XT_New/models"
5
-	"github.com/jinzhu/gorm"
6
-	"time"
7
-)
8
-
9
-func GetAppVersionByAppType(apptype int64) (*models.AppVersion, error) {
10
-	var version models.AppVersion
11
-	err := readDb.Model(&models.AppVersion{}).Where("app_type=?", apptype).First(&version).Error
12
-	if err == gorm.ErrRecordNotFound {
13
-		return nil, nil
14
-	}
15
-
16
-	if err != nil {
17
-		return nil, err
18
-	}
19
-	return &version, nil
20
-}
21
-
22
-func GetAllAppOrg() ([]*models.OrgApp, error) {
23
-	var app []*models.OrgApp
24
-	err := readUserDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id > 0").Group("org_id").Find(&app).Error
25
-	if err == gorm.ErrRecordNotFound {
26
-		return nil, nil
27
-	}
28
-
29
-	if err != nil {
30
-		return nil, err
31
-	}
32
-	return app, nil
33
-}
34
-
35
-func GetSystemApp() ([]*models.OrgApp, error) {
36
-	var app []*models.OrgApp
37
-	err := readDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id = 0 ").Find(&app).Error
38
-	if err == gorm.ErrRecordNotFound {
39
-		return nil, nil
40
-	}
41
-
42
-	if err != nil {
43
-		return nil, err
44
-	}
45
-	return app, nil
46
-}
47
-
48
-func GetApp() ([]*models.OrgApp, error) {
49
-	var app []*models.OrgApp
50
-	err := readDb.Model(&models.OrgApp{}).Where("status = 1 AND org_id = 0").Find(&app).Error
51
-	if err == gorm.ErrRecordNotFound {
52
-		return nil, nil
53
-	}
54
-
55
-	if err != nil {
56
-		return nil, err
57
-	}
58
-	return app, nil
59
-}
60
-
61
-func GetAppByType(orgID int64, app_type int) (*models.OrgApp, error) {
62
-	var apps models.OrgApp
63
-	err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
64
-	if err != nil {
65
-		return nil, err
66
-	}
67
-	return &apps, nil
68
-}
69
-
70
-func CreateOrgApp(app *models.OrgApp) {
71
-	writeUserDb.Create(&app)
72
-
73
-}
74
-
75
-func GetAllUserRole(org_id int64) (appRole []*models.App_Role) {
76
-	if org_id == 0 {
77
-		readUserDb.Model(&models.App_Role{}).Where("status = 1").Find(&appRole)
78
-
79
-	} else {
80
-		readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? ", org_id).Find(&appRole)
81
-
82
-	}
83
-	return
84
-}
85
-
86
-func GetAllUserRoleByUserTypeOne(org_id int) (appRole []*models.App_Role) {
87
-	readUserDb.Model(&models.App_Role{}).Where("status = 1 AND user_type = 1").Find(&appRole)
88
-	return
89
-}
90
-
91
-func GetAllUserRoleByUserTypeOther() (appRole []*models.App_Role) {
92
-	//app, _ := GetOrgApp(int64(org_id), 3)
93
-
94
-	//if org_id == 0 {
95
-	readUserDb.Model(&models.App_Role{}).Where("status = 1 AND user_type > 1").Find(&appRole)
96
-	//
97
-	//} else {
98
-	//	readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ?  AND user_type > 1 AND app_id = ? ", org_id, app.Id).Find(&appRole)
99
-	//
100
-	//}
101
-	return
102
-}
103
-
104
-func FindRoleByUserTypeOne(org_id int64) (role models.Role) {
105
-	readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id = ? AND is_system = 2 AND role_name = '医生'", org_id).First(&role)
106
-	return
107
-}
108
-
109
-func FindRoleByUserTypeTwo(org_id int64) (role models.Role) {
110
-	readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id = ? AND is_system = 3 AND role_name = '护士'", org_id).First(&role)
111
-	return
112
-}
113
-
114
-func GetAllRole() ([]*models.Role, error) {
115
-	var app []*models.Role
116
-	err := readUserDb.Model(&models.Role{}).Where("status = 1 AND org_id > 0").Group("org_id").Find(&app).Error
117
-	if err == gorm.ErrRecordNotFound {
118
-		return nil, nil
119
-	}
120
-	if err != nil {
121
-		return nil, err
122
-	}
123
-	return app, nil
124
-}
125
-
126
-func UpdateRoleIds(id int64, ids string) {
127
-	writeUserDb.Model(&models.App_Role{}).Where("status = 1 AND id = ?", id).Updates(map[string]interface{}{"role_ids": ids, "mtime": time.Now().Unix()})
128
-
129
-}
130
-
131
-func GetOrgAppA(orgID int64, app_type int) (*models.OrgApp, error) {
132
-	var apps models.OrgApp
133
-	err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
134
-	if err != nil {
135
-		return nil, err
136
-	}
137
-	return &apps, nil
138
-}
139
-
140
-func GetOrgByIdB(orgID int64) (*models.Org, error) {
141
-	var org models.Org
142
-	err := readUserDb.Model(&models.Org{}).Where("id = ?", orgID).First(&org).Error
143
-	if err != nil {
144
-		if err == gorm.ErrRecordNotFound {
145
-			return nil, nil
146
-		} else {
147
-			return nil, err
148
-		}
149
-	}
150
-	return &org, nil
151
-}
152
-
153
-func GetOrgAppB(orgID int64, app_type int) (*models.OrgApp, error) {
154
-	var apps models.OrgApp
155
-	err := readUserDb.Where("app_type = ? AND org_id = ? AND status = 1", app_type, orgID).First(&apps).Error
156
-	if err != nil {
157
-		return nil, err
158
-	}
159
-	return &apps, nil
160
-}
161
-
162
-func CreateOrgRoleB(role *models.Role) (err error) {
163
-	err = writeUserDb.Create(&role).Error
164
-	return
165
-}
166
-
167
-func CreateRolePurviewB(purview *models.RolePurview) (err error) {
168
-	err = writeUserDb.Create(&purview).Error
169
-	return
170
-}
171
-
172
-func CreateFuncRolePurviewB(purview *models.SgjUserRoleFuncPurview) (err error) {
173
-	err = writeUserDb.Create(&purview).Error
174
-	return
175
-}
176
-
177
-func GetSystemRole(orgID int64) ([]*models.Role, error) {
178
-	var roles []*models.Role
179
-	err := readUserDb.Where(" org_id = ? AND status = 1 AND is_system > 1", orgID).First(&roles).Error
180
-	if err != nil {
181
-		return nil, err
182
-	}
183
-	return roles, nil
184
-}
185
-
186
-func HandleData() {
187
-	var pe []*models.PredialysisEvaluation
188
-	//readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = 12 AND record_date <= 1587571200").Find(&prescription)
189
-	//for _, item := range prescription {
190
-	//	writeDb.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id =12 AND assessment_date = ?", item.RecordDate).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "actual_ultrafiltration": item.Ultrafiltration})
191
-	//}
192
-	readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = 9538 AND dialysis_order_id > 0").Find(&pe)
193
-
194
-	for _, item := range pe {
195
-		var sch models.Schedule
196
-		err := readDb.Model(&models.Schedule{}).Where("status = 1 AND schedule_date = ? AND patient_id = ? AND user_org_id = 9538", item.AssessmentDate, item.PatientId).First(&sch).Error
197
-
198
-		if err == nil {
199
-			if sch.ID > 0 {
200
-				order := &models.DialysisOrder{
201
-					DialysisDate:   sch.ScheduleDate,
202
-					UserOrgId:      9538,
203
-					PatientId:      sch.PatientId,
204
-					Stage:          2,
205
-					BedID:          sch.BedId,
206
-					StartNurse:     554,
207
-					FinishNurse:    554,
208
-					Status:         1,
209
-					CreatedTime:    sch.ScheduleDate,
210
-					UpdatedTime:    sch.ScheduleDate,
211
-					StartTime:      sch.ScheduleDate,
212
-					EndTime:        sch.ScheduleDate,
213
-					PunctureNurse:  554,
214
-					Creator:        554,
215
-					Modifier:       554,
216
-					FinishCreator:  554,
217
-					FinishModifier: 554,
218
-					SchedualType:   sch.ScheduleType,
219
-				}
220
-				writeDb.Create(&order)
221
-			}
222
-		}
223
-
224
-	}
225
-
226
-}
227
-
228
-func FindAllOrgByImportType() (org []*models.Org, err error) {
229
-	err = readUserDb.Model(&models.Org{}).Where("status =1 AND import = 0").Find(&org).Error
230
-	return
231
-}
232
-
233
-func FindAllPrescription(org_id int64) (prescription []*models.DialysisPrescription, err error) {
234
-	err = readDb.Model(&models.DialysisPrescription{}).Where("user_org_id=? AND status= 1 AND record_date >= 1593446400", org_id).Find(&prescription).Error
235
-	return
236
-}
237
-
238
-func AddSigleDialysisBeforePre(before *models.DialysisBeforePrepare) {
239
-	writeDb.Create(&before)
240
-}
241
-
242
-func GetAllHisDoctorInfo(org_id int64) (his []*models.HisDoctorAdviceInfo, err error) {
243
-	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND status = 1", org_id).Find(&his).Error
244
-	return
245
-}
246
-
247
-func GetAllHisInfo(org_id int64) (his []*models.HisPrescriptionProject, err error) {
248
-	err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND status = 1", org_id).Find(&his).Error
249
-	return
250
-}
251
-
252
-func UpDateHis(his *models.HisDoctorAdviceInfo) {
253
-	writeDb.Save(&his)
254
-}
255
-
256
-func UpDateHis2(his *models.HisPrescriptionProject) {
257
-	writeDb.Save(&his)
258
-}
259
-
260
-func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
261
-	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code = '' AND fa_piao_number = '' ", org_id).Find(&his).Error
262
-	return
263
-}
264
-
265
-func GetAllHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
266
-	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code <> '' AND fa_piao_number <> '' ", org_id).Last(&his).Error
267
-	return
268
-}
269
-
270
-func GetLastHisOrder() (his models.HisOrder, err error) {
271
-	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 AND status = 1 AND order_status = 2").Last(&his).Error
272
-	return
273
-}
274
-
275
-type HisPrescriptionAdviceTemplate struct {
276
-	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
277
-	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
278
-	PatientId             int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
279
-	HisPatientId          int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
280
-	AdviceType            int64   `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
281
-	AdviceDate            int64   `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
282
-	StartTime             int64   `gorm:"column:start_time" json:"start_time" form:"start_time"`
283
-	AdviceName            string  `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
284
-	AdviceDesc            string  `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
285
-	ReminderDate          int64   `gorm:"column:reminder_date" json:"reminder_date" form:"reminder_date"`
286
-	SingleDose            float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
287
-	SingleDoseUnit        string  `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
288
-	PrescribingNumber     float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
289
-	PrescribingNumberUnit string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
290
-	DeliveryWay           string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
291
-	ExecutionFrequency    string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
292
-	AdviceDoctor          int64   `gorm:"column:advice_doctor" json:"advice_doctor" form:"advice_doctor"`
293
-	Status                int64   `gorm:"column:status" json:"status" form:"status"`
294
-	CreatedTime           int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
295
-	UpdatedTime           int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
296
-	AdviceAffirm          string  `gorm:"column:advice_affirm" json:"advice_affirm" form:"advice_affirm"`
297
-	Remark                string  `gorm:"column:remark" json:"remark" form:"remark"`
298
-	StopTime              int64   `gorm:"column:stop_time" json:"stop_time" form:"stop_time"`
299
-	StopReason            string  `gorm:"column:stop_reason" json:"stop_reason" form:"stop_reason"`
300
-	StopDoctor            int64   `gorm:"column:stop_doctor" json:"stop_doctor" form:"stop_doctor"`
301
-	StopState             int64   `gorm:"column:stop_state" json:"stop_state" form:"stop_state"`
302
-	ParentId              int64   `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
303
-	ExecutionTime         int64   `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
304
-	ExecutionStaff        int64   `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
305
-	ExecutionState        int64   `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
306
-	Checker               int64   `gorm:"column:checker" json:"checker" form:"checker"`
307
-	RecordDate            int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
308
-	DialysisOrderId       int64   `gorm:"column:dialysis_order_id" json:"dialysis_order_id" form:"dialysis_order_id"`
309
-	CheckTime             int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
310
-	CheckState            int64   `gorm:"column:check_state" json:"check_state" form:"check_state"`
311
-	DrugSpec              float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
312
-	DrugSpecUnit          string  `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
313
-	Groupno               int64   `gorm:"column:groupno" json:"groupno" form:"groupno"`
314
-	RemindType            int64   `gorm:"column:remind_type" json:"remind_type" form:"remind_type"`
315
-	FrequencyType         int64   `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
316
-	DayCount              int64   `gorm:"column:day_count" json:"day_count" form:"day_count"`
317
-	WeekDay               string  `gorm:"column:week_day" json:"week_day" form:"week_day"`
318
-	TemplateId            string  `gorm:"column:template_id" json:"template_id" form:"template_id"`
319
-	Modifier              int64   `gorm:"column:modifier" json:"modifier" form:"modifier"`
320
-	DrugId                int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
321
-	Price                 float64 `gorm:"column:price" json:"price" form:"price"`
322
-	PrescriptionId        int64   `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
323
-	MedListCodg           string  `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
324
-	FeedetlSn             string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
325
-	Day                   int64   `gorm:"column:day" json:"day" form:"day"`
326
-	Diagnosis             int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
327
-	HospApprFlag          int64   `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
328
-	LmtUsedFlag           int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
329
-}
330
-
331
-func (HisPrescriptionAdviceTemplate) TableName() string {
332
-	return "his_prescription_advice_template"
333
-}
334
-
335
-type HisPrescriptionInfoTemplateTwo struct {
336
-	ID                            int64                           `gorm:"column:id" json:"id" form:"id"`
337
-	UserOrgId                     int64                           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
338
-	RecordDate                    int64                           `gorm:"column:record_date" json:"record_date" form:"record_date"`
339
-	PatientId                     int64                           `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
340
-	Status                        int64                           `gorm:"column:status" json:"status" form:"status"`
341
-	Ctime                         int64                           `gorm:"column:ctime" json:"ctime" form:"ctime"`
342
-	Mtime                         int64                           `gorm:"column:mtime" json:"mtime" form:"mtime"`
343
-	Type                          int64                           `gorm:"column:type" json:"type" form:"type"`
344
-	Creator                       int64                           `gorm:"column:creator" json:"creator" form:"creator"`
345
-	Modifier                      int64                           `gorm:"column:modifier" json:"modifier" form:"modifier"`
346
-	PType                         int64                           `gorm:"column:p_type" json:"p_type" form:"p_type"`
347
-	PTemplateId                   int64                           `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
348
-	HisPrescriptionAdviceTemplate []HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
349
-	MedType                       string                          `gorm:"column:med_type" json:"med_type" form:"med_type"`
350
-}
351
-
352
-func (HisPrescriptionInfoTemplateTwo) TableName() string {
353
-	return "his_prescription_info_template"
354
-}
355
-
356
-func GetHisPrescriptionTemplateTwo() (prescription []*HisPrescriptionInfoTemplateTwo, err error) {
357
-	err = readDb.Model(&HisPrescriptionInfoTemplateTwo{}).
358
-		Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
359
-			return db.Where("status = 1")
360
-		}).
361
-		Where("status = 1 ").
362
-		Find(&prescription).Error
363
-	return
364
-}
365
-
366
-func SaveAdviceTemplate(advice HisPrescriptionAdviceTemplate) {
367
-	writeDb.Save(&advice)
368
-}
369
-
370
-func GetAllPT(org_id int64) (his []*models.HisPrescriptionTemplate, err error) {
371
-	err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? AND status = 1", org_id).Find(&his).Error
372
-	return
373
-}
374
-
375
-type HisPrescriptionProjectTemplate struct {
376
-	ID                 int64   `gorm:"column:id" json:"id" form:"id"`
377
-	ProjectId          int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
378
-	Price              float64 `gorm:"column:price" json:"price" form:"price"`
379
-	UserOrgId          int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
380
-	Status             int64   `gorm:"column:status" json:"status" form:"status"`
381
-	Ctime              int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
382
-	Mtime              int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
383
-	PatientId          int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
384
-	HisPatientId       int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
385
-	RecordDate         int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
386
-	Count              string  `gorm:"column:count" json:"count" form:"count"`
387
-	FeedetlSn          string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
388
-	MedListCodg        string  `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
389
-	SingleDose         string  `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
390
-	DeliveryWay        string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
391
-	ExecutionFrequency string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
392
-	Day                string  `gorm:"column:day" json:"day" form:"day"`
393
-	Remark             string  `gorm:"column:remark" json:"remark" form:"remark"`
394
-	Unit               string  `gorm:"column:unit" json:"unit" form:"unit"`
395
-	Type               int64   `gorm:"column:type" json:"type" form:"type"`
396
-	PrescriptionId     int64   `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
397
-	FrequencyType      int64   `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
398
-	DayCount           int64   `gorm:"column:day_count" json:"day_count" form:"day_count"`
399
-	WeekDay            string  `gorm:"column:week_day" json:"week_day" form:"week_day"`
400
-}
401
-
402
-func (HisPrescriptionProjectTemplate) TableName() string {
403
-	return "his_prescription_project_template"
404
-}
405
-
406
-type HisPrescriptionInfoTemplateTHree struct {
407
-	ID                             int64                            `gorm:"column:id" json:"id" form:"id"`
408
-	UserOrgId                      int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
409
-	RecordDate                     int64                            `gorm:"column:record_date" json:"record_date" form:"record_date"`
410
-	PatientId                      int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
411
-	Status                         int64                            `gorm:"column:status" json:"status" form:"status"`
412
-	Ctime                          int64                            `gorm:"column:ctime" json:"ctime" form:"ctime"`
413
-	Mtime                          int64                            `gorm:"column:mtime" json:"mtime" form:"mtime"`
414
-	Type                           int64                            `gorm:"column:type" json:"type" form:"type"`
415
-	Creator                        int64                            `gorm:"column:creator" json:"creator" form:"creator"`
416
-	Modifier                       int64                            `gorm:"column:modifier" json:"modifier" form:"modifier"`
417
-	PType                          int64                            `gorm:"column:p_type" json:"p_type" form:"p_type"`
418
-	PTemplateId                    int64                            `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
419
-	HisPrescriptionAdviceTemplate  []HisPrescriptionAdviceTemplate  `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
420
-	HisPrescriptionProjectTemplate []HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
421
-	MedType                        string                           `gorm:"column:med_type" json:"med_type" form:"med_type"`
422
-}
423
-
424
-func (HisPrescriptionInfoTemplateTHree) TableName() string {
425
-	return "his_prescription_info_template"
426
-}
427
-
428
-func GetAllPTInfo(org_id int64, p_template_id int64) (his []*HisPrescriptionInfoTemplateTHree, err error) {
429
-	err = readDb.Model(&HisPrescriptionInfoTemplateTHree{}).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
430
-		return db.Where("status = 1")
431
-	}).Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
432
-		return db.Where("status = 1")
433
-	}).Where("user_org_id = ? AND status = 1 AND p_template_id = ?", org_id, p_template_id).Find(&his).Error
434
-	return
435
-}
436
-
437
-func GetAllInfo(org_id int64, project_id int64) (his []*HisPrescriptionProjectTemplate, err error) {
438
-	err = readDb.Model(&HisPrescriptionProjectTemplate{}).Where("user_org_id = ? AND status = 1 AND project_id = ? ", org_id, project_id).Find(&his).Error
439
-	return
440
-}
441
-func UpdateStatus(project_id int64, p_id int64) {
442
-	writeDb.Model(&HisPrescriptionProjectTemplate{}).Where("id = ?", project_id).Updates(map[string]interface{}{"status": 0})
443
-	writeDb.Model(&HisPrescriptionInfoTemplateTwo{}).Where("id = ?", p_id).Updates(map[string]interface{}{"status": 0})
444
-}
445
-
446
-func SaveOrder(order *models.HisOrder) {
447
-	writeDb.Save(&order)
448
-}
449
-
450
-func GetAllPrivateHis(org_id int64) (his []*models.HisPatient) {
451
-	readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND balance_accounts_type = 2 AND status = 1", org_id).Find(&his)
452
-	return
453
-}
454
-
455
-func SaveHis(his *models.HisPatient) {
456
-	writeDb.Save(his)
457
-	return
458
-}

Filskillnaden har hållits tillbaka eftersom den är för stor
+ 0 - 2026
controllers/service/new_warehouse_service.go


Filskillnaden har hållits tillbaka eftersom den är för stor
+ 0 - 6052
controllers/service/warhouse_service.go


+ 75 - 78
service/warhouse_service.go Visa fil

@@ -134,72 +134,55 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
134 134
 
135 135
 	// 将该批次的剩余库存数量转换为拆零数量
136 136
 
137
-	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
138
-
139
-		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
140
-
141
-	}
142
-	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
143
-
144
-		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
137
+	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
145 138
 
146
-	}
147
-	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
139
+	//查找药品信息
140
+	//baseInfo, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
148 141
 
149
-		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
142
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
150 143
 
151
-	}
144
+	if stock_number >= deliver_number {
152 145
 
153
-	var maxNumber int64 = 0
154
-	var minNumber int64 = 0
146
+		var maxNumber int64 = 0
147
+		var minNumber int64 = 0
148
+		//var stock_max_number int64 = 0
149
+		//stock_max_number = warehouse.StockMaxNumber
155 150
 
156
-	maxNumber = deliver_number / drup.MinNumber
157
-	minNumber = deliver_number % drup.MinNumber
151
+		maxNumber = deliver_number / drup.MinNumber
152
+		minNumber = deliver_number % drup.MinNumber
158 153
 
159
-	if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
160
-		minNumber = maxNumber
161
-	}
154
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
155
+			minNumber = maxNumber
156
+		}
162 157
 
163
-	if drup.MaxUnit != drup.MinUnit {
164
-		if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
165
-			return errors.New("库存数量不足")
158
+		if drup.MaxUnit != drup.MinUnit {
159
+			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
160
+				return errors.New("库存数量不足")
161
+			}
166 162
 		}
167
-	}
168 163
 
169
-	if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
170
-		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
171
-	}
172
-	if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
173
-		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
174
-	}
175
-	if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
176 164
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
177
-	}
178 165
 
179
-	if warehouse.StockMaxNumber < 0 {
180
-		warehouse.StockMaxNumber = 0
181
-	}
182
-	if warehouse.StockMinNumber < 0 {
183
-		warehouse.StockMinNumber = 0
184
-	}
166
+		if warehouse.StockMaxNumber < 0 {
167
+			warehouse.StockMaxNumber = 0
168
+		}
169
+		if warehouse.StockMinNumber < 0 {
170
+			warehouse.StockMinNumber = 0
171
+		}
185 172
 
186
-	warehouse.Mtime = time.Now().Unix()
173
+		warehouse.Mtime = time.Now().Unix()
187 174
 
188
-	if warehouse.StockMinNumber < minNumber {
175
+		if warehouse.StockMinNumber < minNumber {
189 176
 
190
-		warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
191
-		warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
192
-	} else {
193
-		if minNumber > 0 {
194
-			if (warehouse.StockMinNumber - minNumber) >= 0 {
177
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
178
+			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
179
+		} else {
180
+			if minNumber > 0 {
195 181
 				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
196 182
 			}
197 183
 
198
-		}
199
-
200
-		if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
201
-			if warehouse.StockMinNumber > 0 {
202
-				if (warehouse.StockMinNumber - deliver_number) >= 0 {
184
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
185
+				if warehouse.StockMinNumber > 0 {
203 186
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
204 187
 				}
205 188
 
@@ -207,43 +190,37 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
207 190
 
208 191
 		}
209 192
 
210
-	}
193
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
194
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
195
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
196
+			}
211 197
 
212
-	if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
213
-		if (warehouse.StockMinNumber - deliver_number) >= 0 {
214
-			warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
215 198
 		}
216 199
 
217
-	}
218
-
219
-	if drup.MaxUnit != drup.MinUnit {
220
-		if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
221
-			return errors.New("库存数量不足")
200
+		if drup.MaxUnit != drup.MinUnit {
201
+			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
202
+				return errors.New("库存数量不足")
203
+			}
204
+		}
205
+		if warehouse.StockMinNumber <= 0 {
206
+			warehouse.StockMinNumber = 0
222 207
 		}
223
-	}
224
-	if warehouse.StockMinNumber <= 0 {
225
-		warehouse.StockMinNumber = 0
226
-	}
227
-
228
-	errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
229 208
 
230
-	if errThree != nil {
231
-		return errThree
232
-	}
209
+		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
233 210
 
234
-	//查询剩余库存
235
-	stockInfo, _ := GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId)
236
-	var sum_count int64
237
-	for _, its := range stockInfo {
238
-		if its.MaxUnit == drup.MaxUnit {
239
-			its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
211
+		if errThree != nil {
212
+			return errThree
240 213
 		}
241
-		sum_count += its.StockMaxNumber + its.StockMinNumber
242
-	}
243 214
 
244
-	// 当库存数量大于或等于出库数量的话,则正常出库该批次
245
-
246
-	if stock_number >= deliver_number {
215
+		//查询剩余库存
216
+		stockInfo, _ := GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId)
217
+		var sum_count int64
218
+		for _, its := range stockInfo {
219
+			if its.MaxUnit == drup.MaxUnit {
220
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
221
+			}
222
+			sum_count += its.StockMaxNumber + its.StockMinNumber
223
+		}
247 224
 
248 225
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
249 226
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
@@ -271,6 +248,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
271 248
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
272 249
 			StorehouseId:            storeConfig.DrugStorehouseOut,
273 250
 			IsCheck:                 1,
251
+			OverCount:               sum_count,
274 252
 		}
275 253
 
276 254
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
@@ -330,6 +308,15 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
330 308
 			return errTwo
331 309
 		}
332 310
 
311
+		var out_count int64
312
+		//查询出库数据
313
+		infoCountList, _ := FindDrugWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
314
+		for _, item := range infoCountList {
315
+			out_count += item.Count
316
+		}
317
+		//出库数量相加
318
+		AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
319
+
333 320
 		return nil
334 321
 	} else {
335 322
 
@@ -433,6 +420,14 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
433 420
 			sum_count += its.StockMaxNumber + its.StockMinNumber
434 421
 		}
435 422
 
423
+		var out_count int64
424
+
425
+		//查询出库数据
426
+		infoCountList, _ := FindDrugWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
427
+		for _, item := range infoCountList {
428
+			out_count += item.Count
429
+		}
430
+
436 431
 		drugflow := models.DrugFlow{
437 432
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
438 433
 			WarehouseOutId:          warehouseout.ID,
@@ -463,6 +458,8 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
463 458
 		}
464 459
 
465 460
 		CreateDrugFlowOne(drugflow)
461
+		//出库数量相加
462
+		AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
466 463
 
467 464
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
468 465
 		prescribingNumber_two_temp := deliver_number - stock_number