exhibition-register/internal/logic/register_logic.go

155 lines
4.2 KiB
Go
Raw Normal View History

2024-01-30 03:52:56 +00:00
package logic
2024-01-30 09:39:04 +00:00
import (
"exhibition-register/internal/dao"
2024-02-01 10:56:19 +00:00
"exhibition-register/internal/model"
2024-01-30 09:39:04 +00:00
"exhibition-register/pb/exhibition"
2024-02-01 10:56:19 +00:00
"exhibition-register/pkg/utils"
2024-01-30 09:39:04 +00:00
)
2024-01-30 03:52:56 +00:00
type IRegister interface {
2024-01-31 01:23:32 +00:00
CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error)
2024-02-01 10:56:19 +00:00
SaveRegisterRecord(in *exhibition.RegisterInfo) (out *exhibition.SaveRegisterRecordResp, err error)
RegisterRecordList(in *exhibition.RecordListReq) (out *exhibition.RecordListResp, err error)
FindAllRecord() (out *exhibition.ExportRecordResp, err error)
2024-01-30 09:39:04 +00:00
}
func NewRegister() IRegister {
return &Register{}
2024-01-30 03:52:56 +00:00
}
type Register struct {
}
2024-01-30 09:39:04 +00:00
2024-02-01 10:56:19 +00:00
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,
2024-02-02 09:05:34 +00:00
CreatedAt: record.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: record.UpdatedAt.Format("2006-01-02 15:04:05"),
2024-02-01 10:56:19 +00:00
}
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,
2024-02-02 09:05:34 +00:00
CreatedAt: item.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: item.UpdatedAt.Format("2006-01-02 15:04:05"),
2024-02-01 10:56:19 +00:00
}
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,
}
2024-02-02 09:05:34 +00:00
tmpRecord := &model.RegisterRecord{}
2024-02-01 10:56:19 +00:00
if in.Uuid != "" {
record.UUID = in.Uuid
2024-02-02 09:05:34 +00:00
registerRecord, err := dao.UpdateRegisterRecord(record)
if err != nil {
2024-02-01 10:56:19 +00:00
return nil, err
}
2024-02-02 09:05:34 +00:00
tmpRecord = registerRecord
2024-02-01 10:56:19 +00:00
} else {
record.UUID = utils.GetUUID()
2024-02-02 09:05:34 +00:00
registerRecord, err := dao.CreateRegisterRecord(record)
if err != nil {
2024-02-01 10:56:19 +00:00
return nil, err
}
2024-02-02 09:05:34 +00:00
tmpRecord = registerRecord
2024-02-01 10:56:19 +00:00
}
2024-02-02 09:05:34 +00:00
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
2024-02-01 10:56:19 +00:00
return out, nil
}
// CheckByPhone 通过手机号检索 存在的就返回数据
2024-01-31 01:23:32 +00:00
func (r *Register) CheckByPhone(in *exhibition.RegisterInfo) (out *exhibition.CheckPhoneResp, err error) {
2024-01-30 09:39:04 +00:00
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,
2024-02-02 09:05:34 +00:00
CreatedAt: record.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: record.UpdatedAt.Format("2006-01-02 15:04:05"),
2024-01-30 09:39:04 +00:00
}
out.Data = data
out.IsExist = true
return out, nil
}