package com.smartdot.cgt.activity; import java.util.Date; import java.util.List; import java.util.Map; import android.content.DialogInterface; import android.content.Intent; import android.os.Message; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import com.smartdot.cgt.R; import com.smartdot.cgt.model.CaseModel; import com.smartdot.cgt.model.ResponseResult; import com.smartdot.cgt.request.Request; import com.smartdot.cgt.util.ApplicationMain; import com.smartdot.cgt.util.BaseThread; import com.smartdot.cgt.util.ChineseCalendar; import com.smartdot.cgt.util.HandlerStatus; import com.smartdot.cgt.util.LoginVo; import com.smartdot.cgt.util.Msg; import com.smartdot.cgt.util.MsgCallback; import com.smartdot.cgt.util.PerformanceUtil; import com.smartdot.cgt.util.PollingService; import com.smartdot.cgt.util.PollingUtils; import com.smartdot.cgt.view.TitleBar; public class FrmTakeOff extends BaseActivity { private Button btnExit; private Button btnTakeOff; private TextView txtDate; private TextView txtWeather; private TextView txtHour; private TextView txtMinute; private View layoutToUpdate; private TextView txtFinishedTask; private TextView txtInputCount; private TextView txtCheckCount; private TextView txtReCheckCount; private TextView txtToFinishedTask; private TextView txtTaskCount; private BaseThread thread; private BaseThread requestThread; private BaseThread threadTakeOff; /** * 核实无效 */ private final String CASE_STATE_1 = "核实无效"; /** * 核实有效 */ private final String CASE_STATE_2 = "核实有效"; /** * 已报送 */ private final String CASE_STATE_3 = "已报送"; /** * 已核查不通过 */ private final String CASE_STATE_4 = "已核查不通过"; /** * 已核查通过 */ private final String CASE_STATE_5 = "已核查通过"; /** * 剩余任务 */ private final String CASE_STATE_6 = "剩余任务"; private boolean mThreadStart = false; private String[] dayArr = new String[] { "日", "一", "二", "三", "四", "五", "六" }; @Override protected void addEventListener() { btnExit.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Msg.confirm(FrmTakeOff.this, "确认退出本系统?", "提示", new MsgCallback() { @Override public void callBack(Boolean result) { if (result.booleanValue()) { finishAllActivity(); Intent intent = new Intent(FrmTakeOff.this, FrmLogin.class); startActivity(intent); } } }); } }); btnTakeOff.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Msg.confirm(FrmTakeOff.this, "确认退出本系统?", "提示", new MsgCallback() { @Override public void callBack(Boolean result) { if (result.booleanValue()) { takeOffAndExit(); } } }); } }); } @SuppressWarnings("unchecked") @Override protected void handleMessage(Message msg) { if (msg.what == HandlerStatus.INVOKE_UIUPDATE && msg.arg1 == HandlerStatus.HANDLE_OK) { String[] dateStringList = (String[]) msg.obj; txtDate.setText(dateStringList[0]); txtHour.setText(dateStringList[1]); txtMinute.setText(dateStringList[2]); txtWeather.setText("2℃-13℃\n多云转晴\n微风"); layoutToUpdate.postInvalidate(); } else if (msg.what == HandlerStatus.REQUEST_LOGOUT) { if (msg.arg1 == HandlerStatus.HANDLE_OK) { finishAllActivity(); } else if (msg.arg1 == HandlerStatus.HANDLE_ERROR) { Msg.showInfo(FrmTakeOff.this, "退出登录过程中出现错误!"); } else { Msg.showInfo(FrmTakeOff.this, "退出登录失败!"); } closeProgress(); } else if (msg.what == HandlerStatus.REQUEST_TODAY_TASK) { if (msg.arg1 == HandlerStatus.HANDLE_OK) { Map < String, Integer > resultObj = (Map < String, Integer >) msg.obj; int problemInputCount = resultObj.containsKey(CASE_STATE_3) ? resultObj.get(CASE_STATE_3).intValue() : 0; int problemCheckOKCount = resultObj.containsKey(CASE_STATE_2) ? problemCheckOKCount = resultObj.get( CASE_STATE_2).intValue() : 0; int problemCheckFailCount = resultObj.containsKey(CASE_STATE_1) ? resultObj.get(CASE_STATE_1) .intValue() : 0; int problemReCheckOKCount = resultObj.containsKey(CASE_STATE_5) ? resultObj.get(CASE_STATE_5) .intValue() : 0; int problemReCheckFailCount = resultObj.containsKey(CASE_STATE_4) ? resultObj.get(CASE_STATE_4) .intValue() : 0; int taskToDoCount = resultObj.containsKey(CASE_STATE_6) ? resultObj.get(CASE_STATE_6).intValue() : 0; int finishedCount = 0, toFinishCount = 0; if (problemInputCount > 0) { finishedCount++; txtInputCount.setText("今日上报工单" + problemInputCount + "个"); } if (problemCheckOKCount + problemCheckFailCount > 0) { finishedCount++; txtCheckCount.setText("今日核实工单" + (problemCheckOKCount + problemCheckFailCount) + "个"); } if (problemReCheckOKCount + problemReCheckFailCount > 0) { finishedCount++; txtReCheckCount.setText("今日核查工单" + (problemReCheckOKCount + problemReCheckFailCount) + "个"); } if (taskToDoCount > 0) { toFinishCount++; txtTaskCount.setText("尚有" + taskToDoCount + "个工单未处理"); } txtFinishedTask.setText(finishedCount + "个"); txtToFinishedTask.setText(taskToDoCount + "个"); } else if (msg.arg1 == HandlerStatus.HANDLE_ERROR) { Msg.showInfo(FrmTakeOff.this, "获取任务信息出现错误!"); } else { Msg.showInfo(FrmTakeOff.this, "获取任务信息失败!"); } } } @Override protected void onCancelProgress(DialogInterface arg0) { if (threadTakeOff != null) { threadTakeOff.interrupt(); } } @Override protected void setLayout() { initActivity(); setContentView(R.layout.takeoff); btnTakeOff = (Button) findViewById(R.id.btnTakeOff); btnExit = (Button) findViewById(R.id.btnExit); txtDate = (TextView) findViewById(R.id.txtDate); txtWeather = (TextView) findViewById(R.id.txtWeather); txtHour = (TextView) findViewById(R.id.txtHour); txtMinute = (TextView) findViewById(R.id.txtMinute); layoutToUpdate = findViewById(R.id.layoutToUpdate); txtFinishedTask = (TextView) findViewById(R.id.txtFinishedTask); txtInputCount = (TextView) findViewById(R.id.txtInputCount); txtCheckCount = (TextView) findViewById(R.id.txtCheckCount); txtReCheckCount = (TextView) findViewById(R.id.txtReCheckCount); txtToFinishedTask = (TextView) findViewById(R.id.txtToFinishedTask); txtTaskCount = (TextView) findViewById(R.id.txtTaskCount); TitleBar titlebar = (TitleBar) this.findViewById(R.id.titlebar); titlebar.setTitleText(R.string.module_takeoff); } @Override protected void doInit() { startTimeWeatherUpdate(); getTodayFinish(); } @Override protected void doDestroy() { mThreadStart = false; thread.interrupt(); } private void getTodayFinish() { requestThread = new BaseThread(baseHandler) { @Override public void runThread() { Message msg = requestThread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.REQUEST_TODAY_TASK; try { String userId=""; if(ApplicationMain.getInstance()!=null&&ApplicationMain.getInstance().getUserModel()!=null&&ApplicationMain.getInstance().getUserModel().getBgAdminId()!=null) { userId=ApplicationMain.getInstance().getUserModel().getBgAdminId(); }else{ LoginVo vo= PerformanceUtil.getUser(FrmTakeOff.this); userId=vo.getBgadminid(); } ResponseResult < Map < String, Integer >> result = Request.getRequest().getTodayFinish( userId); if (result.isSuccess()) { ResponseResult < List < CaseModel >> taskListResult = Request.getRequest() .getTaskCountAndTop(userId); ResponseResult < List < CaseModel >> taskListResult2 = Request.getRequest() .getTaskCountAndTop2(userId); if (taskListResult.isSuccess()) { Map < String, Integer > messageResult = result.getResultObj(); messageResult.put(CASE_STATE_6, taskListResult.getAllCount()+taskListResult2.getAllCount()); msg.arg1 = HandlerStatus.HANDLE_OK; msg.obj = messageResult; } } else if (result.isHadError()) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } else { msg.arg1 = HandlerStatus.HANDLE_FAIL; } } catch (Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } requestThread.sendMessage(msg); } } }; requestThread.start(); } private void startTimeWeatherUpdate() { mThreadStart = true; thread = new BaseThread(baseHandler) { @Override public void runThread() { while (mThreadStart) { Message msg = thread.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.INVOKE_UIUPDATE; msg.arg1 = HandlerStatus.HANDLE_OK; Date d = new Date(); String lundarDateString = ChineseCalendar.sCalendarSolarToLundarDateString(d.getYear() + 1900, d.getMonth() + 1, d.getDate()); String dateString = "" + (d.getYear() + 1900) + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日\n星期" + dayArr[d.getDay()] + " " + lundarDateString; String hours = ApplicationMain.getInstance().getTwoNumber(d.getHours()); String minutes = ApplicationMain.getInstance().getTwoNumber(d.getMinutes()); msg.obj = new String[] { dateString, hours, minutes }; thread.sendMessage(msg); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } } } } }; thread.start(); } private void takeOffAndExit() { threadTakeOff = new BaseThread(baseHandler) { @Override public void runThread() { Message msg = threadTakeOff.obtainMessage(); if (msg != null) { msg.what = HandlerStatus.REQUEST_LOGOUT; try { String userId=""; if(ApplicationMain.getInstance()!=null&&ApplicationMain.getInstance().getUserModel()!=null&&ApplicationMain.getInstance().getUserModel().getBgAdminId()!=null) { userId=ApplicationMain.getInstance().getUserModel().getBgAdminId(); }else{ userId= PerformanceUtil.getUser(FrmTakeOff.this).getBgadminid(); } ResponseResult < String > result = Request.getRequest().logout( userId); if (result.isSuccess()) { msg.arg1 = HandlerStatus.HANDLE_OK; } else if (result.isHadError()) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } else { msg.arg1 = HandlerStatus.HANDLE_FAIL; } } catch (Exception e) { msg.arg1 = HandlerStatus.HANDLE_ERROR; } threadTakeOff.sendMessage(msg); } } }; PollingUtils.stopPollingService(this, PollingService.class, PollingService.ACTION); showProgress("退出登录中。。。", ""); threadTakeOff.start(); } }