edit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
import lingtao.net.vo.ProductVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 提供画布产品的定价策略。
|
||||
* 该类主要用于计算画布类产品的价格列表,根据产品信息和用户角色进行价格计算。
|
||||
*/
|
||||
public class CanvasPricingStrategy implements PricingStrategy {
|
||||
/**
|
||||
* 根据产品信息和用户角色计算画布产品的价格。
|
||||
*
|
||||
* @param dto 产品信息对象,包含产品详细信息。
|
||||
* @param role 用户角色,用于确定价格策略。
|
||||
* @return 返回计算后的价格列表对象,如果未实现或无法计算则返回null。
|
||||
*/
|
||||
@Override
|
||||
public PricingListVo calculatePrice(Product dto, String role) {
|
||||
String plantName = dto.getPlantName();
|
||||
double width = dto.getWidth();
|
||||
double length = dto.getLength();
|
||||
int count = dto.getCount();
|
||||
int number = dto.getNumber();
|
||||
double price = 0.0;
|
||||
double basePrice = 0.0;
|
||||
List<ProductVo> resultList = new ArrayList<>();
|
||||
|
||||
|
||||
if ("领鸿".equals(plantName)) {
|
||||
double area = Math.max(count * number * width * length / 10000, 0.2);
|
||||
price = new BigDecimal(basePrice * area).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
|
||||
ProductVo pro = new ProductVo();
|
||||
pro.setCount(count);
|
||||
pro.setPrice(price);
|
||||
pro.setNumber(number);
|
||||
pro.setWeight(BigDecimal.valueOf(width / 100 * length / 100 * count * 0.07).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
||||
resultList.add(pro);
|
||||
return new PricingListVo(resultList);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,398 @@
|
||||
package lingtao.net.Factory;public class CardPricingStrategy {
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
import lingtao.net.vo.ProductVo;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
|
||||
public class CardPricingStrategy implements PricingStrategy {
|
||||
@Override
|
||||
public PricingListVo calculatePrice(Product dto, String role) {
|
||||
String plantName = dto.getPlantName();
|
||||
String kindValue = dto.getProTypeLabel();
|
||||
|
||||
if ("菜单".equals(kindValue)) {
|
||||
//return new PricingListVo(100, "暂无报价"); // 返回空列表表示不适用
|
||||
// String size = dto.getUi_menu_size();
|
||||
// dto.setLength(Double.valueOf(size.substring(0, size.indexOf("*"))));
|
||||
// if (size.contains(",")) {
|
||||
// size = size.split(",")[0];
|
||||
// }
|
||||
// if (size.indexOf(("*"), size.indexOf("*") + 1) == -1) {
|
||||
// dto.setWidth(Double.valueOf(size.substring(size.indexOf("*") + 1)));
|
||||
// } else {
|
||||
// dto.setWidth(Double.valueOf(size.substring(size.indexOf("*") + 1, size.indexOf(("*"), size.indexOf("*") + 1))));
|
||||
// dto.setLength(Math.abs(Double.parseDouble(size.substring(size.indexOf(("*"), size.indexOf("*") + 1) + 1))));
|
||||
// }
|
||||
}
|
||||
double width = dto.getWidth();
|
||||
double length = dto.getLength();
|
||||
int count = dto.getCount();
|
||||
int number = dto.getNumber();
|
||||
// 定义纸张尺寸(单位:毫米)
|
||||
double paperLength = 280; // 纸张长度
|
||||
double paperWidth = 420; // 纸张宽度
|
||||
String basePrice = "0"; // 基础价格
|
||||
BigDecimal price = new BigDecimal(0); // 最终价格
|
||||
BigDecimal weight = BigDecimal.ZERO;
|
||||
|
||||
length = convertToMillimetersWithMargin(length);
|
||||
width = convertToMillimetersWithMargin(width);
|
||||
String material = "1";
|
||||
if ("婚礼报纸".equals(kindValue)) {
|
||||
material = "2";//157g铜版纸
|
||||
} else if ("特种纸名片".equals(kindValue)) {
|
||||
material = dto.getKindValue6();
|
||||
} else if ("菜单".equals(kindValue) && "2".equals(dto.getKindValue5())) {
|
||||
material = "pvc";
|
||||
}
|
||||
String ggSize = dto.getSize1();//刮刮膜
|
||||
List<ProductVo> resultList = new ArrayList<>();
|
||||
List<String> craft_list = dto.getCraft() != null ? Arrays.asList(dto.getCraft()) : new ArrayList<>();
|
||||
if ("艾印".equals(plantName) && !"种子纸".equals(kindValue) && !"菜单".equals(kindValue)) {
|
||||
if (craft_list.contains("烫金") || craft_list.contains("彩色印刷+烫金")) {
|
||||
return new PricingListVo(100, "车间无烫金工艺"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
|
||||
Map<String, Map<String, String>> kindValuePrice = new HashMap<>();
|
||||
|
||||
// 统一键的类型为字符串
|
||||
kindValuePrice.put("1", createPriceMap("1", "3", "2", "3.3"));//300g铜版纸
|
||||
kindValuePrice.put("2", createPriceMap("1", "1.8", "2", "2.4"));//157g铜版纸
|
||||
kindValuePrice.put("皙贝", createPriceMap("1", "2.1", "2", "3.1"));//白卡
|
||||
kindValuePrice.put("琮纹", createPriceMap("1", "2.5", "2", "3.7"));//刚古
|
||||
kindValuePrice.put("玉蕊", createPriceMap("1", "2.7", "2", "3.8"));//蛋壳
|
||||
kindValuePrice.put("睿狐", createPriceMap("1", "2.7", "2", "3.8"));//莱尼
|
||||
kindValuePrice.put("溪雪", createPriceMap("1", "3.2", "2", "3.2"));//珠光
|
||||
if (!kindValuePrice.containsKey(material)) {
|
||||
return new PricingListVo(100, "暂无报价"); // 返回空列表表示不适用
|
||||
}
|
||||
// 检查是否超出纸张尺寸限制
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
return new PricingListVo(100, "出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
int requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
//单双面单价不一致
|
||||
Map<String, String> prices = kindValuePrice.get(material);
|
||||
if ("双面印刷".equals(dto.getCraftShua())) {
|
||||
basePrice = prices.get("2");
|
||||
} else {
|
||||
basePrice = prices.get("1");
|
||||
}
|
||||
price = new BigDecimal(basePrice).multiply(new BigDecimal(requiredSheets)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
if ("刮刮卡".equals(kindValue)) {
|
||||
Map<String, Map<String, String>> ggmPrices = new HashMap<String, Map<String, String>>();
|
||||
ggmPrices.put("60*25", createPriceMap("50", "3", "100", "5"));
|
||||
ggmPrices.put("48*15", createPriceMap("50", "2", "100", "3"));
|
||||
ggmPrices.put("8*30", createPriceMap("50", "1", "100", "2"));
|
||||
ggmPrices.put("6*22", createPriceMap("50", "0.8", "100", "1.6"));
|
||||
if (!ggmPrices.containsKey(ggSize)) {
|
||||
return new PricingListVo(100, "无该尺寸刮刮膜"); // 返回空列表表示不适用
|
||||
}
|
||||
Map<String, String> ggmPrice = ggmPrices.get(ggSize);
|
||||
if (count <= 50) {
|
||||
price = price.add(new BigDecimal(ggmPrice.get("50"))).setScale(2, RoundingMode.HALF_UP);
|
||||
} else {
|
||||
price = price.add(new BigDecimal(ggmPrice.get("100"))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ("即客".equals(plantName) && !"种子纸".equals(kindValue) && !"菜单".equals(kindValue)) {
|
||||
if (craft_list.contains("烫金") || craft_list.contains("彩色印刷+烫金")) {
|
||||
return new PricingListVo(100, "车间无烫金工艺"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
Map<String, Map<String, String>> kindValuePrice = new HashMap<>();
|
||||
|
||||
// 统一键的类型为字符串
|
||||
kindValuePrice.put("1", createPriceMap("1", "3", "2", "3.3"));//300g铜版纸
|
||||
kindValuePrice.put("2", createPriceMap("1", "1.8", "2", "2.4"));//157g铜版纸
|
||||
kindValuePrice.put("萱姿", createPriceMap("1", "3", "2", "3"));//雅柔
|
||||
kindValuePrice.put("芳怡", createPriceMap("1", "3", "2", "3"));//草香
|
||||
if (!kindValuePrice.containsKey(material)) {
|
||||
return new PricingListVo(100, "暂无报价"); // 返回空列表表示不适用
|
||||
}
|
||||
// 检查是否超出纸张尺寸限制
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
return new PricingListVo(100, "出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
int requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
//单双面单价不一致
|
||||
Map<String, String> prices = kindValuePrice.get(material);
|
||||
if ("双面印刷".equals(dto.getCraftShua())) {
|
||||
basePrice = prices.get("2");
|
||||
} else {
|
||||
basePrice = prices.get("1");
|
||||
}
|
||||
price = new BigDecimal(basePrice).multiply(new BigDecimal(requiredSheets)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
if ("刮刮卡".equals(kindValue)) {
|
||||
Map<String, Map<String, String>> ggmPrices = new HashMap<String, Map<String, String>>();
|
||||
ggmPrices.put("60*25", createPriceMap("50", "3", "100", "6"));
|
||||
ggmPrices.put("48*15", createPriceMap("50", "2", "100", "4"));
|
||||
ggmPrices.put("8*30", createPriceMap("50", "1", "100", "2"));
|
||||
ggmPrices.put("6*22", createPriceMap("50", "0.8", "100", "1.6"));
|
||||
if (!ggmPrices.containsKey(ggSize)) {
|
||||
return new PricingListVo(100, "无该尺寸刮刮膜"); // 返回空列表表示不适用
|
||||
}
|
||||
Map<String, String> ggmPrice = ggmPrices.get(ggSize);
|
||||
if (count <= 50) {
|
||||
price = price.add(new BigDecimal(ggmPrice.get("50"))).setScale(2, RoundingMode.HALF_UP);
|
||||
} else {
|
||||
price = price.add(new BigDecimal(ggmPrice.get("100"))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ("欣海信".equals(plantName) && !"种子纸".equals(kindValue)) {
|
||||
paperLength = 272; // 纸张长度
|
||||
paperWidth = 390; // 纸张宽度
|
||||
Map<String, Map<String, String>> kindValuePrice = new HashMap<>();
|
||||
|
||||
// 统一键的类型为字符串
|
||||
kindValuePrice.put("1", createPriceMap("1", "3", "2", "3.3"));//300g铜版纸
|
||||
kindValuePrice.put("pvc", createPriceMap("1", "3", "2", "3.3"));//300g铜版纸
|
||||
kindValuePrice.put("2", createPriceMap("1", "1.8", "2", "2.4"));//157g铜版纸
|
||||
kindValuePrice.put("溪雪", createPriceMap("1", "4", "2", "6"));//珠光
|
||||
kindValuePrice.put("琮纹", createPriceMap("1", "4", "2", "6"));//刚古
|
||||
kindValuePrice.put("睿狐", createPriceMap("1", "4", "2", "6"));//莱尼
|
||||
kindValuePrice.put("玉蕊", createPriceMap("1", "4", "2", "6"));//蛋壳
|
||||
if (!kindValuePrice.containsKey(material)) {
|
||||
return new PricingListVo(100, "暂无报价"); // 返回空列表表示不适用
|
||||
}
|
||||
// 检查是否超出纸张尺寸限制
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
return new PricingListVo(100, "出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
int requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
//单双面单价不一致
|
||||
Map<String, String> prices = kindValuePrice.get(material);
|
||||
if ("双面印刷".equals(dto.getCraftShua())) {
|
||||
basePrice = prices.get("2");
|
||||
if (craft_list.contains("烫金") || craft_list.contains("彩色印刷+烫金")) {
|
||||
basePrice = new BigDecimal(basePrice).add(new BigDecimal(prices.get("18"))).setScale(2, RoundingMode.HALF_UP).toString();
|
||||
}
|
||||
} else {
|
||||
basePrice = prices.get("1");
|
||||
if (craft_list.contains("烫金") || craft_list.contains("彩色印刷+烫金")) {
|
||||
basePrice = new BigDecimal(basePrice).add(new BigDecimal(prices.get("9"))).setScale(2, RoundingMode.HALF_UP).toString();
|
||||
}
|
||||
}
|
||||
price = new BigDecimal(basePrice).multiply(new BigDecimal(requiredSheets)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
if ("刮刮卡".equals(kindValue)) {
|
||||
price = price.add(new BigDecimal(0.3).multiply(new BigDecimal(count))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
if ("彩印通".equals(plantName) && !"种子纸".equals(kindValue) && !"菜单".equals(kindValue)) {
|
||||
paperLength = 297;
|
||||
paperWidth = 420;
|
||||
if (craft_list.contains("烫金") || craft_list.contains("彩色印刷+烫金")) {
|
||||
return new PricingListVo(100, "车间无烫金工艺"); // 返回空列表表示不适用
|
||||
}
|
||||
Map<String, Map<String, String>> kindValuePrice = new HashMap<>();
|
||||
|
||||
// 统一键的类型为字符串
|
||||
kindValuePrice.put("1", createPriceMap("1", "2.5", "2", "3"));//300g铜版纸
|
||||
kindValuePrice.put("芳怡", createPriceMap("1", "5.5", "2", "5.5"));//草香
|
||||
kindValuePrice.put("溪雪", createPriceMap("1", "3.5", "2", "3.5"));//珠光
|
||||
kindValuePrice.put("萱姿", createPriceMap("1", "5", "2", "5"));//雅柔
|
||||
if (!kindValuePrice.containsKey(material)) {
|
||||
return new PricingListVo(100, "暂无报价"); // 返回空列表表示不适用
|
||||
}
|
||||
// 检查是否超出纸张尺寸限制
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
return new PricingListVo(100, "出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
int requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
//单双面单价不一致
|
||||
Map<String, String> prices = kindValuePrice.get(material);
|
||||
if ("双面印刷".equals(dto.getCraftShua())) {
|
||||
basePrice = prices.get("2");
|
||||
} else {
|
||||
basePrice = prices.get("1");
|
||||
}
|
||||
if (craft_list.contains("异形")) {
|
||||
basePrice = new BigDecimal(basePrice).add(new BigDecimal("0.5")).setScale(2, RoundingMode.HALF_UP).toString();
|
||||
}
|
||||
price = new BigDecimal(basePrice).multiply(new BigDecimal(requiredSheets)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
if ("刮刮卡".equals(kindValue)) {
|
||||
BigDecimal ggPrice = new BigDecimal("0.02").multiply(new BigDecimal(count));
|
||||
price = price.add(ggPrice.compareTo(new BigDecimal("30")) > 0 ? ggPrice : new BigDecimal("30")).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
if ("种子纸".equals(kindValue) && "鸿晟".equals(plantName)) {
|
||||
if (!StringUtils.isEmpty(dto.getSwitchz3Size()) || "2".equals(dto.getZ3type())) {
|
||||
count = Math.max(count, 300);
|
||||
}
|
||||
price = BigDecimal.valueOf((length * width * count * 70) / 1000000).setScale(2, RoundingMode.HALF_UP);//价格计算尺寸*数量*200/10000
|
||||
|
||||
if (craft_list.contains("编码")) {//起步价10
|
||||
price = price.add(max(new BigDecimal(count * 0.4), new BigDecimal(10))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (craft_list.contains("打孔")) {
|
||||
price = price.add(max(new BigDecimal(count * 0.1), new BigDecimal(10))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (craft_list.contains("手撕线")) {
|
||||
price = price.add(max(new BigDecimal(count * 0.2), new BigDecimal(10))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (craft_list.contains("压痕")) {
|
||||
price = price.add(max(new BigDecimal(count * 0.2), new BigDecimal(10))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
price = price.multiply(new BigDecimal(number));//款数翻倍
|
||||
price = max(price, new BigDecimal(80)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
if (!StringUtils.isEmpty(dto.getSwitchz3Size())) {
|
||||
price = price.add(new BigDecimal(100)).add(new BigDecimal(count * 0.1)).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (craft_list.size() > 0 && craft_list.contains("绳子")) {
|
||||
price = price.add(max(new BigDecimal(0.1 * number * count), new BigDecimal(5))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
if ("种子纸".equals(kindValue) && "驰远".equals(plantName)) {
|
||||
if (!StringUtils.isEmpty(dto.getSwitchz3Size()) || "2".equals(dto.getZ3type())) {
|
||||
count = Math.max(count, 300);
|
||||
}
|
||||
basePrice = "45";
|
||||
if (!StringUtils.isEmpty(dto.getSwitchz3Size())) {
|
||||
basePrice = "65";
|
||||
if (length > 12 || width > 12) {
|
||||
return new PricingListVo(100, "纸张尺寸超出");
|
||||
}
|
||||
}
|
||||
price = BigDecimal.valueOf((length * width * count) / 1000000).multiply(new BigDecimal(basePrice)).setScale(2, RoundingMode.HALF_UP);//价格计算尺寸*数量*200/10000
|
||||
|
||||
if (craft_list.contains("编码")) {//起步价10
|
||||
price = price.add(max(new BigDecimal(count * 0.4), new BigDecimal(10))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (craft_list.contains("打孔")) {
|
||||
price = price.add(max(new BigDecimal(count * 0.1), new BigDecimal(10))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (craft_list.contains("手撕线")) {
|
||||
price = price.add(max(new BigDecimal(count * 0.2), new BigDecimal(10))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (craft_list.contains("压痕")) {
|
||||
price = price.add(max(new BigDecimal(count * 0.2), new BigDecimal(10))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
price = price.multiply(new BigDecimal(number));//款数翻倍
|
||||
price = max(price, new BigDecimal(80)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
|
||||
if (craft_list.size() > 0 && craft_list.contains("绳子")) {
|
||||
price = price.add(max(new BigDecimal(0.1 * number * count), new BigDecimal(5))).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
weight = BigDecimal.valueOf(number * (length) / 1000 * (width) / 1000 * count * 0.25 * 1.15);
|
||||
// 创建产品对象并添加到结果列表
|
||||
ProductVo pro = new ProductVo();
|
||||
pro.setPrice(price.doubleValue());
|
||||
pro.setCount(count);
|
||||
pro.setWeight(weight.toString());
|
||||
resultList.add(pro);
|
||||
return new PricingListVo(resultList);
|
||||
}
|
||||
|
||||
public static BigDecimal max(BigDecimal a, BigDecimal b) {
|
||||
if (a == null) {
|
||||
return b;
|
||||
}
|
||||
if (b == null) {
|
||||
return a;
|
||||
}
|
||||
return a.compareTo(b) >= 0 ? a : b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建价格映射
|
||||
*
|
||||
* @param keysAndValues 键值对数组
|
||||
* @return 初始化后的价格映射
|
||||
*/
|
||||
private Map<String, String> createPriceMap(String... keysAndValues) {
|
||||
if (keysAndValues.length % 2 != 0) {
|
||||
throw new IllegalArgumentException("键值对数量必须为偶数");
|
||||
}
|
||||
Map<String, String> priceMap = new HashMap<>();
|
||||
for (int i = 0; i < keysAndValues.length; i += 2) {
|
||||
priceMap.put(keysAndValues[i], keysAndValues[i + 1]);
|
||||
}
|
||||
return priceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将给定的尺寸转换为毫米,并在每边增加3毫米的边距
|
||||
*
|
||||
* @param size 需要转换的原始尺寸
|
||||
* @return 转换后的尺寸,单位为毫米,包括边距
|
||||
*/
|
||||
private double convertToMillimetersWithMargin(double size) {
|
||||
return size * 10 + 2 * 2; // 换成毫米,每边+2
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查给定的长度和宽度是否在纸张尺寸范围内
|
||||
*
|
||||
* @param length 需要检查的长度
|
||||
* @param width 需要检查的宽度
|
||||
* @param paperLength 纸张的长度
|
||||
* @param paperWidth 纸张的宽度
|
||||
* @return 如果给定尺寸在纸张尺寸范围内,则返回true;否则返回false
|
||||
*/
|
||||
private boolean isWithinPaperSize(double length, double width, double paperLength, double paperWidth) {
|
||||
return (length <= paperLength && width <= paperWidth) || (length <= paperWidth && width <= paperLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算每张纸最多可以容纳的物品数量
|
||||
*
|
||||
* @param length 物品的长度
|
||||
* @param width 物品的宽度
|
||||
* @param paperLength 纸张的长度
|
||||
* @param paperWidth 纸张的宽度
|
||||
* @return 每张纸最多可以容纳的物品数量
|
||||
*/
|
||||
private double calculateMaxItemsPerSheet(double length, double width, double paperLength, double paperWidth) {
|
||||
return Math.max(
|
||||
Math.floor(paperLength / length) * Math.floor(paperWidth / width),
|
||||
Math.floor(paperLength / width) * Math.floor(paperWidth / length)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算完成指定数量的物品所需的纸张数量
|
||||
*
|
||||
* @param count 物品的总数量
|
||||
* @param number 每个物品需要的数量
|
||||
* @param maxItemsPerSheet 每张纸最多可以容纳的物品数量
|
||||
* @return 完成指定数量的物品所需的纸张数量
|
||||
*/
|
||||
private int calculateRequiredSheets(int count, int number, double maxItemsPerSheet) {
|
||||
return (int) Math.ceil((count * number) / maxItemsPerSheet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
import lingtao.net.vo.ProductVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 班级标志定价策略类
|
||||
* 实现了PricingStrategy接口,用于根据用户角色计算产品价格
|
||||
* 此策略专注于处理与班级标志相关的产品价格计算
|
||||
*/
|
||||
public class ClassFlagPricingStrategy implements PricingStrategy {
|
||||
/**
|
||||
* 根据用户角色计算产品价格
|
||||
* 此方法旨在根据不同用户角色计算产品的价格,但具体实现尚未完成
|
||||
*
|
||||
* @param dto 产品信息对象,包含产品详细信息
|
||||
* @param role 用户角色,用于确定价格策略
|
||||
* @return 返回计算后的价格信息对象,当前实现返回null
|
||||
*/
|
||||
@Override
|
||||
public PricingListVo calculatePrice(Product dto, String role) {
|
||||
String plantName = dto.getPlantName();
|
||||
double width = dto.getWidth();
|
||||
double length = dto.getLength();
|
||||
int count = dto.getCount();
|
||||
int number = dto.getNumber();
|
||||
double price = 0.0;
|
||||
double basePrice = 0.0;
|
||||
List<ProductVo> resultList = new ArrayList<>();
|
||||
List<String> craft_list = Optional.ofNullable(dto)
|
||||
.map(Product::getCraft) // 假设 dto 是 Dto 类型
|
||||
.map(Arrays::asList)
|
||||
.orElseGet(ArrayList::new);
|
||||
|
||||
// 确保 craftList 是可变的
|
||||
craft_list = new ArrayList<>(craft_list);
|
||||
if ("领鸿".equals(plantName)) {
|
||||
//旗帜布
|
||||
basePrice = 6.5;
|
||||
double area = Math.max(count * number * width * length / 10000, 0.3);
|
||||
price = new BigDecimal(basePrice * area).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
if (craft_list.contains("旗杆")) {
|
||||
price = BigDecimal.valueOf(price).add(BigDecimal.valueOf(count * number * 15.0)).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
ProductVo pro = new ProductVo();
|
||||
pro.setCount(count);
|
||||
pro.setPrice(price);
|
||||
pro.setNumber(number);
|
||||
pro.setWeight(BigDecimal.valueOf(width / 100 * length / 100 * count * 0.07).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
||||
resultList.add(pro);
|
||||
return new PricingListVo(resultList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
import lingtao.net.vo.ProductVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 提供了一种特定的定价策略。
|
||||
* 该策略专门用于处理挂布产品的定价计算,根据产品信息和用户角色来确定最终价格。
|
||||
*/
|
||||
public class DossalPricingStrategy implements PricingStrategy {
|
||||
/**
|
||||
* 根据产品信息和用户角色计算价格。
|
||||
* 此方法旨在根据不同类型的用户(如普通用户、会员等)对Dossal产品提供定制化的定价。
|
||||
*
|
||||
* @param dto 产品信息对象,包含了需要计算价格的产品的所有必要信息。
|
||||
* @param role 用户角色,用于确定用户类型,进而影响最终的定价结果。
|
||||
* @return 返回计算后的价格列表视图对象,若不适用或未实现则返回null。
|
||||
*/
|
||||
@Override
|
||||
public PricingListVo calculatePrice(Product dto, String role) {
|
||||
String plantName = dto.getPlantName();
|
||||
double width = dto.getWidth();
|
||||
double length = dto.getLength();
|
||||
int count = dto.getCount();
|
||||
int number = dto.getNumber();
|
||||
double price = 0.0;
|
||||
double basePrice = 0.0;
|
||||
List<ProductVo> resultList = new ArrayList<>();
|
||||
List<String> craft_list = Optional.ofNullable(dto)
|
||||
.map(Product::getCraft) // 假设 dto 是 Dto 类型
|
||||
.map(Arrays::asList)
|
||||
.orElseGet(ArrayList::new);
|
||||
// 确保 craftList 是可变的
|
||||
craft_list = new ArrayList<>(craft_list);
|
||||
if ("领鸿".equals(plantName)) {
|
||||
if ("半透纱幔".equals(dto.getKindValue())) {
|
||||
basePrice = 15.0;
|
||||
double area = Math.max(count * number * width * length / 10000, 0.3);
|
||||
|
||||
price = new BigDecimal(basePrice * area).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
ProductVo pro = new ProductVo();
|
||||
pro.setCount(count);
|
||||
pro.setPrice(price);
|
||||
pro.setNumber(number);
|
||||
pro.setWeight(BigDecimal.valueOf(width / 100 * length / 100 * count * 0.07).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
||||
resultList.add(pro);
|
||||
return new PricingListVo(resultList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
import lingtao.net.vo.ProductVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HandFlagPricingStrategy implements PricingStrategy {
|
||||
@Override
|
||||
public PricingListVo calculatePrice(Product dto, String role) {
|
||||
String plantName = dto.getPlantName();
|
||||
double width = dto.getWidth();
|
||||
double length = dto.getLength();
|
||||
int count = dto.getCount();
|
||||
int number = dto.getNumber();
|
||||
double price = 0.0;
|
||||
double basePrice = 0.0;
|
||||
List<ProductVo> resultList = new ArrayList<>();
|
||||
if ("领鸿".equals(plantName)) {
|
||||
//春亚布
|
||||
if ("1".equals(dto.getKindValue())) {
|
||||
|
||||
// 合并逻辑,减少嵌套层级
|
||||
if (width == 17 && length <= 20) {
|
||||
basePrice = 2.5;
|
||||
} else if (width == 24 && length <= 70) {
|
||||
basePrice = 3;
|
||||
} else if (length > 70) {
|
||||
basePrice = 4;
|
||||
}
|
||||
|
||||
}
|
||||
//贡缎布
|
||||
if ("2".equals(dto.getKindValue())) {
|
||||
if (width == 17 && length <= 20) {
|
||||
basePrice = 4;
|
||||
} else if (width == 24 && length <= 70) {
|
||||
basePrice = 5;
|
||||
} else if (length > 70) {
|
||||
basePrice = 6;
|
||||
}
|
||||
}
|
||||
if (basePrice == 0) {
|
||||
return new PricingListVo(100, "暂无报价。");
|
||||
}
|
||||
|
||||
price = new BigDecimal(basePrice * count * number / 10000).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
ProductVo pro = new ProductVo();
|
||||
pro.setCount(count);
|
||||
pro.setPrice(price);
|
||||
pro.setNumber(number);
|
||||
pro.setWeight(BigDecimal.valueOf(width / 100 * length / 100 * count * 0.07).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
||||
resultList.add(pro);
|
||||
return new PricingListVo(resultList);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,231 @@
|
||||
package lingtao.net.Factory;public class MetalTargetStrategy {
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.util.PriceUtils;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
import lingtao.net.vo.ProductVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetalTargetStrategy implements PricingStrategy {
|
||||
|
||||
@Override
|
||||
public PricingListVo calculatePrice(Product dto, String role) {
|
||||
String plantName = dto.getPlantName();
|
||||
double width = dto.getWidth();
|
||||
double length = dto.getLength();
|
||||
int count = dto.getCount();
|
||||
int number = dto.getNumber();
|
||||
|
||||
List<ProductVo> resultList = new ArrayList<>();
|
||||
|
||||
// 定义纸张尺寸(单位:毫米)
|
||||
double paperLength = 295; // 纸张长度
|
||||
double paperWidth = 195; // 纸张宽度
|
||||
double basePrice = 0; // 基础价格
|
||||
double minPrice = 0; // 起步价
|
||||
double price = 0; // 最终价格
|
||||
double colorPrice = 0; // 颜色附加费
|
||||
double moreColorPrice = 0; // 多颜色附加费
|
||||
int requiredSheets = 0;
|
||||
BigDecimal weight = BigDecimal.ZERO;
|
||||
// 转换尺寸为毫米并增加边距
|
||||
length = convertToMillimetersWithMargin(length);
|
||||
width = convertToMillimetersWithMargin(width);
|
||||
|
||||
if ("金大".equals(plantName) || "鑫灿".equals(plantName)) {
|
||||
|
||||
// 检查是否超出纸张尺寸限制
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
|
||||
return new PricingListVo(100, "出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
|
||||
// 计算颜色附加费
|
||||
if (!"金色".equals(dto.getTcolor()) && !"银色".equals(dto.getTcolor()) && !"玫瑰金色".equals(dto.getTcolor())) {
|
||||
colorPrice = 1;
|
||||
}
|
||||
|
||||
if ("金大".equals(plantName)) {
|
||||
// 设置起步价
|
||||
minPrice = 45;
|
||||
if ("双色".equals(dto.getCraftMo())) {
|
||||
minPrice = 70;
|
||||
moreColorPrice = 10;
|
||||
}
|
||||
if ("彩色(三色)".equals(dto.getCraftMo())) {
|
||||
minPrice = 105;
|
||||
moreColorPrice = 20;
|
||||
|
||||
}
|
||||
colorPrice += moreColorPrice;
|
||||
// 根据数量计算基础价格
|
||||
if (requiredSheets <= 2) {
|
||||
price = minPrice + colorPrice;
|
||||
} else if (requiredSheets <= 9) {
|
||||
price = minPrice + (requiredSheets - 2) * (12 + colorPrice);
|
||||
} else if (requiredSheets <= 19) {
|
||||
price = Math.ceil((13 + colorPrice) * requiredSheets);
|
||||
} else if (requiredSheets <= 29) {
|
||||
price = Math.ceil((12 + colorPrice) * requiredSheets);
|
||||
} else if (requiredSheets <= 39) {
|
||||
price = Math.ceil((11 + colorPrice) * requiredSheets);
|
||||
} else if (requiredSheets <= 49) {
|
||||
price = Math.ceil((10 + colorPrice) * requiredSheets);
|
||||
} else {
|
||||
price = Math.ceil((9 + colorPrice) * requiredSheets);
|
||||
}
|
||||
}
|
||||
if ("鑫灿".equals(plantName)) {
|
||||
// 设置起步价
|
||||
minPrice = 45;
|
||||
if ("双色".equals(dto.getCraftMo())) {
|
||||
minPrice = 55;
|
||||
moreColorPrice = 10;
|
||||
}
|
||||
if ("彩色(三色)".equals(dto.getCraftMo())) {
|
||||
minPrice = 105;
|
||||
moreColorPrice = 20;
|
||||
|
||||
}
|
||||
colorPrice += moreColorPrice;
|
||||
// 根据数量计算基础价格
|
||||
if (requiredSheets <= 2) {
|
||||
price = minPrice + colorPrice;
|
||||
} else if (requiredSheets <= 9) {
|
||||
price = minPrice + (requiredSheets - 2) * (10 + colorPrice);
|
||||
} else if (requiredSheets <= 19) {
|
||||
price = Math.ceil((13 + colorPrice) * requiredSheets);
|
||||
} else if (requiredSheets <= 29) {
|
||||
price = Math.ceil((12 + colorPrice) * requiredSheets);
|
||||
} else if (requiredSheets <= 39) {
|
||||
price = Math.ceil((11 + colorPrice) * requiredSheets);
|
||||
} else if (requiredSheets <= 49) {
|
||||
price = Math.ceil((10 + colorPrice) * requiredSheets);
|
||||
} else if (requiredSheets <= 100) {
|
||||
price = Math.ceil((9 + colorPrice) * requiredSheets);
|
||||
} else {
|
||||
price = Math.ceil((8 + colorPrice) * requiredSheets);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if ("紫瑶".equals(plantName)) {
|
||||
paperLength = 170;
|
||||
paperWidth = 300;
|
||||
// 检查是否超出纸张尺寸限制
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
return new PricingListVo(100, "出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
// 计算颜色附加费
|
||||
if (!"银色".equals(dto.getTcolor())) {
|
||||
colorPrice = 1;
|
||||
}
|
||||
// 设置起步价
|
||||
minPrice = 40;
|
||||
if ("单色".equals(dto.getCraftMo())) {
|
||||
if (requiredSheets == 1) {
|
||||
price = colorPrice == 1 ? 45 : 40;
|
||||
} else if (requiredSheets == 2) {
|
||||
price = colorPrice == 1 ? 55 : 50;
|
||||
} else if (requiredSheets == 3) {
|
||||
price = colorPrice == 1 ? 65 : 55;
|
||||
} else if (requiredSheets == 4) {
|
||||
price = colorPrice == 1 ? 70 : 60;
|
||||
} else if (requiredSheets == 5) {
|
||||
price = colorPrice == 1 ? 75 : 65;
|
||||
} else if (requiredSheets == 6) {
|
||||
price = colorPrice == 1 ? 80 : 70;
|
||||
} else {
|
||||
price = colorPrice == 1 ? 80 + (requiredSheets - 6) * 9 : 70 + (requiredSheets - 6) * 8;
|
||||
}
|
||||
}
|
||||
if ("双色".equals(dto.getCraftMo())) {
|
||||
minPrice = 60;
|
||||
moreColorPrice = 30;
|
||||
|
||||
}
|
||||
if ("彩色(三色)".equals(dto.getCraftMo())) {
|
||||
minPrice = 70;
|
||||
moreColorPrice = 40;
|
||||
|
||||
}
|
||||
if (price == 0) {
|
||||
price = Math.ceil(minPrice + moreColorPrice * (requiredSheets - 1));
|
||||
}
|
||||
}
|
||||
// 创建产品对象并添加到结果列表
|
||||
ProductVo pro = new ProductVo();
|
||||
pro.setPrice(price);
|
||||
pro.setCount(count);
|
||||
pro.setWeight(BigDecimal.valueOf(requiredSheets / 30).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
||||
resultList.add(pro);
|
||||
return new PricingListVo(resultList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将给定的尺寸转换为毫米,并在每边增加3毫米的边距
|
||||
*
|
||||
* @param size 需要转换的原始尺寸
|
||||
* @return 转换后的尺寸,单位为毫米,包括边距
|
||||
*/
|
||||
private double convertToMillimetersWithMargin(double size) {
|
||||
return size * 10 + 2 * 1.5; // 换成毫米,每边+3
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查给定的长度和宽度是否在纸张尺寸范围内
|
||||
*
|
||||
* @param length 需要检查的长度
|
||||
* @param width 需要检查的宽度
|
||||
* @param paperLength 纸张的长度
|
||||
* @param paperWidth 纸张的宽度
|
||||
* @return 如果给定尺寸在纸张尺寸范围内,则返回true;否则返回false
|
||||
*/
|
||||
private boolean isWithinPaperSize(double length, double width, double paperLength, double paperWidth) {
|
||||
return (length <= paperLength && width <= paperWidth) || (length <= paperWidth && width <= paperLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算每张纸最多可以容纳的物品数量
|
||||
*
|
||||
* @param length 物品的长度
|
||||
* @param width 物品的宽度
|
||||
* @param paperLength 纸张的长度
|
||||
* @param paperWidth 纸张的宽度
|
||||
* @return 每张纸最多可以容纳的物品数量
|
||||
*/
|
||||
private double calculateMaxItemsPerSheet(double length, double width, double paperLength, double paperWidth) {
|
||||
return Math.max(
|
||||
Math.floor(paperLength / length) * Math.floor(paperWidth / width),
|
||||
Math.floor(paperLength / width) * Math.floor(paperWidth / length)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算完成指定数量的物品所需的纸张数量
|
||||
*
|
||||
* @param count 物品的总数量
|
||||
* @param number 每个物品需要的数量
|
||||
* @param maxItemsPerSheet 每张纸最多可以容纳的物品数量
|
||||
* @return 完成指定数量的物品所需的纸张数量
|
||||
*/
|
||||
private int calculateRequiredSheets(int count, int number, double maxItemsPerSheet) {
|
||||
return (int) Math.ceil((count * number) / maxItemsPerSheet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
import lingtao.net.vo.ProductVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PosterPricingStrategy implements PricingStrategy {
|
||||
@Override
|
||||
public PricingListVo calculatePrice(Product dto, String role) {
|
||||
String plantName = dto.getPlantName();
|
||||
String kindValue = dto.getKindValue();
|
||||
String kinde2Value = dto.getKind2Value();
|
||||
double width = dto.getWidth();
|
||||
double length = dto.getLength();
|
||||
int count = dto.getCount();
|
||||
int number = dto.getNumber();
|
||||
List<ProductVo> resultList = new ArrayList<>();
|
||||
|
||||
double price = 0;
|
||||
double basePrice = 0;
|
||||
|
||||
if ("佳达".equals(plantName)) {
|
||||
//制度牌
|
||||
if ("0".equals(kindValue)) {
|
||||
//室内写真裱冷板
|
||||
if ("0".equals(kinde2Value)) {
|
||||
basePrice = 20;
|
||||
}
|
||||
//室内写真裱冷板装小C边(小金边/银边)
|
||||
if ("3".equals(kinde2Value)) {
|
||||
basePrice = 11;
|
||||
}
|
||||
//户外写真裱冷板装小C边(小金边/银边)
|
||||
if ("8".equals(kinde2Value)) {
|
||||
basePrice = 11;
|
||||
}
|
||||
}
|
||||
//室内写真
|
||||
if ("1".equals(kindValue)) {
|
||||
//pp纸(室内)
|
||||
if ("3".equals(kinde2Value)) {
|
||||
basePrice = 12;
|
||||
}
|
||||
//直喷PVC
|
||||
if ("5".equals(kinde2Value)) {
|
||||
basePrice = 11;
|
||||
}
|
||||
//软膜
|
||||
if ("14".equals(kinde2Value)) {
|
||||
basePrice = 15;
|
||||
}
|
||||
//地贴(复防滑膜)
|
||||
if ("15".equals(kinde2Value)) {
|
||||
basePrice = 25;
|
||||
}
|
||||
}
|
||||
//户外写真
|
||||
if ("2".equals(kindValue)) {
|
||||
//户外写真白胶(国产)
|
||||
if ("0".equals(kinde2Value)) {
|
||||
basePrice = 11;
|
||||
}
|
||||
//户外写真黑胶(国产)
|
||||
if ("1".equals(kinde2Value)) {
|
||||
basePrice = 11;
|
||||
}
|
||||
//户外写真可移白胶、黑胶
|
||||
if ("2".equals(kinde2Value)) {
|
||||
basePrice = 12;
|
||||
}
|
||||
//车贴(白胶)
|
||||
if ("6".equals(kinde2Value)) {
|
||||
basePrice = 22;
|
||||
}
|
||||
//摆摊软膜灯箱
|
||||
if ("24".equals(kinde2Value)) {
|
||||
basePrice = 190;
|
||||
}
|
||||
}
|
||||
//布
|
||||
if ("3".equals(kindValue)) {
|
||||
//黑底布
|
||||
if ("2".equals(kinde2Value)) {
|
||||
basePrice = 8;
|
||||
}
|
||||
//写真布
|
||||
if ("6".equals(kinde2Value)) {
|
||||
basePrice = 0;
|
||||
}
|
||||
//油画布
|
||||
if ("8".equals(kinde2Value)) {
|
||||
basePrice = 22;
|
||||
}
|
||||
//550灯布
|
||||
if ("11".equals(kinde2Value)) {
|
||||
basePrice = 6.5;
|
||||
}
|
||||
//550黑底灯布
|
||||
if ("13".equals(kinde2Value)) {
|
||||
basePrice = 8;
|
||||
}
|
||||
}
|
||||
//展架
|
||||
if ("4".equals(kindValue)) {
|
||||
//直喷PVC装美式展架180*80cm
|
||||
if ("0".equals(kinde2Value)) {
|
||||
basePrice = 28;
|
||||
}
|
||||
//直喷PVC装美式展架160*60cm
|
||||
if ("1".equals(kinde2Value)) {
|
||||
basePrice = 21;
|
||||
}
|
||||
//PP纸装美式展架180*80cm
|
||||
if ("2".equals(kinde2Value)) {
|
||||
basePrice = 28;
|
||||
}
|
||||
//PP纸装美式展架160*60cm
|
||||
if ("3".equals(kinde2Value)) {
|
||||
basePrice = 21;
|
||||
}
|
||||
//直喷PVC装门型展架180*80cm
|
||||
if ("4".equals(kinde2Value)) {
|
||||
basePrice = 40.5;
|
||||
}
|
||||
|
||||
//PP纸装门型展架180*80cm
|
||||
if ("6".equals(kinde2Value)) {
|
||||
basePrice = 40.5;
|
||||
}
|
||||
//PP纸装门型展架160*60cm
|
||||
if ("7".equals(kinde2Value)) {
|
||||
basePrice = 37;
|
||||
}
|
||||
//X展架180*80cm(不含画面)
|
||||
if ("8".equals(kinde2Value)) {
|
||||
basePrice = 12;
|
||||
}
|
||||
//X展架160*60cm(不含画面)
|
||||
if ("9".equals(kinde2Value)) {
|
||||
basePrice = 10;
|
||||
}
|
||||
//门型展架180*80cm(不含画面)
|
||||
if ("10".equals(kinde2Value)) {
|
||||
basePrice = 30;
|
||||
}
|
||||
//门型展架160*60cm(不含画面)
|
||||
if ("11".equals(kinde2Value)) {
|
||||
basePrice = 27;
|
||||
}
|
||||
//直喷pvc铝合金易拉宝202*78cm
|
||||
if ("12".equals(kinde2Value)) {
|
||||
basePrice = 40;
|
||||
}
|
||||
//直喷pvc塑钢易拉宝200*80cm
|
||||
if ("13".equals(kinde2Value)) {
|
||||
basePrice = 47;
|
||||
}
|
||||
}
|
||||
if (basePrice == 0) {
|
||||
return new PricingListVo(100, "暂无报价。");
|
||||
}
|
||||
|
||||
if (!"4".equals(kindValue)) {
|
||||
price = new BigDecimal(basePrice * count * number * width * length / 10000).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
} else {
|
||||
price = new BigDecimal(basePrice * count * number).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
}
|
||||
if ("领鸿".equals(plantName)) {
|
||||
//旗帜布
|
||||
if ("6".equals(dto.getKindValue())) {
|
||||
basePrice = 6.5;
|
||||
}
|
||||
//贡缎布
|
||||
if ("7".equals(dto.getKindValue())) {
|
||||
basePrice = 15;
|
||||
}
|
||||
if (basePrice == 0) {
|
||||
return new PricingListVo(100, "暂无报价。");
|
||||
}
|
||||
double area = Math.max(count * number * width * length / 10000, 0.3);
|
||||
price = new BigDecimal(basePrice * area).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
//旗杆
|
||||
if (dto.getYaheng() != null && dto.getYaheng() > 0) {
|
||||
price = BigDecimal.valueOf(price).add(BigDecimal.valueOf(dto.getYaheng() * 15.0)).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
}
|
||||
ProductVo pro = new ProductVo();
|
||||
pro.setCount(count);
|
||||
pro.setPrice(price);
|
||||
pro.setNumber(number);
|
||||
resultList.add(pro);
|
||||
return new PricingListVo(resultList);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,10 @@
|
||||
package lingtao.net.Factory;public interface PricingStrategy {
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PricingStrategy {
|
||||
PricingListVo calculatePrice(Product dto, String role);
|
||||
}
|
||||
|
||||
@@ -1,2 +1,31 @@
|
||||
package lingtao.net.Factory;public class PricingStrategyFactory {
|
||||
package lingtao.net.Factory;
|
||||
|
||||
public class PricingStrategyFactory {
|
||||
public static PricingStrategy getStrategy(String proType) {
|
||||
switch (proType) {
|
||||
case "0":
|
||||
return new StickerPricingStrategy();
|
||||
// 其他产品类型对应的策略
|
||||
case "金属标":
|
||||
return new MetalTargetStrategy();
|
||||
// 其他产品类型对应的策略
|
||||
case "卡片少数量":
|
||||
return new CardPricingStrategy();
|
||||
case "17":
|
||||
return new PosterPricingStrategy();
|
||||
case "帆布":
|
||||
return new CanvasPricingStrategy();
|
||||
case "班旗":
|
||||
return new ClassFlagPricingStrategy();
|
||||
case "挂布":
|
||||
return new DossalPricingStrategy();
|
||||
case "手拉旗":
|
||||
return new HandFlagPricingStrategy();
|
||||
// 其他产品类型对应的策略
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
package lingtao.net.Factory;
|
||||
|
||||
import lingtao.net.bean.Product;
|
||||
import lingtao.net.vo.PricingListVo;
|
||||
import lingtao.net.vo.ProductVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 提供不干胶产品的定价策略。
|
||||
* 该类主要用于处理贴纸产品价格的计算,根据不同的用户角色提供相应的价格策略。
|
||||
*/
|
||||
public class StickerPricingStrategy implements PricingStrategy {
|
||||
|
||||
/**
|
||||
* 根据用户角色计算产品价格。
|
||||
* 此方法旨在根据不同用户的角色对产品进行定价,但当前实现尚未完成。
|
||||
*
|
||||
* @param dto 产品信息的传输对象,包含需要计算价格的产品数据。
|
||||
* @param role 用户角色,用于确定适用的定价策略。
|
||||
* @return 返回经过计算价格更新后的产品列表,当前实现返回null。
|
||||
*/
|
||||
@Override
|
||||
public PricingListVo calculatePrice(Product dto, String role) {
|
||||
String plantName = dto.getPlantName();
|
||||
double width = dto.getWidth();
|
||||
double length = dto.getLength();
|
||||
int count = dto.getCount();
|
||||
int number = dto.getNumber();
|
||||
// 定义纸张尺寸(单位:毫米)
|
||||
double paperLength = 280; // 纸张长度
|
||||
double paperWidth = 420; // 纸张宽度
|
||||
String basePrice = "0"; // 基础价格
|
||||
BigDecimal price = new BigDecimal(0); // 最终价格
|
||||
length = convertToMillimetersWithMargin(length);
|
||||
width = convertToMillimetersWithMargin(width);
|
||||
int requiredSheets = 0;
|
||||
List<ProductVo> resultList = new ArrayList<>();
|
||||
|
||||
if ("艾印".equals(plantName) || "即客".equals(plantName)) {
|
||||
Map<String, String> kindValuePrice = new HashMap<String, String>() {{
|
||||
put("0", "2.3"); //铜版纸不干胶
|
||||
put("1", "2.9"); //pvc不干胶
|
||||
put("2", "2.9"); //透明不干胶
|
||||
put("3", "2.3"); //牛皮纸
|
||||
put("5", "3.2"); //哑金不干胶
|
||||
put("6", "3.2"); //哑银不干胶
|
||||
put("7", "2.7"); //书写纸不干胶
|
||||
put("亮金", "3.2"); //
|
||||
put("亮银", "3.2"); //
|
||||
put("珠光冰白纸", "3.2"); //
|
||||
put("美纹纸", "2.8"); //
|
||||
put("拉丝金", "3.3"); //
|
||||
put("拉丝银", "3.3"); //
|
||||
put("易碎纸不干胶", "3.7"); //
|
||||
put("PP合成纸", "2.9"); //
|
||||
put("刚古水纹超白", "2.8"); //
|
||||
}};
|
||||
if ("即客".equals(plantName)) {
|
||||
kindValuePrice.put("树纹纸", "3.3");
|
||||
kindValuePrice.put("银平光", "3.6");
|
||||
kindValuePrice.put("白散金", "2.8");
|
||||
kindValuePrice.put("红洒金", "2.8");
|
||||
kindValuePrice.put("布纹纸超白", "5");
|
||||
kindValuePrice.put("草香纸", "3");
|
||||
}
|
||||
if (!kindValuePrice.containsKey(dto.getKindValue())) {
|
||||
return new PricingListVo(100, "暂不支持该产品");
|
||||
|
||||
}
|
||||
basePrice = kindValuePrice.get(dto.getKindValue());
|
||||
// 检查是否超出纸张尺寸限制
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
return new PricingListVo(100, "超出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
|
||||
price = new BigDecimal(basePrice).multiply(new BigDecimal(requiredSheets)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
|
||||
}
|
||||
if ("欣海信".equals(dto.getPlantName())) {
|
||||
paperLength = 390; // 纸张长度
|
||||
paperWidth = 272; // 纸张宽度
|
||||
|
||||
// 检查是否超出纸张尺寸限制
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
return new PricingListVo(100, "超出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
BigDecimal paperCount = new BigDecimal(requiredSheets);
|
||||
BigDecimal yinbai = new BigDecimal("0");
|
||||
//铜版纸
|
||||
if ("0".equals(dto.getKindValue())) {
|
||||
basePrice = "2.5";
|
||||
|
||||
} else {
|
||||
basePrice = "4";
|
||||
}
|
||||
if ("印白墨".equals(dto.getYinbai())) {
|
||||
yinbai = "0".equals(dto.getKindValue()) ? new BigDecimal("20") : new BigDecimal("22");
|
||||
}
|
||||
price = new BigDecimal(basePrice).multiply(paperCount).setScale(2, RoundingMode.HALF_UP);
|
||||
price = price.add(yinbai.multiply(paperCount)).setScale(2, RoundingMode.HALF_UP);
|
||||
if (dto.getN_mq_num() > 0) {
|
||||
price = price.add(paperCount).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
}
|
||||
if ("彩印通".equals(dto.getPlantName())) {
|
||||
Map<String, String> kindValuePrice = new HashMap<String, String>() {{
|
||||
put("0", "2"); //铜版纸不干胶
|
||||
put("1", "3.2"); //pvc不干胶
|
||||
put("2", "3.2"); //透明不干胶
|
||||
put("3", "2.5"); //牛皮纸
|
||||
put("5", "3.5"); //哑金不干胶
|
||||
put("6", "3.5"); //哑银不干胶
|
||||
put("7", "3"); //书写纸不干胶
|
||||
put("亮金", "3.5"); //
|
||||
put("亮银", "4"); //
|
||||
put("珠光冰白纸", "3.5"); //
|
||||
put("美纹纸", "2.5"); //
|
||||
put("红洒金", "3.5"); //
|
||||
put("布纹纸超白", "3.5"); //
|
||||
put("刚古水纹超白", "3.5"); //
|
||||
put("银平光", "4"); //
|
||||
put("拉丝金", "3.5"); //
|
||||
put("拉丝银", "3.5"); //
|
||||
put("易碎纸不干胶", "4"); //
|
||||
put("PP合成纸", "3.2"); //
|
||||
put("草香纸", "3.5"); //
|
||||
put("树纹纸", "3.5"); //
|
||||
put("白散金", "3.5"); //
|
||||
put("飘金超白不干胶", "3.5"); //
|
||||
put("美纹纸散金", "3.5"); //
|
||||
}};
|
||||
if ("0".equals(dto.getKindValue())) {
|
||||
paperLength = 450; // 纸张长度
|
||||
paperWidth = 320; // 纸张宽度
|
||||
} else {
|
||||
paperLength = 420; // 纸张长度
|
||||
paperWidth = 297; // 纸张宽度
|
||||
}
|
||||
if (!kindValuePrice.containsKey(dto.getKindValue())) {
|
||||
return new PricingListVo(100, "暂无报价"); // 返回空列表表示不适用
|
||||
}
|
||||
if (!isWithinPaperSize(length, width, paperLength, paperWidth)) {
|
||||
return new PricingListVo(100, "出纸张尺寸限制"); // 返回空列表表示不适用
|
||||
}
|
||||
basePrice = kindValuePrice.get(dto.getKindValue());
|
||||
// 计算一张纸能容纳的最大金属标数量
|
||||
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
|
||||
|
||||
// 计算所需纸张数量
|
||||
requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
|
||||
BigDecimal yinbai = new BigDecimal("0");
|
||||
if ("印白墨".equals(dto.getYinbai())) {
|
||||
yinbai = "2".equals(dto.getKindValue()) ? new BigDecimal("6.2") : new BigDecimal("3");
|
||||
}
|
||||
BigDecimal paperCount = new BigDecimal(requiredSheets);
|
||||
price = new BigDecimal(basePrice).multiply(paperCount).setScale(2, RoundingMode.HALF_UP);
|
||||
price = price.add(yinbai.multiply(paperCount)).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
ProductVo pro = new ProductVo();
|
||||
pro.setPrice(price.doubleValue());
|
||||
pro.setCount(count);
|
||||
|
||||
// if ("1".equals(dto.getKindValue())) {
|
||||
// pro.setWeight(BigDecimal.valueOf(number * length / 100 * width / 100 * requiredSheets * 0.3).setScale(2, RoundingMode.HALF_UP).toString());
|
||||
// } else {
|
||||
// pro.setWeight(BigDecimal.valueOf(number * length / 100 * width / 100 * requiredSheets * 0.24).setScale(2, RoundingMode.HALF_UP).toString());
|
||||
// }
|
||||
|
||||
pro.setWeight(BigDecimal.valueOf(number * length / 1000 * width / 1000 * count * 0.21 * 1.16).setScale(2, RoundingMode.HALF_UP).toString());
|
||||
// 创建产品对象并添加到结果列表
|
||||
resultList.add(pro);
|
||||
return new PricingListVo(resultList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将给定的尺寸转换为毫米,并在每边增加3毫米的边距
|
||||
*
|
||||
* @param size 需要转换的原始尺寸
|
||||
* @return 转换后的尺寸,单位为毫米,包括边距
|
||||
*/
|
||||
private double convertToMillimetersWithMargin(double size) {
|
||||
return size * 10 + 2 * 2; // 换成毫米,每边+2
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查给定的长度和宽度是否在纸张尺寸范围内
|
||||
*
|
||||
* @param length 需要检查的长度
|
||||
* @param width 需要检查的宽度
|
||||
* @param paperLength 纸张的长度
|
||||
* @param paperWidth 纸张的宽度
|
||||
* @return 如果给定尺寸在纸张尺寸范围内,则返回true;否则返回false
|
||||
*/
|
||||
private boolean isWithinPaperSize(double length, double width, double paperLength, double paperWidth) {
|
||||
return (length <= paperLength && width <= paperWidth) || (length <= paperWidth && width <= paperLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算每张纸最多可以容纳的物品数量
|
||||
*
|
||||
* @param length 物品的长度
|
||||
* @param width 物品的宽度
|
||||
* @param paperLength 纸张的长度
|
||||
* @param paperWidth 纸张的宽度
|
||||
* @return 每张纸最多可以容纳的物品数量
|
||||
*/
|
||||
private double calculateMaxItemsPerSheet(double length, double width, double paperLength, double paperWidth) {
|
||||
return Math.max(
|
||||
Math.floor(paperLength / length) * Math.floor(paperWidth / width),
|
||||
Math.floor(paperLength / width) * Math.floor(paperWidth / length)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算完成指定数量的物品所需的纸张数量
|
||||
*
|
||||
* @param count 物品的总数量
|
||||
* @param number 每个物品需要的数量
|
||||
* @param maxItemsPerSheet 每张纸最多可以容纳的物品数量
|
||||
* @return 完成指定数量的物品所需的纸张数量
|
||||
*/
|
||||
private int calculateRequiredSheets(int count, int number, double maxItemsPerSheet) {
|
||||
return (int) Math.ceil((count * number) / maxItemsPerSheet);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user