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

@@ -31,6 +31,7 @@ public class AppVenueLessonController {
*/ */
@RequestMapping("/getLessonOrder/{id}") @RequestMapping("/getLessonOrder/{id}")
public String getLessonOrder(@PathVariable("id") Integer id,String date) { public String getLessonOrder(@PathVariable("id") Integer id,String date) {
System.out.println("测试一下 ====================== " + date);
if (date == null && "".equals(date)){ if (date == null && "".equals(date)){
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
date = now.toString(); date = now.toString();

View File

@@ -9,6 +9,7 @@ import com.sv.netty.netty.service.MessageService;
import com.sv.service.api.QRCodeService; import com.sv.service.api.QRCodeService;
import com.ydd.framework.core.common.dto.ResponseDTO; import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController; import com.ydd.framework.core.controller.BaseApiController;
import com.ydd.framework.core.exception.ServiceException;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -36,7 +37,8 @@ public class QREnterController extends BaseApiController {
Integer venueId = getVenueId(deviceId); Integer venueId = getVenueId(deviceId);
String deviceName = getDeviceName(deviceId); String deviceName = getDeviceName(deviceId);
DeviceType enterOrOut = getEnterOrOut(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 (venue!=null){
if (DeviceType.OUT == enterOrOut){ if (DeviceType.OUT == enterOrOut){
// 出场 // 出场
@@ -55,13 +57,18 @@ public class QREnterController extends BaseApiController {
*/ */
@RequestMapping(value = "/qrCode/init", method = RequestMethod.GET) @RequestMapping(value = "/qrCode/init", method = RequestMethod.GET)
public ResponseDTO initEnter(@RequestParam("deviceId")String deviceId) { public ResponseDTO initEnter(@RequestParam("deviceId")String deviceId) {
try {
Integer memberId = getMemberIdByAccessToken(); Integer memberId = getMemberIdByAccessToken();
Integer venueId = getVenueId(deviceId); Integer venueId = getVenueId(deviceId);
String deviceName = getDeviceName(deviceId); String deviceName = getDeviceName(deviceId);
DeviceType enterOrOut = getEnterOrOut(deviceId); DeviceType enterOrOut = getEnterOrOut(deviceId);
Venue venue = qrCodeService.initEnter(venueId, deviceName,enterOrOut); Venue venue = qrCodeService.initEnter(venueId, deviceName, enterOrOut,memberId);
messageService.sendLoading(deviceName,venueId ,enterOrOut,memberId); qrCodeService.bindMember(venueId, deviceName, enterOrOut,memberId);
messageService.sendLoading(deviceName, venueId, enterOrOut, memberId);
return ResponseDTO.ok().addAttribute("venueInit", venue); return ResponseDTO.ok().addAttribute("venueInit", venue);
}catch(ServiceException e){
return ResponseDTO.ok().addAttribute("InitError",e.getMessage());
}
} }

View File

@@ -194,7 +194,7 @@ public class AppMessageHandlerAdapter implements MessageService {
sendMessage(channel,new MessageDTO(MessageType.FAILED, ErrorCode.NO_USE_CARD.getMsg())); sendMessage(channel,new MessageDTO(MessageType.FAILED, ErrorCode.NO_USE_CARD.getMsg()));
} }
} else { } else {
logger.info(member.getId() + "入场失败:连续入场"); logger.info(member == null ? "null" : member.getId() + "入场失败:连续入场");
Config config = configService.findById(1); Config config = configService.findById(1);
sendMessage(channel,new MessageDTO(MessageType.OPEN_DOOR, MessageFormat.format(ErrorCode.CHECK_ENTER_INTERVAL.getMsg(),config.getValue()))); sendMessage(channel,new MessageDTO(MessageType.OPEN_DOOR, MessageFormat.format(ErrorCode.CHECK_ENTER_INTERVAL.getMsg(),config.getValue())));
} }

View File

@@ -58,5 +58,6 @@
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />
<appender-ref ref="COMMON-DEFAULT" /> <appender-ref ref="COMMON-DEFAULT" />
<appender-ref ref="COMMON-ERROR" /> <appender-ref ref="COMMON-ERROR" />
<appender-ref ref="CONNECTION_APPENDER" />
</root> </root>
</configuration> </configuration>

View File

@@ -32,7 +32,7 @@ public class ClientThread extends Thread{
if (instance == null) { if (instance == null) {
synchronized (ClientThread.class) { synchronized (ClientThread.class) {
if (instance == null) { if (instance == null) {
instance = new ClientThread("127.0.0.1", 56792); instance = new ClientThread("lmqhznn.goho.co", 26283);
} }
} }
} }

View File

@@ -39,6 +39,10 @@ public class Device implements Serializable {
private Integer venueType; private Integer venueType;
private DeviceType deviceType; private DeviceType deviceType;
private Integer bindMember;
private Date bindTime;
/** /**
* 创建者编号 * 创建者编号
*/ */
@@ -252,4 +256,20 @@ public class Device implements Serializable {
public void setDeviceType(DeviceType deviceType) { public void setDeviceType(DeviceType deviceType) {
this.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;
}
} }

View File

@@ -53,6 +53,8 @@ public class ExceptionCodeTemplate {
public static final ExceptionCode DEVICE_ERROR = ExceptionCode.init(30024, "未找到该设备"); public static final ExceptionCode DEVICE_ERROR = ExceptionCode.init(30024, "未找到该设备");
public static final ExceptionCode VENUE_TYPE_ERROR = ExceptionCode.init(30025, "该场馆暂不支持扫码入场"); 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, "已有用户正在入场,请有序排队入场");

View File

@@ -85,4 +85,16 @@ public interface DeviceMapper {
* @return * @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,@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.DeviceType;
import com.enums.VenueTypeEnum; import com.enums.VenueTypeEnum;
import com.sv.entity.Device;
import com.sv.entity.Venue; import com.sv.entity.Venue;
import com.sv.mapper.DeviceMapper; import com.sv.mapper.DeviceMapper;
import com.sv.mapper.VenueMapper; import com.sv.mapper.VenueMapper;
import com.sv.service.api.util.DateUtilCard;
import com.ydd.framework.core.exception.ServiceException; import com.ydd.framework.core.exception.ServiceException;
import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
/** /**
* 小程序扫二维码处理 * 小程序扫二维码处理
@@ -26,11 +30,29 @@ public class QRCodeService {
@Resource @Resource
private DeviceMapper deviceMapper; 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); Integer integer = deviceMapper.checkDevice(deviceName, venueId,deviceType);
if (integer != 1){ if (integer != 1){
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.DEVICE_ERROR); 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); Venue venue = venueMapper.findById(venueId);
if (venue==null){ if (venue==null){
throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.VENUE_ERROR); throw new ServiceException(com.sv.exception.api.ExceptionCodeTemplate.VENUE_ERROR);
@@ -41,5 +63,14 @@ public class QRCodeService {
return venue; 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);
}
} }

View File

@@ -9,6 +9,8 @@
<result column="venue_id" property="venueId"/> <result column="venue_id" property="venueId"/>
<result column="venue_type" property="venueType"/> <result column="venue_type" property="venueType"/>
<result column="device_type" property="deviceType"/> <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="status" property="status"/>
<result column="created_id" property="createdId"/> <result column="created_id" property="createdId"/>
<result column="modified_id" property="modifiedId"/> <result column="modified_id" property="modifiedId"/>
@@ -35,6 +37,8 @@
status, status,
venue_type, venue_type,
device_type, device_type,
bind_member,
bind_time,
created_id, created_id,
modified_id, modified_id,
created_time, created_time,
@@ -50,6 +54,8 @@
#{venue_id, jdbcType=INTEGER}, #{venue_id, jdbcType=INTEGER},
#{venue_type, jdbcType=INTEGER}, #{venue_type, jdbcType=INTEGER},
#{device_type, jdbcType=VARCHAR}, #{device_type, jdbcType=VARCHAR},
#{bind_member, jdbcType=INTEGER},
#{bind_time, jdbcType=TIMESTAMP},
#{createdId, jdbcType=INTEGER}, #{createdId, jdbcType=INTEGER},
#{modifiedId, jdbcType=INTEGER}, #{modifiedId, jdbcType=INTEGER},
#{createdTime, jdbcType=TIMESTAMP}, #{createdTime, jdbcType=TIMESTAMP},
@@ -91,6 +97,12 @@
<if test="deviceType != null"> <if test="deviceType != null">
device_type, device_type,
</if> </if>
<if test="bindMember != null">
bind_member,
</if>
<if test="bindTime != null">
bind_time,
</if>
<if test="status != null"> <if test="status != null">
status, status,
</if> </if>
@@ -129,6 +141,12 @@
<if test="deviceType != null"> <if test="deviceType != null">
#{deviceType}, #{deviceType},
</if> </if>
<if test="bindMember != null">
#{bindMember},
</if>
<if test="bindTime != null">
#{bindTime},
</if>
<if test="status != null"> <if test="status != null">
#{status}, #{status},
</if> </if>
@@ -196,6 +214,12 @@
<if test="deviceType != null"> <if test="deviceType != null">
device_type = #{deviceType}, device_type = #{deviceType},
</if> </if>
<if test="bindMember != null">
bind_member = #{bindMember},
</if>
<if test="bindTime != null">
bind_time = #{bindTime},
</if>
<if test="createdId != null"> <if test="createdId != null">
created_id = #{createdId}, created_id = #{createdId},
</if> </if>
@@ -277,4 +301,19 @@
</if> </if>
</select> </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> </mapper>