Ver código fonte

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

test_user 2 anos atrás
pai
commit
c970180b2e
29 arquivos alterados com 1748 adições e 473 exclusões
  1. 1 1
      conf/app.conf
  2. 15 6
      controllers/dialysis_api_controller.go
  3. 17 3
      controllers/doctors_api_controller.go
  4. 196 4
      controllers/his_api_controller.go
  5. 7 2
      controllers/mobile_api_controllers/check_weight_api_controller.go
  6. 300 244
      controllers/mobile_api_controllers/dialysis_api_controller.go
  7. 13 3
      controllers/mobile_api_controllers/patient_api_controller.go
  8. 0 6
      controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go
  9. 14 0
      controllers/new_mobile_api_controllers/mobile_his_api_controller.go
  10. 2 0
      controllers/new_mobile_api_controllers/new_mobile_api_router_register.go
  11. 28 8
      controllers/patient_api_controller.go
  12. 152 55
      controllers/pharmacy_controller.go
  13. 5 2
      controllers/print_data_api_controller.go
  14. 1 1
      controllers/self_drug_api_congtroller.go
  15. 4 0
      models/dialysis.go
  16. 3 0
      models/patient_models.go
  17. 11 0
      models/pharmacy_models.go
  18. 1 1
      routers/router.go
  19. 7 1
      service/dialysis_service.go
  20. 3 3
      service/dialysis_solution_service.go
  21. 12 0
      service/his_service.go
  22. 27 3
      service/mobile_dialysis_service.go
  23. 602 8
      service/new_warehouse_service.go
  24. 2 2
      service/patientmanage_service.go
  25. 185 115
      service/pharmacy_service.go
  26. 1 0
      service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go
  27. 8 0
      service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go
  28. 8 0
      service/stock_service.go
  29. 123 5
      service/warhouse_service.go

+ 1 - 1
conf/app.conf Ver arquivo

1
 appname = 血透
1
 appname = 血透
2
 httpport = 9531
2
 httpport = 9531
3
-runmode = prod
3
+runmode = dev
4
 #dev/prod
4
 #dev/prod
5
 
5
 
6
 #
6
 #

+ 15 - 6
controllers/dialysis_api_controller.go Ver arquivo

582
 			if filedConfig.ID > 0 {
582
 			if filedConfig.ID > 0 {
583
 				str = dialyzerPerfusionApparatus
583
 				str = dialyzerPerfusionApparatus
584
 			} else {
584
 			} else {
585
-				str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
585
+				str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
586
 			}
586
 			}
587
 			service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
587
 			service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
588
 		}
588
 		}
858
 		if filedConfig.ID > 0 {
858
 		if filedConfig.ID > 0 {
859
 			str = dialyzerPerfusionApparatus
859
 			str = dialyzerPerfusionApparatus
860
 		} else {
860
 		} else {
861
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
861
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
862
+
862
 		}
863
 		}
863
 		service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
864
 		service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
864
 	}
865
 	}
1353
 	pipeline_connection_desc := c.GetString("pipeline_connection_desc")
1354
 	pipeline_connection_desc := c.GetString("pipeline_connection_desc")
1354
 	collator, _ := c.GetInt64("collator", 0)
1355
 	collator, _ := c.GetInt64("collator", 0)
1355
 	employee_number := c.GetString("employee_number")
1356
 	employee_number := c.GetString("employee_number")
1357
+	dialyzer_batch_number := c.GetString("dialyzer_batch_number")
1358
+	needle_batch_number := c.GetString("needle_batch_number")
1356
 	if id <= 0 {
1359
 	if id <= 0 {
1357
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1360
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1358
 		return
1361
 		return
1423
 		UpdatedTime:                time.Now().Unix(),
1426
 		UpdatedTime:                time.Now().Unix(),
1424
 		CheckDate:                  recordDate.Unix(),
1427
 		CheckDate:                  recordDate.Unix(),
1425
 		EmployeeNumber:             employee_number,
1428
 		EmployeeNumber:             employee_number,
1429
+		DialyzerBatchNumber:        dialyzer_batch_number,
1430
+		NeedleBatchNumber:          needle_batch_number,
1426
 	}
1431
 	}
1427
 
1432
 
1428
 	_, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
1433
 	_, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
1460
 		doubleCheck.CreatedTime = check.CreatedTime
1465
 		doubleCheck.CreatedTime = check.CreatedTime
1461
 		doubleCheck.UpdatedTime = time.Now().Unix()
1466
 		doubleCheck.UpdatedTime = time.Now().Unix()
1462
 		doubleCheck.ID = check.ID
1467
 		doubleCheck.ID = check.ID
1468
+
1463
 		redis := service.RedisClient()
1469
 		redis := service.RedisClient()
1464
 		err := service.UpdateDoubleCheck(&doubleCheck)
1470
 		err := service.UpdateDoubleCheck(&doubleCheck)
1465
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
1471
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
4391
 			}
4397
 			}
4392
 
4398
 
4393
 			//长沙南雅
4399
 			//长沙南雅
4394
-			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 {
4400
+			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
4395
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
4401
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
4396
 
4402
 
4397
 				record.UltrafiltrationRate = ultrafiltration_rate
4403
 				record.UltrafiltrationRate = ultrafiltration_rate
4420
 	}
4426
 	}
4421
 
4427
 
4422
 	//长沙南雅
4428
 	//长沙南雅
4423
-	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 {
4429
+	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
4424
 
4430
 
4425
 		if ultrafiltration_rate > 0 {
4431
 		if ultrafiltration_rate > 0 {
4426
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
4432
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
6033
 
6039
 
6034
 	schedule_type, _ := this.GetInt64("schedule_type")
6040
 	schedule_type, _ := this.GetInt64("schedule_type")
6035
 
6041
 
6036
-	partion_type, _ := this.GetInt64("partion_type")
6042
+	//partion_type, _ := this.GetInt64("partion_type")
6037
 
6043
 
6044
+	partion_type := this.GetString("partion_type")
6045
+	var ids []string
6046
+	ids = strings.Split(partion_type, ",")
6038
 	start_time := this.GetString("selected_date")
6047
 	start_time := this.GetString("selected_date")
6039
 	timeLayout := "2006-01-02"
6048
 	timeLayout := "2006-01-02"
6040
 	loc, _ := time.LoadLocation("Local")
6049
 	loc, _ := time.LoadLocation("Local")
6041
 	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6050
 	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6042
 
6051
 
6043
-	list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, partion_type, startTime.Unix())
6052
+	list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
6044
 
6053
 
6045
 	drug, _ := service.GetAllBaseDrugListTwenty(orgId)
6054
 	drug, _ := service.GetAllBaseDrugListTwenty(orgId)
6046
 	_, config := service.FindXTHisRecordByOrgId(orgId)
6055
 	_, config := service.FindXTHisRecordByOrgId(orgId)

+ 17 - 3
controllers/doctors_api_controller.go Ver arquivo

123
 		hisAdvices, err := service.GetHisDoctorAdvicesTwentyOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id, excution_way, 0, execution_frequency)
123
 		hisAdvices, err := service.GetHisDoctorAdvicesTwentyOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id, excution_way, 0, execution_frequency)
124
 		adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
124
 		adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
125
 		project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id, excution_way)
125
 		project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id, excution_way)
126
+
127
+		drug, _ := service.GetAllBaseDrugListTwenty(orgID)
126
 		for _, item := range project {
128
 		for _, item := range project {
127
 			index := 0
129
 			index := 0
128
 			for _, subItem := range item.HisPrescriptionTeamProject {
130
 			for _, subItem := range item.HisPrescriptionTeamProject {
152
 				"config":         config,
154
 				"config":         config,
153
 				"project_config": project_config,
155
 				"project_config": project_config,
154
 				"project":        project,
156
 				"project":        project,
157
+				"drug":           drug,
155
 			})
158
 			})
156
 		}
159
 		}
157
 	}
160
 	}
1485
 	diagnostic_basis := dataBody["diagnostic_basis"].(string)
1488
 	diagnostic_basis := dataBody["diagnostic_basis"].(string)
1486
 	differential_diagnosis := dataBody["differential_diagnosis"].(string)
1489
 	differential_diagnosis := dataBody["differential_diagnosis"].(string)
1487
 	treatment_plan := dataBody["treatment_plan"].(string)
1490
 	treatment_plan := dataBody["treatment_plan"].(string)
1488
-
1491
+	inspect_date := dataBody["inspect_date"].(string)
1492
+	project_id := dataBody["project_id"].(string)
1489
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1493
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1490
 	firstdisease := models.XtPatientFirstDisease{
1494
 	firstdisease := models.XtPatientFirstDisease{
1491
 		Title:                 title,
1495
 		Title:                 title,
1502
 		Ctime:                 time.Now().Unix(),
1506
 		Ctime:                 time.Now().Unix(),
1503
 		Mtime:                 0,
1507
 		Mtime:                 0,
1504
 		Status:                1,
1508
 		Status:                1,
1509
+		ProjectId:             project_id,
1510
+		InspectDate:           inspect_date,
1505
 	}
1511
 	}
1506
 
1512
 
1507
 	error := service.CreatePatientFirstDisease(firstdisease)
1513
 	error := service.CreatePatientFirstDisease(firstdisease)
1540
 
1546
 
1541
 	id, _ := c.GetInt64("id")
1547
 	id, _ := c.GetInt64("id")
1542
 	list, err := service.GetFirstDetailById(id)
1548
 	list, err := service.GetFirstDetailById(id)
1549
+	ids := strings.Split(list.ProjectId, ",")
1550
+	datelist := strings.Split(list.InspectDate, ",")
1551
+	fmt.Println("list232323232323w", datelist)
1552
+	inspectlist, err := service.GetInspectionItemlist(list.PatientId, datelist, ids)
1543
 	if err == nil {
1553
 	if err == nil {
1544
 		c.ServeSuccessJSON(map[string]interface{}{
1554
 		c.ServeSuccessJSON(map[string]interface{}{
1545
-			"detail": list,
1555
+			"detail":      list,
1556
+			"inspectlist": inspectlist,
1546
 		})
1557
 		})
1547
 		return
1558
 		return
1548
 	}
1559
 	}
1568
 	diagnostic_basis := dataBody["diagnostic_basis"].(string)
1579
 	diagnostic_basis := dataBody["diagnostic_basis"].(string)
1569
 	differential_diagnosis := dataBody["differential_diagnosis"].(string)
1580
 	differential_diagnosis := dataBody["differential_diagnosis"].(string)
1570
 	treatment_plan := dataBody["treatment_plan"].(string)
1581
 	treatment_plan := dataBody["treatment_plan"].(string)
1571
-
1582
+	inspect_date := dataBody["inspect_date"].(string)
1583
+	project_id := dataBody["project_id"].(string)
1572
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1584
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1573
 	firstdisease := models.XtPatientFirstDisease{
1585
 	firstdisease := models.XtPatientFirstDisease{
1574
 		Title:                 title,
1586
 		Title:                 title,
1586
 		Mtime:                 0,
1598
 		Mtime:                 0,
1587
 		Status:                1,
1599
 		Status:                1,
1588
 		ID:                    id,
1600
 		ID:                    id,
1601
+		InspectDate:           inspect_date,
1602
+		ProjectId:             project_id,
1589
 	}
1603
 	}
1590
 
1604
 
1591
 	error := service.UpdatePatientFirstDisease(firstdisease, id)
1605
 	error := service.UpdatePatientFirstDisease(firstdisease, id)

+ 196 - 4
controllers/his_api_controller.go Ver arquivo

1054
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
1054
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
1055
 		return
1055
 		return
1056
 	}
1056
 	}
1057
-	//已发药和已收费限制逻辑
1058
 
1057
 
1058
+	pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
1059
+
1060
+	fmt.Println("0230032032032032032032023---------------", pharmacyConfig.IsOpen)
1061
+	//药品发药出库
1062
+	if pharmacyConfig.IsOpen == 1 {
1063
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1064
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
1065
+			if len(prescriptions) > 0 {
1066
+				for _, item := range prescriptions {
1067
+					items := item.(map[string]interface{})
1068
+					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
1069
+						advices := items["advices"].([]interface{})
1070
+						if len(advices) > 0 {
1071
+							for _, advice := range advices {
1072
+								var drug_id int64
1073
+								var prescribing_number float64
1074
+								var prescribingNumberUnit string
1075
+
1076
+								var adviceId int64
1077
+								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1078
+									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1079
+								}
1080
+								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1081
+									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1082
+									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1083
+								}
1084
+
1085
+								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1086
+									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1087
+								}
1088
+
1089
+								if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1090
+									adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1091
+								}
1092
+
1093
+								drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1094
+								if drug.ID == 0 {
1095
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1096
+									return
1097
+								}
1098
+
1099
+								//查询药品的所有库存
1100
+								list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1101
+
1102
+								var total_count int64
1103
+								for _, it := range list {
1104
+									total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1105
+								}
1106
+								totals := strconv.FormatInt(total_count, 10)
1107
+								//查询该药品是否存在开药记录
1108
+								advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1109
+
1110
+								//新增处方
1111
+								if advicelist.ID == 0 {
1112
+									all_count, _ := strconv.ParseFloat(totals, 64)
1113
+									if prescribingNumberUnit == drug.MinUnit {
1114
+
1115
+										if drug.IsUse != 1 {
1116
+											if prescribing_number > all_count {
1117
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1118
+												return
1119
+											}
1120
+
1121
+										}
1122
+
1123
+									}
1124
+									if prescribingNumberUnit == drug.MaxUnit {
1125
+										num := prescribing_number * float64(drug.MinNumber)
1126
+										if drug.IsUse != 1 {
1127
+											if num > all_count {
1128
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1129
+												return
1130
+											}
1131
+										}
1132
+									}
1133
+								}
1134
+
1135
+								drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
1136
+								if drugOutConfig.IsOpen != 1 {
1137
+									//修改处方
1138
+									for _, advice := range advices {
1139
+										var drug_id int64
1140
+										var prescribing_number float64
1141
+										var prescribingNumberUnit string
1142
+										var prescribingNumber string
1143
+
1144
+										var adviceId int64
1145
+										if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1146
+											drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1147
+										}
1148
+										if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1149
+											prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1150
+											prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1151
+											prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
1152
+										}
1153
+
1154
+										if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1155
+											prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1156
+										}
1157
+
1158
+										if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1159
+											adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1160
+										}
1161
+
1162
+										drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1163
+										if drug.ID == 0 {
1164
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1165
+											return
1166
+										}
1167
+										//查询药品的所有库存
1168
+										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1169
+										var total_count int64
1170
+										for _, it := range list {
1171
+											total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1172
+										}
1173
+										totals := strconv.FormatInt(total_count, 10)
1174
+										//查询该药品是否存在开药记录
1175
+										advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1176
+
1177
+										//新增处方
1178
+										if advicelist.ID == 0 {
1179
+
1180
+											all_count, _ := strconv.ParseFloat(totals, 64)
1181
+											if prescribingNumberUnit == drug.MinUnit {
1182
+												if drug.IsUse != 1 {
1183
+													if prescribing_number > all_count {
1184
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1185
+														return
1186
+													}
1187
+
1188
+												}
1189
+
1190
+											} else {
1191
+												if prescribingNumberUnit == drug.MaxUnit {
1192
+													num := prescribing_number * float64(drug.MinNumber)
1193
+													if drug.IsUse != 1 {
1194
+														if num > all_count {
1195
+															c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1196
+															return
1197
+														}
1198
+
1199
+													}
1200
+
1201
+												}
1202
+											}
1203
+										}
1204
+										//修改处方
1205
+										if advicelist.ID > 0 {
1206
+
1207
+											var device_number int64
1208
+
1209
+											if advicelist.PrescribingNumberUnit == drug.MaxUnit {
1210
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1211
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1212
+												device_number = prescribingNumberInt * drug.MinNumber
1213
+											}
1214
+											if advicelist.PrescribingNumberUnit == drug.MinUnit {
1215
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1216
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1217
+												device_number = prescribingNumberInt
1218
+											}
1219
+
1220
+											var number_count int64
1221
+											if prescribingNumberUnit == drug.MaxUnit {
1222
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1223
+												number_count = prescribingNumberInt * drug.MinNumber
1224
+											}
1225
+											if prescribingNumberUnit == drug.MinUnit {
1226
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1227
+												number_count = prescribingNumberInt
1228
+											}
1229
+
1230
+											//如果修改的数量大于之前修改的数量
1231
+											if (number_count - device_number) > 0 {
1232
+												//如果修改的差数量 大于库存数量
1233
+												if drug.IsUse != 1 {
1234
+													if (number_count - device_number) > total_count {
1235
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1236
+														return
1237
+													}
1238
+												}
1239
+											}
1240
+										}
1241
+									}
1242
+								}
1243
+							}
1244
+						}
1245
+					}
1246
+				}
1247
+			}
1248
+		}
1249
+	}
1250
+
1251
+	//已发药和已收费限制逻辑
1059
 	if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
1252
 	if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
1060
 		//校验库存总量
1253
 		//校验库存总量
1061
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1254
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1282
 														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1475
 														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1283
 														return
1476
 														return
1284
 													}
1477
 													}
1285
-													if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
1478
+													if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
1286
 														// 查询该药品最后一次出库记录
1479
 														// 查询该药品最后一次出库记录
1287
 														outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
1480
 														outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
1288
 
1481
 
1755
 
1948
 
1756
 											}
1949
 											}
1757
 
1950
 
1758
-											//删除记录
1759
 											service.DeleteAutoWarehouse(patient_id, recordDateTime)
1951
 											service.DeleteAutoWarehouse(patient_id, recordDateTime)
1760
 
1952
 
1761
 										}
1953
 										}
2389
 						//如果历史数和当前数据不想等才进行退库出库
2581
 						//如果历史数和当前数据不想等才进行退库出库
2390
 						if out_count != parseIntCount {
2582
 						if out_count != parseIntCount {
2391
 							service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
2583
 							service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
2392
-							fmt.Println("9999999----------------------------------------")
2584
+
2393
 							service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
2585
 							service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
2394
 							detail := models.AutomaticReduceDetail{
2586
 							detail := models.AutomaticReduceDetail{
2395
 								WarehouseOutId:          0,
2587
 								WarehouseOutId:          0,

+ 7 - 2
controllers/mobile_api_controllers/check_weight_api_controller.go Ver arquivo

269
 
269
 
270
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
270
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
271
 
271
 
272
-	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 {
272
+	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
273
 		if adminUserInfo.Org.Id != 10447 {
273
 		if adminUserInfo.Org.Id != 10447 {
274
 			dewater_amount = dewater_amount * 1000
274
 			dewater_amount = dewater_amount * 1000
275
 		}
275
 		}
378
 			newprescribe.RecordDate = theAssessmentDateTime
378
 			newprescribe.RecordDate = theAssessmentDateTime
379
 			newprescribe.DewaterAmount = dewater_amount
379
 			newprescribe.DewaterAmount = dewater_amount
380
 			newprescribe.TargetUltrafiltration = dewater_amount
380
 			newprescribe.TargetUltrafiltration = dewater_amount
381
+			newprescribe.PrescriptionWater = dewater_amount
381
 			newprescribe.Status = 1
382
 			newprescribe.Status = 1
382
 			if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
383
 			if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
383
 				newprescribe.Remark = dialysisSolution.Remark
384
 				newprescribe.Remark = dialysisSolution.Remark
461
 				newprescribe.RecordDate = theAssessmentDateTime
462
 				newprescribe.RecordDate = theAssessmentDateTime
462
 				newprescribe.DewaterAmount = dewater_amount
463
 				newprescribe.DewaterAmount = dewater_amount
463
 				newprescribe.TargetUltrafiltration = dewater_amount
464
 				newprescribe.TargetUltrafiltration = dewater_amount
465
+				newprescribe.PrescriptionWater = dewater_amount
464
 				newprescribe.Status = 1
466
 				newprescribe.Status = 1
465
 				newprescribe.Remark = lastDialysisPrescribe.Remark
467
 				newprescribe.Remark = lastDialysisPrescribe.Remark
466
 				if adminUserInfo.Org.Id == 10340 {
468
 				if adminUserInfo.Org.Id == 10340 {
681
 					evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
683
 					evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
682
 				}
684
 				}
683
 
685
 
684
-				if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
686
+				if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
685
 					evaluation.PulseFrequency = 80
687
 					evaluation.PulseFrequency = 80
686
 				}
688
 				}
687
 				if adminUserInfo.Org.Id == 10440 {
689
 				if adminUserInfo.Org.Id == 10440 {
690
 				if adminUserInfo.Org.Id == 10469 {
692
 				if adminUserInfo.Org.Id == 10469 {
691
 					evaluation.Temperature = 36.5
693
 					evaluation.Temperature = 36.5
692
 				}
694
 				}
695
+				if adminUserInfo.Org.Id == 10471 {
696
+					evaluation.Temperature = 36.5
697
+				}
693
 			}
698
 			}
694
 		} else {
699
 		} else {
695
 			evaluation.UpdatedTime = time.Now().Unix()
700
 			evaluation.UpdatedTime = time.Now().Unix()

+ 300 - 244
controllers/mobile_api_controllers/dialysis_api_controller.go Ver arquivo

744
 	pipeline_connection_desc := c.GetString("pipeline_connection_desc")
744
 	pipeline_connection_desc := c.GetString("pipeline_connection_desc")
745
 	collator, _ := c.GetInt64("collator", 0)
745
 	collator, _ := c.GetInt64("collator", 0)
746
 	employee_number := c.GetString("employee_number")
746
 	employee_number := c.GetString("employee_number")
747
-
747
+	dialyzer_batch_number := c.GetString("dialyzer_batch_number")
748
+	needle_batch_number := c.GetString("needle_batch_number")
748
 	if id <= 0 {
749
 	if id <= 0 {
749
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
750
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
750
 		return
751
 		return
828
 		CheckDate:                  recordDate.Unix(),
829
 		CheckDate:                  recordDate.Unix(),
829
 		UpdatedTime:                time.Now().Unix(),
830
 		UpdatedTime:                time.Now().Unix(),
830
 		EmployeeNumber:             employee_number,
831
 		EmployeeNumber:             employee_number,
832
+		DialyzerBatchNumber:        dialyzer_batch_number,
833
+		NeedleBatchNumber:          needle_batch_number,
831
 	}
834
 	}
832
 
835
 
833
 	_, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
836
 	_, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
885
 		doubleCheck.CreatedTime = check.CreatedTime
888
 		doubleCheck.CreatedTime = check.CreatedTime
886
 		doubleCheck.ID = check.ID
889
 		doubleCheck.ID = check.ID
887
 		doubleCheck.EmployeeNumber = employee_number
890
 		doubleCheck.EmployeeNumber = employee_number
891
+		doubleCheck.NeedleBatchNumber = needle_batch_number
892
+		doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
888
 		err := service.UpdateDoubleCheck(&doubleCheck)
893
 		err := service.UpdateDoubleCheck(&doubleCheck)
889
 		//针对长沙南雅
894
 		//针对长沙南雅
890
 		if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
895
 		if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
1490
 		if filedConfig.ID > 0 {
1495
 		if filedConfig.ID > 0 {
1491
 			str = dialyzerPerfusionApparatus
1496
 			str = dialyzerPerfusionApparatus
1492
 		} else {
1497
 		} else {
1493
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
1498
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
1494
 		}
1499
 		}
1495
 		service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
1500
 		service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
1496
 	}
1501
 	}
2391
 		dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
2396
 		dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
2392
 		dialysisOrder.EndTime = endDate.Unix()
2397
 		dialysisOrder.EndTime = endDate.Unix()
2393
 
2398
 
2399
+		// 长沙南雅需求
2400
+		if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
2401
+
2402
+			//获取最后1条监测的数据
2403
+			fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
2404
+			lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
2405
+			var accumulatedBloodVolume float64
2406
+			accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
2407
+			fmt.Println("累计血容量", accumulatedBloodVolume)
2408
+			err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
2409
+			fmt.Println(err)
2410
+		}
2411
+
2394
 		go func() {
2412
 		go func() {
2395
 			ssoDomain := beego.AppConfig.String("call_domain")
2413
 			ssoDomain := beego.AppConfig.String("call_domain")
2396
 			api := ssoDomain + "/index/downpatient"
2414
 			api := ssoDomain + "/index/downpatient"
3022
 		if filedConfig.ID > 0 {
3040
 		if filedConfig.ID > 0 {
3023
 			str = dialyzerPerfusionApparatus
3041
 			str = dialyzerPerfusionApparatus
3024
 		} else {
3042
 		} else {
3025
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
3043
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
3026
 		}
3044
 		}
3027
 		service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
3045
 		service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
3028
 	}
3046
 	}
3604
 				record.UltrafiltrationRate = ultrafiltration_rate
3622
 				record.UltrafiltrationRate = ultrafiltration_rate
3605
 			}
3623
 			}
3606
 
3624
 
3607
-			fmt.Println("adminiNof2323323232", adminInfo.Org.Id)
3608
-			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10469 {
3625
+			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10471 {
3609
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
3626
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
3610
-				fmt.Println("ooooooooooo", ultrafiltration_rate)
3627
+
3611
 				record.UltrafiltrationRate = ultrafiltration_rate
3628
 				record.UltrafiltrationRate = ultrafiltration_rate
3612
 			}
3629
 			}
3613
 			//if template.TemplateId == 47 {
3630
 			//if template.TemplateId == 47 {
3636
 	}
3653
 	}
3637
 
3654
 
3638
 	//长沙南雅
3655
 	//长沙南雅
3639
-	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 {
3640
-		fmt.Println("ultrafiltration_rate-------", ultrafiltration_rate)
3656
+	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10471 {
3657
+
3641
 		if ultrafiltration_rate > 0 {
3658
 		if ultrafiltration_rate > 0 {
3642
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
3659
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
3643
-			fmt.Println("ultrafiltration_volume=======", ultrafiltration_volume)
3660
+
3644
 			record.UltrafiltrationVolume = ultrafiltration_volume
3661
 			record.UltrafiltrationVolume = ultrafiltration_volume
3645
 		}
3662
 		}
3646
 
3663
 
3647
 	}
3664
 	}
3648
 	//长沙南雅累计血容量自动计算
3665
 	//长沙南雅累计血容量自动计算
3649
-	if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 {
3650
-		record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
3651
-	}
3666
+	//if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 ||  adminInfo.Org.Id == 3877{
3667
+	//	record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
3668
+	//}
3652
 
3669
 
3653
 	if template.TemplateId == 47 || template.TemplateId == 54 {
3670
 	if template.TemplateId == 47 || template.TemplateId == 54 {
3654
 		record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
3671
 		record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
4564
 	}
4581
 	}
4565
 
4582
 
4566
 	if len(advices) > 0 {
4583
 	if len(advices) > 0 {
4584
+
4567
 		list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
4585
 		list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
4568
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
4586
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
4569
 		redis := service.RedisClient()
4587
 		redis := service.RedisClient()
4904
 			}
4922
 			}
4905
 		}
4923
 		}
4906
 
4924
 
4907
-		fmt.Println("active------------------------------------", active)
4908
-		fmt.Println("len------------------------------", len(goods))
4909
 		//新增
4925
 		//新增
4910
 		if active == 1 && len(goods) > 0 {
4926
 		if active == 1 && len(goods) > 0 {
4911
 			for _, item := range dialysisBefor {
4927
 			for _, item := range dialysisBefor {
5677
 
5693
 
5678
 				}
5694
 				}
5679
 
5695
 
5680
-				//退库
5681
-				for _, item := range cancelbefor {
5682
-					warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5683
-					creater := adminInfo.AdminUser.Id
5696
+				if len(cancelbefor) > 0 {
5684
 					//退库
5697
 					//退库
5685
-					//err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
5686
-					//查询该患者当天已经出库的耗材信息
5698
+					for _, item := range cancelbefor {
5699
+						warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5700
+						creater := adminInfo.AdminUser.Id
5687
 
5701
 
5688
-					warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
5702
+						//查询该患者当天已经出库的耗材信息
5703
+						warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
5689
 
5704
 
5690
-					var delete_count int64 = 0
5705
+						var delete_count int64 = 0
5691
 
5706
 
5692
-					delete_count = warehouseOutInfos.Count - item.Count
5707
+						delete_count = warehouseOutInfos.Count - item.Count
5693
 
5708
 
5694
-					//增加库存数量
5695
-					service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5709
+						//增加库存数量
5710
+						service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5696
 
5711
 
5697
-					//增加出库库存数量
5698
-					service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5712
+						//减少实际出库库存数量
5713
+						service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5699
 
5714
 
5700
-					// 删除出库完成后,要增加对应批次的库存数量
5715
+						// 删除出库完成后,要增加对应批次的库存数量
5701
 
5716
 
5702
-					service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5717
+						service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5703
 
5718
 
5704
-					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5719
+						houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5705
 
5720
 
5706
-					//更新剩余库存
5707
-					goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5708
-					var flush_count int64
5709
-					for _, it := range goodListOne {
5710
-						flush_count += it.StockCount
5711
-					}
5712
-					service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5721
+						//更新剩余库存
5722
+						goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5723
+						var flush_count int64
5724
+						for _, it := range goodListOne {
5725
+							flush_count += it.StockCount
5726
+						}
5727
+						service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5713
 
5728
 
5714
-					//查询剩余库存
5715
-					goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5716
-					var sum_count int64
5717
-					for _, item := range goodList {
5718
-						sum_count += item.StockCount
5719
-					}
5729
+						//查询剩余库存
5730
+						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5731
+						var sum_count int64
5732
+						for _, item := range goodList {
5733
+							sum_count += item.StockCount
5734
+						}
5720
 
5735
 
5721
-					// 在出库记录表里记录退库详情
5722
-					warehouseOutInfo := &models.WarehouseOutInfo{
5723
-						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5724
-						WarehouseOutId:          warehouseOut.ID,
5725
-						Status:                  1,
5726
-						Ctime:                   time.Now().Unix(),
5727
-						OrgId:                   adminInfo.Org.Id,
5728
-						Type:                    1,
5729
-						IsSys:                   1,
5730
-						SysRecordTime:           record_time,
5731
-						GoodTypeId:              item.GoodTypeId,
5732
-						GoodId:                  item.GoodId,
5733
-						PatientId:               patient_id,
5734
-						ConsumableType:          2,
5735
-						StorehouseId:            houseConfig.StorehouseOutInfo,
5736
-						IsCheck:                 1,
5737
-						OverCount:               sum_count,
5738
-					}
5739
-					warehouseOutInfo.Count = item.Count
5740
-
5741
-					stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
5742
-					warehouseOutInfo.Price = stockInInfo.Price
5743
-					warehouseOutInfo.Dealer = stockInInfo.Dealer
5744
-					warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
5745
-					warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
5746
-					warehouseOutInfo.ProductDate = stockInInfo.ProductDate
5747
-					warehouseOutInfo.Number = warehouseOutInfos.Number
5748
-					warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
5749
-					warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
5750
-					//查找当天是否存在出库记录
5751
-					_, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
5752
-
5753
-					if errcod == gorm.ErrRecordNotFound {
5754
-						service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5755
-						//插入详情明细表
5756
-						stockFlow := models.VmStockFlow{
5736
+						// 在出库记录表里记录退库详情
5737
+						warehouseOutInfo := &models.WarehouseOutInfo{
5757
 							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5738
 							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5758
 							WarehouseOutId:          warehouseOut.ID,
5739
 							WarehouseOutId:          warehouseOut.ID,
5759
-							GoodId:                  item.GoodId,
5760
-							Number:                  warehouseOutInfos.Number,
5761
-							ProductDate:             stockInInfo.ProductDate,
5762
-							ExpireDate:              stockInInfo.ExpiryDate,
5763
-							Count:                   item.Count,
5764
-							Price:                   stockInInfo.Price,
5765
 							Status:                  1,
5740
 							Status:                  1,
5766
 							Ctime:                   time.Now().Unix(),
5741
 							Ctime:                   time.Now().Unix(),
5767
-							UserOrgId:               adminInfo.Org.Id,
5768
-							Manufacturer:            stockInInfo.Manufacturer,
5769
-							Dealer:                  stockInInfo.Dealer,
5770
-							LicenseNumber:           stockInInfo.LicenseNumber,
5771
-							IsEdit:                  2,
5772
-							Creator:                 creater,
5773
-							SystemTime:              record_time,
5774
-							ConsumableType:          3,
5775
-							WarehousingDetailId:     0,
5742
+							OrgId:                   adminInfo.Org.Id,
5743
+							Type:                    1,
5776
 							IsSys:                   1,
5744
 							IsSys:                   1,
5777
-							UpdateCreator:           creater,
5745
+							SysRecordTime:           record_time,
5746
+							GoodTypeId:              item.GoodTypeId,
5747
+							GoodId:                  item.GoodId,
5778
 							PatientId:               patient_id,
5748
 							PatientId:               patient_id,
5749
+							ConsumableType:          2,
5779
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5750
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5751
+							IsCheck:                 1,
5752
+							OverCount:               sum_count,
5780
 						}
5753
 						}
5781
-						exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5782
-						if errflow == gorm.ErrRecordNotFound {
5783
-							//创建流水表
5784
-							err := service.CreateStockFlowOne(stockFlow)
5785
-							fmt.Println("err", err)
5786
-						} else if errflow == nil {
5754
+						warehouseOutInfo.Count = item.Count
5755
+
5756
+						stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
5757
+						warehouseOutInfo.Price = stockInInfo.Price
5758
+						warehouseOutInfo.Dealer = stockInInfo.Dealer
5759
+						warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
5760
+						warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
5761
+						warehouseOutInfo.ProductDate = stockInInfo.ProductDate
5762
+						warehouseOutInfo.Number = warehouseOutInfos.Number
5763
+						warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
5764
+						warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
5765
+						//查找当天是否存在出库记录
5766
+						_, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
5767
+
5768
+						if errcod == gorm.ErrRecordNotFound {
5769
+							service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5787
 							//插入详情明细表
5770
 							//插入详情明细表
5788
 							stockFlow := models.VmStockFlow{
5771
 							stockFlow := models.VmStockFlow{
5789
-								ID:                      exsit.ID,
5790
-								WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5791
 								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5772
 								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5792
 								WarehouseOutId:          warehouseOut.ID,
5773
 								WarehouseOutId:          warehouseOut.ID,
5793
 								GoodId:                  item.GoodId,
5774
 								GoodId:                  item.GoodId,
5794
 								Number:                  warehouseOutInfos.Number,
5775
 								Number:                  warehouseOutInfos.Number,
5795
 								ProductDate:             stockInInfo.ProductDate,
5776
 								ProductDate:             stockInInfo.ProductDate,
5796
 								ExpireDate:              stockInInfo.ExpiryDate,
5777
 								ExpireDate:              stockInInfo.ExpiryDate,
5797
-								Count:                   exsit.Count - delete_count,
5778
+								Count:                   item.Count,
5798
 								Price:                   stockInInfo.Price,
5779
 								Price:                   stockInInfo.Price,
5799
 								Status:                  1,
5780
 								Status:                  1,
5800
 								Ctime:                   time.Now().Unix(),
5781
 								Ctime:                   time.Now().Unix(),
5812
 								PatientId:               patient_id,
5793
 								PatientId:               patient_id,
5813
 								StorehouseId:            houseConfig.StorehouseOutInfo,
5794
 								StorehouseId:            houseConfig.StorehouseOutInfo,
5814
 							}
5795
 							}
5796
+							exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5797
+							if errflow == gorm.ErrRecordNotFound {
5798
+								//创建流水表
5799
+								err := service.CreateStockFlowOne(stockFlow)
5800
+								fmt.Println("err", err)
5801
+							} else if errflow == nil {
5802
+								//插入详情明细表
5803
+								stockFlow := models.VmStockFlow{
5804
+									ID:                      exsit.ID,
5805
+									WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5806
+									WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5807
+									WarehouseOutId:          warehouseOut.ID,
5808
+									GoodId:                  item.GoodId,
5809
+									Number:                  warehouseOutInfos.Number,
5810
+									ProductDate:             stockInInfo.ProductDate,
5811
+									ExpireDate:              stockInInfo.ExpiryDate,
5812
+									Count:                   exsit.Count - delete_count,
5813
+									Price:                   stockInInfo.Price,
5814
+									Status:                  1,
5815
+									Ctime:                   time.Now().Unix(),
5816
+									UserOrgId:               adminInfo.Org.Id,
5817
+									Manufacturer:            stockInInfo.Manufacturer,
5818
+									Dealer:                  stockInInfo.Dealer,
5819
+									LicenseNumber:           stockInInfo.LicenseNumber,
5820
+									IsEdit:                  2,
5821
+									Creator:                 creater,
5822
+									SystemTime:              record_time,
5823
+									ConsumableType:          3,
5824
+									WarehousingDetailId:     0,
5825
+									IsSys:                   1,
5826
+									UpdateCreator:           creater,
5827
+									PatientId:               patient_id,
5828
+									StorehouseId:            houseConfig.StorehouseOutInfo,
5829
+								}
5815
 
5830
 
5816
-							service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5817
-						}
5831
+								service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5832
+							}
5818
 
5833
 
5819
-					} else if errcod == nil {
5820
-						service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
5834
+						} else if errcod == nil {
5835
+							service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
5821
 
5836
 
5822
-						fmt.Println("进来-------------------------------------------------")
5837
+							//查询剩余库存
5838
+							goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5839
+							var sum_count int64
5840
+							for _, item := range goodList {
5841
+								sum_count += item.StockCount
5842
+							}
5823
 
5843
 
5824
-						//查询剩余库存
5825
-						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5826
-						var sum_count int64
5827
-						for _, item := range goodList {
5828
-							sum_count += item.StockCount
5844
+							//创建退库单,生成退库数据
5845
+							houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5846
+							good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
5847
+
5848
+							operation_time := time.Now().Unix()
5849
+							creater := adminInfo.AdminUser.Id
5850
+							//创建退库单
5851
+							timeStr := time.Now().Format("2006-01-02")
5852
+							timeArr := strings.Split(timeStr, "-")
5853
+							total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
5854
+							total = total + 1
5855
+							orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
5856
+
5857
+							cancelStock := models.CancelStock{
5858
+								OrderNumber:  orderNumber,
5859
+								OperaTime:    operation_time,
5860
+								OrgId:        adminInfo.Org.Id,
5861
+								Creater:      creater,
5862
+								Ctime:        time.Now().Unix(),
5863
+								Status:       1,
5864
+								ReturnTime:   record_time,
5865
+								Type:         1,
5866
+								StorehouseId: houseConfig.StorehouseOutInfo,
5867
+								IsCheck:      1,
5868
+							}
5869
+							_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
5870
+							if msgerrkonde == gorm.ErrRecordNotFound {
5871
+								service.AddSigleCancelStock(&cancelStock)
5872
+							}
5873
+							cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
5874
+
5875
+							//查询是否有出库
5876
+							info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
5877
+
5878
+							manufacturer, _ := service.GetManufactureById(info.Manufacturer)
5879
+							deaerler, _ := service.GetDealerById(info.Dealer)
5880
+
5881
+							if info.ID > 0 {
5882
+								cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
5883
+								cancelStockInfo := models.CancelStockInfo{
5884
+									GoodId:          item.GoodId,
5885
+									CancelStockId:   cancel.ID,
5886
+									GoodTypeId:      good.GoodTypeId,
5887
+									Count:           delete_count,
5888
+									Price:           info.Price,
5889
+									Total:           0,
5890
+									ProductDate:     info.ProductDate,
5891
+									ExpiryDate:      info.ExpiryDate,
5892
+									Ctime:           time.Now().Unix(),
5893
+									Status:          1,
5894
+									OrgId:           adminInfo.Org.Id,
5895
+									OrderNumber:     cancel.OrderNumber,
5896
+									Type:            0,
5897
+									Dealer:          deaerler.DealerName,
5898
+									Manufacturer:    manufacturer.ManufacturerName,
5899
+									Number:          info.Number,
5900
+									RegisterAccount: "",
5901
+									Remark:          "",
5902
+									WarehouseInfoId: info.WarehouseInfotId,
5903
+									PatientId:       info.PatientId,
5904
+									RecordDate:      info.SysRecordTime,
5905
+									StorehouseId:    houseConfig.StorehouseOutInfo,
5906
+									IsCheck:         1,
5907
+								}
5908
+
5909
+								service.CreateCancelStockInfoOne(&cancelStockInfo)
5910
+
5911
+								//退库数量增加
5912
+								service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
5913
+
5914
+								//查询剩余库存
5915
+								goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5916
+								var over_count int64
5917
+								for _, it := range goodList {
5918
+									over_count += it.StockCount
5919
+								}
5920
+
5921
+								flow := models.VmStockFlow{
5922
+									WarehousingId:           info.WarehouseInfotId,
5923
+									GoodId:                  item.GoodId,
5924
+									Number:                  info.Number,
5925
+									LicenseNumber:           info.LicenseNumber,
5926
+									Count:                   delete_count,
5927
+									UserOrgId:               adminInfo.Org.Id,
5928
+									PatientId:               patient_id,
5929
+									SystemTime:              info.SysRecordTime,
5930
+									ConsumableType:          7,
5931
+									IsSys:                   0,
5932
+									WarehousingOrder:        "",
5933
+									WarehouseOutId:          info.WarehouseOutId,
5934
+									WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
5935
+									IsEdit:                  0,
5936
+									CancelStockId:           cancel.ID,
5937
+									CancelOrderNumber:       cancel.OrderNumber,
5938
+									Manufacturer:            manufacturer.ID,
5939
+									Dealer:                  0,
5940
+									Creator:                 adminInfo.AdminUser.Id,
5941
+									UpdateCreator:           0,
5942
+									Status:                  1,
5943
+									Ctime:                   time.Now().Unix(),
5944
+									Mtime:                   0,
5945
+									Price:                   info.Price,
5946
+									WarehousingDetailId:     info.WarehouseInfotId,
5947
+									WarehouseOutDetailId:    info.ID,
5948
+									CancelOutDetailId:       cancelInfo.ID,
5949
+									ProductDate:             info.ProductDate,
5950
+									ExpireDate:              info.ExpiryDate,
5951
+									StorehouseId:            houseConfig.StorehouseOutInfo,
5952
+									OverCount:               over_count,
5953
+								}
5954
+								service.CreateStockFlowOne(flow)
5955
+
5956
+							}
5829
 						}
5957
 						}
5830
-						//插入详情明细表
5831
-						stockFlow := models.VmStockFlow{
5832
-							WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5833
-							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5834
-							WarehouseOutId:          warehouseOut.ID,
5958
+
5959
+						//更改自动出库的表格
5960
+						details := models.BloodAutomaticReduceDetail{
5961
+							WarehouseOutId:          warehouseOutInfo.ID,
5962
+							WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
5963
+							PatientId:               patient_id,
5964
+							Ctime:                   time.Now().Unix(),
5965
+							Mtime:                   time.Now().Unix(),
5966
+							Status:                  1,
5967
+							RecordTime:              record_time,
5968
+							OrgId:                   adminInfo.Org.Id,
5835
 							GoodId:                  item.GoodId,
5969
 							GoodId:                  item.GoodId,
5836
-							Number:                  warehouseOutInfos.Number,
5837
-							ProductDate:             stockInInfo.ProductDate,
5838
-							ExpireDate:              stockInInfo.ExpiryDate,
5970
+							GoodTypeId:              item.GoodTypeId,
5839
 							Count:                   item.Count,
5971
 							Count:                   item.Count,
5840
-							Price:                   stockInInfo.Price,
5841
-							Status:                  1,
5842
-							Ctime:                   time.Now().Unix(),
5843
-							UserOrgId:               adminInfo.Org.Id,
5844
-							Manufacturer:            stockInInfo.Manufacturer,
5845
-							Dealer:                  stockInInfo.Dealer,
5846
-							LicenseNumber:           stockInInfo.LicenseNumber,
5847
-							IsEdit:                  2,
5848
-							Creator:                 creater,
5849
-							SystemTime:              record_time,
5850
-							ConsumableType:          3,
5851
-							WarehousingDetailId:     0,
5852
-							IsSys:                   1,
5853
-							UpdateCreator:           creater,
5854
-							PatientId:               patient_id,
5855
-							ReturnCount:             delete_count,
5856
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5972
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5857
-							OverCount:               sum_count,
5858
 						}
5973
 						}
5859
-						exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5974
+						//查询当天耗材是否已经存在数据
5975
+						_, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5860
 
5976
 
5861
-						if errflows == gorm.ErrRecordNotFound {
5862
-							//创建流水表
5863
-							service.CreateStockFlowOne(stockFlow)
5864
-						} else if errflows == nil {
5865
-							stockFlow := models.VmStockFlow{
5866
-								WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5867
-								ID:                      exsit.ID,
5868
-								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5869
-								WarehouseOutId:          warehouseOut.ID,
5870
-								GoodId:                  item.GoodId,
5871
-								Number:                  warehouseOutInfos.Number,
5872
-								ProductDate:             stockInInfo.ProductDate,
5873
-								ExpireDate:              stockInInfo.ExpiryDate,
5874
-								Count:                   exsit.Count - delete_count,
5875
-								Price:                   stockInInfo.Price,
5876
-								Status:                  1,
5877
-								Ctime:                   time.Now().Unix(),
5878
-								UserOrgId:               adminInfo.Org.Id,
5879
-								Manufacturer:            stockInInfo.Manufacturer,
5880
-								Dealer:                  stockInInfo.Dealer,
5881
-								LicenseNumber:           stockInInfo.LicenseNumber,
5882
-								IsEdit:                  2,
5883
-								Creator:                 creater,
5884
-								SystemTime:              record_time,
5885
-								ConsumableType:          3,
5886
-								WarehousingDetailId:     0,
5887
-								IsSys:                   1,
5888
-								UpdateCreator:           creater,
5889
-								PatientId:               patient_id,
5890
-								ReturnCount:             delete_count,
5891
-								StorehouseId:            houseConfig.StorehouseOutInfo,
5892
-								OverCount:               exsit.OverCount + delete_count,
5893
-							}
5894
-							fmt.Println("stockFlow--------------------", stockFlow.OverCount)
5895
-							service.UpdatedStockFlowFive(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5896
-						}
5977
+						if errcode == gorm.ErrRecordNotFound {
5978
+							service.CreateAutoReduceRecord(&details)
5897
 
5979
 
5898
-					}
5980
+						} else if errcode == nil {
5981
+							service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5982
+							service.CreateAutoReduceRecord(&details)
5899
 
5983
 
5900
-					//更改自动出库的表格
5901
-					details := models.BloodAutomaticReduceDetail{
5902
-						WarehouseOutId:          warehouseOutInfo.ID,
5903
-						WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
5904
-						PatientId:               patient_id,
5905
-						Ctime:                   time.Now().Unix(),
5906
-						Mtime:                   time.Now().Unix(),
5907
-						Status:                  1,
5908
-						RecordTime:              record_time,
5909
-						OrgId:                   adminInfo.Org.Id,
5910
-						GoodId:                  item.GoodId,
5911
-						GoodTypeId:              item.GoodTypeId,
5912
-						Count:                   item.Count,
5913
-						StorehouseId:            houseConfig.StorehouseOutInfo,
5914
-					}
5915
-					//查询当天耗材是否已经存在数据
5916
-					_, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5917
-
5918
-					if errcode == gorm.ErrRecordNotFound {
5919
-						service.CreateAutoReduceRecord(&details)
5984
+						}
5920
 
5985
 
5921
-					} else if errcode == nil {
5922
-						service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5923
-						service.CreateAutoReduceRecord(&details)
5986
+						//查询默认仓库
5987
+						storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5988
+						stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5989
+						var total_count int64
5990
+						for _, it := range stockList {
5991
+							total_count += it.StockCount
5992
+						}
5993
+						//基础库插入数据
5994
+						service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5924
 
5995
 
5925
 					}
5996
 					}
5926
-
5927
-					//errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
5928
-					//fmt.Println("errOne", errOne)
5929
-
5930
-					//查询默认仓库
5931
-					storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5932
-					stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5933
-					var total_count int64
5934
-					for _, it := range stockList {
5935
-						total_count += it.StockCount
5936
-					}
5937
-					//基础库插入数据
5938
-					service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5939
-
5940
 				}
5997
 				}
5941
 
5998
 
5942
 				fmt.Println("lnet---------------------------", len(outbefor))
5999
 				fmt.Println("lnet---------------------------", len(outbefor))
5950
 						//计算当前出库和最后一次出库数据相差数据
6007
 						//计算当前出库和最后一次出库数据相差数据
5951
 						last_total = item.Count - goodInfoOne.Count
6008
 						last_total = item.Count - goodInfoOne.Count
5952
 
6009
 
5953
-						//查询该批次剩余库存
5954
-						lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
5955
-
5956
-						if lastInfo.StockCount == 0 {
5957
-							//查询该耗材的总库存
5958
-							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
5959
-							if wareinfo.StockCount == 0 {
5960
-								goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
5961
-								c.ServeSuccessJSON(map[string]interface{}{
5962
-									"message":            "1",
5963
-									"good_name":          goodObj.GoodName,
5964
-									"specification_name": goodObj.SpecificationName,
5965
-								})
5966
-								return
5967
-							}
5968
-
5969
-						}
5970
-
5971
 						//查询该耗材的总库存
6010
 						//查询该耗材的总库存
5972
 						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
6011
 						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
6012
+
5973
 						// 如果库存差大于剩余库存则提示库存不足
6013
 						// 如果库存差大于剩余库存则提示库存不足
5974
 						if last_total > wareinfo.StockCount {
6014
 						if last_total > wareinfo.StockCount {
5975
 							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6015
 							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6035
 								ProjectId:    0,
6075
 								ProjectId:    0,
6036
 								StorehouseId: houseConfig.StorehouseOutInfo,
6076
 								StorehouseId: houseConfig.StorehouseOutInfo,
6037
 							}
6077
 							}
6038
-							//fmt.Println("prepare", prepare.Count)
6039
-							//fmt.Println("count", item.Count)
6078
+
6040
 							service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
6079
 							service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
6041
 							//增加出库数量
6080
 							//增加出库数量
6042
 							service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
6081
 							service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
6096
 					for _, it := range goodList {
6135
 					for _, it := range goodList {
6097
 						flush_count += it.StockCount
6136
 						flush_count += it.StockCount
6098
 					}
6137
 					}
6138
+
6099
 					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
6139
 					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
6100
 
6140
 
6101
 				}
6141
 				}
6360
 				}
6400
 				}
6361
 				project_id := int64(items["project_id"].(float64))
6401
 				project_id := int64(items["project_id"].(float64))
6362
 
6402
 
6403
+				new_count := int64(items["new_count"].(float64))
6404
+				old_count := int64(items["old_count"].(float64))
6405
+
6363
 				prepare := &models.DialysisBeforePrepareGoods{
6406
 				prepare := &models.DialysisBeforePrepareGoods{
6364
 					GoodId:       good_id,
6407
 					GoodId:       good_id,
6365
 					GoodTypeId:   good_type_id,
6408
 					GoodTypeId:   good_type_id,
6366
 					Count:        count,
6409
 					Count:        count,
6367
 					ProjectId:    project_id,
6410
 					ProjectId:    project_id,
6368
 					StorehouseId: houseConfig.StorehouseOutInfo,
6411
 					StorehouseId: houseConfig.StorehouseOutInfo,
6412
+					NewCount:     new_count,
6413
+					OldCount:     old_count,
6369
 				}
6414
 				}
6415
+
6370
 				beforePrepares = append(beforePrepares, prepare)
6416
 				beforePrepares = append(beforePrepares, prepare)
6371
 
6417
 
6372
 				newPrepare := &models.NewDialysisBeforePrepareGoods{
6418
 				newPrepare := &models.NewDialysisBeforePrepareGoods{
6375
 					Count:        count,
6421
 					Count:        count,
6376
 					ProjectId:    project_id,
6422
 					ProjectId:    project_id,
6377
 					StorehouseId: houseConfig.StorehouseOutInfo,
6423
 					StorehouseId: houseConfig.StorehouseOutInfo,
6424
+					NewCount:     new_count,
6425
+					OldCount:     old_count,
6378
 				}
6426
 				}
6427
+
6379
 				newBeforePrepares = append(newBeforePrepares, newPrepare)
6428
 				newBeforePrepares = append(newBeforePrepares, newPrepare)
6429
+
6380
 			}
6430
 			}
6381
 		}
6431
 		}
6382
 	}
6432
 	}
6383
 
6433
 
6384
 	//查询是否有库存
6434
 	//查询是否有库存
6435
+
6385
 	for _, item := range beforePrepares {
6436
 	for _, item := range beforePrepares {
6386
-		storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6387
-		warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
6388
-		if item.Count > warehouse.Count {
6389
-			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6390
-			c.ServeSuccessJSON(map[string]interface{}{
6391
-				"message":            "1",
6392
-				"good_name":          goodObj.GoodName,
6393
-				"specification_name": goodObj.SpecificationName,
6394
-			})
6395
-			return
6437
+
6438
+		if item.NewCount > 0 {
6439
+			storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6440
+			warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
6441
+
6442
+			if item.Count > warehouse.Count {
6443
+				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6444
+				c.ServeSuccessJSON(map[string]interface{}{
6445
+					"message":            "1",
6446
+					"good_name":          goodObj.GoodName,
6447
+					"specification_name": goodObj.SpecificationName,
6448
+				})
6449
+				return
6450
+			}
6396
 		}
6451
 		}
6452
+
6397
 	}
6453
 	}
6398
 
6454
 
6399
 	//出库逻辑
6455
 	//出库逻辑

+ 13 - 3
controllers/mobile_api_controllers/patient_api_controller.go Ver arquivo

3640
 			return
3640
 			return
3641
 		}
3641
 		}
3642
 		advice_date, _ := dataBody["advice_date"].(string)
3642
 		advice_date, _ := dataBody["advice_date"].(string)
3643
-		fmt.Println("advice_date----------------------------------", advice_date)
3644
 
3643
 
3645
 		var advicedateunix int64
3644
 		var advicedateunix int64
3646
 		if len(advice_date) > 0 {
3645
 		if len(advice_date) > 0 {
3674
 			return
3673
 			return
3675
 		}
3674
 		}
3676
 		startTime, _ := dataBody["start_time"].(string)
3675
 		startTime, _ := dataBody["start_time"].(string)
3676
+
3677
 		if len(startTime) == 0 {
3677
 		if len(startTime) == 0 {
3678
 			utils.ErrorLog("len(start_time) == 0")
3678
 			utils.ErrorLog("len(start_time) == 0")
3679
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3679
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3680
 			return
3680
 			return
3681
 		}
3681
 		}
3682
 		theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
3682
 		theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
3683
+
3684
+		theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
3685
+
3683
 		if err != nil {
3686
 		if err != nil {
3684
 			utils.ErrorLog(err.Error())
3687
 			utils.ErrorLog(err.Error())
3685
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3688
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3707
 			advice.Remark = Remark
3710
 			advice.Remark = Remark
3708
 			advice.AdviceType = adviceType
3711
 			advice.AdviceType = adviceType
3709
 			advice.StartTime = StartTime
3712
 			advice.StartTime = StartTime
3710
-			advice.AdviceDate = AdviceDate
3711
-			advice.RecordDate = RecordDate
3713
+			if adminUserInfo.Org.Id == 10340 {
3714
+				advice.AdviceDate = AdviceDate
3715
+				advice.RecordDate = RecordDate
3716
+			}
3717
+			if adminUserInfo.Org.Id != 10340 {
3718
+				advice.AdviceDate = theTimeOne.Unix()
3719
+				advice.RecordDate = theTimeOne.Unix()
3720
+			}
3721
+
3712
 			advice.Status = 1
3722
 			advice.Status = 1
3713
 			advice.CreatedTime = time.Now().Unix()
3723
 			advice.CreatedTime = time.Now().Unix()
3714
 			advice.UpdatedTime = time.Now().Unix()
3724
 			advice.UpdatedTime = time.Now().Unix()

+ 0 - 6
controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go Ver arquivo

30
 	loc, _ := time.LoadLocation("Local")
30
 	loc, _ := time.LoadLocation("Local")
31
 	adminUserInfo := this.GetMobileAdminUserInfo()
31
 	adminUserInfo := this.GetMobileAdminUserInfo()
32
 	orgid := adminUserInfo.Org.Id
32
 	orgid := adminUserInfo.Org.Id
33
-	fmt.Println(orgid)
34
 	keywords := this.GetString("keyword")
33
 	keywords := this.GetString("keyword")
35
 	start_time := this.GetString("start_time")
34
 	start_time := this.GetString("start_time")
36
-	fmt.Println("start_time", start_time)
37
 	limit, _ := this.GetInt64("limit")
35
 	limit, _ := this.GetInt64("limit")
38
-	fmt.Println(limit)
39
 	page, _ := this.GetInt64("page")
36
 	page, _ := this.GetInt64("page")
40
-	fmt.Println(page)
41
 	partitionType, _ := this.GetInt64("partitionType")
37
 	partitionType, _ := this.GetInt64("partitionType")
42
-	fmt.Println("partiontype", partitionType)
43
 	scheduleType, _ := this.GetInt64("scheduleType")
38
 	scheduleType, _ := this.GetInt64("scheduleType")
44
-	fmt.Println(scheduleType)
45
 
39
 
46
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
40
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
47
 	if len(keywords) > 0 {
41
 	if len(keywords) > 0 {

+ 14 - 0
controllers/new_mobile_api_controllers/mobile_his_api_controller.go Ver arquivo

1255
 	}
1255
 	}
1256
 	return
1256
 	return
1257
 }
1257
 }
1258
+
1259
+func (c *MobileHisApiController) GetPatientPlan() {
1260
+
1261
+	plan, _ := service.GetPatientPlan(10340)
1262
+
1263
+	for _, item := range plan {
1264
+		service.UpdatePatienPlan(item.ID, item.TreatmentPlan)
1265
+	}
1266
+	c.ServeSuccessJSON(map[string]interface{}{
1267
+		"plan": plan,
1268
+		"msg":  "ok",
1269
+	})
1270
+	return
1271
+}

+ 2 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go Ver arquivo

180
 	beego.Router("/m/api/hisproject/delete", &MobileHisApiController{}, "Post:DeleteProject")
180
 	beego.Router("/m/api/hisproject/delete", &MobileHisApiController{}, "Post:DeleteProject")
181
 	beego.Router("/m/api/prescription/create", &MobileHisApiController{}, "Post:CreateHisPrescription")
181
 	beego.Router("/m/api/prescription/create", &MobileHisApiController{}, "Post:CreateHisPrescription")
182
 
182
 
183
+	beego.Router("/m/api/patient/getpatientplan", &MobileHisApiController{}, "Get:GetPatientPlan")
184
+
183
 }
185
 }

+ 28 - 8
controllers/patient_api_controller.go Ver arquivo

84
 
84
 
85
 }
85
 }
86
 
86
 
87
-//GetPatientsList 取患者列表
87
+// GetPatientsList 取患者列表
88
 func (c *PatientApiController) GetPatientsList() {
88
 func (c *PatientApiController) GetPatientsList() {
89
 	var err error
89
 	var err error
90
 	defer func() {
90
 	defer func() {
157
 
157
 
158
 }
158
 }
159
 
159
 
160
-//GetPatientTotal
160
+// GetPatientTotal
161
 func (c *PatientApiController) GetPatientTotal() {
161
 func (c *PatientApiController) GetPatientTotal() {
162
 	adminUserInfo := c.GetAdminUserInfo()
162
 	adminUserInfo := c.GetAdminUserInfo()
163
 
163
 
182
 	return
182
 	return
183
 }
183
 }
184
 
184
 
185
-//GenerateDialysisNo 生成透析号
185
+// GenerateDialysisNo 生成透析号
186
 func (c *PatientApiController) GenerateDialysisNo() {
186
 func (c *PatientApiController) GenerateDialysisNo() {
187
 	adminUserInfo := c.GetAdminUserInfo()
187
 	adminUserInfo := c.GetAdminUserInfo()
188
 
188
 
206
 	return
206
 	return
207
 }
207
 }
208
 
208
 
209
-//CreatePatient 创建患者
209
+// CreatePatient 创建患者
210
 func (c *PatientApiController) CreatePatient() {
210
 func (c *PatientApiController) CreatePatient() {
211
 	record_date := c.GetString("record_date")
211
 	record_date := c.GetString("record_date")
212
 	is_infectious, _ := c.GetInt64("is_infectious")
212
 	is_infectious, _ := c.GetInt64("is_infectious")
443
 	return
443
 	return
444
 }
444
 }
445
 
445
 
446
-//EditPatient 修改
446
+// EditPatient 修改
447
 func (c *PatientApiController) EditPatient() {
447
 func (c *PatientApiController) EditPatient() {
448
 	id, _ := c.GetInt64("id", 0)
448
 	id, _ := c.GetInt64("id", 0)
449
 
449
 
1074
 	return
1074
 	return
1075
 }
1075
 }
1076
 
1076
 
1077
-//GetDryWeights 取患者干体重调整铺
1077
+// GetDryWeights 取患者干体重调整铺
1078
 func (c *PatientApiController) GetDryWeights() {
1078
 func (c *PatientApiController) GetDryWeights() {
1079
 	page, _ := c.GetInt64("page", 1)
1079
 	page, _ := c.GetInt64("page", 1)
1080
 	limit, _ := c.GetInt64("limit", 10)
1080
 	limit, _ := c.GetInt64("limit", 10)
1289
 	Remark := ""
1289
 	Remark := ""
1290
 	if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
1290
 	if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
1291
 		remark, _ := dataBody["remark"].(string)
1291
 		remark, _ := dataBody["remark"].(string)
1292
+
1292
 		Remark = remark
1293
 		Remark = remark
1293
 	}
1294
 	}
1294
-
1295
 	var advices []*models.GroupAdvice
1295
 	var advices []*models.GroupAdvice
1296
 	if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
1296
 	if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
1297
 		utils.ErrorLog("adviceNames")
1297
 		utils.ErrorLog("adviceNames")
1323
 			return
1323
 			return
1324
 		}
1324
 		}
1325
 		adviceName, _ := adviceNameM["advice_name"].(string)
1325
 		adviceName, _ := adviceNameM["advice_name"].(string)
1326
+		fmt.Println("adviceceNMAE--------------------------------", adviceName)
1326
 		if len(adviceName) == 0 {
1327
 		if len(adviceName) == 0 {
1327
 			utils.ErrorLog("len(advice_name) == 0")
1328
 			utils.ErrorLog("len(advice_name) == 0")
1328
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1329
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1416
 			advice.DrugNameId = drug_name_id
1417
 			advice.DrugNameId = drug_name_id
1417
 		}
1418
 		}
1418
 
1419
 
1420
+		remark, _ := adviceNameM["remark"].(string)
1421
+		fmt.Println("哦哦撒搜哦搜搜哦remark-----------------------------------", remark)
1422
+		advice.Remark = remark
1423
+
1419
 		if adviceType == 1 {
1424
 		if adviceType == 1 {
1420
 
1425
 
1421
 			if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
1426
 			if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
1470
 					child.PatientId = patientInfo.ID
1475
 					child.PatientId = patientInfo.ID
1471
 					child.AdviceDoctor = adminUserInfo.AdminUser.Id
1476
 					child.AdviceDoctor = adminUserInfo.AdminUser.Id
1472
 					child.IsSettle = 2
1477
 					child.IsSettle = 2
1478
+
1473
 					if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
1479
 					if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
1474
 						utils.ErrorLog("child advice_name")
1480
 						utils.ErrorLog("child advice_name")
1475
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1481
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1535
 
1541
 
1536
 					child.DeliveryWay = advice.DeliveryWay
1542
 					child.DeliveryWay = advice.DeliveryWay
1537
 					child.ExecutionFrequency = advice.ExecutionFrequency
1543
 					child.ExecutionFrequency = advice.ExecutionFrequency
1544
+
1545
+					if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
1546
+						if child.PrescribingNumber == 0 {
1547
+							child.PrescribingNumber = 1
1548
+						}
1549
+						//查询该患者今日有没有双人核对
1550
+						check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
1551
+
1552
+						if check.ID > 0 {
1553
+							child.Checker = check.Modifier
1554
+							child.CheckState = 1
1555
+							child.CheckTime = time.Now().Unix()
1556
+						}
1557
+					}
1538
 					advice.Children = append(advice.Children, &child)
1558
 					advice.Children = append(advice.Children, &child)
1539
 				}
1559
 				}
1540
 			}
1560
 			}
3014
 	return
3034
 	return
3015
 }
3035
 }
3016
 
3036
 
3017
-//GetDoctorAdvices 医嘱列表
3037
+// GetDoctorAdvices 医嘱列表
3018
 func (c *PatientApiController) GetDoctorAdvices() {
3038
 func (c *PatientApiController) GetDoctorAdvices() {
3019
 	id, _ := c.GetInt64("id", 0)
3039
 	id, _ := c.GetInt64("id", 0)
3020
 	adviceType, _ := c.GetInt64("advice_type", 0)
3040
 	adviceType, _ := c.GetInt64("advice_type", 0)

+ 152 - 55
controllers/pharmacy_controller.go Ver arquivo

7
 	"XT_New/utils"
7
 	"XT_New/utils"
8
 	"fmt"
8
 	"fmt"
9
 	"github.com/astaxie/beego"
9
 	"github.com/astaxie/beego"
10
+	"math"
11
+	"strconv"
10
 	"time"
12
 	"time"
11
 )
13
 )
12
 
14
 
78
 	times := this.GetString("time", "")
80
 	times := this.GetString("time", "")
79
 	timeLayout := "2006-01-02"
81
 	timeLayout := "2006-01-02"
80
 	loc, _ := time.LoadLocation("Local")
82
 	loc, _ := time.LoadLocation("Local")
81
-	//shift, err := this.GetInt64("shift", 0) //班次
82
-	//if err != nil {
83
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
84
-	//	return
85
-	//}
86
-	//partition, err := this.GetInt64("partition", 0) //分区
87
-	//if err != nil {
88
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
89
-	//	return
90
-	//}
83
+
91
 	var stime, etime int64
84
 	var stime, etime int64
92
 	if times == "" {
85
 	if times == "" {
93
 		stime, etime = service.GetNowTime()
86
 		stime, etime = service.GetNowTime()
96
 		stime = stmp.Unix()
89
 		stime = stmp.Unix()
97
 		etime = stime + 86399
90
 		etime = stime + 86399
98
 	}
91
 	}
99
-	//查询表里当天的数据
100
-	var wtotal int
101
-	wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
102
-	if err != nil {
103
-		utils.ErrorLog(err.Error())
104
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
92
+
93
+	if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
94
+		//查询表里当天的数据
95
+		var wtotal int
96
+		wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
97
+
98
+		if err != nil {
99
+			utils.ErrorLog(err.Error())
100
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
101
+			return
102
+		}
103
+
104
+		var itotal int
105
+		itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
106
+
107
+		if err != nil {
108
+			utils.ErrorLog(err.Error())
109
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
110
+			return
111
+		}
112
+		this.ServeSuccessJSON(map[string]interface{}{
113
+			"wtotal": wtotal,
114
+			"itotal": itotal,
115
+		})
105
 		return
116
 		return
106
 	}
117
 	}
107
-	var itotal int
108
-	itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
109
-	if err != nil {
110
-		utils.ErrorLog(err.Error())
111
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
118
+
119
+	if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
120
+		var wtotal int
121
+		var itotal int
122
+		//查找出库数量
123
+		wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
124
+
125
+		itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
126
+		this.ServeSuccessJSON(map[string]interface{}{
127
+			"wtotal": wtotal,
128
+			"itotal": itotal,
129
+		})
112
 		return
130
 		return
113
 	}
131
 	}
114
-	this.ServeSuccessJSON(map[string]interface{}{
115
-		"wtotal": wtotal,
116
-		"itotal": itotal,
117
-	})
118
-	return
132
+
119
 }
133
 }
120
 func (this *PharmacyController) IssuedDrug() {
134
 func (this *PharmacyController) IssuedDrug() {
121
 	var err error
135
 	var err error
150
 		stime = stmp.Unix()
164
 		stime = stmp.Unix()
151
 		etime = stime + 86399
165
 		etime = stime + 86399
152
 	}
166
 	}
153
-	//查询表里当天的数据
154
-	var flist []*models.TmpPatient
155
-	flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
156
-	if err != nil {
157
-		utils.ErrorLog(err.Error())
158
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
159
-		return
167
+
168
+	if orgid == 10164 || orgid == 3877 || orgid == 10188 || orgid == 10217 || orgid == 9671 {
169
+		list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1)
170
+		fmt.Println("list23323232323232", list)
171
+		var flist []models.TmpPatientOne
172
+		if len(list) > 0 {
173
+			for _, item := range list {
174
+				patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
175
+				flist = append(flist, patientlist)
176
+			}
177
+		}
178
+		this.ServeSuccessJSON(map[string]interface{}{
179
+			"list": flist,
180
+		})
160
 	}
181
 	}
161
-	listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
162
-	if err != nil {
163
-		utils.ErrorLog(err.Error())
164
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
182
+
183
+	if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 {
184
+		//查询表里当天的数据
185
+		var flist []*models.TmpPatient
186
+		flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
187
+		if err != nil {
188
+			utils.ErrorLog(err.Error())
189
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
190
+			return
191
+		}
192
+		listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
193
+		if err != nil {
194
+			utils.ErrorLog(err.Error())
195
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
196
+			return
197
+		}
198
+		this.ServeSuccessJSON(map[string]interface{}{
199
+			"list": listt,
200
+		})
165
 		return
201
 		return
166
 	}
202
 	}
167
-	this.ServeSuccessJSON(map[string]interface{}{
168
-		"list": listt,
169
-	})
170
-	return
203
+
171
 }
204
 }
172
 func (this *PharmacyController) WaitingDrug() {
205
 func (this *PharmacyController) WaitingDrug() {
173
 	var err error
206
 	var err error
202
 		stime = stmp.Unix()
235
 		stime = stmp.Unix()
203
 		etime = stime + 86399
236
 		etime = stime + 86399
204
 	}
237
 	}
205
-	//查询表里当天的数据
206
-	var flist []*models.TmpPatient
207
-	flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
208
-	if err != nil {
209
-		utils.ErrorLog(err.Error())
210
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
238
+
239
+	if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
240
+		//查询表里当天的数据
241
+		var flist []*models.TmpPatient
242
+		flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
243
+
244
+		if err != nil {
245
+			utils.ErrorLog(err.Error())
246
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
247
+			return
248
+		}
249
+		listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
250
+		if err != nil {
251
+			utils.ErrorLog(err.Error())
252
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
253
+			return
254
+		}
255
+		this.ServeSuccessJSON(map[string]interface{}{
256
+			"list": listt,
257
+		})
211
 		return
258
 		return
212
 	}
259
 	}
213
-	listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
214
-	if err != nil {
215
-		utils.ErrorLog(err.Error())
216
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
260
+
261
+	//当天已发药的人数
262
+	if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
263
+
264
+		list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0)
265
+
266
+		var flist []models.TmpPatientOne
267
+		if len(list) > 0 {
268
+			for _, item := range list {
269
+				patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
270
+				flist = append(flist, patientlist)
271
+			}
272
+		}
273
+		this.ServeSuccessJSON(map[string]interface{}{
274
+			"list": flist,
275
+		})
217
 		return
276
 		return
218
 	}
277
 	}
219
-	this.ServeSuccessJSON(map[string]interface{}{
220
-		"list": listt,
221
-	})
222
-	return
278
+
223
 }
279
 }
224
 
280
 
225
 //
281
 //
290
 		etime = stime + 86399
346
 		etime = stime + 86399
291
 	}
347
 	}
292
 
348
 
349
+	advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
350
+	if len(advicelist) > 0 {
351
+		var total int64
352
+		var prescribing_number_total int64
353
+		for _, item := range advicelist {
354
+			houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
355
+			//查询该药品是否有库存
356
+			list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
357
+
358
+			//查询改药品信息
359
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
360
+			//判断单位是否相等
361
+			if medical.MaxUnit == item.PrescribingNumberUnit {
362
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
363
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
364
+				//转化为最小单位
365
+				total = list.Count*medical.MinNumber + list.StockMinNumber
366
+				prescribing_number_total = count * medical.MinNumber
367
+			}
368
+			if medical.MinUnit == item.PrescribingNumberUnit {
369
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
370
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
371
+				total = list.Count*medical.MinNumber + list.StockMinNumber
372
+				prescribing_number_total = count
373
+			}
374
+
375
+			if medical.IsUse != 1 {
376
+				//如果出库数量大于库存数量
377
+				if prescribing_number_total > total {
378
+					err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
379
+					if err != nil {
380
+						utils.ErrorLog(err.Error())
381
+						this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
382
+						return
383
+					}
384
+				}
385
+			}
386
+
387
+		}
388
+	}
389
+
293
 	err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
390
 	err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
294
 	if err != nil {
391
 	if err != nil {
295
 		utils.ErrorLog(err.Error())
392
 		utils.ErrorLog(err.Error())

+ 5 - 2
controllers/print_data_api_controller.go Ver arquivo

37
 	idStrs := strings.Split(schIDStr, ",")
37
 	idStrs := strings.Split(schIDStr, ",")
38
 	adminUserInfo := this.GetAdminUserInfo()
38
 	adminUserInfo := this.GetAdminUserInfo()
39
 
39
 
40
-	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 {
40
+	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 || this.GetAdminUserInfo().CurrentOrgId == 10188 || this.GetAdminUserInfo().CurrentOrgId == 10217 || this.GetAdminUserInfo().CurrentOrgId == 10340 {
41
 		schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
41
 		schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
42
 		for _, item := range schedules {
42
 		for _, item := range schedules {
43
 
43
 
136
 		})
136
 		})
137
 	}
137
 	}
138
 
138
 
139
-	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 && this.GetAdminUserInfo().CurrentOrgId != 10138 && this.GetAdminUserInfo().CurrentOrgId != 10278 && this.GetAdminUserInfo().CurrentOrgId != 9841 && this.GetAdminUserInfo().CurrentOrgId != 9845 && this.GetAdminUserInfo().CurrentOrgId != 10081 && this.GetAdminUserInfo().CurrentOrgId != 10215 && this.GetAdminUserInfo().CurrentOrgId != 10121 && this.GetAdminUserInfo().CurrentOrgId != 10234 {
139
+	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 && this.GetAdminUserInfo().CurrentOrgId != 10138 && this.GetAdminUserInfo().CurrentOrgId != 10278 && this.GetAdminUserInfo().CurrentOrgId != 9841 && this.GetAdminUserInfo().CurrentOrgId != 9845 && this.GetAdminUserInfo().CurrentOrgId != 10081 && this.GetAdminUserInfo().CurrentOrgId != 10215 && this.GetAdminUserInfo().CurrentOrgId != 10121 && this.GetAdminUserInfo().CurrentOrgId != 10234 && this.GetAdminUserInfo().CurrentOrgId != 10188 && this.GetAdminUserInfo().CurrentOrgId != 10217 && this.GetAdminUserInfo().CurrentOrgId != 10340 {
140
 		schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
140
 		schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
141
 		for _, item := range schedules {
141
 		for _, item := range schedules {
142
 			list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
142
 			list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
259
 	patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
259
 	patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
260
 
260
 
261
 	adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
261
 	adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
262
+
263
+	operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId)
262
 	if err != nil {
264
 	if err != nil {
263
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
265
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
264
 		return
266
 		return
267
 			"record":    record,
269
 			"record":    record,
268
 			"patient":   patient,
270
 			"patient":   patient,
269
 			"adminUser": adminUser,
271
 			"adminUser": adminUser,
272
+			"operators": operators,
270
 		})
273
 		})
271
 	}
274
 	}
272
 }
275
 }

+ 1 - 1
controllers/self_drug_api_congtroller.go Ver arquivo

2716
 	})
2716
 	})
2717
 }
2717
 }
2718
 
2718
 
2719
-//库存优化接口
2719
+// 库存优化接口
2720
 func (this *SelfDrugApiController) GetStorehouseList() {
2720
 func (this *SelfDrugApiController) GetStorehouseList() {
2721
 
2721
 
2722
 	orgId := this.GetAdminUserInfo().CurrentOrgId
2722
 	orgId := this.GetAdminUserInfo().CurrentOrgId

+ 4 - 0
models/dialysis.go Ver arquivo

549
 	CheckTime                  int64  `gorm:"column:check_time" json:"check_time"`
549
 	CheckTime                  int64  `gorm:"column:check_time" json:"check_time"`
550
 	FirstCheckTime             int64  `gorm:"column:first_check_time" json:"first_check_time"`
550
 	FirstCheckTime             int64  `gorm:"column:first_check_time" json:"first_check_time"`
551
 	EmployeeNumber             string `gorm:"column:employee_number" json:"employee_number" form:"employee_number"`
551
 	EmployeeNumber             string `gorm:"column:employee_number" json:"employee_number" form:"employee_number"`
552
+	DialyzerBatchNumber        string `gorm:"column:dialyzer_batch_number" json:"dialyzer_batch_number" form:"dialyzer_batch_number"`
553
+	NeedleBatchNumber          string `gorm:"column:needle_batch_number" json:"needle_batch_number" form:"needle_batch_number"`
552
 }
554
 }
553
 
555
 
554
 func (DoubleCheck) TableName() string {
556
 func (DoubleCheck) TableName() string {
1103
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1105
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1104
 	OrderId           int64  `gorm:"column:order_id" json:"order_id" form:"order_id"`
1106
 	OrderId           int64  `gorm:"column:order_id" json:"order_id" form:"order_id"`
1105
 	NewCount          int64  `gorm:"column:new_count" json:"new_count" form:"new_count"`
1107
 	NewCount          int64  `gorm:"column:new_count" json:"new_count" form:"new_count"`
1108
+	OldCount          int64  `gorm:"column:old_count" json:"old_count" form:"old_count"`
1106
 }
1109
 }
1107
 
1110
 
1108
 type NewDialysisBeforePrepareGoods struct {
1111
 type NewDialysisBeforePrepareGoods struct {
1119
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1122
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1120
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1123
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1121
 	OrderId                            int64                            `gorm:"column:order_id" json:"order_id" form:"order_id"`
1124
 	OrderId                            int64                            `gorm:"column:order_id" json:"order_id" form:"order_id"`
1125
+	OldCount                           int64                            `gorm:"column:old_count" json:"old_count" form:"old_count"`
1122
 }
1126
 }
1123
 
1127
 
1124
 type OldDialysisBeforePrepareGoods struct {
1128
 type OldDialysisBeforePrepareGoods struct {

+ 3 - 0
models/patient_models.go Ver arquivo

1176
 	UserSysBeforeCount           int64   `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
1176
 	UserSysBeforeCount           int64   `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
1177
 	SchRemark                    string  `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
1177
 	SchRemark                    string  `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
1178
 	ScheduleRemark               string  `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
1178
 	ScheduleRemark               string  `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
1179
+	TreatmentPlan                string  `gorm:"column:treatment_plan" json:"treatment_plan" form:"treatment_plan"`
1179
 }
1180
 }
1180
 
1181
 
1181
 func (XtPatients) TableName() string {
1182
 func (XtPatients) TableName() string {
1817
 	Ctime                 int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
1818
 	Ctime                 int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
1818
 	Mtime                 int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
1819
 	Mtime                 int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
1819
 	Status                int64  `gorm:"column:status" json:"status" form:"status"`
1820
 	Status                int64  `gorm:"column:status" json:"status" form:"status"`
1821
+	ProjectId             string `gorm:"column:project_id" json:"project_id" form:"project_id"`
1822
+	InspectDate           string `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
1820
 }
1823
 }
1821
 
1824
 
1822
 func (XtPatientFirstDisease) TableName() string {
1825
 func (XtPatientFirstDisease) TableName() string {

+ 11 - 0
models/pharmacy_models.go Ver arquivo

31
 	PatientID  int64
31
 	PatientID  int64
32
 	Name       string
32
 	Name       string
33
 	DialysisNo string //透析号
33
 	DialysisNo string //透析号
34
+
35
+}
36
+
37
+type TmpPatientOne struct {
38
+	PatientID  int64  `gorm:"column:id" json:"PatientID" form:"id"`
39
+	DialysisNo string `gorm:"column:dialysis_no" json:"DialysisNo" form:"dialysis_no"`
40
+	Name       string `gorm:"column:name" json:"Name" form:"name"`
41
+}
42
+
43
+func (TmpPatientOne) TableName() string {
44
+	return "xt_patients"
34
 }
45
 }
35
 
46
 
36
 //药品信息
47
 //药品信息

+ 1 - 1
routers/router.go Ver arquivo

11
 func init() {
11
 func init() {
12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
13
 		//AllowAllOrigins:  true,
13
 		//AllowAllOrigins:  true,
14
-		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com"},
14
+		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://api.xt.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com", "https://mobile.kuyicloud.com"},
15
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
15
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
17
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission", "KyToken"},
17
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission", "KyToken"},

+ 7 - 1
service/dialysis_service.go Ver arquivo

1593
 	advice_list_str, _ := redis.Get(key).Result()
1593
 	advice_list_str, _ := redis.Get(key).Result()
1594
 
1594
 
1595
 	if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1595
 	if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1596
-		err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).Find(&advices).Error
1596
+		err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ?", orgID, scheduleDate).Find(&advices).Error
1597
 		if err != nil {
1597
 		if err != nil {
1598
 			if err == gorm.ErrRecordNotFound {
1598
 			if err == gorm.ErrRecordNotFound {
1599
 				if len(advices) <= 0 {
1599
 				if len(advices) <= 0 {
2084
 	err := XTWriteDB().Model(&advice).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": checker, "check_state": 1, "check_time": time.Now().Unix()}).Error
2084
 	err := XTWriteDB().Model(&advice).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": checker, "check_state": 1, "check_time": time.Now().Unix()}).Error
2085
 	return err
2085
 	return err
2086
 }
2086
 }
2087
+
2088
+func UpdateLastMonitorRecordToday(accumulated_blood_volume float64, id int64) error {
2089
+
2090
+	err := XTWriteDB().Model(&models.MonitoringRecord{}).Where(" id = ? and status= 1", id).Update(map[string]interface{}{"accumulated_blood_volume": accumulated_blood_volume}).Error
2091
+	return err
2092
+}

+ 3 - 3
service/dialysis_solution_service.go Ver arquivo

495
 
495
 
496
 }
496
 }
497
 
497
 
498
-func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
498
+func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
499
 
499
 
500
 	db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
500
 	db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
501
 
501
 
505
 	if schedule_type > 0 {
505
 	if schedule_type > 0 {
506
 		db = db.Where("schedule_type = ?", schedule_type)
506
 		db = db.Where("schedule_type = ?", schedule_type)
507
 	}
507
 	}
508
-	if partition_id > 0 {
509
-		db = db.Where("partition_id = ?", partition_id)
508
+	if len(partition_id) > 0 {
509
+		db = db.Where("partition_id in(?)", partition_id)
510
 	}
510
 	}
511
 
511
 
512
 	if orgID > 0 {
512
 	if orgID > 0 {

+ 12 - 0
service/his_service.go Ver arquivo

2702
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
2702
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
2703
 	return order, err
2703
 	return order, err
2704
 }
2704
 }
2705
+
2706
+func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
2707
+
2708
+	err = XTReadDB().Where("user_org_id = ? and status=  1", orgid).Find(&patient).Error
2709
+	return patient, err
2710
+}
2711
+
2712
+func UpdatePatienPlan(id int64, trement_plan string) error {
2713
+
2714
+	err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
2715
+	return err
2716
+}

+ 27 - 3
service/mobile_dialysis_service.go Ver arquivo

4357
 func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
4357
 func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
4358
 
4358
 
4359
 	prepare := models.DialysisBeforePrepare{}
4359
 	prepare := models.DialysisBeforePrepare{}
4360
+	var err error
4361
+	if count > 0 {
4362
+		err = XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count  <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
4363
+	}
4364
+	if count <= 0 {
4365
+		err = XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count  <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count, "status": 0}).Error
4366
+	}
4360
 
4367
 
4361
-	err := XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count  <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
4362
 	return err
4368
 	return err
4363
 }
4369
 }
4364
 
4370
 
4477
 }
4483
 }
4478
 
4484
 
4479
 func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string) ([]*MScheduleDoctorAdviceVM, error) {
4485
 func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string) ([]*MScheduleDoctorAdviceVM, error) {
4486
+
4487
+	fmt.Println("execution_frequency---------------------------", execution_frequency)
4488
+	fmt.Println("cost_type-----------", cost_type)
4489
+	fmt.Println("adviceType-----------", adviceType)
4490
+	fmt.Println("patientType---------", patientType)
4491
+	fmt.Println("len(deliverWay)--------", len(deliverWay))
4480
 	var vms []*MScheduleDoctorAdviceVM
4492
 	var vms []*MScheduleDoctorAdviceVM
4481
 	adviceWhere := ""
4493
 	adviceWhere := ""
4482
 	adviceCondition := []interface{}{}
4494
 	adviceCondition := []interface{}{}
5316
 		}
5328
 		}
5317
 
5329
 
5318
 	} else if adviceType == 2 && len(deliverWay) > 0 {
5330
 	} else if adviceType == 2 && len(deliverWay) > 0 {
5331
+
5319
 		if patientType == 0 {
5332
 		if patientType == 0 {
5320
 			if patient_id > 0 {
5333
 			if patient_id > 0 {
5321
 				if execution_state > 0 {
5334
 				if execution_state > 0 {
5592
 		}
5605
 		}
5593
 
5606
 
5594
 	} else if adviceType == 2 && len(deliverWay) <= 0 {
5607
 	} else if adviceType == 2 && len(deliverWay) <= 0 {
5608
+		fmt.Println("寄哪里233223322323233232", patientType)
5609
+		fmt.Println("patient_id", patient_id)
5610
+		fmt.Println("execution_state000000", execution_state)
5611
+		fmt.Println("cost_type", cost_type)
5612
+		fmt.Println("len23323232", len(execution_frequency))
5595
 		if patientType == 0 {
5613
 		if patientType == 0 {
5596
 			if patient_id > 0 {
5614
 			if patient_id > 0 {
5597
 				if execution_state > 0 {
5615
 				if execution_state > 0 {
5668
 						}
5686
 						}
5669
 
5687
 
5670
 					} else {
5688
 					} else {
5671
-						adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
5672
-						adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
5689
+						if len(execution_frequency) > 0 {
5690
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
5691
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
5692
+						} else {
5693
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
5694
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
5695
+						}
5696
+
5673
 					}
5697
 					}
5674
 
5698
 
5675
 				}
5699
 				}

+ 602 - 8
service/new_warehouse_service.go Ver arquivo

26
 	// 如果没有对应的库存,则报错
26
 	// 如果没有对应的库存,则报错
27
 
27
 
28
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
28
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
29
-	if err != nil {
30
-		return errors.New("库存数量不足")
29
+	if goods.Count > 0 {
30
+		if err != nil {
31
+			return errors.New("库存数量不足")
32
+		}
31
 	}
33
 	}
32
 
34
 
33
 	stock_number = warehouse.StockCount
35
 	stock_number = warehouse.StockCount
36
 	if stock_number >= deliver_number {
38
 	if stock_number >= deliver_number {
37
 
39
 
38
 		maxNumber = goods.Count
40
 		maxNumber = goods.Count
41
+
39
 		//出库
42
 		//出库
40
 		warehouse.StockCount = warehouse.StockCount - maxNumber
43
 		warehouse.StockCount = warehouse.StockCount - maxNumber
41
 		warehouse.Mtime = time.Now().Unix()
44
 		warehouse.Mtime = time.Now().Unix()
352
 			warehouseOutInfo.Price = goodsInfo.PackingPrice
355
 			warehouseOutInfo.Price = goodsInfo.PackingPrice
353
 		}
356
 		}
354
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
357
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
355
-		//fmt.Println("errcodes23332322332323223", errcodes, goods.ProjectId)
358
+
356
 		if errcodes == gorm.ErrRecordNotFound {
359
 		if errcodes == gorm.ErrRecordNotFound {
357
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
360
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
358
 			if errOne != nil {
361
 			if errOne != nil {
1494
 			cancel_count += item.Count
1497
 			cancel_count += item.Count
1495
 		}
1498
 		}
1496
 
1499
 
1497
-		fmt.Println("deliver_number", deliver_number)
1498
-		fmt.Println("out_count", out_count)
1499
-		fmt.Println("cancel_count", cancel_count)
1500
+		//fmt.Println("deliver_number", deliver_number)
1501
+		//fmt.Println("out_count", out_count)
1502
+		//fmt.Println("cancel_count", cancel_count)
1503
+		//
1504
+		//fmt.Println("出库数据", deliver_number)
1505
+		//fmt.Println("出库流水---------------------", out_count, cancel_count)
1500
 		//如果本次出库数据大于历史出库数据 新增1条流水
1506
 		//如果本次出库数据大于历史出库数据 新增1条流水
1501
-		if deliver_number > (out_count - cancel_count) {
1507
+		if deliver_number >= (out_count - cancel_count) {
1502
 			drugflow := models.DrugFlow{
1508
 			drugflow := models.DrugFlow{
1503
 				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
1509
 				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
1504
 				WarehouseOutId:          warehouseout.ID,
1510
 				WarehouseOutId:          warehouseout.ID,
3004
 		if warehouse.StockCount < 0 {
3010
 		if warehouse.StockCount < 0 {
3005
 			return errors.New("库存数量不足")
3011
 			return errors.New("库存数量不足")
3006
 		}
3012
 		}
3007
-		err := tx.Save(&warehouse).Error
3013
+		var info models.WarehousingInfo
3014
+		err := tx.Model(&info).Where("id = ?", warehouse.ID).Updates(map[string]interface{}{"stock_count": warehouse.StockCount}).Error
3008
 		if err != nil {
3015
 		if err != nil {
3009
 			return err
3016
 			return err
3010
 		}
3017
 		}
3548
 	}
3555
 	}
3549
 	return err
3556
 	return err
3550
 }
3557
 }
3558
+
3559
+func ConsumablesGoodDeliveryNew(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
3560
+
3561
+	//开事务
3562
+	tx := XTWriteDB().Begin()
3563
+	if err != nil {
3564
+		utils.ErrorLog("事务失败,原因为: %v", err)
3565
+		tx.Rollback()
3566
+	} else {
3567
+		fmt.Println("err-----------------------", err)
3568
+		tx.Commit()
3569
+	}
3570
+	var deliver_number int64 = 0
3571
+	var stock_number int64 = 0
3572
+	var maxNumber int64 = 0
3573
+
3574
+	deliver_number = goods.Count
3575
+
3576
+	// 根据先进先出原则,查询最先入库的批次,进行出库
3577
+	// 如果没有对应的库存,则报错
3578
+
3579
+	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
3580
+	if goods.Count > 0 {
3581
+		if err != nil {
3582
+			return errors.New("库存数量不足")
3583
+		}
3584
+	}
3585
+
3586
+	stock_number = warehouse.StockCount
3587
+
3588
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
3589
+	if stock_number >= deliver_number {
3590
+
3591
+		maxNumber = goods.Count
3592
+
3593
+		//出库
3594
+		warehouse.StockCount = warehouse.StockCount - maxNumber
3595
+		warehouse.Mtime = time.Now().Unix()
3596
+		if warehouse.StockCount < 0 {
3597
+			return errors.New("库存数量不足")
3598
+		}
3599
+
3600
+		err := tx.Save(&warehouse).Error
3601
+		if err != nil {
3602
+			return err
3603
+		}
3604
+		//更新his_prescripton_project出库状态值
3605
+		UpdateHisPrescriptionProjectStatus(goods.GoodId, record_time, orgID, patient_id)
3606
+
3607
+		var info []*models.WarehousingInfo
3608
+		err = tx.Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goods.GoodId, orgID, goods.StorehouseId).Find(&info).Error
3609
+		var sum_count int64
3610
+		for _, item := range info {
3611
+			sum_count += item.StockCount
3612
+		}
3613
+
3614
+		warehouseOutInfo := &models.WarehouseOutInfo{
3615
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3616
+			WarehouseOutId:          warehouseOut.ID,
3617
+			WarehouseInfotId:        warehouse.ID,
3618
+			Status:                  1,
3619
+			Ctime:                   time.Now().Unix(),
3620
+			Remark:                  warehouse.Remark,
3621
+			OrgId:                   orgID,
3622
+			Type:                    1,
3623
+			Manufacturer:            warehouse.Manufacturer,
3624
+			Dealer:                  warehouse.Dealer,
3625
+			IsSys:                   1,
3626
+			SysRecordTime:           record_time,
3627
+			GoodTypeId:              goods.GoodTypeId,
3628
+			GoodId:                  goods.GoodId,
3629
+			PatientId:               patient_id,
3630
+			Number:                  warehouse.Number,
3631
+			LicenseNumber:           warehouse.LicenseNumber,
3632
+			Price:                   warehouse.PackingPrice,
3633
+			ExpiryDate:              warehouse.ExpiryDate,
3634
+			ProductDate:             warehouse.ProductDate,
3635
+			ProjectId:               goods.ProjectId,
3636
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3637
+			StorehouseId:            goods.StorehouseId,
3638
+			IsCheck:                 1,
3639
+			OverCount:               sum_count,
3640
+			RegisterNumber:          warehouse.RegisterNumber,
3641
+		}
3642
+		warehouseOutInfo.Count = count
3643
+		if orgID == 9671 || orgID == 10265 {
3644
+			goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3645
+			warehouseOutInfo.Price = goodsInfo.PackingPrice
3646
+		}
3647
+		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
3648
+		if errcodes == gorm.ErrRecordNotFound {
3649
+			err := tx.Create(&warehouseOutInfo).Error
3650
+			if err != nil {
3651
+				return err
3652
+			}
3653
+		} else if errcodes == nil {
3654
+
3655
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
3656
+			if count != outInfoOne.Count {
3657
+
3658
+				outInfo := models.WarehouseOutInfo{}
3659
+				err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", goods.GoodId, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": warehouseOutInfo.WarehouseOutId, "WarehouseOutOrderNumber": warehouseOutInfo.WarehouseOutOrderNumber, "sys_record_time": warehouseOutInfo.SysRecordTime, "good_type_id": warehouseOutInfo.GoodTypeId, "patient_id": warehouseOutInfo.PatientId, "consumable_type": warehouseOutInfo.ConsumableType, "count": warehouseOutInfo.Count, "price": warehouseOutInfo.Price, "dealer": warehouseOutInfo.Dealer, "manufacturer": warehouseOutInfo.Manufacturer, "number": warehouseOutInfo.Number, "license_number": warehouseOutInfo.LicenseNumber, "over_count": warehouseOutInfo.OverCount}).Error
3660
+				if err != nil {
3661
+					return err
3662
+				}
3663
+			}
3664
+
3665
+		}
3666
+		lastOut, _ := FindWarehouseOutInfoByPatientId(patient_id, record_time, goods.GoodId, orgID)
3667
+
3668
+		//查询已经出库的数据
3669
+		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
3670
+		var out_count int64
3671
+		var out_count_one int64
3672
+		for _, item := range flowGood {
3673
+			out_count += item.Count
3674
+		}
3675
+
3676
+		//查询退库数据
3677
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
3678
+		for _, item := range flowGoodTwo {
3679
+			out_count_one += item.Count
3680
+		}
3681
+		//如果本次出库数据大于历史出库数据 新增1条流水
3682
+		if count > (out_count - out_count_one) {
3683
+
3684
+			flow := models.VmStockFlow{
3685
+				WarehouseOutId:          warehouseOut.ID,
3686
+				WarehousingId:           warehouse.ID,
3687
+				GoodId:                  goods.GoodId,
3688
+				Number:                  warehouse.Number,
3689
+				ProductDate:             warehouse.ProductDate,
3690
+				ExpireDate:              warehouse.ExpiryDate,
3691
+				Count:                   count - out_count + out_count_one,
3692
+				Price:                   warehouse.PackingPrice,
3693
+				Status:                  1,
3694
+				Ctime:                   time.Now().Unix(),
3695
+				UserOrgId:               orgID,
3696
+				Manufacturer:            warehouse.Manufacturer,
3697
+				Dealer:                  warehouse.Dealer,
3698
+				LicenseNumber:           warehouse.LicenseNumber,
3699
+				IsEdit:                  2,
3700
+				Creator:                 warehouseOut.Creater,
3701
+				SystemTime:              record_time,
3702
+				ConsumableType:          3,
3703
+				WarehouseOutDetailId:    lastOut.ID,
3704
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3705
+				IsSys:                   1,
3706
+				PatientId:               patient_id,
3707
+				ProjectId:               goods.ProjectId,
3708
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3709
+				StorehouseId:            goods.StorehouseId,
3710
+				OverCount:               sum_count,
3711
+				BuyPrice:                warehouse.Price,
3712
+				RegisterNumber:          warehouse.RegisterNumber,
3713
+			}
3714
+			if orgID == 9671 || orgID == 10265 {
3715
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3716
+				flow.Price = goodsInfo.PackingPrice
3717
+				flow.BuyPrice = goodsInfo.BuyPrice
3718
+			}
3719
+
3720
+			err := tx.Create(&flow).Error
3721
+			if err != nil {
3722
+				return err
3723
+			}
3724
+
3725
+		}
3726
+
3727
+		//如果本次出库数据小于历史出库数据 新增1条退库流水
3728
+
3729
+		if count < (out_count - out_count_one) {
3730
+
3731
+			operation_time := time.Now().Unix()
3732
+
3733
+			//创建退库单
3734
+			timeStr := time.Now().Format("2006-01-02")
3735
+			timeArr := strings.Split(timeStr, "-")
3736
+			total, _ := FindAllCancelStockTotal(orgID)
3737
+			total = total + 1
3738
+			orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
3739
+
3740
+			cancelStock := models.CancelStock{
3741
+				OrderNumber:  orderNumber,
3742
+				OperaTime:    operation_time,
3743
+				OrgId:        orgID,
3744
+				Creater:      warehouseOut.Creater,
3745
+				Ctime:        time.Now().Unix(),
3746
+				Status:       1,
3747
+				ReturnTime:   record_time,
3748
+				Type:         1,
3749
+				StorehouseId: goods.StorehouseId,
3750
+				IsCheck:      1,
3751
+			}
3752
+			_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, orgID)
3753
+			if msgerrkonde == gorm.ErrRecordNotFound {
3754
+
3755
+				err := tx.Create(&cancelStock).Error
3756
+				if err != nil {
3757
+					return err
3758
+				}
3759
+			}
3760
+
3761
+			cancel, _ := GetLastCancelStockById(orgID)
3762
+
3763
+			manufacturer, _ := GetManufactureById(warehouse.Manufacturer)
3764
+			deaerler, _ := GetDealerById(warehouse.Dealer)
3765
+			cancelStockInfo := models.CancelStockInfo{
3766
+				GoodId:          goods.GoodId,
3767
+				CancelStockId:   cancel.ID,
3768
+				GoodTypeId:      goods.GoodTypeId,
3769
+				Count:           out_count - out_count_one - count,
3770
+				Price:           warehouse.PackingPrice,
3771
+				Total:           0,
3772
+				ProductDate:     warehouse.ProductDate,
3773
+				ExpiryDate:      warehouse.ExpiryDate,
3774
+				Ctime:           time.Now().Unix(),
3775
+				Status:          1,
3776
+				OrgId:           orgID,
3777
+				OrderNumber:     cancel.OrderNumber,
3778
+				Type:            0,
3779
+				Dealer:          deaerler.DealerName,
3780
+				Manufacturer:    manufacturer.ManufacturerName,
3781
+				Number:          warehouse.Number,
3782
+				RegisterAccount: "",
3783
+				Remark:          "",
3784
+				WarehouseInfoId: warehouse.ID,
3785
+				PatientId:       patient_id,
3786
+				RecordDate:      record_time,
3787
+				StorehouseId:    goods.StorehouseId,
3788
+				IsCheck:         1,
3789
+			}
3790
+			if orgID == 9671 || orgID == 10265 {
3791
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3792
+				cancelStockInfo.Price = goodsInfo.PackingPrice
3793
+			}
3794
+
3795
+			err := tx.Create(&cancelStockInfo).Error
3796
+			if err != nil {
3797
+				return err
3798
+			}
3799
+
3800
+			cancelInfo, _ := GetLastCancelStockInfoByGoodId(goods.GoodId)
3801
+
3802
+			flow := models.VmStockFlow{
3803
+				WarehousingId:           warehouse.ID,
3804
+				GoodId:                  goods.GoodId,
3805
+				Number:                  warehouse.Number,
3806
+				LicenseNumber:           warehouse.LicenseNumber,
3807
+				Count:                   out_count - out_count_one - count,
3808
+				UserOrgId:               orgID,
3809
+				PatientId:               patient_id,
3810
+				SystemTime:              record_time,
3811
+				ConsumableType:          7,
3812
+				IsSys:                   1,
3813
+				WarehousingOrder:        "",
3814
+				WarehouseOutId:          lastOut.WarehouseOutId,
3815
+				WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
3816
+				IsEdit:                  0,
3817
+				CancelStockId:           cancel.ID,
3818
+				CancelOrderNumber:       cancel.OrderNumber,
3819
+				Manufacturer:            manufacturer.ID,
3820
+				Dealer:                  0,
3821
+				Creator:                 warehouseOut.Creater,
3822
+				UpdateCreator:           0,
3823
+				Status:                  1,
3824
+				Ctime:                   time.Now().Unix(),
3825
+				Mtime:                   0,
3826
+				Price:                   warehouse.PackingPrice,
3827
+				WarehousingDetailId:     warehouse.ID,
3828
+				WarehouseOutDetailId:    lastOut.ID,
3829
+				CancelOutDetailId:       cancelInfo.ID,
3830
+				ProductDate:             warehouse.ProductDate,
3831
+				ExpireDate:              warehouse.ExpiryDate,
3832
+				StorehouseId:            goods.StorehouseId,
3833
+				BuyPrice:                warehouse.Price,
3834
+				ProjectId:               goods.ProjectId,
3835
+				OverCount:               sum_count,
3836
+				RegisterNumber:          warehouse.RegisterNumber,
3837
+			}
3838
+			if orgID == 9671 || orgID == 10265 {
3839
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3840
+				flow.Price = goodsInfo.PackingPrice
3841
+				flow.BuyPrice = goodsInfo.BuyPrice
3842
+			}
3843
+
3844
+			err = tx.Create(&flow).Error
3845
+			if err != nil {
3846
+				return err
3847
+			}
3848
+		}
3849
+
3850
+		details := models.BloodAutomaticReduceDetail{
3851
+			WarehouseOutId:          lastOut.ID,
3852
+			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
3853
+			PatientId:               patient_id,
3854
+			Ctime:                   time.Now().Unix(),
3855
+			Mtime:                   time.Now().Unix(),
3856
+			Status:                  1,
3857
+			RecordTime:              record_time,
3858
+			OrgId:                   orgID,
3859
+			GoodId:                  goods.GoodId,
3860
+			GoodTypeId:              goods.GoodTypeId,
3861
+			Count:                   count,
3862
+			ProjectId:               goods.ProjectId,
3863
+			StorehouseId:            goods.StorehouseId,
3864
+		}
3865
+
3866
+		////查询该耗材已经出库的数量
3867
+		_, errcode := GetAutoMaticReduceDetailTwenty(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
3868
+		if errcode == gorm.ErrRecordNotFound {
3869
+
3870
+			err := tx.Create(&details).Error
3871
+			if err != nil {
3872
+				return err
3873
+			}
3874
+		} else if errcode == nil {
3875
+
3876
+			detail := models.BloodAutomaticReduceDetail{}
3877
+			err := tx.Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and good_type_id = ?", orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3878
+			if err != nil {
3879
+				return err
3880
+			}
3881
+
3882
+			err = tx.Create(&detail).Error
3883
+			if err != nil {
3884
+				return err
3885
+			}
3886
+		}
3887
+
3888
+		return nil
3889
+	} else {
3890
+
3891
+		// 当刚批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
3892
+		warehouse.StockCount = 0
3893
+		warehouse.Mtime = time.Now().Unix()
3894
+
3895
+		err := tx.Save(&warehouse).Error
3896
+		if err != nil {
3897
+			return err
3898
+		}
3899
+		var info []*models.WarehousingInfo
3900
+		err = tx.Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goods.GoodId, orgID, goods.StorehouseId).Find(&info).Error
3901
+		var sum_count int64
3902
+		for _, item := range info {
3903
+			sum_count += item.StockCount
3904
+		}
3905
+		warehouseOutInfo := &models.WarehouseOutInfo{
3906
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3907
+			WarehouseOutId:          warehouseOut.ID,
3908
+			WarehouseInfotId:        warehouse.ID,
3909
+			Status:                  1,
3910
+			Ctime:                   time.Now().Unix(),
3911
+			Remark:                  warehouse.Remark,
3912
+			OrgId:                   orgID,
3913
+			Type:                    1,
3914
+			Manufacturer:            warehouse.Manufacturer,
3915
+			Dealer:                  warehouse.Dealer,
3916
+			IsSys:                   1,
3917
+			SysRecordTime:           record_time,
3918
+			GoodTypeId:              goods.GoodTypeId,
3919
+			GoodId:                  goods.GoodId,
3920
+			PatientId:               patient_id,
3921
+			Number:                  warehouse.Number,
3922
+			LicenseNumber:           warehouse.LicenseNumber,
3923
+			Price:                   warehouse.PackingPrice,
3924
+			ExpiryDate:              warehouse.ExpiryDate,
3925
+			ProductDate:             warehouse.ProductDate,
3926
+			ProjectId:               goods.ProjectId,
3927
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3928
+			StorehouseId:            goods.StorehouseId,
3929
+			IsCheck:                 1,
3930
+			OverCount:               sum_count,
3931
+			RegisterNumber:          warehouse.RegisterNumber,
3932
+		}
3933
+		warehouseOutInfo.Count = stock_number
3934
+		if orgID == 9671 || orgID == 10265 {
3935
+			goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3936
+			warehouseOutInfo.Price = goodsInfo.PackingPrice
3937
+		}
3938
+		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
3939
+
3940
+		if errcodes == gorm.ErrRecordNotFound {
3941
+
3942
+			errors := tx.Create(warehouseOutInfo).Error
3943
+			if errors != nil {
3944
+				return errors
3945
+			}
3946
+		} else if errcodes == nil {
3947
+			goods.Count = deliver_number - stock_number
3948
+			//更新数量为  该批次剩余数量  + 还有未出的数量
3949
+			warehouseOutInfo.Count = stock_number
3950
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
3951
+			if count != outInfoOne.Count {
3952
+
3953
+				outInfo := models.WarehouseOutInfo{}
3954
+				err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", goods.GoodId, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": warehouseOutInfo.WarehouseOutId, "WarehouseOutOrderNumber": warehouseOutInfo.WarehouseOutOrderNumber, "sys_record_time": warehouseOutInfo.SysRecordTime, "good_type_id": warehouseOutInfo.GoodTypeId, "patient_id": warehouseOutInfo.PatientId, "consumable_type": warehouseOutInfo.ConsumableType, "count": warehouseOutInfo.Count, "price": warehouseOutInfo.Price, "dealer": warehouseOutInfo.Dealer, "manufacturer": warehouseOutInfo.Manufacturer, "number": warehouseOutInfo.Number, "license_number": warehouseOutInfo.LicenseNumber, "over_count": warehouseOutInfo.OverCount}).Error
3955
+				if err != nil {
3956
+					return err
3957
+				}
3958
+			}
3959
+
3960
+		}
3961
+		lastOut, _ := FindWarehouseOutInfoByPatientId(patient_id, record_time, goods.GoodId, orgID)
3962
+		//查询该该批次已经出库的数据
3963
+		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
3964
+		var out_count int64
3965
+		var out_count_one int64
3966
+		for _, item := range flowGood {
3967
+			out_count += item.Count
3968
+		}
3969
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
3970
+		for _, item := range flowGoodTwo {
3971
+			out_count_one += item.Count
3972
+		}
3973
+		//如果出库数量 大于 历史出库数据 新增1条流水
3974
+		if count > out_count-out_count_one {
3975
+			flow := models.VmStockFlow{
3976
+				WarehouseOutId:          warehouseOut.ID,
3977
+				WarehousingId:           warehouse.ID,
3978
+				GoodId:                  goods.GoodId,
3979
+				Number:                  warehouse.Number,
3980
+				ProductDate:             warehouse.ProductDate,
3981
+				ExpireDate:              warehouse.ExpiryDate,
3982
+				Count:                   stock_number,
3983
+				Price:                   warehouse.PackingPrice,
3984
+				Status:                  1,
3985
+				Ctime:                   time.Now().Unix(),
3986
+				UserOrgId:               orgID,
3987
+				Manufacturer:            warehouse.Manufacturer,
3988
+				Dealer:                  warehouse.Dealer,
3989
+				LicenseNumber:           warehouse.LicenseNumber,
3990
+				IsEdit:                  2,
3991
+				Creator:                 warehouseOut.Creater,
3992
+				SystemTime:              record_time,
3993
+				ConsumableType:          3,
3994
+				WarehouseOutDetailId:    lastOut.ID,
3995
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3996
+				IsSys:                   1,
3997
+				PatientId:               patient_id,
3998
+				ProjectId:               goods.ProjectId,
3999
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4000
+				StorehouseId:            goods.StorehouseId,
4001
+				OverCount:               sum_count,
4002
+				BuyPrice:                warehouse.Price,
4003
+				RegisterNumber:          warehouse.RegisterNumber,
4004
+			}
4005
+			if orgID == 9671 || orgID == 10265 {
4006
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4007
+				flow.Price = goodsInfo.PackingPrice
4008
+				flow.BuyPrice = goodsInfo.BuyPrice
4009
+			}
4010
+
4011
+			err := tx.Create(&flow).Error
4012
+			if err != nil {
4013
+				return err
4014
+			}
4015
+		}
4016
+		//退库
4017
+		if count < out_count-out_count_one {
4018
+			operation_time := time.Now().Unix()
4019
+
4020
+			//创建退库单
4021
+			timeStr := time.Now().Format("2006-01-02")
4022
+			timeArr := strings.Split(timeStr, "-")
4023
+			total, _ := FindAllCancelStockTotal(orgID)
4024
+			total = total + 1
4025
+			orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
4026
+
4027
+			cancelStock := models.CancelStock{
4028
+				OrderNumber:  orderNumber,
4029
+				OperaTime:    operation_time,
4030
+				OrgId:        orgID,
4031
+				Creater:      warehouseOut.Creater,
4032
+				Ctime:        time.Now().Unix(),
4033
+				Status:       1,
4034
+				ReturnTime:   record_time,
4035
+				Type:         1,
4036
+				StorehouseId: goods.StorehouseId,
4037
+				IsCheck:      1,
4038
+			}
4039
+			_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, orgID)
4040
+			if msgerrkonde == gorm.ErrRecordNotFound {
4041
+
4042
+				err := tx.Create(&cancelStock).Error
4043
+				if err != nil {
4044
+					return err
4045
+				}
4046
+			}
4047
+
4048
+			cancel, _ := GetLastCancelStockById(orgID)
4049
+
4050
+			manufacturer, _ := GetManufactureById(warehouse.Manufacturer)
4051
+			deaerler, _ := GetDealerById(warehouse.Dealer)
4052
+			cancelStockInfo := models.CancelStockInfo{
4053
+				GoodId:          goods.GoodId,
4054
+				CancelStockId:   cancel.ID,
4055
+				GoodTypeId:      goods.GoodTypeId,
4056
+				Count:           out_count - out_count_one - count,
4057
+				Price:           warehouse.PackingPrice,
4058
+				Total:           0,
4059
+				ProductDate:     warehouse.ProductDate,
4060
+				ExpiryDate:      warehouse.ExpiryDate,
4061
+				Ctime:           time.Now().Unix(),
4062
+				Status:          1,
4063
+				OrgId:           orgID,
4064
+				OrderNumber:     cancel.OrderNumber,
4065
+				Type:            0,
4066
+				Dealer:          deaerler.DealerName,
4067
+				Manufacturer:    manufacturer.ManufacturerName,
4068
+				Number:          warehouse.Number,
4069
+				RegisterAccount: "",
4070
+				Remark:          "",
4071
+				WarehouseInfoId: warehouse.ID,
4072
+				PatientId:       patient_id,
4073
+				RecordDate:      record_time,
4074
+				StorehouseId:    goods.StorehouseId,
4075
+				IsCheck:         1,
4076
+			}
4077
+			if orgID == 9671 || orgID == 10265 {
4078
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4079
+				cancelStockInfo.Price = goodsInfo.PackingPrice
4080
+			}
4081
+
4082
+			err := tx.Create(&cancelStockInfo).Error
4083
+			if err != nil {
4084
+				return err
4085
+			}
4086
+
4087
+			cancelInfo, _ := GetLastCancelStockInfoByGoodId(goods.GoodId)
4088
+
4089
+			flow := models.VmStockFlow{
4090
+				WarehousingId:           warehouse.ID,
4091
+				GoodId:                  goods.GoodId,
4092
+				Number:                  warehouse.Number,
4093
+				LicenseNumber:           warehouse.LicenseNumber,
4094
+				Count:                   out_count - count,
4095
+				UserOrgId:               orgID,
4096
+				PatientId:               patient_id,
4097
+				SystemTime:              record_time,
4098
+				ConsumableType:          7,
4099
+				IsSys:                   1,
4100
+				WarehousingOrder:        "",
4101
+				WarehouseOutId:          lastOut.WarehouseOutId,
4102
+				WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
4103
+				IsEdit:                  0,
4104
+				CancelStockId:           cancel.ID,
4105
+				CancelOrderNumber:       cancel.OrderNumber,
4106
+				Manufacturer:            manufacturer.ID,
4107
+				Dealer:                  0,
4108
+				Creator:                 warehouseOut.Creater,
4109
+				UpdateCreator:           0,
4110
+				Status:                  1,
4111
+				Ctime:                   time.Now().Unix(),
4112
+				Mtime:                   0,
4113
+				Price:                   warehouse.PackingPrice,
4114
+				WarehousingDetailId:     warehouse.ID,
4115
+				WarehouseOutDetailId:    lastOut.ID,
4116
+				CancelOutDetailId:       cancelInfo.ID,
4117
+				ProductDate:             warehouse.ProductDate,
4118
+				ExpireDate:              warehouse.ExpiryDate,
4119
+				StorehouseId:            goods.StorehouseId,
4120
+				BuyPrice:                warehouse.Price,
4121
+				ProjectId:               goods.ProjectId,
4122
+				OverCount:               sum_count,
4123
+				RegisterNumber:          warehouse.RegisterNumber,
4124
+			}
4125
+			if orgID == 9671 || orgID == 10265 {
4126
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4127
+				flow.Price = goodsInfo.PackingPrice
4128
+				flow.BuyPrice = goodsInfo.BuyPrice
4129
+			}
4130
+			err = tx.Create(&flow).Error
4131
+			if err != nil {
4132
+				return err
4133
+			}
4134
+		}
4135
+
4136
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
4137
+		goods.Count = deliver_number - stock_number
4138
+
4139
+		ConsumablesGoodDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
4140
+
4141
+	}
4142
+
4143
+	return nil
4144
+}

+ 2 - 2
service/patientmanage_service.go Ver arquivo

1055
 	if projectid > 0 {
1055
 	if projectid > 0 {
1056
 		db = db.Where("x.project_id = ?", projectid)
1056
 		db = db.Where("x.project_id = ?", projectid)
1057
 	}
1057
 	}
1058
-	err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0)   ").Scan(&inspection).Error
1058
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id = x.org_id) OR ( x.item_id = r.id AND r.org_id = 0)   ").Scan(&inspection).Error
1059
 	return inspection, err
1059
 	return inspection, err
1060
 }
1060
 }
1061
 
1061
 
1948
 
1948
 
1949
 func UpdatePatientFirstDisease(disease models.XtPatientFirstDisease, id int64) error {
1949
 func UpdatePatientFirstDisease(disease models.XtPatientFirstDisease, id int64) error {
1950
 
1950
 
1951
-	err := XTWriteDB().Model(&models.XtPatientFirstDisease{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"title": disease.Title, "doctor": disease.Doctor, "record_date": disease.RecordDate, "main_content": disease.MainContent, "patient_case": disease.PatientCase, "tentative_diagnosis": disease.TentativeDiagnosis, "diagnostic_basis": disease.DiagnosticBasis, "differential_diagnosis": disease.DifferentialDiagnosis, "treatment_plan": disease.TreatmentPlan}).Error
1951
+	err := XTWriteDB().Model(&models.XtPatientFirstDisease{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"title": disease.Title, "doctor": disease.Doctor, "record_date": disease.RecordDate, "main_content": disease.MainContent, "patient_case": disease.PatientCase, "tentative_diagnosis": disease.TentativeDiagnosis, "diagnostic_basis": disease.DiagnosticBasis, "differential_diagnosis": disease.DifferentialDiagnosis, "treatment_plan": disease.TreatmentPlan, "project_id": disease.ProjectId, "inspect_date": disease.InspectDate}).Error
1952
 	return err
1952
 	return err
1953
 }
1953
 }
1954
 
1954
 

+ 185 - 115
service/pharmacy_service.go Ver arquivo

30
 	XTWriteDB().Create(&tmp)
30
 	XTWriteDB().Create(&tmp)
31
 }
31
 }
32
 
32
 
33
-//
34
 func SavePharmacy() (err error) {
33
 func SavePharmacy() (err error) {
35
 	var advice_info []*models.HisDoctorAdviceInfo
34
 	var advice_info []*models.HisDoctorAdviceInfo
36
 	err = XTReadDB().Raw("select * from xt_doctor_advice where id > 21780 and id < 21790").Scan(&advice_info).Error
35
 	err = XTReadDB().Raw("select * from xt_doctor_advice where id > 21780 and id < 21790").Scan(&advice_info).Error
40
 	return nil
39
 	return nil
41
 }
40
 }
42
 
41
 
43
-//查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
42
+// 查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
44
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
43
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
45
 	//orgid = 9675
44
 	//orgid = 9675
46
 	InitDrugidIsNil(orgid, stime, etime)
45
 	InitDrugidIsNil(orgid, stime, etime)
47
 	var tmp []*models.TmpTTT
46
 	var tmp []*models.TmpTTT
48
 	if is_medicine == 0 {
47
 	if is_medicine == 0 {
49
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
48
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
50
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
49
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 0 and "+
51
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
50
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
52
 			"union "+
51
 			"union "+
53
 			"select distinct patient_id from xt_doctor_advice where "+
52
 			"select distinct patient_id from xt_doctor_advice where "+
54
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
53
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 0 and "+
55
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
54
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
56
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
55
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
57
 		if err != nil {
56
 		if err != nil {
59
 		}
58
 		}
60
 	} else {
59
 	} else {
61
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
60
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
62
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
61
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 1 and "+
63
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
62
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
64
 			"union "+
63
 			"union "+
65
 			"select distinct patient_id from xt_doctor_advice where "+
64
 			"select distinct patient_id from xt_doctor_advice where "+
66
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
65
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 1 and "+
67
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
66
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
68
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
67
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
69
 		if err != nil {
68
 		if err != nil {
75
 
74
 
76
 }
75
 }
77
 
76
 
78
-//(改)
77
+func GetTodayAdviceCount(stime, etime, orgid, is_medicine int64) (num int, err error) {
78
+
79
+	//orgid = 9675
80
+	InitDrugidIsNil(orgid, stime, etime)
81
+	var tmp []*models.TmpTTT
82
+	if is_medicine == 0 {
83
+		err = XTReadDB().Raw("select * from his_doctor_advice_info where status= 1 and advice_date>=? and advice_date<=? and user_org_id=? and is_medicine=0 group by patient_id",
84
+			stime, etime, orgid).Scan(&tmp).Error
85
+		if err != nil {
86
+			return
87
+		}
88
+	} else {
89
+		err = XTReadDB().Raw("select * from his_doctor_advice_info where status= 1 and advice_date>=? and advice_date<=? and user_org_id=? and is_medicine=1 group by patient_id",
90
+			stime, etime, orgid).Scan(&tmp).Error
91
+		if err != nil {
92
+			return
93
+		}
94
+	}
95
+
96
+	return len(tmp), err
97
+}
98
+
99
+func GetTodayAdviceCountOne(stime int64, etime int64, orgid int64, is_medicine int64) (advice []*models.HisDoctorAdviceInfo, err error) {
100
+
101
+	db := XTReadDB().Model(&advice).Where("status=1 and is_medicine = ?", is_medicine)
102
+	if stime > 0 {
103
+		db = db.Where("advice_date>=?", stime)
104
+	}
105
+	if etime > 0 {
106
+		db = db.Where("advice_date<=?", stime)
107
+	}
108
+	if orgid > 0 {
109
+		db = db.Where("user_org_id = ?", orgid)
110
+	}
111
+
112
+	err = db.Group("patient_id").Find(&advice).Error
113
+	return advice, err
114
+}
115
+
116
+func GetPatientByAdviceId(patient_id int64) (models.TmpPatientOne, error) {
117
+
118
+	patient := models.TmpPatientOne{}
119
+	err = XTReadDB().Where("id = ?", patient_id).Find(&patient).Error
120
+	return patient, err
121
+}
122
+
123
+// (改)
79
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
124
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
80
 	InitDrugidIsNil(orgid, stime, etime)
125
 	InitDrugidIsNil(orgid, stime, etime)
81
 	//病人
126
 	//病人
85
 		if keyword != "" {
130
 		if keyword != "" {
86
 			keyword = "%" + keyword + "%"
131
 			keyword = "%" + keyword + "%"
87
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
132
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
88
-				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
133
+				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
89
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
134
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
90
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
135
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
91
 				"union "+
136
 				"union "+
92
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
137
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
93
-				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
138
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
94
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
139
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
95
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
140
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
96
 				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
141
 				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
97
 		} else {
142
 		} else {
98
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
143
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
99
-				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
144
+				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
100
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
145
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
101
 				"union "+
146
 				"union "+
102
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
147
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
103
-				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
148
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
104
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
149
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
105
 				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
150
 				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
106
 		}
151
 		}
150
 
195
 
151
 }
196
 }
152
 
197
 
153
-//查询患者(改)
198
+// 查询患者(改)
154
 func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
199
 func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
155
 
200
 
156
 	for i := 0; i < len(tmp); i++ {
201
 	for i := 0; i < len(tmp); i++ {
167
 	return
212
 	return
168
 }
213
 }
169
 
214
 
170
-//查询患者当天时间段中的药,is_medicine:0未发,1已发(改)
215
+// 查询患者当天时间段中的药,is_medicine:0未发,1已发(改)
171
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
216
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
172
 	InitDrugidIsNil(orgid, stime, etime)
217
 	InitDrugidIsNil(orgid, stime, etime)
173
 	var tmp []*models.HisDoctorAdviceInfoL
218
 	var tmp []*models.HisDoctorAdviceInfoL
174
 	if is_medicine == 0 {
219
 	if is_medicine == 0 {
175
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
220
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
176
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
221
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
177
 		if err != nil {
222
 		if err != nil {
178
 			return pp, err
223
 			return pp, err
179
 		}
224
 		}
180
 	} else {
225
 	} else {
181
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
226
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
182
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
227
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
183
 		if err != nil {
228
 		if err != nil {
184
 			return pp, err
229
 			return pp, err
185
 		}
230
 		}
202
 	var tmp_advice []*models.XtDoctorAdviceL
247
 	var tmp_advice []*models.XtDoctorAdviceL
203
 	if is_medicine == 0 {
248
 	if is_medicine == 0 {
204
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
249
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
205
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
250
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
206
 		if err != nil {
251
 		if err != nil {
207
 			return pp, err
252
 			return pp, err
208
 		}
253
 		}
209
 	} else {
254
 	} else {
210
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
255
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
211
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
256
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
212
 		if err != nil {
257
 		if err != nil {
213
 			return pp, err
258
 			return pp, err
214
 		}
259
 		}
230
 	return
275
 	return
231
 }
276
 }
232
 
277
 
233
-//获取创建者姓名(改)
278
+// 获取创建者姓名(改)
234
 func GetAdminUserName(doctor, orgid int64) string {
279
 func GetAdminUserName(doctor, orgid int64) string {
235
 	var tmp models.VmUserAdminRole
280
 	var tmp models.VmUserAdminRole
236
 	XTReadDB().Model(&models.VmUserAdminRole{}).Where("admin_user_id = ? and org_id = ? and status = 1", doctor, orgid).Find(&tmp)
281
 	XTReadDB().Model(&models.VmUserAdminRole{}).Where("admin_user_id = ? and org_id = ? and status = 1", doctor, orgid).Find(&tmp)
237
 	return tmp.UserName
282
 	return tmp.UserName
238
 }
283
 }
239
 
284
 
240
-//查询该机构的药房配置,true: 通过药房发药,false:不通过药房发药。如果没有该机构的信息则生成一条数据
285
+// 查询该机构的药房配置,true: 通过药房发药,false:不通过药房发药。如果没有该机构的信息则生成一条数据
241
 func GetOrgIdPharmacyConfig(orgid int64) bool {
286
 func GetOrgIdPharmacyConfig(orgid int64) bool {
242
 	var total int
287
 	var total int
243
 	var tmp_pharmacy models.PharmacyConfig
288
 	var tmp_pharmacy models.PharmacyConfig
263
 	}
308
 	}
264
 }
309
 }
265
 
310
 
266
-//修改该机构的药房配置
311
+// 修改该机构的药房配置
267
 func ModifyPharmacyConfig(orgid, isopen int64) (err error) {
312
 func ModifyPharmacyConfig(orgid, isopen int64) (err error) {
268
 	if isopen == 1 || isopen == 2 {
313
 	if isopen == 1 || isopen == 2 {
269
 		err = XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{
314
 		err = XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{
276
 	return
321
 	return
277
 }
322
 }
278
 
323
 
279
-//查询该药品是否通过药房发药.0否;1是
324
+// 查询该药品是否通过药房发药.0否;1是
280
 func DrugAllocation(drug_id int64) (is_pharmacy int64, err error) {
325
 func DrugAllocation(drug_id int64) (is_pharmacy int64, err error) {
281
 	tmp := models.BaseDrugLib{}
326
 	tmp := models.BaseDrugLib{}
282
 	err = XTReadDB().Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).Find(&tmp).Error
327
 	err = XTReadDB().Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).Find(&tmp).Error
283
 	return tmp.IsPharmacy, err
328
 	return tmp.IsPharmacy, err
284
 }
329
 }
285
 
330
 
286
-//根据id查询该药是否发药
331
+// 根据id查询该药是否发药
287
 func MedicineState(id int64) (is_medicine models.HisDoctorAdviceInfoL, err error) {
332
 func MedicineState(id int64) (is_medicine models.HisDoctorAdviceInfoL, err error) {
288
 	tmp := models.HisDoctorAdviceInfoL{}
333
 	tmp := models.HisDoctorAdviceInfoL{}
289
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("id = ?", id).Find(&tmp).Error
334
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("id = ?", id).Find(&tmp).Error
290
 	return tmp, err
335
 	return tmp, err
291
 }
336
 }
292
 
337
 
293
-//发药明细列表(
338
+// 发药明细列表(
294
 func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword string) (dislist []*models.DispensingList, total int64, err error) {
339
 func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword string) (dislist []*models.DispensingList, total int64, err error) {
295
 	var fenye []*models.Pharmary //分页用的
340
 	var fenye []*models.Pharmary //分页用的
296
 	offset := (page - 1) * limit
341
 	offset := (page - 1) * limit
329
 	return
374
 	return
330
 }
375
 }
331
 
376
 
332
-//处方详情//////////////////////
377
+// 处方详情//////////////////////
333
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
378
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
334
 	var tmp []*models.HisDoctorAdviceInfoL
379
 	var tmp []*models.HisDoctorAdviceInfoL
335
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
380
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
371
 	return
416
 	return
372
 }
417
 }
373
 
418
 
374
-//查询病人的his id
419
+// 查询病人的his id
375
 func GetHisID(prescription_id, orgid int64) (id int64) {
420
 func GetHisID(prescription_id, orgid int64) (id int64) {
376
 	var tmp models.HisPrintPrescription
421
 	var tmp models.HisPrintPrescription
377
 	XTReadDB().Model(&models.HisPrintPrescription{}).Where("id = ?", prescription_id).Find(&tmp)
422
 	XTReadDB().Model(&models.HisPrintPrescription{}).Where("id = ?", prescription_id).Find(&tmp)
380
 	return fin.ID
425
 	return fin.ID
381
 }
426
 }
382
 
427
 
383
-//根据药品id获取药品信息
428
+// 根据药品id获取药品信息
384
 func GetDrugNameTX(id int64, tx *gorm.DB) (tmp models.SpBaseDrug, err error) {
429
 func GetDrugNameTX(id int64, tx *gorm.DB) (tmp models.SpBaseDrug, err error) {
385
 	err = tx.Model(&models.SpBaseDrug{}).Where("id = ? and status = 1", id).Find(&tmp).Error
430
 	err = tx.Model(&models.SpBaseDrug{}).Where("id = ? and status = 1", id).Find(&tmp).Error
386
 	return
431
 	return
392
 	return
437
 	return
393
 }
438
 }
394
 
439
 
395
-//查询药品(使用keyword)
440
+// 查询药品(使用keyword)
396
 func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDrug, error) {
441
 func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDrug, error) {
397
 	var tmp []*models.PharmacyBaseDrug
442
 	var tmp []*models.PharmacyBaseDrug
398
 	tt := make(map[int64]models.PharmacyBaseDrug)
443
 	tt := make(map[int64]models.PharmacyBaseDrug)
403
 	return tt, err
448
 	return tt, err
404
 }
449
 }
405
 
450
 
406
-//查询(
451
+// 查询(
407
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
452
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
408
 	InitDrugidIsNil(orgid, stime, etime)
453
 	InitDrugidIsNil(orgid, stime, etime)
409
 	var tmp []*models.TmpLLL
454
 	var tmp []*models.TmpLLL
474
 	return
519
 	return
475
 }
520
 }
476
 
521
 
477
-//根据药品id获取药品规格(
522
+// 根据药品id获取药品规格(
478
 func FindDrugSpecifications(id int64) (name, specifications string) {
523
 func FindDrugSpecifications(id int64) (name, specifications string) {
479
 	var tmp models.PharmacyBaseDrug
524
 	var tmp models.PharmacyBaseDrug
480
 	XTReadDB().Model(&models.PharmacyBaseDrug{}).Where("id = ?", id).Find(&tmp)
525
 	XTReadDB().Model(&models.PharmacyBaseDrug{}).Where("id = ?", id).Find(&tmp)
483
 	return
528
 	return
484
 }
529
 }
485
 
530
 
486
-//根据药品id获取当前药品出库仓库的库存数量
531
+// 根据药品id获取当前药品出库仓库的库存数量
487
 func GetInventoryQuantity(orgid, drugid int64) (number string, err error) {
532
 func GetInventoryQuantity(orgid, drugid int64) (number string, err error) {
488
 	//获取药品拆零数量
533
 	//获取药品拆零数量
489
 	var phar models.PharmacyBaseDrug
534
 	var phar models.PharmacyBaseDrug
516
 	return
561
 	return
517
 }
562
 }
518
 
563
 
519
-//获取该药品的病人信息(
564
+// 获取该药品的病人信息(
520
 func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*models.PatientInformation, err error) { ///////////////
565
 func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*models.PatientInformation, err error) { ///////////////
521
 	InitDrugidIsNil(orgid, stime, etime)
566
 	InitDrugidIsNil(orgid, stime, etime)
522
 	var tmp []*models.HisDoctorAdviceInfoL
567
 	var tmp []*models.HisDoctorAdviceInfoL
566
 	return
611
 	return
567
 }
612
 }
568
 
613
 
569
-//患者发药按钮点击(
614
+// 患者发药按钮点击(
570
 func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err error) {
615
 func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err error) {
571
 	//开事务
616
 	//开事务
572
 	tx := XTWriteDB().Begin()
617
 	tx := XTWriteDB().Begin()
581
 	time_now := time.Now().Unix()
626
 	time_now := time.Now().Unix()
582
 	var hids []*models.TmpID
627
 	var hids []*models.TmpID
583
 	var xids []*models.TmpID
628
 	var xids []*models.TmpID
584
-	err = tx.Raw("select id from his_doctor_advice_info where status = 1 and created_time >= ? and created_time <= ? "+
629
+	err = tx.Raw("select id from his_doctor_advice_info where status = 1 and advice_date >= ? and advice_date <= ? "+
585
 		"and user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
630
 		"and user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
586
 	if err != nil {
631
 	if err != nil {
587
 		return
632
 		return
601
 			if PettyCash(v.DrugId) {
646
 			if PettyCash(v.DrugId) {
602
 				continue
647
 				continue
603
 			}
648
 			}
604
-			//判断药品库存是否充足
649
+			////判断药品库存是否充足
605
 			kou := FenDrugInventory(v, orgid)
650
 			kou := FenDrugInventory(v, orgid)
606
 			if !kou {
651
 			if !kou {
607
 				err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
652
 				err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
630
 		return err1
675
 		return err1
631
 	}
676
 	}
632
 
677
 
633
-	err = tx.Raw("select id from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and "+
634
-		"user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
635
-	if err != nil {
636
-		return
637
-	}
638
-	xid := make([]int64, 0)
639
-	for _, v := range xids {
640
-		xid = append(xid, v.Id)
641
-	}
642
-	var advice []*models.HisDoctorAdviceInfo
643
-	err = tx.Raw("select * from xt_doctor_advice where id in (?) and status = 1", xid).Scan(&advice).Error
644
-	if err != nil {
645
-		return
646
-	}
647
-	for _, v := range advice {
648
-		tmp_bool := IsPharmacyConfig(orgid)
649
-		if tmp_bool {
650
-			if PettyCash(v.DrugId) {
651
-				continue
652
-			}
653
-			kou := FenDrugInventory(v, orgid)
654
-			if !kou {
655
-				err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
656
-				return
657
-			}
658
-			//扣减库存
659
-			err = FenStock(orgid, creater, v)
660
-			if err != nil {
661
-				err = fmt.Errorf("!:%v", err)
662
-				return
678
+	//针对大丰响水
679
+	if orgid != 10217 && orgid != 10188 && orgid != 9671 && orgid != 10164 {
680
+		err = tx.Raw("select id from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and "+
681
+			"user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
682
+		if err != nil {
683
+			return
684
+		}
685
+		xid := make([]int64, 0)
686
+		for _, v := range xids {
687
+			xid = append(xid, v.Id)
688
+		}
689
+		var advice []*models.HisDoctorAdviceInfo
690
+		err = tx.Raw("select * from xt_doctor_advice where id in (?) and status = 1", xid).Scan(&advice).Error
691
+		if err != nil {
692
+			return
693
+		}
694
+
695
+		for _, v := range advice {
696
+			tmp_bool := IsPharmacyConfig(orgid)
697
+			if tmp_bool {
698
+				if PettyCash(v.DrugId) {
699
+					continue
700
+				}
701
+				kou := FenDrugInventory(v, orgid)
702
+				if !kou {
703
+					err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
704
+					return
705
+				}
706
+				//扣减库存
707
+				err = FenStock(orgid, creater, v)
708
+				if err != nil {
709
+					err = fmt.Errorf("!:%v", err)
710
+					return
711
+				}
663
 			}
712
 			}
664
 		}
713
 		}
665
-	}
666
-	//修改状态
667
-	errs1 := XTWriteDB().Model(&models.XtDoctorAdviceL{}).Where("id in (?)", xid).Updates(map[string]interface{}{
668
-		"is_medicine":     1,
669
-		"people":          0,
670
-		"dispensing_time": time_now,
671
-		"updated_time":    time.Now().Unix(),
672
-	}).Error
673
-	if errs1 != nil {
674
-		return errs1
714
+		//修改状态
715
+		errs1 := XTWriteDB().Model(&models.XtDoctorAdviceL{}).Where("id in (?)", xid).Updates(map[string]interface{}{
716
+			"is_medicine":     1,
717
+			"people":          0,
718
+			"dispensing_time": time_now,
719
+			"updated_time":    time.Now().Unix(),
720
+		}).Error
721
+		if errs1 != nil {
722
+			return errs1
723
+		}
675
 	}
724
 	}
676
 
725
 
677
 	//生成明细记录
726
 	//生成明细记录
688
 	return
737
 	return
689
 }
738
 }
690
 
739
 
691
-//患者退药按钮点击
740
+// 患者退药按钮点击
692
 func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error) {
741
 func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error) {
693
 	//开事务
742
 	//开事务
694
 	tx := XTWriteDB().Begin()
743
 	tx := XTWriteDB().Begin()
829
 	return
878
 	return
830
 }
879
 }
831
 
880
 
832
-//获取患者名称
881
+// 获取患者名称
833
 func FindUserName(patient_id int64) (name string) {
882
 func FindUserName(patient_id int64) (name string) {
834
 	var tmp models.GetHisName
883
 	var tmp models.GetHisName
835
 	XTReadDB().Model(&models.GetHisName{}).Where("id = ?", patient_id).Find(&tmp)
884
 	XTReadDB().Model(&models.GetHisName{}).Where("id = ?", patient_id).Find(&tmp)
837
 	return
886
 	return
838
 }
887
 }
839
 
888
 
840
-//获取药品名称
889
+// 获取药品名称
841
 func FindDrugsName(drug_id int64) (name string) {
890
 func FindDrugsName(drug_id int64) (name string) {
842
 	var tmp models.Drug
891
 	var tmp models.Drug
843
 	XTReadDB().Model(&models.Drug{}).Where("id = ?", drug_id).Find(&tmp)
892
 	XTReadDB().Model(&models.Drug{}).Where("id = ?", drug_id).Find(&tmp)
845
 	return
894
 	return
846
 }
895
 }
847
 
896
 
848
-//药品发药按钮点击(
897
+// 药品发药按钮点击(
849
 func MedicineDeparture(ids string, creater, orgid int64) (err error) {
898
 func MedicineDeparture(ids string, creater, orgid int64) (err error) {
850
 	//开事务
899
 	//开事务
851
 	tx := XTWriteDB().Begin()
900
 	tx := XTWriteDB().Begin()
995
 	return
1044
 	return
996
 }
1045
 }
997
 
1046
 
998
-//获取领药人姓名(
1047
+// 获取领药人姓名(
999
 func GetUserAdminName(id, orgID int64) string {
1048
 func GetUserAdminName(id, orgID int64) string {
1000
 	var tmp models.XTSgjUserAdminRole
1049
 	var tmp models.XTSgjUserAdminRole
1001
 	XTReadDB().Model(&models.XTSgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgID).Find(&tmp)
1050
 	XTReadDB().Model(&models.XTSgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgID).Find(&tmp)
1002
 	return tmp.UserName
1051
 	return tmp.UserName
1003
 }
1052
 }
1004
 
1053
 
1005
-//根据id查询是否已发药,true已发药,false未发药gai
1054
+// 根据id查询是否已发药,true已发药,false未发药gai
1006
 func GiveTheMedicine(id int64) bool {
1055
 func GiveTheMedicine(id int64) bool {
1007
 	var xue models.PharmacyDoctorAdvice
1056
 	var xue models.PharmacyDoctorAdvice
1008
 	XTReadDB().Model(&models.PharmacyDoctorAdvice{}).Where("id = ?", id).Find(&xue)
1057
 	XTReadDB().Model(&models.PharmacyDoctorAdvice{}).Where("id = ?", id).Find(&xue)
1012
 	return false
1061
 	return false
1013
 }
1062
 }
1014
 
1063
 
1015
-//查询改组中的药品是否包含已发药的,true已发药,false未发药
1064
+// 查询改组中的药品是否包含已发药的,true已发药,false未发药
1016
 func GiveGroupMedicine(orgid, groupNo int64) bool {
1065
 func GiveGroupMedicine(orgid, groupNo int64) bool {
1017
 	var total int
1066
 	var total int
1018
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ? and status = 1 and is_medicine = 1", orgid, groupNo).Count(&total)
1067
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ? and status = 1 and is_medicine = 1", orgid, groupNo).Count(&total)
1022
 	return false
1071
 	return false
1023
 }
1072
 }
1024
 
1073
 
1025
-//查询处方中是否包含已发药的
1074
+// 查询处方中是否包含已发药的
1026
 func GiveChuMedicine(id int64) bool {
1075
 func GiveChuMedicine(id int64) bool {
1027
 	var total int
1076
 	var total int
1028
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", id).Count(&total)
1077
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", id).Count(&total)
1032
 	return false
1081
 	return false
1033
 }
1082
 }
1034
 
1083
 
1035
-//根据处方id查找该处方中是否存在已发药的药品
1084
+// 根据处方id查找该处方中是否存在已发药的药品
1036
 func IsChuIssuedDrugs(prescription_id int64) bool {
1085
 func IsChuIssuedDrugs(prescription_id int64) bool {
1037
 	var total int
1086
 	var total int
1038
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", prescription_id).Count(&total)
1087
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", prescription_id).Count(&total)
1042
 	return false
1091
 	return false
1043
 }
1092
 }
1044
 
1093
 
1045
-//判断该药品是否通过药房管理出库,true是,false否
1046
-//id 药品id,org_id 机构id
1094
+// 判断该药品是否通过药房管理出库,true是,false否
1095
+// id 药品id,org_id 机构id
1047
 func IsPharmacyDelivery(id, org_id int64) bool {
1096
 func IsPharmacyDelivery(id, org_id int64) bool {
1048
 	//判断药品是否通过药房管理
1097
 	//判断药品是否通过药房管理
1049
 	var total01 int
1098
 	var total01 int
1057
 	return false
1106
 	return false
1058
 }
1107
 }
1059
 
1108
 
1060
-//判断机构是否通过药房管理出库
1109
+// 判断机构是否通过药房管理出库
1061
 func IsPharmacyConfig(orgid int64) (bo bool) {
1110
 func IsPharmacyConfig(orgid int64) (bo bool) {
1062
 	var total int
1111
 	var total int
1063
 	XTReadDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and is_open = 1 and status = 1", orgid).Count(&total)
1112
 	XTReadDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and is_open = 1 and status = 1", orgid).Count(&total)
1067
 	return false
1116
 	return false
1068
 }
1117
 }
1069
 
1118
 
1070
-//根据患者id和发药时间,获取医生的id和姓名
1119
+// 根据患者id和发药时间,获取医生的id和姓名
1071
 func GetDoctorIds(id, recordtime, orgid int64) (doctor_id int64, doctor_name string, err error) {
1120
 func GetDoctorIds(id, recordtime, orgid int64) (doctor_id int64, doctor_name string, err error) {
1072
 	var tmp []*models.TmpAdviceDoctor
1121
 	var tmp []*models.TmpAdviceDoctor
1073
 	//var tmp []int64
1122
 	//var tmp []int64
1091
 	return dataString
1140
 	return dataString
1092
 }
1141
 }
1093
 
1142
 
1094
-//封装扣减库存
1143
+// 封装扣减库存
1095
 func FenStock(orgid, creater int64, v *models.HisDoctorAdviceInfo) (err error) {
1144
 func FenStock(orgid, creater int64, v *models.HisDoctorAdviceInfo) (err error) {
1096
 
1145
 
1097
 	err = HisDrugsDelivery(orgid, creater, v)
1146
 	err = HisDrugsDelivery(orgid, creater, v)
1118
 	return
1167
 	return
1119
 }
1168
 }
1120
 
1169
 
1121
-//封装查询药品库存是否足够
1170
+// 封装查询药品库存是否足够
1122
 func FenDrugInventory(item *models.HisDoctorAdviceInfo, orgid int64) bool {
1171
 func FenDrugInventory(item *models.HisDoctorAdviceInfo, orgid int64) bool {
1123
 	var total int64
1172
 	var total int64
1124
 	var prescribing_number_total int64
1173
 	var prescribing_number_total int64
1233
 	return false, err
1282
 	return false, err
1234
 }
1283
 }
1235
 
1284
 
1236
-//判断药品是否零用
1285
+// 判断药品是否零用
1237
 func PettyCash(id int64) bool {
1286
 func PettyCash(id int64) bool {
1238
 	drug := models.XtBaseDrug{}
1287
 	drug := models.XtBaseDrug{}
1239
 	XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug)
1288
 	XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug)
1243
 	return false
1292
 	return false
1244
 }
1293
 }
1245
 
1294
 
1246
-//初始化
1295
+// 初始化
1247
 func InitDrugidIsNil(orgid, stime, etime int64) {
1296
 func InitDrugidIsNil(orgid, stime, etime int64) {
1248
 	var advice []*models.DoctorAdvice
1297
 	var advice []*models.DoctorAdvice
1249
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("drug_id = 0 and user_org_id = ? and status = 1 and created_time >= ? and created_time <= ?", orgid, stime, etime).Find(&advice)
1298
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("drug_id = 0 and user_org_id = ? and status = 1 and created_time >= ? and created_time <= ?", orgid, stime, etime).Find(&advice)
1250
 	for _, v := range advice {
1299
 	for _, v := range advice {
1251
-		XTWriteDB().Exec("update xt_doctor_advice set drug_id = (select id from xt_base_drug where drug_name = ? and org_id = ?) where id = ?", v.AdviceName, v.UserOrgId, v.ID)
1300
+		XTWriteDB().Exec("update xt_doctor_advice set drug_id = (select id from xt_base_drug where drug_name = ? and org_id = ? and status = 1 limit 1) where id = ?", v.AdviceName, v.UserOrgId, v.ID)
1252
 	}
1301
 	}
1253
 }
1302
 }
1254
 
1303
 
1255
-//改变处方状态(发药
1304
+// 改变处方状态(发药
1256
 func ChangeHisPrescription(tmp []int64) (err error) {
1305
 func ChangeHisPrescription(tmp []int64) (err error) {
1257
 	var advice_info []*models.HisDoctorAdviceInfo
1306
 	var advice_info []*models.HisDoctorAdviceInfo
1258
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1307
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1279
 	return
1328
 	return
1280
 }
1329
 }
1281
 
1330
 
1282
-//改变处方状态(退药
1331
+// 改变处方状态(退药
1283
 func ChangeHisPrescriptionT(tmp []int64) (err error) {
1332
 func ChangeHisPrescriptionT(tmp []int64) (err error) {
1284
 	var advice_info []*models.HisDoctorAdviceInfo
1333
 	var advice_info []*models.HisDoctorAdviceInfo
1285
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1334
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1311
 	return
1360
 	return
1312
 }
1361
 }
1313
 
1362
 
1314
-//改变处方状态
1363
+// 改变处方状态
1315
 func ChangeHisPrescriptionid(id string) (err error) {
1364
 func ChangeHisPrescriptionid(id string) (err error) {
1316
 	var advice models.HisDoctorAdviceInfo
1365
 	var advice models.HisDoctorAdviceInfo
1317
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and status = 1", id).Find(&advice).Error
1366
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and status = 1", id).Find(&advice).Error
1331
 	return
1380
 	return
1332
 }
1381
 }
1333
 
1382
 
1334
-//获取药品规格
1383
+// 获取药品规格
1335
 func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrugs, err error) {
1384
 func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrugs, err error) {
1336
 	var g errgroup.Group
1385
 	var g errgroup.Group
1337
 	var lib []*models.BaseDrugLib
1386
 	var lib []*models.BaseDrugLib
1368
 	return
1417
 	return
1369
 }
1418
 }
1370
 
1419
 
1371
-//获取药品规格,不考虑特殊病
1420
+// 获取药品规格,不考虑特殊病
1372
 func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error) {
1421
 func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error) {
1373
 	var lib []*models.BaseDrugLib
1422
 	var lib []*models.BaseDrugLib
1374
 	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1 and drug_status not like '%停用%' ", orgid).Find(&lib).Error
1423
 	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1 and drug_status not like '%停用%' ", orgid).Find(&lib).Error
1390
 	return
1439
 	return
1391
 }
1440
 }
1392
 
1441
 
1393
-//根据药品id获取药品名字
1442
+// 根据药品id获取药品名字
1394
 func IdToDrugName(id int64) (name string) {
1443
 func IdToDrugName(id int64) (name string) {
1395
 	var lib models.BaseDrugLib
1444
 	var lib models.BaseDrugLib
1396
 	readDb.Model(&models.BaseDrugLib{}).Where("id = ?", id).Find(&lib)
1445
 	readDb.Model(&models.BaseDrugLib{}).Where("id = ?", id).Find(&lib)
1397
 	return lib.DrugName
1446
 	return lib.DrugName
1398
 }
1447
 }
1399
 
1448
 
1400
-//获取项目和耗材和套餐
1449
+// 获取项目和耗材和套餐
1401
 func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1450
 func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1402
 
1451
 
1403
 	var project []*models.XtHisProject
1452
 	var project []*models.XtHisProject
1439
 	return
1488
 	return
1440
 }
1489
 }
1441
 
1490
 
1442
-//获取项目和耗材
1491
+// 获取项目和耗材
1443
 func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList, err error) {
1492
 func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList, err error) {
1444
 
1493
 
1445
 	var project []*models.XtHisProject
1494
 	var project []*models.XtHisProject
1477
 	return
1526
 	return
1478
 }
1527
 }
1479
 
1528
 
1480
-//获取项目和耗材不考虑特殊病
1529
+// 获取项目和耗材不考虑特殊病
1481
 func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error) {
1530
 func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error) {
1482
 
1531
 
1483
 	var project []*models.XtHisProject
1532
 	var project []*models.XtHisProject
1507
 	return
1556
 	return
1508
 }
1557
 }
1509
 
1558
 
1510
-//查询药品
1559
+// 查询药品
1511
 func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1560
 func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1512
 	var total int
1561
 	var total int
1513
 	XTReadDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1 and "+
1562
 	XTReadDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1 and "+
1519
 	return false
1568
 	return false
1520
 }
1569
 }
1521
 
1570
 
1522
-//查询项目
1571
+// 查询项目
1523
 func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1572
 func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1524
 	var total int
1573
 	var total int
1525
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 2 and "+
1574
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 2 and "+
1531
 	return false
1580
 	return false
1532
 }
1581
 }
1533
 
1582
 
1534
-//查询耗材
1583
+// 查询耗材
1535
 func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1584
 func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1536
 	var total int
1585
 	var total int
1537
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 3 and "+
1586
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 3 and "+
1543
 	return false
1592
 	return false
1544
 }
1593
 }
1545
 
1594
 
1546
-//types处方类型,1.药品 2.项目,model透析模式
1595
+// types处方类型,1.药品 2.项目,model透析模式
1547
 func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1596
 func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1548
 	type tmpid struct {
1597
 	type tmpid struct {
1549
 		Id int64
1598
 		Id int64
1557
 	return
1606
 	return
1558
 }
1607
 }
1559
 
1608
 
1560
-//替换药品处方模板
1609
+// 替换药品处方模板
1561
 func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionAdviceTemplate, tx *gorm.DB) (err error) {
1610
 func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionAdviceTemplate, tx *gorm.DB) (err error) {
1562
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1611
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1563
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1612
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1577
 	return err
1626
 	return err
1578
 }
1627
 }
1579
 
1628
 
1580
-//替换项目模板
1629
+// 替换项目模板
1581
 func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionProjectTemplate, tx *gorm.DB) (err error) {
1630
 func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionProjectTemplate, tx *gorm.DB) (err error) {
1582
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1631
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1583
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1632
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1599
 	return err
1648
 	return err
1600
 }
1649
 }
1601
 
1650
 
1602
-//删除项目模板
1651
+// 删除项目模板
1603
 func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1652
 func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1604
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1653
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1605
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1654
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1609
 	return err
1658
 	return err
1610
 }
1659
 }
1611
 
1660
 
1612
-//删除处方模板
1661
+// 删除处方模板
1613
 func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1662
 func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1614
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1663
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1615
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1664
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1619
 	return err
1668
 	return err
1620
 }
1669
 }
1621
 
1670
 
1622
-//根据透析模式和患者id获取该患者的处方内容
1671
+// 根据透析模式和患者id获取该患者的处方内容
1623
 func PTemplateInformation(orgid, mode_id, patient_id int64) (tmp interface{}, err error) {
1672
 func PTemplateInformation(orgid, mode_id, patient_id int64) (tmp interface{}, err error) {
1624
 	//获取处方id
1673
 	//获取处方id
1625
 	var tt []*models.HisPrescriptionTemplate
1674
 	var tt []*models.HisPrescriptionTemplate
1695
 
1744
 
1696
 }
1745
 }
1697
 
1746
 
1698
-//收尾工作
1747
+// 收尾工作
1699
 func Scavenger(orgid int64) (err error) {
1748
 func Scavenger(orgid int64) (err error) {
1700
 	//开事务
1749
 	//开事务
1701
 	tx := XTWriteDB().Begin()
1750
 	tx := XTWriteDB().Begin()
1764
 	return
1813
 	return
1765
 }
1814
 }
1766
 
1815
 
1767
-//分区和收费(患者发药
1816
+// 分区和收费(患者发药
1768
 func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*models.TmpPatient) (tmp []*models.TmpPatient, err error) {
1817
 func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*models.TmpPatient) (tmp []*models.TmpPatient, err error) {
1769
 	//获取排班
1818
 	//获取排班
1770
 	var sch []*models.XtScheduleTwo
1819
 	var sch []*models.XtScheduleTwo
1794
 	return
1843
 	return
1795
 }
1844
 }
1796
 
1845
 
1797
-//分区和收费(药品发药
1846
+// 分区和收费(药品发药
1798
 func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, partition int64, flist []*models.PatientInformation) (tmp []*models.PatientInformation, err error) {
1847
 func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, partition int64, flist []*models.PatientInformation) (tmp []*models.PatientInformation, err error) {
1799
 	//获取排班
1848
 	//获取排班
1800
 	var sch []*models.XtScheduleTwo
1849
 	var sch []*models.XtScheduleTwo
1833
 	return
1882
 	return
1834
 }
1883
 }
1835
 
1884
 
1836
-//给药途径
1885
+// 给药途径
1837
 func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs) (tmp []*models.ListOfDrugs, err error) {
1886
 func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs) (tmp []*models.ListOfDrugs, err error) {
1838
 	//查询药品
1887
 	//查询药品
1839
 	var pp []*models.PharmacyBaseDrug
1888
 	var pp []*models.PharmacyBaseDrug
1860
 	return
1909
 	return
1861
 }
1910
 }
1862
 
1911
 
1863
-//计算总量
1912
+// 计算总量
1864
 func CalculateTheTotalAmount(tmp []*models.PatientInformation, drug_id int64) (total string, err error) {
1913
 func CalculateTheTotalAmount(tmp []*models.PatientInformation, drug_id int64) (total string, err error) {
1865
 	//获取药品信息
1914
 	//获取药品信息
1866
 	var t models.SpBaseDrug
1915
 	var t models.SpBaseDrug
1912
 	}
1961
 	}
1913
 	return zones, nil
1962
 	return zones, nil
1914
 }
1963
 }
1964
+
1965
+func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
1966
+
1967
+	db := XTReadDB().Model(&advice).Where("status= 1")
1968
+
1969
+	if orgid > 0 {
1970
+		db = db.Where("user_org_id = ?", orgid)
1971
+	}
1972
+	if patient_id > 0 {
1973
+		db = db.Where("patient_id = ?", patient_id)
1974
+	}
1975
+	if stime > 0 {
1976
+		db = db.Where("advice_date >=?", stime)
1977
+	}
1978
+	if etime > 0 {
1979
+		db = db.Where("advice_date<=?", etime)
1980
+	}
1981
+	err = db.Find(&advice).Error
1982
+
1983
+	return advice, err
1984
+}

+ 1 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go Ver arquivo

104
 	WashpipeNurse  int64           `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
104
 	WashpipeNurse  int64           `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
105
 	UserOrgId      int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
105
 	UserOrgId      int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
106
 	QualityNurseId int64           `gorm:"column:quality_nurse_id" json:"quality_nurse_id" form:"quality_nurse_id"`
106
 	QualityNurseId int64           `gorm:"column:quality_nurse_id" json:"quality_nurse_id" form:"quality_nurse_id"`
107
+	Url            string          `gorm:"column:url" json:"url" form:"url"`
107
 }
108
 }
108
 
109
 
109
 func (DialysisOrderVM) TableName() string {
110
 func (DialysisOrderVM) TableName() string {

+ 8 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go Ver arquivo

479
 	err := p_service.XTReadDB().Where("user_org_id = ? and patient_id = ? and assessment_date =? and status = 1", orgid, patient_id, assessment_date).Find(&SummerVM).Error
479
 	err := p_service.XTReadDB().Where("user_org_id = ? and patient_id = ? and assessment_date =? and status = 1", orgid, patient_id, assessment_date).Find(&SummerVM).Error
480
 	return &SummerVM, err
480
 	return &SummerVM, err
481
 }
481
 }
482
+
483
+func GetAdminUserEsTwo(orgid int64) (admin []*models.UserAdminRoles, err error) {
484
+	db := p_service.UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
485
+	table := p_service.UserReadDB().Table("sgj_user_admin_electronic_signature as s")
486
+	fmt.Println("table", table)
487
+	err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&admin).Error
488
+	return admin, err
489
+}

+ 8 - 0
service/stock_service.go Ver arquivo

8508
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
8508
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
8509
 	return config, err
8509
 	return config, err
8510
 }
8510
 }
8511
+
8512
+func UpdateDeleteAutoGood(good_id int64, record_date int64, patient_id int64) error {
8513
+
8514
+	err := XTWriteDB().Model(&models.AutomaticReduceDetail{}).Where("good_id = ? and record_time = ? and patient_id = ?", good_id, record_date, patient_id).Updates(map[string]interface{}{"status": 1}).Error
8515
+
8516
+	err = XTWriteDB().Model(&models.DialysisBeforePrepare{}).Where("good_id = ? and record_date = ? and patient_id = ?", good_id, record_date, patient_id).Updates(map[string]interface{}{"status": 1}).Error
8517
+	return err
8518
+}

+ 123 - 5
service/warhouse_service.go Ver arquivo

1208
 
1208
 
1209
 	//查询该患者当天已经出库的耗材信息
1209
 	//查询该患者当天已经出库的耗材信息
1210
 	goods_yc, _ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
1210
 	goods_yc, _ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
1211
+
1211
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
1212
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
1212
 	for i := len(goods_yc) - 1; i >= 0; i-- {
1213
 	for i := len(goods_yc) - 1; i >= 0; i-- {
1213
 		goods_yc_temp := goods_yc[i]
1214
 		goods_yc_temp := goods_yc[i]
1244
 
1245
 
1245
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1246
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1246
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
1247
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
1247
-
1248
+	fmt.Println("len233333333333333w", len(goods_yc))
1249
+	fmt.Println("需要出库的数据", len(goods))
1248
 	if len(goods) > 0 {
1250
 	if len(goods) > 0 {
1249
 		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1251
 		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1250
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1252
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1293
 
1295
 
1294
 			var cha_count int64
1296
 			var cha_count int64
1295
 			var cha_count_two int64
1297
 			var cha_count_two int64
1298
+			//查询已经出库的数量
1296
 			flowGood, _ := GetStockFlowIsBatchNumberTwo(patient_id, record_time, item.GoodId)
1299
 			flowGood, _ := GetStockFlowIsBatchNumberTwo(patient_id, record_time, item.GoodId)
1297
 			var out_count int64
1300
 			var out_count int64
1298
 			for _, item := range flowGood {
1301
 			for _, item := range flowGood {
1299
 				out_count += item.Count
1302
 				out_count += item.Count
1300
 			}
1303
 			}
1304
+			//已经出库的数量 减掉目前需要出库的数据
1301
 			cha_count = item.Count - out_count
1305
 			cha_count = item.Count - out_count
1302
-			//fmt.Println("item.Count", item.Count)
1303
-			//fmt.Println("item.Count", out_count)
1304
-			//fmt.Println("cha_count2323223232323223", cha_count)
1306
+
1305
 			cha_count_two = out_count - item.Count
1307
 			cha_count_two = out_count - item.Count
1306
 
1308
 
1307
 			prepare := models.DialysisBeforePrepare{
1309
 			prepare := models.DialysisBeforePrepare{
1313
 			}
1315
 			}
1314
 
1316
 
1315
 			ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
1317
 			ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
1318
+
1316
 			//数量增加
1319
 			//数量增加
1317
 			if cha_count > 0 {
1320
 			if cha_count > 0 {
1318
 				//出库数量累加
1321
 				//出库数量累加
1319
 				ModifyGoodSumCount(houseConfig.StorehouseOutInfo, cha_count, orgID, item.GoodId)
1322
 				ModifyGoodSumCount(houseConfig.StorehouseOutInfo, cha_count, orgID, item.GoodId)
1320
 			}
1323
 			}
1321
-			//数量减少
1324
+
1325
+			//已经出库的数据 大于 目前需要出库的数据
1322
 			if cha_count_two > 0 {
1326
 			if cha_count_two > 0 {
1327
+
1323
 				ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, cha_count_two, orgID, item.GoodId)
1328
 				ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, cha_count_two, orgID, item.GoodId)
1324
 				//退库数量增加
1329
 				//退库数量增加
1325
 				UpdateSumAddCancelCount(orgID, item.GoodId, houseConfig.StorehouseOutInfo, cha_count_two)
1330
 				UpdateSumAddCancelCount(orgID, item.GoodId, houseConfig.StorehouseOutInfo, cha_count_two)
1326
 
1331
 
1332
+				//生成退库单
1333
+
1327
 			}
1334
 			}
1328
 			//更新剩余库存
1335
 			//更新剩余库存
1329
 			goodListSix, _ := GetSumGoodList(orgID, houseConfig.StorehouseOutInfo, item.GoodId)
1336
 			goodListSix, _ := GetSumGoodList(orgID, houseConfig.StorehouseOutInfo, item.GoodId)
1826
 		if errThree != nil {
1833
 		if errThree != nil {
1827
 			return errThree
1834
 			return errThree
1828
 		}
1835
 		}
1836
+		fmt.Println("errThreee23333333333333333333333", errThree)
1829
 		//查询剩余库存
1837
 		//查询剩余库存
1830
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1838
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1831
 		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
1839
 		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
1833
 		for _, item := range goodList {
1841
 		for _, item := range goodList {
1834
 			sum_count += item.StockCount
1842
 			sum_count += item.StockCount
1835
 		}
1843
 		}
1844
+		fmt.Println("sum_count++++++++++++++++++++++++++++++++=", sum_count)
1836
 		// 判断当前出库的数据和删除出库数量
1845
 		// 判断当前出库的数据和删除出库数量
1837
 		if good_yc.Count <= ware.Count {
1846
 		if good_yc.Count <= ware.Count {
1838
 			delete_count = good_yc.Count
1847
 			delete_count = good_yc.Count
1902
 		//退库数量相加
1911
 		//退库数量相加
1903
 		UpdateSumAddCancelCount(good_yc.UserOrgId, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
1912
 		UpdateSumAddCancelCount(good_yc.UserOrgId, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
1904
 
1913
 
1914
+		operation_time := time.Now().Unix()
1915
+		//创建退库单
1916
+		timeStr := time.Now().Format("2006-01-02")
1917
+		timeArr := strings.Split(timeStr, "-")
1918
+		total, _ := FindAllCancelStockTotal(good_yc.UserOrgId)
1919
+		total = total + 1
1920
+		orderNumber := "CKTKD" + strconv.FormatInt(good_yc.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
1921
+
1922
+		cancelStock := models.CancelStock{
1923
+			OrderNumber:  orderNumber,
1924
+			OperaTime:    operation_time,
1925
+			OrgId:        good_yc.UserOrgId,
1926
+			Creater:      warehouseOut.Creater,
1927
+			Ctime:        time.Now().Unix(),
1928
+			Status:       1,
1929
+			ReturnTime:   record_time,
1930
+			Type:         1,
1931
+			StorehouseId: houseConfig.StorehouseOutInfo,
1932
+			IsCheck:      1,
1933
+		}
1934
+		_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, good_yc.UserOrgId)
1935
+		if msgerrkonde == gorm.ErrRecordNotFound {
1936
+			AddSigleCancelStock(&cancelStock)
1937
+		}
1938
+		cancel, _ := GetLastCancelStockById(good_yc.UserOrgId)
1939
+
1940
+		manufacturer, _ := GetManufactureById(ware.Manufacturer)
1941
+		deaerler, _ := GetDealerById(ware.Dealer)
1942
+
1943
+		cancelStockInfo := models.CancelStockInfo{
1944
+			GoodId:          ware.GoodId,
1945
+			CancelStockId:   cancel.ID,
1946
+			GoodTypeId:      ware.GoodTypeId,
1947
+			Count:           delete_count,
1948
+			Price:           ware.Price,
1949
+			Total:           0,
1950
+			ProductDate:     ware.ProductDate,
1951
+			ExpiryDate:      ware.ExpiryDate,
1952
+			Ctime:           time.Now().Unix(),
1953
+			Status:          1,
1954
+			OrgId:           good_yc.UserOrgId,
1955
+			OrderNumber:     cancel.OrderNumber,
1956
+			Type:            0,
1957
+			Dealer:          deaerler.DealerName,
1958
+			Manufacturer:    manufacturer.ManufacturerName,
1959
+			Number:          ware.Number,
1960
+			RegisterAccount: "",
1961
+			Remark:          "",
1962
+			WarehouseInfoId: ware.WarehouseInfotId,
1963
+			PatientId:       ware.PatientId,
1964
+			RecordDate:      record_time,
1965
+			StorehouseId:    houseConfig.StorehouseOutInfo,
1966
+			IsCheck:         1,
1967
+		}
1968
+
1969
+		CreateCancelStockInfoOne(&cancelStockInfo)
1970
+		cancelInfo, _ := GetLastCancelStockInfoByGoodId(ware.GoodId)
1971
+		goodListOne, _ := GetSumGoodList(good_yc.UserOrgId, houseConfig.StorehouseOutInfo, good_yc.GoodId)
1972
+		var over_count int64
1973
+		for _, it := range goodListOne {
1974
+			over_count += it.StockCount
1975
+		}
1976
+		flow := models.VmStockFlow{
1977
+			WarehousingId:           ware.WarehouseInfotId,
1978
+			GoodId:                  ware.GoodId,
1979
+			Number:                  ware.Number,
1980
+			LicenseNumber:           ware.LicenseNumber,
1981
+			Count:                   ware.Count,
1982
+			UserOrgId:               ware.OrgId,
1983
+			PatientId:               ware.PatientId,
1984
+			SystemTime:              record_time,
1985
+			ConsumableType:          7,
1986
+			IsSys:                   0,
1987
+			WarehousingOrder:        "",
1988
+			WarehouseOutId:          ware.WarehouseOutId,
1989
+			WarehouseOutOrderNumber: ware.WarehouseOutOrderNumber,
1990
+			IsEdit:                  0,
1991
+			CancelStockId:           cancel.ID,
1992
+			CancelOrderNumber:       cancel.OrderNumber,
1993
+			Manufacturer:            manufacturer.ID,
1994
+			Dealer:                  0,
1995
+			Creator:                 warehouseOut.Creater,
1996
+			UpdateCreator:           0,
1997
+			Status:                  1,
1998
+			Ctime:                   time.Now().Unix(),
1999
+			Mtime:                   0,
2000
+			Price:                   ware.Price,
2001
+			WarehousingDetailId:     ware.WarehouseInfotId,
2002
+			WarehouseOutDetailId:    ware.ID,
2003
+			CancelOutDetailId:       cancelInfo.ID,
2004
+			ProductDate:             ware.ProductDate,
2005
+			ExpireDate:              ware.ExpiryDate,
2006
+			StorehouseId:            houseConfig.StorehouseOutInfo,
2007
+			OverCount:               over_count,
2008
+		}
2009
+		CreateStockFlowOne(flow)
2010
+
1905
 		// 增加了对应的库存后,看看还有多少需要退库的
2011
 		// 增加了对应的库存后,看看还有多少需要退库的
1906
 		good_yc.Count = good_yc.Count - delete_count
2012
 		good_yc.Count = good_yc.Count - delete_count
1907
 		if good_yc.Count == 0 {
2013
 		if good_yc.Count == 0 {
6044
 	return err
6150
 	return err
6045
 }
6151
 }
6046
 
6152
 
6153
+func ModifyReduceGoodSumCountTwenty(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6154
+	ut := XTWriteDB().Begin()
6155
+
6156
+	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
6157
+	if err != nil {
6158
+		ut.Rollback()
6159
+		return err
6160
+	}
6161
+	ut.Commit()
6162
+	return err
6163
+}
6164
+
6047
 func ModifyAddGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6165
 func ModifyAddGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6048
 	ut := XTWriteDB().Begin()
6166
 	ut := XTWriteDB().Begin()
6049
 
6167