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