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