Browse Source

新建单例的自提配送规则

hulh 8 years ago
parent
commit
14da92b3f5

+ 23 - 0
src/main/java/com/uas/platform/b2c/logistics/model/UsableRuleInfo.java

@@ -1,10 +1,33 @@
 package com.uas.platform.b2c.logistics.model;
 package com.uas.platform.b2c.logistics.model;
 
 
+import com.uas.platform.b2c.core.constant.Type;
+
 /**
 /**
  * Created by hulh on 2017/9/13.
  * Created by hulh on 2017/9/13.
  * 适用的配送规则简要信息
  * 适用的配送规则简要信息
  */
  */
 public class UsableRuleInfo {
 public class UsableRuleInfo {
+
+	/**
+	 * 单例实现共用的上门自提配送规则
+	 */
+	private static volatile UsableRuleInfo TAKE_SELF_RULE = null;
+	private static final String TAKE_SELF_NAME = "上门自提免运费";
+
+	public static UsableRuleInfo getTakeSelfRule(){
+		if (TAKE_SELF_RULE == null){
+			synchronized (UsableRuleInfo.class){
+				if (TAKE_SELF_RULE == null){
+					TAKE_SELF_RULE = new UsableRuleInfo();
+					TAKE_SELF_RULE.setMethod(Type.Delivery_BySelf_Code.value());
+					TAKE_SELF_RULE.setRuleName(TAKE_SELF_NAME);
+					TAKE_SELF_RULE.setFare(0d);
+				}
+			}
+		}
+		return TAKE_SELF_RULE;
+	}
+
 	/**
 	/**
 	 * 配送id
 	 * 配送id
 	 */
 	 */

+ 19 - 10
src/main/java/com/uas/platform/b2c/logistics/service/impl/DistributionRuleServiceImpl.java

@@ -5,11 +5,9 @@ import com.uas.platform.b2c.core.config.SysConf;
 import com.uas.platform.b2c.core.constant.ShortConstant;
 import com.uas.platform.b2c.core.constant.ShortConstant;
 import com.uas.platform.b2c.core.constant.SplitChar;
 import com.uas.platform.b2c.core.constant.SplitChar;
 import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.b2c.logistics.dao.AddressTakeSelfDao;
 import com.uas.platform.b2c.logistics.dao.DistributionRuleDao;
 import com.uas.platform.b2c.logistics.dao.DistributionRuleDao;
-import com.uas.platform.b2c.logistics.model.DistributionRule;
-import com.uas.platform.b2c.logistics.model.RuleQtyArea;
-import com.uas.platform.b2c.logistics.model.RuleQtyFare;
-import com.uas.platform.b2c.logistics.model.UsableRuleInfo;
+import com.uas.platform.b2c.logistics.model.*;
 import com.uas.platform.b2c.logistics.service.DistributionRuleService;
 import com.uas.platform.b2c.logistics.service.DistributionRuleService;
 import com.uas.platform.b2c.prod.store.dao.StoreInDao;
 import com.uas.platform.b2c.prod.store.dao.StoreInDao;
 import com.uas.platform.b2c.prod.store.model.StoreIn;
 import com.uas.platform.b2c.prod.store.model.StoreIn;
@@ -18,6 +16,7 @@ import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.PageParams;
 import com.uas.platform.core.model.PageParams;
+import com.uas.platform.core.model.Type;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
@@ -47,6 +46,9 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
 	@Autowired
 	@Autowired
 	private StoreInDao storeInDao;
 	private StoreInDao storeInDao;
 
 
+	@Autowired
+	private AddressTakeSelfDao takeSelfDao;
+
 	@Autowired
 	@Autowired
 	private SysConf sysConf;
 	private SysConf sysConf;
 
 
@@ -287,12 +289,14 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
 			throw new IllegalOperatorException("配送规则信息丢失,请刷新后重试");
 			throw new IllegalOperatorException("配送规则信息丢失,请刷新后重试");
 		}
 		}
 		for (UsableRuleInfo info : ruleList){
 		for (UsableRuleInfo info : ruleList){
-			DistributionRule rule = distributionRuleDao.findOne(info.getId());
-			if (rule == null){
-				throw new IllegalOperatorException("配送规则信息丢失,请刷新后重试");
+			if (info.getId() != null && info.getMethod() != Type.Delivery_BySelf_Code.value()){
+				DistributionRule rule = distributionRuleDao.findOne(info.getId());
+				if (rule == null){
+					throw new IllegalOperatorException("配送规则信息丢失,请刷新后重试");
+				}
+				Double fare = getFareOfRule(rule, price);
+				info.setFare(fare);
 			}
 			}
-			Double fare = getFareOfRule(rule, price);
-			info.setFare(fare);
 		}
 		}
 		return ruleList;
 		return ruleList;
 	}
 	}
@@ -347,10 +351,15 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
 					ruleInfoList.add(info);
 					ruleInfoList.add(info);
 				}
 				}
 			}
 			}
-			if (methodList.size() == 3){
+			if (methodList.size() == 2){
 				break;
 				break;
 			}
 			}
 		}
 		}
+		List<AddressTakeSelf> takeSelfList = takeSelfDao.findByEnuuAndActiveOrderByCreatetimeDesc(store.getEnUU(), ShortConstant.YES_SHORT);
+		if (!CollectionUtils.isEmpty(takeSelfList)){
+			UsableRuleInfo takeRule = UsableRuleInfo.getTakeSelfRule();
+			ruleInfoList.add(takeRule);
+		}
 		return ruleInfoList;
 		return ruleInfoList;
 	}
 	}