Browse Source

11月8日库存管理

XMLWAN 2 years ago
parent
commit
7df9b87494

+ 3 - 3
controllers/drug_stock_api_contorller.go View File

853
 				//查询默认仓库
853
 				//查询默认仓库
854
 				houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
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
 				var sum_count int64
857
 				var sum_count int64
858
 				var sum_in_count int64
858
 				var sum_in_count int64
859
 				for _, it := range list {
859
 				for _, it := range list {
899
 				//查询默认仓库
899
 				//查询默认仓库
900
 				houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
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
 				var sum_count int64
903
 				var sum_count int64
904
 				var sum_in_count int64
904
 				var sum_in_count int64
905
 				for _, it := range list {
905
 				for _, it := range list {
989
 				//查询默认仓库
989
 				//查询默认仓库
990
 				houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
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
 				var sum_count int64
993
 				var sum_count int64
994
 				var sum_in_count int64
994
 				var sum_in_count int64
995
 				for _, it := range list {
995
 				for _, it := range list {

+ 1 - 0
controllers/his_api_controller.go View File

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

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

90
 
90
 
91
 	scheduals_json_str, _ := redis.Get(key).Result()
91
 	scheduals_json_str, _ := redis.Get(key).Result()
92
 	redis.Set(key, "", time.Second)
92
 	redis.Set(key, "", time.Second)
93
+	patients, _ := service.GetAllPatientListSix(orgID)
93
 	if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
94
 	if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
94
 		scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
95
 		scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
95
 
96
 
98
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
99
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
99
 		} else {
100
 		} else {
100
 			if len(scheduals) > 0 {
101
 			if len(scheduals) > 0 {
101
-				patients, _ := service.GetAllPatientListSix(orgID)
102
+
102
 				devices, _ := service.GetAllDevicetByListSix(orgID)
103
 				devices, _ := service.GetAllDevicetByListSix(orgID)
103
 				advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
104
 				advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
104
 				prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
105
 				prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
4163
 							service.CreateDialysisBeforePrepareOne(&prepare)
4164
 							service.CreateDialysisBeforePrepareOne(&prepare)
4164
 							//查询默认仓库
4165
 							//查询默认仓库
4165
 							houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
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
 							var sum_count int64
4168
 							var sum_count int64
4168
 							var sum_in_count int64
4169
 							var sum_in_count int64
4169
 							for _, it := range goodList {
4170
 							for _, it := range goodList {
4314
 					service.CreateDialysisBeforePrepareOne(&prepare)
4315
 					service.CreateDialysisBeforePrepareOne(&prepare)
4315
 					//查询默认仓库
4316
 					//查询默认仓库
4316
 					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
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
 					var sum_count int64
4319
 					var sum_count int64
4319
 					var sum_in_count int64
4320
 					var sum_in_count int64
4320
 					for _, it := range goodList {
4321
 					for _, it := range goodList {
4357
 					service.CreateDialysisBeforePrepareOne(&prepare)
4358
 					service.CreateDialysisBeforePrepareOne(&prepare)
4358
 					//查询默认仓库
4359
 					//查询默认仓库
4359
 					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
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
 					var sum_count int64
4362
 					var sum_count int64
4362
 					var sum_in_count int64
4363
 					var sum_in_count int64
4363
 					for _, it := range goodList {
4364
 					for _, it := range goodList {
4875
 
4876
 
4876
 	//出库逻辑
4877
 	//出库逻辑
4877
 	err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
4878
 	err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
4879
+
4878
 	if err != nil {
4880
 	if err != nil {
4879
 		utils.ErrorLog(err.Error())
4881
 		utils.ErrorLog(err.Error())
4880
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4882
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4905
 
4907
 
4906
 		//查询默认仓库
4908
 		//查询默认仓库
4907
 		houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
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
 		var sum_count int64
4911
 		var sum_count int64
4910
 		var sum_in_count int64
4912
 		var sum_in_count int64
4911
 		for _, it := range goodList {
4913
 		for _, it := range goodList {
4912
 			sum_count += it.StockCount
4914
 			sum_count += it.StockCount
4913
 			sum_in_count += it.WarehousingCount
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
 
3855
 
3856
 			err = service.DeleteDoctorAdviceByGroupNo(&advice)
3856
 			err = service.DeleteDoctorAdviceByGroupNo(&advice)
3857
 			key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
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
 			redis.Set(key, "", time.Second)
3859
 			redis.Set(key, "", time.Second)
3861
 
3860
 
3870
 			key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
3869
 			key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
3871
 
3870
 
3872
 			redis.Set(key, "", time.Second)
3871
 			redis.Set(key, "", time.Second)
3873
-			fmt.Println("key2332323223323232323232323", key)
3872
+
3874
 			keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
3873
 			keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
3875
-			fmt.Println("key2332323223323232323232323", keyTwo)
3874
+
3876
 			redis.Set(keyTwo, "", time.Second)
3875
 			redis.Set(keyTwo, "", time.Second)
3877
 			keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
3876
 			keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
3878
 			redis.Set(keyThree, "", time.Second)
3877
 			redis.Set(keyThree, "", time.Second)
4009
 	adminInfo := c.GetMobileAdminUserInfo()
4008
 	adminInfo := c.GetMobileAdminUserInfo()
4010
 
4009
 
4011
 	project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
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
 	if project.ExecutionState == 1 {
4057
 	if project.ExecutionState == 1 {
4013
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
4058
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
4014
 		return
4059
 		return

+ 2 - 2
controllers/secondary_order_api_contorller.go View File

1488
 			//查询默认仓库
1488
 			//查询默认仓库
1489
 			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1489
 			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1490
 			//查询默认仓库剩余多少库存
1490
 			//查询默认仓库剩余多少库存
1491
-			list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseInfo, orgId, item.ProjectId)
1491
+			list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, orgId, item.ProjectId)
1492
 			var sum_count int64
1492
 			var sum_count int64
1493
 			var sum_in_count int64
1493
 			var sum_in_count int64
1494
 			for _, it := range list {
1494
 			for _, it := range list {
1534
 
1534
 
1535
 			//查询默认仓库
1535
 			//查询默认仓库
1536
 			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1536
 			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1537
-			goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseInfo, item.ProjectId, item.UserOrgId)
1537
+			goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.UserOrgId)
1538
 			var sum_count int64
1538
 			var sum_count int64
1539
 			var sum_in_count int64
1539
 			var sum_in_count int64
1540
 			for _, it := range goodList {
1540
 			for _, it := range goodList {

+ 1 - 1
controllers/stock_good_api_controller.go View File

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

+ 2 - 2
controllers/stock_in_api_controller.go View File

783
 				//查询该机构默认仓库
783
 				//查询该机构默认仓库
784
 				storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
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
 				var sum_count int64
787
 				var sum_count int64
788
 				var sum_in_count int64
788
 				var sum_in_count int64
789
 				for _, item := range goodList {
789
 				for _, item := range goodList {
823
 				//查询该机构默认仓库
823
 				//查询该机构默认仓库
824
 				storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
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
 				var sum_count int64
827
 				var sum_count int64
828
 				var sum_in_count int64
828
 				var sum_in_count int64
829
 				for _, item := range goodList {
829
 				for _, item := range goodList {

+ 3 - 0
enums/error_code.go View File

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

+ 1 - 0
models/patient_models.go View File

22
 	Name               string `gorm:"column:name" json:"name" form:"name"`
22
 	Name               string `gorm:"column:name" json:"name" form:"name"`
23
 	IdCardNo           string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
23
 	IdCardNo           string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
24
 	UserSysBeforeCount int64  `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
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
 func (MSchedualPatientList) TableName() string {
28
 func (MSchedualPatientList) TableName() string {

+ 8 - 8
service/secondary_service.go View File

980
 
980
 
981
 	err := XTWriteDB().Model(&models.Warehousing{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
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
 	return err
986
 	return err
987
 }
987
 }
988
 
988
 
996
 func ModifyWarehouseOut(id int64, orgid int64, good_id int64) error {
996
 func ModifyWarehouseOut(id int64, orgid int64, good_id int64) error {
997
 	err := XTWriteDB().Model(&models.WarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"status": 0}).Error
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
 	return err
1002
 	return err
1003
 }
1003
 }
1004
 
1004
 
1030
 
1030
 
1031
 	err := XTWriteDB().Model(&models.DrugWarehouse{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
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
 	return err
1036
 	return err
1037
 }
1037
 }
1038
 
1038
 
1046
 func DeleteStoreWarehouseOut(id int64, orgid int64, drug_id int64) error {
1046
 func DeleteStoreWarehouseOut(id int64, orgid int64, drug_id int64) error {
1047
 	err := XTWriteDB().Model(&models.DrugWarehouseOut{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
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
 	return err
1052
 	return err
1053
 }
1053
 }
1054
 
1054
 

+ 31 - 16
service/stock_service.go View File

6329
 
6329
 
6330
 func GetDrugDetailSummary(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (adviceinfo []*models.BloodHisDoctorAdviceInfo, total int64, err error) {
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
 	if startime > 0 {
6335
 	if startime > 0 {
6335
 		db = db.Where("x.advice_date >= ?", startime)
6336
 		db = db.Where("x.advice_date >= ?", startime)
6336
 	}
6337
 	}
6344
 
6345
 
6345
 	if len(keyword) > 0 {
6346
 	if len(keyword) > 0 {
6346
 		likeKey := "%" + keyword + "%"
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").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
 	offset := (page - 1) * limit
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
 	return adviceinfo, total, err
6353
 	return adviceinfo, total, err
6352
 }
6354
 }
6353
 
6355
 
6354
 func GetDrugDetailSummaryOne(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (adviceinfo []*models.BloodHisDoctorAdviceInfo, total int64, err error) {
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
 	if startime > 0 {
6361
 	if startime > 0 {
6359
 		db = db.Where("x.advice_date >= ?", startime)
6362
 		db = db.Where("x.advice_date >= ?", startime)
6360
 	}
6363
 	}
6369
 
6372
 
6370
 	if len(keyword) > 0 {
6373
 	if len(keyword) > 0 {
6371
 		likeKey := "%" + keyword + "%"
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").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
6373
 	}
6376
 	}
6377
+
6374
 	offset := (page - 1) * limit
6378
 	offset := (page - 1) * limit
6375
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.created_time desc").Find(&adviceinfo).Error
6379
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.created_time desc").Scan(&adviceinfo).Error
6376
 	return adviceinfo, total, err
6380
 	return adviceinfo, total, err
6377
 }
6381
 }
6378
 
6382
 
6384
 
6388
 
6385
 func GetGoodDetailSummary(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (project []*models.BloodHisPrescriptionProject, total int64, err error) {
6389
 func GetGoodDetailSummary(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (project []*models.BloodHisPrescriptionProject, total int64, err error) {
6386
 
6390
 
6387
-	db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1 and x.execution_state = 1 and x.type = 3")
6388
-
6391
+	db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1  and x.type = 3")
6392
+	table := XTReadDB().Table("xt_good_information as d")
6393
+	fmt.Println(table)
6389
 	if startime > 0 {
6394
 	if startime > 0 {
6390
 		db = db.Where("x.record_date >= ?", startime)
6395
 		db = db.Where("x.record_date >= ?", startime)
6391
 	}
6396
 	}
6399
 
6404
 
6400
 	if len(keyword) > 0 {
6405
 	if len(keyword) > 0 {
6401
 		likeKey := "%" + keyword + "%"
6406
 		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")
6407
+		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)
6403
 	}
6408
 	}
6409
+
6404
 	offset := (page - 1) * limit
6410
 	offset := (page - 1) * limit
6405
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Group("x.project_id").Find(&project).Error
6411
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Group("x.project_id").Scan(&project).Error
6406
 	return project, total, err
6412
 	return project, total, err
6407
 }
6413
 }
6408
 
6414
 
6409
 func GetGoodDetailSummaryOne(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (project []*models.BloodHisPrescriptionProject, total int64, err error) {
6415
 func GetGoodDetailSummaryOne(startime int64, endtime int64, keyword string, limit int64, page int64, orgid int64) (project []*models.BloodHisPrescriptionProject, total int64, err error) {
6410
 
6416
 
6411
-	db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1 and x.execution_state = 1 and x.type = 3")
6412
-
6417
+	db := XTReadDB().Table("his_prescription_project as x").Where("x.status = 1 and x.type = 3")
6418
+	table := XTReadDB().Table("xt_good_information as d")
6419
+	fmt.Println(table)
6413
 	if startime > 0 {
6420
 	if startime > 0 {
6414
 		db = db.Where("x.record_date >= ?", startime)
6421
 		db = db.Where("x.record_date >= ?", startime)
6415
 	}
6422
 	}
6423
 
6430
 
6424
 	if len(keyword) > 0 {
6431
 	if len(keyword) > 0 {
6425
 		likeKey := "%" + keyword + "%"
6432
 		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")
6433
+		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)
6427
 	}
6434
 	}
6435
+
6428
 	offset := (page - 1) * limit
6436
 	offset := (page - 1) * limit
6429
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Find(&project).Error
6437
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Group("x.id").Scan(&project).Error
6430
 	return project, total, err
6438
 	return project, total, err
6431
 }
6439
 }
6432
 
6440
 
6468
 	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
6476
 	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
6469
 	return setting, err
6477
 	return setting, err
6470
 }
6478
 }
6479
+
6480
+func GetAutoStockOutById(good_id, record_date int64, orgid int64, patient_id int64) (models.BloodAutomaticReduceDetail, error) {
6481
+
6482
+	detail := models.BloodAutomaticReduceDetail{}
6483
+	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
6484
+	return detail, err
6485
+}