Skip to content

Commit

Permalink
Merge pull request #286 from ArtisanCloud/dev/michaelhu
Browse files Browse the repository at this point in the history
Dev/michaelhu
  • Loading branch information
Matrix-X authored Oct 9, 2024
2 parents be5588b + a57a94f commit d04004d
Show file tree
Hide file tree
Showing 145 changed files with 2,440 additions and 745 deletions.
2 changes: 1 addition & 1 deletion api/admin/department.api
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type (
type (
CreateDepartmentRequest {
DepName string `json:"depName"`
LeaderId int64 `json:"leaderId"`
LeaderUuid string `json:"leaderUuid"`
PId int64 `json:"pId"`
Desc string `json:"desc,optional"`
PhoneNumber string `json:"phoneNumber,optional"`
Expand Down
2 changes: 1 addition & 1 deletion api/admin/scrm/customer/weworkcustomer.api
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type (
UserId string `json:"userId"`
Remark string `json:"remark"`
Description string `json:"description"`
Createtime int `json:"createtime"`
CreatedTime int `json:"createtime"`
Tags []WechatCustomersFollowUserWithTags `json:"tags"`
TagIds []string `json:"tagIds"`
WechatChannels WechatCustomersFollowUserWithWechatChannels `json:"wechatChannels"`
Expand Down
2 changes: 1 addition & 1 deletion api/admin/scrm/qrcode/weworkcustomergroupqrcode.api
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ type (

ActionRequest {
Qid string `path:"qid"`// 唯一标识
SceneQrcodeLink string `json:"sceneQrcodeLink,optional"`
SceneQRCodeLink string `json:"sceneQrcodeLink,optional"`
}
)
16 changes: 8 additions & 8 deletions api/admin/user.api
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ service PowerX {

@doc "查询员工"
@handler GetUser
get /users/:id (GetUserRequest) returns (GetUserReply)
get /users/:uuid (GetUserRequest) returns (GetUserReply)

@doc "List员工"
@handler ListUsers
Expand All @@ -33,11 +33,11 @@ service PowerX {

@doc "编辑员工信息"
@handler UpdateUser
patch /users/:id (UpdateUserRequest) returns (UpdateUserReply)
patch /users/:uuid (UpdateUserRequest) returns (UpdateUserReply)

@doc "删除员工"
@handler DeleteUser
delete /users/:id (DeleteUserRequest) returns (DeleteUserReply)
delete /users/:uuid (DeleteUserRequest) returns (DeleteUserReply)

@doc "重设密码"
@handler ResetPassword
Expand All @@ -46,7 +46,7 @@ service PowerX {

type (
GetUserRequest {
Id int64 `path:"id"`
Uuid string `path:"uuid"`
}

GetUserReply {
Expand Down Expand Up @@ -136,7 +136,7 @@ type (

type (
UpdateUserRequest {
Id int64 `path:"id"`
Uuid string `path:"uuid"`
Name string `json:"name,optional"`
NickName string `json:"nickName,optional"`
Desc string `json:"desc,optional"`
Expand All @@ -159,17 +159,17 @@ type (

type (
DeleteUserRequest {
Id int64 `path:"id"`
Uuid string `path:"uuid"`
}

DeleteUserReply {
Id int64 `json:"id"`
Uuid string `json:"uuid"`
}
)

type (
ResetPasswordRequest {
UserId int64 `json:"userId"`
UserUuid string `json:"userUuid"`
}

ResetPasswordReply {
Expand Down
1 change: 1 addition & 0 deletions api/custom.api
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Custom APis
5 changes: 4 additions & 1 deletion api/openapi.api
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import "openapi/auth.api"
import "openapi/demo.api"
import "openapi/demo.api"

// provider
import "openapi/provider/brainx/demo.api"
40 changes: 40 additions & 0 deletions api/openapi/provider/brainx/demo.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "v1"

info(
title: "Provider Demo Open API of BrainX"
desc: "This is a api of Open API in Artisan Cloud"
author: "Matrix-X"
email: "[email protected]"
version: "v1"
)

@server(
group: openapi/provider/brainx
prefix: /openapi/v1/provider/brainx
middleware: OpenAPIJWTAuth
)

service PowerX {
@doc "hello world api for provider demo"
@handler HelloWorld
get /hello-world returns (HelloWorldResponse)

@doc "timeout api for provider demo"
@handler EchoLongTime
post /echo-long-time (EchoLongTimeRequest) returns (EchoLongTimeResponse)
}



type (
HelloWorldResponse {
Message string `json:"message"`
}

EchoLongTimeRequest {
Timeout int `json:"timeout"`
}
EchoLongTimeResponse {
Message string `json:"message"`
}
)
3 changes: 2 additions & 1 deletion api/powerx.api
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import "admin.wechat.offiaccount.api"
import "mp.api"
import "web.api"
import "openapi.api"
//import "custom.api"
import "pro.api"
import "custom.api"
import "plugin.api"
import "health.api"

Expand Down
1 change: 1 addition & 0 deletions api/pro.api
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Pro APis
7 changes: 7 additions & 0 deletions api/pro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Pro模块开发

## 项目模块

## 全渠道模块

## AI模块
40 changes: 40 additions & 0 deletions api/provider/brainx/demo.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "v1"

info(
title: "Provider Demo Open API of BrainX"
desc: "This is a api of Open API in Artisan Cloud"
author: "Matrix-X"
email: "[email protected]"
version: "v1"
)

@server(
group: openapi/provider/brainx
prefix: /openapi/v1/provider/brainx
middleware: OpenAPIJWTAuth
)

service PowerX {
@doc "hello world api for provider demo"
@handler HelloWorld
get /hello-world returns (HelloWorldResponse)

@doc "timeout api for provider demo"
@handler EchoLongTime
post /echo-long-time (EchoLongTimeRequest) returns (EchoLongTimeResponse)
}



type (
HelloWorldResponse {
Message string `json:"message"`
}

EchoLongTimeRequest {
Timeout int `json:"timeout"`
}
EchoLongTimeResponse {
Message string `json:"message"`
}
)
4 changes: 2 additions & 2 deletions api/web/scene/qrcode.api
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ info(
service PowerX {
@doc "获取场景落地页详情"
@handler DetailQrcode
get /qrcode/detail/:qid(SceneRequest) returns (SceneQrcodeActiveReply)
get /qrcode/detail/:qid(SceneRequest) returns (SceneQRCodeActiveReply)


}
Expand All @@ -27,7 +27,7 @@ type (
Status string `json:"status"`
}

SceneQrcodeActiveReply {
SceneQRCodeActiveReply {

QId string `json:"qid"` // 唯一码
Name string `json:"name"` // 活码名称
Expand Down
47 changes: 38 additions & 9 deletions cmd/ctl/database/migrate/powerx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migrate

import (
"PowerX/cmd/ctl/database/custom/migrate"
migratePro "PowerX/cmd/ctl/database/pro/migrate"
"PowerX/internal/config"
"PowerX/internal/model"
"PowerX/internal/model/crm/customerdomain"
Expand All @@ -11,15 +12,16 @@ import (
"PowerX/internal/model/crm/trade"
infoorganizatoin "PowerX/internal/model/infoorganization"
"PowerX/internal/model/media"
"PowerX/internal/model/origanzation"
"PowerX/internal/model/organization"
"PowerX/internal/model/permission"
"PowerX/internal/model/scene"
"PowerX/internal/model/scrm/app"
"PowerX/internal/model/scrm/customer"
"PowerX/internal/model/scrm/organization"
organization2 "PowerX/internal/model/scrm/organization"
"PowerX/internal/model/scrm/resource"
"PowerX/internal/model/scrm/tag"
"PowerX/internal/model/wechat"
"fmt"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
Expand Down Expand Up @@ -47,10 +49,34 @@ func NewPowerMigrator(conf *config.Config) (*PowerMigrator, error) {
}, err
}

func (m *PowerMigrator) InitSchema(schema string) error {
// 检查 schema 是否存在
var exists bool
query := `SELECT EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = ?);`
err := m.db.Raw(query, schema).Scan(&exists).Error
if err != nil {
return fmt.Errorf("failed to check schema existence: %w", err)
}

// 如果 schema 不存在,创建它
if !exists {
createSchemaQuery := fmt.Sprintf("CREATE SCHEMA %s;", schema)
err := m.db.Exec(createSchemaQuery).Error
if err != nil {
return fmt.Errorf("failed to create schema: %w", err)
}
fmt.Printf("Schema %s created successfully.\n", schema)
} else {
fmt.Printf("Schema %s already exists.\n", schema)
}

return nil
}

func (m *PowerMigrator) AutoMigrate() {

_ = m.db.AutoMigrate(&model.DataDictionaryType{}, &model.DataDictionaryItem{}, &model.PivotDataDictionaryToObject{})
_ = m.db.AutoMigrate(&origanzation.Department{}, &origanzation.User{}, &origanzation.Position{})
_ = m.db.AutoMigrate(&organization.Department{}, &organization.User{}, &organization.Position{})
_ = m.db.AutoMigrate(&permission.UserCasbinPolicy{}, permission.AdminRole{}, permission.AdminRoleMenuName{}, permission.AdminAPI{})

// info organization
Expand All @@ -62,16 +88,16 @@ func (m *PowerMigrator) AutoMigrate() {
&customerdomain.Lead{}, &customerdomain.Contact{}, customerdomain.RegisterCode{},
&customerdomain.Customer{}, &operation.Membership{},
)
_ = m.db.AutoMigrate(&wechat.WechatOACustomer{}, &wechat.WechatMPCustomer{}, &wechat.WeWorkExternalContact{})
_ = m.db.AutoMigrate(&wechat.WechatOACustomer{}, &wechat.WechatMPCustomer{})
_ = m.db.AutoMigrate(
&product.PivotProductToProductCategory{},
)
// product
_ = m.db.AutoMigrate(&product.Product{}, &product.ProductCategory{})
_ = m.db.AutoMigrate(&product.ProductSpecific{}, &product.SpecificOption{}, &product.ProductStatistics{})
_ = m.db.AutoMigrate(&product.SKU{}, &product.PivotSkuToSpecificOption{})
_ = m.db.AutoMigrate(&product.PriceBook{}, &product.PriceBookEntry{}, &product.PriceConfig{})
_ = m.db.AutoMigrate(&market.Store{}, &product.Artisan{}, &product.PivotStoreToArtisan{})
_ = m.db.AutoMigrate(&product.PriceBookEntry{}, &product.PriceBook{}, &product.PriceConfig{})
_ = m.db.AutoMigrate(&product.PivotStoreToArtisan{}, &market.Store{}, &product.Artisan{})

// market
_ = m.db.AutoMigrate(&market.Media{})
Expand All @@ -92,19 +118,22 @@ func (m *PowerMigrator) AutoMigrate() {
trade.TokenReservation{}, trade.TokenTransaction{},
)

// pro
migratePro.AutoMigratePro(m.db)

// custom
migrate.AutoMigrateCustom(m.db)

// wechat organization
_ = m.db.AutoMigrate(&organization.WeWorkUser{}, &organization.WeWorkDepartment{})
_ = m.db.AutoMigrate(&organization2.WeWorkUser{}, &organization2.WeWorkDepartment{})
// wechat customer
_ = m.db.AutoMigrate(&customer.WeWorkExternalContacts{}, &customer.WeWorkExternalContactFollow{})
_ = m.db.AutoMigrate(&customer.WeWorkExternalContact{}, &customer.WeWorkExternalContactFollow{})
// wechat resource
_ = m.db.AutoMigrate(&resource.WeWorkResource{})
// wechat app
_ = m.db.AutoMigrate(&app.WeWorkAppGroup{})
// wechat tag
_ = m.db.AutoMigrate(&tag.WeWorkTag{}, &tag.WeWorkTagGroup{})
// qrcode
_ = m.db.AutoMigrate(&scene.SceneQrcode{})
_ = m.db.AutoMigrate(&scene.SceneQRCode{})
}
12 changes: 12 additions & 0 deletions cmd/ctl/database/pro/migrate/pro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package migrate

import (
"gorm.io/gorm"
)

func AutoMigratePro(db *gorm.DB) {
// migrate your pro models

_ = db.AutoMigrate()

}
17 changes: 17 additions & 0 deletions cmd/ctl/database/pro/seed/datadictionary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seed

import (
"PowerX/internal/model"
"PowerX/internal/uc/powerx"
"gorm.io/gorm"
)

var UseCaseDD *powerx.DataDictionaryUseCase

func ProDataDictionary(db *gorm.DB) (data []*model.DataDictionaryType) {

UseCaseDD = powerx.NewDataDictionaryUseCase(db)

return data

}
9 changes: 9 additions & 0 deletions cmd/ctl/database/pro/seed/pro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package seed

import (
"gorm.io/gorm"
)

func CreateProSeeds(db *gorm.DB) {

}
8 changes: 5 additions & 3 deletions cmd/ctl/database/seed/datadictionary/datadictionary.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package datadictionary

import (
"PowerX/cmd/ctl/database/custom/seed"
seedCustom "PowerX/cmd/ctl/database/custom/seed"
seedPro "PowerX/cmd/ctl/database/pro/seed"
"PowerX/internal/model"
"PowerX/internal/uc/powerx"
"PowerX/pkg/slicex"
Expand All @@ -20,8 +21,9 @@ func CreateDataDictionaries(db *gorm.DB) (err error) {

UseCaseDD = powerx.NewDataDictionaryUseCase(db)
data := DefaultDataDictionary()
customData := seed.CustomDataDictionary(db)
data = slicex.Concatenate(data, customData)
proData := seedPro.ProDataDictionary(db)
customData := seedCustom.CustomDataDictionary(db)
data = slicex.Concatenate(data, proData, customData)

if count == 0 {
if err = db.Model(&model.DataDictionaryType{}).Create(data).Error; err != nil {
Expand Down
Loading

0 comments on commit d04004d

Please sign in to comment.