正在显示
1 个修改的文件
包含
32 行增加
和
14 行删除
@@ -73,7 +73,7 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | @@ -73,7 +73,7 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | ||
73 | //查看所有公开的 | 73 | //查看所有公开的 |
74 | sql6 string = fmt.Sprintf(`SELECT id FROM chance WHERE review_status =3 AND enable_status=1 And company_id=%d `, companyid) | 74 | sql6 string = fmt.Sprintf(`SELECT id FROM chance WHERE review_status =3 AND enable_status=1 And company_id=%d `, companyid) |
75 | //获取指定部门未通过的 | 75 | //获取指定部门未通过的 |
76 | - sql7 string = "SELECT id FROM chance WHERE department_id IN (%s) and review_status =2 AND enable_status=1" | 76 | + sql7 string = "SELECT id FROM chance WHERE department_id IN (%s) and (review_status=2 Or review_status =1) AND enable_status=1" |
77 | 77 | ||
78 | allsql string = ` SELECT t.id FROM (%s) as t ` | 78 | allsql string = ` SELECT t.id FROM (%s) as t ` |
79 | unionsql string = `` | 79 | unionsql string = `` |
@@ -90,26 +90,42 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | @@ -90,26 +90,42 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | ||
90 | usrPermission *serverabc.OptionOpportunity | 90 | usrPermission *serverabc.OptionOpportunity |
91 | ok bool | 91 | ok bool |
92 | //预设仅可以查看自己 | 92 | //预设仅可以查看自己 |
93 | - sqlslice = []string{sql1, sql2} | 93 | + sqlmap = map[string]bool{ |
94 | + sql1: true, sql2: true, | ||
95 | + } | ||
96 | + // sqlslice = []string{sql1, sql2} | ||
94 | ) | 97 | ) |
98 | + unionSqlMap := func(m map[string]bool) string { | ||
99 | + var s strings.Builder | ||
100 | + for k := range m { | ||
101 | + if s.Len() == 0 { | ||
102 | + s.WriteString(k) | ||
103 | + } else { | ||
104 | + s.WriteString(" UNION " + k) | ||
105 | + } | ||
106 | + } | ||
107 | + return s.String() | ||
108 | + } | ||
95 | if usrPermission, ok = permissionObject.(*serverabc.OptionOpportunity); !ok { | 109 | if usrPermission, ok = permissionObject.(*serverabc.OptionOpportunity); !ok { |
96 | log.Error("*serverabc.OptionOpportunity断言失败") | 110 | log.Error("*serverabc.OptionOpportunity断言失败") |
97 | - unionsql = sql1 + " UNION " + sql2 | 111 | + unionsql = unionSqlMap(sqlmap) |
98 | return fmt.Sprintf(allsql, unionsql) | 112 | return fmt.Sprintf(allsql, unionsql) |
99 | } | 113 | } |
100 | log.Debug("获取到的权限规则,check:%+v,option:%+v", usrPermission.CheckMap, usrPermission.CheckOption) | 114 | log.Debug("获取到的权限规则,check:%+v,option:%+v", usrPermission.CheckMap, usrPermission.CheckOption) |
101 | if len(usrPermission.CheckMap) == 1 { | 115 | if len(usrPermission.CheckMap) == 1 { |
102 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv1]; ok { | 116 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv1]; ok { |
103 | log.Debug("命中规则:仅查看自己") | 117 | log.Debug("命中规则:仅查看自己") |
104 | - return strings.Join(sqlslice, " UNION ") | 118 | + unionsql = unionSqlMap(sqlmap) |
119 | + return fmt.Sprintf(allsql, unionsql) | ||
105 | } | 120 | } |
106 | } | 121 | } |
107 | //进行权限判定 | 122 | //进行权限判定 |
108 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv4]; ok { | 123 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv4]; ok { |
109 | //查看所有 | 124 | //查看所有 |
110 | log.Debug("命中规则:查看所有") | 125 | log.Debug("命中规则:查看所有") |
111 | - sqlslice = append(sqlslice, sql6) | ||
112 | - return strings.Join(sqlslice, " UNION ") | 126 | + sqlmap[sql6] = true |
127 | + unionsql = unionSqlMap(sqlmap) | ||
128 | + return fmt.Sprintf(allsql, unionsql) | ||
113 | } | 129 | } |
114 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv3]; ok { | 130 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv3]; ok { |
115 | //指定部门 | 131 | //指定部门 |
@@ -119,7 +135,9 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | @@ -119,7 +135,9 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | ||
119 | } | 135 | } |
120 | if len(ids) > 0 { | 136 | if len(ids) > 0 { |
121 | log.Debug("命中规则:指定部门") | 137 | log.Debug("命中规则:指定部门") |
122 | - sqlslice = append(sqlslice, fmt.Sprintf(sql4, strings.Join(ids, ","))) | 138 | + sql4 = fmt.Sprintf(sql4, strings.Join(ids, ",")) |
139 | + sqlmap[sql4] = true | ||
140 | + sqlmap[sql5] = true | ||
123 | } | 141 | } |
124 | } | 142 | } |
125 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv2]; ok { | 143 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv2]; ok { |
@@ -131,7 +149,9 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | @@ -131,7 +149,9 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | ||
131 | utils.ExecuteQueryAll(&ids, sql6, usercompanyid) | 149 | utils.ExecuteQueryAll(&ids, sql6, usercompanyid) |
132 | if len(ids) > 0 { | 150 | if len(ids) > 0 { |
133 | log.Error("命中规则:公开到我的部门") | 151 | log.Error("命中规则:公开到我的部门") |
134 | - sqlslice = append(sqlslice, fmt.Sprintf(sql3, strings.Join(ids, ","))) | 152 | + sql3 = fmt.Sprintf(sql3, strings.Join(ids, ",")) |
153 | + sqlmap[sql3] = true | ||
154 | + sqlmap[sql5] = true | ||
135 | } | 155 | } |
136 | } | 156 | } |
137 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv5]; ok { | 157 | if _, ok := usrPermission.CheckMap[serverabc.OpportunityCheckLv5]; ok { |
@@ -142,14 +162,12 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | @@ -142,14 +162,12 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st | ||
142 | } | 162 | } |
143 | if len(ids) > 0 { | 163 | if len(ids) > 0 { |
144 | log.Debug("命中规则:指定部门未通过") | 164 | log.Debug("命中规则:指定部门未通过") |
145 | - sqlslice = append(sqlslice, fmt.Sprintf(sql7, strings.Join(ids, ","))) | ||
146 | - } | 165 | + sql7 = fmt.Sprintf(sql7, strings.Join(ids, ",")) |
166 | + sqlmap[sql7] = true | ||
147 | } | 167 | } |
148 | - if len(usrPermission.CheckMap) > 0 { | ||
149 | - sqlslice = append(sqlslice, sql5) | ||
150 | } | 168 | } |
151 | - | ||
152 | - return fmt.Sprintf(allsql, strings.Join(sqlslice, " UNION ")) | 169 | + unionsql = unionSqlMap(sqlmap) |
170 | + return fmt.Sprintf(allsql, unionsql) | ||
153 | } | 171 | } |
154 | 172 | ||
155 | func GetAuditListSql(param protocol.RequestAuditList, companyid int64, userid int64, ucompanyid int64) (coutsql string, | 173 | func GetAuditListSql(param protocol.RequestAuditList, companyid int64, userid int64, ucompanyid int64) (coutsql string, |
-
请 注册 或 登录 后发表评论