Browse Source

Merge branch '20211122' of http://git.shengws.com/csx/XT_New into 20211122

csx 3 years ago
parent
commit
013d81be3e

+ 1 - 3
controllers/dialysis_record_api_controller.go View File

@@ -77,7 +77,7 @@ func (this *DialysisRecordAPIController) GetSchedules() {
77 77
 	redis := service.RedisClient()
78 78
 	defer redis.Close()
79 79
 	key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
80
-
80
+	patients, _ := service.GetAllPcPatientListByListSeven(orgID)
81 81
 	scheduals_json_str, _ := redis.Get(key).Result()
82 82
 
83 83
 	if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
@@ -89,8 +89,6 @@ func (this *DialysisRecordAPIController) GetSchedules() {
89 89
 		} else {
90 90
 			if len(scheduals) > 0 {
91 91
 
92
-				patients, _ := service.GetAllPcPatientListByListSeven(orgID)
93
-
94 92
 				dialysisOrders, _ := service.GetAllPcDialysisOrdersByList(orgID, date.Unix())
95 93
 
96 94
 				prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())

+ 3 - 3
controllers/drug_stock_api_contorller.go View File

@@ -853,7 +853,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
853 853
 				//查询默认仓库
854 854
 				houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
855 855
 				//查询默认仓库剩余多少库存
856
-				list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseInfo, adminUserInfo.CurrentOrgId, item.DrugId)
856
+				list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, adminUserInfo.CurrentOrgId, item.DrugId)
857 857
 				var sum_count int64
858 858
 				var sum_in_count int64
859 859
 				for _, it := range list {
@@ -899,7 +899,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
899 899
 				//查询默认仓库
900 900
 				houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
901 901
 				//查询默认仓库剩余多少库存
902
-				list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseInfo, adminUserInfo.CurrentOrgId, item.DrugId)
902
+				list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, adminUserInfo.CurrentOrgId, item.DrugId)
903 903
 				var sum_count int64
904 904
 				var sum_in_count int64
905 905
 				for _, it := range list {
@@ -989,7 +989,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
989 989
 				//查询默认仓库
990 990
 				houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
991 991
 				//查询默认仓库剩余多少库存
992
-				list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseInfo, adminUserInfo.CurrentOrgId, item.DrugId)
992
+				list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, adminUserInfo.CurrentOrgId, item.DrugId)
993 993
 				var sum_count int64
994 994
 				var sum_in_count int64
995 995
 				for _, it := range list {

+ 32 - 0
controllers/gobal_config_api_controller.go View File

@@ -112,6 +112,8 @@ func GobalConfigRegistRouters() {
112 112
 	beego.Router("/api/drug/getexportoutorderdruglist", &GobalConfigApiController{}, "Get:GetExportOutOrderDrugList")
113 113
 	beego.Router("/api/drug/getdrugflow", &GobalConfigApiController{}, "Get:GetDrugFlow")
114 114
 	beego.Router("/api/drug/getcancelstockdetail", &GobalConfigApiController{}, "Get:GetCancelStockDetail")
115
+
116
+	beego.Router("/api/changestocksetting/isopen", &GobalConfigApiController{}, "Get:ChangeStockSetting")
115 117
 }
116 118
 
117 119
 //provinces, _ := service.GetDistrictsByUpid(0)21
@@ -1557,9 +1559,11 @@ func (c *GobalConfigApiController) GetAllIsOpenConfig() {
1557 1559
 	_, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
1558 1560
 	_, project_config := service.FindXTHisProjectByOrgIdOne(adminUserInfo.CurrentOrgId)
1559 1561
 
1562
+	stockSetting, _ := service.FindStockSettingById(adminUserInfo.CurrentOrgId)
1560 1563
 	c.ServeSuccessJSON(map[string]interface{}{
1561 1564
 		"is_open_xt_his":         config.IsOpen,
1562 1565
 		"is_open_xt_his_project": project_config.IsOpen,
1566
+		"is_open_stock":          stockSetting.IsType,
1563 1567
 	})
1564 1568
 
1565 1569
 }
@@ -2331,3 +2335,31 @@ func (c *GobalConfigApiController) GetCancelStockDetail() {
2331 2335
 		"list": list,
2332 2336
 	})
2333 2337
 }
2338
+
2339
+func (c *GobalConfigApiController) ChangeStockSetting() {
2340
+
2341
+	is_type, _ := c.GetInt64("is_type")
2342
+
2343
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2344
+	setting := models.XtStockSetting{
2345
+		IsType:    is_type,
2346
+		UserOrgId: orgId,
2347
+		Status:    1,
2348
+		Ctime:     time.Now().Unix(),
2349
+		Mtime:     0,
2350
+	}
2351
+
2352
+	//查询机该机构是否已经配置
2353
+	_, errcode := service.GetStockSettingIsExsit(orgId)
2354
+	if errcode == gorm.ErrRecordNotFound {
2355
+		service.CreateStockSetting(setting)
2356
+		c.ServeSuccessJSON(map[string]interface{}{
2357
+			"msg": 1,
2358
+		})
2359
+	} else if errcode == nil {
2360
+		service.UpdateStockSetting(orgId, setting)
2361
+		c.ServeSuccessJSON(map[string]interface{}{
2362
+			"msg": 1,
2363
+		})
2364
+	}
2365
+}

+ 1 - 0
controllers/his_api_controller.go View File

@@ -1198,6 +1198,7 @@ func (c *HisApiController) CreateHisPrescription() {
1198 1198
 										//}
1199 1199
 
1200 1200
 										good, _ := service.GetGoodInformationByGoodId(project_id)
1201
+										fmt.Println("parsetotal3232323223233232232323233", parsetotal, good.SumCount)
1201 1202
 										if parsetotal > good.SumCount {
1202 1203
 											c.ServeDynamicFailJsonSend(project_name + "库存不足")
1203 1204
 											return

+ 8 - 6
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -90,6 +90,7 @@ func (this *DialysisAPIController) Scheduals() {
90 90
 
91 91
 	scheduals_json_str, _ := redis.Get(key).Result()
92 92
 	redis.Set(key, "", time.Second)
93
+	patients, _ := service.GetAllPatientListSix(orgID)
93 94
 	if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
94 95
 		scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
95 96
 
@@ -98,7 +99,7 @@ func (this *DialysisAPIController) Scheduals() {
98 99
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
99 100
 		} else {
100 101
 			if len(scheduals) > 0 {
101
-				patients, _ := service.GetAllPatientListSix(orgID)
102
+
102 103
 				devices, _ := service.GetAllDevicetByListSix(orgID)
103 104
 				advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
104 105
 				prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
@@ -4163,7 +4164,7 @@ func (c *DialysisAPIController) CreateConsumables() {
4163 4164
 							service.CreateDialysisBeforePrepareOne(&prepare)
4164 4165
 							//查询默认仓库
4165 4166
 							houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
4166
-							goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseInfo, item.GoodId, adminUser.Org.Id)
4167
+							goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.Org.Id)
4167 4168
 							var sum_count int64
4168 4169
 							var sum_in_count int64
4169 4170
 							for _, it := range goodList {
@@ -4314,7 +4315,7 @@ func (c *DialysisAPIController) CreateStockOutInfo() {
4314 4315
 					service.CreateDialysisBeforePrepareOne(&prepare)
4315 4316
 					//查询默认仓库
4316 4317
 					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
4317
-					goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseInfo, item.GoodId, adminInfo.Org.Id)
4318
+					goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id)
4318 4319
 					var sum_count int64
4319 4320
 					var sum_in_count int64
4320 4321
 					for _, it := range goodList {
@@ -4357,7 +4358,7 @@ func (c *DialysisAPIController) CreateStockOutInfo() {
4357 4358
 					service.CreateDialysisBeforePrepareOne(&prepare)
4358 4359
 					//查询默认仓库
4359 4360
 					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
4360
-					goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseInfo, item.GoodId, adminInfo.Org.Id)
4361
+					goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id)
4361 4362
 					var sum_count int64
4362 4363
 					var sum_in_count int64
4363 4364
 					for _, it := range goodList {
@@ -4875,6 +4876,7 @@ func (c *DialysisAPIController) CreateOtherStockOutInfo() {
4875 4876
 
4876 4877
 	//出库逻辑
4877 4878
 	err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
4879
+
4878 4880
 	if err != nil {
4879 4881
 		utils.ErrorLog(err.Error())
4880 4882
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -4905,14 +4907,14 @@ func (c *DialysisAPIController) CreateOtherStockOutInfo() {
4905 4907
 
4906 4908
 		//查询默认仓库
4907 4909
 		houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
4908
-		goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseInfo, item.ProjectId, adminInfo.Org.Id)
4910
+		goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id)
4909 4911
 		var sum_count int64
4910 4912
 		var sum_in_count int64
4911 4913
 		for _, it := range goodList {
4912 4914
 			sum_count += it.StockCount
4913 4915
 			sum_in_count += it.WarehousingCount
4914 4916
 		}
4915
-		service.UpdateGoodByGoodId(item.ProjectId, sum_count, sum_in_count, adminInfo.Org.Id)
4917
+		service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, adminInfo.Org.Id)
4916 4918
 
4917 4919
 	}
4918 4920
 

+ 48 - 3
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -3855,7 +3855,6 @@ func (c *PatientApiController) DelDoctorAdvice() {
3855 3855
 
3856 3856
 			err = service.DeleteDoctorAdviceByGroupNo(&advice)
3857 3857
 			key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
3858
-			fmt.Println("key2332323223323232323232323", key)
3859 3858
 
3860 3859
 			redis.Set(key, "", time.Second)
3861 3860
 
@@ -3870,9 +3869,9 @@ func (c *PatientApiController) DelDoctorAdvice() {
3870 3869
 			key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
3871 3870
 
3872 3871
 			redis.Set(key, "", time.Second)
3873
-			fmt.Println("key2332323223323232323232323", key)
3872
+
3874 3873
 			keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
3875
-			fmt.Println("key2332323223323232323232323", keyTwo)
3874
+
3876 3875
 			redis.Set(keyTwo, "", time.Second)
3877 3876
 			keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
3878 3877
 			redis.Set(keyThree, "", time.Second)
@@ -4009,6 +4008,52 @@ func (c *PatientApiController) ExecProject() {
4009 4008
 	adminInfo := c.GetMobileAdminUserInfo()
4010 4009
 
4011 4010
 	project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
4011
+
4012
+	if project.Type == 3 {
4013
+		good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
4014
+		if good.IsUser != 1 {
4015
+
4016
+			//查询开关是否开启
4017
+			stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
4018
+
4019
+			//开关已经开启
4020
+			if stockSetting.IsType == 1 {
4021
+				theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
4022
+				scheduleDateStart := theTime.Format("2006-01-02")
4023
+				timeLayout3 := "2006-01-02"
4024
+				loc, _ := time.LoadLocation("Local")
4025
+				execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
4026
+				//查询该耗材是否已经出库
4027
+				auto, _ := service.GetAutoStockOutById(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
4028
+				if auto.ID == 0 {
4029
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
4030
+					return
4031
+				}
4032
+			}
4033
+		}
4034
+
4035
+		if good.IsUser == 1 && good.IsWarehouse == 1 {
4036
+
4037
+			//查询开关是否开启
4038
+			stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
4039
+
4040
+			//开关已经开启
4041
+			if stockSetting.IsType == 1 {
4042
+				theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
4043
+				scheduleDateStart := theTime.Format("2006-01-02")
4044
+				timeLayout3 := "2006-01-02"
4045
+				loc, _ := time.LoadLocation("Local")
4046
+				execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
4047
+				//查询该耗材是否已经出库
4048
+				auto, _ := service.GetAutoStockOutById(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
4049
+				if auto.ID == 0 {
4050
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
4051
+					return
4052
+				}
4053
+			}
4054
+		}
4055
+	}
4056
+
4012 4057
 	if project.ExecutionState == 1 {
4013 4058
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
4014 4059
 		return

+ 8 - 0
controllers/patient_api_controller.go View File

@@ -568,6 +568,14 @@ func (c *PatientApiController) EditPatient() {
568 568
 	//	//更新病人ID获取新表病人ID
569 569
 	err = service.UpdatepatientTwo(&patientsNew, id)
570 570
 
571
+	nowTimeUinx := time.Now()
572
+	today := nowTimeUinx.Format("2006-01-02")
573
+
574
+	redis := service.RedisClient()
575
+	defer redis.Close()
576
+	key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
577
+	redis.Set(key, "", time.Second*60*60*18)
578
+
571 579
 	if len(record_date) > 0 {
572 580
 		var recordTime int64
573 581
 		timeLayout := "2006-01-02"

+ 81 - 24
controllers/secondary_order_api_contorller.go View File

@@ -40,25 +40,6 @@ func SecondaryOrderApiRegistRouters() {
40 40
 	beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit")                         //初始化旧数据
41 41
 	beego.Router("/api/secondary/getcreaterid", &SecondaryOrderApiController{}, "get:GetCreaterId")                 //获取当前登录的人的id
42 42
 
43
-	beego.Router("/api/secondary/getcode", &SecondaryOrderApiController{}, "get:GetStoreCode")                      //获取仓库编码
44
-	beego.Router("/api/secondary/updatestatus", &SecondaryOrderApiController{}, "get:UpdateStatus")                 //修改仓库状态
45
-	beego.Router("/api/secondary/deletestorehouse", &SecondaryOrderApiController{}, "get:DeleteStorehouse")         //删除仓库
46
-	beego.Router("/api/secondary/isstorehousename", &SecondaryOrderApiController{}, "get:IsStorehouseName")         //仓库名称是否重复
47
-	beego.Router("/api/secondary/isstorehouseaddress", &SecondaryOrderApiController{}, "get:IsStorehouseAddress")   //仓库地址是否重复
48
-	beego.Router("/api/secondary/storehouselist", &SecondaryOrderApiController{}, "get:StorehouseList")             //分页
49
-	beego.Router("/api/secondary/addstorehouse", &SecondaryOrderApiController{}, "post:AddStorehouse")              //新增仓库
50
-	beego.Router("/api/secondary/updatestorehouse", &SecondaryOrderApiController{}, "post:UpdateStorehouse")        //修改
51
-	beego.Router("/api/secondary/getonestorehouse", &SecondaryOrderApiController{}, "get:GetOneStorehouse")         //查一条仓库的信息
52
-	beego.Router("/api/secondary/getallstorehousename", &SecondaryOrderApiController{}, "get:GetAllStorehouseName") //获取当前机构的所有可用仓库名称
53
-	beego.Router("/api/secondary/findstorehouseconfig", &SecondaryOrderApiController{}, "get:FindStorehouseConfig") //查询该机构的仓库配置
54
-	beego.Router("/api/secondary/updateinfo", &SecondaryOrderApiController{}, "get:UpdateInfo")                     //更改耗材自动入库仓库
55
-	beego.Router("/api/secondary/updateoutinfo", &SecondaryOrderApiController{}, "get:UpdateOutInfo")               //更改耗材自动出库仓库
56
-	beego.Router("/api/secondary/updatedruginfo", &SecondaryOrderApiController{}, "get:UpdateDrugInfo")             //更改药品自动入库仓库
57
-	beego.Router("/api/secondary/updatedrugout", &SecondaryOrderApiController{}, "get:UpdateDrugOut")               //更改药品自动出库仓库
58
-	beego.Router("/api/secondary/getusername", &SecondaryOrderApiController{}, "get:GetuserName")                   //获取仓库管理员信息
59
-	beego.Router("/api/secondary/byliinit", &SecondaryOrderApiController{}, "get:Byliinit")                         //初始化旧数据
60
-	beego.Router("/api/secondary/getcreaterid", &SecondaryOrderApiController{}, "get:GetCreaterId")
61
-
62 43
 	beego.Router("/api/seconde/getsencondegoodlist", &SecondaryOrderApiController{}, "Get:GetSencondeGoodList")
63 44
 	beego.Router("/api/senconde/savesencondorder", &SecondaryOrderApiController{}, "Post:SaveSencondOrder")
64 45
 	beego.Router("/api/senconde/getallsecondeorderlist", &SecondaryOrderApiController{}, "Get:GetAllSecondeOrderList")
@@ -664,7 +645,6 @@ func (this *SecondaryOrderApiController) SaveSencondOrder() {
664 645
 func (this *SecondaryOrderApiController) GetAllSecondeOrderList() {
665 646
 
666 647
 	check_id, _ := this.GetInt64("check_id")
667
-	fmt.Println("checkd_id3232323233233223", check_id)
668 648
 	start_time := this.GetString("start_time")
669 649
 	timeLayout := "2006-01-02"
670 650
 	loc, _ := time.LoadLocation("Local")
@@ -950,7 +930,7 @@ func (this *SecondaryOrderApiController) GetSecondOrderById() {
950 930
 	warehouse, _ := service.GetSecondWarehouseOrderById(id)
951 931
 	list, _ := service.GetSencondOrderDetail(id, orgId)
952 932
 	appId := this.GetAdminUserInfo().CurrentAppId
953
-	doctor, _ := service.GetAllDoctor(orgId, appId)
933
+	doctor, _ := service.GetAllDoctorSix(orgId, appId)
954 934
 	houseList, _ := service.GetAllStoreHouseList(orgId)
955 935
 	this.ServeSuccessJSON(map[string]interface{}{
956 936
 		"warehouse":  warehouse,
@@ -1508,7 +1488,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1508 1488
 			//查询默认仓库
1509 1489
 			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1510 1490
 			//查询默认仓库剩余多少库存
1511
-			list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseInfo, orgId, item.ProjectId)
1491
+			list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ProjectId)
1512 1492
 			var sum_count int64
1513 1493
 			var sum_in_count int64
1514 1494
 			for _, it := range list {
@@ -1539,7 +1519,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1539 1519
 				outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1540 1520
 				for _, it := range outList {
1541 1521
 					//回退库存
1542
-					service.ModifyStoreWarehouseById(it.WarehouseInfotId, item.Count)
1522
+					service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
1543 1523
 
1544 1524
 					//获取入库单
1545 1525
 					storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
@@ -1554,7 +1534,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1554 1534
 
1555 1535
 			//查询默认仓库
1556 1536
 			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1557
-			goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseInfo, item.ProjectId, item.UserOrgId)
1537
+			goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
1558 1538
 			var sum_count int64
1559 1539
 			var sum_in_count int64
1560 1540
 			for _, it := range goodList {
@@ -1786,6 +1766,22 @@ func (this *SecondaryOrderApiController) UpdateInfo() {
1786 1766
 	}
1787 1767
 	id, _ := this.GetInt64("id")
1788 1768
 	err = service.UpdateInfo(orgId, id)
1769
+
1770
+	//查询默认仓库
1771
+	houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1772
+
1773
+	list, _ := service.GetAllGoodList(orgId)
1774
+	for _, item := range list {
1775
+		var sum_count int64
1776
+		var sum_in_count int64
1777
+		goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
1778
+		for _, it := range goodList {
1779
+			sum_count += it.StockCount
1780
+			sum_in_count += it.WarehousingCount
1781
+		}
1782
+		service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
1783
+	}
1784
+
1789 1785
 	if err != nil {
1790 1786
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1791 1787
 		return
@@ -1810,6 +1806,22 @@ func (this *SecondaryOrderApiController) UpdateOutInfo() {
1810 1806
 	}
1811 1807
 	id, _ := this.GetInt64("id")
1812 1808
 	err = service.UpdateOutInfo(orgId, id)
1809
+
1810
+	//查询默认仓库
1811
+	houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1812
+
1813
+	list, _ := service.GetAllGoodList(orgId)
1814
+	for _, item := range list {
1815
+		var sum_count int64
1816
+		var sum_in_count int64
1817
+		goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ID, orgId)
1818
+		for _, it := range goodList {
1819
+			sum_count += it.StockCount
1820
+			sum_in_count += it.WarehousingCount
1821
+		}
1822
+		service.UpdateGoodByGoodId(item.ID, sum_count, sum_in_count, orgId)
1823
+	}
1824
+
1813 1825
 	if err != nil {
1814 1826
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1815 1827
 		return
@@ -1833,7 +1845,30 @@ func (this *SecondaryOrderApiController) UpdateDrugInfo() {
1833 1845
 		return
1834 1846
 	}
1835 1847
 	id, _ := this.GetInt64("id")
1848
+
1836 1849
 	err = service.UpdateDrugInfo2(orgId, id)
1850
+
1851
+	//查询默认仓库
1852
+	houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1853
+	baseDrug, _ := service.GetAllBaseDrugList(orgId)
1854
+
1855
+	for _, item := range baseDrug {
1856
+		var sum_drug_count int64
1857
+		var sum_drug_in_count int64
1858
+
1859
+		//查询默认仓库剩余多少库存
1860
+		list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
1861
+		for _, it := range list {
1862
+			if it.MaxUnit == item.MaxUnit {
1863
+				it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
1864
+				it.WarehousingCount = it.WarehousingCount * item.MinNumber
1865
+			}
1866
+			sum_drug_count += it.StockMaxNumber + it.StockMinNumber
1867
+			sum_drug_in_count += it.WarehousingCount
1868
+		}
1869
+		service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
1870
+	}
1871
+
1837 1872
 	if err != nil {
1838 1873
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1839 1874
 		return
@@ -1858,6 +1893,28 @@ func (this *SecondaryOrderApiController) UpdateDrugOut() {
1858 1893
 	}
1859 1894
 	id, _ := this.GetInt64("id")
1860 1895
 	err = service.UpdateDrugOut(orgId, id)
1896
+
1897
+	//查询默认仓库
1898
+	houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1899
+	baseDrug, _ := service.GetAllBaseDrugList(orgId)
1900
+
1901
+	for _, item := range baseDrug {
1902
+		var sum_drug_count int64
1903
+		var sum_drug_in_count int64
1904
+
1905
+		//查询默认仓库剩余多少库存
1906
+		list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ID)
1907
+		for _, it := range list {
1908
+			if it.MaxUnit == item.MaxUnit {
1909
+				it.StockMaxNumber = it.StockMaxNumber * item.MinNumber
1910
+				it.WarehousingCount = it.WarehousingCount * item.MinNumber
1911
+			}
1912
+			sum_drug_count += it.StockMaxNumber + it.StockMinNumber
1913
+			sum_drug_in_count += it.WarehousingCount
1914
+		}
1915
+		service.UpdateMedicalSumCount(item.ID, sum_drug_count, sum_drug_in_count, orgId)
1916
+	}
1917
+
1861 1918
 	if err != nil {
1862 1919
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1863 1920
 		return

+ 1 - 1
controllers/stock_good_api_controller.go View File

@@ -176,7 +176,7 @@ func (c *StockGoodApiController) GetAllGoodType() {
176 176
 	goodTypes, err := service.FindAllGoodType(adminUserInfo.CurrentOrgId)
177 177
 	houseList, _ := service.GetAllStoreHouseListTwo(adminUserInfo.CurrentOrgId)
178 178
 	storehouselist, _ := service.GetAllStoreHouseList(adminUserInfo.CurrentOrgId)
179
-	goodInfo, _ := service.FindAllGoodInfo(adminUserInfo.CurrentOrgId)
179
+	goodInfo, _ := service.FindAllGoodInfoTwo(adminUserInfo.CurrentOrgId)
180 180
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
181 181
 	if err == nil {
182 182
 		c.ServeSuccessJSON(map[string]interface{}{

+ 5 - 5
controllers/stock_in_api_controller.go View File

@@ -783,7 +783,7 @@ func (c *StockManagerApiController) EditWarehouse() {
783 783
 				//查询该机构默认仓库
784 784
 				storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
785 785
 				//查询剩余库存
786
-				goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseInfo, item.GoodId, adminUserInfo.CurrentOrgId)
786
+				goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
787 787
 				var sum_count int64
788 788
 				var sum_in_count int64
789 789
 				for _, item := range goodList {
@@ -823,7 +823,7 @@ func (c *StockManagerApiController) EditWarehouse() {
823 823
 				//查询该机构默认仓库
824 824
 				storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
825 825
 				//查询剩余库存
826
-				goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseInfo, item.GoodId, adminUserInfo.CurrentOrgId)
826
+				goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
827 827
 				var sum_count int64
828 828
 				var sum_in_count int64
829 829
 				for _, item := range goodList {
@@ -7711,9 +7711,9 @@ func (this *StockManagerApiController) GetDrugDetailSummary() {
7711 7711
 	page, _ := this.GetInt64("page")
7712 7712
 	orgId := this.GetAdminUserInfo().CurrentOrgId
7713 7713
 	list, total, err := service.GetDrugDetailSummary(startTime, endTime, keyword, limit, page, orgId)
7714
-
7714
+	fmt.Println("list23323232233232233223232323", list)
7715 7715
 	druglist, _, _ := service.GetDrugDetailSummaryOne(startTime, endTime, keyword, limit, page, orgId)
7716
-
7716
+	fmt.Println("druglist2332322332223322323", druglist)
7717 7717
 	patients, _ := service.GetAllpatient(orgId)
7718 7718
 	var drugType = "药品类型"
7719 7719
 	drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
@@ -7753,7 +7753,7 @@ func (this *StockManagerApiController) GetGoodDetailSummary() {
7753 7753
 			return
7754 7754
 		}
7755 7755
 		startTime = theTime.Unix()
7756
-		fmt.Println("开始时间", startTime)
7756
+
7757 7757
 	}
7758 7758
 	var endTime int64
7759 7759
 	if len(end_time) > 0 {

+ 3 - 0
enums/error_code.go View File

@@ -90,6 +90,7 @@ const ( // ErrorCode
90 90
 	ErrorCodeNotSelectLapsetoType           = 1042
91 91
 	ErrorCodeNotSelectLapsetoTime           = 1043
92 92
 	ErrorCodeEquitNoExist                   = 1045
93
+	ErrorCodeStockExced                     = 1046
93 94
 
94 95
 	ErrorCodeInspectionDateExit    = 1201
95 96
 	ErrorCodeInspectionAddFail     = 1202
@@ -477,6 +478,8 @@ var ErrCodeMsgs = map[int]string{
477 478
 	ErrorCodeHospitalExistDataException: "该患者已经入院,请选办理出院结算后再进行办理入院操作",
478 479
 
479 480
 	ErrorCodeRecordFailedException: "记录不存在",
481
+
482
+	ErrorCodeStockExced: "请先出库,执行失败",
480 483
 }
481 484
 
482 485
 type SGJError struct {

+ 1 - 0
models/patient_models.go View File

@@ -22,6 +22,7 @@ type MSchedualPatientList struct {
22 22
 	Name               string `gorm:"column:name" json:"name" form:"name"`
23 23
 	IdCardNo           string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
24 24
 	UserSysBeforeCount int64  `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
25
+	TrobleShoot        int64  `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
25 26
 }
26 27
 
27 28
 func (MSchedualPatientList) TableName() string {

+ 13 - 0
models/stock_models.go View File

@@ -1332,3 +1332,16 @@ type BloodHisPrescriptionProject struct {
1332 1332
 func (BloodHisPrescriptionProject) TableName() string {
1333 1333
 	return "his_prescription_project"
1334 1334
 }
1335
+
1336
+type XtStockSetting struct {
1337
+	ID        int64 `gorm:"column:id" json:"id" form:"id"`
1338
+	IsType    int64 `gorm:"column:is_type" json:"is_type" form:"is_type"`
1339
+	UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1340
+	Status    int64 `gorm:"column:status" json:"status" form:"status"`
1341
+	Ctime     int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
1342
+	Mtime     int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
1343
+}
1344
+
1345
+func (XtStockSetting) TableName() string {
1346
+	return "xt_stock_setting"
1347
+}

+ 8 - 8
service/secondary_service.go View File

@@ -980,9 +980,9 @@ func ModifyStoreWarehouse(id int64, orgid int64, good_id int64) error {
980 980
 
981 981
 	err := XTWriteDB().Model(&models.Warehousing{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
982 982
 
983
-	err = XTWriteDB().Model(&models.WarehousingInfo{}).Where("warehousing_id in(?) and org_id = ? and status =1 and good_id = ?", id, orgid, good_id).Update(map[string]interface{}{"status": 0}).Error
983
+	err = XTWriteDB().Model(&models.WarehousingInfo{}).Where("warehousing_id  = ? and org_id = ? and status =1 and good_id = ?", id, orgid, good_id).Update(map[string]interface{}{"status": 0}).Error
984 984
 
985
-	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("warehousing_id in(?) and user_org_id = ? and status = 1 and good_id = ?", id, orgid, good_id).Update(map[string]interface{}{"status": 0}).Error
985
+	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("warehousing_id = ? and user_org_id = ? and status = 1 and good_id = ?", id, orgid, good_id).Update(map[string]interface{}{"status": 0}).Error
986 986
 	return err
987 987
 }
988 988
 
@@ -996,9 +996,9 @@ func GetStoreWarehouseOutById(id int64, orgid int64) (models.WarehouseOut, error
996 996
 func ModifyWarehouseOut(id int64, orgid int64, good_id int64) error {
997 997
 	err := XTWriteDB().Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
998 998
 
999
-	err = XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id in(?) and org_id = ? and status =1 and good_id = ?", id, orgid, good_id).Update(map[string]interface{}{"status": 0}).Error
999
+	err = XTWriteDB().Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id = ? and org_id = ? and status =1 and good_id = ?", id, orgid, good_id).Update(map[string]interface{}{"status": 0}).Error
1000 1000
 
1001
-	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("warehouse_out_id in(?) and user_org_id = ? and status = 1 and good_id = ?", id, orgid, good_id).Update(map[string]interface{}{"status": 0}).Error
1001
+	err = XTWriteDB().Model(&models.VmStockFlow{}).Where("warehouse_out_id = ? and user_org_id = ? and status = 1 and good_id = ?", id, orgid, good_id).Update(map[string]interface{}{"status": 0}).Error
1002 1002
 	return err
1003 1003
 }
1004 1004
 
@@ -1030,9 +1030,9 @@ func DeleteStoreWarehousingId(id int64, orgid int64, drug_id int64) error {
1030 1030
 
1031 1031
 	err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
1032 1032
 
1033
-	err = XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("warehousing_id in(?) and org_id = ? and status = 1 and drug_id = ?", id, orgid, drug_id).Update(map[string]interface{}{"status": 0}).Error
1033
+	err = XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("warehousing_id  = ? and org_id = ? and status = 1 and drug_id = ?", id, orgid, drug_id).Update(map[string]interface{}{"status": 0}).Error
1034 1034
 
1035
-	err = XTWriteDB().Model(&models.DrugFlow{}).Where("warehousing_id in(?) and user_org_id =? and status = 1 and drug_id = ?", id, orgid, drug_id).Update(map[string]interface{}{"status": 0}).Error
1035
+	err = XTWriteDB().Model(&models.DrugFlow{}).Where("warehousing_id = ? and user_org_id =? and status = 1 and drug_id = ?", id, orgid, drug_id).Update(map[string]interface{}{"status": 0}).Error
1036 1036
 	return err
1037 1037
 }
1038 1038
 
@@ -1046,9 +1046,9 @@ func GetStoreDrugWarehouseOutById(id int64, orgid int64) (models.DrugWarehouseOu
1046 1046
 func DeleteStoreWarehouseOut(id int64, orgid int64, drug_id int64) error {
1047 1047
 	err := XTWriteDB().Model(&models.DrugWarehouseOut{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
1048 1048
 
1049
-	err = XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id in(?) and org_id = ? and status = 1 and drug_id = ?", id, orgid, drug_id).Update(map[string]interface{}{"status": 0}).Error
1049
+	err = XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and org_id = ? and status = 1 and drug_id = ?", id, orgid, drug_id).Update(map[string]interface{}{"status": 0}).Error
1050 1050
 
1051
-	err = XTWriteDB().Model(&models.DrugFlow{}).Where("warehouse_out_id in(?) and user_org_id =? and status = 1 and drug_id = ?", id, orgid, drug_id).Update(map[string]interface{}{"status": 0}).Error
1051
+	err = XTWriteDB().Model(&models.DrugFlow{}).Where("warehouse_out_id = ? and user_org_id =? and status = 1 and drug_id = ?", id, orgid, drug_id).Update(map[string]interface{}{"status": 0}).Error
1052 1052
 	return err
1053 1053
 }
1054 1054
 

+ 64 - 18
service/stock_service.go View File

@@ -6329,8 +6329,9 @@ func UpdateGoodByGoodId(good_id int64, sum_count int64, sum_in_count int64, orgi
6329 6329
 
6330 6330
 func GetDrugDetailSummary(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (adviceinfo []*models.BloodHisDoctorAdviceInfo, total int64, err error) {
6331 6331
 
6332
-	db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.execution_state = 1")
6333
-
6332
+	db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
6333
+	table := XTReadDB().Table("xt_base_drug as x d")
6334
+	fmt.Println(table)
6334 6335
 	if startime > 0 {
6335 6336
 		db = db.Where("x.advice_date >= ?", startime)
6336 6337
 	}
@@ -6344,17 +6345,19 @@ func GetDrugDetailSummary(startime int64, endtime int64, keyword string, limit i
6344 6345
 
6345 6346
 	if len(keyword) > 0 {
6346 6347
 		likeKey := "%" + keyword + "%"
6347
-		db = db.Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey).Group("d.id")
6348
+		db = db.Select("x.patient_id,x.user_org_id,x.id,x.advice_date,x.advice_date,x.prescribing_number_unit,x.drug_id").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
6348 6349
 	}
6350
+
6349 6351
 	offset := (page - 1) * limit
6350
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.created_time desc").Group("x.drug_id").Find(&adviceinfo).Error
6352
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.created_time desc").Group("x.drug_id").Scan(&adviceinfo).Error
6351 6353
 	return adviceinfo, total, err
6352 6354
 }
6353 6355
 
6354 6356
 func GetDrugDetailSummaryOne(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (adviceinfo []*models.BloodHisDoctorAdviceInfo, total int64, err error) {
6355 6357
 
6356
-	db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.execution_state = 1")
6357
-
6358
+	db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
6359
+	table := XTReadDB().Table("xt_base_drug as x d")
6360
+	fmt.Println(table)
6358 6361
 	if startime > 0 {
6359 6362
 		db = db.Where("x.advice_date >= ?", startime)
6360 6363
 	}
@@ -6369,10 +6372,10 @@ func GetDrugDetailSummaryOne(startime int64, endtime int64, keyword string, limi
6369 6372
 
6370 6373
 	if len(keyword) > 0 {
6371 6374
 		likeKey := "%" + keyword + "%"
6372
-		db = db.Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey).Group("d.id")
6375
+		db = db.Select("x.patient_id,x.user_org_id,x.id,x.advice_date,x.advice_date,x.prescribing_number_unit,x.drug_id").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
6373 6376
 	}
6374
-	offset := (page - 1) * limit
6375
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.created_time desc").Find(&adviceinfo).Error
6377
+
6378
+	err = db.Order("x.created_time desc").Scan(&adviceinfo).Error
6376 6379
 	return adviceinfo, total, err
6377 6380
 }
6378 6381
 
@@ -6384,8 +6387,9 @@ func GetAllDrugSummary(orgid int64) (drug []*models.BaseDrugLib, err error) {
6384 6387
 
6385 6388
 func GetGoodDetailSummary(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (project []*models.BloodHisPrescriptionProject, total int64, err error) {
6386 6389
 
6387
-	db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1 and x.execution_state = 1 and x.type = 3")
6388
-
6390
+	db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1  and x.type = 3")
6391
+	table := XTReadDB().Table("xt_good_information as d")
6392
+	fmt.Println(table)
6389 6393
 	if startime > 0 {
6390 6394
 		db = db.Where("x.record_date >= ?", startime)
6391 6395
 	}
@@ -6399,17 +6403,19 @@ func GetGoodDetailSummary(startime int64, endtime int64, keyword string, limit i
6399 6403
 
6400 6404
 	if len(keyword) > 0 {
6401 6405
 		likeKey := "%" + keyword + "%"
6402
-		db = db.Joins("left join sgj_xt.xt_good_information as d on d.id = x.drug_id").Where("d.good_name like ?", likeKey).Group("d.id")
6406
+		db = db.Select("x.id,x.project_id,x.user_org_id,x.patient_id,x.record_date").Joins("left join xt_good_information as d on d.id = x.project_id").Where("d.good_name like ?", likeKey).Group("d.id")
6403 6407
 	}
6408
+
6404 6409
 	offset := (page - 1) * limit
6405
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Group("x.project_id").Find(&project).Error
6410
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Group("x.project_id").Scan(&project).Error
6406 6411
 	return project, total, err
6407 6412
 }
6408 6413
 
6409 6414
 func GetGoodDetailSummaryOne(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (project []*models.BloodHisPrescriptionProject, total int64, err error) {
6410 6415
 
6411
-	db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1 and x.execution_state = 1 and x.type = 3")
6412
-
6416
+	db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1 and x.type = 3")
6417
+	table := XTReadDB().Table("xt_good_information as d")
6418
+	fmt.Println(table)
6413 6419
 	if startime > 0 {
6414 6420
 		db = db.Where("x.record_date >= ?", startime)
6415 6421
 	}
@@ -6423,10 +6429,10 @@ func GetGoodDetailSummaryOne(startime int64, endtime int64, keyword string, limi
6423 6429
 
6424 6430
 	if len(keyword) > 0 {
6425 6431
 		likeKey := "%" + keyword + "%"
6426
-		db = db.Joins("left join sgj_xt.xt_good_information as d on d.id = x.drug_id").Where("d.good_name like ?", likeKey).Group("d.id")
6432
+		db = db.Select("x.id,x.project_id,x.user_org_id,x.patient_id,x.record_date").Joins("left join xt_good_information as d on d.id = x.project_id").Where("d.good_name like ? ", likeKey).Group("d.id")
6427 6433
 	}
6428
-	offset := (page - 1) * limit
6429
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Find(&project).Error
6434
+
6435
+	err = db.Order("x.ctime desc").Group("x.id").Scan(&project).Error
6430 6436
 	return project, total, err
6431 6437
 }
6432 6438
 
@@ -6435,3 +6441,43 @@ func GeAllGoodInformation(orgid int64) (good []*models.GoodInfo, err error) {
6435 6441
 	err = XTReadDB().Where("org_id =? and status = 1 and is_user = 1", orgid).Find(&good).Error
6436 6442
 	return good, err
6437 6443
 }
6444
+
6445
+func GetStockSettingIsExsit(orgid int64) (*models.XtStockSetting, error) {
6446
+
6447
+	setting := models.XtStockSetting{}
6448
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
6449
+	if err == gorm.ErrRecordNotFound {
6450
+		return nil, err
6451
+	}
6452
+	if err != nil {
6453
+		return nil, err
6454
+	}
6455
+	return &setting, nil
6456
+}
6457
+
6458
+func CreateStockSetting(setting models.XtStockSetting) error {
6459
+
6460
+	err := XTWriteDB().Create(&setting).Error
6461
+
6462
+	return err
6463
+}
6464
+
6465
+func UpdateStockSetting(orgid int64, setting models.XtStockSetting) error {
6466
+
6467
+	err := XTWriteDB().Model(&models.XtStockSetting{}).Where("user_org_id = ? and status = 1", orgid).Update(map[string]interface{}{"is_type": setting.IsType}).Error
6468
+	return err
6469
+}
6470
+
6471
+func FindStockSettingById(orgid int64) (models.XtStockSetting, error) {
6472
+
6473
+	setting := models.XtStockSetting{}
6474
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
6475
+	return setting, err
6476
+}
6477
+
6478
+func GetAutoStockOutById(good_id, record_date int64, orgid int64, patient_id int64) (models.BloodAutomaticReduceDetail, error) {
6479
+
6480
+	detail := models.BloodAutomaticReduceDetail{}
6481
+	err := XTReadDB().Where("good_id = ? and record_time = ? and org_id = ? and status = 1 and patient_id = ?", good_id, record_date, orgid, patient_id).Find(&detail).Error
6482
+	return detail, err
6483
+}