Procházet zdrojové kódy

11月8日库存管理

XMLWAN před 2 roky
rodič
revize
7df9b87494

+ 3 - 3
controllers/drug_stock_api_contorller.go Zobrazit soubor

@@ -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 {

+ 1 - 0
controllers/his_api_controller.go Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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

+ 2 - 2
controllers/secondary_order_api_contorller.go Zobrazit soubor

@@ -1488,7 +1488,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1488 1488
 			//查询默认仓库
1489 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 1492
 			var sum_count int64
1493 1493
 			var sum_in_count int64
1494 1494
 			for _, it := range list {
@@ -1534,7 +1534,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1534 1534
 
1535 1535
 			//查询默认仓库
1536 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 1538
 			var sum_count int64
1539 1539
 			var sum_in_count int64
1540 1540
 			for _, it := range goodList {

+ 1 - 1
controllers/stock_good_api_controller.go Zobrazit soubor

@@ -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{}{

+ 2 - 2
controllers/stock_in_api_controller.go Zobrazit soubor

@@ -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 {

+ 3 - 0
enums/error_code.go Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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 {

+ 8 - 8
service/secondary_service.go Zobrazit soubor

@@ -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
 

+ 31 - 16
service/stock_service.go Zobrazit soubor

@@ -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").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,11 @@ 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").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 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 6380
 	return adviceinfo, total, err
6377 6381
 }
6378 6382
 
@@ -6384,8 +6388,9 @@ func GetAllDrugSummary(orgid int64) (drug []*models.BaseDrugLib, err error) {
6384 6388
 
6385 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 6394
 	if startime > 0 {
6390 6395
 		db = db.Where("x.record_date >= ?", startime)
6391 6396
 	}
@@ -6399,17 +6404,19 @@ func GetGoodDetailSummary(startime int64, endtime int64, keyword string, limit i
6399 6404
 
6400 6405
 	if len(keyword) > 0 {
6401 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 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 6412
 	return project, total, err
6407 6413
 }
6408 6414
 
6409 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 6420
 	if startime > 0 {
6414 6421
 		db = db.Where("x.record_date >= ?", startime)
6415 6422
 	}
@@ -6423,10 +6430,11 @@ func GetGoodDetailSummaryOne(startime int64, endtime int64, keyword string, limi
6423 6430
 
6424 6431
 	if len(keyword) > 0 {
6425 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 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 6438
 	return project, total, err
6431 6439
 }
6432 6440
 
@@ -6468,3 +6476,10 @@ func FindStockSettingById(orgid int64) (models.XtStockSetting, error) {
6468 6476
 	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
6469 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
+}