Pārlūkot izejas kodu

Merge branch '13.9' into debug

# Conflicts:
#	models/chart.go
Roc 2 gadi atpakaļ
vecāks
revīzija
48b330fe96
4 mainītis faili ar 375 papildinājumiem un 65 dzēšanām
  1. 3 3
      controllers/chart_common.go
  2. 10 7
      models/chart.go
  3. 340 55
      services/data/future_good/chart_info.go
  4. 22 0
      utils/common.go

+ 3 - 3
controllers/chart_common.go

@@ -140,7 +140,7 @@ func GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key
 	// 商品价格曲线图的一些配置
 	var barConfig data_manage.BarChartInfoReq
 	barChartInfoDateList := make([]data_manage.BarChartInfoDateReq, 0)
-	barChartInfoSort := data_manage.BarChartInfoSortReq{}
+	//barChartInfoSort := data_manage.BarChartInfoSortReq{}
 
 	if chartInfo.BarConfig == `` {
 		msg = "商品价格曲线图未配置"
@@ -155,10 +155,10 @@ func GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key
 	}
 
 	barChartInfoDateList = barConfig.DateList
-	barChartInfoSort = barConfig.Sort
+	//barChartInfoSort = barConfig.Sort
 
 	// 获取图表中的指标数据
-	barConfigEdbInfoIdList, edbList, xEdbIdValue, xDataList, yDataList, err := future_goodServ.GetChartEdbData(chartInfoId, startDate, endDate, edbInfoMapping, futureGoodEdbInfoMapping, barChartInfoDateList, barChartInfoSort)
+	barConfigEdbInfoIdList, edbList, xEdbIdValue, xDataList, yDataList, err := future_goodServ.GetChartEdbData(chartInfoId, startDate, endDate, edbInfoMapping, futureGoodEdbInfoMapping, barChartInfoDateList)
 	if err != nil {
 		msg = "获取失败"
 		errMsg = "获取图表,指标信息失败,Err:" + err.Error()

+ 10 - 7
models/chart.go

@@ -173,13 +173,16 @@ type XData struct {
 
 // YData 柱方图的y轴数据
 type YData struct {
-	Date           string    `description:"数据日期"`
-	Color          string    `description:"数据颜色"`
-	Name           string    `description:"别名"`
-	NameEn         string    `description:"英文别名"`
-	Value          []float64 `description:"每个指标的值"`
-	NoDataEdbList  []int     `description:"没有数据的指标列表"`
-	XEdbInfoIdList []int     `description:"对应X轴的指标id列表"`
+	Date           string          `description:"数据日期"`
+	ConfigDate     time.Time       `description:"配置的日期" json:"-"`
+	Color          string          `description:"数据颜色"`
+	Name           string          `description:"别名"`
+	NameEn         string          `description:"英文别名"`
+	Value          []float64       `description:"每个指标的值"`
+	NoDataEdbList  []int           `description:"没有数据的指标列表"`
+	XEdbInfoIdList []int           `description:"对应X轴的指标id列表"`
+	EdbValMap      map[int]float64 `description:"指标与值的对应" json:"-"`
+	M              []int           `description:"对应开始日期的间隔值" json:"-"`
 }
 
 // RollingCorrelationChartDataResp 滚动相关性图

+ 340 - 55
services/data/future_good/chart_info.go

@@ -10,12 +10,13 @@ import (
 	"hongze/hongze_chart_lib/services/alarm_msg"
 	"hongze/hongze_chart_lib/services/data"
 	"hongze/hongze_chart_lib/utils"
+	"sort"
 	"strconv"
 	"time"
 )
 
 // GetChartEdbData 获取图表的指标数据
-func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping, futureGoodEdbInfoMapping *models.ChartEdbInfoMapping, barChartInfoDateList []data_manage.BarChartInfoDateReq, barChartInfoSort data_manage.BarChartInfoSortReq) (barConfigEdbInfoIdList []data_manage.BarChartInfoEdbItemReq, edbList []*models.ChartEdbInfoMapping, xEdbIdValue []int, xDataList []models.XData, yDataList []models.YData, err error) {
+func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping, futureGoodEdbInfoMapping *models.ChartEdbInfoMapping, barChartInfoDateList []data_manage.BarChartInfoDateReq) (barConfigEdbInfoIdList []data_manage.BarChartInfoEdbItemReq, edbList []*models.ChartEdbInfoMapping, xEdbIdValue []int, xDataList []models.XData, yDataList []models.YData, err error) {
 	edbList = make([]*models.ChartEdbInfoMapping, 0)
 
 	if futureGoodEdbInfoMapping == nil {
@@ -120,41 +121,10 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
 		return
 	}
 
-	maxM := 36
-	futureGoodEdbInfoList := make([]*future_good.FutureGoodEdbInfo, 0)
 	latestDateTime, _ := time.ParseInLocation(utils.FormatDate, latestDate, time.Local)
-
-	for _, v := range tmpFutureGoodEdbInfoList {
-		if v.RegionType == `国内` {
-			futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
-			continue
-		}
-		//海外的连续日期,目前
-		if v.FutureGoodEdbType == 2 {
-			if v.Month <= maxM {
-				addMonth := int(latestDateTime.Month()) + v.Month
-				v.Year = latestDateTime.Year() + addMonth/12
-				realMonth := addMonth % 12
-				if realMonth == 0 {
-					realMonth = 12
-				}
-				v.Month = realMonth
-				futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
-			}
-			continue
-		}
-
-		// 小于等于当前年,那么就肯定是ok的
-		if v.Year <= latestDateTime.Year() {
-			futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
-			continue
-		}
-		// 如果(当前年-最新日期的年份) * 12个月 + (当前月-最新日期的月份) 小于总月份
-		if (v.Year-latestDateTime.Year())*12+(v.Month-int(latestDateTime.Month())) <= maxM {
-			futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
-			continue
-		}
-
+	_, futureGoodEdbInfoList, err := getFutureGoodEdbInfoList(latestDateTime, tmpFutureGoodEdbInfoList, barChartInfoDateList)
+	if err != nil {
+		return
 	}
 
 	futureGoodMappingList := make([]*models.ChartEdbInfoMapping, 0)
@@ -231,6 +201,7 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
 	}
 
 	edbList = append(edbList, futureGoodMappingList...)
+
 	xEdbIdValue, yDataList, err = BarChartData(edbList[0], futureGoodEdbInfoList, edbDataListMap, barChartInfoDateList, regionType, latestDate)
 
 	xDataList = []models.XData{
@@ -239,23 +210,109 @@ func GetChartEdbData(chartInfoId int, startDate, endDate string, edbInfoMapping,
 			NameEn: "Spot Price",
 		},
 	}
-	if regionType == `国内` {
-		for i := range futureGoodEdbInfoList {
-			xDataList = append(xDataList, models.XData{
-				Name:   fmt.Sprint("M+", i),
-				NameEn: fmt.Sprint("M+ ", i),
-			})
+	//yDataList =make([]data_manage.YData,0)
+	//data_manage.YData{
+	//	Date:           "",
+	//	Color:          "",
+	//	Name:           "",
+	//	NameEn:         "",
+	//	Value:          nil,
+	//	NoDataEdbList:  nil,
+	//	XEdbInfoIdList: nil,
+	//}
+	futureGoodEdbInfoIndexMap := make(map[int]int)
+	for index, v := range futureGoodEdbInfoList {
+		futureGoodEdbInfoIndexMap[v.FutureGoodEdbInfoId] = index
+	}
+	nMap := make(map[int]int)
+	maxIndex := 0 // 最大x轴的下标
+	for k, tmpYData := range yDataList {
+		yDataMap := tmpYData.EdbValMap
+		edbInfoIdList := make([]int, 0)
+		noDataEdbInfoIdList := make([]int, 0)
+		valueList := make([]float64, 0)
+		noDataEdbIdMap := make(map[int]int)
+
+		// 所有的N值
+		for _, n := range tmpYData.M {
+			nMap[n] = n
 		}
-	} else {
-		for _, v := range futureGoodEdbInfoList {
-			divMonth := (v.Year-latestDateTime.Year())*12 + (v.Month - int(latestDateTime.Month()))
-			xDataList = append(xDataList, models.XData{
-				Name:   fmt.Sprint("M+", divMonth),
-				NameEn: fmt.Sprint("M+ ", divMonth),
-			})
+
+		// 基础指标
+		{
+			baseEdbInfId := edbList[0].EdbInfoId
+			edbInfoIdList = append(edbInfoIdList, baseEdbInfId)
+			tmpVal, ok := yDataMap[baseEdbInfId]
+			valueList = append(valueList, tmpVal)
+			if !ok || tmpVal == 0 {
+				noDataEdbInfoIdList = append(noDataEdbInfoIdList, baseEdbInfId)
+				noDataEdbIdMap[baseEdbInfId] = baseEdbInfId
+			}
+		}
+
+		for _, futureGoodEdbInfo := range futureGoodEdbInfoList {
+			tmpEdbInfId := futureGoodEdbInfo.FutureGoodEdbInfoId
+			edbInfoIdList = append(edbInfoIdList, tmpEdbInfId)
+			tmpVal, ok := yDataMap[tmpEdbInfId]
+			valueList = append(valueList, tmpVal)
+			if !ok || tmpVal == 0 {
+				noDataEdbInfoIdList = append(noDataEdbInfoIdList, tmpEdbInfId)
+				noDataEdbIdMap[tmpEdbInfId] = tmpEdbInfId
+			}
+		}
+		//tmpYData.Value = valueList
+		tmpYData.NoDataEdbList = noDataEdbInfoIdList
+		yDataList[k] = tmpYData
+
+		lenEdbId := len(edbInfoIdList)
+		tmpMaxIndex := lenEdbId - 1 // 当前数据的最大x轴的下标
+
+		for i := lenEdbId - 1; i >= 0; i-- {
+			// 如果没有在无数据的指标列表中找到,那么就找到了最大x轴的下标
+			if _, ok := noDataEdbIdMap[edbInfoIdList[i]]; !ok {
+				// 如果最大x轴的下标 小于 当前下标,那么就重新赋值
+				if maxIndex < i-1 {
+					maxIndex = i - 1
+				}
+				break
+			}
+
+			tmpMaxIndex = i - 1
+		}
+
+		// 如果最大x轴的下标 小于 当前下标,那么就重新赋值
+		if maxIndex < tmpMaxIndex {
+			maxIndex = tmpMaxIndex
+		}
+	}
+
+	//xEdbIdValue = xEdbIdValue[0:maxIndex]
+
+	// 找出所有的N值,并进行正序排列
+	nList := make([]int, 0)
+	for _, n := range nMap {
+		nList = append(nList, n)
+	}
+	sort.Slice(nList, func(i, j int) bool {
+		return nList[i] < nList[j]
+	})
+
+	for k, v := range yDataList {
+		if len(v.XEdbInfoIdList) >= maxIndex+1 {
+			yDataList[k].XEdbInfoIdList = v.XEdbInfoIdList[0 : maxIndex+1]
+		}
+		if len(v.Value) >= maxIndex+1 {
+			yDataList[k].Value = v.Value[0 : maxIndex+1]
 		}
 	}
 
+	tmpXDataList, newYDataList, err := handleResultData(regionType, yDataList, futureGoodEdbInfoList, maxIndex)
+	if err != nil {
+		return
+	}
+	xDataList = append(xDataList, tmpXDataList...)
+	yDataList = newYDataList
+
 	return
 }
 
@@ -468,6 +525,7 @@ func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingL
 	yDataList = make([]models.YData, 0) //y轴的数据列表
 
 	for _, barChartInfoDate := range barChartInfoDateList {
+		yDataMap := make(map[int]float64)
 		var maxDate time.Time
 
 		var findDateTime time.Time
@@ -505,6 +563,7 @@ func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingL
 			return
 		}
 		findDataList = append(findDataList, findDataValue)
+		yDataMap[edbInfoMapping.EdbInfoId] = findDataValue
 		if isFind {
 			maxDate = realDateTime
 		} else {
@@ -514,30 +573,37 @@ func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingL
 		currMonth := findDateTime.Month() // 当前月份
 		currYear := findDateTime.Year()   // 当前年份
 		xEdbInfoIdList = append(xEdbInfoIdList, edbInfoMapping.EdbInfoId)
-
+		mList := make([]int, 0) // 间隔月份
 		indexList := make([]int, 0)
 		if regionType == `国内` {
 			for i := currMonth; i < 12; i++ {
 				indexList = append(indexList, int(i))
+				mList = append(mList, int(i-currMonth))
 			}
 			for i := 1; i < int(currMonth); i++ {
 				indexList = append(indexList, i)
+				mList = append(mList, 12+i-int(currMonth))
 			}
 		} else {
 			for i, v := range futureGoodMappingList {
-				if v.Year > currYear || (v.Year == currYear && v.Month >= int(currMonth)) {
+				if v.Year > currYear || (v.Year == currYear && v.Month > int(currMonth)) {
 					indexList = append(indexList, i)
+					mList = append(mList, (v.Year-currYear)*12+v.Month-int(currMonth))
 				}
 			}
 		}
 
 		for _, i := range indexList {
 			futureGoodMapping := futureGoodMappingList[i] // 当前的期货指标
-			tmpRealDateTime, tmpFindDataValue, tmpIsFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[futureGoodMapping.FutureGoodEdbInfoId], edbDataMap[futureGoodMapping.FutureGoodEdbInfoId])
-			if tmpErr != nil {
-				err = tmpErr
-				return
-			}
+			//tmpRealDateTime, tmpFindDataValue, tmpIsFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[futureGoodMapping.FutureGoodEdbInfoId], edbDataMap[futureGoodMapping.FutureGoodEdbInfoId])
+			//if tmpErr != nil {
+			//	err = tmpErr
+			//	return
+			//}
+			tmpRealDateTime := findDateTime
+			tmpFindDataValue, tmpIsFind := edbDataMap[futureGoodMapping.FutureGoodEdbInfoId][findDateTime.Format(utils.FormatDate)]
+			yDataMap[futureGoodMapping.FutureGoodEdbInfoId] = tmpFindDataValue
+
 			findDataList = append(findDataList, tmpFindDataValue)
 			if tmpIsFind {
 				if maxDate.IsZero() || maxDate.Before(tmpRealDateTime) {
@@ -601,12 +667,15 @@ func BarChartData(edbInfoMapping *models.ChartEdbInfoMapping, futureGoodMappingL
 
 		yDataList = append(yDataList, models.YData{
 			Date:           yDate,
+			ConfigDate:     findDateTime,
 			Value:          findDataList,
 			NoDataEdbList:  noDataIdList,
 			XEdbInfoIdList: xEdbInfoIdList,
 			Color:          barChartInfoDate.Color,
 			Name:           yName,
 			NameEn:         yNameEn,
+			EdbValMap:      yDataMap,
+			M:              mList,
 		})
 	}
 
@@ -689,3 +758,219 @@ func FutureGoodChartInfoRefresh(chartInfoId int) (err error) {
 
 	return
 }
+
+// handleResultData 处理成最终的结果数据
+func handleResultData(regionType string, yDataList []models.YData, futureGoodEdbInfoList []*future_good.FutureGoodEdbInfo, maxIndex int) (xDataList []models.XData, newYDataList []models.YData, err error) {
+	xDataList = make([]models.XData, 0)
+	newYDataList = yDataList
+
+	if regionType == `国内` {
+		for i := range futureGoodEdbInfoList {
+			if i > maxIndex {
+				break
+			}
+			xDataList = append(xDataList, models.XData{
+				Name:   fmt.Sprint("M+", i),
+				NameEn: fmt.Sprint("M+", i),
+			})
+		}
+		return
+	}
+
+	futureGoodEdbInfoMap := make(map[int]*future_good.FutureGoodEdbInfo)
+	for _, v := range futureGoodEdbInfoList {
+		futureGoodEdbInfoMap[v.FutureGoodEdbInfoId] = v
+	}
+
+	nMap := make(map[int]int)
+
+	for _, v := range yDataList {
+		findDateTime := v.ConfigDate
+		currMonth := findDateTime.Month() // 当前月份
+		currYear := findDateTime.Year()   // 当前年份
+		//v.XEdbInfoIdList
+		for edbInfoIndex, edbInfoId := range v.XEdbInfoIdList {
+			// 第一个不处理
+			if edbInfoIndex == 0 {
+				continue
+			}
+
+			futureGoodEdbInfo, ok := futureGoodEdbInfoMap[edbInfoId]
+			if !ok {
+				err = errors.New("找不到指标")
+				return
+			}
+			n := (futureGoodEdbInfo.Year-currYear)*12 + futureGoodEdbInfo.Month - int(currMonth)
+			nMap[n] = n
+		}
+
+	}
+
+	// 找出所有的N值,并进行正序排列
+	nList := make([]int, 0)
+	for _, n := range nMap {
+		nList = append(nList, n)
+	}
+	sort.Slice(nList, func(i, j int) bool {
+		return nList[i] < nList[j]
+	})
+
+	//prevMonth := 1
+
+	for _, n := range nList {
+		xDataList = append(xDataList, models.XData{
+			Name:   fmt.Sprint("M+", n),
+			NameEn: fmt.Sprint("M+", n),
+		})
+	}
+
+	for yIndex, yData := range yDataList {
+		newYDataList[yIndex].XEdbInfoIdList = []int{}
+		newYDataList[yIndex].Value = []float64{}
+		tmpNList := nList
+
+		//当前的主力合约
+		newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, yData.XEdbInfoIdList[0])
+		newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, yData.Value[0])
+
+		xEdbInfoIdList := yData.XEdbInfoIdList[1:]
+		currDataTime := yData.ConfigDate
+		valIndex := 1
+		needNum := 0
+		for _, n := range tmpNList {
+			if len(xEdbInfoIdList) > 0 {
+				edbInfoId := xEdbInfoIdList[0]
+				futureGoodEdbInfo, ok := futureGoodEdbInfoMap[edbInfoId]
+				if !ok {
+					err = errors.New("找不到指标")
+					return
+				}
+				// 当前距离最早的日期相差的N数
+				divMonth := (futureGoodEdbInfo.Year-currDataTime.Year())*12 + (futureGoodEdbInfo.Month - int(currDataTime.Month()))
+				if divMonth == n {
+					if needNum > 0 {
+						currVal := yData.Value[valIndex]
+						preVal := yData.Value[valIndex-1]
+						hcValDeci := decimal.NewFromFloat(currVal).Sub(decimal.NewFromFloat(preVal)).Div(decimal.NewFromInt(int64(needNum + 1)))
+
+						for tmpNum := 0; tmpNum < needNum; tmpNum++ {
+							newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, 0)
+
+							// 赋值平均值
+							tmpVal, _ := decimal.NewFromFloat(preVal).Add(hcValDeci.Mul(decimal.NewFromInt(int64(tmpNum + 1)))).RoundCeil(4).Float64()
+							newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, tmpVal)
+						}
+					}
+
+					newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, edbInfoId)
+					newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, yData.Value[valIndex])
+					valIndex++
+					needNum = 0
+					if len(xEdbInfoIdList) > 0 {
+						xEdbInfoIdList = xEdbInfoIdList[1:]
+					}
+				} else {
+					needNum++
+				}
+			}
+		}
+	}
+
+	maxI := 100000
+	for _, yData := range newYDataList {
+		lenEdb := len(yData.XEdbInfoIdList)
+		for i := lenEdb - 1; i >= 0; i-- {
+			if yData.XEdbInfoIdList[i] == 0 || utils.InArrayByInt(yData.NoDataEdbList, yData.XEdbInfoIdList[i]) {
+				maxI = i
+				if maxI > i {
+					maxI = i
+				}
+			} else {
+				break
+			}
+		}
+	}
+
+	//xDataList = xDataList[0:maxI]
+	//for yIndex, yData := range newYDataList {
+	//	if len(yData.XEdbInfoIdList) > maxI {
+	//		newYDataList[yIndex].XEdbInfoIdList = yData.XEdbInfoIdList[0:maxI]
+	//	}
+	//	if len(yData.Value) > maxI {
+	//		newYDataList[yIndex].Value = yData.Value[0:maxI]
+	//	}
+	//}
+	return
+}
+
+// getFutureGoodEdbInfoList 获取适用的指标列表
+func getFutureGoodEdbInfoList(latestDateTime time.Time, tmpFutureGoodEdbInfoList []*future_good.FutureGoodEdbInfo, barChartInfoDateList []data_manage.BarChartInfoDateReq) (earliestDateTime time.Time, futureGoodEdbInfoList []*future_good.FutureGoodEdbInfo, err error) {
+	maxM := 32 //最大32期合约
+	futureGoodEdbInfoList = make([]*future_good.FutureGoodEdbInfo, 0)
+	earliestDateTime = latestDateTime // 数据的最早日期,目的是为了找出最早的合约
+	for _, barChartInfoDate := range barChartInfoDateList {
+		var findDateTime time.Time
+		switch barChartInfoDate.Type {
+		case 1: //最新值
+			findDateTime = latestDateTime
+		case 2: //近期几天
+			findDateTime = latestDateTime.AddDate(0, 0, -barChartInfoDate.Value)
+		case 3: // 固定日期
+			//寻找固定日期的数据
+			tmpFindDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, barChartInfoDate.Date, time.Local)
+			if tmpErr != nil {
+				err = tmpErr
+				return
+			}
+			findDateTime = tmpFindDateTime
+		default:
+			err = errors.New(fmt.Sprint("日期类型异常,Type:", barChartInfoDate.Type))
+			return
+		}
+		if findDateTime.IsZero() {
+			err = errors.New("错误的日期")
+			return
+		}
+		if findDateTime.Before(earliestDateTime) {
+			earliestDateTime = findDateTime
+		}
+	}
+
+	for _, v := range tmpFutureGoodEdbInfoList {
+		if v.RegionType == `国内` {
+			futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
+			continue
+		}
+		//海外的连续日期,目前
+		if v.FutureGoodEdbType == 2 {
+			if v.Month <= maxM {
+				addMonth := int(earliestDateTime.Month()) + v.Month
+				v.Year = earliestDateTime.Year() + addMonth/12
+				realMonth := addMonth % 12
+				if realMonth == 0 {
+					realMonth = 12
+				}
+				v.Month = realMonth
+				futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
+			}
+			continue
+		}
+
+		if v.Year < earliestDateTime.Year() {
+			continue
+		}
+		// 小于等于当前年,那么就肯定是ok的
+		if v.Year <= earliestDateTime.Year() {
+			futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
+			continue
+		}
+		// 如果(当前年-最新日期的年份) * 12个月 + (当前月-最新日期的月份) 小于总月份
+		if (v.Year-earliestDateTime.Year())*12+(v.Month-int(earliestDateTime.Month())) <= maxM {
+			futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
+			continue
+		}
+
+	}
+
+	return
+}

+ 22 - 0
utils/common.go

@@ -708,3 +708,25 @@ func (ms MapSorter) Less(i, j int) bool {
 func (ms MapSorter) Swap(i, j int) {
 	ms[i], ms[j] = ms[j], ms[i]
 }
+
+// InArrayByInt php中的in_array(判断Int类型的切片中是否存在该int值)
+func InArrayByInt(idIntList []int, searchId int) (has bool) {
+	for _, id := range idIntList {
+		if id == searchId {
+			has = true
+			return
+		}
+	}
+	return
+}
+
+// InArrayByStr php中的in_array(判断String类型的切片中是否存在该string值)
+func InArrayByStr(idStrList []string, searchId string) (has bool) {
+	for _, id := range idStrList {
+		if id == searchId {
+			has = true
+			return
+		}
+	}
+	return
+}