io.github.nichetoolkit.socket.handler.Jt0x0303Handler Maven / Gradle / Ivy
package io.github.nichetoolkit.socket.handler;
import io.github.nichetoolkit.socket.server.SocketPackage;
import io.github.nichetoolkit.socket.server.handler.SocketPackageHandler;
import io.github.nichetoolkit.socket.service.Jt808DataService;
import io.github.nichetoolkit.socket.util.ByteHexUtils;
import io.github.nichetoolkit.socket.util.Jt808Utils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Jt0x0303Handler 点播信息
* 可以是网络获取 或者 本地存储 平台点播信息 为所有终端共享
* @author Cyan ([email protected])
* @version v.1.0
*/
@Slf4j
@SocketPackage(messageId = 0x0303)
@AllArgsConstructor
public class Jt0x0303Handler implements SocketPackageHandler {
@Autowired
private ThreadPoolExecutor threadPoolExecutor;
@Autowired
private Jt808DataService dataService;
@Override
public byte[] handle(byte[] phoneBytes, byte[] flowIdBytes, byte[] messageIdBytes, byte[] messageBodyBytes) {
log.info("[Jt0x0303] 0303 [信息点播/取消] info request or cancel");
threadPoolExecutor.execute(() -> {
String phone = ByteHexUtils.parseHex(phoneBytes);
/** 点播类型 */
byte type = messageBodyBytes[0];
/** 点播或者取消 */
byte order = messageBodyBytes[1];
if (order == 1) {
/** 保存点播 */
dataService.orderInfo(phone, type);
} else {
/** 取消点播 */
dataService.cancelOrderInfo(phone, type);
}
});
return Jt808Utils.buildJt8001(phoneBytes, flowIdBytes, messageIdBytes, (byte) 0x00);
}
}