183 lines
6.2 KiB
Go
Executable File
183 lines
6.2 KiB
Go
Executable File
package repository
|
|
|
|
import (
|
|
"github.com/rovina/zsp-backend/internal/model"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ZSPFinancesRepository interface {
|
|
CreateFreightCharge(charge *model.ZSPFreightCharges) error
|
|
GetFreightCharge(id string) (*model.ZSPFreightCharges, error)
|
|
ListFreightCharges() ([]model.ZSPFreightCharges, error)
|
|
UpdateFreightCharge(charge *model.ZSPFreightCharges) error
|
|
DeleteFreightCharge(id string) error
|
|
|
|
CreateMiscCharge(charge *model.ZSPMiscCharges) error
|
|
GetMiscCharge(id string) (*model.ZSPMiscCharges, error)
|
|
ListMiscCharges() ([]model.ZSPMiscCharges, error)
|
|
UpdateMiscCharge(charge *model.ZSPMiscCharges) error
|
|
DeleteMiscCharge(id string) error
|
|
|
|
CreateServiceFee(fee *model.ZSPServiceFees) error
|
|
GetServiceFee(id string) (*model.ZSPServiceFees, error)
|
|
ListServiceFees() ([]model.ZSPServiceFees, error)
|
|
UpdateServiceFee(fee *model.ZSPServiceFees) error
|
|
DeleteServiceFee(id string) error
|
|
|
|
CreateCostBreakdown(breakdown *model.ZSPCostBreakdown) error
|
|
GetCostBreakdown(id string) (*model.ZSPCostBreakdown, error)
|
|
ListCostBreakdowns(businessID string) ([]model.ZSPCostBreakdown, error)
|
|
UpdateCostBreakdown(breakdown *model.ZSPCostBreakdown) error
|
|
DeleteCostBreakdown(id string) error
|
|
|
|
CreateProfitRecord(record *model.ZSPProfitRecord) error
|
|
GetProfitRecord(id string) (*model.ZSPProfitRecord, error)
|
|
ListProfitRecords(filters map[string]string) ([]model.ZSPProfitRecord, error)
|
|
UpdateProfitRecord(id string, req *model.ZSPProfitRecord) error
|
|
DeleteProfitRecord(id string) error
|
|
}
|
|
|
|
type zspFinancesRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewZSPFinancesRepository(db *gorm.DB) ZSPFinancesRepository {
|
|
return &zspFinancesRepository{db: db}
|
|
}
|
|
|
|
// ============ 货代费用 ============
|
|
func (r *zspFinancesRepository) CreateFreightCharge(charge *model.ZSPFreightCharges) error {
|
|
return r.db.Create(charge).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) GetFreightCharge(id string) (*model.ZSPFreightCharges, error) {
|
|
var charge model.ZSPFreightCharges
|
|
err := r.db.First(&charge, id).Error
|
|
return &charge, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) ListFreightCharges() ([]model.ZSPFreightCharges, error) {
|
|
var charges []model.ZSPFreightCharges
|
|
err := r.db.Order("create_time desc").Find(&charges).Error
|
|
return charges, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) UpdateFreightCharge(charge *model.ZSPFreightCharges) error {
|
|
return r.db.Save(charge).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) DeleteFreightCharge(id string) error {
|
|
return r.db.Delete(&model.ZSPFreightCharges{}, id).Error
|
|
}
|
|
|
|
// ============ 杂费 ============
|
|
func (r *zspFinancesRepository) CreateMiscCharge(charge *model.ZSPMiscCharges) error {
|
|
return r.db.Create(charge).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) GetMiscCharge(id string) (*model.ZSPMiscCharges, error) {
|
|
var charge model.ZSPMiscCharges
|
|
err := r.db.First(&charge, id).Error
|
|
return &charge, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) ListMiscCharges() ([]model.ZSPMiscCharges, error) {
|
|
var charges []model.ZSPMiscCharges
|
|
err := r.db.Order("create_time desc").Find(&charges).Error
|
|
return charges, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) UpdateMiscCharge(charge *model.ZSPMiscCharges) error {
|
|
return r.db.Save(charge).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) DeleteMiscCharge(id string) error {
|
|
return r.db.Delete(&model.ZSPMiscCharges{}, id).Error
|
|
}
|
|
|
|
// ============ 服务费 ============
|
|
func (r *zspFinancesRepository) CreateServiceFee(fee *model.ZSPServiceFees) error {
|
|
return r.db.Create(fee).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) GetServiceFee(id string) (*model.ZSPServiceFees, error) {
|
|
var fee model.ZSPServiceFees
|
|
err := r.db.First(&fee, id).Error
|
|
return &fee, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) ListServiceFees() ([]model.ZSPServiceFees, error) {
|
|
var fees []model.ZSPServiceFees
|
|
err := r.db.Order("create_time desc").Find(&fees).Error
|
|
return fees, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) UpdateServiceFee(fee *model.ZSPServiceFees) error {
|
|
return r.db.Save(fee).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) DeleteServiceFee(id string) error {
|
|
return r.db.Delete(&model.ZSPServiceFees{}, id).Error
|
|
}
|
|
|
|
// ============ 成本构成 ============
|
|
func (r *zspFinancesRepository) CreateCostBreakdown(breakdown *model.ZSPCostBreakdown) error {
|
|
return r.db.Create(breakdown).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) GetCostBreakdown(id string) (*model.ZSPCostBreakdown, error) {
|
|
var breakdown model.ZSPCostBreakdown
|
|
err := r.db.First(&breakdown, id).Error
|
|
return &breakdown, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) ListCostBreakdowns(businessID string) ([]model.ZSPCostBreakdown, error) {
|
|
var breakdowns []model.ZSPCostBreakdown
|
|
query := r.db.Model(&model.ZSPCostBreakdown{})
|
|
if businessID != "" {
|
|
query = query.Where("business_id = ?", businessID)
|
|
}
|
|
err := query.Order("create_time desc").Find(&breakdowns).Error
|
|
return breakdowns, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) UpdateCostBreakdown(breakdown *model.ZSPCostBreakdown) error {
|
|
return r.db.Save(breakdown).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) DeleteCostBreakdown(id string) error {
|
|
return r.db.Delete(&model.ZSPCostBreakdown{}, id).Error
|
|
}
|
|
|
|
// ============ 利润记录 ============
|
|
func (r *zspFinancesRepository) CreateProfitRecord(record *model.ZSPProfitRecord) error {
|
|
return r.db.Create(record).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) GetProfitRecord(id string) (*model.ZSPProfitRecord, error) {
|
|
var record model.ZSPProfitRecord
|
|
err := r.db.First(&record, id).Error
|
|
return &record, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) ListProfitRecords(filters map[string]string) ([]model.ZSPProfitRecord, error) {
|
|
var records []model.ZSPProfitRecord
|
|
query := r.db.Model(&model.ZSPProfitRecord{})
|
|
if filters["businessId"] != "" {
|
|
query = query.Where("business_id = ?", filters["businessId"])
|
|
}
|
|
if filters["businessType"] != "" {
|
|
query = query.Where("business_type = ?", filters["businessType"])
|
|
}
|
|
err := query.Order("create_time desc").Find(&records).Error
|
|
return records, err
|
|
}
|
|
|
|
func (r *zspFinancesRepository) UpdateProfitRecord(id string, req *model.ZSPProfitRecord) error {
|
|
return r.db.Save(req).Error
|
|
}
|
|
|
|
func (r *zspFinancesRepository) DeleteProfitRecord(id string) error {
|
|
return r.db.Delete(&model.ZSPProfitRecord{}, id).Error
|
|
}
|