Browse Source

修改redis清除数据时间

csx 4 years ago
parent
commit
b152e80545

+ 4 - 4
controllers/base_api_controller.go View File

@@ -81,7 +81,7 @@ func (this *BaseAuthAPIController) Prepare() {
81 81
 		userAdmin.ModifyTime = 1530786071
82 82
 		var subscibe models.ServeSubscibe
83 83
 		subscibe.ID = 1
84
-		subscibe.OrgId = 7957
84
+		subscibe.OrgId = 4
85 85
 		subscibe.PeriodStart = 1538035409
86 86
 		subscibe.PeriodEnd = 1569571409
87 87
 		subscibe.State = 1
@@ -91,7 +91,7 @@ func (this *BaseAuthAPIController) Prepare() {
91 91
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
92 92
 		subscibes[4] = &subscibe
93 93
 		var adminUserInfo service.AdminUserInfo
94
-		adminUserInfo.CurrentOrgId = 7957
94
+		adminUserInfo.CurrentOrgId = 4
95 95
 		adminUserInfo.CurrentAppId = 18
96 96
 		adminUserInfo.AdminUser = &userAdmin
97 97
 		adminUserInfo.Subscibes = subscibes
@@ -326,7 +326,7 @@ func (this *BaseServeAPIController) Prepare() {
326 326
 		userAdmin.ModifyTime = 1530786071
327 327
 		var subscibe models.ServeSubscibe
328 328
 		subscibe.ID = 1
329
-		subscibe.OrgId = 7957
329
+		subscibe.OrgId = 4
330 330
 		subscibe.PeriodStart = 1538035409
331 331
 		subscibe.PeriodEnd = 1569571409
332 332
 		subscibe.State = 1
@@ -336,7 +336,7 @@ func (this *BaseServeAPIController) Prepare() {
336 336
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
337 337
 		subscibes[4] = &subscibe
338 338
 		var adminUserInfo service.AdminUserInfo
339
-		adminUserInfo.CurrentOrgId = 7957
339
+		adminUserInfo.CurrentOrgId = 4
340 340
 		adminUserInfo.CurrentAppId = 18
341 341
 		adminUserInfo.AdminUser = &userAdmin
342 342
 		adminUserInfo.Subscibes = subscibes

File diff suppressed because it is too large
+ 137 - 2220
controllers/dialysis_api_controller.go


File diff suppressed because it is too large
+ 26 - 1467
controllers/dialysis_record_api_controller.go


+ 11 - 11
controllers/mobile_api_controllers/check_weight_api_controller.go View File

@@ -554,17 +554,17 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
554 554
 			}
555 555
 		}
556 556
 
557
-		//if dialysisPrescribe != nil {
558
-		//	dialysisPrescribe.UpdatedTime = time.Now().Unix()
559
-		//	dialysisPrescribe.RecordDate = theAssessmentDateTime
560
-		//	dialysisPrescribe.DewaterAmount = dewater_amount
561
-		//	dialysisPrescribe.TargetUltrafiltration = dewater_amount
562
-		//	dialysisPrescribe.Status = 1
563
-		//	updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
564
-		//	if updateErr != nil {
565
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
566
-		//	}
567
-		//}
557
+		if dialysisPrescribe != nil {
558
+			dialysisPrescribe.UpdatedTime = time.Now().Unix()
559
+			dialysisPrescribe.RecordDate = theAssessmentDateTime
560
+			dialysisPrescribe.DewaterAmount = dewater_amount
561
+			dialysisPrescribe.TargetUltrafiltration = dewater_amount
562
+			dialysisPrescribe.Status = 1
563
+			updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
564
+			if updateErr != nil {
565
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
566
+			}
567
+		}
568 568
 
569 569
 		theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
570 570
 		if getPEErr != nil {

File diff suppressed because it is too large
+ 2124 - 4439
controllers/mobile_api_controllers/dialysis_api_controller.go


+ 2 - 2
controllers/mobile_api_controllers/login_api_controller.go View File

@@ -33,8 +33,8 @@ func (this *LoginAPIController) LoginByPwd() {
33 33
 		return
34 34
 	}
35 35
 	ip := utils.GetIP(this.Ctx.Request)
36
-	ssoDomain := beego.AppConfig.String("sso_domain")
37
-	//ssoDomain := "http://localhost:8091"
36
+	//ssoDomain := beego.AppConfig.String("sso_domain")
37
+	ssoDomain := "http://localhost:8091"
38 38
 	api := ssoDomain + "/m/login/pwd"
39 39
 	values := make(url.Values)
40 40
 	values.Set("mobile", mobile)

+ 12 - 0
controllers/mobile_api_controllers/mobile_api_router_register.go View File

@@ -118,4 +118,16 @@ func MobileAPIControllersRegisterRouters() {
118 118
 
119 119
 	beego.Router("/m/api/doctoradvice/get", &DialysisAPIController{}, "Get:GetLastOrNextDoctorAdvice")
120 120
 
121
+	beego.Router("/m/api/dialysisbeforeprepare/create", &DialysisAPIController{}, "Post:CreateConsumables")
122
+	beego.Router("/m/api/dialysisbeforeprepare/edit", &DialysisAPIController{}, "Post:EditConsumables")
123
+
124
+	beego.Router("/m/api/stockout/create", &DialysisAPIController{}, "Post:CreateStockOutInfo")
125
+	//beego.Router("/m/api/stockout/edit", &DialysisAPIController{}, "Post:EditStockOutInfo")
126
+
127
+	beego.Router("/m/api/otherstockout/create", &DialysisAPIController{}, "Post:CreateOtherStockOutInfo")
128
+
129
+	beego.Router("/m/api/dialysisgoods/get", &DialysisAPIController{}, "Get:GetDialysisGoods")
130
+	beego.Router("/m/api/goodstatistics/get", &DialysisAPIController{}, "Get:GetDialysisGoodsStatistics")
131
+	beego.Router("/m/api/stockingood/get", &DialysisAPIController{}, "Get:GetStockInGoodInfo")
132
+
121 133
 }

+ 10 - 0
controllers/new_mobile_api_controllers/home_api_controller.go View File

@@ -17,11 +17,17 @@ import (
17 17
 	"time"
18 18
 )
19 19
 
20
+//func InitGoodTypesConfig(org *models.Org){
21
+//
22
+//
23
+//}
24
+
20 25
 type HomeController struct {
21 26
 	NewMobileBaseAPIAuthController
22 27
 }
23 28
 
24 29
 func (this *HomeController) GetHomeData() {
30
+
25 31
 	adminUserInfo := this.GetMobileAdminUserInfo()
26 32
 	if adminUserInfo.Org != nil && adminUserInfo.Org.Id != 0 {
27 33
 		//获取该管理员所有机构列表
@@ -73,6 +79,7 @@ func (this *HomeController) GetHomeData() {
73 79
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
74 80
 			return
75 81
 		}
82
+
76 83
 		cretor := adminUserInfo.AdminUser.Id
77 84
 		this.ServeSuccessJSON(map[string]interface{}{
78 85
 			"orgs":            orgs,
@@ -83,6 +90,7 @@ func (this *HomeController) GetHomeData() {
83 90
 			"cretor":          cretor,
84 91
 		})
85 92
 	} else {
93
+
86 94
 		apps, err := service.GetAllApp(0)
87 95
 		if err != nil {
88 96
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -404,6 +412,8 @@ func (this *HomeController) CreateOrg() {
404 412
 		InitEquitMentInformation(org)
405 413
 		//初始化显示配置和打印模版
406 414
 		InitShowConfig(org)
415
+		//初始化商品类型
416
+		InitGoodTypesConfig(org)
407 417
 
408 418
 		if len(orgs) == 0 {
409 419
 			ip := utils.GetIP(this.Ctx.Request)

+ 67 - 0
controllers/new_mobile_api_controllers/mobile_regist_controller.go View File

@@ -242,6 +242,9 @@ func (this *MobileRegistController) CreateOrg() {
242 242
 		//初始化显示配置和打印模版
243 243
 		InitShowConfig(org)
244 244
 
245
+		//初始化商品类型
246
+		InitGoodTypesConfig(org)
247
+
245 248
 		//创建完机构后进行登录验证操作
246 249
 		ip := utils.GetIP(this.Ctx.Request)
247 250
 		ssoDomain := beego.AppConfig.String("sso_domain")
@@ -1205,3 +1208,67 @@ func InitShowConfig(org *models.Org) {
1205 1208
 	}
1206 1209
 	service.CreateVMPrintTemplate(template)
1207 1210
 }
1211
+
1212
+type GoodTypesConfig struct {
1213
+	Types []*models.VMGoodsType "json:types"
1214
+}
1215
+
1216
+func LoadGoodTypeConfig(dataFile string) *GoodTypesConfig {
1217
+	var config GoodTypesConfig
1218
+	_, filename, _, _ := runtime.Caller(1)
1219
+	datapath := path.Join(path.Dir(filename), dataFile)
1220
+	config_file, err := os.Open(datapath)
1221
+	fmt.Println("1111111")
1222
+	fmt.Println(err)
1223
+	fmt.Println("2222222")
1224
+
1225
+	if err != nil {
1226
+		emit("Failed to open config file '%s': %s\n", datapath, err)
1227
+		return &config
1228
+	}
1229
+
1230
+	fi, _ := config_file.Stat()
1231
+
1232
+	buffer := make([]byte, fi.Size())
1233
+	_, err = config_file.Read(buffer)
1234
+
1235
+	buffer, err = StripComments(buffer) //去掉注释
1236
+	fmt.Println("333333")
1237
+	fmt.Println(err)
1238
+	fmt.Println("4444444")
1239
+	if err != nil {
1240
+		emit("Failed to strip comments from json: %s\n", err)
1241
+		return &config
1242
+	}
1243
+
1244
+	buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
1245
+	err = json.Unmarshal(buffer, &config)         //解析json格式数据
1246
+	fmt.Println("55555555")
1247
+	fmt.Println(err)
1248
+	fmt.Println("66666666")
1249
+	if err != nil {
1250
+		emit("Failed unmarshalling json: %s\n", err)
1251
+		return &config
1252
+	}
1253
+	return &config
1254
+}
1255
+
1256
+func InitGoodTypesConfig(org *models.Org) {
1257
+	good_types := LoadGoodTypeConfig("./good_types.json").Types
1258
+	fmt.Println(good_types)
1259
+	for _, item := range good_types {
1260
+		good_type := &models.GoodsType{
1261
+			TypeCode: item.TypeCode,
1262
+			TypeName: item.TypeName,
1263
+			Remark:   "",
1264
+			Number:   item.Number,
1265
+			Ctime:    time.Now().Unix(),
1266
+			Mtime:    time.Now().Unix(),
1267
+			OrgId:    org.Id,
1268
+			Status:   1,
1269
+			Type:     1,
1270
+		}
1271
+		service.AddSigleGoodType(good_type)
1272
+	}
1273
+
1274
+}

+ 85 - 0
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go View File

@@ -5,6 +5,7 @@ import (
5 5
 	"XT_New/enums"
6 6
 	"XT_New/service"
7 7
 	"fmt"
8
+	"time"
8 9
 )
9 10
 
10 11
 type StaffScheduleApiController struct {
@@ -235,3 +236,87 @@ func (this *StaffScheduleApiController) ChangeMobileOption() {
235 236
 		"chartworkdayminute": chartworkdayminute,
236 237
 	})
237 238
 }
239
+
240
+func (this *StaffScheduleApiController) GetAllZone() {
241
+
242
+	id := this.GetMobileAdminUserInfo().Org.Id
243
+	zone, err := service.GetAllMobileZone(id)
244
+	if err != nil {
245
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
246
+		return
247
+	}
248
+	this.ServeSuccessJSON(map[string]interface{}{
249
+		"zone": zone,
250
+	})
251
+}
252
+
253
+func (this *StaffScheduleApiController) GetPatientScheduleList() {
254
+	orgid := this.GetMobileAdminUserInfo().Org.Id
255
+	fmt.Println("orgid", orgid)
256
+	timeLayout := "2006-01-02"
257
+	loc, _ := time.LoadLocation("Local")
258
+	start_time := this.GetString("start_time")
259
+	var startTime int64
260
+	if len(start_time) > 0 {
261
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
262
+		if err != nil {
263
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
264
+			return
265
+		}
266
+		startTime = theTime.Unix()
267
+	}
268
+	fmt.Println("时间搓", startTime)
269
+	zoneid, _ := this.GetInt64("zoneid")
270
+	fmt.Println(zoneid)
271
+	classtype, _ := this.GetInt64("classtype")
272
+	fmt.Println("classtype", classtype)
273
+
274
+	//获取当天排班的病人情况
275
+	schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
276
+
277
+	if err != nil {
278
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
279
+		return
280
+	}
281
+	this.ServeSuccessJSON(map[string]interface{}{
282
+		"schedule": schedule,
283
+	})
284
+}
285
+
286
+func (this *StaffScheduleApiController) DeleteSchedule() {
287
+	id, _ := this.GetInt64("id")
288
+	fmt.Println("id", id)
289
+	err := service.DeleteSchedule(id)
290
+	fmt.Println(err)
291
+	returnData := make(map[string]interface{}, 0)
292
+	returnData["msg"] = "ok"
293
+	this.ServeSuccessJSON(returnData)
294
+	return
295
+}
296
+
297
+func (this *StaffScheduleApiController) SearchPatient() {
298
+	timeLayout := "2006-01-02"
299
+	loc, _ := time.LoadLocation("Local")
300
+	keyword := this.GetString("keyword")
301
+	fmt.Println(keyword)
302
+	orgId := this.GetMobileAdminUserInfo().Org.Id
303
+	start_time := this.GetString("start_time")
304
+	var startTime int64
305
+	if len(start_time) > 0 {
306
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
307
+		if err != nil {
308
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
309
+			return
310
+		}
311
+		startTime = theTime.Unix()
312
+	}
313
+	schedule, err := service.GetSearchPatient(keyword, orgId, startTime)
314
+
315
+	if err != nil {
316
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
317
+		return
318
+	}
319
+	this.ServeSuccessJSON(map[string]interface{}{
320
+		"schedule": schedule,
321
+	})
322
+}

+ 4 - 0
controllers/new_mobile_api_controllers/staff_schedule_api_router.go View File

@@ -15,4 +15,8 @@ func StaffScheduleApiControllersRegisterRouters() {
15 15
 	beego.Router("/m/api/getmobilechartlist", &StaffScheduleApiController{}, "Get:GetMobileChartList")
16 16
 	beego.Router("/m/api/tosearchmobiletotal", &StaffScheduleApiController{}, "Get:ToSearchMobileTotal")
17 17
 	beego.Router("/m/api/changemobileoption", &StaffScheduleApiController{}, "Get:ChangeMobileOption")
18
+	beego.Router("/m/api/getallzone", &StaffScheduleApiController{}, "Get:GetAllZone")
19
+	beego.Router("/m/api/getpatientschedulelist", &StaffScheduleApiController{}, "Get:GetPatientScheduleList")
20
+	beego.Router("/m/api/deleteSchedule", &StaffScheduleApiController{}, "Get:DeleteSchedule")
21
+	beego.Router("/m/api/ssearchpatient", &StaffScheduleApiController{}, "Get:SearchPatient")
18 22
 }

+ 250 - 1
controllers/public_api_controller.go View File

@@ -24,8 +24,8 @@ func PublicApiRegistRouters() {
24 24
 	beego.Router("/api/public/servertime", &PublicApiController{}, "Get:GetServerTime")
25 25
 	beego.Router("/api/app/release", &PublicApiController{}, "Get:AppRelease")
26 26
 	beego.Router("/api/get", &PublicApiController{}, "Get:GetJson")
27
-
28 27
 	beego.Router("/api/public/handledata", &PublicApiController{}, "get:HandleData")
28
+	beego.Router("/api/public/handlestockdata", &PublicApiController{}, "get:HandleStockData")
29 29
 
30 30
 }
31 31
 
@@ -654,3 +654,252 @@ func LoadRoleConfig(dataFile string) *RoleConfig {
654 654
 	}
655 655
 	return &config
656 656
 }
657
+
658
+type GoodTypesConfig struct {
659
+	GoodTypes []*models.VMGoodsType "json:list"
660
+}
661
+
662
+func LoadGoodTypeConfig(dataFile string) *GoodTypesConfig {
663
+	var config GoodTypesConfig
664
+	_, filename, _, _ := runtime.Caller(1)
665
+	datapath := path.Join(path.Dir(filename), dataFile)
666
+	config_file, err := os.Open(datapath)
667
+	if err != nil {
668
+		emit("Failed to open config file '%s': %s\n", datapath, err)
669
+		return &config
670
+	}
671
+
672
+	fi, _ := config_file.Stat()
673
+
674
+	buffer := make([]byte, fi.Size())
675
+	_, err = config_file.Read(buffer)
676
+
677
+	buffer, err = StripComments(buffer) //去掉注释
678
+	if err != nil {
679
+		emit("Failed to strip comments from json: %s\n", err)
680
+		return &config
681
+	}
682
+
683
+	buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
684
+	err = json.Unmarshal(buffer, &config)         //解析json格式数据
685
+	if err != nil {
686
+		emit("Failed unmarshalling json: %s\n", err)
687
+		return &config
688
+	}
689
+	return &config
690
+}
691
+
692
+func (c *PublicApiController) HandleStockData() {
693
+	org, _ := service.FindAllOrgByImportType()
694
+	for _, item := range org {
695
+		goodTypes := &models.GoodsType{
696
+			TypeCode: "14000000",
697
+			TypeName: "穿刺针",
698
+			Remark:   "",
699
+			Ctime:    time.Now().Unix(),
700
+			Mtime:    time.Now().Unix(),
701
+			Creater:  0,
702
+			Modifier: 0,
703
+			OrgId:    item.Id,
704
+			Status:   1,
705
+			Type:     1,
706
+			Number:   1,
707
+		}
708
+
709
+		service.AddSigleGoodType(goodTypes)
710
+
711
+		goodTypes1 := &models.GoodsType{
712
+			TypeCode: "14000001",
713
+			TypeName: "透析器",
714
+			Remark:   "",
715
+			Ctime:    time.Now().Unix(),
716
+			Mtime:    time.Now().Unix(),
717
+			Creater:  0,
718
+			Modifier: 0,
719
+			OrgId:    item.Id,
720
+			Status:   1,
721
+			Type:     1,
722
+			Number:   2,
723
+		}
724
+
725
+		service.AddSigleGoodType(goodTypes1)
726
+
727
+		goodTypes2 := &models.GoodsType{
728
+			TypeCode: "14000002",
729
+			TypeName: "灌流器",
730
+			Remark:   "",
731
+			Ctime:    time.Now().Unix(),
732
+			Mtime:    time.Now().Unix(),
733
+			Creater:  0,
734
+			Modifier: 0,
735
+			OrgId:    item.Id,
736
+			Status:   1,
737
+			Type:     1,
738
+			Number:   3,
739
+		}
740
+
741
+		service.AddSigleGoodType(goodTypes2)
742
+
743
+		goodTypes3 := &models.GoodsType{
744
+			TypeCode: "14000003",
745
+			TypeName: "血路管",
746
+			Remark:   "",
747
+			Ctime:    time.Now().Unix(),
748
+			Mtime:    time.Now().Unix(),
749
+			Creater:  0,
750
+			Modifier: 0,
751
+			OrgId:    item.Id,
752
+			Status:   1,
753
+			Type:     1,
754
+			Number:   4,
755
+		}
756
+
757
+		service.AddSigleGoodType(goodTypes3)
758
+
759
+		goodTypes4 := &models.GoodsType{
760
+			TypeCode: "14000004",
761
+			TypeName: "血滤补液管",
762
+			Remark:   "",
763
+			Ctime:    time.Now().Unix(),
764
+			Mtime:    time.Now().Unix(),
765
+			Creater:  0,
766
+			Modifier: 0,
767
+			OrgId:    item.Id,
768
+			Status:   1,
769
+			Type:     1,
770
+			Number:   5,
771
+		}
772
+
773
+		service.AddSigleGoodType(goodTypes4)
774
+
775
+		goodTypes5 := &models.GoodsType{
776
+			TypeCode: "14000005",
777
+			TypeName: "注射器",
778
+			Remark:   "",
779
+			Ctime:    time.Now().Unix(),
780
+			Mtime:    time.Now().Unix(),
781
+			Creater:  0,
782
+			Modifier: 0,
783
+			OrgId:    item.Id,
784
+			Status:   1,
785
+			Type:     1,
786
+			Number:   6,
787
+		}
788
+
789
+		service.AddSigleGoodType(goodTypes5)
790
+
791
+		goodTypes6 := &models.GoodsType{
792
+			TypeCode: "14000006",
793
+			TypeName: "护理包(内瘘穿刺包)",
794
+			Remark:   "",
795
+			Ctime:    time.Now().Unix(),
796
+			Mtime:    time.Now().Unix(),
797
+			Creater:  0,
798
+			Modifier: 0,
799
+			OrgId:    item.Id,
800
+			Status:   1,
801
+			Type:     1,
802
+			Number:   7,
803
+		}
804
+
805
+		service.AddSigleGoodType(goodTypes6)
806
+
807
+		goodTypes7 := &models.GoodsType{
808
+			TypeCode: "14000007",
809
+			TypeName: "细菌过滤器",
810
+			Remark:   "",
811
+			Ctime:    time.Now().Unix(),
812
+			Mtime:    time.Now().Unix(),
813
+			Creater:  0,
814
+			Modifier: 0,
815
+			OrgId:    item.Id,
816
+			Status:   1,
817
+			Type:     1,
818
+			Number:   8,
819
+		}
820
+
821
+		service.AddSigleGoodType(goodTypes7)
822
+
823
+		goodTypes8 := &models.GoodsType{
824
+			TypeCode: "14000008",
825
+			TypeName: "血液透析干粉",
826
+			Remark:   "",
827
+			Ctime:    time.Now().Unix(),
828
+			Mtime:    time.Now().Unix(),
829
+			Creater:  0,
830
+			Modifier: 0,
831
+			OrgId:    item.Id,
832
+			Status:   1,
833
+			Type:     1,
834
+			Number:   9,
835
+		}
836
+
837
+		service.AddSigleGoodType(goodTypes8)
838
+
839
+		goodTypes9 := &models.GoodsType{
840
+			TypeCode: "14000009",
841
+			TypeName: "A液",
842
+			Remark:   "",
843
+			Ctime:    time.Now().Unix(),
844
+			Mtime:    time.Now().Unix(),
845
+			Creater:  0,
846
+			Modifier: 0,
847
+			OrgId:    item.Id,
848
+			Status:   1,
849
+			Type:     1,
850
+			Number:   10,
851
+		}
852
+
853
+		service.AddSigleGoodType(goodTypes9)
854
+
855
+		goodTypes10 := &models.GoodsType{
856
+			TypeCode: "14000010",
857
+			TypeName: "B液",
858
+			Remark:   "",
859
+			Ctime:    time.Now().Unix(),
860
+			Mtime:    time.Now().Unix(),
861
+			Creater:  0,
862
+			Modifier: 0,
863
+			OrgId:    item.Id,
864
+			Status:   1,
865
+			Type:     1,
866
+			Number:   11,
867
+		}
868
+
869
+		service.AddSigleGoodType(goodTypes10)
870
+
871
+		goodTypes11 := &models.GoodsType{
872
+			TypeCode: "14000011",
873
+			TypeName: "导管包",
874
+			Remark:   "",
875
+			Ctime:    time.Now().Unix(),
876
+			Mtime:    time.Now().Unix(),
877
+			Creater:  0,
878
+			Modifier: 0,
879
+			OrgId:    item.Id,
880
+			Status:   1,
881
+			Type:     1,
882
+			Number:   12,
883
+		}
884
+
885
+		service.AddSigleGoodType(goodTypes11)
886
+
887
+		goodTypes12 := &models.GoodsType{
888
+			TypeCode: "14000012",
889
+			TypeName: "血液透析导管",
890
+			Remark:   "",
891
+			Ctime:    time.Now().Unix(),
892
+			Mtime:    time.Now().Unix(),
893
+			Creater:  0,
894
+			Modifier: 0,
895
+			OrgId:    item.Id,
896
+			Status:   1,
897
+			Type:     1,
898
+			Number:   13,
899
+		}
900
+
901
+		service.AddSigleGoodType(goodTypes12)
902
+
903
+	}
904
+
905
+}

+ 7 - 0
controllers/stock_good_api_controller.go View File

@@ -279,10 +279,17 @@ func (c *StockGoodApiController) DeleteGoodInfo() {
279 279
 	adminUserInfo := c.GetAdminUserInfo()
280 280
 
281 281
 	total, _ := service.FindWarehouseInfoTotalByGoodId(id)
282
+	total2, _ := service.FindWarehouseOutInfoTotalByGoodId(id)
283
+
282 284
 	if total > 0 {
283 285
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
284 286
 		return
285 287
 	}
288
+	if total2 > 0 {
289
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteGoodInfoFail)
290
+		return
291
+	}
292
+
286 293
 	err := service.DeleteGoodInfoById(id, adminUserInfo.AdminUser.Id)
287 294
 	if err == nil {
288 295
 		c.ServeSuccessJSON(map[string]interface{}{

+ 14 - 14
controllers/stock_in_api_controller.go View File

@@ -1339,20 +1339,6 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1339 1339
 				}
1340 1340
 				id := int64(items["id"].(float64))
1341 1341
 
1342
-				if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
1343
-					utils.ErrorLog("is_sys")
1344
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1345
-					return
1346
-				}
1347
-				is_sys := int64(items["is_sys"].(float64))
1348
-
1349
-				if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
1350
-					utils.ErrorLog("sys_record_time")
1351
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1352
-					return
1353
-				}
1354
-				sys_record_time := int64(items["sys_record_time"].(float64))
1355
-
1356 1342
 				if id == 0 {
1357 1343
 					warehouseOutInfo := &models.WarehouseOutInfo{
1358 1344
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1375,6 +1361,20 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1375 1361
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1376 1362
 
1377 1363
 				} else {
1364
+					if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
1365
+						utils.ErrorLog("is_sys")
1366
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1367
+						return
1368
+					}
1369
+					is_sys := int64(items["is_sys"].(float64))
1370
+
1371
+					if items["sys_record_time"] == nil || reflect.TypeOf(items["sys_record_time"]).String() != "float64" {
1372
+						utils.ErrorLog("sys_record_time")
1373
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1374
+						return
1375
+					}
1376
+					sys_record_time := int64(items["sys_record_time"].(float64))
1377
+
1378 1378
 					warehouseOutInfo := &models.WarehouseOutInfo{
1379 1379
 						ID: id,
1380 1380
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,

+ 4 - 1
enums/error_code.go View File

@@ -202,6 +202,8 @@ const ( // ErrorCode
202 202
 	ErrorCodeOrgNoPatient = 20051
203 203
 
204 204
 	ErrorCodeDoctorAdviceEmpty = 20052
205
+
206
+	ErrorCodeOpenStocktWrong = 20053
205 207
 )
206 208
 
207 209
 var ErrCodeMsgs = map[int]string{
@@ -346,7 +348,7 @@ var ErrCodeMsgs = map[int]string{
346 348
 
347 349
 	ErrorCodeCancelStockFail:    "出库退库失败",
348 350
 	ErrorCodeDeleteGoodTypeFail: "该类型存在商品信息,无法删除",
349
-	ErrorCodeDeleteGoodInfoFail: "该商品已经入库无法删除",
351
+	ErrorCodeDeleteGoodInfoFail: "该商品已经入库或者出库无法删除",
350 352
 
351 353
 	ErrorCodeDeleteFail: "删除失败",
352 354
 
@@ -401,6 +403,7 @@ var ErrCodeMsgs = map[int]string{
401 403
 	ErrorCodeOrgNoPatient: "暂无病人",
402 404
 
403 405
 	ErrorCodeDoctorAdviceEmpty: "没有更多了",
406
+	ErrorCodeOpenStocktWrong:   "未开启自动扣减功能,无法出库",
404 407
 }
405 408
 
406 409
 type SGJError struct {

+ 19 - 0
models/dialysis.go View File

@@ -905,3 +905,22 @@ type UserAdminRoles struct {
905 905
 	Url           string `gorm:"column:url" json:"url" form:"url"`
906 906
 	Hash          string `gorm:"column:hash" json:"hash" form:"hash"`
907 907
 }
908
+
909
+type DialysisBeforePrepare struct {
910
+	ID         int64 `gorm:"column:id" json:"id" form:"id"`
911
+	UserOrgId  int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
912
+	PatientId  int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
913
+	RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
914
+	GoodId     int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
915
+	GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
916
+	Count      int64 `gorm:"column:count" json:"count" form:"count"`
917
+	Ctime      int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
918
+	Mtime      int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
919
+	Creater    int64 `gorm:"column:creater" json:"creater" form:"creater"`
920
+	Modifier   int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
921
+	Status     int64 `gorm:"column:status" json:"status" form:"status"`
922
+}
923
+
924
+func (DialysisBeforePrepare) TableName() string {
925
+	return "dialysis_before_prepare"
926
+}

+ 1 - 0
models/good_models.go View File

@@ -12,6 +12,7 @@ type GoodsType struct {
12 12
 	OrgId    int64  `gorm:"column:org_id" json:"org_id"`
13 13
 	Status   int64  `gorm:"column:status" json:"status"`
14 14
 	Type     int64  `gorm:"column:type" json:"type"`
15
+	Number   int64  `gorm:"column:number" json:"number"`
15 16
 }
16 17
 
17 18
 func (GoodsType) TableName() string {

+ 1 - 0
models/stock_models.go View File

@@ -296,6 +296,7 @@ type AutomaticReduceDetail struct {
296 296
 	GoodInfo                GoodInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
297 297
 	GoodsType               GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
298 298
 	Patients                Patients  `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
299
+	Count                   int64     `gorm:"column:count" json:"count"`
299 300
 }
300 301
 
301 302
 func (AutomaticReduceDetail) TableName() string {

+ 19 - 0
models/vm_models.go View File

@@ -334,3 +334,22 @@ type VMGobalTemplate struct {
334 334
 func (VMGobalTemplate) TableName() string {
335 335
 	return "xt_gobal_template"
336 336
 }
337
+
338
+type VMGoodsType struct {
339
+	ID       int64  `gorm:"column:id" json:"id"`
340
+	TypeCode string `gorm:"column:type_code" json:"type_code"`
341
+	TypeName string `gorm:"column:type_name" json:"type_name"`
342
+	Remark   string `gorm:"column:remark" json:"remark"`
343
+	Ctime    int64  `gorm:"column:ctime" json:"ctime"`
344
+	Mtime    int64  `gorm:"column:mtime" json:"mtime"`
345
+	Creater  int64  `gorm:"column:creater" json:"creater"`
346
+	Modifier int64  `gorm:"column:modifier" json:"modifier"`
347
+	OrgId    int64  `gorm:"column:org_id" json:"org_id"`
348
+	Status   int64  `gorm:"column:status" json:"status"`
349
+	Type     int64  `gorm:"column:type" json:"type"`
350
+	Number   int64  `gorm:"column:number" json:"number"`
351
+}
352
+
353
+func (VMGoodsType) TableName() string {
354
+	return "xt_goods_type"
355
+}

+ 5 - 0
service/app_version.go View File

@@ -224,3 +224,8 @@ func HandleData() {
224 224
 	}
225 225
 
226 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
+}

+ 58 - 1
service/dialysis_service.go View File

@@ -3,6 +3,7 @@ package service
3 3
 import (
4 4
 	"XT_New/models"
5 5
 	"fmt"
6
+	"strings"
6 7
 	"time"
7 8
 
8 9
 	"github.com/jinzhu/gorm"
@@ -1011,7 +1012,7 @@ func GetLastLongAdviceByGroupNoThree(orgId int64, patient_id int64) (advice []*m
1011 1012
 }
1012 1013
 
1013 1014
 func FindAllDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, temp_id string) (advice []*models.DoctorAdvice, err error) {
1014
-	err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 2   AND frequency_type = 2 AND advice_date > ? AND advice_date <= ? AND template_id = ?  ", orgId, patient_id, end, now, temp_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
1015
+	err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 2   AND advice_date > ? AND advice_date <= ? AND template_id = ?  ", orgId, patient_id, end, now, temp_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
1015 1016
 	return
1016 1017
 }
1017 1018
 
@@ -1024,3 +1025,59 @@ func UpdateAssessmentAfterDate(patient_id int64, org_id int64, date int64, actua
1024 1025
 	err = writeDb.Model(&models.AssessmentAfterDislysis{}).Where("status =1 AND user_org_id = ? AND patient_id = ? AND assessment_date = ?", org_id, patient_id, date).Updates(map[string]interface{}{"actual_treatment_hour": actual_treatment_hour, "actual_treatment_minute": actual_treatment_minute}).Error
1025 1026
 	return
1026 1027
 }
1028
+
1029
+func CreateDialysisBeforePrepare(beforePrepares []*models.DialysisBeforePrepare) (err error) {
1030
+	if len(beforePrepares) > 0 {
1031
+		utx := writeDb.Begin()
1032
+		if len(beforePrepares) > 0 {
1033
+			thisSQL := "INSERT INTO dialysis_before_prepare (user_org_id, patient_id, record_date, good_id, good_type_id,count,ctime,mtime,creater,modifier,status) VALUES "
1034
+			insertParams := make([]string, 0)
1035
+			insertData := make([]interface{}, 0)
1036
+			for _, prepare := range beforePrepares {
1037
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?)")
1038
+				insertData = append(insertData, prepare.UserOrgId)
1039
+				insertData = append(insertData, prepare.PatientId)
1040
+				insertData = append(insertData, prepare.RecordDate)
1041
+				insertData = append(insertData, prepare.GoodId)
1042
+				insertData = append(insertData, prepare.GoodTypeId)
1043
+				insertData = append(insertData, prepare.Count)
1044
+				insertData = append(insertData, prepare.Ctime)
1045
+				insertData = append(insertData, prepare.Mtime)
1046
+				insertData = append(insertData, prepare.Creater)
1047
+				insertData = append(insertData, prepare.Modifier)
1048
+				insertData = append(insertData, 1)
1049
+
1050
+			}
1051
+			thisSQL += strings.Join(insertParams, ", ")
1052
+			err = utx.Exec(thisSQL, insertData...).Error
1053
+			if err != nil {
1054
+				utx.Rollback()
1055
+				return
1056
+			}
1057
+		}
1058
+		utx.Commit()
1059
+	}
1060
+	return
1061
+
1062
+}
1063
+
1064
+func UpdateDialysisBeforePrepare(info *models.DialysisBeforePrepare) (err error) {
1065
+	err = writeDb.Save(&info).Error
1066
+	return err
1067
+}
1068
+
1069
+func UpdateOrderCountSub(good_type_id int64, good_id int64, number string, org_id int64, count int64) {
1070
+	writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).UpdateColumn("count", gorm.Expr("count - ?", count))
1071
+
1072
+}
1073
+
1074
+func UpdateOrderCountAdd(good_type_id int64, good_id int64, number string, org_id int64, count int64) {
1075
+	writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).UpdateColumn("count", gorm.Expr("count + ?", count))
1076
+
1077
+}
1078
+
1079
+func UpdateUserInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.WarehouseOutInfo) {
1080
+	writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"count": count})
1081
+	//writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber).UpdateColumn("count", count)
1082
+
1083
+}

+ 42 - 2
service/doctor_schedule_service.go View File

@@ -139,7 +139,7 @@ func GetStaffScheduleList(orgid int64, startime int64, endtime int64) (schedule
139 139
 	if orgid > 0 {
140 140
 		db = db.Where("x.user_org_id = ?", orgid)
141 141
 	}
142
-	err = db.Group("x.id").Select("x.id,x.doctor_id,x.doctor_type,x.schedule_type,x.schedule_week,x.user_org_id,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.admin_user_id,r.user_type,s.class_attributes,r.sort,r.is_sort,s.work_time,s.minute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1", orgid, orgid).Scan(&schedule).Error
142
+	err = db.Group("x.id").Select("x.id,x.doctor_id,x.doctor_type,x.schedule_type,x.schedule_week,x.user_org_id,x.start_time,x.end_time,x.schedule_date,r.user_name,s.class_name,r.admin_user_id,r.user_type,s.class_attributes,r.sort,r.is_sort,s.work_time,s.minute").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Where("r.org_id = ? and r.status = 1 and s.user_org_id = ? and s.status = 1 and r.is_sort = 1", orgid, orgid).Scan(&schedule).Error
143 143
 	return schedule, err
144 144
 }
145 145
 
@@ -198,7 +198,7 @@ func ToSearchSeacheduleList(keywords string, startime int64, endtime int64, orgi
198 198
 	//if(doctorid >0){
199 199
 	//  db = db.Where("x.doctor_id = ?", doctorid)
200 200
 	//}
201
-	err = db.Group("x.id").Select("x.id,x.doctor_id,x.doctor_type,x.schedule_type,x.schedule_week,x.user_org_id,x.start_time,x.schedule_date,x.end_time,r.user_type,r.user_name,s.class_name,r.admin_user_id,s.class_attributes,r.sort,r.is_sort").Joins("left join sgj_users.sgj_user_admin_role AS r ON r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type and s.user_org_id = ?", orgid).Where("r.org_id = ? and r.status = 1  and r.user_name like ?", orgid, likeKey).Scan(&schedule).Error
201
+	err = db.Group("x.id").Select("x.id,x.doctor_id,x.doctor_type,x.schedule_type,x.schedule_week,x.user_org_id,x.start_time,x.schedule_date,x.end_time,r.user_type,r.user_name,s.class_name,r.admin_user_id,s.class_attributes,r.sort,r.is_sort").Joins("left join sgj_users.sgj_user_admin_role AS r ON r.admin_user_id = x.doctor_id").Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type and s.user_org_id = ?", orgid).Where("r.org_id = ? and r.status = 1 and r.is_sort = 1  and r.user_name like ?", orgid, likeKey).Scan(&schedule).Error
202 202
 	return schedule, err
203 203
 }
204 204
 
@@ -575,3 +575,43 @@ func GetMySchedule(startime int64, endtime int64, orgid int64, creator int64) (s
575 575
 	err = db.Group("x.id").Select("x.doctor_id,x.schedule_week,s.class_name").Where("x.start_time >=? and x.end_time<=? and x.user_org_id = ? and x.doctor_id = ?", startime, endtime, orgid, creator).Joins("left join xt_doctor_schedules as s on s.id = x.schedule_type").Scan(&schedule).Error
576 576
 	return schedule, err
577 577
 }
578
+
579
+func GetAllMobileZone(orgid int64) (zone []*models.DeviceZone, err error) {
580
+
581
+	err = XTReadDB().Model(&zone).Where("org_id = ? and status = 1", orgid).Find(&zone).Error
582
+	return zone, err
583
+}
584
+
585
+func GetPatientSchedule(startime int64, zoneid int64, classtype int64, orgid int64) (schedule []*models.Schedule, err error) {
586
+
587
+	db := XTReadDB().Table("xt_schedule as s")
588
+	if zoneid > 0 {
589
+		db = db.Where("s.partition_id = ?", zoneid)
590
+	}
591
+	if classtype > 0 {
592
+		db = db.Where("s.schedule_type = ?", classtype)
593
+	}
594
+	err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", "status= 1").
595
+		Preload("DialysisOrder", "status =1").Joins("JOIN xt_patients as p ON p.id = s.patient_id").Where("s.user_org_id = ? and s.schedule_date = ? and s.status =1", orgid, startime).
596
+		Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id,p.name as patient").Find(&schedule).Error
597
+	return schedule, err
598
+}
599
+
600
+func DeleteSchedule(id int64) error {
601
+
602
+	schedule := models.XtSchedule{}
603
+
604
+	err := XTWriteDB().Model(&schedule).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
605
+	return err
606
+}
607
+
608
+func GetSearchPatient(keywords string, orgid int64, startime int64) (schedule []*models.Schedule, err error) {
609
+
610
+	likeKey := "%" + keywords + "%"
611
+	db := XTReadDB().Table("xt_schedule as s")
612
+	err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", "status= 1").
613
+		Preload("DialysisOrder", "status =1").
614
+		Joins("JOIN xt_patients as p ON p.id = s.patient_id And(p.name LIKE ? OR p.dialysis_no LIKE ?)", likeKey, likeKey).Where("s.user_org_id = ? and s.schedule_date = ? and s.status =1", orgid, startime).
615
+		Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id,p.name as patient").Find(&schedule).Error
616
+	return schedule, err
617
+}

+ 244 - 0
service/mobile_dialysis_service.go View File

@@ -1299,3 +1299,247 @@ func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64,
1299 1299
 	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule AS x ON x.patient_id = o.patient_id   where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1 and o.patient_id = ?", startime, endtime, orgid, patientid).Scan(&order).Group("o.patient_id").Error
1300 1300
 	return order, err
1301 1301
 }
1302
+
1303
+func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
1304
+	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 	AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
1305
+	return
1306
+}
1307
+
1308
+//func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
1309
+//	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patient_id,recordDate).Find(&consumables).Error
1310
+//	return
1311
+//}
1312
+//
1313
+
1314
+func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
1315
+	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date < ?", patientID, orgID, maxDate).Order("record_date desc").Find(&prepare).Error
1316
+
1317
+	return
1318
+}
1319
+
1320
+type GoodsType struct {
1321
+	ID       int64  `gorm:"column:id" json:"id"`
1322
+	TypeName string `gorm:"column:type_name" json:"type_name"`
1323
+	Remark   string `gorm:"column:remark" json:"remark"`
1324
+	OrgId    int64  `gorm:"column:org_id" json:"org_id"`
1325
+	Status   int64  `gorm:"column:status" json:"status"`
1326
+	Type     int64  `gorm:"column:type" json:"type"`
1327
+}
1328
+
1329
+func (GoodsType) TableName() string {
1330
+	return "xt_goods_type"
1331
+}
1332
+
1333
+type VMGoodInfo struct {
1334
+	ID                int64  `gorm:"column:id" json:"id"`
1335
+	SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
1336
+	GoodTypeId        int64  `gorm:"column:good_type_id" json:"good_type_id"`
1337
+	OrgId             int64  `gorm:"column:org_id" json:"org_id"`
1338
+}
1339
+
1340
+func (VMGoodInfo) TableName() string {
1341
+	return "xt_good_information"
1342
+}
1343
+
1344
+type AutomaticReduceDetail struct {
1345
+	ID         int64      `gorm:"column:id" json:"id"`
1346
+	PatientId  int64      `gorm:"column:patient_id" json:"patient_id"`
1347
+	Status     int64      `gorm:"column:status" json:"status"`
1348
+	RecordTime int64      `gorm:"column:record_time" json:"record_time"`
1349
+	OrgId      int64      `gorm:"column:org_id" json:"org_id"`
1350
+	GoodId     int64      `gorm:"column:good_id" json:"good_id"`
1351
+	GoodTypeId int64      `gorm:"column:good_type_id" json:"good_type_id"`
1352
+	VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
1353
+	GoodsType  GoodsType  `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
1354
+	Count      int64      `gorm:"column:count" json:"count"`
1355
+}
1356
+
1357
+func (AutomaticReduceDetail) TableName() string {
1358
+	return "xt_automatic_reduce_detail"
1359
+}
1360
+
1361
+type DialysisBeforePrepare struct {
1362
+	ID         int64      `gorm:"column:id" json:"id" form:"id"`
1363
+	UserOrgId  int64      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1364
+	PatientId  int64      `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1365
+	RecordDate int64      `gorm:"column:record_date" json:"record_date" form:"record_date"`
1366
+	GoodId     int64      `gorm:"column:good_id" json:"good_id" form:"good_id"`
1367
+	GoodTypeId int64      `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
1368
+	Count      int64      `gorm:"column:count" json:"count" form:"count"`
1369
+	Ctime      int64      `gorm:"column:ctime" json:"ctime" form:"ctime"`
1370
+	Mtime      int64      `gorm:"column:mtime" json:"mtime" form:"mtime"`
1371
+	Creater    int64      `gorm:"column:creater" json:"creater" form:"creater"`
1372
+	Modifier   int64      `gorm:"column:modifier" json:"modifier" form:"modifier"`
1373
+	VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
1374
+	GoodsType  GoodsType  `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
1375
+}
1376
+
1377
+func (DialysisBeforePrepare) TableName() string {
1378
+	return "dialysis_before_prepare"
1379
+}
1380
+
1381
+type MDialysisGoodsVM struct {
1382
+	ID           int64 `gorm:"column:id" json:"id"`
1383
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id"`
1384
+	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id"`
1385
+	BedId        int64 `gorm:"column:bed_id" json:"bed_id"`
1386
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id"`
1387
+	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
1388
+	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
1389
+	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
1390
+	ModeId       int64 `gorm:"column:mode_id" json:"mode_id"`
1391
+	Status       int64 `gorm:"column:status" json:"status"`
1392
+
1393
+	DeviceNumber              *MDeviceNumberVM         `gorm:"ForeignKey:BedId" json:"device_number"`
1394
+	SchedualPatient           *MSchedualPatientVMList  `gorm:"ForeignKey:PatientId" json:"patient"`
1395
+	AutomaticReduceDetail     []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordTime" json:"good_user"`
1396
+	LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
1397
+	DialysisBeforePrepare     []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
1398
+	LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
1399
+}
1400
+
1401
+func (MDialysisGoodsVM) TableName() string {
1402
+	return "xt_schedule"
1403
+}
1404
+
1405
+type VMWarehouseOutInfo struct {
1406
+	ID                      int64      `gorm:"column:id" json:"id"`
1407
+	WarehouseOutId          int64      `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
1408
+	GoodId                  int64      `gorm:"column:good_id" json:"good_id"`
1409
+	GoodTypeId              int64      `gorm:"column:good_type_id" json:"good_type_id"`
1410
+	Count                   int64      `gorm:"column:count" json:"count"`
1411
+	Price                   float64    `gorm:"column:price" json:"price"`
1412
+	TotalPrice              float64    `gorm:"column:total_price" json:"total_price"`
1413
+	Status                  int64      `gorm:"column:status" json:"status"`
1414
+	OrgId                   int64      `gorm:"column:org_id" json:"org_id"`
1415
+	WarehouseOutOrderNumber string     `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
1416
+	GoodInfo                VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
1417
+	GoodsType               GoodsType  `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
1418
+	IsSys                   int64      `gorm:"column:is_sys" json:"is_sys"`
1419
+	SysRecordTime           int64      `gorm:"column:sys_record_time" json:"sys_record_time"`
1420
+	Mtime                   int64      `gorm:"column:mtime" json:"mtime"`
1421
+	Ctime                   int64      `gorm:"column:ctime" json:"ctime"`
1422
+}
1423
+
1424
+func (VMWarehouseOutInfo) TableName() string {
1425
+	return "xt_warehouse_out_info"
1426
+}
1427
+
1428
+type DialysisGoodsDate struct {
1429
+	RecordDate int64
1430
+}
1431
+
1432
+type DialysisGoodsDetailDate struct {
1433
+	RecordTime int64
1434
+}
1435
+
1436
+func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string) ([]*MDialysisGoodsVM, error, int64) {
1437
+	var vms []*MDialysisGoodsVM
1438
+	var total int64
1439
+
1440
+	db := readDb.
1441
+		Table("xt_schedule as sch").
1442
+		Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
1443
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1444
+		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1445
+		Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
1446
+			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ?  AND count > 0 ", orgID, scheduleDate)
1447
+		}).
1448
+		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
1449
+			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND record_time = ? AND count > 0 ", orgID, scheduleDate)
1450
+		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
1451
+	if scheduleDate != 0 {
1452
+		db = db.Where("schedule_date = ?", scheduleDate)
1453
+	}
1454
+	if schedule_type != 0 {
1455
+		db = db.Where("schedule_type = ?", schedule_type)
1456
+	}
1457
+	if partition_id != 0 {
1458
+		db = db.Where("partition_id = ?", partition_id)
1459
+	}
1460
+	if patient_id != 0 {
1461
+		db = db.Where("patient_id = ?", patient_id)
1462
+	}
1463
+	//db = db.Count(&total)
1464
+	//offset := (page - 1) * limit
1465
+	//
1466
+	//db = db.Offset(offset).Limit(limit)
1467
+	err := db.Find(&vms).Error
1468
+
1469
+	return vms, err, total
1470
+}
1471
+
1472
+func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
1473
+	var Id []*DialysisGoodsDetailDate
1474
+	err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
1475
+	if len(Id) > 0 {
1476
+		err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Find(&goodUser).Error
1477
+	}
1478
+	return
1479
+}
1480
+
1481
+func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
1482
+	var Id []*DialysisGoodsDate
1483
+	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
1484
+	if len(Id) > 0 {
1485
+		err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
1486
+	}
1487
+	return
1488
+}
1489
+
1490
+func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
1491
+	db := readDb.Model(&models.StockInfo{})
1492
+	db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
1493
+	db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgID).Group("xt_good_information.id")
1494
+	db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
1495
+		return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1", orgID).Joins("JOIN xt_warehouse_out ON xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.status = 1 AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.org_id = ? ", start_time, end_time, orgID)
1496
+	})
1497
+	db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
1498
+	err = db.Order("ctime desc").Find(&list).Error
1499
+	return
1500
+}
1501
+
1502
+func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string) ([]*MDialysisGoodsVM, error, int64) {
1503
+	var vms []*MDialysisGoodsVM
1504
+	var total int64
1505
+
1506
+	db := readDb.
1507
+		Model(&models.Schedule{}).
1508
+		Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
1509
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1510
+		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1511
+		Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
1512
+			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?   ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
1513
+		}).
1514
+		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
1515
+			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND record_time = ?  AND count > 0", orgID, scheduleDate)
1516
+		}).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
1517
+
1518
+	if scheduleDate != 0 {
1519
+		db = db.Where("schedule_date = ?", scheduleDate)
1520
+	}
1521
+	if patient_id != 0 {
1522
+		db = db.Where("patient_id = ?", patient_id)
1523
+	}
1524
+	if len(keywords) != 0 {
1525
+		keywords = "%" + keywords + "%"
1526
+		db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
1527
+	} else {
1528
+		if schedule_type != 0 {
1529
+			db = db.Where("schedule_type = ?", schedule_type)
1530
+		}
1531
+		if partition_id != 0 {
1532
+			db = db.Where("partition_id = ?", partition_id)
1533
+		}
1534
+
1535
+		db = db.Count(&total)
1536
+		offset := (page - 1) * limit
1537
+
1538
+		db = db.Offset(offset).Limit(limit)
1539
+
1540
+	}
1541
+
1542
+	err := db.Find(&vms).Error
1543
+
1544
+	return vms, err, total
1545
+}

+ 1 - 1
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go View File

@@ -169,7 +169,7 @@ func FindPrintStockGoodInfoByType(types int, startTime int64, end_time int64, or
169 169
 		})
170 170
 
171 171
 	}
172
-	db = db.Preload("GoodsType", "(org_id = ? AND status = 1) OR (status = 1 AND type = 1)", orgId)
172
+	db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgId)
173 173
 	err = db.Order("ctime desc").Find(&list).Error
174 174
 	return
175 175
 }

+ 57 - 13
service/stock_service.go View File

@@ -137,13 +137,13 @@ func ModifyGoodType(goodType *models.GoodsType) (error, *models.GoodsType) {
137 137
 func FindAllGoodTypeList(orgId int64, page int64, limit int64, keyword string) (list []*models.GoodsType, total int64, err error) {
138 138
 	offset := (page - 1) * limit
139 139
 	db := readDb.Model(&models.GoodsType{})
140
-	db = db.Where("(org_id=? AND status = 1) OR (type = 1 AND status = 1)", orgId)
140
+	db = db.Where("org_id=? AND status = 1", orgId)
141 141
 	if len(keyword) > 0 {
142 142
 		likeKey := "%" + keyword + "%"
143 143
 		db = db.Where("type_code LIKE ? OR type_name LIKE ?", likeKey, likeKey)
144 144
 	}
145 145
 
146
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
146
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("type desc, number desc,ctime desc").Find(&list).Error
147 147
 	return
148 148
 }
149 149
 
@@ -220,7 +220,7 @@ func FindGoodInfoById(id int64) (*models.GoodInfo, error) {
220 220
 }
221 221
 
222 222
 func FindAllGoodType(org_id int64) (goodType []*models.GoodsType, err error) {
223
-	err = readDb.Model(&models.GoodsType{}).Where("(org_id = ? AND status = 1) OR (type = 1 AND status = 1)", org_id).Find(&goodType).Error
223
+	err = readDb.Model(&models.GoodsType{}).Where("org_id = ? AND status = 1", org_id).Find(&goodType).Error
224 224
 	return goodType, err
225 225
 }
226 226
 
@@ -654,7 +654,7 @@ func FindAllStockInfo(orgId int64, page int64, limit int64, keyword string) (lis
654 654
 
655 655
 	db := readDb.Model(&models.StockInfo{})
656 656
 	db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgId)
657
-	db = db.Joins("JOIN xt_warehouse_info AS info ON info.good_id=xt_good_information.id AND info.status = 1").Group("xt_good_information.id")
657
+	db = db.Group("xt_good_information.id")
658 658
 	db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
659 659
 		return db.Where("org_id = ? AND status = 1", orgId)
660 660
 	})
@@ -663,11 +663,11 @@ func FindAllStockInfo(orgId int64, page int64, limit int64, keyword string) (lis
663 663
 		return db.Where("org_id = ? AND status = 1", orgId)
664 664
 	})
665 665
 	db = db.Preload("QueryCancelStockInfo", "org_id = ? AND status = 1", orgId)
666
-	db = db.Preload("GoodsType", "(org_id = ? AND status = 1) OR (status = 1 AND type = 1)", orgId)
666
+	db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgId)
667 667
 
668 668
 	if len(keyword) > 0 {
669 669
 		likeKey := "%" + keyword + "%"
670
-		db = db.Joins("join xt_goods_type on xt_goods_type.id = xt_good_information.good_type_id  AND ((xt_goods_type.org_id = ? AND xt_goods_type.status = 1) OR (xt_goods_type.type = 1 AND xt_goods_type.status = 1))", orgId)
670
+		db = db.Joins("join xt_goods_type on xt_goods_type.id = xt_good_information.good_type_id  AND xt_goods_type.org_id = ? AND xt_goods_type.status = 1", orgId)
671 671
 		db = db.Where("xt_good_information.good_code LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_goods_type.type_name LIKE ?", likeKey, likeKey, likeKey).Group("xt_good_information.id")
672 672
 	}
673 673
 
@@ -682,6 +682,10 @@ func FindWarehouseInfoTotalByGoodId(goodId int64) (total int64, err error) {
682 682
 	return
683 683
 }
684 684
 
685
+func FindWarehouseOutInfoTotalByGoodId(goodId int64) (total int64, err error) {
686
+	err = readDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND status = 1", goodId).Count(&total).Error
687
+	return
688
+}
685 689
 func UpDateWarehouse(warehouse *models.Warehousing) (err error) {
686 690
 	err = readDb.Model(&models.Warehousing{}).Where("warehousing_order = ? AND status = 1", warehouse.WarehousingOrder).Update(map[string]interface{}{"operation_time": warehouse.OperationTime, "mtime": warehouse.Mtime, "modifier": warehouse.Modifier}).Error
687 691
 	return
@@ -769,7 +773,7 @@ func FindAllGoodByManufactureId(manufacturer_id int64, dealer_id int64, org_id i
769 773
 	if dealer_id > 0 {
770 774
 		db = db.Where("dealer = ?", dealer_id)
771 775
 	}
772
-	err = db.Preload("GoodsType", "status = 1 AND (org_id = ? OR type = 1)", org_id).Find(&goodInfo).Error
776
+	err = db.Preload("GoodsType", "status = 1 AND org_id = ?", org_id).Find(&goodInfo).Error
773 777
 	return goodInfo, err
774 778
 }
775 779
 
@@ -801,7 +805,7 @@ func FindAllWarehouse(org_id int64, types int64) (list []*models.Warehousing, er
801 805
 
802 806
 func FindAllWarehouseInfo(org_id int64, types int64) (list []*models.WarehousingInfoConfig, err error) {
803 807
 	err = readDb.Model(&models.WarehousingInfoConfig{}).Preload("WarehousingGoodInfo", func(db *gorm.DB) *gorm.DB {
804
-		return db.Where("status = 1 AND org_id = ?", org_id).Preload("GoodsType", "(status = 1 AND org_id = ?)OR(type = 1 AND status = 1)", org_id).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id)
808
+		return db.Where("status = 1 AND org_id = ?", org_id).Preload("GoodsType", "status = 1 AND org_id = ?", org_id).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id)
805 809
 	}).Where("org_id = ? AND status = 1 AND type = ?", org_id, types).Find(&list).Error
806 810
 	return list, err
807 811
 }
@@ -946,7 +950,7 @@ func FindWarehouseOutList(org_id int64, types int64) (list []*models.WarehouseOu
946 950
 
947 951
 func FindAllWarehouseOutInfo(org_id int64, types int64) (list []*models.WarehousingOutInfoConfig, err error) {
948 952
 	err = readDb.Model(&models.WarehousingOutInfoConfig{}).Preload("WarehousingGoodInfo", func(db *gorm.DB) *gorm.DB {
949
-		return db.Where("status = 1 AND org_id = ?", org_id).Preload("GoodsType", "(status = 1 AND org_id = ?) OR (status = 1 AND type = 1) ", org_id).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id)
953
+		return db.Where("status = 1 AND org_id = ?", org_id).Preload("GoodsType", "status = 1 AND org_id = ? ", org_id).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id)
950 954
 	}).Where("org_id = ? AND status = 1 AND type = ?", org_id, types).Find(&list).Error
951 955
 	return list, err
952 956
 
@@ -1172,7 +1176,7 @@ func FindStockInByManufacturerId(id int64) (total int64, err error) {
1172 1176
 }
1173 1177
 
1174 1178
 func FindGoodTypeByName(name string, org_id int64) (total int64) {
1175
-	readDb.Model(&models.GoodsType{}).Where("(org_id = ? OR type = 1) AND status = 1 AND type_name = ? ", org_id, name).Count(&total)
1179
+	readDb.Model(&models.GoodsType{}).Where("org_id = ? AND status = 1 AND type_name = ? ", org_id, name).Count(&total)
1176 1180
 	return
1177 1181
 }
1178 1182
 func FindGoodInfoByName(name string, org_id int64) (total int64) {
@@ -1215,8 +1219,8 @@ func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
1215 1219
 
1216 1220
 }
1217 1221
 
1218
-func FindStockOutInfoByTypeId(org_id int64, good_type_id int64, good_id int64, out_id int64) (out models.WarehouseOutInfo, err error) {
1219
-	err = readDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND  warehouse_out_id = ?", org_id, good_type_id, good_id, out_id).First(&out).Error
1222
+func FindStockOutInfoByTypeId(org_id int64, good_type_id int64, good_id int64, out_id int64, number string) (out models.WarehouseOutInfo, err error) {
1223
+	err = readDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND  (warehouse_out_id = ? or warehouse_out_order_number = ?)", org_id, good_type_id, good_id, out_id, number).First(&out).Error
1220 1224
 	return
1221 1225
 }
1222 1226
 
@@ -1228,10 +1232,50 @@ func UpdateStockOutInfoCount(org_id int64, id int64) {
1228 1232
 func FindUserDetailById(org_id int64, id int64) (user []*models.AutomaticReduceDetail, err error, total int64) {
1229 1233
 	db := readDb.Model(&models.AutomaticReduceDetail{})
1230 1234
 	db = db.Preload("GoodInfo", "org_id = ? AND status = 1", org_id)
1231
-	db = db.Preload("GoodsType", "type = 1 AND status = 1")
1235
+	db = db.Preload("GoodsType", "status = 1")
1232 1236
 	db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
1233 1237
 	db = db.Where("status = 1 AND org_id = ? AND warehouse_out_id = ? AND good_id != 0", org_id, id)
1234 1238
 	db = db.Count(&total)
1235 1239
 	err = db.Find(&user).Error
1236 1240
 	return
1237 1241
 }
1242
+
1243
+func UpdateStockOutInfoCount2(org_id int64, id int64, count int64) {
1244
+	writeDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND id = ?", org_id, id).UpdateColumn("count", gorm.Expr("count + ?", count))
1245
+
1246
+}
1247
+
1248
+type VMWarehousingInfo struct {
1249
+	ID            int64    `gorm:"column:id" json:"id"`
1250
+	WarehousingId int64    `gorm:"column:warehousing_id" json:"warehousing_id"`
1251
+	GoodId        int64    `gorm:"column:good_id" json:"good_id"`
1252
+	GoodTypeId    int64    `gorm:"column:good_type_id" json:"good_type_id"`
1253
+	Status        int64    `gorm:"column:status" json:"status"`
1254
+	OrgId         int64    `gorm:"column:org_id" json:"org_id"`
1255
+	GoodInfo      GoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
1256
+}
1257
+
1258
+func (VMWarehousingInfo) TableName() string {
1259
+	return "xt_warehouse_info"
1260
+}
1261
+
1262
+type GoodInfo struct {
1263
+	ID                int64  `gorm:"column:id" json:"id"`
1264
+	SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
1265
+	Status            int64  `gorm:"column:status" json:"status"`
1266
+	OrgId             int64  `gorm:"column:org_id" json:"org_id"`
1267
+}
1268
+
1269
+func (GoodInfo) TableName() string {
1270
+	return "xt_good_information"
1271
+}
1272
+
1273
+func GetStockInGoodInfo(orgId int64) (stockIn []*VMWarehousingInfo, err error) {
1274
+	err = readDb.Model(&VMWarehousingInfo{}).Preload("GoodInfo", "status = 1 AND org_id = ?", orgId).Where("org_id = ? AND status = 1", orgId).Find(&stockIn).Error
1275
+	return
1276
+}
1277
+
1278
+func GetAllStockOutUserDetail(patient_id int64, orgId int64, record_time int64) (goodUser []*models.DialysisBeforePrepare, err error) {
1279
+	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND record_date = ? AND status = 1", patient_id, orgId, record_time).Find(&goodUser).Error
1280
+	return
1281
+}