瀏覽代碼

配送规则新增适用配送方式的方法

hulh 8 年之前
父節點
當前提交
793b1027bf

+ 9 - 0
src/main/java/com/uas/platform/b2c/logistics/dao/DistributionRuleDao.java

@@ -48,4 +48,13 @@ public interface DistributionRuleDao extends JpaSpecificationExecutor<Distributi
 	 */
 	@Query(value = "select d.ruleName from DistributionRule d where d.enuu = :enuu")
 	List<String> findAllRuleNameByEnuu(@Param("enuu") Long enuu);
+
+	/**
+	 * 根据enuu和配送方式获取配送规则列表
+	 *
+	 * @param enuu
+	 * @param shippingMethod
+	 * @return
+	 */
+	List<DistributionRule> findByEnuuAndShippingMethod(Long enuu, Integer shippingMethod);
 }

+ 94 - 0
src/main/java/com/uas/platform/b2c/logistics/service/impl/DistributionRuleServiceImpl.java

@@ -1,8 +1,10 @@
 package com.uas.platform.b2c.logistics.service.impl;
 
+import com.uas.platform.b2c.core.constant.SplitChar;
 import com.uas.platform.b2c.core.support.SystemSession;
 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.service.DistributionRuleService;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.model.PageInfo;
@@ -16,7 +18,10 @@ import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Created by hulh on 2017/8/28.
@@ -151,4 +156,93 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
 		int count = distributionRuleDao.findCountByEnuu(enuu);
 		return ResultMap.success(count);
 	}
+
+//	@Override
+	public List<DistributionRule> ruleMatchArea(Integer method, String area) {
+		Long enuu = SystemSession.getUser().getEnterprise().getUu();
+		List<DistributionRule> resultList = new ArrayList<>();
+		// 根据配送方式找出所有的配送规则
+		List<DistributionRule> methodList = distributionRuleDao.findByEnuuAndShippingMethod(enuu, method);
+
+		for (DistributionRule rule : methodList){
+			List<RuleQtyArea> qtyArea = rule.getAreas();
+			Map<String, Map<String, List<String>>> resultMap = convertArea(qtyArea);
+			boolean isContains = containsArea(resultMap, area);
+			if (isContains){
+				resultList.add(rule);
+			}
+		}
+		return resultList;
+	}
+
+	/**
+	 * 根据分段地区集合转化为可用的Map集合
+	 *
+	 * @param qtyArea 分段地区集合
+	 * @return
+	 */
+	public Map<String, Map<String, List<String>>> convertArea(List<RuleQtyArea> qtyArea){
+		Map<String, Map<String, List<String>>> areaMap = new HashMap<>();
+
+		for (RuleQtyArea a : qtyArea){
+			if (a.getProvince() != null && a.getProvince().length() != 0){
+				//判断该RuleQtyArea是否包含省字段
+				Map<String, List<String>> cityMap = null;
+				if (!areaMap.containsKey(a.getProvince())){
+					cityMap = new HashMap<>();
+					areaMap.put(a.getProvince(), cityMap);
+				}
+				cityMap = areaMap.get(a.getProvince());
+				if (a.getCity() != null && a.getCity().length() != 0){
+					//判断该RuleQtyArea是否包含市字段
+					List<String> areaList = null;
+					if (!cityMap.containsKey(a.getCity())){
+						areaList = new ArrayList<>();
+						cityMap.put(a.getCity(), areaList);
+					}
+					areaList = cityMap.get(a.getCity());
+					if (a.getArea() != null && a.getArea().length() != 0){
+						if (!areaList.contains(a.getArea())){
+							areaList.add(a.getArea());
+						}
+					}
+				}
+			}
+		}
+		return areaMap;
+	}
+
+	/**
+	 * 是否匹配该地区
+	 *
+	 * @param resultMap 转化的地区map集合
+	 * @param area 要匹配的地区
+	 * @return
+	 */
+	public boolean containsArea(Map<String, Map<String, List<String>>> resultMap, String area){
+		String[] areaArray = area.split(SplitChar.COMMA); //拆分地区数据,获取省,市,区的数组
+		if (resultMap.containsKey(areaArray[0])){ //是否包含该省
+			Map<String, List<String>> cityMap = resultMap.get(areaArray[0]);
+			if (cityMap.isEmpty()){ //没有市数据
+				return true;
+			}else {
+				if (cityMap.containsKey(areaArray[1])){ //是否包含该市
+					List<String> areaList = cityMap.get(areaArray[1]);
+					if (areaList.isEmpty()){ //没有区数据
+						return true;
+					}else {
+						if (areaList.contains(areaArray[2])){
+							return true;
+						}else {
+							return false;
+						}
+					}
+				}else {
+					return false;
+				}
+			}
+		}else {
+			return false;
+		}
+	}
 }

+ 22 - 0
src/main/webapp/resources/js/vendor/controllers/forstore/vendor_deliveryRule_ctrl.js

@@ -587,6 +587,28 @@ define([ 'app/app' ], function(app) {
             var me = this;
             me.$data = tree;
 
+            /**
+             * 初始化树,勾选已有的数据
+             * @param initData
+             */
+            me.newInitData = function (initData) {
+                //initData,这时只有省,市,区的数据
+                if(initData){
+                    angular.forEach(initData, function (v) {
+                        var p = {};
+                        for(var i in me.$data) {
+                            var m = me.$data[i];
+                           for(var i in m.items){
+                               var value = m.items[i];
+                               if (value.label == v.province){
+                                   p = value; break;
+                               }
+                           }
+                        }
+                    })
+                }
+            };
+
             me.initData = function (initData) {
                 console.log(initData);
                 if(initData) {