|
@@ -6,6 +6,8 @@ import ( |
|
@@ -6,6 +6,8 @@ import ( |
6
|
"oppmg/common/log"
|
6
|
"oppmg/common/log"
|
7
|
"oppmg/models"
|
7
|
"oppmg/models"
|
8
|
"oppmg/protocol"
|
8
|
"oppmg/protocol"
|
|
|
9
|
+ serverabc "oppmg/services/rbac"
|
|
|
10
|
+ "oppmg/storage/redisdata"
|
9
|
"oppmg/utils"
|
11
|
"oppmg/utils"
|
10
|
"strings"
|
12
|
"strings"
|
11
|
"time"
|
13
|
"time"
|
|
@@ -26,6 +28,105 @@ type SqlData struct { |
|
@@ -26,6 +28,105 @@ type SqlData struct { |
26
|
Code string `orm:"column(code)"`
|
28
|
Code string `orm:"column(code)"`
|
27
|
}
|
29
|
}
|
28
|
|
30
|
|
|
|
31
|
+//根据权限获取机会列表
|
|
|
32
|
+func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) string {
|
|
|
33
|
+ /*
|
|
|
34
|
+ OpportunityCheckLv1 int = 1
|
|
|
35
|
+ OpportunityCheckLv2 int = 2
|
|
|
36
|
+ OpportunityCheckLv3 int = 3
|
|
|
37
|
+ OpportunityCheckLv4 int = 4
|
|
|
38
|
+ */
|
|
|
39
|
+ var (
|
|
|
40
|
+ //自己提交的
|
|
|
41
|
+ sql1 string = fmt.Sprintf(` SELECT id FROM chance WHERE user_id=%d `, usercompanyid)
|
|
|
42
|
+ //自己可审核的
|
|
|
43
|
+ sql2 string = fmt.Sprintf(` SELECT a.id FROM chance AS a
|
|
|
44
|
+ JOIN audit_flow_process AS b ON a.id=b.chance_id
|
|
|
45
|
+ WHERE b.uid=%d AND a.review_status = 3 `, usercompanyid)
|
|
|
46
|
+ //公开到自己部门的
|
|
|
47
|
+ sql3 string = ` SELECT a.id FROM chance AS a
|
|
|
48
|
+ JOIN chance_department AS b ON a.id=b.chance_id
|
|
|
49
|
+ WHERE b.department_id IN (%s) AND a.review_status = 3 `
|
|
|
50
|
+ //指定提交的部门
|
|
|
51
|
+ sql4 string = ` SELECT id FROM chance WHERE department_id IN (%s) and review_status =3 `
|
|
|
52
|
+ //全公司公开的
|
|
|
53
|
+ sql5 string = ` SELECT id FROM chance where publish_status = 1 AND review_status = 3 `
|
|
|
54
|
+
|
|
|
55
|
+ allsql string = ` SELECT t.id FROM (%s) as t `
|
|
|
56
|
+ unionsql string = ``
|
|
|
57
|
+ permissionObject serverabc.PermissionOptionObject
|
|
|
58
|
+ err error
|
|
|
59
|
+ )
|
|
|
60
|
+ //获取权限
|
|
|
61
|
+ if ok := redisdata.ExistUserPermission(userid); !ok {
|
|
|
62
|
+ //尝试重数据库获取
|
|
|
63
|
+ permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
|
|
|
64
|
+ if err != nil {
|
|
|
65
|
+ log.Debug("从数据库未获得对应权限 :%s", err)
|
|
|
66
|
+ unionsql = sql1 + " UNION " + sql2
|
|
|
67
|
+ return fmt.Sprintf(allsql, unionsql)
|
|
|
68
|
+ }
|
|
|
69
|
+ if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
|
|
|
70
|
+ unionsql = sql1 + " UNION " + sql2
|
|
|
71
|
+ return fmt.Sprintf(allsql, unionsql)
|
|
|
72
|
+ } else {
|
|
|
73
|
+ permissionObject = v
|
|
|
74
|
+ }
|
|
|
75
|
+ } else {
|
|
|
76
|
+ //使用缓存
|
|
|
77
|
+ permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
|
|
|
78
|
+ if err != nil {
|
|
|
79
|
+ log.Debug("从缓存未获得对应权限 :%s", err)
|
|
|
80
|
+ unionsql = sql1 + " UNION " + sql2
|
|
|
81
|
+ return fmt.Sprintf(allsql, unionsql)
|
|
|
82
|
+ }
|
|
|
83
|
+ }
|
|
|
84
|
+ var (
|
|
|
85
|
+ usrPermission *serverabc.OptionOpportunity
|
|
|
86
|
+ ok bool
|
|
|
87
|
+ //预设仅可以查看自己
|
|
|
88
|
+ sqlslice = []string{sql1, sql2}
|
|
|
89
|
+ )
|
|
|
90
|
+ if usrPermission, ok = permissionObject.(*serverabc.OptionOpportunity); !ok {
|
|
|
91
|
+ log.Error("*serverabc.OptionOpportunity断言失败")
|
|
|
92
|
+ unionsql = sql1 + " UNION " + sql2
|
|
|
93
|
+ return fmt.Sprintf(allsql, unionsql)
|
|
|
94
|
+ }
|
|
|
95
|
+ log.Debug("获取到的权限规则:%v", usrPermission)
|
|
|
96
|
+ //进行权限判定
|
|
|
97
|
+ if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv4]; ok {
|
|
|
98
|
+ //查看所有
|
|
|
99
|
+ log.Debug("命中规则:查看所有")
|
|
|
100
|
+ return ""
|
|
|
101
|
+ }
|
|
|
102
|
+ if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv3]; ok {
|
|
|
103
|
+ //指定部门
|
|
|
104
|
+ ids := []string{}
|
|
|
105
|
+ for _, v := range usrPermission.CheckOption.Departments {
|
|
|
106
|
+ ids = append(ids, fmt.Sprint(v.Id))
|
|
|
107
|
+ }
|
|
|
108
|
+ if len(ids) > 0 {
|
|
|
109
|
+ log.Debug("命中规则:指定部门")
|
|
|
110
|
+ sqlslice = append(sqlslice, fmt.Sprintf(sql4, strings.Join(ids, ",")))
|
|
|
111
|
+ }
|
|
|
112
|
+ }
|
|
|
113
|
+ if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv2]; ok {
|
|
|
114
|
+ //公开到我的部门
|
|
|
115
|
+ ids := []string{}
|
|
|
116
|
+ sql6 := `SELECT a.id FROM department AS a WHERE a.id IN (
|
|
|
117
|
+ SELECT department_id FROM user_department WHERE user_company_id = ? AND enable_status = 1
|
|
|
118
|
+ ) `
|
|
|
119
|
+ utils.ExecuteQueryAll(&ids, sql6, usercompanyid)
|
|
|
120
|
+ if len(ids) > 0 {
|
|
|
121
|
+ log.Error("命中规则:公开到我的部门")
|
|
|
122
|
+ sqlslice = append(sqlslice, fmt.Sprintf(sql3, strings.Join(ids, ",")))
|
|
|
123
|
+ }
|
|
|
124
|
+ }
|
|
|
125
|
+ //添加规则全公司公开
|
|
|
126
|
+ sqlslice = append(sqlslice, sql5)
|
|
|
127
|
+ return fmt.Sprintf(allsql, strings.Join(sqlslice, " UNION "))
|
|
|
128
|
+}
|
|
|
129
|
+
|
29
|
func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64) (protocol.ResponseAuditList, error) {
|
130
|
func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64) (protocol.ResponseAuditList, error) {
|
30
|
|
131
|
|
31
|
var (
|
132
|
var (
|
|
@@ -35,7 +136,9 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 |
|
@@ -35,7 +136,9 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 |
35
|
cnt int
|
136
|
cnt int
|
36
|
err error
|
137
|
err error
|
37
|
cond []interface{}
|
138
|
cond []interface{}
|
|
|
139
|
+ sqlFromPermission string
|
38
|
)
|
140
|
)
|
|
|
141
|
+
|
39
|
returnData := protocol.ResponseAuditList{
|
142
|
returnData := protocol.ResponseAuditList{
|
40
|
ResponsePageInfo: protocol.ResponsePageInfo{
|
143
|
ResponsePageInfo: protocol.ResponsePageInfo{
|
41
|
TotalPage: 0,
|
144
|
TotalPage: 0,
|
|
@@ -43,16 +146,32 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 |
|
@@ -43,16 +146,32 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 |
43
|
},
|
146
|
},
|
44
|
List: make([]protocol.RspAuditList, 0),
|
147
|
List: make([]protocol.RspAuditList, 0),
|
45
|
}
|
148
|
}
|
46
|
- datasql.WriteString(`SELECT a.id,a.user_id,a.department_id,a.audit_template_id,a.chance_type_id
|
149
|
+ usercompany, err := models.GetUserCompanyBy(userid, companyid)
|
|
|
150
|
+ if err != nil {
|
|
|
151
|
+ log.Error("GetUserCompanyBy(userid, companyid) err:%s", err)
|
|
|
152
|
+ return returnData, protocol.NewErrWithMessage("1")
|
|
|
153
|
+ }
|
|
|
154
|
+ sqlFromPermission = buildSqlForAuditList(usercompany.Id, usercompany.CompanyId, usercompany.UserId)
|
|
|
155
|
+ s1 := `SELECT a.id,a.user_id,a.department_id,a.audit_template_id,a.chance_type_id
|
47
|
,a.publish_status,a.create_at,a.review_status,a.enable_status
|
156
|
,a.publish_status,a.create_at,a.review_status,a.enable_status
|
48
|
,a.discovery_score,a.comment_total ,a.code,d.nick_name
|
157
|
,a.discovery_score,a.comment_total ,a.code,d.nick_name
|
49
|
FROM chance AS a
|
158
|
FROM chance AS a
|
50
|
JOIN user_company AS c ON c.id = a.user_id
|
159
|
JOIN user_company AS c ON c.id = a.user_id
|
51
|
JOIN user AS d ON c.user_id = d.id
|
160
|
JOIN user AS d ON c.user_id = d.id
|
52
|
- where a.company_id=? `)
|
|
|
53
|
-
|
|
|
54
|
- countsql.WriteString(`SELECT count(*) FROM chance as a
|
|
|
55
|
- where a.company_id=? `)
|
161
|
+ %s
|
|
|
162
|
+ where a.company_id=? `
|
|
|
163
|
+ s2 := ` SELECT count(*) FROM chance as a
|
|
|
164
|
+ JOIN user_company AS c ON c.id = a.user_id
|
|
|
165
|
+ JOIN user AS d ON c.user_id = d.id
|
|
|
166
|
+ %s
|
|
|
167
|
+ where a.company_id=?`
|
|
|
168
|
+ if len(sqlFromPermission) > 0 {
|
|
|
169
|
+ temp := fmt.Sprintf(`JOIN (%s) AS tt ON tt.id=a.id`, sqlFromPermission)
|
|
|
170
|
+ s1 = fmt.Sprintf(s1, temp)
|
|
|
171
|
+ s2 = fmt.Sprintf(s2, temp)
|
|
|
172
|
+ }
|
|
|
173
|
+ datasql.WriteString(s1)
|
|
|
174
|
+ countsql.WriteString(s2)
|
56
|
cond = append(cond, companyid)
|
175
|
cond = append(cond, companyid)
|
57
|
if param.ChanceTypeId > 0 {
|
176
|
if param.ChanceTypeId > 0 {
|
58
|
//一级分类过滤
|
177
|
//一级分类过滤
|