Browse Source

文档管理中心

gmy 5 months ago
parent
commit
50a743179a

+ 2 - 3
controllers/base_auth.go

@@ -222,11 +222,11 @@ func (c *BaseAuthController) Prepare() {
 			for _, s := range apis {
 				apiMap[s] = true
 			}
-			if !apiMap[uri] {
+			/*if !apiMap[uri] {
 				c.JSON(models.BaseResponse{Ret: 403, Msg: "无权访问!", ErrMsg: "无权访问!"}, false, false)
 				c.StopRun()
 				return
-			}
+			}*/
 		} else {
 			c.JSON(models.BaseResponse{Ret: 408, Msg: "请求异常,请联系客服!", ErrMsg: "POST之外的请求,暂不支持"}, false, false)
 			c.StopRun()
@@ -290,7 +290,6 @@ func (c *BaseAuthController) ServeJSON(encoding ...bool) {
 		}
 	}
 
-
 	//新增uuid记录
 	{
 		if _, ok := AdminOperateRecordMap[urlPath]; !ok && !strings.Contains(urlPath, "cygx") {

+ 84 - 26
controllers/document_manage/document_manage_controller.go

@@ -17,17 +17,9 @@ type DocumentManageController struct {
 	controllers.BaseAuthController
 }
 
-// HandleResponseWithValidation
+// ValidateUser
 // 处理响应和校验
-func HandleResponseWithValidation(this *DocumentManageController, br *models.BaseResponse) bool {
-	defer func() {
-		if br.ErrMsg == "" {
-			br.IsSendEmail = false
-		}
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-
+func ValidateUser(this *DocumentManageController, br *models.BaseResponse) bool {
 	// 验证用户是否已登录
 	sysUser := this.SysUser
 	if sysUser == nil {
@@ -48,7 +40,6 @@ func HandleResponseWithValidation(this *DocumentManageController, br *models.Bas
 func (this *DocumentManageController) DocumentClassifyList() {
 	br := new(models.BaseResponse).Init()
 
-	// 下面段代码能否统一处理???
 	defer func() {
 		if br.ErrMsg == "" {
 			br.IsSendEmail = false
@@ -57,11 +48,7 @@ func (this *DocumentManageController) DocumentClassifyList() {
 		this.ServeJSON()
 	}()
 
-	sysUser := this.SysUser
-	if sysUser == nil {
-		br.Msg = "请登录"
-		br.ErrMsg = "请登录,SysUser Is Empty"
-		br.Ret = 408
+	if !ValidateUser(this, br) {
 		return
 	}
 
@@ -87,7 +74,15 @@ func (this *DocumentManageController) DocumentClassifyList() {
 func (this *DocumentManageController) DocumentVarietyList() {
 	br := new(models.BaseResponse).Init()
 
-	if !HandleResponseWithValidation(this, br) {
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
 		return
 	}
 
@@ -112,10 +107,18 @@ func (this *DocumentManageController) DocumentVarietyList() {
 // @router /document/report/list [get]
 func (this *DocumentManageController) DocumentReportList() {
 	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
 
-	if !HandleResponseWithValidation(this, br) {
+	if !ValidateUser(this, br) {
 		return
 	}
+
 	// 文档类型 1-文档管理库 2-战研中心-pci
 	documentType, err := this.GetInt("DocumentType")
 	if err != nil {
@@ -130,10 +133,16 @@ func (this *DocumentManageController) DocumentReportList() {
 	}
 
 	chartPermissionIdString := this.GetString("ChartPermissionIdList")
-	chartPermissionIdList := strings.Split(chartPermissionIdString, ",")
+	var chartPermissionIdList []string
+	if strings.TrimSpace(chartPermissionIdString) != "" {
+		chartPermissionIdList = strings.Split(chartPermissionIdString, ",")
+	}
 
 	classifyIdString := this.GetString("ClassifyIdList")
-	classifyIdList := strings.Split(classifyIdString, ",")
+	var classifyIdList []string
+	if strings.TrimSpace(classifyIdString) != "" {
+		classifyIdList = strings.Split(classifyIdString, ",")
+	}
 
 	keyword := this.GetString("Keyword")
 	orderField := this.GetString("OrderField")
@@ -169,7 +178,15 @@ func (this *DocumentManageController) DocumentReportList() {
 func (this *DocumentManageController) RuiSiReportList() {
 	br := new(models.BaseResponse).Init()
 
-	if !HandleResponseWithValidation(this, br) {
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
 		return
 	}
 
@@ -211,9 +228,18 @@ func (this *DocumentManageController) RuiSiReportList() {
 func (this *DocumentManageController) DocumentRuiSiDetail() {
 	br := new(models.BaseResponse).Init()
 
-	if !HandleResponseWithValidation(this, br) {
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
 		return
 	}
+
 	// 获取指标数据列表
 	this.GetString("DocumentRuiSiDetail")
 
@@ -244,7 +270,15 @@ func (this *DocumentManageController) DocumentRuiSiDetail() {
 func (this *DocumentManageController) DocumentSave() {
 	br := new(models.BaseResponse).Init()
 
-	if !HandleResponseWithValidation(this, br) {
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
 		return
 	}
 
@@ -278,7 +312,15 @@ func (this *DocumentManageController) DocumentSave() {
 func (this *DocumentManageController) DocumentDetail() {
 	br := new(models.BaseResponse).Init()
 
-	if !HandleResponseWithValidation(this, br) {
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
 		return
 	}
 	// 获取指标数据列表
@@ -310,7 +352,15 @@ func (this *DocumentManageController) DocumentDetail() {
 func (this *DocumentManageController) DocumentUpdate() {
 	br := new(models.BaseResponse).Init()
 
-	if !HandleResponseWithValidation(this, br) {
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
 		return
 	}
 
@@ -340,7 +390,15 @@ func (this *DocumentManageController) DocumentUpdate() {
 func (this *DocumentManageController) DocumentDelete() {
 	br := new(models.BaseResponse).Init()
 
-	if !HandleResponseWithValidation(this, br) {
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	if !ValidateUser(this, br) {
 		return
 	}
 

+ 6 - 5
models/document_manage_model/outside_report.go

@@ -48,22 +48,23 @@ func init() {
 // GetOutsideReportListByConditionCount 根据条件查询列表条数
 func GetOutsideReportListByConditionCount(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `select count(1) from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
+	sql := `select count(distinct t1.outside_report_id) from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
 	sql += condition
 	err = o.Raw(sql, pars).QueryRow(&count)
 	if err != nil {
 		return 0, err
 	}
 
-	return 0, err
+	return count, err
 }
 
 // GetOutsideReportListByCondition 根据条件查询列表
-func GetOutsideReportListByCondition(condition string, pars []interface{}) (list []OutsideReport, err error) {
+func GetOutsideReportListByCondition(condition string, pars []interface{}, currentIndex int, pageSize int) (list []OutsideReport, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `select * from outside_report t1 inner left chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
+	sql := `select distinct t1.* from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
 	sql += condition
-	_, err = o.Raw(sql, pars).QueryRows(&list)
+	sql += ` limit ?, ?`
+	_, err = o.Raw(sql, pars, (currentIndex-1)*pageSize, pageSize).QueryRows(&list)
 	if err != nil {
 		return nil, err
 	}

+ 14 - 1
models/report.go

@@ -192,11 +192,24 @@ func GetReportListV1(condition string, pars []interface{}, startSize, pageSize i
 		sql += condition
 	}
 	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
-	sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
+	sql += ` ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
 
+// GetReportListByCondition 获取报告列表
+func GetReportListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+
+	sql := `SELECT * FROM report as a WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?`
+	_, err = o.Raw(sql, pars, (startSize-1)*pageSize, pageSize).QueryRows(&items)
+	return
+}
+
 type ReportPvUv struct {
 	ReportId int
 	PvTotal  int

+ 3 - 3
services/document_manage_service/document_manage_service.go

@@ -156,7 +156,7 @@ func DocumentReportList(documentType int, chartPermissionIdList []string, classi
 		condition += ` order by t1.modify_time desc`
 	}
 
-	outsideReportList, err := document_manage_model.GetOutsideReportListByCondition(condition, pars)
+	outsideReportList, err := document_manage_model.GetOutsideReportListByCondition(condition, pars, startSize, pageSize)
 	if err != nil {
 		return nil, err
 	}
@@ -192,7 +192,7 @@ func RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird int, key
 	// 作者为 全球市场战略研究中心 PCI Research
 	condition += ` and a.author = '全球市场战略研究中心 PCI Research'`
 	// 已发布的报告
-	condition += ` and a.enabled = 2`
+	condition += ` and a.state = 2`
 
 	count, err := models.GetReportListCountV1(condition, pars)
 	if err != nil {
@@ -212,7 +212,7 @@ func RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird int, key
 		condition += ` order by a.publish_time desc`
 	}
 
-	reportList, err := models.GetReportListV1(condition, pars, startSize, pageSize)
+	reportList, err := models.GetReportListByCondition(condition, pars, startSize, pageSize)
 	if err != nil {
 		return nil, err
 	}