Commit a4f62104 by Kazuyuki Hida

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

parent 0474d906
......@@ -20,7 +20,7 @@ public class LockReportLogic extends AbstractLogic {
return new LockReportLogic();
}
public LockResult lock(Map<String, String> param) {
public Result lock(Map<String, String> param) {
return sendLockReport(
param.get("taskKey"),
longOrNull(param.get("taskReportId")),
......@@ -28,7 +28,7 @@ public class LockReportLogic extends AbstractLogic {
);
}
private LockResult sendLockReport(
private Result sendLockReport(
String taskKey,
Long taskReportId,
Date reportStartDate
......@@ -46,14 +46,14 @@ public class LockReportLogic extends AbstractLogic {
if (!networkAdapter.isNetworkConnected()) {
// オフラインだったら、ロック成功扱い
return LockResult.offLine();
return Result.offLine();
}
try {
LockReportJSON reportJSON = client.sendLockReport(param);
return LockResult.succsess(reportJSON);
return Result.succsess(reportJSON);
} catch (Throwable e) {
return LockResult.failure(e);
return Result.failure(e);
}
}
......@@ -76,56 +76,40 @@ public class LockReportLogic extends AbstractLogic {
}
// コールバック用のパラメータ
public static class LockResult {
public static class Result {
int result;
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.message = "";
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", reportJSON.getReportStatus());
extParam.put("reportLockUserId", reportJSON.getReportLockUserId());
extParam.put("reportLockUserName", reportJSON.getReportLockUserName());
extParam.put("reportLockTime", reportJSON.getReportLockTime());
result.extParam = extParam.toString();
result.extParam = new ExtParam(
reportJSON.getReportStatus(),
reportJSON.getReportLockUserId(),
reportJSON.getReportLockUserName(),
reportJSON.getReportLockTime()
);
return result;
}
static LockResult failure(Throwable e) {
static Result failure(Throwable e) {
// 例外がでたとき
LockResult result = new LockResult();
Result result = new Result();
result.result = 1;
result.message = e.getLocalizedMessage();
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();
result.extParam = new ExtParam(999, null, null, null);
return result;
}
static LockResult offLine() {
static Result offLine() {
// オフラインは成功扱い
LockResult result = new LockResult();
Result result = new Result();
result.result = 0;
result.message = "";
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();
result.extParam = new ExtParam(3, null, null, null);
return result;
}
......@@ -137,8 +121,53 @@ public class LockReportLogic extends AbstractLogic {
return message;
}
public String getExtParam() {
public ExtParam getExtParam() {
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 {
public static class Result {
int result;
String message;
String extParam;
ExtParam extParam;
static Result succsess(UnlockReportJSON reportJSON) {
// 成功したとき
Result result = new Result();
result.result = reportJSON.httpStatus == HTTP_OK ? 0 : 1;
result.message = "";
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", reportJSON.getReportStatus());
result.extParam = extParam.toString();
result.extParam = new ExtParam(reportJSON.getReportStatus());
return result;
}
......@@ -96,11 +92,7 @@ public class UnlockReportLogic extends AbstractLogic {
Result result = new Result();
result.result = 1;
result.message = e.getLocalizedMessage();
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "999");
result.extParam = extParam.toString();
result.extParam = new ExtParam(999);
return result;
}
......@@ -109,11 +101,7 @@ public class UnlockReportLogic extends AbstractLogic {
Result result = new Result();
result.result = 0;
result.message = "";
JSONObject extParam = new JSONObject();
extParam.put("reportStatus", "3"); // オフラインはstatus 3
result.extParam = extParam.toString();
result.extParam = new ExtParam(3);
return result;
}
......@@ -125,8 +113,26 @@ public class UnlockReportLogic extends AbstractLogic {
return message;
}
public String getExtParam() {
public ExtParam getExtParam() {
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;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
......@@ -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.log.Logger;
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.dto.ContentDto;
import jp.agentec.abook.abv.bl.dto.MydataDto;
......@@ -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.NoPdfViewActivity;
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.FileUtil;
import jp.agentec.adf.util.StringUtil;
......@@ -1073,11 +1077,45 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
// 1:中心温度計 2:置くだけセンサー 3:バーコード
getDeviceInfo(abookCheckParam);
} else if (mCmd.equals(ABookKeys.CMD_LOCK_REPORT)) {
LockReportLogic.LockResult r = LockReportLogic.newInstance().lock(abookCheckParam);
afterABookCheckApi(mCmd, mTaskKey, r.getResult(), r.getMessage(), r.getExtParam());
LockReportLogic.Result r = LockReportLogic.newInstance().lock(abookCheckParam);
// ローカル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)) {
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 {
//ABVCheckContentViewActivityから処理
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