Commit 1eddccd8 by Kazuyuki Hida

オフライン時でも報告を保存できるようにした。件数表示などもそれに準拠するようにした。

まだ、オンライン復帰後にCMSに届ける処理ができていない。
parent b25b1fd9
...@@ -533,4 +533,22 @@ public class TaskReportDao extends AbstractDao { ...@@ -533,4 +533,22 @@ public class TaskReportDao extends AbstractDao {
} }
return count > 0; return count > 0;
} }
public boolean isWorking(String taskKey, int taskReportId, String reportStartDate) {
int count;
StringBuilder sql = new StringBuilder();
sql.append("SELECT count(*) FROM t_task_report");
sql.append(" WHERE task_status = 1 ");
if (reportStartDate == null) {
// 報告
sql.append(" AND task_key=?");
count = rawQueryGetInt(sql.toString(), new String[] { taskKey });
} else {
// 点検
sql.append(" AND task_report_id=?");
sql.append(" AND datetime(report_start_date)=datetime(?, 'utc')");
count = rawQueryGetInt(sql.toString(), new String[] { String.valueOf(taskReportId), reportStartDate });
}
return count > 0;
}
} }
...@@ -65,6 +65,7 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -65,6 +65,7 @@ import jp.agentec.adf.util.DateTimeUtil;
import jp.agentec.adf.util.FileUtil; import jp.agentec.adf.util.FileUtil;
import jp.agentec.adf.util.StringUtil; import jp.agentec.adf.util.StringUtil;
import static jp.agentec.abook.abv.bl.acms.client.json.OperationDataJSON.Task;
import static jp.agentec.abook.abv.bl.acms.client.json.OperationListJSON.OperationEndDate; import static jp.agentec.abook.abv.bl.acms.client.json.OperationListJSON.OperationEndDate;
import static jp.agentec.abook.abv.bl.acms.client.json.OperationListJSON.OperationStartDate; import static jp.agentec.abook.abv.bl.acms.client.json.OperationListJSON.OperationStartDate;
...@@ -949,7 +950,7 @@ public class OperationLogic extends AbstractLogic { ...@@ -949,7 +950,7 @@ public class OperationLogic extends AbstractLogic {
if (!routineTaskFlg) { if (!routineTaskFlg) {
String jsonText = FileUtil.readTextFile(contentPath + "/" + ABookKeys.TASK_REPORT + ".json"); String jsonText = FileUtil.readTextFile(contentPath + "/" + ABookKeys.TASK_REPORT + ".json");
JSONObject jsonObject = new JSONObject(jsonText); JSONObject jsonObject = new JSONObject(jsonText);
JSONArray taskReportJsonArray = jsonObject.getJSONArray(ABookKeys.KEY_TASK_REPORT_0); JSONArray taskReportJsonArray = jsonObject.has(ABookKeys.KEY_TASK_REPORT_0) ? jsonObject.getJSONArray(ABookKeys.KEY_TASK_REPORT_0) : new JSONArray();
for (int i = 0; i < taskReportJsonArray.length(); i++) { for (int i = 0; i < taskReportJsonArray.length(); i++) {
JSONObject taskReportJsonObject = taskReportJsonArray.getJSONObject(i); JSONObject taskReportJsonObject = taskReportJsonArray.getJSONObject(i);
String taskKey = taskReportJsonObject.getString(ABookKeys.TASK_KEY); String taskKey = taskReportJsonObject.getString(ABookKeys.TASK_KEY);
...@@ -1498,7 +1499,16 @@ public class OperationLogic extends AbstractLogic { ...@@ -1498,7 +1499,16 @@ public class OperationLogic extends AbstractLogic {
} }
throw ex; throw ex;
} catch (Exception ex) { } catch (Exception ex) {
Logger.e(TAG, ex);
if (ex instanceof NetworkDisconnectedException) {
// オフラインの場合、エラー扱いにしないで、設問の状況から、taskStatusを推測する
taskReportDto.taskStatus = recoveryTaskStatus(taskReportDto.jsonData);
taskReportDto.dataSendFlg = true;
taskReportDto.attachedFileSendFlg = true;
mTaskReportDao.update(taskReportDto);
} else {
throw ex; throw ex;
}
} finally { } finally {
if (zipFile != null) { if (zipFile != null) {
zipFile.delete(); zipFile.delete();
...@@ -1522,6 +1532,27 @@ public class OperationLogic extends AbstractLogic { ...@@ -1522,6 +1532,27 @@ public class OperationLogic extends AbstractLogic {
} }
} }
private int recoveryTaskStatus(String taskReportInfo) {
JSONObject jsonObject = new JSONObject(taskReportInfo);
JSONObject taskObject = jsonObject.getJSONObject(Task);
Iterator<String> keys = taskObject.keys();
while (keys.hasNext()) {
String key = keys.next();
if (key.startsWith("q_3_")) { // 状況入力欄
try {
int taskStatus = Integer.parseInt(taskObject.getString(key));
if (taskStatus != 0 && taskStatus != 999) {
taskStatus = 1;
}
return taskStatus;
} catch (Throwable ignored) {
return 0;
}
}
}
return 0;
}
/** /**
* 作業関連ディレクトリ削除 * 作業関連ディレクトリ削除
* *
......
...@@ -27,7 +27,7 @@ public class UnlockReportLogic extends AbstractLogic { ...@@ -27,7 +27,7 @@ public class UnlockReportLogic extends AbstractLogic {
public Result unlock(String taskKey, Long taskReportId, Date reportStartDate) { public Result unlock(String taskKey, Long taskReportId, Date reportStartDate) {
Result r = sendUnlockReport(taskKey, taskReportId, reportStartDate); Result r = sendUnlockReport(taskKey, taskReportId, reportStartDate);
if (r.result == 0) { if (r.result == 0 || r.extParam.reportStatus == 3) {
updateLocalDB(taskKey, taskReportId, reportStartDate, r.extParam.getReportStatus()); updateLocalDB(taskKey, taskReportId, reportStartDate, r.extParam.getReportStatus());
} }
return r; return r;
......
...@@ -98,21 +98,27 @@ public class ABookCheckWebViewHelper extends ABookHelper { ...@@ -98,21 +98,27 @@ public class ABookCheckWebViewHelper extends ABookHelper {
case ABookKeys.CMD_UPDATE_TASK_REPORT: { case ABookKeys.CMD_UPDATE_TASK_REPORT: {
// もとから作業中だったかを調べる // もとから作業中だったかを調べる
TaskReportDao taskReportDao = AbstractDao.getDao(TaskReportDao.class); TaskReportDao taskReportDao = AbstractDao.getDao(TaskReportDao.class);
int rportId = Integer.parseInt(String.valueOf(param.getOrDefault(TaskReportId, "0"))); int reportId = Integer.parseInt(String.valueOf(param.getOrDefault(TaskReportId, "0")));
String startDate = param.getOrDefault(ReportStartDate, null); String startDate = param.getOrDefault(ReportStartDate, null);
boolean isLocalSaved = taskReportDao.isLocalSaved(taskKey, rportId, startDate); boolean isLocalSaved = taskReportDao.isLocalSaved(taskKey, reportId, startDate);
boolean isCompleted = taskReportDao.isCompleted(taskKey, rportId, startDate); boolean isCompleted = taskReportDao.isCompleted(taskKey, reportId, startDate);
boolean isWorking = taskReportDao.isWorking(taskKey, reportId, startDate);
// 報告書の更新 // 報告書の更新
insertOrUpdateTaskReport(taskKey, enableReportHistory, operationId, contentId, param, contentPath, reportType, taskReportLevel, false); insertOrUpdateTaskReport(taskKey, enableReportHistory, operationId, contentId, param, contentPath, reportType, taskReportLevel, false);
copyTaskAttachedMovie(operationId, contentId, taskKey, taskReportLevel); copyTaskAttachedMovie(operationId, contentId, taskKey, taskReportLevel);
sendTaskData(context, operationId, taskKey, taskReportLevel); sendTaskData(context, operationId, taskKey, taskReportLevel);
// 作業ステータスのカウントを変える // 作業ステータスのカウントを変える todo:要リファクタリング
OperationDao operationDao = AbstractDao.getDao(OperationDao.class); OperationDao operationDao = AbstractDao.getDao(OperationDao.class);
if (isLocalSaved) { if (isLocalSaved) {
operationDao.coutUpCompletedFromWorking(operationId); operationDao.coutUpCompletedFromWorking(operationId);
} else if (! isCompleted) { } else if (! isCompleted) {
boolean nowWorking = taskReportDao.isWorking(taskKey, reportId, startDate);
if (!isWorking && nowWorking) {
operationDao.countUpWorking(operationId);
} else {
operationDao.countUpCompleted(operationId); operationDao.countUpCompleted(operationId);
} }
}
break; break;
} }
case ABookKeys.CMD_LOCAL_SAVE_TASK_REPORT: // 一時保存 case ABookKeys.CMD_LOCAL_SAVE_TASK_REPORT: // 一時保存
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment