呼叫介面實現定時功能
web端:
<span class="subt"><input type="button" value="定時" id="submitButOntime" onclick="javascript:addOrderOntime();"/></span>
<div style="display: none; " id="dingshifabu">
<input type="text" id="rqStartOntime" name="" size="20" value="<s:property value='bean.pickupDate'/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});" class="Wdate">
<span ><input type="button" value="定時" id="submitButOntime" onclick="javascript:orderOntime();"/></span>
$("#submitButOntime").toggle(function(){
$("#dingshifabu").css("display", "block");
},function(){
$("#dingshifabu").css("display", "none");
})
js部分:
var url=proContextPath + "/good/good_addGoodr.action?bean.timingRelease="+timingRelease;
$("#submitBut").attr("disabled","disabled");
$.ajax({
type: "POST",
url: url,
data:$("#searchForm").serialize()+paramStr,
success:function(data){
var obj = eval("("+data+")");
alert(obj.outResultReason);
if(obj.outResult=="1"){
$('#importId').val("");
$('#goodsOwnerId').val("");
$("#submitBut").removeAttr("disabled");
}else{
$("#submitBut").removeAttr("disabled");
}
},
error:function(XMLHttpRequest, textStatus, errorThrown){
$("#submitBut").removeAttr("disabled");
}
});
java部分:
Date date =new Date();
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowDate=format.format(date);
if(bean.getTimingRelease()==null || bean.getTimingRelease()==""){
map.put("status", "20");
map.put("timingRelease", nowDate);
}else {
map.put("timingRelease", bean.getTimingRelease());
map.put("status", "10");
}
api部分:
public class TimingListener implements ServletContextListener {private Timer timer = null;
public void contextInitialized(ServletContextEvent event) {
timer = new Timer(true);
try{
this.timingRelease();
}catch(Exception e){
e.printStackTrace();
}
}
public void contextDestroyed(ServletContextEvent event) {
timer.cancel();
}
public void timingRelease(){
timer = new Timer(true);
Calendar theTaskCalendar = Calendar.getInstance();
theTaskCalendar.add(Calendar.MINUTE, 1);
theTaskCalendar.add(Calendar.SECOND, 0);
long interval =1000*60*10;
timer.schedule(new TimingRelease(interval), theTaskCalendar.getTime(), interval);
}
}
--------------------------
public class TimingRelease extends TimerTask{
protected Log log;
ArrayList list;
long intervalTime;
private Map map;
public TimingRelease(long interval){
this.log = LogFactory.getLog(super.getClass());
this.intervalTime = interval;
}
@Override
public void run() {
try {
this.map = new HashMap();
this.map.put("switchType", "DS_00006");
ITaskService taskService = (ITaskService)SpringBeanProxy.getBean("taskService");
this.list = ((ArrayList)taskService.getPlatformList(this.map));
this.map.clear();
for(int i=0 ;i<list.size() ; i++){
this.map = (Map)this.list.get(i);
if (this.map.get("switchValue").equals("1")) {
taskService.OnTimingRelease(this.map);
}
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("定時異常:" + e.getMessage());
}
}
public Map getMap() {
return map;
}
public void setMap(Map map) {
this.map = map;
}}
------------
public void OnTimingRelease(Map map) {
map.put("platformId", map.get("platformId"));
dao.update("json.onTimingRelease", map);
}
--------------------
<update id="json.onTimingRelease" parameterClass="map">
UPDATE goodsorderm a
SET a.`status` = '20'
WHERE
a.`status` = '10'
and a.platform_id=#platformId#
AND a.timingRelease < NOW()
</update>