api-二维码扫码锁定(新增字段绑定用户)
This commit is contained in:
@@ -31,6 +31,7 @@ public class AppVenueLessonController {
|
||||
*/
|
||||
@RequestMapping("/getLessonOrder/{id}")
|
||||
public String getLessonOrder(@PathVariable("id") Integer id,String date) {
|
||||
System.out.println("测试一下 ====================== " + date);
|
||||
if (date == null && "".equals(date)){
|
||||
LocalDate now = LocalDate.now();
|
||||
date = now.toString();
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.sv.netty.netty.service.MessageService;
|
||||
import com.sv.service.api.QRCodeService;
|
||||
import com.ydd.framework.core.common.dto.ResponseDTO;
|
||||
import com.ydd.framework.core.controller.BaseApiController;
|
||||
import com.ydd.framework.core.exception.ServiceException;
|
||||
import io.netty.channel.Channel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -36,7 +37,8 @@ public class QREnterController extends BaseApiController {
|
||||
Integer venueId = getVenueId(deviceId);
|
||||
String deviceName = getDeviceName(deviceId);
|
||||
DeviceType enterOrOut = getEnterOrOut(deviceId);
|
||||
Venue venue = qrCodeService.initEnter(venueId, deviceName,enterOrOut);
|
||||
Venue venue = qrCodeService.initEnter(venueId, deviceName,enterOrOut,memberId);
|
||||
qrCodeService.unBindMember(venueId, deviceName, enterOrOut);
|
||||
if (venue!=null){
|
||||
if (DeviceType.OUT == enterOrOut){
|
||||
// 出场
|
||||
@@ -55,13 +57,18 @@ public class QREnterController extends BaseApiController {
|
||||
*/
|
||||
@RequestMapping(value = "/qrCode/init", method = RequestMethod.GET)
|
||||
public ResponseDTO initEnter(@RequestParam("deviceId")String deviceId) {
|
||||
Integer memberId = getMemberIdByAccessToken();
|
||||
Integer venueId = getVenueId(deviceId);
|
||||
String deviceName = getDeviceName(deviceId);
|
||||
DeviceType enterOrOut = getEnterOrOut(deviceId);
|
||||
Venue venue = qrCodeService.initEnter(venueId, deviceName,enterOrOut);
|
||||
messageService.sendLoading(deviceName,venueId ,enterOrOut,memberId);
|
||||
return ResponseDTO.ok().addAttribute("venueInit", venue);
|
||||
try {
|
||||
Integer memberId = getMemberIdByAccessToken();
|
||||
Integer venueId = getVenueId(deviceId);
|
||||
String deviceName = getDeviceName(deviceId);
|
||||
DeviceType enterOrOut = getEnterOrOut(deviceId);
|
||||
Venue venue = qrCodeService.initEnter(venueId, deviceName, enterOrOut,memberId);
|
||||
qrCodeService.bindMember(venueId, deviceName, enterOrOut,memberId);
|
||||
messageService.sendLoading(deviceName, venueId, enterOrOut, memberId);
|
||||
return ResponseDTO.ok().addAttribute("venueInit", venue);
|
||||
}catch(ServiceException e){
|
||||
return ResponseDTO.ok().addAttribute("InitError",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ public class AppMessageHandlerAdapter implements MessageService {
|
||||
*/
|
||||
@Override
|
||||
public void enterVenue(String deviceName, Integer venueId, Integer memberId, Venue venue) {
|
||||
Member member = memberService.findByMember(memberId);
|
||||
Member member = memberService.findByMember(memberId);
|
||||
Channel channel = getCurrentChannel(deviceName, venueId, DeviceType.ENTER);
|
||||
// 校验入场时间是否正常
|
||||
if (checkInterval(member,venueId)) {
|
||||
@@ -194,7 +194,7 @@ public class AppMessageHandlerAdapter implements MessageService {
|
||||
sendMessage(channel,new MessageDTO(MessageType.FAILED, ErrorCode.NO_USE_CARD.getMsg()));
|
||||
}
|
||||
} else {
|
||||
logger.info(member.getId() + "入场失败:连续入场");
|
||||
logger.info(member == null ? "null" : member.getId() + "入场失败:连续入场");
|
||||
Config config = configService.findById(1);
|
||||
sendMessage(channel,new MessageDTO(MessageType.OPEN_DOOR, MessageFormat.format(ErrorCode.CHECK_ENTER_INTERVAL.getMsg(),config.getValue())));
|
||||
}
|
||||
|
||||
@@ -58,5 +58,6 @@
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="COMMON-DEFAULT" />
|
||||
<appender-ref ref="COMMON-ERROR" />
|
||||
<appender-ref ref="CONNECTION_APPENDER" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -32,7 +32,7 @@ public class ClientThread extends Thread{
|
||||
if (instance == null) {
|
||||
synchronized (ClientThread.class) {
|
||||
if (instance == null) {
|
||||
instance = new ClientThread("127.0.0.1", 56792);
|
||||
instance = new ClientThread("lmqhznn.goho.co", 26283);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ public class Device implements Serializable {
|
||||
private Integer venueType;
|
||||
|
||||
private DeviceType deviceType;
|
||||
|
||||
private Integer bindMember;
|
||||
|
||||
private Date bindTime;
|
||||
/**
|
||||
* 创建者编号
|
||||
*/
|
||||
@@ -252,4 +256,20 @@ public class Device implements Serializable {
|
||||
public void setDeviceType(DeviceType deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public Integer getBindMember() {
|
||||
return bindMember;
|
||||
}
|
||||
|
||||
public void setBindMember(Integer bindMember) {
|
||||
this.bindMember = bindMember;
|
||||
}
|
||||
|
||||
public Date getBindTime() {
|
||||
return bindTime;
|
||||
}
|
||||
|
||||
public void setBindTime(Date bindTime) {
|
||||
this.bindTime = bindTime;
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,8 @@ public class ExceptionCodeTemplate {
|
||||
|
||||
public static final ExceptionCode DEVICE_ERROR = ExceptionCode.init(30024, "未找到该设备");
|
||||
public static final ExceptionCode VENUE_TYPE_ERROR = ExceptionCode.init(30025, "该场馆暂不支持扫码入场");
|
||||
public static final ExceptionCode OPERATE_TIMEOUT_ERROR = ExceptionCode.init(30026, "操作超时,请重新扫码入场");
|
||||
public static final ExceptionCode BIND_ERROR = ExceptionCode.init(30027, "已有用户正在入场,请有序排队入场");
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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