28169 hace 1 año
padre
commit
03dd062894

+ 5 - 0
controllers/dialysis_record_api_controller.go Ver fichero

@@ -412,6 +412,9 @@ func (this *DialysisRecordAPIController) DialysisSchedule() {
412 412
 	lastDryWeightDislysis, getDryErr := service.GetLastDryWeight(adminInfo.CurrentOrgId, patientID)
413 413
 
414 414
 	lastOrder, _ := service.GetLastDilysisOrder(adminInfo.CurrentOrgId, patientID, date.Unix())
415
+
416
+	//统计表
417
+	dryWeightList, _ := service.GetPatientDryWeight(adminInfo.CurrentOrgId, patientID)
415 418
 	if getDryErr != nil {
416 419
 		this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
417 420
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -466,6 +469,7 @@ func (this *DialysisRecordAPIController) DialysisSchedule() {
466 469
 			"information":                 information,
467 470
 			"is_advice_open":              adviceConfig,
468 471
 			"lastOrder":                   lastOrder,
472
+			"dryWeightList":               dryWeightList,
469 473
 		}
470 474
 		this.ServeSuccessJSON(returnData)
471 475
 
@@ -503,6 +507,7 @@ func (this *DialysisRecordAPIController) DialysisSchedule() {
503 507
 			"information":                 information,
504 508
 			"is_advice_open":              adviceConfig,
505 509
 			"lastOrder":                   lastOrder,
510
+			"dryWeightList":               dryWeightList,
506 511
 		}
507 512
 		this.ServeSuccessJSON(returnData)
508 513
 	}

+ 43 - 32
controllers/mobile_api_controllers/patient_api_controller.go Ver fichero

@@ -1075,6 +1075,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1075 1075
 			item.ExecutionState = 1
1076 1076
 			item.ExecutionStaff = adminInfo.AdminUser.Id
1077 1077
 			item.ExecutionTime = theTime.Unix()
1078
+			item.IsMobile = 1
1078 1079
 			err = service.SaveHisDoctorAdvice(item)
1079 1080
 			key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
1080 1081
 			redis := service.RedisClient()
@@ -1171,18 +1172,22 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1171 1172
 						}
1172 1173
 
1173 1174
 						if medical.IsUse == 1 {
1174
-							drugError := models.XtDrugError{
1175
-								UserOrgId:  adminInfo.Org.Id,
1176
-								DrugId:     item.DrugId,
1177
-								RecordDate: item.AdviceDate,
1178
-								PatientId:  item.PatientId,
1179
-								Remark:     "零用药品",
1180
-								Status:     1,
1181
-								Ctime:      time.Now().Unix(),
1182
-								Mtime:      0,
1183
-							}
1184
-							service.CreateDrugError(drugError)
1175
+
1185 1176
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
1177
+								drugError := models.XtDrugError{
1178
+									UserOrgId:             adminInfo.Org.Id,
1179
+									DrugId:                item.DrugId,
1180
+									RecordDate:            item.AdviceDate,
1181
+									PatientId:             item.PatientId,
1182
+									Remark:                "零用药品库存不足",
1183
+									Status:                1,
1184
+									Ctime:                 time.Now().Unix(),
1185
+									Mtime:                 0,
1186
+									SumCount:              list.Count*medical.MinNumber + list.StockMinNumber,
1187
+									Prescribingnumber:     advice.PrescribingNumber,
1188
+									PrescribingNumberUnit: advice.PrescribingNumberUnit,
1189
+								}
1190
+								service.CreateDrugError(drugError)
1186 1191
 								c.ServeSuccessJSON(map[string]interface{}{
1187 1192
 									"msg":    "1",
1188 1193
 									"advice": advice,
@@ -1192,18 +1197,22 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1192 1197
 							}
1193 1198
 						}
1194 1199
 						if medical.IsUse != 1 {
1195
-							drugError := models.XtDrugError{
1196
-								UserOrgId:  adminInfo.Org.Id,
1197
-								DrugId:     item.DrugId,
1198
-								RecordDate: item.AdviceDate,
1199
-								PatientId:  item.PatientId,
1200
-								Remark:     "药品库存不足",
1201
-								Status:     1,
1202
-								Ctime:      time.Now().Unix(),
1203
-								Mtime:      0,
1204
-							}
1205
-							service.CreateDrugError(drugError)
1200
+
1206 1201
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
1202
+								drugError := models.XtDrugError{
1203
+									UserOrgId:             adminInfo.Org.Id,
1204
+									DrugId:                item.DrugId,
1205
+									RecordDate:            item.AdviceDate,
1206
+									PatientId:             item.PatientId,
1207
+									Remark:                "药品库存不足",
1208
+									Status:                1,
1209
+									Ctime:                 time.Now().Unix(),
1210
+									Mtime:                 0,
1211
+									SumCount:              list.Count*medical.MinNumber + list.StockMinNumber,
1212
+									Prescribingnumber:     advice.PrescribingNumber,
1213
+									PrescribingNumberUnit: advice.PrescribingNumberUnit,
1214
+								}
1215
+								service.CreateDrugError(drugError)
1207 1216
 								c.ServeSuccessJSON(map[string]interface{}{
1208 1217
 									"msg":    "3",
1209 1218
 									"advice": advice,
@@ -1213,14 +1222,17 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1213 1222
 							}
1214 1223
 							if prescribing_number_total > total {
1215 1224
 								drugError := models.XtDrugError{
1216
-									UserOrgId:  adminInfo.Org.Id,
1217
-									DrugId:     item.DrugId,
1218
-									RecordDate: item.AdviceDate,
1219
-									PatientId:  item.PatientId,
1220
-									Remark:     "出库数量大于库存",
1221
-									Status:     1,
1222
-									Ctime:      time.Now().Unix(),
1223
-									Mtime:      0,
1225
+									UserOrgId:             adminInfo.Org.Id,
1226
+									DrugId:                item.DrugId,
1227
+									RecordDate:            item.AdviceDate,
1228
+									PatientId:             item.PatientId,
1229
+									Remark:                "出库数量大于库存",
1230
+									Status:                1,
1231
+									Ctime:                 time.Now().Unix(),
1232
+									Mtime:                 0,
1233
+									SumCount:              list.Count*medical.MinNumber + list.StockMinNumber,
1234
+									Prescribingnumber:     advice.PrescribingNumber,
1235
+									PrescribingNumberUnit: advice.PrescribingNumberUnit,
1224 1236
 								}
1225 1237
 								service.CreateDrugError(drugError)
1226 1238
 								c.ServeSuccessJSON(map[string]interface{}{
@@ -3808,13 +3820,12 @@ func (c *PatientApiController) CreateGroupAdvice() {
3808 3820
 				}
3809 3821
 			}
3810 3822
 
3811
-			fmt.Println("admin==================", adminUserInfo.Org.Id)
3812 3823
 			//长沙南雅
3813 3824
 			if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
3814 3825
 
3815 3826
 				//查询该患者今日有没有双人核对
3816 3827
 				check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
3817
-				fmt.Println("check----------------", check)
3828
+
3818 3829
 				if check.ID > 0 {
3819 3830
 					advice.Checker = check.Modifier
3820 3831
 					advice.CheckState = 1

+ 12 - 9
models/drug_stock.go Ver fichero

@@ -711,15 +711,18 @@ func (DrugWarehouseOutInfoNight) TableName() string {
711 711
 }
712 712
 
713 713
 type XtDrugError struct {
714
-	ID         int64  `gorm:"column:id" json:"id" form:"id"`
715
-	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
716
-	DrugId     int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
717
-	RecordDate int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
718
-	PatientId  int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
719
-	Remark     string `gorm:"column:remark" json:"remark" form:"remark"`
720
-	Status     int64  `gorm:"column:status" json:"status" form:"status"`
721
-	Ctime      int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
722
-	Mtime      int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
714
+	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
715
+	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
716
+	DrugId                int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
717
+	RecordDate            int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
718
+	PatientId             int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
719
+	Remark                string  `gorm:"column:remark" json:"remark" form:"remark"`
720
+	Status                int64   `gorm:"column:status" json:"status" form:"status"`
721
+	Ctime                 int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
722
+	Mtime                 int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
723
+	Prescribingnumber     float64 `gorm:"column:prescribingnumber" json:"prescribingnumber" form:"prescribingnumber"`
724
+	PrescribingNumberUnit string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
725
+	SumCount              int64   `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
723 726
 }
724 727
 
725 728
 func (XtDrugError) TableName() string {

+ 1 - 0
models/his_models.go Ver fichero

@@ -261,6 +261,7 @@ type HisDoctorAdviceInfo struct {
261 261
 	ExecutionFrequencyId  int64                  `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
262 262
 	Child                 []*HisDoctorAdviceInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:DrugId" json:"child"`
263 263
 	IsSettle              int64                  `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
264
+	IsMobile              int64                  `gorm:"column:is_mobile" json:"is_mobile" form:"is_mobile"`
264 265
 }
265 266
 
266 267
 func (HisDoctorAdviceInfo) TableName() string {

+ 7 - 0
service/mobile_dialysis_service.go Ver fichero

@@ -7236,3 +7236,10 @@ func GetHisDoctorAdvicesTwentyOne(orgID int64, scheduleDate int64, deliverWay st
7236 7236
 
7237 7237
 	return vms, err
7238 7238
 }
7239
+
7240
+func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.XtPatientDryweight, err error) {
7241
+
7242
+	err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Find(&weight).Error
7243
+
7244
+	return weight, err
7245
+}

+ 371 - 37
service/new_warehouse_service.go Ver fichero

@@ -1261,6 +1261,20 @@ func BloodDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *
1261 1261
 // 药品自动出库 递归方式
1262 1262
 func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo) (err error) {
1263 1263
 
1264
+	drugError := models.XtDrugError{
1265
+		UserOrgId:             orgID,
1266
+		DrugId:                advice.DrugId,
1267
+		RecordDate:            advice.AdviceDate,
1268
+		PatientId:             advice.PatientId,
1269
+		Remark:                "进入出库页面",
1270
+		Status:                1,
1271
+		Ctime:                 time.Now().Unix(),
1272
+		Mtime:                 0,
1273
+		SumCount:              0,
1274
+		Prescribingnumber:     advice.PrescribingNumber,
1275
+		PrescribingNumberUnit: advice.PrescribingNumberUnit,
1276
+	}
1277
+	CreateDrugError(drugError)
1264 1278
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
1265 1279
 	var deliver_number int64 = 0
1266 1280
 	var stock_number int64 = 0
@@ -1306,28 +1320,39 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1306 1320
 	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
1307 1321
 
1308 1322
 	if err != nil {
1309
-
1323
+		drugError := models.XtDrugError{
1324
+			UserOrgId:             orgID,
1325
+			DrugId:                advice.DrugId,
1326
+			RecordDate:            advice.AdviceDate,
1327
+			PatientId:             advice.PatientId,
1328
+			Remark:                "查询库存报错",
1329
+			Status:                1,
1330
+			Ctime:                 time.Now().Unix(),
1331
+			Mtime:                 0,
1332
+			SumCount:              0,
1333
+			Prescribingnumber:     advice.PrescribingNumber,
1334
+			PrescribingNumberUnit: advice.PrescribingNumberUnit,
1335
+		}
1336
+		CreateDrugError(drugError)
1310 1337
 		return err
1311 1338
 	}
1312
-	// 将该批次的剩余库存数量转换为拆零数量
1339
+
1313 1340
 	// 将该批次的剩余库存数量转换为拆零数量
1314 1341
 	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
1315
-		//fmt.Println("进来1")
1342
+
1316 1343
 		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
1317
-		//fmt.Println("剩余库存1", stock_number)
1344
+
1318 1345
 	}
1319 1346
 	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
1320
-		//fmt.Println("进来2")
1347
+
1321 1348
 		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
1322
-		//fmt.Println("剩余库存2", stock_number)
1349
+
1323 1350
 	}
1324 1351
 	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
1325
-		//fmt.Println("进来3")
1352
+
1326 1353
 		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
1327
-		//fmt.Println("剩余库存3", stock_number)
1354
+
1328 1355
 	}
1329
-	//fmt.Println("剩余库存23333333333333333333333333333wo", stock_number)
1330
-	//fmt.Println("出库数量2333333333333333333333333333333333333wo", deliver_number)
1331 1356
 
1332 1357
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1333 1358
 	if stock_number >= deliver_number {
@@ -1367,10 +1392,6 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1367 1392
 
1368 1393
 		warehouse.Mtime = time.Now().Unix()
1369 1394
 
1370
-		fmt.Println("minnU目标而332322323323233223323223我", minNumber)
1371
-		fmt.Println("max_number232232332232322wo", maxNumber)
1372
-		fmt.Println(" warehouse.StockMinNumber", warehouse.StockMinNumber)
1373
-
1374 1395
 		if warehouse.StockMinNumber < minNumber {
1375 1396
 
1376 1397
 			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
@@ -1416,6 +1437,20 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1416 1437
 		//扣减库存数据
1417 1438
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
1418 1439
 		if errThree != nil {
1440
+			drugError := models.XtDrugError{
1441
+				UserOrgId:             orgID,
1442
+				DrugId:                advice.DrugId,
1443
+				RecordDate:            advice.AdviceDate,
1444
+				PatientId:             advice.PatientId,
1445
+				Remark:                "扣减库存失败",
1446
+				Status:                1,
1447
+				Ctime:                 time.Now().Unix(),
1448
+				Mtime:                 0,
1449
+				SumCount:              0,
1450
+				Prescribingnumber:     advice.PrescribingNumber,
1451
+				PrescribingNumberUnit: advice.PrescribingNumberUnit,
1452
+			}
1453
+			CreateDrugError(drugError)
1419 1454
 			return errThree
1420 1455
 		}
1421 1456
 
@@ -1464,6 +1499,20 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1464 1499
 		if lastDrugOutInfo.ID == 0 {
1465 1500
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1466 1501
 			if errOne != nil {
1502
+				drugError := models.XtDrugError{
1503
+					UserOrgId:             orgID,
1504
+					DrugId:                advice.DrugId,
1505
+					RecordDate:            advice.AdviceDate,
1506
+					PatientId:             advice.PatientId,
1507
+					Remark:                "创建出库单失败",
1508
+					Status:                1,
1509
+					Ctime:                 time.Now().Unix(),
1510
+					Mtime:                 0,
1511
+					SumCount:              0,
1512
+					Prescribingnumber:     advice.PrescribingNumber,
1513
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
1514
+				}
1515
+				CreateDrugError(drugError)
1467 1516
 				return errOne
1468 1517
 			}
1469 1518
 		}
@@ -1478,6 +1527,20 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1478 1527
 			if deliver_number != his_count {
1479 1528
 				errThree := UpdateSigleDrugWarehouseOutInfo(lastDrugOutInfo.ID, warehouseOutInfo)
1480 1529
 				if errThree != nil {
1530
+					drugError := models.XtDrugError{
1531
+						UserOrgId:             orgID,
1532
+						DrugId:                advice.DrugId,
1533
+						RecordDate:            advice.AdviceDate,
1534
+						PatientId:             advice.PatientId,
1535
+						Remark:                "更新出库单失败",
1536
+						Status:                1,
1537
+						Ctime:                 time.Now().Unix(),
1538
+						Mtime:                 0,
1539
+						SumCount:              0,
1540
+						Prescribingnumber:     advice.PrescribingNumber,
1541
+						PrescribingNumberUnit: advice.PrescribingNumberUnit,
1542
+					}
1543
+					CreateDrugError(drugError)
1481 1544
 					return errThree
1482 1545
 				}
1483 1546
 			}
@@ -1497,12 +1560,6 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1497 1560
 			cancel_count += item.Count
1498 1561
 		}
1499 1562
 
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)
1506 1563
 		//如果本次出库数据大于历史出库数据 新增1条流水
1507 1564
 		if deliver_number >= (out_count - cancel_count) {
1508 1565
 			drugflow := models.DrugFlow{
@@ -1536,9 +1593,43 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1536 1593
 				LastPrice:               warehouse.Price,
1537 1594
 			}
1538 1595
 
1539
-			CreateDrugFlowOne(drugflow)
1596
+			errThreeTy := CreateDrugFlowOne(drugflow)
1597
+
1598
+			if errThreeTy != nil {
1599
+				drugError := models.XtDrugError{
1600
+					UserOrgId:             orgID,
1601
+					DrugId:                advice.DrugId,
1602
+					RecordDate:            advice.AdviceDate,
1603
+					PatientId:             advice.PatientId,
1604
+					Remark:                "创建流水失败",
1605
+					Status:                1,
1606
+					Ctime:                 time.Now().Unix(),
1607
+					Mtime:                 0,
1608
+					SumCount:              0,
1609
+					Prescribingnumber:     advice.PrescribingNumber,
1610
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
1611
+				}
1612
+				CreateDrugError(drugError)
1613
+			}
1540 1614
 			//出库数量相加
1541
-			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
1615
+			errThreeTys := AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
1616
+
1617
+			if errThreeTys != nil {
1618
+				drugError := models.XtDrugError{
1619
+					UserOrgId:             orgID,
1620
+					DrugId:                advice.DrugId,
1621
+					RecordDate:            advice.AdviceDate,
1622
+					PatientId:             advice.PatientId,
1623
+					Remark:                "出库数量相加失败",
1624
+					Status:                1,
1625
+					Ctime:                 time.Now().Unix(),
1626
+					Mtime:                 0,
1627
+					SumCount:              0,
1628
+					Prescribingnumber:     advice.PrescribingNumber,
1629
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
1630
+				}
1631
+				CreateDrugError(drugError)
1632
+			}
1542 1633
 
1543 1634
 		}
1544 1635
 
@@ -1570,7 +1661,23 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1570 1661
 
1571 1662
 			_, errCode := FindDrugCancelStock(advice.AdviceDate, advice.UserOrgId)
1572 1663
 			if errCode == gorm.ErrRecordNotFound {
1573
-				AddSigleDrugCancelStock(&cancelStock)
1664
+				errCode := AddSigleDrugCancelStock(&cancelStock)
1665
+				if errCode != nil {
1666
+					drugError := models.XtDrugError{
1667
+						UserOrgId:             orgID,
1668
+						DrugId:                advice.DrugId,
1669
+						RecordDate:            advice.AdviceDate,
1670
+						PatientId:             advice.PatientId,
1671
+						Remark:                "创建退库单失败",
1672
+						Status:                1,
1673
+						Ctime:                 time.Now().Unix(),
1674
+						Mtime:                 0,
1675
+						SumCount:              0,
1676
+						Prescribingnumber:     advice.PrescribingNumber,
1677
+						PrescribingNumberUnit: advice.PrescribingNumberUnit,
1678
+					}
1679
+					CreateDrugError(drugError)
1680
+				}
1574 1681
 			}
1575 1682
 			lastDrugCancelStock, _ := FindLastDrugCancelStock(advice.AdviceDate, advice.UserOrgId)
1576 1683
 
@@ -1602,7 +1709,23 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1602 1709
 				StorehouseId:     storeConfig.DrugStorehouseOut,
1603 1710
 				IsCheck:          1,
1604 1711
 			}
1605
-			CreatedCancelStock(cancelStockInfo)
1712
+			errCodes := CreatedCancelStock(cancelStockInfo)
1713
+			if errCodes != nil {
1714
+				drugError := models.XtDrugError{
1715
+					UserOrgId:             orgID,
1716
+					DrugId:                advice.DrugId,
1717
+					RecordDate:            advice.AdviceDate,
1718
+					PatientId:             advice.PatientId,
1719
+					Remark:                "创建退库单失败",
1720
+					Status:                1,
1721
+					Ctime:                 time.Now().Unix(),
1722
+					Mtime:                 0,
1723
+					SumCount:              0,
1724
+					Prescribingnumber:     advice.PrescribingNumber,
1725
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
1726
+				}
1727
+				CreateDrugError(drugError)
1728
+			}
1606 1729
 			flow := models.DrugFlow{
1607 1730
 				WarehousingId:           warehouse.ID,
1608 1731
 				DrugId:                  warehouse.DrugId,
@@ -1640,9 +1763,57 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1640 1763
 				LastPrice:               warehouse.Price,
1641 1764
 				OverCount:               sum_count,
1642 1765
 			}
1643
-			CreateDrugFlowOne(flow)
1644
-			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
1645
-			ReduceDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count)
1766
+			errCodeflow := CreateDrugFlowOne(flow)
1767
+			if errCodeflow != nil {
1768
+				drugError := models.XtDrugError{
1769
+					UserOrgId:             orgID,
1770
+					DrugId:                advice.DrugId,
1771
+					RecordDate:            advice.AdviceDate,
1772
+					PatientId:             advice.PatientId,
1773
+					Remark:                "退库流水创建失败",
1774
+					Status:                1,
1775
+					Ctime:                 time.Now().Unix(),
1776
+					Mtime:                 0,
1777
+					SumCount:              0,
1778
+					Prescribingnumber:     advice.PrescribingNumber,
1779
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
1780
+				}
1781
+				CreateDrugError(drugError)
1782
+			}
1783
+			errCodesum := AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
1784
+			if errCodesum != nil {
1785
+				drugError := models.XtDrugError{
1786
+					UserOrgId:             orgID,
1787
+					DrugId:                advice.DrugId,
1788
+					RecordDate:            advice.AdviceDate,
1789
+					PatientId:             advice.PatientId,
1790
+					Remark:                "增加退库数量失败",
1791
+					Status:                1,
1792
+					Ctime:                 time.Now().Unix(),
1793
+					Mtime:                 0,
1794
+					SumCount:              0,
1795
+					Prescribingnumber:     advice.PrescribingNumber,
1796
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
1797
+				}
1798
+				CreateDrugError(drugError)
1799
+			}
1800
+			errCodereduce := ReduceDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count)
1801
+			if errCodereduce != nil {
1802
+				drugError := models.XtDrugError{
1803
+					UserOrgId:             orgID,
1804
+					DrugId:                advice.DrugId,
1805
+					RecordDate:            advice.AdviceDate,
1806
+					PatientId:             advice.PatientId,
1807
+					Remark:                "减少出库数量失败",
1808
+					Status:                1,
1809
+					Ctime:                 time.Now().Unix(),
1810
+					Mtime:                 0,
1811
+					SumCount:              0,
1812
+					Prescribingnumber:     advice.PrescribingNumber,
1813
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
1814
+				}
1815
+				CreateDrugError(drugError)
1816
+			}
1646 1817
 		}
1647 1818
 
1648 1819
 		//查询是否存在数据
@@ -1664,6 +1835,20 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1664 1835
 		}
1665 1836
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
1666 1837
 		if errTwo != nil {
1838
+			drugError := models.XtDrugError{
1839
+				UserOrgId:             orgID,
1840
+				DrugId:                advice.DrugId,
1841
+				RecordDate:            advice.AdviceDate,
1842
+				PatientId:             advice.PatientId,
1843
+				Remark:                "新增自动出库表失败",
1844
+				Status:                1,
1845
+				Ctime:                 time.Now().Unix(),
1846
+				Mtime:                 0,
1847
+				SumCount:              0,
1848
+				Prescribingnumber:     advice.PrescribingNumber,
1849
+				PrescribingNumberUnit: advice.PrescribingNumberUnit,
1850
+			}
1851
+			CreateDrugError(drugError)
1667 1852
 			return errTwo
1668 1853
 		}
1669 1854
 		return nil
@@ -1705,6 +1890,20 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1705 1890
 		errThree := UpDateDrugWarehouseInfoByStock(&info)
1706 1891
 
1707 1892
 		if errThree != nil {
1893
+			drugError := models.XtDrugError{
1894
+				UserOrgId:             orgID,
1895
+				DrugId:                advice.DrugId,
1896
+				RecordDate:            advice.AdviceDate,
1897
+				PatientId:             advice.PatientId,
1898
+				Remark:                "第二批次扣减库存失败",
1899
+				Status:                1,
1900
+				Ctime:                 time.Now().Unix(),
1901
+				Mtime:                 0,
1902
+				SumCount:              0,
1903
+				Prescribingnumber:     advice.PrescribingNumber,
1904
+				PrescribingNumberUnit: advice.PrescribingNumberUnit,
1905
+			}
1906
+			CreateDrugError(drugError)
1708 1907
 			return errThree
1709 1908
 		}
1710 1909
 		//查询剩余库存
@@ -1749,9 +1948,22 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1749 1948
 		//查询是否存在出库数据
1750 1949
 		_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
1751 1950
 		if errCode == gorm.ErrRecordNotFound {
1752
-			fmt.Println("j你俩3233223323232323233wo")
1753 1951
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1754 1952
 			if errOne != nil {
1953
+				drugError := models.XtDrugError{
1954
+					UserOrgId:             orgID,
1955
+					DrugId:                advice.DrugId,
1956
+					RecordDate:            advice.AdviceDate,
1957
+					PatientId:             advice.PatientId,
1958
+					Remark:                "创建出库表失败",
1959
+					Status:                1,
1960
+					Ctime:                 time.Now().Unix(),
1961
+					Mtime:                 0,
1962
+					SumCount:              0,
1963
+					Prescribingnumber:     advice.PrescribingNumber,
1964
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
1965
+				}
1966
+				CreateDrugError(drugError)
1755 1967
 				return errOne
1756 1968
 			}
1757 1969
 		}
@@ -1768,6 +1980,20 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1768 1980
 			if deliver_number != his_count {
1769 1981
 				errThree := UpdateSingleDrugWarehouseOutInfoSix(advice.PatientId, advice.AdviceDate, orgID, warehouseOutInfo, advice.ID)
1770 1982
 				if errThree != nil {
1983
+					drugError := models.XtDrugError{
1984
+						UserOrgId:             orgID,
1985
+						DrugId:                advice.DrugId,
1986
+						RecordDate:            advice.AdviceDate,
1987
+						PatientId:             advice.PatientId,
1988
+						Remark:                "更新出库表失败",
1989
+						Status:                1,
1990
+						Ctime:                 time.Now().Unix(),
1991
+						Mtime:                 0,
1992
+						SumCount:              0,
1993
+						Prescribingnumber:     advice.PrescribingNumber,
1994
+						PrescribingNumberUnit: advice.PrescribingNumberUnit,
1995
+					}
1996
+					CreateDrugError(drugError)
1771 1997
 					return errThree
1772 1998
 				}
1773 1999
 			}
@@ -1795,11 +2021,42 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1795 2021
 		if errcodeThree == gorm.ErrRecordNotFound {
1796 2022
 			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
1797 2023
 			if errTwo != nil {
2024
+				drugError := models.XtDrugError{
2025
+					UserOrgId:             orgID,
2026
+					DrugId:                advice.DrugId,
2027
+					RecordDate:            advice.AdviceDate,
2028
+					PatientId:             advice.PatientId,
2029
+					Remark:                "第二批次新增自动出库表失败",
2030
+					Status:                1,
2031
+					Ctime:                 time.Now().Unix(),
2032
+					Mtime:                 0,
2033
+					SumCount:              0,
2034
+					Prescribingnumber:     advice.PrescribingNumber,
2035
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
2036
+				}
2037
+				CreateDrugError(drugError)
1798 2038
 				return errTwo
1799 2039
 			}
1800 2040
 		}
1801 2041
 		if errcodeThree == nil {
1802
-			UpdateDrugAutoReduceRecordInfo(advice.PatientId, advice.RecordDate, advice.DrugId, details)
2042
+			errThreeauto := UpdateDrugAutoReduceRecordInfo(advice.PatientId, advice.RecordDate, advice.DrugId, details)
2043
+			if errThreeauto != nil {
2044
+				drugError := models.XtDrugError{
2045
+					UserOrgId:             orgID,
2046
+					DrugId:                advice.DrugId,
2047
+					RecordDate:            advice.AdviceDate,
2048
+					PatientId:             advice.PatientId,
2049
+					Remark:                "第二批次更新自动出库表失败",
2050
+					Status:                1,
2051
+					Ctime:                 time.Now().Unix(),
2052
+					Mtime:                 0,
2053
+					SumCount:              0,
2054
+					Prescribingnumber:     advice.PrescribingNumber,
2055
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
2056
+				}
2057
+				CreateDrugError(drugError)
2058
+			}
2059
+
1803 2060
 		}
1804 2061
 
1805 2062
 		var out_count int64
@@ -1855,9 +2112,6 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1855 2112
 			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
1856 2113
 		}
1857 2114
 
1858
-		fmt.Println("libai", out_count)
1859
-		fmt.Println("cancel", cancel_count)
1860
-		fmt.Println("deliver_number", deliver_number)
1861 2115
 		if deliver_number < (out_count - cancel_count) {
1862 2116
 			operation_time := time.Now().Unix()
1863 2117
 
@@ -1884,7 +2138,23 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1884 2138
 
1885 2139
 			_, errCode := FindDrugCancelStock(advice.AdviceDate, advice.UserOrgId)
1886 2140
 			if errCode == gorm.ErrRecordNotFound {
1887
-				AddSigleDrugCancelStock(&cancelStock)
2141
+				errCodeCancel := AddSigleDrugCancelStock(&cancelStock)
2142
+				if errCodeCancel != nil {
2143
+					drugError := models.XtDrugError{
2144
+						UserOrgId:             orgID,
2145
+						DrugId:                advice.DrugId,
2146
+						RecordDate:            advice.AdviceDate,
2147
+						PatientId:             advice.PatientId,
2148
+						Remark:                "第二批次新增流水表失败",
2149
+						Status:                1,
2150
+						Ctime:                 time.Now().Unix(),
2151
+						Mtime:                 0,
2152
+						SumCount:              0,
2153
+						Prescribingnumber:     advice.PrescribingNumber,
2154
+						PrescribingNumberUnit: advice.PrescribingNumberUnit,
2155
+					}
2156
+					CreateDrugError(drugError)
2157
+				}
1888 2158
 			}
1889 2159
 			lastDrugCancelStock, _ := FindLastDrugCancelStock(advice.AdviceDate, advice.UserOrgId)
1890 2160
 
@@ -1916,7 +2186,23 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1916 2186
 				StorehouseId:     storeConfig.DrugStorehouseOut,
1917 2187
 				IsCheck:          1,
1918 2188
 			}
1919
-			CreatedCancelStock(cancelStockInfo)
2189
+			errCodeCancel := CreatedCancelStock(cancelStockInfo)
2190
+			if errCodeCancel != nil {
2191
+				drugError := models.XtDrugError{
2192
+					UserOrgId:             orgID,
2193
+					DrugId:                advice.DrugId,
2194
+					RecordDate:            advice.AdviceDate,
2195
+					PatientId:             advice.PatientId,
2196
+					Remark:                "第二批次创建自动退库表失败",
2197
+					Status:                1,
2198
+					Ctime:                 time.Now().Unix(),
2199
+					Mtime:                 0,
2200
+					SumCount:              0,
2201
+					Prescribingnumber:     advice.PrescribingNumber,
2202
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
2203
+				}
2204
+				CreateDrugError(drugError)
2205
+			}
1920 2206
 			flow := models.DrugFlow{
1921 2207
 				WarehousingId:           warehouse.ID,
1922 2208
 				DrugId:                  warehouse.DrugId,
@@ -1954,11 +2240,59 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1954 2240
 				LastPrice:               warehouse.Price,
1955 2241
 				OverCount:               sum_count,
1956 2242
 			}
1957
-			CreateDrugFlowOne(flow)
2243
+			errCodeFlows := CreateDrugFlowOne(flow)
2244
+			if errCodeFlows != nil {
2245
+				drugError := models.XtDrugError{
2246
+					UserOrgId:             orgID,
2247
+					DrugId:                advice.DrugId,
2248
+					RecordDate:            advice.AdviceDate,
2249
+					PatientId:             advice.PatientId,
2250
+					Remark:                "第二批次创建自动退库流水表失败",
2251
+					Status:                1,
2252
+					Ctime:                 time.Now().Unix(),
2253
+					Mtime:                 0,
2254
+					SumCount:              0,
2255
+					Prescribingnumber:     advice.PrescribingNumber,
2256
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
2257
+				}
2258
+				CreateDrugError(drugError)
2259
+			}
1958 2260
 
1959 2261
 			//退库数量增加
1960
-			AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
1961
-			ReduceDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count)
2262
+			errCodeFlows = AddCancelSumCountOne(storeConfig.DrugStorehouseOut, advice.DrugId, advice.UserOrgId, flow.Count)
2263
+			if errCodeFlows != nil {
2264
+				drugError := models.XtDrugError{
2265
+					UserOrgId:             orgID,
2266
+					DrugId:                advice.DrugId,
2267
+					RecordDate:            advice.AdviceDate,
2268
+					PatientId:             advice.PatientId,
2269
+					Remark:                "第二批次创建自动退库流水表失败",
2270
+					Status:                1,
2271
+					Ctime:                 time.Now().Unix(),
2272
+					Mtime:                 0,
2273
+					SumCount:              0,
2274
+					Prescribingnumber:     advice.PrescribingNumber,
2275
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
2276
+				}
2277
+				CreateDrugError(drugError)
2278
+			}
2279
+			errCodereduce := ReduceDrugCountTwo(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, flow.Count)
2280
+			if errCodereduce != nil {
2281
+				drugError := models.XtDrugError{
2282
+					UserOrgId:             orgID,
2283
+					DrugId:                advice.DrugId,
2284
+					RecordDate:            advice.AdviceDate,
2285
+					PatientId:             advice.PatientId,
2286
+					Remark:                "第二批次减少库存表失败",
2287
+					Status:                1,
2288
+					Ctime:                 time.Now().Unix(),
2289
+					Mtime:                 0,
2290
+					SumCount:              0,
2291
+					Prescribingnumber:     advice.PrescribingNumber,
2292
+					PrescribingNumberUnit: advice.PrescribingNumberUnit,
2293
+				}
2294
+				CreateDrugError(drugError)
2295
+			}
1962 2296
 		}
1963 2297
 
1964 2298
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作

+ 2 - 0
service/warhouse_service.go Ver fichero

@@ -483,6 +483,7 @@ func HisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdvice
483 483
 	// 2.判断当天当前机构有没有创建出库单,没有则创建
484 484
 	// 3.创建出库流程
485 485
 	// 3.1 实现先进先出逻辑 由于药品执行后,不可以修改和删除,所以不考虑出库后的退库和修改出库数量等
486
+
486 487
 	isHasWay := false
487 488
 	record_time := int64(0)
488 489
 	isHasWay = true
@@ -491,6 +492,7 @@ func HisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdvice
491 492
 	if isHasWay {
492 493
 		//判断当天当前机构有没有创建出库单,没有则创建
493 494
 		out, err := FindDrugStockOutByIsSys(orgID, 1, record_time)
495
+
494 496
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
495 497
 		if err == gorm.ErrRecordNotFound {
496 498
 			timeStr := time.Now().Format("2006-01-02")