5

我的任务是将两个 if 语句组合Js成一个剪纸脚本。它是一个打印管理软件。我拥有我需要的一切,我相信下面的脚本。问题是将这两个 if 组合成一个我相信的陈述。我不熟悉 Javascript,也不熟悉 python。我希望在重新安排这个脚本时得到一些帮助,如下所述。

PaperCut 打印脚本 API 参考

目标:

仅当他们打印超过 10 页的作业时才会弹出成本中心,否则只会将作业自动计入公司不可计费 (ADM-3900) 帐户。如果作业超过 50 页,请将其从 HP 重定向到更大的复印机。在这种情况下,从 test_printer3 到 Copier – Color。

/*
* Redirect large jobs without confirmation
* 
* Users printing jobs larger than the defined number of pages have their jobs 
* automatically redirected to another printer or virtual queue.
* This can be used to redirect large jobs from slower or high cost printers 
* to more efficient or faster high volume printers.
*/

function printJobHook(inputs, actions) {

  /*
  * This print hook will need access to all job details
  * so return if full job analysis is not yet complete.
  * The only job details that are available before analysis
  * are metadata such as username, printer name, and date.
  *
  * See reference documentation for full explanation.
  */

  /*
  * NOTE: The high-volume printer must be compatible with the source printer.
  *       i.e. use the same printer language like PCL or Postscript.
  *       If this is a virtual queue, all printers in the queue must use
  *       the same printer language.
  */

  if (!inputs.job.isAnalysisComplete) {
    // No job details yet so return.

    return;
    actions.job.chargeToPersonalAccount();

    return;


    if (inputs.job.totalPages < 10) {

      // Charge to the firm non-bill account

      actions.job.chargeToSharedAccount(ADM-3900);

    } 
    // Account Selection will still show

  } 

  var LIMIT             = 5; // Redirect jobs over 5 pages.


  var HIGH_VOL_PRINTER  = "Copier - Color";

  if (inputs.job.totalPages > LIMIT) {
    /*
    * Specify actions.job.bypassReleaseQueue() if you wish to bypass the release queue
    * on the original printer the job was sent to.  (Otherwise if held at the target,
    * the job will need to be released from two different queues before it will print.)
    */
    actions.job.bypassReleaseQueue();

    /*
    * Job is larger than our page limit, so redirect to high-volume printer,
    * and send a message to the user.
    * Specify "allowHoldAtTarget":true to allow the job to be held at the hold/release
    * queue for the high-volume printer, if one is defined.
    */

    actions.job.redirect(HIGH_VOL_PRINTER, {allowHoldAtTarget: true});

    // Notify the user that the job was automatically redirected.
    actions.client.sendMessage(
      "The print job was over " + LIMIT + " pages and was sent to " 
      + " printer: " + HIGH_VOL_PRINTER + ".");

    // Record that the job was redirected in the application log.
    actions.log.info("Large job redirected from printer '" + inputs.job.printerName 
                     + "' to printer '" + HIGH_VOL_PRINTER + "'.");
  }

}
4

5 回答 5

3

我相信这就是您要寻找的东西,但这并不完全清楚。在不知道所有逻辑分支的情况下很难合并条件。

/*
* Redirect large jobs without confirmation
* 
* Users printing jobs larger than the defined number of pages have their jobs 
* automatically redirected to another printer or virtual queue.
* This can be used to redirect large jobs from slower or high cost printers 
* to more efficient or faster high volume printers.
*/

 function printJobHook(inputs, actions) {

 /*
 * This print hook will need access to all job details
 * so return if full job analysis is not yet complete.
 * The only job details that are available before analysis
 * are metadata such as username, printer name, and date.
 *
 * See reference documentation for full explanation.
 */

 /*
 * NOTE: The high-volume printer must be compatible with the source printer.
 *       i.e. use the same printer language like PCL or Postscript.
 *       If this is a virtual queue, all printers in the queue must use
 *       the same printer language.
 */


 var LIMIT             = 5; // Redirect jobs over 5 pages.
 var HIGH_VOL_PRINTER  = "Copier - Color";  

if (!inputs.job.isAnalysisComplete) { 
 return;// No job details yet so return. 
} 


//Charge jobs with less than 10 pages to non-bill account
if (inputs.job.totalPages < 10) {
  // Charge to the firm non-bill account
  actions.job.chargeToSharedAccount(ADM-3900);
} 
else //Charge jobs with more than 10 pages to the personal account
{   
    actions.job.chargeToPersonalAccount();

      if (inputs.job.totalPages > LIMIT) {
        /*
        * Specify actions.job.bypassReleaseQueue() if you wish to bypass the release queue
        * on the original printer the job was sent to.  (Otherwise if held at the target,
        * the job will need to be released from two different queues before it will print.)
        */
        actions.job.bypassReleaseQueue();

        /*
        * Job is larger than our page limit, so redirect to high-volume printer,
        * and send a message to the user.
        * Specify "allowHoldAtTarget":true to allow the job to be held at the hold/release
        * queue for the high-volume printer, if one is defined.
        */

        actions.job.redirect(HIGH_VOL_PRINTER, {allowHoldAtTarget: true});

        // Notify the user that the job was automatically redirected.
        actions.client.sendMessage(
          "The print job was over " + LIMIT + " pages and was sent to " 
          + " printer: " + HIGH_VOL_PRINTER + ".");

        // Record that the job was redirected in the application log.
        actions.log.info("Large job redirected from printer '" + inputs.job.printerName 
                         + "' to printer '" + HIGH_VOL_PRINTER + "'.");
      }
}
   return
}
于 2018-10-10T17:54:04.757 回答
0

我认为您在这里遇到的问题必须处理您提到的 if 语句块中的多个 return 语句。

这个块就是你所拥有的......

if (!inputs.job.isAnalysisComplete) {
    return;
    actions.job.chargeToPersonalAccount();
    return;

    if (inputs.job.totalPages < 10) {
        actions.job.chargeToSharedAccount(ADM-3900);
    } 
} 

我认为如果它是这样的,这个块会更准确......

/*No details of print analysis?  Return the the function immediately!*/
if (!inputs.job.isAnalysisComplete) {
    return;
} 

/*Job less than ten pages?  Charge shared account.  Otherwise charge personal account.*/
if (inputs.job.totalPages < 10) {

    /*Also, my bet is that the ADM-3900 needs to be in quotes for a string unless other wise stated in the manual.*/

    actions.job.chargeToSharedAccount("ADM-3900");
} else {
    actions.job.chargeToPersonalAccount();
}

请注意,这是我最好的猜测,因为我不熟悉 Papercut 软件。

如果这没有帮助,总是有技术支持

于 2018-10-08T19:53:56.323 回答
0

根据我对您的目标的理解,我将对您的代码进行下一步更改:

/*
* Redirect large jobs without confirmation
* 
* Users printing jobs larger than the defined number of pages have their jobs 
* automatically redirected to another printer or virtual queue.
* This can be used to redirect large jobs from slower or high cost printers 
* to more efficient or faster high volume printers.
*/

// Setup limit for charge the job to ADM-3900.

var ADM_3900_CHARGE_LIMIT = 10;

// Setup of redirection for larger jobs.

var REDIRECT_PAGE_LIMIT = 50;
var REDIRECT_PRINTER  = "Copier - Color";

function printJobHook(inputs, actions)
{    
    /*
    * This print hook will need access to all job details
    * so return if full job analysis is not yet complete.
    * The only job details that are available before analysis
    * are metadata such as username, printer name, and date.
    *
    * See reference documentation for full explanation.
    */

    /*
    * NOTE: The high-volume printer must be compatible with the source printer.
    *       i.e. use the same printer language like PCL or Postscript.
    *       If this is a virtual queue, all printers in the queue must use
    *       the same printer language.
    */

    // Check if job analysis is completed (return if not)

    if (!inputs.job.isAnalysisComplete)
    {
        // No job details yet so return.
        // XXX: We should return some value that the client can
        // identify and know he have to call the method again on a
        // few seconds (when job analysis is complete). the client could
        // also check this condition before calling us.
        return false;
    }

    // If pages to print is less than ADM_3900_CHARGE_LIMIT,
    // just charge the job to the firm non-billable (ADM-3900) account.

    if (inputs.job.totalPages < ADM_3900_CHARGE_LIMIT)
    {
        // Charge to the firm non-bill account.
        actions.job.chargeToSharedAccount(ADM-3900);

        // Return with success.
        return true;
    }

    // At this point, we have to charge to personal account.

    actions.job.chargeToPersonalAccount();

    // Finally, check if we have to redirect to a more efficient or
    // faster high volume printer.

    if (inputs.job.totalPages > REDIRECT_PAGE_LIMIT)
    {
        /*
        * Specify actions.job.bypassReleaseQueue() if you wish to bypass
        * the release queue on the original printer the job was sent to.
        * (Otherwise if held at the target, the job will need to be released
        * from two different queues before it will print.)
        */

        actions.job.bypassReleaseQueue();

        /*
        * Job is larger than our page limit, so redirect to high-volume printer,
        * and send a message to the user.
        * Specify "allowHoldAtTarget":true to allow the job to be held at the
        * hold/release queue for the high-volume printer, if one is defined.
        */

        actions.job.redirect(REDIRECT_PRINTER, {allowHoldAtTarget: true});

        // Notify the user that the job was automatically redirected.

        actions.client.sendMessage(
            "The print job was over " + REDIRECT_PAGE_LIMIT + " pages and" +
            " was sent to printer: " + REDIRECT_PRINTER + "."
        );

        // Record that the job was redirected in the application log.

        actions.log.info(
            "Large job redirected from printer '" + inputs.job.printerName +
            "' to printer '" + REDIRECT_PRINTER + "'."
        );
    }

    // Return with success.
    return true;
}
于 2018-10-10T18:51:23.577 回答
0

我的代码,以达到指定的目标:

/*
* Redirect large jobs without confirmation
* 
* Users printing jobs larger than the defined number of pages have their jobs 
* automatically redirected to another printer or virtual queue.
* This can be used to redirect large jobs from slower or high cost printers 
* to more efficient or faster high volume printers.
*/

function printJobHook(inputs, actions) {

  /*
  * This print hook will need access to all job details
  * so return if full job analysis is not yet complete.
  * The only job details that are available before analysis
  * are metadata such as username, printer name, and date.
  *
  * See reference documentation for full explanation.
  */
  if (!inputs.job.isAnalysisComplete) {
    // No job details yet so return.
    return;
  }
  /*
  * NOTE: The high-volume printer must be compatible with the source printer.
  *       i.e. use the same printer language like PCL or Postscript.
  *       If this is a virtual queue, all printers in the queue must use
  *       the same printer language.
  */

  if (inputs.job.totalPages < 10) {
    // Below 10 - charge to the firm non-bill account
    actions.job.chargeToSharedAccount("ADM-3900");
  }
  else{
    //job is 10+ pages - do the cost center popup

    actions.job.chargeToPersonalAccount();
    // Account Selection will still show

    var LIMIT             = 50; // Redirect jobs over 50+ pages.
    var HIGH_VOL_PRINTER  = "Copier - Color";

    if (inputs.job.totalPages > LIMIT) {
      //The job is 50+ pages

      /*
      * Specify actions.job.bypassReleaseQueue() if you wish to bypass the release queue
      * on the original printer the job was sent to.  (Otherwise if held at the target,
      * the job will need to be released from two different queues before it will print.)
      */
      actions.job.bypassReleaseQueue();

      /*
      * Job is larger than our page limit, so redirect to high-volume printer,
      * and send a message to the user.
      * Specify "allowHoldAtTarget":true to allow the job to be held at the hold/release
      * queue for the high-volume printer, if one is defined.
      */
      actions.job.redirect(HIGH_VOL_PRINTER, {allowHoldAtTarget: true});

      // Notify the user that the job was automatically redirected.
      actions.client.sendMessage(
        "The print job was over " + LIMIT + " pages and was sent to " 
        + " printer: " + HIGH_VOL_PRINTER + ".");

      // Record that the job was redirected in the application log.
      actions.log.info("Large job redirected from printer '" + inputs.job.printerName 
                     + "' to printer '" + HIGH_VOL_PRINTER + "'.");
    }
  }
}
于 2018-10-11T13:46:49.320 回答
0

您的文字翻译为:

if(jobs > 50) redirect to Copier-Color
elseif(jobs > 10) cost center popup
else charge automagically

在 JS 中是:

const   LIMIT_10            = 10,
        LIMIT_50            = 50,
        HIGH_VOL_PRINTER  = "Copier - Color";

function printJobHook(inputs, actions) {
    if (!inputs.job.isAnalysisComplete)
        return;

    if (inputs.job.totalPages > LIMIT_50) {
        actions.job.bypassReleaseQueue();
        actions.job.redirect(HIGH_VOL_PRINTER, {allowHoldAtTarget: true});
        actions.client.sendMessage(
          "The print job was over " + LIMIT + " pages and was sent to " 
          + " printer: " + HIGH_VOL_PRINTER + ".");

        actions.log.info("Large job redirected from printer '" + inputs.job.printerName 
                         + "' to printer '" + HIGH_VOL_PRINTER + "'.");
    }else if (inputs.job.totalPages > LIMIT_10) {
        actions.job.chargeToSharedAccount();
    }else{
        actions.job.chargeToPersonalAccount(ADM-3900);
    }
}
于 2018-10-15T05:57:17.657 回答