Przeglądaj źródła

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

csx 3 lat temu
rodzic
commit
ff9b874fc7

+ 6 - 2
conf/app.conf Wyświetl plik

@@ -7,7 +7,7 @@ copyrequestbody = true
7 7
 sessionon = true
8 8
 #sessiongcmaxlifetime = 64800
9 9
 
10
-tokencookiemaxlifetime = 7200
10
+tokencookiemaxlifetime = 604800
11 11
 enablexsrf = false
12 12
 xsrfkey = 61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o
13 13
 xsrfexpire = 3600
@@ -218,7 +218,11 @@ writesgjpatientmysqluser = root
218 218
 writesgjpatientmysqlpass = 1Q2W3e4r!@#$
219 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
 

+ 220 - 101
controllers/drug_stock_api_contorller.go Wyświetl plik

@@ -8,6 +8,7 @@ import (
8 8
 	"encoding/json"
9 9
 	"fmt"
10 10
 	"github.com/astaxie/beego"
11
+	"github.com/jinzhu/gorm"
11 12
 	"reflect"
12 13
 	"strconv"
13 14
 	"strings"
@@ -626,10 +627,38 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
626 627
 
627 628
 		errs = service.CreateDrugWarehousingInfo(warehousingInfo)
628 629
 		if errs == nil {
629
-			service.CreateDrugFlow(drugFlow)
630 630
 			//更改库存
631 631
 			service.UpdateDrugInfo(warehousingInfo)
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)
632 657
 
658
+				if existerrcodes == gorm.ErrRecordNotFound {
659
+					service.CreateDrugFlowOne(flows)
660
+				}
661
+			}
633 662
 		}
634 663
 
635 664
 	}
@@ -638,53 +667,96 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
638 667
 		var total int64
639 668
 		var minNumber float64
640 669
 		var allTotal int64
670
+		var chaTotal int64
641 671
 		for _, item := range upDateWarehousingInfo {
642 672
 			//查询修改的记录
643 673
 			orderInfo, _ := service.GetDrugWarehouseOrderOne(id, item.DrugId)
644 674
 
675
+			fmt.Println("hh23323232323232332233232", orderInfo)
676
+
645 677
 			info, _ := service.FindeDrugInfo(item.DrugId)
646 678
 
679
+			//历史入库总数
647 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 712
 			warehouseInfo, _ := service.FindeLastWarehouseInfo(item.ID)
661 713
 			fmt.Println("hhhhh23hh32h232332323223", warehouseInfo)
662 714
 			var total int64
715
+
663 716
 			//比较大小(加)
717
+			// 如果当前的入库数量 大于 历史入库数量
664 718
 			if item.WarehousingCount > warehouseInfo.WarehousingCount {
665 719
 				total = item.WarehousingCount - warehouseInfo.WarehousingCount
720
+				item.StockMaxNumber = warehouseInfo.StockMaxNumber + total
721
+
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
+					}
733
+				}
734
+				break
666 735
 			}
667
-			item.StockMaxNumber = warehouseInfo.StockMaxNumber + total
736
+
737
+			// 如果当前的入库数量 小于 历史入库数量
668 738
 			if item.WarehousingCount < warehouseInfo.WarehousingCount {
669 739
 				total = warehouseInfo.WarehousingCount - item.WarehousingCount
740
+				item.StockMaxNumber = warehouseInfo.StockMaxNumber - total
741
+
742
+				errs = service.UpDateDrugWarehousingInfo(item)
743
+				if len(drugFlow) > 0 {
744
+					for _, it := range drugFlow {
745
+						fmt.Println(it)
746
+						flow := models.DrugFlow{
747
+							Count: item.StockMaxNumber,
748
+						}
749
+						parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, warehouseInfo.WarehousingId)
750
+						fmt.Println(parseDateErr)
751
+					}
752
+				}
753
+				break
670 754
 			}
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 755
 
681
-	if len(drugFlow) > 0 {
682
-		for _, item := range drugFlow {
683
-			flow := models.DrugFlow{
684
-				Count: item.Count,
756
+			if item.WarehousingCount == warehouseInfo.WarehousingCount {
757
+				errs = service.UpDateDrugWarehousingInfo(item)
758
+				break
685 759
 			}
686
-			parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, item.WarehousingId)
687
-			fmt.Println(parseDateErr)
688 760
 		}
689 761
 	}
690 762
 
@@ -1153,7 +1225,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1153 1225
 
1154 1226
 	var warehousingOutInfo []*models.DrugWarehouseOutInfo
1155 1227
 
1156
-	var drugFlow []*models.DrugFlow
1228
+	//var drugFlow []*models.DrugFlow
1157 1229
 
1158 1230
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1159 1231
 		thisStockIn, _ := dataBody["stockOut"].([]interface{})
@@ -1226,7 +1298,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1226 1298
 					}
1227 1299
 
1228 1300
 				}
1229
-				fmt.Println("孟子", warehouseOut.ID)
1301
+
1230 1302
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1231 1303
 
1232 1304
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1253,52 +1325,46 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1253 1325
 					WarehouseInfoId:         warehouse_info_id,
1254 1326
 				}
1255 1327
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1256
-				fmt.Println("hhhhhhhhhhhhhhhh", warehouseOut.ID)
1257 1328
 
1258
-				drugflow := &models.DrugFlow{
1259
-					WarehouseOutId:          warehouseOut.ID,
1260
-					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1261
-					DrugId:                  drug_id,
1262
-					Number:                  number,
1263
-					ProductDate:             productDates,
1264
-					ExpireDate:              expiryDates,
1265
-					Count:                   count,
1266
-					Price:                   price,
1267
-					Status:                  1,
1268
-					Ctime:                   ctime,
1269
-					UserOrgId:               adminUserInfo.CurrentOrgId,
1270
-					Manufacturer:            manufacturer,
1271
-					Dealer:                  dealer,
1272
-					BatchNumber:             batch_number,
1273
-					MaxUnit:                 max_unit,
1274
-					ConsumableType:          2,
1275
-					IsEdit:                  1,
1276
-					Creator:                 adminUserInfo.AdminUser.Id,
1277
-					IsSys:                   0,
1278
-				}
1279
-				drugFlow = append(drugFlow, drugflow)
1329
+				//drugflow := &models.DrugFlow{
1330
+				//	WarehouseOutId:          warehouseOut.ID,
1331
+				//	WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1332
+				//	DrugId:                  drug_id,
1333
+				//	Number:                  number,
1334
+				//	ProductDate:             productDates,
1335
+				//	ExpireDate:              expiryDates,
1336
+				//	Count:                   count,
1337
+				//	Price:                   price,
1338
+				//	Status:                  1,
1339
+				//	Ctime:                   ctime,
1340
+				//	UserOrgId:               adminUserInfo.CurrentOrgId,
1341
+				//	Manufacturer:            manufacturer,
1342
+				//	Dealer:                  dealer,
1343
+				//	BatchNumber:             batch_number,
1344
+				//	MaxUnit:                 max_unit,
1345
+				//	ConsumableType:          2,
1346
+				//	IsEdit:                  1,
1347
+				//	Creator:                 adminUserInfo.AdminUser.Id,
1348
+				//	IsSys:                   0,
1349
+				//}
1350
+				//drugFlow = append(drugFlow, drugflow)
1280 1351
 			}
1281 1352
 		}
1282 1353
 	}
1283
-	var total_count int64
1284
-	var prescribing_number_total int64
1354
+
1355
+	var total_count int64              //总库存
1356
+	var prescribing_number_total int64 //出库数据
1285 1357
 	//调用出库逻辑
1286 1358
 	for _, item := range warehousingOutInfo {
1287 1359
 		//获取药品库存
1288
-		info, _ := service.GetDrugTotalCountOne(item.DrugId, item.OrgId, item.WarehouseInfoId)
1360
+		info, _ := service.GetDrugTotalCountTwo(item.DrugId)
1361
+
1362
+		for _, it := range info {
1363
+			total_count += it.StockMaxNumber*it.MinNumber + it.StockMinNumber
1364
+		}
1289 1365
 		//查询改药品信息
1290 1366
 		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)
1367
+
1302 1368
 		//判断单位是否相等
1303 1369
 		if medical.MaxUnit == item.CountUnit {
1304 1370
 			//转化为最小单位
@@ -1308,8 +1374,10 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1308 1374
 			prescribing_number_total = item.Count
1309 1375
 		}
1310 1376
 
1377
+		fmt.Println("药品ID", item.DrugId)
1311 1378
 		fmt.Println("数量一", prescribing_number_total)
1312 1379
 		fmt.Println("数量二", total_count)
1380
+
1313 1381
 		//判断单位
1314 1382
 		if total_count == 0 {
1315 1383
 			goodObj, _ := service.GetDrugByGoodId(item.DrugId)
@@ -1339,11 +1407,11 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1339 1407
 			return
1340 1408
 		} else {
1341 1409
 			service.AddSigleDrugWarehouseOut(&warehouseOut)
1342
-			list, _ := service.GetLastWarehouseOut(adminUserInfo.CurrentOrgId)
1343
-			for _, item := range drugFlow {
1344
-				item.WarehouseOutId = list.ID
1345
-			}
1346
-			service.CreateDrugFlow(drugFlow)
1410
+			//list, _ := service.GetLastWarehouseOut(adminUserInfo.CurrentOrgId)
1411
+			//for _, item := range drugFlow {
1412
+			//	item.WarehouseOutId = list.ID
1413
+			//}
1414
+			//service.CreateDrugFlow(drugFlow)
1347 1415
 			// 出库流程
1348 1416
 			// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1349 1417
 			drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
@@ -1351,6 +1419,8 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1351 1419
 				prescribingNumber := item.Count
1352 1420
 				service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
1353 1421
 			}
1422
+			prescribing_number_total = 0
1423
+			total_count = 0
1354 1424
 		}
1355 1425
 
1356 1426
 	}
@@ -1364,7 +1434,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1364 1434
 		"min_unit":   "",
1365 1435
 		"max_unit":   "",
1366 1436
 	})
1367
-
1437
+	return
1368 1438
 }
1369 1439
 func (c *StockDrugApiController) GetDrugWarehouseOutList() {
1370 1440
 	page, _ := c.GetInt64("page", -1)
@@ -1836,14 +1906,12 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1836 1906
 			}
1837 1907
 
1838 1908
 			all_number = info.Count*medical.MinNumber + info.StockMinNumber
1839
-			fmt.Println("总库存223232", all_number)
1840
-			fmt.Println("当前库存00000000000000000000000000000000000000000", max_number)
1909
+
1841 1910
 			////比较当前出库数量 和 最后一次出库数量,正常出库
1842 1911
 			if max_number <= min_number {
1843 1912
 				errs = service.UpDateDrugWarehouseOutInfo(item)
1844 1913
 				cha_number = min_number - max_number
1845
-				fmt.Println("差库存", cha_number)
1846
-				fmt.Println("最后一次库存0000000000000000000000000000000000000000", min_number)
1914
+
1847 1915
 				if item.CountUnit == medical.MaxUnit {
1848 1916
 					maxNumber = cha_number / medical.MinNumber
1849 1917
 					parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
@@ -1900,9 +1968,6 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1900 1968
 				}
1901 1969
 
1902 1970
 			}
1903
-
1904
-			fmt.Println("当前出库", max_number)
1905
-			fmt.Println("最后一次232233", min_number)
1906 1971
 			//退库操作
1907 1972
 			if max_number > min_number {
1908 1973
 
@@ -1911,12 +1976,12 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1911 1976
 				if all_number >= cha_number {
1912 1977
 
1913 1978
 					errs = service.UpDateDrugWarehouseOutInfo(item)
1914
-					fmt.Println("232322332233232", item.CountUnit, medical.MaxUnit)
1979
+
1915 1980
 					if item.CountUnit == medical.MaxUnit {
1916 1981
 						maxNumber = cha_number / medical.MinNumber
1917
-						fmt.Println("maxNumber232323232323232232", maxNumber)
1982
+
1918 1983
 						parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1919
-						fmt.Println("parseDateErr9999999999999999999999", parseDateErr)
1984
+						fmt.Println("parseDateErr", parseDateErr)
1920 1985
 						if parseDateErr != nil {
1921 1986
 							utils.ErrorLog(errs.Error())
1922 1987
 							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
@@ -2018,8 +2083,6 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2018 2083
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2019 2084
 		return
2020 2085
 	}
2021
-	fmt.Println("cancelStockDate232323223233223", cancelStockDate.Unix())
2022
-
2023 2086
 	adminUserInfo := c.GetAdminUserInfo()
2024 2087
 	operation_time := time.Now().Unix()
2025 2088
 	creater := adminUserInfo.AdminUser.Id
@@ -2044,7 +2107,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2044 2107
 		Type:         types,
2045 2108
 	}
2046 2109
 	service.AddSigleDrugCancelStock(&cancelStock)
2047
-	fmt.Println("hh232323232323232323232323232322332", parseDateErr)
2110
+
2048 2111
 	dataBody := make(map[string]interface{}, 0)
2049 2112
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
2050 2113
 	if err != nil {
@@ -2151,7 +2214,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2151 2214
 						dealer_id = item.ID
2152 2215
 					}
2153 2216
 				}
2154
-				fmt.Println("99999999999999999999", batch_number_id)
2217
+
2155 2218
 				cancelStockInfo := &models.DrugCancelStockInfo{
2156 2219
 					OrderNumber:      cancelStock.OrderNumber,
2157 2220
 					CancelStockId:    cancelStock.ID,
@@ -2227,7 +2290,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2227 2290
 		if item.MaxUnit == medical.MinUnit {
2228 2291
 			total_number = item.Count
2229 2292
 		}
2230
-		fmt.Println("当前库存", total_number)
2293
+		fmt.Println("当前退库数量", total_number)
2231 2294
 		//查询当前药品退库的批次号的总入库数
2232 2295
 		infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2233 2296
 		fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit, infoWareInfo.StockMaxNumber, infoWareInfo.StockMinNumber)
@@ -2237,9 +2300,10 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2237 2300
 
2238 2301
 		//查询该批次的出库数量
2239 2302
 		outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2240
-		//查询该批次总的退库数量
2241 2303
 
2304
+		//查询该批次总的退库数量
2242 2305
 		canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2306
+
2243 2307
 		for _, item := range canInfo {
2244 2308
 			if item.MaxUnit == medical.MaxUnit {
2245 2309
 				item.Count = item.Count * medical.MinNumber
@@ -2263,8 +2327,10 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2263 2327
 		for _, item := range outInfo {
2264 2328
 			out_number += item.Count
2265 2329
 		}
2330
+		fmt.Println("当前退库数量", total_number)
2266 2331
 		fmt.Println("出库数量23232232323222332", out_number)
2267 2332
 		if out_number == 0 {
2333
+			service.UpdateDrugCancel(item.CancelStockId)
2268 2334
 			c.ServeSuccessJSON(map[string]interface{}{
2269 2335
 				"msg": "2",
2270 2336
 			})
@@ -2274,14 +2340,16 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2274 2340
 		if total_number > out_number {
2275 2341
 			service.UpdateDrugCancel(item.CancelStockId)
2276 2342
 			c.ServeSuccessJSON(map[string]interface{}{
2277
-				"msg": "4",
2343
+				"msg": "2",
2278 2344
 			})
2279 2345
 			return
2280 2346
 		}
2281 2347
 
2282 2348
 		//判断总退库数量是否大于出库数量
2283
-		fmt.Println("hhhhhhhhhhh", can_number+total_number)
2349
+		fmt.Println("该批次总退库数量", can_number+total_number)
2350
+		fmt.Println("总出口数量", out_number)
2284 2351
 		if can_number+total_number > out_number {
2352
+			//清空退库单
2285 2353
 			service.UpdateDrugCancel(item.CancelStockId)
2286 2354
 			c.ServeSuccessJSON(map[string]interface{}{
2287 2355
 				"msg": "2",
@@ -2297,8 +2365,6 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2297 2365
 			errs = service.CreateDrugFlow(drugFlow)
2298 2366
 
2299 2367
 			var total int64
2300
-			////退库到当前批次,获取当前退库批次的库存
2301
-			//info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
2302 2368
 
2303 2369
 			if medical.MaxUnit == item.MaxUnit {
2304 2370
 				total = item.Count
@@ -2318,7 +2384,6 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2318 2384
 				})
2319 2385
 			}
2320 2386
 			if medical.MinUnit == item.MaxUnit {
2321
-				fmt.Println("hhhhhh2323323232322332232332999999999进来", item.Count)
2322 2387
 				total = item.Count
2323 2388
 				warehouseInfo := models.XtDrugWarehouseInfo{
2324 2389
 					StockMinNumber: total,
@@ -2664,8 +2729,6 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2664 2729
 			}
2665 2730
 		}
2666 2731
 	}
2667
-	fmt.Println("cancelStockInfos232323223323223322323223", cancelStockInfos)
2668
-	fmt.Println("cancelStockInfos232323223323223322323223", upDateCancelStockInfos)
2669 2732
 
2670 2733
 	var errs error
2671 2734
 	if len(cancelStockInfos) > 0 {
@@ -2741,7 +2804,13 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2741 2804
 				//创建退库详情
2742 2805
 				errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2743 2806
 				//创建库存明细
2744
-				errs = service.CreateDrugFlow(drugFlow)
2807
+				//查询这个药品这个订单是否已存在流水
2808
+				for _, items := range drugFlow {
2809
+					_, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
2810
+					if errsId == gorm.ErrRecordNotFound {
2811
+						errs = service.CreateDrugFlowTwo(items)
2812
+					}
2813
+				}
2745 2814
 
2746 2815
 				//获取该批次最后一条退库详情
2747 2816
 				lastCancel, _ := service.GetLastCancelStockInfo(id)
@@ -2753,7 +2822,7 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2753 2822
 				if lastCancel.MaxUnit == medical.MinUnit {
2754 2823
 					cancel_number = lastCancel.Count
2755 2824
 				}
2756
-				fmt.Println("999999232323232232232323232323", lastCancel)
2825
+				fmt.Println("999999232323232232232323232323", item.Count, cancel_number)
2757 2826
 				var total int64
2758 2827
 
2759 2828
 				if medical.MaxUnit == item.MaxUnit {
@@ -2803,21 +2872,31 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2803 2872
 		}
2804 2873
 	}
2805 2874
 	if len(drugFlow) > 0 {
2806
-		parseDateErr := service.CreateDrugFlow(drugFlow)
2807
-		fmt.Println(parseDateErr)
2875
+		for _, items := range drugFlow {
2876
+			_, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
2877
+			if errsId == gorm.ErrRecordNotFound {
2878
+				errs = service.CreateDrugFlowTwo(items)
2879
+			}
2880
+		}
2808 2881
 	}
2809 2882
 
2810 2883
 	if len(upDateCancelStockInfos) > 0 {
2811 2884
 		var total int64
2812 2885
 		var out_count int64
2886
+		var cancel_count int64
2887
+		var now_count int64
2888
+		var all_count int64
2813 2889
 		for _, item := range upDateCancelStockInfos {
2890
+			//查询最后一条退库记录
2891
+			info, _ := service.GetLastCancelStockInfoOne(id, item.DrugId)
2814 2892
 			errs = service.UpDateDrugCancelStockInfo(item)
2815
-			//查询该批次最后一条退库记录
2816
-			info, _ := service.GetLastCancelStockInfo(id)
2893
+			fmt.Println("hh23232oooooooo2o3o2o32o23oo23o23o23", info)
2817 2894
 			//查询该药品的信息
2818 2895
 			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2819 2896
 			//统计该批次的总出库数
2820 2897
 			outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2898
+			//查询该批次的总退库数量
2899
+			cancelInfo, _ := service.GetTotalDrugCancelInfo(item.BatchNumberId, item.DrugId, item.ID)
2821 2900
 			for _, item := range outInfo {
2822 2901
 				if item.CountUnit == medical.MaxUnit {
2823 2902
 					item.Count = item.Count * medical.MinNumber
@@ -2831,21 +2910,61 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2831 2910
 				out_count += item.Count
2832 2911
 			}
2833 2912
 
2913
+			for _, item := range cancelInfo {
2914
+				if item.MaxUnit == medical.MaxUnit {
2915
+					item.Count = item.Count * medical.MinNumber
2916
+				}
2917
+				if item.MaxUnit == medical.MinUnit {
2918
+					item.Count = item.Count
2919
+				}
2920
+			}
2921
+
2922
+			for _, item := range cancelInfo {
2923
+				cancel_count += item.Count
2924
+			}
2925
+
2834 2926
 			fmt.Println("out_count232233332232323223", out_count)
2835 2927
 
2836 2928
 			if item.MaxUnit == medical.MaxUnit {
2837
-				item.Count = item.Count * medical.MinNumber
2929
+				now_count = item.Count * medical.MinNumber
2930
+			}
2931
+			if item.MaxUnit == medical.MinUnit {
2932
+				now_count = item.Count
2933
+			}
2934
+			fmt.Println("hhhhhh2323322323", now_count+cancel_count)
2935
+			//总退库批次
2936
+			all_count = now_count + cancel_count
2937
+
2938
+			//该批次的总出库数小与退库数报错返回
2939
+			if all_count > out_count {
2940
+				c.ServeSuccessJSON(map[string]interface{}{
2941
+					"msg": "4",
2942
+				})
2943
+				return
2944
+			}
2945
+
2946
+			if item.MaxUnit == medical.MaxUnit {
2838 2947
 				//更新库存
2839 2948
 				total = item.Count - info.Count
2840
-				fmt.Println("total232323232323232232323", total)
2841
-				service.UpdatedDrugInfo(item.BatchNumberId, total)
2949
+				parseDateErr := service.UpdatedDrugInfo(item.BatchNumberId, total)
2950
+				fmt.Println("parseDateErr", parseDateErr)
2951
+
2952
+				flow := models.DrugFlow{
2953
+					Count: item.Count,
2954
+				}
2955
+				service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
2842 2956
 				break
2957
+
2843 2958
 			}
2844 2959
 
2845 2960
 			if item.MaxUnit == medical.MinUnit {
2846 2961
 				item.Count = item.Count
2847 2962
 				total = item.Count - info.Count
2848 2963
 				service.UpdatedDrugInfoOne(item.BatchNumberId, total)
2964
+				flow := models.DrugFlow{
2965
+					Count: item.Count,
2966
+				}
2967
+				service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
2849 2968
 				break
2850 2969
 			}
2851 2970
 		}

+ 108 - 109
controllers/his_api_controller.go Wyświetl plik

@@ -633,115 +633,114 @@ func (c *HisApiController) CreateHisPrescription() {
633 633
 
634 634
 	patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
635 635
 
636
-	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
637
-
638
-	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
639
-
640
-	if drugStockConfig.IsOpen == 1 {
641
-		//校验库存总量
642
-		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
643
-			prescriptions, _ := dataBody["prescriptions"].([]interface{})
644
-			if len(prescriptions) > 0 {
645
-				for _, item := range prescriptions {
646
-					items := item.(map[string]interface{})
647
-					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
648
-						advices := items["advices"].([]interface{})
649
-						if len(advices) > 0 {
650
-							for _, advice := range advices {
651
-								var drug_id int64
652
-								var prescribing_number float64
653
-								var prescribingNumberUnit string
654
-
655
-								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
656
-									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
657
-								}
658
-								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
659
-									//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
660
-									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
661
-									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
662
-
663
-								}
664
-
665
-								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
666
-									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
667
-								}
668
-
669
-								drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
670
-								if drug.ID == 0 {
671
-									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
672
-									return
673
-								}
674
-
675
-								if prescribingNumberUnit == drug.MinUnit {
676
-									if prescribing_number > drug.Total {
677
-										c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
678
-										//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
679
-										return
680
-									}
681
-								} else {
682
-									if prescribingNumberUnit == drug.MaxUnit {
683
-										num := prescribing_number * float64(drug.MinNumber)
684
-										if num > drug.Total {
685
-											c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
686
-											//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
687
-											return
688
-										}
689
-									}
690
-								}
691
-							}
692
-						}
693
-					}
694
-				}
695
-			}
696
-		}
697
-	}
698
-
699
-	if stockConfig.IsOpen == 1 {
700
-		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
701
-			prescriptions, _ := dataBody["prescriptions"].([]interface{})
702
-			if len(prescriptions) > 0 {
703
-				for _, item := range prescriptions {
704
-					items := item.(map[string]interface{})
705
-					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
706
-						projects := items["project"].([]interface{})
707
-						if len(projects) > 0 {
708
-							for _, project := range projects {
709
-								var project_id int64
710
-								var project_type int64
711
-								var totals float64
712
-								if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
713
-									project_id = int64(project.(map[string]interface{})["project_id"].(float64))
714
-								}
715
-								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
716
-									project_type = int64(project.(map[string]interface{})["type"].(float64))
717
-								}
718
-								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
719
-									total, _ := project.(map[string]interface{})["total"].(string)
720
-
721
-									totals, _ = strconv.ParseFloat(total, 64)
722
-								}
723
-								if project_type == 3 {
724
-									good, _ := service.FindGoodInfoByIdTwo(project_id)
725
-									if good.ID == 0 {
726
-										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
727
-										return
728
-									}
729
-									if totals > good.Total {
730
-										c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
731
-										//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
732
-										return
733
-									}
734
-
735
-								}
736
-
737
-							}
738
-						}
739
-					}
740
-				}
741
-			}
742
-		}
743
-
744
-	}
636
+	//_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
637
+	//
638
+	//_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
639
+	//
640
+	//if drugStockConfig.IsOpen == 1 {
641
+	//	//校验库存总量
642
+	//	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
643
+	//		prescriptions, _ := dataBody["prescriptions"].([]interface{})
644
+	//		if len(prescriptions) > 0 {
645
+	//			for _, item := range prescriptions {
646
+	//				items := item.(map[string]interface{})
647
+	//				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
648
+	//					advices := items["advices"].([]interface{})
649
+	//					if len(advices) > 0 {
650
+	//						for _, advice := range advices {
651
+	//							var drug_id int64
652
+	//							var prescribing_number float64
653
+	//							var prescribingNumberUnit string
654
+	//
655
+	//							if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
656
+	//								drug_id = int64(advice.(map[string]interface{})["id"].(float64))
657
+	//							}
658
+	//							if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
659
+	//								//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
660
+	//								prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
661
+	//								prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
662
+	//
663
+	//							}
664
+	//
665
+	//							if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
666
+	//								prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
667
+	//							}
668
+	//
669
+	//							drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
670
+	//							if drug.ID == 0 {
671
+	//								c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
672
+	//								return
673
+	//							}
674
+	//
675
+	//							if prescribingNumberUnit == drug.MinUnit {
676
+	//								if prescribing_number > drug.Total {
677
+	//									c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
678
+	//									//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
679
+	//									return
680
+	//								}
681
+	//							} else {
682
+	//								if prescribingNumberUnit == drug.MaxUnit {
683
+	//									num := prescribing_number * float64(drug.MinNumber)
684
+	//									if num > drug.Total {
685
+	//										c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
686
+	//										//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
687
+	//										return
688
+	//									}
689
+	//								}
690
+	//							}
691
+	//						}
692
+	//					}
693
+	//				}
694
+	//			}
695
+	//		}
696
+	//	}
697
+	//}
698
+	//
699
+	//if stockConfig.IsOpen == 1 {
700
+	//	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
701
+	//		prescriptions, _ := dataBody["prescriptions"].([]interface{})
702
+	//		if len(prescriptions) > 0 {
703
+	//			for _, item := range prescriptions {
704
+	//				items := item.(map[string]interface{})
705
+	//				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
706
+	//					projects := items["project"].([]interface{})
707
+	//					if len(projects) > 0 {
708
+	//						for _, project := range projects {
709
+	//							var project_id int64
710
+	//							var project_type int64
711
+	//							var totals float64
712
+	//							if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
713
+	//								project_id = int64(project.(map[string]interface{})["project_id"].(float64))
714
+	//							}
715
+	//							if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
716
+	//								project_type = int64(project.(map[string]interface{})["type"].(float64))
717
+	//							}
718
+	//							if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
719
+	//								total, _ := project.(map[string]interface{})["total"].(string)
720
+	//
721
+	//								totals, _ = strconv.ParseFloat(total, 64)
722
+	//							}
723
+	//							if project_type == 3 {
724
+	//								good, _ := service.FindGoodInfoByIdTwo(project_id)
725
+	//								if good.ID == 0 {
726
+	//									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
727
+	//									return
728
+	//								}
729
+	//								if totals > good.Total {
730
+	//									c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
731
+	//									//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
732
+	//									return
733
+	//								}
734
+	//
735
+	//							}
736
+	//
737
+	//						}
738
+	//					}
739
+	//				}
740
+	//			}
741
+	//		}
742
+	//	}
743
+	//}
745 744
 
746 745
 	info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
747 746
 	var hpInfo models.HisPrescriptionInfo

+ 5 - 8
controllers/manage_api_controller.go Wyświetl plik

@@ -2300,15 +2300,12 @@ func (this *MachineApiController) EditUser() {
2300 2300
 	id, _ := this.GetInt64("id")
2301 2301
 	fmt.Println("id", id)
2302 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 2309
 	this.ServeSuccessJSON(map[string]interface{}{
2313 2310
 		"device":   device,
2314 2311
 		"patients": patients,

+ 27 - 37
controllers/mobile_api_controllers/dialysis_api_controller.go Wyświetl plik

@@ -1511,7 +1511,7 @@ func (c *DialysisAPIController) Finish() {
1511 1511
 		tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
1512 1512
 
1513 1513
 	}
1514
-	if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 {
1514
+	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 || adminUserInfo.Org.Id == 10243 {
1515 1515
 		evaluation, _ := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, recordDate.Unix())
1516 1516
 		if evaluation.SystolicBloodPressure == 0 {
1517 1517
 			evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
@@ -3650,34 +3650,6 @@ func (c *DialysisAPIController) CreateConsumables() {
3650 3650
 				}
3651 3651
 			}
3652 3652
 
3653
-			//出库
3654
-			//err = service.ConsumablesDeliveryTotal(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
3655
-			//fmt.Println("err", err)
3656
-			////查询今日出库数据
3657
-			//list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
3658
-			//
3659
-			//if len(list) == 0 {
3660
-			//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3661
-			//	return
3662
-			//}
3663
-			//
3664
-			//for _, item := range list {
3665
-			//	prepare := models.DialysisBeforePrepare{
3666
-			//		UserOrgId:  item.OrgId,
3667
-			//		PatientId:  patient_id,
3668
-			//		RecordDate: item.RecordTime,
3669
-			//		GoodId:     item.GoodId,
3670
-			//		GoodTypeId: item.GoodTypeId,
3671
-			//		Count:      item.Count,
3672
-			//		Ctime:      time.Now().Unix(),
3673
-			//		Creater:    adminUser.AdminUser.Id,
3674
-			//		Status:     1,
3675
-			//	}
3676
-			//	//删除准备表数据
3677
-			//	service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
3678
-			//	service.CreateDialysisBeforePrepareOne(&prepare)
3679
-			//}
3680
-
3681 3653
 		}
3682 3654
 	}
3683 3655
 
@@ -3923,7 +3895,6 @@ func (c *DialysisAPIController) EditConsumables() {
3923 3895
 				}
3924 3896
 
3925 3897
 				for _, item := range beforePrepares {
3926
-					fmt.Println("23232323232323为什么99999999999999999999999999999999", item.GoodId)
3927 3898
 
3928 3899
 					//1.查看该患者该耗材型号最后一次出库数量
3929 3900
 					goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
@@ -3948,6 +3919,7 @@ func (c *DialysisAPIController) EditConsumables() {
3948 3919
 
3949 3920
 						//查询该批次剩余库存
3950 3921
 						lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
3922
+						fmt.Println("剩余库存333333333333333", lastInfo)
3951 3923
 						if lastInfo.StockCount == 0 {
3952 3924
 							//查询该耗材的总库存
3953 3925
 							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
@@ -3962,20 +3934,37 @@ func (c *DialysisAPIController) EditConsumables() {
3962 3934
 							}
3963 3935
 
3964 3936
 						}
3937
+
3965 3938
 						//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
3966 3939
 						fmt.Println("剩余库存", lastInfo.StockCount)
3967 3940
 						fmt.Println("差", last_total)
3968
-						if lastInfo.StockCount >= last_total {
3941
+						//查询该耗材的总库存
3942
+						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
3943
+						// 如果库存差大于剩余库存则提示库存不足
3944
+						if last_total > wareinfo.StockCount {
3945
+							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3946
+							c.ServeSuccessJSON(map[string]interface{}{
3947
+								"message":            "1",
3948
+								"good_name":          goodObj.GoodName,
3949
+								"specification_name": goodObj.SpecificationName,
3950
+							})
3951
+							return
3952
+						} else {
3969 3953
 							err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3970 3954
 							break
3971 3955
 						}
3972 3956
 
3973
-						//如果库存不够,则出库到下一个批次
3974
-						if lastInfo.StockCount < last_total {
3975
-
3976
-							err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3977
-							break
3978
-						}
3957
+						//if lastInfo.StockCount >= last_total {
3958
+						//	err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3959
+						//	break
3960
+						//}
3961
+						//
3962
+						////如果库存不够,则出库到下一个批次
3963
+						//if lastInfo.StockCount < last_total {
3964
+						//
3965
+						//	err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
3966
+						//	break
3967
+						//}
3979 3968
 					}
3980 3969
 				}
3981 3970
 
@@ -4914,6 +4903,7 @@ func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int6
4914 4903
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
4915 4904
 	fmt.Println("goods222222222222", goods)
4916 4905
 	fmt.Println("goodsy999999999999", goods_yc)
4906
+
4917 4907
 	if len(goods) > 0 {
4918 4908
 		out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
4919 4909
 		if err == gorm.ErrRecordNotFound {

+ 18 - 32
controllers/mobile_api_controllers/patient_api_controller.go Wyświetl plik

@@ -608,7 +608,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
608 608
 
609 609
 		//自备药信息
610 610
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
611
-		fmt.Println("2323232323232323232开关", drugStockConfig.IsOpen)
611
+
612 612
 		if drugStockConfig.IsOpen == 1 {
613 613
 			if groupno > 0 {
614 614
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
@@ -624,9 +624,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
624 624
 					var prescribing_number_total int64
625 625
 					for _, item := range advices {
626 626
 						if item.Way == 1 {
627
-							//查询该药品是否有库存
627
+							//查询该药品的剩余库存
628 628
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
629
-							fmt.Println("list23232323232232323232323232", list)
629
+
630 630
 							//查询改药品信息
631 631
 							medical, _ := service.GetBaseDrugMedical(item.DrugId)
632 632
 							//判断单位是否相等
@@ -644,8 +644,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
644 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 650
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
651 651
 								c.ServeSuccessJSON(map[string]interface{}{
@@ -686,26 +686,29 @@ func (c *PatientApiController) ExecDoctorAdvice() {
686 686
 						isHasWay = true
687 687
 					}
688 688
 				}
689
-				fmt.Println("hh2h32323232323232323", isHasWay)
689
+
690 690
 				if isHasWay {
691 691
 					var total int64
692 692
 					var prescribing_number_total int64
693 693
 					for _, item := range advices {
694
-						fmt.Println("hhh23h2h3h232323", item.Way)
694
+
695 695
 						if item.Way == 1 {
696
-							//查询该药品是否有库存
696
+							//查询该药品的剩余库存
697 697
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
698 698
 
699 699
 							//查询改药品信息
700 700
 							medical, _ := service.GetBaseDrugMedical(item.DrugId)
701
+
701 702
 							//判断单位是否相等
702 703
 							if medical.MaxUnit == item.PrescribingNumberUnit {
703 704
 								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
704 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 709
 								prescribing_number_total = count * medical.MinNumber
708 710
 							}
711
+
709 712
 							if medical.MinUnit == item.PrescribingNumberUnit {
710 713
 								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
711 714
 								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
@@ -713,8 +716,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
713 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 722
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
720 723
 								c.ServeSuccessJSON(map[string]interface{}{
@@ -732,6 +735,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
732 735
 								})
733 736
 								return
734 737
 							}
738
+
735 739
 							if prescribing_number_total <= total {
736 740
 								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
737 741
 								c.ServeSuccessJSON(map[string]interface{}{
@@ -900,26 +904,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
900 904
 				for _, item := range advices {
901 905
 
902 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 908
 					var total int64
924 909
 					var prescribing_number_total int64
925 910
 					//查询该药品是否有库存
@@ -932,9 +917,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
932 917
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
933 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 921
 						prescribing_number_total = count * medical.MinNumber
937 922
 					}
923
+					fmt.Println("医嘱开的数量", total)
938 924
 					if medical.MinUnit == advice.PrescribingNumberUnit {
939 925
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
940 926
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)

+ 75 - 10
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go Wyświetl plik

@@ -6,6 +6,7 @@ import (
6 6
 	"XT_New/models"
7 7
 	"XT_New/service"
8 8
 	"fmt"
9
+	"github.com/jinzhu/gorm"
9 10
 	"strings"
10 11
 	"time"
11 12
 )
@@ -268,22 +269,36 @@ func (this *StaffScheduleApiController) GetPatientScheduleList() {
268 269
 		}
269 270
 		startTime = theTime.Unix()
270 271
 	}
271
-	fmt.Println("时间搓", startTime)
272 272
 	zoneid, _ := this.GetInt64("zoneid")
273 273
 	fmt.Println(zoneid)
274 274
 	classtype, _ := this.GetInt64("classtype")
275
-	fmt.Println("classtype", classtype)
276 275
 
277
-	//获取当天排班的病人情况
278
-	schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
276
+	is_open, _ := this.GetInt64("is_open")
279 277
 
280
-	if err != nil {
281
-		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
282
-		return
278
+	if is_open == 0 {
279
+		//获取当天排班的病人情况
280
+		schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
281
+
282
+		if err != nil {
283
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
284
+			return
285
+		}
286
+		this.ServeSuccessJSON(map[string]interface{}{
287
+			"schedule": schedule,
288
+		})
289
+	}
290
+	if is_open == 1 {
291
+		//获取空床位的排班数据
292
+		list, err := service.GetPatientScheduleByBed(startTime, zoneid, orgid)
293
+
294
+		if err != nil {
295
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
296
+			return
297
+		}
298
+		this.ServeSuccessJSON(map[string]interface{}{
299
+			"schedule": list,
300
+		})
283 301
 	}
284
-	this.ServeSuccessJSON(map[string]interface{}{
285
-		"schedule": schedule,
286
-	})
287 302
 }
288 303
 
289 304
 func (this *StaffScheduleApiController) DeleteSchedule() {
@@ -352,3 +367,53 @@ func (this *StaffScheduleApiController) UpdatePatientScheduleById() {
352 367
 		"msg": "切换成功",
353 368
 	})
354 369
 }
370
+
371
+func (this *StaffScheduleApiController) UpdateBloodSchedule() {
372
+	timeLayout := "2006-01-02"
373
+	loc, _ := time.LoadLocation("Local")
374
+	id, _ := this.GetInt64("id")
375
+	patient_id, _ := this.GetInt64("patient_id")
376
+	mode_id, _ := this.GetInt64("mode_id")
377
+	schedule_type, _ := this.GetInt64("schedule_type")
378
+	start_time := this.GetString("start_time")
379
+	dialyzer_perfusion_apparatus := this.GetString("dialyzer_perfusion_apparatus")
380
+	var startTime int64
381
+	if len(start_time) > 0 {
382
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
383
+		if err != nil {
384
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
385
+			return
386
+		}
387
+		startTime = theTime.Unix()
388
+	}
389
+
390
+	//更改排班
391
+	schedule := models.XtSchedule{
392
+		ScheduleType: schedule_type,
393
+		ModeId:       mode_id,
394
+	}
395
+
396
+	service.UpdatedSchedule(schedule, id)
397
+
398
+	//更改透析模式
399
+	_, errcode := service.GetDialyisSolution(patient_id, startTime)
400
+	if errcode == gorm.ErrRecordNotFound {
401
+		orgId := this.GetAdminUserInfo().CurrentOrgId
402
+		prescription := models.DialysisPrescription{
403
+			DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus,
404
+			DialysisDialyszers:         dialyzer_perfusion_apparatus,
405
+			PatientId:                  patient_id,
406
+			UserOrgId:                  orgId,
407
+			Status:                     1,
408
+			RecordDate:                 startTime,
409
+			CreatedTime:                time.Now().Unix(),
410
+		}
411
+		service.CreateDialysisPrescription(prescription)
412
+	} else if errcode == nil {
413
+		prescription := models.DialysisPrescription{
414
+			DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus,
415
+			DialysisDialyszers:         dialyzer_perfusion_apparatus,
416
+		}
417
+		service.UpdateDialysisPrescriptionOne(prescription, patient_id, startTime)
418
+	}
419
+}

+ 1 - 0
controllers/new_mobile_api_controllers/staff_schedule_api_router.go Wyświetl plik

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

+ 64 - 70
controllers/patient_api_controller.go Wyświetl plik

@@ -1678,7 +1678,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1678 1678
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1679 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 1682
 					prescribing_number_total = count * medical.MinNumber
1683 1683
 				}
1684 1684
 				if medical.MinUnit == item.PrescribingNumberUnit {
@@ -1715,27 +1715,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1715 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,7 +1798,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1819 1798
 		}
1820 1799
 
1821 1800
 		executionStaff := adminUserInfo.AdminUser.Id
1822
-		// checker := adminUserInfo.AdminUser.Id
1823 1801
 
1824 1802
 		timeLayout := "2006-01-02 15:04:05"
1825 1803
 		loc, _ := time.LoadLocation("Local")
@@ -1879,7 +1857,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1879 1857
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1880 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 1861
 					prescribing_number_total = count * medical.MinNumber
1884 1862
 				}
1885 1863
 				fmt.Println("单位1", medical.MinUnit)
@@ -1889,9 +1867,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1889 1867
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1890 1868
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1891 1869
 					total = list.Count*medical.MinNumber + list.StockMinNumber
1892
-					fmt.Println("23232322323322323233223", total)
1870
+
1893 1871
 					prescribing_number_total = count
1894
-					fmt.Println("7777777777777777", prescribing_number_total)
1872
+
1895 1873
 				}
1896 1874
 
1897 1875
 				fmt.Println("数量一", prescribing_number_total)
@@ -1921,26 +1899,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1921 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 1904
 		c.ServeSuccessJSON(map[string]interface{}{
1946 1905
 			"msg":    "1",
@@ -2491,36 +2450,71 @@ func (c *PatientApiController) GetDoctorAdvices() {
2491 2450
 		theEndtTIme = theTime.Unix()
2492 2451
 	}
2493 2452
 
2494
-	advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
2495
-	advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
2453
+	hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
2496 2454
 
2497
-	if len(advices) > 0 {
2498
-		for _, item := range advices {
2499
-			if item.AdviceDoctor > 0 {
2500
-				operatorIDs = append(operatorIDs, item.AdviceDoctor)
2501
-			}
2502
-			if item.ExecutionStaff > 0 {
2503
-				operatorIDs = append(operatorIDs, item.ExecutionStaff)
2504
-			}
2505
-			if item.Checker > 0 {
2506
-				operatorIDs = append(operatorIDs, item.Checker)
2455
+	if hisconfig.IsOpen == 1 {
2456
+		advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
2457
+		advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
2458
+
2459
+		if len(advices) > 0 {
2460
+			for _, item := range advices {
2461
+				if item.AdviceDoctor > 0 {
2462
+					operatorIDs = append(operatorIDs, item.AdviceDoctor)
2463
+				}
2464
+				if item.ExecutionStaff > 0 {
2465
+					operatorIDs = append(operatorIDs, item.ExecutionStaff)
2466
+				}
2467
+				if item.Checker > 0 {
2468
+					operatorIDs = append(operatorIDs, item.Checker)
2469
+				}
2470
+				if item.StopDoctor > 0 {
2471
+					operatorIDs = append(operatorIDs, item.StopDoctor)
2472
+				}
2507 2473
 			}
2508
-			if item.StopDoctor > 0 {
2509
-				operatorIDs = append(operatorIDs, item.StopDoctor)
2474
+		}
2475
+
2476
+		//相关操作对应的操作人
2477
+		operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
2478
+
2479
+		c.ServeSuccessJSON(map[string]interface{}{
2480
+			"advices":   advices,
2481
+			"operators": operators,
2482
+			"total":     total,
2483
+			"advicetwo": advicestwo,
2484
+		})
2485
+		return
2486
+	} else {
2487
+		advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
2488
+		advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
2489
+
2490
+		if len(advices) > 0 {
2491
+			for _, item := range advices {
2492
+				if item.AdviceDoctor > 0 {
2493
+					operatorIDs = append(operatorIDs, item.AdviceDoctor)
2494
+				}
2495
+				if item.ExecutionStaff > 0 {
2496
+					operatorIDs = append(operatorIDs, item.ExecutionStaff)
2497
+				}
2498
+				if item.Checker > 0 {
2499
+					operatorIDs = append(operatorIDs, item.Checker)
2500
+				}
2501
+				if item.StopDoctor > 0 {
2502
+					operatorIDs = append(operatorIDs, item.StopDoctor)
2503
+				}
2510 2504
 			}
2511 2505
 		}
2512
-	}
2513 2506
 
2514
-	//相关操作对应的操作人
2515
-	operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
2507
+		//相关操作对应的操作人
2508
+		operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
2516 2509
 
2517
-	c.ServeSuccessJSON(map[string]interface{}{
2518
-		"advices":   advices,
2519
-		"operators": operators,
2520
-		"total":     total,
2521
-		"advicetwo": advicestwo,
2522
-	})
2523
-	return
2510
+		c.ServeSuccessJSON(map[string]interface{}{
2511
+			"advices":   advices,
2512
+			"operators": operators,
2513
+			"total":     total,
2514
+			"advicetwo": advicestwo,
2515
+		})
2516
+		return
2517
+	}
2524 2518
 
2525 2519
 }
2526 2520
 

+ 8 - 5
controllers/self_drug_api_congtroller.go Wyświetl plik

@@ -2404,7 +2404,7 @@ func (this *SelfDrugApiController) SaveInventoryList() {
2404 2404
 	fmt.Println(err)
2405 2405
 
2406 2406
 	tableData, _ := dataBody["tableData"].([]interface{})
2407
-	fmt.Println("999939433443", tableData)
2407
+
2408 2408
 	if len(tableData) > 0 {
2409 2409
 		for _, item := range tableData {
2410 2410
 			items := item.(map[string]interface{})
@@ -2489,6 +2489,9 @@ func (this *SelfDrugApiController) SaveInventoryList() {
2489 2489
 				consumable_type = 10
2490 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 2497
 			info := models.DrugWarehouseInfo{
@@ -2571,12 +2574,12 @@ func (this *SelfDrugApiController) SaveInventoryList() {
2571 2574
 				CancelOutDetailId:       0,
2572 2575
 				ExpireDate:              expiry_date,
2573 2576
 				ProductDate:             0,
2574
-				MaxUnit:                 max_unit,
2577
+				MaxUnit:                 min_unit,
2575 2578
 				MinUnit:                 min_unit,
2576 2579
 			}
2577
-
2578
-			service.CreateDrugFlowOne(flow)
2579
-
2580
+			if ord_total != new_total {
2581
+				service.CreateDrugFlowOne(flow)
2582
+			}
2580 2583
 			if err != nil {
2581 2584
 				this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
2582 2585
 				return

+ 422 - 90
controllers/stock_in_api_controller.go Wyświetl plik

@@ -129,7 +129,8 @@ func StockManagerApiRegistRouters() {
129 129
 	beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
130 130
 	beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
131 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 136
 func (c *StockManagerApiController) CreateWarehouse() {
@@ -574,32 +575,8 @@ func (c *StockManagerApiController) EditWarehouse() {
574 575
 					}
575 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 578
 				} else {
602
-					fmt.Println("id23233232323232323232323223", id)
579
+
603 580
 					warehouseInfo := &models.WarehousingInfo{
604 581
 						ID:               id,
605 582
 						WarehousingOrder: warehouse.WarehousingOrder,
@@ -653,27 +630,113 @@ func (c *StockManagerApiController) EditWarehouse() {
653 630
 	var errs error
654 631
 	if len(warehousingInfo) > 0 {
655 632
 		errs = service.CreateWarehousingInfo(warehousingInfo)
656
-		service.CreateStockFlow(stockFlow)
633
+
634
+		for _, its := range warehousingInfo {
635
+			//查询
636
+			info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
637
+			flows := models.VmStockFlow{
638
+				WarehousingOrder:    info.WarehousingOrder,
639
+				WarehousingId:       info.ID,
640
+				GoodId:              info.GoodId,
641
+				Number:              info.Number,
642
+				ProductDate:         info.ProductDate,
643
+				ExpireDate:          info.ExpiryDate,
644
+				Count:               info.WarehousingCount,
645
+				Price:               info.Price,
646
+				Status:              1,
647
+				Ctime:               ctime,
648
+				UserOrgId:           adminUserInfo.CurrentOrgId,
649
+				Manufacturer:        info.Manufacturer,
650
+				Dealer:              info.Dealer,
651
+				LicenseNumber:       info.LicenseNumber,
652
+				IsEdit:              1,
653
+				Creator:             adminUserInfo.AdminUser.Id,
654
+				SystemTime:          ctime,
655
+				ConsumableType:      1,
656
+				WarehousingDetailId: info.ID,
657
+			}
658
+			_, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
659
+
660
+			if errcodescode == gorm.ErrRecordNotFound {
661
+				service.CreateStockFlowOne(flows)
662
+			}
663
+
664
+			//改变库存
665
+			good, _ := service.GetLastInfoMationById(info.GoodId)
666
+			warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
667
+			total, _ := strconv.ParseFloat(warhouseCount, 64)
668
+			goodInfo := models.GoodInfo{
669
+				Total: good.Total + total,
670
+			}
671
+			errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
672
+			fmt.Println(errcodescode)
673
+		}
657 674
 	}
658 675
 
659 676
 	if len(upDateWarehousingInfo) > 0 {
660 677
 
661 678
 		for _, item := range upDateWarehousingInfo {
662
-
663 679
 			var total int64
664
-			var all_total int64
665 680
 			//获取该批次该型号的库存
666 681
 			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 682
 
673
-			item.StockCount = all_total
674
-			fmt.Println("hhhhhhhhhhhhh", item.StockCount)
683
+			//增加库存
684
+			if item.WarehousingCount > info.WarehousingCount {
685
+
686
+				total = item.WarehousingCount - info.WarehousingCount
687
+				goodinfo := models.WarehousingInfo{
688
+					WarehousingCount: item.WarehousingCount,
689
+					StockCount:       info.StockCount + total,
690
+				}
691
+
692
+				service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
693
+				//改变库存
694
+				good, _ := service.GetLastInfoMationById(info.GoodId)
695
+				warhouseCount := strconv.FormatInt(total, 10)
696
+				all_total, _ := strconv.ParseFloat(warhouseCount, 64)
697
+				goodInfo := models.GoodInfo{
698
+					Total: good.Total + all_total,
699
+				}
700
+				service.UpdateGoodInfoMation(info.GoodId, goodInfo)
701
+
702
+			}
703
+
704
+			if item.WarehousingCount < info.WarehousingCount {
705
+
706
+				total = info.WarehousingCount - item.WarehousingCount
707
+				goodinfo := models.WarehousingInfo{
708
+					WarehousingCount: item.WarehousingCount,
709
+					StockCount:       info.StockCount - total,
710
+				}
711
+				service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
712
+				//改变库存
713
+				good, _ := service.GetLastInfoMationById(info.GoodId)
714
+				warhouseCount := strconv.FormatInt(total, 10)
715
+				all_total, _ := strconv.ParseFloat(warhouseCount, 64)
716
+				goodInfo := models.GoodInfo{
717
+					Total: good.Total - all_total,
718
+				}
719
+				service.UpdateGoodInfoMation(info.GoodId, goodInfo)
720
+
721
+			}
722
+
723
+			if item.WarehousingCount == info.WarehousingCount {
724
+				goodinfo := models.WarehousingInfo{
725
+					WarehousingCount: item.WarehousingCount,
726
+					StockCount:       info.StockCount,
727
+					Price:            item.Price,
728
+					Manufacturer:     item.Manufacturer,
729
+					Number:           item.Number,
730
+					ProductDate:      item.ProductDate,
731
+					ExpiryDate:       item.ExpiryDate,
732
+					LicenseNumber:    item.LicenseNumber,
733
+					Dealer:           item.Dealer,
734
+					Remark:           item.Remark,
735
+				}
736
+				service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
737
+				break
738
+			}
675 739
 
676
-			errs = service.UpDateWarehousingInfo(item)
677 740
 		}
678 741
 	}
679 742
 
@@ -1242,14 +1305,13 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1242 1305
 
1243 1306
 	//出库逻辑
1244 1307
 	for _, item := range warehousingOutInfo {
1245
-		//查询库存
1246
-		//warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1247
-		//查询该批次的库存
1248 1308
 
1249
-		warehouseOne, _ := service.FindWarehousingInfoByIdSeven(item.WarehouseInfotId)
1250
-		fmt.Println("数据232323232323232323323232", warehouseOne)
1251
-		fmt.Println("库存查询23322332233232233232322323232323", warehouseOne.StockCount)
1309
+		// 查询该耗材是否有库存
1310
+		warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
1311
+		fmt.Println("hhh2333223223", item.GoodId, item.Count, warehouseOne.StockCount)
1312
+		// 如果出库数量大于该批次剩余库存数量
1252 1313
 		if item.Count > warehouseOne.StockCount {
1314
+
1253 1315
 			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1254 1316
 			c.ServeSuccessJSON(map[string]interface{}{
1255 1317
 				"msg":                "1",
@@ -1258,31 +1320,29 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1258 1320
 			})
1259 1321
 			return
1260 1322
 
1261
-		} else {
1262
-
1263
-			_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1264
-			if errcodes == gorm.ErrRecordNotFound {
1265
-				service.AddSigleWarehouseOut(&warehouseOut)
1266
-			}
1267
-			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
1268
-			if parseDateErr != nil {
1269
-				utils.ErrorLog(parseDateErr.Error())
1270
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1271
-				return
1272
-			}
1273
-
1274
-			c.ServeSuccessJSON(map[string]interface{}{
1275
-				"msg":                "2",
1276
-				"good_name":          "",
1277
-				"specification_name": "",
1278
-			})
1279 1323
 		}
1280
-
1281 1324
 	}
1282 1325
 
1283
-	//errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1284
-	//info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1326
+	for _, it := range warehousingOutInfo {
1327
+		//查询是否生成出库单
1328
+		_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1329
+		if errcodes == gorm.ErrRecordNotFound {
1330
+			service.AddSigleWarehouseOut(&warehouseOut)
1331
+		}
1332
+		//出库逻辑
1333
+		parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), it, &warehouseOut, it.Count, creater)
1334
+		if parseDateErr != nil {
1335
+			utils.ErrorLog(parseDateErr.Error())
1336
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1337
+			return
1338
+		}
1285 1339
 
1340
+		c.ServeSuccessJSON(map[string]interface{}{
1341
+			"msg":                "2",
1342
+			"good_name":          "",
1343
+			"specification_name": "",
1344
+		})
1345
+	}
1286 1346
 }
1287 1347
 func (c *StockManagerApiController) GetWarehouseOutList() {
1288 1348
 	page, _ := c.GetInt64("page", -1)
@@ -1396,7 +1456,6 @@ func (c *StockManagerApiController) GetWarehouseOutInfoList() {
1396 1456
 }
1397 1457
 func (c *StockManagerApiController) EditWarehouseOut() {
1398 1458
 	warehouse_out_time := c.GetString("warehouse_out_time")
1399
-
1400 1459
 	id, _ := c.GetInt64("id", 0)
1401 1460
 	types, _ := c.GetInt64("type", 0)
1402 1461
 
@@ -1592,18 +1651,50 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1592 1651
 		}
1593 1652
 	}
1594 1653
 	var errs error
1654
+	//新增出库
1595 1655
 	if len(warehousingOutInfo) > 0 {
1596 1656
 
1597
-		errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
1657
+		warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
1658
+		if parseDateErr != nil {
1659
+			c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
1660
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1661
+			return
1662
+		}
1663
+		creater := adminUserInfo.AdminUser.Id
1664
+
1665
+		for _, item := range warehousingOutInfo {
1666
+			// 查询该耗材是否有库存
1667
+			warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
1668
+			// 如果出库数量大于该批次剩余库存数量
1669
+			if item.Count > warehouseOne.StockCount {
1670
+				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1671
+				c.ServeSuccessJSON(map[string]interface{}{
1672
+					"msg":                "7",
1673
+					"good_name":          goodObj.GoodName,
1674
+					"specification_name": goodObj.SpecificationName,
1675
+				})
1676
+				return
1677
+
1678
+			} else {
1679
+
1680
+				warehouseOut, _ := service.GetWarehouseById(id)
1681
+
1682
+				//出库逻辑
1683
+				parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
1684
+				if parseDateErr != nil {
1685
+					utils.ErrorLog(parseDateErr.Error())
1686
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1687
+					return
1688
+				}
1689
+			}
1690
+		}
1598 1691
 	}
1599 1692
 
1600 1693
 	if len(upDateWarehouseOutInfos) > 0 {
1601 1694
 		for _, item := range upDateWarehouseOutInfos {
1602 1695
 
1603 1696
 			//1.查询该耗材该批次的最后一次出库记录
1604
-			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
1605
-			fmt.Println("lastGood", lastGood.Count)
1606
-			fmt.Println("item2323232", item.Count)
1697
+			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId)
1607 1698
 
1608 1699
 			// 退库的库存和该耗材该批次最后一次出库数量进行比较
1609 1700
 			//如果退库数量大于 最后一次批次的数量(要么要进行出库)
@@ -1612,7 +1703,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1612 1703
 
1613 1704
 				//查询该耗材是否还有库存
1614 1705
 				warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
1615
-				fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
1706
+
1616 1707
 				//无库存
1617 1708
 				if warehouseinfo.StockCount <= 0 {
1618 1709
 					c.ServeSuccessJSON(map[string]interface{}{
@@ -1628,10 +1719,10 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1628 1719
 					var total_count int64
1629 1720
 					//计算和最后一次出库数据的差
1630 1721
 					total = item.Count - lastGood.Count
1631
-					fmt.Println("total22323232", total)
1722
+
1632 1723
 					//获取该耗材该批次的剩余库存量
1633 1724
 					info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1634
-					fmt.Println("info2232323232323", info)
1725
+
1635 1726
 					//判断该批次的剩余库存 和出库的库存进行比较
1636 1727
 					//如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
1637 1728
 
@@ -1641,12 +1732,20 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1641 1732
 						//清空本批次次库存
1642 1733
 						service.DeleteWarehouseInfo(item.WarehouseInfotId)
1643 1734
 						//调用出库逻辑
1644
-						service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
1735
+						parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
1736
+						if parseDateErr != nil {
1737
+							utils.ErrorLog(errs.Error())
1738
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1739
+							return
1740
+						}
1741
+						c.ServeSuccessJSON(map[string]interface{}{
1742
+							"msg": "1",
1743
+						})
1645 1744
 					}
1646 1745
 					//如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
1647 1746
 					if item.Count <= info.StockCount {
1648 1747
 						stock_cout = lastGood.Count + total
1649
-						fmt.Println("232323223232323232323232", stock_cout)
1748
+						fmt.Println(stock_cout)
1650 1749
 						//扣减库存
1651 1750
 						warehouse := models.WarehousingInfo{
1652 1751
 							StockCount: info.StockCount - total,
@@ -1689,8 +1788,13 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1689 1788
 							c.ServeSuccessJSON(map[string]interface{}{
1690 1789
 								"msg": "1",
1691 1790
 							})
1791
+							return
1692 1792
 						} else if errcode == nil {
1693 1793
 							service.UpDateWarehouseOutInfo(item)
1794
+							c.ServeSuccessJSON(map[string]interface{}{
1795
+								"msg": "1",
1796
+							})
1797
+							return
1694 1798
 						}
1695 1799
 
1696 1800
 					}
@@ -1702,31 +1806,30 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1702 1806
 			var stock_total int64
1703 1807
 			//如果退库数量小于最后一次批次的数量(要么要进行退库)
1704 1808
 			if item.Count < lastGood.Count {
1705
-				fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
1809
+
1706 1810
 				//退库数量和最后一次出库数据进行计算
1707 1811
 				last_count = lastGood.Count - item.Count
1708
-				fmt.Println("last_count", last_count)
1812
+
1709 1813
 				//获取该耗材该批次的剩余库存量
1710 1814
 				infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1711 1815
 
1712 1816
 				//退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
1713 1817
 				all_total = last_count + infoInfo.StockCount
1714
-				fmt.Println("all_total", all_total)
1818
+
1715 1819
 				//如果库存大于总数量,则退回到这个批次
1716
-				fmt.Println("inf232323", infoInfo.WarehousingCount)
1717 1820
 
1718 1821
 				if infoInfo.WarehousingCount > all_total {
1719 1822
 					stock_total = last_count + infoInfo.StockCount
1720
-					fmt.Println("经历323232323232232", last_count, stock_total)
1823
+
1721 1824
 					//退回该批次,计算数量
1722 1825
 					warehousingInfoOne := models.WarehousingInfo{
1723 1826
 						StockCount: stock_total,
1724 1827
 						ID:         item.WarehouseInfotId,
1725 1828
 						OrgId:      item.OrgId,
1726 1829
 					}
1727
-					fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
1830
+
1728 1831
 					parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
1729
-					fmt.Println("parseDateErr2323232322323", parseDateErr)
1832
+					fmt.Println("parseDateErr", parseDateErr)
1730 1833
 					//插入一条新纪录
1731 1834
 					warehouseOutInfoThree := &models.WarehouseOutInfo{
1732 1835
 						WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
@@ -1762,8 +1865,10 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1762 1865
 						c.ServeSuccessJSON(map[string]interface{}{
1763 1866
 							"msg": "1",
1764 1867
 						})
1868
+						return
1765 1869
 					} else if errcode == nil {
1766 1870
 						service.UpDateWarehouseOutInfo(item)
1871
+						return
1767 1872
 					}
1768 1873
 				}
1769 1874
 
@@ -1777,6 +1882,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1777 1882
 			}
1778 1883
 
1779 1884
 			if item.Count == lastGood.Count {
1885
+
1780 1886
 				errs = service.UpDateWarehouseOutInfo(item)
1781 1887
 				if errs != nil {
1782 1888
 					utils.ErrorLog(errs.Error())
@@ -1786,6 +1892,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1786 1892
 				c.ServeSuccessJSON(map[string]interface{}{
1787 1893
 					"msg": "1",
1788 1894
 				})
1895
+				return
1789 1896
 			}
1790 1897
 
1791 1898
 		}
@@ -4357,7 +4464,6 @@ func (this *StockManagerApiController) GetAllStockList() {
4357 4464
 	orgId := adminUserInfo.CurrentOrgId
4358 4465
 
4359 4466
 	list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
4360
-	fmt.Println("耗材总计23323232232323232323", total)
4361 4467
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4362 4468
 	this.ServeSuccessJSON(map[string]interface{}{
4363 4469
 		"list":             list,
@@ -4492,15 +4598,9 @@ func (this *StockManagerApiController) GetOrderDetialByOrderId() {
4492 4598
 	ids := this.GetString("id")
4493 4599
 	idsArray := strings.Split(ids, ",")
4494 4600
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4495
-	order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
4496 4601
 	list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
4497
-	//获取该耗材的最后一条数据
4498
-	info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
4499
-	fmt.Println("info323e2342342342432342342432", info)
4500 4602
 	this.ServeSuccessJSON(map[string]interface{}{
4501
-		"order": order,
4502
-		"list":  list,
4503
-		"info":  info,
4603
+		"list": list,
4504 4604
 	})
4505 4605
 }
4506 4606
 
@@ -5237,13 +5337,17 @@ func (this *StockManagerApiController) GetReportStockList() {
5237 5337
 	orgId := this.GetAdminUserInfo().CurrentOrgId
5238 5338
 	keyword := this.GetString("keyword")
5239 5339
 	fmt.Println("startTime", startTime, "endTime", endTime)
5240
-	list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
5340
+	//list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
5341
+
5342
+	list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit)
5343
+	damageList, _ := service.GetStockDamagedCount(orgId)
5241 5344
 	doctorlist, _ := service.GetAllDoctorThree(orgId)
5242 5345
 
5243 5346
 	this.ServeSuccessJSON(map[string]interface{}{
5244 5347
 		"list":       list,
5245 5348
 		"total":      total,
5246 5349
 		"doctorlist": doctorlist,
5350
+		"damageList": damageList,
5247 5351
 	})
5248 5352
 }
5249 5353
 
@@ -6158,3 +6262,231 @@ func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
6158 6262
 		"list": list,
6159 6263
 	})
6160 6264
 }
6265
+
6266
+func (this *StockManagerApiController) SaveStockInventoryList() {
6267
+
6268
+	dataBody := make(map[string]interface{}, 0)
6269
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
6270
+	fmt.Println(err)
6271
+
6272
+	tableData, _ := dataBody["tableData"].([]interface{})
6273
+
6274
+	if len(tableData) > 0 {
6275
+		for _, item := range tableData {
6276
+			items := item.(map[string]interface{})
6277
+			good_name := items["good_name"].(string)
6278
+			if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
6279
+				utils.ErrorLog("good_name")
6280
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6281
+				return
6282
+			}
6283
+
6284
+			specification_name := items["specification_name"].(string)
6285
+			if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
6286
+				utils.ErrorLog("specification_name")
6287
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6288
+				return
6289
+			}
6290
+
6291
+			warehousing_unit := items["warehousing_unit"].(string)
6292
+			if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
6293
+				utils.ErrorLog("warehousing_unit")
6294
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6295
+				return
6296
+			}
6297
+
6298
+			stock_count := int64(items["stock_count"].(float64))
6299
+			if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
6300
+				utils.ErrorLog("stock_count")
6301
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6302
+				return
6303
+			}
6304
+
6305
+			price := items["price"].(float64)
6306
+			if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
6307
+				utils.ErrorLog("price")
6308
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6309
+				return
6310
+			}
6311
+
6312
+			manufacturer_name := items["manufacturer_name"].(string)
6313
+			if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
6314
+				utils.ErrorLog("manufacturer_name")
6315
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6316
+				return
6317
+			}
6318
+
6319
+			good_id := int64(items["good_id"].(float64))
6320
+			if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
6321
+				utils.ErrorLog("good_id")
6322
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6323
+				return
6324
+			}
6325
+
6326
+			manufacturer := int64(items["manufacturer"].(float64))
6327
+			if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
6328
+				utils.ErrorLog("manufacturer")
6329
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6330
+				return
6331
+			}
6332
+
6333
+			warehousing_order := items["warehousing_order"].(string)
6334
+			if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
6335
+				utils.ErrorLog("warehousing_order")
6336
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6337
+				return
6338
+			}
6339
+
6340
+			number := items["number"].(string)
6341
+			if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
6342
+				utils.ErrorLog("number")
6343
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6344
+				return
6345
+			}
6346
+
6347
+			id := int64(items["id"].(float64))
6348
+			if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
6349
+				utils.ErrorLog("id")
6350
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6351
+				return
6352
+			}
6353
+
6354
+			if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
6355
+				utils.ErrorLog("expiry_date")
6356
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6357
+				return
6358
+			}
6359
+			expiry_date := int64(items["expiry_date"].(float64))
6360
+
6361
+			if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
6362
+				utils.ErrorLog("product_date")
6363
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6364
+				return
6365
+			}
6366
+			product_date := int64(items["product_date"].(float64))
6367
+
6368
+			orgId := this.GetAdminUserInfo().CurrentOrgId
6369
+			adminId := this.GetAdminUserInfo().AdminUser.Id
6370
+
6371
+			stock_type := int64(items["type"].(float64))
6372
+			if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
6373
+				utils.ErrorLog("type")
6374
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6375
+				return
6376
+			}
6377
+
6378
+			last_stock_count := int64(items["last_stock_count"].(float64))
6379
+			if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
6380
+				utils.ErrorLog("last_stock_count")
6381
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6382
+				return
6383
+			}
6384
+			var total_count int64
6385
+			var inventory_type int64
6386
+			fmt.Println("盘点前", stock_count)
6387
+			fmt.Println("盘点后", last_stock_count)
6388
+			if stock_count > last_stock_count {
6389
+				total_count = stock_count - last_stock_count
6390
+				inventory_type = 11
6391
+			}
6392
+			if stock_count < last_stock_count {
6393
+				total_count = last_stock_count - stock_count
6394
+				inventory_type = 10
6395
+			}
6396
+
6397
+			creater := this.GetAdminUserInfo().AdminUser.Id
6398
+			inventory := models.XtStockInventory{
6399
+				GoodName:          good_name,
6400
+				SpecificationName: specification_name,
6401
+				WarehousingUnit:   warehousing_unit,
6402
+				Count:             total_count,
6403
+				BuyPrice:          price,
6404
+				PackingPrice:      price,
6405
+				NewPrice:          0,
6406
+				Manufacturer:      manufacturer_name,
6407
+				Dealer:            "",
6408
+				Remark:            "",
6409
+				GoodId:            good_id,
6410
+				UserOrgId:         orgId,
6411
+				Ctime:             time.Now().Unix(),
6412
+				Mtime:             0,
6413
+				Status:            1,
6414
+				WarehousingOrder:  warehousing_order,
6415
+				LicenseNumber:     number,
6416
+				StartTime:         time.Now().Unix(),
6417
+				Creater:           adminId,
6418
+				Checker:           0,
6419
+				CheckerStatus:     0,
6420
+				CheckerTime:       0,
6421
+				Total:             0,
6422
+				Number:            number,
6423
+				WarehousingInfoId: id,
6424
+				ExpireDate:        expiry_date,
6425
+				ProductDate:       product_date,
6426
+				GoodOriginPlace:   "",
6427
+				Type:              10,
6428
+				InventoryType:     stock_type,
6429
+				LastStockCount:    last_stock_count,
6430
+				StockCount:        stock_count,
6431
+			}
6432
+			service.CreateInentory(inventory)
6433
+
6434
+			stockFlow := models.VmStockFlow{
6435
+				WarehousingId:           0,
6436
+				GoodId:                  good_id,
6437
+				Number:                  number,
6438
+				LicenseNumber:           "",
6439
+				Count:                   total_count,
6440
+				UserOrgId:               orgId,
6441
+				PatientId:               0,
6442
+				SystemTime:              0,
6443
+				ConsumableType:          inventory_type,
6444
+				IsSys:                   0,
6445
+				WarehousingOrder:        "",
6446
+				WarehouseOutId:          0,
6447
+				WarehouseOutOrderNumber: warehousing_order,
6448
+				IsEdit:                  0,
6449
+				CancelStockId:           0,
6450
+				CancelOrderNumber:       "",
6451
+				Manufacturer:            manufacturer,
6452
+				Dealer:                  0,
6453
+				Creator:                 creater,
6454
+				UpdateCreator:           0,
6455
+				Status:                  1,
6456
+				Ctime:                   time.Now().Unix(),
6457
+				Mtime:                   0,
6458
+				Price:                   price,
6459
+				WarehousingDetailId:     0,
6460
+				WarehouseOutDetailId:    0,
6461
+				CancelOutDetailId:       0,
6462
+				ProductDate:             product_date,
6463
+				ExpireDate:              expiry_date,
6464
+				ReturnCount:             0,
6465
+			}
6466
+
6467
+			info := models.WarehousingInfo{
6468
+				StockCount: last_stock_count,
6469
+			}
6470
+			//更改库存
6471
+			service.UpdatedWarehousingInfo(info, id)
6472
+			if stock_count != last_stock_count {
6473
+				service.CreateStockFlowOne(stockFlow)
6474
+			}
6475
+			this.ServeSuccessJSON(map[string]interface{}{
6476
+				"inventory": inventory,
6477
+			})
6478
+		}
6479
+	}
6480
+}
6481
+
6482
+func (this *StockManagerApiController) GetDamageDetailByGoodId() {
6483
+
6484
+	good_id, _ := this.GetInt64("good_id")
6485
+	list, _ := service.GetDamageDetailByGoodId(good_id)
6486
+	orgId := this.GetAdminUserInfo().CurrentOrgId
6487
+	damageList, _ := service.GetStockDamagedCount(orgId)
6488
+	this.ServeSuccessJSON(map[string]interface{}{
6489
+		"list":       list,
6490
+		"damageList": damageList,
6491
+	})
6492
+}

+ 52 - 0
models/device_models.go Wyświetl plik

@@ -1054,3 +1054,55 @@ type VmXtSchedule struct {
1054 1054
 	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
1055 1055
 	Count        int64
1056 1056
 }
1057
+
1058
+type PatientDeviceNumber struct {
1059
+	ID       int64           `gorm:"column:id" json:"id" form:"id"`
1060
+	OrgId    int64           `gorm:"column:org_id" json:"org_id" form:"org_id"`
1061
+	Number   string          `gorm:"column:number" json:"number" form:"number"`
1062
+	GroupId  int64           `gorm:"column:group_id" json:"group_id" form:"group_id"`
1063
+	ZoneId   int64           `gorm:"column:zone_id" json:"zone_id" form:"zone_id"`
1064
+	Status   int64           `gorm:"column:status" json:"status" form:"status"`
1065
+	Ctime    int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
1066
+	Mtime    int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
1067
+	Sort     int64           `gorm:"column:sort" json:"sort" form:"sort"`
1068
+	Schedule []*BlodSchedule `json:"schedule" gorm:"foreignkey:BedId;AssociationForeignKey:ID;"`
1069
+}
1070
+
1071
+func (PatientDeviceNumber) TableName() string {
1072
+
1073
+	return "xt_device_number"
1074
+}
1075
+
1076
+type PatientDialysisOrder struct {
1077
+	ID                     int64  `gorm:"column:id" json:"id" form:"id"`
1078
+	DialysisDate           int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
1079
+	UserOrgId              int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1080
+	PatientId              int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1081
+	PrescriptionId         int64  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
1082
+	Stage                  int64  `gorm:"column:stage" json:"stage" form:"stage"`
1083
+	Remark                 string `gorm:"column:remark" json:"remark" form:"remark"`
1084
+	BedId                  int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
1085
+	StartNurse             int64  `gorm:"column:start_nurse" json:"start_nurse" form:"start_nurse"`
1086
+	FinishNurse            int64  `gorm:"column:finish_nurse" json:"finish_nurse" form:"finish_nurse"`
1087
+	Status                 int64  `gorm:"column:status" json:"status" form:"status"`
1088
+	CreatedTime            int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
1089
+	UpdatedTime            int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
1090
+	PunctureNurse          int64  `gorm:"column:puncture_nurse" json:"puncture_nurse" form:"puncture_nurse"`
1091
+	Creator                int64  `gorm:"column:creator" json:"creator" form:"creator"`
1092
+	Modifier               int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
1093
+	FinishCreator          int64  `gorm:"column:finish_creator" json:"finish_creator" form:"finish_creator"`
1094
+	FinishModifier         int64  `gorm:"column:finish_modifier" json:"finish_modifier" form:"finish_modifier"`
1095
+	SchedualType           int64  `gorm:"column:schedual_type" json:"schedual_type" form:"schedual_type"`
1096
+	StartTime              int64  `gorm:"column:start_time" json:"start_time" form:"start_time"`
1097
+	EndTime                int64  `gorm:"column:end_time" json:"end_time" form:"end_time"`
1098
+	WashpipeNurse          int64  `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
1099
+	ChangeNurse            int64  `gorm:"column:change_nurse" json:"change_nurse" form:"change_nurse"`
1100
+	DifficultPunctureNurse int64  `gorm:"column:difficult_puncture_nurse" json:"difficult_puncture_nurse" form:"difficult_puncture_nurse"`
1101
+	NewFistulaNurse        int64  `gorm:"column:new_fistula_nurse" json:"new_fistula_nurse" form:"new_fistula_nurse"`
1102
+	ZoneId                 int64  `gorm:"column:zone_id" json:"zone_id" form:"zone_id"`
1103
+}
1104
+
1105
+func (PatientDialysisOrder) TableName() string {
1106
+
1107
+	return "xt_dialysis_order"
1108
+}

+ 56 - 0
models/dialysis.go Wyświetl plik

@@ -1093,3 +1093,59 @@ type BloodDoctorAdvice struct {
1093 1093
 	DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
1094 1094
 	Total       int64
1095 1095
 }
1096
+
1097
+type HisDoctorAdvice struct {
1098
+	ID                    int64              `gorm:"column:id" json:"id" form:"id"`
1099
+	GroupNo               int64              `gorm:"column:groupno" json:"groupno" form:"groupno"`
1100
+	UserOrgId             int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1101
+	PatientId             int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1102
+	AdviceType            int64              `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
1103
+	AdviceDate            int64              `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
1104
+	StartTime             int64              `gorm:"column:start_time" json:"start_time" form:"start_time"`
1105
+	AdviceName            string             `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
1106
+	AdviceDesc            string             `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
1107
+	ReminderDate          int64              `gorm:"column:reminder_date" json:"reminder_date" form:"reminder_date"`
1108
+	SingleDose            float64            `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
1109
+	SingleDoseUnit        string             `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
1110
+	DrugSpec              float64            `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
1111
+	DrugSpecUnit          string             `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
1112
+	PrescribingNumber     float64            `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
1113
+	PrescribingNumberUnit string             `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
1114
+	DeliveryWay           string             `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
1115
+	ExecutionFrequency    string             `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
1116
+	AdviceDoctor          int64              `gorm:"column:advice_doctor" json:"advice_doctor" form:"advice_doctor"`
1117
+	Status                int64              `gorm:"column:status" json:"status" form:"status"`
1118
+	CreatedTime           int64              `gorm:"column:created_time" json:"created_time" form:"created_time"`
1119
+	UpdatedTime           int64              `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
1120
+	AdviceAffirm          string             `gorm:"column:advice_affirm" json:"advice_affirm" form:"advice_affirm"`
1121
+	Remark                string             `gorm:"column:remark" json:"remark" form:"remark"`
1122
+	StopTime              int64              `gorm:"column:stop_time" json:"stop_time" form:"stop_time"`
1123
+	StopReason            string             `gorm:"column:stop_reason" json:"stop_reason" form:"stop_reason"`
1124
+	StopDoctor            int64              `gorm:"column:stop_doctor" json:"stop_doctor" form:"stop_doctor"`
1125
+	StopState             int64              `gorm:"column:stop_state" json:"stop_state" form:"stop_state"`
1126
+	ParentId              int64              `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
1127
+	ExecutionTime         int64              `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
1128
+	ExecutionStaff        int64              `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
1129
+	ExecutionState        int64              `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
1130
+	Checker               int64              `gorm:"column:checker" json:"checker" form:"checker"`
1131
+	RecordDate            int64              `gorm:"column:record_date" json:"record_date"`
1132
+	DialysisOrderId       int64              `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
1133
+	CheckTime             int64              `gorm:"column:check_time" json:"check_time" form:"check_time"`
1134
+	CheckState            int64              `gorm:"column:check_state" json:"check_state" form:"check_state"`
1135
+	AdviceId              int64              `gorm:"-"`
1136
+	RemindType            int64              `gorm:"column:remind_type" json:"remind_type"`
1137
+	FrequencyType         int64              `gorm:"column:frequency_type" json:"frequency_type"`
1138
+	DayCount              int64              `gorm:"column:day_count" json:"day_count"`
1139
+	WeekDay               string             `gorm:"column:week_day" json:"week_day"`
1140
+	ChildDoctorAdvice     []*HisDoctorAdvice `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"child"`
1141
+	TemplateId            string             `gorm:"column:template_id" json:"template_id"`
1142
+	Modifier              int64              `gorm:"column:modifier" json:"modifier" form:"modifier"`
1143
+	IsCheck               int64              `gorm:"-" json:"is_check" form:"is_check"`
1144
+	Way                   int64              `gorm:"column:way" json:"way" form:"way"`
1145
+	DrugId                int64              `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
1146
+	DrugNameId            int64              `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
1147
+}
1148
+
1149
+func (HisDoctorAdvice) TableName() string {
1150
+	return "his_doctor_advice_info"
1151
+}

+ 1 - 0
models/drug_stock.go Wyświetl plik

@@ -283,6 +283,7 @@ type VmDrugWarehouseInfo struct {
283 283
 	CountUnit      string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
284 284
 	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
285 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 289
 type StDrugWarehouseOutInfo struct {

+ 1 - 0
models/good_models.go Wyświetl plik

@@ -79,6 +79,7 @@ type GoodInfo struct {
79 79
 	Total                       float64              `gorm:"column:total" json:"total" form:"total"`
80 80
 	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"xt_warehouse_info"`
81 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 85
 func (GoodInfo) TableName() string {

+ 92 - 6
models/schedule_models.go Wyświetl plik

@@ -44,12 +44,12 @@ type Schedule struct {
44 44
 	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
45 45
 	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
46 46
 
47
-	Patient       string        `gorm:"-" json:"patient" form:"patient"`
48
-	DeviceZone    DeviceZone    `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
49
-	DeviceNumber  DeviceNumber  `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
50
-	TreatmentMode TreatmentMode `json:"mode" gorm:"foreignkey:ModeId"`
51
-	DialysisOrder DialysisOrder `json:"order" gorm:"foreignkey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
52
-
47
+	Patient                   string               `gorm:"-" json:"patient" form:"patient"`
48
+	DeviceZone                DeviceZone           `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
49
+	DeviceNumber              DeviceNumber         `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
50
+	TreatmentMode             TreatmentMode        `json:"mode" gorm:"foreignkey:ModeId"`
51
+	DialysisOrder             DialysisOrder        `json:"order" gorm:"foreignkey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
52
+	DialysisPrescription      DialysisPrescription `json:"order" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId;"`
53 53
 	PatientInfectiousDiseases []InfectiousDiseases `json:"patient_contagions" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
54 54
 }
55 55
 
@@ -203,3 +203,89 @@ type VmSchedulesRemind struct {
203 203
 func (VmSchedulesRemind) TableName() string {
204 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
+}
236
+
237
+type BlodSchedule struct {
238
+	ID                        int64                     `gorm:"column:id" json:"id" form:"id"`
239
+	UserOrgId                 int64                     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
240
+	PartitionId               int64                     `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
241
+	BedId                     int64                     `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
242
+	PatientId                 int64                     `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
243
+	ScheduleDate              int64                     `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
244
+	ScheduleType              int64                     `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
245
+	ScheduleWeek              int64                     `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
246
+	ModeId                    int64                     `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
247
+	Status                    int64                     `gorm:"column:status" json:"status" form:"status"`
248
+	VmBloodPatients           VmBloodPatients           `json:"patient" gorm:"foreignkey:ID;AssociationForeignKey:PatientId;"`
249
+	BloodDialysisOrder        BloodPatientDialysisOrder `json:"order" gorm:"foreignkey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
250
+	BloodDialysisPrescription BloodDialysisPrescription `json:"prescription" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId;"`
251
+}
252
+
253
+func (BlodSchedule) TableName() string {
254
+	return "xt_schedule"
255
+}
256
+
257
+type BloodPatientDialysisOrder struct {
258
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
259
+	DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
260
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
261
+	Stage        int64 `gorm:"column:stage" json:"stage" form:"stage"`
262
+	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
263
+}
264
+
265
+func (BloodPatientDialysisOrder) TableName() string {
266
+	return "xt_dialysis_order"
267
+}
268
+
269
+type BloodPatientDialysisPrescription struct {
270
+	ID                         int64  `gorm:"column:id" json:"id" form:"id"`
271
+	PatientId                  int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
272
+	MachineType                string `gorm:"column:machine_type" json:"machine_type" form:"machine_type"`
273
+	ModeId                     int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
274
+	DialysisDialyszers         string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
275
+	DialysisIrrigation         string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
276
+	DialyzerPerfusionApparatus string `gorm:"column:dialyzer_perfusion_apparatus" json:"dialyzer_perfusion_apparatus" form:"dialyzer_perfusion_apparatus"`
277
+}
278
+
279
+func (BloodPatientDialysisPrescription) TableName() string {
280
+	return "xt_dialysis_prescription"
281
+}
282
+
283
+type VmBloodPatients struct {
284
+	ID    int64  `gorm:"column:id" json:"id" form:"id"`
285
+	BedId int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
286
+	Name  string `gorm:"column:name" json:"name" form:"name"`
287
+}
288
+
289
+func (VmBloodPatients) TableName() string {
290
+	return "xt_patients"
291
+}

+ 1 - 0
models/self_drug_models.go Wyświetl plik

@@ -670,6 +670,7 @@ type VmDrugWarehouseOutInfo struct {
670 670
 	MinPrice                float64 `json:"min_price"`
671 671
 	DrugName                string  `json:"drug_name"`
672 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 676
 type XtDrugAdjustPrice struct {

+ 19 - 0
models/stock_models.go Wyświetl plik

@@ -986,6 +986,10 @@ type XtStockInventory struct {
986 986
 	ExpireDate        int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
987 987
 	ProductDate       int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
988 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 995
 func (XtStockInventory) TableName() string {
@@ -1022,6 +1026,10 @@ type VmStockInventory struct {
1022 1026
 	Number            string  `gorm:"column:number" json:"number" form:"number"`
1023 1027
 	ExpireDate        int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
1024 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 1035
 type XtStockCorrectRecord struct {
@@ -1104,3 +1112,14 @@ type SgjCancelStockInfo struct {
1104 1112
 	RetailPrice       float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
1105 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 Wyświetl plik

@@ -1179,7 +1179,7 @@ func SaveHisDoctorAdvice(advice *models.HisDoctorAdviceInfo) (err error) {
1179 1179
 
1180 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 and status = 1").Find(&goodinfo).Error
1183 1183
 	return goodinfo, err
1184 1184
 }
1185 1185
 

+ 66 - 0
service/doctor_schedule_service.go Wyświetl plik

@@ -598,6 +598,38 @@ func GetPatientSchedule(startime int64, zoneid int64, classtype int64, orgid int
598 598
 	return schedule, err
599 599
 }
600 600
 
601
+func GetPatientScheduleByBed(schedule_date int64, zoneid int64, orgid int64) (list []*models.PatientDeviceNumber, err error) {
602
+
603
+	db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
604
+	if zoneid > 0 {
605
+		db = db.Where("x.zone_id = ?", zoneid)
606
+	}
607
+	if orgid > 0 {
608
+		db = db.Where("x.org_id = ?", orgid)
609
+	}
610
+	err = db.Select("x.id,x.number,x.sort,x.group_id,x.zone_id,x.sort").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
611
+		return XTReadDB().Model(&models.BlodSchedule{}).Where("status = 1 AND user_org_id = ? and schedule_date = ?", orgid, schedule_date).Preload("VmBloodPatients", "status = 1 and user_org_id = ?", orgid).Preload("BloodDialysisOrder", "status = 1").Preload("BloodDialysisPrescription", "status = 1")
612
+	}).Find(&list).Error
613
+
614
+	return list, err
615
+}
616
+
617
+func GetPatientDialysisOrderDate(shcedule_date int64, class_type int64, orgid int64) (schedule []*models.Schedule, err error) {
618
+
619
+	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
620
+	if shcedule_date > 0 {
621
+		db = db.Where("x.schedule_date = ?", shcedule_date)
622
+	}
623
+	if class_type > 0 {
624
+		db = db.Where("x.schedule_type = ?", class_type)
625
+	}
626
+	if orgid > 0 {
627
+		db = db.Where("x.user_org_id = ?", orgid)
628
+	}
629
+	err = db.Select("x.id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id").Preload("DialysisOrder", "status = 1").Preload("DialysisPrescription", "status = 1").Find(&schedule).Error
630
+	return schedule, err
631
+}
632
+
601 633
 func DeleteSchedule(id int64) error {
602 634
 
603 635
 	schedule := models.XtSchedule{}
@@ -635,3 +667,37 @@ func UpdateStaffScheduleOne(nextid int64, schedule models.WeekSchedule) error {
635 667
 	err := XTWriteDB().Model(&schedule).Where("id = ?", nextid).Updates(map[string]interface{}{"patient_id": schedule.PatientId, "mode_id": schedule.ModeId}).Error
636 668
 	return err
637 669
 }
670
+
671
+func UpdatedSchedule(schedule models.XtSchedule, id int64) error {
672
+
673
+	xtSchedule := models.XtSchedule{}
674
+	err := XTWriteDB().Model(&xtSchedule).Where("id = ? and status =1", id).Updates(map[string]interface{}{"schedule_type": schedule.ScheduleType, "mode_id": schedule.ModeId}).Error
675
+	return err
676
+}
677
+
678
+func GetDialyisSolution(patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
679
+
680
+	prescription := models.DialysisPrescription{}
681
+
682
+	err := XTReadDB().Model(&prescription).Where("patient_id = ? and record_date = ? and status = 1", patientid, recorddate).Find(&prescription).Error
683
+	if err == gorm.ErrRecordNotFound {
684
+		return nil, err
685
+	}
686
+	if err != nil {
687
+		return nil, err
688
+	}
689
+	return &prescription, nil
690
+}
691
+
692
+func CreateDialysisPrescription(prescription models.DialysisPrescription) error {
693
+
694
+	err := XTReadDB().Create(&prescription).Error
695
+
696
+	return err
697
+}
698
+
699
+func UpdateDialysisPrescriptionOne(prescription models.DialysisPrescription, patientid int64, recordate int64) error {
700
+
701
+	err := XTReadDB().Model(&prescription).Where("patient_id = ? and record_date = ? and status = 1", patientid, recordate).Updates(map[string]interface{}{"dialyzers": prescription.Dialyzer, "dialyzer_perfusion_apparatus": prescription.DialyzerPerfusionApparatus}).Error
702
+	return err
703
+}

+ 6 - 6
service/gobal_config_service.go Wyświetl plik

@@ -570,7 +570,7 @@ func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int6
570 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 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 574
 	likeKey := "%" + keyword + "%"
575 575
 	if orgid > 0 {
576 576
 		db = db.Where("org_id = ?", orgid)
@@ -691,7 +691,7 @@ func GetDrugCountList(startime int64, endtime int64, orgid int64) (info []*model
691 691
 }
692 692
 
693 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 696
 	if startime > 0 {
697 697
 		db = db.Where("x.ctime >=?", startime)
@@ -707,7 +707,7 @@ func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models
707 707
 }
708 708
 
709 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 712
 	if startime > 0 {
713 713
 		db = db.Where("x.ctime >=?", startime)
@@ -723,7 +723,7 @@ func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*mo
723 723
 }
724 724
 
725 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 728
 	if startime > 0 {
729 729
 		db = db.Where("x.record_time >=?", startime)
@@ -741,7 +741,7 @@ func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*m
741 741
 
742 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 746
 	if startime > 0 {
747 747
 		db = db.Where("x.ctime >=?", startime)
@@ -784,7 +784,7 @@ func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouse
784 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 788
 	return info, err
789 789
 }
790 790
 

+ 3 - 1
service/his_service.go Wyświetl plik

@@ -593,6 +593,8 @@ type OtherDrugWarehouseInfo struct {
593 593
 	WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
594 594
 	Status           int64 `gorm:"column:status" json:"status" form:"status"`
595 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 600
 func (OtherDrugWarehouseInfo) TableName() string {
@@ -719,7 +721,7 @@ func (BaseDrugLib) TableName() string {
719 721
 }
720 722
 
721 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 725
 	return
724 726
 }
725 727
 

+ 88 - 2
service/patient_service.go Wyświetl plik

@@ -788,7 +788,7 @@ func GetDoctorAdviceListOne(orgID, patientID, advice_type, stop, start, end int6
788 788
 		db = db.Where("x.start_time>=?", start)
789 789
 	}
790 790
 	if end != 0 {
791
-		db = db.Where("start_time<=?", end)
791
+		db = db.Where("x.start_time<=?", end)
792 792
 	}
793 793
 	if len(keywords) > 0 {
794 794
 		likeKey := "%" + keywords + "%"
@@ -831,7 +831,7 @@ func GetDoctorAdviceListTwo(orgID int64, patientID int64, advice_type int64, sto
831 831
 		db = db.Where("x.start_time>=?", start)
832 832
 	}
833 833
 	if end != 0 {
834
-		db = db.Where("start_time<=?", end)
834
+		db = db.Where("x.start_time<=?", end)
835 835
 	}
836 836
 	if len(keywords) > 0 {
837 837
 		likeKey := "%" + keywords + "%"
@@ -1515,3 +1515,89 @@ func UpdateScheduleItemByPatientId(id int64) error {
1515 1515
 	err := XTWriteDB().Model(models.PatientScheduleTemplateItem{}).Where("patient_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
1516 1516
 	return err
1517 1517
 }
1518
+
1519
+func GetDoctorAdviceListThree(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64) (advices []*models.HisDoctorAdvice, total int64, err error) {
1520
+
1521
+	db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
1522
+	table := UserReadDB().Table("sgj_user_admin_role as r")
1523
+	fmt.Print("table", table)
1524
+	if orgID > 0 {
1525
+		db = db.Where("x.user_org_id=?", orgID)
1526
+	}
1527
+	if patientID > 0 {
1528
+		db = db.Where("x.patient_id = ?", patientID)
1529
+	}
1530
+	if advice_type == 1 && advice_type > 0 {
1531
+		db = db.Where("x.advice_type = ?", advice_type)
1532
+	}
1533
+	if advice_type == 3 && advice_type > 0 {
1534
+		db = db.Where("x.advice_type = 2 or x.advice_type = 3")
1535
+	}
1536
+	if advice_type == 4 && advice_type > 0 {
1537
+		db = db.Where("x.advice_type = 4")
1538
+	}
1539
+	if stop == 1 {
1540
+		db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
1541
+	} else if stop == 2 {
1542
+		db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
1543
+	}
1544
+
1545
+	if start != 0 {
1546
+		db = db.Where("x.start_time>=?", start)
1547
+	}
1548
+	if end != 0 {
1549
+		db = db.Where("x.start_time<=?", end)
1550
+	}
1551
+	if len(keywords) > 0 {
1552
+		likeKey := "%" + keywords + "%"
1553
+		db = db.Where("x.advice_name LIKE ?", likeKey)
1554
+	}
1555
+	offset := (page - 1) * limit
1556
+	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
1557
+	fmt.Print("err", err)
1558
+	return
1559
+}
1560
+
1561
+func GetDoctorAdviceListFour(orgID int64, patientID int64, advice_type int64, stop int64, start int64, end int64, keywords string, limit int64, page int64) (advices []*models.HisDoctorAdvice, total int64, err error) {
1562
+
1563
+	db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
1564
+	table := UserReadDB().Table("sgj_user_admin_role as r")
1565
+	fmt.Println(table)
1566
+	if orgID > 0 {
1567
+		db = db.Where("x.user_org_id=?", orgID)
1568
+	}
1569
+	if patientID > 0 {
1570
+		db = db.Where("x.patient_id = ?", patientID)
1571
+	}
1572
+	if advice_type == 1 {
1573
+		db = db.Where("x.advice_type = ?", advice_type)
1574
+	}
1575
+	if advice_type == 3 && advice_type > 0 {
1576
+		db = db.Where("x.advice_type = 2 or x.advice_type = 3")
1577
+	}
1578
+	if advice_type == 4 && advice_type > 0 {
1579
+		db = db.Where("x.advice_type = 4")
1580
+	}
1581
+
1582
+	if stop == 1 {
1583
+		db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
1584
+	} else if stop == 2 {
1585
+		db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
1586
+	}
1587
+
1588
+	if start != 0 {
1589
+		db = db.Where("x.start_time>=?", start)
1590
+	}
1591
+	if end != 0 {
1592
+		db = db.Where("x.start_time<=?", end)
1593
+	}
1594
+	if len(keywords) > 0 {
1595
+		likeKey := "%" + keywords + "%"
1596
+		db = db.Where("x.advice_name LIKE ?", likeKey)
1597
+	}
1598
+	offset := (page - 1) * limit
1599
+	err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&advices).Error
1600
+	fmt.Print("错误是什么", err)
1601
+	return
1602
+
1603
+}

+ 3 - 3
service/schedule_service.go Wyświetl plik

@@ -610,7 +610,7 @@ func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType in
610 610
 	}).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
611 611
 		return db.Where("status =1").Order("id asc")
612 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 614
 	}).Find(&list).Error
615 615
 
616 616
 	return list, err
@@ -795,7 +795,7 @@ func UpdateNewScheduleTemplateStatus(id int64, org_id int64) (err error) {
795 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 800
 	db := readDb.Table("xt_schedule as s ").Where("s.status =1")
801 801
 	if orgID > 0 {
@@ -825,7 +825,7 @@ func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endt
825 825
 		}).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
826 826
 		return db.Where("status = 1").Order("id asc")
827 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 829
 	}).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
830 830
 		return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
831 831
 	}).Preload("HisDoctorAdviceInfo", "status = 1").Joins("JOIN xt_patients as p ON p.id = s.patient_id").

+ 2 - 2
service/self_drug_service.go Wyświetl plik

@@ -1037,10 +1037,10 @@ func GetLastDrugWarehouseOut(orgid int64) (models.DrugWarehouseOut, error) {
1037 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 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 1044
 	return info, err
1045 1045
 }
1046 1046
 

+ 188 - 25
service/stock_service.go Wyświetl plik

@@ -319,7 +319,7 @@ func FindGoodInfoById(id int64) (*models.GoodInfo, error) {
319 319
 }
320 320
 
321 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 323
 	return goodType, err
324 324
 }
325 325
 
@@ -329,7 +329,7 @@ func FindAllGoodTypeOne(org_id int64) (goodType []*models.GoodsType, err error)
329 329
 }
330 330
 
331 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 333
 	return goodInfo, err
334 334
 }
335 335
 
@@ -579,6 +579,20 @@ func CreateDrugFlow(drugflow []*models.DrugFlow) (err error) {
579 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 596
 func GetDrugByWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
583 597
 
584 598
 	info := models.XtDrugWarehouseInfo{}
@@ -599,6 +613,11 @@ func CreateDrugFlowOne(flow models.DrugFlow) error {
599 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 621
 func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err error) {
603 622
 	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
604 623
 
@@ -629,6 +648,12 @@ func FindWarehousingInfoByIdSeven(id int64) (models.WarehousingInfo, error) {
629 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 659
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
@@ -1645,7 +1670,7 @@ func FindAllStockOutList(orgId int64, page int64, limit int64, startTime int64,
1645 1670
 
1646 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 1674
 	if startime > 0 {
1650 1675
 
1651 1676
 		db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
@@ -2903,7 +2928,7 @@ func UpdateGoodsInformation(info *models.GoodInfo, goodName string, goodType int
2903 2928
 
2904 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 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 2933
 	return houseOutInfo, err
2909 2934
 }
@@ -2911,10 +2936,10 @@ func GetCoutWareseOutInfo(startime int64, endtime int64, orgid int64) (houseOutI
2911 2936
 func GetGoodInfomationList(orgid int64, keyword string) (goodInfo []*models.GoodInfo, err error) {
2912 2937
 	key := "%" + keyword + "%"
2913 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 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 2945
 	return goodInfo, err
@@ -2995,7 +3020,7 @@ func EditDrugWarehousingOne(warehouse models.DrugWarehouse, id int64) {
2995 3020
 
2996 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 3024
 	return list, err
3000 3025
 }
3001 3026
 
@@ -3161,7 +3186,7 @@ func GetWarehouseOrderInfoList(orgid int64) (list []*models.WarehousingInfo, err
3161 3186
 
3162 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 3190
 	if len(keywords) > 0 {
3166 3191
 		likekey := "%" + keywords + "%"
3167 3192
 		err = db.Where("(drug_name LIKE ?)", likekey).Find(&drug).Error
@@ -3173,7 +3198,7 @@ func GetSearchDrugList(keywords string, orgid int64) (drug []*models.BaseDrugLib
3173 3198
 
3174 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 3202
 	if len(keywords) > 0 {
3178 3203
 		likekey := "%" + keywords + "%"
3179 3204
 		err = db.Where("(good_name Like ?)", likekey).Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
@@ -3277,7 +3302,7 @@ func GetAllStockList(page int64, limit int64, startime int64, endtime int64, goo
3277 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 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 3307
 	likeKey := "%" + keyword + "%"
3283 3308
 	if len(likeKey) > 0 {
@@ -3364,7 +3389,7 @@ func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, starti
3364 3389
 
3365 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 3393
 	if startime > 0 {
3369 3394
 		db = db.Where("x.ctime >=?", startime)
3370 3395
 	}
@@ -3380,7 +3405,7 @@ func GetStockDrugCount(startime int64, endtime int64, orgid int64) (info []*mode
3380 3405
 }
3381 3406
 
3382 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 3409
 	if startime > 0 {
3385 3410
 		db = db.Where("x.ctime >=?", startime)
3386 3411
 	}
@@ -3398,7 +3423,7 @@ func GetAutoDiallysisBefor(startime int64, endtime int64, orgid int64) (info []*
3398 3423
 func GetOutStockTotalCountFour(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
3399 3424
 
3400 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 3428
 	if endtime == 0 {
3404 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,7 +3444,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
3419 3444
 	if orgid > 0 {
3420 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 3448
 	return out, err
3424 3449
 }
3425 3450
 
@@ -3512,8 +3537,8 @@ func GetExprotStockList(orgid int64, orderid []string, startime int64, endtime i
3512 3537
 
3513 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 3542
 	fmt.Println(table)
3518 3543
 	if startime > 0 {
3519 3544
 		db = db.Where("x.ctime>=?", startime)
@@ -3685,6 +3710,19 @@ func GetDrugTotalCountOne(drugid int64, orgid int64, id int64) (models.VmDrugWar
3685 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 3726
 func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
3689 3727
 
3690 3728
 	lib := models.BaseDrugLib{}
@@ -3850,13 +3888,13 @@ func UpdateCancelInfo(id int64) (models.CancelStock, error) {
3850 3888
 
3851 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 3892
 	return info, err
3855 3893
 }
3856 3894
 
3857 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 3898
 	return info, err
3861 3899
 }
3862 3900
 
@@ -3927,7 +3965,7 @@ func GetExportOutOrderDrugListOne(warehouse_out_id []string) (out []*models.StDr
3927 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 3970
 	info := models.WarehouseOutInfo{}
3933 3971
 	err := XTReadDB().Where("good_id = ? and warehouse_info_id= ? and status =1", goodid, warehouse_info_id).Last(&info).Error
@@ -3962,7 +4000,7 @@ func UpdateWarehousingInfo(info models.WarehousingInfo, id int64) error {
3962 4000
 }
3963 4001
 
3964 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 4004
 	return info, err
3967 4005
 }
3968 4006
 
@@ -4310,15 +4348,29 @@ func GetLastCancelStockInfo(id int64) (models.DrugCancelStockInfo, error) {
4310 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 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 4368
 	return err
4317 4369
 }
4318 4370
 
4319 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 4374
 	return err
4323 4375
 }
4324 4376
 
@@ -4540,6 +4592,37 @@ func GetReportStockList(startime int64, endtime int64, orgid int64, keyword stri
4540 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 4626
 func UpdateCheckDamage(ids []string, reportPrice models.XtStockReportPrice) error {
4544 4627
 
4545 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,17 +4761,17 @@ func GetInventoryDetailList(keyword string, limit int64, page int64, orgid int64
4678 4761
 
4679 4762
 	likeKey := "%" + keyword + "%"
4680 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 4765
 	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
4683 4766
 	tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
4684 4767
 	fmt.Println(table, tab)
4685 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 4771
 	if orgid > 0 {
4689 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 4775
 	return list, total, err
4693 4776
 }
4694 4777
 
@@ -4777,3 +4860,83 @@ func GetGoodInventoryWarehouseList(id int64) (info []*models.WarehousingInfo, er
4777 4860
 	err = XTReadDB().Model(&info).Where("good_id = ? and status = 1", id).Preload("GoodInfo", "status = 1").Find(&info).Error
4778 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
+}
4937
+
4938
+func UpdateWarehouseInfoByGoodIdOne(info models.WarehousingInfo, id int64) error {
4939
+
4940
+	err := XTWriteDB().Model(&info).Where("id =? and status = 1", id).Updates(map[string]interface{}{"warehousing_count": info.WarehousingCount, "stock_count": info.StockCount, "price": info.Price, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "license_number": info.LicenseNumber, "manufacturer": info.Manufacturer, "dealer": info.Dealer, "remark": info.Remark}).Error
4941
+	return err
4942
+}

+ 3 - 7
service/user_service.go Wyświetl plik

@@ -48,16 +48,14 @@ func GetAllDoctorAndNurse(orgId, appid int64) (doctors []AdminUserList, nurses [
48 48
 }
49 49
 
50 50
 func GetAllAdminUsers(orgId, appid int64) (list []*AdminUserList, err error) {
51
-	//fmt.Println("orgid", orgId)
52
-	//fmt.Println("appid", appid)
51
+
53 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 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 54
 	return
56 55
 }
57 56
 
58 57
 func GetAllAdminUsersTwo(orgId int64) (list []*AdminUserList, err error) {
59
-	//fmt.Println("orgid", orgId)
60
-	//fmt.Println("appid", appid)
58
+
61 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 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 61
 	return
@@ -140,9 +138,7 @@ func GetLastData(orgid int64) (models.SgjPatientDryweight, error) {
140 138
 }
141 139
 
142 140
 func UpdateDialysisPrescription(patientid int64, orgid int64, dryweight float64, prescription models.PredialysisEvaluation) error {
143
-	fmt.Println("patientid", patientid)
144
-	fmt.Println("orgid", orgid)
145
-	fmt.Println("dryweight", dryweight)
141
+
146 142
 	err := XTWriteDB().Model(&prescription).Where("patient_id = ? AND user_org_id = ?", patientid, orgid).Update(map[string]interface{}{"dry_weight": dryweight, "mtime": time.Now().Unix()}).Last(&prescription).Error
147 143
 	fmt.Println("错误是设么", err)
148 144
 	return err

Plik diff jest za duży
+ 859 - 528
service/warhouse_service.go