Commit 8c47a854 authored by shaol~'s avatar shaol~

运行脚本

parent f30c105f
package console
import (
"bufio"
"context"
"doc-service/domain/entity/serversitemicros/docserverproject"
"doc-service/domain/service"
"doc-service/infra/db"
"fmt"
"gitlab.galaxy-immi.com/Backend-group/go-com/third/log"
"os"
"strings"
"time"
)
func DoAliData() {
fmt.Println("开始刷新请求...")
ctx := context.Background()
// 启动一个协程来执行定时任务 20秒一次
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
go func() {
for {
select {
case <-ticker.C:
i := toDoData(ctx)
if i == 0 {
fmt.Println("没有数据: " + time.Now().Format("2006-01-02 15:04:05"))
}
}
}
}()
// 监听命令行输入
reader := bufio.NewReader(os.Stdin)
for {
text, _ := reader.ReadString('\n')
text = strings.TrimSpace(text)
if text == "exit" {
fmt.Println("Exiting process...")
os.Exit(0)
}
}
}
//获取数据
func toDoData(c context.Context) int8 {
projectData, err := db.GetServerSiteMicrosDB().DocServerProject.Query().Where(
docserverproject.StatusEQ(0),
).All(c)
if err != nil {
return 0
}
if len(projectData) <= 0 {
return 0
}
for _, item := range projectData {
docService := &service.DocServiceService{}
ali := docService.DoConversionToAli(c, item.ID)
if ali {
_, errUpdate := db.GetServerSiteMicrosDB().DocServerProject.UpdateOneID(item.ID).SetStatus(1).Save(c)
if errUpdate != nil {
log.Info("修改状态出错" + errUpdate.Error())
continue
}
}
log.Info("脚本请求阿里文件转换完成: " + string(item.ID))
fmt.Printf("脚本请求阿里文件转换完成: %d\n", item.ID)
}
return 1
}
......@@ -32,6 +32,8 @@ type DocServerProject struct {
TaskID string `json:"task_id,omitempty"`
// 应用id
AppID int32 `json:"app_id,omitempty"`
// 是否公有
IsPrivate int8 `json:"is_private,omitempty"`
// 状态
Status int32 `json:"status,omitempty"`
// 创建时间
......@@ -44,7 +46,7 @@ func (*DocServerProject) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case docserverproject.FieldID, docserverproject.FieldAppID, docserverproject.FieldStatus:
case docserverproject.FieldID, docserverproject.FieldAppID, docserverproject.FieldIsPrivate, docserverproject.FieldStatus:
values[i] = new(sql.NullInt64)
case docserverproject.FieldProjectName, docserverproject.FieldSourceType, docserverproject.FieldTargetType, docserverproject.FieldSourceURL, docserverproject.FieldTargetURL, docserverproject.FieldTaskID:
values[i] = new(sql.NullString)
......@@ -115,6 +117,12 @@ func (dsp *DocServerProject) assignValues(columns []string, values []any) error
} else if value.Valid {
dsp.AppID = int32(value.Int64)
}
case docserverproject.FieldIsPrivate:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field is_private", values[i])
} else if value.Valid {
dsp.IsPrivate = int8(value.Int64)
}
case docserverproject.FieldStatus:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
......@@ -189,6 +197,9 @@ func (dsp *DocServerProject) String() string {
builder.WriteString("app_id=")
builder.WriteString(fmt.Sprintf("%v", dsp.AppID))
builder.WriteString(", ")
builder.WriteString("is_private=")
builder.WriteString(fmt.Sprintf("%v", dsp.IsPrivate))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", dsp.Status))
builder.WriteString(", ")
......
......@@ -26,6 +26,8 @@ const (
FieldTaskID = "task_id"
// FieldAppID holds the string denoting the app_id field in the database.
FieldAppID = "app_id"
// FieldIsPrivate holds the string denoting the is_private field in the database.
FieldIsPrivate = "is_private"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldCreatedAt holds the string denoting the created_at field in the database.
......@@ -44,6 +46,7 @@ var Columns = []string{
FieldTargetURL,
FieldTaskID,
FieldAppID,
FieldIsPrivate,
FieldStatus,
FieldCreatedAt,
}
......@@ -79,6 +82,8 @@ var (
DefaultTaskID string
// DefaultAppID holds the default value on creation for the "app_id" field.
DefaultAppID int32
// DefaultIsPrivate holds the default value on creation for the "is_private" field.
DefaultIsPrivate int8
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus int32
)
......@@ -126,6 +131,11 @@ func ByAppID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAppID, opts...).ToFunc()
}
// ByIsPrivate orders the results by the is_private field.
func ByIsPrivate(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldIsPrivate, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
......
......@@ -89,6 +89,11 @@ func AppID(v int32) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldEQ(FieldAppID, v))
}
// IsPrivate applies equality check predicate on the "is_private" field. It's identical to IsPrivateEQ.
func IsPrivate(v int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldEQ(FieldIsPrivate, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v int32) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldEQ(FieldStatus, v))
......@@ -549,6 +554,46 @@ func AppIDLTE(v int32) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldLTE(FieldAppID, v))
}
// IsPrivateEQ applies the EQ predicate on the "is_private" field.
func IsPrivateEQ(v int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldEQ(FieldIsPrivate, v))
}
// IsPrivateNEQ applies the NEQ predicate on the "is_private" field.
func IsPrivateNEQ(v int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldNEQ(FieldIsPrivate, v))
}
// IsPrivateIn applies the In predicate on the "is_private" field.
func IsPrivateIn(vs ...int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldIn(FieldIsPrivate, vs...))
}
// IsPrivateNotIn applies the NotIn predicate on the "is_private" field.
func IsPrivateNotIn(vs ...int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldNotIn(FieldIsPrivate, vs...))
}
// IsPrivateGT applies the GT predicate on the "is_private" field.
func IsPrivateGT(v int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldGT(FieldIsPrivate, v))
}
// IsPrivateGTE applies the GTE predicate on the "is_private" field.
func IsPrivateGTE(v int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldGTE(FieldIsPrivate, v))
}
// IsPrivateLT applies the LT predicate on the "is_private" field.
func IsPrivateLT(v int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldLT(FieldIsPrivate, v))
}
// IsPrivateLTE applies the LTE predicate on the "is_private" field.
func IsPrivateLTE(v int8) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldLTE(FieldIsPrivate, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v int32) predicate.DocServerProject {
return predicate.DocServerProject(sql.FieldEQ(FieldStatus, v))
......
......@@ -118,6 +118,20 @@ func (dspc *DocServerProjectCreate) SetNillableAppID(i *int32) *DocServerProject
return dspc
}
// SetIsPrivate sets the "is_private" field.
func (dspc *DocServerProjectCreate) SetIsPrivate(i int8) *DocServerProjectCreate {
dspc.mutation.SetIsPrivate(i)
return dspc
}
// SetNillableIsPrivate sets the "is_private" field if the given value is not nil.
func (dspc *DocServerProjectCreate) SetNillableIsPrivate(i *int8) *DocServerProjectCreate {
if i != nil {
dspc.SetIsPrivate(*i)
}
return dspc
}
// SetStatus sets the "status" field.
func (dspc *DocServerProjectCreate) SetStatus(i int32) *DocServerProjectCreate {
dspc.mutation.SetStatus(i)
......@@ -209,6 +223,10 @@ func (dspc *DocServerProjectCreate) defaults() error {
v := docserverproject.DefaultAppID
dspc.mutation.SetAppID(v)
}
if _, ok := dspc.mutation.IsPrivate(); !ok {
v := docserverproject.DefaultIsPrivate
dspc.mutation.SetIsPrivate(v)
}
if _, ok := dspc.mutation.Status(); !ok {
v := docserverproject.DefaultStatus
dspc.mutation.SetStatus(v)
......@@ -243,6 +261,9 @@ func (dspc *DocServerProjectCreate) check() error {
if _, ok := dspc.mutation.AppID(); !ok {
return &ValidationError{Name: "app_id", err: errors.New(`serversitemicros: missing required field "DocServerProject.app_id"`)}
}
if _, ok := dspc.mutation.IsPrivate(); !ok {
return &ValidationError{Name: "is_private", err: errors.New(`serversitemicros: missing required field "DocServerProject.is_private"`)}
}
if _, ok := dspc.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`serversitemicros: missing required field "DocServerProject.status"`)}
}
......@@ -306,6 +327,10 @@ func (dspc *DocServerProjectCreate) createSpec() (*DocServerProject, *sqlgraph.C
_spec.SetField(docserverproject.FieldAppID, field.TypeInt32, value)
_node.AppID = value
}
if value, ok := dspc.mutation.IsPrivate(); ok {
_spec.SetField(docserverproject.FieldIsPrivate, field.TypeInt8, value)
_node.IsPrivate = value
}
if value, ok := dspc.mutation.Status(); ok {
_spec.SetField(docserverproject.FieldStatus, field.TypeInt32, value)
_node.Status = value
......
......@@ -145,6 +145,27 @@ func (dspu *DocServerProjectUpdate) AddAppID(i int32) *DocServerProjectUpdate {
return dspu
}
// SetIsPrivate sets the "is_private" field.
func (dspu *DocServerProjectUpdate) SetIsPrivate(i int8) *DocServerProjectUpdate {
dspu.mutation.ResetIsPrivate()
dspu.mutation.SetIsPrivate(i)
return dspu
}
// SetNillableIsPrivate sets the "is_private" field if the given value is not nil.
func (dspu *DocServerProjectUpdate) SetNillableIsPrivate(i *int8) *DocServerProjectUpdate {
if i != nil {
dspu.SetIsPrivate(*i)
}
return dspu
}
// AddIsPrivate adds i to the "is_private" field.
func (dspu *DocServerProjectUpdate) AddIsPrivate(i int8) *DocServerProjectUpdate {
dspu.mutation.AddIsPrivate(i)
return dspu
}
// SetStatus sets the "status" field.
func (dspu *DocServerProjectUpdate) SetStatus(i int32) *DocServerProjectUpdate {
dspu.mutation.ResetStatus()
......@@ -275,6 +296,12 @@ func (dspu *DocServerProjectUpdate) sqlSave(ctx context.Context) (n int, err err
if value, ok := dspu.mutation.AddedAppID(); ok {
_spec.AddField(docserverproject.FieldAppID, field.TypeInt32, value)
}
if value, ok := dspu.mutation.IsPrivate(); ok {
_spec.SetField(docserverproject.FieldIsPrivate, field.TypeInt8, value)
}
if value, ok := dspu.mutation.AddedIsPrivate(); ok {
_spec.AddField(docserverproject.FieldIsPrivate, field.TypeInt8, value)
}
if value, ok := dspu.mutation.Status(); ok {
_spec.SetField(docserverproject.FieldStatus, field.TypeInt32, value)
}
......@@ -424,6 +451,27 @@ func (dspuo *DocServerProjectUpdateOne) AddAppID(i int32) *DocServerProjectUpdat
return dspuo
}
// SetIsPrivate sets the "is_private" field.
func (dspuo *DocServerProjectUpdateOne) SetIsPrivate(i int8) *DocServerProjectUpdateOne {
dspuo.mutation.ResetIsPrivate()
dspuo.mutation.SetIsPrivate(i)
return dspuo
}
// SetNillableIsPrivate sets the "is_private" field if the given value is not nil.
func (dspuo *DocServerProjectUpdateOne) SetNillableIsPrivate(i *int8) *DocServerProjectUpdateOne {
if i != nil {
dspuo.SetIsPrivate(*i)
}
return dspuo
}
// AddIsPrivate adds i to the "is_private" field.
func (dspuo *DocServerProjectUpdateOne) AddIsPrivate(i int8) *DocServerProjectUpdateOne {
dspuo.mutation.AddIsPrivate(i)
return dspuo
}
// SetStatus sets the "status" field.
func (dspuo *DocServerProjectUpdateOne) SetStatus(i int32) *DocServerProjectUpdateOne {
dspuo.mutation.ResetStatus()
......@@ -584,6 +632,12 @@ func (dspuo *DocServerProjectUpdateOne) sqlSave(ctx context.Context) (_node *Doc
if value, ok := dspuo.mutation.AddedAppID(); ok {
_spec.AddField(docserverproject.FieldAppID, field.TypeInt32, value)
}
if value, ok := dspuo.mutation.IsPrivate(); ok {
_spec.SetField(docserverproject.FieldIsPrivate, field.TypeInt8, value)
}
if value, ok := dspuo.mutation.AddedIsPrivate(); ok {
_spec.AddField(docserverproject.FieldIsPrivate, field.TypeInt8, value)
}
if value, ok := dspuo.mutation.Status(); ok {
_spec.SetField(docserverproject.FieldStatus, field.TypeInt32, value)
}
......
......@@ -67,6 +67,7 @@ var (
{Name: "target_url", Type: field.TypeString, Nullable: true, Size: 65535, SchemaType: map[string]string{"mysql": "text"}},
{Name: "task_id", Type: field.TypeString, Default: "", SchemaType: map[string]string{"mysql": "varchar(128)"}},
{Name: "app_id", Type: field.TypeInt32, Default: 0, SchemaType: map[string]string{"mysql": "int"}},
{Name: "is_private", Type: field.TypeInt8, Default: 0, SchemaType: map[string]string{"mysql": "tinyint"}},
{Name: "status", Type: field.TypeInt32, Default: 0, SchemaType: map[string]string{"mysql": "int"}},
{Name: "created_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"mysql": "datetime"}},
}
......
......@@ -2232,6 +2232,8 @@ type DocServerProjectMutation struct {
task_id *string
app_id *int32
addapp_id *int32
is_private *int8
addis_private *int8
status *int32
addstatus *int32
created_at *time.Time
......@@ -2643,6 +2645,62 @@ func (m *DocServerProjectMutation) ResetAppID() {
m.addapp_id = nil
}
// SetIsPrivate sets the "is_private" field.
func (m *DocServerProjectMutation) SetIsPrivate(i int8) {
m.is_private = &i
m.addis_private = nil
}
// IsPrivate returns the value of the "is_private" field in the mutation.
func (m *DocServerProjectMutation) IsPrivate() (r int8, exists bool) {
v := m.is_private
if v == nil {
return
}
return *v, true
}
// OldIsPrivate returns the old "is_private" field's value of the DocServerProject entity.
// If the DocServerProject object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DocServerProjectMutation) OldIsPrivate(ctx context.Context) (v int8, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsPrivate is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsPrivate requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsPrivate: %w", err)
}
return oldValue.IsPrivate, nil
}
// AddIsPrivate adds i to the "is_private" field.
func (m *DocServerProjectMutation) AddIsPrivate(i int8) {
if m.addis_private != nil {
*m.addis_private += i
} else {
m.addis_private = &i
}
}
// AddedIsPrivate returns the value that was added to the "is_private" field in this mutation.
func (m *DocServerProjectMutation) AddedIsPrivate() (r int8, exists bool) {
v := m.addis_private
if v == nil {
return
}
return *v, true
}
// ResetIsPrivate resets all changes to the "is_private" field.
func (m *DocServerProjectMutation) ResetIsPrivate() {
m.is_private = nil
m.addis_private = nil
}
// SetStatus sets the "status" field.
func (m *DocServerProjectMutation) SetStatus(i int32) {
m.status = &i
......@@ -2782,7 +2840,7 @@ func (m *DocServerProjectMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *DocServerProjectMutation) Fields() []string {
fields := make([]string, 0, 9)
fields := make([]string, 0, 10)
if m.project_name != nil {
fields = append(fields, docserverproject.FieldProjectName)
}
......@@ -2804,6 +2862,9 @@ func (m *DocServerProjectMutation) Fields() []string {
if m.app_id != nil {
fields = append(fields, docserverproject.FieldAppID)
}
if m.is_private != nil {
fields = append(fields, docserverproject.FieldIsPrivate)
}
if m.status != nil {
fields = append(fields, docserverproject.FieldStatus)
}
......@@ -2832,6 +2893,8 @@ func (m *DocServerProjectMutation) Field(name string) (ent.Value, bool) {
return m.TaskID()
case docserverproject.FieldAppID:
return m.AppID()
case docserverproject.FieldIsPrivate:
return m.IsPrivate()
case docserverproject.FieldStatus:
return m.Status()
case docserverproject.FieldCreatedAt:
......@@ -2859,6 +2922,8 @@ func (m *DocServerProjectMutation) OldField(ctx context.Context, name string) (e
return m.OldTaskID(ctx)
case docserverproject.FieldAppID:
return m.OldAppID(ctx)
case docserverproject.FieldIsPrivate:
return m.OldIsPrivate(ctx)
case docserverproject.FieldStatus:
return m.OldStatus(ctx)
case docserverproject.FieldCreatedAt:
......@@ -2921,6 +2986,13 @@ func (m *DocServerProjectMutation) SetField(name string, value ent.Value) error
}
m.SetAppID(v)
return nil
case docserverproject.FieldIsPrivate:
v, ok := value.(int8)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsPrivate(v)
return nil
case docserverproject.FieldStatus:
v, ok := value.(int32)
if !ok {
......@@ -2946,6 +3018,9 @@ func (m *DocServerProjectMutation) AddedFields() []string {
if m.addapp_id != nil {
fields = append(fields, docserverproject.FieldAppID)
}
if m.addis_private != nil {
fields = append(fields, docserverproject.FieldIsPrivate)
}
if m.addstatus != nil {
fields = append(fields, docserverproject.FieldStatus)
}
......@@ -2959,6 +3034,8 @@ func (m *DocServerProjectMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case docserverproject.FieldAppID:
return m.AddedAppID()
case docserverproject.FieldIsPrivate:
return m.AddedIsPrivate()
case docserverproject.FieldStatus:
return m.AddedStatus()
}
......@@ -2977,6 +3054,13 @@ func (m *DocServerProjectMutation) AddField(name string, value ent.Value) error
}
m.AddAppID(v)
return nil
case docserverproject.FieldIsPrivate:
v, ok := value.(int8)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddIsPrivate(v)
return nil
case docserverproject.FieldStatus:
v, ok := value.(int32)
if !ok {
......@@ -3053,6 +3137,9 @@ func (m *DocServerProjectMutation) ResetField(name string) error {
case docserverproject.FieldAppID:
m.ResetAppID()
return nil
case docserverproject.FieldIsPrivate:
m.ResetIsPrivate()
return nil
case docserverproject.FieldStatus:
m.ResetStatus()
return nil
......
......@@ -102,8 +102,12 @@ func init() {
docserverprojectDescAppID := docserverprojectFields[7].Descriptor()
// docserverproject.DefaultAppID holds the default value on creation for the app_id field.
docserverproject.DefaultAppID = docserverprojectDescAppID.Default.(int32)
// docserverprojectDescIsPrivate is the schema descriptor for is_private field.
docserverprojectDescIsPrivate := docserverprojectFields[8].Descriptor()
// docserverproject.DefaultIsPrivate holds the default value on creation for the is_private field.
docserverproject.DefaultIsPrivate = docserverprojectDescIsPrivate.Default.(int8)
// docserverprojectDescStatus is the schema descriptor for status field.
docserverprojectDescStatus := docserverprojectFields[8].Descriptor()
docserverprojectDescStatus := docserverprojectFields[9].Descriptor()
// docserverproject.DefaultStatus holds the default value on creation for the status field.
docserverproject.DefaultStatus = docserverprojectDescStatus.Default.(int32)
}
......
......@@ -53,6 +53,10 @@ func (DocServerProject) Fields() []ent.Field {
dialect.MySQL: "int",
}).Default(0).Comment(`应用id`),
field.Int8("is_private").SchemaType(map[string]string{
dialect.MySQL: "tinyint",
}).Default(0).Comment(`是否公有`),
field.Int32("status").SchemaType(map[string]string{
dialect.MySQL: "int",
}).Default(0).Comment(`状态`),
......
......@@ -172,7 +172,6 @@ func (o *Conversion) Conversion(arg *DoConversionRequest) (map[string]interface{
if parseTargetErr != nil {
return ret, parseTargetErr
}
fmt.Println("24324324324324")
// query params
queries := map[string]interface{}{}
queries["ProjectName"] = arg.ProjectName
......
package service
// 脚本回调业务方
func CallBackBusiness(callbackId int32) bool {
return true
}
......@@ -5,8 +5,8 @@ import (
"doc-service/domain/entity/serversitemicros/docserverproject"
service "doc-service/domain/repository"
"doc-service/infra/db"
"fmt"
"github.com/nacos-group/nacos-sdk-go/v2/common/logger"
"gitlab.galaxy-immi.com/Backend-group/go-com/third/log"
pb "gitlab.galaxy-immi.com/Backend-group/proto/pb/docservice"
"time"
)
......@@ -33,7 +33,6 @@ func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversi
//创建项目
createErr := service.NewConversion().CreateProject()
fmt.Println(createErr)
if createErr != nil {
resp.Msg = createErr.Error()
resp.Code = 100010
......@@ -42,11 +41,17 @@ func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversi
}
//入库
isPri := 0
if req.IsPrivate {
isPri = 1
}
save, errsInfo := db.GetServerSiteMicrosDB().DocServerProject.Create().
SetProjectName(req.ProjectName).
SetCreatedAt(time.Now()).
SetSourceURL(request.SourceURI).
SetSourceType(req.SourceType).
SetTargetType(req.TargetType).
SetIsPrivate(int8(isPri)).
SetTargetURL(request.TargetURI).
Save(c)
......@@ -58,7 +63,7 @@ func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversi
}
//添加回调
_, err = db.GetServerSiteMicrosDB().DocServerCallback.Create().
back, errBack := db.GetServerSiteMicrosDB().DocServerCallback.Create().
SetCreatedAt(time.Now()).
SetCallbackData(request.CallbackData).
SetCallbackURL(request.CallbackUrl).
......@@ -66,11 +71,11 @@ func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversi
SetServerProjectID(save.ID).
Save(c)
if err != nil {
resp.Msg = err.Error()
if errBack != nil {
resp.Msg = errBack.Error()
resp.Code = 100010
resp.Data = nil
return resp, err
return resp, errBack
}
resp.Msg = "success"
......@@ -78,17 +83,21 @@ func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversi
resp.Data = &pb.DoConversionData{
Id: save.ID,
TaskId: "",
CallbackId: back.ID,
}
return resp, nil
}
// 执行文件转换(脚本使用)
func (doc *DocServiceService) DoConversionToAli(c context.Context, projectId int32) bool {
ConversionInfo, infoErr := db.GetServerSiteMicrosDB().DocServerProject.Get(c, projectId)
if infoErr != nil {
return false
}
IsPrivate := true
if ConversionInfo.IsPrivate == 0 {
IsPrivate = false
}
request := &service.DoConversionRequest{
ProjectName: ConversionInfo.ProjectName,
......@@ -96,48 +105,30 @@ func (doc *DocServiceService) DoConversionToAli(c context.Context, projectId int
TargetType: ConversionInfo.TargetType,
SourceURI: *ConversionInfo.SourceURL,
TargetURI: *ConversionInfo.TargetURL,
IsPrivate: ConversionInfo.IsPrivate,
IsPrivate: IsPrivate,
}
//创建项目
createErr := service.NewConversion().CreateProject()
if createErr != nil {
log.Info("创建项目出错" + createErr.Error())
return false
}
//执行转换
result, errs := service.NewConversion().Conversion(request)
if errs != nil {
resp.Msg = createErr.Error()
resp.Code = 100010
resp.Data = nil
return resp, err
log.Info("转换出错" + errs.Error())
return false
}
taskId := result["body"].(map[string]interface{})["TaskId"].(string)
//入库
save, errsInfo := db.GetServerSiteMicrosDB().DocServerProject.Create().
SetProjectName(req.ProjectName).
SetCreatedAt(time.Now()).
SetSourceURL(request.SourceURI).
SetSourceType(req.SourceType).
SetTargetURL(request.TargetURI).
SetTaskID(taskId).Save(c)
_, errsInfo := db.GetServerSiteMicrosDB().DocServerProject.UpdateOneID(projectId).SetTaskID(taskId).Save(c)
if errsInfo != nil {
resp.Msg = errsInfo.Error()
resp.Code = 100010
resp.Data = nil
return resp, errsInfo
}
resp.Msg = "success"
resp.Code = 200
resp.Data = &pb.DoConversionData{
Id: save.ID,
TaskId: taskId,
log.Info("入库出错" + errsInfo.Error())
return false
}
return resp, nil
return true
}
// 获取转换结果
......
......@@ -12,7 +12,10 @@ require (
github.com/alibabacloud-go/tea-utils/v2 v2.0.6
github.com/go-sql-driver/mysql v1.8.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
github.com/nacos-group/nacos-sdk-go/v2 v2.2.4
github.com/robfig/cron v1.2.0
gitlab.galaxy-immi.com/Backend-group/go-com v1.4.2-test-rc12
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240914031913-37c18f143a6d
go.uber.org/zap v1.21.0
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094
google.golang.org/grpc v1.64.0
......@@ -60,7 +63,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mozillazg/go-pinyin v0.20.0 // indirect
github.com/nacos-group/nacos-sdk-go/v2 v2.2.4 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/parnurzeal/gorequest v0.2.16 // indirect
github.com/pkg/errors v0.9.1 // indirect
......@@ -81,7 +83,6 @@ require (
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/zclconf/go-cty v1.8.0 // indirect
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913105216-6591457b3d19 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
......
......@@ -104,7 +104,6 @@ github.com/aliyun/credentials-go v1.3.1/go.mod h1:8jKYhQuDawt8x2+fusqa1Y6mPxemTs
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
......@@ -202,7 +201,6 @@ github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpv
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
......@@ -356,7 +354,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
......@@ -465,6 +462,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
......@@ -474,7 +473,6 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil/v3 v3.21.6 h1:vU7jrp1Ic/2sHB7w6UNs7MIkn7ebVtTb5D9j45o9VYE=
github.com/shirou/gopsutil/v3 v3.21.6/go.mod h1:JfVbDpIBLVzT8oKbvMg9P3wEIMDDpVn+LwHTKj0ST88=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
......@@ -545,27 +543,10 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA=
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
gitlab.galaxy-immi.com/Backend-group/go-com v1.4.2-test-rc12 h1:bzReHSzFXDEDY63QL0VDMfcfAL8MYm7I4h6iB6qIAeY=
gitlab.galaxy-immi.com/Backend-group/go-com v1.4.2-test-rc12/go.mod h1:Wyfqynjmd55ApRDPxuFOlOwcYhS+L0LZU4oExla7+Lw=
gitlab.galaxy-immi.com/Backend-group/proto v1.6.31-test-rc7 h1:+VWYjaAlEOztKmFxZnhQvreUreYTyndSt9lKkJTSers=
gitlab.galaxy-immi.com/Backend-group/proto v1.6.31-test-rc7/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913021148-7b04b3f8b54c h1:hpq3YUnjU6xEquL/Xr2FBqD+poT+FOx0BOdVtKvgLZk=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913021148-7b04b3f8b54c/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913024000-a982660f14ac h1:010Dii9aRY8rZ8zbLIy5X8FD+optcGKLRSxMd+aswb8=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913024000-a982660f14ac/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913031009-a5919c6b0055 h1:myVSbH6V/gEP1jDYGypAQuKFaoQTHQqTvApjDahA3Fc=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913031009-a5919c6b0055/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913032051-277c2f16a798 h1:905lnaETrbPjiPexZ7ArCTEeFK8sqVIolwdhgtIHBxE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913032051-277c2f16a798/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913053623-1b403c8f08e2 h1:RWSf9MntpTBUFNiF6Bw6La7Af1TIIfhEiVOlo0ZYYk4=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913053623-1b403c8f08e2/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913054214-762767e8ba9e h1:d4L+kDc8w5Aha9kf9pMd3bF1/j+H7sQ/wmducpXCtpA=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913054214-762767e8ba9e/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913063110-b668f029e9c5 h1:RjVYcLotQxjcBVm4eeA1HoQaCb1Xb9lGcRX/O3EgpyQ=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913063110-b668f029e9c5/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913105216-6591457b3d19 h1:WQcvVIQC/9TgEfRn0Rtk4iu9LsykFCdzxSaBWDedsGg=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240913105216-6591457b3d19/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240914031913-37c18f143a6d h1:ceqoQcF4aT0Uo3vR3yB4IVqbrWiJwY4/Tawfc/6hrOs=
gitlab.galaxy-immi.com/Backend-group/proto v1.10.11-0.20240914031913-37c18f143a6d/go.mod h1:vXZLtbzFvAjc86DXqO8LdYjBkMGc5fVh5XGe2bi4FqE=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
......
......@@ -3,6 +3,7 @@ package main
import (
"context"
"doc-service/console"
repository "doc-service/domain/repository"
"doc-service/domain/service"
"doc-service/infra/db"
......@@ -163,19 +164,16 @@ func run() error {
}
nacos.RegisterService(localIP, projectConf.GrpcPort, *serviceName)
srv := &http.Server{
Addr: httpPort,
Handler: tool.HttpInterceptor(serviceMux),
}
handleSignal(ctx, srv, grpcServer, localIP, projectConf)
return srv.ListenAndServe()
}
func main() {
fmt.Println("bessssss")
go console.DoAliData()
if err := run(); err != nil && !errors.Is(err, http.ErrServerClosed) {
panic(err)
}
......
syntax = "proto3";
package cuser;
option go_package = "gitlab.galaxy-immi.com/Backend-group/proto/pb/cuser";
option java_package = "com.cuser.pb";
// List 接口
message ListDocServerProjectRequest {
int32 id = 1[json_name="id"];// id
string projectName = 2[json_name="project_name"];// 项目名称
string sourceType = 3[json_name="source_type"];// 来源类型
string targetType = 4[json_name="target_type"];// 文件类型
string sourceURL = 5[json_name="source_url"];// 原url
string targetURL = 6[json_name="target_url"];// 目标url
string taskID = 7[json_name="task_id"];// 返回的文件转换任务id
int32 appID = 8[json_name="app_id"];// 应用id
int64 isPrivate = 9[json_name="is_private"];// 是否公有
int32 status = 10[json_name="status"];// 状态
string createdAt = 11[json_name="created_at"];// 创建时间
}
message DocServerProjectItem {
int32 id = 1[json_name="id"];// id
string projectName = 2[json_name="project_name"];// 项目名称
string sourceType = 3[json_name="source_type"];// 来源类型
string targetType = 4[json_name="target_type"];// 文件类型
optional string sourceURL = 5[json_name="source_url"];// 原url
optional string targetURL = 6[json_name="target_url"];// 目标url
string taskID = 7[json_name="task_id"];// 返回的文件转换任务id
int32 appID = 8[json_name="app_id"];// 应用id
int64 isPrivate = 9[json_name="is_private"];// 是否公有
int32 status = 10[json_name="status"];// 状态
optional string createdAt = 11[json_name="created_at"];// 创建时间
}
message ListDocServerProjectResponse {
int32 code = 1;
string msg = 2;
repeated DocServerProjectItem data = 3;
}
// Del 接口
message DelDocServerProjectRequest {
int32 id = 3[json_name="id"]; // id
}
message DelDocServerProjectResponse {
int32 code = 1;
string msg = 2;
int32 id = 3[json_name="id"]; // id
}
// Add 接口
message AddDocServerProjectRequest {
int32 id = 1[json_name="id"];// id
string projectName = 2[json_name="project_name"];// 项目名称
string sourceType = 3[json_name="source_type"];// 来源类型
string targetType = 4[json_name="target_type"];// 文件类型
optional string sourceURL = 5[json_name="source_url"];// 原url
optional string targetURL = 6[json_name="target_url"];// 目标url
string taskID = 7[json_name="task_id"];// 返回的文件转换任务id
int32 appID = 8[json_name="app_id"];// 应用id
int64 isPrivate = 9[json_name="is_private"];// 是否公有
int32 status = 10[json_name="status"];// 状态
optional string createdAt = 11[json_name="created_at"];// 创建时间
}
message AddDocServerProjectResponse {
int32 code = 1;
string msg = 2;
int32 id = 3[json_name="id"]; // id
}
// Edit 接口
message EditDocServerProjectRequest {
int32 id = 1[json_name="id"];// id
string projectName = 2[json_name="project_name"];// 项目名称
string sourceType = 3[json_name="source_type"];// 来源类型
string targetType = 4[json_name="target_type"];// 文件类型
optional string sourceURL = 5[json_name="source_url"];// 原url
optional string targetURL = 6[json_name="target_url"];// 目标url
string taskID = 7[json_name="task_id"];// 返回的文件转换任务id
int32 appID = 8[json_name="app_id"];// 应用id
int64 isPrivate = 9[json_name="is_private"];// 是否公有
int32 status = 10[json_name="status"];// 状态
optional string createdAt = 11[json_name="created_at"];// 创建时间
}
message EditDocServerProjectResponse {
int32 code = 1;
string msg = 2;
int32 id = 3[json_name="id"];// id
}
// Detail 接口
message DetailDocServerProjectRequest {
int32 id = 1[json_name="id"]; // id
}
message DetailDocServerProjectResponse {
int32 code = 1;
string msg = 2;
DocServerProjectItem data = 3;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment