NutzCN Logo
问答 定时器里调用的Run>类。。。里面有一些
发布于 3020天前 作者 qq_7a5ddda8 2212 次浏览 复制 上一个帖子 下一个帖子
标签:
//--------run
@Override
	public void run() {
		try {
			log.info("统计活跃度run方法=========== StatisticsActivityTask");
			ConsultantActivityRun consultantActivityRun = new ConsultantActivityRun();
			consultantActivityRun.insertRecord(consultantActivityDao, insertActivityLogic);
		} catch (Exception e) {
			log.error("ConsultingStatisticTask 执行任务类出错 -======================-", e);
			e.printStackTrace();
		}
	}
//------ConsultantActivityRun
@IocBean
public class ConsultantActivityRun {

	private Dao goldDao;
	private Dao systemDao;
	private Dao bbsDao;
	private Dao coreDao;
	public ConsultantActivityRun(Dao goldDao, Dao systemDao, Dao bbsDao, Dao coreDao){
		this.bbsDao = bbsDao;
		this.goldDao = goldDao;
		this.systemDao = systemDao;
		this.coreDao = coreDao;
	}
	private static Log log = Logs.getLog(Log.class);

	public void insertRecord(ConsultantActivityDao consultantActivityDao, InsertActivityLogic insertActivityLogic, Dao bbsDao, Dao goldDao, Dao systemDao) {
		try {
			log.info("===========活跃度insertRecord方法===========");
			log.info("活跃度统计数量列表");
			List<ConsultantActivityDetail> activitDetailList = consultantActivityDao.queryDetailList(systemDao);
			log.info("活跃度详情的数据数量:" + activitDetailList.size());
			/**
			 * 登录
			 */
			insertActivityLogic.insertLoginRecord();
			/*List<ConsultantActivityDetail> activitListLogin = consultantActivityDao.queryDetailList();
			insertActivityLogic.groupToActivity(activitListLogin);*/
			/**
			 * 送暖
			 */
			insertActivityLogic.insertBbsPriseRecord();
			/*List<ConsultantActivityDetail> activitListPrise = consultantActivityDao.queryDetailList();
			insertActivityLogic.groupToActivity(activitListPrise);*/
			/**
			 * 回帖
			 */
			insertActivityLogic.insertReplyRecord();
			/*List<ConsultantActivityDetail> activitListReply = consultantActivityDao.queryDetailList();
			insertActivityLogic.groupToActivity(activitListReply);*/
			/**
			 * 释梦
			 */
			insertActivityLogic.insertDreamServiceRecord();
			/*List<ConsultantActivityDetail> activitListDream = consultantActivityDao.queryDetailList();
			insertActivityLogic.groupToActivity(activitListDream);*/
			/**
			 * 图文咨询
			 */
			insertActivityLogic.insertconsultServicRecord();
			/*List<ConsultantActivityDetail> activitListConsultService = consultantActivityDao.queryDetailList();
			insertActivityLogic.groupToActivity(activitListConsultService);*/
			/**
			 * 发帖
			 */
			/*insertActivityLogic.insertPostRecord();
			List<ConsultantActivityDetail> activitList = consultantActivityDao.queryDetailList();
			insertActivityLogic.groupToActivity(activitList);*/
			/**
			 * 星级评价
			 */
			insertActivityLogic.insertCommentLevelRecord();
			/*List<ConsultantActivityDetail> activeListCommentLv = consultantActivityDao.queryDetailList();
			insertActivityLogic.groupToActivity(activeListCommentLv);*/
			insertActivityLogic.groupToActivity(activitDetailList);
			
		} catch (Exception e) {
			log.error("===========活跃度insertRecord出现异常===========", e);
		}
	}

}
//----错误信息
org.nutz.dao.DaoException: com.alibaba.druid.pool.DataSourceClosedException: dataSource already closed at Tue Aug 16 17:48:31 CST 2016
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:76)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:205)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:183)
	at com.nuanxinli.logic.InsertActivityLogic.logintMaxTime(InsertActivityLogic.java:103)
	at com.nuanxinli.logic.InsertActivityLogic.insertLoginRecord(InsertActivityLogic.java:135)
	at com.nuanxinli.logic.ConsultantActivityRun.insertRecord(ConsultantActivityRun.java:30)
	at com.nuanxinli.scheduler.StatisticsActivityTask.run(StatisticsActivityTask.java:34)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:722)
Caused by: com.alibaba.druid.pool.DataSourceClosedException: dataSource already closed at Tue Aug 16 17:48:31 CST 2016
	at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:990)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:898)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:882)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:59)
	... 14 more

12 回复

你确定这代码能运行??? 前一句是不带构造方法的调用,然后这个类是没有无参构造方法的.

ConsultantActivityRun consultantActivityRun = new ConsultantActivityRun();

public ConsultantActivityRun(Dao goldDao, Dao systemDao, Dao bbsDao, Dao coreDao){
		this.bbsDao = bbsDao;
		this.goldDao = goldDao;
		this.systemDao = systemDao;
		this.coreDao = coreDao;
	}

我改了 可是还是不行啊 。我改成这样了
//这是 taskList 类 任务列表 里面的
StatisticsActivityTask statisticsActivityTask = new StatisticsActivityTask(consultantActivityDao,
insertActivityLogic, bbsDao, systemDao, goldDao, coreDao);
log.info("statisticsActivityTask start ...");
//这是 run
@Override
public void run() {
try {
log.info("统计活跃度run方法=========== StatisticsActivityTask");
ConsultantActivityRun consultantActivityRun = new ConsultantActivityRun(goldDao, systemDao, bbsDao);
consultantActivityRun.insertRecord(consultantActivityDao, insertActivityLogic, bbsDao, systemDao, goldDao);
} catch (Exception e) {
log.error("ConsultingStatisticTask 执行任务类出错 -======================-", e);
e.printStackTrace();
}
}
//-----------这是 run引用到的 类
//---部分1
@IocBean
public class ConsultantActivityRun {

private Dao goldDao;
private Dao systemDao;
private Dao bbsDao;
private Dao coreDao;
public ConsultantActivityRun(Dao goldDao, Dao systemDao, Dao bbsDao){
    this.bbsDao = bbsDao;
    this.goldDao = goldDao;
    this.systemDao = systemDao;
    this.coreDao = coreDao;
}
private static Log log = Logs.getLog(Log.class);

public void insertRecord(ConsultantActivityDao consultantActivityDao, InsertActivityLogic insertActivityLogic, Dao bbsDao, Dao goldDao, Dao systemDao) {
    try {
       log.info("===========活跃度insertRecord方法===========");
       log.info("活跃度统计数量列表");
       List<ConsultantActivityDetail> activitDetailList = consultantActivityDao.queryDetailList(systemDao);
       log.info("活跃度详情的数据数量:" + activitDetailList.size());
       /**
        * 登录
        */
       insertActivityLogic.insertLoginRecord();
       /*List<ConsultantActivityDetail> activitListLogin = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListLogin);*/
       /**
        * 送暖
        */
       insertActivityLogic.insertBbsPriseRecord();
       /*List<ConsultantActivityDetail> activitListPrise = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListPrise);*/
       /**
        * 回帖
        */
       insertActivityLogic.insertReplyRecord();
       /*List<ConsultantActivityDetail> activitListReply = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListReply);*/
       /**
        * 释梦
        */
       insertActivityLogic.insertDreamServiceRecord();
       /*List<ConsultantActivityDetail> activitListDream = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListDream);*/
       /**
        * 图文咨询
        */
       insertActivityLogic.insertconsultServicRecord();
       /*List<ConsultantActivityDetail> activitListConsultService = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListConsultService);*/
       /**
        * 发帖
        */
       /*insertActivityLogic.insertPostRecord();
       List<ConsultantActivityDetail> activit   List = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitList);*/
       /**
        * 星级评价
        */
       insertActivityLogic.insertCommentLevelRecord();
       /*List<ConsultantActivityDetail> activeListCommentLv = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activeListCommentLv);*/
       insertActivityLogic.groupToActivity(activitDetailList, systemDao, bbsDao, goldDao);

    } catch (Exception e) {
       log.error("===========活跃度insertRecord出现异常===========", e);
    }
}

}

insertActivityLogic 这个对象是怎么来的, 贴代码.

另外, 因为ConsultantActivityRun 是你的代码自行new出来的,所以上面的Ioc注解全部无意义.

insertActivityLogic 这是在 那 taskList列表 里面注入的啊
//-----------------taskList
package com.nuanxinli.scheduler;

import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Tasks;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import com.nuanxinli.dao.ChatLogDao;
import com.nuanxinli.dao.ChatLogDetailDao;
import com.nuanxinli.dao.ConsultantActivityDao;
import com.nuanxinli.dao.CouponDao;
import com.nuanxinli.dao.CouponPoolDao;
import com.nuanxinli.logic.BbsLogic;
import com.nuanxinli.logic.ChatLogDetailLogic;
import com.nuanxinli.logic.ChatLogLogic;
import com.nuanxinli.logic.InsertActivityLogic;
import com.nuanxinli.logic.WarmNotificationLogic;
import com.nuanxinli.util.DateUtil;

@IocBean
public class TaskList {

@Inject("refer:system_dao")
private Dao systemDao;
@Inject("refer:core_dao")
private Dao coreDao;
@Inject("refer:bbs_dao")
private Dao bbsDao;
@Inject("refer:gold_dao")
private Dao goldDao;
@Inject
private WarmNotificationLogic warmNotificationLogic;
@Inject
private CouponPoolDao couponPoolDao;
@Inject
private CouponDao couponDao;
@Inject
private BbsLogic bbsLogic;
@Inject
private ConsultantActivityDao consultantActivityDao;
@Inject
private InsertActivityLogic insertActivityLogic;
@Inject
private ChatLogDetailDao chatLogDetailDao;
@Inject
private ChatLogDao chatLogDao;
@Inject
private ChatLogDetailLogic chatLogDetailLogic;
@Inject
private ChatLogLogic chatLogLogic;

private static Log log = Logs.getLog(TaskList.class);

private static TaskList taskList;

public TaskList() {

}

public static TaskList getInstance() {
    if (taskList == null) {
       taskList = new TaskList();
    }
    return taskList;
}

public void start() {
    log.info("开始执行任务1--列表里的任务.");
    try {
       // 检查定时发送的消息,有则发送。
      WarmNotificationTask warmNotificationTask = new WarmNotificationTask(coreDao, systemDao,
          warmNotificationLogic);
       log.debug("warmNotificationTask start ...");
       Tasks.scheduleAtFixedRate(warmNotificationTask, 600);
       log.debug("warmNotificationTask end ...");

       // 心理咨询师回复用户的梦后, 用户在十天后还没有评论时, 就自动默认好评.
       DefaultCommentTask defaultCommentTask = new DefaultCommentTask(goldDao);
       log.debug("defaultCommentTask start ...");
       Tasks.scheduleWithFixedDelay(defaultCommentTask, DateUtil.getThreeAMTime(new Date(), 1, 3), 1,
          TimeUnit.DAYS);
       log.debug("defaultCommentTask end ...");

       // 给所有版块计算热度值.
       bbsLogic.setAllPartHotrank();

       // 优惠券即将过期-消息推送-在还差1天过期时发送
       CouponExpiringTask couponExpiringTask = new CouponExpiringTask(coreDao, systemDao, couponDao,
          warmNotificationLogic);
       log.debug("couponExpiringTask start ...");
       Tasks.scheduleAtFixedRate(couponExpiringTask, 3600);
       log.debug("couponExpiringTask end ...");

       // 优惠券刚刚过期-消息推送-在刚刚过期时发送
       CouponExpiredTask couponExpiredTask = new CouponExpiredTask(coreDao, systemDao, couponDao,
          warmNotificationLogic);
       log.debug("couponExpiredTask start ...");
       Tasks.scheduleWithFixedDelay(couponExpiredTask, DateUtil.getZeroTime(1), 1, TimeUnit.DAYS);
       log.debug("couponExpiredTask end ...");

       // 查询24小时未评论的用户,短信 app  都发
       CheckCommentTask checkCommentTask = new CheckCommentTask(systemDao, goldDao, coreDao, warmNotificationLogic);
       log.debug("checkCommentTask start...");
       Tasks.scheduleAtFixedRate(checkCommentTask, 3600);
       log.debug("checkCommentTask end...");
       //查询24小时未填写咨询报告的咨询师,短信 app  都发
       CheckSummaryTask checkSummaryTask = new CheckSummaryTask(systemDao, goldDao, coreDao, warmNotificationLogic);
       log.debug("checkSummaryTask start...");
       Tasks.scheduleAtFixedRate(checkSummaryTask, 3600);
       log.debug("checkSummaryTask end...");

       // 第二天凌晨2点执行, 统计第一天的咨询接诊情况.
       ConsultingStatisticTask consultingStatisticTask = new ConsultingStatisticTask(systemDao, goldDao);
       log.debug("consultingStatisticTask start ...");
       Tasks.scheduleWithFixedDelay(consultingStatisticTask, DateUtil.getThreeAMTime(new Date(), 1, 2), 1,
          TimeUnit.DAYS);
       log.debug("consultingStatisticTask end ...");  
       // 第二天凌晨3点执行,统计活跃度.
       StatisticsActivityTask statisticsActivityTask = new StatisticsActivityTask(consultantActivityDao,
          insertActivityLogic, bbsDao, systemDao, goldDao, coreDao);
       log.info("statisticsActivityTask start ...");
       /*Tasks.scheduleWithFixedDelay(statisticsActivityTask, DateUtil.getThreeAMTime(new Date(), 1, 3), 1,
          TimeUnit.DAYS);*/
       /*立即执行活跃度统计*/
       Tasks.scheduleAtFixedRate(statisticsActivityTask, 300);
       log.info("statisticsActivityTask end ...");
       // 第二天凌4点执行, 聊天记录导入.--因为开通了实时回调消息

       //ImportChatLogTask importChatLogTask = new ImportChatLogTask(chatLogLogic);
       //log.debug("importChatLogTask start ...");
       //Tasks.scheduleWithFixedDelay(importChatLogTask, DateUtil.getThreeAMTime(new Date(), 1, 4), 1, TimeUnit.DAYS);
       //log.debug("importChatLogTask end ...");


       //未付款的订单,自动取消
       OrderTimeoutTask orderTimeoutTask = new OrderTimeoutTask(goldDao);
       log.debug("orderTimeoutTask start...");
       Tasks.scheduleAtFixedRate(orderTimeoutTask, 1, 3, TimeUnit.MINUTES);
       log.debug("orderTimeoutTask end...");


       //处理咨询服务预约时间超时还没有结束的咨询记录.
       ServiceAutoEndTask serviceAutoEndTask = new ServiceAutoEndTask(systemDao, goldDao, coreDao, warmNotificationLogic);
       log.debug("serviceAutoEndTask start...");
       Tasks.scheduleAtFixedRate(serviceAutoEndTask, 360);
       log.debug("serviceAutoEndTask end...");

       // 咨询前发送通知
       CheckConsultation2 checkConsultation2 = new CheckConsultation2(systemDao, goldDao, coreDao, warmNotificationLogic);
       log.debug("checkConsultation2 start...");
       Tasks.scheduleAtFixedRate(checkConsultation2, 120);
       log.debug("checkConsultation2 end...");


    } catch (Exception e) {
       log.error(e);
    }
}

}
//-------------taskList-end
//-------------------StatisticsActivityTask -
package com.nuanxinli.scheduler;

import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import com.nuanxinli.dao.ConsultantActivityDao;
import com.nuanxinli.logic.ConsultantActivityRun;
import com.nuanxinli.logic.InsertActivityLogic;

/**
* 添加活跃度
*
* @author Administrator
*
*/
public class StatisticsActivityTask implements Runnable {

private static final Log log = Logs.getLog(ConsultingStatisticTask.class);
private Dao goldDao;
private Dao systemDao;
private Dao bbsDao;
private Dao coreDao;
private ConsultantActivityDao consultantActivityDao;
private InsertActivityLogic insertActivityLogic;

public StatisticsActivityTask(ConsultantActivityDao consultantActivityDao, InsertActivityLogic insertActivityLogic,
       Dao goldDao, Dao systemDao, Dao bbsDao, Dao coreDao) {
    this.coreDao = coreDao;
    this.systemDao = systemDao;
    this.bbsDao = bbsDao;
    this.goldDao = goldDao;
    this.consultantActivityDao = consultantActivityDao;
    this.insertActivityLogic = insertActivityLogic;
}

@Override
public void run() {
    try {
       log.info("统计活跃度run方法=========== StatisticsActivityTask");
       ConsultantActivityRun consultantActivityRun = new ConsultantActivityRun(goldDao, systemDao, bbsDao);
       consultantActivityRun.insertRecord();
    } catch (Exception e) {
       log.error("ConsultingStatisticTask 执行任务类出错 -======================-", e);
       e.printStackTrace();
    }
}

}

//---------StatisticsActivityTask-end

//------ConsultantActivityRun--
package com.nuanxinli.logic;

import java.util.List;

import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import com.nuanxinli.bo.instance.ConsultantActivityDetail;
import com.nuanxinli.dao.ConsultantActivityDao;

@IocBean
public class ConsultantActivityRun {

private Dao goldDao;
private Dao systemDao;
private Dao bbsDao;
private Dao coreDao;
private ConsultantActivityDao consultantActivityDao;
private InsertActivityLogic insertActivityLogic;
public ConsultantActivityRun(Dao goldDao, Dao systemDao, Dao bbsDao){
    this.bbsDao = bbsDao;
    this.goldDao = goldDao;
    this.systemDao = systemDao;
}
private static Log log = Logs.getLog(Log.class);

public void insertRecord() {
    try {
       log.info("===========活跃度insertRecord方法===========");
       log.info("活跃度统计数量列表");
       List<ConsultantActivityDetail> activitDetailList = consultantActivityDao.queryDetailList(systemDao);
       log.info("活跃度详情的数据数量:" + activitDetailList.size());
       /**
        * 登录
        */
       insertActivityLogic.insertLoginRecord();
       /*List<ConsultantActivityDetail> activitListLogin = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListLogin);*/
       /**
        * 送暖
        */
       insertActivityLogic.insertBbsPriseRecord();
       /*List<ConsultantActivityDetail> activitListPrise = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListPrise);*/
       /**
        * 回帖
        */
       insertActivityLogic.insertReplyRecord();
       /*List<ConsultantActivityDetail> activitListReply = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListReply);*/
       /**
        * 释梦
        */
       insertActivityLogic.insertDreamServiceRecord();
       /*List<ConsultantActivityDetail> activitListDream = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListDream);*/
       /**
        * 图文咨询
        */
       insertActivityLogic.insertconsultServicRecord();
       /*List<ConsultantActivityDetail> activitListConsultService = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitListConsultService);*/
       /**
        * 发帖
        */
       /*insertActivityLogic.insertPostRecord();
       List<ConsultantActivityDetail> activit   List = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activitList);*/
       /**
        * 星级评价
        */
       insertActivityLogic.insertCommentLevelRecord();
       /*List<ConsultantActivityDetail> activeListCommentLv = consultantActivityDao.queryDetailList();
       insertActivityLogic.groupToActivity(activeListCommentLv);*/
       insertActivityLogic.groupToActivity(activitDetailList, systemDao, bbsDao, goldDao);

    } catch (Exception e) {
       log.error("===========活跃度insertRecord出现异常===========", e);
    }
}

}

//---ConsultantActivityRun--end
//------dao

package com.nuanxinli.dao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.sql.Criteria;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import com.nuanxinli.bo.instance.ConsultantActivityDetail;

@IocBean
public class ConsultantActivityDao {
private Log log = Logs.getLog(ConsultantActivityDao.class);
/*// imeapmamt数据库
@Inject("refer:system_dao")
private Dao systemDao;
// test数据库
@Inject("refer:core_dao")
private Dao coreDao;
// bbs数据库
@Inject("refer:bbs_dao")
private Dao bbsdao;
// gold数据库
@Inject("refer:gold_dao")
private Dao golddao;*/
private Dao systemDao;
public ConsultantActivityDao(Dao systemDao){
this.systemDao = systemDao;
}
/**
* 获取详细表记录
* @return 详细表记录list
*/
public List queryDetailList(Dao systemDao){

    //2016-07-08
    Date d = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    try {
       d = sdf.parse("2016-07-08");
    } catch (ParseException e) {

    }
    Criteria cri = Cnd.cri();
    cri.where().andNotIsNull("username").and("act_time",">",d);
    List<ConsultantActivityDetail> detailList = systemDao.query(ConsultantActivityDetail.class,cri);
    return detailList;
}
public static Date minuteAfter(Date date, int n) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.DATE, n);
    return calendar.getTime();
}

}

//---dao end
//----logic
package com.nuanxinli.logic;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import com.nuanxinli.bo.instance.BbsPost;
import com.nuanxinli.bo.instance.BbsPostPraise;
import com.nuanxinli.bo.instance.BbsReply;
import com.nuanxinli.bo.instance.Consultant;
import com.nuanxinli.bo.instance.ConsultantActivity;
import com.nuanxinli.bo.instance.ConsultantActivityDetail;
import com.nuanxinli.bo.instance.ConsultingService;
import com.nuanxinli.bo.instance.DreamService;
import com.nuanxinli.bo.instance.LoginHistory;
import com.nuanxinli.bo.instance.ServiceComment;
import com.nuanxinli.util.DateUtil;

@IocBean
public class InsertActivityLogic {
private Dao systemDao;
private Dao bbsDao;
private Dao goldDao;
InsertActivityLogic(Dao systemDao, Dao bbsDao, Dao goldDao){
this.bbsDao = bbsDao;
this.goldDao = goldDao;
this.systemDao = systemDao;
}
// imeapmamt数据库
/*@Inject("refer:system_dao")
private Dao systemDao;
// test数据库
@Inject("refer:core_dao")
private Dao coreDao;
// bbs数据库
@Inject("refer:bbs_dao")
private Dao bbsdao;
// gold数据库
@Inject("refer:gold_dao")
private Dao golddao;*/
private static String dateStr = DateUtil.getStringTomorrowZeroDateLong(new Date(), -1);
/**
* 添加信息到统计表
*
* @param username
* @param cadList
*/

public void groupToActivity(List<ConsultantActivityDetail> cadList, Dao systemDao, Dao bbsDao, Dao goldDao) {
    // 创建map
    Map<String, ConsultantActivity> activeMap = new HashMap<String, ConsultantActivity>();
    for (ConsultantActivityDetail detail : cadList) {
       // 获取详细动作时间
       String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(detail.getActTime());
       // 按时间生成唯一Key,便于统计
       String key = detail.getUsername() + detail.getActName() + dateStr;
       // 创建一个ConsultantActivity
       ConsultantActivity act = activeMap.get(key);
       if (act == null) {
         act = new ConsultantActivity();
         act.setActName(detail.getActName()+detail.getActDecoration());
         act.setUsername(detail.getUsername());
         act.setPoint(detail.getPoint());
         act.setActCount(1);
         act.setActTime(detail.getActTime());
         activeMap.put(key, act);
       } else {
         act.setActCount(act.getActCount() + 1);
         act.setPoint(act.getPoint() + detail.getPoint());
       }
    }
    //
    for (ConsultantActivity act : activeMap.values()) {

       List<ConsultantActivity> oldActList = systemDao.query(
          ConsultantActivity.class,
          Cnd.where("act_name", "=", act.getActName()).and("username", "=", act.getUsername())
                 .and("act_time", "=", DateUtil.getStringDateShort(act.getActTime())));
       if (oldActList.isEmpty()) {
         systemDao.insert(act);
       } else {
         ConsultantActivity oldAct = oldActList.get(0);
         oldAct.setActCount(act.getActCount());
         oldAct.setPoint(act.getPoint());
         systemDao.update(oldAct);
       }
    }
}


/** 
 * --------登录
 * @throws ParseException 
 */
// 获取详细表中最后登录时间 Maxtime
public Date logintMaxTime() throws ParseException {
    Sql sql = Sqls.create("select max(act_time) from consultant_activity_detail where act_name = '登录'");
    sql.setCallback(Sqls.callback.str());
    systemDao.execute(sql);
    String timeObj = (String) sql.getResult();
    if(timeObj == null){
       Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
       return d;
    }
    Date maxTime = null;
    try {
       String timeStr = timeObj.substring(0, timeObj.length() - 2);
       maxTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeStr);
       System.out.println(maxTime);
    } catch (ParseException e) {
       e.printStackTrace();
    }
    return maxTime;
}


// 按时间查询登录统计
public List<LoginHistory> queryLoginHistory(Date maxTime) {
    List<Consultant> consultList = systemDao.query(Consultant.class,Cnd.where("1","=","1"));
    List<LoginHistory> list = null;
    List<LoginHistory> loginHistory = new ArrayList<LoginHistory>();
    for(int i = 0;i < consultList.size();i ++){
       list = systemDao.query(LoginHistory.class, Cnd.where("login_time", ">", maxTime).and("username","=",consultList.get(i).getUsername()));
       loginHistory.addAll(list);
    }
    return loginHistory;
}

// 添加到detail
public void insertLoginRecord() throws ParseException {
    Date d = logintMaxTime();
    // --正式部署时候换成MaxTime 取记录中最大时间
    List<LoginHistory> querylist = queryLoginHistory(d);
    for (LoginHistory lg : querylist) {
       if (lg.getLoginTime() != null && lg.getUsername() != null) {
         ConsultantActivityDetail active = new ConsultantActivityDetail();
         active.setActName("登录");
         active.setActTime(lg.getLoginTime());
         active.setUsername(lg.getUsername());
         active.setPoint(1);
         systemDao.insert(active);
       }
    }
}
/**
 * --------送暖
 * @throws ParseException 
 */

public Date priseMaxTime() throws ParseException {
    Sql sql = Sqls.create("select max(act_time) from consultant_activity_detail where act_name = '送暖'");
    sql.setCallback(Sqls.callback.str());
    systemDao.execute(sql);
    String timeObj = (String) sql.getResult();
    if(timeObj == null){
       Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
       return d;
    }
    Date maxTime = null;
    try {
       String timeStr = timeObj.substring(0, timeObj.length() - 2);
       maxTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeStr);
       System.out.println(maxTime);
    } catch (ParseException e) {
       e.printStackTrace();
    }
    //TODO 部署时候改为d当前时间

    return maxTime;
}
// 按时间查询送暖统计
    public List<BbsPostPraise> queryBbsPriseHistory(Date maxTime) {
       List<Consultant> consultList = systemDao.query(Consultant.class,Cnd.where("1","=","1"));
       List<BbsPostPraise> list = null;
       List<BbsPostPraise> bbsPostPraiseList = new ArrayList<BbsPostPraise>();
        for(Consultant c : consultList){
         list = bbsDao.query(BbsPostPraise.class, Cnd.where("create_time", ">", maxTime).and("username","=",c.getUsername()));
         bbsPostPraiseList.addAll(list);
        }
       return bbsPostPraiseList;
    }
    //添加送暖记录
    public void insertBbsPriseRecord() throws ParseException {
       Date d = priseMaxTime();
       // --正式部署时候换成MaxTime 取记录中最大时间
       List<BbsPostPraise> querylist = queryBbsPriseHistory(d);
       for (BbsPostPraise lg : querylist) {
         if (lg.getCreateTime() != null && lg.getUsername() != null) {
          ConsultantActivityDetail active = new ConsultantActivityDetail();
          active.setActName("送暖");
          active.setActTime(lg.getCreateTime());
          active.setUsername(lg.getUsername());
          active.setPoint(3);
          systemDao.insert(active);
         }
       }
    }
    /**
     * --------回帖
     * @throws ParseException 
     */
    // 获取详细表中最后回帖时间 Maxtime
    public Date replaceMaxTime() throws ParseException{
       Sql sql = Sqls.create("select max(act_time) from consultant_activity_detail where act_name = '回帖'");
       sql.setCallback(Sqls.callback.str());
       systemDao.execute(sql);
       String timeObj = (String) sql.getResult();
       if(timeObj == null){
         Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
         return d;
       }
       Date maxTime = null;
       try {
         String timeStr = timeObj.substring(0, timeObj.length() - 2);
         maxTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeStr);
         System.out.println(maxTime);
       } catch (ParseException e) {
         e.printStackTrace();
       }

       return maxTime;
    }

    // 按时间查询回帖统计
    public List<BbsReply> queryReplyHistory(Date maxTime) {
       List<Consultant> consultList = systemDao.query(Consultant.class,Cnd.where("1","=","1"));
       List<BbsReply> list = null;
       List<BbsReply> replaceHistoryList = new ArrayList<BbsReply>();
       for(Consultant c : consultList){
        list = bbsDao.query(BbsReply.class, Cnd.where("create_time", ">", maxTime).and("create_user","=",c.getUsername()));
        replaceHistoryList.addAll(list);
       }
       return replaceHistoryList;
    }

    // 添加到detail
    public void insertReplyRecord() throws ParseException {
       Date d = replaceMaxTime();
       // --正式部署时候换成MaxTime 取记录中最大时间
       List<BbsReply> querylist = queryReplyHistory(d);
       for (BbsReply lg : querylist) {
         if (lg.getCreateTime() != null && lg.getCreateUser() != null) {
          ConsultantActivityDetail active = new ConsultantActivityDetail();
          active.setActName("回帖");
          active.setActTime(lg.getCreateTime());
          active.setUsername(lg.getCreateUser());
          active.setPoint(10);
          systemDao.insert(active);
         }
       }
    }
    /**
     * --------释梦
     * @throws ParseException 
     */
    // 获取详细表中最后释梦时间 Maxtime
    public Date dreamServiceMaxTime() throws ParseException{
       Sql sql = Sqls.create("select max(act_time) from consultant_activity_detail where act_name = '释梦'");
       sql.setCallback(Sqls.callback.str());
       systemDao.execute(sql);
       String timeObj = (String) sql.getResult();
       if(timeObj == null){
         Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
         return d;
       }
       Date maxTime = null;
       try {
         String timeStr = timeObj.substring(0, timeObj.length() - 2);
         maxTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeStr);
         Date ddd = maxTime;
         System.out.println(ddd);
       } catch (ParseException e) {
         e.printStackTrace();
       }

       return maxTime;
    }

    // 按时间查询释梦统计
    public List<DreamService> queryDreamServiceHistory(Date maxTime) {
       List<Consultant> consultList = systemDao.query(Consultant.class,Cnd.where("1","=","1"));
       List<DreamService> list = null;
       List<DreamService> dreamserviceHistoryList = new ArrayList<DreamService>();
       for(Consultant c : consultList){
       list = goldDao.query(DreamService.class, Cnd.where("create_time", ">", maxTime).and("provider_name","=",c.getUsername()));
        dreamserviceHistoryList.addAll(list);
       }
        return dreamserviceHistoryList;
    }

    // 添加到detail
    public void insertDreamServiceRecord() throws ParseException {
       Date d = dreamServiceMaxTime();
       // --正式部署时候换成MaxTime 取记录中最大时间
       List<DreamService> querylist = queryDreamServiceHistory(d);
       for (DreamService lg : querylist) {
         if (lg.getCreateTime() != null && lg.getProviderName() != null) {
          ConsultantActivityDetail active = new ConsultantActivityDetail();
          active.setActName("释梦");
          active.setActTime(lg.getCreateTime());
          active.setUsername(lg.getProviderName());
          active.setPoint(15);
          systemDao.insert(active);
         }
       }
    }
    /**
     * -----图文咨询
     * @throws ParseException 
     */
    public Date consultServiceMaxTime() throws ParseException{
       Sql sql = Sqls.create("select max(act_time) from consultant_activity_detail where act_name = '图文咨询'");
       sql.setCallback(Sqls.callback.str());
       systemDao.execute(sql);
       String timeObj = (String) sql.getResult();
       if(timeObj == null){
         Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
         return d;
       }
       Date maxTime = null;
       try {
         String timeStr = timeObj.substring(0, timeObj.length() - 2);
         maxTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeStr);
         System.out.println(maxTime);
       } catch (ParseException e) {
         e.printStackTrace();
       }

       return maxTime;
    }

    // 按时间查询图文咨询统计
    public List<ConsultingService> queryConsultingServicHistory(Date maxTime) {
      List<Consultant> consultList = systemDao.query(Consultant.class,Cnd.where("1","=","1"));
      List<ConsultingService> list = null;
      List<ConsultingService> consultingServiceList = new ArrayList<ConsultingService>();
       for(Consultant c : consultList){
         list = goldDao.query(ConsultingService.class, Cnd.where("create_time", ">", maxTime).and("provider_name","=",c.getUsername()));
         consultingServiceList.addAll(list);
       }
       return consultingServiceList;
    }

    // 添加到detail
    public void insertconsultServicRecord() throws ParseException {
       Date d = consultServiceMaxTime();
       // --正式部署时候换成MaxTime 取记录中最大时间
       List<ConsultingService> querylist = queryConsultingServicHistory(d);
       for (ConsultingService lg : querylist) {
         if (lg.getCreateTime() != null && lg.getProviderName() != null) {
          ConsultantActivityDetail active = new ConsultantActivityDetail();
          active.setActName("图文咨询");
          active.setActTime(lg.getCreateTime());
          active.setUsername(lg.getProviderName());
          active.setPoint(20);
          systemDao.insert(active);
         }
       }
    }

    /**
     * ----发帖
     * @throws ParseException 
     */
    public Date postMaxTime() throws ParseException {
       Sql sql = Sqls.create("select max(act_time) from consultant_activity_detail where act_name = '发帖'");
       sql.setCallback(Sqls.callback.str());
       systemDao.execute(sql);
       String timeObj = (String) sql.getResult();
       if(timeObj == null){
         Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
         return d;
       }
       Date maxTime = null;
       try {
         String timeStr = timeObj.substring(0, timeObj.length() - 2);
         maxTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeStr);
         System.out.println(maxTime);
       } catch (ParseException e) {
         e.printStackTrace();
       }

       return maxTime;
    }


    public List<BbsPost> queryPostHistory(Date maxTime) {
       List<Consultant> consultList = systemDao.query(Consultant.class,Cnd.where("1","=","1"));
       List<BbsPost> list = null;
       List<BbsPost> bbsPostHistoryList = new ArrayList<BbsPost>();
        for(Consultant c : consultList){
         list = bbsDao.query(BbsPost.class, Cnd.where("create_time", ">", maxTime).and("create_user","=",c.getUsername()));
         bbsPostHistoryList.addAll(list);
       }
       return bbsPostHistoryList;
    }

    // 添加到detail
    public void insertPostRecord() throws ParseException {
       Date d = postMaxTime();
       List<BbsPost> querylist = queryPostHistory(d);
       for (BbsPost lg : querylist) {
         if (lg.getCreateTime() != null && lg.getCreateUser() != null) {
          ConsultantActivityDetail active = new ConsultantActivityDetail();
          active.setActName("发帖");
          active.setActTime(lg.getCreateTime());
          active.setUsername(lg.getCreateUser());
          active.setPoint(15);
          systemDao.insert(active);
         }
       }
    }
    /**
     * 获得 星级评价
     * @throws ParseException 
     */
    public Date commentLevelMaxTime() throws ParseException {
       Sql sql = Sqls.create("select max(act_time) from consultant_activity_detail where act_name = '评价'");
       sql.setCallback(Sqls.callback.str());
       systemDao.execute(sql);
       String timeObj = (String) sql.getResult();
       if(timeObj == null){
         Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr);
         return d;
       }
       Date maxTime = null;
       try {
         String timeStr = timeObj.substring(0, timeObj.length() - 2);
         maxTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeStr);
         System.out.println(maxTime);
       } catch (ParseException e) {
         e.printStackTrace();
       }

       return maxTime;
    }


    // ----获取评价最大时间
    public List<ServiceComment> queryCommentLevelHistory(Date maxTime) {
       List<Consultant> consultList = systemDao.query(Consultant.class,Cnd.where("1","=","1"));
       List<ServiceComment> list = null;
       List<ServiceComment> serviceCommentList = new ArrayList<ServiceComment>();
        for(Consultant c : consultList){
        list = goldDao.query(ServiceComment.class, Cnd.where("create_time", ">", maxTime).and("provider_name","=",c.getUsername()));
        serviceCommentList.addAll(list);
        }
       return serviceCommentList;
    }

    // 添加到detail
    public void insertCommentLevelRecord() throws ParseException {
       Date d = commentLevelMaxTime();
       // --正式部署时候换成MaxTime 取记录中最大时间
       List<ServiceComment> querylist = queryCommentLevelHistory(d);
       for (ServiceComment lg : querylist) {
         if (lg.getCreateTime() != null && lg.getLevel() != null) {
          ConsultantActivityDetail active = new ConsultantActivityDetail();
          active.setActName("评价");
          active.setActTime(lg.getCreateTime());
          active.setUsername(lg.getProviderName());
          active.setActDecoration("获得"+lg.getLevel()+"星");
          switch (lg.getLevel()) {
          case 1:
              active.setPoint(5);
              systemDao.insert(active);
              break;
          case 2:

              active.setPoint(10);
              systemDao.insert(active);
              break;
          case 3:

              active.setPoint(15);
              systemDao.insert(active);
              break;
          case 4:

              active.setPoint(20);
              systemDao.insert(active);
              break;
          case 5:

              active.setPoint(25);
              systemDao.insert(active);
              break;

          }
         }
       }
    }

}
//----

另外,这不是web项目吗? 如果是, 用下面的代码就能拿到Ioc容器

Ioc ioc = Mvcs.ctx().getDefaultIoc();

还有就是, 如果是mvc项目(且使用的是nutz mvc), 是不是存在new NutIoc的代码? 这点非常重要

菜单有贴代码的按钮啊!!!! 不要直接贴代码啊啊啊!!!! 图片按钮的旁边啊啊啊啊


o(╯□╰)o。。。不好意思啊 我有点迷糊

既然你说上面的都是注入得到的,那么这是啥? 自行new了对象?

public TaskList() {

}

public static TaskList getInstance() {
    if (taskList == null) {
       taskList = new TaskList();
    }
    return taskList;
}

如果是通过 TaskList.getInstance()拿到的实例,那么该实例的属性全是null. 然后, 因为抛出的并不是空指针异常,所以, 推测并不能通过getInstance拿到的实例

那么 TaskList的实例是哪里来的呢? 贴出相关代码,且回答"是不是Mvc项目?" 有没有"new NutIoc"这种代码存在?

TaskList 能拿到啊 !在 启动的时候
这里

/**
 * 系统初始化公共类
 */
public class Setup implements org.nutz.mvc.Setup {

	private static final Log log = Logs.getLog(Setup.class);

	/**
	 * 系统启动事件
	 */
	@Override
	public void init(NutConfig config) {
		
		log.info("Setup init...");
		TaskList taskList = Mvcs.getIoc().get(TaskList.class, "taskList");
		taskList.start();
		TaskList2 taskList2 = Mvcs.getIoc().get(TaskList2.class, "taskList2");
		taskList2.start();
		log.info("-----任务计时器工具加载完毕-----");
	}

	/**
	 * 系统关闭事件
	 */
	@Override
	public void destroy(NutConfig config) {
	}

}

这是个定时器啊 mvc 结构 没有很明确 就是有个任务类,有个 执行列表

着急哭了 啊啊啊 我这改的 越来越离谱了 taskList都拿不到了

 org.nutz.ioc.IocException: create ioc bean fail name=taskList ioc define:

@qq_7a5ddda8 那就统统退回去

来自炫酷的 NutzCN

话说我也没叫你改啥呢

问题要一步步分析,而不是乱改一通,找到原因了再试着改

来自炫酷的 NutzCN

添加回复
请先登陆
回到顶部