定时任务类:
package com.cairenhui.sec.task;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.mail.internet.MimeMessage;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import com.cairenhui.sec.service.ObsUserHkInfoService;
import com.cairenhui.sec.util.ExcelUtil;
import com.cairenhui.sec.utils.PropertiesUtils;
/**
*
* @author jinxd 2014-12-29 从数据库中导出excel,然后调用邮件发送接口,发送邮件
*/
@Component
public class HKTask {
@Autowired
private ObsUserHkInfoService obsUserHkInfoService;
@Autowired
private JavaMailSenderImpl mailSender;
private static final Logger log = Logger.getLogger(HKTask.class);
/**
* 港股通业务,通过OBS_USER_HK_INFO表,每天23:55导出excel,并发送邮件
*/
public void sendHKInfoEmailJob() {
long t1 = System.currentTimeMillis();
log.info("-------------- 执行港股通定时任务 start --------------------" + t1);
try {
@SuppressWarnings("unchecked")
List<Map<String, Object>> list = obsUserHkInfoService.findTheSameDay();// 查询数据
if (list.size() > 0) {
StringBuilder fileName = new StringBuilder();
String name = "HKStockCount_" + (new Date()).getTime();// 表格名字
String encoderName = "";
try {
encoderName = URLEncoder.enc