csx 3 anni fa
parent
commit
b00973bb67

+ 106 - 0
controllers/his_api_controller.go Vedi File

@@ -327,6 +327,8 @@ func (c *HisApiController) CreateHisPrescription() {
327 327
 
328 328
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
329 329
 
330
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
331
+
330 332
 	if drugStockConfig.IsOpen == 1 {
331 333
 		//校验库存总量
332 334
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
@@ -383,6 +385,53 @@ func (c *HisApiController) CreateHisPrescription() {
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 435
 	info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
387 436
 	var hpInfo models.HisPrescriptionInfo
388 437
 	if info.ID == 0 {
@@ -594,6 +643,7 @@ func (c *HisApiController) CreateHisPrescription() {
594 643
 								return
595 644
 							}
596 645
 							service.CreateHisProjectTwo(&p)
646
+
597 647
 							var randNum int
598 648
 							randNum = rand.Intn(10000) + 1000
599 649
 							timestamp := time.Now().Unix()
@@ -903,10 +953,21 @@ func (c *HisApiController) DeletePrescription() {
903 953
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
904 954
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
905 955
 
956
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
957
+
906 958
 	err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
907 959
 	if err == nil {
908 960
 		if len(projects) > 0 {
909 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 971
 				if item.Type == 3 { //处理透前准备耗材数量数据
911 972
 					consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
912 973
 					if consumables.ID > 0 {
@@ -979,11 +1040,21 @@ func (c *HisApiController) DeleteProject() {
979 1040
 	adminInfo := c.GetAdminUserInfo()
980 1041
 	project, _ := service.GetHisProjectByID(id)
981 1042
 	var consumable models.DialysisBeforePrepare
1043
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
1044
+
982 1045
 	if project.ID > 0 && project.Type == 3 {
983 1046
 		consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
984 1047
 	}
985 1048
 	err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
986 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 1058
 		if consumable.ID > 0 {
988 1059
 			consumable.Count = 0
989 1060
 			service.UpdateConsumables(&consumable)
@@ -1857,6 +1928,41 @@ func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionPro
1857 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 1966
 	return 0
1861 1967
 }
1862 1968
 

+ 104 - 0
controllers/new_mobile_api_controllers/mobile_his_api_controller.go Vedi File

@@ -140,6 +140,7 @@ func (c *MobileHisApiController) DeletePrescription() {
140 140
 	projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
141 141
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
142 142
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
143
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
143 144
 
144 145
 	err := service.DelelteHisPrescription(prescription_id, c.GetMobileAdminUserInfo().Org.Id)
145 146
 	if err == nil {
@@ -152,6 +153,15 @@ func (c *MobileHisApiController) DeletePrescription() {
152 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 167
 		if drugStockConfig.IsOpen == 1 {
@@ -217,8 +227,19 @@ func (c *MobileHisApiController) DeleteProject() {
217 227
 	if project.ID > 0 && project.Type == 3 {
218 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 232
 	err := service.DelelteProject(id, c.GetMobileAdminUserInfo().Org.Id)
221 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 243
 		if consumable.ID > 0 {
223 244
 			consumable.Count = 0
224 245
 			service.UpdateConsumables(&consumable)
@@ -265,6 +286,7 @@ func (c *MobileHisApiController) CreateHisPrescription() {
265 286
 	//校验库存总量
266 287
 
267 288
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
289
+	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetMobileAdminUserInfo().Org.Id)
268 290
 
269 291
 	if drugStockConfig.IsOpen == 1 {
270 292
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
@@ -321,6 +343,51 @@ func (c *MobileHisApiController) CreateHisPrescription() {
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 392
 	info, _ := service.FindPatientPrescriptionInfo(adminInfo.Org.Id, patient_id, recordDateTime, 2)
326 393
 	var hpInfo models.HisPrescriptionInfo
@@ -527,6 +594,7 @@ func (c *MobileHisApiController) CreateHisPrescription() {
527 594
 								return
528 595
 							}
529 596
 							service.CreateHisProjectTwo(&p)
597
+
530 598
 							var randNum int
531 599
 							randNum = rand.Intn(10000) + 1000
532 600
 							timestamp := time.Now().Unix()
@@ -878,6 +946,42 @@ func (c *MobileHisApiController) setProjectWithJSON(project *models.HisPrescript
878 946
 		unit, _ := json["unit"].(string)
879 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 985
 	return 0
882 986
 }
883 987
 func (c *MobileHisApiController) GetHisPatientList() {

+ 1 - 0
models/good_models.go Vedi File

@@ -76,6 +76,7 @@ type GoodInfo struct {
76 76
 	PackingPrice                float64   `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
77 77
 	DefaultCountUnit            string    `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
78 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 82
 func (GoodInfo) TableName() string {

+ 1 - 0
models/stock_models.go Vedi File

@@ -263,6 +263,7 @@ type WarehousingGoodInfo struct {
263 263
 	Manufacturers     Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
264 264
 	Dealers           Dealer       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
265 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 269
 func (WarehousingGoodInfo) TableName() string {

+ 5 - 0
service/his_service.go Vedi File

@@ -1870,3 +1870,8 @@ func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceIn
1870 1870
 	err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
1871 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 Vedi File

@@ -1500,12 +1500,13 @@ func (GoodsType) TableName() string {
1500 1500
 }
1501 1501
 
1502 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 1512
 func (VMGoodInfo) TableName() string {

+ 5 - 0
service/stock_service.go Vedi File

@@ -2726,3 +2726,8 @@ func GetAutoDialysisBefor(goodid int64, goodtypeid int64, patientid int64, orgid
2726 2726
 	}
2727 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
+}