|
|
@@ -7,6 +7,7 @@ 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.model.RuleQtyFare;
|
|
|
import com.uas.platform.b2c.logistics.service.DistributionRuleService;
|
|
|
import com.uas.platform.b2c.prod.store.dao.StoreInDao;
|
|
|
import com.uas.platform.b2c.prod.store.model.StoreIn;
|
|
|
@@ -60,6 +61,13 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
}, pageInfo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存或修改配送规则
|
|
|
+ * @param isAdd true-保存,false-另存
|
|
|
+ * @param isActive
|
|
|
+ * @param rule
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public ResultMap saveDistributionRule(Boolean isAdd, Boolean isActive, DistributionRule rule) {
|
|
|
if (rule.getShippingMethod() == null){
|
|
|
@@ -74,7 +82,7 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
if (rule.getFareType() == 2 && CollectionUtils.isEmpty(rule.getFares())){
|
|
|
return new ResultMap(CodeType.NO_INFO, "请完善计费方式");
|
|
|
}
|
|
|
- if (rule.getId() == null){
|
|
|
+ if (rule.getId() == null){ //新增配送规则,初始化数据
|
|
|
Long uu = SystemSession.getUser().getUserUU();
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
rule.setUseruu(uu);
|
|
|
@@ -91,7 +99,7 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
}else {
|
|
|
rule.setActive(ShortConstant.NO_SHORT);
|
|
|
}
|
|
|
- if (!isAdd){
|
|
|
+ if (!isAdd){ //若为另存为,则将主键id设为空
|
|
|
if (rule.getId() != null){
|
|
|
rule.setId(null);
|
|
|
}
|
|
|
@@ -137,6 +145,11 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
return ResultMap.success(null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改,排序已有配送规则列表,本配送规则不参与排序,空出num位置
|
|
|
+ * @param id
|
|
|
+ * @param num
|
|
|
+ */
|
|
|
public void sortRule(Long id, int num){
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
List<DistributionRule> ruleList = distributionRuleDao.findAllByEnuu(enuu);
|
|
|
@@ -153,15 +166,17 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
distributionRuleDao.save(ruleList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增,排序已有配送规则列表,空出num位置
|
|
|
+ * @param num
|
|
|
+ */
|
|
|
public void sortRule(int num){
|
|
|
-// System.out.println("num=" + num);
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
List<DistributionRule> ruleList = distributionRuleDao.findAllByEnuu(enuu);
|
|
|
int start = 1;
|
|
|
for (DistributionRule rule : ruleList){
|
|
|
if (start == num){
|
|
|
start++;
|
|
|
- System.out.println("start=" + start);
|
|
|
}
|
|
|
rule.setNum(start++);
|
|
|
}
|
|
|
@@ -187,6 +202,10 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
return distributionRuleDao.findAllRuleNameByEnuu(enuu);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询已设置配送规则的数量
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public ResultMap findCountRule() {
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
@@ -194,16 +213,21 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
return ResultMap.success(count);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据配送规则名称查询是否已存在
|
|
|
+ * @param id
|
|
|
+ * @param ruleName 配送规则名称
|
|
|
+ * @param newSave 是否为另存,true-另存 false-保存
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public ResultMap containsName(Long id, String ruleName, Boolean newSave) {
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
Boolean repeat = null;
|
|
|
-// System.out.println("id=" + id);
|
|
|
if (id != null){
|
|
|
//修改配送规则情况,分保存和另存为两种
|
|
|
if (newSave){ //另存为
|
|
|
int count = distributionRuleDao.findCountRuleName(enuu, ruleName);
|
|
|
-// System.out.println("count=" + count);
|
|
|
if (count != 0){
|
|
|
repeat = true;
|
|
|
}else {
|
|
|
@@ -215,7 +239,6 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
repeat = false;
|
|
|
}else {
|
|
|
int count = distributionRuleDao.findCountRuleName(enuu, ruleName);
|
|
|
-// System.out.println("count=" + count);
|
|
|
if (count != 0){
|
|
|
repeat = true;
|
|
|
}else {
|
|
|
@@ -225,7 +248,6 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
}
|
|
|
}else { //新增配送规则情况
|
|
|
int count = distributionRuleDao.findCountRuleName(enuu, ruleName);
|
|
|
-// System.out.println("count=" + count);
|
|
|
if (count != 0){
|
|
|
repeat = true;
|
|
|
}else {
|
|
|
@@ -235,12 +257,25 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
return ResultMap.success(repeat);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Integer> findUsableShippingMethod() {
|
|
|
+ Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ return distributionRuleDao.findShippingMethodByEnuuAndActive(enuu, ShortConstant.YES_SHORT);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据配送方式获取匹配地区的配送规则列表
|
|
|
+ * @param method
|
|
|
+ * @param area
|
|
|
+ * @param uuid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<DistributionRule> ruleMatchArea(Integer method, String area, String uuid) {
|
|
|
StoreIn store = storeInDao.findByUuid(uuid);
|
|
|
|
|
|
List<DistributionRule> resultList = new ArrayList<>();
|
|
|
- // 根据配送方式找出所有的配送规则
|
|
|
+ // 根据配送方式找出所有生效的配送规则
|
|
|
List<DistributionRule> methodList = distributionRuleDao.findByEnuuAndShippingMethodAndActive(store.getEnUU(), method, ShortConstant.YES_SHORT);
|
|
|
|
|
|
for (DistributionRule rule : methodList){
|
|
|
@@ -254,6 +289,51 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取运费最小的配送规则
|
|
|
+ * @param price
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public DistributionRule getRuleOInMinFare(Double price){
|
|
|
+ //获取匹配地区的配送规则列表
|
|
|
+ List<DistributionRule> matchList = null;
|
|
|
+ DistributionRule minRule = null; //最少运费的配送规则
|
|
|
+ Double minFare = getFareOfRule(matchList.get(0), price);
|
|
|
+ for (int i = 1; i<matchList.size(); i++){
|
|
|
+ Double fare = getFareOfRule(matchList.get(i), price);
|
|
|
+ if (fare < minFare){
|
|
|
+ minRule = matchList.get(i);
|
|
|
+ minFare = fare;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return minRule;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定配送规则的运费
|
|
|
+ * @param rule
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Double getFareOfRule(DistributionRule rule, Double price){
|
|
|
+ Double needFare = null;
|
|
|
+ if (rule.getFareType() == 1){
|
|
|
+ needFare = rule.getUniformPrice();
|
|
|
+ }else {
|
|
|
+ for (RuleQtyFare fare : rule.getFares()){
|
|
|
+ if (fare.getStart() <= price){
|
|
|
+ if (fare.getEnd() != null){
|
|
|
+ if (fare.getEnd() > price){
|
|
|
+ needFare = fare.getFare();
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ needFare = fare.getFare();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return needFare;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据分段地区集合转化为可用的Map集合
|
|
|
*
|