csx 3 gadus atpakaļ
vecāks
revīzija
c7674d0b54

+ 22 - 36
controllers/drug_stock_api_contorller.go Parādīt failu

183
 
183
 
184
 				}
184
 				}
185
 
185
 
186
-				if items["lot_number"] == nil || reflect.TypeOf(items["lot_number"]).String() != "string" {
187
-					utils.ErrorLog("lot_number")
188
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
189
-					return
190
-				}
191
 				lot_number, _ := items["lot_number"].(string)
186
 				lot_number, _ := items["lot_number"].(string)
192
 
187
 
193
-				if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
194
-					utils.ErrorLog("batch_number")
195
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
196
-					return
197
-				}
198
 				batch_number, _ := items["batch_number"].(string)
188
 				batch_number, _ := items["batch_number"].(string)
199
 
189
 
200
 				if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
190
 				if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
465
 	}
455
 	}
466
 
456
 
467
 	warehousingInfo, err := service.FindDrugWarehousingInfoById(id, admin.CurrentOrgId)
457
 	warehousingInfo, err := service.FindDrugWarehousingInfoById(id, admin.CurrentOrgId)
458
+	fmt.Println("warehousinginfo000000000000000", warehousingInfo)
468
 	if err == nil {
459
 	if err == nil {
469
 		c.ServeSuccessJSON(map[string]interface{}{
460
 		c.ServeSuccessJSON(map[string]interface{}{
470
 			"info":             warehousingInfo,
461
 			"info":             warehousingInfo,
612
 				}
603
 				}
613
 				number, _ := items["lot_number"].(string)
604
 				number, _ := items["lot_number"].(string)
614
 
605
 
615
-				if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
616
-					utils.ErrorLog("batch_number")
617
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
618
-					return
619
-				}
620
 				batch_number, _ := items["batch_number"].(string)
606
 				batch_number, _ := items["batch_number"].(string)
621
 
607
 
622
 				max_unit, _ := items["max_unit"].(string)
608
 				max_unit, _ := items["max_unit"].(string)
1227
 				remark := items["remark"].(string)
1213
 				remark := items["remark"].(string)
1228
 				max_unit := items["max_unit"].(string)
1214
 				max_unit := items["max_unit"].(string)
1229
 
1215
 
1230
-				fmt.Println("包装单位999999999999", max_unit)
1231
-
1232
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1216
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1233
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1217
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1234
 					WarehouseOutId:          warehouseOut.ID,
1218
 					WarehouseOutId:          warehouseOut.ID,
1254
 	}
1238
 	}
1255
 
1239
 
1256
 	//调用出库逻辑
1240
 	//调用出库逻辑
1257
-	for _, item := range warehousingOutInfo {
1258
-
1259
-		// 出库流程
1260
-		// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1261
-		drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
1262
-		if drup.ID > 0 {
1263
-			prescribingNumber := item.Count
1264
-
1265
-			service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
1266
-
1267
-		}
1241
+	//for _, item := range warehousingOutInfo {
1242
+	//
1243
+	//	// 出库流程
1244
+	//	// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1245
+	//	drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
1246
+	//	if drup.ID > 0 {
1247
+	//		prescribingNumber := item.Count
1248
+	//
1249
+	//		service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
1250
+	//
1251
+	//	}
1252
+	//
1253
+	//}
1268
 
1254
 
1255
+	errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1256
+	info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1257
+	if errs != nil {
1258
+		utils.ErrorLog(errs.Error())
1259
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1260
+		return
1269
 	}
1261
 	}
1270
 
1262
 
1271
-	//errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1272
-	//info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1273
-	//if errs != nil {
1274
-	//	utils.ErrorLog(errs.Error())
1275
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1276
-	//	return
1277
-	//}
1278
-
1279
 	c.ServeSuccessJSON(map[string]interface{}{
1263
 	c.ServeSuccessJSON(map[string]interface{}{
1264
+		"info":                  info,
1280
 		"msg":                   "出库成功",
1265
 		"msg":                   "出库成功",
1281
 		"warehousing_out_order": warehousing_out_order,
1266
 		"warehousing_out_order": warehousing_out_order,
1282
 	})
1267
 	})
1999
 	}
1984
 	}
2000
 	adminUserInfo := this.GetAdminUserInfo()
1985
 	adminUserInfo := this.GetAdminUserInfo()
2001
 	userDetails, err, total := service.FindDrugStockUserDetailById(adminUserInfo.CurrentOrgId, order_id)
1986
 	userDetails, err, total := service.FindDrugStockUserDetailById(adminUserInfo.CurrentOrgId, order_id)
1987
+
2002
 	if err == nil {
1988
 	if err == nil {
2003
 		this.ServeSuccessJSON(map[string]interface{}{
1989
 		this.ServeSuccessJSON(map[string]interface{}{
2004
 			"list":  userDetails,
1990
 			"list":  userDetails,

+ 133 - 16
controllers/gobal_config_api_controller.go Parādīt failu

95
 
95
 
96
 	beego.Router("/api/drugoutstock/getoutdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugOutStockFlow")
96
 	beego.Router("/api/drugoutstock/getoutdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugOutStockFlow")
97
 	beego.Router("/api/drug/getbatchorderdetail", &GobalConfigApiController{}, "Get:GetBatchOrderDetail")
97
 	beego.Router("/api/drug/getbatchorderdetail", &GobalConfigApiController{}, "Get:GetBatchOrderDetail")
98
+
99
+	beego.Router("/api/drug/getdrugcountlist", &GobalConfigApiController{}, "Get:GetDrugCountList")
100
+	beego.Router("/api/drug/getsingleorderdetail", &GobalConfigApiController{}, "Get:GetSingleOrderDetail")
101
+	beego.Router("/api/drug/getautodrugdetial", &GobalConfigApiController{}, "Get:GetAutoDrugDetail")
102
+	beego.Router("/api/drug/getdrugorderinprint", &GobalConfigApiController{}, "Get:GetDrugOrderInPrint")
103
+	beego.Router("/api/drug/getdrugoutorderdetailprint", &GobalConfigApiController{}, "Get:GetDrugOutOrderPrint")
98
 }
104
 }
99
 
105
 
100
 //provinces, _ := service.GetDistrictsByUpid(0)21
106
 //provinces, _ := service.GetDistrictsByUpid(0)21
1783
 	drugConfig, _ := service.GetDrugStockConfig(orgId)
1789
 	drugConfig, _ := service.GetDrugStockConfig(orgId)
1784
 	list, err := service.GetDrugAutoMaticList(orgId, warehous_out_id, record_time, warehouse_out_order_number)
1790
 	list, err := service.GetDrugAutoMaticList(orgId, warehous_out_id, record_time, warehouse_out_order_number)
1785
 	drugList, err := service.GetAllBaseDrugList(orgId)
1791
 	drugList, err := service.GetAllBaseDrugList(orgId)
1792
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
1786
 	if err != nil {
1793
 	if err != nil {
1787
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1794
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1788
 		return
1795
 		return
1789
 	}
1796
 	}
1790
 	c.ServeSuccessJSON(map[string]interface{}{
1797
 	c.ServeSuccessJSON(map[string]interface{}{
1791
-		"list":       list,
1792
-		"drugConfig": drugConfig,
1793
-		"drugList":   drugList,
1798
+		"list":             list,
1799
+		"drugConfig":       drugConfig,
1800
+		"drugList":         drugList,
1801
+		"manufacturerList": manufacturerList,
1794
 	})
1802
 	})
1795
 }
1803
 }
1796
 
1804
 
1809
 	page, _ := c.GetInt64("page", -1)
1817
 	page, _ := c.GetInt64("page", -1)
1810
 	limit, _ := c.GetInt64("limit", -1)
1818
 	limit, _ := c.GetInt64("limit", -1)
1811
 	keyword := c.GetString("keyword")
1819
 	keyword := c.GetString("keyword")
1812
-	drug_category, _ := c.GetInt64("drug_category")
1820
+	drug_type, _ := c.GetInt64("drug_type")
1813
 	start_time := c.GetString("start_time")
1821
 	start_time := c.GetString("start_time")
1814
 	end_time := c.GetString("end_time")
1822
 	end_time := c.GetString("end_time")
1815
 	timeLayout := "2006-01-02"
1823
 	timeLayout := "2006-01-02"
1838
 	adminUserInfo := c.GetAdminUserInfo()
1846
 	adminUserInfo := c.GetAdminUserInfo()
1839
 
1847
 
1840
 	//查询入库数量
1848
 	//查询入库数量
1841
-	list, total, err := service.GetDrugStockList(page, limit, keyword, drug_category, startTime, endTime, adminUserInfo.CurrentOrgId)
1849
+	list, total, err := service.GetDrugStockList(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
1842
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
1850
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
1843
 	if err != nil {
1851
 	if err != nil {
1844
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1852
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1932
 		endTime = theTime.Unix()
1940
 		endTime = theTime.Unix()
1933
 	}
1941
 	}
1934
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1942
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1935
-	if stock_type >= 0 && stock_type != 3 {
1936
-		outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
1937
 
1943
 
1938
-		if err != nil {
1939
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1940
-			return
1941
-		}
1942
-		c.ServeSuccessJSON(map[string]interface{}{
1943
-			"outList": outList,
1944
-			"total":   total,
1945
-		})
1944
+	outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
1945
+
1946
+	if err != nil {
1947
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1948
+		return
1946
 	}
1949
 	}
1950
+	c.ServeSuccessJSON(map[string]interface{}{
1951
+		"outList": outList,
1952
+		"total":   total,
1953
+	})
1954
+
1947
 }
1955
 }
1948
 
1956
 
1949
 func (c *GobalConfigApiController) GetBatchOrderDetail() {
1957
 func (c *GobalConfigApiController) GetBatchOrderDetail() {
1952
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1960
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1953
 	limit, _ := c.GetInt64("limit")
1961
 	limit, _ := c.GetInt64("limit")
1954
 	page, _ := c.GetInt64("page")
1962
 	page, _ := c.GetInt64("page")
1955
-	detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, limit, page)
1963
+	detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, page, limit)
1956
 	if err != nil {
1964
 	if err != nil {
1957
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1965
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1958
 		return
1966
 		return
1962
 		"total":  total,
1970
 		"total":  total,
1963
 	})
1971
 	})
1964
 }
1972
 }
1973
+
1974
+func (c *GobalConfigApiController) GetDrugCountList() {
1975
+
1976
+	start_time := c.GetString("start_time")
1977
+
1978
+	end_time := c.GetString("end_time")
1979
+
1980
+	timeLayout := "2006-01-02"
1981
+	loc, _ := time.LoadLocation("Local")
1982
+	var startTime int64
1983
+	if len(start_time) > 0 {
1984
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
1985
+		if err != nil {
1986
+			fmt.Println(err)
1987
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1988
+			return
1989
+		}
1990
+		startTime = theTime.Unix()
1991
+	}
1992
+	var endTime int64
1993
+	if len(end_time) > 0 {
1994
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
1995
+		if err != nil {
1996
+			utils.ErrorLog(err.Error())
1997
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1998
+			return
1999
+		}
2000
+		endTime = theTime.Unix()
2001
+	}
2002
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2003
+	list, err := service.GetDrugCountList(startTime, endTime, orgId)
2004
+	countList, err := service.GetMinCountList(startTime, endTime, orgId)
2005
+	outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
2006
+	auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
2007
+	info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
2008
+	if err != nil {
2009
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2010
+		return
2011
+	}
2012
+	c.ServeSuccessJSON(map[string]interface{}{
2013
+		"countList":    list,
2014
+		"outCountList": outCountList,
2015
+		"auCountList":  auCountList,
2016
+		"minCount":     countList,
2017
+		"info":         info,
2018
+	})
2019
+}
2020
+
2021
+func (c *GobalConfigApiController) GetSingleOrderDetail() {
2022
+
2023
+	id, _ := c.GetInt64("id")
2024
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2025
+	list, err := service.GetSingleOrderDetail(id, orgId)
2026
+	if err != nil {
2027
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2028
+		return
2029
+	}
2030
+	c.ServeSuccessJSON(map[string]interface{}{
2031
+		"list": list,
2032
+	})
2033
+}
2034
+
2035
+func (c *GobalConfigApiController) GetAutoDrugDetail() {
2036
+
2037
+	id, _ := c.GetInt64("drug_id")
2038
+	record_time, _ := c.GetInt64("record_time")
2039
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2040
+	list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
2041
+	if err != nil {
2042
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2043
+		return
2044
+	}
2045
+	c.ServeSuccessJSON(map[string]interface{}{
2046
+		"list":  list,
2047
+		"total": total,
2048
+	})
2049
+}
2050
+
2051
+func (c *GobalConfigApiController) GetDrugOrderInPrint() {
2052
+
2053
+	id := c.GetString("id")
2054
+	ids := strings.Split(id, ",")
2055
+	admin := c.GetAdminUserInfo()
2056
+
2057
+	info, _ := service.FindDrugWarehousingByIdOne(ids, admin.CurrentOrgId)
2058
+	manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
2059
+
2060
+	warehousingInfo, _ := service.FindDrugWarehousingInfoByIdOne(ids, admin.CurrentOrgId)
2061
+
2062
+	c.ServeSuccessJSON(map[string]interface{}{
2063
+		"info":             info,
2064
+		"warehousing":      warehousingInfo,
2065
+		"manufacturerList": manufacturerList,
2066
+	})
2067
+}
2068
+
2069
+func (c *GobalConfigApiController) GetDrugOutOrderPrint() {
2070
+	id := c.GetString("id")
2071
+	ids := strings.Split(id, ",")
2072
+	admin := c.GetAdminUserInfo()
2073
+	info, _ := service.FindeDrugWarehouseOutOrder(ids, admin.CurrentOrgId)
2074
+	manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
2075
+	warehousing, _ := service.FindeDrugWarehouseOutDetail(ids, admin.CurrentOrgId)
2076
+	c.ServeSuccessJSON(map[string]interface{}{
2077
+		"info":             info,
2078
+		"warehousing":      warehousing,
2079
+		"manufacturerList": manufacturerList,
2080
+	})
2081
+}

+ 1 - 1
controllers/mobile_api_controllers/check_weight_api_controller.go Parādīt failu

335
 
335
 
336
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
336
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
337
 
337
 
338
-	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 {
338
+	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 {
339
 		dewater_amount = dewater_amount * 1000
339
 		dewater_amount = dewater_amount * 1000
340
 	}
340
 	}
341
 
341
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 406 - 515
controllers/mobile_api_controllers/dialysis_api_controller.go


+ 2 - 0
controllers/mobile_api_controllers/mobile_api_router_register.go Parādīt failu

161
 	//医嘱批量执行
161
 	//医嘱批量执行
162
 	beego.Router("/m/api/batchadviceexecution", &DialysisAPIController{}, "Get:BatchAdviceExecution")
162
 	beego.Router("/m/api/batchadviceexecution", &DialysisAPIController{}, "Get:BatchAdviceExecution")
163
 
163
 
164
+	beego.Router("/m/api/updatestockgoods", &DialysisAPIController{}, "Get:UpdateStockGoods")
165
+
164
 }
166
 }

+ 9 - 452
controllers/mobile_api_controllers/patient_api_controller.go Parādīt failu

541
 
541
 
542
 		adminUserInfo := c.GetMobileAdminUserInfo()
542
 		adminUserInfo := c.GetMobileAdminUserInfo()
543
 
543
 
544
-		//appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
545
-		//
546
-		//if appRole.UserType == 2 || appRole.UserType == 1 {
547
-		//	headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
548
-		//	if getPermissionErr != nil {
549
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
550
-		//		return
551
-		//	} else if headNursePermission == nil {
552
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
553
-		//		return
554
-		//	}
555
-		//}
556
-
557
 		var advice models.DoctorAdvice
544
 		var advice models.DoctorAdvice
558
 
545
 
559
 		if groupno > 0 {
546
 		if groupno > 0 {
561
 			for _, item := range advices {
548
 			for _, item := range advices {
562
 				if item.ExecutionState == 2 {
549
 				if item.ExecutionState == 2 {
563
 					advice = item
550
 					advice = item
564
-
565
 				}
551
 				}
566
 			}
552
 			}
567
 		} else {
553
 		} else {
569
 			for _, item := range advices {
555
 			for _, item := range advices {
570
 				if item.ExecutionState == 2 {
556
 				if item.ExecutionState == 2 {
571
 					advice = item
557
 					advice = item
572
-
573
 				}
558
 				}
574
 			}
559
 			}
575
 		}
560
 		}
628
 			if groupno > 0 {
613
 			if groupno > 0 {
629
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
614
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
630
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
615
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
631
-				record_time := int64(0)
632
 				for _, item := range advices {
616
 				for _, item := range advices {
633
 					if item.Way == 1 {
617
 					if item.Way == 1 {
634
 						isHasWay = true
618
 						isHasWay = true
635
-						record_time = item.RecordDate
636
 					}
619
 					}
637
 				}
620
 				}
638
 
621
 
639
 				if isHasWay {
622
 				if isHasWay {
640
-					_, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
641
-					if err == gorm.ErrRecordNotFound {
642
-						//没有记录,则创建出库单
643
-						timeStr := time.Now().Format("2006-01-02")
644
-						timeArr := strings.Split(timeStr, "-")
645
-						total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
646
-						total = total + 1
647
-						warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
648
-						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
649
-						number = number + total
650
-						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
651
-						creater := adminUserInfo.AdminUser.Id
652
-						warehouseOut := models.DrugWarehouseOut{
653
-							WarehouseOutOrderNumber: warehousing_out_order,
654
-							OperationTime:           time.Now().Unix(),
655
-							OrgId:                   adminUserInfo.Org.Id,
656
-							Creater:                 creater,
657
-							Ctime:                   time.Now().Unix(),
658
-							Status:                  1,
659
-							WarehouseOutTime:        record_time,
660
-							Dealer:                  0,
661
-							Manufacturer:            0,
662
-							Type:                    1,
663
-							IsSys:                   1,
664
-						}
665
-						err := service.AddSigleDrugWarehouseOut(&warehouseOut)
666
-						if err != nil {
667
-							utils.TraceLog("创建出库单失败 err = %v", err)
668
-						} else {
669
-							for _, item := range advices {
670
-								if item.Way == 1 {
671
-
672
-									service.DrugsDelivery(item.UserOrgId, &item)
673
-
674
-									//if item.PrescribingNumber > 0 {
675
-									//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
676
-									//		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
677
-									//		WarehouseOutId:          warehouseOut.ID,
678
-									//		Status:                  1,
679
-									//		Ctime:                   time.Now().Unix(),
680
-									//		Remark:                  "",
681
-									//		OrgId:                   adminUserInfo.Org.Id,
682
-									//		Type:                    1,
683
-									//		Manufacturer:            0,
684
-									//		Dealer:                  0,
685
-									//		IsSys:                   1,
686
-									//		SysRecordTime:           record_time,
687
-									//		DrugId:                  item.DrugId,
688
-									//	}
689
-									//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
690
-									//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
691
-									//	warehouseOutInfo.Count = count
692
-									//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
693
-									//	warehouseOutInfo.Price = stockInInfo.Price
694
-									//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
695
-									//	if err == nil {
696
-									//		details := &models.DrugAutomaticReduceDetail{
697
-									//			WarehouseOutId:          warehouseOutInfo.ID,
698
-									//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
699
-									//			PatientId:               item.PatientId,
700
-									//			Ctime:                   time.Now().Unix(),
701
-									//			Mtime:                   time.Now().Unix(),
702
-									//			Status:                  1,
703
-									//			RecordTime:              record_time,
704
-									//			OrgId:                   adminUserInfo.Org.Id,
705
-									//			DrugId:                  item.DrugId,
706
-									//			Count:                   count,
707
-									//		}
708
-									//		service.AddSigleDrugAutoReduceRecordInfo(details)
709
-									//	}
710
-									//}
711
-								}
712
-
713
-							}
714
-						}
715
-
716
-					} else if err == nil {
717
-						for _, item := range advices {
718
-							if item.Way == 1 {
719
-								service.DrugsDelivery(item.UserOrgId, &item)
720
-								//outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
721
-								//if err == gorm.ErrRecordNotFound {
722
-								//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
723
-								//		WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
724
-								//		WarehouseOutId:          out.ID,
725
-								//		Status:                  1,
726
-								//		Ctime:                   time.Now().Unix(),
727
-								//		Remark:                  "",
728
-								//		OrgId:                   adminUserInfo.Org.Id,
729
-								//		Type:                    1,
730
-								//		Manufacturer:            0,
731
-								//		Dealer:                  0,
732
-								//		IsSys:                   1,
733
-								//		SysRecordTime:           record_time,
734
-								//	}
735
-								//
736
-								//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
737
-								//	warehouseOutInfo.Price = stockInInfo.Price
738
-								//	warehouseOutInfo.DrugId = item.DrugId
739
-								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
740
-								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
741
-								//	warehouseOutInfo.Count = count
742
-								//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
743
-								//	if err == nil {
744
-								//		details := &models.DrugAutomaticReduceDetail{
745
-								//			WarehouseOutId:          warehouseOutInfo.ID,
746
-								//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
747
-								//			PatientId:               item.PatientId,
748
-								//			Ctime:                   time.Now().Unix(),
749
-								//			Mtime:                   time.Now().Unix(),
750
-								//			Status:                  1,
751
-								//			RecordTime:              record_time,
752
-								//			OrgId:                   adminUserInfo.Org.Id,
753
-								//			DrugId:                  item.DrugId,
754
-								//			Count:                   count,
755
-								//		}
756
-								//		service.AddSigleDrugAutoReduceRecordInfo(details)
757
-								//	}
758
-								//
759
-								//} else if err == nil { //记录存在,则将增加数量
760
-								//	if outInfo.ID > 0 {
761
-								//		prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
762
-								//		count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
763
-								//		service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
764
-								//	}
765
-								//
766
-								//	//count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
767
-								//	//if count == 0 {
768
-								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
769
-								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
770
-								//	details := &models.DrugAutomaticReduceDetail{
771
-								//		WarehouseOutId:          outInfo.ID,
772
-								//		WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
773
-								//		PatientId:               item.PatientId,
774
-								//		Ctime:                   time.Now().Unix(),
775
-								//		Mtime:                   time.Now().Unix(),
776
-								//		Status:                  1,
777
-								//		RecordTime:              record_time,
778
-								//		OrgId:                   adminUserInfo.Org.Id,
779
-								//		DrugId:                  item.DrugId,
780
-								//		Count:                   count,
781
-								//	}
782
-								//	service.AddSigleDrugAutoReduceRecordInfo(details)
783
-								//
784
-								//}
785
-							}
623
+					for _, item := range advices {
624
+						if item.Way == 1 {
625
+							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
786
 						}
626
 						}
787
-
788
 					}
627
 					}
789
-
790
 				}
628
 				}
791
 			} else {
629
 			} else {
792
 				advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
630
 				advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
793
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
631
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
794
-				record_time := int64(0)
632
+
795
 				for _, item := range advices {
633
 				for _, item := range advices {
796
 					if item.Way == 1 {
634
 					if item.Way == 1 {
797
 						isHasWay = true
635
 						isHasWay = true
798
-						record_time = item.RecordDate
799
 					}
636
 					}
800
 				}
637
 				}
801
-
802
 				if isHasWay {
638
 				if isHasWay {
803
-					_, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
804
-					if err == gorm.ErrRecordNotFound {
805
-						//没有记录,则创建出库单
806
-						timeStr := time.Now().Format("2006-01-02")
807
-						timeArr := strings.Split(timeStr, "-")
808
-						total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
809
-						total = total + 1
810
-						warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
811
-						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
812
-						number = number + total
813
-						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
814
-						creater := adminUserInfo.AdminUser.Id
815
-						warehouseOut := models.DrugWarehouseOut{
816
-							WarehouseOutOrderNumber: warehousing_out_order,
817
-							OperationTime:           time.Now().Unix(),
818
-							OrgId:                   adminUserInfo.Org.Id,
819
-							Creater:                 creater,
820
-							Ctime:                   time.Now().Unix(),
821
-							Status:                  1,
822
-							WarehouseOutTime:        record_time,
823
-							Dealer:                  0,
824
-							Manufacturer:            0,
825
-							Type:                    1,
826
-							IsSys:                   1,
827
-						}
828
-						err := service.AddSigleDrugWarehouseOut(&warehouseOut)
829
-						if err != nil {
830
-							utils.TraceLog("创建出库单失败 err = %v", err)
831
-						} else {
832
-							for _, item := range advices {
833
-								if item.Way == 1 {
834
-									service.DrugsDelivery(item.UserOrgId, &item)
835
-									//if item.PrescribingNumber > 0 {
836
-									//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
837
-									//		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
838
-									//		WarehouseOutId:          warehouseOut.ID,
839
-									//		Status:                  1,
840
-									//		Ctime:                   time.Now().Unix(),
841
-									//		Remark:                  "",
842
-									//		OrgId:                   adminUserInfo.Org.Id,
843
-									//		Type:                    1,
844
-									//		Manufacturer:            0,
845
-									//		Dealer:                  0,
846
-									//		IsSys:                   1,
847
-									//		SysRecordTime:           record_time,
848
-									//		DrugId:                  item.DrugId,
849
-									//	}
850
-									//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
851
-									//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
852
-									//	warehouseOutInfo.Count = count
853
-									//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
854
-									//	warehouseOutInfo.Price = stockInInfo.Price
855
-									//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
856
-									//	if err == nil {
857
-									//		details := &models.DrugAutomaticReduceDetail{
858
-									//			WarehouseOutId:          warehouseOutInfo.ID,
859
-									//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
860
-									//			PatientId:               item.PatientId,
861
-									//			Ctime:                   time.Now().Unix(),
862
-									//			Mtime:                   time.Now().Unix(),
863
-									//			Status:                  1,
864
-									//			RecordTime:              record_time,
865
-									//			OrgId:                   adminUserInfo.Org.Id,
866
-									//			DrugId:                  item.DrugId,
867
-									//			Count:                   count,
868
-									//		}
869
-									//		service.AddSigleDrugAutoReduceRecordInfo(details)
870
-									//	}
871
-									//}
872
-								}
873
-
874
-							}
639
+					for _, item := range advices {
640
+						if item.Way == 1 {
641
+							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
875
 						}
642
 						}
876
-
877
-					} else if err == nil {
878
-						for _, item := range advices {
879
-							if item.Way == 1 {
880
-								service.DrugsDelivery(item.UserOrgId, &item)
881
-								//outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
882
-								//if err == gorm.ErrRecordNotFound {
883
-								//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
884
-								//		WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
885
-								//		WarehouseOutId:          out.ID,
886
-								//		Status:                  1,
887
-								//		Ctime:                   time.Now().Unix(),
888
-								//		Remark:                  "",
889
-								//		OrgId:                   adminUserInfo.Org.Id,
890
-								//		Type:                    1,
891
-								//		Manufacturer:            0,
892
-								//		Dealer:                  0,
893
-								//		IsSys:                   1,
894
-								//		SysRecordTime:           record_time,
895
-								//	}
896
-								//
897
-								//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
898
-								//	warehouseOutInfo.Price = stockInInfo.Price
899
-								//	warehouseOutInfo.DrugId = item.DrugId
900
-								//	//warehouseOutInfo.Count = item.
901
-								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
902
-								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
903
-								//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
904
-								//	if err == nil {
905
-								//		details := &models.DrugAutomaticReduceDetail{
906
-								//			WarehouseOutId:          warehouseOutInfo.ID,
907
-								//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
908
-								//			PatientId:               item.PatientId,
909
-								//			Ctime:                   time.Now().Unix(),
910
-								//			Mtime:                   time.Now().Unix(),
911
-								//			Status:                  1,
912
-								//			RecordTime:              record_time,
913
-								//			OrgId:                   adminUserInfo.Org.Id,
914
-								//			DrugId:                  item.DrugId,
915
-								//			Count:                   count,
916
-								//		}
917
-								//		service.AddSigleDrugAutoReduceRecordInfo(details)
918
-								//	}
919
-								//
920
-								//} else if err == nil { //记录存在,则将增加数量
921
-								//	if outInfo.ID > 0 {
922
-								//		prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
923
-								//		count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
924
-								//		service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
925
-								//	}
926
-								//
927
-								//	//count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
928
-								//	//if count == 0 {
929
-								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
930
-								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
931
-								//	details := &models.DrugAutomaticReduceDetail{
932
-								//		WarehouseOutId:          outInfo.ID,
933
-								//		WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
934
-								//		PatientId:               item.PatientId,
935
-								//		Ctime:                   time.Now().Unix(),
936
-								//		Mtime:                   time.Now().Unix(),
937
-								//		Status:                  1,
938
-								//		RecordTime:              record_time,
939
-								//		OrgId:                   adminUserInfo.Org.Id,
940
-								//		DrugId:                  item.DrugId,
941
-								//		Count:                   count,
942
-								//	}
943
-								//	service.AddSigleDrugAutoReduceRecordInfo(details)
944
-								//
945
-								//
946
-								//}
947
-							}
948
-						}
949
-
950
 					}
643
 					}
951
-
952
 				}
644
 				}
953
 			}
645
 			}
954
 		}
646
 		}
1070
 			return
762
 			return
1071
 		}
763
 		}
1072
 		adminInfo := c.GetMobileAdminUserInfo()
764
 		adminInfo := c.GetMobileAdminUserInfo()
765
+		creater := c.GetMobileAdminUserInfo().AdminUser.Id
1073
 		advice_id, _ := c.GetInt64("advice_id")
766
 		advice_id, _ := c.GetInt64("advice_id")
1074
 		advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
767
 		advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
1075
 		if advices.ExecutionState == 1 {
768
 		if advices.ExecutionState == 1 {
1096
 			fmt.Println("drugstockconfig000000000000000000000000", drugStockConfig.IsOpen)
789
 			fmt.Println("drugstockconfig000000000000000000000000", drugStockConfig.IsOpen)
1097
 			if drugStockConfig.IsOpen == 1 {
790
 			if drugStockConfig.IsOpen == 1 {
1098
 				advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
791
 				advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
1099
-				record_time := advice.RecordDate
1100
-
1101
-				out, err := service.FindDrugStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
1102
-				if err == gorm.ErrRecordNotFound {
1103
-					//没有记录,则创建出库单
1104
-					timeStr := time.Now().Format("2006-01-02")
1105
-					timeArr := strings.Split(timeStr, "-")
1106
-					total, _ := service.FindAllDrugWarehouseOut(adminInfo.Org.Id)
1107
-					total = total + 1
1108
-					warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1109
-					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1110
-					number = number + total
1111
-					warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1112
-					creater := adminInfo.AdminUser.Id
1113
-					warehouseOut := models.DrugWarehouseOut{
1114
-						WarehouseOutOrderNumber: warehousing_out_order,
1115
-						OperationTime:           time.Now().Unix(),
1116
-						OrgId:                   adminInfo.Org.Id,
1117
-						Creater:                 creater,
1118
-						Ctime:                   time.Now().Unix(),
1119
-						Status:                  1,
1120
-						WarehouseOutTime:        record_time,
1121
-						Dealer:                  0,
1122
-						Manufacturer:            0,
1123
-						Type:                    1,
1124
-						IsSys:                   1,
1125
-					}
1126
-					err := service.AddSigleDrugWarehouseOut(&warehouseOut)
1127
-					if err != nil {
1128
-						utils.TraceLog("创建出库单失败 err = %v", err)
1129
-					} else {
1130
-						if advice.PrescribingNumber > 0 {
1131
-							warehouseOutInfo := &models.DrugWarehouseOutInfo{
1132
-								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1133
-								WarehouseOutId:          warehouseOut.ID,
1134
-								Status:                  1,
1135
-								Ctime:                   time.Now().Unix(),
1136
-								Remark:                  "",
1137
-								OrgId:                   adminInfo.Org.Id,
1138
-								Type:                    1,
1139
-								Manufacturer:            0,
1140
-								Dealer:                  0,
1141
-								IsSys:                   1,
1142
-								SysRecordTime:           record_time,
1143
-								DrugId:                  advice.DrugId,
1144
-							}
1145
-							prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1146
-							count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1147
-							warehouseOutInfo.Count = count
1148
-							stockInInfo, _ := service.FindLastDrugStockInInfoRecord(advice.DrugId, adminInfo.Org.Id)
1149
-							warehouseOutInfo.Price = stockInInfo.Price
1150
-							err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1151
-
1152
-							if err == nil {
1153
-								service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1154
-								//details := &models.DrugAutomaticReduceDetail{
1155
-								//	WarehouseOutId:          warehouseOutInfo.ID,
1156
-								//	WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1157
-								//	PatientId:               advice.PatientId,
1158
-								//	Ctime:                   time.Now().Unix(),
1159
-								//	Mtime:                   time.Now().Unix(),
1160
-								//	Status:                  1,
1161
-								//	RecordTime:              record_time,
1162
-								//	OrgId:                   adminInfo.Org.Id,
1163
-								//	DrugId:                  advice.DrugId,
1164
-								//	Count:                   count,
1165
-								//}
1166
-								//service.AddSigleDrugAutoReduceRecordInfo(details)
1167
-							}
1168
-						}
1169
-					}
1170
-
1171
-				} else if err == nil {
1172
-					_, err := service.FindDrugStockOutInfoByTypeId(adminInfo.Org.Id, advice.DrugId, out.ID, out.WarehouseOutOrderNumber)
1173
-					if err == gorm.ErrRecordNotFound {
1174
-						warehouseOutInfo := &models.DrugWarehouseOutInfo{
1175
-							WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
1176
-							WarehouseOutId:          out.ID,
1177
-							Status:                  1,
1178
-							Ctime:                   time.Now().Unix(),
1179
-							Remark:                  "",
1180
-							OrgId:                   adminInfo.Org.Id,
1181
-							Type:                    1,
1182
-							Manufacturer:            0,
1183
-							Dealer:                  0,
1184
-							IsSys:                   1,
1185
-							SysRecordTime:           record_time,
1186
-						}
1187
-
1188
-						stockInInfo, _ := service.FindLastDrugStockInInfoRecord(advice.DrugId, adminInfo.Org.Id)
1189
-						warehouseOutInfo.Price = stockInInfo.Price
1190
-						warehouseOutInfo.DrugId = advice.DrugId
1191
-						prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1192
-						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1193
-						warehouseOutInfo.Count = count
1194
-						err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1195
-						if err == nil {
1196
-							service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1197
-							//details := &models.DrugAutomaticReduceDetail{
1198
-							//	WarehouseOutId:          warehouseOutInfo.ID,
1199
-							//	WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1200
-							//	PatientId:               advice.PatientId,
1201
-							//	Ctime:                   time.Now().Unix(),
1202
-							//	Mtime:                   time.Now().Unix(),
1203
-							//	Status:                  1,
1204
-							//	RecordTime:              record_time,
1205
-							//	OrgId:                   adminInfo.Org.Id,
1206
-							//	DrugId:                  advice.DrugId,
1207
-							//	Count:                   count,
1208
-							//}
1209
-							//service.AddSigleDrugAutoReduceRecordInfo(details)
1210
-						}
1211
-
1212
-					} else if err == nil { //记录存在,则将增加数量
1213
-						service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1214
-						//if outInfo.ID > 0 {
1215
-						//	prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1216
-						//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1217
-						//	service.UpdateDrugStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, count)
1218
-						//}
1219
-						//prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1220
-						//count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1221
-						//details := &models.DrugAutomaticReduceDetail{
1222
-						//	WarehouseOutId:          outInfo.ID,
1223
-						//	WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
1224
-						//	PatientId:               advice.PatientId,
1225
-						//	Ctime:                   time.Now().Unix(),
1226
-						//	Mtime:                   time.Now().Unix(),
1227
-						//	Status:                  1,
1228
-						//	RecordTime:              record_time,
1229
-						//	OrgId:                   adminInfo.Org.Id,
1230
-						//	DrugId:                  advice.DrugId,
1231
-						//	Count:                   count,
1232
-						//}
1233
-						//service.AddSigleDrugAutoReduceRecordInfo(details)
1234
-					}
1235
-				}
792
+				service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1236
 			}
793
 			}
1237
 			c.ServeSuccessJSON(map[string]interface{}{
794
 			c.ServeSuccessJSON(map[string]interface{}{
1238
 				"msg":    "ok",
795
 				"msg":    "ok",

+ 5 - 5
controllers/patient_api_controller.go Parādīt failu

1234
 		}
1234
 		}
1235
 
1235
 
1236
 		if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
1236
 		if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
1237
+
1237
 			template_id, _ := adviceNameM["template_id"].(string)
1238
 			template_id, _ := adviceNameM["template_id"].(string)
1238
 			advice.TemplateId = template_id
1239
 			advice.TemplateId = template_id
1239
 		}
1240
 		}
1570
 
1571
 
1571
 func (c *PatientApiController) ExecDoctorAdvice() {
1572
 func (c *PatientApiController) ExecDoctorAdvice() {
1572
 
1573
 
1573
-	fmt.Println("hhhhhhhhhhhhhhh9999999999")
1574
 	origin, _ := c.GetInt64("origin", 0)
1574
 	origin, _ := c.GetInt64("origin", 0)
1575
 
1575
 
1576
 	patient, _ := c.GetInt64("patient", 0)
1576
 	patient, _ := c.GetInt64("patient", 0)
1649
 
1649
 
1650
 		//药品管理信息
1650
 		//药品管理信息
1651
 		_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
1651
 		_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
1652
-
1652
+		fmt.Println("999999992322322323232", drugStockConfig.IsOpen)
1653
 		//自备药信息
1653
 		//自备药信息
1654
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
1654
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
1655
-		fmt.Println("9999999999999999999999999", drugStockConfig.IsOpen)
1655
+
1656
 		if drugStockConfig.IsOpen == 1 {
1656
 		if drugStockConfig.IsOpen == 1 {
1657
 			//查询已经执行的医嘱
1657
 			//查询已经执行的医嘱
1658
 			//advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1658
 			//advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1856
 			for _, item := range advices {
1856
 			for _, item := range advices {
1857
 				fmt.Println("imte00000000000000", item.PrescribingNumber)
1857
 				fmt.Println("imte00000000000000", item.PrescribingNumber)
1858
 				//调用药品出库接口
1858
 				//调用药品出库接口
1859
-				service.DrugsDelivery(item.UserOrgId, item)
1859
+				service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1860
 
1860
 
1861
 				//if item.Way == 1 {
1861
 				//if item.Way == 1 {
1862
 				//	out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
1862
 				//	out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
2180
 			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
2180
 			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
2181
 			for _, item := range advices {
2181
 			for _, item := range advices {
2182
 
2182
 
2183
-				service.HisDrugsDelivery(item.UserOrgId, item)
2183
+				service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
2184
 
2184
 
2185
 				//out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
2185
 				//out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
2186
 				//if err == gorm.ErrRecordNotFound {
2186
 				//if err == gorm.ErrRecordNotFound {

+ 5 - 2
controllers/patient_dataconfig_api_controller.go Parādīt failu

5
 	"XT_New/models"
5
 	"XT_New/models"
6
 	"XT_New/service"
6
 	"XT_New/service"
7
 	"XT_New/utils"
7
 	"XT_New/utils"
8
+	"fmt"
8
 	"strconv"
9
 	"strconv"
9
 	"strings"
10
 	"strings"
10
 	"time"
11
 	"time"
14
 
15
 
15
 func PatientDataConfigAPIControllerRegistRouters() {
16
 func PatientDataConfigAPIControllerRegistRouters() {
16
 	beego.Router("/api/patient/courses", &PatientDataConfigAPIController{}, "get:Courses")
17
 	beego.Router("/api/patient/courses", &PatientDataConfigAPIController{}, "get:Courses")
17
-	beego.Router("/api/patient/course/create", &PatientDataConfigAPIController{}, "post:CreateCourse")
18
+	beego.Router("/api/patient/course/create", &PatientDataConfigAPIController{}, "get:CreateCourse")
18
 	beego.Router("/api/patient/course/delete", &PatientDataConfigAPIController{}, "post:DeleteCourse")
19
 	beego.Router("/api/patient/course/delete", &PatientDataConfigAPIController{}, "post:DeleteCourse")
19
-	beego.Router("/api/patient/course/modify", &PatientDataConfigAPIController{}, "post:ModifyCourse")
20
+	beego.Router("/api/patient/course/modify", &PatientDataConfigAPIController{}, "get:ModifyCourse")
20
 
21
 
21
 	beego.Router("/api/patient/rescues", &PatientDataConfigAPIController{}, "get:Rescues")
22
 	beego.Router("/api/patient/rescues", &PatientDataConfigAPIController{}, "get:Rescues")
22
 	beego.Router("/api/patient/rescue/create", &PatientDataConfigAPIController{}, "post:CreateRescue")
23
 	beego.Router("/api/patient/rescue/create", &PatientDataConfigAPIController{}, "post:CreateRescue")
83
 // @param content:string
84
 // @param content:string
84
 func (this *PatientDataConfigAPIController) CreateCourse() {
85
 func (this *PatientDataConfigAPIController) CreateCourse() {
85
 	patientID, _ := this.GetInt64("patient_id")
86
 	patientID, _ := this.GetInt64("patient_id")
87
+	fmt.Println(patientID)
86
 	content := this.GetString("content")
88
 	content := this.GetString("content")
89
+	fmt.Println("content22222222222222222222", content)
87
 	record_time_str := this.GetString("record_time")
90
 	record_time_str := this.GetString("record_time")
88
 	title := this.GetString("title")
91
 	title := this.GetString("title")
89
 
92
 

+ 355 - 62
controllers/stock_in_api_controller.go Parādīt failu

83
 
83
 
84
 	beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
84
 	beego.Router("/api/stock/getstocklistbyid", &StockManagerApiController{}, "Get:GetStockListById")
85
 	beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
85
 	beego.Router("/api/stock/getstockoutlist", &StockManagerApiController{}, "Get:GetStockOutList")
86
+
87
+	beego.Router("/api/good/getstockdrugcount", &StockManagerApiController{}, "Get:GetStockDrugCount")
88
+
89
+	beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
90
+	beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
91
+	beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
92
+	beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
93
+	beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
94
+
86
 }
95
 }
87
 
96
 
88
 func (c *StockManagerApiController) CreateWarehouse() {
97
 func (c *StockManagerApiController) CreateWarehouse() {
89
 
98
 
90
 	warehousing_time := c.GetString("warehousing_time")
99
 	warehousing_time := c.GetString("warehousing_time")
91
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
92
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
93
 
100
 
94
 	types, _ := c.GetInt64("type", 0)
101
 	types, _ := c.GetInt64("type", 0)
95
 
102
 
117
 		Ctime:            ctime,
124
 		Ctime:            ctime,
118
 		Status:           1,
125
 		Status:           1,
119
 		WarehousingTime:  warehousingDate.Unix(),
126
 		WarehousingTime:  warehousingDate.Unix(),
120
-		Dealer:           dealer_id,
121
-		Manufacturer:     manufacturer_id,
122
 		Type:             types,
127
 		Type:             types,
123
 	}
128
 	}
124
 	service.AddSigleWarehouse(&warehousing)
129
 	service.AddSigleWarehouse(&warehousing)
205
 
210
 
206
 				remark, _ := items["remark"].(string)
211
 				remark, _ := items["remark"].(string)
207
 
212
 
213
+				manufacturer := int64(items["manufacturer"].(float64))
214
+				dealer := int64(items["dealer"].(float64))
215
+
216
+				license_number, _ := items["license_number"].(string)
208
 				warehouseInfo := &models.WarehousingInfo{
217
 				warehouseInfo := &models.WarehousingInfo{
209
 					WarehousingOrder: warehousing.WarehousingOrder,
218
 					WarehousingOrder: warehousing.WarehousingOrder,
210
 					WarehousingId:    warehousing.ID,
219
 					WarehousingId:    warehousing.ID,
221
 					Remark:           remark,
230
 					Remark:           remark,
222
 					OrgId:            adminUserInfo.CurrentOrgId,
231
 					OrgId:            adminUserInfo.CurrentOrgId,
223
 					Type:             types,
232
 					Type:             types,
224
-					Manufacturer:     manufacturer_id,
225
-					Dealer:           dealer_id,
233
+					Manufacturer:     manufacturer,
226
 					StockCount:       warehousing_count,
234
 					StockCount:       warehousing_count,
235
+					Dealer:           dealer,
236
+					LicenseNumber:    license_number,
227
 				}
237
 				}
228
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
238
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
229
 
239
 
388
 	end_time := c.GetString("end_time")
398
 	end_time := c.GetString("end_time")
389
 	types, _ := c.GetInt64("type", 0)
399
 	types, _ := c.GetInt64("type", 0)
390
 	keywords := c.GetString("keywords")
400
 	keywords := c.GetString("keywords")
391
-
392
-	fmt.Println(start_time)
393
-	fmt.Println(end_time)
394
-
395
 	timeLayout := "2006-01-02"
401
 	timeLayout := "2006-01-02"
396
 	loc, _ := time.LoadLocation("Local")
402
 	loc, _ := time.LoadLocation("Local")
397
 	var startTime int64
403
 	var startTime int64
416
 	}
422
 	}
417
 
423
 
418
 	adminUserInfo := c.GetAdminUserInfo()
424
 	adminUserInfo := c.GetAdminUserInfo()
419
-	warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
425
+	var ids []int64
426
+	var goodids []int64
427
+	//查询商品名称
428
+	if len(keywords) > 0 {
429
+		//查询商品名称
430
+		list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
431
+		for _, item := range list {
432
+			goodids = append(goodids, item.ID)
433
+			//入库详情但里面查询
434
+		}
435
+		if len(goodids) > 0 {
436
+			info, _ := service.GetWarehoureOrderInfoByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
437
+			for _, it := range info {
438
+				ids = append(ids, it.WarehousingId)
439
+			}
440
+		}
441
+	}
442
+
443
+	warehouseList, total, err := service.FindAllWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
420
 	if err == nil {
444
 	if err == nil {
421
 		c.ServeSuccessJSON(map[string]interface{}{
445
 		c.ServeSuccessJSON(map[string]interface{}{
422
 			"list":  warehouseList,
446
 			"list":  warehouseList,
427
 	}
451
 	}
428
 }
452
 }
429
 func (c *StockManagerApiController) GetWarehouseInfoList() {
453
 func (c *StockManagerApiController) GetWarehouseInfoList() {
430
-	id, _ := c.GetInt64("id", 0)
431
 
454
 
432
-	if id <= 0 {
433
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
434
-		return
435
-	}
436
-
437
-	warehousing, err := service.FindWarehousingById(id)
455
+	id := c.GetString("id")
456
+	idArray := strings.Split(id, ",")
457
+	warehousing, err := service.FindWarehousingByIdOne(idArray)
438
 
458
 
439
 	if err != nil {
459
 	if err != nil {
440
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
460
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
441
 		return
461
 		return
442
 	}
462
 	}
443
 
463
 
444
-	if warehousing.ID <= 0 {
445
-		return
464
+	var ids []int64
465
+
466
+	for _, item := range warehousing {
467
+		ids = append(ids, item.ID)
446
 	}
468
 	}
447
 
469
 
448
-	warehousingInfo, err := service.FindWarehousingInfoById(id)
470
+	warehousingInfo, err := service.FindWarehousingInfoByIdOne(ids)
449
 	if err == nil {
471
 	if err == nil {
450
 		c.ServeSuccessJSON(map[string]interface{}{
472
 		c.ServeSuccessJSON(map[string]interface{}{
451
 			"info":        warehousingInfo,
473
 			"info":        warehousingInfo,
459
 	warehousing_time := c.GetString("warehousing_time")
481
 	warehousing_time := c.GetString("warehousing_time")
460
 	id, _ := c.GetInt64("id", 0)
482
 	id, _ := c.GetInt64("id", 0)
461
 	types, _ := c.GetInt64("type", 0)
483
 	types, _ := c.GetInt64("type", 0)
462
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
463
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
464
 
484
 
465
 	if id == 0 {
485
 	if id == 0 {
466
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
486
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
488
 		Status:           1,
508
 		Status:           1,
489
 		WarehousingTime:  warehousingDate.Unix(),
509
 		WarehousingTime:  warehousingDate.Unix(),
490
 		Type:             warehouse.Type,
510
 		Type:             warehouse.Type,
491
-		Dealer:           dealer_id,
492
-		Manufacturer:     manufacturer_id,
493
 	}
511
 	}
494
 
512
 
495
 	service.EditWarehousing(warehousing)
513
 	service.EditWarehousing(warehousing)
578
 
596
 
579
 				remark, _ := items["remark"].(string)
597
 				remark, _ := items["remark"].(string)
580
 
598
 
599
+				manufacturer := int64(items["manufacturer"].(float64))
600
+				dealer := int64(items["dealer"].(float64))
601
+				license_number, _ := items["license_number"].(string)
581
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
602
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
582
 					utils.ErrorLog("id")
603
 					utils.ErrorLog("id")
583
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
604
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
602
 						Remark:           remark,
623
 						Remark:           remark,
603
 						OrgId:            adminUserInfo.CurrentOrgId,
624
 						OrgId:            adminUserInfo.CurrentOrgId,
604
 						Type:             types,
625
 						Type:             types,
605
-						Manufacturer:     manufacturer_id,
606
-						Dealer:           dealer_id,
626
+						Manufacturer:     manufacturer,
627
+						Dealer:           dealer,
628
+						StockCount:       warehousing_count,
629
+						LicenseNumber:    license_number,
607
 					}
630
 					}
608
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
631
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
609
 
632
 
625
 						Remark:           remark,
648
 						Remark:           remark,
626
 						OrgId:            adminUserInfo.CurrentOrgId,
649
 						OrgId:            adminUserInfo.CurrentOrgId,
627
 						Type:             types,
650
 						Type:             types,
628
-						Manufacturer:     manufacturer_id,
629
-						Dealer:           dealer_id,
651
+						Manufacturer:     manufacturer,
652
+						Dealer:           dealer,
653
+						StockCount:       warehousing_count,
654
+						LicenseNumber:    license_number,
630
 					}
655
 					}
631
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
656
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
632
 				}
657
 				}
1037
 }
1062
 }
1038
 
1063
 
1039
 func (c *StockManagerApiController) CreateWarehouseOut() {
1064
 func (c *StockManagerApiController) CreateWarehouseOut() {
1040
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
1041
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
1065
+
1042
 	types, _ := c.GetInt64("type", 0)
1066
 	types, _ := c.GetInt64("type", 0)
1043
 
1067
 
1044
 	ctime := time.Now().Unix()
1068
 	ctime := time.Now().Unix()
1063
 	operation_time := time.Now().Unix()
1087
 	operation_time := time.Now().Unix()
1064
 	creater := adminUserInfo.AdminUser.Id
1088
 	creater := adminUserInfo.AdminUser.Id
1065
 
1089
 
1090
+	_, errcode := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1066
 	warehouseOut := models.WarehouseOut{
1091
 	warehouseOut := models.WarehouseOut{
1067
 		WarehouseOutOrderNumber: warehousing_out_order,
1092
 		WarehouseOutOrderNumber: warehousing_out_order,
1068
 		OperationTime:           operation_time,
1093
 		OperationTime:           operation_time,
1071
 		Ctime:                   ctime,
1096
 		Ctime:                   ctime,
1072
 		Status:                  1,
1097
 		Status:                  1,
1073
 		WarehouseOutTime:        warehousingOutDate.Unix(),
1098
 		WarehouseOutTime:        warehousingOutDate.Unix(),
1074
-		Dealer:                  dealer_id,
1075
-		Manufacturer:            manufacturer_id,
1076
 		Type:                    types,
1099
 		Type:                    types,
1077
 	}
1100
 	}
1078
-	service.AddSigleWarehouseOut(&warehouseOut)
1101
+	if errcode == gorm.ErrRecordNotFound {
1102
+		service.AddSigleWarehouseOut(&warehouseOut)
1103
+	}
1104
+
1079
 	dataBody := make(map[string]interface{}, 0)
1105
 	dataBody := make(map[string]interface{}, 0)
1080
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1106
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1081
 	if err != nil {
1107
 	if err != nil {
1100
 				}
1126
 				}
1101
 
1127
 
1102
 				good_id := int64(items["good_id"].(float64))
1128
 				good_id := int64(items["good_id"].(float64))
1103
-				fmt.Println("stockout223232324343445456465656565565665", good_id)
1129
+
1104
 				if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
1130
 				if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
1105
 					utils.ErrorLog("good_type_id")
1131
 					utils.ErrorLog("good_type_id")
1106
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1132
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1126
 				total := float64(count) * price
1152
 				total := float64(count) * price
1127
 				remark := items["remark"].(string)
1153
 				remark := items["remark"].(string)
1128
 
1154
 
1155
+				manufacturer := int64(items["manufacturer"].(float64))
1156
+
1157
+				dealer := int64(items["dealer"].(float64))
1158
+				number := items["number"].(string)
1159
+
1160
+				expiry_date := items["expiry_date"].(string)
1161
+
1162
+				timeLayout := "2006-01-02"
1163
+				loc, _ := time.LoadLocation("Local")
1164
+				var expiryDate int64
1165
+				if len(expiry_date) > 0 {
1166
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1167
+					if err != nil {
1168
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1169
+						return
1170
+					}
1171
+					expiryDate = theTime.Unix()
1172
+				}
1173
+
1174
+				product_date := items["product_date"].(string)
1175
+
1176
+				var productDate int64
1177
+				if len(product_date) > 0 {
1178
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1179
+					if err != nil {
1180
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1181
+						return
1182
+					}
1183
+					productDate = theTime.Unix()
1184
+				}
1185
+
1129
 				warehouseOutInfo := &models.WarehouseOutInfo{
1186
 				warehouseOutInfo := &models.WarehouseOutInfo{
1130
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1187
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1131
 					WarehouseOutId:          warehouseOut.ID,
1188
 					WarehouseOutId:          warehouseOut.ID,
1139
 					Remark:                  remark,
1196
 					Remark:                  remark,
1140
 					OrgId:                   adminUserInfo.CurrentOrgId,
1197
 					OrgId:                   adminUserInfo.CurrentOrgId,
1141
 					Type:                    types,
1198
 					Type:                    types,
1142
-					Manufacturer:            manufacturer_id,
1143
-					Dealer:                  dealer_id,
1199
+					Manufacturer:            manufacturer,
1200
+					Number:                  number,
1201
+					ExpiryDate:              expiryDate,
1202
+					ProductDate:             productDate,
1203
+					Dealer:                  dealer,
1144
 				}
1204
 				}
1145
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1205
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1146
 
1206
 
1162
 		}
1222
 		}
1163
 	}
1223
 	}
1164
 
1224
 
1165
-	//查询库存
1225
+	//出库逻辑
1166
 	for _, item := range warehousingOutInfo {
1226
 	for _, item := range warehousingOutInfo {
1167
-		parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
1168
-		fmt.Println(parseDateErr)
1169
-	}
1227
+		//查询库存
1228
+		warehouse, err := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1229
+		fmt.Println("库存数量组吗", warehouse.Count)
1230
+		if err != nil {
1231
+			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1232
+			c.ServeSuccessJSON(map[string]interface{}{
1233
+				"msg":                "1",
1234
+				"good_name":          goodObj.GoodName,
1235
+				"specification_name": goodObj.SpecificationName,
1236
+			})
1237
+			return
1238
+		} else {
1239
+			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
1240
+			fmt.Println(parseDateErr)
1241
+			if parseDateErr != nil {
1242
+				utils.ErrorLog(parseDateErr.Error())
1243
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1244
+				return
1245
+			}
1246
+
1247
+			c.ServeSuccessJSON(map[string]interface{}{
1248
+				"msg":                "2",
1249
+				"good_name":          "",
1250
+				"specification_name": "",
1251
+			})
1252
+		}
1170
 
1253
 
1171
-	errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1172
-	info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1173
-	if errs != nil {
1174
-		utils.ErrorLog(errs.Error())
1175
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1176
-		return
1177
 	}
1254
 	}
1178
 
1255
 
1179
-	c.ServeSuccessJSON(map[string]interface{}{
1180
-		"msg":                   "出库成功",
1181
-		"info":                  info,
1182
-		"warehousing_out_order": warehousing_out_order,
1183
-	})
1256
+	//errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1257
+	//info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1184
 
1258
 
1185
 }
1259
 }
1186
 func (c *StockManagerApiController) GetWarehouseOutList() {
1260
 func (c *StockManagerApiController) GetWarehouseOutList() {
1214
 	}
1288
 	}
1215
 
1289
 
1216
 	adminUserInfo := c.GetAdminUserInfo()
1290
 	adminUserInfo := c.GetAdminUserInfo()
1217
-	warehouseOutList, total, err := service.FindAllWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
1291
+	var ids []int64
1292
+	var goodids []int64
1293
+	if len(keywords) > 0 {
1294
+		//查询商品名称
1295
+		list, _ := service.GetGoodInforByGoodName(keywords, adminUserInfo.CurrentOrgId)
1296
+		for _, item := range list {
1297
+			goodids = append(goodids, item.ID)
1298
+		}
1299
+
1300
+		if len(goodids) > 0 {
1301
+			//出库详情但里面查询
1302
+			info, _ := service.GetWarehoureOrderOutByGoodId(goodids, startTime, endTime, adminUserInfo.CurrentOrgId)
1303
+			for _, it := range info {
1304
+				ids = append(ids, it.WarehouseOutId)
1305
+			}
1306
+		}
1307
+
1308
+	}
1309
+	warehouseOutList, total, err := service.FindAllWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
1218
 	fmt.Println(err)
1310
 	fmt.Println(err)
1219
 	if err == nil {
1311
 	if err == nil {
1220
 		c.ServeSuccessJSON(map[string]interface{}{
1312
 		c.ServeSuccessJSON(map[string]interface{}{
1277
 }
1369
 }
1278
 func (c *StockManagerApiController) EditWarehouseOut() {
1370
 func (c *StockManagerApiController) EditWarehouseOut() {
1279
 	warehouse_out_time := c.GetString("warehouse_out_time")
1371
 	warehouse_out_time := c.GetString("warehouse_out_time")
1372
+
1280
 	id, _ := c.GetInt64("id", 0)
1373
 	id, _ := c.GetInt64("id", 0)
1281
 	types, _ := c.GetInt64("type", 0)
1374
 	types, _ := c.GetInt64("type", 0)
1282
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
1283
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
1284
 
1375
 
1285
 	if id == 0 {
1376
 	if id == 0 {
1286
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1377
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1304
 		ID:               warehouseOut.ID,
1395
 		ID:               warehouseOut.ID,
1305
 		Mtime:            mtime,
1396
 		Mtime:            mtime,
1306
 		WarehouseOutTime: warehouseOutDate.Unix(),
1397
 		WarehouseOutTime: warehouseOutDate.Unix(),
1307
-		Manufacturer:     manufacturer_id,
1308
-		Dealer:           dealer_id,
1309
 	}
1398
 	}
1310
 
1399
 
1311
 	service.EditWarehouseOut(tempWarehouseOut)
1400
 	service.EditWarehouseOut(tempWarehouseOut)
1366
 				}
1455
 				}
1367
 				id := int64(items["id"].(float64))
1456
 				id := int64(items["id"].(float64))
1368
 
1457
 
1458
+				manufacturer := int64(items["manufacturer"].(float64))
1459
+
1460
+				dealer := int64(items["dealer"].(float64))
1461
+
1462
+				number := items["number"].(string)
1463
+
1464
+				timeLayout := "2006-01-02"
1465
+				loc, _ := time.LoadLocation("Local")
1466
+				expiry_date := items["expiry_date"].(string)
1467
+				var expiryDate int64
1468
+				if len(expiry_date) > 0 {
1469
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1470
+					if err != nil {
1471
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1472
+						return
1473
+					}
1474
+					expiryDate = theTime.Unix()
1475
+				}
1476
+
1477
+				product_date := items["product_date"].(string)
1478
+
1479
+				var productDate int64
1480
+				if len(product_date) > 0 {
1481
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1482
+					if err != nil {
1483
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1484
+						return
1485
+					}
1486
+					productDate = theTime.Unix()
1487
+				}
1488
+
1369
 				if id == 0 {
1489
 				if id == 0 {
1370
 					warehouseOutInfo := &models.WarehouseOutInfo{
1490
 					warehouseOutInfo := &models.WarehouseOutInfo{
1371
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1491
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1380
 						Remark:                  remark,
1500
 						Remark:                  remark,
1381
 						OrgId:                   adminUserInfo.CurrentOrgId,
1501
 						OrgId:                   adminUserInfo.CurrentOrgId,
1382
 						Type:                    types,
1502
 						Type:                    types,
1383
-						Manufacturer:            manufacturer_id,
1384
-						Dealer:                  dealer_id,
1385
 						IsSys:                   0,
1503
 						IsSys:                   0,
1386
 						SysRecordTime:           0,
1504
 						SysRecordTime:           0,
1505
+						Number:                  number,
1506
+						ExpiryDate:              expiryDate,
1507
+						ProductDate:             productDate,
1508
+						Dealer:                  dealer,
1509
+						Manufacturer:            manufacturer,
1387
 					}
1510
 					}
1388
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1511
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1389
 
1512
 
1417
 						OrgId:                   adminUserInfo.CurrentOrgId,
1540
 						OrgId:                   adminUserInfo.CurrentOrgId,
1418
 						Mtime:                   time.Now().Unix(),
1541
 						Mtime:                   time.Now().Unix(),
1419
 						Type:                    types,
1542
 						Type:                    types,
1420
-						Manufacturer:            manufacturer_id,
1421
-						Dealer:                  dealer_id,
1543
+						Manufacturer:            manufacturer,
1422
 						IsSys:                   is_sys,
1544
 						IsSys:                   is_sys,
1423
 						SysRecordTime:           sys_record_time,
1545
 						SysRecordTime:           sys_record_time,
1546
+						Number:                  number,
1547
+						ExpiryDate:              expiryDate,
1548
+						ProductDate:             productDate,
1549
+						Dealer:                  dealer,
1424
 					}
1550
 					}
1425
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1551
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1426
 				}
1552
 				}
3610
 	orgId := adminUserInfo.CurrentOrgId
3736
 	orgId := adminUserInfo.CurrentOrgId
3611
 	list, _ := service.GetSearchGoodList(keyword, orgId)
3737
 	list, _ := service.GetSearchGoodList(keyword, orgId)
3612
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
3738
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
3739
+	dealerList, _ := service.GetAllDealerList(orgId)
3613
 	this.ServeSuccessJSON(map[string]interface{}{
3740
 	this.ServeSuccessJSON(map[string]interface{}{
3614
 		"list":             list,
3741
 		"list":             list,
3615
 		"manufacturerList": manufacturerList,
3742
 		"manufacturerList": manufacturerList,
3743
+		"dealerList":       dealerList,
3616
 	})
3744
 	})
3617
 }
3745
 }
3618
 
3746
 
3669
 	loc, _ := time.LoadLocation("Local")
3797
 	loc, _ := time.LoadLocation("Local")
3670
 	start_time := this.GetString("start_time")
3798
 	start_time := this.GetString("start_time")
3671
 	end_time := this.GetString("end_time")
3799
 	end_time := this.GetString("end_time")
3800
+
3672
 	var startTime int64
3801
 	var startTime int64
3673
 	if len(start_time) > 0 {
3802
 	if len(start_time) > 0 {
3674
 		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3803
 		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3695
 		"total":            total,
3824
 		"total":            total,
3696
 		"manufacturerList": manufacturerList,
3825
 		"manufacturerList": manufacturerList,
3697
 	})
3826
 	})
3827
+
3698
 }
3828
 }
3699
 
3829
 
3700
 func (this *StockManagerApiController) GetStockOutList() {
3830
 func (this *StockManagerApiController) GetStockOutList() {
3708
 	loc, _ := time.LoadLocation("Local")
3838
 	loc, _ := time.LoadLocation("Local")
3709
 	start_time := this.GetString("start_time")
3839
 	start_time := this.GetString("start_time")
3710
 	end_time := this.GetString("end_time")
3840
 	end_time := this.GetString("end_time")
3841
+	is_sys, _ := this.GetInt64("is_sys")
3711
 	var startTime int64
3842
 	var startTime int64
3712
 	if len(start_time) > 0 {
3843
 	if len(start_time) > 0 {
3713
 		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3844
 		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3727
 		}
3858
 		}
3728
 		endTime = theTime.Unix()
3859
 		endTime = theTime.Unix()
3729
 	}
3860
 	}
3730
-	outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime)
3861
+	outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
3731
 	this.ServeSuccessJSON(map[string]interface{}{
3862
 	this.ServeSuccessJSON(map[string]interface{}{
3732
 		"outList": outList,
3863
 		"outList": outList,
3733
 		"total":   total,
3864
 		"total":   total,
3734
 	})
3865
 	})
3735
 }
3866
 }
3867
+
3868
+func (this *StockManagerApiController) GetStockDrugCount() {
3869
+
3870
+	adminUserInfo := this.GetAdminUserInfo()
3871
+	orgId := adminUserInfo.CurrentOrgId
3872
+	fmt.Println(orgId)
3873
+	timeLayout := "2006-01-02"
3874
+	loc, _ := time.LoadLocation("Local")
3875
+	start_time := this.GetString("start_time")
3876
+	end_time := this.GetString("end_time")
3877
+	var startTime int64
3878
+	if len(start_time) > 0 {
3879
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3880
+		if err != nil {
3881
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3882
+			return
3883
+		}
3884
+		startTime = theTime.Unix()
3885
+	}
3886
+	var endTime int64
3887
+	if len(end_time) > 0 {
3888
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
3889
+		if err != nil {
3890
+			utils.ErrorLog(err.Error())
3891
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3892
+			return
3893
+		}
3894
+		endTime = theTime.Unix()
3895
+	}
3896
+
3897
+	count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
3898
+	outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
3899
+	autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
3900
+
3901
+	this.ServeSuccessJSON(map[string]interface{}{
3902
+		"count":     count,
3903
+		"outList":   outList,
3904
+		"autoCount": autoCount,
3905
+	})
3906
+}
3907
+
3908
+func (this *StockManagerApiController) GetOrderDetialByOrderId() {
3909
+
3910
+	//id, _ := this.GetInt64("id")
3911
+	ids := this.GetString("id")
3912
+	idsArray := strings.Split(ids, ",")
3913
+	orgId := this.GetAdminUserInfo().CurrentOrgId
3914
+	order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
3915
+	list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
3916
+	this.ServeSuccessJSON(map[string]interface{}{
3917
+		"order": order,
3918
+		"list":  list,
3919
+	})
3920
+}
3921
+
3922
+func (this *StockManagerApiController) GetOrderDetailById() {
3923
+
3924
+	good_id, _ := this.GetInt64("good_id")
3925
+	record_time, _ := this.GetInt64("record_time")
3926
+	orgId := this.GetAdminUserInfo().CurrentOrgId
3927
+
3928
+	userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
3929
+	if err == nil {
3930
+		this.ServeSuccessJSON(map[string]interface{}{
3931
+			"list":  userDetails,
3932
+			"total": total,
3933
+		})
3934
+	} else {
3935
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3936
+		return
3937
+	}
3938
+}
3939
+
3940
+func (this *StockManagerApiController) GetSingleOutOrderDetail() {
3941
+	id, _ := this.GetInt64("id", 0)
3942
+	orgId := this.GetAdminUserInfo().CurrentOrgId
3943
+
3944
+	warehouseOutInfo, _ := service.GetOrderDetialByOrderId(id, orgId)
3945
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
3946
+	dealerList, _ := service.GetAllDealerList(orgId)
3947
+	goodType, _ := service.GetAllGoodType(orgId)
3948
+	this.ServeSuccessJSON(map[string]interface{}{
3949
+		"list":             warehouseOutInfo,
3950
+		"dealerList":       dealerList,
3951
+		"manufacturerList": manufacturerList,
3952
+		"goodType":         goodType,
3953
+	})
3954
+}
3955
+
3956
+func (this *StockManagerApiController) GetExprotStockList() {
3957
+
3958
+	adminUserInfo := this.GetAdminUserInfo()
3959
+	orgId := adminUserInfo.CurrentOrgId
3960
+	timeLayout := "2006-01-02"
3961
+	loc, _ := time.LoadLocation("Local")
3962
+	start_time := this.GetString("start_time")
3963
+	end_time := this.GetString("end_time")
3964
+	idArray := this.GetString("id")
3965
+	ids := strings.Split(idArray, ",")
3966
+	var startTime int64
3967
+	if len(start_time) > 0 {
3968
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3969
+		if err != nil {
3970
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3971
+			return
3972
+		}
3973
+		startTime = theTime.Unix()
3974
+	}
3975
+	var endTime int64
3976
+	if len(end_time) > 0 {
3977
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
3978
+		if err != nil {
3979
+			utils.ErrorLog(err.Error())
3980
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3981
+			return
3982
+		}
3983
+		endTime = theTime.Unix()
3984
+	}
3985
+
3986
+	list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
3987
+	this.ServeSuccessJSON(map[string]interface{}{
3988
+		"list": list,
3989
+	})
3990
+}
3991
+
3992
+func (this *StockManagerApiController) GetOutExprotList() {
3993
+
3994
+	adminUserInfo := this.GetAdminUserInfo()
3995
+	orgId := adminUserInfo.CurrentOrgId
3996
+	timeLayout := "2006-01-02"
3997
+	loc, _ := time.LoadLocation("Local")
3998
+	start_time := this.GetString("start_time")
3999
+	end_time := this.GetString("end_time")
4000
+	idArray := this.GetString("id")
4001
+	ids := strings.Split(idArray, ",")
4002
+	fmt.Println("ids2222222222", ids)
4003
+	var startTime int64
4004
+	if len(start_time) > 0 {
4005
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
4006
+		if err != nil {
4007
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4008
+			return
4009
+		}
4010
+		startTime = theTime.Unix()
4011
+	}
4012
+	var endTime int64
4013
+	if len(end_time) > 0 {
4014
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
4015
+		if err != nil {
4016
+			utils.ErrorLog(err.Error())
4017
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4018
+			return
4019
+		}
4020
+		endTime = theTime.Unix()
4021
+	}
4022
+	list, _ := service.GetOutExprotList(orgId, ids, startTime, endTime)
4023
+	outCount, _ := service.GetOutStockTotalCountOne(startTime, endTime, orgId)
4024
+	this.ServeSuccessJSON(map[string]interface{}{
4025
+		"list":  list,
4026
+		"count": outCount,
4027
+	})
4028
+}

+ 5 - 0
models/drug_stock.go Parādīt failu

232
 	DrugId                  int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
232
 	DrugId                  int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
233
 	Total                   int64
233
 	Total                   int64
234
 }
234
 }
235
+
236
+type VmDrugWarehouseInfo struct {
237
+	DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
238
+	Count  int64 `gorm:"column:count" json:"count" form:"count"`
239
+}

+ 56 - 55
models/good_models.go Parādīt failu

22
 }
22
 }
23
 
23
 
24
 type GoodInfo struct {
24
 type GoodInfo struct {
25
-	ID                          int64     `gorm:"column:id" json:"id" form:"id"`
26
-	GoodCode                    string    `gorm:"column:good_code" json:"good_code" form:"good_code"`
27
-	SpecificationName           string    `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
28
-	GoodTypeId                  int64     `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
29
-	GoodUnit                    int64     `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
30
-	BuyPrice                    float64   `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
31
-	SellPrice                   float64   `gorm:"column:sell_price" json:"sell_price" form:"sell_price"`
32
-	Remark                      string    `gorm:"column:remark" json:"remark" form:"remark"`
33
-	Ctime                       int64     `gorm:"column:ctime" json:"ctime" form:"ctime"`
34
-	Mtime                       int64     `gorm:"column:mtime" json:"mtime" form:"mtime"`
35
-	Manufacturer                int64     `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
36
-	Dealer                      int64     `gorm:"column:dealer" json:"dealer" form:"dealer"`
37
-	ExpiryDateWarnDayCount      int64     `gorm:"column:expiry_date_warn_day_count" json:"expiry_date_warn_day_count" form:"expiry_date_warn_day_count"`
38
-	StockWarnCount              int64     `gorm:"column:stock_warn_count" json:"stock_warn_count" form:"stock_warn_count"`
39
-	IsReuse                     int64     `gorm:"column:is_reuse" json:"is_reuse" form:"is_reuse"`
40
-	Status                      int64     `gorm:"column:status" json:"status" form:"status"`
41
-	FilmArea                    string    `gorm:"column:film_area" json:"film_area" form:"film_area"`
42
-	IsUse                       int64     `gorm:"column:is_use" json:"is_use" form:"is_use"`
43
-	FilmMaterialQuality         string    `gorm:"column:film_material_quality" json:"film_material_quality" form:"film_material_quality"`
44
-	OrgId                       int64     `gorm:"column:org_id" json:"org_id" form:"org_id"`
45
-	Modifier                    int64     `gorm:"column:modifier" json:"modifier" form:"modifier"`
46
-	Creater                     int64     `gorm:"column:creater" json:"creater" form:"creater"`
47
-	GoodName                    string    `gorm:"column:good_name" json:"good_name" form:"good_name"`
48
-	Pinyin                      string    `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
49
-	Wubi                        string    `gorm:"column:wubi" json:"wubi" form:"wubi"`
50
-	GoodKind                    int64     `gorm:"column:good_kind" json:"good_kind" form:"good_kind"`
51
-	MedicalInsuranceLevel       int64     `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
52
-	RetailPrice                 float64   `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
53
-	MedicalInsuranceNumber      string    `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
54
-	IsSpecialDiseases           int64     `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
55
-	IsRecord                    int64     `gorm:"column:is_record" json:"is_record" form:"is_record"`
56
-	StatisticsCategory          int64     `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
57
-	GoodStatus                  string    `gorm:"column:good_status" json:"good_status" form:"good_status"`
58
-	DefaultCount                int64     `gorm:"column:default_count" json:"default_count" form:"default_count"`
59
-	Sign                        int64     `gorm:"column:sign" json:"sign" form:"sign"`
60
-	IsDefault                   int64     `gorm:"column:is_default" json:"is_default" form:"is_default"`
61
-	IsChargeUse                 int64     `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
62
-	IsChargePredict             int64     `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
63
-	IsStatisticsWork            int64     `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
64
-	Sort                        int64     `gorm:"column:sort" json:"sort" form:"sort"`
65
-	IsDoctorUse                 int64     `gorm:"column:is_doctor_use" json:"is_doctor_use" form:"is_doctor_use"`
66
-	Agent                       string    `gorm:"column:agent" json:"agent" form:"agent"`
67
-	GoodNumber                  string    `gorm:"column:good_number" json:"good_number" form:"good_number"`
68
-	GoodsType                   GoodsType `gorm:"ForeignKey:ID;AssociationForeignKey:GoodTypeId" json:"type"`
69
-	CommdityCode                string    `gorm:"column:commdity_code" json:"commdity_code" form:"commdity_code"`
70
-	SocialSecurityDirectoryCode string    `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
71
-	ProductionType              string    `gorm:"column:production_type" json:"production_type" form:"production_type"`
72
-	SpecialMedical              string    `gorm:"column:special_medical" json:"special_medical" form:"special_medical"`
73
-	IsMark                      int64     `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
74
-	MinNumber                   int64     `gorm:"column:min_number" json:"min_number" form:"min_number"`
75
-	PackingUnit                 string    `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
76
-	PackingPrice                float64   `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
77
-	DefaultCountUnit            string    `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
78
-	MinUnit                     string    `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
79
-	Total                       float64   `gorm:"column:total" json:"total" form:"total"`
25
+	ID                          int64                `gorm:"column:id" json:"id" form:"id"`
26
+	GoodCode                    string               `gorm:"column:good_code" json:"good_code" form:"good_code"`
27
+	SpecificationName           string               `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
28
+	GoodTypeId                  int64                `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
29
+	GoodUnit                    int64                `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
30
+	BuyPrice                    float64              `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
31
+	SellPrice                   float64              `gorm:"column:sell_price" json:"sell_price" form:"sell_price"`
32
+	Remark                      string               `gorm:"column:remark" json:"remark" form:"remark"`
33
+	Ctime                       int64                `gorm:"column:ctime" json:"ctime" form:"ctime"`
34
+	Mtime                       int64                `gorm:"column:mtime" json:"mtime" form:"mtime"`
35
+	Manufacturer                int64                `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
36
+	Dealer                      int64                `gorm:"column:dealer" json:"dealer" form:"dealer"`
37
+	ExpiryDateWarnDayCount      int64                `gorm:"column:expiry_date_warn_day_count" json:"expiry_date_warn_day_count" form:"expiry_date_warn_day_count"`
38
+	StockWarnCount              int64                `gorm:"column:stock_warn_count" json:"stock_warn_count" form:"stock_warn_count"`
39
+	IsReuse                     int64                `gorm:"column:is_reuse" json:"is_reuse" form:"is_reuse"`
40
+	Status                      int64                `gorm:"column:status" json:"status" form:"status"`
41
+	FilmArea                    string               `gorm:"column:film_area" json:"film_area" form:"film_area"`
42
+	IsUse                       int64                `gorm:"column:is_use" json:"is_use" form:"is_use"`
43
+	FilmMaterialQuality         string               `gorm:"column:film_material_quality" json:"film_material_quality" form:"film_material_quality"`
44
+	OrgId                       int64                `gorm:"column:org_id" json:"org_id" form:"org_id"`
45
+	Modifier                    int64                `gorm:"column:modifier" json:"modifier" form:"modifier"`
46
+	Creater                     int64                `gorm:"column:creater" json:"creater" form:"creater"`
47
+	GoodName                    string               `gorm:"column:good_name" json:"good_name" form:"good_name"`
48
+	Pinyin                      string               `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
49
+	Wubi                        string               `gorm:"column:wubi" json:"wubi" form:"wubi"`
50
+	GoodKind                    int64                `gorm:"column:good_kind" json:"good_kind" form:"good_kind"`
51
+	MedicalInsuranceLevel       int64                `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
52
+	RetailPrice                 float64              `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
53
+	MedicalInsuranceNumber      string               `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
54
+	IsSpecialDiseases           int64                `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
55
+	IsRecord                    int64                `gorm:"column:is_record" json:"is_record" form:"is_record"`
56
+	StatisticsCategory          int64                `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
57
+	GoodStatus                  string               `gorm:"column:good_status" json:"good_status" form:"good_status"`
58
+	DefaultCount                int64                `gorm:"column:default_count" json:"default_count" form:"default_count"`
59
+	Sign                        int64                `gorm:"column:sign" json:"sign" form:"sign"`
60
+	IsDefault                   int64                `gorm:"column:is_default" json:"is_default" form:"is_default"`
61
+	IsChargeUse                 int64                `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
62
+	IsChargePredict             int64                `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
63
+	IsStatisticsWork            int64                `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
64
+	Sort                        int64                `gorm:"column:sort" json:"sort" form:"sort"`
65
+	IsDoctorUse                 int64                `gorm:"column:is_doctor_use" json:"is_doctor_use" form:"is_doctor_use"`
66
+	Agent                       string               `gorm:"column:agent" json:"agent" form:"agent"`
67
+	GoodNumber                  string               `gorm:"column:good_number" json:"good_number" form:"good_number"`
68
+	GoodsType                   GoodsType            `gorm:"ForeignKey:ID;AssociationForeignKey:GoodTypeId" json:"type"`
69
+	CommdityCode                string               `gorm:"column:commdity_code" json:"commdity_code" form:"commdity_code"`
70
+	SocialSecurityDirectoryCode string               `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
71
+	ProductionType              string               `gorm:"column:production_type" json:"production_type" form:"production_type"`
72
+	SpecialMedical              string               `gorm:"column:special_medical" json:"special_medical" form:"special_medical"`
73
+	IsMark                      int64                `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
74
+	MinNumber                   int64                `gorm:"column:min_number" json:"min_number" form:"min_number"`
75
+	PackingUnit                 string               `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
76
+	PackingPrice                float64              `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
77
+	DefaultCountUnit            string               `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
78
+	MinUnit                     string               `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
79
+	Total                       float64              `gorm:"column:total" json:"total" form:"total"`
80
+	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:good_id;AssociationForeignKey:ID" json:"xt_warehouse_info"`
80
 }
81
 }
81
 
82
 
82
 func (GoodInfo) TableName() string {
83
 func (GoodInfo) TableName() string {

+ 35 - 0
models/self_drug_models.go Parādīt failu

599
 	PackingUnit      string  `json:"packing_unit"`
599
 	PackingUnit      string  `json:"packing_unit"`
600
 	Dosage           int64   `json:"dosage"`
600
 	Dosage           int64   `json:"dosage"`
601
 }
601
 }
602
+
603
+type VmDrugWarehouseOutInfo struct {
604
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
605
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
606
+	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
607
+	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
608
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
609
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
610
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
611
+	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
612
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
613
+	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
614
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
615
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
616
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
617
+	OrgId                   int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
618
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
619
+	IsCancel                int64   `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
620
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
621
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
622
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
623
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
624
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
625
+	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
626
+	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
627
+	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
628
+	DrugType                int64   `json:"drug_type"`
629
+	MaxUnit                 string  `json:"max_unit"`
630
+	MinUnit                 string  `json:"min_unit"`
631
+	MinNumber               int64   `json:"min_number"`
632
+	Dose                    float64 `json:"dose"`
633
+	DoseUnit                string  `json:"dose_unit"`
634
+	LastPrice               string  `json:"last_price"`
635
+	DrugName                string  `json:"drug_name"`
636
+}

+ 112 - 1
models/stock_models.go Parādīt failu

70
 	return "xt_warehouse"
70
 	return "xt_warehouse"
71
 }
71
 }
72
 
72
 
73
+type StWarehousingInfo struct {
74
+	ID                int64   `gorm:"column:id" json:"id"`
75
+	WarehousingId     int64   `gorm:"column:warehousing_id" json:"warehousing_id"`
76
+	GoodId            int64   `gorm:"column:good_id" json:"good_id"`
77
+	GoodTypeId        int64   `gorm:"column:good_type_id" json:"good_type_id"`
78
+	Number            string  `gorm:"column:number" json:"number"`
79
+	ProductDate       int64   `gorm:"column:product_date" json:"product_date"`
80
+	ExpiryDate        int64   `gorm:"column:expiry_date" json:"expiry_date"`
81
+	WarehousingCount  int64   `gorm:"column:warehousing_count" json:"warehousing_count"`
82
+	WarehousingUnit   string  `gorm:"column:warehousing_unit" json:"warehousing_unit"`
83
+	Price             float64 `gorm:"column:price" json:"price"`
84
+	TotalPrice        float64 `gorm:"column:total_price" json:"total_price"`
85
+	Dealer            int64   `gorm:"column:dealer" json:"dealer"`
86
+	Manufacturer      int64   `gorm:"column:manufacturer" json:"manufacturer"`
87
+	Remark            string  `gorm:"column:remark" json:"remark"`
88
+	Ctime             int64   `gorm:"column:ctime" json:"ctime"`
89
+	Mtime             int64   `gorm:"column:mtime" json:"mtime"`
90
+	Status            int64   `gorm:"column:status" json:"status"`
91
+	OrgId             int64   `gorm:"column:org_id" json:"org_id"`
92
+	IsReturn          int64   `gorm:"column:is_return" json:"is_return"`
93
+	StockCount        int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
94
+	WarehousingOrder  string  `gorm:"column:warehousing_order" json:"warehousing_order"`
95
+	Type              int64   `gorm:"column:type" json:"type"`
96
+	GoodName          string  `json:"good_name"`
97
+	PackingUnit       string  `json:"packing_unit"`
98
+	TotalCount        int64   `json:"total_count"`
99
+	SpecificationName string  `json:"specification_name"`
100
+}
101
+
102
+func (StWarehousingInfo) TableName() string {
103
+	return "xt_warehouse_info"
104
+}
105
+
73
 type WarehousingInfo struct {
106
 type WarehousingInfo struct {
74
 	ID               int64       `gorm:"column:id" json:"id"`
107
 	ID               int64       `gorm:"column:id" json:"id"`
75
 	WarehousingId    int64       `gorm:"column:warehousing_id" json:"warehousing_id"`
108
 	WarehousingId    int64       `gorm:"column:warehousing_id" json:"warehousing_id"`
95
 	WarehousingOrder string      `gorm:"column:warehousing_order" json:"warehousing_order"`
128
 	WarehousingOrder string      `gorm:"column:warehousing_order" json:"warehousing_order"`
96
 	GoodInfo         GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
129
 	GoodInfo         GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
97
 	Type             int64       `gorm:"column:type" json:"type"`
130
 	Type             int64       `gorm:"column:type" json:"type"`
131
+	LicenseNumber    string      `gorm:"column:license_number" json:"license_number" form:"license_number"`
98
 }
132
 }
99
 
133
 
100
 func (WarehousingInfo) TableName() string {
134
 func (WarehousingInfo) TableName() string {
129
 	GoodName          string      `gorm:"column:good_name" json:"good_name"`
163
 	GoodName          string      `gorm:"column:good_name" json:"good_name"`
130
 	SpecificationName string      `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
164
 	SpecificationName string      `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
131
 	MinNumber         int64       `gorm:"column:min_number" json:"min_number" form:"min_number"`
165
 	MinNumber         int64       `gorm:"column:min_number" json:"min_number" form:"min_number"`
132
-	MinUnit           string      `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
166
+	PackingUnit       string      `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
167
+	Count             int64       `gorm:json:"count"`
133
 }
168
 }
134
 
169
 
135
 type WarehouseOut struct {
170
 type WarehouseOut struct {
183
 	IsSys                   int64        `gorm:"column:is_sys" json:"is_sys"`
218
 	IsSys                   int64        `gorm:"column:is_sys" json:"is_sys"`
184
 	SysRecordTime           int64        `gorm:"column:sys_record_time" json:"sys_record_time"`
219
 	SysRecordTime           int64        `gorm:"column:sys_record_time" json:"sys_record_time"`
185
 	PatientId               int64        `gorm:"column:patient_id" json:"patient_id"`
220
 	PatientId               int64        `gorm:"column:patient_id" json:"patient_id"`
221
+	Number                  string       `gorm:"column:number" json:"number" form:"number"`
186
 }
222
 }
187
 
223
 
188
 func (WarehouseOutInfo) TableName() string {
224
 func (WarehouseOutInfo) TableName() string {
353
 	Price  float64 `gorm:"column:price" json:"price"`
389
 	Price  float64 `gorm:"column:price" json:"price"`
354
 	OrgId  int64   `gorm:"column:org_id" json:"org_id"`
390
 	OrgId  int64   `gorm:"column:org_id" json:"org_id"`
355
 }
391
 }
392
+
393
+type VmWarehouseInfo struct {
394
+	GoodId int64 `gorm:"column:good_id" json:"good_id"`
395
+	Count  int64 `gorm:"column:count" json:"count"`
396
+	OrgId  int64 `gorm:"column:org_id" json:"org_id"`
397
+}
398
+
399
+type WarehouseOutInfoOne struct {
400
+	ID                      int64   `gorm:"column:id" json:"id"`
401
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
402
+	WarehouseInfotId        int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id"`
403
+	GoodId                  int64   `gorm:"column:good_id" json:"good_id"`
404
+	GoodTypeId              int64   `gorm:"column:good_type_id" json:"good_type_id"`
405
+	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target"`
406
+	Count                   int64   `gorm:"column:count" json:"count"`
407
+	Price                   float64 `gorm:"column:price" json:"price"`
408
+	TotalPrice              float64 `gorm:"column:total_price" json:"total_price"`
409
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date"`
410
+	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date"`
411
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime"`
412
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime"`
413
+	Status                  int64   `gorm:"column:status" json:"status"`
414
+	OrgId                   int64   `gorm:"column:org_id" json:"org_id"`
415
+	Remark                  string  `gorm:"column:remark" json:"remark"`
416
+	IsCancel                int64   `gorm:"column:is_cancel" json:"is_cancel"`
417
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
418
+	Type                    int64   `gorm:"column:type" json:"type"`
419
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer"`
420
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer"`
421
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys"`
422
+	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time"`
423
+	PatientId               int64   `gorm:"column:patient_id" json:"patient_id"`
424
+	GoodName                string  `gorm:"column:good_name" json:"good_name" form:"good_name"`
425
+	SpecificationName       string  `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
426
+	MinNumber               int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
427
+	PackingPrice            float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
428
+	MinUnit                 string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
429
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
430
+	PackingUnit             string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
431
+}
432
+
433
+type WarehouseOutInfoTwo struct {
434
+	ID                      int64                `gorm:"column:id" json:"id"`
435
+	WarehouseOutId          int64                `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
436
+	WarehouseInfotId        int64                `gorm:"column:warehouse_info_id" json:"warehouse_info_id"`
437
+	GoodId                  int64                `gorm:"column:good_id" json:"good_id"`
438
+	GoodTypeId              int64                `gorm:"column:good_type_id" json:"good_type_id"`
439
+	WarehousingOutTarget    int64                `gorm:"column:warehousing_out_target" json:"warehousing_out_target"`
440
+	Count                   int64                `gorm:"column:count" json:"count"`
441
+	Price                   float64              `gorm:"column:price" json:"price"`
442
+	TotalPrice              float64              `gorm:"column:total_price" json:"total_price"`
443
+	ProductDate             int64                `gorm:"column:product_date" json:"product_date"`
444
+	ExpiryDate              int64                `gorm:"column:expiry_date" json:"expiry_date"`
445
+	Mtime                   int64                `gorm:"column:mtime" json:"mtime"`
446
+	Ctime                   int64                `gorm:"column:ctime" json:"ctime"`
447
+	Status                  int64                `gorm:"column:status" json:"status"`
448
+	OrgId                   int64                `gorm:"column:org_id" json:"org_id"`
449
+	Remark                  string               `gorm:"column:remark" json:"remark"`
450
+	IsCancel                int64                `gorm:"column:is_cancel" json:"is_cancel"`
451
+	WarehouseOutOrderNumber string               `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
452
+	Type                    int64                `gorm:"column:type" json:"type"`
453
+	Dealer                  int64                `gorm:"column:dealer" json:"dealer"`
454
+	Manufacturer            int64                `gorm:"column:manufacturer" json:"manufacturer"`
455
+	IsSys                   int64                `gorm:"column:is_sys" json:"is_sys"`
456
+	SysRecordTime           int64                `gorm:"column:sys_record_time" json:"sys_record_time"`
457
+	PatientId               int64                `gorm:"column:patient_id" json:"patient_id"`
458
+	GoodName                string               `gorm:"column:good_name" json:"good_name" form:"good_name"`
459
+	SpecificationName       string               `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
460
+	MinNumber               int64                `gorm:"column:min_number" json:"min_number" form:"min_number"`
461
+	PackingPrice            float64              `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
462
+	MinUnit                 string               `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
463
+	Number                  string               `gorm:"column:number" json:"number" form:"number"`
464
+	PackingUnit             string               `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
465
+	StWarehousingInfo       []*StWarehousingInfo `gorm:"ForeignKey:good_id;AssociationForeignKey:GoodId" json:"xt_warehouse_info"`
466
+}

+ 7 - 7
models/stock_query_models.go Parādīt failu

1
 package models
1
 package models
2
 
2
 
3
 type StockInfo struct {
3
 type StockInfo struct {
4
-	ID                int64  `gorm:"column:id" json:"id"`
5
-	GoodCode          string `gorm:"column:good_code" json:"good_code"`
6
-	GoodName          string `gorm:"column:good_name" json:"good_name"`
7
-	SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
8
-	GoodTypeId        int64  `gorm:"column:good_type_id" json:"good_type_id"`
9
-	GoodUnit          int64  `gorm:"column:good_unit" json:"good_unit"`
10
-
4
+	ID                    int64                   `gorm:"column:id" json:"id"`
5
+	GoodCode              string                  `gorm:"column:good_code" json:"good_code"`
6
+	GoodName              string                  `gorm:"column:good_name" json:"good_name"`
7
+	SpecificationName     string                  `gorm:"column:specification_name" json:"specification_name"`
8
+	GoodTypeId            int64                   `gorm:"column:good_type_id" json:"good_type_id"`
9
+	GoodUnit              int64                   `gorm:"column:good_unit" json:"good_unit"`
10
+	MinUnit               string                  `gorm:"column:min_unit" json:"min_unit"`
11
 	QueryWarehousingInfo  []QueryWarehousingInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_warehousing_info"`
11
 	QueryWarehousingInfo  []QueryWarehousingInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_warehousing_info"`
12
 	QuerySalesReturnInfo  []QuerySalesReturnInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_sales_return_info"`
12
 	QuerySalesReturnInfo  []QuerySalesReturnInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_sales_return_info"`
13
 	QueryWarehouseOutInfo []QueryWarehouseOutInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_warehouseout_info"`
13
 	QueryWarehouseOutInfo []QueryWarehouseOutInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_warehouseout_info"`

+ 0 - 5
service/app_version.go Parādīt failu

266
 	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 4 AND status = 1 AND order_status = 2").Last(&his).Error
266
 	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 4 AND status = 1 AND order_status = 2").Last(&his).Error
267
 	return
267
 	return
268
 }
268
 }
269
-
270
-func SaveOrder(his *models.HisOrder) {
271
-	writeDb.Save(&his)
272
-
273
-}

+ 120 - 18
service/gobal_config_service.go Parādīt failu

497
 }
497
 }
498
 
498
 
499
 func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
499
 func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
500
-
500
+	offset := (page - 1) * limit
501
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
501
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
502
 
502
 
503
 	likeKey := "%" + keyword + "%"
503
 	likeKey := "%" + keyword + "%"
504
-	offset := (page - 1) * limit
505
-	if len(keyword) > 0 {
506
-		db = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status= 1 and t.org_id = ? and  t.drug_name like ?", orgid, likeKey)
507
-	} else {
508
-		db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status= 1 and t.org_id = ?", orgid)
509
-	}
510
-	if drugcategory > 0 {
511
-		db = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status= 1 and t.org_id = ? and  t.drug_category = ?", orgid, drugcategory)
512
-	} else {
513
-		db = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status= 1 and t.org_id = ? and  t.drug_category = ?", orgid, drugcategory)
504
+	if orgid > 0 {
505
+		db = db.Where("x.org_id = ?", orgid)
514
 	}
506
 	}
515
 
507
 
516
 	if startime > 0 {
508
 	if startime > 0 {
519
 	if endtime > 0 {
511
 	if endtime > 0 {
520
 		db = db.Where("x.ctime<=?", endtime)
512
 		db = db.Where("x.ctime<=?", endtime)
521
 	}
513
 	}
514
+	if drugcategory > 0 && len(keyword) == 0 {
515
+		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id =?", orgid).Where("t.drug_type = ?", drugcategory).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
516
+		return
517
+	}
518
+	if drugcategory <= 0 && len(keyword) == 0 {
519
+		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
520
+		return
521
+	}
522
 
522
 
523
-	if orgid > 0 {
524
-		db = db.Where("x.org_id = ?", orgid)
523
+	if len(keyword) > 0 && drugcategory == 0 {
524
+		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id=?", orgid).Where("t.drug_name like ?", likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
525
+		return
526
+	}
527
+	if len(keyword) <= 0 && drugcategory == 0 {
528
+		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
529
+		return
530
+	}
531
+
532
+	if len(keyword) > 0 && drugcategory > 0 {
533
+		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Where("t.drug_type = ? or t.drug_name like ?", drugcategory, likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
534
+		return
525
 	}
535
 	}
526
 
536
 
527
-	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Offset(offset).Count(&total).Group("x.drug_id").Order("x.ctime desc").Scan(&list).Error
528
 	return list, total, err
537
 	return list, total, err
529
 }
538
 }
530
 
539
 
547
 		db = db.Where("x.drug_id = ?", drugid)
556
 		db = db.Where("x.drug_id = ?", drugid)
548
 	}
557
 	}
549
 
558
 
550
-	err = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status = 1 and t.org_id = ?", orgid).Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Offset(offset).Count(&total).Order("x.ctime desc").Scan(&list).Error
559
+	err = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status = 1 and t.org_id = ?", orgid).Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,x.ctime,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Offset(offset).Count(&total).Order("x.ctime desc").Scan(&list).Error
551
 	return list, total, err
560
 	return list, total, err
552
 }
561
 }
553
 
562
 
573
 		db = db.Where("x.is_sys = 0")
582
 		db = db.Where("x.is_sys = 0")
574
 	}
583
 	}
575
 	if stocktype == 2 {
584
 	if stocktype == 2 {
576
-		db = db.Where("x,is_sys = 1")
585
+		db = db.Where("x.is_sys = 1")
577
 	}
586
 	}
578
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id").Offset(offset).Count(&total).Order("x.ctime desc").Scan(&list).Error
587
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id,x.ctime").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
579
 	return list, total, err
588
 	return list, total, err
580
 }
589
 }
581
 
590
 
582
 func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
591
 func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
583
 	offset := (page - 1) * limit
592
 	offset := (page - 1) * limit
584
-	err = XTReadDB().Model(&drug).Where("drug_id = ? and org_id = ?", drugid, orgid).Offset(offset).Count(&total).Find(&drug).Error
593
+	err = XTReadDB().Model(&drug).Where("drug_id = ? and org_id = ?", drugid, orgid).Count(&total).Offset(offset).Limit(limit).Find(&drug).Error
585
 	return drug, total, err
594
 	return drug, total, err
586
 }
595
 }
596
+
597
+func GetDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
598
+
599
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
600
+
601
+	if startime > 0 {
602
+		db = db.Where("x.ctime >=?", startime)
603
+	}
604
+	if endtime > 0 {
605
+		db = db.Where("x.ctime<=?", endtime)
606
+	}
607
+	if orgid > 0 {
608
+		db = db.Where("x.org_id = ?", orgid)
609
+	}
610
+	err = db.Select("sum(x.warehousing_count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
611
+	return info, err
612
+}
613
+
614
+func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
615
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
616
+
617
+	if startime > 0 {
618
+		db = db.Where("x.ctime >=?", startime)
619
+	}
620
+	if endtime > 0 {
621
+		db = db.Where("x.ctime<=?", endtime)
622
+	}
623
+	if orgid > 0 {
624
+		db = db.Where("x.org_id = ?", orgid)
625
+	}
626
+	err = db.Select("sum(x.stock_min_number) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
627
+	return info, err
628
+}
629
+
630
+func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
631
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
632
+
633
+	if startime > 0 {
634
+		db = db.Where("x.ctime >=?", startime)
635
+	}
636
+	if endtime > 0 {
637
+		db = db.Where("x.ctime<=?", endtime)
638
+	}
639
+	if orgid > 0 {
640
+		db = db.Where("x.org_id = ?", orgid)
641
+	}
642
+	err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
643
+	return info, err
644
+}
645
+
646
+func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugAutomaticReduceDetail, err error) {
647
+	db := XTReadDB().Table("xt_drug_automatic_reduce_detail as x").Where("x.status = 1")
648
+
649
+	if startime > 0 {
650
+		db = db.Where("x.record_time >=?", startime)
651
+	}
652
+	if endtime > 0 {
653
+		db = db.Where("x.record_time<=?", endtime)
654
+	}
655
+	if orgid > 0 {
656
+		db = db.Where("x.org_id = ?", orgid)
657
+	}
658
+	err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
659
+	return info, err
660
+
661
+}
662
+
663
+func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
664
+
665
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
666
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
667
+	fmt.Println(table)
668
+	if orgid > 0 {
669
+		db = db.Where("x.org_id = ?", orgid)
670
+	}
671
+	if id > 0 {
672
+		db = db.Where("x.warehouse_out_id = ?", id)
673
+	}
674
+
675
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
676
+	return info, err
677
+}
678
+
679
+func FindDrugStockUserDetailByIdThree(id int64, record_time int64, org_id int64) (user []*DrugAutomaticReduceDetail, err error, total int64) {
680
+
681
+	db := readDb.Model(&user)
682
+	db = db.Preload("Drug", "org_id = ? AND status = 1", org_id)
683
+	db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
684
+	db = db.Where("status = 1 AND org_id = ? AND drug_id = ? AND record_time =?", org_id, id, record_time)
685
+	db = db.Count(&total)
686
+	err = db.Find(&user).Error
687
+	return user, err, total
688
+}

+ 3 - 1
service/his_project_service.go Parādīt failu

398
 
398
 
399
 func GetDoctorAdvicePrint(his_patient_id int64, recorddate int64, schIDs []string, orgid int64) (prescription []*models.HisPrescription, err error) {
399
 func GetDoctorAdvicePrint(his_patient_id int64, recorddate int64, schIDs []string, orgid int64) (prescription []*models.HisPrescription, err error) {
400
 
400
 
401
-	err = XTReadDB().Model(&prescription).Where("patient_id = ? and record_date = ? and id in(?) and  status = 1 ", his_patient_id, recorddate, schIDs).Preload("Patients", "status = 1 and user_org_id = ?", orgid).Preload("HisDoctorAdviceInfo", "status = 1 and user_org_id = ?", orgid).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
401
+	err = XTReadDB().Model(&prescription).Where("patient_id = ? and record_date = ? and id in(?) and  status = 1 ", his_patient_id, recorddate, schIDs).Preload("Patients", "status = 1 and user_org_id = ?", orgid).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
402
+		return db.Where("status = 1 and user_org_id = ?", orgid).Preload("Drug", "status = 1")
403
+	}).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
402
 		return db.Where("status = 1 AND user_org_id = ?", orgid).Preload("HisProject").Preload("GoodInfo", "status=1")
404
 		return db.Where("status = 1 AND user_org_id = ?", orgid).Preload("HisProject").Preload("GoodInfo", "status=1")
403
 	}).Preload("VMHisPrescriptionInfo", "status =1 and user_org_id = ?", orgid).Preload("XtHisAdditionalCharge", "status = 1 and user_org_id = ?", orgid).Find(&prescription).Error
405
 	}).Preload("VMHisPrescriptionInfo", "status =1 and user_org_id = ?", orgid).Preload("XtHisAdditionalCharge", "status = 1 and user_org_id = ?", orgid).Find(&prescription).Error
404
 
406
 

+ 49 - 25
service/mobile_dialysis_service.go Parādīt failu

894
 		if patientType == 0 {
894
 		if patientType == 0 {
895
 			db := readDb.
895
 			db := readDb.
896
 				Table("xt_schedule").
896
 				Table("xt_schedule").
897
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
898
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
897
 				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
899
 				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
900
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
898
 				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
901
 				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
899
 					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
902
 					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
900
 				}).
903
 				}).
901
 				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
904
 				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
902
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
905
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
903
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
904
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
905
-				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
906
 				Where("status = 1 AND user_org_id = ?", orgID)
906
 				Where("status = 1 AND user_org_id = ?", orgID)
907
 			if scheduleDate != 0 {
907
 			if scheduleDate != 0 {
908
 				db = db.Where("schedule_date = ?", scheduleDate)
908
 				db = db.Where("schedule_date = ?", scheduleDate)
912
 		if patientType > 0 {
912
 		if patientType > 0 {
913
 			db := readDb.
913
 			db := readDb.
914
 				Table("xt_schedule").
914
 				Table("xt_schedule").
915
-				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
916
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
917
-					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
918
-				}).
919
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
920
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
921
 				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
915
 				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
916
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
922
 				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
917
 				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
923
 				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
918
 				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
924
-				Where("status = 1 AND user_org_id = ?", orgID)
919
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
920
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
921
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
922
+					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
923
+				}).Where("status = 1 AND user_org_id = ?", orgID)
925
 			if scheduleDate != 0 {
924
 			if scheduleDate != 0 {
926
 				db = db.Where("schedule_date = ?", scheduleDate)
925
 				db = db.Where("schedule_date = ?", scheduleDate)
927
 			}
926
 			}
932
 		if patientType == 0 {
931
 		if patientType == 0 {
933
 			db := readDb.
932
 			db := readDb.
934
 				Table("xt_schedule").
933
 				Table("xt_schedule").
935
-				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
934
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
935
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
936
 				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
936
 				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
937
 					return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
937
 					return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
938
 				}).
938
 				}).
939
 				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
939
 				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
940
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
940
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
941
 				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
941
 				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
942
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
943
-				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
942
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
944
 				Where("status = 1 AND user_org_id = ?", orgID)
943
 				Where("status = 1 AND user_org_id = ?", orgID)
945
 			if scheduleDate != 0 {
944
 			if scheduleDate != 0 {
946
 				db = db.Where("schedule_date = ?", scheduleDate)
945
 				db = db.Where("schedule_date = ?", scheduleDate)
950
 		if patientType > 0 {
949
 		if patientType > 0 {
951
 			db := readDb.
950
 			db := readDb.
952
 				Table("xt_schedule").
951
 				Table("xt_schedule").
952
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
953
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
954
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
953
 				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
955
 				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
954
 				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
956
 				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
955
 					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
957
 					return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
956
-				}).
957
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
958
+				}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
958
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
959
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
959
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
960
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
961
-				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
962
 				Where("status = 1 AND user_org_id = ?", orgID)
960
 				Where("status = 1 AND user_org_id = ?", orgID)
963
 			if scheduleDate != 0 {
961
 			if scheduleDate != 0 {
964
 				db = db.Where("schedule_date = ?", scheduleDate)
962
 				db = db.Where("schedule_date = ?", scheduleDate)
1523
 	return
1521
 	return
1524
 }
1522
 }
1525
 
1523
 
1524
+func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
1525
+	err = readDb.Model(&models.BloodAutomaticReduceDetail{}).Where("user_org_id = ? AND patient_id = ? AND record_time = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
1526
+	return
1527
+}
1528
+
1526
 //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
1529
 //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
1527
 //	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patient_id,recordDate).Find(&consumables).Error
1530
 //	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patient_id,recordDate).Find(&consumables).Error
1528
 //	return
1531
 //	return
1833
 	ScheduleType           int64                            `gorm:"column:schedule_type" json:"schedule_type"`
1836
 	ScheduleType           int64                            `gorm:"column:schedule_type" json:"schedule_type"`
1834
 	ModeId                 int64                            `gorm:"column:mode_id" json:"mode_id"`
1837
 	ModeId                 int64                            `gorm:"column:mode_id" json:"mode_id"`
1835
 	Status                 int64                            `gorm:"column:status" json:"status"`
1838
 	Status                 int64                            `gorm:"column:status" json:"status"`
1836
-	DialysisOrder          *MDialysisOrderVM                `gorm:"ForeignKeyPatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
1839
+	DialysisOrder          *MDialysisOrderVM                `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
1837
 	SchedualPatient        *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
1840
 	SchedualPatient        *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
1838
 	DeviceNumber           *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
1841
 	DeviceNumber           *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
1839
 	Prescription           *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
1842
 	Prescription           *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
2037
 			db = db.Where("partition_id = ?", partitionType)
2040
 			db = db.Where("partition_id = ?", partitionType)
2038
 		}
2041
 		}
2039
 		db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
2042
 		db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
2040
-			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
2041
-				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
2042
-			}).
2043
 			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
2043
 			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
2044
 			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2044
 			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2045
 			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
2045
 			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
2046
 			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
2046
 			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
2047
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
2048
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
2049
+			}).
2047
 			Where("status = 1 AND user_org_id = ?", orgID)
2050
 			Where("status = 1 AND user_org_id = ?", orgID)
2048
 		if scheduleDate != 0 {
2051
 		if scheduleDate != 0 {
2049
 			db = db.Where("schedule_date = ?", scheduleDate)
2052
 			db = db.Where("schedule_date = ?", scheduleDate)
2058
 			db = db.Where("partition_id = ?", partitionType)
2061
 			db = db.Where("partition_id = ?", partitionType)
2059
 		}
2062
 		}
2060
 		db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
2063
 		db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
2061
-			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
2062
-				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
2063
-			}).
2064
 			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
2064
 			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
2065
 			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2065
 			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2066
 			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
2066
 			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
2067
 			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
2067
 			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
2068
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
2069
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
2070
+			}).
2068
 			Where("status = 1 AND user_org_id = ?", orgID)
2071
 			Where("status = 1 AND user_org_id = ?", orgID)
2069
 		if scheduleDate != 0 {
2072
 		if scheduleDate != 0 {
2070
 			db = db.Where("schedule_date = ?", scheduleDate)
2073
 			db = db.Where("schedule_date = ?", scheduleDate)
2140
 	return err
2143
 	return err
2141
 }
2144
 }
2142
 
2145
 
2146
+func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
2147
+	detail := models.DialysisBeforePrepare{}
2148
+	err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_date = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"status": 0}).Error
2149
+	return err
2150
+}
2151
+
2143
 func BatchAdviceCheck(ids []string, creator int64) error {
2152
 func BatchAdviceCheck(ids []string, creator int64) error {
2144
 
2153
 
2145
 	advice := models.XtDoctorAdvice{}
2154
 	advice := models.XtDoctorAdvice{}
2237
 
2246
 
2238
 	return vms, err
2247
 	return vms, err
2239
 }
2248
 }
2249
+
2250
+func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
2251
+
2252
+	prepare := models.DialysisBeforePrepare{}
2253
+
2254
+	err := XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count  <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
2255
+	return err
2256
+}
2257
+
2258
+func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
2259
+
2260
+	detail := models.AutomaticReduceDetail{}
2261
+	err := XTWriteDB().Model(&detail).Where("good_id = ? and record_time = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
2262
+	return err
2263
+}

+ 383 - 20
service/stock_service.go Parādīt failu

375
 	if len(warehousingInfo) > 0 {
375
 	if len(warehousingInfo) > 0 {
376
 		utx := writeDb.Begin()
376
 		utx := writeDb.Begin()
377
 		if len(warehousingInfo) > 0 {
377
 		if len(warehousingInfo) > 0 {
378
-			thisSQL := "INSERT INTO xt_warehouse_info (warehousing_id, good_id, good_type_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,stock_count) VALUES "
378
+			thisSQL := "INSERT INTO xt_warehouse_info (warehousing_id, good_id, good_type_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,stock_count,license_number) VALUES "
379
 			insertParams := make([]string, 0)
379
 			insertParams := make([]string, 0)
380
 			insertData := make([]interface{}, 0)
380
 			insertData := make([]interface{}, 0)
381
 			for _, info := range warehousingInfo {
381
 			for _, info := range warehousingInfo {
382
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
382
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
383
 				insertData = append(insertData, info.WarehousingId)
383
 				insertData = append(insertData, info.WarehousingId)
384
 				insertData = append(insertData, info.GoodId)
384
 				insertData = append(insertData, info.GoodId)
385
 				insertData = append(insertData, info.GoodTypeId)
385
 				insertData = append(insertData, info.GoodTypeId)
399
 				insertData = append(insertData, info.WarehousingOrder)
399
 				insertData = append(insertData, info.WarehousingOrder)
400
 				insertData = append(insertData, info.Type)
400
 				insertData = append(insertData, info.Type)
401
 				insertData = append(insertData, info.WarehousingCount)
401
 				insertData = append(insertData, info.WarehousingCount)
402
-
402
+				insertData = append(insertData, info.LicenseNumber)
403
 			}
403
 			}
404
 			thisSQL += strings.Join(insertParams, ", ")
404
 			thisSQL += strings.Join(insertParams, ", ")
405
 			err = utx.Exec(thisSQL, insertData...).Error
405
 			err = utx.Exec(thisSQL, insertData...).Error
475
 	return info, err
475
 	return info, err
476
 }
476
 }
477
 
477
 
478
+func FindFirstWarehousingInfoByStockTwo(good_id int64, good_type_id int64) (info models.VmWarehousingInfo, err error) {
479
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
480
+	if good_id > 0 {
481
+		db = db.Where("x.good_id = ?", good_id)
482
+	}
483
+	if good_type_id > 0 {
484
+		db = db.Where("x.good_type_id = ?", good_type_id)
485
+	}
486
+	err = db.Select("sum(x.stock_count) as count").Scan(&info).Error
487
+	return info, err
488
+}
489
+
478
 //药品先进先出,找出最先入库的批次
490
 //药品先进先出,找出最先入库的批次
479
 
491
 
480
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
492
 func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouseInfo, err error) {
502
 
514
 
503
 }
515
 }
504
 
516
 
505
-func FindAllWarehousingList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.Warehousing, total int64, err error) {
517
+func FindAllWarehousingList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*models.Warehousing, total int64, err error) {
506
 	db := readDb.Model(&models.Warehousing{})
518
 	db := readDb.Model(&models.Warehousing{})
507
 	db = db.Where("xt_warehouse.org_id = ? AND xt_warehouse.status = 1 AND xt_warehouse.type = ?", orgId, types)
519
 	db = db.Where("xt_warehouse.org_id = ? AND xt_warehouse.status = 1 AND xt_warehouse.type = ?", orgId, types)
508
 
520
 
509
 	if len(keywords) > 0 {
521
 	if len(keywords) > 0 {
510
 		likeKey := "%" + keywords + "%"
522
 		likeKey := "%" + keywords + "%"
523
+
511
 		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse.creater")
524
 		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse.creater")
512
-		db = db.Joins("join xt_manufacturer on xt_manufacturer.id = xt_warehouse.manufacturer")
513
-		db = db.Where("xt_manufacturer.manufacturer_name LIKE ? OR sgj_user_admin_role.user_name LIKE ? OR xt_warehouse.warehousing_order LIKE ?", likeKey, likeKey, likeKey).Group("xt_warehouse.id")
525
+
526
+		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse.warehousing_order LIKE ? or xt_warehouse.id in(?)", likeKey, likeKey, ids).Group("xt_warehouse.id")
514
 	}
527
 	}
515
 
528
 
516
 	if startTime > 0 {
529
 	if startTime > 0 {
519
 	if endTime > 0 {
532
 	if endTime > 0 {
520
 		db = db.Where("xt_warehouse.operation_time<= ?", endTime)
533
 		db = db.Where("xt_warehouse.operation_time<= ?", endTime)
521
 	}
534
 	}
535
+
522
 	db = db.Count(&total)
536
 	db = db.Count(&total)
523
 	offset := (page - 1) * limit
537
 	offset := (page - 1) * limit
524
 	err = db.Offset(offset).Limit(limit).Order("xt_warehouse.ctime desc").Find(&list).Error
538
 	err = db.Offset(offset).Limit(limit).Order("xt_warehouse.ctime desc").Find(&list).Error
525
 	return
539
 	return
526
 }
540
 }
527
 
541
 
542
+func GetGoodInforByGoodName(keyword string, orgid int64) (goodInfo []*models.GoodInfo, err error) {
543
+
544
+	db := XTReadDB().Model(&goodInfo).Where("status = 1")
545
+	if orgid > 0 {
546
+		db = db.Where("org_id = ?", orgid)
547
+	}
548
+	if len(keyword) > 0 {
549
+		likeKey := "%" + keyword + "%"
550
+		db = db.Where("good_name like ?", likeKey)
551
+	}
552
+	err = db.Find(&goodInfo).Error
553
+	return goodInfo, err
554
+
555
+}
556
+
557
+func GetWarehoureOrderInfoByGoodId(good_id []int64, startime int64, endtime int64, orgid int64) (info []*models.WarehousingInfo, err error) {
558
+
559
+	db := XTReadDB().Model(&info).Where("status =1")
560
+	if len(good_id) > 0 {
561
+		db = db.Where("good_id in (?)", good_id)
562
+	}
563
+	if startime > 0 {
564
+		db = db.Where("ctime >=?", startime)
565
+	}
566
+	if endtime > 0 {
567
+		db = db.Where("ctime<=?", endtime)
568
+	}
569
+	if orgid > 0 {
570
+		db = db.Where("org_id = ?", orgid)
571
+	}
572
+	err = db.Find(&info).Error
573
+	return info, err
574
+}
575
+
576
+func GetWarehoureOrderOutByGoodId(good_id []int64, startime int64, endtime int64, orgid int64) (info []*models.WarehouseOutInfo, err error) {
577
+
578
+	db := XTReadDB().Model(&info).Where("status =1")
579
+	if len(good_id) > 0 {
580
+		db = db.Where("good_id in (?)", good_id)
581
+	}
582
+	if startime > 0 {
583
+		db = db.Where("ctime >=?", startime)
584
+	}
585
+	if endtime > 0 {
586
+		db = db.Where("ctime<=?", endtime)
587
+	}
588
+	if orgid > 0 {
589
+		db = db.Where("org_id = ?", orgid)
590
+	}
591
+	err = db.Find(&info).Error
592
+	return info, err
593
+}
594
+
528
 type VMDrugWarehouse struct {
595
 type VMDrugWarehouse struct {
529
 	ID               int64                `gorm:"column:id" json:"id" form:"id"`
596
 	ID               int64                `gorm:"column:id" json:"id" form:"id"`
530
 	WarehousingOrder string               `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
597
 	WarehousingOrder string               `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
630
 func FindWarehousingInfoById(id int64) (list []*models.WarehousingInfo, err error) {
697
 func FindWarehousingInfoById(id int64) (list []*models.WarehousingInfo, err error) {
631
 	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? AND status = 1", id).Preload("GoodInfo").Find(&list).Error
698
 	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? AND status = 1", id).Preload("GoodInfo").Find(&list).Error
632
 	return list, err
699
 	return list, err
700
+}
633
 
701
 
702
+func FindWarehousingInfoByIdOne(id []int64) (list []*models.WarehousingInfo, err error) {
703
+	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id in(?) AND status = 1", id).Preload("GoodInfo").Find(&list).Error
704
+	return list, err
634
 }
705
 }
635
 
706
 
636
 func FindDrugWarehousingInfoById(id int64, org_id int64) (list []*VMDrugWarehouseInfo, err error) {
707
 func FindDrugWarehousingInfoById(id int64, org_id int64) (list []*VMDrugWarehouseInfo, err error) {
638
 	return list, err
709
 	return list, err
639
 }
710
 }
640
 
711
 
712
+func FindDrugWarehousingInfoByIdOne(id []string, org_id int64) (list []*models.StDrugWarehouseInfo, err error) {
713
+
714
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
715
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
716
+	fmt.Println(table)
717
+	if len(id) > 0 {
718
+		db = db.Where("x.warehousing_id in(?)", id)
719
+	}
720
+	if org_id > 0 {
721
+		db = db.Where("x.org_id = ?", org_id)
722
+	}
723
+	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,t.manufacturer,t.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
724
+	return list, err
725
+}
726
+
641
 func FindWarehousingById(id int64) (warehousing models.Warehousing, err error) {
727
 func FindWarehousingById(id int64) (warehousing models.Warehousing, err error) {
642
 	err = readDb.Model(&models.Warehousing{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
728
 	err = readDb.Model(&models.Warehousing{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
643
 	return warehousing, err
729
 	return warehousing, err
644
 
730
 
645
 }
731
 }
646
 
732
 
733
+func FindWarehousingByIdOne(id []string) (warehousing []*models.Warehousing, err error) {
734
+	err = readDb.Model(&models.Warehousing{}).Where("id in(?) and status = 1", id).Find(&warehousing).Error
735
+	//err = readDb.Model(&models.Warehousing{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
736
+	return warehousing, err
737
+
738
+}
739
+
647
 func FindDrugWarehousingById(id int64, org_id int64) (warehousing VMDrugWarehouse, err error) {
740
 func FindDrugWarehousingById(id int64, org_id int64) (warehousing VMDrugWarehouse, err error) {
648
 	err = readDb.Model(&VMDrugWarehouse{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
741
 	err = readDb.Model(&VMDrugWarehouse{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
649
 	return warehousing, err
742
 	return warehousing, err
650
 
743
 
651
 }
744
 }
652
 
745
 
746
+func FindDrugWarehousingByIdOne(id []string, org_id int64) (warehousing []*models.DrugWarehouse, err error) {
747
+
748
+	db := XTReadDB().Table("xt_drug_warehouse as x").Where("x.status = 1")
749
+	if len(id) > 0 {
750
+		db = db.Where("x.id in(?)", id)
751
+	}
752
+	if org_id > 0 {
753
+		db = db.Where("x.org_id = ?", org_id)
754
+	}
755
+
756
+	err = db.Select("x.id,x.warehousing_order,x.operation_time,x.org_id,x.creater,x.ctime,x.modifier,x.warehousing_time").Find(&warehousing).Error
757
+	return warehousing, err
758
+}
759
+
653
 //func FindDrugWarehousingById(id int64) (warehousing models.DrugWarehouse, err error) {
760
 //func FindDrugWarehousingById(id int64) (warehousing models.DrugWarehouse, err error) {
654
 //	err = readDb.Model(&models.DrugWarehouse{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
761
 //	err = readDb.Model(&models.DrugWarehouse{}).Where("id = ? AND status = 1 ", id).First(&warehousing).Error
655
 //	return warehousing, err
762
 //	return warehousing, err
891
 	if len(warehouseOutInfo) > 0 {
998
 	if len(warehouseOutInfo) > 0 {
892
 		utx := writeDb.Begin()
999
 		utx := writeDb.Begin()
893
 		if len(warehouseOutInfo) > 0 {
1000
 		if len(warehouseOutInfo) > 0 {
894
-			thisSQL := "INSERT INTO xt_warehouse_out_info (warehouse_out_id, good_id, good_type_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer) VALUES "
1001
+			thisSQL := "INSERT INTO xt_warehouse_out_info (warehouse_out_id, good_id, good_type_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,number) VALUES "
895
 			insertParams := make([]string, 0)
1002
 			insertParams := make([]string, 0)
896
 			insertData := make([]interface{}, 0)
1003
 			insertData := make([]interface{}, 0)
897
 			for _, info := range warehouseOutInfo {
1004
 			for _, info := range warehouseOutInfo {
898
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1005
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
899
 				insertData = append(insertData, info.WarehouseOutId)
1006
 				insertData = append(insertData, info.WarehouseOutId)
900
 				insertData = append(insertData, info.GoodId)
1007
 				insertData = append(insertData, info.GoodId)
901
 				insertData = append(insertData, info.GoodTypeId)
1008
 				insertData = append(insertData, info.GoodTypeId)
912
 				insertData = append(insertData, info.Type)
1019
 				insertData = append(insertData, info.Type)
913
 				insertData = append(insertData, info.Dealer)
1020
 				insertData = append(insertData, info.Dealer)
914
 				insertData = append(insertData, info.Manufacturer)
1021
 				insertData = append(insertData, info.Manufacturer)
915
-
1022
+				insertData = append(insertData, info.Number)
916
 			}
1023
 			}
917
 			thisSQL += strings.Join(insertParams, ", ")
1024
 			thisSQL += strings.Join(insertParams, ", ")
918
 			err = utx.Exec(thisSQL, insertData...).Error
1025
 			err = utx.Exec(thisSQL, insertData...).Error
1006
 
1113
 
1007
 }
1114
 }
1008
 
1115
 
1116
+func FindAllWarehouseOutListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*models.WarehouseOut, total int64, err error) {
1117
+	db := readDb.Model(&models.WarehouseOut{})
1118
+	db = db.Where("xt_warehouse_out.org_id = ? AND xt_warehouse_out.status = 1 AND xt_warehouse_out.type = ?", orgId, types)
1119
+
1120
+	if len(keywords) > 0 {
1121
+		likeKey := "%" + keywords + "%"
1122
+		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_warehouse_out.creater")
1123
+		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_warehouse_out.warehouse_out_order_number LIKE ? or xt_warehouse_out.id in(?)", likeKey, likeKey, ids).Group("xt_warehouse_out.id")
1124
+	}
1125
+
1126
+	if startTime > 0 {
1127
+		db = db.Where("xt_warehouse_out.ctime >=?", startTime)
1128
+	}
1129
+	if endTime > 0 {
1130
+		db = db.Where("xt_warehouse_out.ctime<= ?", endTime)
1131
+	}
1132
+	db = db.Count(&total)
1133
+	offset := (page - 1) * limit
1134
+	err = db.Offset(offset).Limit(limit).Order("xt_warehouse_out.ctime desc").Find(&list).Error
1135
+	return list, total, err
1136
+
1137
+}
1138
+
1009
 func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugWarehouseOut, total int64, err error) {
1139
 func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugWarehouseOut, total int64, err error) {
1010
 	db := readDb.Model(&models.DrugWarehouseOut{})
1140
 	db := readDb.Model(&models.DrugWarehouseOut{})
1011
 	db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
1141
 	db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
1644
 }
1774
 }
1645
 
1775
 
1646
 func UpDateWarehouseInfoByStock(info *models.WarehousingInfo) (err error) {
1776
 func UpDateWarehouseInfoByStock(info *models.WarehousingInfo) (err error) {
1647
-	err = writeDb.Save(&info).Error
1777
+	ut := writeDb.Begin()
1778
+	err = ut.Save(&info).Error
1779
+	if err != nil {
1780
+		ut.Rollback()
1781
+		return err
1782
+	}
1783
+	ut.Commit()
1648
 	return err
1784
 	return err
1649
 }
1785
 }
1650
 
1786
 
2150
 }
2286
 }
2151
 
2287
 
2152
 func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
2288
 func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
2153
-	err := writeDb.Create(&detail).Error
2289
+	ut := writeDb.Begin()
2290
+	err := ut.Create(&detail).Error
2291
+	if err != nil {
2292
+		ut.Rollback()
2293
+		return err
2294
+	}
2295
+	ut.Commit()
2154
 	return err
2296
 	return err
2155
-
2156
 }
2297
 }
2157
 
2298
 
2158
 func AddSigleDrugAutoReduceRecordInfo(detail *models.DrugAutomaticReduceDetail) error {
2299
 func AddSigleDrugAutoReduceRecordInfo(detail *models.DrugAutomaticReduceDetail) error {
2677
 	db := XTReadDB().Model(&good).Where("org_id =? and status = 1", orgid)
2818
 	db := XTReadDB().Model(&good).Where("org_id =? and status = 1", orgid)
2678
 	if len(keywords) > 0 {
2819
 	if len(keywords) > 0 {
2679
 		likekey := "%" + keywords + "%"
2820
 		likekey := "%" + keywords + "%"
2680
-		err = db.Where("(good_name Like ?)", likekey).Find(&good).Error
2821
+		err = db.Where("(good_name Like ?)", likekey).Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
2822
+			return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0", orgid)
2823
+		}).Find(&good).Error
2681
 	} else {
2824
 	} else {
2682
 		err = db.Find(&good).Error
2825
 		err = db.Find(&good).Error
2683
 	}
2826
 	}
2685
 }
2828
 }
2686
 
2829
 
2687
 func CreateAutoReduceRecord(detail *models.BloodAutomaticReduceDetail) error {
2830
 func CreateAutoReduceRecord(detail *models.BloodAutomaticReduceDetail) error {
2688
-
2689
-	err := writeDb.Create(&detail).Error
2831
+	db := writeDb.Begin()
2832
+	err := db.Create(&detail).Error
2833
+	if err != nil {
2834
+		db.Rollback()
2835
+		return err
2836
+	}
2837
+	db.Commit()
2690
 	return err
2838
 	return err
2691
 }
2839
 }
2692
 
2840
 
2694
 
2842
 
2695
 	var autoreduece models.BloodAutomaticReduceDetail
2843
 	var autoreduece models.BloodAutomaticReduceDetail
2696
 	var err error
2844
 	var err error
2697
-	err = XTReadDB().Model(&autoreduece).Where("org_id = ? and patient_id = ?  and status = 1 and record_time = ? and good_id = ? and good_type_id = ?", orgid, patient_id, recordtime, goodid, goodtypeid).Find(&autoreduece).Error
2845
+	err = XTReadDB().Model(&autoreduece).Where("org_id = ? and patient_id = ?  and status = 1 and record_time = ? and good_id = ? and good_type_id = ? and count<> 0", orgid, patient_id, recordtime, goodid, goodtypeid).Find(&autoreduece).Error
2698
 	if err == gorm.ErrRecordNotFound {
2846
 	if err == gorm.ErrRecordNotFound {
2699
 		return nil, err
2847
 		return nil, err
2700
 	}
2848
 	}
2759
 	if good_type > 0 {
2907
 	if good_type > 0 {
2760
 		db = db.Where("t.good_type_id = ?", good_type)
2908
 		db = db.Where("t.good_type_id = ?", good_type)
2761
 	}
2909
 	}
2762
-	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.manufacturer").Joins("left join xt_good_information as t on t.id = x.good_id").Offset(offset).Count(&total).Group("x.good_id").Scan(&info).Error
2910
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.manufacturer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&info).Error
2763
 	return info, total, err
2911
 	return info, total, err
2764
 }
2912
 }
2765
 
2913
 
2782
 	if good_id > 0 {
2930
 	if good_id > 0 {
2783
 		db = db.Where("x.good_id = ?", good_id)
2931
 		db = db.Where("x.good_id = ?", good_id)
2784
 	}
2932
 	}
2785
-	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit").Joins("left join xt_good_information as t on t.id = x.good_id").Offset(offset).Count(&total).Scan(&info).Error
2933
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit").Joins("left join xt_good_information as t on t.id = x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&info).Error
2786
 	return info, total, err
2934
 	return info, total, err
2787
 
2935
 
2788
 }
2936
 }
2789
 
2937
 
2790
-func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64) (info []*models.WarehouseOutInfo, total int64, err error) {
2938
+func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, startime int64, endtime int64, is_sys int64) (info []*models.WarehouseOutInfo, total int64, err error) {
2791
 	offset := (page - 1) * limit
2939
 	offset := (page - 1) * limit
2792
 
2940
 
2793
 	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status= 1")
2941
 	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status= 1")
2804
 	if good_id > 0 {
2952
 	if good_id > 0 {
2805
 		db = db.Where("x.good_id = ?", good_id)
2953
 		db = db.Where("x.good_id = ?", good_id)
2806
 	}
2954
 	}
2807
-	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id").Offset(offset).Count(&total).Scan(&info).Error
2955
+	if is_sys == 2 {
2956
+		db = db.Where("x.is_sys = 1")
2957
+	}
2958
+	if is_sys == 3 {
2959
+		db = db.Where("x.is_sys = 0")
2960
+	}
2961
+	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.is_sys").Offset(offset).Count(&total).Scan(&info).Error
2808
 	return info, total, err
2962
 	return info, total, err
2809
 }
2963
 }
2964
+
2965
+func GetStockDrugCount(startime int64, endtime int64, orgid int64) (info []*models.VmWarehouseInfo, err error) {
2966
+
2967
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
2968
+	if startime > 0 {
2969
+		db = db.Where("x.ctime >=?", startime)
2970
+	}
2971
+	if endtime > 0 {
2972
+		db = db.Where("x.ctime<=?", endtime)
2973
+	}
2974
+	if orgid > 0 {
2975
+		db = db.Where("x.org_id = ?", orgid)
2976
+	}
2977
+
2978
+	err = db.Select("sum(x.warehousing_count) as count,x.good_id").Group("x.good_id").Scan(&info).Error
2979
+	return info, err
2980
+}
2981
+
2982
+func GetAutoDiallysisBefor(startime int64, endtime int64, orgid int64) (info []*models.VmWarehouseInfo, err error) {
2983
+	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
2984
+	if startime > 0 {
2985
+		db = db.Where("x.ctime >=?", startime)
2986
+	}
2987
+	if endtime > 0 {
2988
+		db = db.Where("x.ctime<=?", endtime)
2989
+	}
2990
+	if orgid > 0 {
2991
+		db = db.Where("x.org_id = ?", orgid)
2992
+	}
2993
+
2994
+	err = db.Select("sum(x.count) as count,x.good_id").Where("is_sys = 0").Group("x.good_id").Scan(&info).Error
2995
+	return info, err
2996
+}
2997
+
2998
+func GetOutStockTotalCountFour(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
2999
+
3000
+	if startime > 0 {
3001
+		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >=?  and `status` = 1)  as b GROUP BY good_id", orgid, startime).Scan(&autoMatic).Error
3002
+	} else {
3003
+		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3004
+	}
3005
+
3006
+	if endtime > 0 {
3007
+		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time <=?  and `status` = 1)  as b GROUP BY good_id", orgid, endtime).Scan(&autoMatic).Error
3008
+	} else {
3009
+		err = XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and `status` = 1)  as b GROUP BY good_id", orgid).Scan(&autoMatic).Error
3010
+	}
3011
+
3012
+	return autoMatic, err
3013
+
3014
+}
3015
+
3016
+func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutInfoOne, err error) {
3017
+
3018
+	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
3019
+	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
3020
+	fmt.Println(table)
3021
+	if id > 0 {
3022
+		db = db.Where("x.warehouse_out_id = ?", id)
3023
+	}
3024
+	if orgid > 0 {
3025
+		db = db.Where("x.org_id = ?", orgid)
3026
+	}
3027
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3028
+	return out, err
3029
+}
3030
+
3031
+func GetWarehouseOutOrder(id []string, orgid int64) (out []*models.WarehouseOut, err error) {
3032
+
3033
+	db := XTReadDB().Table("xt_warehouse_out as x").Where("x.status = 1")
3034
+	if len(id) > 0 {
3035
+		db = db.Where("x.id in(?)", id)
3036
+	}
3037
+	if orgid > 0 {
3038
+		db = db.Where("x.org_id= ?", orgid)
3039
+	}
3040
+	err = db.Select("x.id,x.warehouse_out_order_number,x.operation_time,x.creater,x.org_id,x.modifier,x.remark,x.warehouse_out_time,x.dealer,x.manufacturer,x.type").Find(&out).Error
3041
+	return out, err
3042
+}
3043
+
3044
+func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.WarehouseOutInfoOne, err error) {
3045
+
3046
+	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
3047
+	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
3048
+	fmt.Println(table)
3049
+	if len(id) > 0 {
3050
+		db = db.Where("x.warehouse_out_id in (?)", id)
3051
+	}
3052
+	if orgid > 0 {
3053
+		db = db.Where("x.org_id = ?", orgid)
3054
+	}
3055
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3056
+	return out, err
3057
+}
3058
+
3059
+func FindUserDetailByIdOne(good_id int64, record_time int64, org_id int64) (user []*models.AutomaticReduceDetail, err error, total int64) {
3060
+	db := readDb.Model(&models.AutomaticReduceDetail{})
3061
+	db = db.Preload("GoodInfo", "org_id = ? AND status = 1", org_id)
3062
+	db = db.Preload("GoodsType", "status = 1")
3063
+	db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
3064
+	db = db.Where("status = 1 AND org_id = ? AND good_id = ? AND record_time = ? ", org_id, good_id, record_time)
3065
+	db = db.Count(&total)
3066
+	err = db.Find(&user).Error
3067
+	return
3068
+}
3069
+
3070
+func GetGoodInformationByGoodId(good_id int64) (models.GoodInfo, error) {
3071
+
3072
+	info := models.GoodInfo{}
3073
+	err := XTReadDB().Where("id = ? and status = 1", good_id).Find(&info).Error
3074
+	return info, err
3075
+}
3076
+
3077
+func GetExprotStockList(orgid int64, orderid []string, startime int64, endtime int64) (info []*models.StWarehousingInfo, err error) {
3078
+
3079
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
3080
+
3081
+	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
3082
+	fmt.Println(table)
3083
+
3084
+	if orgid > 0 {
3085
+		db = db.Where("x.org_id = ?", orgid)
3086
+	}
3087
+	if len(orderid) > 0 {
3088
+		db = db.Where("x.warehousing_id in(?)", orderid)
3089
+	}
3090
+	if startime > 0 {
3091
+		db = db.Where("x.ctime>=?", startime)
3092
+	}
3093
+	if endtime > 0 {
3094
+		db = db.Where("x.ctime<=?", endtime)
3095
+	}
3096
+	err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,Sum(x.warehousing_count)as total_count,x.price,x.dealer,x.manufacturer,x.remark,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&info).Error
3097
+
3098
+	return info, err
3099
+}
3100
+
3101
+func GetDrugWarehouOrderInfo(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
3102
+
3103
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
3104
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
3105
+	fmt.Println(table)
3106
+	if startime > 0 {
3107
+		db = db.Where("x.ctime>=?", startime)
3108
+	}
3109
+	if endtime > 0 {
3110
+		db = db.Where("x.ctime<=?", endtime)
3111
+	}
3112
+	if orgid > 0 {
3113
+		db = db.Where("x.org_id = ?", orgid)
3114
+	}
3115
+
3116
+	err = db.Select("x.drug_id,x.count,x.count_unit,t.max_unit,t.min_unit,t.min_number").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&info).Error
3117
+	return info, err
3118
+}
3119
+
3120
+func GetOutExprotList(orgid int64, ids []string, startime int64, endtime int64) (out []*models.WarehouseOutInfoOne, err error) {
3121
+
3122
+	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status =1 ")
3123
+	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
3124
+	fmt.Println(table)
3125
+	if orgid > 0 {
3126
+		db = db.Where("x.org_id = ?", orgid)
3127
+	}
3128
+
3129
+	if len(ids) > 0 {
3130
+		db = db.Where("x.warehouse_out_id in (?)", ids)
3131
+	}
3132
+	if startime > 0 {
3133
+		db = db.Where("x.ctime>=?", startime)
3134
+	}
3135
+	if endtime > 0 {
3136
+		db = db.Where("x.ctime<=?", endtime)
3137
+	}
3138
+
3139
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.warehousing_out_target,Sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.number,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&out).Error
3140
+	return out, err
3141
+
3142
+}
3143
+
3144
+func FindeDrugWarehouseOutOrder(ids []string, orgid int64) (info []*models.DrugWarehouseOut, err error) {
3145
+
3146
+	db := XTReadDB().Table("xt_drug_warehouse_out as x").Where("x.status = 1")
3147
+	if len(ids) > 0 {
3148
+		db = db.Where("x.id in(?)", ids)
3149
+	}
3150
+	if orgid > 0 {
3151
+		db = db.Where("x.org_id = ?", orgid)
3152
+	}
3153
+
3154
+	err = db.Select("x.id,x.warehouse_out_order_number,x.operation_time,x.creater,x.org_id,x.modifier,x.remark,x.warehouse_out_time,x.is_sys").Scan(&info).Error
3155
+	return info, err
3156
+
3157
+}
3158
+
3159
+func FindeDrugWarehouseOutDetail(ids []string, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
3160
+
3161
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status =1 ")
3162
+	table := XTReadDB().Table("x.base_drug as t").Where("t.status = 1")
3163
+	fmt.Println(table)
3164
+	if len(ids) > 0 {
3165
+		db = db.Where("x.warehouse_out_id in(?)", ids)
3166
+	}
3167
+	if orgid > 0 {
3168
+		db = db.Where("x.org_id = ?", orgid)
3169
+	}
3170
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.product_date,x.expiry_date,x.number,x.batch_number,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.drug_name").Joins("left join xt_base_drug as t on t.id =x.drug_id").Scan(&info).Error
3171
+	return info, err
3172
+}

+ 227 - 276
service/warhouse_service.go Parādīt failu

16
 
16
 
17
 // 药品出库
17
 // 药品出库
18
 
18
 
19
-func DrugsDelivery(orgID int64, advice *models.DoctorAdvice) (err error) {
19
+func DrugsDelivery(orgID int64, creater int64, advice *models.DoctorAdvice) (err error) {
20
 	// 1.判断药品是否来自专用字典的药品库
20
 	// 1.判断药品是否来自专用字典的药品库
21
 	// 2.判断当天当前机构有没有创建出库单,没有则创建
21
 	// 2.判断当天当前机构有没有创建出库单,没有则创建
22
 	// 3.创建出库流程
22
 	// 3.创建出库流程
45
 				WarehouseOutOrderNumber: warehousing_out_order,
45
 				WarehouseOutOrderNumber: warehousing_out_order,
46
 				OperationTime:           time.Now().Unix(),
46
 				OperationTime:           time.Now().Unix(),
47
 				OrgId:                   orgID,
47
 				OrgId:                   orgID,
48
-				Creater:                 0,
48
+				Creater:                 creater,
49
 				Ctime:                   time.Now().Unix(),
49
 				Ctime:                   time.Now().Unix(),
50
 				Status:                  1,
50
 				Status:                  1,
51
 				WarehouseOutTime:        record_time,
51
 				WarehouseOutTime:        record_time,
258
 
258
 
259
 // 药品出库
259
 // 药品出库
260
 
260
 
261
-func HisDrugsDelivery(orgID int64, advice *models.HisDoctorAdviceInfo) (err error) {
261
+func HisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo) (err error) {
262
 	// 1.判断药品是否来自专用字典的药品库
262
 	// 1.判断药品是否来自专用字典的药品库
263
 	// 2.判断当天当前机构有没有创建出库单,没有则创建
263
 	// 2.判断当天当前机构有没有创建出库单,没有则创建
264
 	// 3.创建出库流程
264
 	// 3.创建出库流程
284
 				WarehouseOutOrderNumber: warehousing_out_order,
284
 				WarehouseOutOrderNumber: warehousing_out_order,
285
 				OperationTime:           time.Now().Unix(),
285
 				OperationTime:           time.Now().Unix(),
286
 				OrgId:                   orgID,
286
 				OrgId:                   orgID,
287
-				Creater:                 0,
287
+				Creater:                 creater,
288
 				Ctime:                   time.Now().Unix(),
288
 				Ctime:                   time.Now().Unix(),
289
 				Status:                  1,
289
 				Status:                  1,
290
 				WarehouseOutTime:        record_time,
290
 				WarehouseOutTime:        record_time,
350
 	// 将该批次的剩余库存数量转换为拆零数量
350
 	// 将该批次的剩余库存数量转换为拆零数量
351
 
351
 
352
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
352
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
353
-
353
+	fmt.Println("拆零数量2222222222222222222", stock_number)
354
+	fmt.Println("出库数量55555555555555555555", deliver_number)
354
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
355
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
355
 	if stock_number >= deliver_number {
356
 	if stock_number >= deliver_number {
356
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
357
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
369
 		}
370
 		}
370
 
371
 
371
 		warehouseOutInfo.Count = deliver_number
372
 		warehouseOutInfo.Count = deliver_number
372
-		warehouseOutInfo.CountUnit = drup.MinUnit
373
+		warehouseOutInfo.CountUnit = advice.PrescribingNumberUnit
373
 
374
 
374
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
375
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
375
 
376
 
388
 				OrgId:                   orgID,
389
 				OrgId:                   orgID,
389
 				DrugId:                  advice.DrugId,
390
 				DrugId:                  advice.DrugId,
390
 				Count:                   deliver_number,
391
 				Count:                   deliver_number,
391
-				CountUnit:               drup.MinUnit,
392
+				CountUnit:               advice.PrescribingNumberUnit,
392
 			}
393
 			}
393
 			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
394
 			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
394
 			if errTwo != nil {
395
 			if errTwo != nil {
633
 
634
 
634
 	//查询该患者当天已经出库的耗材信息
635
 	//查询该患者当天已经出库的耗材信息
635
 	goods_yc, _ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
636
 	goods_yc, _ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
636
-	for _, item := range goods_yc {
637
-		fmt.Println("item0000000000000", item.Count)
638
-	}
639
-	for _, item := range goods {
640
-		fmt.Println("item1111111111111", item.Count)
641
-	}
642
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
637
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
643
 	for i := len(goods_yc) - 1; i >= 0; i-- {
638
 	for i := len(goods_yc) - 1; i >= 0; i-- {
644
 		goods_yc_temp := goods_yc[i]
639
 		goods_yc_temp := goods_yc[i]
652
 					goods = append(goods[:j], goods[j+1:]...)
647
 					goods = append(goods[:j], goods[j+1:]...)
653
 					break
648
 					break
654
 				}
649
 				}
655
-				fmt.Println("998888888888888", goods_yc_temp.Count)
656
-				fmt.Println("7777777777777777", goods_temp.Count)
657
 				// 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
650
 				// 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
658
 				if goods_yc_temp.Count > goods_temp.Count {
651
 				if goods_yc_temp.Count > goods_temp.Count {
659
-					fmt.Println("进来了是吗")
652
+
660
 					temp_count := goods_yc_temp.Count - goods_temp.Count
653
 					temp_count := goods_yc_temp.Count - goods_temp.Count
661
 					goods_yc[i].Count = temp_count
654
 					goods_yc[i].Count = temp_count
662
 					goods = append(goods[:j], goods[j+1:]...)
655
 					goods = append(goods[:j], goods[j+1:]...)
663
 					break
656
 					break
664
 				}
657
 				}
665
-				fmt.Println("555555555555", goods_yc_temp.Count)
666
-				fmt.Println("444444444444", goods_temp.Count)
667
 				// 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
658
 				// 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
668
 				if goods_yc_temp.Count < goods_temp.Count {
659
 				if goods_yc_temp.Count < goods_temp.Count {
669
 					temp_count := goods_temp.Count - goods_yc_temp.Count
660
 					temp_count := goods_temp.Count - goods_yc_temp.Count
670
-					fmt.Println("988888888888888", temp_count)
661
+					//fmt.Println("988888888888888", temp_count)
671
 					goods[j].Count = temp_count
662
 					goods[j].Count = temp_count
672
 					goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
663
 					goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
673
-					fmt.Println("888888888", goods_yc)
664
+					//fmt.Println("888888888", goods_yc)
674
 					break
665
 					break
675
 				}
666
 				}
676
 			}
667
 			}
678
 	}
669
 	}
679
 
670
 
680
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
671
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
681
-	// goods 这个数据就是需要出库的耗材的数据
672
+	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
682
 	fmt.Println("goods222222222222", goods)
673
 	fmt.Println("goods222222222222", goods)
683
 	fmt.Println("goodsy999999999999", goods_yc)
674
 	fmt.Println("goodsy999999999999", goods_yc)
684
 	if len(goods) > 0 {
675
 	if len(goods) > 0 {
718
 		for _, item := range goods {
709
 		for _, item := range goods {
719
 			var newCount int64 = 0
710
 			var newCount int64 = 0
720
 			for _, it := range goodOne {
711
 			for _, it := range goodOne {
721
-				if item.GoodTypeId == it.GoodTypeId && it.GoodId == it.GoodId {
712
+				if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
722
 					newCount = it.Count
713
 					newCount = it.Count
723
 				}
714
 				}
724
 			}
715
 			}
731
 			ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
722
 			ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
732
 		}
723
 		}
733
 
724
 
734
-		// for _, item := range goodOne {
735
-		// 	prepare := models.DialysisBeforePrepare{
736
-		// 		GoodTypeId: item.GoodTypeId,
737
-		// 		GoodId:     item.GoodId,
738
-		// 		Count:      item.Count,
739
-		// 		NewCount:   item.NewCount,
740
-		// 	}
741
-		// 	fmt.Println("数量99999999999999999", item.Count)
742
-		// 	ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, item.Count)
743
-		// }
744
 	}
725
 	}
745
 
726
 
746
 	if len(goods_yc) > 0 {
727
 	if len(goods_yc) > 0 {
797
 		warehouseOutInfo.Count = count
778
 		warehouseOutInfo.Count = count
798
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
779
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
799
 		warehouseOutInfo.Price = stockInInfo.Price
780
 		warehouseOutInfo.Price = stockInInfo.Price
800
-
801
-		//判断当前耗材是否有出库详情记录
802
-		_, errcode := GetStockInRecoredByGoodId(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID)
803
-		if errcode == gorm.ErrRecordNotFound {
804
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
805
-			if errOne != nil {
806
-				return errOne
807
-			} else {
808
-
809
-				details := models.BloodAutomaticReduceDetail{
810
-					WarehouseOutId:          warehouseOutInfo.ID,
811
-					WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
812
-					PatientId:               patient_id,
813
-					Ctime:                   time.Now().Unix(),
814
-					Mtime:                   time.Now().Unix(),
815
-					Status:                  1,
816
-					RecordTime:              record_time,
817
-					OrgId:                   orgID,
818
-					GoodId:                  goods.GoodId,
819
-					GoodTypeId:              goods.GoodTypeId,
820
-					Count:                   count,
821
-				}
822
-				//查询当天耗材是否已经存在数据
823
-				_, errcode := GetAutoMaticReduceDetail(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
824
-				if errcode == gorm.ErrRecordNotFound {
825
-					errTwo := CreateAutoReduceRecord(&details)
826
-					if errTwo != nil {
827
-						return errTwo
828
-					}
829
-				} else if errcode == nil {
830
-					DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
831
-					CreateAutoReduceRecord(&details)
832
-				}
833
-			}
834
-		} else if errcode == nil {
835
-			warehouseOutInfo := &models.WarehouseOutInfo{
836
-				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
837
-				WarehouseOutId:          warehouseOut.ID,
838
-				WarehouseInfotId:        warehouse.ID,
839
-				Status:                  1,
840
-				Ctime:                   time.Now().Unix(),
841
-				Remark:                  "",
842
-				OrgId:                   orgID,
843
-				Type:                    1,
844
-				Manufacturer:            0,
845
-				Dealer:                  0,
846
-				IsSys:                   1,
847
-				SysRecordTime:           record_time,
848
-				GoodTypeId:              goods.GoodTypeId,
849
-				GoodId:                  goods.GoodId,
850
-				PatientId:               patient_id,
851
-			}
852
-			warehouseOutInfo.Count = count
853
-			//更新入库详情表
854
-			UpdateAutoMaticReduceDetail(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID, warehouseOutInfo)
781
+		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
782
+		if errOne != nil {
783
+			return errOne
784
+		} else {
855
 			details := models.BloodAutomaticReduceDetail{
785
 			details := models.BloodAutomaticReduceDetail{
856
 				WarehouseOutId:          warehouseOutInfo.ID,
786
 				WarehouseOutId:          warehouseOutInfo.ID,
857
 				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
787
 				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
867
 			}
797
 			}
868
 			//查询当天耗材是否已经存在数据
798
 			//查询当天耗材是否已经存在数据
869
 			_, errcode := GetAutoMaticReduceDetail(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
799
 			_, errcode := GetAutoMaticReduceDetail(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
800
+
870
 			if errcode == gorm.ErrRecordNotFound {
801
 			if errcode == gorm.ErrRecordNotFound {
871
 				errTwo := CreateAutoReduceRecord(&details)
802
 				errTwo := CreateAutoReduceRecord(&details)
872
 				if errTwo != nil {
803
 				if errTwo != nil {
874
 				}
805
 				}
875
 			} else if errcode == nil {
806
 			} else if errcode == nil {
876
 				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
807
 				DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
877
-
878
 				CreateAutoReduceRecord(&details)
808
 				CreateAutoReduceRecord(&details)
879
 			}
809
 			}
880
 		}
810
 		}
881
-		fmt.Println("newcount9999999999999999999999999999999", goods.NewCount)
882
-		
811
+
883
 		maxNumber = goods.Count
812
 		maxNumber = goods.Count
884
-		
885
 
813
 
886
 		if warehouse.StockCount < maxNumber {
814
 		if warehouse.StockCount < maxNumber {
887
 			return errors.New("库存数量不足")
815
 			return errors.New("库存数量不足")
888
 		}
816
 		}
889
 
817
 
890
 		warehouse.StockCount = warehouse.StockCount - maxNumber
818
 		warehouse.StockCount = warehouse.StockCount - maxNumber
891
-		fmt.Println("999999999999999", warehouse.StockCount)
892
 
819
 
893
 		warehouse.Mtime = time.Now().Unix()
820
 		warehouse.Mtime = time.Now().Unix()
894
 
821
 
902
 
829
 
903
 		return nil
830
 		return nil
904
 	} else {
831
 	} else {
905
-		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
906
-		// warehouseOutInfo := &models.WarehouseOutInfo{
907
-		// 	WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
908
-		// 	WarehouseOutId:          warehouseOut.ID,
909
-		// 	WarehouseInfotId:        warehouse.ID,
910
-		// 	Status:                  1,
911
-		// 	Ctime:                   time.Now().Unix(),
912
-		// 	Remark:                  "",
913
-		// 	OrgId:                   orgID,
914
-		// 	Type:                    1,
915
-		// 	Manufacturer:            0,
916
-		// 	Dealer:                  0,
917
-		// 	IsSys:                   1,
918
-		// 	SysRecordTime:           record_time,
919
-		// 	GoodTypeId:              goods.GoodTypeId,
920
-		// 	GoodId:                  goods.GoodId,
921
-		// 	PatientId:               patient_id,
922
-		// }
923
-		// warehouseOutInfo.Count = stock_number
924
-		// stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
925
-		// warehouseOutInfo.Price = stockInInfo.Price
926
-
927
-		// cur_warehouse, errcode := GetStockInRecoredByGoodId(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID)
928
-		// if errcode == gorm.ErrRecordNotFound {
929
-		// 	errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
930
-
931
-		// 	if errOne != nil {
932
-		// 		return errOne
933
-		// 	} else {
934
-		// 		details := &models.AutomaticReduceDetail{
935
-		// 			WarehouseOutId:          warehouseOutInfo.ID,
936
-		// 			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
937
-		// 			PatientId:               patient_id,
938
-		// 			Ctime:                   time.Now().Unix(),
939
-		// 			Mtime:                   time.Now().Unix(),
940
-		// 			Status:                  1,
941
-		// 			RecordTime:              record_time,
942
-		// 			OrgId:                   orgID,
943
-		// 			GoodId:                  goods.GoodId,
944
-		// 			GoodTypeId:              goods.GoodTypeId,
945
-		// 			Count:                   goods.Count,
946
-		// 		}
947
-		// 		errTwo := service.AddSigleAutoReduceRecordInfo(details)
948
-		// 		if errTwo != nil {
949
-		// 			return errTwo
950
-		// 		}
951
-		// 	}
952
-		// 	// 出库完成后,要将该批次库存清零
953
-		// 	warehouse.StockCount = 0
954
-		// 	warehouse.Mtime = time.Now().Unix()
955
-		// 	errThree := UpDateWarehouseInfoByStock(&warehouse)
956
-		// 	if errThree != nil {
957
-		// 		return errThree
958
-		// 	}
959
-		// 	// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
960
-		// 	goods.Count = deliver_number - stock_number
961
-
962
-		// 	ConsumablesDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
963
-		// } else if errcode == nil {
964
-
965
-		// 	warehouseOutInfo := &models.WarehouseOutInfo{
966
-		// 		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
967
-		// 		WarehouseOutId:          warehouseOut.ID,
968
-		// 		WarehouseInfotId:        warehouse.ID,
969
-		// 		Status:                  1,
970
-		// 		Ctime:                   time.Now().Unix(),
971
-		// 		Remark:                  "",
972
-		// 		OrgId:                   orgID,
973
-		// 		Type:                    1,
974
-		// 		Manufacturer:            0,
975
-		// 		Dealer:                  0,
976
-		// 		IsSys:                   1,
977
-		// 		SysRecordTime:           record_time,
978
-		// 		GoodTypeId:              goods.GoodTypeId,
979
-		// 		GoodId:                  goods.GoodId,
980
-		// 		PatientId:               patient_id,
981
-		// 	}
982
-		// 	warehouseOutInfo.Count = cur_warehouse.Count + StockCount
983
-		// 	//更新入库详情表
984
-		// 	UpdateAutoMaticReduceDetail(goods.GoodId, goods.GoodTypeId, record_time, patient_id, orgID, warehouseOutInfo)
985
-		// 	details := models.BloodAutomaticReduceDetail{
986
-		// 		WarehouseOutId:          warehouseOutInfo.ID,
987
-		// 		WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
988
-		// 		PatientId:               patient_id,
989
-		// 		Ctime:                   time.Now().Unix(),
990
-		// 		Mtime:                   time.Now().Unix(),
991
-		// 		Status:                  1,
992
-		// 		RecordTime:              record_time,
993
-		// 		OrgId:                   orgID,
994
-		// 		GoodId:                  goods.GoodId,
995
-		// 		GoodTypeId:              goods.GoodTypeId,
996
-		// 		Count:                   count,
997
-		// 	}
998
-		// 	//查询当天耗材是否已经存在数据
999
-		// 	_, errcode := GetAutoMaticReduceDetail(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1000
-		// 	if errcode == gorm.ErrRecordNotFound {
1001
-		// 		errTwo := CreateAutoReduceRecord(&details)
1002
-		// 		if errTwo != nil {
1003
-		// 			return errTwo
1004
-		// 		}
1005
-		// 	} else if errcode == nil {
1006
-		// 		DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
1007
-
1008
-		// 		CreateAutoReduceRecord(&details)
1009
-		// 	}
1010
-		// }
1011
 		// 出库完成后,要将该批次库存清零
832
 		// 出库完成后,要将该批次库存清零
1012
 		warehouse.StockCount = 0
833
 		warehouse.StockCount = 0
1013
 		warehouse.Mtime = time.Now().Unix()
834
 		warehouse.Mtime = time.Now().Unix()
1019
 		goods.Count = deliver_number - stock_number
840
 		goods.Count = deliver_number - stock_number
1020
 
841
 
1021
 		ConsumablesDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
842
 		ConsumablesDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
1022
-		
843
+
1023
 	}
844
 	}
1024
 	return nil
845
 	return nil
1025
 }
846
 }
1117
 
938
 
1118
 func GetAutoReduceRecordInfoByPatientId(orgid int64, patient_id int64, recordTime int64) (autoReduce []*models.AutomaticReduceDetail, err error) {
939
 func GetAutoReduceRecordInfoByPatientId(orgid int64, patient_id int64, recordTime int64) (autoReduce []*models.AutomaticReduceDetail, err error) {
1119
 
940
 
1120
-	err = XTReadDB().Model(&autoReduce).Where("org_id = ? and patient_id = ? and record_time = ? and status = 1 and count<>0", orgid, patient_id, recordTime).Find(&autoReduce).Error
941
+	err = XTReadDB().Model(&autoReduce).Where("org_id = ? and patient_id = ? and record_time = ? and status = 1", orgid, patient_id, recordTime).Find(&autoReduce).Error
1121
 	return autoReduce, err
942
 	return autoReduce, err
1122
 }
943
 }
1123
 
944
 
1127
 	return err
948
 	return err
1128
 }
949
 }
1129
 
950
 
951
+func DeleteDialysisBeforThree(orgid int64, patient_id int64, record_date int64) error {
952
+	prepare := models.DialysisBeforePrepare{}
953
+	err := XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patient_id, record_date).Updates(map[string]interface{}{"status": 0, "count": 0, "mtime": time.Now().Unix()}).Error
954
+	return err
955
+}
956
+
1130
 func ConsumablesDeliveryTotalOne(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods) (err error) {
957
 func ConsumablesDeliveryTotalOne(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods) (err error) {
1131
 
958
 
1132
 	//查询该患者当天已经出库的耗材信息
959
 	//查询该患者当天已经出库的耗材信息
1259
 	// 根据先进先出原则,查询最先入库的批次,进行出库
1086
 	// 根据先进先出原则,查询最先入库的批次,进行出库
1260
 	// 如果没有对应的库存,则报错
1087
 	// 如果没有对应的库存,则报错
1261
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
1088
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
1262
-
1089
+	fmt.Println("err222222222222222222222", warehouse.StockCount)
1263
 	if err != nil {
1090
 	if err != nil {
1091
+		fmt.Println("232323232323进来")
1264
 		return err
1092
 		return err
1265
 	}
1093
 	}
1266
 
1094
 
1267
 	// 将该批次的剩余库存数量转换为拆零数量
1095
 	// 将该批次的剩余库存数量转换为拆零数量
1268
 	stock_number = warehouse.StockCount
1096
 	stock_number = warehouse.StockCount
1269
-
1097
+	fmt.Println("3434343434343434", stock_number)
1098
+	fmt.Println("8888888888888888888", deliver_number)
1270
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1099
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1271
 	if stock_number >= deliver_number {
1100
 	if stock_number >= deliver_number {
1272
 		warehouseOutInfo := &models.WarehouseOutInfo{
1101
 		warehouseOutInfo := &models.WarehouseOutInfo{
1275
 			WarehouseInfotId:        warehouse.ID,
1104
 			WarehouseInfotId:        warehouse.ID,
1276
 			Status:                  1,
1105
 			Status:                  1,
1277
 			Ctime:                   time.Now().Unix(),
1106
 			Ctime:                   time.Now().Unix(),
1278
-			Remark:                  "",
1107
+			Remark:                  goods.Remark,
1279
 			OrgId:                   orgID,
1108
 			OrgId:                   orgID,
1280
 			Type:                    1,
1109
 			Type:                    1,
1281
-			Manufacturer:            0,
1282
-			Dealer:                  0,
1283
-			IsSys:                   2,
1110
+			Manufacturer:            goods.Manufacturer,
1111
+			Dealer:                  goods.Dealer,
1112
+			IsSys:                   0,
1284
 			SysRecordTime:           record_time,
1113
 			SysRecordTime:           record_time,
1285
 			GoodTypeId:              goods.GoodTypeId,
1114
 			GoodTypeId:              goods.GoodTypeId,
1286
 			GoodId:                  goods.GoodId,
1115
 			GoodId:                  goods.GoodId,
1116
+			ExpiryDate:              goods.ExpiryDate,
1117
+			ProductDate:             goods.ProductDate,
1118
+			Number:                  goods.Number,
1119
+			Price:                   goods.Price,
1287
 		}
1120
 		}
1288
 		warehouseOutInfo.Count = goods.Count
1121
 		warehouseOutInfo.Count = goods.Count
1289
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1122
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1290
 		warehouseOutInfo.Price = stockInInfo.Price
1123
 		warehouseOutInfo.Price = stockInInfo.Price
1291
 
1124
 
1292
-		//判断当前耗材是否有出库详情记录
1293
-		_, errcode := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, record_time, orgID)
1294
-		if errcode == gorm.ErrRecordNotFound {
1295
-			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1296
-			if errOne != nil {
1297
-				return errOne
1298
-			}
1299
-		} else if errcode == nil {
1300
-			warehouseOutInfo := &models.WarehouseOutInfo{
1301
-				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1302
-				WarehouseOutId:          warehouseOut.ID,
1303
-				WarehouseInfotId:        warehouse.ID,
1304
-				Status:                  1,
1305
-				Ctime:                   time.Now().Unix(),
1306
-				Remark:                  "",
1307
-				OrgId:                   orgID,
1308
-				Type:                    1,
1309
-				Manufacturer:            0,
1310
-				Dealer:                  0,
1311
-				IsSys:                   2,
1312
-				SysRecordTime:           record_time,
1313
-				GoodTypeId:              goods.GoodTypeId,
1314
-				GoodId:                  goods.GoodId,
1315
-			}
1316
-			warehouseOutInfo.Count = goods.Count
1317
-
1125
+		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1126
+		if errOne != nil {
1127
+			return errOne
1318
 		}
1128
 		}
1319
 
1129
 
1320
 		maxNumber = goods.Count
1130
 		maxNumber = goods.Count
1325
 
1135
 
1326
 		warehouse.StockCount = warehouse.StockCount - maxNumber
1136
 		warehouse.StockCount = warehouse.StockCount - maxNumber
1327
 		warehouse.Mtime = time.Now().Unix()
1137
 		warehouse.Mtime = time.Now().Unix()
1328
-
1329
 		if warehouse.StockCount < 0 {
1138
 		if warehouse.StockCount < 0 {
1139
+			fmt.Println("进来33232323232232323233232", warehouse.StockCount)
1330
 			return errors.New("库存数量不足")
1140
 			return errors.New("库存数量不足")
1331
 		}
1141
 		}
1332
-		errThree := UpDateWarehouseInfoByStock(&warehouse)
1333
-		if errThree != nil {
1334
-			return errThree
1335
-		}
1336
-
1337
 		return nil
1142
 		return nil
1338
 	} else {
1143
 	} else {
1339
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1144
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1343
 			WarehouseInfotId:        warehouse.ID,
1148
 			WarehouseInfotId:        warehouse.ID,
1344
 			Status:                  1,
1149
 			Status:                  1,
1345
 			Ctime:                   time.Now().Unix(),
1150
 			Ctime:                   time.Now().Unix(),
1346
-			Remark:                  "",
1151
+			Remark:                  goods.Remark,
1347
 			OrgId:                   orgID,
1152
 			OrgId:                   orgID,
1348
 			Type:                    1,
1153
 			Type:                    1,
1349
-			Manufacturer:            0,
1350
-			Dealer:                  0,
1351
-			IsSys:                   1,
1154
+			Manufacturer:            goods.Manufacturer,
1155
+			Dealer:                  goods.Dealer,
1156
+			IsSys:                   0,
1352
 			SysRecordTime:           record_time,
1157
 			SysRecordTime:           record_time,
1353
 			GoodTypeId:              goods.GoodTypeId,
1158
 			GoodTypeId:              goods.GoodTypeId,
1354
 			GoodId:                  goods.GoodId,
1159
 			GoodId:                  goods.GoodId,
1160
+			ExpiryDate:              goods.ExpiryDate,
1161
+			ProductDate:             goods.ProductDate,
1162
+			Number:                  goods.Number,
1163
+			Price:                   goods.Price,
1355
 		}
1164
 		}
1356
 		warehouseOutInfo.Count = stock_number
1165
 		warehouseOutInfo.Count = stock_number
1357
 		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1166
 		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1358
 		warehouseOutInfo.Price = stockInInfo.Price
1167
 		warehouseOutInfo.Price = stockInInfo.Price
1359
 
1168
 
1360
-		_, errcode := GetStockInRecoredByGoodIdOne(goods.GoodId, goods.GoodTypeId, record_time, orgID)
1361
-		if errcode == gorm.ErrRecordNotFound {
1362
-			errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1169
+		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1363
 
1170
 
1364
-			if errOne != nil {
1365
-				return errOne
1366
-			}
1367
-			// 出库完成后,要将该批次库存清零
1368
-			warehouse.StockCount = 0
1369
-			warehouse.Mtime = time.Now().Unix()
1370
-			errThree := UpDateWarehouseInfoByStock(&warehouse)
1371
-			if errThree != nil {
1372
-				return errThree
1373
-			}
1374
-			// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1375
-			goods.Count = deliver_number - stock_number
1171
+		if errOne != nil {
1172
+			return errOne
1173
+		}
1174
+		// 出库完成后,要将该批次库存清零
1175
+		warehouse.StockCount = 0
1176
+		warehouse.Mtime = time.Now().Unix()
1177
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
1178
+		if errThree != nil {
1179
+			return errThree
1180
+		}
1181
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1182
+		goods.Count = deliver_number - stock_number
1376
 
1183
 
1377
-			ConsumablesDeliveryOne(orgID, record_time, goods, warehouseOut, count)
1378
-		} else if errcode == nil {
1184
+		ConsumablesDeliveryOne(orgID, record_time, goods, warehouseOut, count)
1379
 
1185
 
1380
-			warehouseOutInfo := &models.WarehouseOutInfo{
1381
-				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1382
-				WarehouseOutId:          warehouseOut.ID,
1383
-				WarehouseInfotId:        warehouse.ID,
1384
-				Status:                  1,
1385
-				Ctime:                   time.Now().Unix(),
1386
-				Remark:                  "",
1186
+	}
1187
+	return nil
1188
+}
1189
+
1190
+//耗材出库删除
1191
+func ConsumablesDeliveryDeleteOne(orgID int64, record_time int64, good_yc *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut) (err error) {
1192
+	// 先根据相关信息查询当天该耗材的出库信息
1193
+	warehouseOutInfos, err := FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
1194
+	if err != nil {
1195
+		return err
1196
+	}
1197
+
1198
+	var delete_count int64 = 0
1199
+
1200
+	for _, ware := range warehouseOutInfos {
1201
+		// 判断当前出库的数据和删除出库数量
1202
+		if good_yc.Count <= ware.Count {
1203
+			delete_count = good_yc.Count
1204
+		} else {
1205
+			delete_count = ware.Count
1206
+		}
1207
+		// 在出库记录表里记录退库详情
1208
+		warehouseOutInfo := &models.WarehouseOutInfo{
1209
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1210
+			WarehouseOutId:          warehouseOut.ID,
1211
+			//WarehouseInfoId:		 warehouse.ID,
1212
+			Status:        1,
1213
+			Ctime:         time.Now().Unix(),
1214
+			Remark:        "",
1215
+			OrgId:         orgID,
1216
+			Type:          1,
1217
+			Manufacturer:  0,
1218
+			Dealer:        0,
1219
+			IsSys:         0,
1220
+			SysRecordTime: record_time,
1221
+			GoodTypeId:    good_yc.GoodTypeId,
1222
+			GoodId:        good_yc.GoodId,
1223
+		}
1224
+		warehouseOutInfo.Count = delete_count
1225
+		stockInInfo, _ := FindLastStockInInfoRecord(good_yc.GoodId, orgID)
1226
+		warehouseOutInfo.Price = stockInInfo.Price
1227
+		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1228
+		if errOne != nil {
1229
+			return errOne
1230
+		}
1231
+		// 删除出库完成后,要增加对应批次的库存数量
1232
+
1233
+		errThree := UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count)
1234
+		if errThree != nil {
1235
+			return errThree
1236
+		}
1237
+
1238
+		// 增加了对应的库存后,看看还有多少需要退库的
1239
+		good_yc.Count = good_yc.Count - delete_count
1240
+		if good_yc.Count == 0 {
1241
+			return nil
1242
+		}
1243
+	}
1244
+
1245
+	if good_yc.Count == 0 {
1246
+		return nil
1247
+	} else {
1248
+		return errors.New("退库和出库数据不匹配")
1249
+	}
1250
+}
1251
+
1252
+func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods) (err error) {
1253
+
1254
+	//查询该患者当天已经出库的耗材信息
1255
+	goods_yc, _ := FindConsumablesByDateThree(orgID, patient_id, record_time)
1256
+	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
1257
+	for i := len(goods_yc) - 1; i >= 0; i-- {
1258
+		goods_yc_temp := goods_yc[i]
1259
+		for j := len(goods) - 1; j >= 0; j-- {
1260
+			goods_temp := goods[j]
1261
+			// 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
1262
+			if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
1263
+				// 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
1264
+				if goods_yc_temp.Count == goods_temp.Count {
1265
+					goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
1266
+					goods = append(goods[:j], goods[j+1:]...)
1267
+					break
1268
+				}
1269
+				// 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
1270
+				if goods_yc_temp.Count > goods_temp.Count {
1271
+
1272
+					temp_count := goods_yc_temp.Count - goods_temp.Count
1273
+					goods_yc[i].Count = temp_count
1274
+					goods = append(goods[:j], goods[j+1:]...)
1275
+					break
1276
+				}
1277
+				// 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
1278
+				if goods_yc_temp.Count < goods_temp.Count {
1279
+					temp_count := goods_temp.Count - goods_yc_temp.Count
1280
+					//fmt.Println("988888888888888", temp_count)
1281
+					goods[j].Count = temp_count
1282
+					goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
1283
+					//fmt.Println("888888888", goods_yc)
1284
+					break
1285
+				}
1286
+			}
1287
+		}
1288
+	}
1289
+
1290
+	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1291
+	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
1292
+	fmt.Println("goods222222222222", goods)
1293
+	fmt.Println("goodsy999999999999", goods_yc)
1294
+	if len(goods) > 0 {
1295
+		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1296
+		if err == gorm.ErrRecordNotFound {
1297
+			//没有记录,则创建出库单
1298
+			timeStr := time.Now().Format("2006-01-02")
1299
+			timeArr := strings.Split(timeStr, "-")
1300
+			total, _ := FindAllWarehouseOut(orgID)
1301
+			total = total + 1
1302
+			warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1303
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1304
+			number = number + total
1305
+			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1306
+			warehouseOut := models.WarehouseOut{
1307
+				WarehouseOutOrderNumber: warehousing_out_order,
1308
+				OperationTime:           time.Now().Unix(),
1387
 				OrgId:                   orgID,
1309
 				OrgId:                   orgID,
1388
-				Type:                    1,
1389
-				Manufacturer:            0,
1310
+				Creater:                 0,
1311
+				Ctime:                   time.Now().Unix(),
1312
+				Status:                  1,
1313
+				WarehouseOutTime:        record_time,
1390
 				Dealer:                  0,
1314
 				Dealer:                  0,
1315
+				Manufacturer:            0,
1316
+				Type:                    1,
1391
 				IsSys:                   1,
1317
 				IsSys:                   1,
1392
-				SysRecordTime:           record_time,
1393
-				GoodTypeId:              goods.GoodTypeId,
1394
-				GoodId:                  goods.GoodId,
1395
 			}
1318
 			}
1396
-			warehouseOutInfo.Count = goods.Count
1397
-			//更新入库详情表
1398
-			UpdateAutoMaticReduceDetailOne(goods.GoodId, goods.GoodTypeId, record_time, orgID, warehouseOutInfo)
1319
+			err := AddSigleWarehouseOut(&warehouseOut)
1320
+			if err != nil {
1321
+				utils.TraceLog("创建出库单失败 err = %v", err)
1322
+				return err
1323
+			} else {
1324
+				out = warehouseOut
1325
+			}
1326
+		}
1327
+
1328
+		for _, item := range goods {
1329
+			var newCount int64 = 0
1330
+			for _, it := range goodOne {
1331
+				if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
1332
+					newCount = it.Count
1333
+				}
1334
+			}
1335
+			prepare := models.DialysisBeforePrepare{
1336
+				GoodTypeId: item.GoodTypeId,
1337
+				GoodId:     item.GoodId,
1338
+				Count:      item.Count,
1339
+			}
1340
+
1341
+			ConsumablesDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
1399
 		}
1342
 		}
1400
 
1343
 
1401
 	}
1344
 	}
1345
+
1346
+	if len(goods_yc) > 0 {
1347
+		for _, good_yc := range goods_yc {
1348
+			out, _ := FindStockOutByIsSys(orgID, 1, record_time)
1349
+			ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
1350
+		}
1351
+	}
1352
+
1402
 	return nil
1353
 	return nil
1403
 }
1354
 }
1404
 
1355
 
1405
 //耗材出库删除
1356
 //耗材出库删除
1406
-func ConsumablesDeliveryDeleteOne(orgID int64, record_time int64, good_yc *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut) (err error) {
1357
+func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
1407
 	// 先根据相关信息查询当天该耗材的出库信息
1358
 	// 先根据相关信息查询当天该耗材的出库信息
1408
 	warehouseOutInfos, err := FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
1359
 	warehouseOutInfos, err := FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
1409
 	if err != nil {
1360
 	if err != nil {
1431
 			Type:          1,
1382
 			Type:          1,
1432
 			Manufacturer:  0,
1383
 			Manufacturer:  0,
1433
 			Dealer:        0,
1384
 			Dealer:        0,
1434
-			IsSys:         2,
1385
+			IsSys:         0,
1435
 			SysRecordTime: record_time,
1386
 			SysRecordTime: record_time,
1436
 			GoodTypeId:    good_yc.GoodTypeId,
1387
 			GoodTypeId:    good_yc.GoodTypeId,
1437
 			GoodId:        good_yc.GoodId,
1388
 			GoodId:        good_yc.GoodId,