浏览代码

Merge branch 'bzq/dev' of eta_mini/eta_mini_bridge into master

baoziqiang 4 月之前
父节点
当前提交
18be0e52f9
共有 2 个文件被更改,包括 42 次插入25 次删除
  1. 28 13
      controllers/report.go
  2. 14 12
      models/report.go

+ 28 - 13
controllers/report.go

@@ -5,6 +5,7 @@ import (
 	"eta/eta_mini_bridge/models/response"
 	"eta/eta_mini_bridge/services"
 	"eta/eta_mini_bridge/utils"
+	"fmt"
 	"html"
 	"strconv"
 	"time"
@@ -763,6 +764,7 @@ func (this *ReportController) Search() {
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   RangeType   query   string  true       "范围类型,1-一天内,2-一周内,3-半年内"
 // @Param   ClassifyId   query   int  true       "分类id"
+// @Param   ReportType   query   int  true       "报告类型:1-eta报告,2-pdf报告"
 // @Success 200 {object} response.ReportListResp
 // @router /list [get]
 func (this *ReportNoAuthController) List() {
@@ -778,19 +780,32 @@ func (this *ReportNoAuthController) List() {
 	level, _ := this.GetInt("Level")
 	rangeType, _ := this.GetInt("RangeType")
 	classifyId, _ := this.GetInt("ClassifyId")
+	reportType, _ := this.GetInt("ReportType")
 
-	if chartPermissionId < 0 {
-		br.Msg = "品种参数错误"
-		return
-	}
+	now := time.Now()
+	todayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
 	var condition string
 	switch rangeType {
 	case 1:
-		condition += ` AND DATE(modify_time)=DATE(NOW()) `
+		condition += fmt.Sprintf(` AND modify_time >= '%s' `, todayStart.Format(utils.FormatDateTime))
 	case 2:
-		condition += ` AND DATE(modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() `
+		oneWeekAgo := now.AddDate(0, 0, -7)
+		condition += fmt.Sprintf(` AND modify_time >= '%s' `, oneWeekAgo.Format(utils.FormatDateTime))
 	case 3:
-		condition += ` AND DATE(modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() `
+		sixMonthAgo := now.AddDate(0, -6, 0)
+		condition += fmt.Sprintf(` AND modify_time >= '%s' `, sixMonthAgo.Format(utils.FormatDateTime))
+	}
+
+	switch reportType {
+	case utils.ReportTypeEta:
+		if chartPermissionId < 0 {
+			br.Msg = "品种参数错误"
+			return
+		}
+	case utils.ReportTypePdf:
+	default:
+		br.Msg = "报告类型参数错误"
+		return
 	}
 
 	var startSize int
@@ -877,14 +892,14 @@ func (this *ReportNoAuthController) List() {
 				classifyThirdIds = append(classifyThirdIds, v.Id)
 			}
 		}
-		tmptotal, err := models.GetPushReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
+		tmptotal, err := models.GetPushReportCountByClassifyIds(reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
 		if err != nil {
 			br.Msg = "获取数据失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
 		total = tmptotal
-		tmpReportList, err := models.GetPushReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
+		tmpReportList, err := models.GetPushReportListByClassifyIds(reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取报告列表失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
@@ -945,14 +960,14 @@ func (this *ReportNoAuthController) List() {
 				classifyThirdIds = append(classifyThirdIds, v.Id)
 			}
 		}
-		tmptotal, err := models.GetPushReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
+		tmptotal, err := models.GetPushReportCountByClassifyIds(reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
 		if err != nil {
 			br.Msg = "获取数据失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
 		total = tmptotal
-		tmpReportList, err := models.GetPushReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
+		tmpReportList, err := models.GetPushReportListByClassifyIds(reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取报告列表失败"
 			br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
@@ -964,14 +979,14 @@ func (this *ReportNoAuthController) List() {
 		for k := range classifyIdMap {
 			selectedClassifyIds = append(selectedClassifyIds, k)
 		}
-		tmptotal, err := models.GetPushReportCount(selectedClassifyIds, condition)
+		tmptotal, err := models.GetPushReportCount(reportType, selectedClassifyIds, condition)
 		if err != nil {
 			br.Msg = "获取数据失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
 		total = tmptotal
-		tmpReportList, err := models.GetPushReportListByPage(selectedClassifyIds, condition, startSize, pageSize)
+		tmpReportList, err := models.GetPushReportListByPage(reportType, selectedClassifyIds, condition, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取报告列表失败"
 			br.ErrMsg = "获取报告列表失败,Err:" + err.Error()

+ 14 - 12
models/report.go

@@ -152,12 +152,12 @@ func GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyTh
 	return
 }
 
-func GetPushReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string) (count int, err error) {
+func GetPushReportCountByClassifyIds(reportType int, classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string) (count int, err error) {
 	if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
 		return
 	}
 	o := orm.NewOrm()
-	sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=1 AND (1=2 `
+	sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=? AND (1=2 `
 
 	if len(classifyFirstIds) > 0 {
 		sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
@@ -172,16 +172,16 @@ func GetPushReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classi
 	if condition != "" {
 		sql += condition
 	}
-	err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds).QueryRow(&count)
+	err = o.Raw(sql, reportType, classifyFirstIds, classifySecondIds, classifyThirdIds).QueryRow(&count)
 	return
 }
 
-func GetPushReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string, startSize, pageSize int) (items []*ReportPushView, err error) {
+func GetPushReportListByClassifyIds(reportType int, classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string, startSize, pageSize int) (items []*ReportPushView, err error) {
 	if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
 		return
 	}
 	o := orm.NewOrm()
-	sql := `SELECT * FROM report_push_status WHERE state=1 AND report_type=1 AND (1=2 `
+	sql := `SELECT * FROM report_push_status WHERE state=1 AND report_type=? AND (1=2 `
 	// AND (a.classify_id_first IN (%s) OR a.classify_id_second IN (%s) OR a.classify_id_third IN (%s)) `
 	if len(classifyFirstIds) > 0 {
 		sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
@@ -197,13 +197,13 @@ func GetPushReportListByClassifyIds(classifyFirstIds, classifySecondIds, classif
 		sql += condition
 	}
 	sql += ` ORDER BY publish_time DESC LIMIT ?,? `
-	_, err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds, startSize, pageSize).QueryRows(&items)
+	_, err = o.Raw(sql, reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, startSize, pageSize).QueryRows(&items)
 	return
 }
 
-func GetPushReportCount(classifyIds []int, dateCondition string) (count int, err error) {
+func GetPushReportCount(reportType int, classifyIds []int, dateCondition string) (count int, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=1 `
+	sql := ` SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=? `
 	var pars []interface{}
 	if len(classifyIds) > 0 {
 		sql += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s)) `
@@ -213,13 +213,15 @@ func GetPushReportCount(classifyIds []int, dateCondition string) (count int, err
 	if dateCondition != "" {
 		sql += dateCondition
 	}
-	err = o.Raw(sql, pars...).QueryRow(&count)
+	tmpPars := []interface{}{reportType}
+	tmpPars = append(tmpPars, pars...)
+	err = o.Raw(sql, tmpPars).QueryRow(&count)
 	return
 }
 
-func GetPushReportListByPage(classifyIds []int, dateCondition string, startSize, pageSize int) (items []*ReportPushView, err error) {
+func GetPushReportListByPage(reportType int, classifyIds []int, dateCondition string, startSize, pageSize int) (items []*ReportPushView, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM report_push_status WHERE state=1 AND report_type=1 `
+	sql := ` SELECT * FROM report_push_status WHERE state=1 AND report_type=? `
 	var pars []interface{}
 	if len(classifyIds) > 0 {
 		sql += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s)) `
@@ -230,7 +232,7 @@ func GetPushReportListByPage(classifyIds []int, dateCondition string, startSize,
 		sql += dateCondition
 	}
 	sql += ` ORDER BY publish_time DESC LIMIT ?,? `
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	_, err = o.Raw(sql, reportType, pars, startSize, pageSize).QueryRows(&items)
 	return
 }