package com.palmnest.service.estateserve.impl;

import com.alibaba.fastjson.JSON;
import com.palmnest.application.bean.Page;
import com.palmnest.application.dto.bo.VirServiceBO;
import com.palmnest.application.dto.output.enterprise.OpenedFunctionOutDto;
import com.palmnest.application.dto.output.enterprise.VirPermConfigDTO;
import com.palmnest.dao.estateserve.EnterprisePermissionDao;
import com.palmnest.dao.release.GoodsCompanyDao;
import com.palmnest.model.enterprise.VirPermConfig;
import com.palmnest.model.enterprise.VirServiceRelation;
import com.palmnest.model.estateserve.AppUser;
import com.palmnest.model.estateserve.GoodsConfig;
import com.palmnest.model.estateserve.VirServiceChild;
import com.palmnest.model.estateserve.VirtualAccount;
import com.palmnest.model.property.TbOrganization;
import com.palmnest.model.property.VirtualArchitecture;
import com.palmnest.service.OrganizationManager;
import com.palmnest.service.estateserve.AppUserManager;
import com.palmnest.service.estateserve.EnterprisePermissionManager;
import com.palmnest.service.estateserve.ServiceProjectAllocationManager;
import com.palmnest.service.estateserve.VirtualArchManager;
import com.palmnest.service.impl.GenericManagerImpl;
import com.palmnest.service.virtProject.manager.VirtualAccountManager;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import scala.Int;

import java.util.*;

/**
 * @Author HIAPAD
 * @Description TODO
 * @Date 2019/2/25 9:36
 **/
@Slf4j
@Service("enterprisePermissionManager")
public class EnterprisePermissionManagerImpl extends GenericManagerImpl<VirPermConfig, Long> implements EnterprisePermissionManager {


	private EnterprisePermissionDao enterprisePermissionDao;

	@Autowired
	public void setEnterprisePermissionDao(EnterprisePermissionDao enterprisePermissionDao) {
		this.enterprisePermissionDao = enterprisePermissionDao;
		this.dao = enterprisePermissionDao;
	}

	@Autowired
	private VirtualArchManager              virtualArchManager;
	@Autowired
	private OrganizationManager             organizationManager;
	@Autowired
	private ServiceProjectAllocationManager serviceProjectAllocationManager;
	@Autowired
	private AppUserManager                  appUserManager;
	@Autowired
	private VirtualAccountManager           virtualAccountManager;

    @Autowired
    private GoodsCompanyDao                   goodsCompanyDao;
	/**
	 * 新增 或 更新 企业权限
	 *
	 * @param virServiceBO
	 */
	@Override
	public void addUpdateVirPerm(VirServiceBO virServiceBO) {

		if (virServiceBO.getId() == null) {

			// 新增
			VirPermConfig config = new VirPermConfig();

			config.setCreateTime(new Date());
			config.setCreator(virServiceBO.getCreator());
			config.setEnable(1);
//            config.setGeneral(virServiceBO.getIsGeneral());
			config.setName(virServiceBO.getVirPermName());
			config.setOrgId(virServiceBO.getOrgId());
			config.setPermType(virServiceBO.getPermType());

			if (virServiceBO.getPermType().equals(1)) {// 身份权限配置
				config.setVirId(virServiceBO.getVirId());
			}

			config.setCheckRole(virServiceBO.getCheckRole());

			VirPermConfig save = enterprisePermissionDao.save(config);

			System.out.println(save.getId());

			if (StringUtils.isNotBlank(virServiceBO.getServiceId())) {
				saveVirPermServiceRelation(save.getId(), virServiceBO.getServiceId());
			}

			if (StringUtils.isNotBlank(virServiceBO.getServiceChildId())) {
				saveVirPermService(save.getId(), virServiceBO.getServiceChildId());
			}

		} else {

			// 修改
			VirPermConfig config = enterprisePermissionDao.get(virServiceBO.getId());

			config.setModifyTime(new Date());
			config.setName(virServiceBO.getVirPermName());
			config.setOrgId(virServiceBO.getOrgId());
			config.setCheckRole(virServiceBO.getCheckRole());

			if (virServiceBO.getPermType().equals(1)) {// 身份权限配置
				config.setVirId(virServiceBO.getVirId());
			}

			enterprisePermissionDao.save(config);

			// 先删除之前的旧关系数据,然后新增
			enterprisePermissionDao.delVirPermServiceRelation(virServiceBO.getId());

			if (StringUtils.isNotBlank(virServiceBO.getServiceId())) {
				saveVirPermServiceRelation(virServiceBO.getId(), virServiceBO.getServiceId());
			}

			// 先删除之前的旧关系数据,然后新增
			enterprisePermissionDao.delVirPermService(virServiceBO.getId());

			if (StringUtils.isNotBlank(virServiceBO.getServiceChildId())) {
				saveVirPermService(virServiceBO.getId(), virServiceBO.getServiceChildId());
			}
		}
	}

	public void saveVirPermServiceRelation(Long virPermId, String serviceId) {
		String[] serviceIds = serviceId.split(";");
		for (String id : serviceIds) {
			VirServiceRelation relation = new VirServiceRelation();
			relation.setCreateTime(new Date());
			relation.setServiceId(Integer.parseInt(id));
			relation.setVirPermId(virPermId);
			enterprisePermissionDao.saveOtherObj(relation);
		}
	}

	public void saveVirPermService(Long virPermId, String serviceChildId) {
		String[] serviceIds = serviceChildId.split(";");
		for (String id : serviceIds) {
			VirServiceChild relation = new VirServiceChild();
			relation.setServiceChildId(Integer.parseInt(id));
			relation.setVirPermId(virPermId);
			enterprisePermissionDao.saveOtherObj(relation);
		}
	}

	@Override
	public Page queryVirPermListPage(int pageNo, int pageSize, String sql) {

		Page page = enterprisePermissionDao.queryVirPermListPage(pageNo, pageSize, sql);

		List<Map<String, Object>> items = page.getItems();

		if (!CollectionUtils.isEmpty(items)) {
			for (Map<String, Object> map : items) {
				// 查询每个企业权限关联的服务

				List<OpenedFunctionOutDto> dtos  = new ArrayList<>();
				List<OpenedFunctionOutDto> dtos2 = new ArrayList<>();

				List<Map<String, Object>> list         = enterprisePermissionDao.getVirPermService(Long.parseLong(map.get("id").toString()));
				List<Integer>             relationList = enterprisePermissionDao.getVirPermServiceIds(Long.parseLong(map.get("id").toString()));

				if (list != null && list.size() > 0) {

					for (Map<String, Object> service : list) {

						OpenedFunctionOutDto dto = new OpenedFunctionOutDto();

						dto.setId((Integer) service.get("id"));
						dto.setServiceId((Integer) service.get("serviceId"));
						dto.setName((String) service.get("name"));

						dtos.add(dto);

						if (relationList.contains(dto.getId())) {
							dto.setChecked(true);
						} else {
							dto.setChecked(false);
						}
					}
				}

				List<Integer> serviceIdList = new ArrayList<>();

				for (OpenedFunctionOutDto openedFunctionOutDto : dtos) {
					serviceIdList.add(openedFunctionOutDto.getServiceId());
				}

				List<OpenedFunctionOutDto> serviceChildList = serviceProjectAllocationManager.getOpenedFunctionServiceChildList(serviceIdList);
				List<Integer>              relationList1    = enterprisePermissionDao.getVirPermServiceChildIds(Long.parseLong(map.get("id").toString()));

				for (OpenedFunctionOutDto dto : serviceChildList) {
					if (relationList1.contains(dto.getId())) {
						dto.setChecked(true);
					} else {
						dto.setChecked(false);
					}
				}
//                List<Map<String, Object>> list1 = enterprisePermissionDao.getVirPermServiceChild(Long.parseLong(map.get("id").toString()));
//                if (list1 != null && list1.size() > 0) {
//                    for (Map<String, Object> service : list1) {
//                        OpenedFunctionOutDto dto = new OpenedFunctionOutDto();
//                        dto.setId((Integer) service.get("id"));
//                        dto.setServiceId((Integer) service.get("serviceId"));
//                        dto.setName((String) service.get("name"));
//                        dto.setCode((String) service.get("code"));
//                        dtos2.add(dto);
//                    }
//                }


				String relation = enterprisePermissionDao.getVirPermServiceRelationStr(Long.parseLong(map.get("id").toString()));

				map.put("funcListStr", relation);
				map.put("funcList", dtos);
				map.put("funcChildList", serviceChildList);
//                map.put("funcChildList", dtos2);
				map.put("createTime", map.get("createTime").toString());
			}
		}

		page.setItems(items);

		return page;
	}

	@Override
	public void delVirPerm(Long id) {

		// 修改
		VirPermConfig config = enterprisePermissionDao.get(id);

		config.setModifyTime(new Date());
		config.setEnable(0);

		enterprisePermissionDao.save(config);
		// 先删除之前的旧关系数据,然后新增
		enterprisePermissionDao.delVirPermServiceRelation(id);
	}

	@Override
	public void batchSetVirPerm(String virIds, String virPermId) {

		if (StringUtils.isNotBlank(virIds)) {
			// 先清除该权限下原先绑定的企业,然后重新关联
			enterprisePermissionDao.clearVirPermRelation(Long.parseLong(virPermId));

			String[] virIdArray = virIds.split(";");
			for (String virId : virIdArray) {
				VirtualArchitecture virInfo = virtualArchManager.get(Integer.parseInt(virId));
				virInfo.setVirType(Long.parseLong(virPermId));
				virtualArchManager.updateModel(virInfo);
			}
		}
	}

	@Override
	public VirPermConfigDTO virPermInfo(Long virPermId) {

		// 查询详情
		VirPermConfig config = enterprisePermissionDao.get(virPermId);

		// 对返回结果进行封装
		VirPermConfigDTO virPermConfigDTO = new VirPermConfigDTO();
		virPermConfigDTO.setId(virPermId);
		virPermConfigDTO.setOrgId(config.getOrgId());
		virPermConfigDTO.setName(config.getName());
		virPermConfigDTO.setCheckRole(config.getCheckRole());
		TbOrganization organization = organizationManager.getOrganizationById(config.getOrgId());
		virPermConfigDTO.setOrgName(organization.getName());
		if (config.getVirId() != null) {
			virPermConfigDTO.setVirId(config.getVirId());
			VirtualArchitecture architecture = virtualArchManager.get(config.getVirId());
			virPermConfigDTO.setVirName(architecture.getName());
		}

		// 先查询当前项目下的开启权限配置的功能列表
		List<OpenedFunctionOutDto> serviceList = serviceProjectAllocationManager.getOpenedFunctionServiceList(config.getOrgId());
		// 查询该权限已关联的服务列表
		List<Integer> relationList = enterprisePermissionDao.getVirPermServiceIds(virPermId);
		for (OpenedFunctionOutDto dto : serviceList) {
			if (relationList.contains(dto.getId())) {
				dto.setChecked(true);
			} else {
				dto.setChecked(false);
			}
		}

		List<Integer> serviceIdList = new ArrayList<>();

		for (OpenedFunctionOutDto openedFunctionOutDto : serviceList) {
			serviceIdList.add(openedFunctionOutDto.getServiceId());
		}
		List<OpenedFunctionOutDto> serviceChildList = serviceProjectAllocationManager.getOpenedFunctionServiceChildList(serviceIdList);
		List<Integer>              relationList1    = enterprisePermissionDao.getVirPermServiceChildIds(virPermId);
		for (OpenedFunctionOutDto dto : serviceChildList) {
			if (relationList1.contains(dto.getId())) {
				dto.setChecked(true);
			} else {
				dto.setChecked(false);
			}
		}


		virPermConfigDTO.setFuncList(serviceList);
		virPermConfigDTO.setFuncChildList(serviceChildList);
		return virPermConfigDTO;
	}

	/**
	 * @param orgId
	 * @return
	 */
	public List<Map<String, Object>> getOrgRelationVirPermList(Integer orgId) {
		// 获取当前项目下配置的企业权限列表
		List<VirPermConfig> virPermList = enterprisePermissionDao.getOrgRelationVirPermList(orgId);
		return getRealtionList(virPermList);
	}

	private List<Map<String, Object>> getRealtionList(List<VirPermConfig> virPermList) {

		List<Map<String, Object>> permList = new ArrayList<>();
		if (!CollectionUtils.isEmpty(virPermList)) {
			// 获取各个权限已关联的企业列表
			for (VirPermConfig config : virPermList) {
				Map<String, Object> permMap = new HashMap<>();
				permMap.put("permId", config.getId());
				permMap.put("permName", config.getName());
				List<VirtualArchitecture> virListByPermId = enterprisePermissionDao.getVirListByPermId(config.getId());

				List<Map<String, Object>> virList = new ArrayList<>();
				for (VirtualArchitecture vir : virListByPermId) {
					Map<String, Object> virInfo = new HashMap<>();
					virInfo.put("virId", vir.getId());
					virInfo.put("virName", vir.getName());
					virList.add(virInfo);
				}
				permMap.put("virList", virList);
				permList.add(permMap);
			}
		}
		return permList;
	}

	@Override
	public List<Map<String, Object>> getVirPermServiceRelation(Long id) {
		return enterprisePermissionDao.getVirPermServiceRelation(id);
	}

	@Override
	public String getVirPermServiceRelationStr(Long id) {
		return enterprisePermissionDao.getVirPermServiceRelationStr(id);
	}

	@Override
	public List<Map<String, Object>> getVirPermService(long id) {
		return enterprisePermissionDao.getVirPermService(id);
	}

	@Override
	public void saveOrUpdateGoodsConfig(Long orgId, String[] virLists, String[] proLists, String[] passVirLists, String[] passProLists, boolean isSaveGoodsRelease,String companyName,String type) {
		int sort = 1;
		if (isSaveGoodsRelease) { //物品 1,2 电子3,4
			enterprisePermissionDao.delGoodsConfig(orgId, "1,2");
		} else {
			enterprisePermissionDao.delGoodsConfig(orgId, "3,4");
		}

		if (virLists != null && virLists.length > 0) {
			for (String virId : virLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(1);
				goodsConfig.setRoleId(Integer.parseInt(virId));
				goodsConfig.setSort(sort++);
				goodsConfig.setProcessType(1);
				enterprisePermissionDao.saveOtherObj(goodsConfig);
			}
		}
		if (proLists != null && proLists.length > 0) {
			for (String proId : proLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(2);
				goodsConfig.setRoleId(Integer.parseInt(proId));
				goodsConfig.setSort(sort++);
				goodsConfig.setProcessType(1);
				enterprisePermissionDao.saveOtherObj(goodsConfig);
			}
		}


		if (passVirLists != null && passVirLists.length > 0) {
			for (String virId : passVirLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(3);
				goodsConfig.setRoleId(Integer.parseInt(virId));
				goodsConfig.setSort(sort++);
				enterprisePermissionDao.saveOtherObj(goodsConfig);
			}
		}
		if (passProLists != null && passProLists.length > 0) {
			for (String proId : passProLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(4);
				goodsConfig.setRoleId(Integer.parseInt(proId));
				goodsConfig.setSort(sort++);
				goodsConfig.setProcessType(1);
				enterprisePermissionDao.saveOtherObj(goodsConfig);
			}
		}

		List<Map<String, Object>> list=goodsCompanyDao.getGoodsCompany(orgId);
		if (list != null && list.size() > 0) {
			goodsCompanyDao.updateGoodsCompany(orgId,companyName,type);
		}else {
			goodsCompanyDao.addGoodsCompany(orgId,companyName,type);
		}
	}



	//需要提前删除
    public void  delMoreGoodsConfig(Long orgId,boolean isSaveGoodsRelease){

		if (isSaveGoodsRelease) { //物品 1,2 电子3,4
			enterprisePermissionDao.delGoodsConfig(orgId, "1,2");
		} else {
			enterprisePermissionDao.delGoodsConfig(orgId, "3,4");
		}

	}


	@Override
	public void saveOrUpdateMoreGoodsConfig(Long orgId, Integer processType,String processName,String[] virLists, String[] proLists, String[] virNameLists, String[] proNameLists, boolean isSaveGoodsRelease,String companyName,String type) {

		int sort = 1;
		/*if (isSaveGoodsRelease) { //物品 1,2 电子3,4
			enterprisePermissionDao.delGoodsConfig(orgId, "1,2");
		} else {
			enterprisePermissionDao.delGoodsConfig(orgId, "3,4");
		}*/

		if (virLists != null && virLists.length > 0) {

			int virIdNum =0;
			for (String virId : virLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(1);
				goodsConfig.setRoleId(Integer.parseInt(virId));
				goodsConfig.setRoleName(virNameLists[virIdNum]);
				goodsConfig.setSort(sort++);

				goodsConfig.setProcessType(processType);
				goodsConfig.setProcessName(processName);

				enterprisePermissionDao.saveOtherObj(goodsConfig);
				++virIdNum;
			}
		}
		if (proLists != null && proLists.length > 0) {

			int proIdNum = 0;
			for (String proId : proLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(2);
				goodsConfig.setRoleId(Integer.parseInt(proId));
				goodsConfig.setRoleName(proNameLists[proIdNum]);
				goodsConfig.setSort(sort++);

				goodsConfig.setProcessType(processType);
				goodsConfig.setProcessName(processName);

				enterprisePermissionDao.saveOtherObj(goodsConfig);
				++proIdNum;
			}
		}


		/*if (passVirLists != null && passVirLists.length > 0) {
			for (String virId : passVirLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(3);
				goodsConfig.setRoleId(Integer.parseInt(virId));
				goodsConfig.setSort(sort++);

				goodsConfig.setProcessType(processType);
				goodsConfig.setProcessName(processName);

				enterprisePermissionDao.saveOtherObj(goodsConfig);
			}
		}*/

		/*if (passProLists != null && passProLists.length > 0) {
			for (String proId : passProLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(4);
				goodsConfig.setRoleId(Integer.parseInt(proId));
				goodsConfig.setSort(sort++);

				goodsConfig.setProcessType(processType);
				goodsConfig.setProcessName(processName);

				enterprisePermissionDao.saveOtherObj(goodsConfig);
			}
		}*/

		List<Map<String, Object>> list=goodsCompanyDao.getGoodsCompany(orgId);
		if (list != null && list.size() > 0) {
			goodsCompanyDao.updateGoodsCompany(orgId,companyName,type);
		}else {
			goodsCompanyDao.addGoodsCompany(orgId,companyName,type);
		}
	}

	@Override
	public void saveOrUpdateAirConfig(Long orgId, String[] virLists, String[] proLists) {
		int sort = 1;

		enterprisePermissionDao.delGoodsConfig(orgId, "5,6");

		if (virLists != null && virLists.length > 0) {
			for (String virId : virLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(5);
				goodsConfig.setRoleId(Integer.parseInt(virId));
				goodsConfig.setSort(sort++);
				goodsConfig.setProcessType(1);
				enterprisePermissionDao.saveOtherObj(goodsConfig);
			}
		}
		if (proLists != null && proLists.length > 0) {
			for (String proId : proLists) {
				GoodsConfig goodsConfig = new GoodsConfig();
				goodsConfig.setOrgId(orgId);
				goodsConfig.setType(6);
				goodsConfig.setRoleId(Integer.parseInt(proId));
				goodsConfig.setSort(sort++);
				goodsConfig.setProcessType(1);
				enterprisePermissionDao.saveOtherObj(goodsConfig);
			}
		}
	}


	@Override
	public Map<String, Object> getGoodsConfig(Long id) {

		log.info("===>电子等配置流程-getGoodsConfig-OrgId:{}",id);

		Map<String, Object> map = new HashMap<>();
		map.put("orgId", id);
		List<Map<String, Object>> list  = enterprisePermissionDao.getGoodsConfig(id, "1","");
		List<Map<String, Object>> list2 = enterprisePermissionDao.getGoodsConfig(id, "2","");
		map.put("virList", list);//电子放行
		map.put("proList", list2);

		List<Map<String, Object>> lis3  = enterprisePermissionDao.getGoodsConfig(id, "3","");
		List<Map<String, Object>> list4 = enterprisePermissionDao.getGoodsConfig(id, "4","");
		map.put("passVirList", lis3);//电子通行
		map.put("passProList", list4);


		List<Map<String, Object>> lis5  = enterprisePermissionDao.getGoodsConfig(id, "5","");
		List<Map<String, Object>> list6 = enterprisePermissionDao.getGoodsConfig(id, "6","");
		map.put("airVirList", lis5);//空调加时
		map.put("airProList", list6);

		return map;
	}

	@Override
	public List<Map<String, Object>>  getProcessName(Long orgId, String types) {
		return enterprisePermissionDao.getProcessName(orgId,types);
	}


	@Override
	public Map<String, Object> getMoreGoodsConfig(Long id,String processName) {

		log.info("===>电子等配置流程-多级-getMoreGoodsConfig-OrgId:{}",id);

		Map<String, Object> map = new HashMap<>();
		map.put("orgId", id);
		List<Map<String, Object>> list  = enterprisePermissionDao.getGoodsConfig(id, "1",processName);
		List<Map<String, Object>> list2 = enterprisePermissionDao.getGoodsConfig(id, "2",processName);
		map.put("virList", list);//电子放行
		map.put("proList", list2);

		Integer processType = 1;
		if(list.size()>=1){
			processType = Integer.valueOf(list.get(0).get("processType").toString());
		}
		if(list2.size()>=1){
			processType = Integer.valueOf(list2.get(0).get("processType").toString());
		}
		map.put("processType", processType);
        map.put("processName", processName);

		//List<Map<String, Object>> lis3  = enterprisePermissionDao.getGoodsConfig(id, "3");
		//List<Map<String, Object>> list4 = enterprisePermissionDao.getGoodsConfig(id, "4");
		//map.put("passVirList", lis3);//电子通行
		//map.put("passProList", list4);


		//List<Map<String, Object>> lis5  = enterprisePermissionDao.getGoodsConfig(id, "5");
		//List<Map<String, Object>> list6 = enterprisePermissionDao.getGoodsConfig(id, "6");
		//map.put("airVirList", lis5);//空调加时
		//map.put("airProList", list6);

		return map;
	}

	@Override
	public List<Map<String, Object>> getPermByCheckRole(Long orgId) {
		return enterprisePermissionDao.getPermByCheckRole(orgId);
	}

	@Override
	public Boolean checkedHasFuncPerm(Integer id, String serviceCode, Integer accountType) {

		if (accountType.equals(0)) {
			// 企业账号
			VirtualAccount virtualAccount = virtualAccountManager.get(id.longValue());
			// 获取企业所属权限组
			VirtualArchitecture virtualArchitecture = virtualArchManager.get(virtualAccount.getVirId());

			if (Objects.isNull(virtualArchitecture.getVirType())) {
				// 如果该企业没分配权限,则默认使用所有;
				return true;
			}
			// 查询该企业账号无权限的服务列表(编码列表)
			List<String> permList = enterprisePermissionDao
					.getNoPermServiceCodeList(virtualArchitecture.getOrganizationId(), virtualArchitecture.getVirType());

			if (permList.contains(serviceCode)) {
				return false;
			}

		} else if (accountType.equals(1)) {
			// 个人账号 查询该用户所对应的权限列表(低权限用户不拦截,由原有逻辑去校验)
			AppUser user = appUserManager.get(id);
			if ("-1".equals(user.getUserType())) {
				return true;
			}

			if (Objects.isNull(user.getVirPermId())) {
				// 1.如果用户没分配权限,则默认使用所有;
				// 2.如果该项目没有配置功能权限的服务,则默认使用所有;
				return true;
			}

			// 查询该用户无权限的服务列表(编码列表)
			List<String> permList = enterprisePermissionDao.getNoPermServiceCodeList(user.getOrganizationId(), user.getVirPermId());
			if (permList.contains(serviceCode)) {
				return false;
			}
		}

		return true;
	}

	@Override
	public List<OpenedFunctionOutDto> checkedServiceChild(Integer id) {

		List<OpenedFunctionOutDto> dtos2 = new ArrayList<>();

		List<Map<String, Object>> list1 = enterprisePermissionDao.getVirPermServiceChild(id);
		if (list1 != null && list1.size() > 0) {
			for (Map<String, Object> service : list1) {
				OpenedFunctionOutDto dto = new OpenedFunctionOutDto();
				dto.setId((Integer) service.get("id"));
				dto.setName((String) service.get("name"));
				dtos2.add(dto);
			}
		}

		return dtos2;
	}

}
