|
@@ -1,10 +1,30 @@
|
|
|
package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.chelvc.cloud.vehicle.api.constant.UserCouponStatus;
|
|
|
+import com.chelvc.cloud.vehicle.api.dto.UserCouponDTO;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.UserCouponModifyParam;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.UserCouponPagingParam;
|
|
|
+import com.chelvc.cloud.vehicle.api.param.UserCouponQueryParam;
|
|
|
+import com.chelvc.cloud.vehicle.server.copier.UserCouponCopier;
|
|
|
import com.chelvc.cloud.vehicle.server.dao.UserCouponMapper;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.UserCoupon;
|
|
|
import com.chelvc.cloud.vehicle.server.service.UserCouponService;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
+import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
+import com.chelvc.framework.base.util.ResourceUtils;
|
|
|
+import com.chelvc.framework.common.model.Pagination;
|
|
|
+import com.chelvc.framework.database.util.PagingUtils;
|
|
|
+import lombok.NonNull;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.dubbo.config.annotation.DubboService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 优惠券领取业务操作实现
|
|
@@ -12,6 +32,80 @@ import org.springframework.stereotype.Service;
|
|
|
* @author Woody
|
|
|
* @date 2023/7/17
|
|
|
*/
|
|
|
-@Service
|
|
|
-public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCoupon> implements UserCouponService {
|
|
|
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
+@DubboService(interfaceClass = com.chelvc.cloud.vehicle.api.service.UserCouponService.class)
|
|
|
+public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCoupon> implements UserCouponService,
|
|
|
+ com.chelvc.cloud.vehicle.api.service.UserCouponService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<UserCouponDTO> listUserCoupons(@NonNull UserCouponQueryParam param) {
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
+ // 查询过期的优惠券
|
|
|
+ if (UserCouponStatus.EXPIRED.equals(param.getStatus())) {
|
|
|
+ List<UserCoupon> userCoupons = this.baseMapper.listExpiredUserCoupons(userId, param);
|
|
|
+ if (CollectionUtils.isEmpty(userCoupons)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return userCoupons
|
|
|
+ .stream()
|
|
|
+ .map(o -> UserCouponCopier.INSTANCE.copying(o, o.getCoupon()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ // 查询未使用或已使用的优惠券
|
|
|
+ List<UserCoupon> userCoupons = this.baseMapper.listUserCoupons(userId, param);
|
|
|
+ if (CollectionUtils.isEmpty(userCoupons)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return userCoupons
|
|
|
+ .stream()
|
|
|
+ .map(o -> UserCouponCopier.INSTANCE.copying(o, o.getCoupon()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long addUserCoupon(@NonNull UserCouponModifyParam param) {
|
|
|
+ UserCoupon userCoupon = UserCouponCopier.INSTANCE.copying(param);
|
|
|
+ this.save(userCoupon);
|
|
|
+ return userCoupon.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateUserCoupon(@NonNull Long id, @NonNull UserCouponModifyParam param) {
|
|
|
+ UserCoupon userCoupon = ResourceUtils.required(this.getById(id), "优惠券领取记录不存在");
|
|
|
+ UserCouponCopier.INSTANCE.copying(param, userCoupon);
|
|
|
+ this.updateById(userCoupon);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserCouponDTO getUserCoupon(@NonNull Long id) {
|
|
|
+ return this.convert(this.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Pagination<UserCouponDTO> getUserCouponPaging(@NonNull UserCouponPagingParam param) {
|
|
|
+ // 查询优惠券领取记录列表
|
|
|
+ Page<UserCoupon> page = this.lambdaQuery()
|
|
|
+ .eq(Objects.nonNull(param.getType()), UserCoupon::getType, param.getType().name())
|
|
|
+ .eq(UserCouponStatus.USED.equals(param.getStatus()), UserCoupon::getUsed, 1)
|
|
|
+ .eq(UserCouponStatus.UNUSED.equals(param.getStatus()), UserCoupon::getUsed, 0)
|
|
|
+ .orderByDesc(UserCoupon::getId).page(PagingUtils.convert(param.getPaging()));
|
|
|
+ List<UserCoupon> records = page.getRecords();
|
|
|
+ if (CollectionUtils.isEmpty(records)) {
|
|
|
+ return Pagination.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建优惠券领取记录信息
|
|
|
+ List<UserCouponDTO> userCoupons = records.stream().map(this::convert).collect(Collectors.toList());
|
|
|
+ return PagingUtils.convert(page, userCoupons);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转换优惠券领取记录信息
|
|
|
+ *
|
|
|
+ * @param userCoupon 优惠券领取记录实例
|
|
|
+ * @return 优惠券领取记录信息
|
|
|
+ */
|
|
|
+ private UserCouponDTO convert(UserCoupon userCoupon) {
|
|
|
+ return UserCouponCopier.INSTANCE.copying(userCoupon);
|
|
|
+ }
|
|
|
}
|