zqbao 7 месяцев назад
Родитель
Сommit
6003215775

+ 23 - 27
controllers/data_manage/sci_hq_data.go

@@ -455,7 +455,7 @@ func (this *SciHqDataController) IndexPageList() {
 // SearchList
 // @Title 卓创红期模糊搜索
 // @Description 卓创红期模糊搜索
-// @Param   Keyword   query   string  ture       "关键字搜索"
+// @Param   Keyword   query   string  true       "关键字搜索"
 // @Success 200 {object} models.BaseResponse
 // @router /sci_hq/search_list [get]
 func (this *SciHqDataController) SearchList() {
@@ -1344,9 +1344,9 @@ func (this *SciHqDataController) DeleteSciHqData() {
 // ExportSciHqList
 // @Title 导出Sci数据
 // @Description 导出Sci数据
-// @Param   request	body request.ExportSciHqExcelReq true "type json string"
+// @Param   ClassifyId   query   int  true       "关键字搜索"
 // @Success 200  导出成功
-// @router /export/sciHqList [post]
+// @router /export/sciHqList [get]
 func (this *SciHqDataController) ExportSciHqList() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
@@ -1360,42 +1360,38 @@ func (this *SciHqDataController) ExportSciHqList() {
 		return
 	}
 
-	//typeName := this.GetString("TypeName") //分类
-	//frequency := this.GetString("Frequency")
-	var req request.ExportSciHqExcelReq
-	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + e.Error()
+	classifyId, _ := this.GetInt("ClassifyId")
+	if classifyId < 0 {
+		br.Msg = "请选择分类"
 		return
 	}
 	secNameList := make([]*models.EdbdataExportList, 0)
-
 	dir, _ := os.Executable()
 	exPath := filepath.Dir(dir)
-
 	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
 	xlsxFile := xlsx.NewFile()
 
 	var condition string
 	var pars []interface{}
-	if req.KeyWord != "" {
-		condition += `AND (index_code=? OR index_name=?)`
-		pars = utils.GetLikeKeywordPars(pars, req.KeyWord, 2)
-	}
-	if req.IsSelectedAll {
-		if len(req.IndexCode) > 0 {
-			condition += ` AND index_code NOT IN (` + utils.GetOrmInReplace(len(req.IndexCode)) + `)`
-			pars = append(pars, req.IndexCode)
+	if classifyId > 0 {
+		childClassify, err := data_manage.GetChildSciHqClassifyListById(classifyId)
+		if err != nil {
+			br.Msg = "下载失败"
+			br.ErrMsg = "获取分类失败,Err:" + err.Error()
+			return
 		}
-	} else {
-		if len(req.IndexCode) > 0 {
-			condition += ` AND index_code IN (` + utils.GetOrmInReplace(len(req.IndexCode)) + `)`
-			pars = append(pars, req.IndexCode)
+		if len(childClassify) > 0 {
+			condition += `AND classify_id IN (` + utils.GetOrmInReplace(len(childClassify)) + `)`
+			for _, child := range childClassify {
+				pars = append(pars, child.ClassifyId)
+			}
+		} else {
+			condition += ` AND classify_id=?`
+			pars = append(pars, classifyId)
 		}
-	}
-	if req.ClassifyId >= 0 {
+	} else {
 		condition += ` AND classify_id=?`
-		pars = append(pars, req.ClassifyId)
+		pars = append(pars, classifyId)
 	}
 	frequencies, err := data_manage.GetSciHqFrequencyByCondition(condition, pars)
 	if err != nil {
@@ -1430,7 +1426,7 @@ func (this *SciHqDataController) ExportSciHqList() {
 		unitRow := sheetNew.AddRow()
 		lastModifyDateRow := sheetNew.AddRow()
 		//获取分类下指标最大数据量
-		dataMax, err := data_manage.GetSciHqDataMaxCount(req.ClassifyId)
+		dataMax, err := data_manage.GetSciHqDataMaxCount(condition, pars)
 		if err != nil {
 			fmt.Println("获取指标最大数据量失败", err.Error())
 			return

+ 7 - 8
models/data_manage/base_from_sci_hq_index.go

@@ -202,15 +202,14 @@ func GetSciHqIndexBaseInfoByCondition(condition string, pars []interface{}) (ite
 	return
 }
 
-func GetSciHqDataMaxCount(classifyId int) (count int, err error) {
+func GetSciHqDataMaxCount(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT MAX(t.num) AS count FROM (
-				SELECT COUNT(1) AS num  FROM base_from_sci_hq_index AS a
-				INNER JOIN base_from_sci_hq_data AS b ON a.index_code=b.index_code
-				WHERE a.classify_id=?
-				GROUP BY a.base_from_sci_hq_index_id
-			)AS t `
-	err = o.Raw(sql, classifyId).QueryRow(&count)
+	sql := `SELECT MAX(t.num) AS count FROM ( SELECT COUNT(1) AS num  FROM base_from_sci_hq_index AS a INNER JOIN base_from_sci_hq_data AS b ON a.index_code=b.index_code WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY a.base_from_sci_hq_index_id) AS t `
+	err = o.Raw(sql, pars).QueryRow(&count)
 	return
 }
 

+ 1 - 1
routers/commentsRouter.go

@@ -5258,7 +5258,7 @@ func init() {
         beego.ControllerComments{
             Method: "ExportSciHqList",
             Router: `/export/sciHqList`,
-            AllowHTTPMethods: []string{"post"},
+            AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
             Filters: nil,
             Params: nil})