You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.5 KiB
Go

8 months ago
package logic
8 months ago
import (
"exhibition-register/internal/dao"
8 months ago
"exhibition-register/internal/model"
8 months ago
"exhibition-register/pb/exhibition"
8 months ago
"exhibition-register/pkg/utils"
8 months ago
)
8 months ago
type IRegister interface {
8 months ago
CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error)
8 months ago
SaveRegisterRecord(in *exhibition.RegisterInfo) (out *exhibition.SaveRegisterRecordResp, err error)
RegisterRecordList(in *exhibition.RecordListReq) (out *exhibition.RecordListResp, err error)
FindAllRecord() (out *exhibition.ExportRecordResp, err error)
8 months ago
}
func NewRegister() IRegister {
return &Register{}
8 months ago
}
type Register struct {
}
8 months ago
8 months ago
func (r *Register) FindAllRecord() (out *exhibition.ExportRecordResp, err error) {
out = &exhibition.ExportRecordResp{}
allRecord, err := dao.AllRecord()
if err != nil {
return nil, err
}
if len(allRecord) > 0 {
for _, record := range allRecord {
tmp := &exhibition.ExportInfo{
ArtistName: record.ArtistName,
Gender: record.Gender,
PhoneNum: record.PhoneNum,
IdCard: record.IdCard,
Address: record.Address,
IdCardPhoto: record.IdCardPhoto,
ArtistPhoto: record.ArtistPhoto,
CreatedAt: record.CreatedAt.String(),
UpdatedAt: record.UpdatedAt.String(),
}
out.Data = append(out.Data, tmp)
}
}
return
}
func (r *Register) RegisterRecordList(in *exhibition.RecordListReq) (out *exhibition.RecordListResp, err error) {
out = &exhibition.RecordListResp{}
recordList, total, err := dao.RecordList(in)
if err != nil {
return nil, err
}
if total > 0 {
for _, item := range recordList {
tmp := &exhibition.RegisterInfo{
Id: int32(item.ID),
Uuid: item.UUID,
ArtistName: item.ArtistName,
Gender: item.Gender,
PhoneNum: item.PhoneNum,
IdCard: item.IdCard,
Address: item.Address,
IdCardPhoto: item.IdCardPhoto,
ArtistPhoto: item.ArtistPhoto,
CreatedAt: item.CreatedAt.String(),
UpdatedAt: item.UpdatedAt.String(),
}
out.Data = append(out.Data, tmp)
}
out.Count = int32(total)
}
return out, err
}
func (r *Register) SaveRegisterRecord(in *exhibition.RegisterInfo) (out *exhibition.SaveRegisterRecordResp, err error) {
out = &exhibition.SaveRegisterRecordResp{}
record := &model.RegisterRecord{
ArtistName: in.ArtistName,
Gender: in.Gender,
PhoneNum: in.PhoneNum,
IdCard: in.IdCard,
Address: in.Address,
IdCardPhoto: in.IdCardPhoto,
ArtistPhoto: in.ArtistPhoto,
}
if in.Uuid != "" {
record.UUID = in.Uuid
if err := dao.UpdateRegisterRecord(record); err != nil {
return nil, err
}
} else {
record.UUID = utils.GetUUID()
if err := dao.CreateRegisterRecord(record); err != nil {
return nil, err
}
}
return out, nil
}
// CheckByPhone 通过手机号检索 存在的就返回数据
8 months ago
func (r *Register) CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error) {
8 months ago
out = &exhibition.CheckPhoneResp{}
record, err := dao.CheckByPhone(in.PhoneNum)
if err != nil {
return nil, err
}
if record == nil {
out.IsExist = false
return out, nil
}
data := &exhibition.RegisterInfo{
Id: int32(record.ID),
Uuid: record.UUID,
ArtistName: record.ArtistName,
Gender: record.Gender,
PhoneNum: record.PhoneNum,
IdCard: record.IdCard,
Address: record.Address,
IdCardPhoto: record.IdCardPhoto,
ArtistPhoto: record.ArtistPhoto,
CreatedAt: record.CreatedAt.String(),
UpdatedAt: record.UpdatedAt.String(),
}
out.Data = data
out.IsExist = true
return out, nil
}