瀏覽代碼

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

csx 3 年之前
父節點
當前提交
217bd498a3

+ 1 - 1
conf/app.conf 查看文件

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

+ 102 - 25
controllers/drug_stock_api_contorller.go 查看文件

@@ -568,6 +568,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
568 568
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
569 569
 
570 570
 				} else {
571
+
571 572
 					warehouseInfo := &models.DrugWarehouseInfo{
572 573
 						ID:               id,
573 574
 						WarehousingOrder: warehouse.WarehousingOrder,
@@ -633,7 +634,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
633 634
 				info, _ := service.GetLastDrugWarehouseInfSix(it.DrugId)
634 635
 				flows := models.DrugFlow{
635 636
 					WarehousingOrder: info.WarehousingOrder,
636
-					WarehousingId:    info.ID,
637
+					WarehousingId:    info.WarehousingId,
637 638
 					DrugId:           info.DrugId,
638 639
 					Number:           info.Number,
639 640
 					ProductDate:      info.ProductDate,
@@ -754,7 +755,19 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
754 755
 			}
755 756
 
756 757
 			if item.WarehousingCount == warehouseInfo.WarehousingCount {
757
-				errs = service.UpDateDrugWarehousingInfo(item)
758
+				item.OrgId = item.OrgId
759
+				warehouseinfo := &models.DrugWarehouseInfo{
760
+					Number:       item.Number,
761
+					ProductDate:  item.ProductDate,
762
+					ExpiryDate:   item.ExpiryDate,
763
+					Price:        item.Price,
764
+					TotalPrice:   item.TotalPrice,
765
+					Dealer:       item.Dealer,
766
+					Manufacturer: item.Manufacturer,
767
+					Remark:       item.Remark,
768
+					BatchNumber:  item.BatchNumber,
769
+				}
770
+				errs = service.UpDateDrugWarehousingInfoTwo(item.ID, warehouseinfo)
758 771
 			}
759 772
 		}
760 773
 	}
@@ -1572,9 +1585,10 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1572 1585
 	warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
1573 1586
 
1574 1587
 	tempWarehouseOut := models.DrugWarehouseOut{
1575
-		ID:               warehouseOut.ID,
1576
-		Mtime:            mtime,
1577
-		WarehouseOutTime: warehouseOutDate.Unix(),
1588
+		ID:                      warehouseOut.ID,
1589
+		Mtime:                   mtime,
1590
+		WarehouseOutTime:        warehouseOutDate.Unix(),
1591
+		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1578 1592
 	}
1579 1593
 
1580 1594
 	service.EditDrugWarehouseOut(tempWarehouseOut)
@@ -1856,8 +1870,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1856 1870
 				})
1857 1871
 				return
1858 1872
 			} else {
1859
-				errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1860
-				service.CreateDrugFlow(drugFlow)
1873
+				//errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1874
+				//service.CreateDrugFlow(drugFlow)
1861 1875
 				// 出库流程
1862 1876
 				// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1863 1877
 				drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
@@ -1972,7 +1986,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1972 1986
 
1973 1987
 				cha_number = min_number - max_number
1974 1988
 				//如果总库存大于差,正常出库
1975
-				if all_number >= cha_number {
1989
+				if all_number > cha_number {
1976 1990
 
1977 1991
 					errs = service.UpDateDrugWarehouseOutInfo(item)
1978 1992
 
@@ -2033,7 +2047,36 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
2033 2047
 						})
2034 2048
 					}
2035 2049
 				}
2050
+				if all_number == cha_number {
2051
+					warehouseInfo := models.XtDrugWarehouseInfo{
2052
+						Number:       item.Number,
2053
+						ProductDate:  item.ProductDate,
2054
+						ExpiryDate:   item.ExpiryDate,
2055
+						Price:        item.Price,
2056
+						TotalPrice:   item.TotalPrice,
2057
+						Dealer:       item.Dealer,
2058
+						Manufacturer: item.Manufacturer,
2059
+						Remark:       item.Remark,
2060
+						BatchNumber:  item.BatchNumber,
2061
+						MaxUnit:      item.CountUnit,
2062
+					}
2063
+					parseDateErr := service.UpdateDrugWarehouseingInfoSix(item.ID, warehouseInfo)
2064
+					if parseDateErr != nil {
2065
+						utils.ErrorLog(errs.Error())
2066
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
2067
+						return
2068
+					}
2036 2069
 
2070
+					c.ServeSuccessJSON(map[string]interface{}{
2071
+						"msg":        "2",
2072
+						"drug_name":  "",
2073
+						"dose":       "",
2074
+						"dose_unit":  "",
2075
+						"min_number": "",
2076
+						"min_unit":   "",
2077
+						"max_unit":   "",
2078
+					})
2079
+				}
2037 2080
 				if all_number < cha_number {
2038 2081
 					goodObj, _ := service.GetDrugByGoodId(item.DrugId)
2039 2082
 					c.ServeSuccessJSON(map[string]interface{}{
@@ -2302,29 +2345,29 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2302 2345
 		//查询该批次总的退库数量
2303 2346
 		canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2304 2347
 
2305
-		for _, item := range canInfo {
2306
-			if item.MaxUnit == medical.MaxUnit {
2307
-				item.Count = item.Count * medical.MinNumber
2348
+		for _, it := range canInfo {
2349
+			if it.MaxUnit == medical.MaxUnit {
2350
+				it.Count = it.Count * medical.MinNumber
2308 2351
 			}
2309
-			if item.MaxUnit == medical.MinUnit {
2310
-				item.Count = item.Count
2352
+			if it.MaxUnit == medical.MinUnit {
2353
+				it.Count = it.Count
2311 2354
 			}
2312 2355
 		}
2313 2356
 
2314
-		for _, item := range canInfo {
2315
-			can_number += item.Count
2357
+		for _, it := range canInfo {
2358
+			can_number += it.Count
2316 2359
 		}
2317 2360
 
2318
-		for _, item := range outInfo {
2319
-			if item.CountUnit == medical.MaxUnit {
2320
-				item.Count = item.Count * medical.MinNumber
2361
+		for _, it := range outInfo {
2362
+			if it.CountUnit == medical.MaxUnit {
2363
+				it.Count = it.Count * medical.MinNumber
2321 2364
 			}
2322
-			if item.CountUnit == medical.MinUnit {
2323
-				item.Count = item.Count
2365
+			if it.CountUnit == medical.MinUnit {
2366
+				it.Count = it.Count
2324 2367
 			}
2325 2368
 		}
2326
-		for _, item := range outInfo {
2327
-			out_number += item.Count
2369
+		for _, it := range outInfo {
2370
+			out_number += it.Count
2328 2371
 		}
2329 2372
 
2330 2373
 		if out_number == 0 {
@@ -2335,7 +2378,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2335 2378
 			return
2336 2379
 		}
2337 2380
 
2338
-		fmt.Println("hhhh233323232322323", total_number, total_count)
2381
+		fmt.Println("时间任命323332233232", total_number, total_count)
2339 2382
 
2340 2383
 		//判断退库数量是否大于总入库数量
2341 2384
 		if total_number > total_count {
@@ -2363,9 +2406,42 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2363 2406
 		//正常退库
2364 2407
 		if total_number <= out_number {
2365 2408
 			//创建退库详情
2366
-			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2409
+			errs := service.CreateCancelStockInfoTwo(item)
2367 2410
 			//创建库存明细
2368
-			errs = service.CreateDrugFlow(drugFlow)
2411
+			flows := models.DrugFlow{
2412
+				WarehousingId:           0,
2413
+				DrugId:                  item.DrugId,
2414
+				Number:                  "",
2415
+				BatchNumber:             item.BatchNumber,
2416
+				Count:                   item.Count,
2417
+				UserOrgId:               adminUserInfo.CurrentOrgId,
2418
+				PatientId:               0,
2419
+				SystemTime:              ctime,
2420
+				ConsumableType:          4,
2421
+				IsSys:                   0,
2422
+				WarehousingOrder:        infoWareInfo.WarehousingOrder,
2423
+				WarehouseOutId:          0,
2424
+				WarehouseOutOrderNumber: "",
2425
+				IsEdit:                  0,
2426
+				CancelStockId:           cancelStock.ID,
2427
+				CancelOrderNumber:       cancelStock.OrderNumber,
2428
+				Manufacturer:            manufacturer_id,
2429
+				Dealer:                  dealer_id,
2430
+				Creator:                 adminUserInfo.AdminUser.Id,
2431
+				UpdateCreator:           0,
2432
+				Status:                  1,
2433
+				Ctime:                   time.Now().Unix(),
2434
+				Mtime:                   0,
2435
+				Price:                   item.Price,
2436
+				WarehousingDetailId:     0,
2437
+				WarehouseOutDetailId:    0,
2438
+				CancelOutDetailId:       0,
2439
+				ExpireDate:              item.ExpiryDate,
2440
+				ProductDate:             item.ProductDate,
2441
+				MaxUnit:                 item.MaxUnit,
2442
+				MinUnit:                 "",
2443
+			}
2444
+			errs = service.CreateDrugFlowOne(flows)
2369 2445
 
2370 2446
 			var total int64
2371 2447
 
@@ -2404,6 +2480,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2404 2480
 				})
2405 2481
 			}
2406 2482
 		}
2483
+
2407 2484
 	}
2408 2485
 }
2409 2486
 func (c *StockDrugApiController) GetDrugCancelStockInfoList() {

+ 126 - 108
controllers/his_api_controller.go 查看文件

@@ -650,114 +650,132 @@ func (c *HisApiController) CreateHisPrescription() {
650 650
 
651 651
 	patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
652 652
 
653
-	//_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
654
-	//
655
-	//_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
656
-	//
657
-	//if drugStockConfig.IsOpen == 1 {
658
-	//	//校验库存总量
659
-	//	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
660
-	//		prescriptions, _ := dataBody["prescriptions"].([]interface{})
661
-	//		if len(prescriptions) > 0 {
662
-	//			for _, item := range prescriptions {
663
-	//				items := item.(map[string]interface{})
664
-	//				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
665
-	//					advices := items["advices"].([]interface{})
666
-	//					if len(advices) > 0 {
667
-	//						for _, advice := range advices {
668
-	//							var drug_id int64
669
-	//							var prescribing_number float64
670
-	//							var prescribingNumberUnit string
671
-	//
672
-	//							if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
673
-	//								drug_id = int64(advice.(map[string]interface{})["id"].(float64))
674
-	//							}
675
-	//							if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
676
-	//								//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
677
-	//								prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
678
-	//								prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
679
-	//
680
-	//							}
681
-	//
682
-	//							if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
683
-	//								prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
684
-	//							}
685
-	//
686
-	//							drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
687
-	//							if drug.ID == 0 {
688
-	//								c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
689
-	//								return
690
-	//							}
691
-	//
692
-	//							if prescribingNumberUnit == drug.MinUnit {
693
-	//								if prescribing_number > drug.Total {
694
-	//									c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
695
-	//									//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
696
-	//									return
697
-	//								}
698
-	//							} else {
699
-	//								if prescribingNumberUnit == drug.MaxUnit {
700
-	//									num := prescribing_number * float64(drug.MinNumber)
701
-	//									if num > drug.Total {
702
-	//										c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
703
-	//										//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
704
-	//										return
705
-	//									}
706
-	//								}
707
-	//							}
708
-	//						}
709
-	//					}
710
-	//				}
711
-	//			}
712
-	//		}
713
-	//	}
714
-	//}
715
-	//
716
-	//if stockConfig.IsOpen == 1 {
717
-	//	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
718
-	//		prescriptions, _ := dataBody["prescriptions"].([]interface{})
719
-	//		if len(prescriptions) > 0 {
720
-	//			for _, item := range prescriptions {
721
-	//				items := item.(map[string]interface{})
722
-	//				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
723
-	//					projects := items["project"].([]interface{})
724
-	//					if len(projects) > 0 {
725
-	//						for _, project := range projects {
726
-	//							var project_id int64
727
-	//							var project_type int64
728
-	//							var totals float64
729
-	//							if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
730
-	//								project_id = int64(project.(map[string]interface{})["project_id"].(float64))
731
-	//							}
732
-	//							if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
733
-	//								project_type = int64(project.(map[string]interface{})["type"].(float64))
734
-	//							}
735
-	//							if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
736
-	//								total, _ := project.(map[string]interface{})["total"].(string)
737
-	//
738
-	//								totals, _ = strconv.ParseFloat(total, 64)
739
-	//							}
740
-	//							if project_type == 3 {
741
-	//								good, _ := service.FindGoodInfoByIdTwo(project_id)
742
-	//								if good.ID == 0 {
743
-	//									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
744
-	//									return
745
-	//								}
746
-	//								if totals > good.Total {
747
-	//									c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
748
-	//									//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
749
-	//									return
750
-	//								}
751
-	//
752
-	//							}
753
-	//
754
-	//						}
755
-	//					}
756
-	//				}
757
-	//			}
758
-	//		}
759
-	//	}
760
-	//}
653
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
654
+
655
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
656
+
657
+	if drugStockConfig.IsOpen == 1 {
658
+		//校验库存总量
659
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
660
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
661
+			if len(prescriptions) > 0 {
662
+				for _, item := range prescriptions {
663
+					items := item.(map[string]interface{})
664
+					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
665
+						advices := items["advices"].([]interface{})
666
+						if len(advices) > 0 {
667
+							for _, advice := range advices {
668
+								var drug_id int64
669
+								var prescribing_number float64
670
+								var prescribingNumberUnit string
671
+
672
+								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
673
+									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
674
+								}
675
+								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
676
+									//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
677
+									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
678
+									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
679
+
680
+								}
681
+
682
+								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
683
+									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
684
+								}
685
+
686
+								drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
687
+								if drug.ID == 0 {
688
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
689
+									return
690
+								}
691
+
692
+								//查询药品的搜有库存
693
+								list, _ := service.GetDrugWarehouseInfoPrescription(drug_id, adminInfo.CurrentOrgId)
694
+								var total_count int64
695
+								for _, it := range list {
696
+									total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
697
+								}
698
+								totals := strconv.FormatInt(total_count, 10)
699
+								all_count, _ := strconv.ParseFloat(totals, 64)
700
+								fmt.Println("all_count2323323233232", all_count)
701
+								if prescribingNumberUnit == drug.MinUnit {
702
+									if prescribing_number > all_count {
703
+										c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
704
+										//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
705
+										return
706
+									}
707
+								} else {
708
+									if prescribingNumberUnit == drug.MaxUnit {
709
+										num := prescribing_number * float64(drug.MinNumber)
710
+										if num > all_count {
711
+											c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
712
+											//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
713
+											return
714
+										}
715
+									}
716
+								}
717
+
718
+							}
719
+						}
720
+					}
721
+				}
722
+			}
723
+		}
724
+	}
725
+
726
+	if stockConfig.IsOpen == 1 {
727
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
728
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
729
+			if len(prescriptions) > 0 {
730
+				for _, item := range prescriptions {
731
+					items := item.(map[string]interface{})
732
+					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
733
+						projects := items["project"].([]interface{})
734
+						if len(projects) > 0 {
735
+							for _, project := range projects {
736
+								var project_id int64
737
+								var project_type int64
738
+								var totals float64
739
+								if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
740
+									project_id = int64(project.(map[string]interface{})["project_id"].(float64))
741
+								}
742
+								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
743
+									project_type = int64(project.(map[string]interface{})["type"].(float64))
744
+								}
745
+								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
746
+									total, _ := project.(map[string]interface{})["total"].(string)
747
+
748
+									totals, _ = strconv.ParseFloat(total, 64)
749
+								}
750
+								if project_type == 3 {
751
+									good, _ := service.FindGoodInfoByIdTwo(project_id)
752
+									if good.ID == 0 {
753
+										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
754
+										return
755
+									}
756
+									//查询耗材库存
757
+									list, _ := service.GetGoodWarehouseInfo(project_id)
758
+									var stock_count int64
759
+									for _, it := range list {
760
+										stock_count += it.StockCount
761
+									}
762
+									stock_counts := strconv.FormatInt(stock_count, 10)
763
+									stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
764
+									if totals > stock_total_count {
765
+										c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
766
+
767
+										return
768
+									}
769
+
770
+								}
771
+
772
+							}
773
+						}
774
+					}
775
+				}
776
+			}
777
+		}
778
+	}
761 779
 
762 780
 	info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
763 781
 	var hpInfo models.HisPrescriptionInfo

+ 12 - 10
controllers/mobile_api_controllers/dialysis_api_controller.go 查看文件

@@ -3911,6 +3911,7 @@ func (c *DialysisAPIController) EditConsumables() {
3911 3911
 						err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, beforePrepares, adminInfo.AdminUser.Id, item.Count)
3912 3912
 						break
3913 3913
 					}
3914
+
3914 3915
 					var last_total int64
3915 3916
 
3916 3917
 					//如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
@@ -4580,7 +4581,6 @@ func (c *DialysisAPIController) UpdateStockGoods() {
4580 4581
 //当前数据比上一次出库数据少
4581 4582
 func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
4582 4583
 
4583
-	fmt.Println("w我的中国馆公共区发电房阿道夫安抚安抚安抚安抚安抚安抚阿道夫阿道夫阿凡达阿道夫a", count)
4584 4584
 	//查询该患者当天已经出库的耗材信息
4585 4585
 	goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
4586 4586
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
@@ -4619,7 +4619,6 @@ func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time in
4619 4619
 
4620 4620
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
4621 4621
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
4622
-	fmt.Println("goodsy999999999999", goods_yc)
4623 4622
 
4624 4623
 	//退库
4625 4624
 	if len(goods_yc) > 0 {
@@ -4635,10 +4634,8 @@ func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time in
4635 4634
 //耗材出库删除
4636 4635
 func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
4637 4636
 
4638
-	fmt.Println("count2323223884584854854854u5454785487547845785478758487545475475487,count", count)
4639 4637
 	// 先根据相关信息查询当天该耗材的出库信息
4640 4638
 	warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
4641
-	fmt.Println("errr232323232323232323232323232", err)
4642 4639
 
4643 4640
 	if err != nil {
4644 4641
 		return err
@@ -4740,7 +4737,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4740 4737
 				PatientId:               patient_id,
4741 4738
 			}
4742 4739
 
4743
-			service.UpdatedStockFlow(stockFlow)
4740
+			service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
4744 4741
 		}
4745 4742
 
4746 4743
 		if errOne != nil {
@@ -4807,7 +4804,8 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4807 4804
 				PatientId:               patient_id,
4808 4805
 				ReturnCount:             delete_count,
4809 4806
 			}
4810
-			service.UpdatedStockFlow(stockFlow)
4807
+			//service.UpdatedStockFlow(stockFlow)
4808
+			service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
4811 4809
 		}
4812 4810
 
4813 4811
 	}
@@ -4841,7 +4839,8 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4841 4839
 	// 删除出库完成后,要增加对应批次的库存数量
4842 4840
 	fmt.Println("deletecount2323232323232323232323232323", delete_count)
4843 4841
 	errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count)
4844
-
4842
+	errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
4843
+	fmt.Println("erron2332323232323232232323", errOne)
4845 4844
 	if errThree != nil {
4846 4845
 		return errThree
4847 4846
 	}
@@ -4994,14 +4993,17 @@ func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *mod
4994 4993
 		stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
4995 4994
 		warehouseOutInfo.Price = stockInInfo.Price
4996 4995
 		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
4996
+
4997 4997
 		if errOne != nil {
4998 4998
 			return errOne
4999 4999
 		}
5000 5000
 
5001
-		//更改自动出库的表格
5002
-
5003 5001
 		// 删除出库完成后,要增加对应批次的库存数量
5004
-		fmt.Println("deletecount2323232323232323232323232323", delete_count)
5002
+		fmt.Println("时间人秘股呢换药2232323223323223322323232323232323232323232323", delete_count)
5003
+
5004
+		// 删除出库完成后,要改变流水库存
5005
+		errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
5006
+		fmt.Println("erron2332323232323232232323", errOne)
5005 5007
 		errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count)
5006 5008
 
5007 5009
 		if errThree != nil {

+ 13 - 6
controllers/stock_in_api_controller.go 查看文件

@@ -2121,10 +2121,11 @@ func (c *StockManagerApiController) CreateCancelStock() {
2121 2121
 				service.AddSigleCancelStock(&cancelStock)
2122 2122
 			}
2123 2123
 			listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
2124
-			for _, it := range cancelStockInfos {
2125
-				it.CancelStockId = listcancel.ID
2126
-			}
2127
-			errs := service.CreateCancelStockInfo(cancelStockInfos)
2124
+
2125
+			fmt.Println("2332323232323232323", cancelStockInfos)
2126
+			item.CancelStockId = listcancel.ID
2127
+			errs := service.CreateCancelStockInfoOne(item)
2128
+
2128 2129
 			if len(stockFLow) > 0 {
2129 2130
 				service.CreateStockFlow(stockFLow)
2130 2131
 			}
@@ -2144,7 +2145,11 @@ func (c *StockManagerApiController) CreateCancelStock() {
2144 2145
 			}
2145 2146
 			//更改入库数量
2146 2147
 			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
2147
-			break
2148
+			if err != nil {
2149
+				utils.ErrorLog(err.Error())
2150
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2151
+				return
2152
+			}
2148 2153
 		}
2149 2154
 	}
2150 2155
 
@@ -4604,9 +4609,11 @@ func (this *StockManagerApiController) GetOrderDetialByOrderId() {
4604 4609
 	ids := this.GetString("id")
4605 4610
 	idsArray := strings.Split(ids, ",")
4606 4611
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4612
+	order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
4607 4613
 	list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
4608 4614
 	this.ServeSuccessJSON(map[string]interface{}{
4609
-		"list": list,
4615
+		"list":  list,
4616
+		"order": order,
4610 4617
 	})
4611 4618
 }
4612 4619
 

+ 13 - 12
models/device_models.go 查看文件

@@ -393,18 +393,19 @@ type Schedules struct {
393 393
 }
394 394
 
395 395
 type XtSchedule struct {
396
-	ID           int64 `gorm:"column:id" json:"id" form:"id"`
397
-	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
398
-	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
399
-	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
400
-	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
401
-	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
402
-	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
403
-	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
404
-	ModeId       int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
405
-	Status       int64 `gorm:"column:status" json:"status" form:"status"`
406
-	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
407
-	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
396
+	ID              int64                   `gorm:"column:id" json:"id" form:"id"`
397
+	UserOrgId       int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
398
+	PartitionId     int64                   `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
399
+	BedId           int64                   `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
400
+	PatientId       int64                   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
401
+	ScheduleDate    int64                   `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
402
+	ScheduleType    int64                   `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
403
+	ScheduleWeek    int64                   `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
404
+	ModeId          int64                   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
405
+	Status          int64                   `gorm:"column:status" json:"status" form:"status"`
406
+	CreatedTime     int64                   `gorm:"column:created_time" json:"created_time" form:"created_time"`
407
+	UpdatedTime     int64                   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
408
+	LastAfterWeight AssessmentAfterDislysis `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
408 409
 }
409 410
 
410 411
 func (XtSchedule) TableName() string {

+ 1 - 1
models/dialysis.go 查看文件

@@ -863,7 +863,7 @@ type XtDialysisOrders struct {
863 863
 	FinishModifier int64  `gorm:"column:finish_modifier" json:"finish_modifier" form:"finish_modifier"`
864 864
 	SchedualType   int64  `gorm:"column:schedual_type" json:"schedual_type" form:"schedual_type"`
865 865
 	Number         string `gorm:"column:number" json:"number" form:"number"`
866
-	UserName       int64  `gorm:"column:user_name" json:"user_name" form:"user_name"`
866
+	UserName       string `gorm:"column:user_name" json:"user_name" form:"user_name"`
867 867
 	WashpipeNurse  int64  `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
868 868
 	ModeId         int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
869 869
 }

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

@@ -325,6 +325,7 @@ type StDrugWarehouseOutInfo struct {
325 325
 	LastPrice               string  `json:"last_price"`
326 326
 	PackingUnit             string  `json:"packing_unit"`
327 327
 	Dosage                  int64   `json:"dosage"`
328
+	ExpireDate              int64   `json:"expire_date"`
328 329
 }
329 330
 
330 331
 type DrugFlow struct {

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

@@ -197,6 +197,7 @@ type VmSchedulesRemind struct {
197 197
 	HisDoctorAdviceInfo        []*HisDoctorAdviceInfo     `json:"hisdoctoradviceinfo" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
198 198
 	DialysisSolution           DialysisSolution           `json:"dialysissolution" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId;"`
199 199
 	XtAssessmentBeforeDislysis XtAssessmentBeforeDislysis `json:"assessmentbefor" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
200
+	LastAfterWeight            AssessmentAfterDislysis    `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
200 201
 }
201 202
 
202 203
 func (VmSchedulesRemind) TableName() string {

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

@@ -650,7 +650,7 @@ func GetSearchPatient(keywords string, orgid int64, startime int64) (schedule []
650 650
 	db := XTReadDB().Table("xt_schedule as s")
651 651
 	err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
652 652
 		return db.Where("status =1").Preload("DeviceZone", "status = 1")
653
-	}).Preload("DialysisOrder", "status =1").
653
+	}).Preload("DialysisOrder", "status =1").Preload("DialysisPrescription", "status =1").
654 654
 		Joins("JOIN xt_patients as p ON p.id = s.patient_id And(p.name LIKE ? OR p.dialysis_no LIKE ?)", likeKey, likeKey).Where("s.user_org_id = ? and s.schedule_date = ? and s.status =1", orgid, startime).
655 655
 		Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id,p.name as patient").Find(&schedule).Error
656 656
 	return schedule, err

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

@@ -1876,7 +1876,7 @@ func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64
1876 1876
 			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ?  AND count > 0 ", orgID, scheduleDate)
1877 1877
 		}).
1878 1878
 		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
1879
-			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ?  ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
1879
+			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?  ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ?  ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
1880 1880
 		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
1881 1881
 	if scheduleDate != 0 {
1882 1882
 		db = db.Where("schedule_date = ?", scheduleDate)

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

@@ -422,7 +422,7 @@ func SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode *m
422 422
 	nextMonday, _ := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
423 423
 	nextSecWeek := now.AddDate(0, 0, 14)
424 424
 	_, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
425
-	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
425
+	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
426 426
 	if disableErr != nil {
427 427
 		tx.Rollback()
428 428
 		return disableErr

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

@@ -67,7 +67,7 @@ func GetPatientList(orgID int64, keywords string, page, limit, schedulType, bind
67 67
 
68 68
 	offset := (page - 1) * limit
69 69
 
70
-	err = db.Order("p.id desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
70
+	err = db.Order("p.id desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time,p.is_infectious").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
71 71
 	return
72 72
 }
73 73
 

+ 9 - 3
service/schedule_service.go 查看文件

@@ -591,7 +591,7 @@ func GetWeekDayScheduleById(orgid int64, scheduleDate int64, scheduleType int64,
591 591
 
592 592
 func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
593 593
 
594
-	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
594
+	db := readDb2.Table("xt_schedule as x").Where("x.status = 1")
595 595
 	if orgid > 0 {
596 596
 		db = db.Where("x.user_org_id = ?", orgid)
597 597
 	}
@@ -609,6 +609,8 @@ func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType in
609 609
 		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1")
610 610
 	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ?", scheduleDate).Preload("DialysisPrescription", "status = 1 and record_date =?", scheduleDate).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
611 611
 		return db.Where("status =1").Order("id asc")
612
+	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
613
+		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
612 614
 	}).Find(&list).Error
613 615
 
614 616
 	return list, err
@@ -616,7 +618,7 @@ func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType in
616 618
 
617 619
 func GetWeekDayScheduleByIdTwo(orgid int64, scheduleDate int64, scheduleType int64, startDate int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
618 620
 
619
-	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
621
+	db := readDb2.Table("xt_schedule as x").Where("x.status = 1")
620 622
 	if orgid > 0 {
621 623
 		db = db.Where("x.user_org_id = ?", orgid)
622 624
 	}
@@ -634,6 +636,8 @@ func GetWeekDayScheduleByIdTwo(orgid int64, scheduleDate int64, scheduleType int
634 636
 		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1")
635 637
 	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ?", scheduleDate).Preload("DialysisPrescription", "status = 1 and record_date = ?", scheduleDate).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
636 638
 		return db.Where("status =1").Order("id asc")
639
+	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
640
+		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
637 641
 	}).Find(&list).Error
638 642
 
639 643
 	return list, err
@@ -987,6 +991,8 @@ func GetDataPrint(orgid int64) (models.XtDataPrint, error) {
987 991
 
988 992
 func GetNextWeekPanels(startime int64, endtime int64, orgid int64) (schedule []*models.XtSchedule, err error) {
989 993
 
990
-	err = XTReadDB().Model(&schedule).Where("schedule_date >=? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Find(&schedule).Error
994
+	err = readDb2.Model(&schedule).Where("schedule_date >=? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
995
+		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, endtime)
996
+	}).Find(&schedule).Error
991 997
 	return schedule, err
992 998
 }

+ 60 - 5
service/stock_service.go 查看文件

@@ -604,7 +604,7 @@ func GetDrugByWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
604 604
 func UpdateDrugWarehouseingInfo(id int64, info models.XtDrugWarehouseInfo) error {
605 605
 
606 606
 	warehouseInfo := models.XtDrugWarehouseInfo{}
607
-	err := XTReadDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
607
+	err := XTWriteDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
608 608
 	return err
609 609
 }
610 610
 
@@ -1605,6 +1605,18 @@ func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error
1605 1605
 
1606 1606
 }
1607 1607
 
1608
+func CreateCancelStockInfoTwo(info *models.DrugCancelStockInfo) error {
1609
+
1610
+	err := XTWriteDB().Create(&info).Error
1611
+	return err
1612
+}
1613
+
1614
+func CreateCancelStockInfoOne(info *models.CancelStockInfo) error {
1615
+
1616
+	err := XTWriteDB().Create(&info).Error
1617
+	return err
1618
+}
1619
+
1608 1620
 func CreateDrugCancelStockInfo(cancelStockInfo []*models.DrugCancelStockInfo) (err error) {
1609 1621
 	if len(cancelStockInfo) > 0 {
1610 1622
 		utx := writeDb.Begin()
@@ -1912,6 +1924,11 @@ func UpDateDrugWarehousingInfo(info *models.DrugWarehouseInfo) (err error) {
1912 1924
 	return err
1913 1925
 }
1914 1926
 
1927
+func UpDateDrugWarehousingInfoTwo(id int64, info *models.DrugWarehouseInfo) (err error) {
1928
+	err = writeDb.Model(&info).Where("id= ? and status = 1", id).Updates(map[string]interface{}{"number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "batch_number": info.BatchNumber}).Error
1929
+	return err
1930
+}
1931
+
1915 1932
 func GetDrugWarehouseOrderOne(id int64, drug_id int64) (models.DrugWarehouseInfo, error) {
1916 1933
 
1917 1934
 	info := models.DrugWarehouseInfo{}
@@ -3251,7 +3268,7 @@ func GetAutoMaticReduceDetail(orgid int64, patient_id int64, recordtime int64, g
3251 3268
 func DeleteAutoRedeceDetailTwo(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) error {
3252 3269
 
3253 3270
 	detail := models.BloodAutomaticReduceDetail{}
3254
-	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and good_type_id = ?", orgid, patient_id, recordtime, goodid, goodtypeid).Updates(map[string]interface{}{"status": 0}).Error
3271
+	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and good_type_id = ?", orgid, patient_id, recordtime, goodid, goodtypeid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3255 3272
 	return err
3256 3273
 }
3257 3274
 
@@ -3260,6 +3277,12 @@ func UpDateWarehouseInfoByStockDelete(id int64, count int64) (err error) {
3260 3277
 	return err
3261 3278
 }
3262 3279
 
3280
+func UpDateWarehouStockFlowByStockDelete(id int64, recordtime int64, good_id int64, count int64, patient_id int64) (err error) {
3281
+
3282
+	err = writeDb.Model(&models.VmStockFlow{}).Where("warehousing_id = ? and system_time = ? and good_id = ? and patient_id = ?", id, recordtime, good_id, patient_id).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
3283
+	return err
3284
+}
3285
+
3263 3286
 func UpDateWarehouseInfoByStockDeleteOne(id int64, count int64) (err error) {
3264 3287
 	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
3265 3288
 	return err
@@ -3284,6 +3307,12 @@ func FindGoodInfoByIdTwo(id int64) (goodInfo models.GoodInfo, err error) {
3284 3307
 	return
3285 3308
 }
3286 3309
 
3310
+func GetGoodWarehouseInfo(good_id int64) (info []*models.WarehousingInfo, err error) {
3311
+
3312
+	err = readDb.Where("good_id = ? and status = 1 and stock_count<>0", good_id).Find(&info).Error
3313
+	return info, err
3314
+}
3315
+
3287 3316
 func GetAllStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.VmWarehousingInfo, total int64, err error) {
3288 3317
 
3289 3318
 	offset := (page - 1) * limit
@@ -3505,7 +3534,7 @@ func FindUserDetailByIdOne(good_id int64, record_time int64, org_id int64) (user
3505 3534
 	db = db.Preload("GoodsType", "status = 1")
3506 3535
 	db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
3507 3536
 	db = db.Preload("WarehouseOutInfo", "org_id = ? and status = 1 and good_id = ? and sys_record_time = ?", org_id, good_id, record_time)
3508
-	db = db.Where("status = 1 AND org_id = ? AND good_id = ? AND record_time = ? ", org_id, good_id, record_time)
3537
+	db = db.Where("status = 1 AND org_id = ? AND good_id = ? AND record_time = ? and count<> 0 ", org_id, good_id, record_time)
3509 3538
 	db = db.Count(&total)
3510 3539
 	err = db.Find(&user).Error
3511 3540
 
@@ -3934,7 +3963,7 @@ func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlo
3934 3963
 
3935 3964
 func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
3936 3965
 
3937
-	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1")
3966
+	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and count > 0")
3938 3967
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
3939 3968
 	fmt.Println(table)
3940 3969
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
@@ -3989,7 +4018,7 @@ func GetExportOutOrderDrugListOne(warehouse_out_id []string) (out []*models.StDr
3989 4018
 	if len(warehouse_out_id) > 0 {
3990 4019
 		db = db.Where("x.warehouse_out_id in(?)", warehouse_out_id)
3991 4020
 	}
3992
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.max_unit as count_unit,x.price,x.product_date,x.expire_date as expire_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.number,x.batch_number,x.patient_id,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
4021
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.max_unit as count_unit,x.price,x.product_date,x.expire_date,x.warehouse_out_order_number,x.dealer,x.manufacturer,x.is_sys,x.number,x.batch_number,x.patient_id,b.dose,b.dose_unit,b.min_number,b.min_unit,b.max_unit,b.drug_name,b.drug_type,b.min_price").Joins("left join xt_base_drug as b on b.id = x.drug_id").Scan(&out).Error
3993 4022
 	return out, err
3994 4023
 }
3995 4024
 
@@ -4095,6 +4124,12 @@ func UpdatedStockFlow(flow models.VmStockFlow) error {
4095 4124
 	return err
4096 4125
 }
4097 4126
 
4127
+func UpdatedStockFlowOne(flow models.VmStockFlow, warehousing_id int64, patient_id int64, record_time int64, good_id int64) error {
4128
+
4129
+	err = XTWriteDB().Model(&flow).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehousing_id, patient_id, record_time, good_id).Updates(map[string]interface{}{"number": flow.Number, "license_number": flow.LicenseNumber, "count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer}).Error
4130
+	return err
4131
+}
4132
+
4098 4133
 func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (*models.VmStockFlow, error) {
4099 4134
 
4100 4135
 	stock := models.VmStockFlow{}
@@ -4353,6 +4388,12 @@ func GetDrugWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
4353 4388
 	return info, err
4354 4389
 }
4355 4390
 
4391
+func GetDrugWarehouseInfoPrescription(drugid int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
4392
+
4393
+	err = XTReadDB().Where("drug_id = ? and org_id =? and status = 1", drugid, orgid).Find(&info).Error
4394
+	return info, err
4395
+}
4396
+
4356 4397
 func GetDrugWarehouseInfoById(id int64) (models.XtDrugWarehouseInfo, error) {
4357 4398
 
4358 4399
 	info := models.XtDrugWarehouseInfo{}
@@ -5033,3 +5074,17 @@ func GetInventoryExportList(orgid int64) (info []*models.PatientWarehouseInfo, e
5033 5074
 	err = db.Select("x.id,x.good_id,x.number,x.number,x.product_date,x.expiry_date,x.warehousing_unit,x.dealer,x.manufacturer,t.good_name,t.specification_name,t.packing_unit,t.remark").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id,x.number").Scan(&info).Error
5034 5075
 	return info, err
5035 5076
 }
5077
+
5078
+func GetDrugWarehouseingInfo(id int64) (models.XtDrugWarehouseInfo, error) {
5079
+
5080
+	info := models.XtDrugWarehouseInfo{}
5081
+	err := XTReadDB().Where("id=? and status = 1", id).Find(&info).Error
5082
+	return info, err
5083
+}
5084
+
5085
+func UpdateDrugWarehouseingInfoSix(id int64, info models.XtDrugWarehouseInfo) error {
5086
+
5087
+	warehouseInfo := models.XtDrugWarehouseInfo{}
5088
+	err := XTWriteDB().Model(&warehouseInfo).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "price": info.Price, "total_price": info.TotalPrice, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "remark": info.Remark, "batch_number": info.BatchNumber, "max_unit": info.MaxUnit}).Error
5089
+	return err
5090
+}

+ 19 - 18
service/warhouse_service.go 查看文件

@@ -836,14 +836,15 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
836 836
 		if errOne != nil {
837 837
 			return errOne
838 838
 		}
839
-		list, _ := GetLastWarehouseOut(drup.OrgId)
839
+		fmt.Println("hh233223323223232323233223232323233223232323", warehouseout.ID, warehouseout.WarehouseOutOrderNumber)
840
+		//list, _ := GetLastWarehouseOut(drup.OrgId)
840 841
 		drugflow := models.DrugFlow{
841
-			WarehouseOutId:          list.ID,
842
+			WarehouseOutId:          warehouseout.ID,
842 843
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
843 844
 			DrugId:                  advice.DrugId,
844 845
 			Number:                  warehouse.Number,
845
-			ProductDate:             warehouse.ProductDate,
846
-			ExpireDate:              warehouse.ExpiryDate,
846
+			ProductDate:             advice.ProductDate,
847
+			ExpireDate:              advice.ExpiryDate,
847 848
 			Count:                   deliver_number,
848 849
 			Price:                   advice.Price,
849 850
 			Status:                  1,
@@ -929,14 +930,14 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
929 930
 		if errOne != nil {
930 931
 			return errOne
931 932
 		}
932
-		list, _ := GetLastWarehouseOut(drup.OrgId)
933
+		//list, _ := GetLastWarehouseOut(drup.OrgId)
933 934
 		drugflow := models.DrugFlow{
934
-			WarehouseOutId:          list.ID,
935
+			WarehouseOutId:          warehouseout.ID,
935 936
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
936 937
 			DrugId:                  advice.DrugId,
937 938
 			Number:                  warehouse.Number,
938
-			ProductDate:             warehouse.ProductDate,
939
-			ExpireDate:              warehouse.ExpiryDate,
939
+			ProductDate:             advice.ProductDate,
940
+			ExpireDate:              advice.ExpiryDate,
940 941
 			Count:                   deliver_number,
941 942
 			Price:                   advice.Price,
942 943
 			Status:                  1,
@@ -1079,9 +1080,6 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1079 1080
 //耗材出库
1080 1081
 func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
1081 1082
 
1082
-	fmt.Println("count23232323232323232323232323", count)
1083
-	fmt.Println("hhhh2h3h3h2h23h32hh23h32h23", goods.Count)
1084
-	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
1085 1083
 	var deliver_number int64 = 0
1086 1084
 	var stock_number int64 = 0
1087 1085
 	var maxNumber int64 = 0
@@ -1097,7 +1095,6 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1097 1095
 		return errors.New("库存数量不足")
1098 1096
 	}
1099 1097
 
1100
-	// 将该批次的剩余库存数量转换为拆零数量
1101 1098
 	stock_number = warehouse.StockCount
1102 1099
 
1103 1100
 	//获取耗材信息
@@ -1185,7 +1182,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1185 1182
 				PatientId:               patient_id,
1186 1183
 			}
1187 1184
 			//查询流水是否存在
1188
-			exsit, errflow := GetStockFlowIsExsit(warehouseOut.ID, patient_id, record_time, goods.GoodId)
1185
+			exsit, errflow := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1189 1186
 
1190 1187
 			fmt.Println("什么数据233232323", errflow)
1191 1188
 			if errflow == gorm.ErrRecordNotFound {
@@ -1220,7 +1217,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1220 1217
 					PatientId:               patient_id,
1221 1218
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1222 1219
 				}
1223
-				errFour := UpdatedStockFlow(flow)
1220
+
1221
+				errFour := UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1224 1222
 				if errFour != nil {
1225 1223
 					return errFour
1226 1224
 				}
@@ -1252,7 +1250,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1252 1250
 				PatientId:               patient_id,
1253 1251
 			}
1254 1252
 			//查询流水是否存在
1255
-			exsit, errflow := GetStockFlowIsExsit(warehouseOut.ID, patient_id, record_time, goods.GoodId)
1253
+			exsit, errflow := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1256 1254
 
1257 1255
 			if errflow == gorm.ErrRecordNotFound {
1258 1256
 				CreateStockFlowOne(flow)
@@ -1285,7 +1283,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1285 1283
 					PatientId:               patient_id,
1286 1284
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1287 1285
 				}
1288
-				UpdatedStockFlow(flow)
1286
+				//UpdatedStockFlow(flow)
1287
+				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1289 1288
 				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1290 1289
 				CreateAutoReduceRecord(&details)
1291 1290
 			}
@@ -1403,7 +1402,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1403 1402
 					PatientId:               patient_id,
1404 1403
 					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1405 1404
 				}
1406
-				UpdatedStockFlow(flow)
1405
+				//UpdatedStockFlow(flow)
1406
+				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1407 1407
 			}
1408 1408
 
1409 1409
 		} else if errcodes == nil {
@@ -1468,7 +1468,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1468 1468
 					IsSys:                   1,
1469 1469
 					PatientId:               patient_id,
1470 1470
 				}
1471
-				UpdatedStockFlow(flow)
1471
+				//UpdatedStockFlow(flow)
1472
+				UpdatedStockFlowOne(flow, warehouse.ID, patient_id, record_time, goods.GoodId)
1472 1473
 			}
1473 1474
 		}
1474 1475