XMLWAN 3 年 前
コミット
86bc300b00

+ 6 - 2
conf/app.conf ファイルの表示

7
 sessionon = true
7
 sessionon = true
8
 #sessiongcmaxlifetime = 64800
8
 #sessiongcmaxlifetime = 64800
9
 
9
 
10
-tokencookiemaxlifetime = 7200
10
+tokencookiemaxlifetime = 64800
11
 enablexsrf = false
11
 enablexsrf = false
12
 xsrfkey = 61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o
12
 xsrfkey = 61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o
13
 xsrfexpire = 3600
13
 xsrfexpire = 3600
218
 writesgjpatientmysqlpass = 1Q2W3e4r!@#$
218
 writesgjpatientmysqlpass = 1Q2W3e4r!@#$
219
 writesgjpatientmysqlname = sgj_patient
219
 writesgjpatientmysqlname = sgj_patient
220
 
220
 
221
-
221
+readmysqlhost2 = rm-wz9rg531npf61q03tro.mysql.rds.aliyuncs.com
222
+readmysqlport2 = 3306
223
+readmysqluser2 = root
224
+readmysqlpass2 = 1Q2W3e4r!@#$
225
+readmysqlname2 = sgj_xt
222
 
226
 
223
 
227
 
224
 
228
 

+ 181 - 75
controllers/drug_stock_api_contorller.go ファイルの表示

8
 	"encoding/json"
8
 	"encoding/json"
9
 	"fmt"
9
 	"fmt"
10
 	"github.com/astaxie/beego"
10
 	"github.com/astaxie/beego"
11
+	"github.com/jinzhu/gorm"
11
 	"reflect"
12
 	"reflect"
12
 	"strconv"
13
 	"strconv"
13
 	"strings"
14
 	"strings"
626
 
627
 
627
 		errs = service.CreateDrugWarehousingInfo(warehousingInfo)
628
 		errs = service.CreateDrugWarehousingInfo(warehousingInfo)
628
 		if errs == nil {
629
 		if errs == nil {
629
-			service.CreateDrugFlow(drugFlow)
630
 			//更改库存
630
 			//更改库存
631
 			service.UpdateDrugInfo(warehousingInfo)
631
 			service.UpdateDrugInfo(warehousingInfo)
632
-
632
+			for _, it := range warehousingInfo {
633
+				info, _ := service.GetLastDrugWarehouseInfSix(it.DrugId)
634
+				flows := models.DrugFlow{
635
+					WarehousingOrder: info.WarehousingOrder,
636
+					WarehousingId:    info.ID,
637
+					DrugId:           info.DrugId,
638
+					Number:           info.Number,
639
+					ProductDate:      info.ProductDate,
640
+					ExpireDate:       info.ExpiryDate,
641
+					Count:            info.WarehousingCount,
642
+					Price:            info.Price,
643
+					Status:           1,
644
+					Ctime:            ctime,
645
+					UserOrgId:        adminUserInfo.CurrentOrgId,
646
+					Manufacturer:     info.Manufacturer,
647
+					Dealer:           info.Dealer,
648
+					BatchNumber:      info.BatchNumber,
649
+					MaxUnit:          info.MaxUnit,
650
+					MinUnit:          "",
651
+					ConsumableType:   1,
652
+					IsEdit:           1,
653
+					Creator:          adminUserInfo.AdminUser.Id,
654
+					IsSys:            0,
655
+				}
656
+				_, existerrcodes := service.GetDrugFlowIsExist(info.ID, info.DrugId)
657
+				fmt.Println("23323232232323我的时间232332332232332322323232", existerrcodes)
658
+				if existerrcodes == gorm.ErrRecordNotFound {
659
+					service.CreateDrugFlowOne(flows)
660
+				}
661
+			}
633
 		}
662
 		}
634
 
663
 
635
 	}
664
 	}
638
 		var total int64
667
 		var total int64
639
 		var minNumber float64
668
 		var minNumber float64
640
 		var allTotal int64
669
 		var allTotal int64
670
+		var chaTotal int64
641
 		for _, item := range upDateWarehousingInfo {
671
 		for _, item := range upDateWarehousingInfo {
642
 			//查询修改的记录
672
 			//查询修改的记录
643
 			orderInfo, _ := service.GetDrugWarehouseOrderOne(id, item.DrugId)
673
 			orderInfo, _ := service.GetDrugWarehouseOrderOne(id, item.DrugId)
644
 
674
 
675
+			fmt.Println("hh23323232323232332233232", orderInfo)
676
+
645
 			info, _ := service.FindeDrugInfo(item.DrugId)
677
 			info, _ := service.FindeDrugInfo(item.DrugId)
646
 
678
 
679
+			//历史入库总数
647
 			total = orderInfo.StockMaxNumber * info.MinNumber
680
 			total = orderInfo.StockMaxNumber * info.MinNumber
648
 
681
 
649
-			allTotal = item.WarehousingCount*info.MinNumber - total
682
+			//当前入库总数
683
+			allTotal = item.WarehousingCount * info.MinNumber
650
 
684
 
651
-			str := strconv.FormatInt(allTotal, 10)
652
-			minFloat, _ := strconv.ParseFloat(str, 64)
685
+			//如果历史的入库总数 大于当前入库总数 则需要扣减
686
+			if total > allTotal {
687
+				chaTotal = total - allTotal
688
+				str := strconv.FormatInt(chaTotal, 10)
689
+				minFloat, _ := strconv.ParseFloat(str, 64)
653
 
690
 
654
-			minNumber = info.Total + minFloat
691
+				minNumber = info.Total - minFloat
655
 
692
 
656
-			lib := models.BaseDrugLib{
657
-				Total: minNumber,
693
+				lib := models.BaseDrugLib{
694
+					Total: minNumber,
695
+				}
696
+				service.UpdateBaseDrug(&lib, item.DrugId)
658
 			}
697
 			}
659
-			service.UpdateBaseDrug(&lib, item.DrugId)
698
+			//如果历史的入库总数 小于当前入库总数 则需增加库存
699
+			if total < allTotal {
700
+				chaTotal = allTotal - total
701
+				str := strconv.FormatInt(chaTotal, 10)
702
+				minFloat, _ := strconv.ParseFloat(str, 64)
703
+
704
+				minNumber = info.Total + minFloat
705
+
706
+				lib := models.BaseDrugLib{
707
+					Total: minNumber,
708
+				}
709
+				service.UpdateBaseDrug(&lib, item.DrugId)
710
+			}
711
+
660
 			warehouseInfo, _ := service.FindeLastWarehouseInfo(item.ID)
712
 			warehouseInfo, _ := service.FindeLastWarehouseInfo(item.ID)
661
 			fmt.Println("hhhhh23hh32h232332323223", warehouseInfo)
713
 			fmt.Println("hhhhh23hh32h232332323223", warehouseInfo)
662
 			var total int64
714
 			var total int64
715
+
663
 			//比较大小(加)
716
 			//比较大小(加)
717
+			// 如果当前的入库数量 大于 历史入库数量
664
 			if item.WarehousingCount > warehouseInfo.WarehousingCount {
718
 			if item.WarehousingCount > warehouseInfo.WarehousingCount {
665
 				total = item.WarehousingCount - warehouseInfo.WarehousingCount
719
 				total = item.WarehousingCount - warehouseInfo.WarehousingCount
720
+				item.StockMaxNumber = warehouseInfo.StockMaxNumber + total
721
+				fmt.Println("我的世界hhh23323232333232323", item.StockMaxNumber)
722
+				errs = service.UpDateDrugWarehousingInfo(item)
723
+				if len(drugFlow) > 0 {
724
+					for _, it := range drugFlow {
725
+						fmt.Println(it)
726
+						flow := models.DrugFlow{
727
+							Count: item.StockMaxNumber,
728
+						}
729
+						parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, warehouseInfo.WarehousingId)
730
+						fmt.Println(parseDateErr)
731
+					}
732
+				}
666
 			}
733
 			}
667
-			item.StockMaxNumber = warehouseInfo.StockMaxNumber + total
734
+
735
+			// 如果当前的入库数量 小于 历史入库数量
668
 			if item.WarehousingCount < warehouseInfo.WarehousingCount {
736
 			if item.WarehousingCount < warehouseInfo.WarehousingCount {
669
 				total = warehouseInfo.WarehousingCount - item.WarehousingCount
737
 				total = warehouseInfo.WarehousingCount - item.WarehousingCount
738
+				item.StockMaxNumber = warehouseInfo.StockMaxNumber - total
739
+				errs = service.UpDateDrugWarehousingInfo(item)
740
+				if len(drugFlow) > 0 {
741
+					for _, it := range drugFlow {
742
+						fmt.Println(it)
743
+						flow := models.DrugFlow{
744
+							Count: item.StockMaxNumber,
745
+						}
746
+						parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, warehouseInfo.WarehousingId)
747
+						fmt.Println(parseDateErr)
748
+					}
749
+				}
670
 			}
750
 			}
671
-			item.StockMaxNumber = warehouseInfo.StockMaxNumber - total
672
-			if item.WarehousingCount == warehouseInfo.StockMaxNumber {
673
-
674
-				item.StockMaxNumber = item.WarehousingCount
675
-			}
676
-			errs = service.UpDateDrugWarehousingInfo(item)
677
-
678
-		}
679
-	}
680
-
681
-	if len(drugFlow) > 0 {
682
-		for _, item := range drugFlow {
683
-			flow := models.DrugFlow{
684
-				Count: item.Count,
685
-			}
686
-			parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, item.WarehousingId)
687
-			fmt.Println(parseDateErr)
688
 		}
751
 		}
689
 	}
752
 	}
690
 
753
 
1226
 					}
1289
 					}
1227
 
1290
 
1228
 				}
1291
 				}
1229
-				fmt.Println("孟子", warehouseOut.ID)
1292
+
1230
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1293
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1231
 
1294
 
1232
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1295
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1253
 					WarehouseInfoId:         warehouse_info_id,
1316
 					WarehouseInfoId:         warehouse_info_id,
1254
 				}
1317
 				}
1255
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1318
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1256
-				fmt.Println("hhhhhhhhhhhhhhhh", warehouseOut.ID)
1257
 
1319
 
1258
 				drugflow := &models.DrugFlow{
1320
 				drugflow := &models.DrugFlow{
1259
 					WarehouseOutId:          warehouseOut.ID,
1321
 					WarehouseOutId:          warehouseOut.ID,
1280
 			}
1342
 			}
1281
 		}
1343
 		}
1282
 	}
1344
 	}
1283
-	var total_count int64
1284
-	var prescribing_number_total int64
1345
+
1346
+	var total_count int64              //总库存
1347
+	var prescribing_number_total int64 //出库数据
1285
 	//调用出库逻辑
1348
 	//调用出库逻辑
1286
 	for _, item := range warehousingOutInfo {
1349
 	for _, item := range warehousingOutInfo {
1287
 		//获取药品库存
1350
 		//获取药品库存
1288
-		info, _ := service.GetDrugTotalCountOne(item.DrugId, item.OrgId, item.WarehouseInfoId)
1351
+		info, _ := service.GetDrugTotalCountTwo(item.DrugId)
1352
+
1353
+		for _, it := range info {
1354
+			total_count += it.StockMaxNumber*it.MinNumber + it.StockMinNumber
1355
+		}
1289
 		//查询改药品信息
1356
 		//查询改药品信息
1290
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1357
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1291
-		total_count = info.StockMaxNumber*medical.MinNumber + info.StockMinNumber
1292
-		//for _, it := range info{
1293
-		//  if medical.MaxUnit == it.MaxUnit{
1294
-		//    it.Count = it.StockMaxNumber * medical.MinNumber
1295
-		//  }
1296
-		//  if medical.MinUnit == it.MinUnit{
1297
-		//    it.Count = it.StockMinNumber
1298
-		//  }
1299
-		//  total_count += it.Count
1300
-		//}
1301
-		fmt.Println("总库存23232323232232332232332223", total_count)
1358
+
1302
 		//判断单位是否相等
1359
 		//判断单位是否相等
1303
 		if medical.MaxUnit == item.CountUnit {
1360
 		if medical.MaxUnit == item.CountUnit {
1304
 			//转化为最小单位
1361
 			//转化为最小单位
1836
 			}
1893
 			}
1837
 
1894
 
1838
 			all_number = info.Count*medical.MinNumber + info.StockMinNumber
1895
 			all_number = info.Count*medical.MinNumber + info.StockMinNumber
1839
-			fmt.Println("总库存223232", all_number)
1840
-			fmt.Println("当前库存00000000000000000000000000000000000000000", max_number)
1896
+
1841
 			////比较当前出库数量 和 最后一次出库数量,正常出库
1897
 			////比较当前出库数量 和 最后一次出库数量,正常出库
1842
 			if max_number <= min_number {
1898
 			if max_number <= min_number {
1843
 				errs = service.UpDateDrugWarehouseOutInfo(item)
1899
 				errs = service.UpDateDrugWarehouseOutInfo(item)
1844
 				cha_number = min_number - max_number
1900
 				cha_number = min_number - max_number
1845
-				fmt.Println("差库存", cha_number)
1846
-				fmt.Println("最后一次库存0000000000000000000000000000000000000000", min_number)
1901
+
1847
 				if item.CountUnit == medical.MaxUnit {
1902
 				if item.CountUnit == medical.MaxUnit {
1848
 					maxNumber = cha_number / medical.MinNumber
1903
 					maxNumber = cha_number / medical.MinNumber
1849
 					parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1904
 					parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1900
 				}
1955
 				}
1901
 
1956
 
1902
 			}
1957
 			}
1903
-
1904
-			fmt.Println("当前出库", max_number)
1905
-			fmt.Println("最后一次232233", min_number)
1906
 			//退库操作
1958
 			//退库操作
1907
 			if max_number > min_number {
1959
 			if max_number > min_number {
1908
 
1960
 
1911
 				if all_number >= cha_number {
1963
 				if all_number >= cha_number {
1912
 
1964
 
1913
 					errs = service.UpDateDrugWarehouseOutInfo(item)
1965
 					errs = service.UpDateDrugWarehouseOutInfo(item)
1914
-					fmt.Println("232322332233232", item.CountUnit, medical.MaxUnit)
1966
+
1915
 					if item.CountUnit == medical.MaxUnit {
1967
 					if item.CountUnit == medical.MaxUnit {
1916
 						maxNumber = cha_number / medical.MinNumber
1968
 						maxNumber = cha_number / medical.MinNumber
1917
-						fmt.Println("maxNumber232323232323232232", maxNumber)
1969
+
1918
 						parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1970
 						parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1919
-						fmt.Println("parseDateErr9999999999999999999999", parseDateErr)
1971
+						fmt.Println("parseDateErr", parseDateErr)
1920
 						if parseDateErr != nil {
1972
 						if parseDateErr != nil {
1921
 							utils.ErrorLog(errs.Error())
1973
 							utils.ErrorLog(errs.Error())
1922
 							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1974
 							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
2018
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2070
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2019
 		return
2071
 		return
2020
 	}
2072
 	}
2021
-	fmt.Println("cancelStockDate232323223233223", cancelStockDate.Unix())
2022
-
2023
 	adminUserInfo := c.GetAdminUserInfo()
2073
 	adminUserInfo := c.GetAdminUserInfo()
2024
 	operation_time := time.Now().Unix()
2074
 	operation_time := time.Now().Unix()
2025
 	creater := adminUserInfo.AdminUser.Id
2075
 	creater := adminUserInfo.AdminUser.Id
2044
 		Type:         types,
2094
 		Type:         types,
2045
 	}
2095
 	}
2046
 	service.AddSigleDrugCancelStock(&cancelStock)
2096
 	service.AddSigleDrugCancelStock(&cancelStock)
2047
-	fmt.Println("hh232323232323232323232323232322332", parseDateErr)
2097
+
2048
 	dataBody := make(map[string]interface{}, 0)
2098
 	dataBody := make(map[string]interface{}, 0)
2049
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
2099
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
2050
 	if err != nil {
2100
 	if err != nil {
2151
 						dealer_id = item.ID
2201
 						dealer_id = item.ID
2152
 					}
2202
 					}
2153
 				}
2203
 				}
2154
-				fmt.Println("99999999999999999999", batch_number_id)
2204
+
2155
 				cancelStockInfo := &models.DrugCancelStockInfo{
2205
 				cancelStockInfo := &models.DrugCancelStockInfo{
2156
 					OrderNumber:      cancelStock.OrderNumber,
2206
 					OrderNumber:      cancelStock.OrderNumber,
2157
 					CancelStockId:    cancelStock.ID,
2207
 					CancelStockId:    cancelStock.ID,
2227
 		if item.MaxUnit == medical.MinUnit {
2277
 		if item.MaxUnit == medical.MinUnit {
2228
 			total_number = item.Count
2278
 			total_number = item.Count
2229
 		}
2279
 		}
2230
-		fmt.Println("当前库存", total_number)
2280
+		fmt.Println("当前退库数量", total_number)
2231
 		//查询当前药品退库的批次号的总入库数
2281
 		//查询当前药品退库的批次号的总入库数
2232
 		infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2282
 		infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2233
 		fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit, infoWareInfo.StockMaxNumber, infoWareInfo.StockMinNumber)
2283
 		fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit, infoWareInfo.StockMaxNumber, infoWareInfo.StockMinNumber)
2237
 
2287
 
2238
 		//查询该批次的出库数量
2288
 		//查询该批次的出库数量
2239
 		outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2289
 		outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2240
-		//查询该批次总的退库数量
2241
 
2290
 
2291
+		//查询该批次总的退库数量
2242
 		canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2292
 		canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2293
+
2243
 		for _, item := range canInfo {
2294
 		for _, item := range canInfo {
2244
 			if item.MaxUnit == medical.MaxUnit {
2295
 			if item.MaxUnit == medical.MaxUnit {
2245
 				item.Count = item.Count * medical.MinNumber
2296
 				item.Count = item.Count * medical.MinNumber
2263
 		for _, item := range outInfo {
2314
 		for _, item := range outInfo {
2264
 			out_number += item.Count
2315
 			out_number += item.Count
2265
 		}
2316
 		}
2317
+		fmt.Println("当前退库数量", total_number)
2266
 		fmt.Println("出库数量23232232323222332", out_number)
2318
 		fmt.Println("出库数量23232232323222332", out_number)
2267
 		if out_number == 0 {
2319
 		if out_number == 0 {
2320
+			service.UpdateDrugCancel(item.CancelStockId)
2268
 			c.ServeSuccessJSON(map[string]interface{}{
2321
 			c.ServeSuccessJSON(map[string]interface{}{
2269
 				"msg": "2",
2322
 				"msg": "2",
2270
 			})
2323
 			})
2274
 		if total_number > out_number {
2327
 		if total_number > out_number {
2275
 			service.UpdateDrugCancel(item.CancelStockId)
2328
 			service.UpdateDrugCancel(item.CancelStockId)
2276
 			c.ServeSuccessJSON(map[string]interface{}{
2329
 			c.ServeSuccessJSON(map[string]interface{}{
2277
-				"msg": "4",
2330
+				"msg": "2",
2278
 			})
2331
 			})
2279
 			return
2332
 			return
2280
 		}
2333
 		}
2281
 
2334
 
2282
 		//判断总退库数量是否大于出库数量
2335
 		//判断总退库数量是否大于出库数量
2283
-		fmt.Println("hhhhhhhhhhh", can_number+total_number)
2336
+		fmt.Println("该批次总退库数量", can_number+total_number)
2337
+		fmt.Println("总出口数量", out_number)
2284
 		if can_number+total_number > out_number {
2338
 		if can_number+total_number > out_number {
2339
+			//清空退库单
2285
 			service.UpdateDrugCancel(item.CancelStockId)
2340
 			service.UpdateDrugCancel(item.CancelStockId)
2286
 			c.ServeSuccessJSON(map[string]interface{}{
2341
 			c.ServeSuccessJSON(map[string]interface{}{
2287
 				"msg": "2",
2342
 				"msg": "2",
2297
 			errs = service.CreateDrugFlow(drugFlow)
2352
 			errs = service.CreateDrugFlow(drugFlow)
2298
 
2353
 
2299
 			var total int64
2354
 			var total int64
2300
-			////退库到当前批次,获取当前退库批次的库存
2301
-			//info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
2302
 
2355
 
2303
 			if medical.MaxUnit == item.MaxUnit {
2356
 			if medical.MaxUnit == item.MaxUnit {
2304
 				total = item.Count
2357
 				total = item.Count
2318
 				})
2371
 				})
2319
 			}
2372
 			}
2320
 			if medical.MinUnit == item.MaxUnit {
2373
 			if medical.MinUnit == item.MaxUnit {
2321
-				fmt.Println("hhhhhh2323323232322332232332999999999进来", item.Count)
2322
 				total = item.Count
2374
 				total = item.Count
2323
 				warehouseInfo := models.XtDrugWarehouseInfo{
2375
 				warehouseInfo := models.XtDrugWarehouseInfo{
2324
 					StockMinNumber: total,
2376
 					StockMinNumber: total,
2664
 			}
2716
 			}
2665
 		}
2717
 		}
2666
 	}
2718
 	}
2667
-	fmt.Println("cancelStockInfos232323223323223322323223", cancelStockInfos)
2668
-	fmt.Println("cancelStockInfos232323223323223322323223", upDateCancelStockInfos)
2669
 
2719
 
2670
 	var errs error
2720
 	var errs error
2671
 	if len(cancelStockInfos) > 0 {
2721
 	if len(cancelStockInfos) > 0 {
2741
 				//创建退库详情
2791
 				//创建退库详情
2742
 				errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2792
 				errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2743
 				//创建库存明细
2793
 				//创建库存明细
2744
-				errs = service.CreateDrugFlow(drugFlow)
2794
+				//查询这个药品这个订单是否已存在流水
2795
+				for _, items := range drugFlow {
2796
+					_, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
2797
+					if errsId == gorm.ErrRecordNotFound {
2798
+						errs = service.CreateDrugFlowTwo(items)
2799
+					}
2800
+				}
2745
 
2801
 
2746
 				//获取该批次最后一条退库详情
2802
 				//获取该批次最后一条退库详情
2747
 				lastCancel, _ := service.GetLastCancelStockInfo(id)
2803
 				lastCancel, _ := service.GetLastCancelStockInfo(id)
2753
 				if lastCancel.MaxUnit == medical.MinUnit {
2809
 				if lastCancel.MaxUnit == medical.MinUnit {
2754
 					cancel_number = lastCancel.Count
2810
 					cancel_number = lastCancel.Count
2755
 				}
2811
 				}
2756
-				fmt.Println("999999232323232232232323232323", lastCancel)
2812
+				fmt.Println("999999232323232232232323232323", item.Count, cancel_number)
2757
 				var total int64
2813
 				var total int64
2758
 
2814
 
2759
 				if medical.MaxUnit == item.MaxUnit {
2815
 				if medical.MaxUnit == item.MaxUnit {
2803
 		}
2859
 		}
2804
 	}
2860
 	}
2805
 	if len(drugFlow) > 0 {
2861
 	if len(drugFlow) > 0 {
2806
-		parseDateErr := service.CreateDrugFlow(drugFlow)
2807
-		fmt.Println(parseDateErr)
2862
+		for _, items := range drugFlow {
2863
+			_, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
2864
+			if errsId == gorm.ErrRecordNotFound {
2865
+				errs = service.CreateDrugFlowTwo(items)
2866
+			}
2867
+		}
2808
 	}
2868
 	}
2809
 
2869
 
2810
 	if len(upDateCancelStockInfos) > 0 {
2870
 	if len(upDateCancelStockInfos) > 0 {
2811
 		var total int64
2871
 		var total int64
2812
 		var out_count int64
2872
 		var out_count int64
2873
+		var cancel_count int64
2874
+		var now_count int64
2875
+		var all_count int64
2813
 		for _, item := range upDateCancelStockInfos {
2876
 		for _, item := range upDateCancelStockInfos {
2877
+			//查询最后一条退库记录
2878
+			info, _ := service.GetLastCancelStockInfoOne(id, item.DrugId)
2814
 			errs = service.UpDateDrugCancelStockInfo(item)
2879
 			errs = service.UpDateDrugCancelStockInfo(item)
2815
-			//查询该批次最后一条退库记录
2816
-			info, _ := service.GetLastCancelStockInfo(id)
2880
+			fmt.Println("hh23232oooooooo2o3o2o32o23oo23o23o23", info)
2817
 			//查询该药品的信息
2881
 			//查询该药品的信息
2818
 			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2882
 			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2819
 			//统计该批次的总出库数
2883
 			//统计该批次的总出库数
2820
 			outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2884
 			outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2885
+			//查询该批次的总退库数量
2886
+			cancelInfo, _ := service.GetTotalDrugCancelInfo(item.BatchNumberId, item.DrugId, item.ID)
2821
 			for _, item := range outInfo {
2887
 			for _, item := range outInfo {
2822
 				if item.CountUnit == medical.MaxUnit {
2888
 				if item.CountUnit == medical.MaxUnit {
2823
 					item.Count = item.Count * medical.MinNumber
2889
 					item.Count = item.Count * medical.MinNumber
2831
 				out_count += item.Count
2897
 				out_count += item.Count
2832
 			}
2898
 			}
2833
 
2899
 
2900
+			for _, item := range cancelInfo {
2901
+				if item.MaxUnit == medical.MaxUnit {
2902
+					item.Count = item.Count * medical.MinNumber
2903
+				}
2904
+				if item.MaxUnit == medical.MinUnit {
2905
+					item.Count = item.Count
2906
+				}
2907
+			}
2908
+
2909
+			for _, item := range cancelInfo {
2910
+				cancel_count += item.Count
2911
+			}
2912
+
2834
 			fmt.Println("out_count232233332232323223", out_count)
2913
 			fmt.Println("out_count232233332232323223", out_count)
2835
 
2914
 
2836
 			if item.MaxUnit == medical.MaxUnit {
2915
 			if item.MaxUnit == medical.MaxUnit {
2837
-				item.Count = item.Count * medical.MinNumber
2916
+				now_count = item.Count * medical.MinNumber
2917
+			}
2918
+			if item.MaxUnit == medical.MinUnit {
2919
+				now_count = item.Count
2920
+			}
2921
+			fmt.Println("hhhhhh2323322323", now_count+cancel_count)
2922
+			//总退库批次
2923
+			all_count = now_count + cancel_count
2924
+
2925
+			//该批次的总出库数小与退库数报错返回
2926
+			if all_count > out_count {
2927
+				c.ServeSuccessJSON(map[string]interface{}{
2928
+					"msg": "4",
2929
+				})
2930
+				return
2931
+			}
2932
+
2933
+			if item.MaxUnit == medical.MaxUnit {
2838
 				//更新库存
2934
 				//更新库存
2839
 				total = item.Count - info.Count
2935
 				total = item.Count - info.Count
2840
-				fmt.Println("total232323232323232232323", total)
2841
-				service.UpdatedDrugInfo(item.BatchNumberId, total)
2936
+				parseDateErr := service.UpdatedDrugInfo(item.BatchNumberId, total)
2937
+				fmt.Println("parseDateErr", parseDateErr)
2938
+
2939
+				flow := models.DrugFlow{
2940
+					Count: item.Count,
2941
+				}
2942
+				service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
2842
 				break
2943
 				break
2944
+
2843
 			}
2945
 			}
2844
 
2946
 
2845
 			if item.MaxUnit == medical.MinUnit {
2947
 			if item.MaxUnit == medical.MinUnit {
2846
 				item.Count = item.Count
2948
 				item.Count = item.Count
2847
 				total = item.Count - info.Count
2949
 				total = item.Count - info.Count
2848
 				service.UpdatedDrugInfoOne(item.BatchNumberId, total)
2950
 				service.UpdatedDrugInfoOne(item.BatchNumberId, total)
2951
+				flow := models.DrugFlow{
2952
+					Count: item.Count,
2953
+				}
2954
+				service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
2849
 				break
2955
 				break
2850
 			}
2956
 			}
2851
 		}
2957
 		}

+ 5 - 8
controllers/manage_api_controller.go ファイルの表示

2300
 	id, _ := this.GetInt64("id")
2300
 	id, _ := this.GetInt64("id")
2301
 	fmt.Println("id", id)
2301
 	fmt.Println("id", id)
2302
 	patientid, _ := this.GetInt64("patientid")
2302
 	patientid, _ := this.GetInt64("patientid")
2303
-	device, err := service.GetUserInformation(id)
2303
+	device, _ := service.GetUserInformation(id)
2304
 	//获取初次使用记录
2304
 	//获取初次使用记录
2305
-	macher, err := service.GetUserTotalByMacher(device.EquimentId)
2306
-	count, err := service.GetUserTotalCount(orgId, device.BedNumber)
2307
-	patients, err := service.GetPatientInfoMation(patientid)
2308
-	if err != nil {
2309
-		this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
2310
-		return
2311
-	}
2305
+	macher, _ := service.GetUserTotalByMacher(device.EquimentId)
2306
+	count, _ := service.GetUserTotalCount(orgId, device.BedNumber)
2307
+	patients, _ := service.GetPatientInfoMation(patientid)
2308
+
2312
 	this.ServeSuccessJSON(map[string]interface{}{
2309
 	this.ServeSuccessJSON(map[string]interface{}{
2313
 		"device":   device,
2310
 		"device":   device,
2314
 		"patients": patients,
2311
 		"patients": patients,

+ 27 - 37
controllers/mobile_api_controllers/dialysis_api_controller.go ファイルの表示

1493
 		tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
1493
 		tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
1494
 
1494
 
1495
 	}
1495
 	}
1496
-	if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 {
1496
+	if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 {
1497
 		evaluation, _ := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, recordDate.Unix())
1497
 		evaluation, _ := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, recordDate.Unix())
1498
 		if evaluation.SystolicBloodPressure == 0 {
1498
 		if evaluation.SystolicBloodPressure == 0 {
1499
 			evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
1499
 			evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
3632
 				}
3632
 				}
3633
 			}
3633
 			}
3634
 
3634
 
3635
-			//出库
3636
-			//err = service.ConsumablesDeliveryTotal(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
3637
-			//fmt.Println("err", err)
3638
-			////查询今日出库数据
3639
-			//list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
3640
-			//
3641
-			//if len(list) == 0 {
3642
-			//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3643
-			//	return
3644
-			//}
3645
-			//
3646
-			//for _, item := range list {
3647
-			//	prepare := models.DialysisBeforePrepare{
3648
-			//		UserOrgId:  item.OrgId,
3649
-			//		PatientId:  patient_id,
3650
-			//		RecordDate: item.RecordTime,
3651
-			//		GoodId:     item.GoodId,
3652
-			//		GoodTypeId: item.GoodTypeId,
3653
-			//		Count:      item.Count,
3654
-			//		Ctime:      time.Now().Unix(),
3655
-			//		Creater:    adminUser.AdminUser.Id,
3656
-			//		Status:     1,
3657
-			//	}
3658
-			//	//删除准备表数据
3659
-			//	service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
3660
-			//	service.CreateDialysisBeforePrepareOne(&prepare)
3661
-			//}
3662
-
3663
 		}
3635
 		}
3664
 	}
3636
 	}
3665
 
3637
 
3905
 				}
3877
 				}
3906
 
3878
 
3907
 				for _, item := range beforePrepares {
3879
 				for _, item := range beforePrepares {
3908
-					fmt.Println("23232323232323为什么99999999999999999999999999999999", item.GoodId)
3909
 
3880
 
3910
 					//1.查看该患者该耗材型号最后一次出库数量
3881
 					//1.查看该患者该耗材型号最后一次出库数量
3911
 					goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
3882
 					goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
3930
 
3901
 
3931
 						//查询该批次剩余库存
3902
 						//查询该批次剩余库存
3932
 						lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
3903
 						lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
3904
+						fmt.Println("剩余库存333333333333333", lastInfo)
3933
 						if lastInfo.StockCount == 0 {
3905
 						if lastInfo.StockCount == 0 {
3934
 							//查询该耗材的总库存
3906
 							//查询该耗材的总库存
3935
 							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
3907
 							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
3944
 							}
3916
 							}
3945
 
3917
 
3946
 						}
3918
 						}
3919
+
3947
 						//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
3920
 						//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
3948
 						fmt.Println("剩余库存", lastInfo.StockCount)
3921
 						fmt.Println("剩余库存", lastInfo.StockCount)
3949
 						fmt.Println("差", last_total)
3922
 						fmt.Println("差", last_total)
3950
-						if lastInfo.StockCount >= last_total {
3923
+						//查询该耗材的总库存
3924
+						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
3925
+						// 如果库存差大于剩余库存则提示库存不足
3926
+						if last_total > wareinfo.StockCount {
3927
+							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3928
+							c.ServeSuccessJSON(map[string]interface{}{
3929
+								"message":            "1",
3930
+								"good_name":          goodObj.GoodName,
3931
+								"specification_name": goodObj.SpecificationName,
3932
+							})
3933
+							return
3934
+						} else {
3951
 							err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3935
 							err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3952
 							break
3936
 							break
3953
 						}
3937
 						}
3954
 
3938
 
3955
-						//如果库存不够,则出库到下一个批次
3956
-						if lastInfo.StockCount < last_total {
3957
-
3958
-							err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3959
-							break
3960
-						}
3939
+						//if lastInfo.StockCount >= last_total {
3940
+						//	err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3941
+						//	break
3942
+						//}
3943
+						//
3944
+						////如果库存不够,则出库到下一个批次
3945
+						//if lastInfo.StockCount < last_total {
3946
+						//
3947
+						//	err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3948
+						//	break
3949
+						//}
3961
 					}
3950
 					}
3962
 				}
3951
 				}
3963
 
3952
 
4896
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
4885
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
4897
 	fmt.Println("goods222222222222", goods)
4886
 	fmt.Println("goods222222222222", goods)
4898
 	fmt.Println("goodsy999999999999", goods_yc)
4887
 	fmt.Println("goodsy999999999999", goods_yc)
4888
+
4899
 	if len(goods) > 0 {
4889
 	if len(goods) > 0 {
4900
 		out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
4890
 		out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
4901
 		if err == gorm.ErrRecordNotFound {
4891
 		if err == gorm.ErrRecordNotFound {

+ 18 - 32
controllers/mobile_api_controllers/patient_api_controller.go ファイルの表示

608
 
608
 
609
 		//自备药信息
609
 		//自备药信息
610
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
610
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
611
-		fmt.Println("2323232323232323232开关", drugStockConfig.IsOpen)
611
+
612
 		if drugStockConfig.IsOpen == 1 {
612
 		if drugStockConfig.IsOpen == 1 {
613
 			if groupno > 0 {
613
 			if groupno > 0 {
614
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
614
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
624
 					var prescribing_number_total int64
624
 					var prescribing_number_total int64
625
 					for _, item := range advices {
625
 					for _, item := range advices {
626
 						if item.Way == 1 {
626
 						if item.Way == 1 {
627
-							//查询该药品是否有库存
627
+							//查询该药品的剩余库存
628
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
628
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
629
-							fmt.Println("list23232323232232323232323232", list)
629
+
630
 							//查询改药品信息
630
 							//查询改药品信息
631
 							medical, _ := service.GetBaseDrugMedical(item.DrugId)
631
 							medical, _ := service.GetBaseDrugMedical(item.DrugId)
632
 							//判断单位是否相等
632
 							//判断单位是否相等
644
 								prescribing_number_total = count
644
 								prescribing_number_total = count
645
 							}
645
 							}
646
 
646
 
647
-							fmt.Println("数量", prescribing_number_total)
648
-							fmt.Println("数量二", total)
647
+							fmt.Println("开医嘱数量", prescribing_number_total)
648
+							fmt.Println("剩余库存", total)
649
 
649
 
650
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
650
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
651
 								c.ServeSuccessJSON(map[string]interface{}{
651
 								c.ServeSuccessJSON(map[string]interface{}{
686
 						isHasWay = true
686
 						isHasWay = true
687
 					}
687
 					}
688
 				}
688
 				}
689
-				fmt.Println("hh2h32323232323232323", isHasWay)
689
+
690
 				if isHasWay {
690
 				if isHasWay {
691
 					var total int64
691
 					var total int64
692
 					var prescribing_number_total int64
692
 					var prescribing_number_total int64
693
 					for _, item := range advices {
693
 					for _, item := range advices {
694
-						fmt.Println("hhh23h2h3h232323", item.Way)
694
+
695
 						if item.Way == 1 {
695
 						if item.Way == 1 {
696
-							//查询该药品是否有库存
696
+							//查询该药品的剩余库存
697
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
697
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
698
 
698
 
699
 							//查询改药品信息
699
 							//查询改药品信息
700
 							medical, _ := service.GetBaseDrugMedical(item.DrugId)
700
 							medical, _ := service.GetBaseDrugMedical(item.DrugId)
701
+
701
 							//判断单位是否相等
702
 							//判断单位是否相等
702
 							if medical.MaxUnit == item.PrescribingNumberUnit {
703
 							if medical.MaxUnit == item.PrescribingNumberUnit {
703
 								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
704
 								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
704
 								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
705
 								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
705
 								//转化为最小单位
706
 								//转化为最小单位
706
-								total = list.Count * medical.MinNumber
707
+								total = list.Count*medical.MinNumber + list.StockMinNumber
708
+								fmt.Println("美国疫情2332323233232323232332323232233232323232", total)
707
 								prescribing_number_total = count * medical.MinNumber
709
 								prescribing_number_total = count * medical.MinNumber
708
 							}
710
 							}
711
+
709
 							if medical.MinUnit == item.PrescribingNumberUnit {
712
 							if medical.MinUnit == item.PrescribingNumberUnit {
710
 								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
713
 								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
711
 								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
714
 								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
713
 								prescribing_number_total = count
716
 								prescribing_number_total = count
714
 							}
717
 							}
715
 
718
 
716
-							fmt.Println("数量", prescribing_number_total)
717
-							fmt.Println("数量二", total)
719
+							fmt.Println("开医嘱数量", prescribing_number_total)
720
+							fmt.Println("剩余库存", total)
718
 
721
 
719
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
722
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
720
 								c.ServeSuccessJSON(map[string]interface{}{
723
 								c.ServeSuccessJSON(map[string]interface{}{
732
 								})
735
 								})
733
 								return
736
 								return
734
 							}
737
 							}
738
+
735
 							if prescribing_number_total <= total {
739
 							if prescribing_number_total <= total {
736
 								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
740
 								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
737
 								c.ServeSuccessJSON(map[string]interface{}{
741
 								c.ServeSuccessJSON(map[string]interface{}{
900
 				for _, item := range advices {
904
 				for _, item := range advices {
901
 
905
 
902
 					advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
906
 					advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
903
-					//查询该药品是否有库存
904
-					//  list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
905
-					//  prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
906
-					//  count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
907
-					//  if list.Count == 0 {
908
-					//    c.ServeSuccessJSON(map[string]interface{}{
909
-					//      "msg":    "1",
910
-					//      "advice": advice,
911
-					//      "ids":    ids,
912
-					//    })
913
-					//    return
914
-					//  }
915
-					//  if count > list.Count {
916
-					//    c.ServeSuccessJSON(map[string]interface{}{
917
-					//      "msg":    "2",
918
-					//      "advice": advice,
919
-					//      "ids":    ids,
920
-					//    })
921
-					//    return
922
-					//}
907
+
923
 					var total int64
908
 					var total int64
924
 					var prescribing_number_total int64
909
 					var prescribing_number_total int64
925
 					//查询该药品是否有库存
910
 					//查询该药品是否有库存
932
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
917
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
933
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
918
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
934
 						//转化为最小单位
919
 						//转化为最小单位
935
-						total = list.Count * medical.MinNumber
920
+						total = list.Count*medical.MinNumber + list.StockMinNumber
936
 						prescribing_number_total = count * medical.MinNumber
921
 						prescribing_number_total = count * medical.MinNumber
937
 					}
922
 					}
923
+					fmt.Println("医嘱开的数量", total)
938
 					if medical.MinUnit == advice.PrescribingNumberUnit {
924
 					if medical.MinUnit == advice.PrescribingNumberUnit {
939
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
925
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
940
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
926
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)

+ 5 - 46
controllers/patient_api_controller.go ファイルの表示

1678
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1678
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1679
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1679
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1680
 					//转化为最小单位
1680
 					//转化为最小单位
1681
-					total = list.Count * medical.MinNumber
1681
+					total = list.Count*medical.MinNumber + list.StockMinNumber
1682
 					prescribing_number_total = count * medical.MinNumber
1682
 					prescribing_number_total = count * medical.MinNumber
1683
 				}
1683
 				}
1684
 				if medical.MinUnit == item.PrescribingNumberUnit {
1684
 				if medical.MinUnit == item.PrescribingNumberUnit {
1715
 					return
1715
 					return
1716
 				}
1716
 				}
1717
 
1717
 
1718
-				////查询该药品是否有库存
1719
-				//list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1720
-				//prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1721
-				//count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1722
-				//if list.Count == 0 {
1723
-				//	c.ServeSuccessJSON(map[string]interface{}{
1724
-				//		"msg":    "1",
1725
-				//		"advice": advice,
1726
-				//	})
1727
-				//	return
1728
-				//}
1729
-				//if count > list.Count {
1730
-				//	c.ServeSuccessJSON(map[string]interface{}{
1731
-				//		"msg":    "2",
1732
-				//		"advice": advice,
1733
-				//	})
1734
-				//	return
1735
-				//}
1736
-				////调用药品出库接口
1737
-				//service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1738
-
1739
 			}
1718
 			}
1740
 		}
1719
 		}
1741
 
1720
 
1819
 		}
1798
 		}
1820
 
1799
 
1821
 		executionStaff := adminUserInfo.AdminUser.Id
1800
 		executionStaff := adminUserInfo.AdminUser.Id
1822
-		// checker := adminUserInfo.AdminUser.Id
1823
 
1801
 
1824
 		timeLayout := "2006-01-02 15:04:05"
1802
 		timeLayout := "2006-01-02 15:04:05"
1825
 		loc, _ := time.LoadLocation("Local")
1803
 		loc, _ := time.LoadLocation("Local")
1879
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1857
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1880
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1858
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1881
 					//转化为最小单位
1859
 					//转化为最小单位
1882
-					total = list.Count * medical.MinNumber
1860
+					total = list.Count*medical.MinNumber + list.StockMinNumber
1883
 					prescribing_number_total = count * medical.MinNumber
1861
 					prescribing_number_total = count * medical.MinNumber
1884
 				}
1862
 				}
1885
 				fmt.Println("单位1", medical.MinUnit)
1863
 				fmt.Println("单位1", medical.MinUnit)
1889
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1867
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1890
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1868
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1891
 					total = list.Count*medical.MinNumber + list.StockMinNumber
1869
 					total = list.Count*medical.MinNumber + list.StockMinNumber
1892
-					fmt.Println("23232322323322323233223", total)
1870
+
1893
 					prescribing_number_total = count
1871
 					prescribing_number_total = count
1894
-					fmt.Println("7777777777777777", prescribing_number_total)
1872
+
1895
 				}
1873
 				}
1896
 
1874
 
1897
 				fmt.Println("数量一", prescribing_number_total)
1875
 				fmt.Println("数量一", prescribing_number_total)
1921
 					return
1899
 					return
1922
 				}
1900
 				}
1923
 			}
1901
 			}
1924
-			//	//查询该药品是否有库存
1925
-			//	list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1926
-			//	prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1927
-			//	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1928
-			//	if list.Count == 0 {
1929
-			//		c.ServeSuccessJSON(map[string]interface{}{
1930
-			//			"msg":    "1",
1931
-			//			"advice": advice,
1932
-			//		})
1933
-			//		return
1934
-			//	}
1935
-			//	if count > list.Count {
1936
-			//		c.ServeSuccessJSON(map[string]interface{}{
1937
-			//			"msg":    "2",
1938
-			//			"advice": advice,
1939
-			//		})
1940
-			//		return
1941
-			//	}
1942
-			//	service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1943
-			//}
1902
+
1944
 		}
1903
 		}
1945
 		c.ServeSuccessJSON(map[string]interface{}{
1904
 		c.ServeSuccessJSON(map[string]interface{}{
1946
 			"msg":    "1",
1905
 			"msg":    "1",

+ 7 - 4
controllers/self_drug_api_congtroller.go ファイルの表示

2404
 	fmt.Println(err)
2404
 	fmt.Println(err)
2405
 
2405
 
2406
 	tableData, _ := dataBody["tableData"].([]interface{})
2406
 	tableData, _ := dataBody["tableData"].([]interface{})
2407
-	fmt.Println("999939433443", tableData)
2407
+
2408
 	if len(tableData) > 0 {
2408
 	if len(tableData) > 0 {
2409
 		for _, item := range tableData {
2409
 		for _, item := range tableData {
2410
 			items := item.(map[string]interface{})
2410
 			items := item.(map[string]interface{})
2489
 				consumable_type = 10
2489
 				consumable_type = 10
2490
 				consumable_count = new_total - ord_total
2490
 				consumable_count = new_total - ord_total
2491
 			}
2491
 			}
2492
+			fmt.Println("ord_total", ord_total)
2493
+			fmt.Println("new_total23323232323223", new_total)
2494
+			fmt.Println("consumable_count", consumable_count)
2492
 
2495
 
2493
 			//改变库存
2496
 			//改变库存
2494
 			info := models.DrugWarehouseInfo{
2497
 			info := models.DrugWarehouseInfo{
2574
 				MaxUnit:                 max_unit,
2577
 				MaxUnit:                 max_unit,
2575
 				MinUnit:                 min_unit,
2578
 				MinUnit:                 min_unit,
2576
 			}
2579
 			}
2577
-
2578
-			service.CreateDrugFlowOne(flow)
2579
-
2580
+			if ord_total != new_total {
2581
+				service.CreateDrugFlowOne(flow)
2582
+			}
2580
 			if err != nil {
2583
 			if err != nil {
2581
 				this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
2584
 				this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
2582
 				return
2585
 				return

+ 388 - 74
controllers/stock_in_api_controller.go ファイルの表示

129
 	beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
129
 	beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
130
 	beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
130
 	beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
131
 	beego.Router("/api/stock/getgoodinventorywarehouselist", &StockManagerApiController{}, "Get:GetGoodInventoryWarehouseList")
131
 	beego.Router("/api/stock/getgoodinventorywarehouselist", &StockManagerApiController{}, "Get:GetGoodInventoryWarehouseList")
132
-
132
+	beego.Router("/api/stock/savestockinentorylist", &StockManagerApiController{}, "Post:SaveStockInventoryList")
133
+	beego.Router("/api/sotck/getdamagedetailbygoodid", &StockManagerApiController{}, "Get:GetDamageDetailByGoodId")
133
 }
134
 }
134
 
135
 
135
 func (c *StockManagerApiController) CreateWarehouse() {
136
 func (c *StockManagerApiController) CreateWarehouse() {
574
 					}
575
 					}
575
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
576
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
576
 
577
 
577
-					flow := &models.VmStockFlow{
578
-						WarehousingOrder:    warehousing.WarehousingOrder,
579
-						WarehousingId:       warehousing.ID,
580
-						GoodId:              good_id,
581
-						Number:              number,
582
-						ProductDate:         productDates,
583
-						ExpireDate:          expiryDates,
584
-						Count:               warehousing_count,
585
-						Price:               price,
586
-						Status:              1,
587
-						Ctime:               ctime,
588
-						UserOrgId:           adminUserInfo.CurrentOrgId,
589
-						Manufacturer:        manufacturer,
590
-						Dealer:              dealer,
591
-						LicenseNumber:       license_number,
592
-						IsEdit:              1,
593
-						Creator:             adminUserInfo.AdminUser.Id,
594
-						SystemTime:          ctime,
595
-						ConsumableType:      1,
596
-						WarehousingDetailId: warehouseInfo.ID,
597
-					}
598
-
599
-					stockFlow = append(stockFlow, flow)
600
-
601
 				} else {
578
 				} else {
602
-					fmt.Println("id23233232323232323232323223", id)
579
+
603
 					warehouseInfo := &models.WarehousingInfo{
580
 					warehouseInfo := &models.WarehousingInfo{
604
 						ID:               id,
581
 						ID:               id,
605
 						WarehousingOrder: warehouse.WarehousingOrder,
582
 						WarehousingOrder: warehouse.WarehousingOrder,
653
 	var errs error
630
 	var errs error
654
 	if len(warehousingInfo) > 0 {
631
 	if len(warehousingInfo) > 0 {
655
 		errs = service.CreateWarehousingInfo(warehousingInfo)
632
 		errs = service.CreateWarehousingInfo(warehousingInfo)
656
-		service.CreateStockFlow(stockFlow)
633
+
634
+		for _, its := range warehousingInfo {
635
+			//查询
636
+			info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
637
+			fmt.Println("hh23323232323233232323322323", info)
638
+			flows := models.VmStockFlow{
639
+				WarehousingOrder:    info.WarehousingOrder,
640
+				WarehousingId:       info.ID,
641
+				GoodId:              info.GoodId,
642
+				Number:              info.Number,
643
+				ProductDate:         info.ProductDate,
644
+				ExpireDate:          info.ExpiryDate,
645
+				Count:               info.WarehousingCount,
646
+				Price:               info.Price,
647
+				Status:              1,
648
+				Ctime:               ctime,
649
+				UserOrgId:           adminUserInfo.CurrentOrgId,
650
+				Manufacturer:        info.Manufacturer,
651
+				Dealer:              info.Dealer,
652
+				LicenseNumber:       info.LicenseNumber,
653
+				IsEdit:              1,
654
+				Creator:             adminUserInfo.AdminUser.Id,
655
+				SystemTime:          ctime,
656
+				ConsumableType:      1,
657
+				WarehousingDetailId: info.ID,
658
+			}
659
+			_, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
660
+			fmt.Println("wodeshijehh23322333223233223323232", errcodescode)
661
+			if errcodescode == gorm.ErrRecordNotFound {
662
+				service.CreateStockFlowOne(flows)
663
+			}
664
+
665
+			//改变库存
666
+			good, _ := service.GetLastInfoMationById(info.GoodId)
667
+			warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
668
+			total, _ := strconv.ParseFloat(warhouseCount, 64)
669
+			goodInfo := models.GoodInfo{
670
+				Total: good.Total + total,
671
+			}
672
+			errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
673
+			fmt.Println(errcodescode)
674
+		}
657
 	}
675
 	}
658
 
676
 
659
 	if len(upDateWarehousingInfo) > 0 {
677
 	if len(upDateWarehousingInfo) > 0 {
660
 
678
 
661
 		for _, item := range upDateWarehousingInfo {
679
 		for _, item := range upDateWarehousingInfo {
662
-
663
 			var total int64
680
 			var total int64
664
-			var all_total int64
665
 			//获取该批次该型号的库存
681
 			//获取该批次该型号的库存
666
 			info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
682
 			info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
667
-			fmt.Println("oooooooooo", info.WarehousingCount)
668
-			//判断 该批次的入库数量
669
-			total = item.WarehousingCount - info.WarehousingCount
670
-			fmt.Println("total232323322332232332", total)
671
-			all_total = info.StockCount + total
672
 
683
 
673
-			item.StockCount = all_total
674
-			fmt.Println("hhhhhhhhhhhhh", item.StockCount)
684
+			//判断 该批次的库存数量 和 编辑库存数量
685
+			fmt.Println("库存11111111111111", item.WarehousingCount)
686
+			fmt.Println("库存22222222222222", info.WarehousingCount)
687
+			//增加库存
688
+			if item.WarehousingCount > info.WarehousingCount {
689
+
690
+				total = item.WarehousingCount - info.WarehousingCount
691
+				goodinfo := models.WarehousingInfo{
692
+					WarehousingCount: item.WarehousingCount,
693
+					StockCount:       info.StockCount + total,
694
+				}
675
 
695
 
676
-			errs = service.UpDateWarehousingInfo(item)
696
+				service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
697
+				//改变库存
698
+				good, _ := service.GetLastInfoMationById(info.GoodId)
699
+				warhouseCount := strconv.FormatInt(total, 10)
700
+				all_total, _ := strconv.ParseFloat(warhouseCount, 64)
701
+				goodInfo := models.GoodInfo{
702
+					Total: good.Total + all_total,
703
+				}
704
+				service.UpdateGoodInfoMation(info.GoodId, goodInfo)
705
+
706
+			}
707
+
708
+			if item.WarehousingCount < info.WarehousingCount {
709
+
710
+				total = info.WarehousingCount - item.WarehousingCount
711
+				goodinfo := models.WarehousingInfo{
712
+					WarehousingCount: item.WarehousingCount,
713
+					StockCount:       info.StockCount - total,
714
+				}
715
+				service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
716
+				//改变库存
717
+				good, _ := service.GetLastInfoMationById(info.GoodId)
718
+				warhouseCount := strconv.FormatInt(total, 10)
719
+				all_total, _ := strconv.ParseFloat(warhouseCount, 64)
720
+				goodInfo := models.GoodInfo{
721
+					Total: good.Total - all_total,
722
+				}
723
+				service.UpdateGoodInfoMation(info.GoodId, goodInfo)
724
+			}
677
 		}
725
 		}
678
 	}
726
 	}
679
 
727
 
1242
 
1290
 
1243
 	//出库逻辑
1291
 	//出库逻辑
1244
 	for _, item := range warehousingOutInfo {
1292
 	for _, item := range warehousingOutInfo {
1245
-		//查询库存
1246
-		//warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1247
-		//查询该批次的库存
1248
 
1293
 
1249
-		warehouseOne, _ := service.FindWarehousingInfoByIdSeven(item.WarehouseInfotId)
1250
-		fmt.Println("数据232323232323232323323232", warehouseOne)
1251
-		fmt.Println("库存查询23322332233232233232322323232323", warehouseOne.StockCount)
1294
+		// 查询该耗材是否有库存
1295
+		warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
1296
+		// 如果出库数量大于该批次剩余库存数量
1252
 		if item.Count > warehouseOne.StockCount {
1297
 		if item.Count > warehouseOne.StockCount {
1253
 			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1298
 			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1254
 			c.ServeSuccessJSON(map[string]interface{}{
1299
 			c.ServeSuccessJSON(map[string]interface{}{
1259
 			return
1304
 			return
1260
 
1305
 
1261
 		} else {
1306
 		} else {
1262
-
1307
+			//查询是否生成出库单
1263
 			_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1308
 			_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1264
 			if errcodes == gorm.ErrRecordNotFound {
1309
 			if errcodes == gorm.ErrRecordNotFound {
1265
 				service.AddSigleWarehouseOut(&warehouseOut)
1310
 				service.AddSigleWarehouseOut(&warehouseOut)
1266
 			}
1311
 			}
1312
+			//出库逻辑
1267
 			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
1313
 			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
1268
 			if parseDateErr != nil {
1314
 			if parseDateErr != nil {
1269
 				utils.ErrorLog(parseDateErr.Error())
1315
 				utils.ErrorLog(parseDateErr.Error())
1279
 		}
1325
 		}
1280
 
1326
 
1281
 	}
1327
 	}
1282
-
1283
-	//errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1284
-	//info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1285
-
1286
 }
1328
 }
1287
 func (c *StockManagerApiController) GetWarehouseOutList() {
1329
 func (c *StockManagerApiController) GetWarehouseOutList() {
1288
 	page, _ := c.GetInt64("page", -1)
1330
 	page, _ := c.GetInt64("page", -1)
1396
 }
1438
 }
1397
 func (c *StockManagerApiController) EditWarehouseOut() {
1439
 func (c *StockManagerApiController) EditWarehouseOut() {
1398
 	warehouse_out_time := c.GetString("warehouse_out_time")
1440
 	warehouse_out_time := c.GetString("warehouse_out_time")
1399
-
1400
 	id, _ := c.GetInt64("id", 0)
1441
 	id, _ := c.GetInt64("id", 0)
1401
 	types, _ := c.GetInt64("type", 0)
1442
 	types, _ := c.GetInt64("type", 0)
1402
 
1443
 
1592
 		}
1633
 		}
1593
 	}
1634
 	}
1594
 	var errs error
1635
 	var errs error
1636
+	//新增出库
1595
 	if len(warehousingOutInfo) > 0 {
1637
 	if len(warehousingOutInfo) > 0 {
1596
 
1638
 
1597
-		errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
1639
+		warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
1640
+		if parseDateErr != nil {
1641
+			c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
1642
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1643
+			return
1644
+		}
1645
+		creater := adminUserInfo.AdminUser.Id
1646
+
1647
+		for _, item := range warehousingOutInfo {
1648
+			// 查询该耗材是否有库存
1649
+			warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
1650
+			// 如果出库数量大于该批次剩余库存数量
1651
+			if item.Count > warehouseOne.StockCount {
1652
+				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1653
+				c.ServeSuccessJSON(map[string]interface{}{
1654
+					"msg":                "7",
1655
+					"good_name":          goodObj.GoodName,
1656
+					"specification_name": goodObj.SpecificationName,
1657
+				})
1658
+				return
1659
+
1660
+			} else {
1661
+
1662
+				warehouseOut, _ := service.GetWarehouseById(id)
1663
+
1664
+				//出库逻辑
1665
+				parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
1666
+				if parseDateErr != nil {
1667
+					utils.ErrorLog(parseDateErr.Error())
1668
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1669
+					return
1670
+				}
1671
+			}
1672
+		}
1598
 	}
1673
 	}
1599
 
1674
 
1600
 	if len(upDateWarehouseOutInfos) > 0 {
1675
 	if len(upDateWarehouseOutInfos) > 0 {
1601
 		for _, item := range upDateWarehouseOutInfos {
1676
 		for _, item := range upDateWarehouseOutInfos {
1602
 
1677
 
1603
 			//1.查询该耗材该批次的最后一次出库记录
1678
 			//1.查询该耗材该批次的最后一次出库记录
1604
-			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
1605
-			fmt.Println("lastGood", lastGood.Count)
1606
-			fmt.Println("item2323232", item.Count)
1679
+			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId)
1607
 
1680
 
1608
 			// 退库的库存和该耗材该批次最后一次出库数量进行比较
1681
 			// 退库的库存和该耗材该批次最后一次出库数量进行比较
1609
 			//如果退库数量大于 最后一次批次的数量(要么要进行出库)
1682
 			//如果退库数量大于 最后一次批次的数量(要么要进行出库)
1612
 
1685
 
1613
 				//查询该耗材是否还有库存
1686
 				//查询该耗材是否还有库存
1614
 				warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
1687
 				warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
1615
-				fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
1688
+
1616
 				//无库存
1689
 				//无库存
1617
 				if warehouseinfo.StockCount <= 0 {
1690
 				if warehouseinfo.StockCount <= 0 {
1618
 					c.ServeSuccessJSON(map[string]interface{}{
1691
 					c.ServeSuccessJSON(map[string]interface{}{
1628
 					var total_count int64
1701
 					var total_count int64
1629
 					//计算和最后一次出库数据的差
1702
 					//计算和最后一次出库数据的差
1630
 					total = item.Count - lastGood.Count
1703
 					total = item.Count - lastGood.Count
1631
-					fmt.Println("total22323232", total)
1704
+
1632
 					//获取该耗材该批次的剩余库存量
1705
 					//获取该耗材该批次的剩余库存量
1633
 					info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1706
 					info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1634
-					fmt.Println("info2232323232323", info)
1707
+
1635
 					//判断该批次的剩余库存 和出库的库存进行比较
1708
 					//判断该批次的剩余库存 和出库的库存进行比较
1636
 					//如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
1709
 					//如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
1637
 
1710
 
1641
 						//清空本批次次库存
1714
 						//清空本批次次库存
1642
 						service.DeleteWarehouseInfo(item.WarehouseInfotId)
1715
 						service.DeleteWarehouseInfo(item.WarehouseInfotId)
1643
 						//调用出库逻辑
1716
 						//调用出库逻辑
1644
-						service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
1717
+						parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
1718
+						if parseDateErr != nil {
1719
+							utils.ErrorLog(errs.Error())
1720
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1721
+							return
1722
+						}
1723
+						c.ServeSuccessJSON(map[string]interface{}{
1724
+							"msg": "1",
1725
+						})
1645
 					}
1726
 					}
1646
 					//如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
1727
 					//如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
1647
 					if item.Count <= info.StockCount {
1728
 					if item.Count <= info.StockCount {
1648
 						stock_cout = lastGood.Count + total
1729
 						stock_cout = lastGood.Count + total
1649
-						fmt.Println("232323223232323232323232", stock_cout)
1730
+						fmt.Println(stock_cout)
1650
 						//扣减库存
1731
 						//扣减库存
1651
 						warehouse := models.WarehousingInfo{
1732
 						warehouse := models.WarehousingInfo{
1652
 							StockCount: info.StockCount - total,
1733
 							StockCount: info.StockCount - total,
1689
 							c.ServeSuccessJSON(map[string]interface{}{
1770
 							c.ServeSuccessJSON(map[string]interface{}{
1690
 								"msg": "1",
1771
 								"msg": "1",
1691
 							})
1772
 							})
1773
+							return
1692
 						} else if errcode == nil {
1774
 						} else if errcode == nil {
1693
 							service.UpDateWarehouseOutInfo(item)
1775
 							service.UpDateWarehouseOutInfo(item)
1776
+							c.ServeSuccessJSON(map[string]interface{}{
1777
+								"msg": "1",
1778
+							})
1779
+							return
1694
 						}
1780
 						}
1695
 
1781
 
1696
 					}
1782
 					}
1702
 			var stock_total int64
1788
 			var stock_total int64
1703
 			//如果退库数量小于最后一次批次的数量(要么要进行退库)
1789
 			//如果退库数量小于最后一次批次的数量(要么要进行退库)
1704
 			if item.Count < lastGood.Count {
1790
 			if item.Count < lastGood.Count {
1705
-				fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
1791
+
1706
 				//退库数量和最后一次出库数据进行计算
1792
 				//退库数量和最后一次出库数据进行计算
1707
 				last_count = lastGood.Count - item.Count
1793
 				last_count = lastGood.Count - item.Count
1708
-				fmt.Println("last_count", last_count)
1794
+
1709
 				//获取该耗材该批次的剩余库存量
1795
 				//获取该耗材该批次的剩余库存量
1710
 				infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1796
 				infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1711
 
1797
 
1712
 				//退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
1798
 				//退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
1713
 				all_total = last_count + infoInfo.StockCount
1799
 				all_total = last_count + infoInfo.StockCount
1714
-				fmt.Println("all_total", all_total)
1800
+
1715
 				//如果库存大于总数量,则退回到这个批次
1801
 				//如果库存大于总数量,则退回到这个批次
1716
-				fmt.Println("inf232323", infoInfo.WarehousingCount)
1717
 
1802
 
1718
 				if infoInfo.WarehousingCount > all_total {
1803
 				if infoInfo.WarehousingCount > all_total {
1719
 					stock_total = last_count + infoInfo.StockCount
1804
 					stock_total = last_count + infoInfo.StockCount
1720
-					fmt.Println("经历323232323232232", last_count, stock_total)
1805
+
1721
 					//退回该批次,计算数量
1806
 					//退回该批次,计算数量
1722
 					warehousingInfoOne := models.WarehousingInfo{
1807
 					warehousingInfoOne := models.WarehousingInfo{
1723
 						StockCount: stock_total,
1808
 						StockCount: stock_total,
1724
 						ID:         item.WarehouseInfotId,
1809
 						ID:         item.WarehouseInfotId,
1725
 						OrgId:      item.OrgId,
1810
 						OrgId:      item.OrgId,
1726
 					}
1811
 					}
1727
-					fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
1812
+
1728
 					parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
1813
 					parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
1729
-					fmt.Println("parseDateErr2323232322323", parseDateErr)
1814
+					fmt.Println("parseDateErr", parseDateErr)
1730
 					//插入一条新纪录
1815
 					//插入一条新纪录
1731
 					warehouseOutInfoThree := &models.WarehouseOutInfo{
1816
 					warehouseOutInfoThree := &models.WarehouseOutInfo{
1732
 						WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
1817
 						WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
1762
 						c.ServeSuccessJSON(map[string]interface{}{
1847
 						c.ServeSuccessJSON(map[string]interface{}{
1763
 							"msg": "1",
1848
 							"msg": "1",
1764
 						})
1849
 						})
1850
+						return
1765
 					} else if errcode == nil {
1851
 					} else if errcode == nil {
1766
 						service.UpDateWarehouseOutInfo(item)
1852
 						service.UpDateWarehouseOutInfo(item)
1853
+						return
1767
 					}
1854
 					}
1768
 				}
1855
 				}
1769
 
1856
 
1777
 			}
1864
 			}
1778
 
1865
 
1779
 			if item.Count == lastGood.Count {
1866
 			if item.Count == lastGood.Count {
1867
+
1780
 				errs = service.UpDateWarehouseOutInfo(item)
1868
 				errs = service.UpDateWarehouseOutInfo(item)
1781
 				if errs != nil {
1869
 				if errs != nil {
1782
 					utils.ErrorLog(errs.Error())
1870
 					utils.ErrorLog(errs.Error())
1786
 				c.ServeSuccessJSON(map[string]interface{}{
1874
 				c.ServeSuccessJSON(map[string]interface{}{
1787
 					"msg": "1",
1875
 					"msg": "1",
1788
 				})
1876
 				})
1877
+				return
1789
 			}
1878
 			}
1790
 
1879
 
1791
 		}
1880
 		}
4357
 	orgId := adminUserInfo.CurrentOrgId
4446
 	orgId := adminUserInfo.CurrentOrgId
4358
 
4447
 
4359
 	list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
4448
 	list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
4360
-	fmt.Println("耗材总计23323232232323232323", total)
4361
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4449
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4362
 	this.ServeSuccessJSON(map[string]interface{}{
4450
 	this.ServeSuccessJSON(map[string]interface{}{
4363
 		"list":             list,
4451
 		"list":             list,
4492
 	ids := this.GetString("id")
4580
 	ids := this.GetString("id")
4493
 	idsArray := strings.Split(ids, ",")
4581
 	idsArray := strings.Split(ids, ",")
4494
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4582
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4495
-	order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
4496
 	list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
4583
 	list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
4497
-	//获取该耗材的最后一条数据
4498
-	info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
4499
-	fmt.Println("info323e2342342342432342342432", info)
4500
 	this.ServeSuccessJSON(map[string]interface{}{
4584
 	this.ServeSuccessJSON(map[string]interface{}{
4501
-		"order": order,
4502
-		"list":  list,
4503
-		"info":  info,
4585
+		"list": list,
4504
 	})
4586
 	})
4505
 }
4587
 }
4506
 
4588
 
5237
 	orgId := this.GetAdminUserInfo().CurrentOrgId
5319
 	orgId := this.GetAdminUserInfo().CurrentOrgId
5238
 	keyword := this.GetString("keyword")
5320
 	keyword := this.GetString("keyword")
5239
 	fmt.Println("startTime", startTime, "endTime", endTime)
5321
 	fmt.Println("startTime", startTime, "endTime", endTime)
5240
-	list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
5322
+	//list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
5323
+
5324
+	list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit)
5325
+	damageList, _ := service.GetStockDamagedCount(orgId)
5241
 	doctorlist, _ := service.GetAllDoctorThree(orgId)
5326
 	doctorlist, _ := service.GetAllDoctorThree(orgId)
5242
 
5327
 
5243
 	this.ServeSuccessJSON(map[string]interface{}{
5328
 	this.ServeSuccessJSON(map[string]interface{}{
5244
 		"list":       list,
5329
 		"list":       list,
5245
 		"total":      total,
5330
 		"total":      total,
5246
 		"doctorlist": doctorlist,
5331
 		"doctorlist": doctorlist,
5332
+		"damageList": damageList,
5247
 	})
5333
 	})
5248
 }
5334
 }
5249
 
5335
 
6158
 		"list": list,
6244
 		"list": list,
6159
 	})
6245
 	})
6160
 }
6246
 }
6247
+
6248
+func (this *StockManagerApiController) SaveStockInventoryList() {
6249
+
6250
+	dataBody := make(map[string]interface{}, 0)
6251
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
6252
+	fmt.Println(err)
6253
+
6254
+	tableData, _ := dataBody["tableData"].([]interface{})
6255
+
6256
+	if len(tableData) > 0 {
6257
+		for _, item := range tableData {
6258
+			items := item.(map[string]interface{})
6259
+			good_name := items["good_name"].(string)
6260
+			if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
6261
+				utils.ErrorLog("good_name")
6262
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6263
+				return
6264
+			}
6265
+
6266
+			specification_name := items["specification_name"].(string)
6267
+			if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
6268
+				utils.ErrorLog("specification_name")
6269
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6270
+				return
6271
+			}
6272
+
6273
+			warehousing_unit := items["warehousing_unit"].(string)
6274
+			if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
6275
+				utils.ErrorLog("warehousing_unit")
6276
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6277
+				return
6278
+			}
6279
+
6280
+			stock_count := int64(items["stock_count"].(float64))
6281
+			if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
6282
+				utils.ErrorLog("stock_count")
6283
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6284
+				return
6285
+			}
6286
+
6287
+			price := items["price"].(float64)
6288
+			if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
6289
+				utils.ErrorLog("price")
6290
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6291
+				return
6292
+			}
6293
+
6294
+			manufacturer_name := items["manufacturer_name"].(string)
6295
+			if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
6296
+				utils.ErrorLog("manufacturer_name")
6297
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6298
+				return
6299
+			}
6300
+
6301
+			good_id := int64(items["good_id"].(float64))
6302
+			if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
6303
+				utils.ErrorLog("good_id")
6304
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6305
+				return
6306
+			}
6307
+
6308
+			manufacturer := int64(items["manufacturer"].(float64))
6309
+			if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
6310
+				utils.ErrorLog("manufacturer")
6311
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6312
+				return
6313
+			}
6314
+
6315
+			warehousing_order := items["warehousing_order"].(string)
6316
+			if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
6317
+				utils.ErrorLog("warehousing_order")
6318
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6319
+				return
6320
+			}
6321
+
6322
+			number := items["number"].(string)
6323
+			if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
6324
+				utils.ErrorLog("number")
6325
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6326
+				return
6327
+			}
6328
+
6329
+			id := int64(items["id"].(float64))
6330
+			if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
6331
+				utils.ErrorLog("id")
6332
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6333
+				return
6334
+			}
6335
+
6336
+			if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
6337
+				utils.ErrorLog("expiry_date")
6338
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6339
+				return
6340
+			}
6341
+			expiry_date := int64(items["expiry_date"].(float64))
6342
+
6343
+			if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
6344
+				utils.ErrorLog("product_date")
6345
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6346
+				return
6347
+			}
6348
+			product_date := int64(items["product_date"].(float64))
6349
+
6350
+			orgId := this.GetAdminUserInfo().CurrentOrgId
6351
+			adminId := this.GetAdminUserInfo().AdminUser.Id
6352
+
6353
+			stock_type := int64(items["type"].(float64))
6354
+			if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
6355
+				utils.ErrorLog("type")
6356
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6357
+				return
6358
+			}
6359
+
6360
+			last_stock_count := int64(items["last_stock_count"].(float64))
6361
+			if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
6362
+				utils.ErrorLog("last_stock_count")
6363
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6364
+				return
6365
+			}
6366
+			var total_count int64
6367
+			var inventory_type int64
6368
+			fmt.Println("盘点前", stock_count)
6369
+			fmt.Println("盘点后", last_stock_count)
6370
+			if stock_count > last_stock_count {
6371
+				total_count = stock_count - last_stock_count
6372
+				inventory_type = 11
6373
+			}
6374
+			if stock_count < last_stock_count {
6375
+				total_count = last_stock_count - stock_count
6376
+				inventory_type = 10
6377
+			}
6378
+
6379
+			creater := this.GetAdminUserInfo().AdminUser.Id
6380
+			inventory := models.XtStockInventory{
6381
+				GoodName:          good_name,
6382
+				SpecificationName: specification_name,
6383
+				WarehousingUnit:   warehousing_unit,
6384
+				Count:             total_count,
6385
+				BuyPrice:          price,
6386
+				PackingPrice:      price,
6387
+				NewPrice:          0,
6388
+				Manufacturer:      manufacturer_name,
6389
+				Dealer:            "",
6390
+				Remark:            "",
6391
+				GoodId:            good_id,
6392
+				UserOrgId:         orgId,
6393
+				Ctime:             time.Now().Unix(),
6394
+				Mtime:             0,
6395
+				Status:            1,
6396
+				WarehousingOrder:  warehousing_order,
6397
+				LicenseNumber:     number,
6398
+				StartTime:         time.Now().Unix(),
6399
+				Creater:           adminId,
6400
+				Checker:           0,
6401
+				CheckerStatus:     0,
6402
+				CheckerTime:       0,
6403
+				Total:             0,
6404
+				Number:            number,
6405
+				WarehousingInfoId: id,
6406
+				ExpireDate:        expiry_date,
6407
+				ProductDate:       product_date,
6408
+				GoodOriginPlace:   "",
6409
+				Type:              10,
6410
+				InventoryType:     stock_type,
6411
+				LastStockCount:    last_stock_count,
6412
+				StockCount:        stock_count,
6413
+			}
6414
+			service.CreateInentory(inventory)
6415
+
6416
+			stockFlow := models.VmStockFlow{
6417
+				WarehousingId:           0,
6418
+				GoodId:                  good_id,
6419
+				Number:                  number,
6420
+				LicenseNumber:           "",
6421
+				Count:                   total_count,
6422
+				UserOrgId:               orgId,
6423
+				PatientId:               0,
6424
+				SystemTime:              0,
6425
+				ConsumableType:          inventory_type,
6426
+				IsSys:                   0,
6427
+				WarehousingOrder:        "",
6428
+				WarehouseOutId:          0,
6429
+				WarehouseOutOrderNumber: warehousing_order,
6430
+				IsEdit:                  0,
6431
+				CancelStockId:           0,
6432
+				CancelOrderNumber:       "",
6433
+				Manufacturer:            manufacturer,
6434
+				Dealer:                  0,
6435
+				Creator:                 creater,
6436
+				UpdateCreator:           0,
6437
+				Status:                  1,
6438
+				Ctime:                   time.Now().Unix(),
6439
+				Mtime:                   0,
6440
+				Price:                   price,
6441
+				WarehousingDetailId:     0,
6442
+				WarehouseOutDetailId:    0,
6443
+				CancelOutDetailId:       0,
6444
+				ProductDate:             product_date,
6445
+				ExpireDate:              expiry_date,
6446
+				ReturnCount:             0,
6447
+			}
6448
+
6449
+			info := models.WarehousingInfo{
6450
+				StockCount: last_stock_count,
6451
+			}
6452
+			//更改库存
6453
+			service.UpdatedWarehousingInfo(info, id)
6454
+			if stock_count != last_stock_count {
6455
+				service.CreateStockFlowOne(stockFlow)
6456
+			}
6457
+			this.ServeSuccessJSON(map[string]interface{}{
6458
+				"inventory": inventory,
6459
+			})
6460
+		}
6461
+	}
6462
+}
6463
+
6464
+func (this *StockManagerApiController) GetDamageDetailByGoodId() {
6465
+
6466
+	good_id, _ := this.GetInt64("good_id")
6467
+	list, _ := service.GetDamageDetailByGoodId(good_id)
6468
+	orgId := this.GetAdminUserInfo().CurrentOrgId
6469
+	damageList, _ := service.GetStockDamagedCount(orgId)
6470
+	this.ServeSuccessJSON(map[string]interface{}{
6471
+		"list":       list,
6472
+		"damageList": damageList,
6473
+	})
6474
+}

+ 1 - 0
models/drug_stock.go ファイルの表示

283
 	CountUnit      string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
283
 	CountUnit      string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
284
 	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
284
 	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
285
 	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
285
 	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
286
+	MinNumber      int64  `gorm:"column:min_number" json:"min_number" form:"min_number"`
286
 }
287
 }
287
 
288
 
288
 type StDrugWarehouseOutInfo struct {
289
 type StDrugWarehouseOutInfo struct {

+ 1 - 0
models/good_models.go ファイルの表示

79
 	Total                       float64              `gorm:"column:total" json:"total" form:"total"`
79
 	Total                       float64              `gorm:"column:total" json:"total" form:"total"`
80
 	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:GoodId;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
 	CancelStockInfo             []*CancelStockInfo   `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"cancel_stock_info"`
82
+	GoodSotckInfo               []*GoodSotckInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_stock_in"`
82
 }
83
 }
83
 
84
 
84
 func (GoodInfo) TableName() string {
85
 func (GoodInfo) TableName() string {

+ 30 - 0
models/schedule_models.go ファイルの表示

203
 func (VmSchedulesRemind) TableName() string {
203
 func (VmSchedulesRemind) TableName() string {
204
 	return "xt_schedule"
204
 	return "xt_schedule"
205
 }
205
 }
206
+
207
+type WeekScheduleSix struct {
208
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
209
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
210
+	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
211
+	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
212
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
213
+	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
214
+	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
215
+	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
216
+	ModeId       int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
217
+	Status       int64 `gorm:"column:status" json:"status" form:"status"`
218
+	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
219
+	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
220
+	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
221
+
222
+	Patient                    string                     `gorm:"-" json:"patient" form:"patient"`
223
+	DeviceZone                 DeviceZone                 `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
224
+	DeviceNumber               DeviceNumber               `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
225
+	DialysisPrescription       DialysisSolution           `json:"prescription" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId"`
226
+	DoctorAdvice               []*DoctorAdvice            `json:"doctoradvice" gorm:"foreignkey:AdviceDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
227
+	HisDoctorAdviceInfo        []*HisDoctorAdviceInfo     `json:"hisdoctoradviceinfo" gorm:"foreignkey:AdviceDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
228
+	Solution                   []*DialysisSolution        `json:"solution" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId"`
229
+	DialysisSolution           DialysisSolution           `json:"dialysissolution" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId"`
230
+	XtAssessmentBeforeDislysis XtAssessmentBeforeDislysis `json:"assessmentbefor" gorm:"foreignkey:PatientId,AssessmentDate;AssociationForeignKey:PatientId,ScheduleDate"`
231
+}
232
+
233
+func (WeekScheduleSix) TableName() string {
234
+	return "xt_schedule"
235
+}

+ 1 - 0
models/self_drug_models.go ファイルの表示

670
 	MinPrice                float64 `json:"min_price"`
670
 	MinPrice                float64 `json:"min_price"`
671
 	DrugName                string  `json:"drug_name"`
671
 	DrugName                string  `json:"drug_name"`
672
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
672
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
673
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
673
 }
674
 }
674
 
675
 
675
 type XtDrugAdjustPrice struct {
676
 type XtDrugAdjustPrice struct {

+ 19 - 0
models/stock_models.go ファイルの表示

986
 	ExpireDate        int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
986
 	ExpireDate        int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
987
 	ProductDate       int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
987
 	ProductDate       int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
988
 	GoodOriginPlace   string  `gorm:"column:good_origin_place" json:"good_origin_place" form:"good_origin_place"`
988
 	GoodOriginPlace   string  `gorm:"column:good_origin_place" json:"good_origin_place" form:"good_origin_place"`
989
+	Type              int64   `gorm:"column:type" json:"type" form:"type"`
990
+	InventoryType     int64   `gorm:"column:inventory_type" json:"inventory_type" form:"inventory_type"`
991
+	LastStockCount    int64   `gorm:"column:last_stock_count" json:"last_stock_count" form:"last_stock_count"`
992
+	StockCount        int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
989
 }
993
 }
990
 
994
 
991
 func (XtStockInventory) TableName() string {
995
 func (XtStockInventory) TableName() string {
1022
 	Number            string  `gorm:"column:number" json:"number" form:"number"`
1026
 	Number            string  `gorm:"column:number" json:"number" form:"number"`
1023
 	ExpireDate        int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
1027
 	ExpireDate        int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
1024
 	ProductDate       int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
1028
 	ProductDate       int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
1029
+	Type              int64   `gorm:"column:type" json:"type" form:"type"`
1030
+	InventoryType     int64   `gorm:"column:inventory_type" json:"inventory_type" form:"inventory_type"`
1031
+	LastStockCount    int64   `gorm:"column:last_stock_count" json:"last_stock_count" form:"last_stock_count"`
1032
+	StockCount        int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
1025
 }
1033
 }
1026
 
1034
 
1027
 type XtStockCorrectRecord struct {
1035
 type XtStockCorrectRecord struct {
1104
 	RetailPrice       float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
1112
 	RetailPrice       float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
1105
 	PackingPrice      float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
1113
 	PackingPrice      float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
1106
 }
1114
 }
1115
+
1116
+type GoodSotckInfo struct {
1117
+	GoodId            int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
1118
+	StockCount        int64  `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
1119
+	GoodName          string `gorm:"column:good_name" json:"good_name"`
1120
+	SpecificationName string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
1121
+}
1122
+
1123
+func (GoodSotckInfo) TableName() string {
1124
+	return "xt_warehouse_info"
1125
+}

+ 1 - 1
service/dialysis_service.go ファイルの表示

1179
 
1179
 
1180
 func GetGoodInfoMation(orgid int64) (goodinfo []*models.GoodInfo, err error) {
1180
 func GetGoodInfoMation(orgid int64) (goodinfo []*models.GoodInfo, err error) {
1181
 
1181
 
1182
-	err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND  find_in_set('停用',good_status) = 0", orgid).Find(&goodinfo).Error
1182
+	err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND  find_in_set('停用',good_status) = 0", orgid).Preload("GoodSotckInfo", "stock_count >0").Find(&goodinfo).Error
1183
 	return goodinfo, err
1183
 	return goodinfo, err
1184
 }
1184
 }
1185
 
1185
 

+ 6 - 6
service/gobal_config_service.go ファイルの表示

570
 func GetAllBaseDurgListCount(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (drug []*models.VmBaseDrug, total int64, err error) {
570
 func GetAllBaseDurgListCount(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (drug []*models.VmBaseDrug, total int64, err error) {
571
 
571
 
572
 	offset := (page - 1) * limit
572
 	offset := (page - 1) * limit
573
-	db := XTReadDB().Table("xt_base_drug").Where("status = 1")
573
+	db := readDb2.Table("xt_base_drug").Where("status = 1")
574
 	likeKey := "%" + keyword + "%"
574
 	likeKey := "%" + keyword + "%"
575
 	if orgid > 0 {
575
 	if orgid > 0 {
576
 		db = db.Where("org_id = ?", orgid)
576
 		db = db.Where("org_id = ?", orgid)
691
 }
691
 }
692
 
692
 
693
 func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
693
 func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
694
-	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
694
+	db := readDb2.Table("xt_drug_warehouse_info as x").Where("x.status = 1")
695
 
695
 
696
 	if startime > 0 {
696
 	if startime > 0 {
697
 		db = db.Where("x.ctime >=?", startime)
697
 		db = db.Where("x.ctime >=?", startime)
707
 }
707
 }
708
 
708
 
709
 func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
709
 func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
710
-	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
710
+	db := readDb2.Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
711
 
711
 
712
 	if startime > 0 {
712
 	if startime > 0 {
713
 		db = db.Where("x.ctime >=?", startime)
713
 		db = db.Where("x.ctime >=?", startime)
723
 }
723
 }
724
 
724
 
725
 func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugAutomaticReduceDetail, err error) {
725
 func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugAutomaticReduceDetail, err error) {
726
-	db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
726
+	db := readDb2.Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
727
 
727
 
728
 	if startime > 0 {
728
 	if startime > 0 {
729
 		db = db.Where("x.record_time >=?", startime)
729
 		db = db.Where("x.record_time >=?", startime)
741
 
741
 
742
 func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
742
 func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
743
 
743
 
744
-	db := XTReadDB().Table(" xt_drug_cancel_stock_info as x").Where("x.status = 1")
744
+	db := readDb2.Table(" xt_drug_cancel_stock_info as x").Where("x.status = 1")
745
 
745
 
746
 	if startime > 0 {
746
 	if startime > 0 {
747
 		db = db.Where("x.ctime >=?", startime)
747
 		db = db.Where("x.ctime >=?", startime)
784
 		db = db.Where("x.warehouse_out_id = ?", id)
784
 		db = db.Where("x.warehouse_out_id = ?", id)
785
 	}
785
 	}
786
 
786
 
787
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price,t.min_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
787
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price,t.min_price,x.warehouse_info_id").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
788
 	return info, err
788
 	return info, err
789
 }
789
 }
790
 
790
 

+ 3 - 1
service/his_service.go ファイルの表示

593
 	WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
593
 	WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
594
 	Status           int64 `gorm:"column:status" json:"status" form:"status"`
594
 	Status           int64 `gorm:"column:status" json:"status" form:"status"`
595
 	OrgId            int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
595
 	OrgId            int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
596
+	StockMaxNumber   int64 `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
597
+	StockMinNumber   int64 `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
596
 }
598
 }
597
 
599
 
598
 func (OtherDrugWarehouseInfo) TableName() string {
600
 func (OtherDrugWarehouseInfo) TableName() string {
719
 }
721
 }
720
 
722
 
721
 func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
723
 func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
722
-	err = readDb.Model(&BaseDrugLib{}).Where("org_id = ?  AND status = 1 AND  find_in_set('停用',drug_status) = 0", org_id).Find(&list).Error
724
+	err = readDb.Model(&BaseDrugLib{}).Where("org_id = ?  AND status = 1 AND  find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", "status = 1 and (stock_max_number > 0 or stock_min_number >0)").Find(&list).Error
723
 	return
725
 	return
724
 }
726
 }
725
 
727
 

+ 3 - 3
service/schedule_service.go ファイルの表示

610
 	}).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
610
 	}).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
611
 		return db.Where("status =1").Order("id asc")
611
 		return db.Where("status =1").Order("id asc")
612
 	}).Preload("Solution", func(db *gorm.DB) *gorm.DB {
612
 	}).Preload("Solution", func(db *gorm.DB) *gorm.DB {
613
-		return db.Where("status =1").Group("patient_id,mode_id").Order("id desc")
613
+		return db.Where("status =1").Group("patient_id,mode_id").Order("id asc")
614
 	}).Find(&list).Error
614
 	}).Find(&list).Error
615
 
615
 
616
 	return list, err
616
 	return list, err
795
 	return
795
 	return
796
 }
796
 }
797
 
797
 
798
-func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string) (schedules []*models.WeekSchedule, err error) {
798
+func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string) (schedules []*models.WeekScheduleSix, err error) {
799
 
799
 
800
 	db := readDb.Table("xt_schedule as s ").Where("s.status =1")
800
 	db := readDb.Table("xt_schedule as s ").Where("s.status =1")
801
 	if orgID > 0 {
801
 	if orgID > 0 {
825
 		}).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
825
 		}).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
826
 		return db.Where("status = 1").Order("id asc")
826
 		return db.Where("status = 1").Order("id asc")
827
 	}).Preload("Solution", func(db *gorm.DB) *gorm.DB {
827
 	}).Preload("Solution", func(db *gorm.DB) *gorm.DB {
828
-		return db.Where("status = 1").Group("patient_id,mode_id").Order("id desc")
828
+		return db.Where("status = 1").Group("patient_id,mode_id").Order("id asc")
829
 	}).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
829
 	}).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
830
 		return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
830
 		return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
831
 	}).Preload("HisDoctorAdviceInfo", "status = 1").Joins("JOIN xt_patients as p ON p.id = s.patient_id").
831
 	}).Preload("HisDoctorAdviceInfo", "status = 1").Joins("JOIN xt_patients as p ON p.id = s.patient_id").

+ 2 - 2
service/self_drug_service.go ファイルの表示

1037
 	return info, err
1037
 	return info, err
1038
 }
1038
 }
1039
 
1039
 
1040
-func GetLastDrugWarehouseInfo(drugid int64) (models.XtDrugWarehouseInfo, error) {
1040
+func GetLastDrugWarehouseInfSix(drugid int64) (models.XtDrugWarehouseInfo, error) {
1041
 
1041
 
1042
 	info := models.XtDrugWarehouseInfo{}
1042
 	info := models.XtDrugWarehouseInfo{}
1043
-	err := XTReadDB().Model(&info).Where("id=? and status = 1", drugid).Last(&info).Error
1043
+	err := XTReadDB().Model(&info).Where("drug_id=? and status = 1", drugid).Last(&info).Error
1044
 	return info, err
1044
 	return info, err
1045
 }
1045
 }
1046
 
1046
 

+ 182 - 25
service/stock_service.go ファイルの表示

319
 }
319
 }
320
 
320
 
321
 func FindAllGoodType(org_id int64) (goodType []*models.GoodsType, err error) {
321
 func FindAllGoodType(org_id int64) (goodType []*models.GoodsType, err error) {
322
-	err = readDb.Model(&models.GoodsType{}).Where("org_id = ? AND status = 1", org_id).Find(&goodType).Error
322
+	err = readDb2.Model(&models.GoodsType{}).Where("org_id = ? AND status = 1", org_id).Find(&goodType).Error
323
 	return goodType, err
323
 	return goodType, err
324
 }
324
 }
325
 
325
 
329
 }
329
 }
330
 
330
 
331
 func FindAllGoodInfo(org_id int64) (goodInfo []*models.GoodInfo, err error) {
331
 func FindAllGoodInfo(org_id int64) (goodInfo []*models.GoodInfo, err error) {
332
-	err = readDb.Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1", org_id).Find(&goodInfo).Error
332
+	err = readDb2.Model(&models.GoodInfo{}).Where("org_id = ? AND status = 1", org_id).Find(&goodInfo).Error
333
 	return goodInfo, err
333
 	return goodInfo, err
334
 }
334
 }
335
 
335
 
579
 	return
579
 	return
580
 }
580
 }
581
 
581
 
582
+func GetDrugFlowIsExist(warhouseing int64, drug_id int64) (*models.DrugFlow, error) {
583
+
584
+	info := models.DrugFlow{}
585
+	err = XTReadDB().Where("warehousing_id = ? and drug_id = ? and status = 1", warhouseing, drug_id).Find(&info).Error
586
+
587
+	if err == gorm.ErrRecordNotFound {
588
+		return nil, err
589
+	}
590
+	if err != nil {
591
+		return nil, err
592
+	}
593
+	return &info, nil
594
+}
595
+
582
 func GetDrugByWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
596
 func GetDrugByWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
583
 
597
 
584
 	info := models.XtDrugWarehouseInfo{}
598
 	info := models.XtDrugWarehouseInfo{}
599
 	return err
613
 	return err
600
 }
614
 }
601
 
615
 
616
+func CreateDrugFlowTwo(flow *models.DrugFlow) error {
617
+
618
+	err := XTWriteDB().Create(&flow).Error
619
+	return err
620
+}
602
 func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err error) {
621
 func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err error) {
603
 	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
622
 	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
604
 
623
 
629
 	return info, err
648
 	return info, err
630
 }
649
 }
631
 
650
 
651
+func FindWarehousingInfoTen(goodId int64) (models.WarehousingInfo, error) {
652
+	info := models.WarehousingInfo{}
653
+	err := XTReadDB().Select(" good_id,sum(stock_count) as stock_count").Where("good_id = ? and status = 1", goodId).Find(&info).Error
654
+	return info, err
655
+}
656
+
632
 //药品先进先出,找出最先入库的批次
657
 //药品先进先出,找出最先入库的批次
633
 
658
 
634
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
659
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
1645
 
1670
 
1646
 func FindAllStockInfo(orgId int64, page int64, limit int64, keyword string, startime int64, endtime int64, type_name int64) (list []*models.StockInfo, total int64, err error) {
1671
 func FindAllStockInfo(orgId int64, page int64, limit int64, keyword string, startime int64, endtime int64, type_name int64) (list []*models.StockInfo, total int64, err error) {
1647
 
1672
 
1648
-	db := readDb.Model(&models.StockInfo{})
1673
+	db := readDb2.Model(&models.StockInfo{})
1649
 	if startime > 0 {
1674
 	if startime > 0 {
1650
 
1675
 
1651
 		db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
1676
 		db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
2903
 
2928
 
2904
 func GetCoutWareseOutInfo(startime int64, endtime int64, orgid int64) (houseOutInfo []*models.VmWarehouseOutInfo, err error) {
2929
 func GetCoutWareseOutInfo(startime int64, endtime int64, orgid int64) (houseOutInfo []*models.VmWarehouseOutInfo, err error) {
2905
 
2930
 
2906
-	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status  =1")
2931
+	db := readDb2.Table("xt_warehouse_out_info as x").Where("x.status  =1")
2907
 	err = db.Select("x.good_id,Sum(x.count) as count,x.remark,x.price,x.org_id").Where("x.ctime >=? and x.ctime<=? and x.org_id = ?", startime, endtime, orgid).Group("x.good_id").Scan(&houseOutInfo).Error
2932
 	err = db.Select("x.good_id,Sum(x.count) as count,x.remark,x.price,x.org_id").Where("x.ctime >=? and x.ctime<=? and x.org_id = ?", startime, endtime, orgid).Group("x.good_id").Scan(&houseOutInfo).Error
2908
 	return houseOutInfo, err
2933
 	return houseOutInfo, err
2909
 }
2934
 }
2911
 func GetGoodInfomationList(orgid int64, keyword string) (goodInfo []*models.GoodInfo, err error) {
2936
 func GetGoodInfomationList(orgid int64, keyword string) (goodInfo []*models.GoodInfo, err error) {
2912
 	key := "%" + keyword + "%"
2937
 	key := "%" + keyword + "%"
2913
 	if len(keyword) == 0 {
2938
 	if len(keyword) == 0 {
2914
-		err = XTReadDB().Where("org_id = ? and status = 1 AND  find_in_set('停用',good_status) = 0", orgid).Find(&goodInfo).Error
2939
+		err = readDb2.Where("org_id = ? and status = 1 AND  find_in_set('停用',good_status) = 0", orgid).Find(&goodInfo).Error
2915
 
2940
 
2916
 	} else {
2941
 	} else {
2917
-		err = XTReadDB().Where("org_id = ? and status = 1 AND good_name like ? AND  find_in_set('停用',good_status) = 0", orgid, key).Find(&goodInfo).Error
2942
+		err = readDb2.Where("org_id = ? and status = 1 AND good_name like ? AND  find_in_set('停用',good_status) = 0", orgid, key).Find(&goodInfo).Error
2918
 
2943
 
2919
 	}
2944
 	}
2920
 	return goodInfo, err
2945
 	return goodInfo, err
2995
 
3020
 
2996
 func GetAllManufacturerList(orgid int64) (list []*models.Manufacturer, err error) {
3021
 func GetAllManufacturerList(orgid int64) (list []*models.Manufacturer, err error) {
2997
 
3022
 
2998
-	err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&list).Error
3023
+	err = readDb2.Where("org_id = ? and status = 1", orgid).Find(&list).Error
2999
 	return list, err
3024
 	return list, err
3000
 }
3025
 }
3001
 
3026
 
3161
 
3186
 
3162
 func GetSearchDrugList(keywords string, orgid int64) (drug []*models.BaseDrugLib, err error) {
3187
 func GetSearchDrugList(keywords string, orgid int64) (drug []*models.BaseDrugLib, err error) {
3163
 
3188
 
3164
-	db := XTReadDB().Model(&drug).Where("org_id=? and status=1 ", orgid)
3189
+	db := XTReadDB().Model(&drug).Where("org_id=? and status=1  and drug_status<>'停用'", orgid)
3165
 	if len(keywords) > 0 {
3190
 	if len(keywords) > 0 {
3166
 		likekey := "%" + keywords + "%"
3191
 		likekey := "%" + keywords + "%"
3167
 		err = db.Where("(drug_name LIKE ?)", likekey).Find(&drug).Error
3192
 		err = db.Where("(drug_name LIKE ?)", likekey).Find(&drug).Error
3173
 
3198
 
3174
 func GetSearchGoodList(keywords string, orgid int64) (good []*models.GoodInfo, err error) {
3199
 func GetSearchGoodList(keywords string, orgid int64) (good []*models.GoodInfo, err error) {
3175
 
3200
 
3176
-	db := XTReadDB().Model(&good).Where("org_id =? and status = 1", orgid)
3201
+	db := XTReadDB().Model(&good).Where("org_id =? and status = 1 and good_status <> '停用'", orgid)
3177
 	if len(keywords) > 0 {
3202
 	if len(keywords) > 0 {
3178
 		likekey := "%" + keywords + "%"
3203
 		likekey := "%" + keywords + "%"
3179
 		err = db.Where("(good_name Like ?)", likekey).Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
3204
 		err = db.Where("(good_name Like ?)", likekey).Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
3277
 func GetAllGoodInfoStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.GoodInfo, total int64, err error) {
3302
 func GetAllGoodInfoStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.GoodInfo, total int64, err error) {
3278
 
3303
 
3279
 	offset := (page - 1) * limit
3304
 	offset := (page - 1) * limit
3280
-	db := XTReadDB().Table("xt_good_information as x").Where("x.status= 1")
3305
+	db := readDb2.Table("xt_good_information as x").Where("x.status= 1")
3281
 
3306
 
3282
 	likeKey := "%" + keyword + "%"
3307
 	likeKey := "%" + keyword + "%"
3283
 	if len(likeKey) > 0 {
3308
 	if len(likeKey) > 0 {
3364
 
3389
 
3365
 func GetStockDrugCount(startime int64, endtime int64, orgid int64) (info []*models.VmWarehouseInfo, err error) {
3390
 func GetStockDrugCount(startime int64, endtime int64, orgid int64) (info []*models.VmWarehouseInfo, err error) {
3366
 
3391
 
3367
-	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
3392
+	db := readDb2.Table("xt_warehouse_info as x").Where("x.status = 1")
3368
 	if startime > 0 {
3393
 	if startime > 0 {
3369
 		db = db.Where("x.ctime >=?", startime)
3394
 		db = db.Where("x.ctime >=?", startime)
3370
 	}
3395
 	}
3380
 }
3405
 }
3381
 
3406
 
3382
 func GetAutoDiallysisBefor(startime int64, endtime int64, orgid int64) (info []*models.VmWarehouseInfo, err error) {
3407
 func GetAutoDiallysisBefor(startime int64, endtime int64, orgid int64) (info []*models.VmWarehouseInfo, err error) {
3383
-	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
3408
+	db := readDb2.Table("xt_warehouse_out_info as x").Where("x.status = 1")
3384
 	if startime > 0 {
3409
 	if startime > 0 {
3385
 		db = db.Where("x.ctime >=?", startime)
3410
 		db = db.Where("x.ctime >=?", startime)
3386
 	}
3411
 	}
3398
 func GetOutStockTotalCountFour(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
3423
 func GetOutStockTotalCountFour(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
3399
 
3424
 
3400
 	if endtime > 0 {
3425
 	if endtime > 0 {
3401
-		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count,x.record_time FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time <=?  and `status` = 1)  as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
3426
+		err = readDb2.Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count,x.record_time FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time <=?  and `status` = 1)  as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
3402
 	}
3427
 	}
3403
 	if endtime == 0 {
3428
 	if endtime == 0 {
3404
 		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count,x.record_time FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3429
 		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count,x.record_time FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3419
 	if orgid > 0 {
3444
 	if orgid > 0 {
3420
 		db = db.Where("x.org_id = ?", orgid)
3445
 		db = db.Where("x.org_id = ?", orgid)
3421
 	}
3446
 	}
3422
-	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3447
+	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id,x.warehouse_info_id").Order("x.ctime desc").Scan(&out).Error
3423
 	return out, err
3448
 	return out, err
3424
 }
3449
 }
3425
 
3450
 
3512
 
3537
 
3513
 func GetDrugWarehouOrderInfo(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
3538
 func GetDrugWarehouOrderInfo(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
3514
 
3539
 
3515
-	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
3516
-	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
3540
+	db := readDb2.Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
3541
+	table := readDb2.Table("xt_base_drug as t").Where("t.status = 1")
3517
 	fmt.Println(table)
3542
 	fmt.Println(table)
3518
 	if startime > 0 {
3543
 	if startime > 0 {
3519
 		db = db.Where("x.ctime>=?", startime)
3544
 		db = db.Where("x.ctime>=?", startime)
3685
 	return info, err
3710
 	return info, err
3686
 }
3711
 }
3687
 
3712
 
3713
+func GetDrugTotalCountTwo(drugid int64) (list []*models.VmDrugWarehouseInfo, err error) {
3714
+
3715
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3716
+	table := XTReadDB().Table("xt_base_drug as d").Where("d.status = 1")
3717
+	fmt.Println(table)
3718
+	if drugid > 0 {
3719
+		db = db.Where("x.drug_id = ?", drugid)
3720
+	}
3721
+	err = db.Select("x.drug_id,x.stock_max_number,x.stock_min_number,d.min_number").Joins("left join xt_base_drug as d on d.id = x.drug_id").Scan(&list).Error
3722
+
3723
+	return list, err
3724
+}
3725
+
3688
 func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
3726
 func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
3689
 
3727
 
3690
 	lib := models.BaseDrugLib{}
3728
 	lib := models.BaseDrugLib{}
3850
 
3888
 
3851
 func GetStockBatchNumber(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
3889
 func GetStockBatchNumber(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
3852
 
3890
 
3853
-	err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1 and number <> ''", id, orgid).Group("number").Find(&info).Error
3891
+	err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1 and number <> '' and stock_count<> 0", id, orgid).Find(&info).Error
3854
 	return info, err
3892
 	return info, err
3855
 }
3893
 }
3856
 
3894
 
3857
 func GetWarehouseOutInfoById(id int64, goodid int64) (info []*models.WarehouseOutInfo, err error) {
3895
 func GetWarehouseOutInfoById(id int64, goodid int64) (info []*models.WarehouseOutInfo, err error) {
3858
 
3896
 
3859
-	err = XTReadDB().Model(&info).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
3897
+	err = XTReadDB().Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
3860
 	return info, err
3898
 	return info, err
3861
 }
3899
 }
3862
 
3900
 
3927
 	return out, err
3965
 	return out, err
3928
 }
3966
 }
3929
 
3967
 
3930
-func GetLastGoodInformationByGoodId(goodid int64, warehouse_info_id int64, orgid int64) (models.WarehouseOutInfo, error) {
3968
+func GetLastGoodInformationByGoodId(goodid int64, warehouse_info_id int64) (models.WarehouseOutInfo, error) {
3931
 
3969
 
3932
 	info := models.WarehouseOutInfo{}
3970
 	info := models.WarehouseOutInfo{}
3933
 	err := XTReadDB().Where("good_id = ? and warehouse_info_id= ? and status =1", goodid, warehouse_info_id).Last(&info).Error
3971
 	err := XTReadDB().Where("good_id = ? and warehouse_info_id= ? and status =1", goodid, warehouse_info_id).Last(&info).Error
3962
 }
4000
 }
3963
 
4001
 
3964
 func FindFirstWarehousingInfoByGoodId(good_id int64, id int64) (info models.WarehousingInfo, err error) {
4002
 func FindFirstWarehousingInfoByGoodId(good_id int64, id int64) (info models.WarehousingInfo, err error) {
3965
-	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1 and id<>?", good_id, id).Order("ctime").First(&info).Error
4003
+	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND status = 1 and stock_count > 0", good_id).Order("ctime asc").First(&info).Error
3966
 	return info, err
4004
 	return info, err
3967
 }
4005
 }
3968
 
4006
 
4310
 	return info, err
4348
 	return info, err
4311
 }
4349
 }
4312
 
4350
 
4351
+func GetLastCancelStockInfoOne(id int64, drug_id int64) (models.DrugCancelStockInfo, error) {
4352
+
4353
+	info := models.DrugCancelStockInfo{}
4354
+
4355
+	err := XTReadDB().Where("cancel_stock_id = ? and drug_id = ? and status = 1", id, drug_id).Find(&info).Error
4356
+	return info, err
4357
+}
4358
+
4313
 func UpdatedDrugInfo(id int64, count int64) (err error) {
4359
 func UpdatedDrugInfo(id int64, count int64) (err error) {
4314
 
4360
 
4315
-	err = writeDb.Model(&models.DrugWarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
4361
+	err = XTWriteDB().Model(&models.XtDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
4362
+	return err
4363
+}
4364
+
4365
+func UpdatedDrugFlow(cancelstockid int64, drug_id int64, flow models.DrugFlow) error {
4366
+
4367
+	err := XTWriteDB().Model(&models.DrugFlow{}).Where("cancel_stock_id = ? and drug_id = ? and status = 1", cancelstockid, drug_id).Updates(map[string]interface{}{"count": flow.Count}).Error
4316
 	return err
4368
 	return err
4317
 }
4369
 }
4318
 
4370
 
4319
 func UpdatedDrugInfoOne(id int64, count int64) (err error) {
4371
 func UpdatedDrugInfoOne(id int64, count int64) (err error) {
4320
 
4372
 
4321
-	err = writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4373
+	err = XTWriteDB().Model(&models.XtDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4322
 	return err
4374
 	return err
4323
 }
4375
 }
4324
 
4376
 
4540
 	return adjust, total, err
4592
 	return adjust, total, err
4541
 }
4593
 }
4542
 
4594
 
4595
+func GetStockDamagedList(orgid int64, keyword string, page int64, limit int64) (adjust []*models.VmStockInventory, total int64, err error) {
4596
+	likeKey := "%" + keyword + "%"
4597
+	offset := (page - 1) * limit
4598
+	db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1 and x.inventory_type = 4")
4599
+	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
4600
+	tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
4601
+	fmt.Println(table, tab)
4602
+
4603
+	if len(keyword) > 0 {
4604
+		db = db.Where("x.warehousing_order like ? or r.user_name like ?", likeKey, likeKey)
4605
+	}
4606
+
4607
+	if orgid > 0 {
4608
+		db = db.Where("x.user_org_id = ?", orgid)
4609
+	}
4610
+
4611
+	err = db.Group("x.id").Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,t.packing_unit,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&adjust).Error
4612
+	return adjust, total, err
4613
+
4614
+}
4615
+
4616
+func GetStockDamagedCount(orgid int64) (adjust []*models.VmStockInventory, err error) {
4617
+
4618
+	db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1 and x.inventory_type = 4")
4619
+	if orgid > 0 {
4620
+		db = db.Where("x.user_org_id = ?", orgid)
4621
+	}
4622
+	err = db.Group("x.good_id").Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,sum(x.count) as count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number").Scan(&adjust).Error
4623
+	return adjust, err
4624
+}
4625
+
4543
 func UpdateCheckDamage(ids []string, reportPrice models.XtStockReportPrice) error {
4626
 func UpdateCheckDamage(ids []string, reportPrice models.XtStockReportPrice) error {
4544
 
4627
 
4545
 	err := XTWriteDB().Model(&reportPrice).Where("id in(?) and status = 1", ids).Updates(map[string]interface{}{"checker": reportPrice.Checker, "checker_time": reportPrice.CheckerTime, "checker_status": reportPrice.CheckerStatus}).Error
4628
 	err := XTWriteDB().Model(&reportPrice).Where("id in(?) and status = 1", ids).Updates(map[string]interface{}{"checker": reportPrice.Checker, "checker_time": reportPrice.CheckerTime, "checker_status": reportPrice.CheckerStatus}).Error
4678
 
4761
 
4679
 	likeKey := "%" + keyword + "%"
4762
 	likeKey := "%" + keyword + "%"
4680
 	offset := (page - 1) * limit
4763
 	offset := (page - 1) * limit
4681
-	db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1")
4764
+	db := XTReadDB().Table("xt_stock_inventory as x").Where("x.status = 1 and x.type = 10")
4682
 	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
4765
 	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
4683
 	tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
4766
 	tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
4684
 	fmt.Println(table, tab)
4767
 	fmt.Println(table, tab)
4685
 	if len(keyword) > 0 {
4768
 	if len(keyword) > 0 {
4686
-		db = db.Where("x.warehousing_order = ? or r.user_name like ?", keyword, likeKey)
4769
+		db = db.Where("x.good_name = ?", likeKey)
4687
 	}
4770
 	}
4688
 	if orgid > 0 {
4771
 	if orgid > 0 {
4689
 		db = db.Where("x.user_org_id = ?", orgid)
4772
 		db = db.Where("x.user_org_id = ?", orgid)
4690
 	}
4773
 	}
4691
-	err = db.Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,x.expire_date,x.product_date,t.packing_unit").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&list).Error
4774
+	err = db.Select("x.id,x.good_name,x.specification_name,x.warehousing_unit,x.count,x.buy_price,x.packing_price,x.new_price,x.manufacturer,x.dealer,x.remark,x.good_id,x.warehousing_order,x.license_number,x.start_time,x.creater,x.checker,x.checker_status,x.checker_time,x.total,x.number,x.expire_date,x.product_date,t.packing_unit,x.last_stock_count,x.type,x.inventory_type,x.stock_count").Joins("left join sgj_users.sgj_user_admin_role as r on r.id = x.creater").Joins("left join xt_good_information as t on t.id =x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&list).Error
4692
 	return list, total, err
4775
 	return list, total, err
4693
 }
4776
 }
4694
 
4777
 
4777
 	err = XTReadDB().Model(&info).Where("good_id = ? and status = 1", id).Preload("GoodInfo", "status = 1").Find(&info).Error
4860
 	err = XTReadDB().Model(&info).Where("good_id = ? and status = 1", id).Preload("GoodInfo", "status = 1").Find(&info).Error
4778
 	return info, err
4861
 	return info, err
4779
 }
4862
 }
4863
+
4864
+func UpdatedWarehousingInfo(info models.WarehousingInfo, id int64) error {
4865
+	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
4866
+	return err
4867
+}
4868
+
4869
+func GetDamageDetailByGoodId(good_id int64) (list []*models.XtStockInventory, err error) {
4870
+
4871
+	err = XTReadDB().Model(&list).Where("good_id = ? and status = 1", good_id).Find(&list).Error
4872
+
4873
+	return list, err
4874
+}
4875
+
4876
+func GetCancelStockId(cancelstock_id int64, drug_id int64) (*models.DrugFlow, error) {
4877
+	flow := models.DrugFlow{}
4878
+	err := XTReadDB().Where("cancel_stock_id = ? and drug_id = ?", cancelstock_id, drug_id).Find(&flow).Error
4879
+	if err == gorm.ErrRecordNotFound {
4880
+		return nil, err
4881
+	}
4882
+	if err != nil {
4883
+		return nil, err
4884
+	}
4885
+	return &flow, nil
4886
+}
4887
+
4888
+func GetTotalDrugCancelInfo(batchNumber_id int64, drug_id int64, id int64) (info []*models.DrugCancelStockInfo, err error) {
4889
+
4890
+	err = XTReadDB().Where("batch_number_id = ? and drug_id = ? and status = 1 and id<>?", batchNumber_id, drug_id, id).Find(&info).Error
4891
+	return info, err
4892
+}
4893
+
4894
+func GetLastDrugWarehouseInfo(drugid int64) (models.XtDrugWarehouseInfo, error) {
4895
+	info := models.XtDrugWarehouseInfo{}
4896
+	err := XTReadDB().Where("drug_id = ? and status =1", drugid).Last(&info).Error
4897
+	return info, err
4898
+}
4899
+
4900
+func GetLastGoodWarehouseInfo(goodid int64) (models.WarehousingInfo, error) {
4901
+
4902
+	info := models.WarehousingInfo{}
4903
+	err := XTReadDB().Where("good_id =? and status = 1", goodid).Find(&info).Error
4904
+	return info, err
4905
+}
4906
+
4907
+func GetGoodStockFlowInfo(warehouseid int64, goodid int64) (*models.VmStockFlow, error) {
4908
+
4909
+	flow := models.VmStockFlow{}
4910
+	err := XTReadDB().Where("warehousing_detail_id = ? and good_id = ? and status = 1", warehouseid, goodid).Find(&flow).Error
4911
+	if err == gorm.ErrRecordNotFound {
4912
+		return nil, err
4913
+	}
4914
+	if err != nil {
4915
+		return nil, err
4916
+	}
4917
+	return &flow, nil
4918
+}
4919
+
4920
+func GetLastInfoMationById(id int64) (models.GoodInfo, error) {
4921
+	info := models.GoodInfo{}
4922
+	err := XTReadDB().Where("id =? and status = 1", id).Find(&info).Error
4923
+	return info, err
4924
+}
4925
+
4926
+func UpdateGoodInfoMation(goodid int64, info models.GoodInfo) error {
4927
+
4928
+	err := XTWriteDB().Model(&info).Where("id =? and status = 1", goodid).Updates(map[string]interface{}{"total": info.Total}).Error
4929
+	return err
4930
+}
4931
+
4932
+func UpdateWarehouseInfoByGoodId(info models.WarehousingInfo, id int64) error {
4933
+
4934
+	err := XTWriteDB().Model(&info).Where("id =? and status = 1", id).Updates(map[string]interface{}{"warehousing_count": info.WarehousingCount, "stock_count": info.StockCount}).Error
4935
+	return err
4936
+}

+ 2 - 4
service/user_service.go ファイルの表示

48
 }
48
 }
49
 
49
 
50
 func GetAllAdminUsers(orgId, appid int64) (list []*AdminUserList, err error) {
50
 func GetAllAdminUsers(orgId, appid int64) (list []*AdminUserList, err error) {
51
-	//fmt.Println("orgid", orgId)
52
-	//fmt.Println("appid", appid)
51
+
53
 	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
52
 	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
54
 	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
53
 	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
55
 	return
54
 	return
56
 }
55
 }
57
 
56
 
58
 func GetAllAdminUsersTwo(orgId int64) (list []*AdminUserList, err error) {
57
 func GetAllAdminUsersTwo(orgId int64) (list []*AdminUserList, err error) {
59
-	//fmt.Println("orgid", orgId)
60
-	//fmt.Println("appid", appid)
58
+
61
 	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=?  and ua.status=1", orgId).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
59
 	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=?  and ua.status=1", orgId).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
62
 	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
60
 	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
63
 	return
61
 	return

File diff suppressed because it is too large
+ 819 - 536
service/warhouse_service.go