api-二维码扫码锁定(新增字段绑定用户)

This commit is contained in:
limqhz
2020-08-30 22:49:19 +08:00
parent dc26c2b55c
commit 223906117c
10 changed files with 125 additions and 12 deletions

View File

@@ -85,4 +85,16 @@ public interface DeviceMapper {
* @return
*/
Device findByDevice(@Param("deviceName") String deviceName,@Param("venueId") Integer venueId,@Param("deviceType") DeviceType deviceType);
/**
* 设备绑定正在扫码的用户
*/
void bindMember(@Param("bindMember") Integer bindMember,@Param("venueId") Integer venueId,@Param("deviceName") String deviceName,@Param("deviceType")DeviceType deviceType);
/**
* 更新设备状态为 2 - 连接成功
*/
void unBindMember(@Param("venueId") Integer venueId, @Param("deviceName") String deviceName, @Param("deviceType")DeviceType deviceType);
}

View File

@@ -2,16 +2,20 @@ 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;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
/**
* 小程序扫二维码处理
@@ -26,11 +30,29 @@ public class QRCodeService {
@Resource
private DeviceMapper deviceMapper;
public Venue initEnter(Integer venueId,String deviceName,DeviceType deviceType) {
public Venue initEnter(Integer venueId,String deviceName,DeviceType deviceType,Integer memberId) throws ServiceException{
Integer integer = deviceMapper.checkDevice(deviceName, venueId,deviceType);
if (integer != 1){
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.DEVICE_ERROR);
}
Device device = deviceMapper.findByDevice(deviceName, venueId, deviceType);
if (device == null){
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.DEVICE_ERROR);
}else {
Date bindTime = device.getBindTime();
Integer bindMember = device.getBindMember();
if (bindTime != null && bindMember != null){
Date now = new Date();
Date endTime = DateUtils.addSeconds(bindTime, 60);
if (bindMember == memberId && now.after(endTime)){
// 设备绑定人员是自己 但是绑定时间已经超过了一分钟
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.OPERATE_TIMEOUT_ERROR);
}else if (bindMember != memberId && now.before(endTime)){
// 设备绑定的人不是自己,并且呢人家的操作时间还没有结束呢(还没有解绑)
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.BIND_ERROR);
}
}
}
Venue venue = venueMapper.findById(venueId);
if (venue==null){
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.VENUE_ERROR);
@@ -41,5 +63,14 @@ public class QRCodeService {
return venue;
}
@Transactional
public void bindMember(Integer venueId,String deviceName,DeviceType deviceType,Integer memberId){
deviceMapper.bindMember(memberId, venueId, deviceName, deviceType);
}
@Transactional
public void unBindMember(Integer venueId,String deviceName,DeviceType deviceType){
deviceMapper.unBindMember(venueId, deviceName, deviceType);
}
}