Commit 5f528090 by weijiguang

..

parent 22665e2b
...@@ -7,6 +7,7 @@ import com.soss.common.core.page.TableDataInfo; ...@@ -7,6 +7,7 @@ import com.soss.common.core.page.TableDataInfo;
import com.soss.common.exception.ServiceException; import com.soss.common.exception.ServiceException;
import com.soss.system.domain.SysBanner; import com.soss.system.domain.SysBanner;
import com.soss.system.domain.po.BannerPo; import com.soss.system.domain.po.BannerPo;
import com.soss.system.domain.vo.BannerVo;
import com.soss.system.service.ISysBannerService; import com.soss.system.service.ISysBannerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -29,7 +30,9 @@ public class BannerController extends BaseController { ...@@ -29,7 +30,9 @@ public class BannerController extends BaseController {
public TableDataInfo list(@RequestBody SysBanner banner) { public TableDataInfo list(@RequestBody SysBanner banner) {
startPage(); startPage();
List<SysBanner> list = bannerService.selectBanner(banner); List<SysBanner> list = bannerService.selectBanner(banner);
return getDataTable(list); List<BannerVo> bannerVos = bannerService.copyBanner(list);
bannerService.translateArea(bannerVos);
return getDataTable(bannerVos);
} }
/** /**
......
...@@ -31,7 +31,7 @@ public class SysBanner extends BaseEntity { ...@@ -31,7 +31,7 @@ public class SysBanner extends BaseEntity {
*/ */
private Integer type; private Integer type;
/** /**
* 目标:1-小程序首页,2-小程序我的 * 目标:1-小程序首页,2-小程序我的,0-其它
*/ */
private Integer target; private Integer target;
/** /**
......
...@@ -22,7 +22,7 @@ public class BannerPo { ...@@ -22,7 +22,7 @@ public class BannerPo {
*/ */
private Integer type; private Integer type;
/** /**
* 目标:1-小程序首页,2-小程序我的 * 目标:1-小程序首页,2-小程序我的,0-其它
*/ */
private Integer target; private Integer target;
/** /**
......
package com.soss.system.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@ApiModel("轮播图请求类")
public class BannerVo {
/** 主键 */
private Long id;
/**
* 图片url
*/
private String image;
/**
* 页面url
*/
private String page;
/**
* 类型:1-小程序,2-KDS,3-点单屏
*/
private Integer type;
/**
* 目标:1-小程序首页,2-小程序我的,0-其它
*/
private Integer target;
/**
* 排序
*/
private Integer sort;
@ApiModelProperty("可用省份列表,全国通用传 [0]")
private String provinceStr;
private String[] province;
@ApiModelProperty("可用城市列表")
private String cityStr;
private String[] city;
@ApiModelProperty("可用区域列表")
private String areaStr;
private String[] area;
@ApiModelProperty("可用店铺ID列表")
private String shopIdsStr;
private Long[] shopIds;
private String areaLimitDesc;
/**
* 状态:0-在线,1-下线
*/
private Integer state;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createdAt;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updatedAt;
}
package com.soss.system.domain.vo.orderTaking; package com.soss.system.domain.vo.orderTaking;
import com.alibaba.fastjson.JSONArray;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
public class ImagesVo { public class ImagesVo {
private JSONArray left; private List<String> left;
// private JSONObject right; // private JSONObject right;
} }
...@@ -2,6 +2,7 @@ package com.soss.system.service; ...@@ -2,6 +2,7 @@ package com.soss.system.service;
import com.soss.system.domain.SysBanner; import com.soss.system.domain.SysBanner;
import com.soss.system.domain.po.BannerPo; import com.soss.system.domain.po.BannerPo;
import com.soss.system.domain.vo.BannerVo;
import java.util.List; import java.util.List;
...@@ -22,5 +23,9 @@ public interface ISysBannerService { ...@@ -22,5 +23,9 @@ public interface ISysBannerService {
Boolean delete(Long bannerId); Boolean delete(Long bannerId);
List<BannerVo> copyBanner(List<SysBanner> banners);
void translateArea(List<BannerVo> bannerVos);
List<SysBanner> getBannersByShopId(Long shopId, Integer type, Integer target); List<SysBanner> getBannersByShopId(Long shopId, Integer type, Integer target);
List<String> getKDSBannerByShopId(Long shopId);
} }
...@@ -34,6 +34,8 @@ public class OrderTakingServiceImpl { ...@@ -34,6 +34,8 @@ public class OrderTakingServiceImpl {
private GoodsCategoryMapper goodsCategoryMapper; private GoodsCategoryMapper goodsCategoryMapper;
@Autowired @Autowired
private ShopMapper shopMapper; private ShopMapper shopMapper;
@Autowired
private SysBannerServiceImpl bannerService;
/** /**
...@@ -65,15 +67,16 @@ public class OrderTakingServiceImpl { ...@@ -65,15 +67,16 @@ public class OrderTakingServiceImpl {
} }
orderTakingVo.setShopState(shop.getState()); orderTakingVo.setShopState(shop.getState());
ImagesVo imagesVo = new ImagesVo(); ImagesVo imagesVo = new ImagesVo();
imagesVo.setLeft(bannerService.getKDSBannerByShopId(shopId));
orderTakingVo.setImages(imagesVo); orderTakingVo.setImages(imagesVo);
String menuLeft = sysConfigService.selectConfigByKey("menu.left"); // String menuLeft = sysConfigService.selectConfigByKey("menu.left");
if (StringUtils.isNotEmpty(menuLeft)) { // if (StringUtils.isNotEmpty(menuLeft)) {
if (menuLeft.startsWith("[")) { // if (menuLeft.startsWith("[")) {
imagesVo.setLeft(JSONArray.parseArray(menuLeft)); // imagesVo.setLeft(JSONArray.parseArray(menuLeft));
} else { // } else {
imagesVo.setLeft(JSONArray.parseArray(JSONArray.toJSONString(Collections.singletonList(menuLeft)))); // imagesVo.setLeft(JSONArray.parseArray(JSONArray.toJSONString(Collections.singletonList(menuLeft))));
} // }
} // }
// imagesVo.setRight(JSONObject.parseObject(sysConfigService.selectConfigByKey("menu.right"))); // imagesVo.setRight(JSONObject.parseObject(sysConfigService.selectConfigByKey("menu.right")));
orderTakingVo.setCountOfOrder(sysConfigService.selectConfigByKey("goods.limit")); orderTakingVo.setCountOfOrder(sysConfigService.selectConfigByKey("goods.limit"));
orderTakingVo.setTips(sysConfigService.selectConfigByKey("tips.address")); orderTakingVo.setTips(sysConfigService.selectConfigByKey("tips.address"));
......
...@@ -5,17 +5,19 @@ import com.soss.common.utils.StringUtils; ...@@ -5,17 +5,19 @@ import com.soss.common.utils.StringUtils;
import com.soss.system.domain.Shop; import com.soss.system.domain.Shop;
import com.soss.system.domain.SysBanner; import com.soss.system.domain.SysBanner;
import com.soss.system.domain.po.BannerPo; import com.soss.system.domain.po.BannerPo;
import com.soss.system.domain.vo.BannerVo;
import com.soss.system.mapper.ShopMapper;
import com.soss.system.mapper.SysBannerMapper; import com.soss.system.mapper.SysBannerMapper;
import com.soss.system.service.ISysBannerService; import com.soss.system.service.ISysBannerService;
import com.soss.system.utils.AreaUtil;
import com.soss.system.utils.ArrayUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays; import java.util.function.Function;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -31,6 +33,10 @@ public class SysBannerServiceImpl implements ISysBannerService { ...@@ -31,6 +33,10 @@ public class SysBannerServiceImpl implements ISysBannerService {
private SysBannerMapper sysBannerMapper; private SysBannerMapper sysBannerMapper;
@Autowired @Autowired
private ShopServiceImpl shopService; private ShopServiceImpl shopService;
@Autowired
private ShopMapper shopMapper;
@Autowired
private AreaUtil areaUtil;
@Override @Override
public List<SysBanner> selectBanner(SysBanner banner) { public List<SysBanner> selectBanner(SysBanner banner) {
...@@ -49,8 +55,8 @@ public class SysBannerServiceImpl implements ISysBannerService { ...@@ -49,8 +55,8 @@ public class SysBannerServiceImpl implements ISysBannerService {
if (banner.getType() == null || banner.getType() < 1 || banner.getType() > 3) { if (banner.getType() == null || banner.getType() < 1 || banner.getType() > 3) {
throw new ServiceException("类型不正确,1-小程序,2-KDS,3-点单屏"); throw new ServiceException("类型不正确,1-小程序,2-KDS,3-点单屏");
} }
if (banner.getTarget() == null || banner.getTarget() < 1 || banner.getTarget() > 2) { if (banner.getTarget() == null || banner.getTarget() < 0 || banner.getTarget() > 2) {
throw new ServiceException("轮播位置不正确,1-小程序首页,2-小程序我的"); throw new ServiceException("轮播位置不正确,1-小程序首页,2-小程序我的,0-其它");
} }
if (banner.getSort() == null) { if (banner.getSort() == null) {
throw new ServiceException("轮播顺序不能为空"); throw new ServiceException("轮播顺序不能为空");
...@@ -81,8 +87,8 @@ public class SysBannerServiceImpl implements ISysBannerService { ...@@ -81,8 +87,8 @@ public class SysBannerServiceImpl implements ISysBannerService {
if (banner.getType() == null || banner.getType() < 1 || banner.getType() > 3) { if (banner.getType() == null || banner.getType() < 1 || banner.getType() > 3) {
throw new ServiceException("类型不正确,1-小程序,2-KDS,3-点单屏"); throw new ServiceException("类型不正确,1-小程序,2-KDS,3-点单屏");
} }
if (banner.getTarget() == null || banner.getTarget() < 1 || banner.getTarget() > 2) { if (banner.getTarget() == null || banner.getTarget() < 0 || banner.getTarget() > 2) {
throw new ServiceException("轮播位置不正确,1-小程序首页,2-小程序我的"); throw new ServiceException("轮播位置不正确,1-小程序首页,2-小程序我的,0-其它");
} }
if (banner.getSort() == null) { if (banner.getSort() == null) {
throw new ServiceException("轮播顺序不能为空"); throw new ServiceException("轮播顺序不能为空");
...@@ -117,10 +123,50 @@ public class SysBannerServiceImpl implements ISysBannerService { ...@@ -117,10 +123,50 @@ public class SysBannerServiceImpl implements ISysBannerService {
if (bannerPo.getShopIds() != null && bannerPo.getShopIds().length > 0) { if (bannerPo.getShopIds() != null && bannerPo.getShopIds().length > 0) {
banner.setShopIds(Arrays.asList(bannerPo.getShopIds()).stream().map(x -> String.valueOf(x)).collect(Collectors.joining(","))); banner.setShopIds(Arrays.asList(bannerPo.getShopIds()).stream().map(x -> String.valueOf(x)).collect(Collectors.joining(",")));
} }
return banner; return banner;
} }
public List<BannerVo> copyBanner(List<SysBanner> banners) {
List<BannerVo> bannerVos = new ArrayList<>();
if (CollectionUtils.isEmpty(banners)) {
return bannerVos;
}
banners.forEach(banner -> bannerVos.add(copyBanner(banner)));
return bannerVos;
}
private BannerVo copyBanner(SysBanner banner) {
BannerVo bannerVo = new BannerVo();
bannerVo.setId(banner.getId());
bannerVo.setImage(banner.getImage());
bannerVo.setPage(banner.getPage());
bannerVo.setType(banner.getType());
bannerVo.setTarget(banner.getTarget());
bannerVo.setSort(banner.getSort());
bannerVo.setProvinceStr(banner.getProvince());
bannerVo.setCityStr(banner.getCity());
bannerVo.setAreaStr(banner.getArea());
bannerVo.setShopIdsStr(banner.getShopIds());
if (!StringUtils.isEmpty(banner.getProvince())) {
bannerVo.setProvince(banner.getProvince().split(","));
}
if (!StringUtils.isEmpty(banner.getCity())) {
bannerVo.setCity(banner.getCity().split(","));
}
if (!StringUtils.isEmpty(banner.getArea())) {
bannerVo.setArea(banner.getArea().split(","));
}
if (!StringUtils.isEmpty(banner.getShopIds())) {
String[] shopIds = banner.getShopIds().split(",");
Long[] ids = new Long[shopIds.length];
for (int i = 0; i < shopIds.length; i++) {
ids[i] = Long.parseLong(shopIds[i]);
}
bannerVo.setShopIds(ids);
}
return bannerVo;
}
@Override @Override
public Boolean updateState(Long bannerId, Integer state) { public Boolean updateState(Long bannerId, Integer state) {
SysBanner banner = new SysBanner(); SysBanner banner = new SysBanner();
...@@ -194,4 +240,117 @@ public class SysBannerServiceImpl implements ISysBannerService { ...@@ -194,4 +240,117 @@ public class SysBannerServiceImpl implements ISysBannerService {
}); });
return list; return list;
} }
@Override
public List<String> getKDSBannerByShopId(Long shopId) {
List<SysBanner> banners = sysBannerMapper.selectBanners(2, 0);
if (CollectionUtils.isEmpty(banners)) {
log.info("banner list is empty");
return null;
}
Shop shop = shopService.selectShopById(shopId);
if (shop == null) {
log.info("shop is null");
return null;
}
List<String> list = new ArrayList<>();
banners.forEach(banner -> {
if (!StringUtils.isEmpty(banner.getProvince())) {
Arrays.stream(banner.getProvince().split(",")).forEach(p -> {
if (p.equals(shop.getProvince())) {
list.add(banner.getImage());
return;
}
});
}
if (!StringUtils.isEmpty(banner.getCity())) {
Arrays.stream(banner.getCity().split(",")).forEach(p -> {
if (p.equals(shop.getCity())) {
list.add(banner.getImage());
return;
}
});
}
if (!StringUtils.isEmpty(banner.getArea())) {
Arrays.stream(banner.getArea().split(",")).forEach(p -> {
if (p.equals(shop.getZone())) {
list.add(banner.getImage());
return;
}
});
}
if (!StringUtils.isEmpty(banner.getShopIds())) {
Arrays.stream(banner.getShopIds().split(",")).forEach(p -> {
if (p.equals(String.valueOf(shop.getId()))) {
list.add(banner.getImage());
return;
}
});
}
});
return list;
}
public void translateArea(List<BannerVo> bannerVos) {
if(CollectionUtils.isEmpty(bannerVos)){
return;
}
List<String> province = new ArrayList<>(16);
List<String> city = new ArrayList<>(16);
List<String> area = new ArrayList<>(16);
List<Long> shopIds = new ArrayList<>(16);
for (BannerVo bannerVo : bannerVos) {
if (!ArrayUtil.isAllAvailable(bannerVo.getProvince())) {
ArrayUtil.listAddArray(province, bannerVo.getProvince());
}
ArrayUtil.listAddArray(city, bannerVo.getCity());
ArrayUtil.listAddArray(area, bannerVo.getArea());
ArrayUtil.listAddArray(shopIds, bannerVo.getShopIds());
}
Map<Long, Shop> shopMapInit;
if (!CollectionUtils.isEmpty(shopIds)) {
List<Shop> shops = shopMapper.selectShopByIds(shopIds);
shopMapInit = shops.stream().collect(Collectors.toMap(Shop::getId, Function.identity()));
} else {
shopMapInit = new HashMap<>(0);
}
Map<Long, Shop> shopMap = shopMapInit;
for (BannerVo bannerVo : bannerVos) {
if (ArrayUtil.isAllAvailable(bannerVo.getProvince())) {
bannerVo.setAreaLimitDesc("全国通用");
continue;
} else if (ArrayUtil.hasContents(bannerVo.getProvince())) {
String provDesc = Arrays.stream(bannerVo.getProvince()).map(areaUtil::getProvNameByCode).collect(Collectors.joining(","));
bannerVo.setAreaLimitDesc(provDesc);
continue;
}
if (ArrayUtil.hasContents(bannerVo.getCity())) {
String cityDesc = Arrays.stream(bannerVo.getCity()).map(areaUtil::getCityOrAreaNameByCode).collect(Collectors.joining(","));
bannerVo.setAreaLimitDesc(cityDesc);
continue;
}
if (ArrayUtil.hasContents(bannerVo.getArea())) {
String areaDesc = Arrays.stream(bannerVo.getArea()).map(areaUtil::getCityOrAreaNameByCode).collect(Collectors.joining(","));
bannerVo.setAreaLimitDesc(areaDesc);
continue;
}
if (!ArrayUtil.hasContents(bannerVo.getShopIds())) {
continue;
}
String shopDesc = Arrays.stream(bannerVo.getShopIds()).map(shopId -> {
Shop shop = shopMap.get(shopId);
if (shop == null) {
return null;
}
return areaUtil.getCityOrAreaNameByCode(shop.getZone()) + shop.getName();
}).filter(Objects::nonNull).collect(Collectors.joining(","));
bannerVo.setAreaLimitDesc(shopDesc);
}
}
} }
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