001package scpc.model; 002 003import java.math.BigDecimal; 004import javax.script.ScriptException; 005 006/** 007 * Promotion rule which could be applicable to shopping cart. 008 * <br>促眅規則 009 * 010 * @author Kent Yeh 011 * @param <T> type of real cart item. 012 */ 013public interface IRule<T> { 014 015 /** 016 * Priority, the smaller the value the higher the priority. 017 * <br>優先順序,數值越小越優先 018 * 019 * @return priority of rules. 020 */ 021 public int getPriority(); 022 023 /** 024 * Detecting item whether is applicable to this rule or not. 025 * <br>購物車品項是否適用於此規則 026 * 027 * @param item object in shopping cart. 028 * @return 029 */ 030 public boolean contains(IItem<T> item); 031 032 /** 033 * Determined iterable items if matched. 034 * <br>走訪購物車品項時決定是否觸發的公式 035 * 036 * @param item cart item 037 * @return true if item matched. 038 * @throws javax.script.ScriptException 039 */ 040 public boolean isTriggered(SingleItem<T> item) throws ScriptException; 041 042 /** 043 * Whether this rule is a leaf rule or not. 044 * <br>是否為最未端規則 045 * 046 * @return true if this rule is terminal. 047 */ 048 public boolean isLeaf(); 049 050 /** 051 * Previous rule. 052 * <br>串連的前規則 053 * 054 * @return previus link rule; 055 */ 056 public IChainRule<T> getPrevious(); 057 058 /** 059 * 價格精度 060 * 061 * @return price number scale. 062 */ 063 public int getPriceScale(); 064 065 /** 066 * Increase one count of items that is applicable to this rule. 067 * <br>增加符合此規則的品項計次 068 * 069 * @return this rule 070 */ 071 public IRule<T> containsCountInc(); 072 073 /** 074 * 符合此規則的品項數量 075 * 076 * @return number of items that could applicable to this rule. 077 */ 078 public int getContainsCount(); 079 080 /** 081 * 082 * @param doAdd true to add one to the serial number otherwise reset serial number to one. 083 * @return this rule 084 */ 085 public IRule<T> serialNumInc(boolean doAdd); 086 087 /** 088 * 目前走訪商品之同品項物品的編號(從1起算) 089 * 090 * @return n'th item of same serial items current visited.(Starting from 1) 091 */ 092 public int getSerialNum(); 093 094 /** 095 * Increase the summary sale price of applicable items. 096 * <br>增加符合此規則的品項售價小計 097 * 098 * @param salePrice 099 * @return 100 */ 101 public IRule<T> sumOfContainsSalePriceInc(BigDecimal salePrice); 102 103 /** 104 * 符合此規則的品項售價小計 105 * 106 * @return The summary sale price of applicable items. 107 */ 108 public BigDecimal getSumOfContainsSalePrice(); 109 110 /** 111 * Increase the summary regular price of applicable items. 112 * <br>增加符合此規則的品項原價小計 113 * 114 * @param salePrice 115 * @return 116 */ 117 public IRule<T> sumOfContainsRegularPriceInc(BigDecimal salePrice); 118 119 /** 120 * 符合此規則的品項原價小計 121 * 122 * @return The summary regular price of applicable items. 123 */ 124 public BigDecimal getSumOfContainsRegularPrice(); 125 126 /** 127 * Increase the summary sale price of the same applicable items. 128 * <br>增加符合此規則的同品項物品售價小計 129 * 130 * @param saleprice 131 * @return this rule. 132 */ 133 public IRule<T> sumOfSerialSalePriceInc(BigDecimal saleprice); 134 135 /** 136 * 符合此規則的同品項售價小計 137 * 138 * @return The summary sale price of the same applicable items. 139 */ 140 public BigDecimal getSumOfSerialSalePrice(); 141 142 /** 143 * Reset the summary sale price of the same applicable items. 144 * 145 * @return this rule. 146 */ 147 public IRule<T> resetSumOfSerialSalePrice(); 148 149 /** 150 * Increase the summary regular price of the same applicable items. 151 * <br>增加符合此規則的同品項原價小計 152 * 153 * @param regPrice regular price 154 * @return this rule 155 */ 156 public IRule<T> sumOfSerialRegularPriceInc(BigDecimal regPrice); 157 158 /** 159 * 符合此規則的同品項原價小計 160 * 161 * @return The summary regular price of the same applicable items. 162 */ 163 public BigDecimal getSumOfSerialRegularPrice(); 164 165 /** 166 * Reset the summary regular price of the same applicable items. 167 * 168 * @return this rule 169 */ 170 public IRule<T> resetSumOfSerialRegularPrice(); 171 172 /** 173 * Reset sumary price to zero <br> 174 * 重置所有價格累計為零 175 */ 176 public void resetSumOfPrice(); 177}