1、applicationContext-quartz.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">
<!-- 网格化接口定时器 -->
<bean id="jobDetail2"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="matterQuartz" />
</property>
<property name="targetMethod">
<value>reportPort</value>
</property>
</bean>
<!-- 网格化接口定时器 -->
<bean id="cornTrigger2" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail2"/>
<property name="cronExpression" value="0 0 0/12 * * ?" />
</bean>
<!-- 定义核心调度器 -->
<bean id="scheduler" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<!-- 网格化接口定时器 -->
<ref bean="cornTrigger2"/>
</list>
</property>
</bean>
<bean id="matterQuartz" class="com.jpxx.util.weixin.core.MatterQuartz" />
</beans>
2、MatterQuartz.java
package com.jpxx.util.weixin.core;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import com.jpxx.controller.base.BaseController;
import com.jpxx.service.weixin.matter.MatterService;
import com.jpxx.service.weixin.report.ReportService;
import com.jpxx.util.PageData;
import com.jpxx.util.UuidUtil;
/**
*
* @ClassName: MatterQuartz
* @Description: 网格化接口定时器
* @author Jiaanjun Jiaanjunvv@126.com
* @date 2016-5-5 上午9:50:36
*/
public class MatterQuartz extends BaseController{
@Resource(name="reportService")
private ReportService reportService;
//我要上报数据对接
public void reportPort() {
PageData pd = new PageData();
try {
//更新问题
reportService.updatelistupdatematter(pd);
} catch (Exception e) {
}
}
}
3、reportService.java
//获取问题列表接口
@SuppressWarnings("unchecked")
public List<PageData> updatelistupdatematter(PageData pd)throws Exception{
Properties pro = GetProperties.getKey("wgh.properties");
String url = pro.getProperty("getUrl");
List<PageData> listoldmatter = (List<PageData>)dao.findForList("ReportMapper.listAllByisOver", pd);
if(listoldmatter.size()>0){
for(int i=0;i<listoldmatter.size();i++){
PageData pds = listoldmatter.get(i);
if(!pds.getString("eId").equals("")&&pds.getString("eId")!=null){
String result;
try {
result = HttpRequest.sendGet(url+pds.getString("eId"));
JSONObject newresult = JSONObject.fromObject(result);
int errorCode = (int)newresult.getInt("errorCode");
if(errorCode==0){
JSONObject eventInfoData = (JSONObject)newresult.get("eventInfoData");
pd = new PageData();
pd.put("id", pds.getString("id"));
pd.put("eId", eventInfoData.get("id"));//唯一标识
pd.put("title", pds.getString("title"));//标题
pd.put("name", pds.getString("name"));//提交用户
pd.put("address", pds.getString("address"));//地址
pd.put("content", pds.getString("content"));//描述
pd.put("createTime", pds.getString("createTime"));//提交时间
if(eventInfoData.getInt("isFiling") == 2){ //已废弃
pd.put("isDo", "4");//已废除
}else if(eventInfoData.getInt("isFiling") == 0){ //不立案
if(eventInfoData.getInt("isOver") == 1){
pd.put("isDo", "3");//已办结
pd.put("doUserName", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doUserName"));//办理人
pd.put("doInfo", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doInfo"));//办理信息
pd.put("doDate", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doDate"));//办理时间
}else{
pd.put("isDo", "1");//已受理
}
}else if(eventInfoData.getInt("isFiling") == 1){//立案
if(eventInfoData.getInt("isOver") == 1){
pd.put("isDo", "3");//已办结
pd.put("doUserName", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doUserName"));//办理人
pd.put("doInfo", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doInfo"));//办理信息
pd.put("doDate", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doDate"));//办理时间
}else{
pd.put("isDo", "2");//处理中
pd.put("doUserName", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doUserName"));//办理人
pd.put("doInfo", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doInfo"));//办理信息
pd.put("doDate", eventInfoData.getJSONArray("eventTasks").getJSONObject(0).getString("doDate"));//办理时间
}
}
pd.put("isSynchro", "1");//是否同步
pd.put("isOver",eventInfoData.getInt("isOver")+"");//是否办结
pd.put("longitude", pds.getString("coordLong"));//经度
pd.put("latitude", pds.getString("coordLat"));//北纬
dao.update("ReportMapper.edit", pd);
}
} catch (Exception e) {
System.out.println("接口更新失败");
}
}
}
}
return listoldmatter;
}