Search in sources :

Example 1 with CouponApiVO

use of com.whoiszxl.cqrs.vo.CouponApiVO in project shopzz by whoiszxl.

the class ActivityServiceImpl method detail.

@Override
public ActivityApiResponse detail(Long id) {
    String redisKey = RedisKeyPrefixConstants.ACTIVITY_DETAIL + id;
    String activityJson = redisUtils.get(redisKey);
    if (StringUtils.isBlank(activityJson)) {
        synchronized (this) {
            activityJson = redisUtils.get(redisKey);
            if (StringUtils.isBlank(activityJson)) {
                // 从数据库拿数据
                ActivityApiResponse response = new ActivityApiResponse();
                Activity activity = super.getById(id);
                dozerUtils.map(activity, response);
                List<ActivityCoupon> activityCouponList = activityCouponService.list(Wrappers.<ActivityCoupon>lambdaQuery().eq(ActivityCoupon::getActivityId, id));
                List<Long> couponIdList = activityCouponList.stream().map(ActivityCoupon::getCouponId).collect(Collectors.toList());
                List<Coupon> couponList = couponService.listByIds(couponIdList);
                List<CouponApiVO> couponApiVOList = dozerUtils.mapList(couponList, CouponApiVO.class);
                response.setCouponList(couponApiVOList);
                activityJson = JsonUtil.toJson(response);
                redisUtils.set(redisKey, activityJson);
            }
        }
    }
    return JsonUtil.fromJson(activityJson, ActivityApiResponse.class);
}
Also used : ActivityCoupon(com.whoiszxl.entity.ActivityCoupon) Coupon(com.whoiszxl.entity.Coupon) ActivityCoupon(com.whoiszxl.entity.ActivityCoupon) CouponApiVO(com.whoiszxl.cqrs.vo.CouponApiVO) Activity(com.whoiszxl.entity.Activity) ActivityApiResponse(com.whoiszxl.cqrs.response.ActivityApiResponse)

Example 2 with CouponApiVO

use of com.whoiszxl.cqrs.vo.CouponApiVO in project shopzz by whoiszxl.

the class CouponServiceImpl method getCouponAllUnlimited.

@Override
public List<CouponApiVO> getCouponAllUnlimited() {
    String redisKey = RedisKeyPrefixConstants.ACTIVITY_NOTLIMIT_COUPONLIST;
    String allUnlimitedCouponListJson = redisUtils.get(redisKey);
    if (StringUtils.isBlank(allUnlimitedCouponListJson)) {
        synchronized (this) {
            allUnlimitedCouponListJson = redisUtils.get(redisKey);
            if (StringUtils.isBlank(allUnlimitedCouponListJson)) {
                List<Coupon> couponList = super.list(Wrappers.<Coupon>lambdaQuery().eq(Coupon::getFullLimited, CouponFullLimitedEnum.NOT_LIMIT.getCode()).eq(Coupon::getStatus, CouponStatusEnum.AVAIL.getCode()));
                if (couponList.isEmpty()) {
                    return Collections.emptyList();
                }
                List<CouponApiVO> couponApiVOList = dozerUtils.mapList(couponList, CouponApiVO.class);
                allUnlimitedCouponListJson = JsonUtil.toJson(couponApiVOList);
                redisUtils.set(redisKey, allUnlimitedCouponListJson);
            }
        }
    }
    Type collectionType = new TypeToken<List<CouponApiVO>>() {
    }.getType();
    return JsonUtil.fromJsonToList(allUnlimitedCouponListJson, collectionType);
}
Also used : Coupon(com.whoiszxl.entity.Coupon) MemberCoupon(com.whoiszxl.entity.MemberCoupon) Type(java.lang.reflect.Type) CouponApiVO(com.whoiszxl.cqrs.vo.CouponApiVO) List(java.util.List)

Aggregations

CouponApiVO (com.whoiszxl.cqrs.vo.CouponApiVO)2 Coupon (com.whoiszxl.entity.Coupon)2 ActivityApiResponse (com.whoiszxl.cqrs.response.ActivityApiResponse)1 Activity (com.whoiszxl.entity.Activity)1 ActivityCoupon (com.whoiszxl.entity.ActivityCoupon)1 MemberCoupon (com.whoiszxl.entity.MemberCoupon)1 Type (java.lang.reflect.Type)1 List (java.util.List)1