Commit 01b5fc0a by guojuxing

策略命中接口调整

parent 1b27c126
package com.gic.store.service;
import com.gic.store.dto.StoreDTO;
import com.gic.store.dto.StoreStrategyDTO;
import com.gic.store.entity.TabStore;
import com.gic.store.entity.TabStoreStrategy;
import com.github.pagehelper.Page;
......@@ -122,4 +124,12 @@ public interface StoreStrategyService {
*/
String isHitStrategy(int storeId, int enterpriseId, int strategyType);
/**
* 验证是否命中,如果命中,返回的result值就是命中值,否则是空字符串
* @param storeDTO
* @param strategyType 1:门店启用状态策略 2:分组策略
* @return
*/
String isHitStrategy(StoreDTO storeDTO, int strategyType);
}
......@@ -6,6 +6,8 @@ import com.gic.commons.util.EntityUtil;
import com.gic.store.constant.StoreGroupConstant;
import com.gic.store.constant.StrategyStoreFieldEnum;
import com.gic.store.dao.mapper.TabStoreStrategyMapper;
import com.gic.store.dto.StoreDTO;
import com.gic.store.dto.StoreExtendDTO;
import com.gic.store.dto.StoreStrategyDTO;
import com.gic.store.entity.TabStore;
import com.gic.store.entity.TabStoreExtend;
......@@ -16,10 +18,13 @@ import com.gic.store.service.StoreStrategyService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author guojx
......@@ -152,12 +157,25 @@ public class StoreStrategyServiceImpl implements StoreStrategyService{
@Override
public String isHitStrategy(int storeId, int enterpriseId, int strategyType) {
List<TabStoreStrategy> strategyList = listStoreStrategy(enterpriseId, strategyType);
TabStore store = storeService.getById(storeId);
return validIsHit(strategyType, store, null);
}
@Override
public String isHitStrategy(StoreDTO storeDTO, int strategyType) {
return validIsHit(strategyType, EntityUtil.changeEntityNew(TabStore.class, storeDTO), storeDTO.getStoreExtendList());
}
private String validIsHit(int strategyType, TabStore store, List<StoreExtendDTO> extendDTOList) {
Map<Integer, String> extendMap = new HashMap<>(16);
if (extendDTOList != null) {
for (StoreExtendDTO extendDTO : extendDTOList) {
extendMap.put(extendDTO.getStoreFieldId(), extendDTO.getValue());
}
}
//命中值
String result = "";
TabStore store = storeService.getById(storeId);
List<TabStoreStrategy> strategyList = listStoreStrategy(store.getEnterpriseId(), strategyType);
for (int num = 0, strategyLength = strategyList.size(); num < strategyLength; num ++) {
//如果数值对上,则说明命中
int validSize = 0;
......@@ -198,9 +216,16 @@ public class StoreStrategyServiceImpl implements StoreStrategyService{
}
} else {
//单选或者多选
TabStoreExtend storeExtend = storeExtendService.getStoreExtendByStoreIdAndFieldId(storeId, Integer.parseInt(key));
if (!isBrandIdHitStrategy(storeExtend.getValue(), value)) {
continue;
if (extendDTOList != null) {
TabStoreExtend storeExtend = storeExtendService.getStoreExtendByStoreIdAndFieldId(store.getStoreId(), Integer.parseInt(key));
if (storeExtend != null && !isBrandIdHitStrategy(storeExtend.getValue(), value)) {
continue;
}
} else {
String storeFieldValue = extendMap.get(Integer.parseInt(key));
if (StringUtils.isNotBlank(storeFieldValue) && !isBrandIdHitStrategy(storeFieldValue, value)) {
continue;
}
}
}
......@@ -226,7 +251,6 @@ public class StoreStrategyServiceImpl implements StoreStrategyService{
break;
}
}
return result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment