unified local file path for download and decode
This commit is contained in:
@@ -6,7 +6,6 @@ import net.irext.server.service.model.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -22,21 +21,41 @@ import java.util.List;
|
||||
@Controller
|
||||
public class IndexingLogic {
|
||||
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
@Autowired
|
||||
private BrandMapper brandMapper;
|
||||
|
||||
@Autowired
|
||||
private CityMapper cityMapper;
|
||||
|
||||
@Autowired
|
||||
private StbOperatorMapper stbOperatorMapper;
|
||||
|
||||
@Autowired
|
||||
private RemoteIndexMapper remoteIndexMapper;
|
||||
|
||||
@Autowired
|
||||
public void setCategoryMapper(CategoryMapper categoryMapper) {
|
||||
this.categoryMapper = categoryMapper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setBrandMapper(BrandMapper brandMapper) {
|
||||
this.brandMapper = brandMapper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setCityMapper(CityMapper cityMapper) {
|
||||
this.cityMapper = cityMapper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStbOperatorMapper(StbOperatorMapper stbOperatorMapper) {
|
||||
this.stbOperatorMapper = stbOperatorMapper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setRemoteIndexMapper(RemoteIndexMapper remoteIndexMapper) {
|
||||
this.remoteIndexMapper = remoteIndexMapper;
|
||||
}
|
||||
|
||||
private static final String IR_BIN_FILE_PREFIX = "irda_";
|
||||
private static final String IR_BIN_FILE_SUFFIX = ".bin";
|
||||
|
||||
@@ -98,17 +117,4 @@ public class IndexingLogic {
|
||||
}
|
||||
return remoteIndexList;
|
||||
}
|
||||
|
||||
public File getDownloadStream(int remoteIndexId) {
|
||||
List<RemoteIndex> remoteIndexList = remoteIndexMapper.getRemoteIndexById(remoteIndexId);
|
||||
if (null == remoteIndexList || 0 == remoteIndexList.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RemoteIndex remote = remoteIndexList.get(0);
|
||||
String downloadPath = "/home/strawmanbobi/";
|
||||
String fileName = IR_BIN_FILE_PREFIX + remote.getRemoteMap() + IR_BIN_FILE_SUFFIX;
|
||||
String localFilePath = downloadPath + fileName;
|
||||
return new File(localFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.squareup.okhttp.*;
|
||||
import net.irext.server.sdk.bean.TemperatureRange;
|
||||
import net.irext.server.service.cache.IDecodeSessionRepository;
|
||||
import net.irext.server.service.cache.IIRBinaryRepository;
|
||||
import net.irext.server.service.mapper.RemoteIndexMapper;
|
||||
import net.irext.server.service.model.ACParameters;
|
||||
import net.irext.server.service.model.RemoteIndex;
|
||||
import net.irext.server.service.utils.FileUtil;
|
||||
@@ -12,6 +13,8 @@ import net.irext.server.service.utils.MD5Util;
|
||||
import net.irext.server.sdk.IRDecode;
|
||||
import net.irext.server.sdk.bean.ACStatus;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.File;
|
||||
@@ -19,9 +22,10 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Filename: DecodeLogic
|
||||
* Filename: OperationLogic
|
||||
* Revised: Date: 2018-12-30
|
||||
* Revision: Revision: 1.0
|
||||
* <p>
|
||||
@@ -31,9 +35,10 @@ import java.security.MessageDigest;
|
||||
* 2018-12-30: created by strawmanbobi
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class DecodeLogic {
|
||||
@Controller
|
||||
public class OperationLogic {
|
||||
|
||||
private static final String TAG = DecodeLogic.class.getSimpleName();
|
||||
private static final String TAG = OperationLogic.class.getSimpleName();
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final String IR_BIN_FILE_PREFIX = "irda_";
|
||||
@@ -41,13 +46,20 @@ public class DecodeLogic {
|
||||
|
||||
private static final String IR_BIN_DOWNLOAD_PREFIX = "http://irext-debug.oss-cn-hangzhou.aliyuncs.com/";
|
||||
|
||||
private static DecodeLogic decodeLogic;
|
||||
private static OperationLogic operationLogic;
|
||||
|
||||
public static DecodeLogic getInstance() {
|
||||
if (null == decodeLogic) {
|
||||
decodeLogic = new DecodeLogic();
|
||||
public static OperationLogic getInstance() {
|
||||
if (null == operationLogic) {
|
||||
operationLogic = new OperationLogic();
|
||||
}
|
||||
return decodeLogic;
|
||||
return operationLogic;
|
||||
}
|
||||
|
||||
private RemoteIndexMapper remoteIndexMapper;
|
||||
|
||||
@Autowired
|
||||
public void setRemoteIndexMapper(RemoteIndexMapper remoteIndexMapper) {
|
||||
this.remoteIndexMapper = remoteIndexMapper;
|
||||
}
|
||||
|
||||
public RemoteIndex openIRBinary(ServletContext context, IIRBinaryRepository irBinaryRepository,
|
||||
@@ -259,4 +271,23 @@ public class DecodeLogic {
|
||||
Response response = new OkHttpClient().newCall(request).execute();
|
||||
return response.body().byteStream();
|
||||
}
|
||||
|
||||
public File getDownloadFile(ServletContext context, int remoteIndexId) {
|
||||
try {
|
||||
List<RemoteIndex> remoteIndexList = remoteIndexMapper.getRemoteIndexById(remoteIndexId);
|
||||
if (null == remoteIndexList || 0 == remoteIndexList.size()) {
|
||||
return null;
|
||||
}
|
||||
RemoteIndex remoteIndex = remoteIndexList.get(0);
|
||||
String downloadPath = context.getRealPath("") + "bin_cache" + File.separator;
|
||||
String fileName = IR_BIN_FILE_PREFIX + remoteIndex.getRemoteMap() + IR_BIN_FILE_SUFFIX;
|
||||
String localFilePath = downloadPath + fileName;
|
||||
File binFile = new File(localFilePath);
|
||||
getFile(binFile, downloadPath, fileName, remoteIndex.getBinaryMd5().toUpperCase());
|
||||
return binFile;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.irext.server.service.restapi;
|
||||
|
||||
import net.irext.server.service.businesslogic.DecodeLogic;
|
||||
import net.irext.server.service.businesslogic.OperationLogic;
|
||||
import net.irext.server.service.cache.IDecodeSessionRepository;
|
||||
import net.irext.server.service.cache.IIRBinaryRepository;
|
||||
import net.irext.server.service.model.ACParameters;
|
||||
@@ -26,14 +26,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import static org.apache.commons.io.filefilter.DirectoryFileFilter.DIRECTORY;
|
||||
|
||||
/**
|
||||
* Filename: IRDecodeService.java
|
||||
* Revised: Date: 2018-12-16
|
||||
@@ -57,6 +54,8 @@ public class IROperationService extends AbstractBaseService {
|
||||
|
||||
private IndexingLogic indexingLogic;
|
||||
|
||||
private OperationLogic operationLogic;
|
||||
|
||||
private IIRBinaryRepository irBinaryRepository;
|
||||
|
||||
private IDecodeSessionRepository decodeSessionRepository;
|
||||
@@ -71,6 +70,11 @@ public class IROperationService extends AbstractBaseService {
|
||||
this.indexingLogic = indexingLogic;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setOperationLogic(OperationLogic operationLogic) {
|
||||
this.operationLogic = operationLogic;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setIrBinaryRepository(IIRBinaryRepository irBinaryRepository) {
|
||||
this.irBinaryRepository = irBinaryRepository;
|
||||
@@ -85,7 +89,7 @@ public class IROperationService extends AbstractBaseService {
|
||||
public ResponseEntity<InputStreamResource> downloadBin(
|
||||
@RequestBody DownloadBinaryRequest downloadBinaryRequest) throws IOException {
|
||||
|
||||
File downloadFile = indexingLogic.getDownloadStream(downloadBinaryRequest.getIndexId());
|
||||
File downloadFile = operationLogic.getDownloadFile(context, downloadBinaryRequest.getIndexId());
|
||||
|
||||
if (null == downloadFile) {
|
||||
return ResponseEntity.ok().body(null);
|
||||
@@ -122,7 +126,7 @@ public class IROperationService extends AbstractBaseService {
|
||||
remoteIndex.getRemoteMap());
|
||||
}
|
||||
RemoteIndex cachedRemoteIndex =
|
||||
DecodeLogic.getInstance().openIRBinary(context, irBinaryRepository, remoteIndex);
|
||||
OperationLogic.getInstance().openIRBinary(context, irBinaryRepository, remoteIndex);
|
||||
|
||||
if (null != cachedRemoteIndex) {
|
||||
LoggerUtil.getInstance().trace(TAG, "binary content fetched : " +
|
||||
@@ -170,7 +174,7 @@ public class IROperationService extends AbstractBaseService {
|
||||
return response;
|
||||
}
|
||||
|
||||
ACParameters acParameters = DecodeLogic.getInstance().getACParameters(cachedRemoteIndex, mode);
|
||||
ACParameters acParameters = OperationLogic.getInstance().getACParameters(cachedRemoteIndex, mode);
|
||||
|
||||
response.setStatus(new Status(Constants.ERROR_CODE_SUCCESS, Constants.ERROR_CODE_SUCESS_TEXT));
|
||||
response.setEntity(acParameters);
|
||||
@@ -201,7 +205,7 @@ public class IROperationService extends AbstractBaseService {
|
||||
return response;
|
||||
}
|
||||
|
||||
int[] irArray = DecodeLogic.getInstance().decode(
|
||||
int[] irArray = OperationLogic.getInstance().decode(
|
||||
cachedRemoteIndex,
|
||||
acStatus,
|
||||
keyCode,
|
||||
@@ -221,7 +225,7 @@ public class IROperationService extends AbstractBaseService {
|
||||
try {
|
||||
String sessionId = closeRequest.getSessionId();
|
||||
ServiceResponse response = new ServiceResponse();
|
||||
DecodeLogic.getInstance().close(decodeSessionRepository, sessionId);
|
||||
OperationLogic.getInstance().close(decodeSessionRepository, sessionId);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -5,4 +5,5 @@ spring.redis.host=localhost
|
||||
spring.redis.port=6379
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/irext?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=421aWill.
|
||||
spring.datasource.password=421aWill.
|
||||
user.data.basedir=/data/
|
||||
Reference in New Issue
Block a user