Procházet zdrojové kódy

Merge branch '20230223_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20230223_xt_api_new_branch

陈少旭 před 7 měsíci
rodič
revize
13b74d8798

+ 4 - 4
controllers/base_api_controller.go Zobrazit soubor

@@ -83,7 +83,7 @@ func (this *BaseAuthAPIController) Prepare() {
83 83
 		userAdmin.ModifyTime = 1530786071
84 84
 		var subscibe models.ServeSubscibe
85 85
 		subscibe.ID = 11
86
-		subscibe.OrgId = 10666 //机构id
86
+		subscibe.OrgId = 10633 //机构id
87 87
 		subscibe.PeriodStart = 1547447814
88 88
 		subscibe.PeriodEnd = 1550039814
89 89
 		subscibe.State = 1
@@ -93,7 +93,7 @@ func (this *BaseAuthAPIController) Prepare() {
93 93
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
94 94
 		subscibes[4] = &subscibe
95 95
 		var adminUserInfo service.AdminUserInfo
96
-		adminUserInfo.CurrentOrgId = 10666 //机构id小英9675或4
96
+		adminUserInfo.CurrentOrgId = 10633 //机构id小英9675或4
97 97
 		adminUserInfo.CurrentAppId = 17876 //4
98 98
 		adminUserInfo.AdminUser = &userAdmin
99 99
 		adminUserInfo.Subscibes = subscibes
@@ -329,7 +329,7 @@ func (this *BaseServeAPIController) Prepare() {
329 329
 		userAdmin.ModifyTime = 1530786071
330 330
 		var subscibe models.ServeSubscibe
331 331
 		subscibe.ID = 11
332
-		subscibe.OrgId = 10666 //机构id小英9675或4
332
+		subscibe.OrgId = 10633 //机构id小英9675或4
333 333
 		subscibe.PeriodStart = 1538035409
334 334
 		subscibe.PeriodEnd = 1569571409
335 335
 		subscibe.State = 1
@@ -339,7 +339,7 @@ func (this *BaseServeAPIController) Prepare() {
339 339
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
340 340
 		subscibes[4] = &subscibe
341 341
 		var adminUserInfo service.AdminUserInfo
342
-		adminUserInfo.CurrentOrgId = 10666 //机构id小英9675或4
342
+		adminUserInfo.CurrentOrgId = 10633 //机构id小英9675或4
343 343
 		adminUserInfo.CurrentAppId = 17876 //4
344 344
 		adminUserInfo.AdminUser = &userAdmin
345 345
 		adminUserInfo.Subscibes = subscibes

+ 140 - 132
controllers/his_api_controller.go Zobrazit soubor

@@ -3185,7 +3185,7 @@ func (c *HisApiController) CreateHisPrescription() {
3185 3185
 	var adviceList []models.HisDoctorAdviceInfo
3186 3186
 	var projectList []models.HisPrescriptionProject
3187 3187
 
3188
-	if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 9675 {
3188
+	if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 {
3189 3189
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
3190 3190
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
3191 3191
 
@@ -4943,7 +4943,6 @@ func (c *HisApiController) CreateHisPrescription() {
4943 4943
 			////同步到自备药
4944 4944
 			selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
4945 4945
 
4946
-			fmt.Println("selfPrescriptionOpen--------------------------------------------------", selfPrescriptionOpen.IsOpen)
4947 4946
 			if selfPrescriptionOpen.IsOpen == 1 {
4948 4947
 
4949 4948
 				timeStr := time.Now().Format("2006-01-02")
@@ -5008,7 +5007,6 @@ func (c *HisApiController) CreateHisPrescription() {
5008 5007
 
5009 5008
 					}
5010 5009
 
5011
-					fmt.Println("selfBasedrug--------------------", selfBasedrug.IsSelfDrug)
5012 5010
 					if selfBasedrug.IsSelfDrug == 1 {
5013 5011
 						var total_count int64
5014 5012
 
@@ -5027,8 +5025,6 @@ func (c *HisApiController) CreateHisPrescription() {
5027 5025
 							total_count += prescribingNumberSeven
5028 5026
 						}
5029 5027
 
5030
-						fmt.Println("tota_count==================================", total_count)
5031
-						fmt.Println("in_count==================================", in_count)
5032 5028
 						//入库
5033 5029
 						if total_count > in_count {
5034 5030
 
@@ -5208,8 +5204,6 @@ func (c *HisApiController) CreateHisPrescription() {
5208 5204
 									maxNumber = cha_count / selfBasedrug.MinNumber
5209 5205
 									minNumber = cha_count % selfBasedrug.MinNumber
5210 5206
 
5211
-									fmt.Println("maxNumber----------------------------", maxNumber)
5212
-									fmt.Println("minNumber----------------------------", minNumber)
5213 5207
 									if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5214 5208
 										minNumber = maxNumber
5215 5209
 									}
@@ -5694,70 +5688,23 @@ func (c *HisApiController) DeletePrescription() {
5694 5688
 
5695 5689
 	////同步到自备药
5696 5690
 	selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
5691
+
5692
+	fmt.Println("selfPrescriptionOpen=---------------------------", selfPrescriptionOpen)
5697 5693
 	var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
5694
+
5698 5695
 	if selfPrescriptionOpen.IsOpen == 1 {
5699
-		// 开始主事务
5696
+		// 在函数结束时处理事务回滚
5700 5697
 		db := service.XTWriteDB()
5701 5698
 		tx := db.Begin()
5702
-
5703
-		// 在函数结束时处理事务回滚
5704 5699
 		defer func() {
5705 5700
 			if r := recover(); r != nil {
5706 5701
 				tx.Rollback()
5702
+			} else {
5703
+				tx.Commit()
5707 5704
 			}
5708 5705
 		}()
5709
-		for _, item := range advices {
5710
-			selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
5711
-
5712
-			var total_count int64
5713
-			prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
5714
-			prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
5715
-
5716
-			if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5717
-				total_count += prescribingNumberSeven * selfBasedrug.MinNumber
5718
-			}
5719
-
5720
-			if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5721
-				total_count += prescribingNumberSeven
5722
-			}
5723
-
5724
-			if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5725
-				total_count += prescribingNumberSeven
5726
-			}
5727
-			//出库
5728
-			warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
5729
-				DrugId:           item.DrugId,
5730
-				Count:            total_count,
5731
-				Price:            0,
5732
-				TotalPrice:       0,
5733
-				Status:           1,
5734
-				Ctime:            item.AdviceDate,
5735
-				Mtime:            item.AdviceDate,
5736
-				Remark:           "",
5737
-				OrgId:            item.UserOrgId,
5738
-				Type:             0,
5739
-				Manufacturer:     selfBasedrug.Manufacturer,
5740
-				Dealer:           selfBasedrug.Dealer,
5741
-				RetailPrice:      0,
5742
-				RetailTotalPrice: 0,
5743
-				CountUnit:        item.PrescribingNumberUnit,
5744
-				ExpiryDate:       0,
5745
-				ProductDate:      0,
5746
-				Number:           "",
5747
-				BatchNumber:      "",
5748
-				IsSys:            0,
5749
-				WarehouseInfoId:  0,
5750
-				AdminUserId:      0,
5751
-				StockCount:       "",
5752
-				IsCheck:          2,
5753
-				SysRecordTime:    item.AdviceDate,
5754
-				PatientId:        item.PatientId,
5755
-				ClassType:        "",
5756
-			}
5757
-			warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
5758
-		}
5759
-
5760
-		for _, it := range warehousingOutInfo {
5706
+		advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
5707
+		for _, item := range advicesList {
5761 5708
 
5762 5709
 			timeStr := time.Now().Format("2006-01-02")
5763 5710
 			timeArr := strings.Split(timeStr, "-")
@@ -5765,6 +5712,7 @@ func (c *HisApiController) DeletePrescription() {
5765 5712
 
5766 5713
 			total = total + 1
5767 5714
 			warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
5715
+			fmt.Println("warehousing_out_order--------------------------------------", warehousing_out_order)
5768 5716
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
5769 5717
 			number = number + total
5770 5718
 			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
@@ -5779,23 +5727,80 @@ func (c *HisApiController) DeletePrescription() {
5779 5727
 				Creater:                 creater,
5780 5728
 				Ctime:                   time.Now().Unix(),
5781 5729
 				Status:                  1,
5782
-				WarehouseOutTime:        it.SysRecordTime,
5730
+				WarehouseOutTime:        item.AdviceDate,
5783 5731
 				Type:                    0,
5784
-				PatientId:               it.PatientId,
5785
-				IsCheck:                 2,
5732
+				PatientId:               item.PatientId,
5733
+				IsCheck:                 1,
5786 5734
 			}
5787 5735
 
5788 5736
 			//查询今日是否有出库数据
5789
-			lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx)
5737
+			lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
5790 5738
 
5739
+			fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
5791 5740
 			if lastWarehouseOut.ID == 0 {
5792
-				service.AddSelfSigleDrugWarehouseOut(&lastWarehouseOut, tx)
5741
+				service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
5793 5742
 			}
5743
+			selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
5744
+
5745
+			var total_count int64
5746
+			prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
5747
+			prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
5794 5748
 
5749
+			if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5750
+				total_count += prescribingNumberSeven * selfBasedrug.MinNumber
5751
+			}
5752
+
5753
+			if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5754
+				total_count += prescribingNumberSeven
5755
+			}
5756
+
5757
+			if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5758
+				total_count += prescribingNumberSeven
5759
+			}
5760
+			//出库
5761
+			warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
5762
+				WarehouseOutOrderNumber: warehousing_out_order,
5763
+				WarehouseOutId:          lastWarehouseOut.ID,
5764
+				DrugId:                  item.DrugId,
5765
+				Count:                   total_count,
5766
+				Price:                   0,
5767
+				TotalPrice:              0,
5768
+				Status:                  1,
5769
+				Ctime:                   item.AdviceDate,
5770
+				Mtime:                   item.AdviceDate,
5771
+				Remark:                  "",
5772
+				OrgId:                   item.UserOrgId,
5773
+				Type:                    0,
5774
+				Manufacturer:            selfBasedrug.Manufacturer,
5775
+				Dealer:                  selfBasedrug.Dealer,
5776
+				RetailPrice:             0,
5777
+				RetailTotalPrice:        0,
5778
+				CountUnit:               selfBasedrug.MinUnit,
5779
+				ExpiryDate:              0,
5780
+				ProductDate:             0,
5781
+				Number:                  "",
5782
+				BatchNumber:             "",
5783
+				IsSys:                   1,
5784
+				WarehouseInfoId:         0,
5785
+				AdminUserId:             0,
5786
+				StockCount:              "",
5787
+				IsCheck:                 1,
5788
+				SysRecordTime:           item.AdviceDate,
5789
+				PatientId:               item.PatientId,
5790
+				ClassType:               "",
5791
+				AdviceId:                item.ID,
5792
+			}
5793
+			warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
5794
+		}
5795
+
5796
+		fmt.Println("长度-------------------------------", warehousingOutInfo)
5797
+		for _, it := range warehousingOutInfo {
5798
+			//查询今日是否有出库数据
5799
+			lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
5795 5800
 			medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5796 5801
 			drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
5797 5802
 			//出库逻辑
5798
-			service.AutoSelfDrugDeliverInfoFourtyOne(c.GetAdminUserInfo().CurrentOrgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
5803
+			service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
5799 5804
 
5800 5805
 			//查询剩余库存
5801 5806
 			stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
@@ -6367,14 +6372,14 @@ func (c *HisApiController) DeleteDoctorAdvice() {
6367 6372
 	selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
6368 6373
 	var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
6369 6374
 	if selfPrescriptionOpen.IsOpen == 1 {
6370
-		// 开始主事务
6375
+
6371 6376
 		db := service.XTWriteDB()
6372 6377
 		tx := db.Begin()
6373
-
6374
-		// 在函数结束时处理事务回滚
6375 6378
 		defer func() {
6376 6379
 			if r := recover(); r != nil {
6377 6380
 				tx.Rollback()
6381
+			} else {
6382
+				tx.Commit()
6378 6383
 			}
6379 6384
 		}()
6380 6385
 
@@ -6395,77 +6400,80 @@ func (c *HisApiController) DeleteDoctorAdvice() {
6395 6400
 		if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
6396 6401
 			total_count += prescribingNumberSeven
6397 6402
 		}
6398
-		//出库
6399
-		warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
6400
-			DrugId:           advice.DrugId,
6401
-			Count:            total_count,
6402
-			Price:            0,
6403
-			TotalPrice:       0,
6404
-			Status:           1,
6405
-			Ctime:            advice.AdviceDate,
6406
-			Mtime:            advice.AdviceDate,
6407
-			Remark:           "",
6408
-			OrgId:            advice.UserOrgId,
6409
-			Type:             0,
6410
-			Manufacturer:     selfBasedrug.Manufacturer,
6411
-			Dealer:           selfBasedrug.Dealer,
6412
-			RetailPrice:      0,
6413
-			RetailTotalPrice: 0,
6414
-			CountUnit:        advice.PrescribingNumberUnit,
6415
-			ExpiryDate:       0,
6416
-			ProductDate:      0,
6417
-			Number:           "",
6418
-			BatchNumber:      "",
6419
-			IsSys:            0,
6420
-			WarehouseInfoId:  0,
6421
-			AdminUserId:      0,
6422
-			StockCount:       "",
6423
-			IsCheck:          2,
6424
-			SysRecordTime:    advice.AdviceDate,
6425
-			PatientId:        advice.PatientId,
6426
-			ClassType:        "",
6427
-		}
6428
-		warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
6429 6403
 
6430
-		for _, it := range warehousingOutInfo {
6404
+		timeStr := time.Now().Format("2006-01-02")
6405
+		timeArr := strings.Split(timeStr, "-")
6406
+		total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
6431 6407
 
6432
-			timeStr := time.Now().Format("2006-01-02")
6433
-			timeArr := strings.Split(timeStr, "-")
6434
-			total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
6408
+		total = total + 1
6409
+		warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
6410
+		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
6411
+		number = number + total
6412
+		warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
6413
+		operation_time := time.Now().Unix()
6435 6414
 
6436
-			total = total + 1
6437
-			warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
6438
-			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
6439
-			number = number + total
6440
-			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
6441
-			operation_time := time.Now().Unix()
6415
+		creater := c.GetAdminUserInfo().AdminUser.Id
6416
+		//创建一个出库单
6417
+		drugWarehouseOut := models.XtSelfDrugWarehouseOut{
6418
+			WarehouseOutOrderNumber: warehousing_out_order,
6419
+			OperationTime:           operation_time,
6420
+			OrgId:                   c.GetAdminUserInfo().CurrentOrgId,
6421
+			Creater:                 creater,
6422
+			Ctime:                   time.Now().Unix(),
6423
+			Status:                  1,
6424
+			WarehouseOutTime:        advice.AdviceDate,
6425
+			Type:                    0,
6426
+			PatientId:               advice.PatientId,
6427
+			IsCheck:                 1,
6428
+		}
6442 6429
 
6443
-			creater := c.GetAdminUserInfo().AdminUser.Id
6444
-			//创建一个出库单
6445
-			drugWarehouseOut := models.XtSelfDrugWarehouseOut{
6446
-				WarehouseOutOrderNumber: warehousing_out_order,
6447
-				OperationTime:           operation_time,
6448
-				OrgId:                   c.GetAdminUserInfo().CurrentOrgId,
6449
-				Creater:                 creater,
6450
-				Ctime:                   time.Now().Unix(),
6451
-				Status:                  1,
6452
-				WarehouseOutTime:        it.SysRecordTime,
6453
-				Type:                    0,
6454
-				PatientId:               it.PatientId,
6455
-				IsCheck:                 2,
6456
-			}
6430
+		//查询今日是否有出库数据
6431
+		lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
6457 6432
 
6458
-			//查询今日是否有出库数据
6459
-			lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx)
6433
+		if lastWarehouseOut.ID == 0 {
6434
+			service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
6435
+		}
6436
+		//出库
6437
+		warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
6438
+			WarehouseOutId:          lastWarehouseOut.ID,
6439
+			WarehouseOutOrderNumber: warehousing_out_order,
6440
+			DrugId:                  advice.DrugId,
6441
+			Count:                   total_count,
6442
+			Price:                   0,
6443
+			TotalPrice:              0,
6444
+			Status:                  1,
6445
+			Ctime:                   advice.AdviceDate,
6446
+			Mtime:                   advice.AdviceDate,
6447
+			Remark:                  "",
6448
+			OrgId:                   advice.UserOrgId,
6449
+			Type:                    0,
6450
+			Manufacturer:            selfBasedrug.Manufacturer,
6451
+			Dealer:                  selfBasedrug.Dealer,
6452
+			RetailPrice:             0,
6453
+			RetailTotalPrice:        0,
6454
+			CountUnit:               advice.PrescribingNumberUnit,
6455
+			ExpiryDate:              0,
6456
+			ProductDate:             0,
6457
+			Number:                  "",
6458
+			BatchNumber:             "",
6459
+			IsSys:                   0,
6460
+			WarehouseInfoId:         0,
6461
+			AdminUserId:             0,
6462
+			StockCount:              "",
6463
+			IsCheck:                 1,
6464
+			SysRecordTime:           advice.AdviceDate,
6465
+			PatientId:               advice.PatientId,
6466
+			AdviceId:                advice.ID,
6467
+			ClassType:               "",
6468
+		}
6469
+		warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
6460 6470
 
6461
-			if lastWarehouseOut.ID == 0 {
6462
-				service.AddSelfSigleDrugWarehouseOut(&lastWarehouseOut, tx)
6463
-			}
6471
+		for _, it := range warehousingOutInfo {
6464 6472
 
6465 6473
 			medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
6466 6474
 			drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
6467 6475
 			//出库逻辑
6468
-			service.AutoSelfDrugDeliverInfoFourtyOne(c.GetAdminUserInfo().CurrentOrgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
6476
+			service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
6469 6477
 
6470 6478
 			//查询剩余库存
6471 6479
 			stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)

+ 320 - 4
controllers/mobile_api_controllers/patient_api_controller.go Zobrazit soubor

@@ -1263,6 +1263,171 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1263 1263
 				return
1264 1264
 			}
1265 1265
 		}
1266
+
1267
+		//自备药
1268
+		selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
1269
+
1270
+		if selfPrescriptionOutOpen.IsOpen == 1 {
1271
+
1272
+			db := service.XTWriteDB()
1273
+			tx := db.Begin()
1274
+			defer func() {
1275
+				if r := recover(); r != nil {
1276
+					tx.Rollback()
1277
+				} else {
1278
+					tx.Commit()
1279
+				}
1280
+			}()
1281
+
1282
+			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
1283
+
1284
+			if selfBasedrug.IsSelfDrug == 1 {
1285
+
1286
+				//查询是否有库存
1287
+				info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
1288
+
1289
+				if len(info) > 0 {
1290
+					var total_count int64
1291
+					var prescribing_number_total int64
1292
+					for _, item := range info {
1293
+						if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1294
+							item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
1295
+						}
1296
+
1297
+						total_count += item.StockMaxNumber + item.StockMinNumber
1298
+					}
1299
+
1300
+					//判断单位是否相等
1301
+					if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1302
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1303
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1304
+						//转化为最小单位
1305
+						prescribing_number_total = count * selfBasedrug.MinNumber
1306
+					}
1307
+
1308
+					if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1309
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1310
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1311
+						prescribing_number_total = count
1312
+
1313
+					}
1314
+
1315
+					if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
1316
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1317
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1318
+						prescribing_number_total = count
1319
+
1320
+					}
1321
+
1322
+					if prescribing_number_total > total_count {
1323
+						c.ServeSuccessJSON(map[string]interface{}{
1324
+							"msg":    "3",
1325
+							"advice": advice,
1326
+						})
1327
+						return
1328
+					}
1329
+					var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
1330
+					//出库
1331
+					if prescribing_number_total <= total_count {
1332
+						timeStr := time.Now().Format("2006-01-02")
1333
+						timeArr := strings.Split(timeStr, "-")
1334
+						total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
1335
+
1336
+						total = total + 1
1337
+						warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1338
+						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1339
+						number = number + total
1340
+						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1341
+						operation_time := time.Now().Unix()
1342
+
1343
+						creater := c.GetAdminUserInfo().AdminUser.Id
1344
+						//创建一个出库单
1345
+						drugWarehouseOut := models.XtSelfDrugWarehouseOut{
1346
+							WarehouseOutOrderNumber: warehousing_out_order,
1347
+							OperationTime:           operation_time,
1348
+							OrgId:                   adminUserInfo.Org.Id,
1349
+							Creater:                 creater,
1350
+							Ctime:                   time.Now().Unix(),
1351
+							Status:                  1,
1352
+							WarehouseOutTime:        advice.AdviceDate,
1353
+							Type:                    0,
1354
+							PatientId:               advice.PatientId,
1355
+							IsCheck:                 1,
1356
+							IsSys:                   1,
1357
+						}
1358
+
1359
+						//查询今日是否有出库数据
1360
+						lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, advice.AdviceDate, tx, 1)
1361
+
1362
+						if lastWarehouseOut.ID == 0 {
1363
+							service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
1364
+						}
1365
+						//出库
1366
+						warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
1367
+							WarehouseOutOrderNumber: warehousing_out_order,
1368
+							DrugId:                  advice.DrugId,
1369
+							Count:                   total_count,
1370
+							Price:                   0,
1371
+							TotalPrice:              0,
1372
+							Status:                  1,
1373
+							Ctime:                   advice.AdviceDate,
1374
+							Mtime:                   advice.AdviceDate,
1375
+							Remark:                  "",
1376
+							OrgId:                   advice.UserOrgId,
1377
+							Type:                    0,
1378
+							Manufacturer:            selfBasedrug.Manufacturer,
1379
+							Dealer:                  selfBasedrug.Dealer,
1380
+							RetailPrice:             0,
1381
+							RetailTotalPrice:        0,
1382
+							CountUnit:               advice.PrescribingNumberUnit,
1383
+							ExpiryDate:              0,
1384
+							ProductDate:             0,
1385
+							Number:                  "",
1386
+							BatchNumber:             "",
1387
+							IsSys:                   0,
1388
+							WarehouseInfoId:         0,
1389
+							AdminUserId:             0,
1390
+							StockCount:              "",
1391
+							IsCheck:                 1,
1392
+							SysRecordTime:           advice.AdviceDate,
1393
+							PatientId:               advice.PatientId,
1394
+							AdviceId:                advice.ID,
1395
+							ClassType:               "",
1396
+						}
1397
+						warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1398
+
1399
+						for _, it := range warehousingOutInfo {
1400
+
1401
+							medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
1402
+							drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
1403
+							//出库逻辑
1404
+							service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
1405
+
1406
+							//查询剩余库存
1407
+							stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
1408
+							var sum_count int64
1409
+							for _, its := range stockInfo {
1410
+								if its.MaxUnit == medical.MaxUnit {
1411
+									its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
1412
+								}
1413
+								sum_count += its.StockMaxNumber + its.StockMinNumber
1414
+							}
1415
+							service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
1416
+						}
1417
+					}
1418
+
1419
+				} else {
1420
+					c.ServeSuccessJSON(map[string]interface{}{
1421
+						"msg":    "3",
1422
+						"advice": advice,
1423
+					})
1424
+					return
1425
+				}
1426
+
1427
+			}
1428
+
1429
+		}
1430
+
1266 1431
 		c.ServeSuccessJSON(map[string]interface{}{
1267 1432
 			"msg":    "1",
1268 1433
 			"advice": advice,
@@ -1477,8 +1642,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1477 1642
 					}
1478 1643
 				}
1479 1644
 
1480
-				fmt.Println("total_count-------------------------------", total_count)
1481
-				fmt.Println("drug_count-------------------------------", drug_count)
1482 1645
 				if total_count == drug_count {
1483 1646
 					advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
1484 1647
 					tx.Commit()
@@ -1497,7 +1660,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1497 1660
 
1498 1661
 				//保存处方出库
1499 1662
 				config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
1500
-				fmt.Println("config============================================")
1663
+
1501 1664
 				if config.IsOpen != 1 {
1502 1665
 					//查询该药品是否有库存
1503 1666
 					houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
@@ -1814,7 +1977,160 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1814 1977
 					}
1815 1978
 				}
1816 1979
 
1817
-				fmt.Println("org_id =============================", adminInfo.Org.Id)
1980
+				//自备药
1981
+				selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminInfo.Org.Id)
1982
+
1983
+				if selfPrescriptionOutOpen.IsOpen == 1 {
1984
+
1985
+					selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
1986
+
1987
+					if selfBasedrug.IsSelfDrug == 1 {
1988
+
1989
+						//查询是否有库存
1990
+						info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
1991
+
1992
+						if len(info) > 0 {
1993
+							var total_count int64
1994
+							var prescribing_number_total int64
1995
+							for _, item := range info {
1996
+								if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1997
+									item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
1998
+								}
1999
+
2000
+								total_count += item.StockMaxNumber + item.StockMinNumber
2001
+							}
2002
+
2003
+							//判断单位是否相等
2004
+							if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
2005
+								prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2006
+								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2007
+								//转化为最小单位
2008
+								prescribing_number_total = count * selfBasedrug.MinNumber
2009
+							}
2010
+
2011
+							if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
2012
+								prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2013
+								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2014
+								prescribing_number_total = count
2015
+
2016
+							}
2017
+
2018
+							if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
2019
+								prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2020
+								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2021
+								prescribing_number_total = count
2022
+
2023
+							}
2024
+
2025
+							if prescribing_number_total > total_count {
2026
+								c.ServeSuccessJSON(map[string]interface{}{
2027
+									"msg":    "3",
2028
+									"advice": advice,
2029
+								})
2030
+								return
2031
+							}
2032
+							var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
2033
+							//出库
2034
+							if prescribing_number_total <= total_count {
2035
+								timeStr := time.Now().Format("2006-01-02")
2036
+								timeArr := strings.Split(timeStr, "-")
2037
+								total, _ := service.FindAllSelfDrugWarehouseOut(adminInfo.Org.Id, tx)
2038
+
2039
+								total = total + 1
2040
+								warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
2041
+								number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
2042
+								number = number + total
2043
+								warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
2044
+								operation_time := time.Now().Unix()
2045
+
2046
+								creater := adminInfo.AdminUser.Id
2047
+								//创建一个出库单
2048
+								drugWarehouseOut := models.XtSelfDrugWarehouseOut{
2049
+									WarehouseOutOrderNumber: warehousing_out_order,
2050
+									OperationTime:           operation_time,
2051
+									OrgId:                   adminInfo.Org.Id,
2052
+									Creater:                 creater,
2053
+									Ctime:                   time.Now().Unix(),
2054
+									Status:                  1,
2055
+									WarehouseOutTime:        advice.AdviceDate,
2056
+									Type:                    0,
2057
+									PatientId:               advice.PatientId,
2058
+									IsCheck:                 1,
2059
+									IsSys:                   1,
2060
+								}
2061
+
2062
+								//查询今日是否有出库数据
2063
+								lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
2064
+
2065
+								if lastWarehouseOut.ID == 0 {
2066
+									service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
2067
+								}
2068
+								//出库
2069
+								warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
2070
+									WarehouseOutOrderNumber: warehousing_out_order,
2071
+									DrugId:                  advice.DrugId,
2072
+									Count:                   total_count,
2073
+									Price:                   0,
2074
+									TotalPrice:              0,
2075
+									Status:                  1,
2076
+									Ctime:                   advice.AdviceDate,
2077
+									Mtime:                   advice.AdviceDate,
2078
+									Remark:                  "",
2079
+									OrgId:                   advice.UserOrgId,
2080
+									Type:                    0,
2081
+									Manufacturer:            selfBasedrug.Manufacturer,
2082
+									Dealer:                  selfBasedrug.Dealer,
2083
+									RetailPrice:             0,
2084
+									RetailTotalPrice:        0,
2085
+									CountUnit:               advice.PrescribingNumberUnit,
2086
+									ExpiryDate:              0,
2087
+									ProductDate:             0,
2088
+									Number:                  "",
2089
+									BatchNumber:             "",
2090
+									IsSys:                   0,
2091
+									WarehouseInfoId:         0,
2092
+									AdminUserId:             0,
2093
+									StockCount:              "",
2094
+									IsCheck:                 1,
2095
+									SysRecordTime:           advice.AdviceDate,
2096
+									PatientId:               advice.PatientId,
2097
+									AdviceId:                advice.ID,
2098
+									ClassType:               "",
2099
+								}
2100
+								warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
2101
+
2102
+								for _, it := range warehousingOutInfo {
2103
+
2104
+									medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
2105
+									drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
2106
+									//出库逻辑
2107
+									service.AutoSelfDrugDeliverInfoFourtyTwo(adminInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
2108
+
2109
+									//查询剩余库存
2110
+									stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
2111
+									var sum_count int64
2112
+									for _, its := range stockInfo {
2113
+										if its.MaxUnit == medical.MaxUnit {
2114
+											its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
2115
+										}
2116
+										sum_count += its.StockMaxNumber + its.StockMinNumber
2117
+									}
2118
+									service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
2119
+								}
2120
+							}
2121
+
2122
+						} else {
2123
+							c.ServeSuccessJSON(map[string]interface{}{
2124
+								"msg":    "3",
2125
+								"advice": advice,
2126
+							})
2127
+							return
2128
+						}
2129
+
2130
+					}
2131
+
2132
+				}
2133
+
1818 2134
 				////针对异常未出库问题的脚本
1819 2135
 				//if adminInfo.Org.Id == 10598 {
1820 2136
 				//

+ 326 - 0
controllers/patient_api_controller.go Zobrazit soubor

@@ -2628,6 +2628,172 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2628 2628
 			}
2629 2629
 		}
2630 2630
 
2631
+		//自备药
2632
+		selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
2633
+
2634
+		if selfPrescriptionOutOpen.IsOpen == 1 {
2635
+
2636
+			db := service.XTWriteDB()
2637
+			tx := db.Begin()
2638
+			defer func() {
2639
+				if r := recover(); r != nil {
2640
+					tx.Rollback()
2641
+				} else {
2642
+					tx.Commit()
2643
+				}
2644
+			}()
2645
+
2646
+			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
2647
+
2648
+			fmt.Println("selfBasedrug-----------------------------------------", selfBasedrug.IsSelfDrug)
2649
+
2650
+			if selfBasedrug.IsSelfDrug == 1 {
2651
+
2652
+				//查询是否有库存
2653
+				info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
2654
+
2655
+				if len(info) > 0 {
2656
+					var total_count int64
2657
+					var prescribing_number_total int64
2658
+					for _, item := range info {
2659
+						if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
2660
+							item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
2661
+						}
2662
+
2663
+						total_count += item.StockMaxNumber + item.StockMinNumber
2664
+					}
2665
+
2666
+					//判断单位是否相等
2667
+					if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
2668
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2669
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2670
+						//转化为最小单位
2671
+						prescribing_number_total = count * selfBasedrug.MinNumber
2672
+					}
2673
+
2674
+					if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
2675
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2676
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2677
+						prescribing_number_total = count
2678
+
2679
+					}
2680
+
2681
+					if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
2682
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2683
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2684
+						prescribing_number_total = count
2685
+
2686
+					}
2687
+
2688
+					if prescribing_number_total > total_count {
2689
+						c.ServeSuccessJSON(map[string]interface{}{
2690
+							"msg":    "3",
2691
+							"advice": advice,
2692
+						})
2693
+						return
2694
+					}
2695
+					var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
2696
+					//出库
2697
+					if prescribing_number_total <= total_count {
2698
+						timeStr := time.Now().Format("2006-01-02")
2699
+						timeArr := strings.Split(timeStr, "-")
2700
+						total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
2701
+
2702
+						total = total + 1
2703
+						warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
2704
+						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
2705
+						number = number + total
2706
+						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
2707
+						operation_time := time.Now().Unix()
2708
+
2709
+						creater := c.GetAdminUserInfo().AdminUser.Id
2710
+						//创建一个出库单
2711
+						drugWarehouseOut := models.XtSelfDrugWarehouseOut{
2712
+							WarehouseOutOrderNumber: warehousing_out_order,
2713
+							OperationTime:           operation_time,
2714
+							OrgId:                   c.GetAdminUserInfo().CurrentOrgId,
2715
+							Creater:                 creater,
2716
+							Ctime:                   time.Now().Unix(),
2717
+							Status:                  1,
2718
+							WarehouseOutTime:        advice.AdviceDate,
2719
+							Type:                    0,
2720
+							PatientId:               advice.PatientId,
2721
+							IsCheck:                 1,
2722
+							IsSys:                   1,
2723
+						}
2724
+
2725
+						//查询今日是否有出库数据
2726
+						lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
2727
+
2728
+						if lastWarehouseOut.ID == 0 {
2729
+							service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
2730
+						}
2731
+						//出库
2732
+						warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
2733
+							WarehouseOutOrderNumber: warehousing_out_order,
2734
+							DrugId:                  advice.DrugId,
2735
+							Count:                   total_count,
2736
+							Price:                   0,
2737
+							TotalPrice:              0,
2738
+							Status:                  1,
2739
+							Ctime:                   advice.AdviceDate,
2740
+							Mtime:                   advice.AdviceDate,
2741
+							Remark:                  "",
2742
+							OrgId:                   advice.UserOrgId,
2743
+							Type:                    0,
2744
+							Manufacturer:            selfBasedrug.Manufacturer,
2745
+							Dealer:                  selfBasedrug.Dealer,
2746
+							RetailPrice:             0,
2747
+							RetailTotalPrice:        0,
2748
+							CountUnit:               advice.PrescribingNumberUnit,
2749
+							ExpiryDate:              0,
2750
+							ProductDate:             0,
2751
+							Number:                  "",
2752
+							BatchNumber:             "",
2753
+							IsSys:                   0,
2754
+							WarehouseInfoId:         0,
2755
+							AdminUserId:             0,
2756
+							StockCount:              "",
2757
+							IsCheck:                 1,
2758
+							SysRecordTime:           advice.AdviceDate,
2759
+							PatientId:               advice.PatientId,
2760
+							AdviceId:                advice.ID,
2761
+							ClassType:               "",
2762
+						}
2763
+						warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
2764
+
2765
+						for _, it := range warehousingOutInfo {
2766
+
2767
+							medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
2768
+							drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
2769
+							//出库逻辑
2770
+							service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
2771
+
2772
+							//查询剩余库存
2773
+							stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
2774
+							var sum_count int64
2775
+							for _, its := range stockInfo {
2776
+								if its.MaxUnit == medical.MaxUnit {
2777
+									its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
2778
+								}
2779
+								sum_count += its.StockMaxNumber + its.StockMinNumber
2780
+							}
2781
+							service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
2782
+						}
2783
+					}
2784
+
2785
+				} else {
2786
+					c.ServeSuccessJSON(map[string]interface{}{
2787
+						"msg":    "3",
2788
+						"advice": advice,
2789
+					})
2790
+					return
2791
+				}
2792
+
2793
+			}
2794
+
2795
+		}
2796
+
2631 2797
 		advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
2632 2798
 		for _, item := range advices {
2633 2799
 
@@ -3274,6 +3440,166 @@ func (c *PatientApiController) ExecDoctorAdvice() {
3274 3440
 			}
3275 3441
 
3276 3442
 		}
3443
+
3444
+		//自备药
3445
+
3446
+		selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
3447
+
3448
+		if selfPrescriptionOutOpen.IsOpen == 1 {
3449
+
3450
+			db := service.XTWriteDB()
3451
+			tx := db.Begin()
3452
+			defer func() {
3453
+				if r := recover(); r != nil {
3454
+					tx.Rollback()
3455
+				} else {
3456
+					tx.Commit()
3457
+				}
3458
+			}()
3459
+
3460
+			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
3461
+
3462
+			if selfBasedrug.IsSelfDrug == 1 {
3463
+
3464
+				//查询是否有库存
3465
+				info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
3466
+
3467
+				if len(info) > 0 {
3468
+					var total_count int64
3469
+					var prescribing_number_total int64
3470
+					for _, item := range info {
3471
+						if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
3472
+							item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
3473
+						}
3474
+
3475
+						total_count += item.StockMaxNumber + item.StockMinNumber
3476
+					}
3477
+
3478
+					//判断单位是否相等
3479
+					if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
3480
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
3481
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
3482
+						//转化为最小单位
3483
+						prescribing_number_total = count * selfBasedrug.MinNumber
3484
+					}
3485
+
3486
+					if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
3487
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
3488
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
3489
+						prescribing_number_total = count
3490
+
3491
+					}
3492
+
3493
+					if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
3494
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
3495
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
3496
+						prescribing_number_total = count
3497
+
3498
+					}
3499
+
3500
+					if prescribing_number_total > total_count {
3501
+						c.ServeSuccessJSON(map[string]interface{}{
3502
+							"msg":    "3",
3503
+							"advice": advice,
3504
+						})
3505
+						return
3506
+					}
3507
+					var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
3508
+					//出库
3509
+					if prescribing_number_total <= total_count {
3510
+						timeStr := time.Now().Format("2006-01-02")
3511
+						timeArr := strings.Split(timeStr, "-")
3512
+						total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
3513
+
3514
+						total = total + 1
3515
+						warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
3516
+						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3517
+						number = number + total
3518
+						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
3519
+						operation_time := time.Now().Unix()
3520
+
3521
+						creater := c.GetAdminUserInfo().AdminUser.Id
3522
+						//创建一个出库单
3523
+						drugWarehouseOut := models.XtSelfDrugWarehouseOut{
3524
+							WarehouseOutOrderNumber: warehousing_out_order,
3525
+							OperationTime:           operation_time,
3526
+							OrgId:                   c.GetAdminUserInfo().CurrentOrgId,
3527
+							Creater:                 creater,
3528
+							Ctime:                   time.Now().Unix(),
3529
+							Status:                  1,
3530
+							WarehouseOutTime:        advice.AdviceDate,
3531
+							Type:                    0,
3532
+							PatientId:               advice.PatientId,
3533
+							IsCheck:                 1,
3534
+							IsSys:                   1,
3535
+						}
3536
+
3537
+						//查询今日是否有出库数据
3538
+						lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
3539
+
3540
+						if lastWarehouseOut.ID == 0 {
3541
+							service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
3542
+						}
3543
+						//出库
3544
+						warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
3545
+							WarehouseOutOrderNumber: warehousing_out_order,
3546
+							DrugId:                  advice.DrugId,
3547
+							Count:                   total_count,
3548
+							Price:                   0,
3549
+							TotalPrice:              0,
3550
+							Status:                  1,
3551
+							Ctime:                   advice.AdviceDate,
3552
+							Mtime:                   advice.AdviceDate,
3553
+							Remark:                  "",
3554
+							OrgId:                   advice.UserOrgId,
3555
+							Type:                    0,
3556
+							Manufacturer:            selfBasedrug.Manufacturer,
3557
+							Dealer:                  selfBasedrug.Dealer,
3558
+							RetailPrice:             0,
3559
+							RetailTotalPrice:        0,
3560
+							CountUnit:               advice.PrescribingNumberUnit,
3561
+							ExpiryDate:              0,
3562
+							ProductDate:             0,
3563
+							Number:                  "",
3564
+							BatchNumber:             "",
3565
+							IsSys:                   0,
3566
+							WarehouseInfoId:         0,
3567
+							AdminUserId:             0,
3568
+							StockCount:              "",
3569
+							IsCheck:                 1,
3570
+							SysRecordTime:           advice.AdviceDate,
3571
+							PatientId:               advice.PatientId,
3572
+							AdviceId:                advice.ID,
3573
+							ClassType:               "",
3574
+						}
3575
+						warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
3576
+
3577
+						for _, it := range warehousingOutInfo {
3578
+
3579
+							medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
3580
+							drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
3581
+							//出库逻辑
3582
+							service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
3583
+
3584
+							//查询剩余库存
3585
+							stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
3586
+							var sum_count int64
3587
+							for _, its := range stockInfo {
3588
+								if its.MaxUnit == medical.MaxUnit {
3589
+									its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
3590
+								}
3591
+								sum_count += its.StockMaxNumber + its.StockMinNumber
3592
+							}
3593
+							service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
3594
+						}
3595
+					}
3596
+
3597
+				}
3598
+
3599
+			}
3600
+
3601
+		}
3602
+
3277 3603
 		c.ServeSuccessJSON(map[string]interface{}{
3278 3604
 			"msg":    "1",
3279 3605
 			"advice": advice,

+ 44 - 45
controllers/self_drug_api_congtroller.go Zobrazit soubor

@@ -180,6 +180,8 @@ func SelfDrugRouters() {
180 180
 	beego.Router("/api/drug/getallselfdrugwarehouseout", &SelfDrugApiController{}, "Get:GetAllSelfDrugWarehouseOut")
181 181
 
182 182
 	beego.Router("/api/drug/deleteselfwarehouseoutlist", &SelfDrugApiController{}, "Get:DeleteSelfWarehouseOutList")
183
+
184
+	beego.Router("/api/drug/getselfDrugwarehouseoutdetailbypatientid", &SelfDrugApiController{}, "Get:GetSelfDrugWarehouseOutDetailByPatientId")
183 185
 }
184 186
 
185 187
 func (this *SelfDrugApiController) GetCurrentPatient() {
@@ -4777,8 +4779,8 @@ func (c *SelfDrugApiController) GetAllSelfDrugWarehouseInfoList() {
4777 4779
 func (c *SelfDrugApiController) GetSelfDrugWarehouseInfoByID() {
4778 4780
 
4779 4781
 	id, _ := c.GetInt64("id")
4780
-	info, _ := service.GetSelfDrugWarehouseInfoByID(id)
4781
-	warehouseInfo, _ := service.GetSelfDrugWarehouseInfo(info.WarehousingId)
4782
+	info, _ := service.GetSelfDrugWarehouseInfoByIDOne(id)
4783
+	warehouseInfo, _ := service.GetSelfDrugWarehouseInfo(id)
4782 4784
 	orgId := c.GetAdminUserInfo().CurrentOrgId
4783 4785
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4784 4786
 	dealerList, _ := service.GetAllDealerList(orgId)
@@ -5446,18 +5448,21 @@ func (c *SelfDrugApiController) GetSelfDrugWarehouseOutById() {
5446 5448
 	id, _ := c.GetInt64("id")
5447 5449
 	orgId := c.GetAdminUserInfo().CurrentOrgId
5448 5450
 	outInfo, _ := service.GetSelfDrugWarehouseOutById(id)
5449
-
5451
+	outOne, _ := service.GetSelfDrugWarehouseOutOne(id)
5450 5452
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
5451 5453
 	dealerList, _ := service.GetAllDealerList(orgId)
5452 5454
 	var drugType = "药品类型"
5453 5455
 	drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
5454 5456
 	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
5455 5457
 
5458
+	patients, _ := service.GetAllpatient(orgId)
5456 5459
 	c.ServeSuccessJSON(map[string]interface{}{
5457 5460
 		"outInfo":          outInfo,
5458 5461
 		"manufacturerList": manufacturerList,
5459 5462
 		"dealerList":       dealerList,
5460 5463
 		"drugTypeList":     drugTypeList,
5464
+		"patients":         patients,
5465
+		"outOne":           outOne,
5461 5466
 	})
5462 5467
 }
5463 5468
 
@@ -5473,43 +5478,13 @@ func (c *SelfDrugApiController) ModifySelfDrugWarehouseOut() {
5473 5478
 		}
5474 5479
 	}()
5475 5480
 	patient_id, _ := c.GetInt64("patient_id")
5481
+	fmt.Println("patinet_id=-------------------------------", patient_id)
5476 5482
 	warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
5483
+	fmt.Println("patinet_id=-------------------------------", warehouse_out_id)
5477 5484
 	ctime := time.Now().Unix()
5478 5485
 	adminUserInfo := c.GetAdminUserInfo()
5479
-	warehousing_out_time := c.GetString("warehousing_out_time")
5480
-	warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_out_time)
5481
-	if parseDateErr != nil {
5482
-		c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
5483
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
5484
-		return
5485
-	}
5486
-	timeStr := time.Now().Format("2006-01-02")
5487
-	timeArr := strings.Split(timeStr, "-")
5488
-	total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.CurrentOrgId, tx)
5489 5486
 
5490
-	total = total + 1
5491
-	warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
5492
-	number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
5493
-	number = number + total
5494
-	warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
5495
-	operation_time := time.Now().Unix()
5496
-
5497
-	creater := adminUserInfo.AdminUser.Id
5498
-	//创建一个出库单
5499
-	warehouseOut := models.XtSelfDrugWarehouseOut{
5500
-		WarehouseOutOrderNumber: warehousing_out_order,
5501
-		OperationTime:           operation_time,
5502
-		OrgId:                   adminUserInfo.CurrentOrgId,
5503
-		Creater:                 creater,
5504
-		Ctime:                   ctime,
5505
-		Status:                  1,
5506
-		WarehouseOutTime:        warehousingOutDate.Unix(),
5507
-		Type:                    0,
5508
-		PatientId:               patient_id,
5509
-		IsCheck:                 2,
5510
-	}
5511
-
5512
-	lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOut(adminUserInfo.CurrentOrgId, tx)
5487
+	lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutOne(adminUserInfo.CurrentOrgId, tx)
5513 5488
 
5514 5489
 	dataBody := make(map[string]interface{}, 0)
5515 5490
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -5590,14 +5565,14 @@ func (c *SelfDrugApiController) ModifySelfDrugWarehouseOut() {
5590 5565
 
5591 5566
 				warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
5592 5567
 					ID:                      id,
5593
-					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5568
+					WarehouseOutOrderNumber: lastWarehouseOut.WarehouseOutOrderNumber,
5594 5569
 					WarehouseOutId:          lastWarehouseOut.ID,
5595 5570
 					DrugId:                  drug_id,
5596 5571
 					Count:                   count,
5597 5572
 					Price:                   0,
5598 5573
 					TotalPrice:              0,
5599 5574
 					Status:                  1,
5600
-					Ctime:                   warehousingOutDate.Unix(),
5575
+					Ctime:                   lastWarehouseOut.WarehouseOutTime,
5601 5576
 					Mtime:                   ctime,
5602 5577
 					Remark:                  remark,
5603 5578
 					OrgId:                   adminUserInfo.CurrentOrgId,
@@ -5616,7 +5591,7 @@ func (c *SelfDrugApiController) ModifySelfDrugWarehouseOut() {
5616 5591
 					AdminUserId:             0,
5617 5592
 					StockCount:              stock_count,
5618 5593
 					IsCheck:                 2,
5619
-					SysRecordTime:           warehousingOutDate.Unix(),
5594
+					SysRecordTime:           lastWarehouseOut.WarehouseOutTime,
5620 5595
 					PatientId:               patient_id,
5621 5596
 					ClassType:               class_type,
5622 5597
 				}
@@ -5667,8 +5642,6 @@ func (c *SelfDrugApiController) ModifySelfDrugWarehouseOut() {
5667 5642
 func (c *SelfDrugApiController) GetSelfDrugQuery() {
5668 5643
 
5669 5644
 	keyword := c.GetString("keyword")
5670
-	limit, _ := c.GetInt64("limit")
5671
-	page, _ := c.GetInt64("page")
5672 5645
 	var goodIds []int64
5673 5646
 	org_id := c.GetAdminUserInfo().CurrentOrgId
5674 5647
 	drugList, _ := service.GetDrugNameByword(org_id, keyword)
@@ -5676,7 +5649,7 @@ func (c *SelfDrugApiController) GetSelfDrugQuery() {
5676 5649
 	for _, it := range drugList {
5677 5650
 		goodIds = append(goodIds, it.ID)
5678 5651
 	}
5679
-	list, total, _ := service.GetSelfDrugQuery(orgId, goodIds, limit, page)
5652
+	list, total, _ := service.GetSelfDrugQuery(orgId, goodIds)
5680 5653
 	var drugType = "药品类型"
5681 5654
 	drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
5682 5655
 	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, org_id)
@@ -5985,6 +5958,7 @@ func (c *SelfDrugApiController) GetSelfDrugFlow() {
5985 5958
 	orgId := c.GetAdminUserInfo().CurrentOrgId
5986 5959
 	page, _ := c.GetInt64("page")
5987 5960
 	limit, _ := c.GetInt64("limit")
5961
+	patient_id, _ := c.GetInt64("patient_id")
5988 5962
 	timeLayout := "2006-01-02"
5989 5963
 	loc, _ := time.LoadLocation("Local")
5990 5964
 	var startTime int64
@@ -6007,7 +5981,7 @@ func (c *SelfDrugApiController) GetSelfDrugFlow() {
6007 5981
 		}
6008 5982
 		endTime = theTime.Unix()
6009 5983
 	}
6010
-	list, total, _ := service.GetSelfDrugFlow(drug_id, startTime, endTime, orgId, page, limit)
5984
+	list, total, _ := service.GetSelfDrugFlow(drug_id, startTime, endTime, orgId, page, limit, patient_id)
6011 5985
 	drug, _ := service.GetSelfBasedrugById(drug_id, orgId)
6012 5986
 	patients, _ := service.GetAllpatient(orgId)
6013 5987
 	c.ServeSuccessJSON(map[string]interface{}{
@@ -6026,6 +6000,7 @@ func (c *SelfDrugApiController) GetSelfDrugBatchNumberList() {
6026 6000
 	orgId := c.GetAdminUserInfo().CurrentOrgId
6027 6001
 	page, _ := c.GetInt64("page")
6028 6002
 	limit, _ := c.GetInt64("limit")
6003
+	patient_id, _ := c.GetInt64("patient_id")
6029 6004
 	timeLayout := "2006-01-02"
6030 6005
 	loc, _ := time.LoadLocation("Local")
6031 6006
 	var startTime int64
@@ -6049,7 +6024,7 @@ func (c *SelfDrugApiController) GetSelfDrugBatchNumberList() {
6049 6024
 		endTime = theTime.Unix()
6050 6025
 	}
6051 6026
 
6052
-	list, total, _ := service.GetSelfDrugBatchNumberList(drug_id, startTime, endTime, orgId, page, limit)
6027
+	list, total, _ := service.GetSelfDrugBatchNumberList(drug_id, startTime, endTime, orgId, page, limit, patient_id)
6053 6028
 	drug, _ := service.GetSelfBasedrugById(drug_id, orgId)
6054 6029
 	c.ServeSuccessJSON(map[string]interface{}{
6055 6030
 		"list":  list,
@@ -6132,6 +6107,7 @@ func (c *SelfDrugApiController) GetAllSelfDrugWarehouseOut() {
6132 6107
 	appId := c.GetAdminUserInfo().CurrentAppId
6133 6108
 	page, _ := c.GetInt64("page")
6134 6109
 	limit, _ := c.GetInt64("limit")
6110
+	check_type, _ := c.GetInt64("check_type")
6135 6111
 	patient_id, _ := c.GetInt64("patient_id")
6136 6112
 	timeLayout := "2006-01-02"
6137 6113
 	loc, _ := time.LoadLocation("Local")
@@ -6156,7 +6132,7 @@ func (c *SelfDrugApiController) GetAllSelfDrugWarehouseOut() {
6156 6132
 		endTime = theTime.Unix()
6157 6133
 	}
6158 6134
 
6159
-	list, total, _ := service.GetAllSelfDrugWarehouseOut(startTime, endTime, orgId, page, limit, patient_id, keyword)
6135
+	list, total, _ := service.GetAllSelfDrugWarehouseOut(startTime, endTime, orgId, page, limit, patient_id, keyword, check_type)
6160 6136
 	doctorList, _ := service.GetAllDoctorList(orgId, appId)
6161 6137
 	c.ServeSuccessJSON(map[string]interface{}{
6162 6138
 		"list":       list,
@@ -6176,3 +6152,26 @@ func (c *SelfDrugApiController) DeleteSelfWarehouseOutList() {
6176 6152
 		"ok": "msg",
6177 6153
 	})
6178 6154
 }
6155
+
6156
+func (c *SelfDrugApiController) GetSelfDrugWarehouseOutDetailByPatientId() {
6157
+
6158
+	patient_id, _ := c.GetInt64("patient_id")
6159
+
6160
+	page, _ := c.GetInt64("page")
6161
+
6162
+	limit, _ := c.GetInt64("limit")
6163
+
6164
+	orgId := c.GetAdminUserInfo().CurrentOrgId
6165
+
6166
+	list, total, _ := service.GetSelfDrugWarehouseOutDetailByPatientId(patient_id, page, limit, orgId)
6167
+
6168
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
6169
+	dealerList, _ := service.GetAllDealerList(orgId)
6170
+
6171
+	c.ServeSuccessJSON(map[string]interface{}{
6172
+		"list":             list,
6173
+		"total":            total,
6174
+		"manufacturerList": manufacturerList,
6175
+		"dealerList":       dealerList,
6176
+	})
6177
+}

+ 13 - 0
service/dialysis_service.go Zobrazit soubor

@@ -2563,3 +2563,16 @@ func ModfiyReduceDialysisAuto(patient_id int64, record_date int64, count int64,
2563 2563
 	}
2564 2564
 	return err
2565 2565
 }
2566
+
2567
+func GetHisExecutionDoctorsThree(orgid int64, patientid int64, id int64, tx *gorm.DB) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) {
2568
+
2569
+	err = tx.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and patient_id = ? AND id = ? and status = 1 and execution_state = 1", orgid, patientid, id).Find(&doctorAdvice).Error
2570
+
2571
+	if err != gorm.ErrRecordNotFound {
2572
+		if err != nil {
2573
+			tx.Rollback()
2574
+			return doctorAdvice, err
2575
+		}
2576
+	}
2577
+	return doctorAdvice, err
2578
+}

+ 105 - 12
service/self_drug_service.go Zobrazit soubor

@@ -3649,6 +3649,13 @@ func GetSelfDrugWarehouseInfoByID(id int64) (models.XtSelfDrugWarehouseInfo, err
3649 3649
 	return selfDrugWarehouseInfo, err
3650 3650
 }
3651 3651
 
3652
+func GetSelfDrugWarehouseInfoByIDOne(id int64) (selfDrugWarehouseInfo []*models.XtSelfDrugWarehouseInfo, err error) {
3653
+
3654
+	err = XTReadDB().Where("warehousing_id = ? and status=1", id).Preload("BaseDrugLib", "status=1").Find(&selfDrugWarehouseInfo).Error
3655
+
3656
+	return selfDrugWarehouseInfo, err
3657
+}
3658
+
3652 3659
 func GetSelfDrugWarehouseInfo(id int64) (models.XtSelfDrugWarehouse, error) {
3653 3660
 
3654 3661
 	warehouse := models.XtSelfDrugWarehouse{}
@@ -3812,23 +3819,30 @@ func DeleteSelfWarehouseOut(id int64) (models.XtSelfDrugWarehouseOutInfo, error)
3812 3819
 	return outInfo, err
3813 3820
 }
3814 3821
 
3815
-func GetSelfDrugWarehouseOutById(id int64) (models.XtSelfDrugWarehouseOutInfo, error) {
3822
+func GetSelfDrugWarehouseOutById(id int64) (outInfo []*models.XtSelfDrugWarehouseOutInfo, err error) {
3816 3823
 
3817
-	outInfo := models.XtSelfDrugWarehouseOutInfo{}
3818 3824
 	err = XTReadDB().Where("warehouse_out_id = ? and status =1", id).Preload("BaseDrugLib", "status=1").Find(&outInfo).Error
3819 3825
 
3820 3826
 	return outInfo, err
3821 3827
 }
3822 3828
 
3823
-func GetSelfDrugQuery(user_org_id int64, ids []int64, limit int64, page int64) (drug []*models.XtSelfDrugStockCount, total int64, err error) {
3829
+func GetSelfDrugWarehouseOutOne(id int64) (models.XtSelfDrugWarehouseOut, error) {
3830
+
3831
+	out := models.XtSelfDrugWarehouseOut{}
3832
+	err = XTReadDB().Where("id = ? and status =1", id).Find(&out).Error
3833
+
3834
+	return out, err
3835
+}
3836
+
3837
+func GetSelfDrugQuery(user_org_id int64, ids []int64) (drug []*models.XtSelfDrugStockCount, total int64, err error) {
3824 3838
 
3825 3839
 	db := XTReadDB().Model(&drug).Where("status=1")
3826
-	offset := (page - 1) * limit
3840
+
3827 3841
 	if len(ids) > 0 {
3828 3842
 		db = db.Where("drug_id in(?)", ids)
3829 3843
 	}
3830 3844
 
3831
-	err = db.Count(&total).Offset(offset).Limit(limit).Where("user_org_id = ? and status=1", user_org_id).Preload("BaseDrugLib", "org_id = ? and status =1", user_org_id).Find(&drug).Error
3845
+	err = db.Count(&total).Where("user_org_id = ? and status=1", user_org_id).Preload("BaseDrugLib", "org_id = ? and status =1", user_org_id).Find(&drug).Error
3832 3846
 
3833 3847
 	return drug, total, err
3834 3848
 }
@@ -4185,7 +4199,7 @@ func ReduceSelfDrugStockCount(patient_id int64, drug_id int64, user_org_id int64
4185 4199
 
4186 4200
 func ReturnSelfCheckWarehouseingInfo(id int64, orgid int64, tx *gorm.DB) error {
4187 4201
 
4188
-	err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
4202
+	err := tx.Model(&models.XtSelfDrugWarehouse{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
4189 4203
 	if err != nil {
4190 4204
 		tx.Rollback()
4191 4205
 		return err
@@ -4208,13 +4222,16 @@ func CheckSelfWarehousingInfo(id int64, orgid int64, checker int64, tx *gorm.DB)
4208 4222
 	return err
4209 4223
 }
4210 4224
 
4211
-func GetSelfDrugFlow(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
4225
+func GetSelfDrugFlow(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64, patient_id int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
4212 4226
 
4213 4227
 	db := XTReadDB().Model(&flow).Where("status=1")
4214 4228
 
4215 4229
 	if drug_id > 0 {
4216 4230
 		db = db.Where("drug_id =?", drug_id)
4217 4231
 	}
4232
+	if patient_id > 0 {
4233
+		db = db.Where("patient_id = ?", patient_id)
4234
+	}
4218 4235
 	if start_time > 0 {
4219 4236
 		db = db.Where("ctime>=?", start_time)
4220 4237
 	}
@@ -4241,7 +4258,7 @@ func GetSelfBasedrugById(drug_id int64, user_org_id int64) (models.BaseDrugLib,
4241 4258
 	return lib, err
4242 4259
 }
4243 4260
 
4244
-func GetSelfDrugBatchNumberList(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
4261
+func GetSelfDrugBatchNumberList(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64, patient_id int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
4245 4262
 
4246 4263
 	db := XTReadDB().Model(&flow).Where("status=1 and consumable_type =1")
4247 4264
 
@@ -4257,6 +4274,9 @@ func GetSelfDrugBatchNumberList(drug_id int64, start_time int64, end_time int64,
4257 4274
 	if user_org_id > 0 {
4258 4275
 		db = db.Where("user_org_id =?", user_org_id)
4259 4276
 	}
4277
+	if patient_id > 0 {
4278
+		db = db.Where("patient_id = ?", patient_id)
4279
+	}
4260 4280
 
4261 4281
 	offset := (page - 1) * limit
4262 4282
 
@@ -4308,7 +4328,7 @@ func DeleteSelfWarehouse(id int64) error {
4308 4328
 	return err
4309 4329
 }
4310 4330
 
4311
-func GetAllSelfDrugWarehouseOut(start_time int64, end_time int64, org_id int64, page int64, limit int64, patient_id int64, keyword string) (out []*models.XtSelfDrugWarehouseOut, total int64, err error) {
4331
+func GetAllSelfDrugWarehouseOut(start_time int64, end_time int64, org_id int64, page int64, limit int64, patient_id int64, keyword string, check_type int64) (out []*models.XtSelfDrugWarehouseOut, total int64, err error) {
4312 4332
 
4313 4333
 	db := XTReadDB().Model(&out).Where("status=1")
4314 4334
 	offset := (page - 1) * limit
@@ -4333,6 +4353,9 @@ func GetAllSelfDrugWarehouseOut(start_time int64, end_time int64, org_id int64,
4333 4353
 	if patient_id > 0 {
4334 4354
 		db = db.Where("patient_id = ?", patient_id)
4335 4355
 	}
4356
+	if check_type > 0 {
4357
+		db = db.Where("is_check=?", check_type)
4358
+	}
4336 4359
 
4337 4360
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("operation_time desc").Find(&out).Error
4338 4361
 
@@ -4343,7 +4366,7 @@ func DeleteSelfWarehouseOutList(id int64) (models.XtSelfDrugWarehouseOut, error)
4343 4366
 
4344 4367
 	warehouseOut := models.XtSelfDrugWarehouseOut{}
4345 4368
 
4346
-	err := XTWriteDB().Model(&warehouseOut).Where("id = ? an status=1", id).Updates(map[string]interface{}{"status": 0}).Error
4369
+	err := XTWriteDB().Model(&warehouseOut).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
4347 4370
 
4348 4371
 	err = XTWriteDB().Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
4349 4372
 
@@ -4404,9 +4427,9 @@ func GetSelfDrugWarehouseOutDrugFlow(patient_id int64, drug_id int64, user_org_i
4404 4427
 	return flow, err
4405 4428
 }
4406 4429
 
4407
-func GetSelfDrugLastWarehouseOutTwety(orgid int64, record_date int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOut, error) {
4430
+func GetSelfDrugLastWarehouseOutTwety(orgid int64, record_date int64, tx *gorm.DB, is_sys int64) (models.XtSelfDrugWarehouseOut, error) {
4408 4431
 	out := models.XtSelfDrugWarehouseOut{}
4409
-	err := tx.Where("org_id = ? and status = 1 and warehouse_out_time = ?", orgid, record_date).Find(&out).Error
4432
+	err := tx.Where("org_id = ? and status = 1 and warehouse_out_time = ? and is_sys =?", orgid, record_date, is_sys).Find(&out).Error
4410 4433
 	if err != gorm.ErrRecordNotFound {
4411 4434
 		if err != nil {
4412 4435
 			tx.Rollback()
@@ -4416,3 +4439,73 @@ func GetSelfDrugLastWarehouseOutTwety(orgid int64, record_date int64, tx *gorm.D
4416 4439
 	}
4417 4440
 	return out, err
4418 4441
 }
4442
+
4443
+func GetSelfHisPrescriptionAdviceByID(id int64, tx *gorm.DB) (advices []*models.HisDoctorAdviceInfo, err error) {
4444
+	err = tx.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
4445
+
4446
+	if err != gorm.ErrRecordNotFound {
4447
+		if err != nil {
4448
+			tx.Rollback()
4449
+			return advices, err
4450
+		}
4451
+	}
4452
+	return
4453
+}
4454
+
4455
+func GetSelfNewDrugWarehouseOutInfoSix(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64, warehouse_info_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
4456
+
4457
+	info := models.DrugWarehouseOutInfo{}
4458
+	var err error
4459
+	err = tx.Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", drugid, patient_id, record_date, org_id, advice_id, warehouse_info_id).Find(&info).Error
4460
+
4461
+	if err != gorm.ErrRecordNotFound {
4462
+		if err != nil {
4463
+			tx.Rollback()
4464
+			return info, err
4465
+		}
4466
+	}
4467
+
4468
+	return info, err
4469
+}
4470
+
4471
+func UpdateSelfDrugWarehouseOutInfoTen(patient_id int64, sys_record_time int64, advice_id int64, tx *gorm.DB) error {
4472
+
4473
+	err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("patient_id = ? and sys_record_time  = ? and status=1 and advice_id = ?", patient_id, sys_record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
4474
+
4475
+	if err != nil {
4476
+		tx.Rollback()
4477
+		return err
4478
+	}
4479
+	return err
4480
+}
4481
+
4482
+func GetSelfWarehouseInfoByWarehouseInfoTwo(drug_id int64, patient_id int64, org_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
4483
+
4484
+	err = tx.Where("drug_id =? and patient_id =? and status=1 and org_id =?", drug_id, patient_id, org_id).Find(&info).Error
4485
+
4486
+	if err != gorm.ErrRecordNotFound {
4487
+		if err != nil {
4488
+			tx.Rollback()
4489
+			return info, err
4490
+		}
4491
+	}
4492
+	return info, err
4493
+}
4494
+
4495
+func GetSelfDrugWarehouseOutDetailByPatientId(patient_id int64, page int64, limit int64, user_org_id int64) (out []*models.XtSelfDrugStockCount, total int64, err error) {
4496
+
4497
+	db := XTReadDB().Model(&out).Where("status=1")
4498
+
4499
+	if patient_id > 0 {
4500
+		db = db.Where("patient_id = ?", patient_id)
4501
+	}
4502
+	if user_org_id > 0 {
4503
+		db = db.Where("user_org_id = ?", user_org_id)
4504
+	}
4505
+
4506
+	offset := (page - 1) * limit
4507
+
4508
+	err = db.Count(&total).Offset(offset).Limit(limit).Preload("BaseDrugLib", "status=1 and org_id = ?", user_org_id).Find(&out).Error
4509
+
4510
+	return out, total, err
4511
+}

+ 13 - 0
service/stock_service.go Zobrazit soubor

@@ -8211,6 +8211,19 @@ func GetSelfDrugLastWarehouseOut(orgid int64, tx *gorm.DB) (models.XtSelfDrugWar
8211 8211
 	return out, err
8212 8212
 }
8213 8213
 
8214
+func GetSelfDrugLastWarehouseOutOne(id int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOut, error) {
8215
+	out := models.XtSelfDrugWarehouseOut{}
8216
+	err := tx.Where("id = ? and status = 1", id).Find(&out).Error
8217
+	if err != gorm.ErrRecordNotFound {
8218
+		if err != nil {
8219
+			tx.Rollback()
8220
+			return out, err
8221
+		}
8222
+
8223
+	}
8224
+	return out, err
8225
+}
8226
+
8214 8227
 func GetDrugWarehouseOutListById(warehouse_out_id int64, orgId int64) (info []*models.DrugWarehouseOutInfo, err error) {
8215 8228
 
8216 8229
 	err = XTReadDB().Where("warehouse_out_id = ? and org_id  =? and status = 1", warehouse_out_id, orgId).Preload("BaseDrugLib", "status=1").Find(&info).Error

+ 372 - 3
service/warhouse_service.go Zobrazit soubor

@@ -9910,6 +9910,22 @@ func AutoSelfDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, ware
9910 9910
 			over_count += its.StockMaxNumber + its.StockMinNumber
9911 9911
 		}
9912 9912
 
9913
+		//更新出库id
9914
+		//查询今日该药品该患者是否有出库数据
9915
+		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
9916
+
9917
+		if lastDrugOutInfo.ID == 0 {
9918
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
9919
+		}
9920
+		if lastDrugOutInfo.ID > 0 {
9921
+
9922
+			//删除在新增
9923
+			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
9924
+
9925
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
9926
+
9927
+		}
9928
+
9913 9929
 		drugWareInfo, _ := GetSelfLastWarehouseOutInfoById(advice.DrugId, tx)
9914 9930
 		drugflow := models.XtSelfDrugFlow{
9915 9931
 			WarehouseOutId:          warehouseout.ID,
@@ -9954,8 +9970,12 @@ func AutoSelfDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, ware
9954 9970
 
9955 9971
 		CreateSelfDrugFlowOne(drugflow, tx)
9956 9972
 
9957
-		//更新出库id
9958
-		UpdateSelfDrugWarehouseOutInfo(advice.ID, warehouse.ID, advice.OrgId, over_count, drug_price, tx)
9973
+		//出库数量相加
9974
+		AddSelfDrugCount(advice.DrugId, orgID, advice.PatientId, drugflow.Count, tx)
9975
+
9976
+		fmt.Println("advice-------------------------------------", advice.ID)
9977
+		fmt.Println("warehouse-------------------------------------", warehouse.ID)
9978
+		fmt.Println("over_count====================================", over_count)
9959 9979
 
9960 9980
 		return nil
9961 9981
 
@@ -9982,6 +10002,20 @@ func AutoSelfDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, ware
9982 10002
 			}
9983 10003
 			over_count += its.StockMaxNumber + its.StockMinNumber
9984 10004
 		}
10005
+		//查询今日该药品该患者是否有出库数据
10006
+		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
10007
+
10008
+		if lastDrugOutInfo.ID == 0 {
10009
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10010
+		}
10011
+		if lastDrugOutInfo.ID > 0 {
10012
+
10013
+			//删除在新增
10014
+			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
10015
+
10016
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10017
+
10018
+		}
9985 10019
 		drugWareInfo, _ := GetSelfLastWarehouseOutInfoById(advice.DrugId, tx)
9986 10020
 		drugflow := models.XtSelfDrugFlow{
9987 10021
 			WarehouseOutId:          warehouseout.ID,
@@ -10022,8 +10056,343 @@ func AutoSelfDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, ware
10022 10056
 		}
10023 10057
 
10024 10058
 		CreateSelfDrugFlowOne(drugflow, tx)
10059
+
10060
+		AddSelfDrugCount(advice.DrugId, orgID, advice.PatientId, drugflow.Count, tx)
10061
+		// 出库完成后,要将该批次库存清零
10062
+
10063
+		prescribingNumber_two_temp := deliver_number - stock_number
10064
+
10065
+		advice.CountUnit = drup.MinUnit
10066
+
10067
+		AutoSelfDrugDeliverInfoFourtyOne(orgID, prescribingNumber_two_temp, warehouseout, drup, advice, unit, tx)
10068
+	}
10069
+
10070
+	return
10071
+}
10072
+
10073
+// 药品手动出库 递归方式
10074
+func AutoSelfDrugDeliverInfoFourtyTwo(orgID int64, prescribingNumber int64, warehouseout *models.XtSelfDrugWarehouseOut, drup *models.BaseDrugLib, advice *models.XtSelfDrugWarehouseOutInfo, unit string, tx *gorm.DB) (err error) {
10075
+
10076
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
10077
+	var deliver_number int64 = 0
10078
+
10079
+	var stock_number int64 = 0
10080
+
10081
+	var drug_price float64
10082
+	if advice.CountUnit == drup.MaxUnit {
10083
+		deliver_number = prescribingNumber * drup.MinNumber
10084
+
10085
+	} else {
10086
+		deliver_number = prescribingNumber
10087
+
10088
+	}
10089
+	if advice.CountUnit == drup.MaxUnit {
10090
+		drug_price = drup.RetailPrice
10091
+	}
10092
+	fmt.Println(drug_price)
10093
+
10094
+	if advice.CountUnit == drup.MinUnit {
10095
+		drug_price = drup.MinPrice
10096
+	}
10097
+
10098
+	if advice.CountUnit != drup.MaxUnit || advice.CountUnit != drup.MinUnit {
10099
+		drug_price = drup.RetailPrice
10100
+	}
10101
+
10102
+	// 根据先进先出原则,查询最先入库的批次,进行出库
10103
+	// 如果没有对应的库存,则报错
10104
+	lastWarehouse, _ := FindSelfLastDrugWarehousingInfoByID(advice.DrugId, advice.PatientId, tx)
10105
+
10106
+	if lastWarehouse.MaxUnit != lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
10107
+		if lastWarehouse.StockMinNumber >= drup.MinNumber {
10108
+			var stockMax int64
10109
+			var stockMin int64
10110
+			stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
10111
+			stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
10112
+
10113
+			ChangeSelfMaxNumber(lastWarehouse.ID, stockMax, tx)
10114
+			UpdateSelfMinNumber(lastWarehouse.ID, stockMin, tx)
10115
+
10116
+		}
10117
+	}
10118
+
10119
+	if lastWarehouse.MaxUnit == lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
10120
+
10121
+		lastWarehouse.StockMaxNumber = lastWarehouse.StockMaxNumber + lastWarehouse.StockMinNumber
10122
+		ChangeSelfMaxNumberOne(lastWarehouse.ID, lastWarehouse.StockMaxNumber, tx)
10123
+
10124
+	}
10125
+
10126
+	warehouse, err := FindSelfLastDrugWarehousingInfoByID(advice.DrugId, advice.PatientId, tx)
10127
+
10128
+	// 将该批次的剩余库存数量转换为拆零数量
10129
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
10130
+
10131
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
10132
+
10133
+	}
10134
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
10135
+
10136
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
10137
+
10138
+	}
10139
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
10140
+
10141
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
10142
+
10143
+	}
10144
+	if stock_number >= deliver_number {
10145
+
10146
+		var maxNumber int64 = 0
10147
+		var minNumber int64 = 0
10148
+
10149
+		maxNumber = deliver_number / drup.MinNumber
10150
+		minNumber = deliver_number % drup.MinNumber
10151
+
10152
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
10153
+			minNumber = maxNumber
10154
+		}
10155
+
10156
+		if drup.MaxUnit != drup.MinUnit {
10157
+			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
10158
+				return errors.New("库存数量不足")
10159
+			}
10160
+		}
10161
+
10162
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
10163
+
10164
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
10165
+		}
10166
+
10167
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
10168
+
10169
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
10170
+		}
10171
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
10172
+
10173
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
10174
+		}
10175
+
10176
+		if warehouse.StockMaxNumber < 0 {
10177
+			warehouse.StockMaxNumber = 0
10178
+		}
10179
+		if warehouse.StockMinNumber < 0 {
10180
+			warehouse.StockMinNumber = 0
10181
+		}
10182
+
10183
+		warehouse.Mtime = time.Now().Unix()
10184
+
10185
+		if warehouse.StockMinNumber < minNumber {
10186
+			//fmt.Println("金4")
10187
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
10188
+			if warehouse.MaxUnit != warehouse.MinUnit {
10189
+				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
10190
+			}
10191
+			if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
10192
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
10193
+			}
10194
+		} else {
10195
+			//fmt.Println("金5")
10196
+			if minNumber > 0 {
10197
+				if (warehouse.StockMinNumber - minNumber) >= 0 {
10198
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
10199
+				}
10200
+
10201
+			}
10202
+
10203
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
10204
+				//fmt.Println("6")
10205
+				if warehouse.StockMinNumber > 0 {
10206
+					if warehouse.StockMinNumber-deliver_number >= 0 {
10207
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
10208
+					}
10209
+
10210
+				}
10211
+
10212
+			}
10213
+
10214
+		}
10215
+
10216
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
10217
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
10218
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
10219
+			}
10220
+
10221
+		}
10222
+
10223
+		if drup.MaxUnit != drup.MinUnit {
10224
+			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
10225
+				return errors.New("库存数量不足")
10226
+			}
10227
+		}
10228
+		if warehouse.StockMinNumber <= 0 {
10229
+			warehouse.StockMinNumber = 0
10230
+		}
10231
+
10232
+		errThree := UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
10233
+
10234
+		if errThree != nil {
10235
+			return errors.New("扣减库存失败")
10236
+		}
10237
+
10238
+		//查询该药品剩余库存
10239
+		infolist, _ := FindSelfDrugWarehouseInfoFlushCount(advice.DrugId, advice.OrgId, tx)
10240
+		var over_count int64
10241
+		for _, its := range infolist {
10242
+			if its.MaxUnit == drup.MaxUnit {
10243
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
10244
+			}
10245
+			over_count += its.StockMaxNumber + its.StockMinNumber
10246
+		}
10247
+
10025 10248
 		//更新出库id
10026
-		UpdateSelfDrugWarehouseOutInfo(advice.ID, warehouse.ID, advice.OrgId, over_count, drug_price, tx)
10249
+		//查询今日该药品该患者是否有出库数据
10250
+		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
10251
+
10252
+		if lastDrugOutInfo.ID == 0 {
10253
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10254
+		}
10255
+		if lastDrugOutInfo.ID > 0 {
10256
+
10257
+			//删除在新增
10258
+			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
10259
+
10260
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10261
+
10262
+		}
10263
+
10264
+		drugWareInfo, _ := GetSelfLastWarehouseOutInfoById(advice.DrugId, tx)
10265
+		drugflow := models.XtSelfDrugFlow{
10266
+			WarehouseOutId:          warehouseout.ID,
10267
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
10268
+			DrugId:                  advice.DrugId,
10269
+			Number:                  warehouse.Number,
10270
+			ProductDate:             advice.ProductDate,
10271
+			ExpireDate:              advice.ExpiryDate,
10272
+			Count:                   deliver_number,
10273
+			Price:                   warehouse.RetailPrice,
10274
+			Status:                  1,
10275
+			Ctime:                   advice.SysRecordTime,
10276
+			Mtime:                   time.Now().Unix(),
10277
+			UserOrgId:               advice.OrgId,
10278
+			Manufacturer:            advice.Manufacturer,
10279
+			Dealer:                  advice.Dealer,
10280
+			BatchNumber:             warehouse.BatchNumber,
10281
+			MaxUnit:                 drup.MinUnit,
10282
+			ConsumableType:          3,
10283
+			IsEdit:                  1,
10284
+			Creator:                 0,
10285
+			IsSys:                   0,
10286
+			WarehouseOutDetailId:    drugWareInfo.ID,
10287
+			AdviceId:                advice.ID,
10288
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
10289
+			StorehouseId:            advice.StorehouseId,
10290
+			AdminUserId:             advice.AdminUserId,
10291
+			LastPrice:               warehouse.Price,
10292
+			StockCount:              advice.StockCount,
10293
+			WarehousingDetailId:     warehouse.ID,
10294
+			OverCount:               over_count,
10295
+			RetailPrice:             drug_price, //手动出库出库价格
10296
+			WarehousingId:           warehouse.ID,
10297
+			SystemTime:              advice.SysRecordTime,
10298
+			PatientId:               advice.PatientId,
10299
+			Remark:                  advice.Remark,
10300
+			OperateTime:             time.Now().Unix(),
10301
+		}
10302
+		if warehouse.RetailPrice == 0 {
10303
+			drugflow.Price = advice.Price
10304
+		}
10305
+
10306
+		CreateSelfDrugFlowOne(drugflow, tx)
10307
+
10308
+		//出库数量相加
10309
+		AddSelfDrugCount(advice.DrugId, orgID, advice.PatientId, drugflow.Count, tx)
10310
+
10311
+		fmt.Println("advice-------------------------------------", advice.ID)
10312
+		fmt.Println("warehouse-------------------------------------", warehouse.ID)
10313
+		fmt.Println("over_count====================================", over_count)
10314
+
10315
+		return nil
10316
+
10317
+	} else {
10318
+		stock_number_int := strconv.FormatInt(stock_number, 10)
10319
+		stock_number_int_count, _ := strconv.ParseFloat(stock_number_int, 64)
10320
+		drug_price = stock_number_int_count * advice.Price
10321
+		//扣减库存
10322
+		warehouse.StockMaxNumber = 0
10323
+		warehouse.StockMinNumber = 0
10324
+		warehouse.Mtime = time.Now().Unix()
10325
+
10326
+		errThree := UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
10327
+		if errThree != nil {
10328
+			return errThree
10329
+		}
10330
+
10331
+		//查询该药品剩余库存
10332
+		infolist, _ := FindDrugWarehouseInfoFlushCount(advice.DrugId, advice.OrgId)
10333
+		var over_count int64
10334
+		for _, its := range infolist {
10335
+			if its.MaxUnit == drup.MaxUnit {
10336
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
10337
+			}
10338
+			over_count += its.StockMaxNumber + its.StockMinNumber
10339
+		}
10340
+		//查询今日该药品该患者是否有出库数据
10341
+		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
10342
+
10343
+		if lastDrugOutInfo.ID == 0 {
10344
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10345
+		}
10346
+		if lastDrugOutInfo.ID > 0 {
10347
+
10348
+			//删除在新增
10349
+			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
10350
+
10351
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10352
+
10353
+		}
10354
+		drugWareInfo, _ := GetSelfLastWarehouseOutInfoById(advice.DrugId, tx)
10355
+		drugflow := models.XtSelfDrugFlow{
10356
+			WarehouseOutId:          warehouseout.ID,
10357
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
10358
+			DrugId:                  advice.DrugId,
10359
+			Number:                  warehouse.Number,
10360
+			ProductDate:             advice.ProductDate,
10361
+			ExpireDate:              advice.ExpiryDate,
10362
+			Count:                   stock_number,
10363
+			Price:                   warehouse.RetailPrice,
10364
+			Status:                  1,
10365
+			Ctime:                   advice.SysRecordTime,
10366
+			Mtime:                   time.Now().Unix(),
10367
+			UserOrgId:               advice.OrgId,
10368
+			Manufacturer:            advice.Manufacturer,
10369
+			Dealer:                  advice.Dealer,
10370
+			BatchNumber:             warehouse.BatchNumber,
10371
+			MaxUnit:                 drup.MinUnit,
10372
+			ConsumableType:          3,
10373
+			IsEdit:                  1,
10374
+			Creator:                 0,
10375
+			IsSys:                   0,
10376
+			WarehouseOutDetailId:    drugWareInfo.ID,
10377
+			AdviceId:                advice.ID,
10378
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
10379
+			StorehouseId:            advice.StorehouseId,
10380
+			AdminUserId:             advice.AdminUserId,
10381
+			LastPrice:               warehouse.Price,
10382
+			StockCount:              advice.StockCount,
10383
+			OverCount:               over_count,
10384
+			RetailPrice:             drug_price, //手动出库出库价格
10385
+			WarehousingId:           warehouse.ID,
10386
+			WarehousingDetailId:     warehouse.ID,
10387
+			SystemTime:              advice.SysRecordTime,
10388
+			PatientId:               advice.PatientId,
10389
+			Remark:                  advice.Remark,
10390
+			OperateTime:             time.Now().Unix(),
10391
+		}
10392
+
10393
+		CreateSelfDrugFlowOne(drugflow, tx)
10394
+
10395
+		AddSelfDrugCount(advice.DrugId, orgID, advice.PatientId, drugflow.Count, tx)
10027 10396
 		// 出库完成后,要将该批次库存清零
10028 10397
 
10029 10398
 		prescribingNumber_two_temp := deliver_number - stock_number