Ver código fonte

11月8日库存管理

XMLWAN 2 anos atrás
pai
commit
c8d47635ac

+ 0 - 1
controllers/dialysis_parameter_api_controller.go Ver arquivo

@@ -37,7 +37,6 @@ func (this *DialysisPrameterApiController) GetDialysisParameters() {
37 37
 	adminUserInfo := this.GetAdminUserInfo()
38 38
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
39 39
 
40
-	fmt.Println("scheduletype", schedulType, start_time, partitionType, keywords, theTime.Unix())
41 40
 	if len(keywords) > 0 {
42 41
 		dialysisSchedule, err, total := service.GetDialysisParametersByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, theTime.Unix())
43 42
 		patient, err := service.GetDialysisTodaySchedulePatient(adminUserInfo.CurrentOrgId, theTime.Unix(), page, limit, keywords, schedulType, partitionType)

+ 201 - 25
controllers/his_api_controller.go Ver arquivo

@@ -965,6 +965,8 @@ func (c *HisApiController) CreateHisPrescription() {
965 965
 	adminInfo := c.GetAdminUserInfo()
966 966
 	recordDateTime := theTime.Unix()
967 967
 
968
+	//查询默认出库仓库库存
969
+	storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
968 970
 	role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
969 971
 
970 972
 	if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
@@ -1018,8 +1020,7 @@ func (c *HisApiController) CreateHisPrescription() {
1018 1020
 									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1019 1021
 									return
1020 1022
 								}
1021
-								//查询默认出库仓库库存
1022
-								storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
1023
+
1023 1024
 								//查询药品的所有库存
1024 1025
 								list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1025 1026
 
@@ -1104,9 +1105,8 @@ func (c *HisApiController) CreateHisPrescription() {
1104 1105
 											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1105 1106
 											return
1106 1107
 										}
1107
-										houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
1108 1108
 										//查询药品的所有库存
1109
-										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
1109
+										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1110 1110
 										var total_count int64
1111 1111
 										for _, it := range list {
1112 1112
 											total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
@@ -1157,6 +1157,7 @@ func (c *HisApiController) CreateHisPrescription() {
1157 1157
 										}
1158 1158
 										//修改处方
1159 1159
 										if advicelist.ID > 0 {
1160
+											fmt.Println("232323232323232332323o2323o23o23o23o3o")
1160 1161
 											//查询最新批次库存
1161 1162
 											info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1162 1163
 											var batch_number_count int64
@@ -1184,7 +1185,8 @@ func (c *HisApiController) CreateHisPrescription() {
1184 1185
 												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1185 1186
 												number_count = prescribingNumberInt
1186 1187
 											}
1187
-
1188
+											fmt.Println("number-count23323232233223", number_count)
1189
+											fmt.Println("device_number232323322323233223", device_number)
1188 1190
 											//如果修改的数量大于之前修改的数量
1189 1191
 											if (number_count - device_number) > 0 {
1190 1192
 												//如果修改的差数量 大于库存数量
@@ -1193,10 +1195,39 @@ func (c *HisApiController) CreateHisPrescription() {
1193 1195
 														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1194 1196
 														return
1195 1197
 													}
1198
+													fmt.Println("(number_count - device_number3232323232332", number_count-device_number)
1199
+													fmt.Println("(number_count - device_number3232323232332", batch_number_count)
1196 1200
 													if (number_count - device_number) > batch_number_count {
1197 1201
 														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1198 1202
 														return
1199 1203
 													}
1204
+
1205
+													// 查询该药品最后一次出库记录
1206
+													outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
1207
+													var out_count int64
1208
+													var in_count int64
1209
+													var stock_max_number int64
1210
+													var stock_min_number int64
1211
+													for _, it := range outInfo {
1212
+														if it.CountUnit == drug.MaxUnit {
1213
+															it.Count = it.Count * drug.MinNumber
1214
+														}
1215
+														out_count += it.Count
1216
+														warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
1217
+														stock_max_number = warehouseInfoList.StockMaxNumber
1218
+														stock_min_number = warehouseInfoList.StockMinNumber
1219
+														if warehouseInfoList.MaxUnit == drug.MaxUnit {
1220
+															in_count = warehouseInfoList.WarehousingCount * drug.MinNumber
1221
+														}
1222
+														if warehouseInfoList.MaxUnit == drug.MinUnit {
1223
+															in_count = warehouseInfoList.WarehousingCount
1224
+														}
1225
+													}
1226
+													if (out_count + (number_count - device_number)) > in_count {
1227
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
1228
+														return
1229
+													}
1230
+
1200 1231
 												}
1201 1232
 
1202 1233
 											}
@@ -1234,11 +1265,9 @@ func (c *HisApiController) CreateHisPrescription() {
1234 1265
 												//删除记录
1235 1266
 												service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
1236 1267
 
1237
-												//查询默认仓库
1238
-												storeHouseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
1239 1268
 												//查询默认仓库剩余多少库存
1240 1269
 												var sum_count int64
1241
-												stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
1270
+												stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
1242 1271
 												for _, its := range stockInfo {
1243 1272
 													sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
1244 1273
 												}
@@ -1248,6 +1277,167 @@ func (c *HisApiController) CreateHisPrescription() {
1248 1277
 										}
1249 1278
 									}
1250 1279
 								}
1280
+
1281
+								//保存处方开药
1282
+								if drugOutConfig.IsOpen == 1 {
1283
+									//修改处方
1284
+									for _, advice := range advices {
1285
+										var drug_id int64
1286
+										var prescribing_number float64
1287
+										var prescribingNumberUnit string
1288
+										var prescribingNumber string
1289
+
1290
+										var adviceId int64
1291
+										if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1292
+											drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1293
+										}
1294
+										if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1295
+											prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1296
+											prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1297
+											prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
1298
+										}
1299
+
1300
+										if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1301
+											prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1302
+										}
1303
+
1304
+										if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1305
+											adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1306
+										}
1307
+
1308
+										drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1309
+										if drug.ID == 0 {
1310
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1311
+											return
1312
+										}
1313
+										//查询药品的所有库存
1314
+										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1315
+										var total_count int64
1316
+										for _, it := range list {
1317
+											total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1318
+										}
1319
+										totals := strconv.FormatInt(total_count, 10)
1320
+										//查询该药品是否存在开药记录
1321
+										advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1322
+
1323
+										//新增处方
1324
+										if advicelist.ID == 0 {
1325
+											//查询最新批次库存
1326
+											info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1327
+											var batch_number_count int64
1328
+											batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1329
+											batch_number_counts := strconv.FormatInt(batch_number_count, 10)
1330
+											all_count, _ := strconv.ParseFloat(totals, 64)
1331
+											if prescribingNumberUnit == drug.MinUnit {
1332
+												batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1333
+												if drug.IsUse != 1 {
1334
+													if prescribing_number > all_count {
1335
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1336
+														return
1337
+													}
1338
+													if prescribing_number > batch_number_all_count {
1339
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1340
+														return
1341
+													}
1342
+												}
1343
+
1344
+											} else {
1345
+												if prescribingNumberUnit == drug.MaxUnit {
1346
+													batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1347
+													num := prescribing_number * float64(drug.MinNumber)
1348
+													if drug.IsUse != 1 {
1349
+														if num > all_count {
1350
+															c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1351
+															return
1352
+														}
1353
+
1354
+														if prescribing_number > batch_number_all_count {
1355
+															c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1356
+															return
1357
+														}
1358
+													}
1359
+
1360
+												}
1361
+											}
1362
+										}
1363
+										//修改处方
1364
+										if advicelist.ID > 0 {
1365
+											//查询最新批次库存
1366
+											info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1367
+											var batch_number_count int64
1368
+											batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1369
+
1370
+											var device_number int64
1371
+
1372
+											if advicelist.PrescribingNumberUnit == drug.MaxUnit {
1373
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1374
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1375
+												device_number = prescribingNumberInt * drug.MinNumber
1376
+											}
1377
+											if advicelist.PrescribingNumberUnit == drug.MinUnit {
1378
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1379
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1380
+												device_number = prescribingNumberInt
1381
+											}
1382
+
1383
+											var number_count int64
1384
+											if prescribingNumberUnit == drug.MaxUnit {
1385
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1386
+												number_count = prescribingNumberInt * drug.MinNumber
1387
+											}
1388
+											if prescribingNumberUnit == drug.MinUnit {
1389
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1390
+												number_count = prescribingNumberInt
1391
+											}
1392
+											//如果修改的数量大于之前修改的数量
1393
+											if (number_count - device_number) > 0 {
1394
+												//如果修改的差数量 大于库存数量
1395
+												if drug.IsUse != 1 {
1396
+													if (number_count - device_number) > total_count {
1397
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1398
+														return
1399
+													}
1400
+													if (number_count - device_number) > batch_number_count {
1401
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1402
+														return
1403
+													}
1404
+
1405
+													//查询历史出库数据总批次
1406
+													// 查询该药品最后一次出库记录
1407
+													outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
1408
+													var out_count int64
1409
+													var in_count int64
1410
+													var stock_max_number int64
1411
+													var stock_min_number int64
1412
+													for _, it := range outInfo {
1413
+														if it.CountUnit == drug.MaxUnit {
1414
+															it.Count = it.Count * drug.MinNumber
1415
+														}
1416
+														out_count += it.Count
1417
+														warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
1418
+														stock_max_number = warehouseInfoList.StockMaxNumber
1419
+														stock_min_number = warehouseInfoList.StockMinNumber
1420
+														if warehouseInfoList.MaxUnit == drug.MaxUnit {
1421
+															in_count = warehouseInfoList.WarehousingCount * drug.MinNumber
1422
+														}
1423
+														if warehouseInfoList.MaxUnit == drug.MinUnit {
1424
+															in_count = warehouseInfoList.WarehousingCount
1425
+														}
1426
+													}
1427
+													//fmt.Println("out_count23323232233233223",out_count)
1428
+													//fmt.Println("+(number_count - device_number)",(number_count - device_number))
1429
+													//fmt.Println("in_count23322323222222",in_count)
1430
+													if (out_count + (number_count - device_number)) > in_count {
1431
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
1432
+														return
1433
+													}
1434
+
1435
+												}
1436
+											}
1437
+										}
1438
+									}
1439
+								}
1440
+
1251 1441
 							}
1252 1442
 						}
1253 1443
 					}
@@ -1340,8 +1530,7 @@ func (c *HisApiController) CreateHisPrescription() {
1340 1530
 												service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
1341 1531
 
1342 1532
 												//查询默认仓库
1343
-												storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
1344
-												stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, item.OrgId)
1533
+												stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
1345 1534
 												var total_count int64
1346 1535
 												for _, it := range stockList {
1347 1536
 													total_count += it.StockCount
@@ -1406,7 +1595,6 @@ func (c *HisApiController) CreateHisPrescription() {
1406 1595
 		defer redis.Close()
1407 1596
 	} else {
1408 1597
 		hpInfo = models.HisPrescriptionInfo{
1409
-
1410 1598
 			ID:                 info.ID,
1411 1599
 			UserOrgId:          adminInfo.CurrentOrgId,
1412 1600
 			RecordDate:         info.RecordDate,
@@ -1444,8 +1632,6 @@ func (c *HisApiController) CreateHisPrescription() {
1444 1632
 	var adviceList []models.HisDoctorAdviceInfo
1445 1633
 	var projectList []models.HisPrescriptionProject
1446 1634
 
1447
-	//var hisLis  []models.HisList
1448
-
1449 1635
 	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1450 1636
 		prescriptions, _ := dataBody["prescriptions"].([]interface{})
1451 1637
 
@@ -1722,15 +1908,6 @@ func (c *HisApiController) CreateHisPrescription() {
1722 1908
 
1723 1909
 							service.SaveHisProjectTwo(&p)
1724 1910
 
1725
-							//if p.Type == 3 { //处理透前准备耗材数量数据
1726
-							//	consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
1727
-							//	if consumables.ID > 0 {
1728
-							//		cnt, _ := strconv.ParseInt(p.Count, 10, 64)
1729
-							//		consumables.Count = cnt
1730
-							//		service.UpdateConsumables(&consumables)
1731
-							//	}
1732
-							//}
1733
-
1734 1911
 						}
1735 1912
 					}
1736 1913
 				}
@@ -1774,18 +1951,17 @@ func (c *HisApiController) CreateHisPrescription() {
1774 1951
 
1775 1952
 		//查询今日该患者开的药品处方
1776 1953
 		hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
1777
-		storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
1778 1954
 		drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
1779 1955
 		if drugOutConfig.IsOpen == 1 {
1780 1956
 			for _, item := range hisdoctorlist {
1781 1957
 				drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
1782
-
1783 1958
 				// 查询该药品最后一次出库记录
1784 1959
 				druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
1785 1960
 
1786 1961
 				if len(druginfo) > 0 {
1787 1962
 					//回退库存
1788 1963
 					for _, it := range druginfo {
1964
+
1789 1965
 						if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1790 1966
 							service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
1791 1967
 						}
@@ -1809,7 +1985,7 @@ func (c *HisApiController) CreateHisPrescription() {
1809 1985
 					}
1810 1986
 
1811 1987
 					//更新字典里面的库存
1812
-					stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1988
+					stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1813 1989
 					var sum_count int64
1814 1990
 					for _, its := range stockInfo {
1815 1991
 						sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber