199 lines
5.3 KiB
Go
199 lines
5.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"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/exhibition-main/pkg/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin/binding"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"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 := []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.Data.System.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 OcrBase64(c *gin.Context) {
|
|
|
|
var req model.OcrQuery
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
logger.Errorf("OcrBase64 ShouldBind err", err)
|
|
response.ResponseQuickMsg(c, msg.Fail, msg.INVALID_PARAMS, nil)
|
|
return
|
|
}
|
|
|
|
img := req.IdCardUrl
|
|
|
|
response1, err := http.Get(img)
|
|
if err != nil {
|
|
fmt.Println("网络请求错误:", err)
|
|
return
|
|
}
|
|
|
|
defer response1.Body.Close()
|
|
|
|
// 读取图片数据
|
|
imageData, err := ioutil.ReadAll(response1.Body)
|
|
if err != nil {
|
|
fmt.Println("读取图片数据错误:", err)
|
|
return
|
|
}
|
|
|
|
// 将图片数据转换为base64编码
|
|
base64Data := base64.StdEncoding.EncodeToString(imageData)
|
|
fmt.Println(base64Data)
|
|
|
|
side := ""
|
|
if req.Side == 1 {
|
|
side = "front"
|
|
} else {
|
|
side = "back"
|
|
}
|
|
result, err := model.OcrGetIdCard(base64Data, side)
|
|
if err != nil {
|
|
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
|
|
return
|
|
}
|
|
|
|
res := model.OcrRes{}
|
|
if side == "front" {
|
|
res.IDNum = result.IdCard
|
|
res.RealName = result.Name
|
|
res.Path = result.Path
|
|
res.Age = result.Age
|
|
res.Birthday = result.Birthday
|
|
res.Sex = result.Sex
|
|
fmt.Println("身份证和名字", res.IDNum, res.RealName)
|
|
res.CheckIdAndName()
|
|
fmt.Println("身份证和名字", res.IDNum, res.RealName)
|
|
} else {
|
|
res.IssueDate = result.IssueDate
|
|
res.ExpirationDate = result.ExpirationDate
|
|
}
|
|
|
|
response.ResponseQuickMsg(c, msg.Ok, "操作成功", res)
|
|
return
|
|
}
|