Browse Source

11月8日库存管理

XMLWAN 3 years ago
parent
commit
93f5852620

+ 1 - 2
controllers/dialysis_api_controller.go View File

@@ -3510,7 +3510,7 @@ func (c *DialysisApiController) UploadDryWeight() {
3510 3510
 		redis.Set(keyOne, "", time.Second)
3511 3511
 
3512 3512
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
3513
-		fmt.Println("敢提哦那个key23232332323223232332232323", key)
3513
+
3514 3514
 		redis.Set(key, "", time.Second)
3515 3515
 		keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
3516 3516
 		redis.Set(keyTwo, "", time.Second)
@@ -3559,7 +3559,6 @@ func (c *DialysisApiController) UploadDryWeight() {
3559 3559
 
3560 3560
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
3561 3561
 		redis.Set(key, "", time.Second)
3562
-		fmt.Println("敢提哦那个key23232332323223232332232323", key)
3563 3562
 		keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
3564 3563
 		redis.Set(keyTwo, "", time.Second)
3565 3564
 		redis.Close()

+ 1 - 1
controllers/drug_stock_api_contorller.go View File

@@ -732,7 +732,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
732 732
 							BatchNumber:  it.BatchNumber,
733 733
 							Price:        it.Price,
734 734
 						}
735
-						parseDateErr := service.UpdateDrugFlowTen(flow, item.DrugId, warehouseInfo.WarehousingId)
735
+						parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, warehouseInfo.WarehousingId)
736 736
 						fmt.Println(parseDateErr)
737 737
 
738 738
 					}

+ 596 - 51
controllers/his_api_controller.go View File

@@ -105,6 +105,8 @@ func HisManagerApiRegistRouters() {
105 105
 
106 106
 	beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
107 107
 
108
+	beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
109
+
108 110
 }
109 111
 
110 112
 func (c *HisApiController) GetHisUnChargePatientList() {
@@ -702,13 +704,15 @@ func (c *HisApiController) CreateHisPrescription() {
702 704
 								var drug_id int64
703 705
 								var prescribing_number float64
704 706
 								var prescribingNumberUnit string
705
-
707
+								var prescribingNumber string
708
+								var adviceId int64
706 709
 								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
707 710
 									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
708 711
 								}
709 712
 								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
710 713
 									//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
711 714
 									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
715
+									prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
712 716
 									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
713 717
 
714 718
 								}
@@ -717,38 +721,114 @@ func (c *HisApiController) CreateHisPrescription() {
717 721
 									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
718 722
 								}
719 723
 
724
+								if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
725
+									adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
726
+								}
727
+
720 728
 								drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
721 729
 								if drug.ID == 0 {
722 730
 									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
723 731
 									return
724 732
 								}
725 733
 
726
-								//查询药品的有库存
734
+								//查询药品的有库存
727 735
 								list, _ := service.GetDrugWarehouseInfoPrescription(drug_id, adminInfo.CurrentOrgId)
728 736
 								var total_count int64
737
+
729 738
 								for _, it := range list {
730 739
 									total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
731 740
 								}
732 741
 								totals := strconv.FormatInt(total_count, 10)
733
-								all_count, _ := strconv.ParseFloat(totals, 64)
734
-								fmt.Println("all_count2323323233232", all_count)
735
-								if prescribingNumberUnit == drug.MinUnit {
736
-									if prescribing_number > all_count {
737
-										c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
738
-										//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
739
-										return
742
+								//查询该药品是否存在开药记录
743
+								advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
744
+								//修改处方
745
+								if advicelist.ID > 0 {
746
+									var device_number int64
747
+									if advicelist.PrescribingNumberUnit == drug.MaxUnit {
748
+										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
749
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
750
+										device_number = prescribingNumberInt * drug.MinNumber
751
+									}
752
+									if advicelist.PrescribingNumberUnit == drug.MinUnit {
753
+										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
754
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
755
+										device_number = prescribingNumberInt
740 756
 									}
741
-								} else {
757
+
758
+									var number_count int64
742 759
 									if prescribingNumberUnit == drug.MaxUnit {
743
-										num := prescribing_number * float64(drug.MinNumber)
744
-										if num > all_count {
760
+										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
761
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
762
+										number_count = prescribingNumberInt * drug.MinNumber
763
+									}
764
+									if prescribingNumberUnit == drug.MinUnit {
765
+										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
766
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
767
+										number_count = prescribingNumberInt
768
+									}
769
+									//如果修改的数量大于之前修改的数量
770
+									if (number_count - device_number) > 0 {
771
+										//如果修改的差数量 大于库存数量
772
+										if (number_count - device_number) > total_count {
745 773
 											c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
746
-											//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
747 774
 											return
748 775
 										}
749 776
 									}
777
+
778
+									var sum_count int64
779
+									//判断是否做过修改
780
+									if prescribingNumberUnit == drug.MaxUnit {
781
+
782
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
783
+
784
+										sum_count = prescribingNumberInt * drug.MinNumber
785
+									}
786
+									if prescribingNumberUnit == drug.MinUnit {
787
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
788
+										sum_count = prescribingNumberInt
789
+									}
790
+									fmt.Println("原先药品记录", device_number)
791
+									fmt.Println("现在出库数量", sum_count)
792
+									if device_number != sum_count {
793
+
794
+										// 查询该药品最后一次出库记录
795
+										druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime)
796
+										//回退库存
797
+										if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
798
+											service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
799
+										}
800
+										if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
801
+											service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, druginfo.Count)
802
+										}
803
+
804
+										if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
805
+											service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
806
+										}
807
+
808
+										//删除记录
809
+										service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
810
+									}
811
+
750 812
 								}
751 813
 
814
+								//新增处方
815
+								if advicelist.ID == 0 {
816
+									all_count, _ := strconv.ParseFloat(totals, 64)
817
+									if prescribingNumberUnit == drug.MinUnit {
818
+										if prescribing_number > all_count {
819
+											c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
820
+											return
821
+										}
822
+									} else {
823
+										if prescribingNumberUnit == drug.MaxUnit {
824
+											num := prescribing_number * float64(drug.MinNumber)
825
+											if num > all_count {
826
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
827
+												return
828
+											}
829
+										}
830
+									}
831
+								}
752 832
 							}
753 833
 						}
754 834
 					}
@@ -770,6 +850,7 @@ func (c *HisApiController) CreateHisPrescription() {
770 850
 								var project_id int64
771 851
 								var project_type int64
772 852
 								var totals float64
853
+								var parsetotal int64
773 854
 								if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
774 855
 									project_id = int64(project.(map[string]interface{})["project_id"].(float64))
775 856
 								}
@@ -780,27 +861,53 @@ func (c *HisApiController) CreateHisPrescription() {
780 861
 									total, _ := project.(map[string]interface{})["total"].(string)
781 862
 
782 863
 									totals, _ = strconv.ParseFloat(total, 64)
864
+									parsetotal, _ = strconv.ParseInt(total, 10, 64)
783 865
 								}
784 866
 								if project_type == 3 {
785
-									good, _ := service.FindGoodInfoByIdTwo(project_id)
786
-									if good.ID == 0 {
787
-										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
788
-										return
789
-									}
790
-									//查询耗材库存
791
-									list, _ := service.GetGoodWarehouseInfo(project_id)
792
-									var stock_count int64
793
-									for _, it := range list {
794
-										stock_count += it.StockCount
795
-									}
796
-									stock_counts := strconv.FormatInt(stock_count, 10)
797
-									stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
798
-									if totals > stock_total_count {
799
-										c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
800 867
 
801
-										return
802
-									}
868
+									//查找该耗材的出库记录
869
+									goodWarehouseInfo, _ := service.GetAutoRecordByGoodId(project_id, patient_id, recordDateTime)
870
+									fmt.Println("出库数量00000000000000000000000", parsetotal)
871
+									fmt.Println("已经出库数量0000000000000000000", goodWarehouseInfo.Count)
872
+
873
+									//查询该患者耗材的历史数据
874
+									ordProject, _ := service.GetHisProjectPrescriptionByPatientId(patient_id, recordDateTime)
875
+									fmt.Println("长度1", len(ordProject))
876
+									fmt.Println("新长度", len(projects))
877
+									if goodWarehouseInfo.ID > 0 {
878
+										//数量发生改变
879
+										if parsetotal != goodWarehouseInfo.Count || len(ordProject) != len(projects) {
880
+											//查找今日该患者已经出库的所有耗材
881
+											goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
882
+											for _, item := range goodList {
883
+												//回退库存
884
+												service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
885
+												//删除记录
886
+												service.DeleteAutoWarehouse(item.PatientId, item.SysRecordTime)
887
+											}
888
+
889
+										}
803 890
 
891
+									}
892
+									if goodWarehouseInfo.ID == 0 {
893
+										good, _ := service.FindGoodInfoByIdTwo(project_id)
894
+										if good.ID == 0 {
895
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
896
+											return
897
+										}
898
+										//查询耗材库存
899
+										list, _ := service.GetGoodWarehouseInfo(project_id)
900
+										var stock_count int64
901
+										for _, it := range list {
902
+											stock_count += it.StockCount
903
+										}
904
+										stock_counts := strconv.FormatInt(stock_count, 10)
905
+										stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
906
+										if totals > stock_total_count {
907
+											c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
908
+											return
909
+										}
910
+									}
804 911
 								}
805 912
 
806 913
 							}
@@ -1478,20 +1585,117 @@ func (c *HisApiController) DeletePrescription() {
1478 1585
 				if stockConfig.IsOpen == 1 {
1479 1586
 					if item.Type == 3 {
1480 1587
 						good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
1481
-						//cnt, _ := strconv.ParseInt(item.Count, 10, 64)
1482 1588
 						f_count, _ := strconv.ParseFloat(item.Count, 64)
1483 1589
 						good.Total = good.Total + f_count
1484 1590
 						service.UpdateGoodInfo(&good)
1485
-					}
1486
-				}
1591
+						operation_time := time.Now().Unix()
1592
+						creater := c.GetAdminUserInfo().AdminUser.Id
1593
+						//创建退库单
1594
+						timeStr := time.Now().Format("2006-01-02")
1595
+						timeArr := strings.Split(timeStr, "-")
1596
+						total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
1597
+						total = total + 1
1598
+						orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
1599
+
1600
+						cancelStock := models.CancelStock{
1601
+							OrderNumber: orderNumber,
1602
+							OperaTime:   operation_time,
1603
+							OrgId:       c.GetAdminUserInfo().CurrentOrgId,
1604
+							Creater:     creater,
1605
+							Ctime:       time.Now().Unix(),
1606
+							Status:      1,
1607
+							ReturnTime:  item.RecordDate,
1608
+							Type:        1,
1609
+						}
1610
+						_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
1611
+						if msgerrkonde == gorm.ErrRecordNotFound {
1612
+							service.AddSigleCancelStock(&cancelStock)
1613
+						}
1614
+						cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
1615
+						floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
1616
+						prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
1617
+						//获取该耗材有库存的第一条数据
1618
+						info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
1619
+
1620
+						manufacturer, _ := service.GetManufactureById(info.Manufacturer)
1621
+						deaerler, _ := service.GetDealerById(info.Dealer)
1622
+						if info.ID > 0 {
1623
+							cancelStockInfo := models.CancelStockInfo{
1624
+								GoodId:          item.ProjectId,
1625
+								CancelStockId:   cancel.ID,
1626
+								GoodTypeId:      info.GoodTypeId,
1627
+								Count:           prescribingNumber,
1628
+								Price:           info.Price,
1629
+								Total:           0,
1630
+								ProductDate:     info.ProductDate,
1631
+								ExpiryDate:      info.ExpiryDate,
1632
+								Ctime:           time.Now().Unix(),
1633
+								Status:          1,
1634
+								OrgId:           c.GetAdminUserInfo().CurrentOrgId,
1635
+								OrderNumber:     cancel.OrderNumber,
1636
+								Type:            0,
1637
+								Dealer:          deaerler.DealerName,
1638
+								Manufacturer:    manufacturer.ManufacturerName,
1639
+								Number:          info.Number,
1640
+								RegisterAccount: "",
1641
+								Remark:          "",
1642
+								WarehouseInfoId: info.WarehouseInfotId,
1643
+							}
1644
+
1645
+							service.CreateCancelStockInfoOne(&cancelStockInfo)
1646
+
1647
+							cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
1648
+
1649
+							flow := models.VmStockFlow{
1650
+								WarehousingId:           0,
1651
+								GoodId:                  item.ProjectId,
1652
+								Number:                  info.Number,
1653
+								LicenseNumber:           info.LicenseNumber,
1654
+								Count:                   prescribingNumber,
1655
+								UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
1656
+								PatientId:               item.PatientId,
1657
+								SystemTime:              time.Now().Unix(),
1658
+								ConsumableType:          7,
1659
+								IsSys:                   0,
1660
+								WarehousingOrder:        "",
1661
+								WarehouseOutId:          0,
1662
+								WarehouseOutOrderNumber: "",
1663
+								IsEdit:                  0,
1664
+								CancelStockId:           cancel.ID,
1665
+								CancelOrderNumber:       cancel.OrderNumber,
1666
+								Manufacturer:            manufacturer.ID,
1667
+								Dealer:                  0,
1668
+								Creator:                 c.GetAdminUserInfo().CurrentOrgId,
1669
+								UpdateCreator:           0,
1670
+								Status:                  1,
1671
+								Ctime:                   time.Now().Unix(),
1672
+								Mtime:                   0,
1673
+								Price:                   info.Price,
1674
+								WarehousingDetailId:     info.WarehouseInfotId,
1675
+								WarehouseOutDetailId:    0,
1676
+								CancelOutDetailId:       cancelInfo.ID,
1677
+								ProductDate:             info.ProductDate,
1678
+								ExpireDate:              info.ExpiryDate,
1679
+							}
1680
+							service.CreateStockFlowOne(flow)
1681
+
1682
+							//删除出库表
1683
+							service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
1684
+
1685
+							//回退库存
1686
+							service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber)
1687
+						}
1487 1688
 
1488
-				if item.Type == 3 { //处理透前准备耗材数量数据
1489
-					consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
1490
-					if consumables.ID > 0 {
1491
-						consumables.Count = 0
1492
-						service.UpdateConsumables(&consumables)
1493 1689
 					}
1494 1690
 				}
1691
+
1692
+				//if item.Type == 3 { //处理透前准备耗材数量数据
1693
+				//	consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
1694
+				//	if consumables.ID > 0 {
1695
+				//		consumables.Count = 0
1696
+				//		service.UpdateConsumables(&consumables)
1697
+				//	}
1698
+				//}
1495 1699
 			}
1496 1700
 		}
1497 1701
 
@@ -1503,6 +1707,224 @@ func (c *HisApiController) DeletePrescription() {
1503 1707
 					keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
1504 1708
 					redis.Set(keyFive, "", time.Second)
1505 1709
 					redis.Close()
1710
+
1711
+					//查询该药品是否存在出库记录
1712
+					info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
1713
+
1714
+					if errcode == gorm.ErrRecordNotFound {
1715
+
1716
+					} else if errcode == nil {
1717
+						if item.PrescribingNumberUnit == drug.MinUnit {
1718
+
1719
+							floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
1720
+							prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
1721
+
1722
+							//退库
1723
+							warehouseInfo := models.DrugWarehouseInfo{
1724
+								StockMinNumber: prescribingNumber,
1725
+							}
1726
+
1727
+							service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
1728
+
1729
+							adminUserInfo := c.GetAdminUserInfo()
1730
+							operation_time := time.Now().Unix()
1731
+							creater := adminUserInfo.AdminUser.Id
1732
+
1733
+							ctime := time.Now().Unix()
1734
+							timeStr := time.Now().Format("2006-01-02")
1735
+							timeArr := strings.Split(timeStr, "-")
1736
+							total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
1737
+							total = total + 1
1738
+							orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
1739
+
1740
+							cancelStock := models.DrugCancelStock{
1741
+								OrderNumber:  orderNumber,
1742
+								OperaTime:    operation_time,
1743
+								OrgId:        adminUserInfo.CurrentOrgId,
1744
+								Creater:      creater,
1745
+								Ctime:        ctime,
1746
+								Status:       1,
1747
+								ReturnTime:   item.AdviceDate,
1748
+								Dealer:       info.Dealer,
1749
+								Manufacturer: info.Manufacturer,
1750
+								Type:         1,
1751
+							}
1752
+							service.AddSigleDrugCancelStock(&cancelStock)
1753
+
1754
+							manufactureName, _ := service.GetManufactureById(info.Manufacturer)
1755
+							dealer, _ := service.GetDealerById(info.Dealer)
1756
+							cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
1757
+							cancelStockInfo := models.DrugCancelStockInfo{
1758
+								OrderNumber:      cancelInfo.OrderNumber,
1759
+								CancelStockId:    cancelInfo.ID,
1760
+								DrugId:           info.DrugId,
1761
+								Count:            info.Count,
1762
+								Status:           1,
1763
+								Ctime:            ctime,
1764
+								OrgId:            adminUserInfo.CurrentOrgId,
1765
+								Type:             1,
1766
+								Manufacturer:     manufactureName.ManufacturerName,
1767
+								Dealer:           dealer.DealerName,
1768
+								Total:            0,
1769
+								RetailPrice:      info.RetailPrice,
1770
+								RetailTotalPrice: info.RetailTotalPrice,
1771
+								Price:            info.Price,
1772
+								RegisterAccount:  "",
1773
+								Remark:           info.Remark,
1774
+								BatchNumber:      info.BatchNumber,
1775
+								MaxUnit:          info.CountUnit,
1776
+								ProductDate:      info.ProductDate,
1777
+								ExpiryDate:       info.ExpiryDate,
1778
+								BatchNumberId:    info.WarehouseInfoId,
1779
+							}
1780
+
1781
+							flow := models.DrugFlow{
1782
+								WarehousingId:           0,
1783
+								DrugId:                  info.DrugId,
1784
+								Number:                  "",
1785
+								BatchNumber:             info.BatchNumber,
1786
+								Count:                   info.Count,
1787
+								UserOrgId:               adminUserInfo.CurrentOrgId,
1788
+								PatientId:               0,
1789
+								SystemTime:              ctime,
1790
+								ConsumableType:          7,
1791
+								IsSys:                   0,
1792
+								WarehousingOrder:        "",
1793
+								WarehouseOutId:          0,
1794
+								WarehouseOutOrderNumber: "",
1795
+								IsEdit:                  0,
1796
+								CancelStockId:           cancelStock.ID,
1797
+								CancelOrderNumber:       cancelStock.OrderNumber,
1798
+								Manufacturer:            info.Manufacturer,
1799
+								Dealer:                  info.Dealer,
1800
+								Creator:                 adminUserInfo.AdminUser.Id,
1801
+								UpdateCreator:           0,
1802
+								Status:                  1,
1803
+								Ctime:                   time.Now().Unix(),
1804
+								Mtime:                   0,
1805
+								Price:                   info.Price,
1806
+								WarehousingDetailId:     0,
1807
+								WarehouseOutDetailId:    0,
1808
+								CancelOutDetailId:       0,
1809
+								ExpireDate:              info.ExpiryDate,
1810
+								ProductDate:             info.ProductDate,
1811
+								MaxUnit:                 info.CountUnit,
1812
+								MinUnit:                 "",
1813
+							}
1814
+							service.CreatedCancelStock(cancelStockInfo)
1815
+							service.CreateDrugFlowOne(flow)
1816
+
1817
+							//删除出库记录
1818
+							service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
1819
+							//删除流水
1820
+							service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
1821
+						} else {
1822
+							floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
1823
+
1824
+							prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
1825
+
1826
+							if item.PrescribingNumberUnit == drug.MaxUnit {
1827
+								warehouseInfo := models.DrugWarehouseInfo{
1828
+									StockMaxNumber: prescribingNumber,
1829
+								}
1830
+								service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
1831
+
1832
+							}
1833
+
1834
+							adminUserInfo := c.GetAdminUserInfo()
1835
+							operation_time := time.Now().Unix()
1836
+							creater := adminUserInfo.AdminUser.Id
1837
+
1838
+							ctime := time.Now().Unix()
1839
+							timeStr := time.Now().Format("2006-01-02")
1840
+							timeArr := strings.Split(timeStr, "-")
1841
+							total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
1842
+							total = total + 1
1843
+							orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
1844
+
1845
+							cancelStock := models.DrugCancelStock{
1846
+								OrderNumber:  orderNumber,
1847
+								OperaTime:    operation_time,
1848
+								OrgId:        adminUserInfo.CurrentOrgId,
1849
+								Creater:      creater,
1850
+								Ctime:        ctime,
1851
+								Status:       1,
1852
+								ReturnTime:   item.AdviceDate,
1853
+								Dealer:       info.Dealer,
1854
+								Manufacturer: info.Manufacturer,
1855
+								Type:         1,
1856
+							}
1857
+							service.AddSigleDrugCancelStock(&cancelStock)
1858
+
1859
+							manufactureName, _ := service.GetManufactureById(info.Manufacturer)
1860
+							dealer, _ := service.GetDealerById(info.Dealer)
1861
+							cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
1862
+							cancelStockInfo := models.DrugCancelStockInfo{
1863
+								OrderNumber:      cancelInfo.OrderNumber,
1864
+								CancelStockId:    cancelInfo.ID,
1865
+								DrugId:           info.DrugId,
1866
+								Count:            info.Count,
1867
+								Status:           1,
1868
+								Ctime:            ctime,
1869
+								OrgId:            adminUserInfo.CurrentOrgId,
1870
+								Type:             1,
1871
+								Manufacturer:     manufactureName.ManufacturerName,
1872
+								Dealer:           dealer.DealerName,
1873
+								Total:            0,
1874
+								RetailPrice:      info.RetailPrice,
1875
+								RetailTotalPrice: info.RetailTotalPrice,
1876
+								Price:            info.Price,
1877
+								RegisterAccount:  "",
1878
+								Remark:           info.Remark,
1879
+								BatchNumber:      info.BatchNumber,
1880
+								MaxUnit:          info.CountUnit,
1881
+								ProductDate:      info.ProductDate,
1882
+								ExpiryDate:       info.ExpiryDate,
1883
+								BatchNumberId:    info.WarehouseInfoId,
1884
+							}
1885
+
1886
+							flow := models.DrugFlow{
1887
+								WarehousingId:           0,
1888
+								DrugId:                  info.DrugId,
1889
+								Number:                  "",
1890
+								BatchNumber:             info.BatchNumber,
1891
+								Count:                   info.Count,
1892
+								UserOrgId:               adminUserInfo.CurrentOrgId,
1893
+								PatientId:               0,
1894
+								SystemTime:              ctime,
1895
+								ConsumableType:          7,
1896
+								IsSys:                   0,
1897
+								WarehousingOrder:        "",
1898
+								WarehouseOutId:          0,
1899
+								WarehouseOutOrderNumber: "",
1900
+								IsEdit:                  0,
1901
+								CancelStockId:           cancelStock.ID,
1902
+								CancelOrderNumber:       cancelStock.OrderNumber,
1903
+								Manufacturer:            info.Manufacturer,
1904
+								Dealer:                  info.Dealer,
1905
+								Creator:                 adminUserInfo.AdminUser.Id,
1906
+								UpdateCreator:           0,
1907
+								Status:                  1,
1908
+								Ctime:                   time.Now().Unix(),
1909
+								Mtime:                   0,
1910
+								Price:                   info.Price,
1911
+								WarehousingDetailId:     0,
1912
+								WarehouseOutDetailId:    0,
1913
+								CancelOutDetailId:       0,
1914
+								ExpireDate:              info.ExpiryDate,
1915
+								ProductDate:             info.ProductDate,
1916
+								MaxUnit:                 info.CountUnit,
1917
+								MinUnit:                 "",
1918
+							}
1919
+							service.CreatedCancelStock(cancelStockInfo)
1920
+							service.CreateDrugFlowOne(flow)
1921
+							//删除出库记录
1922
+							service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
1923
+							//删除流水
1924
+							service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
1925
+						}
1926
+					}
1927
+
1506 1928
 					if item.PrescribingNumberUnit == drug.MinUnit {
1507 1929
 						drug.Total = drug.Total + item.PrescribingNumber
1508 1930
 						service.UpdateBaseDrugLib(&drug)
@@ -1513,6 +1935,7 @@ func (c *HisApiController) DeletePrescription() {
1513 1935
 							service.UpdateBaseDrugLib(&drug)
1514 1936
 						}
1515 1937
 					}
1938
+
1516 1939
 				}
1517 1940
 			}
1518 1941
 		}
@@ -1536,13 +1959,17 @@ func (c *HisApiController) DeleteDoctorAdvice() {
1536 1959
 	redis := service.RedisClient()
1537 1960
 	keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
1538 1961
 	redis.Set(keyFive, "", time.Second)
1962
+	keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
1963
+	redis.Set(keyOne, "", time.Second)
1964
+
1539 1965
 	redis.Close()
1540 1966
 	if err == nil {
1541 1967
 		if drugStockConfig.IsOpen == 1 {
1542 1968
 			//判断该医嘱是否执行了
1543 1969
 			if advice.ExecutionState == 1 {
1970
+				fmt.Println("advice_id23323232323233232323233223322323", advice.ID)
1544 1971
 				//查询该病人该药品是否有库存记录
1545
-				info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
1972
+				info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
1546 1973
 				if errcode == gorm.ErrRecordNotFound {
1547 1974
 
1548 1975
 				} else {
@@ -1621,7 +2048,7 @@ func (c *HisApiController) DeleteDoctorAdvice() {
1621 2048
 							UserOrgId:               adminUserInfo.CurrentOrgId,
1622 2049
 							PatientId:               0,
1623 2050
 							SystemTime:              ctime,
1624
-							ConsumableType:          4,
2051
+							ConsumableType:          7,
1625 2052
 							IsSys:                   0,
1626 2053
 							WarehousingOrder:        "",
1627 2054
 							WarehouseOutId:          0,
@@ -1647,20 +2074,25 @@ func (c *HisApiController) DeleteDoctorAdvice() {
1647 2074
 						}
1648 2075
 						service.CreatedCancelStock(cancelStockInfo)
1649 2076
 						service.CreateDrugFlowOne(flow)
2077
+
2078
+						//删除出库记录
2079
+						service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
2080
+						//删除流水
2081
+						service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
1650 2082
 					} else {
1651 2083
 
1652 2084
 						floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
1653 2085
 
1654 2086
 						prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
1655 2087
 
1656
-						fmt.Println("PrescribingNumber", prescribingNumber)
1657 2088
 						if advice.PrescribingNumberUnit == drug.MaxUnit {
1658 2089
 							warehouseInfo := models.DrugWarehouseInfo{
1659
-								StockMinNumber: prescribingNumber,
2090
+								StockMaxNumber: prescribingNumber,
1660 2091
 							}
1661 2092
 							service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
1662 2093
 
1663 2094
 						}
2095
+
1664 2096
 						adminUserInfo := c.GetAdminUserInfo()
1665 2097
 						operation_time := time.Now().Unix()
1666 2098
 						creater := adminUserInfo.AdminUser.Id
@@ -1722,7 +2154,7 @@ func (c *HisApiController) DeleteDoctorAdvice() {
1722 2154
 							UserOrgId:               adminUserInfo.CurrentOrgId,
1723 2155
 							PatientId:               0,
1724 2156
 							SystemTime:              ctime,
1725
-							ConsumableType:          4,
2157
+							ConsumableType:          7,
1726 2158
 							IsSys:                   0,
1727 2159
 							WarehousingOrder:        "",
1728 2160
 							WarehouseOutId:          0,
@@ -1748,6 +2180,11 @@ func (c *HisApiController) DeleteDoctorAdvice() {
1748 2180
 						}
1749 2181
 						service.CreatedCancelStock(cancelStockInfo)
1750 2182
 						service.CreateDrugFlowOne(flow)
2183
+						//删除出库记录
2184
+						service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
2185
+						//删除流水
2186
+						service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
2187
+
1751 2188
 					}
1752 2189
 				}
1753 2190
 			}
@@ -1768,12 +2205,12 @@ func (c *HisApiController) DeleteProject() {
1768 2205
 	id, _ := c.GetInt64("id")
1769 2206
 	adminInfo := c.GetAdminUserInfo()
1770 2207
 	project, _ := service.GetHisProjectByID(id)
1771
-	var consumable models.DialysisBeforePrepare
2208
+	//	var consumable models.DialysisBeforePrepare
1772 2209
 	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
1773 2210
 
1774
-	if project.ID > 0 && project.Type == 3 {
1775
-		consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
1776
-	}
2211
+	//if project.ID > 0 && project.Type == 3 {
2212
+	//	consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
2213
+	//}
1777 2214
 	err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
1778 2215
 	if err == nil {
1779 2216
 		service.DeletePrintInfo(id)
@@ -1787,12 +2224,110 @@ func (c *HisApiController) DeleteProject() {
1787 2224
 				f_count, _ := strconv.ParseFloat(project.Count, 64)
1788 2225
 				good.Total = good.Total + f_count
1789 2226
 				service.UpdateGoodInfo(&good)
2227
+
2228
+				operation_time := time.Now().Unix()
2229
+				creater := adminInfo.AdminUser.Id
2230
+				//创建退库单
2231
+				timeStr := time.Now().Format("2006-01-02")
2232
+				timeArr := strings.Split(timeStr, "-")
2233
+				total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
2234
+				total = total + 1
2235
+				orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
2236
+
2237
+				cancelStock := models.CancelStock{
2238
+					OrderNumber: orderNumber,
2239
+					OperaTime:   operation_time,
2240
+					OrgId:       adminInfo.CurrentOrgId,
2241
+					Creater:     creater,
2242
+					Ctime:       time.Now().Unix(),
2243
+					Status:      1,
2244
+					ReturnTime:  project.RecordDate,
2245
+					Type:        1,
2246
+				}
2247
+				_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
2248
+				if msgerrkonde == gorm.ErrRecordNotFound {
2249
+					service.AddSigleCancelStock(&cancelStock)
2250
+				}
2251
+				cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
2252
+				floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
2253
+				prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
2254
+				//获取该耗材有库存的第一条数据
2255
+				info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
2256
+
2257
+				manufacturer, _ := service.GetManufactureById(info.Manufacturer)
2258
+				deaerler, _ := service.GetDealerById(info.Dealer)
2259
+				if info.ID > 0 {
2260
+					cancelStockInfo := models.CancelStockInfo{
2261
+						GoodId:          project.ProjectId,
2262
+						CancelStockId:   cancel.ID,
2263
+						GoodTypeId:      info.GoodTypeId,
2264
+						Count:           prescribingNumber,
2265
+						Price:           info.Price,
2266
+						Total:           0,
2267
+						ProductDate:     info.ProductDate,
2268
+						ExpiryDate:      info.ExpiryDate,
2269
+						Ctime:           time.Now().Unix(),
2270
+						Status:          1,
2271
+						OrgId:           adminInfo.CurrentOrgId,
2272
+						OrderNumber:     cancel.OrderNumber,
2273
+						Type:            0,
2274
+						Dealer:          deaerler.DealerName,
2275
+						Manufacturer:    manufacturer.ManufacturerName,
2276
+						Number:          info.Number,
2277
+						RegisterAccount: "",
2278
+						Remark:          "",
2279
+						WarehouseInfoId: info.WarehouseInfotId,
2280
+					}
2281
+
2282
+					service.CreateCancelStockInfoOne(&cancelStockInfo)
2283
+
2284
+					cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
2285
+
2286
+					flow := models.VmStockFlow{
2287
+						WarehousingId:           0,
2288
+						GoodId:                  project.ProjectId,
2289
+						Number:                  info.Number,
2290
+						LicenseNumber:           info.LicenseNumber,
2291
+						Count:                   prescribingNumber,
2292
+						UserOrgId:               adminInfo.CurrentOrgId,
2293
+						PatientId:               project.PatientId,
2294
+						SystemTime:              time.Now().Unix(),
2295
+						ConsumableType:          7,
2296
+						IsSys:                   0,
2297
+						WarehousingOrder:        "",
2298
+						WarehouseOutId:          0,
2299
+						WarehouseOutOrderNumber: "",
2300
+						IsEdit:                  0,
2301
+						CancelStockId:           cancel.ID,
2302
+						CancelOrderNumber:       cancel.OrderNumber,
2303
+						Manufacturer:            manufacturer.ID,
2304
+						Dealer:                  0,
2305
+						Creator:                 adminInfo.AdminUser.Id,
2306
+						UpdateCreator:           0,
2307
+						Status:                  1,
2308
+						Ctime:                   time.Now().Unix(),
2309
+						Mtime:                   0,
2310
+						Price:                   info.Price,
2311
+						WarehousingDetailId:     info.WarehouseInfotId,
2312
+						WarehouseOutDetailId:    0,
2313
+						CancelOutDetailId:       cancelInfo.ID,
2314
+						ProductDate:             info.ProductDate,
2315
+						ExpireDate:              info.ExpiryDate,
2316
+					}
2317
+					service.CreateStockFlowOne(flow)
2318
+
2319
+					//删除出库表
2320
+					service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
2321
+
2322
+					//回退库存
2323
+					service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber)
2324
+				}
1790 2325
 			}
1791 2326
 		}
1792
-		if consumable.ID > 0 {
1793
-			consumable.Count = 0
1794
-			service.UpdateConsumables(&consumable)
1795
-		}
2327
+		//if consumable.ID > 0 {
2328
+		//	consumable.Count = 0
2329
+		//	service.UpdateConsumables(&consumable)
2330
+		//}
1796 2331
 
1797 2332
 		c.ServeSuccessJSON(map[string]interface{}{
1798 2333
 			"msg": "删除成功",
@@ -6067,3 +6602,13 @@ func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
6067 6602
 	}
6068 6603
 	return err
6069 6604
 }
6605
+
6606
+func (c *HisApiController) GetHisDoctorAdviceInfo() {
6607
+
6608
+	id, _ := c.GetInt64("id")
6609
+	advice, _ := service.GetHisDoctorAdviceInfo(id)
6610
+	c.ServeSuccessJSON(map[string]interface{}{
6611
+		"advice": advice,
6612
+	})
6613
+	return
6614
+}

+ 24 - 12
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -196,9 +196,10 @@ func (this *DialysisAPIController) Scheduals() {
196 196
 
197 197
 			list, err := service.MobileGetDialysisGoodsSix(orgID, date.Unix())
198 198
 
199
+			autoList, _ := service.GetMobileAutoReduce(orgID, date.Unix())
199 200
 			for _, item := range goodList {
200 201
 				for _, it := range list {
201
-					if item.RecordDate == it.RecordDate && it.PatientId == it.PatientId {
202
+					if item.RecordDate == it.RecordDate && item.PatientId == it.PatientId {
202 203
 						item.Children = append(item.Children, it)
203 204
 					}
204 205
 				}
@@ -209,6 +210,7 @@ func (this *DialysisAPIController) Scheduals() {
209 210
 				"scheduals": scheduals,
210 211
 				"project":   project,
211 212
 				"goodList":  goodList,
213
+				"autoList":  autoList,
212 214
 			})
213 215
 		}
214 216
 
@@ -231,17 +233,19 @@ func (this *DialysisAPIController) Scheduals() {
231 233
 
232 234
 		for _, item := range goodList {
233 235
 			for _, it := range list {
234
-				if item.RecordDate == it.RecordDate && it.PatientId == it.PatientId {
236
+				if item.RecordDate == it.RecordDate && item.PatientId == it.PatientId {
235 237
 					item.Children = append(item.Children, it)
236 238
 				}
237 239
 			}
238 240
 		}
241
+		autoList, _ := service.GetMobileAutoReduce(orgID, date.Unix())
239 242
 		this.ServeSuccessJSON(map[string]interface{}{
240 243
 			"scheduals": dat,
241 244
 			"redis":     "true",
242 245
 			"date":      schedualDate,
243 246
 			"project":   project,
244 247
 			"goodList":  goodList,
248
+			"autoList":  autoList,
245 249
 		})
246 250
 
247 251
 	}
@@ -567,6 +571,20 @@ func (this *DialysisAPIController) DialysisRecord() {
567 571
 		// 先走redis,没有走数据库
568 572
 		his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
569 573
 	}
574
+
575
+	//获取今日透析准备的数据
576
+	goodList, _ := service.MobileGetDialysisGoodsSeven(adminInfo.Org.Id, date.Unix())
577
+	list, _ := service.MobileGetDialysisGoodsSix(adminInfo.Org.Id, date.Unix())
578
+
579
+	autoList, _ := service.GetMobileAutoReduce(adminInfo.Org.Id, date.Unix())
580
+	for _, item := range goodList {
581
+		for _, it := range list {
582
+			if item.RecordDate == it.RecordDate && item.PatientId == it.PatientId {
583
+				item.Children = append(item.Children, it)
584
+			}
585
+		}
586
+	}
587
+
570 588
 	returnData := map[string]interface{}{
571 589
 		"patient":                        patient,
572 590
 		"schedual":                       schedual,
@@ -597,6 +615,8 @@ func (this *DialysisAPIController) DialysisRecord() {
597 615
 		"is_project_open_config":         is_project_open_config,
598 616
 		"project":                        projects,
599 617
 		"team_projects":                  team_projects,
618
+		"goodList":                       goodList,
619
+		"autoList":                       autoList,
600 620
 	}
601 621
 	this.ServeSuccessJSON(returnData)
602 622
 }
@@ -693,16 +713,6 @@ func (c *DialysisAPIController) PostAtreatmentInfo() {
693 713
 			"summary": summary,
694 714
 		})
695 715
 	} else { //修改
696
-		//if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
697
-		//	headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
698
-		//	if getPermissionErr != nil {
699
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
700
-		//		return
701
-		//	} else if headNursePermission == nil {
702
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
703
-		//		return
704
-		//	}
705
-		//}
706 716
 
707 717
 		summary.Creater = treatmentSummary.Creater
708 718
 		summary.CreatedTime = treatmentSummary.CreatedTime
@@ -4520,7 +4530,9 @@ func (c *DialysisAPIController) GetDialysisGoods() {
4520 4530
 		if patient_id != 0 {
4521 4531
 			for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
4522 4532
 				goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
4533
+
4523 4534
 				lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
4535
+				fmt.Println("GOOD333232323223322332232332232323322323", lastGoodUserDetial)
4524 4536
 				item.LastAutomaticReduceDetail = goodUser
4525 4537
 				item.LastDialysisBeforePrepare = lastGoodUserDetial
4526 4538
 				item.Project = project

+ 36 - 2
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -655,7 +655,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
655 655
 			theTime := toTime.Format("2006-01-02")
656 656
 			fmt.Println("theTIME", theTime)
657 657
 			keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
658
-			fmt.Println("keyFour323223323232323232", keyFour)
659 658
 			redis.Set(keyFour, "", time.Second)
660 659
 			keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
661 660
 			redis.Set(keySix, "", time.Second)
@@ -1031,6 +1030,41 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1031 1030
 					fmt.Println("数量一", prescribing_number_total)
1032 1031
 					fmt.Println("数量二", total)
1033 1032
 
1033
+					//查询该药品的医嘱记录
1034
+					//advicelist, _ := service.GetHisAdviceListByDrugId(advice.DrugId, advice.PatientId, advice.AdviceDate)
1035
+					//if(advicelist.ID > 0){
1036
+					//  //获取上一次的出库记录
1037
+					//  record, _ := service.GetDrugAutoReduceRecordOne(advice.DrugId, advice.PatientId, advice.AdviceDate)
1038
+					//  var out_count int64
1039
+					//  for _, res := range record {
1040
+					//    if(res.CountUnit == medical.MaxUnit){
1041
+					//      res.Count = res.Count * medical.MinNumber
1042
+					//    }
1043
+					//    if(res.CountUnit == medical.MinUnit){
1044
+					//      res.Count = res.Count
1045
+					//    }
1046
+					//    out_count += res.Count
1047
+					//  }
1048
+					//  if((prescribing_number_total - out_count) > 0){
1049
+					//
1050
+					//    if((prescribing_number_total - out_count) > total){
1051
+					//      c.ServeSuccessJSON(map[string]interface{}{
1052
+					//        "msg":    "2",
1053
+					//        "advice": advice,
1054
+					//        "ids":    ids,
1055
+					//      })
1056
+					//      return
1057
+					//
1058
+					//    }else{
1059
+					//      service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1060
+					//      break
1061
+					//    }
1062
+					//  }else{
1063
+					//    service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1064
+					//    break
1065
+					//  }
1066
+					//}
1067
+
1034 1068
 					if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
1035 1069
 						c.ServeSuccessJSON(map[string]interface{}{
1036 1070
 							"msg":    "3",
@@ -1049,8 +1083,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1049 1083
 					}
1050 1084
 					if prescribing_number_total <= total {
1051 1085
 						service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1052
-
1053 1086
 					}
1087
+
1054 1088
 				}
1055 1089
 			}
1056 1090
 			for _, item := range advices {

+ 35 - 32
controllers/schedule_api_controller.go View File

@@ -970,7 +970,7 @@ func (this *ScheduleApiController) ExportSchedule() {
970 970
 	end_time := dataBody["end_time"].(string)
971 971
 
972 972
 	delete_type := int64(dataBody["delete_type"].(float64))
973
-
973
+	fmt.Println("delete_type", delete_type)
974 974
 	timeLayout := "2006-01-02"
975 975
 	loc, _ := time.LoadLocation("Local")
976 976
 	theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
@@ -1413,43 +1413,46 @@ func (this *ScheduleApiController) ExportSchedule() {
1413 1413
 		errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
1414 1414
 
1415 1415
 		if len(schedules) > 0 {
1416
-			//schedule_date := time.Now().Format("2006-01-02")
1417
-			//date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
1418
-			//clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
1419
-			//err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
1416
+			schedule_date := time.Now().Format("2006-01-02")
1417
+			date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
1418
+			clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
1419
+			//	err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
1420 1420
 			if err == nil {
1421 1421
 				//清除该机构的排班
1422
-				if delete_type == 1 {
1423
-					service.ModeScheduleByTimeOne(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
1424
-				}
1425
-				if delete_type == 0 {
1426
-					service.ModeScheduleByTime(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
1427
-				}
1422
+				//if delete_type == 1 {
1423
+				//  service.ModeScheduleByTimeOne(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
1424
+				//}
1425
+				//if delete_type == 0 {
1426
+				//  service.ModeScheduleByTime(theTimeStart.Unix(), theTimeEnd.Unix(), this.GetAdminUserInfo().CurrentOrgId)
1427
+				//}
1428 1428
 
1429 1429
 				for _, item := range schedules {
1430
-					//删除当天的日期排班
1431
-					/*service.DeleteScheduleExist(item.ScheduleDate, item.UserOrgId)*/
1432
-					//查找当天日期是否存在
1433
-					_, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
1434
-					if errcode == gorm.ErrRecordNotFound {
1435
-						//清除当天该床位已有的患者
1436
-						// service.ModeFyScheduleById(item.ScheduleDate,item.BedId,item.ScheduleType)
1437
-						service.CreateSchedule(item)
1438
-					} else if errcode == nil {
1439
-						schedule := models.XtSchedule{
1440
-							PartitionId:  item.PartitionId,
1441
-							BedId:        item.BedId,
1442
-							PatientId:    item.PatientId,
1443
-							ScheduleDate: item.ScheduleDate,
1444
-							ScheduleType: item.ScheduleType,
1445
-							ScheduleWeek: item.ScheduleWeek,
1446
-							ModeId:       item.ModeId,
1447
-							Status:       1,
1430
+					// fmt.Println("clear_schedule_date3232232332232332232323",clear_schedule_date)
1431
+					if item.ScheduleDate > clear_schedule_date {
1432
+						//删除当天的以后日期排班
1433
+						// service.DeleteScheduleExist(item.ScheduleDate, item.UserOrgId)
1434
+						//查找当天日期是否存在
1435
+						_, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
1436
+						if errcode == gorm.ErrRecordNotFound {
1437
+
1438
+							//清除当天该床位已有的患者
1439
+							service.ModeFyScheduleById(item.ScheduleDate, item.BedId, item.ScheduleType)
1440
+							service.CreateSchedule(item)
1441
+						} else if errcode == nil {
1442
+							schedule := models.XtSchedule{
1443
+								PartitionId:  item.PartitionId,
1444
+								BedId:        item.BedId,
1445
+								PatientId:    item.PatientId,
1446
+								ScheduleDate: item.ScheduleDate,
1447
+								ScheduleType: item.ScheduleType,
1448
+								ScheduleWeek: item.ScheduleWeek,
1449
+								ModeId:       item.ModeId,
1450
+								Status:       1,
1451
+							}
1452
+
1453
+							service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
1448 1454
 						}
1449
-
1450
-						service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
1451 1455
 					}
1452
-
1453 1456
 				}
1454 1457
 
1455 1458
 				log := models.ExportLog{

+ 15 - 14
models/dialysis.go View File

@@ -1013,20 +1013,21 @@ type UserAdminRoles struct {
1013 1013
 }
1014 1014
 
1015 1015
 type DialysisBeforePrepare struct {
1016
-	ID           int64  `gorm:"column:id" json:"id" form:"id"`
1017
-	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1018
-	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1019
-	RecordDate   int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
1020
-	GoodId       int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
1021
-	GoodTypeId   int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
1022
-	Count        int64  `gorm:"column:count" json:"count" form:"count"`
1023
-	Ctime        int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
1024
-	Mtime        int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
1025
-	Creater      int64  `gorm:"column:creater" json:"creater" form:"creater"`
1026
-	Modifier     int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
1027
-	Status       int64  `gorm:"column:status" json:"status" form:"status"`
1028
-	CommdityCode string `gorm:"column:commdity_code" json:"commdity_code" form:"commdity_code"`
1029
-	NewCount     int64  `gorm:"column:new_count" json:"new_count" form:"new_count"`
1016
+	ID           int64                    `gorm:"column:id" json:"id" form:"id"`
1017
+	UserOrgId    int64                    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1018
+	PatientId    int64                    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1019
+	RecordDate   int64                    `gorm:"column:record_date" json:"record_date" form:"record_date"`
1020
+	GoodId       int64                    `gorm:"column:good_id" json:"good_id" form:"good_id"`
1021
+	GoodTypeId   int64                    `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
1022
+	Count        int64                    `gorm:"column:count" json:"count" form:"count"`
1023
+	Ctime        int64                    `gorm:"column:ctime" json:"ctime" form:"ctime"`
1024
+	Mtime        int64                    `gorm:"column:mtime" json:"mtime" form:"mtime"`
1025
+	Creater      int64                    `gorm:"column:creater" json:"creater" form:"creater"`
1026
+	Modifier     int64                    `gorm:"column:modifier" json:"modifier" form:"modifier"`
1027
+	Status       int64                    `gorm:"column:status" json:"status" form:"status"`
1028
+	CommdityCode string                   `gorm:"column:commdity_code" json:"commdity_code" form:"commdity_code"`
1029
+	NewCount     int64                    `gorm:"column:new_count" json:"new_count" form:"new_count"`
1030
+	Children     []*DialysisBeforePrepare `gorm:"column:children" json:"children" form:"children"`
1030 1031
 }
1031 1032
 
1032 1033
 func (DialysisBeforePrepare) TableName() string {

+ 4 - 0
models/drug_stock.go View File

@@ -137,6 +137,7 @@ type DrugWarehouseOutInfo struct {
137 137
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
138 138
 	PatientId               int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
139 139
 	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
140
+	AdviceId                int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
140 141
 }
141 142
 
142 143
 func (DrugWarehouseOutInfo) TableName() string {
@@ -259,6 +260,8 @@ type DrugAutomaticReduceDetail struct {
259 260
 	DrugId                  int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
260 261
 	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
261 262
 	CountUnit               string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
263
+	WarehouseInfoId         int64  `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
264
+	AdviceId                int64  `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
262 265
 }
263 266
 
264 267
 func (DrugAutomaticReduceDetail) TableName() string {
@@ -367,6 +370,7 @@ type DrugFlow struct {
367 370
 	LastStockMinNumber      int64                `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
368 371
 	DrugWarehouseInfo       []*DrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:DrugId" `
369 372
 	BaseDrugLib             BaseDrugLib          `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
373
+	AdviceId                int64                `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
370 374
 }
371 375
 
372 376
 func (DrugFlow) TableName() string {

+ 1 - 1
service/gobal_config_service.go View File

@@ -794,7 +794,7 @@ func GetAllCountList(startime int64, endtime int64, orgid int64) (info []*models
794 794
 
795 795
 func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
796 796
 
797
-	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
797
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1 and x.count>0")
798 798
 	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
799 799
 	fmt.Println(table)
800 800
 	if orgid > 0 {

+ 8 - 0
service/his_service.go View File

@@ -2224,3 +2224,11 @@ func CreateHisLabelRecord(label *models.HisLabelPrintInfo) error {
2224 2224
 	err := writeDb.Save(&label).Error
2225 2225
 	return err
2226 2226
 }
2227
+
2228
+func GetHisDoctorAdviceInfo(id int64) (models.HisDoctorAdviceInfo, error) {
2229
+
2230
+	info := models.HisDoctorAdviceInfo{}
2231
+
2232
+	err := readDb.Model(&info).Where("id = ? and status = 1", id).Preload("Drug", "status = 1").Find(&info).Error
2233
+	return info, err
2234
+}

+ 12 - 0
service/manage_center_service.go View File

@@ -185,6 +185,18 @@ func GetDrugAutoWarehouseOut(patient_id int64, advicedate int64, drugid int64) (
185 185
 	return &detail, nil
186 186
 }
187 187
 
188
+func GetDrugAutoWarehouseOutSeven(patient_id int64, advicedate int64, drugid int64, adviceid int64) (*models.DrugWarehouseOutInfo, error) {
189
+	detail := models.DrugWarehouseOutInfo{}
190
+	err := XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&detail).Error
191
+	if err == gorm.ErrRecordNotFound {
192
+		return nil, err
193
+	}
194
+	if err != nil {
195
+		return nil, err
196
+	}
197
+	return &detail, nil
198
+}
199
+
188 200
 func UpdateDrugWarehouse(id int64, info models.DrugWarehouseInfo) error {
189 201
 	err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
190 202
 	return err

+ 7 - 1
service/mobile_dialysis_service.go View File

@@ -2758,7 +2758,7 @@ func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goo
2758 2758
 
2759 2759
 	err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
2760 2760
 	if len(Id) > 0 {
2761
-
2761
+		fmt.Println("ids232323223322233233233322332", Id)
2762 2762
 		err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Find(&goodUser).Error
2763 2763
 	}
2764 2764
 	return
@@ -3610,3 +3610,9 @@ func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*mode
3610 3610
 	err = readDb.Where("user_org_id = ? AND status=1 AND record_date < ? AND count > 0", orgID, scheduleDate).Select("patient_id,good_id,record_date").Find(&prepare).Error
3611 3611
 	return prepare, err
3612 3612
 }
3613
+
3614
+func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
3615
+
3616
+	err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
3617
+	return auto, err
3618
+}

+ 208 - 6
service/stock_service.go View File

@@ -638,6 +638,26 @@ func CreateDrugFlowOne(flow models.DrugFlow) error {
638 638
 	return err
639 639
 }
640 640
 
641
+func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64) (models.DrugAutomaticReduceDetail, error) {
642
+
643
+	detail := models.DrugAutomaticReduceDetail{}
644
+	err := XTWriteDB().Model(&detail).Where("patient_id = ? and record_time = ? and drug_id = ? and status= 1 and advice_id =?", patientid, recorddate, drugid, advice_id).Updates(map[string]interface{}{"status": 0}).Error
645
+	err = XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("patient_id =? and sys_record_time =? and drug_id = ? and status = 1 and advice_id =?", patientid, recorddate, drugid, advice_id).Updates(map[string]interface{}{"status": 0}).Error
646
+	return detail, err
647
+}
648
+
649
+func UpdateDrugFlowTens(patientid int64, warehouse_out_number string, drug_id int64, advice_id int64) (models.DrugFlow, error) {
650
+	flow := models.DrugFlow{}
651
+	err := XTWriteDB().Model(&flow).Where("patient_id =? and warehouse_out_order_number = ? and drug_id = ? and status = 1 and advice_id =?", patientid, warehouse_out_number, drug_id, advice_id).Updates(map[string]interface{}{"status": 0}).Error
652
+	return flow, err
653
+}
654
+
655
+func UpdateDrugFlowTen(patientid int64, warehouse_out_number string, drug_id int64) (models.DrugFlow, error) {
656
+	flow := models.DrugFlow{}
657
+	err := XTWriteDB().Model(&flow).Where("patient_id =? and warehouse_out_order_number = ? and drug_id = ? and status = 1", patientid, warehouse_out_number, drug_id).Updates(map[string]interface{}{"status": 0}).Error
658
+	return flow, err
659
+}
660
+
641 661
 func CreateDrugFlowTwo(flow *models.DrugFlow) error {
642 662
 
643 663
 	err := XTWriteDB().Create(&flow).Error
@@ -2524,7 +2544,7 @@ func FindStockInDetailList(orgId int64, page int64, limit int64, startTime int64
2524 2544
 		//db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_warehouse.manufacturer")
2525 2545
 		//db = db.Where(" sgj_user_admin_role.user_name LIKE ?", likeKey).Group("xt_warehouse_info.id")
2526 2546
 
2527
-		db = db.Where(" sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_info.warehousing_order LIKE ? OR xt_good_information.specification_name LIKE ?", likeKey, likeKey, likeKey).Group("xt_warehouse_info.id")
2547
+		db = db.Where(" sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_info.warehousing_order LIKE ? OR xt_good_information.specification_name LIKE ?  OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_warehouse_info.id")
2528 2548
 	} else {
2529 2549
 		db = db.Joins("join xt_warehouse on xt_warehouse.id = xt_warehouse_info.warehousing_id AND xt_warehouse.warehousing_time >=? AND xt_warehouse.warehousing_time<= ? AND xt_warehouse.status = 1 AND xt_warehouse.org_id = ?", startTime, endTime, orgId)
2530 2550
 	}
@@ -2593,7 +2613,7 @@ func FindStockOutDetailList(orgId int64, page int64, limit int64, startTime int6
2593 2613
 		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse_out.creater")
2594 2614
 		db = db.Joins("join xt_good_information on xt_good_information.id = xt_warehouse_out_info.good_id")
2595 2615
 
2596
-		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out_info.warehouse_out_order_number LIKE ?  OR xt_good_information.specification_name LIKE ?", likeKey, likeKey, likeKey).Group("xt_warehouse_out_info.id")
2616
+		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out_info.warehouse_out_order_number LIKE ?  OR xt_good_information.specification_name LIKE ?  OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_warehouse_out_info.id")
2597 2617
 	} else {
2598 2618
 		db = db.Joins("join xt_warehouse_out on xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.org_id = ?", startTime, endTime, orgId)
2599 2619
 	}
@@ -2660,7 +2680,7 @@ func FindSalesReturnDetailList(orgId int64, page int64, limit int64, startTime i
2660 2680
 		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_sales_return.creater")
2661 2681
 		db = db.Joins("join xt_good_information on xt_good_information.id = xt_sales_return_info.good_id")
2662 2682
 
2663
-		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_sales_return_info.order_number LIKE ? OR xt_good_information.specification_name LIKE ?", likeKey, likeKey, likeKey).Group("xt_sales_return_info.id")
2683
+		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_sales_return_info.order_number LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_sales_return_info.id")
2664 2684
 	} else {
2665 2685
 		db = db.Joins("join xt_sales_return on xt_sales_return.id = xt_sales_return_info.sales_return_id AND xt_sales_return.return_time >=? AND xt_sales_return.return_time<= ? AND xt_sales_return.status = 1 AND xt_sales_return.org_id = ?", startTime, endTime, orgId)
2666 2686
 	}
@@ -2721,7 +2741,7 @@ func FindCancelDetailList(orgId int64, page int64, limit int64, startTime int64,
2721 2741
 		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_cancel_stock.creater")
2722 2742
 		db = db.Joins("join xt_good_information on xt_good_information.id = xt_cancel_stock_info.good_id")
2723 2743
 
2724
-		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_cancel_stock_info.order_number LIKE ? OR xt_good_information.specification_name LIKE ?", likeKey, likeKey, likeKey).Group("xt_cancel_stock_info.id")
2744
+		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_cancel_stock_info.order_number LIKE ? OR xt_good_information.specification_name LIKE ? OR xt_good_information.good_name LIKE ?", likeKey, likeKey, likeKey, likeKey).Group("xt_cancel_stock_info.id")
2725 2745
 	} else {
2726 2746
 		db = db.Joins("join xt_cancel_stock on xt_cancel_stock.id = xt_cancel_stock_info.cancel_stock_id AND xt_cancel_stock.return_time >=? AND xt_cancel_stock.return_time<= ? ", startTime, endTime)
2727 2747
 	}
@@ -3505,6 +3525,39 @@ func GetAutoDialysisBefor(goodid int64, goodtypeid int64, patientid int64, orgid
3505 3525
 	return &autoreduece, nil
3506 3526
 }
3507 3527
 
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
3531
+	return detail, err
3532
+}
3533
+
3534
+func GetHisProjectPrescriptionByPatientId(patientid int64, recorddate int64) (project []*models.HisPrescriptionProject, err error) {
3535
+
3536
+	err = XTReadDB().Model(&project).Where("patient_id = ? and record_date = ? and status =1", patientid, recorddate).Find(&project).Error
3537
+	return project, err
3538
+}
3539
+
3540
+func GetAllAutoRecordByPatient(patientid int64, recorddate int64) (auto []*models.WarehouseOutInfo, err error) {
3541
+
3542
+	err = XTReadDB().Model(&auto).Where("patient_id = ? and sys_record_time = ? and status = 1", patientid, recorddate).Find(&auto).Error
3543
+	return auto, err
3544
+}
3545
+
3546
+func ModefyWarehouseInfo(count int64, id int64) error {
3547
+
3548
+	err := XTWriteDB().Model(models.WarehousingInfo{}).Where(" id =? and status = 1", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
3549
+	return err
3550
+}
3551
+
3552
+func DeleteAutoWarehouse(patient_id int64, record_time int64) error {
3553
+
3554
+	err := XTWriteDB().Model(models.AutomaticReduceDetail{}).Where("patient_id = ? and record_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3555
+	err = XTWriteDB().Model(models.DialysisBeforePrepare{}).Where("patient_id = ? and record_date = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3556
+	err = XTWriteDB().Model(models.WarehouseOutInfo{}).Where("patient_id = ? and sys_record_time =? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3557
+	err = XTWriteDB().Model(models.VmStockFlow{}).Where("patient_id = ? and system_time = ? and status = 1", patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
3558
+	return err
3559
+}
3560
+
3508 3561
 func FindGoodInfoByIdTwo(id int64) (goodInfo models.GoodInfo, err error) {
3509 3562
 	err = readDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1", id).First(&goodInfo).Error
3510 3563
 	return
@@ -4492,7 +4545,7 @@ func GetStockGoodCount(good_id int64) (models.WarehousingInfo, error) {
4492 4545
 func GetDrugFlow(drugid int64, orgid int64, limit int64, page int64, startTime int64, endTime int64, stock_type int64) (drug_flow []*models.DrugFlow, total int64, err error) {
4493 4546
 
4494 4547
 	offset := (page - 1) * limit
4495
-	db := XTReadDB().Model(drug_flow)
4548
+	db := XTReadDB().Model(drug_flow).Where("status = 1")
4496 4549
 	if drugid > 0 {
4497 4550
 		db = db.Where("drug_id = ?", drugid)
4498 4551
 	}
@@ -4550,6 +4603,13 @@ func GetDrugWarehouseOutInfoIsExit(drug_id int64, patient_id int64, recordtime i
4550 4603
 	return &outInfo, nil
4551 4604
 }
4552 4605
 
4606
+func GetDrugWarehouseOutInfoIsExitOne(drug_id int64, patient_id int64, recordtime int64) (outInfo []*models.DrugWarehouseOutInfo, err error) {
4607
+
4608
+	err = XTReadDB().Model(&outInfo).Where("drug_id = ? and patient_id = ? and status = 1 and sys_record_time = ?", drug_id, patient_id, recordtime).Find(&outInfo).Error
4609
+
4610
+	return outInfo, err
4611
+}
4612
+
4553 4613
 func UpdatedDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo, drug_id int64, patient_id int64, record_date int64, orgid int64) error {
4554 4614
 
4555 4615
 	outInfo := models.DrugWarehouseOutInfo{}
@@ -4609,6 +4669,54 @@ func GetDrugWarehouseInfoPrescription(drugid int64, orgid int64) (info []*models
4609 4669
 	return info, err
4610 4670
 }
4611 4671
 
4672
+func GetHisAdviceListByDrugId(drugid int64, patient_id int64, advice_date int64) (models.HisDoctorAdviceInfo, error) {
4673
+
4674
+	info := models.HisDoctorAdviceInfo{}
4675
+	err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and advice_date = ? and status = 1", drugid, patient_id, advice_date).Find(&info).Error
4676
+	return info, err
4677
+}
4678
+
4679
+func GetHisAdviceListByDrugIdEight(drugid int64, patient_id int64, advice_date int64, advice_id int64) (models.HisDoctorAdviceInfo, error) {
4680
+
4681
+	info := models.HisDoctorAdviceInfo{}
4682
+	err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and advice_date = ? and status = 1 and id =?", drugid, patient_id, advice_date, advice_id).Find(&info).Error
4683
+	return info, err
4684
+}
4685
+
4686
+func GetLastDrugWarehouseOutByDrugId(drugid int64, patient_id int64, advice_date int64) (models.DrugAutomaticReduceDetail, error) {
4687
+	detail := models.DrugAutomaticReduceDetail{}
4688
+	err := XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1", drugid, patient_id, advice_date).Last(&detail).Error
4689
+	return detail, err
4690
+}
4691
+
4692
+func ModefyDrugByWarehouseInfo(id int64, stock_max_number int64) error {
4693
+
4694
+	err := XTWriteDB().Model(models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", stock_max_number)).Error
4695
+	return err
4696
+}
4697
+
4698
+func ModefyDrugByWarehouseInfoOne(id int64, stock_min_number int64) error {
4699
+
4700
+	err := XTWriteDB().Model(models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", stock_min_number)).Error
4701
+	return err
4702
+}
4703
+
4704
+func DeleteDrugAutoWarehouse(drugid int64, patient_id int64, record_time int64) error {
4705
+
4706
+	err := XTWriteDB().Model(models.DrugAutomaticReduceDetail{}).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1", drugid, patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
4707
+	err = XTWriteDB().Model(models.DrugWarehouseOutInfo{}).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1", drugid, patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
4708
+	err = XTWriteDB().Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1", drugid, patient_id, record_time).Updates(map[string]interface{}{"status": 0}).Error
4709
+	return err
4710
+}
4711
+
4712
+func DeleteDrugAutoWarehouseSeven(drugid int64, patient_id int64, record_time int64, advice_id int64) error {
4713
+
4714
+	err := XTWriteDB().Model(models.DrugAutomaticReduceDetail{}).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
4715
+	err = XTWriteDB().Model(models.DrugWarehouseOutInfo{}).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
4716
+	err = XTWriteDB().Model(models.DrugFlow{}).Where("drug_id = ? and patient_id = ? and system_time = ? and status = 1 and advice_id = ?", drugid, patient_id, record_time, advice_id).Updates(map[string]interface{}{"status": 0}).Error
4717
+	return err
4718
+}
4719
+
4612 4720
 func GetDrugWarehouseInfoById(id int64) (models.XtDrugWarehouseInfo, error) {
4613 4721
 
4614 4722
 	info := models.XtDrugWarehouseInfo{}
@@ -4772,7 +4880,7 @@ func UpdateDrugFlow(flow models.DrugFlow, drugid int64, warehousing_id int64) er
4772 4880
 	return err
4773 4881
 }
4774 4882
 
4775
-func UpdateDrugFlowTen(flow models.DrugFlow, drugid int64, warehousing_id int64) error {
4883
+func UpdateDrugFlowNight(flow models.DrugFlow, drugid int64, warehousing_id int64) error {
4776 4884
 
4777 4885
 	drugFlow := models.DrugFlow{}
4778 4886
 	err := XTWriteDB().Model(&drugFlow).Where("drug_id = ? and warehousing_id= ? and status = 1", drugid, warehousing_id).Updates(map[string]interface{}{"count": flow.Count, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "number": flow.Number, "batch_number": flow.BatchNumber, "price": flow.Price}).Error
@@ -5389,3 +5497,97 @@ func GetLastWarehoseByGoodId(goodid int64, patient_id int64, record_date int64)
5389 5497
 
5390 5498
 	return info, err
5391 5499
 }
5500
+
5501
+func ModifyDrugWarehouseOutInfo(info models.DrugWarehouseOutInfo, drugid int64, patientid int64, sys_record_time int64) error {
5502
+
5503
+	err := XTWriteDB().Model(&info).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1", drugid, patientid, sys_record_time).Updates(map[string]interface{}{"count": info.Count, "count_unit": info.CountUnit}).Error
5504
+	return err
5505
+}
5506
+
5507
+func ModifyDrugWarehouseOutInfoOne(info models.DrugWarehouseOutInfo, drugid int64, patientid int64, sys_record_time int64, warehouse_info_id int64) error {
5508
+
5509
+	err := XTWriteDB().Model(&info).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1 and warehouse_info_id = ?", drugid, patientid, sys_record_time, warehouse_info_id).Updates(map[string]interface{}{"count": info.Count, "count_unit": info.CountUnit}).Error
5510
+	return err
5511
+}
5512
+
5513
+func GetDrugWarehouseOutInfoByWarehosueId(drugid int64, patientid int64, recorddate int64, warehosueinfoid int64) (*models.DrugWarehouseOutInfo, error) {
5514
+	info := models.DrugWarehouseOutInfo{}
5515
+	err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and sys_record_time = ? and warehouse_info_id  = ? and status = 1", drugid, patientid, recorddate, warehosueinfoid).Find(&info).Error
5516
+	if err == gorm.ErrRecordNotFound {
5517
+		return nil, err
5518
+	}
5519
+	if err != nil {
5520
+		return nil, err
5521
+	}
5522
+	return &info, nil
5523
+}
5524
+
5525
+func GetDrugFlowRecord(warehouse_out_order_number string, drugid int64, patientid int64) (*models.DrugFlow, error) {
5526
+
5527
+	drugFlow := models.DrugFlow{}
5528
+
5529
+	err := XTReadDB().Where("warehouse_out_order_number = ? and drug_id =? and patient_id = ? and status = 1", warehouse_out_order_number, drugid, patientid).Find(&drugFlow).Error
5530
+
5531
+	if err == gorm.ErrRecordNotFound {
5532
+		return nil, err
5533
+	}
5534
+	if err != nil {
5535
+		return nil, err
5536
+	}
5537
+	return &drugFlow, nil
5538
+}
5539
+
5540
+func ModifyDrugFlow(flow models.DrugFlow, warehouse_out_order_number string, drugid int64, patient_id int64) error {
5541
+
5542
+	err := XTWriteDB().Model(&flow).Where("warehouse_out_order_number = ? and drug_id = ? and patient_id = ? and status = 1", warehouse_out_order_number, drugid, patient_id).Updates(map[string]interface{}{"count": flow.Count, "max_unit": flow.MaxUnit}).Error
5543
+	return err
5544
+}
5545
+
5546
+func ModifyDrugFlowOne(flow models.DrugFlow, warehouse_out_order_number string, drugid int64, patient_id int64, warehousing_detail_id int64) error {
5547
+
5548
+	err := XTWriteDB().Model(&flow).Where("warehouse_out_order_number = ? and drug_id = ? and patient_id = ? and status = 1 and warehousing_detail_id = ?", warehouse_out_order_number, drugid, patient_id, warehousing_detail_id).Updates(map[string]interface{}{"count": flow.Count, "max_unit": flow.MaxUnit}).Error
5549
+	return err
5550
+}
5551
+
5552
+func GetDrugAutoReduceRecordOne(drugid int64, patientid int64, recorddate int64) (detail []*models.DrugAutomaticReduceDetail, err error) {
5553
+
5554
+	err = XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time  = ? and status = 1", drugid, patientid, recorddate).Find(&detail).Error
5555
+
5556
+	return detail, err
5557
+}
5558
+
5559
+func GetDrugAutoReduceRecord(drugid int64, patientid int64, recorddate int64) (*models.DrugAutomaticReduceDetail, error) {
5560
+
5561
+	detail := models.DrugAutomaticReduceDetail{}
5562
+
5563
+	err := XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time  = ? and status = 1", drugid, patientid, recorddate).Find(&detail).Error
5564
+
5565
+	if err == gorm.ErrRecordNotFound {
5566
+		return nil, err
5567
+	}
5568
+	if err != nil {
5569
+		return nil, err
5570
+	}
5571
+	return &detail, nil
5572
+}
5573
+
5574
+func ModifyAutoMaticReduce(auto models.DrugAutomaticReduceDetail, patientid int64, recordate int64, drugid int64) error {
5575
+
5576
+	err := XTWriteDB().Model(&auto).Where("patient_id = ? and record_time = ? and drug_id = ? and status = 1", patientid, recordate, drugid).Updates(map[string]interface{}{"count": auto.Count, "count_unit": auto.CountUnit}).Error
5577
+	return err
5578
+}
5579
+
5580
+func ModifyAutoMaticReduceOne(auto models.DrugAutomaticReduceDetail, patientid int64, recordate int64, drugid int64, warehouse_info_id int64) error {
5581
+
5582
+	err := XTWriteDB().Model(&auto).Where("patient_id = ? and record_time = ? and drug_id = ? and status = 1 and warehouse_info_id = ?", patientid, recordate, drugid, warehouse_info_id).Updates(map[string]interface{}{"count": auto.Count, "count_unit": auto.CountUnit}).Error
5583
+	return err
5584
+}
5585
+
5586
+func ModifyDrugWarehouse(id int64, stock_max_number int64, stock_min_number int64) (models.DrugWarehouseInfo, error) {
5587
+
5588
+	info := models.DrugWarehouseInfo{}
5589
+
5590
+	err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", stock_max_number)).Error
5591
+	err = XTWriteDB().Model(&info).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", stock_min_number)).Error
5592
+	return info, err
5593
+}

+ 249 - 41
service/warhouse_service.go View File

@@ -176,6 +176,8 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
176 176
 			Creator:                 advice.ExecutionStaff,
177 177
 			IsSys:                   1,
178 178
 			PatientId:               advice.PatientId,
179
+			SystemTime:              advice.AdviceDate,
180
+			WarehousingDetailId:     warehouse.ID,
179 181
 		}
180 182
 
181 183
 		CreateDrugFlowOne(drugflow)
@@ -207,6 +209,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
207 209
 			DrugId:                  advice.DrugId,
208 210
 			Count:                   count,
209 211
 			CountUnit:               advice.PrescribingNumberUnit,
212
+			WarehouseInfoId:         warehouse.ID,
210 213
 		}
211 214
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
212 215
 		if errTwo != nil {
@@ -287,16 +290,6 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
287 290
 		if errOne != nil {
288 291
 			return errOne
289 292
 		}
290
-		//查询是否存在数据
291
-		//_, errcodes := GetDrugWarehouseOutInfoIsExit(advice.DrugId, advice.PatientId, advice.RecordDate)
292
-		//if errcodes == gorm.ErrRecordNotFound {
293
-		//	errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
294
-		//	if errOne != nil {
295
-		//		return errOne
296
-		//	}
297
-		//} else if errcodes == nil {
298
-		//	UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
299
-		//}
300 293
 
301 294
 		details := &models.DrugAutomaticReduceDetail{
302 295
 			WarehouseOutId:          warehouseout.ID,
@@ -310,6 +303,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
310 303
 			DrugId:                  advice.DrugId,
311 304
 			Count:                   deliver_number,
312 305
 			CountUnit:               drup.MinUnit,
306
+			WarehouseInfoId:         warehouse.ID,
313 307
 		}
314 308
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
315 309
 		if errTwo != nil {
@@ -373,6 +367,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
373 367
 			Creator:                 advice.ExecutionStaff,
374 368
 			IsSys:                   1,
375 369
 			PatientId:               advice.PatientId,
370
+			WarehousingDetailId:     warehouse.ID,
376 371
 		}
377 372
 
378 373
 		CreateDrugFlowOne(drugflow)
@@ -442,7 +437,6 @@ func HisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdvice
442 437
 		drup, _ := FindBaseDrugLibRecord(orgID, advice.DrugId)
443 438
 		if drup.ID > 0 {
444 439
 			prescribingNumber := advice.PrescribingNumber
445
-
446 440
 			HisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice)
447 441
 
448 442
 		} else {
@@ -524,6 +518,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
524 518
 			PatientId:               advice.PatientId,
525 519
 			WarehouseInfoId:         warehouse.ID,
526 520
 			Count:                   deliver_number,
521
+			AdviceId:                advice.ID,
527 522
 		}
528 523
 
529 524
 		drugflow := models.DrugFlow{
@@ -547,6 +542,9 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
547 542
 			Creator:                 advice.ExecutionStaff,
548 543
 			IsSys:                   1,
549 544
 			PatientId:               advice.PatientId,
545
+			SystemTime:              advice.AdviceDate,
546
+			WarehousingDetailId:     warehouse.ID,
547
+			AdviceId:                advice.ID,
550 548
 		}
551 549
 
552 550
 		CreateDrugFlowOne(drugflow)
@@ -555,16 +553,6 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
555 553
 		if errOne != nil {
556 554
 			return errOne
557 555
 		}
558
-		//查询是否存在数据
559
-		//_, errcodes := GetDrugWarehouseOutInfoIsExit(advice.DrugId, advice.PatientId, advice.RecordDate)
560
-		//if errcodes == gorm.ErrRecordNotFound {
561
-		//	errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
562
-		//	if errOne != nil {
563
-		//		return errOne
564
-		//	}
565
-		//} else if errcodes == nil {
566
-		//	UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
567
-		//}
568 556
 
569 557
 		details := &models.DrugAutomaticReduceDetail{
570 558
 			WarehouseOutId:          warehouseout.ID,
@@ -578,6 +566,8 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
578 566
 			DrugId:                  advice.DrugId,
579 567
 			Count:                   deliver_number,
580 568
 			CountUnit:               drup.MinUnit,
569
+			WarehouseInfoId:         warehouse.ID,
570
+			AdviceId:                advice.ID,
581 571
 		}
582 572
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
583 573
 		if errTwo != nil {
@@ -656,6 +646,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
656 646
 			WarehouseInfoId:         warehouse.ID,
657 647
 			Count:                   stock_number,
658 648
 			CountUnit:               drup.MinUnit,
649
+			AdviceId:                advice.ID,
659 650
 		}
660 651
 
661 652
 		drugflow := models.DrugFlow{
@@ -679,6 +670,9 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
679 670
 			Creator:                 advice.ExecutionStaff,
680 671
 			IsSys:                   1,
681 672
 			PatientId:               advice.PatientId,
673
+			SystemTime:              advice.AdviceDate,
674
+			WarehousingDetailId:     warehouse.ID,
675
+			AdviceId:                advice.ID,
682 676
 		}
683 677
 
684 678
 		CreateDrugFlowOne(drugflow)
@@ -700,6 +694,8 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
700 694
 			DrugId:                  advice.DrugId,
701 695
 			Count:                   stock_number,
702 696
 			CountUnit:               drup.MinUnit,
697
+			WarehouseInfoId:         warehouse.ID,
698
+			AdviceId:                advice.ID,
703 699
 		}
704 700
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
705 701
 		if errTwo != nil {
@@ -806,6 +802,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
806 802
 			Price:                   advice.Price,
807 803
 			WarehouseInfoId:         warehouse.ID,
808 804
 			CountUnit:               drup.MinUnit,
805
+			AdviceId:                advice.ID,
809 806
 		}
810 807
 
811 808
 		warehouseOutInfo.Count = prescribingNumber
@@ -838,6 +835,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
838 835
 			Creator:                 0,
839 836
 			IsSys:                   0,
840 837
 			WarehouseOutDetailId:    drugWareInfo.ID,
838
+			AdviceId:                advice.ID,
841 839
 		}
842 840
 
843 841
 		CreateDrugFlowOne(drugflow)
@@ -901,6 +899,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
901 899
 			Price:                   advice.Price,
902 900
 			WarehouseInfoId:         warehouse.ID,
903 901
 			CountUnit:               drup.MinUnit,
902
+			AdviceId:                advice.ID,
904 903
 		}
905 904
 		warehouseOutInfo.Count = prescribingNumber
906 905
 
@@ -932,6 +931,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
932 931
 			Creator:                 0,
933 932
 			IsSys:                   0,
934 933
 			WarehouseOutDetailId:    drugWareInfo.ID,
934
+			AdviceId:                advice.ID,
935 935
 		}
936 936
 		CreateDrugFlowOne(drugflow)
937 937
 		// 出库完成后,要将该批次库存清零
@@ -1985,6 +1985,7 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
1985 1985
 			Creator:                 advice.ExecutionStaff,
1986 1986
 			IsSys:                   1,
1987 1987
 			PatientId:               advice.PatientId,
1988
+			WarehousingDetailId:     warehouse.ID,
1988 1989
 		}
1989 1990
 
1990 1991
 		CreateDrugFlowOne(drugflow)
@@ -2014,6 +2015,7 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
2014 2015
 			DrugId:                  advice.DrugId,
2015 2016
 			Count:                   count,
2016 2017
 			CountUnit:               advice.PrescribingNumberUnit,
2018
+			WarehouseInfoId:         warehouse.ID,
2017 2019
 		}
2018 2020
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
2019 2021
 		if errTwo != nil {
@@ -2111,6 +2113,7 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
2111 2113
 			DrugId:                  advice.DrugId,
2112 2114
 			Count:                   deliver_number,
2113 2115
 			CountUnit:               drup.MinUnit,
2116
+			WarehouseInfoId:         warehouse.ID,
2114 2117
 		}
2115 2118
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
2116 2119
 		if errTwo != nil {
@@ -2178,6 +2181,7 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
2178 2181
 			Creator:                 advice.ExecutionStaff,
2179 2182
 			IsSys:                   1,
2180 2183
 			PatientId:               advice.PatientId,
2184
+			WarehousingDetailId:     warehouse.ID,
2181 2185
 		}
2182 2186
 
2183 2187
 		CreateDrugFlowOne(drugflow)
@@ -2285,6 +2289,8 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2285 2289
 			Creator:                 advice.ExecutionStaff,
2286 2290
 			IsSys:                   1,
2287 2291
 			PatientId:               advice.PatientId,
2292
+			SystemTime:              advice.RecordDate,
2293
+			WarehousingDetailId:     warehouse.ID,
2288 2294
 		}
2289 2295
 
2290 2296
 		CreateDrugFlowOne(drugflow)
@@ -2292,16 +2298,6 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2292 2298
 		if errOne != nil {
2293 2299
 			return errOne
2294 2300
 		}
2295
-		//查询是否存在数据
2296
-		//_, errcodes := GetDrugWarehouseOutInfoIsExit(advice.DrugId, advice.PatientId, advice.RecordDate)
2297
-		//if errcodes == gorm.ErrRecordNotFound {
2298
-		//  errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2299
-		//  if errOne != nil {
2300
-		//    return errOne
2301
-		//  }
2302
-		//} else if errcodes == nil {
2303
-		//  UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
2304
-		//}
2305 2301
 
2306 2302
 		details := &models.DrugAutomaticReduceDetail{
2307 2303
 			WarehouseOutId:          warehouseout.ID,
@@ -2315,6 +2311,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2315 2311
 			DrugId:                  advice.DrugId,
2316 2312
 			Count:                   deliver_number,
2317 2313
 			CountUnit:               drup.MinUnit,
2314
+			WarehouseInfoId:         warehouse.ID,
2318 2315
 		}
2319 2316
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
2320 2317
 		if errTwo != nil {
@@ -2406,6 +2403,8 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2406 2403
 			Creator:                 advice.ExecutionStaff,
2407 2404
 			IsSys:                   1,
2408 2405
 			PatientId:               advice.PatientId,
2406
+			SystemTime:              advice.RecordDate,
2407
+			WarehousingDetailId:     warehouse.ID,
2409 2408
 		}
2410 2409
 
2411 2410
 		CreateDrugFlowOne(drugflow)
@@ -2413,16 +2412,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2413 2412
 		if errOne != nil {
2414 2413
 			return errOne
2415 2414
 		}
2416
-		//查询是否存在数据
2417
-		//_, errcodes := GetDrugWarehouseOutInfoIsExit(advice.DrugId, advice.PatientId, advice.RecordDate)
2418
-		//if errcodes == gorm.ErrRecordNotFound {
2419
-		//  errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2420
-		//  if errOne != nil {
2421
-		//    return errOne
2422
-		//  }
2423
-		//} else if errcodes == nil {
2424
-		//  UpdatedDrugWarehouseOutInfo(warehouseOutInfo, advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId)
2425
-		//}
2415
+
2426 2416
 		details := &models.DrugAutomaticReduceDetail{
2427 2417
 			WarehouseOutId:          warehouseout.ID,
2428 2418
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
@@ -2435,6 +2425,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2435 2425
 			DrugId:                  advice.DrugId,
2436 2426
 			Count:                   deliver_number,
2437 2427
 			CountUnit:               drup.MinUnit,
2428
+			WarehouseInfoId:         warehouse.ID,
2438 2429
 		}
2439 2430
 		errTwo := AddSigleDrugAutoReduceRecordInfo(details)
2440 2431
 		if errTwo != nil {
@@ -2484,3 +2475,220 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2484 2475
 
2485 2476
 	return
2486 2477
 }
2478
+
2479
+// 药品出库 递归方式
2480
+func HisAuToReduce(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo) (err error) {
2481
+
2482
+	//查询最后一次出库数据
2483
+	drugInfo, _ := GetDrugWarehouseOutInfoIsExit(advice.DrugId, advice.PatientId, advice.RecordDate)
2484
+
2485
+	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
2486
+	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2487
+	var count_number int64
2488
+	var device_number int64
2489
+	if advice.PrescribingNumberUnit == drup.MaxUnit {
2490
+		device_number = count * drup.MinNumber
2491
+	}
2492
+	if advice.PrescribingNumberUnit == drup.MinUnit {
2493
+		device_number = count
2494
+	}
2495
+
2496
+	if drugInfo.CountUnit == drup.MaxUnit {
2497
+		count_number = drugInfo.Count * drup.MinNumber
2498
+	}
2499
+	if drugInfo.CountUnit == drup.MinUnit {
2500
+		count_number = drugInfo.Count
2501
+	}
2502
+
2503
+	//  比较数据大小
2504
+	//如果当期医嘱数量小于最后一次出库则退库
2505
+	if device_number < count_number {
2506
+		fmt.Println("进来了吗")
2507
+		var cha_number int64
2508
+		var maxNumber int64
2509
+		var minNumber int64
2510
+		cha_number = count_number - device_number
2511
+		maxNumber = cha_number / drup.MinNumber
2512
+		minNumber = cha_number % drup.MinNumber
2513
+		//更改库存
2514
+		ModifyDrugWarehouse(drugInfo.WarehouseInfoId, maxNumber, minNumber)
2515
+
2516
+		//修改出库表
2517
+		info := models.DrugWarehouseOutInfo{
2518
+			Count:     device_number,
2519
+			CountUnit: advice.PrescribingNumberUnit,
2520
+		}
2521
+
2522
+		ModifyDrugWarehouseOutInfo(info, advice.DrugId, advice.PatientId, advice.RecordDate)
2523
+
2524
+		//修改自动出库表
2525
+		detail := models.DrugAutomaticReduceDetail{
2526
+			Count:     device_number,
2527
+			CountUnit: advice.PrescribingNumberUnit,
2528
+		}
2529
+		ModifyAutoMaticReduce(detail, advice.PatientId, advice.RecordDate, advice.DrugId)
2530
+		//修改流水
2531
+		flow := models.DrugFlow{
2532
+			Count:   device_number,
2533
+			MaxUnit: drup.MinUnit,
2534
+		}
2535
+		ModifyDrugFlow(flow, drugInfo.WarehouseOutOrderNumber, advice.DrugId, advice.PatientId)
2536
+
2537
+	}
2538
+	fmt.Println("医嘱数量44444444444444", device_number)
2539
+	fmt.Println("最后一次出库数量", count_number)
2540
+	//如果当期医嘱数量大于最后一次出库则需要出库
2541
+	if device_number > count_number {
2542
+		var cha_number int64
2543
+		cha_number = device_number - count_number
2544
+
2545
+		// 根据先进先出原则,查询最先入库的批次,进行出库
2546
+
2547
+		warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId)
2548
+		//查找药品信息
2549
+		//baseInfo, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
2550
+		if err != nil {
2551
+			return err
2552
+		}
2553
+
2554
+		// 将该批次的剩余库存数量转换为拆零数量
2555
+		var stock_number int64
2556
+		var maxNumber int64
2557
+		var minNumber int64
2558
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
2559
+
2560
+		//如果库存数量大于出库数据,正常出库
2561
+		if stock_number >= cha_number {
2562
+			//扣减库存
2563
+			maxNumber = cha_number / drup.MinNumber
2564
+			minNumber = cha_number % drup.MinNumber
2565
+
2566
+			if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
2567
+				minNumber = maxNumber
2568
+			}
2569
+
2570
+			if drup.MaxUnit != drup.MinUnit {
2571
+				if warehouse.StockMaxNumber < maxNumber {
2572
+					return errors.New("库存数量不足")
2573
+				}
2574
+			}
2575
+
2576
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
2577
+			if warehouse.StockMaxNumber < 0 {
2578
+				warehouse.StockMaxNumber = 0
2579
+			}
2580
+
2581
+			warehouse.Mtime = time.Now().Unix()
2582
+
2583
+			if warehouse.StockMinNumber < minNumber {
2584
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
2585
+				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
2586
+			} else {
2587
+
2588
+				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2589
+
2590
+			}
2591
+
2592
+			if drup.MaxUnit != drup.MinUnit {
2593
+				if warehouse.StockMaxNumber < 0 {
2594
+					return errors.New("库存数量不足")
2595
+				}
2596
+			}
2597
+
2598
+			//扣减库存232332332332
2599
+			errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
2600
+
2601
+			if errThree != nil {
2602
+				return errThree
2603
+			}
2604
+
2605
+			//修改出库表
2606
+			info := models.DrugWarehouseOutInfo{
2607
+				Count:     device_number,
2608
+				CountUnit: advice.PrescribingNumberUnit,
2609
+			}
2610
+			ModifyDrugWarehouseOutInfoOne(info, advice.DrugId, advice.PatientId, advice.RecordDate, warehouse.ID)
2611
+			//修改自动出库表
2612
+			detail := models.DrugAutomaticReduceDetail{
2613
+				Count:     device_number,
2614
+				CountUnit: advice.PrescribingNumberUnit,
2615
+			}
2616
+			ModifyAutoMaticReduceOne(detail, advice.PatientId, advice.RecordDate, advice.DrugId, warehouse.ID)
2617
+			//修改流水
2618
+			flow := models.DrugFlow{
2619
+				Count:   device_number,
2620
+				MaxUnit: advice.PrescribingNumberUnit,
2621
+			}
2622
+			ModifyDrugFlowOne(flow, drugInfo.WarehouseOutOrderNumber, advice.DrugId, advice.PatientId, warehouse.ID)
2623
+		}
2624
+		//如果库存数量小于出库数据,则需要出库到下一个批次
2625
+		if stock_number < cha_number {
2626
+
2627
+			//修改出库表
2628
+			info := models.DrugWarehouseOutInfo{
2629
+				Count:     cha_number,
2630
+				CountUnit: advice.PrescribingNumberUnit,
2631
+			}
2632
+			ModifyDrugWarehouseOutInfoOne(info, advice.DrugId, advice.PatientId, advice.RecordDate, warehouse.ID)
2633
+			//修改自动出库表
2634
+			detail := models.DrugAutomaticReduceDetail{
2635
+				Count:     cha_number,
2636
+				CountUnit: advice.PrescribingNumberUnit,
2637
+			}
2638
+			ModifyAutoMaticReduceOne(detail, advice.PatientId, advice.RecordDate, advice.DrugId, warehouse.ID)
2639
+			//修改流水
2640
+			flow := models.DrugFlow{
2641
+				Count:   cha_number,
2642
+				MaxUnit: advice.PrescribingNumberUnit,
2643
+			}
2644
+			ModifyDrugFlowOne(flow, drugInfo.WarehouseOutOrderNumber, advice.DrugId, advice.PatientId, warehouse.ID)
2645
+
2646
+			druginfo := &models.XtDrugWarehouseInfo{
2647
+				ID:                warehouse.ID,
2648
+				WarehousingId:     warehouse.WarehousingId,
2649
+				DrugId:            warehouse.DrugId,
2650
+				Number:            warehouse.Number,
2651
+				ProductDate:       warehouse.ProductDate,
2652
+				ExpiryDate:        warehouse.ExpiryDate,
2653
+				WarehousingCount:  warehouse.WarehousingCount,
2654
+				Price:             warehouse.Price,
2655
+				TotalPrice:        warehouse.TotalPrice,
2656
+				Dealer:            warehouse.Dealer,
2657
+				Manufacturer:      warehouse.Manufacturer,
2658
+				Remark:            warehouse.Remark,
2659
+				Ctime:             warehouse.Ctime,
2660
+				Mtime:             warehouse.Mtime,
2661
+				Status:            1,
2662
+				OrgId:             warehouse.OrgId,
2663
+				IsReturn:          warehouse.IsReturn,
2664
+				WarehousingOrder:  warehouse.WarehousingOrder,
2665
+				Type:              warehouse.Type,
2666
+				RetailPrice:       warehouse.RetailPrice,
2667
+				RetailTotalPrice:  warehouse.RetailPrice,
2668
+				StockMaxNumber:    0,
2669
+				StockMinNumber:    0,
2670
+				BatchNumber:       warehouse.BatchNumber,
2671
+				MaxUnit:           warehouse.MaxUnit,
2672
+				WarehousingInfoId: warehouse.WarehousingInfoId,
2673
+			}
2674
+			errThree := UpDateDrugWarehouseInfoByStock(druginfo)
2675
+			if errThree != nil {
2676
+				return errThree
2677
+			}
2678
+
2679
+			// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
2680
+			prescribingNumber_two_temp := cha_number - stock_number
2681
+
2682
+			overPlusNumber := float64(prescribingNumber_two_temp)
2683
+
2684
+			advice.PrescribingNumber = float64(prescribingNumber_two_temp)
2685
+
2686
+			advice.PrescribingNumberUnit = advice.PrescribingNumberUnit
2687
+
2688
+			NewHisDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice)
2689
+
2690
+		}
2691
+	}
2692
+
2693
+	return
2694
+}