Pārlūkot izejas kodu

11月9日库存管理

XMLWAN 2 gadus atpakaļ
vecāks
revīzija
6a727ad483

+ 1 - 0
models/dialysis.go Parādīt failu

@@ -707,6 +707,7 @@ type MonitoringRecord struct {
707 707
 	MonitoringTime              string  `gorm:"column:monitoring_time" json:"monitoring_time"`
708 708
 	PulseFrequency              float64 `gorm:"column:pulse_frequency" json:"pulse_frequency"`
709 709
 	BreathingRate               string  `gorm:"column:breathing_rate" json:"breathing_rate"`
710
+	BreathingRate               string  `gorm:"column:breathing_rate" json:"breathing_rate"`
710 711
 	SystolicBloodPressure       float64 `gorm:"column:systolic_blood_pressure" json:"systolic_blood_pressure"`
711 712
 	DiastolicBloodPressure      float64 `gorm:"column:diastolic_blood_pressure" json:"diastolic_blood_pressure"`
712 713
 	BloodPressureType           int64   `gorm:"column:blood_pressure_type" json:"blood_pressure_type"`

+ 1 - 0
service/dialysis_service.go Parādīt failu

@@ -132,6 +132,7 @@ func GetTotalDialysisCout(orgid int64, patientid int64) (order []*models.Dialysi
132 132
 func FindDoctorAdviceOrderById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
133 133
 	err = readDb.Model(&models.DoctorAdvice{}).
134 134
 		Where("patient_id = ? and user_org_id=? and status=1 and advice_date = ? and advice_type = 2", patientsId, orgID, recordDate).
135
+		Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientsId, orgID, recordDate).
135 136
 		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno, IF(parent_id > 0, parent_id, id) as advice_order").Order("start_time asc, groupno desc, advice_order desc, id asc").
136 137
 		Find(&patient).Error
137 138
 	return

+ 77 - 0
service/dialysis_solution_service.go Parādīt failu

@@ -0,0 +1,77 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"fmt"
6
+)
7
+
8
+func GetPatientSolutionGroupList(patient_id int64, orgid int64) (solution []*models.DialysisSolution, err error) {
9
+
10
+	err = XTReadDB().Where("patient_id = ? and status = 1 and user_org_id = ?", patient_id, orgid).Group("mode_id").Find(&solution).Error
11
+
12
+	return solution, err
13
+}
14
+
15
+func GetNewPatientSolutionByModeId(patient_id int64, mode_id int64, orgid int64) (models.DialysisSolution, error) {
16
+
17
+	solution := models.DialysisSolution{}
18
+	err := XTReadDB().Where("patient_id = ? and mode_id = ? and user_org_id = ? and status = 1", patient_id, mode_id, orgid).Order("updated_time desc").First(&solution).Error
19
+	return solution, err
20
+}
21
+
22
+func UpdateDialysisSolutionStatus(id int64, mode_id int64, orgid int64, patient_id int64) error {
23
+
24
+	err := XTWriteDB().Model(&models.DialysisSolution{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Update(map[string]interface{}{"solution_status": 1}).Error
25
+
26
+	err = XTWriteDB().Model(&models.DialysisSolution{}).Where("id <> ? and mode_id = ? and user_org_id = ? and status = 1 and patient_id = ?", id, mode_id, orgid, patient_id).Update(map[string]interface{}{"solution_status": 2}).Error
27
+	return err
28
+}
29
+
30
+func UpdateDialysisSolutionStatusTwo(id int64, mode_id int64, orgid int64, patient_id int64) error {
31
+
32
+	err = XTWriteDB().Model(&models.DialysisSolution{}).Where("id <> ? and mode_id = ? and user_org_id = ? and status = 1 and patient_id = ?", id, mode_id, orgid, patient_id).Update(map[string]interface{}{"solution_status": 2}).Error
33
+	return err
34
+}
35
+
36
+func GetLastPatientDialysisSolution(patient_id int64, orgid int64) (models.DialysisSolution, error) {
37
+
38
+	solution := models.DialysisSolution{}
39
+	err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status = 1", patient_id, orgid).Last(&solution).Error
40
+	return solution, err
41
+}
42
+
43
+func GetPatientDialysisSolutionGroupList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64) (schedule []*models.VmBloodSchedule, total int64, err error) {
44
+
45
+	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
46
+	offset := (page - 1) * limit
47
+	if scheduleDate > 0 {
48
+		db = db.Where("schedule_date = ?", scheduleDate)
49
+	}
50
+	if schedule_type > 0 {
51
+		db = db.Where("schedule_type = ?", schedule_type)
52
+	}
53
+	if partition_id > 0 {
54
+		db = db.Where("partition_id = ?", partition_id)
55
+	}
56
+	if orgID > 0 {
57
+		db = db.Where("user_org_id  = ?", orgID)
58
+	}
59
+
60
+	if len(keywords) > 0 {
61
+		keywords = "%" + keywords + "%"
62
+		db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
63
+		err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
64
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
65
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
66
+			Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error
67
+	} else {
68
+		err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
69
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
70
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
71
+			Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error
72
+	}
73
+	fmt.Println("err2332232323233223232332", err)
74
+	fmt.Println("total99999999999999999999", total)
75
+	fmt.Println("scheudle23323233232", schedule)
76
+	return schedule, total, err
77
+}

+ 47 - 4
service/gobal_config_service.go Parādīt failu

@@ -749,9 +749,28 @@ func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64
749 749
 	return list, total, err
750 750
 }
751 751
 
752
-func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
752
+func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64, startime int64, endtime int64, start_first_time int64, end_first_time int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
753 753
 	offset := (page - 1) * limit
754
-	err = XTReadDB().Model(&drug).Where("drug_id = ? and org_id = ? and status = 1 and is_check = 1", drugid, orgid).Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&drug).Error
754
+	db := XTReadDB().Model(&drug).Where("status = 1 and is_check = 1")
755
+	if drugid > 0 {
756
+		db = db.Where("drug_id = ?", drugid)
757
+	}
758
+	if orgid > 0 {
759
+		db = db.Where("org_id = ?", orgid)
760
+	}
761
+	if startime > 0 {
762
+		db = db.Where("ctime >=?", startime)
763
+	}
764
+	if endtime > 0 {
765
+		db = db.Where("ctime <=?", endtime)
766
+	}
767
+	if start_first_time > 0 {
768
+		db = db.Where("expiry_date >=?", start_first_time)
769
+	}
770
+	if end_first_time > 0 {
771
+		db = db.Where("expiry_date <=?", end_first_time)
772
+	}
773
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&drug).Error
755 774
 	return drug, total, err
756 775
 }
757 776
 
@@ -863,13 +882,19 @@ func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouse
863 882
 		db = db.Where("x.org_id = ?", orgid)
864 883
 	}
865 884
 	if id > 0 {
866
-		db = db.Where("x.warehouse_out_id = ?", id)
885
+		db = db.Where("x.warehouse_out_id in(?)", id)
867 886
 	}
868 887
 
869 888
 	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.count_unit,x.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 as total_price,x.retail_total_price,x.storehouse_id,x.stock_count,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,x.admin_user_id,t.dose,t.dose_unit,t.last_price,t.min_price,t.medical_insurance_number,t.retail_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
870 889
 	return info, err
871 890
 }
872 891
 
892
+func GetDrugWarehouseOutDetailSeventy(id int64, org_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
893
+
894
+	err = XTReadDB().Where("warehouse_out_id in(?) and org_id = ? and status =1", id, org_id).Find(&info).Error
895
+	return info, err
896
+}
897
+
873 898
 func GetDrugStockFlowDetail(record_time int64, orgid int64) (drugflow []*models.XtDrugAutomaticReduceDetail, err error) {
874 899
 
875 900
 	err = XTReadDB().Where("record_time = ? and org_id = ? and status = 1", record_time, orgid).Preload("XtBaseDrug", "status = 1").Find(&drugflow).Error
@@ -887,7 +912,7 @@ func GetSingeOrderFlow(id int64, orgid int64) (outInfo []*models.VmDrugWarehouse
887 912
 		db = db.Where("x.warehouse_out_id in(?)", id)
888 913
 	}
889 914
 
890
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.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,t.retail_price,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").Scan(&outInfo).Error
915
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.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,x.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,t.retail_price,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").Scan(&outInfo).Error
891 916
 	return outInfo, err
892 917
 }
893 918
 
@@ -907,6 +932,24 @@ func GetAllSingleDrugDetail(id int64, orgid int64) (outInfo []*models.VmDrugWare
907 932
 	return outInfo, err
908 933
 }
909 934
 
935
+func GetDrugFlowList(id int64, orgid int64) (stockflow []*models.DrugFlow, err error) {
936
+
937
+	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Preload("BaseDrugLib", "org_id = ? and status = 1", orgid).Preload("DrugWarehouseInfoOne", "org_id = ? and status = 1", orgid).Find(&stockflow).Error
938
+	return stockflow, err
939
+}
940
+
941
+func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
942
+
943
+	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
944
+	return drugFlow, err
945
+}
946
+
947
+func GetDrugFlowListGroupByIdOne(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
948
+
949
+	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("batch_number").Find(&drugFlow).Error
950
+	return drugFlow, err
951
+}
952
+
910 953
 func FindDrugStockUserDetailByIdThree(id int64, record_time int64, org_id int64) (user []*DrugAutomaticReduceDetail, err error, total int64) {
911 954
 
912 955
 	db := readDb.Model(&user)

+ 25 - 10
service/manage_center_service.go Parādīt failu

@@ -439,7 +439,6 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
439 439
 	storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
440 440
 	//退库
441 441
 	drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
442
-	fmt.Println("list223323232233223322323323223", len(list))
443 442
 
444 443
 	//如果剩余数量 + 退库数量 < 总入库数量
445 444
 	if len(list) > 0 {
@@ -476,9 +475,6 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
476 475
 				sum_count = druginfo.WarehousingCount
477 476
 			}
478 477
 
479
-			fmt.Println("该批次剩余库存", over_count)
480
-			fmt.Println("该批次退库数量", out_count)
481
-			fmt.Println("该批次总入库数量", sum_count)
482 478
 			if (over_count + out_count) <= sum_count {
483 479
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
484 480
 					fmt.Println("进来1", its.Count)
@@ -487,6 +483,12 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
487 483
 						StockMinNumber: its.Count,
488 484
 					}
489 485
 					UpdateDrugWarehouse(its.WarehouseInfoId, warehouseInfo)
486
+
487
+					//增加退库数量
488
+					AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count)
489
+					//出库数量减少
490
+					UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count)
491
+
490 492
 				}
491 493
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
492 494
 					fmt.Println("进来2", its.Count)
@@ -494,6 +496,11 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
494 496
 						StockMaxNumber: its.Count,
495 497
 					}
496 498
 					UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
499
+
500
+					//增加退库数量
501
+					AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
502
+					//出库数量减少
503
+					UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count*drug.MinNumber)
497 504
 				}
498 505
 
499 506
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
@@ -502,6 +509,10 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
502 509
 						StockMaxNumber: its.Count,
503 510
 					}
504 511
 					UpdateDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
512
+					//增加退库数量
513
+					AddCancelSumCountOne(storeHouseConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
514
+					//出库数量减少
515
+					UpdateSumOutDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, its.Count*drug.MinNumber)
505 516
 				}
506 517
 
507 518
 			}
@@ -566,7 +577,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
566 577
 			}
567 578
 
568 579
 			flow := models.DrugFlow{
569
-				WarehousingId:           0,
580
+				WarehousingId:           info.WarehouseInfoId,
570 581
 				DrugId:                  info.DrugId,
571 582
 				Number:                  "",
572 583
 				BatchNumber:             info.BatchNumber,
@@ -590,7 +601,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
590 601
 				Ctime:                   time.Now().Unix(),
591 602
 				Mtime:                   0,
592 603
 				Price:                   info.Price,
593
-				WarehousingDetailId:     0,
604
+				WarehousingDetailId:     info.WarehouseInfoId,
594 605
 				WarehouseOutDetailId:    0,
595 606
 				CancelOutDetailId:       0,
596 607
 				ExpireDate:              info.ExpiryDate,
@@ -666,7 +677,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
666 677
 			}
667 678
 
668 679
 			flow := models.DrugFlow{
669
-				WarehousingId:           0,
680
+				WarehousingId:           info.WarehouseInfoId,
670 681
 				DrugId:                  info.DrugId,
671 682
 				Number:                  "",
672 683
 				BatchNumber:             info.BatchNumber,
@@ -690,7 +701,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
690 701
 				Ctime:                   time.Now().Unix(),
691 702
 				Mtime:                   0,
692 703
 				Price:                   info.Price,
693
-				WarehousingDetailId:     0,
704
+				WarehousingDetailId:     info.WarehouseInfoId,
694 705
 				WarehouseOutDetailId:    0,
695 706
 				CancelOutDetailId:       0,
696 707
 				ExpireDate:              info.ExpiryDate,
@@ -766,7 +777,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
766 777
 			}
767 778
 
768 779
 			flow := models.DrugFlow{
769
-				WarehousingId:           0,
780
+				WarehousingId:           info.WarehouseInfoId,
770 781
 				DrugId:                  info.DrugId,
771 782
 				Number:                  "",
772 783
 				BatchNumber:             info.BatchNumber,
@@ -790,7 +801,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
790 801
 				Ctime:                   time.Now().Unix(),
791 802
 				Mtime:                   0,
792 803
 				Price:                   info.Price,
793
-				WarehousingDetailId:     0,
804
+				WarehousingDetailId:     info.WarehouseInfoId,
794 805
 				WarehouseOutDetailId:    0,
795 806
 				CancelOutDetailId:       0,
796 807
 				ExpireDate:              info.ExpiryDate,
@@ -817,6 +828,10 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
817 828
 			sum_count_one += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
818 829
 		}
819 830
 		UpdateBaseDrugSumTwo(advice.DrugId, sum_count_one, advice.UserOrgId)
831
+
832
+		//更新库存
833
+		UpdateSumDrug(advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, advice.DrugId, sum_count_one)
834
+
820 835
 	}
821 836
 	return err
822 837
 }

+ 16 - 5
service/mobile_dialysis_service.go Parādīt failu

@@ -764,6 +764,7 @@ func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int
764 764
 	fmt.Println("key23233232323323wi", key)
765 765
 	doctor_advices_str, _ := redis.Get(key).Result()
766 766
 	redis.Set(doctor_advices_str, "", time.Second)
767
+	redis.Set(doctor_advices_str, "", time.Second)
767 768
 	if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
768 769
 
769 770
 		err := readDb.Model(&models.DoctorAdvice{}).
@@ -2707,6 +2708,7 @@ type MDialysisGoodsVM struct {
2707 2708
 	DialysisBeforePrepare     []*DialysisBeforePrepare         `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
2708 2709
 	LastDialysisBeforePrepare []*DialysisBeforePrepare         `gorm:"-" json:"last_good_user_detail"`
2709 2710
 	Project                   []*models.HisPrescriptionProject `gorm:"-" json:"project"`
2711
+	//WarehouseOutInfo          []*models.WarehouseOutInfoSeven   `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
2710 2712
 }
2711 2713
 
2712 2714
 func (MDialysisGoodsVM) TableName() string {
@@ -2771,10 +2773,7 @@ func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64
2771 2773
 	if patient_id != 0 {
2772 2774
 		db = db.Where("patient_id = ?", patient_id)
2773 2775
 	}
2774
-	//db = db.Count(&total)
2775
-	//offset := (page - 1) * limit
2776
-	//
2777
-	//db = db.Offset(offset).Limit(limit)
2776
+
2778 2777
 	err := db.Find(&vms).Error
2779 2778
 
2780 2779
 	return vms, err, total
@@ -2801,6 +2800,12 @@ func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int
2801 2800
 	return
2802 2801
 }
2803 2802
 
2803
+func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
2804
+
2805
+	err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
2806
+	return info, err
2807
+}
2808
+
2804 2809
 func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
2805 2810
 	db := readDb.Model(&models.StockInfo{})
2806 2811
 	db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
@@ -2920,7 +2925,7 @@ func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his
2920 2925
 	his_doctor_advice_str, _ := redis.Get(key).Result()
2921 2926
 	redis.Set(key, "", time.Second)
2922 2927
 	if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2923
-		err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
2928
+		err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Order("created_time asc").Find(&his).Error
2924 2929
 		if err != nil {
2925 2930
 			if err == gorm.ErrRecordNotFound {
2926 2931
 				if len(his) <= 0 {
@@ -4098,3 +4103,9 @@ func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticR
4098 4103
 	err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
4099 4104
 	return auto, err
4100 4105
 }
4106
+
4107
+func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
4108
+
4109
+	err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
4110
+	return outifno, err
4111
+}

+ 340 - 0
service/new_stock_service.go Parādīt failu

@@ -0,0 +1,340 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"github.com/jinzhu/gorm"
6
+)
7
+
8
+func GetGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64) (*models.XtGoodStockCount, error) {
9
+
10
+	goodStock := models.XtGoodStockCount{}
11
+	var err error
12
+	err = XTReadDB().Where("user_org_id = ? and storehouse_id = ? and good_id = ?", user_org_id, storehouse_id, good_id).Find(&goodStock).Error
13
+	if err == gorm.ErrRecordNotFound {
14
+		return nil, err
15
+	}
16
+	if err != nil {
17
+		return nil, err
18
+	}
19
+	return &goodStock, nil
20
+}
21
+
22
+func CreateGoodCount(good models.XtGoodStockCount) error {
23
+
24
+	db := writeDb.Begin()
25
+	err := db.Create(&good).Error
26
+	if err != nil {
27
+		db.Rollback()
28
+		return err
29
+	}
30
+	db.Commit()
31
+	return err
32
+}
33
+
34
+func UpdateGoodStockCount(user_org_id int64, storehouse_id int64, good_id int64, count int64, flush_count int64) error {
35
+
36
+	db := writeDb.Begin()
37
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and good_id  = ? and status = 1", user_org_id, storehouse_id, good_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count + ?", count)).Error
38
+	if err != nil {
39
+		db.Rollback()
40
+		return err
41
+	}
42
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", user_org_id, storehouse_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
43
+	if err != nil {
44
+		db.Rollback()
45
+		return err
46
+	}
47
+	db.Commit()
48
+	return err
49
+}
50
+
51
+func UpdateGoodInCount(count int64, user_org_id int64, good_id int64, storehouse_id int64, flush_count int64) error {
52
+	db := writeDb.Begin()
53
+	err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id  = ? and storehouse_id = ? and status = 1", user_org_id, good_id, storehouse_id).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count - ?", count)).Error
54
+	if err != nil {
55
+		db.Rollback()
56
+		return err
57
+	}
58
+	err = db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and good_id = ? and storehouse_id = ? and status = 1", user_org_id, good_id, storehouse_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
59
+	if err != nil {
60
+		db.Rollback()
61
+		return err
62
+	}
63
+	db.Commit()
64
+	return err
65
+}
66
+
67
+func CreateGoodErrcode(errcode models.XtGoodErrcode) error {
68
+
69
+	db := writeDb.Begin()
70
+	err := db.Create(&errcode).Error
71
+	if err != nil {
72
+		db.Rollback()
73
+		return err
74
+	}
75
+	db.Commit()
76
+	return err
77
+}
78
+
79
+func GetGoodStockList(orgId int64, storehouse_id int64, good_type int64, keyword string, page int64, limit int64, ids []int64) (good []*models.GoodInformation, total int64, err error) {
80
+	offset := (page - 1) * limit
81
+	likeKey := "%" + keyword + "%"
82
+
83
+	db := XTReadDB().Table("xt_good_information as x").Where("x.status = 1 and x.total_count > 0 and x.org_id =?", orgId)
84
+
85
+	if good_type == 2 {
86
+		db = db.Where(" x.total_count<=x.stock_warn_count")
87
+	}
88
+
89
+	if len(keyword) > 0 {
90
+		db = db.Where("good_name like ? or manufacturer in(?)", likeKey, ids)
91
+	}
92
+
93
+	db = db.Preload("XtGoodStockCount", func(db *gorm.DB) *gorm.DB {
94
+		if storehouse_id > 0 {
95
+			db = db.Where("storehouse_id = ?", storehouse_id)
96
+		}
97
+		return db.Where("status = 1 and user_org_id = ?", orgId)
98
+	})
99
+
100
+	db = db.Preload("GoodStockCount", func(db *gorm.DB) *gorm.DB {
101
+		if storehouse_id > 0 {
102
+			db = db.Where("storehouse_id = ?", storehouse_id)
103
+		}
104
+		return db.Where("status = 1 and user_org_id = ?", orgId).Group("good_id,storehouse_id")
105
+	})
106
+
107
+	db = db.Preload("WarehousingInfo", func(db *gorm.DB) *gorm.DB {
108
+		if storehouse_id > 0 {
109
+			db = db.Where("storehouse_id = ?", storehouse_id)
110
+		}
111
+		return db.Where("status = 1 and org_id = ? and is_check = 1", orgId)
112
+	})
113
+
114
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Find(&good).Error
115
+
116
+	return good, total, err
117
+}
118
+
119
+func GetSumGoodList(orgid int64, storehouse_id int64, good_id int64) (info []*models.WarehousingInfo, err error) {
120
+
121
+	err = XTReadDB().Where("org_id = ? and storehouse_id = ? and good_id = ? and status =1  and is_check = 1", orgid, storehouse_id, good_id).Find(&info).Error
122
+	return info, err
123
+}
124
+
125
+func UpdateSumGood(orgid int64, storehouse_id int64, good_id int64, flush_count int64) error {
126
+	db := writeDb.Begin()
127
+	err := db.Model(&models.XtGoodStockCount{}).Where("user_org_id = ? and storehouse_id = ? and good_id = ? and status = 1", orgid, storehouse_id, good_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
128
+	if err != nil {
129
+		db.Rollback()
130
+		return err
131
+	}
132
+	db.Commit()
133
+	return err
134
+}
135
+
136
+func UpdateSumCount(user_org_id int64, storehouse_id int64, good_id int64, count int64) error {
137
+	ut := XTWriteDB().Begin()
138
+
139
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
140
+	if err != nil {
141
+		ut.Rollback()
142
+		return err
143
+	}
144
+	ut.Commit()
145
+	return err
146
+}
147
+
148
+func GetSendGoodInformation(org_id int64) (info []*models.WarehousingInfo, err error) {
149
+
150
+	err = XTReadDB().Where("org_id = ? and is_check = 1 and status = 1", org_id).Find(&info).Error
151
+	return info, err
152
+}
153
+
154
+func GetStockFlush(storehouse_id int64, good_id int64, orgid int64) (*models.XtGoodStockCount, error) {
155
+
156
+	stockCount := models.XtGoodStockCount{}
157
+	var err error
158
+	err = XTReadDB().Where("storehouse_id  =? and good_id = ? and user_org_id = ?", storehouse_id, good_id, orgid).Find(&stockCount).Error
159
+	if err == gorm.ErrRecordNotFound {
160
+		return nil, err
161
+	}
162
+	if err != nil {
163
+		return nil, err
164
+	}
165
+	return &stockCount, nil
166
+}
167
+
168
+func CreateGoodCountSix(good models.XtGoodStockCount) error {
169
+
170
+	err := XTWriteDB().Create(&good).Error
171
+	return err
172
+}
173
+
174
+func UpdateGoodCount(warehousingCount int64, stock_count int64, out_count int64, storehouse_id int64, good_id int64, orgid int64, cancel_count int64, act_count int64) error {
175
+
176
+	err := XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).UpdateColumn("stock_in_count", gorm.Expr("stock_in_count+?", warehousingCount)).Error
177
+	err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_out_count": out_count}).Error
178
+	err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).UpdateColumn("flush_count", gorm.Expr("flush_count + ?", stock_count)).Error
179
+	err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_cancel_count": cancel_count}).Error
180
+	err = XTWriteDB().Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and good_id = ? and status =1 and user_org_id = ?", storehouse_id, good_id, orgid).Update(map[string]interface{}{"stock_act_out_count": act_count}).Error
181
+	return err
182
+}
183
+
184
+func GetAllCancelCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
185
+
186
+	err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 4 or consumable_type= 7) and status = 1", storehouse_id, good_id, org_id).Find(&flow).Error
187
+	return flow, err
188
+}
189
+
190
+func GetAllStockOutCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
191
+
192
+	err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 2 or consumable_type= 3) and is_read = 0", storehouse_id, good_id, org_id).Find(&flow).Error
193
+	return flow, err
194
+}
195
+
196
+func GetActStockOutCount(storehouse_id int64, good_id int64, org_id int64) (flow []*models.VmStockFlow, err error) {
197
+	err = XTReadDB().Where("storehouse_id = ? and good_id = ? and user_org_id = ? and (consumable_type = 2 or consumable_type= 3) and status = 1", storehouse_id, good_id, org_id).Find(&flow).Error
198
+	return flow, err
199
+}
200
+
201
+func GetDrugStockCount(storehouse_id int64, drug_id int64, org_id int64) (*models.XtDrugStockCount, error) {
202
+	drugStockCount := models.XtDrugStockCount{}
203
+	var err error
204
+	err = XTReadDB().Where("storehouse_id = ? and drug_id = ? and user_org_id  = ? and status = 1", storehouse_id, drug_id, org_id).Find(&drugStockCount).Error
205
+	if err == gorm.ErrRecordNotFound {
206
+		return nil, err
207
+	}
208
+	if err != nil {
209
+		return nil, err
210
+	}
211
+	return &drugStockCount, nil
212
+}
213
+
214
+func CreateDrugStockSum(drug models.XtDrugStockCount) error {
215
+
216
+	ut := XTWriteDB().Begin()
217
+	err := ut.Create(&drug).Error
218
+	if err != nil {
219
+		ut.Rollback()
220
+		return err
221
+	}
222
+	ut.Commit()
223
+	return err
224
+}
225
+
226
+func AddDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
227
+
228
+	db := writeDb.Begin()
229
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id  = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count + ?", waresing_count)).Error
230
+	if err != nil {
231
+		db.Rollback()
232
+		return err
233
+	}
234
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
235
+	if err != nil {
236
+		db.Rollback()
237
+		return err
238
+	}
239
+	db.Commit()
240
+	return err
241
+}
242
+
243
+func UpdateDrugStockSum(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
244
+	db := writeDb.Begin()
245
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id  = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"sum_in_count": waresing_count}).Error
246
+	if err != nil {
247
+		db.Rollback()
248
+		return err
249
+	}
250
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
251
+	if err != nil {
252
+		db.Rollback()
253
+		return err
254
+	}
255
+	db.Commit()
256
+	return err
257
+}
258
+
259
+func ReduceDrugStockCount(storehouse_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64) error {
260
+	db := writeDb.Begin()
261
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", waresing_count)).Error
262
+	if err != nil {
263
+		db.Rollback()
264
+		return err
265
+	}
266
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
267
+	if err != nil {
268
+		db.Rollback()
269
+		return err
270
+	}
271
+	db.Commit()
272
+	return err
273
+}
274
+
275
+func AddCancelSumCount(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, over_count int64) error {
276
+
277
+	db := writeDb.Begin()
278
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
279
+	if err != nil {
280
+		db.Rollback()
281
+		return err
282
+	}
283
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
284
+	if err != nil {
285
+		db.Rollback()
286
+		return err
287
+	}
288
+	db.Commit()
289
+	return err
290
+}
291
+
292
+func AddCancelSumCountOne(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64) error {
293
+
294
+	db := writeDb.Begin()
295
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
296
+	if err != nil {
297
+		db.Rollback()
298
+		return err
299
+	}
300
+	db.Commit()
301
+	return err
302
+}
303
+
304
+func ReduceCancelSumCount(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, over_count int64) error {
305
+	db := writeDb.Begin()
306
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count - ?", cancel_count)).Error
307
+	if err != nil {
308
+		db.Rollback()
309
+		return err
310
+	}
311
+	err = db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
312
+	if err != nil {
313
+		db.Rollback()
314
+		return err
315
+	}
316
+	db.Commit()
317
+	return err
318
+}
319
+
320
+func UpdateSumDrug(orgid int64, storehouse_id int64, drug_id int64, flush_count int64) error {
321
+	db := writeDb.Begin()
322
+	err := db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", orgid, storehouse_id, drug_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
323
+	if err != nil {
324
+		db.Rollback()
325
+		return err
326
+	}
327
+	db.Commit()
328
+	return err
329
+}
330
+
331
+func UpdateSumOutDrug(orgid int64, storehouse_id int64, drug_id int64, sum_out_count int64) error {
332
+	db := writeDb.Begin()
333
+	err := db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", orgid, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", sum_out_count)).Error
334
+	if err != nil {
335
+		db.Rollback()
336
+		return err
337
+	}
338
+	db.Commit()
339
+	return err
340
+}

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2005 - 0
service/new_warehouse_service.go


+ 31 - 0
service/patient_service.go Parādīt failu

@@ -2636,3 +2636,34 @@ func GetAllHisProjectPrescription(orgid int64, recorddate int64) (project []*mod
2636 2636
 	err = XTReadDB().Where("user_org_id = ? and record_date = ? and status = 1", orgid, recorddate).Find(&project).Error
2637 2637
 	return project, err
2638 2638
 }
2639
+
2640
+func GetPatientDialysisLongSolution(patient_id int64, page int64, limit int64, orgid int64) (solution []*models.DialysisSolution, total int64, err error) {
2641
+
2642
+	db := XTReadDB().Model(&solution).Where("status = 1 and solution_status = 1")
2643
+	if patient_id > 0 {
2644
+		db = db.Where("patient_id = ?", patient_id)
2645
+	}
2646
+	if orgid > 0 {
2647
+		db = db.Where("user_org_id = ?", orgid)
2648
+	}
2649
+	offset := (page - 1) * limit
2650
+
2651
+	err = db.Group("mode_id").Count(&total).Offset(offset).Limit(limit).Order("created_time desc").Find(&solution).Error
2652
+	return solution, total, err
2653
+}
2654
+
2655
+func GetDialysisSolutionDetailList(orgid int64, patient_id int64, mode_id int64, page int64, limit int64) (solution []*models.DialysisSolution, total int64, err error) {
2656
+	offset := (page - 1) * limit
2657
+	db := XTReadDB().Model(&solution).Where("status = 1")
2658
+	if orgid > 0 {
2659
+		db = db.Where("user_org_id = ?", orgid)
2660
+	}
2661
+	if patient_id > 0 {
2662
+		db = db.Where("patient_id = ?", patient_id)
2663
+	}
2664
+	if mode_id > 0 {
2665
+		db = db.Where("mode_id = ?", mode_id)
2666
+	}
2667
+	err = db.Count(&total).Offset(offset).Limit(limit).Find(&solution).Order("created_time desc").Error
2668
+	return solution, total, err
2669
+}

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1167 - 80
service/self_drug_service.go


+ 307 - 62
service/stock_service.go Parādīt failu

@@ -734,8 +734,13 @@ func UpdateDrugWarehouseingInfo(id int64, info models.XtDrugWarehouseInfo) error
734 734
 }
735 735
 
736 736
 func CreateDrugFlowOne(flow models.DrugFlow) error {
737
-
738
-	err := XTWriteDB().Create(&flow).Error
737
+	ut := writeDb.Begin()
738
+	err := ut.Create(&flow).Error
739
+	if err != nil {
740
+		ut.Rollback()
741
+		return err
742
+	}
743
+	ut.Commit()
739 744
 	return err
740 745
 }
741 746
 
@@ -748,7 +753,7 @@ func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice
748 753
 
749 754
 func UpdateDrugFlowTens(patientid int64, warehouse_out_number string, drug_id int64, advice_id int64) (models.DrugFlow, error) {
750 755
 	flow := models.DrugFlow{}
751
-	err := XTWriteDB().Model(&flow).Where("patient_id =? and warehouse_out_order_number = ? and drug_id = ? and status = 1 and advice_id =?", patientid, warehouse_out_number, drug_id, advice_id).Updates(map[string]interface{}{"status": 0}).Error
756
+	err := XTWriteDB().Model(&flow).Where("patient_id =? and warehouse_out_order_number = ? and drug_id = ? and status = 1 and advice_id =?", patientid, warehouse_out_number, drug_id, advice_id).Updates(map[string]interface{}{"is_read": 1}).Error
752 757
 	return flow, err
753 758
 }
754 759
 
@@ -3179,7 +3184,7 @@ func GetStockInRecoredByGoodIdOne(goodid int64, goodtypeid int64, recordtime int
3179 3184
 
3180 3185
 func UpdateAutoMaticReduceDetail(goodid int64, goodtypeid int64, recordtime int64, patientid int64, orgid int64, prepare *models.WarehouseOutInfo) error {
3181 3186
 
3182
-	err := XTWriteDB().Model(&prepare).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and patient_id = ? and org_id = ? and status =1", goodid, goodtypeid, recordtime, patientid, orgid).Updates(map[string]interface{}{"count": prepare.Count}).Error
3187
+	err := XTWriteDB().Model(&prepare).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and patient_id = ? and org_id = ? and status =1", goodid, goodtypeid, recordtime, patientid, orgid).Updates(map[string]interface{}{"count": prepare.Count, "over_count": prepare.OverCount}).Error
3183 3188
 	return err
3184 3189
 }
3185 3190
 
@@ -3837,6 +3842,12 @@ func GetAutoMaticReduceDetail(orgid int64, patient_id int64, recordtime int64, g
3837 3842
 	return &autoreduece, nil
3838 3843
 }
3839 3844
 
3845
+func GetAutoMaticReduceDetailTwenty(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) (models.BloodAutomaticReduceDetail, error) {
3846
+	auto := models.BloodAutomaticReduceDetail{}
3847
+	err = XTReadDB().Model(&auto).Where("org_id = ? and patient_id = ?  and status = 1 and record_time = ? and good_id = ? and good_type_id = ? and count>0", orgid, patient_id, recordtime, goodid, goodtypeid).Find(&auto).Error
3848
+	return auto, err
3849
+}
3850
+
3840 3851
 func DeleteAutoRedeceDetailTwo(orgid int64, patient_id int64, recordtime int64, goodid int64, goodtypeid int64) error {
3841 3852
 
3842 3853
 	detail := models.BloodAutomaticReduceDetail{}
@@ -3850,6 +3861,16 @@ func GetWarehosueOutByStockFlow(patient_id int64, recrod_date int64, goodid int6
3850 3861
 	return stockflow, err
3851 3862
 }
3852 3863
 
3864
+func UpdateAutoGood(orgid int64, patient_id int64, recordtime int64, goodid int64, project_id int64, count int64) (err error) {
3865
+
3866
+	err = XTWriteDB().Model(models.BloodAutomaticReduceDetail{}).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ?", orgid, patient_id, recordtime, goodid).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
3867
+	err = XTWriteDB().Model(models.WarehouseOutInfo{}).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
3868
+	//err = XTWriteDB().Model(models.WarehouseOutInfo{}).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).UpdateColumn("over_count", gorm.Expr("over_count + ?", count)).Error
3869
+	err = XTWriteDB().Model(&models.DialysisBeforePrepare{}).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
3870
+	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
3871
+	return err
3872
+}
3873
+
3853 3874
 func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64) error {
3854 3875
 
3855 3876
 	detail := models.BloodAutomaticReduceDetail{}
@@ -3859,14 +3880,15 @@ func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64,
3859 3880
 	prepare := models.DialysisBeforePrepare{}
3860 3881
 	err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3861 3882
 	flow := models.VmStockFlow{}
3862
-	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3883
+	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"is_read": 1}).Error
3863 3884
 	return err
3864 3885
 
3865 3886
 }
3866 3887
 
3867
-func UpDateWarehouseInfoByStockDelete(id int64, count int64) (err error) {
3888
+func UpDateWarehouseInfoByStockDelete(id int64, count int64, patient_id int64, record_time int64, goodid int64) (err error) {
3868 3889
 
3869 3890
 	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
3891
+	err = writeDb.Model(&models.VmStockFlow{}).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", id, patient_id, record_time, goodid).UpdateColumn("over_count", gorm.Expr("over_count + ?", count)).Error
3870 3892
 	return err
3871 3893
 }
3872 3894
 
@@ -3932,18 +3954,11 @@ func GetHisProjectPrescriptionByPatientIdOne(id int64) (models.HisPrescriptionPr
3932 3954
 
3933 3955
 func GetAllAutoRecordByPatient(patientid int64, recorddate int64) (auto []*models.WarehouseOutInfoNight, err error) {
3934 3956
 
3935
-	err = XTReadDB().Select("count,warehouse_info_id,good_id,org_id").Where(" patient_id = ? and sys_record_time = ?  and status = 1 and is_sys = 1 and count>0", patientid, recorddate).Find(&auto).Error
3957
+	err = XTReadDB().Select("count,warehouse_info_id,good_id,org_id,sys_record_time,patient_id,project_id,warehouse_info_id,warehouse_out_order_number,storehouse_id,price,dealer,manufacturer,good_type_id,product_date,expiry_date,number,license_number").Where(" patient_id = ? and sys_record_time = ?  and status = 1 and is_sys = 1 and count>0", patientid, recorddate).Find(&auto).Error
3936 3958
 	return auto, err
3937 3959
 
3938 3960
 }
3939 3961
 
3940
-//func GetAllAutoRecordByPatient(patientid int64, recorddate int64) (auto []*models.VmStockFlow, err error) {
3941
-//
3942
-//	err = XTReadDB().Select("count,warehousing_id").Where(" patient_id = ? and system_time = ?  and status = 1 and is_sys = 1 and count>0",patientid,recorddate).Find(&auto).Error
3943
-//	return auto, err
3944
-//
3945
-//}
3946
-
3947 3962
 func ModefyWarehouseInfo(count int64, id int64) error {
3948 3963
 
3949 3964
 	err := XTWriteDB().Model(models.WarehousingInfo{}).Where(" id =? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
@@ -3954,9 +3969,9 @@ func DeleteAutoWarehouse(patient_id int64, record_time int64) error {
3954 3969
 
3955 3970
 	err := XTWriteDB().Model(models.AutomaticReduceDetail{}).Where("patient_id = ? and record_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3956 3971
 	err = XTWriteDB().Model(models.DialysisBeforePrepare{}).Where("patient_id = ? and record_date = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3957
-	err = XTWriteDB().Model(models.VmStockFlow{}).Where("patient_id = ? and system_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3958
-	err = XTWriteDB().Model(models.WarehouseOutInfoNight{}).Where("patient_id = ? and sys_record_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3959
-	fmt.Println("err2332332322323322323232323232332", err)
3972
+	err = XTWriteDB().Model(models.VmStockFlow{}).Where("patient_id = ? and system_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"is_read": 1}).Error
3973
+	//err = XTWriteDB().Model(models.WarehouseOutInfoNight{}).Where("patient_id = ? and sys_record_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3974
+
3960 3975
 	return err
3961 3976
 }
3962 3977
 
@@ -4069,7 +4084,7 @@ func GetAllGoodInfoStockList(page int64, limit int64, startime int64, endtime in
4069 4084
 	return info, total, err
4070 4085
 }
4071 4086
 
4072
-func GetStockListById(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64) (info []*models.VmWarehousingInfo, total int64, err error) {
4087
+func GetStockListById(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64, startfirsttime int64, endfirsttime int64) (info []*models.VmWarehousingInfo, total int64, err error) {
4073 4088
 
4074 4089
 	offset := (page - 1) * limit
4075 4090
 	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status= 1 and x.is_check = 1")
@@ -4082,6 +4097,12 @@ func GetStockListById(good_id int64, orgid int64, limit int64, page int64, start
4082 4097
 	if endtime > 0 {
4083 4098
 		db = db.Where("x.ctime<=?", endtime)
4084 4099
 	}
4100
+	if startfirsttime > 0 {
4101
+		db = db.Where("x.expiry_date >=?", startfirsttime)
4102
+	}
4103
+	if endfirsttime > 0 {
4104
+		db = db.Where("x.expiry_date <=?", endfirsttime)
4105
+	}
4085 4106
 
4086 4107
 	if orgid > 0 {
4087 4108
 		db = db.Where("x.org_id = ?", orgid)
@@ -4089,7 +4110,7 @@ func GetStockListById(good_id int64, orgid int64, limit int64, page int64, start
4089 4110
 	if good_id > 0 {
4090 4111
 		db = db.Where("x.good_id = ?", good_id)
4091 4112
 	}
4092
-	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.packing_price,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,x.storehouse_id,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.buy_price,f.batch_number_count").Joins("left join xt_good_information as t on t.id = x.good_id").Joins("left join xt_stock_flow as f on f.warehousing_detail_id = x.id").Count(&total).Offset(offset).Limit(limit).Order("x.id desc").Scan(&info).Error
4113
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.packing_price,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,x.storehouse_id,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.buy_price,f.batch_number_count").Joins("left join xt_good_information as t on t.id = x.good_id").Joins("left join xt_stock_flow as f on f.warehousing_detail_id = x.id").Count(&total).Offset(offset).Limit(limit).Group("x.id").Order("x.id desc").Scan(&info).Error
4093 4114
 	return info, total, err
4094 4115
 
4095 4116
 }
@@ -4199,9 +4220,7 @@ func GetWarehouseOutOrder(id []string, orgid int64) (out []*models.WarehouseOut,
4199 4220
 	if orgid > 0 {
4200 4221
 		db = db.Where("x.org_id= ?", orgid)
4201 4222
 	}
4202
-	err = db.Select("x.id,x.warehouse_out_order_number,x.operation_time,x.creater,x.org_id,x.modifier,x.remark,x.warehouse_out_time,x.dealer,x.manufacturer,x.type").Preload("WarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
4203
-		return XTReadDB().Where("org_id=? and status = 1", orgid).Preload("WarehousingInfo", "status = 1 and org_id = ?", orgid)
4204
-	}).Find(&out).Error
4223
+	err = db.Select("x.id,x.warehouse_out_order_number,x.operation_time,x.creater,x.org_id,x.modifier,x.remark,x.warehouse_out_time,x.dealer,x.manufacturer,x.type").Find(&out).Error
4205 4224
 	return out, err
4206 4225
 }
4207 4226
 
@@ -4218,7 +4237,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
4218 4237
 		db = db.Where("x.org_id = ?", orgid)
4219 4238
 	}
4220 4239
 
4221
-	err = db.Select("x.id,x.warehouse_out_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,t.social_security_directory_code,x.is_sys,x.sys_record_time,n.number,x.remark,x.license_number,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit,t.packing_price").Joins("left join xt_warehouse_info as n on n.id=x.warehouse_info_id").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
4240
+	err = db.Select("x.id,x.warehouse_out_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,x.manufacturer,t.social_security_directory_code,x.is_sys,x.sys_record_time,n.number,x.remark,x.license_number,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,x.warehouse_info_id,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit,t.packing_price").Joins("left join xt_warehouse_info as n on n.id=x.warehouse_info_id").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
4222 4241
 
4223 4242
 	return out, err
4224 4243
 }
@@ -4727,7 +4746,24 @@ func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlo
4727 4746
 
4728 4747
 func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
4729 4748
 
4730
-	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and count > 0")
4749
+	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and x.count > 0 and (x.consumable_type = 3 or x.consumable_type = 2")
4750
+	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
4751
+	fmt.Println(table)
4752
+	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
4753
+	fmt.Println(tableone)
4754
+	if id > 0 {
4755
+		db = db.Where("x.warehouse_out_id = ?", id)
4756
+	}
4757
+	if goodid > 0 {
4758
+		db = db.Where("x.good_id = ?", goodid)
4759
+	}
4760
+
4761
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.number,x.count,x.patient_id,x.system_time,x.is_sys,x.warehousing_order,x.warehouse_out_id,x.warehouse_out_order_number,x.price,x.product_date,x.expire_date,x.ctime,o.packing_unit,t.name").Joins("left join xt_patients as t on t.id = x.patient_id").Joins("left join xt_good_information as o on o.id = x.good_id").Scan(&stock).Error
4762
+	return stock, err
4763
+}
4764
+
4765
+func GetStockFlowCancelInfo(id int64, goodid int64) (stock []*models.VmStockFlowOne, err error) {
4766
+	db := XTReadDB().Table("xt_stock_flow as x").Where("x.status = 1 and x.count > 0 and x.consumable_type = 7")
4731 4767
 	table := XTReadDB().Table("xt_patients as t").Where("t.status = 1")
4732 4768
 	fmt.Println(table)
4733 4769
 	tableone := XTReadDB().Table("xt_good_information as o").Where("o.status = 1")
@@ -4740,7 +4776,6 @@ func GetStockFlowBatchNumberOne(id int64, goodid int64) (stock []*models.VmStock
4740 4776
 	}
4741 4777
 
4742 4778
 	err = db.Select("x.id,x.warehousing_id,x.good_id,x.number,x.count,x.patient_id,x.system_time,x.is_sys,x.warehousing_order,x.warehouse_out_id,x.warehouse_out_order_number,x.price,x.product_date,x.expire_date,x.ctime,o.packing_unit,t.name").Joins("left join xt_patients as t on t.id = x.patient_id").Joins("left join xt_good_information as o on o.id = x.good_id").Scan(&stock).Error
4743
-	//err =XTReadDB()()()()().Model(&stock).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Find(&stock).Error
4744 4779
 	return stock, err
4745 4780
 }
4746 4781
 
@@ -4901,13 +4936,13 @@ func CreateStockFlow(warehousingInfo []*models.VmStockFlow) (err error) {
4901 4936
 }
4902 4937
 
4903 4938
 func CreateStockFlowOne(flow models.VmStockFlow) error {
4904
-	tx := XTWriteDB().Begin()
4905
-	err := tx.Create(&flow).Error
4939
+	utx := XTWriteDB().Begin()
4940
+	err := utx.Create(&flow).Error
4906 4941
 	if err != nil {
4907
-		tx.Rollback()
4942
+		utx.Rollback()
4908 4943
 		return err
4909 4944
 	}
4910
-	tx.Commit()
4945
+	utx.Commit()
4911 4946
 	return err
4912 4947
 }
4913 4948
 
@@ -4924,7 +4959,7 @@ func UpdatedStockFlow(flow models.VmStockFlow) error {
4924 4959
 
4925 4960
 func UpdatedStockFlowOne(flow models.VmStockFlow, warehousing_id int64, patient_id int64, record_time int64, good_id int64) error {
4926 4961
 
4927
-	err = XTWriteDB().Model(&flow).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehousing_id, patient_id, record_time, good_id).Updates(map[string]interface{}{"number": flow.Number, "license_number": flow.LicenseNumber, "count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer}).Error
4962
+	err = XTWriteDB().Model(&flow).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehousing_id, patient_id, record_time, good_id).Updates(map[string]interface{}{"number": flow.Number, "license_number": flow.LicenseNumber, "count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "over_count": flow.OverCount}).Error
4928 4963
 	return err
4929 4964
 }
4930 4965
 
@@ -4932,7 +4967,7 @@ func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int
4932 4967
 
4933 4968
 	stock := models.VmStockFlow{}
4934 4969
 	var err error
4935
-	err = XTReadDB().Model(&stock).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", warehousing_id, patient_id, record_time, good_id).Find(&stock).Error
4970
+	err = XTReadDB().Model(&stock).Where("warehousing_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and is_read = 0", warehousing_id, patient_id, record_time, good_id).Find(&stock).Error
4936 4971
 	if err == gorm.ErrRecordNotFound {
4937 4972
 		return nil, err
4938 4973
 	}
@@ -4942,6 +4977,24 @@ func GetStockFlowIsExsit(warehousing_id int64, patient_id int64, record_time int
4942 4977
 	return &stock, nil
4943 4978
 }
4944 4979
 
4980
+func GetStockFlowIsBatchNumber(warehousing_id int64, patient_id int64, record_time int64, good_id int64) (flow []*models.VmStockFlow, err error) {
4981
+
4982
+	err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type = 3", patient_id, record_time, good_id).Find(&flow).Error
4983
+	return flow, nil
4984
+}
4985
+
4986
+func GetStockFlowIsBatchNumberTwo(patient_id int64, record_time int64, good_id int64) (flow []*models.WarehouseOutInfo, err error) {
4987
+
4988
+	err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 ", patient_id, record_time, good_id).Find(&flow).Error
4989
+	return flow, nil
4990
+}
4991
+
4992
+func GetStockFlowIsBatchNumberThree(patient_id int64, record_time int64, good_id int64) (flow []*models.VmStockFlow, err error) {
4993
+
4994
+	err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type =7", patient_id, record_time, good_id).Find(&flow).Error
4995
+	return flow, nil
4996
+}
4997
+
4945 4998
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
4946 4999
 
4947 5000
 	info := models.WarehouseOutInfo{}
@@ -4956,7 +5009,7 @@ func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
4956 5009
 	return &info, nil
4957 5010
 }
4958 5011
 
4959
-func GetWarehouseOutInfoIsExistOne(good_id int64, patient_id int64, record_time int64) (*models.WarehouseOutInfo, error) {
5012
+func GetWarehouseOutInfoIsExistOne(good_id int64, patient_id int64, record_time int64, project_id int64) (*models.WarehouseOutInfo, error) {
4960 5013
 
4961 5014
 	info := models.WarehouseOutInfo{}
4962 5015
 	var err error
@@ -4970,6 +5023,12 @@ func GetWarehouseOutInfoIsExistOne(good_id int64, patient_id int64, record_time
4970 5023
 	return &info, nil
4971 5024
 }
4972 5025
 
5026
+func GetWarehouseOutInfoIsExistTwo(good_id int64, patient_id int64, record_time int64, project_id int64) (models.WarehouseOutInfo, error) {
5027
+	info := models.WarehouseOutInfo{}
5028
+	err := XTReadDB().Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ?", good_id, record_time, patient_id).Find(&info).Error
5029
+	return info, err
5030
+}
5031
+
4973 5032
 func GetStockFlowList(limit int64, page int64, consumable_type int64, orgId int64, startTime int64, endTime int64, good_id int64) (flow []*models.VmStockFlow, total int64, err error) {
4974 5033
 
4975 5034
 	offset := (page - 1) * limit
@@ -4994,6 +5053,10 @@ func GetStockFlowList(limit int64, page int64, consumable_type int64, orgId int6
4994 5053
 		if consumable_type == 4 {
4995 5054
 			db = db.Where(" consumable_type = ?", consumable_type)
4996 5055
 		}
5056
+		//自动退库
5057
+		if consumable_type == 7 {
5058
+			db = db.Where(" consumable_type = ?", consumable_type)
5059
+		}
4997 5060
 
4998 5061
 		if consumable_type == 10 {
4999 5062
 			db = db.Where(" consumable_type = ?", consumable_type)
@@ -5047,7 +5110,14 @@ func GetLastGoodListByPatientIdOne(recordtime int64, patientid int64, goodid int
5047 5110
 	return detail, err
5048 5111
 }
5049 5112
 
5050
-func UpdatedWarehouseOutInfo(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64) error {
5113
+func UpdatedWarehouseOutInfo(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64, project_id int64) error {
5114
+
5115
+	outInfo := models.WarehouseOutInfo{}
5116
+	err := XTWriteDB().Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", good_id, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber, "over_count": info.OverCount}).Error
5117
+	return err
5118
+}
5119
+
5120
+func UpdatedWarehouseOutInfoTwo(info *models.WarehouseOutInfo, good_id int64, patient_id int64, record_time int64) error {
5051 5121
 
5052 5122
 	outInfo := models.WarehouseOutInfo{}
5053 5123
 	err := XTWriteDB().Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", good_id, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": info.WarehouseOutId, "WarehouseOutOrderNumber": info.WarehouseOutOrderNumber, "sys_record_time": info.SysRecordTime, "good_type_id": info.GoodTypeId, "patient_id": info.PatientId, "consumable_type": info.ConsumableType, "count": info.Count, "price": info.Price, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "number": info.Number, "license_number": info.LicenseNumber}).Error
@@ -5286,8 +5356,8 @@ func DeleteDrugAutoWarehouse(drugid int64, patient_id int64, record_time int64)
5286 5356
 func DeleteDrugAutoWarehouseSeven(drugid int64, patient_id int64, record_time int64, advice_id int64) error {
5287 5357
 
5288 5358
 	err := XTWriteDB().Model(models.DrugAutomaticReduceDetail{}).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
5289
-	err = XTWriteDB().Model(models.DrugWarehouseOutInfo{}).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
5290
-	err = XTWriteDB().Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
5359
+	//err = XTWriteDB().Model(models.DrugWarehouseOutInfo{}).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
5360
+	//err = XTWriteDB().Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
5291 5361
 	return err
5292 5362
 }
5293 5363
 
@@ -5977,7 +6047,7 @@ func ModifyDrugWarehouseInfoSix(info *models.DrugWarehouseInfo, id int64) error
5977 6047
 
5978 6048
 func GetGoodInventoryWarehouseList(id int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
5979 6049
 
5980
-	err = XTReadDB().Model(&info).Where("good_id = ? and status = 1 and storehouse_id=?", id, storehouse_id).Preload("GoodInfo", "status = 1").Find(&info).Error
6050
+	err = XTReadDB().Model(&info).Where("good_id = ? and status = 1 and storehouse_id=? and is_check= 1", id, storehouse_id).Preload("GoodInfo", "status = 1").Find(&info).Error
5981 6051
 	return info, err
5982 6052
 }
5983 6053
 
@@ -7019,8 +7089,13 @@ func UpdatedWarehouseOut(id int64) error {
7019 7089
 
7020 7090
 func UpdatedSigleWarehouseOutInfo(id int64, info *models.WarehouseOutInfo) error {
7021 7091
 
7022
-	err := XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"warehouse_info_id": info.WarehouseInfotId}).Error
7023
-
7092
+	tx := XTWriteDB().Begin()
7093
+	err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"warehouse_info_id": info.WarehouseInfotId}).Error
7094
+	if err != nil {
7095
+		tx.Rollback()
7096
+		return err
7097
+	}
7098
+	tx.Commit()
7024 7099
 	return err
7025 7100
 
7026 7101
 }
@@ -7059,17 +7134,40 @@ func GetLastGoodWarehouseOutTwenty(orgid int64) (models.WarehouseOut, error) {
7059 7134
 
7060 7135
 func UpdateaGoodWarehouseInfo(count int64, good_id int64, orgid int64, warehouse_info_id int64) error {
7061 7136
 
7062
-	err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("good_id = ?  and org_id = ? and status = 1 and id = ?", good_id, orgid, warehouse_info_id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
7063
-
7137
+	ut := writeDb.Begin()
7138
+	err := ut.Model(&models.WarehousingInfo{}).Where("good_id = ?  and org_id = ? and status = 1 and id = ?", good_id, orgid, warehouse_info_id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
7139
+	if err != nil {
7140
+		ut.Rollback()
7141
+		return err
7142
+	}
7143
+	ut.Commit()
7064 7144
 	return err
7145
+
7065 7146
 }
7066 7147
 
7067 7148
 func ModifyGoodWarehouseOut(id int64) error {
7068
-
7069
-	err := XTWriteDB().Model(&models.WarehouseOut{}).Where("id = ? and status =1", id).Update(map[string]interface{}{"is_check": 2}).Error
7070
-	err = XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
7071
-	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
7072
-
7149
+	ut := writeDb.Begin()
7150
+	err := ut.Model(&models.WarehouseOut{}).Where("id = ? and status =1", id).Update(map[string]interface{}{"is_check": 2}).Error
7151
+	if err != nil {
7152
+		ut.Rollback()
7153
+		return err
7154
+	}
7155
+	err = ut.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
7156
+	if err != nil {
7157
+		ut.Rollback()
7158
+		return err
7159
+	}
7160
+	err = ut.Model(&models.VmStockFlow{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"status": 0, "is_check": 2}).Error
7161
+	if err != nil {
7162
+		ut.Rollback()
7163
+		return err
7164
+	}
7165
+	err = ut.Model(&models.XtWarehouseFlushInfo{}).Where("warehouse_out_id in(?) and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
7166
+	if err != nil {
7167
+		ut.Rollback()
7168
+		return err
7169
+	}
7170
+	ut.Commit()
7073 7171
 	return err
7074 7172
 }
7075 7173
 
@@ -7095,6 +7193,15 @@ func UpdateWarehouseDetail(info *models.WarehousingInfo, id int64) error {
7095 7193
 }
7096 7194
 
7097 7195
 func UpdateCheckWarehouseInfo(id int64) error {
7196
+
7197
+	tx := XTWriteDB().Begin()
7198
+	err := tx.Model(&models.Warehousing{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
7199
+	if err != nil {
7200
+		tx.Rollback()
7201
+		return err
7202
+	}
7203
+	tx.Commit()
7204
+	return err
7098 7205
 	tx := XTWriteDB().Begin()
7099 7206
 	err := tx.Model(&models.Warehousing{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
7100 7207
 	if err != nil {
@@ -7112,6 +7219,20 @@ func GetWarehouseInfoList(id int64, orgid int64) (info []*models.WarehousingInfo
7112 7219
 }
7113 7220
 
7114 7221
 func UpdateWarehouseInfoByIdList(count int64, id int64) error {
7222
+
7223
+	tx := XTWriteDB().Begin()
7224
+	err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
7225
+	if err != nil {
7226
+		tx.Rollback()
7227
+		return err
7228
+	}
7229
+	err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
7230
+	if err != nil {
7231
+		tx.Rollback()
7232
+		return err
7233
+	}
7234
+	tx.Commit()
7235
+	return err
7115 7236
 	tx := XTWriteDB().Begin()
7116 7237
 	err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
7117 7238
 	if err != nil {
@@ -7128,6 +7249,16 @@ func UpdateWarehouseInfoByIdList(count int64, id int64) error {
7128 7249
 }
7129 7250
 
7130 7251
 func ReturnCheckWarehouseInfo(id int64) error {
7252
+
7253
+	tx := XTWriteDB().Begin()
7254
+	err := tx.Model(&models.Warehousing{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
7255
+	if err != nil {
7256
+		tx.Rollback()
7257
+		return err
7258
+	}
7259
+	err = tx.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
7260
+	tx.Commit()
7261
+	return err
7131 7262
 	tx := XTWriteDB().Begin()
7132 7263
 	err := tx.Model(&models.Warehousing{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
7133 7264
 	if err != nil {
@@ -7140,6 +7271,20 @@ func ReturnCheckWarehouseInfo(id int64) error {
7140 7271
 }
7141 7272
 
7142 7273
 func UpdateWarehouseInfoByIdListTwo(count int64, id int64) error {
7274
+
7275
+	tx := XTWriteDB().Begin()
7276
+	err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
7277
+	if err != nil {
7278
+		tx.Rollback()
7279
+		return err
7280
+	}
7281
+	err = tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
7282
+	if err != nil {
7283
+		tx.Rollback()
7284
+		return err
7285
+	}
7286
+	tx.Commit()
7287
+	return err
7143 7288
 	tx := XTWriteDB().Begin()
7144 7289
 	err := tx.Model(&models.WarehousingInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", count)).Error
7145 7290
 	if err != nil {
@@ -7156,8 +7301,9 @@ func UpdateWarehouseInfoByIdListTwo(count int64, id int64) error {
7156 7301
 }
7157 7302
 
7158 7303
 func UpdateWarehouseInfoFlow(id int64) error {
7304
+
7159 7305
 	tx := XTWriteDB().Begin()
7160
-	err := tx.Model(models.VmStockFlow{}).Where("warehousing_detail_id =  ?", id).Update(map[string]interface{}{"status": 0}).Error
7306
+	err := tx.Model(models.VmStockFlow{}).Where("warehousing_detail_id =  ?", id).Update(map[string]interface{}{"status": 0, "is_check": 2}).Error
7161 7307
 
7162 7308
 	if err != nil {
7163 7309
 		tx.Rollback()
@@ -7165,6 +7311,12 @@ func UpdateWarehouseInfoFlow(id int64) error {
7165 7311
 	}
7166 7312
 	tx.Commit()
7167 7313
 	return err
7314
+	if err != nil {
7315
+		tx.Rollback()
7316
+		return err
7317
+	}
7318
+	tx.Commit()
7319
+	return err
7168 7320
 }
7169 7321
 
7170 7322
 func FindLastWarehousingSix(org_id int64) (info models.Warehousing, err error) {
@@ -7414,6 +7566,14 @@ func UpdateGoodInfoSumCount(goodid int64, sum_count int64, orgid int64) error {
7414 7566
 }
7415 7567
 
7416 7568
 func UpdateGoodInfoReduceSumCount(goodid int64, sum_count int64, orgid int64) error {
7569
+	tx := XTWriteDB().Begin()
7570
+	err = tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
7571
+	if err != nil {
7572
+		tx.Rollback()
7573
+		return err
7574
+	}
7575
+	tx.Commit()
7576
+	return err
7417 7577
 
7418 7578
 	err = XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
7419 7579
 	return err
@@ -7430,6 +7590,18 @@ func UpdateGoodInfoAddSumCount(goodid int64, sum_count int64, orgid int64) error
7430 7590
 	return err
7431 7591
 }
7432 7592
 
7593
+func UpdateGoodInfoAddSumCount(goodid int64, sum_count int64, orgid int64, sum_in_count int64) error {
7594
+
7595
+	tx := XTWriteDB().Begin()
7596
+	err := tx.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", goodid, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
7597
+	if err != nil {
7598
+		tx.Rollback()
7599
+		return err
7600
+	}
7601
+	tx.Commit()
7602
+	return err
7603
+}
7604
+
7433 7605
 func GetCancelStockInfo(id int64, orgid int64) (stock []*models.CancelStockInfo, err error) {
7434 7606
 
7435 7607
 	err = XTReadDB().Where("cancel_stock_id  = ? and org_id = ? and status  = 1", id, orgid).Preload("GoodInfo", "status = 1 and org_id = ?", orgid).Preload("WarehousingInfo", "status = 1 and org_id = ?", orgid).Find(&stock).Error
@@ -7461,9 +7633,18 @@ func GetCancelWarehouseList(orgId int64, goodId int64, warehouseInfoId int64) (i
7461 7633
 }
7462 7634
 
7463 7635
 func CheckCancelStock(stock models.CancelStock, cancel_stock_id int64, orgid int64) error {
7464
-
7465
-	err := XTWriteDB().Model(&models.CancelStock{}).Where("id = ? and status = 1 and org_id = ?", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 1}).Error
7466
-	err = XTWriteDB().Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? and status = 1 and org_id = ?", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 1}).Error
7636
+	ut := writeDb.Begin()
7637
+	err := ut.Model(&models.CancelStock{}).Where("id = ? and status = 1 and org_id = ?", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 1}).Error
7638
+	if err != nil {
7639
+		ut.Rollback()
7640
+		return err
7641
+	}
7642
+	err = ut.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? and status = 1 and org_id = ?", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 1}).Error
7643
+	if err != nil {
7644
+		ut.Rollback()
7645
+		return err
7646
+	}
7647
+	ut.Commit()
7467 7648
 	return err
7468 7649
 }
7469 7650
 
@@ -7474,33 +7655,67 @@ func GetCancelStockInfoById(cancel_stock_id int64, orgid int64) (info []*models.
7474 7655
 }
7475 7656
 
7476 7657
 func UpdateCancelStockNumber(stock_count int64, warehouse_info_id int64, orgid int64) error {
7477
-
7478
-	err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ? and org_id = ? and status = 1", warehouse_info_id, orgid).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", stock_count)).Error
7658
+	ut := writeDb.Begin()
7659
+	err := ut.Model(&models.WarehousingInfo{}).Where("id = ? and org_id = ? and status = 1", warehouse_info_id, orgid).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", stock_count)).Error
7660
+	if err != nil {
7661
+		ut.Rollback()
7662
+		return err
7663
+	}
7664
+	ut.Commit()
7479 7665
 	return err
7480 7666
 }
7481 7667
 
7482 7668
 func UpdateGoodSumCount(sum_count int64, good_id int64, orgid int64) error {
7483
-
7484
-	err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
7669
+	ut := writeDb.Begin()
7670
+	err := ut.Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).UpdateColumn("sum_count", gorm.Expr("sum_count + ?", sum_count)).Error
7671
+	if err != nil {
7672
+		ut.Rollback()
7673
+		return err
7674
+	}
7675
+	ut.Commit()
7485 7676
 	return err
7486 7677
 }
7487 7678
 
7488 7679
 func UpdateStockWarehouseInfo(cancel_stock_id int64, orgid int64, stock models.CancelStock) error {
7489
-
7490
-	err := XTWriteDB().Model(&models.CancelStock{}).Where("id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
7491
-	err = XTWriteDB().Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
7680
+	ut := writeDb.Begin()
7681
+	err := ut.Model(&models.CancelStock{}).Where("id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
7682
+	if err != nil {
7683
+		ut.Rollback()
7684
+		return err
7685
+	}
7686
+	err = ut.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? and org_id = ? and status = 1", cancel_stock_id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
7687
+	if err != nil {
7688
+		ut.Rollback()
7689
+		return err
7690
+	}
7691
+	ut.Commit()
7492 7692
 	return err
7493 7693
 }
7494 7694
 
7495 7695
 func UpdateStockWarehouseInfoStockFlow(id int64, orgid int64, goodid int64) error {
7496
-	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("cancel_out_detail_id = ? and user_org_id = ? and status = 1 and good_id =?", id, orgid, goodid).Update(map[string]interface{}{"status": 0}).Error
7696
+	ut := writeDb.Begin()
7697
+	err = ut.Model(&models.VmStockFlow{}).Where("cancel_out_detail_id = ? and user_org_id = ? and status = 1 and good_id =?", id, orgid, goodid).Update(map[string]interface{}{"status": 0}).Error
7698
+	if err != nil {
7699
+		ut.Rollback()
7700
+		return err
7701
+	}
7702
+	ut.Commit()
7497 7703
 	return err
7498 7704
 }
7499 7705
 
7500 7706
 func UpdateStockNumberWarehouseInfo(warehouse_info_id int64, good_id int64, org_id int64, stock_count int64) error {
7501
-
7707
+	ut := writeDb.Begin()
7502 7708
 	err := XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ? and good_id = ? and org_id = ? and status = 1", warehouse_info_id, good_id, org_id).UpdateColumn("stock_count", gorm.Expr("stock_count - ?", stock_count)).Error
7709
+	if err != nil {
7710
+		ut.Rollback()
7711
+		return err
7712
+	}
7503 7713
 	err = XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and status = 1 and org_id = ?", good_id, org_id).UpdateColumn("sum_count", gorm.Expr("sum_count - ?", stock_count)).Error
7714
+	if err != nil {
7715
+		ut.Rollback()
7716
+		return err
7717
+	}
7718
+	ut.Commit()
7504 7719
 	return err
7505 7720
 }
7506 7721
 
@@ -7531,6 +7746,18 @@ func GetDrugAllStockInfo(storehouse_id int64, orgid int64, drugid int64) (info [
7531 7746
 }
7532 7747
 
7533 7748
 func UpdateBaseDrugSumInfo(sum_count int64, drugid int64, orgid int64, sum_in_count int64) error {
7749
+	ut := XTWriteDB().Begin()
7750
+	err := ut.Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
7751
+	if err != nil {
7752
+		ut.Rollback()
7753
+		return err
7754
+	}
7755
+	err = ut.Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", drugid, orgid).Update(map[string]interface{}{"sum_in_count": sum_in_count}).Error
7756
+	if err != nil {
7757
+		ut.Rollback()
7758
+		return err
7759
+	}
7760
+	ut.Commit()
7534 7761
 	tx := XTWriteDB().Begin()
7535 7762
 	err := tx.Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
7536 7763
 	if err != nil {
@@ -7547,8 +7774,13 @@ func UpdateBaseDrugSumInfo(sum_count int64, drugid int64, orgid int64, sum_in_co
7547 7774
 }
7548 7775
 
7549 7776
 func UpdateBaseDrugSumTwo(drugid int64, sum_count int64, orgid int64) error {
7550
-
7551
-	err = XTWriteDB().Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
7777
+	ut := writeDb.Begin()
7778
+	err = ut.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drugid, orgid).Update(map[string]interface{}{"sum_count": sum_count}).Error
7779
+	if err != nil {
7780
+		ut.Rollback()
7781
+		return err
7782
+	}
7783
+	ut.Commit()
7552 7784
 	return err
7553 7785
 }
7554 7786
 
@@ -7632,9 +7864,15 @@ func ModifyDrugFlowByCancelId(cancelstock_id int64, drugId int64, orgid int64) e
7632 7864
 }
7633 7865
 
7634 7866
 func ModifyDrugMaxNumberWarehouseInfo(id int64, count int64, orgid int64) error {
7635
-
7636
-	err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and org_id = ? and status = 1", id, orgid).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
7867
+	ut := XTWriteDB().Begin()
7868
+	err := ut.Model(&models.DrugWarehouseInfo{}).Where("id = ? and org_id = ? and status = 1", id, orgid).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
7869
+	if err != nil {
7870
+		ut.Rollback()
7871
+		return err
7872
+	}
7873
+	ut.Commit()
7637 7874
 	return err
7875
+
7638 7876
 }
7639 7877
 
7640 7878
 func ModifyDrugMinNumberWarehouseInfo(id int64, count int64, orgid int64) error {
@@ -7664,3 +7902,10 @@ func GetPrintList(storehouse_id int64, good_name string, orgid int64, limit int6
7664 7902
 	err = XTReadDB().Preload("GoodInfo", "status = 1 and org_id = ?", orgid).Preload("WarehousingInfo", "status = 1 and org_id=?", orgid).Find(&storeinventory).Error
7665 7903
 	return storeinventory, err
7666 7904
 }
7905
+
7906
+func GetGoodDialysisOutInfo(orgid int64, patient_id int64, sys_record_time int64, good_id int64) (models.AutomaticReduceDetail, error) {
7907
+
7908
+	detail := models.AutomaticReduceDetail{}
7909
+	err := XTReadDB().Where("org_id =? and patient_id = ? and record_time = ? and good_id = ? and status= 1", orgid, patient_id, sys_record_time, good_id).Find(&detail).Error
7910
+	return detail, err
7911
+}