package logic import ( "context" "errors" "fmt" "github.com/fonchain_enterprise/fonchain-main/api/approval" "github.com/fonchain_enterprise/fonchain-main/pkg/es" "github.com/fonchain_enterprise/fonchain-main/pkg/service/es_service/approval/common" "github.com/fonchain_enterprise/fonchain-main/pkg/service/es_service/approval/model" "github.com/jinzhu/copier" "go.uber.org/zap" ) func UpdateIndexApprovalDoc(index string, approval *approval.CreateRequest) error { if approval.ID == 0 { return nil } doc := model.EsApproval{} copyWithOptionErr := copier.CopyWithOption(&doc, approval, copier.Option{DeepCopy: true}) if copyWithOptionErr != nil { fmt.Println("======================= CopyWithOption es err =======================") fmt.Println("err : ", copyWithOptionErr.Error()) zap.L().Error("UpdateIndexApprovalDoc CopyWithOption", zap.Error(copyWithOptionErr)) fmt.Println("======================= CopyWithOption es err =======================") return errors.New(common.ErrorCopierApproval) } _, updateErr := es.ElasticClient.Update().Index(index).Id(fmt.Sprintf("%d", approval.ID)).Doc(doc).Do(context.Background()) if updateErr != nil { fmt.Println("======================= Update es err =======================") fmt.Println("err : ", updateErr.Error()) zap.L().Error("UpdateIndexApprovalDoc Update", zap.Error(updateErr)) fmt.Println("======================= Update es err =======================") return errors.New(common.ErrorUpdateApproval) } return nil } func DeleteIndexApprovalDoc(index string, id uint64) error { if id == 0 { return nil } _, deleteErr := es.ElasticClient.Delete().Index(index).Id(fmt.Sprintf("%d", id)).Do(context.Background()) if deleteErr != nil { fmt.Println("======================= Delete es err =======================") fmt.Println("err : ", deleteErr.Error()) zap.L().Error("DeleteIndexApprovalDoc Delete", zap.Error(deleteErr)) fmt.Println("======================= Delete es err =======================") return errors.New(common.ErrorDeleteApproval) } return nil }