浏览代码

11月8日库存管理

XMLWAN 3 年前
父节点
当前提交
f15cf6d2c5

文件差异内容过多而无法显示
+ 633 - 468
controllers/his_api_controller.go


+ 2 - 1
controllers/manager_center_api_controller.go 查看文件

@@ -1682,8 +1682,9 @@ func (c *ManagerCenterApiController) GetGoodInfoList() {
1682 1682
 	good_kind, _ := c.GetInt64("good_kind")
1683 1683
 	is_mark, _ := c.GetInt64("is_mark")
1684 1684
 	manufacturer, _ := c.GetInt64("manufacturer")
1685
+	is_type, _ := c.GetInt64("is_type")
1685 1686
 	adminUserInfo := c.GetAdminUserInfo()
1686
-	goodInfos, total, err := service.FindGoodInfoList(adminUserInfo.CurrentOrgId, page, limit, keyword, is_use, is_charge, good_kind, is_mark, manufacturer)
1687
+	goodInfos, total, err := service.FindGoodInfoList(adminUserInfo.CurrentOrgId, page, limit, keyword, is_use, is_charge, good_kind, is_mark, manufacturer, is_type)
1687 1688
 	if err == nil {
1688 1689
 		c.ServeSuccessJSON(map[string]interface{}{
1689 1690
 			"list":  goodInfos,

+ 2 - 0
models/stock_models.go 查看文件

@@ -595,6 +595,8 @@ type CancelStockInfo struct {
595 595
 	WarehouseInfoId int64              `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
596 596
 	GoodInfo        GoodInfo           `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
597 597
 	WarehousingInfo []*WarehousingInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"xt_warehouse_info"`
598
+	PatientId       int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
599
+	RecordDate      int64              `gorm:"column:record_date" json:"record_date" form:"record_date"`
598 600
 }
599 601
 
600 602
 func (CancelStockInfo) TableName() string {

+ 6 - 6
service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go 查看文件

@@ -554,12 +554,11 @@ func (MonitoringRecordVM) TableName() string {
554 554
 }
555 555
 
556 556
 type ScheduleVM struct {
557
-	ID           int64 `gorm:"column:id" json:"id"`
558
-	PatientID    int64 `gorm:"column:patient_id" json:"patient_id"`
559
-	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
560
-	BedID        int64 `gorm:"column:bed_id" json:"bed_id"`
561
-	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
562
-
557
+	ID                       int64                            `gorm:"column:id" json:"id"`
558
+	PatientID                int64                            `gorm:"column:patient_id" json:"patient_id"`
559
+	ScheduleDate             int64                            `gorm:"column:schedule_date" json:"schedule_date"`
560
+	BedID                    int64                            `gorm:"column:bed_id" json:"bed_id"`
561
+	PartitionId              int64                            `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
563 562
 	Patient                  *PatientVM                       `gorm:"ForeignKey:PatientID" json:"patient"`
564 563
 	DialysisOrder            DialysisOrderVM                  `gorm:"ForeignKey:DialysisDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"dialysis_order"`
565 564
 	Prescription             PrescriptionVM                   `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"prescription"`
@@ -576,6 +575,7 @@ type ScheduleVM struct {
576 575
 	LastAfterWeight          XtAssessmentAfterDislysisVM      `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
577 576
 	HisAdvices               []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"his_advices"`
578 577
 	HisPrescriptionProject   []*models.HisPrescriptionProject `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"his_project"`
578
+	Count                    int
579 579
 }
580 580
 
581 581
 func (ScheduleVM) TableName() string {

+ 6 - 1
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go 查看文件

@@ -59,7 +59,7 @@ func GetSchedules(orgID int64, schIDs []string) ([]*ScheduleVM, error) {
59 59
 	for _, item := range schedules {
60 60
 
61 61
 		if orgID != 10101 {
62
-			dialysis_count, _ := GetDialysisOrderCount(orgID, item.PatientID, item.ScheduleDate)
62
+			dialysis_count, _ := GetDialysisOrderCountOne(orgID, item.PatientID, item.ScheduleDate)
63 63
 			item.Patient.TotalDialysis = dialysis_count
64 64
 		}
65 65
 		if orgID == 10101 {
@@ -207,6 +207,11 @@ func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (cou
207 207
 	return
208 208
 }
209 209
 
210
+//func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64)(order []*models.DialysisOrder,err error) {
211
+// err = p_service.XTReadDB().Where("dialysis_date <= ? AND status = 1 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Find(&order).Error
212
+// return order,err
213
+//}
214
+
210 215
 func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
211 216
 	err = p_service.XTReadDB().Model(&models.DialysisOrder{}).Where("dialysis_date >=1640966400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
212 217
 	return

+ 35 - 9
service/stock_service.go 查看文件

@@ -259,7 +259,7 @@ func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
259 259
 
260 260
 }
261 261
 
262
-func FindGoodInfoList(orgId int64, page int64, limit int64, keyword string, is_use int64, is_charge int64, good_kind int64, is_mark int64, manufacturer int64) (list []*models.GoodInfo, total int64, err error) {
262
+func FindGoodInfoList(orgId int64, page int64, limit int64, keyword string, is_use int64, is_charge int64, good_kind int64, is_mark int64, manufacturer int64, is_type int64) (list []*models.GoodInfo, total int64, err error) {
263 263
 	offset := (page - 1) * limit
264 264
 	db := readDb.Model(&models.GoodInfo{})
265 265
 	db = db.Where("org_id = ? AND status = 1", orgId)
@@ -291,6 +291,9 @@ func FindGoodInfoList(orgId int64, page int64, limit int64, keyword string, is_u
291 291
 		if manufacturer > 0 {
292 292
 			db = db.Where("manufacturer = ?", manufacturer)
293 293
 		}
294
+		if is_type > 0 {
295
+			db = db.Where("good_type_id = ?", is_type)
296
+		}
294 297
 	} else {
295 298
 		if is_use > 0 {
296 299
 			if is_use == 1 {
@@ -316,6 +319,9 @@ func FindGoodInfoList(orgId int64, page int64, limit int64, keyword string, is_u
316 319
 		if manufacturer > 0 {
317 320
 			db = db.Where("manufacturer = ?", manufacturer)
318 321
 		}
322
+		if is_type > 0 {
323
+			db = db.Where("good_type_id = ?", is_type)
324
+		}
319 325
 	}
320 326
 
321 327
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
@@ -3483,6 +3489,12 @@ func DeleteAutoRedeceDetailTwo(orgid int64, patient_id int64, recordtime int64,
3483 3489
 	return err
3484 3490
 }
3485 3491
 
3492
+func GetWarehosueOutByStockFlow(patient_id int64, recrod_date int64, goodid int64) (stockflow []*models.VmStockFlow, err error) {
3493
+
3494
+	err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and consumable_type = 3 and status = 1", patient_id, recrod_date, goodid).Find(&stockflow).Error
3495
+	return stockflow, err
3496
+}
3497
+
3486 3498
 func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64) error {
3487 3499
 
3488 3500
 	detail := models.BloodAutomaticReduceDetail{}
@@ -3491,15 +3503,30 @@ func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64,
3491 3503
 	err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3492 3504
 	prepare := models.DialysisBeforePrepare{}
3493 3505
 	err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3506
+	flow := models.VmStockFlow{}
3507
+	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3494 3508
 	return err
3495 3509
 
3496 3510
 }
3497 3511
 
3498 3512
 func UpDateWarehouseInfoByStockDelete(id int64, count int64) (err error) {
3513
+
3499 3514
 	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
3500 3515
 	return err
3501 3516
 }
3502 3517
 
3518
+func GetCancelStockInfoByPatientId(patientid int64, goodid int64, record_date int64) (info []*models.CancelStockInfo, err error) {
3519
+
3520
+	err = XTReadDB().Where("patient_id = ? and good_id = ? and record_date = ? and status = 1", patientid, goodid, record_date).Find(&info).Error
3521
+	return info, err
3522
+}
3523
+
3524
+func GetHisPrepscritionByPatientId(patientid int64, goodid int64, record_date int64) (list []*models.HisPrescriptionProject, err error) {
3525
+
3526
+	err = XTReadDB().Where("patient_id = ? and project_id = ? and record_date = ? and status = 1", patientid, goodid, record_date).Find(&list).Error
3527
+	return list, err
3528
+}
3529
+
3503 3530
 func UpDateWarehouStockFlowByStockDelete(id int64, recordtime int64, good_id int64, count int64, patient_id int64) (err error) {
3504 3531
 
3505 3532
 	err = writeDb.Model(&models.VmStockFlow{}).Where("warehousing_id = ? and system_time = ? and good_id = ? and patient_id = ?", id, recordtime, good_id, patient_id).UpdateColumn("count", gorm.Expr("count - ?", count)).Error
@@ -3525,15 +3552,14 @@ func GetAutoDialysisBefor(goodid int64, goodtypeid int64, patientid int64, orgid
3525 3552
 	return &autoreduece, nil
3526 3553
 }
3527 3554
 
3528
-func GetAutoRecordByGoodId(goodid int64, patientid int64, recorddate int64) (models.WarehouseOutInfo, error) {
3529
-	detail := models.WarehouseOutInfo{}
3530
-	err := XTReadDB().Model(&detail).Where("good_id = ? and patient_id = ? and sys_record_time = ? and status = 1", goodid, patientid, recorddate).Find(&detail).Error
3555
+func GetAutoRecordByGoodIdSeven(goodid int64, patientid int64, recorddate int64) (models.WarehouseOutInfoSeven, error) {
3556
+	detail := models.WarehouseOutInfoSeven{}
3557
+	err := XTReadDB().Select("id,count").Where(" good_id = ? and sys_record_time = ?  and patient_id = ?  and status = 1", goodid, recorddate, patientid).Find(&detail).Error
3531 3558
 	return detail, err
3532 3559
 }
3533 3560
 
3534
-func GetAutoRecordByGoodIdSeven(goodid int64, patientid int64, recorddate int64) (models.WarehouseOutInfoSeven, error) {
3535
-	detail := models.WarehouseOutInfoSeven{}
3536
-	err := XTReadDB().Model(&detail).Where("sys_record_time = ? and good_id = ? and patient_id = ?  and status = 1", recorddate, goodid, patientid).Find(&detail).Error
3561
+func GetAutoRecordByGoodIdSevenEight(goodid int64, patientid int64, recorddate int64) (detail []*models.WarehouseOutInfoSeven, err error) {
3562
+	err = XTReadDB().Select("id,count").Where("good_id = ? and sys_record_time = ?  and patient_id = ?  and status = 1", goodid, recorddate, patientid).Find(&detail).Error
3537 3563
 	return detail, err
3538 3564
 }
3539 3565
 
@@ -4706,9 +4732,9 @@ func GetHisAdviceListByDrugIdEight(drugid int64, patient_id int64, advice_date i
4706 4732
 	return info, err
4707 4733
 }
4708 4734
 
4709
-func GetLastDrugWarehouseOutByDrugId(drugid int64, patient_id int64, advice_date int64) (models.DrugAutomaticReduceDetail, error) {
4735
+func GetLastDrugWarehouseOutByDrugId(drugid int64, patient_id int64, advice_date int64, advice_id int64) (models.DrugAutomaticReduceDetail, error) {
4710 4736
 	detail := models.DrugAutomaticReduceDetail{}
4711
-	err := XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1", drugid, patient_id, advice_date).Last(&detail).Error
4737
+	err := XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, advice_date, advice_id).Last(&detail).Error
4712 4738
 	return detail, err
4713 4739
 }
4714 4740
 

+ 30 - 2
service/warhouse_service.go 查看文件

@@ -582,6 +582,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
582 582
 
583 583
 		maxNumber = deliver_number / drup.MinNumber
584 584
 		minNumber = deliver_number % drup.MinNumber
585
+
585 586
 		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
586 587
 			minNumber = maxNumber
587 588
 		}
@@ -591,8 +592,9 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
591 592
 				return errors.New("库存数量不足")
592 593
 			}
593 594
 		}
594
-
595
-		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
595
+		if minNumber != 0 {
596
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
597
+		}
596 598
 
597 599
 		if warehouse.StockMaxNumber < 0 {
598 600
 			warehouse.StockMaxNumber = 0
@@ -602,19 +604,31 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
602 604
 		}
603 605
 
604 606
 		warehouse.Mtime = time.Now().Unix()
607
+		fmt.Println("w23332233232232332", warehouse.StockMinNumber, minNumber)
605 608
 
606 609
 		if warehouse.StockMinNumber < minNumber {
610
+			fmt.Println("进来的风3232332322323")
607 611
 			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
608 612
 			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
609 613
 		} else {
614
+			fmt.Println("进3232332322323")
610 615
 			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
611 616
 		}
612 617
 
618
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
619
+			fmt.Println("2223232332322323", warehouse.StockMinNumber)
620
+			warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
621
+
622
+		}
623
+
613 624
 		if drup.MaxUnit != drup.MinUnit {
614 625
 			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
615 626
 				return errors.New("库存数量不足")
616 627
 			}
617 628
 		}
629
+		if warehouse.StockMinNumber <= 0 {
630
+			warehouse.StockMinNumber = 0
631
+		}
618 632
 
619 633
 		//扣减库存232332332332
620 634
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
@@ -1064,6 +1078,7 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1064 1078
 //耗材出库
1065 1079
 func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
1066 1080
 
1081
+	fmt.Println("count23323223233232323232332232323", count, goods.Count)
1067 1082
 	var deliver_number int64 = 0
1068 1083
 	var stock_number int64 = 0
1069 1084
 	var maxNumber int64 = 0
@@ -1977,6 +1992,7 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
1977 1992
 			PatientId:               advice.PatientId,
1978 1993
 			Count:                   deliver_number, //出最小单位
1979 1994
 			WarehouseInfoId:         warehouse.ID,
1995
+			AdviceId:                advice.ID,
1980 1996
 		}
1981 1997
 
1982 1998
 		drugflow := models.DrugFlow{
@@ -2001,6 +2017,7 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
2001 2017
 			IsSys:                   1,
2002 2018
 			PatientId:               advice.PatientId,
2003 2019
 			WarehousingDetailId:     warehouse.ID,
2020
+			AdviceId:                advice.ID,
2004 2021
 		}
2005 2022
 
2006 2023
 		CreateDrugFlowOne(drugflow)
@@ -2100,6 +2117,7 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
2100 2117
 			PatientId:               advice.PatientId,
2101 2118
 			Count:                   deliver_number,
2102 2119
 			WarehouseInfoId:         warehouse.ID,
2120
+			AdviceId:                advice.ID,
2103 2121
 		}
2104 2122
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2105 2123
 		if errOne != nil {
@@ -2197,6 +2215,7 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
2197 2215
 			IsSys:                   1,
2198 2216
 			PatientId:               advice.PatientId,
2199 2217
 			WarehousingDetailId:     warehouse.ID,
2218
+			AdviceId:                advice.ID,
2200 2219
 		}
2201 2220
 
2202 2221
 		CreateDrugFlowOne(drugflow)
@@ -2281,6 +2300,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2281 2300
 			PatientId:               advice.PatientId,
2282 2301
 			WarehouseInfoId:         warehouse.ID,
2283 2302
 			Count:                   deliver_number,
2303
+			AdviceId:                advice.ID,
2284 2304
 		}
2285 2305
 
2286 2306
 		drugflow := models.DrugFlow{
@@ -2306,6 +2326,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2306 2326
 			PatientId:               advice.PatientId,
2307 2327
 			SystemTime:              advice.RecordDate,
2308 2328
 			WarehousingDetailId:     warehouse.ID,
2329
+			AdviceId:                advice.ID,
2309 2330
 		}
2310 2331
 
2311 2332
 		CreateDrugFlowOne(drugflow)
@@ -2327,6 +2348,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2327 2348
 			Count:                   deliver_number,
2328 2349
 			CountUnit:               drup.MinUnit,
2329 2350
 			WarehouseInfoId:         warehouse.ID,
2351
+			AdviceId:                advice.ID,
2330 2352
 		}
2331 2353
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
2332 2354
 		if errTwo != nil {
@@ -2362,6 +2384,9 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2362 2384
 		if warehouse.StockMaxNumber < 0 {
2363 2385
 			return errors.New("库存数量不足")
2364 2386
 		}
2387
+		if warehouse.StockMinNumber <= 0 {
2388
+			warehouse.StockMinNumber = 0
2389
+		}
2365 2390
 
2366 2391
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
2367 2392
 
@@ -2395,6 +2420,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2395 2420
 			WarehouseInfoId:         warehouse.ID,
2396 2421
 			Count:                   deliver_number,
2397 2422
 			CountUnit:               drup.MinUnit,
2423
+			AdviceId:                advice.ID,
2398 2424
 		}
2399 2425
 
2400 2426
 		drugflow := models.DrugFlow{
@@ -2420,6 +2446,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2420 2446
 			PatientId:               advice.PatientId,
2421 2447
 			SystemTime:              advice.RecordDate,
2422 2448
 			WarehousingDetailId:     warehouse.ID,
2449
+			AdviceId:                advice.ID,
2423 2450
 		}
2424 2451
 
2425 2452
 		CreateDrugFlowOne(drugflow)
@@ -2441,6 +2468,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2441 2468
 			Count:                   deliver_number,
2442 2469
 			CountUnit:               drup.MinUnit,
2443 2470
 			WarehouseInfoId:         warehouse.ID,
2471
+			AdviceId:                advice.ID,
2444 2472
 		}
2445 2473
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
2446 2474
 		if errTwo != nil {