package logic import ( "exhibition-register/internal/dao" "exhibition-register/internal/model" "exhibition-register/pb/exhibition" "exhibition-register/pkg/utils" ) type IRegister interface { CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error) SaveRegisterRecord(in *exhibition.RegisterInfo) (out *exhibition.SaveRegisterRecordResp, err error) RegisterRecordList(in *exhibition.RecordListReq) (out *exhibition.RecordListResp, err error) FindAllRecord() (out *exhibition.ExportRecordResp, err error) } func NewRegister() IRegister { return &Register{} } type Register struct { } 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.Format("2006-01-02 15:04:05"), UpdatedAt: record.UpdatedAt.Format("2006-01-02 15:04:05"), } 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.Format("2006-01-02 15:04:05"), UpdatedAt: item.UpdatedAt.Format("2006-01-02 15:04:05"), } 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, } tmpRecord := &model.RegisterRecord{} if in.Uuid != "" { record.UUID = in.Uuid registerRecord, err := dao.UpdateRegisterRecord(record) if err != nil { return nil, err } tmpRecord = registerRecord } else { record.UUID = utils.GetUUID() registerRecord, err := dao.CreateRegisterRecord(record) if err != nil { return nil, err } tmpRecord = registerRecord } data := &exhibition.RegisterInfo{ Id: int32(tmpRecord.ID), Uuid: tmpRecord.UUID, ArtistName: tmpRecord.ArtistName, Gender: tmpRecord.Gender, PhoneNum: tmpRecord.PhoneNum, IdCard: tmpRecord.IdCard, Address: tmpRecord.Address, IdCardPhoto: tmpRecord.IdCardPhoto, ArtistPhoto: tmpRecord.ArtistPhoto, CreatedAt: tmpRecord.CreatedAt.Format("2006-01-02 15:04:05"), UpdatedAt: tmpRecord.UpdatedAt.Format("2006-01-02 15:04:05"), } out.Data = data return out, nil } // CheckByPhone 通过手机号检索 存在的就返回数据 func (r *Register) CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error) { 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.Format("2006-01-02 15:04:05"), UpdatedAt: record.UpdatedAt.Format("2006-01-02 15:04:05"), } out.Data = data out.IsExist = true return out, nil }