28169 1 anno fa
parent
commit
0e51c93b63

+ 0 - 1
controllers/his_api_controller.go Vedi File

@@ -4166,7 +4166,6 @@ func (c *HisApiController) CreateHisPrescription() {
4166 4166
 					theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
4167 4167
 					result := strings.Split(preTime, " ")
4168 4168
 					theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
4169
-					fmt.Println("theTime30000000000000000000000", theTime3.Unix())
4170 4169
 					if err != nil {
4171 4170
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4172 4171
 						return

+ 49 - 20
controllers/mobile_api_controllers/patient_api_controller.go Vedi File

@@ -1271,6 +1271,16 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1271 1271
 		return
1272 1272
 	} else if origin == 2 {
1273 1273
 
1274
+		// 开始主事务
1275
+		db := service.XTWriteDB()
1276
+		tx := db.Begin()
1277
+
1278
+		// 在函数结束时处理事务回滚
1279
+		defer func() {
1280
+			if r := recover(); r != nil {
1281
+				tx.Rollback()
1282
+			}
1283
+		}()
1274 1284
 		adminInfo := c.GetMobileAdminUserInfo()
1275 1285
 		creater := c.GetMobileAdminUserInfo().AdminUser.Id
1276 1286
 		var ids []string
@@ -1337,7 +1347,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1337 1347
 
1338 1348
 				}
1339 1349
 			}
1340
-			err = service.SaveHisDoctorAdvice(item)
1350
+
1351
+			//err = service.SaveHisDoctorAdvice(item)
1352
+
1353
+			service.SaveHisDoctorAdviceOne(item, tx)
1341 1354
 
1342 1355
 			//记录日志
1343 1356
 			byterequest, _ := json.Marshal(item)
@@ -1397,14 +1410,14 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1397 1410
 		if drugStockConfig.IsOpen == 1 {
1398 1411
 			for _, item := range advices {
1399 1412
 				//查询改药品信息
1400
-				medical, _ := service.GetBaseDrugMedical(item.DrugId)
1413
+				medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
1401 1414
 
1402 1415
 				//判断单位是否合格
1403 1416
 				if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
1404 1417
 					//查询该药品是否有出库记录
1405
-					flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
1418
+					flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
1406 1419
 					if len(flowMap) == 0 {
1407
-						errs := service.UpdateHisAdviceById(item.ID)
1420
+						errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
1408 1421
 						if errs != nil {
1409 1422
 							drugError := models.XtDrugError{
1410 1423
 								UserOrgId:             adminInfo.Org.Id,
@@ -1422,7 +1435,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1422 1435
 							service.CreateDrugError(drugError)
1423 1436
 						}
1424 1437
 					}
1425
-					advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
1438
+					advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
1439
+					tx.Commit()
1426 1440
 					c.ServeSuccessJSON(map[string]interface{}{
1427 1441
 						"msg":    "7",
1428 1442
 						"advice": advice,
@@ -1432,8 +1446,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1432 1446
 				}
1433 1447
 
1434 1448
 				//查询这个患者这个患者这个药已经出库的所有数量
1435
-				advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
1436
-				drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
1449
+				advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
1450
+				drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
1437 1451
 				var total_count int64
1438 1452
 				var drug_count int64
1439 1453
 				for _, it := range advicelist {
@@ -1460,8 +1474,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1460 1474
 				}
1461 1475
 
1462 1476
 				if total_count == drug_count {
1463
-
1464
-					advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
1477
+					advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
1478
+					tx.Commit()
1465 1479
 					c.ServeSuccessJSON(map[string]interface{}{
1466 1480
 						"msg":    "1",
1467 1481
 						"advice": advice,
@@ -1470,7 +1484,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1470 1484
 					return
1471 1485
 				}
1472 1486
 
1473
-				advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
1487
+				advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
1474 1488
 
1475 1489
 				var total int64
1476 1490
 				var prescribing_number_total int64
@@ -1480,7 +1494,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1480 1494
 				if config.IsOpen != 1 {
1481 1495
 					//查询该药品是否有库存
1482 1496
 					houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
1483
-					list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
1497
+					list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
1484 1498
 
1485 1499
 					//判断单位是否相等
1486 1500
 					if medical.MaxUnit == advice.PrescribingNumberUnit {
@@ -1540,6 +1554,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1540 1554
 								PrescribingNumberUnit: advice.PrescribingNumberUnit,
1541 1555
 							}
1542 1556
 							service.CreateDrugError(drugError)
1557
+							tx.Commit()
1543 1558
 							c.ServeSuccessJSON(map[string]interface{}{
1544 1559
 								"msg":    "3",
1545 1560
 								"advice": advice,
@@ -1562,6 +1577,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1562 1577
 								PrescribingNumberUnit: advice.PrescribingNumberUnit,
1563 1578
 							}
1564 1579
 							service.CreateDrugError(drugError)
1580
+							tx.Commit()
1565 1581
 							c.ServeSuccessJSON(map[string]interface{}{
1566 1582
 								"msg":    "2",
1567 1583
 								"advice": advice,
@@ -1571,6 +1587,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1571 1587
 						}
1572 1588
 					}
1573 1589
 
1590
+					fmt.Println("hhahhahahahhhhhha", prescribing_number_total)
1591
+					fmt.Println("total0000000000000", total)
1592
+					fmt.Println("medical22222222222222", medical.IsUse)
1593
+					fmt.Println("config.isp", config.IsOpen)
1574 1594
 					if prescribing_number_total <= total {
1575 1595
 
1576 1596
 						pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
@@ -1579,13 +1599,15 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1579 1599
 
1580 1600
 							if config.IsOpen != 1 {
1581 1601
 								if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
1582
-									service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1602
+
1603
+									//service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
1604
+									//service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1583 1605
 
1584 1606
 									if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
1585 1607
 										//查询该药品是否有出库记录
1586
-										flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
1608
+										flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
1587 1609
 										if len(flowMap) == 0 {
1588
-											errs := service.UpdateHisAdviceById(advice.ID)
1610
+											errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
1589 1611
 											if errs != nil {
1590 1612
 												drugError := models.XtDrugError{
1591 1613
 													UserOrgId:             adminInfo.Org.Id,
@@ -1602,6 +1624,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1602 1624
 												}
1603 1625
 												service.CreateDrugError(drugError)
1604 1626
 											}
1627
+											tx.Commit()
1605 1628
 											c.ServeSuccessJSON(map[string]interface{}{
1606 1629
 												"msg":    "6",
1607 1630
 												"advice": advice,
@@ -1613,14 +1636,15 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1613 1636
 								}
1614 1637
 								if pharmacyConfig.IsOpen != 1 {
1615 1638
 
1616
-									service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1639
+									//service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1640
+									service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
1617 1641
 									if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
1618 1642
 										//查询该药品是否有出库记录
1619
-										flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
1643
+										flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
1620 1644
 
1621 1645
 										if len(flowMap) == 0 {
1622 1646
 
1623
-											errs := service.UpdateHisAdviceById(advice.ID)
1647
+											errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
1624 1648
 											if errs != nil {
1625 1649
 												drugError := models.XtDrugError{
1626 1650
 													UserOrgId:             adminInfo.Org.Id,
@@ -1637,18 +1661,20 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1637 1661
 												}
1638 1662
 												service.CreateDrugError(drugError)
1639 1663
 											}
1664
+											tx.Commit()
1640 1665
 											c.ServeSuccessJSON(map[string]interface{}{
1641 1666
 												"msg":    "6",
1642 1667
 												"advice": advice,
1643 1668
 												"ids":    ids,
1644 1669
 											})
1670
+
1645 1671
 											return
1646 1672
 										}
1647 1673
 									}
1648 1674
 								}
1649 1675
 
1650 1676
 								//更新字典里面的库存
1651
-								stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1677
+								stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
1652 1678
 								var sum_count int64
1653 1679
 								for _, its := range stockInfo {
1654 1680
 									if its.MaxUnit == medical.MaxUnit {
@@ -1656,9 +1682,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1656 1682
 									}
1657 1683
 									sum_count += its.StockMaxNumber + its.StockMinNumber
1658 1684
 								}
1659
-								service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
1685
+								service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
1660 1686
 								//剩余库存
1661
-								service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
1687
+								service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
1688
+
1662 1689
 							}
1663 1690
 
1664 1691
 						}
@@ -1687,8 +1714,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1687 1714
 
1688 1715
 			}
1689 1716
 		}
1717
+		tx.Commit()
1690 1718
 		for _, item := range advices {
1691 1719
 			advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
1720
+
1692 1721
 			c.ServeSuccessJSON(map[string]interface{}{
1693 1722
 				"msg":    "1",
1694 1723
 				"advice": advice,

+ 21 - 15
controllers/self_drug_api_congtroller.go Vedi File

@@ -3689,15 +3689,18 @@ func (this *SelfDrugApiController) GetGoodNewPurchaseStockQuery() {
3689 3689
 	}
3690 3690
 	var ids []int64
3691 3691
 	var goodIds []int64
3692
-	infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
3693
-	for _, it := range infoList {
3694
-		goodIds = append(goodIds, it.GoodId)
3695
-	}
3692
+	//infoList, _ := service.GetGoodWarehouseInfoByOrgIdTwo(orgId)
3693
+	//for _, it := range infoList {
3694
+	//	goodIds = append(goodIds, it.GoodId)
3695
+	//}
3696 3696
 
3697
-	manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
3698
-	for _, it := range manufacturers {
3699
-		ids = append(ids, it.ID)
3697
+	if len(keyword) > 0 {
3698
+		manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
3699
+		for _, it := range manufacturers {
3700
+			ids = append(ids, it.ID)
3701
+		}
3700 3702
 	}
3703
+
3701 3704
 	manufacturerList, _ := service.GetNewAllManufacturerList(orgId)
3702 3705
 
3703 3706
 	if orgId == 10265 {
@@ -3909,14 +3912,18 @@ func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
3909 3912
 	var ids []int64
3910 3913
 	var infoIds []int64
3911 3914
 
3912
-	manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
3913
-	for _, it := range manufacturers {
3914
-		ids = append(ids, it.ID)
3915
-	}
3916
-	infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
3917
-	for _, it := range infoList {
3918
-		infoIds = append(infoIds, it.DrugId)
3915
+	if len(keyword) > 0 {
3916
+		manufacturers, _ := service.GetManufacturerListByKeyword(orgId, keyword)
3917
+		for _, it := range manufacturers {
3918
+			ids = append(ids, it.ID)
3919
+		}
3919 3920
 	}
3921
+
3922
+	//infoList, _ := service.GetDrugWarehouseInfoByOrgIdTwo(orgId)
3923
+	//for _, it := range infoList {
3924
+	//	infoIds = append(infoIds, it.DrugId)
3925
+	//}
3926
+
3920 3927
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
3921 3928
 	list, total, err := service.GetDrugNewPurchaseStockQuery(good_type, keyword, page, limit, orgId, startTime, endTime, ids, infoIds)
3922 3929
 
@@ -3940,7 +3947,6 @@ func (this *SelfDrugApiController) GetPurchaseNewDrugQuery() {
3940 3947
 
3941 3948
 		//期中减少
3942 3949
 		outInfo, _ := service.FindeDrugWarehouseOutInfo(item.ID, item.OrgId, startTime, endTime)
3943
-		fmt.Println("putInfo2o2o2oo2o2", outInfo)
3944 3950
 		for _, it := range outInfo {
3945 3951
 			item.DrugWarehouseOutInfoStartEnd = append(item.DrugWarehouseOutInfoStartEnd, it)
3946 3952
 		}

+ 21 - 0
service/dialysis_service.go Vedi File

@@ -1493,6 +1493,17 @@ func FindHisDoctorAdviceById(orgID int64, id int64) (advice models.HisDoctorAdvi
1493 1493
 	return
1494 1494
 }
1495 1495
 
1496
+func FindHisDoctorAdviceByIdTwo(orgID int64, id int64, tx *gorm.DB) (advice models.HisDoctorAdviceInfo, err error) {
1497
+	err = tx.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error
1498
+	if err != gorm.ErrRecordNotFound {
1499
+		if err != nil {
1500
+			tx.Rollback()
1501
+			return
1502
+		}
1503
+	}
1504
+	return
1505
+}
1506
+
1496 1507
 func FindHisDoctorAdviceByIds(orgID int64, ids []string) (advice []*models.HisDoctorAdviceInfo, err error) {
1497 1508
 	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id in (?)", orgID, ids).Find(&advice).Error
1498 1509
 	return
@@ -1503,6 +1514,16 @@ func SaveHisDoctorAdvice(advice *models.HisDoctorAdviceInfo) (err error) {
1503 1514
 	return
1504 1515
 }
1505 1516
 
1517
+func SaveHisDoctorAdviceOne(advice *models.HisDoctorAdviceInfo, tx *gorm.DB) (err error) {
1518
+	err = tx.Save(&advice).Error
1519
+	if err != nil {
1520
+
1521
+		tx.Rollback()
1522
+		return
1523
+	}
1524
+	return
1525
+}
1526
+
1506 1527
 func GetGoodInfoMation(orgid int64) (goodinfo []*models.GoodInfo, err error) {
1507 1528
 
1508 1529
 	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

+ 20 - 7
service/self_drug_service.go Vedi File

@@ -137,6 +137,19 @@ func GetBaseDrugMedical(id int64) (models.XtBaseDrug, error) {
137 137
 	return drug, err
138 138
 }
139 139
 
140
+func GetBaseDrugMedicalOne(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
141
+	drug := models.XtBaseDrug{}
142
+	err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
143
+	if err != gorm.ErrRecordNotFound {
144
+		if err != nil {
145
+			tx.Rollback()
146
+			return drug, err
147
+		}
148
+
149
+	}
150
+	return drug, err
151
+}
152
+
140 153
 func GetNewBaseDrugMedical(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
141 154
 	drug := models.XtBaseDrug{}
142 155
 	err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
@@ -2801,7 +2814,7 @@ func CreateDrugStockCount(stockCount models.XtDrugStockCount) error {
2801 2814
 
2802 2815
 func GetGoodNewPurchaseStockQuery(good_type int64, keyword string, page int64, limit int64, orgid int64, ids []int64, goodIds []int64) (goodinfo []*models.GoodInfoTwenty, total int64, err error) {
2803 2816
 
2804
-	db := XTReadDB().Model(&goodinfo).Where("status = 1 and total_count > 0")
2817
+	db := XTReadDB().Model(&goodinfo).Where("status = 1")
2805 2818
 	offset := (page - 1) * limit
2806 2819
 	likeKey := "%" + keyword + "%"
2807 2820
 	if good_type > 0 {
@@ -2811,9 +2824,9 @@ func GetGoodNewPurchaseStockQuery(good_type int64, keyword string, page int64, l
2811 2824
 	if orgid > 0 {
2812 2825
 		db = db.Where("org_id = ?", orgid)
2813 2826
 	}
2814
-	if len(ids) > 0 {
2815
-		db = db.Where("id in(?)", goodIds)
2816
-	}
2827
+	//if len(ids) > 0 {
2828
+	//	db = db.Where("id in(?)", goodIds)
2829
+	//}
2817 2830
 	if len(keyword) > 0 {
2818 2831
 		db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
2819 2832
 	}
@@ -2887,9 +2900,9 @@ func GetDrugNewPurchaseStockQuery(good_type int64, keyword string, page int64, l
2887 2900
 	if len(keyword) > 0 {
2888 2901
 		db = db.Where("drug_name like ? or manufacturer in(?)", likeKey, ids)
2889 2902
 	}
2890
-	if len(infos) > 0 {
2891
-		db = db.Where("id in(?)", infos)
2892
-	}
2903
+	//if len(infos) > 0 {
2904
+	//	db = db.Where("id in(?)", infos)
2905
+	//}
2893 2906
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&druginfo).Error
2894 2907
 
2895 2908
 	return druginfo, total, err

+ 50 - 7
service/stock_service.go Vedi File

@@ -4841,6 +4841,29 @@ func GetDrugTotalCount(drugid int64, orgid int64, storehouse_id int64) (info mod
4841 4841
 	return info, err
4842 4842
 }
4843 4843
 
4844
+func GetDrugTotalCountTwoTwety(drugid int64, orgid int64, storehouse_id int64, tx *gorm.DB) (info models.VmDrugWarehouseInfo, err error) {
4845
+
4846
+	db := tx.Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1")
4847
+	if drugid > 0 {
4848
+		db = db.Where("x.drug_id = ?", drugid)
4849
+	}
4850
+	if orgid > 0 {
4851
+		db = db.Where("x.org_id = ?", orgid)
4852
+	}
4853
+	if storehouse_id > 0 {
4854
+		db = db.Where("x.storehouse_id = ?", storehouse_id)
4855
+	}
4856
+	err = db.Select("x.drug_id,sum(x.stock_max_number) as count,sum(x.stock_min_number) as stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
4857
+	if err != gorm.ErrRecordNotFound {
4858
+		if err != nil {
4859
+			tx.Rollback()
4860
+			return info, err
4861
+		}
4862
+
4863
+	}
4864
+	return info, err
4865
+}
4866
+
4844 4867
 func GetDrugTotalCountTwenty(drugid int64, orgid int64, storehouse_id int64) (info models.VmDrugWarehouseInfo, err error) {
4845 4868
 
4846 4869
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1 ")
@@ -6948,12 +6971,36 @@ func GetAllHisDoctorAdviceById(drugid int64, patient_id int64, advicedate int64,
6948 6971
 	return advice, err
6949 6972
 }
6950 6973
 
6974
+func GetAllHisDoctorAdviceByIdOne(drugid int64, patient_id int64, advicedate int64, orgid int64, tx *gorm.DB) (advice []*models.HisDoctorAdviceInfo, err error) {
6975
+
6976
+	err = tx.Where("drug_id = ? and patient_id = ? and advice_date = ? and execution_state = 1 and status = 1 and user_org_id = ?", drugid, patient_id, advicedate, orgid).Find(&advice).Error
6977
+	if err != gorm.ErrRecordNotFound {
6978
+		if err != nil {
6979
+			tx.Rollback()
6980
+			return advice, err
6981
+		}
6982
+	}
6983
+	return advice, err
6984
+}
6985
+
6951 6986
 func GetAllDrugFlowById(drugid int64, patient_id int64, advicedate int64, orgid int64) (info []*models.DrugWarehouseOutInfo, err error) {
6952 6987
 
6953 6988
 	err = XTReadDB().Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ? and status = 1", drugid, patient_id, advicedate, orgid).Find(&info).Error
6954 6989
 	return info, err
6955 6990
 }
6956 6991
 
6992
+func GetAllDrugFlowByIdOne(drugid int64, patient_id int64, advicedate int64, orgid int64, tx *gorm.DB) (info []*models.DrugWarehouseOutInfo, err error) {
6993
+
6994
+	err = tx.Where("drug_id = ? and patient_id = ? and sys_record_time = ? and org_id = ? and status = 1", drugid, patient_id, advicedate, orgid).Find(&info).Error
6995
+	if err != gorm.ErrRecordNotFound {
6996
+		if err != nil {
6997
+			tx.Rollback()
6998
+			return info, err
6999
+		}
7000
+	}
7001
+	return info, err
7002
+}
7003
+
6957 7004
 // 耗材加库存
6958 7005
 func ModifyGoodAddInformation(good_id int64, sum_count int64, orgid int64) (models.GoodInfo, error) {
6959 7006
 
@@ -8285,13 +8332,9 @@ func UpdateBaseDrugSumInfo(sum_count int64, drugid int64, orgid int64, sum_in_co
8285 8332
 }
8286 8333
 
8287 8334
 func UpdateBaseDrugSumTwo(drugid int64, sum_count int64, orgid int64) error {
8288
-	ut := writeDb.Begin()
8289
-	err = ut.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
8290
-	if err != nil {
8291
-		ut.Rollback()
8292
-		return err
8293
-	}
8294
-	ut.Commit()
8335
+
8336
+	err = writeDb.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
8337
+
8295 8338
 	return err
8296 8339
 }
8297 8340
 

+ 23 - 17
service/warhouse_service.go Vedi File

@@ -622,22 +622,6 @@ func HisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdvice
622 622
 
623 623
 			BloodHisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit)
624 624
 
625
-			////查询今日出库的数据
626
-			//if orgID == 10188 || orgID == 10217 || orgID == 10344 {
627
-			//	//查询这个患者今日用过的总数量
628
-			//	listDrugFlow, _ := GetDrugFlowByWatch(advice.PatientId, advice.DrugId, advice.AdviceDate, advice.UserOrgId)
629
-			//	for _, item := range listDrugFlow {
630
-			//
631
-			//		outInfor, _ := GetDrugWarehouseOutInfor(item.WarehouseOutDetailId, item.UserOrgId)
632
-			//		if item.MaxUnit == outInfor.CountUnit {
633
-			//			if item.Count != outInfor.Count {
634
-			//				UpdateDrugWarehouseOutInfoById(outInfor.ID, item.Count)
635
-			//			}
636
-			//		}
637
-			//
638
-			//	}
639
-			//}
640
-
641 625
 		} else {
642 626
 			return errors.New("药品信息不存在")
643 627
 		}
@@ -7811,12 +7795,34 @@ func GetDrugFLowByAdviceById(drug_id int64, patient_id int64, user_org_id int64,
7811 7795
 	return outInfo, err
7812 7796
 }
7813 7797
 
7798
+func GetDrugFLowByAdviceByIdOne(drug_id int64, patient_id int64, user_org_id int64, advice_date int64, tx *gorm.DB) (outInfo []*models.DrugWarehouseOutInfo, err error) {
7799
+
7800
+	err = tx.Where("drug_id = ? and patient_id = ? and org_id = ? and sys_record_time = ? and status= 1", drug_id, patient_id, user_org_id, advice_date).Find(&outInfo).Error
7801
+	if err != gorm.ErrRecordNotFound {
7802
+		if err != nil {
7803
+			tx.Rollback()
7804
+			return outInfo, err
7805
+		}
7806
+	}
7807
+	return outInfo, err
7808
+}
7809
+
7814 7810
 func UpdateHisAdviceById(id int64) error {
7815 7811
 
7816 7812
 	err := XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", id).Updates(map[string]interface{}{"execution_time": "", "execution_staff": "", "execution_state": 2}).Error
7817 7813
 	return err
7818 7814
 }
7819 7815
 
7816
+func UpdateHisAdviceByIdOne(id int64, tx *gorm.DB) error {
7817
+
7818
+	err := tx.Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", id).Updates(map[string]interface{}{"execution_time": "", "execution_staff": "", "execution_state": 2}).Error
7819
+	if err != nil {
7820
+		tx.Rollback()
7821
+		return err
7822
+	}
7823
+	return err
7824
+}
7825
+
7820 7826
 func GetAdviceIsOut(advice_id int64, user_org_id int64, patient_id int64, advice_date int64, drug_id int64) (models.DrugWarehouseOutInfo, error) {
7821 7827
 
7822 7828
 	advice := models.DrugWarehouseOutInfo{}
@@ -7884,7 +7890,7 @@ func NewHisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdv
7884 7890
 		drup, _ := FindNewBaseDrugLibRecord(orgID, advice.DrugId, tx)
7885 7891
 		if drup.ID > 0 {
7886 7892
 			prescribingNumber := advice.PrescribingNumber
7887
-
7893
+			fmt.Println(prescribingNumber)
7888 7894
 			NewBloodHisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit, tx)
7889 7895
 
7890 7896
 		} else {