package com.app.admin.framework.system.module.convert;

import com.app.admin.framework.system.module.model.SysModule;
import com.app.admin.framework.system.module.view.SysModuleTreeNode;
import com.app.framework.core.support.convert.ConvertTreeNodeUtils;
import org.springframework.beans.BeanUtils;

import java.util.Set;

public class SysModuleTreeConvert extends  ConvertTreeNodeUtils<SysModule, SysModuleTreeNode> {

	@Override
	public void convert(SysModule entity, SysModuleTreeNode node) {
		BeanUtils.copyProperties(entity, node, new String[]{"oid", "parent"});
		node.setId(entity.getOid().toString());
		node.setOid(entity.getOid().toString());
		node.setIconCls(entity.getIconcls());
		node.setOpen(true);
		if (!entity.getParentId().equals(0L)) {
			node.setParentId(entity.getParentId().toString());
		}
	}

	@Override
	public void nodeCheck(SysModuleTreeNode node, Set<String> checkedOidSet){
		if (checkedOidSet != null && checkedOidSet.contains(node.getOid())) {
			node.setChecked(true);
		}
	}
	
}
