ソースを参照

11月8日库存管理

XMLWAN 3 年 前
コミット
f15cf6d2c5

File diff suppressed because it is too large
+ 633 - 468
controllers/his_api_controller.go


+ 2 - 1
controllers/manager_center_api_controller.go ファイルの表示

1682
 	good_kind, _ := c.GetInt64("good_kind")
1682
 	good_kind, _ := c.GetInt64("good_kind")
1683
 	is_mark, _ := c.GetInt64("is_mark")
1683
 	is_mark, _ := c.GetInt64("is_mark")
1684
 	manufacturer, _ := c.GetInt64("manufacturer")
1684
 	manufacturer, _ := c.GetInt64("manufacturer")
1685
+	is_type, _ := c.GetInt64("is_type")
1685
 	adminUserInfo := c.GetAdminUserInfo()
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
 	if err == nil {
1688
 	if err == nil {
1688
 		c.ServeSuccessJSON(map[string]interface{}{
1689
 		c.ServeSuccessJSON(map[string]interface{}{
1689
 			"list":  goodInfos,
1690
 			"list":  goodInfos,

+ 2 - 0
models/stock_models.go ファイルの表示

595
 	WarehouseInfoId int64              `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
595
 	WarehouseInfoId int64              `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
596
 	GoodInfo        GoodInfo           `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
596
 	GoodInfo        GoodInfo           `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
597
 	WarehousingInfo []*WarehousingInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"xt_warehouse_info"`
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
 func (CancelStockInfo) TableName() string {
602
 func (CancelStockInfo) TableName() string {

+ 6 - 6
service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go ファイルの表示

554
 }
554
 }
555
 
555
 
556
 type ScheduleVM struct {
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
 	Patient                  *PatientVM                       `gorm:"ForeignKey:PatientID" json:"patient"`
562
 	Patient                  *PatientVM                       `gorm:"ForeignKey:PatientID" json:"patient"`
564
 	DialysisOrder            DialysisOrderVM                  `gorm:"ForeignKey:DialysisDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"dialysis_order"`
563
 	DialysisOrder            DialysisOrderVM                  `gorm:"ForeignKey:DialysisDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"dialysis_order"`
565
 	Prescription             PrescriptionVM                   `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"prescription"`
564
 	Prescription             PrescriptionVM                   `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"prescription"`
576
 	LastAfterWeight          XtAssessmentAfterDislysisVM      `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
575
 	LastAfterWeight          XtAssessmentAfterDislysisVM      `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
577
 	HisAdvices               []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"his_advices"`
576
 	HisAdvices               []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"his_advices"`
578
 	HisPrescriptionProject   []*models.HisPrescriptionProject `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"his_project"`
577
 	HisPrescriptionProject   []*models.HisPrescriptionProject `gorm:"ForeignKey:RecordDate,PatientID;AssociationForeignKey:ScheduleDate,PatientID" json:"his_project"`
578
+	Count                    int
579
 }
579
 }
580
 
580
 
581
 func (ScheduleVM) TableName() string {
581
 func (ScheduleVM) TableName() string {

+ 6 - 1
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go ファイルの表示

59
 	for _, item := range schedules {
59
 	for _, item := range schedules {
60
 
60
 
61
 		if orgID != 10101 {
61
 		if orgID != 10101 {
62
-			dialysis_count, _ := GetDialysisOrderCount(orgID, item.PatientID, item.ScheduleDate)
62
+			dialysis_count, _ := GetDialysisOrderCountOne(orgID, item.PatientID, item.ScheduleDate)
63
 			item.Patient.TotalDialysis = dialysis_count
63
 			item.Patient.TotalDialysis = dialysis_count
64
 		}
64
 		}
65
 		if orgID == 10101 {
65
 		if orgID == 10101 {
207
 	return
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
 func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
215
 func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
211
 	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
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
 	return
217
 	return

+ 35 - 9
service/stock_service.go ファイルの表示

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
 	offset := (page - 1) * limit
263
 	offset := (page - 1) * limit
264
 	db := readDb.Model(&models.GoodInfo{})
264
 	db := readDb.Model(&models.GoodInfo{})
265
 	db = db.Where("org_id = ? AND status = 1", orgId)
265
 	db = db.Where("org_id = ? AND status = 1", orgId)
291
 		if manufacturer > 0 {
291
 		if manufacturer > 0 {
292
 			db = db.Where("manufacturer = ?", manufacturer)
292
 			db = db.Where("manufacturer = ?", manufacturer)
293
 		}
293
 		}
294
+		if is_type > 0 {
295
+			db = db.Where("good_type_id = ?", is_type)
296
+		}
294
 	} else {
297
 	} else {
295
 		if is_use > 0 {
298
 		if is_use > 0 {
296
 			if is_use == 1 {
299
 			if is_use == 1 {
316
 		if manufacturer > 0 {
319
 		if manufacturer > 0 {
317
 			db = db.Where("manufacturer = ?", manufacturer)
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
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
327
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
3483
 	return err
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
 func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64) error {
3498
 func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64) error {
3487
 
3499
 
3488
 	detail := models.BloodAutomaticReduceDetail{}
3500
 	detail := models.BloodAutomaticReduceDetail{}
3491
 	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
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
 	prepare := models.DialysisBeforePrepare{}
3504
 	prepare := models.DialysisBeforePrepare{}
3493
 	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
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
 	return err
3508
 	return err
3495
 
3509
 
3496
 }
3510
 }
3497
 
3511
 
3498
 func UpDateWarehouseInfoByStockDelete(id int64, count int64) (err error) {
3512
 func UpDateWarehouseInfoByStockDelete(id int64, count int64) (err error) {
3513
+
3499
 	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
3514
 	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
3500
 	return err
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
 func UpDateWarehouStockFlowByStockDelete(id int64, recordtime int64, good_id int64, count int64, patient_id int64) (err error) {
3530
 func UpDateWarehouStockFlowByStockDelete(id int64, recordtime int64, good_id int64, count int64, patient_id int64) (err error) {
3504
 
3531
 
3505
 	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
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
 	return &autoreduece, nil
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
 	return detail, err
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
 	return detail, err
3563
 	return detail, err
3538
 }
3564
 }
3539
 
3565
 
4706
 	return info, err
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
 	detail := models.DrugAutomaticReduceDetail{}
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
 	return detail, err
4738
 	return detail, err
4713
 }
4739
 }
4714
 
4740
 

+ 30 - 2
service/warhouse_service.go ファイルの表示

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