Commit a4f62104 by Kazuyuki Hida

ロックの結果をローカルのDBに反映するようにした。

parent 0474d906
...@@ -20,7 +20,7 @@ public class LockReportLogic extends AbstractLogic { ...@@ -20,7 +20,7 @@ public class LockReportLogic extends AbstractLogic {
return new LockReportLogic(); return new LockReportLogic();
} }
public LockResult lock(Map<String, String> param) { public Result lock(Map<String, String> param) {
return sendLockReport( return sendLockReport(
param.get("taskKey"), param.get("taskKey"),
longOrNull(param.get("taskReportId")), longOrNull(param.get("taskReportId")),
...@@ -28,7 +28,7 @@ public class LockReportLogic extends AbstractLogic { ...@@ -28,7 +28,7 @@ public class LockReportLogic extends AbstractLogic {
); );
} }
private LockResult sendLockReport( private Result sendLockReport(
String taskKey, String taskKey,
Long taskReportId, Long taskReportId,
Date reportStartDate Date reportStartDate
...@@ -46,14 +46,14 @@ public class LockReportLogic extends AbstractLogic { ...@@ -46,14 +46,14 @@ public class LockReportLogic extends AbstractLogic {
if (!networkAdapter.isNetworkConnected()) { if (!networkAdapter.isNetworkConnected()) {
// オフラインだったら、ロック成功扱い // オフラインだったら、ロック成功扱い
return LockResult.offLine(); return Result.offLine();
} }
try { try {
LockReportJSON reportJSON = client.sendLockReport(param); LockReportJSON reportJSON = client.sendLockReport(param);
return LockResult.succsess(reportJSON); return Result.succsess(reportJSON);
} catch (Throwable e) { } catch (Throwable e) {
return LockResult.failure(e); return Result.failure(e);
} }
} }
...@@ -76,56 +76,40 @@ public class LockReportLogic extends AbstractLogic { ...@@ -76,56 +76,40 @@ public class LockReportLogic extends AbstractLogic {
} }
// コールバック用のパラメータ // コールバック用のパラメータ
public static class LockResult { public static class Result {
int result; int result;
String message; String message;
String extParam; ExtParam extParam;
static LockResult succsess(LockReportJSON reportJSON) { static Result succsess(LockReportJSON reportJSON) {
// 成功したとき // 成功したとき
LockResult result = new LockResult(); Result result = new Result();
result.result = reportJSON.httpStatus == HTTP_OK ? 0 : 1; result.result = reportJSON.httpStatus == HTTP_OK ? 0 : 1;
result.message = ""; result.message = "";
result.extParam = new ExtParam(
JSONObject extParam = new JSONObject(); reportJSON.getReportStatus(),
extParam.put("reportStatus", reportJSON.getReportStatus()); reportJSON.getReportLockUserId(),
extParam.put("reportLockUserId", reportJSON.getReportLockUserId()); reportJSON.getReportLockUserName(),
extParam.put("reportLockUserName", reportJSON.getReportLockUserName()); reportJSON.getReportLockTime()
extParam.put("reportLockTime", reportJSON.getReportLockTime()); );
result.extParam = extParam.toString();
return result; return result;
} }
static LockResult failure(Throwable e) { static Result failure(Throwable e) {
// 例外がでたとき // 例外がでたとき
LockResult result = new LockResult(); Result result = new Result();
result.result = 1; result.result = 1;
result.message = e.getLocalizedMessage(); result.message = e.getLocalizedMessage();
result.extParam = new ExtParam(999, null, null, null);
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "999");
extParam.put("reportLockUserId", (String)null);
extParam.put("reportLockUserName", (String)null);
extParam.put("reportLockTime", (String)null);
result.extParam = extParam.toString();
return result; return result;
} }
static LockResult offLine() { static Result offLine() {
// オフラインは成功扱い // オフラインは成功扱い
LockResult result = new LockResult(); Result result = new Result();
result.result = 0; result.result = 0;
result.message = ""; result.message = "";
result.extParam = new ExtParam(3, null, null, null);
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "3"); // オフラインはstatus 3
extParam.put("reportLockUserId", (String)null);
extParam.put("reportLockUserName", (String)null);
extParam.put("reportLockTime", (String)null);
result.extParam = extParam.toString();
return result; return result;
} }
...@@ -137,8 +121,53 @@ public class LockReportLogic extends AbstractLogic { ...@@ -137,8 +121,53 @@ public class LockReportLogic extends AbstractLogic {
return message; return message;
} }
public String getExtParam() { public ExtParam getExtParam() {
return extParam; return extParam;
} }
} }
static public class ExtParam {
int reportStatus;
String reportLockUserId;
String reportLockUserName;
Date reportLockTime;
ExtParam(
int reportStatus,
String reportLockUserId,
String reportLockUserName,
Date reportLockTime
) {
this.reportStatus = reportStatus;
this.reportLockUserId = reportLockUserId;
this.reportLockUserName = reportLockUserName;
this.reportLockTime = reportLockTime;
}
public int getReportStatus() {
return reportStatus;
}
public String getReportLockUserId() {
return reportLockUserId;
}
public String getReportLockUserName() {
return reportLockUserName;
}
public Date getReportLockTime() {
return reportLockTime;
}
public String json() {
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", String.valueOf(reportStatus));
extParam.put("reportLockUserId", reportLockUserId);
extParam.put("reportLockUserName", reportLockUserName);
extParam.put("reportLockTime", reportLockTime);
return extParam.toString();
}
}
} }
...@@ -76,18 +76,14 @@ public class UnlockReportLogic extends AbstractLogic { ...@@ -76,18 +76,14 @@ public class UnlockReportLogic extends AbstractLogic {
public static class Result { public static class Result {
int result; int result;
String message; String message;
String extParam; ExtParam extParam;
static Result succsess(UnlockReportJSON reportJSON) { static Result succsess(UnlockReportJSON reportJSON) {
// 成功したとき // 成功したとき
Result result = new Result(); Result result = new Result();
result.result = reportJSON.httpStatus == HTTP_OK ? 0 : 1; result.result = reportJSON.httpStatus == HTTP_OK ? 0 : 1;
result.message = ""; result.message = "";
result.extParam = new ExtParam(reportJSON.getReportStatus());
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", reportJSON.getReportStatus());
result.extParam = extParam.toString();
return result; return result;
} }
...@@ -96,11 +92,7 @@ public class UnlockReportLogic extends AbstractLogic { ...@@ -96,11 +92,7 @@ public class UnlockReportLogic extends AbstractLogic {
Result result = new Result(); Result result = new Result();
result.result = 1; result.result = 1;
result.message = e.getLocalizedMessage(); result.message = e.getLocalizedMessage();
result.extParam = new ExtParam(999);
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "999");
result.extParam = extParam.toString();
return result; return result;
} }
...@@ -109,11 +101,7 @@ public class UnlockReportLogic extends AbstractLogic { ...@@ -109,11 +101,7 @@ public class UnlockReportLogic extends AbstractLogic {
Result result = new Result(); Result result = new Result();
result.result = 0; result.result = 0;
result.message = ""; result.message = "";
result.extParam = new ExtParam(3);
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "3"); // オフラインはstatus 3
result.extParam = extParam.toString();
return result; return result;
} }
...@@ -125,8 +113,26 @@ public class UnlockReportLogic extends AbstractLogic { ...@@ -125,8 +113,26 @@ public class UnlockReportLogic extends AbstractLogic {
return message; return message;
} }
public String getExtParam() { public ExtParam getExtParam() {
return extParam; return extParam;
} }
} }
public static class ExtParam {
int reportStatus ;
ExtParam(int reportStatus) {
this.reportStatus = reportStatus;
}
public int getReportStatus() {
return reportStatus;
}
public String json() {
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", String.valueOf(reportStatus));
return extParam.toString();
}
}
} }
...@@ -29,6 +29,7 @@ import org.json.adf.JSONObject; ...@@ -29,6 +29,7 @@ import org.json.adf.JSONObject;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -43,6 +44,8 @@ import jp.agentec.abook.abv.bl.common.Constant; ...@@ -43,6 +44,8 @@ import jp.agentec.abook.abv.bl.common.Constant;
import jp.agentec.abook.abv.bl.common.constant.ABookKeys; import jp.agentec.abook.abv.bl.common.constant.ABookKeys;
import jp.agentec.abook.abv.bl.common.log.Logger; import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.data.ABVDataCache; import jp.agentec.abook.abv.bl.data.ABVDataCache;
import jp.agentec.abook.abv.bl.data.dao.AbstractDao;
import jp.agentec.abook.abv.bl.data.dao.TaskReportDao;
import jp.agentec.abook.abv.bl.download.ContentFileExtractor; import jp.agentec.abook.abv.bl.download.ContentFileExtractor;
import jp.agentec.abook.abv.bl.dto.ContentDto; import jp.agentec.abook.abv.bl.dto.ContentDto;
import jp.agentec.abook.abv.bl.dto.MydataDto; import jp.agentec.abook.abv.bl.dto.MydataDto;
...@@ -77,6 +80,7 @@ import jp.agentec.abook.abv.ui.home.helper.ActivityHandlingHelper; ...@@ -77,6 +80,7 @@ import jp.agentec.abook.abv.ui.home.helper.ActivityHandlingHelper;
import jp.agentec.abook.abv.ui.viewer.activity.HTMLXWalkWebViewActivity; import jp.agentec.abook.abv.ui.viewer.activity.HTMLXWalkWebViewActivity;
import jp.agentec.abook.abv.ui.viewer.activity.NoPdfViewActivity; import jp.agentec.abook.abv.ui.viewer.activity.NoPdfViewActivity;
import jp.agentec.abook.abv.ui.viewer.foxitPdf.FoxitPdfCore; import jp.agentec.abook.abv.ui.viewer.foxitPdf.FoxitPdfCore;
import jp.agentec.adf.util.DateTimeFormat;
import jp.agentec.adf.util.DateTimeUtil; 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;
...@@ -1073,11 +1077,45 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -1073,11 +1077,45 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
// 1:中心温度計 2:置くだけセンサー 3:バーコード // 1:中心温度計 2:置くだけセンサー 3:バーコード
getDeviceInfo(abookCheckParam); getDeviceInfo(abookCheckParam);
} else if (mCmd.equals(ABookKeys.CMD_LOCK_REPORT)) { } else if (mCmd.equals(ABookKeys.CMD_LOCK_REPORT)) {
LockReportLogic.LockResult r = LockReportLogic.newInstance().lock(abookCheckParam); LockReportLogic.Result r = LockReportLogic.newInstance().lock(abookCheckParam);
afterABookCheckApi(mCmd, mTaskKey, r.getResult(), r.getMessage(), r.getExtParam()); // ローカルDBに反映
TaskReportDao dao = AbstractDao.getDao(TaskReportDao.class);
dao.updateReportLock(
mTaskKey,
dateOrNull(abookCheckParam.get("reportStartDate")),
r.getExtParam().getReportStatus(),
r.getExtParam().getReportLockUserId(),
r.getExtParam().getReportLockUserName(),
r.getExtParam().getReportLockTime()
);
// JSコールバック
afterABookCheckApi(
mCmd,
mTaskKey,
r.getResult(),
r.getMessage(),
r.getExtParam().json()
);
} else if (mCmd.equals(ABookKeys.CMD_UNLOCK_REPORT)) { } else if (mCmd.equals(ABookKeys.CMD_UNLOCK_REPORT)) {
UnlockReportLogic.Result r = UnlockReportLogic.newInstance().unlock(abookCheckParam); UnlockReportLogic.Result r = UnlockReportLogic.newInstance().unlock(abookCheckParam);
afterABookCheckApi(mCmd, mTaskKey, r.getResult(), r.getMessage(), r.getExtParam()); // ローカルDBに反映
TaskReportDao dao = AbstractDao.getDao(TaskReportDao.class);
dao.updateReportLock(
mTaskKey,
dateOrNull(abookCheckParam.get("reportStartDate")),
r.getExtParam().getReportStatus(),
null,
null,
null
);
// JSコールバック
afterABookCheckApi(
mCmd,
mTaskKey,
r.getResult(),
r.getMessage(),
r.getExtParam().json()
);
} }
} }
...@@ -1330,4 +1368,11 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -1330,4 +1368,11 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
//ABVCheckContentViewActivityから処理 //ABVCheckContentViewActivityから処理
protected void getDeviceInfo(Map<String, String> abookCheckParam) {} protected void getDeviceInfo(Map<String, String> abookCheckParam) {}
}
private Date dateOrNull(String s) {
try {
return DateTimeUtil.toDate(s, "UTC", DateTimeFormat.yyyyMMdd_hyphen);
} catch (Exception e) {
return null;
}
}}
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