XMLWAN 3 年 前
コミット
1f3fa08012

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

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9529
2
+httpport = 9531
3 3
 runmode = dev
4 4
 
5 5
 #

+ 43 - 24
controllers/mobile_api_controllers/doctor_advice_api_controller.go ファイルの表示

@@ -37,36 +37,55 @@ func (this *DoctorAdviceAPIController) ScheduleAdvices() {
37 37
 
38 38
 	adminInfo := this.GetMobileAdminUserInfo()
39 39
 	orgID := adminInfo.Org.Id
40
-
41
-	scheduals, err := service.MobileGetScheduleDoctorAdvices(orgID, date.Unix(), adviceType, patientType, adminInfo.AdminUser.Id, delivery_way)
42
-	//获取his医嘱数据
43
-	fmt.Println("date.un222222", date.Unix())
44
-	hisAdvices, _ := service.GetHisDoctorAdvices(orgID, date.Unix(), delivery_way, patientType, adminInfo.AdminUser.Id)
45
-
46
-	project, _ := service.GetMobileHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, adminInfo.AdminUser.Id)
40
+	scheduals, err := service.MobileGetScheduleDoctorAdvicesTwo(orgID, date.Unix(), adviceType, patientType, adminInfo.AdminUser.Id, delivery_way)
47 41
 	config, _ := service.GetHisDoctorConfig(orgID)
48 42
 	project_config, _ := service.GetHisProjectConfig(orgID)
49
-
50
-	adminUser, _ := service.GetAllAdminUsers(orgID, adminInfo.App.Id)
51
-	if err != nil {
52
-		this.ErrorLog("获取排班信息失败:%v", err)
53
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
43
+	fmt.Println("project_config23223232323", project_config)
44
+	if project_config.IsOpen == 1 || project_config.IsOpen == 2 {
45
+		//获取his医嘱数据
46
+		project, _ := service.GetMobileHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, adminInfo.AdminUser.Id)
47
+		hisAdvices, _ := service.GetHisDoctorAdvicesTwo(orgID, date.Unix(), delivery_way, patientType, adminInfo.AdminUser.Id)
48
+		adminUser, _ := service.GetAllAdminUsers(orgID, adminInfo.App.Id)
49
+		if err != nil {
50
+			this.ErrorLog("获取排班信息失败:%v", err)
51
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
52
+		} else {
53
+			filtedScheduals := []*service.MScheduleDoctorAdviceVMOne{}
54
+			for _, schedual := range scheduals {
55
+				if len(schedual.DoctorAdvices) > 0 {
56
+					filtedScheduals = append(filtedScheduals, schedual)
57
+				}
58
+			}
59
+			this.ServeSuccessJSON(map[string]interface{}{
60
+				"scheduals":      filtedScheduals,
61
+				"adminUser":      adminUser,
62
+				"config":         config,
63
+				"project":        project,
64
+				"project_config": project_config,
65
+				"hisAdvices":     hisAdvices,
66
+			})
67
+		}
54 68
 	} else {
55
-		filtedScheduals := []*service.MScheduleDoctorAdviceVM{}
56
-		for _, schedual := range scheduals {
57
-			if len(schedual.DoctorAdvices) > 0 {
58
-				filtedScheduals = append(filtedScheduals, schedual)
69
+		adminUser, _ := service.GetAllAdminUsers(orgID, adminInfo.App.Id)
70
+		if err != nil {
71
+			this.ErrorLog("获取排班信息失败:%v", err)
72
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
73
+		} else {
74
+			filtedScheduals := []*service.MScheduleDoctorAdviceVMOne{}
75
+			for _, schedual := range scheduals {
76
+				if len(schedual.DoctorAdvices) > 0 {
77
+					filtedScheduals = append(filtedScheduals, schedual)
78
+				}
59 79
 			}
80
+			this.ServeSuccessJSON(map[string]interface{}{
81
+				"scheduals":      filtedScheduals,
82
+				"adminUser":      adminUser,
83
+				"config":         config,
84
+				"project_config": project_config,
85
+			})
60 86
 		}
61
-		this.ServeSuccessJSON(map[string]interface{}{
62
-			"scheduals":      filtedScheduals,
63
-			"adminUser":      adminUser,
64
-			"hisAdvices":     hisAdvices,
65
-			"config":         config,
66
-			"project":        project,
67
-			"project_config": project_config,
68
-		})
69 87
 	}
88
+
70 89
 }
71 90
 
72 91
 func (c *DoctorAdviceAPIController) GetAdviceConfigs() {

+ 1 - 0
controllers/mobile_api_controllers/patient_api_controller.go ファイルの表示

@@ -2704,6 +2704,7 @@ func (c *PatientApiController) GetPrintDialysisOrder() {
2704 2704
 			advice.AdviceDoctor = item.Doctor
2705 2705
 			if item.Type == 3 {
2706 2706
 				advice.AdviceName = item.GoodInfo.GoodName
2707
+				advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
2707 2708
 			} else if item.Type == 2 {
2708 2709
 				advice.AdviceName = item.HisProject.ProjectName
2709 2710
 			}

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

@@ -687,7 +687,7 @@ func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*mo
687 687
 	if orgid > 0 {
688 688
 		db = db.Where("x.org_id = ?", orgid)
689 689
 	}
690
-	err = db.Select("x.count,x.drug_id,x.count_unit").Find(&info).Error
690
+	err = db.Select("sum(x.count) as count,x.drug_id,x.count_unit").Group("x.drug_id").Find(&info).Error
691 691
 	return info, err
692 692
 }
693 693
 

+ 221 - 0
service/mobile_dialysis_service.go ファイルの表示

@@ -742,6 +742,28 @@ func (MScheduleDoctorAdviceVM) TableName() string {
742 742
 	return "xt_schedule"
743 743
 }
744 744
 
745
+type MScheduleDoctorAdviceVMOne struct {
746
+	ID              int64                            `gorm:"column:id" json:"id"`
747
+	UserOrgId       int64                            `gorm:"column:user_org_id" json:"user_org_id"`
748
+	PartitionId     int64                            `gorm:"column:partition_id" json:"partition_id"`
749
+	BedId           int64                            `gorm:"column:bed_id" json:"bed_id"`
750
+	PatientId       int64                            `gorm:"column:patient_id" json:"patient_id"`
751
+	ScheduleDate    int64                            `gorm:"column:schedule_date" json:"schedule_date"`
752
+	ScheduleType    int64                            `gorm:"column:schedule_type" json:"schedule_type"`
753
+	ModeId          int64                            `gorm:"column:mode_id" json:"mode_id"`
754
+	Status          int64                            `gorm:"column:status" json:"status"`
755
+	DialysisOrder   *MDialysisOrderVM                `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
756
+	SchedualPatient *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
757
+	DeviceNumber    *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
758
+	DoctorAdvices   []*MDoctorAdviceVM               `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
759
+	Prescription    *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
760
+	//DialysisAssesmentBefor *models.DialysisAssesmentBefor   `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
761
+}
762
+
763
+func (MScheduleDoctorAdviceVMOne) TableName() string {
764
+	return "xt_schedule"
765
+}
766
+
745 767
 type MDoctorAdviceVM struct {
746 768
 	ID                    int64   `gorm:"column:id" json:"id"`
747 769
 	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id"`
@@ -887,6 +909,101 @@ func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType
887 909
 	return vms, err
888 910
 }
889 911
 
912
+func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
913
+	var vms []*MScheduleDoctorAdviceVMOne
914
+	adviceWhere := ""
915
+	adviceCondition := []interface{}{}
916
+	if adviceType == 0 {
917
+		if patientType == 0 {
918
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
919
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
920
+
921
+		} else if patientType == 1 {
922
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
923
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
924
+
925
+		} else if patientType == 2 {
926
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
927
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
928
+		}
929
+
930
+	} else if adviceType == 1 {
931
+		if patientType == 0 {
932
+			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ?  "
933
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
934
+
935
+		} else if patientType == 1 {
936
+			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
937
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
938
+
939
+		} else if patientType == 2 {
940
+			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
941
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
942
+
943
+		}
944
+
945
+	} else if adviceType == 3 {
946
+		if patientType == 0 {
947
+			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ?  "
948
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
949
+
950
+		} else if patientType == 1 {
951
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
952
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
953
+		} else if patientType == 2 {
954
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0"
955
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
956
+		}
957
+
958
+	} else if adviceType == 2 && len(deliverWay) > 0 {
959
+		if patientType == 0 {
960
+			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
961
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
962
+
963
+		} else if patientType == 1 {
964
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? "
965
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
966
+		} else if patientType == 2 {
967
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ?"
968
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
969
+		}
970
+
971
+	} else if adviceType == 2 && len(deliverWay) <= 0 {
972
+
973
+		if patientType == 0 {
974
+			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
975
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
976
+
977
+		} else if patientType == 1 {
978
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
979
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
980
+		} else if patientType == 2 {
981
+			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
982
+			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
983
+		}
984
+
985
+	}
986
+
987
+	db := readDb.
988
+		Table("xt_schedule").
989
+		Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
990
+		Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
991
+			return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
992
+		}).
993
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
994
+		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
995
+		Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
996
+		//Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
997
+		Preload("DoctorAdvices", adviceCondition...).
998
+		Where("status = 1 AND user_org_id = ?", orgID)
999
+	if scheduleDate != 0 {
1000
+		db = db.Where("schedule_date = ?", scheduleDate)
1001
+	}
1002
+
1003
+	err := db.Find(&vms).Error
1004
+	return vms, err
1005
+}
1006
+
890 1007
 func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
891 1008
 
892 1009
 	var vms []*HisMScheduleDoctorAdviceVM
@@ -969,6 +1086,88 @@ func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, pat
969 1086
 	return vms, err
970 1087
 }
971 1088
 
1089
+func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
1090
+
1091
+	var vms []*HisMScheduleDoctorAdviceVMOne
1092
+	if len(deliverWay) > 0 {
1093
+		if patientType == 0 {
1094
+			db := readDb.
1095
+				Table("xt_schedule").
1096
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
1097
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1098
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
1099
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1100
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
1101
+					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
1102
+				}).
1103
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1104
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1105
+				Where("status = 1 AND user_org_id = ?", orgID)
1106
+			if scheduleDate != 0 {
1107
+				db = db.Where("schedule_date = ?", scheduleDate)
1108
+			}
1109
+			err = db.Find(&vms).Error
1110
+		}
1111
+		if patientType > 0 {
1112
+			db := readDb.
1113
+				Table("xt_schedule").
1114
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1115
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
1116
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
1117
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1118
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1119
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1120
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
1121
+					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
1122
+				}).Where("status = 1 AND user_org_id = ?", orgID)
1123
+			if scheduleDate != 0 {
1124
+				db = db.Where("schedule_date = ?", scheduleDate)
1125
+			}
1126
+			err = db.Find(&vms).Error
1127
+		}
1128
+
1129
+	} else {
1130
+		if patientType == 0 {
1131
+			db := readDb.
1132
+				Table("xt_schedule").
1133
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
1134
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1135
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
1136
+					return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
1137
+				}).
1138
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1139
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1140
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1141
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
1142
+				Where("status = 1 AND user_org_id = ?", orgID)
1143
+			if scheduleDate != 0 {
1144
+				db = db.Where("schedule_date = ?", scheduleDate)
1145
+			}
1146
+			err = db.Find(&vms).Error
1147
+		}
1148
+		if patientType > 0 {
1149
+			db := readDb.
1150
+				Table("xt_schedule").
1151
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1152
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
1153
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1154
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
1155
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
1156
+					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
1157
+				}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1158
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1159
+				Where("status = 1 AND user_org_id = ?", orgID)
1160
+			if scheduleDate != 0 {
1161
+				db = db.Where("schedule_date = ?", scheduleDate)
1162
+			}
1163
+			err = db.Find(&vms).Error
1164
+		}
1165
+
1166
+	}
1167
+
1168
+	return vms, err
1169
+}
1170
+
972 1171
 func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
973 1172
 	var vms []*HisMScheduleProjectVM
974 1173
 	if patientType == 0 {
@@ -1848,6 +2047,28 @@ func (HisMScheduleDoctorAdviceVM) TableName() string {
1848 2047
 	return "xt_schedule"
1849 2048
 }
1850 2049
 
2050
+type HisMScheduleDoctorAdviceVMOne struct {
2051
+	ID                     int64                            `gorm:"column:id" json:"id"`
2052
+	UserOrgId              int64                            `gorm:"column:user_org_id" json:"user_org_id"`
2053
+	PartitionId            int64                            `gorm:"column:partition_id" json:"partition_id"`
2054
+	BedId                  int64                            `gorm:"column:bed_id" json:"bed_id"`
2055
+	PatientId              int64                            `gorm:"column:patient_id" json:"patient_id"`
2056
+	ScheduleDate           int64                            `gorm:"column:schedule_date" json:"schedule_date"`
2057
+	ScheduleType           int64                            `gorm:"column:schedule_type" json:"schedule_type"`
2058
+	ModeId                 int64                            `gorm:"column:mode_id" json:"mode_id"`
2059
+	Status                 int64                            `gorm:"column:status" json:"status"`
2060
+	DialysisOrder          *MDialysisOrderVM                `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
2061
+	SchedualPatient        *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
2062
+	DeviceNumber           *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
2063
+	Prescription           *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
2064
+	HisDoctorAdviceInfo    []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
2065
+	HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
2066
+}
2067
+
2068
+func (HisMScheduleDoctorAdviceVMOne) TableName() string {
2069
+	return "xt_schedule"
2070
+}
2071
+
1851 2072
 type HisMScheduleProjectVM struct {
1852 2073
 	ID                     int64                            `gorm:"column:id" json:"id"`
1853 2074
 	UserOrgId              int64                            `gorm:"column:user_org_id" json:"user_org_id"`

+ 17 - 12
service/stock_service.go ファイルの表示

@@ -3335,20 +3335,25 @@ func GetAutoDiallysisBefor(startime int64, endtime int64, orgid int64) (info []*
3335 3335
 
3336 3336
 func GetOutStockTotalCountFour(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
3337 3337
 
3338
-	//if startime > 0 {
3339
-	//	err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >=?  and `status` = 1)  as b GROUP BY good_id", orgid, startime).Scan(&autoMatic).Error
3340
-	//} else {
3341
-	//	err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3342
-	//}
3343
-
3344
-	if startime > 0 || endtime > 0 {
3345
-		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time <=?  and `status` = 1)  as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
3346
-	} else {
3347
-		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3338
+	if endtime > 0 {
3339
+		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count,x.record_time FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time <=?  and `status` = 1)  as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
3340
+	}
3341
+	if endtime == 0 {
3342
+		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count,x.record_time FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3348 3343
 	}
3349 3344
 
3350
-	//err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.record_time,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time<=? and `status` = 1)  as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error
3351
-
3345
+	//db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
3346
+	//
3347
+	//if startime > 0 {
3348
+	//  db = db.Where("x.ctime >=?", startime)
3349
+	//}
3350
+	//if endtime > 0{
3351
+	//  db = db.Where("x.ctime<=?", endtime)
3352
+	//}
3353
+	//if orgid > 0 {
3354
+	//  db = db.Where("x.org_id = ?", orgid)
3355
+	//}
3356
+	//err = db.Group("x.good_id").Select("x.good_id,sum(x.count) as count").Scan(&autoMatic).Error
3352 3357
 	return autoMatic, err
3353 3358
 
3354 3359
 }