112 lines
3.3 KiB
Go
112 lines
3.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/dubbogo/gost/log/logger"
|
|
"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/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(®isterInfo); err != nil {
|
|
logger.Errorf("CheckPhone ShouldBind err", err)
|
|
response.ResponseQuickMsg(c, msg.Fail, msg.INVALID_PARAMS, nil)
|
|
return
|
|
}
|
|
resp, err := GrpcExhibitionClientImpl.CheckPhone(context.Background(), ®isterInfo)
|
|
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(®isterInfo); err != nil {
|
|
logger.Errorf("SaveRegisterRecord ShouldBind err", err)
|
|
response.ResponseQuickMsg(c, msg.Fail, msg.INVALID_PARAMS, nil)
|
|
return
|
|
}
|
|
resp, err := GrpcExhibitionClientImpl.SaveRegisterRecord(context.Background(), ®isterInfo)
|
|
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 := make([]string, 0)
|
|
columns = append(columns, "画家姓名", "性别", "手机号", "身份证号", "通讯地址", "身份证照片", "本人近照", "报名时间", "更新时间")
|
|
exportFileName := fmt.Sprintf("国展报名%v.xlsx", time.Now().String())
|
|
filePath := fmt.Sprintf("./runtime/%s", exportFileName)
|
|
// 下载图片 自适应插入到Excel
|
|
err = logic.DealListExcelImg(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
|
|
|
|
}
|