-
Notifications
You must be signed in to change notification settings - Fork 66
/
integration.go
126 lines (96 loc) · 4.14 KB
/
integration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package repo
import (
v1 "github.com/aaronchen2k/deeptest/cmd/server/v1/domain"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
"github.com/aaronchen2k/deeptest/internal/server/modules/model"
"gorm.io/gorm"
)
type IntegrationRepo struct {
*BaseRepo `inject:""`
DB *gorm.DB `inject:""`
}
func (r *IntegrationRepo) GetProjectListWithRoleBySpace(tenantId consts.TenantId, spaceCode string) (res []v1.ProjectListWithRole, err error) {
err = r.GetDB(tenantId).Model(&model.Project{}).
Joins("LEFT JOIN biz_integration_project_space_rel rel ON biz_project.id=rel.project_id").
Select("biz_project.id, biz_project.name, biz_project.short_name").
Where("rel.space_code = ? AND not biz_project.deleted AND not biz_project.disabled", spaceCode).
Find(&res).Error
return
}
func (r *IntegrationRepo) DeleteBySpaceCode(tenantId consts.TenantId, spaceCode string) (err error) {
err = r.GetDB(tenantId).Model(&model.ProjectSpaceRel{}).
Where("space_code = ?", spaceCode).
Delete(&model.ProjectSpaceRel{}).Error
return
}
func (r *IntegrationRepo) DeleteSpaceByProject(tenantId consts.TenantId, projectId uint) (err error) {
err = r.GetDB(tenantId).Model(&model.ProjectSpaceRel{}).
Where("project_id = ?", projectId).
Delete(&model.ProjectSpaceRel{}).Error
return
}
func (r *IntegrationRepo) BatchCreateProjectSpaceRel(tenantId consts.TenantId, relations []model.ProjectSpaceRel) (err error) {
err = r.GetDB(tenantId).Model(&model.ProjectSpaceRel{}).Create(&relations).Error
return
}
func (r *IntegrationRepo) DeleteProductByProject(tenantId consts.TenantId, projectId uint) (err error) {
err = r.GetDB(tenantId).Model(&model.ProjectProductRel{}).
Where("project_id = ?", projectId).
Delete(&model.ProjectProductRel{}).Error
return
}
func (r *IntegrationRepo) BatchCreateProjectProductRel(tenantId consts.TenantId, relations []model.ProjectProductRel) (err error) {
err = r.GetDB(tenantId).Model(&model.ProjectProductRel{}).Create(&relations).Error
return
}
func (r *IntegrationRepo) GetAllProductIds(tenantId consts.TenantId) (res []uint, err error) {
err = r.GetDB(tenantId).Model(&model.ProjectProductRel{}).
Select("distinct product_id").
Where("NOT deleted AND NOT disabled").
Find(&res).Error
return
}
func (r *IntegrationRepo) GetAllProjectProductRels(tenantId consts.TenantId) (res []model.ProjectProductRel, err error) {
err = r.GetDB(tenantId).Model(&model.ProjectProductRel{}).
Where("NOT deleted AND NOT disabled").
Find(&res).Error
return
}
func (r *IntegrationRepo) GetProductsByProject(tenantId consts.TenantId, projectId uint) (res []uint, err error) {
err = r.GetDB(tenantId).Model(&model.ProjectProductRel{}).
Select("product_id").
Where("project_id = ? AND NOT deleted AND NOT disabled", projectId).
Find(&res).Error
return
}
func (r *IntegrationRepo) GetSpacesByProject(tenantId consts.TenantId, projectId uint) (res []string, err error) {
err = r.GetDB(tenantId).Model(&model.ProjectSpaceRel{}).
Select("space_code").
Where("project_id = ? AND NOT deleted AND NOT disabled", projectId).
Find(&res).Error
return
}
func (r *IntegrationRepo) DeleteEngineeringByProject(tenantId consts.TenantId, projectId uint) (err error) {
err = r.GetDB(tenantId).Model(&model.ProjectEngineeringRel{}).
Where("project_id = ?", projectId).
Delete(&model.ProjectEngineeringRel{}).Error
return
}
func (r *IntegrationRepo) BatchCreateProjectEngineeringRel(tenantId consts.TenantId, relations []model.ProjectEngineeringRel) (err error) {
err = r.GetDB(tenantId).Model(&model.ProjectEngineeringRel{}).Create(&relations).Error
return
}
func (r *IntegrationRepo) GetEngineeringByProject(tenantId consts.TenantId, projectId uint) (res []string, err error) {
err = r.GetDB(tenantId).Model(&model.ProjectEngineeringRel{}).
Select("code").
Where("project_id = ? AND NOT deleted AND NOT disabled", projectId).
Find(&res).Error
return
}
func (r *IntegrationRepo) GetProjectByEngineering(tenantId consts.TenantId, engineering string) (res []uint, err error) {
err = r.GetDB(tenantId).Model(&model.ProjectEngineeringRel{}).
Select("project_id").
Where("code = ? AND NOT deleted AND NOT disabled", engineering).
Find(&res).Error
return
}