|
@@ -5,13 +5,15 @@ import (
|
|
|
"errors"
|
|
|
"eta/eta_api/models/data_manage"
|
|
|
"eta/eta_api/services/google"
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
-func HandleExtraConfig(chartType int, extraConfigStr string) (newExtraConfigStr string, err error, errMsg string) {
|
|
|
+func HandleExtraConfig(chartType int, extraConfigStr string) (newExtraConfigStr string, newAllExtraConfigStr string, err error, errMsg string) {
|
|
|
newExtraConfigStr = extraConfigStr
|
|
|
-
|
|
|
switch chartType {
|
|
|
case 10: // 截面散点图
|
|
|
var tmpExtraConfig data_manage.SectionScatterReq
|
|
@@ -28,6 +30,48 @@ func HandleExtraConfig(chartType int, extraConfigStr string) (newExtraConfigStr
|
|
|
}
|
|
|
|
|
|
newExtraConfigStr, err, errMsg = handleSectionScatterChartData(tmpExtraConfig)
|
|
|
+ case utils.CHART_TYPE_SECTION_COMBINE:
|
|
|
+ //整理组合图的配置信息,将部分信息存入其他表
|
|
|
+ // 预览和详情都走这个接口
|
|
|
+ var sectionExtraConfig data_manage.ChartSectionAllExtraConf
|
|
|
+ if extraConfigStr == `` {
|
|
|
+ errMsg = "截面组合图未配置"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = json.Unmarshal([]byte(extraConfigStr), §ionExtraConfig)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "截面组合图配置异常"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newAllExtraConfig, e, msg := handleChartSectionCombineData(sectionExtraConfig)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ errMsg = msg
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newAllExtraConfigByte, e := json.Marshal(newAllExtraConfig)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newAllExtraConfigStr = string(newAllExtraConfigByte)
|
|
|
+
|
|
|
+ newExtraConfig := &data_manage.ChartSectionExtraConf{
|
|
|
+ DateConfList: newAllExtraConfig.DateConfList,
|
|
|
+ IsHeap: newAllExtraConfig.IsHeap,
|
|
|
+ XDataList: newAllExtraConfig.XDataList,
|
|
|
+ UnitList: newAllExtraConfig.UnitList,
|
|
|
+ BaseChartSeriesName: newAllExtraConfig.BaseChartSeriesName,
|
|
|
+ SortType: newAllExtraConfig.SortType,
|
|
|
+ }
|
|
|
+ extraConfigByte, e := json.Marshal(newExtraConfig)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ extraConfigStr = string(extraConfigByte)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -197,3 +241,466 @@ func GetEnNameMapByCnNameList(cnNameList []string) (contentEnMap map[string]stri
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// handleSectionScatterChartData 截面组合图的数据处理
|
|
|
+func handleChartSectionCombineData(extraConfig data_manage.ChartSectionAllExtraConf) (newExtraConfig data_manage.ChartSectionAllExtraConf, err error, errMsg string) {
|
|
|
+ translateNameList := make([]string, 0)
|
|
|
+ translateNameMap := make(map[string]bool, 0)
|
|
|
+ for _, v := range extraConfig.DateConfList {
|
|
|
+ if _, ok := translateNameMap[v.DateConfName]; !ok && v.DateConfNameEn == "" {
|
|
|
+ translateNameMap[v.DateConfName] = true
|
|
|
+ tmpName := strings.TrimSuffix(v.DateConfName, " ")
|
|
|
+ tmpName = strings.TrimPrefix(tmpName, " ")
|
|
|
+ translateNameList = append(translateNameList, tmpName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range extraConfig.UnitList {
|
|
|
+ if _, ok := translateNameMap[v.Name]; !ok && v.NameEn == "" {
|
|
|
+ translateNameMap[v.Name] = true
|
|
|
+ tmpName := strings.TrimSuffix(v.Name, " ")
|
|
|
+ tmpName = strings.TrimPrefix(tmpName, " ")
|
|
|
+ translateNameList = append(translateNameList, tmpName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range extraConfig.XDataList {
|
|
|
+ if _, ok := translateNameMap[v.Name]; !ok && v.NameEn == "" {
|
|
|
+ translateNameMap[v.Name] = true
|
|
|
+ tmpName := strings.TrimSuffix(v.Name, " ")
|
|
|
+ tmpName = strings.TrimPrefix(tmpName, " ")
|
|
|
+ translateNameList = append(translateNameList, tmpName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range extraConfig.SeriesList {
|
|
|
+ if v.SeriesNameEn == `` {
|
|
|
+ if _, ok := translateNameMap[v.SeriesName]; !ok {
|
|
|
+ translateNameMap[v.SeriesName] = true
|
|
|
+ tmpName := strings.TrimSuffix(v.SeriesName, " ")
|
|
|
+ tmpName = strings.TrimPrefix(tmpName, " ")
|
|
|
+ translateNameList = append(translateNameList, tmpName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取英文名称map
|
|
|
+ enNameMap, _, _ := GetEnNameMapByCnNameList(translateNameList)
|
|
|
+
|
|
|
+ for k, seriesItem := range extraConfig.SeriesList {
|
|
|
+ if len(seriesItem.EdbInfoList) <= 0 {
|
|
|
+ errMsg = "指标不能为空"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if seriesItem.SeriesNameEn == `` { //系列英文名称
|
|
|
+ if tmpNameEn, ok := enNameMap[seriesItem.SeriesName]; ok {
|
|
|
+ seriesItem.SeriesNameEn = tmpNameEn
|
|
|
+ }
|
|
|
+ }
|
|
|
+ extraConfig.SeriesList[k] = seriesItem
|
|
|
+ }
|
|
|
+
|
|
|
+ for k, v := range extraConfig.XDataList {
|
|
|
+ if tmpNameEn, ok := enNameMap[v.Name]; ok && v.NameEn == "" {
|
|
|
+ extraConfig.XDataList[k].NameEn = tmpNameEn
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for k, v := range extraConfig.UnitList {
|
|
|
+ if tmpNameEn, ok := enNameMap[v.Name]; ok && v.NameEn == "" {
|
|
|
+ extraConfig.UnitList[k].NameEn = tmpNameEn
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for k, v := range extraConfig.DateConfList {
|
|
|
+ if tmpNameEn, ok := enNameMap[v.DateConfName]; ok && v.DateConfNameEn == "" {
|
|
|
+ extraConfig.DateConfList[k].DateConfNameEn = tmpNameEn
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ newExtraConfig = extraConfig
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetChartSectionCombineData 截面组合图的数据处理
|
|
|
+func GetChartSectionCombineData(chartInfoId int, mappingList []*data_manage.ChartEdbInfoMapping, edbDataListMap map[int][]*data_manage.EdbDataList, extraConfig data_manage.ChartSectionAllExtraConf) (edbIdList []int, dataListResp data_manage.ChartSectionCombineDataResp, err error) {
|
|
|
+ // 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
|
|
|
+ edbDataMap := make(map[int]map[string]float64)
|
|
|
+ for edbInfoId, edbDataList := range edbDataListMap {
|
|
|
+ edbDateData := make(map[string]float64)
|
|
|
+ for _, edbData := range edbDataList {
|
|
|
+ edbDateData[edbData.DataTime] = edbData.Value
|
|
|
+ }
|
|
|
+ edbDataMap[edbInfoId] = edbDateData
|
|
|
+ }
|
|
|
+
|
|
|
+ // edbIdList 指标展示顺序;x轴的指标顺序
|
|
|
+ edbIdList = make([]int, 0)
|
|
|
+ edbMappingMap := make(map[int]*data_manage.ChartEdbInfoMapping)
|
|
|
+ for _, v := range mappingList {
|
|
|
+ edbIdList = append(edbIdList, v.EdbInfoId)
|
|
|
+ edbMappingMap[v.EdbInfoId] = v
|
|
|
+ }
|
|
|
+ // 确定好截面散点图返回的数据格式
|
|
|
+ // 获取所有的引用日期设置
|
|
|
+ DateConfListMap := make(map[string]*data_manage.ChartSectionDateConfItem)
|
|
|
+ for _, v := range extraConfig.DateConfList {
|
|
|
+ DateConfListMap[v.DateConfName] = v
|
|
|
+ }
|
|
|
+ // 遍历每个系列
|
|
|
+ // 遍历每个指标,根据选中的日期,进行日期变换得到最终的日期,根据最终的日期获取对应的值
|
|
|
+ // 组装数据
|
|
|
+ baseSeries := new(data_manage.ChartSectionSeriesItem) //y轴的系列
|
|
|
+ var firstUnit, leftUnit, rightUnit, right2Unit *data_manage.XData
|
|
|
+ for _, seriesItem := range extraConfig.SeriesList {
|
|
|
+ var maxDate time.Time
|
|
|
+ var minVal, maxVal float64
|
|
|
+ noDataEdbIdList := make([]int, 0)
|
|
|
+ dataList := make([]float64, len(seriesItem.EdbInfoList))
|
|
|
+ for index, edbConf := range seriesItem.EdbInfoList {
|
|
|
+ edbInfoId := edbConf.EdbInfoId //X轴的指标
|
|
|
+ edbMappingInfo, ok := edbMappingMap[edbInfoId]
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ seriesItem.EdbInfoList[index].EdbName = edbMappingInfo.EdbName
|
|
|
+ seriesItem.EdbInfoList[index].EdbNameEn = edbMappingInfo.EdbNameEn
|
|
|
+ seriesItem.EdbInfoList[index].Unit = edbMappingInfo.Unit
|
|
|
+ seriesItem.EdbInfoList[index].UnitEn = edbMappingInfo.UnitEn
|
|
|
+ if index == 0 {
|
|
|
+ firstUnit = &data_manage.XData{
|
|
|
+ Name: edbMappingInfo.Unit,
|
|
|
+ NameEn: edbMappingInfo.UnitEn,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ edbDataList, ok3 := edbDataListMap[edbInfoId]
|
|
|
+ if !ok3 {
|
|
|
+ err = fmt.Errorf("指标%d的日期数据不存在", edbInfoId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ /*dataList := edbDataListMap[edbInfoId] //指标的所有数据值
|
|
|
+ if len(dataList) <= 0 {
|
|
|
+ // 没有数据的指标id
|
|
|
+ //findDataList = append(findDataList, 0)
|
|
|
+ continue
|
|
|
+ }*/
|
|
|
+ //日期变换处理,判断用指标的最新日期还是,直接获取引用日期
|
|
|
+ var findDate string
|
|
|
+ if edbConf.DateConfName == "" {
|
|
|
+ findDate, err = GetChartSectionSeriesDateByDateChange(edbInfoId, edbDataList, edbConf.DateConf.DateChange, edbConf.DateConf.MoveForward)
|
|
|
+ } else {
|
|
|
+ // 获取日期配置
|
|
|
+ dateConfItem, ok1 := DateConfListMap[edbConf.DateConfName]
|
|
|
+ if !ok1 {
|
|
|
+ err = fmt.Errorf("引用日期配置不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // todo 根据日期变换得到最终日期
|
|
|
+ edbDataListTmp := make([]*data_manage.EdbDataList, 0)
|
|
|
+ if dateConfItem.EdbInfoId > 0 {
|
|
|
+ edbDataListTmp, ok1 = edbDataListMap[dateConfItem.EdbInfoId]
|
|
|
+ if !ok1 {
|
|
|
+ err = fmt.Errorf("指标%d的日期数据不存在", dateConfItem.EdbInfoId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ findDate, err = GetChartSectionSeriesDateByDateChange(dateConfItem.EdbInfoId, edbDataListTmp, dateConfItem.DateChange, dateConfItem.MoveForward)
|
|
|
+ }
|
|
|
+ findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
|
|
|
+ if maxDate.IsZero() {
|
|
|
+ maxDate = findDateTime
|
|
|
+ } else {
|
|
|
+ if findDateTime.After(maxDate) {
|
|
|
+ maxDate = findDateTime
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
|
|
|
+ dataList[index] = tmpValue
|
|
|
+ if index == 0 {
|
|
|
+ minVal = tmpValue
|
|
|
+ maxVal = tmpValue
|
|
|
+ } else {
|
|
|
+ if tmpValue < minVal {
|
|
|
+ minVal = tmpValue
|
|
|
+ }
|
|
|
+ if tmpValue > maxVal {
|
|
|
+ maxVal = tmpValue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ noDataEdbIdList = append(noDataEdbIdList, edbInfoId)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ seriesItem.DataList = dataList
|
|
|
+ seriesItem.MinData = minVal
|
|
|
+ seriesItem.MaxData = maxVal
|
|
|
+ seriesItem.NoDataEdbIdList = noDataEdbIdList
|
|
|
+ if extraConfig.BaseChartSeriesName == seriesItem.SeriesName {
|
|
|
+ baseSeries = seriesItem
|
|
|
+ }
|
|
|
+ if seriesItem.IsAxis == 1 && leftUnit == nil { //左轴,右轴
|
|
|
+ leftUnit = firstUnit
|
|
|
+ } else if seriesItem.IsAxis == 0 && rightUnit == nil {
|
|
|
+ rightUnit = firstUnit
|
|
|
+ } else if seriesItem.IsAxis == 2 && right2Unit == nil {
|
|
|
+ right2Unit = firstUnit
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理横轴
|
|
|
+ // 遍历基准系列,判断有几个横轴名称
|
|
|
+ if baseSeries == nil {
|
|
|
+ err = fmt.Errorf("基准系列不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ xDataList := make([]data_manage.XData, 0)
|
|
|
+ for index, item := range baseSeries.EdbInfoList {
|
|
|
+ if index == 0 {
|
|
|
+ firstUnit = &data_manage.XData{
|
|
|
+ Name: item.Unit,
|
|
|
+ NameEn: item.UnitEn,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tmp := data_manage.XData{
|
|
|
+ Name: item.EdbName,
|
|
|
+ NameEn: item.EdbNameEn,
|
|
|
+ }
|
|
|
+ // 如果已经设置了横轴名称,则用设置的名称替换
|
|
|
+ if len(extraConfig.XDataList) > index {
|
|
|
+ newItem := extraConfig.XDataList[index]
|
|
|
+ if newItem.Name != "" {
|
|
|
+ tmp = newItem
|
|
|
+ }
|
|
|
+ }
|
|
|
+ xDataList = append(xDataList, tmp)
|
|
|
+ }
|
|
|
+ dataListResp.XDataList = xDataList
|
|
|
+
|
|
|
+ // todo 处理纵轴, 如果只存在一个右轴会有问题
|
|
|
+ unitList := make([]*data_manage.XData, 3)
|
|
|
+ if baseSeries.IsAxis == 1 { //左轴,右轴
|
|
|
+ leftUnit = firstUnit
|
|
|
+ } else if baseSeries.IsAxis == 2 {
|
|
|
+ rightUnit = firstUnit
|
|
|
+ } else {
|
|
|
+ right2Unit = firstUnit
|
|
|
+ }
|
|
|
+ if len(extraConfig.UnitList) == 0 {
|
|
|
+ unitList[0] = leftUnit
|
|
|
+ unitList[1] = rightUnit
|
|
|
+ unitList[2] = right2Unit
|
|
|
+ } else if len(extraConfig.UnitList) == 1 {
|
|
|
+ unitList[0] = extraConfig.UnitList[0]
|
|
|
+ unitList[1] = rightUnit
|
|
|
+ unitList[2] = right2Unit
|
|
|
+ } else if len(extraConfig.UnitList) == 2 {
|
|
|
+ unitList[0] = extraConfig.UnitList[0]
|
|
|
+ unitList[1] = extraConfig.UnitList[1]
|
|
|
+ unitList[2] = right2Unit
|
|
|
+ }
|
|
|
+
|
|
|
+ dataListResp.XDataList = extraConfig.XDataList
|
|
|
+ dataListResp.SeriesList = extraConfig.SeriesList
|
|
|
+ dataListResp.DateConfList = extraConfig.DateConfList
|
|
|
+ dataListResp.BaseChartSeriesName = extraConfig.BaseChartSeriesName
|
|
|
+ dataListResp.UnitList = extraConfig.UnitList
|
|
|
+ dataListResp.IsHeap = extraConfig.IsHeap
|
|
|
+ dataListResp.SortType = extraConfig.SortType
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetChartSectionSeriesDateByDateChange 获取日期变换后的日期edbInfoId 1指标日期,2 系统日期
|
|
|
+func GetChartSectionSeriesDateByDateChange(edbInfoId int, dataList []*data_manage.EdbDataList, dateChange []*data_manage.ChartSectionDateChange, moveForward int) (newDate string, err error) {
|
|
|
+ if edbInfoId > 0 { //指标日期
|
|
|
+ newDate = GetEdbDateByMoveForward(moveForward, dataList)
|
|
|
+ } else {
|
|
|
+ //系统日期
|
|
|
+ newDate = time.Now().Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ if newDate != "" && len(dateChange) > 0 {
|
|
|
+ newDate, err = HandleChartSectionSeriesDateChange(newDate, dateChange)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetEdbDateByMoveForward(moveForward int, edbDataList []*data_manage.EdbDataList) (date string) {
|
|
|
+ dateList := make([]string, 0)
|
|
|
+ for _, v := range edbDataList {
|
|
|
+ dateList = append(dateList, v.DataTime)
|
|
|
+ }
|
|
|
+
|
|
|
+ date = GetEdbDateByMoveForwardByDateList(moveForward, dateList)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetEdbDateByMoveForwardByDateList(moveForward int, dateList []string) (date string) {
|
|
|
+ // 根据日期进行排序
|
|
|
+ index := len(dateList) - 1 - moveForward
|
|
|
+ for k, v := range dateList {
|
|
|
+ if k == index {
|
|
|
+ date = v
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// HandleChartSectionSeriesDateChange 处理日期变换
|
|
|
+func HandleChartSectionSeriesDateChange(date string, dateChange []*data_manage.ChartSectionDateChange) (newDate string, err error) {
|
|
|
+ newDate = date
|
|
|
+ if newDate != "" {
|
|
|
+ if len(dateChange) > 0 {
|
|
|
+ var dateTime time.Time
|
|
|
+ dateTime, err = time.ParseInLocation(utils.FormatDate, newDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("日期解析失败: %s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range dateChange {
|
|
|
+ if v.ChangeType == 1 {
|
|
|
+ dateTime = dateTime.AddDate(v.Year, v.Month, v.Day)
|
|
|
+ newDate = dateTime.Format(utils.FormatDate)
|
|
|
+ } else if v.ChangeType == 2 {
|
|
|
+ newDate, err, _ = handleSystemAppointDateT(dateTime, v.FrequencyDay, v.Frequency)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ dateTime, err = time.ParseInLocation(utils.FormatDate, newDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("日期解析失败: %s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// handleSystemAppointDateT
|
|
|
+// @Description: 处理系统日期相关的指定频率(所在周/旬/月/季/半年/年的最后/最早一天)
|
|
|
+// @author: Roc
|
|
|
+// @datetime2023-10-27 09:31:35
|
|
|
+// @param Frequency string
|
|
|
+// @param Day string
|
|
|
+// @return date string
|
|
|
+// @return err error
|
|
|
+// @return errMsg string
|
|
|
+func handleSystemAppointDateT(currDate time.Time, appointDay, frequency string) (date string, err error, errMsg string) {
|
|
|
+ //currDate := time.Now()
|
|
|
+ switch frequency {
|
|
|
+ case "本周":
|
|
|
+ day := int(currDate.Weekday())
|
|
|
+ if day == 0 { // 周日
|
|
|
+ day = 7
|
|
|
+ }
|
|
|
+ num := 0
|
|
|
+ switch appointDay {
|
|
|
+ case "周一":
|
|
|
+ num = 1
|
|
|
+ case "周二":
|
|
|
+ num = 2
|
|
|
+ case "周三":
|
|
|
+ num = 3
|
|
|
+ case "周四":
|
|
|
+ num = 4
|
|
|
+ case "周五":
|
|
|
+ num = 5
|
|
|
+ case "周六":
|
|
|
+ num = 6
|
|
|
+ case "周日":
|
|
|
+ num = 7
|
|
|
+ }
|
|
|
+ day = num - day
|
|
|
+ date = currDate.AddDate(0, 0, day).Format(utils.FormatDate)
|
|
|
+ case "本旬":
|
|
|
+ day := currDate.Day()
|
|
|
+ var tmpDate time.Time
|
|
|
+ switch appointDay {
|
|
|
+ case "第一天":
|
|
|
+ if day <= 10 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if day <= 20 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 11, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 21, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
+ case "最后一天":
|
|
|
+ if day <= 10 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 10, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if day <= 20 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 20, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month()+1, 1, 0, 0, 0, 0, currDate.Location()).AddDate(0, 0, -1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
+ case "本月":
|
|
|
+ var tmpDate time.Time
|
|
|
+ switch appointDay {
|
|
|
+ case "第一天":
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ case "最后一天":
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month()+1, 1, 0, 0, 0, 0, currDate.Location()).AddDate(0, 0, -1)
|
|
|
+ }
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
+ case "本季":
|
|
|
+ month := currDate.Month()
|
|
|
+ var tmpDate time.Time
|
|
|
+ switch appointDay {
|
|
|
+ case "第一天":
|
|
|
+ if month <= 3 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if month <= 6 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 4, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if month <= 9 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 7, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 10, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
+ case "最后一天":
|
|
|
+ if month <= 3 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 3, 31, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if month <= 6 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 6, 30, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if month <= 9 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 9, 30, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
+ case "本半年":
|
|
|
+ month := currDate.Month()
|
|
|
+ var tmpDate time.Time
|
|
|
+ switch appointDay {
|
|
|
+ case "第一天":
|
|
|
+ if month <= 6 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 7, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
+ case "最后一天":
|
|
|
+ if month <= 6 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 6, 30, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
+ case "本年":
|
|
|
+ var tmpDate time.Time
|
|
|
+ switch appointDay {
|
|
|
+ case "第一天":
|
|
|
+ tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ case "最后一天":
|
|
|
+ tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
+ default:
|
|
|
+ errMsg = "错误的日期频度:" + frequency
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|