瀏覽代碼

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

test_user 1 年之前
父節點
當前提交
5829ad1949

+ 0 - 1
.idea/vcs.xml 查看文件

@@ -7,6 +7,5 @@
7 7
   </component>
8 8
   <component name="VcsDirectoryMappings">
9 9
     <mapping directory="$PROJECT_DIR$" vcs="Git" />
10
-    <mapping directory="$PROJECT_DIR$/src/golang.org/x/sync" vcs="Git" />
11 10
   </component>
12 11
 </project>

+ 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
 

+ 1 - 1
controllers/data_api_controller.go 查看文件

@@ -400,7 +400,7 @@ func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
400 400
 	}
401 401
 	dataconfig.Module = module
402 402
 
403
-	if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" || module == "admitting_diagnosis" || module == "discharge_diagnosis" || module == "diagnosis_admission" || module == "treatment" || module == "illness_discharge" || module == "discharge_advice" {
403
+	if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" || module == "admitting_diagnosis" || module == "discharge_diagnosis" || module == "diagnosis_admission" || module == "treatment" || module == "illness_discharge" || module == "discharge_advice" || module == "dialysis_remark" {
404 404
 		if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
405 405
 			utils.ErrorLog("title")
406 406
 			code = enums.ErrorCodeParamWrong

+ 59 - 9
controllers/dialysis_api_controller.go 查看文件

@@ -107,6 +107,8 @@ func DialysisApiRegistRouters() {
107 107
 	beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
108 108
 
109 109
 	beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
110
+
111
+	beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
110 112
 }
111 113
 
112 114
 func (c *DialysisApiController) GetQueueCall() {
@@ -321,6 +323,7 @@ func (c *DialysisApiController) PostPrescription() {
321 323
 	water_machine := c.GetString("water_machine")
322 324
 	add_amount, _ := c.GetFloat("add_amount")
323 325
 	reduce_amount, _ := c.GetFloat("reduce_amount")
326
+	dialysis_remark := c.GetString("dialysis_remark")
324 327
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
325 328
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
326 329
 
@@ -428,6 +431,7 @@ func (c *DialysisApiController) PostPrescription() {
428 431
 		WaterMachine:               water_machine,
429 432
 		AddAmount:                  add_amount,
430 433
 		ReduceAmount:               reduce_amount,
434
+		DialysisRemark:             dialysis_remark,
431 435
 	}
432 436
 
433 437
 	if appRole.UserType == 2 || appRole.UserType == 1 {
@@ -659,6 +663,7 @@ func (c *DialysisApiController) PostSoulution() {
659 663
 	water_machine := c.GetString("water_machine")
660 664
 	add_amount, _ := c.GetFloat("add_amount")
661 665
 	reduce_amount, _ := c.GetFloat("reduce_amount")
666
+	dialysis_remark := c.GetString("dialysis_remark")
662 667
 	var prescription_doctor int64
663 668
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
664 669
 
@@ -778,6 +783,7 @@ func (c *DialysisApiController) PostSoulution() {
778 783
 		WaterMachine:               water_machine,
779 784
 		AddAmount:                  add_amount,
780 785
 		ReduceAmount:               reduce_amount,
786
+		DialysisRemark:             dialysis_remark,
781 787
 	}
782 788
 
783 789
 	//查询最近透析准备表里是否存在 透析器 灌流器
@@ -948,6 +954,7 @@ func (c *DialysisApiController) PostSoulution() {
948 954
 		OxygenTime:                 oxygen_time,
949 955
 		PreImpulse:                 preImpules,
950 956
 		SolutionStatus:             1,
957
+		DialysisRemark:             dialysis_remark,
951 958
 	}
952 959
 
953 960
 	//针对河间咸得
@@ -2955,13 +2962,22 @@ func (c *DialysisApiController) GetDialysisOrder() {
2955 2962
 
2956 2963
 	check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2957 2964
 
2958
-	if adminUserInfo.CurrentOrgId != 10101 {
2965
+	if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 {
2959 2966
 		dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2960 2967
 		patientInfo.TotalDialysis = dialysis_count
2961 2968
 	}
2962
-	if adminUserInfo.CurrentOrgId == 10101 {
2963
-		dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2964
-		patientInfo.TotalDialysis = dialysis_count
2969
+	if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 {
2970
+
2971
+		if xttime <= 1640966400 {
2972
+			dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2973
+			patientInfo.TotalDialysis = dialysis_count
2974
+		}
2975
+
2976
+		if xttime >= 1672502400 {
2977
+			dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2978
+			patientInfo.TotalDialysis = dialysis_count
2979
+		}
2980
+
2965 2981
 	}
2966 2982
 
2967 2983
 	//相关操作对应的操作人
@@ -4805,7 +4821,8 @@ func (this *DialysisApiController) ExcutionDoctorAdvice() {
4805 4821
 					prescribing_number = parseIntPrescribingNumber
4806 4822
 				}
4807 4823
 				sum_out_count += prescribing_number
4808
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId)
4824
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
4825
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
4809 4826
 				//库存不足
4810 4827
 				if sum_out_count > drugStockOut.FlushCount {
4811 4828
 					this.ServeSuccessJSON(map[string]interface{}{
@@ -4952,7 +4969,8 @@ func (this *DialysisApiController) ExcutionDoctorAdvice() {
4952 4969
 					prescribing_number = parseIntPrescribingNumber
4953 4970
 				}
4954 4971
 				sum_out_count += prescribing_number
4955
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId)
4972
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
4973
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
4956 4974
 				//库存不足
4957 4975
 				if sum_out_count > drugStockOut.FlushCount {
4958 4976
 					this.ServeSuccessJSON(map[string]interface{}{
@@ -5209,8 +5227,8 @@ func (this *DialysisApiController) ExcutionDoctorAdviceById() {
5209 5227
 		if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5210 5228
 			prescribing_number = parseIntPrescribingNumber
5211 5229
 		}
5212
-
5213
-		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId)
5230
+		houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
5231
+		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
5214 5232
 		//库存不足
5215 5233
 		if prescribing_number > drugStockOut.FlushCount {
5216 5234
 			this.ServeSuccessJSON(map[string]interface{}{
@@ -5349,7 +5367,8 @@ func (this *DialysisApiController) ExcutionDoctorAdviceById() {
5349 5367
 		if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5350 5368
 			prescribing_number = parseIntPrescribingNumber
5351 5369
 		}
5352
-		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId)
5370
+		houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
5371
+		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
5353 5372
 		//库存不足
5354 5373
 		if prescribing_number > drugStockOut.FlushCount {
5355 5374
 			this.ServeSuccessJSON(map[string]interface{}{
@@ -5442,3 +5461,34 @@ func (this *DialysisApiController) ExcutionDoctorAdviceById() {
5442 5461
 	return
5443 5462
 
5444 5463
 }
5464
+
5465
+func (this *DialysisApiController) GetDialysisAdviceToday() {
5466
+
5467
+	orgId := this.GetAdminUserInfo().CurrentOrgId
5468
+
5469
+	schedule_type, _ := this.GetInt64("schedule_type")
5470
+
5471
+	partion_type, _ := this.GetInt64("partion_type")
5472
+
5473
+	start_time := this.GetString("selected_date")
5474
+	timeLayout := "2006-01-02"
5475
+	loc, _ := time.LoadLocation("Local")
5476
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
5477
+
5478
+	list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, partion_type, startTime.Unix())
5479
+
5480
+	drug, _ := service.GetAllBaseDrugListTwenty(orgId)
5481
+	_, config := service.FindXTHisRecordByOrgId(orgId)
5482
+	if err == nil {
5483
+		this.ServeSuccessJSON(map[string]interface{}{
5484
+			"list":   list,
5485
+			"drug":   drug,
5486
+			"config": config,
5487
+		})
5488
+		return
5489
+
5490
+	} else {
5491
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
5492
+		return
5493
+	}
5494
+}

+ 18 - 0
controllers/dialysis_record_api_controller.go 查看文件

@@ -1009,6 +1009,24 @@ func (this *DialysisRecordAPIController) StartDialysis() {
1009 1009
 	createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
1010 1010
 	//更新患者表排班备注
1011 1011
 	service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, patientID, schedule_remark)
1012
+
1013
+	////统计该患者总次数
1014
+	//dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
1015
+	//
1016
+	//service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
1017
+
1018
+	if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 3877 {
1019
+		//统计该患者总次数
1020
+		dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
1021
+		service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
1022
+	}
1023
+
1024
+	if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 3877 {
1025
+		//统计该患者总次数
1026
+		dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.CurrentOrgId, patientID)
1027
+		service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
1028
+	}
1029
+
1012 1030
 	key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
1013 1031
 	redis := service.RedisClient()
1014 1032
 	//清空key 值

+ 1 - 1
controllers/gobal_config_api_controller.go 查看文件

@@ -2231,7 +2231,7 @@ func (c *GobalConfigApiController) GetSingleOrderDetail() {
2231 2231
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2232 2232
 
2233 2233
 	list, err := service.GetSingleOrderDetail(id, orgId)
2234
-	drugoutlist, _ := service.GetDrugWarehouseOutDetailSeventy(id, orgId)
2234
+	drugoutlist, _ := service.GetDrugWarehouseOutDetailNighty(id, orgId)
2235 2235
 	dealerList, err := service.GetAllDealerList(orgId)
2236 2236
 	manufacturerList, err := service.GetAllManufacturerList(orgId)
2237 2237
 	drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)

+ 271 - 167
controllers/his_api_controller.go 查看文件

@@ -988,6 +988,8 @@ func (c *HisApiController) CreateHisPrescription() {
988 988
 	//耗材保存处方出库
989 989
 	goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
990 990
 
991
+	settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
992
+
991 993
 	//已发药和已收费限制逻辑
992 994
 	isMidicine := false
993 995
 	isCharge := false
@@ -1048,7 +1050,7 @@ func (c *HisApiController) CreateHisPrescription() {
1048 1050
 	}
1049 1051
 	//已发药和已收费限制逻辑
1050 1052
 
1051
-	if drugStockConfig.IsOpen == 1 {
1053
+	if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
1052 1054
 		//校验库存总量
1053 1055
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1054 1056
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
@@ -1564,6 +1566,97 @@ func (c *HisApiController) CreateHisPrescription() {
1564 1566
 		}
1565 1567
 	}
1566 1568
 
1569
+	//校验耗材库存
1570
+	if goodOutConfig.IsOpen == 1 {
1571
+
1572
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1573
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
1574
+
1575
+			if len(prescriptions) > 0 {
1576
+				for _, item := range prescriptions {
1577
+
1578
+					items := item.(map[string]interface{})
1579
+					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
1580
+						projects := items["project"].([]interface{})
1581
+						if len(projects) > 0 {
1582
+
1583
+							for _, project := range projects {
1584
+								var project_id int64
1585
+								var project_type int64
1586
+								var totals float64
1587
+								var project_name string
1588
+								var parsetotal int64
1589
+								var id int64
1590
+								if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
1591
+									project_id = int64(project.(map[string]interface{})["project_id"].(float64))
1592
+								}
1593
+								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
1594
+									project_type = int64(project.(map[string]interface{})["type"].(float64))
1595
+								}
1596
+								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
1597
+									total, _ := project.(map[string]interface{})["total"].(string)
1598
+									totals, _ = strconv.ParseFloat(total, 64)
1599
+								}
1600
+
1601
+								if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
1602
+									project_name = project.(map[string]interface{})["project_name"].(string)
1603
+
1604
+								}
1605
+								if project_type == 3 {
1606
+
1607
+									//查找该耗材的出库记录
1608
+									goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
1609
+
1610
+									if len(goodWarehouseInfo) == 0 {
1611
+										//查询耗材库存
1612
+										list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
1613
+										var stock_count int64
1614
+										for _, it := range list {
1615
+											stock_count += it.StockCount
1616
+										}
1617
+										stock_counts := strconv.FormatInt(stock_count, 10)
1618
+										stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
1619
+										if totals > stock_total_count {
1620
+											c.ServeDynamicFailJsonSend(project_name + "库存不足")
1621
+											return
1622
+										}
1623
+									}
1624
+
1625
+									if len(goodWarehouseInfo) > 0 {
1626
+										//查询该患者耗材的历史数据
1627
+										ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
1628
+										count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
1629
+										//数量发生改变
1630
+										if parsetotal != count {
1631
+											//如果现在的数量大于历史数量,就要看库存是否足够
1632
+											if parsetotal > count {
1633
+
1634
+												//查询耗材所有库存
1635
+												list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
1636
+												var stock_count int64
1637
+												for _, it := range list {
1638
+													stock_count += it.StockCount
1639
+												}
1640
+
1641
+												//库存不足
1642
+												if (parsetotal - count) > stock_count {
1643
+													c.ServeDynamicFailJsonSend(project_name + "库存不足")
1644
+													return
1645
+												}
1646
+											}
1647
+										}
1648
+									}
1649
+
1650
+								}
1651
+
1652
+							}
1653
+						}
1654
+					}
1655
+				}
1656
+			}
1657
+		}
1658
+	}
1659
+
1567 1660
 	//不使用耗材保存处方出库
1568 1661
 	if goodOutConfig.IsOpen != 1 {
1569 1662
 		if stockConfig.IsOpen == 1 {
@@ -2190,15 +2283,22 @@ func (c *HisApiController) CreateHisPrescription() {
2190 2283
 
2191 2284
 			//查询今日耗材出库数量
2192 2285
 			hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
2286
+
2193 2287
 			for _, item := range hisgoodlist {
2194 2288
 				//查询耗材最后一次出库记录
2195 2289
 				wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
2290
+				fmt.Println("hh23h232323o23o23o2o32o23o2o3o2o23o32o23o2o323o23o23o23o23o23o")
2291
+				//查询默认出库仓库库存
2292
+				storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
2196 2293
 				if len(wareOut) > 0 {
2294
+
2197 2295
 					for _, it := range wareOut {
2198 2296
 						//回退库存
2199 2297
 						service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
2200 2298
 						//删除出库记录
2201 2299
 						service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
2300
+						//出库数量减少
2301
+						service.UpdateSumCount(it.OrgId, storeConfig.StorehouseOutInfo, it.ProjectId, it.Count)
2202 2302
 					}
2203 2303
 				}
2204 2304
 
@@ -2214,8 +2314,7 @@ func (c *HisApiController) CreateHisPrescription() {
2214 2314
 
2215 2315
 				operation_time := time.Now().Unix()
2216 2316
 				creater := c.GetAdminUserInfo().AdminUser.Id
2217
-				//查询默认出库仓库库存
2218
-				storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
2317
+
2219 2318
 				recordDateStr := time.Now().Format("2006-01-02")
2220 2319
 				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
2221 2320
 				nowtime := recordDate.Unix()
@@ -2243,6 +2342,7 @@ func (c *HisApiController) CreateHisPrescription() {
2243 2342
 				goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
2244 2343
 				houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
2245 2344
 				parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
2345
+
2246 2346
 				dialyPrepareOne := models.DialysisBeforePrepare{
2247 2347
 					GoodTypeId:   goodObj.GoodTypeId,
2248 2348
 					GoodId:       item.ProjectId,
@@ -2257,10 +2357,10 @@ func (c *HisApiController) CreateHisPrescription() {
2257 2357
 					ProjectId:    item.ID,
2258 2358
 				}
2259 2359
 
2260
-				service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater)
2360
+				service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
2261 2361
 
2262 2362
 				//查询剩余库存
2263
-				goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId)
2363
+				goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
2264 2364
 				var sum_count int64
2265 2365
 				for _, item := range goodList {
2266 2366
 					sum_count += item.StockCount
@@ -2833,7 +2933,7 @@ func (c *HisApiController) DeletePrescription() {
2833 2933
 
2834 2934
 							if prescribingNumber >= dialysisInfo.Count {
2835 2935
 								//删除出库表
2836
-								service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
2936
+								service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
2837 2937
 							}
2838 2938
 
2839 2939
 							//更新库存
@@ -2917,11 +3017,11 @@ func (c *HisApiController) DeletePrescription() {
2917 3017
 				}
2918 3018
 			}
2919 3019
 
2920
-			fmt.Println("goodOutConfig.IsOpen23232332233232232323232323", goodOutConfig.IsOpen)
2921 3020
 			//保存耗材出库
2922 3021
 			if goodOutConfig.IsOpen == 1 {
2923 3022
 
2924 3023
 				if item.Type == 3 {
3024
+					fmt.Println("出库数量99999999999999999999999999", item.Count)
2925 3025
 					good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
2926 3026
 					f_count, _ := strconv.ParseFloat(item.Count, 64)
2927 3027
 					good.Total = good.Total + f_count
@@ -2968,159 +3068,156 @@ func (c *HisApiController) DeletePrescription() {
2968 3068
 					for _, it := range goodList {
2969 3069
 						flush_count += it.StockCount
2970 3070
 					}
2971
-					fmt.Println("nfo.Count342232332323223232323", info.Count)
2972
-					fmt.Println("total_count0999923923932923", total_count)
3071
+					fmt.Println("历史出库数据", info.Count)
3072
+					fmt.Println("出库数量", total_count)
2973 3073
 					if info.ID > 0 {
2974
-						if info.Count >= total_count {
2975
-
2976
-							//回退库存
2977
-							service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
2978
-							cancelStockInfo := models.CancelStockInfo{
2979
-								GoodId:          item.ProjectId,
2980
-								CancelStockId:   cancel.ID,
2981
-								GoodTypeId:      good.GoodTypeId,
2982
-								Count:           prescribingNumber,
2983
-								Price:           info.Price,
2984
-								Total:           0,
2985
-								ProductDate:     info.ProductDate,
2986
-								ExpiryDate:      info.ExpiryDate,
2987
-								Ctime:           time.Now().Unix(),
2988
-								Status:          1,
2989
-								OrgId:           c.GetAdminUserInfo().CurrentOrgId,
2990
-								OrderNumber:     cancel.OrderNumber,
2991
-								Type:            0,
2992
-								Dealer:          deaerler.DealerName,
2993
-								Manufacturer:    manufacturer.ManufacturerName,
2994
-								Number:          info.Number,
2995
-								RegisterAccount: "",
2996
-								Remark:          "",
2997
-								WarehouseInfoId: info.WarehouseInfotId,
2998
-								PatientId:       info.PatientId,
2999
-								RecordDate:      info.SysRecordTime,
3000
-								StorehouseId:    houseConfig.StorehouseOutInfo,
3001
-								IsCheck:         1,
3002
-							}
3003
-
3004
-							service.CreateCancelStockInfoOne(&cancelStockInfo)
3005
-
3006
-							cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3007
-
3008
-							flow := models.VmStockFlow{
3009
-								WarehousingId:           info.WarehouseInfotId,
3010
-								GoodId:                  item.ProjectId,
3011
-								Number:                  info.Number,
3012
-								LicenseNumber:           info.LicenseNumber,
3013
-								Count:                   prescribingNumber,
3014
-								UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3015
-								PatientId:               item.PatientId,
3016
-								SystemTime:              info.SysRecordTime,
3017
-								ConsumableType:          7,
3018
-								IsSys:                   0,
3019
-								WarehousingOrder:        "",
3020
-								WarehouseOutId:          info.WarehouseOutId,
3021
-								WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3022
-								IsEdit:                  0,
3023
-								CancelStockId:           cancel.ID,
3024
-								CancelOrderNumber:       cancel.OrderNumber,
3025
-								Manufacturer:            manufacturer.ID,
3026
-								Dealer:                  0,
3027
-								Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3028
-								UpdateCreator:           0,
3029
-								Status:                  1,
3030
-								Ctime:                   time.Now().Unix(),
3031
-								Mtime:                   0,
3032
-								Price:                   info.Price,
3033
-								WarehousingDetailId:     info.WarehouseInfotId,
3034
-								WarehouseOutDetailId:    info.ID,
3035
-								CancelOutDetailId:       cancelInfo.ID,
3036
-								ProductDate:             info.ProductDate,
3037
-								ExpireDate:              info.ExpiryDate,
3038
-								StorehouseId:            houseConfig.StorehouseOutInfo,
3039
-								OverCount:               flush_count,
3040
-							}
3041
-							service.CreateStockFlowOne(flow)
3042
-
3043
-							//退库数量增加
3044
-							service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
3045
-							//出库数量减少
3046
-							service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
3047 3074
 
3075
+						//回退库存
3076
+						service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
3077
+						cancelStockInfo := models.CancelStockInfo{
3078
+							GoodId:          item.ProjectId,
3079
+							CancelStockId:   cancel.ID,
3080
+							GoodTypeId:      good.GoodTypeId,
3081
+							Count:           prescribingNumber,
3082
+							Price:           info.Price,
3083
+							Total:           0,
3084
+							ProductDate:     info.ProductDate,
3085
+							ExpiryDate:      info.ExpiryDate,
3086
+							Ctime:           time.Now().Unix(),
3087
+							Status:          1,
3088
+							OrgId:           c.GetAdminUserInfo().CurrentOrgId,
3089
+							OrderNumber:     cancel.OrderNumber,
3090
+							Type:            0,
3091
+							Dealer:          deaerler.DealerName,
3092
+							Manufacturer:    manufacturer.ManufacturerName,
3093
+							Number:          info.Number,
3094
+							RegisterAccount: "",
3095
+							Remark:          "",
3096
+							WarehouseInfoId: info.WarehouseInfotId,
3097
+							PatientId:       info.PatientId,
3098
+							RecordDate:      info.SysRecordTime,
3099
+							StorehouseId:    houseConfig.StorehouseOutInfo,
3100
+							IsCheck:         1,
3048 3101
 						}
3049 3102
 
3050
-						if info.Count < total_count {
3051
-							//回退库存
3052
-							service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
3053
-							cancelStockInfo := models.CancelStockInfo{
3054
-								GoodId:          item.ProjectId,
3055
-								CancelStockId:   cancel.ID,
3056
-								GoodTypeId:      good.GoodTypeId,
3057
-								Count:           info.Count,
3058
-								Price:           info.Price,
3059
-								Total:           0,
3060
-								ProductDate:     info.ProductDate,
3061
-								ExpiryDate:      info.ExpiryDate,
3062
-								Ctime:           time.Now().Unix(),
3063
-								Status:          1,
3064
-								OrgId:           c.GetAdminUserInfo().CurrentOrgId,
3065
-								OrderNumber:     cancel.OrderNumber,
3066
-								Type:            0,
3067
-								Dealer:          deaerler.DealerName,
3068
-								Manufacturer:    manufacturer.ManufacturerName,
3069
-								Number:          info.Number,
3070
-								RegisterAccount: "",
3071
-								Remark:          "",
3072
-								WarehouseInfoId: info.WarehouseInfotId,
3073
-								PatientId:       info.PatientId,
3074
-								RecordDate:      info.SysRecordTime,
3075
-								StorehouseId:    houseConfig.StorehouseOutInfo,
3076
-								IsCheck:         1,
3077
-							}
3078
-
3079
-							service.CreateCancelStockInfoOne(&cancelStockInfo)
3080
-
3081
-							cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3082
-
3083
-							flow := models.VmStockFlow{
3084
-								WarehousingId:           info.WarehouseInfotId,
3085
-								GoodId:                  item.ProjectId,
3086
-								Number:                  info.Number,
3087
-								LicenseNumber:           info.LicenseNumber,
3088
-								Count:                   info.Count,
3089
-								UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3090
-								PatientId:               item.PatientId,
3091
-								SystemTime:              info.SysRecordTime,
3092
-								ConsumableType:          7,
3093
-								IsSys:                   0,
3094
-								WarehousingOrder:        "",
3095
-								WarehouseOutId:          info.WarehouseOutId,
3096
-								WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3097
-								IsEdit:                  0,
3098
-								CancelStockId:           cancel.ID,
3099
-								CancelOrderNumber:       cancel.OrderNumber,
3100
-								Manufacturer:            manufacturer.ID,
3101
-								Dealer:                  0,
3102
-								Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3103
-								UpdateCreator:           0,
3104
-								Status:                  1,
3105
-								Ctime:                   time.Now().Unix(),
3106
-								Mtime:                   0,
3107
-								Price:                   info.Price,
3108
-								WarehousingDetailId:     info.WarehouseInfotId,
3109
-								WarehouseOutDetailId:    info.ID,
3110
-								CancelOutDetailId:       cancelInfo.ID,
3111
-								ProductDate:             info.ProductDate,
3112
-								ExpireDate:              info.ExpiryDate,
3113
-								StorehouseId:            houseConfig.StorehouseOutInfo,
3114
-								OverCount:               flush_count,
3115
-							}
3116
-							service.CreateStockFlowOne(flow)
3103
+						service.CreateCancelStockInfoOne(&cancelStockInfo)
3117 3104
 
3118
-							//退库数量增加
3119
-							service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
3120
-							//出库数量减少
3121
-							service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
3105
+						cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3122 3106
 
3107
+						flow := models.VmStockFlow{
3108
+							WarehousingId:           info.WarehouseInfotId,
3109
+							GoodId:                  item.ProjectId,
3110
+							Number:                  info.Number,
3111
+							LicenseNumber:           info.LicenseNumber,
3112
+							Count:                   prescribingNumber,
3113
+							UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3114
+							PatientId:               item.PatientId,
3115
+							SystemTime:              info.SysRecordTime,
3116
+							ConsumableType:          7,
3117
+							IsSys:                   0,
3118
+							WarehousingOrder:        "",
3119
+							WarehouseOutId:          info.WarehouseOutId,
3120
+							WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3121
+							IsEdit:                  0,
3122
+							CancelStockId:           cancel.ID,
3123
+							CancelOrderNumber:       cancel.OrderNumber,
3124
+							Manufacturer:            manufacturer.ID,
3125
+							Dealer:                  0,
3126
+							Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3127
+							UpdateCreator:           0,
3128
+							Status:                  1,
3129
+							Ctime:                   time.Now().Unix(),
3130
+							Mtime:                   0,
3131
+							Price:                   info.Price,
3132
+							WarehousingDetailId:     info.WarehouseInfotId,
3133
+							WarehouseOutDetailId:    info.ID,
3134
+							CancelOutDetailId:       cancelInfo.ID,
3135
+							ProductDate:             info.ProductDate,
3136
+							ExpireDate:              info.ExpiryDate,
3137
+							StorehouseId:            houseConfig.StorehouseOutInfo,
3138
+							OverCount:               flush_count,
3123 3139
 						}
3140
+						service.CreateStockFlowOne(flow)
3141
+
3142
+						//退库数量增加
3143
+						service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
3144
+						//出库数量减少
3145
+						service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
3146
+
3147
+						//if info.Count < total_count {
3148
+						//	//回退库存
3149
+						//	service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
3150
+						//	cancelStockInfo := models.CancelStockInfo{
3151
+						//		GoodId:          item.ProjectId,
3152
+						//		CancelStockId:   cancel.ID,
3153
+						//		GoodTypeId:      good.GoodTypeId,
3154
+						//		Count:           info.Count,
3155
+						//		Price:           info.Price,
3156
+						//		Total:           0,
3157
+						//		ProductDate:     info.ProductDate,
3158
+						//		ExpiryDate:      info.ExpiryDate,
3159
+						//		Ctime:           time.Now().Unix(),
3160
+						//		Status:          1,
3161
+						//		OrgId:           c.GetAdminUserInfo().CurrentOrgId,
3162
+						//		OrderNumber:     cancel.OrderNumber,
3163
+						//		Type:            0,
3164
+						//		Dealer:          deaerler.DealerName,
3165
+						//		Manufacturer:    manufacturer.ManufacturerName,
3166
+						//		Number:          info.Number,
3167
+						//		RegisterAccount: "",
3168
+						//		Remark:          "",
3169
+						//		WarehouseInfoId: info.WarehouseInfotId,
3170
+						//		PatientId:       info.PatientId,
3171
+						//		RecordDate:      info.SysRecordTime,
3172
+						//		StorehouseId:    houseConfig.StorehouseOutInfo,
3173
+						//		IsCheck:         1,
3174
+						//	}
3175
+						//
3176
+						//	service.CreateCancelStockInfoOne(&cancelStockInfo)
3177
+						//
3178
+						//	cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3179
+						//
3180
+						//	flow := models.VmStockFlow{
3181
+						//		WarehousingId:           info.WarehouseInfotId,
3182
+						//		GoodId:                  item.ProjectId,
3183
+						//		Number:                  info.Number,
3184
+						//		LicenseNumber:           info.LicenseNumber,
3185
+						//		Count:                   info.Count,
3186
+						//		UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3187
+						//		PatientId:               item.PatientId,
3188
+						//		SystemTime:              info.SysRecordTime,
3189
+						//		ConsumableType:          7,
3190
+						//		IsSys:                   0,
3191
+						//		WarehousingOrder:        "",
3192
+						//		WarehouseOutId:          info.WarehouseOutId,
3193
+						//		WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3194
+						//		IsEdit:                  0,
3195
+						//		CancelStockId:           cancel.ID,
3196
+						//		CancelOrderNumber:       cancel.OrderNumber,
3197
+						//		Manufacturer:            manufacturer.ID,
3198
+						//		Dealer:                  0,
3199
+						//		Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3200
+						//		UpdateCreator:           0,
3201
+						//		Status:                  1,
3202
+						//		Ctime:                   time.Now().Unix(),
3203
+						//		Mtime:                   0,
3204
+						//		Price:                   info.Price,
3205
+						//		WarehousingDetailId:     info.WarehouseInfotId,
3206
+						//		WarehouseOutDetailId:    info.ID,
3207
+						//		CancelOutDetailId:       cancelInfo.ID,
3208
+						//		ProductDate:             info.ProductDate,
3209
+						//		ExpireDate:              info.ExpiryDate,
3210
+						//		StorehouseId:            houseConfig.StorehouseOutInfo,
3211
+						//		OverCount:               flush_count,
3212
+						//	}
3213
+						//	service.CreateStockFlowOne(flow)
3214
+						//
3215
+						//	//退库数量增加
3216
+						//	service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
3217
+						//	//出库数量减少
3218
+						//	service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
3219
+						//
3220
+						//}
3124 3221
 
3125 3222
 						//查询已出库数量
3126 3223
 						dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
@@ -3132,7 +3229,7 @@ func (c *HisApiController) DeletePrescription() {
3132 3229
 
3133 3230
 						if prescribingNumber >= dialysisInfo.Count {
3134 3231
 							//删除出库表
3135
-							service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
3232
+							service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
3136 3233
 						}
3137 3234
 
3138 3235
 						goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
@@ -3570,7 +3667,7 @@ func (c *HisApiController) DeleteProject() {
3570 3667
 
3571 3668
 					if prescribingNumber >= dialysisInfo.Count {
3572 3669
 						//删除出库表
3573
-						service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
3670
+						service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
3574 3671
 					}
3575 3672
 
3576 3673
 					//更新剩余库存
@@ -3897,7 +3994,7 @@ func (c *HisApiController) DeleteProject() {
3897 3994
 
3898 3995
 				if prescribingNumber >= dialysisInfo.Count {
3899 3996
 					//删除出库表
3900
-					service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
3997
+					service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
3901 3998
 				}
3902 3999
 
3903 4000
 				//更新剩余库存
@@ -5843,6 +5940,7 @@ func (c *HisApiController) GetUploadInfo() {
5843 5940
 			}
5844 5941
 
5845 5942
 			for _, info := range prescriptionsOne {
5943
+
5846 5944
 				if info.Type == 1 {
5847 5945
 					hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
5848 5946
 				}
@@ -5866,9 +5964,10 @@ func (c *HisApiController) GetUploadInfo() {
5866 5964
 
5867 5965
 			//判断
5868 5966
 			for _, itemOne := range infos {
5967
+
5869 5968
 				for _, itemTwo := range hisAdvice {
5870 5969
 					if itemOne.DrugId == itemTwo.DrugId {
5871
-						itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
5970
+						itemTwo.Child = append(itemTwo.Child, itemOne)
5872 5971
 					}
5873 5972
 				}
5874 5973
 			}
@@ -5889,10 +5988,13 @@ func (c *HisApiController) GetUploadInfo() {
5889 5988
 					if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5890 5989
 						prescribing_number = parseIntPrescribingNumber
5891 5990
 					}
5991
+
5892 5992
 					sum_out_count += prescribing_number
5893 5993
 				}
5894
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId)
5994
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
5895 5995
 
5996
+				fmt.Println("sum_out_count233232323232wo", sum_out_count)
5997
+				fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
5896 5998
 				if sum_out_count > drugStockOut.FlushCount {
5897 5999
 					c.ServeSuccessJSON(map[string]interface{}{
5898 6000
 						"msg":  "2",
@@ -5901,11 +6003,11 @@ func (c *HisApiController) GetUploadInfo() {
5901 6003
 					return
5902 6004
 				}
5903 6005
 			}
5904
-
6006
+			fmt.Println("newGoods99999988882os", newGoods)
5905 6007
 			for _, itemOne := range newGoods {
5906 6008
 				for _, item := range newGoodOne {
5907
-					if itemOne.ProjectId == item.ProjectId {
5908
-						item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
6009
+					if itemOne.GoodId == item.GoodId {
6010
+						item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
5909 6011
 					}
5910 6012
 				}
5911 6013
 			}
@@ -5913,11 +6015,10 @@ func (c *HisApiController) GetUploadInfo() {
5913 6015
 			for _, item := range newGoodOne {
5914 6016
 				var sum_out_count_one int64
5915 6017
 				good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
5916
-
5917 6018
 				for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
5918 6019
 					sum_out_count_one += itemOne.Count
5919 6020
 				}
5920
-				list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId)
6021
+				list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
5921 6022
 				fmt.Println("sum_out_count_one", sum_out_count_one)
5922 6023
 				fmt.Println("list.FlushCount", list.FlushCount)
5923 6024
 				if sum_out_count_one > list.FlushCount {
@@ -6255,7 +6356,7 @@ func (c *HisApiController) GetUploadInfo() {
6255 6356
 
6256 6357
 						service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
6257 6358
 						//查询剩余库存
6258
-						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId)
6359
+						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
6259 6360
 						var sum_count int64
6260 6361
 						for _, item := range goodList {
6261 6362
 							sum_count += item.StockCount
@@ -6433,7 +6534,8 @@ func (c *HisApiController) GetUploadInfo() {
6433 6534
 							}
6434 6535
 							sum_out_count += prescribing_number
6435 6536
 						}
6436
-						drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId)
6537
+						houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
6538
+						drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
6437 6539
 
6438 6540
 						if sum_out_count > drugStockOut.FlushCount {
6439 6541
 							c.ServeSuccessJSON(map[string]interface{}{
@@ -6459,7 +6561,7 @@ func (c *HisApiController) GetUploadInfo() {
6459 6561
 						for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
6460 6562
 							sum_out_count_one += itemOne.Count
6461 6563
 						}
6462
-						list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId)
6564
+						list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
6463 6565
 						fmt.Println("sum_out_count_one", sum_out_count_one)
6464 6566
 						fmt.Println("list.FlushCount", list.FlushCount)
6465 6567
 						if sum_out_count_one > list.FlushCount {
@@ -6534,7 +6636,7 @@ func (c *HisApiController) Refund() {
6534 6636
 			infos = append(infos, &info.HisDoctorAdviceInfo)
6535 6637
 		}
6536 6638
 		if info.ProjectId > 0 && info.AdviceId == 0 {
6537
-			fmt.Println("info232323233232233", info.PatientId)
6639
+			fmt.Println("info232323233232233", order_id)
6538 6640
 			if info.HisPrescriptionProject.Type == 3 {
6539 6641
 				var good models.DialysisBeforePrepareGoods
6540 6642
 				var newGood models.NewDialysisBeforePrepareGoods
@@ -6545,6 +6647,7 @@ func (c *HisApiController) Refund() {
6545 6647
 				good.StorehouseId = houseConfig.StorehouseOutInfo
6546 6648
 				good.ProjectId = info.HisPrescriptionProject.ID
6547 6649
 				good.PatientId = info.PatientId
6650
+				good.OrderId = order_id
6548 6651
 				goods = append(goods, &good)
6549 6652
 
6550 6653
 				newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
@@ -6556,6 +6659,7 @@ func (c *HisApiController) Refund() {
6556 6659
 				newGood.RecordDate = order.SettleAccountsDate
6557 6660
 				newGood.UserOrgId = order.UserOrgId
6558 6661
 				newGood.PatientId = info.PatientId
6662
+				newGood.OrderId = order_id
6559 6663
 				newGoods = append(newGoods, &newGood)
6560 6664
 			}
6561 6665
 		}

+ 29 - 4
controllers/mobile_api_controllers/dialysis_api_controller.go 查看文件

@@ -1385,6 +1385,7 @@ func (c *DialysisAPIController) PostDialysisPrescription() {
1385 1385
 	water_machine := c.GetString("water_machine")
1386 1386
 	add_amount, _ := c.GetFloat("add_amount")
1387 1387
 	reduce_amount, _ := c.GetFloat("reduce_amount")
1388
+	dialysis_remark := c.GetString("dialysis_remark")
1388 1389
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
1389 1390
 
1390 1391
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
@@ -1497,6 +1498,7 @@ func (c *DialysisAPIController) PostDialysisPrescription() {
1497 1498
 		WaterMachine:               water_machine,
1498 1499
 		AddAmount:                  add_amount,
1499 1500
 		ReduceAmount:               reduce_amount,
1501
+		DialysisRemark:             dialysis_remark,
1500 1502
 	}
1501 1503
 
1502 1504
 	//查询最近透析准备表里是否存在 透析器 灌流器
@@ -1842,7 +1844,10 @@ func (c *DialysisAPIController) Finish() {
1842 1844
 		tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
1843 1845
 		tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
1844 1846
 		tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
1845
-		tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
1847
+		if adminUserInfo.Org.Id != 10445 {
1848
+			tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
1849
+		}
1850
+
1846 1851
 		tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
1847 1852
 
1848 1853
 	}
@@ -2043,6 +2048,7 @@ func (c *DialysisAPIController) Finish() {
2043 2048
 		redis.Set(keyOne, "", time.Second)
2044 2049
 		//结束时候透析次数加1
2045 2050
 		service.UpdateSolutionByPatientId(id)
2051
+
2046 2052
 		dialysisOrder.Stage = 2
2047 2053
 		dialysisOrder.FinishNurse = nurseID
2048 2054
 		dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
@@ -2339,6 +2345,19 @@ func (this *DialysisAPIController) StartDialysis() {
2339 2345
 
2340 2346
 		createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
2341 2347
 		service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
2348
+
2349
+		if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 {
2350
+			//统计该患者总次数
2351
+			dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
2352
+			service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
2353
+		}
2354
+
2355
+		if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
2356
+			//统计该患者总次数
2357
+			dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
2358
+			service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
2359
+		}
2360
+
2342 2361
 		redis := service.RedisClient()
2343 2362
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
2344 2363
 		redis.Set(key, "", time.Second)
@@ -2633,6 +2652,7 @@ func (c *DialysisAPIController) PostSolution() {
2633 2652
 	drhy_water := c.GetString("drhy_water")
2634 2653
 	dry_water_hour := c.GetString("dry_water_hour")
2635 2654
 	water_machine := c.GetString("water_machine")
2655
+	dialysis_remark := c.GetString("dialysis_remark")
2636 2656
 	if mode_id > 0 {
2637 2657
 		service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
2638 2658
 	}
@@ -2746,6 +2766,7 @@ func (c *DialysisAPIController) PostSolution() {
2746 2766
 		WaterMachine:               water_machine,
2747 2767
 		AddAmount:                  add_amount,
2748 2768
 		ReduceAmount:               reduce_amount,
2769
+		DialysisRemark:             dialysis_remark,
2749 2770
 	}
2750 2771
 
2751 2772
 	_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
@@ -2844,6 +2865,7 @@ func (c *DialysisAPIController) PostSolution() {
2844 2865
 		MaxUltrafiltrationRate:     max_ultrafiltration_rate,
2845 2866
 		PreImpulse:                 impulse,
2846 2867
 		SolutionStatus:             1,
2868
+		DialysisRemark:             dialysis_remark,
2847 2869
 	}
2848 2870
 
2849 2871
 	//针对河间咸的
@@ -6722,7 +6744,7 @@ func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *model
6722 6744
 	//扣减出库数量
6723 6745
 	service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
6724 6746
 	//查询剩余库存
6725
-	goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID)
6747
+	goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
6726 6748
 	var sum_count int64
6727 6749
 	for _, item := range goodList {
6728 6750
 		sum_count += item.StockCount
@@ -7165,7 +7187,8 @@ func (this *DialysisAPIController) ExectionMobileAdvice() {
7165 7187
 				}
7166 7188
 				sum_out_count += prescribing_number
7167 7189
 			}
7168
-			drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId)
7190
+			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7191
+			drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
7169 7192
 
7170 7193
 			//库存不足
7171 7194
 			if sum_out_count > drugStockOut.FlushCount {
@@ -7285,7 +7308,8 @@ func (this *DialysisAPIController) ExectionMobileAdvice() {
7285 7308
 					}
7286 7309
 					sum_out_count += prescribing_number
7287 7310
 				}
7288
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId)
7311
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7312
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
7289 7313
 
7290 7314
 				//库存不足
7291 7315
 				if sum_out_count > drugStockOut.FlushCount {
@@ -7627,6 +7651,7 @@ func (this *DialysisAPIController) CheckSchedule() {
7627 7651
 		if schedule.ID == 0 {
7628 7652
 			this.ServeSuccessJSON(map[string]interface{}{
7629 7653
 				"status": 0,
7654
+				"msg":    "请求失败",
7630 7655
 			})
7631 7656
 
7632 7657
 		} else {

+ 13 - 3
controllers/print_data_api_controller.go 查看文件

@@ -85,10 +85,20 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
85 85
 				item.Count = list.Count
86 86
 			}
87 87
 			if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
88
-				listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
88
+				if item.ScheduleDate <= 1640966400 {
89
+					listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
90
+
91
+					item.Patient.TotalDialysis = listOne.Count
92
+					item.Count = listOne.Count
93
+				}
94
+
95
+				if item.ScheduleDate >= 1672502400 {
96
+					listOne, _ := service.GetDialysisOrderCountNight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
97
+
98
+					item.Patient.TotalDialysis = listOne.Count
99
+					item.Count = listOne.Count
100
+				}
89 101
 
90
-				item.Patient.TotalDialysis = listOne.Count
91
-				item.Count = listOne.Count
92 102
 			}
93 103
 		}
94 104
 		if getScheduleErr != nil {

+ 297 - 149
controllers/secondary_order_api_contorller.go 查看文件

@@ -1397,118 +1397,6 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1397 1397
 		}
1398 1398
 	}
1399 1399
 
1400
-	//获取所有的入库仓库
1401
-	//druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
1402
-	//for _, item := range druglist {
1403
-	//	//查询该药品该仓库是否有数据
1404
-	//	drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
1405
-	//
1406
-	//	//查询该仓库该药品的入库数量
1407
-	//	medical, _ := service.GetBaseDrugMedical(item.DrugId)
1408
-	//
1409
-	//	var sum_in_count int64
1410
-	//	var flush_count int64
1411
-	//	var sum_out_count int64
1412
-	//	var cancel_out_count int64
1413
-	//	//查询入库数量和剩余库存
1414
-	//	infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
1415
-	//	for _, it := range infolist {
1416
-	//		if it.MaxUnit == medical.MaxUnit {
1417
-	//			it.WarehousingCount = it.WarehousingCount * medical.MinNumber
1418
-	//			it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
1419
-	//		}
1420
-	//		sum_in_count += it.WarehousingCount
1421
-	//		flush_count += it.StockMaxNumber + it.StockMinNumber
1422
-	//	}
1423
-	//
1424
-	//	//获取出库数量
1425
-	//	outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
1426
-	//	for _, it := range outinfolist {
1427
-	//		if it.MaxUnit == medical.MaxUnit {
1428
-	//			it.Count = it.Count * medical.MinNumber
1429
-	//		}
1430
-	//		sum_out_count += it.Count
1431
-	//	}
1432
-	//
1433
-	//	//获取退库数量
1434
-	//	cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
1435
-	//	for _, it := range cancelinfolist {
1436
-	//		if it.MaxUnit == medical.MaxUnit {
1437
-	//			it.Count = it.Count * medical.MinNumber
1438
-	//		}
1439
-	//		cancel_out_count += it.Count
1440
-	//	}
1441
-	//
1442
-	//	//新增
1443
-	//	if drug.ID == 0 {
1444
-	//		drugstock := models.XtDrugStockCount{
1445
-	//			UserOrgId:      orgId,
1446
-	//			StorehouseId:   item.StorehouseId,
1447
-	//			SumInCount:     sum_in_count,
1448
-	//			SumOutCount:    sum_out_count - cancel_out_count,
1449
-	//			SumCancelCount: cancel_out_count,
1450
-	//			DrugId:         item.DrugId,
1451
-	//			Ctime:          time.Now().Unix(),
1452
-	//			Mtime:          0,
1453
-	//			Status:         1,
1454
-	//			FlushCount:     flush_count,
1455
-	//			SumActOutCount: sum_out_count,
1456
-	//		}
1457
-	//		service.CreateDrugStockCount(drugstock)
1458
-	//	}
1459
-	//}
1460
-	//
1461
-	////获取入库数量
1462
-	//
1463
-	//
1464
-	//
1465
-	//////获取入库数据
1466
-	//goodlist, _ := service.GetSendGoodInformation(orgId)
1467
-	//for _, it := range goodlist {
1468
-	//	//查询是否有数据
1469
-	//	_, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
1470
-	//	//获取总退库数量
1471
-	//	var cancel_count int64
1472
-	//	var out_count int64
1473
-	//	var act_count int64
1474
-	//	//退库总数量
1475
-	//	cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
1476
-	//	for _, item := range cancellist {
1477
-	//		cancel_count += item.Count
1478
-	//	}
1479
-	//	//出库总数量
1480
-	//	outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1481
-	//	for _, item := range outlist {
1482
-	//		out_count += item.Count
1483
-	//	}
1484
-	//
1485
-	//	//实际出库总数量
1486
-	//	actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1487
-	//	for _, item := range actlist {
1488
-	//		act_count += item.Count
1489
-	//	}
1490
-	//
1491
-	//	if errcode == gorm.ErrRecordNotFound {
1492
-	//		good := models.XtGoodStockCount{
1493
-	//			UserOrgId:        it.OrgId,
1494
-	//			GoodId:           it.GoodId,
1495
-	//			StorehouseId:     it.StorehouseId,
1496
-	//			Status:           1,
1497
-	//			Ctime:            time.Now().Unix(),
1498
-	//			Mtime:            0,
1499
-	//			StockInCount:     it.WarehousingCount,
1500
-	//			StockOutCount:    out_count - cancel_count,
1501
-	//			StockCancelCount: cancel_count,
1502
-	//			FlushCount:       it.StockCount,
1503
-	//			StockActOutCount: act_count,
1504
-	//		}
1505
-	//		service.CreateGoodCountSix(good)
1506
-	//	}
1507
-	//	if errcode == nil {
1508
-	//		service.UpdateGoodCountSend(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
1509
-	//	}
1510
-	//}
1511
-
1512 1400
 	this.ServeSuccessJSON(map[string]interface{}{
1513 1401
 		"msg": 1,
1514 1402
 	})
@@ -1547,6 +1435,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1547 1435
 	for _, item := range list {
1548 1436
 		//药品
1549 1437
 		if item.IsSource == 1 {
1438
+
1550 1439
 			medical, _ := service.GetBaseDrugMedical(item.ProjectId)
1551 1440
 			//查询该仓库的药品库存是否满足调出数量
1552 1441
 			drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
@@ -1568,6 +1457,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1568 1457
 			}
1569 1458
 
1570 1459
 			if total_count > total {
1460
+
1571 1461
 				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
1572 1462
 				storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
1573 1463
 				this.ServeSuccessJSON(map[string]interface{}{
@@ -1639,38 +1529,177 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1639 1529
 				total_count = item.Count
1640 1530
 			}
1641 1531
 
1532
+			fmt.Println("total_count2332232333233223", total_count)
1533
+			fmt.Println("totoal2323232332322332", total)
1642 1534
 			if total_count <= total {
1643 1535
 
1644
-				//回退库存,查询该订单出库记录
1645
-				drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1646
-				for _, it := range drugOutList {
1647
-
1648
-					if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
1649
-						//回退库存
1650
-						service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
1651
-					}
1536
+				timeStr := time.Now().Format("2006-01-02")
1537
+				timeArr := strings.Split(timeStr, "-")
1538
+				creater := this.GetAdminUserInfo().AdminUser.Id
1539
+				drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
1540
+				recordDateStr := time.Now().Format("2006-01-02")
1541
+				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
1542
+				record_date := recordDate.Unix()
1543
+				drug_total = drug_total + 1
1544
+				drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1545
+				number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
1546
+				number = number + drug_total
1547
+				drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1548
+				operation_time := time.Now().Unix()
1549
+
1550
+				drugWarehouseOut := models.DrugWarehouseOut{
1551
+					WarehouseOutOrderNumber: drug_warehousing_out_order,
1552
+					OperationTime:           operation_time,
1553
+					OrgId:                   orgId,
1554
+					Creater:                 creater,
1555
+					Ctime:                   time.Now().Unix(),
1556
+					Status:                  1,
1557
+					WarehouseOutTime:        record_date,
1558
+					Type:                    2,
1559
+					StorehouseId:            item.StorehouseInId,
1560
+					SecondWarehouseId:       item.WarehouseId,
1561
+					IsSys:                   12,
1562
+					IsCheck:                 1,
1563
+				}
1564
+				_, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
1652 1565
 
1653
-					if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
1654
-						//回退库存
1655
-						service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
1656
-					}
1566
+				if drugerrcodes == gorm.ErrRecordNotFound {
1567
+					service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
1568
+				}
1657 1569
 
1658
-					if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
1570
+				drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
1659 1571
 
1660
-						service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
1661
-					}
1572
+				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1573
+					WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
1574
+					WarehouseOutId:          drugOut.ID,
1575
+					DrugId:                  item.ProjectId,
1576
+					Count:                   item.Count,
1577
+					Price:                   medical.RetailPrice,
1578
+					TotalPrice:              0,
1579
+					Status:                  1,
1580
+					Ctime:                   time.Now().Unix(),
1581
+					Remark:                  item.Remake,
1582
+					OrgId:                   orgId,
1583
+					Type:                    2,
1584
+					Manufacturer:            0,
1585
+					Dealer:                  0,
1586
+					RetailPrice:             item.MinPrice,
1587
+					RetailTotalPrice:        0,
1588
+					CountUnit:               item.SencondUnit,
1589
+					ExpiryDate:              0,
1590
+					ProductDate:             0,
1591
+					Number:                  "",
1592
+					BatchNumber:             "",
1593
+					IsSys:                   0,
1594
+					WarehouseInfoId:         0,
1595
+					StorehouseId:            item.StorehouseInId,
1596
+					SecondWarehouseInfoId:   item.ID,
1597
+					IsCheck:                 1,
1598
+				}
1599
+				drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
1600
+
1601
+				drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
1602
+				drug_in_total = drug_in_total + 1
1603
+
1604
+				warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
1605
+
1606
+				drug_warehousing := models.DrugWarehouse{
1607
+					WarehousingOrder:  warehousing_order,
1608
+					OperationTime:     operation_time,
1609
+					OrgId:             orgId,
1610
+					Creater:           creater,
1611
+					Ctime:             time.Now().Unix(),
1612
+					Status:            1,
1613
+					WarehousingTime:   record_date,
1614
+					Type:              1,
1615
+					StorehouseId:      item.StorehouseOutId,
1616
+					IsSys:             13,
1617
+					SecondWarehouseId: item.WarehouseId,
1618
+					IsCheck:           1,
1619
+				}
1662 1620
 
1663
-					//查询入库单
1664
-					storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
1665
-					//删除入库单
1666
-					service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
1621
+				//查询该调拨单是否有生成入库单
1622
+				_, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
1623
+				if drugerrcodess == gorm.ErrRecordNotFound {
1624
+					service.CreateDrugWaresing(drug_warehousing)
1625
+				}
1667 1626
 
1668
-					//查询出单
1669
-					storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
1627
+				drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
1628
+
1629
+				drugwarehouseInfo := &models.DrugWarehouseInfo{
1630
+					WarehousingOrder:      drugInfoObj.WarehousingOrder,
1631
+					WarehousingId:         drugInfoObj.ID,
1632
+					DrugId:                item.ProjectId,
1633
+					Number:                "",
1634
+					ProductDate:           0,
1635
+					ExpiryDate:            0,
1636
+					WarehousingCount:      0,
1637
+					Price:                 0,
1638
+					TotalPrice:            0,
1639
+					Status:                1,
1640
+					Ctime:                 time.Now().Unix(),
1641
+					Remark:                "",
1642
+					OrgId:                 orgId,
1643
+					Type:                  2,
1644
+					Manufacturer:          0,
1645
+					Dealer:                0,
1646
+					StockMaxNumber:        0,
1647
+					RetailTotalPrice:      0,
1648
+					BatchNumber:           "",
1649
+					MaxUnit:               "",
1650
+					MinUnit:               "",
1651
+					RetailPrice:           0,
1652
+					StorehouseId:          item.StorehouseOutId,
1653
+					SecondWarehouseInfoId: item.ID,
1654
+					IsCheck:               1,
1655
+				}
1656
+				fmt.Println("尽力发的233223323232")
1657
+				service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
1670 1658
 
1671
-					//删除出库单
1672
-					service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
1659
+				//查询默认仓库
1660
+				storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1661
+				//更新字典里面的库存
1662
+				stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
1663
+				var sum_count int64
1664
+				for _, its := range stockInfo {
1665
+					baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
1666
+					if its.MaxUnit == baseDrug.MaxUnit {
1667
+						its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
1668
+					}
1669
+					sum_count += its.StockMaxNumber + its.StockMinNumber
1673 1670
 				}
1671
+				service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
1672
+
1673
+				//回退库存,查询该订单出库记录
1674
+				//drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1675
+				//for _, it := range drugOutList {
1676
+				//
1677
+				//	if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
1678
+				//		//回退库存
1679
+				//		service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
1680
+				//	}
1681
+				//
1682
+				//	if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
1683
+				//		//回退库存
1684
+				//		service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
1685
+				//	}
1686
+				//
1687
+				//	if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
1688
+				//
1689
+				//		service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
1690
+				//	}
1691
+				//
1692
+				//	//查询入库单
1693
+				//	//storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
1694
+				//	//删除入库单
1695
+				//	//service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
1696
+				//
1697
+				//	//查询出单
1698
+				//	//storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
1699
+				//
1700
+				//	//删除出库单
1701
+				// 	//service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
1702
+				//}
1674 1703
 
1675 1704
 			}
1676 1705
 
@@ -1716,21 +1745,140 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1716 1745
 			//满足调拨
1717 1746
 			if item.Count <= total {
1718 1747
 
1719
-				//回退库存,查询该订单出库记录
1720
-				outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1721
-				for _, it := range outList {
1722
-					//回退库存
1723
-					service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
1724
-
1725
-					//获取入库单
1726
-					storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
1727
-					//删除入库单 入库流水
1728
-					service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
1729
-					//获取出库单
1730
-					storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
1731
-					//删除出库单
1732
-					service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
1748
+				timeStr := time.Now().Format("2006-01-02")
1749
+				timeArr := strings.Split(timeStr, "-")
1750
+				total, _ := service.FindAllWarehouseOut(orgId)
1751
+
1752
+				total = total + 1
1753
+				warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1754
+				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1755
+				number = number + total
1756
+				warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1757
+				operation_time := time.Now().Unix()
1758
+				creater := this.GetAdminUserInfo().AdminUser.Id
1759
+				recordDateStr := time.Now().Format("2006-01-02")
1760
+				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
1761
+				record_date := recordDate.Unix()
1762
+
1763
+				totals, _ := service.FindAllWarehouseTotal(orgId)
1764
+				totals = totals + 1
1765
+				warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
1766
+				//创建出库单
1767
+				goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
1768
+				warehouseOut := models.WarehouseOut{
1769
+					WarehouseOutOrderNumber: warehousing_out_order,
1770
+					OperationTime:           operation_time,
1771
+					OrgId:                   orgId,
1772
+					Creater:                 creater,
1773
+					Ctime:                   time.Now().Unix(),
1774
+					Status:                  1,
1775
+					WarehouseOutTime:        record_date,
1776
+					Type:                    1,
1777
+					StorehouseId:            item.StorehouseInId,
1778
+					IsSys:                   12,
1779
+					SecondWarehouseId:       item.WarehouseId,
1780
+					IsCheck:                 1,
1781
+				}
1782
+
1783
+				//查询今日是否存在调拨出库
1784
+				_, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
1785
+				if errcodes == gorm.ErrRecordNotFound {
1786
+					service.AddSigleWarehouseOut(&warehouseOut)
1787
+				}
1788
+
1789
+				out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
1790
+				warehouseOutInfo := &models.WarehouseOutInfo{
1791
+					WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
1792
+					WarehouseOutId:          out.ID,
1793
+					GoodId:                  item.ProjectId,
1794
+					GoodTypeId:              goodObj.GoodTypeId,
1795
+					Count:                   item.Count,
1796
+					Price:                   item.MinPrice,
1797
+					TotalPrice:              0,
1798
+					Status:                  1,
1799
+					Ctime:                   time.Now().Unix(),
1800
+					Remark:                  item.Remake,
1801
+					OrgId:                   orgId,
1802
+					Type:                    1,
1803
+					Manufacturer:            0,
1804
+					Number:                  "",
1805
+					ExpiryDate:              0,
1806
+					ProductDate:             0,
1807
+					Dealer:                  0,
1808
+					LicenseNumber:           "",
1809
+					WarehouseInfotId:        0,
1810
+					StorehouseId:            item.StorehouseInId,
1811
+					SecondWarehouseInfoId:   item.ID,
1812
+					IsCheck:                 1,
1813
+				}
1814
+
1815
+				//入库操作
1816
+				warehousing := models.Warehousing{
1817
+					WarehousingOrder:  warehousing_order,
1818
+					OperationTime:     operation_time,
1819
+					OrgId:             orgId,
1820
+					Creater:           creater,
1821
+					Ctime:             time.Now().Unix(),
1822
+					Status:            1,
1823
+					WarehousingTime:   record_date,
1824
+					Type:              1,
1825
+					StorehouseId:      item.StorehouseOutId,
1826
+					IsSys:             12,
1827
+					SecondWarehouseId: item.WarehouseId,
1828
+					IsCheck:           1,
1829
+				}
1830
+				//查询该调拨单是否有生成入库单
1831
+				_, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
1832
+				if errcodess == gorm.ErrRecordNotFound {
1833
+					service.AddSigleWarehouse(&warehousing)
1733 1834
 				}
1835
+				infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
1836
+
1837
+				warehouseInfo := &models.WarehousingInfo{
1838
+					WarehousingOrder:      infoObj.WarehousingOrder,
1839
+					WarehousingId:         infoObj.ID,
1840
+					GoodId:                item.ProjectId,
1841
+					Number:                "",
1842
+					GoodTypeId:            goodObj.GoodTypeId,
1843
+					ProductDate:           0,
1844
+					ExpiryDate:            0,
1845
+					WarehousingCount:      item.Count,
1846
+					Price:                 goodObj.BuyPrice,
1847
+					TotalPrice:            0,
1848
+					Status:                1,
1849
+					Ctime:                 time.Now().Unix(),
1850
+					Remark:                item.Remake,
1851
+					OrgId:                 orgId,
1852
+					Type:                  1,
1853
+					Manufacturer:          0,
1854
+					StockCount:            item.Count,
1855
+					Dealer:                0,
1856
+					LicenseNumber:         "",
1857
+					PackingPrice:          item.MinPrice,
1858
+					StorehouseId:          item.StorehouseOutId,
1859
+					SecondWarehouseInfoId: item.ID,
1860
+					IsCheck:               1,
1861
+				}
1862
+
1863
+				//出库逻辑
1864
+				parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
1865
+				fmt.Println(parseDateErr)
1866
+
1867
+				//回退库存,查询该订单出库记录
1868
+				//outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1869
+				//for _, it := range outList {
1870
+				//	//回退库存
1871
+				//	service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
1872
+				//
1873
+				//	//获取入库单
1874
+				//	//storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
1875
+				//	//删除入库单 入库流水
1876
+				//	//service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
1877
+				//	//获取出库单
1878
+				//	//storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
1879
+				//	//删除出库单
1880
+				//	//service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
1881
+				//}
1734 1882
 			}
1735 1883
 
1736 1884
 			//查询默认仓库

+ 34 - 0
models/dialysis.go 查看文件

@@ -849,6 +849,7 @@ type DialysisOrder struct {
849 849
 	NucleinDate                int64         `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
850 850
 	ScheduleRemark             string        `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
851 851
 	OrderRemark                string        `gorm:"column:order_remark" json:"order_remark" form:"order_remark"`
852
+	DialysisTotal              int64         `gorm:"column:dialysis_total" json:"dialysis_total" form:"dialysis_total"`
852 853
 }
853 854
 
854 855
 func (DialysisOrder) TableName() string {
@@ -1096,6 +1097,7 @@ type DialysisBeforePrepareGoods struct {
1096 1097
 	ProjectId         int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
1097 1098
 	StorehouseId      int64  `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
1098 1099
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1100
+	OrderId           int64  `gorm:"column:order_id" json:"order_id" form:"order_id"`
1099 1101
 }
1100 1102
 
1101 1103
 type NewDialysisBeforePrepareGoods struct {
@@ -1111,6 +1113,7 @@ type NewDialysisBeforePrepareGoods struct {
1111 1113
 	UserOrgId                          int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1112 1114
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1113 1115
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1116
+	OrderId                            int64                            `gorm:"column:order_id" json:"order_id" form:"order_id"`
1114 1117
 }
1115 1118
 
1116 1119
 type OldDialysisBeforePrepareGoods struct {
@@ -1385,3 +1388,34 @@ type XtDialysisOrderSix struct {
1385 1388
 func (XtDialysisOrderSix) TableName() string {
1386 1389
 	return "xt_dialysis_order"
1387 1390
 }
1391
+
1392
+type HisDoctorAdviceFourty struct {
1393
+	ID                    int64                    `gorm:"column:id" json:"id" form:"id"`
1394
+	UserOrgId             int64                    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1395
+	PatientId             int64                    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1396
+	AdviceDate            int64                    `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
1397
+	StartTime             int64                    `gorm:"column:start_time" json:"start_time" form:"start_time"`
1398
+	AdviceName            string                   `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
1399
+	PrescribingNumber     float64                  `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
1400
+	PrescribingNumberUnit string                   `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
1401
+	Status                int64                    `gorm:"column:status" json:"status" form:"status"`
1402
+	CreatedTime           int64                    `gorm:"column:created_time" json:"created_time" form:"created_time"`
1403
+	UpdatedTime           int64                    `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
1404
+	ParentId              int64                    `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
1405
+	ExecutionTime         int64                    `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
1406
+	ExecutionStaff        int64                    `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
1407
+	ExecutionState        int64                    `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
1408
+	Checker               int64                    `gorm:"column:checker" json:"checker" form:"checker"`
1409
+	CheckTime             int64                    `gorm:"column:check_time" json:"check_time" form:"check_time"`
1410
+	CheckState            int64                    `gorm:"column:check_state" json:"check_state" form:"check_state"`
1411
+	ChildDoctorAdvice     []*HisDoctorAdviceFourty `gorm:"ForeignKey:DrugId;AssociationForeignKey:DrugId" json:"child"`
1412
+	IsCheck               int64                    `gorm:"-" json:"is_check" form:"is_check"`
1413
+	Way                   int64                    `gorm:"column:way" json:"way" form:"way"`
1414
+	DrugId                int64                    `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
1415
+	IsSettle              int64                    `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
1416
+	Drug                  Drug                     `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
1417
+}
1418
+
1419
+func (HisDoctorAdviceFourty) TableName() string {
1420
+	return "his_doctor_advice_info"
1421
+}

+ 109 - 0
models/drug_stock.go 查看文件

@@ -587,3 +587,112 @@ type XtDrugWarehouseFlushInfo struct {
587 587
 func (XtDrugWarehouseFlushInfo) TableName() string {
588 588
 	return "xt_drug_warehouse_flush_info"
589 589
 }
590
+
591
+type DrugFlowNight struct {
592
+	ID                        int64             `gorm:"column:id" json:"id" form:"id"`
593
+	WarehousingId             int64             `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
594
+	DrugId                    int64             `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
595
+	Number                    string            `gorm:"column:number" json:"number" form:"number"`
596
+	BatchNumber               string            `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
597
+	Count                     int64             `gorm:"column:count" json:"count" form:"count"`
598
+	UserOrgId                 int64             `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
599
+	PatientId                 int64             `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
600
+	SystemTime                int64             `gorm:"column:system_time" json:"system_time" form:"system_time"`
601
+	ConsumableType            int64             `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
602
+	IsSys                     int64             `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
603
+	WarehousingOrder          string            `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
604
+	WarehouseOutId            int64             `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
605
+	WarehouseOutOrderNumber   string            `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
606
+	IsEdit                    int64             `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
607
+	CancelStockId             int64             `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
608
+	CancelOrderNumber         string            `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
609
+	Manufacturer              int64             `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
610
+	Dealer                    int64             `gorm:"column:dealer" json:"dealer" form:"dealer"`
611
+	Creator                   int64             `gorm:"column:creator" json:"creator" form:"creator"`
612
+	UpdateCreator             int64             `gorm:"column:update_creator" json:"update_creator" form:"update_creator"`
613
+	Status                    int64             `gorm:"column:status" json:"status" form:"status"`
614
+	Ctime                     int64             `gorm:"column:ctime" json:"ctime" form:"ctime"`
615
+	Mtime                     int64             `gorm:"column:mtime" json:"mtime" form:"mtime"`
616
+	Price                     float64           `gorm:"column:price" json:"price" form:"price"`
617
+	WarehousingDetailId       int64             `gorm:"column:warehousing_detail_id" json:"warehousing_detail_id" form:"warehousing_detail_id"`
618
+	WarehouseOutDetailId      int64             `gorm:"column:warehouse_out_detail_id" json:"warehouse_out_detail_id" form:"warehouse_out_detail_id"`
619
+	CancelOutDetailId         int64             `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
620
+	ExpireDate                int64             `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
621
+	ProductDate               int64             `gorm:"column:product_date" json:"product_date" form:"product_date"`
622
+	MaxUnit                   string            `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
623
+	MinUnit                   string            `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
624
+	StockMaxNumber            int64             `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
625
+	StockMinNumber            int64             `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
626
+	LastStockMaxNumber        int64             `gorm:"column:last_stock_max_number" json:"last_stock_max_number" form:"last_stock_max_number"`
627
+	LastStockMinNumber        int64             `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
628
+	BaseDrugLibSeven          BaseDrugLibSeven  `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
629
+	AdviceId                  int64             `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
630
+	SupplyWarehouseId         int64             `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
631
+	SupplyCancelOutId         int64             `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
632
+	SupplyWarehouseDetailInfo int64             `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
633
+	StorehouseId              int64             `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
634
+	SecondWarehouseInfoId     int64             `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
635
+	AdminUserId               int64             `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
636
+	LastPrice                 float64           `gorm:"column:last_price" json:"last_price" form:"last_price"`
637
+	StockCount                string            `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
638
+	PharmacyId                int64             `gorm:"column:pharmacy_id" json:"pharmacy_id" form:"pharmacy_id"`
639
+	DrugWarehouseInfoOne      DrugWarehouseInfo `gorm:"ForeignKey:ID;AssociationForeignKey:WarehousingDetailId"json:"xt_drug_warehouse_info" `
640
+	IsRead                    int64             `gorm:"column:is_read" json:"is_read" form:"is_read"`
641
+	IsCheck                   int64             `gorm:"column:is_check" json:"is_check" form:"is_check"`
642
+	OverCount                 int64             `gorm:"column:over_count" json:"over_count" form:"over_count"`
643
+	RetailPrice               float64           `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
644
+	OrderId                   int64             `gorm:"column:order_id" json:"order_id" form:"order_id"`
645
+}
646
+
647
+func (DrugFlowNight) TableName() string {
648
+	return "xt_drug_flow"
649
+}
650
+
651
+type DrugWarehouseOutInfoNight struct {
652
+	ID                      int64            `gorm:"column:id" json:"id" form:"id"`
653
+	WarehouseOutId          int64            `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
654
+	DrugId                  int64            `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
655
+	WarehousingOutTarget    int64            `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
656
+	Count                   int64            `gorm:"column:count" json:"count" form:"count"`
657
+	CountUnit               string           `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
658
+	Price                   float64          `gorm:"column:price" json:"price" form:"price"`
659
+	TotalPrice              float64          `gorm:"column:total_price" json:"total_price" form:"total_price"`
660
+	ProductDate             int64            `gorm:"column:product_date" json:"product_date" form:"product_date"`
661
+	ExpiryDate              int64            `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
662
+	Mtime                   int64            `gorm:"column:mtime" json:"mtime" form:"mtime"`
663
+	Ctime                   int64            `gorm:"column:ctime" json:"ctime" form:"ctime"`
664
+	Status                  int64            `gorm:"column:status" json:"status" form:"status"`
665
+	OrgId                   int64            `gorm:"column:org_id" json:"org_id" form:"org_id"`
666
+	Remark                  string           `gorm:"column:remark" json:"remark" form:"remark"`
667
+	IsCancel                int64            `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
668
+	WarehouseOutOrderNumber string           `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
669
+	Type                    int64            `gorm:"column:type" json:"type" form:"type"`
670
+	Dealer                  int64            `gorm:"column:dealer" json:"dealer" form:"dealer"`
671
+	Manufacturer            int64            `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
672
+	IsSys                   int64            `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
673
+	SysRecordTime           int64            `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
674
+	RetailPrice             float64          `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
675
+	RetailTotalPrice        float64          `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
676
+	Number                  string           `gorm:"column:number" json:"number" form:"number"`
677
+	BatchNumber             string           `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
678
+	PatientId               int64            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
679
+	WarehouseInfoId         int64            `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
680
+	AdviceId                int64            `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
681
+	SupplyCancelOutId       int64            `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
682
+	SupplyWarehouseId       int64            `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
683
+	IsSource                int64            `gorm:"column:is_source" json:"is_source" form:"is_source"`
684
+	StorehouseId            int64            `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
685
+	SecondWarehouseInfoId   int64            `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
686
+	AdminUserId             int64            `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
687
+	LastPrice               float64          `gorm:"column:last_price" json:"last_price" form:"last_price"`
688
+	StockCount              string           `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
689
+	PharmacyId              int64            `gorm:"column:pharmacy_id" json:"pharmacy_id" form:"pharmacy_id"`
690
+	IsCheck                 int64            `gorm:"column:is_check" json:"is_check" form:"is_check"`
691
+	Drug                    BaseDrugLibSeven `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId"json:"drug" `
692
+	OverCount               int64            `gorm:"column:over_count" json:"over_count" form:"over_count"`
693
+	OrderId                 int64            `gorm:"column:order_id" json:"order_id" form:"order_id"`
694
+}
695
+
696
+func (DrugWarehouseOutInfoNight) TableName() string {
697
+	return "xt_drug_warehouse_out_info"
698
+}

+ 9 - 8
models/new_monitor.go 查看文件

@@ -41,14 +41,15 @@ func (VMMonitorPatients) TableName() string {
41 41
 }
42 42
 
43 43
 type VMMonitorDialysisOrder struct {
44
-	ID           int64        `gorm:"column:id" json:"id"`
45
-	DialysisDate int64        `gorm:"column:dialysis_date" json:"dialysis_date"`
46
-	UserOrgId    int64        `gorm:"column:user_org_id" json:"user_org_id"`
47
-	PatientId    int64        `gorm:"column:patient_id" json:"patient_id"`
48
-	BedID        int64        `gorm:"column:bed_id" json:"bed_id"`
49
-	Status       int64        `gorm:"column:status" json:"status"`
50
-	DeviceNumber DeviceNumber `gorm:"ForeignKey:BedId" json:"device_number"`
51
-	StartTime    int64        `gorm:"column:start_time" json:"start_time"`
44
+	ID            int64        `gorm:"column:id" json:"id"`
45
+	DialysisDate  int64        `gorm:"column:dialysis_date" json:"dialysis_date"`
46
+	UserOrgId     int64        `gorm:"column:user_org_id" json:"user_org_id"`
47
+	PatientId     int64        `gorm:"column:patient_id" json:"patient_id"`
48
+	BedID         int64        `gorm:"column:bed_id" json:"bed_id"`
49
+	Status        int64        `gorm:"column:status" json:"status"`
50
+	DeviceNumber  DeviceNumber `gorm:"ForeignKey:BedId" json:"device_number"`
51
+	StartTime     int64        `gorm:"column:start_time" json:"start_time"`
52
+	DialysisTotal int64        `gorm:"column:dialysis_total" json:"dialysis_total" form:"dialysis_total"`
52 53
 }
53 54
 
54 55
 func (VMMonitorDialysisOrder) TableName() string {

+ 2 - 0
models/patient_models.go 查看文件

@@ -356,6 +356,7 @@ type DialysisPrescription struct {
356 356
 	WaterMachine               string        `gorm:"column:water_machine" json:"water_machine" form:"water_machine"`
357 357
 	AddAmount                  float64       `gorm:"column:add_amount" json:"add_amount" form:"add_amount"`
358 358
 	ReduceAmount               float64       `gorm:"column:reduce_amount" json:"reduce_amount" form:"reduce_amount"`
359
+	DialysisRemark             string        `gorm:"column:dialysis_remark" json:"dialysis_remark" form:"dialysis_remark"`
359 360
 }
360 361
 
361 362
 func (DialysisPrescription) TableName() string {
@@ -562,6 +563,7 @@ type DialysisSolution struct {
562 563
 	MaxUltrafiltrationRate     float64 `gorm:"column:max_ultrafiltration_rate" json:"max_ultrafiltration_rate" form:"max_ultrafiltration_rate"`
563 564
 	PreImpulse                 float64 `gorm:"column:pre_impulse" json:"pre_impulse" form:"pre_impulse"`
564 565
 	SolutionStatus             int64   `gorm:"column:solution_status" json:"solution_status" form:"solution_status"`
566
+	DialysisRemark             string  `gorm:"column:dialysis_remark" json:"dialysis_remark" form:"dialysis_remark"`
565 567
 }
566 568
 
567 569
 func (DialysisSolution) TableName() string {

+ 24 - 0
models/schedule_models.go 查看文件

@@ -523,3 +523,27 @@ type ScheduleTwentyOne struct {
523 523
 func (ScheduleTwentyOne) TableName() string {
524 524
 	return "xt_schedule"
525 525
 }
526
+
527
+type VmBloodScheduleOne struct {
528
+	ID              int64                      `gorm:"column:id" json:"id" form:"id"`
529
+	UserOrgId       int64                      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
530
+	PartitionId     int64                      `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
531
+	BedId           int64                      `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
532
+	PatientId       int64                      `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
533
+	ScheduleDate    int64                      `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
534
+	ScheduleType    int64                      `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
535
+	ScheduleWeek    int64                      `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
536
+	ModeId          int64                      `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
537
+	Status          int64                      `gorm:"column:status" json:"status" form:"status"`
538
+	CreatedTime     int64                      `gorm:"column:created_time" json:"created_time" form:"created_time"`
539
+	UpdatedTime     int64                      `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
540
+	IsExport        int64                      `gorm:"column:is_export" json:"is_export" form:"is_export"`
541
+	DeviceNumber    *NewMDeviceNumberVM        `gorm:"ForeignKey:BedId" json:"device_number"`
542
+	SchedualPatient *NewMSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
543
+	XtDoctorAdvice  []*XtDoctorAdvice          `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,ScheduleDate" json:"xt_doctor_advice"`
544
+	HisDoctorAdvice []*HisDoctorAdviceFourty   `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_doctor_advice"`
545
+}
546
+
547
+func (VmBloodScheduleOne) TableName() string {
548
+	return "xt_schedule"
549
+}

+ 2 - 1
models/stock_models.go 查看文件

@@ -152,7 +152,8 @@ func (WarehousingInfo) TableName() string {
152 152
 }
153 153
 
154 154
 type WarehousingInfoSeven struct {
155
-	StockCount int64 `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
155
+	StockCount   int64 `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
156
+	StorehouseId int64 `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
156 157
 }
157 158
 
158 159
 func (WarehousingInfoSeven) TableName() string {

+ 7 - 5
service/device_service.go 查看文件

@@ -391,11 +391,13 @@ func UpdateDeviceGroup(group *models.DeviceGroup) error {
391 391
 //////// 机号 Number
392 392
 
393 393
 type DeviceNumberVM struct {
394
-	ID     int64  `gorm:"column:id" json:"id"`
395
-	OrgID  int64  `gorm:"column:org_id" json:"-"`
396
-	Number string `gorm:"column:number" json:"number"`
397
-	ZoneID int64  `gorm:"column:zone_id" json:"zone_id"`
398
-	Status int64  `gorm:"column:status" json:"status" form:"status"`
394
+	ID      int64  `gorm:"column:id" json:"id"`
395
+	OrgID   int64  `gorm:"column:org_id" json:"-"`
396
+	Number  string `gorm:"column:number" json:"number"`
397
+	ZoneID  int64  `gorm:"column:zone_id" json:"zone_id"`
398
+	Status  int64  `gorm:"column:status" json:"status" form:"status"`
399
+	Sort    int64  `gorm:"column:sort" json:"sort" form:"sort"`
400
+	GroupId int64  `gorm:"column:group_id" json:"group_id" form:"group_id"`
399 401
 }
400 402
 
401 403
 func (DeviceNumberVM) TableName() string {

+ 20 - 8
service/dialysis_solution_service.go 查看文件

@@ -216,9 +216,9 @@ func GetDialysisGoodTotalCount(orgID int64, schedule_type int64, partition_id in
216 216
 
217 217
 }
218 218
 
219
-func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
219
+func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
220 220
 
221
-	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
221
+	db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
222 222
 
223 223
 	if scheduleDate > 0 {
224 224
 		db = db.Where("schedule_date = ?", scheduleDate)
@@ -235,8 +235,9 @@ func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id
235 235
 	err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
236 236
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
237 237
 		Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
238
-		Preload("HisDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
239
-		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
238
+		Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
239
+			return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
240
+		}).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
240 241
 
241 242
 	return schedule, err
242 243
 
@@ -364,7 +365,6 @@ func SaveHisDialysis(orgid int64, ids []string) error {
364 365
 }
365 366
 
366 367
 func GetHisPatientDialysisSolutionGroupList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64, ids []string) (schedule []*models.VmBloodScheduleTwo, total int64, err error) {
367
-	fmt.Println("ids23322332323232hhha", ids)
368 368
 	db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
369 369
 	offset := (page - 1) * limit
370 370
 	if scheduleDate > 0 {
@@ -391,7 +391,7 @@ func GetHisPatientDialysisSolutionGroupList(keywords string, limit int64, page i
391 391
 			Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
392 392
 				return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
393 393
 					return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
394
-						return db.Where("user_org_id = ? and status = 1 and type = 3", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
394
+						return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
395 395
 					})
396 396
 				})
397 397
 			})
@@ -405,7 +405,7 @@ func GetHisPatientDialysisSolutionGroupList(keywords string, limit int64, page i
405 405
 			Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
406 406
 				return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
407 407
 					return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
408
-						return db.Where("user_org_id = ? and status = 1 and type = 3", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
408
+						return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
409 409
 					})
410 410
 				})
411 411
 			}).Find(&schedule).Error
@@ -437,10 +437,22 @@ func GetHisDialysisGoodCount(orgID int64, schedule_type int64, partition_id int6
437 437
 		Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
438 438
 			return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
439 439
 				return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
440
-					return db.Where("user_org_id = ? and status = 1 and type = 3", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
440
+					return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
441 441
 				})
442 442
 			})
443 443
 		}).Find(&schedule).Error
444 444
 
445 445
 	return schedule, err
446 446
 }
447
+
448
+func GeAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
449
+
450
+	err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Find(&advice).Error
451
+	return advice, err
452
+}
453
+
454
+func GetHisAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.HisDoctorAdviceFourty, err error) {
455
+
456
+	err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Preload("Drug", "org_id = ? and status=1", user_org_id).Find(&advice).Error
457
+	return advice, err
458
+}

+ 8 - 2
service/gobal_config_service.go 查看文件

@@ -902,6 +902,12 @@ func GetDrugWarehouseOutDetailSeventy(id int64, org_id int64) (info []*models.Dr
902 902
 	return info, err
903 903
 }
904 904
 
905
+func GetDrugWarehouseOutDetailNighty(id int64, org_id int64) (info []*models.DrugWarehouseOutInfoNight, err error) {
906
+
907
+	err = XTReadDB().Where("warehouse_out_id in(?) and org_id = ? and status =1", id, org_id).Preload("Drug", "org_id = ? and status = 1", org_id).Find(&info).Error
908
+	return info, err
909
+}
910
+
905 911
 func GetDrugStockFlowDetail(record_time int64, orgid int64) (drugflow []*models.XtDrugAutomaticReduceDetail, err error) {
906 912
 
907 913
 	err = XTReadDB().Where("record_time = ? and org_id = ? and status = 1", record_time, orgid).Preload("XtBaseDrug", "status = 1").Find(&drugflow).Error
@@ -945,7 +951,7 @@ func GetDrugFlowList(id int64, orgid int64) (stockflow []*models.DrugFlow, err e
945 951
 	return stockflow, err
946 952
 }
947 953
 
948
-func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
954
+func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlowNight, err error) {
949 955
 
950 956
 	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
951 957
 	return drugFlow, err
@@ -953,7 +959,7 @@ func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlo
953 959
 
954 960
 func GetDrugFlowListGroupByIdOne(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
955 961
 
956
-	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("batch_number").Find(&drugFlow).Error
962
+	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
957 963
 	return drugFlow, err
958 964
 }
959 965
 

+ 4 - 4
service/his_service.go 查看文件

@@ -2676,19 +2676,19 @@ func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
2676 2676
 	return
2677 2677
 }
2678 2678
 
2679
-func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64) (models.XtDrugStockCount, error) {
2679
+func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64, storehouse_id int64) (models.XtDrugStockCount, error) {
2680 2680
 
2681 2681
 	drug := models.XtDrugStockCount{}
2682 2682
 
2683
-	err := XTReadDB().Where("drug_id = ? and user_org_id = ? and status = 1", drug_id, user_org_id).Find(&drug).Error
2683
+	err := XTReadDB().Where("drug_id = ? and user_org_id = ? and status = 1 and storehouse_id =?", drug_id, user_org_id, storehouse_id).Find(&drug).Error
2684 2684
 
2685 2685
 	return drug, err
2686 2686
 }
2687 2687
 
2688
-func GetStockGoodList(good_id int64, org_id int64) (models.XtGoodStockCount, error) {
2688
+func GetStockGoodList(good_id int64, org_id int64, storehouse_id int64) (models.XtGoodStockCount, error) {
2689 2689
 
2690 2690
 	stockCount := models.XtGoodStockCount{}
2691
-	err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1", good_id, org_id).Find(&stockCount).Error
2691
+	err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1 and storehouse_id = ?", good_id, org_id, storehouse_id).Find(&stockCount).Error
2692 2692
 	return stockCount, err
2693 2693
 }
2694 2694
 

+ 26 - 10
service/manage_center_service.go 查看文件

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"fmt"
5 6
 	"github.com/jinzhu/gorm"
6 7
 	"strconv"
7 8
 	"strings"
@@ -210,6 +211,12 @@ func GetDrugAutoWarehouseOutEight(patient_id int64, advicedate int64, drugid int
210 211
 	return detail, err
211 212
 }
212 213
 
214
+func GetDrugAutoWarehouseOutTen(patient_id int64, advicedate int64, drugid int64, adviceid int64, warehouse_info_id int64) (models.DrugWarehouseOutInfo, error) {
215
+	detail := models.DrugWarehouseOutInfo{}
216
+	err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", patient_id, advicedate, drugid, adviceid, warehouse_info_id).Find(&detail).Error
217
+	return detail, err
218
+}
219
+
213 220
 func GetDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.DrugWarehouseOutInfo, err error) {
214 221
 
215 222
 	err = XTReadDB().Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&night).Error
@@ -430,11 +437,11 @@ func GetAllDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
430 437
 
431 438
 func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
432 439
 
433
-	//查询该病人该药品是否有库存记录
440
+	//查询该批次病人该药品出库数据
434 441
 	info, _ := GetDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
435
-
436 442
 	list, _ := GetDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
437 443
 
444
+	fmt.Println("lsit233323232323233232332wo", list)
438 445
 	storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
439 446
 	//退库
440 447
 	drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
@@ -442,24 +449,29 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
442 449
 	//如果剩余数量 + 退库数量 < 总入库数量
443 450
 	if len(list) > 0 {
444 451
 		for _, its := range list {
452
+			fmt.Println("its,23322323323223232332wo", its.WarehouseInfoId)
453
+
454
+			//查询该批次病人该药品出库数据
455
+			infos, _ := GetDrugAutoWarehouseOutTen(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID, its.WarehouseInfoId)
456
+			fmt.Println("info2332323232332233223wo", infos.Count)
445 457
 			//查询该药品出库批次总入库数量
446
-			druginfo, _ := GetDrugInfoSix(its.WarehouseInfoId, info.OrgId)
458
+			druginfo, _ := GetDrugInfoSix(its.WarehouseInfoId, infos.OrgId)
447 459
 
448 460
 			var out_count int64  //该批次出库库存
449 461
 			var sum_count int64  //该批次总库存
450 462
 			var over_count int64 //剩余数量
451 463
 
452 464
 			over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
453
-			if info.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
465
+			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
454 466
 				out_count = info.Count * drug.MinNumber
455 467
 
456 468
 			}
457
-			if info.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
458
-				out_count = info.Count
469
+			if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
470
+				out_count = infos.Count
459 471
 			}
460 472
 
461
-			if info.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
462
-				out_count = info.Count
473
+			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
474
+				out_count = infos.Count
463 475
 			}
464 476
 
465 477
 			if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
@@ -474,6 +486,9 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
474 486
 				sum_count = druginfo.WarehousingCount
475 487
 			}
476 488
 
489
+			fmt.Println("//剩余数量", over_count)
490
+			fmt.Println("该批出出库数量3223323232wo", out_count)
491
+			fmt.Println("g该批次总库存wowowoowow", sum_count)
477 492
 			if (over_count + out_count) <= sum_count {
478 493
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
479 494
 
@@ -891,8 +906,9 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
891 906
 
892 907
 func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
893 908
 
909
+	fmt.Print("order_id223233232323223323223wo", good.OrderId)
894 910
 	//查询已经出库数量
895
-	info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId)
911
+	info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId, good.OrderId)
896 912
 	if len(info) > 0 {
897 913
 		houseConfig, _ := GetAllStoreHouseConfig(good.UserOrgId)
898 914
 
@@ -1001,7 +1017,7 @@ func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater i
1001 1017
 			//出库数量减少
1002 1018
 			UpdateSumCount(good.UserOrgId, houseConfig.StorehouseOutInfo, good.GoodId, good.Count)
1003 1019
 			//删除出库表
1004
-			DeleteAutoRedeceDetailTen(good.UserOrgId, item.PatientId, item.SysRecordTime, item.GoodId)
1020
+			DeleteAutoRedeceDetailTenOne(good.UserOrgId, item.PatientId, item.SysRecordTime, item.GoodId, item.OrderId)
1005 1021
 
1006 1022
 			goodListOne, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
1007 1023
 			var flush_count int64

+ 34 - 0
service/mobile_dialysis_service.go 查看文件

@@ -2755,6 +2755,11 @@ func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (
2755 2755
 	return
2756 2756
 }
2757 2757
 
2758
+func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
2759
+	err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1672502400 and  dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
2760
+	return
2761
+}
2762
+
2758 2763
 func GetFirstDateOfMonth(d time.Time) time.Time {
2759 2764
 	d = d.AddDate(0, 0, -d.Day()+1)
2760 2765
 	return GetZeroTime(d)
@@ -5188,3 +5193,32 @@ func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string)
5188 5193
 	err = XTWriteDB().Model(models.XtPatientsNew{}).Where("user_org_id = ? and id = ? and status = 1", org_id, patient_id).Updates(map[string]interface{}{"schedule_remark": schedule_remark}).Error
5189 5194
 	return err
5190 5195
 }
5196
+
5197
+func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
5198
+
5199
+	order := models.BloodDialysisOrderCount{}
5200
+	db := XTReadDB().Table("xt_dialysis_order as o")
5201
+
5202
+	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and  x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
5203
+
5204
+	return order, err
5205
+}
5206
+
5207
+func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
5208
+
5209
+	order := models.BloodDialysisOrderCount{}
5210
+	db := XTReadDB().Table("xt_dialysis_order as o")
5211
+
5212
+	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1672502400 and  x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
5213
+
5214
+	return order, err
5215
+}
5216
+
5217
+func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
5218
+
5219
+	order := models.DialysisOrder{}
5220
+
5221
+	err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"dialysis_total": dialysis_total}).Error
5222
+
5223
+	return order, err
5224
+}

+ 2 - 2
service/new_stock_service.go 查看文件

@@ -370,9 +370,9 @@ func UpdateLastAutoCount(id int64, count int64) error {
370 370
 	return err
371 371
 }
372 372
 
373
-func GetWareOutInfo(good_id int64, record_date int64, user_org_id int64, patient_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
373
+func GetWareOutInfo(good_id int64, record_date int64, user_org_id int64, patient_id int64, order_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
374 374
 
375
-	err = XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ?", good_id, record_date, user_org_id, patient_id).Find(&outinfo).Error
375
+	err = XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ? and order_id = ?", good_id, record_date, user_org_id, patient_id, order_id).Find(&outinfo).Error
376 376
 	return outinfo, err
377 377
 }
378 378
 

+ 56 - 10
service/new_warehouse_service.go 查看文件

@@ -50,7 +50,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
50 50
 		UpdateHisPrescriptionProjectStatus(goods.GoodId, record_time, orgID, patient_id)
51 51
 
52 52
 		//查询剩余库存
53
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
53
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
54 54
 		var sum_count int64
55 55
 		for _, item := range goodList {
56 56
 			sum_count += item.StockCount
@@ -312,7 +312,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
312 312
 		if errThree != nil {
313 313
 			return errThree
314 314
 		}
315
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
315
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
316 316
 		var sum_count int64
317 317
 		for _, item := range goodList {
318 318
 			sum_count += item.StockCount
@@ -1457,7 +1457,6 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1457 1457
 
1458 1458
 		//查询今日该药品该患者是否有出库数据
1459 1459
 		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
1460
-		fmt.Println("lastDrugOutInfowwowowowoowowowowowowowowo", lastDrugOutInfo.ID)
1461 1460
 		if lastDrugOutInfo.ID == 0 {
1462 1461
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1463 1462
 			if errOne != nil {
@@ -1997,7 +1996,7 @@ func GetSigleDrugWarehouseOutInfo(patient_id int64, advice_date int64, orgid int
1997 1996
 func GetSigleDrugWarehouseOutInfoOne(patient_id int64, advice_date int64, orgid int64) (models.XtDrugWarehouseOutInfo, error) {
1998 1997
 
1999 1998
 	info := models.XtDrugWarehouseOutInfo{}
2000
-	err = XTReadDB().Where("patient_id = ? and advice_date = ? and org_id = ? and status = 1", patient_id, advice_date, orgid).Find(&info).Error
1999
+	err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and org_id = ? and status = 1", patient_id, advice_date, orgid).Find(&info).Error
2001 2000
 	return info, err
2002 2001
 }
2003 2002
 
@@ -2069,6 +2068,12 @@ func FindDrugWarehouseOutInfoCount(drugid int64, patient_id int64, record_date i
2069 2068
 	return flow, err
2070 2069
 }
2071 2070
 
2071
+func FindDrugSettleWarehouseOutInfoCount(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64) (flow []*models.DrugFlow, err error) {
2072
+
2073
+	err = XTReadDB().Where("drug_id = ? and patient_id = ? and system_time = ? and user_org_id = ? and consumable_type = 15 and status = 1 and advice_id = ?", drugid, patient_id, record_date, org_id, advice_id).Find(&flow).Error
2074
+	return flow, err
2075
+}
2076
+
2072 2077
 func FindDrugCancelOutInfo(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64) (flow []*models.DrugFlow, err error) {
2073 2078
 	err = XTReadDB().Where("drug_id = ? and patient_id = ? and system_time = ? and user_org_id = ? and consumable_type = 7 and status = 1 and advice_id = ?", drugid, patient_id, record_date, org_id, advice_id).Find(&flow).Error
2074 2079
 	return flow, err
@@ -2191,6 +2196,8 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2191 2196
 	}
2192 2197
 
2193 2198
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2199
+	fmt.Println("stock_nbumber3223323232", stock_number)
2200
+	fmt.Println("deliver_number", deliver_number)
2194 2201
 	if stock_number >= deliver_number {
2195 2202
 
2196 2203
 		var maxNumber int64 = 0
@@ -2349,7 +2356,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2349 2356
 		var out_count int64
2350 2357
 		var cancel_count int64
2351 2358
 		//查询出库数据
2352
-		infoCountList, _ := FindDrugWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2359
+		infoCountList, _ := FindDrugSettleWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2353 2360
 		//查询退库数据
2354 2361
 		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2355 2362
 		for _, item := range infoCountList {
@@ -2403,6 +2410,45 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2403 2410
 
2404 2411
 		}
2405 2412
 
2413
+		if deliver_number == (out_count - cancel_count) {
2414
+			drugflow := models.DrugFlow{
2415
+				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2416
+				WarehouseOutId:          warehouseout.ID,
2417
+				DrugId:                  advice.DrugId,
2418
+				Number:                  warehouse.Number,
2419
+				ProductDate:             warehouse.ProductDate,
2420
+				ExpireDate:              warehouse.ExpiryDate,
2421
+				Count:                   deliver_number, //按最小单位计算,
2422
+				Price:                   warehouse.RetailPrice,
2423
+				Status:                  1,
2424
+				Ctime:                   time.Now().Unix(),
2425
+				UserOrgId:               orgID,
2426
+				Manufacturer:            warehouse.Manufacturer,
2427
+				Dealer:                  warehouse.Dealer,
2428
+				BatchNumber:             warehouse.BatchNumber,
2429
+				MaxUnit:                 drup.MinUnit,
2430
+				ConsumableType:          15,
2431
+				IsEdit:                  1,
2432
+				Creator:                 advice.ExecutionStaff,
2433
+				IsSys:                   1,
2434
+				PatientId:               advice.PatientId,
2435
+				SystemTime:              advice.AdviceDate,
2436
+				WarehousingDetailId:     warehouse.ID,
2437
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2438
+				StorehouseId:            storeConfig.DrugStorehouseOut,
2439
+				WarehouseOutDetailId:    lastDrugOutInfo.ID,
2440
+				OverCount:               sum_count,
2441
+				AdviceId:                advice.ID,
2442
+				LastPrice:               warehouse.Price,
2443
+				OrderId:                 warehouseout.OrderId,
2444
+			}
2445
+
2446
+			CreateDrugFlowOne(drugflow)
2447
+			//出库数量相加
2448
+			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
2449
+
2450
+		}
2451
+
2406 2452
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
2407 2453
 		if deliver_number < (out_count - cancel_count) {
2408 2454
 
@@ -2475,14 +2521,14 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2475 2521
 				UserOrgId:               advice.UserOrgId,
2476 2522
 				PatientId:               advice.PatientId,
2477 2523
 				SystemTime:              advice.AdviceDate,
2478
-				ConsumableType:          16,
2524
+				ConsumableType:          7,
2479 2525
 				IsSys:                   0,
2480 2526
 				WarehousingOrder:        "",
2481 2527
 				WarehouseOutId:          0,
2482 2528
 				WarehouseOutOrderNumber: "",
2483 2529
 				IsEdit:                  0,
2484 2530
 				CancelStockId:           cancelStock.ID,
2485
-				CancelOrderNumber:       cancelStock.OrderNumber,
2531
+				CancelOrderNumber:       lastDrugCancelStock.OrderNumber,
2486 2532
 				Manufacturer:            warehouse.Manufacturer,
2487 2533
 				Dealer:                  warehouse.Dealer,
2488 2534
 				Creator:                 advice.ExecutionStaff,
@@ -2670,7 +2716,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2670 2716
 		var out_count int64
2671 2717
 		var cancel_count int64
2672 2718
 		//查询出库数据
2673
-		infoCountList, _ := FindDrugWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2719
+		infoCountList, _ := FindDrugSettleWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2674 2720
 		//查询退库数据
2675 2721
 		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2676 2722
 		for _, item := range infoCountList {
@@ -2791,14 +2837,14 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2791 2837
 				UserOrgId:               advice.UserOrgId,
2792 2838
 				PatientId:               advice.PatientId,
2793 2839
 				SystemTime:              advice.AdviceDate,
2794
-				ConsumableType:          16,
2840
+				ConsumableType:          7,
2795 2841
 				IsSys:                   0,
2796 2842
 				WarehousingOrder:        "",
2797 2843
 				WarehouseOutId:          0,
2798 2844
 				WarehouseOutOrderNumber: "",
2799 2845
 				IsEdit:                  0,
2800 2846
 				CancelStockId:           cancelStock.ID,
2801
-				CancelOrderNumber:       cancelStock.OrderNumber,
2847
+				CancelOrderNumber:       lastDrugCancelStock.OrderNumber,
2802 2848
 				Manufacturer:            warehouse.Manufacturer,
2803 2849
 				Dealer:                  warehouse.Dealer,
2804 2850
 				Creator:                 advice.ExecutionStaff,

+ 1 - 1
service/patient_service.go 查看文件

@@ -2517,7 +2517,7 @@ func GetAllPatientListByListOne(orgID int64) (patients []*models.VMMonitorPatien
2517 2517
 	patient_info_str, _ := redis.Get(key).Result()
2518 2518
 
2519 2519
 	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2520
-		err = readDb.Model(&models.VMMonitorPatients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
2520
+		err = readDb.Model(&models.VMMonitorPatients{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
2521 2521
 		if err != nil {
2522 2522
 			if err == gorm.ErrRecordNotFound {
2523 2523
 				return nil, nil

+ 1 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go 查看文件

@@ -215,6 +215,7 @@ type PrescriptionVM struct {
215 215
 	OxygenUptake               int64   `gorm:"column:oxygen_uptake" json:"oxygen_uptake" form:"oxygen_uptake"`
216 216
 	OxygenFlow                 string  `gorm:"column:oxygen_flow" json:"oxygen_flow" form:"oxygen_flow"`
217 217
 	OxygenTime                 string  `gorm:"column:oxygen_time" json:"oxygen_time" form:"oxygen_time"`
218
+	DialysisRemark             string  `gorm:"column:dialysis_remark" json:"dialysis_remark" form:"dialysis_remark"`
218 219
 }
219 220
 
220 221
 func (PrescriptionVM) TableName() string {

+ 7 - 1
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go 查看文件

@@ -57,7 +57,7 @@ func GetSchedules(orgID int64, schIDs []string) ([]*ScheduleVM, error) {
57 57
 		return nil, err
58 58
 	}
59 59
 	for _, item := range schedules {
60
-		if orgID != 10101 {
60
+		if orgID != 10101 && orgID != 10445 {
61 61
 			dialysis_count, _ := GetDialysisOrderCount(orgID, item.PatientID, item.ScheduleDate)
62 62
 
63 63
 			item.Patient.TotalDialysis = dialysis_count
@@ -227,6 +227,12 @@ func GetDialysisOrderCountEight(orgID int64, patient_id int64, recordDate int64)
227 227
 	return order, err
228 228
 }
229 229
 
230
+func GetDialysisOrderCountNight(orgID int64, patient_id int64, recordDate int64) (models.VmDialysisOrder, error) {
231
+	order := models.VmDialysisOrder{}
232
+	err := p_service.XTReadDB().Raw("SELECT Count(id) as count,Max(dialysis_date) as dialysis_date  from xt_dialysis_order where dialysis_date>=1672502400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND patient_id = ? and user_org_id = ?", recordDate, patient_id, orgID).Scan(&order).Error
233
+	return order, err
234
+}
235
+
230 236
 func GetOutStockTotalCountTwo(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
231 237
 
232 238
 	err = p_service.XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.record_time,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time<=? and `status` = 1)  as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error

+ 2 - 2
service/self_drug_service.go 查看文件

@@ -1516,7 +1516,7 @@ func GetGoodPatientList(orgid int64, keyword string) (patient []*models.XtPatien
1516 1516
 
1517 1517
 func GetWarehouseOutDetailByPatientIdOne(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (info []*models.WarehouseOutInfo, total int64, err error) {
1518 1518
 
1519
-	db := XTReadDB().Model(&info).Where("status = 1 and is_sys = 1")
1519
+	db := XTReadDB().Model(&info).Where("status = 1 and (is_sys = 1 or is_sys = 5)")
1520 1520
 	offset := (page - 1) * limit
1521 1521
 	if orgid > 0 {
1522 1522
 		db = db.Where("org_id = ?", orgid)
@@ -1536,7 +1536,7 @@ func GetWarehouseOutDetailByPatientIdOne(orgid int64, patient_id int64, startime
1536 1536
 
1537 1537
 func GetWarehouseOutDetailByPatientId(orgid int64, patient_id int64, startime int64, endtime int64) (info []*models.WarehouseOutInfo, err error) {
1538 1538
 
1539
-	db := XTReadDB().Model(&info).Where("status = 1 and is_sys = 1")
1539
+	db := XTReadDB().Model(&info).Where("status = 1 and (is_sys = 1 or is_sys =5)")
1540 1540
 	if orgid > 0 {
1541 1541
 		db = db.Where("org_id = ?", orgid)
1542 1542
 	}

+ 43 - 3
service/stock_service.go 查看文件

@@ -3883,16 +3883,30 @@ func UpdateAutoGood(orgid int64, patient_id int64, recordtime int64, goodid int6
3883 3883
 	return err
3884 3884
 }
3885 3885
 
3886
-func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64) error {
3886
+func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64, project_id int64) error {
3887 3887
 
3888 3888
 	detail := models.BloodAutomaticReduceDetail{}
3889 3889
 	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? ", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3890 3890
 	info := models.WarehouseOutInfo{}
3891
-	err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3891
+	err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3892 3892
 	prepare := models.DialysisBeforePrepare{}
3893 3893
 	err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3894 3894
 	flow := models.VmStockFlow{}
3895
-	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"is_read": 1}).Error
3895
+	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"is_read": 1}).Error
3896
+	return err
3897
+
3898
+}
3899
+
3900
+func DeleteAutoRedeceDetailTenOne(orgid int64, patient_id int64, recordtime int64, goodid int64, order_id int64) error {
3901
+
3902
+	detail := models.BloodAutomaticReduceDetail{}
3903
+	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? ", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3904
+	info := models.WarehouseOutInfo{}
3905
+	err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and order_id = ?", orgid, patient_id, recordtime, goodid, order_id).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3906
+	prepare := models.DialysisBeforePrepare{}
3907
+	err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3908
+	flow := models.VmStockFlow{}
3909
+	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and order_id = ?", orgid, patient_id, recordtime, goodid, order_id).Updates(map[string]interface{}{"is_read": 1}).Error
3896 3910
 	return err
3897 3911
 
3898 3912
 }
@@ -4009,6 +4023,12 @@ func GetGoodWarehouseInfoSeven(good_id int64) (info []*models.WarehousingInfoSev
4009 4023
 	return info, err
4010 4024
 }
4011 4025
 
4026
+func GetGoodWarehouseInfoSevenTen(good_id int64, storehouse_id int64) (info []*models.WarehousingInfoSeven, err error) {
4027
+
4028
+	err = readDb.Select("stock_count").Where("good_id = ? and status = 1 and stock_count<>0 and storehouse_id = ?", good_id, storehouse_id).Find(&info).Error
4029
+	return info, err
4030
+}
4031
+
4012 4032
 func GetAllStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.VmWarehousingInfo, total int64, err error) {
4013 4033
 
4014 4034
 	offset := (page - 1) * limit
@@ -5072,6 +5092,12 @@ func GetStockFlowIsBatchNumberThree(patient_id int64, record_time int64, good_id
5072 5092
 	return flow, nil
5073 5093
 }
5074 5094
 
5095
+func GetStockFlowIsBatchNumberFour(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.VmStockFlow, err error) {
5096
+
5097
+	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
5098
+	return flow, nil
5099
+}
5100
+
5075 5101
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
5076 5102
 
5077 5103
 	info := models.WarehouseOutInfo{}
@@ -8340,3 +8366,17 @@ func GetWarehouseOutInfoIsExistThree(good_id int64, patient_id int64, record_tim
8340 8366
 	err := XTReadDB().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
8341 8367
 	return info, err
8342 8368
 }
8369
+
8370
+func GetWarehouseOutInfoIsExistSix(good_id int64, patient_id int64, record_time int64, project_id int64) (*models.WarehouseOutInfo, error) {
8371
+
8372
+	info := models.WarehouseOutInfo{}
8373
+	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
8375
+	if err == gorm.ErrRecordNotFound {
8376
+		return nil, err
8377
+	}
8378
+	if err != nil {
8379
+		return nil, err
8380
+	}
8381
+	return &info, nil
8382
+}

+ 83 - 50
service/warhouse_service.go 查看文件

@@ -7493,7 +7493,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
7493 7493
 			return errThree
7494 7494
 		}
7495 7495
 		//查询剩余库存
7496
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
7496
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
7497 7497
 		var sum_count int64
7498 7498
 		for _, item := range goodList {
7499 7499
 			sum_count += item.StockCount
@@ -7721,7 +7721,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
7721 7721
 		if errThree != nil {
7722 7722
 			return errThree
7723 7723
 		}
7724
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
7724
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
7725 7725
 		var sum_count int64
7726 7726
 		for _, item := range goodList {
7727 7727
 			sum_count += item.StockCount
@@ -7936,7 +7936,8 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
7936 7936
 			return errThree
7937 7937
 		}
7938 7938
 		//查询剩余库存
7939
-		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID)
7939
+		houseConfig, _ := GetAllStoreHouseConfig(orgID)
7940
+		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
7940 7941
 		var sum_count int64
7941 7942
 		for _, item := range goodList {
7942 7943
 			sum_count += item.StockCount
@@ -7947,7 +7948,7 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
7947 7948
 		} else {
7948 7949
 			delete_count = ware.Count
7949 7950
 		}
7950
-		houseConfig, _ := GetAllStoreHouseConfig(orgID)
7951
+
7951 7952
 		// 在出库记录表里记录退库详情
7952 7953
 		warehouseOutInfo := &models.WarehouseOutInfo{
7953 7954
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -10209,6 +10210,7 @@ func AddWarehosingInfo(info *models.WarehousingInfo) error {
10209 10210
 // 药品出库 递归方式
10210 10211
 func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo, drugWarehouse *models.DrugWarehouseInfo) (err error) {
10211 10212
 
10213
+	fmt.Println("尽力2333223333233323322332")
10212 10214
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
10213 10215
 	var deliver_number int64 = 0
10214 10216
 	var stock_number int64 = 0
@@ -10222,8 +10224,10 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10222 10224
 	// 根据先进先出原则,查询最先入库的批次,进行出库
10223 10225
 	// 如果没有对应的库存,则报错
10224 10226
 	//开启事物
10225
-	storeConfig, _ := GetAllStoreHouseConfig(orgID)
10226
-	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
10227
+	//storeConfig, _ := GetAllStoreHouseConfig(orgID)
10228
+	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, warehouseout.StorehouseId)
10229
+	fmt.Println("lastWarehouse.StockMinNumber", lastWarehouse.StockMinNumber)
10230
+	fmt.Println("drup.MinNumber", drup.MinNumber)
10227 10231
 	if lastWarehouse.StockMinNumber >= drup.MinNumber {
10228 10232
 		var stockMax int64
10229 10233
 		var stockMin int64
@@ -10244,6 +10248,8 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10244 10248
 
10245 10249
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
10246 10250
 
10251
+	fmt.Println("stock23233233232", stock_number)
10252
+	fmt.Println("deliver_number", deliver_number)
10247 10253
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
10248 10254
 	if stock_number >= deliver_number {
10249 10255
 
@@ -10328,6 +10334,8 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10328 10334
 			maxNumber = prescribingNumber
10329 10335
 		}
10330 10336
 
10337
+		//fmt.Println("warehouse.StockMaxNumber",warehouse.StockMaxNumber)
10338
+		//fmt.Println("maxNumber9899923323232wo",maxNumber)
10331 10339
 		if warehouse.StockMaxNumber < maxNumber {
10332 10340
 
10333 10341
 			return errors.New("库存数量不足")
@@ -10347,22 +10355,11 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10347 10355
 			warehouse.StockMinNumber = 0
10348 10356
 		}
10349 10357
 
10358
+		fmt.Println("warehouse.StockMaxNumber323232323233232332", warehouse.StockMaxNumber)
10350 10359
 		if warehouse.StockMaxNumber < 0 {
10351 10360
 			return errors.New("库存数量不足")
10352 10361
 		}
10353 10362
 
10354
-		////扣减库存
10355
-		//if(warehouse.StockMaxNumber > 0){
10356
-		//  var sum_count int64
10357
-		//  sum_count = maxNumber * drup.MinNumber
10358
-		//  ModifyDrugReduceInformationSix(warehouse.DrugId,sum_count,warehouse.OrgId,warehouse.RetailPrice)
10359
-		//}
10360
-		//if(warehouse.StockMinNumber > 0){
10361
-		//  var sum_count int64
10362
-		//  sum_count = minNumber
10363
-		//  ModifyDrugReduceInformationSix(warehouse.DrugId,sum_count,warehouse.OrgId,warehouse.RetailPrice)
10364
-		//}
10365
-
10366 10363
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
10367 10364
 
10368 10365
 		if errThree != nil {
@@ -11306,7 +11303,7 @@ func ConsumablesDeliveryThirty(orgID int64, record_time int64, goods *models.War
11306 11303
 		}
11307 11304
 
11308 11305
 		//查询剩余库存
11309
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
11306
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
11310 11307
 		var sum_count int64
11311 11308
 		for _, item := range goodList {
11312 11309
 			sum_count += item.StockCount
@@ -11477,7 +11474,7 @@ func ConsumablesDeliveryThirty(orgID int64, record_time int64, goods *models.War
11477 11474
 		}
11478 11475
 
11479 11476
 		//查询剩余库存
11480
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
11477
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
11481 11478
 		var sum_count int64
11482 11479
 		for _, item := range goodList {
11483 11480
 			sum_count += item.StockCount
@@ -11773,6 +11770,7 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
11773 11770
 			OverCount:               over_count,
11774 11771
 			RetailPrice:             retail_price, //手动出库出库价格
11775 11772
 			WarehousingId:           warehouse.ID,
11773
+			SystemTime:              advice.SysRecordTime,
11776 11774
 		}
11777 11775
 		if warehouse.RetailPrice == 0 {
11778 11776
 			drugflow.Price = advice.Price
@@ -11840,6 +11838,7 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
11840 11838
 			RetailPrice:             retail_price, //手动出库出库价格
11841 11839
 			WarehousingId:           warehouse.ID,
11842 11840
 			WarehousingDetailId:     warehouse.ID,
11841
+			SystemTime:              advice.SysRecordTime,
11843 11842
 		}
11844 11843
 
11845 11844
 		CreateDrugFlowOne(drugflow)
@@ -11898,9 +11897,9 @@ func FindLastDrugWarehouseOutInfo(orgid int64) (models.DrugWarehouseOutInfo, err
11898 11897
 	return info, err
11899 11898
 }
11900 11899
 
11901
-func GetAllGoodSumCount(goodid int64, orgid int64) (info []*models.WarehousingInfo, err error) {
11900
+func GetAllGoodSumCount(goodid int64, orgid int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
11902 11901
 
11903
-	err = XTReadDB().Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0", goodid, orgid).Find(&info).Error
11902
+	err = XTReadDB().Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goodid, orgid, storehouse_id).Find(&info).Error
11904 11903
 	return info, err
11905 11904
 }
11906 11905
 
@@ -12265,6 +12264,9 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12265 12264
 	stock_number = warehouse.StockCount
12266 12265
 
12267 12266
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
12267
+
12268
+	fmt.Println("stock_numnber233232232323", stock_number)
12269
+	fmt.Println("deliver_nmuberwooeooo2oo23", deliver_number)
12268 12270
 	if stock_number >= deliver_number {
12269 12271
 		maxNumber = goods.Count
12270 12272
 		warehouse.StockCount = warehouse.StockCount - maxNumber
@@ -12291,7 +12293,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12291 12293
 		}
12292 12294
 
12293 12295
 		//查询剩余库存
12294
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12296
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12295 12297
 		var sum_count int64
12296 12298
 		for _, item := range goodList {
12297 12299
 			sum_count += item.StockCount
@@ -12496,7 +12498,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12496 12498
 		}
12497 12499
 
12498 12500
 		//查询剩余库存
12499
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12501
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12500 12502
 		var sum_count int64
12501 12503
 		for _, item := range goodList {
12502 12504
 			sum_count += item.StockCount
@@ -12531,7 +12533,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12531 12533
 			RegisterNumber:          warehouse.RegisterNumber,
12532 12534
 			OrderId:                 order_id,
12533 12535
 		}
12534
-		OutInfo.Count = goods.Count
12536
+		OutInfo.Count = stock_number
12535 12537
 
12536 12538
 		AddSigleWarehouseOutInfo(OutInfo)
12537 12539
 
@@ -12636,7 +12638,17 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12636 12638
 
12637 12639
 	goods.Count = deliver_number - stock_number
12638 12640
 	prepare := &models.DialysisBeforePrepare{
12639
-		Count: deliver_number - stock_number,
12641
+		Count:        deliver_number - stock_number,
12642
+		GoodTypeId:   goods.GoodTypeId,
12643
+		GoodId:       goods.GoodId,
12644
+		PatientId:    goods.PatientId,
12645
+		RecordDate:   goods.RecordDate,
12646
+		UserOrgId:    orgID,
12647
+		Ctime:        time.Now().Unix(),
12648
+		Creater:      goods.Creater,
12649
+		CommdityCode: goods.CommdityCode,
12650
+		Status:       1,
12651
+		StorehouseId: goods.StorehouseId,
12640 12652
 	}
12641 12653
 	ConsumableSettleDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator, order_id)
12642 12654
 
@@ -12644,12 +12656,12 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12644 12656
 }
12645 12657
 
12646 12658
 //保存处方出库
12647
-func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, creator int64) (err error) {
12659
+func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, creator int64, count int64) (err error) {
12648 12660
 
12649 12661
 	var deliver_number int64 = 0
12650 12662
 	var stock_number int64 = 0
12651 12663
 	var maxNumber int64 = 0
12652
-	fmt.Println("223323233233223233223233223woo", goods.Count)
12664
+
12653 12665
 	deliver_number = goods.Count
12654 12666
 
12655 12667
 	// 根据先进先出原则,查询最先入库的批次,进行出库
@@ -12676,6 +12688,8 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12676 12688
 
12677 12689
 	stock_number = warehouse.StockCount
12678 12690
 
12691
+	fmt.Println("sotck_number233223322o", stock_number)
12692
+	fmt.Println("deliver_number", deliver_number)
12679 12693
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
12680 12694
 	if stock_number >= deliver_number {
12681 12695
 		maxNumber = goods.Count
@@ -12703,7 +12717,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12703 12717
 		}
12704 12718
 
12705 12719
 		//查询剩余库存
12706
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12720
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12707 12721
 		var sum_count int64
12708 12722
 		for _, item := range goodList {
12709 12723
 			sum_count += item.StockCount
@@ -12760,9 +12774,9 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12760 12774
 			RegisterNumber:          warehouse.RegisterNumber,
12761 12775
 		}
12762 12776
 		fmt.Println("goods.count2323232233232233232322332322332", goods.Count)
12763
-		OutInfo.Count = goods.Count
12777
+		OutInfo.Count = count
12764 12778
 
12765
-		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
12779
+		_, errcodes := GetWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId)
12766 12780
 		if errcodes == gorm.ErrRecordNotFound {
12767 12781
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
12768 12782
 			if errOne != nil {
@@ -12771,7 +12785,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12771 12785
 		} else if errcodes == nil {
12772 12786
 
12773 12787
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
12774
-			if goods.Count != outInfoOne.Count {
12788
+			if count != outInfoOne.Count {
12775 12789
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
12776 12790
 			}
12777 12791
 
@@ -12780,6 +12794,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12780 12794
 		lastOut, _ := FindWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId)
12781 12795
 		//查询已经出库的数据
12782 12796
 		flowGood, _ := GetStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId)
12797
+		fmt.Println("flowgood23323223323222323wo", flowGood)
12783 12798
 		var out_count int64
12784 12799
 		var out_count_one int64
12785 12800
 		for _, item := range flowGood {
@@ -12787,22 +12802,23 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12787 12802
 		}
12788 12803
 
12789 12804
 		//查询退库数据
12790
-		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
12805
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberFour(patient_id, record_time, goods.GoodId, goods.ProjectId)
12791 12806
 		for _, item := range flowGoodTwo {
12792 12807
 			out_count_one += item.Count
12793 12808
 		}
12794 12809
 
12795 12810
 		//如果本次出库数据大于历史出库数据 新增1条流水
12796
-		fmt.Println("goods_count233232323223", goods.Count)
12797
-		fmt.Println("out_count - out_count_one", out_count-out_count_one)
12798
-		if goods.Count > (out_count - out_count_one) {
12811
+		fmt.Println("out_count23323233232wo", out_count)
12812
+		fmt.Println("goods_count233232323223", count)
12813
+		fmt.Println("out_count - out_count_one", out_count_one)
12814
+		if count > (out_count - out_count_one) {
12799 12815
 
12800 12816
 			stockFlow := models.VmStockFlow{
12801 12817
 				WarehousingId:           warehouse.ID,
12802 12818
 				GoodId:                  goods.GoodId,
12803 12819
 				Number:                  warehouse.Number,
12804 12820
 				LicenseNumber:           warehouse.LicenseNumber,
12805
-				Count:                   goods.Count - out_count + out_count_one,
12821
+				Count:                   count - out_count + out_count_one,
12806 12822
 				UserOrgId:               orgID,
12807 12823
 				PatientId:               goods.PatientId,
12808 12824
 				SystemTime:              record_time,
@@ -12878,7 +12894,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12878 12894
 
12879 12895
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
12880 12896
 
12881
-		if goods.Count < (out_count - out_count_one) {
12897
+		if count < (out_count - out_count_one) {
12882 12898
 
12883 12899
 			operation_time := time.Now().Unix()
12884 12900
 
@@ -12914,7 +12930,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12914 12930
 				GoodId:          goods.GoodId,
12915 12931
 				CancelStockId:   cancel.ID,
12916 12932
 				GoodTypeId:      goods.GoodTypeId,
12917
-				Count:           out_count - out_count_one - goods.Count,
12933
+				Count:           out_count - out_count_one - count,
12918 12934
 				Price:           warehouse.PackingPrice,
12919 12935
 				Total:           0,
12920 12936
 				ProductDate:     warehouse.ProductDate,
@@ -12948,7 +12964,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12948 12964
 				GoodId:                  goods.GoodId,
12949 12965
 				Number:                  warehouse.Number,
12950 12966
 				LicenseNumber:           warehouse.LicenseNumber,
12951
-				Count:                   out_count - out_count_one - goods.Count,
12967
+				Count:                   out_count - out_count_one - count,
12952 12968
 				UserOrgId:               orgID,
12953 12969
 				PatientId:               patient_id,
12954 12970
 				SystemTime:              record_time,
@@ -12988,6 +13004,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12988 13004
 
12989 13005
 			//退库数量增加
12990 13006
 			UpdateSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count)
13007
+			ModifyAddGoodSumCount(goods.StorehouseId, flow.Count, orgID, goods.GoodId)
12991 13008
 		}
12992 13009
 
12993 13010
 		//添加入库ID
@@ -13054,11 +13071,12 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13054 13071
 		}
13055 13072
 
13056 13073
 		//查询剩余库存
13057
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
13074
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
13058 13075
 		var sum_count int64
13059 13076
 		for _, item := range goodList {
13060 13077
 			sum_count += item.StockCount
13061 13078
 		}
13079
+		fmt.Println("剩余库存", sum_count)
13062 13080
 
13063 13081
 		OutInfo := &models.WarehouseOutInfo{
13064 13082
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -13088,9 +13106,9 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13088 13106
 			OverCount:               sum_count,
13089 13107
 			RegisterNumber:          warehouse.RegisterNumber,
13090 13108
 		}
13091
-		OutInfo.Count = goods.Count
13109
+		OutInfo.Count = stock_number
13092 13110
 
13093
-		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
13111
+		_, errcodes := GetWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId)
13094 13112
 		if errcodes == gorm.ErrRecordNotFound {
13095 13113
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
13096 13114
 			if errOne != nil {
@@ -13099,7 +13117,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13099 13117
 		} else if errcodes == nil {
13100 13118
 
13101 13119
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
13102
-			if goods.Count != outInfoOne.Count {
13120
+			if count != outInfoOne.Count {
13103 13121
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
13104 13122
 			}
13105 13123
 
@@ -13117,8 +13135,10 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13117 13135
 		for _, item := range flowGoodTwo {
13118 13136
 			out_count_one += item.Count
13119 13137
 		}
13138
+		fmt.Println("出库数量", stock_number)
13139
+		fmt.Println("历史出库数据", out_count-out_count_one)
13120 13140
 		//如果出库数量 大于 历史出库数据 新增1条流水
13121
-		if goods.Count > out_count-out_count_one {
13141
+		if count > out_count-out_count_one {
13122 13142
 			stockFlow := models.VmStockFlow{
13123 13143
 				WarehousingId:           warehouse.ID,
13124 13144
 				GoodId:                  goods.GoodId,
@@ -13201,7 +13221,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13201 13221
 		}
13202 13222
 
13203 13223
 		//退库
13204
-		if goods.Count < out_count-out_count_one {
13224
+		if count < out_count-out_count_one {
13205 13225
 
13206 13226
 			operation_time := time.Now().Unix()
13207 13227
 
@@ -13237,7 +13257,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13237 13257
 				GoodId:          goods.GoodId,
13238 13258
 				CancelStockId:   cancel.ID,
13239 13259
 				GoodTypeId:      goods.GoodTypeId,
13240
-				Count:           out_count - out_count_one - goods.Count,
13260
+				Count:           out_count - out_count_one - count,
13241 13261
 				Price:           warehouse.PackingPrice,
13242 13262
 				Total:           0,
13243 13263
 				ProductDate:     warehouse.ProductDate,
@@ -13271,7 +13291,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13271 13291
 				GoodId:                  goods.GoodId,
13272 13292
 				Number:                  warehouse.Number,
13273 13293
 				LicenseNumber:           warehouse.LicenseNumber,
13274
-				Count:                   out_count - goods.Count,
13294
+				Count:                   out_count - count,
13275 13295
 				UserOrgId:               orgID,
13276 13296
 				PatientId:               patient_id,
13277 13297
 				SystemTime:              record_time,
@@ -13311,6 +13331,8 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13311 13331
 
13312 13332
 			//退库数量增加
13313 13333
 			UpdateSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count)
13334
+			//实际出库减少
13335
+			ModifyAddGoodSumCount(goods.StorehouseId, flow.Count, orgID, goods.GoodId)
13314 13336
 		}
13315 13337
 
13316 13338
 		errWarehouse := UpdateGoodWarehouseOutById(goods.ID, warehouse.ID, orgID, sum_count)
@@ -13335,9 +13357,20 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13335 13357
 
13336 13358
 	goods.Count = deliver_number - stock_number
13337 13359
 	prepare := &models.DialysisBeforePrepare{
13338
-		Count: deliver_number - stock_number,
13360
+		Count:        deliver_number - stock_number,
13361
+		GoodTypeId:   goods.GoodTypeId,
13362
+		GoodId:       goods.GoodId,
13363
+		PatientId:    goods.PatientId,
13364
+		RecordDate:   goods.RecordDate,
13365
+		UserOrgId:    orgID,
13366
+		Ctime:        time.Now().Unix(),
13367
+		Creater:      creator,
13368
+		Status:       1,
13369
+		StorehouseId: goods.StorehouseId,
13370
+		ProjectId:    goods.ProjectId,
13339 13371
 	}
13340
-	ConsumablePrescriptionDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator)
13372
+	fmt.Println("剩余出库数量", prepare.Count)
13373
+	ConsumablePrescriptionDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator, count)
13341 13374
 
13342 13375
 	return nil
13343 13376
 }