Commit 5887a91f by Yujin Seo

Merge branch 'feature/contract/sato/1.0.300_operation_counts' into 'contract/sato/1.0.300'

件数表示周りの不具合の修正

See merge request !271
parents fe5d22b4 f87bac92
package jp.agentec.abook.abv.bl.data.dao;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -550,4 +549,61 @@ public class OperationDao extends AbstractDao {
return sql.toString();
}
}
\ No newline at end of file
private String incrementCount(long operationId, String column) {
StringBuilder sql = new StringBuilder();
sql.append("UPDATE t_operation ");
sql.append(" SET ").append(column).append(" = (").append(column).append(" + 1)");
sql.append(" WHERE operation_id = ").append(operationId);
return sql.toString();
}
private String decrementCount(long operationId, String column) {
StringBuilder sql = new StringBuilder();
sql.append("UPDATE t_operation ");
sql.append(" SET ").append(column).append(" = (").append(column).append(" - 1)");
sql.append(" WHERE operation_id = ").append(operationId);
sql.append(" AND ").append(column).append(" > 0");
return sql.toString();
}
public void countUpCompleted(long operationId) {
beginTransaction();
try {
execSql(decrementCount(operationId, "status_not_started_count"));
execSql(incrementCount(operationId, "status_completed_count"));
commit();
} catch (Throwable e) {
rollback();
Logger.e(TAG, e);
}
}
public void countUpWorking(long operationId) {
beginTransaction();
try {
execSql(decrementCount(operationId, "status_not_started_count"));
execSql(incrementCount(operationId, "status_working_count"));
commit();
} catch (Throwable e) {
rollback();
Logger.e(TAG, e);
}
}
public void coutUpCompletedFromWorking(long operationId) {
beginTransaction();
try {
execSql(decrementCount(operationId, "status_working_count"));
execSql(incrementCount(operationId, "status_completed_count"));
commit();
} catch (Throwable e) {
rollback();
Logger.e(TAG, e);
}
}
}
......@@ -494,4 +494,40 @@ public class TaskReportDao extends AbstractDao {
public String getRoutineTaskReportAttachedFileName(String taskKey, int taskReportId, String reportStartDate) {
return rawQueryGetString("select local_attached_file_name from t_task_report where task_key=? and task_report_id=? and datetime(report_start_date)=datetime(?, 'utc')", new String[]{ taskKey, "" + taskReportId, reportStartDate });
}
public boolean isLocalSaved(String taskKey, int taskReportId, String reportStartDate) {
int count;
StringBuilder sql = new StringBuilder();
sql.append("SELECT count(*) FROM t_task_report");
sql.append(" WHERE local_saved_flg > 0");
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;
}
public boolean isCompleted(String taskKey, int taskReportId, String reportStartDate) {
int count;
StringBuilder sql = new StringBuilder();
sql.append("SELECT count(*) FROM t_task_report");
sql.append(" WHERE task_report_info_id > 0");
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;
}
}
package jp.agentec.abook.abv.bl.data.dao;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jp.agentec.abook.abv.bl.common.db.Cursor;
import jp.agentec.abook.abv.bl.dto.WorkingReportDto;
public class WorkingReportDao extends AbstractDao {
@Override
protected WorkingReportDto convert(Cursor cursor) {
return new WorkingReportDto(
getLongOrNull(cursor, "operation_id"),
getIntOrNull(cursor, "count")
);
}
private Long getLongOrNull(Cursor cursor, String name) {
int column = cursor.getColumnIndex(name);
if (column < 0) {
return null;
} else {
return cursor.getLong(column);
}
}
private Integer getIntOrNull(Cursor cursor, String name) {
int column = cursor.getColumnIndex(name);
if (column < 0) {
return null;
} else {
return cursor.getInt(column);
}
}
public Map<Long, Integer> getWorkingTaskReportCounts() {
StringBuilder sql = new StringBuilder();
sql.append(" SELECT t_operation.operation_id AS operation_id, count(*) AS count FROM t_task_report ");
sql.append(" INNER JOIN t_task ON t_task_report.task_key = t_task.task_key ");
sql.append(" INNER JOIN t_operation ON t_task.operation_id = t_operation.operation_id");
sql.append(" WHERE t_task_report.local_saved_flg > 0");
sql.append(" GROUP BY t_operation.operation_id");
List<WorkingReportDto> list = rawQueryGetDtoList(sql.toString(), null, WorkingReportDto.class);
Map<Long, Integer> map = new HashMap<Long, Integer>();
for (WorkingReportDto dto : list) {
Long id = dto.getOperationId();
Integer cnt = dto.getCount();
if (id != null && cnt != null) {
map.put(id, cnt);
}
}
return map;
}
}
package jp.agentec.abook.abv.bl.dto;
public class WorkingReportDto extends AbstractDto {
private final Long operationId;
private final Integer count;
public WorkingReportDto(Long operationId, Integer count) {
super();
this.operationId = operationId;
this.count = count;
}
@Override
public String[] getKeyValues() {
return new String[0];
}
@Override
public Object[] getInsertValues() {
return new Object[0];
}
public Long getOperationId() {
return operationId;
}
public Integer getCount() {
return count;
}
}
......@@ -47,6 +47,7 @@ import jp.agentec.abook.abv.bl.data.dao.TaskReportItemsDao;
import jp.agentec.abook.abv.bl.data.dao.TaskReportSendDao;
import jp.agentec.abook.abv.bl.data.dao.TaskWorkerGroupDao;
import jp.agentec.abook.abv.bl.data.dao.WorkerGroupDao;
import jp.agentec.abook.abv.bl.data.dao.WorkingReportDao;
import jp.agentec.abook.abv.bl.dto.CategoryContentDto;
import jp.agentec.abook.abv.bl.dto.ContentDto;
import jp.agentec.abook.abv.bl.dto.OperationContentDto;
......@@ -1186,7 +1187,23 @@ public class OperationLogic extends AbstractLogic {
* @return 作業情報配列
*/
public List<OperationDto> getRefreshOperation(String searchWord, String searchStartDateStr, String searchEndDateStr, String reportTypeStr) {
return mOperationDao.getOperations(searchWord, searchStartDateStr, searchEndDateStr, reportTypeStr);
List<OperationDto> list = mOperationDao.getOperations(searchWord, searchStartDateStr, searchEndDateStr, reportTypeStr);
WorkingReportDao dao = AbstractDao.getDao(WorkingReportDao.class);
// ローカル保存している分を補正する
Map<Long, Integer> working = dao.getWorkingTaskReportCounts();
for (OperationDto dto : list) {
Integer workingCount = working.get(dto.operationId);
if (workingCount != null) {
if (dto.reportType == 1) {
// 定期点検の場合は、先にレポートが作られるので、その分を差し引く
dto.statusNotStartedCount -= workingCount;
}
dto.statusWorkingCount += workingCount;
}
}
return list;
}
/**
......
Subproject commit 7bcb5bfc6820f6ea7f9dc94d32dc982deaced578
Subproject commit 39a8f243e91a4a70143ef6cfe7ba33807de9cdfb
......@@ -2,7 +2,6 @@ package jp.agentec.abook.abv.ui.home.activity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.EditorInfo;
......@@ -19,11 +18,12 @@ import android.widget.ProgressBar;
import org.json.adf.JSONArray;
import org.json.adf.JSONObject;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jp.agentec.abook.abv.bl.acms.type.OperationType;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
......@@ -74,7 +74,7 @@ import static jp.agentec.abook.abv.bl.common.constant.ABookKeys.CMD_UNLOCK_REPOR
public class DashboardActivity extends OperationActivity {
private static final String TAG = "DashboardActivity";
private static final String DASHBOARD_URL = "file:///android_asset/dashboard/app/index.html";
private static final String DASHBOARD_URL = "file:///android_asset/dashboard/app/index.html?app=android";
private WebView webView;
private ProgressBar progress;
......@@ -105,6 +105,16 @@ public class DashboardActivity extends OperationActivity {
}
@Override
protected void onResume() {
super.onResume();
try {
getReportStatusCount();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onStop() {
super.onStop();
if (webView != null) {
......@@ -144,6 +154,8 @@ public class DashboardActivity extends OperationActivity {
webView.setWebViewClient(new ViewClient());
webView.addJavascriptInterface(new JsInf(), "android");
webView.getSettings().setJavaScriptEnabled(true); // JavaScriptを有効にする
Logger.d(TAG, "loadUrl: " + DASHBOARD_URL);
}
......@@ -154,7 +166,7 @@ public class DashboardActivity extends OperationActivity {
settings.setLoadsImagesAutomatically(true); // イメージを自動的にロードする
settings.setBuiltInZoomControls(true); // ズーム機能を有効にする
settings.setSupportZoom(true); // ズーム機能を有効にする
settings.setJavaScriptEnabled(true); // JavaScriptを有効にする
//settings.setJavaScriptEnabled(true); // JavaScriptを有効にする
settings.setLoadWithOverviewMode(true); // 画面の横幅にページの横幅を合わせる
settings.setUseWideViewPort(true); // 画面の横幅にページの横幅を合わせる
//noinspection deprecation(API18から非推奨になった。無視)
......@@ -217,12 +229,28 @@ public class DashboardActivity extends OperationActivity {
}
@JavascriptInterface
public void getAttachedDataUrl(String taskKey, String data) {
//commonAttachedDataUrl(taskKey, data);
public String getCachePath() {
return getCacheDir().getAbsolutePath();
}
@JavascriptInterface
public void sendParam(String param) {
Logger.i(TAG, "sendParam: %s", param);
final JSONObject json = new JSONObject(param);
runOnUiThread(new Runnable() {
@Override
public void run() {
checkApiLoading(json);
}
});
}
@JavascriptInterface
public void getAttachedDataUrl(String taskKey, String data) {}
}
private class ViewClient extends WebViewClient {
private static class ViewClient extends WebViewClient {
@SuppressWarnings("deprecation")
@Override
......@@ -233,79 +261,60 @@ public class DashboardActivity extends OperationActivity {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Logger.v(TAG, "shouldOverrideUrlLoading: %s", url);
if (url.startsWith("abook")) {
final Uri uri = Uri.parse(url);
// AndroidOSが5以下のPANO_SERVER処理のため、置き換える必要がある。
url = "/" + url;
if (url.contains(ABookKeys.ABOOK_CHECK_API)) {
return checkApiLoding(uri);
}
return true;
}
return false;
}
}
private boolean checkApiLoding(Uri uri) {
Map<String, String> param = new HashMap<>();
for (String key : uri.getQueryParameterNames()) {
param.put(key, uri.getQueryParameter(key));
}
private void checkApiLoading(JSONObject json) {
String cmd = param.get(ABookKeys.CMD);
String cmd = json.getString(ABookKeys.CMD);
if (cmd == null) {
return false;
return;
}
try {
switch (cmd) {
case CMD_GET_REPORT_STATUS_COUNT: {
return getReportStatusCount();
getReportStatusCount();
break;
}
case CMD_GET_REPORT_LIST: {
String reportStatusId = param.get(ReportStatusId);
if (reportStatusId != null) {
return getReportList(Integer.parseInt(reportStatusId));
} else {
return false;
}
int reportStatusId = json.getInt(ReportStatusId);
getReportList(reportStatusId);
break;
}
case CMD_GO_REPORT_DETAIL: {
Long operationId = getLongOrNull(param.get(OperationId));
if (operationId == null) {
return true;
} else {
return goReportDetail(operationId);
}
long operationId = json.getLong(OperationId);
goReportDetail(operationId);
break;
}
case CMD_LOCK_REPORT: {
String taskKey = param.get(TaskKey);
Long taskReportId = getLongOrNull(param.get(TaskReportId));
Date reportStartDate = getDateOrNull(param.get(ReportStartDate));
return lockReport(taskKey, taskReportId, reportStartDate);
String taskKey = json.getString(TaskKey);
long taskReportId = json.getLong(TaskReportId);
Date reportStartDate = getDateOrNull(json.getString(ReportStartDate));
lockReport(taskKey, taskReportId, reportStartDate);
break;
}
case CMD_UNLOCK_REPORT: {
String taskKey = param.get(TaskKey);
Long taskReportId = getLongOrNull(param.get(TaskReportId));
Date reportStartDate = getDateOrNull(param.get(ReportStartDate));
return unlockReport(taskKey, taskReportId, reportStartDate);
String taskKey = json.getString(TaskKey);
long taskReportId = json.getLong(TaskReportId);
Date reportStartDate = getDateOrNull(json.getString(ReportStartDate));
unlockReport(taskKey, taskReportId, reportStartDate);
break;
}
}
} catch (Throwable e) {
Logger.e(TAG, e.getLocalizedMessage());
return false;
Logger.e(TAG, e);
}
return false;
}
private boolean getReportStatusCount() {
//todo
return false;
private void getReportStatusCount() throws IOException {
ReportStatusDao dao = AbstractDao.getDao(ReportStatusDao.class);
JSONObject extParam = dao.getReportStatusCountJson();
saveCounts(extParam);
}
private boolean getReportList(int reportStatusId) {
private void getReportList(int reportStatusId) {
ReportStatusDao dao = AbstractDao.getDao(ReportStatusDao.class);
List<ReportStatusDto> reports = null;
switch (reportStatusId) {
......@@ -345,9 +354,6 @@ public class DashboardActivity extends OperationActivity {
JSONObject param = makeReportTree(reportStatusId, reports);
String script = "javascript:CHK_Dashboard.reportListCallback(" + reportStatusId + "," + param.toString() + ")";
webView.loadUrl(script);
return true;
} else {
return false;
}
}
......@@ -387,9 +393,9 @@ public class DashboardActivity extends OperationActivity {
return tree;
}
private boolean goReportDetail(long operationId) {
private void goReportDetail(long operationId) {
if (ActivityHandlingHelper.getInstance().isMeetingConnected()) {
return true;
return;
}
// 新着更新を止める
contentRefresher.stopRefresh();
......@@ -434,7 +440,6 @@ public class DashboardActivity extends OperationActivity {
intent.setClass(this, HTMLXWalkWebViewActivity.class);
ActivityHandlingHelper.getInstance().startHTMLXWalkWebActivity(this, intent, "file://" + path, contentDto.contentId, -1, -1, -1, -1, -1);
}
return true;
} else {
Logger.w(TAG, "content is not download");
}
......@@ -442,11 +447,9 @@ public class DashboardActivity extends OperationActivity {
Logger.e(TAG, e);
handleErrorMessageToast(ErrorCode.E107);
}
return false;
}
private boolean lockReport(String taskKey, Long taskReportId, Date reportStartDate) {
private void lockReport(String taskKey, Long taskReportId, Date reportStartDate) {
try {
LockReportLogic.Result r = LockReportLogic.newInstance().lock(taskKey, taskReportId, reportStartDate);
// JSコールバック
......@@ -457,14 +460,12 @@ public class DashboardActivity extends OperationActivity {
r.getMessage(),
r.getExtParam().json()
);
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
private boolean unlockReport(String taskKey, Long taskReportId, Date reportStartDate) {
private void unlockReport(String taskKey, Long taskReportId, Date reportStartDate) {
try {
UnlockReportLogic.Result r = UnlockReportLogic.newInstance().unlock(taskKey, taskReportId, reportStartDate);
// JSコールバック
......@@ -475,10 +476,8 @@ public class DashboardActivity extends OperationActivity {
r.getMessage(),
r.getExtParam().json()
);
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
......@@ -494,21 +493,28 @@ public class DashboardActivity extends OperationActivity {
});
}
private Long getLongOrNull(String s) {
private Date getDateOrNull(String s) {
try {
return Long.parseLong(s);
return DateTimeUtil.toDate(s, "UTC", DateTimeFormat.yyyyMMddHHmmss_hyphen);
} catch (Exception e) {
Logger.e(TAG, e.getLocalizedMessage());
return null;
}
}
private Date getDateOrNull(String s) {
try {
return DateTimeUtil.toDate(s, "UTC", DateTimeFormat.yyyyMMddHHmmss_hyphen);
} catch (Exception e) {
Logger.e(TAG, e.getLocalizedMessage());
return null;
public String getCachePath() {
return getCacheDir().getAbsolutePath();
}
private void saveCounts(JSONObject counts) throws IOException {
File dir = new File(getCachePath());
File file = new File(dir, "getReportStatusCount.json");
try(FileWriter writer = new FileWriter(file)) {
writer.write(counts.toString());
} catch (Throwable e) {
Logger.e(TAG, e);
throw e;
}
}
}
......@@ -18,6 +18,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.Callback;
......@@ -27,6 +28,9 @@ import jp.agentec.abook.abv.bl.common.constant.ABookKeys;
import jp.agentec.abook.abv.bl.common.exception.ABVExceptionCode;
import jp.agentec.abook.abv.bl.common.exception.AcmsException;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.data.dao.AbstractDao;
import jp.agentec.abook.abv.bl.data.dao.OperationDao;
import jp.agentec.abook.abv.bl.data.dao.TaskReportDao;
import jp.agentec.abook.abv.bl.dto.OperationDto;
import jp.agentec.abook.abv.bl.dto.OperationTaskDto;
import jp.agentec.abook.abv.bl.dto.TaskDto;
......@@ -44,6 +48,8 @@ import jp.agentec.adf.util.DateTimeUtil;
import jp.agentec.adf.util.FileUtil;
import jp.agentec.adf.util.StringUtil;
import static jp.agentec.abook.abv.bl.acms.client.json.OperationDataJSON.ReportStartDate;
import static jp.agentec.abook.abv.bl.acms.client.json.OperationDataJSON.TaskReportId;
import static jp.agentec.abook.abv.cl.util.PreferenceUtil.getUserPref;
/**
......@@ -89,25 +95,51 @@ public class ABookCheckWebViewHelper extends ABookHelper {
switch (cmd) {
case ABookKeys.CMD_INSERT_TASK_REPORT:
case ABookKeys.CMD_UPDATE_TASK_REPORT:
case ABookKeys.CMD_UPDATE_TASK_REPORT: {
// もとから作業中だったかを調べる
TaskReportDao taskReportDao = AbstractDao.getDao(TaskReportDao.class);
int rportId = Integer.parseInt(String.valueOf(param.getOrDefault(TaskReportId, "0")));
String startDate = param.getOrDefault(ReportStartDate, null);
boolean isLocalSaved = taskReportDao.isLocalSaved(taskKey, rportId, startDate);
boolean isCompleted = taskReportDao.isCompleted(taskKey, rportId, startDate);
// 報告書の更新
insertOrUpdateTaskReport(taskKey, enableReportHistory, operationId, contentId, param, contentPath, reportType, taskReportLevel, false);
copyTaskAttachedMovie(operationId, contentId, taskKey, taskReportLevel);
sendTaskData(context, operationId, taskKey, taskReportLevel);
// 作業ステータスのカウントを変える
OperationDao operationDao = AbstractDao.getDao(OperationDao.class);
if (isLocalSaved) {
operationDao.coutUpCompletedFromWorking(operationId);
} else if (! isCompleted) {
operationDao.countUpCompleted(operationId);
}
break;
}
case ABookKeys.CMD_LOCAL_SAVE_TASK_REPORT: // 一時保存
// もとから作業中だったかを調べる
TaskReportDao taskReportDao = AbstractDao.getDao(TaskReportDao.class);
int rportId = Integer.parseInt(String.valueOf(param.getOrDefault(TaskReportId, "0")));
String startDate = param.getOrDefault(ReportStartDate, null);
boolean isLocalSaved = taskReportDao.isLocalSaved(taskKey, rportId, startDate);
// 報告書の更新
insertOrUpdateTaskReport(taskKey, enableReportHistory, operationId, contentId, param, contentPath, reportType, taskReportLevel, true);
copyTaskAttachedMovie(operationId, contentId, taskKey, taskReportLevel);
ABVToastUtil.showMakeText(context, R.string.msg_temp_save_result, Toast.LENGTH_SHORT);
// 作業ステータスのカウントを変える
if (! isLocalSaved) {
OperationDao operationDao = AbstractDao.getDao(OperationDao.class);
operationDao.countUpWorking(operationId);
}
mFinishCallback.callback(false);
break;
case ABookKeys.CMD_DELETE_TASK_REPORT:
case ABookKeys.CMD_DELETE_TASK_REPORT: {
int taskReportId = 0;
String reportStartDate = "";
boolean sendTaskReportDataFlg = false;
if (reportType == Constant.ReportType.RoutineTask) {
taskReportId = Integer.valueOf(param.get(ABookKeys.TASK_REPORT_ID));
reportStartDate = param.get(ABookKeys.REPORT_START_DATE).replace("T", " ");
reportStartDate = param.get(ABookKeys.REPORT_START_DATE);
mOperationLogic.deleteRoutineTaskReport(operationId, contentId, taskKey, taskReportId, reportStartDate);
mOperationLogic.createJsonForOperationContent(operationId, contentPath, true);
copyRoutineTaskReportAttachedMovie(operationId, contentId, taskKey, taskReportId, reportStartDate);
......@@ -128,6 +160,7 @@ public class ABookCheckWebViewHelper extends ABookHelper {
sendTaskData(context, operationId, taskKey, taskReportLevel);
break;
}
case ABookKeys.CMD_MOVE_HOT_SPOT:
mOperationLogic.updateTaskHotspot(taskKey, param);
mOperationLogic.createHopSpotJson(operationId, contentPath);
......
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