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.

154 lines
4.5 KiB
Go

package service
import (
"context"
"fmt"
"github.com/dubbogo/gost/log/logger"
"github.com/exhibition-main/api/artist"
"github.com/exhibition-main/api/exhibition"
"github.com/exhibition-main/internal/config"
"github.com/exhibition-main/internal/model"
"github.com/exhibition-main/internal/msg"
"github.com/exhibition-main/internal/response"
"github.com/exhibition-main/pkg/logic"
"github.com/exhibition-main/pkg/utils"
"github.com/gin-gonic/gin"
"time"
)
func RegisterList(c *gin.Context) {
var recordListReq exhibition.RecordListReq
if err := c.ShouldBind(&recordListReq); err != nil {
logger.Errorf("RegisterRecordList ShouldBind err", err)
response.ResponseQuickMsg(c, msg.Fail, msg.INVALID_PARAMS, nil)
return
}
resp, err := GrpcExhibitionClientImpl.RegisterRecordList(context.Background(), &recordListReq)
if err != nil {
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
return
}
response.ResponseQuickMsg(c, msg.Ok, resp.Msg, resp)
return
}
func CheckByPhone(c *gin.Context) {
var registerInfo exhibition.RegisterInfo
if err := c.ShouldBind(&registerInfo); err != nil {
logger.Errorf("CheckPhone ShouldBind err", err)
response.ResponseQuickMsg(c, msg.Fail, msg.INVALID_PARAMS, nil)
return
}
resp, err := GrpcExhibitionClientImpl.CheckPhone(context.Background(), &registerInfo)
if err != nil {
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
return
}
response.ResponseQuickMsg(c, msg.Ok, resp.Msg, resp)
return
}
func SaveRegister(c *gin.Context) {
var registerInfo exhibition.RegisterInfo
if err := c.ShouldBind(&registerInfo); err != nil {
logger.Errorf("SaveRegisterRecord ShouldBind err", err)
response.ResponseQuickMsg(c, msg.Fail, msg.INVALID_PARAMS, nil)
return
}
resp, err := GrpcExhibitionClientImpl.SaveRegisterRecord(context.Background(), &registerInfo)
if err != nil {
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
return
}
response.ResponseQuickMsg(c, msg.Ok, resp.Msg, resp)
return
}
// ExportRegister 导出报名信息列表
func ExportRegister(c *gin.Context) {
var exportRecordReq exhibition.ExportRecordReq
//if err := c.ShouldBind(&exportRecordReq); err != nil {
// logger.Errorf("SaveRegisterRecord ShouldBind err", err)
// response.ResponseQuickMsg(c, msg.Fail, msg.INVALID_PARAMS, nil)
// return
//}
resp, err := GrpcExhibitionClientImpl.ExportRegisterRecord(context.Background(), &exportRecordReq)
if err != nil {
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
return
}
if len(resp.Data) == 0 {
resp.Data = []*exhibition.ExportInfo{}
}
columns := []string{"画家姓名", "性别", "手机号", "身份证号", "通讯地址", "身份证照片", "本人近照", "报名时间", "更新时间"}
exportFileName := fmt.Sprintf("国展报名%v.xlsx", time.Now().Format("2006-01-01"))
filePath := fmt.Sprintf("./runtime/%s", exportFileName)
data := make([]interface{}, 0)
for _, v := range resp.Data {
var temp []string
temp = append(temp, v.ArtistName)
var gender string
if v.Gender == 1 {
gender = "男"
} else {
gender = "女"
}
temp = append(temp, gender)
temp = append(temp, v.PhoneNum)
temp = append(temp, v.IdCard)
temp = append(temp, v.Address)
temp = append(temp, v.IdCardPhoto)
temp = append(temp, v.ArtistPhoto)
temp = append(temp, v.CreatedAt)
temp = append(temp, v.UpdatedAt)
data = append(data, &temp)
}
_, _ = utils.ToExcelByType(columns, data, "slice", filePath)
//处理图片
err = logic.DealExcelImg(filePath)
if err != nil {
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
return
}
var httpType string
if config.IsHttps {
httpType = model.HttpsType
} else {
httpType = model.HttpType
}
var exportUrl string = fmt.Sprintf("%s%s/static/%s", httpType, c.Request.Host, exportFileName)
response.ResponseQuickMsg(c, msg.Ok, resp.Msg, map[string]string{
"exportUrl": exportUrl,
})
return
}
func GetCardIdWithImg(c *gin.Context) {
var listReq artist.GetCardIdWithImgReq
if err := c.ShouldBind(&listReq); err != nil {
logger.Errorf("GetCardIdWithImg ShouldBind err", err)
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
return
}
if err := listReq.Validate(); err != nil {
err = utils.SubstrError(err)
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
return
}
resp, err := GrpcArtistImpl.GetCardIdWithImg(context.Background(), &listReq)
if err != nil {
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
return
}
response.ResponseQuickMsg(c, msg.Ok, resp.Msg, resp)
return
}