浏览代码

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

see999 3 年前
父节点
当前提交
0153b9326d

+ 3 - 0
conf/app.conf 查看文件

@@ -19,6 +19,9 @@ qiniu_bucket = syhclub-storage
19 19
 
20 20
 
21 21
 
22
+
23
+
24
+
22 25
 aes_key = "xuetou-201807319"
23 26
 
24 27
 wxtoken = gh_ac6cd0cdde3d

+ 39 - 0
controllers/doctors_api_controller.go 查看文件

@@ -39,6 +39,11 @@ func DoctorApiRegistRouters() {
39 39
 	beego.Router("/api/patient/updatepasswayassesment", &DoctorsApiController{}, "Get:UpdatePassWayAssesment")
40 40
 	beego.Router("/api/patient/deletepasswayassessment", &DoctorsApiController{}, "Get:DeleteWayAssessment")
41 41
 	beego.Router("/api/patient/getaccesslist", &DoctorsApiController{}, "Get:GetAccessList")
42
+
43
+	//阶段小结路由
44
+	beego.Router("/api/patient/getinspectionmajoritem", &DoctorsApiController{}, "Get:GetInspectionMajorItem")
45
+	beego.Router("/api/patient/getinspectiondetail", &DoctorsApiController{}, "Get:GetInspectionDetailByProject")
46
+
42 47
 }
43 48
 
44 49
 func (c *DoctorsApiController) ScheduleAdvices() {
@@ -661,3 +666,37 @@ func (this *DoctorsApiController) GetAccessList() {
661 666
 		return
662 667
 	}
663 668
 }
669
+
670
+func (this *DoctorsApiController) GetInspectionMajorItem() {
671
+
672
+	other_start_time := this.GetString("other_start_time")
673
+	timeLayout := "2006-01-02"
674
+	loc, _ := time.LoadLocation("Local")
675
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", other_start_time+" 23:59:59", loc)
676
+	fmt.Println("startTime2222345555533344334334433433344", startTime.Unix())
677
+	patient_id, _ := this.GetInt64("patient_id")
678
+	adminUserInfo := this.GetAdminUserInfo()
679
+	orgId := adminUserInfo.CurrentOrgId
680
+	list, err := service.GetInspectionMajorItem(startTime.Unix(), orgId, patient_id)
681
+	if err == nil {
682
+		this.ServeSuccessJSON(map[string]interface{}{
683
+			"list": list,
684
+		})
685
+		return
686
+	}
687
+}
688
+
689
+func (this *DoctorsApiController) GetInspectionDetailByProject() {
690
+
691
+	project_id, _ := this.GetInt64("project_id")
692
+	patient_id, _ := this.GetInt64("patient_id")
693
+	inspect_date, _ := this.GetInt64("inspect_date")
694
+	orgId := this.GetAdminUserInfo().CurrentOrgId
695
+	list, err := service.GetInspectionDetailByProject(project_id, patient_id, inspect_date, orgId)
696
+	if err == nil {
697
+		this.ServeSuccessJSON(map[string]interface{}{
698
+			"list": list,
699
+		})
700
+		return
701
+	}
702
+}

+ 161 - 21
controllers/drug_stock_api_contorller.go 查看文件

@@ -543,6 +543,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
543 543
 						BatchNumber:      batch_number,
544 544
 						MaxUnit:          max_unit,
545 545
 						MinUnit:          min_unit,
546
+						StockMaxNumber:   warehousing_count,
546 547
 					}
547 548
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
548 549
 
@@ -567,7 +568,6 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
567 568
 						Dealer:           dealer,
568 569
 						RetailPrice:      last_price,
569 570
 						RetailTotalPrice: retail_price_total,
570
-						StockMaxNumber:   warehousing_count,
571 571
 						MaxUnit:          max_unit,
572 572
 						MinUnit:          min_unit,
573 573
 						BatchNumber:      batch_number,
@@ -576,7 +576,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
576 576
 
577 577
 					drugflow := &models.DrugFlow{
578 578
 						WarehousingOrder: warehousing.WarehousingOrder,
579
-						WarehousingId:    warehousing.ID,
579
+						WarehousingId:    id,
580 580
 						DrugId:           drug_id,
581 581
 						Number:           number,
582 582
 						ProductDate:      productDates,
@@ -638,8 +638,34 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
638 638
 				Total: minNumber,
639 639
 			}
640 640
 			service.UpdateBaseDrug(&lib, item.DrugId)
641
+			warehouseInfo, _ := service.FindeLastWarehouseInfo(item.ID)
642
+			fmt.Println("hhhhh23hh32h232332323223", warehouseInfo)
643
+			var total int64
644
+			//比较大小(加)
645
+			if item.WarehousingCount > warehouseInfo.WarehousingCount {
646
+				total = item.WarehousingCount - warehouseInfo.WarehousingCount
647
+			}
648
+			item.StockMaxNumber = warehouseInfo.StockMaxNumber + total
649
+			if item.WarehousingCount < warehouseInfo.WarehousingCount {
650
+				total = warehouseInfo.WarehousingCount - item.WarehousingCount
651
+			}
652
+			item.StockMaxNumber = warehouseInfo.StockMaxNumber - total
653
+			if item.WarehousingCount == warehouseInfo.StockMaxNumber {
654
+
655
+				item.StockMaxNumber = item.WarehousingCount
656
+			}
641 657
 			errs = service.UpDateDrugWarehousingInfo(item)
642
-			service.CreateDrugFlow(drugFlow)
658
+
659
+		}
660
+	}
661
+
662
+	if len(drugFlow) > 0 {
663
+		for _, item := range drugFlow {
664
+			flow := models.DrugFlow{
665
+				Count: item.Count,
666
+			}
667
+			parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, item.WarehousingId)
668
+			fmt.Println(parseDateErr)
643 669
 		}
644 670
 	}
645 671
 
@@ -1152,11 +1178,13 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1152 1178
 				remark := items["remark"].(string)
1153 1179
 				max_unit := items["max_unit"].(string)
1154 1180
 				dealer := int64(items["dealer"].(float64))
1155
-				fmt.Println("dealer2222222222222222222", dealer)
1181
+
1156 1182
 				manufacturer := int64(items["manufacturer"].(float64))
1157
-				fmt.Println("manufacturer22222222222222", manufacturer)
1183
+
1158 1184
 				number := items["number"].(string)
1159 1185
 				batch_number := items["batch_number"].(string)
1186
+
1187
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1160 1188
 				var productDates int64
1161 1189
 				var expiryDates int64
1162 1190
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
@@ -1209,6 +1237,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1209 1237
 					Number:                  number,
1210 1238
 					BatchNumber:             batch_number,
1211 1239
 					IsSys:                   0,
1240
+					WarehouseInfoId:         warehouse_info_id,
1212 1241
 				}
1213 1242
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1214 1243
 
@@ -1242,17 +1271,26 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1242 1271
 	//调用出库逻辑
1243 1272
 	for _, item := range warehousingOutInfo {
1244 1273
 		//获取药品库存
1245
-		info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1274
+		info, _ := service.GetDrugTotalCountOne(item.DrugId, item.OrgId, item.WarehouseInfoId)
1246 1275
 		//查询改药品信息
1247 1276
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1277
+		total_count = info.StockMaxNumber*medical.MinNumber + info.StockMinNumber
1278
+		//for _, it := range info{
1279
+		//  if medical.MaxUnit == it.MaxUnit{
1280
+		//    it.Count = it.StockMaxNumber * medical.MinNumber
1281
+		//  }
1282
+		//  if medical.MinUnit == it.MinUnit{
1283
+		//    it.Count = it.StockMinNumber
1284
+		//  }
1285
+		//  total_count += it.Count
1286
+		//}
1287
+		fmt.Println("总库存23232323232232332232332223", total_count)
1248 1288
 		//判断单位是否相等
1249 1289
 		if medical.MaxUnit == item.CountUnit {
1250 1290
 			//转化为最小单位
1251
-			total_count = info.Count * medical.MinNumber
1252 1291
 			prescribing_number_total = item.Count * medical.MinNumber
1253 1292
 		}
1254 1293
 		if medical.MinUnit == item.CountUnit {
1255
-			total_count = info.Count
1256 1294
 			prescribing_number_total = item.Count
1257 1295
 		}
1258 1296
 
@@ -1521,7 +1559,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1521 1559
 				batch_number := items["batch_number"].(string)
1522 1560
 				number := items["number"].(string)
1523 1561
 				max_unit := items["count_unit"].(string)
1524
-
1562
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1525 1563
 				var productDates int64
1526 1564
 				var expiryDates int64
1527 1565
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
@@ -1551,8 +1589,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1551 1589
 					}
1552 1590
 
1553 1591
 				}
1554
-				fmt.Println("生产日期22222222222222222222222222", expiryDates)
1555
-				fmt.Println("生产日期22222222222222222222222222", productDates)
1592
+
1556 1593
 				if id == 0 {
1557 1594
 					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1558 1595
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1577,6 +1614,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1577 1614
 						ProductDate:             productDates,
1578 1615
 						ExpiryDate:              expiryDates,
1579 1616
 						CountUnit:               count_unit,
1617
+						WarehouseInfoId:         warehouse_info_id,
1580 1618
 					}
1581 1619
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1582 1620
 
@@ -1601,7 +1639,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1601 1639
 						Creator:                 adminUserInfo.AdminUser.Id,
1602 1640
 						IsSys:                   0,
1603 1641
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1604
-						WarehouseOutId:          warehouseOut.ID,
1642
+						WarehouseOutId:          id,
1605 1643
 					}
1606 1644
 
1607 1645
 					drugFlow = append(drugFlow, drugflow)
@@ -1646,6 +1684,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1646 1684
 						ProductDate:             productDates,
1647 1685
 						ExpiryDate:              expiryDates,
1648 1686
 						CountUnit:               count_unit,
1687
+						WarehouseInfoId:         warehouse_info_id,
1649 1688
 					}
1650 1689
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1651 1690
 
@@ -2147,6 +2186,8 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2147 2186
 	//扣减库存逻辑
2148 2187
 	for _, item := range cancelStockInfos {
2149 2188
 		var total_number int64
2189
+		var out_number int64
2190
+		var can_number int64
2150 2191
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
2151 2192
 		//将当前退库数转为最小单位
2152 2193
 		if item.MaxUnit == medical.MaxUnit {
@@ -2163,15 +2204,62 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2163 2204
 		total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2164 2205
 		fmt.Println("当前批次总库存", total_count)
2165 2206
 
2207
+		//查询该批次的出库数量
2208
+		outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2209
+		//查询该批次总的退库数量
2210
+
2211
+		canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2212
+		for _, item := range canInfo {
2213
+			if item.MaxUnit == medical.MaxUnit {
2214
+				item.Count = item.Count * medical.MinNumber
2215
+			}
2216
+			if item.MaxUnit == medical.MinUnit {
2217
+				item.Count = item.Count
2218
+			}
2219
+		}
2220
+		for _, item := range canInfo {
2221
+			can_number += item.Count
2222
+		}
2223
+
2224
+		for _, item := range outInfo {
2225
+			if item.CountUnit == medical.MaxUnit {
2226
+				item.Count = item.Count * medical.MinNumber
2227
+			}
2228
+			if item.CountUnit == medical.MinUnit {
2229
+				item.Count = item.Count
2230
+			}
2231
+		}
2232
+		for _, item := range outInfo {
2233
+			out_number += item.Count
2234
+		}
2235
+		fmt.Println("出库数量23232232323222332", out_number)
2236
+		if out_number == 0 {
2237
+			c.ServeSuccessJSON(map[string]interface{}{
2238
+				"msg": "2",
2239
+			})
2240
+			return
2241
+		}
2166 2242
 		//判断退库数量是否大于总入库数量
2167
-		if total_number > total_count {
2243
+		if total_number > out_number {
2244
+			service.UpdateDrugCancel(item.CancelStockId)
2245
+			c.ServeSuccessJSON(map[string]interface{}{
2246
+				"msg": "4",
2247
+			})
2248
+			return
2249
+		}
2250
+
2251
+		//判断总退库数量是否大于出库数量
2252
+		fmt.Println("hhhhhhhhhhh", can_number+total_number)
2253
+		if can_number+total_number > out_number {
2254
+			service.UpdateDrugCancel(item.CancelStockId)
2168 2255
 			c.ServeSuccessJSON(map[string]interface{}{
2169 2256
 				"msg": "2",
2170 2257
 			})
2171 2258
 			return
2172 2259
 		}
2260
+
2173 2261
 		//正常退库
2174
-		if total_number <= total_count {
2262
+		if total_number <= out_number {
2175 2263
 			//创建退库详情
2176 2264
 			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2177 2265
 			//创建库存明细
@@ -2558,6 +2646,8 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2558 2646
 			infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2559 2647
 			fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
2560 2648
 			var total_count int64
2649
+			var cancel_count int64
2650
+			var out_count int64
2561 2651
 			total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2562 2652
 			//转化为最小单位
2563 2653
 			var total_number int64
@@ -2567,13 +2657,46 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2567 2657
 			if item.MaxUnit == medical.MinUnit {
2568 2658
 				total_number = item.Count
2569 2659
 			}
2570
-			//if item.MaxUnit == medical.MaxUnit {
2571
-			//	total_count = infoWareInfo.WarehousingCount
2572
-			//}
2573
-			////转化为最小库存
2574
-			//if item.MaxUnit == medical.MinUnit {
2575
-			//	total_count = infoWareInfo.WarehousingCount * medical.MinNumber
2576
-			//}
2660
+
2661
+			//统计该批次的总出库数
2662
+			outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2663
+			for _, item := range outInfo {
2664
+				if item.CountUnit == medical.MaxUnit {
2665
+					item.Count = item.Count * medical.MinNumber
2666
+				}
2667
+				if item.CountUnit == medical.MinUnit {
2668
+					item.Count = item.Count
2669
+				}
2670
+			}
2671
+
2672
+			for _, item := range outInfo {
2673
+				out_count += item.Count
2674
+			}
2675
+			fmt.Println("out_count232233332232323223", out_count)
2676
+
2677
+			//判断退库数量是否大于出库数量
2678
+			cancelInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2679
+			for _, item := range cancelInfo {
2680
+				if item.MaxUnit == medical.MaxUnit {
2681
+					item.Count = item.Count * medical.MinNumber
2682
+				}
2683
+				if item.MaxUnit == medical.MinUnit {
2684
+					item.Count = item.Count
2685
+				}
2686
+			}
2687
+
2688
+			for _, item := range cancelInfo {
2689
+				cancel_count += item.Count
2690
+			}
2691
+			fmt.Println("cancel_count", cancel_count)
2692
+			fmt.Println("hhhhhh23h2h332322323232", total_number+cancel_count)
2693
+			if total_number+cancel_count > out_count {
2694
+				c.ServeSuccessJSON(map[string]interface{}{
2695
+					"msg": "4",
2696
+				})
2697
+				return
2698
+			}
2699
+
2577 2700
 			//判断退库数量是否大于总入库数量
2578 2701
 			if total_number > total_count {
2579 2702
 				c.ServeSuccessJSON(map[string]interface{}{
@@ -2655,12 +2778,29 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2655 2778
 
2656 2779
 	if len(upDateCancelStockInfos) > 0 {
2657 2780
 		var total int64
2781
+		var out_count int64
2658 2782
 		for _, item := range upDateCancelStockInfos {
2659 2783
 			errs = service.UpDateDrugCancelStockInfo(item)
2660 2784
 			//查询该批次最后一条退库记录
2661 2785
 			info, _ := service.GetLastCancelStockInfo(id)
2662 2786
 			//查询该药品的信息
2663 2787
 			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2788
+			//统计该批次的总出库数
2789
+			outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2790
+			for _, item := range outInfo {
2791
+				if item.CountUnit == medical.MaxUnit {
2792
+					item.Count = item.Count * medical.MinNumber
2793
+				}
2794
+				if item.CountUnit == medical.MinUnit {
2795
+					item.Count = item.Count
2796
+				}
2797
+			}
2798
+
2799
+			for _, item := range outInfo {
2800
+				out_count += item.Count
2801
+			}
2802
+
2803
+			fmt.Println("out_count232233332232323223", out_count)
2664 2804
 
2665 2805
 			if item.MaxUnit == medical.MaxUnit {
2666 2806
 				item.Count = item.Count * medical.MinNumber

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

@@ -1851,7 +1851,10 @@ func (c *GobalConfigApiController) GetDrugStockList() {
1851 1851
 	adminUserInfo := c.GetAdminUserInfo()
1852 1852
 
1853 1853
 	//查询入库数量
1854
-	list, total, err := service.GetDrugStockList(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
1854
+	//list, total, err := service.GetDrugStockList(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
1855
+
1856
+	list, total, err := service.GetAllBaseDurgListCount(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
1857
+	fmt.Println("total232323232323232232323", total)
1855 1858
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
1856 1859
 	if err != nil {
1857 1860
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
@@ -2007,18 +2010,19 @@ func (c *GobalConfigApiController) GetDrugCountList() {
2007 2010
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2008 2011
 	list, err := service.GetDrugCountList(startTime, endTime, orgId)
2009 2012
 	countList, err := service.GetMinCountList(startTime, endTime, orgId)
2010
-	outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
2011
-	auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
2013
+	//outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
2014
+	//auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
2012 2015
 	info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
2013 2016
 	cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
2017
+	//service.GetAllCountList(startTime,endTime,orgId)
2014 2018
 	if err != nil {
2015 2019
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2016 2020
 		return
2017 2021
 	}
2018 2022
 	c.ServeSuccessJSON(map[string]interface{}{
2019
-		"countList":       list,
2020
-		"outCountList":    outCountList,
2021
-		"auCountList":     auCountList,
2023
+		"countList": list,
2024
+		//"outCountList":    outCountList,
2025
+		//"auCountList":     auCountList,
2022 2026
 		"minCount":        countList,
2023 2027
 		"info":            info,
2024 2028
 		"cancelCountList": cancelCountList,
@@ -2028,11 +2032,13 @@ func (c *GobalConfigApiController) GetDrugCountList() {
2028 2032
 func (c *GobalConfigApiController) GetSingleOrderDetail() {
2029 2033
 
2030 2034
 	id, _ := c.GetInt64("id")
2035
+	start_time, _ := c.GetInt64("start_time")
2031 2036
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2032 2037
 	list, err := service.GetSingleOrderDetail(id, orgId)
2033 2038
 	outList, err := service.GetAllSingleDrugDetail(id, orgId)
2034 2039
 	dealerList, err := service.GetAllDealerList(orgId)
2035 2040
 	manufacturerList, err := service.GetAllManufacturerList(orgId)
2041
+	drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)
2036 2042
 	if err != nil {
2037 2043
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2038 2044
 		return
@@ -2042,6 +2048,7 @@ func (c *GobalConfigApiController) GetSingleOrderDetail() {
2042 2048
 		"dealerList":       dealerList,
2043 2049
 		"manufacturerList": manufacturerList,
2044 2050
 		"outList":          outList,
2051
+		"drugFlowList":     drugFlowList,
2045 2052
 	})
2046 2053
 }
2047 2054
 

+ 75 - 6
controllers/mobile_api_controllers/dialysis_api_controller.go 查看文件

@@ -3866,7 +3866,7 @@ func (c *DialysisAPIController) EditConsumables() {
3866 3866
 					if err != nil {
3867 3867
 						goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
3868 3868
 						c.ServeSuccessJSON(map[string]interface{}{
3869
-							"message":            "1",
3869
+							"message":            "2",
3870 3870
 							"good_name":          goodObj.GoodName,
3871 3871
 							"specification_name": goodObj.SpecificationName,
3872 3872
 						})
@@ -4591,9 +4591,43 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4591 4591
 			UpdateCreator:           creater,
4592 4592
 			PatientId:               patient_id,
4593 4593
 		}
4594
-		//创建流水表
4595
-		err := service.CreateStockFlowOne(stockFlow)
4596
-		fmt.Println("h2h3h2323342i24i242i4u2i4242u42424", err)
4594
+		exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
4595
+		if errflow == gorm.ErrRecordNotFound {
4596
+			//创建流水表
4597
+			err := service.CreateStockFlowOne(stockFlow)
4598
+			fmt.Println("h2h3h2323342i24i242i4u2i4242u42424", err)
4599
+		} else if errflow == nil {
4600
+			//插入详情明细表
4601
+			stockFlow := models.VmStockFlow{
4602
+				ID:                      exsit.ID,
4603
+				WarehousingId:           warehouseOutInfos.WarehouseInfotId,
4604
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4605
+				WarehouseOutId:          warehouseOut.ID,
4606
+				GoodId:                  good_yc.GoodId,
4607
+				Number:                  warehouseOutInfos.Number,
4608
+				ProductDate:             stockInInfo.ProductDate,
4609
+				ExpireDate:              stockInInfo.ExpiryDate,
4610
+				Count:                   exsit.Count - delete_count,
4611
+				Price:                   stockInInfo.Price,
4612
+				Status:                  1,
4613
+				Ctime:                   time.Now().Unix(),
4614
+				UserOrgId:               good_yc.OrgId,
4615
+				Manufacturer:            stockInInfo.Manufacturer,
4616
+				Dealer:                  stockInInfo.Dealer,
4617
+				LicenseNumber:           stockInInfo.LicenseNumber,
4618
+				IsEdit:                  2,
4619
+				Creator:                 creater,
4620
+				SystemTime:              record_time,
4621
+				ConsumableType:          3,
4622
+				WarehousingDetailId:     0,
4623
+				IsSys:                   1,
4624
+				UpdateCreator:           creater,
4625
+				PatientId:               patient_id,
4626
+			}
4627
+
4628
+			service.UpdatedStockFlow(stockFlow)
4629
+		}
4630
+
4597 4631
 		if errOne != nil {
4598 4632
 			return errOne
4599 4633
 		}
@@ -4601,6 +4635,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4601 4635
 		service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time)
4602 4636
 		//插入详情明细表
4603 4637
 		stockFlow := models.VmStockFlow{
4638
+			WarehousingId:           warehouseOutInfos.WarehouseInfotId,
4604 4639
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4605 4640
 			WarehouseOutId:          warehouseOut.ID,
4606 4641
 			GoodId:                  good_yc.GoodId,
@@ -4623,9 +4658,43 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4623 4658
 			IsSys:                   1,
4624 4659
 			UpdateCreator:           creater,
4625 4660
 			PatientId:               patient_id,
4661
+			ReturnCount:             delete_count,
4626 4662
 		}
4627
-		//创建流水表
4628
-		service.CreateStockFlowOne(stockFlow)
4663
+		exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
4664
+		if errflows == gorm.ErrRecordNotFound {
4665
+			//创建流水表
4666
+			service.CreateStockFlowOne(stockFlow)
4667
+		} else if errflows == nil {
4668
+			stockFlow := models.VmStockFlow{
4669
+				WarehousingId:           warehouseOutInfos.WarehouseInfotId,
4670
+				ID:                      exsit.ID,
4671
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4672
+				WarehouseOutId:          warehouseOut.ID,
4673
+				GoodId:                  good_yc.GoodId,
4674
+				Number:                  warehouseOutInfos.Number,
4675
+				ProductDate:             stockInInfo.ProductDate,
4676
+				ExpireDate:              stockInInfo.ExpiryDate,
4677
+				Count:                   exsit.Count - delete_count,
4678
+				Price:                   stockInInfo.Price,
4679
+				Status:                  1,
4680
+				Ctime:                   time.Now().Unix(),
4681
+				UserOrgId:               good_yc.OrgId,
4682
+				Manufacturer:            stockInInfo.Manufacturer,
4683
+				Dealer:                  stockInInfo.Dealer,
4684
+				LicenseNumber:           stockInInfo.LicenseNumber,
4685
+				IsEdit:                  2,
4686
+				Creator:                 creater,
4687
+				SystemTime:              record_time,
4688
+				ConsumableType:          3,
4689
+				WarehousingDetailId:     0,
4690
+				IsSys:                   1,
4691
+				UpdateCreator:           creater,
4692
+				PatientId:               patient_id,
4693
+				ReturnCount:             delete_count,
4694
+			}
4695
+			service.UpdatedStockFlow(stockFlow)
4696
+		}
4697
+
4629 4698
 	}
4630 4699
 
4631 4700
 	//更改自动出库的表格

+ 41 - 0
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go 查看文件

@@ -3,8 +3,10 @@ package new_mobile_api_controllers
3 3
 import (
4 4
 	"XT_New/controllers/mobile_api_controllers"
5 5
 	"XT_New/enums"
6
+	"XT_New/models"
6 7
 	"XT_New/service"
7 8
 	"fmt"
9
+	"strings"
8 10
 	"time"
9 11
 )
10 12
 
@@ -320,3 +322,42 @@ func (this *StaffScheduleApiController) SearchPatient() {
320 322
 		"schedule": schedule,
321 323
 	})
322 324
 }
325
+
326
+func (this *StaffScheduleApiController) UpdatePatientScheduleById() {
327
+
328
+	ids := this.GetString("ids")
329
+	idSplit := strings.Split(ids, ",")
330
+	var err error
331
+	//查询患者信息
332
+	list, _ := service.GetStaffScheduleById(idSplit)
333
+	if len(list) > 0 {
334
+		for index, _ := range list {
335
+			fmt.Println("index2322332", index)
336
+			schedule := models.XtSchedule{
337
+				PartitionId:  list[0].PartitionId,
338
+				BedId:        list[0].BedId,
339
+				PatientId:    list[0].PatientId,
340
+				ScheduleDate: list[0].ScheduleDate,
341
+				ScheduleType: list[0].ScheduleType,
342
+				ScheduleWeek: list[0].ScheduleWeek,
343
+				ModeId:       list[0].ModeId,
344
+			}
345
+			xtSchedule := models.WeekSchedule{
346
+				PartitionId:  list[1].PartitionId,
347
+				BedId:        list[1].BedId,
348
+				PatientId:    list[1].PatientId,
349
+				ScheduleDate: list[1].ScheduleDate,
350
+				ScheduleType: list[1].ScheduleType,
351
+				ScheduleWeek: list[1].ScheduleWeek,
352
+				ModeId:       list[1].ModeId,
353
+			}
354
+			err = service.UpdateStaffSchedule(list[1].ID, schedule)
355
+			fmt.Println("errrrrrrr2323323232323", err)
356
+			service.UpdateStaffScheduleOne(list[0].ID, xtSchedule)
357
+		}
358
+	}
359
+	fmt.Println(err)
360
+	this.ServeSuccessJSON(map[string]interface{}{
361
+		"msg": "切换成功",
362
+	})
363
+}

+ 1 - 0
controllers/new_mobile_api_controllers/staff_schedule_api_router.go 查看文件

@@ -19,4 +19,5 @@ func StaffScheduleApiControllersRegisterRouters() {
19 19
 	beego.Router("/m/api/getpatientschedulelist", &StaffScheduleApiController{}, "Get:GetPatientScheduleList")
20 20
 	beego.Router("/m/api/deleteSchedule", &StaffScheduleApiController{}, "Get:DeleteSchedule")
21 21
 	beego.Router("/m/api/ssearchpatient", &StaffScheduleApiController{}, "Get:SearchPatient")
22
+	beego.Router("/m/api/updatepatientschedule", &StaffScheduleApiController{}, "Get:UpdatePatientScheduleById")
22 23
 }

+ 38 - 8
controllers/stock_in_api_controller.go 查看文件

@@ -554,6 +554,7 @@ func (c *StockManagerApiController) EditWarehouse() {
554 554
 					stockFlow = append(stockFlow, flow)
555 555
 
556 556
 				} else {
557
+					fmt.Println("id23233232323232323232323223", id)
557 558
 					warehouseInfo := &models.WarehousingInfo{
558 559
 						ID:               id,
559 560
 						WarehousingOrder: warehouse.WarehousingOrder,
@@ -573,14 +574,13 @@ func (c *StockManagerApiController) EditWarehouse() {
573 574
 						Type:             types,
574 575
 						Manufacturer:     manufacturer,
575 576
 						Dealer:           dealer,
576
-						StockCount:       warehousing_count,
577 577
 						LicenseNumber:    license_number,
578 578
 					}
579 579
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
580 580
 
581 581
 					flow := &models.VmStockFlow{
582 582
 						WarehousingOrder:    warehousing.WarehousingOrder,
583
-						WarehousingId:       warehousing.ID,
583
+						WarehousingId:       id,
584 584
 						GoodId:              good_id,
585 585
 						Number:              number,
586 586
 						ProductDate:         productDates,
@@ -614,20 +614,31 @@ func (c *StockManagerApiController) EditWarehouse() {
614 614
 	if len(upDateWarehousingInfo) > 0 {
615 615
 
616 616
 		for _, item := range upDateWarehousingInfo {
617
+
617 618
 			var total int64
618 619
 			var all_total int64
619 620
 			//获取该批次该型号的库存
620
-			info, _ := service.GetLastWarehousingById(item.WarehousingId, item.GoodId)
621
-
621
+			info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
622
+			fmt.Println("oooooooooo", info.WarehousingCount)
622 623
 			//判断 该批次的入库数量
623 624
 			total = item.WarehousingCount - info.WarehousingCount
624
-
625
+			fmt.Println("total232323322332232332", total)
625 626
 			all_total = info.StockCount + total
626 627
 
627 628
 			item.StockCount = all_total
629
+			fmt.Println("hhhhhhhhhhhhh", item.StockCount)
630
+
628 631
 			errs = service.UpDateWarehousingInfo(item)
632
+		}
633
+	}
629 634
 
630
-			service.CreateStockFlow(stockFlow)
635
+	if len(stockFlow) > 0 {
636
+		for _, item := range stockFlow {
637
+			flow := models.VmStockFlow{
638
+				Count: item.Count,
639
+			}
640
+			parseDateErr := service.UpdateStockFlow(flow, item.GoodId, item.WarehousingId)
641
+			fmt.Println(parseDateErr)
631 642
 		}
632 643
 	}
633 644
 
@@ -1929,7 +1940,9 @@ func (c *StockManagerApiController) CreateCancelStock() {
1929 1940
 
1930 1941
 		//统计该耗材的出库数量
1931 1942
 		info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
1943
+		fmt.Println("2333223323322332233223322323", item.Count, info.Count)
1932 1944
 		if item.Count > info.Count {
1945
+			service.UpdateCancelInfo(item.CancelStockId)
1933 1946
 			c.ServeSuccessJSON(map[string]interface{}{
1934 1947
 				"msg": "2",
1935 1948
 			})
@@ -1958,6 +1971,14 @@ func (c *StockManagerApiController) CreateCancelStock() {
1958 1971
 				return
1959 1972
 			}
1960 1973
 
1974
+			//查询该批次的剩余库存
1975
+			wareouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
1976
+			if (wareouseinfo.StockCount + item.Count) > wareouseinfo.WarehousingCount {
1977
+				c.ServeSuccessJSON(map[string]interface{}{
1978
+					"msg": "5",
1979
+				})
1980
+				return
1981
+			}
1961 1982
 			//更改入库数量
1962 1983
 			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
1963 1984
 
@@ -2365,6 +2386,13 @@ func (c *StockManagerApiController) EditCancelStock() {
2365 2386
 				errs = service.UpDateCancelStockInfo(item)
2366 2387
 
2367 2388
 				service.CreateStockFlow(stockFlow)
2389
+				warehouseinfo, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2390
+				if (warehouseinfo.StockCount + total) > warehouseinfo.StockCount {
2391
+					c.ServeSuccessJSON(map[string]interface{}{
2392
+						"msg": "5",
2393
+					})
2394
+					return
2395
+				}
2368 2396
 				parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
2369 2397
 				if parseDateErr != nil {
2370 2398
 					utils.ErrorLog(errs.Error())
@@ -2386,6 +2414,7 @@ func (c *StockManagerApiController) EditCancelStock() {
2386 2414
 				}
2387 2415
 				if item.Count <= infolist.WarehousingCount {
2388 2416
 					var total_count = info.Count - item.Count
2417
+
2389 2418
 					parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
2390 2419
 					if parseDateErr != nil {
2391 2420
 						utils.ErrorLog(errs.Error())
@@ -4281,7 +4310,8 @@ func (this *StockManagerApiController) GetAllStockList() {
4281 4310
 	adminUserInfo := this.GetAdminUserInfo()
4282 4311
 	orgId := adminUserInfo.CurrentOrgId
4283 4312
 
4284
-	list, total, _ := service.GetAllStockList(page, limit, startTime, endTime, types, keywords, orgId)
4313
+	list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
4314
+	fmt.Println("耗材总计23323232232323232323", total)
4285 4315
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4286 4316
 	this.ServeSuccessJSON(map[string]interface{}{
4287 4317
 		"list":             list,
@@ -4440,7 +4470,7 @@ func (this *StockManagerApiController) GetOrderDetailById() {
4440 4470
 	//手动出库
4441 4471
 	info, _ := service.GetWarehouseOutInfoById(id, good_id)
4442 4472
 
4443
-	stockFlowList, err := service.GetStockFlowBatchNumber(id, good_id)
4473
+	stockFlowList, err := service.GetStockFlowBatchNumberOne(id, good_id)
4444 4474
 	if err == nil {
4445 4475
 		this.ServeSuccessJSON(map[string]interface{}{
4446 4476
 			"list":          userDetails,

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

@@ -279,6 +279,7 @@ type VmDrugWarehouseInfo struct {
279 279
 	Count          int64  `gorm:"column:count" json:"count" form:"count"`
280 280
 	MaxUnit        string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
281 281
 	MinUnit        string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
282
+	CountUnit      string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
282 283
 	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
283 284
 	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
284 285
 }

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

@@ -77,7 +77,8 @@ type GoodInfo struct {
77 77
 	DefaultCountUnit            string               `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
78 78
 	MinUnit                     string               `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
79 79
 	Total                       float64              `gorm:"column:total" json:"total" form:"total"`
80
-	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:good_id;AssociationForeignKey:ID" json:"xt_warehouse_info"`
80
+	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"xt_warehouse_info"`
81
+	CancelStockInfo             []*CancelStockInfo   `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"cancel_stock_info"`
81 82
 }
82 83
 
83 84
 func (GoodInfo) TableName() string {

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

@@ -800,6 +800,26 @@ func (XtInspection) TableName() string {
800 800
 	return "xt_inspection"
801 801
 }
802 802
 
803
+type VmInspection struct {
804
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
805
+	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
806
+	OrgId        int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
807
+	ProjectId    int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
808
+	ItemId       int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
809
+	ItemName     string `gorm:"column:item_name" json:"item_name" form:"item_name"`
810
+	ProjectName  string `gorm:"column:project_name" json:"project_name" form:"project_name"`
811
+	InspectType  int64  `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
812
+	InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
813
+	InspectDate  int64  `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
814
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
815
+	CreatedTime  int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
816
+	UpdatedTime  int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
817
+	RangeMin     string `gorm:"column:range_min" json:"range_min" form:"range_min"`
818
+	RangeMax     string `gorm:"column:range_max" json:"range_max" form:"range_max"`
819
+	RangeValue   string `gorm:"column:range_value" json:"range_value" form:"range_value"`
820
+	Unit         string `gorm:"column:unit" json:"unit" form:"unit"`
821
+}
822
+
803 823
 type BloodXtPatients struct {
804 824
 	ID         int64  `gorm:"column:id" json:"id" form:"id"`
805 825
 	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`

+ 2 - 2
models/self_drug_models.go 查看文件

@@ -365,9 +365,9 @@ type XtDrugAutomaticReduceDetail struct {
365 365
 	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
366 366
 	RecordTime              int64  `gorm:"column:record_time" json:"record_time" form:"record_time"`
367 367
 	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
368
-	GoodId                  int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
369
-	GoodTypeId              int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
368
+	DrugId                  int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
370 369
 	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
370
+	CountUnit               string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
371 371
 }
372 372
 
373 373
 func (XtDrugAutomaticReduceDetail) TableName() string {

+ 193 - 0
models/stock_models.go 查看文件

@@ -520,6 +520,7 @@ type VmStockFlow struct {
520 520
 	CancelOutDetailId       int64   `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
521 521
 	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
522 522
 	ExpireDate              int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
523
+	ReturnCount             int64   `gorm:"column:return_count" json:"return_count" form:"return_count"`
523 524
 }
524 525
 
525 526
 func (VmStockFlow) TableName() string {
@@ -555,3 +556,195 @@ type CancelStockInfo struct {
555 556
 func (CancelStockInfo) TableName() string {
556 557
 	return "xt_cancel_stock_info"
557 558
 }
559
+
560
+type VmBaseDrug struct {
561
+	ID                          int64                     `gorm:"column:id" json:"id" form:"id"`
562
+	DrugName                    string                    `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
563
+	Pinyin                      string                    `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
564
+	Wubi                        string                    `gorm:"column:wubi" json:"wubi" form:"wubi"`
565
+	DrugAlias                   string                    `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
566
+	DrugAliasPinyin             string                    `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
567
+	DrugAliasWubi               string                    `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
568
+	DrugCategory                int64                     `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
569
+	DrugSpec                    string                    `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
570
+	DrugType                    int64                     `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
571
+	DrugStockLimit              string                    `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
572
+	DrugOriginPlace             string                    `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
573
+	DrugDosageForm              int64                     `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
574
+	MedicalInsuranceLevel       int64                     `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
575
+	MaxUnit                     string                    `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
576
+	MinNumber                   int64                     `gorm:"column:min_number" json:"min_number" form:"min_number"`
577
+	MinUnit                     string                    `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
578
+	Dose                        float64                   `gorm:"column:dose" json:"dose" form:"dose"`
579
+	DoseUnit                    string                    `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
580
+	UnitMatrixing               string                    `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
581
+	RetailPrice                 float64                   `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
582
+	MinPrice                    float64                   `gorm:"column:min_price" json:"min_price" form:"min_price"`
583
+	LastPrice                   float64                   `gorm:"column:last_price" json:"last_price" form:"last_price"`
584
+	DrugControl                 int64                     `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
585
+	Number                      string                    `gorm:"column:number" json:"number" form:"number"`
586
+	DrugClassify                string                    `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
587
+	DrugDose                    float64                   `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
588
+	DrugDoseUnit                int64                     `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
589
+	MedicalInsuranceNumber      string                    `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
590
+	Manufacturer                int64                     `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
591
+	PharmacologyCategory        int64                     `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
592
+	StatisticsCategory          int64                     `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
593
+	Code                        string                    `gorm:"column:code" json:"code" form:"code"`
594
+	IsSpecialDiseases           int64                     `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
595
+	IsRecord                    int64                     `gorm:"column:is_record" json:"is_record" form:"is_record"`
596
+	Agent                       string                    `gorm:"column:agent" json:"agent" form:"agent"`
597
+	DrugStatus                  string                    `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
598
+	LimitRemark                 string                    `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
599
+	DeliveryWay                 string                    `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
600
+	ExecutionFrequency          string                    `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
601
+	SingleDose                  float64                   `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
602
+	PrescribingNumber           float64                   `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
603
+	Label                       int64                     `gorm:"column:label" json:"label" form:"label"`
604
+	Sort                        int64                     `gorm:"column:sort" json:"sort" form:"sort"`
605
+	IsUseDoctorAdvice           int64                     `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
606
+	IsDefault                   int64                     `gorm:"column:is_default" json:"is_default" form:"is_default"`
607
+	IsChargePredict             int64                     `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
608
+	IsStatisticsWork            int64                     `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
609
+	IsChargeUse                 int64                     `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
610
+	Status                      int64                     `gorm:"column:status" json:"status" form:"status"`
611
+	Ctime                       int64                     `gorm:"column:ctime" json:"ctime" form:"ctime"`
612
+	Mtime                       int64                     `gorm:"column:mtime" json:"mtime" form:"mtime"`
613
+	OrgId                       int64                     `gorm:"column:org_id" json:"org_id" form:"org_id"`
614
+	DrugCode                    string                    `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
615
+	Dealer                      int64                     `gorm:"column:dealer" json:"dealer" form:"dealer"`
616
+	PrescriptionMark            int64                     `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
617
+	RecordDate                  int64                     `gorm:"column:record_date" json:"record_date" form:"record_date"`
618
+	DrugRemark                  string                    `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
619
+	SocialSecurityDirectoryCode string                    `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
620
+	DoseCode                    string                    `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
621
+	IsMark                      int64                     `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
622
+	HospApprFlag                int64                     `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
623
+	LmtUsedFlag                 int64                     `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
624
+	DrugDay                     string                    `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
625
+	Total                       float64                   `gorm:"column:total" json:"total" form:"total"`
626
+	PrescribingNumberUnit       string                    `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
627
+	DrugWarehouseInfo           []*VsDrugWarehouseInfo    `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug_warehouse_info"`
628
+	DrugCancelStockInfo         []*VsDrugCancelStockInfo  `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug_cancel_stock_info"`
629
+	DrugWarehouseOutInfo        []*VsDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug_warehouse_out"`
630
+}
631
+
632
+func (VmBaseDrug) TableName() string {
633
+	return "xt_base_drug"
634
+}
635
+
636
+type VsDrugWarehouseInfo struct {
637
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
638
+	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
639
+	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
640
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
641
+	ProductDate      int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
642
+	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
643
+	WarehousingCount int64   `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
644
+	WarehouseingUnit string  `gorm:"column:warehouseing_unit" json:"warehouseing_unit" form:"warehouseing_unit"`
645
+	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
646
+	MinUnit          string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
647
+	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
648
+	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
649
+	Price            float64 `gorm:"column:price" json:"price" form:"price"`
650
+	TotalPrice       float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
651
+	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
652
+	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
653
+	Remark           string  `gorm:"column:remark" json:"remark" form:"remark"`
654
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
655
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
656
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
657
+	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
658
+	IsReturn         int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
659
+	WarehousingOrder string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
660
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
661
+	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
662
+	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
663
+	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
664
+}
665
+
666
+func (VsDrugWarehouseInfo) TableName() string {
667
+	return "xt_drug_warehouse_info"
668
+}
669
+
670
+type VsDrugCancelStockInfo struct {
671
+	ID               int64       `gorm:"column:id" json:"id" form:"id"`
672
+	DrugId           int64       `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
673
+	CancelStockId    int64       `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
674
+	Count            int64       `gorm:"column:count" json:"count" form:"count"`
675
+	Price            float64     `gorm:"column:price" json:"price" form:"price"`
676
+	Total            float64     `gorm:"column:total" json:"total" form:"total"`
677
+	ProductDate      int64       `gorm:"column:product_date" json:"product_date" form:"product_date"`
678
+	ExpiryDate       int64       `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
679
+	Ctime            int64       `gorm:"column:ctime" json:"ctime" form:"ctime"`
680
+	Mtime            int64       `gorm:"column:mtime" json:"mtime" form:"mtime"`
681
+	Status           int64       `gorm:"column:status" json:"status" form:"status"`
682
+	OrgId            int64       `gorm:"column:org_id" json:"org_id" form:"org_id"`
683
+	OrderNumber      string      `gorm:"column:order_number" json:"order_number" form:"order_number"`
684
+	Type             int64       `gorm:"column:type" json:"type" form:"type"`
685
+	Dealer           string      `gorm:"column:dealer" json:"dealer" form:"dealer"`
686
+	Manufacturer     string      `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
687
+	RetailPrice      float64     `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
688
+	RetailTotalPrice float64     `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
689
+	Number           string      `gorm:"column:number" json:"number" form:"number"`
690
+	RegisterAccount  string      `gorm:"column:register_account" json:"register_account" form:"register_account"`
691
+	Remark           string      `gorm:"column:remark" json:"remark" form:"remark"`
692
+	BatchNumber      string      `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
693
+	MaxUnit          string      `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
694
+	BaseDrugLib      BaseDrugLib `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" `
695
+}
696
+
697
+func (VsDrugCancelStockInfo) TableName() string {
698
+	return "xt_drug_cancel_stock_info"
699
+}
700
+
701
+type VsDrugWarehouseOutInfo struct {
702
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
703
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
704
+	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
705
+	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
706
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
707
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
708
+	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
709
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
710
+	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
711
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
712
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
713
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
714
+	OrgId                   int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
715
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
716
+	IsCancel                int64   `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
717
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
718
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
719
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
720
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
721
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
722
+	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
723
+	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
724
+	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
725
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
726
+}
727
+
728
+func (VsDrugWarehouseOutInfo) TableName() string {
729
+	return "xt_drug_warehouse_out_info"
730
+}
731
+
732
+type VmStockFlowOne struct {
733
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
734
+	WarehousingId           int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
735
+	GoodId                  int64   `gorm:"column:good_id" json:"good_id" form:"good_id"`
736
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
737
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
738
+	PatientId               int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
739
+	SystemTime              int64   `gorm:"column:system_time" json:"system_time" form:"system_time"`
740
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
741
+	WarehousingOrder        string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
742
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
743
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
744
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
745
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
746
+	ExpireDate              int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
747
+	PackingUnit             string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
748
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
749
+	Name                    string  `gorm:"column:name" json:"name" form:"name"`
750
+}

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

@@ -387,7 +387,7 @@ type DeviceNumberViewModel struct {
387 387
 
388 388
 func GetAllValidDeviceNumbers(orgID int64) ([]*DeviceNumberViewModel, error) {
389 389
 	var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
390
-	rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id AND z.status = 1 join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1)", orgID).Rows()
390
+	rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number  as n join xt_device_zone as z on z.id = n.zone_id AND z.status = 1 join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1) order by sort ", orgID).Rows()
391 391
 	defer rows.Close()
392 392
 	if err != nil {
393 393
 		return nil, err

+ 19 - 0
service/doctor_schedule_service.go 查看文件

@@ -615,3 +615,22 @@ func GetSearchPatient(keywords string, orgid int64, startime int64) (schedule []
615 615
 		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
616 616
 	return schedule, err
617 617
 }
618
+
619
+func GetStaffScheduleById(ids []string) (schedule []*models.XtSchedule, err error) {
620
+
621
+	err = XTReadDB().Where("id in(?)", ids).Find(&schedule).Error
622
+	return schedule, err
623
+
624
+}
625
+
626
+func UpdateStaffSchedule(nextid int64, schedule models.XtSchedule) error {
627
+
628
+	err := XTWriteDB().Model(&schedule).Where("id = ?", nextid).Updates(map[string]interface{}{"partition_id": schedule.PartitionId, "bed_id": schedule.BedId, "patient_id": schedule.PatientId, "schedule_type": schedule.ScheduleType, "schedule_week": schedule.ScheduleWeek, "mode_id": schedule.ModeId}).Error
629
+	return err
630
+}
631
+
632
+func UpdateStaffScheduleOne(nextid int64, schedule models.WeekSchedule) error {
633
+
634
+	err := XTWriteDB().Model(&schedule).Where("id = ?", nextid).Updates(map[string]interface{}{"partition_id": schedule.PartitionId, "bed_id": schedule.BedId, "patient_id": schedule.PatientId, "schedule_type": schedule.ScheduleType, "schedule_week": schedule.ScheduleWeek, "mode_id": schedule.ModeId}).Error
635
+	return err
636
+}

+ 45 - 4
service/gobal_config_service.go 查看文件

@@ -499,7 +499,6 @@ func GetDrugWarehuseOrderInfo(orgid int64) (drug []*models.DrugWarehouseInfo, er
499 499
 func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
500 500
 	offset := (page - 1) * limit
501 501
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
502
-
503 502
 	likeKey := "%" + keyword + "%"
504 503
 	if orgid > 0 {
505 504
 		db = db.Where("x.org_id = ?", orgid)
@@ -537,6 +536,26 @@ func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int6
537 536
 	return list, total, err
538 537
 }
539 538
 
539
+func GetAllBaseDurgListCount(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (drug []*models.VmBaseDrug, total int64, err error) {
540
+
541
+	offset := (page - 1) * limit
542
+	db := XTReadDB().Table("xt_base_drug").Where("status = 1")
543
+	likeKey := "%" + keyword + "%"
544
+	if orgid > 0 {
545
+		db = db.Where("org_id = ?", orgid)
546
+	}
547
+	if drugcategory > 0 {
548
+		db = db.Where("drug_type = ?", drugcategory)
549
+	}
550
+
551
+	if len(keyword) > 0 {
552
+		db = db.Where("drug_name like ?", likeKey)
553
+	}
554
+
555
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Preload("DrugWarehouseInfo", "status=1 and org_id = ? and ctime >=? and ctime<=?", orgid, startime, endtime).Preload("DrugCancelStockInfo", "status=1 and org_id = ? and ctime >=? and ctime<=?", orgid, startime, endtime).Preload("DrugWarehouseOutInfo", "status=1 and org_id = ? and ctime >=? and ctime<=?", orgid, startime, endtime).Find(&drug).Error
556
+	return drug, total, err
557
+}
558
+
540 559
 func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
541 560
 
542 561
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
@@ -643,7 +662,7 @@ func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*mo
643 662
 	if orgid > 0 {
644 663
 		db = db.Where("x.org_id = ?", orgid)
645 664
 	}
646
-	err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
665
+	err = db.Select("x.count,x.drug_id,x.count_unit").Find(&info).Error
647 666
 	return info, err
648 667
 }
649 668
 
@@ -659,7 +678,7 @@ func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*m
659 678
 	if orgid > 0 {
660 679
 		db = db.Where("x.org_id = ?", orgid)
661 680
 	}
662
-	err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
681
+	err = db.Select("x.count,x.drug_id,x.count_unit").Find(&info).Error
663 682
 	return info, err
664 683
 
665 684
 }
@@ -681,6 +700,22 @@ func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []
681 700
 	return info, err
682 701
 }
683 702
 
703
+func GetAllCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
704
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
705
+
706
+	if startime > 0 {
707
+		db = db.Where("x.ctime >=?", startime)
708
+	}
709
+	if endtime > 0 {
710
+		db = db.Where("x.ctime<=?", endtime)
711
+	}
712
+	if orgid > 0 {
713
+		db = db.Where("x.org_id = ?", orgid)
714
+	}
715
+	err = db.Find(&info).Error
716
+	return info, err
717
+}
718
+
684 719
 func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
685 720
 
686 721
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
@@ -697,6 +732,12 @@ func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouse
697 732
 	return info, err
698 733
 }
699 734
 
735
+func GetDrugStockFlowDetail(id int64, orgid int64) (drugflow []*models.XtDrugAutomaticReduceDetail, err error) {
736
+
737
+	err = XTReadDB().Where("record_time = ? and org_id = ? and status = 1", id, orgid).Find(&drugflow).Error
738
+	return drugflow, err
739
+}
740
+
700 741
 func GetAllSingleDrugDetail(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
701 742
 
702 743
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
@@ -734,6 +775,6 @@ func FindeDrugWarehouserInfo(ware_out_id int64, drug_id int64, orgid int64) (out
734 775
 
735 776
 func GetDrugFlowBatch(ware_out_id int64, drug_id int64, orgid int64) (flow []*models.DrugFlow, err error) {
736 777
 
737
-	err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and user_org_id = ? and status = 1", ware_out_id, drug_id, orgid).Group("number").Find(&flow).Error
778
+	err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and user_org_id = ? and status = 1", ware_out_id, drug_id, orgid).Find(&flow).Error
738 779
 	return flow, err
739 780
 }

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

@@ -521,7 +521,7 @@ func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int
521 521
 
522 522
 	err := readDb.
523 523
 		Model(&models.DoctorAdvice{}).
524
-		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
524
+		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
525 525
 		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
526 526
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
527 527
 		Scan(&records).Error

+ 37 - 0
service/patientmanage_service.go 查看文件

@@ -1621,3 +1621,40 @@ func GetTotalBedNumber(orgid int64, ids []string) (list []*models.XtDeviceNumber
1621 1621
 	err = db.Count(&total).Find(&list).Error
1622 1622
 	return list, total, err
1623 1623
 }
1624
+
1625
+func GetInspectionMajorItem(startime int64, orgid int64, patientid int64) (inspection []*models.XtInspection, err error) {
1626
+
1627
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
1628
+	if startime > 0 {
1629
+		db = db.Where("x.inspect_date<=?", startime)
1630
+	}
1631
+	if orgid > 0 {
1632
+		db = db.Where("x.org_id = ?", orgid)
1633
+	}
1634
+	if patientid > 0 {
1635
+		db = db.Where("x.patient_id = ?", patientid)
1636
+	}
1637
+	err = db.Group("x.project_id").Find(&inspection).Error
1638
+	return inspection, err
1639
+}
1640
+
1641
+func GetInspectionDetailByProject(project_id int64, patientid int64, inspect_date int64, orgid int64) (inspection []*models.VmInspection, err error) {
1642
+
1643
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
1644
+	table := XTReadDB().Table("xt_inspection_reference as t").Where("t.status = 1")
1645
+	fmt.Println(table)
1646
+	if inspect_date > 0 {
1647
+		db = db.Where("x.inspect_date=?", inspect_date)
1648
+	}
1649
+	if orgid > 0 {
1650
+		db = db.Where("x.org_id = ?", orgid)
1651
+	}
1652
+	if patientid > 0 {
1653
+		db = db.Where("x.patient_id = ?", patientid)
1654
+	}
1655
+	if project_id > 0 {
1656
+		db = db.Where("x.project_id = ?", project_id)
1657
+	}
1658
+	err = db.Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,t.range_max,t.range_min,t.range_value,t.unit").Joins("left join xt_inspection_reference as t on t.id = x.item_id").Scan(&inspection).Error
1659
+	return inspection, err
1660
+}

+ 147 - 0
service/stock_service.go 查看文件

@@ -505,6 +505,11 @@ func UpdateBaseDrug(lib *models.BaseDrugLib, id int64) error {
505 505
 	err := XTWriteDB().Model(&lib).Where("id = ?", id).Updates(map[string]interface{}{"total": lib.Total}).Error
506 506
 	return err
507 507
 }
508
+func FindeLastWarehouseInfo(id int64) (models.DrugWarehouseInfo, error) {
509
+	info := models.DrugWarehouseInfo{}
510
+	err := XTReadDB().Model(&info).Where("id=? and status = 1", id).Find(&info).Error
511
+	return info, err
512
+}
508 513
 
509 514
 func CreateDrugFlow(drugflow []*models.DrugFlow) (err error) {
510 515
 	if len(drugflow) > 0 {
@@ -1397,6 +1402,7 @@ type DrugWarehouseOutInfo struct {
1397 1402
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
1398 1403
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1399 1404
 	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1405
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
1400 1406
 }
1401 1407
 
1402 1408
 func (DrugWarehouseOutInfo) TableName() string {
@@ -1799,6 +1805,13 @@ func GetLastWarehousingById(warehousing_id int64, orgid int64) (models.Warehousi
1799 1805
 	return info, err
1800 1806
 }
1801 1807
 
1808
+func GetLastWarehousingByIdOne(warehousing_id int64, orgid int64) (models.WarehousingInfo, error) {
1809
+
1810
+	info := models.WarehousingInfo{}
1811
+	err = XTReadDB().Model(&info).Where("id = ? and good_id = ? and status = 1", warehousing_id, orgid).Find(&info).Error
1812
+	return info, err
1813
+}
1814
+
1802 1815
 func UpDateWarehousingInfo(info *models.WarehousingInfo) (err error) {
1803 1816
 	err = writeDb.Save(&info).Error
1804 1817
 	return err
@@ -3168,6 +3181,26 @@ func GetAllStockList(page int64, limit int64, startime int64, endtime int64, goo
3168 3181
 	return info, total, err
3169 3182
 }
3170 3183
 
3184
+func GetAllGoodInfoStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.GoodInfo, total int64, err error) {
3185
+
3186
+	offset := (page - 1) * limit
3187
+	db := XTReadDB().Table("xt_good_information as x").Where("x.status= 1")
3188
+
3189
+	likeKey := "%" + keyword + "%"
3190
+	if len(likeKey) > 0 {
3191
+		db = db.Where("x.good_name like ?", likeKey)
3192
+	}
3193
+	if orgid > 0 {
3194
+		db = db.Where("x.org_id = ?", orgid)
3195
+	}
3196
+	if good_type > 0 {
3197
+		db = db.Where("x.good_type_id = ?", good_type)
3198
+	}
3199
+
3200
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Preload("StWarehousingInfo", "status= 1 and org_id =? and ctime>=? and ctime<=?", orgid, startime, endtime).Preload("CancelStockInfo", "status= 1 and org_id =? and ctime>=? and ctime<=?", orgid, startime, endtime).Find(&info).Error
3201
+	return info, total, err
3202
+}
3203
+
3171 3204
 func GetStockListById(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64) (info []*models.VmWarehousingInfo, total int64, err error) {
3172 3205
 
3173 3206
 	offset := (page - 1) * limit
@@ -3514,6 +3547,35 @@ func GetDrugTotalCount(drugid int64, orgid int64) (info models.VmDrugWarehouseIn
3514 3547
 	return info, err
3515 3548
 }
3516 3549
 
3550
+func GetDrugTotalCountSwx(id int64, orgid int64) (info models.VmDrugWarehouseInfo, err error) {
3551
+
3552
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3553
+	if id > 0 {
3554
+		db = db.Where("x.id = ?", id)
3555
+	}
3556
+	if orgid > 0 {
3557
+		db = db.Where("x.org_id = ?", orgid)
3558
+	}
3559
+	err = db.Select("x.drug_id,sum(x.stock_max_number) as count,sum(x.stock_min_number) as stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
3560
+	return info, err
3561
+}
3562
+
3563
+func GetDrugTotalCountOne(drugid int64, orgid int64, id int64) (models.VmDrugWarehouseInfo, error) {
3564
+	info := models.VmDrugWarehouseInfo{}
3565
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3566
+	if id == 0 {
3567
+		db = db.Where("id = ?", id)
3568
+	}
3569
+	if drugid > 0 {
3570
+		db = db.Where("x.drug_id = ?", drugid)
3571
+	}
3572
+	if orgid > 0 {
3573
+		db = db.Where("x.org_id = ?", orgid)
3574
+	}
3575
+	err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
3576
+	return info, err
3577
+}
3578
+
3517 3579
 func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
3518 3580
 
3519 3581
 	lib := models.BaseDrugLib{}
@@ -3668,6 +3730,12 @@ func GetWarehoureOrderInfoCount(goodid int64, orgid int64) (info models.Warehous
3668 3730
 	return info, err
3669 3731
 }
3670 3732
 
3733
+func UpdateCancelInfo(id int64) (models.CancelStock, error) {
3734
+	stock := models.CancelStock{}
3735
+	err := XTWriteDB().Model(&stock).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
3736
+	return stock, err
3737
+}
3738
+
3671 3739
 func GetStockBatchNumber(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
3672 3740
 
3673 3741
 	err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1 and number <> ''", id, orgid).Group("number").Find(&info).Error
@@ -3686,6 +3754,25 @@ func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlo
3686 3754
 	return stock, err
3687 3755
 }
3688 3756
 
3757
+func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
3758
+
3759
+	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1")
3760
+	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
3761
+	fmt.Println(table)
3762
+	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
3763
+	fmt.Println(tableone)
3764
+	if id > 0 {
3765
+		db = db.Where("x.warehouse_out_id = ?", id)
3766
+	}
3767
+	if goodid > 0 {
3768
+		db = db.Where("x.good_id = ?", goodid)
3769
+	}
3770
+
3771
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.number,x.count,x.patient_id,x.system_time,x.is_sys,x.warehousing_order,x.warehouse_out_id,x.warehouse_out_order_number,x.price,x.product_date,x.expire_date,x.ctime,o.packing_unit,t.name").Joins("left join xt_patients as t on t.id = x.patient_id").Joins("left join xt_good_information as o on o.id = x.good_id").Scan(&stock).Error
3772
+	//err = XTReadDB().Model(&stock).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Find(&stock).Error
3773
+	return stock, err
3774
+}
3775
+
3689 3776
 func GetDrugBatchNumber(drug_id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
3690 3777
 
3691 3778
 	err = XTReadDB().Model(&info).Where("drug_id = ? and org_id = ? and status = 1 and batch_number <>''", drug_id, orgid).Find(&info).Error
@@ -3814,6 +3901,25 @@ func CreateStockFlowOne(flow models.VmStockFlow) error {
3814 3901
 	return err
3815 3902
 }
3816 3903
 
3904
+func UpdatedStockFlow(flow models.VmStockFlow) error {
3905
+	err := XTWriteDB().Save(&flow).Error
3906
+	return err
3907
+}
3908
+
3909
+func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (*models.VmStockFlow, error) {
3910
+
3911
+	stock := models.VmStockFlow{}
3912
+	var err error
3913
+	err = XTReadDB().Model(&stock).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehousing_id, patient_id, record_time, good_id).Find(&stock).Error
3914
+	if err == gorm.ErrRecordNotFound {
3915
+		return nil, err
3916
+	}
3917
+	if err != nil {
3918
+		return nil, err
3919
+	}
3920
+	return &stock, nil
3921
+}
3922
+
3817 3923
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
3818 3924
 
3819 3925
 	info := models.WarehouseOutInfo{}
@@ -4119,3 +4225,44 @@ func GetLastCancelInfo(id int64, goodid int64) (models.CancelStockInfo, error) {
4119 4225
 	err := XTReadDB().Model(&info).Where("warehouse_info_id  = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
4120 4226
 	return info, err
4121 4227
 }
4228
+
4229
+func UpdateStockFlow(flow models.VmStockFlow, goodid int64, warehousing_id int64) error {
4230
+
4231
+	err := XTWriteDB().Model(&flow).Where("good_id = ? and warehousing_id= ? and status = 1", goodid, warehousing_id).Updates(map[string]interface{}{"count": flow.Count}).Error
4232
+	return err
4233
+}
4234
+
4235
+func UpdateDrugFlow(flow models.DrugFlow, drugid int64, warehousing_id int64) error {
4236
+
4237
+	drugFlow := models.DrugFlow{}
4238
+	err := XTWriteDB().Model(&drugFlow).Where("drug_id = ? and warehousing_id= ? and status = 1", drugid, warehousing_id).Updates(map[string]interface{}{"count": flow.Count}).Error
4239
+	return err
4240
+}
4241
+
4242
+func UpdateDrugCancel(id int64) (models.DrugCancelStock, error) {
4243
+
4244
+	stock := models.DrugCancelStock{}
4245
+
4246
+	err := XTWriteDB().Model(&stock).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
4247
+	return stock, err
4248
+}
4249
+
4250
+func GetDrugWarehouseOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
4251
+
4252
+	db := XTReadDB().Model(&info)
4253
+	if warehouse_info_id > 0 {
4254
+		db = db.Where("warehouse_info_id = ?", warehouse_info_id)
4255
+	}
4256
+	if drug_id > 0 {
4257
+		db = db.Where("drug_id = ? and status =1", drug_id)
4258
+	}
4259
+
4260
+	err = db.Find(&info).Error
4261
+	return info, err
4262
+}
4263
+
4264
+func GetCancelDrugStockOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugCancelStockInfo, err error) {
4265
+
4266
+	err = XTReadDB().Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
4267
+	return info, err
4268
+}

+ 234 - 51
service/warhouse_service.go 查看文件

@@ -141,6 +141,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
141 141
 			ExpiryDate:              warehouse.ExpiryDate,
142 142
 			PatientId:               advice.PatientId,
143 143
 			Count:                   count,
144
+			WarehouseInfoId:         warehouse.ID,
144 145
 		}
145 146
 
146 147
 		fmt.Println("单据号2232322323232323232323232323232323", warehouseout.WarehouseOutOrderNumber)
@@ -181,8 +182,8 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
181 182
 			UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
182 183
 		}
183 184
 		details := &models.DrugAutomaticReduceDetail{
184
-			WarehouseOutId:          warehouseOutInfo.ID,
185
-			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
185
+			WarehouseOutId:          warehouseout.ID,
186
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
186 187
 			PatientId:               advice.PatientId,
187 188
 			Ctime:                   time.Now().Unix(),
188 189
 			Mtime:                   time.Now().Unix(),
@@ -202,24 +203,27 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
202 203
 		// 判断处方里药品单位是拆零单位还是包装单位,	如果是拆零单位,则根据规格,将拆零数量转为包装数量
203 204
 		var maxNumber int64 = 0
204 205
 		var minNumber int64 = 0
205
-		if advice.PrescribingNumberUnit == drup.MinUnit {
206
+		fmt.Println("单位1111111111", advice.PrescribingNumberUnit)
207
+		fmt.Println("单位222222222222222", drup.MaxUnit)
208
+		if advice.PrescribingNumberUnit == drup.MaxUnit {
206 209
 			maxNumber = count / drup.MinNumber
207 210
 			minNumber = count % drup.MinNumber
208 211
 		} else {
209
-			maxNumber = count
212
+			minNumber = count
210 213
 		}
211
-
214
+		fmt.Println("maxNumber0000000000000", maxNumber)
215
+		fmt.Println("minNumber999999999999999", minNumber)
212 216
 		if warehouse.StockMaxNumber < maxNumber {
213
-			fmt.Println("尽量323223232")
217
+
214 218
 			return errors.New("库存数量不足")
215 219
 		}
216 220
 
217 221
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
218 222
 		warehouse.Mtime = time.Now().Unix()
219
-
220 223
 		if warehouse.StockMinNumber < minNumber {
221 224
 			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
222 225
 			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
226
+
223 227
 		} else {
224 228
 			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
225 229
 		}
@@ -227,6 +231,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
227 231
 		if warehouse.StockMaxNumber < 0 {
228 232
 			return errors.New("库存数量不足")
229 233
 		}
234
+
230 235
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
231 236
 		if errThree != nil {
232 237
 			return errThree
@@ -256,38 +261,71 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
256 261
 			ExpiryDate:              warehouse.ExpiryDate,
257 262
 			PatientId:               advice.PatientId,
258 263
 			Count:                   count,
264
+			WarehouseInfoId:         warehouse.ID,
259 265
 		}
260
-
261
-		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
262
-		if errOne != nil {
263
-			return errOne
264
-		} else {
265
-			details := &models.DrugAutomaticReduceDetail{
266
-				WarehouseOutId:          warehouseOutInfo.ID,
267
-				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
268
-				PatientId:               advice.PatientId,
269
-				Ctime:                   time.Now().Unix(),
270
-				Mtime:                   time.Now().Unix(),
271
-				Status:                  1,
272
-				RecordTime:              advice.RecordDate,
273
-				OrgId:                   orgID,
274
-				DrugId:                  advice.DrugId,
275
-				Count:                   count,
276
-				CountUnit:               advice.PrescribingNumberUnit,
277
-			}
278
-			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
279
-			if errTwo != nil {
280
-				return errTwo
266
+		//查询是否存在数据
267
+		_, errcodes := GetDrugWarehouseOutInfoIsExit(advice.DrugId, advice.PatientId, advice.RecordDate)
268
+		if errcodes == gorm.ErrRecordNotFound {
269
+			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
270
+			if errOne != nil {
271
+				return errOne
281 272
 			}
273
+		} else if errcodes == nil {
274
+			UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
282 275
 		}
276
+
277
+		details := &models.DrugAutomaticReduceDetail{
278
+			WarehouseOutId:          warehouseout.ID,
279
+			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
280
+			PatientId:               advice.PatientId,
281
+			Ctime:                   time.Now().Unix(),
282
+			Mtime:                   time.Now().Unix(),
283
+			Status:                  1,
284
+			RecordTime:              advice.RecordDate,
285
+			OrgId:                   orgID,
286
+			DrugId:                  advice.DrugId,
287
+			Count:                   stock_number,
288
+			CountUnit:               advice.PrescribingNumberUnit,
289
+		}
290
+		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
291
+		if errTwo != nil {
292
+			return errTwo
293
+		}
294
+
283 295
 		// 出库完成后,要将该批次库存清零
284 296
 		warehouse.StockMaxNumber = 0
285 297
 		warehouse.StockMinNumber = 0
286 298
 		warehouse.Mtime = time.Now().Unix()
287 299
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
300
+
288 301
 		if errThree != nil {
289 302
 			return errThree
290 303
 		}
304
+
305
+		drugflow := models.DrugFlow{
306
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
307
+			WarehouseOutId:          warehouseout.ID,
308
+			DrugId:                  advice.DrugId,
309
+			Number:                  warehouse.Number,
310
+			ProductDate:             warehouse.ProductDate,
311
+			ExpireDate:              warehouse.ExpiryDate,
312
+			Count:                   stock_number,
313
+			Price:                   baseInfo.RetailPrice,
314
+			Status:                  1,
315
+			Ctime:                   time.Now().Unix(),
316
+			UserOrgId:               orgID,
317
+			Manufacturer:            warehouse.Manufacturer,
318
+			Dealer:                  warehouse.Dealer,
319
+			BatchNumber:             warehouse.BatchNumber,
320
+			MaxUnit:                 advice.PrescribingNumberUnit,
321
+			ConsumableType:          3,
322
+			IsEdit:                  1,
323
+			Creator:                 advice.ExecutionStaff,
324
+			IsSys:                   1,
325
+			PatientId:               advice.PatientId,
326
+		}
327
+
328
+		CreateDrugFlowOne(drugflow)
291 329
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
292 330
 		prescribingNumber_two_temp := deliver_number - stock_number
293 331
 		overPlusNumber := float64(prescribingNumber_two_temp)
@@ -419,6 +457,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
419 457
 			ProductDate:             warehouse.ProductDate,
420 458
 			ExpiryDate:              warehouse.ExpiryDate,
421 459
 			PatientId:               advice.PatientId,
460
+			WarehouseInfoId:         warehouse.ID,
422 461
 		}
423 462
 
424 463
 		warehouseOutInfo.Count = count
@@ -461,8 +500,8 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
461 500
 		}
462 501
 
463 502
 		details := &models.DrugAutomaticReduceDetail{
464
-			WarehouseOutId:          warehouseOutInfo.ID,
465
-			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
503
+			WarehouseOutId:          warehouseout.ID,
504
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
466 505
 			PatientId:               advice.PatientId,
467 506
 			Ctime:                   time.Now().Unix(),
468 507
 			Mtime:                   time.Now().Unix(),
@@ -535,6 +574,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
535 574
 			ProductDate:             warehouse.ProductDate,
536 575
 			ExpiryDate:              warehouse.ExpiryDate,
537 576
 			PatientId:               advice.PatientId,
577
+			WarehouseInfoId:         warehouse.ID,
538 578
 		}
539 579
 
540 580
 		warehouseOutInfo.Count = count
@@ -548,7 +588,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
548 588
 			Number:                  warehouse.Number,
549 589
 			ProductDate:             warehouse.ProductDate,
550 590
 			ExpireDate:              warehouse.ExpiryDate,
551
-			Count:                   count,
591
+			Count:                   stock_number,
552 592
 			Price:                   baseInfo.RetailPrice,
553 593
 			Status:                  1,
554 594
 			Ctime:                   time.Now().Unix(),
@@ -577,8 +617,8 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
577 617
 			UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
578 618
 		}
579 619
 		details := &models.DrugAutomaticReduceDetail{
580
-			WarehouseOutId:          warehouseOutInfo.ID,
581
-			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
620
+			WarehouseOutId:          warehouseout.ID,
621
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
582 622
 			PatientId:               advice.PatientId,
583 623
 			Ctime:                   time.Now().Unix(),
584 624
 			Mtime:                   time.Now().Unix(),
@@ -668,6 +708,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
668 708
 			Count:                   advice.Count,
669 709
 			RetailPrice:             advice.RetailPrice,
670 710
 			Price:                   advice.Price,
711
+			WarehouseInfoId:         advice.WarehouseInfoId,
671 712
 		}
672 713
 
673 714
 		warehouseOutInfo.Count = prescribingNumber
@@ -872,6 +913,7 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
872 913
 func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
873 914
 
874 915
 	fmt.Println("count23232323232323232323232323", count)
916
+	fmt.Println("hhhh2h3h3h2h23h32hh23h32h23", goods.Count)
875 917
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
876 918
 	var deliver_number int64 = 0
877 919
 	var stock_number int64 = 0
@@ -885,8 +927,6 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
885 927
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
886 928
 	if err != nil {
887 929
 
888
-		fmt.Println("进来232323232323234343434343434343434343", warehouse.StockCount)
889
-
890 930
 		return errors.New("库存数量不足")
891 931
 	}
892 932
 
@@ -949,6 +989,9 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
949 989
 
950 990
 		if errcode == gorm.ErrRecordNotFound {
951 991
 			errTwo := CreateAutoReduceRecord(&details)
992
+			if errTwo != nil {
993
+				return errTwo
994
+			}
952 995
 			//插入库存流水表
953 996
 			flow := models.VmStockFlow{
954 997
 				WarehouseOutId:          warehouseOut.ID,
@@ -974,14 +1017,49 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
974 1017
 				IsSys:                   1,
975 1018
 				PatientId:               patient_id,
976 1019
 			}
977
-			CreateStockFlowOne(flow)
978
-			if errTwo != nil {
979
-				return errTwo
1020
+			//查询流水是否存在
1021
+			exsit, errflow := GetStockFlowIsExsit(warehouseOut.ID, patient_id, record_time, goods.GoodId)
1022
+
1023
+			fmt.Println("什么数据233232323", errflow)
1024
+			if errflow == gorm.ErrRecordNotFound {
1025
+				errThre := CreateStockFlowOne(flow)
1026
+				if errThre != nil {
1027
+					return errThre
1028
+				}
1029
+			} else if errflow == nil {
1030
+				flow := models.VmStockFlow{
1031
+					ID:                      exsit.ID,
1032
+					WarehouseOutId:          warehouseOut.ID,
1033
+					WarehousingId:           warehouse.ID,
1034
+					GoodId:                  goods.GoodId,
1035
+					Number:                  warehouse.Number,
1036
+					ProductDate:             warehouse.ProductDate,
1037
+					ExpireDate:              warehouse.ExpiryDate,
1038
+					Count:                   exsit.Count + goods.Count,
1039
+					Price:                   info.PackingPrice,
1040
+					Status:                  1,
1041
+					Ctime:                   time.Now().Unix(),
1042
+					UserOrgId:               orgID,
1043
+					Manufacturer:            info.Manufacturer,
1044
+					Dealer:                  info.Dealer,
1045
+					LicenseNumber:           warehouse.LicenseNumber,
1046
+					IsEdit:                  2,
1047
+					Creator:                 warehouseOut.Creater,
1048
+					SystemTime:              record_time,
1049
+					ConsumableType:          3,
1050
+					WarehouseOutDetailId:    warehouseOutInfo.ID,
1051
+					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1052
+					IsSys:                   1,
1053
+					PatientId:               patient_id,
1054
+					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1055
+				}
1056
+				errFour := UpdatedStockFlow(flow)
1057
+				if errFour != nil {
1058
+					return errFour
1059
+				}
980 1060
 			}
1061
+
981 1062
 		} else if errcode == nil {
982
-			DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
983
-			CreateAutoReduceRecord(&details)
984
-			//插入库存流水表
985 1063
 			flow := models.VmStockFlow{
986 1064
 				WarehouseOutId:          warehouseOut.ID,
987 1065
 				WarehousingId:           warehouse.ID,
@@ -1006,7 +1084,45 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1006 1084
 				IsSys:                   1,
1007 1085
 				PatientId:               patient_id,
1008 1086
 			}
1009
-			CreateStockFlowOne(flow)
1087
+			//查询流水是否存在
1088
+			exsit, errflow := GetStockFlowIsExsit(warehouseOut.ID, patient_id, record_time, goods.GoodId)
1089
+
1090
+			if errflow == gorm.ErrRecordNotFound {
1091
+				CreateStockFlowOne(flow)
1092
+				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1093
+				CreateAutoReduceRecord(&details)
1094
+			} else if errflow == nil {
1095
+				flow := models.VmStockFlow{
1096
+					ID:                      exsit.ID,
1097
+					WarehouseOutId:          warehouseOut.ID,
1098
+					WarehousingId:           warehouse.ID,
1099
+					GoodId:                  goods.GoodId,
1100
+					Number:                  warehouse.Number,
1101
+					ProductDate:             warehouse.ProductDate,
1102
+					ExpireDate:              warehouse.ExpiryDate,
1103
+					Count:                   exsit.Count + goods.Count,
1104
+					Price:                   info.PackingPrice,
1105
+					Status:                  1,
1106
+					Ctime:                   time.Now().Unix(),
1107
+					UserOrgId:               orgID,
1108
+					Manufacturer:            info.Manufacturer,
1109
+					Dealer:                  info.Dealer,
1110
+					LicenseNumber:           warehouse.LicenseNumber,
1111
+					IsEdit:                  2,
1112
+					Creator:                 warehouseOut.Creater,
1113
+					SystemTime:              record_time,
1114
+					ConsumableType:          3,
1115
+					WarehouseOutDetailId:    warehouseOutInfo.ID,
1116
+					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1117
+					IsSys:                   1,
1118
+					PatientId:               patient_id,
1119
+					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1120
+				}
1121
+				UpdatedStockFlow(flow)
1122
+				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1123
+				CreateAutoReduceRecord(&details)
1124
+			}
1125
+
1010 1126
 		}
1011 1127
 
1012 1128
 		maxNumber = goods.Count
@@ -1029,7 +1145,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1029 1145
 
1030 1146
 		return nil
1031 1147
 	} else {
1032
-
1148
+		fmt.Println("不进来22323232323232323232233223323223322323")
1033 1149
 		// 当刚批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1034 1150
 		warehouseOutInfo := &models.WarehouseOutInfo{
1035 1151
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1056,7 +1172,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1056 1172
 		warehouseOutInfo.Count = stock_number
1057 1173
 
1058 1174
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, goods.PatientId, record_time)
1059
-
1175
+		fmt.Println("hhhhh2h323233223232323", errcodes)
1060 1176
 		if errcodes == gorm.ErrRecordNotFound {
1061 1177
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1062 1178
 
@@ -1072,7 +1188,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1072 1188
 				ProductDate:             warehouse.ProductDate,
1073 1189
 				ExpireDate:              warehouse.ExpiryDate,
1074 1190
 				Count:                   stock_number,
1075
-				Price:                   warehouse.Price,
1191
+				Price:                   info.PackingPrice,
1076 1192
 				Status:                  1,
1077 1193
 				Ctime:                   time.Now().Unix(),
1078 1194
 				UserOrgId:               orgID,
@@ -1088,11 +1204,46 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1088 1204
 				IsSys:                   1,
1089 1205
 				PatientId:               patient_id,
1090 1206
 			}
1091
-			CreateStockFlowOne(flow)
1207
+			//查询流水是否存在
1208
+			exsit, errflows := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1209
+
1210
+			if errflows == gorm.ErrRecordNotFound {
1211
+				CreateStockFlowOne(flow)
1212
+			} else if errflows == nil {
1213
+				flow := models.VmStockFlow{
1214
+					ID:                      exsit.ID,
1215
+					WarehouseOutId:          warehouseOut.ID,
1216
+					WarehousingId:           warehouse.ID,
1217
+					GoodId:                  goods.GoodId,
1218
+					Number:                  warehouse.Number,
1219
+					ProductDate:             warehouse.ProductDate,
1220
+					ExpireDate:              warehouse.ExpiryDate,
1221
+					Count:                   exsit.Count + goods.Count,
1222
+					Price:                   info.PackingPrice,
1223
+					Status:                  1,
1224
+					Ctime:                   time.Now().Unix(),
1225
+					UserOrgId:               orgID,
1226
+					Manufacturer:            info.Manufacturer,
1227
+					Dealer:                  info.Dealer,
1228
+					LicenseNumber:           warehouse.LicenseNumber,
1229
+					IsEdit:                  2,
1230
+					Creator:                 warehouseOut.Creater,
1231
+					SystemTime:              record_time,
1232
+					ConsumableType:          3,
1233
+					WarehouseOutDetailId:    warehouseOutInfo.ID,
1234
+					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1235
+					IsSys:                   1,
1236
+					PatientId:               patient_id,
1237
+					ReturnCount:             exsit.Count + (exsit.Count + deliver_number),
1238
+				}
1239
+				UpdatedStockFlow(flow)
1240
+			}
1241
+
1092 1242
 		} else if errcodes == nil {
1243
+			fmt.Println("尽力3323232322323232323232323232323")
1093 1244
 			goods.Count = deliver_number - stock_number
1094
-			//更新数量为  刚批次剩余数量  + 还有未出的数量
1095
-			warehouseOutInfo.Count = goods.Count + stock_number
1245
+			//更新数量为  批次剩余数量  + 还有未出的数量
1246
+			warehouseOutInfo.Count = stock_number
1096 1247
 			UpdatedWarehouseOutInfo(warehouseOutInfo, goods.GoodId, goods.PatientId, record_time)
1097 1248
 			//插入库存流水表
1098 1249
 			flow := models.VmStockFlow{
@@ -1102,8 +1253,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1102 1253
 				Number:                  warehouse.Number,
1103 1254
 				ProductDate:             warehouse.ProductDate,
1104 1255
 				ExpireDate:              warehouse.ExpiryDate,
1105
-				Count:                   goods.Count + stock_number,
1106
-				Price:                   warehouse.Price,
1256
+				Count:                   stock_number,
1257
+				Price:                   info.PackingPrice,
1107 1258
 				Status:                  1,
1108 1259
 				Ctime:                   time.Now().Unix(),
1109 1260
 				UserOrgId:               orgID,
@@ -1119,7 +1270,39 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1119 1270
 				IsSys:                   1,
1120 1271
 				PatientId:               patient_id,
1121 1272
 			}
1122
-			CreateStockFlowOne(flow)
1273
+			//查询流水是否存在
1274
+			exsit, errflows := GetStockFlowIsExsit(warehouse.ID, patient_id, record_time, goods.GoodId)
1275
+			if errflows == gorm.ErrRecordNotFound {
1276
+				CreateStockFlowOne(flow)
1277
+			} else if errflows == nil {
1278
+				fmt.Println("尽力3323232322323232323232323232323", exsit.Count+goods.Count)
1279
+				flow := models.VmStockFlow{
1280
+					ID:                      exsit.ID,
1281
+					WarehouseOutId:          warehouseOut.ID,
1282
+					WarehousingId:           warehouse.ID,
1283
+					GoodId:                  goods.GoodId,
1284
+					Number:                  warehouse.Number,
1285
+					ProductDate:             warehouse.ProductDate,
1286
+					ExpireDate:              warehouse.ExpiryDate,
1287
+					Count:                   exsit.Count + goods.Count,
1288
+					Price:                   info.PackingPrice,
1289
+					Status:                  1,
1290
+					Ctime:                   time.Now().Unix(),
1291
+					UserOrgId:               orgID,
1292
+					Manufacturer:            info.Manufacturer,
1293
+					Dealer:                  info.Dealer,
1294
+					LicenseNumber:           warehouse.LicenseNumber,
1295
+					IsEdit:                  2,
1296
+					Creator:                 warehouseOut.Creater,
1297
+					SystemTime:              record_time,
1298
+					ConsumableType:          3,
1299
+					WarehouseOutDetailId:    warehouseOutInfo.ID,
1300
+					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1301
+					IsSys:                   1,
1302
+					PatientId:               patient_id,
1303
+				}
1304
+				UpdatedStockFlow(flow)
1305
+			}
1123 1306
 		}
1124 1307
 
1125 1308
 		// 出库完成后,要将该批次库存清零