package com.palmnest.service.estateserve.impl;

import com.palmnest.application.CodeConstants;
import com.palmnest.application.bean.AppResultDto;
import com.palmnest.application.core.util.*;
import com.palmnest.application.dto.CommonDto;
import com.palmnest.application.dto.input.EmigrationInputDto;
import com.palmnest.application.dto.output.EmigSettleOutPutDto;
import com.palmnest.application.dto.output.EmigSumIndexDto;
import com.palmnest.application.dto.output.EmigrationDto;
import com.palmnest.application.dto.output.EnterInfoDto;
import com.palmnest.dao.ElementGroupDao;
import com.palmnest.dao.UserDao;
import com.palmnest.dao.estateserve.*;
import com.palmnest.dao.wechat.ReplayContentDao;
import com.palmnest.model.*;
import com.palmnest.model.emig.EmigrationSettle;
import com.palmnest.model.estateserve.WxUser;
import com.palmnest.model.property.TbBuild;
import com.palmnest.model.property.TbOrganization;
import com.palmnest.model.property.VirtualArchitecture;
import com.palmnest.service.estateserve.EmigrationManager;
import com.palmnest.service.estateserve.EnterpriseManager;
import com.palmnest.service.estateserve.ScWxuserManager;
import com.palmnest.service.impl.GenericManagerImpl;
import com.palmnest.service.property.PropertyManager;
import com.palmnest.service.wechat.WeChatApiManager;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
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 java.util.*;

/**
 * 企业迁出
 *
 * @author longmeizhen
 */
@Slf4j
@Service("emigrationManager")
public class EmigrationManagerImpl extends GenericManagerImpl<EnterpriseInfo, Integer> implements EmigrationManager {


	private static final String QYQC = "qyqc";

	private EmigrationDao emigrationDao;

	@Autowired
	public void setEmigrationDao(EmigrationDao emigrationDao) {
		this.emigrationDao = emigrationDao;
		this.dao = emigrationDao;
	}

	@Autowired
	private FloorInfoDao       floorInfoDao;
	@Autowired
	private VirtualArchDao     virtualArchDao;
	@Autowired
	private VirtUserDao        virtUserDao;
	@Autowired
	private AppUserDao         appUserDao;
	@Autowired
	private EnterpriseDao      enterpriseDao;
	@Autowired
	private EnterpriseManager  enterpriseManager;
	@Autowired
	private WatermeterDao      watermeterDao;
	@Autowired
	private EnterpriseAuditDao enterpriseAuditDao;
	@Autowired
	private UserDao            userDao;
	@Autowired
	private EmigSettleDao      emigSettleDao;
	@Autowired
	private ElementGroupDao    elementGroupDao;
	@Autowired
	private ScWxuserManager    scWxuserManager;
	@Autowired
	private WeChatApiManager   weChatApiManager;
	@Autowired
	private ReplayContentDao   replayContentDao;
	@Autowired
	private PropertyManager    propertyManager;
	@Autowired
	private RoomInfoDao        roomInfoDao;

	public static String settleTableTempleteId = PropertiesKit.readPropertiesValue("settleTableTempleteId", "wechat.properties");

	@Override
	public AppResultDto getFloorVirList(String floorIds) throws Exception {
		List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
		try {
			if (StringUtils.isNotEmpty(floorIds)) {
				String[] str = floorIds.split(";");
				if (str.length > 0) {
					for (int i = 0; i < str.length; i++) {
						Map<String, Object> obj = new HashMap<String, Object>();
						obj.put("floorId", str[i]);
						FloorInfo floorInfo = floorInfoDao.get(Integer.parseInt(str[i]));
						if (floorInfo.getIsEnabled() == 1) {
							obj.put("floorName", floorInfo.getName());
							List<CommonDto> list    = emigrationDao.getFloorVirList(str[i]);
							List<CommonDto> listDto = new ArrayList<CommonDto>();
							if (list != null && list.size() > 0) {
								for (int k = 0; k < list.size(); k++) {
									CommonDto            dto    = list.get(k);
									String               isBand = "";
									List<EnterpriseInfo> list1  = enterpriseDao.getEnterListByVirId(String.valueOf(dto.getId()));
									if (list1 != null && list1.size() > 0) {
										isBand = "1";
									} else {
										listDto.add(dto);
									}
								}
							}

							obj.put("virList", listDto);
							mapList.add(obj);
						}

					}
				}
			}
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
			return AppResultUtil.createErrorDto("100", "获取楼层企业失败：" + e.getMessage());
		}

		return AppResultUtil.createSuccesDto(mapList);
	}

	@Override
	public EnterpriseInfo saveEnterInfo(EmigrationInputDto emigInputDto, int userId, String newWay)
			throws Exception {

		EnterpriseInfo enterInfo = new EnterpriseInfo();//首先设置一些必要的值，然后再进行别的字段的获取
		try {
			int    virId       = emigInputDto.getVirId();//企业Id
			int    orgId       = emigInputDto.getOrgId();//楼栋Id
			int    emigReason  = emigInputDto.getEmigrationReason();//迁出原因
			int    emigType    = emigInputDto.getEmigrationType();//迁出类型
			String otherRemark = emigInputDto.getOtherRemark() == null ? "" : emigInputDto.getOtherRemark();//其他说明
			enterInfo.setApplyName(emigInputDto.getApplyName());//申请人姓名
			enterInfo.setApplyTel(emigInputDto.getApplyTel());//申请人电话
			enterInfo.setState("2");//状态为2是迁出
			enterInfo.setOrgId(String.valueOf(orgId));//楼栋id
			enterInfo.setEnterNumber(CodeGenerateUtils.generate(QYQC));
			enterInfo.setIsEnabled("1");
			enterInfo.setStatus("1");//待处理
			enterInfo.setCreateTime(new Date());
			enterInfo.setCreator(userId);//当为微信端发出时 newWay=1,保存的是微信userid;当为app端发出时 newWay=2,保存的是app userid
//			enterInfo.setEmigReason(String.valueOf(emigReason));
//			enterInfo.setEmigType(String.valueOf(emigType));
//			enterInfo.setRemark(otherRemark);
			enterInfo.setEmigNewWay(newWay);
			enterInfo.setEmail(emigInputDto.getEmail());
			VirtualArchitecture virInfo = virtualArchDao.get(virId);//设置企业下对应的值
			if (virInfo != null) {
				enterInfo.setFloorIds(virInfo.getFloorIds());
				enterInfo.setFloorNames(virInfo.getFloorNames());
				enterInfo.setRoomIds(virInfo.getRoomIds());
				enterInfo.setRoomNames(virInfo.getRoomNames());
				enterInfo.setVirName(virInfo.getName());
				enterInfo.setVirId(virId);
				enterInfo.setIsEmail(virInfo.getIsEmail() == null ? 0 : virInfo.getIsEmail());
				enterInfo.setIsMessage(virInfo.getIsMessage() == null ? 0 : virInfo.getIsMessage());
				enterInfo.setIsWechat(virInfo.getIsWechat() == null ? 0 : virInfo.getIsWechat());
				enterInfo.setBusinessImageUrl(virInfo.getBusinessImageUrl());
				enterInfo.setPowerAttorneyImageUrl(virInfo.getPowerAttorneyImageUrl());
				enterInfo.setPowerFaceImageUrl(virInfo.getPowerFaceImageUrl());
				enterInfo.setPowerNationImageUrl(virInfo.getPowerNationImageUrl());
			}
			/*List<VirtUserInfo> virUserList=virtUserDao.getVirUserByVirId(virId);//查询出该企业对应的负责人信息
			if(virUserList!=null&&virUserList.size()>0){
				for(int i=0;i<virUserList.size();i++){
					VirtUserInfo virUserInfo=virUserList.get(i);
					if(virUserInfo!=null){
						if(virUserInfo.getReorder()==1){//负责人1
							AppUser user=appUserDao.get(virUserInfo.getUserId());
							enterInfo.setRemanName1(user.getUserName());
							enterInfo.setRemanTel1(user.getUserMobile());
							enterInfo.setRemanEmail1(user.getEmail());
							enterInfo.setIsPushPower1(user.getIsPushPower());
							enterInfo.setIsReleasePower1(user.getIsReleasePower());
						}else if(virUserInfo.getReorder()==2){//负责人2
							AppUser user=appUserDao.get(virUserInfo.getUserId());
							enterInfo.setRemanName2(user.getUserName());
							enterInfo.setRemanTel2(user.getUserMobile());
							enterInfo.setRemanEmail2(user.getEmail());
							enterInfo.setIsPushPower2(user.getIsPushPower());
							enterInfo.setIsReleasePower2(user.getIsReleasePower());
						}
					}
				}
			}*/
			enterInfo = emigrationDao.save(enterInfo);
		} catch (Exception e) {
			log.error("保存迁出信息失败：" + e.getMessage());
			e.printStackTrace();
			throw new Exception(e);
		}
		return enterInfo;
	}

	@Override
	public Map<String, Object> getEmigInfoByVirId(String virId)
			throws Exception {
		VirtualArchitecture virInfo = virtualArchDao.get(Integer.parseInt(virId));
		Map<String, Object> map     = new HashMap<String, Object>();
		/*List<VirtUserInfo> virUserList=virtUserDao.getVirUserByVirId(Integer.parseInt(virId));//查询出该企业对应的负责人信息
		String remanName1="";
		String remanName2="";
		if(virUserList!=null&&virUserList.size()>0){
			for(int i=0;i<virUserList.size();i++){
				VirtUserInfo virUserInfo=virUserList.get(i);
				if(virUserInfo!=null){
					if(virUserInfo.getReorder()==1){//负责人1
						AppUser user=appUserDao.get(virUserInfo.getUserId());
						remanName1=user.getUserName();
					}else if(virUserInfo.getReorder()==2){//负责人2
						AppUser user=appUserDao.get(virUserInfo.getUserId());
						remanName2=user.getUserName();
					}
				}
			}
		}
		TbOrganization orgInfo=new TbOrganization();
		if(virtualArchDao.getBuild()!=null&&virtualArchDao.getBuild().size()>0){
			orgInfo=virtualArchDao.getBuild().get(0);
		}
		String address="";
		if(StringUtils.isNotEmpty(virInfo.getAddress())){
			address=virInfo.getAddress();
		}
		map.put("remanName2", remanName2);
		map.put("remanName1",remanName1);
		if(StringUtils.isNotEmpty(address)){
			map.put("virAddress", address.substring(0,address.length()-1));
		}else{
			map.put("virAddress", address);
		}*/
		map.put("virName", virInfo.getName());//企业名称
		map.put("virId", virInfo.getId());//企业id
		String buildName = "";//楼宇名称
		if (null != virInfo.getBuildId()) {
			TbBuild tbBuild = (TbBuild) propertyManager.getTbBuildById(virInfo.getBuildId());
			buildName = tbBuild.getName();
			map.put("orgId", tbBuild.getId());//楼宇id
		}
		map.put("buildName", buildName);//楼宇名称

		String floorAndRoom = "";
		String roomIds      = virInfo.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("floorAndRoom", floorAndRoom);//楼宇名称
		return map;
	}


	@Override
	public EmigrationDto getEnterInfo(int id, String userId) throws Exception {
		EnterpriseInfo enterInfo = enterpriseDao.get(id);
		try {
			if (enterInfo != null) {
				EnterInfoDto         dto          = new EnterInfoDto();
				String               floorAndRoom = enterpriseManager.getFloorAndRooms(enterInfo);
				List<TbOrganization> list         = virtualArchDao.getBuild();
				String               orgName      = "";
				if (list != null && list.size() > 0) {
					TbOrganization orgInfo = list.get(0);
					orgName = orgInfo.getName();
				}
				List<WatermeterInfo> wateList      = watermeterDao.getWatermeterList(id, 2, "", "");
				int                  waterInfoType = 1;
				if (wateList != null && wateList.size() > 0) {
					waterInfoType = 2;
				}
				String                reason    = "";
				List<EnterpriseAudit> auditList = enterpriseAuditDao.getEnterAuditList("2", id);//2代表企业迁出
				if (auditList != null && auditList.size() > 0) {
					EnterpriseAudit audit = auditList.get(0);
					reason = audit.getContent();
				}
				String cusServiceName = "";
				if (StringUtils.isNotEmpty(enterInfo.getCustomerService()) && !"0".equals(enterInfo.getCustomerService())) {
					User user = userDao.get(Long.parseLong(enterInfo.getCustomerService()));
					cusServiceName = user.getFullName();
				}
				String engPersonName = "";
				if (StringUtils.isNotEmpty(enterInfo.getEngPerson()) && !"0".equals(enterInfo.getEngPerson())) {
					User user = userDao.get(Long.parseLong(enterInfo.getEngPerson()));
					engPersonName = user.getFullName();
				}
				String cusSerivce = "0";
				if (StringUtils.isNotEmpty(enterInfo.getCustomerService())) {
					cusSerivce = enterInfo.getCustomerService();
				}
				String engPeason = "0";
				if (StringUtils.isNotEmpty(enterInfo.getEngPerson())) {
					engPeason = enterInfo.getEngPerson();
				}

				int              isSendSettle = 1;//结算表
				EmigrationSettle es           = emigrationDao.getEmigrationSettle(enterInfo.getId());
				if (es != null) {
					isSendSettle = 2;
				}
				String otherRecord = "";
				if (StringUtils.isNotEmpty(enterInfo.getOtherRecord())) {
					otherRecord = enterInfo.getOtherRecord();
				}
				String repairNumber = "";
				if (StringUtils.isNotEmpty(enterInfo.getRepairNumber())) {
					repairNumber = enterInfo.getRepairNumber();
				}

				String remark = "";
				if (StringUtils.isNotEmpty(enterInfo.getRemark())) {
					remark = enterInfo.getRemark();
				}
				String  emigType         = "";
				String  emigReason       = "";
				Element emigrationReason = new Element();
				if (StringUtils.isNotEmpty(enterInfo.getEmigReason())) {
					emigrationReason = elementGroupDao.getElementId(Long.parseLong(enterInfo.getEmigReason()));
				}

				Element emigrationType = new Element();
				if (StringUtils.isNotEmpty(enterInfo.getEmigReason())) {
					emigrationType = elementGroupDao.getElementId(Long.parseLong(enterInfo.getEmigType()));
				}
				if (emigrationReason != null) {
					emigReason = emigrationReason.getItemname();
				}
				if (emigrationType != null) {
					emigType = emigrationType.getItemname();
				}
				String emigNewWay = "";
				if (StringUtils.isNotEmpty(enterInfo.getEmigNewWay())) {
					if ("2".equals(enterInfo.getEmigNewWay())) {
						emigNewWay = "2";//app发起
					} else if ("1".equals(enterInfo.getEmigNewWay())) {
						emigNewWay = "1";//微信发起
					}
				}

				String isSupervisor  = enterpriseDao.isHavePower(userId, Integer.parseInt(CodeConstants.ENTERCUSMANAGE_PERMISSION));
				String isCustService = enterpriseDao.isHavePower(userId, Integer.parseInt(CodeConstants.ENTERCUS_PERMISSION));
				String isProgramme   = enterpriseDao.isHavePower(userId, Integer.parseInt(CodeConstants.ENTERENG_PERMISSION));
				//havePower:1代表三种权限都包含;2代表有客服主管和客服权限；3代表客服主管和工程人员；4代表客服和工程人员；5客服主管；6客服；7工程人员
				String peasonPower = "";
//				if("1".equals(isSupervisor)&&"1".equals(isCustService)){
//					peasonPower="4";
//				}else if("1".equals(isSupervisor)){
//					peasonPower="1";
//				}else if("1".equals(isCustService)){
//					peasonPower="2";
//				}else if("1".equals(isProgramme)){
//					peasonPower="3";
//				}

				//用户权限1客服主管2跟进客服3跟进工程人员4既有客服主管又有跟进客服权限5有客服主管和工程人员6跟进客服和工程人员7所有权限
				if ("1".equals(isSupervisor) && "1".equals(isCustService) && "1".equals(isProgramme)) {
					peasonPower = "7";
				} else if ("1".equals(isSupervisor) && "1".equals(isCustService)) {
					peasonPower = "4";
				} else if ("1".equals(isSupervisor) && "1".equals(isProgramme)) {
					peasonPower = "5";
				} else if ("1".equals(isCustService) && "1".equals(isProgramme)) {
					peasonPower = "6";
				} else if ("1".equals(isSupervisor)) {
					peasonPower = "1";
				} else if ("1".equals(isCustService)) {
					peasonPower = "2";
				} else if ("1".equals(isProgramme)) {
					peasonPower = "3";
				}
				EmigrationDto enDto = new EmigrationDto(enterInfo.getId(), enterInfo.getEnterNumber(), enterInfo.getOrgId(), orgName, floorAndRoom, enterInfo.getVirName()
						, remark, otherRecord, enterInfo.getStatus(), repairNumber, Integer.parseInt(cusSerivce)
						, Integer.parseInt(engPeason), cusServiceName, engPersonName, waterInfoType, isSendSettle, reason
						, emigType == null ? "" : emigType, emigReason == null ? "" : emigReason, emigNewWay, peasonPower);
				return enDto;
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			throw new Exception(e);
		}

		return null;
	}

	@Override
	public EmigrationSettle getEmigrationSettle(int emigId) throws Exception {
		return emigrationDao.getEmigrationSettle(emigId);
	}

	@Override
	@Transactional
	public EmigrationSettle saveEmigraSettle(double amount, String settleImage, String emigId,
											 String userId) throws Exception {
		EmigrationSettle esInfo = new EmigrationSettle();
		if (StringUtils.isNotEmpty(emigId)) {
			emigSettleDao.delEmigSettleByEmigId(emigId);
			esInfo.setCreateTime(new Date());
			esInfo.setCreator(userId);
			esInfo.setEnterId(emigId);
			esInfo.setIsEnabled("1");
			esInfo.setAmount(amount);
			esInfo.setSettlementImageUrl(settleImage);
			esInfo = emigSettleDao.save(esInfo);
		}
		return esInfo;
	}

	@Override
	public List<CommonDto> getVirListByReman(int userId) throws Exception {
		List<VirtUserInfo> virUserList = virtUserDao.getVirIdByUserId(userId);
		List<CommonDto>    listDto     = new ArrayList<CommonDto>();
		if (virUserList != null && virUserList.size() > 0) {
			for (int i = 0; i < virUserList.size(); i++) {
				CommonDto    dto         = new CommonDto();
				VirtUserInfo virUserInfo = virUserList.get(i);
				String       isBand      = "";
				if (virUserInfo != null) {
					List<EnterpriseInfo> list = enterpriseDao.getEnterListByVirId(String.valueOf(virUserInfo.getVirId()));
					if (list != null && list.size() > 0) {
						isBand = "1";
					}
				}
				boolean bool = virtualArchDao.exists(virUserInfo.getVirId());
				if (bool) {
					VirtualArchitecture virInfo = virtualArchDao.get(virUserInfo.getVirId());
					if (virInfo != null && !"1".equals(isBand)) {
						String virId = String.valueOf(virInfo.getId());
						dto.setId(Long.parseLong(virId));
						dto.setName(virInfo.getName());
						listDto.add(dto);
					}
				}
			}
		}
		return listDto;
	}

	@Override
	public EmigSumIndexDto findIndex(String userId, String orgIds) {
		try {
//			Map<String,Object> map1 = new HashMap<String,Object>();
//			map1.put("type",1);
//			map1.put("orgId",orgIds);
//			map1.put("isHisList","1");
//			Page page1=enterpriseManager.getEnterList(map1,1, Integer.MAX_VALUE-1);//企业入驻待处理列表
//			map1.put("type",2);
//			Page page2=enterpriseManager.getEnterList(map1,1, Integer.MAX_VALUE-1);//企业迁出待处理列表
//			EmigSumIndexDto dto=new EmigSumIndexDto();
//			int emigCount=0;
//			int enterCount=0;
//			if(page1!=null&&page1.getTotalCount()>0){
//				enterCount=Integer.parseInt(String.valueOf(page1.getTotalCount()));
//			}
//			if(page2!=null&&page2.getTotalCount()>0){
//				emigCount=Integer.parseInt(String.valueOf(page2.getTotalCount()));
//			}
//			dto.setEmigIndex(emigCount);
//			dto.setEnterIndex(enterCount);
//			return dto;
			int             enterCount = enterpriseDao.getEnterprisePendingNum(1, orgIds);//入驻待处理总数
			int             emigCount  = enterpriseDao.getEnterprisePendingNum(2, orgIds);//迁出待处理总数
			EmigSumIndexDto dto        = new EmigSumIndexDto();
			dto.setEmigIndex(emigCount);
			dto.setEnterIndex(enterCount);
			return dto;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	@Transactional
	public EmigSettleOutPutDto updateSettle(int emigId, double amount, String userId, String fileUrl) throws Exception {
		FileUploadUtils  fileUploadUtils = new FileUploadUtils();
		EmigrationSettle esInfo          = emigrationDao.getEmigrationSettle(emigId);
		esInfo.setAmount(amount);
		esInfo.setModifyTime(new Date());
		esInfo.setModifier(userId);
		esInfo.setSettlementImageUrl(fileUrl);
		emigSettleDao.updateObj(esInfo);
		String              image = fileUploadUtils.fullVisitPath(fileUrl);
		EmigSettleOutPutDto dto   = new EmigSettleOutPutDto(esInfo.getId(), image, esInfo.getEnterId(), esInfo.getAmount(), fileUrl);
		return dto;
	}


	@Async
	public String sendWechat(String enterId, EmigSettleOutPutDto dto) throws Exception {
//		List<WxtemplateMessageTypeModel> templateList=replayContentDao.getWxTemplateByTempId(0, "KlRZryc99rR8oHAlQ9e6gIrzMHSKOgLTyGNsF4K7KZ4");
		String templateId = settleTableTempleteId;
		String code       = "fail";
		if (StringUtils.isEmpty(templateId)) {
			return code;
		}
		EnterpriseInfo enterInfo = new EnterpriseInfo();
		if (StringUtils.isNotEmpty(enterId)) {
			enterInfo = enterpriseDao.get(Integer.parseInt(enterId));
		}
		if (enterInfo != null) {
			String floorAndRoom = enterpriseManager.getFloorAndRooms(enterInfo);
			String virName      = enterInfo.getVirName() == null ? "" : enterInfo.getVirName();
			double amount       = dto.getAmount();
			if (StringUtils.isNotEmpty(floorAndRoom) && floorAndRoom.length() > 0) {
				floorAndRoom = floorAndRoom.substring(0, floorAndRoom.length() - 1);
			}
			//根据企业id查出相应的负责人----要给两个负责人发送
			if (StringUtils.isNotEmpty(String.valueOf(enterInfo.getVirId()))) {
				List<VirtUserInfo> list = virtUserDao.getVirUserByVirId(enterInfo.getVirId());
				if (list != null && list.size() > 0) {
					for (int k = 0; k < list.size(); k++) {
						VirtUserInfo virUserInfo = list.get(k);
						int          userId      = virUserInfo.getUserId();//这个是tb_user表中的id
						WxUser       wxUser      = scWxuserManager.getScWxuserByUserId(userId);
						if (wxUser != null) {
							Map<String, String> paramMap = new HashMap<String, String>();
							paramMap.put("developId", wxUser.getDevelopId());
							paramMap.put("openId", wxUser.getOpenId());
							paramMap.put("templateId", templateId);
							paramMap.put("url", "");
							paramMap.put("first", "您好！您有一份迁出结算表，请及时查看！");
							paramMap.put("keyword1", DateHelper.formatDate(enterInfo.getCreateTime(), DateHelper.DATE_TIME_STRING));//时间
							paramMap.put("keyword2", String.valueOf(amount));//结算金额
							paramMap.put("remark", "点击详情可查看更详细的结算表信息，欢迎您再次回家！");
							weChatApiManager.sendTemplateWithOpenId(wxUser.getDevelopId(), templateId, "", userId, paramMap);
						}
					}
				}
			}
		}
		return code;
	}

	@Override
	public boolean checkHasUnhandleOrder(int virId) {
		//是否正在待审核
		List<EnterpriseInfo> list = enterpriseDao.getUnhandleOrder(virId);
		if (list != null && list.size() > 0) {
			return true;
		}
		//是否已经迁出成功  查询企业表中该企业是否在租  如果是在租状态则可迁出  否则不可迁出
		VirtualArchitecture architecture = virtualArchDao.get(virId);
		if (architecture.getLeaseStatus() == 0) {
			//不是在租状态,说明该企业已经迁出,不可重复迁出
			return true;
		}
		return false;
	}
}
