从list中提取某字段生成数组
List<String> ids = productForm.stream().filter(x -> x.getProvinceCode() != null&&x.getProvinceCode() != "").map(u -> u.getProvinceCode()).collect(Collectors.toList());
过滤主图 、企业名称 为空的 VIP标王
List<CollectDictDataConfig> collectDictDataConfigList = collectDictDataConfigs.stream() .filter(x -> isNotEmpty(x.getEnterpriseName()) && isNotEmpty(x.getImgUrl())) .collect(Collectors.toList());
/** 订单创建时间(开始) */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date insertTimeBegin; /** 订单创建时间(结束) */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date insertTimeEnd;
热销产品更新
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateProductIsHotSale(ProductForm productForm) {
List<EnterpriseProduct> productList = productForm.getEnterpriseProductList();
//提取产品id
List<String> ids = productList.stream().filter(x -> isNotEmpty(x.getProvinceCode())).map(u -> u.getProvinceCode()).collect(Collectors.toList());
List<String> list = new ArrayList<>();
if(isNotEmpty(ids)){
//判断产品id是否都存在
if(ids.size() == enterpriseProductMapper.CountProductByIds(ids) ){
//初始化热销产品排序
enterpriseProductMapper.updateProductIsHotSaleDefault();
//保存热销产品排序
enterpriseProductMapper.updateProductIsHotSale(productList);
}else{
//判断产品是否重复
list=ids.stream().collect(Collectors.toMap(e -> e,e -> 1, (a,b) -> a+b))
.entrySet().stream()
.filter(enttry -> enttry.getValue() > 1)
.map(entry ->entry.getKey())
.collect(Collectors.toList());
if(list.size() > 0){
String str = String.join(",",list);
throw new BusinessException("产品 "+str+" 重复,请验证产品id");
}
//判断产品是否存在
for (String id : ids) {
if(enterpriseProductMapper.CountProductById(id) == 0){
list.add(id);
}
}
if(list.size() > 0){
String str = String.join(",",list);
throw new BusinessException("产品 "+str+" 不存在,请验证产品id");
}
}
}else{
// 产品id的个数为0 初始化热销产品排序
enterpriseProductMapper.updateProductIsHotSaleDefault();
}
return true;
}
//修改企业banner //会员等级发生改变 if (enterpriseInfoProvider.getMemberLevel() != basicInfo.getMemberLevel()){ List<SysDictData> sysDictData = dictDataMapper.selectDictDataByType("wgw_enterprise_banner"); Optional<SysDictData> any = sysDictData.stream().filter(e -> e.getRemark().equals(basicInfo.getBannerUrl())).findAny(); //any为null 是自己上传的banner if (any.isPresent()){ //找到会员等级对应的bannerUrl SysDictData sysDictData1 = sysDictData.stream().filter(u -> u.getDictValue().equals(basicInfo.getMemberLevel().toString())).collect(Collectors.toList()).get(0); basicInfo.setBannerUrl(sysDictData1.getRemark()); } }