package com.strongit.zwjc.infopush.vo;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import com.strongit.zwjc.common.dao.BaseDAO;
import com.strongit.zwjc.infopush.po.Afficheinfo;
import com.strongit.zwjc.infopush.po.InfopushDocClass;
import com.strongit.zwjc.infopush.po.Performance;
import com.strongit.zwjc.util.TimeKit1;
/**
* 瀹氫竴涓畾鏃舵煡璇㈢殑綾?br />
*/
public class ScheduledTimer {
/**
* 瀹氭椂榪愯鐨勬柟娉?br />
*/
private BaseDAO baseDaoImpl;
@SuppressWarnings({ "unchecked", "deprecation" })
public void startRun() throws Exception {
// 絎竴錛屾煡璇㈢被鍨嬭〃涓殑瑙勫垯
Calendar now = Calendar.getInstance();
@SuppressWarnings("unused")
int nowDay = now.get(Calendar.DAY_OF_MONTH);
int nowMonth = now.get(Calendar.MONTH) + 1;
List<InfopushDocClass> InfopushClassList = this.baseDaoImpl
.findAll(InfopushDocClass.class);
String docPushRule = "monthly:15";
@SuppressWarnings("unused")
String monthly = "";
String strDay = "";
int intDay = 0;
String classId = "";
String className = "" ;
String orgId = "";
String orgName = "orgName" ;
//InfopushDoc infopushDoc = null;
List infopushDocList = null ;
Performance performance = null ;
Afficheinfo afficheinfo = null ;
String strSfficheinfo = "" ;
List<Performance> performanceList = null ;
Date performanceDate = TimeKit1.getDateByString(TimeKit1.now("short"));
for (InfopushDocClass infopushDocClass : InfopushClassList) {
docPushRule = infopushDocClass.getDocPushRule();
classId = infopushDocClass.getClassId();
orgId = infopushDocClass.getOrgId();
monthly = docPushRule.split(":")[0];
strDay = docPushRule.split(":")[1];
intDay = Integer.parseInt(strDay);
//姝ゆ柟娉曞彧鑳介傚簲涓?nbsp;鏈堟姤
if (nowDay == intDay) {
infopushDocList = this.baseDaoImpl
.findAll("FROM InfopushDoc idoc where idoc.infopushDocClass.classId='"
+ classId
+ "' and idoc.orgId = '"
+ orgId
+ "'");
int totalsize = infopushDocList.size() ;
performanceList = this.baseDaoImpl.findAll(Performance.class);
if(totalsize>0){
boolean flag = false ;
for(Performance performance2:performanceList){
int performanceMonth = performance2.getPerformanceDate().getMonth()+1 ;
if(nowMonth==performanceMonth){
flag = true ;
break ;
}
}
if(flag){
}else{
// 鏈夋暟鎹?nbsp;鍔犲垎
className = infopushDocClass.getClassName() ;
orgName = infopushDocClass.getOrgName() ;
performance = new Performance() ;
performance.setClassId(classId);
performance.setOrgId(orgId);
performance.setOrgName(orgName);
performance.setClassName(className);
performance.setPerformanceDate(performanceDate);
performance.setScore(Long.valueOf("1"));
this.baseDaoImpl.insert(performance);
}
}else{
boolean flag = false ;
for(Performance performance2:performanceList){
int performanceMonth = performance2.getPerformanceDate().getMonth()+1 ;
if(nowMonth==performanceMonth){
flag = true ;
break ;
}
}
if(flag){
}else{
// 娌℃湁鏁版嵁 涓?鍒嗭紝騫朵笖閫氭姤
orgName = infopushDocClass.getOrgName() ;
className = infopushDocClass.getClassName() ;
performance = new Performance() ;
performance.setClassId(classId);
performance.setClassName(className);
performance.setOrgId(orgId);
performance.setOrgName(orgName);
performance.setPerformanceDate(performanceDate);
performance.setScore(Long.valueOf("0"));
this.baseDaoImpl.insert(performance);
className = infopushDocClass.getClassName() ;
afficheinfo = new Afficheinfo() ;
afficheinfo.setClassId(classId);
afficheinfo.setOrgId(orgId);
afficheinfo.setAfficheinfoDate(performanceDate);
strSfficheinfo = "銆?/span>"+TimeKit1.getNowDate()+"銆戙?/span>"+orgName+"銆戞湭鎺ㄩ併?/span>"+className+"銆戝垎綾繪枃鐚俊鎭?/span>" ;
afficheinfo.setAfficheInfo(strSfficheinfo);
afficheinfo.setClassName(className);
afficheinfo.setOrgName(orgName);
this.baseDaoImpl.insert(afficheinfo);
}
}
}
}
System.out.println("鎴愬姛鎻掑叆錛侊紒");
}
public BaseDAO getBaseDaoImpl() {
return baseDaoImpl;
}
public void setBaseDaoImpl(BaseDAO baseDaoImpl) {
this.baseDaoImpl = baseDaoImpl;
}
}
applicationContext-infopush-timer.xml錛?br />
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 瀹氭椂榪愯鐨勭被 -->
<bean id="scheduledTimer"
class="com.strongit.zwjc.infopush.vo.ScheduledTimer">
<property name="baseDaoImpl">
<ref bean="baseDAO" />
</property>
</bean>
<!--瀹氫箟瀹氭椂鎵цScheduledTimer綾諱腑 鐨剆tartRun()鏂規硶-->
<bean id="scheduledTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="scheduledTimer" />
</property>
<property name="targetMethod">
<value>startRun</value>
</property>
</bean>
<!--瑙﹀彂鍣ㄧ殑bean鐨勮緗紝鍦ㄨ繖閲屾垜浠緗簡鎴戜滑瑕佽Е鍙戠殑jobDetail鏄摢涓?br />
榪欓噷鎴戜滑瀹氫箟浜嗚瑙﹀彂鐨刯obDetail錛屽嵆瑙﹀彂鍣ㄥ幓瑙﹀彂鍝釜bean..騫朵笖鎴戜滑榪樺畾涔変簡瑙﹀彂鐨勬椂闂?/span>-->
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="scheduledTask" />
</property>
<property name="cronExpression">
<!-- 鍏抽敭鍦ㄩ厤緗琛ㄨ揪寮?nbsp;姣忓ぉ涓崍12鐐歸挓鏁磋Е鍙戜簨浠?/span>-->
<value>0 0 12 * * ?</value>
</property>
</bean>
<!--綆$悊瑙﹀彂鍣ㄧ殑鎬昏緗?鍙互鏀劇疆澶氫釜瑙﹀彂鍣ㄣ?/span>-->
<bean autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
</beans>
涓よ呯粨鍚堝氨鑳藉疄鐜板畾鏃惰繍琛岀▼搴忥紒

]]>