|
|
|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.google.gson.JsonArray; |
|
|
|
import com.iformall.common.*; |
|
|
|
import com.iformall.domain.dto.WxSharingOrderDto; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
@@ -18,6 +19,7 @@ import com.iformall.domain.po.msg.FmInsideCouponVerifyMsg; |
|
|
|
import com.iformall.domain.po.msg.MpAppMsg; |
|
|
|
import com.iformall.domain.vo.*; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.BizException; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
|
@@ -33,7 +35,9 @@ import com.iformall.service.pay.service.share.PayShareAdapterService; |
|
|
|
import com.iformall.utils.Constant; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import com.iformall.utils.RedisLock; |
|
|
|
import com.iformall.utils.service.MallUtils; |
|
|
|
import org.apache.commons.beanutils.BeanUtils; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
@@ -203,6 +207,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
@Autowired |
|
|
|
WxMallMapper wxMallMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponSendMapper wxCouponSendMapper; |
|
|
|
|
|
|
|
private final SimpleDateFormat mydateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
@Override |
|
|
|
@@ -959,10 +966,6 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
} |
|
|
|
|
|
|
|
private List<WxCouponOrderBVo> handleQueryResult(boolean cUserEntry,List<WxCouponOrder> list,TenantEntity couponOrderTenantEntity) { |
|
|
|
// 获取该租户下所有的商户 |
|
|
|
List<WxMerchant> merchants = wxMerchantMapper.selectList(new LambdaQueryWrapper<WxMerchant>().select(WxMerchant::getId, WxMerchant::getName).eq(WxMerchant::getTenantId, couponOrderTenantEntity.getFinalTenantId())); |
|
|
|
Map<Long, String> merchantMap = merchants.stream().collect(Collectors.toMap(WxMerchant::getId, WxMerchant::getName)); |
|
|
|
|
|
|
|
if (null != list && list.size() > 0) { |
|
|
|
|
|
|
|
//循环list,获取 cUserId |
|
|
|
@@ -971,6 +974,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
Map<String,List<Long>> mallMerchantIdList = new HashMap<String,List<Long>>(); |
|
|
|
List<Long> couponIdList = new ArrayList<Long>(); |
|
|
|
|
|
|
|
// mallTenantIdList:当前广场的兄弟广场以及当前广场的子广场 |
|
|
|
List<String> mallTenantIdList = new ArrayList<String>(); |
|
|
|
mallTenantIdList.add(couponOrderTenantEntity.getTenantId()); |
|
|
|
//查询子广场 |
|
|
|
@@ -1059,12 +1063,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
|
|
|
|
for (int i = 0 ; i < mallTenantIdList.size(); i++) { |
|
|
|
String mallTenantId = mallTenantIdList.get(i); |
|
|
|
List<Long> merchantIds = mallMerchantIdList.get(mallTenantId); |
|
|
|
List<Long> merchantIds = Optional.ofNullable(mallMerchantIdList.get(mallTenantId)).orElse(new ArrayList<>()); |
|
|
|
List<WxMerchantProductVo> merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(mallTenantId, couponIdList); |
|
|
|
if (null != merchantProductVos) { |
|
|
|
if (null == merchantIds) { |
|
|
|
merchantIds = new ArrayList<Long>(); |
|
|
|
} |
|
|
|
for (int j = 0 ; j < merchantProductVos.size(); j ++) { |
|
|
|
WxMerchantProductVo mp = merchantProductVos.get(j); |
|
|
|
if (mp.getMc() > 1) { |
|
|
|
@@ -1076,8 +1077,24 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
mallMerchantIdList.put(mallTenantId, merchantIds); |
|
|
|
} |
|
|
|
// 可从wx_coupon_send表中取发劵商户 |
|
|
|
List<WxCouponSend> couponSends = wxCouponSendMapper.selectList(new LambdaQueryWrapper<WxCouponSend>() |
|
|
|
.select(WxCouponSend::getConditions) |
|
|
|
.eq(WxCouponSend::getTenantId, mallTenantId) |
|
|
|
.in(!CollectionUtils.isEmpty(couponIdList), WxCouponSend::getCouponId, couponIdList)); |
|
|
|
List<Long> sendMerchantIds = couponSends.stream().filter(x -> StringUtils.isNotBlank(x.getConditions())).map(x -> { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
try { |
|
|
|
jsonObject = JSONObject.parseObject(x.getConditions()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
} |
|
|
|
return jsonObject.getLong("id"); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
Set<Long> merchantIdsSet = new HashSet<>(merchantIds); |
|
|
|
merchantIdsSet.addAll(sendMerchantIds); |
|
|
|
mallMerchantIdList.put(mallTenantId, new ArrayList<>(merchantIdsSet)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@@ -1130,8 +1147,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
co.setUpdateDate(null); |
|
|
|
} |
|
|
|
if (null != co.getSendMerchantId()) { |
|
|
|
// co.setSendMerchantName(merchantNameMap.get(co.getSendMerchantId())); |
|
|
|
co.setSendMerchantName(merchantMap.get(co.getSendMerchantId())); |
|
|
|
co.setSendMerchantName(merchantNameMap.get(co.getSendMerchantId())); |
|
|
|
} |
|
|
|
WxCoupon coupon = couponMap.get(co.getCouponId()); |
|
|
|
if (null != coupon) { |
|
|
|
@@ -1196,9 +1212,126 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
return new ArrayList<WxCouponOrderBVo>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Long> getMerchantIdsQueryParam(WxCouponOrderBVo wxCouponOrder) { |
|
|
|
|
|
|
|
private List<WxCouponOrderBVo> buildQueryResult(boolean cUserEntry,List<WxCouponOrder> list,TenantEntity couponOrderTenantEntity) { |
|
|
|
// 必有字段:couponId,cuserId 非必有字段:buserId,bmerchantId |
|
|
|
// 根据集合查询c端用户 |
|
|
|
List<Long> cUserIds = list.stream().map(WxCouponOrder::getCUserId).distinct().collect(Collectors.toList()); |
|
|
|
List<WxCUserBasicInfo> cUsers = wxCUserBasicInfoMapper.selectList(new LambdaQueryWrapper<WxCUserBasicInfo>() |
|
|
|
.eq(WxCUserBasicInfo::getFinalTenantId, couponOrderTenantEntity.getFinalTenantId()) |
|
|
|
.in(!CollectionUtils.isEmpty(cUserIds), WxCUserBasicInfo::getId, cUserIds)); |
|
|
|
Map<Long, WxCUserBasicInfo> cUserMap = cUsers.stream().collect(Collectors.toMap(WxCUserBasicInfo::getId, Function.identity())); |
|
|
|
// 根据集合查询优惠券 |
|
|
|
List<Long> couponIds = list.stream().map(WxCouponOrder::getCouponId).distinct().collect(Collectors.toList()); |
|
|
|
List<WxCoupon> wxCoupons = wxCouponMapper.selectList(new LambdaQueryWrapper<WxCoupon>() |
|
|
|
.eq(WxCoupon::getTenantId, couponOrderTenantEntity.getTenantId()) |
|
|
|
.in(!CollectionUtils.isEmpty(couponIds), WxCoupon::getId, couponIds)); |
|
|
|
Map<Long, WxCoupon> couponMap = wxCoupons.stream().collect(Collectors.toMap(WxCoupon::getId, Function.identity())); |
|
|
|
// 此处由于集团版劵的所属商户可能是兄弟广场或是子广场,可用以下方式得到商户 |
|
|
|
// 根据卷商户映射,得到集合中每个租户的商户id(劵商户映射不包括商户发劵) 可从wx_coupon_merchant表中取商户 |
|
|
|
List<WxMall> malls = wxMallMapper.selectList(new LambdaQueryWrapper<WxMall>() |
|
|
|
.select(WxMall::getTenantId, WxMall::getParentTenantId)); |
|
|
|
List<String> tenantIds = MallUtils.findTenantIds(couponOrderTenantEntity, malls); |
|
|
|
List<WxCouponMerchant> couponMerchants = wxCouponMerchantMapper.selectList(new LambdaQueryWrapper<WxCouponMerchant>() |
|
|
|
.in(!CollectionUtils.isEmpty(tenantIds), WxCouponMerchant::getTenantId, tenantIds) |
|
|
|
.in(!CollectionUtils.isEmpty(couponIds), WxCouponMerchant::getProductId, couponIds)); |
|
|
|
Map<String, List<WxCouponMerchant>> tenantMerchantMap = couponMerchants.stream().collect(Collectors.groupingBy(WxCouponMerchant::getTenantId)); |
|
|
|
Map<Long, List<WxCouponMerchant>> couponMerchantMap = couponMerchants.stream().collect(Collectors.groupingBy(WxCouponMerchant::getProductId)); |
|
|
|
|
|
|
|
Map<Long, String> merchantNameMap = new HashMap<>(); |
|
|
|
Map<Long, WxMerchantBUser> bUserMap = new HashMap<>(); |
|
|
|
// 根据集合统计b端用户id |
|
|
|
List<Long> bUserIds = list.stream().filter(x -> x.getBUserId() != null).map(WxCouponOrder::getBUserId).distinct().collect(Collectors.toList()); |
|
|
|
for (Map.Entry<String, List<WxCouponMerchant>> entry : tenantMerchantMap.entrySet()) { |
|
|
|
String tenantId = entry.getKey(); |
|
|
|
Set<Long> merchantIds = entry.getValue().stream().map(WxCouponMerchant::getMerchantId).collect(Collectors.toSet()); |
|
|
|
List<Long> productIds = entry.getValue().stream().map(WxCouponMerchant::getProductId).distinct().collect(Collectors.toList()); |
|
|
|
|
|
|
|
// 可从wx_coupon_send表中取发劵商户 |
|
|
|
List<WxCouponSend> couponSends = wxCouponSendMapper.selectList(new LambdaQueryWrapper<WxCouponSend>() |
|
|
|
.select(WxCouponSend::getConditions) |
|
|
|
.eq(WxCouponSend::getTenantId, tenantId) |
|
|
|
.in(!CollectionUtils.isEmpty(productIds), WxCouponSend::getCouponId, productIds)); |
|
|
|
Set<Long> sendMerchantIds = couponSends.stream().filter(x -> StringUtils.isNotBlank(x.getConditions())).map(x -> { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
try { |
|
|
|
jsonObject = JSONObject.parseObject(x.getConditions()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
} |
|
|
|
return jsonObject.getLong("id"); |
|
|
|
}).collect(Collectors.toSet()); |
|
|
|
merchantIds.addAll(sendMerchantIds); |
|
|
|
|
|
|
|
// 商户数据 |
|
|
|
List<WxMerchant> merchants = wxMerchantMapper.selectList(new LambdaQueryWrapper<WxMerchant>() |
|
|
|
.select(WxMerchant::getId, WxMerchant::getName) |
|
|
|
.eq(WxMerchant::getTenantId, tenantId) |
|
|
|
.in(!CollectionUtils.isEmpty(merchantIds), WxMerchant::getId, merchantIds)); |
|
|
|
merchants.stream().map(x -> merchantNameMap.put(x.getId(), x.getName())); |
|
|
|
|
|
|
|
// b端用户数据 可从wx_merchant_b_user表中查用户 |
|
|
|
List<WxMerchantBUser> bUsers = wxMerchantBUserMapper.selectList(new LambdaQueryWrapper<WxMerchantBUser>() |
|
|
|
.eq(WxMerchantBUser::getTenantId, tenantId) |
|
|
|
.in(!CollectionUtils.isEmpty(bUserIds), WxMerchantBUser::getId, bUserIds)); |
|
|
|
bUsers.stream().map(x -> bUserMap.put(x.getId(), x)); |
|
|
|
} |
|
|
|
return list.stream().map(x -> { |
|
|
|
WxCouponOrderBVo co = new WxCouponOrderBVo(); |
|
|
|
try { |
|
|
|
BeanUtils.copyProperties(co, x); |
|
|
|
if (co.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) { |
|
|
|
co.setUpdateDate(null); |
|
|
|
} |
|
|
|
if (null != co.getSendMerchantId()) { |
|
|
|
co.setSendMerchantName(merchantNameMap.get(co.getSendMerchantId())); |
|
|
|
} |
|
|
|
WxCoupon coupon = couponMap.get(co.getCouponId()); |
|
|
|
if (null != coupon) { |
|
|
|
co.setTitle(coupon.getTitle()); |
|
|
|
co.setSalePrice(coupon.getSalePrice()); |
|
|
|
co.setUsePrice(coupon.getUsePrice()); |
|
|
|
co.setPrice(coupon.getPrice()); |
|
|
|
co.setAutoRefund(coupon.getAutoRefund()); |
|
|
|
co.setBusiness(coupon.getBusiness()); |
|
|
|
co.setSubsidyType(coupon.getSubsidyType()); |
|
|
|
co.setSourceType(coupon.getSourceType()); |
|
|
|
} |
|
|
|
co.setSubsidyNum(co.getSubsidy()); |
|
|
|
List<WxCouponMerchant> couponMerchantNum = couponMerchantMap.get(co.getCouponId()); |
|
|
|
if (couponMerchantNum.size() > 1) { |
|
|
|
co.setMerchantName("多商户通用"); |
|
|
|
co.setMerchantId(0L); |
|
|
|
}else { |
|
|
|
Long merchantId = couponMerchantNum.get(0).getMerchantId(); |
|
|
|
co.setMerchantName(merchantNameMap.get(merchantId)); |
|
|
|
co.setMerchantId(merchantId); |
|
|
|
} |
|
|
|
if(co.getBMerchantId() != null){ |
|
|
|
co.setbMerchantName(merchantNameMap.get(co.getBMerchantId())); |
|
|
|
co.setVerifyMerchantName(merchantNameMap.get(co.getBMerchantId())); |
|
|
|
} |
|
|
|
WxCUserBasicInfo basicInfo = cUserMap.get(co.getCUserId()); |
|
|
|
if (!cUserEntry) { |
|
|
|
co.setcuserPhone(basicInfo.getPhone()); |
|
|
|
co.setUserNickName(basicInfo.getNickName()); |
|
|
|
}else { |
|
|
|
co.setcuserPhone("保密"); |
|
|
|
co.setUserNickName("保密"); |
|
|
|
} |
|
|
|
if(null != co.getBUserId()){ |
|
|
|
WxMerchantBUser bUser = bUserMap.get(co.getBUserId()); |
|
|
|
co.setbUserPhone(bUser.getPhone()); |
|
|
|
co.setbuserName(bUser.getName()); |
|
|
|
} |
|
|
|
} catch (IllegalAccessException | InvocationTargetException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
} |
|
|
|
return co; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
private List<Long> getMerchantIdsQueryParam(WxCouponOrderBVo wxCouponOrder) { |
|
|
|
|
|
|
|
List<Long> retMerchantIdList = new ArrayList<Long>(); |
|
|
|
boolean isConditiondQquery = false; |
|
|
|
|