FxApp.java 18.8 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 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
package cn.csbr.app;

import cn.csbr.app.auth.LoginService;
import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.gui.component.New.table.DomeTable;
import cn.csbr.app.gui.component.New.table.WaitFrm;
import cn.csbr.app.gui.component.check.CheckTable;
import cn.csbr.app.gui.component.common.*;
import cn.csbr.app.gui.handler.CloseAppHandler;
import cn.csbr.app.gui.page.MainPage;
import cn.csbr.app.gui.page.WelcomePage;
import cn.csbr.app.gui.page.query.QueryPage;
import cn.csbr.app.gui.page.setting.Auwinodws;
import cn.csbr.app.gui.util.CsButtonGroup;
import cn.csbr.app.gui.util.DialogUtils;
import cn.csbr.app.hardware.HFbwcabinet.HFHardWaredll;
import cn.csbr.app.hardware.RfidHardWareApiDecisior;
import cn.csbr.app.model.InboundItem;
import cn.csbr.app.model.LoginUser;
import cn.csbr.app.model.TableModelTest;
import cn.csbr.app.util.WindowsUnKeys;
import cn.csbr.configenc.MyEncryptionPropertyResolver;
import com.ulisesbocchio.jasyptspringboot.EncryptablePropertyResolver;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javafx.stage.StageStyle;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

import static cn.csbr.app.gui.util.SystemUtils.getScreenHeight;
import static cn.csbr.app.gui.util.SystemUtils.getScreenWidth;

/**
 * java fx入口方法 。
 * 在javafx启动类中启动springboot环境。这个过程不能反过来。
 */

@SpringBootApplication
public class FxApp extends Application {
    public static ConfigurableApplicationContext applicationContext;

    private FxConfigure fxConfigure;

    private GUIContext context;

    private CloseAppHandler closeAppHandler;

    private RfidHardWareApiDecisior rfidHardWareApiDecisior;

    private WelcomePage welcomePage;

    private MainPage mainPage;

    private Stage stage = null;
    @Autowired
    private LoginService loginService;

    private static Logger log = LoggerFactory.getLogger(LoginService.class);

    public FxApp() {
    }


    public static void main(String[] args) {
        System.setProperty("jna.encoding", "GBK");
        System.setProperty("jna.library.path", "/");
        System.setProperty("jna.debug_load", "false");


        FxApp.launch(args);

    }

    /**
     * 在这个方法中处理spring context启动过程。 这个init方法是javafx提供的。
     * 会在start开始前执行。
     *
     * @throws Exception
     */
    @Override
    public void init() throws Exception {
    }

    /**
     * java fx 提供的应用程序启动方法。
     *
     * @param primaryStage
     *
     * @throws Exception
     */

    public void start1(Stage primaryStage) throws Exception {
        final QueryButtons[] queryButtons = {null};
        // 舞台,容纳scene的容器
        this.stage = primaryStage;

        // 面板,节点放置在面板中央
        StackPane bp = new StackPane();

        HBox imageButton=new HBox();
        imageButton.setUserData("xl");
        imageButton.setTranslateX(300);
        imageButton.setTranslateY(-560);
       // imageButton.setTranslateY(-260);

        imageButton.setStyle("-fx-background-image: url(images/New/tc.png);" +
                "-fx-background-repeat: stretch;" +
                "-fx-background-position: center center;" +
                "-fx-max-height: 28px;-fx-max-width: 40px;");
      //  imageButton.setPickOnBounds(false);
        imageButton.setOnMouseClicked(e->{
            if(queryButtons[0] ==null) {
                queryButtons[0] = new QueryButtons(null,null,null,null);
                queryButtons[0].start(primaryStage);
            }
        });
        bp.setOnMouseClicked(e->{
            if(((Node)e.getTarget()).getUserData()!=null && ((Node)e.getTarget()).getUserData().equals("xl")) {
                return;
            }
            if(queryButtons[0] !=null) {
                queryButtons[0].close();
                queryButtons[0] = null;
            }
            //System.out.println("关闭窗口");
        });
        Image image = new Image(FxApp.class.getResourceAsStream("/cn/csbr/app/logo.png"));// 应用图标
        Label label =new Label("查询");
        label.setFont(Font.font("圆体",28));
        label.setTranslateX(300);
        label.setTranslateY(-645);
        label.setTextFill(Color.WHITE);


        Label userlable=new Label("张三 / 内科2区");
        userlable.setFont(Font.font("12"));
        userlable.setTextFill(Color.rgb(140,140,140));
        userlable.setTranslateX(-265);
        userlable.setTranslateY(-560);
        HBox imagehb1=new HBox();
        imagehb1.setTranslateX(-335);
        imagehb1.setTranslateY(-560);
        imagehb1.setStyle("-fx-background-image: url(images/New/renyuan.png);-fx-background-repeat: stretch;-fx-background-position: center center;");



        Label timelable=new Label("2021.10.28 16:40:00");
        timelable.setFont(Font.font("12"));
        timelable.setTextFill(Color.rgb(140,140,140));
        timelable.setTranslateX(-65);
        timelable.setTranslateY(-560);
        HBox imagehb2=new HBox();
        imagehb2.setTranslateX(-155);
        imagehb2.setTranslateY(-560);
        imagehb2.setStyle("-fx-background-image: url(images/New/24hour.png);-fx-background-repeat: stretch;-fx-background-position: center center;");

        HBox ss=new CssTextfieldn("","商品信息,商品编码,商品名称,高值码过滤",690,40, e->{
            DialogUtils.showAlert("aaaaaaaa",e2->{});
        });
        ss.setMaxHeight(50);
        ss.setMaxWidth(690);
        ss.setTranslateY(-480);


        HBox gys=new CssComBoxn<String>( "供应商",160,50,e->{
            DialogUtils.showAlert("aaaaaaaa",e2->{});
        });
        gys.setMaxHeight(50);
        gys.setMaxWidth(160);
        gys.setTranslateY(-400);
        gys.setTranslateX(-184);

        HBox hg=new CssComBoxn<String>( "货位",160,50,e->{
            DialogUtils.showAlert("aaaaaaaa",e2->{});
        });
        hg.setMaxHeight(50);
        hg.setMaxWidth(160);
        hg.setTranslateY(-400);
        hg.setTranslateX(188);


        DomeTable inboundItemTable = new DomeTable();
        inboundItemTable.setTranslateX(0);
        inboundItemTable.setTranslateY(90);
        inboundItemTable.setMaxWidth(690);
        inboundItemTable.setMinWidth(690);
        inboundItemTable.setMaxHeight(870);
        inboundItemTable.setMinHeight(870);

        inboundItemTable.setOnScroll(e->{

            if(e.getTextDeltaY()<0||e.getDeltaY()<0){
              //  DialogUtils.showAlert("loading",e3->{});
                WaitFrm waitFrm=new WaitFrm();
                new Thread(()->{
                    Platform.runLater(() -> {
                        waitFrm.start(this.stage,0,0,768,1399,3000);
                    });
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException interruptedException) {
                        interruptedException.printStackTrace();
                    }
                    Platform.runLater(() -> {
                        waitFrm.closeFrm();
                    });
                }).start();

                getTestData(inboundItemTable.items,10);
                inboundItemTable.scrollTo(inboundItemTable.items.size()-10);
            }
        });
        List<TableModelTest> list=new ArrayList<>();
        inboundItemTable.updateDatas(getTestData(list,10));

      //  Label countlabel=new Label("总数:10");

        Button btn1 = CsButtonGroup.createButton("返回", "icon/icon_back.png");
        btn1.setStyle("-fx-border-width: 1 1 1 1;-fx-border-style: solid;-fx-border-color: #5BA7AA;-fx-border-radius:5px ");
        Button btn2 = CsButtonGroup.createButton("顶部", "images/New/top.png");
        btn2.setStyle("-fx-border-width: 1 1 1 1;-fx-border-style: solid;-fx-border-color: #5BA7AA;-fx-border-radius:5px ");
        btn1.setOnMouseClicked(e->{
            DialogUtils.showAlert("返回",e1->{

            });
        });
        btn2.setOnMouseClicked(e->{
            inboundItemTable.scrollTo(0);
        });
        imagehb1.setPickOnBounds(false);
        userlable.setPickOnBounds(false);
        imagehb2.setPickOnBounds(false);
        timelable.setPickOnBounds(false);
        ss.setPickOnBounds(false);
        gys.setPickOnBounds(false);
        hg.setPickOnBounds(false);

        bp.getChildren().addAll(imageButton,label,imagehb1,userlable,imagehb2,timelable,ss,gys,hg,inboundItemTable,btn1,btn2);
        btn1.setTranslateY(580);
        btn1.setTranslateX(100);
        btn2.setTranslateY(580);
        btn2.setTranslateX(-80);
        primaryStage.setFullScreen(true);
        primaryStage.getIcons().add(image);
        primaryStage.setTitle("耗材柜管理应用");
        primaryStage.setMinWidth(768);
        primaryStage.setMinHeight(1366);

        bp.setStyle("-fx-background-image: url(/images/New/main_bg.jpg);-fx-background-repeat: stretch;-fx-background-position: center center;");

        bp.setMinWidth(getScreenWidth());
        bp.setMinHeight(getScreenHeight());

        // 场景
        Scene scene = new Scene(bp);
        scene.getStylesheets().add(getClass().getResource("/styles/commonNew.css").toExternalForm());
        primaryStage.setScene(scene);
        // 展示内容放置在置中
        primaryStage.centerOnScreen();
        primaryStage.setMaximized(true);
        primaryStage.show();
    }
    public List<TableModelTest> getTestData(List<TableModelTest> oldls,int count){
        for(int i=0;i<count;i++){
            TableModelTest item5=new TableModelTest();
            item5.setLeft("序号,"+(i+oldls.size()));
            item5.setCentre("追溯码,Xddkdafefkafa;");
            item5.setRight("供应商,上海国药");
            TableModelTest item4=new TableModelTest();
            item4.setLeft("批号,20121224001,2012-12-24,2015-12-24");
            item4.setCentre("商品,YY00001,一次性碗筷,套,武汉链享医药有限公司,准准准准准准准准准准准准");
            item4.setRight("库存,一套,货位,A-01");
            oldls.add(item5);
            oldls.add(item4);
        }
        return oldls;
    }
   // @Override
    public void start(Stage primaryStage) throws Exception {
        // 舞台,容纳scene的容器
        this.stage = primaryStage;

        // 面板,节点放置在面板中央
        StackPane bp = new StackPane();
        Timer timer = new Timer();

        Thread thread = new Thread(() -> {
            applicationContext = SpringApplication.run(this.getClass());

            FxApp.applicationContext.getBeanFactory().autowireBean(this);

            context = applicationContext.getBean(GUIContext.class);
            context.setPrimaryStage(stage);
            Platform.runLater(() -> {
                // 取消定时器
                timer.cancel();

                //welcomePage = applicationContext.getBean(WelcomePage.class);
                mainPage = applicationContext.getBean(MainPage.class);
                LoginUser user = new LoginUser();
                log.info("登录开始");
                // 调用登录方法
                boolean logintrue=false;
                while (!logintrue) {
                    try{
                    loginService.login(user);
                        logintrue=true;
                    }
                    catch (Exception ex)
                    {log.info(ex.getMessage());

                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
                // 将欢迎页面的场景图节点添加到面板的子类中
                bp.getChildren().clear();
                //bp.getChildren().add(welcomePage.getContent());
                bp.getChildren().add(mainPage.getContent());

                // 刷新欢迎界面
                //welcomePage.refresh();
                // 刷新主界面
                mainPage.refresh();

                bp.setMinWidth(getScreenWidth());
                bp.setMinHeight(getScreenHeight());

                // 公共信息类设置主面板为欢迎页面
                context.setMainPane(bp);

                closeAppHandler = applicationContext.getBean(CloseAppHandler.class);

                primaryStage.setOnCloseRequest(closeAppHandler);
                //sendTheread.start();
            });
        });

        thread.start();

        Image image = new Image(FxApp.class.getResourceAsStream("/cn/csbr/app/logo.png"));// 应用图标

        primaryStage.setFullScreen(true);
        primaryStage.getIcons().add(image);
        primaryStage.setTitle("耗材柜管理应用");
        primaryStage.setMinWidth(getScreenWidth());
        primaryStage.setMinHeight(getScreenHeight());

        Label label = new Label();
        label.setText("系统正在启动中,请稍候   ");
        label.setStyle("-fx-font-size: 3em; -fx-font-weight: bold;");

        // 加载效果
        timer.schedule(new TimerTask() {
            int index = 0;

            @Override
            public void run() {
                Platform.runLater(() -> {
                    index++;
                    String temp = "";

                    for (int i = 0; i < index; i++) {
                        temp += ".";
                    }

                    for (int i = index; i < 3; i++) {
                        temp += " ";
                    }

                    label.setText("系统正在启动中,请稍候" + temp);

                    if (index >= 3) {
                        index = 0;
                    }
                });
            }
        }, 300, 1000);

        bp.getChildren().add(label);
        bp.setStyle("-fx-background-image: url(/images/New/main_bg.png);-fx-background-repeat: stretch;-fx-background-position: center center;");

        bp.setMinWidth(getScreenWidth());
        bp.setMinHeight(getScreenHeight());

        // 场景
        Scene scene = new Scene(bp);
       // scene.getStylesheets().add(getClass().getResource("/styles/common.css").toExternalForm());
        scene.getStylesheets().add(getClass().getResource("/styles/commonNew.css").toExternalForm());
        primaryStage.setScene(scene);
        scene.setOnKeyPressed(e->{
            if(context!=null) {
                if (context.getCurrentPage() != null)
                    if (context.getCurrentPage().getTitle()!=null&&(context.getCurrentPage().getTitle().equals("main_page"))) {
                        for (int i = 0; i < context.getCurqjaj().size(); i++) {
                            if (context.getCurqjaj().get(i).equals(e.getCode().getName())) {
                                return;
                            }
                        }
                        context.getCurqjaj().add(e.getCode().getName());
                        if(context.getCurqjaj().size()==this.context.getYckjj().size()){
                            for(int i=0;i<context.getCurqjaj().size();i++){
                                if(!context.getCurqjaj().get(i).equals(context.getYckjj().get(i))){
                                    return;
                                }
                            }
                            if(context.getKjjispwd().equals("是")){
                                Auwinodws auwinodws = new Auwinodws(primaryStage,context);
                            }else {
                                primaryStage.setIconified(true);
                            }
                        }
                    }
            }
        });
        scene.setOnKeyReleased(e->{
            if(context!=null) {
                if (context.getCurrentPage() != null&&context.getCurrentPage().getTitle()!=null)
                    if ((context.getCurrentPage().getTitle().equals("main_page"))) {
                        for (int i = 0; i < context.getCurqjaj().size(); i++) {
                            if (context.getCurqjaj().get(i).equals(e.getCode().getName())) {
                                System.out.println(context.getCurqjaj().get(i) + "被移除");
                                context.getCurqjaj().remove(i);
                                break;
                            }
                        }
                    }
            }
        });
        // 展示内容放置在置中
        primaryStage.centerOnScreen();
        primaryStage.setMaximized(true);
        // 无边框
        // primaryStage.initStyle(StageStyle.UNDECORATED);
       //   primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);//去掉esc提示
        // WindowsUnKeys.blockWindowsKey();//屏蔽按键
    //    WindowsUnKeys.unblockWindowsKey();//取消屏蔽
        // 将舞台中的内容展示出来
        primaryStage.show();
    }
    private static Logger logger = LoggerFactory.getLogger(HFHardWaredll.class);
    @Override
    public void stop() throws Exception {
        super.stop();

        try {
            logger.info("开始关闭硬件");
            // 关闭硬件
            this.rfidHardWareApiDecisior = applicationContext.getBean(RfidHardWareApiDecisior.class);

            this.rfidHardWareApiDecisior.instance().closeHardWare();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 /*   @Bean
    public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer(){
        PropertyPlaceholderConfigurer placeholderConfigurer=new MyPropertyPlaceholderConfigurer();
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource resource = resolver.getResource("classpath:application-test.properties");
        Resource resource2 = resolver.getResource("classpath:application.properties");
        placeholderConfigurer.setLocations(resource2,resource);

        return placeholderConfigurer;
    }*/

    @Bean
    public EncryptablePropertyResolver encryptablePropertyResolver() {

        return new MyEncryptionPropertyResolver();
    }

}