|
@@ -542,8 +542,9 @@ public class PageServiceImpl implements PageService {
|
|
|
public ResponseJson<List<ProductListVo>> getProductDetailRecommends(Integer productId, Integer recommendType, Integer userId) {
|
|
|
// 根据用户Id查询用户身份
|
|
|
Integer identity = 0;
|
|
|
- if (null != userId) {
|
|
|
+ if (null != userId && userId > 0) {
|
|
|
identity = priceMapper.getIdentityByUserId(userId);
|
|
|
+ if (null == identity){identity = 0;}
|
|
|
}
|
|
|
List<ProductListVo> list = null;
|
|
|
//相关推荐类型 0自动选择; 1手动推荐
|
|
@@ -552,21 +553,19 @@ public class PageServiceImpl implements PageService {
|
|
|
} else {
|
|
|
list = pageMapper.getAutoProductRecommends(productId);
|
|
|
}
|
|
|
- //使用迭代器判断删除列表中的不满足条件的商品
|
|
|
- Iterator<ProductListVo> iterator=list.iterator();
|
|
|
- while (iterator.hasNext()){
|
|
|
- //多线程情况下加锁
|
|
|
- synchronized (list){
|
|
|
- ProductListVo product = iterator.next();
|
|
|
- // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
|
|
|
- // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
|
|
|
- boolean passFlag =identity ==1 || identity == 2 || product.getVisibility()==3 || (identity == 4 && product.getVisibility()==2);
|
|
|
- if(!passFlag){
|
|
|
- iterator.remove();
|
|
|
- } else {
|
|
|
+ if (null != list && list.size()>0) {
|
|
|
+ // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
|
|
|
+ // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
|
|
|
+ // boolean passFlag = identity ==1 || identity == 2 || product.getVisibility()==3 || (identity == 4 && product.getVisibility()==2);
|
|
|
+ try {
|
|
|
+ Integer finalIdentity = identity;
|
|
|
+ list.removeIf(product -> (null == product || null == product.getVisibility() || !(finalIdentity == 1 || finalIdentity == 2 || product.getVisibility()==3 || (finalIdentity == 4 && product.getVisibility()==2))));
|
|
|
+ list.forEach(product -> {
|
|
|
// 设置 图片路径
|
|
|
product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
|
|
|
- }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("相关推荐", e);
|
|
|
}
|
|
|
}
|
|
|
return ResponseJson.success(list);
|