Sfoglia il codice sorgente

fix:调整统计图的接口

zqbao 9 mesi fa
parent
commit
05c33c29a6
3 ha cambiato i file con 69 aggiunte e 37 eliminazioni
  1. 50 27
      controllers/user_read_record.go
  2. 4 4
      models/user_read_record.go
  3. 15 6
      routers/commentsRouter.go

+ 50 - 27
controllers/user_read_record.go

@@ -269,51 +269,40 @@ func (this *UserReadRecordController) Detail() {
 	br.Ret = 200
 }
 
-// Info
-// @Title 用户阅读统计图信息
-// @Description 用户阅读统计图信息
+// ReadCntChart
+// @Title 用户阅读统计图信息
+// @Description 用户阅读统计图信息
 // @Param   ChartPermissionIds   query   string  true       "品种列表"
 // @Param   ClassifyIds   query   string  true       "品种列表"
 // @Param   StartDate   query   string  true       "开始时间"
 // @Param   EndDate   query   string  true       "结束时间"
-// @Param   KeyWord   query   string  true       "关键字"
+// @Param   UserId   query   int  true       "用户id"
 // @Success 200 {object} models.LoginResp
-// @router /chart/info [get]
-func (this *UserReadRecordController) Info() {
+// @router /readCntChart [get]
+func (this *UserReadRecordController) ReadCntChart() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+	userId, _ := this.GetInt("UserId")
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
 	chartPermissionIds := this.GetString("ChartPermissionIds")
 	classifyIds := this.GetString("ClassifyIds")
-	keyWord := this.GetString("KeyWord")
-
-	if startDate == "" {
-		startDate = time.Now().AddDate(-1, 0, 0).Format("2006-01-02")
-	}
-	if endDate == "" {
-		endDate = time.Now().AddDate(0, 0, 1).Format("2006-01-02")
-	}
 	var condition string
 	var pars []interface{}
 
-	if keyWord != "" {
-		condition += ` AND (real_name LIKE ? OR phone LIKE ? OR email LIKE ? OR company LIKE ?) `
-		pars = utils.GetLikeKeywordPars(pars, keyWord, 4)
-	}
 	if chartPermissionIds != "" {
 		ids := strings.Split(chartPermissionIds, ",")
 		if len(ids) != 0 {
 			condition += ` AND ( `
 			for i, id := range ids {
 				if i == 0 {
-					condition += ` urp2.chart_permission_id = ? `
+					condition += ` urp.chart_permission_id = ? `
 					pars = append(pars, id)
 				} else {
-					condition += ` OR urp2.chart_permission_id = ? `
+					condition += ` OR urp.chart_permission_id = ? `
 					pars = append(pars, id)
 				}
 			}
@@ -337,6 +326,16 @@ func (this *UserReadRecordController) Info() {
 		}
 	}
 
+	if startDate == "" {
+		startDate = time.Now().AddDate(-1, 0, 0).Format(utils.FormatDate)
+	}
+	if endDate == "" {
+		endDate = time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
+	}
+	if userId > 0 {
+		condition += ` AND ur.user_id = ? `
+		pars = append(pars, userId)
+	}
 	readCnts, err := models.GetStaticReadCnt(condition, pars, startDate, endDate)
 	if err != nil {
 		br.Msg = "获取阅读统计失败"
@@ -344,18 +343,42 @@ func (this *UserReadRecordController) Info() {
 		return
 	}
 
-	permissionCnts, err := models.GetStaticPermissionCnt(condition, pars, startDate, endDate)
+	br.Msg = "查询成功"
+	br.Data = readCnts
+	br.Ret = 200
+	br.Success = true
+}
+
+// readPermissionChart
+// @Title 用户阅读品种图信息
+// @Description 用户阅读品种图信息
+// @Param   UserId   query   string  true       "用户id"
+// @Success 200 {object} models.LoginResp
+// @router /readPermissionChart [get]
+func (this *UserReadRecordController) ReadPermissionChart() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	userId, _ := this.GetInt("UserId")
+
+	var condition string
+	var pars []interface{}
+	if userId > 0 {
+		condition += ` AND ur.user_id = ? `
+		pars = append(pars, userId)
+	}
+
+	permissionCnts, err := models.GetStaticPermissionCnt(condition, pars)
 	if err != nil {
 		br.Msg = "获取品种阅读统计失败"
 		br.ErrMsg = "获取品种阅读统计失败,系统错误,Err:" + err.Error()
 		return
 	}
-	resp := new(response.StaticInfoResp)
-	resp.PermissionCntList = permissionCnts
-	resp.ReadCntList = readCnts
 
-	br.Data = resp
-	br.Success = true
-	br.Msg = "获取成功"
+	br.Msg = "查询成功"
+	br.Data = permissionCnts
 	br.Ret = 200
+	br.Success = true
 }

+ 4 - 4
models/user_read_record.go

@@ -58,7 +58,7 @@ func GetStaticReadCnt(condition string, pars []interface{}, startDate, endDate s
 	FROM user_read_record AS ur
 	LEFT JOIN user_read_permission2 AS urp
 	ON ur.user_read_record_id = urp.user_read_record_id
-	WHERE 1=1 `
+	WHERE 1=1  `
 	if condition != "" {
 		sql += condition
 	}
@@ -67,7 +67,7 @@ func GetStaticReadCnt(condition string, pars []interface{}, startDate, endDate s
 	return
 }
 
-func GetStaticPermissionCnt(condition string, pars []interface{}, startDate, endDate string) (items []*PermissionCntStaitc, err error) {
+func GetStaticPermissionCnt(condition string, pars []interface{}) (items []*PermissionCntStaitc, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT urp.chart_permission_id, urp.permission_name,COUNT(*) AS count
 	FROM user_read_permission1 AS urp
@@ -77,7 +77,7 @@ func GetStaticPermissionCnt(condition string, pars []interface{}, startDate, end
 	if condition != "" {
 		sql += condition
 	}
-	sql += ` AND (ur.create_date BETWEEN ? AND ?) GROUP BY urp.chart_permission_id`
-	_, err = o.Raw(sql, pars, startDate, endDate).QueryRows(&items)
+	sql += ` GROUP BY urp.chart_permission_id`
+	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }

+ 15 - 6
routers/commentsRouter.go

@@ -333,8 +333,8 @@ func init() {
 
     beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:UserReadRecordController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:UserReadRecordController"],
         beego.ControllerComments{
-            Method: "Info",
-            Router: `/chart/info`,
+            Method: "Detail",
+            Router: `/detail`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,
@@ -342,8 +342,8 @@ func init() {
 
     beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:UserReadRecordController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:UserReadRecordController"],
         beego.ControllerComments{
-            Method: "Detail",
-            Router: `/detail`,
+            Method: "List",
+            Router: `/list`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,
@@ -351,8 +351,17 @@ func init() {
 
     beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:UserReadRecordController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:UserReadRecordController"],
         beego.ControllerComments{
-            Method: "List",
-            Router: `/list`,
+            Method: "ReadCntChart",
+            Router: `/readCntChart`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:UserReadRecordController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:UserReadRecordController"],
+        beego.ControllerComments{
+            Method: "ReadPermissionChart",
+            Router: `/readPermissionChart`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,