forked from free-lancers/electricity_bill_calc_service
feat(user):完成用户部分所有接口的迁移。
This commit is contained in:
126
vo/user.go
Normal file
126
vo/user.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package vo
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/tools/time"
|
||||
st "time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type MGTAndOPSAccountCreationForm struct {
|
||||
Username string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
Contact *string `json:"contact"`
|
||||
Phone *string `json:"phone"`
|
||||
UserType int16 `json:"type"`
|
||||
}
|
||||
|
||||
func (u MGTAndOPSAccountCreationForm) IntoUser() *model.User {
|
||||
return &model.User{
|
||||
Username: u.Username,
|
||||
Password: "",
|
||||
ResetNeeded: false,
|
||||
UserType: u.UserType,
|
||||
Enabled: true,
|
||||
CreatedAt: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (u MGTAndOPSAccountCreationForm) IntoUserDetail() *model.UserDetail {
|
||||
return &model.UserDetail{
|
||||
Name: &u.Name,
|
||||
Abbr: nil,
|
||||
Region: nil,
|
||||
Address: nil,
|
||||
Contact: u.Contact,
|
||||
Phone: u.Phone,
|
||||
UnitServiceFee: decimal.Zero,
|
||||
ServiceExpiration: model.SpecificDate(2099, st.December, 31),
|
||||
CreatedAt: time.Now(),
|
||||
CreatedBy: nil,
|
||||
LastModifiedAt: time.Now(),
|
||||
LastModifiedBy: nil,
|
||||
DeletedAt: nil,
|
||||
DeletedBy: nil,
|
||||
}
|
||||
}
|
||||
|
||||
type EnterpriseAccountCreationForm struct {
|
||||
Username string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
Region *string `json:"region"`
|
||||
Address *string `json:"address"`
|
||||
Contact *string `json:"contact"`
|
||||
Phone *string `json:"phone"`
|
||||
UnitServiceFee string `json:"unitServiceFee"`
|
||||
}
|
||||
|
||||
func (u EnterpriseAccountCreationForm) IntoUser() *model.User {
|
||||
return &model.User{
|
||||
Username: u.Username,
|
||||
Password: "",
|
||||
ResetNeeded: false,
|
||||
UserType: model.USER_TYPE_ENT,
|
||||
Enabled: true,
|
||||
CreatedAt: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (u EnterpriseAccountCreationForm) IntoUserDetail() (*model.UserDetail, error) {
|
||||
unitServiceFee, err := decimal.NewFromString(u.UnitServiceFee)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &model.UserDetail{
|
||||
Name: &u.Name,
|
||||
Abbr: nil,
|
||||
Region: u.Region,
|
||||
Address: u.Address,
|
||||
Contact: u.Contact,
|
||||
Phone: u.Phone,
|
||||
UnitServiceFee: unitServiceFee,
|
||||
ServiceExpiration: model.SpecificDate(2000, st.January, 1),
|
||||
CreatedAt: time.Now(),
|
||||
CreatedBy: nil,
|
||||
LastModifiedAt: time.Now(),
|
||||
LastModifiedBy: nil,
|
||||
DeletedAt: nil,
|
||||
DeletedBy: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type UserDetailModificationForm struct {
|
||||
Name string `json:"name"`
|
||||
Region *string `json:"region"`
|
||||
Address *string `json:"address"`
|
||||
Contact *string `json:"contact"`
|
||||
Phone *string `json:"phone"`
|
||||
UnitServiceFee *string `json:"unitServiceFee"`
|
||||
}
|
||||
|
||||
func (u UserDetailModificationForm) IntoModificationModel() (*model.UserModificationForm, error) {
|
||||
unitServiceFee, err := decimal.NewFromString(*u.UnitServiceFee)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &model.UserModificationForm{
|
||||
Name: u.Name,
|
||||
Region: u.Region,
|
||||
Address: u.Address,
|
||||
Contact: u.Contact,
|
||||
Phone: u.Phone,
|
||||
UnitServiceFee: &unitServiceFee,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type UserStateChangeForm struct {
|
||||
Uid string `json:"uid"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type RepasswordForm struct {
|
||||
VerifyCode string `json:"verifyCode"`
|
||||
Username string `json:"uname"`
|
||||
NewPassword string `json:"newPass"`
|
||||
}
|
Reference in New Issue
Block a user