api_byte_lib.go 3.7 KB
package bytelib

import (
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
	"time"
)

// ApiByteLib 字库底层接口
type ApiByteLib struct {
	api.BaseServiceGateway
	baseUrL string
}

func NewApiByteLib(host string) *ApiByteLib {
	gt := api.NewBaseServiceGateway(host)
	gt.ConnectTimeout = 10 * time.Second
	gt.ReadWriteTimeout = 10 * time.Second
	gt.Interceptor = func(msg string) {
		log.Logger.Info(msg)
	}
	return &ApiByteLib{
		BaseServiceGateway: gt,
	}
}

// 加载数据

func (gateway ApiByteLib) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) {
	return nil, nil
}

// EditTable 编辑表格
func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) {
	url := gateway.Host() + "/table/edit"
	method := "post"
	var data bytecore.DataEditDataTable
	err := gateway.FastDoRequest(url, method, param, &data)
	if err != nil {
		return nil, err
	}
	return &data, nil
}

// SaveTable 保存校验文件 (文件地址)
func (gateway ApiByteLib) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) {
	url := gateway.Host() + "/table/save"
	method := "post"
	var data bytecore.DataSaveTable
	err := gateway.FastDoRequest(url, method, param, &data)
	if err != nil {
		return nil, err
	}
	return &data, nil
}

// GenerateTable 生成主表
func (gateway ApiByteLib) GenerateTable(param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) {
	url := gateway.Host() + "/table/generate"
	method := "post"
	var data bytecore.DataGenerateTable
	err := gateway.FastDoRequest(url, method, param, &data)
	if err != nil {
		return nil, err
	}
	return &data, nil
}

// CopyTable 表复制
func (gateway ApiByteLib) CopyTable(param bytecore.ReqCopyTable) (*bytecore.DataCopyTable, error) {
	url := gateway.Host() + "/table/copy"
	method := "post"
	var data bytecore.DataCopyTable
	err := gateway.FastDoRequest(url, method, param, &data)
	if err != nil {
		return nil, err
	}
	return &data, nil
}

// AppendData 追加数据
func (gateway ApiByteLib) AppendData(param bytecore.ReqAppendData) (*bytecore.DataAppendData, error) {
	url := gateway.Host() + "/table/append"
	method := "post"
	var data bytecore.DataAppendData
	err := gateway.FastDoRequest(url, method, param, &data)
	if err != nil {
		return nil, err
	}
	return &data, nil
}

// DeleteTable 表删除 (主表、副表、分表)
func (gateway ApiByteLib) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.DataDeleteTable, error) {
	url := gateway.Host() + "/table/delete"
	method := "post"
	var data bytecore.DataDeleteTable
	err := gateway.FastDoRequest(url, method, param, &data)
	if err != nil {
		return nil, err
	}
	return &data, nil
}

// CancelFile 表删除 (主表、副表、分表)
func (gateway ApiByteLib) CancelFile(param bytecore.ReqCancelFile) (*bytecore.DataCancelFile, error) {
	url := gateway.Host() + "/table/cancel-file"
	method := "post"
	var data bytecore.DataCancelFile
	err := gateway.FastDoRequest(url, method, param, &data)
	if err != nil {
		return nil, err
	}
	return &data, nil
}

// 表拆分

// 更新表结构(分表)

// EditTableData 编辑、添加、删除表数据(副表)
func (gateway ApiByteLib) EditTableData(param bytecore.ReqEditTableData) (*bytecore.DataEditTableData, error) {
	url := gateway.Host() + "/table/cancel-file"
	method := "post"
	var data bytecore.DataEditTableData
	err := gateway.FastDoRequest(url, method, param, &data)
	if err != nil {
		return nil, err
	}
	return &data, nil
}