package com.czg.account.vo;

import lombok.Data;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

import java.util.List;

/**
 * 行政区域返回vo
 */
@Data
public class DistrictVo {
    /**
     * 城市代码
     */
    private Object citycode;
    private String adcode;
    /**
     * 名称
     */
    private String name;
    /**
     * 经纬度
     */
    private String center;
    /**
     * 级别
     */
    private String level;
    /**
     * 行政区信息
     */
    private List<DistrictVo> districts;

    public String getNameAsPY() {
        return getPinYin(name);
    }

    public String getPinYin(String name){
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        // 设置声调类型为WITH_TONE_MARK
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        // 设置拼音输出的大小写格式为小写
        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        String pinyin = "";
        try {
            pinyin = PinyinHelper.toHanYuPinyinString(name,format , "", false);
        } catch (BadHanyuPinyinOutputFormatCombination e) {
            return pinyin;
        }
        return pinyin;
    }
}
