Barcode.java 15.0 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
package com.myproject.bean.update;

import com.google.common.collect.Lists;
import com.myproject.bean.BaseMongoBean;
import com.myproject.util.DateUtil;
import com.myproject.util.StorageConstants;
import org.springframework.data.annotation.Transient;

import java.util.Date;
import java.util.List;

/**
 * Created by kangmor on 2015/12/1.
 */

/**
 * '[)>@06@12S0002@P5292001000@1P1690215@31P1690215@12V527973628@10VCHN-YANTAI@2P@20P@6D20170626@14D20171223@30PY@ZN@K0@16K0@V815@3SB370000000EZZ@Q500GRM000@20T1@1TMT72543954@2T@1Z@@' 
 * [@xx@xx@partNO.@xx@xx@xx@xx@xx@生产日期@过期日期@xx@xx@xx@xx@xx@psckid唯一码@重量@xx@xx@xx@xc@@' 
 */
public class Barcode extends BaseMongoBean {
    private String barcode;
    /**
     * 物料类型:PCB,锡膏,或其他
     */
    private int type = StorageConstants.COMPONENT_TYPE.COMPONENT;
    //锡膏回温时间,小于回温时间不可出库
    private int warmTime = 0;

    /**
     * 搅拌时间(分钟)
     */
    private int mixTime = 0;

    private float maxStorageTime = 0;
    /**
     * 过期时间(入库时间+最大存储时间)
     */
    private Date expTime;

    //过期状态,-1未入库0在库,1已出库正常,2已出库且已过期
    private int  status = StorageConstants.BARCODE_STATUS.NEW;

    /**
     * 锡膏状态
     */
    private int solderStatus = StorageConstants.SOLDER_STATUS.NONE;

    /**
     * 锡膏指定时间出库
     */
    private Date needOutDate;
    //private int componentType = 0;
    private String partNumber;
    //"供应商编号"
    private String providerNumber;
    private int initialAmount;
    private int amount;
    /**
     * 标签解析出来的数量,用于判断条码是否是重新打印的,重新打印的条码需要重新设置数量
     */
    private int labelAmount = 0;
    private int plateSize;
    private int height;
    private String provider;
    private String batch;
    private String msl;

    //备用字段1(配套单号))或 family
    private String otherField1;
    //备用字段2 (产品型号)
    private String otherField2;
    //备用字段3 (组件型号)
    private String otherField3;
    //备用字段4 (元器件型号)
    private String otherField4;
    //备用字段5 (检验编号)
    private String otherField5;
    //备用字段5 (备注)
    private String otherField6;
    /**
     * 包装上带的过期时间
     */
    private Date expireDate;
    private boolean used = false;

    //备注信息
    private String memo;

    /**
     * 库位信息
     */
    private String posName;

    /**
     * 只能单盘出库
     */
    private boolean onlySingleOut = false;

    /**
     * 贴片机补料信息
     */
    private String nextBarcode;

    /**
     * 第一次入库时间戳
     */
    private long putInTime = -1;

    /**
     * 开始回温时间
     */
    private long startWarmTime = -1;

    /**
     * 入库时间
     */
    private Date putInDate;

    /**
     * 入库操作人
     */
    private String inOpor;

    /**
     * 出库操作人
     */
    private String outOpor;

    /**
     * 最后一次出库的时间
     */
    private Date checkOutDate;

    /**
     * 关联条码,夹具时关联相关的物料,用于入库完成时插入相关物料
     */
    @Transient
    private List<String> relationCodes;

    public int getInitialAmount() {
        if (initialAmount == 0) {
            setInitialAmount(amount);
        }
        return initialAmount;
    }

    public void setInitialAmount(int initialAmount) {
        this.initialAmount = initialAmount;
    }

    /**
     * 上次使用时间(出入库时更改)
     */
    private Date usedDate;
    /**
     * 使用次数(入库后+1)
     */
    private int usedCount = 0;

    /**
     * 生产日期
     */
    private Date produceDate;

    /**
     * 锁定ID(目前只有指定批次会锁定)
     */
    private String lockId;

    /**
     * 锁定名
     */
    private String lockName;

    public String getLockId() {
        return lockId;
    }

    public void setLockId(String lockId) {
        this.lockId = lockId;
    }

    public String getLockName() {
        return lockName;
    }

    public void setLockName(String lockName) {
        this.lockName = lockName;
    }

    public String getBarcode() {
        return barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    public String getPartNumber() {
        return partNumber;
    }

    public void setPartNumber(String partNumber) {
        this.partNumber = partNumber;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public int getPlateSize() {
        return plateSize;
    }

    public void setPlateSize(int plateSize) {
        this.plateSize = plateSize;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public String getProvider() {
        return provider;
    }

    public void setProvider(String provider) {
        this.provider = provider;
    }

    public String getBatch() {
        return batch;
    }

    public void setBatch(String batch) {
        this.batch = batch;
    }

    public Date getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }

    public boolean isUsed() {
        return used;
    }

    public void setUsed(boolean used) {
        this.used = used;
    }

    public Date getProduceDate() {
        return produceDate;
    }

    public void setProduceDate(Date produceDate) {
        this.produceDate = produceDate;
    }

    public int getUsedCount() {
        return usedCount;
    }

    public void setUsedCount(int usedCount) {
        this.usedCount = usedCount;
    }

    public Date getUsedDate() {
        return usedDate;
    }

    public void setUsedDate(Date usedDate) {
        this.usedDate = usedDate;
    }

    public String getProviderNumber() {
        return providerNumber;
    }

    public void setProviderNumber(String providerNumber) {
        this.providerNumber = providerNumber;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    /**
     * 是否是锡膏
     */
    public boolean isSolder(){
        return type == StorageConstants.COMPONENT_TYPE.SOLDERPASTE;
    }

    public int getWarmTime() {
        return warmTime;
    }

    public void setWarmTime(int warmTime) {
        this.warmTime = warmTime;
    }

    public float getMaxStorageTime() {
        return maxStorageTime;
    }

    public void setMaxStorageTime(float maxStorageTime) {
        this.maxStorageTime = maxStorageTime;
    }


    public List<String> getRelationCodes() {
        if (relationCodes == null) {
            return Lists.newArrayList();
        }
        return relationCodes;
    }

    /**
     * 添加相关联条码
     *
     * @param relationCode
     */
    public void addRelationCode(String relationCode) {
        if (relationCodes == null) {
            relationCodes = Lists.newArrayList();
        }
        relationCodes.add(relationCode);
    }

    public long getPutInTime() {
        return putInTime;
    }

    public void setPutInTime(long putInTime) {
        if(this.putInTime == -1){
            this.putInTime = putInTime;
            this.putInDate = new Date(putInTime);
        }

        status = StorageConstants.BARCODE_STATUS.IN_STORE;

        updateExpTime();

    }


    public Date getPutInDate() {
        return putInDate;
    }

    public String getPutInDateStr(){
        if(putInDate == null){
            return "";
        }
        return DateUtil.toDateTimeString(putInDate);
    }

    public void setPutInDate(Date putInDate) {
        this.putInDate = putInDate;
    }

    private void updateExpTime(){
        if(expTime == null && maxStorageTime != 0F && putInTime != -1){
            Float maxStorageTimeMill = maxStorageTime * 60 * 60 * 1000;
            expTime = new Date(putInTime + maxStorageTimeMill.longValue());
            if(expireDate != null){
                //如果是在包装上的过期时间之前,使用包装上的过期时间
                if(expireDate.getTime()< expTime.getTime()){
                    expTime = expireDate;
                }
            }
        }
    }

    /**
     * 到达回温的时间
     */
    public long getReachWarmTime(){
        long reachWarmTime = System.currentTimeMillis();
        if(StorageConstants.COMPONENT_TYPE.SOLDERPASTE == type && putInTime != -1){
            reachWarmTime = putInTime + warmTime * 60 * 60 * 1000;
        }
        return reachWarmTime;
    }

    /**
     * 是否达到回温时间,只有锡膏才需要判定
     */
    public boolean isReachedWarmTime(){
        return getReachWarmTime() <= System.currentTimeMillis();
    }

    public long getInStoreHour(){
        if(putInTime != -1){
            return (System.currentTimeMillis() - putInTime) / 60 / 60 / 1000;
        }
        return 0;
    }

    public long getInStoreMiniute(){
        if(putInTime != -1){
            long minutes = (System.currentTimeMillis() - getPutInTime()) / 60000 % 60;
            if(minutes == 0){
                if(getInStoreHour() == 0){
                    minutes = 1;
                }
            }
            return minutes;
        }
        return 0;
    }

    public String getOtherField2() {
        return otherField2;
    }

    public void setOtherField2(String otherField2) {
        this.otherField2 = otherField2;
    }

    public String getOtherField1() {
        return otherField1;
    }

    public void setOtherField1(String otherField1) {
        this.otherField1 = otherField1;
    }

    public String getOtherField3() {
        return otherField3;
    }

    public void setOtherField3(String otherField3) {
        this.otherField3 = otherField3;
    }

    public String getOtherField4() {
        return otherField4;
    }

    public void setOtherField4(String otherField4) {
        this.otherField4 = otherField4;
    }

    public String getOtherField5() {
        return otherField5;
    }

    public void setOtherField5(String otherField5) {
        this.otherField5 = otherField5;
    }

    public String getOtherField6() {
        return otherField6;
    }

    public void setOtherField6(String otherField6) {
        this.otherField6 = otherField6;
    }

    public Date getCheckOutDate() {
        return checkOutDate;
    }

    public void setCheckOutDate(Date checkOutDate, String opor) {
        this.checkOutDate = checkOutDate;
        this.outOpor = opor;
        if(checkOutDate != null){//出库时判断是否过期
            updateExpTime();
            if(expTime != null && checkOutDate.after(expTime)){
                //过期时间小于出库时间,说明出库的时候已经过期了
                status = StorageConstants.BARCODE_STATUS.OUT_EXPIRED;
            }else{
                status = StorageConstants.BARCODE_STATUS.OUT_NORMAL;
            }
        }
    }

    public Date getExpTime() {
        return expTime;
    }

    public void setExpTime(Date expTime) {
        this.expTime = expTime;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getInOpor() {
        return inOpor;
    }

    public void setInOpor(String inOpor) {
        if(putInTime == -1){
            this.inOpor = inOpor;
        }
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public String getOutOpor() {
        return outOpor;
    }

    public void setOutOpor(String outOpor) {
        this.outOpor = outOpor;
    }

    public String getPosName() {
        return posName;
    }

    public void setPosName(String posName) {
        this.posName = posName;
    }

    public String getNextBarcode() {
        return nextBarcode;
    }

    public void setNextBarcode(String nextBarcode) {
        this.nextBarcode = nextBarcode;
    }

    public boolean isOnlySingleOut() {
        return onlySingleOut;
    }

    public void setOnlySingleOut(boolean onlySingleOut) {
        this.onlySingleOut = onlySingleOut;
    }

    public String getMsl() {
        return msl;
    }

    public void setMsl(String msl) {
        this.msl = msl;
    }

    public int getMixTime() {
        return mixTime;
    }

    public void setMixTime(int mixTime) {
        this.mixTime = mixTime;
    }

    public long getStartWarmTime() {
        return startWarmTime;
    }

    public void setStartWarmTime(long startWarmTime) {
        this.startWarmTime = startWarmTime;
    }

    public int getSolderStatus() {
        if(solderStatus == StorageConstants.SOLDER_STATUS.REWARMING){
            //如果状态是回温中,且回温时间已经大于warmTime,修改状态为待搅拌
            long now = System.currentTimeMillis();
            if(startWarmTime - now >  warmTime * 60 * 60 * 1000){
                solderStatus = StorageConstants.SOLDER_STATUS.TO_BE_MIXED;
            }
        }
        return solderStatus;
    }

    public void setSolderStatus(int solderStatus) {
        this.solderStatus = solderStatus;
    }

    public Date getNeedOutDate() {
        return needOutDate;
    }

    public void setNeedOutDate(Date needOutDate) {
        this.needOutDate = needOutDate;
    }

    public String getNeedOutDateStr(){
        if(needOutDate == null){
            return "";
        }
        return DateUtil.toDateTimeString(needOutDate);
    }

    public String getExpireDateStr(){
        if(expireDate  != null){
            return DateUtil.toDateString(expireDate);
        }
        return "";
    }

    /**
     * 是否已过期
     */
    public boolean isExpired(){
        if(expireDate != null){
            return expireDate.before(new Date());
        }
        return false;
    }

    /**
     * 是否即将(3天内)过期,已过期后,此字段变为false
     */
    public boolean isWillExpired(){
        if(isExpired()){
            return false;
        }
        if(expireDate != null){
            return expireDate.before(DateUtil.addDays(new Date(),3));
        }
        return false;
    }

    public int getLabelAmount() {
        return labelAmount;
    }

    public void setLabelAmount(int labelAmount) {
        this.labelAmount = labelAmount;
    }

    //    public void setNoChangeField(Barcode oldBarcode){
//        if(oldBarcode != null){
//            this.expireDate = oldBarcode.getExpireDate();
//            this.batch = oldBarcode.getBatch();
//            this.checkOutDate = oldBarcode.getCheckOutDate();
//            this.putInTime = oldBarcode.getPutInTime();
//            this.expTime = oldBarcode.getExpTime();
//            this.relationCodes = oldBarcode.getRelationCodes();
//            this.lockId = oldBarcode.getLockId();
//            this.lockName = oldBarcode.getLockName();
//            this.status = oldBarcode.getStatus();
//        }
//    }

}