统计 用户 领取 记录
This commit is contained in:
@@ -4,6 +4,7 @@ import com.czg.account.dto.QueryReceiveDto;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.ShopInfoCouponVO;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.market.vo.CouponRecordCountVO;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
@@ -26,4 +27,7 @@ public interface MkShopCouponRecordMapper extends BaseMapper<MkShopCouponRecord>
|
||||
List<UserCouponVo> queryByVipIdAndShopId(Long shopId, Long shopUserId, Integer type, Integer isFood);
|
||||
|
||||
List<ShopInfoCouponVO> getShopByCouponRecord(Long userId);
|
||||
|
||||
|
||||
List<CouponRecordCountVO> countRecordBySource(Long couponId, Long userId, Integer status, String source, String startTime, String endTime);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
@@ -21,6 +23,7 @@ import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.entity.SmsPushEventUser;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.vo.CouponRecordCountVO;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.czg.service.market.mapper.MkShopCouponRecordMapper;
|
||||
import com.czg.service.market.mapper.ShopCouponMapper;
|
||||
@@ -38,9 +41,9 @@ import org.apache.dubbo.config.annotation.DubboService;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 优惠券发放记录表 服务层实现。
|
||||
@@ -64,6 +67,25 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||
@Resource
|
||||
private ShopCouponMapper couponService;
|
||||
|
||||
private static final List<String> TARGET_KEY;
|
||||
|
||||
private static final Map<String, String> SOURCE_TO_CATEGORY;
|
||||
|
||||
static {
|
||||
TARGET_KEY = Arrays.asList("消费赠券", "充值赠券", "管理员赠送", "兑换码兑换", "生日赠券", "购买会员赠券", "短信发放", "公众号发放", "用户弹窗领取");
|
||||
SOURCE_TO_CATEGORY = Map.of(
|
||||
"用户弹窗领取", "用户领取",
|
||||
"兑换码兑换", "用户领取",
|
||||
"短信发放", "推广发放",
|
||||
"公众号发放", "推广发放",
|
||||
"管理员赠送", "管理员赠送",
|
||||
"消费赠券", "系统发送",
|
||||
"充值赠券", "系统发送",
|
||||
"生日赠券", "系统发送",
|
||||
"购买会员赠券", "系统发送"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<CouponReceiveVo> queryReceive(QueryReceiveDto param) {
|
||||
@@ -82,7 +104,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||
|
||||
|
||||
@Override
|
||||
public Page<MkShopCouponRecordDTO> getRecord(MkShopCouponRecordDTO mkShopCouponRecordDTO, String startTime, String endTime) {
|
||||
public Map<String, Object> getRecord(MkShopCouponRecordDTO mkShopCouponRecordDTO, String startTime, String endTime) {
|
||||
AssertUtil.isNull(mkShopCouponRecordDTO.getCouponId(), "优惠券Id不能为空");
|
||||
ShopCoupon coupon = couponService.selectOneById(mkShopCouponRecordDTO.getCouponId());
|
||||
AssertUtil.isNull(coupon, "优惠券不存在");
|
||||
@@ -125,7 +147,41 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||
record.setNickName(userInfo.getNickName());
|
||||
}
|
||||
}
|
||||
return recordPage;
|
||||
Map<String, Object> resultmap = BeanUtil.beanToMap(recordPage);
|
||||
List<CouponRecordCountVO> recordCountVO = getMapper().countRecordBySource(mkShopCouponRecordDTO.getCouponId(), mkShopCouponRecordDTO.getUserId(),
|
||||
mkShopCouponRecordDTO.getStatus(), mkShopCouponRecordDTO.getSource(), startTime, endTime);
|
||||
Map<String, Long> tempMap = recordCountVO.stream()
|
||||
.collect(Collectors.toMap(
|
||||
CouponRecordCountVO::getSourceType,
|
||||
CouponRecordCountVO::getCount,
|
||||
(existing, _) -> existing
|
||||
));
|
||||
Map<String, Long> categoryMap = TARGET_KEY.stream()
|
||||
.collect(Collectors.toMap(
|
||||
key -> key,
|
||||
key -> tempMap.getOrDefault(key, 0L)
|
||||
));
|
||||
resultmap.put("categoryMap", categoryMap);
|
||||
Map<String, Long> resultCountMap = new HashMap<>();
|
||||
resultCountMap.put("用户领取", 0L);
|
||||
resultCountMap.put("推广发放", 0L);
|
||||
resultCountMap.put("管理员赠送", 0L);
|
||||
resultCountMap.put("系统发送", 0L);
|
||||
|
||||
if (CollUtil.isNotEmpty(recordCountVO)) {
|
||||
for (CouponRecordCountVO record : recordCountVO) {
|
||||
String sourceName = record.getSourceType();
|
||||
Long count = record.getCount();
|
||||
|
||||
String category = SOURCE_TO_CATEGORY.get(sourceName);
|
||||
if (category != null) {
|
||||
resultCountMap.put(category, resultCountMap.get(category) + count);
|
||||
}
|
||||
}
|
||||
}
|
||||
resultmap.put("categoryMap", categoryMap);
|
||||
resultmap.put("resultCountMap", resultCountMap);
|
||||
return resultmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -352,6 +408,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||
/**
|
||||
* 发放券 批量发放 不计限领
|
||||
* 检查优惠券状态 检查店铺ID是否存在且与发放店铺一致 检查优惠券是否失效
|
||||
*
|
||||
* @param giftDTO 除 sourceFlowId shopUserId外 全必填 如果有 也填
|
||||
* @param number 发放数量
|
||||
*/
|
||||
|
||||
@@ -156,4 +156,39 @@
|
||||
AND inRecord.is_del = 0
|
||||
GROUP BY inRecord.shop_id
|
||||
</select>
|
||||
|
||||
<select id="countRecordBySource" resultType="com.czg.market.vo.CouponRecordCountVO">
|
||||
SELECT CASE
|
||||
WHEN source LIKE '充值赠券%' THEN '充值赠券'
|
||||
WHEN source LIKE '购买会员赠券%' THEN '购买会员赠券'
|
||||
ELSE source
|
||||
END AS sourceType,
|
||||
COUNT(1) AS count
|
||||
FROM `mk_shop_coupon_record`
|
||||
where (coupon_id = #{couponId} or coupon_sync_id = #{couponId})
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="source != null and source != ''">
|
||||
<choose>
|
||||
<when test='source == "充值赠券"'>
|
||||
AND source LIKE '充值赠券%'
|
||||
</when>
|
||||
<when test='source == "购买会员赠券"'>
|
||||
AND source LIKE '购买会员赠券%'
|
||||
</when>
|
||||
<otherwise>
|
||||
AND source = #{source}
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="startTime != null and endTime != null and startTime != '' and endTime != ''">
|
||||
AND create_time BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
GROUP BY sourceType;
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user