implemented getRemoteIndex method

This commit is contained in:
strawmanbobi
2018-12-24 23:37:18 +08:00
parent f0b3837566
commit fdf10dca1b
7 changed files with 51 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
package net.irext.decoder;
import net.irext.decoder.model.RemoteIndex;
import org.apache.ibatis.type.MappedTypes;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
@@ -16,7 +17,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* 2018-12-08: created by strawmanbobi
*/
@MapperScan("net.irext.decoder.mybatis.springbootmybatis.mapper")
@MappedTypes(RemoteIndex.class)
@MapperScan("net.irext.decoder.mapper")
@SpringBootApplication
public class IRDecoderApplication {

View File

@@ -1,5 +1,6 @@
package net.irext.decoder.businesslogic;
import net.irext.decoder.mapper.RemoteIndexMapper;
import net.irext.decoder.model.RemoteIndex;
import org.springframework.stereotype.Controller;
@@ -18,14 +19,20 @@ public class IndexLogic {
private static IndexLogic indexLogic;
public static IndexLogic getInstance() {
private RemoteIndexMapper remoteIndexMapper;
public static IndexLogic getInstance(RemoteIndexMapper remoteIndexMapper) {
if (null == indexLogic) {
indexLogic = new IndexLogic();
indexLogic = new IndexLogic(remoteIndexMapper);
}
return indexLogic;
}
public IndexLogic(RemoteIndexMapper remoteIndexMapper) {
this.remoteIndexMapper = remoteIndexMapper;
}
public RemoteIndex getRemoteIndex(int indexId) {
return null;
return remoteIndexMapper.getRemoteIndexById(indexId);
}
}

View File

@@ -0,0 +1,22 @@
package net.irext.decoder.mapper;
import net.irext.decoder.model.RemoteIndex;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
/**
* Filename: RemoteIndexMapper.java
* Revised: Date: 2018-12-08
* Revision: Revision: 1.0
* <p>
* Description: CollectRemote Mybatis Mapper
* <p>
* Revision log:
* 2018-12-08: created by strawmanbobi
*/
@Mapper
public interface RemoteIndexMapper {
@Select("SELECT * FROM remote_index WHERE id = #{id}")
RemoteIndex getRemoteIndexById(int id);
}

View File

@@ -2,6 +2,7 @@ package net.irext.decoder.service;
import net.irext.decoder.businesslogic.DecodeLogic;
import net.irext.decoder.businesslogic.IndexLogic;
import net.irext.decoder.mapper.RemoteIndexMapper;
import net.irext.decoder.model.RemoteIndex;
import net.irext.decoder.request.CloseRequest;
import net.irext.decoder.request.DecodeRequest;
@@ -28,8 +29,10 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/irext")
public class IRDecodeService extends AbstractBaseService {
public IRDecodeService() {
private RemoteIndexMapper remoteIndexMapper;
public IRDecodeService(RemoteIndexMapper remoteIndexMapper) {
this.remoteIndexMapper = remoteIndexMapper;
}
@PostMapping("/open")
@@ -38,7 +41,7 @@ public class IRDecodeService extends AbstractBaseService {
int indexId = openRequest.getIndexId();
ServiceResponse response = new ServiceResponse();
RemoteIndex index = IndexLogic.getInstance().getRemoteIndex(indexId);
RemoteIndex index = IndexLogic.getInstance(remoteIndexMapper).getRemoteIndex(indexId);
if (null == index) {
response.setStatus(new Status(Constants.ERROR_CODE_NETWORK_ERROR, ""));
return response;

View File

@@ -1,4 +1,8 @@
server.port=8082
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.port=6379
spring.datasource.url=jdbc:mysql://localhost:3306/irext
spring.datasource.username=root
spring.datasource.password=root