All Downloads are FREE. Search and download functionalities are using the official Maven repository.

group.rober.base.dict.model.DictEntry Maven / Gradle / Ivy

The newest version!
package group.rober.base.dict.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import group.rober.runtime.kit.StringKit;

import javax.persistence.Id;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.*;

public class DictEntry implements Serializable {
    @Id
    protected String code;
    protected String name;
    protected String nameI18nCode;
    protected String categoryCode;
    protected String sortCode;
    protected String intro;
    protected List items = new ArrayList<>();

    @Transient
    private Map itemMap = new LinkedHashMap();

    public void setItems(List items) {
        this.items = items;
    }

    @JsonIgnore
    public List getDictItemEntrys() {
        return items;
    }

    public String getCode() {
        return code;
    }

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

    public String getName() {
        return name;
    }

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

    public String getNameI18nCode() {
        return nameI18nCode;
    }

    public void setNameI18nCode(String nameI18nCode) {
        this.nameI18nCode = nameI18nCode;
    }

    public String getCategoryCode() {
        return categoryCode;
    }

    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }

    public String getSortCode() {
        return sortCode;
    }

    public void setSortCode(String sortCode) {
        this.sortCode = sortCode;
    }

    public String getIntro() {
        return intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }

    public DictItemEntry getItem(String itemCode) {
        return itemMap.get(itemCode);
    }

    public void setItemMap(Map itemMap) {
        this.itemMap = itemMap;
    }

    public List getItems() {
        List retItems = null;
        if(items==null||items.isEmpty()){
            List itemList = new ArrayList();
            itemList.addAll(itemMap.values());
            retItems = itemList;
        }else {
            retItems = items;
        }
        //重新按排序号排序
//        Collections.sort(retItems, new Comparator() {
//            public int compare(DictItemEntry o1, DictItemEntry o2) {
//                String sortCode1 = StringKit.nvl(o1.getSortCode(),o1.getCode());
//                String sortCode2 = StringKit.nvl(o2.getSortCode(),o2.getCode());
//                sortCode1 = StringKit.nvl(sortCode1,"");
//                sortCode2 = StringKit.nvl(sortCode2,"");
//
//                return sortCode1.compareTo(sortCode2);
//            }
//        });
        retItems.sort(new Comparator() {
            public int compare(DictItemEntry o1, DictItemEntry o2) {
                String sortCode1 = StringKit.nvl(o1.getSortCode(),o1.getCode());
                String sortCode2 = StringKit.nvl(o2.getSortCode(),o2.getCode());
                //当排序号相同时,用ID来排
                if(sortCode1.equals(sortCode2))return o1.getCode().compareTo(o2.getCode());

                return sortCode1.compareTo(sortCode2);
            }
        });

        return retItems;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy