Преглед на файлове

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

test_user преди 1 година
родител
ревизия
9daaacbe73

+ 1 - 1
conf/app.conf Целия файл

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9531
2
+httpport = 9529
3 3
 runmode =dev
4 4
 #dev/prod
5 5
 

+ 16 - 0
controllers/dialysis_record_api_controller.go Целия файл

@@ -80,7 +80,13 @@ func (this *DialysisRecordAPIController) GetSchedules() {
80 80
 	patients, _ := service.GetAllPcPatientListByListEight(orgID)
81 81
 	scheduals_json_str, _ := redis.Get(key).Result()
82 82
 
83
+	if orgID == 9671 || orgID == 9675 || orgID == 10164 || orgID == 9679 {
84
+		redis.Set(key, scheduals_json_str, time.Second*60)
85
+	}
86
+	fmt.Println("len2o2o2o2o2", len(scheduals_json_str))
87
+
83 88
 	if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
89
+
84 90
 		scheduals, err := service.GetDialysisSchedualsOne(orgID, date.Unix())
85 91
 
86 92
 		if err != nil {
@@ -101,7 +107,17 @@ func (this *DialysisRecordAPIController) GetSchedules() {
101 107
 
102 108
 				advices, _ := service.GetAllPcAdvicestByList(orgID, date.Unix())
103 109
 
110
+				inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
111
+
104 112
 				for key, item := range scheduals {
113
+
114
+					for _, infor := range inforMation {
115
+
116
+						if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
117
+							scheduals[key].NewDeviceInformation = infor
118
+							break
119
+						}
120
+					}
105 121
 					// 获取患者信息
106 122
 					for _, patient := range patients {
107 123
 						if item.PatientId == patient.ID {

+ 212 - 342
controllers/his_api_controller.go Целия файл

@@ -1703,7 +1703,7 @@ func (c *HisApiController) CreateHisPrescription() {
1703 1703
 
1704 1704
 										//查找该耗材的出库记录
1705 1705
 										goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
1706
-
1706
+										fmt.Println("goodWarehouseInfo---------------------------------------------", goodWarehouseInfo)
1707 1707
 										if len(goodWarehouseInfo) == 0 {
1708 1708
 											//查询耗材库存
1709 1709
 											list, _ := service.GetGoodWarehouseInfoSeven(project_id)
@@ -2287,7 +2287,6 @@ func (c *HisApiController) CreateHisPrescription() {
2287 2287
 			for _, item := range hisgoodlist {
2288 2288
 				//查询耗材最后一次出库记录
2289 2289
 				wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
2290
-				fmt.Println("hh23h232323o23o23o2o32o23o2o3o2o23o32o23o2o323o23o23o23o23o23o")
2291 2290
 				//查询默认出库仓库库存
2292 2291
 				storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
2293 2292
 				if len(wareOut) > 0 {
@@ -2297,8 +2296,11 @@ func (c *HisApiController) CreateHisPrescription() {
2297 2296
 						service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
2298 2297
 						//删除出库记录
2299 2298
 						service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
2299
+						fmt.Println("it23------------------------------------------------", it.GoodId)
2300
+						fmt.Println("it.Count------------------------------------------------", it.Count)
2300 2301
 						//出库数量减少
2301
-						service.UpdateSumCount(it.OrgId, storeConfig.StorehouseOutInfo, it.ProjectId, it.Count)
2302
+						service.UpdateSumCount(it.OrgId, storeConfig.StorehouseOutInfo, it.GoodId, it.Count)
2303
+						service.UpdateActSumCount(it.OrgId, storeConfig.StorehouseOutInfo, it.GoodId, it.Count)
2302 2304
 					}
2303 2305
 				}
2304 2306
 
@@ -2374,6 +2376,23 @@ func (c *HisApiController) CreateHisPrescription() {
2374 2376
 					service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
2375 2377
 				}
2376 2378
 
2379
+				if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
2380
+					service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
2381
+
2382
+					//查询剩余库存
2383
+					goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
2384
+					var sum_count int64
2385
+					for _, item := range goodList {
2386
+						sum_count += item.StockCount
2387
+					}
2388
+
2389
+					//更新剩余库存
2390
+					service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
2391
+
2392
+					//耗材
2393
+					service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
2394
+				}
2395
+
2377 2396
 			}
2378 2397
 		}
2379 2398
 	}
@@ -2945,75 +2964,6 @@ func (c *HisApiController) DeletePrescription() {
2945 2964
 
2946 2965
 							//更新基础库库存
2947 2966
 							service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
2948
-							//查询今日该耗材退库数量
2949
-							//cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
2950
-							//var cancel_Count int64
2951
-							//for _, items := range cancelInfoOne {
2952
-							//	cancel_Count += items.Count
2953
-							//}
2954
-							//
2955
-							//cha_count = total_count - cancel_Count
2956
-							//
2957
-							//if total_count > cancel_Count {
2958
-							//
2959
-							//	out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
2960
-							//	if err == gorm.ErrRecordNotFound {
2961
-							//		//没有记录,则创建出库单
2962
-							//		timeStr := time.Now().Format("2006-01-02")
2963
-							//		timeArr := strings.Split(timeStr, "-")
2964
-							//		total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
2965
-							//		total = total + 1
2966
-							//		warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
2967
-							//		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
2968
-							//		number = number + total
2969
-							//		warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
2970
-							//		warehouseOut := models.WarehouseOut{
2971
-							//			WarehouseOutOrderNumber: warehousing_out_order,
2972
-							//			OperationTime:           time.Now().Unix(),
2973
-							//			OrgId:                   c.GetAdminUserInfo().CurrentOrgId,
2974
-							//			Creater:                 creater,
2975
-							//			Ctime:                   time.Now().Unix(),
2976
-							//			Status:                  1,
2977
-							//			WarehouseOutTime:        info.SysRecordTime,
2978
-							//			Dealer:                  0,
2979
-							//			Manufacturer:            0,
2980
-							//			Type:                    1,
2981
-							//			IsSys:                   1,
2982
-							//			StorehouseId:            houseConfig.StorehouseOutInfo,
2983
-							//			IsCheck:                 1,
2984
-							//		}
2985
-							//		err := service.AddSigleWarehouseOut(&warehouseOut)
2986
-							//		if err != nil {
2987
-							//			utils.TraceLog("创建出库单失败 err = %v", err)
2988
-							//			return
2989
-							//		}
2990
-							//		prepare := &models.DialysisBeforePrepare{
2991
-							//			UserOrgId:    c.GetAdminUserInfo().CurrentOrgId,
2992
-							//			PatientId:    info.PatientId,
2993
-							//			RecordDate:   info.SysRecordTime,
2994
-							//			GoodId:       item.ProjectId,
2995
-							//			GoodTypeId:   info.GoodTypeId,
2996
-							//			Count:        cha_count,
2997
-							//			StorehouseId: houseConfig.StorehouseOutInfo,
2998
-							//		}
2999
-							//		//出库
3000
-							//		service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
3001
-							//	} else if err == nil {
3002
-							//
3003
-							//		prepare := &models.DialysisBeforePrepare{
3004
-							//			UserOrgId:    c.GetAdminUserInfo().CurrentOrgId,
3005
-							//			PatientId:    info.PatientId,
3006
-							//			RecordDate:   info.SysRecordTime,
3007
-							//			GoodId:       item.ProjectId,
3008
-							//			GoodTypeId:   info.GoodTypeId,
3009
-							//			Count:        cha_count,
3010
-							//			StorehouseId: houseConfig.StorehouseOutInfo,
3011
-							//		}
3012
-							//		//出库
3013
-							//		service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
3014
-							//	}
3015
-							//
3016
-							//}
3017 2967
 
3018 2968
 						}
3019 2969
 
@@ -3074,9 +3024,6 @@ func (c *HisApiController) DeletePrescription() {
3074 3024
 					fmt.Println("历史出库数据", info.Count)
3075 3025
 					fmt.Println("出库数量", total_count)
3076 3026
 					if info.ID > 0 {
3077
-
3078
-						//回退库存
3079
-						service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
3080 3027
 						cancelStockInfo := models.CancelStockInfo{
3081 3028
 							GoodId:          item.ProjectId,
3082 3029
 							CancelStockId:   cancel.ID,
@@ -3107,121 +3054,106 @@ func (c *HisApiController) DeletePrescription() {
3107 3054
 
3108 3055
 						cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3109 3056
 
3110
-						flow := models.VmStockFlow{
3111
-							WarehousingId:           info.WarehouseInfotId,
3112
-							GoodId:                  item.ProjectId,
3113
-							Number:                  info.Number,
3114
-							LicenseNumber:           info.LicenseNumber,
3115
-							Count:                   prescribingNumber,
3116
-							UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3117
-							PatientId:               item.PatientId,
3118
-							SystemTime:              info.SysRecordTime,
3119
-							ConsumableType:          7,
3120
-							IsSys:                   0,
3121
-							WarehousingOrder:        "",
3122
-							WarehouseOutId:          info.WarehouseOutId,
3123
-							WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3124
-							IsEdit:                  0,
3125
-							CancelStockId:           cancel.ID,
3126
-							CancelOrderNumber:       cancel.OrderNumber,
3127
-							Manufacturer:            manufacturer.ID,
3128
-							Dealer:                  0,
3129
-							Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3130
-							UpdateCreator:           0,
3131
-							Status:                  1,
3132
-							Ctime:                   time.Now().Unix(),
3133
-							Mtime:                   0,
3134
-							Price:                   info.Price,
3135
-							WarehousingDetailId:     info.WarehouseInfotId,
3136
-							WarehouseOutDetailId:    info.ID,
3137
-							CancelOutDetailId:       cancelInfo.ID,
3138
-							ProductDate:             info.ProductDate,
3139
-							ExpireDate:              info.ExpiryDate,
3140
-							StorehouseId:            houseConfig.StorehouseOutInfo,
3141
-							OverCount:               flush_count,
3057
+						//查询出库数量
3058
+						list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
3059
+
3060
+						//出库数据 大于 退库数量
3061
+						if len(list) > 0 {
3062
+							for _, it := range list {
3063
+								//回退库存
3064
+								service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
3065
+								goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
3066
+								var flush_count_one int64
3067
+								for _, it := range goodList {
3068
+									flush_count_one += it.StockCount
3069
+								}
3070
+								//查询该批次是否有退库数据
3071
+								flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
3072
+								creater := c.GetAdminUserInfo().AdminUser.Id
3073
+								if flow.ID == 0 {
3074
+
3075
+									flow := models.VmStockFlow{
3076
+										WarehousingId:           it.WarehouseInfotId,
3077
+										GoodId:                  it.GoodId,
3078
+										Number:                  it.Number,
3079
+										LicenseNumber:           it.LicenseNumber,
3080
+										Count:                   it.Count,
3081
+										UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3082
+										PatientId:               it.PatientId,
3083
+										SystemTime:              it.SysRecordTime,
3084
+										ConsumableType:          7,
3085
+										IsSys:                   0,
3086
+										WarehousingOrder:        "",
3087
+										WarehouseOutId:          it.WarehouseOutId,
3088
+										WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
3089
+										IsEdit:                  0,
3090
+										CancelStockId:           cancel.ID,
3091
+										CancelOrderNumber:       cancel.OrderNumber,
3092
+										Manufacturer:            manufacturer.ID,
3093
+										Dealer:                  0,
3094
+										Creator:                 creater,
3095
+										UpdateCreator:           0,
3096
+										Status:                  1,
3097
+										Ctime:                   time.Now().Unix(),
3098
+										Mtime:                   0,
3099
+										Price:                   it.Price,
3100
+										WarehousingDetailId:     it.WarehouseInfotId,
3101
+										WarehouseOutDetailId:    it.ID,
3102
+										CancelOutDetailId:       cancelInfo.ID,
3103
+										ProductDate:             it.ProductDate,
3104
+										ExpireDate:              it.ExpiryDate,
3105
+										StorehouseId:            houseConfig.StorehouseOutInfo,
3106
+										OverCount:               flush_count_one,
3107
+									}
3108
+									service.CreateStockFlowOne(flow)
3109
+								}
3110
+								if flow.ID > 0 {
3111
+									service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
3112
+								}
3113
+							}
3114
+
3142 3115
 						}
3143
-						service.CreateStockFlowOne(flow)
3116
+
3117
+						//flow := models.VmStockFlow{
3118
+						//	WarehousingId:           info.WarehouseInfotId,
3119
+						//	GoodId:                  item.ProjectId,
3120
+						//	Number:                  info.Number,
3121
+						//	LicenseNumber:           info.LicenseNumber,
3122
+						//	Count:                   prescribingNumber,
3123
+						//	UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3124
+						//	PatientId:               item.PatientId,
3125
+						//	SystemTime:              info.SysRecordTime,
3126
+						//	ConsumableType:          7,
3127
+						//	IsSys:                   0,
3128
+						//	WarehousingOrder:        "",
3129
+						//	WarehouseOutId:          info.WarehouseOutId,
3130
+						//	WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3131
+						//	IsEdit:                  0,
3132
+						//	CancelStockId:           cancel.ID,
3133
+						//	CancelOrderNumber:       cancel.OrderNumber,
3134
+						//	Manufacturer:            manufacturer.ID,
3135
+						//	Dealer:                  0,
3136
+						//	Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3137
+						//	UpdateCreator:           0,
3138
+						//	Status:                  1,
3139
+						//	Ctime:                   time.Now().Unix(),
3140
+						//	Mtime:                   0,
3141
+						//	Price:                   info.Price,
3142
+						//	WarehousingDetailId:     info.WarehouseInfotId,
3143
+						//	WarehouseOutDetailId:    info.ID,
3144
+						//	CancelOutDetailId:       cancelInfo.ID,
3145
+						//	ProductDate:             info.ProductDate,
3146
+						//	ExpireDate:              info.ExpiryDate,
3147
+						//	StorehouseId:            houseConfig.StorehouseOutInfo,
3148
+						//	OverCount:               flush_count,
3149
+						//}
3150
+						//service.CreateStockFlowOne(flow)
3144 3151
 
3145 3152
 						//退库数量增加
3146 3153
 						service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
3147 3154
 						//出库数量减少
3148 3155
 						service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
3149 3156
 
3150
-						//if info.Count < total_count {
3151
-						//	//回退库存
3152
-						//	service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
3153
-						//	cancelStockInfo := models.CancelStockInfo{
3154
-						//		GoodId:          item.ProjectId,
3155
-						//		CancelStockId:   cancel.ID,
3156
-						//		GoodTypeId:      good.GoodTypeId,
3157
-						//		Count:           info.Count,
3158
-						//		Price:           info.Price,
3159
-						//		Total:           0,
3160
-						//		ProductDate:     info.ProductDate,
3161
-						//		ExpiryDate:      info.ExpiryDate,
3162
-						//		Ctime:           time.Now().Unix(),
3163
-						//		Status:          1,
3164
-						//		OrgId:           c.GetAdminUserInfo().CurrentOrgId,
3165
-						//		OrderNumber:     cancel.OrderNumber,
3166
-						//		Type:            0,
3167
-						//		Dealer:          deaerler.DealerName,
3168
-						//		Manufacturer:    manufacturer.ManufacturerName,
3169
-						//		Number:          info.Number,
3170
-						//		RegisterAccount: "",
3171
-						//		Remark:          "",
3172
-						//		WarehouseInfoId: info.WarehouseInfotId,
3173
-						//		PatientId:       info.PatientId,
3174
-						//		RecordDate:      info.SysRecordTime,
3175
-						//		StorehouseId:    houseConfig.StorehouseOutInfo,
3176
-						//		IsCheck:         1,
3177
-						//	}
3178
-						//
3179
-						//	service.CreateCancelStockInfoOne(&cancelStockInfo)
3180
-						//
3181
-						//	cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3182
-						//
3183
-						//	flow := models.VmStockFlow{
3184
-						//		WarehousingId:           info.WarehouseInfotId,
3185
-						//		GoodId:                  item.ProjectId,
3186
-						//		Number:                  info.Number,
3187
-						//		LicenseNumber:           info.LicenseNumber,
3188
-						//		Count:                   info.Count,
3189
-						//		UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3190
-						//		PatientId:               item.PatientId,
3191
-						//		SystemTime:              info.SysRecordTime,
3192
-						//		ConsumableType:          7,
3193
-						//		IsSys:                   0,
3194
-						//		WarehousingOrder:        "",
3195
-						//		WarehouseOutId:          info.WarehouseOutId,
3196
-						//		WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3197
-						//		IsEdit:                  0,
3198
-						//		CancelStockId:           cancel.ID,
3199
-						//		CancelOrderNumber:       cancel.OrderNumber,
3200
-						//		Manufacturer:            manufacturer.ID,
3201
-						//		Dealer:                  0,
3202
-						//		Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3203
-						//		UpdateCreator:           0,
3204
-						//		Status:                  1,
3205
-						//		Ctime:                   time.Now().Unix(),
3206
-						//		Mtime:                   0,
3207
-						//		Price:                   info.Price,
3208
-						//		WarehousingDetailId:     info.WarehouseInfotId,
3209
-						//		WarehouseOutDetailId:    info.ID,
3210
-						//		CancelOutDetailId:       cancelInfo.ID,
3211
-						//		ProductDate:             info.ProductDate,
3212
-						//		ExpireDate:              info.ExpiryDate,
3213
-						//		StorehouseId:            houseConfig.StorehouseOutInfo,
3214
-						//		OverCount:               flush_count,
3215
-						//	}
3216
-						//	service.CreateStockFlowOne(flow)
3217
-						//
3218
-						//	//退库数量增加
3219
-						//	service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
3220
-						//	//出库数量减少
3221
-						//	service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
3222
-						//
3223
-						//}
3224
-
3225 3157
 						//查询已出库数量
3226 3158
 						dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
3227 3159
 
@@ -3278,6 +3210,7 @@ func (c *HisApiController) DeletePrescription() {
3278 3210
 		}
3279 3211
 
3280 3212
 	} else {
3213
+
3281 3214
 		if drugOutConfig.IsOpen == 1 {
3282 3215
 			if len(advices) > 0 {
3283 3216
 				for _, item := range advices {
@@ -3285,6 +3218,13 @@ func (c *HisApiController) DeletePrescription() {
3285 3218
 					service.DrugAutoAddCancelInfo(item, creater)
3286 3219
 				}
3287 3220
 			}
3221
+		} else {
3222
+			if len(advices) > 0 {
3223
+				for _, item := range advices {
3224
+					creater := c.GetAdminUserInfo().AdminUser.Id
3225
+					service.DrugAutoAddCancelInfo(item, creater)
3226
+				}
3227
+			}
3288 3228
 		}
3289 3229
 	}
3290 3230
 
@@ -3474,6 +3414,7 @@ func (c *HisApiController) DeleteProject() {
3474 3414
 			}
3475 3415
 
3476 3416
 			if project.Type == 3 && project.IsOut == 1 {
3417
+
3477 3418
 				houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
3478 3419
 				good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
3479 3420
 				f_count, _ := strconv.ParseFloat(project.Count, 64)
@@ -3506,7 +3447,7 @@ func (c *HisApiController) DeleteProject() {
3506 3447
 				cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
3507 3448
 				floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
3508 3449
 				prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
3509
-				//获取出库数据
3450
+				//查询是否有出库
3510 3451
 				info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
3511 3452
 
3512 3453
 				manufacturer, _ := service.GetManufactureById(info.Manufacturer)
@@ -3584,12 +3525,15 @@ func (c *HisApiController) DeleteProject() {
3584 3525
 						service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
3585 3526
 					}
3586 3527
 
3528
+					//查询剩余库存
3587 3529
 					goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
3588 3530
 					var over_count int64
3589 3531
 					for _, it := range goodList {
3590 3532
 						over_count += it.StockCount
3591 3533
 					}
3534
+					//出库数据 大于 退库数量
3592 3535
 					if info.Count >= prescribingNumber {
3536
+
3593 3537
 						flow := models.VmStockFlow{
3594 3538
 							WarehousingId:           info.WarehouseInfotId,
3595 3539
 							GoodId:                  project.ProjectId,
@@ -3626,6 +3570,7 @@ func (c *HisApiController) DeleteProject() {
3626 3570
 						service.CreateStockFlowOne(flow)
3627 3571
 					}
3628 3572
 
3573
+					//出库数据小于退库数据
3629 3574
 					if info.Count < prescribingNumber {
3630 3575
 						flow := models.VmStockFlow{
3631 3576
 							WarehousingId:           info.WarehouseInfotId,
@@ -3679,84 +3624,6 @@ func (c *HisApiController) DeleteProject() {
3679 3624
 					//更新剩余库存
3680 3625
 					service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
3681 3626
 
3682
-					//查询今日该患者开了多少耗材
3683
-					//projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
3684
-					//
3685
-					//var total_count int64
3686
-					//var cha_count int64
3687
-					//for _, item := range projectList {
3688
-					//	count, _ := strconv.ParseInt(item.Count, 10, 64)
3689
-					//	total_count += count
3690
-					//}
3691
-					//
3692
-					////查询今日该耗材退库数量
3693
-					//cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
3694
-					//var cancel_count int64
3695
-					//for _, items := range cancelInfoOne {
3696
-					//	cancel_count += items.Count
3697
-					//}
3698
-					//
3699
-					//cha_count = total_count - cancel_count
3700
-					//
3701
-					//if total_count > cancel_count {
3702
-					//
3703
-					//	out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
3704
-					//	if err == gorm.ErrRecordNotFound {
3705
-					//		//没有记录,则创建出库单
3706
-					//		timeStr := time.Now().Format("2006-01-02")
3707
-					//		timeArr := strings.Split(timeStr, "-")
3708
-					//		total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
3709
-					//		total = total + 1
3710
-					//		warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
3711
-					//		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
3712
-					//		number = number + total
3713
-					//		warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
3714
-					//		warehouseOut := models.WarehouseOut{
3715
-					//			WarehouseOutOrderNumber: warehousing_out_order,
3716
-					//			OperationTime:           time.Now().Unix(),
3717
-					//			OrgId:                   adminInfo.CurrentOrgId,
3718
-					//			Creater:                 creater,
3719
-					//			Ctime:                   time.Now().Unix(),
3720
-					//			Status:                  1,
3721
-					//			WarehouseOutTime:        info.SysRecordTime,
3722
-					//			Dealer:                  0,
3723
-					//			Manufacturer:            0,
3724
-					//			Type:                    1,
3725
-					//			IsSys:                   1,
3726
-					//			StorehouseId:            houseConfig.StorehouseOutInfo,
3727
-					//		}
3728
-					//		err := service.AddSigleWarehouseOut(&warehouseOut)
3729
-					//		if err != nil {
3730
-					//			utils.TraceLog("创建出库单失败 err = %v", err)
3731
-					//			return
3732
-					//		}
3733
-					//		prepare := &models.DialysisBeforePrepare{
3734
-					//			UserOrgId:    adminInfo.CurrentOrgId,
3735
-					//			PatientId:    info.PatientId,
3736
-					//			RecordDate:   info.SysRecordTime,
3737
-					//			GoodId:       project.ProjectId,
3738
-					//			GoodTypeId:   info.GoodTypeId,
3739
-					//			Count:        cha_count,
3740
-					//			StorehouseId: houseConfig.StorehouseOutInfo,
3741
-					//		}
3742
-					//		//出库
3743
-					//		service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
3744
-					//	} else if err == nil {
3745
-					//		prepare := &models.DialysisBeforePrepare{
3746
-					//			UserOrgId:    adminInfo.CurrentOrgId,
3747
-					//			PatientId:    info.PatientId,
3748
-					//			RecordDate:   info.SysRecordTime,
3749
-					//			GoodId:       project.ProjectId,
3750
-					//			GoodTypeId:   info.GoodTypeId,
3751
-					//			Count:        cha_count,
3752
-					//			StorehouseId: houseConfig.StorehouseOutInfo,
3753
-					//		}
3754
-					//		//出库
3755
-					//		service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
3756
-					//	}
3757
-					//
3758
-					//}
3759
-
3760 3627
 					stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
3761 3628
 					var total_count_one int64
3762 3629
 					for _, it := range stockList {
@@ -3798,11 +3665,13 @@ func (c *HisApiController) DeleteProject() {
3798 3665
 		}
3799 3666
 	}
3800 3667
 
3668
+	//保存处方出库
3801 3669
 	if goodOutConfig.IsOpen == 1 {
3802 3670
 
3803 3671
 		if project.Type == 3 {
3804 3672
 			houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
3805 3673
 			good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
3674
+
3806 3675
 			f_count, _ := strconv.ParseFloat(project.Count, 64)
3807 3676
 
3808 3677
 			operation_time := time.Now().Unix()
@@ -3868,19 +3737,18 @@ func (c *HisApiController) DeleteProject() {
3868 3737
 					}
3869 3738
 
3870 3739
 					service.CreateCancelStockInfoOne(&cancelStockInfo)
3871
-					//回退库存
3872
-					service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
3740
+
3873 3741
 					//退库数量增加
3874
-					service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
3742
+					//service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
3875 3743
 					//出库数量减少
3876
-					service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
3744
+					//service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
3877 3745
 				}
3878 3746
 				if info.Count < prescribingNumber {
3879 3747
 					cancelStockInfo := models.CancelStockInfo{
3880 3748
 						GoodId:          project.ProjectId,
3881 3749
 						CancelStockId:   cancel.ID,
3882 3750
 						GoodTypeId:      good.GoodTypeId,
3883
-						Count:           info.Count,
3751
+						Count:           prescribingNumber,
3884 3752
 						Price:           info.Price,
3885 3753
 						Total:           0,
3886 3754
 						ProductDate:     info.ProductDate,
@@ -3904,11 +3772,8 @@ func (c *HisApiController) DeleteProject() {
3904 3772
 
3905 3773
 					service.CreateCancelStockInfoOne(&cancelStockInfo)
3906 3774
 					//回退库存
3907
-					service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
3908
-					//退库数量增加
3909
-					service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
3910
-					//出库数量减少
3911
-					service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
3775
+					//service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
3776
+
3912 3777
 				}
3913 3778
 
3914 3779
 				goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
@@ -3916,78 +3781,68 @@ func (c *HisApiController) DeleteProject() {
3916 3781
 				for _, it := range goodList {
3917 3782
 					over_count += it.StockCount
3918 3783
 				}
3919
-				if info.Count >= prescribingNumber {
3920
-					flow := models.VmStockFlow{
3921
-						WarehousingId:           info.WarehouseInfotId,
3922
-						GoodId:                  project.ProjectId,
3923
-						Number:                  info.Number,
3924
-						LicenseNumber:           info.LicenseNumber,
3925
-						Count:                   prescribingNumber,
3926
-						UserOrgId:               adminInfo.CurrentOrgId,
3927
-						PatientId:               project.PatientId,
3928
-						SystemTime:              info.SysRecordTime,
3929
-						ConsumableType:          7,
3930
-						IsSys:                   0,
3931
-						WarehousingOrder:        "",
3932
-						WarehouseOutId:          info.WarehouseOutId,
3933
-						WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3934
-						IsEdit:                  0,
3935
-						CancelStockId:           cancel.ID,
3936
-						CancelOrderNumber:       cancel.OrderNumber,
3937
-						Manufacturer:            manufacturer.ID,
3938
-						Dealer:                  0,
3939
-						Creator:                 adminInfo.AdminUser.Id,
3940
-						UpdateCreator:           0,
3941
-						Status:                  1,
3942
-						Ctime:                   time.Now().Unix(),
3943
-						Mtime:                   0,
3944
-						Price:                   info.Price,
3945
-						WarehousingDetailId:     info.WarehouseInfotId,
3946
-						WarehouseOutDetailId:    info.ID,
3947
-						CancelOutDetailId:       cancelInfo.ID,
3948
-						ProductDate:             info.ProductDate,
3949
-						ExpireDate:              info.ExpiryDate,
3950
-						StorehouseId:            houseConfig.StorehouseOutInfo,
3951
-						OverCount:               over_count,
3952
-					}
3953
-					service.CreateStockFlowOne(flow)
3954
-				}
3955 3784
 
3956
-				if info.Count < prescribingNumber {
3957
-					flow := models.VmStockFlow{
3958
-						WarehousingId:           info.WarehouseInfotId,
3959
-						GoodId:                  project.ProjectId,
3960
-						Number:                  info.Number,
3961
-						LicenseNumber:           info.LicenseNumber,
3962
-						Count:                   info.Count,
3963
-						UserOrgId:               adminInfo.CurrentOrgId,
3964
-						PatientId:               project.PatientId,
3965
-						SystemTime:              info.SysRecordTime,
3966
-						ConsumableType:          7,
3967
-						IsSys:                   0,
3968
-						WarehousingOrder:        "",
3969
-						WarehouseOutId:          info.WarehouseOutId,
3970
-						WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3971
-						IsEdit:                  0,
3972
-						CancelStockId:           cancel.ID,
3973
-						CancelOrderNumber:       cancel.OrderNumber,
3974
-						Manufacturer:            manufacturer.ID,
3975
-						Dealer:                  0,
3976
-						Creator:                 adminInfo.AdminUser.Id,
3977
-						UpdateCreator:           0,
3978
-						Status:                  1,
3979
-						Ctime:                   time.Now().Unix(),
3980
-						Mtime:                   0,
3981
-						Price:                   info.Price,
3982
-						WarehousingDetailId:     info.WarehouseInfotId,
3983
-						WarehouseOutDetailId:    info.ID,
3984
-						CancelOutDetailId:       cancelInfo.ID,
3985
-						ProductDate:             info.ProductDate,
3986
-						ExpireDate:              info.ExpiryDate,
3987
-						StorehouseId:            houseConfig.StorehouseOutInfo,
3988
-						OverCount:               over_count,
3785
+				//查询出库数量
3786
+				list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
3787
+
3788
+				//出库数据 大于 退库数量
3789
+				if len(list) > 0 {
3790
+					for _, it := range list {
3791
+						//回退库存
3792
+						service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
3793
+						//退库数量增加
3794
+						service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
3795
+						//出库数量减少
3796
+						service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
3797
+						goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
3798
+						var over_count_one int64
3799
+						for _, it := range goodList {
3800
+							over_count_one += it.StockCount
3801
+						}
3802
+						//查询该批次是否有退库数据
3803
+						flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
3804
+
3805
+						if flow.ID == 0 {
3806
+							flow := models.VmStockFlow{
3807
+								WarehousingId:           it.WarehouseInfotId,
3808
+								GoodId:                  it.GoodId,
3809
+								Number:                  it.Number,
3810
+								LicenseNumber:           it.LicenseNumber,
3811
+								Count:                   it.Count,
3812
+								UserOrgId:               adminInfo.CurrentOrgId,
3813
+								PatientId:               it.PatientId,
3814
+								SystemTime:              it.SysRecordTime,
3815
+								ConsumableType:          7,
3816
+								IsSys:                   0,
3817
+								WarehousingOrder:        "",
3818
+								WarehouseOutId:          it.WarehouseOutId,
3819
+								WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
3820
+								IsEdit:                  0,
3821
+								CancelStockId:           cancel.ID,
3822
+								CancelOrderNumber:       cancel.OrderNumber,
3823
+								Manufacturer:            manufacturer.ID,
3824
+								Dealer:                  0,
3825
+								Creator:                 adminInfo.AdminUser.Id,
3826
+								UpdateCreator:           0,
3827
+								Status:                  1,
3828
+								Ctime:                   time.Now().Unix(),
3829
+								Mtime:                   0,
3830
+								Price:                   it.Price,
3831
+								WarehousingDetailId:     it.WarehouseInfotId,
3832
+								WarehouseOutDetailId:    it.ID,
3833
+								CancelOutDetailId:       cancelInfo.ID,
3834
+								ProductDate:             it.ProductDate,
3835
+								ExpireDate:              it.ExpiryDate,
3836
+								StorehouseId:            houseConfig.StorehouseOutInfo,
3837
+								OverCount:               over_count_one,
3838
+							}
3839
+							service.CreateStockFlowOne(flow)
3840
+						}
3841
+						if flow.ID > 0 {
3842
+							service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, over_count_one)
3843
+						}
3989 3844
 					}
3990
-					service.CreateStockFlowOne(flow)
3845
+
3991 3846
 				}
3992 3847
 
3993 3848
 				//查询已出库数量
@@ -6301,6 +6156,7 @@ func (c *HisApiController) GetUploadInfo() {
6301 6156
 						service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
6302 6157
 						service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
6303 6158
 					}
6159
+
6304 6160
 				}
6305 6161
 				orgId := c.GetAdminUserInfo().CurrentOrgId
6306 6162
 
@@ -6374,6 +6230,20 @@ func (c *HisApiController) GetUploadInfo() {
6374 6230
 							service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
6375 6231
 						}
6376 6232
 
6233
+						if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
6234
+							service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
6235
+							//查询剩余库存
6236
+							goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
6237
+							var sum_count int64
6238
+							for _, item := range goodList {
6239
+								sum_count += item.StockCount
6240
+							}
6241
+							service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
6242
+
6243
+							//耗材
6244
+							service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
6245
+						}
6246
+
6377 6247
 					}
6378 6248
 				}
6379 6249
 

+ 7 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go Целия файл

@@ -3333,6 +3333,13 @@ func (this *DialysisAPIController) ModifyStartDialysisOrder() {
3333 3333
 		ScheduleRemark:         schedule_remark,
3334 3334
 	}
3335 3335
 
3336
+	if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
3337
+
3338
+		if tempDialysisRecord.BedID != bedID {
3339
+			service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
3340
+		}
3341
+	}
3342
+
3336 3343
 	updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
3337 3344
 	order, _ := service.GetLastPatientOrder(record_id)
3338 3345
 	service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)

+ 2 - 2
controllers/mobile_api_controllers/patient_api_controller.go Целия файл

@@ -4182,7 +4182,7 @@ func (c *PatientApiController) ExecProject() {
4182 4182
 				loc, _ := time.LoadLocation("Local")
4183 4183
 				execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
4184 4184
 				//查询该耗材是否已经出库
4185
-				auto, _ := service.GetAutoStockOutById(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
4185
+				auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
4186 4186
 				if auto.ID == 0 {
4187 4187
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
4188 4188
 					return
@@ -4203,7 +4203,7 @@ func (c *PatientApiController) ExecProject() {
4203 4203
 				loc, _ := time.LoadLocation("Local")
4204 4204
 				execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
4205 4205
 				//查询该耗材是否已经出库
4206
-				auto, _ := service.GetAutoStockOutById(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
4206
+				auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
4207 4207
 				if auto.ID == 0 {
4208 4208
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
4209 4209
 					return

+ 2 - 2
controllers/print_data_api_controller.go Целия файл

@@ -37,7 +37,7 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
37 37
 	idStrs := strings.Split(schIDStr, ",")
38 38
 	adminUserInfo := this.GetAdminUserInfo()
39 39
 
40
-	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 {
40
+	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 {
41 41
 		schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
42 42
 		for _, item := range schedules {
43 43
 
@@ -127,7 +127,7 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
127 127
 		})
128 128
 	}
129 129
 
130
-	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 {
130
+	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 && this.GetAdminUserInfo().CurrentOrgId != 10138 && this.GetAdminUserInfo().CurrentOrgId != 10278 && this.GetAdminUserInfo().CurrentOrgId != 9841 && this.GetAdminUserInfo().CurrentOrgId != 9845 && this.GetAdminUserInfo().CurrentOrgId != 10081 {
131 131
 		schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
132 132
 		for _, item := range schedules {
133 133
 			list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)

+ 2 - 1
controllers/stock_in_api_controller.go Целия файл

@@ -7428,13 +7428,14 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7428 7428
 	Creator := this.GetAdminUserInfo().AdminUser.Id
7429 7429
 	//查询默认仓库
7430 7430
 	storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7431
+
7431 7432
 	//更改审核状态
7432 7433
 	err := service.UpdateCheckWarehouseInfo(warehousing_info_id)
7433 7434
 	if err == nil {
7434 7435
 		list, _ := service.GetWarehouseInfoList(warehousing_info_id, orgId)
7435 7436
 
7436 7437
 		for _, item := range list {
7437
-			service.UpdateWarehouseInfoByIdList(item.WarehousingCount, item.ID)
7438
+			service.UpdateWarehouseInfoByIdListThree(item.WarehousingCount, item.ID)
7438 7439
 
7439 7440
 			//查询该耗材剩余库存库
7440 7441
 			stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId)

+ 40 - 0
models/dialysis.go Целия файл

@@ -1419,3 +1419,43 @@ type HisDoctorAdviceFourty struct {
1419 1419
 func (HisDoctorAdviceFourty) TableName() string {
1420 1420
 	return "his_doctor_advice_info"
1421 1421
 }
1422
+
1423
+type NewDialysisOrder struct {
1424
+	ID                 int64  `gorm:"column:id" json:"id"`
1425
+	DialysisDate       int64  `gorm:"column:dialysis_date" json:"dialysis_date"`
1426
+	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id"`
1427
+	PatientId          int64  `gorm:"column:patient_id" json:"patient_id"`
1428
+	Stage              int64  `gorm:"column:stage" json:"stage"`
1429
+	BedID              int64  `gorm:"column:bed_id" json:"bed_id"`
1430
+	StartNurse         int64  `gorm:"column:start_nurse" json:"start_nurse"`
1431
+	FinishNurse        int64  `gorm:"column:finish_nurse" json:"finish_nurse"`
1432
+	Status             int64  `gorm:"column:status" json:"status"`
1433
+	DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
1434
+	DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
1435
+	BloodAccessId      int64  `gorm:"column:blood_access_id" json:"blood_access_id" form:"blood_access_id"`
1436
+	NucleinDate        int64  `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
1437
+	ScheduleRemark     string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
1438
+	OrderRemark        string `gorm:"column:order_remark" json:"order_remark" form:"order_remark"`
1439
+	DialysisTotal      int64  `gorm:"column:dialysis_total" json:"dialysis_total" form:"dialysis_total"`
1440
+}
1441
+
1442
+func (NewDialysisOrder) TableName() string {
1443
+	return "xt_dialysis_order"
1444
+}
1445
+
1446
+type NewAssessmentAfterDislysis struct {
1447
+	ID                     int64   `gorm:"column:id" json:"id"`
1448
+	UserOrgId              int64   `gorm:"column:user_org_id" json:"user_org_id"`
1449
+	PatientId              int64   `gorm:"column:patient_id" json:"patient_id"`
1450
+	AssessmentDate         int64   `gorm:"column:assessment_date" json:"assessment_date"`
1451
+	DialysisOrderId        int64   `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
1452
+	SystolicBloodPressure  float64 `gorm:"column:systolic_blood_pressure" json:"systolic_blood_pressure"`
1453
+	DiastolicBloodPressure float64 `gorm:"column:diastolic_blood_pressure" json:"diastolic_blood_pressure"`
1454
+	ActualUltrafiltration  float64 `gorm:"column:actual_ultrafiltration" json:"actual_ultrafiltration"`
1455
+	WeightLoss             float64 `gorm:"column:weight_loss" json:"weight_loss"`
1456
+	Status                 int64   `gorm:"column:status" json:"status"`
1457
+}
1458
+
1459
+func (NewAssessmentAfterDislysis) TableName() string {
1460
+	return "xt_assessment_after_dislysis"
1461
+}

+ 1 - 1
models/good_models.go Целия файл

@@ -277,7 +277,7 @@ type GoodInformationThirty struct {
277 277
 	ProvincesCode               string  `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
278 278
 	IsUser                      int64   `gorm:"column:is_user" json:"is_user" form:"is_user"`
279 279
 	Number                      string  `gorm:"column:number" json:"number" form:"number"`
280
-	IsWarehouse                 string  `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
280
+	IsWarehouse                 int64   `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
281 281
 	BatchRetaiPrice             float64 `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
282 282
 	SumCount                    int64   `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
283 283
 	SumInCount                  int64   `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`

+ 72 - 0
models/patient_models.go Целия файл

@@ -1657,3 +1657,75 @@ type PatientsThirty struct {
1657 1657
 func (PatientsThirty) TableName() string {
1658 1658
 	return "xt_patients"
1659 1659
 }
1660
+
1661
+type XtNewPatients struct {
1662
+	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
1663
+	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1664
+	DialysisNo         string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
1665
+	AdmissionNumber    string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
1666
+	Source             int64  `gorm:"column:source" json:"source" form:"source"`
1667
+	Lapseto            int64  `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
1668
+	Name               string `gorm:"column:name" json:"name" form:"name"`
1669
+	Gender             int64  `gorm:"column:gender" json:"gender" form:"gender"`
1670
+	IdCardNo           string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
1671
+	Birthday           int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
1672
+	UserSysBeforeCount int64  `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
1673
+	SchRemark          string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
1674
+	ScheduleRemark     string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
1675
+	Status             int64  `gorm:"column:status" json:"status" form:"status"`
1676
+}
1677
+
1678
+func (XtNewPatients) TableName() string {
1679
+
1680
+	return "xt_patients"
1681
+}
1682
+
1683
+type XtNewAssessmentBeforeDislysis struct {
1684
+	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
1685
+	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1686
+	PatientId             int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1687
+	AssessmentDate        int64   `gorm:"column:assessment_date" json:"assessment_date" form:"assessment_date"`
1688
+	DryWeight             float64 `gorm:"column:dry_weight" json:"dry_weight" form:"dry_weight"`
1689
+	WeightBefore          float64 `gorm:"column:weight_before" json:"weight_before" form:"weight_before"`
1690
+	UltrafiltrationAmount float64 `gorm:"column:ultrafiltration_amount" json:"ultrafiltration_amount" form:"ultrafiltration_amount"`
1691
+	Remark                string  `gorm:"column:remark" json:"remark" form:"remark"`
1692
+	Status                int64   `gorm:"column:status" json:"status" form:"status"`
1693
+}
1694
+
1695
+func (XtNewAssessmentBeforeDislysis) TableName() string {
1696
+	return "xt_assessment_before_dislysis"
1697
+}
1698
+
1699
+type NewDialysisSolution struct {
1700
+	ID                     int64   `gorm:"column:id" json:"id" form:"id"`
1701
+	Name                   string  `gorm:"column:name" json:"name" form:"name"`
1702
+	UserOrgId              int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1703
+	PatientId              int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1704
+	Type                   int64   `gorm:"column:type" json:"type" form:"type"`
1705
+	Anticoagulant          int64   `gorm:"column:anticoagulant" json:"anticoagulant" form:"anticoagulant"`
1706
+	AnticoagulantShouji    float64 `gorm:"column:anticoagulant_shouji" json:"anticoagulant_shouji" form:"anticoagulant_shouji"`
1707
+	AnticoagulantWeichi    float64 `gorm:"column:anticoagulant_weichi" json:"anticoagulant_weichi" form:"anticoagulant_weichi"`
1708
+	AnticoagulantZongliang float64 `gorm:"column:anticoagulant_zongliang" json:"anticoagulant_zongliang" form:"anticoagulant_zongliang"`
1709
+	ModeName               string  `gorm:"column:mode_name" json:"mode_name" form:"mode_name"`
1710
+	ModeId                 int64   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
1711
+	Glucose                float64 `gorm:"column:glucose" json:"glucose" form:"glucose"`
1712
+	Kalium                 float64 `gorm:"column:kalium" json:"kalium" form:"kalium"`
1713
+	Sodium                 float64 `gorm:"column:sodium" json:"sodium" form:"sodium"`
1714
+	Calcium                float64 `gorm:"column:calcium" json:"calcium" form:"calcium"`
1715
+	Remark                 string  `gorm:"column:remark" json:"remark" form:"remark"`
1716
+	Status                 int64   `gorm:"column:status" json:"status" form:"status"`
1717
+	Ultrafiltration        float64 `gorm:"column:ultrafiltration" json:"ultrafiltration"`
1718
+	DialysisDurationHour   int64   `gorm:"column:dialysis_duration_hour" json:"dialysis_duration_hour" form:"dialysis_duration_hour"`
1719
+	DialysisDurationMinute int64   `gorm:"column:dialysis_duration_minute" json:"dialysis_duration_minute" form:"dialysis_duration_minute"`
1720
+	TargetUltrafiltration  float64 `gorm:"column:target_ultrafiltration" json:"target_ultrafiltration" form:"target_ultrafiltration"`
1721
+	DialysisDialyszers     string  `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
1722
+	DialysisIrrigation     string  `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
1723
+	MaxUltrafiltrationRate float64 `gorm:"column:max_ultrafiltration_rate" json:"max_ultrafiltration_rate" form:"max_ultrafiltration_rate"`
1724
+	SolutionStatus         int64   `gorm:"column:solution_status" json:"solution_status" form:"solution_status"`
1725
+	DialysisRemark         string  `gorm:"column:dialysis_remark" json:"dialysis_remark" form:"dialysis_remark"`
1726
+	BloodAccess            int64   `gorm:"column:blood_access" json:"blood_access"`
1727
+}
1728
+
1729
+func (NewDialysisSolution) TableName() string {
1730
+	return "xt_dialysis_solution"
1731
+}

+ 32 - 0
models/schedule_models.go Целия файл

@@ -547,3 +547,35 @@ type VmBloodScheduleOne struct {
547 547
 func (VmBloodScheduleOne) TableName() string {
548 548
 	return "xt_schedule"
549 549
 }
550
+
551
+type VmNewSchedulesRemind struct {
552
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
553
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
554
+	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
555
+	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
556
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
557
+	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
558
+	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
559
+	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
560
+	ModeId       int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
561
+	Status       int64 `gorm:"column:status" json:"status" form:"status"`
562
+	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
563
+	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
564
+	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
565
+
566
+	DeviceZone                 DeviceZone                    `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
567
+	DeviceNumber               DeviceNumber                  `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
568
+	DialysisOrder              NewDialysisOrder              `json:"order" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
569
+	XtPatients                 XtNewPatients                 `json:"patient" gorm:"foreignkey:ID;AssociationForeignKey:PatientId;"`
570
+	DoctorAdvice               []*DoctorAdvice               `json:"doctoradvice" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
571
+	DialysisPrescription       DialysisPrescription          `json:"prescription" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
572
+	HisDoctorAdviceInfo        []*HisDoctorAdviceInfo        `json:"hisdoctoradviceinfo" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
573
+	DialysisSolution           NewDialysisSolution           `json:"dialysissolution" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId;"`
574
+	XtAssessmentBeforeDislysis XtNewAssessmentBeforeDislysis `json:"assessmentbefor" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
575
+	LastAfterWeight            NewAssessmentAfterDislysis    `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
576
+	XtDialysisOrderSix         XtDialysisOrderSix            `json:"dialysis_order" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
577
+}
578
+
579
+func (VmNewSchedulesRemind) TableName() string {
580
+	return "xt_schedule"
581
+}

+ 2 - 0
models/stock_models.go Целия файл

@@ -285,6 +285,7 @@ type WarehouseOutInfoNight struct {
285 285
 	SysRecordTime           int64                 `gorm:"column:sys_record_time" json:"sys_record_time"`
286 286
 	PatientId               int64                 `gorm:"column:patient_id" json:"patient_id"`
287 287
 	ProjectId               int64                 `gorm:"column:project_id" json:"project_id" form:"project_id"`
288
+	WarehouseOutId          int64                 `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
288 289
 	WarehouseInfotId        int64                 `gorm:"column:warehouse_info_id" json:"warehouse_info_id"`
289 290
 	IsSys                   int64                 `gorm:"column:is_sys" json:"is_sys"`
290 291
 	Status                  int64                 `gorm:"column:status" json:"status"`
@@ -1301,6 +1302,7 @@ type PatientWarehouseInfo struct {
1301 1302
 	SpecificationName string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
1302 1303
 	PackingUnit       string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
1303 1304
 	Remark            string `gorm:"column:remark" json:"remark" form:"remark"`
1305
+	OrgId             int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
1304 1306
 }
1305 1307
 
1306 1308
 func (PatientWarehouseInfo) TableName() string {

+ 6 - 0
service/dialysis_service.go Целия файл

@@ -2038,3 +2038,9 @@ func GetLastOrder(user_org_id int64, patient_id int64, dialysis_date int64) (mod
2038 2038
 
2039 2039
 	return twenty, err
2040 2040
 }
2041
+
2042
+func GetTodayInforMation(orgid int64, record_date int64) (list []*NewDeviceInformation, err error) {
2043
+
2044
+	err = UserReadDB().Where("user_org_id = ? and date = ? and status = 1", orgid, record_date).Find(&list).Error
2045
+	return list, err
2046
+}

+ 26 - 0
service/mobile_dialysis_service.go Целия файл

@@ -111,6 +111,7 @@ type MDialysisScheduleVM struct {
111 111
 	HisAdvices               []*VMHisDoctorAdviceInfo          `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
112 112
 	Advices                  []*VMDoctorAdvice                 `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
113 113
 	TreatmentSummary         *VMTreatmentSummary               `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
114
+	NewDeviceInformation     *NewDeviceInformation             `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
114 115
 }
115 116
 
116 117
 func (MDialysisScheduleVM) TableName() string {
@@ -355,6 +356,24 @@ func (VMAssessmentAfterDislysis) TableName() string {
355 356
 	return "xt_assessment_after_dislysis"
356 357
 }
357 358
 
359
+type NewDeviceInformation struct {
360
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
361
+	Date       int64  `gorm:"column:date" json:"date" form:"date"`
362
+	Class      int64  `gorm:"column:class" json:"class" form:"class"`
363
+	Zone       int64  `gorm:"column:zone" json:"zone" form:"zone"`
364
+	BedNumber  int64  `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
365
+	PatientId  int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
366
+	Status     int64  `gorm:"column:status" json:"status" form:"status"`
367
+	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
368
+	EquimentId int64  `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
369
+	Bed        string `gorm:"column:bed" json:"bed" form:"bed"`
370
+	Stime      int64  `gorm:"column:stime" json:"stime" form:"stime"`
371
+}
372
+
373
+func (NewDeviceInformation) TableName() string {
374
+	return "xt_device_information"
375
+}
376
+
358 377
 // 获取透析记录
359 378
 func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
360 379
 	var record models.DialysisOrder
@@ -5222,3 +5241,10 @@ func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int6
5222 5241
 
5223 5242
 	return order, err
5224 5243
 }
5244
+
5245
+func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
5246
+
5247
+	information := models.DeviceInformation{}
5248
+	err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
5249
+	return err
5250
+}

+ 34 - 0
service/new_stock_service.go Целия файл

@@ -145,6 +145,18 @@ func UpdateSumCount(user_org_id int64, storehouse_id int64, good_id int64, count
145 145
 	return err
146 146
 }
147 147
 
148
+func UpdateActSumCount(user_org_id int64, storehouse_id int64, good_id int64, count int64) error {
149
+	ut := XTWriteDB().Begin()
150
+
151
+	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 - ?", count)).Error
152
+	if err != nil {
153
+		ut.Rollback()
154
+		return err
155
+	}
156
+	ut.Commit()
157
+	return err
158
+}
159
+
148 160
 func GetSendGoodInformation(org_id int64) (info []*models.WarehousingInfo, err error) {
149 161
 
150 162
 	err = XTReadDB().Where("org_id = ? and is_check = 1 and status = 1", org_id).Find(&info).Error
@@ -514,3 +526,25 @@ func ReduceDrugStockCountSeven(storehouse_id int64, drug_id int64, user_org_id i
514 526
 	db.Commit()
515 527
 	return err
516 528
 }
529
+
530
+func GetWarehouseOutInfoByProjectIdList(project_id int64, org_id int64, storehouse_id int64, good_id int64, patient_id int64, sys_record_time int64) (info []*models.WarehouseOutInfoNight, err error) {
531
+
532
+	err = XTReadDB().Where("project_id = ? and org_id = ? and storehouse_id = ? and good_id = ? and patient_id = ? and sys_record_time = ?", project_id, org_id, storehouse_id, good_id, patient_id, sys_record_time).Find(&info).Error
533
+	return info, err
534
+}
535
+
536
+func GetWarehouseStockFlow(warehouse_info_id int64, good_id int64, user_org_id int64, patient_id int64, system_time int64) (models.VmStockFlow, error) {
537
+
538
+	stockFlow := models.VmStockFlow{}
539
+	err := XTReadDB().Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?", warehouse_info_id, good_id, user_org_id, patient_id, system_time).Find(&stockFlow).Error
540
+	return stockFlow, err
541
+}
542
+
543
+func AddCountFlowOne(warehouse_info_id int64, good_id int64, user_org_id int64, patient_id int64, count int64, system_time int64, over_count int64) error {
544
+
545
+	stockFlow := models.VmStockFlow{}
546
+	err := XTWriteDB().Model(&stockFlow).Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?", warehouse_info_id, good_id, user_org_id, patient_id, system_time).UpdateColumn("count", gorm.Expr("count + ?", count)).Error
547
+
548
+	err = XTWriteDB().Model(&stockFlow).Where("warehousing_detail_id = ? and good_id = ? and user_org_id = ? and patient_id = ? AND consumable_type = 7 and system_time = ?").Update(map[string]interface{}{"over_count": over_count}).Error
549
+	return err
550
+}

+ 18 - 14
service/new_warehouse_service.go Целия файл

@@ -2129,19 +2129,20 @@ func UpdateHisPrescriptionProjectStatus(project_id int64, record_time int64, use
2129 2129
 	return project, err
2130 2130
 }
2131 2131
 
2132
-// 药品自动出库 递归方式
2133
-func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo, prescribingCount float64) (err error) {
2132
+// 药品自动出库 递归方式  deliver_number_one已经转成最小数量
2133
+func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo, deliver_number_one int64) (err error) {
2134 2134
 
2135
+	fmt.Println("deliver_number_one -----------------------------------------", deliver_number_one)
2135 2136
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
2136 2137
 	var deliver_number int64 = 0
2137
-	var deliver_number_one int64 = 0
2138
+	//var deliver_number_one int64 = 0
2138 2139
 	var stock_number int64 = 0
2139 2140
 
2140 2141
 	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
2141 2142
 	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2142 2143
 
2143
-	prescribingCount_temp := strconv.FormatFloat(math.Abs(prescribingCount), 'f', 0, 64)
2144
-	prescribe_count, _ := strconv.ParseInt(prescribingCount_temp, 10, 64)
2144
+	//prescribingCount_temp := strconv.FormatFloat(math.Abs(prescribingCount), 'f', 0, 64)
2145
+	//prescribe_count, _ := strconv.ParseInt(prescribingCount_temp, 10, 64)
2145 2146
 
2146 2147
 	var drug_price float64
2147 2148
 	if advice.PrescribingNumberUnit == drup.MaxUnit {
@@ -2152,13 +2153,13 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2152 2153
 
2153 2154
 	}
2154 2155
 
2155
-	if advice.PrescribingNumberUnit == drup.MaxUnit {
2156
-		deliver_number_one = prescribe_count * drup.MinNumber
2157
-
2158
-	} else {
2159
-		deliver_number_one = prescribe_count
2160
-
2161
-	}
2156
+	//if advice.PrescribingNumberUnit == drup.MaxUnit {
2157
+	//	deliver_number_one = prescribe_count * drup.MinNumber
2158
+	//
2159
+	//} else {
2160
+	//	deliver_number_one = prescribe_count
2161
+	//
2162
+	//}
2162 2163
 
2163 2164
 	if advice.PrescribingNumberUnit == drup.MaxUnit {
2164 2165
 		drug_price = drup.RetailPrice
@@ -2427,7 +2428,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2427 2428
 			cancel_count += item.Count
2428 2429
 		}
2429 2430
 
2430
-		fmt.Println("deliver_number_one", deliver_number)
2431
+		fmt.Println("deliver_number_one", deliver_number_one)
2431 2432
 		fmt.Println("out_count", out_count)
2432 2433
 		fmt.Println("cancel_count", cancel_count)
2433 2434
 		//如果本次出库数据大于历史出库数据 新增1条流水
@@ -2509,6 +2510,9 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2509 2510
 
2510 2511
 		}
2511 2512
 
2513
+		fmt.Println("出库数据", deliver_number_one)
2514
+		fmt.Println("马文强out_count233232232ooqw", out_count)
2515
+		fmt.Println("马cancel_count33232232ooqw", cancel_count)
2512 2516
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
2513 2517
 		if deliver_number_one < (out_count - cancel_count) {
2514 2518
 
@@ -2953,7 +2957,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2953 2957
 		advice.PrescribingNumberUnit = drup.MinUnit
2954 2958
 		fmt.Println("剩余库存9999999233232", overPlusNumber)
2955 2959
 
2956
-		HisSettleDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice, prescribingCount)
2960
+		HisSettleDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice, deliver_number_one)
2957 2961
 	}
2958 2962
 
2959 2963
 	return

+ 46 - 4
service/stock_service.go Целия файл

@@ -5080,6 +5080,12 @@ func GetStockFlowIsBatchNumberSix(patient_id int64, record_time int64, good_id i
5080 5080
 	return flow, nil
5081 5081
 }
5082 5082
 
5083
+func GetStockFlowIsBatchNumberSixty(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.WarehouseOutInfo, err error) {
5084
+
5085
+	err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
5086
+	return flow, nil
5087
+}
5088
+
5083 5089
 func GetStockFlowIsBatchNumberTwo(patient_id int64, record_time int64, good_id int64) (flow []*models.WarehouseOutInfo, err error) {
5084 5090
 
5085 5091
 	err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 ", patient_id, record_time, good_id).Find(&flow).Error
@@ -5098,6 +5104,12 @@ func GetStockFlowIsBatchNumberFour(patient_id int64, record_time int64, good_id
5098 5104
 	return flow, nil
5099 5105
 }
5100 5106
 
5107
+func GetStockFlowIsBatchNumberFourty(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.VmStockFlow, err error) {
5108
+
5109
+	err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type =7 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
5110
+	return flow, nil
5111
+}
5112
+
5101 5113
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
5102 5114
 
5103 5115
 	info := models.WarehouseOutInfo{}
@@ -5223,10 +5235,10 @@ func UpdatedWarehouseOutInfo(info *models.WarehouseOutInfo, good_id int64, patie
5223 5235
 	return err
5224 5236
 }
5225 5237
 
5226
-func UpdatedWarehouseOutInfoTwo(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64) error {
5238
+func UpdatedWarehouseOutInfoSix(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64) error {
5227 5239
 
5228 5240
 	outInfo := models.WarehouseOutInfo{}
5229
-	err := XTWriteDB().Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", good_id, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber}).Error
5241
+	err := XTWriteDB().Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1 and project_id = ? and warehouse_info_id =? ", good_id, patient_id, record_time, project_id, warehouse_info_id).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber, "over_count": info.OverCount}).Error
5230 5242
 	return err
5231 5243
 }
5232 5244
 
@@ -6930,6 +6942,13 @@ func GetAutoStockOutById(good_id, record_date int64, orgid int64, patient_id int
6930 6942
 	return detail, err
6931 6943
 }
6932 6944
 
6945
+func GetAutoWarehouseOutList(good_id, record_date int64, orgid int64, patient_id int64) (models.WarehouseOutInfoNight, error) {
6946
+
6947
+	detail := models.WarehouseOutInfoNight{}
6948
+	err := XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ?", good_id, record_date, orgid, patient_id).Find(&detail).Error
6949
+	return detail, err
6950
+}
6951
+
6933 6952
 func GetAdviceConfig(orgid int64) (*models.XtAdviceSetting, error) {
6934 6953
 
6935 6954
 	setting := models.XtAdviceSetting{}
@@ -7351,6 +7370,23 @@ func UpdateWarehouseInfoByIdList(count int64, id int64) error {
7351 7370
 	return err
7352 7371
 }
7353 7372
 
7373
+func UpdateWarehouseInfoByIdListThree(count int64, id int64) error {
7374
+
7375
+	tx := XTWriteDB().Begin()
7376
+	err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"stock_count": count}).Error
7377
+	if err != nil {
7378
+		tx.Rollback()
7379
+		return err
7380
+	}
7381
+	err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
7382
+	if err != nil {
7383
+		tx.Rollback()
7384
+		return err
7385
+	}
7386
+	tx.Commit()
7387
+	return err
7388
+}
7389
+
7354 7390
 func ReturnCheckWarehouseInfo(id int64) error {
7355 7391
 
7356 7392
 	tx := XTWriteDB().Begin()
@@ -8367,11 +8403,17 @@ func GetWarehouseOutInfoIsExistThree(good_id int64, patient_id int64, record_tim
8367 8403
 	return info, err
8368 8404
 }
8369 8405
 
8370
-func GetWarehouseOutInfoIsExistSix(good_id int64, patient_id int64, record_time int64, project_id int64) (*models.WarehouseOutInfo, error) {
8406
+func GetWarehouseOutInfoIsExistTen(good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64) (models.WarehouseOutInfo, error) {
8407
+	info := models.WarehouseOutInfo{}
8408
+	err := XTReadDB().Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ? and warehouse_info_id = ?", good_id, record_time, patient_id, project_id, warehouse_info_id).Find(&info).Error
8409
+	return info, err
8410
+}
8411
+
8412
+func GetNewWarehouseOutInfoIsExistSix(good_id int64, patient_id int64, record_time int64, project_id int64, warehouse_info_id int64) (*models.WarehouseOutInfo, error) {
8371 8413
 
8372 8414
 	info := models.WarehouseOutInfo{}
8373 8415
 	var err error
8374
-	err = XTReadDB().Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ?", good_id, record_time, patient_id, project_id).Find(&info).Error
8416
+	err = XTReadDB().Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ? and warehouse_info_id = ?", good_id, record_time, patient_id, project_id, warehouse_info_id).Find(&info).Error
8375 8417
 	if err == gorm.ErrRecordNotFound {
8376 8418
 		return nil, err
8377 8419
 	}

+ 166 - 131
service/warhouse_service.go Целия файл

@@ -9878,6 +9878,24 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
9878 9878
 
9879 9879
 	stock_number = warehouse.StockCount
9880 9880
 
9881
+	maxNumber = goods.Count
9882
+
9883
+	if warehouse.StockCount < maxNumber {
9884
+		return errors.New("库存数量不足")
9885
+	}
9886
+
9887
+	warehouse.StockCount = warehouse.StockCount - maxNumber
9888
+	warehouse.Mtime = time.Now().Unix()
9889
+
9890
+	//扣减库存
9891
+	errThree := UpDateWarehouseInfoByStock(&warehouse)
9892
+
9893
+	//查询剩余库存
9894
+	goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
9895
+	var sum_count int64
9896
+	for _, item := range goodList {
9897
+		sum_count += item.StockCount
9898
+	}
9881 9899
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
9882 9900
 	if stock_number >= deliver_number {
9883 9901
 
@@ -9905,6 +9923,7 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
9905 9923
 			StorehouseId:            goods.StorehouseId,
9906 9924
 			SecondWarehouseInfoId:   goods.SecondWarehouseInfoId,
9907 9925
 			IsCheck:                 1,
9926
+			OverCount:               sum_count,
9908 9927
 		}
9909 9928
 
9910 9929
 		warehouseOutInfo.Count = goods.Count
@@ -9947,23 +9966,12 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
9947 9966
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
9948 9967
 			StorehouseId:            warehouse.StorehouseId,
9949 9968
 			SecondWarehouseInfoId:   goods.SecondWarehouseInfoId,
9969
+			OverCount:               sum_count,
9950 9970
 		}
9951 9971
 
9952 9972
 		//创建出库流水
9953 9973
 		CreateStockFlowOne(stockFlow)
9954 9974
 
9955
-		maxNumber = goods.Count
9956
-
9957
-		if warehouse.StockCount < maxNumber {
9958
-			return errors.New("库存数量不足")
9959
-		}
9960
-
9961
-		warehouse.StockCount = warehouse.StockCount - maxNumber
9962
-		warehouse.Mtime = time.Now().Unix()
9963
-
9964
-		//扣减库存
9965
-		errThree := UpDateWarehouseInfoByStock(&warehouse)
9966
-
9967 9975
 		//入库
9968 9976
 		warehouseInfo := &models.WarehousingInfo{
9969 9977
 			WarehousingOrder:      warehouseInfo.WarehousingOrder,
@@ -10037,6 +10045,24 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
10037 10045
 
10038 10046
 	} else {
10039 10047
 
10048
+		// 出库完成后,要将该批次库存清零
10049
+		warehouse.StockCount = 0
10050
+		warehouse.Mtime = time.Now().Unix()
10051
+
10052
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
10053
+
10054
+		if errThree != nil {
10055
+			return errThree
10056
+		}
10057
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
10058
+		goods.Count = deliver_number - stock_number
10059
+
10060
+		//查询剩余库存
10061
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
10062
+		var sum_count int64
10063
+		for _, item := range goodList {
10064
+			sum_count += item.StockCount
10065
+		}
10040 10066
 		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
10041 10067
 		warehouseOutInfo := &models.WarehouseOutInfo{
10042 10068
 			WarehouseOutOrderNumber: goods.WarehouseOutOrderNumber,
@@ -10062,6 +10088,7 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
10062 10088
 			StorehouseId:            warehouse.StorehouseId,
10063 10089
 			SecondWarehouseInfoId:   goods.SecondWarehouseInfoId,
10064 10090
 			IsCheck:                 1,
10091
+			OverCount:               sum_count,
10065 10092
 		}
10066 10093
 		warehouseOutInfo.Count = warehouse.StockCount
10067 10094
 
@@ -10112,6 +10139,7 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
10112 10139
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
10113 10140
 			StorehouseId:            goods.StorehouseId,
10114 10141
 			SecondWarehouseInfoId:   goods.SecondWarehouseInfoId,
10142
+			OverCount:               sum_count,
10115 10143
 		}
10116 10144
 
10117 10145
 		//创建出库明细
@@ -10183,17 +10211,6 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
10183 10211
 
10184 10212
 		//创建出库流水
10185 10213
 		CreateStockFlowOne(stockInfoFlow)
10186
-		// 出库完成后,要将该批次库存清零
10187
-		warehouse.StockCount = 0
10188
-		warehouse.Mtime = time.Now().Unix()
10189
-
10190
-		errThree := UpDateWarehouseInfoByStock(&warehouse)
10191
-
10192
-		if errThree != nil {
10193
-			return errThree
10194
-		}
10195
-		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
10196
-		goods.Count = deliver_number - stock_number
10197 10214
 
10198 10215
 		ConsumablesDeliveryTwelve(orgID, record_time, goods, warehouseOut, count, creator, warehouseInfo)
10199 10216
 
@@ -10210,7 +10227,6 @@ func AddWarehosingInfo(info *models.WarehousingInfo) error {
10210 10227
 // 药品出库 递归方式
10211 10228
 func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo, drugWarehouse *models.DrugWarehouseInfo) (err error) {
10212 10229
 
10213
-	fmt.Println("尽力2333223333233323322332")
10214 10230
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
10215 10231
 	var deliver_number int64 = 0
10216 10232
 	var stock_number int64 = 0
@@ -10250,6 +10266,62 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10250 10266
 
10251 10267
 	fmt.Println("stock23233233232", stock_number)
10252 10268
 	fmt.Println("deliver_number", deliver_number)
10269
+
10270
+	// 出库完成后,要减去对应批次的库存数量
10271
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是拆零单位,则根据规格,将拆零数量转为包装数量
10272
+	var maxNumber int64 = 0
10273
+	var minNumber int64 = 0
10274
+	if advice.CountUnit == drup.MinUnit {
10275
+		maxNumber = prescribingNumber / drup.MinNumber
10276
+		minNumber = prescribingNumber % drup.MinNumber
10277
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
10278
+			minNumber = maxNumber
10279
+		}
10280
+	} else {
10281
+		maxNumber = prescribingNumber
10282
+	}
10283
+
10284
+	//fmt.Println("warehouse.StockMaxNumber",warehouse.StockMaxNumber)
10285
+	//fmt.Println("maxNumber9899923323232wo",maxNumber)
10286
+	if warehouse.StockMaxNumber < maxNumber {
10287
+
10288
+		return errors.New("库存数量不足")
10289
+	}
10290
+
10291
+	warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
10292
+	warehouse.Mtime = time.Now().Unix()
10293
+
10294
+	if warehouse.StockMinNumber < minNumber {
10295
+		warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
10296
+		warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
10297
+	} else {
10298
+		warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
10299
+	}
10300
+
10301
+	if warehouse.StockMaxNumber == 1 && warehouse.StockMinNumber == 1 && drup.MaxUnit == drup.MinUnit {
10302
+		warehouse.StockMinNumber = 0
10303
+	}
10304
+
10305
+	if warehouse.StockMaxNumber < 0 {
10306
+		return errors.New("库存数量不足")
10307
+	}
10308
+
10309
+	errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
10310
+
10311
+	if errThree != nil {
10312
+		return errThree
10313
+	}
10314
+
10315
+	//查询剩余库存
10316
+	stockInfo, _ := GetDrugAllStockInfo(advice.StorehouseId, orgID, advice.DrugId)
10317
+	var sum_count int64
10318
+	for _, its := range stockInfo {
10319
+		if its.MaxUnit == drup.MaxUnit {
10320
+			its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
10321
+		}
10322
+		sum_count += its.StockMaxNumber + its.StockMinNumber
10323
+	}
10324
+
10253 10325
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
10254 10326
 	if stock_number >= deliver_number {
10255 10327
 
@@ -10280,6 +10352,7 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10280 10352
 			StorehouseId:            advice.StorehouseId,
10281 10353
 			SecondWarehouseInfoId:   advice.SecondWarehouseInfoId,
10282 10354
 			IsCheck:                 1,
10355
+			OverCount:               sum_count,
10283 10356
 		}
10284 10357
 
10285 10358
 		warehouseOutInfo.Count = prescribingNumber
@@ -10317,54 +10390,10 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10317 10390
 			StorehouseId:            advice.StorehouseId,
10318 10391
 			SecondWarehouseInfoId:   advice.SecondWarehouseInfoId,
10319 10392
 			WarehousingDetailId:     warehouse.ID,
10393
+			OverCount:               sum_count,
10320 10394
 		}
10321 10395
 
10322 10396
 		CreateDrugFlowOne(drugflow)
10323
-		// 出库完成后,要减去对应批次的库存数量
10324
-		// 判断处方里药品单位是拆零单位还是包装单位,	如果是拆零单位,则根据规格,将拆零数量转为包装数量
10325
-		var maxNumber int64 = 0
10326
-		var minNumber int64 = 0
10327
-		if advice.CountUnit == drup.MinUnit {
10328
-			maxNumber = prescribingNumber / drup.MinNumber
10329
-			minNumber = prescribingNumber % drup.MinNumber
10330
-			if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
10331
-				minNumber = maxNumber
10332
-			}
10333
-		} else {
10334
-			maxNumber = prescribingNumber
10335
-		}
10336
-
10337
-		//fmt.Println("warehouse.StockMaxNumber",warehouse.StockMaxNumber)
10338
-		//fmt.Println("maxNumber9899923323232wo",maxNumber)
10339
-		if warehouse.StockMaxNumber < maxNumber {
10340
-
10341
-			return errors.New("库存数量不足")
10342
-		}
10343
-
10344
-		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
10345
-		warehouse.Mtime = time.Now().Unix()
10346
-
10347
-		if warehouse.StockMinNumber < minNumber {
10348
-			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
10349
-			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
10350
-		} else {
10351
-			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
10352
-		}
10353
-
10354
-		if warehouse.StockMaxNumber == 1 && warehouse.StockMinNumber == 1 && drup.MaxUnit == drup.MinUnit {
10355
-			warehouse.StockMinNumber = 0
10356
-		}
10357
-
10358
-		fmt.Println("warehouse.StockMaxNumber323232323233232332", warehouse.StockMaxNumber)
10359
-		if warehouse.StockMaxNumber < 0 {
10360
-			return errors.New("库存数量不足")
10361
-		}
10362
-
10363
-		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
10364
-
10365
-		if errThree != nil {
10366
-			return errThree
10367
-		}
10368 10397
 
10369 10398
 		//入库
10370 10399
 		drugInfo := models.DrugWarehouseInfo{
@@ -10439,6 +10468,31 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10439 10468
 
10440 10469
 		return nil
10441 10470
 	} else {
10471
+
10472
+		warehouse.StockMaxNumber = 0
10473
+		warehouse.StockMinNumber = 0
10474
+		warehouse.Mtime = time.Now().Unix()
10475
+
10476
+		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
10477
+		if errThree != nil {
10478
+			return errThree
10479
+		}
10480
+
10481
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
10482
+		prescribingNumber_two_temp := deliver_number - stock_number
10483
+
10484
+		advice.CountUnit = drup.MinUnit
10485
+
10486
+		//查询剩余库存
10487
+		stockInfo, _ := GetDrugAllStockInfo(advice.StorehouseId, orgID, advice.DrugId)
10488
+		var sum_count int64
10489
+		for _, its := range stockInfo {
10490
+			if its.MaxUnit == drup.MaxUnit {
10491
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
10492
+			}
10493
+			sum_count += its.StockMaxNumber + its.StockMinNumber
10494
+		}
10495
+
10442 10496
 		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
10443 10497
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
10444 10498
 			WarehouseOutOrderNumber: advice.WarehouseOutOrderNumber,
@@ -10467,6 +10521,7 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10467 10521
 			StorehouseId:            advice.StorehouseId,
10468 10522
 			SecondWarehouseInfoId:   advice.SecondWarehouseInfoId,
10469 10523
 			IsCheck:                 1,
10524
+			OverCount:               sum_count,
10470 10525
 		}
10471 10526
 		warehouseOutInfo.Count = stock_number
10472 10527
 
@@ -10503,6 +10558,7 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10503 10558
 			StorehouseId:            advice.StorehouseId,
10504 10559
 			SecondWarehouseInfoId:   advice.SecondWarehouseInfoId,
10505 10560
 			WarehousingDetailId:     warehouse.ID,
10561
+			OverCount:               sum_count,
10506 10562
 		}
10507 10563
 		CreateDrugFlowOne(drugflow)
10508 10564
 		// 出库完成后,要将该批次库存清零
@@ -10574,24 +10630,11 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10574 10630
 			StockMinNumber:          stock_number,
10575 10631
 			StorehouseId:            drugWarehouse.StorehouseId,
10576 10632
 			SecondWarehouseInfoId:   drugWarehouse.SecondWarehouseInfoId,
10633
+			OverCount:               sum_count,
10577 10634
 		}
10578 10635
 
10579 10636
 		CreateDrugFlowOne(flow)
10580 10637
 
10581
-		warehouse.StockMaxNumber = 0
10582
-		warehouse.StockMinNumber = 0
10583
-		warehouse.Mtime = time.Now().Unix()
10584
-
10585
-		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
10586
-		if errThree != nil {
10587
-			return errThree
10588
-		}
10589
-
10590
-		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
10591
-		prescribingNumber_two_temp := deliver_number - stock_number
10592
-
10593
-		advice.CountUnit = drup.MinUnit
10594
-
10595 10638
 		AutoDrugDeliverInfoTwelve(orgID, prescribingNumber_two_temp, warehouseout, drup, advice, drugWarehouse)
10596 10639
 	}
10597 10640
 
@@ -12219,7 +12262,20 @@ func HisSettleDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctor
12219 12262
 		if drup.ID > 0 {
12220 12263
 			prescribingNumber := advice.PrescribingNumber
12221 12264
 
12222
-			HisSettleDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber)
12265
+			var prescribingNumberOne int64
12266
+			prescribingCount_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
12267
+			prescribe_count, _ := strconv.ParseInt(prescribingCount_temp, 10, 64)
12268
+			if advice.PrescribingNumberUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
12269
+				prescribingNumberOne = prescribe_count * drup.MinNumber
12270
+			}
12271
+			if advice.PrescribingNumberUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
12272
+				prescribingNumberOne = prescribe_count
12273
+			}
12274
+			if advice.PrescribingNumberUnit == drup.MinUnit && drup.MaxUnit == drup.MinUnit {
12275
+				prescribingNumberOne = prescribe_count
12276
+			}
12277
+
12278
+			HisSettleDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumberOne)
12223 12279
 
12224 12280
 		} else {
12225 12281
 			return errors.New("药品信息不存在")
@@ -12395,6 +12451,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12395 12451
 			OverCount:               sum_count,
12396 12452
 			RegisterNumber:          warehouse.RegisterNumber,
12397 12453
 			OrderId:                 order_id,
12454
+			ProjectId:               goods.ProjectId,
12398 12455
 		}
12399 12456
 		//创建出库流水
12400 12457
 		errflow := CreateStockFlowOne(stockFlow)
@@ -12577,6 +12634,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12577 12634
 			OverCount:               sum_count,
12578 12635
 			RegisterNumber:          warehouse.RegisterNumber,
12579 12636
 			OrderId:                 order_id,
12637
+			ProjectId:               goods.ProjectId,
12580 12638
 		}
12581 12639
 		//创建出库流水
12582 12640
 		errflow := CreateStockFlowOne(stockFlow)
@@ -12723,28 +12781,19 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12723 12781
 			sum_count += item.StockCount
12724 12782
 		}
12725 12783
 
12726
-		warehouseOutInfo := &models.WarehouseOutInfo{
12727
-			WarehouseInfotId: warehouse.ID,
12728
-		}
12729
-		//添加入库单详情ID
12730
-		errOne := UpdatedSigleWarehouseOutInfo(goods.ID, warehouseOutInfo)
12731
-		if errOne != nil {
12732
-			goodErrcode := models.XtGoodErrcode{
12733
-				UserOrgId:      goods.UserOrgId,
12734
-				Errcode:        "添加入库单详情ID",
12735
-				GoodId:         goods.GoodId,
12736
-				Status:         1,
12737
-				Ctime:          time.Now().Unix(),
12738
-				Mtime:          0,
12739
-				Count:          0,
12740
-				StockCount:     0,
12741
-				Creater:        creator,
12742
-				BatchNumberId:  warehouse.ID,
12743
-				WarehouseOutId: 0,
12744
-			}
12745
-			CreateGoodErrcode(goodErrcode)
12746
-			return errOne
12784
+		flowGood, _ := GetStockFlowIsBatchNumberSixty(patient_id, record_time, goods.GoodId, goods.ProjectId)
12785
+
12786
+		var out_count int64
12787
+		var out_count_one int64
12788
+		for _, item := range flowGood {
12789
+			out_count += item.Count
12747 12790
 		}
12791
+
12792
+		//查询退库数据
12793
+		//flowGoodTwo, _ := GetStockFlowIsBatchNumberFourty(patient_id, record_time, goods.GoodId, goods.ProjectId)
12794
+		//for _, item := range flowGoodTwo {
12795
+		//  out_count_one += item.Count
12796
+		//}
12748 12797
 		OutInfo := &models.WarehouseOutInfo{
12749 12798
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
12750 12799
 			WarehouseOutId:          warehouseOut.ID,
@@ -12773,17 +12822,15 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12773 12822
 			OverCount:               sum_count,
12774 12823
 			RegisterNumber:          warehouse.RegisterNumber,
12775 12824
 		}
12776
-		fmt.Println("goods.count2323232233232233232322332322332", goods.Count)
12777
-		OutInfo.Count = count
12825
+		OutInfo.Count = count - out_count + out_count_one
12778 12826
 
12779
-		_, errcodes := GetWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId)
12827
+		_, errcodes := GetNewWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID)
12780 12828
 		if errcodes == gorm.ErrRecordNotFound {
12781 12829
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
12782 12830
 			if errOne != nil {
12783 12831
 				return errOne
12784 12832
 			}
12785 12833
 		} else if errcodes == nil {
12786
-
12787 12834
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
12788 12835
 			if count != outInfoOne.Count {
12789 12836
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
@@ -12792,20 +12839,6 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12792 12839
 		}
12793 12840
 
12794 12841
 		lastOut, _ := FindWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId)
12795
-		//查询已经出库的数据
12796
-		flowGood, _ := GetStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId)
12797
-		fmt.Println("flowgood23323223323222323wo", flowGood)
12798
-		var out_count int64
12799
-		var out_count_one int64
12800
-		for _, item := range flowGood {
12801
-			out_count += item.Count
12802
-		}
12803
-
12804
-		//查询退库数据
12805
-		flowGoodTwo, _ := GetStockFlowIsBatchNumberFour(patient_id, record_time, goods.GoodId, goods.ProjectId)
12806
-		for _, item := range flowGoodTwo {
12807
-			out_count_one += item.Count
12808
-		}
12809 12842
 
12810 12843
 		//如果本次出库数据大于历史出库数据 新增1条流水
12811 12844
 		fmt.Println("out_count23323233232wo", out_count)
@@ -13108,7 +13141,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13108 13141
 		}
13109 13142
 		OutInfo.Count = stock_number
13110 13143
 
13111
-		_, errcodes := GetWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId)
13144
+		_, errcodes := GetNewWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID)
13112 13145
 		if errcodes == gorm.ErrRecordNotFound {
13113 13146
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
13114 13147
 			if errOne != nil {
@@ -13116,25 +13149,27 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13116 13149
 			}
13117 13150
 		} else if errcodes == nil {
13118 13151
 
13119
-			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
13152
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTen(goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID)
13120 13153
 			if count != outInfoOne.Count {
13121
-				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
13154
+				UpdatedWarehouseOutInfoSix(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId, warehouse.ID)
13122 13155
 			}
13123 13156
 
13124 13157
 		}
13125 13158
 
13126 13159
 		lastOut, _ := FindWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId)
13127 13160
 		//查询该该批次已经出库的数据
13128
-		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
13161
+		//flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
13162
+		//查询已经出库的数据
13163
+		flowGood, _ := GetStockFlowIsBatchNumberSixty(patient_id, record_time, goods.GoodId, goods.ProjectId)
13129 13164
 		var out_count int64
13130 13165
 		var out_count_one int64
13131 13166
 		for _, item := range flowGood {
13132 13167
 			out_count += item.Count
13133 13168
 		}
13134
-		flowGoodTwo, _ := GetStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId)
13135
-		for _, item := range flowGoodTwo {
13136
-			out_count_one += item.Count
13137
-		}
13169
+		//flowGoodTwo, _ := GetStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId)
13170
+		//for _, item := range flowGoodTwo {
13171
+		//	out_count_one += item.Count
13172
+		//}
13138 13173
 		fmt.Println("出库数量", stock_number)
13139 13174
 		fmt.Println("历史出库数据", out_count-out_count_one)
13140 13175
 		//如果出库数量 大于 历史出库数据 新增1条流水