作者 庄敏学

merge

正在显示 45 个修改的文件 包含 2457 行增加148 行删除
@@ -2,17 +2,18 @@ package main @@ -2,17 +2,18 @@ package main
2 2
3 import ( 3 import (
4 "flag" 4 "flag"
  5 + "github.com/golang-jwt/jwt/v4/request"
  6 + "github.com/zeromicro/go-queue/kq"
5 "github.com/zeromicro/go-zero/core/logx" 7 "github.com/zeromicro/go-zero/core/logx"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/config"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/consumer"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db" 12 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain" 13 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
8 "net/http" 14 "net/http"
9 "strings" 15 "strings"
10 -  
11 - "github.com/golang-jwt/jwt/v4/request"  
12 -  
13 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/config"  
14 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler"  
15 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc" 16 + "time"
16 17
17 "github.com/zeromicro/go-zero/core/conf" 18 "github.com/zeromicro/go-zero/core/conf"
18 "github.com/zeromicro/go-zero/rest" 19 "github.com/zeromicro/go-zero/rest"
@@ -56,7 +57,60 @@ func main() { @@ -56,7 +57,60 @@ func main() {
56 handler.RegisterHandlers(server, ctx) 57 handler.RegisterHandlers(server, ctx)
57 58
58 db.Migrate(ctx.DB) 59 db.Migrate(ctx.DB)
  60 + //启动消费队列
  61 + startConsume(c)
59 62
60 logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port) 63 logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port)
61 server.Start() 64 server.Start()
62 } 65 }
  66 +
  67 +func startConsume(c config.Config) {
  68 + //svcCtx := svc.NewServiceContext(c)
  69 + go func() {
  70 + //for {
  71 + // notice := &domain.ObjectNotice{
  72 + // CompanyId: 1598224576532189184,
  73 + // TableId: 521,
  74 + // TableType: "主表",
  75 + // ObjectType: "导入模块",
  76 + // Event: "table.data.edit",
  77 + // TableAffectedList: []int{521},
  78 + // DataChanged: true,
  79 + // StructChanged: true,
  80 + // MetaData: domain.ObjectNoticeMetaData{
  81 + // Module: 0,
  82 + // Status: 0,
  83 + // },
  84 + // }
  85 + // mBytes, _ := json.Marshal(notice)
  86 + // err := kq.NewPusher(c.KqConsumerConf.Brokers, c.KqConsumerConf.Topic).Push(string(mBytes))
  87 + // fmt.Println(err)
  88 + // time.Sleep(10 * 10 * time.Second)
  89 + //}
  90 + }()
  91 + //kafka消费队列 处理字库推送事件
  92 + go func() {
  93 + svcCtx := svc.NewServiceContext(c)
  94 + queue, err := kq.NewQueue(c.KqConsumerConf, consumer.NewByteNoticeLogic(svcCtx))
  95 + if err != nil {
  96 + panic(err)
  97 + } else {
  98 + queue.Start()
  99 + }
  100 + }()
  101 + //redis消费队列 处理表数据存储到本地
  102 + go func() {
  103 + for {
  104 + svcCtx := svc.NewServiceContext(c)
  105 + str, err := svcCtx.Redis.Rpop(c.Name + ":table_data")
  106 + if err == nil {
  107 + _ = consumer.NewByteTableDataLogic(svcCtx).Sync(str)
  108 + }
  109 + time.Sleep(3 * time.Second)
  110 + }
  111 + }()
  112 + //kq.MustNewQueue(c.KqConsumerConf, consumer.NewByteNoticeLogic(svcCtx))
  113 + //for {
  114 + //time.Sleep(1 * time.Second)
  115 + //}
  116 +}
@@ -25,4 +25,11 @@ DB: @@ -25,4 +25,11 @@ DB:
25 ByteMetadata: 25 ByteMetadata:
26 Name: ApiByteMetadata 26 Name: ApiByteMetadata
27 Host: http://character-library-metadata-bastion-test.fjmaimaimai.com 27 Host: http://character-library-metadata-bastion-test.fjmaimaimai.com
28 - Timeout: 0s  
  28 + Timeout: 0s
  29 +KqConsumerConf:
  30 + Name: KqConsumer
  31 + Brokers:
  32 + - 47.97.5.102:9092
  33 + Group: bchart_dev
  34 + Topic: allied_creation_metadata_table_sync_notice
  35 + Processors: 1
@@ -28,4 +28,12 @@ ByteMetadata: @@ -28,4 +28,12 @@ ByteMetadata:
28 Name: ApiByteMetadata 28 Name: ApiByteMetadata
29 Host1: http://127.0.0.1:8080 29 Host1: http://127.0.0.1:8080
30 Host: http://character-library-metadata-bastion-test.fjmaimaimai.com 30 Host: http://character-library-metadata-bastion-test.fjmaimaimai.com
31 - Timeout: 0s  
  31 + Timeout: 0s
  32 +
  33 +KqConsumerConf:
  34 + Name: KqConsumer
  35 + Brokers:
  36 + - 47.97.5.102:9092
  37 + Group: bchart_dev
  38 + Topic: allied_creation_metadata_table_sync_notice
  39 + Processors: 1
1 package config 1 package config
2 2
3 import ( 3 import (
  4 + "github.com/zeromicro/go-queue/kq"
4 "github.com/zeromicro/go-zero/core/stores/redis" 5 "github.com/zeromicro/go-zero/core/stores/redis"
5 "github.com/zeromicro/go-zero/rest" 6 "github.com/zeromicro/go-zero/rest"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/config" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/config"
@@ -10,9 +11,10 @@ import ( @@ -10,9 +11,10 @@ import (
10 type Config struct { 11 type Config struct {
11 rest.RestConf 12 rest.RestConf
12 config.Config 13 config.Config
13 - Redis redis.RedisConf `json:",optional"`  
14 - ByteMetadata ApiService  
15 - HostName string // 服务域名 14 + Redis redis.RedisConf `json:",optional"`
  15 + ByteMetadata ApiService
  16 + HostName string // 服务域名
  17 + KqConsumerConf kq.KqConf
16 } 18 }
17 19
18 type ApiService struct { 20 type ApiService struct {
@@ -95,6 +95,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -95,6 +95,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
95 Path: "/table/data", 95 Path: "/table/data",
96 Handler: table.SearchTableDataHandler(serverCtx), 96 Handler: table.SearchTableDataHandler(serverCtx),
97 }, 97 },
  98 + {
  99 + Method: http.MethodGet,
  100 + Path: "/table/sync",
  101 + Handler: table.SyncTableHandler(serverCtx),
  102 + },
98 }, 103 },
99 rest.WithPrefix("/v1"), 104 rest.WithPrefix("/v1"),
100 ) 105 )
  1 +package table
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/table"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
  9 +)
  10 +
  11 +func SyncTableHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  12 + return func(w http.ResponseWriter, r *http.Request) {
  13 + l := table.NewSyncTableLogic(r.Context(), svcCtx)
  14 + resp, err := l.SyncTable()
  15 + if err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + } else {
  18 + httpx.OkJsonCtx(r.Context(), w, resp)
  19 + }
  20 + }
  21 +}
@@ -2,6 +2,7 @@ package chart @@ -2,6 +2,7 @@ package chart
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "encoding/json"
5 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
@@ -89,6 +90,16 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha @@ -89,6 +90,16 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha
89 }, true); err != nil { 90 }, true); err != nil {
90 return nil, xerr.NewErrMsgErr("创建失败", err) 91 return nil, xerr.NewErrMsgErr("创建失败", err)
91 } 92 }
  93 + if len(chartSetting.DataSourceIds) > 0 {
  94 + for _, sourceId := range chartSetting.DataSourceIds {
  95 + pusher := &types.SyncTableDataPusher{
  96 + CompanyId: tenantId,
  97 + ObjectId: int(sourceId),
  98 + }
  99 + mBytes, _ := json.Marshal(pusher)
  100 + _, _ = l.svcCtx.Redis.LpushCtx(l.ctx, l.svcCtx.Config.Name+":table_data", string(mBytes))
  101 + }
  102 + }
92 resp = &types.ChartSaveResponse{ 103 resp = &types.ChartSaveResponse{
93 Chart: types.NewChartItemWithSetting(chart, chartSetting), 104 Chart: types.NewChartItemWithSetting(chart, chartSetting),
94 } 105 }
@@ -2,6 +2,8 @@ package chart @@ -2,6 +2,8 @@ package chart
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "encoding/json"
  6 + "github.com/samber/lo"
5 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
@@ -41,6 +43,7 @@ func (l *UpdateChartLogic) UpdateChart(req *types.ChartUpdateRequest) (resp *typ @@ -41,6 +43,7 @@ func (l *UpdateChartLogic) UpdateChart(req *types.ChartUpdateRequest) (resp *typ
41 if chartSetting, err = l.svcCtx.ChartSettingRepository.FindOne(l.ctx, conn, req.Id); err != nil { 43 if chartSetting, err = l.svcCtx.ChartSettingRepository.FindOne(l.ctx, conn, req.Id); err != nil {
42 return nil, xerr.NewErrMsgErr("图表配置不存在", err) 44 return nil, xerr.NewErrMsgErr("图表配置不存在", err)
43 } 45 }
  46 + oldDataSource := chartSetting.DataSourceIds
44 47
45 if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { 48 if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
46 if len(req.Cover) > 0 && chart.Cover != req.Cover { 49 if len(req.Cover) > 0 && chart.Cover != req.Cover {
@@ -54,9 +57,36 @@ func (l *UpdateChartLogic) UpdateChart(req *types.ChartUpdateRequest) (resp *typ @@ -54,9 +57,36 @@ func (l *UpdateChartLogic) UpdateChart(req *types.ChartUpdateRequest) (resp *typ
54 chartSetting.TableAbility = chartProperty.TableAbility 57 chartSetting.TableAbility = chartProperty.TableAbility
55 chartSetting.Series = chartProperty.Series 58 chartSetting.Series = chartProperty.Series
56 chartSetting.Other = chartProperty.Other 59 chartSetting.Other = chartProperty.Other
  60 + chartSetting.DataSourceIds = chartProperty.GetAllDataSourceId()
57 if chartSetting, err = l.svcCtx.ChartSettingRepository.UpdateWithVersion(l.ctx, conn, chartSetting); err != nil { 61 if chartSetting, err = l.svcCtx.ChartSettingRepository.UpdateWithVersion(l.ctx, conn, chartSetting); err != nil {
58 return err 62 return err
59 } 63 }
  64 + //对比更新前后数据源
  65 + left, right := lo.Difference(chartSetting.DataSourceIds, oldDataSource)
  66 + //同步
  67 + if len(left) > 0 {
  68 + for _, sourceId := range left {
  69 + pusher := &types.SyncTableDataPusher{
  70 + CompanyId: tenantId,
  71 + ObjectId: int(sourceId),
  72 + }
  73 + mBytes, _ := json.Marshal(pusher)
  74 + _, _ = l.svcCtx.Redis.LpushCtx(l.ctx, l.svcCtx.Config.Name+":table_data", string(mBytes))
  75 + }
  76 + }
  77 + //删除
  78 + if len(right) > 0 {
  79 + for _, sourceId := range right {
  80 + //验证其他图表是否使用
  81 + used, err := l.svcCtx.ChartSettingRepository.CheckUseDataSource(l.ctx, conn, int(sourceId))
  82 + if err == nil && !used { //未使用,删除
  83 + err = l.svcCtx.ObjectTableDataRepository.DropTable(l.ctx, conn, int(sourceId))
  84 + if err != nil {
  85 + return err
  86 + }
  87 + }
  88 + }
  89 + }
60 return nil 90 return nil
61 }, true); err != nil { 91 }, true); err != nil {
62 return nil, xerr.NewErrMsgErr("创建失败", err) 92 return nil, xerr.NewErrMsgErr("创建失败", err)
  1 +package consumer
  2 +
  3 +import (
  4 + "context"
  5 + "encoding/json"
  6 + "fmt"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  12 +)
  13 +
  14 +type ByteNoticeLogic struct {
  15 + ctx context.Context
  16 + svcCtx *svc.ServiceContext
  17 + conn transaction.Conn
  18 +}
  19 +
  20 +func NewByteNoticeLogic(svcCtx *svc.ServiceContext) *ByteNoticeLogic {
  21 + return &ByteNoticeLogic{
  22 + ctx: context.Background(),
  23 + svcCtx: svcCtx,
  24 + conn: svcCtx.DefaultDBConn(),
  25 + }
  26 +}
  27 +
  28 +func (logic *ByteNoticeLogic) Consume(key, value string) error {
  29 + fmt.Println(key, value)
  30 + notice := &domain.ObjectNotice{}
  31 + err := json.Unmarshal([]byte(value), notice)
  32 + if err != nil {
  33 + return err
  34 + }
  35 + //保存推送消息
  36 + _, err = logic.svcCtx.ObjectNoticeRepository.Insert(logic.ctx, logic.conn, notice)
  37 + if err != nil {
  38 + return err
  39 + }
  40 + //处理消息
  41 + err = transaction.UseTrans(logic.ctx, logic.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
  42 + return logic.handleNotice(conn, notice)
  43 + }, true)
  44 + //更新处理结果
  45 + if err != nil {
  46 + notice.Status = domain.ObjectNoticeStatusError
  47 + notice.Message = err.Error()
  48 + } else {
  49 + notice.Status = domain.ObjectNoticeStatusDone
  50 + notice.Message = "OK"
  51 + }
  52 + _, _ = logic.svcCtx.ObjectNoticeRepository.Update(logic.ctx, logic.conn, notice)
  53 + return err
  54 +}
  55 +
  56 +// handleNotice 处理消息
  57 +func (logic *ByteNoticeLogic) handleNotice(conn transaction.Conn, notice *domain.ObjectNotice) error {
  58 + //是否删除消息
  59 + if notice.IsDeletedEvent() {
  60 + return logic.handleDelete(conn, notice)
  61 + }
  62 + accessToken, _ := types.TableAccessToken{CompanyId: notice.CompanyId}.GenerateToken()
  63 + //结构变更
  64 + if notice.StructChanged {
  65 + request := bytelib.ObjectTableSearchRequest{
  66 + Token: accessToken,
  67 + Module: bytelib.ModuleDigitalCenter,
  68 + }
  69 + if notice.ObjectType == "导入模块" {
  70 + request.TableTypes = []string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable}
  71 + }
  72 + if notice.ObjectType == "拆解模块" {
  73 + request.TableTypes = []string{bytelib.SchemaTable}
  74 + request.ReturnGroupItem = true
  75 + }
  76 + if notice.ObjectType == "计算模块" {
  77 + request.TableTypes = []string{bytelib.CalculateItem, bytelib.CalculateSet}
  78 + request.ReturnGroupItem = true
  79 + request.ExcludeTables = []int{0}
  80 + }
  81 + list, err := logic.svcCtx.ByteMetadataService.ObjectTableSearch(logic.ctx, request)
  82 + if err != nil {
  83 + return err
  84 + }
  85 + tableInfo, err := logic.svcCtx.ByteMetadataService.TableInfo(logic.ctx, &bytelib.TableInfoRequest{
  86 + Token: accessToken,
  87 + TableId: notice.TableId,
  88 + })
  89 + if err != nil {
  90 + return nil
  91 + }
  92 + if len(list.List) > 0 {
  93 + objectTables := make([]*domain.ObjectTable, 0)
  94 + for _, item := range list.List {
  95 + if item.TableId == notice.TableId {
  96 + objectTables = append(objectTables, &domain.ObjectTable{
  97 + Id: item.Id,
  98 + TableId: item.TableId,
  99 + Name: item.Name,
  100 + TableType: item.TableType,
  101 + CompanyId: notice.CompanyId,
  102 + ParentId: item.ParentId,
  103 + Flag: item.Flag,
  104 + })
  105 + //父级节点
  106 + objectTables = append(objectTables, logic.getParents(notice.CompanyId, item.ParentId, list.List)...)
  107 + }
  108 + }
  109 + err = logic.saveTables(conn, objectTables)
  110 + if err != nil {
  111 + return err
  112 + }
  113 + }
  114 + //保存字段
  115 + _, err = logic.saveFields(conn, &domain.ObjectField{
  116 + Id: int64(tableInfo.TableId),
  117 + Name: tableInfo.Name,
  118 + Fields: tableInfo.Fields,
  119 + })
  120 + if err != nil {
  121 + return err
  122 + }
  123 + }
  124 + //数据变更
  125 + if notice.DataChanged {
  126 + data := &types.SyncTableDataPusher{
  127 + CompanyId: notice.CompanyId,
  128 + ObjectId: notice.TableId,
  129 + }
  130 + mBytes, _ := json.Marshal(data)
  131 + _, err := logic.svcCtx.Redis.LpushCtx(logic.ctx, logic.svcCtx.Config.Name+":table_data", string(mBytes))
  132 + return err
  133 + }
  134 + return nil
  135 +}
  136 +
  137 +func (logic *ByteNoticeLogic) getParents(companyId int64, parentId int, list []*bytelib.Table) []*domain.ObjectTable {
  138 + result := make([]*domain.ObjectTable, 0)
  139 + for _, item := range list {
  140 + if item.Id == parentId {
  141 + result = append(result, &domain.ObjectTable{
  142 + Id: item.Id,
  143 + TableId: item.TableId,
  144 + Name: item.Name,
  145 + TableType: item.TableType,
  146 + CompanyId: companyId,
  147 + ParentId: item.ParentId,
  148 + Flag: item.Flag,
  149 + })
  150 + if item.ParentId > 0 {
  151 + result = append(result, logic.getParents(companyId, item.ParentId, list)...)
  152 + }
  153 + }
  154 + }
  155 + return result
  156 +}
  157 +
  158 +// handleDelete 删除
  159 +func (logic *ByteNoticeLogic) handleDelete(conn transaction.Conn, notice *domain.ObjectNotice) error {
  160 + objectTable, err := logic.svcCtx.ObjectTableRepository.FindOneByTableId(logic.ctx, conn, notice.TableId)
  161 + if err == nil && objectTable.Id > 0 {
  162 + objectTable.RemoteDeleted = 1
  163 + _, err := logic.svcCtx.ObjectTableRepository.Update(logic.ctx, conn, objectTable)
  164 + if err != nil {
  165 + return err
  166 + }
  167 + }
  168 + //是否有使用数据源
  169 + used, err := logic.svcCtx.ChartSettingRepository.CheckUseDataSource(logic.ctx, conn, notice.TableId)
  170 + if err == nil && !used {
  171 + err = logic.svcCtx.ObjectTableDataRepository.DropTable(logic.ctx, conn, notice.TableId)
  172 + if err != nil {
  173 + return err
  174 + }
  175 + }
  176 + return nil
  177 +}
  178 +
  179 +// saveTables 保存表结构
  180 +func (logic *ByteNoticeLogic) saveTables(conn transaction.Conn, tables []*domain.ObjectTable) error {
  181 + if len(tables) > 0 {
  182 + for _, item := range tables {
  183 + objectTable, err := logic.svcCtx.ObjectTableRepository.FindOne(logic.ctx, conn, item.Id)
  184 + if err == nil && objectTable.Id > 0 {
  185 + item.Id = objectTable.Id
  186 + item.Version = objectTable.Version + 1
  187 + _, err := logic.svcCtx.ObjectTableRepository.Update(logic.ctx, conn, item)
  188 + if err != nil {
  189 + return err
  190 + }
  191 + } else {
  192 + _, err := logic.svcCtx.ObjectTableRepository.Insert(logic.ctx, conn, item)
  193 + if err != nil {
  194 + return err
  195 + }
  196 + }
  197 + }
  198 + }
  199 + return nil
  200 +}
  201 +
  202 +// saveFields 保存表字段
  203 +func (logic *ByteNoticeLogic) saveFields(conn transaction.Conn, objectField *domain.ObjectField) (*domain.ObjectField, error) {
  204 + mField, err := logic.svcCtx.ObjectFieldRepository.FindOne(logic.ctx, conn, objectField.Id)
  205 + if err == nil && mField.Id > 0 { //已存在 - 更新
  206 + objectField.Version = mField.Version + 1
  207 + return logic.svcCtx.ObjectFieldRepository.Update(logic.ctx, conn, objectField)
  208 + } else {
  209 + return logic.svcCtx.ObjectFieldRepository.Insert(logic.ctx, conn, objectField)
  210 + }
  211 +}
  1 +package consumer
  2 +
  3 +import (
  4 + "context"
  5 + "encoding/json"
  6 + "github.com/pkg/errors"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  11 +)
  12 +
  13 +type ByteTableDataLogic struct {
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewByteTableDataLogic(svcCtx *svc.ServiceContext) *ByteTableDataLogic {
  19 + return &ByteTableDataLogic{
  20 + svcCtx: svcCtx,
  21 + ctx: context.Background(),
  22 + }
  23 +}
  24 +
  25 +func (logic *ByteTableDataLogic) Sync(pusherStr string) error {
  26 + pusher := &types.SyncTableDataPusher{}
  27 + err := json.Unmarshal([]byte(pusherStr), pusher)
  28 + if err != nil {
  29 + return err
  30 + }
  31 + conn := logic.svcCtx.DefaultDBConn()
  32 + accessToken, _ := types.TableAccessToken{CompanyId: pusher.CompanyId}.GenerateToken()
  33 + tableDataPreview, err := logic.svcCtx.ByteMetadataService.TableDataPreview(logic.ctx, &bytelib.TableDataPreviewRequest{
  34 + Token: accessToken,
  35 + ObjectId: int64(pusher.ObjectId),
  36 + ObjectType: bytelib.ObjectMetaTable,
  37 + Where: &bytelib.TableQueryWhere{
  38 + PageNumber: 1,
  39 + PageSize: bytelib.MaxPageSize,
  40 + },
  41 + UseCache: true,
  42 + HiddenData: false,
  43 + })
  44 + if err != nil {
  45 + return err
  46 + }
  47 + err = transaction.UseTrans(logic.ctx, conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
  48 + err = logic.svcCtx.ObjectTableDataRepository.InsertWithTableData(logic.ctx, conn, bytelib.TableData(tableDataPreview))
  49 + if err != nil {
  50 + return err
  51 + }
  52 + //更新标记本地存储
  53 + err = logic.updateTableWithLocal(conn, int(tableDataPreview.ObjectId))
  54 + if err != nil {
  55 + return err
  56 + }
  57 + return nil
  58 + }, true)
  59 + return err
  60 +}
  61 +
  62 +// updateTableWithLocal 更新表标记本地存储
  63 +func (logic *ByteTableDataLogic) updateTableWithLocal(conn transaction.Conn, tableId int) error {
  64 + objectTable, err := logic.svcCtx.ObjectTableRepository.FindOneByTableId(logic.ctx, conn, tableId)
  65 + if err == nil && objectTable.Id > 0 {
  66 + objectTable.IsLocal = true
  67 + _, err = logic.svcCtx.ObjectTableRepository.Update(logic.ctx, conn, objectTable)
  68 + return err
  69 + }
  70 + return errors.New("表不存在")
  71 +}
@@ -26,6 +26,11 @@ func NewGetTableDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge @@ -26,6 +26,11 @@ func NewGetTableDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
26 } 26 }
27 27
28 func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (resp interface{}, err error) { 28 func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (resp interface{}, err error) {
  29 + //获取本地数据
  30 + local, err := l.GetLocal(req.TableId)
  31 + if err == nil {
  32 + return local, nil
  33 + }
29 response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{TableId: req.TableId, Token: req.Token}) 34 response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{TableId: req.TableId, Token: req.Token})
30 if err != nil { 35 if err != nil {
31 logx.Error(err) 36 logx.Error(err)
@@ -35,3 +40,25 @@ func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) ( @@ -35,3 +40,25 @@ func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (
35 resp = response 40 resp = response
36 return 41 return
37 } 42 }
  43 +
  44 +func (l *GetTableDetailLogic) GetLocal(tableId int) (interface{}, error) {
  45 + conn := l.svcCtx.DefaultDBConn()
  46 + //查询表数据
  47 + objectTable, err := l.svcCtx.ObjectTableRepository.FindOneByTableId(l.ctx, conn, tableId)
  48 + if err != nil || objectTable.Id <= 0 {
  49 + return nil, xerr.NewErrMsg("表不存在")
  50 + }
  51 + //查询表字段
  52 + objectField, err := l.svcCtx.ObjectFieldRepository.FindOne(l.ctx, conn, int64(tableId))
  53 + if err != nil || objectField.Id <= 0 {
  54 + return nil, xerr.NewErrMsg("表字段不存在")
  55 + }
  56 + resp := bytelib.TableInfoResponse{
  57 + TableId: objectTable.TableId,
  58 + TableType: objectTable.TableType,
  59 + Name: objectTable.Name,
  60 + ParentId: objectTable.ParentId,
  61 + Fields: removeIdField(objectField.Fields),
  62 + }
  63 + return resp, nil
  64 +}
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
11 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr" 12 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
12 ) 13 )
13 14
@@ -29,50 +30,86 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM @@ -29,50 +30,86 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM
29 var result = make(map[string]interface{}) 30 var result = make(map[string]interface{})
30 var batchError errorx.BatchError 31 var batchError errorx.BatchError
31 fx.Parallel(func() { 32 fx.Parallel(func() {
32 - list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{  
33 - Token: req.Token,  
34 - TableTypes: []string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable},  
35 - Module: bytelib.ModuleChartTemplate,  
36 - }) 33 + mResp, err := l.getTableByLocal([]string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable})
37 if err != nil { 34 if err != nil {
38 batchError.Add(err) 35 batchError.Add(err)
39 } 36 }
40 - result["导入模块"] = newList(list) 37 + result["导入模块"] = mResp
  38 + //if err == nil {
  39 + // result["导入模块"] = mResp
  40 + //} else {
  41 + // list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
  42 + // Token: req.Token,
  43 + // TableTypes: []string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable},
  44 + // Module: bytelib.ModuleChartTemplate, // TODO:字库更新完改为只查 bytelib.ModuleChartTemplate
  45 + // })
  46 + // if err != nil {
  47 + // batchError.Add(err)
  48 + // }
  49 + // result["导入模块"] = newList(list)
  50 + //}
41 }, func() { 51 }, func() {
42 - list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{  
43 - Token: req.Token,  
44 - TableTypes: []string{bytelib.SchemaTable},  
45 - Module: bytelib.ModuleQuerySetCenter,  
46 - ReturnGroupItem: true,  
47 - }) 52 + mResp, err := l.getTableByLocal([]string{bytelib.SchemaTable})
48 if err != nil { 53 if err != nil {
49 batchError.Add(err) 54 batchError.Add(err)
50 } 55 }
51 - result["拆解模块"] = newList(list) 56 + result["拆解模块"] = mResp
  57 + //if err == nil {
  58 + // result["拆解模块"] = mResp
  59 + //} else {
  60 + // list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
  61 + // Token: req.Token,
  62 + // TableTypes: []string{bytelib.SchemaTable},
  63 + // Module: bytelib.ModuleQuerySetCenter,
  64 + // ReturnGroupItem: true,
  65 + // })
  66 + // if err != nil {
  67 + // batchError.Add(err)
  68 + // }
  69 + // result["拆解模块"] = newList(list)
  70 + //}
52 }, func() { 71 }, func() {
53 - list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{  
54 - Token: req.Token,  
55 - TableTypes: []string{bytelib.CalculateItem},  
56 - Module: bytelib.ModuleCalculateCenter,  
57 - ReturnGroupItem: true,  
58 - ExcludeTables: []int{0},  
59 - }) 72 + mResp, err := l.getTableByLocal([]string{bytelib.CalculateItem})
60 if err != nil { 73 if err != nil {
61 batchError.Add(err) 74 batchError.Add(err)
62 } 75 }
63 - result["计算项"] = newList(list) 76 + result["计算项"] = mResp
  77 + //if err == nil {
  78 + // result["计算项"] = mResp
  79 + //} else {
  80 + // list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
  81 + // Token: req.Token,
  82 + // TableTypes: []string{bytelib.CalculateItem},
  83 + // Module: bytelib.ModuleCalculateCenter,
  84 + // ReturnGroupItem: true,
  85 + // ExcludeTables: []int{0},
  86 + // })
  87 + // if err != nil {
  88 + // batchError.Add(err)
  89 + // }
  90 + // result["计算项"] = newList(list)
  91 + //}
64 }, func() { 92 }, func() {
65 - list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{  
66 - Token: req.Token,  
67 - TableTypes: []string{bytelib.CalculateSet},  
68 - Module: bytelib.ModuleCalculateCenter,  
69 - ReturnGroupItem: true,  
70 - ExcludeTables: []int{0},  
71 - }) 93 + mResp, err := l.getTableByLocal([]string{bytelib.CalculateSet})
72 if err != nil { 94 if err != nil {
73 batchError.Add(err) 95 batchError.Add(err)
74 } 96 }
75 - result["计算集"] = newList(list) 97 + result["计算集"] = mResp
  98 + //if err == nil {
  99 + // result["计算集"] = mResp
  100 + //} else {
  101 + // list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
  102 + // Token: req.Token,
  103 + // TableTypes: []string{bytelib.CalculateSet},
  104 + // Module: bytelib.ModuleCalculateCenter,
  105 + // ReturnGroupItem: true,
  106 + // ExcludeTables: []int{0},
  107 + // })
  108 + // if err != nil {
  109 + // batchError.Add(err)
  110 + // }
  111 + // result["计算集"] = newList(list)
  112 + //}
76 }) 113 })
77 if err = batchError.Err(); err != nil { 114 if err = batchError.Err(); err != nil {
78 logx.Error(err) 115 logx.Error(err)
@@ -88,3 +125,31 @@ func newList(r bytelib.ObjectTableSearchResponse) interface{} { @@ -88,3 +125,31 @@ func newList(r bytelib.ObjectTableSearchResponse) interface{} {
88 "list": r.List, 125 "list": r.List,
89 } 126 }
90 } 127 }
  128 +
  129 +func (l *SearchTableByModuleLogic) getTableByLocal(modules []string) (types.SearchTableByModuleResponse, error) {
  130 + tenantId := contextdata.GetTenantFromCtx(l.ctx)
  131 + response := types.SearchTableByModuleResponse{
  132 + Count: 0,
  133 + List: make([]types.SearchTableByModuleItem, 0),
  134 + }
  135 + total, list, err := l.svcCtx.ObjectTableRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), map[string]interface{}{
  136 + "companyId": tenantId,
  137 + "tableTypeIn": modules,
  138 + })
  139 + if err != nil {
  140 + return response, err
  141 + }
  142 + response.Count = int(total)
  143 + for _, item := range list {
  144 + response.List = append(response.List, types.SearchTableByModuleItem{
  145 + Id: item.Id,
  146 + TableId: item.TableId,
  147 + TableType: item.TableType,
  148 + Name: item.Name,
  149 + ParentId: item.ParentId,
  150 + Flag: item.Flag,
  151 + IsLocal: item.IsLocal,
  152 + })
  153 + }
  154 + return response, nil
  155 +}
@@ -2,9 +2,11 @@ package table @@ -2,9 +2,11 @@ package table
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "github.com/jinzhu/copier"
5 "github.com/zeromicro/go-zero/core/logx" 6 "github.com/zeromicro/go-zero/core/logx"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr" 11 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
10 "sort" 12 "sort"
@@ -33,9 +35,68 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest @@ -33,9 +35,68 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
33 "fields": nil, 35 "fields": nil,
34 "total": 0, 36 "total": 0,
35 "data": make([]string, 0), 37 "data": make([]string, 0),
  38 + "local": false,
36 } 39 }
37 return 40 return
38 } 41 }
  42 + resp, err = l.getLocal(req)
  43 + if err == nil {
  44 + return resp, nil
  45 + }
  46 + return l.getRemote(req)
  47 +}
  48 +
  49 +// getLocal 获取本地数据
  50 +func (l *SearchTableDataLogic) getLocal(req *types.SearchTableDataRequest) (interface{}, error) {
  51 + conn := l.svcCtx.DefaultDBConn()
  52 + conditions := make([]*domain.TableDataCondition, 0)
  53 + _ = copier.Copy(&conditions, req.Condition)
  54 + //查询表数据
  55 + objectTable, err := l.svcCtx.ObjectTableRepository.FindOneByTableId(l.ctx, conn, req.ObjectId)
  56 + if err != nil || objectTable.Id <= 0 {
  57 + return nil, xerr.NewErrMsg("表不存在")
  58 + }
  59 + if !objectTable.IsLocal {
  60 + return nil, xerr.NewErrMsg("未保存到本地存储")
  61 + }
  62 + //查询表字段
  63 + objectField, err := l.svcCtx.ObjectFieldRepository.FindOne(l.ctx, conn, int64(req.ObjectId))
  64 + if err != nil || objectField.Id <= 0 {
  65 + return nil, xerr.NewErrMsg("表字段不存在")
  66 + }
  67 + //替换中文字段
  68 + for _, item := range conditions {
  69 + replace := false
  70 + for _, field := range objectField.Fields {
  71 + if field.Name == item.FieldName {
  72 + item.FieldName = field.SQLName
  73 + replace = true
  74 + }
  75 + }
  76 + if !replace {
  77 + return nil, xerr.NewErrMsg("字段" + item.FieldName + "不存在")
  78 + }
  79 + }
  80 + //表数据
  81 + total, list, err := l.svcCtx.ObjectTableDataRepository.Find(l.ctx, conn, req.ObjectId, &domain.ObjectTableDataQuery{
  82 + Page: req.PageNumber,
  83 + Size: req.PageSize,
  84 + Conditions: conditions,
  85 + })
  86 + if err != nil {
  87 + return nil, xerr.NewErrMsg("查询表数据失败")
  88 + }
  89 + return map[string]interface{}{
  90 + "objectId": req.ObjectId,
  91 + "fields": removeIdField(objectField.Fields),
  92 + "total": total,
  93 + "data": list,
  94 + "local": true,
  95 + }, nil
  96 +}
  97 +
  98 +// getRemote 获取远程字库数据
  99 +func (l *SearchTableDataLogic) getRemote(req *types.SearchTableDataRequest) (resp interface{}, err error) {
39 tableDataPreviewRequest := &bytelib.TableDataPreviewRequest{ 100 tableDataPreviewRequest := &bytelib.TableDataPreviewRequest{
40 Token: req.Token, 101 Token: req.Token,
41 ObjectType: bytelib.ObjectMetaTable, 102 ObjectType: bytelib.ObjectMetaTable,
@@ -95,6 +156,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest @@ -95,6 +156,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
95 "fields": removeIdField(response.Fields), 156 "fields": removeIdField(response.Fields),
96 "total": response.Grid.Total, 157 "total": response.Grid.Total,
97 "data": response.Grid.List, 158 "data": response.Grid.List,
  159 + "local": false,
98 } 160 }
99 return 161 return
100 } 162 }
@@ -2,13 +2,15 @@ package table @@ -2,13 +2,15 @@ package table
2 2
3 import ( 3 import (
4 "context" 4 "context"
5 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"  
6 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"  
7 - 5 + "fmt"
  6 + "github.com/jinzhu/copier"
  7 + "github.com/samber/lo"
  8 + "github.com/zeromicro/go-zero/core/logx"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
10 -  
11 - "github.com/zeromicro/go-zero/core/logx" 11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  13 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
12 ) 14 )
13 15
14 type SearchTableFieldOptionalValuesLogic struct { 16 type SearchTableFieldOptionalValuesLogic struct {
@@ -26,6 +28,12 @@ func NewSearchTableFieldOptionalValuesLogic(ctx context.Context, svcCtx *svc.Ser @@ -26,6 +28,12 @@ func NewSearchTableFieldOptionalValuesLogic(ctx context.Context, svcCtx *svc.Ser
26 } 28 }
27 29
28 func (l *SearchTableFieldOptionalValuesLogic) SearchTableFieldOptionalValues(req *types.SearchTableFieldOptionalValuesRequest) (resp *types.SearchTableFieldOptionalValuesResponse, err error) { 30 func (l *SearchTableFieldOptionalValuesLogic) SearchTableFieldOptionalValues(req *types.SearchTableFieldOptionalValuesRequest) (resp *types.SearchTableFieldOptionalValuesResponse, err error) {
  31 + //取本地数据
  32 + resp, err = l.getLocal(req)
  33 + if err == nil {
  34 + return resp, err
  35 + }
  36 + //获取远程数据
29 fieldOptionalValuesRequest := &bytelib.TableFieldOptionalValuesRequest{ 37 fieldOptionalValuesRequest := &bytelib.TableFieldOptionalValuesRequest{
30 Token: req.Token, 38 Token: req.Token,
31 ObjectType: bytelib.ObjectMetaTable, 39 ObjectType: bytelib.ObjectMetaTable,
@@ -71,3 +79,64 @@ func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere { @@ -71,3 +79,64 @@ func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere {
71 } 79 }
72 return where 80 return where
73 } 81 }
  82 +
  83 +func (l *SearchTableFieldOptionalValuesLogic) getLocal(req *types.SearchTableFieldOptionalValuesRequest) (resp *types.SearchTableFieldOptionalValuesResponse, err error) {
  84 + conn := l.svcCtx.DefaultDBConn()
  85 + //查询表数据
  86 + objectTable, err := l.svcCtx.ObjectTableRepository.FindOneByTableId(l.ctx, conn, req.ObjectId)
  87 + if err != nil || objectTable.Id <= 0 {
  88 + return nil, xerr.NewErrMsg("表不存在")
  89 + }
  90 + if !objectTable.IsLocal {
  91 + return nil, xerr.NewErrMsg("未保存到本地存储")
  92 + }
  93 + //查询表字段
  94 + objectField, err := l.svcCtx.ObjectFieldRepository.FindOne(l.ctx, conn, int64(req.ObjectId))
  95 + if err != nil || objectField.Id <= 0 {
  96 + return nil, xerr.NewErrMsg("表字段不存在")
  97 + }
  98 + conditions := make([]*domain.TableDataCondition, 0)
  99 + _ = copier.Copy(&conditions, req.Condition)
  100 + //替换中文字段
  101 + for _, item := range conditions {
  102 + replace := false
  103 + for _, field := range objectField.Fields {
  104 + if field.Name == item.FieldName {
  105 + item.FieldName = field.SQLName
  106 + replace = true
  107 + }
  108 + }
  109 + if !replace {
  110 + return nil, xerr.NewErrMsg("字段" + item.FieldName + "不存在")
  111 + }
  112 + }
  113 + field := req.Field
  114 + for _, item := range objectField.Fields {
  115 + if req.Field == item.Name {
  116 + field = item.SQLName
  117 + }
  118 + }
  119 + //表数据
  120 + _, list, err := l.svcCtx.ObjectTableDataRepository.Find(l.ctx, conn, req.ObjectId, &domain.ObjectTableDataQuery{
  121 + Conditions: conditions,
  122 + Group: field,
  123 + Select: field,
  124 + })
  125 + if err != nil {
  126 + return nil, xerr.NewErrMsg("查询表数据失败")
  127 + }
  128 + resp = &types.SearchTableFieldOptionalValuesResponse{
  129 + Values: make([]string, 0),
  130 + Total: 0,
  131 + }
  132 + if len(list) > 0 {
  133 + lo.ForEach(list, func(item map[string]interface{}, index int) {
  134 + if _, ok := item[field]; ok {
  135 + resp.Values = append(resp.Values, fmt.Sprintf("%v", item[field]))
  136 + }
  137 + })
  138 + resp.Values = lo.Uniq(resp.Values)
  139 + resp.Total = int64(len(resp.Values))
  140 + }
  141 + return resp, nil
  142 +}
  1 +package table
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
  10 +
  11 + "github.com/zeromicro/go-zero/core/logx"
  12 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
  13 +)
  14 +
  15 +type SyncTableLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 + conn transaction.Conn
  20 +}
  21 +
  22 +func NewSyncTableLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SyncTableLogic {
  23 + return &SyncTableLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + conn: svcCtx.DefaultDBConn(),
  28 + }
  29 +}
  30 +
  31 +func (l *SyncTableLogic) SyncTable() (resp interface{}, err error) {
  32 + companyIds, err := l.svcCtx.ChartRepository.FindCompanyIds(l.ctx, l.conn)
  33 + if err != nil {
  34 + return nil, xerr.NewErrMsg("查询公司ID失败:" + err.Error())
  35 + }
  36 + tables := make([]*domain.ObjectTable, 0)
  37 + for _, companyId := range companyIds {
  38 + accessToken, _ := types.TableAccessToken{CompanyId: companyId}.GenerateToken()
  39 + //获取导入模块
  40 + response, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
  41 + Token: accessToken,
  42 + TableTypes: []string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable},
  43 + Module: bytelib.ModuleChartTemplate,
  44 + })
  45 + if err == nil {
  46 + tables = append(tables, l.getTables(companyId, response)...)
  47 + }
  48 + //拆解模块
  49 + response, err = l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
  50 + Token: accessToken,
  51 + TableTypes: []string{bytelib.SchemaTable},
  52 + Module: bytelib.ModuleQuerySetCenter,
  53 + ReturnGroupItem: true,
  54 + })
  55 + if err == nil {
  56 + tables = append(tables, l.getTables(companyId, response)...)
  57 + }
  58 + //计算项 计算集
  59 + response, err = l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
  60 + Token: accessToken,
  61 + TableTypes: []string{bytelib.CalculateItem, bytelib.CalculateSet},
  62 + Module: bytelib.ModuleCalculateCenter,
  63 + ReturnGroupItem: true,
  64 + ExcludeTables: []int{0},
  65 + })
  66 + if err == nil {
  67 + tables = append(tables, l.getTables(companyId, response)...)
  68 + }
  69 + }
  70 + //获取字段信息
  71 + fields := l.getFields(tables)
  72 + //保存数据
  73 + err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
  74 + err = l.SaveTables(conn, tables)
  75 + if err != nil {
  76 + return err
  77 + }
  78 + err = l.SaveFields(conn, fields)
  79 + if err != nil {
  80 + return err
  81 + }
  82 + return nil
  83 + }, true)
  84 + return companyIds, err
  85 +}
  86 +
  87 +func (l *SyncTableLogic) getTables(companyId int64, response bytelib.ObjectTableSearchResponse) []*domain.ObjectTable {
  88 + tables := make([]*domain.ObjectTable, 0)
  89 + if len(response.List) > 0 {
  90 + for _, item := range response.List {
  91 + tables = append(tables, &domain.ObjectTable{
  92 + Id: item.Id,
  93 + TableId: item.TableId,
  94 + Name: item.Name,
  95 + TableType: item.TableType,
  96 + CompanyId: companyId,
  97 + ParentId: item.ParentId,
  98 + Flag: item.Flag,
  99 + Version: 1,
  100 + IsLocal: false,
  101 + RemoteDeleted: 0,
  102 + })
  103 + }
  104 + }
  105 + return tables
  106 +}
  107 +
  108 +func (l *SyncTableLogic) getFields(list []*domain.ObjectTable) []*domain.ObjectField {
  109 + fields := make([]*domain.ObjectField, 0)
  110 + for _, item := range list {
  111 + accessToken, _ := types.TableAccessToken{CompanyId: item.CompanyId}.GenerateToken()
  112 + if item.TableId > 0 {
  113 + response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{
  114 + Token: accessToken,
  115 + TableId: item.TableId,
  116 + })
  117 + if err == nil {
  118 + fields = append(fields, &domain.ObjectField{
  119 + Id: int64(item.TableId),
  120 + Name: response.Name,
  121 + Fields: response.Fields,
  122 + Version: 1,
  123 + })
  124 + }
  125 + }
  126 + }
  127 + return fields
  128 +}
  129 +
  130 +// SaveTables 保存数据
  131 +func (l *SyncTableLogic) SaveTables(conn transaction.Conn, list []*domain.ObjectTable) error {
  132 + for _, item := range list {
  133 + objectTable, err := l.svcCtx.ObjectTableRepository.FindOne(l.ctx, conn, item.Id)
  134 + if err == nil && objectTable.Id > 0 {
  135 + item.IsLocal = objectTable.IsLocal
  136 + item.Version = objectTable.Version + 1
  137 + }
  138 + _, err = l.svcCtx.ObjectTableRepository.Insert(l.ctx, conn, item)
  139 + if err != nil {
  140 + return err
  141 + }
  142 + }
  143 + return nil
  144 +}
  145 +
  146 +func (l *SyncTableLogic) SaveFields(conn transaction.Conn, list []*domain.ObjectField) error {
  147 + for _, item := range list {
  148 + objectTable, err := l.svcCtx.ObjectFieldRepository.FindOne(l.ctx, conn, item.Id)
  149 + if err == nil && objectTable.Id > 0 {
  150 + item.Version = objectTable.Version + 1
  151 + }
  152 + _, err = l.svcCtx.ObjectFieldRepository.Insert(l.ctx, conn, item)
  153 + if err != nil {
  154 + return err
  155 + }
  156 + }
  157 + return nil
  158 +}
@@ -15,13 +15,17 @@ import ( @@ -15,13 +15,17 @@ import (
15 ) 15 )
16 16
17 type ServiceContext struct { 17 type ServiceContext struct {
18 - Config config.Config  
19 - DB *gorm.DB  
20 - Redis *redis.Redis  
21 - RedisCache gzcache.GZCache  
22 - ChartRepository domain.ChartRepository  
23 - ChartSettingRepository domain.ChartSettingRepository  
24 - AppPageRepository domain.AppPageRepository 18 + Config config.Config
  19 + DB *gorm.DB
  20 + Redis *redis.Redis
  21 + RedisCache gzcache.GZCache
  22 + ChartRepository domain.ChartRepository
  23 + ChartSettingRepository domain.ChartSettingRepository
  24 + AppPageRepository domain.AppPageRepository
  25 + ObjectNoticeRepository domain.ObjectNoticeRepository
  26 + ObjectTableRepository domain.ObjectTableRepository
  27 + ObjectFieldRepository domain.ObjectFieldRepository
  28 + ObjectTableDataRepository domain.ObjectTableDataRepository
25 29
26 ByteMetadataService bytelib.ByteMetadataService 30 ByteMetadataService bytelib.ByteMetadataService
27 } 31 }
@@ -33,13 +37,17 @@ func NewServiceContext(c config.Config) *ServiceContext { @@ -33,13 +37,17 @@ func NewServiceContext(c config.Config) *ServiceContext {
33 redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"}) 37 redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"})
34 38
35 return &ServiceContext{ 39 return &ServiceContext{
36 - Config: c,  
37 - DB: db,  
38 - RedisCache: redisCache,  
39 - Redis: redis,  
40 - ChartRepository: repository.NewChartRepository(cache.NewCachedRepository(mlCache)),  
41 - ChartSettingRepository: repository.NewChartSettingRepository(cache.NewCachedRepository(mlCache)),  
42 - AppPageRepository: repository.NewAppPageRepository(cache.NewCachedRepository(mlCache)), 40 + Config: c,
  41 + DB: db,
  42 + RedisCache: redisCache,
  43 + Redis: redis,
  44 + ChartRepository: repository.NewChartRepository(cache.NewCachedRepository(mlCache)),
  45 + ChartSettingRepository: repository.NewChartSettingRepository(cache.NewCachedRepository(mlCache)),
  46 + AppPageRepository: repository.NewAppPageRepository(cache.NewCachedRepository(mlCache)),
  47 + ObjectNoticeRepository: repository.NewObjectNoticeRepository(cache.NewCachedRepository(mlCache)),
  48 + ObjectTableRepository: repository.NewObjectTableRepository(cache.NewCachedRepository(mlCache)),
  49 + ObjectFieldRepository: repository.NewObjectFieldRepository(cache.NewCachedRepository(mlCache)),
  50 + ObjectTableDataRepository: repository.NewObjectTableDataRepository(),
43 51
44 ByteMetadataService: bytelib.ByteMetadataService{ 52 ByteMetadataService: bytelib.ByteMetadataService{
45 Service: gateway.NewService(c.ByteMetadata.Name, c.ByteMetadata.Host, c.ByteMetadata.Timeout), 53 Service: gateway.NewService(c.ByteMetadata.Name, c.ByteMetadata.Host, c.ByteMetadata.Timeout),
1 package types 1 package types
  2 +
  3 +import (
  4 + "github.com/golang-jwt/jwt/v4"
  5 + "time"
  6 +)
  7 +
  8 +type TableAccessToken struct {
  9 + UserId int64 `json:"userId"`
  10 + CompanyId int64 `json:"companyId"`
  11 + UserName string `json:"userName"`
  12 + Phone string `json:"phone"`
  13 +}
  14 +
  15 +func (tk TableAccessToken) GenerateToken() (string, error) {
  16 + claims := make(jwt.MapClaims)
  17 + claims["exp"] = time.Now().Unix() + 3600
  18 + claims["iat"] = time.Now().Unix()
  19 + claims["UserId"] = tk.UserId
  20 + claims["CompanyId"] = tk.CompanyId
  21 + claims["UserName"] = tk.UserName
  22 + claims["Phone"] = tk.Phone
  23 + token := jwt.New(jwt.SigningMethodHS256)
  24 + token.Claims = claims
  25 + return token.SignedString([]byte("digital-platform"))
  26 +}
@@ -219,6 +219,18 @@ type SearchTableByModuleRequest struct { @@ -219,6 +219,18 @@ type SearchTableByModuleRequest struct {
219 } 219 }
220 220
221 type SearchTableByModuleResponse struct { 221 type SearchTableByModuleResponse struct {
  222 + Count int `json:"count"`
  223 + List []SearchTableByModuleItem `json:"list"`
  224 +}
  225 +
  226 +type SearchTableByModuleItem struct {
  227 + Id int `json:"id"` //ID
  228 + TableId int `json:"tableId"` //表ID
  229 + Name string `json:"name"` //表名
  230 + TableType string `json:"tableType"` //表类型
  231 + ParentId int `json:"parentId"` //父级ID
  232 + Flag string `json:"flag"` //分组:Group 集合:Set
  233 + IsLocal bool `json:"isLocal"` //是否本地存储
222 } 234 }
223 235
224 type SearchTableFieldOptionalValuesRequest struct { 236 type SearchTableFieldOptionalValuesRequest struct {
@@ -259,6 +271,14 @@ type SearchTableDataRequest struct { @@ -259,6 +271,14 @@ type SearchTableDataRequest struct {
259 type SearchTableDataResponse struct { 271 type SearchTableDataResponse struct {
260 } 272 }
261 273
  274 +type SyncTableDataPusher struct {
  275 + CompanyId int64 `json:"companyId,string"` //公司ID
  276 + ObjectId int `json:"objectId"`
  277 +}
  278 +
  279 +type SyncTableResponse struct {
  280 +}
  281 +
262 type AppPageGetRequest struct { 282 type AppPageGetRequest struct {
263 Id int64 `path:"id"` 283 Id int64 `path:"id"`
264 } 284 }
  1 +
  2 +syntax = "v1"
  3 +
  4 +info(
  5 + title: "xx实例"
  6 + desc: "xx实例"
  7 + author: "author"
  8 + email: "email"
  9 + version: "v1"
  10 +)
  11 +
  12 +@server(
  13 + prefix: object_field/v1
  14 + group: object_field
  15 + jwt: JwtAuth
  16 +)
  17 +service Core {
  18 + @handler getObjectField
  19 + post /object_field/:id (ObjectFieldGetRequest) returns (ObjectFieldGetResponse)
  20 + @handler saveObjectField
  21 + post /object_field (ObjectFieldSaveRequest) returns (ObjectFieldSaveResponse)
  22 + @handler deleteObjectField
  23 + delete /object_field/:id (ObjectFieldDeleteRequest) returns (ObjectFieldDeleteResponse)
  24 + @handler updateObjectField
  25 + put /object_field/:id (ObjectFieldUpdateRequest) returns (ObjectFieldUpdateResponse)
  26 + @handler searchObjectField
  27 + post /object_field/search (ObjectFieldSearchRequest) returns (ObjectFieldSearchResponse)
  28 +}
  29 +
  30 +type (
  31 + ObjectFieldGetRequest {
  32 + Id int64 `path:"id"`
  33 + }
  34 + ObjectFieldGetResponse struct{
  35 + ObjectField ObjectFieldItem `json:"object_field"`
  36 + }
  37 +
  38 + ObjectFieldSaveRequest struct{
  39 + ObjectField ObjectFieldItem `json:"object_field"`
  40 + }
  41 + ObjectFieldSaveResponse struct{}
  42 +
  43 + ObjectFieldDeleteRequest struct{
  44 + Id int64 `path:"id"`
  45 + }
  46 + ObjectFieldDeleteResponse struct{}
  47 +
  48 + ObjectFieldUpdateRequest struct{
  49 + Id int64 `path:"id"`
  50 + ObjectField ObjectFieldItem `json:"object_field"`
  51 + }
  52 + ObjectFieldUpdateResponse struct{}
  53 +
  54 + ObjectFieldSearchRequest struct{
  55 + Page int `json:"page"`
  56 + Size int `json:"size"`
  57 + }
  58 + ObjectFieldSearchResponse{
  59 + List []ObjectFieldItem `json:"list"`
  60 + Total int64 `json:"total"`
  61 + }
  62 + ObjectFieldItem struct{
  63 +
  64 + }
  65 +)
  1 +
  2 +syntax = "v1"
  3 +
  4 +info(
  5 + title: "xx实例"
  6 + desc: "xx实例"
  7 + author: "author"
  8 + email: "email"
  9 + version: "v1"
  10 +)
  11 +
  12 +@server(
  13 + prefix: object_notice/v1
  14 + group: object_notice
  15 + jwt: JwtAuth
  16 +)
  17 +service Core {
  18 + @handler getObjectNotice
  19 + post /object_notice/:id (ObjectNoticeGetRequest) returns (ObjectNoticeGetResponse)
  20 + @handler saveObjectNotice
  21 + post /object_notice (ObjectNoticeSaveRequest) returns (ObjectNoticeSaveResponse)
  22 + @handler deleteObjectNotice
  23 + delete /object_notice/:id (ObjectNoticeDeleteRequest) returns (ObjectNoticeDeleteResponse)
  24 + @handler updateObjectNotice
  25 + put /object_notice/:id (ObjectNoticeUpdateRequest) returns (ObjectNoticeUpdateResponse)
  26 + @handler searchObjectNotice
  27 + post /object_notice/search (ObjectNoticeSearchRequest) returns (ObjectNoticeSearchResponse)
  28 +}
  29 +
  30 +type (
  31 + ObjectNoticeGetRequest {
  32 + Id int64 `path:"id"`
  33 + }
  34 + ObjectNoticeGetResponse struct{
  35 + ObjectNotice ObjectNoticeItem `json:"object_notice"`
  36 + }
  37 +
  38 + ObjectNoticeSaveRequest struct{
  39 + ObjectNotice ObjectNoticeItem `json:"object_notice"`
  40 + }
  41 + ObjectNoticeSaveResponse struct{}
  42 +
  43 + ObjectNoticeDeleteRequest struct{
  44 + Id int64 `path:"id"`
  45 + }
  46 + ObjectNoticeDeleteResponse struct{}
  47 +
  48 + ObjectNoticeUpdateRequest struct{
  49 + Id int64 `path:"id"`
  50 + ObjectNotice ObjectNoticeItem `json:"object_notice"`
  51 + }
  52 + ObjectNoticeUpdateResponse struct{}
  53 +
  54 + ObjectNoticeSearchRequest struct{
  55 + Page int `json:"page"`
  56 + Size int `json:"size"`
  57 + }
  58 + ObjectNoticeSearchResponse{
  59 + List []ObjectNoticeItem `json:"list"`
  60 + Total int64 `json:"total"`
  61 + }
  62 + ObjectNoticeItem struct{
  63 +
  64 + }
  65 +)
  1 +
  2 +syntax = "v1"
  3 +
  4 +info(
  5 + title: "xx实例"
  6 + desc: "xx实例"
  7 + author: "author"
  8 + email: "email"
  9 + version: "v1"
  10 +)
  11 +
  12 +@server(
  13 + prefix: object_table/v1
  14 + group: object_table
  15 + jwt: JwtAuth
  16 +)
  17 +service Core {
  18 + @handler getObjectTable
  19 + post /object_table/:id (ObjectTableGetRequest) returns (ObjectTableGetResponse)
  20 + @handler saveObjectTable
  21 + post /object_table (ObjectTableSaveRequest) returns (ObjectTableSaveResponse)
  22 + @handler deleteObjectTable
  23 + delete /object_table/:id (ObjectTableDeleteRequest) returns (ObjectTableDeleteResponse)
  24 + @handler updateObjectTable
  25 + put /object_table/:id (ObjectTableUpdateRequest) returns (ObjectTableUpdateResponse)
  26 + @handler searchObjectTable
  27 + post /object_table/search (ObjectTableSearchRequest) returns (ObjectTableSearchResponse)
  28 +}
  29 +
  30 +type (
  31 + ObjectTableGetRequest {
  32 + Id int64 `path:"id"`
  33 + }
  34 + ObjectTableGetResponse struct{
  35 + ObjectTable ObjectTableItem `json:"object_table"`
  36 + }
  37 +
  38 + ObjectTableSaveRequest struct{
  39 + ObjectTable ObjectTableItem `json:"object_table"`
  40 + }
  41 + ObjectTableSaveResponse struct{}
  42 +
  43 + ObjectTableDeleteRequest struct{
  44 + Id int64 `path:"id"`
  45 + }
  46 + ObjectTableDeleteResponse struct{}
  47 +
  48 + ObjectTableUpdateRequest struct{
  49 + Id int64 `path:"id"`
  50 + ObjectTable ObjectTableItem `json:"object_table"`
  51 + }
  52 + ObjectTableUpdateResponse struct{}
  53 +
  54 + ObjectTableSearchRequest struct{
  55 + Page int `json:"page"`
  56 + Size int `json:"size"`
  57 + }
  58 + ObjectTableSearchResponse{
  59 + List []ObjectTableItem `json:"list"`
  60 + Total int64 `json:"total"`
  61 + }
  62 + ObjectTableItem struct{
  63 +
  64 + }
  65 +)
  1 +
  2 +syntax = "proto3";
  3 +
  4 +option go_package ="./pb";
  5 +
  6 +package pb;
  7 +
  8 +message ObjectFieldGetReq {
  9 + int64 Id = 1;
  10 +}
  11 +message ObjectFieldGetResp{
  12 + ObjectFieldItem User = 1;
  13 +}
  14 +
  15 +message ObjectFieldSaveReq {
  16 +
  17 +}
  18 +message ObjectFieldSaveResp{
  19 +
  20 +}
  21 +
  22 +message ObjectFieldDeleteReq {
  23 + int64 Id = 1;
  24 +}
  25 +message ObjectFieldDeleteResp{
  26 +
  27 +}
  28 +
  29 +message ObjectFieldUpdateReq {
  30 + int64 Id = 1;
  31 +}
  32 +message ObjectFieldUpdateResp{
  33 +
  34 +}
  35 +
  36 +message ObjectFieldSearchReq {
  37 + int64 PageNumber = 1;
  38 + int64 PageSize = 2;
  39 +}
  40 +message ObjectFieldSearchResp{
  41 + repeated ObjectFieldItem List =1;
  42 + int64 Total =2;
  43 +}
  44 +message ObjectFieldItem {
  45 +
  46 +}
  47 +
  48 +service ObjectFieldService {
  49 + rpc ObjectFieldGet(ObjectFieldGetReq) returns(ObjectFieldGetResp);
  50 + rpc ObjectFieldSave(ObjectFieldSaveReq) returns(ObjectFieldSaveResp);
  51 + rpc ObjectFieldDelete(ObjectFieldDeleteReq) returns(ObjectFieldDeleteResp);
  52 + rpc ObjectFieldUpdate(ObjectFieldUpdateReq) returns(ObjectFieldUpdateResp);
  53 + rpc ObjectFieldSearch(ObjectFieldSearchReq) returns(ObjectFieldSearchResp);
  54 +}
  1 +
  2 +syntax = "proto3";
  3 +
  4 +option go_package ="./pb";
  5 +
  6 +package pb;
  7 +
  8 +message ObjectNoticeGetReq {
  9 + int64 Id = 1;
  10 +}
  11 +message ObjectNoticeGetResp{
  12 + ObjectNoticeItem User = 1;
  13 +}
  14 +
  15 +message ObjectNoticeSaveReq {
  16 +
  17 +}
  18 +message ObjectNoticeSaveResp{
  19 +
  20 +}
  21 +
  22 +message ObjectNoticeDeleteReq {
  23 + int64 Id = 1;
  24 +}
  25 +message ObjectNoticeDeleteResp{
  26 +
  27 +}
  28 +
  29 +message ObjectNoticeUpdateReq {
  30 + int64 Id = 1;
  31 +}
  32 +message ObjectNoticeUpdateResp{
  33 +
  34 +}
  35 +
  36 +message ObjectNoticeSearchReq {
  37 + int64 PageNumber = 1;
  38 + int64 PageSize = 2;
  39 +}
  40 +message ObjectNoticeSearchResp{
  41 + repeated ObjectNoticeItem List =1;
  42 + int64 Total =2;
  43 +}
  44 +message ObjectNoticeItem {
  45 +
  46 +}
  47 +
  48 +service ObjectNoticeService {
  49 + rpc ObjectNoticeGet(ObjectNoticeGetReq) returns(ObjectNoticeGetResp);
  50 + rpc ObjectNoticeSave(ObjectNoticeSaveReq) returns(ObjectNoticeSaveResp);
  51 + rpc ObjectNoticeDelete(ObjectNoticeDeleteReq) returns(ObjectNoticeDeleteResp);
  52 + rpc ObjectNoticeUpdate(ObjectNoticeUpdateReq) returns(ObjectNoticeUpdateResp);
  53 + rpc ObjectNoticeSearch(ObjectNoticeSearchReq) returns(ObjectNoticeSearchResp);
  54 +}
  1 +
  2 +syntax = "proto3";
  3 +
  4 +option go_package ="./pb";
  5 +
  6 +package pb;
  7 +
  8 +message ObjectTableGetReq {
  9 + int64 Id = 1;
  10 +}
  11 +message ObjectTableGetResp{
  12 + ObjectTableItem User = 1;
  13 +}
  14 +
  15 +message ObjectTableSaveReq {
  16 +
  17 +}
  18 +message ObjectTableSaveResp{
  19 +
  20 +}
  21 +
  22 +message ObjectTableDeleteReq {
  23 + int64 Id = 1;
  24 +}
  25 +message ObjectTableDeleteResp{
  26 +
  27 +}
  28 +
  29 +message ObjectTableUpdateReq {
  30 + int64 Id = 1;
  31 +}
  32 +message ObjectTableUpdateResp{
  33 +
  34 +}
  35 +
  36 +message ObjectTableSearchReq {
  37 + int64 PageNumber = 1;
  38 + int64 PageSize = 2;
  39 +}
  40 +message ObjectTableSearchResp{
  41 + repeated ObjectTableItem List =1;
  42 + int64 Total =2;
  43 +}
  44 +message ObjectTableItem {
  45 +
  46 +}
  47 +
  48 +service ObjectTableService {
  49 + rpc ObjectTableGet(ObjectTableGetReq) returns(ObjectTableGetResp);
  50 + rpc ObjectTableSave(ObjectTableSaveReq) returns(ObjectTableSaveResp);
  51 + rpc ObjectTableDelete(ObjectTableDeleteReq) returns(ObjectTableDeleteResp);
  52 + rpc ObjectTableUpdate(ObjectTableUpdateReq) returns(ObjectTableUpdateResp);
  53 + rpc ObjectTableSearch(ObjectTableSearchReq) returns(ObjectTableSearchResp);
  54 +}
@@ -10,5 +10,8 @@ func Migrate(db *gorm.DB) { @@ -10,5 +10,8 @@ func Migrate(db *gorm.DB) {
10 &models.Chart{}, 10 &models.Chart{},
11 &models.ChartSetting{}, 11 &models.ChartSetting{},
12 &models.AppPage{}, 12 &models.AppPage{},
  13 + &models.ObjectNotice{},
  14 + &models.ObjectTable{},
  15 + &models.ObjectField{},
13 ) 16 )
14 } 17 }
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  7 + "gorm.io/gorm"
  8 + "gorm.io/plugin/soft_delete"
  9 + "time"
  10 +)
  11 +
  12 +type ObjectField struct {
  13 + Id int64 `json:"id" gorm:"primaryKey"` // ID
  14 + Name string `json:"name"` //表名
  15 + Fields []*bytelib.Field `json:"fields" gorm:"serializer:json"` //表字段
  16 + Version int `json:",omitempty"` //版本
  17 + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记
  18 + CreatedAt int64 `json:",omitempty"` //创建时间
  19 + UpdatedAt int64 `json:",omitempty"` //更新时间
  20 + DeletedAt int64 `json:",omitempty"` //删除时间
  21 +}
  22 +
  23 +func (m *ObjectField) TableName() string {
  24 + return "object_field"
  25 +}
  26 +
  27 +func (m *ObjectField) BeforeCreate(tx *gorm.DB) (err error) {
  28 + m.CreatedAt = time.Now().Unix()
  29 + m.UpdatedAt = time.Now().Unix()
  30 + return
  31 +}
  32 +
  33 +func (m *ObjectField) BeforeUpdate(tx *gorm.DB) (err error) {
  34 + m.UpdatedAt = time.Now().Unix()
  35 + return
  36 +}
  37 +
  38 +func (m *ObjectField) CacheKeyFunc() string {
  39 + if m.Id == 0 {
  40 + return ""
  41 + }
  42 + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
  43 +}
  44 +
  45 +func (m *ObjectField) CacheKeyFuncByObject(obj interface{}) string {
  46 + if v, ok := obj.(*ObjectField); ok {
  47 + return v.CacheKeyFunc()
  48 + }
  49 + return ""
  50 +}
  51 +
  52 +func (m *ObjectField) CachePrimaryKeyFunc() string {
  53 + if len("") == 0 {
  54 + return ""
  55 + }
  56 + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
  57 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  6 + "gorm.io/gorm"
  7 + "gorm.io/plugin/soft_delete"
  8 + "time"
  9 +)
  10 +
  11 +type ObjectNotice struct {
  12 + Id int64 `json:"id" gorm:"primaryKey"` // ID
  13 + CompanyId int64 `json:"companyId"` //公司ID
  14 + TableId int64 `json:"tableId"` //表ID
  15 + TableType string `json:"tableType"` //表类型 导入模块(主表、附表、分表) 拆解(方案、子过程、计算表) 计算(计算项、计算集)
  16 + ObjectType string `json:"objectType"` //模块 导入模块、拆解模块、计算模块
  17 + Event string `json:"event"` //事件
  18 + TableAffectedList []int `json:"TableAffectedList" gorm:"serializer:json"` //级联影响到的表
  19 + DataChanged bool `json:"dataChanged"` //数据有更新
  20 + StructChanged bool `json:"structChanged"` //结构有更新
  21 + Status int `json:"status" gorm:"index:idx_object_notice_status"` //状态 1-等待处理 2-处理完成 3-处理失败
  22 + Message string `json:"message"` //错误信息
  23 + Retry int `json:"retry" gorm:"default:0"` //重试次数
  24 + MetaData domain.ObjectNoticeMetaData `json:"metaData" gorm:"serializer:json"` //模块信息
  25 + Version int `json:",omitempty"` //版本
  26 + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记
  27 + CreatedAt int64 `json:",omitempty"` //创建时间
  28 + UpdatedAt int64 `json:",omitempty"` //更新时间
  29 + DeletedAt int64 `json:",omitempty"` //删除时间
  30 +}
  31 +
  32 +func (m *ObjectNotice) TableName() string {
  33 + return "object_notice"
  34 +}
  35 +
  36 +func (m *ObjectNotice) BeforeCreate(tx *gorm.DB) (err error) {
  37 + m.CreatedAt = time.Now().Unix()
  38 + m.UpdatedAt = time.Now().Unix()
  39 + return
  40 +}
  41 +
  42 +func (m *ObjectNotice) BeforeUpdate(tx *gorm.DB) (err error) {
  43 + m.UpdatedAt = time.Now().Unix()
  44 + return
  45 +}
  46 +
  47 +func (m *ObjectNotice) CacheKeyFunc() string {
  48 + if m.Id == 0 {
  49 + return ""
  50 + }
  51 + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
  52 +}
  53 +
  54 +func (m *ObjectNotice) CacheKeyFuncByObject(obj interface{}) string {
  55 + if v, ok := obj.(*ObjectNotice); ok {
  56 + return v.CacheKeyFunc()
  57 + }
  58 + return ""
  59 +}
  60 +
  61 +func (m *ObjectNotice) CachePrimaryKeyFunc() string {
  62 + if len("") == 0 {
  63 + return ""
  64 + }
  65 + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
  66 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  6 + "gorm.io/gorm"
  7 + "gorm.io/plugin/soft_delete"
  8 + "time"
  9 +)
  10 +
  11 +type ObjectTable struct {
  12 + Id int `json:"id" gorm:"primaryKey"` // ID
  13 + TableId int `json:"tableId" gorm:"index:idx_object_table_id"` //表ID
  14 + Name string `json:"name"` //表名
  15 + TableType string `json:"tableType" gorm:"index:idx_object_table_type"` //模块
  16 + CompanyId int64 `json:"companyId" gorm:"index:idx_object_table_company"` //公司id
  17 + ParentId int `json:"parentId" gorm:"default:0"` //父id
  18 + Flag string `json:"flag"` //分组:Group 集合:Set
  19 + Version int `json:",omitempty"` //版本
  20 + IsLocal bool `json:"isLocal" gorm:"default:false"` //是否有本地存储
  21 + RemoteDeleted int `json:"remoteDeleted"` //远端删除
  22 + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记
  23 + CreatedAt int64 `json:",omitempty"` //创建时间
  24 + UpdatedAt int64 `json:",omitempty"` //更新时间
  25 + DeletedAt int64 `json:",omitempty"` //删除时间
  26 +}
  27 +
  28 +func (m *ObjectTable) TableName() string {
  29 + return "object_table"
  30 +}
  31 +
  32 +func (m *ObjectTable) BeforeCreate(tx *gorm.DB) (err error) {
  33 + m.CreatedAt = time.Now().Unix()
  34 + m.UpdatedAt = time.Now().Unix()
  35 + return
  36 +}
  37 +
  38 +func (m *ObjectTable) BeforeUpdate(tx *gorm.DB) (err error) {
  39 + m.UpdatedAt = time.Now().Unix()
  40 + return
  41 +}
  42 +
  43 +func (m *ObjectTable) CacheKeyFunc() string {
  44 + if m.Id == 0 {
  45 + return ""
  46 + }
  47 + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
  48 +}
  49 +
  50 +func (m *ObjectTable) CacheKeyFuncByObject(obj interface{}) string {
  51 + if v, ok := obj.(*ObjectTable); ok {
  52 + return v.CacheKeyFunc()
  53 + }
  54 + return ""
  55 +}
  56 +
  57 +func (m *ObjectTable) CachePrimaryKeyFunc() string {
  58 + if len("") == 0 {
  59 + return ""
  60 + }
  61 + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
  62 +}
@@ -201,6 +201,18 @@ func (repository *ChartRepository) FindOneByGroup(ctx context.Context, conn tran @@ -201,6 +201,18 @@ func (repository *ChartRepository) FindOneByGroup(ctx context.Context, conn tran
201 return repository.ModelToDomainModel(m) 201 return repository.ModelToDomainModel(m)
202 } 202 }
203 203
  204 +// FindCompanyIds 获取所有的公司ID
  205 +func (repository *ChartRepository) FindCompanyIds(ctx context.Context, conn transaction.Conn) ([]int64, error) {
  206 + var (
  207 + err error
  208 + tx = conn.DB()
  209 + m = new(models.Chart)
  210 + )
  211 + list := make([]int64, 0)
  212 + err = tx.Model(&m).Group("tenant_id").Pluck("tenant_id", &list).Error
  213 + return list, err
  214 +}
  215 +
204 func (repository *ChartRepository) ModelToDomainModel(from *models.Chart) (*domain.Chart, error) { 216 func (repository *ChartRepository) ModelToDomainModel(from *models.Chart) (*domain.Chart, error) {
205 to := &domain.Chart{} 217 to := &domain.Chart{}
206 err := copier.Copy(to, from) 218 err := copier.Copy(to, from)
@@ -140,6 +140,16 @@ func (repository *ChartSettingRepository) Find(ctx context.Context, conn transac @@ -140,6 +140,16 @@ func (repository *ChartSettingRepository) Find(ctx context.Context, conn transac
140 return total, dms, nil 140 return total, dms, nil
141 } 141 }
142 142
  143 +// CheckUseDataSource 检验是否使用数据源
  144 +func (repository *ChartSettingRepository) CheckUseDataSource(ctx context.Context, conn transaction.Conn, objectId int) (bool, error) {
  145 + var count int64
  146 + err := conn.DB().Model(&models.ChartSetting{}).Where("data_source_ids::jsonb @>'[?]'", objectId).Count(&count).Error
  147 + if err != nil {
  148 + return false, err
  149 + }
  150 + return count > 0, nil
  151 +}
  152 +
143 func (repository *ChartSettingRepository) ModelToDomainModel(from *models.ChartSetting) (*domain.ChartSetting, error) { 153 func (repository *ChartSettingRepository) ModelToDomainModel(from *models.ChartSetting) (*domain.ChartSetting, error) {
144 to := &domain.ChartSetting{} 154 to := &domain.ChartSetting{}
145 err := copier.Copy(to, from) 155 err := copier.Copy(to, from)
  1 +package repository
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/jinzhu/copier"
  6 + "github.com/pkg/errors"
  7 + "github.com/tiptok/gocomm/pkg/cache"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/models"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  11 + "gorm.io/gorm"
  12 +)
  13 +
  14 +type ObjectFieldRepository struct {
  15 + *cache.CachedRepository
  16 +}
  17 +
  18 +func (repository *ObjectFieldRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.ObjectField) (*domain.ObjectField, error) {
  19 + var (
  20 + err error
  21 + m = &models.ObjectField{}
  22 + tx = conn.DB()
  23 + )
  24 + if m, err = repository.DomainModelToModel(dm); err != nil {
  25 + return nil, err
  26 + }
  27 + if tx = tx.Model(m).Save(m); tx.Error != nil {
  28 + return nil, tx.Error
  29 + }
  30 + dm.Id = m.Id
  31 + return repository.ModelToDomainModel(m)
  32 +}
  33 +
  34 +func (repository *ObjectFieldRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ObjectField) (*domain.ObjectField, error) {
  35 + var (
  36 + err error
  37 + m *models.ObjectField
  38 + tx = conn.DB()
  39 + )
  40 + if m, err = repository.DomainModelToModel(dm); err != nil {
  41 + return nil, err
  42 + }
  43 + queryFunc := func() (interface{}, error) {
  44 + tx = tx.Model(m).Updates(m)
  45 + return nil, tx.Error
  46 + }
  47 + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  48 + return nil, err
  49 + }
  50 + return repository.ModelToDomainModel(m)
  51 +}
  52 +
  53 +func (repository *ObjectFieldRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.ObjectField) (*domain.ObjectField, error) {
  54 + var (
  55 + err error
  56 + m *models.ObjectField
  57 + tx = transaction.DB()
  58 + )
  59 + if m, err = repository.DomainModelToModel(dm); err != nil {
  60 + return nil, err
  61 + }
  62 + oldVersion := dm.Version
  63 + m.Version += 1
  64 + queryFunc := func() (interface{}, error) {
  65 + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
  66 + if tx.RowsAffected == 0 {
  67 + return nil, domain.ErrUpdateFail
  68 + }
  69 + return nil, tx.Error
  70 + }
  71 + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  72 + return nil, err
  73 + }
  74 + return repository.ModelToDomainModel(m)
  75 +}
  76 +
  77 +func (repository *ObjectFieldRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ObjectField) (*domain.ObjectField, error) {
  78 + var (
  79 + tx = conn.DB()
  80 + m = &models.ObjectField{Id: dm.Identify().(int64)}
  81 + )
  82 + queryFunc := func() (interface{}, error) {
  83 + tx = tx.Where("id = ?", m.Id).Unscoped().Delete(m)
  84 + return m, tx.Error
  85 + }
  86 + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  87 + return dm, err
  88 + }
  89 + return repository.ModelToDomainModel(m)
  90 +}
  91 +
  92 +func (repository *ObjectFieldRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.ObjectField, error) {
  93 + var (
  94 + err error
  95 + tx = conn.DB()
  96 + m = new(models.ObjectField)
  97 + )
  98 + queryFunc := func() (interface{}, error) {
  99 + tx = tx.Model(m).Where("id = ?", id).First(m)
  100 + if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
  101 + return nil, domain.ErrNotFound
  102 + }
  103 + return m, tx.Error
  104 + }
  105 + cacheModel := new(models.ObjectField)
  106 + cacheModel.Id = id
  107 + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
  108 + return nil, err
  109 + }
  110 + return repository.ModelToDomainModel(m)
  111 +}
  112 +
  113 +func (repository *ObjectFieldRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.ObjectField, error) {
  114 + var (
  115 + tx = conn.DB()
  116 + ms []*models.ObjectField
  117 + dms = make([]*domain.ObjectField, 0)
  118 + total int64
  119 + )
  120 + queryFunc := func() (interface{}, error) {
  121 + tx = tx.Model(&ms).Order("id desc")
  122 + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
  123 + return dms, tx.Error
  124 + }
  125 + return dms, nil
  126 + }
  127 +
  128 + if _, err := repository.Query(queryFunc); err != nil {
  129 + return 0, nil, err
  130 + }
  131 +
  132 + for _, item := range ms {
  133 + if dm, err := repository.ModelToDomainModel(item); err != nil {
  134 + return 0, dms, err
  135 + } else {
  136 + dms = append(dms, dm)
  137 + }
  138 + }
  139 + return total, dms, nil
  140 +}
  141 +
  142 +func (repository *ObjectFieldRepository) ModelToDomainModel(from *models.ObjectField) (*domain.ObjectField, error) {
  143 + to := &domain.ObjectField{}
  144 + err := copier.Copy(to, from)
  145 + return to, err
  146 +}
  147 +
  148 +func (repository *ObjectFieldRepository) DomainModelToModel(from *domain.ObjectField) (*models.ObjectField, error) {
  149 + to := &models.ObjectField{}
  150 + err := copier.Copy(to, from)
  151 + return to, err
  152 +}
  153 +
  154 +func NewObjectFieldRepository(cache *cache.CachedRepository) domain.ObjectFieldRepository {
  155 + return &ObjectFieldRepository{CachedRepository: cache}
  156 +}
  1 +package repository
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/jinzhu/copier"
  6 + "github.com/pkg/errors"
  7 + "github.com/tiptok/gocomm/pkg/cache"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/models"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  11 + "gorm.io/gorm"
  12 +)
  13 +
  14 +type ObjectNoticeRepository struct {
  15 + *cache.CachedRepository
  16 +}
  17 +
  18 +func (repository *ObjectNoticeRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.ObjectNotice) (*domain.ObjectNotice, error) {
  19 + var (
  20 + err error
  21 + m = &models.ObjectNotice{}
  22 + tx = conn.DB()
  23 + )
  24 + if m, err = repository.DomainModelToModel(dm); err != nil {
  25 + return nil, err
  26 + }
  27 + if tx = tx.Model(m).Save(m); tx.Error != nil {
  28 + return nil, tx.Error
  29 + }
  30 + dm.Id = m.Id
  31 + return repository.ModelToDomainModel(m)
  32 +
  33 +}
  34 +
  35 +func (repository *ObjectNoticeRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ObjectNotice) (*domain.ObjectNotice, error) {
  36 + var (
  37 + err error
  38 + m *models.ObjectNotice
  39 + tx = conn.DB()
  40 + )
  41 + if m, err = repository.DomainModelToModel(dm); err != nil {
  42 + return nil, err
  43 + }
  44 + queryFunc := func() (interface{}, error) {
  45 + tx = tx.Model(m).Updates(m)
  46 + return nil, tx.Error
  47 + }
  48 + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  49 + return nil, err
  50 + }
  51 + return repository.ModelToDomainModel(m)
  52 +}
  53 +
  54 +func (repository *ObjectNoticeRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.ObjectNotice) (*domain.ObjectNotice, error) {
  55 + var (
  56 + err error
  57 + m *models.ObjectNotice
  58 + tx = transaction.DB()
  59 + )
  60 + if m, err = repository.DomainModelToModel(dm); err != nil {
  61 + return nil, err
  62 + }
  63 + oldVersion := dm.Version
  64 + m.Version += 1
  65 + queryFunc := func() (interface{}, error) {
  66 + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
  67 + if tx.RowsAffected == 0 {
  68 + return nil, domain.ErrUpdateFail
  69 + }
  70 + return nil, tx.Error
  71 + }
  72 + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  73 + return nil, err
  74 + }
  75 + return repository.ModelToDomainModel(m)
  76 +}
  77 +
  78 +func (repository *ObjectNoticeRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ObjectNotice) (*domain.ObjectNotice, error) {
  79 + var (
  80 + tx = conn.DB()
  81 + m = &models.ObjectNotice{Id: dm.Identify().(int64)}
  82 + )
  83 + queryFunc := func() (interface{}, error) {
  84 + tx = tx.Where("id = ?", m.Id).Delete(m)
  85 + return m, tx.Error
  86 + }
  87 + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  88 + return dm, err
  89 + }
  90 + return repository.ModelToDomainModel(m)
  91 +}
  92 +
  93 +func (repository *ObjectNoticeRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.ObjectNotice, error) {
  94 + var (
  95 + err error
  96 + tx = conn.DB()
  97 + m = new(models.ObjectNotice)
  98 + )
  99 + queryFunc := func() (interface{}, error) {
  100 + tx = tx.Model(m).Where("id = ?", id).First(m)
  101 + if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
  102 + return nil, domain.ErrNotFound
  103 + }
  104 + return m, tx.Error
  105 + }
  106 + cacheModel := new(models.ObjectNotice)
  107 + cacheModel.Id = id
  108 + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
  109 + return nil, err
  110 + }
  111 + return repository.ModelToDomainModel(m)
  112 +}
  113 +
  114 +func (repository *ObjectNoticeRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.ObjectNotice, error) {
  115 + var (
  116 + tx = conn.DB()
  117 + ms []*models.ObjectNotice
  118 + dms = make([]*domain.ObjectNotice, 0)
  119 + total int64
  120 + )
  121 + queryFunc := func() (interface{}, error) {
  122 + tx = tx.Model(&ms).Order("id desc")
  123 + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
  124 + return dms, tx.Error
  125 + }
  126 + return dms, nil
  127 + }
  128 +
  129 + if _, err := repository.Query(queryFunc); err != nil {
  130 + return 0, nil, err
  131 + }
  132 +
  133 + for _, item := range ms {
  134 + if dm, err := repository.ModelToDomainModel(item); err != nil {
  135 + return 0, dms, err
  136 + } else {
  137 + dms = append(dms, dm)
  138 + }
  139 + }
  140 + return total, dms, nil
  141 +}
  142 +
  143 +func (repository *ObjectNoticeRepository) ModelToDomainModel(from *models.ObjectNotice) (*domain.ObjectNotice, error) {
  144 + to := &domain.ObjectNotice{}
  145 + err := copier.Copy(to, from)
  146 + return to, err
  147 +}
  148 +
  149 +func (repository *ObjectNoticeRepository) DomainModelToModel(from *domain.ObjectNotice) (*models.ObjectNotice, error) {
  150 + to := &models.ObjectNotice{}
  151 + err := copier.Copy(to, from)
  152 + return to, err
  153 +}
  154 +
  155 +func NewObjectNoticeRepository(cache *cache.CachedRepository) domain.ObjectNoticeRepository {
  156 + return &ObjectNoticeRepository{CachedRepository: cache}
  157 +}
  1 +package repository
  2 +
  3 +import (
  4 + "context"
  5 + "fmt"
  6 + "github.com/pkg/errors"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  10 + "strings"
  11 +)
  12 +
  13 +type ObjectTableDataRepository struct{}
  14 +
  15 +type TableColumnSQL struct {
  16 + Sql string `json:"sql"`
  17 + Column []string `json:"column"`
  18 + Data []map[string]string `json:"data"`
  19 +}
  20 +
  21 +// makeDropTableSQL 创建删除表SQL
  22 +func (repository *ObjectTableDataRepository) makeDropTableSQL(tableId int) (string, error) {
  23 + return fmt.Sprintf(`drop table if exists data."%v"`, tableId), nil
  24 +}
  25 +
  26 +// makeCreateTableSQL 创建表SQL
  27 +func (repository *ObjectTableDataRepository) makeCreateTableSQL(tableId int, fields []*bytelib.Field) (string, error) {
  28 + if len(fields) <= 0 {
  29 + return "", errors.New("缺少字段信息")
  30 + }
  31 + columns := make([]string, 0)
  32 + for _, item := range fields {
  33 + columns = append(columns, item.SQLName+" text ")
  34 + }
  35 + sql := `Create TABLE data."` + fmt.Sprintf("%v", tableId) + `" (` + strings.Join(columns, ",") + `);`
  36 + return sql, nil
  37 +}
  38 +
  39 +// makeInsertTableSQL 创建表数据SQL
  40 +func (repository *ObjectTableDataRepository) makeInsertTableSQL(tableId int, fields []*bytelib.Field, list []map[string]string) (*TableColumnSQL, error) {
  41 + tableColumnSQL := &TableColumnSQL{
  42 + Column: make([]string, 0),
  43 + Data: make([]map[string]string, 0),
  44 + }
  45 + if len(list) > 0 && len(fields) > 0 {
  46 + for _, field := range fields {
  47 + tableColumnSQL.Column = append(tableColumnSQL.Column, field.SQLName)
  48 + }
  49 + for _, item := range list {
  50 + values := make(map[string]string)
  51 + for _, field := range tableColumnSQL.Column {
  52 + if _, ok := item[field]; ok {
  53 + values[field] = item[field]
  54 + } else {
  55 + return tableColumnSQL, errors.New("未获取到字段值")
  56 + }
  57 + }
  58 + tableColumnSQL.Data = append(tableColumnSQL.Data, values)
  59 + }
  60 +
  61 + tableColumnSQL.Sql = fmt.Sprintf(`INSERT INTO data."%v" (%s) values (%s)`, tableId, strings.Join(tableColumnSQL.Column, ","), repository.sqlPlaceHoldersSnippet(tableColumnSQL.Column))
  62 + }
  63 + return tableColumnSQL, nil
  64 +}
  65 +
  66 +func (repository *ObjectTableDataRepository) sqlPlaceHoldersSnippet(sqlBuildFields []string) string {
  67 + var placeHolder []string
  68 + for i := 0; i < len(sqlBuildFields); i++ {
  69 + placeHolder = append(placeHolder, "?")
  70 + }
  71 + return strings.Join(placeHolder, ",")
  72 +}
  73 +
  74 +func (repository *ObjectTableDataRepository) DropTable(ctx context.Context, conn transaction.Conn, tableId int) error {
  75 + sql, err := repository.makeDropTableSQL(tableId)
  76 + if err != nil {
  77 + return err
  78 + }
  79 + err = conn.DB().Exec(sql).Error
  80 + if err != nil {
  81 + return err
  82 + }
  83 + //设置数据表本地存储为false
  84 + return conn.DB().Exec("update object_table set is_local=false where table_id = ? and is_del=0", tableId).Error
  85 +}
  86 +
  87 +// InsertWithTableData 写入表数据
  88 +func (repository *ObjectTableDataRepository) InsertWithTableData(ctx context.Context, conn transaction.Conn, tableDataPreview bytelib.TableData) error {
  89 + //删除表
  90 + err := repository.DropTable(ctx, conn, int(tableDataPreview.ObjectId))
  91 + if err != nil {
  92 + return err
  93 + }
  94 + //创建表
  95 + createTableSql, err := repository.makeCreateTableSQL(int(tableDataPreview.ObjectId), tableDataPreview.Fields)
  96 + if err != nil {
  97 + return err
  98 + }
  99 + err = conn.DB().Exec(createTableSql).Error
  100 + if err != nil {
  101 + return err
  102 + }
  103 + tableColumnSQL, err := repository.makeInsertTableSQL(int(tableDataPreview.ObjectId), tableDataPreview.Fields, tableDataPreview.Grid.List)
  104 + if err != nil {
  105 + return err
  106 + }
  107 + if len(tableColumnSQL.Column) > 0 && len(tableColumnSQL.Data) > 0 {
  108 + for _, item := range tableColumnSQL.Data {
  109 + if len(item) > 0 {
  110 + params := make([]interface{}, 0)
  111 + for _, m := range tableColumnSQL.Column {
  112 + if _, ok := item[m]; ok {
  113 + params = append(params, item[m])
  114 + } else {
  115 + params = append(params, "")
  116 + }
  117 + }
  118 + err = conn.DB().Exec(tableColumnSQL.Sql, params...).Error
  119 + if err != nil {
  120 + return err
  121 + }
  122 + }
  123 + }
  124 + }
  125 + return nil
  126 +}
  127 +
  128 +// Find 获取表内所有数据
  129 +func (repository *ObjectTableDataRepository) Find(ctx context.Context, conn transaction.Conn, tableId int, query *domain.ObjectTableDataQuery) (int64, []map[string]interface{}, error) {
  130 + tx := conn.DB().Table(fmt.Sprintf("data.%v", tableId))
  131 + if len(query.Conditions) > 0 {
  132 + for _, item := range query.Conditions {
  133 + if item.FieldName == "" {
  134 + continue
  135 + }
  136 + if item.Like != "" {
  137 + tx = tx.Where(item.FieldName+" like ?", item.Like)
  138 + }
  139 + if len(item.In) > 0 {
  140 + tx = tx.Where(item.FieldName+" in ?", item.In)
  141 + }
  142 + if item.Order != "" {
  143 + tx = tx.Order(item.FieldName + " " + item.Order)
  144 + }
  145 + }
  146 + }
  147 + if query.Group != "" {
  148 + tx = tx.Group(query.Group)
  149 + }
  150 + if query.Select != "" {
  151 + tx = tx.Select(query.Select)
  152 + }
  153 + list := make([]map[string]interface{}, 0)
  154 + options := domain.NewQueryOptions()
  155 + if query.Size > 0 {
  156 + options = options.WithOffsetLimit(query.Page, query.Size)
  157 + }
  158 + total, tx := transaction.PaginationAndCount(ctx, tx, options, &list)
  159 + return total, list, tx.Error
  160 +}
  161 +
  162 +// SyncData 同步表数据
  163 +//func (repository *ObjectTableDataRepository) SyncData(ctx context.Context, conn transaction.Conn, companyId int64, tableId int) error {
  164 +//
  165 +//}
  166 +
  167 +func NewObjectTableDataRepository() domain.ObjectTableDataRepository {
  168 + return &ObjectTableDataRepository{}
  169 +}
  1 +package repository
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/jinzhu/copier"
  6 + "github.com/pkg/errors"
  7 + "github.com/tiptok/gocomm/pkg/cache"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/models"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
  11 + "gorm.io/gorm"
  12 +)
  13 +
  14 +type ObjectTableRepository struct {
  15 + *cache.CachedRepository
  16 +}
  17 +
  18 +func (repository *ObjectTableRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.ObjectTable) (*domain.ObjectTable, error) {
  19 + var (
  20 + err error
  21 + m = &models.ObjectTable{}
  22 + tx = conn.DB()
  23 + )
  24 + if m, err = repository.DomainModelToModel(dm); err != nil {
  25 + return nil, err
  26 + }
  27 + if tx = tx.Model(m).Save(m); tx.Error != nil {
  28 + return nil, tx.Error
  29 + }
  30 + dm.Id = m.Id
  31 + return repository.ModelToDomainModel(m)
  32 +
  33 +}
  34 +
  35 +func (repository *ObjectTableRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ObjectTable) (*domain.ObjectTable, error) {
  36 + var (
  37 + err error
  38 + m *models.ObjectTable
  39 + tx = conn.DB()
  40 + )
  41 + if m, err = repository.DomainModelToModel(dm); err != nil {
  42 + return nil, err
  43 + }
  44 + queryFunc := func() (interface{}, error) {
  45 + tx = tx.Model(m).Updates(m)
  46 + return nil, tx.Error
  47 + }
  48 + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  49 + return nil, err
  50 + }
  51 + return repository.ModelToDomainModel(m)
  52 +}
  53 +
  54 +func (repository *ObjectTableRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.ObjectTable) (*domain.ObjectTable, error) {
  55 + var (
  56 + err error
  57 + m *models.ObjectTable
  58 + tx = transaction.DB()
  59 + )
  60 + if m, err = repository.DomainModelToModel(dm); err != nil {
  61 + return nil, err
  62 + }
  63 + oldVersion := dm.Version
  64 + m.Version += 1
  65 + queryFunc := func() (interface{}, error) {
  66 + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
  67 + if tx.RowsAffected == 0 {
  68 + return nil, domain.ErrUpdateFail
  69 + }
  70 + return nil, tx.Error
  71 + }
  72 + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  73 + return nil, err
  74 + }
  75 + return repository.ModelToDomainModel(m)
  76 +}
  77 +
  78 +func (repository *ObjectTableRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ObjectTable) (*domain.ObjectTable, error) {
  79 + var (
  80 + tx = conn.DB()
  81 + m = &models.ObjectTable{Id: dm.Identify().(int)}
  82 + )
  83 + queryFunc := func() (interface{}, error) {
  84 + tx = tx.Where("id = ?", m.Id).Unscoped().Delete(m)
  85 + return m, tx.Error
  86 + }
  87 + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  88 + return dm, err
  89 + }
  90 + return repository.ModelToDomainModel(m)
  91 +}
  92 +
  93 +func (repository *ObjectTableRepository) FindOne(ctx context.Context, conn transaction.Conn, id int) (*domain.ObjectTable, error) {
  94 + var (
  95 + err error
  96 + tx = conn.DB()
  97 + m = new(models.ObjectTable)
  98 + )
  99 + queryFunc := func() (interface{}, error) {
  100 + tx = tx.Model(m).Where("id = ?", id).First(m)
  101 + if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
  102 + return nil, domain.ErrNotFound
  103 + }
  104 + return m, tx.Error
  105 + }
  106 + cacheModel := new(models.ObjectTable)
  107 + cacheModel.Id = id
  108 + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
  109 + return nil, err
  110 + }
  111 + return repository.ModelToDomainModel(m)
  112 +}
  113 +
  114 +func (repository *ObjectTableRepository) FindOneByTableId(ctx context.Context, conn transaction.Conn, tableId int) (*domain.ObjectTable, error) {
  115 + var (
  116 + tx = conn.DB()
  117 + m = new(models.ObjectTable)
  118 + )
  119 + tx = tx.Model(m).Where("table_id = ?", tableId).First(m)
  120 + if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
  121 + return nil, domain.ErrNotFound
  122 + }
  123 + return repository.ModelToDomainModel(m)
  124 +}
  125 +
  126 +func (repository *ObjectTableRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.ObjectTable, error) {
  127 + var (
  128 + tx = conn.DB()
  129 + ms []*models.ObjectTable
  130 + dms = make([]*domain.ObjectTable, 0)
  131 + total int64
  132 + )
  133 + queryFunc := func() (interface{}, error) {
  134 + tx = tx.Model(&ms).Order("id desc")
  135 + if v, ok := queryOptions["companyId"]; ok {
  136 + tx = tx.Where("company_id = ?", v)
  137 + }
  138 + if v, ok := queryOptions["tableTypeIn"]; ok {
  139 + tx = tx.Where("table_type in ?", v)
  140 + }
  141 + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
  142 + return dms, tx.Error
  143 + }
  144 + return dms, nil
  145 + }
  146 +
  147 + if _, err := repository.Query(queryFunc); err != nil {
  148 + return 0, nil, err
  149 + }
  150 +
  151 + for _, item := range ms {
  152 + if dm, err := repository.ModelToDomainModel(item); err != nil {
  153 + return 0, dms, err
  154 + } else {
  155 + dms = append(dms, dm)
  156 + }
  157 + }
  158 + return total, dms, nil
  159 +}
  160 +
  161 +func (repository *ObjectTableRepository) ModelToDomainModel(from *models.ObjectTable) (*domain.ObjectTable, error) {
  162 + to := &domain.ObjectTable{}
  163 + err := copier.Copy(to, from)
  164 + return to, err
  165 +}
  166 +
  167 +func (repository *ObjectTableRepository) DomainModelToModel(from *domain.ObjectTable) (*models.ObjectTable, error) {
  168 + to := &models.ObjectTable{}
  169 + err := copier.Copy(to, from)
  170 + return to, err
  171 +}
  172 +
  173 +func NewObjectTableRepository(cache *cache.CachedRepository) domain.ObjectTableRepository {
  174 + return &ObjectTableRepository{CachedRepository: cache}
  175 +}
@@ -35,6 +35,7 @@ type ChartRepository interface { @@ -35,6 +35,7 @@ type ChartRepository interface {
35 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Chart, error) 35 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Chart, error)
36 FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*Chart, error) 36 FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*Chart, error)
37 FindByTypeAndName(ctx context.Context, conn transaction.Conn, tenantId int64, t string, name string) (int64, []*Chart, error) 37 FindByTypeAndName(ctx context.Context, conn transaction.Conn, tenantId int64, t string, name string) (int64, []*Chart, error)
  38 + FindCompanyIds(ctx context.Context, conn transaction.Conn) ([]int64, error)
38 } 39 }
39 40
40 /*************** 索引函数 开始****************/ 41 /*************** 索引函数 开始****************/
@@ -30,6 +30,7 @@ type ChartSettingRepository interface { @@ -30,6 +30,7 @@ type ChartSettingRepository interface {
30 Delete(ctx context.Context, conn transaction.Conn, dm *ChartSetting) (*ChartSetting, error) 30 Delete(ctx context.Context, conn transaction.Conn, dm *ChartSetting) (*ChartSetting, error)
31 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ChartSetting, error) 31 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ChartSetting, error)
32 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ChartSetting, error) 32 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ChartSetting, error)
  33 + CheckUseDataSource(ctx context.Context, conn transaction.Conn, objectId int) (bool, error)
33 } 34 }
34 35
35 func (m *ChartSetting) Identify() interface{} { 36 func (m *ChartSetting) Identify() interface{} {
  1 +package domain
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  7 + "gorm.io/plugin/soft_delete"
  8 +)
  9 +
  10 +type ObjectField struct {
  11 + Id int64 `json:"id"` // ID
  12 + Name string `json:"name"` //表名
  13 + Fields []*bytelib.Field `json:"fields"` //表字段
  14 + Version int `json:"version,omitempty"` //版本
  15 + IsDel soft_delete.DeletedAt `json:"isDel"` //删除标记
  16 + CreatedAt int64 `json:"createdAt,omitempty"` //创建时间
  17 + UpdatedAt int64 `json:"updatedAt,omitempty"` //更新时间
  18 + DeletedAt int64 `json:"deletedAt,omitempty"` //删除时间
  19 +}
  20 +
  21 +type ObjectFieldRepository interface {
  22 + Insert(ctx context.Context, conn transaction.Conn, dm *ObjectField) (*ObjectField, error)
  23 + Update(ctx context.Context, conn transaction.Conn, dm *ObjectField) (*ObjectField, error)
  24 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ObjectField) (*ObjectField, error)
  25 + Delete(ctx context.Context, conn transaction.Conn, dm *ObjectField) (*ObjectField, error)
  26 + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ObjectField, error)
  27 + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ObjectField, error)
  28 +}
  29 +
  30 +func (m *ObjectField) Identify() interface{} {
  31 + if m.Id == 0 {
  32 + return nil
  33 + }
  34 + return m.Id
  35 +}
  1 +package domain
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  7 + "gorm.io/plugin/soft_delete"
  8 +)
  9 +
  10 +type ObjectNotice struct {
  11 + Id int64 `json:"id"` // ID
  12 + CompanyId int64 `json:"companyId"` //公司ID
  13 + TableId int `json:"tableId"` //表ID
  14 + TableType string `json:"tableType"` //表类型 导入模块(主表、附表、分表) 拆解(方案、子过程、计算表) 计算(计算项、计算集)
  15 + ObjectType string `json:"objectType"` //模块 导入模块、拆解模块、计算模块
  16 + Event string `json:"event"` //事件
  17 + TableAffectedList []int `json:"TableAffectedList"` //级联影响到的表
  18 + DataChanged bool `json:"dataChanged"` //数据有更新
  19 + StructChanged bool `json:"structChanged"` //结构有更新
  20 + Status int `json:"status"` //状态 1-等待处理 2-处理完成 3-处理失败
  21 + UpdateTable int `json:"updateTable"` //更新表结构
  22 + UpdateData int `json:"updateData"` //更新表数据
  23 + Message string `json:"message"` //错误信息
  24 + Retry int `json:"retry"` //重试次数
  25 + MetaData ObjectNoticeMetaData `json:"metaData"` //模块信息
  26 + Version int `json:",omitempty"` //版本
  27 + IsDel soft_delete.DeletedAt `json:"isDel"` //删除标记
  28 + CreatedAt int64 `json:"createdAt,omitempty"` //创建时间
  29 + UpdatedAt int64 `json:"updatedAt,omitempty"` //更新时间
  30 + DeletedAt int64 `json:"deletedAt,omitempty"` //删除时间
  31 +}
  32 +
  33 +type ObjectNoticeMetaData struct {
  34 + Module int `json:"module"` // 导入模块判断是否 取消应用
  35 + Status int `json:"status"` // 拆解模块判断是否 取消
  36 +}
  37 +
  38 +var (
  39 + ObjectNoticeStatusWait = 1 //等待处理
  40 + ObjectNoticeStatusDone = 2 //处理完成
  41 + ObjectNoticeStatusError = 3 //处理失败
  42 +)
  43 +
  44 +type ObjectNoticeRepository interface {
  45 + Insert(ctx context.Context, conn transaction.Conn, dm *ObjectNotice) (*ObjectNotice, error)
  46 + Update(ctx context.Context, conn transaction.Conn, dm *ObjectNotice) (*ObjectNotice, error)
  47 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ObjectNotice) (*ObjectNotice, error)
  48 + Delete(ctx context.Context, conn transaction.Conn, dm *ObjectNotice) (*ObjectNotice, error)
  49 + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ObjectNotice, error)
  50 + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ObjectNotice, error)
  51 +}
  52 +
  53 +func (m *ObjectNotice) Identify() interface{} {
  54 + if m.Id == 0 {
  55 + return nil
  56 + }
  57 + return m.Id
  58 +}
  59 +
  60 +// IsDeletedEvent 是否删除事件
  61 +func (m *ObjectNotice) IsDeletedEvent() bool {
  62 + deletedEvents := []string{
  63 + "table.delete",
  64 + "table.query.set.delete",
  65 + }
  66 + for _, event := range deletedEvents {
  67 + if m.Event == event {
  68 + return true
  69 + }
  70 + }
  71 + //导入模块 取消应用和应用于
  72 + if m.Event == "table.apply-on" {
  73 + if m.MetaData.Module&bytelib.ModuleChartTemplate == 0 {
  74 + return true
  75 + }
  76 + }
  77 + //拆解模块 方案启用、禁用
  78 + //计算模块 计算项和计算集启用、禁用
  79 + if m.Event == "table.query.set.update.status" {
  80 + if m.MetaData.Status&bytelib.ModuleChartTemplate == 0 {
  81 + return true
  82 + }
  83 + }
  84 + return false
  85 +}
  1 +package domain
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
  7 + "gorm.io/plugin/soft_delete"
  8 +)
  9 +
  10 +type ObjectTable struct {
  11 + Id int `json:"id"` // ID
  12 + TableId int `json:"tableId" ` //表ID
  13 + Name string `json:"name"` //表名
  14 + TableType string `json:"tableType" ` //模块
  15 + CompanyId int64 `json:"companyId"` //公司id
  16 + ParentId int `json:"parentId"` //父id
  17 + Flag string `json:"flag"` //分组:Group 集合:Set
  18 + Version int `json:"version,omitempty"` //版本
  19 + IsLocal bool `json:"isLocal"` //是否有本地存储
  20 + RemoteDeleted int `json:"remoteDeleted"` //远端删除
  21 + IsDel soft_delete.DeletedAt `json:"isDel,omitempty"` //删除标记
  22 + CreatedAt int64 `json:"createdAt,omitempty"` //创建时间
  23 + UpdatedAt int64 `json:"updatedAt,omitempty"` //更新时间
  24 + DeletedAt int64 `json:"deletedAt,omitempty"` //删除时间
  25 +}
  26 +
  27 +type ObjectTableRepository interface {
  28 + Insert(ctx context.Context, conn transaction.Conn, dm *ObjectTable) (*ObjectTable, error)
  29 + Update(ctx context.Context, conn transaction.Conn, dm *ObjectTable) (*ObjectTable, error)
  30 + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ObjectTable) (*ObjectTable, error)
  31 + Delete(ctx context.Context, conn transaction.Conn, dm *ObjectTable) (*ObjectTable, error)
  32 + FindOne(ctx context.Context, conn transaction.Conn, id int) (*ObjectTable, error)
  33 + FindOneByTableId(ctx context.Context, conn transaction.Conn, tableId int) (*ObjectTable, error)
  34 + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ObjectTable, error)
  35 +}
  36 +
  37 +type ObjectTableDataQuery struct {
  38 + Page int
  39 + Size int
  40 + Conditions []*TableDataCondition
  41 + Group string
  42 + Select string
  43 +}
  44 +
  45 +type TableDataCondition struct {
  46 + FieldName string `json:"field"` // 条件字段
  47 + Like string `json:"like"` // 模糊匹配
  48 + In []string `json:"in"` // 匹配多个值
  49 + Order string `json:"order"` // 排序 ASC DESC 默认ASC
  50 +}
  51 +
  52 +type ObjectTableDataRepository interface {
  53 + InsertWithTableData(ctx context.Context, conn transaction.Conn, tableDataPreview bytelib.TableData) error
  54 + Find(ctx context.Context, conn transaction.Conn, tableId int, query *ObjectTableDataQuery) (int64, []map[string]interface{}, error)
  55 + DropTable(ctx context.Context, conn transaction.Conn, tableId int) error
  56 +}
  57 +
  58 +func (m *ObjectTable) Identify() interface{} {
  59 + if m.Id == 0 {
  60 + return nil
  61 + }
  62 + return m.Id
  63 +}
@@ -24,3 +24,7 @@ const ( @@ -24,3 +24,7 @@ const (
24 ObjectMetaTable = "MetaTable" 24 ObjectMetaTable = "MetaTable"
25 ObjectDBTable = "DBTable" 25 ObjectDBTable = "DBTable"
26 ) 26 )
  27 +
  28 +const (
  29 + MaxPageSize = 30000 //最大读取行数
  30 +)
1 syntax = "v1" 1 syntax = "v1"
2 2
3 info( 3 info(
4 - title: "天联字库图表模板"  
5 - desc: "图表模板"  
6 - author: "小火箭"  
7 - email: "email"  
8 - version: "v1" 4 + title: "天联字库图表模板"
  5 + desc: "图表模板"
  6 + author: "小火箭"
  7 + email: "email"
  8 + version: "v1"
9 ) 9 )
10 10
11 @server( 11 @server(
12 - prefix: v1  
13 - group: table  
14 - //jwt: JwtAuth  
15 - //middleware: Authority 12 + prefix: v1
  13 + group: table
  14 + //jwt: JwtAuth
  15 + //middleware: Authority
16 ) 16 )
17 service Core { 17 service Core {
18 - @doc "源数据表-字段可选值"  
19 - @handler searchTableFieldOptionalValues  
20 - post /table/field-optional-values (SearchTableByModuleRequest) returns (SearchTableByModuleResponse) 18 + @doc "源数据表-字段可选值"
  19 + @handler searchTableFieldOptionalValues
  20 + post /table/field-optional-values (SearchTableByModuleRequest) returns (SearchTableByModuleResponse)
21 21
22 - @doc "源数据表-详情"  
23 - @handler getTableDetail  
24 - get /table/:tableId (GetTableDetailRequest) returns (GetTableDetailResponse) 22 + @doc "源数据表-详情"
  23 + @handler getTableDetail
  24 + get /table/:tableId (GetTableDetailRequest) returns (GetTableDetailResponse)
25 25
26 - @doc "源数据表-数据"  
27 - @handler searchTableData  
28 - post /table/data (SearchTableDataRequest) returns (SearchTableDataResponse) 26 + @doc "源数据表-数据"
  27 + @handler searchTableData
  28 + post /table/data (SearchTableDataRequest) returns (SearchTableDataResponse)
  29 +
  30 + @doc "源数据表-初始化同步表(首次使用本地存储执行一次)"
  31 + @handler syncTable
  32 + get /table/sync returns (SyncTableResponse)
29 } 33 }
30 34
31 @server( 35 @server(
32 - prefix: v1  
33 - group: table  
34 - jwt: JwtAuth  
35 - //middleware: Authority 36 + prefix: v1
  37 + group: table
  38 + jwt: JwtAuth
  39 + //middleware: Authority
36 ) 40 )
37 service Core { 41 service Core {
38 - @doc "源数据表-按模块搜索"  
39 - @handler searchTableByModule  
40 - post /table/search-by-module (SearchTableByModuleRequest) returns (SearchTableByModuleResponse) 42 + @doc "源数据表-按模块搜索"
  43 + @handler searchTableByModule
  44 + post /table/search-by-module (SearchTableByModuleRequest) returns (SearchTableByModuleResponse)
41 } 45 }
42 46
43 type ( 47 type (
44 - SearchTableByModuleRequest struct{  
45 - Token string `header:"x-mmm-accesstoken,optional"`  
46 - }  
47 - SearchTableByModuleResponse struct{  
48 -  
49 - } 48 + SearchTableByModuleRequest {
  49 + Token string `header:"x-mmm-accesstoken,optional"`
  50 + }
  51 + SearchTableByModuleResponse {
  52 + Count int `json:"count"`
  53 + List []SearchTableByModuleItem `json:"list"`
  54 + }
  55 + SearchTableByModuleItem {
  56 + Id int `json:"id"` //ID
  57 + TableId int `json:"tableId"` //表ID
  58 + Name string `json:"name"` //表名
  59 + TableType string `json:"tableType"` //表类型
  60 + ParentId int `json:"parentId"` //父级ID
  61 + Flag string `json:"flag"` //分组:Group 集合:Set
  62 + IsLocal bool `json:"isLocal"` //是否本地存储
  63 + }
50 64
51 - SearchTableFieldOptionalValuesRequest struct{  
52 - Token string `header:"x-mmm-accesstoken,optional"`  
53 - ObjectId int `json:"objectId"` // 对象ID  
54 - Field string `json:"field"` // 当前选择的字段  
55 - //SqlName string `json:"sqlName,optional"` // 字段SqlName  
56 - // Match string `json:"match"`  
57 - //PageNumber int `json:"pageNumber,optional"` // 分页数  
58 - //PageSize int `json:"pageSize,optional"` // 页码  
59 - Condition []*Condition `json:"conditions,optional"` // 条件  
60 - }  
61 - SearchTableFieldOptionalValuesResponse struct{  
62 - Values []string `json:"values"`  
63 - Total int64 `json:"total"`  
64 - }  
65 - Condition struct {  
66 - FieldName string `json:"field"` // 条件字段  
67 - //SqlName string `json:"sqlName,optional"` // 字段SqlName  
68 - Like string `json:"like,optional"` // 模糊匹配  
69 - In []string `json:"in,optional"` // 匹配多个值  
70 - Order string `json:"order,optional,options=ASC||DESC"` // 排序 ASC DESC 默认ASC  
71 - } 65 + SearchTableFieldOptionalValuesRequest {
  66 + Token string `header:"x-mmm-accesstoken,optional"`
  67 + ObjectId int `json:"objectId"` // 对象ID
  68 + Field string `json:"field"` // 当前选择的字段
  69 + //SqlName string `json:"sqlName,optional"` // 字段SqlName
  70 + // Match string `json:"match"`
  71 + //PageNumber int `json:"pageNumber,optional"` // 分页数
  72 + //PageSize int `json:"pageSize,optional"` // 页码
  73 + Condition []*Condition `json:"conditions,optional"` // 条件
  74 + }
  75 + SearchTableFieldOptionalValuesResponse {
  76 + Values []string `json:"values"`
  77 + Total int64 `json:"total"`
  78 + }
  79 + Condition {
  80 + FieldName string `json:"field"` // 条件字段
  81 + //SqlName string `json:"sqlName,optional"` // 字段SqlName
  82 + Like string `json:"like,optional"` // 模糊匹配
  83 + In []string `json:"in,optional"` // 匹配多个值
  84 + Order string `json:"order,optional,options=ASC||DESC"` // 排序 ASC DESC 默认ASC
  85 + }
72 86
73 - GetTableDetailRequest struct {  
74 - Token string `header:"x-mmm-accesstoken,optional"`  
75 - TableId int `path:"tableId"` // 表ID  
76 - }  
77 - GetTableDetailResponse struct{ 87 + GetTableDetailRequest {
  88 + Token string `header:"x-mmm-accesstoken,optional"`
  89 + TableId int `path:"tableId"` // 表ID
  90 + }
  91 + GetTableDetailResponse {
  92 + }
78 93
79 - } 94 + SearchTableDataRequest {
  95 + Token string `header:"x-mmm-accesstoken,optional"`
  96 + ObjectId int `json:"objectId,optional"` // 对象ID
  97 + PageNumber int `json:"page,optional"` // 分页数
  98 + PageSize int `json:"size,optional"` // 页码
  99 + Condition []*Condition `json:"conditions,optional"` // 条件
  100 + }
  101 + SearchTableDataResponse {
  102 + }
80 103
81 - SearchTableDataRequest struct{  
82 - Token string `header:"x-mmm-accesstoken,optional"`  
83 - ObjectId int `json:"objectId,optional"` // 对象ID  
84 - PageNumber int `json:"page,optional"` // 分页数  
85 - PageSize int `json:"size,optional"` // 页码  
86 - Condition []*Condition `json:"conditions,optional"` // 条件  
87 - }  
88 - SearchTableDataResponse struct{ 104 + SyncTableDataPusher {
  105 + CompanyId int64 `json:"companyId,string"` //公司ID
  106 + ObjectId int `json:"objectId"`
  107 + }
  108 + SyncTableResponse {
89 109
90 - } 110 + }
91 ) 111 )
  1 +CREATE TABLE `chart`
  2 +(
  3 + `id` bigint(0) NOT NULL COMMENT 'ID',
  4 + `pid` bigint(0) NOT NULL COMMENT '父级ID',
  5 + `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '类型',
  6 + `sort` int(0) NOT NULL COMMENT '排序',
  7 + `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '名称',
  8 + PRIMARY KEY (`id`) USING BTREE
  9 +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
  10 +
  11 +CREATE TABLE `chart_setting`
  12 +(
  13 + `id` bigint(0) NOT NULL COMMENT 'ID ',
  14 + `chart_id` bigint(0) NOT NULL COMMENT '图表ID',
  15 + `property` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '属性',
  16 + `style` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '样式',
  17 + `series` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '系列值-数据绑定',
  18 + PRIMARY KEY (`id`) USING BTREE
  19 +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
1 20
2 -CREATE TABLE `chart` (  
3 - `id` bigint(0) NOT NULL COMMENT 'ID',  
4 - `pid` bigint(0) NOT NULL COMMENT '父级ID',  
5 - `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '类型',  
6 - `sort` int(0) NOT NULL COMMENT '排序',  
7 - `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '名称',  
8 - PRIMARY KEY (`id`) USING BTREE 21 +CREATE TABLE `app_page`
  22 +(
  23 + `id` int(0) NOT NULL COMMENT '唯一标识',
  24 + PRIMARY KEY (`id`) USING BTREE
9 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 25 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
10 26
11 -CREATE TABLE `chart_setting` (  
12 - `id` bigint(0) NOT NULL COMMENT 'ID ',  
13 - `chart_id` bigint(0) NOT NULL COMMENT '图表ID',  
14 - `property` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '属性',  
15 - `style` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '样式',  
16 - `series` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '系列值-数据绑定',  
17 - PRIMARY KEY (`id`) USING BTREE 27 +Create Table `object_table`
  28 +(
  29 + `id` int not null comment 'ID',
  30 + PRIMARY KEY (`id`) USING BTREE
18 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 31 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
19 32
20 -CREATE TABLE `app_page` (  
21 - `id` int(0) NOT NULL COMMENT '唯一标识',  
22 - PRIMARY KEY (`id`) USING BTREE 33 +Create Table `object_field`
  34 +(
  35 + `id` int not null comment 'ID',
  36 + PRIMARY KEY (`id`) USING BTREE
23 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 37 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
  38 +
  39 +Create Table `object_notice`
  40 +(
  41 + `id` int not null comment 'ID',
  42 + PRIMARY KEY (`id`) USING BTREE
  43 +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
@@ -6,10 +6,14 @@ require ( @@ -6,10 +6,14 @@ require (
6 github.com/golang-jwt/jwt/v4 v4.5.0 6 github.com/golang-jwt/jwt/v4 v4.5.0
7 github.com/jinzhu/copier v0.4.0 7 github.com/jinzhu/copier v0.4.0
8 github.com/jinzhu/now v1.1.5 8 github.com/jinzhu/now v1.1.5
  9 + github.com/magiconair/properties v1.8.0
9 github.com/pkg/errors v0.9.1 10 github.com/pkg/errors v0.9.1
  11 + github.com/samber/lo v1.38.1
10 github.com/stretchr/testify v1.8.4 12 github.com/stretchr/testify v1.8.4
11 github.com/tiptok/gocomm v1.0.14 13 github.com/tiptok/gocomm v1.0.14
  14 + github.com/zeromicro/go-queue v1.1.8
12 github.com/zeromicro/go-zero v1.5.5 15 github.com/zeromicro/go-zero v1.5.5
  16 + golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17
13 google.golang.org/grpc v1.57.0 17 google.golang.org/grpc v1.57.0
14 gorm.io/driver/mysql v1.5.1 18 gorm.io/driver/mysql v1.5.1
15 gorm.io/driver/postgres v1.5.2 19 gorm.io/driver/postgres v1.5.2
@@ -37,7 +41,6 @@ require ( @@ -37,7 +41,6 @@ require (
37 github.com/garyburd/redigo v1.6.3 // indirect 41 github.com/garyburd/redigo v1.6.3 // indirect
38 github.com/gin-contrib/sse v0.1.0 // indirect 42 github.com/gin-contrib/sse v0.1.0 // indirect
39 github.com/gin-gonic/gin v1.5.0 // indirect 43 github.com/gin-gonic/gin v1.5.0 // indirect
40 - github.com/go-gota/gota v0.12.0 // indirect  
41 github.com/go-logr/logr v1.2.3 // indirect 44 github.com/go-logr/logr v1.2.3 // indirect
42 github.com/go-logr/stdr v1.2.2 // indirect 45 github.com/go-logr/stdr v1.2.2 // indirect
43 github.com/go-openapi/jsonpointer v0.19.6 // indirect 46 github.com/go-openapi/jsonpointer v0.19.6 // indirect
@@ -73,7 +76,6 @@ require ( @@ -73,7 +76,6 @@ require (
73 github.com/json-iterator/go v1.1.12 // indirect 76 github.com/json-iterator/go v1.1.12 // indirect
74 github.com/klauspost/compress v1.15.15 // indirect 77 github.com/klauspost/compress v1.15.15 // indirect
75 github.com/leodido/go-urn v1.1.0 // indirect 78 github.com/leodido/go-urn v1.1.0 // indirect
76 - github.com/magiconair/properties v1.8.0 // indirect  
77 github.com/mailru/easyjson v0.7.7 // indirect 79 github.com/mailru/easyjson v0.7.7 // indirect
78 github.com/mattn/go-colorable v0.1.13 // indirect 80 github.com/mattn/go-colorable v0.1.13 // indirect
79 github.com/mattn/go-isatty v0.0.17 // indirect 81 github.com/mattn/go-isatty v0.0.17 // indirect
@@ -93,7 +95,7 @@ require ( @@ -93,7 +95,7 @@ require (
93 github.com/prometheus/common v0.42.0 // indirect 95 github.com/prometheus/common v0.42.0 // indirect
94 github.com/prometheus/procfs v0.10.1 // indirect 96 github.com/prometheus/procfs v0.10.1 // indirect
95 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect 97 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
96 - github.com/samber/lo v1.38.1 // indirect 98 + github.com/segmentio/kafka-go v0.4.38 // indirect
97 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect 99 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
98 github.com/spaolacci/murmur3 v1.1.0 // indirect 100 github.com/spaolacci/murmur3 v1.1.0 // indirect
99 github.com/spf13/afero v1.2.2 // indirect 101 github.com/spf13/afero v1.2.2 // indirect
@@ -121,7 +123,6 @@ require ( @@ -121,7 +123,6 @@ require (
121 go.uber.org/multierr v1.9.0 // indirect 123 go.uber.org/multierr v1.9.0 // indirect
122 go.uber.org/zap v1.24.0 // indirect 124 go.uber.org/zap v1.24.0 // indirect
123 golang.org/x/crypto v0.12.0 // indirect 125 golang.org/x/crypto v0.12.0 // indirect
124 - golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect  
125 golang.org/x/net v0.14.0 // indirect 126 golang.org/x/net v0.14.0 // indirect
126 golang.org/x/oauth2 v0.7.0 // indirect 127 golang.org/x/oauth2 v0.7.0 // indirect
127 golang.org/x/sys v0.11.0 // indirect 128 golang.org/x/sys v0.11.0 // indirect
@@ -137,7 +138,7 @@ require ( @@ -137,7 +138,7 @@ require (
137 gopkg.in/inf.v0 v0.9.1 // indirect 138 gopkg.in/inf.v0 v0.9.1 // indirect
138 gopkg.in/yaml.v2 v2.4.0 // indirect 139 gopkg.in/yaml.v2 v2.4.0 // indirect
139 gopkg.in/yaml.v3 v3.0.1 // indirect 140 gopkg.in/yaml.v3 v3.0.1 // indirect
140 - gorm.io/datatypes v1.2.0 // indirect 141 + gorm.io/driver/sqlite v1.4.3 // indirect
141 k8s.io/api v0.26.3 // indirect 142 k8s.io/api v0.26.3 // indirect
142 k8s.io/apimachinery v0.27.0-alpha.3 // indirect 143 k8s.io/apimachinery v0.27.0-alpha.3 // indirect
143 k8s.io/client-go v0.26.3 // indirect 144 k8s.io/client-go v0.26.3 // indirect
此 diff 太大无法显示。