瀏覽代碼

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

baoziqiang 4 月之前
父節點
當前提交
57ccad9d26
共有 2 個文件被更改,包括 37 次插入2 次删除
  1. 2 2
      controllers/ppt_report.go
  2. 35 0
      models/ppt_v2.go

+ 2 - 2
controllers/ppt_report.go

@@ -268,13 +268,13 @@ func (this *PptV2Controller) ReportList() {
 	}
 
 	pptOb := new(models.PptV2)
-	total, e := pptOb.GetCountByCondition(cond, pars)
+	total, e := pptOb.GetCountByConditionWithAdminId(cond, pars, this.SysUser.AdminId)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = fmt.Sprintf("获取PPT总数失败, %v", e)
 		return
 	}
-	list, e := pptOb.GetPageItemsByCondition(cond, pars, models.PptReportQueryFields, "modify_time DESC", startSize, pageSize)
+	list, e := pptOb.GetPageItemsByConditionWithAdminId(cond, pars, models.PptReportQueryFields, "modify_time DESC", this.SysUser.AdminId, startSize, pageSize)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = fmt.Sprintf("获取PPT失败, %v", e)

+ 35 - 0
models/ppt_v2.go

@@ -360,12 +360,47 @@ func (m *PptV2) GetPageItemsByCondition(condition string, pars []interface{}, fi
 	return
 }
 
+func (m *PptV2) GetPageItemsByConditionWithAdminId(condition string, pars []interface{}, fieldArr []string, orderRule string, adminId, startSize, pageSize int) (items []*PptV2, err error) {
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`
+	SELECT %s FROM %s WHERE 1=1 AND classify_id NOT IN (
+		SELECT DISTINCT "classify_id" FROM "classify_visible") %s
+	UNION ALL
+	SELECT %s FROM %s WHERE 1=1 AND classify_id IN (
+		SELECT DISTINCT "classify_id" FROM "classify_visible" WHERE "admin_id" = %d) %s %s LIMIT ?,? `, fields, m.TableName(), condition, fields, m.TableName(), adminId, condition, order)
+	pars = append(pars, pars...)
+	pars = append(pars, startSize, pageSize)
+	err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
+	return
+}
+
 func (m *PptV2) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
 	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
 	return
 }
 
+func (m *PptV2) GetCountByConditionWithAdminId(condition string, pars []interface{}, adminId int) (count int, err error) {
+	sql := fmt.Sprintf(`
+	SELECT (
+		(SELECT COUNT(1) FROM %s WHERE 1=1 AND classify_id NOT IN (
+			SELECT DISTINCT "classify_id" FROM "classify_visible") %s)
+		+
+		(SELECT COUNT(1) FROM %s WHERE 1=1 AND classify_id IN (
+			SELECT DISTINCT "classify_id" FROM "classify_visible" WHERE "admin_id" = %d) %s)
+	) AS count `, m.TableName(), condition, m.TableName(), adminId, condition)
+	pars = append(pars, pars...)
+	err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
+	return
+}
+
 // PptReportQueryFields 除富文本的常用查询字段
 var PptReportQueryFields = []string{
 	"ppt_id", "title", "classify_id", "ppt_version", "pptx_url", "ppt_page", "title_setting", "state", "report_source", "publish_time", "submit_time", "approve_time", "create_time", "modify_time", "admin_id", "admin_real_name", "collaborate_type", "collaborate_users",