Browse Source

Merge remote-tracking branch 'origin/eta/2.0.0'

Roc 6 months ago
parent
commit
fbebf9f492

+ 6 - 1
controllers/data_manage/manual_edb.go

@@ -330,6 +330,9 @@ func (c *ManualEdbController) EdbList() {
 	var condition string
 	var pars []interface{}
 
+	// 权限用户id
+	permissionUserId := sysUser.AdminId
+
 	//超管账号可以查看分类下的所有频度数据
 	if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
 		classifyIdList, err := data.GetUserManualClassifyIdList(sysUser.AdminId)
@@ -344,6 +347,8 @@ func (c *ManualEdbController) EdbList() {
 			pars = append(pars, classifyIdList)
 		}
 
+	} else {
+		permissionUserId = 0
 	}
 
 	// 关键词
@@ -359,7 +364,7 @@ func (c *ManualEdbController) EdbList() {
 	// 所属分类
 	if classifyId > 0 {
 		// 获取有用权限的分类
-		classifyList, err := models.GetEdbdataClassify(int64(userId))
+		classifyList, err := models.GetEdbdataClassify(int64(permissionUserId))
 		if err != nil {
 			return
 		}

+ 83 - 43
controllers/target.go

@@ -953,7 +953,7 @@ func (this *TargetController) ExportDataList() {
 
 	var condition string
 	var pars []interface{}
-	//分类ID
+	// 指标名称
 	if keyWord != "" {
 		condition += ` AND  a.SEC_NAME LIKE '%` + keyWord + `%'`
 	}
@@ -975,10 +975,45 @@ func (this *TargetController) ExportDataList() {
 	//	condition += ` AND a.frequency = ? `
 	//	pars = append(pars, frequency)
 	//}
+	permissionUserId := sysUser.AdminId
+	if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
+		permissionUserId = 0
+	}
+
+	childClassifyIdList := make([]int, 0)
+	// 所属分类
 	if classifyId > 0 {
-		condition += ` AND a.classify_id = ? `
-		pars = append(pars, classifyId)
+		// 获取有用权限的分类
+		classifyList, err := models.GetEdbdataClassify(int64(permissionUserId))
+		if err != nil {
+			return
+		}
+
+		var isParent bool
+		for _, v := range classifyList {
+			if v.ClassifyId == classifyId {
+				isParent = true
+				childClassifyIdList = append(childClassifyIdList, v.ClassifyId)
+				if v.Child != nil && len(v.Child) > 0 {
+					for _, vv := range v.Child {
+						childClassifyIdList = append(childClassifyIdList, vv.ClassifyId)
+					}
+				}
+				break
+			}
+		}
+
+		// 如果是最小级,那么就把自己放进去
+		if !isParent {
+			childClassifyIdList = append(childClassifyIdList, classifyId)
+		}
 	}
+
+	// 如果所选分类是一级时,那么是一级下的所有分类;如果是二级时,那么是二级自己本身
+	num := len(childClassifyIdList)
+	condition += ` AND a.classify_id in (` + utils.GetOrmInReplace(num) + `) `
+	pars = append(pars, childClassifyIdList)
+
 	if mobile != "" {
 		condition += ` AND d.mobile=? `
 		pars = append(pars, mobile)
@@ -999,28 +1034,39 @@ func (this *TargetController) ExportDataList() {
 	dir, _ := os.Executable()
 	exPath := filepath.Dir(dir)
 
-	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	downloadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
 	xlsxFile := xlsx.NewFile()
 	if err != nil {
 		br.Msg = "生成文件失败"
 		br.ErrMsg = "生成文件失败"
 		return
 	}
-	var frequencies []*string
-	if keyWord == "" {
-		frequencies, err = models.GetEdbDataFrequency(classifyId)
+	var frequencies []string
+	if len(childClassifyIdList) > 0 {
+		frequencies, err = models.GetEdbDataFrequencyByClassifyIdList(childClassifyIdList)
 		if err != nil {
 			br.Msg = "查询频度失败"
 			br.ErrMsg = "查询频度失败"
 			return
 		}
-	} else {
+	} else if tradeCode != `` {
+		manualEdb, err := models.GetEdbinfoByTradeCode(tradeCode)
+		if err != nil {
+			br.Msg = "查询指标信息失败"
+			br.ErrMsg = "查询指标信息失败,err:" + err.Error()
+			return
+		}
+		frequencies = append(frequencies, manualEdb.Frequency)
+	} else if keyWord != `` {
 		frequencies, err = models.GetEdbDataFrequencyByKeyord(keyWord)
 		if err != nil {
 			br.Msg = "查询频度失败"
 			br.ErrMsg = "查询频度失败"
 			return
 		}
+	} else {
+		// 啥也没选的情况下
+		frequencies = append(frequencies, `日度`, `周度`, `月度`, `季度`, `半年度`, `年度`)
 	}
 
 	fileName := `手工数据`
@@ -1052,7 +1098,7 @@ func (this *TargetController) ExportDataList() {
 		}
 		var sheet *xlsx.Sheet
 		if len(secNameList) > 0 {
-			sheet, err = xlsxFile.AddSheet(*frequency)
+			sheet, err = xlsxFile.AddSheet(frequency)
 			if err != nil {
 				br.Msg = "新增Sheet失败"
 				br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
@@ -1129,7 +1175,7 @@ func (this *TargetController) ExportDataList() {
 
 	}
 
-	err = xlsxFile.Save(downLoadnFilePath)
+	err = xlsxFile.Save(downloadFilePath)
 	if err != nil {
 		//有指标无数据时先导出一遍空表
 		sheet, err := xlsxFile.AddSheet("无数据")
@@ -1141,19 +1187,20 @@ func (this *TargetController) ExportDataList() {
 		rowSecName := sheet.AddRow()
 		celSecName := rowSecName.AddCell()
 		celSecName.SetValue("")
-		err = xlsxFile.Save(downLoadnFilePath)
+		err = xlsxFile.Save(downloadFilePath)
 		if err != nil {
 			br.Msg = "保存文件失败"
 			br.ErrMsg = "保存文件失败"
 			return
 		}
 	}
-
-	fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
-	this.Ctx.Output.Download(downLoadnFilePath, fileName)
 	defer func() {
-		os.Remove(downLoadnFilePath)
+		os.Remove(downloadFilePath)
 	}()
+
+	fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
+	this.Ctx.Output.Download(downloadFilePath, fileName)
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "success"
@@ -3302,22 +3349,8 @@ func (this *TargetController) ExcelDataAdd() {
 	userId := sysUser.AdminId
 	if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
 		userId = 0
-
-		// 校验下当前用户是否有该指标的权限
-		count, err := models.GetCountManualUserClassify(sysUser.AdminId, req.ClassifyId)
-		if err != nil {
-			br.Msg = "获取分类数据失败"
-			br.ErrMsg = "获取分类数据失败,err:" + err.Error()
-			return
-		}
-
-		if count <= 0 {
-			br.Msg = "无权访问"
-			br.ErrMsg = "无权访问"
-			br.IsSendEmail = false
-			return
-		}
 	}
+
 	//获取账户所拥有权限的分类id集合
 	classifyIdList, err := data.GetUserManualClassifyIdList(userId)
 	if err != nil {
@@ -3325,6 +3358,12 @@ func (this *TargetController) ExcelDataAdd() {
 		br.Msg = "获取拥有的分类数据失败,Err:" + err.Error()
 		return
 	}
+	if !utils.InArrayByInt(classifyIdList, req.ClassifyId) {
+		br.Msg = "无权访问"
+		br.ErrMsg = "无权访问"
+		br.IsSendEmail = false
+		return
+	}
 
 	//操作指标,新增指标及数据等
 	{
@@ -3413,6 +3452,20 @@ func (this *TargetController) ExcelDataAdd() {
 						continue
 					}
 
+					// 指标信息变更,需要更新
+					if frequency != target.Frequency || unit != target.Unit || req.ClassifyId != target.ClassifyId {
+						fmt.Println("更新指标频度或单位")
+						err = models.ModifyEdbinfo(target.TradeCode, unit, frequency, req.ClassifyId)
+						if err != nil {
+							fmt.Println("EditEdbinfo err:", err.Error())
+							return
+						}
+						// 指标信息变更
+						if _, isAdd := addEdbTradeMap[target.TradeCode]; !isAdd {
+							updateEdbTradeMap[target.TradeCode] = true
+						}
+					}
+
 					//判断指标数据是否已经存在
 					tmpDataMap, ok2 := edbCodeDataMap[target.TradeCode]
 					if !ok2 {
@@ -3468,19 +3521,6 @@ func (this *TargetController) ExcelDataAdd() {
 							// 指标数据变更
 							updateDataTradeMap[target.TradeCode] = true
 						}
-
-						if frequency != target.Frequency || unit != target.Unit || req.ClassifyId != target.ClassifyId {
-							fmt.Println("更新指标频度或单位")
-							err = models.ModifyEdbinfo(target.TradeCode, unit, frequency, req.ClassifyId)
-							if err != nil {
-								fmt.Println("EditEdbinfo err:", err.Error())
-								return
-							}
-							// 指标信息变更
-							if _, isAdd := addEdbTradeMap[target.TradeCode]; !isAdd {
-								updateEdbTradeMap[target.TradeCode] = true
-							}
-						}
 					} else { //数据不存在,进行新增操作
 						if target.TradeCode != "" && createDate != "" && closeVal != "" {
 							fmt.Println("新增")

+ 3 - 3
models/data_manage/excel/excel_edb_mapping.go

@@ -141,12 +141,12 @@ func GetExcelEdbMappingByEdbInfoIdAndSource(edbInfoId int, sources []int) (items
 // @Description: 根据指标id删除与自定义分析表格的关系
 // @author: Roc
 // @datetime 2023-11-02 13:20:02
-// @param excelInfoId int
+// @param edbInfoId int
 // @return err error
-func DeleteCustomAnalysisExcelEdbMappingByEdbInfoId(excelInfoId int) (err error) {
+func DeleteCustomAnalysisExcelEdbMappingByEdbInfoId(edbInfoId int) (err error) {
 	o := orm.NewOrmUsingDB("data")
 	sql := `DELETE FROM excel_edb_mapping WHERE source = ? AND edb_info_id = ? LIMIT 1`
-	_, err = o.Raw(sql, utils.CUSTOM_ANALYSIS_TABLE, excelInfoId).Exec()
+	_, err = o.Raw(sql, utils.CUSTOM_ANALYSIS_TABLE, edbInfoId).Exec()
 
 	return
 }

+ 3 - 3
models/manual_edb.go

@@ -104,7 +104,7 @@ type EdbListResp struct {
 // @return err error
 func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfoListItem, err error) {
 	o := orm.NewOrmUsingDB("edb")
-	sql := `SELECT DISTINCT a.* FROM edbinfo AS a  WHERE a.REMARK='手动' `
+	sql := `SELECT DISTINCT a.* FROM edbinfo AS a  WHERE a.classify_id > 0 `
 	if condition != "" {
 		sql += condition
 	}
@@ -130,7 +130,7 @@ func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize in
 // @return err error
 func GetCountEdbInfoList(condition string, pars []interface{}) (total int, err error) {
 	o := orm.NewOrmUsingDB("edb")
-	sql := `SELECT COUNT(1) ct FROM edbinfo AS a  WHERE a.REMARK='手动' `
+	sql := `SELECT COUNT(1) ct FROM edbinfo AS a  WHERE a.classify_id > 0 `
 	if condition != "" {
 		sql += condition
 	}
@@ -167,7 +167,7 @@ func DelEdbdataByCodeAndDateList(tradeCode string, dateList []string) (err error
 	}
 
 	o := orm.NewOrmUsingDB("edb")
-	sql := `delete from  edbdata AS a  WHERE a.TRADE_CODE=? and DT in (` + utils.GetOrmInReplace(num) + `) `
+	sql := `delete from edbdata  WHERE TRADE_CODE=? AND DT in (` + utils.GetOrmInReplace(num) + `) `
 	_, err = o.Raw(sql, tradeCode, dateList).Exec()
 
 	return

+ 40 - 22
models/target.go

@@ -36,7 +36,7 @@ func GetDataList(condition string, pars []interface{}, startSize, pageSize int)
 	sql := `select a.TRADE_CODE,a.SEC_NAME,a.UNIT,a.frequency,a.classify_id,b.classify_name,c.DT,c.CLOSE,c.modify_time FROM edbdata AS c
                 inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
                 left join edbdata_classify AS b ON a.classify_id=b.classify_id
-                where left(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
+                where a.classify_id>0`
 	if condition != "" {
 		sql += condition
 	}
@@ -50,7 +50,7 @@ func GetDataListCount(condition string, pars []interface{}) (count int, err erro
 	sql := ` select count(1) as count FROM edbdata AS c
                     inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE    
                     left join edbdata_classify AS b ON a.classify_id=b.classify_id
-                    where left(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
+                    where a.classify_id>0 `
 	if condition != "" {
 		sql += condition
 	}
@@ -191,14 +191,14 @@ func GetEdbinfoListCount(condition string, pars []interface{}, mobile string, ro
 	if mobile != "" && roleType == 1 {
 		sql = `SELECT COUNT(1) AS count FROM edbinfo AS a 
              INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
-             WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
+             WHERE a.classify_id>0`
 
 		if condition != "" {
 			sql += condition
 		}
 		err = o.Raw(sql, mobile, pars).QueryRow(&count)
 	} else {
-		sql := `SELECT COUNT(1) AS count FROM edbinfo AS a WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
+		sql := `SELECT COUNT(1) AS count FROM edbinfo AS a WHERE a.classify_id>0`
 
 		if condition != "" {
 			sql += condition
@@ -234,7 +234,7 @@ func GetEdbinfoItemList(condition string, pars []interface{}, startSize, pageSiz
 		sql = ` SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
                     LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
                     INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
-                    WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
+                    WHERE a.classify_id>0`
 		if condition != "" {
 			sql += condition
 		}
@@ -243,7 +243,7 @@ func GetEdbinfoItemList(condition string, pars []interface{}, startSize, pageSiz
 	} else {
 		sql = `SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
                      LEFT JOIN edbdata_classify AS b on a.classify_id=b.classify_id
-                     WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
+                     WHERE a.classify_id>0`
 		if condition != "" {
 			sql += condition
 		}
@@ -296,7 +296,7 @@ type EdbinfoAddReq struct {
 
 // GetMaxTradeCode 获取指标最大trade_code
 func GetMaxTradeCode() (max_trade_code string, err error) {
-	sql := " SELECT MAX(TRADE_CODE) AS max_trade_code FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' AND TRADE_CODE not like '%index%' and TRADE_CODE NOT LIKE 'WDC%'"
+	sql := " SELECT MAX(TRADE_CODE) AS max_trade_code FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' "
 	o := orm.NewOrmUsingDB("edb")
 	err = o.Raw(sql).QueryRow(&max_trade_code)
 	if (err != nil && err.Error() == utils.ErrNoRow()) || max_trade_code == `` {
@@ -306,7 +306,7 @@ func GetMaxTradeCode() (max_trade_code string, err error) {
 }
 
 func GetEdbinfoBySecName(secName string) (item *Edbinfo, err error) {
-	sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' `
+	sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? `
 	o := orm.NewOrmUsingDB("edb")
 	err = o.Raw(sql, secName).QueryRow(&item)
 	return
@@ -367,7 +367,7 @@ func EditEdbinfo(tradeCode, secName, unit, frequency, noticeTime string, classif
 func SearchTargetEntry(classifyId int, keyWord string) (items []*Edbinfo, err error) {
 	where := ""
 	pars := make([]interface{}, 0)
-	sql := `SELECT * FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' AND REMARK='手动' AND classify_id>0 AND classify_id=? `
+	sql := `SELECT * FROM edbinfo WHERE classify_id>0 AND classify_id=? `
 	pars = append(pars, classifyId)
 	if keyWord != "" {
 		sql += `AND SEC_NAME LIKE ? `
@@ -471,7 +471,7 @@ type EdbdataClassifyResp struct {
 }
 
 func GetTargetBySecName(secName string) (item *Edbinfo, err error) {
-	sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' `
+	sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? `
 	o := orm.NewOrmUsingDB("edb")
 	err = o.Raw(sql, secName).QueryRow(&item)
 	return
@@ -580,7 +580,7 @@ func GetDataListForExport(startDate, endDate, frequency, keyWord string, classif
 	sql := ` SELECT a.TRADE_CODE,a.SEC_NAME,a.UNIT,a.frequency,a.classify_id,b.classify_name,c.DT,c.CLOSE FROM edbdata AS c
                 INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
                 LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
-                WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
+                WHERE a.classify_id>0 `
 	if where != "" {
 		sql += where
 	}
@@ -676,7 +676,7 @@ func GetResearcherEntry() (items []*Researcher, err error) {
 		mobile := items[i].Mobile
 		sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM  edbinfo_user AS a
             INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
-            WHERE a.mobile=? AND LEFT(b.TRADE_CODE,1)='W' AND b.REMARK='手动' AND b.classify_id>0 `
+            WHERE a.mobile=? AND b.classify_id>0 `
 		err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
 		items[i].TargetCount = count
 	}
@@ -697,7 +697,7 @@ func GetResearcherEntryByMobile(mobile string) (items []*Researcher, err error)
 		mobile := items[i].Mobile
 		sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM  edbinfo_user AS a
             INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
-            WHERE a.mobile=? AND LEFT(b.TRADE_CODE,1)='W' AND b.REMARK='手动' AND b.classify_id>0 `
+            WHERE a.mobile=? AND b.classify_id>0 `
 		err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
 		items[i].TargetCount = count
 	}
@@ -729,10 +729,10 @@ type SortEdbInfo []EdbinfoItems
 func GetTargetItems(mobile string, classifyId int) (lastItems SortEdbInfo, err error) {
 	var items []*EdbinfoItems
 	o := orm.NewOrmUsingDB("edb")
-	//sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
+	//sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE a.classify_id>0 `
 
 	sql := ` SELECT *,'' modify_date,'' STATUS FROM edbinfo AS a 
-            WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0
+            WHERE a.classify_id>0
              `
 	if classifyId > 0 {
 		sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ``
@@ -741,7 +741,7 @@ func GetTargetItems(mobile string, classifyId int) (lastItems SortEdbInfo, err e
 
 	//if classifyId > 0 {
 	//	sql = ` SELECT *,'' modify_date,'' status FROM edbinfo AS a
-	//        WHERE a.classify_id=` + strconv.Itoa(classifyId) + ` AND LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0
+	//        WHERE a.classify_id=` + strconv.Itoa(classifyId) + ` AND a.classify_id>0
 	//         GROUP BY a.TRADE_CODE `
 	//}
 
@@ -1035,12 +1035,12 @@ func GetEdbdataSecName(condition string, pars []interface{}) (items []*EdbdataEx
 	//	        INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
 	//	        INNER JOIN edbinfo_user AS d ON a.TRADE_CODE=d.TRADE_CODE
 	//	        LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
-	//	        WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
+	//	        WHERE a.classify_id>0`
 	sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt,b.classify_name
 		        FROM edbdata AS c
 		        INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
 		        LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
-		        WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
+		        WHERE a.classify_id>0`
 	if condition != "" {
 		sql += condition
 	}
@@ -1057,7 +1057,25 @@ func GetEdbDataFrequency(classifyId int) (items []*string, err error) {
 	return
 }
 
-func GetEdbDataFrequencyByKeyord(keyword string) (items []*string, err error) {
+// GetEdbDataFrequencyByClassifyIdList
+// @Description: 根据分类列表获取所有的频度
+// @author: Roc
+// @datetime 2024-08-15 17:51:13
+// @param classifyIdList []int
+// @return items []*string
+// @return err error
+func GetEdbDataFrequencyByClassifyIdList(classifyIdList []int) (items []string, err error) {
+	num := len(classifyIdList)
+	if num <= 0 {
+		return
+	}
+	sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id in (` + utils.GetOrmInReplace(num) + `) AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
+	o := orm.NewOrmUsingDB("edb")
+	_, err = o.Raw(sql, classifyIdList).QueryRows(&items)
+	return
+}
+
+func GetEdbDataFrequencyByKeyord(keyword string) (items []string, err error) {
 	sql := `SELECT DISTINCT frequency FROM edbinfo where SEC_NAME=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
 	o := orm.NewOrmUsingDB("edb")
 	_, err = o.Raw(sql, keyword).QueryRows(&items)
@@ -1279,7 +1297,7 @@ func GetTargetItemList(classifyId, edbShowType int, frequency, keyword, tradeCod
 		sql = ` SELECT a.*,b.DT,'' modify_date,'' STATUS FROM edbinfo AS a 
 left join edbdata b on a.TRADE_CODE=b.TRADE_CODE `
 	}
-	sql += ` WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
+	sql += ` WHERE a.classify_id>0 `
 
 	//如果没有分类id集合列表,那么就没有数据了,不用往下执行了,直接返回好了
 	if len(classifyIdStrList) <= 0 {
@@ -1432,7 +1450,7 @@ func GetEdbInfoCountByClassifyId(classifyId int) (count int, err error) {
 	o := orm.NewOrmUsingDB("edb")
 	sql := `SELECT COUNT(1) AS count FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a 
              INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
-             WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id=? group by a.TRADE_CODE) d `
+             WHERE a.classify_id=? group by a.TRADE_CODE) d `
 	err = o.Raw(sql, classifyId).QueryRow(&count)
 	return
 }
@@ -1448,7 +1466,7 @@ func GetEdbInfoGroupCountByClassifyIds(classifyIds string) (list []*EdbInfoGroup
 	o := orm.NewOrmUsingDB("edb")
 	sql := `SELECT COUNT(1) AS count,classify_id FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a 
              INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
-             WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' and a.classify_id in (` + classifyIds + `) group by a.TRADE_CODE) d 
+             WHERE a.classify_id in (` + classifyIds + `) group by a.TRADE_CODE) d 
 						 GROUP BY classify_id `
 	_, err = o.Raw(sql).QueryRows(&list)
 	return

+ 28 - 5
services/data/manual.go

@@ -285,16 +285,29 @@ func ImportManualData(path string, sysUser *system.Admin) (successCount, failCou
 			err = errors.New(errMsg)
 			return
 		}
+
+		templateType := 1 // 模板类型
+		minCellNum := 6   // 模板最小列数
 		headerCell := rowList[0].Cells
-		if len(headerCell) < 7 {
+
+		// 确定模板
+		for _, v := range headerCell {
+			if v.String() == "导入模板2/Import Template 2" {
+				templateType = 2
+				minCellNum = 2
+				break
+			}
+		}
+
+		// 如果小于最少列数,则报错
+		if len(headerCell) < minCellNum {
 			errMsg = sheet.Name + "页模板异常"
 			err = errors.New(errMsg)
 			return
 		}
 
-		templateName := headerCell[6].String()
-		switch templateName {
-		case "导入模板2/Import Template 2":
+		switch templateType {
+		case 2:
 			// 模板2需要走对应的取数逻辑
 			tmpIndexDataList, tmpFailDataList, err, errMsg = getDataByTemplate2(sheet, sysUser.AdminId)
 		default:
@@ -695,7 +708,17 @@ func getDataByTemplate1(sheet *xlsx.Sheet, sysUserId int) (indexDataList []Impor
 	for i := 2; i < maxRow; i++ {
 		row := sheet.Row(i)
 		cells := row.Cells
-		if len(cells) < 6 {
+		lenCell := len(cells)
+
+		// 过滤空白行
+		if lenCell <= 0 {
+			continue
+		}
+
+		if lenCell < 6 {
+			if cells[0].Value == `` {
+				continue
+			}
 			errMsg = "导入文件异常,请下载最新导入模板文件"
 			err = errors.New(errMsg)
 			return

BIN
static/template/导入模板1.xlsx