获取时区列表 二十五个 utc0 utc12 utc-12

一、最后结果集

在这里插入图片描述

二、代码

@GetMapping("/getTimeZoneList")
@ApiOperation(value = "获取时区列表", notes = "获取时区列表")
public Result<List<TimeZoneVO>> getTimeZoneList() {
    return opLocationService.getTimeZoneList();
}

    public List<TimeZoneVO> getTimeZoneList() {
        List<TimeZoneInfoDTO> zoneList = TimeZoneInfoDTO.getTimeZoneList();
        Map<String, List<TimeZoneInfoDTO>> timeZoneMap = zoneList.stream().collect(Collectors.groupingBy(TimeZoneInfoDTO::getTimeZone));
        List<TimeZoneVO> timeZoneList = TimeZoneEnum.timeZoneList();
        timeZoneList.forEach(item -> {
            List<TimeZoneInfoDTO> infoList = timeZoneMap.get(item.getCode());
            if (CollectionUtils.isNotEmpty(infoList)) {
                item.setZoneIdList(infoList.stream().map(TimeZoneInfoDTO::getZoneId).collect(Collectors.toList()));
            }
        });
        return timeZoneList;
    }
TimeZoneVO
package com.autel.cloud.pile.base.vo;

import lombok.Data;

import java.util.List;

@Data
public class TimeZoneVO {
    private static final long serialVersionUID = -8941450954477609031L;
    private String code;
    private String name;
    private List<String> zoneIdList;

    public TimeZoneVO(String code, String name, List<String> zoneIdList) {
        this.code = code;
        this.name = name;
        this.zoneIdList = zoneIdList;
    }

    public String getCode() {
        return this.code;
    }

    public String getName() {
        return this.name;
    }

    public List<String> getZoneIdList() {
        return this.zoneIdList;
    }

    public TimeZoneVO setCode(String code) {
        this.code = code;
        return this;
    }

    public TimeZoneVO setName(String name) {
        this.name = name;
        return this;
    }

    public TimeZoneVO setZoneIdList(List<String> zoneIdList) {
        this.zoneIdList = zoneIdList;
        return this;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof TimeZoneVO)) {
            return false;
        } else {
            TimeZoneVO other = (TimeZoneVO) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label47:
                {
                    Object this$code = this.getCode();
                    Object other$code = other.getCode();
                    if (this$code == null) {
                        if (other$code == null) {
                            break label47;
                        }
                    } else if (this$code.equals(other$code)) {
                        break label47;
                    }

                    return false;
                }

                Object this$name = this.getName();
                Object other$name = other.getName();
                if (this$name == null) {
                    if (other$name != null) {
                        return false;
                    }
                } else if (!this$name.equals(other$name)) {
                    return false;
                }

                Object this$zoneIdList = this.getZoneIdList();
                Object other$zoneIdList = other.getZoneIdList();
                if (this$zoneIdList == null) {
                    if (other$zoneIdList != null) {
                        return false;
                    }
                } else if (!this$zoneIdList.equals(other$zoneIdList)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof TimeZoneVO;
    }


    public String toString() {
        return "TimeZone(code=" + this.getCode() + ", name=" + this.getName() + ", zoneIdList=" + this.getZoneIdList() + ")";
    }
}

TimeZoneInfoDTO
package com.autel.cloud.pile.base.dto;

import java.time.ZoneId;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.util.stream.Collectors;

public class TimeZoneInfoDTO {
    private String timeZone;
    private String zoneId;

    public static List getTimeZoneList() {
        Set<String> zoneIds = ZoneId.getAvailableZoneIds();
        return zoneIds.parallelStream().map((item) -> {
            TimeZone timeZone = TimeZone.getTimeZone(item);
            int time = timeZone.getRawOffset() / 3600000;
            if (time > 12) {
                time = 12;
            }

            String timeZoneStr = time >= 0 ? "UTC+" + time : "UTC" + time;
            return builder().timeZone(timeZoneStr).zoneId(item).build();
        }).collect(Collectors.toList());
    }

    public static TimeZoneInfoDTO.TimeZoneInfoDTOBuilder builder() {
        return new TimeZoneInfoDTO.TimeZoneInfoDTOBuilder();
    }

    public String getTimeZone() {
        return this.timeZone;
    }

    public String getZoneId() {
        return this.zoneId;
    }

    public void setTimeZone(String timeZone) {
        this.timeZone = timeZone;
    }

    public void setZoneId(String zoneId) {
        this.zoneId = zoneId;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof TimeZoneInfoDTO)) {
            return false;
        } else {
            TimeZoneInfoDTO other = (TimeZoneInfoDTO) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$timeZone = this.getTimeZone();
                Object other$timeZone = other.getTimeZone();
                if (this$timeZone == null) {
                    if (other$timeZone != null) {
                        return false;
                    }
                } else if (!this$timeZone.equals(other$timeZone)) {
                    return false;
                }

                Object this$zoneId = this.getZoneId();
                Object other$zoneId = other.getZoneId();
                if (this$zoneId == null) {
                    if (other$zoneId != null) {
                        return false;
                    }
                } else if (!this$zoneId.equals(other$zoneId)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof TimeZoneInfoDTO;
    }


    public String toString() {
        return "TimeZoneInfoDTO(timeZone=" + this.getTimeZone() + ", zoneId=" + this.getZoneId() + ")";
    }

    public TimeZoneInfoDTO(String timeZone, String zoneId) {
        this.timeZone = timeZone;
        this.zoneId = zoneId;
    }

    public TimeZoneInfoDTO() {
    }

    public static class TimeZoneInfoDTOBuilder {
        private String timeZone;
        private String zoneId;

        TimeZoneInfoDTOBuilder() {
        }

        public TimeZoneInfoDTO.TimeZoneInfoDTOBuilder timeZone(String timeZone) {
            this.timeZone = timeZone;
            return this;
        }

        public TimeZoneInfoDTO.TimeZoneInfoDTOBuilder zoneId(String zoneId) {
            this.zoneId = zoneId;
            return this;
        }

        public TimeZoneInfoDTO build() {
            return new TimeZoneInfoDTO(this.timeZone, this.zoneId);
        }

        public String toString() {
            return "TimeZoneInfoDTO.TimeZoneInfoDTOBuilder(timeZone=" + this.timeZone + ", zoneId=" + this.zoneId + ")";
        }
    }
}

TimeZoneEnum

package com.autel.cloud.pile.base.enums;

import cn.hutool.core.text.CharSequenceUtil;
import com.autel.cloud.pile.base.vo.TimeZoneVO;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.TimeZone;

public enum TimeZoneEnum {
    UTC("UTC+0", "协调世界时"),
    EAST_ONE("UTC+1", "东一区"),
    EAST_TWO("UTC+2", "东二区"),
    EAST_THREE("UTC+3", "东三区"),
    EAST_FOUR("UTC+4", "东四区"),
    EAST_FIVE("UTC+5", "东五区"),
    EAST_SIX("UTC+6", "东六区"),
    EAST_SEVEN("UTC+7", "东七区"),
    EAST_EIGHT("UTC+8", "东八区"),
    EAST_NINE("UTC+9", "东九区"),
    EAST_TEN("UTC+10", "东十区"),
    EAST_ELEVEN("UTC+11", "东十一区"),
    EAST_TWELVE("UTC+12", "东十二区"),
    WEST_ONE("UTC-1", "西一区"),
    WEST_TWO("UTC-2", "西二区"),
    WEST_THREE("UTC-3", "西三区"),
    WEST_FOUR("UTC-4", "西四区"),
    WEST_FIVE("UTC-5", "西五区"),
    WEST_SIX("UTC-6", "西六区"),
    WEST_SEVEN("UTC-7", "西七区"),
    WEST_EIGHT("UTC-8", "西八区"),
    WEST_NINE("UTC-9", "西九区"),
    WEST_TEN("UTC-10", "西十区"),
    WEST_ELEVEN("UTC-11", "西十一区"),
    WEST_TWELVE("UTC-12", "西十二区");

    private String code;
    private String name;

    public int getHour() {
        return 0;
    }

    public static String getText(String code) {
        if (CharSequenceUtil.isBlank(code)) {
            return "";
        } else {
            TimeZoneEnum[] var1 = values();
            int var2 = var1.length;

            for (int var3 = 0; var3 < var2; ++var3) {
                TimeZoneEnum timeZoneEnum = var1[var3];
                if (Objects.equals(code, timeZoneEnum.code)) {
                    return timeZoneEnum.name;
                }
            }

            return "";
        }
    }

    public static List<TimeZoneVO> timeZoneList() {
        List<TimeZoneVO> zoneList = new ArrayList();
        TimeZoneEnum[] var1 = values();
        int var2 = var1.length;
        List<TimeZone> temp = new ArrayList();
        for (int var3 = 0; var3 < var2; ++var3) {
            TimeZoneEnum timeZoneEnum = var1[var3];
            zoneList.add(new TimeZoneVO(timeZoneEnum.code, timeZoneEnum.name, null));
        }
        return zoneList;
    }

    public String getCode() {
        return this.code;
    }

    public String getName() {
        return this.name;
    }

    private TimeZoneEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飘然生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值