feat: 初始化

This commit is contained in:
2024-04-09 11:34:46 +08:00
commit 39f3acc15f
3209 changed files with 253442 additions and 0 deletions
@@ -0,0 +1,36 @@
package com.yida.data.server;
import cc.mrbird.febs.common.security.starter.annotation.EnableFebsCloudResourceServer;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableAsync
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
@EnableFebsCloudResourceServer
@EnableTransactionManagement
@MapperScan("com.yida.data.server.mapper")
@EnableFeignClients(basePackages = "com.yida.data")
@EnableScheduling
public class App {
public static void main(String[] args) {
//获取application的上下文
ApplicationContext applicationContext = new SpringApplicationBuilder(App.class)
.web(WebApplicationType.SERVLET)
.run(args);
/**
* 启动netty dtu的服务端
*/
// StartConfig socketServer = applicationContext.getBean(StartConfig.class);
// socketServer.start();
}
}
@@ -0,0 +1,15 @@
//package com.yida.data.server.config;
//
//import cc.mrbird.febs.common.redis.service.RedisService;
//import com.yida.data.server.service.DataService;
//import lombok.RequiredArgsConstructor;
//import org.springframework.context.annotation.Configuration;
//
//@Configuration
//@RequiredArgsConstructor
//public class HandlerConfig {
//
// private final RedisService redisService;
// private final DataService dataService;
//
//}
@@ -0,0 +1,130 @@
//package com.yida.data.server.config;
//
//import cc.mrbird.febs.common.redis.service.RedisService;
//import com.yida.data.server.handler.MyHandler;
//import com.yida.data.server.service.DataService;
//import io.netty.bootstrap.ServerBootstrap;
//import io.netty.buffer.PooledByteBufAllocator;
//import io.netty.buffer.Unpooled;
//import io.netty.channel.ChannelFuture;
//import io.netty.channel.ChannelInitializer;
//import io.netty.channel.ChannelOption;
//import io.netty.channel.ChannelPipeline;
//import io.netty.channel.EventLoopGroup;
//import io.netty.channel.nio.NioEventLoopGroup;
//import io.netty.channel.socket.SocketChannel;
//import io.netty.channel.socket.nio.NioServerSocketChannel;
//import io.netty.handler.codec.DelimiterBasedFrameDecoder;
//import io.netty.handler.codec.string.StringDecoder;
//import io.netty.handler.codec.string.StringEncoder;
//import io.netty.util.concurrent.Future;
//import io.netty.util.concurrent.GenericFutureListener;
//import java.net.InetAddress;
//import java.net.InetSocketAddress;
//import java.net.UnknownHostException;
//import javax.annotation.Resource;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.context.annotation.Configuration;
//
//@Slf4j
//@Configuration
//public class StartConfig {
//
// @Resource
// private DataService dataService;
// @Resource
// private RedisService redisService;
//
// private final static EventLoopGroup bossGroup = new NioEventLoopGroup();
// //开启两个线程池
// private final static EventLoopGroup workGroup = new NioEventLoopGroup();
// //启动装饰类
// private final static ServerBootstrap serverBootstrap = new ServerBootstrap();
// //本机的ip地址
// private String ip;
//
// //启动端口
// private int port = 1993;
//
// /**
// * 启动服务
// */
// public void start() {
//
// try {
// //获取本机的ip地址
// ip = InetAddress.getLocalHost().getHostAddress();
// } catch (UnknownHostException e1) {
// e1.printStackTrace();
// }
//
// serverBootstrap.group(bossGroup, workGroup)
// //非阻塞
// .channel(NioServerSocketChannel.class)
// //连接缓冲池的大小
// .option(ChannelOption.SO_BACKLOG, 1024)
// //设置通道Channel的分配器
// .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
// .childHandler(new ChannelInitializer<SocketChannel>() {
//
// @Override
// protected void initChannel(SocketChannel socketChannel) throws Exception {
// ChannelPipeline pipeline = socketChannel.pipeline();
// // 按#分割 最大长度1024字节
// pipeline.addLast(new DelimiterBasedFrameDecoder(1024, Unpooled.copiedBuffer("#".getBytes())));
// // 解码器 转换为字符串
// pipeline.addLast(new StringDecoder());
// // 编码器
// pipeline.addLast(new StringEncoder());
// //数据处理
// pipeline.addLast(new MyHandler(dataService, redisService));
//
//
// }
// });
// ChannelFuture channelFuture = null;
// //启动成功标识
// boolean startFlag = false;
// //启动失败时,多次启动,直到启动成功为止
// while (!startFlag) {
// try {
// channelFuture = serverBootstrap.bind(port).sync();
// startFlag = true;
// } catch (Exception e) {
// log.info("端口号:" + port + "已被占用!");
// port++;
// log.info("尝试一个新的端口:" + port);
// //重新便规定端口号
// serverBootstrap.localAddress(new InetSocketAddress(port));
// }
// }
//
// //服务端启动监听事件
// channelFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
// @Override
// public void operationComplete(Future<? super Void> future) throws Exception {
// //启动成功后的处理
// if (future.isSuccess()) {
// log.info("netty 服务器启动成功,Started Successed:" + ip + ":" + port);
// } else {
// log.info("netty 服务器启动失败,Started Failed:" + ip + ":" + port);
// }
// }
// });
//
// try {
// // 监听通道关闭事件
// // 应用程序会一直等待,直到channel关闭
// ChannelFuture closeFuture = channelFuture.channel().closeFuture();
// closeFuture.sync();
// } catch (Exception e) {
// e.printStackTrace();
// log.error("发生其他异常", e);
// } finally {
// // 优雅关闭EventLoopGroup
// // 释放掉所有资源包括创建的线程
// bossGroup.shutdownGracefully();
// workGroup.shutdownGracefully();
// }
// }
//}
@@ -0,0 +1,15 @@
package com.yida.data.server.constants;
public interface CardConstants {
/**
* 命令起始符
*/
String START_WITH = "*";
/**
* 命令结束符
*/
String END_WITH = "#";
}
@@ -0,0 +1,32 @@
package com.yida.data.server.constants;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum MsgType {
V4("V4", "回复信息"),
// 设备上报信息
V2("V2", "设备gps定位信息"),
WIFIMAC("WIFIMAC", "设备wifi定位信息"),
KA("KA", "设备基站定位信息"),
V3("V3", "设备补传定位信息"),
ALARM_STATIC("STATIC", "设备静止上报"),
POWER_ON("POWERON", "开机上报"),
POWER_OFF("POWEROFF", "关机上报"),
STEP("STEP", "步数上报"),
FENCE_OUT("POSTOUT", "设备离开围栏信息"),
FENCE_IN("POSTIN", "设备进入围栏信息"),
// 平台下发指令
WHITE_ALL("WLALL", "批量设置白名单"),
FENCE("POSTSELF", "设置围栏"),
FENCE_SWITCH("RFSWITCH", "设置围栏"),
DISTURB_TIME("CLASS", "设置免打扰时间"),
DISTURB_SWITCH("CLASSSWITCH", "设置免打扰开关"),
LOCATION("D1", "立即定位"),
WEATHER("WEATHER", "下发天气");
private String value;
private String name;
}
@@ -0,0 +1,70 @@
//package com.yida.data.server.controller.in;
//
//import com.yida.data.common.core.common.ResultBean;
//import com.yida.data.server.dto.DisturbDTO;
//import com.yida.data.server.dto.FenceDTO;
//import com.yida.data.server.dto.WhiteListDTO;
//import com.yida.data.server.service.OperationService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiModelProperty;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import lombok.RequiredArgsConstructor;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//@Api(tags = "下发指令")
//@RequiredArgsConstructor
//@RestController
//@RequestMapping("/in/operation")
//public class InOperationController {
//
// private final OperationService operationService;
//
// @ApiOperation("设置白名单")
// @PostMapping("/whiteList")
// public ResultBean whiteList(@RequestBody WhiteListDTO dto) {
// operationService.whiteList(dto);
// return ResultBean.buildSuccess();
// }
//
// @ApiOperation("围栏通知开关")
// @PostMapping("/fenceSwitch")
// public ResultBean fenceSwitch(@RequestParam String imei,
// @ApiParam("0-关闭,1-开") @RequestParam Integer type) {
// operationService.fenceSwitch(imei, type);
// return ResultBean.buildSuccess();
// }
//
// @ApiOperation("创建围栏")
// @PostMapping("/fence")
// public ResultBean fence(@RequestBody FenceDTO dto) {
// operationService.fence(dto);
// return ResultBean.buildSuccess();
// }
//
// @ApiModelProperty("免打扰时间设置")
// @PostMapping("/disturbTime")
// public ResultBean disturb(@RequestBody DisturbDTO dto) {
// operationService.disturbTime(dto);
// return ResultBean.buildSuccess();
// }
//
// @ApiModelProperty("免打扰开关")
// @PostMapping("/disturbSwitch")
// public ResultBean disturbSwitch(@RequestParam String imei,
// @ApiParam("0-关闭,1-打开常规免打扰,2-打开静默") @RequestParam Integer type) {
// operationService.disturbSwitch(imei, type);
// return ResultBean.buildSuccess();
// }
//
// @ApiModelProperty("主动定位")
// @PostMapping("/nowLocation")
// public ResultBean nowLocation(@RequestParam String imei) {
// operationService.nowLocation(imei);
// return ResultBean.buildSuccess();
// }
//}
@@ -0,0 +1,78 @@
package com.yida.data.server.controller.out;
import cn.hutool.core.util.NumberUtil;
import com.yida.data.server.dto._810ADeviceStaticDTO;
import com.yida.data.server.dto._810ALocationDTO;
import com.yida.data.server.dto._810ALowBatDTO;
import com.yida.data.server.dto._810ARiskAreaDTO;
import com.yida.data.server.dto._810AStepDTO;
import com.yida.data.server.vo._810AResVO;
import io.swagger.annotations.ApiOperation;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ApiOperation("810A学生证对接")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/out/810a")
public class Out810AController {
private final com.yida.data.server.service._810ADataService _810ADataService;
@ApiOperation("推送设备最新位置")
@RequestMapping("PushDeviceCurpos")
public _810AResVO pushDeviceCurpos(@RequestBody _810ALocationDTO dto) {
_810ADataService.dealLocation(dto);
return _810AResVO.success();
}
@ApiOperation("围栏告警")
@RequestMapping("/PushDeviceFence")
public _810AResVO pushDeviceFence(@RequestBody LinkedHashMap<String, String> dto) {
_810ARiskAreaDTO dto1 = new _810ARiskAreaDTO();
log.info("接收告警数据:[{}]", dto);
dto1.setDEVICENUM(dto.get("DEVICENUM"));
dto1.setFENCETYPE(NumberUtil.parseInt(dto.get("FENCETYPE")));
dto1.setBAT(NumberUtil.parseInt(dto.get("BAT")));
dto1.setGPS(NumberUtil.parseInt(dto.get("GPS")));
dto1.setGSM(NumberUtil.parseInt(dto.get("GSM")));
dto1.setISONLINE(NumberUtil.parseInt(dto.get("ISONLINE")));
dto1.setLA(NumberUtil.parseDouble(dto.get("LA")));
dto1.setLO(NumberUtil.parseDouble(dto.get("LO")));
dto1.setLOCTIME(LocalDateTime.parse(dto.get("LOCTIME"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
dto1.setPOSDESC(dto.get("POSDESC"));
dto1.setREMARK(dto.get("REMARK"));
dto1.setSPEED(NumberUtil.parseInt(dto.get("SPEED")));
dto1.setTYPE(NumberUtil.parseInt(dto.get("TYPE")));
_810ADataService.riskArea(dto1);
return _810AResVO.success();
}
@ApiOperation("学生步数")
@RequestMapping("/PushDeviceStep")
public _810AResVO pushDeviceStep(@RequestBody _810AStepDTO dto) {
_810ADataService.stepPush(dto);
return _810AResVO.success();
}
@ApiOperation("低电量")
@RequestMapping("/PushDeviceLowbat")
public _810AResVO pushDeviceLowbat(@RequestBody _810ALowBatDTO dto) {
_810ADataService.lowBat(dto);
return _810AResVO.success();
}
@ApiOperation("设备脱落")
@RequestMapping("PushDeviceStatic")
public _810AResVO pushDeviceStatic(@RequestBody _810ADeviceStaticDTO dto) {
_810ADataService.deviceStatic(dto);
return _810AResVO.success();
}
}
@@ -0,0 +1,26 @@
//package com.yida.data.server.controller.out;
//
//
//import com.yida.data.common.core.common.ResultBean;
//import com.yida.data.server.service.OperationService;
//import io.swagger.annotations.Api;
//import lombok.RequiredArgsConstructor;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//@Api(tags = "下发指令")
//@RequiredArgsConstructor
//@RestController
//@RequestMapping("/out/operation")
//public class OutOperationController {
//
// private final OperationService operationService;
//
// @GetMapping("/cmd")
// public ResultBean cmd(String imei, String cmd) {
// operationService.cmd(imei, cmd);
// return ResultBean.buildSuccess();
// }
//
//}
@@ -0,0 +1,22 @@
package com.yida.data.server.dto;
import lombok.Data;
@Data
public class BaseMsgDTO {
/**
* 设备厂商,两位
*/
private String vendor;
/**
* 设备imei号
*/
private String imei;
/**
* 时分秒 HHmmss
*/
private String time;
}
@@ -0,0 +1,92 @@
package com.yida.data.server.dto;
import lombok.Data;
@Data
public class DeviceMsgDTO extends BaseMsgDTO {
/**
* v2 上报信息 v4 确认指令
*/
private String type;
/**
* 信号值 0-99
*/
private Integer signal;
/**
* 可见卫星数
*/
private Integer sv;
/**
* 电量 0-99
*/
private Integer bat;
/**
* 数据有效位 A-有效数据 V-无效数据
*/
private String s;
/**
* 纬度
*/
private String lat;
/**
* N-北纬,S-南纬
*/
private String d;
/**
* 经度
*/
private String lng;
/**
* E-东经,W-西经
*/
private String g;
/**
* 速度
*/
private Double speed;
/**
* 定位精度
*/
private Double pdop;
/**
* dd/MM/yyyy
*/
private String date;
/**
* 设备状态
*/
private String status;
/**
* 指令
*/
private String cmd;
/**
* 指令时间
*/
private String seq;
/**
* 指令参数
*/
private String params;
/**
* 设备时间 HHMMSS
*/
private String time;
}
@@ -0,0 +1,5 @@
package com.yida.data.server.dto;
public class DeviceV2Msg {
}
@@ -0,0 +1,26 @@
package com.yida.data.server.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import lombok.Data;
@ApiModel("围栏进出消息")
@Data
public class FenceAlarmDTO {
private String imei;
private Double lat;
private Double lng;
@ApiModelProperty("围栏id")
private Integer id;
@ApiModelProperty("发生时间")
private LocalDateTime time;
@ApiModelProperty("0-进入围栏,1-离开围栏")
private Integer type;
}
@@ -0,0 +1,18 @@
package com.yida.data.server.dto;
import lombok.Data;
@Data
public class ServerMsgDTO extends BaseMsgDTO {
private String v4;
private String cmd;
private String time;
private String params;
private String seq;
}
@@ -0,0 +1,21 @@
package com.yida.data.server.dto;
import lombok.Data;
/**
* 设备确认信息
*/
@Data
public class ServerVerifyMsgDTO {
/**
* 确认指令
*/
private String v4;
private String cmd;
private String seq;
private String time;
}
@@ -0,0 +1,52 @@
package com.yida.data.server.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Data
@Builder
@Document
@NoArgsConstructor
@AllArgsConstructor
public class BtsLocation {
@Id
private String id;
private Double lat;
private Double lng;
@ApiModelProperty("移动设备国家代码,中国-460")
private String mcc;
@ApiModelProperty("移动设备网络代码,移动-00,联通-01,电信-11")
private String mnc;
@ApiModelProperty("位置区域码 GSM/UMTS 取 LAC,LTE/5G 取 TAC")
private String lac;
@ApiModelProperty("基站小区编号")
private String cid;
@ApiModelProperty("信号强度(转换后)")
private Integer signal;
@ApiModelProperty("城市代码")
private String adcode;
public BtsLocation(Double lng, Double lat, String mcc, String mnc, String lac, String cid, Integer signal) {
this.lng = lng;
this.lat = lat;
this.mcc = mcc;
this.mnc = mnc;
this.lac = lac;
this.cid = cid;
this.signal = signal;
}
}
@@ -0,0 +1,46 @@
package com.yida.data.server.entity;
import io.swagger.annotations.ApiModelProperty;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Data
@Builder
@Document
@NoArgsConstructor
@AllArgsConstructor
public class WifimacLocation {
@Id
private String id;
private Double lng;
private Double lat;
@ApiModelProperty("mac地址,最长六个")
private String mac1;
private String mac2;
private String mac3;
private String mac4;
private String mac5;
private String mac6;
public WifimacLocation(Double lng, Double lat, String mac1, String mac2, String mac3, String mac4, String mac5,
String mac6) {
this.lng = lng;
this.lat = lat;
this.mac1 = Optional.ofNullable(mac1).orElse("");
this.mac2 = Optional.ofNullable(mac2).orElse("");
this.mac3 = Optional.ofNullable(mac3).orElse("");
this.mac4 = Optional.ofNullable(mac4).orElse("");
this.mac5 = Optional.ofNullable(mac5).orElse("");
this.mac6 = Optional.ofNullable(mac6).orElse("");
}
}
@@ -0,0 +1,105 @@
//package com.yida.data.server.handler;
//
//import cc.mrbird.febs.common.redis.service.RedisService;
//import cn.hutool.core.util.StrUtil;
//import com.yida.data.common.core.entity.constant.CachePrefixConstant;
//import com.yida.data.common.core.entity.constant.LockPrefixConstant;
//import com.yida.data.common.core.utils.EnumUtils;
//import com.yida.data.server.constants.MsgType;
//import com.yida.data.server.service.DataService;
//import com.yida.data.server.utils.ChannelUtil;
//import io.netty.channel.Channel;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.SimpleChannelInboundHandler;
//import java.time.LocalTime;
//import java.time.format.DateTimeFormatter;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//
//@Slf4j
//@RequiredArgsConstructor
//public class MyHandler extends SimpleChannelInboundHandler<String> {
//
// private final DataService dataService;
// private final RedisService redisService;
//
// @Override
// protected void channelRead0(ChannelHandlerContext ctx, String msg) throws NoSuchMethodException {
// msg = StrUtil.trim(msg).substring(1);
// log.info("接收消息:[{}]", msg);
// String[] datas = msg.split(",");
// String type = datas[2];
// String imei = datas[1];
// if (MsgType.V4.getValue().equals(type)) { // 指令上报回复
// // 释放锁
// redisService.falseUnLock(LockPrefixConstant.CARD_CMD_LOCK + datas[1]);
//// type = datas[3];
//// switch (EnumUtils.valueOf(MsgType.class, type, MsgType.class.getMethod("getValue"))) {
//// case LOCATION:
//// dataService.dealLocation(datas);
//// }
// } else { // 定位信息
// Channel channel = ctx.channel();
// // 初次登录系统
// if (!redisService.hasKey(CachePrefixConstant.DEVICE_CARD_ONLINE + imei)) {
// redisService.hset(CachePrefixConstant.DEVICE_CARD_IMEI_VENDOR, imei, datas[0]);
// ChannelUtil.online(channel, imei);
// }
// switch (EnumUtils.valueOf(MsgType.class, type, MsgType.class.getMethod("getValue"))) {
// case V2:
// dataService.dealDeviceV2(datas);
// break;
// case WIFIMAC:
// dataService.dealDeviceWifi(datas);
// break;
// case KA:
// dataService.dealDeviceKa(datas);
// break;
// case V3:
// dataService.dealDeviceV3(datas);
// break;
// case FENCE_IN:
// dataService.dealFenceAlarm(datas, 0);
// break;
// case FENCE_OUT:
// dataService.dealFenceAlarm(datas, 1);
// break;
// case STEP:
// dataService.dealStep(datas);
// }
//
// // 回复设备
// StringBuilder sb = new StringBuilder();
// sb.append("*")
// .append(datas[0])
// .append(",")
// .append(datas[1])
// .append(",V4,")
// .append(type)
// .append(",")
// .append(datas[3])
// .append(",")
// .append(LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")))
// .append("#");
// channel.writeAndFlush(sb.toString());
//
// }
// // 在线数据保留300s
// redisService.set(CachePrefixConstant.DEVICE_CARD_ONLINE + imei, 0, 300L);
// }
//
// @Override
// public void channelActive(ChannelHandlerContext ctx) throws Exception {
// log.info("链接成功");
// }
//
// @Override
// public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
// Channel channel = ctx.channel();
// String imei = ChannelUtil.getImei(channel);
// if (StrUtil.isNotBlank(imei)) {
// redisService.del(CachePrefixConstant.DEVICE_CARD_ONLINE + imei);
// ChannelUtil.removeChannel(imei);
// }
// }
//}
@@ -0,0 +1,11 @@
package com.yida.data.server.repository;
import com.yida.data.server.entity.BtsLocation;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface BtsLocationRespository extends MongoRepository<BtsLocation, String> {
BtsLocation findByMccAndMncAndLacAndCid(String mcc, String mnc, String lac, String cid);
}
@@ -0,0 +1,10 @@
package com.yida.data.server.repository;
import com.yida.data.common.core.entity.card.EduStudentCardLocation;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface EduStudentCardLocationRespository extends ElasticsearchRepository<EduStudentCardLocation, Long> {
}
@@ -0,0 +1,13 @@
package com.yida.data.server.repository;
import com.yida.data.server.entity.WifimacLocation;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface WifimacLocationRespository extends MongoRepository<WifimacLocation, String> {
WifimacLocation findByMac1InAndMac2InAndMac3InAndMac4InAndMac5InAndMac6In(List<String> mac1, List<String> mac2,
List<String> mac3, List<String> mac4, List<String> mac5, List<String> mac6);
}
@@ -0,0 +1,48 @@
//package com.yida.data.server.service;
//
//import org.springframework.scheduling.annotation.Async;
//
//public interface DataService {
//
// /**
// * 处理基站数据
// */
// @Async
// void dealDeviceKa(String[] datas);
//
// /**
// * 处理gps数据
// *
// * @param datas
// */
// @Async
// void dealDeviceV2(String[] datas);
//
// @Async
// void dealDeviceV3(String[] datas);
//
// /**
// * 处理wifi数据
// *
// * @param datas
// */
// @Async
// void dealDeviceWifi(String[] datas);
//
// /**
// * 处理进出围栏数据
// *
// * @param datas
// * @param type 0-进,1-出
// */
// @Async
// void dealFenceAlarm(String[] datas, Integer type);
//
// /**
// * 处理步数上报
// */
// void dealStep(String[] data);
//
// void dealLocation(String[] datas);
//
//}
@@ -0,0 +1,70 @@
//package com.yida.data.server.service;
//
//import com.yida.data.server.dto.DisturbDTO;
//import com.yida.data.server.dto.FenceDTO;
//import com.yida.data.server.dto.WhiteListDTO;
//
//public interface OperationService {
//
// /**
// * 获取定位信息
// */
// void getLocation(String imei);
//
// /**
// * 白名单
// *
// * @param dto
// */
// void whiteList(WhiteListDTO dto);
//
// /**
// * 切换围栏通知状态
// *
// * @param imei
// * @param type 0-关,1-开
// */
// void fenceSwitch(String imei, Integer type);
//
// /**
// * 围栏
// *
// * @param dto
// */
// void fence(FenceDTO dto);
//
// /**
// * 免打扰
// *
// * @param dto
// */
// void disturbTime(DisturbDTO dto);
//
// /**
// * 免打扰切换
// *
// * @param imei
// * @param type
// */
// void disturbSwitch(String imei, Integer type);
//
// /**
// * 立即定位
// *
// * @param imei
// */
// void nowLocation(String imei);
//
// /**
// * 下发命令
// *
// * @param imei
// * @param cmd
// */
// void cmd(String imei, String cmd);
//
// /**
// * 下发天气
// */
// void weather(String imei, String adCode);
//}
@@ -0,0 +1,34 @@
package com.yida.data.server.service;
import com.yida.data.server.dto._810ADeviceStaticDTO;
import com.yida.data.server.dto._810ALocationDTO;
import com.yida.data.server.dto._810ALowBatDTO;
import com.yida.data.server.dto._810ARiskAreaDTO;
import com.yida.data.server.dto._810AStepDTO;
import com.yida.data.server.vo._810AResVO;
public interface _810ADataService {
/**
* 处理带定位数据定位推送
*/
_810AResVO dealLocation(_810ALocationDTO dto);
_810AResVO riskArea(_810ARiskAreaDTO dto);
/**
* 步数推送
*/
_810AResVO stepPush(_810AStepDTO dto);
/**
* 低电量
*/
_810AResVO lowBat(_810ALowBatDTO dto);
/**
* 设备脱落
*/
_810AResVO deviceStatic(_810ADeviceStaticDTO dto);
}
@@ -0,0 +1,295 @@
//package com.yida.data.server.service.impl;
//
//import cc.mrbird.febs.common.redis.service.RedisService;
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.lang.Snowflake;
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.json.JSONObject;
//import com.yida.data.common.core.entity.card.EduStudentCardLocation;
//import com.yida.data.common.core.entity.constant.CachePrefixConstant;
//import com.yida.data.common.core.utils.GeoUtil;
//import com.yida.data.common.core.utils.LocationUtil;
//import com.yida.data.device.vo.studentCard.LocationVO;
//import com.yida.data.rabbit.constant.RabbitConstant;
//import com.yida.data.rabbit.util.RabbitUtil;
//import com.yida.data.server.dto.DeviceReportDTO;
//import com.yida.data.server.dto.FenceAlarmDTO;
//import com.yida.data.server.entity.BtsLocation;
//import com.yida.data.server.entity.WifimacLocation;
//import com.yida.data.server.repository.BtsLocationRespository;
//import com.yida.data.server.repository.EduStudentCardLocationRespository;
//import com.yida.data.server.repository.WifimacLocationRespository;
//import com.yida.data.server.service.DataService;
//import com.yida.data.server.service.OperationService;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.List;
//import lombok.RequiredArgsConstructor;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//
//@Service
//@RequiredArgsConstructor
//public class DataServiceImpl implements DataService {
//
// private final EduStudentCardLocationRespository eduStudentCardLocationRespository;
// private final BtsLocationRespository btsLocationRespository;
// private final WifimacLocationRespository wifimacLocationRespository;
// private final OperationService operationService;
// private final RedisService redisService;
// private final RabbitUtil rabbitUtil;
// private final static Snowflake snowFlake = new Snowflake(1L, 1L);
//
// /**
// * 处理设备V2数据
// */
// public void dealDeviceV2(String[] datas) {
// EduStudentCardLocation position = new EduStudentCardLocation();
// position.setId(snowFlake.nextId());
// position.setCreateDate(LocalDateTime.now());
// position.setType(0);
// position.setLat(positionTrans(datas[9].equals("N") ? 1 : -1, datas[8]));
// position.setLng(positionTrans(datas[11].equals("E") ? 1 : -1, datas[10]));
// position.setImei(datas[1]);
// position.setVendor(datas[0]);
// position.setBat(Integer.valueOf(datas[6]));
//// position.setSv(Integer.valueOf(datas[5]));
//// position.setSignal(Integer.valueOf(datas[4]));
//// position.setSpeed(Double.valueOf(datas[12]));
//// position.setPdop(Double.valueOf(datas[13]));
// position.setDeviceTime(dealDateTime(datas[14], datas[3]));
// position.setStatus(datas[15]);
// // gps数据需要转换为高德坐标系
// List<Double> togcj02 = GeoUtil.wgs84togcj02(position.getLng(), position.getLat());
// position.setLng(togcj02.get(0));
// position.setLat(togcj02.get(1));
// afterLocationDeal(position);
// }
//
// @Override
// public void dealDeviceV3(String[] datas) {
// EduStudentCardLocation position = new EduStudentCardLocation();
// position.setType(3);
//
// position.setImei(datas[1]);
// position.setVendor(datas[0]);
//
// position.setStatus(datas[datas.length - 1]);
// int locationNum = Integer.valueOf(datas[4]);
// // 保存其它点
// for (int i = 0; i < locationNum; i++) {
// // 设备定位点间隔20s
// position.setDeviceTime(i == 0 ? dealDateTime(datas[6], datas[3]) : position.getDeviceTime().plusSeconds(20L));
// String lngStr = datas[8 + i * 2];
// String latStr = datas[7 + i * 2];
// position.setLng(StrUtil.isNotEmpty(lngStr) ? positionTrans(1, lngStr) : position.getLng());
// position.setLat(StrUtil.isNotEmpty(latStr) ? positionTrans(1, latStr) : position.getLat());
// // gps数据需要转换为高德坐标系
// if (StrUtil.isNotBlank(lngStr)) {
// List<Double> togcj02 = GeoUtil.wgs84togcj02(position.getLng(), position.getLat());
// position.setLng(togcj02.get(0));
// position.setLat(togcj02.get(1));
// }
// position.setId(snowFlake.nextId());
// position.setCreateDate(LocalDateTime.now());
// // 保存数据
// eduStudentCardLocationRespository.save(position);
// }
//// afterLocationDeal(position);
// }
//
// @Override
// public void dealFenceAlarm(String[] datas, Integer type) {
// FenceAlarmDTO dto = new FenceAlarmDTO();
// dto.setImei(datas[1]);
// dto.setLng(positionTrans(datas[9].equals("N") ? 1 : -1, datas[8]));
// dto.setLat(positionTrans(datas[7].equals("E") ? 1 : -1, datas[6]));
// dto.setId(Integer.valueOf(datas[4]));
// dto.setTime(dealDateTime(datas[12], datas[3]));
// // TODO: 2021/11/25 保存告警信息
// }
//
// @Override
// public void dealStep(String[] datas) {
// DeviceReportDTO reportMsg = new DeviceReportDTO();
// reportMsg.setImei(datas[1]);
// reportMsg.setStep(Integer.valueOf(datas[2]));
// reportMsg.setDeviceTime(dealDateTime(datas[5], datas[3]));
// rabbitUtil.convertAndSendMsg(RabbitConstant.CARD_EXCHANGE, RabbitConstant.CARD_LOCATION_KEY, reportMsg);
// }
//
// @Override
// public void dealLocation(String[] datas) {
// EduStudentCardLocation position = new EduStudentCardLocation();
// position.setId(snowFlake.nextId());
// position.setCreateDate(LocalDateTime.now());
// position.setVendor(datas[0]);
// position.setImei(datas[1]);
// position.setType(1);
// position.setSignal(Integer.valueOf(datas[20]));
// position.setSv(Integer.valueOf(datas[21]));
// position.setBat(Integer.valueOf(datas[22]));
// position.setDeviceTime(dealDateTime(datas[datas.length - 2], datas[5]));
// position.setStatus(datas[datas.length - 1]);
// // 查询经纬度数据
// BtsLocation btsLocation = null;
// // 基站数据是否缓存
// Boolean locationCache = redisService
// .hasKey(CachePrefixConstant.LOCATION_BTS + StrUtil.join(",", datas[13], datas[14], datas[17], datas[18]));
// if (locationCache) {
// btsLocation = (BtsLocation) redisService
// .get(CachePrefixConstant.LOCATION_BTS + StrUtil.join(",", datas[13], datas[14], datas[17], datas[18]));
// } else {
// btsLocation = btsLocationRespository
// .findByMccAndMncAndLacAndCid(datas[13], datas[14], datas[17], datas[18]);
// // 未保存该数据 从高德查询
// if (btsLocation == null) {
// JSONObject locationJson = LocationUtil
// .translateBts(datas[13], datas[14], datas[17], datas[18], Integer.valueOf(datas[21]) * 2 - 113);
// String[] location = locationJson.getStr("location").split(",");
// btsLocation = new BtsLocation(Double.valueOf(location[0]), Double.valueOf(location[1]), datas[13],
// datas[14], datas[17], datas[18], Integer.valueOf(datas[21]) * 2 - 113);
// btsLocation.setAdcode(locationJson.getStr("adcode"));
// btsLocationRespository.insert(btsLocation);
// }
// // 缓存两小时基站数据
// redisService.set(
// CachePrefixConstant.LOCATION_BTS + StrUtil.join(",", datas[13], datas[14], datas[17], datas[18]),
// btsLocation, 7200L);
// }
// position.setLng(btsLocation.getLng());
// position.setLat(btsLocation.getLat());
// if (!redisService.hasKey(CachePrefixConstant.DEVICE_CARD_WEATHER + position.getImei())) {
// // 天气数据12小时有效
// operationService.weather(position.getImei(), btsLocation.getAdcode());
// redisService.set(CachePrefixConstant.DEVICE_CARD_WEATHER + position.getImei(), 43200L);
// }
// afterLocationDeal(position);
// }
//
// public void dealDeviceKa(String[] datas) {
// EduStudentCardLocation position = new EduStudentCardLocation();
// position.setId(snowFlake.nextId());
// position.setCreateDate(LocalDateTime.now());
// position.setVendor(datas[0]);
// position.setImei(datas[1]);
// position.setType(1);
// position.setSignal(Integer.valueOf(datas[4]));
// position.setSv(Integer.valueOf(datas[5]));
// position.setBat(Integer.valueOf(datas[6]));
// position.setDeviceTime(dealDateTime(datas[datas.length - 2], datas[3]));
// position.setStatus(datas[datas.length - 1]);
// // 查询经纬度数据
// BtsLocation btsLocation = null;
// // 基站数据是否缓存
// Boolean locationCache = redisService
// .hasKey(CachePrefixConstant.LOCATION_BTS + StrUtil.join(",", datas[7], datas[8], datas[11], datas[12]));
// if (locationCache) {
// btsLocation = (BtsLocation) redisService
// .get(CachePrefixConstant.LOCATION_BTS + StrUtil.join(",", datas[7], datas[8], datas[11], datas[12]));
// } else {
// btsLocation = btsLocationRespository
// .findByMccAndMncAndLacAndCid(datas[7], datas[8], datas[11], datas[12]);
// // 未保存该数据 从高德查询
// if (btsLocation == null) {
// JSONObject locationJson = LocationUtil
// .translateBts(datas[7], datas[8], datas[11], datas[12], Integer.valueOf(datas[13]) * 2 - 113);
// String[] location = locationJson.getStr("location").split(",");
// btsLocation = new BtsLocation(Double.valueOf(location[0]), Double.valueOf(location[1]), datas[7],
// datas[8], datas[11], datas[12], Integer.valueOf(datas[13]) * 2 - 113);
// btsLocation.setAdcode(locationJson.getStr("adcode"));
// btsLocationRespository.insert(btsLocation);
// }
// // 缓存两小时基站数据
// redisService.set(
// CachePrefixConstant.LOCATION_BTS + StrUtil.join(",", datas[7], datas[8], datas[11], datas[12]),
// btsLocation, 7200L);
// }
// position.setLng(btsLocation.getLng());
// position.setLat(btsLocation.getLat());
// if (!redisService.hasKey(CachePrefixConstant.DEVICE_CARD_WEATHER + position.getImei())) {
// // 天气数据12小时有效
// operationService.weather(position.getImei(), btsLocation.getAdcode());
// redisService.set(CachePrefixConstant.DEVICE_CARD_WEATHER + position.getImei(), 43200L);
// }
// afterLocationDeal(position);
// }
//
// @Override
// public void dealDeviceWifi(String[] datas) {
// EduStudentCardLocation position = new EduStudentCardLocation();
// position.setId(snowFlake.nextId());
// position.setCreateDate(LocalDateTime.now());
// position.setVendor(datas[0]);
// position.setImei(datas[1]);
// position.setType(2);
// position.setSignal(Integer.valueOf(datas[4]));
// position.setSv(Integer.valueOf(datas[5]));
// position.setBat(Integer.valueOf(datas[6]));
// position.setDeviceTime(dealDateTime(datas[datas.length - 2], datas[3]));
// position.setStatus(datas[datas.length - 1]);
// // 查询经纬度数据
// WifimacLocation wifimacLocation = null;
// Integer wifiNum = Integer.valueOf(datas[7]);
// List<String> mac = CollUtil.newArrayList("", "", "", "", "", "");
// List<String> rssi = CollUtil.newArrayList("", "", "", "", "", "");
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < wifiNum; i++) {
// mac.set(i, datas[8 + 2 * i]);
// rssi.set(i, datas[9 + 2 * i]);
// sb.append(mac.get(i))
// .append(",")
// .append(rssi.get(i))
// .append("|");
// }
// wifimacLocation = wifimacLocationRespository
// .findByMac1InAndMac2InAndMac3InAndMac4InAndMac5InAndMac6In(mac, mac, mac, mac, mac, mac);
// // 未保存该数据 从高德查询
// if (wifimacLocation == null) {
// JSONObject locationJson = LocationUtil.translateWifimac(sb.substring(0, sb.length() - 1));
// String[] location = locationJson.getStr("location").split(",");
// // 存入mongo
// wifimacLocation = new WifimacLocation(Double.valueOf(location[0]), Double.valueOf(location[1]), mac.get(0),
// mac.get(1), mac.get(2), mac.get(3), mac.get(4), mac.get(5));
// wifimacLocationRespository.insert(wifimacLocation);
// }
// position.setLng(wifimacLocation.getLng());
// position.setLat(wifimacLocation.getLat());
// afterLocationDeal(position);
// }
//
// private void afterLocationDeal(EduStudentCardLocation location) {
// // 存入es
// eduStudentCardLocationRespository.save(location);
// // 缓存定位数据
// LocationVO locationVO = new LocationVO();
// BeanUtils.copyProperties(location, locationVO);
// redisService.hset(CachePrefixConstant.DEVICE_CARD_LATEST_LOCATION, location.getImei(), locationVO);
// DeviceReportDTO reportMsg = new DeviceReportDTO();
// BeanUtils.copyProperties(location, reportMsg);
// // 消息通知
// rabbitUtil.convertAndSendMsg(RabbitConstant.CARD_EXCHANGE, RabbitConstant.CARD_LOCATION_KEY, reportMsg);
// }
//
// /**
// * @param type 1-东经/北纬,-1-西经/南纬
// * @param data
// * @return
// */
// private static Double positionTrans(Integer type, String data) {
// int base = Integer.parseInt(data.substring(0, data.indexOf(".") - 2));
// double v = Double.valueOf(data.substring(data.indexOf(".") - 2)) / 60;
// return (base + v) * type;
// }
//
// private static LocalDateTime dealDateTime(String date, String time) {
// if (date.length() == 5) {
// date = "0" + date;
// }
// if (time.length() == 5) {
// time = "0" + time;
// }
// date = date.substring(0, 4) + "20" + date.substring(4);
// return LocalDateTime.parse(date + time, DateTimeFormatter.ofPattern("ddMMyyyyHHmmss"));
// }
//}
@@ -0,0 +1,327 @@
//package com.yida.data.server.service.impl;
//
//import cc.mrbird.febs.common.redis.service.RedisService;
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.util.NumberUtil;
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.json.JSONObject;
//import com.yida.data.common.core.entity.constant.CachePrefixConstant;
//import com.yida.data.common.core.entity.constant.LockPrefixConstant;
//import com.yida.data.common.core.utils.Asserts;
//import com.yida.data.common.core.utils.LocationUtil;
//import com.yida.data.server.constants.CardConstants;
//import com.yida.data.server.constants.MsgType;
//import com.yida.data.server.dto.DisturbDTO;
//import com.yida.data.server.dto.FenceDTO;
//import com.yida.data.server.dto.WhiteListDTO;
//import com.yida.data.server.service.OperationService;
//import com.yida.data.server.utils.ChannelUtil;
//import io.netty.channel.Channel;
//import java.time.LocalTime;
//import java.time.format.DateTimeFormatter;
//import java.util.ArrayList;
//import java.util.List;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//
//@Slf4j
//@Service
//@RequiredArgsConstructor
//public class OperationServiceImpl implements OperationService {
//
// private final RedisService redisService;
//
// @Override
// public void getLocation(String imei) {
//
// }
//
// @Override
// public void whiteList(WhiteListDTO dto) {
// Asserts.isTrue(redisService.hasKey(CachePrefixConstant.DEVICE_CARD_ONLINE + dto.getImei()), "设备不在线");
// String vendor = redisService.hget(CachePrefixConstant.DEVICE_CARD_IMEI_VENDOR, dto.getImei()).toString();
// List<String> cmd = new ArrayList<>();
// cmd.add(vendor);
// cmd.add(dto.getImei());
// cmd.add(MsgType.WHITE_ALL.getValue());
// cmd.add(LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")));
// for (int i = 1; i <= 20; i++) {
// cmd.add(String.valueOf(i));
// cmd.add(dto.getMobiles().size() >= i ? dto.getMobiles().get(i - 1) : "");
// cmd.add(String.valueOf(1));
// }
// sendMsg(dto.getImei(), cmd);
// }
//
// @Override
// public void fenceSwitch(String imei, Integer type) {
// Asserts.isTrue(redisService.hasKey(CachePrefixConstant.DEVICE_CARD_ONLINE + imei), "设备不在线");
// String vendor = redisService.hget(CachePrefixConstant.DEVICE_CARD_IMEI_VENDOR, imei).toString();
// List<String> cmd = new ArrayList<>();
// cmd.add(vendor);
// cmd.add(imei);
// cmd.add(MsgType.FENCE_SWITCH.getValue());
// cmd.add(LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")));
// cmd.add(type.toString());
// sendMsg(imei, cmd);
// }
//
// @Override
// public void fence(FenceDTO dto) {
// if (dto.getType() == 0) {
// Asserts.isTrue(redisService.hasKey(CachePrefixConstant.DEVICE_CARD_ONLINE + dto.getImei()), "设备不在线");
// String vendor = redisService.hget(CachePrefixConstant.DEVICE_CARD_IMEI_VENDOR, dto.getImei()).toString();
// List<String> cmd = new ArrayList<>();
// cmd.add(vendor);
// cmd.add(dto.getImei());
// cmd.add(MsgType.FENCE.getValue());
// cmd.add(LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")));
// cmd.add(dto.getId().toString());
// cmd.add(transferPosition(dto.getLat().get(0)));
// cmd.add(transferPosition(dto.getLng().get(0)));
// cmd.add(dto.getRadius().toString());
// sendMsg(dto.getImei(), cmd);
// }
// }
//
// @Override
// public void disturbTime(DisturbDTO dto) {
// Asserts.isTrue(redisService.hasKey(CachePrefixConstant.DEVICE_CARD_ONLINE + dto.getImei()), "设备不在线");
// String vendor = redisService.hget(CachePrefixConstant.DEVICE_CARD_IMEI_VENDOR, dto.getImei()).toString();
// List<String> cmd = new ArrayList<>();
// cmd.add(vendor);
// cmd.add(dto.getImei());
// cmd.add(MsgType.DISTURB_TIME.getValue());
// cmd.add(LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")));
// for (int i = 0; i < dto.getNum(); i++) {
// cmd.add(String.valueOf(i + 1));
// StringBuilder time = new StringBuilder();
// time.append(dto.getStartTime().get(i).format(DateTimeFormatter.ofPattern("HHmm")))
// .append(dto.getEndTime().get(i).format(DateTimeFormatter.ofPattern("HHmm")));
// String week = dto.getWeekFlag().get(i);
// for (int j = 0; j < 7; j++) {
// time.append(String.valueOf(j + 1))
// .append(week.charAt(j));
// }
// cmd.add(time.toString());
// }
// sendMsg(dto.getImei(), cmd);
// }
//
// @Override
// public void disturbSwitch(String imei, Integer type) {
// Asserts.isTrue(redisService.hasKey(CachePrefixConstant.DEVICE_CARD_ONLINE + imei), "设备不在线");
// String vendor = redisService.hget(CachePrefixConstant.DEVICE_CARD_IMEI_VENDOR, imei).toString();
// List<String> cmd = new ArrayList<>();
// cmd.add(vendor);
// cmd.add(imei);
// cmd.add(MsgType.DISTURB_SWITCH.getValue());
// cmd.add(LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")));
// cmd.add(type.toString());
// sendMsg(imei, cmd);
// }
//
// @Override
// public void nowLocation(String imei) {
// Asserts.isTrue(redisService.hasKey(CachePrefixConstant.DEVICE_CARD_ONLINE + imei), "设备不在线");
// String vendor = redisService.hget(CachePrefixConstant.DEVICE_CARD_IMEI_VENDOR, imei).toString();
// List<String> cmd = new ArrayList<>();
// cmd.add(vendor);
// cmd.add(imei);
// cmd.add(MsgType.LOCATION.getValue());
// cmd.add(LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")));
// sendMsg(imei, cmd);
// }
//
// @Override
// public void weather(String imei, String adCode) {
// Asserts.isTrue(redisService.hasKey(CachePrefixConstant.DEVICE_CARD_ONLINE + imei), "设备不在线");
// String vendor = redisService.hget(CachePrefixConstant.DEVICE_CARD_IMEI_VENDOR, imei).toString();
// List<String> cmd = new ArrayList<>();
// cmd.add(vendor);
// cmd.add(imei);
// cmd.add(MsgType.WEATHER.getValue());
// cmd.add(LocalTime.now().format(DateTimeFormatter.ofPattern("HHmmss")));
// // 天气数据是否存在
// JSONObject weather = (JSONObject) redisService.get(CachePrefixConstant.DEVICE_CARD_CITY_WEATHER + adCode);
// if (weather == null) {
// weather = LocationUtil.getWeather(adCode);
// redisService.set(CachePrefixConstant.DEVICE_CARD_CITY_WEATHER + adCode, weather, 43200L);
// }
// // 天气状况
// String weatherStr = weatherToCode(weather.getStr("weather"));
// if (StrUtil.isBlank(weatherStr)) {
// return;
// }
// // 风向
// String weatherDir = weatherDirToCode(weather.getStr("winddirection"));
// // 风力
// String weatherPower = weatherPowerToCode(weather.getStr("windpower"));
// if (StrUtil.isBlank(weatherStr) || StrUtil.isBlank(weatherDir) || StrUtil.isBlank(weatherPower)) {
// return;
// }
// //气温
// String temp = weather.getStr("temperature");
// cmd.add(weatherStr);
// cmd.add(temp);
// cmd.add(weatherDir);
// cmd.add(weatherPower);
// sendMsg(imei, cmd);
// }
//
// @Override
// public void cmd(String imei, String cmd) {
// cmd = CardConstants.START_WITH + cmd + CardConstants.END_WITH;
// Channel channel = ChannelUtil.getChannel(imei);
// Asserts.isNotNull(channel, "设备不在线");
// redisService.falseLock(LockPrefixConstant.CARD_CMD_LOCK + imei);
// channel.writeAndFlush(cmd);
// log.info("发送指令::[{}]", cmd);
// redisService.falseLock(LockPrefixConstant.CARD_CMD_LOCK + imei);
// redisService.falseUnLock(LockPrefixConstant.CARD_CMD_LOCK + imei);
// }
//
// private void sendMsg(String imei, List<String> msg) {
// String cmd = CardConstants.START_WITH + CollUtil.join(msg, ",") + CardConstants.END_WITH;
// Channel channel = ChannelUtil.getChannel(imei);
// Asserts.isNotNull(channel, "设备不在线");
// redisService.falseLock(LockPrefixConstant.CARD_CMD_LOCK + imei);
// channel.writeAndFlush(cmd);
// log.info("发送指令::[{}]", cmd);
// redisService.falseLock(LockPrefixConstant.CARD_CMD_LOCK + imei);
// redisService.falseUnLock(LockPrefixConstant.CARD_CMD_LOCK + imei);
// }
//
// private String transferPosition(Double data) {
// double m = data.intValue();
// m += (data - m) * 60;
// return NumberUtil.decimalFormat("#.0000", m);
// }
//
// private String weatherToCode(String weather) {
// // 晴
// if (weather.equals("晴")) {
// return "0";
// } else if (weather.contains("云")) {
// return "1";
// } else if (weather.equals("阴")) {
// return "2";
// } else if (weather.equals("阵雨")) {
// return "3";
// } else if (weather.equals("雷阵雨")) {
// return "4";
// } else if (weather.equals("雷阵雨并伴有冰雹")) {
// return "5";
// } else if (weather.contains("雨") && weather.contains("雪")) {
// return "6";
// } else if (weather.equals("小雨")) {
// return "7";
// } else if (weather.equals("中雨")) {
// return "8";
// } else if (weather.equals("大雨")) {
// return "9";
// } else if (weather.equals("暴雨")) {
// return "10";
// } else if (weather.equals("大暴雨")) {
// return "11";
// } else if (weather.equals("特大暴雨")) {
// return "12";
// } else if (weather.equals("阵雪")) {
// return "13";
// } else if (weather.equals("小雪")) {
// return "14";
// } else if (weather.equals("中雪")) {
// return "15";
// } else if (weather.equals("大雪")) {
// return "16";
// } else if (weather.equals("暴雪")) {
// return "17";
// } else if (weather.equals("雾")) {
// return "18";
// } else if (weather.equals("冻雨")) {
// return "19";
// } else if (weather.equals("沙尘暴")) {
// return "20";
// } else if (weather.equals("小雨-中雨")) {
// return "21";
// } else if (weather.equals("中雨-大雨")) {
// return "22";
// } else if (weather.equals("大雨-暴雨 ")) {
// return "23";
// } else if (weather.equals("暴雨-大暴雨")) {
// return "24";
// } else if (weather.equals("大暴雨-特大暴雨")) {
// return "25";
// } else if (weather.equals("小雪-中雪")) {
// return "26";
// } else if (weather.equals("中雪-大雪")) {
// return "27";
// } else if (weather.equals("大雪-暴雪")) {
// return "28";
// } else if (weather.equals("浮尘")) {
// return "29";
// } else if (weather.equals("扬沙")) {
// return "30";
// } else if (weather.equals("强沙尘暴")) {
// return "31";
// } else if (weather.equals("龙卷风")) {
// return "33";
// } else if (weather.equals("轻雾")) {
// return "35";
// } else if (weather.equals("霾")) {
// return "53";
// }
// return null;
// }
//
// private String weatherDirToCode(String dir) {
// if (dir.equals("无风向")) {
// return "0";
// } else if (dir.equals("东北")) {
// return "1";
// } else if (dir.equals("东")) {
// return "2";
// } else if (dir.equals("东南")) {
// return "3";
// } else if (dir.equals("南")) {
// return "4";
// } else if (dir.equals("西南")) {
// return "5";
// } else if (dir.equals("西")) {
// return "6";
// } else if (dir.equals("西北")) {
// return "7";
// } else if (dir.equals("北")) {
// return "8";
// } else if (dir.equals("旋转不定")) {
// return "9";
// }
// return null;
// }
//
// private String weatherPowerToCode(String power) {
// if (power.equals("≤3")) {
// return "0";
// } else if (power.equals("4")) {
// return "1";
// } else if (power.equals("5")) {
// return "2";
// } else if (power.equals("6")) {
// return "3";
// } else if (power.equals("7")) {
// return "4";
// } else if (power.equals("8")) {
// return "5";
// } else if (power.equals("9")) {
// return "6";
// } else if (power.equals("10")) {
// return "7";
// } else if (power.equals("11")) {
// return "8";
// } else if (power.equals("12")) {
// return "9";
// }
// return null;
// }
//}
@@ -0,0 +1,222 @@
package com.yida.data.server.service.impl;
import cc.mrbird.febs.common.redis.service.RedisService;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.crypto.SecureUtil;
import com.yida.data.common.core.entity.card.EduStudentCardLocation;
import com.yida.data.common.core.entity.constant.CachePrefixConstant;
import com.yida.data.device.dto.studentCard.CardMsgDTO;
import com.yida.data.rabbit.constant.RabbitConstant;
import com.yida.data.rabbit.util.RabbitUtil;
import com.yida.data.server.dto._810ABaseMsg;
import com.yida.data.server.dto._810ADeviceStaticDTO;
import com.yida.data.server.dto._810ALocationDTO;
import com.yida.data.server.dto._810ALowBatDTO;
import com.yida.data.server.dto._810ARiskAreaDTO;
import com.yida.data.server.dto._810AStepDTO;
import com.yida.data.server.repository.EduStudentCardLocationRespository;
import com.yida.data.server.service._810ADataService;
import com.yida.data.server.vo._810AResVO;
import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.Locale;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
@Slf4j
public class _810ADataServiceImpl implements _810ADataService {
private final EduStudentCardLocationRespository eduStudentCardLocationRespository;
private final RedisService redisService;
private final RabbitUtil rabbitUtil;
private final static Snowflake ID_GENERATOR = new Snowflake(1, 1);
private final static String SECRET = "EDC9411E58C1D7B011A6DCE6985F0ACE";
@Override
public _810AResVO dealLocation(_810ALocationDTO dto) {
log.info("接收定位数据:[{}],key:[{}]", dto, dto.getKEY());
EduStudentCardLocation location = new EduStudentCardLocation();
location.setId(ID_GENERATOR.nextId());
location.setCreateDate(LocalDateTime.now());
location.setType(dto.getTYPE());
location.setLng(dto.getLO());
location.setLat(dto.getLA());
location.setImei(dto.getDEVICENUM());
location.setBat(dto.getBAT());
location.setGsm(dto.getGSM());
location.setGps(dto.getGPS());
location.setDeviceTime(dto.getLOCTIME());
// 异或取反
location.setOnline(dto.getISONLINE() ^ 1);
if (location.getOnline() == 0) {
redisService.set(CachePrefixConstant.DEVICE_CARD_ONLINE + location.getImei(), 0, 300L);
}
// 存入es
eduStudentCardLocationRespository.save(location);
// 消息通知
CardMsgDTO reportMsg = new CardMsgDTO();
BeanUtils.copyProperties(location, reportMsg);
reportMsg.setAddress(dto.getPOSDESC());
// 消息类型
reportMsg.setMsgType(CardMsgDTO.LOCATION);
rabbitUtil.convertAndSendMsg(RabbitConstant.CARD_EXCHANGE, RabbitConstant.CARD_810A_MSG_KEY, reportMsg);
// 验签
try {
// this.signVerify(dto);
} catch (Exception e) {
log.error("验签失败,", e);
}
return null;
}
@Override
public _810AResVO riskArea(_810ARiskAreaDTO dto) {
log.info("接收危险区域数据:[{}],key:[{}]", dto, dto.getKEY());
EduStudentCardLocation location = new EduStudentCardLocation();
location.setId(ID_GENERATOR.nextId());
location.setCreateDate(LocalDateTime.now());
location.setType(dto.getTYPE());
location.setLng(dto.getLO());
location.setLat(dto.getLA());
location.setImei(dto.getDEVICENUM());
location.setBat(dto.getBAT());
location.setGsm(dto.getGSM());
location.setGps(dto.getGPS());
location.setDeviceTime(dto.getLOCTIME());
// 异或取反
location.setOnline(0);
if (location.getOnline() == 0) {
redisService.set(CachePrefixConstant.DEVICE_CARD_ONLINE + location.getImei(), 0, 300L);
}
// 存入es
eduStudentCardLocationRespository.save(location);
// 消息通知
CardMsgDTO reportMsg = new CardMsgDTO();
BeanUtils.copyProperties(location, reportMsg);
reportMsg.setAddress(dto.getPOSDESC());
reportMsg.setRemark(dto.getREMARK());
// 消息类型
reportMsg.setMsgType(CardMsgDTO.RISK_AREA);
rabbitUtil.convertAndSendMsg(RabbitConstant.CARD_EXCHANGE, RabbitConstant.CARD_810A_MSG_KEY, reportMsg);
// 验签
try {
// this.signVerify(dto);
} catch (Exception e) {
log.error("验签失败,", e);
}
return null;
}
@Override
public _810AResVO stepPush(_810AStepDTO dto) {
log.info("接收步数:[{}],key:[{}]", dto, dto.getKEY());
// 消息通知
CardMsgDTO reportMsg = new CardMsgDTO();
reportMsg.setStep(dto.getSTEPS());
reportMsg.setImei(dto.getDEVICENUM());
reportMsg.setDeviceTime(dto.getTIME());
reportMsg.setMsgType(CardMsgDTO.STEP);
rabbitUtil.convertAndSendMsg(RabbitConstant.CARD_EXCHANGE, RabbitConstant.CARD_810A_MSG_KEY, reportMsg);
return null;
}
@Override
public _810AResVO lowBat(_810ALowBatDTO dto) {
log.info("接收低电量数据:[{}],key:[{}]", dto, dto.getKEY());
EduStudentCardLocation location = new EduStudentCardLocation();
location.setId(ID_GENERATOR.nextId());
location.setCreateDate(LocalDateTime.now());
location.setType(dto.getTYPE());
location.setLng(dto.getLO());
location.setLat(dto.getLA());
location.setImei(dto.getDEVICENUM());
location.setBat(dto.getBAT());
location.setGsm(dto.getGSM());
location.setGps(dto.getGPS());
location.setDeviceTime(dto.getLOCTIME());
// 异或取反
location.setOnline(dto.getISONLINE() ^ 1);
if (location.getOnline() == 0) {
redisService.set(CachePrefixConstant.DEVICE_CARD_ONLINE + location.getImei(), 0, 300L);
}
// 存入es
eduStudentCardLocationRespository.save(location);
// 消息通知
CardMsgDTO reportMsg = new CardMsgDTO();
BeanUtils.copyProperties(location, reportMsg);
reportMsg.setAddress(dto.getPOSDESC());
// 消息类型
reportMsg.setMsgType(CardMsgDTO.LOW_BAT);
rabbitUtil.convertAndSendMsg(RabbitConstant.CARD_EXCHANGE, RabbitConstant.CARD_810A_MSG_KEY, reportMsg);
// 验签
try {
// this.signVerify(dto);
} catch (Exception e) {
log.error("验签失败,", e);
}
return null;
}
@Override
public _810AResVO deviceStatic(_810ADeviceStaticDTO dto) {
log.info("接收设备脱落数据:[{}],key:[{}]", dto, dto.getKEY());
EduStudentCardLocation location = new EduStudentCardLocation();
location.setId(ID_GENERATOR.nextId());
location.setCreateDate(LocalDateTime.now());
location.setType(dto.getTYPE());
location.setLng(dto.getLO());
location.setLat(dto.getLA());
location.setImei(dto.getDEVICENUM());
location.setBat(dto.getBAT());
location.setGsm(dto.getGSM());
location.setGps(dto.getGPS());
location.setDeviceTime(dto.getLOCTIME());
// 异或取反
location.setOnline(dto.getISONLINE() ^ 1);
if (location.getOnline() == 0) {
redisService.set(CachePrefixConstant.DEVICE_CARD_ONLINE + location.getImei(), 0, 300L);
}
// 存入es
eduStudentCardLocationRespository.save(location);
// 消息通知
CardMsgDTO reportMsg = new CardMsgDTO();
BeanUtils.copyProperties(location, reportMsg);
reportMsg.setAddress(dto.getPOSDESC());
// 消息类型
reportMsg.setMsgType(CardMsgDTO.DEVICE_STATIC);
rabbitUtil.convertAndSendMsg(RabbitConstant.CARD_EXCHANGE, RabbitConstant.CARD_810A_MSG_KEY, reportMsg);
// 验签
try {
// this.signVerify(dto);
} catch (Exception e) {
log.error("验签失败,", e);
}
return null;
}
private void signVerify(_810ABaseMsg param) {
StringBuilder builder = new StringBuilder().append(SECRET).append(param.getTIMESTAMP());
Class<?> targetClass = param.getClass();
Field[] fields = targetClass.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
try {
builder.append(field.getName())
.append("=")
.append(field.getType().equals(LocalDateTime.class) ? LocalDateTimeUtil
.format((LocalDateTime) field.get(param), "yyyy-MM-dd HH:mm:ss") : String.valueOf(field.get(param)));
} catch (Exception e) {
log.error("810A验签失败", e);
}
}
log.info("验签字符串:[{}]", builder);
String sign = SecureUtil.md5().digestHex(builder.toString()).toUpperCase(Locale.ROOT);
log.info("计算出的sign:[{}]", sign);
log.info("接收的sign:[{}]", param.getSIGN());
}
}
@@ -0,0 +1,22 @@
package com.yida.data.server.utils;
import cc.mrbird.febs.common.redis.service.RedisService;
import java.nio.channels.Channel;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class UserUtil {
private final static String USER_LIST = "device.card.810a.tcp.list";
private final RedisService redisService;
public void addUser(String cardId, Channel channel) {
redisService.hset(USER_LIST, cardId, channel);
}
public void remove(String cardId) {
redisService.hdel(USER_LIST, cardId);
}
}
@@ -0,0 +1,30 @@
spring:
profiles:
active: "@env-name@"
application:
name: Edu-Card-Server
cloud:
nacos:
config:
server-addr: ${nacos.url}
group: DEFAULT_GROUP
prefix: edu-card-server
file-extension: yaml
refreshable-dataids:
discovery:
server-addr: ${nacos.url}
logging:
level:
org:
springframework:
boot:
actuate:
endpoint:
EndpointId: error
com:
alibaba:
cloud:
nacos:
client:
NacosPropertySourceBuilder: error