|
|
package GPA;
|
|
|
|
|
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
public class startGPA {
|
|
|
private final int MAX_ERROR_MSG=1000;
|
|
|
private List<Thread> stop_list;
|
|
|
private List<State> state_list;
|
|
|
private List<String> ErrorMsg_list;
|
|
|
{
|
|
|
stop_list=new ArrayList<>();
|
|
|
state_list=new ArrayList<>();
|
|
|
ErrorMsg_list=new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
|
|
|
public static class State{
|
|
|
long ThreadId;
|
|
|
long StateUpdateTime;
|
|
|
}
|
|
|
|
|
|
public synchronized void UpdateState(long ThreadId){
|
|
|
for (int i = 0; i < state_list.size(); i++) {
|
|
|
State s=state_list.get(i);
|
|
|
if (s.ThreadId==ThreadId){
|
|
|
s.StateUpdateTime=System.currentTimeMillis();
|
|
|
state_list.set(i,s);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
public synchronized Date GetRunState(){
|
|
|
long minTime=0;
|
|
|
for (int i = 0; i < state_list.size(); i++) {
|
|
|
State s=state_list.get(i);
|
|
|
if (s.StateUpdateTime < minTime || minTime==0){
|
|
|
minTime=s.StateUpdateTime;
|
|
|
}
|
|
|
}
|
|
|
return new Date(minTime);
|
|
|
}
|
|
|
|
|
|
public void WriteLog(String info){
|
|
|
|
|
|
}
|
|
|
public synchronized boolean init(String jarPath){
|
|
|
WriteLog("软件启动");
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
boolean runAble=true;
|
|
|
|
|
|
|
|
|
public synchronized void stop(){
|
|
|
runAble=false;
|
|
|
for (int i = 0; i < stop_list.size(); i++) {
|
|
|
Thread thread=stop_list.get(i);
|
|
|
try {
|
|
|
LogClass.debug("开始停止"+thread);
|
|
|
thread.join(1000);
|
|
|
LogClass.debug("已停止"+thread);
|
|
|
}
|
|
|
catch (Exception e){
|
|
|
WriteLog("停止线程错误:"+e.getMessage());
|
|
|
LogClass.debug("程序停止异常"+e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
stop_list.clear();
|
|
|
state_list.clear();
|
|
|
WriteLog("线程停止");
|
|
|
}
|
|
|
|
|
|
public synchronized String[] GetErrorLog(){
|
|
|
int MsgCount=ErrorMsg_list.size();
|
|
|
if (MsgCount>MAX_ERROR_MSG){
|
|
|
MsgCount=MAX_ERROR_MSG;
|
|
|
}
|
|
|
String[] ErrorLogs=new String[MsgCount];
|
|
|
for (int i = 0; i < MsgCount; i++) {
|
|
|
ErrorLogs[i]=ErrorMsg_list.get(i);
|
|
|
}
|
|
|
for (int i = 0; i < MsgCount; i++) {
|
|
|
ErrorMsg_list.remove(0);
|
|
|
}
|
|
|
return ErrorLogs;
|
|
|
}
|
|
|
|
|
|
public synchronized void SetErrorLog(int Type,int MsgCode,String info){
|
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
String ErrorInfo="{\"TYPE\":"+String.valueOf(Type)+",\"MSGCODE\":"+String.valueOf(MsgCode)+",\"MSG\":"+String.valueOf(info)+",\"DT\":\""+sdf.format(new Date())+"\"}";
|
|
|
ErrorMsg_list.add(ErrorInfo);
|
|
|
while (ErrorMsg_list.size()>MAX_ERROR_MSG){
|
|
|
ErrorMsg_list.remove(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public synchronized void exit(){
|
|
|
WriteLog("软件退出");
|
|
|
}
|
|
|
|
|
|
public synchronized List<Thread> startUp() throws Exception {
|
|
|
return Main_void("1");
|
|
|
}
|
|
|
|
|
|
private List<Thread> Main_voidTest(String dbType) throws Exception {
|
|
|
try {
|
|
|
JdbcTemplate jdbcTemplate=new JdbcTemplate(new DBUtil().Hikar_DataSource());
|
|
|
String sql4_1 = "delete gantry_pass_center where ROUND(TO_NUMBER(sysdate - handletime))>25";
|
|
|
|
|
|
deleteCenter deleteC=new deleteCenter(jdbcTemplate,sql4_1,runAble,this);
|
|
|
Thread thread=new Thread(deleteC);
|
|
|
thread.start();//true
|
|
|
|
|
|
|
|
|
stop_list.add(thread);//false
|
|
|
State state=new State();
|
|
|
state.ThreadId=thread.getId();
|
|
|
state.StateUpdateTime=System.currentTimeMillis();
|
|
|
state_list.add(state);
|
|
|
|
|
|
|
|
|
for (int i = 0; i < stop_list.size(); i++) {
|
|
|
LogClass.error("线程ID:"+stop_list.get(i).getId()+"线程状态:"+stop_list.get(i).isAlive());
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
finally {
|
|
|
return stop_list;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
{
|
|
|
try {
|
|
|
jdbcTemplate = new JdbcTemplate(new DBUtil().Hikar_DataSource());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<Thread> Main_void(String dbType) throws Exception {
|
|
|
boolean flag=true;
|
|
|
//List<Thread> starup_list=new ArrayList<>();
|
|
|
stop_list.clear();
|
|
|
runAble=true;
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
List list_PARTICIPANT = CommonHelp.getListBySql("select * from TB_PARTICIPANT",jdbcTemplate);
|
|
|
|
|
|
List list_LINE_TABLE=CommonHelp.getListBySql("select LINENAME,GBLINEID from line_table",jdbcTemplate);
|
|
|
|
|
|
List list_FEEUNIT_TABLE=CommonHelp.getListBySql("select ID,NAME FROM FEEUNIT_TABLE",jdbcTemplate);
|
|
|
|
|
|
List list_GANTRY_TABLE=CommonHelp.getListBySql("select * from gantry_table",jdbcTemplate);
|
|
|
|
|
|
int GPA_THREAD_COUNT_1=7;
|
|
|
//正常数据处理线程,4个
|
|
|
|
|
|
if (dbType.equals("1")) {//oracle
|
|
|
for (int i = 0; i < GPA_THREAD_COUNT_1; i++) {
|
|
|
String sql="select * from gantry_pass_center where ishandle=0 and isout=1 and issecond=0 and payfee_all=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60)>" + CommonHelp.GetConfigValue("lastTimeOut") + " and ora_hash(passid,"+(GPA_THREAD_COUNT_1-1)+")="+i;
|
|
|
Thread thread=new GetAllData((i+11),0,sql,jdbcTemplate,list_PARTICIPANT,list_LINE_TABLE,list_FEEUNIT_TABLE,list_GANTRY_TABLE,runAble,this);
|
|
|
thread.start();
|
|
|
stop_list.add(thread);
|
|
|
State state=new State();
|
|
|
state.ThreadId=thread.getId();
|
|
|
state.StateUpdateTime=System.currentTimeMillis();
|
|
|
state_list.add(state);
|
|
|
}
|
|
|
} else if (dbType.equals("2")) {//DM
|
|
|
for (int i = 0; i < GPA_THREAD_COUNT_1; i++) {
|
|
|
String sql="select * from gantry_pass_center where ishandle=0 and isout=1 and issecond=0 and payfee_all=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60)>" + CommonHelp.GetConfigValue("lastTimeOut") + " and DM_HASH(passid)%"+GPA_THREAD_COUNT_1+"="+i+" and rownum<=1500";
|
|
|
Thread thread=new GetAllData((i+11),0,sql,jdbcTemplate,list_PARTICIPANT,list_LINE_TABLE,list_FEEUNIT_TABLE,list_GANTRY_TABLE,runAble,this);
|
|
|
thread.start();
|
|
|
stop_list.add(thread);
|
|
|
State state=new State();
|
|
|
state.ThreadId=thread.getId();
|
|
|
state.StateUpdateTime=System.currentTimeMillis();
|
|
|
state_list.add(state);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//超时数据处理线程,3个
|
|
|
|
|
|
if (dbType.equals("1")) {//oracle
|
|
|
//超时第一种情况--有出口但是累计金额不相等的
|
|
|
|
|
|
//超时第二种情况--累计金额相等但是没有出口的
|
|
|
String sql2_2_1 = "select * from gantry_pass_center where ishandle=0 and isout=0 and payfee_all=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut");
|
|
|
//超时第三种情况--没有出口累计金额也不相等的
|
|
|
String sql2_3_1 = "select * from gantry_pass_center where ishandle=0 and isout=0 and payfee_all!=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut");
|
|
|
|
|
|
|
|
|
List<Map<String,Integer>> listTemp=new ArrayList<>();
|
|
|
|
|
|
for (int i = 0; i <= 6; i++) {
|
|
|
String sql2_1_1 = "select * from(select * from gantry_pass_center where ishandle=0 and isout=1 and payfee_all!=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut")+") t where ora_hash(passid,6)="+i;
|
|
|
Map map=new HashMap();
|
|
|
map.put("sql",sql2_1_1);
|
|
|
map.put("threadid",20+i+1);
|
|
|
listTemp.add(map);
|
|
|
}
|
|
|
Map map1=new HashMap();
|
|
|
map1.put("sql",sql2_2_1);
|
|
|
map1.put("threadid",28);
|
|
|
listTemp.add(map1);
|
|
|
|
|
|
Map map2=new HashMap();
|
|
|
map2.put("sql",sql2_3_1);
|
|
|
map2.put("threadid",29);
|
|
|
listTemp.add(map2);
|
|
|
|
|
|
for (int i = 0; i < listTemp.size(); i++) {
|
|
|
Map map=listTemp.get(i);
|
|
|
Thread thread=new GetAllData(21+i,1,map.get("sql").toString(),jdbcTemplate,list_PARTICIPANT,list_LINE_TABLE,list_FEEUNIT_TABLE,list_GANTRY_TABLE,runAble,this);
|
|
|
thread.start();
|
|
|
stop_list.add(thread);
|
|
|
startGPA.State state=new startGPA.State();
|
|
|
state.ThreadId=thread.getId();
|
|
|
state.StateUpdateTime=System.currentTimeMillis();
|
|
|
state_list.add(state);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //超时第一种情况--有出口但是累计金额不相等的
|
|
|
// String sql2_1_1 = "select * from gantry_pass_center where ishandle=0 and isout=1 and payfee_all!=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut");
|
|
|
// //超时第二种情况--累计金额相等但是没有出口的
|
|
|
// String sql2_2_1 = "select * from gantry_pass_center where ishandle=0 and isout=0 and payfee_all=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut");
|
|
|
// //超时第三种情况--没有出口累计金额也不相等的
|
|
|
// String sql2_3_1 = "select * from gantry_pass_center where ishandle=0 and isout=0 and payfee_all!=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut");
|
|
|
//
|
|
|
// List<String> listTemp=new ArrayList<>();
|
|
|
// listTemp.add(sql2_1_1);
|
|
|
// listTemp.add(sql2_2_1);
|
|
|
// listTemp.add(sql2_3_1);
|
|
|
//
|
|
|
// for (int i = 0; i < listTemp.size(); i++) {
|
|
|
//
|
|
|
// Thread thread=new GetAllData((21+i),1,listTemp.get(i).toString(),jdbcTemplate,list_PARTICIPANT,list_LINE_TABLE,list_FEEUNIT_TABLE,list_GANTRY_TABLE,runAble,this);
|
|
|
// thread.start();
|
|
|
// stop_list.add(thread);
|
|
|
// State state=new State();
|
|
|
// state.ThreadId=thread.getId();
|
|
|
// state.StateUpdateTime=System.currentTimeMillis();
|
|
|
// state_list.add(state);
|
|
|
// }
|
|
|
|
|
|
|
|
|
} else if (dbType.equals("2")) {//DM
|
|
|
|
|
|
//超时第一种情况--有出口但是累计金额不相等的技巧口诀图解
|
|
|
String sql2_1_1 = "select PASSID,OUT_TRADEID,PAYFEE_ALL,FEE_ALL,OBUPROVPAYFEESUMAFTER,TRANSTIME,TRADEID,ISOUT,DISCOUNTFEE_ALL,OUT_GANTRYID,ISHANDLE,ID,FEEPROVBEGINHEX,FEEPROVBEGINTIME,HANDLETIME,EXPOINTID,EXPOINTNAME,MEDIATYPE,ISTIMEOUT,ISSECOND,UPDATETIME,ENTIME,TRANSNUM,PROVINCENUMAFTER,BACKUP3 from gantry_pass_center where ishandle=0 and isout=1 and payfee_all!=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut")+" and rownum<=1500";
|
|
|
//超时第二种情况--累计金额相等但是没有出口的
|
|
|
String sql2_2_1 = "select PASSID,OUT_TRADEID,PAYFEE_ALL,FEE_ALL,OBUPROVPAYFEESUMAFTER,TRANSTIME,TRADEID,ISOUT,DISCOUNTFEE_ALL,OUT_GANTRYID,ISHANDLE,ID,FEEPROVBEGINHEX,FEEPROVBEGINTIME,HANDLETIME,EXPOINTID,EXPOINTNAME,MEDIATYPE,ISTIMEOUT,ISSECOND,UPDATETIME,ENTIME,TRANSNUM,PROVINCENUMAFTER,BACKUP3 from gantry_pass_center where ishandle=0 and isout=0 and payfee_all=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut")+" and rownum<=1500";
|
|
|
//超时第三种情况--没有出口累计金额也不相等的
|
|
|
String sql2_3_1 = "select PASSID,OUT_TRADEID,PAYFEE_ALL,FEE_ALL,OBUPROVPAYFEESUMAFTER,TRANSTIME,TRADEID,ISOUT,DISCOUNTFEE_ALL,OUT_GANTRYID,ISHANDLE,ID,FEEPROVBEGINHEX,FEEPROVBEGINTIME,HANDLETIME,EXPOINTID,EXPOINTNAME,MEDIATYPE,ISTIMEOUT,ISSECOND,UPDATETIME,ENTIME,TRANSNUM,PROVINCENUMAFTER,BACKUP3 from gantry_pass_center where ishandle=0 and isout=0 and payfee_all!=obuprovpayfeesumafter and ROUND(TO_NUMBER(sysdate - transtime) * 24 * 60)>" + CommonHelp.GetConfigValue("timeOut") + " and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60) > " + CommonHelp.GetConfigValue("lastTimeOut")+" and rownum<=1500";
|
|
|
|
|
|
List<String> listTemp=new ArrayList<>();
|
|
|
listTemp.add(sql2_1_1);
|
|
|
listTemp.add(sql2_2_1);
|
|
|
listTemp.add(sql2_3_1);
|
|
|
|
|
|
for (int i = 0; i < listTemp.size(); i++) {
|
|
|
Thread thread=new GetAllData((21+i),1,listTemp.get(i).toString(),jdbcTemplate,list_PARTICIPANT,list_LINE_TABLE,list_FEEUNIT_TABLE,list_GANTRY_TABLE,runAble,this);
|
|
|
thread.start();
|
|
|
stop_list.add(thread);
|
|
|
State state=new State();
|
|
|
state.ThreadId=thread.getId();
|
|
|
state.StateUpdateTime=System.currentTimeMillis();
|
|
|
state_list.add(state);
|
|
|
}
|
|
|
}
|
|
|
//二次数据上传处理线程,1个
|
|
|
String sql3_1 = "";
|
|
|
if (dbType.equals("1")) {//oracle
|
|
|
sql3_1 = "select * from gantry_pass_center where ishandle=1 and issecond=1 and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60)>" + CommonHelp.GetConfigValue("lastTimeOut");
|
|
|
|
|
|
Thread thread3_1=new GetAllData(31,0,sql3_1,jdbcTemplate,list_PARTICIPANT,list_LINE_TABLE,list_FEEUNIT_TABLE,list_GANTRY_TABLE,runAble,this);
|
|
|
thread3_1.start();
|
|
|
|
|
|
stop_list.add(thread3_1);
|
|
|
State state3_1=new State();
|
|
|
state3_1.ThreadId=thread3_1.getId();
|
|
|
state3_1.StateUpdateTime=System.currentTimeMillis();
|
|
|
state_list.add(state3_1);
|
|
|
} else if (dbType.equals("2")) {//DM
|
|
|
sql3_1 = "select * from gantry_pass_center where ishandle=1 and issecond=1 and ROUND(TO_NUMBER(sysdate - updatetime) * 24 * 60)>" + CommonHelp.GetConfigValue("lastTimeOut");
|
|
|
|
|
|
Thread thread3_1= new GetAllData(31,0,sql3_1,jdbcTemplate,list_PARTICIPANT,list_LINE_TABLE,list_FEEUNIT_TABLE,list_GANTRY_TABLE,runAble,this);
|
|
|
thread3_1.start();
|
|
|
}
|
|
|
//删除中间表数据线程,1个
|
|
|
if (dbType.equals("1")) {
|
|
|
String sql4_1 = "delete gantry_pass_center where ROUND(TO_NUMBER(sysdate - handletime))>25";
|
|
|
deleteCenter deleteC=new deleteCenter(jdbcTemplate,sql4_1,runAble,this);
|
|
|
Thread thread=new Thread(deleteC);
|
|
|
thread.start();
|
|
|
// stop_list.add(thread);
|
|
|
// State state=new State();
|
|
|
// state.ThreadId=thread.getId();
|
|
|
// state.StateUpdateTime=System.currentTimeMillis();
|
|
|
// state_list.add(state);
|
|
|
}
|
|
|
//预分账线程,7个
|
|
|
int THREAD_GANTRY_STAT_COUNT=7;
|
|
|
for (int i = 0; i < THREAD_GANTRY_STAT_COUNT; i++) {
|
|
|
String sql="select * from gantry_pass_stat_temp where ora_hash(tradeid,"+(THREAD_GANTRY_STAT_COUNT-1)+")="+i+" and rownum<=1000";
|
|
|
GetGantryStat getGantryStat=new GetGantryStat(jdbcTemplate,sql,runAble,this);
|
|
|
Thread thread=new Thread(getGantryStat);
|
|
|
thread.start();
|
|
|
stop_list.add(thread);
|
|
|
State state=new State();
|
|
|
state.ThreadId=thread.getId();
|
|
|
state.StateUpdateTime=System.currentTimeMillis();
|
|
|
state_list.add(state);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
catch (Exception e){
|
|
|
flag=false;
|
|
|
e.printStackTrace();
|
|
|
LogClass.debug(e.toString());
|
|
|
}
|
|
|
finally {
|
|
|
return stop_list;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|