Browse Source

耗材参数

XMLWAN 3 years ago
parent
commit
1fcc38b980

+ 2 - 2
conf/app.conf View File

@@ -1,6 +1,6 @@
1 1
 appname = 血透
2
-httpport = 9531
3
-runmode = prod
2
+httpport = 9529
3
+runmode = dev
4 4
 
5 5
 #
6 6
 copyrequestbody = true

+ 29 - 8
controllers/stock_in_api_controller.go View File

@@ -1099,7 +1099,8 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1099 1099
 	}
1100 1100
 
1101 1101
 	var warehousingOutInfo []*models.WarehouseOutInfo
1102
-
1102
+	var beforePrepares []*models.DialysisBeforePrepareGoods
1103
+	var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
1103 1104
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1104 1105
 		thisStockIn, _ := dataBody["stockOut"].([]interface{})
1105 1106
 		if len(thisStockIn) > 0 {
@@ -1156,20 +1157,40 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1156 1157
 				}
1157 1158
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1158 1159
 
1160
+				prepareGoods := &models.DialysisBeforePrepareGoods{
1161
+					GoodTypeId: good_type_id,
1162
+					GoodId:     good_id,
1163
+					Count:      count,
1164
+				}
1165
+
1166
+				beforePrepares = append(beforePrepares, prepareGoods)
1167
+
1168
+				newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
1169
+					GoodTypeId: good_type_id,
1170
+					GoodId:     good_id,
1171
+					Count:      count,
1172
+				}
1173
+				newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
1159 1174
 			}
1160 1175
 		}
1161 1176
 	}
1162
-	errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1163
-	info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1164
-	if errs != nil {
1165
-		utils.ErrorLog(errs.Error())
1166
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1167
-		return
1177
+
1178
+	//查询库存
1179
+	for _, item := range warehousingOutInfo {
1180
+		parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
1181
+		fmt.Println(parseDateErr)
1168 1182
 	}
1169 1183
 
1184
+	//errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1185
+	//info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1186
+	//if errs != nil {
1187
+	//	utils.ErrorLog(errs.Error())
1188
+	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1189
+	//	return
1190
+	//}
1191
+
1170 1192
 	c.ServeSuccessJSON(map[string]interface{}{
1171 1193
 		"msg":                   "出库成功",
1172
-		"info":                  info,
1173 1194
 		"warehousing_out_order": warehousing_out_order,
1174 1195
 	})
1175 1196
 

+ 2 - 6
models/drug.go View File

@@ -65,12 +65,8 @@ type BaseDrugLib struct {
65 65
 	HospApprFlag                int64   `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
66 66
 	LmtUsedFlag                 int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
67 67
 	//MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
68
-	DrugDay      string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
69
-	Total        float64 `gorm:"column:total" json:"total" form:"total"`
70
-	Dosage       string  `gorm:"column:dosage" json:"dosage" form:"dosage"`
71
-	Unval        string  `gorm:"column:unval" json:"unval" form:"unval"`
72
-	PackingUnit  string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
73
-	PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
68
+	DrugDay string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
69
+	Total   float64 `gorm:"column:total" json:"total" form:"total"`
74 70
 }
75 71
 
76 72
 func (BaseDrugLib) TableName() string {

+ 0 - 1
models/stock_models.go View File

@@ -80,7 +80,6 @@ type WarehousingInfo struct {
80 80
 	ExpiryDate       int64       `gorm:"column:expiry_date" json:"expiry_date"`
81 81
 	WarehousingCount int64       `gorm:"column:warehousing_count" json:"warehousing_count"`
82 82
 	WarehousingUnit  string      `gorm:"column:warehousing_unit" json:"warehousing_unit"`
83
-	StockNumber      int64       `gorm:"column:stock_number" json:"stock_number"`
84 83
 	Price            float64     `gorm:"column:price" json:"price"`
85 84
 	TotalPrice       float64     `gorm:"column:total_price" json:"total_price"`
86 85
 	Dealer           int64       `gorm:"column:dealer" json:"dealer"`

+ 29 - 0
service/stock_service.go View File

@@ -484,6 +484,7 @@ func FindLastWarehousingInfoByID(drug_id int64) (info models.WarehousingInfo, er
484 484
 	err = readDb.Model(&models.WarehousingInfo{}).Where("drup_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) ", drug_id).Order("ctime").First(&info).Error
485 485
 	return info, err
486 486
 }
487
+
487 488
 //
488 489
 //// 出库时先进先出,找出最先入库的批次
489 490
 //func  (drug_id int64) (info models.WarehousingInfo, err error) {
@@ -2098,12 +2099,35 @@ func GetStockInRecoredByGoodId(goodid int64, goodtypeid int64, recordtime int64,
2098 2099
 	return &info, nil
2099 2100
 }
2100 2101
 
2102
+func GetStockInRecoredByGoodIdOne(goodid int64, goodtypeid int64, recordtime int64, orgid int64) (*models.WarehouseOutInfo, error) {
2103
+
2104
+	info := models.WarehouseOutInfo{}
2105
+
2106
+	err := XTReadDB().Model(&info).Where("good_id = ? and good_type_id = ? and sys_record_time = ?  and org_id = ? and status = 1", goodid, goodtypeid, recordtime, orgid).Find(&info).Error
2107
+
2108
+	if err == gorm.ErrRecordNotFound {
2109
+		return nil, err
2110
+	}
2111
+
2112
+	if err != nil {
2113
+		return nil, err
2114
+	}
2115
+
2116
+	return &info, nil
2117
+}
2118
+
2101 2119
 func UpdateAutoMaticReduceDetail(goodid int64, goodtypeid int64, recordtime int64, patientid int64, orgid int64, prepare *models.WarehouseOutInfo) error {
2102 2120
 
2103 2121
 	err := XTWriteDB().Model(&prepare).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and patient_id = ? and org_id = ? and status =1", goodid, goodtypeid, recordtime, patientid, orgid).Updates(map[string]interface{}{"count": prepare.Count}).Error
2104 2122
 	return err
2105 2123
 }
2106 2124
 
2125
+func UpdateAutoMaticReduceDetailOne(goodid int64, goodtypeid int64, recordtime int64, orgid int64, prepare *models.WarehouseOutInfo) error {
2126
+
2127
+	err := XTWriteDB().Model(&prepare).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and org_id = ? and status =1", goodid, goodtypeid, recordtime, orgid).Updates(map[string]interface{}{"count": prepare.Count}).Error
2128
+	return err
2129
+}
2130
+
2107 2131
 func AddSigleWarehouseOutInfo(info *models.WarehouseOutInfo) error {
2108 2132
 
2109 2133
 	err := writeDb.Create(&info).Error
@@ -2144,6 +2168,11 @@ func FindStockOutInfoByStock(org_id int64, good_type_id int64, good_id int64, re
2144 2168
 	return
2145 2169
 }
2146 2170
 
2171
+func FindStockOutInfoByStockOne(org_id int64, good_type_id int64, good_id int64, record_date int64) (out []*models.WarehouseOutInfo, err error) {
2172
+	err = readDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND sys_record_time = ?", org_id, good_type_id, good_id, record_date).Order("ctime desc").Find(&out).Error
2173
+	return
2174
+}
2175
+
2147 2176
 func FindDrugStockOutInfoByTypeId(org_id int64, drug_id int64, out_id int64, number string) (out models.DrugWarehouseOutInfo, err error) {
2148 2177
 	err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND  drug_id = ? AND is_sys = 1 AND  (warehouse_out_id = ? or warehouse_out_order_number = ?)", org_id, drug_id, out_id, number).First(&out).Error
2149 2178
 	return

+ 19 - 576
service/warhouse_service.go View File

@@ -871,563 +871,6 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
871 871
 				CreateAutoReduceRecord(&details)
872 872
 			}
873 873
 		}
874
-//
875
-//import (
876
-//	"XT_New/models"
877
-//	"XT_New/utils"
878
-//	"errors"
879
-//	"fmt"
880
-//	_ "fmt"
881
-//	"github.com/jinzhu/gorm"
882
-//	"math"
883
-//	"strconv"
884
-//	"strings"
885
-//	"time"
886
-//)
887
-//
888
-//// 药品出库
889
-//
890
-//func DrugsDelivery(orgID int64, advice *models.DoctorAdvice) (err error) {
891
-//	// 1.判断药品是否来自专用字典的药品库
892
-//	// 2.判断当天当前机构有没有创建出库单,没有则创建
893
-//	// 3.创建出库流程
894
-//	// 3.1 实现先进先出逻辑 由于药品执行后,不可以修改和删除,所以不考虑出库后的退库和修改出库数量等
895
-//	isHasWay := false
896
-//	record_time := int64(0)
897
-//	if advice.Way == 1 {
898
-//		isHasWay = true
899
-//		record_time = advice.RecordDate
900
-//	}
901
-//	if isHasWay {
902
-//		//判断当天当前机构有没有创建出库单,没有则创建
903
-//		out, err := FindDrugStockOutByIsSys(orgID, 1, record_time)
904
-//		if err == gorm.ErrRecordNotFound {
905
-//			timeStr := time.Now().Format("2006-01-02")
906
-//			timeArr := strings.Split(timeStr, "-")
907
-//			total, _ := FindAllDrugWarehouseOut(orgID)
908
-//			total = total + 1
909
-//			warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
910
-//			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
911
-//			number = number + total
912
-//			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
913
-//			// creater := adminUserInfo.AdminUser.Id
914
-//			warehouseOut := models.DrugWarehouseOut{
915
-//				WarehouseOutOrderNumber: warehousing_out_order,
916
-//				OperationTime:           time.Now().Unix(),
917
-//				OrgId:                   orgID,
918
-//				Creater:                 0,
919
-//				Ctime:                   time.Now().Unix(),
920
-//				Status:                  1,
921
-//				WarehouseOutTime:        record_time,
922
-//				Dealer:                  0,
923
-//				Manufacturer:            0,
924
-//				Type:                    1,
925
-//				IsSys:                   1,
926
-//			}
927
-//			err := AddSigleDrugWarehouseOut(&warehouseOut)
928
-//			if err != nil {
929
-//				utils.TraceLog("创建出库单失败 err = %v", err)
930
-//				return err
931
-//			} else {
932
-//				out = warehouseOut
933
-//			}
934
-//		}
935
-//
936
-//		// 出库流程
937
-//		// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
938
-//		drup, _ := FindBaseDrugLibRecord(orgID, advice.DrugId)
939
-//		if drup.ID > 0 {
940
-//			prescribingNumber := advice.PrescribingNumber
941
-//			DrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice)
942
-//		} else {
943
-//			return errors.New("药品信息不存在")
944
-//		}
945
-//
946
-//	}
947
-//
948
-//	return
949
-//}
950
-//
951
-//// 药品出库 递归方式
952
-//func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DoctorAdvice) (err error) {
953
-//	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
954
-//	var deliver_number int64 = 0
955
-//	var stock_number int64 = 0
956
-//
957
-//	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
958
-//	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
959
-//	if advice.PrescribingNumberUnit == drup.MaxUnit {
960
-//		deliver_number = count * drup.MinNumber
961
-//	} else {
962
-//		deliver_number = count
963
-//	}
964
-//
965
-//	// 根据先进先出原则,查询最先入库的批次,进行出库
966
-//	// 如果没有对应的库存,则报错
967
-//	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId)
968
-//	fmt.Println("查询222222222222222222222222222222222222222222222222", err)
969
-//	if err != nil {
970
-//		return err
971
-//	}
972
-//
973
-//	// 将该批次的剩余库存数量转换为拆零数量
974
-//	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
975
-//	// 当库存数量大于或等于出库数量的话,则正常出库该批次
976
-//	if stock_number >= deliver_number {
977
-//		warehouseOutInfo := &models.DrugWarehouseOutInfo{
978
-//			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
979
-//			WarehouseOutId:          warehouseout.ID,
980
-//			Status:                  1,
981
-//			Ctime:                   time.Now().Unix(),
982
-//			Remark:                  "",
983
-//			OrgId:                   orgID,
984
-//			Type:                    1,
985
-//			Manufacturer:            0,
986
-//			Dealer:                  0,
987
-//			IsSys:                   1,
988
-//			SysRecordTime:           advice.RecordDate,
989
-//			DrugId:                  advice.DrugId,
990
-//		}
991
-//		warehouseOutInfo.Count = deliver_number
992
-//		warehouseOutInfo.CountUnit = drup.MinUnit
993
-//		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
994
-//		if errOne != nil {
995
-//			return errOne
996
-//		} else {
997
-//			// prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
998
-//			// count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
999
-//			details := &models.DrugAutomaticReduceDetail{
1000
-//				WarehouseOutId:          warehouseOutInfo.ID,
1001
-//				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1002
-//				PatientId:               advice.PatientId,
1003
-//				Ctime:                   time.Now().Unix(),
1004
-//				Mtime:                   time.Now().Unix(),
1005
-//				Status:                  1,
1006
-//				RecordTime:              advice.RecordDate,
1007
-//				OrgId:                   orgID,
1008
-//				DrugId:                  advice.DrugId,
1009
-//				Count:                   deliver_number,
1010
-//				CountUnit:               drup.MinUnit,
1011
-//			}
1012
-//			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
1013
-//			if errTwo != nil {
1014
-//				return errTwo
1015
-//			}
1016
-//		}
1017
-//		// 出库完成后,要减去对应批次的库存数量
1018
-//		// 判断处方里药品单位是拆零单位还是包装单位,	如果是拆零单位,则根据规格,将拆零数量转为包装数量
1019
-//		var maxNumber int64 = 0
1020
-//		var minNumber int64 = 0
1021
-//		if advice.PrescribingNumberUnit == drup.MinUnit {
1022
-//			maxNumber = count / drup.MinNumber
1023
-//			minNumber = count % drup.MinNumber
1024
-//		} else {
1025
-//			maxNumber = count
1026
-//		}
1027
-//
1028
-//		if warehouse.StockMaxNumber < maxNumber {
1029
-//			return errors.New("库存数量不足")
1030
-//		}
1031
-//
1032
-//		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
1033
-//		warehouse.Mtime = time.Now().Unix()
1034
-//		if warehouse.StockMinNumber < minNumber {
1035
-//			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
1036
-//			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
1037
-//		} else {
1038
-//			warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
1039
-//		}
1040
-//
1041
-//		if warehouse.StockMaxNumber < 0 {
1042
-//			return errors.New("库存数量不足")
1043
-//		}
1044
-//		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
1045
-//		if errThree != nil {
1046
-//			return errThree
1047
-//		}
1048
-//
1049
-//		return nil
1050
-//	} else {
1051
-//		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1052
-//		warehouseOutInfo := &models.DrugWarehouseOutInfo{
1053
-//			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
1054
-//			WarehouseOutId:          warehouseout.ID,
1055
-//			Status:                  1,
1056
-//			Ctime:                   time.Now().Unix(),
1057
-//			Remark:                  "",
1058
-//			OrgId:                   orgID,
1059
-//			Type:                    1,
1060
-//			Manufacturer:            0,
1061
-//			Dealer:                  0,
1062
-//			IsSys:                   1,
1063
-//			SysRecordTime:           advice.RecordDate,
1064
-//			DrugId:                  advice.DrugId,
1065
-//		}
1066
-//		// prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1067
-//		// count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1068
-//		warehouseOutInfo.Count = stock_number
1069
-//		warehouseOutInfo.CountUnit = drup.MinUnit
1070
-//
1071
-//		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1072
-//		if errOne != nil {
1073
-//			return errOne
1074
-//		} else {
1075
-//			details := &models.DrugAutomaticReduceDetail{
1076
-//				WarehouseOutId:          warehouseOutInfo.ID,
1077
-//				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1078
-//				PatientId:               advice.PatientId,
1079
-//				Ctime:                   time.Now().Unix(),
1080
-//				Mtime:                   time.Now().Unix(),
1081
-//				Status:                  1,
1082
-//				RecordTime:              advice.RecordDate,
1083
-//				OrgId:                   orgID,
1084
-//				DrugId:                  advice.DrugId,
1085
-//				Count:                   stock_number,
1086
-//				CountUnit:               drup.MinUnit,
1087
-//			}
1088
-//			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
1089
-//			if errTwo != nil {
1090
-//				return errTwo
1091
-//			}
1092
-//		}
1093
-//		// 出库完成后,要将该批次库存清零
1094
-//		warehouse.StockMaxNumber = 0
1095
-//		warehouse.StockMinNumber = 0
1096
-//		warehouse.Mtime = time.Now().Unix()
1097
-//		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
1098
-//		if errThree != nil {
1099
-//			return errThree
1100
-//		}
1101
-//		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1102
-//		prescribingNumber_two_temp := deliver_number - stock_number
1103
-//		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
1104
-//		advice.PrescribingNumberUnit = drup.MinUnit
1105
-//		DrugDeliverInfo(orgID, prescribingNumber, warehouseout, drup, advice)
1106
-//	}
1107
-//	return
1108
-//}
1109
-//
1110
-//// 耗材出库
1111
-//func ConsumablesDeliveryTotal(orgID int64,patient_id int64,record_time int64,goods []models.DialysisBeforePrepareGoods) (err error) {
1112
-//	//查询该患者当天已经出库的耗材信息
1113
-//	goods_yc,_ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
1114
-//	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
1115
-//	for i := len(goods_yc) - 1; i >= 0; i--{
1116
-//		goods_yc_temp := goods_yc[i]
1117
-//		for j := len(goods) - 1; j >= 0; j-- {
1118
-//			goods_temp := goods[j]
1119
-//			// 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
1120
-//			if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId{
1121
-//				// 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
1122
-//				if goods_yc_temp.Count == goods_temp.Count {
1123
-//					goods_yc = append(goods_yc[:i],goods_yc[i+1:]...)
1124
-//					goods = append(goods[:j],goods[j+1:]...)
1125
-//				}
1126
-//
1127
-//				// 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
1128
-//				if goods_yc_temp.Count > goods_temp.Count {
1129
-//					temp_count := goods_yc_temp.Count - goods_temp.Count
1130
-//					goods_yc[i].Count = temp_count
1131
-//					goods = append(goods[:j],goods[j+1:]...)
1132
-//				}
1133
-//
1134
-//				// 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
1135
-//				if goods_yc_temp.Count < goods_temp.Count {
1136
-//					temp_count := goods_temp.Count - goods_yc_temp.Count
1137
-//					goods[j].Count = temp_count
1138
-//					goods_yc = append(goods_yc[:i],goods_yc[i+1:]...)
1139
-//				}
1140
-//			}
1141
-//		}
1142
-//	}
1143
-//
1144
-//	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1145
-//	// goods 这个数据就是需要出库的耗材的数据
1146
-//	if len(goods) > 0 {
1147
-//		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1148
-//		if err == gorm.ErrRecordNotFound {
1149
-//			//没有记录,则创建出库单
1150
-//			timeStr := time.Now().Format("2006-01-02")
1151
-//			timeArr := strings.Split(timeStr, "-")
1152
-//			total, _ :=  FindAllWarehouseOut(orgID)
1153
-//			total = total + 1
1154
-//			warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1155
-//			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1156
-//			number = number + total
1157
-//			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1158
-//			warehouseOut := models.WarehouseOut{
1159
-//				WarehouseOutOrderNumber: warehousing_out_order,
1160
-//				OperationTime:           time.Now().Unix(),
1161
-//				OrgId:                   orgID,
1162
-//				Creater:                 0,
1163
-//				Ctime:                   time.Now().Unix(),
1164
-//				Status:                  1,
1165
-//				WarehouseOutTime:        record_time,
1166
-//				Dealer:                  0,
1167
-//				Manufacturer:            0,
1168
-//				Type:                    1,
1169
-//				IsSys:                   1,
1170
-//			}
1171
-//			err := AddSigleWarehouseOut(&warehouseOut)
1172
-//			if err != nil {
1173
-//				utils.TraceLog("创建出库单失败 err = %v", err)
1174
-//				return err
1175
-//			} else {
1176
-//				out = warehouseOut
1177
-//			}
1178
-//		}
1179
-//		for _,good := range goods {
1180
-//			ConsumablesDelivery(orgID ,patient_id ,record_time ,good,out )
1181
-//		}
1182
-//	}
1183
-//
1184
-//	if len(goods_yc) > 0 {
1185
-//		for _,good_yc := range goods_yc{
1186
-//			ConsumablesDeliveryDelete(orgID ,patient_id ,record_time ,good_yc ,out )
1187
-//		}
1188
-//	}
1189
-//
1190
-//	return nil
1191
-//}
1192
-//
1193
-//// 耗材出库
1194
-//func ConsumablesDelivery(orgID int64,patient_id int64,record_time int64,goods models.DialysisBeforePrepareGoods,warehouseOut models.WarehouseOut) (err error) {
1195
-//	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
1196
-//	var deliver_number int64 = 0
1197
-//	var stock_number int64 = 0
1198
-//
1199
-//	deliver_number = good.Count
1200
-//
1201
-//
1202
-//	// 根据先进先出原则,查询最先入库的批次,进行出库
1203
-//	// 如果没有对应的库存,则报错
1204
-//	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId,goods.GoodTypeId)
1205
-//	if err != nil {
1206
-//		return err
1207
-//	}
1208
-//
1209
-//	// 将该批次的剩余库存数量转换为拆零数量
1210
-//	stock_number = warehouse.StockCount
1211
-//	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1212
-//	if stock_number >= deliver_number {
1213
-//		warehouseOutInfo := &models.WarehouseOutInfo{
1214
-//			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1215
-//			WarehouseOutId:          warehouseOut.ID,
1216
-//			WarehouseInfoId:		 warehouse.ID,
1217
-//			Status:                  1,
1218
-//			Ctime:                   time.Now().Unix(),
1219
-//			Remark:                  "",
1220
-//			OrgId:                   orgID,
1221
-//			Type:                    1,
1222
-//			Manufacturer:            0,
1223
-//			Dealer:                  0,
1224
-//			IsSys:                   1,
1225
-//			SysRecordTime:           record_time,
1226
-//			GoodTypeId:              goods.GoodTypeId,
1227
-//			GoodId:                  goods.GoodId,
1228
-//			PatientId:				 patient_id,
1229
-//		}
1230
-//		warehouseOutInfo.Count = goods.Count
1231
-//		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1232
-//		warehouseOutInfo.Price = stockInInfo.Price
1233
-//		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1234
-//		if errOne != nil {
1235
-//			return errOne
1236
-//		} else {
1237
-//			details := &models.AutomaticReduceDetail{
1238
-//				WarehouseOutId:          warehouseOutInfo.ID,
1239
-//				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1240
-//				PatientId:               patient_id,
1241
-//				Ctime:                   time.Now().Unix(),
1242
-//				Mtime:                   time.Now().Unix(),
1243
-//				Status:                  1,
1244
-//				RecordTime:              record_time,
1245
-//				OrgId:                   orgID,
1246
-//				GoodId:                  goods.GoodId,
1247
-//				GoodTypeId:              goods.GoodTypeId,
1248
-//				Count:                   goods.Count,
1249
-//			}
1250
-//			errTwo := service.AddSigleAutoReduceRecordInfo(details)
1251
-//			if errTwo != nil {
1252
-//				return errTwo
1253
-//			}
1254
-//		}
1255
-//
1256
-//		// 出库完成后,要减去对应批次的库存数量
1257
-//
1258
-//		maxNumber = goods.Count
1259
-//
1260
-//
1261
-//		if warehouse.StockMaxNumber < maxNumber {
1262
-//			return errors.New("库存数量不足")
1263
-//		}
1264
-//
1265
-//		warehouse.StockNumber = warehouse.StockMaxNumber - maxNumber
1266
-//		warehouse.Mtime = time.Now().Unix()
1267
-//
1268
-//
1269
-//		if warehouse.StockNumber < 0 {
1270
-//			return errors.New("库存数量不足")
1271
-//		}
1272
-//		errThree := UpDateWarehouseInfoByStock(&warehouse)
1273
-//		if errThree != nil {
1274
-//			return errThree
1275
-//		}
1276
-//
1277
-//		return nil
1278
-//	}  else {
1279
-//		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1280
-//		warehouseOutInfo := &models.WarehouseOutInfo{
1281
-//			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1282
-//			WarehouseOutId:          warehouseOut.ID,
1283
-//			WarehouseInfoId:		 warehouse.ID,
1284
-//			Status:                  1,
1285
-//			Ctime:                   time.Now().Unix(),
1286
-//			Remark:                  "",
1287
-//			OrgId:                   orgID,
1288
-//			Type:                    1,
1289
-//			Manufacturer:            0,
1290
-//			Dealer:                  0,
1291
-//			IsSys:                   1,
1292
-//			SysRecordTime:           record_time,
1293
-//			GoodTypeId:              goods..GoodTypeId,
1294
-//			GoodId:                  goods.GoodId,
1295
-//			PatientId:				 patient_id,
1296
-//		}
1297
-//		warehouseOutInfo.Count = stock_number
1298
-//		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1299
-//		warehouseOutInfo.Price = stockInInfo.Price
1300
-//		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1301
-//		if errOne != nil {
1302
-//			return errOne
1303
-//		} else {
1304
-//			details := &models.AutomaticReduceDetail{
1305
-//				WarehouseOutId:          warehouseOutInfo.ID,
1306
-//				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1307
-//				PatientId:               patient_id,
1308
-//				Ctime:                   time.Now().Unix(),
1309
-//				Mtime:                   time.Now().Unix(),
1310
-//				Status:                  1,
1311
-//				RecordTime:              record_time,
1312
-//				OrgId:                   orgID,
1313
-//				GoodId:                  goods.GoodId,
1314
-//				GoodTypeId:              goods.GoodTypeId,
1315
-//				Count:                   goods.Count,
1316
-//			}
1317
-//			errTwo := service.AddSigleAutoReduceRecordInfo(details)
1318
-//			if errTwo != nil {
1319
-//				return errTwo
1320
-//			}
1321
-//		}
1322
-//		// 出库完成后,要将该批次库存清零
1323
-//		warehouse.StockNumber = 0
1324
-//		warehouse.Mtime = time.Now().Unix()
1325
-//		errThree := UpDateWarehouseInfoByStock(&warehouse)
1326
-//		if errThree != nil {
1327
-//			return errThree
1328
-//		}
1329
-//		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1330
-//		goods.Count := deliver_number - stock_number
1331
-//
1332
-//		ConsumablesDelivery(orgID ,patient_id ,record_time ,good,out )
1333
-//	}
1334
-//	return nil
1335
-//}
1336
-//
1337
-//// 耗材出库删除
1338
-//func ConsumablesDeliveryDelete(orgID int64,patient_id int64,record_time int64,good_yc models.DialysisBeforePrepare,warehouseOut models.WarehouseOut) (err error) {
1339
-//	// 先根据相关信息查询当天该耗材的出库信息
1340
-//	warehouseOutInfos,err :=FindStockOutInfoByStock(orgID,good_yc.GoodTypeId,good_yc.GoodId,record_time,patient_id)
1341
-//	if err != nil {
1342
-//		return err
1343
-//	}
1344
-//
1345
-//	var delete_count int64 = 0
1346
-//
1347
-//	for _ , ware := range warehouseOutInfos{
1348
-//		// 判断当前出库的数据和删除出库数量
1349
-//		if good_yc.Count <= ware.Count {
1350
-//			delete_count = good_yc.Count
1351
-//		} else {
1352
-//			delete_count = ware.Count
1353
-//		}
1354
-//		// 在出库记录表里记录退库详情
1355
-//		warehouseOutInfo := &models.WarehouseOutInfo{
1356
-//			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1357
-//			WarehouseOutId:          warehouseOut.ID,
1358
-//			WarehouseInfoId:		 warehouse.ID,
1359
-//			Status:                  1,
1360
-//			Ctime:                   time.Now().Unix(),
1361
-//			Remark:                  "",
1362
-//			OrgId:                   orgID,
1363
-//			Type:                    1,
1364
-//			Manufacturer:            0,
1365
-//			Dealer:                  0,
1366
-//			IsSys:                   2,
1367
-//			SysRecordTime:           record_time,
1368
-//			GoodTypeId:              goods..GoodTypeId,
1369
-//			GoodId:                  goods.GoodId,
1370
-//			PatientId:				 patient_id,
1371
-//		}
1372
-//		warehouseOutInfo.Count = delete_count
1373
-//		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1374
-//		warehouseOutInfo.Price = stockInInfo.Price
1375
-//		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1376
-//		if errOne != nil {
1377
-//			return errOne
1378
-//		} else {
1379
-//			details := &models.AutomaticReduceDetail{
1380
-//				WarehouseOutId:          warehouseOutInfo.ID,
1381
-//				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1382
-//				PatientId:               patient_id,
1383
-//				Ctime:                   time.Now().Unix(),
1384
-//				Mtime:                   time.Now().Unix(),
1385
-//				Status:                  1,
1386
-//				RecordTime:              record_time,
1387
-//				OrgId:                   orgID,
1388
-//				GoodId:                  goods.GoodId,
1389
-//				GoodTypeId:              goods.GoodTypeId,
1390
-//				Count:                   delete_count,
1391
-//				Type:					 2,
1392
-//			}
1393
-//			errTwo := AddSigleAutoReduceRecordInfo(details)
1394
-//			if errTwo != nil {
1395
-//				return errTwo
1396
-//			}
1397
-//		}
1398
-//
1399
-//		// 删除出库完成后,要增加对应批次的库存数量
1400
-//
1401
-//
1402
-//
1403
-//		errThree := UpDateWarehouseInfoByStockDelete(ware.WarehouseInfoId,delete_count)
1404
-//		if errThree != nil {
1405
-//			return errThree
1406
-//		}
1407
-//
1408
-//		// 增加了对应的库存后,看看还有多少需要退库的
1409
-//		good_yc.Count = goods_yc.Count - delete_count
1410
-//		if good_yc.Count == 0 {
1411
-//			return nil
1412
-//		}
1413
-//	}
1414
-//
1415
-//	if good_yd.Count == 0 {
1416
-//		return nil
1417
-//	}  else {
1418
-//		return errors.New("退库和出库数据不匹配")
1419
-//	}
1420
-//}
1421
-
1422
-		// 出库完成后,要减去对应批次的库存数量
1423
-
1424
-		//查询是否有出库记录
1425
-		//_, errcodeOne := GetAutoDialysisBefor(goods.GoodId, goods.GoodTypeId, goods.PatientId, goods.UserOrgId, goods.RecordDate)
1426
-		//if errcodeOne == gorm.ErrRecordNotFound{
1427
-		//  maxNumber = goods.Count
1428
-		//}else if errcodeOne == nil{
1429
-		//  maxNumber = goods.NewCount
1430
-		//}
1431 874
 		fmt.Println("newcount9999999999999999999999999999999", goods.NewCount)
1432 875
 		maxNumber = goods.NewCount
1433 876
 
@@ -1758,20 +1201,25 @@ func ConsumablesDeliveryTotalOne(orgID int64, patient_id int64, record_time int6
1758 1201
 		}
1759 1202
 
1760 1203
 		for _, item := range goodOne {
1761
-			prepare := models.DialysisBeforePrepare{
1204
+			//prepare := models.DialysisBeforePrepare{
1205
+			//	GoodTypeId: item.GoodTypeId,
1206
+			//	GoodId:     item.GoodId,
1207
+			//	Count:      item.Count,
1208
+			//	NewCount:   item.NewCount,
1209
+			//}
1210
+			info := models.WarehouseOutInfo{
1762 1211
 				GoodTypeId: item.GoodTypeId,
1763 1212
 				GoodId:     item.GoodId,
1764 1213
 				Count:      item.Count,
1765
-				NewCount:   item.NewCount,
1766 1214
 			}
1767
-			ConsumablesDeliveryOne(orgID, patient_id, record_time, &prepare, &out, item.Count)
1215
+			ConsumablesDeliveryOne(orgID, record_time, &info, &out, item.Count)
1768 1216
 		}
1769 1217
 	}
1770 1218
 
1771 1219
 	if len(goods_yc) > 0 {
1772 1220
 		for _, good_yc := range goods_yc {
1773 1221
 			out, _ := FindStockOutByIsSys(orgID, 1, record_time)
1774
-			ConsumablesDeliveryDeleteOne(orgID, patient_id, record_time, good_yc, &out)
1222
+			ConsumablesDeliveryDeleteOne(orgID, record_time, good_yc, &out)
1775 1223
 		}
1776 1224
 	}
1777 1225
 
@@ -1779,7 +1227,7 @@ func ConsumablesDeliveryTotalOne(orgID int64, patient_id int64, record_time int6
1779 1227
 }
1780 1228
 
1781 1229
 //耗材出库
1782
-func ConsumablesDeliveryOne(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
1230
+func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.WarehouseOutInfo, warehouseOut *models.WarehouseOut, count int64) (err error) {
1783 1231
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
1784 1232
 	var deliver_number int64 = 0
1785 1233
 	var stock_number int64 = 0
@@ -1812,18 +1260,17 @@ func ConsumablesDeliveryOne(orgID int64, patient_id int64, record_time int64, go
1812 1260
 			Type:                    1,
1813 1261
 			Manufacturer:            0,
1814 1262
 			Dealer:                  0,
1815
-			IsSys:                   1,
1263
+			IsSys:                   2,
1816 1264
 			SysRecordTime:           record_time,
1817 1265
 			GoodTypeId:              goods.GoodTypeId,
1818 1266
 			GoodId:                  goods.GoodId,
1819
-			PatientId:               patient_id,
1820 1267
 		}
1821 1268
 		warehouseOutInfo.Count = goods.Count
1822 1269
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1823 1270
 		warehouseOutInfo.Price = stockInInfo.Price
1824 1271
 
1825 1272
 		//判断当前耗材是否有出库详情记录
1826
-		_, errcode := GetStockInRecoredByGoodId(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID)
1273
+		_, errcode := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, record_time, orgID)
1827 1274
 		if errcode == gorm.ErrRecordNotFound {
1828 1275
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1829 1276
 			if errOne != nil {
@@ -1841,17 +1288,16 @@ func ConsumablesDeliveryOne(orgID int64, patient_id int64, record_time int64, go
1841 1288
 				Type:                    1,
1842 1289
 				Manufacturer:            0,
1843 1290
 				Dealer:                  0,
1844
-				IsSys:                   1,
1291
+				IsSys:                   2,
1845 1292
 				SysRecordTime:           record_time,
1846 1293
 				GoodTypeId:              goods.GoodTypeId,
1847 1294
 				GoodId:                  goods.GoodId,
1848
-				PatientId:               patient_id,
1849 1295
 			}
1850 1296
 			warehouseOutInfo.Count = goods.Count
1851 1297
 
1852 1298
 		}
1853 1299
 
1854
-		maxNumber = goods.NewCount
1300
+		maxNumber = goods.Count
1855 1301
 
1856 1302
 		if warehouse.StockCount < maxNumber {
1857 1303
 			return errors.New("库存数量不足")
@@ -1886,13 +1332,12 @@ func ConsumablesDeliveryOne(orgID int64, patient_id int64, record_time int64, go
1886 1332
 			SysRecordTime:           record_time,
1887 1333
 			GoodTypeId:              goods.GoodTypeId,
1888 1334
 			GoodId:                  goods.GoodId,
1889
-			PatientId:               patient_id,
1890 1335
 		}
1891 1336
 		warehouseOutInfo.Count = stock_number
1892 1337
 		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1893 1338
 		warehouseOutInfo.Price = stockInInfo.Price
1894 1339
 
1895
-		_, errcode := GetStockInRecoredByGoodId(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID)
1340
+		_, errcode := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, record_time, orgID)
1896 1341
 		if errcode == gorm.ErrRecordNotFound {
1897 1342
 			errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1898 1343
 
@@ -1909,7 +1354,7 @@ func ConsumablesDeliveryOne(orgID int64, patient_id int64, record_time int64, go
1909 1354
 			// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1910 1355
 			goods.Count = deliver_number - stock_number
1911 1356
 
1912
-			ConsumablesDeliveryOne(orgID, patient_id, record_time, goods, warehouseOut, count)
1357
+			ConsumablesDeliveryOne(orgID, record_time, goods, warehouseOut, count)
1913 1358
 		} else if errcode == nil {
1914 1359
 
1915 1360
 			warehouseOutInfo := &models.WarehouseOutInfo{
@@ -1927,11 +1372,10 @@ func ConsumablesDeliveryOne(orgID int64, patient_id int64, record_time int64, go
1927 1372
 				SysRecordTime:           record_time,
1928 1373
 				GoodTypeId:              goods.GoodTypeId,
1929 1374
 				GoodId:                  goods.GoodId,
1930
-				PatientId:               patient_id,
1931 1375
 			}
1932 1376
 			warehouseOutInfo.Count = goods.Count
1933 1377
 			//更新入库详情表
1934
-			UpdateAutoMaticReduceDetail(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID, warehouseOutInfo)
1378
+			UpdateAutoMaticReduceDetailOne(goods.GoodId, goods.GoodTypeId, record_time, orgID, warehouseOutInfo)
1935 1379
 		}
1936 1380
 
1937 1381
 	}
@@ -1939,9 +1383,9 @@ func ConsumablesDeliveryOne(orgID int64, patient_id int64, record_time int64, go
1939 1383
 }
1940 1384
 
1941 1385
 //耗材出库删除
1942
-func ConsumablesDeliveryDeleteOne(orgID int64, patient_id int64, record_time int64, good_yc *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut) (err error) {
1386
+func ConsumablesDeliveryDeleteOne(orgID int64, record_time int64, good_yc *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut) (err error) {
1943 1387
 	// 先根据相关信息查询当天该耗材的出库信息
1944
-	warehouseOutInfos, err := FindStockOutInfoByStock(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, patient_id)
1388
+	warehouseOutInfos, err := FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
1945 1389
 	if err != nil {
1946 1390
 		return err
1947 1391
 	}
@@ -1971,7 +1415,6 @@ func ConsumablesDeliveryDeleteOne(orgID int64, patient_id int64, record_time int
1971 1415
 			SysRecordTime: record_time,
1972 1416
 			GoodTypeId:    good_yc.GoodTypeId,
1973 1417
 			GoodId:        good_yc.GoodId,
1974
-			PatientId:     patient_id,
1975 1418
 		}
1976 1419
 		warehouseOutInfo.Count = delete_count
1977 1420
 		stockInInfo, _ := FindLastStockInInfoRecord(good_yc.GoodId, orgID)