美文网首页
数据字典,查询到数组转Tree

数据字典,查询到数组转Tree

作者: 崔螫 | 来源:发表于2019-08-22 21:51 被阅读0次

    Java后台数据字典

    public class Dict implements IDObject {
    
        /* 字典ID*/
        private String id;
        /* 字典编码 */
        private String code;
        /* 字典中文名*/
        private String label;
        /* 开发级别*/
        private int openLevel;
        /* 创建人*/
        private String creatorId;
        private String creator;
        /* 创建时间 */
        private Date createTime;
        /*描述*/
        private String description;
    }
    

    字典枚举值

    public class DictValue  {
        /* 字典编码*/
        private String dictCode;
        /*顶级团队ID */
        private String rootTeamId;
        /* 枚举值编码 */
        private String valueCode;
        /*枚举值父节点编码 */
        private String parentCode;
        /* 枚举值名称 */
        private String label;
        /* 枚举值参数*/
        private String param;
        /*子节点列表*/
        private List<DictValue> childList = new ArrayList<DictValue>();
    }
    

    后台查询数据字典集合

    @Override
        public InvokeResult getValueList(String rootTeamId,String dictCode){
                    //判断空值
            if(existEmptyArg(rootTeamId,dictCode))
            {
                return errorResult(ErrorCodeConstants.INVALID_INPUT, "参数缺失!");
            }
            Dict tmp=new Dict();
            tmp.setCode(dictCode);
            Dict dict=dictDao.get(tmp);
            if(dict==null)
            {
                return errorResult(ErrorCodeConstants.RUNTIME_ERROR, "没有找到相应的字典!");
            }
            if(!rootTeamId.equals(TerminalUserType.PLATFORM_USER)&&dict.getOpenLevel()==Dict.OpenLevel.NO_OPEN)
            {
                return errorResult(ErrorCodeConstants.RUNTIME_ERROR, "您没有权限执行此操作");
            }
            DictValue vtmp=new DictValue();
            if(dict.getOpenLevel()==Dict.OpenLevel.READ_OPEN)
            {
                vtmp.setRootTeamId(TerminalUserType.PLATFORM_USER);
            }else if(dict.getOpenLevel()==Dict.OpenLevel.WRITE_OPEN)
            {
                vtmp.setRootTeamId(rootTeamId);
            }
            vtmp.setDictCode(dictCode);
            List<DictValue> list = dictValueDao.getList(vtmp);
            if(list.size()==0&&!rootTeamId.equals(TerminalUserType.PLATFORM_USER)&&dict.getOpenLevel()==Dict.OpenLevel.WRITE_OPEN)
            {
                vtmp.setRootTeamId(TerminalUserType.PLATFORM_USER);
                list=dictValueDao.getList(vtmp);
                if(list.size()>0)
                {
                    for(DictValue v:list)
                    {
                        v.setRootTeamId(rootTeamId);
                    }
                    dictValueDao.insertList(list);
                }
                
            }
            return successResult(list);
        }
    

    //数组转Tree
    前台js转化

    const listToTree = function (data) {
      data.forEach(function (item) {
        delete item.children;
      });
      let map = {};
      data.forEach(function (item) {
        map[item.id] = item;
      });
      let val = [];
      data.forEach(function (item) {
        let parent = map[item.parentId];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          val.push(item);
        }
      });
      return val;
    }

    相关文章

      网友评论

          本文标题:数据字典,查询到数组转Tree

          本文链接:https://www.haomeiwen.com/subject/ufxasctx.html