Commit ea3d86f2 by 陶光胜

观云台小程序

parent 00b4adfb
......@@ -47,8 +47,16 @@ public class BaseSalesController {
List<String> onLine = this.storeSearchUtils.onLineStoreSearch(userId, enterpriseId, searchJSON);
List<Integer> childrenStoreGroupIdList = this.storeSearchUtils.getChildrenStoreGroupIdList(parentId);
List<Long> mbrAreaIdList = this.dataAuthUtils.getMbrAreaId(userId, enterpriseId);
Integer maxLevel = 0;
/******线下渠道需要点击下钻,该值只会在线下时才会使用********/
if(level == null){
level = this.storeSearchUtils.getLevel(userId, enterpriseId, searchJSON).getLevel();
LevelVo levelVo = this.storeSearchUtils.getLevel(userId, enterpriseId, searchJSON);
level = levelVo.getLevel();
maxLevel = levelVo.getMaxLevel();
}
/****首页进入基础页面时,如果渠道为空,根据当前条件判断渠道,channel==null表示多渠道***/
if(channel == null){
channel = this.storeSearchUtils.getChannel(userId, enterpriseId, searchJSON);
}
BaseSalesParamsDTO dto = new BaseSalesParamsDTO();
dto.setChannel(channel);
......@@ -67,7 +75,7 @@ public class BaseSalesController {
dto.setPageSize(pageSize);
ServiceResponse<Page<BaseSalesDTO>> response = this.baseSalesApiService.pageBaseSales(dto);
BaseSalesVo vo = new BaseSalesVo();
vo.setPage(this.parseData(response.getResult(), channel, enterpriseId, level));
vo.setPage(this.parseData(response.getResult(), channel, enterpriseId, level, maxLevel));
dto.setCountType(2);//合计
ServiceResponse<Page<BaseSalesDTO>> response1 = this.baseSalesApiService.pageBaseSales(dto);
if(response1.isSuccess() && response1.getResult() != null && CollectionUtils.isNotEmpty(response1.getResult().getResult())){
......@@ -93,21 +101,30 @@ public class BaseSalesController {
return RestResponse.success(vo);
}
public Page<BaseSalesDTO> parseData(Page<BaseSalesDTO> page , Integer channel, Integer enterpriseId, Integer level){
public Page<BaseSalesDTO> parseData(Page<BaseSalesDTO> page , Integer channel, Integer enterpriseId, Integer level, Integer maxLevel){
if(page != null && CollectionUtils.isNotEmpty(page.getResult())){
if(channel == null){ //全渠道
page.getResult().stream().forEach(baseSalesDTO -> {
baseSalesDTO.setLevel(level - 1);
if(StoreChannelEnum.OFFLINE.getChannel() == Integer.valueOf(baseSalesDTO.getId())){
baseSalesDTO.setName(StoreChannelEnum.OFFLINE.getMessage());
baseSalesDTO.setChannel(StoreChannelEnum.OFFLINE.getChannel());
baseSalesDTO.setHasChildren(1);
}
if(StoreChannelEnum.GICMALL.getChannel() == Integer.valueOf(baseSalesDTO.getId())){
baseSalesDTO.setName(StoreChannelEnum.GICMALL.getMessage());
baseSalesDTO.setChannel(StoreChannelEnum.GICMALL.getChannel());
baseSalesDTO.setHasChildren(1);
}
if(StoreChannelEnum.WMMALL.getChannel() == Integer.valueOf(baseSalesDTO.getId())){
baseSalesDTO.setName(StoreChannelEnum.WMMALL.getMessage());
baseSalesDTO.setChannel(StoreChannelEnum.WMMALL.getChannel());
baseSalesDTO.setHasChildren(1);
}
if(StoreChannelEnum.TIANMAO.getChannel() == Integer.valueOf(baseSalesDTO.getId())){
baseSalesDTO.setName(StoreChannelEnum.TIANMAO.getMessage());
baseSalesDTO.setChannel(StoreChannelEnum.TIANMAO.getChannel());
baseSalesDTO.setHasChildren(1);
}
});
}
......@@ -115,9 +132,11 @@ public class BaseSalesController {
List<ShopDTO> result = shopApiService.getAllShopByEnterpriseIdAndName(enterpriseId, null, ShopTypeEnum.MALL_SHOP.getCode()).getResult();
if(CollectionUtils.isNotEmpty(result)){
page.getResult().stream().forEach(baseSalesDTO -> {
baseSalesDTO.setLevel(level - 1);
for(ShopDTO shopDTO : result){
if(baseSalesDTO.getId().equals(shopDTO.getId())){
baseSalesDTO.setName(shopDTO.getName());
baseSalesDTO.setChannel(StoreChannelEnum.OFFLINE.getChannel());
}
}
});
......@@ -127,9 +146,11 @@ public class BaseSalesController {
List<WmStoreDTO> result1 = wmStoreApiService.listWmStore(enterpriseId, null).getResult();
if(CollectionUtils.isNotEmpty(result1)){
page.getResult().stream().forEach(baseSalesDTO -> {
baseSalesDTO.setLevel(level - 1);
for(WmStoreDTO dto : result1){
if(baseSalesDTO.getId().equals(dto.getWmMallStoreId()+"")){
baseSalesDTO.setName(dto.getWmMainAccount());
baseSalesDTO.setChannel(StoreChannelEnum.OFFLINE.getChannel());
}
}
});
......@@ -138,6 +159,8 @@ public class BaseSalesController {
if(channel == StoreChannelEnum.OFFLINE.getChannel()){
page.getResult().stream().forEach(baseSalesDTO -> {
baseSalesDTO.setLevel(level);
baseSalesDTO.setChannel(StoreChannelEnum.OFFLINE.getChannel());
baseSalesDTO.setHasChildren(level < maxLevel ? 1 : 0);
});
}
}
......
......@@ -15,6 +15,7 @@ import com.gic.cloud.web.auth.StoreAuth;
import com.gic.cloud.web.constant.StoreChannelEnum;
import com.gic.cloud.web.qo.StoreSearchQo;
import com.gic.cloud.web.vo.LevelVo;
import com.gic.redis.data.util.RedisUtil;
import com.gic.store.dto.StoreDTO;
import com.gic.store.dto.StoreGroupDTO;
import com.gic.store.dto.StoreSearchDTO;
......@@ -32,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Component
......@@ -51,17 +53,19 @@ public class StoreSearchUtils {
private StoreGroupApiService storeGroupApiService;
public List<Integer> storeSearch(Integer userId, Integer enterpriseId, String searchJson){
String key = "1:" + enterpriseId + ":" + userId +":" + (StringUtils.isNotBlank(searchJson) ? searchJson.hashCode() : "searchJSON".hashCode());
StoreAuth storeAuth = this.dataAuthUtils.getStoreAuth(userId, enterpriseId);
if(!storeAuth.isHasAuth()){
ArrayList<Integer> list = new ArrayList<>();
list.add(0);
return list;
}
List<Integer> resultList = new ArrayList<>();
if(StringUtils.isNotBlank(searchJson)){
JSONObject json = JSON.parseObject(searchJson);
StoreSearchQo storeSearchQo = json.getObject(StoreChannelEnum.OFFLINE.getChannel().toString(), StoreSearchQo.class);
if(storeSearchQo.getAll() == 1){
return storeAuth.getStoreInfoIdList();
resultList = storeAuth.getStoreInfoIdList();
}else {
StoreSearchDTO storeSearchDTO = new StoreSearchDTO();
storeSearchDTO.setEnterpriseId(enterpriseId);
......@@ -91,30 +95,35 @@ public class StoreSearchUtils {
List<StoreDTO> storeDTOList = pageServiceResponse.getResult().getResult();
List<Integer> storeInfoIdList = storeDTOList.stream().map(storeDTO -> storeDTO.getStoreInfoId()).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(storeAuth.getStoreInfoIdList())){
return storeInfoIdList.stream().filter(s -> {
for(Integer storeInfoId : storeAuth.getStoreInfoIdList()){
if(s.intValue() == storeInfoId.intValue()){
resultList = storeInfoIdList.stream().filter(s -> {
for (Integer storeInfoId : storeAuth.getStoreInfoIdList()) {
if (s.intValue() == storeInfoId.intValue()) {
return true;
}
}
return false;
}).collect(Collectors.toList());
}else {
return storeInfoIdList;
}
}
}
}else {
resultList = storeAuth.getStoreInfoIdList();
}
if(CollectionUtils.isNotEmpty(resultList)){
RedisUtil.setCache(key, 1, 10l, TimeUnit.MINUTES);
}else {
resultList.add(0);
}
return storeAuth.getStoreInfoIdList();
return resultList;
}
public List<String> onLineStoreSearch(Integer userId, Integer enterpriseId, String searchJson){
OnLineAuth onlineStoreAuth = this.dataAuthUtils.getOnlineStore(userId, enterpriseId);
List<String> list = new ArrayList<>();
if(onlineStoreAuth.isHasAuth()){
this.getOnlineStoreIds(searchJson, onlineStoreAuth, list, StoreChannelEnum.GICMALL.getChannel());
this.getOnlineStoreIds(searchJson, onlineStoreAuth, list, StoreChannelEnum.WMMALL.getChannel());
this.getOnlineStoreIds(searchJson, onlineStoreAuth, list, StoreChannelEnum.TIANMAO.getChannel());
this.getOnlineStoreIds(searchJson, onlineStoreAuth, list, StoreChannelEnum.GICMALL.getChannel(), userId, enterpriseId);
this.getOnlineStoreIds(searchJson, onlineStoreAuth, list, StoreChannelEnum.WMMALL.getChannel(), userId, enterpriseId);
this.getOnlineStoreIds(searchJson, onlineStoreAuth, list, StoreChannelEnum.TIANMAO.getChannel(), userId, enterpriseId);
}else {
list.add("noauth");
}
......@@ -147,17 +156,47 @@ public class StoreSearchUtils {
}
});
int start = 0;
while (true){
if(levelMap.get(start) != null && levelMap.get(start).intValue() > 1){
vo.setLevel(start);
break;
if(!levelMap.isEmpty()){
while (true){
if(levelMap.get(start) != null && levelMap.get(start).intValue() > 1){
vo.setLevel(start);
break;
}
start++;
}
start++;
vo.setMaxLevel(levelMap.size() - 1);
}
vo.setMaxLevel(levelMap.size() - 1);
return vo;
}
public Integer getChannel(Integer userId, Integer enterpriseId, String searchJson){
String offlineKey = "1:" + enterpriseId + ":" + userId +":" + (StringUtils.isNotBlank(searchJson) ? searchJson.hashCode() : "searchJSON".hashCode());
String gicMallKey = "2:" + enterpriseId + ":" + userId +":" + (StringUtils.isNotBlank(searchJson) ? searchJson.hashCode() : "searchJSON".hashCode());
String wmKey = "3:" + enterpriseId + ":" + userId +":" + (StringUtils.isNotBlank(searchJson) ? searchJson.hashCode() : "searchJSON".hashCode());
String tmKey = "4:" + enterpriseId + ":" + userId +":" + (StringUtils.isNotBlank(searchJson) ? searchJson.hashCode() : "searchJSON".hashCode());
int offline = RedisUtil.getCache(offlineKey) == null ? 0 : 1;
int gicMall = RedisUtil.getCache(gicMallKey) == null ? 0 : 1;
int wm = RedisUtil.getCache(wmKey) == null ? 0 : 1;
int tm = RedisUtil.getCache(tmKey) == null ? 0 : 1;
if((offline + gicMall + wm + tm) > 1){ //多渠道
return null;
}else if((offline + gicMall + wm + tm) == 1){
if(offline == 1){
return offline;
}
if(gicMall == 1){
return gicMall;
}
if(wm == 1){
return wm;
}
if(tm == 1){
return tm;
}
}
return null;
}
public List<Integer> getChildrenStoreGroupIdList(Integer storeGroupId){
if(storeGroupId != null){
List<StoreGroupDTO> result = this.storeGroupApiService.listStoreGroupAndChildren(storeGroupId).getResult();
......@@ -168,24 +207,30 @@ public class StoreSearchUtils {
return new ArrayList<>();
}
private void getOnlineStoreIds(String searchJson, OnLineAuth onlineStoreAuth, List<String> list, Integer channel){
private void getOnlineStoreIds(String searchJson, OnLineAuth onlineStoreAuth, List<String> list, Integer channel, Integer userId, Integer enterpriseId){
String key = channel + ":" + enterpriseId +":" + userId +":" + (StringUtils.isNotBlank(searchJson) ? searchJson.hashCode() : "searchJSON".hashCode());
if(StringUtils.isNotBlank(searchJson)){
StoreSearchQo searchQo = JSON.parseObject(searchJson).getObject(channel.toString(), StoreSearchQo.class);
log.info("getOnlineStoreIds:{},{}", searchJson, JSON.toJSONString(searchQo));
if(searchQo != null){
if(searchQo.getAll() == 1){
onlineStoreAuth.getList().stream().filter(s -> {
if(s.getChannel() == channel){
list.addAll(s.getStoreIdList());
}
return false;
});
}else {
if(searchQo.getAll() != 1){
if(StringUtils.isNotBlank(searchQo.getStoreGroupIds())){
RedisUtil.setCache(key, 1, 10l, TimeUnit.MINUTES);
list.addAll(Arrays.asList(searchQo.getStoreGroupIds().split(",")));
}
}
}
} else {
onlineStoreAuth.getList().stream().forEach(s -> {
System.out.println(JSON.toJSONString(s));
if(s.getChannel().intValue() == channel.intValue()){
if(CollectionUtils.isNotEmpty(s.getStoreIdList())){
RedisUtil.setCache(key, 1, 10l, TimeUnit.MINUTES);
list.addAll(s.getStoreIdList());
}
}
});
}
}
}
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