001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.hayabusa.report2; 017 018import java.io.File; 019 020import org.opengion.hayabusa.db.DBTableModel; 021 022/** 023 * 帳票処理要求を管理するキューオブジェクトです。 024 * このオブジェクトでは、帳票の定義及びデータと、処理中に発生したエラーメッセージを管理します。 025 * また、このキューを生成したオブジェクトもこのオブジェクトにセットされます。 026 * 027 * @og.group 帳票システム 028 * 029 * @version 4.0 030 * @author Hiroki.Nakamura 031 * @since JDK1.6 032 */ 033public class ExecQueue { 034 035 /** 実行方法 {@value} */ 036 protected static final String OUT_ODS_ONLY = "1"; 037 /** 実行方法 {@value} */ 038 protected static final String OUT_PRINT_ONLY = "2"; 039 /** 実行方法 {@value} */ 040 protected static final String OUT_ODS_PRINT = "3"; 041 /** 実行方法 {@value} */ 042 protected static final String OUT_ODS_PDF = "P"; 043 /** 実行方法 {@value} */ 044 protected static final String OUT_ODS_PRINT_PDF = "Q"; 045 /** 実行方法 {@value} */ 046 protected static final String OUT_ODS_EXCEL = "E"; 047 /** 実行方法 {@value} */ 048 protected static final String OUT_ODS_ODS = "S"; // 4.3.3.4 (2008/11/01) 追加 049 /** 実行方法 {@value} */ 050 protected static final String IN_INPUT_ONLY = "5"; 051 /** 実行方法 {@value} */ 052 protected static final String IN_EXEC_ONLY = "6"; 053 /** 実行方法 {@value} */ 054 protected static final String IN_INPUT_EXEC = "7"; 055 /** 実行方法 {@value} */ 056 protected static final String RFID_PRINT = "A"; 057 /** 実行方法 {@value} */ 058 protected static final String RFID_ALLPRINT = "B"; 059 /** 実行方法 {@value} */ 060 protected static final String RFID_ALLERASE = "C"; 061 /** 実行方法 {@value} */ 062 protected static final String RFID_SEQERASE = "D"; 063 064 // 5.9.0.0 (2015/09/04) CSV出力対応 065 /** 実行方法 {@value} */ 066 protected static final String CSV_PRINT = "G"; 067 /** 実行方法 {@value} */ 068 protected static final String CSV_PRINT_EXCEL = "H"; 069 /** 実行方法 {@value} */ 070 protected static final String CSV_PRINT_PDF = "I"; 071 /** 実行方法 {@value} */ 072 protected static final String CSV_PRINT_EXCEL2 = "J"; // 5.9.4.2 (2016/01/15) EXCEL2追加 073 074 /** 最大シート数 {@value} */ 075 protected static final int MAX_SHEETS_PER_FILE = 256; // 5.1.2.0 (2010/01/01) 076 077 private String ykno = null; 078 private String systemId = null; 079 private DBTableModel body = null; 080 private DBTableModel header = null; 081 private DBTableModel footer = null; 082 private String listId = null; 083 private String pdfPasswd = null; 084 private String lang = null; 085 private String threadId = null; 086 private String templateName = null; 087 private String outputType = null; 088 private String printerName = null; 089 private String outputName = null; 090 private boolean fglocal = false; 091 private boolean fgcut = false; 092 private QueueManager manager = null; 093 private String prgdir = null; // 4.3.3.0 (2008/10/01) 板金RFID対応。 094 private String prgfile = null; // 4.3.3.0 (2008/10/01) 095 private String prtid = null; // 4.3.3.0 (2008/10/01) 096 097 private String grpid = null; // 5.9.2.2 (2015/11/20) 098 private String dmngrp = null; // 5.9.2.2 (2015/11/20) 099 100 private int pageCnt = 0; // 5.1.2.0 (2010/01/01) 処理したページ数 101 private int rowCnt = 0; // 5.1.2.0 (2010/01/01) 処理した行数 102 private boolean isDataEnd = false; // 5.1.2.0 (2010/01/01) 全データが処理されたか (メソッド名と同じ変数名変更) 103 104 private boolean useSheetName = false; // 5.7.6.2 (2014/05/16) PAGEBREAKカラムの値を、シート名として使うかどうか。 105 106 private final StringBuilder errMsg = new StringBuilder(); 107 108 /** 109 * 要求NOをセットします。 110 * 111 * @param ykno 要求NO 112 */ 113 public void setYkno( final String ykno ) { 114 this.ykno = ykno; 115 } 116 117 /** 118 * 要求NOを取得します。 119 * 120 * @return 要求NO 121 */ 122 public String getYkno() { 123 return ykno; 124 } 125 126 /** 127 * システムIDをセットします。 128 * 129 * @param systemId システムID 130 */ 131 public void setSystemId( final String systemId ) { 132 this.systemId = systemId; 133 } 134 135 /** 136 * システムIDを取得します。 137 * 138 * @return StringシステムID 139 */ 140 public String getSystemId() { 141 return systemId; 142 } 143 144 /** 145 * ボディー部分のDBTableModelをセットします。 146 * 147 * @param body DBTableModelオブジェクト 148 */ 149 public void setBody( final DBTableModel body ) { 150 this.body = body; 151 } 152 153 /** 154 * ボディー部分のDBTableModelを取得します。 155 * 156 * @return ボディー部分のDBTableModelオブジェクト 157 */ 158 public DBTableModel getBody() { 159 return body; 160 } 161 162 /** 163 * ヘッダー部分のDBTableModelをセットします。 164 * 165 * @param header DBTableModelオブジェクト 166 */ 167 public void setHeader( final DBTableModel header ) { 168 this.header = header; 169 } 170 171 /** 172 * ヘッダー部分のDBTableModelを取得します。 173 * 174 * @return ヘッダー部分のDBTableModelオブジェクト 175 */ 176 public DBTableModel getHeader() { 177 return header; 178 } 179 180 /** 181 * フッター部分のDBTableModelをセットします。 182 * 183 * @param footer DBTableModelオブジェクト 184 */ 185 public void setFooter( final DBTableModel footer ) { 186 this.footer = footer; 187 } 188 189 /** 190 * フッター部分のDBTableModelを取得します。 191 * 192 * @return フッター部分のDBTableModelオブジェクト 193 */ 194 public DBTableModel getFooter() { 195 return footer; 196 } 197 198 /** 199 * 帳票IDをセットします。 200 * 201 * @param listId 帳票ID 202 */ 203 public void setListId( final String listId ) { 204 this.listId = listId; 205 } 206 207 /** 208 * 帳票IDを取得します。 209 * 210 * @return 帳票ID 211 */ 212 public String getListId() { 213 return listId; 214 } 215 216 /** 217 * PDFパスワードをセットします。 218 * 219 * @param pdfPasswd PDFパスワード 220 */ 221 public void setPdfPasswd( final String pdfPasswd ) { 222 this.pdfPasswd = pdfPasswd; 223 } 224 225 /** 226 * PDFパスワードを取得します。 227 * 228 * @return PDFパスワード 229 */ 230 public String getPdfPasswd() { 231 return pdfPasswd; 232 } 233 234 /** 235 * 言語をセットします。 236 * 237 * @param lang 言語 238 */ 239 public void setLang( final String lang ) { 240 this.lang = lang; 241 } 242 243 /** 244 * 言語を取得します。 245 * 246 * @return 言語 247 */ 248 public String getLang() { 249 return lang; 250 } 251 252 /** 253 * 雛形ファイル名をセットします。 254 * 255 * @param templateName 雛形ファイル名 256 */ 257 public void setTemplateName( final String templateName ) { 258 this.templateName = templateName; 259 } 260 261 /** 262 * 雛形ファイル名を取得します。 263 * 264 * @return 帳票雛形ファイル名 265 */ 266 public String getTemplateName() { 267 return templateName; 268 } 269 270 /** 271 * 実行方法をセットします。 272 * 273 * @param outputType 実行方法 274 */ 275 public void setOutputType( final String outputType ) { 276 this.outputType = outputType; 277 } 278 279 /** 280 * 出力タイプを取得します。 281 * 282 * @return 出力タイプ 283 */ 284 public String getOutputType() { 285 return outputType; 286 } 287 288 /** 289 * プリンター名をセットします。 290 * 291 * @param printerName プリンター名 292 */ 293 public void setPrinterName( final String printerName ) { 294 this.printerName = printerName; 295 } 296 297 /** 298 * プリンター名を取得します。 299 * 300 * @return プリンタ名 301 */ 302 public String getPrinterName() { 303 return printerName; 304 } 305 306 /** 307 * 処理要求を処理するスレッドIDをセットします。 308 * 309 * @param threadId スレッドID 310 */ 311 public void setThreadId( final String threadId ) { 312 this.threadId = threadId; 313 } 314 315 /** 316 * 処理要求を処理するスレッドIDを取得します。 317 * 318 * @return スレッドID 319 */ 320 public String getThreadId() { 321 return threadId; 322 } 323 324 /** 325 * 出力ファイル名をセットします。 326 * 327 * @param outputName 出力ファイル名 328 */ 329 public void setOutputName( final String outputName ) { 330 this.outputName = outputName; 331 } 332 333 /** 334 * 出力ファイル名を設定します。 335 * GE50に設定されていない場合は第四引数(要求番号)を利用する。 336 * その場合、タイプに応じた拡張子が自動設定される。 337 * 338 * ".xls" : OUT_ODS_EXCEL 339 * ".pdf" : OUT_ODS_PDF , OUT_ODS_PRINT_PDF 340 * ".ods" : OUT_ODS_ODS 341 * ".xml" : RFID_PRINT , RFID_ALLPRINT , RFID_ALLERASE , RFID_SEQERASE 342 * ".csV" : CSV_PINT , CSV_PRINT_EXCEL , CSV_PRINT_PDF 343 * 344 * @og.rev 4.3.3.4 (2008/11/01) ODS出力対応 345 * @og.rev 5.4.3.0 (2011/12/26) RFIDデフォルト対応 346 * @og.rev 5.4.4.1 (2012/02/03) RFID拡張子変更 347 * @og.rev 5.9.0.0 (2015/09/04) CSV対応 348 * 349 * @param outputDir 出力ディレクトリ名 350 * @param outputFile 出力ファイル名 351 * @param type タイプ 352 * @param yokyu 要求番号(ファイル名が指定されていない場合のファイル名) 353 * 354 */ 355 public void setOutputName( final String outputDir, final String outputFile, final String type, final String yokyu ){ 356 StringBuilder filePath = new StringBuilder(); 357 filePath.append( outputDir + File.separator ); 358 359 if( outputFile == null || outputFile.length() == 0 ){ // ファイル名が指定されていない場合は要求番号を利用する。 360 if( OUT_ODS_EXCEL.equals( type ) ){ 361 filePath.append( yokyu ); 362 filePath.append( ".xls" ); 363 } 364 else if( OUT_ODS_PDF.equals( type ) || OUT_ODS_PRINT_PDF.equals( type ) ){ 365 filePath.append( yokyu ); 366 filePath.append( ".pdf" ); 367 } 368 // 4.3.3.4 (2008/11/01) 追加 369 else if( OUT_ODS_ODS.equals ( type ) ){ 370 filePath.append( yokyu ); 371 filePath.append( ".ods" ); 372 } 373 // 5.4.3.0 (2011/12/26) 追加 374 // 5.4.4.2 (2012/02/03) .txtではなく.xml 375 else if( ExecQueue.RFID_PRINT.equals( type ) || ExecQueue.RFID_ALLPRINT.equals( type ) 376 || ExecQueue.RFID_ALLERASE.equals( type ) || ExecQueue.RFID_SEQERASE.equals( type ) ) { 377 filePath.append( yokyu ); 378 filePath.append( ".xml" ); //txt-xml 379 } 380 // 5.9.0.0 (2015/09/04) 追加 381 // 5.9.4.2 (2016/01/13) EXCEL2追加 382 else if( ExecQueue.CSV_PRINT.equals( type ) || ExecQueue.CSV_PRINT_EXCEL.equals( type ) 383 || ExecQueue.CSV_PRINT_PDF.equals( type ) || ExecQueue.CSV_PRINT_EXCEL2.equals( type ) ) { 384 filePath.append( yokyu ); 385 filePath.append( ".csv" ); 386 } 387 } 388 else { 389 filePath.append( outputFile ); 390 } 391 392 this.outputName = filePath.toString(); 393 } 394 395 /** 396 * 出力ファイル名を取得します。 397 * 398 * @og.rev 5.1.2.0 (2010/01/01) 256シートを超える場合に対応。2ファイル目以降は、_1、_2・・・をファイル名の後ろにつける 399 * 400 * @return 出力先ファイル名 401 */ 402 public String getOutputName() { 403 if( pageCnt <= MAX_SHEETS_PER_FILE ) { 404 return outputName; 405 } 406 else { 407 StringBuilder fileName = new StringBuilder(); 408 409 int idx = outputName.lastIndexOf( '.' ); 410 String name = outputName.substring( 0, idx ); 411 String suffix = outputName.substring( idx ); 412 int addNo = (int)Math.ceil( (double)pageCnt/(double)MAX_SHEETS_PER_FILE ) - 1; 413 414 fileName.append( name ).append( "_" ).append( addNo ).append( suffix ); 415 416 return fileName.toString(); 417 } 418 } 419 420 /** 421 * 実行ファイルディレクトリを指定します。 422 * 423 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 424 * 425 * @param dir ディレクトリ 426 */ 427 public void setPrgDir( final String dir ) { 428 this.prgdir = dir; 429 } 430 431 /** 432 * 実行ファイルディレクトリを取得します。 433 * 434 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 435 * 436 * @return プログラムディレクトリ 437 */ 438 public String getPrgDir() { 439 return prgdir; 440 } 441 442 /** 443 * 実行ファイル名をセットします。 444 * 445 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 446 * @param file ファイル名 447 */ 448 public void setPrgFile( final String file ) { 449 this.prgfile = file; 450 } 451 452 /** 453 * 実行ファイル名を取得します。 454 * 455 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 456 * 457 * @return プログラムファイル名 458 */ 459 public String getPrgFile() { 460 return prgfile; 461 } 462 463 /** 464 * プリンタIDをセットします。 465 * 466 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 467 * @param id プリンタID 468 */ 469 public void setPrtId( final String id ) { 470 this.prtid = id; 471 } 472 473 /** 474 * プリンタIDを取得します。 475 * 476 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 477 * 478 * @return プリンタID 479 */ 480 public String getPrtId() { 481 return prtid; 482 } 483 484 /** 485 * グループIDをセットします。 486 * 487 * @og.rev 5.9.2.2 (2015/11/20) 488 * @param id グループID 489 */ 490 public void setGrpId( final String id ) { 491 this.grpid = id; 492 } 493 494 /** 495 * グループIDを取得します。 496 * 497 * @og.rev 5.9.2.2 (2015/11/20) 498 * 499 * @return グループID 500 */ 501 public String getGrpId() { 502 return grpid; 503 } 504 505 /** 506 * デーモングループをセットします。 507 * 508 * @og.rev 5.9.2.2 (2015/11/20) 509 * @param name デーモングループ 510 */ 511 public void setDmnGrp( final String name ) { 512 this.dmngrp = name; 513 } 514 515 /** 516 * デーモングループを取得します。 517 * 518 * @og.rev 5.9.2.2 (2015/11/20) 519 * 520 * @return デーモングループ 521 */ 522 public String getDmnGrp() { 523 return dmngrp; 524 } 525 526 527 /** 528 * ローカルリソース使用フラグをセットします(初期値:false)。 529 * 530 * @param fglocal ローカルリソース使用フラグ[true:使用する/false:使用しない] 531 */ 532 public void setFglocal( final boolean fglocal ) { 533 this.fglocal = fglocal; 534 } 535 536 /** 537 * ローカルリソース使用フラグを取得します。 538 * 539 * @return ロールリソース使用フラグ[true:使用する/false:使用しない] 540 */ 541 public boolean isFglocal() { 542 return fglocal; 543 } 544 545 /** 546 * ページエンドカットフラグをセットします(初期値:false)。 547 * 548 * @param fgcut ページエンドカットの使用可否[true:使用/false:通常] 549 */ 550 public void setFgcut( final boolean fgcut ) { 551 this.fgcut = fgcut; 552 } 553 554 /** 555 * ページエンドカットフラグを取得します。 556 * 557 * @return ページエンドカットフラグ 558 */ 559 public boolean isFgcut() { 560 return fgcut; 561 } 562 563 /** 564 * PAGEBREAKカラムの値を、シート名として使うかどうかをセットします(初期値:false)。 565 * 566 * @og.rev 5.7.6.2 (2014/05/16) 新規追加 567 * 568 * @param useSheetName PAGEBREAKカラムのシート名使用可否[true:使用/false:使用しない] 569 */ 570 public void setUseSheetName( final boolean useSheetName ) { 571 this.useSheetName = useSheetName; 572 } 573 574 /** 575 * PAGEBREAKカラムの値を、シート名として使うかどうかを取得します。 576 * 577 * @og.rev 5.7.6.2 (2014/05/16) 新規追加 578 * 579 * @return PAGEBREAKカラムのシート名使用可否[true:使用/false:使用しない] 580 */ 581 public boolean isUseSheetName() { 582 return useSheetName; 583 } 584 585 /** 586 * キューマネージャーをセットします。 587 * 588 * @param manager キューマネージャー 589 */ 590 public void setManager( final QueueManager manager ) { 591 this.manager = manager; 592 } 593 594 /** 595 * 帳票処理データをセットします。 596 * 既にテーブルモデルがセットされている場合は、再セットしません。 597 * 598 */ 599 public void setData() { 600 if( body == null && manager != null ) { 601 manager.set( this ); 602 } 603 } 604 605 /** 606 * キューを実行中の状態に更新します。 607 * 608 */ 609 public void setExecute() { 610 if( manager != null ) { 611 manager.execute( this ); 612 } 613 } 614 615 /** 616 * キューを完了済の状態に更新します。 617 * 618 */ 619 public void setComplete() { 620 if( manager != null ) { 621 manager.complete( this ); 622 } 623 } 624 625 /** 626 * キューをエラーの状態に更新します。 627 */ 628 public void setError() { 629 if( manager != null ) { 630 manager.error( this ); 631 } 632 } 633 634 /** 635 * エラーメッセージをセットします。 636 * 637 * @param msg エラーメッセージ 638 */ 639 public void addMsg( final String msg ) { 640 errMsg.append( msg ); 641 } 642 643 /** 644 * エラーメッセージを取得します。 645 * 646 * @return エラーメッセージ 647 */ 648 public String getMsg() { 649 return errMsg.toString(); 650 } 651 652 /** 653 * 処理したページ数を引数の分だけカウントアップします。 654 * 655 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 656 * 657 * @param pgs カウントアップするページ数 658 */ 659 public void addExecPageCnt( final int pgs ) { 660 pageCnt += pgs; 661 } 662 663 /** 664 * 処理したページ数を返します。 665 * 666 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 667 * 668 * @return 処理したページ数 669 */ 670 public int getExecPagesCnt() { 671 return pageCnt; 672 } 673 674 /** 675 * 処理した行数をセットします。 676 * 677 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 678 * 679 * @param rws 処理した行数 680 */ 681 public void setExecRowCnt( final int rws ) { 682 rowCnt = rws; 683 } 684 685 /** 686 * 処理した行数を返します。 687 * 688 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 689 * 690 * @return 処理した行数 691 */ 692 public int getExecRowCnt() { 693 return rowCnt; 694 } 695 696 /** 697 * 全ての行が処理されたかをセットします(初期値:false)。 698 * 699 * これは、処理結果が、256シートを超えていた場合、再度残りのデータについて 700 * 処理を行うかどうかの判定するために、利用します。 701 * 702 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 703 * 704 * @param flag 全ての行が処理されたか 705 */ 706 public void setEnd( final boolean flag ) { 707 isDataEnd = flag; 708 } 709 710 /** 711 * 全ての行が処理されているかを返します。 712 * 713 * これは、処理結果が、256シートを超えていた場合、再度残りのデータについて 714 * 処理を行うかどうかの判定するために、利用します。 715 * 716 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 717 * 718 * @return 全ての行が処理されたか 719 */ 720 public boolean isEnd() { 721 return isDataEnd; 722 } 723}