正在显示
45 个修改的文件
包含
2335 行增加
和
44 行删除
| 1 | +package dataset | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +func ChatDatasetAddFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.ChatDatasetAddFilesRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := dataset.NewChatDatasetAddFilesLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.ChatDatasetAddFiles(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package dataset | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +func ChatDatasetRemvoeFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.ChatDatasetAddFilesRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := dataset.NewChatDatasetRemvoeFilesLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.ChatDatasetRemvoeFiles(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package document | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +func ChatDocumentBatchSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.ChatDocumentBatchSaveRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := document.NewChatDocumentBatchSaveLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.ChatDocumentBatchSave(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| @@ -93,6 +93,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -93,6 +93,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 93 | Handler: document.ChatDocumentSaveHandler(serverCtx), | 93 | Handler: document.ChatDocumentSaveHandler(serverCtx), |
| 94 | }, | 94 | }, |
| 95 | { | 95 | { |
| 96 | + Method: http.MethodPost, | ||
| 97 | + Path: "/chat/document/batch_save", | ||
| 98 | + Handler: document.ChatDocumentBatchSaveHandler(serverCtx), | ||
| 99 | + }, | ||
| 100 | + { | ||
| 96 | Method: http.MethodDelete, | 101 | Method: http.MethodDelete, |
| 97 | Path: "/chat/document/:id", | 102 | Path: "/chat/document/:id", |
| 98 | Handler: document.ChatDocumentDeleteHandler(serverCtx), | 103 | Handler: document.ChatDocumentDeleteHandler(serverCtx), |
| @@ -147,6 +152,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -147,6 +152,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 147 | Path: "/chat/dataset/search", | 152 | Path: "/chat/dataset/search", |
| 148 | Handler: dataset.ChatDatasetSearchHandler(serverCtx), | 153 | Handler: dataset.ChatDatasetSearchHandler(serverCtx), |
| 149 | }, | 154 | }, |
| 155 | + { | ||
| 156 | + Method: http.MethodPost, | ||
| 157 | + Path: "/chat/dataset/add_files", | ||
| 158 | + Handler: dataset.ChatDatasetAddFilesHandler(serverCtx), | ||
| 159 | + }, | ||
| 160 | + { | ||
| 161 | + Method: http.MethodPost, | ||
| 162 | + Path: "/chat/dataset/remove_files", | ||
| 163 | + Handler: dataset.ChatDatasetRemvoeFilesHandler(serverCtx), | ||
| 164 | + }, | ||
| 150 | }..., | 165 | }..., |
| 151 | ), | 166 | ), |
| 152 | rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), | 167 | rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), |
| @@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/open" | 7 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/open" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata" | 8 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata" |
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool" | ||
| 9 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" | 10 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" |
| 10 | 11 | ||
| 11 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" | 12 | "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" |
| @@ -31,29 +32,51 @@ func NewChatSessionGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ch | @@ -31,29 +32,51 @@ func NewChatSessionGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ch | ||
| 31 | func (l *ChatSessionGetLogic) ChatSessionGet(req *types.ChatSessionGetRequest) (resp *types.ChatSessionGetResponse, err error) { | 32 | func (l *ChatSessionGetLogic) ChatSessionGet(req *types.ChatSessionGetRequest) (resp *types.ChatSessionGetResponse, err error) { |
| 32 | var ( | 33 | var ( |
| 33 | conn = l.svcCtx.DefaultDBConn() | 34 | conn = l.svcCtx.DefaultDBConn() |
| 34 | - dm *domain.ChatSession | 35 | + session *domain.ChatSession |
| 35 | records []*domain.ChatSessionRecord | 36 | records []*domain.ChatSessionRecord |
| 36 | token = contextdata.GetUserTokenFromCtx(l.ctx) | 37 | token = contextdata.GetUserTokenFromCtx(l.ctx) |
| 37 | user open.User | 38 | user open.User |
| 38 | ) | 39 | ) |
| 39 | // 货号唯一 | 40 | // 货号唯一 |
| 40 | - if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil { | 41 | + if session, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil { |
| 41 | return nil, xerr.NewErrMsgErr("不存在", err) | 42 | return nil, xerr.NewErrMsgErr("不存在", err) |
| 42 | } | 43 | } |
| 43 | - if user, err = l.svcCtx.SystemOpen.User(l.ctx, conn, dm.UserId); err != nil { | 44 | + if user, err = l.svcCtx.SystemOpen.User(l.ctx, conn, session.UserId); err != nil { |
| 44 | return nil, xerr.NewErrMsgErr("用户不存在", err) | 45 | return nil, xerr.NewErrMsgErr("用户不存在", err) |
| 45 | } | 46 | } |
| 46 | - if _, records, err = l.svcCtx.ChatSessionRecordRepository.FindByCompanyUser(l.ctx, conn, token.CompanyId, token.UserId, domain.NewQueryOptions().MustWithKV("sessionId", dm.Id)); err != nil { | 47 | + if _, records, err = l.svcCtx.ChatSessionRecordRepository.FindByCompanyUser(l.ctx, conn, token.CompanyId, token.UserId, domain.NewQueryOptions().MustWithKV("sessionId", session.Id)); err != nil { |
| 47 | return nil, xerr.NewErr(err) | 48 | return nil, xerr.NewErr(err) |
| 48 | } | 49 | } |
| 49 | var typesRecords []types.Record | 50 | var typesRecords []types.Record |
| 50 | lo.ForEach(records, func(item *domain.ChatSessionRecord, index int) { | 51 | lo.ForEach(records, func(item *domain.ChatSessionRecord, index int) { |
| 51 | typesRecords = append(typesRecords, NewTypesChatRecord(item, user)) | 52 | typesRecords = append(typesRecords, NewTypesChatRecord(item, user)) |
| 52 | }) | 53 | }) |
| 54 | + var documents []types.ChatDocumentItem | ||
| 55 | + var dataset types.ChatDatasetItem | ||
| 56 | + if session.Type == domain.TypeSparkDocumentsChat && len(session.Metadata.DocumentIds) > 0 { | ||
| 57 | + for _, id := range session.Metadata.DocumentIds { | ||
| 58 | + if item, _ := l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, id); item != nil { | ||
| 59 | + documents = append(documents, types.NewTypesChatDocument(item)) | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + } else if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 { | ||
| 63 | + _, documentMapping, _ := l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, session.Metadata.DatasetId) | ||
| 64 | + lazyDocument := tool.NewLazyLoadService(l.svcCtx.ChatDocumentRepository.FindOne) | ||
| 65 | + lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) { | ||
| 66 | + if document, _ := lazyDocument.Load(l.ctx, conn, item.DocumentId); document != nil { | ||
| 67 | + documents = append(documents, types.NewTypesChatDocument(document)) | ||
| 68 | + } | ||
| 69 | + }) | ||
| 70 | + if item, _ := l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, session.Metadata.DatasetId); item != nil { | ||
| 71 | + dataset = types.NewTypesChatDataset(item, lo.ToPtr(len(documents))) | ||
| 72 | + } | ||
| 73 | + } | ||
| 53 | 74 | ||
| 54 | resp = &types.ChatSessionGetResponse{ | 75 | resp = &types.ChatSessionGetResponse{ |
| 55 | - ChatSession: NewTypesChatSession(dm), | 76 | + ChatSession: NewTypesChatSession(session), |
| 56 | Records: typesRecords, | 77 | Records: typesRecords, |
| 78 | + Documents: documents, | ||
| 79 | + Dataset: &dataset, | ||
| 57 | } | 80 | } |
| 58 | return | 81 | return |
| 59 | } | 82 | } |
| @@ -67,10 +67,20 @@ func NewDomainChatSession(token contextdata.UserToken, item types.ChatSessionIte | @@ -67,10 +67,20 @@ func NewDomainChatSession(token contextdata.UserToken, item types.ChatSessionIte | ||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | func NewTypesChatSession(item *domain.ChatSession) types.ChatSessionItem { | 69 | func NewTypesChatSession(item *domain.ChatSession) types.ChatSessionItem { |
| 70 | + var documentIds []int64 | ||
| 71 | + var datasetId int64 | ||
| 72 | + if item.Metadata != nil { | ||
| 73 | + datasetId = item.Metadata.DatasetId | ||
| 74 | + documentIds = item.Metadata.DocumentIds | ||
| 75 | + } | ||
| 70 | return types.ChatSessionItem{ | 76 | return types.ChatSessionItem{ |
| 71 | Id: item.Id, | 77 | Id: item.Id, |
| 72 | Title: item.Title, | 78 | Title: item.Title, |
| 73 | Abstract: item.Abstract, | 79 | Abstract: item.Abstract, |
| 74 | CreatedAt: item.CreatedAt, | 80 | CreatedAt: item.CreatedAt, |
| 81 | + Module: item.Module, | ||
| 82 | + Type: item.Type, | ||
| 83 | + DatasetId: datasetId, | ||
| 84 | + DocumentIds: documentIds, | ||
| 75 | } | 85 | } |
| 76 | } | 86 | } |
| 1 | +package dataset | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "github.com/samber/lo" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" | ||
| 9 | + | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types" | ||
| 12 | + | ||
| 13 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +type ChatDatasetAddFilesLogic struct { | ||
| 17 | + logx.Logger | ||
| 18 | + ctx context.Context | ||
| 19 | + svcCtx *svc.ServiceContext | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func NewChatDatasetAddFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetAddFilesLogic { | ||
| 23 | + return &ChatDatasetAddFilesLogic{ | ||
| 24 | + Logger: logx.WithContext(ctx), | ||
| 25 | + ctx: ctx, | ||
| 26 | + svcCtx: svcCtx, | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (l *ChatDatasetAddFilesLogic) ChatDatasetAddFiles(req *types.ChatDatasetAddFilesRequest) (resp *types.ChatDatasetAddFilesResponse, err error) { | ||
| 31 | + var ( | ||
| 32 | + conn = l.svcCtx.DefaultDBConn() | ||
| 33 | + dm *domain.ChatDataset | ||
| 34 | + documentMapping []*domain.ChatDatasetDocumentMapping | ||
| 35 | + ) | ||
| 36 | + // 货号唯一 | ||
| 37 | + if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 38 | + return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 39 | + } | ||
| 40 | + _, documentMapping, _ = l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, dm.Id) | ||
| 41 | + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 42 | + for _, id := range req.DocumentIds { | ||
| 43 | + if lo.ContainsBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) bool { | ||
| 44 | + return item.DocumentId == id | ||
| 45 | + }) { | ||
| 46 | + continue | ||
| 47 | + } | ||
| 48 | + if _, err = l.svcCtx.ChatDatasetDocumentMappingRepository.Insert(l.ctx, conn, &domain.ChatDatasetDocumentMapping{ | ||
| 49 | + DatasetId: dm.Id, | ||
| 50 | + DocumentId: id, | ||
| 51 | + }); err != nil { | ||
| 52 | + return err | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + return err | ||
| 56 | + }, true); err != nil { | ||
| 57 | + return nil, xerr.NewErrMsg("添加文档失败") | ||
| 58 | + } | ||
| 59 | + resp = &types.ChatDatasetAddFilesResponse{} | ||
| 60 | + return | ||
| 61 | +} |
| 1 | +package dataset | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "github.com/samber/lo" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" | ||
| 9 | + | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types" | ||
| 12 | + | ||
| 13 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +type ChatDatasetRemvoeFilesLogic struct { | ||
| 17 | + logx.Logger | ||
| 18 | + ctx context.Context | ||
| 19 | + svcCtx *svc.ServiceContext | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func NewChatDatasetRemvoeFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetRemvoeFilesLogic { | ||
| 23 | + return &ChatDatasetRemvoeFilesLogic{ | ||
| 24 | + Logger: logx.WithContext(ctx), | ||
| 25 | + ctx: ctx, | ||
| 26 | + svcCtx: svcCtx, | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (l *ChatDatasetRemvoeFilesLogic) ChatDatasetRemvoeFiles(req *types.ChatDatasetAddFilesRequest) (resp *types.ChatDatasetAddFilesResponse, err error) { | ||
| 31 | + var ( | ||
| 32 | + conn = l.svcCtx.DefaultDBConn() | ||
| 33 | + dm *domain.ChatDataset | ||
| 34 | + documentMapping []*domain.ChatDatasetDocumentMapping | ||
| 35 | + ) | ||
| 36 | + // 货号唯一 | ||
| 37 | + if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 38 | + return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 39 | + } | ||
| 40 | + _, documentMapping, _ = l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, dm.Id) | ||
| 41 | + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 42 | + for _, id := range req.DocumentIds { | ||
| 43 | + var found *domain.ChatDatasetDocumentMapping | ||
| 44 | + if !lo.ContainsBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) bool { | ||
| 45 | + if item.DocumentId == id { | ||
| 46 | + found = item | ||
| 47 | + } | ||
| 48 | + return item.DocumentId == id | ||
| 49 | + }) { | ||
| 50 | + continue | ||
| 51 | + } | ||
| 52 | + if _, err = l.svcCtx.ChatDatasetDocumentMappingRepository.Delete(l.ctx, conn, found); err != nil { | ||
| 53 | + return err | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + return err | ||
| 57 | + }, true); err != nil { | ||
| 58 | + return nil, xerr.NewErrMsg("添加文档失败") | ||
| 59 | + } | ||
| 60 | + resp = &types.ChatDatasetAddFilesResponse{} | ||
| 61 | + return | ||
| 62 | +} |
| 1 | +package document | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/ai" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" | ||
| 9 | + | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types" | ||
| 12 | + | ||
| 13 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +type ChatDocumentBatchSaveLogic struct { | ||
| 17 | + logx.Logger | ||
| 18 | + ctx context.Context | ||
| 19 | + svcCtx *svc.ServiceContext | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func NewChatDocumentBatchSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentBatchSaveLogic { | ||
| 23 | + return &ChatDocumentBatchSaveLogic{ | ||
| 24 | + Logger: logx.WithContext(ctx), | ||
| 25 | + ctx: ctx, | ||
| 26 | + svcCtx: svcCtx, | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (l *ChatDocumentBatchSaveLogic) ChatDocumentBatchSave(req *types.ChatDocumentBatchSaveRequest) (resp *types.ChatDocumentBatchSaveResponse, err error) { | ||
| 31 | + var ( | ||
| 32 | + model *domain.ChatModel | ||
| 33 | + fileId string | ||
| 34 | + documents = make([]types.ChatDocumentItem, 0) | ||
| 35 | + fileMap = make(map[string]string) | ||
| 36 | + ) | ||
| 37 | + model, _ = domain.DefaultChatModels.Match(4) | ||
| 38 | + | ||
| 39 | + for _, file := range req.Files { | ||
| 40 | + // 文件上传星火文档 | ||
| 41 | + // 设置回调 | ||
| 42 | + if fileId, err = ai.SparkUploadFile(model.Config.AppId, model.Config.AppKey, model.Config.AppSecret, ai.SparkFileRequest{ | ||
| 43 | + Url: file.Url, | ||
| 44 | + FileName: file.FileName, | ||
| 45 | + CallbackUrl: "", | ||
| 46 | + }); err != nil { | ||
| 47 | + return nil, xerr.NewErrMsgErr("上传文件到星火文档失败", err) | ||
| 48 | + } | ||
| 49 | + fileMap[file.Url] = fileId | ||
| 50 | + } | ||
| 51 | + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 52 | + for _, file := range req.Files { | ||
| 53 | + var ok bool | ||
| 54 | + if fileId, ok = fileMap[file.Url]; !ok { | ||
| 55 | + continue | ||
| 56 | + } | ||
| 57 | + var dm *domain.ChatDocument | ||
| 58 | + // 唯一判断 | ||
| 59 | + dm = types.NewDomainChatDocument(file.FileName, file.Url, file.Size, fileId) | ||
| 60 | + if dm, err = l.svcCtx.ChatDocumentRepository.Insert(l.ctx, conn, dm); err != nil { | ||
| 61 | + return err | ||
| 62 | + } | ||
| 63 | + documents = append(documents, types.NewTypesChatDocument(dm)) | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + return err | ||
| 67 | + }, true); err != nil { | ||
| 68 | + return nil, xerr.NewErrMsgErr("保存失败", err) | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + resp = &types.ChatDocumentBatchSaveResponse{ | ||
| 72 | + ChatDocument: documents, | ||
| 73 | + } | ||
| 74 | + return | ||
| 75 | +} |
cmd/ep/chat/api/internal/types/dataset.go
0 → 100644
| 1 | +package types | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/samber/lo" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func NewTypesChatDataset(item *domain.ChatDataset, fileNum *int) ChatDatasetItem { | ||
| 9 | + return ChatDatasetItem{ | ||
| 10 | + Id: item.Id, | ||
| 11 | + Name: lo.ToPtr(item.Name), | ||
| 12 | + Desc: lo.ToPtr(item.Desc), | ||
| 13 | + Status: lo.ToPtr(item.Status), | ||
| 14 | + CreatedAt: item.CreatedAt, | ||
| 15 | + UpdatedAt: item.UpdatedAt, | ||
| 16 | + FileNumber: fileNum, | ||
| 17 | + } | ||
| 18 | +} |
| @@ -8,6 +8,8 @@ type ChatSessionGetRequest struct { | @@ -8,6 +8,8 @@ type ChatSessionGetRequest struct { | ||
| 8 | type ChatSessionGetResponse struct { | 8 | type ChatSessionGetResponse struct { |
| 9 | ChatSession ChatSessionItem `json:"session"` | 9 | ChatSession ChatSessionItem `json:"session"` |
| 10 | Records []Record `json:"records"` | 10 | Records []Record `json:"records"` |
| 11 | + Documents []ChatDocumentItem `json:"documents"` | ||
| 12 | + Dataset *ChatDatasetItem `json:"dataset"` | ||
| 11 | } | 13 | } |
| 12 | 14 | ||
| 13 | type ChatSessionSaveRequest struct { | 15 | type ChatSessionSaveRequest struct { |
| @@ -99,7 +101,7 @@ type ChatSessionConversationRequestWs struct { | @@ -99,7 +101,7 @@ type ChatSessionConversationRequestWs struct { | ||
| 99 | SessionId int64 `form:"sessionId"` // 会话ID | 101 | SessionId int64 `form:"sessionId"` // 会话ID |
| 100 | ModelId int64 `form:"modelId"` // 模型ID | 102 | ModelId int64 `form:"modelId"` // 模型ID |
| 101 | ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document) | 103 | ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document) |
| 102 | - Text string `form:"text"` // 内容文本 | 104 | + Text string `form:"text,optional"` // 内容文本 |
| 103 | } | 105 | } |
| 104 | 106 | ||
| 105 | type Record struct { | 107 | type Record struct { |
| @@ -197,6 +199,20 @@ type ChatDocumentRenameResponse struct { | @@ -197,6 +199,20 @@ type ChatDocumentRenameResponse struct { | ||
| 197 | ChatDocument ChatDocumentItem `json:"document"` | 199 | ChatDocument ChatDocumentItem `json:"document"` |
| 198 | } | 200 | } |
| 199 | 201 | ||
| 202 | +type ChatDocumentBatchSaveRequest struct { | ||
| 203 | + Files []DocumentFile `json:"files"` | ||
| 204 | +} | ||
| 205 | + | ||
| 206 | +type ChatDocumentBatchSaveResponse struct { | ||
| 207 | + ChatDocument []ChatDocumentItem `json:"documents"` | ||
| 208 | +} | ||
| 209 | + | ||
| 210 | +type DocumentFile struct { | ||
| 211 | + FileName string `json:"fileName"` | ||
| 212 | + Url string `json:"url"` | ||
| 213 | + Size float64 `json:"size"` // 文件大小(KB) | ||
| 214 | +} | ||
| 215 | + | ||
| 200 | type ChatDatasetGetRequest struct { | 216 | type ChatDatasetGetRequest struct { |
| 201 | Id int64 `path:"id"` | 217 | Id int64 `path:"id"` |
| 202 | } | 218 | } |
| @@ -260,3 +276,11 @@ type ChatDatasetRenameRequest struct { | @@ -260,3 +276,11 @@ type ChatDatasetRenameRequest struct { | ||
| 260 | type ChatDatasetRenameResponse struct { | 276 | type ChatDatasetRenameResponse struct { |
| 261 | ChatDataset ChatDatasetItem `json:"dataset"` | 277 | ChatDataset ChatDatasetItem `json:"dataset"` |
| 262 | } | 278 | } |
| 279 | + | ||
| 280 | +type ChatDatasetAddFilesRequest struct { | ||
| 281 | + Id int64 `json:"id"` // 文档ID | ||
| 282 | + DocumentIds []int64 `json:"documentIds"` // 文档ID列表 | ||
| 283 | +} | ||
| 284 | + | ||
| 285 | +type ChatDatasetAddFilesResponse struct { | ||
| 286 | +} |
| @@ -26,6 +26,12 @@ service Core { | @@ -26,6 +26,12 @@ service Core { | ||
| 26 | @doc "知识库-搜索" | 26 | @doc "知识库-搜索" |
| 27 | @handler chatDatasetSearch | 27 | @handler chatDatasetSearch |
| 28 | post /chat/dataset/search (ChatDatasetSearchRequest) returns (ChatDatasetSearchResponse) | 28 | post /chat/dataset/search (ChatDatasetSearchRequest) returns (ChatDatasetSearchResponse) |
| 29 | + @doc "知识库-添加文件" | ||
| 30 | + @handler chatDatasetAddFiles | ||
| 31 | + post /chat/dataset/add_files (ChatDatasetAddFilesRequest) returns (ChatDatasetAddFilesResponse) | ||
| 32 | + @doc "知识库-移除文件" | ||
| 33 | + @handler chatDatasetRemvoeFiles | ||
| 34 | + post /chat/dataset/remove_files (ChatDatasetAddFilesRequest) returns (ChatDatasetAddFilesResponse) | ||
| 29 | } | 35 | } |
| 30 | 36 | ||
| 31 | type ( | 37 | type ( |
| @@ -77,6 +83,7 @@ type ( | @@ -77,6 +83,7 @@ type ( | ||
| 77 | } | 83 | } |
| 78 | ) | 84 | ) |
| 79 | 85 | ||
| 86 | +// 知识库重命名 | ||
| 80 | type( | 87 | type( |
| 81 | ChatDatasetRenameRequest{ | 88 | ChatDatasetRenameRequest{ |
| 82 | Id int64 `json:"id"` // 文档ID | 89 | Id int64 `json:"id"` // 文档ID |
| @@ -86,3 +93,14 @@ type( | @@ -86,3 +93,14 @@ type( | ||
| 86 | ChatDataset ChatDatasetItem `json:"dataset"` | 93 | ChatDataset ChatDatasetItem `json:"dataset"` |
| 87 | } | 94 | } |
| 88 | ) | 95 | ) |
| 96 | + | ||
| 97 | +// 知识库添加新文档 | ||
| 98 | +type( | ||
| 99 | + ChatDatasetAddFilesRequest{ | ||
| 100 | + Id int64 `json:"id"` // 文档ID | ||
| 101 | + DocumentIds []int64 `json:"documentIds"` // 文档ID列表 | ||
| 102 | + } | ||
| 103 | + ChatDatasetAddFilesResponse{ | ||
| 104 | + | ||
| 105 | + } | ||
| 106 | +) |
| @@ -14,6 +14,9 @@ service Core { | @@ -14,6 +14,9 @@ service Core { | ||
| 14 | @doc "文档-保存" | 14 | @doc "文档-保存" |
| 15 | @handler chatDocumentSave | 15 | @handler chatDocumentSave |
| 16 | post /chat/document (ChatDocumentSaveRequest) returns (ChatDocumentSaveResponse) | 16 | post /chat/document (ChatDocumentSaveRequest) returns (ChatDocumentSaveResponse) |
| 17 | + @doc "文档-批量保存" | ||
| 18 | + @handler chatDocumentBatchSave | ||
| 19 | + post /chat/document/batch_save (ChatDocumentBatchSaveRequest) returns (ChatDocumentBatchSaveResponse) | ||
| 17 | @doc "文档-删除" | 20 | @doc "文档-删除" |
| 18 | @handler chatDocumentDelete | 21 | @handler chatDocumentDelete |
| 19 | delete /chat/document/:id (ChatDocumentDeleteRequest) returns (ChatDocumentDeleteResponse) | 22 | delete /chat/document/:id (ChatDocumentDeleteRequest) returns (ChatDocumentDeleteResponse) |
| @@ -82,6 +85,7 @@ type ( | @@ -82,6 +85,7 @@ type ( | ||
| 82 | } | 85 | } |
| 83 | ) | 86 | ) |
| 84 | 87 | ||
| 88 | +// 文档重命名 | ||
| 85 | type( | 89 | type( |
| 86 | ChatDocumentRenameRequest{ | 90 | ChatDocumentRenameRequest{ |
| 87 | Id int64 `json:"id"` // 文档ID | 91 | Id int64 `json:"id"` // 文档ID |
| @@ -91,3 +95,18 @@ type( | @@ -91,3 +95,18 @@ type( | ||
| 91 | ChatDocument ChatDocumentItem `json:"document"` | 95 | ChatDocument ChatDocumentItem `json:"document"` |
| 92 | } | 96 | } |
| 93 | ) | 97 | ) |
| 98 | + | ||
| 99 | +//文档批量添加 | ||
| 100 | +type( | ||
| 101 | + ChatDocumentBatchSaveRequest { | ||
| 102 | + Files []DocumentFile `json:"files"` | ||
| 103 | + } | ||
| 104 | + ChatDocumentBatchSaveResponse { | ||
| 105 | + ChatDocument []ChatDocumentItem `json:"documents"` | ||
| 106 | + } | ||
| 107 | + DocumentFile{ | ||
| 108 | + FileName string `json:"fileName"` | ||
| 109 | + Url string `json:"url"` | ||
| 110 | + Size float64 `json:"size"` // 文件大小(KB) | ||
| 111 | + } | ||
| 112 | +) |
| @@ -53,6 +53,8 @@ type ( | @@ -53,6 +53,8 @@ type ( | ||
| 53 | ChatSessionGetResponse { | 53 | ChatSessionGetResponse { |
| 54 | ChatSession ChatSessionItem `json:"session"` | 54 | ChatSession ChatSessionItem `json:"session"` |
| 55 | Records []Record `json:"records"` | 55 | Records []Record `json:"records"` |
| 56 | + Documents []ChatDocumentItem `json:"documents"` | ||
| 57 | + Dataset *ChatDatasetItem `json:"dataset"` | ||
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | ChatSessionSaveRequest { | 60 | ChatSessionSaveRequest { |
| @@ -143,7 +145,7 @@ type( | @@ -143,7 +145,7 @@ type( | ||
| 143 | SessionId int64 `form:"sessionId"` // 会话ID | 145 | SessionId int64 `form:"sessionId"` // 会话ID |
| 144 | ModelId int64 `form:"modelId"` // 模型ID | 146 | ModelId int64 `form:"modelId"` // 模型ID |
| 145 | ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document) | 147 | ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document) |
| 146 | - Text string `form:"text"` // 内容文本 | 148 | + Text string `form:"text,optional"` // 内容文本 |
| 147 | } | 149 | } |
| 148 | Record{ | 150 | Record{ |
| 149 | Id int64 `json:"id"` // 记录ID | 151 | Id int64 `json:"id"` // 记录ID |
| 1 | +package app | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/app" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +func SystemAppGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.SystemAppGetRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := app.NewSystemAppGetLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.SystemAppGet(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package app | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/app" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +func SystemAppSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.SystemAppSearchRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := app.NewSystemAppSearchLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.SystemAppSearch(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package app | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/app" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +func SystemAppSetConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.SystemAppSetConfigRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := app.NewSystemAppSetConfigLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.SystemAppSetConfig(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package employee | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + | ||
| 6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/logic/employee" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +func SystemDepartmentEmployeesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 14 | + var req types.DepartmentEmployeesRequest | ||
| 15 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 17 | + return | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + l := employee.NewSystemDepartmentEmployeesLogic(r.Context(), svcCtx) | ||
| 21 | + resp, err := l.SystemDepartmentEmployees(&req) | ||
| 22 | + if err != nil { | ||
| 23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 24 | + } else { | ||
| 25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} |
| @@ -4,6 +4,7 @@ package handler | @@ -4,6 +4,7 @@ package handler | ||
| 4 | import ( | 4 | import ( |
| 5 | "net/http" | 5 | "net/http" |
| 6 | 6 | ||
| 7 | + app "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/app" | ||
| 7 | auth "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/auth" | 8 | auth "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/auth" |
| 8 | company "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/company" | 9 | company "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/company" |
| 9 | department "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/department" | 10 | department "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/handler/department" |
| @@ -129,6 +130,31 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -129,6 +130,31 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 129 | []rest.Route{ | 130 | []rest.Route{ |
| 130 | { | 131 | { |
| 131 | Method: http.MethodGet, | 132 | Method: http.MethodGet, |
| 133 | + Path: "/system/app/:id", | ||
| 134 | + Handler: app.SystemAppGetHandler(serverCtx), | ||
| 135 | + }, | ||
| 136 | + { | ||
| 137 | + Method: http.MethodPost, | ||
| 138 | + Path: "/system/app/search", | ||
| 139 | + Handler: app.SystemAppSearchHandler(serverCtx), | ||
| 140 | + }, | ||
| 141 | + { | ||
| 142 | + Method: http.MethodGet, | ||
| 143 | + Path: "/system/app/set_config", | ||
| 144 | + Handler: app.SystemAppSetConfigHandler(serverCtx), | ||
| 145 | + }, | ||
| 146 | + }..., | ||
| 147 | + ), | ||
| 148 | + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), | ||
| 149 | + rest.WithPrefix("/v1"), | ||
| 150 | + ) | ||
| 151 | + | ||
| 152 | + server.AddRoutes( | ||
| 153 | + rest.WithMiddlewares( | ||
| 154 | + []rest.Middleware{serverCtx.LogRequest}, | ||
| 155 | + []rest.Route{ | ||
| 156 | + { | ||
| 157 | + Method: http.MethodGet, | ||
| 132 | Path: "/system/employee/:id", | 158 | Path: "/system/employee/:id", |
| 133 | Handler: employee.SystemEmployeeGetHandler(serverCtx), | 159 | Handler: employee.SystemEmployeeGetHandler(serverCtx), |
| 134 | }, | 160 | }, |
| @@ -172,6 +198,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -172,6 +198,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 172 | Path: "/system/employee/export", | 198 | Path: "/system/employee/export", |
| 173 | Handler: employee.SystemEmployeeExportHandler(serverCtx), | 199 | Handler: employee.SystemEmployeeExportHandler(serverCtx), |
| 174 | }, | 200 | }, |
| 201 | + { | ||
| 202 | + Method: http.MethodPost, | ||
| 203 | + Path: "/system/department-employees", | ||
| 204 | + Handler: employee.SystemDepartmentEmployeesHandler(serverCtx), | ||
| 205 | + }, | ||
| 175 | }..., | 206 | }..., |
| 176 | ), | 207 | ), |
| 177 | rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), | 208 | rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), |
| 1 | +package app | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" | ||
| 7 | + | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types" | ||
| 10 | + | ||
| 11 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type SystemAppGetLogic struct { | ||
| 15 | + logx.Logger | ||
| 16 | + ctx context.Context | ||
| 17 | + svcCtx *svc.ServiceContext | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func NewSystemAppGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemAppGetLogic { | ||
| 21 | + return &SystemAppGetLogic{ | ||
| 22 | + Logger: logx.WithContext(ctx), | ||
| 23 | + ctx: ctx, | ||
| 24 | + svcCtx: svcCtx, | ||
| 25 | + } | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func (l *SystemAppGetLogic) SystemAppGet(req *types.SystemAppGetRequest) (resp *types.SystemAppGetResponse, err error) { | ||
| 29 | + var ( | ||
| 30 | + conn = l.svcCtx.DefaultDBConn() | ||
| 31 | + companyApp *domain.SysCompanyApp | ||
| 32 | + app *domain.SysApp | ||
| 33 | + ) | ||
| 34 | + if companyApp, err = l.svcCtx.CompanyAppRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 35 | + return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 36 | + } | ||
| 37 | + if app, err = l.svcCtx.AppRepository.FindOne(l.ctx, conn, companyApp.AppId); err != nil { | ||
| 38 | + return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 39 | + } | ||
| 40 | + resp = &types.SystemAppGetResponse{ | ||
| 41 | + SystemApp: NewTypesSystemAppItem(app, companyApp), | ||
| 42 | + } | ||
| 43 | + return | ||
| 44 | +} |
| 1 | +package app | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "github.com/samber/lo" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" | ||
| 9 | + | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types" | ||
| 12 | + | ||
| 13 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +type SystemAppSearchLogic struct { | ||
| 17 | + logx.Logger | ||
| 18 | + ctx context.Context | ||
| 19 | + svcCtx *svc.ServiceContext | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func NewSystemAppSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemAppSearchLogic { | ||
| 23 | + return &SystemAppSearchLogic{ | ||
| 24 | + Logger: logx.WithContext(ctx), | ||
| 25 | + ctx: ctx, | ||
| 26 | + svcCtx: svcCtx, | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (l *SystemAppSearchLogic) SystemAppSearch(req *types.SystemAppSearchRequest) (resp *types.SystemAppSearchResponse, err error) { | ||
| 31 | + var ( | ||
| 32 | + conn = l.svcCtx.DefaultDBConn() | ||
| 33 | + apps []*domain.SysApp | ||
| 34 | + companyApps []*domain.SysCompanyApp | ||
| 35 | + token = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 36 | + ) | ||
| 37 | + | ||
| 38 | + queryOptions := domain.NewQueryOptions(). | ||
| 39 | + LikeKV("name", req.Name) | ||
| 40 | + if _, apps, err = l.svcCtx.AppRepository.Find(l.ctx, conn, queryOptions); err != nil { | ||
| 41 | + return nil, xerr.NewErr(err) | ||
| 42 | + } | ||
| 43 | + appsMap := lo.SliceToMap(apps, func(item *domain.SysApp) (int64, *domain.SysApp) { | ||
| 44 | + return item.Id, item | ||
| 45 | + }) | ||
| 46 | + | ||
| 47 | + if _, companyApps, err = l.svcCtx.CompanyAppRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("companyId", token.CompanyId)); err != nil { | ||
| 48 | + return nil, xerr.NewErr(err) | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + list := make([]types.SystemAppItem, 0) | ||
| 52 | + for _, cp := range companyApps { | ||
| 53 | + var ( | ||
| 54 | + app *domain.SysApp | ||
| 55 | + ok bool | ||
| 56 | + ) | ||
| 57 | + if app, ok = appsMap[cp.AppId]; !ok { | ||
| 58 | + continue | ||
| 59 | + } | ||
| 60 | + list = append(list, NewTypesSystemAppItem(app, cp)) | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + // 公司配置APP | ||
| 64 | + for _, app := range apps { | ||
| 65 | + if !lo.ContainsBy(companyApps, func(item *domain.SysCompanyApp) bool { | ||
| 66 | + return item.AppId == app.Id | ||
| 67 | + }) { | ||
| 68 | + l.svcCtx.CompanyAppRepository.Insert(l.ctx, conn, &domain.SysCompanyApp{ | ||
| 69 | + CompanyId: token.CompanyId, | ||
| 70 | + AppId: app.Id, | ||
| 71 | + Status: domain.Enable, | ||
| 72 | + VisibleFlag: domain.VisibleAll, | ||
| 73 | + VisibleUsers: make([]int64, 0), | ||
| 74 | + VisibleGroups: make([]int64, 0), | ||
| 75 | + AppConfig: domain.AppConfig{}, | ||
| 76 | + Sort: 1, | ||
| 77 | + }) | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + resp = &types.SystemAppSearchResponse{ | ||
| 81 | + List: list, | ||
| 82 | + Total: int64(len(list)), | ||
| 83 | + } | ||
| 84 | + return | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +//func NewDomainSysApp(item types.SysAppItem) *domain.SysApp { | ||
| 88 | +// return &domain.SysApp{ | ||
| 89 | + | ||
| 90 | +// } | ||
| 91 | +// } | ||
| 92 | + | ||
| 93 | +func NewTypesSystemAppItem(item *domain.SysApp, cp *domain.SysCompanyApp) types.SystemAppItem { | ||
| 94 | + return types.SystemAppItem{ | ||
| 95 | + Id: cp.Id, | ||
| 96 | + Code: item.Code, | ||
| 97 | + Name: item.Name, | ||
| 98 | + Logo: item.Logo, | ||
| 99 | + Description: item.Description, | ||
| 100 | + Type: item.Type, | ||
| 101 | + VersionNumber: item.VersionNumber, | ||
| 102 | + Status: cp.Status, | ||
| 103 | + VisibleFlag: cp.VisibleFlag, | ||
| 104 | + VisibleUsers: cp.VisibleUsers, | ||
| 105 | + Sort: cp.Sort, | ||
| 106 | + } | ||
| 107 | +} |
| 1 | +package app | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types" | ||
| 8 | + | ||
| 9 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type SystemAppSetConfigLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewSystemAppSetConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemAppSetConfigLogic { | ||
| 19 | + return &SystemAppSetConfigLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *SystemAppSetConfigLogic) SystemAppSetConfig(req *types.SystemAppSetConfigRequest) (resp *types.SystemAppSetConfigResponse, err error) { | ||
| 27 | + | ||
| 28 | + return | ||
| 29 | +} |
| 1 | +package employee | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/svc" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/api/internal/types" | ||
| 8 | + | ||
| 9 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type SystemDepartmentEmployeesLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewSystemDepartmentEmployeesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemDepartmentEmployeesLogic { | ||
| 19 | + return &SystemDepartmentEmployeesLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *SystemDepartmentEmployeesLogic) SystemDepartmentEmployees(req *types.DepartmentEmployeesRequest) (resp *types.DepartmentEmployeesResponse, err error) { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return | ||
| 30 | +} |
| @@ -34,6 +34,7 @@ type ServiceContext struct { | @@ -34,6 +34,7 @@ type ServiceContext struct { | ||
| 34 | RoleRepository domain.SysRoleRepository | 34 | RoleRepository domain.SysRoleRepository |
| 35 | GroupRepository domain.SysGroupRepository | 35 | GroupRepository domain.SysGroupRepository |
| 36 | AppRepository domain.SysAppRepository | 36 | AppRepository domain.SysAppRepository |
| 37 | + CompanyAppRepository domain.SysCompanyAppRepository | ||
| 37 | UserDepartmentRepository domain.SysUserDepartmentRepository | 38 | UserDepartmentRepository domain.SysUserDepartmentRepository |
| 38 | } | 39 | } |
| 39 | 40 | ||
| @@ -62,6 +63,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -62,6 +63,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
| 62 | GroupRepository: repository.NewSysGroupRepository(cache.NewCachedRepository(mlCache)), | 63 | GroupRepository: repository.NewSysGroupRepository(cache.NewCachedRepository(mlCache)), |
| 63 | AppRepository: repository.NewSysAppRepository(cache.NewCachedRepository(mlCache)), | 64 | AppRepository: repository.NewSysAppRepository(cache.NewCachedRepository(mlCache)), |
| 64 | UserDepartmentRepository: repository.NewSysUserDepartmentRepository(cache.NewCachedRepository(mlCache)), | 65 | UserDepartmentRepository: repository.NewSysUserDepartmentRepository(cache.NewCachedRepository(mlCache)), |
| 66 | + CompanyAppRepository: repository.NewSysCompanyAppRepository(cache.NewCachedRepository(mlCache)), | ||
| 65 | } | 67 | } |
| 66 | } | 68 | } |
| 67 | 69 |
| @@ -147,6 +147,52 @@ type Group struct { | @@ -147,6 +147,52 @@ type Group struct { | ||
| 147 | Name string `json:"name"` // 分组名称 | 147 | Name string `json:"name"` // 分组名称 |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | +type SystemAppGetRequest struct { | ||
| 151 | + Id int64 `path:"id"` | ||
| 152 | +} | ||
| 153 | + | ||
| 154 | +type SystemAppGetResponse struct { | ||
| 155 | + SystemApp SystemAppItem `json:"app"` | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +type SystemAppUpdateResponse struct { | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +type SystemAppSearchRequest struct { | ||
| 162 | + Page int `json:"page,optional"` | ||
| 163 | + Size int `json:"size,optional"` | ||
| 164 | + Name string `json:"name,optional"` | ||
| 165 | + VisibleFlag int `json:"visibleFlag,optional"` //0:所有 1:全员可见 2:部分可见 3:已停用 | ||
| 166 | +} | ||
| 167 | + | ||
| 168 | +type SystemAppSearchResponse struct { | ||
| 169 | + List []SystemAppItem `json:"list"` | ||
| 170 | + Total int64 `json:"total"` | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +type SystemAppItem struct { | ||
| 174 | + Id int64 `json:"id,omitempty"` // 唯一标识 | ||
| 175 | + Code string `json:"code,omitempty"` // 应用编码 | ||
| 176 | + Name string `json:"name,omitempty"` // 应用名称 | ||
| 177 | + Logo string `json:"logo,omitempty"` // 图标 | ||
| 178 | + Description string `json:"description,omitempty"` // 描述 | ||
| 179 | + Type string `json:"type,omitempty"` // 分类 default | ||
| 180 | + VersionNumber string `json:"versionNumber,omitempty"` // 应用版本号 | ||
| 181 | + Status int `json:"status,omitempty"` // 1:启用、2:停用 | ||
| 182 | + VisibleFlag int `json:"visibleFlag,omitempty"` // 1:全员可见 2:部分可见 | ||
| 183 | + VisibleUsers []int64 `json:"visibleUsers,omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表 | ||
| 184 | + Sort int `json:"sort,omitempty"` // 排序 | ||
| 185 | +} | ||
| 186 | + | ||
| 187 | +type SystemAppSetConfigRequest struct { | ||
| 188 | + VisibleFlag int `json:"visibleFlag"` // 1:全员可见 2:部分可见 | ||
| 189 | + VisibleUsers []int64 `json:"visibleUsers"` // 可见的用户 所有用户:空 部分用户:用户ID列表 | ||
| 190 | +} | ||
| 191 | + | ||
| 192 | +type SystemAppSetConfigResponse struct { | ||
| 193 | + SystemApp SystemAppItem `json:"app"` | ||
| 194 | +} | ||
| 195 | + | ||
| 150 | type EmployeeGetRequest struct { | 196 | type EmployeeGetRequest struct { |
| 151 | Id int64 `path:"id"` | 197 | Id int64 `path:"id"` |
| 152 | } | 198 | } |
| @@ -226,3 +272,18 @@ type EmployeeImportRequest struct { | @@ -226,3 +272,18 @@ type EmployeeImportRequest struct { | ||
| 226 | 272 | ||
| 227 | type EmployeeImportResponse struct { | 273 | type EmployeeImportResponse struct { |
| 228 | } | 274 | } |
| 275 | + | ||
| 276 | +type DepartmentEmployeesRequest struct { | ||
| 277 | + CompanyId int64 `json:"companyId,optional"` | ||
| 278 | +} | ||
| 279 | + | ||
| 280 | +type DepartmentEmployeesResponse struct { | ||
| 281 | + Departments []DepartmentEmployeeItem `json:"departments"` | ||
| 282 | +} | ||
| 283 | + | ||
| 284 | +type DepartmentEmployeeItem struct { | ||
| 285 | + Id int64 `json:"id"` // 部门ID | ||
| 286 | + Name string `json:"name"` // 部门名称 | ||
| 287 | + Parent int64 `json:"parent"` // 父级 | ||
| 288 | + Employees []Employee `json:"employees"` // 职员列表 | ||
| 289 | +} |
| @@ -58,3 +58,15 @@ CREATE TABLE `sys_user_role` | @@ -58,3 +58,15 @@ CREATE TABLE `sys_user_role` | ||
| 58 | `id` int(0) NOT NULL COMMENT '唯一标识', | 58 | `id` int(0) NOT NULL COMMENT '唯一标识', |
| 59 | PRIMARY KEY (`id`) USING BTREE | 59 | PRIMARY KEY (`id`) USING BTREE |
| 60 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | 60 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; |
| 61 | + | ||
| 62 | +CREATE TABLE `sys_app` | ||
| 63 | +( | ||
| 64 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
| 65 | + PRIMARY KEY (`id`) USING BTREE | ||
| 66 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | ||
| 67 | + | ||
| 68 | +CREATE TABLE `sys_company_app` | ||
| 69 | +( | ||
| 70 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
| 71 | + PRIMARY KEY (`id`) USING BTREE | ||
| 72 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; |
cmd/ep/system/deploy/database/v1.sql
0 → 100644
| 1 | +-- 数据初始化 | ||
| 2 | +INSERT INTO "sys"."app"("id", "code", "name", "logo", "description", "type", "version_number", "status", "created_at", "updated_at", "deleted_at", "version", "is_del") | ||
| 3 | +VALUES (1, 'AI0001', 'AI大模型应用', NULL, '高校检索文档信息,准确回答专业问题。', 'default', '1.0.0', 1, 1717050119, 1717050119, 0, 0, 0); | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +-- 公司应用 唯一索引 | ||
| 7 | +CREATE UNIQUE INDEX unique_company_app ON sys.company_app(company_id,app_id ); |
| 1 | syntax = "v1" | 1 | syntax = "v1" |
| 2 | + | ||
| 3 | + | ||
| 4 | +// 后台接口 | ||
| 5 | +@server( | ||
| 6 | + prefix: v1 | ||
| 7 | + group: app | ||
| 8 | + middleware: LogRequest | ||
| 9 | + jwt: SystemAuth | ||
| 10 | +) | ||
| 11 | +service Core { | ||
| 12 | + @doc "应用-详情" | ||
| 13 | + @handler systemAppGet | ||
| 14 | + get /system/app/:id (SystemAppGetRequest) returns (SystemAppGetResponse) | ||
| 15 | + @doc "应用-搜索" | ||
| 16 | + @handler systemAppSearch | ||
| 17 | + post /system/app/search (SystemAppSearchRequest) returns (SystemAppSearchResponse) | ||
| 18 | + @doc "应用-设置配置" | ||
| 19 | + @handler systemAppSetConfig | ||
| 20 | + get /system/app/set_config (SystemAppSetConfigRequest) returns (SystemAppSetConfigResponse) | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +type ( | ||
| 24 | + SystemAppGetRequest { | ||
| 25 | + Id int64 `path:"id"` | ||
| 26 | + } | ||
| 27 | + SystemAppGetResponse { | ||
| 28 | + SystemApp SystemAppItem `json:"app"` | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + SystemAppUpdateResponse {} | ||
| 32 | + | ||
| 33 | + SystemAppSearchRequest { | ||
| 34 | + Page int `json:"page,optional"` | ||
| 35 | + Size int `json:"size,optional"` | ||
| 36 | + Name string `json:"name,optional"` | ||
| 37 | + VisibleFlag int `json:"visibleFlag,optional"` //0:所有 1:全员可见 2:部分可见 3:已停用 | ||
| 38 | + } | ||
| 39 | + SystemAppSearchResponse{ | ||
| 40 | + List []SystemAppItem `json:"list"` | ||
| 41 | + Total int64 `json:"total"` | ||
| 42 | + } | ||
| 43 | + SystemAppItem { | ||
| 44 | + Id int64 `json:"id,omitempty"` // 唯一标识 | ||
| 45 | + Code string `json:"code,omitempty"` // 应用编码 | ||
| 46 | + Name string `json:"name,omitempty"` // 应用名称 | ||
| 47 | + Logo string `json:"logo,omitempty"` // 图标 | ||
| 48 | + Description string `json:"description,omitempty"` // 描述 | ||
| 49 | + Type string `json:"type,omitempty"` // 分类 default | ||
| 50 | + VersionNumber string `json:"versionNumber,omitempty"` // 应用版本号 | ||
| 51 | + Status int `json:"status,omitempty"` // 1:启用、2:停用 | ||
| 52 | + VisibleFlag int `json:"visibleFlag,omitempty"` // 1:全员可见 2:部分可见 | ||
| 53 | + VisibleUsers []int64 `json:"visibleUsers,omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表 | ||
| 54 | + Sort int `json:"sort,omitempty"` // 排序 | ||
| 55 | + } | ||
| 56 | +) | ||
| 57 | + | ||
| 58 | +// 应用-设置配置 | ||
| 59 | +type( | ||
| 60 | + SystemAppSetConfigRequest{ | ||
| 61 | + VisibleFlag int `json:"visibleFlag"` // 1:全员可见 2:部分可见 | ||
| 62 | + VisibleUsers []int64 `json:"visibleUsers"` // 可见的用户 所有用户:空 部分用户:用户ID列表 | ||
| 63 | + } | ||
| 64 | + SystemAppSetConfigResponse{ | ||
| 65 | + SystemApp SystemAppItem `json:"app"` | ||
| 66 | + } | ||
| 67 | +) |
| @@ -35,6 +35,9 @@ service Core { | @@ -35,6 +35,9 @@ service Core { | ||
| 35 | @doc "职员-导出" | 35 | @doc "职员-导出" |
| 36 | @handler systemEmployeeExport | 36 | @handler systemEmployeeExport |
| 37 | post /system/employee/export (EmployeeSearchRequest) returns (EmployeeSearchResponse) | 37 | post /system/employee/export (EmployeeSearchRequest) returns (EmployeeSearchResponse) |
| 38 | + @doc "职员-部门职员" | ||
| 39 | + @handler systemDepartmentEmployees | ||
| 40 | + post /system/department-employees (DepartmentEmployeesRequest) returns (DepartmentEmployeesResponse) | ||
| 38 | } | 41 | } |
| 39 | 42 | ||
| 40 | type( | 43 | type( |
| @@ -108,6 +111,21 @@ type( | @@ -108,6 +111,21 @@ type( | ||
| 108 | EmployeeImportResponse{} | 111 | EmployeeImportResponse{} |
| 109 | ) | 112 | ) |
| 110 | 113 | ||
| 114 | +type ( | ||
| 115 | + DepartmentEmployeesRequest{ | ||
| 116 | + CompanyId int64 `json:"companyId,optional"` | ||
| 117 | + } | ||
| 118 | + DepartmentEmployeesResponse{ | ||
| 119 | + Departments []DepartmentEmployeeItem `json:"departments"` | ||
| 120 | + } | ||
| 121 | + DepartmentEmployeeItem{ | ||
| 122 | + Id int64 `json:"id"` // 部门ID | ||
| 123 | + Name string `json:"name"` // 部门名称 | ||
| 124 | + Parent int64 `json:"parent"` // 父级 | ||
| 125 | + Employees []Employee `json:"employees"` // 职员列表 | ||
| 126 | + } | ||
| 127 | +) | ||
| 128 | + | ||
| 111 | //type( | 129 | //type( |
| 112 | // Department { | 130 | // Department { |
| 113 | // Id int64 `json:"id,optional,omitempty"` // 唯一标识 | 131 | // Id int64 `json:"id,optional,omitempty"` // 唯一标识 |
| @@ -99,6 +99,96 @@ | @@ -99,6 +99,96 @@ | ||
| 99 | ] | 99 | ] |
| 100 | } | 100 | } |
| 101 | }, | 101 | }, |
| 102 | + "v1/system/app/search": { | ||
| 103 | + "post": { | ||
| 104 | + "summary": "应用-搜索", | ||
| 105 | + "operationId": "systemAppSearch", | ||
| 106 | + "responses": { | ||
| 107 | + "200": { | ||
| 108 | + "description": "A successful response.", | ||
| 109 | + "schema": { | ||
| 110 | + "$ref": "#/definitions/SystemAppSearchResponse" | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | + }, | ||
| 114 | + "parameters": [ | ||
| 115 | + { | ||
| 116 | + "name": "body", | ||
| 117 | + "in": "body", | ||
| 118 | + "required": true, | ||
| 119 | + "schema": { | ||
| 120 | + "$ref": "#/definitions/SystemAppSearchRequest" | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + ], | ||
| 124 | + "requestBody": {}, | ||
| 125 | + "tags": [ | ||
| 126 | + "app" | ||
| 127 | + ] | ||
| 128 | + } | ||
| 129 | + }, | ||
| 130 | + "v1/system/app/set_config": { | ||
| 131 | + "get": { | ||
| 132 | + "summary": "应用-设置配置", | ||
| 133 | + "operationId": "systemAppSetConfig", | ||
| 134 | + "responses": { | ||
| 135 | + "200": { | ||
| 136 | + "description": "A successful response.", | ||
| 137 | + "schema": { | ||
| 138 | + "$ref": "#/definitions/SystemAppSetConfigResponse" | ||
| 139 | + } | ||
| 140 | + } | ||
| 141 | + }, | ||
| 142 | + "parameters": [ | ||
| 143 | + { | ||
| 144 | + "name": "visibleFlag", | ||
| 145 | + "description": " 1:全员可见 2:部分可见", | ||
| 146 | + "in": "query", | ||
| 147 | + "required": true, | ||
| 148 | + "type": "integer", | ||
| 149 | + "format": "int32" | ||
| 150 | + }, | ||
| 151 | + { | ||
| 152 | + "name": "visibleUsers", | ||
| 153 | + "description": " 可见的用户 所有用户:空 部分用户:用户ID列表", | ||
| 154 | + "in": "query", | ||
| 155 | + "required": true, | ||
| 156 | + "type": "integer", | ||
| 157 | + "format": "int64" | ||
| 158 | + } | ||
| 159 | + ], | ||
| 160 | + "requestBody": {}, | ||
| 161 | + "tags": [ | ||
| 162 | + "app" | ||
| 163 | + ] | ||
| 164 | + } | ||
| 165 | + }, | ||
| 166 | + "v1/system/app/{id}": { | ||
| 167 | + "get": { | ||
| 168 | + "summary": "应用-详情", | ||
| 169 | + "operationId": "systemAppGet", | ||
| 170 | + "responses": { | ||
| 171 | + "200": { | ||
| 172 | + "description": "A successful response.", | ||
| 173 | + "schema": { | ||
| 174 | + "$ref": "#/definitions/SystemAppGetResponse" | ||
| 175 | + } | ||
| 176 | + } | ||
| 177 | + }, | ||
| 178 | + "parameters": [ | ||
| 179 | + { | ||
| 180 | + "name": "id", | ||
| 181 | + "in": "path", | ||
| 182 | + "required": true, | ||
| 183 | + "type": "string" | ||
| 184 | + } | ||
| 185 | + ], | ||
| 186 | + "requestBody": {}, | ||
| 187 | + "tags": [ | ||
| 188 | + "app" | ||
| 189 | + ] | ||
| 190 | + } | ||
| 191 | + }, | ||
| 102 | "v1/system/company-departments": { | 192 | "v1/system/company-departments": { |
| 103 | "post": { | 193 | "post": { |
| 104 | "summary": "公司部门", | 194 | "summary": "公司部门", |
| @@ -199,6 +289,34 @@ | @@ -199,6 +289,34 @@ | ||
| 199 | ] | 289 | ] |
| 200 | } | 290 | } |
| 201 | }, | 291 | }, |
| 292 | + "v1/system/department-employees": { | ||
| 293 | + "post": { | ||
| 294 | + "summary": "职员-部门职员", | ||
| 295 | + "operationId": "systemDepartmentEmployees", | ||
| 296 | + "responses": { | ||
| 297 | + "200": { | ||
| 298 | + "description": "A successful response.", | ||
| 299 | + "schema": { | ||
| 300 | + "$ref": "#/definitions/DepartmentEmployeesResponse" | ||
| 301 | + } | ||
| 302 | + } | ||
| 303 | + }, | ||
| 304 | + "parameters": [ | ||
| 305 | + { | ||
| 306 | + "name": "body", | ||
| 307 | + "in": "body", | ||
| 308 | + "required": true, | ||
| 309 | + "schema": { | ||
| 310 | + "$ref": "#/definitions/DepartmentEmployeesRequest" | ||
| 311 | + } | ||
| 312 | + } | ||
| 313 | + ], | ||
| 314 | + "requestBody": {}, | ||
| 315 | + "tags": [ | ||
| 316 | + "employee" | ||
| 317 | + ] | ||
| 318 | + } | ||
| 319 | + }, | ||
| 202 | "v1/system/department/batch-del": { | 320 | "v1/system/department/batch-del": { |
| 203 | "delete": { | 321 | "delete": { |
| 204 | "summary": "部门-批量删除", | 322 | "summary": "部门-批量删除", |
| @@ -878,6 +996,64 @@ | @@ -878,6 +996,64 @@ | ||
| 878 | "type": "object", | 996 | "type": "object", |
| 879 | "title": "DepartmentDeleteResponse" | 997 | "title": "DepartmentDeleteResponse" |
| 880 | }, | 998 | }, |
| 999 | + "DepartmentEmployeeItem": { | ||
| 1000 | + "type": "object", | ||
| 1001 | + "properties": { | ||
| 1002 | + "id": { | ||
| 1003 | + "type": "integer", | ||
| 1004 | + "format": "int64", | ||
| 1005 | + "description": " 部门ID" | ||
| 1006 | + }, | ||
| 1007 | + "name": { | ||
| 1008 | + "type": "string", | ||
| 1009 | + "description": " 部门名称" | ||
| 1010 | + }, | ||
| 1011 | + "parent": { | ||
| 1012 | + "type": "integer", | ||
| 1013 | + "format": "int64", | ||
| 1014 | + "description": " 父级" | ||
| 1015 | + }, | ||
| 1016 | + "employees": { | ||
| 1017 | + "type": "array", | ||
| 1018 | + "items": { | ||
| 1019 | + "$ref": "#/definitions/Employee" | ||
| 1020 | + }, | ||
| 1021 | + "description": " 职员列表" | ||
| 1022 | + } | ||
| 1023 | + }, | ||
| 1024 | + "title": "DepartmentEmployeeItem", | ||
| 1025 | + "required": [ | ||
| 1026 | + "id", | ||
| 1027 | + "name", | ||
| 1028 | + "parent", | ||
| 1029 | + "employees" | ||
| 1030 | + ] | ||
| 1031 | + }, | ||
| 1032 | + "DepartmentEmployeesRequest": { | ||
| 1033 | + "type": "object", | ||
| 1034 | + "properties": { | ||
| 1035 | + "companyId": { | ||
| 1036 | + "type": "integer", | ||
| 1037 | + "format": "int64" | ||
| 1038 | + } | ||
| 1039 | + }, | ||
| 1040 | + "title": "DepartmentEmployeesRequest" | ||
| 1041 | + }, | ||
| 1042 | + "DepartmentEmployeesResponse": { | ||
| 1043 | + "type": "object", | ||
| 1044 | + "properties": { | ||
| 1045 | + "departments": { | ||
| 1046 | + "type": "array", | ||
| 1047 | + "items": { | ||
| 1048 | + "$ref": "#/definitions/DepartmentEmployeeItem" | ||
| 1049 | + } | ||
| 1050 | + } | ||
| 1051 | + }, | ||
| 1052 | + "title": "DepartmentEmployeesResponse", | ||
| 1053 | + "required": [ | ||
| 1054 | + "departments" | ||
| 1055 | + ] | ||
| 1056 | + }, | ||
| 881 | "DepartmentGetRequest": { | 1057 | "DepartmentGetRequest": { |
| 882 | "type": "object", | 1058 | "type": "object", |
| 883 | "properties": { | 1059 | "properties": { |
| @@ -1306,6 +1482,183 @@ | @@ -1306,6 +1482,183 @@ | ||
| 1306 | "name" | 1482 | "name" |
| 1307 | ] | 1483 | ] |
| 1308 | }, | 1484 | }, |
| 1485 | + "SystemAppGetRequest": { | ||
| 1486 | + "type": "object", | ||
| 1487 | + "properties": { | ||
| 1488 | + "id": { | ||
| 1489 | + "type": "integer", | ||
| 1490 | + "format": "int64" | ||
| 1491 | + } | ||
| 1492 | + }, | ||
| 1493 | + "title": "SystemAppGetRequest", | ||
| 1494 | + "required": [ | ||
| 1495 | + "id" | ||
| 1496 | + ] | ||
| 1497 | + }, | ||
| 1498 | + "SystemAppGetResponse": { | ||
| 1499 | + "type": "object", | ||
| 1500 | + "properties": { | ||
| 1501 | + "app": { | ||
| 1502 | + "$ref": "#/definitions/SystemAppItem" | ||
| 1503 | + } | ||
| 1504 | + }, | ||
| 1505 | + "title": "SystemAppGetResponse", | ||
| 1506 | + "required": [ | ||
| 1507 | + "app" | ||
| 1508 | + ] | ||
| 1509 | + }, | ||
| 1510 | + "SystemAppItem": { | ||
| 1511 | + "type": "object", | ||
| 1512 | + "properties": { | ||
| 1513 | + "id": { | ||
| 1514 | + "type": "integer", | ||
| 1515 | + "format": "int64", | ||
| 1516 | + "description": " 唯一标识" | ||
| 1517 | + }, | ||
| 1518 | + "code": { | ||
| 1519 | + "type": "string", | ||
| 1520 | + "description": " 应用编码" | ||
| 1521 | + }, | ||
| 1522 | + "name": { | ||
| 1523 | + "type": "string", | ||
| 1524 | + "description": " 应用名称" | ||
| 1525 | + }, | ||
| 1526 | + "logo": { | ||
| 1527 | + "type": "string", | ||
| 1528 | + "description": " 图标" | ||
| 1529 | + }, | ||
| 1530 | + "description": { | ||
| 1531 | + "type": "string", | ||
| 1532 | + "description": " 描述" | ||
| 1533 | + }, | ||
| 1534 | + "type": { | ||
| 1535 | + "type": "string", | ||
| 1536 | + "description": " 分类 default" | ||
| 1537 | + }, | ||
| 1538 | + "versionNumber": { | ||
| 1539 | + "type": "string", | ||
| 1540 | + "description": " 应用版本号" | ||
| 1541 | + }, | ||
| 1542 | + "status": { | ||
| 1543 | + "type": "integer", | ||
| 1544 | + "format": "int32", | ||
| 1545 | + "description": " 1:启用、2:停用" | ||
| 1546 | + }, | ||
| 1547 | + "visibleFlag": { | ||
| 1548 | + "type": "integer", | ||
| 1549 | + "format": "int32", | ||
| 1550 | + "description": " 1:全员可见 2:部分可见" | ||
| 1551 | + }, | ||
| 1552 | + "visibleUsers": { | ||
| 1553 | + "type": "array", | ||
| 1554 | + "items": { | ||
| 1555 | + "type": "integer", | ||
| 1556 | + "format": "int64" | ||
| 1557 | + }, | ||
| 1558 | + "description": " 可见的用户 所有用户:空 部分用户:用户ID列表" | ||
| 1559 | + }, | ||
| 1560 | + "sort": { | ||
| 1561 | + "type": "integer", | ||
| 1562 | + "format": "int32", | ||
| 1563 | + "description": " 排序" | ||
| 1564 | + } | ||
| 1565 | + }, | ||
| 1566 | + "title": "SystemAppItem", | ||
| 1567 | + "required": [ | ||
| 1568 | + "id", | ||
| 1569 | + "code", | ||
| 1570 | + "name", | ||
| 1571 | + "logo", | ||
| 1572 | + "description", | ||
| 1573 | + "type", | ||
| 1574 | + "versionNumber", | ||
| 1575 | + "status", | ||
| 1576 | + "visibleFlag", | ||
| 1577 | + "visibleUsers", | ||
| 1578 | + "sort" | ||
| 1579 | + ] | ||
| 1580 | + }, | ||
| 1581 | + "SystemAppSearchRequest": { | ||
| 1582 | + "type": "object", | ||
| 1583 | + "properties": { | ||
| 1584 | + "page": { | ||
| 1585 | + "type": "integer", | ||
| 1586 | + "format": "int32" | ||
| 1587 | + }, | ||
| 1588 | + "size": { | ||
| 1589 | + "type": "integer", | ||
| 1590 | + "format": "int32" | ||
| 1591 | + }, | ||
| 1592 | + "name": { | ||
| 1593 | + "type": "string" | ||
| 1594 | + }, | ||
| 1595 | + "visibleFlag": { | ||
| 1596 | + "type": "integer", | ||
| 1597 | + "format": "int32", | ||
| 1598 | + "description": "0:所有 1:全员可见 2:部分可见 3:已停用" | ||
| 1599 | + } | ||
| 1600 | + }, | ||
| 1601 | + "title": "SystemAppSearchRequest" | ||
| 1602 | + }, | ||
| 1603 | + "SystemAppSearchResponse": { | ||
| 1604 | + "type": "object", | ||
| 1605 | + "properties": { | ||
| 1606 | + "list": { | ||
| 1607 | + "type": "array", | ||
| 1608 | + "items": { | ||
| 1609 | + "$ref": "#/definitions/SystemAppItem" | ||
| 1610 | + } | ||
| 1611 | + }, | ||
| 1612 | + "total": { | ||
| 1613 | + "type": "integer", | ||
| 1614 | + "format": "int64" | ||
| 1615 | + } | ||
| 1616 | + }, | ||
| 1617 | + "title": "SystemAppSearchResponse", | ||
| 1618 | + "required": [ | ||
| 1619 | + "list", | ||
| 1620 | + "total" | ||
| 1621 | + ] | ||
| 1622 | + }, | ||
| 1623 | + "SystemAppSetConfigRequest": { | ||
| 1624 | + "type": "object", | ||
| 1625 | + "properties": { | ||
| 1626 | + "visibleFlag": { | ||
| 1627 | + "type": "integer", | ||
| 1628 | + "format": "int32", | ||
| 1629 | + "description": " 1:全员可见 2:部分可见" | ||
| 1630 | + }, | ||
| 1631 | + "visibleUsers": { | ||
| 1632 | + "type": "array", | ||
| 1633 | + "items": { | ||
| 1634 | + "type": "integer", | ||
| 1635 | + "format": "int64" | ||
| 1636 | + }, | ||
| 1637 | + "description": " 可见的用户 所有用户:空 部分用户:用户ID列表" | ||
| 1638 | + } | ||
| 1639 | + }, | ||
| 1640 | + "title": "SystemAppSetConfigRequest", | ||
| 1641 | + "required": [ | ||
| 1642 | + "visibleFlag", | ||
| 1643 | + "visibleUsers" | ||
| 1644 | + ] | ||
| 1645 | + }, | ||
| 1646 | + "SystemAppSetConfigResponse": { | ||
| 1647 | + "type": "object", | ||
| 1648 | + "properties": { | ||
| 1649 | + "app": { | ||
| 1650 | + "$ref": "#/definitions/SystemAppItem" | ||
| 1651 | + } | ||
| 1652 | + }, | ||
| 1653 | + "title": "SystemAppSetConfigResponse", | ||
| 1654 | + "required": [ | ||
| 1655 | + "app" | ||
| 1656 | + ] | ||
| 1657 | + }, | ||
| 1658 | + "SystemAppUpdateResponse": { | ||
| 1659 | + "type": "object", | ||
| 1660 | + "title": "SystemAppUpdateResponse" | ||
| 1661 | + }, | ||
| 1309 | "SystemCompanyInfoRequest": { | 1662 | "SystemCompanyInfoRequest": { |
| 1310 | "type": "object", | 1663 | "type": "object", |
| 1311 | "title": "SystemCompanyInfoRequest" | 1664 | "title": "SystemCompanyInfoRequest" |
| 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: v1 | ||
| 14 | + group: sys_company_app | ||
| 15 | + jwt: JwtAuth | ||
| 16 | +) | ||
| 17 | +service Core { | ||
| 18 | + @doc "详情" | ||
| 19 | + @handler sys_company_appGet | ||
| 20 | + get /sys_company_app/:id (SysCompanyAppGetRequest) returns (SysCompanyAppGetResponse) | ||
| 21 | + @doc "保存" | ||
| 22 | + @handler sys_company_appSave | ||
| 23 | + post /sys_company_app (SysCompanyAppSaveRequest) returns (SysCompanyAppSaveResponse) | ||
| 24 | + @doc "删除" | ||
| 25 | + @handler sys_company_appDelete | ||
| 26 | + delete /sys_company_app/:id (SysCompanyAppDeleteRequest) returns (SysCompanyAppDeleteResponse) | ||
| 27 | + @doc "更新" | ||
| 28 | + @handler sys_company_appUpdate | ||
| 29 | + put /sys_company_app/:id (SysCompanyAppUpdateRequest) returns (SysCompanyAppUpdateResponse) | ||
| 30 | + @doc "搜索" | ||
| 31 | + @handler sys_company_appSearch | ||
| 32 | + post /sys_company_app/search (SysCompanyAppSearchRequest) returns (SysCompanyAppSearchResponse) | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +type ( | ||
| 36 | + SysCompanyAppGetRequest { | ||
| 37 | + Id int64 `path:"id"` | ||
| 38 | + } | ||
| 39 | + SysCompanyAppGetResponse { | ||
| 40 | + SysCompanyApp SysCompanyAppItem `json:"sys_company_app"` | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + SysCompanyAppSaveRequest { | ||
| 44 | + SysCompanyApp SysCompanyAppItem `json:"sys_company_app"` | ||
| 45 | + } | ||
| 46 | + SysCompanyAppSaveResponse {} | ||
| 47 | + | ||
| 48 | + SysCompanyAppDeleteRequest { | ||
| 49 | + Id int64 `path:"id"` | ||
| 50 | + } | ||
| 51 | + SysCompanyAppDeleteResponse {} | ||
| 52 | + | ||
| 53 | + SysCompanyAppUpdateRequest { | ||
| 54 | + Id int64 `path:"id"` | ||
| 55 | + SysCompanyApp SysCompanyAppItem `json:"sys_company_app"` | ||
| 56 | + } | ||
| 57 | + SysCompanyAppUpdateResponse {} | ||
| 58 | + | ||
| 59 | + SysCompanyAppSearchRequest { | ||
| 60 | + Page int `json:"page"` | ||
| 61 | + Size int `json:"size"` | ||
| 62 | + } | ||
| 63 | + SysCompanyAppSearchResponse{ | ||
| 64 | + List []SysCompanyAppItem `json:"list"` | ||
| 65 | + Total int64 `json:"total"` | ||
| 66 | + } | ||
| 67 | + SysCompanyAppItem { | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | +) | ||
| 71 | + | ||
| 72 | +// logic CRUD | ||
| 73 | +// Save | ||
| 74 | + //var ( | ||
| 75 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 76 | + // dm *domain.SysCompanyApp | ||
| 77 | + //) | ||
| 78 | + //// 唯一判断 | ||
| 79 | + | ||
| 80 | + //dm = NewDomainSysCompanyApp(req.SysCompanyApp) | ||
| 81 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 82 | + // dm, err = l.svcCtx.SysCompanyAppRepository.Insert(l.ctx, conn, dm) | ||
| 83 | + // return err | ||
| 84 | + //}, true); err != nil { | ||
| 85 | + // return nil, xerr.NewErrMsg("保存失败") | ||
| 86 | + //} | ||
| 87 | + ////resp = &types.SysCompanyAppSaveResponse{} | ||
| 88 | + //return | ||
| 89 | + | ||
| 90 | +//func NewDomainSysCompanyApp(item types.SysCompanyAppItem) *domain.SysCompanyApp { | ||
| 91 | +// return &domain.SysCompanyApp{ | ||
| 92 | + | ||
| 93 | +// } | ||
| 94 | +//} | ||
| 95 | +// | ||
| 96 | +//func NewTypesSysCompanyApp(item *domain.SysCompanyApp) types.SysCompanyAppItem { | ||
| 97 | +// return types.SysCompanyAppItem{ | ||
| 98 | +// Id: item.Id, | ||
| 99 | +// } | ||
| 100 | +//} | ||
| 101 | + | ||
| 102 | +// Get | ||
| 103 | + //var ( | ||
| 104 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 105 | + // dm *domain.SysCompanyApp | ||
| 106 | + //) | ||
| 107 | + //// 货号唯一 | ||
| 108 | + //if dm, err = l.svcCtx.SysCompanyAppRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 109 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 110 | + //} | ||
| 111 | + //resp = &types.SysCompanyAppGetResponse{ | ||
| 112 | + // SysCompanyApp: NewTypesSysCompanyApp(dm), | ||
| 113 | + //} | ||
| 114 | + //return | ||
| 115 | + | ||
| 116 | +// Delete | ||
| 117 | + //var ( | ||
| 118 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 119 | + // dm *domain.SysCompanyApp | ||
| 120 | + //) | ||
| 121 | + //if dm, err = l.svcCtx.SysCompanyAppRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 122 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 123 | + //} | ||
| 124 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 125 | + // if dm, err = l.svcCtx.SysCompanyAppRepository.Delete(l.ctx, conn, dm); err != nil { | ||
| 126 | + // return err | ||
| 127 | + // } | ||
| 128 | + // return nil | ||
| 129 | + //}, true); err != nil { | ||
| 130 | + // return nil, xerr.NewErrMsgErr("移除失败", err) | ||
| 131 | + //} | ||
| 132 | + //return | ||
| 133 | + | ||
| 134 | +// Search | ||
| 135 | + //var ( | ||
| 136 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 137 | + // dms []*domain.SysCompanyApp | ||
| 138 | + // total int64 | ||
| 139 | + //) | ||
| 140 | + // | ||
| 141 | + //queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size). | ||
| 142 | + // WithKV("", "") | ||
| 143 | + | ||
| 144 | + //total, dms, err = l.svcCtx.SysCompanyAppRepository.Find(l.ctx, conn, queryOptions) | ||
| 145 | + //list := make([]types.SysCompanyAppItem, 0) | ||
| 146 | + //for i := range dms { | ||
| 147 | + // list = append(list, NewTypesSysCompanyApp(dms[i])) | ||
| 148 | + //} | ||
| 149 | + //resp = &types.SysCompanyAppSearchResponse{ | ||
| 150 | + // List: list, | ||
| 151 | + // Total: total, | ||
| 152 | + //} | ||
| 153 | + //return | ||
| 154 | + | ||
| 155 | +// Update | ||
| 156 | + //var ( | ||
| 157 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 158 | + // dm *domain.SysCompanyApp | ||
| 159 | + //) | ||
| 160 | + //if dm, err = l.svcCtx.SysCompanyAppRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 161 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 162 | + //} | ||
| 163 | + //// 不可编辑判断 | ||
| 164 | + | ||
| 165 | + //// 赋值 | ||
| 166 | + | ||
| 167 | + //// 更新 | ||
| 168 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 169 | + // dm, err = l.svcCtx.SysCompanyAppRepository.UpdateWithVersion(l.ctx, conn, dm) | ||
| 170 | + // return err | ||
| 171 | + //}, true); err != nil { | ||
| 172 | + // return nil, xerr.NewErrMsg("更新失败") | ||
| 173 | + //} | ||
| 174 | + //resp = &types.SysCompanyAppUpdateResponse{} | ||
| 175 | + //return |
| 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: v1 | ||
| 14 | + group: sys_user_department | ||
| 15 | + jwt: JwtAuth | ||
| 16 | +) | ||
| 17 | +service Core { | ||
| 18 | + @doc "详情" | ||
| 19 | + @handler sys_user_departmentGet | ||
| 20 | + get /sys_user_department/:id (SysUserDepartmentGetRequest) returns (SysUserDepartmentGetResponse) | ||
| 21 | + @doc "保存" | ||
| 22 | + @handler sys_user_departmentSave | ||
| 23 | + post /sys_user_department (SysUserDepartmentSaveRequest) returns (SysUserDepartmentSaveResponse) | ||
| 24 | + @doc "删除" | ||
| 25 | + @handler sys_user_departmentDelete | ||
| 26 | + delete /sys_user_department/:id (SysUserDepartmentDeleteRequest) returns (SysUserDepartmentDeleteResponse) | ||
| 27 | + @doc "更新" | ||
| 28 | + @handler sys_user_departmentUpdate | ||
| 29 | + put /sys_user_department/:id (SysUserDepartmentUpdateRequest) returns (SysUserDepartmentUpdateResponse) | ||
| 30 | + @doc "搜索" | ||
| 31 | + @handler sys_user_departmentSearch | ||
| 32 | + post /sys_user_department/search (SysUserDepartmentSearchRequest) returns (SysUserDepartmentSearchResponse) | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +type ( | ||
| 36 | + SysUserDepartmentGetRequest { | ||
| 37 | + Id int64 `path:"id"` | ||
| 38 | + } | ||
| 39 | + SysUserDepartmentGetResponse { | ||
| 40 | + SysUserDepartment SysUserDepartmentItem `json:"sys_user_department"` | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + SysUserDepartmentSaveRequest { | ||
| 44 | + SysUserDepartment SysUserDepartmentItem `json:"sys_user_department"` | ||
| 45 | + } | ||
| 46 | + SysUserDepartmentSaveResponse {} | ||
| 47 | + | ||
| 48 | + SysUserDepartmentDeleteRequest { | ||
| 49 | + Id int64 `path:"id"` | ||
| 50 | + } | ||
| 51 | + SysUserDepartmentDeleteResponse {} | ||
| 52 | + | ||
| 53 | + SysUserDepartmentUpdateRequest { | ||
| 54 | + Id int64 `path:"id"` | ||
| 55 | + SysUserDepartment SysUserDepartmentItem `json:"sys_user_department"` | ||
| 56 | + } | ||
| 57 | + SysUserDepartmentUpdateResponse {} | ||
| 58 | + | ||
| 59 | + SysUserDepartmentSearchRequest { | ||
| 60 | + Page int `json:"page"` | ||
| 61 | + Size int `json:"size"` | ||
| 62 | + } | ||
| 63 | + SysUserDepartmentSearchResponse{ | ||
| 64 | + List []SysUserDepartmentItem `json:"list"` | ||
| 65 | + Total int64 `json:"total"` | ||
| 66 | + } | ||
| 67 | + SysUserDepartmentItem { | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | +) | ||
| 71 | + | ||
| 72 | +// logic CRUD | ||
| 73 | +// Save | ||
| 74 | + //var ( | ||
| 75 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 76 | + // dm *domain.SysUserDepartment | ||
| 77 | + //) | ||
| 78 | + //// 唯一判断 | ||
| 79 | + | ||
| 80 | + //dm = NewDomainSysUserDepartment(req.SysUserDepartment) | ||
| 81 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 82 | + // dm, err = l.svcCtx.SysUserDepartmentRepository.Insert(l.ctx, conn, dm) | ||
| 83 | + // return err | ||
| 84 | + //}, true); err != nil { | ||
| 85 | + // return nil, xerr.NewErrMsg("保存失败") | ||
| 86 | + //} | ||
| 87 | + ////resp = &types.SysUserDepartmentSaveResponse{} | ||
| 88 | + //return | ||
| 89 | + | ||
| 90 | +//func NewDomainSysUserDepartment(item types.SysUserDepartmentItem) *domain.SysUserDepartment { | ||
| 91 | +// return &domain.SysUserDepartment{ | ||
| 92 | + | ||
| 93 | +// } | ||
| 94 | +//} | ||
| 95 | +// | ||
| 96 | +//func NewTypesSysUserDepartment(item *domain.SysUserDepartment) types.SysUserDepartmentItem { | ||
| 97 | +// return types.SysUserDepartmentItem{ | ||
| 98 | +// Id: item.Id, | ||
| 99 | +// } | ||
| 100 | +//} | ||
| 101 | + | ||
| 102 | +// Get | ||
| 103 | + //var ( | ||
| 104 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 105 | + // dm *domain.SysUserDepartment | ||
| 106 | + //) | ||
| 107 | + //// 货号唯一 | ||
| 108 | + //if dm, err = l.svcCtx.SysUserDepartmentRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 109 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 110 | + //} | ||
| 111 | + //resp = &types.SysUserDepartmentGetResponse{ | ||
| 112 | + // SysUserDepartment: NewTypesSysUserDepartment(dm), | ||
| 113 | + //} | ||
| 114 | + //return | ||
| 115 | + | ||
| 116 | +// Delete | ||
| 117 | + //var ( | ||
| 118 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 119 | + // dm *domain.SysUserDepartment | ||
| 120 | + //) | ||
| 121 | + //if dm, err = l.svcCtx.SysUserDepartmentRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 122 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 123 | + //} | ||
| 124 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 125 | + // if dm, err = l.svcCtx.SysUserDepartmentRepository.Delete(l.ctx, conn, dm); err != nil { | ||
| 126 | + // return err | ||
| 127 | + // } | ||
| 128 | + // return nil | ||
| 129 | + //}, true); err != nil { | ||
| 130 | + // return nil, xerr.NewErrMsgErr("移除失败", err) | ||
| 131 | + //} | ||
| 132 | + //return | ||
| 133 | + | ||
| 134 | +// Search | ||
| 135 | + //var ( | ||
| 136 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 137 | + // dms []*domain.SysUserDepartment | ||
| 138 | + // total int64 | ||
| 139 | + //) | ||
| 140 | + // | ||
| 141 | + //queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size). | ||
| 142 | + // WithKV("", "") | ||
| 143 | + | ||
| 144 | + //total, dms, err = l.svcCtx.SysUserDepartmentRepository.Find(l.ctx, conn, queryOptions) | ||
| 145 | + //list := make([]types.SysUserDepartmentItem, 0) | ||
| 146 | + //for i := range dms { | ||
| 147 | + // list = append(list, NewTypesSysUserDepartment(dms[i])) | ||
| 148 | + //} | ||
| 149 | + //resp = &types.SysUserDepartmentSearchResponse{ | ||
| 150 | + // List: list, | ||
| 151 | + // Total: total, | ||
| 152 | + //} | ||
| 153 | + //return | ||
| 154 | + | ||
| 155 | +// Update | ||
| 156 | + //var ( | ||
| 157 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 158 | + // dm *domain.SysUserDepartment | ||
| 159 | + //) | ||
| 160 | + //if dm, err = l.svcCtx.SysUserDepartmentRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 161 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 162 | + //} | ||
| 163 | + //// 不可编辑判断 | ||
| 164 | + | ||
| 165 | + //// 赋值 | ||
| 166 | + | ||
| 167 | + //// 更新 | ||
| 168 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 169 | + // dm, err = l.svcCtx.SysUserDepartmentRepository.UpdateWithVersion(l.ctx, conn, dm) | ||
| 170 | + // return err | ||
| 171 | + //}, true); err != nil { | ||
| 172 | + // return nil, xerr.NewErrMsg("更新失败") | ||
| 173 | + //} | ||
| 174 | + //resp = &types.SysUserDepartmentUpdateResponse{} | ||
| 175 | + //return |
| 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: v1 | ||
| 14 | + group: sys_user_role | ||
| 15 | + jwt: JwtAuth | ||
| 16 | +) | ||
| 17 | +service Core { | ||
| 18 | + @doc "详情" | ||
| 19 | + @handler sys_user_roleGet | ||
| 20 | + get /sys_user_role/:id (SysUserRoleGetRequest) returns (SysUserRoleGetResponse) | ||
| 21 | + @doc "保存" | ||
| 22 | + @handler sys_user_roleSave | ||
| 23 | + post /sys_user_role (SysUserRoleSaveRequest) returns (SysUserRoleSaveResponse) | ||
| 24 | + @doc "删除" | ||
| 25 | + @handler sys_user_roleDelete | ||
| 26 | + delete /sys_user_role/:id (SysUserRoleDeleteRequest) returns (SysUserRoleDeleteResponse) | ||
| 27 | + @doc "更新" | ||
| 28 | + @handler sys_user_roleUpdate | ||
| 29 | + put /sys_user_role/:id (SysUserRoleUpdateRequest) returns (SysUserRoleUpdateResponse) | ||
| 30 | + @doc "搜索" | ||
| 31 | + @handler sys_user_roleSearch | ||
| 32 | + post /sys_user_role/search (SysUserRoleSearchRequest) returns (SysUserRoleSearchResponse) | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +type ( | ||
| 36 | + SysUserRoleGetRequest { | ||
| 37 | + Id int64 `path:"id"` | ||
| 38 | + } | ||
| 39 | + SysUserRoleGetResponse { | ||
| 40 | + SysUserRole SysUserRoleItem `json:"sys_user_role"` | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + SysUserRoleSaveRequest { | ||
| 44 | + SysUserRole SysUserRoleItem `json:"sys_user_role"` | ||
| 45 | + } | ||
| 46 | + SysUserRoleSaveResponse {} | ||
| 47 | + | ||
| 48 | + SysUserRoleDeleteRequest { | ||
| 49 | + Id int64 `path:"id"` | ||
| 50 | + } | ||
| 51 | + SysUserRoleDeleteResponse {} | ||
| 52 | + | ||
| 53 | + SysUserRoleUpdateRequest { | ||
| 54 | + Id int64 `path:"id"` | ||
| 55 | + SysUserRole SysUserRoleItem `json:"sys_user_role"` | ||
| 56 | + } | ||
| 57 | + SysUserRoleUpdateResponse {} | ||
| 58 | + | ||
| 59 | + SysUserRoleSearchRequest { | ||
| 60 | + Page int `json:"page"` | ||
| 61 | + Size int `json:"size"` | ||
| 62 | + } | ||
| 63 | + SysUserRoleSearchResponse{ | ||
| 64 | + List []SysUserRoleItem `json:"list"` | ||
| 65 | + Total int64 `json:"total"` | ||
| 66 | + } | ||
| 67 | + SysUserRoleItem { | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | +) | ||
| 71 | + | ||
| 72 | +// logic CRUD | ||
| 73 | +// Save | ||
| 74 | + //var ( | ||
| 75 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 76 | + // dm *domain.SysUserRole | ||
| 77 | + //) | ||
| 78 | + //// 唯一判断 | ||
| 79 | + | ||
| 80 | + //dm = NewDomainSysUserRole(req.SysUserRole) | ||
| 81 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 82 | + // dm, err = l.svcCtx.SysUserRoleRepository.Insert(l.ctx, conn, dm) | ||
| 83 | + // return err | ||
| 84 | + //}, true); err != nil { | ||
| 85 | + // return nil, xerr.NewErrMsg("保存失败") | ||
| 86 | + //} | ||
| 87 | + ////resp = &types.SysUserRoleSaveResponse{} | ||
| 88 | + //return | ||
| 89 | + | ||
| 90 | +//func NewDomainSysUserRole(item types.SysUserRoleItem) *domain.SysUserRole { | ||
| 91 | +// return &domain.SysUserRole{ | ||
| 92 | + | ||
| 93 | +// } | ||
| 94 | +//} | ||
| 95 | +// | ||
| 96 | +//func NewTypesSysUserRole(item *domain.SysUserRole) types.SysUserRoleItem { | ||
| 97 | +// return types.SysUserRoleItem{ | ||
| 98 | +// Id: item.Id, | ||
| 99 | +// } | ||
| 100 | +//} | ||
| 101 | + | ||
| 102 | +// Get | ||
| 103 | + //var ( | ||
| 104 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 105 | + // dm *domain.SysUserRole | ||
| 106 | + //) | ||
| 107 | + //// 货号唯一 | ||
| 108 | + //if dm, err = l.svcCtx.SysUserRoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 109 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 110 | + //} | ||
| 111 | + //resp = &types.SysUserRoleGetResponse{ | ||
| 112 | + // SysUserRole: NewTypesSysUserRole(dm), | ||
| 113 | + //} | ||
| 114 | + //return | ||
| 115 | + | ||
| 116 | +// Delete | ||
| 117 | + //var ( | ||
| 118 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 119 | + // dm *domain.SysUserRole | ||
| 120 | + //) | ||
| 121 | + //if dm, err = l.svcCtx.SysUserRoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 122 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 123 | + //} | ||
| 124 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 125 | + // if dm, err = l.svcCtx.SysUserRoleRepository.Delete(l.ctx, conn, dm); err != nil { | ||
| 126 | + // return err | ||
| 127 | + // } | ||
| 128 | + // return nil | ||
| 129 | + //}, true); err != nil { | ||
| 130 | + // return nil, xerr.NewErrMsgErr("移除失败", err) | ||
| 131 | + //} | ||
| 132 | + //return | ||
| 133 | + | ||
| 134 | +// Search | ||
| 135 | + //var ( | ||
| 136 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 137 | + // dms []*domain.SysUserRole | ||
| 138 | + // total int64 | ||
| 139 | + //) | ||
| 140 | + // | ||
| 141 | + //queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size). | ||
| 142 | + // WithKV("", "") | ||
| 143 | + | ||
| 144 | + //total, dms, err = l.svcCtx.SysUserRoleRepository.Find(l.ctx, conn, queryOptions) | ||
| 145 | + //list := make([]types.SysUserRoleItem, 0) | ||
| 146 | + //for i := range dms { | ||
| 147 | + // list = append(list, NewTypesSysUserRole(dms[i])) | ||
| 148 | + //} | ||
| 149 | + //resp = &types.SysUserRoleSearchResponse{ | ||
| 150 | + // List: list, | ||
| 151 | + // Total: total, | ||
| 152 | + //} | ||
| 153 | + //return | ||
| 154 | + | ||
| 155 | +// Update | ||
| 156 | + //var ( | ||
| 157 | + // conn = l.svcCtx.DefaultDBConn() | ||
| 158 | + // dm *domain.SysUserRole | ||
| 159 | + //) | ||
| 160 | + //if dm, err = l.svcCtx.SysUserRoleRepository.FindOne(l.ctx, conn, req.Id); err != nil { | ||
| 161 | + // return nil, xerr.NewErrMsgErr("不存在", err) | ||
| 162 | + //} | ||
| 163 | + //// 不可编辑判断 | ||
| 164 | + | ||
| 165 | + //// 赋值 | ||
| 166 | + | ||
| 167 | + //// 更新 | ||
| 168 | + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 169 | + // dm, err = l.svcCtx.SysUserRoleRepository.UpdateWithVersion(l.ctx, conn, dm) | ||
| 170 | + // return err | ||
| 171 | + //}, true); err != nil { | ||
| 172 | + // return nil, xerr.NewErrMsg("更新失败") | ||
| 173 | + //} | ||
| 174 | + //resp = &types.SysUserRoleUpdateResponse{} | ||
| 175 | + //return |
| 1 | + | ||
| 2 | +syntax = "proto3"; | ||
| 3 | + | ||
| 4 | +option go_package ="./pb"; | ||
| 5 | + | ||
| 6 | +package pb; | ||
| 7 | + | ||
| 8 | +message SysCompanyAppGetReq { | ||
| 9 | + int64 Id = 1; | ||
| 10 | +} | ||
| 11 | +message SysCompanyAppGetResp{ | ||
| 12 | + SysCompanyAppItem SysCompanyApp = 1; | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +message SysCompanyAppSaveReq { | ||
| 16 | + | ||
| 17 | +} | ||
| 18 | +message SysCompanyAppSaveResp{ | ||
| 19 | + | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +message SysCompanyAppDeleteReq { | ||
| 23 | + int64 Id = 1; | ||
| 24 | +} | ||
| 25 | +message SysCompanyAppDeleteResp{ | ||
| 26 | + | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +message SysCompanyAppUpdateReq { | ||
| 30 | + int64 Id = 1; | ||
| 31 | +} | ||
| 32 | +message SysCompanyAppUpdateResp{ | ||
| 33 | + | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +message SysCompanyAppSearchReq { | ||
| 37 | + int64 PageNumber = 1; | ||
| 38 | + int64 PageSize = 2; | ||
| 39 | +} | ||
| 40 | +message SysCompanyAppSearchResp{ | ||
| 41 | + repeated SysCompanyAppItem List =1; | ||
| 42 | + int64 Total =2; | ||
| 43 | +} | ||
| 44 | +message SysCompanyAppItem { | ||
| 45 | + | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +service SysCompanyAppService { | ||
| 49 | + rpc SysCompanyAppGet(SysCompanyAppGetReq) returns(SysCompanyAppGetResp); | ||
| 50 | + rpc SysCompanyAppSave(SysCompanyAppSaveReq) returns(SysCompanyAppSaveResp); | ||
| 51 | + rpc SysCompanyAppDelete(SysCompanyAppDeleteReq) returns(SysCompanyAppDeleteResp); | ||
| 52 | + rpc SysCompanyAppUpdate(SysCompanyAppUpdateReq) returns(SysCompanyAppUpdateResp); | ||
| 53 | + rpc SysCompanyAppSearch(SysCompanyAppSearchReq) returns(SysCompanyAppSearchResp); | ||
| 54 | +} |
| 1 | + | ||
| 2 | +syntax = "proto3"; | ||
| 3 | + | ||
| 4 | +option go_package ="./pb"; | ||
| 5 | + | ||
| 6 | +package pb; | ||
| 7 | + | ||
| 8 | +message SysUserDepartmentGetReq { | ||
| 9 | + int64 Id = 1; | ||
| 10 | +} | ||
| 11 | +message SysUserDepartmentGetResp{ | ||
| 12 | + SysUserDepartmentItem SysUserDepartment = 1; | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +message SysUserDepartmentSaveReq { | ||
| 16 | + | ||
| 17 | +} | ||
| 18 | +message SysUserDepartmentSaveResp{ | ||
| 19 | + | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +message SysUserDepartmentDeleteReq { | ||
| 23 | + int64 Id = 1; | ||
| 24 | +} | ||
| 25 | +message SysUserDepartmentDeleteResp{ | ||
| 26 | + | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +message SysUserDepartmentUpdateReq { | ||
| 30 | + int64 Id = 1; | ||
| 31 | +} | ||
| 32 | +message SysUserDepartmentUpdateResp{ | ||
| 33 | + | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +message SysUserDepartmentSearchReq { | ||
| 37 | + int64 PageNumber = 1; | ||
| 38 | + int64 PageSize = 2; | ||
| 39 | +} | ||
| 40 | +message SysUserDepartmentSearchResp{ | ||
| 41 | + repeated SysUserDepartmentItem List =1; | ||
| 42 | + int64 Total =2; | ||
| 43 | +} | ||
| 44 | +message SysUserDepartmentItem { | ||
| 45 | + | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +service SysUserDepartmentService { | ||
| 49 | + rpc SysUserDepartmentGet(SysUserDepartmentGetReq) returns(SysUserDepartmentGetResp); | ||
| 50 | + rpc SysUserDepartmentSave(SysUserDepartmentSaveReq) returns(SysUserDepartmentSaveResp); | ||
| 51 | + rpc SysUserDepartmentDelete(SysUserDepartmentDeleteReq) returns(SysUserDepartmentDeleteResp); | ||
| 52 | + rpc SysUserDepartmentUpdate(SysUserDepartmentUpdateReq) returns(SysUserDepartmentUpdateResp); | ||
| 53 | + rpc SysUserDepartmentSearch(SysUserDepartmentSearchReq) returns(SysUserDepartmentSearchResp); | ||
| 54 | +} |
| 1 | + | ||
| 2 | +syntax = "proto3"; | ||
| 3 | + | ||
| 4 | +option go_package ="./pb"; | ||
| 5 | + | ||
| 6 | +package pb; | ||
| 7 | + | ||
| 8 | +message SysUserRoleGetReq { | ||
| 9 | + int64 Id = 1; | ||
| 10 | +} | ||
| 11 | +message SysUserRoleGetResp{ | ||
| 12 | + SysUserRoleItem SysUserRole = 1; | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +message SysUserRoleSaveReq { | ||
| 16 | + | ||
| 17 | +} | ||
| 18 | +message SysUserRoleSaveResp{ | ||
| 19 | + | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +message SysUserRoleDeleteReq { | ||
| 23 | + int64 Id = 1; | ||
| 24 | +} | ||
| 25 | +message SysUserRoleDeleteResp{ | ||
| 26 | + | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +message SysUserRoleUpdateReq { | ||
| 30 | + int64 Id = 1; | ||
| 31 | +} | ||
| 32 | +message SysUserRoleUpdateResp{ | ||
| 33 | + | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +message SysUserRoleSearchReq { | ||
| 37 | + int64 PageNumber = 1; | ||
| 38 | + int64 PageSize = 2; | ||
| 39 | +} | ||
| 40 | +message SysUserRoleSearchResp{ | ||
| 41 | + repeated SysUserRoleItem List =1; | ||
| 42 | + int64 Total =2; | ||
| 43 | +} | ||
| 44 | +message SysUserRoleItem { | ||
| 45 | + | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +service SysUserRoleService { | ||
| 49 | + rpc SysUserRoleGet(SysUserRoleGetReq) returns(SysUserRoleGetResp); | ||
| 50 | + rpc SysUserRoleSave(SysUserRoleSaveReq) returns(SysUserRoleSaveResp); | ||
| 51 | + rpc SysUserRoleDelete(SysUserRoleDeleteReq) returns(SysUserRoleDeleteResp); | ||
| 52 | + rpc SysUserRoleUpdate(SysUserRoleUpdateReq) returns(SysUserRoleUpdateResp); | ||
| 53 | + rpc SysUserRoleSearch(SysUserRoleSearchReq) returns(SysUserRoleSearchResp); | ||
| 54 | +} |
| @@ -12,5 +12,7 @@ func Migrate(db *gorm.DB) { | @@ -12,5 +12,7 @@ func Migrate(db *gorm.DB) { | ||
| 12 | models.SysEmployee{}, | 12 | models.SysEmployee{}, |
| 13 | models.SysUser{}, | 13 | models.SysUser{}, |
| 14 | models.SysUserDepartment{}, | 14 | models.SysUserDepartment{}, |
| 15 | + models.SysApp{}, | ||
| 16 | + models.SysCompanyApp{}, | ||
| 15 | ) | 17 | ) |
| 16 | } | 18 | } |
| @@ -10,6 +10,13 @@ import ( | @@ -10,6 +10,13 @@ import ( | ||
| 10 | 10 | ||
| 11 | type SysApp struct { | 11 | type SysApp struct { |
| 12 | Id int64 // 唯一标识 | 12 | Id int64 // 唯一标识 |
| 13 | + Code string // 应用编码 | ||
| 14 | + Name string // 应用名称 | ||
| 15 | + Logo string // 图标 | ||
| 16 | + Description string // 描述 | ||
| 17 | + Type string // 分类 default | ||
| 18 | + VersionNumber string // 应用版本号 | ||
| 19 | + Status int // 1:启用、2:停用 | ||
| 13 | CreatedAt int64 | 20 | CreatedAt int64 |
| 14 | UpdatedAt int64 | 21 | UpdatedAt int64 |
| 15 | DeletedAt int64 | 22 | DeletedAt int64 |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain" | ||
| 6 | + "gorm.io/gorm" | ||
| 7 | + "gorm.io/plugin/soft_delete" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type SysCompanyApp struct { | ||
| 11 | + Id int64 // 唯一标识 | ||
| 12 | + CompanyId int64 // 公司表ID | ||
| 13 | + AppId int64 // 应用ID | ||
| 14 | + Status int // 1:启用、2:停用 | ||
| 15 | + VisibleFlag int // 1:全员可见 2:部分可见 | ||
| 16 | + VisibleUsers []int64 `gorm:"type:jsonb;serializer:json"` // 可见的用户 所有用户:空 部分用户:用户ID列表 | ||
| 17 | + VisibleGroups []int64 `gorm:"type:jsonb;serializer:json"` // 可见的用户组 所有用户:空 部分用户:用户ID列表 | ||
| 18 | + AppConfig domain.AppConfig `gorm:"type:jsonb;serializer:json"` // 应用配置 | ||
| 19 | + Sort int // 排序 | ||
| 20 | + CreatedAt int64 | ||
| 21 | + UpdatedAt int64 | ||
| 22 | + DeletedAt int64 | ||
| 23 | + Version int | ||
| 24 | + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +func (m *SysCompanyApp) TableName() string { | ||
| 28 | + return "sys.company_app" | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +func (m *SysCompanyApp) BeforeCreate(tx *gorm.DB) (err error) { | ||
| 32 | + // m.CreatedAt = time.Now().Unix() | ||
| 33 | + // m.UpdatedAt = time.Now().Unix() | ||
| 34 | + return | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +func (m *SysCompanyApp) BeforeUpdate(tx *gorm.DB) (err error) { | ||
| 38 | + // m.UpdatedAt = time.Now().Unix() | ||
| 39 | + return | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +func (m *SysCompanyApp) CacheKeyFunc() string { | ||
| 43 | + if m.Id == 0 { | ||
| 44 | + return "" | ||
| 45 | + } | ||
| 46 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +func (m *SysCompanyApp) CacheKeyFuncByObject(obj interface{}) string { | ||
| 50 | + if v, ok := obj.(*SysCompanyApp); ok { | ||
| 51 | + return v.CacheKeyFunc() | ||
| 52 | + } | ||
| 53 | + return "" | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +func (m *SysCompanyApp) CachePrimaryKeyFunc() string { | ||
| 57 | + if len("") == 0 { | ||
| 58 | + return "" | ||
| 59 | + } | ||
| 60 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
| 61 | +} |
| 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/su-micro/cmd/ep/system/internal/pkg/db/models" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction" | ||
| 11 | + "gorm.io/gorm" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type SysCompanyAppRepository struct { | ||
| 15 | + *cache.CachedRepository | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (repository *SysCompanyAppRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.SysCompanyApp) (*domain.SysCompanyApp, error) { | ||
| 19 | + var ( | ||
| 20 | + err error | ||
| 21 | + m = &models.SysCompanyApp{} | ||
| 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 *SysCompanyAppRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.SysCompanyApp) (*domain.SysCompanyApp, error) { | ||
| 36 | + var ( | ||
| 37 | + err error | ||
| 38 | + m *models.SysCompanyApp | ||
| 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 *SysCompanyAppRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.SysCompanyApp) (*domain.SysCompanyApp, error) { | ||
| 55 | + var ( | ||
| 56 | + err error | ||
| 57 | + m *models.SysCompanyApp | ||
| 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 *SysCompanyAppRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.SysCompanyApp) (*domain.SysCompanyApp, error) { | ||
| 79 | + var ( | ||
| 80 | + tx = conn.DB() | ||
| 81 | + m = &models.SysCompanyApp{Id: dm.Id} | ||
| 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 *SysCompanyAppRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.SysCompanyApp, error) { | ||
| 94 | + var ( | ||
| 95 | + err error | ||
| 96 | + tx = conn.DB() | ||
| 97 | + m = new(models.SysCompanyApp) | ||
| 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.SysCompanyApp) | ||
| 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 *SysCompanyAppRepository) FindOneUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*domain.SysCompanyApp, error) { | ||
| 115 | + var ( | ||
| 116 | + err error | ||
| 117 | + tx = conn.DB() | ||
| 118 | + m = new(models.SysCompanyApp) | ||
| 119 | + ) | ||
| 120 | + queryFunc := func() (interface{}, error) { | ||
| 121 | + tx = tx.Model(m).Unscoped().Where("id = ?", id).First(m) | ||
| 122 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
| 123 | + return nil, domain.ErrNotFound | ||
| 124 | + } | ||
| 125 | + return m, tx.Error | ||
| 126 | + } | ||
| 127 | + cacheModel := new(models.SysCompanyApp) | ||
| 128 | + cacheModel.Id = id | ||
| 129 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
| 130 | + return nil, err | ||
| 131 | + } | ||
| 132 | + return repository.ModelToDomainModel(m) | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +func (repository *SysCompanyAppRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.SysCompanyApp, error) { | ||
| 136 | + var ( | ||
| 137 | + tx = conn.DB() | ||
| 138 | + ms []*models.SysCompanyApp | ||
| 139 | + dms = make([]*domain.SysCompanyApp, 0) | ||
| 140 | + total int64 | ||
| 141 | + ) | ||
| 142 | + queryFunc := func() (interface{}, error) { | ||
| 143 | + tx = tx.Model(&ms).Order("id desc") | ||
| 144 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
| 145 | + return dms, tx.Error | ||
| 146 | + } | ||
| 147 | + return dms, nil | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + if _, err := repository.Query(queryFunc); err != nil { | ||
| 151 | + return 0, nil, err | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + for _, item := range ms { | ||
| 155 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
| 156 | + return 0, dms, err | ||
| 157 | + } else { | ||
| 158 | + dms = append(dms, dm) | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | + return total, dms, nil | ||
| 162 | +} | ||
| 163 | + | ||
| 164 | +func (repository *SysCompanyAppRepository) ModelToDomainModel(from *models.SysCompanyApp) (*domain.SysCompanyApp, error) { | ||
| 165 | + to := &domain.SysCompanyApp{} | ||
| 166 | + err := copier.Copy(to, from) | ||
| 167 | + return to, err | ||
| 168 | +} | ||
| 169 | + | ||
| 170 | +func (repository *SysCompanyAppRepository) DomainModelToModel(from *domain.SysCompanyApp) (*models.SysCompanyApp, error) { | ||
| 171 | + to := &models.SysCompanyApp{} | ||
| 172 | + err := copier.Copy(to, from) | ||
| 173 | + return to, err | ||
| 174 | +} | ||
| 175 | + | ||
| 176 | +func NewSysCompanyAppRepository(cache *cache.CachedRepository) domain.SysCompanyAppRepository { | ||
| 177 | + return &SysCompanyAppRepository{CachedRepository: cache} | ||
| 178 | +} |
| @@ -42,6 +42,14 @@ func (options QueryOptions) WithKV(key string, value interface{}) QueryOptions { | @@ -42,6 +42,14 @@ func (options QueryOptions) WithKV(key string, value interface{}) QueryOptions { | ||
| 42 | return options | 42 | return options |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | +func (options QueryOptions) LikeKV(key string, value interface{}) QueryOptions { | ||
| 46 | + if isEmptyOrZeroValue(value) { | ||
| 47 | + return options | ||
| 48 | + } | ||
| 49 | + options[key] = fmt.Sprintf("%%%v%%", value) | ||
| 50 | + return options | ||
| 51 | +} | ||
| 52 | + | ||
| 45 | func isEmptyOrZeroValue(i interface{}) bool { | 53 | func isEmptyOrZeroValue(i interface{}) bool { |
| 46 | if i == nil { | 54 | if i == nil { |
| 47 | return true // 如果接口为空,返回true | 55 | return true // 如果接口为空,返回true |
| @@ -8,16 +8,17 @@ import ( | @@ -8,16 +8,17 @@ import ( | ||
| 8 | type SysApp struct { | 8 | type SysApp struct { |
| 9 | Id int64 `json:",omitempty"` // 唯一标识 | 9 | Id int64 `json:",omitempty"` // 唯一标识 |
| 10 | Code string `json:",omitempty"` // 应用编码 | 10 | Code string `json:",omitempty"` // 应用编码 |
| 11 | - CompanyId int64 `json:",omitempty"` // 公司表ID | ||
| 12 | Name string `json:",omitempty"` // 应用名称 | 11 | Name string `json:",omitempty"` // 应用名称 |
| 13 | Logo string `json:",omitempty"` // 图标 | 12 | Logo string `json:",omitempty"` // 图标 |
| 14 | Description string `json:",omitempty"` // 描述 | 13 | Description string `json:",omitempty"` // 描述 |
| 14 | + Type string `json:",omitempty"` // 分类 default | ||
| 15 | + VersionNumber string `json:",omitempty"` // 应用版本号 | ||
| 15 | Status int `json:",omitempty"` // 1:启用、2:停用 | 16 | Status int `json:",omitempty"` // 1:启用、2:停用 |
| 16 | - VisibleFlag int `json:",omitempty"` // 1:全员可见 2:部分可见 | ||
| 17 | - VisibleUsers []int64 `json:",omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表 | ||
| 18 | - VisibleGroups []int64 `json:",omitempty"` // 可见的用户组 所有用户:空 部分用户:用户ID列表 | ||
| 19 | - AppConfig AppConfig `json:",omitempty"` // 应用配置 | ||
| 20 | - Sort int `json:",omitempty"` // 排序 | 17 | + //VisibleFlag int `json:",omitempty"` // 1:全员可见 2:部分可见 |
| 18 | + //VisibleUsers []int64 `json:",omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表 | ||
| 19 | + //VisibleGroups []int64 `json:",omitempty"` // 可见的用户组 所有用户:空 部分用户:用户ID列表 | ||
| 20 | + //AppConfig AppConfig `json:",omitempty"` // 应用配置 | ||
| 21 | + //Sort int `json:",omitempty"` // 排序 | ||
| 21 | CreatedAt int64 `json:",omitempty"` | 22 | CreatedAt int64 `json:",omitempty"` |
| 22 | UpdatedAt int64 `json:",omitempty"` | 23 | UpdatedAt int64 `json:",omitempty"` |
| 23 | DeletedAt int64 `json:",omitempty"` | 24 | DeletedAt int64 `json:",omitempty"` |
| @@ -64,18 +65,22 @@ var DefaultApps = []SysApp{ | @@ -64,18 +65,22 @@ var DefaultApps = []SysApp{ | ||
| 64 | { | 65 | { |
| 65 | Code: "AI0001", | 66 | Code: "AI0001", |
| 66 | Name: "AI大模型应用", | 67 | Name: "AI大模型应用", |
| 67 | - Description: "素天下AI大模型应用", | ||
| 68 | - AppConfig: AppConfig{ | ||
| 69 | - AIConfig: &AIConfig{ | ||
| 70 | - XFSpark: XFSpark{ | ||
| 71 | - APPID: "4fd8694e", | ||
| 72 | - APISecret: "NTVkM2FjNzk2NzQ5MzBkNWMwYTUwNjAz", | ||
| 73 | - APIKey: "4a4081a20e9ba0fb1b9686ed93221989", | ||
| 74 | - }, | ||
| 75 | - ChatGPT: ChatGPT{ | ||
| 76 | - APIKey: "4a4081a20e9ba0fb1b9686ed93221989", | ||
| 77 | - }, | ||
| 78 | - }, | ||
| 79 | - }, | 68 | + Logo: "", |
| 69 | + Type: "default", | ||
| 70 | + Description: "高校检索文档信息,准确回答专业问题。", | ||
| 71 | + VersionNumber: "1.0.0", | ||
| 72 | + Status: 1, | ||
| 73 | + //AppConfig: AppConfig{ | ||
| 74 | + // AIConfig: &AIConfig{ | ||
| 75 | + // XFSpark: XFSpark{ | ||
| 76 | + // APPID: "4fd8694e", | ||
| 77 | + // APISecret: "NTVkM2FjNzk2NzQ5MzBkNWMwYTUwNjAz", | ||
| 78 | + // APIKey: "4a4081a20e9ba0fb1b9686ed93221989", | ||
| 79 | + // }, | ||
| 80 | + // ChatGPT: ChatGPT{ | ||
| 81 | + // APIKey: "4a4081a20e9ba0fb1b9686ed93221989", | ||
| 82 | + // }, | ||
| 83 | + // }, | ||
| 84 | + //}, | ||
| 80 | }, | 85 | }, |
| 81 | } | 86 | } |
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type SysCompanyApp struct { | ||
| 9 | + Id int64 // 唯一标识 | ||
| 10 | + CompanyId int64 `json:",omitempty"` // 公司表ID | ||
| 11 | + AppId int64 `json:",omitempty"` // 应用ID | ||
| 12 | + Status int `json:",omitempty"` // 1:启用、2:停用 | ||
| 13 | + VisibleFlag int `json:",omitempty"` // 1:全员可见 2:部分可见 | ||
| 14 | + VisibleUsers []int64 `json:",omitempty"` // 可见的用户 所有用户:空 部分用户:用户ID列表 | ||
| 15 | + VisibleGroups []int64 `json:",omitempty"` // 可见的用户组 所有用户:空 部分用户:用户ID列表 | ||
| 16 | + AppConfig AppConfig `json:",omitempty"` // 应用配置 | ||
| 17 | + Sort int `json:",omitempty"` // 排序 | ||
| 18 | + CreatedAt int64 `json:",omitempty"` | ||
| 19 | + UpdatedAt int64 `json:",omitempty"` | ||
| 20 | + DeletedAt int64 `json:",omitempty"` | ||
| 21 | + Version int `json:",omitempty"` | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +type SysCompanyAppRepository interface { | ||
| 25 | + Insert(ctx context.Context, conn transaction.Conn, dm *SysCompanyApp) (*SysCompanyApp, error) | ||
| 26 | + Update(ctx context.Context, conn transaction.Conn, dm *SysCompanyApp) (*SysCompanyApp, error) | ||
| 27 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *SysCompanyApp) (*SysCompanyApp, error) | ||
| 28 | + Delete(ctx context.Context, conn transaction.Conn, dm *SysCompanyApp) (*SysCompanyApp, error) | ||
| 29 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*SysCompanyApp, error) | ||
| 30 | + FindOneUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*SysCompanyApp, error) | ||
| 31 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*SysCompanyApp, error) | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +const ( | ||
| 35 | + VisibleAll = 1 // 全员可见 | ||
| 36 | + VisibleParts = 2 // 部分可见 | ||
| 37 | + Invisible = 3 // 都不可见 | ||
| 38 | +) |
| @@ -35,7 +35,7 @@ func ChatSpark(appid string, apiKey string, apiSecret string, question string, c | @@ -35,7 +35,7 @@ func ChatSpark(appid string, apiKey string, apiSecret string, question string, c | ||
| 35 | d := websocket.Dialer{ | 35 | d := websocket.Dialer{ |
| 36 | HandshakeTimeout: 5 * time.Second, | 36 | HandshakeTimeout: 5 * time.Second, |
| 37 | } | 37 | } |
| 38 | - conn, resp, err := d.Dial(assembleAuthUrl(hostChatDocumentUrl, apiKey, apiSecret), nil) | 38 | + conn, resp, err := d.Dial(assembleAuthUrl(hostChatUrl, apiKey, apiSecret), nil) |
| 39 | if err != nil { | 39 | if err != nil { |
| 40 | logx.Error(readResp(resp) + err.Error()) | 40 | logx.Error(readResp(resp) + err.Error()) |
| 41 | return | 41 | return |
| @@ -59,35 +59,29 @@ func ChatSpark(appid string, apiKey string, apiSecret string, question string, c | @@ -59,35 +59,29 @@ func ChatSpark(appid string, apiKey string, apiSecret string, question string, c | ||
| 59 | break | 59 | break |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | - var data map[string]interface{} | 62 | + var data SparkChatMessage |
| 63 | err = json.Unmarshal(msg, &data) | 63 | err = json.Unmarshal(msg, &data) |
| 64 | if err != nil { | 64 | if err != nil { |
| 65 | logx.Error("Error parsing JSON:", err) | 65 | logx.Error("Error parsing JSON:", err) |
| 66 | return | 66 | return |
| 67 | } | 67 | } |
| 68 | logx.Info(string(msg)) | 68 | logx.Info(string(msg)) |
| 69 | - //解析数据 | ||
| 70 | - payload := data["payload"].(map[string]interface{}) | ||
| 71 | - choices := payload["choices"].(map[string]interface{}) | ||
| 72 | - header := data["header"].(map[string]interface{}) | ||
| 73 | - code := header["code"].(float64) | ||
| 74 | - | ||
| 75 | - if code != 0 { | ||
| 76 | - logx.Error(data["payload"]) | 69 | + if data.Header.Code != 0 { |
| 70 | + logx.Error("ws error code ", data.Header.Code) | ||
| 77 | return | 71 | return |
| 78 | } | 72 | } |
| 79 | - status := choices["status"].(float64) | ||
| 80 | - //logx.Info("status:",status) | ||
| 81 | - text := choices["text"].([]interface{}) | ||
| 82 | - content := text[0].(map[string]interface{})["content"].(string) | 73 | + status := data.Payload.Choices.Status |
| 74 | + text := data.Payload.Choices.Text | ||
| 75 | + var content string | ||
| 76 | + if len(text) > 0 { | ||
| 77 | + content = text[0].Content | ||
| 83 | channel <- content | 78 | channel <- content |
| 79 | + } | ||
| 84 | if status != 2 { | 80 | if status != 2 { |
| 85 | answer += content | 81 | answer += content |
| 86 | } else { | 82 | } else { |
| 87 | answer += content | 83 | answer += content |
| 88 | - usage := payload["usage"].(map[string]interface{}) | ||
| 89 | - temp := usage["text"].(map[string]interface{}) | ||
| 90 | - totalTokens := temp["total_tokens"].(float64) | 84 | + totalTokens := data.Payload.Usage.Text.TotalTokens |
| 91 | logx.Infof("收到最终结果 total_tokens: %v answer:%v", totalTokens, answer) | 85 | logx.Infof("收到最终结果 total_tokens: %v answer:%v", totalTokens, answer) |
| 92 | conn.Close() | 86 | conn.Close() |
| 93 | break | 87 | break |
| @@ -96,6 +90,34 @@ func ChatSpark(appid string, apiKey string, apiSecret string, question string, c | @@ -96,6 +90,34 @@ func ChatSpark(appid string, apiKey string, apiSecret string, question string, c | ||
| 96 | return answer, nil | 90 | return answer, nil |
| 97 | } | 91 | } |
| 98 | 92 | ||
| 93 | +type SparkChatMessage struct { | ||
| 94 | + Header struct { | ||
| 95 | + Code int `json:"code"` | ||
| 96 | + Message string `json:"message"` | ||
| 97 | + Sid string `json:"sid"` | ||
| 98 | + Status int `json:"status"` | ||
| 99 | + } `json:"header"` | ||
| 100 | + Payload struct { | ||
| 101 | + Choices struct { | ||
| 102 | + Status int `json:"status"` | ||
| 103 | + Seq int `json:"seq"` | ||
| 104 | + Text []struct { | ||
| 105 | + Content string `json:"content"` | ||
| 106 | + Role string `json:"role"` | ||
| 107 | + Index int `json:"index"` | ||
| 108 | + } `json:"text"` | ||
| 109 | + } `json:"choices"` | ||
| 110 | + Usage struct { | ||
| 111 | + Text struct { | ||
| 112 | + QuestionTokens int `json:"question_tokens"` | ||
| 113 | + PromptTokens int `json:"prompt_tokens"` | ||
| 114 | + CompletionTokens int `json:"completion_tokens"` | ||
| 115 | + TotalTokens int `json:"total_tokens"` | ||
| 116 | + } `json:"text"` | ||
| 117 | + } `json:"usage"` | ||
| 118 | + } `json:"payload"` | ||
| 119 | +} | ||
| 120 | + | ||
| 99 | // 生成参数 | 121 | // 生成参数 |
| 100 | func genParams1(appid, question string) map[string]interface{} { // 根据实际情况修改返回的数据结构和字段名 | 122 | func genParams1(appid, question string) map[string]interface{} { // 根据实际情况修改返回的数据结构和字段名 |
| 101 | 123 |
-
请 注册 或 登录 后发表评论