chart_extra_config.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/services/google"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. func HandleExtraConfig(chartType int, extraConfigStr string) (newExtraConfigStr string, err error, errMsg string) {
  14. newExtraConfigStr = extraConfigStr
  15. switch chartType {
  16. case 10: // 截面散点图
  17. var tmpExtraConfig data_manage.SectionScatterReq
  18. if extraConfigStr == `` {
  19. errMsg = "截面散点图未配置"
  20. err = errors.New(errMsg)
  21. return
  22. }
  23. err = json.Unmarshal([]byte(extraConfigStr), &tmpExtraConfig)
  24. if err != nil {
  25. errMsg = "截面散点配置异常"
  26. err = errors.New(errMsg)
  27. return
  28. }
  29. newExtraConfigStr, err, errMsg = handleSectionScatterChartData(tmpExtraConfig)
  30. }
  31. return
  32. }
  33. // handleSectionScatterChartData 截面散点图的数据处理
  34. func handleSectionScatterChartData(extraConfig data_manage.SectionScatterReq) (extraConfigStr string, err error, errMsg string) {
  35. translateNameList := make([]string, 0)
  36. translateNameMap := make(map[string]bool, 0)
  37. if extraConfig.XNameEn == `` {
  38. if _, ok := translateNameMap[extraConfig.XName]; !ok {
  39. translateNameMap[extraConfig.XName] = true
  40. tmpName := strings.TrimSuffix(extraConfig.XName, " ")
  41. tmpName = strings.TrimPrefix(tmpName, " ")
  42. translateNameList = append(translateNameList, tmpName)
  43. }
  44. }
  45. if extraConfig.XUnitNameEn == `` {
  46. if _, ok := translateNameMap[extraConfig.XUnitName]; !ok {
  47. translateNameMap[extraConfig.XUnitName] = true
  48. tmpName := strings.TrimSuffix(extraConfig.XUnitName, " ")
  49. tmpName = strings.TrimPrefix(tmpName, " ")
  50. translateNameList = append(translateNameList, tmpName)
  51. }
  52. }
  53. if extraConfig.YNameEn == `` {
  54. if _, ok := translateNameMap[extraConfig.YName]; !ok {
  55. translateNameMap[extraConfig.YName] = true
  56. tmpName := strings.TrimSuffix(extraConfig.YName, " ")
  57. tmpName = strings.TrimPrefix(tmpName, " ")
  58. translateNameList = append(translateNameList, tmpName)
  59. }
  60. }
  61. if extraConfig.YUnitNameEn == `` {
  62. if _, ok := translateNameMap[extraConfig.YUnitName]; !ok {
  63. translateNameMap[extraConfig.YUnitName] = true
  64. tmpName := strings.TrimSuffix(extraConfig.YUnitName, " ")
  65. tmpName = strings.TrimPrefix(tmpName, " ")
  66. translateNameList = append(translateNameList, tmpName)
  67. }
  68. }
  69. for _, v := range extraConfig.SeriesList {
  70. if v.NameEn == `` {
  71. if _, ok := translateNameMap[v.Name]; !ok {
  72. translateNameMap[v.Name] = true
  73. tmpName := strings.TrimSuffix(v.Name, " ")
  74. tmpName = strings.TrimPrefix(tmpName, " ")
  75. translateNameList = append(translateNameList, tmpName)
  76. }
  77. }
  78. for _, edbInfo := range v.EdbInfoList {
  79. if edbInfo.NameEn == `` {
  80. if _, ok := translateNameMap[edbInfo.Name]; !ok {
  81. translateNameMap[edbInfo.Name] = true
  82. tmpName := strings.TrimSuffix(edbInfo.Name, " ")
  83. tmpName = strings.TrimPrefix(tmpName, " ")
  84. translateNameList = append(translateNameList, tmpName)
  85. }
  86. }
  87. }
  88. }
  89. // 获取英文名称map
  90. enNameMap, _, _ := GetEnNameMapByCnNameList(translateNameList)
  91. for k, seriesItem := range extraConfig.SeriesList {
  92. if len(seriesItem.EdbInfoList) <= 0 {
  93. errMsg = "指标不能为空"
  94. err = errors.New(errMsg)
  95. return
  96. }
  97. for edbIndex, edbConf := range seriesItem.EdbInfoList {
  98. if edbConf.NameEn == `` { //标签英文名称
  99. if tmpNameEn, ok := enNameMap[edbConf.Name]; ok {
  100. edbConf.NameEn = tmpNameEn
  101. }
  102. }
  103. seriesItem.EdbInfoList[edbIndex] = edbConf
  104. }
  105. if seriesItem.NameEn == `` { //系列英文名称
  106. if tmpNameEn, ok := enNameMap[seriesItem.Name]; ok {
  107. seriesItem.NameEn = tmpNameEn
  108. }
  109. }
  110. extraConfig.SeriesList[k] = seriesItem
  111. }
  112. if extraConfig.XNameEn == `` {
  113. if tmpNameEn, ok := enNameMap[extraConfig.XName]; ok {
  114. extraConfig.XNameEn = tmpNameEn
  115. }
  116. }
  117. if extraConfig.XUnitNameEn == `` {
  118. if tmpNameEn, ok := enNameMap[extraConfig.XUnitName]; ok {
  119. extraConfig.XUnitNameEn = tmpNameEn
  120. }
  121. }
  122. if extraConfig.YNameEn == `` {
  123. if tmpNameEn, ok := enNameMap[extraConfig.YName]; ok {
  124. extraConfig.YNameEn = tmpNameEn
  125. }
  126. }
  127. if extraConfig.YUnitNameEn == `` {
  128. if tmpNameEn, ok := enNameMap[extraConfig.YUnitName]; ok {
  129. extraConfig.YUnitNameEn = tmpNameEn
  130. }
  131. }
  132. extraConfigByte, err := json.Marshal(extraConfig)
  133. if err != nil {
  134. return
  135. }
  136. extraConfigStr = string(extraConfigByte)
  137. return
  138. }
  139. // GetEnNameMapByCnNameList 根据中文名称列表获取英文名称map
  140. func GetEnNameMapByCnNameList(cnNameList []string) (contentEnMap map[string]string, err error, errMsg string) {
  141. // 返回参初始化
  142. contentEnMap = make(map[string]string)
  143. // 英文临时赋值变量
  144. tmpContentEnMapAll := make(map[string]string)
  145. count := 0
  146. contentMap := make(map[string]string, 0)
  147. for k, v := range cnNameList {
  148. //如果单条翻译的字符数超过1000,则直接翻译,否则批量翻译
  149. if count >= 50 { //待翻译的条数不能超过50; 单条翻译字符数不能超过1000字符
  150. tmpContentEnMap, tmpErr, tmpErrMsg := google.BatchTranslateHandlerByGoogle(contentMap)
  151. if tmpErr != nil {
  152. err = tmpErr
  153. errMsg = tmpErrMsg
  154. return
  155. }
  156. for tmpK, contentEn := range tmpContentEnMap {
  157. tmpContentEnMapAll[tmpK] = contentEn
  158. }
  159. contentMap = make(map[string]string, 0)
  160. count = 0
  161. }
  162. contentMap[strconv.Itoa(k)] = v
  163. count += 1
  164. }
  165. //剩余不满50条的content
  166. if count > 0 {
  167. tmpContentEnMap, tmpErr, tmpErrMsg := google.BatchTranslateHandlerByGoogle(contentMap)
  168. if tmpErr != nil {
  169. err = tmpErr
  170. errMsg = tmpErrMsg
  171. return
  172. }
  173. for tmpK, contentEn := range tmpContentEnMap {
  174. tmpContentEnMapAll[tmpK] = contentEn
  175. }
  176. }
  177. // 重新组装拼接返回
  178. lenCnNameList := len(cnNameList)
  179. for k, v := range tmpContentEnMapAll {
  180. tmpIndex, _ := strconv.Atoi(k)
  181. if tmpIndex < lenCnNameList {
  182. contentEnMap[cnNameList[tmpIndex]] = v
  183. }
  184. }
  185. return
  186. }
  187. // GetChartSectionCombineData 截面组合图的数据处理
  188. 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) {
  189. // 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
  190. edbDataMap := make(map[int]map[string]float64)
  191. for edbInfoId, edbDataList := range edbDataListMap {
  192. edbDateData := make(map[string]float64)
  193. for _, edbData := range edbDataList {
  194. edbDateData[edbData.DataTime] = edbData.Value
  195. }
  196. edbDataMap[edbInfoId] = edbDateData
  197. }
  198. // edbIdList 指标展示顺序;x轴的指标顺序
  199. edbIdList = make([]int, 0)
  200. edbMappingMap := make(map[int]*data_manage.ChartEdbInfoMapping)
  201. for _, v := range mappingList {
  202. edbIdList = append(edbIdList, v.EdbInfoId)
  203. edbMappingMap[v.EdbInfoId] = v
  204. }
  205. // 确定好截面散点图返回的数据格式
  206. // 获取所有的引用日期设置
  207. DateConfListMap := make(map[string]*data_manage.ChartSectionDateConfItem)
  208. for _, v := range extraConfig.DateConfList {
  209. DateConfListMap[v.DateConfName] = v
  210. }
  211. // 遍历每个系列
  212. // 遍历每个指标,根据选中的日期,进行日期变换得到最终的日期,根据最终的日期获取对应的值
  213. // 组装数据
  214. baseSeries := new(data_manage.ChartSectionSeriesItem) //y轴的系列
  215. var firstUnit, leftUnit, rightUnit, right2Unit *data_manage.XData
  216. for _, seriesItem := range extraConfig.SeriesList {
  217. var maxDate time.Time
  218. var minVal, maxVal float64
  219. noDataEdbIdList := make([]int, 0)
  220. dataList := make([]float64, len(seriesItem.EdbInfoList))
  221. for index, edbConf := range seriesItem.EdbInfoList {
  222. edbInfoId := edbConf.EdbInfoId //X轴的指标
  223. edbMappingInfo, ok := edbMappingMap[edbInfoId]
  224. if !ok {
  225. continue
  226. }
  227. seriesItem.EdbInfoList[index].EdbName = edbMappingInfo.EdbName
  228. seriesItem.EdbInfoList[index].EdbNameEn = edbMappingInfo.EdbNameEn
  229. seriesItem.EdbInfoList[index].Unit = edbMappingInfo.Unit
  230. seriesItem.EdbInfoList[index].UnitEn = edbMappingInfo.UnitEn
  231. if index == 0 {
  232. firstUnit = &data_manage.XData{
  233. Name: edbMappingInfo.Unit,
  234. NameEn: edbMappingInfo.UnitEn,
  235. }
  236. }
  237. edbDataList, ok3 := edbDataListMap[edbInfoId]
  238. if !ok3 {
  239. err = fmt.Errorf("指标%d的日期数据不存在", edbInfoId)
  240. return
  241. }
  242. /*dataList := edbDataListMap[edbInfoId] //指标的所有数据值
  243. if len(dataList) <= 0 {
  244. // 没有数据的指标id
  245. //findDataList = append(findDataList, 0)
  246. continue
  247. }*/
  248. //日期变换处理,判断用指标的最新日期还是,直接获取引用日期
  249. var findDate string
  250. if edbConf.DateConfName == "" {
  251. findDate, err = GetChartSectionSeriesDateByDateChange(edbInfoId, edbDataList, edbConf.DateConf.DateChange, edbConf.DateConf.MoveForward)
  252. } else {
  253. // 获取日期配置
  254. dateConfItem, ok1 := DateConfListMap[edbConf.DateConfName]
  255. if !ok1 {
  256. err = fmt.Errorf("引用日期配置不存在")
  257. return
  258. }
  259. // todo 根据日期变换得到最终日期
  260. edbDataListTmp := make([]*data_manage.EdbDataList, 0)
  261. if dateConfItem.EdbInfoId > 0 {
  262. edbDataListTmp, ok1 = edbDataListMap[dateConfItem.EdbInfoId]
  263. if !ok1 {
  264. err = fmt.Errorf("指标%d的日期数据不存在", dateConfItem.EdbInfoId)
  265. return
  266. }
  267. }
  268. findDate, err = GetChartSectionSeriesDateByDateChange(dateConfItem.EdbInfoId, edbDataListTmp, dateConfItem.DateChange, dateConfItem.MoveForward)
  269. }
  270. findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
  271. if maxDate.IsZero() {
  272. maxDate = findDateTime
  273. } else {
  274. if findDateTime.After(maxDate) {
  275. maxDate = findDateTime
  276. }
  277. }
  278. if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
  279. dataList[index] = tmpValue
  280. if index == 0 {
  281. minVal = tmpValue
  282. maxVal = tmpValue
  283. } else {
  284. if tmpValue < minVal {
  285. minVal = tmpValue
  286. }
  287. if tmpValue > maxVal {
  288. maxVal = tmpValue
  289. }
  290. }
  291. } else {
  292. noDataEdbIdList = append(noDataEdbIdList, edbInfoId)
  293. continue
  294. }
  295. }
  296. seriesItem.DataList = dataList
  297. seriesItem.MinData = minVal
  298. seriesItem.MaxData = maxVal
  299. seriesItem.NoDataEdbIdList = noDataEdbIdList
  300. if extraConfig.BaseChartSeriesName == seriesItem.SeriesName {
  301. baseSeries = seriesItem
  302. }
  303. if seriesItem.IsAxis == 1 && leftUnit == nil { //左轴,右轴
  304. leftUnit = firstUnit
  305. } else if seriesItem.IsAxis == 0 && rightUnit == nil {
  306. rightUnit = firstUnit
  307. } else if seriesItem.IsAxis == 2 && right2Unit == nil {
  308. right2Unit = firstUnit
  309. }
  310. }
  311. // 处理横轴
  312. // 遍历基准系列,判断有几个横轴名称
  313. if baseSeries == nil {
  314. err = fmt.Errorf("基准系列不存在")
  315. return
  316. }
  317. xDataList := make([]data_manage.XData, 0)
  318. for index, item := range baseSeries.EdbInfoList {
  319. if index == 0 {
  320. firstUnit = &data_manage.XData{
  321. Name: item.Unit,
  322. NameEn: item.UnitEn,
  323. }
  324. }
  325. tmp := data_manage.XData{
  326. Name: item.EdbName,
  327. NameEn: item.EdbNameEn,
  328. }
  329. // 如果已经设置了横轴名称,则用设置的名称替换
  330. if len(extraConfig.XDataList) > index {
  331. newItem := extraConfig.XDataList[index]
  332. if newItem.Name != "" {
  333. tmp = newItem
  334. }
  335. }
  336. xDataList = append(xDataList, tmp)
  337. }
  338. dataListResp.XDataList = xDataList
  339. // todo 处理纵轴, 如果只存在一个右轴会有问题
  340. unitList := make([]*data_manage.XData, 3)
  341. if baseSeries.IsAxis == 1 { //左轴,右轴
  342. leftUnit = firstUnit
  343. } else if baseSeries.IsAxis == 2 {
  344. rightUnit = firstUnit
  345. } else {
  346. right2Unit = firstUnit
  347. }
  348. if len(extraConfig.UnitList) == 0 {
  349. unitList[0] = leftUnit
  350. unitList[1] = rightUnit
  351. unitList[2] = right2Unit
  352. } else if len(extraConfig.UnitList) == 1 {
  353. unitList[0] = extraConfig.UnitList[0]
  354. unitList[1] = rightUnit
  355. unitList[2] = right2Unit
  356. } else if len(extraConfig.UnitList) == 2 {
  357. unitList[0] = extraConfig.UnitList[0]
  358. unitList[1] = extraConfig.UnitList[1]
  359. unitList[2] = right2Unit
  360. }
  361. dataListResp.XDataList = extraConfig.XDataList
  362. dataListResp.SeriesList = extraConfig.SeriesList
  363. dataListResp.DateConfList = extraConfig.DateConfList
  364. dataListResp.BaseChartSeriesName = extraConfig.BaseChartSeriesName
  365. dataListResp.UnitList = extraConfig.UnitList
  366. dataListResp.IsHeap = extraConfig.IsHeap
  367. dataListResp.SortType = extraConfig.SortType
  368. return
  369. }
  370. // GetChartSectionSeriesDateByDateChange 获取日期变换后的日期edbInfoId 1指标日期,2 系统日期
  371. func GetChartSectionSeriesDateByDateChange(edbInfoId int, dataList []*data_manage.EdbDataList, dateChange []*data_manage.ChartSectionDateChange, moveForward int) (newDate string, err error) {
  372. if edbInfoId > 0 { //指标日期
  373. newDate = GetEdbDateByMoveForward(moveForward, dataList)
  374. } else {
  375. //系统日期
  376. newDate = time.Now().Format(utils.FormatDate)
  377. }
  378. if newDate != "" && len(dateChange) > 0 {
  379. newDate, err = HandleChartSectionSeriesDateChange(newDate, dateChange)
  380. }
  381. return
  382. }
  383. func GetEdbDateByMoveForward(moveForward int, edbDataList []*data_manage.EdbDataList) (date string) {
  384. dateList := make([]string, 0)
  385. for _, v := range edbDataList {
  386. dateList = append(dateList, v.DataTime)
  387. }
  388. date = GetEdbDateByMoveForwardByDateList(moveForward, dateList)
  389. return
  390. }
  391. func GetEdbDateByMoveForwardByDateList(moveForward int, dateList []string) (date string) {
  392. // 根据日期进行排序
  393. index := len(dateList) - 1 - moveForward
  394. for k, v := range dateList {
  395. if k == index {
  396. date = v
  397. return
  398. }
  399. }
  400. return
  401. }
  402. // HandleChartSectionSeriesDateChange 处理日期变换
  403. func HandleChartSectionSeriesDateChange(date string, dateChange []*data_manage.ChartSectionDateChange) (newDate string, err error) {
  404. newDate = date
  405. if newDate != "" {
  406. if len(dateChange) > 0 {
  407. var dateTime time.Time
  408. dateTime, err = time.ParseInLocation(utils.FormatDate, newDate, time.Local)
  409. if err != nil {
  410. err = fmt.Errorf("日期解析失败: %s", err.Error())
  411. return
  412. }
  413. for _, v := range dateChange {
  414. if v.ChangeType == 1 {
  415. dateTime = dateTime.AddDate(v.Year, v.Month, v.Day)
  416. newDate = dateTime.Format(utils.FormatDate)
  417. } else if v.ChangeType == 2 {
  418. newDate, err, _ = handleSystemAppointDateT(dateTime, v.FrequencyDay, v.Frequency)
  419. if err != nil {
  420. return
  421. }
  422. dateTime, err = time.ParseInLocation(utils.FormatDate, newDate, time.Local)
  423. if err != nil {
  424. err = fmt.Errorf("日期解析失败: %s", err.Error())
  425. return
  426. }
  427. }
  428. }
  429. }
  430. }
  431. return
  432. }
  433. // handleSystemAppointDateT
  434. // @Description: 处理系统日期相关的指定频率(所在周/旬/月/季/半年/年的最后/最早一天)
  435. // @author: Roc
  436. // @datetime2023-10-27 09:31:35
  437. // @param Frequency string
  438. // @param Day string
  439. // @return date string
  440. // @return err error
  441. // @return errMsg string
  442. func handleSystemAppointDateT(currDate time.Time, appointDay, frequency string) (date string, err error, errMsg string) {
  443. //currDate := time.Now()
  444. switch frequency {
  445. case "本周":
  446. day := int(currDate.Weekday())
  447. if day == 0 { // 周日
  448. day = 7
  449. }
  450. num := 0
  451. switch appointDay {
  452. case "周一":
  453. num = 1
  454. case "周二":
  455. num = 2
  456. case "周三":
  457. num = 3
  458. case "周四":
  459. num = 4
  460. case "周五":
  461. num = 5
  462. case "周六":
  463. num = 6
  464. case "周日":
  465. num = 7
  466. }
  467. day = num - day
  468. date = currDate.AddDate(0, 0, day).Format(utils.FormatDate)
  469. case "本旬":
  470. day := currDate.Day()
  471. var tmpDate time.Time
  472. switch appointDay {
  473. case "第一天":
  474. if day <= 10 {
  475. tmpDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, currDate.Location())
  476. } else if day <= 20 {
  477. tmpDate = time.Date(currDate.Year(), currDate.Month(), 11, 0, 0, 0, 0, currDate.Location())
  478. } else {
  479. tmpDate = time.Date(currDate.Year(), currDate.Month(), 21, 0, 0, 0, 0, currDate.Location())
  480. }
  481. case "最后一天":
  482. if day <= 10 {
  483. tmpDate = time.Date(currDate.Year(), currDate.Month(), 10, 0, 0, 0, 0, currDate.Location())
  484. } else if day <= 20 {
  485. tmpDate = time.Date(currDate.Year(), currDate.Month(), 20, 0, 0, 0, 0, currDate.Location())
  486. } else {
  487. tmpDate = time.Date(currDate.Year(), currDate.Month()+1, 1, 0, 0, 0, 0, currDate.Location()).AddDate(0, 0, -1)
  488. }
  489. }
  490. date = tmpDate.Format(utils.FormatDate)
  491. case "本月":
  492. var tmpDate time.Time
  493. switch appointDay {
  494. case "第一天":
  495. tmpDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, currDate.Location())
  496. case "最后一天":
  497. tmpDate = time.Date(currDate.Year(), currDate.Month()+1, 1, 0, 0, 0, 0, currDate.Location()).AddDate(0, 0, -1)
  498. }
  499. date = tmpDate.Format(utils.FormatDate)
  500. case "本季":
  501. month := currDate.Month()
  502. var tmpDate time.Time
  503. switch appointDay {
  504. case "第一天":
  505. if month <= 3 {
  506. tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
  507. } else if month <= 6 {
  508. tmpDate = time.Date(currDate.Year(), 4, 1, 0, 0, 0, 0, currDate.Location())
  509. } else if month <= 9 {
  510. tmpDate = time.Date(currDate.Year(), 7, 1, 0, 0, 0, 0, currDate.Location())
  511. } else {
  512. tmpDate = time.Date(currDate.Year(), 10, 1, 0, 0, 0, 0, currDate.Location())
  513. }
  514. case "最后一天":
  515. if month <= 3 {
  516. tmpDate = time.Date(currDate.Year(), 3, 31, 0, 0, 0, 0, currDate.Location())
  517. } else if month <= 6 {
  518. tmpDate = time.Date(currDate.Year(), 6, 30, 0, 0, 0, 0, currDate.Location())
  519. } else if month <= 9 {
  520. tmpDate = time.Date(currDate.Year(), 9, 30, 0, 0, 0, 0, currDate.Location())
  521. } else {
  522. tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
  523. }
  524. }
  525. date = tmpDate.Format(utils.FormatDate)
  526. case "本半年":
  527. month := currDate.Month()
  528. var tmpDate time.Time
  529. switch appointDay {
  530. case "第一天":
  531. if month <= 6 {
  532. tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
  533. } else {
  534. tmpDate = time.Date(currDate.Year(), 7, 1, 0, 0, 0, 0, currDate.Location())
  535. }
  536. case "最后一天":
  537. if month <= 6 {
  538. tmpDate = time.Date(currDate.Year(), 6, 30, 0, 0, 0, 0, currDate.Location())
  539. } else {
  540. tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
  541. }
  542. }
  543. date = tmpDate.Format(utils.FormatDate)
  544. case "本年":
  545. var tmpDate time.Time
  546. switch appointDay {
  547. case "第一天":
  548. tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
  549. case "最后一天":
  550. tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
  551. }
  552. date = tmpDate.Format(utils.FormatDate)
  553. default:
  554. errMsg = "错误的日期频度:" + frequency
  555. err = errors.New(errMsg)
  556. return
  557. }
  558. return
  559. }