completed decode procedure framework

This commit is contained in:
strawmanbobi
2019-01-07 22:34:31 +08:00
parent 105bdecb02
commit 9b36d9e715
3 changed files with 43 additions and 14 deletions

View File

@@ -1,12 +1,15 @@
package net.irext.decoder.businesslogic; package net.irext.decoder.businesslogic;
import net.irext.decoder.alioss.OSSHelper; import net.irext.decoder.alioss.OSSHelper;
import net.irext.decoder.cache.IDecodeSessionRepository;
import net.irext.decoder.model.IRBinary; import net.irext.decoder.model.IRBinary;
import net.irext.decoder.model.RemoteIndex; import net.irext.decoder.model.RemoteIndex;
import net.irext.decoder.cache.IIRBinaryRepository; import net.irext.decoder.cache.IIRBinaryRepository;
import net.irext.decoder.utils.FileUtil; import net.irext.decoder.utils.FileUtil;
import net.irext.decoder.utils.LoggerUtil; import net.irext.decoder.utils.LoggerUtil;
import net.irext.decoder.utils.MD5Util; import net.irext.decoder.utils.MD5Util;
import net.irext.decodesdk.IRDecode;
import net.irext.decodesdk.bean.ACStatus;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@@ -90,10 +93,31 @@ public class DecodeLogic {
return null; return null;
} }
public int[] decode() { public int[] decode(IIRBinaryRepository irBinaryRepository, IDecodeSessionRepository decodeSessionRepository,
String sessionId, int remoteIndexId, ACStatus acStatus, int keyCode, int changeWindDirection) {
// since the binary is already opened and probably cached to redis, we just need to load it
Integer cachedRemoteIndexId = decodeSessionRepository.find(sessionId);
int []decoded = null;
if (null != cachedRemoteIndexId) {
byte[] remoteBinary = irBinaryRepository.find(cachedRemoteIndexId);
IRDecode irDecode = IRDecode.getInstance();
int ret = 0;
// int ret = irDecode.openBinary(categoryId, subCate, binaryContent, binaryContent.length);
if (0 == ret) {
decoded = irDecode.decodeBinary(keyCode, acStatus, changeWindDirection);
}
irDecode.closeBinary();
return decoded;
} else {
LoggerUtil.getInstance().trace(TAG, "session cache missed, need to re-open binary");
}
return null; return null;
} }
public void close(IDecodeSessionRepository decodeSessionRepository, String sessionId) {
decodeSessionRepository.delete(sessionId);
}
// helper methods // helper methods
private FileInputStream getFile(File binFile, String downloadPath, String fileName, String checksum) { private FileInputStream getFile(File binFile, String downloadPath, String fileName, String checksum) {
try { try {

View File

@@ -12,22 +12,21 @@ package net.irext.decoder.request;
*/ */
public class CloseRequest { public class CloseRequest {
private int indexId; private String sessionId;
public CloseRequest(int indexId) { public CloseRequest(String sessionId) {
this.indexId = indexId; this.sessionId = sessionId;
} }
public CloseRequest() { public CloseRequest() {
} }
public int getIndexId() { public String getSessionId() {
return indexId; return sessionId;
} }
public void setIndexId(int indexId) { public void setSessionId(String sessionId) {
this.indexId = indexId; this.sessionId = sessionId;
} }
} }

View File

@@ -102,13 +102,20 @@ public class IRDecodeService extends AbstractBaseService {
public DecodeResponse irDecode(@RequestBody DecodeRequest decodeRequest) { public DecodeResponse irDecode(@RequestBody DecodeRequest decodeRequest) {
try { try {
int indexId = decodeRequest.getIndexId(); int indexId = decodeRequest.getIndexId();
ACStatus acstatus = decodeRequest.getAcStatus(); ACStatus acStatus = decodeRequest.getAcStatus();
int keyCode = decodeRequest.getKeyCode(); int keyCode = decodeRequest.getKeyCode();
int changeWindDir = decodeRequest.getChangeWindDir(); int changeWindDir = decodeRequest.getChangeWindDir();
String sessionId = decodeRequest.getSessionId(); String sessionId = decodeRequest.getSessionId();
DecodeResponse response = new DecodeResponse(); DecodeResponse response = new DecodeResponse();
int[] irArray = DecodeLogic.getInstance().decode(); int[] irArray = DecodeLogic.getInstance().decode(
irBinaryRepository,
decodeSessionRepository,
sessionId,
indexId,
acStatus,
keyCode,
changeWindDir);
return response; return response;
} catch (Exception e) { } catch (Exception e) {
@@ -120,10 +127,9 @@ public class IRDecodeService extends AbstractBaseService {
@PostMapping("/close") @PostMapping("/close")
public ServiceResponse irClose(@RequestBody CloseRequest closeRequest) { public ServiceResponse irClose(@RequestBody CloseRequest closeRequest) {
try { try {
String sessionId = closeRequest.getSessionId();
ServiceResponse response = new ServiceResponse(); ServiceResponse response = new ServiceResponse();
DecodeLogic.getInstance().decode(); DecodeLogic.getInstance().close(sessionId);
return response; return response;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();