Browse Source

Merge branch 'bzq/306_report_classify_cf' of eta_gn_server/eta_api into debug

baoziqiang 4 months ago
parent
commit
4693c0bdf4

+ 44 - 6
controllers/classify.go

@@ -3,6 +3,8 @@ package controllers
 import (
 	"encoding/json"
 	"eta_gn/eta_api/models"
+	"eta_gn/eta_api/models/system"
+	"eta_gn/eta_api/models/system/response"
 	"eta_gn/eta_api/services"
 	"eta_gn/eta_api/utils"
 	"fmt"
@@ -585,12 +587,7 @@ func (this *ClassifyController) ListClassify() {
 	visibleUserMap := make(map[int][]int)
 
 	for _, v := range visibleUsers {
-		if m, ok := visibleUserMap[v.ClassifyId]; !ok {
-			visibleUserMap[v.ClassifyId] = make([]int, 0)
-			visibleUserMap[v.ClassifyId] = append(visibleUserMap[v.ClassifyId], v.AdminId)
-		} else {
-			visibleUserMap[v.ClassifyId] = append(m, v.AdminId)
-		}
+		visibleUserMap[v.ClassifyId] = append(visibleUserMap[v.ClassifyId], v.AdminId)
 	}
 
 	for i, v := range list {
@@ -623,6 +620,11 @@ func (this *ClassifyController) ListClassify() {
 			if !utils.InArrayByInt(classifyIds, v.Id) {
 				continue
 			}
+			if visible, ok := visibleUserMap[v.Id]; ok {
+				if !utils.InArrayByInt(visible, this.SysUser.AdminId) {
+					continue
+				}
+			}
 			list = append(list, v)
 		}
 	}
@@ -1010,3 +1012,39 @@ func (this *ClassifyController) ClassifyPermissionV2() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// AdminList
+// @Title 用户列表
+// @Description 用户列表
+// @Success 200 {object} company.PermissionSetResp
+// @router /user/list [get]
+func (this *ClassifyController) AdminList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	adminList, err := system.GetSysAdminListAll()
+	if err != nil {
+		br.Msg = "获取管理员列表失败"
+		br.ErrMsg = "获取管理员列表失败, Err: " + err.Error()
+	}
+
+	list := make([]*response.AdminItem, 0)
+	for _, v := range adminList {
+		item := new(response.AdminItem)
+		item.AdminId = v.AdminId
+		item.AdminName = v.AdminName
+		item.RealName = v.RealName
+		list = append(list, item)
+	}
+
+	resp := new(response.AdminListResp)
+	resp.List = list
+
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 18 - 2
controllers/ppt_report.go

@@ -7,10 +7,11 @@ import (
 	"eta_gn/eta_api/services"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"strconv"
 	"strings"
 	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
 // ReportClassify
@@ -98,8 +99,18 @@ func (this *PptV2Controller) ReportClassify() {
 		classifyPpt[v.ClassifyId] = append(classifyPpt[v.ClassifyId], t)
 	}
 
-	resp := make([]*models.PptReportClassifyItem, 0)
+	visibleUsers, err := models.GetClassifyVisibleAll()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = fmt.Sprintf("获取可见用户失败, err: %s", err.Error())
+		return
+	}
+	visibleUsersMap := make(map[int][]int)
+	for _, v := range visibleUsers {
+		visibleUsersMap[v.ClassifyId] = append(visibleUsersMap[v.ClassifyId], v.AdminId)
+	}
 
+	var resp []*models.PptReportClassifyItem
 	// 获取分类
 	classifies := make([]*models.Classify, 0)
 	{
@@ -145,6 +156,11 @@ func (this *PptV2Controller) ReportClassify() {
 			if !utils.InArrayByInt(classifyIds, v.Id) {
 				continue
 			}
+			if visible, ok := visibleUsersMap[v.Id]; ok {
+				if !utils.InArrayByInt(visible, sysUser.AdminId) {
+					continue
+				}
+			}
 			classifies = append(classifies, v)
 		}
 	}

+ 1 - 1
controllers/report_v2.go

@@ -79,7 +79,7 @@ func (this *ReportController) ListReport() {
 
 	var condition string
 	var pars []interface{}
-
+	pars = append(pars, this.SysUser.AdminId, this.SysUser.AdminId, this.SysUser.AdminId)
 	if keyWord != "" {
 		condition += ` AND (a.title LIKE ? OR a.admin_real_name LIKE ? ) `
 		pars = utils.GetLikeKeywordPars(pars, keyWord, 2)

+ 80 - 4
models/report.go

@@ -174,7 +174,26 @@ type ReportListResp struct {
 // @return count int
 // @return err error
 func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
-	sql := `SELECT COUNT(1) AS count  FROM report as a WHERE 1=1 `
+	sql := `SELECT COUNT(1) AS count  FROM report as a
+	LEFT JOIN classify_visible c ON (
+		CASE
+			WHEN a.classify_id_third > 0 THEN a.classify_id_third
+			WHEN a.classify_id_second > 0 THEN a.classify_id_second
+			ELSE a.classify_id_first
+		END 
+	) = c.classify_id AND c.admin_id =? 
+	WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
+		SELECT id FROM report ta
+		JOIN classify_visible tb ON (
+			CASE
+				WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
+				WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
+				ELSE ta.classify_id_first
+			END 
+		) = tb.classify_id
+		GROUP BY ta."id"
+		HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
+	) `
 	if condition != "" {
 		sql += condition
 	}
@@ -193,7 +212,26 @@ func GetReportListCountV1(condition string, pars []interface{}) (count int, err
 // @return items []*ReportList
 // @return err error
 func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
-	sql := `SELECT * FROM report as a WHERE 1=1  `
+	sql := `SELECT * FROM report as a 
+	LEFT JOIN classify_visible c ON (
+		CASE
+			WHEN a.classify_id_third > 0 THEN a.classify_id_third
+			WHEN a.classify_id_second > 0 THEN a.classify_id_second
+			ELSE a.classify_id_first
+		END 
+	) = c.classify_id AND c.admin_id =? 
+	WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
+		SELECT id FROM report ta
+		JOIN classify_visible tb ON (
+			CASE
+				WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
+				WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
+				ELSE ta.classify_id_first
+			END 
+		) = tb.classify_id
+		GROUP BY ta."id"
+		HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
+	) `
 	if condition != "" {
 		sql += condition
 	}
@@ -232,13 +270,32 @@ func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err er
 func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
 	sql := `SELECT a.id  FROM report as a 
     JOIN report_grant b on a.id=b.report_id 
- WHERE 1=1  `
+	LEFT JOIN classify_visible c ON (
+		CASE
+			WHEN a.classify_id_third > 0 THEN a.classify_id_third
+			WHEN a.classify_id_second > 0 THEN a.classify_id_second
+			ELSE a.classify_id_first
+		END 
+	) = c.classify_id AND c.admin_id =? 
+	WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
+		SELECT id FROM report ta
+		JOIN classify_visible tb ON (
+			CASE
+				WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
+				WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
+				ELSE ta.classify_id_first
+			END 
+		) = tb.classify_id
+		GROUP BY ta."id"
+		HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
+	) `
 	if condition != "" {
 		sql += condition
 	}
 	sql += " GROUP BY a.id "
 
 	sql = `SELECT COUNT(1) AS count  FROM (` + sql + `) d`
+
 	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
 	return
 }
@@ -254,7 +311,26 @@ func GetReportListCountByGrant(condition string, pars []interface{}) (count int,
 // @return items []*ReportList
 // @return err error
 func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
-	sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source FROM report as a JOIN report_grant b on a.id = b.report_id  WHERE 1=1  `
+	sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type,a.report_source FROM report as a JOIN report_grant b on a.id = b.report_id 
+	LEFT JOIN classify_visible c ON (
+		CASE
+			WHEN a.classify_id_third > 0 THEN a.classify_id_third
+			WHEN a.classify_id_second > 0 THEN a.classify_id_second
+			ELSE a.classify_id_first
+		END 
+	) = c.classify_id AND c.admin_id =? 
+	WHERE 1=1 AND (c.admin_id IS NULL OR c.admin_id =?) AND a.id NOT IN (
+		SELECT id FROM report ta
+		JOIN classify_visible tb ON (
+			CASE
+				WHEN ta.classify_id_third > 0 THEN ta.classify_id_third
+				WHEN ta.classify_id_second > 0 THEN ta.classify_id_second
+				ELSE ta.classify_id_first
+			END 
+		) = tb.classify_id
+		GROUP BY ta."id"
+		HAVING SUM(CASE WHEN tb.admin_id = ? THEN 1 ELSE 0 END) = 0
+	) `
 	if condition != "" {
 		sql += condition
 	}

+ 9 - 0
models/system/response/sys_role_admin.go

@@ -40,3 +40,12 @@ type EnglishAuthRoleDetailResp struct {
 	RoleTypeCode string `description:"角色类型编码"`
 	AuthOk       bool   `description:"是否有权限"`
 }
+
+type AdminListResp struct {
+	List []*AdminItem
+}
+type AdminItem struct {
+	AdminId   int
+	AdminName string `description:"系统用户名称"`
+	RealName  string `description:"系统用户姓名"`
+}

+ 7 - 0
models/system/sys_admin.go

@@ -354,3 +354,10 @@ func GetSysAdminList(condition string, pars []interface{}, fieldArr []string, or
 	err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
 	return
 }
+
+// GetSysAdminListAll 获取所有admin列表
+func GetSysAdminListAll() (items []*Admin, err error) {
+	sql := `SELECT admin_id, admin_name, real_name  FROM "admin" `
+	err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -6487,6 +6487,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers:ClassifyController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers:ClassifyController"],
+        beego.ControllerComments{
+            Method: "AdminList",
+            Router: `/user/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta_gn/eta_api/controllers:CompanyPermissionController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers:CompanyPermissionController"],
         beego.ControllerComments{
             Method: "List",