electricity_bill_calc_service/vo/shares.go

46 lines
1008 B
Go

package vo
import (
"electricity_bill_calc/model"
"github.com/jinzhu/copier"
"github.com/shopspring/decimal"
)
type StateForm struct {
Enabled bool `json:"enabled"`
}
type ConsumptionDisplay struct {
AmountStr string `json:"amount"`
FeeStr string `json:"fee"`
PriceStr string `json:"price"`
ProportionStr string `json:"proportion"`
}
func (cd ConsumptionDisplay) Amount(a decimal.Decimal) ConsumptionDisplay {
cd.AmountStr = a.StringFixedBank(4)
return cd
}
func (cd ConsumptionDisplay) Fee(f decimal.Decimal) ConsumptionDisplay {
cd.FeeStr = f.StringFixedBank(4)
return cd
}
func (cd ConsumptionDisplay) Price(p decimal.Decimal) ConsumptionDisplay {
cd.PriceStr = p.StringFixedBank(8)
return cd
}
func (cd ConsumptionDisplay) Proportion(p decimal.Decimal) ConsumptionDisplay {
cd.ProportionStr = p.StringFixedBank(8)
return cd
}
func FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay {
cd := &ConsumptionDisplay{}
copier.Copy(cd, cu)
return *cd
}