@ -26,6 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.data.redis.core.RedisTemplate ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.interceptor.TransactionAspectSupport ;
import org.springframework.transaction.interceptor.TransactionAspectSupport ;
@ -33,7 +34,9 @@ import org.springframework.util.ObjectUtils;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.LinkedHashMap ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
import java.util.Objects ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
@ -60,7 +63,10 @@ public class ApGatewayServiceImpl implements ApGatewayService {
private UserOperationLogsService userOperationLogsService ;
private UserOperationLogsService userOperationLogsService ;
@Resource
@Resource
private NotificationService notificationService ;
private NotificationService notificationService ;
@Resource
private RedisTemplate < String , Object > redisTemplate ;
private static final String CSDJ_DOWNLINK_KEY_PREFIX = "csdj:downlink:" ;
@Override
@Override
public PageInfo < ApGateway > query ( ApGatewayQueryParam param , Long userId , Long companyId , Integer languageType ) {
public PageInfo < ApGateway > query ( ApGatewayQueryParam param , Long userId , Long companyId , Integer languageType ) {
@ -373,4 +379,37 @@ public class ApGatewayServiceImpl implements ApGatewayService {
}
}
@Override
public SimpleDataResponse csdjDownlink ( String terminalId , Integer type ) {
if ( terminalId = = null | | terminalId . isEmpty ( ) ) {
return SimpleDataResponse . fail ( ResponseCode . MSG_ERROR , "terminalId 不能为空" ) ;
}
if ( type = = null ) {
return SimpleDataResponse . fail ( ResponseCode . MSG_ERROR , "type 不能为空" ) ;
}
String payloadHex = switch ( type ) {
case 1 - > "03" ; // 端子状態通知要求(CSDJ用)
default - > null ;
} ;
if ( payloadHex = = null ) {
return SimpleDataResponse . fail ( ResponseCode . MSG_ERROR ,
"不支持的指令类型: " + type + " (当前支持: 1=端子状態通知要求)" ) ;
}
String key = CSDJ_DOWNLINK_KEY_PREFIX + terminalId ;
redisTemplate . opsForList ( ) . rightPush ( key , payloadHex ) ;
Long pendingCount = redisTemplate . opsForList ( ) . size ( key ) ;
Map < String , Object > result = new LinkedHashMap < > ( ) ;
result . put ( "success" , true ) ;
result . put ( "terminalId" , terminalId ) ;
result . put ( "type" , type ) ;
result . put ( "payloadHex" , payloadHex ) ;
result . put ( "pendingCount" , pendingCount ! = null ? pendingCount : 0 ) ;
log . info ( "[CSDJ-Downlink] 已添加下行任务, terminalId={}, type={}, payloadHex={}, pendingCount={}" ,
terminalId , type , payloadHex , pendingCount ) ;
return SimpleDataResponse . success ( result ) ;
}
}
}