Browse Source

11月9日库存管理

XMLWAN 1 year ago
parent
commit
d1f37fae78

+ 0 - 1
.idea/vcs.xml View File

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

+ 1 - 1
conf/app.conf View File

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

+ 1 - 1
controllers/data_api_controller.go View File

400
 	}
400
 	}
401
 	dataconfig.Module = module
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
 		if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
404
 		if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
405
 			utils.ErrorLog("title")
405
 			utils.ErrorLog("title")
406
 			code = enums.ErrorCodeParamWrong
406
 			code = enums.ErrorCodeParamWrong

+ 46 - 5
controllers/dialysis_api_controller.go View File

107
 	beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
107
 	beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
108
 
108
 
109
 	beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
109
 	beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
110
+
111
+	beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
110
 }
112
 }
111
 
113
 
112
 func (c *DialysisApiController) GetQueueCall() {
114
 func (c *DialysisApiController) GetQueueCall() {
321
 	water_machine := c.GetString("water_machine")
323
 	water_machine := c.GetString("water_machine")
322
 	add_amount, _ := c.GetFloat("add_amount")
324
 	add_amount, _ := c.GetFloat("add_amount")
323
 	reduce_amount, _ := c.GetFloat("reduce_amount")
325
 	reduce_amount, _ := c.GetFloat("reduce_amount")
326
+	dialysis_remark := c.GetString("dialysis_remark")
324
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
327
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
325
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
328
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
326
 
329
 
428
 		WaterMachine:               water_machine,
431
 		WaterMachine:               water_machine,
429
 		AddAmount:                  add_amount,
432
 		AddAmount:                  add_amount,
430
 		ReduceAmount:               reduce_amount,
433
 		ReduceAmount:               reduce_amount,
434
+		DialysisRemark:             dialysis_remark,
431
 	}
435
 	}
432
 
436
 
433
 	if appRole.UserType == 2 || appRole.UserType == 1 {
437
 	if appRole.UserType == 2 || appRole.UserType == 1 {
659
 	water_machine := c.GetString("water_machine")
663
 	water_machine := c.GetString("water_machine")
660
 	add_amount, _ := c.GetFloat("add_amount")
664
 	add_amount, _ := c.GetFloat("add_amount")
661
 	reduce_amount, _ := c.GetFloat("reduce_amount")
665
 	reduce_amount, _ := c.GetFloat("reduce_amount")
666
+	dialysis_remark := c.GetString("dialysis_remark")
662
 	var prescription_doctor int64
667
 	var prescription_doctor int64
663
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
668
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
664
 
669
 
778
 		WaterMachine:               water_machine,
783
 		WaterMachine:               water_machine,
779
 		AddAmount:                  add_amount,
784
 		AddAmount:                  add_amount,
780
 		ReduceAmount:               reduce_amount,
785
 		ReduceAmount:               reduce_amount,
786
+		DialysisRemark:             dialysis_remark,
781
 	}
787
 	}
782
 
788
 
783
 	//查询最近透析准备表里是否存在 透析器 灌流器
789
 	//查询最近透析准备表里是否存在 透析器 灌流器
948
 		OxygenTime:                 oxygen_time,
954
 		OxygenTime:                 oxygen_time,
949
 		PreImpulse:                 preImpules,
955
 		PreImpulse:                 preImpules,
950
 		SolutionStatus:             1,
956
 		SolutionStatus:             1,
957
+		DialysisRemark:             dialysis_remark,
951
 	}
958
 	}
952
 
959
 
953
 	//针对河间咸得
960
 	//针对河间咸得
4805
 					prescribing_number = parseIntPrescribingNumber
4812
 					prescribing_number = parseIntPrescribingNumber
4806
 				}
4813
 				}
4807
 				sum_out_count += prescribing_number
4814
 				sum_out_count += prescribing_number
4808
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId)
4815
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
4816
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
4809
 				//库存不足
4817
 				//库存不足
4810
 				if sum_out_count > drugStockOut.FlushCount {
4818
 				if sum_out_count > drugStockOut.FlushCount {
4811
 					this.ServeSuccessJSON(map[string]interface{}{
4819
 					this.ServeSuccessJSON(map[string]interface{}{
4952
 					prescribing_number = parseIntPrescribingNumber
4960
 					prescribing_number = parseIntPrescribingNumber
4953
 				}
4961
 				}
4954
 				sum_out_count += prescribing_number
4962
 				sum_out_count += prescribing_number
4955
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId)
4963
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
4964
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
4956
 				//库存不足
4965
 				//库存不足
4957
 				if sum_out_count > drugStockOut.FlushCount {
4966
 				if sum_out_count > drugStockOut.FlushCount {
4958
 					this.ServeSuccessJSON(map[string]interface{}{
4967
 					this.ServeSuccessJSON(map[string]interface{}{
5209
 		if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5218
 		if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5210
 			prescribing_number = parseIntPrescribingNumber
5219
 			prescribing_number = parseIntPrescribingNumber
5211
 		}
5220
 		}
5212
-
5213
-		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId)
5221
+		houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
5222
+		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
5214
 		//库存不足
5223
 		//库存不足
5215
 		if prescribing_number > drugStockOut.FlushCount {
5224
 		if prescribing_number > drugStockOut.FlushCount {
5216
 			this.ServeSuccessJSON(map[string]interface{}{
5225
 			this.ServeSuccessJSON(map[string]interface{}{
5349
 		if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5358
 		if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5350
 			prescribing_number = parseIntPrescribingNumber
5359
 			prescribing_number = parseIntPrescribingNumber
5351
 		}
5360
 		}
5352
-		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId)
5361
+		houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
5362
+		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
5353
 		//库存不足
5363
 		//库存不足
5354
 		if prescribing_number > drugStockOut.FlushCount {
5364
 		if prescribing_number > drugStockOut.FlushCount {
5355
 			this.ServeSuccessJSON(map[string]interface{}{
5365
 			this.ServeSuccessJSON(map[string]interface{}{
5442
 	return
5452
 	return
5443
 
5453
 
5444
 }
5454
 }
5455
+
5456
+func (this *DialysisApiController) GetDialysisAdviceToday() {
5457
+
5458
+	orgId := this.GetAdminUserInfo().CurrentOrgId
5459
+
5460
+	schedule_type, _ := this.GetInt64("schedule_type")
5461
+
5462
+	partion_type, _ := this.GetInt64("partion_type")
5463
+
5464
+	start_time := this.GetString("selected_date")
5465
+	timeLayout := "2006-01-02"
5466
+	loc, _ := time.LoadLocation("Local")
5467
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
5468
+
5469
+	list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, partion_type, startTime.Unix())
5470
+
5471
+	drug, _ := service.GetAllBaseDrugListTwenty(orgId)
5472
+	_, config := service.FindXTHisRecordByOrgId(orgId)
5473
+	if err == nil {
5474
+		this.ServeSuccessJSON(map[string]interface{}{
5475
+			"list":   list,
5476
+			"drug":   drug,
5477
+			"config": config,
5478
+		})
5479
+		return
5480
+
5481
+	} else {
5482
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
5483
+		return
5484
+	}
5485
+}

+ 6 - 0
controllers/dialysis_record_api_controller.go View File

1009
 	createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
1009
 	createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
1010
 	//更新患者表排班备注
1010
 	//更新患者表排班备注
1011
 	service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, patientID, schedule_remark)
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
+
1012
 	key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
1018
 	key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
1013
 	redis := service.RedisClient()
1019
 	redis := service.RedisClient()
1014
 	//清空key 值
1020
 	//清空key 值

+ 271 - 167
controllers/his_api_controller.go View File

988
 	//耗材保存处方出库
988
 	//耗材保存处方出库
989
 	goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
989
 	goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
990
 
990
 
991
+	settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
992
+
991
 	//已发药和已收费限制逻辑
993
 	//已发药和已收费限制逻辑
992
 	isMidicine := false
994
 	isMidicine := false
993
 	isCharge := false
995
 	isCharge := false
1048
 	}
1050
 	}
1049
 	//已发药和已收费限制逻辑
1051
 	//已发药和已收费限制逻辑
1050
 
1052
 
1051
-	if drugStockConfig.IsOpen == 1 {
1053
+	if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
1052
 		//校验库存总量
1054
 		//校验库存总量
1053
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1055
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1054
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
1056
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
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
 	if goodOutConfig.IsOpen != 1 {
1661
 	if goodOutConfig.IsOpen != 1 {
1569
 		if stockConfig.IsOpen == 1 {
1662
 		if stockConfig.IsOpen == 1 {
2190
 
2283
 
2191
 			//查询今日耗材出库数量
2284
 			//查询今日耗材出库数量
2192
 			hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
2285
 			hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
2286
+
2193
 			for _, item := range hisgoodlist {
2287
 			for _, item := range hisgoodlist {
2194
 				//查询耗材最后一次出库记录
2288
 				//查询耗材最后一次出库记录
2195
 				wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
2289
 				wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
2290
+				fmt.Println("hh23h232323o23o23o2o32o23o2o3o2o23o32o23o2o323o23o23o23o23o23o")
2291
+				//查询默认出库仓库库存
2292
+				storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
2196
 				if len(wareOut) > 0 {
2293
 				if len(wareOut) > 0 {
2294
+
2197
 					for _, it := range wareOut {
2295
 					for _, it := range wareOut {
2198
 						//回退库存
2296
 						//回退库存
2199
 						service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
2297
 						service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
2200
 						//删除出库记录
2298
 						//删除出库记录
2201
 						service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
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
 
2314
 
2215
 				operation_time := time.Now().Unix()
2315
 				operation_time := time.Now().Unix()
2216
 				creater := c.GetAdminUserInfo().AdminUser.Id
2316
 				creater := c.GetAdminUserInfo().AdminUser.Id
2217
-				//查询默认出库仓库库存
2218
-				storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
2317
+
2219
 				recordDateStr := time.Now().Format("2006-01-02")
2318
 				recordDateStr := time.Now().Format("2006-01-02")
2220
 				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
2319
 				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
2221
 				nowtime := recordDate.Unix()
2320
 				nowtime := recordDate.Unix()
2243
 				goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
2342
 				goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
2244
 				houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
2343
 				houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
2245
 				parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
2344
 				parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
2345
+
2246
 				dialyPrepareOne := models.DialysisBeforePrepare{
2346
 				dialyPrepareOne := models.DialysisBeforePrepare{
2247
 					GoodTypeId:   goodObj.GoodTypeId,
2347
 					GoodTypeId:   goodObj.GoodTypeId,
2248
 					GoodId:       item.ProjectId,
2348
 					GoodId:       item.ProjectId,
2257
 					ProjectId:    item.ID,
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
 				var sum_count int64
2364
 				var sum_count int64
2265
 				for _, item := range goodList {
2365
 				for _, item := range goodList {
2266
 					sum_count += item.StockCount
2366
 					sum_count += item.StockCount
2833
 
2933
 
2834
 							if prescribingNumber >= dialysisInfo.Count {
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
 				}
3017
 				}
2918
 			}
3018
 			}
2919
 
3019
 
2920
-			fmt.Println("goodOutConfig.IsOpen23232332233232232323232323", goodOutConfig.IsOpen)
2921
 			//保存耗材出库
3020
 			//保存耗材出库
2922
 			if goodOutConfig.IsOpen == 1 {
3021
 			if goodOutConfig.IsOpen == 1 {
2923
 
3022
 
2924
 				if item.Type == 3 {
3023
 				if item.Type == 3 {
3024
+					fmt.Println("出库数量99999999999999999999999999", item.Count)
2925
 					good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
3025
 					good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
2926
 					f_count, _ := strconv.ParseFloat(item.Count, 64)
3026
 					f_count, _ := strconv.ParseFloat(item.Count, 64)
2927
 					good.Total = good.Total + f_count
3027
 					good.Total = good.Total + f_count
2968
 					for _, it := range goodList {
3068
 					for _, it := range goodList {
2969
 						flush_count += it.StockCount
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
 					if info.ID > 0 {
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
 						dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
3223
 						dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
3132
 
3229
 
3133
 						if prescribingNumber >= dialysisInfo.Count {
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
 						goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
3235
 						goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
3570
 
3667
 
3571
 					if prescribingNumber >= dialysisInfo.Count {
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
 
3994
 
3898
 				if prescribingNumber >= dialysisInfo.Count {
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
 			}
5940
 			}
5844
 
5941
 
5845
 			for _, info := range prescriptionsOne {
5942
 			for _, info := range prescriptionsOne {
5943
+
5846
 				if info.Type == 1 {
5944
 				if info.Type == 1 {
5847
 					hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
5945
 					hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
5848
 				}
5946
 				}
5866
 
5964
 
5867
 			//判断
5965
 			//判断
5868
 			for _, itemOne := range infos {
5966
 			for _, itemOne := range infos {
5967
+
5869
 				for _, itemTwo := range hisAdvice {
5968
 				for _, itemTwo := range hisAdvice {
5870
 					if itemOne.DrugId == itemTwo.DrugId {
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
 					if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5988
 					if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5890
 						prescribing_number = parseIntPrescribingNumber
5989
 						prescribing_number = parseIntPrescribingNumber
5891
 					}
5990
 					}
5991
+
5892
 					sum_out_count += prescribing_number
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
 				if sum_out_count > drugStockOut.FlushCount {
5998
 				if sum_out_count > drugStockOut.FlushCount {
5897
 					c.ServeSuccessJSON(map[string]interface{}{
5999
 					c.ServeSuccessJSON(map[string]interface{}{
5898
 						"msg":  "2",
6000
 						"msg":  "2",
5901
 					return
6003
 					return
5902
 				}
6004
 				}
5903
 			}
6005
 			}
5904
-
6006
+			fmt.Println("newGoods99999988882os", newGoods)
5905
 			for _, itemOne := range newGoods {
6007
 			for _, itemOne := range newGoods {
5906
 				for _, item := range newGoodOne {
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
 			for _, item := range newGoodOne {
6015
 			for _, item := range newGoodOne {
5914
 				var sum_out_count_one int64
6016
 				var sum_out_count_one int64
5915
 				good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
6017
 				good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
5916
-
5917
 				for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
6018
 				for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
5918
 					sum_out_count_one += itemOne.Count
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
 				fmt.Println("sum_out_count_one", sum_out_count_one)
6022
 				fmt.Println("sum_out_count_one", sum_out_count_one)
5922
 				fmt.Println("list.FlushCount", list.FlushCount)
6023
 				fmt.Println("list.FlushCount", list.FlushCount)
5923
 				if sum_out_count_one > list.FlushCount {
6024
 				if sum_out_count_one > list.FlushCount {
6255
 
6356
 
6256
 						service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
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
 						var sum_count int64
6360
 						var sum_count int64
6260
 						for _, item := range goodList {
6361
 						for _, item := range goodList {
6261
 							sum_count += item.StockCount
6362
 							sum_count += item.StockCount
6433
 							}
6534
 							}
6434
 							sum_out_count += prescribing_number
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
 						if sum_out_count > drugStockOut.FlushCount {
6540
 						if sum_out_count > drugStockOut.FlushCount {
6439
 							c.ServeSuccessJSON(map[string]interface{}{
6541
 							c.ServeSuccessJSON(map[string]interface{}{
6459
 						for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
6561
 						for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
6460
 							sum_out_count_one += itemOne.Count
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
 						fmt.Println("sum_out_count_one", sum_out_count_one)
6565
 						fmt.Println("sum_out_count_one", sum_out_count_one)
6464
 						fmt.Println("list.FlushCount", list.FlushCount)
6566
 						fmt.Println("list.FlushCount", list.FlushCount)
6465
 						if sum_out_count_one > list.FlushCount {
6567
 						if sum_out_count_one > list.FlushCount {
6534
 			infos = append(infos, &info.HisDoctorAdviceInfo)
6636
 			infos = append(infos, &info.HisDoctorAdviceInfo)
6535
 		}
6637
 		}
6536
 		if info.ProjectId > 0 && info.AdviceId == 0 {
6638
 		if info.ProjectId > 0 && info.AdviceId == 0 {
6537
-			fmt.Println("info232323233232233", info.PatientId)
6639
+			fmt.Println("info232323233232233", order_id)
6538
 			if info.HisPrescriptionProject.Type == 3 {
6640
 			if info.HisPrescriptionProject.Type == 3 {
6539
 				var good models.DialysisBeforePrepareGoods
6641
 				var good models.DialysisBeforePrepareGoods
6540
 				var newGood models.NewDialysisBeforePrepareGoods
6642
 				var newGood models.NewDialysisBeforePrepareGoods
6545
 				good.StorehouseId = houseConfig.StorehouseOutInfo
6647
 				good.StorehouseId = houseConfig.StorehouseOutInfo
6546
 				good.ProjectId = info.HisPrescriptionProject.ID
6648
 				good.ProjectId = info.HisPrescriptionProject.ID
6547
 				good.PatientId = info.PatientId
6649
 				good.PatientId = info.PatientId
6650
+				good.OrderId = order_id
6548
 				goods = append(goods, &good)
6651
 				goods = append(goods, &good)
6549
 
6652
 
6550
 				newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
6653
 				newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
6556
 				newGood.RecordDate = order.SettleAccountsDate
6659
 				newGood.RecordDate = order.SettleAccountsDate
6557
 				newGood.UserOrgId = order.UserOrgId
6660
 				newGood.UserOrgId = order.UserOrgId
6558
 				newGood.PatientId = info.PatientId
6661
 				newGood.PatientId = info.PatientId
6662
+				newGood.OrderId = order_id
6559
 				newGoods = append(newGoods, &newGood)
6663
 				newGoods = append(newGoods, &newGood)
6560
 			}
6664
 			}
6561
 		}
6665
 		}

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

1385
 	water_machine := c.GetString("water_machine")
1385
 	water_machine := c.GetString("water_machine")
1386
 	add_amount, _ := c.GetFloat("add_amount")
1386
 	add_amount, _ := c.GetFloat("add_amount")
1387
 	reduce_amount, _ := c.GetFloat("reduce_amount")
1387
 	reduce_amount, _ := c.GetFloat("reduce_amount")
1388
+	dialysis_remark := c.GetString("dialysis_remark")
1388
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
1389
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
1389
 
1390
 
1390
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
1391
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
1497
 		WaterMachine:               water_machine,
1498
 		WaterMachine:               water_machine,
1498
 		AddAmount:                  add_amount,
1499
 		AddAmount:                  add_amount,
1499
 		ReduceAmount:               reduce_amount,
1500
 		ReduceAmount:               reduce_amount,
1501
+		DialysisRemark:             dialysis_remark,
1500
 	}
1502
 	}
1501
 
1503
 
1502
 	//查询最近透析准备表里是否存在 透析器 灌流器
1504
 	//查询最近透析准备表里是否存在 透析器 灌流器
1842
 		tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
1844
 		tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
1843
 		tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
1845
 		tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
1844
 		tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
1846
 		tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
1845
-		tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
1847
+		if adminUserInfo.Org.Id != 10445 {
1848
+			tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
1849
+		}
1850
+
1846
 		tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
1851
 		tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
1847
 
1852
 
1848
 	}
1853
 	}
2043
 		redis.Set(keyOne, "", time.Second)
2048
 		redis.Set(keyOne, "", time.Second)
2044
 		//结束时候透析次数加1
2049
 		//结束时候透析次数加1
2045
 		service.UpdateSolutionByPatientId(id)
2050
 		service.UpdateSolutionByPatientId(id)
2051
+
2046
 		dialysisOrder.Stage = 2
2052
 		dialysisOrder.Stage = 2
2047
 		dialysisOrder.FinishNurse = nurseID
2053
 		dialysisOrder.FinishNurse = nurseID
2048
 		dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
2054
 		dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
2339
 
2345
 
2340
 		createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
2346
 		createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
2341
 		service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
2347
 		service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
2348
+
2349
+		//统计该患者总次数
2350
+		dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
2351
+		service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
2342
 		redis := service.RedisClient()
2352
 		redis := service.RedisClient()
2343
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
2353
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
2344
 		redis.Set(key, "", time.Second)
2354
 		redis.Set(key, "", time.Second)
2633
 	drhy_water := c.GetString("drhy_water")
2643
 	drhy_water := c.GetString("drhy_water")
2634
 	dry_water_hour := c.GetString("dry_water_hour")
2644
 	dry_water_hour := c.GetString("dry_water_hour")
2635
 	water_machine := c.GetString("water_machine")
2645
 	water_machine := c.GetString("water_machine")
2646
+	dialysis_remark := c.GetString("dialysis_remark")
2636
 	if mode_id > 0 {
2647
 	if mode_id > 0 {
2637
 		service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
2648
 		service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
2638
 	}
2649
 	}
2746
 		WaterMachine:               water_machine,
2757
 		WaterMachine:               water_machine,
2747
 		AddAmount:                  add_amount,
2758
 		AddAmount:                  add_amount,
2748
 		ReduceAmount:               reduce_amount,
2759
 		ReduceAmount:               reduce_amount,
2760
+		DialysisRemark:             dialysis_remark,
2749
 	}
2761
 	}
2750
 
2762
 
2751
 	_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
2763
 	_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
2844
 		MaxUltrafiltrationRate:     max_ultrafiltration_rate,
2856
 		MaxUltrafiltrationRate:     max_ultrafiltration_rate,
2845
 		PreImpulse:                 impulse,
2857
 		PreImpulse:                 impulse,
2846
 		SolutionStatus:             1,
2858
 		SolutionStatus:             1,
2859
+		DialysisRemark:             dialysis_remark,
2847
 	}
2860
 	}
2848
 
2861
 
2849
 	//针对河间咸的
2862
 	//针对河间咸的
6722
 	//扣减出库数量
6735
 	//扣减出库数量
6723
 	service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
6736
 	service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
6724
 	//查询剩余库存
6737
 	//查询剩余库存
6725
-	goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID)
6738
+	goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
6726
 	var sum_count int64
6739
 	var sum_count int64
6727
 	for _, item := range goodList {
6740
 	for _, item := range goodList {
6728
 		sum_count += item.StockCount
6741
 		sum_count += item.StockCount
7165
 				}
7178
 				}
7166
 				sum_out_count += prescribing_number
7179
 				sum_out_count += prescribing_number
7167
 			}
7180
 			}
7168
-			drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId)
7181
+			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7182
+			drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
7169
 
7183
 
7170
 			//库存不足
7184
 			//库存不足
7171
 			if sum_out_count > drugStockOut.FlushCount {
7185
 			if sum_out_count > drugStockOut.FlushCount {
7285
 					}
7299
 					}
7286
 					sum_out_count += prescribing_number
7300
 					sum_out_count += prescribing_number
7287
 				}
7301
 				}
7288
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId)
7302
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7303
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
7289
 
7304
 
7290
 				//库存不足
7305
 				//库存不足
7291
 				if sum_out_count > drugStockOut.FlushCount {
7306
 				if sum_out_count > drugStockOut.FlushCount {
7627
 		if schedule.ID == 0 {
7642
 		if schedule.ID == 0 {
7628
 			this.ServeSuccessJSON(map[string]interface{}{
7643
 			this.ServeSuccessJSON(map[string]interface{}{
7629
 				"status": 0,
7644
 				"status": 0,
7645
+				"msg":    "请求失败",
7630
 			})
7646
 			})
7631
 
7647
 
7632
 		} else {
7648
 		} else {
7647
 					} else {
7663
 					} else {
7648
 						this.ServeSuccessJSON(map[string]interface{}{
7664
 						this.ServeSuccessJSON(map[string]interface{}{
7649
 							"status": 0,
7665
 							"status": 0,
7666
+							"msg":    "请求失败",
7650
 						})
7667
 						})
7651
 					}
7668
 					}
7652
 				}
7669
 				}
7663
 	} else {
7680
 	} else {
7664
 		this.ServeSuccessJSON(map[string]interface{}{
7681
 		this.ServeSuccessJSON(map[string]interface{}{
7665
 			"status": 0,
7682
 			"status": 0,
7683
+			"msg":    "请求失败",
7666
 		})
7684
 		})
7667
 
7685
 
7668
 	}
7686
 	}

+ 297 - 149
controllers/secondary_order_api_contorller.go View File

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
 	this.ServeSuccessJSON(map[string]interface{}{
1400
 	this.ServeSuccessJSON(map[string]interface{}{
1513
 		"msg": 1,
1401
 		"msg": 1,
1514
 	})
1402
 	})
1547
 	for _, item := range list {
1435
 	for _, item := range list {
1548
 		//药品
1436
 		//药品
1549
 		if item.IsSource == 1 {
1437
 		if item.IsSource == 1 {
1438
+
1550
 			medical, _ := service.GetBaseDrugMedical(item.ProjectId)
1439
 			medical, _ := service.GetBaseDrugMedical(item.ProjectId)
1551
 			//查询该仓库的药品库存是否满足调出数量
1440
 			//查询该仓库的药品库存是否满足调出数量
1552
 			drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
1441
 			drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
1568
 			}
1457
 			}
1569
 
1458
 
1570
 			if total_count > total {
1459
 			if total_count > total {
1460
+
1571
 				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
1461
 				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
1572
 				storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
1462
 				storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
1573
 				this.ServeSuccessJSON(map[string]interface{}{
1463
 				this.ServeSuccessJSON(map[string]interface{}{
1639
 				total_count = item.Count
1529
 				total_count = item.Count
1640
 			}
1530
 			}
1641
 
1531
 
1532
+			fmt.Println("total_count2332232333233223", total_count)
1533
+			fmt.Println("totoal2323232332322332", total)
1642
 			if total_count <= total {
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
 			//满足调拨
1745
 			//满足调拨
1717
 			if item.Count <= total {
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 View File

849
 	NucleinDate                int64         `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
849
 	NucleinDate                int64         `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
850
 	ScheduleRemark             string        `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
850
 	ScheduleRemark             string        `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
851
 	OrderRemark                string        `gorm:"column:order_remark" json:"order_remark" form:"order_remark"`
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
 func (DialysisOrder) TableName() string {
855
 func (DialysisOrder) TableName() string {
1096
 	ProjectId         int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
1097
 	ProjectId         int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
1097
 	StorehouseId      int64  `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
1098
 	StorehouseId      int64  `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
1098
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
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
 type NewDialysisBeforePrepareGoods struct {
1103
 type NewDialysisBeforePrepareGoods struct {
1111
 	UserOrgId                          int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1113
 	UserOrgId                          int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1112
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1114
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1113
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
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
 type OldDialysisBeforePrepareGoods struct {
1119
 type OldDialysisBeforePrepareGoods struct {
1385
 func (XtDialysisOrderSix) TableName() string {
1388
 func (XtDialysisOrderSix) TableName() string {
1386
 	return "xt_dialysis_order"
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
+}

+ 60 - 0
models/drug_stock.go View File

587
 func (XtDrugWarehouseFlushInfo) TableName() string {
587
 func (XtDrugWarehouseFlushInfo) TableName() string {
588
 	return "xt_drug_warehouse_flush_info"
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
+}

+ 2 - 0
models/patient_models.go View File

356
 	WaterMachine               string        `gorm:"column:water_machine" json:"water_machine" form:"water_machine"`
356
 	WaterMachine               string        `gorm:"column:water_machine" json:"water_machine" form:"water_machine"`
357
 	AddAmount                  float64       `gorm:"column:add_amount" json:"add_amount" form:"add_amount"`
357
 	AddAmount                  float64       `gorm:"column:add_amount" json:"add_amount" form:"add_amount"`
358
 	ReduceAmount               float64       `gorm:"column:reduce_amount" json:"reduce_amount" form:"reduce_amount"`
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
 func (DialysisPrescription) TableName() string {
362
 func (DialysisPrescription) TableName() string {
562
 	MaxUltrafiltrationRate     float64 `gorm:"column:max_ultrafiltration_rate" json:"max_ultrafiltration_rate" form:"max_ultrafiltration_rate"`
563
 	MaxUltrafiltrationRate     float64 `gorm:"column:max_ultrafiltration_rate" json:"max_ultrafiltration_rate" form:"max_ultrafiltration_rate"`
563
 	PreImpulse                 float64 `gorm:"column:pre_impulse" json:"pre_impulse" form:"pre_impulse"`
564
 	PreImpulse                 float64 `gorm:"column:pre_impulse" json:"pre_impulse" form:"pre_impulse"`
564
 	SolutionStatus             int64   `gorm:"column:solution_status" json:"solution_status" form:"solution_status"`
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
 func (DialysisSolution) TableName() string {
569
 func (DialysisSolution) TableName() string {

+ 24 - 0
models/schedule_models.go View File

523
 func (ScheduleTwentyOne) TableName() string {
523
 func (ScheduleTwentyOne) TableName() string {
524
 	return "xt_schedule"
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 View File

152
 }
152
 }
153
 
153
 
154
 type WarehousingInfoSeven struct {
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
 func (WarehousingInfoSeven) TableName() string {
159
 func (WarehousingInfoSeven) TableName() string {

+ 20 - 8
service/dialysis_solution_service.go View File

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
 	if scheduleDate > 0 {
223
 	if scheduleDate > 0 {
224
 		db = db.Where("schedule_date = ?", scheduleDate)
224
 		db = db.Where("schedule_date = ?", scheduleDate)
235
 	err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
235
 	err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
236
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
236
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
237
 		Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
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
 	return schedule, err
242
 	return schedule, err
242
 
243
 
364
 }
365
 }
365
 
366
 
366
 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
 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
 	db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
368
 	db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
369
 	offset := (page - 1) * limit
369
 	offset := (page - 1) * limit
370
 	if scheduleDate > 0 {
370
 	if scheduleDate > 0 {
391
 			Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
391
 			Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
392
 				return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
392
 				return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
393
 					return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
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
 			Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
405
 			Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
406
 				return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
406
 				return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
407
 					return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
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
 			}).Find(&schedule).Error
411
 			}).Find(&schedule).Error
437
 		Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
437
 		Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
438
 			return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
438
 			return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
439
 				return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
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
 		}).Find(&schedule).Error
443
 		}).Find(&schedule).Error
444
 
444
 
445
 	return schedule, err
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
+}

+ 1 - 1
service/gobal_config_service.go View File

945
 	return stockflow, err
945
 	return stockflow, err
946
 }
946
 }
947
 
947
 
948
-func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
948
+func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlowNight, err error) {
949
 
949
 
950
 	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
950
 	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
951
 	return drugFlow, err
951
 	return drugFlow, err

+ 4 - 4
service/his_service.go View File

2676
 	return
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
 	drug := models.XtDrugStockCount{}
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
 	return drug, err
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
 	stockCount := models.XtGoodStockCount{}
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
 	return stockCount, err
2692
 	return stockCount, err
2693
 }
2693
 }
2694
 
2694
 

+ 26 - 10
service/manage_center_service.go View File

2
 
2
 
3
 import (
3
 import (
4
 	"XT_New/models"
4
 	"XT_New/models"
5
+	"fmt"
5
 	"github.com/jinzhu/gorm"
6
 	"github.com/jinzhu/gorm"
6
 	"strconv"
7
 	"strconv"
7
 	"strings"
8
 	"strings"
210
 	return detail, err
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
 func GetDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.DrugWarehouseOutInfo, err error) {
220
 func GetDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.DrugWarehouseOutInfo, err error) {
214
 
221
 
215
 	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
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
 
437
 
431
 func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
438
 func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
432
 
439
 
433
-	//查询该病人该药品是否有库存记录
440
+	//查询该批次病人该药品出库数据
434
 	info, _ := GetDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
441
 	info, _ := GetDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
435
-
436
 	list, _ := GetDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
442
 	list, _ := GetDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
437
 
443
 
444
+	fmt.Println("lsit233323232323233232332wo", list)
438
 	storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
445
 	storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
439
 	//退库
446
 	//退库
440
 	drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
447
 	drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
442
 	//如果剩余数量 + 退库数量 < 总入库数量
449
 	//如果剩余数量 + 退库数量 < 总入库数量
443
 	if len(list) > 0 {
450
 	if len(list) > 0 {
444
 		for _, its := range list {
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
 			var out_count int64  //该批次出库库存
460
 			var out_count int64  //该批次出库库存
449
 			var sum_count int64  //该批次总库存
461
 			var sum_count int64  //该批次总库存
450
 			var over_count int64 //剩余数量
462
 			var over_count int64 //剩余数量
451
 
463
 
452
 			over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
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
 				out_count = info.Count * drug.MinNumber
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
 			if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
477
 			if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
474
 				sum_count = druginfo.WarehousingCount
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
 			if (over_count + out_count) <= sum_count {
492
 			if (over_count + out_count) <= sum_count {
478
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
493
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
479
 
494
 
891
 
906
 
892
 func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
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
 	if len(info) > 0 {
912
 	if len(info) > 0 {
897
 		houseConfig, _ := GetAllStoreHouseConfig(good.UserOrgId)
913
 		houseConfig, _ := GetAllStoreHouseConfig(good.UserOrgId)
898
 
914
 
1001
 			//出库数量减少
1017
 			//出库数量减少
1002
 			UpdateSumCount(good.UserOrgId, houseConfig.StorehouseOutInfo, good.GoodId, good.Count)
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
 			goodListOne, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
1022
 			goodListOne, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
1007
 			var flush_count int64
1023
 			var flush_count int64

+ 19 - 0
service/mobile_dialysis_service.go View File

5188
 	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
5188
 	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
 	return err
5189
 	return err
5190
 }
5190
 }
5191
+
5192
+func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
5193
+
5194
+	order := models.BloodDialysisOrderCount{}
5195
+	db := XTReadDB().Table("xt_dialysis_order as o")
5196
+
5197
+	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
5198
+
5199
+	return order, err
5200
+}
5201
+
5202
+func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
5203
+
5204
+	order := models.DialysisOrder{}
5205
+
5206
+	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
5207
+
5208
+	return order, err
5209
+}

+ 2 - 2
service/new_stock_service.go View File

370
 	return err
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
 	return outinfo, err
376
 	return outinfo, err
377
 }
377
 }
378
 
378
 

+ 56 - 10
service/new_warehouse_service.go View File

50
 		UpdateHisPrescriptionProjectStatus(goods.GoodId, record_time, orgID, patient_id)
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
 		var sum_count int64
54
 		var sum_count int64
55
 		for _, item := range goodList {
55
 		for _, item := range goodList {
56
 			sum_count += item.StockCount
56
 			sum_count += item.StockCount
312
 		if errThree != nil {
312
 		if errThree != nil {
313
 			return errThree
313
 			return errThree
314
 		}
314
 		}
315
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
315
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
316
 		var sum_count int64
316
 		var sum_count int64
317
 		for _, item := range goodList {
317
 		for _, item := range goodList {
318
 			sum_count += item.StockCount
318
 			sum_count += item.StockCount
1457
 
1457
 
1458
 		//查询今日该药品该患者是否有出库数据
1458
 		//查询今日该药品该患者是否有出库数据
1459
 		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
1459
 		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
1460
-		fmt.Println("lastDrugOutInfowwowowowoowowowowowowowowo", lastDrugOutInfo.ID)
1461
 		if lastDrugOutInfo.ID == 0 {
1460
 		if lastDrugOutInfo.ID == 0 {
1462
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1461
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1463
 			if errOne != nil {
1462
 			if errOne != nil {
1997
 func GetSigleDrugWarehouseOutInfoOne(patient_id int64, advice_date int64, orgid int64) (models.XtDrugWarehouseOutInfo, error) {
1996
 func GetSigleDrugWarehouseOutInfoOne(patient_id int64, advice_date int64, orgid int64) (models.XtDrugWarehouseOutInfo, error) {
1998
 
1997
 
1999
 	info := models.XtDrugWarehouseOutInfo{}
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
 	return info, err
2000
 	return info, err
2002
 }
2001
 }
2003
 
2002
 
2069
 	return flow, err
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
 func FindDrugCancelOutInfo(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64) (flow []*models.DrugFlow, err error) {
2077
 func FindDrugCancelOutInfo(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64) (flow []*models.DrugFlow, err error) {
2073
 	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
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
 	return flow, err
2079
 	return flow, err
2191
 	}
2196
 	}
2192
 
2197
 
2193
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2198
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2199
+	fmt.Println("stock_nbumber3223323232", stock_number)
2200
+	fmt.Println("deliver_number", deliver_number)
2194
 	if stock_number >= deliver_number {
2201
 	if stock_number >= deliver_number {
2195
 
2202
 
2196
 		var maxNumber int64 = 0
2203
 		var maxNumber int64 = 0
2349
 		var out_count int64
2356
 		var out_count int64
2350
 		var cancel_count int64
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
 		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2361
 		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2355
 		for _, item := range infoCountList {
2362
 		for _, item := range infoCountList {
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
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
2452
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
2407
 		if deliver_number < (out_count - cancel_count) {
2453
 		if deliver_number < (out_count - cancel_count) {
2408
 
2454
 
2475
 				UserOrgId:               advice.UserOrgId,
2521
 				UserOrgId:               advice.UserOrgId,
2476
 				PatientId:               advice.PatientId,
2522
 				PatientId:               advice.PatientId,
2477
 				SystemTime:              advice.AdviceDate,
2523
 				SystemTime:              advice.AdviceDate,
2478
-				ConsumableType:          16,
2524
+				ConsumableType:          7,
2479
 				IsSys:                   0,
2525
 				IsSys:                   0,
2480
 				WarehousingOrder:        "",
2526
 				WarehousingOrder:        "",
2481
 				WarehouseOutId:          0,
2527
 				WarehouseOutId:          0,
2482
 				WarehouseOutOrderNumber: "",
2528
 				WarehouseOutOrderNumber: "",
2483
 				IsEdit:                  0,
2529
 				IsEdit:                  0,
2484
 				CancelStockId:           cancelStock.ID,
2530
 				CancelStockId:           cancelStock.ID,
2485
-				CancelOrderNumber:       cancelStock.OrderNumber,
2531
+				CancelOrderNumber:       lastDrugCancelStock.OrderNumber,
2486
 				Manufacturer:            warehouse.Manufacturer,
2532
 				Manufacturer:            warehouse.Manufacturer,
2487
 				Dealer:                  warehouse.Dealer,
2533
 				Dealer:                  warehouse.Dealer,
2488
 				Creator:                 advice.ExecutionStaff,
2534
 				Creator:                 advice.ExecutionStaff,
2670
 		var out_count int64
2716
 		var out_count int64
2671
 		var cancel_count int64
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
 		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2721
 		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2676
 		for _, item := range infoCountList {
2722
 		for _, item := range infoCountList {
2791
 				UserOrgId:               advice.UserOrgId,
2837
 				UserOrgId:               advice.UserOrgId,
2792
 				PatientId:               advice.PatientId,
2838
 				PatientId:               advice.PatientId,
2793
 				SystemTime:              advice.AdviceDate,
2839
 				SystemTime:              advice.AdviceDate,
2794
-				ConsumableType:          16,
2840
+				ConsumableType:          7,
2795
 				IsSys:                   0,
2841
 				IsSys:                   0,
2796
 				WarehousingOrder:        "",
2842
 				WarehousingOrder:        "",
2797
 				WarehouseOutId:          0,
2843
 				WarehouseOutId:          0,
2798
 				WarehouseOutOrderNumber: "",
2844
 				WarehouseOutOrderNumber: "",
2799
 				IsEdit:                  0,
2845
 				IsEdit:                  0,
2800
 				CancelStockId:           cancelStock.ID,
2846
 				CancelStockId:           cancelStock.ID,
2801
-				CancelOrderNumber:       cancelStock.OrderNumber,
2847
+				CancelOrderNumber:       lastDrugCancelStock.OrderNumber,
2802
 				Manufacturer:            warehouse.Manufacturer,
2848
 				Manufacturer:            warehouse.Manufacturer,
2803
 				Dealer:                  warehouse.Dealer,
2849
 				Dealer:                  warehouse.Dealer,
2804
 				Creator:                 advice.ExecutionStaff,
2850
 				Creator:                 advice.ExecutionStaff,

+ 2 - 2
service/self_drug_service.go View File

1516
 
1516
 
1517
 func GetWarehouseOutDetailByPatientIdOne(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (info []*models.WarehouseOutInfo, total int64, err error) {
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
 	offset := (page - 1) * limit
1520
 	offset := (page - 1) * limit
1521
 	if orgid > 0 {
1521
 	if orgid > 0 {
1522
 		db = db.Where("org_id = ?", orgid)
1522
 		db = db.Where("org_id = ?", orgid)
1536
 
1536
 
1537
 func GetWarehouseOutDetailByPatientId(orgid int64, patient_id int64, startime int64, endtime int64) (info []*models.WarehouseOutInfo, err error) {
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
 	if orgid > 0 {
1540
 	if orgid > 0 {
1541
 		db = db.Where("org_id = ?", orgid)
1541
 		db = db.Where("org_id = ?", orgid)
1542
 	}
1542
 	}

+ 43 - 3
service/stock_service.go View File

3883
 	return err
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
 	detail := models.BloodAutomaticReduceDetail{}
3888
 	detail := models.BloodAutomaticReduceDetail{}
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
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
 	info := models.WarehouseOutInfo{}
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
 	prepare := models.DialysisBeforePrepare{}
3892
 	prepare := models.DialysisBeforePrepare{}
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
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
 	flow := models.VmStockFlow{}
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
 	return err
3910
 	return err
3897
 
3911
 
3898
 }
3912
 }
4009
 	return info, err
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
 func GetAllStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.VmWarehousingInfo, total int64, err error) {
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
 	offset := (page - 1) * limit
4034
 	offset := (page - 1) * limit
5072
 	return flow, nil
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
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
5101
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
5076
 
5102
 
5077
 	info := models.WarehouseOutInfo{}
5103
 	info := models.WarehouseOutInfo{}
8340
 	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
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
 	return info, err
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 View File

7493
 			return errThree
7493
 			return errThree
7494
 		}
7494
 		}
7495
 		//查询剩余库存
7495
 		//查询剩余库存
7496
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
7496
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
7497
 		var sum_count int64
7497
 		var sum_count int64
7498
 		for _, item := range goodList {
7498
 		for _, item := range goodList {
7499
 			sum_count += item.StockCount
7499
 			sum_count += item.StockCount
7721
 		if errThree != nil {
7721
 		if errThree != nil {
7722
 			return errThree
7722
 			return errThree
7723
 		}
7723
 		}
7724
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
7724
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
7725
 		var sum_count int64
7725
 		var sum_count int64
7726
 		for _, item := range goodList {
7726
 		for _, item := range goodList {
7727
 			sum_count += item.StockCount
7727
 			sum_count += item.StockCount
7936
 			return errThree
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
 		var sum_count int64
7941
 		var sum_count int64
7941
 		for _, item := range goodList {
7942
 		for _, item := range goodList {
7942
 			sum_count += item.StockCount
7943
 			sum_count += item.StockCount
7947
 		} else {
7948
 		} else {
7948
 			delete_count = ware.Count
7949
 			delete_count = ware.Count
7949
 		}
7950
 		}
7950
-		houseConfig, _ := GetAllStoreHouseConfig(orgID)
7951
+
7951
 		// 在出库记录表里记录退库详情
7952
 		// 在出库记录表里记录退库详情
7952
 		warehouseOutInfo := &models.WarehouseOutInfo{
7953
 		warehouseOutInfo := &models.WarehouseOutInfo{
7953
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
7954
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
10209
 // 药品出库 递归方式
10210
 // 药品出库 递归方式
10210
 func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo, drugWarehouse *models.DrugWarehouseInfo) (err error) {
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
 	var deliver_number int64 = 0
10215
 	var deliver_number int64 = 0
10214
 	var stock_number int64 = 0
10216
 	var stock_number int64 = 0
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
 	if lastWarehouse.StockMinNumber >= drup.MinNumber {
10231
 	if lastWarehouse.StockMinNumber >= drup.MinNumber {
10228
 		var stockMax int64
10232
 		var stockMax int64
10229
 		var stockMin int64
10233
 		var stockMin int64
10244
 
10248
 
10245
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
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
 	if stock_number >= deliver_number {
10254
 	if stock_number >= deliver_number {
10249
 
10255
 
10328
 			maxNumber = prescribingNumber
10334
 			maxNumber = prescribingNumber
10329
 		}
10335
 		}
10330
 
10336
 
10337
+		//fmt.Println("warehouse.StockMaxNumber",warehouse.StockMaxNumber)
10338
+		//fmt.Println("maxNumber9899923323232wo",maxNumber)
10331
 		if warehouse.StockMaxNumber < maxNumber {
10339
 		if warehouse.StockMaxNumber < maxNumber {
10332
 
10340
 
10333
 			return errors.New("库存数量不足")
10341
 			return errors.New("库存数量不足")
10347
 			warehouse.StockMinNumber = 0
10355
 			warehouse.StockMinNumber = 0
10348
 		}
10356
 		}
10349
 
10357
 
10358
+		fmt.Println("warehouse.StockMaxNumber323232323233232332", warehouse.StockMaxNumber)
10350
 		if warehouse.StockMaxNumber < 0 {
10359
 		if warehouse.StockMaxNumber < 0 {
10351
 			return errors.New("库存数量不足")
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
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
10363
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
10367
 
10364
 
10368
 		if errThree != nil {
10365
 		if errThree != nil {
11306
 		}
11303
 		}
11307
 
11304
 
11308
 		//查询剩余库存
11305
 		//查询剩余库存
11309
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
11306
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
11310
 		var sum_count int64
11307
 		var sum_count int64
11311
 		for _, item := range goodList {
11308
 		for _, item := range goodList {
11312
 			sum_count += item.StockCount
11309
 			sum_count += item.StockCount
11477
 		}
11474
 		}
11478
 
11475
 
11479
 		//查询剩余库存
11476
 		//查询剩余库存
11480
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
11477
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
11481
 		var sum_count int64
11478
 		var sum_count int64
11482
 		for _, item := range goodList {
11479
 		for _, item := range goodList {
11483
 			sum_count += item.StockCount
11480
 			sum_count += item.StockCount
11773
 			OverCount:               over_count,
11770
 			OverCount:               over_count,
11774
 			RetailPrice:             retail_price, //手动出库出库价格
11771
 			RetailPrice:             retail_price, //手动出库出库价格
11775
 			WarehousingId:           warehouse.ID,
11772
 			WarehousingId:           warehouse.ID,
11773
+			SystemTime:              advice.SysRecordTime,
11776
 		}
11774
 		}
11777
 		if warehouse.RetailPrice == 0 {
11775
 		if warehouse.RetailPrice == 0 {
11778
 			drugflow.Price = advice.Price
11776
 			drugflow.Price = advice.Price
11840
 			RetailPrice:             retail_price, //手动出库出库价格
11838
 			RetailPrice:             retail_price, //手动出库出库价格
11841
 			WarehousingId:           warehouse.ID,
11839
 			WarehousingId:           warehouse.ID,
11842
 			WarehousingDetailId:     warehouse.ID,
11840
 			WarehousingDetailId:     warehouse.ID,
11841
+			SystemTime:              advice.SysRecordTime,
11843
 		}
11842
 		}
11844
 
11843
 
11845
 		CreateDrugFlowOne(drugflow)
11844
 		CreateDrugFlowOne(drugflow)
11898
 	return info, err
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
 	return info, err
11903
 	return info, err
11905
 }
11904
 }
11906
 
11905
 
12265
 	stock_number = warehouse.StockCount
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
 	if stock_number >= deliver_number {
12270
 	if stock_number >= deliver_number {
12269
 		maxNumber = goods.Count
12271
 		maxNumber = goods.Count
12270
 		warehouse.StockCount = warehouse.StockCount - maxNumber
12272
 		warehouse.StockCount = warehouse.StockCount - maxNumber
12291
 		}
12293
 		}
12292
 
12294
 
12293
 		//查询剩余库存
12295
 		//查询剩余库存
12294
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12296
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12295
 		var sum_count int64
12297
 		var sum_count int64
12296
 		for _, item := range goodList {
12298
 		for _, item := range goodList {
12297
 			sum_count += item.StockCount
12299
 			sum_count += item.StockCount
12496
 		}
12498
 		}
12497
 
12499
 
12498
 		//查询剩余库存
12500
 		//查询剩余库存
12499
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12501
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12500
 		var sum_count int64
12502
 		var sum_count int64
12501
 		for _, item := range goodList {
12503
 		for _, item := range goodList {
12502
 			sum_count += item.StockCount
12504
 			sum_count += item.StockCount
12531
 			RegisterNumber:          warehouse.RegisterNumber,
12533
 			RegisterNumber:          warehouse.RegisterNumber,
12532
 			OrderId:                 order_id,
12534
 			OrderId:                 order_id,
12533
 		}
12535
 		}
12534
-		OutInfo.Count = goods.Count
12536
+		OutInfo.Count = stock_number
12535
 
12537
 
12536
 		AddSigleWarehouseOutInfo(OutInfo)
12538
 		AddSigleWarehouseOutInfo(OutInfo)
12537
 
12539
 
12636
 
12638
 
12637
 	goods.Count = deliver_number - stock_number
12639
 	goods.Count = deliver_number - stock_number
12638
 	prepare := &models.DialysisBeforePrepare{
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
 	ConsumableSettleDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator, order_id)
12653
 	ConsumableSettleDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator, order_id)
12642
 
12654
 
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
 	var deliver_number int64 = 0
12661
 	var deliver_number int64 = 0
12650
 	var stock_number int64 = 0
12662
 	var stock_number int64 = 0
12651
 	var maxNumber int64 = 0
12663
 	var maxNumber int64 = 0
12652
-	fmt.Println("223323233233223233223233223woo", goods.Count)
12664
+
12653
 	deliver_number = goods.Count
12665
 	deliver_number = goods.Count
12654
 
12666
 
12655
 	// 根据先进先出原则,查询最先入库的批次,进行出库
12667
 	// 根据先进先出原则,查询最先入库的批次,进行出库
12676
 
12688
 
12677
 	stock_number = warehouse.StockCount
12689
 	stock_number = warehouse.StockCount
12678
 
12690
 
12691
+	fmt.Println("sotck_number233223322o", stock_number)
12692
+	fmt.Println("deliver_number", deliver_number)
12679
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
12693
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
12680
 	if stock_number >= deliver_number {
12694
 	if stock_number >= deliver_number {
12681
 		maxNumber = goods.Count
12695
 		maxNumber = goods.Count
12703
 		}
12717
 		}
12704
 
12718
 
12705
 		//查询剩余库存
12719
 		//查询剩余库存
12706
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12720
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12707
 		var sum_count int64
12721
 		var sum_count int64
12708
 		for _, item := range goodList {
12722
 		for _, item := range goodList {
12709
 			sum_count += item.StockCount
12723
 			sum_count += item.StockCount
12760
 			RegisterNumber:          warehouse.RegisterNumber,
12774
 			RegisterNumber:          warehouse.RegisterNumber,
12761
 		}
12775
 		}
12762
 		fmt.Println("goods.count2323232233232233232322332322332", goods.Count)
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
 		if errcodes == gorm.ErrRecordNotFound {
12780
 		if errcodes == gorm.ErrRecordNotFound {
12767
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
12781
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
12768
 			if errOne != nil {
12782
 			if errOne != nil {
12771
 		} else if errcodes == nil {
12785
 		} else if errcodes == nil {
12772
 
12786
 
12773
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
12787
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
12774
-			if goods.Count != outInfoOne.Count {
12788
+			if count != outInfoOne.Count {
12775
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
12789
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
12776
 			}
12790
 			}
12777
 
12791
 
12780
 		lastOut, _ := FindWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId)
12794
 		lastOut, _ := FindWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId)
12781
 		//查询已经出库的数据
12795
 		//查询已经出库的数据
12782
 		flowGood, _ := GetStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId)
12796
 		flowGood, _ := GetStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId)
12797
+		fmt.Println("flowgood23323223323222323wo", flowGood)
12783
 		var out_count int64
12798
 		var out_count int64
12784
 		var out_count_one int64
12799
 		var out_count_one int64
12785
 		for _, item := range flowGood {
12800
 		for _, item := range flowGood {
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
 		for _, item := range flowGoodTwo {
12806
 		for _, item := range flowGoodTwo {
12792
 			out_count_one += item.Count
12807
 			out_count_one += item.Count
12793
 		}
12808
 		}
12794
 
12809
 
12795
 		//如果本次出库数据大于历史出库数据 新增1条流水
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
 			stockFlow := models.VmStockFlow{
12816
 			stockFlow := models.VmStockFlow{
12801
 				WarehousingId:           warehouse.ID,
12817
 				WarehousingId:           warehouse.ID,
12802
 				GoodId:                  goods.GoodId,
12818
 				GoodId:                  goods.GoodId,
12803
 				Number:                  warehouse.Number,
12819
 				Number:                  warehouse.Number,
12804
 				LicenseNumber:           warehouse.LicenseNumber,
12820
 				LicenseNumber:           warehouse.LicenseNumber,
12805
-				Count:                   goods.Count - out_count + out_count_one,
12821
+				Count:                   count - out_count + out_count_one,
12806
 				UserOrgId:               orgID,
12822
 				UserOrgId:               orgID,
12807
 				PatientId:               goods.PatientId,
12823
 				PatientId:               goods.PatientId,
12808
 				SystemTime:              record_time,
12824
 				SystemTime:              record_time,
12878
 
12894
 
12879
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
12895
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
12880
 
12896
 
12881
-		if goods.Count < (out_count - out_count_one) {
12897
+		if count < (out_count - out_count_one) {
12882
 
12898
 
12883
 			operation_time := time.Now().Unix()
12899
 			operation_time := time.Now().Unix()
12884
 
12900
 
12914
 				GoodId:          goods.GoodId,
12930
 				GoodId:          goods.GoodId,
12915
 				CancelStockId:   cancel.ID,
12931
 				CancelStockId:   cancel.ID,
12916
 				GoodTypeId:      goods.GoodTypeId,
12932
 				GoodTypeId:      goods.GoodTypeId,
12917
-				Count:           out_count - out_count_one - goods.Count,
12933
+				Count:           out_count - out_count_one - count,
12918
 				Price:           warehouse.PackingPrice,
12934
 				Price:           warehouse.PackingPrice,
12919
 				Total:           0,
12935
 				Total:           0,
12920
 				ProductDate:     warehouse.ProductDate,
12936
 				ProductDate:     warehouse.ProductDate,
12948
 				GoodId:                  goods.GoodId,
12964
 				GoodId:                  goods.GoodId,
12949
 				Number:                  warehouse.Number,
12965
 				Number:                  warehouse.Number,
12950
 				LicenseNumber:           warehouse.LicenseNumber,
12966
 				LicenseNumber:           warehouse.LicenseNumber,
12951
-				Count:                   out_count - out_count_one - goods.Count,
12967
+				Count:                   out_count - out_count_one - count,
12952
 				UserOrgId:               orgID,
12968
 				UserOrgId:               orgID,
12953
 				PatientId:               patient_id,
12969
 				PatientId:               patient_id,
12954
 				SystemTime:              record_time,
12970
 				SystemTime:              record_time,
12988
 
13004
 
12989
 			//退库数量增加
13005
 			//退库数量增加
12990
 			UpdateSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count)
13006
 			UpdateSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count)
13007
+			ModifyAddGoodSumCount(goods.StorehouseId, flow.Count, orgID, goods.GoodId)
12991
 		}
13008
 		}
12992
 
13009
 
12993
 		//添加入库ID
13010
 		//添加入库ID
13054
 		}
13071
 		}
13055
 
13072
 
13056
 		//查询剩余库存
13073
 		//查询剩余库存
13057
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
13074
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
13058
 		var sum_count int64
13075
 		var sum_count int64
13059
 		for _, item := range goodList {
13076
 		for _, item := range goodList {
13060
 			sum_count += item.StockCount
13077
 			sum_count += item.StockCount
13061
 		}
13078
 		}
13079
+		fmt.Println("剩余库存", sum_count)
13062
 
13080
 
13063
 		OutInfo := &models.WarehouseOutInfo{
13081
 		OutInfo := &models.WarehouseOutInfo{
13064
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
13082
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
13088
 			OverCount:               sum_count,
13106
 			OverCount:               sum_count,
13089
 			RegisterNumber:          warehouse.RegisterNumber,
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
 		if errcodes == gorm.ErrRecordNotFound {
13112
 		if errcodes == gorm.ErrRecordNotFound {
13095
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
13113
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
13096
 			if errOne != nil {
13114
 			if errOne != nil {
13099
 		} else if errcodes == nil {
13117
 		} else if errcodes == nil {
13100
 
13118
 
13101
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
13119
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
13102
-			if goods.Count != outInfoOne.Count {
13120
+			if count != outInfoOne.Count {
13103
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
13121
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
13104
 			}
13122
 			}
13105
 
13123
 
13117
 		for _, item := range flowGoodTwo {
13135
 		for _, item := range flowGoodTwo {
13118
 			out_count_one += item.Count
13136
 			out_count_one += item.Count
13119
 		}
13137
 		}
13138
+		fmt.Println("出库数量", stock_number)
13139
+		fmt.Println("历史出库数据", out_count-out_count_one)
13120
 		//如果出库数量 大于 历史出库数据 新增1条流水
13140
 		//如果出库数量 大于 历史出库数据 新增1条流水
13121
-		if goods.Count > out_count-out_count_one {
13141
+		if count > out_count-out_count_one {
13122
 			stockFlow := models.VmStockFlow{
13142
 			stockFlow := models.VmStockFlow{
13123
 				WarehousingId:           warehouse.ID,
13143
 				WarehousingId:           warehouse.ID,
13124
 				GoodId:                  goods.GoodId,
13144
 				GoodId:                  goods.GoodId,
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
 			operation_time := time.Now().Unix()
13226
 			operation_time := time.Now().Unix()
13207
 
13227
 
13237
 				GoodId:          goods.GoodId,
13257
 				GoodId:          goods.GoodId,
13238
 				CancelStockId:   cancel.ID,
13258
 				CancelStockId:   cancel.ID,
13239
 				GoodTypeId:      goods.GoodTypeId,
13259
 				GoodTypeId:      goods.GoodTypeId,
13240
-				Count:           out_count - out_count_one - goods.Count,
13260
+				Count:           out_count - out_count_one - count,
13241
 				Price:           warehouse.PackingPrice,
13261
 				Price:           warehouse.PackingPrice,
13242
 				Total:           0,
13262
 				Total:           0,
13243
 				ProductDate:     warehouse.ProductDate,
13263
 				ProductDate:     warehouse.ProductDate,
13271
 				GoodId:                  goods.GoodId,
13291
 				GoodId:                  goods.GoodId,
13272
 				Number:                  warehouse.Number,
13292
 				Number:                  warehouse.Number,
13273
 				LicenseNumber:           warehouse.LicenseNumber,
13293
 				LicenseNumber:           warehouse.LicenseNumber,
13274
-				Count:                   out_count - goods.Count,
13294
+				Count:                   out_count - count,
13275
 				UserOrgId:               orgID,
13295
 				UserOrgId:               orgID,
13276
 				PatientId:               patient_id,
13296
 				PatientId:               patient_id,
13277
 				SystemTime:              record_time,
13297
 				SystemTime:              record_time,
13311
 
13331
 
13312
 			//退库数量增加
13332
 			//退库数量增加
13313
 			UpdateSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count)
13333
 			UpdateSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count)
13334
+			//实际出库减少
13335
+			ModifyAddGoodSumCount(goods.StorehouseId, flow.Count, orgID, goods.GoodId)
13314
 		}
13336
 		}
13315
 
13337
 
13316
 		errWarehouse := UpdateGoodWarehouseOutById(goods.ID, warehouse.ID, orgID, sum_count)
13338
 		errWarehouse := UpdateGoodWarehouseOutById(goods.ID, warehouse.ID, orgID, sum_count)
13335
 
13357
 
13336
 	goods.Count = deliver_number - stock_number
13358
 	goods.Count = deliver_number - stock_number
13337
 	prepare := &models.DialysisBeforePrepare{
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
 	return nil
13375
 	return nil
13343
 }
13376
 }