统计 用户 领取 记录
This commit is contained in:
@@ -4,14 +4,16 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.log.annotation.OperationLog;
|
||||
import com.czg.market.dto.*;
|
||||
import com.czg.market.dto.MkCouponGiftDTO;
|
||||
import com.czg.market.dto.MkRewardCouponDTO;
|
||||
import com.czg.market.dto.MkShopCouponRecordDTO;
|
||||
import com.czg.market.dto.ShopCouponDTO;
|
||||
import com.czg.market.service.MkCouponGiftService;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.product.service.ShopSyncService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.task.CouponTask;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
@@ -24,6 +26,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -152,11 +155,11 @@ public class ACouponController {
|
||||
* 优惠券列表/已领取详情
|
||||
*/
|
||||
@GetMapping("/record")
|
||||
public CzgResult<Page<MkShopCouponRecordDTO>> getRecordByCoupon(
|
||||
public CzgResult<Map<String, Object>> getRecordByCoupon(
|
||||
@RequestParam(required = false) String startTime,
|
||||
@RequestParam(required = false) String endTime,
|
||||
MkShopCouponRecordDTO param) {
|
||||
Page<MkShopCouponRecordDTO> data = couponRecordService.getRecord(param, startTime, endTime);
|
||||
Map<String, Object> data = couponRecordService.getRecord(param, startTime, endTime);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
@@ -188,9 +191,7 @@ public class ACouponController {
|
||||
private void asyncToBranchShop(Long id, Integer type) {
|
||||
long shopId = StpKit.USER.getShopId(0L);
|
||||
log.info("优惠券同步,优惠券id:{},类型:{}", id, type);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
shopSyncService.syncCouponBySourceShop(shopId, id, type);
|
||||
});
|
||||
ThreadUtil.execAsync(() -> shopSyncService.syncCouponBySourceShop(shopId, id, type));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.czg.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 回调
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/notify")
|
||||
public class NotifyController {
|
||||
private static final String SUCCESS = "SUCCESS";
|
||||
|
||||
|
||||
|
||||
@PostMapping("testOpen")
|
||||
public JSONObject test1(@RequestBody String string) throws Exception {
|
||||
log.info("扫码回调Post:{}",string);
|
||||
return null;
|
||||
}
|
||||
|
||||
@GetMapping("testOpen")
|
||||
public JSONObject test12(HttpServletRequest request) throws Exception {
|
||||
request.getParameterMap().forEach((k,v)->{
|
||||
log.info("扫码回调Get {}:{}",k,v[0]);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 优惠券发放记录表 服务层。
|
||||
@@ -29,7 +30,7 @@ public interface MkShopCouponRecordService extends IService<MkShopCouponRecord>
|
||||
/**
|
||||
* 优惠券列表/已领取详情
|
||||
*/
|
||||
Page<MkShopCouponRecordDTO> getRecord(MkShopCouponRecordDTO param, String startTime, String endTime);
|
||||
Map<String, Object> getRecord(MkShopCouponRecordDTO param, String startTime, String endTime);
|
||||
/**
|
||||
* 消费赠券已领取详情
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.czg.market.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 惠券发放记录统计 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CouponRecordCountVO {
|
||||
/**
|
||||
* 优惠券来源
|
||||
*/
|
||||
private String sourceType;
|
||||
/**
|
||||
* 优惠券数量
|
||||
*/
|
||||
private Long count;
|
||||
|
||||
}
|
||||
@@ -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