package com.palmnest.service.estateserve.impl;

import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

import com.palmnest.dao.estateserve.*;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.directwebremoting.util.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.palmnest.application.bean.AppResultDto;
import com.palmnest.application.bean.Page;
import com.palmnest.application.core.util.AppResultUtil;
import com.palmnest.application.core.util.PushMessageHelper;
import com.palmnest.application.core.util.RegularPattern;
import com.palmnest.application.dto.VirInfoDto;
import com.palmnest.application.dto.input.MeetingPushDto;
import com.palmnest.application.dto.input.MetingBizAccountDto;
import com.palmnest.application.dto.input.MetingCompanyDto;
import com.palmnest.application.dto.output.VirUserOutputDto;
import com.palmnest.application.dto.output.returnCompanyDto;
import com.palmnest.dao.OrganizationDao;
import com.palmnest.dao.UserDao;
import com.palmnest.dao.property.PropertyDao;
import com.palmnest.model.EnterpriseInfo;
import com.palmnest.model.FloorInfo;
import com.palmnest.model.RoomInfo;
import com.palmnest.model.User;
import com.palmnest.model.VirtUserInfo;
import com.palmnest.model.estateserve.AppUser;
import com.palmnest.model.estateserve.VirUser;
import com.palmnest.model.estateserve.VirtualAccount;
import com.palmnest.model.estateserve.WxUser;
import com.palmnest.model.property.TbOrganization;
import com.palmnest.model.property.VirtualArchitecture;
import com.palmnest.service.estateserve.VirtualArchManager;
import com.palmnest.service.impl.GenericManagerImpl;

/**
 * 企业信息
 *
 * @author longmeizhen
 */
@Service("virtualArchManager")
public class VirtualArchManagerImpl extends GenericManagerImpl<VirtualArchitecture, Integer> implements VirtualArchManager {
	private Logger LOG = Logger.getLogger(AppUserManagerImpl.class);


	private VirtualArchDao virtualArchDao;

	@Autowired
	public void setVirtualArchDao(VirtualArchDao virtualArchDao) {
		this.virtualArchDao = virtualArchDao;
		this.dao = virtualArchDao;
	}

	@Autowired
	private OrganizationDao         organizationDao;
	@Autowired
	private FloorInfoDao            floorInfoDao;
	@Autowired
	private RoomInfoDao             roomInfoDao;
	@Autowired
	private AppUserDao              appUserDao;
	@Autowired
	private VirtUserDao             virtUserDao;
	@Autowired
	private PropertyDao             propertyDao;
	@Autowired
	private EnterpriseDao           enterpriseDao;
	@Autowired
	private UserDao                 userDao;
	@Autowired
	private ScWxuserDao             scWxuserDao;
	@Autowired
	private VirtualAccountDao       virtualAccountDao;
	@Autowired
	private EnterprisePermissionDao enterprisePermissionDao;

	@Override
	public VirtualArchitecture get(Integer id) {
		return virtualArchDao.get(id);
	}


	@Transactional
	@Override
	public Page queryVirtualArchList(String orgId, String floorId, String roomId, String isZuStatus, String virName, int pageNo, int pageSize)
			throws Exception {
		Page page = virtualArchDao.queryVirtualArchList(orgId, floorId, roomId, isZuStatus, virName, pageNo, pageSize);
		List list = page.getItems();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				Map<String, String> map = new HashMap<String, String>();
				Map<Object, Object> obj = (Map<Object, Object>) list.get(i);
				int virId = Integer.parseInt(obj.get("id").toString());
				List<VirtUserInfo> vuList = virtUserDao.getVirUserByVirId(virId);
				for (int j = 0; j < vuList.size(); j++) {
					VirtUserInfo vuser = vuList.get(j);
					AppUser user = appUserDao.get(vuser.getUserId());
					int order = vuser.getReorder();
					obj.put("userOrder" + order, vuser.getReorder());
					obj.put("userName" + order, user.getUserName() == null ? "" : user.getUserName());
					obj.put("userTel" + order, user.getUserMobile() == null ? "" : user.getUserMobile());
					obj.put("userEmail" + order, user.getEmail() == null ? "" : user.getEmail());
					obj.put("isPushPower" + order, user.getIsPushPower());
					obj.put("isReleasePower" + order, user.getIsReleasePower());
				}

				// 添加企业/身份 类型信息
				// 查询每个企业权限关联的服务
				if (!Objects.equals(null, obj.get("virType"))) {
					// 设置权限列表
					String relation = enterprisePermissionDao.getVirPermServiceRelationStr(Long.parseLong(obj.get("virType").toString()));
					obj.put("funcList", StringUtils.isBlank(relation) ? "" : relation);

					// 设置权限名称;如果权限列表为空,则权限名称显示 暂未设置;否则显示对应权限名称
					if (StringUtils.isBlank(relation)) {
						obj.put("virPermName", "暂未设置");
					}

				} else {
					obj.put("funcList", "");
				}
			}
		}

		return page;
	}

	@Transactional
	@Override
	public List<VirtualArchitecture> getVirByParamt(String floorId, String roomId, String isZuStatus, String virName, int pageNo, int pageSize) throws Exception {
		return virtualArchDao.getVirByParamt(floorId, roomId, isZuStatus, virName, pageNo, pageSize);
	}

	@Transactional
	@Override
	public List<AppUser> getAppUserByVirAndIsRes(int virId) throws Exception {
		return virtualArchDao.getAppUserByVirAndIsRes(virId);
	}

	/**
	 * 导入模板
	 */
	@Transactional
	@Override
	public Map<String, Object> saveImportVirtualData(InputStream ins) throws Exception {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Object> userList = new ArrayList<Object>();
		int bugCount = 0;
		StringBuffer bugStr = new StringBuffer("");
		Sheet sheet = null;
		try {
			Workbook workbook = WorkbookFactory.create(ins);
			sheet = workbook.getSheet("VirtualArchitecture");
		} catch (Exception e) {
			bugStr.append("模板格式有问题，请下载最新的模板");
		}

		try {
			if (sheet == null) {
				bugStr.append("模板格式有问题，请下载最新的模板");
			} else {
				int rows = sheet.getLastRowNum();
				//如果大于2000行数据
				if (rows > 20000) {
					bugStr.append("数据量太大，不能大于2w行");
				} else if (rows < 1) {
					bugStr.append("数据为空，请录入账单信息");
				} else {
					for (int i = 1; i <= rows; i++) {
						if (sheet.getRow(i) == null) {
							continue;
						}

						//查询楼宇是否存在？
						if (sheet.getRow(i).getCell(0) == null) {
							bugStr.append("第" + i + "行第1列数据有问题，请检查，问题：楼宇信息必填，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}
						sheet.getRow(i).getCell(0).setCellType(Cell.CELL_TYPE_STRING);

						if (StringUtils.isBlank(sheet.getRow(i).getCell(0).getStringCellValue())) {
							bugStr.append("第" + i + "行第1列数据有问题，请检查，问题：楼宇信息必填，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}
						String orgName = sheet.getRow(i).getCell(0).getStringCellValue();
						TbOrganization tbOrganization = organizationDao.getOrganizationInfoByName(orgName);
						if (tbOrganization == null) {
							bugStr.append("第" + i + "行第1列数据有问题，请检查，问题：楼宇信息不存在，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}
						//楼层
						String floorIds = "";
						if (sheet.getRow(i).getCell(1) == null) {
							bugStr.append("第" + i + "行第2列数据有问题，请检查，问题：楼层信息有误(以逗号','隔开)，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}
						sheet.getRow(i).getCell(1).setCellType(Cell.CELL_TYPE_STRING);
						String floorNames = sheet.getRow(i).getCell(1).getStringCellValue();
						if (StringUtils.isNotBlank(floorNames)) {
							floorNames = floorNames.replace("，", ",").trim();
							String[] floorStr = floorNames.split(",");
							if (floorStr == null || floorStr.length <= 0) {
								bugStr.append("第" + i + "行第2列数据有问题，请检查，问题：楼层信息有误(以逗号','隔开)，请导出系统模板匹配录入<br/>");
								bugCount++;
								continue;
							} else {
								String str = "";
								for (int j = 0; j < floorStr.length; j++) {
									if (StringUtils.isNotBlank(floorStr[j])) {
										str += "'" + floorStr[j] + "',";
									}
								}
								if (StringUtils.isNotEmpty(str)) {
									str = str.substring(0, str.length() - 1);
									List<FloorInfo> floorList = floorInfoDao.getFloorListByOrgId(tbOrganization.getId(), str);
									if (floorList == null || floorList.size() <= 0) {
										bugStr.append("第" + i + "行第2列数据有问题，请检查，问题：楼层信息不存在，请导出系统模板匹配录入<br/>");
										bugCount++;
										continue;
									}
									for (int j = 0; j < floorList.size(); j++) {
										FloorInfo info = floorList.get(j);
										floorIds += info.getId() + ",";
									}
									if (StringUtils.isNotBlank(floorIds)) {
										floorIds = floorIds.substring(0, floorIds.length() - 1);
									} else {
										bugStr.append("第" + i + "行第2列数据有问题，请检查，问题：楼层信息不存在，请导出系统模板匹配录入<br/>");
										bugCount++;
										continue;
									}
								} else {
									bugStr.append("第" + i + "行第2列数据有问题，请检查，问题：楼层信息有误(以逗号','隔开)，请导出系统模板匹配录入<br/>");
									bugCount++;
									continue;
								}

							}
						} else {
							bugStr.append("第" + i + "行第2列数据有问题，请检查，问题：楼层信息不存在，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}

						//房间
						String roomIds = "";
						if (sheet.getRow(i).getCell(2) == null) {
							bugStr.append("第" + i + "行第3列数据有问题，请检查，问题：房间号信息有误(以逗号','隔开)，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}
						sheet.getRow(i).getCell(2).setCellType(Cell.CELL_TYPE_STRING);
						String roomNames = sheet.getRow(i).getCell(2).getStringCellValue();
						if (StringUtils.isNotBlank(roomNames)) {
							roomNames = roomNames.replace("，", ",").trim();
							String[] roomStr = roomNames.split(",");
							if (roomStr == null || roomStr.length <= 0) {
								bugStr.append("第" + i + "行第3列数据有问题，请检查，问题：房间号信息有误(以逗号','隔开)，请导出系统模板匹配录入<br/>");
								bugCount++;
								continue;
							} else {
								String str = "";
								for (int j = 0; j < roomStr.length; j++) {
									if (StringUtils.isNotBlank(roomStr[j])) {
										str += "'" + roomStr[j] + "',";
									}

								}
								if (StringUtils.isNotEmpty(str)) {
									str = str.substring(0, str.length() - 1);
									List<RoomInfo> roomList = roomInfoDao.getRoomListByRooms(str);
									if (roomList == null) {
										bugStr.append("第" + i + "行第3列数据有问题，请检查，问题：房间号信息不存在，请导出系统模板匹配录入<br/>");
										bugCount++;
										continue;
									}
									for (int j = 0; j < roomList.size(); j++) {
										RoomInfo info = roomList.get(j);
										roomIds += info.getId() + ",";
									}
									if (StringUtils.isNotBlank(roomIds)) {
										roomIds = roomIds.substring(0, roomIds.length() - 1);
									} else {
										bugStr.append("第" + i + "行第3列数据有问题，请检查，问题：房间号信息不存在，请导出系统模板匹配录入<br/>");
										bugCount++;
										continue;
									}
								} else {
									bugStr.append("第" + i + "行第3列数据有问题，请检查，问题：房间号信息有误(以逗号','隔开)，请导出系统模板匹配录入<br/>");
									bugCount++;
									continue;
								}

							}
						} else {
							bugStr.append("第" + i + "行第2列数据有问题，请检查，问题：房间号信息不存在，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}

						//企业编码
						if (sheet.getRow(i).getCell(3) == null) {
							bugStr.append("第" + i + "行第4列数据有问题，请检查，问题：企业编码必填，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}
						sheet.getRow(i).getCell(3).setCellType(Cell.CELL_TYPE_STRING);
						if (StringUtils.isBlank(sheet.getRow(i).getCell(3).getStringCellValue())) {
							bugStr.append("第" + i + "行第4列数据有问题，请检查，问题：企业编码必填，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}
						String code = sheet.getRow(i).getCell(3).getStringCellValue();
						List<VirtualArchitecture> virList = virtualArchDao.getVirByCode(code);
						if (virList != null && virList.size() > 0) {
							bugStr.append("第" + i + "行第4列数据有问题，请检查，问题：企业编码已存在，请导出系统模板匹配录入<br/>");
							bugCount++;
							continue;
						}
						//企业名称
						String name = "";
						if (sheet.getRow(i).getCell(4) != null) {
							sheet.getRow(i).getCell(4).setCellType(Cell.CELL_TYPE_STRING);
							name = sheet.getRow(i).getCell(4).getStringCellValue();
						}

						//短信推送


						String isMessage = "";
						if (sheet.getRow(i).getCell(5) != null) {
							sheet.getRow(i).getCell(5).setCellType(Cell.CELL_TYPE_STRING);
							isMessage = sheet.getRow(i).getCell(5).getStringCellValue();
						}
						//微信推送


						String isWechat = "";
						if (sheet.getRow(i).getCell(6) != null) {
							sheet.getRow(i).getCell(6).setCellType(Cell.CELL_TYPE_STRING);
							isWechat = sheet.getRow(i).getCell(6).getStringCellValue();
						}
						//邮件推送


						String isEmail = "";
						if (sheet.getRow(i).getCell(7) != null) {
							sheet.getRow(i).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
							isEmail = sheet.getRow(i).getCell(7).getStringCellValue();
						}
						//企业在租状态


						String lessStatus = "";
						if (sheet.getRow(i).getCell(8) != null) {
							sheet.getRow(i).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
							lessStatus = sheet.getRow(i).getCell(8).getStringCellValue();
						}


						//备注


						String remark = "";
						if (sheet.getRow(i).getCell(19) != null) {
							sheet.getRow(i).getCell(19).setCellType(Cell.CELL_TYPE_STRING);
							remark = sheet.getRow(i).getCell(19).getStringCellValue();
						}

						VirtualArchitecture virtualArchitecture = new VirtualArchitecture();
						virtualArchitecture.setName(name);
						virtualArchitecture.setCode(code);
						virtualArchitecture.setParentCode("");
						virtualArchitecture.setCodeNumber(code);            //唯一编码
						virtualArchitecture.setCustomerNumber(code);        //客户编号
						virtualArchitecture.setOrganizationId(tbOrganization.getId());        //项目ID
						virtualArchitecture.setStatus("1");                //企业状态（0-待审核，1-通过，2-不通过）
						virtualArchitecture.setRemark(remark);
						virtualArchitecture.setCreateTime(new Date());
						//virtualArchitecture.setCreator("");
						virtualArchitecture.setIsEnabled("1");
						virtualArchitecture.setFloorIds(floorIds + ",");
						virtualArchitecture.setRoomIds(roomIds + ",");
						if ("是".equals(isEmail)) {
							virtualArchitecture.setIsEmail(1);
						} else {
							virtualArchitecture.setIsEmail(0);
						}


						if ("是".equals(isWechat)) {
							virtualArchitecture.setIsWechat(1);
						} else {
							virtualArchitecture.setIsWechat(0);
						}

						if ("是".equals(isMessage)) {
							virtualArchitecture.setIsMessage(1);
						} else {
							virtualArchitecture.setIsMessage(0);
						}

						if ("在租".equals(lessStatus)) {
							virtualArchitecture.setLeaseStatus(1);
						} else {
							virtualArchitecture.setLeaseStatus(0);
						}

						virtualArchitecture.setRoomNames(roomNames + ",");
						virtualArchitecture.setFloorNames(floorNames + ",");
						Map<String, Object> userMap = new HashMap<String, Object>();
						userMap.put("virInfo", virtualArchitecture);

						//负责人1名称


						String reName = "";
						if (sheet.getRow(i).getCell(9) != null) {
							sheet.getRow(i).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
							reName = sheet.getRow(i).getCell(9).getStringCellValue();
						}
						//负责人1手机号


						String reTel = "";
						if (sheet.getRow(i).getCell(10) != null) {
							sheet.getRow(i).getCell(10).setCellType(Cell.CELL_TYPE_STRING);
							reTel = sheet.getRow(i).getCell(10).getStringCellValue().trim();
							boolean bool = RegularPattern.isMobileNO(reTel);
							if (StringUtils.isNotEmpty(reTel) && !bool) {
								bugStr.append("第" + i + "行第11列数据有问题，请检查，问题：负责人1手机号码有问题，请导出系统模板匹配录入<br/>");
								bugCount++;
								continue;
							}
						}
						//负责人1邮箱


						String reEmail = "";
						if (sheet.getRow(i).getCell(11) != null) {
							sheet.getRow(i).getCell(11).setCellType(Cell.CELL_TYPE_STRING);
							reEmail = sheet.getRow(i).getCell(11).getStringCellValue().trim();
							boolean bool = RegularPattern.checkEmail(reEmail);
							if (StringUtils.isNotEmpty(reEmail) && !bool) {
								bugStr.append("第" + i + "行第12列数据有问题，请检查，问题：负责人1邮箱有问题，请导出系统模板匹配录入<br/>");
								bugCount++;
								continue;
							}
						}
						//负责人1物品放行


						String isPower = "";
						if (sheet.getRow(i).getCell(12) != null) {
							sheet.getRow(i).getCell(12).setCellType(Cell.CELL_TYPE_STRING);
							isPower = sheet.getRow(i).getCell(12).getStringCellValue();
						}
						//负责人1账单推送


						String isPush = "";
						if (sheet.getRow(i).getCell(13) != null) {
							sheet.getRow(i).getCell(13).setCellType(Cell.CELL_TYPE_STRING);
							isPush = sheet.getRow(i).getCell(13).getStringCellValue();
						}


						if (StringUtils.isNotBlank(reName)) {
							AppUser user = new AppUser();
							user.setUserName(reName);
							user.setUserMobile(reTel);
							user.setEmail(reEmail);
							user.setCreateTime(new Date());
							user.setReOrder(1);
							user.setIsEnabled("1");
							user.setIsResponsible(1);
							if ("是".equals(isPower)) {
								user.setIsReleasePower(1);
							} else {
								user.setIsReleasePower(0);
							}

							if ("是".equals(isPush)) {
								user.setIsPushPower(1);
							} else {
								user.setIsPushPower(0);
							}
							userMap.put("user1", user);
						}


						//负责人2名称


						String respName = "";
						if (sheet.getRow(i).getCell(14) != null) {
							sheet.getRow(i).getCell(14).setCellType(Cell.CELL_TYPE_STRING);
							respName = sheet.getRow(i).getCell(14).getStringCellValue();
						}
						//负责人2手机号


						String respTel = "";
						if (sheet.getRow(i).getCell(15) != null) {
							sheet.getRow(i).getCell(15).setCellType(Cell.CELL_TYPE_STRING);
							respTel = sheet.getRow(i).getCell(15).getStringCellValue().trim();
							boolean bool = RegularPattern.isMobileNO(respTel);
							if (StringUtils.isNotEmpty(respTel) && !bool) {
								bugStr.append("第" + i + "行第16列数据有问题，请检查，问题：负责人2手机号码有问题，请导出系统模板匹配录入<br/>");
								bugCount++;
								continue;
							}
						}
						//负责人2邮箱


						String respEmail = "";
						if (sheet.getRow(i).getCell(16) != null) {
							sheet.getRow(i).getCell(16).setCellType(Cell.CELL_TYPE_STRING);
							respEmail = sheet.getRow(i).getCell(16).getStringCellValue().trim();
							boolean bool = RegularPattern.checkEmail(respEmail);
							if (StringUtils.isNotEmpty(respEmail) && !bool) {
								bugStr.append("第" + i + "行第17列数据有问题，请检查，问题：负责人2邮箱有问题，请导出系统模板匹配录入<br/>");
								bugCount++;
								continue;
							}
						}
						//负责人2物品放行


						String respIsPower = "";
						if (sheet.getRow(i).getCell(17) != null) {
							sheet.getRow(i).getCell(17).setCellType(Cell.CELL_TYPE_STRING);
							respIsPower = sheet.getRow(i).getCell(17).getStringCellValue();
						}
						//负责人2账单推送


						String respIsPush = "";
						if (sheet.getRow(i).getCell(18) != null) {
							sheet.getRow(i).getCell(18).setCellType(Cell.CELL_TYPE_STRING);
							respIsPush = sheet.getRow(i).getCell(18).getStringCellValue();
						}

						if (StringUtils.isNotBlank(respName)) {
							AppUser user = new AppUser();
							user.setUserName(respName);
							user.setUserMobile(respTel);
							user.setEmail(respEmail);
							user.setCreateTime(new Date());
							user.setReOrder(2);
							user.setIsEnabled("1");
							user.setIsResponsible(1);
							if ("是".equals(respIsPower)) {
								user.setIsReleasePower(1);
							} else {
								user.setIsReleasePower(0);
							}

							if ("是".equals(respIsPush)) {
								user.setIsPushPower(1);
							} else {
								user.setIsPushPower(0);
							}
							userMap.put("user2", user);
						}

						userList.add(userMap);
					}
				}
			}
			retMap.put("bugCount", bugCount);
			retMap.put("bugStr", bugStr.toString());
			retMap.put("userList", userList);
			retMap.put("okCount", userList.size());
			return retMap;

		} catch (Exception e) {
			LOG.error(e.getMessage());
			retMap.put("bugCount", bugCount);
			retMap.put("bugStr", bugStr.toString());
			retMap.put("userList", userList);
			retMap.put("okCount", userList.size());
			e.printStackTrace();
			return retMap;
		}


	}

	@Override
	public List<TbOrganization> getBuild() throws Exception {
		return virtualArchDao.getBuild();
	}

	@Override
	public List<VirtualArchitecture> getVirByName(String name) throws Exception {
		return virtualArchDao.getVirByName(name);
	}

	@Override
	public Page queryVirList(int pageNo, int pageSize, String virIds) throws Exception {
		Page page = virtualArchDao.getVirByIds(pageNo, pageSize, virIds);
		List list = page.getItems();
		for (int i = 0; i < list.size(); i++) {
			Map<String, String> map = new HashMap<String, String>();
			Map<Object, Object> obj = (Map<Object, Object>) list.get(i);
			int virId = Integer.parseInt(obj.get("id").toString());
			List<AppUser> userList = virtualArchDao.getAppUserByVirAndIsRes(virId);
			for (int j = 0; j < userList.size(); j++) {
				AppUser user = userList.get(j);
				obj.put("userOrder", user.getReOrder());
				int order = user.getReOrder();
				obj.put("userName" + order, user.getUserName() == null ? "" : user.getUserName());
				obj.put("userTel" + order, user.getUserMobile() == null ? "" : user.getUserMobile());
				obj.put("userEmail" + order, user.getEmail() == null ? "" : user.getEmail());
				obj.put("isPushPower" + order, user.getIsPushPower());
				obj.put("isReleasePower" + order, user.getIsReleasePower());
			}
		}
		return page;
	}

	@Override
	public List<String> getBandRoomId() throws Exception {
		List<String> idList = new ArrayList<String>();//已被占用的房间号集合
		List<VirtualArchitecture> virList = virtualArchDao.getVirByEnLess();//查询出在租状态的企业列表
		List<EnterpriseInfo> enterList = enterpriseDao.getEnterListByBand();//查询出入驻待审核和审核通过的企业列表
		//将在租企业占用的房间号添加到集合中
		if (virList != null && virList.size() > 0) {
			for (int i = 0; i < virList.size(); i++) {
				VirtualArchitecture virInfo = virList.get(i);
				String[] roomIds = virInfo.getRoomIds().split(";");
				for (int j = 0; j < roomIds.length; j++) {
					idList.add(roomIds[j]);
				}
			}
		}
		//将申请中的房间号添加到集合中
		if (enterList != null && enterList.size() > 0) {
			for (int i = 0; i < enterList.size(); i++) {
				EnterpriseInfo enterInfo = enterList.get(i);
				if (enterInfo != null) {
					if (enterInfo.getVirId() == 0 && "1".equals(enterInfo.getStatus())) {//入驻待申请
						String[] roomIds = enterInfo.getRoomIds().split(";");
						for (int j = 0; j < roomIds.length; j++) {
							idList.add(roomIds[j]);
						}
					}

					//原来逻辑....
					String virId = "";
					if (enterInfo.getVirId() != 0) {
						virId = String.valueOf(enterInfo.getVirId());
					}
					if (StringUtils.isNotEmpty(virId)) {
						List<EnterpriseInfo> list = enterpriseDao.getEnterListByVirId(virId);
						if (list == null) {
							String[] roomIds = enterInfo.getRoomIds().split(";");
							for (int j = 0; j < roomIds.length; j++) {
								idList.add(roomIds[j]);
							}
						}
					}
				}
			}
		}
		return idList;
	}

	@Override
	public List<VirtualArchitecture> getVirByCode(String code) throws Exception {
		return virtualArchDao.getVirByCode(code);
	}

	@Override
	public void saveImportVir(List<Object> list, User userLi, TbOrganization tb) throws Exception {
		try {
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> map = (Map<String, Object>) list.get(i);
				if (map.get("virInfo") instanceof VirtualArchitecture) {
					VirtualArchitecture virInfo = (VirtualArchitecture) map.get("virInfo");
					virInfo.setType("1");
					String floorIds = virInfo.getFloorIds();
					virInfo.setFloorIds(floorIds.replace(",", ";"));
					virInfo.setFloorNames(virInfo.getFloorNames().replace(",", ";"));
					String roomIds = virInfo.getRoomIds();
					virInfo.setRoomIds(roomIds.replace(",", ";"));
					virInfo.setStatus("1");
					virInfo.setRoomNames(virInfo.getRoomNames().replace(",", ";"));
					virInfo = virtualArchDao.save(virInfo);
					if (map.get("user1") instanceof AppUser) {
						AppUser user = (AppUser) map.get("user1");
						AppUser user1 = new AppUser();
						AppUser appUser = appUserDao.getAppUsersByPhone(user.getUserMobile());
						if (appUser != null && appUser.getId() != null) {
							appUser.setUserName(user.getUserName());
							appUser.setEmail(user.getEmail());
							appUser.setIsPushPower(user.getIsPushPower());
							appUser.setRoleType("1");
							appUser.setIsReleasePower(user.getIsReleasePower());
							appUser.setIsResponsible(1);
							appUser.setIsEnabled("1");
							if (StringUtils.isEmpty(appUser.getStatus())) {
								appUser.setStatus("1");
							}
							appUser.setModifier(userLi.getUsername());
							appUser.setReOrder(user.getReOrder());
							appUser.setModifyTime(new Date());
							appUser.setVirtualArchId(virInfo.getId());
							appUserDao.updateObj(appUser);
							user1 = appUser;
						} else {
							user.setVirtualArchId(virInfo.getId());
							user.setOrganizationId(tb.getId());
							user.setRoleType("1");
							user.setCreator(userLi.getUsername());
							user.setStatus("1");
							user.setCreateTime(new Date());
							user1 = appUserDao.save(user);
						}
						//保存企业-用户（负责人1信息）中间表1
						VirtUserInfo vuInfo = new VirtUserInfo();
						vuInfo.setReorder(user.getReOrder());
						vuInfo.setVirId(virInfo.getId());
						vuInfo.setUserId(user1.getId());
						virtUserDao.save(vuInfo);
					}
					if (map.get("user2") instanceof AppUser) {
						AppUser user = (AppUser) map.get("user2");
						AppUser appUser = appUserDao.getAppUsersByPhone(user.getUserMobile());
						if (appUser != null && appUser.getId() != null) {
							appUser.setUserName(user.getUserName());
							appUser.setEmail(user.getEmail());
							appUser.setIsPushPower(user.getIsPushPower());
							appUser.setIsReleasePower(user.getIsReleasePower());
							appUser.setIsResponsible(1);
							appUser.setVirtualArchId(virInfo.getId());
							appUser.setRoleType("1");
							appUser.setIsEnabled("1");
							if (StringUtils.isEmpty(appUser.getStatus())) {
								appUser.setStatus("1");
							}
							appUser.setModifier(userLi.getUsername());
							appUser.setModifyTime(new Date());
							appUserDao.updateObj(appUser);
							user = appUser;
						} else {
							user.setVirtualArchId(virInfo.getId());
							user.setOrganizationId(tb.getId());
							user.setRoleType("1");
							user.setCreator(userLi.getUsername());
							user.setStatus("1");
							user.setCreateTime(new Date());
							user = appUserDao.save(user);
						}
						//保存企业-用户（负责人2信息）中间表2
						VirtUserInfo vuInfo = new VirtUserInfo();
						vuInfo.setReorder(user.getReOrder());
						vuInfo.setVirId(virInfo.getId());
						vuInfo.setUserId(user.getId());
						virtUserDao.save(vuInfo);
					}
				}
			}
		} catch (Exception e) {
			LOG.error(e.getMessage());
			throw new Exception(e);
		}

	}

	@Override
	@Transactional
	public AppResultDto saveVirUser(VirUser virUser, TbOrganization tb, User user, List<AppUser> userList, List<AppUser> list, VirtualArchitecture virtualArchitecture, List<VirtualArchitecture> virList) throws Exception {
		virtualArchitecture.setStatus("1");
		if (virtualArchitecture.getId() != null) {//修改
			virtualArchitecture.setType("1");
			virtualArchitecture.setIsEnabled("1");
			virtualArchitecture.setModifyTime(new Date());
			virtualArchitecture.setFreeLenTime(virtualArchitecture.getFreeLenTime() == null ? BigDecimal.ZERO : virtualArchitecture.getFreeLenTime());
			virtualArchitecture.setRemainderTime(virtualArchitecture.getRemainderTime() == null ? BigDecimal.ZERO : virtualArchitecture.getRemainderTime());
			virtualArchitecture.setModifier(user.getUsername());
			virtualArchDao.updateObj(virtualArchitecture);
		} else {//新增
			virtualArchitecture.setType("1");
			virtualArchitecture.setCreator(user.getUsername());
			virtualArchitecture.setCreateTime(new Date());
			virtualArchitecture.setIsEnabled("1");
			virtualArchitecture.setFreeLenTime(virtualArchitecture.getFreeLenTime() == null ? BigDecimal.ZERO : virtualArchitecture.getFreeLenTime());
			virtualArchitecture.setRemainderTime(virtualArchitecture.getRemainderTime() == null ? BigDecimal.ZERO : virtualArchitecture.getRemainderTime());
			virtualArchitecture.setCodeNumber(virtualArchitecture.getCustomerNumber());
			virtualArchitecture = virtualArchDao.save(virtualArchitecture);
		}
		virUser.setVirtualArchitecture(virtualArchitecture);


		if (virtualArchitecture != null) {
			List<VirtUserInfo> virUserList = virtUserDao.getVirUserByVirId(virtualArchitecture.getId());
			if (virUserList != null && virUserList.size() > 0) {
				virtUserDao.delVirtUserByVirtId(virtualArchitecture.getId());
			}

			for (int i = 0; i < userList.size(); i++) {
				AppUser appUser = userList.get(i);
//				if(appUser.getId()!=null){
//					appUser.setModifier(user.getUsername());
//					appUser.setModifyTime(new Date());
//					appUser.setOrganizationId(tb.getId());
//					appUser.setIsEnabled("1");
//					appUser.setIsResponsible(1);
//					appUser.setRoleType("1");
//					appUser.setVirtualArchId(virtualArchitecture.getId());
//					appUserDao.updateObj(appUser);
//				}else{
				AppUser ap = appUserDao.getAppUsersByPhone(appUser.getUserMobile());//如果根据电话号码找到对应的人，那样的话，进行修改
				AppUser ap1 = new AppUser();
				if (ap != null && ap.getId() != null) {
					ap.setUserName(appUser.getUserName());
					ap.setEmail(appUser.getEmail());
					ap.setIsPushPower(appUser.getIsPushPower());
					ap.setIsReleasePower(appUser.getIsReleasePower());
					ap.setIsResponsible(1);
					ap.setRoleType("1");
					ap.setIsEnabled("1");
					ap.setVirtualArchId(virtualArchitecture.getId());
					if (StringUtils.isEmpty(ap.getStatus())) {
						ap.setStatus("1");
					}
					ap.setModifier(user.getUsername());
//						ap.setReOrder(appUser.getReOrder());
					ap.setModifyTime(new Date());
					appUserDao.updateObj(ap);
					ap1 = ap;
				} else {
					appUser.setCreateTime(new Date());
					appUser.setCreator(user.getUsername());
					appUser.setIsEnabled("1");
					appUser.setIsResponsible(1);
					appUser.setRoleType("1");
					appUser.setStatus("1");
					appUser.setOrganizationId(tb.getId());
					appUser.setVirtualArchId(virtualArchitecture.getId());
					ap1 = appUserDao.save(appUser);
				}
				//保存企业-用户（负责人1信息）中间表1
				VirtUserInfo vuInfo = new VirtUserInfo();
				vuInfo.setReorder(appUser.getReOrder());
				vuInfo.setVirId(virtualArchitecture.getId());
				vuInfo.setUserId(ap1.getId());
				virtUserDao.save(vuInfo);
//				}
				list.add(ap1);
			}
			virUser.setUserList(list);
			return AppResultUtil.createSuccesDto(virtualArchitecture);
		} else {
			return AppResultUtil.createErrorDto("100", "操作失败");
		}
	}

	@Override
	public Map<String, Set<returnCompanyDto>> getFloorCompany(
			int organizationId) throws Exception {

		List<Map<String, Object>> listVirs = propertyDao.getVirtualListBySelectCompany(organizationId);
		//List<VirtualArchitecture> listVirs=propertyDao.getVirtualArchitectureList(organizationId);


		//按1楼-公司1 公司2 公司3 2楼-公司1 公司2 公司3 结构
		Map<String, Set<returnCompanyDto>> resultMap = new HashMap<String, Set<returnCompanyDto>>();


		//resultMap


		for (Map<String, Object> obj : listVirs) {

			returnCompanyDto vir = new returnCompanyDto();
			vir.setCompanyId((Integer) obj.get("id"));
			vir.setCompanyName((String) obj.get("name"));

			String floorIds = (String) obj.get("floorIds");

			if (StringUtils.isNotEmpty(floorIds)) {
				String[] floorStrIds = floorIds.split(";");
				for (String floor : floorStrIds) {

					if (resultMap.containsKey(floor)) {
						Set setVirs = resultMap.get(floor);
						setVirs.add(vir);
						resultMap.put(floor, setVirs);
					} else {
						Set setVirs = new HashSet<VirtualArchitecture>();
						setVirs.add(vir);
						resultMap.put(floor, setVirs);
					}
				}
			}

		}

		//排序

		return resultMap;
	}

	@Override
	public List<VirtualArchitecture> getVirByRoomId(String roomIds)
			throws Exception {
		return virtualArchDao.getVirByRoomId(roomIds);
	}

	@Transactional
	public String updateVirInfo(String virId, String remainderTime, String freeLenTime) throws Exception {
		VirtualArchitecture virInfo = virtualArchDao.get(Integer.parseInt(virId));
		String msg = "";
		try {
			if (virInfo != null) {
				if (StringUtils.isEmpty(freeLenTime)) {
					freeLenTime = "0";
				}
				if (StringUtils.isEmpty(remainderTime)) {
					remainderTime = "0";
				}
				BigDecimal bigFreeTime = new BigDecimal(freeLenTime);
				BigDecimal bigRemainderTime = new BigDecimal(remainderTime);
				if (bigRemainderTime.compareTo(bigFreeTime) == 1) {
					msg = "剩余时长不能大于免费时长";
					return msg;
				}
				virInfo.setFreeLenTime(bigFreeTime);
				virInfo.setRemainderTime(bigRemainderTime);
				virtualArchDao.updateObj(virInfo);
			}
		} catch (Exception e) {
			LOG.error(e.getMessage());
		}
		return msg;
	}

	@Async
	public String sendPushMessage(MeetingPushDto mePushDto) throws Exception {
		LOG.info("VirtualArchManagerImpl sendPushMessage======");

		String id = mePushDto.getId();
		String code = mePushDto.getCode();
		String title = mePushDto.getTitle();
		String content = mePushDto.getContent();
		//List<String> userList=mePushDto.getUsers();
		String userList = mePushDto.getUsers();

		LOG.info("sendPushMessage======" + mePushDto.toString());
		LOG.info("sendPushMessage===[id]===" + id);
		LOG.info("sendPushMessage===[code]===" + code);
		LOG.info("sendPushMessage===[title]===" + title);
		LOG.info("sendPushMessage===[content]===" + content);
		LOG.info("sendPushMessage===[userList]===" + userList);


		List<User> users = new ArrayList<User>();
		if (StringUtils.isNotEmpty(userList)) {
			String[] userListStrs = userList.split(";");

			for (int i = 0; i < userListStrs.length; i++) {
				String userId = userListStrs[i];
				if (StringUtils.isNotEmpty(userId)) {
					if (userDao.exists(Long.parseLong(userId))) {
						User user = userDao.get(Long.parseLong(userId));
						users.add(user);
					}

				}
			}

			try {
				if (users != null && users.size() > 0) {
					PushMessageHelper helper=new PushMessageHelper();
					helper.pushMessageTwo(id, code, users, title, content);
				}
			} catch (Exception e) {
				e.printStackTrace();
				LOG.error(e.getMessage());
			}


		}
		
		
		/*if(userList!=null&&userList.size()>0){
			List<User> users=new ArrayList<User>();
			for(int i=0;i<userList.size();i++){
				String userId=userList.get(i);
				if(StringUtils.isNotEmpty(userId)){
					User user=userDao.get(Long.parseLong(userId));
					users.add(user);
				}
			}
			try {
				if(users!=null&&users.size()>0){
					PushMessageHelper.pushMessage(Long.parseLong(id), code, users, title, content);
				}
			}catch (Exception e) {
				e.printStackTrace();
				LOG.error(e.getMessage());
			}
		}*/
		LOG.info("VirtualArchManagerImpl sendPushMessage======");
		return null;
	}

	@Override
	public Map<String, Object> getOpenIdByCompanyId(String virId) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		List<VirtUserInfo> virList = virtUserDao.getVirUserByVirId(Integer.parseInt(virId));
		String openId1 = "";
		String openId2 = "";
		if (virList != null && virList.size() > 0) {
			for (int i = 0; i < virList.size(); i++) {
				VirtUserInfo virUserInfo = virList.get(i);
				if (virUserInfo != null) {
					int order = virUserInfo.getReorder();
					int userId = virUserInfo.getUserId();
					try {
						WxUser wxUser = scWxuserDao.getScWxuserByUserId(userId);
						if (order == 1) {
							openId1 = wxUser.getOpenId();
						} else if (order == 2) {
							openId2 = wxUser.getOpenId();
						}
					} catch (Exception e) {
						e.printStackTrace();
						LOG.error(e.getMessage());
					}
				}
			}
		}
		map.put("openId1", openId1);
		map.put("openId2", openId2);
		return map;
	}

	@Override
	public String updateVirInfoByUseTime(String virId, String useTime) throws Exception {
		VirtualArchitecture virInfo = virtualArchDao.get(Integer.parseInt(virId));
		String msg = "";
		try {
			if (virInfo != null) {
				BigDecimal bigRemainTime = virInfo.getRemainderTime() == null ? BigDecimal.ZERO : virInfo.getRemainderTime();
				BigDecimal bigUseTime = new BigDecimal(useTime);
				BigDecimal bigReTime = bigRemainTime.subtract(bigUseTime);
				if (bigReTime.compareTo(virInfo.getFreeLenTime() == null ? BigDecimal.ZERO : virInfo.getFreeLenTime()) == 1) {
					msg = "本次使用时长不能大于免费时长";
					return msg;
				}
				if (BigDecimal.ZERO.compareTo(bigReTime) == 1) {
					msg = "剩余时长不能小于0";
					return msg;
				} else {
					virInfo.setRemainderTime(bigReTime);
					virtualArchDao.updateObj(virInfo);
				}
			}
		} catch (Exception e) {
			LOG.error(e.getMessage());
			msg = e.getMessage();
		}
		return msg;
	}

	@Transactional
	public String saveVirUserList(Integer virId, List<VirUserOutputDto> userVirList) throws Exception {
		String res = "FAIL";
		try {
			if (virtualArchDao.exists(virId)) {
				VirtualArchitecture virInfo = virtualArchDao.get(virId);
				if (virId != null && virId != 0) {
					List<VirtUserInfo> virUserList = virtUserDao.getVirUserByVirId(virId);
					if (virUserList != null && virUserList.size() > 0) {
						virtUserDao.delVirtUserByVirtId(virId);
					}
					for (int i = 0; i < userVirList.size(); i++) {
						VirUserOutputDto dto = userVirList.get(i);
						if (appUserDao.exists(dto.getId())) {
							AppUser appUser = appUserDao.get(dto.getId());
							AppUser ap1 = new AppUser();
							AppUser ap = appUserDao.getAppUsersByPhone(appUser.getUserMobile());//如果根据电话号码找到对应的人，那样的话，进行修改
							if (ap != null && ap.getId() != null) {
								ap.setUserName(appUser.getUserName());
								ap.setEmail(appUser.getEmail());
								ap.setIsPushPower(appUser.getIsPushPower());
								ap.setIsReleasePower(appUser.getIsReleasePower());
								ap.setIsResponsible(1);
								ap.setRoleType("1");
								ap.setIsEnabled("1");
								ap.setVirtualArchId(virId);
								if (StringUtils.isEmpty(ap.getStatus())) {
									ap.setStatus("1");
								}
								ap.setModifier(dto.getUserName());
								ap.setModifyTime(new Date());
								appUserDao.updateObj(ap);
								ap1 = ap;
							} else {
								appUser.setCreateTime(new Date());
								appUser.setCreator(dto.getUserName());
								appUser.setIsEnabled("1");
								appUser.setIsResponsible(1);
								appUser.setRoleType("1");
								appUser.setStatus("1");
								appUser.setOrganizationId(virInfo.getOrganizationId());
								appUser.setVirtualArchId(virId);
								ap1 = appUserDao.save(appUser);
							}
							//保存企业-用户（负责人1信息）中间表1
							VirtUserInfo vuInfo = new VirtUserInfo();
							vuInfo.setReorder(appUser.getReOrder());
							vuInfo.setVirId(virId);
							vuInfo.setUserId(ap1.getId());
							virtUserDao.save(vuInfo);
							res = "SUCCESS";
						}
					}
				}
			}
		} catch (Exception e) {
			LOG.error(e.getMessage());
			e.printStackTrace();
		}
		return res;
	}


	@Override
	public AppResultDto getVirListByBuildId(String buildId, String virName) {
		List<VirtualArchitecture> list = virtualArchDao.getVirListByBuildId(buildId, virName);
		List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
		for (VirtualArchitecture virtualArchitecture : list) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", virtualArchitecture.getId());
			map.put("virName", virtualArchitecture.getName());

			String floorAndRoom = "";
			String roomIds = virtualArchitecture.getRoomIds();
			if (StringUtils.isNotEmpty(roomIds)) {
				String[] roomIdStr = roomIds.split(";");
				if (roomIdStr != null && roomIdStr.length > 0) {
					for (int j = 0; j < roomIdStr.length; j++) {
						RoomInfo roomInfo = roomInfoDao.get(Integer.parseInt(roomIdStr[j]));
						FloorInfo floorInfo = floorInfoDao.get(Integer.parseInt(String.valueOf(roomInfo.getFloorId())));
						floorAndRoom = floorAndRoom + floorInfo.getName() + "楼" + roomInfo.getName() + "、";
					}
				}
			}
			map.put("floorAndRooms", floorAndRoom);
			mapList.add(map);
		}
		return AppResultUtil.createSuccesDto(mapList);
	}

	@Override
	public List<MetingCompanyDto> getVirByStartTime(String startTime,
													String endTime) throws Exception {
		List<MetingCompanyDto> dtoList = new ArrayList<MetingCompanyDto>();
		List<Map<String, Object>> mapList = virtualArchDao.getVirByStartTime(startTime, endTime);
		if (mapList != null && mapList.size() > 0) {
			for (int i = 0; i < mapList.size(); i++) {
				Map<String, Object> map = mapList.get(i);
				MetingCompanyDto dto = new MetingCompanyDto();
				List<MetingBizAccountDto> listAccountDto = new ArrayList<MetingBizAccountDto>();
				String companyId = map.get("CompanyId") == null ? "" : map.get("CompanyId").toString();
				dto.setClient(map.get("Client") == null ? "" : map.get("Client").toString());
				dto.setCompanyId(companyId);
				dto.setCompanyName(map.get("CompanyName") == null ? "" : map.get("CompanyName").toString());
				dto.setSettleType(map.get("SettleType") == null ? "0" : map.get("SettleType").toString());//(1现结2月结) settleType
				if (StringUtils.isNotEmpty(companyId)) {
					List<VirtualAccount> listAccount = virtualAccountDao.getVirAccByVirId(Integer.parseInt(companyId));
					if (listAccount != null && listAccount.size() > 0) {
						for (int k = 0; k < listAccount.size(); k++) {
							VirtualAccount virtualAccount = listAccount.get(k);
							MetingBizAccountDto accountDto = new MetingBizAccountDto();
							accountDto.setVirId(String.valueOf(virtualAccount.getVirId()));
							accountDto.setVirAccount(virtualAccount.getVirAccount());
							accountDto.setPasswords(virtualAccount.getPassword());
							accountDto.setIsEnable(virtualAccount.getIsEnable());
							listAccountDto.add(accountDto);
						}
					}
				}
				//有企业账号信息才同步
				if (listAccountDto.size() >= 1) {
					dto.setBizAccount(listAccountDto);
					dtoList.add(dto);
				}

			}
		}
		return dtoList;
	}


	/**
	 * 获取该项目下所有有效的企业
	 *
	 * @param orgIds
	 * @return
	 */
	@Override
	public List<VirInfoDto> getVirInfoDtoByOrgId(String orgIds, String virtName) throws Exception {
		List<Map<String, Object>> mapList = virtualArchDao.getVirInfoDtoByOrgId(orgIds, virtName);
		List<VirInfoDto> list = new ArrayList<VirInfoDto>();
		if (mapList != null && mapList.size() > 0) {
			for (int i = 0; i < mapList.size(); i++) {
				Map<String, Object> map = mapList.get(i);
				VirInfoDto dto = new VirInfoDto();
				if (map.containsKey("virId") && StringUtils.isNotEmpty(map.get("virId").toString())) {
					dto.setVirId(Integer.parseInt(map.get("virId").toString()));
				}
				dto.setVirName(map.get("virName") == null ? "" : map.get("virName").toString());
				dto.setVirNumber(map.get("virNumber") == null ? "" : map.get("virNumber").toString());
				dto.setAddress(map.get("address") == null ? "" : map.get("address").toString());
				list.add(dto);
			}
		}
		return list;
	}

	@Override
	public List<Map<String, Object>> getFloorCompanyAndSettleMonth(
			int organizationId, String companyName, boolean isAir) throws Exception {

		List<Map<String, Object>> listVirs = new ArrayList<Map<String, Object>>();
		if (isAir) {
			listVirs = propertyDao.getVirtualListBySettleMonthAir(organizationId, companyName);
		} else {
			listVirs = propertyDao.getVirtualListBySettleMonth(organizationId, companyName);
		}
		//List<Map<String,Object>> listVirs=propertyDao.getVirtualListBySettleMonth(organizationId,companyName);		

		//按1楼-公司1 公司2 公司3 2楼-公司1 公司2 公司3 结构
		Map<String, Set<returnCompanyDto>> resultMap = new LinkedHashMap<String, Set<returnCompanyDto>>();


		List<Map<String, Object>> mapList = new LinkedList<Map<String, Object>>();
		Map tempMap = new HashMap();

		//resultMap
		/*tempMap.put("floorId", floorIds);
		tempMap.put("floorName", "floorName");
		tempMap.put("virList", setVirs);
		mapList.add(tempMap);*/

		for (Map<String, Object> obj : listVirs) {


			Map returnCompanyMap = new LinkedHashMap<String, String>();
			//returnCompanyDto vir=new returnCompanyDto();
			//vir.setCompanyId((Integer)obj.get("id"));
			//vir.setCompanyName((String)obj.get("name"));
			returnCompanyMap.put("id", ((Integer) obj.get("id")).toString());
			returnCompanyMap.put("name", (String) obj.get("name"));
			returnCompanyMap.put("virAccountId", ((Long) obj.get("virAccountId")).toString());

			String floorIds = (String) obj.get("floorIds");

			if (StringUtils.isNotEmpty(floorIds)) {
				String[] floorStrIds = floorIds.split(";");
				for (String floor : floorStrIds) {

					if (resultMap.containsKey(floor)) {
						Set setVirs = resultMap.get(floor);
						setVirs.add(returnCompanyMap);
						resultMap.put(floor, setVirs);
					} else {
						Set setVirs = new HashSet<VirtualArchitecture>();
						setVirs.add(returnCompanyMap);
						resultMap.put(floor, setVirs);
					}
				}
			}

		}

		Map floorIdAndMap = new HashMap();
		List<FloorInfo> listFloors = floorInfoDao.getAll();
		for (FloorInfo fInfo : listFloors) {
			floorIdAndMap.put(fInfo.getId().toString(), fInfo.getName());
		}

		//排序		
		//CollectionUtils.sortList(mapList, "floorId", "ASC");

		Iterator its = resultMap.keySet().iterator();
		while (its.hasNext()) {
			String floorId = (String) its.next();
			Set setVirs = resultMap.get(floorId);

			tempMap = new HashMap();
			tempMap.put("floorId", floorId);
			if (floorIdAndMap.containsKey(floorId)) {
				tempMap.put("floorName", floorIdAndMap.get(floorId));
			} else {
				tempMap.put("floorName", "");
			}
			tempMap.put("virList", setVirs);
			mapList.add(tempMap);
		}

		//排序		
		//CollectionUtils.sortList(mapList, "floorId", "ASC");
		//return ASC_order ? value1.compareTo(value2) : value2.compareTo(value1);

		Collections.sort(mapList, new Comparator() {

			boolean ASC_order = true;

			@Override
			public int compare(Object o1, Object o2) {
				Map<String, Object> map1 = (Map<String, Object>) o1;
				Map<String, Object> map2 = (Map<String, Object>) o2;
				Integer intMap1 = Integer.valueOf(((String) map1.get("floorId")));
				Integer intMap2 = Integer.valueOf(((String) map2.get("floorId")));
				//return Integer.valueOf(((String)map1.get("floorId"))).compareTo(((String)map2.get("floorId")));
				return ASC_order ? intMap1.compareTo(intMap2) : intMap2.compareTo(intMap1);

			}

		});

		return mapList;
	}

	@Override
	public List<Map<String, String>> getVirByOrgIdAndVirName(Integer virtualId, Integer level, int orgId, String virName) {
		List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
		List<VirtualArchitecture> list = virtualArchDao.getVirByOrgIdAndVirName(virtualId, level, orgId, virName);
		if (list != null && list.size() > 0) {
			for (VirtualArchitecture vir : list) {
				Map<String, String> map = new HashMap<String, String>();
				map.put("id", vir.getId().toString());
				map.put("name", vir.getName());
				listMap.add(map);
			}
		}
		return listMap;
	}


	@Override
	public List<Map<String, String>> getVirByOrgIdAndNoAgant(Integer id, int orgId, String virName) {
		List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
		List<VirtualArchitecture> list = virtualArchDao.getVirByOrgIdAndNoAgant(id, orgId, virName);
		if (list != null && list.size() > 0) {
			for (VirtualArchitecture vir : list) {
				Map<String, String> map = new HashMap<String, String>();
				map.put("id", vir.getId().toString());
				map.put("name", vir.getName());
				listMap.add(map);
			}
		}
		return listMap;
	}


	@Override
	public List<Map<String, Object>> getVirtualDataByInfo(String orgId,
														  int dateType, String date, String endDate) {
		return virtualArchDao.getVirtualDataByInfo(orgId, dateType, date, endDate);
	}


	@Override
	public List<Map<String, Object>> getVirtualByRoomId(String roomId) {
		return virtualArchDao.getVirtualByRoomId(roomId);
	}

	@Override
	public List<Map<String, Object>> getVirtualArchAgent() {
		return virtualArchDao.getVirtualArchAgent();
	}
}
