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

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.myproject.bean.BaseMongoBean;
import com.myproject.bean.qisda.AppendInfo;
import com.myproject.bean.qisda.InquiryShelfBean;
import com.myproject.util.StorageConstants;

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

/**
 * 系统出入库记录
 */
public class DataLog extends BaseMongoBean /*implements Comparable<DataLog>*/ {

    /**
     * 是否是单盘出库(联电指出库项目,默认为false即默认批量出库)
     */
    private boolean singleOut = false;

    /**
     * 是否停止向Qisda发料(已经发送过E状态的任务)
     */
    private boolean stopSendToQisda = false;
    /**
     * 所属料仓
     */
    private String storageName;
    /**
     * 料仓 cid
     */
    private String cid;

    /**
     * 料仓 ID
     */
    private String storageId;

    /**
     * 仓位 ID
     */
    private String posId;

    /**
     * 仓位名称
     */
    private String posName;

    //二维码(Reel ID)
    private String barcode;

    /**
     * 料盘宽度信息
     */
    private int w;

    /**
     * 料盘高度信息
     */
    private int h;

    /**
     * 是否是分盘料卷(Barcode中有CutMap)
     */
    private boolean cutReel;

    /**
     * 紧急物料,指定物料,单独出库物料
     */
    private boolean urgentReel = false;

    /**
     * 缺料补发(使用料串)
     */
    private boolean lessSendReel = false;

    /**
     * 是否是包装料卷
     */
    private boolean packageReel;

    /**
     * 附加信息(DN单,需求单等)
     */
    @JsonIgnore
    private AppendInfo appendInfo = new AppendInfo();

    /**
     * 物料编号
     */
    private String partNumber;

    /**
     *数量(从 barCode 中读取)
     */
    private int num;

    /**
     *  类型:入库StorageConstants.OP.PUT_IN,出库StorageConstants.OP.CHECKOUT
     */
    private int type;

    /**
     * 状态:StorageConstants.OP_STATUS
     */
    private String status;

    /**
     * 位置信息,如料架编号,托盘编号,移栽编号,皮带线编号,机器人编号等
     */
    private String locInfo = "";

    /**
     * 指定批次Id
     */
    private String batchId;

    /**
     * 指定批次显示内容
     */
    private String batchInfo;

    /**
     * 指令来源:站位列表 指定订单工单 MES
     */
    private String sourceType;
    /**
     * 来源 id,
     */
    private String sourceId;

    /**
     *  来源名称
     */
    private String sourceName;

    /**
     * 子来源 ID(单个站位)
     */
    private String subSourceId;
    /**
     * 子来源名称
     */
    private String subSourceInfo;

    /**
     * 创建人
     */
    private String creator;
    /**
     * 操作人
     */
    private String operator;

    /**
     * 出库顺序,补料时需要按此顺序从小到大执行出库
     */
    private int outOrder = 0;

    public String getStorageName() {
        return storageName;
    }

    public void setStorageName(String storageName) {
        this.storageName = storageName;
    }

    public String getCid() {
        return cid;
    }

    public void setCid(String cid) {
        this.cid = cid;
    }

    public String getBarcode() {
        if(barcode == null){
            return "";
        }
        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 getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public int getType() {
        return type;
    }

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

    public String getStatus() {
        return status;
    }

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

    public String getSourceType() {
        return sourceType;
    }

    public void setSourceType(String sourceType) {
        this.sourceType = sourceType;
    }

    public String getSourceId() {
        return sourceId;
    }

    public String getSourceKey(){
        return getSourceType() + getSourceId();
    }

    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }

    public String getSourceName() {
        return sourceName;
    }

    public void setSourceName(String sourceName) {
        this.sourceName = sourceName;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public String getStorageId() {
        if(storageId == null){
            return "";
        }
        return storageId;
    }

    public void setStorageId(String storageId) {
        this.storageId = storageId;
    }

    public String getPosId() {
        if(posId == null){
            return "";
        }
        return posId;
    }

    public void setPosId(String posId) {
        this.posId = posId;
    }

    public String getPosName() {
        return posName;
    }

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

    public String getSubSourceId() {
        return subSourceId;
    }

    public void setSubSourceId(String subSourceId) {
        this.subSourceId = subSourceId;
    }

    public String getSubSourceInfo() {
        return subSourceInfo;
    }

    public void setSubSourceInfo(String subSourceInfo) {
        this.subSourceInfo = subSourceInfo;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    /**
     * 是否被取消
     */
    public boolean isCancel(){
        return StorageConstants.OP_STATUS.CANCEL.name().equals(status);
    }

    /**
     * 是否停止向Qisda发送消息
     */
    public boolean isStopSendToQisda() {
        return stopSendToQisda;
    }

    public void setStopSendToQisda(boolean stopSendToQisda) {
        this.stopSendToQisda = stopSendToQisda;
    }


    public boolean isExecuting(){
        return StorageConstants.OP_STATUS.EXECUTING.name().equals(status);
    }

    public boolean isFinished(){
        return StorageConstants.OP_STATUS.FINISHED.name().equals(status);
    }

    public boolean isWait(){
        return StorageConstants.OP_STATUS.WAIT.name().equals(status);
    }


    public boolean isEnd(){
        return StorageConstants.OP_STATUS.END.name().equals(status);
    }


    /**
     * 是否是入库任务
     */
    public boolean isPutInTask(){
        return StorageConstants.OP.PUT_IN == type;
    }

    /**
     * 是否是出库任务
     */
    public boolean isCheckOutTask(){
        return StorageConstants.OP.CHECKOUT == type;
    }

    /**
     * 超过5分钟的已完成,已取消的任务都不再
     */
    public boolean needRemoveFromCache(){
        if(isFinished() || isCancel()){
            if(System.currentTimeMillis() - super.getUpdateDate().getTime() > 3 * 60 * 1000){
                return true;
            }
        }
        return false;
    }

    /**
     * 超过5秒的任务不再显示
     * @return
     */
    public boolean needRemoveFromShow(){
        if(isFinished() || isCancel()){
            if(System.currentTimeMillis() - super.getUpdateDate().getTime() > 25 * 1000){
                return true;
            }
        }
        return false;
    }

    /**
     * 正在执行的出库任务,如果30秒还未完成,再次发送到客户端
     */
    public boolean needReSendToClient(){
        if(isCheckOutTask() && isExecuting()){
            return System.currentTimeMillis() - super.getUpdateDate().getTime() >= 5 * 60 * 1000;
        }
        return false;
    }

    public String getSourceStr(){
        String sourceStr = "";
        if (!Strings.isNullOrEmpty(sourceName)){
            sourceStr = sourceName;
            if(!Strings.isNullOrEmpty(subSourceInfo)){
                sourceStr = sourceName + " ["+subSourceInfo+"]";
            }
        }
        return sourceStr;
    }

    public String getPosStr(){
        return storageName +"["+posName +"]";
    }
    /**
     * 任务展示字符串
     */
    public String getShowStr(){
        String msg = "";
        if(isPutInTask()){//入库
            msg = "物料["+ partNumber + "] 入库到"+ getPosStr();
        }else{
            String sourceInfo = "";
            if(!Strings.isNullOrEmpty(subSourceInfo)){
                sourceInfo = "站位 ["+subSourceInfo+"] 的";
            }
            if(!Strings.isNullOrEmpty(storageName)){
                msg = sourceInfo + "物料["+partNumber + "] 从"+ getPosStr() + "出库";
            }else{
                msg = sourceInfo + "物料["+partNumber + "] 出库";
            }
        }
        return msg;
    }

    public String getBatchId() {
        return batchId;
    }

    public void setBatchId(String batchId) {
        this.batchId = batchId;
    }

    public String getBatchInfo() {
        return batchInfo;
    }

    public void setBatchInfo(String batchInfo) {
        this.batchInfo = batchInfo;
    }

    /**
     * 是否是站位列表任务
     */
    public boolean isFeederTask(){
        return StorageConstants.TASK_SOURCE.FEEDER.name().equals(getSourceType());
    }

    /**
     * 是否是呆滞料出库任务
     */
    public boolean isInactionTask(){
        return StorageConstants.TASK_SOURCE.INACTION.name().equals(getSourceType());
    }

//    @Override
//    public int compareTo(DataLog o) {
//        return getCreateDate().compareTo(o.getCreateDate());
//    }

    @Override
    public boolean equals(Object o) {
        boolean eq = super.equals(o);
        if(!eq && o != null){
            if(o instanceof DataLog){
                return ((DataLog) o).getId().equals(this.getId());
            }
        }
        return eq;
    }

//    @Override
//    public int hashCode() {
//        return getId().hashCode();
//    }

    public boolean isSingleOut() {
        return singleOut;
    }

    public void setSingleOut(boolean singleOut) {
        this.singleOut = singleOut;
    }

    public AppendInfo getAppendInfo() {
        if(appendInfo == null){
            appendInfo = new AppendInfo();
        }
        return appendInfo;
    }

    public void setAppendInfo(AppendInfo appendInfo) {
        this.appendInfo = appendInfo;
    }

    public int resolveRfidLoc(String loc){
        int rfidLoc = Integer.valueOf(loc);
        if(isLessSendReel()){
            if(appendInfo.isFirstReelAction()){
                rfidLoc = 1;
            }else if(appendInfo.isTailAction()){
                rfidLoc = 2;
            }
        }
        return rfidLoc;
    }

    public int getH() {
        return h;
    }

    public void setH(int h) {
        this.h = h;
    }

    public int getW() {
        return w;
    }

    public void setW(int w) {
        this.w = w;
    }

    /**
     * 是否是小料(7x8)的料
     */
    public boolean isSmallReel(){
        if(w == 7){
            return h == 8 || h == 12;
        }
        return false;
    }

    public boolean isCutReel() {
        return cutReel;
    }

    public void setCutReel(boolean cutReel) {
        this.cutReel = cutReel;
    }

    public boolean isPackageReel() {
        return packageReel;
    }

    public void setPackageReel(boolean packageReel) {
        this.packageReel = packageReel;
    }

    public boolean isUrgentReel() {
        return urgentReel;
    }

    public void setUrgentReel(boolean urgentReel) {
        this.urgentReel = urgentReel;
    }

    public boolean isLessSendReel() {
        return lessSendReel;
    }

    public void setLessSendReel(boolean lessSendReel) {
        this.lessSendReel = lessSendReel;
    }

    /**
     * 获取物料类型,大料小料或者包装料
     * @return
     */
    public int getReelType(){
        if(isPackageReel()){
            return StorageConstants.REEL_TYPE.PACKAGE;
        }else if(isSmallReel()){
            return StorageConstants.REEL_TYPE.SMALL;
        }else{
            return StorageConstants.REEL_TYPE.BIG;
        }
    }

    public String getShelfMapKey(){
        String shelfMapKey = appendInfo.gethSerial();
        if(isUrgentReel()){
            //紧急料放在同一个料串或包装料架上,需求单号使用1
            shelfMapKey = InquiryShelfBean.URGENT_SHELF_MAP_KEY;
        }else if(isCutReel()){
            //分盘料放在同一个料串或包装料架上,需求单号使用2
            shelfMapKey = InquiryShelfBean.CUT_SHELF_MAP_KEY;
        }else if(isLessSendReel()){
            //shelfMapKey = "3";
        }
        return shelfMapKey;
    }

    public String getTempRfid(){
        String tempRfid = getShelfMapKey() + "-" + appendInfo.getRfidIndex() + appendInfo.getShelfType();
        return tempRfid;
    }

    public String getLocInfo() {
        return locInfo;
    }

    public void setLocInfo(String locInfo) {
        this.locInfo = locInfo;
    }

    public int getOutOrder() {
        return outOrder;
    }

    public void setOutOrder(int outOrder) {
        this.outOrder = outOrder;
    }

    /**
     * 是否是在皮带线上
     */
    public boolean isInBelt(){
        return status.toLowerCase().equals("inbelt");
    }

    /**
     * 非等待状态,超过10分钟未更新状态,等待状态,超过30分钟未更新过状态,认为超时
     */
    public boolean isTimeout(){
        long now = System.currentTimeMillis();
        long timeoutTime = 20 * 60 * 1000;
        if(!isWait()){
            timeoutTime = 8 * 60 * 1000;
        }
        return now - getUpdateDate().getTime() > timeoutTime;
    }
}