Browse Source

11月8日库存管理

XMLWAN 2 years ago
parent
commit
c6510abd77

+ 85 - 81
controllers/his_api_controller.go View File

@@ -1051,53 +1051,55 @@ func (c *HisApiController) CreateHisPrescription() {
1051 1051
 									}
1052 1052
 
1053 1053
 								}
1054
-								//修改处方
1055
-								//if advicelist.ID > 0 {
1056
-								//all_count, _ := strconv.ParseFloat(totals, 64) //总库存
1057
-								//var  his_count int64 //历史出库数据
1058
-								//if(advicelist.PrescribingNumberUnit == drug.MaxUnit){
1059
-								//  strPrescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'E', -1, 64)
1060
-								//  intPrescribingNumber, _ := strconv.ParseInt(strPrescribingNumber, 10, 64)
1061
-								//  his_count = intPrescribingNumber * drug.MinNumber
1062
-								//}
1063
-								//if(advicelist.PrescribingNumberUnit == drug.MinUnit){
1064
-								//  strPrescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'E', -1, 64)
1065
-								//  intPrescribingNumber, _ := strconv.ParseInt(strPrescribingNumber, 10, 64)
1066
-								//  his_count = intPrescribingNumber
1067
-								//}
1068
-								//
1069
-								//
1070
-								// if prescribingNumberUnit == drug.MinUnit {
1071
-								//
1072
-								//   float_prescribing_number := strconv.FormatFloat(prescribing_number, 'f', -1, 64)
1073
-								//   int_prescribing_number, _ := strconv.ParseInt(float_prescribing_number, 10, 64)
1074
-								//   float_all_count := strconv.FormatFloat(all_count, 'f', -1, 64)
1075
-								//   int_all_count, _ := strconv.ParseInt(float_all_count, 10, 64)
1076
-								//
1077
-								//   fmt.Println("总库存我的",int_all_count)
1078
-								//   fmt.Println("现在出库库存",int_prescribing_number)
1079
-								//   fmt.Println("历史出库数据",his_count)
1080
-								//   if (int_prescribing_number - his_count) > int_all_count {
1081
-								//     c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1082
-								//     return
1083
-								//   }
1084
-								//
1085
-								// }
1086
-								// if prescribingNumberUnit == drug.MaxUnit {
1087
-								//   float_all_count := strconv.FormatFloat(all_count, 'f', -1, 64)
1088
-								//   int_all_count, _ := strconv.ParseInt(float_all_count, 10, 64)
1089
-								//   num := prescribing_number * float64(drug.MinNumber)
1090
-								//   num_str_count := strconv.FormatFloat(num, 'f', -1, 64)
1091
-								//   num_int_count, _ := strconv.ParseInt(num_str_count, 10, 64)
1092
-								//   fmt.Println("总库存我的",int_all_count)
1093
-								//   fmt.Println("现在出库库存",num_str_count)
1094
-								//   fmt.Println("历史出库数据",his_count)
1095
-								//   if (num_int_count - his_count)  > int_all_count {
1096
-								//     c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1097
-								//     return
1098
-								//   }
1099
-								// }
1100
-								//}
1054
+								drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
1055
+								if drugOutConfig.IsOpen != 1 {
1056
+									//修改处方
1057
+									if advicelist.ID > 0 {
1058
+										all_count, _ := strconv.ParseFloat(totals, 64) //总库存
1059
+										var his_count int64                            //历史出库数据
1060
+										if advicelist.PrescribingNumberUnit == drug.MaxUnit {
1061
+											strPrescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'E', -1, 64)
1062
+											intPrescribingNumber, _ := strconv.ParseInt(strPrescribingNumber, 10, 64)
1063
+											his_count = intPrescribingNumber * drug.MinNumber
1064
+										}
1065
+										if advicelist.PrescribingNumberUnit == drug.MinUnit {
1066
+											strPrescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'E', -1, 64)
1067
+											intPrescribingNumber, _ := strconv.ParseInt(strPrescribingNumber, 10, 64)
1068
+											his_count = intPrescribingNumber
1069
+										}
1070
+
1071
+										if prescribingNumberUnit == drug.MinUnit {
1072
+
1073
+											float_prescribing_number := strconv.FormatFloat(prescribing_number, 'f', -1, 64)
1074
+											int_prescribing_number, _ := strconv.ParseInt(float_prescribing_number, 10, 64)
1075
+											float_all_count := strconv.FormatFloat(all_count, 'f', -1, 64)
1076
+											int_all_count, _ := strconv.ParseInt(float_all_count, 10, 64)
1077
+
1078
+											fmt.Println("总库存我的", int_all_count)
1079
+											fmt.Println("现在出库库存", int_prescribing_number)
1080
+											fmt.Println("历史出库数据", his_count)
1081
+											if (int_prescribing_number - his_count) > int_all_count {
1082
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1083
+												return
1084
+											}
1085
+
1086
+										}
1087
+										if prescribingNumberUnit == drug.MaxUnit {
1088
+											float_all_count := strconv.FormatFloat(all_count, 'f', -1, 64)
1089
+											int_all_count, _ := strconv.ParseInt(float_all_count, 10, 64)
1090
+											num := prescribing_number * float64(drug.MinNumber)
1091
+											num_str_count := strconv.FormatFloat(num, 'f', -1, 64)
1092
+											num_int_count, _ := strconv.ParseInt(num_str_count, 10, 64)
1093
+											fmt.Println("总库存我的", int_all_count)
1094
+											fmt.Println("现在出库库存", num_str_count)
1095
+											fmt.Println("历史出库数据", his_count)
1096
+											if (num_int_count - his_count) > int_all_count {
1097
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1098
+												return
1099
+											}
1100
+										}
1101
+									}
1102
+								}
1101 1103
 
1102 1104
 							}
1103 1105
 						}
@@ -1616,48 +1618,49 @@ func (c *HisApiController) CreateHisPrescription() {
1616 1618
 		hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
1617 1619
 		storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
1618 1620
 		drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
1619
-		for _, item := range hisdoctorlist {
1620
-			drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
1621
-
1622
-			// 查询该药品最后一次出库记录
1623
-			druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
1624
-			fmt.Println("drugiNfo23323233232323233223", len(druginfo))
1621
+		if drugOutConfig.IsOpen == 1 {
1622
+			for _, item := range hisdoctorlist {
1623
+				drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
1624
+
1625
+				// 查询该药品最后一次出库记录
1626
+				druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
1627
+
1628
+				if len(druginfo) > 0 {
1629
+					//回退库存
1630
+					for _, it := range druginfo {
1631
+						if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1632
+							service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
1633
+						}
1634
+						if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
1635
+							service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
1636
+						}
1637
+						if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
1625 1638
 
1626
-			if len(druginfo) > 0 {
1627
-				//回退库存
1628
-				for _, it := range druginfo {
1629
-					fmt.Println("it", it.Count)
1630
-					fmt.Println("countuntit", it.CountUnit)
1631
-					if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1632
-						service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
1633
-					}
1634
-					if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
1635
-						service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
1636
-					}
1637
-					if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
1638
-						service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
1639
+							service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
1640
+						}
1639 1641
 					}
1640 1642
 				}
1641
-			}
1642 1643
 
1643
-			//删除记录
1644
-			service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
1645
-			if drugOutConfig.IsOpen == 1 {
1646
-				//出库
1647
-				if drug.IsUse == 2 {
1648
-					creater := adminInfo.AdminUser.Id
1649
-					service.HisDrugsDelivery(item.UserOrgId, creater, item)
1650
-				}
1644
+				//删除记录
1645
+				service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
1646
+				if drugOutConfig.IsOpen == 1 {
1647
+					//出库
1648
+					if drug.IsUse == 2 {
1649
+						creater := adminInfo.AdminUser.Id
1650
+						service.HisDrugsDelivery(item.UserOrgId, creater, item)
1651
+					}
1651 1652
 
1652
-				//更新字典里面的库存
1653
-				stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1654
-				var sum_count int64
1655
-				for _, its := range stockInfo {
1656
-					sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
1653
+					//更新字典里面的库存
1654
+					stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1655
+					var sum_count int64
1656
+					for _, its := range stockInfo {
1657
+						sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
1658
+					}
1659
+					service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
1657 1660
 				}
1658
-				service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
1659 1661
 			}
1660 1662
 		}
1663
+
1661 1664
 	}
1662 1665
 
1663 1666
 	//redisClient := service.RedisClient()
@@ -2176,6 +2179,7 @@ func (c *HisApiController) DeletePrescription() {
2176 2179
 		}
2177 2180
 	}
2178 2181
 	if drugStockConfig.IsOpen == 1 {
2182
+		fmt.Println("woowowowowowowowowowowowowowo", len(advices))
2179 2183
 		if len(advices) > 0 {
2180 2184
 			for _, item := range advices {
2181 2185
 				creater := c.GetAdminUserInfo().AdminUser.Id

+ 51 - 49
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -1098,59 +1098,61 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1098 1098
 
1099 1099
 					var total int64
1100 1100
 					var prescribing_number_total int64
1101
-					//查询该药品是否有库存
1102
-					houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
1103
-					list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
1104
-
1105
-					//判断单位是否相等
1106
-					if medical.MaxUnit == advice.PrescribingNumberUnit {
1107
-						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1108
-						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1109
-						//转化为最小单位
1110
-						total = list.Count*medical.MinNumber + list.StockMinNumber
1111
-						prescribing_number_total = count * medical.MinNumber
1112
-					}
1113
-					//fmt.Println("医嘱开的数量", total)
1114
-					if medical.MinUnit == advice.PrescribingNumberUnit {
1115
-						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1116
-						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1117
-						total = list.Count*medical.MinNumber + list.StockMinNumber
1118
-						prescribing_number_total = count
1119
-					}
1120 1101
 
1121
-					//fmt.Println("数量一", prescribing_number_total)
1122
-					//fmt.Println("数量二", total)
1102
+					config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
1103
+					if config.IsOpen != 1 {
1104
+						//查询该药品是否有库存
1105
+						houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
1106
+						list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
1107
+
1108
+						//判断单位是否相等
1109
+						if medical.MaxUnit == advice.PrescribingNumberUnit {
1110
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1111
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1112
+							//转化为最小单位
1113
+							total = list.Count*medical.MinNumber + list.StockMinNumber
1114
+							prescribing_number_total = count * medical.MinNumber
1115
+						}
1116
+						//fmt.Println("医嘱开的数量", total)
1117
+						if medical.MinUnit == advice.PrescribingNumberUnit {
1118
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1119
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1120
+							total = list.Count*medical.MinNumber + list.StockMinNumber
1121
+							prescribing_number_total = count
1122
+						}
1123 1123
 
1124
-					if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
1125
-						c.ServeSuccessJSON(map[string]interface{}{
1126
-							"msg":    "3",
1127
-							"advice": advice,
1128
-							"ids":    ids,
1129
-						})
1130
-						return
1131
-					}
1132
-					if prescribing_number_total > total {
1133
-						c.ServeSuccessJSON(map[string]interface{}{
1134
-							"msg":    "2",
1135
-							"advice": advice,
1136
-							"ids":    ids,
1137
-						})
1138
-						return
1139
-					}
1140
-					if prescribing_number_total <= total {
1141
-						if medical.IsUse == 2 {
1142
-							config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
1143
-							if config.IsOpen != 1 {
1144
-								service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1145
-								//更新字典里面的库存
1146
-								stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1147
-								var sum_count int64
1148
-								for _, its := range stockInfo {
1149
-									sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
1124
+						if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
1125
+							c.ServeSuccessJSON(map[string]interface{}{
1126
+								"msg":    "3",
1127
+								"advice": advice,
1128
+								"ids":    ids,
1129
+							})
1130
+							return
1131
+						}
1132
+						if prescribing_number_total > total {
1133
+							c.ServeSuccessJSON(map[string]interface{}{
1134
+								"msg":    "2",
1135
+								"advice": advice,
1136
+								"ids":    ids,
1137
+							})
1138
+							return
1139
+						}
1140
+
1141
+						if prescribing_number_total <= total {
1142
+							if medical.IsUse == 2 {
1143
+
1144
+								if config.IsOpen != 1 {
1145
+									service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1146
+									//更新字典里面的库存
1147
+									stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1148
+									var sum_count int64
1149
+									for _, its := range stockInfo {
1150
+										sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
1151
+									}
1152
+									service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
1150 1153
 								}
1151
-								service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
1152
-							}
1153 1154
 
1155
+							}
1154 1156
 						}
1155 1157
 					}
1156 1158
 				}

+ 179 - 66
controllers/patient_api_controller.go View File

@@ -1608,8 +1608,7 @@ func (c *PatientApiController) ExecGroupAdvice() {
1608 1608
 	exceAdvice := models.DoctorAdvice{
1609 1609
 		ExecutionStaff: executionStaff,
1610 1610
 		ExecutionTime:  theTime.Unix(),
1611
-		// Checker:        checker,
1612
-		UpdatedTime: time.Now().Unix(),
1611
+		UpdatedTime:    time.Now().Unix(),
1613 1612
 	}
1614 1613
 	err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
1615 1614
 
@@ -1618,6 +1617,124 @@ func (c *PatientApiController) ExecGroupAdvice() {
1618 1617
 		return
1619 1618
 	}
1620 1619
 
1620
+	//查询自动扣减是否开启
1621
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
1622
+	//查询已经执行的医嘱
1623
+	advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
1624
+
1625
+	if drugStockConfig.IsOpen == 1 {
1626
+		for _, item := range advicelist {
1627
+			medical, _ := service.GetBaseDrugMedical(advice.DrugId)
1628
+			//查询这个患者这个患者这个药已经出库的所有数量
1629
+			advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
1630
+			drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
1631
+			var total_count int64
1632
+			var drug_count int64
1633
+			for _, it := range advicelist {
1634
+				if it.PrescribingNumberUnit == medical.MaxUnit {
1635
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
1636
+					prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1637
+					total_count += prenumber * medical.MinNumber
1638
+				}
1639
+				if it.PrescribingNumberUnit == medical.MinUnit {
1640
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
1641
+					prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1642
+					total_count += prenumber
1643
+				}
1644
+
1645
+			}
1646
+
1647
+			for _, its := range drugoutlist {
1648
+				if its.CountUnit == medical.MaxUnit {
1649
+					drug_count += its.Count * medical.MinNumber
1650
+				}
1651
+				if its.CountUnit == medical.MinUnit {
1652
+					drug_count += its.Count
1653
+				}
1654
+			}
1655
+			if total_count == drug_count {
1656
+				c.ServeSuccessJSON(map[string]interface{}{
1657
+					"msg":    "1",
1658
+					"advice": advice,
1659
+				})
1660
+				return
1661
+			}
1662
+
1663
+			var total int64
1664
+			var prescribing_number_total int64
1665
+
1666
+			//查询默认出库仓库
1667
+			houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
1668
+
1669
+			//查询该药品在默认仓库是否有库存
1670
+			list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
1671
+
1672
+			//判断单位是否相等
1673
+			if medical.MaxUnit == advice.PrescribingNumberUnit {
1674
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1675
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1676
+				//转化为最小单位
1677
+				total = list.Count*medical.MinNumber + list.StockMinNumber
1678
+				prescribing_number_total = count * medical.MinNumber
1679
+			}
1680
+
1681
+			if medical.MinUnit == advice.PrescribingNumberUnit {
1682
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1683
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1684
+				total = list.Count*medical.MinNumber + list.StockMinNumber
1685
+
1686
+				prescribing_number_total = count
1687
+
1688
+			}
1689
+
1690
+			if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
1691
+				c.ServeSuccessJSON(map[string]interface{}{
1692
+					"msg":    "3",
1693
+					"advice": advice,
1694
+				})
1695
+				return
1696
+			}
1697
+			if prescribing_number_total > total {
1698
+				c.ServeSuccessJSON(map[string]interface{}{
1699
+					"msg":    "2",
1700
+					"advice": advice,
1701
+				})
1702
+				return
1703
+			}
1704
+			if prescribing_number_total <= total {
1705
+				if medical.IsUse == 2 {
1706
+					service.DrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
1707
+					//查询默认仓库
1708
+					storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
1709
+					//查询默认仓库剩余多少库存
1710
+					var sum_count int64
1711
+					stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1712
+					for _, its := range stockInfo {
1713
+						sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
1714
+					}
1715
+					service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
1716
+					break
1717
+					c.ServeSuccessJSON(map[string]interface{}{
1718
+						"msg":    "1",
1719
+						"advice": advice,
1720
+					})
1721
+					return
1722
+
1723
+				}
1724
+
1725
+				if medical.IsUse == 1 {
1726
+					c.ServeSuccessJSON(map[string]interface{}{
1727
+						"msg":    "1",
1728
+						"advice": advice,
1729
+					})
1730
+					return
1731
+				}
1732
+
1733
+			}
1734
+
1735
+		}
1736
+	}
1737
+
1621 1738
 	advice.ExecutionStaff = executionStaff
1622 1739
 	advice.ExecutionTime = theTime.Unix()
1623 1740
 
@@ -1795,9 +1912,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1795 1912
 					adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
1796 1913
 
1797 1914
 					if adviceSetting.IsAdviceOpen == 1 {
1798
-
1799 1915
 						//查询是否出库按钮开启
1800 1916
 						prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
1917
+						fmt.Println("prescriptionConfigwodweweeeweweweweweewewewwewew", prescriptionConfig)
1801 1918
 						if prescriptionConfig.IsOpen == 1 {
1802 1919
 							if medical.IsUse == 2 {
1803 1920
 								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
@@ -1869,9 +1986,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1869 1986
 
1870 1987
 			if item.Way == 2 {
1871 1988
 				if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
1872
-
1873
-					//adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
1874
-
1875 1989
 					if item.ExecutionState == 1 {
1876 1990
 						prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1877 1991
 						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
@@ -1962,8 +2076,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1962 2076
 		exceAdvice := models.HisDoctorAdviceInfo{
1963 2077
 			ExecutionStaff: executionStaff,
1964 2078
 			ExecutionTime:  theTime.Unix(),
1965
-			// Checker:        checker,
1966
-			UpdatedTime: time.Now().Unix(),
2079
+			UpdatedTime:    time.Now().Unix(),
1967 2080
 		}
1968 2081
 		if advice.ParentId > 0 {
1969 2082
 			err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
@@ -2015,7 +2128,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2015 2128
 
2016 2129
 		advice.ExecutionStaff = executionStaff
2017 2130
 		advice.ExecutionTime = theTime.Unix()
2018
-		// advice.Checker = checker
2019 2131
 
2020 2132
 		//处理出库相关逻辑
2021 2133
 
@@ -2067,78 +2179,79 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2067 2179
 
2068 2180
 				var total int64
2069 2181
 				var prescribing_number_total int64
2182
+				config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
2183
+				if config.IsOpen != 1 {
2184
+					//查询默认出库仓库
2185
+					houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
2186
+
2187
+					//查询该药品在默认仓库是否有库存
2188
+					list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
2189
+
2190
+					//判断单位是否相等
2191
+					if medical.MaxUnit == advice.PrescribingNumberUnit {
2192
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2193
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2194
+						//转化为最小单位
2195
+						total = list.Count*medical.MinNumber + list.StockMinNumber
2196
+						prescribing_number_total = count * medical.MinNumber
2197
+					}
2070 2198
 
2071
-				//查询默认出库仓库
2072
-				houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
2073
-
2074
-				//查询该药品在默认仓库是否有库存
2075
-				list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
2076
-
2077
-				//判断单位是否相等
2078
-				if medical.MaxUnit == advice.PrescribingNumberUnit {
2079
-					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2080
-					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2081
-					//转化为最小单位
2082
-					total = list.Count*medical.MinNumber + list.StockMinNumber
2083
-					prescribing_number_total = count * medical.MinNumber
2084
-				}
2199
+					if medical.MinUnit == advice.PrescribingNumberUnit {
2200
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2201
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2202
+						total = list.Count*medical.MinNumber + list.StockMinNumber
2085 2203
 
2086
-				if medical.MinUnit == advice.PrescribingNumberUnit {
2087
-					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2088
-					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2089
-					total = list.Count*medical.MinNumber + list.StockMinNumber
2204
+						prescribing_number_total = count
2090 2205
 
2091
-					prescribing_number_total = count
2206
+					}
2092 2207
 
2093
-				}
2208
+					if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
2209
+						c.ServeSuccessJSON(map[string]interface{}{
2210
+							"msg":    "3",
2211
+							"advice": advice,
2212
+						})
2213
+						return
2214
+					}
2215
+					if prescribing_number_total > total {
2216
+						c.ServeSuccessJSON(map[string]interface{}{
2217
+							"msg":    "2",
2218
+							"advice": advice,
2219
+						})
2220
+						return
2221
+					}
2094 2222
 
2095
-				if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
2096
-					c.ServeSuccessJSON(map[string]interface{}{
2097
-						"msg":    "3",
2098
-						"advice": advice,
2099
-					})
2100
-					return
2101
-				}
2102
-				if prescribing_number_total > total {
2103
-					c.ServeSuccessJSON(map[string]interface{}{
2104
-						"msg":    "2",
2105
-						"advice": advice,
2106
-					})
2107
-					return
2108
-				}
2109
-				if prescribing_number_total <= total {
2110
-					if medical.IsUse == 2 {
2111
-						config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
2112
-						if config.IsOpen != 1 {
2113
-							service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
2114
-							//查询默认仓库
2115
-							storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
2116
-							//查询默认仓库剩余多少库存
2117
-							var sum_count int64
2118
-							stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
2119
-							for _, its := range stockInfo {
2120
-								sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
2223
+					if prescribing_number_total <= total {
2224
+						if medical.IsUse == 2 {
2225
+							if config.IsOpen != 1 {
2226
+								service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
2227
+								//查询默认仓库
2228
+								storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
2229
+								//查询默认仓库剩余多少库存
2230
+								var sum_count int64
2231
+								stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
2232
+								for _, its := range stockInfo {
2233
+									sum_count += its.StockMaxNumber*medical.MinNumber + its.StockMinNumber
2234
+								}
2235
+								service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
2236
+								break
2237
+								c.ServeSuccessJSON(map[string]interface{}{
2238
+									"msg":    "1",
2239
+									"advice": advice,
2240
+								})
2241
+								return
2121 2242
 							}
2122
-							service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
2123
-							break
2243
+						}
2244
+
2245
+						if medical.IsUse == 1 {
2124 2246
 							c.ServeSuccessJSON(map[string]interface{}{
2125 2247
 								"msg":    "1",
2126 2248
 								"advice": advice,
2127 2249
 							})
2128 2250
 							return
2129 2251
 						}
2130
-					}
2131 2252
 
2132
-					if medical.IsUse == 1 {
2133
-						c.ServeSuccessJSON(map[string]interface{}{
2134
-							"msg":    "1",
2135
-							"advice": advice,
2136
-						})
2137
-						return
2138 2253
 					}
2139
-
2140 2254
 				}
2141
-
2142 2255
 			}
2143 2256
 
2144 2257
 		}

+ 36 - 103
controllers/stock_in_api_controller.go View File

@@ -3764,38 +3764,6 @@ func (this *StockManagerApiController) AddDrugInformation() {
3764 3764
 
3765 3765
 		drug.DrugName = drug_name
3766 3766
 
3767
-		doses := goodNameM["dose"].(string)
3768
-		dose, _ := strconv.ParseFloat(doses, 64)
3769
-		if dose < 0 { //名字为空则生成一条导入错误日志
3770
-			err_log := models.ExportErrLog{
3771
-				LogType:    4,
3772
-				UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
3773
-				ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
3774
-				Status:     1,
3775
-				CreateTime: time.Now().Unix(),
3776
-				UpdateTime: time.Now().Unix(),
3777
-				ExportTime: time.Now().Unix(),
3778
-			}
3779
-			service.CreateExportErrLog(&err_log)
3780
-			continue
3781
-		}
3782
-
3783
-		drug.Dose = dose
3784
-
3785
-		fmt.Println("drug_233323232323232wo", drug.Dose)
3786
-		if dose < 0 { //名字为空则生成一条导入错误日志
3787
-			err_log := models.ExportErrLog{
3788
-				LogType:    4,
3789
-				UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
3790
-				ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
3791
-				Status:     1,
3792
-				CreateTime: time.Now().Unix(),
3793
-				UpdateTime: time.Now().Unix(),
3794
-				ExportTime: time.Now().Unix(),
3795
-			}
3796
-			service.CreateExportErrLog(&err_log)
3797
-			continue
3798
-		}
3799 3767
 		dose_unit := goodNameM["dose_unit"].(string)
3800 3768
 		drug.DoseUnit = dose_unit
3801 3769
 
@@ -3839,40 +3807,6 @@ func (this *StockManagerApiController) AddDrugInformation() {
3839 3807
 
3840 3808
 		drug.MinUnit = min_unit
3841 3809
 
3842
-		max_unit_id := goodNameM["max_unit"].(string)
3843
-		if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
3844
-			err_log := models.ExportErrLog{
3845
-				LogType:    4,
3846
-				UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
3847
-				ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
3848
-				Status:     1,
3849
-				CreateTime: time.Now().Unix(),
3850
-				UpdateTime: time.Now().Unix(),
3851
-				ExportTime: time.Now().Unix(),
3852
-			}
3853
-			service.CreateExportErrLog(&err_log)
3854
-			continue
3855
-		}
3856
-
3857
-		drug.MaxUnit = max_unit_id
3858
-
3859
-		max_unit := goodNameM["max_unit"].(string)
3860
-		if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
3861
-			err_log := models.ExportErrLog{
3862
-				LogType:    4,
3863
-				UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
3864
-				ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的包装单位不能为空",
3865
-				Status:     1,
3866
-				CreateTime: time.Now().Unix(),
3867
-				UpdateTime: time.Now().Unix(),
3868
-				ExportTime: time.Now().Unix(),
3869
-			}
3870
-			service.CreateExportErrLog(&err_log)
3871
-			continue
3872
-		}
3873
-
3874
-		drug.MaxUnit = max_unit
3875
-
3876 3810
 		drug_type := goodNameM["drug_type"].(string)
3877 3811
 		if len(drug_type) == 0 { //名字为空则生成一条导入错误日志
3878 3812
 			err_log := models.ExportErrLog{
@@ -4641,42 +4575,6 @@ func (this *StockManagerApiController) AddDrugInformation() {
4641 4575
 				}
4642 4576
 			}
4643 4577
 
4644
-			drug_dose := goodNameM["drug_dose"].(string)
4645
-
4646
-			if len(drug_dose) == 0 {
4647
-				err_log := models.ExportErrLog{
4648
-					LogType:    4,
4649
-					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
4650
-					ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量不能为空",
4651
-					Status:     1,
4652
-					CreateTime: time.Now().Unix(),
4653
-					UpdateTime: time.Now().Unix(),
4654
-					ExportTime: time.Now().Unix(),
4655
-				}
4656
-				service.CreateExportErrLog(&err_log)
4657
-				continue
4658
-			}
4659
-			drugDoses, _ := strconv.ParseFloat(drug_dose, 64)
4660
-			drug.DrugDose = drugDoses
4661
-
4662
-			var units = "单位"
4663
-			var unit_id int64
4664
-			drugDoseUnit := goodNameM["drug_dose_unit"].(string)
4665
-
4666
-			if len(drugDoseUnit) == 0 {
4667
-				err_log := models.ExportErrLog{
4668
-					LogType:    4,
4669
-					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
4670
-					ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的默认单次用量单位不能为空",
4671
-					Status:     1,
4672
-					CreateTime: time.Now().Unix(),
4673
-					UpdateTime: time.Now().Unix(),
4674
-					ExportTime: time.Now().Unix(),
4675
-				}
4676
-				service.CreateExportErrLog(&err_log)
4677
-				continue
4678
-			}
4679
-
4680 4578
 			manufacturer := goodNameM["manufacturer"].(string)
4681 4579
 			if len(manufacturer) == 0 { //名字为空则生成一条导入错误日志
4682 4580
 				err_log := models.ExportErrLog{
@@ -4763,6 +4661,10 @@ func (this *StockManagerApiController) AddDrugInformation() {
4763 4661
 
4764 4662
 			drug_category := goodNameM["drug_category"].(string)
4765 4663
 
4664
+			min_prices := goodNameM["min_price"].(string)
4665
+			min_price, _ := strconv.ParseFloat(min_prices, 64)
4666
+
4667
+			drug.MinPrice = min_price
4766 4668
 			var drugCategory = "药品类别"
4767 4669
 			var drug_category_id int64
4768 4670
 
@@ -4990,7 +4892,38 @@ func (this *StockManagerApiController) AddDrugInformation() {
4990 4892
 			drug.DrugStatus = drug_status
4991 4893
 			limit_remark := goodNameM["limit_remark"].(string)
4992 4894
 			drug.LimitRemark = limit_remark
4895
+			doses := goodNameM["dose"].(string)
4896
+			dose, _ := strconv.ParseFloat(doses, 64)
4897
+			if dose < 0 { //名字为空则生成一条导入错误日志
4898
+				err_log := models.ExportErrLog{
4899
+					LogType:    4,
4900
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
4901
+					ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的剂量不能为空",
4902
+					Status:     1,
4903
+					CreateTime: time.Now().Unix(),
4904
+					UpdateTime: time.Now().Unix(),
4905
+					ExportTime: time.Now().Unix(),
4906
+				}
4907
+				service.CreateExportErrLog(&err_log)
4908
+				continue
4909
+			}
4910
+
4911
+			drug.Dose = dose
4993 4912
 
4913
+			fmt.Println("drug_233323232323232wo", drug.Dose)
4914
+			if dose < 0 { //名字为空则生成一条导入错误日志
4915
+				err_log := models.ExportErrLog{
4916
+					LogType:    4,
4917
+					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
4918
+					ErrMsg:     "第" + strconv.Itoa(index+2) + "行" + "的剂量单位不能为空",
4919
+					Status:     1,
4920
+					CreateTime: time.Now().Unix(),
4921
+					UpdateTime: time.Now().Unix(),
4922
+					ExportTime: time.Now().Unix(),
4923
+				}
4924
+				service.CreateExportErrLog(&err_log)
4925
+				continue
4926
+			}
4994 4927
 			drugList = append(drugList, &drug)
4995 4928
 		}
4996 4929
 
@@ -5050,7 +4983,7 @@ func (this *StockManagerApiController) AddDrugInformation() {
5050 4983
 					Dose:                        item.Dose,
5051 4984
 					MinNumber:                   item.MinNumber,
5052 4985
 					IsUse:                       2,
5053
-					MinPrice:                    item.RetailPrice,
4986
+					MinPrice:                    item.MinPrice,
5054 4987
 				}
5055 4988
 
5056 4989
 				//查询同种药品同种规格是否存在

+ 1 - 0
models/drug_stock.go View File

@@ -333,6 +333,7 @@ type VmDrugWarehouseInfo struct {
333 333
 	SupplyWarehouseId         int64  `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
334 334
 	SupplyWarehouseDetailInfo int64  `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
335 335
 	StorehouseId              int64  `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
336
+	IsCheck                   int64  `gorm:"column:is_check" json:"is_check" form:"is_check"`
336 337
 }
337 338
 
338 339
 type StDrugWarehouseOutInfo struct {

+ 6 - 0
service/dialysis_service.go View File

@@ -928,6 +928,12 @@ func ExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int
928 928
 	return err
929 929
 }
930 930
 
931
+func GetExceDoctorAdviceGroupNo(groupNo int64, org_id int64) (advice []*models.DoctorAdvice, err error) {
932
+
933
+	err = XTReadDB().Where("groupno = ?  AND user_org_id = ? AND status = 1", groupNo, org_id).Find(&advice).Error
934
+	return advice, err
935
+}
936
+
931 937
 func ExceOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) {
932 938
 
933 939
 	ut := writeDb.Begin()

+ 5 - 9
service/manage_center_service.go View File

@@ -439,6 +439,8 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
439 439
 	storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
440 440
 	//退库
441 441
 	drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
442
+	fmt.Println("list223323232233223322323323223", len(list))
443
+
442 444
 	//如果剩余数量 + 退库数量 < 总入库数量
443 445
 	if len(list) > 0 {
444 446
 		for _, its := range list {
@@ -479,6 +481,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
479 481
 			fmt.Println("该批次总入库数量", sum_count)
480 482
 			if (over_count + out_count) <= sum_count {
481 483
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
484
+					fmt.Println("进来1", its.Count)
482 485
 					//退库
483 486
 					warehouseInfo := models.DrugWarehouseInfo{
484 487
 						StockMinNumber: its.Count,
@@ -486,6 +489,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
486 489
 					UpdateDrugWarehouse(its.WarehouseInfoId, warehouseInfo)
487 490
 				}
488 491
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
492
+					fmt.Println("进来2", its.Count)
489 493
 					warehouseInfo := models.DrugWarehouseInfo{
490 494
 						StockMaxNumber: its.Count,
491 495
 					}
@@ -493,6 +497,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
493 497
 				}
494 498
 
495 499
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
500
+					fmt.Println("进来3", its.Count)
496 501
 					warehouseInfo := models.DrugWarehouseInfo{
497 502
 						StockMaxNumber: its.Count,
498 503
 					}
@@ -630,7 +635,6 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
630 635
 				IsCheck:      1,
631 636
 			}
632 637
 			AddSigleDrugCancelStock(&cancelStock)
633
-			fmt.Println("到这里了吗32222222222222222222222222222222222222222222222")
634 638
 
635 639
 			manufactureName, _ := GetManufactureById(info.Manufacturer)
636 640
 			dealer, _ := GetDealerById(info.Dealer)
@@ -708,14 +712,6 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
708 712
 
709 713
 			houseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
710 714
 
711
-			if advice.PrescribingNumberUnit == drug.MaxUnit {
712
-				warehouseInfo := models.DrugWarehouseInfo{
713
-					StockMaxNumber: prescribingNumber,
714
-				}
715
-				UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
716
-
717
-			}
718
-
719 715
 			operation_time := time.Now().Unix()
720 716
 			ctime := time.Now().Unix()
721 717
 			timeStr := time.Now().Format("2006-01-02")

+ 6 - 6
service/statistics_service/index_evaluation_service.go View File

@@ -1241,9 +1241,9 @@ func GetDoctorWorkloadTableData(user_org_id int64, start_time int64, end_time in
1241 1241
 	userDb := service.UserReadDB()
1242 1242
 	db := service.XTReadDB()
1243 1243
 	if admin_user_id == 0 {
1244
-		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 2 ", user_org_id).Scan(&datas)
1244
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where  org_id = ?  AND user_type = 2 ", user_org_id).Scan(&datas)
1245 1245
 	} else {
1246
-		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 2  AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
1246
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where  org_id = ?  AND user_type = 2  AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
1247 1247
 	}
1248 1248
 	var sys_datas VMUserAdminRole
1249 1249
 	sys_datas.AdminUserId = 0
@@ -1273,9 +1273,9 @@ func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int
1273 1273
 	db := service.XTReadDB()
1274 1274
 
1275 1275
 	if admin_user_id == 0 {
1276
-		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 3 ", user_org_id).Scan(&datas)
1276
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where  org_id = ?  AND user_type = 3 ", user_org_id).Scan(&datas)
1277 1277
 	} else {
1278
-		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 3  AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
1278
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where   org_id = ?  AND user_type = 3  AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
1279 1279
 	}
1280 1280
 
1281 1281
 	var NewTotalOne int64
@@ -1449,9 +1449,9 @@ func GetNurseWorkloadTableData(user_org_id int64, start_time int64, end_time int
1449 1449
 	//db.Model(&models.Dataconfig{}).Where("name = '血管通路' AND module = 'hemodialysis' AND field_name = 'vascular_access_desc' AND parent_id = 0").First(&tempConfig)
1450 1450
 
1451 1451
 	if admin_user_id == 0 {
1452
-		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 3 ", user_org_id).Offset(offset).Limit(limit).Scan(&datas)
1452
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where org_id = ?  AND user_type = 3 ", user_org_id).Offset(offset).Limit(limit).Scan(&datas)
1453 1453
 	} else {
1454
-		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 3  AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
1454
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where org_id = ?  AND user_type = 3  AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
1455 1455
 	}
1456 1456
 
1457 1457
 	for _, item := range datas {

+ 3 - 3
service/stock_service.go View File

@@ -742,7 +742,7 @@ func CreateDrugFlowOne(flow models.DrugFlow) error {
742 742
 func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64, id int64) (models.DrugAutomaticReduceDetail, error) {
743 743
 	detail := models.DrugAutomaticReduceDetail{}
744 744
 	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
745
-	err = XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("patient_id =? and sys_record_time =? and drug_id = ? and status = 1 and advice_id =? and id = ?", patientid, recorddate, drugid, advice_id, id).Updates(map[string]interface{}{"status": 0}).Error
745
+	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
746 746
 	return detail, err
747 747
 }
748 748
 
@@ -4445,7 +4445,7 @@ func GetDrugWarehouseOrderDetailTwo(ids []int64, orgid int64, startime int64, en
4445 4445
 
4446 4446
 func GetDrugTotalCount(drugid int64, orgid int64, storehouse_id int64) (info models.VmDrugWarehouseInfo, err error) {
4447 4447
 
4448
-	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
4448
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1")
4449 4449
 	if drugid > 0 {
4450 4450
 		db = db.Where("x.drug_id = ?", drugid)
4451 4451
 	}
@@ -4461,7 +4461,7 @@ func GetDrugTotalCount(drugid int64, orgid int64, storehouse_id int64) (info mod
4461 4461
 
4462 4462
 func GetDrugTotalCountTwenty(drugid int64, orgid int64, storehouse_id int64) (info models.VmDrugWarehouseInfo, err error) {
4463 4463
 
4464
-	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 ")
4464
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1 and x.is_check = 1 ")
4465 4465
 	if drugid > 0 {
4466 4466
 		db = db.Where("x.drug_id = ?", drugid)
4467 4467
 	}

+ 63 - 55
service/warhouse_service.go View File

@@ -69,7 +69,7 @@ func DrugsDelivery(orgID int64, creater int64, advice *models.DoctorAdvice) (err
69 69
 		drup, _ := FindBaseDrugLibRecord(orgID, advice.DrugId)
70 70
 		if drup.ID > 0 {
71 71
 			prescribingNumber := advice.PrescribingNumber
72
-
72
+			fmt.Println("出库数量233322332233232233223323232我的", advice.PrescribingNumber, advice.PrescribingNumberUnit)
73 73
 			DrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice)
74 74
 
75 75
 		} else {
@@ -122,6 +122,8 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
122 122
 		var stockMin int64
123 123
 		stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
124 124
 		stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
125
+		fmt.Println("stockMax332332332233232", stockMax)
126
+		fmt.Println("stockMax332332332233232", stockMin)
125 127
 		ChangeMaxNumber(lastWarehouse.ID, stockMax)
126 128
 		UpdateMinNumber(lastWarehouse.ID, stockMin)
127 129
 	}
@@ -140,6 +142,8 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
140 142
 	//baseInfo, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
141 143
 
142 144
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
145
+	fmt.Println("剩余库存", stock_number)
146
+	fmt.Println("出库数量", deliver_number)
143 147
 	if stock_number >= deliver_number {
144 148
 
145 149
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
@@ -202,7 +206,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
202 206
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
203 207
 		fmt.Println(errOne)
204 208
 		//查询是否存在数据
205
-
209
+		fmt.Println("deliver_number2o222222222222", deliver_number)
206 210
 		details := &models.DrugAutomaticReduceDetail{
207 211
 			WarehouseOutId:          warehouseout.ID,
208 212
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
@@ -241,6 +245,9 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
241 245
 			}
242 246
 		}
243 247
 
248
+		fmt.Println("maxNumber", maxNumber)
249
+		fmt.Println("minNumber", minNumber)
250
+
244 251
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
245 252
 
246 253
 		if warehouse.StockMaxNumber < 0 {
@@ -252,30 +259,30 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
252 259
 
253 260
 		warehouse.Mtime = time.Now().Unix()
254 261
 
255
-		//if warehouse.StockMinNumber < minNumber {
256
-		//
257
-		//	warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
258
-		//	warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
259
-		//} else {
260
-		//	if minNumber > 0 {
261
-		//		warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
262
-		//	}
263
-		//
264
-		//	if minNumber == 0 && maxNumber != 1 {
265
-		//		if warehouse.StockMinNumber > 0 {
266
-		//			warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
267
-		//		}
268
-		//
269
-		//	}
270
-		//
271
-		//}
262
+		if warehouse.StockMinNumber < minNumber {
272 263
 
273
-		//if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
274
-		//	if (warehouse.StockMinNumber - deliver_number) > 0 {
275
-		//		warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
276
-		//	}
277
-		//
278
-		//}
264
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
265
+			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
266
+		} else {
267
+			if minNumber > 0 {
268
+				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
269
+			}
270
+
271
+			if minNumber == 0 && maxNumber != 1 {
272
+				if warehouse.StockMinNumber > 0 {
273
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
274
+				}
275
+
276
+			}
277
+
278
+		}
279
+
280
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
281
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
282
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
283
+			}
284
+
285
+		}
279 286
 
280 287
 		if drup.MaxUnit != drup.MinUnit {
281 288
 			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
@@ -294,6 +301,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
294 301
 
295 302
 		return nil
296 303
 	} else {
304
+		fmt.Println("库存数量", stock_number)
297 305
 		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
298 306
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
299 307
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
@@ -315,7 +323,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
315 323
 			ProductDate:             warehouse.ProductDate,
316 324
 			ExpiryDate:              warehouse.ExpiryDate,
317 325
 			PatientId:               advice.PatientId,
318
-			Count:                   deliver_number,
326
+			Count:                   stock_number,
319 327
 			WarehouseInfoId:         warehouse.ID,
320 328
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
321 329
 			StorehouseId:            storeConfig.DrugStorehouseOut,
@@ -336,7 +344,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
336 344
 			RecordTime:              advice.RecordDate,
337 345
 			OrgId:                   orgID,
338 346
 			DrugId:                  advice.DrugId,
339
-			Count:                   deliver_number,
347
+			Count:                   stock_number,
340 348
 			CountUnit:               drup.MinUnit,
341 349
 			WarehouseInfoId:         warehouse.ID,
342 350
 			StorehouseId:            storeConfig.DrugStorehouseOut,
@@ -414,11 +422,11 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
414 422
 
415 423
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
416 424
 		prescribingNumber_two_temp := deliver_number - stock_number
417
-
425
+		fmt.Println("剩余库存", prescribingNumber_two_temp)
418 426
 		overPlusNumber := float64(prescribingNumber_two_temp)
419 427
 
420 428
 		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
421
-		advice.PrescribingNumberUnit = advice.PrescribingNumberUnit
429
+		advice.PrescribingNumberUnit = drup.MinUnit
422 430
 
423 431
 		DrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice)
424 432
 	}
@@ -647,9 +655,9 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
647 655
 		maxNumber = deliver_number / drup.MinNumber
648 656
 		minNumber = deliver_number % drup.MinNumber
649 657
 
650
-		//if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
651
-		//	minNumber = maxNumber
652
-		//}
658
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
659
+			minNumber = maxNumber
660
+		}
653 661
 
654 662
 		if drup.MaxUnit != drup.MinUnit {
655 663
 			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
@@ -670,29 +678,29 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
670 678
 
671 679
 		warehouse.Mtime = time.Now().Unix()
672 680
 
673
-		//if warehouse.StockMinNumber < minNumber {
674
-		//
675
-		//	warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
676
-		//	warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
677
-		//} else {
678
-		//
679
-		//	if minNumber > 0 {
680
-		//		warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
681
-		//	}
682
-		//
683
-		//	if minNumber == 0 && maxNumber != 1 {
684
-		//		if warehouse.StockMinNumber > 0 {
685
-		//			warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
686
-		//		}
687
-		//
688
-		//	}
689
-		//}
681
+		if warehouse.StockMinNumber < minNumber {
690 682
 
691
-		//if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
692
-		//	if (warehouse.StockMinNumber - deliver_number) > 0 {
693
-		//		warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
694
-		//	}
695
-		//}
683
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
684
+			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
685
+		} else {
686
+
687
+			if minNumber > 0 {
688
+				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
689
+			}
690
+
691
+			if minNumber == 0 && maxNumber != 1 {
692
+				if warehouse.StockMinNumber > 0 {
693
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
694
+				}
695
+
696
+			}
697
+		}
698
+
699
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
700
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
701
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
702
+			}
703
+		}
696 704
 
697 705
 		if drup.MaxUnit != drup.MinUnit {
698 706
 			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
@@ -841,7 +849,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
841 849
 
842 850
 		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
843 851
 
844
-		advice.PrescribingNumberUnit = advice.PrescribingNumberUnit
852
+		advice.PrescribingNumberUnit = drup.MinUnit
845 853
 
846 854
 		HisDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice)
847 855
 	}