feat(data): 添加数据格式支持 更改数据写入读取
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m33s
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m33s
This commit is contained in:
@@ -3,52 +3,65 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"dypid/db"
|
"dypid/db"
|
||||||
"dypid/global"
|
"dypid/global"
|
||||||
"dypid/model"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReadDataHandler(c *gin.Context) {
|
func ReadDataHandler(c *gin.Context) {
|
||||||
lLen := global.RDB.LLen(global.RCtx, fmt.Sprintf("list:%s", c.Query("token")))
|
input := struct {
|
||||||
|
Token string `form:"token" binding:"required"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindQuery(&input); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lLen := global.RDB.LLen(global.RCtx, fmt.Sprintf("list:%s", input.Token))
|
||||||
if lLen.Val() == 0 {
|
if lLen.Val() == 0 {
|
||||||
c.JSON(200, gin.H{"result": "数据库没有数据"})
|
c.JSON(http.StatusOK, gin.H{"result": "数据库没有数据"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
retData := global.RDB.BLPop(global.RCtx, 0, fmt.Sprintf("list:%s", c.Query("token")))
|
retData := global.RDB.BLPop(global.RCtx, 0, fmt.Sprintf("list:%s", input.Token)).Val()[1]
|
||||||
newData := model.Data{}
|
|
||||||
err := json.Unmarshal([]byte(retData.Val()[1]), &newData)
|
c.String(http.StatusOK, retData)
|
||||||
if err != nil {
|
|
||||||
c.JSON(400, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.JSON(200, gin.H{"result": newData})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteDataHandler(c *gin.Context) {
|
func WriteDataHandler(c *gin.Context) {
|
||||||
data := model.Data{}
|
input := struct {
|
||||||
|
Token string `form:"token" binding:"required"`
|
||||||
if err := c.BindQuery(&data); err != nil {
|
Data string `form:"data" binding:"required"`
|
||||||
c.JSON(400, gin.H{"error": err.Error()})
|
}{}
|
||||||
|
if err := c.ShouldBindQuery(&input); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dedupObject, err := db.GetDedupObject(data.Token)
|
|
||||||
|
dedupObject, err := db.GetDedupObject(input.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = createBF(fmt.Sprintf("dedup:%s:%s", data.Token, dedupObject), 0.01, 100000000)
|
dataIndex, err := getDataIndex(input.Token)
|
||||||
if err != nil && err.Error() != "ERR item exists" {
|
if err != nil {
|
||||||
c.JSON(400, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
dedupValue := strings.Split(input.Data, "----")[dataIndex[dedupObject]]
|
||||||
|
|
||||||
|
err = createBF(fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject), 0.01, 100000000)
|
||||||
|
if err != nil && err.Error() != "ERR item exists" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
luaScript := `
|
luaScript := `
|
||||||
local dedupKey = KEYS[1] -- KEYS[1]: 去重键 (dedup:token:object)
|
local dedupKey = KEYS[1] -- KEYS[1]: 去重键 (dedup:token:object)
|
||||||
local listKey = KEYS[2] -- KEYS[2]: 列表键 (list:token)
|
local listKey = KEYS[2] -- KEYS[2]: 列表键 (list:token)
|
||||||
local dedupValue = ARGV[1] -- ARGV[1]: 去重值
|
local dedupValue = ARGV[1] -- ARGV[1]: 去重值
|
||||||
local jsonData = ARGV[2] -- ARGV[2]: JSON序列化的数据
|
local rawData = ARGV[2] -- ARGV[2]: 原始数据
|
||||||
|
|
||||||
-- 检查布隆过滤器中是否已存在该值
|
-- 检查布隆过滤器中是否已存在该值
|
||||||
local exists = redis.call('BF.EXISTS', dedupKey, dedupValue)
|
local exists = redis.call('BF.EXISTS', dedupKey, dedupValue)
|
||||||
@@ -61,41 +74,49 @@ end
|
|||||||
-- 添加到布隆过滤器
|
-- 添加到布隆过滤器
|
||||||
redis.call('BF.ADD', dedupKey, dedupValue)
|
redis.call('BF.ADD', dedupKey, dedupValue)
|
||||||
-- 添加到列表
|
-- 添加到列表
|
||||||
redis.call('LPUSH', listKey, jsonData)
|
redis.call('LPUSH', listKey, rawData)
|
||||||
|
|
||||||
-- 返回成功结果
|
-- 返回成功结果
|
||||||
return "ok"
|
return "ok"
|
||||||
`
|
`
|
||||||
k1 := fmt.Sprintf("dedup:%s:%s", data.Token, dedupObject)
|
|
||||||
k2 := fmt.Sprintf("list:%s", data.Token)
|
|
||||||
v1 := c.Query(dedupObject)
|
|
||||||
v2, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(500, gin.H{"error": "JSON序列化失败 " + err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := redis.NewScript(luaScript).Run(
|
result, err := redis.NewScript(luaScript).Run(
|
||||||
global.RCtx,
|
global.RCtx,
|
||||||
global.RDB,
|
global.RDB,
|
||||||
[]string{k1, k2},
|
[]string{
|
||||||
v1,
|
fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject),
|
||||||
string(v2),
|
fmt.Sprintf("list:%s", input.Token),
|
||||||
|
},
|
||||||
|
dedupValue,
|
||||||
|
input.Data,
|
||||||
).Result()
|
).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{"error": "Redis操作失败 " + err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Redis操作失败 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if resultMap, ok := result.(string); ok {
|
if resultMap, ok := result.(string); ok {
|
||||||
c.JSON(200, gin.H{"result": resultMap})
|
c.JSON(http.StatusOK, gin.H{"result": resultMap})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(500, gin.H{"error": "WriteDataHandler 错误"})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "WriteDataHandler 错误"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func createBF(bloomFilter string, errorRate float64, capacity int64) error {
|
func createBF(bloomFilter string, errorRate float64, capacity int64) error {
|
||||||
_, err := global.RDB.BFReserve(global.RCtx, bloomFilter, errorRate, capacity).Result()
|
_, err := global.RDB.BFReserve(global.RCtx, bloomFilter, errorRate, capacity).Result()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDataIndex(token string) (index map[string]int, err error) {
|
||||||
|
dataFormat, err := db.GetDataFormat(token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
f := strings.Split(dataFormat, "----")
|
||||||
|
index = make(map[string]int)
|
||||||
|
for i, s := range f {
|
||||||
|
index[s] = i
|
||||||
|
}
|
||||||
|
return index, nil
|
||||||
|
}
|
||||||
|
@@ -13,50 +13,63 @@ func ListTokenHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateTokenHandler(c *gin.Context) {
|
func CreateTokenHandler(c *gin.Context) {
|
||||||
if c.Query("token") == "" {
|
//解析输入数据
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
input := struct {
|
||||||
return
|
Token string `form:"token" binding:"required"`
|
||||||
} else if c.Query("dedup_object") == "" {
|
DedupObject string `form:"dedup_object" binding:"required"`
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_object不能为空"})
|
DataFormat string `form:"data_format" binding:"required"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindQuery(&input); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := db.CreateToken(c.Query("token"), c.Query("dedup_object"))
|
//创建Token
|
||||||
|
err := db.CreateToken(input.Token, input.DedupObject, input.DataFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//返回
|
||||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateTokenHandler(c *gin.Context) {
|
func UpdateTokenHandler(c *gin.Context) {
|
||||||
if c.Query("token") == "" {
|
input := struct {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
Token string `form:"token" binding:"required"`
|
||||||
return
|
DedupObject string `form:"dedup_object" binding:"required"`
|
||||||
} else if c.Query("dedup_object") == "" {
|
DataFormat string `form:"data_format" binding:"required"`
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_object不能为空"})
|
}{}
|
||||||
|
if err := c.ShouldBindQuery(&input); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := db.UpdateToken(c.Query("token"), c.Query("dedup_object"))
|
err := db.UpdateToken(input.Token, input.DedupObject, input.DataFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteTokenHandler(c *gin.Context) {
|
func DeleteTokenHandler(c *gin.Context) {
|
||||||
if c.Query("token") == "" {
|
input := struct {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
Token string `form:"token" binding:"required"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindQuery(&input); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := db.DeleteToken(c.Query("token"))
|
err := db.DeleteToken(input.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,15 +87,22 @@ func GetTokenInfoHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取去重对象失败 " + err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取去重对象失败 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
dataFormat, err := db.GetDataFormat(input.Token)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取数据格式失败 " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
output := struct {
|
output := struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
DedupObject string `json:"dedup_object"`
|
DedupObject string `json:"dedup_object"`
|
||||||
|
DataFormat string `json:"data_format"`
|
||||||
DedupItemsNumber int64 `json:"dedup_items_number"`
|
DedupItemsNumber int64 `json:"dedup_items_number"`
|
||||||
CacheListNumber int64 `json:"cache_list_number"`
|
CacheListNumber int64 `json:"cache_list_number"`
|
||||||
}{}
|
}{}
|
||||||
output.Token = input.Token
|
output.Token = input.Token
|
||||||
output.DedupObject = dedupObject
|
output.DedupObject = dedupObject
|
||||||
|
output.DataFormat = dataFormat
|
||||||
output.DedupItemsNumber = global.RDB.BFCard(global.RCtx, "dedup:"+input.Token+":"+dedupObject).Val()
|
output.DedupItemsNumber = global.RDB.BFCard(global.RCtx, "dedup:"+input.Token+":"+dedupObject).Val()
|
||||||
output.CacheListNumber = global.RDB.LLen(global.RCtx, "list:"+input.Token).Val()
|
output.CacheListNumber = global.RDB.LLen(global.RCtx, "list:"+input.Token).Val()
|
||||||
|
|
||||||
|
19
db/local.go
19
db/local.go
@@ -12,6 +12,7 @@ var localDB []Token
|
|||||||
type Token struct {
|
type Token struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
DedupObject string `json:"dedup_object"`
|
DedupObject string `json:"dedup_object"`
|
||||||
|
DataFormat string `json:"data_format"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitLocalDB() {
|
func InitLocalDB() {
|
||||||
@@ -35,7 +36,7 @@ func ListToken() []Token {
|
|||||||
return localDB
|
return localDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateToken(token string, dedupObject string) error {
|
func CreateToken(token string, dedupObject string, dataFormat string) error {
|
||||||
InitLocalDB()
|
InitLocalDB()
|
||||||
for _, t := range localDB {
|
for _, t := range localDB {
|
||||||
if t.Token == token {
|
if t.Token == token {
|
||||||
@@ -43,7 +44,7 @@ func CreateToken(token string, dedupObject string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a := append(localDB, Token{token, dedupObject})
|
a := append(localDB, Token{token, dedupObject, dataFormat})
|
||||||
marshal, err := json.Marshal(a)
|
marshal, err := json.Marshal(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -55,12 +56,13 @@ func CreateToken(token string, dedupObject string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateToken(token string, dedupObject string) error {
|
func UpdateToken(token string, dedupObject string, dataFormat string) error {
|
||||||
InitLocalDB()
|
InitLocalDB()
|
||||||
|
|
||||||
for i, t := range localDB {
|
for i, t := range localDB {
|
||||||
if t.Token == token {
|
if t.Token == token {
|
||||||
localDB[i].DedupObject = dedupObject
|
localDB[i].DedupObject = dedupObject
|
||||||
|
localDB[i].DataFormat = dataFormat
|
||||||
|
|
||||||
marshal, err := json.Marshal(localDB)
|
marshal, err := json.Marshal(localDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,6 +74,7 @@ func UpdateToken(token string, dedupObject string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InitLocalDB()
|
InitLocalDB()
|
||||||
return errors.New("token not found")
|
return errors.New("token not found")
|
||||||
}
|
}
|
||||||
@@ -93,6 +96,7 @@ func DeleteToken(token string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InitLocalDB()
|
InitLocalDB()
|
||||||
return errors.New("token not found")
|
return errors.New("token not found")
|
||||||
}
|
}
|
||||||
@@ -105,3 +109,12 @@ func GetDedupObject(token string) (dedupObject string, err error) {
|
|||||||
}
|
}
|
||||||
return "", errors.New("未找到Token")
|
return "", errors.New("未找到Token")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDataFormat(token string) (dataFormat string, err error) {
|
||||||
|
for i, t := range localDB {
|
||||||
|
if t.Token == token {
|
||||||
|
return localDB[i].DataFormat, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", errors.New("未找到Token")
|
||||||
|
}
|
||||||
|
@@ -16,19 +16,6 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UploadData struct {
|
|
||||||
Dyid string // dyid
|
|
||||||
Uid string // uid
|
|
||||||
Secid string // secid
|
|
||||||
Pid string // pid
|
|
||||||
CommentId string // comment_id
|
|
||||||
Id1 string // id1
|
|
||||||
Id2 string // id2
|
|
||||||
Id3 string // id3
|
|
||||||
Id4 string // id4
|
|
||||||
Id5 string // id5
|
|
||||||
}
|
|
||||||
|
|
||||||
var httpClient = &http.Client{
|
var httpClient = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
MaxIdleConns: 200,
|
MaxIdleConns: 200,
|
||||||
@@ -43,10 +30,6 @@ func main() {
|
|||||||
viper.SetDefault("url", "http://localhost:8080")
|
viper.SetDefault("url", "http://localhost:8080")
|
||||||
viper.SetDefault("token", "")
|
viper.SetDefault("token", "")
|
||||||
viper.SetDefault("thread-count", 10)
|
viper.SetDefault("thread-count", 10)
|
||||||
viper.SetDefault("index.uid", 0)
|
|
||||||
viper.SetDefault("index.secid", 1)
|
|
||||||
viper.SetDefault("index.pid", 2)
|
|
||||||
viper.SetDefault("index.comment-id", 3)
|
|
||||||
//设置配置文件名和路径 ./config.toml
|
//设置配置文件名和路径 ./config.toml
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
@@ -89,19 +72,10 @@ func main() {
|
|||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func uploadDataToServer(data UploadData) error {
|
func uploadDataToServer(data string) error {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("token", viper.GetString("token"))
|
params.Set("token", viper.GetString("token"))
|
||||||
params.Add("dyid", data.Dyid)
|
params.Set("data", data)
|
||||||
params.Add("uid", data.Uid)
|
|
||||||
params.Add("secid", data.Secid)
|
|
||||||
params.Add("pid", data.Pid)
|
|
||||||
params.Add("comment_id", data.CommentId)
|
|
||||||
params.Add("id1", data.Id1)
|
|
||||||
params.Add("id2", data.Id2)
|
|
||||||
params.Add("id3", data.Id3)
|
|
||||||
params.Add("id4", data.Id4)
|
|
||||||
params.Add("id5", data.Id5)
|
|
||||||
|
|
||||||
resp, err := httpClient.Post(viper.GetString("url")+"/api/data?"+params.Encode(), "application/x-www-form-urlencoded", strings.NewReader(""))
|
resp, err := httpClient.Post(viper.GetString("url")+"/api/data?"+params.Encode(), "application/x-www-form-urlencoded", strings.NewReader(""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -188,35 +162,8 @@ func processLines(lines <-chan string, workerID int, filePath string) {
|
|||||||
if strings.TrimSpace(line) == "" {
|
if strings.TrimSpace(line) == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用----分割行数据
|
|
||||||
parts := strings.Split(line, "----")
|
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
parts = append(parts, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保有足够的字段
|
|
||||||
if len(parts) < 3 {
|
|
||||||
fmt.Printf("Worker %d (文件 %s): 行数据字段不足,跳过: %s\n", workerID, filePath, line)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建上传数据结构
|
|
||||||
uploadData := UploadData{
|
|
||||||
Uid: parts[viper.GetInt("index.uid")],
|
|
||||||
Secid: parts[viper.GetInt("index.secid")],
|
|
||||||
Pid: parts[viper.GetInt("index.pid")],
|
|
||||||
CommentId: parts[viper.GetInt("index.comment-id")],
|
|
||||||
Dyid: parts[4],
|
|
||||||
Id1: parts[5],
|
|
||||||
Id2: parts[6],
|
|
||||||
Id3: parts[7],
|
|
||||||
Id4: parts[8],
|
|
||||||
Id5: parts[9],
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上传数据
|
// 上传数据
|
||||||
if err := uploadDataToServer(uploadData); err != nil {
|
if err := uploadDataToServer(line); err != nil {
|
||||||
fmt.Printf("Worker %d (文件 %s): 上传失败: %v\n", workerID, filePath, err)
|
fmt.Printf("Worker %d (文件 %s): 上传失败: %v\n", workerID, filePath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="icon" href="/favicon.ico">
|
<link rel="icon" href="/favicon.ico">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Vite App</title>
|
<title>dypid</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
@@ -2,6 +2,10 @@
|
|||||||
import {useCounterStore} from "@/stores/counter.ts";
|
import {useCounterStore} from "@/stores/counter.ts";
|
||||||
import {ref, watch} from 'vue'
|
import {ref, watch} from 'vue'
|
||||||
import axios from "@/axios.ts";
|
import axios from "@/axios.ts";
|
||||||
|
import {useRoute} from "vue-router"
|
||||||
|
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
const result = ref()
|
const result = ref()
|
||||||
const value = ref('')
|
const value = ref('')
|
||||||
@@ -67,7 +71,8 @@ axios.get('/api/token').then(res => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<b>当前Token:</b>
|
<b>当前Token:</b>
|
||||||
<el-select v-model="value" placeholder="选择Token" style="width: 240px">
|
<b v-if="!useCounterStore().isAdmin">{{ route.query.token }}</b>
|
||||||
|
<el-select v-if="useCounterStore().isAdmin" v-model="value" placeholder="选择Token" style="width: 240px">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in options"
|
v-for="item in options"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
@@ -85,6 +90,7 @@ axios.get('/api/token').then(res => {
|
|||||||
border
|
border
|
||||||
>
|
>
|
||||||
<el-descriptions-item label="去重对象">{{ result?.dedup_object }}</el-descriptions-item>
|
<el-descriptions-item label="去重对象">{{ result?.dedup_object }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="上传数据格式">{{ result?.data_format }}</el-descriptions-item>
|
||||||
<el-descriptions-item label="去重记录值">{{ result?.dedup_items_number }}</el-descriptions-item>
|
<el-descriptions-item label="去重记录值">{{ result?.dedup_items_number }}</el-descriptions-item>
|
||||||
<el-descriptions-item label="Redis中数据条数">{{ result?.cache_list_number }}</el-descriptions-item>
|
<el-descriptions-item label="Redis中数据条数">{{ result?.cache_list_number }}</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
import {ref} from "vue";
|
import {ref} from "vue";
|
||||||
import axios from "@/axios.ts";
|
import axios from "@/axios.ts";
|
||||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||||
|
import {useCounterStore} from "@/stores/counter.ts";
|
||||||
|
import {useRouter} from "vue-router";
|
||||||
|
|
||||||
const tableData = ref([])
|
const tableData = ref([])
|
||||||
|
|
||||||
@@ -14,23 +16,27 @@ const value = ref('')
|
|||||||
const options = [
|
const options = [
|
||||||
{
|
{
|
||||||
value: 'uid',
|
value: 'uid',
|
||||||
label: 'uid',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: 'pid',
|
|
||||||
label: 'pid',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'secid',
|
value: 'secid',
|
||||||
label: 'secid',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'dyid',
|
value: 'pid',
|
||||||
label: 'dyid',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'comment_id',
|
value: 'comment_id',
|
||||||
label: 'comment_id',
|
},
|
||||||
|
{
|
||||||
|
value: 'dyid',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const dataFormat = ref('')
|
||||||
|
const dataFormatOptions = [
|
||||||
|
{
|
||||||
|
value: 'uid----secid----pid----comment_id',
|
||||||
|
}, {
|
||||||
|
value: 'uid----secid',
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -38,7 +44,8 @@ const addToken = () => {
|
|||||||
axios.post('/api/token', {}, {
|
axios.post('/api/token', {}, {
|
||||||
params: {
|
params: {
|
||||||
token: input.value,
|
token: input.value,
|
||||||
dedup_object: value.value
|
dedup_object: value.value,
|
||||||
|
data_format: dataFormat.value
|
||||||
}
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (response.data.result == "ok") {
|
if (response.data.result == "ok") {
|
||||||
@@ -55,18 +62,18 @@ const addToken = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
import {useCounterStore} from "@/stores/counter.ts";
|
|
||||||
import {useRouter} from "vue-router";
|
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const viewDetails = (row: any) => {
|
const viewDetails = (row: any) => {
|
||||||
useCounterStore().token = row.token
|
useCounterStore().token = row.token
|
||||||
router.push({
|
router.push({
|
||||||
name: "TokenDetail"
|
name: "TokenDetail",
|
||||||
|
query: {token: row.token}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var rowOut: any
|
var rowOut: any
|
||||||
|
|
||||||
const dedupObjectVisible = ref(false)
|
const dedupObjectVisible = ref(false)
|
||||||
const dialogDedupObjectVisible = (row: any) => {
|
const dialogDedupObjectVisible = (row: any) => {
|
||||||
rowOut = row
|
rowOut = row
|
||||||
@@ -77,7 +84,8 @@ const updateDedupObject = () => {
|
|||||||
axios.put('/api/token', {}, {
|
axios.put('/api/token', {}, {
|
||||||
params: {
|
params: {
|
||||||
token: rowOut.token,
|
token: rowOut.token,
|
||||||
dedup_object: value.value
|
dedup_object: value.value,
|
||||||
|
data_format: rowOut.data_format
|
||||||
}
|
}
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.data.result == "ok") {
|
if (res.data.result == "ok") {
|
||||||
@@ -92,7 +100,34 @@ const updateDedupObject = () => {
|
|||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
ElMessage.error(error.response?.data?.error)
|
ElMessage.error(error.response?.data?.error)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataFormatVisible = ref(false)
|
||||||
|
const dialogDataFormatVisible = (row: any) => {
|
||||||
|
rowOut = row
|
||||||
|
dataFormatVisible.value = true
|
||||||
|
}
|
||||||
|
const updateDataFormat = () => {
|
||||||
|
dataFormatVisible.value = false
|
||||||
|
axios.put('/api/token', {}, {
|
||||||
|
params: {
|
||||||
|
token: rowOut.token,
|
||||||
|
dedup_object: rowOut.dedup_object,
|
||||||
|
data_format: dataFormat.value
|
||||||
|
}
|
||||||
|
}).then(res => {
|
||||||
|
if (res.data.result == "ok") {
|
||||||
|
ElMessage({
|
||||||
|
message: '更改成功',
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
axios.get('/api/token').then(res => {
|
||||||
|
tableData.value = res.data.result
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
ElMessage.error(error.response?.data?.error)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteToken = (row: any) => {
|
const deleteToken = (row: any) => {
|
||||||
@@ -127,7 +162,6 @@ const checkPassword = () => {
|
|||||||
ElMessage.error('密码错误')
|
ElMessage.error('密码错误')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -143,12 +177,18 @@ const checkPassword = () => {
|
|||||||
<!--管理员-->
|
<!--管理员-->
|
||||||
<div v-if="useCounterStore().isAdmin">
|
<div v-if="useCounterStore().isAdmin">
|
||||||
<!--添加Token-->
|
<!--添加Token-->
|
||||||
<el-input v-model="input" style="width: 200px" placeholder="请输入Token名称"/>
|
<el-input v-model="input" style="width: 150px" placeholder="请输入Token名称"/>
|
||||||
<el-select v-model="value" placeholder="选择去重对象" style="width: 200px">
|
<el-select v-model="value" placeholder="选择去重对象" style="width: 150px">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in options"
|
v-for="item in options"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
:label="item.label"
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
<el-select v-model="dataFormat" placeholder="选择数据格式" style="width: 280px">
|
||||||
|
<el-option
|
||||||
|
v-for="item in dataFormatOptions"
|
||||||
|
:key="item.value"
|
||||||
:value="item.value"
|
:value="item.value"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
@@ -156,12 +196,14 @@ const checkPassword = () => {
|
|||||||
|
|
||||||
<!--Token列表-->
|
<!--Token列表-->
|
||||||
<el-table :data="tableData" style="width: 100%">
|
<el-table :data="tableData" style="width: 100%">
|
||||||
<el-table-column prop="token" label="Token" width="180"/>
|
<el-table-column prop="token" label="Token" width="150"/>
|
||||||
<el-table-column prop="dedup_object" label="去重对象" width="180"/>
|
<el-table-column prop="dedup_object" label="去重对象" width="150"/>
|
||||||
|
<el-table-column prop="data_format" label="上传数据格式" width="280"/>
|
||||||
<el-table-column label="操作">
|
<el-table-column label="操作">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button @click="viewDetails(scope.row)">查看详细</el-button>
|
<el-button @click="viewDetails(scope.row)">查看详细</el-button>
|
||||||
<el-button @click="dialogDedupObjectVisible(scope.row)" type="primary">更改去重对象</el-button>
|
<el-button @click="dialogDedupObjectVisible(scope.row)" type="primary">更改去重对象</el-button>
|
||||||
|
<el-button @click="dialogDataFormatVisible(scope.row)" type="primary">更改数据格式</el-button>
|
||||||
<el-popconfirm
|
<el-popconfirm
|
||||||
width="180"
|
width="180"
|
||||||
title="确认删除此Token吗"
|
title="确认删除此Token吗"
|
||||||
@@ -183,7 +225,6 @@ const checkPassword = () => {
|
|||||||
<el-option
|
<el-option
|
||||||
v-for="item in options"
|
v-for="item in options"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
:label="item.label"
|
|
||||||
:value="item.value"
|
:value="item.value"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
@@ -193,6 +234,21 @@ const checkPassword = () => {
|
|||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog v-model="dataFormatVisible" title="更改数据格式" width="400">
|
||||||
|
<el-select v-model="dataFormat" placeholder="选择数据格式" style="width: 280px">
|
||||||
|
<el-option
|
||||||
|
v-for="item in dataFormatOptions"
|
||||||
|
:key="item.value"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
<template #footer>
|
||||||
|
<el-button type="primary" @click="updateDataFormat">
|
||||||
|
确定
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user