HFbwcabinetApi.java 29.4 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 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
package cn.csbr.app.hardware.HFbwcabinet;

import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.gui.page.MainPage;
import cn.csbr.app.gui.page.WelcomePage;
import cn.csbr.app.hardware.BWCabinetTestDll;
import cn.csbr.app.model.LoginUser;
import cn.csbr.app.service.SysUserService;
import cn.csbr.springboot.dao.mapper.DatUserLogMapper;
import cn.csbr.springboot.dao.model.DatUserLog;
import cn.csbr.springboot.dao.model.SysUser;
import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSONArray;
import com.csbr.util.IdUtils;
import com.csbr.util.MD5Util;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import javafx.application.Platform;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import static cn.csbr.app.FxApp.applicationContext;


/**
 * 超高频方法封装类,对于单个柜子
 *
 * @author liwuji
 * @since 2018-12-24
 */

@Component
public class HFbwcabinetApi {


    private WelcomePage welcomePage;
    private MainPage mainPage;
    @Autowired
    private GUIContext guiContext;

    private String rfids = "";
    private String storeguid = ""; //科室CD
    private String quyucd = ""; //区域CD
    private int cabinetType = -1; //柜子类型 1.主柜:上中下三个柜,单锁 2.辅柜:两个门两个锁
    private String cabinetCd = ""; //柜子编号 例:all -1
    private String userId = ""; //用户id
    private String userName = ""; //用户姓名
    private int isFinger; //是否启用指纹id卡验证 0:不启动 1:启用

    public void setIsFinger(int isFinger) {
        this.isFinger = isFinger;
    }

    private volatile boolean runflag = true; //注册指纹时,用来暂时停用指纹和id卡线程

    private int cabinetindex = -1;

    private volatile boolean fingerflag = false;

    private boolean doorflag = false; //门开关的线程
    private volatile boolean cardflag = false;
    private boolean doorOpenflag = false;
    private volatile boolean rfidflag = false; //rfid的读写线程
    @Autowired
    private DatUserLogMapper datUserLogMapper;

    private String logguid;
    //高频的
    private BWCabinetTestDll instance = null;
//    的用这个
//    private BWCabinetTestDll instance = BWCabinetTestDll.instance;
    private static Logger logger = LoggerFactory.getLogger(HFbwcabinetApi.class);

    public static void main(String[] args) {
    }

    public void init(String storeguid, String quyucd, int cabinetindex, int cabinetType, String cabinetCd, GUIContext g, DatUserLogMapper dt) {
        this.storeguid = storeguid;
        this.quyucd = quyucd;
        this.cabinetindex = cabinetindex;
        this.cabinetType = cabinetType;
        this.cabinetCd = cabinetCd;
        this.isFinger = 1;// Integer.valueOf(readFile());;
        this.guiContext = g;
        this.datUserLogMapper = dt;
    }


    public boolean initHardWare() {
        //一个柜子三个线程读卡器的指纹仪以及门状态
        // 加载指纹,刷卡模块
        if (instance.BWConnectFinger(cabinetindex) == 0) {
            logger.info("柜子编号:" + cabinetCd + "指纹连接成功");
            fingerflag = true;
            Thread fingerThread = new Thread(() -> BWQueryFingerNumFuncDo());
            fingerThread.setDaemon(true);
            fingerThread.start();
        } else {
            logger.info("柜子编号:" + cabinetCd + "指纹连接失败");
        }
        if (instance.BWConnectIDCard(cabinetindex) == 0) {
            logger.info("柜子编号:" + cabinetCd + "卡控制器连接成功");
            cardflag = true;
            Thread cardThread = new Thread(() -> BWGetIDCardNumFuncDo());
            cardThread.setDaemon(true);
            cardThread.start();
        } else {
            logger.info("柜子编号:" + cabinetCd + "卡控制器连接失败");
        }
        //加载门状态和rfid读写模块
        if (instance.BWConnectRelay(cabinetindex) == 0) {
            Thread doorThread = new Thread(() -> BWGetCabinetStateFuncDo());//用于防止门之前就被打开了的情况
            doorThread.setDaemon(true);
            doorflag = true;
            doorThread.start();
            logger.info("柜子编号:" + cabinetCd + "控制器连接成功");
        } else {
            logger.info("柜子编号:" + cabinetCd + "控制器连接失败");
        }
        //Cabinetype==-1 时不起用RFID   YYQ 2021/09/09
        if (cabinetType != -1) {
            if (instance.BWConnectRfid(cabinetindex) == 0) {
                rfidflag = true;
                logger.info("柜子编号:" + cabinetCd + "RFID连接成功");
            } else {
                logger.info("柜子编号:" + cabinetCd + "Rfid连接失败");
            }
        }
        return true;
    }

    public boolean closeHardWare() {
        //退出时关闭
        if (cabinetType == 1) {
            fingerflag = false;
            cardflag = false;
            rfidflag = false;
            doorflag = false;
            instance.BWCloseFinger(cabinetindex); //指纹

            instance.BWCloseIDCard(cabinetindex); //指纹
            //instance.BWCloseRelay(cabinetindex);
        } else {
            fingerflag = false;
            cardflag = false;
            rfidflag = false;
            doorflag = false;
//            instance.BWCloseRelay(cabinetindex); //继电器模块   包含锁和灯
            instance.BWCloseFinger(cabinetindex); //指纹
            instance.BWCloseIDCard(cabinetindex);//id卡
            if (cabinetType != -1) {  //为-1时,不启用RFID   yyq 2021/09/09
                instance.BWCloseRfid(cabinetindex); //rfid
            }
            instance.BWCloseRelay(cabinetindex);
        }
        return true;
    }

    public static int BWInitCabinetBWSynFinger(int CabIndex, int nFingerNum) {
        logger.info("初始化硬件开始");
        return new HFbwcabinetApi().instance.BWSynFinger(CabIndex, nFingerNum);
    }

    //初始化硬件
    public static int BWInitCabinet() {
        logger.info("初始化硬件开始");
        return new HFbwcabinetApi().instance.BWInitCabinet();
    }

    //关闭上位机
    public static int BWExitCabinet() {
        return new HFbwcabinetApi().instance.BWExitCabinet();
    }


    //针对关门的操作
    //开关门 1是关锁 0是开锁   1是开门 0是关门
    private void BWGetCabinetStateFuncDo() {
        while (doorflag) {
            doorOpenflag = true;
            IntByReference bLocked = new IntByReference(-1);
            IntByReference bDoorOpened = new IntByReference(-1);
            int flag = instance.BWGetCabinetState(cabinetindex, bLocked, bDoorOpened);
            //   logger.info("柜子编号" + cabinetCd + "的所状态为" + bLocked.getValue() + "门的状态为" + bDoorOpened.getValue());
            if (flag == 1) {
                logger.info("柜子编号:" + cabinetCd + "获取门状态异常");
                continue;
            }
            //为了方便关门先关锁
            if (bDoorOpened.getValue() == 0 && bLocked.getValue() == 0) {
                        instance.BWLockDoor(cabinetindex);
            }
            //再关门关大灯
            if (bDoorOpened.getValue() == 0 && bLocked.getValue() == 1) {
                if (logguid != null) {
                        DatUserLog datUserLog = datUserLogMapper.selectByPrimaryKey(logguid);
                        datUserLog.setClosetime(new Date());
                        datUserLog.setCloseusercode(userId);
                        datUserLog.setCloseusername(userName);
                        datUserLogMapper.updateByPrimaryKeySelective(datUserLog);
                        logguid = null;
                }
                instance.BWCloseAllKeys(cabinetindex);
                doorflag = false;
                doorOpenflag = false;
                rfidflag = true;
                if (cabinetType != -1) {
                        Thread rfidThread = new Thread(() -> {
                            BWQueryRfidTabFunDo();
                        });
                        rfidThread.setDaemon(true);
                        rfidThread.start();
                }
                break;
                }
        }
    }


    //id卡
    private void BWGetIDCardNumFuncDo() {
        //若发生刷卡行为,则对卡号去后台数据库进行校验,校验成功则执行开锁,开灯,获取门状态的线程开始运行
        while (cardflag) {
            if (!runflag) {
                try {
                    Thread.sleep(30);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                continue;
            }
            Pointer outjson_pointer = new Memory(50);
            IntByReference idLength = new IntByReference(-1);
            //logger.info("柜子编号:" + cabinetCd + "准备获取卡信息:" );
            int flag = instance.BWGetIDCardNum(cabinetindex, outjson_pointer, idLength);
            //logger.info("柜子编号:" + cabinetCd + "开始获取卡信息:" );

            //doorOpenflag=true说明开关门线程还在运行中所以不处理
            if (doorOpenflag) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                continue;
            }
            if (flag != 0) {
                continue;
            } else {
                byte[] bytOutjson = outjson_pointer.getByteArray(0, idLength.getValue());
                String cardId = "";
                try {
                    //转化字符编码格式
                    cardId = new String(bytOutjson, "gbk");

                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (StringUtils.isBlank(cardId)) {
                    continue;
                }
                if (isFinger == 1) {
                    //根据卡号去数据库查询有无此人存在
                    SysUser sysUser = new SysUser();
                    sysUser.setCardId(cardId.trim());
                    sysUser.setBizstate("Y");
                    sysUser.setOrgguid(this.storeguid);
                    SysUserService sysUserService = applicationContext.getBean(SysUserService.class);
                    SysUser userFormId = null;
                    if (!guiContext.getCabinetcheckmode().equals("DEPT")) {
                        userFormId = sysUserService.findUserByCardId(sysUser);
                    } else {
                        userFormId = sysUserService.findUserByCardId(sysUser, cabinetCd);//yyq 2021/09/09 增加柜子与科室关系
                    }
                    System.out.println("是否检查到卡:" + (userFormId == null));
                    if (userFormId == null) {
                        instance.BWStartRedLight(cabinetindex, 2);
                        continue;
                    }

                    this.setUserId(userFormId.getGuid());
                    this.setUserName(userFormId.getRealname());
                    DatUserLog datUserLog = new DatUserLog();
                    logguid = IdUtils.getUUID();
                    datUserLog.setGuid(logguid);
                    datUserLog.setLogintime(new Date());
                    datUserLog.setDeptguid(userFormId.getGuid());
                    datUserLog.setCabinet(cabinetCd + "");
                    datUserLog.setLogintype("carid");
                    datUserLog.setStoreguid(guiContext.getStoreguid());
                    datUserLog.setStorename(guiContext.getStorename());
                    datUserLog.setUsercode(userFormId.getLoginuser());
                    datUserLog.setUsername(userFormId.getRealname());
                    datUserLogMapper.insert(datUserLog);


                }
                if (instance.BWUnlockDoor(cabinetindex) == 0) {

                } else {
                    logger.info("柜子编号:" + cabinetCd + "开锁失败");
                }
                doorflag = true;
                doorOpenflag = false;
            }
            try {
                Thread.sleep(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //运行获取当前门状态的线程
            Thread doorThread = new Thread(() -> BWGetCabinetStateFuncDo());
            doorThread.setDaemon(true);
            doorThread.start();

        }
    }

    //指纹
    private void BWQueryFingerNumFuncDo() {
        while (fingerflag) {
            try {
                if (!runflag) {
                    //logger.error("已暂停使用"+cabinetindex+"柜的指纹模块");
                    try {
                        Thread.sleep(30);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    continue;
                }
                IntByReference nFingerNum = new IntByReference(-1);
                if (doorOpenflag) {
                    Thread.sleep(50);
                    continue;
                }
                //logger.info("柜子"+cabinetindex+"开始获取指纹");
                int flag = instance.BWQueryFingerNum(cabinetindex, nFingerNum);
                //若发生按指纹行为,则对卡号去后台数据库进行校验,校验成功则执行开锁,开灯
                //根据卡号去数据库查询有无此人存在
                if (flag == 6) {
                    continue;
                }
                if (isFinger == 1) {
                    if (flag == 4) {
                        instance.BWStartRedLight(cabinetindex, 2);
                        Thread.sleep(30);
                        continue;
                    }
                    SysUser sysUser = new SysUser();
                    sysUser.setFingerprint("" + nFingerNum.getValue());
                    sysUser.setBizstate("Y");
                    sysUser.setOrgguid(this.storeguid);
                    SysUserService sysUserService = applicationContext.getBean(SysUserService.class);
                    SysUser userFormId = null;
                    try {
                        if (!guiContext.getCabinetcheckmode().equals("DEPT")) {
                            userFormId = sysUserService.findUserByFinger(sysUser);
                        } else {
                            userFormId = sysUserService.findUserByFinger(sysUser, cabinetCd);//yyq 2021/09/09 增加柜子与科室关系
                        }
                    } catch (Exception ex) {
                        logger.info("指纹User" + ex.getMessage());
                        userFormId = null;
                    }

                    if (userFormId == null) {
                        instance.BWStartRedLight(cabinetindex, 2);
                        Thread.sleep(30);
                        continue;
                    }
                    // logger.info("获取人员信息"+ JSON.toJSONString(sysUser) +sysUser.getGuid()+sysUser.getRealname());
//                设置当前柜子的开门人
                    this.setUserId(userFormId.getGuid());
                    this.setUserName(userFormId.getRealname());
                    DatUserLog datUserLog = new DatUserLog();
                    logguid = IdUtils.getUUID();
                    datUserLog.setGuid(logguid);
                    datUserLog.setLogintime(new Date());
                    datUserLog.setDeptguid(userFormId.getGuid());
                    System.out.println("kaimen" + cabinetCd);
                    datUserLog.setCabinet(cabinetCd + "");
                    datUserLog.setLogintype("finger");
                    //System.out.println("1"+guiContext.getStoreguid());
                    datUserLog.setStoreguid(guiContext.getStoreguid());
                    //System.out.println("2"+guiContext.getStorename());
                    datUserLog.setStorename(guiContext.getStorename());
                    //System.out.println("3"+guiContext.getLoginUser());
                    datUserLog.setUsercode(userFormId.getLoginuser());
                    // System.out.println("4"+userFormId.getRealname());
                    datUserLog.setUsername(userFormId.getRealname());
                    datUserLogMapper.insert(datUserLog);
                    System.out.println("插入成功");
                }
                //开锁和灯
                instance.BWUnlockDoor(cabinetindex);
                try {
                    Thread.sleep(50);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                doorflag = true;
                doorOpenflag = false;
                //运行获取当前门状态的线程
                Thread doorThread = new Thread(() -> BWGetCabinetStateFuncDo());
                doorThread.setDaemon(true);
                doorThread.start();
            } catch (Exception ex) {
                ex.printStackTrace();
                logger.info("error" + ex.getMessage());
            }
        }
    }


    //rfid读写的数据
    public void BWQueryRfidTabFunDo() {
        synchronized (this) {
            while (rfidflag) {

                String rfidData = "";
                Pointer outjson_pointer = new Memory(102400);
                IntByReference rfidLength = new IntByReference(-1);
                int flag = instance.BWQueryRfidTab(cabinetindex, outjson_pointer, rfidLength);
                if (flag == 6) {
                    logger.info("未读取到柜内rfid");
                    logger.error("获取到的" + cabinetindex + "号柜子的rfid码为空");
                    String rfidmess = rfidBackStructure("", 6);
                    HFHardWaredll.rfidHardWareDataReturnCallback.callback(rfidmess);

                    rfidflag = false;
                    break;
                }
                if (flag == 1) {
                    logger.info("未连接到读取rfid的硬件");
                    break;
                }
                if (rfidLength.getValue() <= 0) {
                    logger.info("未获取到RFID数据");
                    break;
                }

                if (flag == 0) {
                    byte[] bytOutjson = outjson_pointer.getByteArray(0, rfidLength.getValue());
                    try {
                        rfidData = new String(bytOutjson, "gbk");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    logger.info("获取到的" + cabinetindex + "号柜子的rfid码为" + rfidData);
                    String rfidmess = rfidBackStructure(rfidData, 0);
                    rfidflag = false;
                    //释放内存
                    long peer = Pointer.nativeValue(outjson_pointer);
                    Native.free(peer);//手动释放内存
                    Pointer.nativeValue(outjson_pointer, 0);//避免Memory对象被GC时重复执行Nativ.free()方法
                    //回调返回结果
                    HFHardWaredll.rfidHardWareDataReturnCallback.callback(rfidmess);
                    break;
                }
            }
        }
    }

    //进来如果门市开着的,帮他开灯,则在它关闭的时候进行关锁操作
    //开关门 1是关锁 0是开锁   1是开门 0是关门
    private void BWDoorOpend() {
        // daemon.setDaemon(true);
        while (doorflag) {
            try {
                IntByReference bLocked = new IntByReference(-1);
                IntByReference bDoorOpened = new IntByReference(-1);
                int flag = instance.BWGetCabinetState(cabinetindex, bLocked, bDoorOpened);
                //    logger.info("柜子编号"+cabinetindex+"的所状态为LOCK"+ bLocked.getValue()+"门的状态为"+ bDoorOpened.getValue());
                if (flag != 0) {
                    logger.info("无法连接获取" + cabinetindex + "号门状态的");
                }
                if (flag == 0) {

                    //开关门 1是关锁 0是开锁   1是开门 0是关门
                    //若门是关闭的,则不去读rfid,并且执行以下操作
                    if (!doorOpenflag) {
                        if (bDoorOpened.getValue() == 0 && bLocked.getValue() == 1) {
                            break;
                        } else {
                            doorOpenflag = true;
                            // logger.info("柜子编号"+cabinetindex+"的所状态为LOCK"+ bLocked.getValue()+"门的状态为"+ bDoorOpened.getValue()+"opern===ture");

//                        if(cabinetindex==3||cabinetindex==4)
//                        {
//
//                            instance.BWLockDoor(cabinetindex);
//
//                        }

                            continue;
                        }
                    } else {
                        //若门是开着的,进行开灯
//                    if (bDoorOpened.getValue() == 1) {
//                        instance.BWUnlockDoor(cabinetindex);
//                    }
                        //若门关闭,进行关锁,关灯操作
                        if (bDoorOpened.getValue() == 0 && bLocked.getValue() == 0) {
//                        if(!(cabinetindex==3||cabinetindex==4))
//                        {
                            //   System.out.println("1111111");
                            instance.BWLockDoor(cabinetindex);
//                        }
                            // logger.info("柜子编号"+cabinetindex+"的所状态为LOCK"+ bLocked.getValue()+"门的状态为"+ bDoorOpened.getValue()+"关门");

                        }
                        //开关门 1是关锁 0是开锁   1是开门 0是关门
                        else if (bDoorOpened.getValue() == 0 && bLocked.getValue() == 1) {
                            rfidflag = true;
                            System.out.println("222222" + logguid);
                            instance.BWCloseAllKeys(cabinetindex);
                            if (logguid != null) {
                                DatUserLog datUserLog = datUserLogMapper.selectByPrimaryKey(logguid);
                                datUserLog.setClosetime(DateTime.now());
                                datUserLog.setCloseusercode(userId);
                                datUserLog.setCloseusercode(userName);
                                datUserLogMapper.updateByPrimaryKeySelective(datUserLog);
                                logguid = null;
                            }
                            //Cabinetype==-1 时不起用RFID   YYQ 2021/09/09
                            if (cabinetType != -1) {
                                Thread readRfid = new Thread(() -> {
                                    BWQueryRfidTabFunDo();
                                });
                                readRfid.setDaemon(true);
                                readRfid.start();
                            }
                            doorOpenflag = false;
                            doorflag = false;
                            break;
                        } else {
                            //  logger.info("柜子编号"+cabinetindex+"的所状态为LOCK"+ bLocked.getValue()+"门的状态为"+ bDoorOpened.getValue()+"其他状态");
                            try {
                                Thread.sleep(200);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
                try {
                    Thread.sleep(200);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } catch (Exception ex) {
                logger.info(ex.getMessage());
            }
        }
    }

    //构造rfid返回值
    public String rfidBackStructure(String rfidData, int flag) {
        if (flag == 6) {
            rfidData = "1234";
        }
        String str[] = rfidData.split(",");
        List<String> list = Arrays.asList(str);
        JSONArray jsonArray = new JSONArray();
        //构造rfid读写数据,把当前存取的人的id和姓名拼进去
        for (String rfid : list) {
            String jsonObject = "{";
            jsonObject += "QUYUCD:" + this.quyucd;
            jsonObject += ",RFIDCD:" + rfid;
            jsonObject += ",CABINETCD:" + this.cabinetCd;
            jsonObject += ",USERCD:" + this.userId;
            jsonObject += ",USERNAME:" + this.userName;
            jsonObject += "}";

            jsonArray.add(jsonObject);
        }
        return jsonArray.toString();
    }

    //指纹注册

    //获取当前最大指纹号
    public int getBWGetLastFingerNum() {
        IntByReference lastFingerAddress = new IntByReference(-1);
        int flag = instance.BWGetLastFingerNum(5, lastFingerAddress);
        if (flag != 0 && flag!=1) {
            logger.info("获取指纹号失败" + lastFingerAddress.getValue()+":flag="+flag);
            return -2;
        }
        return lastFingerAddress.getValue();
    }

    /*进行指纹注册
     *入参count表示第几次录入指纹
     *返回-1表示读取异常
     */
    public int getFingerImage(int count) {
        System.out.println("开始录入指纹");
        int flag = instance.BWGetFingerImage(5, count);
        System.out.println("指纹录入"+count+"次:返回值="+flag);
        if (flag != 0) {
            return -1;
        }
        return 0;
    }


    /*存储指纹
     *入参lastfinger表示当前写入的指纹号,目前是上一次获得的最大指纹号+1
     * 返回-1表示失败
     */
    public int storageFinger(int lastFinger, int lockControlNum) {
        Integer mainnum= Integer.parseInt(guiContext.getMaincabinetNum());
        //存储指纹信息
        logger.info("开始存储指纹");
        int flag = instance.BWStoreFinger(mainnum, lastFinger);
        if (flag != 0) {
            logger.info(mainnum+"号柜存储指纹失败:"+flag);
            return -1;
        }
        logger.info("存储指纹成功");
        try {
            Thread.sleep(1200);
        } catch (Exception e) {
            logger.info("存储指纹成功" + ",等待时异常" + e.getMessage());
        }
        logger.info("存储指纹开始同步到其余柜子" + String.valueOf(lockControlNum));


        for (int i = 1; i <= lockControlNum; i++) {
            if (i != mainnum) {
                int synFlag = instance.BWSynFinger(i, lastFinger);
                if (synFlag != 0) {
                    logger.info("存储指纹同步到柜子" + i + "失败");
                    return -1;
                }
            }
        }
        logger.info("存储指纹同步到其余柜子成功");
        return 0;
    }


    /*删除指纹
     *入参Fingerid需要删除的指纹的ID(会同步删除所有柜子的)lockControlNum 锁的数量 StartLock开始的柜子 delpc 需要排除的柜子
     * 返回-1表示失败
     */
    public int delFinger(int Fingerid, int lockControlNum) {
        Integer mainnum= Integer.parseInt(guiContext.getMaincabinetNum());
        //删除指纹信息
        for (int i =1; i <= mainnum; i++) {
            int synFlag = instance.BWDelFinger(i, Fingerid);
            System.out.println("指纹"+Fingerid+"删除结果:"+synFlag+"(方法:instance.BWDelFinger("+(i)+", "+Fingerid+"))");
            if (synFlag != 0) {
                logger.info("删除指纹同步到柜子" + i + "失败");
                return -1;
            }
        }
        logger.info("存储指纹同步到其余柜子成功");
        return 0;
    }






    public boolean isRunflag() {
        return runflag;
    }

    public void setRunflag(boolean runflag) {
        if (runflag) {

        }
        this.runflag = runflag;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getStoreguid() {
        return storeguid;
    }

    public void setStoreguid(String storeguid) {
        this.storeguid = storeguid;
    }

    public String getQuyucd() {
        return quyucd;
    }

    public void setQuyucd(String quyucd) {
        this.quyucd = quyucd;
    }

    public int getCabinetType() {
        return cabinetType;
    }

    public void setCabinetType(int cabinetType) {
        this.cabinetType = cabinetType;
    }


    public int getCabinetindex() {
        return cabinetindex;
    }

    public void setCabinetindex(int cabinetindex) {
        this.cabinetindex = cabinetindex;
    }

    public boolean isRfidflag() {
        return rfidflag;
    }

    public void setRfidflag(boolean rfidflag) {
        this.rfidflag = rfidflag;
    }

    public String getCabinetCd() {
        return cabinetCd;
    }

    public void setCabinetCd(String cabinetCd) {
        this.cabinetCd = cabinetCd;
    }

    public boolean isFingerflag() {
        return fingerflag;
    }

    public void setFingerflag(boolean fingerflag) {
        this.fingerflag = fingerflag;
    }

    public boolean isCardflag() {
        return cardflag;
    }

    public void setCardflag(boolean cardflag) {
        this.cardflag = cardflag;
    }

    public String getRfids() {
        return rfids;
    }

    public void setRfids(String rfids) {
        this.rfids = rfids;
    }
}