LoginPage.java
18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
package cn.csbr.app.gui;
import cn.csbr.app.auth.LoginService;
import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.exception.AuthException;
import cn.csbr.app.gui.component.common.ImageButton;
import cn.csbr.app.gui.handler.ReturnMainPageHandler;
import cn.csbr.app.gui.page.AbstractPage;
import cn.csbr.app.gui.page.MainPage;
import cn.csbr.app.gui.page.Page;
import cn.csbr.app.gui.page.setting.SettingPage;
import cn.csbr.app.gui.util.DialogUtils;
import cn.csbr.app.hardware.BWCabinetTestDll;
import cn.csbr.app.hardware.HFbwcabinet.HFbwcabinetApi;
import cn.csbr.app.model.LoginUser;
import cn.csbr.app.service.IdLoginService;
import cn.csbr.app.service.SysUserService;
import cn.csbr.app.util.KeyUp;
import cn.csbr.springboot.dao.model.SysUser;
import cn.hutool.core.date.DateUtil;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.controlsfx.control.textfield.TextFields;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.swing.*;
import java.util.List;
import static cn.csbr.app.FxApp.applicationContext;
import static cn.csbr.app.gui.util.SystemUtils.getDataTableMinHeight;
@Log4j2
@Component
public class LoginPage extends AbstractPage {
Stage primaryStage;
@Autowired
private MainPage mainPage;
@Autowired
private SettingPage settingPage;
@Autowired
private GUIContext context;
@Autowired
private LoginService loginService;
@Autowired
private FxConfigure fxConfigure;
@Autowired
private IdLoginService idLoginService;
@Autowired
private GUIContext guiContext;
private Integer num = 0;
private Integer num2 = 0;
private String cardId;
private Label prompt = new Label();
private TextField usernameField = TextFields.createClearableTextField();
private PasswordField passwordField = TextFields.createClearablePasswordField();
ImageButton loginBtn;
ImageButton closeBtn;
SysUser userByCarid = null;
boolean timeflag = false;
private int countnum=0;
public void start(Stage stage) {
primaryStage = new Stage();
primaryStage.initOwner(stage);
primaryStage.initModality(Modality.APPLICATION_MODAL);
primaryStage.initStyle(StageStyle.TRANSPARENT);//隐藏默认标题栏
// primaryStage.initStyle(StageStyle.UTILITY);//页面风格
primaryStage.setResizable(false);//页面禁止缩放
primaryStage.initStyle(StageStyle.UNDECORATED);//设定窗口无边框
usernameField.setText("hsz");
passwordField.setText("111111");
primaryStage.setOnCloseRequest((e) -> {
mainPage.refresh();
context.updateMainContent(mainPage.getContent());
num = 1;
num2 = 1;
//启动其他柜子的指纹和刷卡
context.startOtherCabFingerAndId();
});
primaryStage.setMaxWidth(fxConfigure.getMinWidth());
primaryStage.setMinWidth(fxConfigure.getMinWidth());
primaryStage.setMinHeight(fxConfigure.getMinHeight());
primaryStage.setMaxHeight(fxConfigure.getMinHeight());
VBox mainPanel = new VBox();
mainPanel.setId("loginPage");
mainPanel.getStylesheets().add("styles/login.css");
//视图布局类继承自parent,为页面元素设置宽高
Region topspacer = new Region();
topspacer.setMinHeight(484);
// HBox布局类将JavaFX子节点放在水平行中。 新的子节点附加到右侧的末尾
HBox centerbox = new HBox();
centerbox.setMinHeight(340);
Region clspacer = new Region();
clspacer.setMinWidth(830);
Region crspacer = new Region();
crspacer.setMinWidth(200);
// 通常用于布局:第一列上的只读标签的输入表单和第二列上的输入字段,可以在行,列或单元格级别指定约束。
GridPane grid = new GridPane();
//CloseBtn = new ImageButton(null,null,"/images/btn_close.png");
//取消按钮
countnum=0;
timeflag=true;
closeBtn = new ImageButton((e) -> {
primaryStage.close();
num = 1;
num2 = 1;
countnum=0;
timeflag=false;
//启动其他柜子的指纹和刷卡
context.startOtherCabFingerAndId();
GUIContext.isOK=0;
}, "closeBtn", "/images/btn_close.png");
closeBtn.setCursor(Cursor.HAND);
// 调用imageButton类的带三个参数的构造函数,设置点击事件,event->事件执行
loginBtn = new ImageButton((e) -> {
LoginUser user = new LoginUser();
log.info("登录验证开始");
// 取到页面上的用户名和密码输入框的值并赋值给user对象
user.setUserName(usernameField.getText());
user.setPassword(passwordField.getText());
try {
// 调用登录方法
String role = loginService.loginVali(user);
if ("482278d18845427ca8fb986d5ba30e4f".equals(role) || "ae990cd2d33a4aa2bc9a52963925bf19".equals(role)) {
primaryStage.close();
num = 1;
num2 = 1;
countnum=0;
timeflag=false;
GUIContext.isOK=1;
//启动其他柜子的指纹和刷卡
context.startOtherCabFingerAndId();
} else {
DialogUtils.showHeaderTextInformationAlert("您无此操作权限!", primaryStage);
}
} catch (AuthException a) {
a.printStackTrace();
Platform.runLater(() -> {
DialogUtils.showHeaderTextInformationAlert(a.getMessage(), primaryStage);
});
} catch (Exception ex) {
ex.printStackTrace();
log.info("异常" + ex.getMessage());
// 显示错误信息
DialogUtils.showHeaderTextInformationAlert("您无此操作权限!", primaryStage);
} finally {
usernameField.clear();
passwordField.clear();
}
}, "loginBtn", "/images/btn_login.png");
loginBtn.setCursor(Cursor.HAND);
usernameField.setMinHeight(50);
// 设置输入框提示语
usernameField.setPromptText("用户名1");
passwordField.setMinHeight(50);
passwordField.setPromptText("密码");
KeyUp.setTextFieldOrPasswordField(this,false);
// 设置上下间距
grid.setVgap(26);
grid.setPadding(new Insets(-170, 0, 0, -20));
//loginBtn.requestFocus();
//column:列 row:行 colspan:多少个列宽 rowspan:多少行宽
grid.add(usernameField, 0, 0, 1, 1);
grid.add(passwordField, 0, 1, 1, 1);
grid.add(loginBtn, 0, 2, 1, 1);
grid.add(closeBtn, 0, 3, 1, 1);
centerbox.getChildren().addAll(clspacer, grid, crspacer);
Region bottomspacer = new Region();
bottomspacer.setMinHeight(400);
prompt.setFont(new Font("Arial", 50));
prompt.setTextFill(Color.web("#ff0060"));
grid.setTranslateX(-250);
grid.setTranslateY(200);
//prompt.setText("请输入用户名密码或刷卡指纹验证用户");
// 设置vbox完整布局
mainPanel.getChildren().addAll(prompt, topspacer, centerbox, bottomspacer);
this.setTitle("欢迎界面");
//暂停其他柜子的指纹和刷卡
context.pauseOtherCabFingerAndId();
mainPanel.setMaxWidth(fxConfigure.getMinWidth());
mainPanel.setMaxHeight(fxConfigure.getMinHeight());
Scene scene = new Scene(mainPanel, fxConfigure.getMinWidth(), fxConfigure.getMinWidth());
primaryStage.setScene(scene);
primaryStage.setY(-17);
primaryStage.setX(-315);
// primaryStage.show();
// LoginUser loginUser=new LoginUser();
// guiContext.setLoginUserVali(loginUser);
/**
* id卡验证
*/
Platform.runLater(() -> {
Thread thread = new Thread(() -> {
BWCabinetTestDll instance=null;
try {
instance = BWCabinetTestDll.instance;
}catch (UnsatisfiedLinkError e){
return;
}catch (NoClassDefFoundError ne){
return;
}
while (true) {//清空串口
Pointer outjson_pointer = new Memory(50);
IntByReference idLength = new IntByReference(-1);
int flag = instance.BWGetIDCardNum(5, outjson_pointer, idLength);
if (flag != 0) {
break;
}
}
while (true) {
if (num == 1) {
num = 0;
break;
}
Pointer outjson_pointer = new Memory(50);
IntByReference idLength = new IntByReference(-1);
//logger.info("柜子编号:" + cabinetCd + "准备获取卡信息:" );
int flag = instance.BWGetIDCardNum(5, outjson_pointer, idLength);
if (flag != 0) {
continue;
}
//取到outjson_pointer中的字符
byte[] bytOutjson = outjson_pointer.getByteArray(0, idLength.getValue());
cardId = "";
try {
//转化字符编码格式
cardId = new String(bytOutjson, "gbk");
// logger.info("柜子编号:" + cabinetCd + "获取到卡信息:" +cardId);
} catch (Exception e) {
e.printStackTrace();
}
if (StringUtils.isBlank(cardId)) {
continue;
}
userByCarid = idLoginService.findUserByCarid(cardId,context.getStoreguid());
if (userByCarid != null) {
String roleByCarid = userByCarid.getRoleguid();
if ("482278d18845427ca8fb986d5ba30e4f".equals(roleByCarid) || "ae990cd2d33a4aa2bc9a52963925bf19".equals(roleByCarid)) {
System.out.println("验证成功");
loginService.LoginByCarid(userByCarid);
if(userByCarid.getOrgguid()==null){
System.out.println("警告:登录人科室为空");
}
Platform.runLater(new Runnable() {
@Override
public void run() {
DialogUtils.showHeaderTextInformationAlert("验证成功!", primaryStage);
primaryStage.close();
num2 = 1;
timeflag=false;
countnum=0;
GUIContext.isOK=1;
}
});
//启动其他柜子的指纹和刷卡
context.startOtherCabFingerAndId();
break;
} else {
Platform.runLater(new Runnable() {
@Override
public void run() {
DialogUtils.showHeaderTextInformationAlert("您无此操作权限!", primaryStage);
}
});
continue;
}
} else {
Platform.runLater(new Runnable() {
@Override
public void run() {
DialogUtils.showHeaderTextInformationAlert("没有当前验证人!", primaryStage);
}
});
continue;
}
}
System.out.println("读取卡线程已退出");
});
thread.start();
//thread2.start();
});
/**
* 指纹验证
*/
Platform.runLater(()-> {
Thread thread2 = new Thread(() -> {
while (true) {
if (num2 == 1) {
num2 = 0;
break;
}
System.out.println("循环读取指纹信息");
IntByReference nFingerNum = new IntByReference(-1);
//超高频的用这个
BWCabinetTestDll instance = BWCabinetTestDll.instance;
int flag = instance.BWQueryFingerNum(5, nFingerNum);
//log.info("指纹信息:" + nFingerNum.getValue() + "当前的flag" + flag);
if(flag==6){
continue;
}
if (flag == 4) {
instance.BWStartRedLight(5, 2);
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
continue;
}
log.info("获取指纹为:" + String.valueOf(nFingerNum.getValue()));
List<SysUser> userRoleByzws = idLoginService.findUserRoleByFinger(context.getStoreguid(),String.valueOf(nFingerNum.getValue()),fxConfigure.getCabinetGroupCode());
SysUser userRoleByzw=null;
if(userRoleByzws.size()>0)
{
userRoleByzw=userRoleByzws.get(0);
}
log.info(userRoleByzw);
if (userRoleByzw != null) {
if(userRoleByzw.getBizstate().equals("N")) {
DialogUtils.showHeaderTextInformationAlert("该用户已被禁用!", primaryStage);
}
String roleByCarid = userRoleByzw.getRoleguid();
if ("482278d18845427ca8fb986d5ba30e4f".equals(roleByCarid) || "ae990cd2d33a4aa2bc9a52963925bf19".equals(roleByCarid)) {
System.out.println("验证成功");
//DialogUtils.showHeaderTextInformationAlert("验证成功!",primaryStage);
loginService.LoginByCarid(userRoleByzw);
Platform.runLater(new Runnable() {
@Override
public void run() {
DialogUtils.showHeaderTextInformationAlert("验证成功!", primaryStage);
primaryStage.close();
num = 1;
timeflag=false;
countnum=0;
GUIContext.isOK=1;
}
});
//启动其他柜子的指纹和刷卡
context.startOtherCabFingerAndId();
break;
} else {
Platform.runLater(new Runnable() {
@Override
public void run() {
DialogUtils.showHeaderTextInformationAlert("您无此操作权限!", primaryStage);
}
});
continue;
//DialogUtils.showHeaderTextInformationAlert("您无此操作权限!",primaryStage);
}
} else {
Platform.runLater(new Runnable() {
@Override
public void run() {
DialogUtils.showHeaderTextInformationAlert("没有当前验证人!", primaryStage);
}
});
continue;
}
}
});
thread2.start();
});
new Thread(() -> {
try {
while (timeflag) {
Platform.runLater(() -> {
if(countnum>60){
timeflag=false;
countnum=0;
primaryStage.close();
num = 1;
num2 = 1;
//启动其他柜子的指纹和刷卡
context.startOtherCabFingerAndId();
mainPage.refresh();
context.updateMainContent(mainPage.getContent());
GUIContext.isOK=0;
}
});
Thread.sleep(1000);
countnum=countnum+1;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
primaryStage.showAndWait();
}
@Override
public void refresh() {
}
@Override
protected Node constructNode() {
return null;
}
}