api-二维码扫码锁定(新增字段绑定用户)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
<result column="venue_id" property="venueId"/>
|
||||
<result column="venue_type" property="venueType"/>
|
||||
<result column="device_type" property="deviceType"/>
|
||||
<result column="bind_member" property="bindMember"/>
|
||||
<result column="bind_time" property="bindTime"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="created_id" property="createdId"/>
|
||||
<result column="modified_id" property="modifiedId"/>
|
||||
@@ -35,6 +37,8 @@
|
||||
status,
|
||||
venue_type,
|
||||
device_type,
|
||||
bind_member,
|
||||
bind_time,
|
||||
created_id,
|
||||
modified_id,
|
||||
created_time,
|
||||
@@ -50,6 +54,8 @@
|
||||
#{venue_id, jdbcType=INTEGER},
|
||||
#{venue_type, jdbcType=INTEGER},
|
||||
#{device_type, jdbcType=VARCHAR},
|
||||
#{bind_member, jdbcType=INTEGER},
|
||||
#{bind_time, jdbcType=TIMESTAMP},
|
||||
#{createdId, jdbcType=INTEGER},
|
||||
#{modifiedId, jdbcType=INTEGER},
|
||||
#{createdTime, jdbcType=TIMESTAMP},
|
||||
@@ -91,6 +97,12 @@
|
||||
<if test="deviceType != null">
|
||||
device_type,
|
||||
</if>
|
||||
<if test="bindMember != null">
|
||||
bind_member,
|
||||
</if>
|
||||
<if test="bindTime != null">
|
||||
bind_time,
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status,
|
||||
</if>
|
||||
@@ -129,6 +141,12 @@
|
||||
<if test="deviceType != null">
|
||||
#{deviceType},
|
||||
</if>
|
||||
<if test="bindMember != null">
|
||||
#{bindMember},
|
||||
</if>
|
||||
<if test="bindTime != null">
|
||||
#{bindTime},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
#{status},
|
||||
</if>
|
||||
@@ -196,6 +214,12 @@
|
||||
<if test="deviceType != null">
|
||||
device_type = #{deviceType},
|
||||
</if>
|
||||
<if test="bindMember != null">
|
||||
bind_member = #{bindMember},
|
||||
</if>
|
||||
<if test="bindTime != null">
|
||||
bind_time = #{bindTime},
|
||||
</if>
|
||||
<if test="createdId != null">
|
||||
created_id = #{createdId},
|
||||
</if>
|
||||
@@ -277,4 +301,19 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<update id="bindMember">
|
||||
UPDATE sv_device set bind_member = #{bind_member},bind_time = now()
|
||||
WHERE name = #{deviceName} and venue_id=#{venueId}
|
||||
<if test="deviceType != null">
|
||||
and device_type = #{deviceType}
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<update id="unBindMember">
|
||||
UPDATE sv_device set bind_member = null,bind_time = null
|
||||
WHERE name = #{deviceName} and venue_id=#{venueId}
|
||||
<if test="deviceType != null">
|
||||
and device_type = #{deviceType}
|
||||
</if>
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user