Kaynağa Gözat

客户端开发

yingp 6 yıl önce
ebeveyn
işleme
977b167992
19 değiştirilmiş dosya ile 170 ekleme ve 83 silme
  1. 31 0
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/control/IconFont.java
  2. 5 5
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/control/NavItem.java
  3. 11 9
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/GateController.java
  4. 1 1
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/GateSettingController.java
  5. 9 0
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/LoginController.java
  6. 9 2
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/MainController.java
  7. 13 6
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/PersonController.java
  8. 18 21
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/PersonEditController.java
  9. 1 1
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/po/GatePersonView.java
  10. 1 1
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/po/Person.java
  11. 14 10
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/po/SexType.java
  12. 13 14
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/task/GateScheduler.java
  13. 4 0
      applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/util/AlertUtils.java
  14. BIN
      applications/device/device-client-biometric/src/main/resources/style/iconfont.ttf
  15. 21 1
      applications/device/device-client-biometric/src/main/resources/style/main.css
  16. 2 2
      applications/device/device-client-biometric/src/main/resources/view/login.fxml
  17. 11 4
      applications/device/device-client-biometric/src/main/resources/view/main.fxml
  18. 5 5
      applications/device/device-client-biometric/src/main/resources/view/person.fxml
  19. 1 1
      applications/device/device-sdk-biometric/src/main/java/com/usoftchina/smartschool/device/biometric/BiometricDeviceService.java

+ 31 - 0
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/control/IconFont.java

@@ -0,0 +1,31 @@
+package com.usoftchina.smartschool.device.client.biometric.control;
+
+import javafx.scene.control.Label;
+import javafx.scene.text.Font;
+
+/**
+ * @author yingp
+ * @date 2019/11/20
+ */
+public class IconFont extends Label {
+    private static Font FONT;
+    private static final int defaultFontSize = 16;
+
+    static {
+        FONT = Font.loadFont(IconFont.class.getResourceAsStream("/style/iconfont.ttf"), defaultFontSize);
+    }
+
+    public static final IconFont FACE = new IconFont('\ue6b6');
+    public static final IconFont PERSON = new IconFont('\ue8ba');
+    public static final IconFont SETTING = new IconFont('\ue610');
+
+    public IconFont() {
+        this.getStyleClass().add("icon-font");
+        this.setFont(FONT);
+    }
+
+    public IconFont(char unicode) {
+        this();
+        setText(String.valueOf(unicode));
+    }
+}

+ 5 - 5
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/control/NavItem.java

@@ -1,7 +1,7 @@
 package com.usoftchina.smartschool.device.client.biometric.control;
 
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.beans.property.StringProperty;
 import javafx.scene.control.TreeItem;
 
 /**
@@ -9,15 +9,15 @@ import javafx.scene.control.TreeItem;
  * @date 2019/11/14
  */
 public class NavItem<T> extends TreeItem<T> {
-    private ObjectProperty<String> viewPath;
+    private StringProperty viewPath;
 
     public String getViewPath() {
         return viewPathProperty().get();
     }
 
-    public ObjectProperty<String> viewPathProperty() {
+    public StringProperty viewPathProperty() {
         if (null == viewPath) {
-            viewPath = new SimpleObjectProperty<>();
+            viewPath = new SimpleStringProperty();
         }
         return viewPath;
     }

+ 11 - 9
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/GateController.java

@@ -19,10 +19,7 @@ import javafx.fxml.FXML;
 import javafx.fxml.Initializable;
 import javafx.geometry.Pos;
 import javafx.scene.Scene;
-import javafx.scene.control.Button;
-import javafx.scene.control.TableCell;
-import javafx.scene.control.TableColumn;
-import javafx.scene.control.TableView;
+import javafx.scene.control.*;
 import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.stage.Stage;
 import org.slf4j.Logger;
@@ -191,11 +188,16 @@ public class GateController implements Initializable {
             AlertUtils.warn("请先选择一行数据");
             return;
         }
-        Platform.runLater(() -> {
-            faceGateService.delete(faceGate.getId());
-            NotifyUtils.info("删除成功");
-            loadData();
-        });
+        AlertUtils.confirm("确定删除设备 " + faceGate.getName() + "?")
+                .ifPresent(b -> {
+                    if (b == ButtonType.OK) {
+                        Platform.runLater(() -> {
+                            faceGateService.delete(faceGate.getId());
+                            NotifyUtils.info("删除成功");
+                            loadData();
+                        });
+                    }
+                });
     }
 
     @FXML

+ 1 - 1
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/GateSettingController.java

@@ -146,8 +146,8 @@ public class GateSettingController implements Initializable {
                         faceGate.setIp(deviceSetting.getIpAddress());
                         faceGateService.save(faceGate);
                     }
-                    NotifyUtils.info("设置成功");
                     softwareVersionLabel.getScene().getWindow().hide();
+                    NotifyUtils.info("设置成功");
                 } catch (Exception e) {
                     AlertUtils.error(e.getMessage());
                 }

+ 9 - 0
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/LoginController.java

@@ -7,6 +7,8 @@ import javafx.fxml.FXML;
 import javafx.fxml.Initializable;
 import javafx.scene.control.PasswordField;
 import javafx.scene.control.TextField;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.KeyEvent;
 import org.springframework.util.StringUtils;
 
 import java.net.URL;
@@ -65,4 +67,11 @@ public class LoginController implements Initializable {
     public static void logout() {
         logon = false;
     }
+
+    @FXML
+    public void handleKeyPressed(KeyEvent keyEvent) {
+        if (keyEvent.getCode() == KeyCode.ENTER) {
+            handleLogin(null);
+        }
+    }
 }

+ 9 - 2
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/MainController.java

@@ -36,8 +36,15 @@ public class MainController implements Initializable {
                 super.updateItem(item, empty);
                 setText(item);
                 TreeItem<String> treeItem = getTreeItem();
-                if (null != treeItem && treeItem.isLeaf()) {
-                    getStyleClass().add("tree-cell-leaf");
+                if (null != treeItem) {
+                    setGraphic(treeItem.getGraphic());
+                    if (treeItem.isLeaf()) {
+                        getStyleClass().add("tree-cell-leaf");
+                    } else {
+                        getStyleClass().remove("tree-cell-leaf");
+                    }
+                } else {
+                    setGraphic(null);
                 }
             }
         });

+ 13 - 6
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/PersonController.java

@@ -6,6 +6,7 @@ import com.usoftchina.smartschool.device.client.biometric.po.Person;
 import com.usoftchina.smartschool.device.client.biometric.po.SexType;
 import com.usoftchina.smartschool.device.client.biometric.service.PersonService;
 import com.usoftchina.smartschool.device.client.biometric.util.AlertUtils;
+import com.usoftchina.smartschool.device.client.biometric.util.NotifyUtils;
 import com.usoftchina.smartschool.device.client.biometric.util.ViewUtils;
 import com.usoftchina.smartschool.device.context.SpringContextHolder;
 import javafx.application.Platform;
@@ -17,10 +18,7 @@ import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
 import javafx.fxml.Initializable;
 import javafx.scene.Scene;
-import javafx.scene.control.Button;
-import javafx.scene.control.TableCell;
-import javafx.scene.control.TableColumn;
-import javafx.scene.control.TableView;
+import javafx.scene.control.*;
 import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.stage.Stage;
 import org.slf4j.Logger;
@@ -139,8 +137,17 @@ public class PersonController implements Initializable {
             AlertUtils.warn("请先选择一行数据");
             return;
         }
-        personService.delete(person.getId());
-        loadData();
+        AlertUtils.confirm("确定删除人员 " + person.getName() + "?")
+                .ifPresent(b -> {
+                    if (b == ButtonType.OK) {
+                        Platform.runLater(() -> {
+                            personService.delete(person.getId());
+                            NotifyUtils.info("删除成功");
+                            loadData();
+                        });
+                    }
+                });
+
     }
 
     @FXML

+ 18 - 21
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/controller/PersonEditController.java

@@ -71,10 +71,7 @@ public class PersonEditController implements Initializable {
     private File unsavedImage;
 
     private ObservableList<SexType> sexOptions =
-            FXCollections.observableArrayList(
-                    new SexType(1, "男"),
-                    new SexType(2, "女")
-            );
+            FXCollections.observableArrayList(SexType.values());
 
     @Override
     public void initialize(URL location, ResourceBundle resources) {
@@ -126,7 +123,7 @@ public class PersonEditController implements Initializable {
         }
     }
 
-    private void save() {
+    private void save(Runnable onComplete) {
         if (StringUtils.isEmpty(person.getName())) {
             AlertUtils.warn("请填写姓名").ifPresent(b -> nameField.requestFocus());
             return;
@@ -156,30 +153,30 @@ public class PersonEditController implements Initializable {
             person.setFaceImage(null);
         }
 
-        Platform.runLater(() -> {
-            try {
-                personService.save(person);
-                NotifyUtils.info("保存成功");
-            } catch (Exception e) {
-                AlertUtils.error(e.getMessage());
-            }
-        });
+        try {
+            personService.save(person);
+            NotifyUtils.info("保存成功");
+            onComplete.run();
+        } catch (Exception e) {
+            AlertUtils.error(e.getMessage());
+        }
     }
 
     @FXML
     public void handleSave(ActionEvent event) {
-        save();
-
-        Stage stage = (Stage) nameField.getScene().getWindow();
-        stage.close();
+        save(() -> {
+            Stage stage = (Stage) nameField.getScene().getWindow();
+            stage.close();
+        });
     }
 
     @FXML
     public void handleSaveAndGoon(ActionEvent event) {
-        save();
-        // 继续新增
-        person = new Person();
-        initFields();
+        save(() -> {
+            // 继续新增
+            person = new Person();
+            initFields();
+        });
     }
 
     @FXML

+ 1 - 1
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/po/GatePersonView.java

@@ -92,7 +92,7 @@ public class GatePersonView extends Selectable{
 
     public void setPersonSex(Integer sex) {
         if (null != sex) {
-            personSexProperty().set(new SexType(sex, 1 == sex ? "男" : "女"));
+            personSexProperty().set(SexType.of(sex));
         }
     }
 

+ 1 - 1
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/po/Person.java

@@ -62,7 +62,7 @@ public class Person {
 
     public void setSex(Integer sex) {
         if (null != sex) {
-            sexProperty().set(new SexType(sex, 1 == sex ? "男" : "女"));
+            sexProperty().set(SexType.of(sex));
         }
     }
 

+ 14 - 10
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/po/SexType.java

@@ -4,11 +4,14 @@ package com.usoftchina.smartschool.device.client.biometric.po;
  * @author yingp
  * @date 2019/11/15
  */
-public class SexType {
-    private Integer value;
-    private String text;
+public enum SexType {
+    MALE(1, "男"),
+    FEMALE(2, "女");
 
-    public SexType(Integer value, String text) {
+    private final Integer value;
+    private final String text;
+
+    SexType(Integer value, String text) {
         this.value = value;
         this.text = text;
     }
@@ -17,16 +20,17 @@ public class SexType {
         return value;
     }
 
-    public void setValue(Integer value) {
-        this.value = value;
-    }
-
     public String getText() {
         return text;
     }
 
-    public void setText(String text) {
-        this.text = text;
+    public static SexType of(Integer value) {
+        for (SexType type : values()) {
+            if (type.getValue().equals(value)) {
+                return type;
+            }
+        }
+        return MALE;
     }
 
     @Override

+ 13 - 14
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/task/GateScheduler.java

@@ -4,6 +4,8 @@ import com.usoftchina.smartschool.device.biometric.BiometricDeviceService;
 import com.usoftchina.smartschool.device.client.biometric.po.FaceGate;
 import com.usoftchina.smartschool.device.client.biometric.po.HealthStatus;
 import com.usoftchina.smartschool.device.client.biometric.service.FaceGateService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -22,25 +24,22 @@ public class GateScheduler {
     private FaceGateService faceGateService;
     @Autowired
     private BiometricDeviceService deviceService;
+    private final Logger logger = LoggerFactory.getLogger(GateScheduler.class);
 
     @Scheduled(fixedDelay = 120000)
     public void pingDevice() {
         List<FaceGate> faceGates = faceGateService.findAll();
         if (!CollectionUtils.isEmpty(faceGates)) {
-            try {
-                faceGates.parallelStream().forEach(faceGate -> {
-                    boolean success = deviceService.ping(faceGate);
-                    if (success) {
-                        faceGate.setLastActiveTime(new Date());
-                        faceGate.setStatus(HealthStatus.HEALTHY.getValue());
-                    } else {
-                        faceGate.setStatus(HealthStatus.UN_HEALTHY.getValue());
-                    }
-                    faceGateService.save(faceGate);
-                });
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            faceGates.parallelStream().forEach(faceGate -> {
+                boolean success = deviceService.ping(faceGate);
+                if (success) {
+                    faceGate.setLastActiveTime(new Date());
+                    faceGate.setStatus(HealthStatus.HEALTHY.getValue());
+                } else {
+                    faceGate.setStatus(HealthStatus.UN_HEALTHY.getValue());
+                }
+                faceGateService.save(faceGate);
+            });
         }
     }
 }

+ 4 - 0
applications/device/device-client-biometric/src/main/java/com/usoftchina/smartschool/device/client/biometric/util/AlertUtils.java

@@ -22,6 +22,10 @@ public class AlertUtils {
         return alert(message, Alert.AlertType.ERROR);
     }
 
+    public static Optional<ButtonType> confirm(String message) {
+        return alert(message, Alert.AlertType.CONFIRMATION);
+    }
+
     public static Optional<ButtonType> alert(String message, Alert.AlertType alertType) {
         Alert alert = new Alert(alertType);
         alert.setHeaderText(null);

BIN
applications/device/device-client-biometric/src/main/resources/style/iconfont.ttf


+ 21 - 1
applications/device/device-client-biometric/src/main/resources/style/main.css

@@ -10,6 +10,15 @@
     -fx-font-family: "Microsoft YaHei";
 }
 
+@font-face {
+    -fx-font-family: "iconfont";
+    src: url('style/iconfont.ttf');
+}
+
+.icon-font {
+    -fx-font-family: "iconfont";
+}
+
 /** tab-pane **/
 .tab {
     -fx-background-insets: 0;
@@ -75,22 +84,32 @@
 .tree-view {
     -fx-background-color: #f8f8fb;
     -fx-border-color: #bfcfda;
+    -fx-padding: 5px 0;
 }
 
 .tree-view .tree-cell {
     -fx-background-color: #f8f8fb;
-    -fx-padding: 6px 0;
+    -fx-padding: 6px 0 6px -11px;
     -fx-text-fill: -fx-dark-color;
     -fx-font-weight: bold;
 }
 
+.tree-view .icon-font {
+    -fx-text-fill: -fx-dark-color;
+    -fx-font-size: 18px;
+}
+
 .tree-cell .tree-disclosure-node .arrow {
     -fx-background-color: transparent;
     -fx-text-fill: transparent;
+    -fx-min-width: 0;
+    -fx-pref-width: 0;
+    -fx-max-width: 0;
 }
 
 .tree-view .tree-cell.tree-cell-leaf {
     -fx-font-weight: normal;
+    -fx-padding: 6px 0 6px 0;
 }
 
 .tree-view .tree-cell.tree-cell-leaf:focused {
@@ -171,6 +190,7 @@ AnchorPane, BorderPane, VBox {
 
 .field-control .field-label {
     -fx-font-weight: bold;
+    -fx-text-fill: #464c5c;
 }
 
 .image-view {

+ 2 - 2
applications/device/device-client-biometric/src/main/resources/view/login.fxml

@@ -11,13 +11,13 @@
             fx:controller="com.usoftchina.smartschool.device.client.biometric.controller.LoginController">
     <children>
         <TextField fx:id="usernameField" layoutX="91.0" layoutY="131.0" prefHeight="43.0" prefWidth="218.0"
-                   promptText="账号">
+                   promptText="账号" onKeyPressed="#handleKeyPressed">
             <font>
                 <Font size="14.0"/>
             </font>
         </TextField>
         <PasswordField fx:id="passwordField" layoutX="92.0" layoutY="190.0" prefHeight="43.0" prefWidth="218.0"
-                       promptText="密码">
+                       promptText="密码" onKeyPressed="#handleKeyPressed">
             <font>
                 <Font size="14.0"/>
             </font>

+ 11 - 4
applications/device/device-client-biometric/src/main/resources/view/main.fxml

@@ -6,10 +6,8 @@
 <?import javafx.scene.control.TreeView?>
 <?import javafx.scene.control.TreeItem?>
 <?import com.usoftchina.smartschool.device.client.biometric.control.NavItem?>
-<?import javafx.scene.control.Tab?>
-<?import javafx.scene.layout.GridPane?>
-<?import javafx.scene.control.ToolBar?>
-<?import javafx.scene.control.Button?>
+<?import com.usoftchina.smartschool.device.client.biometric.control.IconFont?>
+<?import javafx.scene.control.Label?>
 <BorderPane prefHeight="700.0" prefWidth="960.0" stylesheets="/style/main.css"
             xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1"
             fx:controller="com.usoftchina.smartschool.device.client.biometric.controller.MainController">
@@ -19,16 +17,25 @@
                 <TreeItem value="root">
                     <children>
                         <TreeItem expanded="true" value="设备管理">
+                            <graphic>
+                                <IconFont fx:constant="FACE"/>
+                            </graphic>
                             <children>
                                 <NavItem value="人脸闸机" viewPath="/view/gate.fxml"/>
                             </children>
                         </TreeItem>
                         <TreeItem expanded="true" value="人员管理">
+                            <graphic>
+                                <IconFont fx:constant="PERSON"/>
+                            </graphic>
                             <children>
                                 <NavItem value="人员信息" viewPath="/view/person.fxml"/>
                             </children>
                         </TreeItem>
                         <TreeItem expanded="true" value="基础设置">
+                            <graphic>
+                                <IconFont fx:constant="SETTING"/>
+                            </graphic>
                             <children>
                                 <NavItem value="学校信息" viewPath="/view/gate.fxml"/>
                                 <NavItem value="IC卡" viewPath="/view/gate.fxml"/>

+ 5 - 5
applications/device/device-client-biometric/src/main/resources/view/person.fxml

@@ -33,11 +33,11 @@
     <center>
         <TableView fx:id="tableView" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
             <columns>
-                <TableColumn fx:id="classCol" prefWidth="120.0" text="班级"/>
-                <TableColumn fx:id="nameCol" prefWidth="100.0" text="姓名"/>
-                <TableColumn fx:id="sexCol" prefWidth="100.0" text="性别"/>
-                <TableColumn fx:id="cardNoCol" prefWidth="120.0" text="卡号"/>
-                <TableColumn fx:id="createTimeCol" prefWidth="200.0" text="创建时间"/>
+                <TableColumn fx:id="classCol" prefWidth="120.0" minWidth="120" text="班级" style="-fx-alignment: CENTER"/>
+                <TableColumn fx:id="nameCol" prefWidth="100.0" minWidth="100" text="姓名" style="-fx-alignment: CENTER"/>
+                <TableColumn fx:id="sexCol" prefWidth="100.0" text="性别" style="-fx-alignment: CENTER"/>
+                <TableColumn fx:id="cardNoCol" prefWidth="120.0" minWidth="120" text="卡号" style="-fx-alignment: CENTER"/>
+                <TableColumn fx:id="createTimeCol" prefWidth="160.0" minWidth="160" text="创建时间" style="-fx-alignment: CENTER"/>
             </columns>
         </TableView>
     </center>

+ 1 - 1
applications/device/device-sdk-biometric/src/main/java/com/usoftchina/smartschool/device/biometric/BiometricDeviceService.java

@@ -239,7 +239,7 @@ public class BiometricDeviceService implements DeviceApi {
             connect.connect(endpointSocketAddr, 3000);
             isReachable = connect.isConnected();
         } catch (Exception e) {
-            logger.warn("connect error", e);
+            logger.warn(deviceInfo.getIp() + " connect error: " + e.getMessage());
         }
         return isReachable;
     }