package com.palmnest.webapp.controller.wechat;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.palmnest.application.CodeConstants;
import com.palmnest.application.bean.AppCommonResultDto;
import com.palmnest.application.bean.AppResultDto;
import com.palmnest.application.core.util.AppResultUtil;
import com.palmnest.application.core.util.PropertiesKit;
import com.palmnest.application.dto.output.EnterEvaluateDto;
import com.palmnest.application.dto.output.FileDto;
import com.palmnest.model.EnterpriseAudit;
import com.palmnest.model.EnterpriseInfo;
import com.palmnest.model.RoomInfo;
import com.palmnest.model.VirArchModel;
import com.palmnest.model.estateserve.WxUser;
import com.palmnest.model.notice.EmailConfigModel;
import com.palmnest.model.property.TbBuild;
import com.palmnest.service.estateserve.*;
import com.palmnest.service.notice.EmailConfigManager;
import com.palmnest.webapp.controller.BaseFormController;
import com.sun.mail.util.MailSSLSocketFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * 企业入驻微信端控制器
 *
 * @author longmeizhen
 */
@Slf4j
@Controller
@RequestMapping(value = "/wechat/enter/*")
public class WechatEnterpriseController extends BaseFormController {

	@Autowired
	private VirArchModelManager         virArchModelManager;
	@Autowired
	private FloorInfoManager            floorInfoManager;
	@Autowired
	private VirtualArchManager          virtualArchManager;
	@Autowired
	private RoomInfoManager             roomInfoManager;
	@Autowired
	private EnterpriseManager           enterpriseManager;
	@Autowired
	private EnterpriseAuditManager      enterpriseAuditManager;
	@Autowired
	private ScWxuserManager             scWxuserManager;
	@Autowired
	private BillOperationRecodesManager billOperationRecodesManager;
	@Autowired
	private EmailConfigManager          emailConfigManager;

	/**
	 * 获取模板配置
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getVirArchModelByType")
	@ResponseBody
	public AppResultDto getVirArchModelByType(HttpServletRequest request, HttpServletResponse response) {
		int type = 0;
		if (StringUtils.isNotEmpty(request.getParameter("type"))) {
			type = Integer.parseInt(request.getParameter("type"));
		}
		String orgId = request.getParameter("orgId");
		try {
			List<VirArchModel> virModelList = virArchModelManager.getVirArchModelByType(type, orgId);
			return AppResultUtil.createSuccesDto(virModelList);
		} catch (Exception e) {
			log.error(e.getMessage());
			return AppResultUtil.createErrorDto("100", "获取配置模板出错：" + e.getMessage());
		}

	}

	/**
	 * 获取楼层信息
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getFloorByOrgId")
	@ResponseBody
	public AppResultDto getFloorByOrgId(HttpServletRequest request, HttpServletResponse response) {

		String buildId = request.getParameter("buildId");//楼宇id
//    	int orgId=0;
//    	List<TbOrganization> orgList=new ArrayList<TbOrganization>();
		List<Map<String, Object>> floorList = new ArrayList<Map<String, Object>>();
		try {
			//首先查出楼宇(备注：由于目前楼宇仅有一个，因此直接获取数据库中楼宇名称为尚美科技大厦的楼宇)
			/*orgList = virtualArchManager.getBuild();
			if(orgList!=null&&orgList.size()>0){
				TbOrganization orgInfo=orgList.get(0);
				orgId=orgInfo.getId();*/
			floorList = floorInfoManager.getFloorAndRoomByOrgId(Integer.parseInt(buildId));
			return AppResultUtil.createSuccesDto(floorList);
	    	/*}else{
	    		return AppResultUtil.createErrorDto("100", "楼宇获取失败");
	    	}*/

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

	/**
	 * 获取房间号信息(未入驻的房间)
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getRoomByFloorId")
	@ResponseBody
	public AppResultDto getRoomByFloorId(HttpServletRequest request, HttpServletResponse response) {
		int                       floorId  = Integer.parseInt(request.getParameter("floorId"));
		List<RoomInfo>            roomList = new ArrayList<RoomInfo>();
		List<String>              objList  = new ArrayList<String>();
		List<Map<String, Object>> list     = new ArrayList<Map<String, Object>>();
		try {
			objList = virtualArchManager.getBandRoomId();
			roomList = roomInfoManager.getRoomInfoByfloorId(floorId);
			for (int i = 0; i < roomList.size(); i++) {
				Map<String, Object> roomMap  = new HashMap<String, Object>();
				RoomInfo            roomInfo = roomList.get(i);
				roomMap.put("roomInfo", roomInfo);
				boolean bool = objList.contains(roomInfo.getId().toString());
				if (bool) {
					roomMap.put("isLess", 1);//如果房间号在list中，代表该房间号已有企业入驻了
				} else {
					roomMap.put("isLess", 0);
				}
				list.add(roomMap);
			}
			return AppResultUtil.createSuccesDto(list);
		} catch (Exception e) {
			log.error(e.getMessage());
			return AppResultUtil.createErrorDto("100", "获取房间号信息出错：" + e.getMessage());
		}
	}

	/**
	 * 上传图片返回图片路径
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getAttMagePath")
	@ResponseBody
	public AppResultDto getAttMagePath(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> data = new HashMap<String, Object>(3);
		try {
			data = enterpriseManager.uploadImage(request);
			return AppResultUtil.createSuccesDto(data);
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			return AppResultUtil.createErrorDto("100", "上传图片失败：" + e.getMessage());
		}


	}

	/**
	 * 保存企业入驻信息
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "saveEnterprise")
	@ResponseBody
	public AppResultDto saveEnterprise(@ModelAttribute EnterpriseInfo enterpriseInfo, HttpServletRequest request, HttpServletResponse response) {
		try {
			String openId  = request.getParameter("openId");//微信用户openid
			String buildId = request.getParameter("buildId");//楼宇id
			enterpriseInfo.setOrgId(buildId);

			//保存前先进性校验 所选房间是否已经被占用,如果所选房间被选中则提示
			String roomIds   = enterpriseInfo.getRoomIds();//获取到房间号串
			String roomNames = getRoomNames(roomIds);
			if (StringUtils.isNotBlank(roomNames)) {
				return AppResultUtil.createErrorDto("100", roomNames + "已被占用,请重新选择房间!");
			}

			WxUser       wxUser = scWxuserManager.getScWxuserByOpenId(openId);
			AppResultDto dto    = enterpriseManager.saveEnterInfo(enterpriseInfo, wxUser.getId());
			if ("200".equals(dto.getCode())) {
				AppCommonResultDto dto1    = (AppCommonResultDto) dto;
				EnterpriseInfo     entInfo = (EnterpriseInfo) dto1.getData();
				enterpriseManager.sendMessageByCusService(entInfo);
				billOperationRecodesManager.saveRecode(Long.parseLong(entInfo.getId().toString()), CodeConstants.ENTER, CodeConstants.START, Long.parseLong(wxUser.getId().toString()), "发起企业入驻", "发起企业入驻");
			}
			return dto;
		} catch (Exception e) {
			return AppResultUtil.createErrorDto("100", "操作失败" + e.getMessage());
		}
	}

	/**
	 * 获取已被占用房间号名称
	 *
	 * @return
	 */
	private String getRoomNames(String roomIds) throws Exception {
		String roomId = "";//已被占用的房间号串
		if (StringUtils.isNotBlank(roomIds)) {
			String[]     arrRoom = roomIds.split(";");
			List<String> objList = virtualArchManager.getBandRoomId();//已被占用的房间号集合
			for (String s : arrRoom) {
				if (objList.contains(s)) {
					roomId = roomId + s + ";";
				}
			}
		}
		//组装信息
		EnterpriseInfo enterpriseInfo = new EnterpriseInfo();
		enterpriseInfo.setRoomIds(roomId);
		return enterpriseManager.getFloorAndRooms(enterpriseInfo);
	}

	/**
	 * 保存后推送消息
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "sendMessage")
	@ResponseBody
	public AppResultDto sendMessage(HttpServletRequest request, HttpServletResponse response) {
		String enterId = request.getParameter("enterId");
		if (StringUtils.isNotEmpty(enterId)) {
			EnterpriseInfo entInfo = enterpriseManager.get(Integer.parseInt(enterId));
			if (entInfo != null) {//如果不为空，则给app端推送消息//并且还要在审批表中加一条数据
				String result;
				try {
					result = enterpriseManager.sendMessageByCusService(entInfo);
					if ("fail".equals(result)) {
						return AppResultUtil.createErrorDto("100", "消息推送失败");
					} else if ("success".equals(result)) {
						return AppResultUtil.createSuccesDto();
					}
				} catch (Exception e) {
					log.error(e.getMessage());
					e.printStackTrace();
					return AppResultUtil.createErrorDto("100", "消息推送失败:" + e.getMessage());
				}
			}
		}
		return AppResultUtil.createErrorDto("100", "传输对象有误");


	}

	/**
	 * 获取企业入驻审批信息
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getEnterAudit")
	@ResponseBody
	public AppResultDto getEnterAudit(HttpServletRequest request, HttpServletResponse response) {
		String                type           = request.getParameter("type");
		int                   soursId        = Integer.parseInt(request.getParameter("enterpId"));
		List<EnterpriseAudit> enterAuditList = new ArrayList<EnterpriseAudit>();
		try {
			enterAuditList = enterpriseAuditManager.getEnterAuditList(type, soursId);
			return AppResultUtil.createSuccesDto(enterAuditList);
		} catch (Exception e) {
			return AppResultUtil.createErrorDto("100", "企业入驻审批单获取失败：" + e.getMessage());
		}
	}

	/**
	 * 获取企业入驻申请状态列表（type为2是获取企业迁出申请状态列表）
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getEnterAuditList")
	@ResponseBody
	public AppResultDto getEnterAuditList(HttpServletRequest request, HttpServletResponse response) {
		String openId = request.getParameter("openId");
		WxUser wxUser = scWxuserManager.getScWxuserByOpenId(openId);
		int    type   = 0;
		if (StringUtils.isNotEmpty(request.getParameter("type"))) {
			type = Integer.parseInt(request.getParameter("type"));
		}
		String                    orgId          = request.getParameter("orgId");
		List<Map<String, Object>> enterAuditList = new ArrayList<Map<String, Object>>();
		try {
			enterAuditList = enterpriseManager.getEnterInfoList(wxUser.getId(), type, "1", orgId);//迁出时 port 1-微信端 2-app端
			return AppResultUtil.createSuccesDto(enterAuditList);
		} catch (Exception e) {
			log.error(e.getMessage());
			return AppResultUtil.createErrorDto("100", "企业入驻申请状态列表获取失败");
		}
	}

	/**
	 * 企业入驻获取楼栋接口
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "getBuildList")
	@ResponseBody
	public AppResultDto getBuildList(HttpServletRequest request, HttpServletResponse response) {

		//获取当前公众号所属项目下的楼宇列表
		String        organizationId = request.getParameter("organizationId");//获取当前公众号所属项目
		List<TbBuild> buildList      = floorInfoManager.getTbBuildListByOrgaid(organizationId);//根据项目id获取此项目下的楼宇

//		List<TbOrganization> orgList=new ArrayList<TbOrganization>();
		try {
//			orgList = virtualArchManager.getBuild();
//			TbOrganization orgInfo=new TbOrganization();
//			Map<String,Object> map=new HashMap<String, Object>();
			JSONArray jsonArray = new JSONArray();
			for (TbBuild tbBuild : buildList) {
				JSONObject obj = new JSONObject();
				obj.put("id", tbBuild.getId());
				obj.put("name", tbBuild.getName());
				jsonArray.add(obj);
			}
			return AppResultUtil.createSuccesDto(jsonArray);
		} catch (Exception e) {
			log.error(e.getMessage());
			return AppResultUtil.createErrorDto("100", "获取楼层失败");
		}

	}


	/**
	 * 修改评价
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "setEvaluate")
	@ResponseBody
	public AppResultDto setEvaluate(HttpServletRequest request, HttpServletResponse response) {
		String enterId  = request.getParameter("enterId");
		String evaluate = request.getParameter("evaluate");
		if (StringUtils.isNotEmpty(enterId)) {
			try {
				enterpriseManager.setEvaluate(enterId, evaluate);
			} catch (Exception e) {
				e.printStackTrace();
				log.error(e.getMessage());
				return AppResultUtil.createErrorDto("100", "评价失败：" + e.getMessage());
			}
		}
		return AppResultUtil.createSuccesDto();
	}

	/**
	 * 获取企业入驻详情
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "getEnterInfo")
	@ResponseBody
	public AppResultDto getEnterInfo(HttpServletRequest request, HttpServletResponse response) {
		String enterId = request.getParameter("enterId");
		String type    = request.getParameter("type");//1-入驻 2-迁出
//		List<Element> eleList=this.getElementGroupManager().getElementsByGroupName("evaluate");
		try {
			EnterEvaluateDto dto = enterpriseManager.getEnterEvaluateInfo(enterId, type);
			return AppResultUtil.createSuccesDto(dto);
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			return AppResultUtil.createErrorDto("100", "获取详情失败:" + e.getMessage());
		}
	}

	/**
	 * 企业入驻文件列表
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getFileList")
	@ResponseBody
	public AppResultDto getFileList(HttpServletRequest request) {
		String image_server = PropertiesKit.readPropertiesValue("image_server", "wechat.properties");
		String type         = request.getParameter("type");
		String orgId        = request.getParameter("orgId");
		String fileIds      = request.getParameter("fileIds");
		if (StringUtils.isNotEmpty(fileIds) && fileIds.indexOf(";") != -1) {
			fileIds = fileIds.replaceAll(";", ",");
		}
		List<Map<String, Object>> list = enterpriseManager.getFileList(type, orgId, fileIds);
		for (Map<String, Object> map : list) {
			String url = (String) map.get("fileUrl");
			map.put("fileUrl", image_server + url);
		}
		return AppResultUtil.createSuccesDto(list);
	}

	/**
	 * 企业 入驻/迁出 文件邮件发送
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "sendEmail")
	@ResponseBody
	public AppResultDto sendEmail(HttpServletRequest request) throws Exception {
		//文件路径
		String file_path  = PropertiesKit.readPropertiesValue("attachment.root", "wechat.properties");
		String type       = request.getParameter("type");
		String orgId      = request.getParameter("orgId");
		String toEmail    = request.getParameter("toEmail");
		String fileIds    = request.getParameter("fileIds");
		String name       = "5".equals(type) ? "入驻文件" : "迁出文件";
		//String subjectStr = "入驻通知";
		String subjectStr       = "5".equals(type) ? "入驻通知" : "迁出通知";
		String txtStr     = "企业" + name;
		log.error("sendEmail ====> type:" + type);
		if (type.equals("15")) {
			name = "装修申请文件";
			subjectStr = "装修申请文件";
			txtStr = "装修申请文件,请查阅";
		} else if (type.equals("25")) {
			name = "便民资料文件";
			subjectStr = "便民资料文件";
			txtStr = "便民资料文件,请查阅";
		}

		FileInputStream     fis = null;
		BufferedInputStream bis = null;
		FileOutputStream    fos = null;
		ZipOutputStream     zos = null;

		File zipFile = new File(file_path + "/" + "test.zip");//zip临时文件
		try {

			List<FileDto> sourceFiles = new ArrayList<FileDto>();
			//获取文件列表
			List<Map<String, Object>> list = enterpriseManager.getFileList(type, orgId, fileIds);
			for (Map<String, Object> map : list) {
				String  path = file_path + map.get("fileUrl");
				FileDto file = new FileDto(path);
				file.setFileName((String) map.get("fileName"));
				sourceFiles.add(file);
			}

			fos = new FileOutputStream(zipFile);
			zos = new ZipOutputStream(new BufferedOutputStream(fos));
			byte[] bufs = new byte[1024 * 10];
			for (FileDto file : sourceFiles) {
				//创建ZIP实体，并添加进压缩包
				//替换成原文件名
				ZipEntry zipEntry = new ZipEntry(file.getFileName());
				zos.putNextEntry(zipEntry);
				//读取待压缩的文件并写进压缩包里
				fis = new FileInputStream(file);
				bis = new BufferedInputStream(fis, 1024 * 10);
				int read = 0;
				while ((read = bis.read(bufs, 0, 1024 * 10)) != -1) {
					zos.write(bufs, 0, read);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			return AppResultUtil.createErrorDto("100", "发送邮件失败!");
		} finally {
			//关闭流
			try {
				if (null != bis) bis.close();
				if (null != zos) zos.close();
				if (null != fis) fis.close();
				if (null != fos) fos.close();
			} catch (IOException e) {
				log.error(e.getMessage());
			}
		}

		try {
			EmailConfigModel emailConfigModel = emailConfigManager.getEmailByOrg(orgId);
			if (null == emailConfigModel) {
				return AppResultUtil.createErrorDto("100", "当前项目没有配置邮箱信息,请配置!");
			}
			JavaMailSenderImpl sender = new JavaMailSenderImpl();
			sender.setHost(emailConfigModel.getSmtp_server());
			sender.setPort(emailConfigModel.getStmp_port());
			sender.setUsername(emailConfigModel.getEmail_address());
			sender.setPassword(emailConfigModel.getPassword());
			sender.setDefaultEncoding("Utf-8");
			Properties           prop = new Properties();
			MailSSLSocketFactory sf   = new MailSSLSocketFactory();
			sf.setTrustAllHosts(true);
			prop.put("mail.smtp.ssl.enable", "true");
			prop.put("mail.smtp.ssl.socketFactory", sf);
			prop.put("mail.smtp.auth", "true");
			prop.put("mail.smtp.timeout", "20000");
			sender.setJavaMailProperties(prop);

			MimeMessage mimeMessage = sender.createMimeMessage();
			// 设置utf-8或GBK编码，否则邮件会有乱码
			MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
			messageHelper.setFrom(emailConfigModel.getEmail_address());//发件人账号(也可以加个参数,显示发件人昵称)
			messageHelper.setTo(toEmail);//收件人
			messageHelper.setSubject(subjectStr);//邮件标题
			messageHelper.setText(txtStr, true);//文件内容
			messageHelper.addAttachment(MimeUtility.encodeWord(name + ".zip"), zipFile);//附件名和附件
			sender.send(mimeMessage);
			if (zipFile.exists()) {
				zipFile.delete();//发送成功后将压缩包删除
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			return AppResultUtil.createErrorDto("100", "发送邮件失败!");
		}
		return AppResultUtil.createSuccesDto();
	}


	/**
	 * 中航物业演示邮件发送
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "sendDemoEmail")
	@ResponseBody
	public AppResultDto sendDemoEmail(HttpServletRequest request) throws Exception {
		//文件路径前缀
		String file_path = PropertiesKit.readPropertiesValue("attachment.root", "wechat.properties");
		//收件人邮箱
		String toEmail = request.getParameter("toEmail");
		//文件 名/路径 json串
		String fileMap = request.getParameter("files");

		log.info("\n接收到的参数为：[{}, {}, {}]", file_path, toEmail, fileMap);

		FileInputStream     fis = null;
		BufferedInputStream bis = null;
		FileOutputStream    fos = null;
		ZipOutputStream     zos = null;

		File zipFile = new File(file_path + "/" + "test.zip");//zip临时文件
		try {

			List<FileDto> sourceFiles = new ArrayList<FileDto>();
			//获取文件列表
			List<Map> list = JSON.parseArray(fileMap, Map.class);
			for (Map map : list) {
				String  path = file_path + map.get("fileUrl");
				FileDto file = new FileDto(path);
				file.setFileName((String) map.get("fileName"));
				sourceFiles.add(file);
			}

			fos = new FileOutputStream(zipFile);
			zos = new ZipOutputStream(new BufferedOutputStream(fos));
			byte[] bufs = new byte[1024 * 10];
			for (FileDto file : sourceFiles) {
				//创建ZIP实体，并添加进压缩包
				//替换成原文件名
				log.info("文件名称 =====> " + file.getFileName());
				ZipEntry zipEntry = new ZipEntry(file.getFileName());
				zos.putNextEntry(zipEntry);
				//读取待压缩的文件并写进压缩包里
				fis = new FileInputStream(file);
				bis = new BufferedInputStream(fis, 1024 * 10);
				int read = 0;
				while ((read = bis.read(bufs, 0, 1024 * 10)) != -1) {
					zos.write(bufs, 0, read);
				}
			}
		} catch (Exception e) {
			log.error("WechatEnterpriseController sendDemoEmail ====> 压缩文件失败:" + e.getMessage());
			return AppResultUtil.createErrorDto("100", "发送邮件失败!");
		} finally {
			//关闭流
			try {
				if (null != bis) bis.close();
				if (null != zos) zos.close();
				if (null != fis) fis.close();
				if (null != fos) fos.close();
			} catch (IOException e) {
				log.error(e.getMessage());
			}
		}

		try {
			JavaMailSenderImpl sender = new JavaMailSenderImpl();
			sender.setHost("smtp.mxhichina.com");//邮箱服务器
			sender.setPort(465);//端口 本地25 服务器ssl 465
			sender.setUsername("avicsbportal@avic-s.com");//邮箱账号
			sender.setPassword("Avics#123");//邮箱密码
			sender.setDefaultEncoding("Utf-8");
			Properties           prop = new Properties();
			MailSSLSocketFactory sf   = new MailSSLSocketFactory();
			sf.setTrustAllHosts(true);
			prop.put("mail.smtp.ssl.enable", "true");//部署服务器开启
			prop.put("mail.smtp.ssl.socketFactory", sf);
			prop.put("mail.smtp.auth", "true");
			prop.put("mail.smtp.timeout", "200000");
			sender.setJavaMailProperties(prop);

			MimeMessage mimeMessage = sender.createMimeMessage();
			// 设置utf-8或GBK编码，否则邮件会有乱码
			MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
			messageHelper.setFrom("avicsbportal@avic-s.com", "中航物业");//发件人账号,发件人昵称
			messageHelper.setTo(toEmail);
			messageHelper.setSubject("平台资料");//邮件标题
			messageHelper.setText("", true);//文件内容
			messageHelper.addAttachment(MimeUtility.encodeWord("中航物业.zip"), zipFile);//附件名和附件
			sender.send(mimeMessage);
		} catch (Exception e) {
			log.error("WechatEnterpriseController sendDemoEmail ====> 邮件发送失败:" + e.getMessage());
			return AppResultUtil.createErrorDto("100", "发送邮件失败!");
		} finally {
			if (zipFile.exists()) {
				zipFile.delete();//发送成功后将压缩包删除
			}
		}
		return AppResultUtil.createSuccesDto();
	}
}
