{{#eq apps "link"}}
package {{packageName}}.api.{{apps}}.service;

import cn.ibizlab.edge.core.common.domain.*;
import {{packageName}}.api.{{apps}}.dict.*;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import cn.ibizlab.edge.core.common.service.DictCatalogService;

@Slf4j
@Service("link-DictService")
public class DictService {

    @Autowired
    private DictCatalogService dictCatalogService;

    public void syncDict() {
    {{#each app.dicts}}
        {
            DictCatalog dict=new DictCatalog();
            dict.setCode("{{pascalCase codeName}}Dict");
            dict.setName("{{name}}");
            dict.setId(dict.getCode());
            List<DictOption> options=new ArrayList<>();
            new {{pascalCase codeName}}Dict().getAllItems().forEach(item->{
                DictOption option=new DictOption();
                option.setCatalog(dict);
                option.setCatalogId(dict.getId());
                option.setCatalogName(dict.getName());
                option.setValue(item.getValue());
                option.setLabel(item.getLabel());
                option.setParent(item.getParent());
                option.setShoworder(options.size()+1);
                options.add(option);
            });
            dict.setOptions(options);
            dictCatalogService.save(dict);

        }
    {{/each}}
    }

}
{{/eq}}