mainqaq 2 лет назад
Родитель
Сommit
6a2f34bb86
2 измененных файлов: 93 добавлений и 3 удалений
  1. 1 0
      models/self_drug_models.go
  2. 92 3
      service/stock_service.go

+ 1 - 0
models/self_drug_models.go Просмотреть файл

645
 	LastPrice        string  `json:"last_price"`
645
 	LastPrice        string  `json:"last_price"`
646
 	PackingUnit      string  `json:"packing_unit"`
646
 	PackingUnit      string  `json:"packing_unit"`
647
 	Dosage           int64   `json:"dosage"`
647
 	Dosage           int64   `json:"dosage"`
648
+	LimaxUnit        string  `json:"limax_unit"`
648
 }
649
 }
649
 
650
 
650
 type VmDrugWarehouseOutInfo struct {
651
 type VmDrugWarehouseOutInfo struct {

+ 92 - 3
service/stock_service.go Просмотреть файл

728
 	return err
728
 	return err
729
 }
729
 }
730
 
730
 
731
+//func CreateDrugFlowOneTX(flow models.DrugFlow,tx *gorm.DB) error {
732
+//	err := tx.Create(&flow).Error
733
+//	return err
734
+//}
735
+
731
 func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64) (models.DrugAutomaticReduceDetail, error) {
736
 func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64) (models.DrugAutomaticReduceDetail, error) {
732
 
737
 
733
 	detail := models.DrugAutomaticReduceDetail{}
738
 	detail := models.DrugAutomaticReduceDetail{}
1150
 	if org_id > 0 {
1155
 	if org_id > 0 {
1151
 		db = db.Where("x.org_id = ?", org_id)
1156
 		db = db.Where("x.org_id = ?", org_id)
1152
 	}
1157
 	}
1153
-	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,x.manufacturer,x.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
1158
+	err = db.Select("x.id,x.max_unit as limax_unit,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,x.manufacturer,x.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
1154
 	return list, err
1159
 	return list, err
1155
 }
1160
 }
1156
 
1161
 
1292
 func FindAllDrugCancelStockTotal(org_id int64) (total int64, err error) {
1297
 func FindAllDrugCancelStockTotal(org_id int64) (total int64, err error) {
1293
 	err = readDb.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
1298
 	err = readDb.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
1294
 	return total, err
1299
 	return total, err
1295
-
1296
 }
1300
 }
1297
 
1301
 
1302
+//func FindAllDrugCancelStockTotalTX(org_id int64,tx *gorm.DB) (total int64, err error) {
1303
+//	err = tx.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
1304
+//	return total, err
1305
+//}
1306
+
1298
 func FindAllReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.SalesReturn, total int64, err error) {
1307
 func FindAllReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.SalesReturn, total int64, err error) {
1299
 	db := readDb.Model(&models.SalesReturn{})
1308
 	db := readDb.Model(&models.SalesReturn{})
1300
 	db = db.Where("xt_sales_return.org_id = ? AND xt_sales_return.status = 1 AND xt_sales_return.type = ?", orgId, types)
1309
 	db = db.Where("xt_sales_return.org_id = ? AND xt_sales_return.status = 1 AND xt_sales_return.type = ?", orgId, types)
1806
 	return stock, err
1815
 	return stock, err
1807
 }
1816
 }
1808
 
1817
 
1818
+//func GetLastDrugCancelStockByIdTX(orgid int64,tx *gorm.DB) (models.DrugCancelStock, error) {
1819
+//	stock := models.DrugCancelStock{}
1820
+//	err := tx.Where("org_id = ? and status = 1", orgid).Last(&stock).Error
1821
+//	return stock, err
1822
+//}
1823
+
1809
 func GetManufactureById(id int64) (models.Manufacturer, error) {
1824
 func GetManufactureById(id int64) (models.Manufacturer, error) {
1810
 	manufacturer := models.Manufacturer{}
1825
 	manufacturer := models.Manufacturer{}
1811
 	err := XTReadDB().Model(&manufacturer).Where("id = ? and status = 1", id).Find(&manufacturer).Error
1826
 	err := XTReadDB().Model(&manufacturer).Where("id = ? and status = 1", id).Find(&manufacturer).Error
1821
 func AddSigleDrugCancelStock(cancelStock *models.DrugCancelStock) error {
1836
 func AddSigleDrugCancelStock(cancelStock *models.DrugCancelStock) error {
1822
 	err := writeDb.Create(&cancelStock).Error
1837
 	err := writeDb.Create(&cancelStock).Error
1823
 	return err
1838
 	return err
1824
-
1825
 }
1839
 }
1826
 
1840
 
1841
+//func AddSigleDrugCancelStockTX(cancelStock *models.DrugCancelStock,tx *gorm.DB) error {
1842
+//	err := tx.Create(&cancelStock).Error
1843
+//	return err
1844
+//}
1845
+
1827
 func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error) {
1846
 func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error) {
1828
 	if len(cancelStockInfo) > 0 {
1847
 	if len(cancelStockInfo) > 0 {
1829
 		utx := writeDb.Begin()
1848
 		utx := writeDb.Begin()
1873
 	return err
1892
 	return err
1874
 }
1893
 }
1875
 
1894
 
1895
+//func CreateCancelStockInfoTwoTX(info *models.DrugCancelStockInfo,tx *gorm.DB) error {
1896
+//	err := tx.Create(&info).Error
1897
+//	return err
1898
+//}
1899
+
1876
 func GetLastStockInfoThree(drugid int64) (models.DrugCancelStockInfo, error) {
1900
 func GetLastStockInfoThree(drugid int64) (models.DrugCancelStockInfo, error) {
1877
 
1901
 
1878
 	info := models.DrugCancelStockInfo{}
1902
 	info := models.DrugCancelStockInfo{}
1881
 	return info, err
1905
 	return info, err
1882
 }
1906
 }
1883
 
1907
 
1908
+//func GetLastStockInfoThreeTX(drugid int64,tx *gorm.DB) (models.DrugCancelStockInfo, error) {
1909
+//	info := models.DrugCancelStockInfo{}
1910
+//	err := tx.Model(&info).Where("drug_id = ? and status = 1", drugid).Find(&info).Error
1911
+//	return info, err
1912
+//}
1913
+
1884
 func CreateCancelStockInfoOne(info *models.CancelStockInfo) error {
1914
 func CreateCancelStockInfoOne(info *models.CancelStockInfo) error {
1885
 
1915
 
1886
 	err := XTWriteDB().Create(&info).Error
1916
 	err := XTWriteDB().Create(&info).Error
3489
 	return list, err
3519
 	return list, err
3490
 }
3520
 }
3491
 
3521
 
3522
+//func GetAllManufacturerListTX(orgid int64,tx *gorm.DB) (list []*models.Manufacturer, err error) {
3523
+//
3524
+//	err = tx.Where("org_id = ? and status = 1", orgid).Find(&list).Error
3525
+//	return list, err
3526
+//}
3527
+
3492
 func GetAllDealerList(orgid int64) (list []*models.Dealer, err error) {
3528
 func GetAllDealerList(orgid int64) (list []*models.Dealer, err error) {
3493
 
3529
 
3494
 	err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&list).Error
3530
 	err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&list).Error
3495
 	return list, err
3531
 	return list, err
3496
 }
3532
 }
3533
+
3534
+//func GetAllDealerListTX(orgid int64,tx *gorm.DB) (list []*models.Dealer, err error) {
3535
+//	err = tx.Where("org_id = ? and status = 1", orgid).Find(&list).Error
3536
+//	return list, err
3537
+//}
3497
 func GetDealerByName(orgid int64, name string) (*models.Dealer, error) {
3538
 func GetDealerByName(orgid int64, name string) (*models.Dealer, error) {
3498
 	var dealer models.Dealer
3539
 	var dealer models.Dealer
3499
 	var err error
3540
 	var err error
5101
 	return info, err
5142
 	return info, err
5102
 }
5143
 }
5103
 
5144
 
5145
+//func GetDrugWarehouseInfoTX(id int64,tx *gorm.DB) (models.XtDrugWarehouseInfo, error) {
5146
+//	info := models.XtDrugWarehouseInfo{}
5147
+//	db := tx.Model(&info).Where("status = 1")
5148
+//	if id > 0 {
5149
+//		db = db.Where("id = ?", id)
5150
+//	}
5151
+//	err := db.Select("drug_id,warehousing_count,stock_max_number,stock_min_number").Find(&info).Error
5152
+//	return info, err
5153
+//}
5154
+
5104
 func GetDrugWarehouseInfoPrescription(drugid int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
5155
 func GetDrugWarehouseInfoPrescription(drugid int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
5105
 
5156
 
5106
 	err = XTReadDB().Where("drug_id = ? and org_id =? and status = 1", drugid, orgid).Find(&info).Error
5157
 	err = XTReadDB().Where("drug_id = ? and org_id =? and status = 1", drugid, orgid).Find(&info).Error
5181
 	return err
5232
 	return err
5182
 }
5233
 }
5183
 
5234
 
5235
+//func UpdateDrugWarehouseInfoTX(info *models.XtDrugWarehouseInfo, id int64,tx *gorm.DB) error {
5236
+//	err = tx.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
5237
+//	return err
5238
+//}
5239
+
5184
 func UpdateDrugWarehouseInfoOne(info *models.XtDrugWarehouseInfo, id int64) error {
5240
 func UpdateDrugWarehouseInfoOne(info *models.XtDrugWarehouseInfo, id int64) error {
5185
 
5241
 
5186
 	//err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_min_number": info.StockMaxNumber}).Error
5242
 	//err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_min_number": info.StockMaxNumber}).Error
5190
 	return err
5246
 	return err
5191
 }
5247
 }
5192
 
5248
 
5249
+//func UpdateDrugWarehouseInfoOneTX(info *models.XtDrugWarehouseInfo, id int64,tx *gorm.DB) error {
5250
+//	err = tx.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
5251
+//	return err
5252
+//}
5253
+
5193
 func GetLastCancelStockInfo(id int64) (models.DrugCancelStockInfo, error) {
5254
 func GetLastCancelStockInfo(id int64) (models.DrugCancelStockInfo, error) {
5194
 
5255
 
5195
 	info := models.DrugCancelStockInfo{}
5256
 	info := models.DrugCancelStockInfo{}
5358
 	return stock, err
5419
 	return stock, err
5359
 }
5420
 }
5360
 
5421
 
5422
+//func UpdateDrugCancelTX(id int64,tx *gorm.DB) (models.DrugCancelStock, error) {
5423
+//	stock := models.DrugCancelStock{}
5424
+//	err := tx.Model(&stock).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
5425
+//	return stock, err
5426
+//}
5427
+
5361
 func GetDrugWarehouseOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
5428
 func GetDrugWarehouseOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
5362
 
5429
 
5363
 	db := XTReadDB().Model(&info)
5430
 	db := XTReadDB().Model(&info)
5372
 	return info, err
5439
 	return info, err
5373
 }
5440
 }
5374
 
5441
 
5442
+//func GetDrugWarehouseOutInfoTX(warehouse_info_id int64, drug_id int64,tx *gorm.DB) (info []*models.DrugWarehouseOutInfo, err error) {
5443
+//	db := tx.Model(&info)
5444
+//	if warehouse_info_id > 0 {
5445
+//		db = db.Where("warehouse_info_id = ?", warehouse_info_id)
5446
+//	}
5447
+//	if drug_id > 0 {
5448
+//		db = db.Where("drug_id = ? and status =1", drug_id)
5449
+//	}
5450
+//	err = db.Find(&info).Error
5451
+//	return info, err
5452
+//}
5453
+
5375
 func GetCancelDrugStockOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugCancelStockInfo, err error) {
5454
 func GetCancelDrugStockOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugCancelStockInfo, err error) {
5376
 
5455
 
5377
 	err = XTReadDB().Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
5456
 	err = XTReadDB().Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
5378
 	return info, err
5457
 	return info, err
5379
 }
5458
 }
5380
 
5459
 
5460
+//func GetCancelDrugStockOutInfoTX(warehouse_info_id int64, drug_id int64,tx *gorm.DB) (info []*models.DrugCancelStockInfo, err error) {
5461
+//	err = tx.Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
5462
+//	return info, err
5463
+//}
5464
+
5381
 func GetTemplateSummary(orgid int64) (config []*models.Dataconfig, err error) {
5465
 func GetTemplateSummary(orgid int64) (config []*models.Dataconfig, err error) {
5382
 
5466
 
5383
 	err = XTReadDB().Model(&config).Where("module='template_summary' and parent_id=? and org_id in (?)", 0, orgid).Find(&config).Error
5467
 	err = XTReadDB().Model(&config).Where("module='template_summary' and parent_id=? and org_id in (?)", 0, orgid).Find(&config).Error
6418
 	return err
6502
 	return err
6419
 }
6503
 }
6420
 
6504
 
6505
+//func UpdateMedicalSumCountTX(drug_id int64, sum_count int64, sum_in_count int64, orgid int64,tx *gorm.DB) error {
6506
+//	err := tx.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
6507
+//	return err
6508
+//}
6509
+
6421
 func UpdateGoodByGoodId(good_id int64, sum_count int64, sum_in_count int64, orgid int64) error {
6510
 func UpdateGoodByGoodId(good_id int64, sum_count int64, sum_in_count int64, orgid int64) error {
6422
 	err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
6511
 	err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
6423
 	return err
6512
 	return err