门禁开门计费逻辑调整

This commit is contained in:
2023-12-06 10:00:43 +08:00
parent 07a648c3f5
commit 137a5f87ce
35 changed files with 509 additions and 392 deletions

View File

@@ -28,7 +28,7 @@ import java.io.*;
@RestController
public class AdminNettyController extends BaseApiController {
private final Logger logger = LoggerFactory.getLogger(AdminNettyController.class);
private final Logger logger = LoggerFactory.getLogger("NETTY-LOG-NAME");
@Resource
DeviceService deviceService;
@Resource
@@ -139,7 +139,7 @@ public class AdminNettyController extends BaseApiController {
String barcode = MakeCode.makeOfflineCode(barcodeSn);
deviceService.makeDeviceBarcode(device.getName(),device.getVenueId(),barcode);
String documentPath = getDocument(barcodeSn);
String documentPath = getDocument(barcode,barcodeSn);
response.setHeader("Content-disposition","attachment; filename=" + barcodeSn + ".docx");
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setCharacterEncoding("UTF-8");
@@ -163,8 +163,9 @@ public class AdminNettyController extends BaseApiController {
}
}
private static String getDocument(String barcodeSn) throws IOException, InvalidFormatException {
String newFilePath = "/Users/limqhz/home/test/document.docx";
private static String getDocument(String barcode, String barcodeSn) throws IOException, InvalidFormatException {
String newFilePath = "/home/test/" + barcodeSn + ".docx";
// String newFilePath = "/Users/limqhz/home/test/" + barcodeSn + ".docx";
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
@@ -173,7 +174,10 @@ public class AdminNettyController extends BaseApiController {
// 入场二维码
run.setText("订单号:" + barcodeSn);
run.addBreak();
String imgFile = VenueBarcodeUtil.generateBarcode("jdoiawjdoiawioe1","202311161.jpg");
// 入场二维码
run.setText("二维码使用有效期为2小时请及时离场");
run.addBreak();
String imgFile = VenueBarcodeUtil.generateBarcode(barcode,barcodeSn + ".jpg");
int imgFormat = XWPFDocument.PICTURE_TYPE_JPEG;
run.addPicture(new FileInputStream(imgFile), imgFormat, "image description",
Units.toEMU(200), Units.toEMU(200));

View File

@@ -26,7 +26,7 @@ import java.util.concurrent.Executors;
@Component
public class BootService {
private Logger logger = LoggerFactory.getLogger(BootService.class);
private Logger logger = LoggerFactory.getLogger("NETTY-LOG-NAME");
private volatile EventLoopGroup workerGroup;
private volatile EventLoopGroup bossGroup;

View File

@@ -24,7 +24,7 @@ import java.util.Set;
@ChannelHandler.Sharable
public class ServerHandler extends SimpleChannelInboundHandler<String> {
private static Logger logger = LoggerFactory.getLogger(ServerHandler.class);
private static Logger logger = LoggerFactory.getLogger("NETTY-LOG-NAME");
private MessageService messageService;
@@ -67,12 +67,13 @@ public class ServerHandler extends SimpleChannelInboundHandler<String> {
if (offline.startsWith("venue-")) {
// 这是线下开门的逻辑
messageService.offlineOpenDoor(message.getMessage());
}
VenueBarCode venueBarCode = MakeCode.decodeCode(message.getMessage());
if (EnterEnum.ENTER.getValue() == venueBarCode.getDirection()) {
messageService.enterVenue(message.getMessage());
} else {
messageService.outVenue(message.getMessage());
VenueBarCode venueBarCode = MakeCode.decodeCode(message.getMessage());
if (EnterEnum.ENTER.getValue() == venueBarCode.getDirection()) {
messageService.enterVenue(message.getMessage());
} else {
messageService.outVenue(message.getMessage());
}
}
break;
default:

View File

@@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentMap;
@Service("messageService")
public class ServerMessageHandlerAdapter implements MessageService {
private Logger logger = LoggerFactory.getLogger(ServerMessageHandlerAdapter.class);
private Logger logger = LoggerFactory.getLogger("NETTY-LOG-NAME");
/**
* 存储设备通道类型
@@ -120,10 +120,12 @@ public class ServerMessageHandlerAdapter implements MessageService {
String doorSn = venueBarCode.getDeviceName();
boolean lockStat = doorLockUtil.checkDoorLock(doorSn);
if (lockStat) {
logger.error("有人正在操作,请稍后再出场!!!");
throw new ServiceException("有人正在操作,请稍后再试");
}
barcode = MakeCode.reWriteBarcode(barcode);
if (!checkBarcode(barcode)){
logger.error("二维码已经使用,无法出场");
throw new ServiceException("二维码已经使用");
}
Channel channel = getCurrentChannel(doorSn,venueBarCode.getVenueId());
@@ -158,10 +160,12 @@ public class ServerMessageHandlerAdapter implements MessageService {
String doorSn = venueBarCode.getDeviceName();
boolean lockStat = doorLockUtil.checkDoorLock(doorSn);
if (lockStat) {
logger.error("有人正在操作,请稍后再试");
throw new ServiceException("有人正在操作,请稍后再试");
}
barcode = MakeCode.reWriteBarcode(barcode);
if (!checkBarcode(barcode)){
logger.error("二维码已经使用,无法入场");
throw new ServiceException("二维码已经使用");
}
Channel channel = getCurrentChannel(doorSn, venueBarCode.getVenueId());
@@ -189,6 +193,7 @@ public class ServerMessageHandlerAdapter implements MessageService {
private boolean checkBarcode(String barcode) {
Barcode code = barcodeMapper.checkCodeStatus(barcode);
if (code == null) {
logger.error("二维码不存在或者已经被使用!!!");
throw new ServiceException("二维码不存在或者已经被使用");
}
if (BarCodeStatusEnum.INIT.getValue()==code.getStatus()){
@@ -233,11 +238,13 @@ public class ServerMessageHandlerAdapter implements MessageService {
Date endTime = barcodeOffline.getEndTime();
if (endTime.before(new Date())) {
// 二维码已经失效了
throw new ServiceException("二维码已经失效,无法继续使用");
logger.error("二维码已经失效,无法继续使用");
throw new ServiceException("二维码已经失效,无法继续使用");
}
boolean lockStat = doorLockUtil.checkDoorLock(doorSn);
if (lockStat) {
throw new ServiceException("有人正在操作,请稍后再试");
logger.error("有人正在操作,请稍后再试!!!");
throw new ServiceException("有人正在操作,请稍后再试!!!");
}
BarcodeEnterLog lastByBarcode = barcodeEnterLogMapper.findLastByBarcode(barcode);
Integer venueId = barcodeOffline.getVenueId();
@@ -248,6 +255,7 @@ public class ServerMessageHandlerAdapter implements MessageService {
barcodeEnterLog.setBarcode(barcode);
barcodeEnterLog.setType(EnterEnum.OUT.getValue());
barcodeEnterLog.setVenueId(venueId);
barcodeEnterLog.setPlatformId(1);
barcodeEnterLogMapper.insert(barcodeEnterLog);
doorLockUtil.lockDoor(doorSn);
ServerMessageUtils.INSTANCE.sendMsg(channel,new VenueMessage(MessageType.OUT_DOOR,"OK"));
@@ -257,6 +265,7 @@ public class ServerMessageHandlerAdapter implements MessageService {
barcodeEnterLog.setBarcode(barcode);
barcodeEnterLog.setType(EnterEnum.ENTER.getValue());
barcodeEnterLog.setVenueId(venueId);
barcodeEnterLog.setPlatformId(1);
barcodeEnterLogMapper.insert(barcodeEnterLog);
doorLockUtil.lockDoor(doorSn);
ServerMessageUtils.INSTANCE.sendMsg(channel,new VenueMessage(MessageType.ENTER_DOOR,"OK"));

View File

@@ -1,12 +1,12 @@
spring:
datasource:
# url: jdbc:mysql://yingdiandian.mysql.rds.aliyuncs.com:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
# url: jdbc:mysql://yingdiandian.mysql.rds.aliyuncs.com:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
# username: yingdd
# password: Yingdd2015
url: jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
url: jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
username: root
password: 123456
# url: jdbc:mysql://120.27.209.4:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
# url: jdbc:mysql://120.27.209.4:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
# username: root
# password: hyty1234

View File

@@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
url: jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
username: root
password: hyty1234
redis:

View File

@@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:mysql://yingdiandian.mysql.rds.aliyuncs.com:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8
url: jdbc:mysql://yingdiandian.mysql.rds.aliyuncs.com:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=GMT%2b8
username: yingdd
password: Yingdd2015
redis:

View File

@@ -95,7 +95,7 @@ logging:
#netty服务器配置
netty:
port: 56792
port: 56791
boss:
thread:
count: 1

View File

@@ -52,14 +52,13 @@
</encoder>
</appender>
<logger name="com.sv.netty" level="debug" additivity="false">
<logger name="NETTY-LOG-NAME" level="debug" additivity="false">
<appender-ref ref="NETTY-LOG"/>
</logger>
<!-- root -->
<root level="info">
<appender-ref ref="STDOUT" />
<appender-ref ref="NETTY-LOG" />
<appender-ref ref="COMMON-DEFAULT" />
<appender-ref ref="COMMON-ERROR" />
</root>