|
|
@@ -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.
|
|
|
@@ -192,4 +197,93 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
}
|
|
|
return ResultMap.success(repeat);
|
|
|
}
|
|
|
+
|
|
|
+ @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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|