浏览代码

11月8日库存管理

XMLWAN 2 年前
父节点
当前提交
8abfc5686d
共有 1 个文件被更改,包括 467 次插入140 次删除
  1. 467 140
      service/mobile_dialysis_service.go

+ 467 - 140
service/mobile_dialysis_service.go 查看文件

@@ -2799,7 +2799,7 @@ func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (li
2799 2799
 	return
2800 2800
 }
2801 2801
 
2802
-func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
2802
+func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64, good_type int64, ids []int64) ([]*MDialysisGoodsVM, error, int64) {
2803 2803
 	var vms []*MDialysisGoodsVM
2804 2804
 	var total int64
2805 2805
 
@@ -2810,10 +2810,9 @@ func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, pa
2810 2810
 		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2811 2811
 		Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
2812 2812
 			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?   ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
2813
-		}).
2814
-		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
2815
-			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND record_time >= ? AND record_time <=?  AND count > 0", orgID, scheduleDate, end_time)
2816
-		}).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
2813
+		}).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
2814
+		return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND record_time >= ? AND record_time <=?  AND count > 0", orgID, scheduleDate, end_time)
2815
+	}).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
2817 2816
 
2818 2817
 	if scheduleDate != 0 {
2819 2818
 		db = db.Where("schedule_date = ?", scheduleDate)
@@ -2831,7 +2830,12 @@ func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, pa
2831 2830
 		if partition_id != 0 {
2832 2831
 			db = db.Where("partition_id = ?", partition_id)
2833 2832
 		}
2834
-
2833
+		if good_type == 1 {
2834
+			db = db.Where("patient_id in(?)", ids)
2835
+		}
2836
+		if good_type == 2 {
2837
+			db = db.Where("patient_id not in(?)", ids)
2838
+		}
2835 2839
 		db = db.Count(&total)
2836 2840
 		offset := (page - 1) * limit
2837 2841
 
@@ -3053,36 +3057,72 @@ func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, or
3053 3057
 	return advice, err
3054 3058
 }
3055 3059
 
3056
-func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64) ([]*MScheduleDoctorAdviceVM, error) {
3060
+func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64) ([]*MScheduleDoctorAdviceVM, error) {
3057 3061
 	var vms []*MScheduleDoctorAdviceVM
3058 3062
 	adviceWhere := ""
3059 3063
 	adviceCondition := []interface{}{}
3060 3064
 	if adviceType == 0 {
3061 3065
 		if patientType == 0 {
3062 3066
 			if patient_id > 0 {
3063
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
3064
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3067
+				if execution_state > 0 {
3068
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
3069
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3070
+				} else {
3071
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
3072
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3073
+				}
3074
+
3065 3075
 			} else {
3066
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
3067
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3076
+				if execution_state > 0 {
3077
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
3078
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3079
+				} else {
3080
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
3081
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3082
+				}
3083
+
3068 3084
 			}
3069 3085
 
3070 3086
 		} else if patientType == 1 {
3071 3087
 			if patient_id > 0 {
3072
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
3073
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3088
+				if execution_state > 0 {
3089
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
3090
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
3091
+				} else {
3092
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
3093
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3094
+				}
3095
+
3074 3096
 			} else {
3075
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
3076
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3097
+				if execution_state > 0 {
3098
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
3099
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
3100
+				} else {
3101
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
3102
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3103
+				}
3104
+
3077 3105
 			}
3078 3106
 
3079 3107
 		} else if patientType == 2 {
3080 3108
 			if patient_id > 0 {
3081
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
3082
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3109
+				if execution_state > 0 {
3110
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?"
3111
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3112
+				} else {
3113
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
3114
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3115
+				}
3116
+
3083 3117
 			} else {
3084
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
3085
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3118
+				if execution_state > 0 {
3119
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
3120
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3121
+				} else {
3122
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
3123
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3124
+				}
3125
+
3086 3126
 			}
3087 3127
 
3088 3128
 		}
@@ -3090,29 +3130,65 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
3090 3130
 	} else if adviceType == 1 {
3091 3131
 		if patientType == 0 {
3092 3132
 			if patient_id > 0 {
3093
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
3094
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3133
+				if execution_state > 0 {
3134
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
3135
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3136
+				} else {
3137
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
3138
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3139
+				}
3140
+
3095 3141
 			} else {
3096
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ?  "
3097
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3142
+				if execution_state > 0 {
3143
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
3144
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3145
+				} else {
3146
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ?  "
3147
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3148
+				}
3149
+
3098 3150
 			}
3099 3151
 
3100 3152
 		} else if patientType == 1 {
3101 3153
 			if patient_id > 0 {
3102
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
3103
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3154
+				if execution_state > 0 {
3155
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
3156
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
3157
+				} else {
3158
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
3159
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3160
+				}
3161
+
3104 3162
 			} else {
3105
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
3106
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3163
+				if execution_state > 0 {
3164
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
3165
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
3166
+				} else {
3167
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
3168
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3169
+				}
3170
+
3107 3171
 			}
3108 3172
 
3109 3173
 		} else if patientType == 2 {
3110 3174
 			if patient_id > 0 {
3111
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
3112
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3175
+				if execution_state > 0 {
3176
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
3177
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3178
+				} else {
3179
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
3180
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3181
+				}
3182
+
3113 3183
 			} else {
3114
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
3115
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3184
+				if execution_state > 0 {
3185
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
3186
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3187
+				} else {
3188
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
3189
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3190
+				}
3191
+
3116 3192
 			}
3117 3193
 
3118 3194
 		}
@@ -3120,29 +3196,65 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
3120 3196
 	} else if adviceType == 3 {
3121 3197
 		if patientType == 0 {
3122 3198
 			if patient_id > 0 {
3123
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ?  "
3124
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3199
+				if execution_state > 0 {
3200
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and  execution_state = ?"
3201
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3202
+				} else {
3203
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ?  "
3204
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3205
+				}
3206
+
3125 3207
 			} else {
3126
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ?  "
3127
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3208
+				if execution_state > 0 {
3209
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
3210
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3211
+				} else {
3212
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ?  "
3213
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3214
+				}
3215
+
3128 3216
 			}
3129 3217
 
3130 3218
 		} else if patientType == 1 {
3131 3219
 			if patient_id > 0 {
3132
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
3133
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3220
+				if execution_state > 0 {
3221
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
3222
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
3223
+				} else {
3224
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
3225
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3226
+				}
3227
+
3134 3228
 			} else {
3135
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
3136
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3229
+				if execution_state > 0 {
3230
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
3231
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
3232
+				} else {
3233
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
3234
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3235
+				}
3236
+
3137 3237
 			}
3138 3238
 
3139 3239
 		} else if patientType == 2 {
3140 3240
 			if patient_id > 0 {
3141
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and patient_id = ?"
3142
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3241
+				if execution_state > 0 {
3242
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and patient_id = ? and execution_state = ?"
3243
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3244
+				} else {
3245
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and patient_id = ?"
3246
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3247
+				}
3248
+
3143 3249
 			} else {
3144
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0"
3145
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3250
+				if execution_state > 0 {
3251
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and execution_state= ?"
3252
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3253
+				} else {
3254
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0"
3255
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3256
+				}
3257
+
3146 3258
 			}
3147 3259
 
3148 3260
 		}
@@ -3150,28 +3262,65 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
3150 3262
 	} else if adviceType == 2 && len(deliverWay) > 0 {
3151 3263
 		if patientType == 0 {
3152 3264
 			if patient_id > 0 {
3153
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
3154
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
3265
+				if execution_state > 0 {
3266
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
3267
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
3268
+				} else {
3269
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
3270
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
3271
+				}
3272
+
3155 3273
 			} else {
3156
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
3157
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3274
+				if execution_state > 0 {
3275
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
3276
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
3277
+				} else {
3278
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
3279
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3280
+				}
3281
+
3158 3282
 			}
3159 3283
 
3160 3284
 		} else if patientType == 1 {
3161 3285
 			if patient_id > 0 {
3162
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and patient_id = ?"
3163
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
3286
+				if execution_state > 0 {
3287
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and patient_id = ? and execution_state = ?"
3288
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
3289
+				} else {
3290
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and patient_id = ?"
3291
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
3292
+				}
3293
+
3164 3294
 			} else {
3165
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? "
3166
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
3295
+				if execution_state > 0 {
3296
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and execution_state = ?"
3297
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
3298
+				} else {
3299
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? "
3300
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
3301
+				}
3302
+
3167 3303
 			}
3168 3304
 
3169 3305
 		} else if patientType == 2 {
3170 3306
 			if patient_id > 0 {
3307
+				if execution_state > 0 {
3308
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
3309
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
3310
+				} else {
3311
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
3312
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
3313
+				}
3171 3314
 
3172 3315
 			} else {
3173
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ?"
3174
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3316
+				if execution_state > 0 {
3317
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
3318
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
3319
+				} else {
3320
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ?"
3321
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3322
+				}
3323
+
3175 3324
 			}
3176 3325
 
3177 3326
 		}
@@ -3179,29 +3328,65 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
3179 3328
 	} else if adviceType == 2 && len(deliverWay) <= 0 {
3180 3329
 		if patientType == 0 {
3181 3330
 			if patient_id > 0 {
3182
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
3183
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3331
+				if execution_state > 0 {
3332
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
3333
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3334
+				} else {
3335
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
3336
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3337
+				}
3338
+
3184 3339
 			} else {
3185
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
3186
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3340
+				if execution_state > 0 {
3341
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
3342
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3343
+				} else {
3344
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
3345
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3346
+				}
3347
+
3187 3348
 			}
3188 3349
 
3189 3350
 		} else if patientType == 1 {
3190 3351
 			if patient_id > 0 {
3191
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
3192
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3352
+				if execution_state > 0 {
3353
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
3354
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
3355
+				} else {
3356
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
3357
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3358
+				}
3359
+
3193 3360
 			} else {
3194
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
3195
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3361
+				if execution_state > 0 {
3362
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
3363
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
3364
+				} else {
3365
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
3366
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3367
+				}
3368
+
3196 3369
 			}
3197 3370
 
3198 3371
 		} else if patientType == 2 {
3199 3372
 			if patient_id > 0 {
3200
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and patient_id = ?"
3201
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3373
+				if execution_state > 0 {
3374
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and patient_id = ? and execution_state = ?"
3375
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3376
+				} else {
3377
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and patient_id = ?"
3378
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3379
+				}
3380
+
3202 3381
 			} else {
3203
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
3204
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3382
+				if execution_state > 0 {
3383
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and execution_state = ?"
3384
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3385
+				} else {
3386
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
3387
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3388
+				}
3389
+
3205 3390
 			}
3206 3391
 
3207 3392
 		}
@@ -3233,7 +3418,7 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
3233 3418
 	return vms, err
3234 3419
 }
3235 3420
 
3236
-func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64) ([]*HisMScheduleDoctorAdviceVM, error) {
3421
+func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64) ([]*HisMScheduleDoctorAdviceVM, error) {
3237 3422
 
3238 3423
 	var vms []*HisMScheduleDoctorAdviceVM
3239 3424
 	if len(deliverWay) > 0 {
@@ -3245,33 +3430,67 @@ func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string,
3245 3430
 			db = db.Where("partition_id = ?", partitionType)
3246 3431
 		}
3247 3432
 		if patient_id > 0 {
3248
-			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
3249
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3250
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3251
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3252
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
3253
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3254
-					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3255
-				}).
3256
-				Where("status = 1 AND user_org_id = ?", orgID)
3257
-			if scheduleDate != 0 {
3258
-				db = db.Where("schedule_date = ?", scheduleDate)
3433
+			if execution_state > 0 {
3434
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
3435
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3436
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3437
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3438
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?  and patient_id = ? and execution_state = ?", orgID, scheduleDate, deliverWay, patient_id, execution_state).
3439
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3440
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3441
+					}).
3442
+					Where("status = 1 AND user_org_id = ?", orgID)
3443
+				if scheduleDate != 0 {
3444
+					db = db.Where("schedule_date = ?", scheduleDate)
3445
+				}
3446
+				err = db.Find(&vms).Error
3447
+			} else {
3448
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
3449
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3450
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3451
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3452
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
3453
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3454
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3455
+					}).
3456
+					Where("status = 1 AND user_org_id = ?", orgID)
3457
+				if scheduleDate != 0 {
3458
+					db = db.Where("schedule_date = ?", scheduleDate)
3459
+				}
3460
+				err = db.Find(&vms).Error
3259 3461
 			}
3260
-			err = db.Find(&vms).Error
3462
+
3261 3463
 		} else {
3262
-			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3263
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3264
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3265
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3266
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
3267
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3268
-					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3269
-				}).
3270
-				Where("status = 1 AND user_org_id = ?", orgID)
3271
-			if scheduleDate != 0 {
3272
-				db = db.Where("schedule_date = ?", scheduleDate)
3464
+			if execution_state > 0 {
3465
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3466
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3467
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3468
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3469
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
3470
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3471
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3472
+					}).
3473
+					Where("status = 1 AND user_org_id = ?", orgID)
3474
+				if scheduleDate != 0 {
3475
+					db = db.Where("schedule_date = ?", scheduleDate)
3476
+				}
3477
+				err = db.Find(&vms).Error
3478
+			} else {
3479
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3480
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3481
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3482
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3483
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
3484
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3485
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3486
+					}).
3487
+					Where("status = 1 AND user_org_id = ?", orgID)
3488
+				if scheduleDate != 0 {
3489
+					db = db.Where("schedule_date = ?", scheduleDate)
3490
+				}
3491
+				err = db.Find(&vms).Error
3273 3492
 			}
3274
-			err = db.Find(&vms).Error
3493
+
3275 3494
 		}
3276 3495
 
3277 3496
 	} else {
@@ -3283,33 +3502,67 @@ func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string,
3283 3502
 			db = db.Where("partition_id = ?", partitionType)
3284 3503
 		}
3285 3504
 		if patient_id > 0 {
3286
-			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
3287
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3288
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3289
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3290
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3291
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3292
-					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3293
-				}).
3294
-				Where("status = 1 AND user_org_id = ?", orgID)
3295
-			if scheduleDate != 0 {
3296
-				db = db.Where("schedule_date = ?", scheduleDate)
3505
+			if execution_state > 0 {
3506
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
3507
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3508
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3509
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3510
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
3511
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3512
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3513
+					}).
3514
+					Where("status = 1 AND user_org_id = ?", orgID)
3515
+				if scheduleDate != 0 {
3516
+					db = db.Where("schedule_date = ?", scheduleDate)
3517
+				}
3518
+				err = db.Find(&vms).Error
3519
+			} else {
3520
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
3521
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3522
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3523
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3524
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3525
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3526
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3527
+					}).
3528
+					Where("status = 1 AND user_org_id = ?", orgID)
3529
+				if scheduleDate != 0 {
3530
+					db = db.Where("schedule_date = ?", scheduleDate)
3531
+				}
3532
+				err = db.Find(&vms).Error
3297 3533
 			}
3298
-			err = db.Find(&vms).Error
3534
+
3299 3535
 		} else {
3300
-			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3301
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3302
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3303
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3304
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
3305
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3306
-					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3307
-				}).
3308
-				Where("status = 1 AND user_org_id = ?", orgID)
3309
-			if scheduleDate != 0 {
3310
-				db = db.Where("schedule_date = ?", scheduleDate)
3536
+			if execution_state > 0 {
3537
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3538
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3539
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3540
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3541
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
3542
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3543
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3544
+					}).
3545
+					Where("status = 1 AND user_org_id = ?", orgID)
3546
+				if scheduleDate != 0 {
3547
+					db = db.Where("schedule_date = ?", scheduleDate)
3548
+				}
3549
+				err = db.Find(&vms).Error
3550
+			} else {
3551
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3552
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3553
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3554
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3555
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
3556
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3557
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3558
+					}).
3559
+					Where("status = 1 AND user_org_id = ?", orgID)
3560
+				if scheduleDate != 0 {
3561
+					db = db.Where("schedule_date = ?", scheduleDate)
3562
+				}
3563
+				err = db.Find(&vms).Error
3311 3564
 			}
3312
-			err = db.Find(&vms).Error
3565
+
3313 3566
 		}
3314 3567
 
3315 3568
 	}
@@ -3441,36 +3694,16 @@ func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64
3441 3694
 	return
3442 3695
 }
3443 3696
 
3444
-func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64) ([]*HisMScheduleProjectVM, error) {
3697
+func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
3445 3698
 	var vms []*HisMScheduleProjectVM
3446 3699
 
3447 3700
 	if patientType == 0 {
3448 3701
 
3449 3702
 		if patient_id > 0 {
3450
-			db := readDb.
3451
-				Table("xt_schedule").
3452
-				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3453
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3454
-					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3455
-				}).
3456
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3457
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3458
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3459
-				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3460
-					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3461
-				}).
3462
-				Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3463
-					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3464
-				}).Where("status = 1 AND user_org_id = ?", orgID)
3465
-			if scheduleDate != 0 {
3466
-				db = db.Where("schedule_date = ?", scheduleDate)
3467
-			}
3468
-			err = db.Find(&vms).Error
3469
-		} else {
3470
-			if patient_id > 0 {
3703
+			if execution_state > 0 {
3471 3704
 				db := readDb.
3472 3705
 					Table("xt_schedule").
3473
-					Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
3706
+					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3474 3707
 					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3475 3708
 						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3476 3709
 					}).
@@ -3478,7 +3711,7 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3478 3711
 					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3479 3712
 					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3480 3713
 					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3481
-						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3714
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3482 3715
 					}).
3483 3716
 					Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3484 3717
 						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
@@ -3492,11 +3725,11 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3492 3725
 					Table("xt_schedule").
3493 3726
 					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3494 3727
 					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3495
-						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3728
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3496 3729
 					}).
3497 3730
 					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3498 3731
 					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3499
-					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3732
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3500 3733
 					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3501 3734
 						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3502 3735
 					}).
@@ -3508,6 +3741,95 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3508 3741
 				}
3509 3742
 				err = db.Find(&vms).Error
3510 3743
 			}
3744
+
3745
+		} else {
3746
+			if patient_id > 0 {
3747
+				if execution_state > 0 {
3748
+					db := readDb.
3749
+						Table("xt_schedule").
3750
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
3751
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3752
+							return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3753
+						}).
3754
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3755
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3756
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3757
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3758
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3759
+						}).
3760
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3761
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3762
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3763
+					if scheduleDate != 0 {
3764
+						db = db.Where("schedule_date = ?", scheduleDate)
3765
+					}
3766
+					err = db.Find(&vms).Error
3767
+				} else {
3768
+					db := readDb.
3769
+						Table("xt_schedule").
3770
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
3771
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3772
+							return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3773
+						}).
3774
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3775
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3776
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3777
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3778
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3779
+						}).
3780
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3781
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3782
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3783
+					if scheduleDate != 0 {
3784
+						db = db.Where("schedule_date = ?", scheduleDate)
3785
+					}
3786
+					err = db.Find(&vms).Error
3787
+				}
3788
+
3789
+			} else {
3790
+				if execution_state > 0 {
3791
+					db := readDb.
3792
+						Table("xt_schedule").
3793
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3794
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3795
+							return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3796
+						}).
3797
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3798
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3799
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3800
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3801
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3802
+						}).
3803
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3804
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3805
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3806
+					if scheduleDate != 0 {
3807
+						db = db.Where("schedule_date = ?", scheduleDate)
3808
+					}
3809
+					err = db.Find(&vms).Error
3810
+				} else {
3811
+					db := readDb.
3812
+						Table("xt_schedule").
3813
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3814
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3815
+							return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3816
+						}).
3817
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3818
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3819
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3820
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3821
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3822
+						}).
3823
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3824
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3825
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3826
+					if scheduleDate != 0 {
3827
+						db = db.Where("schedule_date = ?", scheduleDate)
3828
+					}
3829
+					err = db.Find(&vms).Error
3830
+				}
3831
+
3832
+			}
3511 3833
 		}
3512 3834
 
3513 3835
 	}
@@ -3625,3 +3947,8 @@ func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, err
3625 3947
 	err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
3626 3948
 	return role, err
3627 3949
 }
3950
+
3951
+func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
3952
+	err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
3953
+	return auto, err
3954
+}