package com.ruoyi.test;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.util.PinYinUtil;
import com.ruoyi.xq.domain.AreaCode;
import com.ruoyi.xq.service.AreaCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RefreshArea {

    @Autowired
    private AreaCodeService areaCodeService;

    public void refreshPinyin(){
        List<AreaCode> list = areaCodeService.list();
        for (AreaCode areaCode : list) {
            String firstSpell = PinYinUtil.getFirstSpell(areaCode.getName());
            areaCodeService.update(Wrappers.lambdaUpdate(AreaCode.class)
                    .eq(AreaCode::getCode, areaCode.getCode())
                    .set(AreaCode::getFirstSpell, firstSpell));
        }
    }


}
