Browse Source

11月8日库存管理

XMLWAN 3 years ago
parent
commit
48b4115bc7
3 changed files with 138 additions and 109 deletions
  1. 126 108
      controllers/his_api_controller.go
  2. 0 1
      controllers/stock_in_api_controller.go
  3. 12 0
      service/stock_service.go

+ 126 - 108
controllers/his_api_controller.go View File

633
 
633
 
634
 	patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
634
 	patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
635
 
635
 
636
-	//_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
637
-	//
638
-	//_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
639
-	//
640
-	//if drugStockConfig.IsOpen == 1 {
641
-	//	//校验库存总量
642
-	//	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
643
-	//		prescriptions, _ := dataBody["prescriptions"].([]interface{})
644
-	//		if len(prescriptions) > 0 {
645
-	//			for _, item := range prescriptions {
646
-	//				items := item.(map[string]interface{})
647
-	//				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
648
-	//					advices := items["advices"].([]interface{})
649
-	//					if len(advices) > 0 {
650
-	//						for _, advice := range advices {
651
-	//							var drug_id int64
652
-	//							var prescribing_number float64
653
-	//							var prescribingNumberUnit string
654
-	//
655
-	//							if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
656
-	//								drug_id = int64(advice.(map[string]interface{})["id"].(float64))
657
-	//							}
658
-	//							if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
659
-	//								//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
660
-	//								prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
661
-	//								prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
662
-	//
663
-	//							}
664
-	//
665
-	//							if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
666
-	//								prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
667
-	//							}
668
-	//
669
-	//							drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
670
-	//							if drug.ID == 0 {
671
-	//								c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
672
-	//								return
673
-	//							}
674
-	//
675
-	//							if prescribingNumberUnit == drug.MinUnit {
676
-	//								if prescribing_number > drug.Total {
677
-	//									c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
678
-	//									//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
679
-	//									return
680
-	//								}
681
-	//							} else {
682
-	//								if prescribingNumberUnit == drug.MaxUnit {
683
-	//									num := prescribing_number * float64(drug.MinNumber)
684
-	//									if num > drug.Total {
685
-	//										c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
686
-	//										//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
687
-	//										return
688
-	//									}
689
-	//								}
690
-	//							}
691
-	//						}
692
-	//					}
693
-	//				}
694
-	//			}
695
-	//		}
696
-	//	}
697
-	//}
698
-	//
699
-	//if stockConfig.IsOpen == 1 {
700
-	//	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
701
-	//		prescriptions, _ := dataBody["prescriptions"].([]interface{})
702
-	//		if len(prescriptions) > 0 {
703
-	//			for _, item := range prescriptions {
704
-	//				items := item.(map[string]interface{})
705
-	//				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
706
-	//					projects := items["project"].([]interface{})
707
-	//					if len(projects) > 0 {
708
-	//						for _, project := range projects {
709
-	//							var project_id int64
710
-	//							var project_type int64
711
-	//							var totals float64
712
-	//							if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
713
-	//								project_id = int64(project.(map[string]interface{})["project_id"].(float64))
714
-	//							}
715
-	//							if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
716
-	//								project_type = int64(project.(map[string]interface{})["type"].(float64))
717
-	//							}
718
-	//							if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
719
-	//								total, _ := project.(map[string]interface{})["total"].(string)
720
-	//
721
-	//								totals, _ = strconv.ParseFloat(total, 64)
722
-	//							}
723
-	//							if project_type == 3 {
724
-	//								good, _ := service.FindGoodInfoByIdTwo(project_id)
725
-	//								if good.ID == 0 {
726
-	//									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
727
-	//									return
728
-	//								}
729
-	//								if totals > good.Total {
730
-	//									c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
731
-	//									//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
732
-	//									return
733
-	//								}
734
-	//
735
-	//							}
736
-	//
737
-	//						}
738
-	//					}
739
-	//				}
740
-	//			}
741
-	//		}
742
-	//	}
743
-	//}
636
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
637
+
638
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
639
+
640
+	if drugStockConfig.IsOpen == 1 {
641
+		//校验库存总量
642
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
643
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
644
+			if len(prescriptions) > 0 {
645
+				for _, item := range prescriptions {
646
+					items := item.(map[string]interface{})
647
+					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
648
+						advices := items["advices"].([]interface{})
649
+						if len(advices) > 0 {
650
+							for _, advice := range advices {
651
+								var drug_id int64
652
+								var prescribing_number float64
653
+								var prescribingNumberUnit string
654
+
655
+								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
656
+									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
657
+								}
658
+								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
659
+									//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
660
+									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
661
+									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
662
+
663
+								}
664
+
665
+								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
666
+									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
667
+								}
668
+
669
+								drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
670
+								if drug.ID == 0 {
671
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
672
+									return
673
+								}
674
+
675
+								//查询药品的搜有库存
676
+								list, _ := service.GetDrugWarehouseInfoPrescription(drug_id, adminInfo.CurrentOrgId)
677
+								var total_count int64
678
+								for _, it := range list {
679
+									total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
680
+								}
681
+								totals := strconv.FormatInt(total_count, 10)
682
+								all_count, _ := strconv.ParseFloat(totals, 64)
683
+								fmt.Println("all_count2323323233232", all_count)
684
+								if prescribingNumberUnit == drug.MinUnit {
685
+									if prescribing_number > all_count {
686
+										c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
687
+										//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
688
+										return
689
+									}
690
+								} else {
691
+									if prescribingNumberUnit == drug.MaxUnit {
692
+										num := prescribing_number * float64(drug.MinNumber)
693
+										if num > all_count {
694
+											c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
695
+											//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
696
+											return
697
+										}
698
+									}
699
+								}
700
+
701
+							}
702
+						}
703
+					}
704
+				}
705
+			}
706
+		}
707
+	}
708
+
709
+	if stockConfig.IsOpen == 1 {
710
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
711
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
712
+			if len(prescriptions) > 0 {
713
+				for _, item := range prescriptions {
714
+					items := item.(map[string]interface{})
715
+					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
716
+						projects := items["project"].([]interface{})
717
+						if len(projects) > 0 {
718
+							for _, project := range projects {
719
+								var project_id int64
720
+								var project_type int64
721
+								var totals float64
722
+								if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
723
+									project_id = int64(project.(map[string]interface{})["project_id"].(float64))
724
+								}
725
+								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
726
+									project_type = int64(project.(map[string]interface{})["type"].(float64))
727
+								}
728
+								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
729
+									total, _ := project.(map[string]interface{})["total"].(string)
730
+
731
+									totals, _ = strconv.ParseFloat(total, 64)
732
+								}
733
+								if project_type == 3 {
734
+									good, _ := service.FindGoodInfoByIdTwo(project_id)
735
+									if good.ID == 0 {
736
+										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
737
+										return
738
+									}
739
+									//查询耗材库存
740
+									list, _ := service.GetGoodWarehouseInfo(project_id)
741
+									var stock_count int64
742
+									for _, it := range list {
743
+										stock_count += it.StockCount
744
+									}
745
+									stock_counts := strconv.FormatInt(stock_count, 10)
746
+									stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
747
+									if totals > stock_total_count {
748
+										c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
749
+
750
+										return
751
+									}
752
+
753
+								}
754
+
755
+							}
756
+						}
757
+					}
758
+				}
759
+			}
760
+		}
761
+	}
744
 
762
 
745
 	info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
763
 	info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
746
 	var hpInfo models.HisPrescriptionInfo
764
 	var hpInfo models.HisPrescriptionInfo

+ 0 - 1
controllers/stock_in_api_controller.go View File

2144
 			}
2144
 			}
2145
 			//更改入库数量
2145
 			//更改入库数量
2146
 			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
2146
 			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
2147
-			break
2148
 		}
2147
 		}
2149
 	}
2148
 	}
2150
 
2149
 

+ 12 - 0
service/stock_service.go View File

3289
 	return
3289
 	return
3290
 }
3290
 }
3291
 
3291
 
3292
+func GetGoodWarehouseInfo(good_id int64) (info []*models.WarehousingInfo, err error) {
3293
+
3294
+	err = readDb.Where("good_id = ? and status = 1 and stock_count<>0", good_id).Find(&info).Error
3295
+	return info, err
3296
+}
3297
+
3292
 func GetAllStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.VmWarehousingInfo, total int64, err error) {
3298
 func GetAllStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.VmWarehousingInfo, total int64, err error) {
3293
 
3299
 
3294
 	offset := (page - 1) * limit
3300
 	offset := (page - 1) * limit
4358
 	return info, err
4364
 	return info, err
4359
 }
4365
 }
4360
 
4366
 
4367
+func GetDrugWarehouseInfoPrescription(drugid int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
4368
+
4369
+	err = XTReadDB().Where("drug_id = ? and org_id =? and status = 1", drugid, orgid).Find(&info).Error
4370
+	return info, err
4371
+}
4372
+
4361
 func GetDrugWarehouseInfoById(id int64) (models.XtDrugWarehouseInfo, error) {
4373
 func GetDrugWarehouseInfoById(id int64) (models.XtDrugWarehouseInfo, error) {
4362
 
4374
 
4363
 	info := models.XtDrugWarehouseInfo{}
4375
 	info := models.XtDrugWarehouseInfo{}