csx преди 3 години
родител
ревизия
b00973bb67

+ 106 - 0
controllers/his_api_controller.go Целия файл

327
 
327
 
328
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
328
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
329
 
329
 
330
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
331
+
330
 	if drugStockConfig.IsOpen == 1 {
332
 	if drugStockConfig.IsOpen == 1 {
331
 		//校验库存总量
333
 		//校验库存总量
332
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
334
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
383
 			}
385
 			}
384
 		}
386
 		}
385
 	}
387
 	}
388
+
389
+	if stockConfig.IsOpen == 1 {
390
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
391
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
392
+			if len(prescriptions) > 0 {
393
+				for _, item := range prescriptions {
394
+					items := item.(map[string]interface{})
395
+					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
396
+						projects := items["project"].([]interface{})
397
+						if len(projects) > 0 {
398
+							for _, project := range projects {
399
+								var project_id int64
400
+								var project_type int64
401
+								var totals float64
402
+								if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
403
+									project_id = int64(project.(map[string]interface{})["id"].(float64))
404
+								}
405
+								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
406
+									project_type = int64(project.(map[string]interface{})["type"].(float64))
407
+								}
408
+								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
409
+									total, _ := project.(map[string]interface{})["total"].(string)
410
+
411
+									totals, _ = strconv.ParseFloat(total, 64)
412
+								}
413
+								if project_type == 3 {
414
+									good, _ := service.FindGoodInfoByIdTwo(project_id)
415
+									if good.ID == 0 {
416
+										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
417
+										return
418
+									}
419
+									if totals > good.Total {
420
+										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
421
+										return
422
+									}
423
+
424
+								}
425
+
426
+							}
427
+						}
428
+					}
429
+				}
430
+			}
431
+		}
432
+
433
+	}
434
+
386
 	info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
435
 	info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
387
 	var hpInfo models.HisPrescriptionInfo
436
 	var hpInfo models.HisPrescriptionInfo
388
 	if info.ID == 0 {
437
 	if info.ID == 0 {
594
 								return
643
 								return
595
 							}
644
 							}
596
 							service.CreateHisProjectTwo(&p)
645
 							service.CreateHisProjectTwo(&p)
646
+
597
 							var randNum int
647
 							var randNum int
598
 							randNum = rand.Intn(10000) + 1000
648
 							randNum = rand.Intn(10000) + 1000
599
 							timestamp := time.Now().Unix()
649
 							timestamp := time.Now().Unix()
903
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
953
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
904
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
954
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
905
 
955
 
956
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
957
+
906
 	err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
958
 	err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
907
 	if err == nil {
959
 	if err == nil {
908
 		if len(projects) > 0 {
960
 		if len(projects) > 0 {
909
 			for _, item := range projects {
961
 			for _, item := range projects {
962
+				if stockConfig.IsOpen == 1 {
963
+					if item.Type == 3 {
964
+						good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
965
+						f_count, _ := strconv.ParseFloat(strconv.FormatInt(item.Count, 10), 64)
966
+						good.Total = good.Total + f_count
967
+						service.UpdateGoodInfo(&good)
968
+					}
969
+				}
970
+
910
 				if item.Type == 3 { //处理透前准备耗材数量数据
971
 				if item.Type == 3 { //处理透前准备耗材数量数据
911
 					consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
972
 					consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
912
 					if consumables.ID > 0 {
973
 					if consumables.ID > 0 {
979
 	adminInfo := c.GetAdminUserInfo()
1040
 	adminInfo := c.GetAdminUserInfo()
980
 	project, _ := service.GetHisProjectByID(id)
1041
 	project, _ := service.GetHisProjectByID(id)
981
 	var consumable models.DialysisBeforePrepare
1042
 	var consumable models.DialysisBeforePrepare
1043
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
1044
+
982
 	if project.ID > 0 && project.Type == 3 {
1045
 	if project.ID > 0 && project.Type == 3 {
983
 		consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
1046
 		consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
984
 	}
1047
 	}
985
 	err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
1048
 	err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
986
 	if err == nil {
1049
 	if err == nil {
1050
+		if stockConfig.IsOpen == 1 {
1051
+			if project.Type == 3 {
1052
+				good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
1053
+				f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
1054
+				good.Total = good.Total + f_count
1055
+				service.UpdateGoodInfo(&good)
1056
+			}
1057
+		}
987
 		if consumable.ID > 0 {
1058
 		if consumable.ID > 0 {
988
 			consumable.Count = 0
1059
 			consumable.Count = 0
989
 			service.UpdateConsumables(&consumable)
1060
 			service.UpdateConsumables(&consumable)
1857
 		project.Unit = unit
1928
 		project.Unit = unit
1858
 	}
1929
 	}
1859
 
1930
 
1931
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
1932
+
1933
+	if project.ID == 0 {
1934
+		if stockConfig.IsOpen == 1 {
1935
+			if project.Type == 3 {
1936
+				good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
1937
+				f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
1938
+				good.Total = good.Total - f_count
1939
+				service.UpdateGoodInfo(&good)
1940
+			}
1941
+		}
1942
+
1943
+	} else {
1944
+		temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
1945
+
1946
+		if stockConfig.IsOpen == 1 {
1947
+			if project.Type == 3 {
1948
+				good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
1949
+				if project.Count < temp_project.Count {
1950
+					other_count := temp_project.Count - project.Count
1951
+					other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
1952
+					good.Total = good.Total + other_count_two
1953
+					service.UpdateGoodInfo(&good)
1954
+				} else if project.Count > temp_project.Count {
1955
+					other_count := project.Count - temp_project.Count
1956
+					other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
1957
+					good.Total = good.Total - other_count_two
1958
+					service.UpdateGoodInfo(&good)
1959
+				}
1960
+
1961
+			}
1962
+		}
1963
+
1964
+	}
1965
+
1860
 	return 0
1966
 	return 0
1861
 }
1967
 }
1862
 
1968
 

+ 104 - 0
controllers/new_mobile_api_controllers/mobile_his_api_controller.go Целия файл

140
 	projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
140
 	projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
141
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
141
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
142
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
142
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
143
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
143
 
144
 
144
 	err := service.DelelteHisPrescription(prescription_id, c.GetMobileAdminUserInfo().Org.Id)
145
 	err := service.DelelteHisPrescription(prescription_id, c.GetMobileAdminUserInfo().Org.Id)
145
 	if err == nil {
146
 	if err == nil {
152
 						service.UpdateConsumables(&consumables)
153
 						service.UpdateConsumables(&consumables)
153
 					}
154
 					}
154
 				}
155
 				}
156
+
157
+				if stockConfig.IsOpen == 1 {
158
+					if item.Type == 3 {
159
+						good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
160
+						f_count, _ := strconv.ParseFloat(strconv.FormatInt(item.Count, 10), 64)
161
+						good.Total = good.Total + f_count
162
+						service.UpdateGoodInfo(&good)
163
+					}
164
+				}
155
 			}
165
 			}
156
 		}
166
 		}
157
 		if drugStockConfig.IsOpen == 1 {
167
 		if drugStockConfig.IsOpen == 1 {
217
 	if project.ID > 0 && project.Type == 3 {
227
 	if project.ID > 0 && project.Type == 3 {
218
 		consumable, _ = service.FindHisConsumablesByID(adminInfo.Org.Id, project.PatientId, project.RecordDate, project.ProjectId)
228
 		consumable, _ = service.FindHisConsumablesByID(adminInfo.Org.Id, project.PatientId, project.RecordDate, project.ProjectId)
219
 	}
229
 	}
230
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
231
+
220
 	err := service.DelelteProject(id, c.GetMobileAdminUserInfo().Org.Id)
232
 	err := service.DelelteProject(id, c.GetMobileAdminUserInfo().Org.Id)
221
 	if err == nil {
233
 	if err == nil {
234
+		if stockConfig.IsOpen == 1 {
235
+			if project.Type == 3 {
236
+				good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
237
+				f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
238
+				good.Total = good.Total + f_count
239
+				service.UpdateGoodInfo(&good)
240
+			}
241
+		}
242
+
222
 		if consumable.ID > 0 {
243
 		if consumable.ID > 0 {
223
 			consumable.Count = 0
244
 			consumable.Count = 0
224
 			service.UpdateConsumables(&consumable)
245
 			service.UpdateConsumables(&consumable)
265
 	//校验库存总量
286
 	//校验库存总量
266
 
287
 
267
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
288
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
289
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
268
 
290
 
269
 	if drugStockConfig.IsOpen == 1 {
291
 	if drugStockConfig.IsOpen == 1 {
270
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
292
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
321
 			}
343
 			}
322
 		}
344
 		}
323
 	}
345
 	}
346
+	if stockConfig.IsOpen == 1 {
347
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
348
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
349
+			if len(prescriptions) > 0 {
350
+				for _, item := range prescriptions {
351
+					items := item.(map[string]interface{})
352
+					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
353
+						projects := items["project"].([]interface{})
354
+						if len(projects) > 0 {
355
+							for _, project := range projects {
356
+								var project_id int64
357
+								var project_type int64
358
+								var totals float64
359
+								if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
360
+									project_id = int64(project.(map[string]interface{})["id"].(float64))
361
+								}
362
+								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
363
+									project_type = int64(project.(map[string]interface{})["type"].(float64))
364
+								}
365
+								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
366
+									total, _ := project.(map[string]interface{})["total"].(string)
367
+
368
+									totals, _ = strconv.ParseFloat(total, 64)
369
+								}
370
+								if project_type == 3 {
371
+									good, _ := service.FindGoodInfoByIdTwo(project_id)
372
+									if good.ID == 0 {
373
+										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
374
+										return
375
+									}
376
+									if totals > good.Total {
377
+										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
378
+										return
379
+									}
380
+
381
+								}
382
+
383
+							}
384
+						}
385
+					}
386
+				}
387
+			}
388
+		}
389
+
390
+	}
324
 
391
 
325
 	info, _ := service.FindPatientPrescriptionInfo(adminInfo.Org.Id, patient_id, recordDateTime, 2)
392
 	info, _ := service.FindPatientPrescriptionInfo(adminInfo.Org.Id, patient_id, recordDateTime, 2)
326
 	var hpInfo models.HisPrescriptionInfo
393
 	var hpInfo models.HisPrescriptionInfo
527
 								return
594
 								return
528
 							}
595
 							}
529
 							service.CreateHisProjectTwo(&p)
596
 							service.CreateHisProjectTwo(&p)
597
+
530
 							var randNum int
598
 							var randNum int
531
 							randNum = rand.Intn(10000) + 1000
599
 							randNum = rand.Intn(10000) + 1000
532
 							timestamp := time.Now().Unix()
600
 							timestamp := time.Now().Unix()
878
 		unit, _ := json["unit"].(string)
946
 		unit, _ := json["unit"].(string)
879
 		project.Unit = unit
947
 		project.Unit = unit
880
 	}
948
 	}
949
+
950
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
951
+
952
+	if project.ID == 0 {
953
+		if stockConfig.IsOpen == 1 {
954
+			if project.Type == 3 {
955
+				good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
956
+				f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
957
+				good.Total = good.Total - f_count
958
+				service.UpdateGoodInfo(&good)
959
+			}
960
+		}
961
+
962
+	} else {
963
+		temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
964
+
965
+		if stockConfig.IsOpen == 1 {
966
+			if project.Type == 3 {
967
+				good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
968
+				if project.Count < temp_project.Count {
969
+					other_count := temp_project.Count - project.Count
970
+					other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
971
+					good.Total = good.Total + other_count_two
972
+					service.UpdateGoodInfo(&good)
973
+				} else if project.Count > temp_project.Count {
974
+					other_count := project.Count - temp_project.Count
975
+					other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
976
+					good.Total = good.Total - other_count_two
977
+					service.UpdateGoodInfo(&good)
978
+				}
979
+
980
+			}
981
+		}
982
+
983
+	}
984
+
881
 	return 0
985
 	return 0
882
 }
986
 }
883
 func (c *MobileHisApiController) GetHisPatientList() {
987
 func (c *MobileHisApiController) GetHisPatientList() {

+ 1 - 0
models/good_models.go Целия файл

76
 	PackingPrice                float64   `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
76
 	PackingPrice                float64   `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
77
 	DefaultCountUnit            string    `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
77
 	DefaultCountUnit            string    `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
78
 	MinUnit                     string    `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
78
 	MinUnit                     string    `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
79
+	Total                       float64   `gorm:"column:total" json:"total" form:"total"`
79
 }
80
 }
80
 
81
 
81
 func (GoodInfo) TableName() string {
82
 func (GoodInfo) TableName() string {

+ 1 - 0
models/stock_models.go Целия файл

263
 	Manufacturers     Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
263
 	Manufacturers     Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
264
 	Dealers           Dealer       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
264
 	Dealers           Dealer       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
265
 	BuyPrice          float64      `gorm:"column:buy_price" json:"buy_price"`
265
 	BuyPrice          float64      `gorm:"column:buy_price" json:"buy_price"`
266
+	Total             float64      `gorm:"column:total" json:"total" form:"total"`
266
 }
267
 }
267
 
268
 
268
 func (WarehousingGoodInfo) TableName() string {
269
 func (WarehousingGoodInfo) TableName() string {

+ 5 - 0
service/his_service.go Целия файл

1870
 	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
1870
 	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
1871
 	return
1871
 	return
1872
 }
1872
 }
1873
+
1874
+func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
1875
+	err = writeDb.Save(&good_info).Error
1876
+	return
1877
+}

+ 7 - 6
service/mobile_dialysis_service.go Целия файл

1500
 }
1500
 }
1501
 
1501
 
1502
 type VMGoodInfo struct {
1502
 type VMGoodInfo struct {
1503
-	ID                int64  `gorm:"column:id" json:"id"`
1504
-	SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
1505
-	GoodTypeId        int64  `gorm:"column:good_type_id" json:"good_type_id"`
1506
-	OrgId             int64  `gorm:"column:org_id" json:"org_id"`
1507
-	GoodName          string `gorm:"column:good_name" json:"good_name" form:"good_name"`
1508
-	GoodUnit          int64  `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
1503
+	ID                int64   `gorm:"column:id" json:"id"`
1504
+	SpecificationName string  `gorm:"column:specification_name" json:"specification_name"`
1505
+	GoodTypeId        int64   `gorm:"column:good_type_id" json:"good_type_id"`
1506
+	OrgId             int64   `gorm:"column:org_id" json:"org_id"`
1507
+	GoodName          string  `gorm:"column:good_name" json:"good_name" form:"good_name"`
1508
+	GoodUnit          int64   `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
1509
+	Total             float64 `gorm:"column:total" json:"total" form:"total"`
1509
 }
1510
 }
1510
 
1511
 
1511
 func (VMGoodInfo) TableName() string {
1512
 func (VMGoodInfo) TableName() string {

+ 5 - 0
service/stock_service.go Целия файл

2726
 	}
2726
 	}
2727
 	return &autoreduece, nil
2727
 	return &autoreduece, nil
2728
 }
2728
 }
2729
+
2730
+func FindGoodInfoByIdTwo(id int64) (goodInfo models.GoodInfo, err error) {
2731
+	err = readDb.Model(&models.GoodInfo{}).Where("id = ? AND status = 1", id).First(&goodInfo).Error
2732
+	return
2733
+}