浏览代码

Merge remote-tracking branch 'origin/master' into sandbox

# Conflicts:
#	models/research_report.go
#	services/report.go
#	services/task.go
Roc 1 年之前
父节点
当前提交
7d187e4a44

+ 3 - 3
controllers/data_manage/lz_data.go

@@ -562,7 +562,7 @@ func (this *EdbInfoController) ExportLzQuotasData() {
 	}
 
 	// 获取多个品种的指标信息
-	quotaList, err := models.GetExportLzSurveyProductByBreedIds(breedIdsStr)
+	quotaList, err := models.GetExportLzSurveyProductByBreedIds(breedIds)
 	if err != nil {
 		br.Msg = "导出失败"
 		br.ErrMsg = "获取指标信息失败, Err: " + err.Error()
@@ -570,7 +570,7 @@ func (this *EdbInfoController) ExportLzQuotasData() {
 	}
 
 	// 获取多个品种的指标最大数据量
-	quotaMaxCountList, err := data_source.GetExportLzSurveyDataMaxCount(breedIdsStr)
+	quotaMaxCountList, err := data_source.GetExportLzSurveyDataMaxCount(breedIds)
 	if err != nil {
 		br.Msg = "导出失败"
 		br.ErrMsg = "获取指标最大数据量失败, Err: " + err.Error()
@@ -587,7 +587,7 @@ func (this *EdbInfoController) ExportLzQuotasData() {
 		var iniArr []*data_source.LongzhongSurveyData
 		productIdDataMatch[quotaList[i].SurveyProductId] = iniArr
 	}
-	quotaDataList, err := data_source.GetExportLzSurveyDataByBreedIds(breedIdsStr)
+	quotaDataList, err := data_source.GetExportLzSurveyDataByBreedIds(breedIds)
 	for k, _ := range productIdDataMatch {
 		var tmpArr []*data_source.LongzhongSurveyData
 		for _, qd := range quotaDataList {

+ 5 - 5
controllers/report.go

@@ -139,14 +139,14 @@ func (this *ReportController) ListReport() {
 				syncReportIdArr = append(syncReportIdArr, strconv.Itoa(list[i].OldReportId))
 			}
 		}
-		reportIds := strings.Join(reportIdArr, ",")
-		syncReportIds := strings.Join(syncReportIdArr, ",")
+		//reportIds := strings.Join(reportIdArr, ",")
+		//syncReportIds := strings.Join(syncReportIdArr, ",")
 
 		// 查询同步过来的报告对应的老报告PV+UV
 		pvMap := make(map[int]int, 0)
 		uvMap := make(map[int]int, 0)
-		if syncReportIds != "" {
-			puvList, e := models.GetPUVByResearchReportIds(syncReportIds)
+		if len(syncReportIdArr) > 0 {
+			puvList, e := models.GetPUVByResearchReportIds(syncReportIdArr)
 			if e != nil {
 				br.Msg = "获取失败"
 				br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
@@ -159,7 +159,7 @@ func (this *ReportController) ListReport() {
 			}
 		}
 		// 晨周报音频列表
-		videoList, err := models.GetReportChapterVideoListByReportIds(reportIds)
+		videoList, err := models.GetReportChapterVideoListByReportIds(reportIdArr)
 		if err != nil {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取报告音频文件失败,Err:" + err.Error()

+ 7 - 5
controllers/sys_admin.go

@@ -116,7 +116,7 @@ func (this *SysAdminController) ListSysuser() {
 	}
 
 	var list []*system.AdminItem
-	adminIdArr := make([]string, 0)
+	adminIdArr := make([]int, 0)
 	if teamId <= 0 {
 		//if groupId > 0 {
 		//	ids, err := system.GetGroupIdByParentId(groupId, startSize, pageSize)
@@ -145,7 +145,8 @@ func (this *SysAdminController) ListSysuser() {
 		for i := 0; i < lenList; i++ {
 
 			item := list[i]
-			adminIdArr = append(adminIdArr, strconv.Itoa(item.AdminId))
+			//adminIdArr = append(adminIdArr, strconv.Itoa(item.AdminId))
+			adminIdArr = append(adminIdArr, item.AdminId)
 			var secondName *string
 			if item.GroupId != 0 {
 				pid, err := company.GetParentIdFromGroup(item.GroupId)
@@ -218,7 +219,8 @@ func (this *SysAdminController) ListSysuser() {
 		lenList := len(list)
 		for i := 0; i < lenList; i++ {
 			item := list[i]
-			adminIdArr = append(adminIdArr, strconv.Itoa(item.AdminId))
+			//adminIdArr = append(adminIdArr, strconv.Itoa(item.AdminId))
+			adminIdArr = append(adminIdArr, item.AdminId)
 
 			if item.DepartmentName != "" {
 				if item.GroupName == "" {
@@ -266,9 +268,9 @@ func (this *SysAdminController) ListSysuser() {
 	}
 	// 研究方向分组
 	if len(adminIdArr) > 0 {
-		adminIds := strings.Join(adminIdArr, ",")
+		//adminIds := strings.Join(adminIdArr, ",")
 		//researchGroupList, e := system.GetAdminResearchGroupListByAdminId(adminIds)
-		researchGroupList, e := models.GetAdminVarietyTagRelationListByAdminId(adminIds)
+		researchGroupList, e := models.GetAdminVarietyTagRelationListByAdminId(adminIdArr)
 		if e != nil {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取研究方向分组列表失败, Err:" + e.Error()

+ 20 - 2
controllers/voice.go

@@ -11,6 +11,8 @@ import (
 	"io/ioutil"
 	"os"
 	"path"
+	"strconv"
+	"strings"
 	"time"
 )
 
@@ -185,11 +187,27 @@ func (this *VoiceCommonController) ReportChapterDownload() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	chapterIds := this.GetString("ChapterIds")
-	if chapterIds == "" {
+	strChapterIds := this.GetString("ChapterIds")
+	if strChapterIds == "" {
 		br.Msg = "参数错误"
 		return
 	}
+	chapterIds := make([]int, 0)
+	chapterIdArr := strings.Split(strChapterIds, ",")
+	for _, v := range chapterIdArr {
+		id, e := strconv.Atoi(v)
+		if e != nil {
+			br.Msg = "参数有误"
+			br.ErrMsg = "章节ID有误, Err: " + e.Error()
+			return
+		}
+		chapterIds = append(chapterIds, id)
+	}
+	if len(chapterIds) == 0 {
+		br.Msg = "参数有误"
+		return
+	}
+
 	videoList, err := models.GetReportChapterVideoListByChapterIds(chapterIds)
 	if err != nil {
 		br.Msg = "获取音频列表失败"

+ 67 - 58
models/data_manage/baiinfo_data.go

@@ -3,6 +3,7 @@ package data_manage
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hz_eta_api/utils"
 )
 
 type BaiinfoClassify struct {
@@ -31,21 +32,21 @@ func GetBaiinfoFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err
 
 type BaiinfoIndex struct {
 	BaseFromBaiinfoIndexId int `orm:"column(base_from_baiinfo_index_id);pk"`
-	Interface          string
-	Name               string
-	IndexCode          string
-	IndexName          string
-	Type1              string `orm:"column(type_1)"`
-	Type2              string `orm:"column(type_2)"`
-	Type3              string `orm:"column(type_3)"`
-	Frequency          string
-	Unit               string
-	ApiStartTime       string
-	ApiUpdateTime      string
-	StartTime          string
-	FinishTime         string
-	CreateTime         string
-	ModifyTime         string
+	Interface              string
+	Name                   string
+	IndexCode              string
+	IndexName              string
+	Type1                  string `orm:"column(type_1)"`
+	Type2                  string `orm:"column(type_2)"`
+	Type3                  string `orm:"column(type_3)"`
+	Frequency              string
+	Unit                   string
+	ApiStartTime           string
+	ApiUpdateTime          string
+	StartTime              string
+	FinishTime             string
+	CreateTime             string
+	ModifyTime             string
 }
 
 func GetBaiinfoIndex(condition string, pars interface{}) (items []*BaiinfoIndex, err error) {
@@ -60,26 +61,28 @@ func GetBaiinfoIndex(condition string, pars interface{}) (items []*BaiinfoIndex,
 }
 
 type BaiinfoExportIndex struct {
-	TypeName	string
-	IndexCode	string
-	IndexName   string
-	Type1		string	`orm:"column(type_1)"`
-	Type2		string	`orm:"column(type_2)"`
-	Type3		string	`orm:"column(type_3)"`
-	Frequency	string
-	Unit		string
-	ModifyTime	string
-}
-
-func GetExportBaiinfoIndex(typeCodes string) (items []*BaiinfoExportIndex, err error) {
+	TypeName   string
+	IndexCode  string
+	IndexName  string
+	Type1      string `orm:"column(type_1)"`
+	Type2      string `orm:"column(type_2)"`
+	Type3      string `orm:"column(type_3)"`
+	Frequency  string
+	Unit       string
+	ModifyTime string
+}
+
+func GetExportBaiinfoIndex(typeCodes []string) (items []*BaiinfoExportIndex, err error) {
+	if len(typeCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT *,CONCAT(type_2, "#", type_3) AS type_name FROM base_from_baiinfo_index WHERE CONCAT(type_2, "#", type_3) IN (` + typeCodes + `) ORDER BY frequency ASC,index_code ASC`
-	_, err = o.Raw(sql).QueryRows(&items)
-
+	sql := ` SELECT *,CONCAT(type_2, "#", type_3) AS type_name FROM base_from_baiinfo_index WHERE CONCAT(type_2, "#", type_3) IN (` + utils.GetOrmInReplace(len(typeCodes)) + `) ORDER BY frequency ASC,index_code ASC`
+	_, err = o.Raw(sql, typeCodes).QueryRows(&items)
 	return
 }
 
-func GetBaiinfoFrequency(classifyId int ) (items []*string,err error){
+func GetBaiinfoFrequency(classifyId int) (items []*string, err error) {
 	sql := `SELECT DISTINCT frequency FROM base_from_baiinfo_index WHERE classify_id=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
 	o := orm.NewOrmUsingDB("data")
 	_, err = o.Raw(sql, classifyId).QueryRows(&items)
@@ -95,22 +98,22 @@ func GetBaiinfoFrequencyByCode(code string) (items []*string, err error) {
 
 type BaiinfoIndexList struct {
 	BaseFromBaiinfoIndexId int `orm:"column(base_from_baiinfo_index_id);pk"`
-	Interface          string
-	Name               string
-	IndexCode          string
-	IndexName          string
-	Type1              string `orm:"column(type_1)"`
-	Type2              string `orm:"column(type_2)"`
-	Type3              string `orm:"column(type_3)"`
-	Frequency          string
-	Unit               string
-	ApiStartTime       string
-	ApiUpdateTime      string
-	StartTime          string
-	FinishTime         string
-	ModifyTime         string
-	DataList           []*BaiinfoIndexData
-	Paging             *paging.PagingItem `description:"分页数据"`
+	Interface              string
+	Name                   string
+	IndexCode              string
+	IndexName              string
+	Type1                  string `orm:"column(type_1)"`
+	Type2                  string `orm:"column(type_2)"`
+	Type3                  string `orm:"column(type_3)"`
+	Frequency              string
+	Unit                   string
+	ApiStartTime           string
+	ApiUpdateTime          string
+	StartTime              string
+	FinishTime             string
+	ModifyTime             string
+	DataList               []*BaiinfoIndexData
+	Paging                 *paging.PagingItem `description:"分页数据"`
 }
 
 type BaiinfoIndexData struct {
@@ -160,11 +163,14 @@ func GetBaiinfoDataMaxCount(classifyId int) (count int, err error) {
 }
 
 type ExportBaiinfoDataMaxCount struct {
-	TypeName	string
-	Count		int
+	TypeName string
+	Count    int
 }
 
-func GetExportBaiinfoDataMaxCount(typeCodes string) (items []*ExportBaiinfoDataMaxCount, err error) {
+func GetExportBaiinfoDataMaxCount(typeCodes []string) (items []*ExportBaiinfoDataMaxCount, err error) {
+	if len(typeCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT
 				MAX(t.num) AS count,
@@ -178,26 +184,29 @@ func GetExportBaiinfoDataMaxCount(typeCodes string) (items []*ExportBaiinfoDataM
 						base_from_baiinfo_index AS a
 					INNER JOIN base_from_baiinfo_data AS b ON a.index_code = b.index_code
 					WHERE
-						CONCAT(a.type_2, "#", a.type_3) IN (` + typeCodes + `)
+						CONCAT(a.type_2, "#", a.type_3) IN (` + utils.GetOrmInReplace(len(typeCodes)) + `)
 					GROUP BY
 						a.base_from_baiinfo_index_id
 				) AS t
 			GROUP BY
 				type_name `
-	_, err = o.Raw(sql).QueryRows(&items)
+	_, err = o.Raw(sql, typeCodes).QueryRows(&items)
 
 	return
 }
 
 type ExportBaiinfoIndexData struct {
-	Value    	string 	`orm:"column(value)" description:"日期"`
-	DataTime 	string 	`orm:"column(data_time)" description:"值"`
-	IndexCode	string	`orm:"column(index_code)" description:"指标编码"`
+	Value     string `orm:"column(value)" description:"日期"`
+	DataTime  string `orm:"column(data_time)" description:"值"`
+	IndexCode string `orm:"column(index_code)" description:"指标编码"`
 }
 
-func GetExportBaiinfoIndexDataByCodes(indexCodes string) (items []*ExportBaiinfoIndexData, err error) {
+func GetExportBaiinfoIndexDataByCodes(indexCodes []string) (items []*ExportBaiinfoIndexData, err error) {
+	if len(indexCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT index_code,data_time,value FROM base_from_baiinfo_data WHERE index_code IN (` + indexCodes + `) ORDER BY data_time DESC  `
-	_, err = o.Raw(sql).QueryRows(&items)
+	sql := ` SELECT index_code,data_time,value FROM base_from_baiinfo_data WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodes)) + `) ORDER BY data_time DESC  `
+	_, err = o.Raw(sql, indexCodes).QueryRows(&items)
 	return
 }

+ 36 - 28
models/data_manage/sci_data.go

@@ -3,6 +3,7 @@ package data_manage
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hz_eta_api/utils"
 )
 
 type SciClassify struct {
@@ -60,26 +61,28 @@ func GetSciIndex(condition string, pars interface{}) (items []*SciIndex, err err
 }
 
 type SciExportIndex struct {
-	TypeName	string
-	IndexCode	string
-	IndexName   string
-	Type1		string	`orm:"column(type_1)"`
-	Type2		string	`orm:"column(type_2)"`
-	Type3		string	`orm:"column(type_3)"`
-	Frequency	string
-	Unit		string
-	ModifyTime	string
-}
-
-func GetExportSciIndex(typeCodes string) (items []*SciExportIndex, err error) {
+	TypeName   string
+	IndexCode  string
+	IndexName  string
+	Type1      string `orm:"column(type_1)"`
+	Type2      string `orm:"column(type_2)"`
+	Type3      string `orm:"column(type_3)"`
+	Frequency  string
+	Unit       string
+	ModifyTime string
+}
+
+func GetExportSciIndex(typeCodes []string) (items []*SciExportIndex, err error) {
+	if len(typeCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT *,CONCAT(type_2, "#", type_3) AS type_name FROM base_from_sci_index WHERE CONCAT(type_2, "#", type_3) IN (` + typeCodes + `) ORDER BY frequency ASC,index_code ASC`
-	_, err = o.Raw(sql).QueryRows(&items)
-
+	sql := ` SELECT *,CONCAT(type_2, "#", type_3) AS type_name FROM base_from_sci_index WHERE CONCAT(type_2, "#", type_3) IN (` + utils.GetOrmInReplace(len(typeCodes)) + `) ORDER BY frequency ASC,index_code ASC`
+	_, err = o.Raw(sql, typeCodes).QueryRows(&items)
 	return
 }
 
-func GetSciFrequency(classifyId int ) (items []*string,err error){
+func GetSciFrequency(classifyId int) (items []*string, err error) {
 	sql := `SELECT DISTINCT frequency FROM base_from_sci_index WHERE classify_id=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
 	o := orm.NewOrmUsingDB("data")
 	_, err = o.Raw(sql, classifyId).QueryRows(&items)
@@ -160,11 +163,14 @@ func GetSciDataMaxCount(classifyId int) (count int, err error) {
 }
 
 type ExportSciDataMaxCount struct {
-	TypeName	string
-	Count		int
+	TypeName string
+	Count    int
 }
 
-func GetExportSciDataMaxCount(typeCodes string) (items []*ExportSciDataMaxCount, err error) {
+func GetExportSciDataMaxCount(typeCodes []string) (items []*ExportSciDataMaxCount, err error) {
+	if len(typeCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT
 				MAX(t.num) AS count,
@@ -178,26 +184,28 @@ func GetExportSciDataMaxCount(typeCodes string) (items []*ExportSciDataMaxCount,
 						base_from_sci_index AS a
 					INNER JOIN base_from_sci_data AS b ON a.index_code = b.index_code
 					WHERE
-						CONCAT(a.type_2, "#", a.type_3) IN (` + typeCodes + `)
+						CONCAT(a.type_2, "#", a.type_3) IN (` + utils.GetOrmInReplace(len(typeCodes)) + `)
 					GROUP BY
 						a.base_from_sci_index_id
 				) AS t
 			GROUP BY
 				type_name `
-	_, err = o.Raw(sql).QueryRows(&items)
-
+	_, err = o.Raw(sql, typeCodes).QueryRows(&items)
 	return
 }
 
 type ExportSciIndexData struct {
-	Value    	string 	`orm:"column(value)" description:"日期"`
-	DataTime 	string 	`orm:"column(data_time)" description:"值"`
-	IndexCode	string	`orm:"column(index_code)" description:"指标编码"`
+	Value     string `orm:"column(value)" description:"日期"`
+	DataTime  string `orm:"column(data_time)" description:"值"`
+	IndexCode string `orm:"column(index_code)" description:"指标编码"`
 }
 
-func GetExportSciIndexDataByCodes(indexCodes string) (items []*ExportSciIndexData, err error) {
+func GetExportSciIndexDataByCodes(indexCodes []string) (items []*ExportSciIndexData, err error) {
+	if len(indexCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT index_code,data_time,value FROM base_from_sci_data WHERE index_code IN (` + indexCodes + `) ORDER BY data_time DESC  `
-	_, err = o.Raw(sql).QueryRows(&items)
+	sql := ` SELECT index_code,data_time,value FROM base_from_sci_data WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodes)) + `) ORDER BY data_time DESC  `
+	_, err = o.Raw(sql, indexCodes).QueryRows(&items)
 	return
 }

+ 36 - 28
models/data_manage/smm_data.go

@@ -3,6 +3,7 @@ package data_manage
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hz_eta_api/utils"
 )
 
 type SmmClassify struct {
@@ -60,26 +61,28 @@ func GetSmmIndex(condition string, pars interface{}) (items []*SmmIndex, err err
 }
 
 type SmmExportIndex struct {
-	TypeName	string
-	IndexCode	string
-	IndexName   string
-	Type1		string	`orm:"column(type_1)"`
-	Type2		string	`orm:"column(type_2)"`
-	Type3		string	`orm:"column(type_3)"`
-	Frequency	string
-	Unit		string
-	ModifyTime	string
-}
-
-func GetExportSmmIndex(typeCodes string) (items []*SmmExportIndex, err error) {
+	TypeName   string
+	IndexCode  string
+	IndexName  string
+	Type1      string `orm:"column(type_1)"`
+	Type2      string `orm:"column(type_2)"`
+	Type3      string `orm:"column(type_3)"`
+	Frequency  string
+	Unit       string
+	ModifyTime string
+}
+
+func GetExportSmmIndex(typeCodes []string) (items []*SmmExportIndex, err error) {
+	if len(typeCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT *,CONCAT(type_2, "#", type_3) AS type_name FROM base_from_smm_index WHERE CONCAT(type_2, "#", type_3) IN (` + typeCodes + `) ORDER BY frequency ASC,index_code ASC`
-	_, err = o.Raw(sql).QueryRows(&items)
-
+	sql := ` SELECT *,CONCAT(type_2, "#", type_3) AS type_name FROM base_from_smm_index WHERE CONCAT(type_2, "#", type_3) IN (` + utils.GetOrmInReplace(len(typeCodes)) + `) ORDER BY frequency ASC,index_code ASC`
+	_, err = o.Raw(sql, typeCodes).QueryRows(&items)
 	return
 }
 
-func GetSmmFrequency(classifyId int ) (items []*string,err error){
+func GetSmmFrequency(classifyId int) (items []*string, err error) {
 	sql := `SELECT DISTINCT frequency FROM base_from_smm_index WHERE classify_id=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
 	o := orm.NewOrmUsingDB("data")
 	_, err = o.Raw(sql, classifyId).QueryRows(&items)
@@ -160,11 +163,14 @@ func GetSmmDataMaxCount(classifyId int) (count int, err error) {
 }
 
 type ExportSmmDataMaxCount struct {
-	TypeName	string
-	Count		int
+	TypeName string
+	Count    int
 }
 
-func GetExportSmmDataMaxCount(typeCodes string) (items []*ExportSmmDataMaxCount, err error) {
+func GetExportSmmDataMaxCount(typeCodes []string) (items []*ExportSmmDataMaxCount, err error) {
+	if len(typeCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
 	sql := ` SELECT
 				MAX(t.num) AS count,
@@ -178,26 +184,28 @@ func GetExportSmmDataMaxCount(typeCodes string) (items []*ExportSmmDataMaxCount,
 						base_from_smm_index AS a
 					INNER JOIN base_from_smm_data AS b ON a.index_code = b.index_code
 					WHERE
-						CONCAT(a.type_2, "#", a.type_3) IN (` + typeCodes + `)
+						CONCAT(a.type_2, "#", a.type_3) IN (` + utils.GetOrmInReplace(len(typeCodes)) + `)
 					GROUP BY
 						a.base_from_smm_index_id
 				) AS t
 			GROUP BY
 				type_name `
-	_, err = o.Raw(sql).QueryRows(&items)
-
+	_, err = o.Raw(sql, typeCodes).QueryRows(&items)
 	return
 }
 
 type ExportSmmIndexData struct {
-	Value    	string 	`orm:"column(value)" description:"日期"`
-	DataTime 	string 	`orm:"column(data_time)" description:"值"`
-	IndexCode	string	`orm:"column(index_code)" description:"指标编码"`
+	Value     string `orm:"column(value)" description:"日期"`
+	DataTime  string `orm:"column(data_time)" description:"值"`
+	IndexCode string `orm:"column(index_code)" description:"指标编码"`
 }
 
-func GetExportSmmIndexDataByCodes(indexCodes string) (items []*ExportSmmIndexData, err error) {
+func GetExportSmmIndexDataByCodes(indexCodes []string) (items []*ExportSmmIndexData, err error) {
+	if len(indexCodes) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT index_code,data_time,value FROM base_from_smm_data WHERE index_code IN (` + indexCodes + `) ORDER BY data_time DESC  `
-	_, err = o.Raw(sql).QueryRows(&items)
+	sql := ` SELECT index_code,data_time,value FROM base_from_smm_data WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodes)) + `) ORDER BY data_time DESC  `
+	_, err = o.Raw(sql, indexCodes).QueryRows(&items)
 	return
 }

+ 13 - 8
models/data_source/longzhong.go

@@ -3,6 +3,7 @@ package data_source
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"hongze/hz_eta_api/models/data_manage"
+	"hongze/hz_eta_api/utils"
 	"time"
 )
 
@@ -83,7 +84,10 @@ type ExportLzSurveyDataMaxCount struct {
 	BreedId int `description:"品种ID"`
 }
 
-func GetExportLzSurveyDataMaxCount(breedIds string) (items []ExportLzSurveyDataMaxCount, err error) {
+func GetExportLzSurveyDataMaxCount(breedIds []string) (items []ExportLzSurveyDataMaxCount, err error) {
+	if len(breedIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("edb")
 	sql := ` SELECT
 				MAX(t.num) AS count,
@@ -97,23 +101,24 @@ func GetExportLzSurveyDataMaxCount(breedIds string) (items []ExportLzSurveyDataM
 						longzhong_survey_product AS a
 					INNER JOIN longzhong_survey_data AS b ON a.survey_product_id = b.survey_product_id
 					WHERE
-						a.breed_id IN (` + breedIds + `)
+						a.breed_id IN (` + utils.GetOrmInReplace(len(breedIds)) + `)
 					GROUP BY
 						a.survey_product_id
 				) AS t
 			GROUP BY
 				t.breed_id `
-	_, err = o.Raw(sql).QueryRows(&items)
-
+	_, err = o.Raw(sql, breedIds).QueryRows(&items)
 	return
 }
 
-func GetExportLzSurveyDataByBreedIds(breedIds string) (items []*LongzhongSurveyData, err error) {
+func GetExportLzSurveyDataByBreedIds(breedIds []string) (items []*LongzhongSurveyData, err error) {
+	if len(breedIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("edb")
 	fields := ` survey_product_id, breed_id, input_value, data_time `
-	sql := `SELECT ` + fields + ` FROM longzhong_survey_data WHERE breed_id IN (` + breedIds + `) ORDER BY breed_id ASC, survey_product_id ASC, data_time DESC `
-	_, err = o.Raw(sql).QueryRows(&items)
-
+	sql := `SELECT ` + fields + ` FROM longzhong_survey_data WHERE breed_id IN (` + utils.GetOrmInReplace(len(breedIds)) + `) ORDER BY breed_id ASC, survey_product_id ASC, data_time DESC `
+	_, err = o.Raw(sql, breedIds).QueryRows(&items)
 	return
 }
 

+ 20 - 13
models/report.go

@@ -3,6 +3,7 @@ package models
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hz_eta_api/utils"
 	"strings"
 	"time"
 )
@@ -125,10 +126,13 @@ func GetReportList(condition string, pars []interface{}, companyType string, sta
 	return
 }
 
-// 发布报告
-func PublishReport(reportIds string) (err error) {
+// PublishReport 发布报告
+func PublishReport(reportIds []int) (err error) {
+	if len(reportIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + reportIds + `)`
+	sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
 	_, err = o.Raw(sql).Exec()
 	return
 }
@@ -196,10 +200,13 @@ func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
 }
 
 // GetSimpleReportByIds 根据报告ID查询报告基本信息
-func GetSimpleReportByIds(reportIds string) (list []*ReportDetail, err error) {
+func GetSimpleReportByIds(reportIds []int) (list []*ReportDetail, err error) {
+	if len(reportIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `SELECT id, title FROM report WHERE id IN (` + reportIds + `)`
-	_, err = o.Raw(sql).QueryRows(&list)
+	sql := `SELECT id, title FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
+	_, err = o.Raw(sql, reportIds).QueryRows(&list)
 	return
 }
 
@@ -598,7 +605,7 @@ func GetNewReportExist(oldReportId int) (item *Report, err error) {
 }
 
 // PublishReportAndChapter 发布报告及章节
-func PublishReportAndChapter(reportInfo *Report, publishIds string, unPublishIds string, isPublishReport bool, cols []string) (err error) {
+func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	to, err := o.Begin()
 	if err != nil {
@@ -618,13 +625,13 @@ func PublishReportAndChapter(reportInfo *Report, publishIds string, unPublishIds
 		}
 	}
 	// 发布章节
-	if publishIds != "" {
-		sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + publishIds + `) `
-		_, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
+	if len(publishIds) > 0 {
+		sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
+		_, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
 	}
-	if unPublishIds != "" {
-		sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + unPublishIds + `) `
-		_, err = to.Raw(sql, reportInfo.Id).Exec()
+	if len(unPublishIds) > 0 {
+		sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(unPublishIds)) + `) `
+		_, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
 	}
 	return
 }

+ 32 - 17
models/report_chapter.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hz_eta_api/utils"
 	"time"
 )
 
@@ -187,7 +188,10 @@ func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, er
 }
 
 // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
-func GetReportChapterVideoListByReportIds(reportIds string) (list []*ReportChapterVideoList, err error) {
+func GetReportChapterVideoListByReportIds(reportIds []string) (list []*ReportChapterVideoList, err error) {
+	if len(reportIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("rddp")
 	sql := ` SELECT
 				report_id,
@@ -198,16 +202,19 @@ func GetReportChapterVideoListByReportIds(reportIds string) (list []*ReportChapt
 			FROM
 				report_chapter
 			WHERE
-				report_id IN (` + reportIds + `) AND publish_state = 2 AND video_url != ""
+				report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ""
 			ORDER BY
 				report_chapter_id ASC `
-	_, err = o.Raw(sql).QueryRows(&list)
+	_, err = o.Raw(sql, reportIds).QueryRows(&list)
 
 	return
 }
 
 // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
-func GetReportChapterVideoListByChapterIds(chapterIds string) (list []*ReportChapterVideoList, err error) {
+func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
+	if len(chapterIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("rddp")
 	sql := ` SELECT
 				report_id,
@@ -218,11 +225,10 @@ func GetReportChapterVideoListByChapterIds(chapterIds string) (list []*ReportCha
 			FROM
 				report_chapter
 			WHERE
-				report_chapter_id IN (` + chapterIds + `) AND publish_state = 2
+				report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) AND publish_state = 2
 			ORDER BY
 				report_chapter_id ASC `
-	_, err = o.Raw(sql).QueryRows(&list)
-
+	_, err = o.Raw(sql, chapterIds).QueryRows(&list)
 	return
 }
 
@@ -251,27 +257,36 @@ func CountPublishedChapterNum(reportId int) (count int, err error) {
 	return
 }
 
-// GetChapterListByReportId 根据ReportId获取章节列表
-func GetChapterListByChapterIds(chapterIds string) (list []*ReportChapter, err error) {
+// GetChapterListByChapterIds 根据ReportId获取章节列表
+func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
+	if len(chapterIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("rddp")
-	sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + chapterIds + `) ORDER BY sort ASC`
-	_, err = o.Raw(sql).QueryRows(&list)
+	sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
+	_, err = o.Raw(sql, chapterIds).QueryRows(&list)
 	return
 }
 
 // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
-func GetChapterSimpleListByChapterIds(chapterIds string) (list []*ReportChapter, err error) {
+func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
+	if len(chapterIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("rddp")
-	sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE report_chapter_id IN (` + chapterIds + `) ORDER BY publish_time desc, sort ASC`
-	_, err = o.Raw(sql).QueryRows(&list)
+	sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY publish_time desc, sort ASC`
+	_, err = o.Raw(sql, chapterIds).QueryRows(&list)
 	return
 }
 
 // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
-func GetChapterSimpleListByReportIds(reportIds string) (list []*ReportChapter, err error) {
+func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
+	if len(reportIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("rddp")
-	sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE publish_state = 2 and report_id IN (` + reportIds + `) ORDER BY publish_time desc, sort ASC`
-	_, err = o.Raw(sql).QueryRows(&list)
+	sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE publish_state = 2 and report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) ORDER BY publish_time desc, sort ASC`
+	_, err = o.Raw(sql, reportIds).QueryRows(&list)
 	return
 }
 

+ 7 - 3
models/system/research_group.go

@@ -2,6 +2,7 @@ package system
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hz_eta_api/utils"
 	"time"
 )
 
@@ -110,7 +111,10 @@ type AdminResearchGroupList struct {
 }
 
 // GetAdminResearchGroupListByAdminId 获取研究员研究方向分组列表
-func GetAdminResearchGroupListByAdminId(adminIds string) (list []*AdminResearchGroupList, err error) {
+func GetAdminResearchGroupListByAdminId(adminIds []int) (list []*AdminResearchGroupList, err error) {
+	if len(adminIds) == 0 {
+		return
+	}
 	o := orm.NewOrm()
 	sql := `SELECT
 				a.admin_id,
@@ -119,9 +123,9 @@ func GetAdminResearchGroupListByAdminId(adminIds string) (list []*AdminResearchG
 				research_group_relation AS a
 			INNER JOIN research_group AS b ON a.research_group_id = b.research_group_id
 			WHERE
-				a.admin_id IN (` + adminIds + `)
+				a.admin_id IN (` + utils.GetOrmInReplace(len(adminIds)) + `)
 			GROUP BY
 				a.admin_id`
-	_, err = o.Raw(sql).QueryRows(&list)
+	_, err = o.Raw(sql, adminIds).QueryRows(&list)
 	return
 }

+ 6 - 4
models/target.go

@@ -1152,12 +1152,14 @@ func GetLzSurveyProductByNameAndFrequency(productName string, frequency int) (it
 	return
 }
 
-func GetExportLzSurveyProductByBreedIds(breedIds string) (items []*LongzhongSurveyProduct, err error) {
+func GetExportLzSurveyProductByBreedIds(breedIds []string) (items []*LongzhongSurveyProduct, err error) {
+	if len(breedIds) == 0 {
+		return
+	}
 	field := ` survey_product_id, breed_id, breed_name, sample_name, custom, quota_name, lz_code, frequency, unit_name, end_date, input_value `
-	sql := `SELECT ` + field + ` FROM longzhong_survey_product WHERE breed_id IN (` + breedIds + `) ORDER BY breed_id ASC, frequency ASC, survey_product_id ASC `
+	sql := `SELECT ` + field + ` FROM longzhong_survey_product WHERE breed_id IN (` + utils.GetOrmInReplace(len(breedIds)) + `) ORDER BY breed_id ASC, frequency ASC, survey_product_id ASC `
 	o := orm.NewOrmUsingDB("edb")
-	_, err = o.Raw(sql).QueryRows(&items)
-
+	_, err = o.Raw(sql, breedIds).QueryRows(&items)
 	return
 }
 

+ 7 - 3
models/user_view_history.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hz_eta_api/utils"
 )
 
 type ResearchReportViewPUV struct {
@@ -11,7 +12,10 @@ type ResearchReportViewPUV struct {
 }
 
 // GetPUVByResearchReportIds 通过报告IDs获取老报告PV、UV
-func GetPUVByResearchReportIds(reportIds string) (list []*ResearchReportViewPUV, err error) {
+func GetPUVByResearchReportIds(reportIds []string) (list []*ResearchReportViewPUV, err error) {
+	if len(reportIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("weekly")
 	sql := `SELECT
 				research_report_id,
@@ -20,9 +24,9 @@ func GetPUVByResearchReportIds(reportIds string) (list []*ResearchReportViewPUV,
 			FROM
 				user_view_history
 			WHERE
-				research_report_id IN (` + reportIds + `)
+				research_report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)
 			GROUP BY
 				research_report_id`
-	_, err = o.Raw(sql).QueryRows(&list)
+	_, err = o.Raw(sql, reportIds).QueryRows(&list)
 	return
 }

+ 7 - 3
models/variety_tag.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hz_eta_api/utils"
 	"time"
 )
 
@@ -173,7 +174,10 @@ type AdminVarietyTagRelationList struct {
 }
 
 // GetAdminVarietyTagRelationListByAdminId 获取研究员研究方向分组列表
-func GetAdminVarietyTagRelationListByAdminId(adminIds string) (list []*AdminVarietyTagRelationList, err error) {
+func GetAdminVarietyTagRelationListByAdminId(adminIds []int) (list []*AdminVarietyTagRelationList, err error) {
+	if len(adminIds) == 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("weekly")
 	sql := `SELECT
 				a.admin_id,
@@ -182,9 +186,9 @@ func GetAdminVarietyTagRelationListByAdminId(adminIds string) (list []*AdminVari
 				research_variety_tag_relation AS a
 			INNER JOIN variety_tag AS b ON a.variety_tag_id = b.variety_tag_id
 			WHERE
-				a.admin_id IN (` + adminIds + `)
+				a.admin_id IN (` + utils.GetOrmInReplace(len(adminIds)) + `)
 			GROUP BY
 				a.admin_id`
-	_, err = o.Raw(sql).QueryRows(&list)
+	_, err = o.Raw(sql, adminIds).QueryRows(&list)
 	return
 }

+ 13 - 3
services/report.go

@@ -245,9 +245,9 @@ func PublishDayWeekReport(reportId int) (tips string, err error) {
 		report.ModifyTime = time.Now().Local()
 	}
 	publishIdStr := utils.IntArr2joinString(publishIdArr, ",")
-	unPublishIdStr := utils.IntArr2joinString(unPublishIdArr, ",")
+	//unPublishIdStr := utils.IntArr2joinString(unPublishIdArr, ",")
 
-	if e := models.PublishReportAndChapter(report, publishIdStr, unPublishIdStr, publishReport, updateCols); e != nil {
+	if e := models.PublishReportAndChapter(report, publishIdArr, unPublishIdArr, publishReport, updateCols); e != nil {
 		err = errors.New("发布报告及章节失败")
 		return
 	}
@@ -273,7 +273,17 @@ func UpdateChaptersVideo(chapterIds string) (err error) {
 	if chapterIds == "" {
 		return
 	}
-	chapterList, err := models.GetChapterListByChapterIds(chapterIds)
+	ids := make([]int, 0)
+	chapterIdArr := strings.Split(chapterIds, ",")
+	for _, v := range chapterIdArr {
+		id, e := strconv.Atoi(v)
+		if e != nil {
+			return
+		}
+		ids = append(ids, id)
+	}
+
+	chapterList, err := models.GetChapterListByChapterIds(ids)
 	if err != nil {
 		return
 	}

+ 0 - 1
services/task.go

@@ -31,7 +31,6 @@ func Task() {
 	//data.GetSmmIndex()
 	//data.GetSmmIndexData()
 	go AutoInsertLogToDB()
-	// TODO:确定晨报在新后台撰写之后打开, 防止误写之后被自动推送
 
 	//手工数据表格导入后的指标库刷新
 	go ImportManualDataRefresh()