Compare commits
	
		
			No commits in common. "b641e50bda10aca49868137b4c9bdc2b705f30ac" and "74062f1e49a2560b8ba18144c408d5683a26f6d2" have entirely different histories.
		
	
	
		
			b641e50bda
			...
			74062f1e49
		
	
		
| @ -8,7 +8,6 @@ import ( | |||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"github.com/360EntSecGroup-Skylar/excelize" |  | ||||||
| 	"github.com/dubbogo/gost/log/logger" | 	"github.com/dubbogo/gost/log/logger" | ||||||
| 	"github.com/exhibition-main/api/exhibition" | 	"github.com/exhibition-main/api/exhibition" | ||||||
| 	"github.com/exhibition-main/internal/config" | 	"github.com/exhibition-main/internal/config" | ||||||
| @ -268,62 +267,3 @@ func OcrBase64(c *gin.Context) { | |||||||
| 	response.ResponseQuickMsg(c, msg.Ok, "操作成功", res) | 	response.ResponseQuickMsg(c, msg.Ok, "操作成功", res) | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| func ImportRecordByExcel(c *gin.Context) { |  | ||||||
| 	file, err := c.FormFile("file") |  | ||||||
| 	if err != nil { |  | ||||||
| 		logger.Errorf("获取文件失败: %v", err) |  | ||||||
| 		response.ResponseQuickMsg(c, msg.Fail, msg.INVALID_PARAMS, nil) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	//打开Excel文件
 |  | ||||||
| 	f, err := file.Open() |  | ||||||
| 	if err != nil { |  | ||||||
| 		logger.Errorf("打开文件失败: %v", err) |  | ||||||
| 		response.ResponseQuickMsg(c, msg.Fail, "文件打开失败", nil) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	defer f.Close() |  | ||||||
| 	excelFile, err := excelize.OpenReader(f) |  | ||||||
| 	if err != nil { |  | ||||||
| 		logger.Errorf("读取Excel失败: %v", err) |  | ||||||
| 		response.ResponseQuickMsg(c, msg.Fail, "Excel解析失败", nil) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	sheetName := excelFile.GetSheetName(0) |  | ||||||
| 	rows := excelFile.GetRows(sheetName) |  | ||||||
| 	if err != nil { |  | ||||||
| 		logger.Errorf("读取工作表失败: %v", err) |  | ||||||
| 		response.ResponseQuickMsg(c, msg.Fail, "工作表读取失败", nil) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 遍历行数据(跳过标题行)
 |  | ||||||
| 	var records []*exhibition.RegisterInfo |  | ||||||
| 	for i, row := range rows { |  | ||||||
| 		if i == 0 { // 跳过标题行
 |  | ||||||
| 			continue |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		if len(row) < 4 { // 确保列数足够
 |  | ||||||
| 			continue |  | ||||||
| 		} |  | ||||||
| 		record := &exhibition.RegisterInfo{ |  | ||||||
| 			ArtistName:  row[0], |  | ||||||
| 			PhoneNum:    row[1], |  | ||||||
| 			Address:     row[2], |  | ||||||
| 			ArtworkName: row[3], |  | ||||||
| 		} |  | ||||||
| 		records = append(records, record) |  | ||||||
| 	} |  | ||||||
| 	for _, r := range records { |  | ||||||
| 		_, err := GrpcExhibitionClientImpl.SaveRegisterRecord(context.Background(), r) |  | ||||||
| 		if err != nil { |  | ||||||
| 			response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil) |  | ||||||
| 			return |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	response.ResponseQuickMsg(c, msg.Ok, "ok", "") |  | ||||||
| 	return |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user