netty-确定客户端和服务端编解码工具

This commit is contained in:
2023-08-22 09:48:23 +08:00
parent eaccee2a9b
commit 86fd226c84
48 changed files with 235 additions and 2786 deletions

View File

@@ -1,6 +1,5 @@
package com.sv.mapper;
import com.common.DeviceDTO;
import com.enums.DeviceType;
import com.sv.entity.Device;
import org.apache.ibatis.annotations.Param;
@@ -67,34 +66,33 @@ public interface DeviceMapper {
/**
* 更新设备状态为 0 - 未连接
*/
void offline(@Param("venueId") Integer venueId,@Param("deviceName") String deviceName,@Param("deviceType")DeviceType deviceType);
void offline(@Param("venueId") Integer venueId,@Param("deviceName") String deviceName);
/**
* 更新设备状态为 2 - 连接成功
*/
void online(@Param("venueId") Integer venueId, @Param("deviceName") String deviceName, @Param("deviceType")DeviceType deviceType);
void online(@Param("venueId") Integer venueId, @Param("deviceName") String deviceName);
Integer checkDevice(@Param("deviceName") String deviceName,@Param("venueId") Integer venueId, @Param("deviceType") DeviceType deviceType);
Integer checkDevice(@Param("deviceName") String deviceName,@Param("venueId") Integer venueId);
/**
* 根据记录找设备
* @param deviceName
* @param venueId
* @param deviceType
* @return
*/
Device findByDevice(@Param("deviceName") String deviceName,@Param("venueId") Integer venueId,@Param("deviceType") DeviceType deviceType);
Device findByDevice(@Param("deviceName") String deviceName,@Param("venueId") Integer venueId);
/**
* 设备绑定正在扫码的用户
*/
void bindMember(@Param("bindMember") Integer bindMember,@Param("venueId") Integer venueId,@Param("deviceName") String deviceName,@Param("deviceType")DeviceType deviceType);
void bindMember(@Param("bindMember") Integer bindMember,@Param("venueId") Integer venueId,@Param("deviceName") String deviceName);
/**
* 更新设备状态为 2 - 连接成功
*/
void unBindMember(@Param("venueId") Integer venueId, @Param("deviceName") String deviceName, @Param("deviceType")DeviceType deviceType);
void unBindMember(@Param("venueId") Integer venueId, @Param("deviceName") String deviceName);
}
}

View File

@@ -1,12 +1,10 @@
package com.sv.service.api;
import com.enums.DeviceType;
import com.enums.VenueTypeEnum;
import com.sv.entity.Device;
import com.sv.entity.Venue;
import com.sv.mapper.DeviceMapper;
import com.sv.mapper.VenueMapper;
import com.sv.service.api.util.DateUtilCard;
import com.ydd.framework.core.exception.ServiceException;
import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger;
@@ -20,22 +18,22 @@ import java.util.Date;
/**
* 小程序扫二维码处理
*/
//@Service("qrCodeService")
//@Transactional(readOnly = true)
@Service("qrCodeService")
@Transactional(readOnly = true)
public class QRCodeService {
private final Logger logger = LoggerFactory.getLogger(ProtocolService.class);
// @Resource
@Resource
private VenueMapper venueMapper;
// @Resource
@Resource
private DeviceMapper deviceMapper;
public Venue initEnter(Integer venueId,String deviceName,DeviceType deviceType,Integer memberId) throws ServiceException{
Integer integer = deviceMapper.checkDevice(deviceName, venueId,deviceType);
public Venue initEnter(Integer venueId,String deviceName,Integer memberId) throws ServiceException{
Integer integer = deviceMapper.checkDevice(deviceName, venueId);
if (integer != 1){
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.DEVICE_ERROR);
}
Device device = deviceMapper.findByDevice(deviceName, venueId, deviceType);
Device device = deviceMapper.findByDevice(deviceName, venueId);
if (device == null){
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.DEVICE_ERROR);
}else {
@@ -64,13 +62,13 @@ public class QRCodeService {
}
@Transactional
public void bindMember(Integer venueId,String deviceName,DeviceType deviceType,Integer memberId){
deviceMapper.bindMember(memberId, venueId, deviceName, deviceType);
public void bindMember(Integer venueId,String deviceName,Integer memberId){
deviceMapper.bindMember(memberId, venueId, deviceName);
}
@Transactional
public void unBindMember(Integer venueId,String deviceName,DeviceType deviceType){
deviceMapper.unBindMember(venueId, deviceName, deviceType);
public void unBindMember(Integer venueId,String deviceName){
deviceMapper.unBindMember(venueId, deviceName);
}
}

View File

@@ -409,7 +409,7 @@ public class VenueService extends BaseServiceImpl {
@Transactional
public synchronized boolean qrCodeEnterVenue(Integer memberId, String deviceName,Integer venueId,Venue venue) {
synchronized (("enter" + memberId).intern()) {
Device device = deviceService.findByDevice(deviceName,venueId, DeviceType.ENTER);
Device device = deviceService.findByDevice(deviceName,venueId);
// 查询当前时间内,场馆对应的价格(健身房没有价格)
if (venue.getStatus().intValue() == 1) {
logger.info(venue.getName() + "被禁用,入场失败");

View File

@@ -2,7 +2,6 @@ package com.sv.service.oms;
import com.common.DeviceDTO;
import com.enums.DeviceStatusEnum;
import com.enums.DeviceType;
import com.github.pagehelper.PageHelper;
import com.sv.entity.Device;
import com.sv.exception.oms.OmsException;
@@ -48,7 +47,7 @@ public class DeviceService extends BaseServiceImpl {
*
* @param device 门禁设备
*/
@Transactional
public void save(Device device) {
if(deviceMapper.countByStream(device.getStream(),device.getId()) > 0){
@@ -68,7 +67,7 @@ public class DeviceService extends BaseServiceImpl {
*
* @param device 门禁设备
*/
@Transactional
public void update(Device device) {
deviceMapper.update(device);
@@ -80,7 +79,7 @@ public class DeviceService extends BaseServiceImpl {
* @param id 编号
* @return 删除数量
*/
@Transactional
public Integer delete(Integer id) {
if (id == null || id <= 0) {
@@ -95,7 +94,7 @@ public class DeviceService extends BaseServiceImpl {
* @param ids 编号数组
* @return 删除数量
*/
@Transactional
public Integer deleteByIds(Integer[] ids) {
if (ids == null || ids.length == 0) {
@@ -120,7 +119,7 @@ public class DeviceService extends BaseServiceImpl {
* @param pagination 分页信息
* @return 分页结果
*/
public Pagination findPage(Pagination pagination) {
PageHelper.startPage(pagination.getPage(), pagination.getPageSize());
pagination.setQueryResult(deviceMapper.findAllDTO());
@@ -135,25 +134,24 @@ public class DeviceService extends BaseServiceImpl {
* 设备连接断开
*/
@Transactional
public void offline(String deviceName, Integer venueId,DeviceType deviceType){
deviceMapper.offline(venueId,deviceName,deviceType);
public void offline(String deviceName, Integer venueId){
deviceMapper.offline(venueId,deviceName);
}
/**
* 新的设备注册的逻辑
*/
@Transactional
public void online(String deviceName,Integer venueId,DeviceType deviceType,Integer venueType,String deviceIp){
public void online(String deviceName,Integer venueId,Integer venueType,String deviceIp){
Device device = new Device();
device.setVenueId(venueId);
device.setVenueType(venueType);
device.setName(deviceName);
device.setStatus(DeviceStatusEnum.ONLINE.value);
device.setStream(deviceIp);
device.setDeviceType(deviceType);
if(deviceMapper.checkDevice(deviceName,venueId,deviceType) > 0){
if(deviceMapper.checkDevice(deviceName,venueId) > 0){
logger.info(deviceName + venueId + "设备已存在");
deviceMapper.online(venueId, deviceName,deviceType);
deviceMapper.online(venueId, deviceName);
}else {
logger.info("落地客户端信息clientId = " + deviceIp + "&deviceName = " + deviceName + "&venueId = " + venueId);
deviceMapper.insert(device);
@@ -192,8 +190,8 @@ public class DeviceService extends BaseServiceImpl {
/**
* find by DeviceName
*/
public Device findByDevice(String deviceName, Integer venueId, DeviceType deviceType){
return deviceMapper.findByDevice(deviceName,venueId,deviceType);
public Device findByDevice(String deviceName, Integer venueId){
return deviceMapper.findByDevice(deviceName,venueId);
}
}