Browse Source

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

陈少旭 9 months ago
parent
commit
ecfbe58e12

BIN
XT_New.exe View File


+ 6 - 6
controllers/base_api_controller.go View File

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

+ 2 - 2
controllers/dialysis_api_controller.go View File

@@ -542,7 +542,7 @@ func (c *DialysisApiController) PostPrescription() {
542 542
 			}
543 543
 
544 544
 			if schedulePatient.ScheduleType == 2 {
545
-				advice.StartTime = recordDate.Unix() + 11*60*60
545
+				advice.StartTime = recordDate.Unix() + 9*60*60
546 546
 			}
547 547
 		}
548 548
 		// 抗凝剂名称
@@ -1523,7 +1523,7 @@ func (c *DialysisApiController) PostSoulution() {
1523 1523
 			}
1524 1524
 
1525 1525
 			if schedulePatient.ScheduleType == 2 {
1526
-				advice.StartTime = recordDate.Unix() + 11*60*60
1526
+				advice.StartTime = recordDate.Unix() + 9*60*60
1527 1527
 			}
1528 1528
 		}
1529 1529
 		// 抗凝剂名称

+ 9 - 8
controllers/doctor_schedule_api_controller.go View File

@@ -1,13 +1,14 @@
1 1
 package controllers
2 2
 
3 3
 import (
4
+	"fmt"
5
+	"time"
6
+
4 7
 	"XT_New/enums"
5 8
 	"XT_New/models"
6 9
 	"XT_New/service"
7
-	"fmt"
8 10
 	"github.com/astaxie/beego"
9 11
 	"github.com/jinzhu/gorm"
10
-	"time"
11 12
 )
12 13
 
13 14
 type DoctorScheduleApiController struct {
@@ -282,17 +283,17 @@ func (this *DoctorScheduleApiController) AddSchedule() {
282 283
 
283 284
 	orgId := this.GetAdminUserInfo().CurrentOrgId
284 285
 	doctor_id, _ := this.GetInt64("doctor_id")
285
-	fmt.Println("doctor_id", doctor_id)
286
+
286 287
 	doctor_type, _ := this.GetInt64("doctor_type")
287
-	fmt.Println("doctor_type", doctor_type)
288
+
288 289
 	start_time, _ := this.GetInt64("start_time")
289
-	fmt.Println("start_time", start_time)
290
+
290 291
 	end_time, _ := this.GetInt64("end_time")
291
-	fmt.Println("end_time", end_time)
292
+
292 293
 	schedule_type, _ := this.GetInt64("schedule_type")
293
-	fmt.Println("schedule_type", schedule_type)
294
+
294 295
 	schedule_week, _ := this.GetInt64("schedule_week")
295
-	fmt.Println("schedule_week", schedule_week)
296
+
296 297
 	schedule_date, _ := this.GetInt64("schedule_date")
297 298
 	schedule := models.StaffSchedule{
298 299
 		DoctorId:     doctor_id,

+ 4 - 7
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -2178,7 +2178,7 @@ func (c *DialysisAPIController) PostDialysisPrescription() {
2178 2178
 				}
2179 2179
 
2180 2180
 				if schedulePatient.ScheduleType == 2 {
2181
-					advice.StartTime = recordDate.Unix() + 10*60*60
2181
+					advice.StartTime = recordDate.Unix() + 9*60*60
2182 2182
 				}
2183 2183
 			}
2184 2184
 			// 抗凝剂名称
@@ -4191,7 +4191,7 @@ func (c *DialysisAPIController) PostSolution() {
4191 4191
 			}
4192 4192
 
4193 4193
 			if schedulePatient.ScheduleType == 2 {
4194
-				advice.StartTime = recordDate.Unix() + 10*60*60
4194
+				advice.StartTime = recordDate.Unix() + 9*60*60
4195 4195
 			}
4196 4196
 		}
4197 4197
 		// 抗凝剂名称
@@ -4483,7 +4483,7 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
4483 4483
 				record.UltrafiltrationRate = ultrafiltration_rate
4484 4484
 			}
4485 4485
 
4486
-			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 {
4486
+			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 {
4487 4487
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
4488 4488
 
4489 4489
 				record.UltrafiltrationRate = ultrafiltration_rate
@@ -4551,7 +4551,7 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
4551 4551
 	}
4552 4552
 
4553 4553
 	//长沙南雅
4554
-	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 {
4554
+	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 {
4555 4555
 
4556 4556
 		if ultrafiltration_rate > 0 {
4557 4557
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
@@ -9628,9 +9628,6 @@ func (this *DialysisAPIController) ExectionMobileAdvice() {
9628 9628
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
9629 9629
 		}
9630 9630
 	}
9631
-
9632
-	fmt.Println("config233322333223", config.IsOpen)
9633
-
9634 9631
 	//血透客户
9635 9632
 	if config.IsOpen == 2 || config.IsOpen == 0 {
9636 9633
 

+ 13 - 33
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -1288,6 +1288,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1288 1288
 		ids = strings.Split(advice_ids, ",")
1289 1289
 		if len(execution_time) <= 0 {
1290 1290
 			utils.ErrorLog("execution_time")
1291
+			tx.Rollback()
1291 1292
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1292 1293
 			return
1293 1294
 		}
@@ -1297,6 +1298,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1297 1298
 
1298 1299
 		if errs != nil {
1299 1300
 			utils.ErrorLog(errs.Error())
1301
+			tx.Rollback()
1300 1302
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1301 1303
 			return
1302 1304
 		}
@@ -1304,16 +1306,19 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1304 1306
 		var err error
1305 1307
 		for _, item := range advices {
1306 1308
 			if item.ExecutionState == 1 {
1309
+				tx.Rollback()
1307 1310
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
1308 1311
 				return
1309 1312
 			}
1310 1313
 
1311 1314
 			if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
1315
+				tx.Rollback()
1312 1316
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
1313 1317
 				return
1314 1318
 			}
1315 1319
 
1316 1320
 			if item.StartTime > theTime.Unix() {
1321
+				tx.Rollback()
1317 1322
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
1318 1323
 				return
1319 1324
 			}
@@ -1341,6 +1346,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1341 1346
 					infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
1342 1347
 					//申请状态不允许的情况 拒绝修改
1343 1348
 					if infor.ApplicationStatus != 1 {
1349
+						tx.Rollback()
1344 1350
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
1345 1351
 						return
1346 1352
 					}
@@ -1436,7 +1442,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1436 1442
 						}
1437 1443
 					}
1438 1444
 					advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
1439
-					tx.Commit()
1445
+					tx.Rollback()
1440 1446
 					c.ServeSuccessJSON(map[string]interface{}{
1441 1447
 						"msg":    "7",
1442 1448
 						"advice": advice,
@@ -1489,6 +1495,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1489 1495
 				var total int64
1490 1496
 				var prescribing_number_total int64
1491 1497
 
1498
+				//保存处方出库
1492 1499
 				config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
1493 1500
 
1494 1501
 				if config.IsOpen != 1 {
@@ -1529,7 +1536,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1529 1536
 								PrescribingNumberUnit: advice.PrescribingNumberUnit,
1530 1537
 							}
1531 1538
 							service.CreateDrugError(drugError)
1532
-							tx.Commit()
1539
+							tx.Rollback()
1533 1540
 							c.ServeSuccessJSON(map[string]interface{}{
1534 1541
 								"msg":    "1",
1535 1542
 								"advice": advice,
@@ -1555,7 +1562,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1555 1562
 								PrescribingNumberUnit: advice.PrescribingNumberUnit,
1556 1563
 							}
1557 1564
 							service.CreateDrugError(drugError)
1558
-							tx.Commit()
1565
+							tx.Rollback()
1559 1566
 							c.ServeSuccessJSON(map[string]interface{}{
1560 1567
 								"msg":    "3",
1561 1568
 								"advice": advice,
@@ -1578,7 +1585,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1578 1585
 								PrescribingNumberUnit: advice.PrescribingNumberUnit,
1579 1586
 							}
1580 1587
 							service.CreateDrugError(drugError)
1581
-							tx.Commit()
1588
+							tx.Rollback()
1582 1589
 							c.ServeSuccessJSON(map[string]interface{}{
1583 1590
 								"msg":    "2",
1584 1591
 								"advice": advice,
@@ -1588,10 +1595,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1588 1595
 						}
1589 1596
 					}
1590 1597
 
1591
-					fmt.Println("hhahhahahahhhhhha", prescribing_number_total)
1592
-					fmt.Println("total0000000000000", total)
1593
-					fmt.Println("medical22222222222222", medical.IsUse)
1594
-					fmt.Println("config.isp", config.IsOpen)
1595 1598
 					if prescribing_number_total <= total {
1596 1599
 
1597 1600
 						pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
@@ -1601,9 +1604,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1601 1604
 							if config.IsOpen != 1 {
1602 1605
 								if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
1603 1606
 
1604
-									//service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
1605
-									//service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1606
-
1607 1607
 									if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
1608 1608
 										//查询该药品是否有出库记录
1609 1609
 										flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
@@ -1625,7 +1625,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1625 1625
 												}
1626 1626
 												service.CreateDrugError(drugError)
1627 1627
 											}
1628
-											tx.Commit()
1628
+											tx.Rollback()
1629 1629
 											c.ServeSuccessJSON(map[string]interface{}{
1630 1630
 												"msg":    "6",
1631 1631
 												"advice": advice,
@@ -1662,7 +1662,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1662 1662
 												}
1663 1663
 												service.CreateDrugError(drugError)
1664 1664
 											}
1665
-											tx.Commit()
1665
+											tx.Rollback()
1666 1666
 											c.ServeSuccessJSON(map[string]interface{}{
1667 1667
 												"msg":    "6",
1668 1668
 												"advice": advice,
@@ -1693,26 +1693,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1693 1693
 					}
1694 1694
 				}
1695 1695
 
1696
-				//fmt.Println("config+++++++++++", config.IsOpen)
1697
-				//fmt.Println("config+++++++++++", item.UserOrgId)
1698
-				//
1699
-				//if config.IsOpen == 1 && item.UserOrgId == 10402 {
1700
-				//
1701
-				//	service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1702
-				//	//更新字典里面的库存
1703
-				//	stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1704
-				//	var sum_count int64
1705
-				//	for _, its := range stockInfo {
1706
-				//		if its.MaxUnit == medical.MaxUnit {
1707
-				//			its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
1708
-				//		}
1709
-				//		sum_count += its.StockMaxNumber + its.StockMinNumber
1710
-				//	}
1711
-				//	service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
1712
-				//	//剩余库存
1713
-				//	service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
1714
-				//}
1715
-
1716 1696
 			}
1717 1697
 		}
1718 1698
 		tx.Commit()

+ 10 - 10
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go View File

@@ -1431,16 +1431,16 @@ func (c *StaffScheduleApiController) ChangeScheduleBed() {
1431 1431
 			}
1432 1432
 		}
1433 1433
 
1434
-		if org_id == 10206 || org_id == 10344 {
1435
-			hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(scheduleToday.PatientId, scheduleToday.ScheduleDate, org_id)
1436
-			project, _ := service.GetHisPrescriptionProjectList(scheduleToday.PatientId, scheduleToday.ScheduleDate, org_id)
1437
-			if len(hisAdvice) > 0 {
1438
-				service.UpdateHisAdviceObj(scheduleToday.PatientId, scheduleToday.ScheduleDate, org_id)
1439
-			}
1440
-			if len(project) > 0 {
1441
-				service.UpdateProjectObj(scheduleToday.PatientId, scheduleToday.ScheduleDate, org_id)
1442
-			}
1443
-		}
1434
+		//if org_id == 10206 || org_id == 10344 {
1435
+		//	hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(scheduleToday.PatientId, scheduleToday.ScheduleDate, org_id)
1436
+		//	project, _ := service.GetHisPrescriptionProjectList(scheduleToday.PatientId, scheduleToday.ScheduleDate, org_id)
1437
+		//	if len(hisAdvice) > 0 {
1438
+		//		service.UpdateHisAdviceObj(scheduleToday.PatientId, scheduleToday.ScheduleDate, org_id)
1439
+		//	}
1440
+		//	if len(project) > 0 {
1441
+		//		service.UpdateProjectObj(scheduleToday.PatientId, scheduleToday.ScheduleDate, org_id)
1442
+		//	}
1443
+		//}
1444 1444
 		if err == nil {
1445 1445
 			c.ServeSuccessJSON(map[string]interface{}{
1446 1446
 				"msg": "ok",

+ 2 - 38
controllers/patient_api_controller.go View File

@@ -2798,7 +2798,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2798 2798
 
2799 2799
 		//1.判断是否启用药品管理和自备药出库功能
2800 2800
 
2801
-		//药品管理信息
2801
+		//药品自动出库开关管理信息
2802 2802
 		_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
2803 2803
 
2804 2804
 		if drugStockConfig.IsOpen == 1 {
@@ -2806,46 +2806,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2806 2806
 			advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
2807 2807
 			for _, item := range advices {
2808 2808
 				medical, _ := service.GetBaseDrugMedical(advice.DrugId)
2809
-				//查询这个患者这个患者这个药已经出库的所有数量
2810
-				//advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
2811
-				//drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
2812
-				//var total_count int64 // 现在出库的
2813
-				//var drug_count int64  // 已经出库的
2814
-				//for _, it := range advicelist {
2815
-				//	if it.PrescribingNumberUnit == medical.MaxUnit {
2816
-				//		prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
2817
-				//		prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2818
-				//		total_count += prenumber * medical.MinNumber
2819
-				//	}
2820
-				//	if it.PrescribingNumberUnit == medical.MinUnit {
2821
-				//		prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
2822
-				//		prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2823
-				//		total_count += prenumber
2824
-				//	}
2825
-				//
2826
-				//}
2827
-				//
2828
-				//
2829
-				//for _, its := range drugoutlist {
2830
-				//	if its.CountUnit == medical.MaxUnit {
2831
-				//		drug_count += its.Count * medical.MinNumber
2832
-				//	}
2833
-				//	if its.CountUnit == medical.MinUnit {
2834
-				//		drug_count += its.Count
2835
-				//	}
2836
-				//}
2837
-				//fmt.Println("total_count23232323232323232wode",total_count)
2838
-				//fmt.Println("total_count23232323232323232wode",drug_count)
2839
-				//if total_count == drug_count {
2840
-				//	c.ServeSuccessJSON(map[string]interface{}{
2841
-				//		"msg":    "1",
2842
-				//		"advice": advice,
2843
-				//	})
2844
-				//	return
2845
-				//}
2846 2809
 
2847 2810
 				var total int64
2848 2811
 				var prescribing_number_total int64
2812
+				//药品保存处方出库
2849 2813
 				config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
2850 2814
 				if config.IsOpen != 1 {
2851 2815
 					//查询默认出库仓库

+ 46 - 39
controllers/pharmacy_controller.go View File

@@ -179,7 +179,7 @@ func (this *PharmacyController) IssuedDrug() {
179 179
 	}
180 180
 
181 181
 	list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1, ids)
182
-	fmt.Println("LIST=================", list)
182
+
183 183
 	var flist []models.TmpPatientOne
184 184
 	if len(list) > 0 {
185 185
 		for _, item := range list {
@@ -335,6 +335,10 @@ func (this *PharmacyController) GetPharmacyContent() {
335 335
 	appId := this.GetAdminUserInfo().CurrentAppId
336 336
 	adminUserES, _ := service.GetAllAdminUserES(orgid, appId)
337 337
 	allDoctor, _ := service.GetAllDoctor(orgid, appId)
338
+
339
+	prescriptionListByToDay, _ := service.GetPrescriptionListByToDay(orgid, patient_id, stime)
340
+
341
+	diagnose, _ := service.FindAllDiagnose(orgid)
338 342
 	if err != nil {
339 343
 		utils.ErrorLog(err.Error())
340 344
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -349,7 +353,8 @@ func (this *PharmacyController) GetPharmacyContent() {
349 353
 	return_value["zoneList"] = zoneList
350 354
 	return_value["adminUserES"] = adminUserES
351 355
 	return_value["doctors"] = allDoctor
352
-
356
+	return_value["prescription"] = prescriptionListByToDay
357
+	return_value["diagnose"] = diagnose
353 358
 	//if is_medicine == 1{发药时间先不展示
354 359
 	//	return_value["time"] = time
355 360
 	//}
@@ -384,48 +389,50 @@ func (this *PharmacyController) DispensingMedicine() {
384 389
 		stime = stmp.Unix()
385 390
 		etime = stime + 86399
386 391
 	}
392
+	tmp_bool := service.IsPharmacyConfig(orgid)
393
+	if tmp_bool == true {
394
+		advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
395
+		if len(advicelist) > 0 {
396
+			var total int64
397
+			var prescribing_number_total int64
398
+			for _, item := range advicelist {
399
+				//查询改药品信息
400
+				medical, _ := service.GetBaseDrugMedical(item.DrugId)
401
+				//如果是药房发药的方式
402
+				if medical.IsPharmacy == 1 {
403
+					houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
404
+					//查询该药品是否有库存
405
+					list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
406
+
407
+					//判断单位是否相等
408
+					if medical.MaxUnit == item.PrescribingNumberUnit {
409
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
410
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
411
+						//转化为最小单位
412
+						total = list.Count*medical.MinNumber + list.StockMinNumber
413
+						prescribing_number_total = count * medical.MinNumber
414
+					}
415
+					if medical.MinUnit == item.PrescribingNumberUnit {
416
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
417
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
418
+						total = list.Count*medical.MinNumber + list.StockMinNumber
419
+						prescribing_number_total = count
420
+					}
387 421
 
388
-	advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
389
-	if len(advicelist) > 0 {
390
-		var total int64
391
-		var prescribing_number_total int64
392
-		for _, item := range advicelist {
393
-			//查询改药品信息
394
-			medical, _ := service.GetBaseDrugMedical(item.DrugId)
395
-			//如果是药房发药的方式
396
-			if medical.IsPharmacy == 1 {
397
-				houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
398
-				//查询该药品是否有库存
399
-				list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
400
-
401
-				//判断单位是否相等
402
-				if medical.MaxUnit == item.PrescribingNumberUnit {
403
-					prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
404
-					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
405
-					//转化为最小单位
406
-					total = list.Count*medical.MinNumber + list.StockMinNumber
407
-					prescribing_number_total = count * medical.MinNumber
408
-				}
409
-				if medical.MinUnit == item.PrescribingNumberUnit {
410
-					prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
411
-					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
412
-					total = list.Count*medical.MinNumber + list.StockMinNumber
413
-					prescribing_number_total = count
414
-				}
415
-
416
-				if medical.IsUse != 1 {
417
-					//如果出库数量大于库存数量
418
-					if prescribing_number_total > total {
419
-						err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
420
-						if err != nil {
421
-							utils.ErrorLog(err.Error())
422
-							this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
423
-							return
422
+					if medical.IsUse != 1 {
423
+						//如果出库数量大于库存数量
424
+						if prescribing_number_total > total {
425
+							err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
426
+							if err != nil {
427
+								utils.ErrorLog(err.Error())
428
+								this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
429
+								return
430
+							}
424 431
 						}
425 432
 					}
426 433
 				}
427
-			}
428 434
 
435
+			}
429 436
 		}
430 437
 	}
431 438
 

+ 10 - 10
controllers/schedule_api_controller.go View File

@@ -742,16 +742,16 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
742 742
 						}
743 743
 					}
744 744
 
745
-					if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
746
-						hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
747
-						project, _ := service.GetHisPrescriptionProjectList(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
748
-						if len(hisAdvice) > 0 {
749
-							service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
750
-						}
751
-						if len(project) > 0 {
752
-							service.UpdateProjectObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
753
-						}
754
-					}
745
+					//if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
746
+					//	hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
747
+					//	project, _ := service.GetHisPrescriptionProjectList(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
748
+					//	if len(hisAdvice) > 0 {
749
+					//		service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
750
+					//	}
751
+					//	if len(project) > 0 {
752
+					//		service.UpdateProjectObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
753
+					//	}
754
+					//}
755 755
 					service.SaveSch(&schedule)
756 756
 				}
757 757
 				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)

+ 1 - 1
controllers/self_drug_api_congtroller.go View File

@@ -2950,7 +2950,7 @@ func (this *SelfDrugApiController) GetGoodExpiryDateQuery() {
2950 2950
 		goodIds = append(goodIds, it.ID)
2951 2951
 	}
2952 2952
 	list, total, err := service.GetGoodExpiryDateQuery(storehouse_id, expiry_type, keyword, page, limit, orgId, ids, goodIds, nowtime, endTime)
2953
-	fmt.Println("total233223322332323232323223", total)
2953
+
2954 2954
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2955 2955
 
2956 2956
 	if err != nil {

+ 10 - 8
controllers/sign_api_controller.go View File

@@ -1223,7 +1223,7 @@ func (this *SignApiController) ToAutoDrug() {
1223 1223
 
1224 1224
 func (this *SignApiController) ToAutoDiagnose() {
1225 1225
 
1226
-	orgId := this.GetAdminUserInfo().CurrentOrgId
1226
+	//orgId := this.GetAdminUserInfo().CurrentOrgId
1227 1227
 
1228 1228
 	//order, _ := service.GetDialysisOrderTotalCount()
1229 1229
 	//
@@ -1238,22 +1238,24 @@ func (this *SignApiController) ToAutoDiagnose() {
1238 1238
 	//	service.UpdateAllPatient(item.BloodId, item.Diagnose, item.UserOrgId)
1239 1239
 	//}
1240 1240
 
1241
-	list, _ := service.GetAllDialysisOrder(10490)
1242
-	for _, item := range list {
1243
-		service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, orgId, item.BedId, item.ZoneId, item.SchedualType)
1244
-	}
1241
+	//list, _ := service.GetAllDialysisOrder(10469)
1242
+	//for _, item := range list {
1243
+	//	schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, orgId, item.BedId, item.ZoneId, item.SchedualType)
1244
+	//	service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, orgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID)
1245
+	//}
1245 1246
 
1246
-	//drugList, _ := service.GetAllBaseDrugList(10571)
1247
+	//drugList, _ := service.GetAllBaseDrugList(10653)
1247 1248
 	//for _, item := range drugList {
1248
-	//	//service.UpdateDrugWarehouseInfoByDrug(item.ID, item.MinPrice, item.OrgId)
1249
+	//	service.UpdateDrugWarehouseInfoByDrug(item.ID, item.MinPrice, item.OrgId)
1249 1250
 	//
1250
-	//	service.UpdateHisDoctorAdviceOne(item.ID, item.MinPrice, item.OrgId)
1251
+	//	//service.UpdateHisDoctorAdviceOne(item.ID, item.MinPrice, item.OrgId)
1251 1252
 	//}
1252 1253
 
1253 1254
 	//goodList, _ := service.GetAllGoodList(10571)
1254 1255
 	//for _, item := range goodList {
1255 1256
 	//	service.UpdasteGoodWarehouseInfoByGood(item.ID, item.PackingPrice, item.OrgId)
1256 1257
 	//}
1258
+
1257 1259
 	this.ServeSuccessJSON(map[string]interface{}{
1258 1260
 		"msg": "ok",
1259 1261
 	})

+ 9 - 0
service/gobal_config_service.go View File

@@ -1368,3 +1368,12 @@ func GetMobiledialysiOrder(user_org_id int64, patient_id int64, record_date int6
1368 1368
 
1369 1369
 	return dialysisOrder, err
1370 1370
 }
1371
+
1372
+func GetPrescriptionListByToDay(user_org_id int64, patient_id int64, record_Date int64) (models.HisPrescriptionInfo, error) {
1373
+
1374
+	prescriptionInfo := models.HisPrescriptionInfo{}
1375
+
1376
+	err := XTReadDB().Where("user_org_id = ? and patient_id = ? and record_date = ? and status =1", user_org_id, patient_id, record_Date).Find(&prescriptionInfo).Error
1377
+
1378
+	return prescriptionInfo, err
1379
+}

+ 192 - 0
service/his_service.go View File

@@ -905,6 +905,44 @@ func CreateHisDoctorAdviceOne(s *models.HisDoctorAdviceInfo, tx *gorm.DB) (err e
905 905
 	return
906 906
 }
907 907
 
908
+func GetHisToday(patient_id int64, advice_date int64, user_org_id int64, drug_id int64, tx *gorm.DB) (list []*models.HisDoctorAdviceInfo, err error) {
909
+
910
+	err = tx.Where("patient_id = ? and advice_date = ? and user_org_id = ? and status =1 and drug_id = ?", patient_id, advice_date, user_org_id, drug_id).Find(&list).Error
911
+	if err != gorm.ErrRecordNotFound {
912
+		if err != nil {
913
+			tx.Rollback()
914
+			return list, err
915
+		}
916
+	}
917
+	return list, err
918
+}
919
+
920
+func GetLastDrugAuto(advice_id int64, drug_id int64, advice_date int64, patient_id int64, user_org_id int64, tx *gorm.DB) (models.DrugAutomaticReduceDetail, error) {
921
+
922
+	automaticReduceDetail := models.DrugAutomaticReduceDetail{}
923
+
924
+	err := XTReadDB().Where("advice_id = ? and drug_id = ? and record_time= ? and patient_id =? and status=1 and org_id = ?", advice_id, drug_id, advice_date, patient_id, user_org_id).Find(&automaticReduceDetail).Error
925
+	if err != gorm.ErrRecordNotFound {
926
+		if err != nil {
927
+			tx.Rollback()
928
+			return automaticReduceDetail, err
929
+		}
930
+	}
931
+	return automaticReduceDetail, err
932
+}
933
+
934
+func UpdateTodayHis(drug_id int64, advice_date int64, patient_id int64, user_org_id int64, min_unit string, count_total int64, id int64, tx *gorm.DB) (models.XtDrugAutomaticReduceDetail, error) {
935
+
936
+	drugAutomaticReduceDetail := models.XtDrugAutomaticReduceDetail{}
937
+
938
+	err = tx.Model(&drugAutomaticReduceDetail).Where("drug_id = ? and record_time = ? and patient_id =? and org_id = ? and status=1 and advice_id = ?", drug_id, advice_date, patient_id, user_org_id, id).Updates(map[string]interface{}{"count": count_total, "count_unit": min_unit}).Error
939
+	if err != nil {
940
+		tx.Rollback()
941
+		return drugAutomaticReduceDetail, err
942
+	}
943
+	return drugAutomaticReduceDetail, err
944
+}
945
+
908 946
 func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
909 947
 
910 948
 	tx := writeDb.Begin()
@@ -3081,3 +3119,157 @@ func UpdateGood(good_id int64, user_org_id int64, packing_price float64) (models
3081 3119
 
3082 3120
 	return goodInfo, err
3083 3121
 }
3122
+
3123
+func GetHistory(id int64, user_org_id int64, tx *gorm.DB) (models.HisDoctorAdviceInfo, error) {
3124
+
3125
+	adviceInfo := models.HisDoctorAdviceInfo{}
3126
+
3127
+	err := tx.Where("id = ? and user_org_id = ? and status=1", id, user_org_id).Find(&adviceInfo).Error
3128
+	if err != gorm.ErrRecordNotFound {
3129
+		if err != nil {
3130
+			tx.Rollback()
3131
+			return adviceInfo, err
3132
+		}
3133
+	}
3134
+	return adviceInfo, err
3135
+}
3136
+
3137
+func GetLastHisDoctorAdviceById(patient_id int64, user_org_id int64, advice_date int64, drug_id int64, tx *gorm.DB) (models.HisDoctorAdviceInfo, error) {
3138
+
3139
+	adviceInfo := models.HisDoctorAdviceInfo{}
3140
+
3141
+	err := tx.Where("patient_id = ? and user_org_id = ? and advice_date = ? and drug_id = ? and status =1", patient_id, user_org_id, advice_date, drug_id).Last(&adviceInfo).Error
3142
+
3143
+	if err != gorm.ErrRecordNotFound {
3144
+		if err != nil {
3145
+			tx.Rollback()
3146
+			return adviceInfo, err
3147
+		}
3148
+	}
3149
+	return adviceInfo, err
3150
+}
3151
+
3152
+func GetDrugWarehouseOutInfoByAdviceId(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, tx *gorm.DB) (outInfo []*models.DrugWarehouseOutInfo, err error) {
3153
+
3154
+	err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and drug_id = ? and status=1 and advice_id = 0", patient_id, user_org_id, sys_record_date, drug_id).Find(&outInfo).Error
3155
+
3156
+	if err != gorm.ErrRecordNotFound {
3157
+		if err != nil {
3158
+			tx.Rollback()
3159
+			return outInfo, err
3160
+		}
3161
+	}
3162
+	return outInfo, err
3163
+}
3164
+
3165
+func GetDrugWarehouseOutInfoByAdviceIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
3166
+
3167
+	outInfo := models.DrugWarehouseOutInfo{}
3168
+	err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and drug_id = ? and status=1 and advice_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
3169
+	if err != gorm.ErrRecordNotFound {
3170
+		if err != nil {
3171
+			tx.Rollback()
3172
+			return outInfo, err
3173
+		}
3174
+	}
3175
+	return outInfo, err
3176
+}
3177
+
3178
+func GetDrugAutoOutInfoByAdviceIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.DrugAutomaticReduceDetail, error) {
3179
+
3180
+	outInfo := models.DrugAutomaticReduceDetail{}
3181
+	err = tx.Where("patient_id = ? and org_id =? and record_time = ? and drug_id = ? and status=1 and advice_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
3182
+	if err != gorm.ErrRecordNotFound {
3183
+		if err != nil {
3184
+			tx.Rollback()
3185
+			return outInfo, err
3186
+		}
3187
+	}
3188
+	return outInfo, err
3189
+}
3190
+
3191
+func GetDrugAutoDetail(patient_id int64, org_id int64, record_time int64, drug_id int64, tx *gorm.DB) (automaticReduceDetail []*models.DrugAutomaticReduceDetail, err error) {
3192
+
3193
+	err = tx.Where("patient_id = ? and org_id = ? and record_time =? and drug_id = ? and status =1 and advice_id = 0", patient_id, org_id, record_time, drug_id).Find(&automaticReduceDetail).Error
3194
+
3195
+	if err != gorm.ErrRecordNotFound {
3196
+		if err != nil {
3197
+			tx.Rollback()
3198
+			return automaticReduceDetail, err
3199
+		}
3200
+	}
3201
+	return automaticReduceDetail, err
3202
+}
3203
+
3204
+func UpdateDrugAutoDetail(id int64, advice_id int64, tx *gorm.DB) error {
3205
+
3206
+	drugAutomaticReduceDetail := models.DrugAutomaticReduceDetail{}
3207
+
3208
+	err := tx.Model(&drugAutomaticReduceDetail).Where("id = ? and status=1", id).Updates(map[string]interface{}{"advice_id": advice_id}).Error
3209
+
3210
+	if err != nil {
3211
+		tx.Rollback()
3212
+		return err
3213
+	}
3214
+	return err
3215
+}
3216
+
3217
+func UpdateDrugOutInfoByAdviceId(id int64, advice_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
3218
+
3219
+	info := models.DrugWarehouseOutInfo{}
3220
+
3221
+	err := tx.Model(&info).Where("id = ? and status=1", id).Updates(map[string]interface{}{"advice_id": advice_id}).Error
3222
+
3223
+	if err != nil {
3224
+		tx.Rollback()
3225
+		return info, err
3226
+	}
3227
+
3228
+	return info, err
3229
+}
3230
+
3231
+func ModifyDrugWarehouseOutInfoByNumber(id int64, cha_count int64, tx *gorm.DB) error {
3232
+
3233
+	err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
3234
+
3235
+	err = tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("over_count", gorm.Expr("over_count + ?", cha_count)).Error
3236
+
3237
+	if err != nil {
3238
+		tx.Rollback()
3239
+		return err
3240
+	}
3241
+	return err
3242
+}
3243
+
3244
+func ModifyDrugAuToWarehouseOut(id int64, cha_count int64, tx *gorm.DB) error {
3245
+
3246
+	err := tx.Model(&models.DrugAutomaticReduceDetail{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
3247
+
3248
+	if err != nil {
3249
+		tx.Rollback()
3250
+		return err
3251
+	}
3252
+	return err
3253
+}
3254
+
3255
+func DeleteDrugWarehouseOutInfoByNumber(id int64, tx *gorm.DB) error {
3256
+
3257
+	err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
3258
+
3259
+	if err != nil {
3260
+		tx.Rollback()
3261
+		return err
3262
+	}
3263
+	return err
3264
+}
3265
+
3266
+func DeleteDrugWarehouseAutoByNumber(id int64, tx *gorm.DB) error {
3267
+
3268
+	err := tx.Model(&models.DrugAutomaticReduceDetail{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
3269
+
3270
+	if err != nil {
3271
+		tx.Rollback()
3272
+		return err
3273
+	}
3274
+	return err
3275
+}

+ 843 - 88
service/new_warehouse_service.go View File

@@ -3682,9 +3682,9 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
3682 3682
 	var deliver_number_one int64 = 0
3683 3683
 	var stock_number int64 = 0
3684 3684
 
3685
-	fmt.Println(deliver_number)
3686
-	fmt.Println(deliver_number_one)
3687
-	fmt.Println(stock_number)
3685
+	//fmt.Println(deliver_number)
3686
+	//fmt.Println(deliver_number_one)
3687
+	//fmt.Println(stock_number)
3688 3688
 	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
3689 3689
 	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
3690 3690
 
@@ -3857,12 +3857,6 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
3857 3857
 		//扣减库存数据
3858 3858
 		UpDateNewDrugWarehouseInfoByStock(&warehouse, tx)
3859 3859
 
3860
-		//更改字典里面的价格
3861
-		//if advice.UserOrgId == 10265 || advice.UserOrgId == 10215 {
3862
-		//
3863
-		//	UpdateNewBasePrice(lastWarehouse.DrugId, lastWarehouse.RetailPrice, tx)
3864
-		//}
3865
-		//
3866 3860
 		////查询剩余库存
3867 3861
 		stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
3868 3862
 		var sum_count int64
@@ -3873,55 +3867,54 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
3873 3867
 			sum_count += its.StockMaxNumber + its.StockMinNumber
3874 3868
 		}
3875 3869
 
3876
-		if orgID != 10188 && orgID != 10217 && orgID != 3877 {
3877
-			warehouseOutInfo := &models.DrugWarehouseOutInfo{
3878
-				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3879
-				WarehouseOutId:          warehouseout.ID,
3880
-				Status:                  1,
3881
-				Ctime:                   advice.RecordDate,
3882
-				Mtime:                   time.Now().Unix(),
3883
-				Remark:                  warehouse.Remark,
3884
-				OrgId:                   orgID,
3885
-				Type:                    1,
3886
-				Manufacturer:            warehouse.Manufacturer,
3887
-				Dealer:                  warehouse.Dealer,
3888
-				IsSys:                   1,
3889
-				SysRecordTime:           advice.RecordDate,
3890
-				DrugId:                  advice.DrugId,
3891
-				Number:                  warehouse.Number,
3892
-				BatchNumber:             warehouse.BatchNumber,
3893
-				Price:                   warehouse.RetailPrice,
3894
-				CountUnit:               drup.MinUnit,
3895
-				RetailPrice:             warehouse.RetailPrice,
3896
-				ProductDate:             warehouse.ProductDate,
3897
-				ExpiryDate:              warehouse.ExpiryDate,
3898
-				PatientId:               advice.PatientId,
3899
-				Count:                   deliver_number, //出最小单位
3900
-				WarehouseInfoId:         warehouse.ID,
3901
-				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3902
-				StorehouseId:            storeConfig.DrugStorehouseOut,
3903
-				IsCheck:                 1,
3904
-				OverCount:               sum_count,
3905
-				AdviceId:                advice.ID,
3906
-			}
3870
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
3871
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3872
+			WarehouseOutId:          warehouseout.ID,
3873
+			Status:                  1,
3874
+			Ctime:                   advice.RecordDate,
3875
+			Mtime:                   time.Now().Unix(),
3876
+			Remark:                  warehouse.Remark,
3877
+			OrgId:                   orgID,
3878
+			Type:                    1,
3879
+			Manufacturer:            warehouse.Manufacturer,
3880
+			Dealer:                  warehouse.Dealer,
3881
+			IsSys:                   1,
3882
+			SysRecordTime:           advice.RecordDate,
3883
+			DrugId:                  advice.DrugId,
3884
+			Number:                  warehouse.Number,
3885
+			BatchNumber:             warehouse.BatchNumber,
3886
+			Price:                   warehouse.RetailPrice,
3887
+			CountUnit:               drup.MinUnit,
3888
+			RetailPrice:             warehouse.RetailPrice,
3889
+			ProductDate:             warehouse.ProductDate,
3890
+			ExpiryDate:              warehouse.ExpiryDate,
3891
+			PatientId:               advice.PatientId,
3892
+			Count:                   deliver_number, //出最小单位
3893
+			WarehouseInfoId:         warehouse.ID,
3894
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3895
+			StorehouseId:            storeConfig.DrugStorehouseOut,
3896
+			IsCheck:                 1,
3897
+			OverCount:               sum_count,
3898
+			AdviceId:                advice.ID,
3899
+		}
3907 3900
 
3908
-			//查询今日该药品该患者是否有出库数据
3909
-			lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
3901
+		//查询今日该药品该患者是否有出库数据
3902
+		lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
3910 3903
 
3911
-			if lastDrugOutInfo.ID == 0 {
3912
-				//删除在新增
3913
-				UpdateNewDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
3914
-				AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
3915
-			}
3916
-			if lastDrugOutInfo.ID > 0 {
3904
+		if lastDrugOutInfo.ID == 0 {
3905
+			//删除在新增
3906
+			UpdateNewDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
3907
+			AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
3908
+		}
3909
+		if lastDrugOutInfo.ID > 0 {
3917 3910
 
3918
-				//删除在新增
3919
-				UpdateNewDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
3911
+			//删除在新增
3912
+			UpdateNewDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
3920 3913
 
3921
-				AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
3914
+			AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
3922 3915
 
3923
-			}
3924 3916
 		}
3917
+
3925 3918
 		//
3926 3919
 		var out_count int64
3927 3920
 		var cancel_count int64
@@ -3938,44 +3931,18 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
3938 3931
 			cancel_count += item.Count
3939 3932
 		}
3940 3933
 
3941
-		if deliver_number_one-(out_count-cancel_count) >= 0 {
3942
-			if (deliver_number_one - out_count - cancel_count) != 0 {
3934
+		fmt.Println("已经出库数据", out_count)
3943 3935
 
3944
-				if orgID == 10217 || orgID == 10188 || orgID == 3877 {
3945
-					warehouseOutInfo := &models.DrugWarehouseOutInfo{
3946
-						WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
3947
-						WarehouseOutId:          warehouseout.ID,
3948
-						Status:                  1,
3949
-						Ctime:                   advice.RecordDate,
3950
-						Mtime:                   time.Now().Unix(),
3951
-						Remark:                  warehouse.Remark,
3952
-						OrgId:                   orgID,
3953
-						Type:                    1,
3954
-						Manufacturer:            warehouse.Manufacturer,
3955
-						Dealer:                  warehouse.Dealer,
3956
-						IsSys:                   1,
3957
-						SysRecordTime:           advice.RecordDate,
3958
-						DrugId:                  advice.DrugId,
3959
-						Number:                  warehouse.Number,
3960
-						BatchNumber:             warehouse.BatchNumber,
3961
-						Price:                   warehouse.RetailPrice,
3962
-						CountUnit:               drup.MinUnit,
3963
-						RetailPrice:             warehouse.RetailPrice,
3964
-						ProductDate:             warehouse.ProductDate,
3965
-						ExpiryDate:              warehouse.ExpiryDate,
3966
-						PatientId:               advice.PatientId,
3967
-						Count:                   deliver_number_one - (out_count - cancel_count), //出最小单位
3968
-						WarehouseInfoId:         warehouse.ID,
3969
-						SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3970
-						StorehouseId:            storeConfig.DrugStorehouseOut,
3971
-						IsCheck:                 1,
3972
-						OverCount:               sum_count,
3973
-						AdviceId:                advice.ID,
3974
-					}
3936
+		fmt.Println("已经退库数据", cancel_count)
3975 3937
 
3976
-					AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
3938
+		fmt.Println("当前正在出库的数据", deliver_number_one)
3939
+
3940
+		fmt.Println("差", deliver_number_one-out_count-cancel_count)
3941
+
3942
+		//如果本次出库数据大于历史出库数据 新增1条退库流水
3943
+		if deliver_number_one-(out_count-cancel_count) >= 0 {
3944
+			if (deliver_number_one - out_count - cancel_count) != 0 {
3977 3945
 
3978
-				}
3979 3946
 				lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
3980 3947
 
3981 3948
 				drugflow := models.DrugFlow{
@@ -4143,7 +4110,6 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
4143 4110
 			StorehouseId:            storeConfig.DrugStorehouseOut,
4144 4111
 			AdviceId:                advice.ID,
4145 4112
 		}
4146
-
4147 4113
 		AddNewSigleDrugAutoReduceRecordInfo(details, tx)
4148 4114
 
4149 4115
 		return nil
@@ -4476,3 +4442,792 @@ func NewBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehous
4476 4442
 
4477 4443
 	return
4478 4444
 }
4445
+
4446
+func HisStoryBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo, hisprescribingNumber float64, unit string, tx *gorm.DB) (err error) {
4447
+
4448
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
4449
+	var deliver_number int64 = 0
4450
+
4451
+	var stock_number int64 = 0
4452
+
4453
+	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
4454
+	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
4455
+
4456
+	if advice.PrescribingNumberUnit == drup.MaxUnit {
4457
+		deliver_number = count * drup.MinNumber
4458
+
4459
+	} else {
4460
+		deliver_number = count
4461
+
4462
+	}
4463
+
4464
+	// 根据先进先出原则,查询最先入库的批次,进行出库
4465
+	// 如果没有对应的库存,则报错
4466
+	storeConfig, _ := GetNewAllStoreHouseConfig(advice.UserOrgId, tx)
4467
+	lastWarehouse, _ := FindNewLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut, tx)
4468
+
4469
+	if lastWarehouse.MaxUnit != lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
4470
+		if lastWarehouse.StockMinNumber >= drup.MinNumber {
4471
+			var stockMax int64
4472
+			var stockMin int64
4473
+			stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
4474
+			stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
4475
+
4476
+			ChangeNewMaxNumber(lastWarehouse.ID, stockMax, tx)
4477
+			UpdateNewMinNumber(lastWarehouse.ID, stockMin, tx)
4478
+
4479
+		}
4480
+	}
4481
+
4482
+	if lastWarehouse.MaxUnit == lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
4483
+
4484
+		lastWarehouse.StockMaxNumber = lastWarehouse.StockMaxNumber + lastWarehouse.StockMinNumber
4485
+		ChangeNewMaxNumberOne(lastWarehouse.ID, lastWarehouse.StockMaxNumber, tx)
4486
+
4487
+	}
4488
+
4489
+	warehouse, _ := FindNewLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut, tx)
4490
+
4491
+	// 将该批次的剩余库存数量转换为拆零数量
4492
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
4493
+
4494
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
4495
+
4496
+	}
4497
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
4498
+
4499
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
4500
+
4501
+	}
4502
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
4503
+
4504
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
4505
+
4506
+	}
4507
+
4508
+	//fmt.Println("stock_number", stock_number)
4509
+	//fmt.Println("deliver_number=============", deliver_number)
4510
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
4511
+	if stock_number >= deliver_number {
4512
+
4513
+		var maxNumber int64 = 0
4514
+		var minNumber int64 = 0
4515
+
4516
+		maxNumber = deliver_number / drup.MinNumber
4517
+		minNumber = deliver_number % drup.MinNumber
4518
+
4519
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
4520
+			minNumber = maxNumber
4521
+		}
4522
+
4523
+		if drup.MaxUnit != drup.MinUnit {
4524
+			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
4525
+				return errors.New("库存数量不足")
4526
+			}
4527
+		}
4528
+
4529
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
4530
+
4531
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
4532
+		}
4533
+
4534
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
4535
+
4536
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
4537
+		}
4538
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
4539
+
4540
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
4541
+		}
4542
+
4543
+		if warehouse.StockMaxNumber < 0 {
4544
+			warehouse.StockMaxNumber = 0
4545
+		}
4546
+		if warehouse.StockMinNumber < 0 {
4547
+			warehouse.StockMinNumber = 0
4548
+		}
4549
+
4550
+		warehouse.Mtime = time.Now().Unix()
4551
+
4552
+		//fmt.Println("hahhahahah", warehouse.StockMinNumber)
4553
+		//fmt.Println("howowowoowow", minNumber)
4554
+		if warehouse.StockMinNumber < minNumber {
4555
+
4556
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
4557
+			if warehouse.MaxUnit != warehouse.MinUnit {
4558
+				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
4559
+			}
4560
+			if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
4561
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
4562
+			}
4563
+		} else {
4564
+
4565
+			if minNumber > 0 {
4566
+				if (warehouse.StockMinNumber - minNumber) >= 0 {
4567
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
4568
+				}
4569
+
4570
+			}
4571
+
4572
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
4573
+
4574
+				if warehouse.StockMinNumber > 0 {
4575
+					if warehouse.StockMinNumber-deliver_number >= 0 {
4576
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4577
+					}
4578
+
4579
+				}
4580
+
4581
+			}
4582
+
4583
+		}
4584
+
4585
+		//fmt.Println("maxNumber", maxNumber)
4586
+		//fmt.Println("minNumber", maxNumber)
4587
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
4588
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
4589
+
4590
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4591
+			}
4592
+
4593
+		}
4594
+
4595
+		if drup.MaxUnit != drup.MinUnit {
4596
+			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
4597
+				return errors.New("库存数量不足")
4598
+			}
4599
+		}
4600
+		if warehouse.StockMinNumber <= 0 {
4601
+			warehouse.StockMinNumber = 0
4602
+		}
4603
+
4604
+		//fmt.Println("warehouse.StockMaxNumber-------------------", warehouse.StockMaxNumber)
4605
+		//
4606
+		//fmt.Println("warehouse.StockMinNumber-------------------", warehouse.StockMinNumber)
4607
+
4608
+		//扣减库存数据
4609
+		UpDateNewDrugWarehouseInfoByStock(&warehouse, tx)
4610
+
4611
+		////查询剩余库存
4612
+		stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
4613
+		var sum_count int64
4614
+		for _, its := range stockInfo {
4615
+			if its.MaxUnit == drup.MaxUnit {
4616
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
4617
+			}
4618
+			sum_count += its.StockMaxNumber + its.StockMinNumber
4619
+		}
4620
+
4621
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
4622
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
4623
+			WarehouseOutId:          warehouseout.ID,
4624
+			Status:                  1,
4625
+			Ctime:                   advice.RecordDate,
4626
+			Mtime:                   time.Now().Unix(),
4627
+			Remark:                  warehouse.Remark,
4628
+			OrgId:                   orgID,
4629
+			Type:                    1,
4630
+			Manufacturer:            warehouse.Manufacturer,
4631
+			Dealer:                  warehouse.Dealer,
4632
+			IsSys:                   1,
4633
+			SysRecordTime:           advice.RecordDate,
4634
+			DrugId:                  advice.DrugId,
4635
+			Number:                  warehouse.Number,
4636
+			BatchNumber:             warehouse.BatchNumber,
4637
+			Price:                   warehouse.RetailPrice,
4638
+			CountUnit:               drup.MinUnit,
4639
+			RetailPrice:             warehouse.RetailPrice,
4640
+			ProductDate:             warehouse.ProductDate,
4641
+			ExpiryDate:              warehouse.ExpiryDate,
4642
+			PatientId:               advice.PatientId,
4643
+			Count:                   deliver_number, //出最小单位
4644
+			WarehouseInfoId:         warehouse.ID,
4645
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4646
+			StorehouseId:            storeConfig.DrugStorehouseOut,
4647
+			IsCheck:                 1,
4648
+			OverCount:               sum_count,
4649
+			AdviceId:                advice.ID,
4650
+		}
4651
+
4652
+		//查询今日该药品该患者是否有出库数据
4653
+		lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
4654
+
4655
+		if lastDrugOutInfo.ID == 0 {
4656
+			AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
4657
+		}
4658
+		//如果有数量则新增数量
4659
+		if lastDrugOutInfo.ID > 0 {
4660
+
4661
+			UpdateSigleDrugWarehouseOutInfoDetail(lastDrugOutInfo.ID, warehouseOutInfo.Count, tx)
4662
+
4663
+		}
4664
+
4665
+		drugflow := models.DrugFlow{
4666
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
4667
+			WarehouseOutId:          warehouseout.ID,
4668
+			DrugId:                  advice.DrugId,
4669
+			Number:                  warehouse.Number,
4670
+			ProductDate:             warehouse.ProductDate,
4671
+			ExpireDate:              warehouse.ExpiryDate,
4672
+			Count:                   deliver_number, //按最小单位计算,
4673
+			Price:                   warehouse.RetailPrice,
4674
+			Status:                  1,
4675
+			Ctime:                   advice.AdviceDate,
4676
+			Mtime:                   time.Now().Unix(),
4677
+			UserOrgId:               orgID,
4678
+			Manufacturer:            warehouse.Manufacturer,
4679
+			Dealer:                  warehouse.Dealer,
4680
+			BatchNumber:             warehouse.BatchNumber,
4681
+			MaxUnit:                 drup.MinUnit,
4682
+			ConsumableType:          3,
4683
+			IsEdit:                  1,
4684
+			Creator:                 advice.ExecutionStaff,
4685
+			IsSys:                   1,
4686
+			PatientId:               advice.PatientId,
4687
+			SystemTime:              advice.AdviceDate,
4688
+			WarehousingDetailId:     warehouse.ID,
4689
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4690
+			StorehouseId:            storeConfig.DrugStorehouseOut,
4691
+			WarehouseOutDetailId:    lastDrugOutInfo.ID,
4692
+			OverCount:               sum_count,
4693
+			AdviceId:                advice.ID,
4694
+			LastPrice:               warehouse.Price,
4695
+		}
4696
+
4697
+		CreateNewDrugFlowOne(drugflow, tx)
4698
+
4699
+		AddNewDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count, tx)
4700
+
4701
+		//查询是否存在数据
4702
+		details := &models.DrugAutomaticReduceDetail{
4703
+			WarehouseOutId:          warehouseout.ID,
4704
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
4705
+			PatientId:               advice.PatientId,
4706
+			Ctime:                   advice.RecordDate,
4707
+			Mtime:                   time.Now().Unix(),
4708
+			Status:                  1,
4709
+			RecordTime:              advice.RecordDate,
4710
+			OrgId:                   orgID,
4711
+			DrugId:                  advice.DrugId,
4712
+			Count:                   deliver_number,
4713
+			CountUnit:               drup.MinUnit,
4714
+			WarehouseInfoId:         warehouse.ID,
4715
+			StorehouseId:            storeConfig.DrugStorehouseOut,
4716
+			AdviceId:                advice.ID,
4717
+		}
4718
+
4719
+		//查找是否有数据
4720
+		autoMaticReduceDetail, _ := GetDrugAutoMaticReduceDetail(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
4721
+
4722
+		if autoMaticReduceDetail.ID == 0 {
4723
+			AddNewSigleDrugAutoReduceRecordInfo(details, tx)
4724
+		}
4725
+
4726
+		if autoMaticReduceDetail.ID > 0 {
4727
+			UpdateNewSingleDrugAutoReduceRecordInfo(autoMaticReduceDetail.ID, deliver_number, tx)
4728
+		}
4729
+
4730
+		return nil
4731
+
4732
+	} else {
4733
+
4734
+		info := models.XtDrugWarehouseInfo{
4735
+			ID:                warehouse.ID,
4736
+			WarehousingId:     warehouse.WarehousingId,
4737
+			DrugId:            warehouse.DrugId,
4738
+			Number:            warehouse.Number,
4739
+			ProductDate:       warehouse.ProductDate,
4740
+			ExpiryDate:        warehouse.ExpiryDate,
4741
+			WarehousingCount:  warehouse.WarehousingCount,
4742
+			Price:             warehouse.RetailPrice,
4743
+			TotalPrice:        warehouse.TotalPrice,
4744
+			Dealer:            warehouse.Dealer,
4745
+			Manufacturer:      warehouse.Manufacturer,
4746
+			Remark:            warehouse.Remark,
4747
+			Ctime:             warehouse.Ctime,
4748
+			Mtime:             warehouse.Mtime,
4749
+			Status:            1,
4750
+			OrgId:             warehouse.OrgId,
4751
+			IsReturn:          warehouse.IsReturn,
4752
+			WarehousingOrder:  warehouse.WarehousingOrder,
4753
+			Type:              warehouse.Type,
4754
+			RetailPrice:       warehouse.RetailPrice,
4755
+			RetailTotalPrice:  warehouse.RetailPrice,
4756
+			StockMaxNumber:    0,
4757
+			StockMinNumber:    0,
4758
+			BatchNumber:       warehouse.BatchNumber,
4759
+			MaxUnit:           warehouse.MaxUnit,
4760
+			MinUnit:           drup.MinUnit,
4761
+			WarehousingInfoId: warehouse.WarehousingInfoId,
4762
+			SupplyWarehouseId: warehouse.SupplyWarehouseId,
4763
+			StorehouseId:      storeConfig.DrugStorehouseOut,
4764
+			IsCheck:           1,
4765
+		}
4766
+		//扣减库存
4767
+		UpDateNewDrugWarehouseInfoByStock(&info, tx)
4768
+
4769
+		//查询剩余库存
4770
+		stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
4771
+		var sum_count int64
4772
+		for _, its := range stockInfo {
4773
+			if its.MaxUnit == drup.MaxUnit {
4774
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
4775
+			}
4776
+			sum_count += its.StockMaxNumber + its.StockMinNumber
4777
+		}
4778
+
4779
+		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
4780
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
4781
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
4782
+			WarehouseOutId:          warehouseout.ID,
4783
+			Status:                  1,
4784
+			Ctime:                   advice.RecordDate,
4785
+			Mtime:                   time.Now().Unix(),
4786
+			Remark:                  warehouse.Remark,
4787
+			OrgId:                   orgID,
4788
+			Type:                    1,
4789
+			Manufacturer:            warehouse.Manufacturer,
4790
+			Dealer:                  warehouse.Dealer,
4791
+			IsSys:                   1,
4792
+			SysRecordTime:           advice.RecordDate,
4793
+			DrugId:                  advice.DrugId,
4794
+			Number:                  warehouse.Number,
4795
+			BatchNumber:             warehouse.BatchNumber,
4796
+			Price:                   warehouse.RetailPrice,
4797
+			CountUnit:               drup.MinUnit,
4798
+			ProductDate:             warehouse.ProductDate,
4799
+			ExpiryDate:              warehouse.ExpiryDate,
4800
+			PatientId:               advice.PatientId,
4801
+			Count:                   stock_number,
4802
+			WarehouseInfoId:         warehouse.ID,
4803
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4804
+			StorehouseId:            storeConfig.DrugStorehouseOut,
4805
+			IsCheck:                 1,
4806
+			OverCount:               sum_count,
4807
+			AdviceId:                advice.ID,
4808
+		}
4809
+
4810
+		//查询今日该药品该患者是否有出库数据
4811
+		lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
4812
+
4813
+		if lastDrugOutInfo.ID == 0 {
4814
+			AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
4815
+		}
4816
+		//如果有数量则新增数量
4817
+		if lastDrugOutInfo.ID > 0 {
4818
+
4819
+			UpdateSigleDrugWarehouseOutInfoDetail(lastDrugOutInfo.ID, warehouseOutInfo.Count, tx)
4820
+
4821
+		}
4822
+
4823
+		//查询是否存在数据
4824
+		details := &models.DrugAutomaticReduceDetail{
4825
+			WarehouseOutId:          warehouseout.ID,
4826
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
4827
+			PatientId:               advice.PatientId,
4828
+			Ctime:                   advice.RecordDate,
4829
+			Mtime:                   time.Now().Unix(),
4830
+			Status:                  1,
4831
+			RecordTime:              advice.RecordDate,
4832
+			OrgId:                   orgID,
4833
+			DrugId:                  advice.DrugId,
4834
+			Count:                   stock_number,
4835
+			CountUnit:               drup.MinUnit,
4836
+			WarehouseInfoId:         warehouse.ID,
4837
+			StorehouseId:            storeConfig.DrugStorehouseOut,
4838
+			AdviceId:                advice.ID,
4839
+		}
4840
+
4841
+		//查找是否有数据
4842
+		autoMaticReduceDetail, _ := GetDrugAutoMaticReduceDetail(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
4843
+
4844
+		if autoMaticReduceDetail.ID == 0 {
4845
+			AddNewSigleDrugAutoReduceRecordInfo(details, tx)
4846
+		}
4847
+
4848
+		if autoMaticReduceDetail.ID > 0 {
4849
+			UpdateNewSingleDrugAutoReduceRecordInfo(autoMaticReduceDetail.ID, deliver_number, tx)
4850
+		}
4851
+
4852
+		drugflow := models.DrugFlow{
4853
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
4854
+			WarehouseOutId:          warehouseout.ID,
4855
+			DrugId:                  advice.DrugId,
4856
+			Number:                  warehouse.Number,
4857
+			ProductDate:             warehouse.ProductDate,
4858
+			ExpireDate:              warehouse.ExpiryDate,
4859
+			Count:                   stock_number,
4860
+			Price:                   warehouse.RetailPrice,
4861
+			Status:                  1,
4862
+			Ctime:                   advice.AdviceDate,
4863
+			Mtime:                   time.Now().Unix(),
4864
+			UserOrgId:               orgID,
4865
+			Manufacturer:            warehouse.Manufacturer,
4866
+			Dealer:                  warehouse.Dealer,
4867
+			BatchNumber:             warehouse.BatchNumber,
4868
+			MaxUnit:                 drup.MinUnit,
4869
+			ConsumableType:          3,
4870
+			IsEdit:                  1,
4871
+			Creator:                 advice.ExecutionStaff,
4872
+			IsSys:                   1,
4873
+			PatientId:               advice.PatientId,
4874
+			WarehousingDetailId:     warehouse.ID,
4875
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4876
+			StorehouseId:            storeConfig.DrugStorehouseOut,
4877
+			WarehouseOutDetailId:    lastDrugOutInfo.ID,
4878
+			OverCount:               sum_count,
4879
+			AdviceId:                advice.ID,
4880
+			LastPrice:               warehouse.Price,
4881
+			SystemTime:              advice.AdviceDate,
4882
+		}
4883
+
4884
+		CreateNewDrugFlowOne(drugflow, tx)
4885
+		//出库数量相加
4886
+		AddNewDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count, tx)
4887
+
4888
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
4889
+		prescribingNumber_two_temp := deliver_number - stock_number
4890
+
4891
+		overPlusNumber := float64(prescribingNumber_two_temp)
4892
+
4893
+		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
4894
+		advice.PrescribingNumberUnit = drup.MinUnit
4895
+
4896
+		HisStoryBloodHisDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice, hisprescribingNumber, unit, tx)
4897
+	}
4898
+
4899
+	return
4900
+}
4901
+
4902
+func NewHisDrugCancelInfo(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo, cha_count int64, drug models.BaseDrugLibSeven, tx *gorm.DB) (err error) {
4903
+
4904
+	storeConfig, _ := GetNewAllStoreHouseConfig(advice.UserOrgId, tx)
4905
+
4906
+	//查找患者最后一条的退库数据是否满足要求
4907
+	var out_count int64
4908
+	drugOutInfo, _ := GetDrugWarehouseOutInfoByAdviceIdTwo(advice.PatientId, advice.UserOrgId, advice.AdviceDate, advice.DrugId, advice.ID, tx)
4909
+
4910
+	if drugOutInfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4911
+
4912
+		out_count = drugOutInfo.Count * drug.MinNumber
4913
+	}
4914
+
4915
+	if drugOutInfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4916
+
4917
+		out_count = drugOutInfo.Count
4918
+	}
4919
+
4920
+	if drugOutInfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
4921
+
4922
+		out_count = drugOutInfo.Count
4923
+	}
4924
+
4925
+	//如果最后1条出库数量大于退库数量,则直接退库,满足退库要求
4926
+	if out_count >= cha_count {
4927
+		//退库 退回 cha_count 的数量
4928
+		ModifyNewDrugWarehouseInfoStockMinNumber(cha_count, drugOutInfo.DrugId, drugOutInfo.OrgId, drugOutInfo.WarehouseInfoId, tx)
4929
+
4930
+		if out_count == cha_count {
4931
+			//删除该出库单
4932
+			DeleteDrugWarehouseOutInfoByNumber(drugOutInfo.ID, tx)
4933
+		}
4934
+
4935
+		//减去出库单里面的数量
4936
+		ModifyDrugWarehouseOutInfoByNumber(drugOutInfo.ID, cha_count, tx)
4937
+
4938
+		//创建退库单
4939
+		//查询剩余库存
4940
+		stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
4941
+		var sum_count int64
4942
+		for _, its := range stockInfo {
4943
+			if its.MaxUnit == drug.MaxUnit {
4944
+				its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
4945
+			}
4946
+			sum_count += its.StockMaxNumber + its.StockMinNumber
4947
+		}
4948
+
4949
+		//创建退库单
4950
+		operation_time := time.Now().Unix()
4951
+		ctime := time.Now().Unix()
4952
+		timeStr := time.Now().Format("2006-01-02")
4953
+		timeArr := strings.Split(timeStr, "-")
4954
+		total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
4955
+		total = total + 1
4956
+		orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
4957
+		cancelStock := models.DrugCancelStock{
4958
+			OrderNumber:  orderNumber,
4959
+			OperaTime:    operation_time,
4960
+			OrgId:        advice.UserOrgId,
4961
+			Creater:      advice.ExecutionStaff,
4962
+			Ctime:        ctime,
4963
+			Status:       1,
4964
+			ReturnTime:   advice.AdviceDate,
4965
+			Dealer:       0,
4966
+			Manufacturer: 0,
4967
+			Type:         1,
4968
+			StorehouseId: storeConfig.DrugStorehouseOut,
4969
+			IsCheck:      1,
4970
+		}
4971
+
4972
+		_, errCode := FindNewDrugCancelStock(advice.AdviceDate, advice.UserOrgId, tx)
4973
+		if errCode == gorm.ErrRecordNotFound {
4974
+			AddNewSigleDrugCancelStock(&cancelStock, tx)
4975
+		}
4976
+		lastDrugCancelStock, _ := FindNewLastDrugCancelStock(advice.AdviceDate, advice.UserOrgId, tx)
4977
+
4978
+		manufactureName, _ := GetNewManufactureById(drugOutInfo.Manufacturer, tx)
4979
+		dealer, _ := GetNewDealerById(drugOutInfo.Dealer, tx)
4980
+		cancelInfo, _ := GetNewLastDrugCancelStockById(advice.UserOrgId, tx)
4981
+		cancelStockInfo := models.DrugCancelStockInfo{
4982
+			OrderNumber:      cancelInfo.OrderNumber,
4983
+			CancelStockId:    lastDrugCancelStock.ID,
4984
+			DrugId:           advice.DrugId,
4985
+			Count:            cha_count,
4986
+			Status:           1,
4987
+			Ctime:            advice.AdviceDate,
4988
+			Mtime:            time.Now().Unix(),
4989
+			OrgId:            advice.UserOrgId,
4990
+			Type:             1,
4991
+			Manufacturer:     manufactureName.ManufacturerName,
4992
+			Dealer:           dealer.DealerName,
4993
+			Total:            0,
4994
+			RetailPrice:      drugOutInfo.RetailPrice,
4995
+			RetailTotalPrice: drugOutInfo.RetailTotalPrice,
4996
+			Price:            drugOutInfo.Price,
4997
+			RegisterAccount:  "",
4998
+			Remark:           drugOutInfo.Remark,
4999
+			BatchNumber:      drugOutInfo.BatchNumber,
5000
+			MaxUnit:          drugOutInfo.CountUnit,
5001
+			ProductDate:      drugOutInfo.ProductDate,
5002
+			ExpiryDate:       drugOutInfo.ExpiryDate,
5003
+			BatchNumberId:    drugOutInfo.WarehouseInfoId,
5004
+			StorehouseId:     storeConfig.DrugStorehouseOut,
5005
+			IsCheck:          1,
5006
+		}
5007
+		CreatedNewCancelStock(cancelStockInfo, tx)
5008
+
5009
+		flow := models.DrugFlow{
5010
+			WarehousingId:           drugOutInfo.WarehouseInfoId,
5011
+			DrugId:                  drugOutInfo.DrugId,
5012
+			Number:                  "",
5013
+			BatchNumber:             drugOutInfo.BatchNumber,
5014
+			Count:                   cha_count,
5015
+			UserOrgId:               advice.UserOrgId,
5016
+			PatientId:               advice.PatientId,
5017
+			SystemTime:              advice.AdviceDate,
5018
+			ConsumableType:          7,
5019
+			IsSys:                   0,
5020
+			WarehousingOrder:        "",
5021
+			WarehouseOutId:          0,
5022
+			WarehouseOutOrderNumber: "",
5023
+			IsEdit:                  0,
5024
+			CancelStockId:           cancelStock.ID,
5025
+			CancelOrderNumber:       cancelStock.OrderNumber,
5026
+			Manufacturer:            drugOutInfo.Manufacturer,
5027
+			Dealer:                  drugOutInfo.Dealer,
5028
+			Creator:                 advice.ExecutionStaff,
5029
+			UpdateCreator:           0,
5030
+			Status:                  1,
5031
+			Ctime:                   advice.AdviceDate,
5032
+			Mtime:                   time.Now().Unix(),
5033
+			Price:                   drugOutInfo.RetailPrice,
5034
+			WarehousingDetailId:     drugOutInfo.ID,
5035
+			WarehouseOutDetailId:    0,
5036
+			CancelOutDetailId:       lastDrugCancelStock.ID,
5037
+			ExpireDate:              drugOutInfo.ExpiryDate,
5038
+			ProductDate:             drugOutInfo.ProductDate,
5039
+			MaxUnit:                 drugOutInfo.CountUnit,
5040
+			MinUnit:                 "",
5041
+			AdviceId:                advice.ID,
5042
+			StorehouseId:            storeConfig.DrugStorehouseOut,
5043
+			LastPrice:               drugOutInfo.Price,
5044
+			OverCount:               sum_count,
5045
+		}
5046
+		CreateNewDrugFlowOne(flow, tx)
5047
+
5048
+		AddNewCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count, tx)
5049
+
5050
+		ReduceNewDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count, tx)
5051
+
5052
+	}
5053
+
5054
+	//如果出库的数据小于这个退库的数量差,则先该批次出库数量出完
5055
+	if out_count < cha_count {
5056
+
5057
+		//把该出库单的数量退完
5058
+		ModifyNewDrugWarehouseInfoStockMinNumber(out_count, drugOutInfo.DrugId, drugOutInfo.OrgId, drugOutInfo.WarehouseInfoId, tx)
5059
+
5060
+		//删除该出库单
5061
+		DeleteDrugWarehouseOutInfoByNumber(drugOutInfo.ID, tx)
5062
+
5063
+		//创建退库单
5064
+		//查询剩余库存
5065
+		stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
5066
+		var sum_count int64
5067
+		for _, its := range stockInfo {
5068
+			if its.MaxUnit == drug.MaxUnit {
5069
+				its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
5070
+			}
5071
+			sum_count += its.StockMaxNumber + its.StockMinNumber
5072
+		}
5073
+
5074
+		//创建退库单
5075
+		operation_time := time.Now().Unix()
5076
+		ctime := time.Now().Unix()
5077
+		timeStr := time.Now().Format("2006-01-02")
5078
+		timeArr := strings.Split(timeStr, "-")
5079
+		total, _ := FindAllDrugCancelStockTotal(advice.UserOrgId)
5080
+		total = total + 1
5081
+		orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
5082
+		cancelStock := models.DrugCancelStock{
5083
+			OrderNumber:  orderNumber,
5084
+			OperaTime:    operation_time,
5085
+			OrgId:        advice.UserOrgId,
5086
+			Creater:      advice.ExecutionStaff,
5087
+			Ctime:        ctime,
5088
+			Status:       1,
5089
+			ReturnTime:   advice.AdviceDate,
5090
+			Dealer:       0,
5091
+			Manufacturer: 0,
5092
+			Type:         1,
5093
+			StorehouseId: storeConfig.DrugStorehouseOut,
5094
+			IsCheck:      1,
5095
+		}
5096
+
5097
+		_, errCode := FindNewDrugCancelStock(advice.AdviceDate, advice.UserOrgId, tx)
5098
+		if errCode == gorm.ErrRecordNotFound {
5099
+			AddNewSigleDrugCancelStock(&cancelStock, tx)
5100
+		}
5101
+		lastDrugCancelStock, _ := FindNewLastDrugCancelStock(advice.AdviceDate, advice.UserOrgId, tx)
5102
+
5103
+		manufactureName, _ := GetNewManufactureById(drugOutInfo.Manufacturer, tx)
5104
+		dealer, _ := GetNewDealerById(drugOutInfo.Dealer, tx)
5105
+		cancelInfo, _ := GetNewLastDrugCancelStockById(advice.UserOrgId, tx)
5106
+		cancelStockInfo := models.DrugCancelStockInfo{
5107
+			OrderNumber:      cancelInfo.OrderNumber,
5108
+			CancelStockId:    lastDrugCancelStock.ID,
5109
+			DrugId:           advice.DrugId,
5110
+			Count:            out_count,
5111
+			Status:           1,
5112
+			Ctime:            advice.AdviceDate,
5113
+			Mtime:            time.Now().Unix(),
5114
+			OrgId:            advice.UserOrgId,
5115
+			Type:             1,
5116
+			Manufacturer:     manufactureName.ManufacturerName,
5117
+			Dealer:           dealer.DealerName,
5118
+			Total:            0,
5119
+			RetailPrice:      drugOutInfo.RetailPrice,
5120
+			RetailTotalPrice: drugOutInfo.RetailTotalPrice,
5121
+			Price:            drugOutInfo.Price,
5122
+			RegisterAccount:  "",
5123
+			Remark:           drugOutInfo.Remark,
5124
+			BatchNumber:      drugOutInfo.BatchNumber,
5125
+			MaxUnit:          drugOutInfo.CountUnit,
5126
+			ProductDate:      drugOutInfo.ProductDate,
5127
+			ExpiryDate:       drugOutInfo.ExpiryDate,
5128
+			BatchNumberId:    drugOutInfo.WarehouseInfoId,
5129
+			StorehouseId:     storeConfig.DrugStorehouseOut,
5130
+			IsCheck:          1,
5131
+		}
5132
+		CreatedNewCancelStock(cancelStockInfo, tx)
5133
+
5134
+		flow := models.DrugFlow{
5135
+			WarehousingId:           drugOutInfo.WarehouseInfoId,
5136
+			DrugId:                  drugOutInfo.DrugId,
5137
+			Number:                  "",
5138
+			BatchNumber:             drugOutInfo.BatchNumber,
5139
+			Count:                   out_count,
5140
+			UserOrgId:               advice.UserOrgId,
5141
+			PatientId:               advice.PatientId,
5142
+			SystemTime:              advice.AdviceDate,
5143
+			ConsumableType:          7,
5144
+			IsSys:                   0,
5145
+			WarehousingOrder:        "",
5146
+			WarehouseOutId:          0,
5147
+			WarehouseOutOrderNumber: "",
5148
+			IsEdit:                  0,
5149
+			CancelStockId:           cancelStock.ID,
5150
+			CancelOrderNumber:       cancelStock.OrderNumber,
5151
+			Manufacturer:            drugOutInfo.Manufacturer,
5152
+			Dealer:                  drugOutInfo.Dealer,
5153
+			Creator:                 advice.ExecutionStaff,
5154
+			UpdateCreator:           0,
5155
+			Status:                  1,
5156
+			Ctime:                   advice.AdviceDate,
5157
+			Mtime:                   time.Now().Unix(),
5158
+			Price:                   drugOutInfo.RetailPrice,
5159
+			WarehousingDetailId:     drugOutInfo.ID,
5160
+			WarehouseOutDetailId:    0,
5161
+			CancelOutDetailId:       lastDrugCancelStock.ID,
5162
+			ExpireDate:              drugOutInfo.ExpiryDate,
5163
+			ProductDate:             drugOutInfo.ProductDate,
5164
+			MaxUnit:                 drugOutInfo.CountUnit,
5165
+			MinUnit:                 "",
5166
+			AdviceId:                advice.ID,
5167
+			StorehouseId:            storeConfig.DrugStorehouseOut,
5168
+			LastPrice:               drugOutInfo.Price,
5169
+			OverCount:               sum_count,
5170
+		}
5171
+		CreateNewDrugFlowOne(flow, tx)
5172
+
5173
+		AddNewCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count, tx)
5174
+
5175
+		ReduceNewDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count, tx)
5176
+
5177
+		//计算还有多少没有退库
5178
+		var over_count = cha_count - out_count
5179
+
5180
+		NewHisDrugCancelInfo(orgID, creater, advice, over_count, drug, tx)
5181
+	}
5182
+	return err
5183
+
5184
+}
5185
+
5186
+func NewHisDrugAutoCancelInfo(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo, cha_count int64, drug models.BaseDrugLibSeven, tx *gorm.DB) error {
5187
+
5188
+	//查找患者最后一条的退库数据是否满足要求
5189
+	var out_count int64
5190
+	drugOutInfo, _ := GetDrugAutoOutInfoByAdviceIdTwo(advice.PatientId, advice.UserOrgId, advice.AdviceDate, advice.DrugId, advice.ID, tx)
5191
+
5192
+	if drugOutInfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
5193
+
5194
+		out_count = drugOutInfo.Count * drug.MinNumber
5195
+	}
5196
+
5197
+	if drugOutInfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
5198
+
5199
+		out_count = drugOutInfo.Count
5200
+	}
5201
+
5202
+	if drugOutInfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
5203
+
5204
+		out_count = drugOutInfo.Count
5205
+	}
5206
+
5207
+	//fmt.Println("out_count++++==++", out_count)
5208
+	//fmt.Println("cha_count-------", cha_count)
5209
+
5210
+	//如果最后1条出库数量大于退库数量,则直接退库,满足退库要求
5211
+	if out_count >= cha_count {
5212
+		//减去出库单里面的数量
5213
+		ModifyDrugAuToWarehouseOut(drugOutInfo.ID, cha_count, tx)
5214
+
5215
+		if out_count == cha_count {
5216
+			//删除该出库单
5217
+			DeleteDrugWarehouseAutoByNumber(drugOutInfo.ID, tx)
5218
+		}
5219
+	}
5220
+
5221
+	//如果出库的数据小于这个退库的数量差,则先该批次出库数量出完
5222
+	if out_count < cha_count {
5223
+
5224
+		//删除该出库单
5225
+		DeleteDrugWarehouseAutoByNumber(drugOutInfo.ID, tx)
5226
+
5227
+		//计算还有多少没有退库
5228
+		var over_count = cha_count - out_count
5229
+
5230
+		NewHisDrugAutoCancelInfo(orgID, creater, advice, over_count, drug, tx)
5231
+	}
5232
+	return err
5233
+}

+ 11 - 7
service/pharmacy_service.go View File

@@ -300,7 +300,6 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
300 300
 				DataSources:  "临时医嘱",
301 301
 				Remarks:      v.Remark,
302 302
 				DrugId:       v.DrugId,
303
-				Price:        v.Price,
304 303
 			})
305 304
 		}
306 305
 		return
@@ -370,7 +369,8 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
370 369
 				ExecutionState: v.ExecutionState,
371 370
 				ExecutionStaff: v.ExecutionStaff,
372 371
 				ExecutionTime:  v.ExecutionTime,
373
-				Price:          v.Price,
372
+				//Price:        v.Price,
373
+
374 374
 			})
375 375
 		}
376 376
 		return
@@ -867,12 +867,16 @@ func DispensingMedicineOne(orgid, patient_id, stime, etime, creater int64) (err
867 867
 	if len(adviceList) > 0 {
868 868
 		for _, item := range adviceList {
869 869
 
870
-			//扣减库存
871
-			err = HisDrugsDelivery(orgid, creater, item)
872
-			if err != nil {
873
-				err = fmt.Errorf("!:%v", err)
874
-				return
870
+			pharmacyConfig := IsPharmacyConfig(orgid)
871
+			if pharmacyConfig == true {
872
+				//扣减库存
873
+				err = HisDrugsDelivery(orgid, creater, item)
874
+				if err != nil {
875
+					err = fmt.Errorf("!:%v", err)
876
+					return
877
+				}
875 878
 			}
879
+
876 880
 			//修改发药状态
877 881
 			err = UpdateIsMedicalHisAdvice(item.ID)
878 882
 			if err != nil {

+ 13 - 7
service/schedule_service.go View File

@@ -1524,8 +1524,14 @@ func GetDoctorAdviceListSchedule(org_id int64, patient_id int64) (advices []*mod
1524 1524
 func GetLastDialysisPrescriptionTwo(org_id int64, patient_id int64, mode_id int64, schedule_date int64) (models.NewDialysisPrescription, error) {
1525 1525
 
1526 1526
 	dialysisprescription := models.NewDialysisPrescription{}
1527
-	err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode_id = ? and status = 1 and record_date = ?", org_id, patient_id, mode_id, schedule_date).Order("id desc").First(&dialysisprescription).Error
1528
-	return dialysisprescription, err
1527
+
1528
+	if org_id == 10340 {
1529
+		err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode_id = ? and status = 1 and record_date <= ?", org_id, patient_id, mode_id, schedule_date).Order("id desc").Last(&dialysisprescription).Error
1530
+		return dialysisprescription, err
1531
+	} else {
1532
+		err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode_id = ? and status = 1 and record_date = ?", org_id, patient_id, mode_id, schedule_date).Order("id desc").First(&dialysisprescription).Error
1533
+		return dialysisprescription, err
1534
+	}
1529 1535
 
1530 1536
 }
1531 1537
 
@@ -1838,23 +1844,23 @@ func GetHisPrescriptionProjectList(patient_id int64, record_date int64, user_org
1838 1844
 
1839 1845
 func UpdateProjectObj(patient_id int64, schedule_date int64, user_org_id int64) (err error) {
1840 1846
 
1841
-	err = XTWriteDB().Model(&models.HisPrescriptionProject{}).Where("patient_id = ? and record_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 9}).Error
1847
+	err = XTWriteDB().Model(&models.HisPrescriptionProject{}).Where("patient_id = ? and record_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
1842 1848
 
1843
-	err = XTWriteDB().Model(&models.HisPrescription{}).Where("patient_id = ? and status=1 and record_date = ? and user_org_id =?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 9}).Error
1849
+	err = XTWriteDB().Model(&models.HisPrescription{}).Where("patient_id = ? and status=1 and record_date = ? and user_org_id =?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
1844 1850
 
1845
-	err = XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("patient_id = ? and status=1 and record_date = ? and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 9}).Error
1851
+	err = XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("patient_id = ? and status=1 and record_date = ? and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
1846 1852
 	return err
1847 1853
 }
1848 1854
 
1849 1855
 func UpdateAdviceObj(patient_id int64, schedule_date int64, user_org_id int64) (err error) {
1850 1856
 
1851
-	err = XTWriteDB().Model(&models.XtDoctorAdvice{}).Where("patient_id = ? and advice_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 9}).Error
1857
+	err = XTWriteDB().Model(&models.XtDoctorAdvice{}).Where("patient_id = ? and advice_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
1852 1858
 	return err
1853 1859
 }
1854 1860
 
1855 1861
 func UpdateHisAdviceObj(patient_id int64, schedule_date int64, user_org_id int64) (err error) {
1856 1862
 
1857
-	err = XTWriteDB().Model(&models.HisDoctorAdvice{}).Where("patient_id = ? and advice_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 9}).Error
1863
+	err = XTWriteDB().Model(&models.HisDoctorAdvice{}).Where("patient_id = ? and advice_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
1858 1864
 	return err
1859 1865
 }
1860 1866
 

+ 1 - 1
service/self_drug_service.go View File

@@ -2002,7 +2002,7 @@ func GetDrugWarehouseInfoName(drugid int64, orgid int64) (info []*models.DrugWar
2002 2002
 
2003 2003
 func UpdateDrugById(id int64, orgid int64, limit_count int64, total_count int64) error {
2004 2004
 
2005
-	err := XTWriteDB().Model(&models.BaseDrugLibTen{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_stock_limit_count": limit_count, "total_count": total_count}).Error
2005
+	err := XTWriteDB().Model(&models.BaseDrugLibTen{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_stock_limit_count": limit_count, "sum_count": total_count}).Error
2006 2006
 	return err
2007 2007
 }
2008 2008
 

+ 11 - 3
service/sign_service.go View File

@@ -2112,14 +2112,22 @@ func UpdateAllPatient(id int64, diagose string, orgid int64) error {
2112 2112
 
2113 2113
 func GetAllDialysisOrder(user_org_id int64) (list []*models.XtDialysisOrder, err error) {
2114 2114
 
2115
-	err = XTReadDB().Where("patient_id = ? and status =1", 21767).Find(&list).Error
2115
+	err = XTReadDB().Where("patient_id = ? and status =1", 28449).Find(&list).Error
2116 2116
 
2117 2117
 	return list, err
2118 2118
 }
2119 2119
 
2120
-func UpdateScheduleByOrder(patient_id int64, schedule_date int64, user_org_id int64, bed_id int64, zone_id int64, shcedule_type int64) error {
2120
+func GetLastScheduleByUserOrg(patient_id int64, schedule_date int64, user_org_id int64, bed_id int64, zone_id int64, shcedule_type int64) (models.Schedule, error) {
2121 2121
 
2122
-	err := XTWriteDB().Model(&models.XtSchedule{}).Where("schedule_date =? and user_org_id =? and patient_id =?", schedule_date, user_org_id, patient_id).Updates(map[string]interface{}{"bed_id": bed_id, "partition_id": zone_id, "schedule_type": shcedule_type, "status": 1}).Error
2122
+	schedule := models.Schedule{}
2123
+	err := XTReadDB().Where("patient_id = ? and schedule_date = ? and status=0", patient_id, schedule_date).First(&schedule).Error
2124
+
2125
+	return schedule, err
2126
+}
2127
+
2128
+func UpdateScheduleByOrder(patient_id int64, schedule_date int64, user_org_id int64, bed_id int64, zone_id int64, shcedule_type int64, id int64) error {
2129
+
2130
+	err := XTWriteDB().Model(&models.XtSchedule{}).Where("id = ?", id).Updates(map[string]interface{}{"bed_id": bed_id, "partition_id": zone_id, "schedule_type": shcedule_type, "status": 1}).Error
2123 2131
 	return err
2124 2132
 }
2125 2133
 

+ 48 - 7
service/stock_service.go View File

@@ -876,6 +876,11 @@ func FindLastDrugWarehousingInfoByID(drug_id int64, storehouse_id int64) (info m
876 876
 	return info, err
877 877
 }
878 878
 
879
+func FindLastDrugWarehousingInfoByIDTwo(drug_id int64, storehouse_id int64) (info models.XtDrugWarehouseInfo, err error) {
880
+	err = readDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 and storehouse_id = ? and is_check = 1", drug_id, storehouse_id).Order("ctime").Last(&info).Error
881
+	return info, err
882
+}
883
+
879 884
 func FindNewLastDrugWarehousingInfoByID(drug_id int64, storehouse_id int64, tx *gorm.DB) (info models.XtDrugWarehouseInfo, err error) {
880 885
 	err = tx.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) and storehouse_id = ? and is_check = 1", drug_id, storehouse_id).Order("ctime").First(&info).Error
881 886
 	if err != gorm.ErrRecordNotFound {
@@ -3468,6 +3473,20 @@ func AddNewSigleDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo, tx *gorm
3468 3473
 	}
3469 3474
 	return err
3470 3475
 }
3476
+
3477
+func UpdateSigleDrugWarehouseOutInfoDetail(id int64, count int64, tx *gorm.DB) error {
3478
+
3479
+	err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status=1", id).UpdateColumn("count", gorm.Expr("count + ?", count)).Error
3480
+
3481
+	err = tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status=1", id).UpdateColumn("over_count", gorm.Expr("over_count - ?", count)).Error
3482
+	if err != nil {
3483
+		tx.Rollback()
3484
+		return err
3485
+	}
3486
+
3487
+	return err
3488
+}
3489
+
3471 3490
 func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
3472 3491
 	ut := writeDb.Begin()
3473 3492
 	err := ut.Create(&detail).Error
@@ -3485,6 +3504,31 @@ func AddSigleDrugAutoReduceRecordInfo(detail *models.DrugAutomaticReduceDetail)
3485 3504
 
3486 3505
 }
3487 3506
 
3507
+func GetDrugAutoMaticReduceDetail(drug_id int64, patient_id int64, record_time int64, org_id int64, adivce_id int64, warehouse_info_id int64, tx *gorm.DB) (models.DrugAutomaticReduceDetail, error) {
3508
+
3509
+	detail := models.DrugAutomaticReduceDetail{}
3510
+	err := tx.Where("drug_id = ? and patient_id =? and record_time =? and org_id = ? and advice_id = ? and warehouse_info_id =?", drug_id, patient_id, record_time, org_id, adivce_id, warehouse_info_id).Find(&detail).Error
3511
+
3512
+	if err != gorm.ErrRecordNotFound {
3513
+		if err != nil {
3514
+			tx.Rollback()
3515
+			return detail, err
3516
+		}
3517
+	}
3518
+	return detail, err
3519
+}
3520
+
3521
+func UpdateNewSingleDrugAutoReduceRecordInfo(id int64, count int64, tx *gorm.DB) error {
3522
+
3523
+	err := tx.Model(models.DrugAutomaticReduceDetail{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count + ?", count)).Error
3524
+
3525
+	if err != nil {
3526
+		tx.Rollback()
3527
+		return err
3528
+	}
3529
+	return err
3530
+}
3531
+
3488 3532
 func AddNewSigleDrugAutoReduceRecordInfo(detail *models.DrugAutomaticReduceDetail, tx *gorm.DB) error {
3489 3533
 
3490 3534
 	err := tx.Create(&detail).Error
@@ -5923,14 +5967,11 @@ func DeleteDrugAutoWarehouseSeven(drugid int64, patient_id int64, record_time in
5923 5967
 	return err
5924 5968
 }
5925 5969
 
5926
-func DeleteNewDrugAutoWarehouseSeven(drugid int64, patient_id int64, record_time int64, advice_id int64, tx *gorm.DB) error {
5970
+func DeleteNewDrugAutoWarehouseSeven(drugid int64, patient_id int64, record_time int64, advice_id int64) error {
5971
+
5972
+	err := XTWriteDB().Model(models.DrugAutomaticReduceDetail{}).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1", drugid, patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
5973
+	err = XTWriteDB().Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
5927 5974
 
5928
-	err := tx.Model(models.DrugAutomaticReduceDetail{}).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
5929
-	err = tx.Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
5930
-	if err != nil {
5931
-		tx.Rollback()
5932
-		return err
5933
-	}
5934 5975
 	return err
5935 5976
 }
5936 5977
 

+ 1 - 3
service/warhouse_service.go View File

@@ -7849,7 +7849,6 @@ func NewHisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdv
7849 7849
 	if isHasWay {
7850 7850
 		//判断当天当前机构有没有创建出库单,没有则创建
7851 7851
 		out, err := FindNewDrugStockOutByIsSys(orgID, 1, record_time, tx)
7852
-		fmt.Println(out)
7853 7852
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
7854 7853
 		if err == gorm.ErrRecordNotFound {
7855 7854
 			timeStr := time.Now().Format("2006-01-02")
@@ -7890,8 +7889,7 @@ func NewHisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdv
7890 7889
 		drup, _ := FindNewBaseDrugLibRecord(orgID, advice.DrugId, tx)
7891 7890
 		if drup.ID > 0 {
7892 7891
 			prescribingNumber := advice.PrescribingNumber
7893
-			fmt.Println(prescribingNumber)
7894
-			NewBloodHisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit, tx)
7892
+			HisStoryBloodHisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit, tx)
7895 7893
 
7896 7894
 		} else {
7897 7895
 			return errors.New("药品信息不存在")