Bläddra i källkod

11月8日库存管理

XMLWAN 2 år sedan
förälder
incheckning
8eadc51dbd
3 ändrade filer med 187 tillägg och 73 borttagningar
  1. 139 36
      controllers/his_api_controller.go
  2. 42 37
      controllers/patient_api_controller.go
  3. 6 0
      service/dialysis_service.go

+ 139 - 36
controllers/his_api_controller.go Visa fil

@@ -1054,53 +1054,145 @@ func (c *HisApiController) CreateHisPrescription() {
1054 1054
 								drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
1055 1055
 								if drugOutConfig.IsOpen != 1 {
1056 1056
 									//修改处方
1057
-									if advicelist.ID > 0 {
1058
-										all_count, _ := strconv.ParseFloat(totals, 64) //总库存
1059
-										var his_count int64                            //历史出库数据
1060
-										if advicelist.PrescribingNumberUnit == drug.MaxUnit {
1061
-											strPrescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'E', -1, 64)
1062
-											intPrescribingNumber, _ := strconv.ParseInt(strPrescribingNumber, 10, 64)
1063
-											his_count = intPrescribingNumber * drug.MinNumber
1057
+									for _, advice := range advices {
1058
+										var drug_id int64
1059
+										var prescribing_number float64
1060
+										var prescribingNumberUnit string
1061
+										var prescribingNumber string
1062
+
1063
+										var adviceId int64
1064
+										if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1065
+											drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1064 1066
 										}
1065
-										if advicelist.PrescribingNumberUnit == drug.MinUnit {
1066
-											strPrescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'E', -1, 64)
1067
-											intPrescribingNumber, _ := strconv.ParseInt(strPrescribingNumber, 10, 64)
1068
-											his_count = intPrescribingNumber
1067
+										if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1068
+											prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1069
+											prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1070
+											prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
1069 1071
 										}
1070 1072
 
1071
-										if prescribingNumberUnit == drug.MinUnit {
1073
+										if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1074
+											prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1075
+										}
1072 1076
 
1073
-											float_prescribing_number := strconv.FormatFloat(prescribing_number, 'f', -1, 64)
1074
-											int_prescribing_number, _ := strconv.ParseInt(float_prescribing_number, 10, 64)
1075
-											float_all_count := strconv.FormatFloat(all_count, 'f', -1, 64)
1076
-											int_all_count, _ := strconv.ParseInt(float_all_count, 10, 64)
1077
+										if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1078
+											adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1079
+										}
1077 1080
 
1078
-											fmt.Println("总库存我的", int_all_count)
1079
-											fmt.Println("现在出库库存", int_prescribing_number)
1080
-											fmt.Println("历史出库数据", his_count)
1081
-											if (int_prescribing_number - his_count) > int_all_count {
1082
-												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1083
-												return
1081
+										drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1082
+										if drug.ID == 0 {
1083
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1084
+											return
1085
+										}
1086
+										houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
1087
+										//查询药品的所有库存
1088
+										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
1089
+										var total_count int64
1090
+										for _, it := range list {
1091
+											total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1092
+										}
1093
+										totals := strconv.FormatInt(total_count, 10)
1094
+										//查询该药品是否存在开药记录
1095
+										advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1096
+
1097
+										//新增处方
1098
+										if advicelist.ID == 0 {
1099
+											all_count, _ := strconv.ParseFloat(totals, 64)
1100
+											if prescribingNumberUnit == drug.MinUnit {
1101
+												if prescribing_number > all_count {
1102
+													c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1103
+													return
1104
+												}
1105
+											} else {
1106
+												if prescribingNumberUnit == drug.MaxUnit {
1107
+													num := prescribing_number * float64(drug.MinNumber)
1108
+													if num > all_count {
1109
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1110
+														return
1111
+													}
1112
+												}
1084 1113
 											}
1085
-
1086 1114
 										}
1087
-										if prescribingNumberUnit == drug.MaxUnit {
1088
-											float_all_count := strconv.FormatFloat(all_count, 'f', -1, 64)
1089
-											int_all_count, _ := strconv.ParseInt(float_all_count, 10, 64)
1090
-											num := prescribing_number * float64(drug.MinNumber)
1091
-											num_str_count := strconv.FormatFloat(num, 'f', -1, 64)
1092
-											num_int_count, _ := strconv.ParseInt(num_str_count, 10, 64)
1093
-											fmt.Println("总库存我的", int_all_count)
1094
-											fmt.Println("现在出库库存", num_str_count)
1095
-											fmt.Println("历史出库数据", his_count)
1096
-											if (num_int_count - his_count) > int_all_count {
1097
-												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1098
-												return
1115
+										//修改处方
1116
+										if advicelist.ID > 0 {
1117
+											var device_number int64
1118
+
1119
+											if advicelist.PrescribingNumberUnit == drug.MaxUnit {
1120
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1121
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1122
+												device_number = prescribingNumberInt * drug.MinNumber
1123
+											}
1124
+											if advicelist.PrescribingNumberUnit == drug.MinUnit {
1125
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1126
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1127
+												device_number = prescribingNumberInt
1128
+											}
1129
+
1130
+											var number_count int64
1131
+											if prescribingNumberUnit == drug.MaxUnit {
1132
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1133
+												number_count = prescribingNumberInt * drug.MinNumber
1134
+											}
1135
+											if prescribingNumberUnit == drug.MinUnit {
1136
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1137
+												number_count = prescribingNumberInt
1138
+											}
1139
+
1140
+											//如果修改的数量大于之前修改的数量
1141
+											if (number_count - device_number) > 0 {
1142
+												//如果修改的差数量 大于库存数量
1143
+												if (number_count - device_number) > total_count {
1144
+													c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1145
+													return
1146
+												}
1147
+											}
1148
+
1149
+											if device_number != number_count {
1150
+
1151
+												// 查询该药品最后一次出库记录
1152
+												druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
1153
+
1154
+												//回退库存
1155
+												if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1156
+
1157
+													service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
1158
+												}
1159
+												if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
1160
+													var stock_max_number int64
1161
+													var stock_min_number int64
1162
+
1163
+													if number_count >= drug.MinNumber {
1164
+
1165
+														stock_max_number = device_number / drug.MinNumber
1166
+														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
1167
+														stock_min_number = device_number % drug.MinNumber
1168
+														service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
1169
+
1170
+													} else {
1171
+
1172
+														service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
1173
+													}
1174
+												}
1175
+
1176
+												if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
1177
+													service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
1178
+												}
1179
+												//删除记录
1180
+												service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
1181
+
1182
+												//查询默认仓库
1183
+												storeHouseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
1184
+												//查询默认仓库剩余多少库存
1185
+												var sum_count int64
1186
+												stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
1187
+												for _, its := range stockInfo {
1188
+													sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
1189
+												}
1190
+												service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
1191
+
1099 1192
 											}
1100 1193
 										}
1101 1194
 									}
1102 1195
 								}
1103
-
1104 1196
 							}
1105 1197
 						}
1106 1198
 					}
@@ -1191,9 +1283,20 @@ func (c *HisApiController) CreateHisPrescription() {
1191 1283
 											for _, item := range goodList {
1192 1284
 												//回退库存
1193 1285
 												service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
1286
+
1287
+												//查询默认仓库
1288
+												storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
1289
+												stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, item.OrgId)
1290
+												var total_count int64
1291
+												for _, it := range stockList {
1292
+													total_count += it.StockCount
1293
+												}
1294
+												//基础库插入数据
1295
+												service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
1194 1296
 											}
1195 1297
 											//删除记录
1196 1298
 											service.DeleteAutoWarehouse(patient_id, recordDateTime)
1299
+
1197 1300
 										}
1198 1301
 
1199 1302
 									}

+ 42 - 37
controllers/patient_api_controller.go Visa fil

@@ -1914,7 +1914,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1914 1914
 					if adviceSetting.IsAdviceOpen == 1 {
1915 1915
 						//查询是否出库按钮开启
1916 1916
 						prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
1917
-						fmt.Println("prescriptionConfigwodweweeeweweweweweewewewwewew", prescriptionConfig)
1917
+						fmt.Println("prescriptionConfigwodweweeeweweweweweewewewwewew", prescriptionConfig.IsOpen)
1918 1918
 						if prescriptionConfig.IsOpen == 1 {
1919 1919
 							if medical.IsUse == 2 {
1920 1920
 								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
@@ -2135,47 +2135,49 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2135 2135
 
2136 2136
 		//药品管理信息
2137 2137
 		_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
2138
-
2138
+		fmt.Println("h2h332o2o23o32o32o32oo32o23o23o23o23o23o32o23o232o3wode", drugStockConfig.IsOpen)
2139 2139
 		if drugStockConfig.IsOpen == 1 {
2140 2140
 			//查询已经执行的医嘱
2141
-			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
2141
+			advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
2142 2142
 			for _, item := range advices {
2143
-
2144 2143
 				medical, _ := service.GetBaseDrugMedical(advice.DrugId)
2145 2144
 				//查询这个患者这个患者这个药已经出库的所有数量
2146
-				advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
2147
-				drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
2148
-				var total_count int64
2149
-				var drug_count int64
2150
-				for _, it := range advicelist {
2151
-					if it.PrescribingNumberUnit == medical.MaxUnit {
2152
-						prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
2153
-						prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2154
-						total_count += prenumber * medical.MinNumber
2155
-					}
2156
-					if it.PrescribingNumberUnit == medical.MinUnit {
2157
-						prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
2158
-						prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2159
-						total_count += prenumber
2160
-					}
2161
-
2162
-				}
2163
-
2164
-				for _, its := range drugoutlist {
2165
-					if its.CountUnit == medical.MaxUnit {
2166
-						drug_count += its.Count * medical.MinNumber
2167
-					}
2168
-					if its.CountUnit == medical.MinUnit {
2169
-						drug_count += its.Count
2170
-					}
2171
-				}
2172
-				if total_count == drug_count {
2173
-					c.ServeSuccessJSON(map[string]interface{}{
2174
-						"msg":    "1",
2175
-						"advice": advice,
2176
-					})
2177
-					return
2178
-				}
2145
+				//advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
2146
+				//drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
2147
+				//var total_count int64 // 现在出库的
2148
+				//var drug_count int64  // 已经出库的
2149
+				//for _, it := range advicelist {
2150
+				//	if it.PrescribingNumberUnit == medical.MaxUnit {
2151
+				//		prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
2152
+				//		prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2153
+				//		total_count += prenumber * medical.MinNumber
2154
+				//	}
2155
+				//	if it.PrescribingNumberUnit == medical.MinUnit {
2156
+				//		prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
2157
+				//		prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2158
+				//		total_count += prenumber
2159
+				//	}
2160
+				//
2161
+				//}
2162
+				//
2163
+				//
2164
+				//for _, its := range drugoutlist {
2165
+				//	if its.CountUnit == medical.MaxUnit {
2166
+				//		drug_count += its.Count * medical.MinNumber
2167
+				//	}
2168
+				//	if its.CountUnit == medical.MinUnit {
2169
+				//		drug_count += its.Count
2170
+				//	}
2171
+				//}
2172
+				//fmt.Println("total_count23232323232323232wode",total_count)
2173
+				//fmt.Println("total_count23232323232323232wode",drug_count)
2174
+				//if total_count == drug_count {
2175
+				//	c.ServeSuccessJSON(map[string]interface{}{
2176
+				//		"msg":    "1",
2177
+				//		"advice": advice,
2178
+				//	})
2179
+				//	return
2180
+				//}
2179 2181
 
2180 2182
 				var total int64
2181 2183
 				var prescribing_number_total int64
@@ -2212,6 +2214,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2212 2214
 						})
2213 2215
 						return
2214 2216
 					}
2217
+					fmt.Println("prescribing_number_totalwodeeeeeeeeeeeeee", prescribing_number_total)
2218
+					fmt.Println("total3233332323223322323322323", total)
2215 2219
 					if prescribing_number_total > total {
2216 2220
 						c.ServeSuccessJSON(map[string]interface{}{
2217 2221
 							"msg":    "2",
@@ -2222,6 +2226,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2222 2226
 
2223 2227
 					if prescribing_number_total <= total {
2224 2228
 						if medical.IsUse == 2 {
2229
+							fmt.Println("config233232323232232333223232332323233223322232wode", config.IsOpen)
2225 2230
 							if config.IsOpen != 1 {
2226 2231
 								service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
2227 2232
 								//查询默认仓库

+ 6 - 0
service/dialysis_service.go Visa fil

@@ -1378,6 +1378,12 @@ func GetHisExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvic
1378 1378
 	return doctorAdvice, err
1379 1379
 }
1380 1380
 
1381
+func GetHisExecutionDoctorsTwo(orgid int64, patientid int64, id int64) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) {
1382
+
1383
+	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and patient_id = ? AND id = ? and status = 1 and execution_state = 1", orgid, patientid, id).Find(&doctorAdvice).Error
1384
+	return doctorAdvice, err
1385
+}
1386
+
1381 1387
 func FindHisDoctorAdviceById(orgID int64, id int64) (advice models.HisDoctorAdviceInfo, err error) {
1382 1388
 	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error
1383 1389
 	return