package cn.estsh.i3plus.core.apiservice.serviceimpl.busi;

import cn.estsh.i3plus.core.api.iservice.busi.ICoreTreeService;
import cn.estsh.i3plus.core.apiservice.dao.ISysMenuDao;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ModelEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.HqlPack;
import cn.estsh.i3plus.pojo.model.platform.CommonTreeModel;
import cn.estsh.i3plus.pojo.platform.bean.SysDepartment;
import cn.estsh.i3plus.pojo.platform.bean.SysMenu;
import cn.estsh.i3plus.pojo.platform.bean.SysOrganize;
import cn.estsh.i3plus.pojo.platform.bean.SysPosition;
import cn.estsh.i3plus.pojo.platform.repository.SysDepartmentRepository;
import cn.estsh.i3plus.pojo.platform.repository.SysMenuRepository;
import cn.estsh.i3plus.pojo.platform.repository.SysOrganizeRepository;
import cn.estsh.i3plus.pojo.platform.repository.SysPositionRepository;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
import cn.estsh.impp.framework.boot.util.ImppRedis;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description : Core 树功能实现
 * @Reference :
 * @Author : wei.peng
 * @Date : 2018-10-24 11:17
 * @Modify :
 **/
@Service
public class CoreTreeService implements ICoreTreeService {

    public static final Logger LOGGER = LoggerFactory.getLogger(CoreTreeService.class);

    @Autowired
    private SysDepartmentRepository departmentRDao;

    @Autowired
    private SysPositionRepository positionRDao;

    @Autowired
    private SysOrganizeRepository organizeRDao;

    @Autowired
    private SysMenuRepository menuRDao;

    @Autowired
    private ISysMenuDao sysMenuDao;

    /**
     * 核心的缓存
     */
    @Resource(name="redisCore")
    protected ImppRedis redisCore;

    @Override
    @ApiOperation(value = "获取岗位树",notes = "根据父节点获取岗位树集合")
    public List<SysPosition> findSysPositionTreeByParentId(long parentId) {
        List<SysPosition> result = positionRDao.findByProperty("parentId", parentId);

        // 循环设置子集
        if(result != null && result.size() > 0){
            for (SysPosition position : result) {
                findSysPositionChildrenTreePack(position,0);
            }
        }

        return result;
    }

    @Override
    @ApiOperation(value = "获取岗位树",notes = "根据父节点获取岗位树")
    public SysPosition getSysPositionTreeById(long id) {
        // 查找数据
        SysPosition position = positionRDao.getById(id);
        // 数据是否真实存在
        ValidatorBean.checkNotNull(position,"不存在的岗位信息");
        // 递归查询子集
        findSysPositionChildrenTreePack(position, 0);

        return position;
    }

    @Override
    @ApiOperation(value = "封装岗位树",notes = "封装当前岗位树")
    public void findSysPositionChildrenTreePack(SysPosition parent, int step) {
        ++step;
        List<SysPosition> childList = positionRDao.findByProperty("parentId", parent.getId());

        if (childList.size() > 0) {
            //说明有子集
            for (SysPosition child : childList) {
                findSysPositionChildrenTreePack(child, step);
            }
        }

        LOGGER.info("【{}】包含子集：{},步长：{}", parent.getName(), childList.size(), step);
        parent.setChildList(childList);
    }

    @Override
    @ApiOperation(value = "父节点检查",notes = "检查岗位的父节点是否是当前节点的子节点")
    public void doValidatorSysPositionParentId(SysPosition position) {
        if(position != null){
            if(position.getParentId().longValue() == position.getId().longValue()){
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("上级岗位不能为当前岗位")
                        .setErrorSolution("请重新操作")
                        .build();
            }
            findSysPositionChildrenTreePack(position,0);
            validatorSysPositionParentId(position.getChildList(),position.getParentId());
        }
    }

    @Override
    @ApiOperation(value = "获取部门树",notes = "根据父节点获取部门树集合")
    public List<SysDepartment> findSysDepartmentTreeByParentId(long parentId) {
        List<SysDepartment> result = departmentRDao.findByProperty("parentId", parentId);

        // 循环设置子集
        if(result != null && result.size() > 0){
            for (SysDepartment department : result) {
                findSysDepartmentChildrenTreePack(department,0);
            }
        }

        return result;
    }

    @Override
    @ApiOperation(value = "获取部门树",notes = "根据父节点获取部门树")
    public SysDepartment getSysDepartmentTreeById(long id) {
        // 查找数据
        SysDepartment department = departmentRDao.getById(id);
        // 数据是否真实存在
        ValidatorBean.checkNotNull(department,"不存在的部门信息");
        // 递归查询子集
        findSysDepartmentChildrenTreePack(department, 0);

        return department;
    }

    @Override
    @ApiOperation(value = "获取部门ID集合",notes = "根据组织ID获取部门子集ID集合")
    public List<Long> findSysDepartmentIdByOrganizeId(long id) {
        List<Long> result = new ArrayList<>();
        if(id > 0){
            List<SysDepartment> list = departmentRDao.findByProperty("organizeId", id);
            if(list != null && list.size()> 0){
                for (SysDepartment department : list) {
                    findSysDepartmentChildrenTreePack(department,0);
                    result.addAll(findSysDepartmentChildIds(department));
                }
            }
        }
        return result;
    }

    @Override
    @ApiOperation(value = "获取部门ID集合",notes = "获取部门子集ID集合")
    public List<Long> findSysDepartmentChildIds(SysDepartment department) {
        List<Long> result = new ArrayList<>();
        if(null != department){
            if(department.getChildList() != null && department.getChildList().size() > 0){
                for (SysDepartment dep : department.getChildList()) {
                    result.addAll(findSysDepartmentChildIds(dep));
                }
            }
            result.add(department.getId());
        }
        return result;
    }

    @Override
    @ApiOperation(value = "封装部门树",notes = "封装当前部门树")
    public void findSysDepartmentChildrenTreePack(SysDepartment parent, int step) {
        ++step;
        List<SysDepartment> childList = departmentRDao.findByProperty("parentId", parent.getId());

        if (childList.size() > 0) {
            //说明有子集
            for (SysDepartment child : childList) {
                findSysDepartmentChildrenTreePack(child, step);
            }
        }

        LOGGER.info("【{}】包含子集：{},步长：{}", parent.getName(), childList.size(), step);
        parent.setChildList(childList);
    }

    @Override
    @ApiOperation(value = "父节点检查",notes = "检查部门的父节点是否是当前节点的子节点")
    public void doValidatorSysDepartmentParentId(SysDepartment department) {
        if(department != null){
            if(department.getParentId().longValue() == department.getId().longValue()){
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("上级部门不能为当前部门")
                        .setErrorSolution("请重新操作")
                        .build();
            }
            findSysDepartmentChildrenTreePack(department,0);
            validatorSysDepartmentParentId(department.getChildList(),department.getParentId());
        }
    }

    @Override
    @ApiOperation(value = "获取组织树",notes = "根据父节点获取组织树集合")
    public List<SysOrganize> findSysOrganizeTreeByParentId(long parentId) {
        StringBuffer orgHQL = new StringBuffer();
        HqlPack.getNumEqualPack(parentId,"parentId",orgHQL);
        HqlPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"organizeSort"}, orgHQL);
        List<SysOrganize> result = findSysOrganizeCacheByHqlWhere(orgHQL.toString());

        // 循环设置子集
        if(result != null && result.size() > 0){
            for (SysOrganize organize : result) {
                findSysOrganizeChildrenTreePack(organize,0);
            }
        }

        return result;
    }

    @Override
    @ApiOperation(value = "获取组织树",notes = "根据父节点获取组织树")
    public SysOrganize getSysOrganizeTreeById(long id) {
        // 查找数据
        SysOrganize organize = organizeRDao.getById(id);
        // 数据是否真实存在
        ValidatorBean.checkNotNull(organize,"不存在的组织信息");
        // 递归查询子集
        findSysOrganizeChildrenTreePack(organize, 0);

        return organize;
    }

    @Override
    public List<Long> findSysOrganizeChildIds(SysOrganize organize) {
        List<Long> result = new ArrayList<>();
        if(null != organize){
            if(organize.getChildList() != null && organize.getChildList().size() > 0){
                for (SysOrganize org : organize.getChildList()) {
                    result.addAll(findSysOrganizeChildIds(org));
                }
            }
            result.add(organize.getId());
        }
        return result;
    }

    @Override
    @ApiOperation(value = "封装组织树",notes = "封装当前组织树")
    public void findSysOrganizeChildrenTreePack(SysOrganize parent, int step) {
        ++step;

        StringBuffer orgHQL = new StringBuffer();
        HqlPack.getNumEqualPack(parent.getId(),"parentId",orgHQL);
        HqlPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"organizeSort"}, orgHQL);
        List<SysOrganize> childList = findSysOrganizeCacheByHqlWhere(orgHQL.toString());

        if (childList.size() > 0) {  //说明有子集
            for (SysOrganize child : childList) {
                findSysOrganizeChildrenTreePack(child, step);
            }
        }

        LOGGER.info("【{}】包含子集：{},步长：{}", parent.getName(), childList.size(), step);
        parent.setChildList(childList);
    }

    @Override
    @ApiOperation(value = "父节点检查",notes = "检查组织的父节点是否是当前节点的子节点")
    public void doValidatorSysOrganizeParentId(SysOrganize organize) {
        if(organize != null){
            if(organize.getParentId().longValue() == organize.getId().longValue()){
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("上级组织不能为当前组织")
                        .setErrorSolution("请重新操作")
                        .build();
            }

            findSysOrganizeChildrenTreePack(organize,0);
            validatorSysOrganizeParentId(organize.getChildList(),organize.getParentId());
        }
    }

    @Override
    @ApiOperation(value = "获取菜单树",notes = "根据父节点获取菜单树集合")
    public List<SysMenu> findSysMenuTreeByParentId(long parentId) {
        List<SysMenu> result = menuRDao.findByProperty("parentId", parentId);

        // 循环设置子集
        if(result != null && result.size() > 0){
            for (SysMenu menu : result) {
                findSysMenuChildrenTreePack(menu,0);
            }
        }

        return result;
    }

    @Override
    @ApiOperation(value = "获取菜单树",notes = "根据父节点获取菜单树")
    public SysMenu getSysMenuTreeById(long id) {
        // 查找数据
        SysMenu menu = menuRDao.getById(id);
        // 数据是否真实存在
        ValidatorBean.checkNotNull(menu,"不存在的组织信息");
        // 递归查询子集
        findSysMenuChildrenTreePack(menu, 0);

        return menu;
    }

    @Override
    @ApiOperation(value = "封装菜单树",notes = "封装当前菜单树")
    public void findSysMenuChildrenTreePack(SysMenu parent, int step) {
        ++step;
        List<SysMenu> childList = menuRDao.findByProperty(
                new String[]{"parentId","menuStatus"},
                new Object[]{parent.getId(),CommonEnumUtil.DATA_STATUS.ENABLE.getValue()});

        if (childList.size() > 0) {  //说明有子集
            for (SysMenu child : childList) {
                findSysMenuChildrenTreePack(child, step);
            }
        }

        LOGGER.info("【{}】包含子集：{},步长：{}", parent.getName(), childList.size(), step);
        parent.setChildList(childList);
    }

    @Override
    public void findSysMenuChildrenTreeByRoleIdPack(SysMenu parent, Long roleId, int step) {
        ++step;
        List<SysMenu> childList = sysMenuDao.findByParentIdAndRoleId(parent.getId(),roleId);

        if (childList.size() > 0) {  //说明有子集
            for (SysMenu child : childList) {
                findSysMenuChildrenTreeByRoleIdPack(child, roleId,step);
            }
        }

        LOGGER.info("【{}】包含子集：{},步长：{}", parent.getName(), childList.size(), step);
        parent.setChildList(childList);
    }

    @Override
    public void findSysMenuChildrenTreeByUserIdPack(SysMenu parent, Long userId, int step) {
        ++step;
        List<SysMenu> childList = sysMenuDao.findByParentIdAndUserId(parent.getId(),userId);

        if (childList.size() > 0) {  //说明有子集
            for (SysMenu child : childList) {
                findSysMenuChildrenTreeByUserIdPack(child, userId,step);
            }
        }

        LOGGER.info("【{}】包含子集：{},步长：{}", parent.getName(), childList.size(), step);
        parent.setChildList(childList);
    }

    @Override
    public void findMemSysMenuChildrenTreeByUserIdPack(SysMenu parent,List<SysMenu> cacheMenuList, int step) {
        ++step;
        List<SysMenu> childList = new ArrayList<>();
        if(cacheMenuList != null && cacheMenuList.size() > 0){
            for (SysMenu menu : cacheMenuList) {
                if(menu.getParentId().equals(parent.getId())){
                    childList.add(menu);
                }
            }
        }

        if (childList.size() > 0) {  //说明有子集
            for (SysMenu child : childList) {
                findMemSysMenuChildrenTreeByUserIdPack(child,cacheMenuList,step);
            }
        }

        LOGGER.info("【{}】包含子集：{},步长：{}", parent.getName(), childList.size(), step);
        parent.setChildList(childList);
    }

    @Override
    @ApiOperation(value = "父节点检查",notes = "检查菜单的父节点是否是当前节点的子节点")
    public void doValidatorSysMenuParentId(SysMenu menu) {
        if(menu != null){
            if(menu.getParentId().longValue() == menu.getId().longValue()){
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("上级组织不能为当前系统功能")
                        .setErrorSolution("请重新操作")
                        .build();
            }

            findSysMenuChildrenTreePack(menu,0);
            validatorSysMenuParentId(menu.getChildList(),menu.getParentId());
        }
    }

    @Override
    @ApiOperation(value = "获取组织部门树",notes = "根据父节点获取组织部门树集合")
    public List<CommonTreeModel> findOrganizeDepartment(long parentId) {
        List<CommonTreeModel> result = new ArrayList<>();

        StringBuffer hql = new StringBuffer();
        HqlPack.getNumEqualPack(parentId,"parentId",hql);
        HqlPack.getOrderByPack(new Object[]{2}, new String[]{"organizeSort"}, hql);
        List<SysOrganize> list = findSysOrganizeCacheByHqlWhere(hql.toString());

        // 循环设置子集
        if(list != null && list.size() > 0){
            for (SysOrganize organize : list) {
                CommonTreeModel treeModel = new CommonTreeModel();
                treeModel.setBean(organize);
                treeModel.setBeanType(ModelEnumUtil.COMMON_TREE_TYPE.TYPE_ORGANIZE.getValue());

                findOrganizeTreePack(treeModel,0);

                result.add(treeModel);
            }
        }


        return result;
    }

    @Override
    @ApiOperation(value = "获取组织部门树",notes = "根据父节点获取组织部门树")
    public CommonTreeModel getOrganizeById(long id) {
        // 查找数据
        SysOrganize organize = organizeRDao.getById(id);
        // 数据是否真实存在
        ValidatorBean.checkNotNull(organize,"不存在的组织信息");

        CommonTreeModel treeModel = new CommonTreeModel();
        treeModel.setBean(organize);
        treeModel.setBeanType(ModelEnumUtil.COMMON_TREE_TYPE.TYPE_ORGANIZE.getValue());

        // 递归查询子集
        findOrganizeTreePack(treeModel, 0);
        return treeModel;
    }

    @Override
    @ApiOperation(value = "封装菜单树",notes = "封装当前组织部门树")
    public void findOrganizeTreePack(CommonTreeModel parent, int step) {
        if(null != parent){
            BaseBean bean = parent.getBean();
            List<CommonTreeModel> childList = new ArrayList<>();
            CommonTreeModel treeModel = null;
            if(bean instanceof SysOrganize){
                SysOrganize organize = (SysOrganize) bean;

                StringBuffer hql = new StringBuffer();
                HqlPack.getNumEqualPack(organize.getId(),"parentId",hql);
                HqlPack.getOrderByPack(new Object[]{2}, new String[]{"organizeSort"}, hql);
                List<SysOrganize> organizeList = findSysOrganizeCacheByHqlWhere(hql.toString());

                if(organizeList != null && organizeList.size() > 0){
                    for (SysOrganize org : organizeList) {
                        treeModel = new CommonTreeModel();
                        treeModel.setBean(org);
                        treeModel.setBeanType(ModelEnumUtil.COMMON_TREE_TYPE.TYPE_ORGANIZE.getValue());

                        findOrganizeTreePack(treeModel,step);

                        childList.add(treeModel);
                    }
                }

                StringBuffer depHQL = new StringBuffer();
                HqlPack.getNumEqualPack(organize.getId(),"organizeId",depHQL);
                HqlPack.getOrderByPack(new Object[]{2}, new String[]{"departmentSort"}, depHQL);
                List<SysDepartment> departmentList = findSysDepartmentCacheByHqlWhere(depHQL.toString());

                if(departmentList != null && departmentList.size() > 0){
                    for (SysDepartment department : departmentList) {
                        if(department.getParentId() != null && department.getParentId() < 0){
                            treeModel = new CommonTreeModel();
                            treeModel.setBean(department);
                            treeModel.setBeanType(ModelEnumUtil.COMMON_TREE_TYPE.TYPE_DEPARTMENT.getValue());

                            findOrganizeTreePack(treeModel,step);

                            childList.add(treeModel);
                        }
                    }
                }
                LOGGER.info("【{}】包含子集：{},步长：{}", parent.getBean().getClass().getName(), parent.getChildList().size(), step);
            }else if(bean instanceof SysDepartment){
                SysDepartment department = (SysDepartment) bean;

                StringBuffer depHQL = new StringBuffer();
                HqlPack.getNumEqualPack(department.getId(),"parentId",depHQL);
                HqlPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"departmentSort"}, depHQL);

                List<SysDepartment> departmentList = findSysDepartmentCacheByHqlWhere(depHQL.toString());

                if(departmentList != null && departmentList.size() > 0){
                    for (SysDepartment dep : departmentList) {
                        treeModel = new CommonTreeModel();
                        treeModel.setBean(dep);
                        treeModel.setBeanType(ModelEnumUtil.COMMON_TREE_TYPE.TYPE_DEPARTMENT.getValue());

                        findOrganizeTreePack(treeModel,step);

                        childList.add(treeModel);
                    }
                }
            }
            parent.setChildList(childList);
        }
    }

    private void validatorSysPositionParentId(List<SysPosition> list, Long parentId){
        if(list != null && list.size() > 0){
            for (SysPosition position : list) {
                // 判断子集的ID 是否是 父节点ID
                if(position.getId().equals(parentId) || position.getId().equals(position.getParentId())){
                    throw ImppExceptionBuilder.newInstance()
                            .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
                            .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                            .setErrorDetail("上级岗位不能为子岗位")
                            .setErrorSolution("请重新操作")
                            .build();
                }

                validatorSysPositionParentId(position.getChildList(),parentId);
            }
        }
    }

    private void validatorSysDepartmentParentId(List<SysDepartment> list, Long parentId){
        if(list != null && list.size() > 0){
            for (SysDepartment department : list) {
                // 判断子集的ID 是否是 父节点ID
                if(department.getId().equals(parentId) || department.getId().equals(department.getParentId())){
                    throw ImppExceptionBuilder.newInstance()
                            .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
                            .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                            .setErrorDetail("上级部门不能为子部门")
                            .setErrorSolution("请重新操作")
                            .build();
                }

                validatorSysDepartmentParentId(department.getChildList(),parentId);
            }
        }
    }

    private void validatorSysOrganizeParentId(List<SysOrganize> list, Long parentId){
        if(list != null && list.size() > 0){
            for (SysOrganize organize : list) {
                // 判断子集的ID 是否是 父节点ID
                if(organize.getId().equals(parentId) || organize.getId().equals(organize.getParentId())){
                    throw ImppExceptionBuilder.newInstance()
                            .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
                            .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                            .setErrorDetail("上级部门不能为子部门")
                            .setErrorSolution("请重新操作")
                            .build();
                }

                validatorSysOrganizeParentId(organize.getChildList(),parentId);
            }
        }
    }

    private void validatorSysMenuParentId(List<SysMenu> list, Long parentId){
        if(list != null && list.size() > 0){
            for (SysMenu menu : list) {
                // 判断子集的ID 是否是 父节点ID
                if(menu.getId().equals(parentId) || menu.getId().equals(menu.getParentId())){
                    throw ImppExceptionBuilder.newInstance()
                            .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
                            .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                            .setErrorDetail("上级部门不能为子目录")
                            .setErrorSolution("请重新操作")
                            .build();
                }

                validatorSysMenuParentId(menu.getChildList(),parentId);
            }
        }
    }

    private List<SysDepartment> findSysDepartmentCacheByHqlWhere(String hql){
        return departmentRDao.findByHqlWhere(hql);
//        if(!StringUtils.isBlank(hql)){
//            String redisKey = CommonConstWords.REDIS_PREFIX_CACHE_DEPARTMENT+ "_findCacheByHqlWhere" + "_" + hql.hashCode();
//            List list = redisCore.getList(redisKey, 0, -1);
//            if(list == null){
//                list = departmentRDao.findByHqlWhere(hql);
//                if(list != null){
//                    redisCore.putList(redisKey,list,CommonConstWords.REDIS_TIME_DAY_ONE);
//                }
//            }
//            return list;
//        }else {
//            return null;
//        }
    }

    private List<SysOrganize> findSysOrganizeCacheByHqlWhere(String hql){
        return organizeRDao.findByHqlWhere(hql);

//        if(!StringUtils.isBlank(hql)){
//            String redisKey = CommonConstWords.REDIS_PREFIX_CACHE_ORGANIZE+ "_findCacheByHqlWhere" + "_" + hql.hashCode();
//            List list = redisCore.getList(redisKey, 0, -1);
//            if(list == null){
//                list = organizeRDao.findByHqlWhere(hql);
//                if(list != null){
//                    redisCore.putList(redisKey,list,CommonConstWords.REDIS_TIME_DAY_ONE);
//                }
//            }
//            return list;
//        }else {
//            return null;
//        }
    }

}
