Просмотр исходного кода

feat:添加查询发劵商户逻辑,添加劵订单构造数据逻辑方法

release_toaliyun_real
xmzhao71 2 лет назад
Родитель
Сommit
c826259fd5
3 измененных файлов: 187 добавлений и 14 удалений
  1. +5
    -0
      mallinkService/src/main/java/com/iformall/exception/BizException.java
  2. +147
    -14
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java
  3. +35
    -0
      mallinkService/src/main/java/com/iformall/utils/service/MallUtils.java

+ 5
- 0
mallinkService/src/main/java/com/iformall/exception/BizException.java Просмотреть файл

@@ -12,6 +12,11 @@ public class BizException extends RuntimeException {
private int code; private int code;
private String msg; private String msg;


public BizException(String msg) {
super(msg);
this.msg = msg;
}

public BizException(int code, String msg) { public BizException(int code, String msg) {
super(msg); super(msg);
this.code = code; this.code = code;


+ 147
- 14
mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java Просмотреть файл

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.iformall.common.*; import com.iformall.common.*;
import com.iformall.domain.dto.WxSharingOrderDto; import com.iformall.domain.dto.WxSharingOrderDto;
import com.iformall.domain.po.*; 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.po.msg.MpAppMsg;
import com.iformall.domain.vo.*; import com.iformall.domain.vo.*;
import com.iformall.enums.*; import com.iformall.enums.*;
import com.iformall.exception.BizException;
import com.iformall.exception.MallinkException; import com.iformall.exception.MallinkException;
import com.iformall.mapper.*; import com.iformall.mapper.*;
import com.iformall.mq.MqBaseProducer; 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.Constant;
import com.iformall.utils.DateUtils; import com.iformall.utils.DateUtils;
import com.iformall.utils.RedisLock; import com.iformall.utils.RedisLock;
import com.iformall.utils.service.MallUtils;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -203,6 +207,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
@Autowired @Autowired
WxMallMapper wxMallMapper; WxMallMapper wxMallMapper;


@Autowired
private WxCouponSendMapper wxCouponSendMapper;

private final SimpleDateFormat mydateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final SimpleDateFormat mydateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


@Override @Override
@@ -959,10 +966,6 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
} }
private List<WxCouponOrderBVo> handleQueryResult(boolean cUserEntry,List<WxCouponOrder> list,TenantEntity couponOrderTenantEntity) { 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) { if (null != list && list.size() > 0) {


//循环list,获取 cUserId //循环list,获取 cUserId
@@ -971,6 +974,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
Map<String,List<Long>> mallMerchantIdList = new HashMap<String,List<Long>>(); Map<String,List<Long>> mallMerchantIdList = new HashMap<String,List<Long>>();
List<Long> couponIdList = new ArrayList<Long>(); List<Long> couponIdList = new ArrayList<Long>();


// mallTenantIdList:当前广场的兄弟广场以及当前广场的子广场
List<String> mallTenantIdList = new ArrayList<String>(); List<String> mallTenantIdList = new ArrayList<String>();
mallTenantIdList.add(couponOrderTenantEntity.getTenantId()); mallTenantIdList.add(couponOrderTenantEntity.getTenantId());
//查询子广场 //查询子广场
@@ -1059,12 +1063,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {


for (int i = 0 ; i < mallTenantIdList.size(); i++) { for (int i = 0 ; i < mallTenantIdList.size(); i++) {
String mallTenantId = mallTenantIdList.get(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); List<WxMerchantProductVo> merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(mallTenantId, couponIdList);
if (null != merchantProductVos) { if (null != merchantProductVos) {
if (null == merchantIds) {
merchantIds = new ArrayList<Long>();
}
for (int j = 0 ; j < merchantProductVos.size(); j ++) { for (int j = 0 ; j < merchantProductVos.size(); j ++) {
WxMerchantProductVo mp = merchantProductVos.get(j); WxMerchantProductVo mp = merchantProductVos.get(j);
if (mp.getMc() > 1) { 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); co.setUpdateDate(null);
} }
if (null != co.getSendMerchantId()) { 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()); WxCoupon coupon = couponMap.get(co.getCouponId());
if (null != coupon) { if (null != coupon) {
@@ -1196,9 +1212,126 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
return new ArrayList<WxCouponOrderBVo>(); 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>(); List<Long> retMerchantIdList = new ArrayList<Long>();
boolean isConditiondQquery = false; boolean isConditiondQquery = false;


+ 35
- 0
mallinkService/src/main/java/com/iformall/utils/service/MallUtils.java Просмотреть файл

@@ -0,0 +1,35 @@
package com.iformall.utils.service;

import com.iformall.domain.po.WxMall;
import com.iformall.domain.po.base.TenantEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class MallUtils {

public static List<String> findTenantIds(TenantEntity tenantEntity, List<WxMall> malls) {
List<String> tenantIds = new ArrayList<>();
for (WxMall mall : malls) {
if (tenantEntity.getParentTenantId() != null && tenantEntity.getParentTenantId().equals(mall.getParentTenantId())) {
tenantIds.add(mall.getTenantId());
findTenantIds(mall, malls);
}
}
Optional.ofNullable(tenantEntity.getParentTenantId()).ifPresent(x -> tenantIds.add(tenantEntity.getParentTenantId()));
return tenantIds;
}

public static List<String> findChildren(TenantEntity tenantEntity, List<WxMall> malls) {
List<String> tenantIds = new ArrayList<>();
for (WxMall mall : malls) {
if (tenantEntity.getTenantId().equals(mall.getParentTenantId())) {
tenantIds.add(mall.getTenantId());
findChildren(mall, malls);
}
}
tenantIds.add(tenantEntity.getTenantId());
return tenantIds;
}
}

Загрузка…
Отмена
Сохранить