소스 검색

历史排班

28169 10 달 전
부모
커밋
28bbc071d8

+ 6 - 6
controllers/base_api_controller.go 파일 보기

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

+ 40 - 0
controllers/dialysis_api_controller.go 파일 보기

@@ -148,6 +148,8 @@ func DialysisApiRegistRouters() {
148 148
 	beego.Router("/api/patient/getpatientrecordlist", &DialysisApiController{}, "Get:GetPatientRecordList")
149 149
 
150 150
 	beego.Router("/api/patient/getdialysistotalcount", &DialysisApiController{}, "Get:GetDialysisTotalCount")
151
+
152
+	beego.Router("/api/schedule/getdialysisproject", &DialysisApiController{}, "Get:GetDialysisProject")
151 153
 }
152 154
 
153 155
 func (c *DialysisApiController) GetQueueCall() {
@@ -2670,6 +2672,8 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
2670 2672
 
2671 2673
 				if adminUserInfo.CurrentOrgId == 10579 {
2672 2674
 					newprescribe.Modifier = 0
2675
+					newprescribe.PrescriptionDoctor = 0
2676
+					newprescribe.Creater = 0
2673 2677
 				}
2674 2678
 				err := service.AddSigleRecord(&newprescribe)
2675 2679
 
@@ -2748,6 +2752,8 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
2748 2752
 					newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
2749 2753
 					if adminUserInfo.CurrentOrgId == 10579 {
2750 2754
 						newprescribe.Modifier = 0
2755
+						newprescribe.PrescriptionDoctor = 0
2756
+						newprescribe.Creater = 0
2751 2757
 					}
2752 2758
 					err := service.AddSigleRecord(&newprescribe)
2753 2759
 					//记录日志
@@ -2793,6 +2799,8 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
2793 2799
 					newprescribe.Modifier = adminUserInfo.AdminUser.Id
2794 2800
 					if adminUserInfo.CurrentOrgId == 10579 {
2795 2801
 						newprescribe.Modifier = 0
2802
+						newprescribe.PrescriptionDoctor = 0
2803
+						newprescribe.Creater = 0
2796 2804
 					}
2797 2805
 					err := service.AddSigleRecord(&newprescribe)
2798 2806
 					//记录日志
@@ -2984,6 +2992,8 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
2984 2992
 			newprescribe.Status = 1
2985 2993
 			if adminUserInfo.CurrentOrgId == 10579 {
2986 2994
 				newprescribe.Modifier = 0
2995
+				newprescribe.PrescriptionDoctor = 0
2996
+				newprescribe.Creater = 0
2987 2997
 			}
2988 2998
 			err := service.AddSigleRecord(&newprescribe)
2989 2999
 			//记录日志
@@ -3059,6 +3069,8 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
3059 3069
 				newprescribe.Status = 1
3060 3070
 				if adminUserInfo.CurrentOrgId == 10579 {
3061 3071
 					newprescribe.Modifier = 0
3072
+					newprescribe.PrescriptionDoctor = 0
3073
+					newprescribe.Creater = 0
3062 3074
 				}
3063 3075
 				err := service.AddSigleRecord(&newprescribe)
3064 3076
 				//记录日志
@@ -7044,6 +7056,34 @@ func (this *DialysisApiController) GetDialysisAdviceToday() {
7044 7056
 	}
7045 7057
 }
7046 7058
 
7059
+func (this *DialysisApiController) GetDialysisProject() {
7060
+
7061
+	orgId := this.GetAdminUserInfo().CurrentOrgId
7062
+
7063
+	schedule_type, _ := this.GetInt64("schedule_type")
7064
+
7065
+	partion_type := this.GetString("partion_type")
7066
+	var ids []string
7067
+	ids = strings.Split(partion_type, ",")
7068
+	start_time := this.GetString("selected_date")
7069
+	timeLayout := "2006-01-02"
7070
+	loc, _ := time.LoadLocation("Local")
7071
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
7072
+
7073
+	list, err := service.GetDialysisProjectSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
7074
+
7075
+	if err == nil {
7076
+		this.ServeSuccessJSON(map[string]interface{}{
7077
+			"list": list,
7078
+		})
7079
+		return
7080
+
7081
+	} else {
7082
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
7083
+		return
7084
+	}
7085
+}
7086
+
7047 7087
 func (this *DialysisApiController) GetMobileScheduleList() {
7048 7088
 
7049 7089
 	orgId := this.GetAdminUserInfo().CurrentOrgId

+ 27 - 7
controllers/dialysis_record_api_controller.go 파일 보기

@@ -249,6 +249,7 @@ func (this *DialysisRecordAPIController) DialysisSchedule() {
249 249
 		recordDateStr = time.Now().Format("2006-01-02")
250 250
 	}
251 251
 	date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
252
+
252 253
 	if parseDateErr != nil {
253 254
 		this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
254 255
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -434,15 +435,18 @@ func (this *DialysisRecordAPIController) DialysisSchedule() {
434 435
 
435 436
 	if is_open_config.IsOpen == 1 {
436 437
 		his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
437
-		fmt.Println("his_advicses--------------------222222", his_advices)
438
+
438 439
 	}
439 440
 	//查询是否是开起
440 441
 	adviceConfig, _ := service.FindAdviceSettingById(adminInfo.CurrentOrgId)
441 442
 	if adviceConfig.IsAdviceOpen == 1 {
442 443
 		his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.CurrentOrgId, patientID, date.Unix())
443
-		fmt.Println("his_advicses--------------------", his_advices)
444 444
 	}
445 445
 
446
+	lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.CurrentOrgId)
447
+
448
+	firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.CurrentOrgId)
449
+
446 450
 	_, errcode := service.GetOrgFollowIsExist(adminInfo.CurrentOrgId)
447 451
 	if errcode == gorm.ErrRecordNotFound {
448 452
 		information, _ := service.GetAdminUserRoleInformation(0)
@@ -481,6 +485,8 @@ func (this *DialysisRecordAPIController) DialysisSchedule() {
481 485
 			"dryWeightList":               dryWeightList,
482 486
 			"docList":                     allDoctor,
483 487
 			"lastAcceptTreatment":         lastAcceptTreatment,
488
+			"firstMonitor":                firstMonitor,
489
+			"lastMonitor":                 lastMonitor,
484 490
 		}
485 491
 		this.ServeSuccessJSON(returnData)
486 492
 
@@ -521,6 +527,8 @@ func (this *DialysisRecordAPIController) DialysisSchedule() {
521 527
 			"dryWeightList":               dryWeightList,
522 528
 			"docList":                     allDoctor,
523 529
 			"lastAcceptTreatment":         lastAcceptTreatment,
530
+			"firstMonitor":                firstMonitor,
531
+			"lastMonitor":                 lastMonitor,
524 532
 		}
525 533
 		this.ServeSuccessJSON(returnData)
526 534
 	}
@@ -1087,8 +1095,12 @@ func (this *DialysisRecordAPIController) StartDialysis() {
1087 1095
 				return
1088 1096
 			}
1089 1097
 		} else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
1090
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
1091
-			return
1098
+
1099
+			modityorder, _ := service.GetDayScheduleByOrder(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
1100
+			if modityorder.ID > 0 && (schedule.PatientId != modityorder.PatientId) {
1101
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
1102
+				return
1103
+			}
1092 1104
 		}
1093 1105
 	} else if err != nil {
1094 1106
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -1949,6 +1961,8 @@ func (this *DialysisRecordAPIController) ModifyStartDialysis() {
1949 1961
 	//查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
1950 1962
 
1951 1963
 	schedule, err := service.GetDayScheduleByBedid(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
1964
+
1965
+	fmt.Println("schedule-----------------------------", schedule)
1952 1966
 	daySchedule, _ := service.GetDaySchedule(adminUserInfo.CurrentOrgId, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
1953 1967
 
1954 1968
 	if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
@@ -1997,9 +2011,13 @@ func (this *DialysisRecordAPIController) ModifyStartDialysis() {
1997 2011
 						return
1998 2012
 					}
1999 2013
 				}
2000
-			} else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
2001
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
2002
-				return
2014
+			} else if schedule.ID > 0 { //有排班且有上机记录
2015
+				modityorder, _ := service.GetDayScheduleByOrder(adminUserInfo.CurrentOrgId, schedulestartTime, bedID, schedual_type)
2016
+				if modityorder.ID > 0 && (schedule.PatientId != modityorder.PatientId) {
2017
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
2018
+					return
2019
+				}
2020
+
2003 2021
 			}
2004 2022
 		} else if err != nil {
2005 2023
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -2061,6 +2079,8 @@ func (this *DialysisRecordAPIController) ModifyStartDialysis() {
2061 2079
 
2062 2080
 	updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
2063 2081
 
2082
+	service.UpdateScheduleByBedId(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.BedID, dialysisRecord.SchedualType, dialysisRecord.ZoneId)
2083
+
2064 2084
 	order, _ := service.GetLastPatientOrder(record_id)
2065 2085
 
2066 2086
 	service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, order.PatientId, schedule_remark)

+ 310 - 128
controllers/his_api_controller.go 파일 보기

@@ -3175,7 +3175,7 @@ func (c *HisApiController) CreateHisPrescription() {
3175 3175
 	var adviceList []models.HisDoctorAdviceInfo
3176 3176
 	var projectList []models.HisPrescriptionProject
3177 3177
 
3178
-	if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10598 {
3178
+	if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10610 {
3179 3179
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
3180 3180
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
3181 3181
 
@@ -3424,9 +3424,6 @@ func (c *HisApiController) CreateHisPrescription() {
3424 3424
 
3425 3425
 										}
3426 3426
 
3427
-										//fmt.Println("is_user_total-----------------------------", is_user_total)
3428
-										//fmt.Println("no_user_total-----------------------------", no_user_total)
3429
-
3430 3427
 										if is_user_total != no_user_total {
3431 3428
 											//出库
3432 3429
 											if drug.IsUse == 2 {
@@ -3649,6 +3646,15 @@ func (c *HisApiController) CreateHisPrescription() {
3649 3646
 								tempTime := time.Unix(timestamp, 0)
3650 3647
 								timeFormat := tempTime.Format("20060102150405")
3651 3648
 								s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
3649
+
3650
+								//查询改药品是否已经停用
3651
+								base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
3652
+								if base.ID > 0 {
3653
+									tx.Rollback()
3654
+									c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
3655
+									return
3656
+
3657
+								}
3652 3658
 								service.CreateHisDoctorAdviceOne(&s, tx)
3653 3659
 
3654 3660
 								tx.Commit()
@@ -3732,47 +3738,25 @@ func (c *HisApiController) CreateHisPrescription() {
3732 3738
 								//
3733 3739
 								//}
3734 3740
 
3735
-								service.CreateNewHisProjectTwo(&p, tx)
3736
-								var randNum int
3737
-								randNum = rand.Intn(10000) + 1000
3738
-								timestamp := time.Now().Unix()
3739
-								tempTime := time.Unix(timestamp, 0)
3740
-								timeFormat := tempTime.Format("20060102150405")
3741
-								p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
3742
-								service.CreateNewHisProjectTwo(&p, tx)
3743
-
3744 3741
 								//查询保存耗材出库开关是否打开
3745 3742
 								if p.PatientId != 30038 {
3746 3743
 									if goodOutConfig.IsOpen == 1 {
3747 3744
 										//耗材出库
3748 3745
 										if p.Type == 3 {
3749
-											lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
3750
-											//查询历史出库数据
3751
-											flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
3752 3746
 
3753
-											var out_count_five int64
3754
-											for _, item := range flowGood {
3755
-												out_count_five += item.Count
3756
-											}
3757
-											parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
3747
+											//对比当前数据和历史出库数据
3758 3748
 
3759
-											//如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
3760
-											if out_count_five != parseIntCount {
3761
-												//查询耗材最后一次出库记录
3762
-												wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
3763
-												//查询默认出库仓库库存
3764
-												storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
3765
-												if len(wareOut) > 0 {
3749
+											historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
3766 3750
 
3767
-													for _, it := range wareOut {
3768
-														//回退库存
3769
-														service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
3751
+											historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
3770 3752
 
3771
-														//删除出库记录
3772
-														service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
3753
+											nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
3773 3754
 
3774
-													}
3775
-												}
3755
+											//如果当前处方数量大于历史数据,则需要出库
3756
+											if nowCount > historyCount {
3757
+
3758
+												var cha_count int64
3759
+												cha_count = nowCount - historyCount
3776 3760
 
3777 3761
 												timeStr := time.Now().Format("2006-01-02")
3778 3762
 												timeArr := strings.Split(timeStr, "-")
@@ -3820,113 +3804,257 @@ func (c *HisApiController) CreateHisPrescription() {
3820 3804
 													PatientId:    p.PatientId,
3821 3805
 													RecordDate:   p.RecordDate,
3822 3806
 													UserOrgId:    adminInfo.CurrentOrgId,
3823
-													Count:        parseIntCount,
3807
+													Count:        cha_count,
3824 3808
 													Ctime:        time.Now().Unix(),
3825 3809
 													Creater:      creater,
3826 3810
 													Status:       1,
3827 3811
 													StorehouseId: houseConfig.StorehouseOutInfo,
3828
-													ProjectId:    lastHisProject.ID,
3812
+													ProjectId:    p.ID,
3829 3813
 												}
3830
-												//判断是否是零用耗材(非零用)
3831
-												if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
3832
-
3833
-													//查询历史出库数据
3834
-													flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
3835
-													var out_count int64
3836
-													for _, item := range flowGood {
3837
-														out_count += item.Count
3838
-													}
3839
-													//如果历史数和当前数据不想等才进行退库出库
3840
-													if out_count != parseIntCount {
3841
-														service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
3842
-
3843
-														service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
3844
-														detail := models.AutomaticReduceDetail{
3845
-															WarehouseOutId:          0,
3846
-															WarehouseOutOrderNumber: "",
3847
-															PatientId:               p.PatientId,
3848
-															Ctime:                   time.Now().Unix(),
3849
-															Mtime:                   0,
3850
-															Status:                  1,
3851
-															RecordTime:              p.RecordDate,
3852
-															OrgId:                   p.UserOrgId,
3853
-															GoodId:                  p.ProjectId,
3854
-															GoodTypeId:              0,
3855
-															Count:                   parseIntCount,
3856
-															Type:                    0,
3857
-															ProjectId:               lastHisProject.ID,
3858
-															StorehouseId:            0,
3859
-														}
3860
-
3861
-														service.CreateNewAutoDetail(detail, tx)
3862
-
3863
-														//查询剩余库存
3864
-														goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
3865
-														var sum_count int64
3866
-														for _, item := range goodList {
3867
-															sum_count += item.StockCount
3868
-														}
3869
-
3870
-														//更新剩余库存
3871
-														service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
3872
-
3873
-														//耗材
3874
-														service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
3875
-
3876
-													}
3877
-													//判断是否是零用耗材(零用但是是出库耗材)
3878
-													if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
3814
+												//出库
3815
+												service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
3879 3816
 
3880
-														//查询历史出库数据
3881
-														flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
3882
-														var out_count int64
3883
-														for _, item := range flowGood {
3884
-															out_count += item.Count
3885
-														}
3886
-														//如果历史数和当前数据不想等才进行退库出库
3887
-														if out_count != parseIntCount {
3888
-															service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
3889
-
3890
-															service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
3891
-															detail := models.AutomaticReduceDetail{
3892
-																WarehouseOutId:          0,
3893
-																WarehouseOutOrderNumber: "",
3894
-																PatientId:               p.PatientId,
3895
-																Ctime:                   time.Now().Unix(),
3896
-																Mtime:                   0,
3897
-																Status:                  1,
3898
-																RecordTime:              p.RecordDate,
3899
-																OrgId:                   p.UserOrgId,
3900
-																GoodId:                  p.ProjectId,
3901
-																GoodTypeId:              0,
3902
-																Count:                   parseIntCount,
3903
-																Type:                    0,
3904
-																ProjectId:               p.ID,
3905
-																StorehouseId:            0,
3906
-															}
3817
+											}
3907 3818
 
3908
-															service.CreateNewAutoDetail(detail, tx)
3819
+											//如果当前处方数量小于历史数据,怎需要退库
3820
+											if nowCount < historyCount {
3909 3821
 
3910
-															//查询剩余库存
3911
-															goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
3912
-															var sum_count int64
3913
-															for _, item := range goodList {
3914
-																sum_count += item.StockCount
3915
-															}
3916
-
3917
-															//更新剩余库存
3918
-															service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
3822
+												var cha_count int64
3823
+												cha_count = historyCount - nowCount
3824
+												goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
3825
+												creater := c.GetAdminUserInfo().AdminUser.Id
3919 3826
 
3920
-															//耗材
3921
-															service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
3922
-														}
3827
+												newPrescriptionProject := &models.HisPrescriptionProject{
3828
+													ID:                   p.ID,
3829
+													ProjectId:            p.ProjectId,
3830
+													Price:                p.Price,
3831
+													UserOrgId:            p.UserOrgId,
3832
+													Status:               1,
3833
+													Ctime:                time.Now().Unix(),
3834
+													Mtime:                time.Now().Unix(),
3835
+													PatientId:            p.PatientId,
3836
+													HisPatientId:         p.HisPatientId,
3837
+													RecordDate:           p.RecordDate,
3838
+													PrescriptionId:       p.PrescriptionId,
3839
+													Count:                p.Count,
3840
+													FeedetlSn:            p.FeedetlSn,
3841
+													MedListCodg:          p.MedListCodg,
3842
+													SingleDose:           p.SingleDose,
3843
+													DeliveryWay:          p.DeliveryWay,
3844
+													ExecutionFrequency:   p.ExecutionFrequency,
3845
+													Day:                  p.Day,
3846
+													HisProject:           models.HisProject{},
3847
+													GoodInfo:             models.GoodInfo{},
3848
+													Remark:               p.Remark,
3849
+													Unit:                 p.Unit,
3850
+													Type:                 p.Type,
3851
+													Doctor:               p.Doctor,
3852
+													ExecutionTime:        p.ExecutionTime,
3853
+													ExecutionStaff:       p.ExecutionStaff,
3854
+													ExecutionState:       p.ExecutionState,
3855
+													CheckTime:            p.CheckTime,
3856
+													CheckState:           p.CheckState,
3857
+													Checker:              p.Checker,
3858
+													StartTime:            p.StartTime,
3859
+													TeamId:               p.TeamId,
3860
+													XtHisProjectTeam:     models.XtHisProjectTeam{},
3861
+													FrequencyType:        p.FrequencyType,
3862
+													DayCount:             p.DayCount,
3863
+													WeekDay:              p.WeekDay,
3864
+													IsCheckTeam:          p.IsCheckTeam,
3865
+													HisOrderInfo:         models.HisOrderInfo{},
3866
+													ExecutionFrequencyId: p.ExecutionFrequencyId,
3867
+													IsOut:                p.IsOut,
3868
+													YbSyncStatus:         p.YbSyncStatus,
3869
+												}
3923 3870
 
3924
-													}
3871
+												service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
3925 3872
 
3926
-												}
3873
+												service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
3927 3874
 
3928 3875
 											}
3929 3876
 
3877
+											//lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
3878
+											////查询历史出库数据
3879
+											//flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
3880
+											//
3881
+											//var out_count_five int64
3882
+											//for _, item := range flowGood {
3883
+											//	out_count_five += item.Count
3884
+											//}
3885
+											//parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
3886
+											//
3887
+											////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
3888
+											//if out_count_five != parseIntCount {
3889
+											//	//查询耗材最后一次出库记录
3890
+											//	wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
3891
+											//	//查询默认出库仓库库存
3892
+											//	storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
3893
+											//	if len(wareOut) > 0 {
3894
+											//
3895
+											//		for _, it := range wareOut {
3896
+											//			//回退库存
3897
+											//			service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
3898
+											//
3899
+											//			//删除出库记录
3900
+											//			service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
3901
+											//
3902
+											//		}
3903
+											//	}
3904
+											//
3905
+											//	timeStr := time.Now().Format("2006-01-02")
3906
+											//	timeArr := strings.Split(timeStr, "-")
3907
+											//	total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
3908
+											//
3909
+											//	total = total + 1
3910
+											//	warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
3911
+											//	number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3912
+											//	number = number + total
3913
+											//	warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
3914
+											//
3915
+											//	operation_time := time.Now().Unix()
3916
+											//	creater := c.GetAdminUserInfo().AdminUser.Id
3917
+											//
3918
+											//	recordDateStr := time.Now().Format("2006-01-02")
3919
+											//	recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3920
+											//	nowtime := recordDate.Unix()
3921
+											//	warehouseOut := models.WarehouseOut{
3922
+											//		WarehouseOutOrderNumber: warehousing_out_order,
3923
+											//		OperationTime:           operation_time,
3924
+											//		OrgId:                   adminInfo.CurrentOrgId,
3925
+											//		Creater:                 creater,
3926
+											//		Ctime:                   time.Now().Unix(),
3927
+											//		Status:                  1,
3928
+											//		WarehouseOutTime:        nowtime,
3929
+											//		Type:                    1,
3930
+											//		StorehouseId:            storeConfig.StorehouseOutInfo,
3931
+											//		IsCheck:                 1,
3932
+											//		IsSys:                   1,
3933
+											//	}
3934
+											//	//查询是否生成出库单
3935
+											//	out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
3936
+											//	if out.ID == 0 {
3937
+											//		service.AddNewSigleWarehouseOut(&warehouseOut, tx)
3938
+											//	}
3939
+											//
3940
+											//	lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
3941
+											//
3942
+											//	goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
3943
+											//	houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
3944
+											//
3945
+											//	dialyPrepareOne := models.DialysisBeforePrepare{
3946
+											//		GoodTypeId:   goodObj.GoodTypeId,
3947
+											//		GoodId:       p.ProjectId,
3948
+											//		PatientId:    p.PatientId,
3949
+											//		RecordDate:   p.RecordDate,
3950
+											//		UserOrgId:    adminInfo.CurrentOrgId,
3951
+											//		Count:        parseIntCount,
3952
+											//		Ctime:        time.Now().Unix(),
3953
+											//		Creater:      creater,
3954
+											//		Status:       1,
3955
+											//		StorehouseId: houseConfig.StorehouseOutInfo,
3956
+											//		ProjectId:    lastHisProject.ID,
3957
+											//	}
3958
+											//	//判断是否是零用耗材(非零用)
3959
+											//	if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
3960
+											//
3961
+											//		//查询历史出库数据
3962
+											//		flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
3963
+											//		var out_count int64
3964
+											//		for _, item := range flowGood {
3965
+											//			out_count += item.Count
3966
+											//		}
3967
+											//		//如果历史数和当前数据不想等才进行退库出库
3968
+											//		if out_count != parseIntCount {
3969
+											//			service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
3970
+											//
3971
+											//			service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
3972
+											//			detail := models.AutomaticReduceDetail{
3973
+											//				WarehouseOutId:          0,
3974
+											//				WarehouseOutOrderNumber: "",
3975
+											//				PatientId:               p.PatientId,
3976
+											//				Ctime:                   time.Now().Unix(),
3977
+											//				Mtime:                   0,
3978
+											//				Status:                  1,
3979
+											//				RecordTime:              p.RecordDate,
3980
+											//				OrgId:                   p.UserOrgId,
3981
+											//				GoodId:                  p.ProjectId,
3982
+											//				GoodTypeId:              0,
3983
+											//				Count:                   parseIntCount,
3984
+											//				Type:                    0,
3985
+											//				ProjectId:               lastHisProject.ID,
3986
+											//				StorehouseId:            0,
3987
+											//			}
3988
+											//
3989
+											//			service.CreateNewAutoDetail(detail, tx)
3990
+											//
3991
+											//			//查询剩余库存
3992
+											//			goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
3993
+											//			var sum_count int64
3994
+											//			for _, item := range goodList {
3995
+											//				sum_count += item.StockCount
3996
+											//			}
3997
+											//
3998
+											//			//更新剩余库存
3999
+											//			service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
4000
+											//
4001
+											//			//耗材
4002
+											//			service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
4003
+											//
4004
+											//		}
4005
+											//		//判断是否是零用耗材(零用但是是出库耗材)
4006
+											//		if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
4007
+											//
4008
+											//			//查询历史出库数据
4009
+											//			flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
4010
+											//			var out_count int64
4011
+											//			for _, item := range flowGood {
4012
+											//				out_count += item.Count
4013
+											//			}
4014
+											//			//如果历史数和当前数据不想等才进行退库出库
4015
+											//			if out_count != parseIntCount {
4016
+											//				service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
4017
+											//
4018
+											//				service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
4019
+											//				detail := models.AutomaticReduceDetail{
4020
+											//					WarehouseOutId:          0,
4021
+											//					WarehouseOutOrderNumber: "",
4022
+											//					PatientId:               p.PatientId,
4023
+											//					Ctime:                   time.Now().Unix(),
4024
+											//					Mtime:                   0,
4025
+											//					Status:                  1,
4026
+											//					RecordTime:              p.RecordDate,
4027
+											//					OrgId:                   p.UserOrgId,
4028
+											//					GoodId:                  p.ProjectId,
4029
+											//					GoodTypeId:              0,
4030
+											//					Count:                   parseIntCount,
4031
+											//					Type:                    0,
4032
+											//					ProjectId:               p.ID,
4033
+											//					StorehouseId:            0,
4034
+											//				}
4035
+											//
4036
+											//				service.CreateNewAutoDetail(detail, tx)
4037
+											//
4038
+											//				//查询剩余库存
4039
+											//				goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
4040
+											//				var sum_count int64
4041
+											//				for _, item := range goodList {
4042
+											//					sum_count += item.StockCount
4043
+											//				}
4044
+											//
4045
+											//				//更新剩余库存
4046
+											//				service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
4047
+											//
4048
+											//				//耗材
4049
+											//				service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
4050
+											//			}
4051
+											//
4052
+											//		}
4053
+											//
4054
+											//	}
4055
+											//
4056
+											//}
4057
+
3930 4058
 											//记录日志
3931 4059
 											byterequest, _ := json.Marshal(p)
3932 4060
 											adviceLog := models.XtDoctorAdviceLog{
@@ -3999,6 +4127,55 @@ func (c *HisApiController) CreateHisPrescription() {
3999 4127
 									}
4000 4128
 								}
4001 4129
 
4130
+								service.CreateNewHisProjectTwo(&p, tx)
4131
+								var randNum int
4132
+								randNum = rand.Intn(10000) + 1000
4133
+								timestamp := time.Now().Unix()
4134
+								tempTime := time.Unix(timestamp, 0)
4135
+								timeFormat := tempTime.Format("20060102150405")
4136
+								p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
4137
+
4138
+								goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
4139
+
4140
+								if goodBase.ID > 0 {
4141
+									tx.Rollback()
4142
+									c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
4143
+									return
4144
+								}
4145
+								service.CreateNewHisProjectTwo(&p, tx)
4146
+
4147
+								houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
4148
+
4149
+								//查询剩余库存
4150
+								goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
4151
+								var sum_count int64
4152
+								for _, item := range goodList {
4153
+									sum_count += item.StockCount
4154
+								}
4155
+
4156
+								//更新剩余库存
4157
+								service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
4158
+
4159
+								//耗材
4160
+								service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
4161
+
4162
+								adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
4163
+
4164
+								outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
4165
+
4166
+								if len(outInfoTwo) > 0 {
4167
+									for _, item := range outInfoTwo {
4168
+										service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
4169
+									}
4170
+								}
4171
+
4172
+								drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
4173
+								if len(drugAutoDetail) > 0 {
4174
+									for _, item := range drugAutoDetail {
4175
+										service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
4176
+									}
4177
+								}
4178
+
4002 4179
 								tx.Commit()
4003 4180
 							}
4004 4181
 						}
@@ -5189,6 +5366,7 @@ func (c *HisApiController) DeletePrescription() {
5189 5366
 									ExpireDate:              info.ExpiryDate,
5190 5367
 									StorehouseId:            houseConfig.StorehouseOutInfo,
5191 5368
 									OverCount:               flush_count,
5369
+									OperateTime:             time.Now().Unix(),
5192 5370
 								}
5193 5371
 								service.CreateStockFlowOne(flow)
5194 5372
 
@@ -5268,6 +5446,7 @@ func (c *HisApiController) DeletePrescription() {
5268 5446
 									ExpireDate:              info.ExpiryDate,
5269 5447
 									StorehouseId:            houseConfig.StorehouseOutInfo,
5270 5448
 									OverCount:               flush_count,
5449
+									OperateTime:             time.Now().Unix(),
5271 5450
 								}
5272 5451
 								service.CreateStockFlowOne(flow)
5273 5452
 
@@ -5908,6 +6087,7 @@ func (c *HisApiController) DeleteProject() {
5908 6087
 							ExpireDate:              info.ExpiryDate,
5909 6088
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5910 6089
 							OverCount:               over_count,
6090
+							OperateTime:             time.Now().Unix(),
5911 6091
 						}
5912 6092
 						service.CreateStockFlowOne(flow)
5913 6093
 					}
@@ -5946,6 +6126,7 @@ func (c *HisApiController) DeleteProject() {
5946 6126
 							ExpireDate:              info.ExpiryDate,
5947 6127
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5948 6128
 							OverCount:               over_count,
6129
+							OperateTime:             time.Now().Unix(),
5949 6130
 						}
5950 6131
 						service.CreateStockFlowOne(flow)
5951 6132
 					}
@@ -6181,6 +6362,7 @@ func (c *HisApiController) DeleteProject() {
6181 6362
 							ExpireDate:              it.ExpiryDate,
6182 6363
 							StorehouseId:            houseConfig.StorehouseOutInfo,
6183 6364
 							OverCount:               over_count_one,
6365
+							OperateTime:             time.Now().Unix(),
6184 6366
 						}
6185 6367
 						service.CreateStockFlowOne(flow)
6186 6368
 

+ 9 - 8
controllers/mobile_api_controllers/check_weight_api_controller.go 파일 보기

@@ -1,21 +1,22 @@
1 1
 package mobile_api_controllers
2 2
 
3 3
 import (
4
-	"XT_New/enums"
5
-	"XT_New/models"
6
-	"XT_New/service"
7
-	_ "XT_New/utils"
8 4
 	"encoding/json"
9 5
 	_ "encoding/json"
10 6
 	"fmt"
11
-	"github.com/astaxie/beego"
12
-	_ "github.com/astaxie/beego"
13
-	"github.com/jinzhu/gorm"
14 7
 	"net/http"
15 8
 	"net/url"
16 9
 	"strconv"
17 10
 	_ "strings"
18 11
 
12
+	"XT_New/enums"
13
+	"XT_New/models"
14
+	"XT_New/service"
15
+	_ "XT_New/utils"
16
+	"github.com/astaxie/beego"
17
+	_ "github.com/astaxie/beego"
18
+	"github.com/jinzhu/gorm"
19
+
19 20
 	// "fmt"
20 21
 	_ "reflect"
21 22
 	"time"
@@ -285,7 +286,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
285 286
 
286 287
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
287 288
 
288
-	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
289
+	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 10537 {
289 290
 		if adminUserInfo.Org.Id != 10447 {
290 291
 			dewater_amount = dewater_amount * 1000
291 292
 		}

+ 22 - 5
controllers/mobile_api_controllers/dialysis_api_controller.go 파일 보기

@@ -608,6 +608,10 @@ func (this *DialysisAPIController) DialysisRecord() {
608 608
 
609 609
 	dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
610 610
 
611
+	lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
612
+
613
+	firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
614
+
611 615
 	returnData := map[string]interface{}{
612 616
 		"patient":                        patient,
613 617
 		"schedual":                       schedual,
@@ -645,6 +649,8 @@ func (this *DialysisAPIController) DialysisRecord() {
645 649
 		"lastDialysisPrescription":       lastDialysisPrescription,
646 650
 		"lastAssesmentBeforDialysis":     lastAssesmentBeforDialysis,
647 651
 		"dryWeightList":                  dryWeightList,
652
+		"firstMonitor":                   firstMonitor,
653
+		"lastMonitor":                    lastMonitor,
648 654
 	}
649 655
 
650 656
 	this.ServeSuccessJSON(returnData)
@@ -2542,6 +2548,7 @@ func (c *DialysisAPIController) Finish() {
2542 2548
 	}
2543 2549
 
2544 2550
 	lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
2551
+	lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
2545 2552
 
2546 2553
 	_, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
2547 2554
 
@@ -2811,8 +2818,8 @@ func (c *DialysisAPIController) Finish() {
2811 2818
 		tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
2812 2819
 		tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
2813 2820
 		tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
2814
-		tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysis.Ktv
2815
-		tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysis.Urr
2821
+		tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
2822
+		tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
2816 2823
 		if tempassessmentAfterDislysis.PatientId == 18695 {
2817 2824
 			tempassessmentAfterDislysis.ActualDisplacement = 0
2818 2825
 		}
@@ -3497,7 +3504,7 @@ func (this *DialysisAPIController) StartDialysis() {
3497 3504
 	}
3498 3505
 
3499 3506
 	//只针对广慈医院
3500
-	if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 {
3507
+	if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
3501 3508
 		// 查询病人是否有透前评估数据
3502 3509
 		befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
3503 3510
 
@@ -3539,6 +3546,16 @@ func (this *DialysisAPIController) StartDialysis() {
3539 3546
 			record.PulseFrequency = befor.PulseFrequency
3540 3547
 			record.BreathingRate = befor.BreathingRate
3541 3548
 		}
3549
+
3550
+		//针对乐山友谊医院的需求
3551
+		if adminUserInfo.Org.Id == 10677 {
3552
+			befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
3553
+			record.SystolicBloodPressure = befor.SystolicBloodPressure
3554
+			record.DiastolicBloodPressure = befor.DiastolicBloodPressure
3555
+			record.Temperature = befor.Temperature
3556
+			record.PulseFrequency = befor.PulseFrequency
3557
+			record.BreathingRate = befor.BreathingRate
3558
+		}
3542 3559
 		//新化博翔
3543 3560
 		if adminUserInfo.Org.Id == 10447 {
3544 3561
 			befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
@@ -4485,7 +4502,7 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
4485 4502
 				record.UltrafiltrationRate = ultrafiltration_rate
4486 4503
 			}
4487 4504
 
4488
-			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 {
4505
+			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 || adminInfo.Org.Id == 10537 {
4489 4506
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
4490 4507
 
4491 4508
 				record.UltrafiltrationRate = ultrafiltration_rate
@@ -4553,7 +4570,7 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
4553 4570
 	}
4554 4571
 
4555 4572
 	//长沙南雅
4556
-	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 {
4573
+	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 || adminInfo.Org.Id == 10537 {
4557 4574
 
4558 4575
 		if ultrafiltration_rate > 0 {
4559 4576
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)

+ 131 - 123
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go 파일 보기

@@ -558,140 +558,148 @@ func (this *StaffScheduleApiController) DeleteSchedule() {
558 558
 	drugOutConfig, _ := service.FindDrugOutConfigById(org_id)
559 559
 	//退库
560 560
 	if drugOutConfig.IsOpen == 1 {
561
-		hisAdvice, _ := service.GetHisDoctorAdviceListTwentyOne(schedule.PatientId, schedule.ScheduleDate, org_id)
562
-		for _, item := range hisAdvice {
563
-			creater := this.GetMobileAdminUserInfo().AdminUser.Id
564
-			err := service.DrugAutoAddCancelInfo(item, creater)
565
-			if err != nil {
566
-				err = fmt.Errorf("!:%v", err)
567
-				return
568
-			}
561
+		hisAdvice, _ := service.GetPatientDrugCountToday(schedule.PatientId, schedule.ScheduleDate, org_id)
562
+		if len(hisAdvice) > 0 {
563
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
564
+			return
569 565
 		}
570
-		//查询是否有出库记录
571
-		service.GetPatientGoodStockCount(schedule.PatientId, schedule.ScheduleDate, org_id)
566
+		//for _, item := range hisAdvice {
567
+		//	creater := this.GetMobileAdminUserInfo().AdminUser.Id
568
+		//	err := service.DrugAutoAddCancelInfo(item, creater)
569
+		//	if err != nil {
570
+		//		err = fmt.Errorf("!:%v", err)
571
+		//		return
572
+		//	}
573
+		//}
574
+		////查询是否有出库记录
575
+		//service.GetPatientGoodStockCount(schedule.PatientId, schedule.ScheduleDate, org_id)
572 576
 	}
573 577
 
574 578
 	//查询该患者当天是否开耗材
575 579
 	list, _ := service.GetPatientGoodCountToday(schedule.PatientId, schedule.ScheduleDate, org_id)
576 580
 	if len(list) > 0 {
577 581
 
578
-		operation_time := time.Now().Unix()
579
-		creater := this.GetMobileAdminUserInfo().AdminUser.Id
580
-		//创建退库单
581
-		timeStr := time.Now().Format("2006-01-02")
582
-		timeArr := strings.Split(timeStr, "-")
583
-		total, _ := service.FindAllCancelStockTotal(org_id)
584
-		total = total + 1
585
-		orderNumber := "CKTKD" + strconv.FormatInt(org_id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
586
-		houseConfig, _ := service.GetAllStoreHouseConfig(org_id)
587
-		cancelStock := models.CancelStock{
588
-			OrderNumber:  orderNumber,
589
-			OperaTime:    operation_time,
590
-			OrgId:        org_id,
591
-			Creater:      creater,
592
-			Ctime:        time.Now().Unix(),
593
-			Status:       1,
594
-			ReturnTime:   schedule.ScheduleDate,
595
-			Type:         1,
596
-			StorehouseId: houseConfig.StorehouseOutInfo,
597
-			IsCheck:      1,
598
-		}
599
-		_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(schedule.ScheduleDate, org_id)
600
-		if msgerrkonde == gorm.ErrRecordNotFound {
601
-			service.AddSigleCancelStock(&cancelStock)
602
-		}
603
-		cancel, _ := service.GetLastCancelStockById(org_id)
604
-		//进行退库操作
605
-		for _, item := range list {
606
-			good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
607
-			manufacturer, _ := service.GetManufactureById(item.Manufacturer)
608
-			deaerler, _ := service.GetDealerById(item.Dealer)
609
-			//回退库存
610
-			service.UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
611
-			goodList, _ := service.GetSumGoodList(org_id, houseConfig.StorehouseOutInfo, item.GoodId)
612
-			var flush_count int64
613
-			for _, it := range goodList {
614
-				flush_count += it.StockCount
615
-			}
616
-			cancelStockInfo := models.CancelStockInfo{
617
-				GoodId:          item.GoodId,
618
-				CancelStockId:   cancel.ID,
619
-				GoodTypeId:      good.GoodTypeId,
620
-				Count:           item.Count,
621
-				Price:           item.Price,
622
-				Total:           0,
623
-				ProductDate:     item.ProductDate,
624
-				ExpiryDate:      item.ExpiryDate,
625
-				Ctime:           time.Now().Unix(),
626
-				Status:          1,
627
-				OrgId:           org_id,
628
-				OrderNumber:     cancel.OrderNumber,
629
-				Type:            0,
630
-				Dealer:          deaerler.DealerName,
631
-				Manufacturer:    manufacturer.ManufacturerName,
632
-				Number:          item.Number,
633
-				RegisterAccount: "",
634
-				Remark:          "",
635
-				WarehouseInfoId: item.WarehouseInfotId,
636
-				PatientId:       item.PatientId,
637
-				RecordDate:      item.SysRecordTime,
638
-				StorehouseId:    houseConfig.StorehouseOutInfo,
639
-				IsCheck:         1,
640
-			}
641
-
642
-			service.CreateCancelStockInfoOne(&cancelStockInfo)
643
-
644
-			cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
645
-
646
-			flow := models.VmStockFlow{
647
-				WarehousingId:           item.WarehouseInfotId,
648
-				GoodId:                  item.GoodId,
649
-				Number:                  item.Number,
650
-				LicenseNumber:           item.LicenseNumber,
651
-				Count:                   item.Count,
652
-				UserOrgId:               org_id,
653
-				PatientId:               item.PatientId,
654
-				SystemTime:              item.SysRecordTime,
655
-				ConsumableType:          7,
656
-				IsSys:                   0,
657
-				WarehousingOrder:        "",
658
-				WarehouseOutId:          item.WarehouseOutId,
659
-				WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
660
-				IsEdit:                  0,
661
-				CancelStockId:           cancel.ID,
662
-				CancelOrderNumber:       cancel.OrderNumber,
663
-				Manufacturer:            manufacturer.ID,
664
-				Dealer:                  0,
665
-				Creator:                 org_id,
666
-				UpdateCreator:           0,
667
-				Status:                  1,
668
-				Ctime:                   time.Now().Unix(),
669
-				Mtime:                   0,
670
-				Price:                   item.Price,
671
-				WarehousingDetailId:     item.WarehouseInfotId,
672
-				WarehouseOutDetailId:    item.ID,
673
-				CancelOutDetailId:       cancelInfo.ID,
674
-				ProductDate:             item.ProductDate,
675
-				ExpireDate:              item.ExpiryDate,
676
-				StorehouseId:            houseConfig.StorehouseOutInfo,
677
-				OverCount:               flush_count,
678
-			}
679
-			service.CreateStockFlowOne(flow)
680
-
681
-			//退库数量增加
682
-			service.UpdateSumAddCancelCount(org_id, item.GoodId, houseConfig.StorehouseOutInfo, item.Count)
683
-			//出库数量减少
684
-			service.UpdateSumCount(org_id, houseConfig.StorehouseOutInfo, item.GoodId, item.Count)
685
-
686
-			//更新库存
687
-			service.UpdateSumGood(org_id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
582
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
583
+		return
688 584
 
689
-			//更新基础库库存
690
-			service.UpdateGoodInfoSumCountSix(item.GoodId, flush_count, org_id)
691
-		}
585
+		//operation_time := time.Now().Unix()
586
+		//creater := this.GetMobileAdminUserInfo().AdminUser.Id
587
+		////创建退库单
588
+		//timeStr := time.Now().Format("2006-01-02")
589
+		//timeArr := strings.Split(timeStr, "-")
590
+		//total, _ := service.FindAllCancelStockTotal(org_id)
591
+		//total = total + 1
592
+		//orderNumber := "CKTKD" + strconv.FormatInt(org_id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
593
+		//houseConfig, _ := service.GetAllStoreHouseConfig(org_id)
594
+		//cancelStock := models.CancelStock{
595
+		//	OrderNumber:  orderNumber,
596
+		//	OperaTime:    operation_time,
597
+		//	OrgId:        org_id,
598
+		//	Creater:      creater,
599
+		//	Ctime:        time.Now().Unix(),
600
+		//	Status:       1,
601
+		//	ReturnTime:   schedule.ScheduleDate,
602
+		//	Type:         1,
603
+		//	StorehouseId: houseConfig.StorehouseOutInfo,
604
+		//	IsCheck:      1,
605
+		//}
606
+		//_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(schedule.ScheduleDate, org_id)
607
+		//if msgerrkonde == gorm.ErrRecordNotFound {
608
+		//	service.AddSigleCancelStock(&cancelStock)
609
+		//}
610
+		//cancel, _ := service.GetLastCancelStockById(org_id)
611
+		////进行退库操作
612
+		//for _, item := range list {
613
+		//	good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
614
+		//	manufacturer, _ := service.GetManufactureById(item.Manufacturer)
615
+		//	deaerler, _ := service.GetDealerById(item.Dealer)
616
+		//	//回退库存
617
+		//	service.UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
618
+		//	goodList, _ := service.GetSumGoodList(org_id, houseConfig.StorehouseOutInfo, item.GoodId)
619
+		//	var flush_count int64
620
+		//	for _, it := range goodList {
621
+		//		flush_count += it.StockCount
622
+		//	}
623
+		//	cancelStockInfo := models.CancelStockInfo{
624
+		//		GoodId:          item.GoodId,
625
+		//		CancelStockId:   cancel.ID,
626
+		//		GoodTypeId:      good.GoodTypeId,
627
+		//		Count:           item.Count,
628
+		//		Price:           item.Price,
629
+		//		Total:           0,
630
+		//		ProductDate:     item.ProductDate,
631
+		//		ExpiryDate:      item.ExpiryDate,
632
+		//		Ctime:           time.Now().Unix(),
633
+		//		Status:          1,
634
+		//		OrgId:           org_id,
635
+		//		OrderNumber:     cancel.OrderNumber,
636
+		//		Type:            0,
637
+		//		Dealer:          deaerler.DealerName,
638
+		//		Manufacturer:    manufacturer.ManufacturerName,
639
+		//		Number:          item.Number,
640
+		//		RegisterAccount: "",
641
+		//		Remark:          "",
642
+		//		WarehouseInfoId: item.WarehouseInfotId,
643
+		//		PatientId:       item.PatientId,
644
+		//		RecordDate:      item.SysRecordTime,
645
+		//		StorehouseId:    houseConfig.StorehouseOutInfo,
646
+		//		IsCheck:         1,
647
+		//	}
648
+		//
649
+		//	service.CreateCancelStockInfoOne(&cancelStockInfo)
650
+		//
651
+		//	cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
652
+		//
653
+		//	flow := models.VmStockFlow{
654
+		//		WarehousingId:           item.WarehouseInfotId,
655
+		//		GoodId:                  item.GoodId,
656
+		//		Number:                  item.Number,
657
+		//		LicenseNumber:           item.LicenseNumber,
658
+		//		Count:                   item.Count,
659
+		//		UserOrgId:               org_id,
660
+		//		PatientId:               item.PatientId,
661
+		//		SystemTime:              item.SysRecordTime,
662
+		//		ConsumableType:          7,
663
+		//		IsSys:                   0,
664
+		//		WarehousingOrder:        "",
665
+		//		WarehouseOutId:          item.WarehouseOutId,
666
+		//		WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
667
+		//		IsEdit:                  0,
668
+		//		CancelStockId:           cancel.ID,
669
+		//		CancelOrderNumber:       cancel.OrderNumber,
670
+		//		Manufacturer:            manufacturer.ID,
671
+		//		Dealer:                  0,
672
+		//		Creator:                 org_id,
673
+		//		UpdateCreator:           0,
674
+		//		Status:                  1,
675
+		//		Ctime:                   time.Now().Unix(),
676
+		//		Mtime:                   0,
677
+		//		Price:                   item.Price,
678
+		//		WarehousingDetailId:     item.WarehouseInfotId,
679
+		//		WarehouseOutDetailId:    item.ID,
680
+		//		CancelOutDetailId:       cancelInfo.ID,
681
+		//		ProductDate:             item.ProductDate,
682
+		//		ExpireDate:              item.ExpiryDate,
683
+		//		StorehouseId:            houseConfig.StorehouseOutInfo,
684
+		//		OverCount:               flush_count,
685
+		//	}
686
+		//	service.CreateStockFlowOne(flow)
687
+		//
688
+		//	//退库数量增加
689
+		//	service.UpdateSumAddCancelCount(org_id, item.GoodId, houseConfig.StorehouseOutInfo, item.Count)
690
+		//	//出库数量减少
691
+		//	service.UpdateSumCount(org_id, houseConfig.StorehouseOutInfo, item.GoodId, item.Count)
692
+		//
693
+		//	//更新库存
694
+		//	service.UpdateSumGood(org_id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
695
+		//
696
+		//	//更新基础库库存
697
+		//	service.UpdateGoodInfoSumCountSix(item.GoodId, flush_count, org_id)
698
+		//}
692 699
 	}
693 700
 
694 701
 	err := service.DeleteSchedule(id)
702
+
695 703
 	if err == nil {
696 704
 
697 705
 		//记录日志

+ 250 - 0
controllers/pharmacy_controller.go 파일 보기

@@ -34,6 +34,12 @@ func PharmacyApiRegistRouters() {
34 34
 	beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName")               //获取当前登录账号的名字(
35 35
 	beego.Router("/api/pharmacy/getpartitionlist", &PharmacyController{}, "get:GetPartitionList")           //获取当前机构的分区列表
36 36
 	beego.Router("/api/pharmacy/routeofadministration", &PharmacyController{}, "get:RouteOfAdministration") //获取当前机构的给药途径
37
+
38
+	beego.Router("/api/pharmacy/getgoodinventorylist", &PharmacyController{}, "Get:GetGoodInventoryList")
39
+	beego.Router("/api/pharmacy/getgoodinventorybygoodid", &PharmacyController{}, "Get:GetGoodInventoryByGoodId")
40
+	beego.Router("/api/pharmacy/updateInventoryWarehouseInfo", &PharmacyController{}, "Get:UpdateInventoryWarehouseInfo")
41
+
42
+	beego.Router("/api/pharmacy/getdruginventoryList", &PharmacyController{}, "Get:GetDrugInventoryList")
37 43
 }
38 44
 
39 45
 // 测试
@@ -839,3 +845,247 @@ func (this *PharmacyController) RouteOfAdministration() {
839 845
 	})
840 846
 	return
841 847
 }
848
+
849
+func (this *PharmacyController) GetGoodInventoryList() {
850
+
851
+	keyword := this.GetString("keywords")
852
+	orgId := this.GetAdminUserInfo().CurrentOrgId
853
+	list, _ := service.GetGoodInventoryList(keyword, orgId)
854
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
855
+	this.ServeSuccessJSON(map[string]interface{}{
856
+		"list":             list,
857
+		"manufacturerList": manufacturerList,
858
+	})
859
+	return
860
+}
861
+
862
+func (this *PharmacyController) GetGoodInventoryByGoodId() {
863
+
864
+	id, _ := this.GetInt64("id")
865
+
866
+	infoList, _ := service.GetGoodInventoryByGoodId(id)
867
+
868
+	this.ServeSuccessJSON(map[string]interface{}{
869
+		"infoList": infoList,
870
+	})
871
+}
872
+
873
+func (this *PharmacyController) UpdateInventoryWarehouseInfo() {
874
+
875
+	id, _ := this.GetInt64("id")
876
+
877
+	stock_count, _ := this.GetInt64("stock_count")
878
+
879
+	last_stock_count, _ := this.GetInt64("last_stock_count")
880
+
881
+	good_id, _ := this.GetInt64("good_id")
882
+
883
+	orgId := this.GetAdminUserInfo().CurrentOrgId
884
+
885
+	storehouse_id, _ := this.GetInt64("storehouse_id")
886
+
887
+	is_type, _ := this.GetInt64("is_type")
888
+
889
+	warehouseInfo, _ := service.GetInventoryWarehouseInfo(id)
890
+	goodInfo, _ := service.GetGoodInformationByGoodIdThirty(good_id)
891
+
892
+	manufacturer, _ := service.GetManufactureById(warehouseInfo.Manufacturer)
893
+
894
+	//更新库存
895
+	service.UpdateWarehouseInfoById(last_stock_count, id)
896
+	recordDateStr := time.Now().Format("2006-01-02")
897
+	recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
898
+	goodListOne, _ := service.GetSumGoodList(orgId, storehouse_id, good_id)
899
+	var flush_count int64
900
+	for _, it := range goodListOne {
901
+		flush_count += it.StockCount
902
+	}
903
+	//盘盈
904
+	if last_stock_count > stock_count {
905
+		var total_count int64
906
+		total_count = last_stock_count - stock_count
907
+		creater := this.GetAdminUserInfo().AdminUser.Id
908
+		inventory := models.XtStockInventory{
909
+			GoodName:          goodInfo.GoodName,
910
+			SpecificationName: goodInfo.SpecificationName,
911
+			WarehousingUnit:   goodInfo.PackingUnit,
912
+			Count:             total_count,
913
+			BuyPrice:          goodInfo.BuyPrice,
914
+			PackingPrice:      goodInfo.PackingPrice,
915
+			NewPrice:          0,
916
+			Manufacturer:      manufacturer.ManufacturerName,
917
+			Dealer:            "",
918
+			Remark:            "",
919
+			GoodId:            good_id,
920
+			UserOrgId:         orgId,
921
+			Ctime:             time.Now().Unix(),
922
+			Mtime:             0,
923
+			Status:            1,
924
+			WarehousingOrder:  warehouseInfo.WarehousingOrder,
925
+			LicenseNumber:     warehouseInfo.LicenseNumber,
926
+			StartTime:         time.Now().Unix(),
927
+			Creater:           creater,
928
+			Checker:           0,
929
+			CheckerStatus:     0,
930
+			CheckerTime:       0,
931
+			Total:             0,
932
+			Number:            warehouseInfo.Number,
933
+			WarehousingInfoId: id,
934
+			ExpireDate:        warehouseInfo.ExpiryDate,
935
+			ProductDate:       warehouseInfo.ProductDate,
936
+			GoodOriginPlace:   "",
937
+			Type:              10,
938
+			InventoryType:     is_type,
939
+			LastStockCount:    last_stock_count,
940
+			StockCount:        stock_count,
941
+			StorehouseId:      storehouse_id,
942
+			RecordDate:        recordDate.Unix(),
943
+		}
944
+		service.CreateInentory(inventory)
945
+
946
+		stockFlow := models.VmStockFlow{
947
+			WarehousingId:           0,
948
+			GoodId:                  good_id,
949
+			Number:                  warehouseInfo.Number,
950
+			LicenseNumber:           "",
951
+			Count:                   total_count,
952
+			UserOrgId:               orgId,
953
+			PatientId:               0,
954
+			SystemTime:              recordDate.Unix(),
955
+			ConsumableType:          10,
956
+			IsSys:                   0,
957
+			WarehousingOrder:        warehouseInfo.WarehousingOrder,
958
+			WarehouseOutId:          0,
959
+			WarehouseOutOrderNumber: "",
960
+			IsEdit:                  0,
961
+			CancelStockId:           0,
962
+			CancelOrderNumber:       "",
963
+			Manufacturer:            warehouseInfo.Manufacturer,
964
+			Dealer:                  0,
965
+			Creator:                 creater,
966
+			UpdateCreator:           0,
967
+			Status:                  1,
968
+			Ctime:                   time.Now().Unix(),
969
+			Mtime:                   0,
970
+			Price:                   warehouseInfo.Price,
971
+			WarehousingDetailId:     0,
972
+			WarehouseOutDetailId:    0,
973
+			CancelOutDetailId:       0,
974
+			ProductDate:             warehouseInfo.ProductDate,
975
+			ExpireDate:              warehouseInfo.ExpiryDate,
976
+			ReturnCount:             0,
977
+			StorehouseId:            storehouse_id,
978
+			OverCount:               flush_count,
979
+		}
980
+		service.CreateStockFlowOne(stockFlow)
981
+
982
+		service.ReduceSumOutCount(good_id, total_count, storehouse_id, orgId)
983
+	}
984
+
985
+	//盘亏
986
+	if last_stock_count < stock_count {
987
+		var total_count int64
988
+		total_count = stock_count - last_stock_count
989
+		creater := this.GetAdminUserInfo().AdminUser.Id
990
+		inventory := models.XtStockInventory{
991
+			GoodName:          goodInfo.GoodName,
992
+			SpecificationName: goodInfo.SpecificationName,
993
+			WarehousingUnit:   goodInfo.PackingUnit,
994
+			Count:             total_count,
995
+			BuyPrice:          goodInfo.BuyPrice,
996
+			PackingPrice:      goodInfo.PackingPrice,
997
+			NewPrice:          0,
998
+			Manufacturer:      manufacturer.ManufacturerName,
999
+			Dealer:            "",
1000
+			Remark:            "",
1001
+			GoodId:            good_id,
1002
+			UserOrgId:         orgId,
1003
+			Ctime:             time.Now().Unix(),
1004
+			Mtime:             0,
1005
+			Status:            1,
1006
+			WarehousingOrder:  warehouseInfo.WarehousingOrder,
1007
+			LicenseNumber:     warehouseInfo.LicenseNumber,
1008
+			StartTime:         time.Now().Unix(),
1009
+			Creater:           creater,
1010
+			Checker:           0,
1011
+			CheckerStatus:     0,
1012
+			CheckerTime:       0,
1013
+			Total:             0,
1014
+			Number:            warehouseInfo.Number,
1015
+			WarehousingInfoId: id,
1016
+			ExpireDate:        warehouseInfo.ExpiryDate,
1017
+			ProductDate:       warehouseInfo.ProductDate,
1018
+			GoodOriginPlace:   "",
1019
+			Type:              10,
1020
+			InventoryType:     is_type,
1021
+			LastStockCount:    last_stock_count,
1022
+			StockCount:        stock_count,
1023
+			StorehouseId:      storehouse_id,
1024
+			RecordDate:        recordDate.Unix(),
1025
+		}
1026
+		service.CreateInentory(inventory)
1027
+
1028
+		stockFlow := models.VmStockFlow{
1029
+			WarehousingId:           0,
1030
+			GoodId:                  good_id,
1031
+			Number:                  warehouseInfo.Number,
1032
+			LicenseNumber:           "",
1033
+			Count:                   total_count,
1034
+			UserOrgId:               orgId,
1035
+			PatientId:               0,
1036
+			SystemTime:              recordDate.Unix(),
1037
+			ConsumableType:          11,
1038
+			IsSys:                   0,
1039
+			WarehousingOrder:        warehouseInfo.WarehousingOrder,
1040
+			WarehouseOutId:          0,
1041
+			WarehouseOutOrderNumber: "",
1042
+			IsEdit:                  0,
1043
+			CancelStockId:           0,
1044
+			CancelOrderNumber:       "",
1045
+			Manufacturer:            warehouseInfo.Manufacturer,
1046
+			Dealer:                  0,
1047
+			Creator:                 creater,
1048
+			UpdateCreator:           0,
1049
+			Status:                  1,
1050
+			Ctime:                   time.Now().Unix(),
1051
+			Mtime:                   0,
1052
+			Price:                   warehouseInfo.Price,
1053
+			WarehousingDetailId:     0,
1054
+			WarehouseOutDetailId:    0,
1055
+			CancelOutDetailId:       0,
1056
+			ProductDate:             warehouseInfo.ProductDate,
1057
+			ExpireDate:              warehouseInfo.ExpiryDate,
1058
+			ReturnCount:             0,
1059
+			StorehouseId:            storehouse_id,
1060
+			OverCount:               flush_count,
1061
+		}
1062
+		service.CreateStockFlowOne(stockFlow)
1063
+		service.ReduceSumInCount(good_id, total_count, storehouse_id, orgId)
1064
+	}
1065
+
1066
+	//查询已审核单据的剩余库存
1067
+	goodList, _ := service.GetGoodSumCountByStoreId(storehouse_id, good_id, orgId)
1068
+	var sum_count int64
1069
+	var sum_in_count int64
1070
+	for _, item := range goodList {
1071
+		sum_count += item.StockCount
1072
+		sum_in_count += item.WarehousingCount
1073
+	}
1074
+	service.UpdateGoodByGoodId(good_id, sum_count, sum_in_count, orgId)
1075
+
1076
+	service.UpdateSumGood(orgId, storehouse_id, good_id, flush_count)
1077
+	this.ServeSuccessJSON(map[string]interface{}{
1078
+		"msg": "msg",
1079
+	})
1080
+
1081
+}
1082
+
1083
+func (this *PharmacyController) GetDrugInventoryList() {
1084
+
1085
+	orgId := this.GetAdminUserInfo().CurrentOrgId
1086
+	drugList, _ := service.GetDrugNewInventoryList(orgId)
1087
+
1088
+	this.ServeSuccessJSON(map[string]interface{}{
1089
+		"drugList": drugList,
1090
+	})
1091
+}

+ 153 - 123
controllers/schedule_api_controller.go 파일 보기

@@ -258,6 +258,27 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
258 258
 		return
259 259
 	}
260 260
 
261
+	//drugOutConfig, _ := service.FindDrugOutConfigById(adminInfo.CurrentOrgId)
262
+	//
263
+	//recordDateStr := time.Now().Format("2006-01-02")
264
+	//
265
+	//recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
266
+	//退库
267
+	//if drugOutConfig.IsOpen == 1 {
268
+	//	hisAdvice, _ := service.GetPatientDrugCountToday(patient_id, recordDate.Unix(), adminInfo.CurrentOrgId)
269
+	//
270
+	//	if len(hisAdvice) > 0 {
271
+	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
272
+	//		return
273
+	//	}
274
+	//}
275
+
276
+	//list, _ := service.GetPatientGoodCountToday(patient_id, recordDate.Unix(), adminInfo.CurrentOrgId)
277
+	//if len(list) > 0 {
278
+	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
279
+	//	return
280
+	//}
281
+
261 282
 	//数据校验
262 283
 	if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
263 284
 		schs, _ := dataBody["smart_schs"].([]interface{})
@@ -466,6 +487,7 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
466 487
 
467 488
 					//一天只有排班一次
468 489
 					daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
490
+
469 491
 					if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
470 492
 						week_type, _ := items["week_type"].(string)
471 493
 						week_name, _ := items["week_name"].(string)
@@ -2028,137 +2050,145 @@ func (c *ScheduleApiController) DeleteSchedule() {
2028 2050
 	drugOutConfig, _ := service.FindDrugOutConfigById(adminINfo.CurrentOrgId)
2029 2051
 	//退库
2030 2052
 	if drugOutConfig.IsOpen == 1 {
2031
-		hisAdvice, _ := service.GetHisDoctorAdviceListTwentyOne(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
2032
-		for _, item := range hisAdvice {
2033
-			creater := adminINfo.AdminUser.Id
2034
-			err = service.DrugAutoAddCancelInfo(item, creater)
2035
-			if err != nil {
2036
-				err = fmt.Errorf("!:%v", err)
2037
-				return
2038
-			}
2053
+		hisAdvice, _ := service.GetPatientDrugCountToday(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
2054
+
2055
+		if len(hisAdvice) > 0 {
2056
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
2057
+			return
2039 2058
 		}
2040
-		//查询是否有出库记录
2041
-		service.GetPatientGoodStockCount(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
2059
+		//for _, item := range hisAdvice {
2060
+		//	creater := adminINfo.AdminUser.Id
2061
+		//	err = service.DrugAutoAddCancelInfo(item, creater)
2062
+		//	if err != nil {
2063
+		//		err = fmt.Errorf("!:%v", err)
2064
+		//		return
2065
+		//	}
2066
+		//}
2067
+		////查询是否有出库记录
2068
+		//service.GetPatientGoodStockCount(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
2042 2069
 	}
2043 2070
 
2044 2071
 	//查询该患者当天是否开耗材
2045 2072
 	list, _ := service.GetPatientGoodCountToday(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
2046 2073
 	if len(list) > 0 {
2047 2074
 
2048
-		operation_time := time.Now().Unix()
2049
-		creater := c.GetAdminUserInfo().AdminUser.Id
2050
-		//创建退库单
2051
-		timeStr := time.Now().Format("2006-01-02")
2052
-		timeArr := strings.Split(timeStr, "-")
2053
-		total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
2054
-		total = total + 1
2055
-		orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
2056
-		houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
2057
-		cancelStock := models.CancelStock{
2058
-			OrderNumber:  orderNumber,
2059
-			OperaTime:    operation_time,
2060
-			OrgId:        c.GetAdminUserInfo().CurrentOrgId,
2061
-			Creater:      creater,
2062
-			Ctime:        time.Now().Unix(),
2063
-			Status:       1,
2064
-			ReturnTime:   schedule.ScheduleDate,
2065
-			Type:         1,
2066
-			StorehouseId: houseConfig.StorehouseOutInfo,
2067
-			IsCheck:      1,
2068
-		}
2069
-		_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(schedule.ScheduleDate, c.GetAdminUserInfo().CurrentOrgId)
2070
-		if msgerrkonde == gorm.ErrRecordNotFound {
2071
-			service.AddSigleCancelStock(&cancelStock)
2072
-		}
2073
-		cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
2074
-		//进行退库操作
2075
-		for _, item := range list {
2076
-			good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
2077
-			manufacturer, _ := service.GetManufactureById(item.Manufacturer)
2078
-			deaerler, _ := service.GetDealerById(item.Dealer)
2079
-			//回退库存
2080
-			service.UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
2081
-			goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId)
2082
-			var flush_count int64
2083
-			for _, it := range goodList {
2084
-				flush_count += it.StockCount
2085
-			}
2086
-			cancelStockInfo := models.CancelStockInfo{
2087
-				GoodId:          item.GoodId,
2088
-				CancelStockId:   cancel.ID,
2089
-				GoodTypeId:      good.GoodTypeId,
2090
-				Count:           item.Count,
2091
-				Price:           item.Price,
2092
-				Total:           0,
2093
-				ProductDate:     item.ProductDate,
2094
-				ExpiryDate:      item.ExpiryDate,
2095
-				Ctime:           time.Now().Unix(),
2096
-				Status:          1,
2097
-				OrgId:           c.GetAdminUserInfo().CurrentOrgId,
2098
-				OrderNumber:     cancel.OrderNumber,
2099
-				Type:            0,
2100
-				Dealer:          deaerler.DealerName,
2101
-				Manufacturer:    manufacturer.ManufacturerName,
2102
-				Number:          item.Number,
2103
-				RegisterAccount: "",
2104
-				Remark:          "",
2105
-				WarehouseInfoId: item.WarehouseInfotId,
2106
-				PatientId:       item.PatientId,
2107
-				RecordDate:      item.SysRecordTime,
2108
-				StorehouseId:    houseConfig.StorehouseOutInfo,
2109
-				IsCheck:         1,
2110
-			}
2111
-
2112
-			service.CreateCancelStockInfoOne(&cancelStockInfo)
2113
-
2114
-			cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
2115
-
2116
-			flow := models.VmStockFlow{
2117
-				WarehousingId:           item.WarehouseInfotId,
2118
-				GoodId:                  item.GoodId,
2119
-				Number:                  item.Number,
2120
-				LicenseNumber:           item.LicenseNumber,
2121
-				Count:                   item.Count,
2122
-				UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
2123
-				PatientId:               item.PatientId,
2124
-				SystemTime:              item.SysRecordTime,
2125
-				ConsumableType:          7,
2126
-				IsSys:                   0,
2127
-				WarehousingOrder:        "",
2128
-				WarehouseOutId:          item.WarehouseOutId,
2129
-				WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
2130
-				IsEdit:                  0,
2131
-				CancelStockId:           cancel.ID,
2132
-				CancelOrderNumber:       cancel.OrderNumber,
2133
-				Manufacturer:            manufacturer.ID,
2134
-				Dealer:                  0,
2135
-				Creator:                 c.GetAdminUserInfo().CurrentOrgId,
2136
-				UpdateCreator:           0,
2137
-				Status:                  1,
2138
-				Ctime:                   time.Now().Unix(),
2139
-				Mtime:                   0,
2140
-				Price:                   item.Price,
2141
-				WarehousingDetailId:     item.WarehouseInfotId,
2142
-				WarehouseOutDetailId:    item.ID,
2143
-				CancelOutDetailId:       cancelInfo.ID,
2144
-				ProductDate:             item.ProductDate,
2145
-				ExpireDate:              item.ExpiryDate,
2146
-				StorehouseId:            houseConfig.StorehouseOutInfo,
2147
-				OverCount:               flush_count,
2148
-			}
2149
-			service.CreateStockFlowOne(flow)
2150
-
2151
-			//退库数量增加
2152
-			service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.GoodId, houseConfig.StorehouseOutInfo, item.Count)
2153
-			//出库数量减少
2154
-			service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId, item.Count)
2155
-
2156
-			//更新库存
2157
-			service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
2075
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
2076
+		return
2158 2077
 
2159
-			//更新基础库库存
2160
-			service.UpdateGoodInfoSumCountSix(item.GoodId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
2161
-		}
2078
+		//operation_time := time.Now().Unix()
2079
+		//creater := c.GetAdminUserInfo().AdminUser.Id
2080
+		////创建退库单
2081
+		//timeStr := time.Now().Format("2006-01-02")
2082
+		//timeArr := strings.Split(timeStr, "-")
2083
+		//total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
2084
+		//total = total + 1
2085
+		//orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
2086
+		//houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
2087
+		//cancelStock := models.CancelStock{
2088
+		//	OrderNumber:  orderNumber,
2089
+		//	OperaTime:    operation_time,
2090
+		//	OrgId:        c.GetAdminUserInfo().CurrentOrgId,
2091
+		//	Creater:      creater,
2092
+		//	Ctime:        time.Now().Unix(),
2093
+		//	Status:       1,
2094
+		//	ReturnTime:   schedule.ScheduleDate,
2095
+		//	Type:         1,
2096
+		//	StorehouseId: houseConfig.StorehouseOutInfo,
2097
+		//	IsCheck:      1,
2098
+		//}
2099
+		//_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(schedule.ScheduleDate, c.GetAdminUserInfo().CurrentOrgId)
2100
+		//if msgerrkonde == gorm.ErrRecordNotFound {
2101
+		//	service.AddSigleCancelStock(&cancelStock)
2102
+		//}
2103
+		//cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
2104
+		////进行退库操作
2105
+		//for _, item := range list {
2106
+		//	good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
2107
+		//	manufacturer, _ := service.GetManufactureById(item.Manufacturer)
2108
+		//	deaerler, _ := service.GetDealerById(item.Dealer)
2109
+		//	//回退库存
2110
+		//	service.UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
2111
+		//	goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId)
2112
+		//	var flush_count int64
2113
+		//	for _, it := range goodList {
2114
+		//		flush_count += it.StockCount
2115
+		//	}
2116
+		//	cancelStockInfo := models.CancelStockInfo{
2117
+		//		GoodId:          item.GoodId,
2118
+		//		CancelStockId:   cancel.ID,
2119
+		//		GoodTypeId:      good.GoodTypeId,
2120
+		//		Count:           item.Count,
2121
+		//		Price:           item.Price,
2122
+		//		Total:           0,
2123
+		//		ProductDate:     item.ProductDate,
2124
+		//		ExpiryDate:      item.ExpiryDate,
2125
+		//		Ctime:           time.Now().Unix(),
2126
+		//		Status:          1,
2127
+		//		OrgId:           c.GetAdminUserInfo().CurrentOrgId,
2128
+		//		OrderNumber:     cancel.OrderNumber,
2129
+		//		Type:            0,
2130
+		//		Dealer:          deaerler.DealerName,
2131
+		//		Manufacturer:    manufacturer.ManufacturerName,
2132
+		//		Number:          item.Number,
2133
+		//		RegisterAccount: "",
2134
+		//		Remark:          "",
2135
+		//		WarehouseInfoId: item.WarehouseInfotId,
2136
+		//		PatientId:       item.PatientId,
2137
+		//		RecordDate:      item.SysRecordTime,
2138
+		//		StorehouseId:    houseConfig.StorehouseOutInfo,
2139
+		//		IsCheck:         1,
2140
+		//	}
2141
+		//
2142
+		//	service.CreateCancelStockInfoOne(&cancelStockInfo)
2143
+		//
2144
+		//	cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
2145
+		//
2146
+		//	flow := models.VmStockFlow{
2147
+		//		WarehousingId:           item.WarehouseInfotId,
2148
+		//		GoodId:                  item.GoodId,
2149
+		//		Number:                  item.Number,
2150
+		//		LicenseNumber:           item.LicenseNumber,
2151
+		//		Count:                   item.Count,
2152
+		//		UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
2153
+		//		PatientId:               item.PatientId,
2154
+		//		SystemTime:              item.SysRecordTime,
2155
+		//		ConsumableType:          7,
2156
+		//		IsSys:                   0,
2157
+		//		WarehousingOrder:        "",
2158
+		//		WarehouseOutId:          item.WarehouseOutId,
2159
+		//		WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
2160
+		//		IsEdit:                  0,
2161
+		//		CancelStockId:           cancel.ID,
2162
+		//		CancelOrderNumber:       cancel.OrderNumber,
2163
+		//		Manufacturer:            manufacturer.ID,
2164
+		//		Dealer:                  0,
2165
+		//		Creator:                 c.GetAdminUserInfo().CurrentOrgId,
2166
+		//		UpdateCreator:           0,
2167
+		//		Status:                  1,
2168
+		//		Ctime:                   time.Now().Unix(),
2169
+		//		Mtime:                   0,
2170
+		//		Price:                   item.Price,
2171
+		//		WarehousingDetailId:     item.WarehouseInfotId,
2172
+		//		WarehouseOutDetailId:    item.ID,
2173
+		//		CancelOutDetailId:       cancelInfo.ID,
2174
+		//		ProductDate:             item.ProductDate,
2175
+		//		ExpireDate:              item.ExpiryDate,
2176
+		//		StorehouseId:            houseConfig.StorehouseOutInfo,
2177
+		//		OverCount:               flush_count,
2178
+		//	}
2179
+		//	service.CreateStockFlowOne(flow)
2180
+		//
2181
+		//	//退库数量增加
2182
+		//	service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.GoodId, houseConfig.StorehouseOutInfo, item.Count)
2183
+		//	//出库数量减少
2184
+		//	service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId, item.Count)
2185
+		//
2186
+		//	//更新库存
2187
+		//	service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
2188
+		//
2189
+		//	//更新基础库库存
2190
+		//	service.UpdateGoodInfoSumCountSix(item.GoodId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
2191
+		//}
2162 2192
 	}
2163 2193
 
2164 2194
 	err = service.UpdateSchedule(schedule)

+ 6 - 6
controllers/sign_api_controller.go 파일 보기

@@ -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,11 +1238,11 @@ func (this *SignApiController) ToAutoDiagnose() {
1238 1238
 	//	service.UpdateAllPatient(item.BloodId, item.Diagnose, item.UserOrgId)
1239 1239
 	//}
1240 1240
 
1241
-	list, _ := service.GetAllDialysisOrder(14749)
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
-	}
1241
+	//list, _ := service.GetAllDialysisOrder(14749)
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
+	//}
1246 1246
 
1247 1247
 	//drugList, _ := service.GetAllBaseDrugList(10318)
1248 1248
 	//for _, item := range drugList {

+ 3 - 0
enums/error_code.go 파일 보기

@@ -281,6 +281,8 @@ const ( // ErrorCode
281 281
 	ErrorCodeInformationExist = 600000008
282 282
 
283 283
 	ErrorScheduleCode = 600000009
284
+
285
+	ErrorAdivceCode = 600000010
284 286
 )
285 287
 
286 288
 var ErrCodeMsgs = map[int]string{
@@ -542,6 +544,7 @@ var ErrCodeMsgs = map[int]string{
542 544
 	AdviceCodeParamWrong:                  "医嘱核对人和执行人不能为同一人,请更换第二核对人!",
543 545
 	ErrorCodeInformationExist:             "已经超过归档天数,不予编辑,请提交申请",
544 546
 	ErrorScheduleCode:                     "未更改排班,保存失败!",
547
+	ErrorAdivceCode:                       "该患者已开药,请先删除药品或耗材",
545 548
 }
546 549
 
547 550
 type SGJError struct {

+ 10 - 8
models/device_models.go 파일 보기

@@ -137,14 +137,15 @@ func (DeviceZonePb) TableName() string {
137 137
 }
138 138
 
139 139
 type DialysisSolutionPb struct {
140
-	UserOrgId                  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
141
-	PatientId                  int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
142
-	DialysisDialyszers         string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
143
-	DialysisIrrigation         string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
144
-	DialyzerPerfusionApparatus string `gorm:"column:dialyzer_perfusion_apparatus" json:"dialyzer_perfusion_apparatus"`
145
-	ModeName                   string `gorm:"column:mode_name" json:"mode_name" form:"mode_name"`
146
-	ModeId                     int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
147
-	Anticoagulant              int64  `gorm:"column:anticoagulant" json:"anticoagulant" form:"anticoagulant"`
140
+	UserOrgId                  int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
141
+	PatientId                  int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
142
+	DialysisDialyszers         string  `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
143
+	DialysisIrrigation         string  `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
144
+	DialyzerPerfusionApparatus string  `gorm:"column:dialyzer_perfusion_apparatus" json:"dialyzer_perfusion_apparatus"`
145
+	ModeName                   string  `gorm:"column:mode_name" json:"mode_name" form:"mode_name"`
146
+	ModeId                     int64   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
147
+	Anticoagulant              int64   `gorm:"column:anticoagulant" json:"anticoagulant" form:"anticoagulant"`
148
+	Calcium                    float64 `gorm:"column:calcium" json:"calcium" form:"calcium"`
148 149
 }
149 150
 
150 151
 func (DialysisSolutionPb) TableName() string {
@@ -204,6 +205,7 @@ type BloodDialysisPrescriptionPb struct {
204 205
 	AnticoagulantGaijiliang   string  `gorm:"column:anticoagulant_gaijiliang" json:"anticoagulant_gaijiliang" form:"anticoagulant_gaijiliang"`
205 206
 	DialysisDialyszers        string  `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
206 207
 	DialysisIrrigation        string  `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
208
+	Calcium                   float64 `gorm:"column:calcium" json:"calcium" form:"calcium"`
207 209
 }
208 210
 
209 211
 func (BloodDialysisPrescriptionPb) TableName() string {

+ 44 - 0
models/dialysis.go 파일 보기

@@ -1488,6 +1488,50 @@ func (HisDoctorAdviceFourty) TableName() string {
1488 1488
 	return "his_doctor_advice_info"
1489 1489
 }
1490 1490
 
1491
+type HisPrescriptionProjectFourty struct {
1492
+	ID                   int64         `gorm:"column:id" json:"id" form:"id"`
1493
+	ProjectId            int64         `gorm:"column:project_id" json:"project_id" form:"project_id"`
1494
+	Price                float64       `gorm:"column:price" json:"price" form:"price"`
1495
+	UserOrgId            int64         `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1496
+	Status               int64         `gorm:"column:status" json:"status" form:"status"`
1497
+	Ctime                int64         `gorm:"column:ctime" json:"ctime" form:"ctime"`
1498
+	Mtime                int64         `gorm:"column:mtime" json:"mtime" form:"mtime"`
1499
+	PatientId            int64         `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1500
+	HisPatientId         int64         `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
1501
+	RecordDate           int64         `gorm:"column:record_date" json:"record_date" form:"record_date"`
1502
+	PrescriptionId       int64         `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
1503
+	Count                string        `gorm:"column:count" json:"count" form:"count"`
1504
+	FeedetlSn            string        `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
1505
+	MedListCodg          string        `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
1506
+	SingleDose           string        `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
1507
+	DeliveryWay          string        `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
1508
+	ExecutionFrequency   string        `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
1509
+	Day                  string        `gorm:"column:day" json:"day" form:"day"`
1510
+	Remark               string        `gorm:"column:remark" json:"remark" form:"remark"`
1511
+	Unit                 string        `gorm:"column:unit" json:"unit" form:"unit"`
1512
+	Type                 int64         `gorm:"column:type" json:"type" form:"type"`
1513
+	Doctor               int64         `gorm:"column:doctor" json:"doctor" form:"doctor"`
1514
+	ExecutionTime        int64         `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
1515
+	ExecutionStaff       int64         `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
1516
+	ExecutionState       int64         `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
1517
+	CheckTime            int64         `gorm:"column:check_time" json:"check_time" form:"check_time"`
1518
+	CheckState           int64         `gorm:"column:check_state" json:"check_state" form:"check_state"`
1519
+	Checker              int64         `gorm:"column:checker" json:"checker" form:"checker"`
1520
+	StartTime            int64         `gorm:"column:start_time" json:"start_time" form:"start_time"`
1521
+	TeamId               int64         `gorm:"column:team_id" json:"team_id" form:"team_id"`
1522
+	FrequencyType        int64         `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
1523
+	DayCount             int64         `gorm:"column:day_count" json:"day_count" form:"day_count"`
1524
+	WeekDay              string        `gorm:"column:week_day" json:"week_day" form:"week_day"`
1525
+	ExecutionFrequencyId int64         `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
1526
+	IsOut                int64         `gorm:"column:is_out" json:"is_out" form:"is_out"`
1527
+	YbSyncStatus         int64         `gorm:"column:yb_sync_status" json:"yb_sync_status" form:"yb_sync_status"`
1528
+	Good                 GoodInfoSeven `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good"`
1529
+}
1530
+
1531
+func (HisPrescriptionProjectFourty) TableName() string {
1532
+	return "his_prescription_project"
1533
+}
1534
+
1491 1535
 type NewDialysisOrder struct {
1492 1536
 	ID                 int64  `gorm:"column:id" json:"id"`
1493 1537
 	DialysisDate       int64  `gorm:"column:dialysis_date" json:"dialysis_date"`

+ 1 - 0
models/drug_stock.go 파일 보기

@@ -460,6 +460,7 @@ type DrugFlow struct {
460 460
 	OrderId                   int64                  `gorm:"column:order_id" json:"order_id" form:"order_id"`
461 461
 	FlushOverCount            int64                  `gorm:"column:flush_over_count" json:"flush_over_count" form:"flush_over_count"`
462 462
 	Remark                    string                 `gorm:"column:remark" json:"remark" form:"remark"`
463
+	OperateTime               int64                  `gorm:"column:operate_time" json:"operate_time" form:"operate_time"`
463 464
 }
464 465
 
465 466
 func (DrugFlow) TableName() string {

+ 18 - 3
models/good_models.go 파일 보기

@@ -236,9 +236,10 @@ func (GoodInfoSevenThirty) TableName() string {
236 236
 }
237 237
 
238 238
 type GoodInfoSeven struct {
239
-	ID         int64  `gorm:"column:id" json:"id" form:"id"`
240
-	GoodName   string `gorm:"column:good_name" json:"good_name" form:"good_name"`
241
-	GoodStatus string `gorm:"column:good_status" json:"good_status" form:"good_status"`
239
+	ID                int64  `gorm:"column:id" json:"id" form:"id"`
240
+	GoodName          string `gorm:"column:good_name" json:"good_name" form:"good_name"`
241
+	GoodStatus        string `gorm:"column:good_status" json:"good_status" form:"good_status"`
242
+	SpecificationName string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
242 243
 }
243 244
 
244 245
 func (GoodInfoSeven) TableName() string {
@@ -256,6 +257,20 @@ func (GoodInfoTen) TableName() string {
256 257
 	return "xt_good_information"
257 258
 }
258 259
 
260
+type GoodInfoEight struct {
261
+	ID                int64  `gorm:"column:id" json:"id" form:"id"`
262
+	GoodName          string `gorm:"column:good_name" json:"good_name" form:"good_name"`
263
+	GoodStatus        string `gorm:"column:good_status" json:"good_status" form:"good_status"`
264
+	SpecificationName string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
265
+	OrgId             int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
266
+	Status            int64  `gorm:"column:status" json:"status" form:"status"`
267
+	Manufacturer      int64  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
268
+}
269
+
270
+func (GoodInfoEight) TableName() string {
271
+	return "xt_good_information"
272
+}
273
+
259 274
 type GoodsTypeOne struct {
260 275
 	ID             int64                    `gorm:"column:id" json:"id"`
261 276
 	TypeCode       string                   `gorm:"column:type_code" json:"type_code"`

+ 23 - 0
models/schedule_models.go 파일 보기

@@ -648,6 +648,29 @@ func (VmBloodScheduleOne) TableName() string {
648 648
 	return "xt_schedule"
649 649
 }
650 650
 
651
+type VmBloodScheduleSix struct {
652
+	ID                     int64                           `gorm:"column:id" json:"id" form:"id"`
653
+	UserOrgId              int64                           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
654
+	PartitionId            int64                           `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
655
+	BedId                  int64                           `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
656
+	PatientId              int64                           `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
657
+	ScheduleDate           int64                           `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
658
+	ScheduleType           int64                           `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
659
+	ScheduleWeek           int64                           `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
660
+	ModeId                 int64                           `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
661
+	Status                 int64                           `gorm:"column:status" json:"status" form:"status"`
662
+	CreatedTime            int64                           `gorm:"column:created_time" json:"created_time" form:"created_time"`
663
+	UpdatedTime            int64                           `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
664
+	IsExport               int64                           `gorm:"column:is_export" json:"is_export" form:"is_export"`
665
+	DeviceNumber           *NewMDeviceNumberVM             `gorm:"ForeignKey:BedId" json:"device_number"`
666
+	SchedualPatient        *NewMSchedualPatientVMList      `gorm:"ForeignKey:PatientId" json:"patient"`
667
+	HisPrescriptionProject []*HisPrescriptionProjectFourty `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"his_doctor_project"`
668
+}
669
+
670
+func (VmBloodScheduleSix) TableName() string {
671
+	return "xt_schedule"
672
+}
673
+
651 674
 type VmNewSchedulesRemind struct {
652 675
 	ID           int64 `gorm:"column:id" json:"id" form:"id"`
653 676
 	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`

+ 1 - 1
models/smart_sch.go 파일 보기

@@ -5,7 +5,7 @@ type SmartSchPatient struct {
5 5
 	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6 6
 	Name       string `gorm:"column:name" json:"name" form:"name"`
7 7
 	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
8
-
8
+	Lapseto    int64  `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
9 9
 	//SmartSchedule []*SmartSchedule `gorm:"-" json:"sch"`
10 10
 }
11 11
 

+ 43 - 0
models/stock_models.go 파일 보기

@@ -697,6 +697,7 @@ type VmStockFlow struct {
697 697
 	OrderId                   int64           `gorm:"column:order_id" json:"order_id" form:"order_id"`
698 698
 	Remark                    string          `gorm:"column:remark" json:"remark" form:"remark"`
699 699
 	FlushOverCount            int64           `gorm:"column:flush_over_count" json:"flush_over_count" form:"flush_over_count"`
700
+	OperateTime               int64           `gorm:"column:operate_time" json:"operate_time" form:"operate_time"`
700 701
 }
701 702
 
702 703
 func (VmStockFlow) TableName() string {
@@ -1188,6 +1189,7 @@ type XtStockInventory struct {
1188 1189
 	StorehouseId      int64           `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
1189 1190
 	GoodInfo          GoodInfo        `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
1190 1191
 	WarehousingInfo   WarehousingInfo `gorm:"ForeignKey:ID;AssociationForeignKey:WarehousingInfoId" json:"xt_warehouse_info"`
1192
+	RecordDate        int64           `gorm:"column:record_date" json:"record_date" form:"record_date"`
1191 1193
 }
1192 1194
 
1193 1195
 func (XtStockInventory) TableName() string {
@@ -1722,3 +1724,44 @@ type WarehouseOutInfoTenty struct {
1722 1724
 func (WarehouseOutInfoTenty) TableName() string {
1723 1725
 	return "xt_warehouse_out_info"
1724 1726
 }
1727
+
1728
+type XtWarehouseInfoEight struct {
1729
+	ID                        int64   `gorm:"column:id" json:"id" form:"id"`
1730
+	WarehousingId             int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
1731
+	GoodId                    int64   `gorm:"column:good_id" json:"good_id" form:"good_id"`
1732
+	GoodTypeId                int64   `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
1733
+	Number                    string  `gorm:"column:number" json:"number" form:"number"`
1734
+	ProductDate               int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
1735
+	ExpiryDate                int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
1736
+	WarehousingCount          int64   `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
1737
+	Price                     float64 `gorm:"column:price" json:"price" form:"price"`
1738
+	TotalPrice                float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
1739
+	Dealer                    int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
1740
+	Manufacturer              int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
1741
+	Remark                    string  `gorm:"column:remark" json:"remark" form:"remark"`
1742
+	Ctime                     int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
1743
+	Mtime                     int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
1744
+	Status                    int64   `gorm:"column:status" json:"status" form:"status"`
1745
+	OrgId                     int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
1746
+	IsReturn                  int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
1747
+	WarehousingOrder          string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
1748
+	Type                      int64   `gorm:"column:type" json:"type" form:"type"`
1749
+	WarehousingUnit           int64   `gorm:"column:warehousing_unit" json:"warehousing_unit" form:"warehousing_unit"`
1750
+	StockCount                int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
1751
+	LicenseNumber             string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
1752
+	WarehouseInfoId           int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
1753
+	PackingPrice              float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
1754
+	SupplyWarehouseId         int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
1755
+	SupplyWarehouseDetailInfo int64   `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
1756
+	StorehouseId              int64   `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
1757
+	SecondWarehouseInfoId     int64   `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
1758
+	IsCheck                   string  `gorm:"column:is_check" json:"is_check" form:"is_check"`
1759
+	RegisterNumber            string  `gorm:"column:register_number" json:"register_number" form:"register_number"`
1760
+	IsUpload                  int64   `gorm:"column:is_upload" json:"is_upload" form:"is_upload"`
1761
+	ManafacturerName          string  `gorm:"column:manafacturer_name" json:"manafacturer_name" form:"manafacturer_name"`
1762
+	DealerName                string  `gorm:"column:dealer_name" json:"dealer_name" form:"dealer_name"`
1763
+}
1764
+
1765
+func (XtWarehouseInfoEight) TableName() string {
1766
+	return "xt_warehouse_info"
1767
+}

+ 27 - 0
service/dialysis_solution_service.go 파일 보기

@@ -548,6 +548,33 @@ func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_
548 548
 
549 549
 }
550 550
 
551
+func GetDialysisProjectSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleSix, err error) {
552
+
553
+	db := XTReadDB().Model(&models.VmBloodScheduleSix{}).Where("status = 1")
554
+
555
+	if scheduleDate > 0 {
556
+		db = db.Where("schedule_date = ?", scheduleDate)
557
+	}
558
+	if schedule_type > 0 {
559
+		db = db.Where("schedule_type = ?", schedule_type)
560
+	}
561
+	if len(partition_id) > 0 {
562
+		db = db.Where("partition_id in(?)", partition_id)
563
+	}
564
+
565
+	if orgID > 0 {
566
+		db = db.Where("user_org_id  = ?", orgID)
567
+	}
568
+	err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
569
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
570
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
571
+			return db.Where("user_org_id = ? and status = 1 and record_date = ? and type =3", orgID, scheduleDate).Preload("Good", "org_id =? and status = 1", orgID)
572
+		}).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
573
+
574
+	return schedule, err
575
+
576
+}
577
+
551 578
 func GetHisDialysisGoodCountTwo(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
552 579
 
553 580
 	db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")

+ 159 - 0
service/his_service.go 파일 보기

@@ -3149,6 +3149,21 @@ func GetLastHisDoctorAdviceById(patient_id int64, user_org_id int64, advice_date
3149 3149
 	return adviceInfo, err
3150 3150
 }
3151 3151
 
3152
+func GetLastHisProjectById(patient_id int64, user_org_id int64, record_date int64, drug_id int64, tx *gorm.DB) (models.HisPrescriptionProject, error) {
3153
+
3154
+	projectInfo := models.HisPrescriptionProject{}
3155
+
3156
+	err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and project_id = ? and status =1", patient_id, user_org_id, record_date, drug_id).Last(&projectInfo).Error
3157
+
3158
+	if err != gorm.ErrRecordNotFound {
3159
+		if err != nil {
3160
+			tx.Rollback()
3161
+			return projectInfo, err
3162
+		}
3163
+	}
3164
+	return projectInfo, err
3165
+}
3166
+
3152 3167
 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 3168
 
3154 3169
 	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
@@ -3162,6 +3177,19 @@ func GetDrugWarehouseOutInfoByAdviceId(patient_id int64, user_org_id int64, sys_
3162 3177
 	return outInfo, err
3163 3178
 }
3164 3179
 
3180
+func GetGoodWarehouseOutInfoByAdviceId(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, tx *gorm.DB) (outInfo []*models.WarehouseOutInfo, err error) {
3181
+
3182
+	err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and good_id = ? and status=1 and project_id = 0", patient_id, user_org_id, sys_record_date, drug_id).Find(&outInfo).Error
3183
+
3184
+	if err != gorm.ErrRecordNotFound {
3185
+		if err != nil {
3186
+			tx.Rollback()
3187
+			return outInfo, err
3188
+		}
3189
+	}
3190
+	return outInfo, err
3191
+}
3192
+
3165 3193
 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 3194
 
3167 3195
 	outInfo := models.DrugWarehouseOutInfo{}
@@ -3201,6 +3229,19 @@ func GetDrugAutoDetail(patient_id int64, org_id int64, record_time int64, drug_i
3201 3229
 	return automaticReduceDetail, err
3202 3230
 }
3203 3231
 
3232
+func GetGoodAutoDetail(patient_id int64, org_id int64, record_time int64, good_id int64, tx *gorm.DB) (automaticReduceDetail []*models.AutomaticReduceDetail, err error) {
3233
+
3234
+	err = tx.Where("patient_id = ? and org_id = ? and record_time =? and good_id = ? and status =1 and project_id = 0", patient_id, org_id, record_time, good_id).Find(&automaticReduceDetail).Error
3235
+
3236
+	if err != gorm.ErrRecordNotFound {
3237
+		if err != nil {
3238
+			tx.Rollback()
3239
+			return automaticReduceDetail, err
3240
+		}
3241
+	}
3242
+	return automaticReduceDetail, err
3243
+}
3244
+
3204 3245
 func UpdateDrugAutoDetail(id int64, advice_id int64, tx *gorm.DB) error {
3205 3246
 
3206 3247
 	drugAutomaticReduceDetail := models.DrugAutomaticReduceDetail{}
@@ -3214,6 +3255,19 @@ func UpdateDrugAutoDetail(id int64, advice_id int64, tx *gorm.DB) error {
3214 3255
 	return err
3215 3256
 }
3216 3257
 
3258
+func UpdateGoodAutoDetail(id int64, project_id int64, tx *gorm.DB) error {
3259
+
3260
+	automaticReduceDetail := models.AutomaticReduceDetail{}
3261
+
3262
+	err := tx.Model(&automaticReduceDetail).Where("id = ? and status=1", id).Updates(map[string]interface{}{"project_id": project_id}).Error
3263
+
3264
+	if err != nil {
3265
+		tx.Rollback()
3266
+		return err
3267
+	}
3268
+	return err
3269
+}
3270
+
3217 3271
 func UpdateDrugOutInfoByAdviceId(id int64, advice_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
3218 3272
 
3219 3273
 	info := models.DrugWarehouseOutInfo{}
@@ -3228,6 +3282,20 @@ func UpdateDrugOutInfoByAdviceId(id int64, advice_id int64, tx *gorm.DB) (models
3228 3282
 	return info, err
3229 3283
 }
3230 3284
 
3285
+func UpdateGoodOutInfoByAdviceId(id int64, project_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
3286
+
3287
+	info := models.WarehouseOutInfo{}
3288
+
3289
+	err := tx.Model(&info).Where("id = ? and status=1", id).Updates(map[string]interface{}{"project_id": project_id}).Error
3290
+
3291
+	if err != nil {
3292
+		tx.Rollback()
3293
+		return info, err
3294
+	}
3295
+
3296
+	return info, err
3297
+}
3298
+
3231 3299
 func ModifyDrugWarehouseOutInfoByNumber(id int64, cha_count int64, tx *gorm.DB) error {
3232 3300
 
3233 3301
 	err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
@@ -3252,6 +3320,17 @@ func ModifyDrugAuToWarehouseOut(id int64, cha_count int64, tx *gorm.DB) error {
3252 3320
 	return err
3253 3321
 }
3254 3322
 
3323
+func ModifyGoodAuToWarehouseOut(id int64, cha_count int64, tx *gorm.DB) error {
3324
+
3325
+	err := tx.Model(&models.AutomaticReduceDetail{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
3326
+
3327
+	if err != nil {
3328
+		tx.Rollback()
3329
+		return err
3330
+	}
3331
+	return err
3332
+}
3333
+
3255 3334
 func DeleteDrugWarehouseOutInfoByNumber(id int64, tx *gorm.DB) error {
3256 3335
 
3257 3336
 	err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
@@ -3273,3 +3352,83 @@ func DeleteDrugWarehouseAutoByNumber(id int64, tx *gorm.DB) error {
3273 3352
 	}
3274 3353
 	return err
3275 3354
 }
3355
+
3356
+func DeleteGoodWarehouseAutoByNumberTwo(id int64, tx *gorm.DB) error {
3357
+
3358
+	err := tx.Model(&models.AutomaticReduceDetail{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
3359
+
3360
+	if err != nil {
3361
+		tx.Rollback()
3362
+		return err
3363
+	}
3364
+	return err
3365
+}
3366
+
3367
+func GetHistoryProject(patient_id int64, user_org_id int64, record_date int64, id int64, good_id int64, tx *gorm.DB) (models.HisPrescriptionProject, error) {
3368
+
3369
+	project := models.HisPrescriptionProject{}
3370
+	err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and id = ? and project_id = ? and status =1", patient_id, user_org_id, record_date, id, good_id).Find(&project).Error
3371
+
3372
+	if err != gorm.ErrRecordNotFound {
3373
+		if err != nil {
3374
+			tx.Rollback()
3375
+			return project, err
3376
+		}
3377
+	}
3378
+	return project, err
3379
+}
3380
+
3381
+func GetGoodWarehouseOutInfoByProjectIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
3382
+
3383
+	outInfo := models.WarehouseOutInfo{}
3384
+	err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and good_id = ? and status=1 and project_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
3385
+	if err != gorm.ErrRecordNotFound {
3386
+		if err != nil {
3387
+			tx.Rollback()
3388
+			return outInfo, err
3389
+		}
3390
+	}
3391
+	return outInfo, err
3392
+}
3393
+
3394
+func DeleteGoodWarehouseOutInfoByNumber(id int64, tx *gorm.DB) error {
3395
+
3396
+	err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
3397
+
3398
+	if err != nil {
3399
+		tx.Rollback()
3400
+		return err
3401
+	}
3402
+	return err
3403
+}
3404
+
3405
+func ModifyGoodWarehouseOutInfoByNumber(id int64, cha_count int64, tx *gorm.DB) error {
3406
+
3407
+	err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
3408
+
3409
+	err = tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("over_count", gorm.Expr("over_count + ?", cha_count)).Error
3410
+
3411
+	if err != nil {
3412
+		tx.Rollback()
3413
+		return err
3414
+	}
3415
+	return err
3416
+}
3417
+
3418
+func GetBasedrugById(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
3419
+
3420
+	lib := models.BaseDrugLib{}
3421
+
3422
+	err := XTReadDB().Where("id = ? and org_id =? and status=1 AND find_in_set('停用',drug_status) = 1", drug_id, user_org_id).Find(&lib).Error
3423
+
3424
+	return lib, err
3425
+}
3426
+
3427
+func GetBaseGoodById(good_id int64, user_org_id int64) (models.GoodInfo, error) {
3428
+
3429
+	info := models.GoodInfo{}
3430
+
3431
+	err := XTReadDB().Where("id = ? and org_id =? and status=1 AND find_in_set('停用',good_status) = 1", good_id, user_org_id).Find(&info).Error
3432
+
3433
+	return info, err
3434
+}

+ 4 - 0
service/manage_center_service.go 파일 보기

@@ -654,6 +654,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
654 654
 				AdviceId:                info.AdviceId,
655 655
 				StorehouseId:            storeHouseConfig.DrugStorehouseOut,
656 656
 				OverCount:               sum_count,
657
+				OperateTime:             time.Now().Unix(),
657 658
 			}
658 659
 			CreatedCancelStock(cancelStockInfo)
659 660
 			CreateDrugFlowOne(flow)
@@ -775,6 +776,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
775 776
 				AdviceId:                info.AdviceId,
776 777
 				StorehouseId:            houseConfig.DrugStorehouseOut,
777 778
 				OverCount:               sum_count,
779
+				OperateTime:             time.Now().Unix(),
778 780
 			}
779 781
 			CreatedCancelStock(cancelStockInfo)
780 782
 			CreateDrugFlowOne(flow)
@@ -885,6 +887,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
885 887
 				AdviceId:                info.AdviceId,
886 888
 				StorehouseId:            houseConfig.DrugStorehouseOut,
887 889
 				OverCount:               sum_count,
890
+				OperateTime:             time.Now().Unix(),
888 891
 			}
889 892
 			CreatedCancelStock(cancelStockInfo)
890 893
 			CreateDrugFlowOne(flow)
@@ -1015,6 +1018,7 @@ func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater i
1015 1018
 				ExpireDate:              item.ExpiryDate,
1016 1019
 				StorehouseId:            houseConfig.StorehouseOutInfo,
1017 1020
 				OverCount:               over_count,
1021
+				OperateTime:             time.Now().Unix(),
1018 1022
 			}
1019 1023
 			CreateStockFlowOne(flow)
1020 1024
 

+ 35 - 1
service/mobile_dialysis_service.go 파일 보기

@@ -1043,7 +1043,7 @@ func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64)
1043 1043
 	// cur_date := time.Now().Format("2006-01-02")
1044 1044
 	key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
1045 1045
 	monitor_record_last_str, _ := redis.Get(key).Result()
1046
-
1046
+	redis.Set(key, "", time.Second)
1047 1047
 	if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1048 1048
 		err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
1049 1049
 		if err != nil {
@@ -1191,6 +1191,20 @@ func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, m
1191 1191
 
1192 1192
 }
1193 1193
 
1194
+func MobileGetLastTimeAssessmentAfterDislysisTwo(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
1195
+	var record models.AssessmentAfterDislysis
1196
+	err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
1197
+	if err != nil {
1198
+		if err == gorm.ErrRecordNotFound {
1199
+			return nil, nil
1200
+		} else {
1201
+			return nil, err
1202
+		}
1203
+	}
1204
+	return &record, nil
1205
+
1206
+}
1207
+
1194 1208
 func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
1195 1209
 	dislysis := models.AssessmentAfterDislysis{}
1196 1210
 	err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&dislysis).Error
@@ -2252,6 +2266,12 @@ func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
2252 2266
 	return err
2253 2267
 }
2254 2268
 
2269
+func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
2270
+
2271
+	err := XTWriteDB().Model(&models.XtSchedule{}).Where("patient_id = ? and schedule_date = ? and status=1", patient_id, schedule_date).Updates(map[string]interface{}{"bed_id": bed_id, "schedule_type": schedule_type, "partition_id": zone_id}).Error
2272
+	return err
2273
+}
2274
+
2255 2275
 func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
2256 2276
 	tx := writeDb.Begin()
2257 2277
 	updateTime := time.Now().Unix()
@@ -8167,6 +8187,20 @@ func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecor
8167 8187
 	return record, err
8168 8188
 }
8169 8189
 
8190
+func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
8191
+
8192
+	record := models.MonitoringRecord{}
8193
+	err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
8194
+	return record, err
8195
+}
8196
+
8197
+func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
8198
+
8199
+	record := models.MonitoringRecord{}
8200
+	err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
8201
+	return record, err
8202
+}
8203
+
8170 8204
 func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
8171 8205
 
8172 8206
 	record := models.MonitoringRecord{}

+ 45 - 0
service/new_stock_service.go 파일 보기

@@ -139,6 +139,34 @@ func UpdateSumGood(orgid int64, storehouse_id int64, good_id int64, flush_count
139 139
 	return err
140 140
 }
141 141
 
142
+func ReduceSumOutCount(good_id int64, total_count int64, storehouse_id int64, user_org_id int64) error {
143
+	ut := XTWriteDB().Begin()
144
+
145
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", total_count)).Error
146
+
147
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count - ?", total_count)).Error
148
+	if err != nil {
149
+		ut.Rollback()
150
+		return err
151
+	}
152
+	ut.Commit()
153
+	return err
154
+}
155
+
156
+func ReduceSumInCount(good_id int64, total_count int64, storehouse_id int64, user_org_id int64) error {
157
+	ut := XTWriteDB().Begin()
158
+
159
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count + ?", total_count)).Error
160
+
161
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_act_out_count", gorm.Expr("stock_act_out_count + ?", total_count)).Error
162
+	if err != nil {
163
+		ut.Rollback()
164
+		return err
165
+	}
166
+	ut.Commit()
167
+	return err
168
+}
169
+
142 170
 func UpdateSumCount(user_org_id int64, storehouse_id int64, good_id int64, count int64) error {
143 171
 	ut := XTWriteDB().Begin()
144 172
 
@@ -595,3 +623,20 @@ func UpdateWarehosueOutInfo(id int64, sys_record_time int64) (models.WarehouseOu
595 623
 
596 624
 	return info, err
597 625
 }
626
+
627
+func AddGoodNewCancelSumCountOne(storehouse_id int64, good_id int64, user_org_id int64, cancel_count int64, tx *gorm.DB) error {
628
+
629
+	err = tx.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_cancel_count", gorm.Expr("stock_cancel_count + ?", cancel_count)).Error
630
+	if err != nil {
631
+		tx.Rollback()
632
+		return err
633
+	}
634
+	return err
635
+}
636
+
637
+func GetDrugNewInventoryList(org_id int64) (drug []*models.BaseDrugLibTwentyOne, err error) {
638
+
639
+	err = XTReadDB().Where("org_id = ? and status =1", org_id).Find(&drug).Error
640
+
641
+	return drug, err
642
+}

+ 26 - 7
service/new_warehouse_service.go 파일 보기

@@ -161,6 +161,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
161 161
 				OverCount:               sum_count,
162 162
 				BuyPrice:                warehouse.Price,
163 163
 				RegisterNumber:          warehouse.RegisterNumber,
164
+				OperateTime:             time.Now().Unix(),
164 165
 			}
165 166
 			if orgID == 9671 || orgID == 10265 {
166 167
 				goodsInfo, _ := FindeGoodInfo(orgID, goods.GoodId)
@@ -276,6 +277,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
276 277
 				ProjectId:               goods.ProjectId,
277 278
 				OverCount:               sum_count,
278 279
 				RegisterNumber:          warehouse.RegisterNumber,
280
+				OperateTime:             time.Now().Unix(),
279 281
 			}
280 282
 			if orgID == 9671 || orgID == 10265 {
281 283
 				goodsInfo, _ := FindeGoodInfo(orgID, goods.GoodId)
@@ -421,6 +423,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
421 423
 				OverCount:               sum_count,
422 424
 				BuyPrice:                warehouse.Price,
423 425
 				RegisterNumber:          warehouse.RegisterNumber,
426
+				OperateTime:             time.Now().Unix(),
424 427
 			}
425 428
 			if orgID == 9671 || orgID == 10265 {
426 429
 				goodsInfo, _ := FindeGoodInfo(orgID, goods.GoodId)
@@ -532,6 +535,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
532 535
 				ProjectId:               goods.ProjectId,
533 536
 				OverCount:               sum_count,
534 537
 				RegisterNumber:          warehouse.RegisterNumber,
538
+				OperateTime:             time.Now().Unix(),
535 539
 			}
536 540
 			if orgID == 9671 || orgID == 10265 {
537 541
 				goodsInfo, _ := FindeGoodInfo(orgID, goods.GoodId)
@@ -940,6 +944,7 @@ func BloodDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *
940 944
 				OverCount:               sum_count,
941 945
 				AdviceId:                advice.ID,
942 946
 				LastPrice:               warehouse.Price,
947
+				OperateTime:             time.Now().Unix(),
943 948
 			}
944 949
 
945 950
 			CreateDrugFlowOne(drugflow)
@@ -1044,6 +1049,7 @@ func BloodDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *
1044 1049
 				AdviceId:                advice.ID,
1045 1050
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1046 1051
 				LastPrice:               warehouse.Price,
1052
+				OperateTime:             time.Now().Unix(),
1047 1053
 			}
1048 1054
 			CreateDrugFlowOne(flow)
1049 1055
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
@@ -1238,6 +1244,7 @@ func BloodDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *
1238 1244
 				WarehouseOutDetailId:    lastDrugOutInfo.ID,
1239 1245
 				OverCount:               sum_count,
1240 1246
 				AdviceId:                advice.ID,
1247
+				OperateTime:             time.Now().Unix(),
1241 1248
 			}
1242 1249
 
1243 1250
 			CreateDrugFlowOne(drugflow)
@@ -1338,6 +1345,7 @@ func BloodDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *
1338 1345
 				MinUnit:                 "",
1339 1346
 				AdviceId:                advice.ID,
1340 1347
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1348
+				OperateTime:             time.Now().Unix(),
1341 1349
 			}
1342 1350
 			CreateDrugFlowOne(flow)
1343 1351
 			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
@@ -1487,9 +1495,6 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1487 1495
 
1488 1496
 	}
1489 1497
 
1490
-	fmt.Println("药品名称", drup.DrugName)
1491
-	fmt.Println("库存数量我哦我我", stock_number)
1492
-	fmt.Println("出库数量", deliver_number)
1493 1498
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1494 1499
 	if stock_number >= deliver_number {
1495 1500
 
@@ -1783,6 +1788,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1783 1788
 					OverCount:               sum_count,
1784 1789
 					AdviceId:                advice.ID,
1785 1790
 					LastPrice:               warehouse.Price,
1791
+					OperateTime:             time.Now().Unix(),
1786 1792
 				}
1787 1793
 
1788 1794
 				errThreeTy := CreateDrugFlowOne(drugflow)
@@ -1958,6 +1964,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1958 1964
 				StorehouseId:            storeConfig.DrugStorehouseOut,
1959 1965
 				LastPrice:               warehouse.Price,
1960 1966
 				OverCount:               sum_count,
1967
+				OperateTime:             time.Now().Unix(),
1961 1968
 			}
1962 1969
 			errCodeflow := CreateDrugFlowOne(flow)
1963 1970
 			if errCodeflow != nil {
@@ -2304,6 +2311,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
2304 2311
 				AdviceId:                advice.ID,
2305 2312
 				LastPrice:               warehouse.Price,
2306 2313
 				SystemTime:              advice.AdviceDate,
2314
+				OperateTime:             time.Now().Unix(),
2307 2315
 			}
2308 2316
 
2309 2317
 			CreateDrugFlowOne(drugflow)
@@ -2440,6 +2448,7 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
2440 2448
 				StorehouseId:            storeConfig.DrugStorehouseOut,
2441 2449
 				LastPrice:               warehouse.Price,
2442 2450
 				OverCount:               sum_count,
2451
+				OperateTime:             time.Now().Unix(),
2443 2452
 			}
2444 2453
 			errCodeFlows := CreateDrugFlowOne(flow)
2445 2454
 			if errCodeFlows != nil {
@@ -4601,10 +4610,6 @@ func HisStoryBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, war
4601 4610
 			warehouse.StockMinNumber = 0
4602 4611
 		}
4603 4612
 
4604
-		//fmt.Println("warehouse.StockMaxNumber-------------------", warehouse.StockMaxNumber)
4605
-		//
4606
-		//fmt.Println("warehouse.StockMinNumber-------------------", warehouse.StockMinNumber)
4607
-
4608 4613
 		//扣减库存数据
4609 4614
 		UpDateNewDrugWarehouseInfoByStock(&warehouse, tx)
4610 4615
 
@@ -4692,6 +4697,7 @@ func HisStoryBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, war
4692 4697
 			OverCount:               sum_count,
4693 4698
 			AdviceId:                advice.ID,
4694 4699
 			LastPrice:               warehouse.Price,
4700
+			OperateTime:             time.Now().Unix(),
4695 4701
 		}
4696 4702
 
4697 4703
 		CreateNewDrugFlowOne(drugflow, tx)
@@ -4879,6 +4885,7 @@ func HisStoryBloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, war
4879 4885
 			AdviceId:                advice.ID,
4880 4886
 			LastPrice:               warehouse.Price,
4881 4887
 			SystemTime:              advice.AdviceDate,
4888
+			OperateTime:             time.Now().Unix(),
4882 4889
 		}
4883 4890
 
4884 4891
 		CreateNewDrugFlowOne(drugflow, tx)
@@ -5042,6 +5049,7 @@ func NewHisDrugCancelInfo(orgID int64, creater int64, advice *models.HisDoctorAd
5042 5049
 			StorehouseId:            storeConfig.DrugStorehouseOut,
5043 5050
 			LastPrice:               drugOutInfo.Price,
5044 5051
 			OverCount:               sum_count,
5052
+			OperateTime:             time.Now().Unix(),
5045 5053
 		}
5046 5054
 		CreateNewDrugFlowOne(flow, tx)
5047 5055
 
@@ -5167,6 +5175,7 @@ func NewHisDrugCancelInfo(orgID int64, creater int64, advice *models.HisDoctorAd
5167 5175
 			StorehouseId:            storeConfig.DrugStorehouseOut,
5168 5176
 			LastPrice:               drugOutInfo.Price,
5169 5177
 			OverCount:               sum_count,
5178
+			OperateTime:             time.Now().Unix(),
5170 5179
 		}
5171 5180
 		CreateNewDrugFlowOne(flow, tx)
5172 5181
 
@@ -5231,3 +5240,13 @@ func NewHisDrugAutoCancelInfo(orgID int64, creater int64, advice *models.HisDoct
5231 5240
 	}
5232 5241
 	return err
5233 5242
 }
5243
+
5244
+func ReduceNewGoodCountTwo(good_id int64, org_id int64, storehouse_id int64, out_count int64, tx *gorm.DB) error {
5245
+
5246
+	err := tx.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id = ? and good_id = ?", storehouse_id, org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", out_count)).Error
5247
+	if err != nil {
5248
+		tx.Rollback()
5249
+		return err
5250
+	}
5251
+	return err
5252
+}

+ 1 - 1
service/patient_service.go 파일 보기

@@ -597,7 +597,7 @@ func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients
597 597
 	defer redis.Close()
598 598
 	key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
599 599
 	patient_info_str, _ := redis.Get(key).Result()
600
-
600
+	redis.Set(key, "", time.Second)
601 601
 	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
602 602
 		err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
603 603
 		if err != nil {

+ 41 - 0
service/pharmacy_service.go 파일 보기

@@ -2305,3 +2305,44 @@ func GetHisPatientAdviceList(user_org_id int64, patient_id int64, start_time int
2305 2305
 	err = XTReadDB().Model(&models.HisDoctorAdvice{}).Where("patient_id=? and advice_date=? and advice_date>=? and advice_date<=? and status=1 and user_org_id = ? and is_medicine =1", patient_id, start_time, end_time, user_org_id).Find(&list).Error
2306 2306
 	return list, err
2307 2307
 }
2308
+
2309
+func GetGoodInventoryList(keyword string, org_id int64) (good []*models.GoodInfoEight, err error) {
2310
+
2311
+	keyword = "%" + keyword + "%"
2312
+
2313
+	db := XTReadDB().Where("status=1")
2314
+
2315
+	if len(keyword) > 0 {
2316
+		db = db.Where("good_name like ? or specification_name like ?", keyword, keyword)
2317
+	}
2318
+	if org_id > 0 {
2319
+		db = db.Where("org_id = ?", org_id)
2320
+	}
2321
+
2322
+	err = db.Order("id desc").Find(&good).Error
2323
+
2324
+	return good, err
2325
+}
2326
+
2327
+func GetGoodInventoryByGoodId(id int64) (info []*models.XtWarehouseInfoEight, err error) {
2328
+
2329
+	err = XTReadDB().Where("good_id = ? and status=1 and is_check=1", id).Order("id desc").Find(&info).Error
2330
+
2331
+	return info, err
2332
+}
2333
+
2334
+func GetInventoryWarehouseInfo(id int64) (models.XtWarehouseInfoEight, error) {
2335
+
2336
+	infoEight := models.XtWarehouseInfoEight{}
2337
+	err := XTReadDB().Where("id = ? and status=1", id).Find(&id).Error
2338
+
2339
+	return infoEight, err
2340
+}
2341
+
2342
+func UpdateWarehouseInfoById(last_stock_count int64, id int64) (models.WarehousingInfo, error) {
2343
+
2344
+	info := models.WarehousingInfo{}
2345
+
2346
+	err := XTWriteDB().Model(&info).Where("id = ? and status =1", id).Updates(map[string]interface{}{"stock_count": last_stock_count}).Error
2347
+	return info, err
2348
+}

+ 11 - 0
service/schedule_service.go 파일 보기

@@ -234,6 +234,11 @@ func GetDayScheduleByBedid(orgID, start, bed_id int64, schedule_type int64) (sch
234 234
 	err = readDb.Model(&models.Schedule{}).Where("user_org_id=?  and schedule_date=? and bed_id=? and status=1 AND schedule_type = ?", orgID, start, bed_id, schedule_type).Preload("DialysisOrder", "status = 1").First(&schedule).Error
235 235
 	return
236 236
 }
237
+
238
+func GetDayScheduleByOrder(orgID, start, bed_id int64, schedule_type int64) (schedule models.DialysisOrder, err error) {
239
+	err = readDb.Model(&models.DialysisOrder{}).Where("user_org_id=?  and dialysis_date=? and bed_id=? and status=1 AND schedual_type = ?", orgID, start, bed_id, schedule_type).First(&schedule).Error
240
+	return
241
+}
237 242
 func GetSourceSch(orgId int64, patient_id int64, record_date int64) (schedule models.Schedule, err error) {
238 243
 	err = readDb.Model(&models.Schedule{}).Where("user_org_id=?  and schedule_date=? and patient_id =? and status=1", orgId, record_date, patient_id).First(&schedule).Error
239 244
 	return
@@ -1916,3 +1921,9 @@ func GetPatientGoodCountToday(patient_id int64, schedule_date int64, user_org_id
1916 1921
 	err = XTReadDB().Where("patient_id =? and sys_record_time=? and org_id = ? and status=1", patient_id, schedule_date, user_org_id).Find(&list).Error
1917 1922
 	return list, err
1918 1923
 }
1924
+
1925
+func GetPatientDrugCountToday(patient_id int64, schedule_date int64, user_org_id int64) (list []*models.DrugWarehouseOutInfo, err error) {
1926
+
1927
+	err = XTReadDB().Where("patient_id =? and sys_record_time=? and org_id = ? and status=1", patient_id, schedule_date, user_org_id).Find(&list).Error
1928
+	return list, err
1929
+}

+ 1 - 1
service/smart_sch.go 파일 보기

@@ -11,7 +11,7 @@ func GetSmartSchPatientByKeyWord(orgID int64, keywords string) (patient []*model
11 11
 	db := readDb.Model(&models.SmartSchPatient{}).Where("user_org_id=? and status=1", orgID)
12 12
 	if len(keywords) > 0 {
13 13
 		likekey := "%" + keywords + "%"
14
-		err = db.Where("name LIKE ? OR dialysis_no LIKE ? ", likekey, likekey).Find(&patient).Error
14
+		err = db.Where("name LIKE ? OR dialysis_no LIKE ? and lapseto =1", likekey, likekey).Find(&patient).Error
15 15
 	} else {
16 16
 		err = db.Find(&patient).Error
17 17
 	}

+ 10 - 0
service/stock_service.go 파일 보기

@@ -9195,3 +9195,13 @@ func UpdateHisPrescriptionProjectList(id int64, price float64) (models.HisPrescr
9195 9195
 	err := XTWriteDB().Model(&templateL).Where("id =? and status=1", id).Updates(map[string]interface{}{"price": price}).Error
9196 9196
 	return templateL, err
9197 9197
 }
9198
+
9199
+func ModifyNewGoodWarehouseInfoStockMinNumber(count int64, goodid int64, orgid int64, id int64, tx *gorm.DB) error {
9200
+
9201
+	err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and org_id = ? and good_id = ? and status = 1", id, orgid, goodid).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
9202
+	if err != nil {
9203
+		tx.Rollback()
9204
+		return err
9205
+	}
9206
+	return err
9207
+}

+ 579 - 10
service/warhouse_service.go 파일 보기

@@ -364,6 +364,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
364 364
 			LastPrice:               warehouse.Price,
365 365
 			OverCount:               sum_count,
366 366
 			AdviceId:                advice.ID,
367
+			OperateTime:             time.Now().Unix(),
367 368
 		}
368 369
 
369 370
 		CreateDrugFlowOne(drugflow)
@@ -541,6 +542,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
541 542
 			LastPrice:               warehouse.Price,
542 543
 			OverCount:               sum_count,
543 544
 			AdviceId:                advice.ID,
545
+			OperateTime:             time.Now().Unix(),
544 546
 		}
545 547
 
546 548
 		CreateDrugFlowOne(drugflow)
@@ -1351,8 +1353,6 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1351 1353
 
1352 1354
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1353 1355
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
1354
-	fmt.Println("len233333333333333w", len(goods_yc))
1355
-	fmt.Println("需要出库的数据", len(goods))
1356 1356
 	if len(goods) > 0 {
1357 1357
 		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1358 1358
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
@@ -7057,8 +7057,6 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7057 7057
 
7058 7058
 	stock_number = warehouse.StockCount
7059 7059
 
7060
-	fmt.Println("sotck_number233223322o", stock_number)
7061
-	fmt.Println("deliver_number", deliver_number)
7062 7060
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
7063 7061
 	if stock_number >= deliver_number {
7064 7062
 		maxNumber = goods.Count
@@ -7174,9 +7172,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7174 7172
 		lastOut, _ := FindWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId)
7175 7173
 
7176 7174
 		//如果本次出库数据大于历史出库数据 新增1条流水
7177
-		fmt.Println("本次出库数据", count)
7178
-		fmt.Println("历史出库数据", out_count)
7179
-		fmt.Println("退库数据", out_count_one)
7175
+
7180 7176
 		if count > (out_count - out_count_one) {
7181 7177
 
7182 7178
 			stockFlow := models.VmStockFlow{
@@ -7219,6 +7215,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7219 7215
 				OverCount:               sum_count,
7220 7216
 				RegisterNumber:          warehouse.RegisterNumber,
7221 7217
 				ProjectId:               goods.ProjectId,
7218
+				OperateTime:             time.Now().Unix(),
7222 7219
 			}
7223 7220
 			//创建出库流水
7224 7221
 			errflow := CreateStockFlowOne(stockFlow)
@@ -7361,6 +7358,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7361 7358
 				ProjectId:               goods.ProjectId,
7362 7359
 				OverCount:               sum_count,
7363 7360
 				RegisterNumber:          warehouse.RegisterNumber,
7361
+				OperateTime:             time.Now().Unix(),
7364 7362
 			}
7365 7363
 			if orgID == 9671 || orgID == 10265 {
7366 7364
 				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
@@ -7515,9 +7513,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7515 7513
 		for _, item := range flowGoodTwo {
7516 7514
 			out_count_one += item.Count
7517 7515
 		}
7518
-		fmt.Println("count----------------", count)
7519
-		fmt.Println("out_count----------", out_count)
7520
-		fmt.Println("out_count_one--------", out_count_one)
7516
+
7521 7517
 		//如果出库数量 大于 历史出库数据 新增1条流水
7522 7518
 		if count > out_count-out_count_one {
7523 7519
 			stockFlow := models.VmStockFlow{
@@ -7560,6 +7556,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7560 7556
 				OverCount:               sum_count,
7561 7557
 				RegisterNumber:          warehouse.RegisterNumber,
7562 7558
 				ProjectId:               goods.ProjectId,
7559
+				OperateTime:             time.Now().Unix(),
7563 7560
 			}
7564 7561
 			//创建出库流水
7565 7562
 			errflow := CreateStockFlowOne(stockFlow)
@@ -7702,6 +7699,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
7702 7699
 				ProjectId:               goods.ProjectId,
7703 7700
 				OverCount:               sum_count,
7704 7701
 				RegisterNumber:          warehouse.RegisterNumber,
7702
+				OperateTime:             time.Now().Unix(),
7705 7703
 			}
7706 7704
 			if orgID == 9671 || orgID == 10265 {
7707 7705
 				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
@@ -8080,6 +8078,7 @@ func ConsumableNewPrescriptionDelivery(orgID int64, patient_id int64, record_tim
8080 8078
 				OverCount:               sum_count,
8081 8079
 				RegisterNumber:          warehouse.RegisterNumber,
8082 8080
 				ProjectId:               goods.ProjectId,
8081
+				OperateTime:             time.Now().Unix(),
8083 8082
 			}
8084 8083
 			//创建出库流水
8085 8084
 			errflow := CreateNewStockFlowOne(stockFlow, tx)
@@ -8222,6 +8221,7 @@ func ConsumableNewPrescriptionDelivery(orgID int64, patient_id int64, record_tim
8222 8221
 				ProjectId:               goods.ProjectId,
8223 8222
 				OverCount:               sum_count,
8224 8223
 				RegisterNumber:          warehouse.RegisterNumber,
8224
+				OperateTime:             time.Now().Unix(),
8225 8225
 			}
8226 8226
 			if orgID == 9671 || orgID == 10265 {
8227 8227
 				goodsInfo, _ := FindeNewGoodInfo(orgID, goods.ProjectId, tx)
@@ -8406,6 +8406,7 @@ func ConsumableNewPrescriptionDelivery(orgID int64, patient_id int64, record_tim
8406 8406
 				OverCount:               sum_count,
8407 8407
 				RegisterNumber:          warehouse.RegisterNumber,
8408 8408
 				ProjectId:               goods.ProjectId,
8409
+				OperateTime:             time.Now().Unix(),
8409 8410
 			}
8410 8411
 			//创建出库流水
8411 8412
 			errflow := CreateNewStockFlowOne(stockFlow, tx)
@@ -8548,6 +8549,7 @@ func ConsumableNewPrescriptionDelivery(orgID int64, patient_id int64, record_tim
8548 8549
 				ProjectId:               goods.ProjectId,
8549 8550
 				OverCount:               sum_count,
8550 8551
 				RegisterNumber:          warehouse.RegisterNumber,
8552
+				OperateTime:             time.Now().Unix(),
8551 8553
 			}
8552 8554
 			if orgID == 9671 || orgID == 10265 {
8553 8555
 				goodsInfo, _ := FindeNewGoodInfo(orgID, goods.ProjectId, tx)
@@ -8600,3 +8602,570 @@ func ConsumableNewPrescriptionDelivery(orgID int64, patient_id int64, record_tim
8600 8602
 
8601 8603
 	return nil
8602 8604
 }
8605
+
8606
+// 保存处方出库
8607
+func ConsumableNewHisPrescriptionDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, creator int64, tx *gorm.DB) (err error) {
8608
+
8609
+	fmt.Println("出库时间-------------------------------------------------", record_time)
8610
+	var deliver_number int64 = 0
8611
+	var stock_number int64 = 0
8612
+	var maxNumber int64 = 0
8613
+
8614
+	deliver_number = goods.Count
8615
+
8616
+	// 根据先进先出原则,查询最先入库的批次,进行出库
8617
+
8618
+	// 如果没有对应的库存,则报错
8619
+	warehouse, _ := FindNewFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId, tx)
8620
+
8621
+	stock_number = warehouse.StockCount
8622
+
8623
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
8624
+	if stock_number >= deliver_number {
8625
+		maxNumber = goods.Count
8626
+		warehouse.StockCount = warehouse.StockCount - maxNumber
8627
+		warehouse.Mtime = time.Now().Unix()
8628
+		//扣减库存
8629
+		UpDateNewWarehouseInfoByStock(&warehouse, tx)
8630
+
8631
+		//查询剩余库存
8632
+		goodList, _ := GetNewAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId, tx)
8633
+		var sum_count int64
8634
+		for _, item := range goodList {
8635
+			sum_count += item.StockCount
8636
+		}
8637
+
8638
+		//创建出库单
8639
+		OutInfo := &models.WarehouseOutInfo{
8640
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
8641
+			WarehouseOutId:          warehouseOut.ID,
8642
+			WarehouseInfotId:        warehouse.ID,
8643
+			Status:                  1,
8644
+			Ctime:                   time.Now().Unix(),
8645
+			Remark:                  warehouse.Remark,
8646
+			OrgId:                   orgID,
8647
+			Type:                    1,
8648
+			Manufacturer:            warehouse.Manufacturer,
8649
+			Dealer:                  warehouse.Dealer,
8650
+			IsSys:                   1,
8651
+			SysRecordTime:           record_time,
8652
+			GoodTypeId:              goods.GoodTypeId,
8653
+			GoodId:                  goods.GoodId,
8654
+			PatientId:               patient_id,
8655
+			Number:                  warehouse.Number,
8656
+			LicenseNumber:           warehouse.LicenseNumber,
8657
+			Price:                   warehouse.PackingPrice,
8658
+			ExpiryDate:              warehouse.ExpiryDate,
8659
+			ProductDate:             warehouse.ProductDate,
8660
+			ProjectId:               goods.ProjectId,
8661
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
8662
+			StorehouseId:            goods.StorehouseId,
8663
+			IsCheck:                 1,
8664
+			OverCount:               sum_count,
8665
+			RegisterNumber:          warehouse.RegisterNumber,
8666
+			Count:                   goods.Count,
8667
+		}
8668
+
8669
+		AddNewSigleWarehouseOutInfo(OutInfo, tx)
8670
+
8671
+		stockFlow := models.VmStockFlow{
8672
+			WarehousingId:           warehouse.ID,
8673
+			GoodId:                  goods.GoodId,
8674
+			Number:                  warehouse.Number,
8675
+			LicenseNumber:           warehouse.LicenseNumber,
8676
+			Count:                   goods.Count,
8677
+			UserOrgId:               orgID,
8678
+			PatientId:               goods.PatientId,
8679
+			SystemTime:              record_time,
8680
+			ConsumableType:          3,
8681
+			IsSys:                   1,
8682
+			WarehousingOrder:        warehouse.WarehousingOrder,
8683
+			WarehouseOutId:          warehouseOut.ID,
8684
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
8685
+			IsEdit:                  1,
8686
+			CancelStockId:           0,
8687
+			CancelOrderNumber:       "",
8688
+			Manufacturer:            warehouse.Manufacturer,
8689
+			Dealer:                  warehouse.Dealer,
8690
+			Creator:                 creator,
8691
+			UpdateCreator:           0,
8692
+			Status:                  1,
8693
+			Ctime:                   time.Now().Unix(),
8694
+			Mtime:                   0,
8695
+			Price:                   warehouse.PackingPrice, //零售价
8696
+			WarehousingDetailId:     warehouse.ID,
8697
+			WarehouseOutDetailId:    goods.ID,
8698
+			CancelOutDetailId:       0,
8699
+			ProductDate:             warehouse.ProductDate,
8700
+			ExpireDate:              warehouse.ExpiryDate,
8701
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
8702
+			StorehouseId:            warehouse.StorehouseId,
8703
+			AdminUserId:             creator,
8704
+			BuyPrice:                warehouse.Price, //进货价
8705
+			StockCount:              "",
8706
+			BatchNumberCount:        warehouse.StockCount - goods.Count,
8707
+			IsCheck:                 1,
8708
+			OverCount:               sum_count,
8709
+			RegisterNumber:          warehouse.RegisterNumber,
8710
+			ProjectId:               goods.ProjectId,
8711
+			OperateTime:             time.Now().Unix(),
8712
+		}
8713
+
8714
+		//插入流水
8715
+		CreateNewStockFlowOne(stockFlow, tx)
8716
+
8717
+		//更新出库数量
8718
+		ModifyNewGoodSumCount(goods.StorehouseId, stockFlow.Count, orgID, goods.GoodId, tx)
8719
+
8720
+		goodObj, _ := GetNewGoodInformationByGoodIdThirty(goods.GoodId, tx)
8721
+
8722
+		autoMatic := &models.AutomaticReduceDetail{
8723
+			Count:        goods.Count,
8724
+			GoodTypeId:   goodObj.GoodTypeId,
8725
+			GoodId:       goods.GoodId,
8726
+			PatientId:    goods.PatientId,
8727
+			RecordTime:   goods.RecordDate,
8728
+			OrgId:        orgID,
8729
+			Ctime:        time.Now().Unix(),
8730
+			Status:       1,
8731
+			StorehouseId: goods.StorehouseId,
8732
+			ProjectId:    goods.ProjectId,
8733
+		}
8734
+
8735
+		CreatedDialysisPrepare(autoMatic, tx)
8736
+
8737
+		return nil
8738
+	} else {
8739
+		// 出库完成后,要将该批次库存清零
8740
+		warehouse.StockCount = 0
8741
+		warehouse.Mtime = time.Now().Unix()
8742
+
8743
+		UpDateNewWarehouseInfoByStock(&warehouse, tx)
8744
+
8745
+		//查询剩余库存
8746
+		goodList, _ := GetNewAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId, tx)
8747
+		var sum_count int64
8748
+		for _, item := range goodList {
8749
+			sum_count += item.StockCount
8750
+		}
8751
+
8752
+		OutInfo := &models.WarehouseOutInfo{
8753
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
8754
+			WarehouseOutId:          warehouseOut.ID,
8755
+			WarehouseInfotId:        warehouse.ID,
8756
+			Status:                  1,
8757
+			Ctime:                   time.Now().Unix(),
8758
+			Remark:                  warehouse.Remark,
8759
+			OrgId:                   orgID,
8760
+			Type:                    1,
8761
+			Manufacturer:            warehouse.Manufacturer,
8762
+			Dealer:                  warehouse.Dealer,
8763
+			IsSys:                   1,
8764
+			SysRecordTime:           record_time,
8765
+			GoodTypeId:              goods.GoodTypeId,
8766
+			GoodId:                  goods.GoodId,
8767
+			PatientId:               patient_id,
8768
+			Number:                  warehouse.Number,
8769
+			LicenseNumber:           warehouse.LicenseNumber,
8770
+			Price:                   warehouse.PackingPrice,
8771
+			ExpiryDate:              warehouse.ExpiryDate,
8772
+			ProductDate:             warehouse.ProductDate,
8773
+			ProjectId:               goods.ProjectId,
8774
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
8775
+			StorehouseId:            goods.StorehouseId,
8776
+			IsCheck:                 1,
8777
+			OverCount:               sum_count,
8778
+			RegisterNumber:          warehouse.RegisterNumber,
8779
+		}
8780
+		OutInfo.Count = stock_number
8781
+
8782
+		AddNewSigleWarehouseOutInfo(OutInfo, tx)
8783
+
8784
+		//如果出库数量 大于 历史出库数据 新增1条流水
8785
+		stockFlow := models.VmStockFlow{
8786
+			WarehousingId:           warehouse.ID,
8787
+			GoodId:                  goods.GoodId,
8788
+			Number:                  warehouse.Number,
8789
+			LicenseNumber:           warehouse.LicenseNumber,
8790
+			Count:                   stock_number,
8791
+			UserOrgId:               orgID,
8792
+			PatientId:               goods.PatientId,
8793
+			SystemTime:              record_time,
8794
+			ConsumableType:          3,
8795
+			IsSys:                   1,
8796
+			WarehousingOrder:        warehouse.WarehousingOrder,
8797
+			WarehouseOutId:          warehouseOut.ID,
8798
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
8799
+			IsEdit:                  1,
8800
+			CancelStockId:           0,
8801
+			CancelOrderNumber:       "",
8802
+			Manufacturer:            warehouse.Manufacturer,
8803
+			Dealer:                  warehouse.Dealer,
8804
+			Creator:                 creator,
8805
+			UpdateCreator:           0,
8806
+			Status:                  1,
8807
+			Ctime:                   time.Now().Unix(),
8808
+			Mtime:                   0,
8809
+			Price:                   warehouse.PackingPrice, //零售价
8810
+			WarehousingDetailId:     warehouse.ID,
8811
+			WarehouseOutDetailId:    goods.ID,
8812
+			CancelOutDetailId:       0,
8813
+			ProductDate:             warehouse.ProductDate,
8814
+			ExpireDate:              warehouse.ExpiryDate,
8815
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
8816
+			StorehouseId:            warehouse.StorehouseId,
8817
+			AdminUserId:             creator,
8818
+			BuyPrice:                warehouse.Price, //进货价
8819
+			StockCount:              "",
8820
+			BatchNumberCount:        0,
8821
+			IsCheck:                 1,
8822
+			OverCount:               sum_count,
8823
+			RegisterNumber:          warehouse.RegisterNumber,
8824
+			ProjectId:               goods.ProjectId,
8825
+			OperateTime:             time.Now().Unix(),
8826
+		}
8827
+		//创建出库流水
8828
+		CreateNewStockFlowOne(stockFlow, tx)
8829
+
8830
+		ModifyNewGoodSumCount(goods.StorehouseId, stock_number, orgID, goods.GoodId, tx)
8831
+
8832
+		UpdateNewGoodWarehouseOutById(goods.ID, warehouse.ID, orgID, sum_count, tx)
8833
+
8834
+	}
8835
+	dialyPrepareOne := &models.DialysisBeforePrepare{
8836
+		GoodTypeId:   goods.GoodTypeId,
8837
+		GoodId:       goods.GoodId,
8838
+		PatientId:    goods.PatientId,
8839
+		RecordDate:   goods.RecordDate,
8840
+		UserOrgId:    orgID,
8841
+		Count:        goods.Count,
8842
+		Ctime:        time.Now().Unix(),
8843
+		Creater:      creator,
8844
+		Status:       1,
8845
+		StorehouseId: goods.StorehouseId,
8846
+		ProjectId:    goods.ID,
8847
+	}
8848
+
8849
+	autoMatic := &models.AutomaticReduceDetail{
8850
+		Count:        stock_number,
8851
+		GoodTypeId:   goods.GoodTypeId,
8852
+		GoodId:       goods.GoodId,
8853
+		PatientId:    goods.PatientId,
8854
+		RecordTime:   goods.RecordDate,
8855
+		OrgId:        orgID,
8856
+		Ctime:        time.Now().Unix(),
8857
+		Status:       1,
8858
+		StorehouseId: goods.StorehouseId,
8859
+		ProjectId:    goods.ProjectId,
8860
+	}
8861
+	CreatedDialysisPrepare(autoMatic, tx)
8862
+
8863
+	goods.Count = deliver_number - stock_number
8864
+	ConsumableNewHisPrescriptionDelivery(orgID, patient_id, record_time, dialyPrepareOne, warehouseOut, creator, tx)
8865
+
8866
+	return nil
8867
+}
8868
+
8869
+func CreatedDialysisPrepare(prepare *models.AutomaticReduceDetail, tx *gorm.DB) error {
8870
+
8871
+	err := tx.Create(&prepare).Error
8872
+
8873
+	if err != nil {
8874
+		tx.Rollback()
8875
+		return err
8876
+	}
8877
+	return err
8878
+}
8879
+
8880
+func NewHisGoodCancelInfo(orgID int64, creater int64, project *models.HisPrescriptionProject, cha_count int64, good models.GoodInformationThirty, tx *gorm.DB) (err error) {
8881
+
8882
+	storeConfig, _ := GetNewAllStoreHouseConfig(orgID, tx)
8883
+
8884
+	//查找患者最后一条的退库数据是否满足要求
8885
+	var out_count int64
8886
+	GoodOutInfo, _ := GetGoodWarehouseOutInfoByProjectIdTwo(project.PatientId, project.UserOrgId, project.RecordDate, project.ProjectId, project.ID, tx)
8887
+
8888
+	out_count = GoodOutInfo.Count
8889
+	//如果最后1条出库数量大于退库数量,则直接退库,满足退库要求
8890
+	fmt.Println("out_count---------------------------------------", out_count)
8891
+	fmt.Println("cha_count++++++++++++++++++++++++++++++++++++++=", cha_count)
8892
+	if out_count >= cha_count {
8893
+		//退库 退回 cha_count 的数量
8894
+		ModifyNewGoodWarehouseInfoStockMinNumber(cha_count, GoodOutInfo.GoodId, GoodOutInfo.OrgId, GoodOutInfo.WarehouseInfotId, tx)
8895
+
8896
+		if out_count == cha_count {
8897
+			//删除该出库单
8898
+			DeleteGoodWarehouseOutInfoByNumber(GoodOutInfo.ID, tx)
8899
+		}
8900
+
8901
+		//减去出库单里面的数量
8902
+		ModifyGoodWarehouseOutInfoByNumber(GoodOutInfo.ID, cha_count, tx)
8903
+
8904
+		//创建退库单
8905
+		goodList, _ := GetNewAllGoodSumCount(project.ProjectId, orgID, storeConfig.StorehouseOutInfo, tx)
8906
+		var sum_count int64
8907
+		for _, item := range goodList {
8908
+			sum_count += item.StockCount
8909
+		}
8910
+
8911
+		operation_time := time.Now().Unix()
8912
+
8913
+		//创建退库单
8914
+		timeStr := time.Now().Format("2006-01-02")
8915
+		timeArr := strings.Split(timeStr, "-")
8916
+		total, _ := FindNewAllCancelStockTotal(orgID, tx)
8917
+		total = total + 1
8918
+		orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
8919
+
8920
+		cancelStock := models.CancelStock{
8921
+			OrderNumber:  orderNumber,
8922
+			OperaTime:    operation_time,
8923
+			OrgId:        orgID,
8924
+			Creater:      creater,
8925
+			Ctime:        time.Now().Unix(),
8926
+			Status:       1,
8927
+			ReturnTime:   project.RecordDate,
8928
+			Type:         1,
8929
+			StorehouseId: storeConfig.StorehouseOutInfo,
8930
+			IsCheck:      1,
8931
+		}
8932
+		_, msgerrkonde := GetNewCancelStockDetailByOrderNumberOne(project.RecordDate, orgID, tx)
8933
+		if msgerrkonde == gorm.ErrRecordNotFound {
8934
+			AddNewSigleCancelStock(&cancelStock, tx)
8935
+		}
8936
+
8937
+		manufactureName, _ := GetNewManufactureById(GoodOutInfo.Manufacturer, tx)
8938
+		dealer, _ := GetNewDealerById(GoodOutInfo.Dealer, tx)
8939
+
8940
+		cancelInfo, _ := GetNewLastCancelStockById(orgID, tx)
8941
+
8942
+		cancelStockInfo := models.CancelStockInfo{
8943
+			GoodId:          project.ProjectId,
8944
+			CancelStockId:   cancelInfo.ID,
8945
+			GoodTypeId:      good.GoodTypeId,
8946
+			Count:           cha_count,
8947
+			Price:           project.Price,
8948
+			Total:           0,
8949
+			ProductDate:     GoodOutInfo.ProductDate,
8950
+			ExpiryDate:      GoodOutInfo.ExpiryDate,
8951
+			Ctime:           time.Now().Unix(),
8952
+			Status:          1,
8953
+			OrgId:           orgID,
8954
+			OrderNumber:     cancelInfo.OrderNumber,
8955
+			Type:            0,
8956
+			Dealer:          dealer.DealerName,
8957
+			Manufacturer:    manufactureName.ManufacturerName,
8958
+			Number:          GoodOutInfo.Number,
8959
+			RegisterAccount: "",
8960
+			Remark:          "",
8961
+			WarehouseInfoId: GoodOutInfo.WarehouseInfotId,
8962
+			PatientId:       project.ProjectId,
8963
+			RecordDate:      project.RecordDate,
8964
+			StorehouseId:    storeConfig.StorehouseOutInfo,
8965
+			IsCheck:         1,
8966
+		}
8967
+		CreateNewCancelStockInfoOne(&cancelStockInfo, tx)
8968
+
8969
+		flow := models.VmStockFlow{
8970
+			WarehousingId:           GoodOutInfo.WarehouseInfotId,
8971
+			GoodId:                  project.ProjectId,
8972
+			Number:                  GoodOutInfo.Number,
8973
+			LicenseNumber:           GoodOutInfo.LicenseNumber,
8974
+			Count:                   cha_count,
8975
+			UserOrgId:               orgID,
8976
+			PatientId:               project.PatientId,
8977
+			SystemTime:              project.RecordDate,
8978
+			ConsumableType:          7,
8979
+			IsSys:                   1,
8980
+			WarehousingOrder:        "",
8981
+			WarehouseOutId:          GoodOutInfo.WarehouseOutId,
8982
+			WarehouseOutOrderNumber: GoodOutInfo.WarehouseOutOrderNumber,
8983
+			IsEdit:                  0,
8984
+			CancelStockId:           cancelInfo.ID,
8985
+			CancelOrderNumber:       cancelInfo.OrderNumber,
8986
+			Manufacturer:            manufactureName.ID,
8987
+			Dealer:                  0,
8988
+			Creator:                 creater,
8989
+			UpdateCreator:           0,
8990
+			Status:                  1,
8991
+			Ctime:                   time.Now().Unix(),
8992
+			Mtime:                   0,
8993
+			Price:                   GoodOutInfo.Price,
8994
+			WarehousingDetailId:     GoodOutInfo.WarehouseInfotId,
8995
+			WarehouseOutDetailId:    GoodOutInfo.ID,
8996
+			CancelOutDetailId:       cancelInfo.ID,
8997
+			ProductDate:             GoodOutInfo.ProductDate,
8998
+			ExpireDate:              GoodOutInfo.ExpiryDate,
8999
+			StorehouseId:            storeConfig.StorehouseOutInfo,
9000
+			BuyPrice:                project.Price,
9001
+			ProjectId:               project.ID,
9002
+			OverCount:               sum_count,
9003
+			RegisterNumber:          GoodOutInfo.RegisterNumber,
9004
+			OperateTime:             time.Now().Unix(),
9005
+		}
9006
+		CreateNewStockFlowOne(flow, tx)
9007
+
9008
+		AddGoodNewCancelSumCountOne(storeConfig.StorehouseOutInfo, project.ProjectId, orgID, flow.Count, tx)
9009
+
9010
+		ReduceNewGoodCountTwo(project.ProjectId, orgID, storeConfig.StorehouseOutInfo, flow.Count, tx)
9011
+
9012
+	}
9013
+
9014
+	//如果出库的数据小于这个退库的数量差,则先该批次出库数量出完
9015
+	if out_count < cha_count {
9016
+
9017
+		//把该出库单的数量退完
9018
+		ModifyNewGoodWarehouseInfoStockMinNumber(out_count, GoodOutInfo.GoodId, GoodOutInfo.OrgId, GoodOutInfo.WarehouseInfotId, tx)
9019
+
9020
+		//删除该出库单
9021
+		DeleteGoodWarehouseOutInfoByNumber(GoodOutInfo.ID, tx)
9022
+
9023
+		//查询剩余库存
9024
+		goodList, _ := GetNewAllGoodSumCount(project.ProjectId, orgID, storeConfig.StorehouseOutInfo, tx)
9025
+		var sum_count int64
9026
+		for _, item := range goodList {
9027
+			sum_count += item.StockCount
9028
+		}
9029
+
9030
+		operation_time := time.Now().Unix()
9031
+		//创建退库单
9032
+		timeStr := time.Now().Format("2006-01-02")
9033
+		timeArr := strings.Split(timeStr, "-")
9034
+		total, _ := FindNewAllCancelStockTotal(orgID, tx)
9035
+		total = total + 1
9036
+		orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
9037
+
9038
+		cancelStock := models.CancelStock{
9039
+			OrderNumber:  orderNumber,
9040
+			OperaTime:    operation_time,
9041
+			OrgId:        orgID,
9042
+			Creater:      creater,
9043
+			Ctime:        time.Now().Unix(),
9044
+			Status:       1,
9045
+			ReturnTime:   project.RecordDate,
9046
+			Type:         1,
9047
+			StorehouseId: storeConfig.StorehouseOutInfo,
9048
+			IsCheck:      1,
9049
+		}
9050
+		_, msgerrkonde := GetNewCancelStockDetailByOrderNumberOne(project.RecordDate, orgID, tx)
9051
+		if msgerrkonde == gorm.ErrRecordNotFound {
9052
+			AddNewSigleCancelStock(&cancelStock, tx)
9053
+		}
9054
+
9055
+		manufactureName, _ := GetNewManufactureById(GoodOutInfo.Manufacturer, tx)
9056
+		dealer, _ := GetNewDealerById(GoodOutInfo.Dealer, tx)
9057
+
9058
+		cancelInfo, _ := GetNewLastCancelStockById(orgID, tx)
9059
+
9060
+		cancelStockInfo := models.CancelStockInfo{
9061
+			GoodId:          project.ProjectId,
9062
+			CancelStockId:   cancelInfo.ID,
9063
+			GoodTypeId:      good.GoodTypeId,
9064
+			Count:           out_count,
9065
+			Price:           project.Price,
9066
+			Total:           0,
9067
+			ProductDate:     GoodOutInfo.ProductDate,
9068
+			ExpiryDate:      GoodOutInfo.ExpiryDate,
9069
+			Ctime:           time.Now().Unix(),
9070
+			Status:          1,
9071
+			OrgId:           orgID,
9072
+			OrderNumber:     cancelInfo.OrderNumber,
9073
+			Type:            0,
9074
+			Dealer:          dealer.DealerName,
9075
+			Manufacturer:    manufactureName.ManufacturerName,
9076
+			Number:          GoodOutInfo.Number,
9077
+			RegisterAccount: "",
9078
+			Remark:          "",
9079
+			WarehouseInfoId: GoodOutInfo.WarehouseInfotId,
9080
+			PatientId:       project.ProjectId,
9081
+			RecordDate:      project.RecordDate,
9082
+			StorehouseId:    storeConfig.StorehouseOutInfo,
9083
+			IsCheck:         1,
9084
+		}
9085
+		CreateNewCancelStockInfoOne(&cancelStockInfo, tx)
9086
+
9087
+		flow := models.VmStockFlow{
9088
+			WarehousingId:           GoodOutInfo.WarehouseInfotId,
9089
+			GoodId:                  project.ProjectId,
9090
+			Number:                  GoodOutInfo.Number,
9091
+			LicenseNumber:           GoodOutInfo.LicenseNumber,
9092
+			Count:                   out_count,
9093
+			UserOrgId:               orgID,
9094
+			PatientId:               project.PatientId,
9095
+			SystemTime:              project.RecordDate,
9096
+			ConsumableType:          7,
9097
+			IsSys:                   1,
9098
+			WarehousingOrder:        "",
9099
+			WarehouseOutId:          GoodOutInfo.WarehouseOutId,
9100
+			WarehouseOutOrderNumber: GoodOutInfo.WarehouseOutOrderNumber,
9101
+			IsEdit:                  0,
9102
+			CancelStockId:           cancelInfo.ID,
9103
+			CancelOrderNumber:       cancelInfo.OrderNumber,
9104
+			Manufacturer:            manufactureName.ID,
9105
+			Dealer:                  0,
9106
+			Creator:                 creater,
9107
+			UpdateCreator:           0,
9108
+			Status:                  1,
9109
+			Ctime:                   time.Now().Unix(),
9110
+			Mtime:                   0,
9111
+			Price:                   GoodOutInfo.Price,
9112
+			WarehousingDetailId:     GoodOutInfo.WarehouseInfotId,
9113
+			WarehouseOutDetailId:    GoodOutInfo.ID,
9114
+			CancelOutDetailId:       cancelInfo.ID,
9115
+			ProductDate:             GoodOutInfo.ProductDate,
9116
+			ExpireDate:              GoodOutInfo.ExpiryDate,
9117
+			StorehouseId:            storeConfig.StorehouseOutInfo,
9118
+			BuyPrice:                project.Price,
9119
+			ProjectId:               project.ID,
9120
+			OverCount:               sum_count,
9121
+			RegisterNumber:          GoodOutInfo.RegisterNumber,
9122
+			OperateTime:             time.Now().Unix(),
9123
+		}
9124
+		CreateNewStockFlowOne(flow, tx)
9125
+
9126
+		AddGoodNewCancelSumCountOne(storeConfig.StorehouseOutInfo, project.ProjectId, orgID, flow.Count, tx)
9127
+
9128
+		ReduceNewGoodCountTwo(project.ProjectId, orgID, storeConfig.StorehouseOutInfo, flow.Count, tx)
9129
+
9130
+		//计算还有多少没有退库
9131
+		var over_count = cha_count - out_count
9132
+
9133
+		NewHisGoodCancelInfo(orgID, creater, project, over_count, good, tx)
9134
+	}
9135
+	return err
9136
+
9137
+}
9138
+
9139
+func NewHisGoodAutoCancelInfo(orgID int64, creater int64, project *models.HisPrescriptionProject, cha_count int64, good models.GoodInformationThirty, tx *gorm.DB) error {
9140
+
9141
+	//查找患者最后一条的退库数据是否满足要求
9142
+	var out_count int64
9143
+	goodOutInfo, _ := GetGoodWarehouseOutInfoByProjectIdTwo(project.PatientId, project.UserOrgId, project.RecordDate, project.ProjectId, project.ID, tx)
9144
+
9145
+	out_count = goodOutInfo.Count
9146
+
9147
+	//如果最后1条出库数量大于退库数量,则直接退库,满足退库要求
9148
+	if out_count >= cha_count {
9149
+
9150
+		//减去出库单里面的数量
9151
+		ModifyGoodAuToWarehouseOut(goodOutInfo.ID, cha_count, tx)
9152
+
9153
+		if out_count == cha_count {
9154
+			//删除该出库单
9155
+			DeleteGoodWarehouseAutoByNumberTwo(goodOutInfo.ID, tx)
9156
+		}
9157
+	}
9158
+
9159
+	//如果出库的数据小于这个退库的数量差,则先该批次出库数量出完
9160
+	if out_count < cha_count {
9161
+
9162
+		//删除该出库单
9163
+		DeleteGoodWarehouseAutoByNumberTwo(goodOutInfo.ID, tx)
9164
+
9165
+		//计算还有多少没有退库
9166
+		var over_count = cha_count - out_count
9167
+
9168
+		NewHisGoodAutoCancelInfo(orgID, creater, project, over_count, good, tx)
9169
+	}
9170
+	return err
9171
+}