|
@@ -1,33 +1,35 @@
|
|
|
package org.jeecg.modules.business.service.impl;
|
|
package org.jeecg.modules.business.service.impl;
|
|
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
-import com.baomidou.mybatisplus.extension.service.IService;
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import lombok.val;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
-import org.jeecg.common.Enum.CouponEnums;
|
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
|
|
+import org.jeecg.common.util.RedisUtil;
|
|
|
import org.jeecg.common.util.TokenUtils;
|
|
import org.jeecg.common.util.TokenUtils;
|
|
|
import org.jeecg.modules.business.dto.CouponsGenerateDto;
|
|
import org.jeecg.modules.business.dto.CouponsGenerateDto;
|
|
|
|
|
+import org.jeecg.modules.business.dto.MobileDto;
|
|
|
|
|
+import org.jeecg.modules.business.dto.ProvideCouponsUsedDto;
|
|
|
import org.jeecg.modules.business.entity.BusMarketCoupons;
|
|
import org.jeecg.modules.business.entity.BusMarketCoupons;
|
|
|
import org.jeecg.modules.business.entity.BusMarketCouponsUsed;
|
|
import org.jeecg.modules.business.entity.BusMarketCouponsUsed;
|
|
|
|
|
+import org.jeecg.modules.business.enums.CouponsStatusEnum;
|
|
|
import org.jeecg.modules.business.mapper.BusMarketCouponsMapper;
|
|
import org.jeecg.modules.business.mapper.BusMarketCouponsMapper;
|
|
|
import org.jeecg.modules.business.mapper.BusMarketCouponsUsedMapper;
|
|
import org.jeecg.modules.business.mapper.BusMarketCouponsUsedMapper;
|
|
|
-import org.jeecg.modules.business.service.IBusMarketCouponsService;
|
|
|
|
|
import org.jeecg.modules.business.service.IBusMarketCouponsUsedService;
|
|
import org.jeecg.modules.business.service.IBusMarketCouponsUsedService;
|
|
|
-import org.jeecg.modules.rooms.DTO.CesRoomLayoutMemberInfoPriceDto;
|
|
|
|
|
-import org.jeecg.modules.rooms.entity.CesRoomLayoutMemberPrice;
|
|
|
|
|
-import org.jeecg.modules.rooms.entity.CesRoomLayoutPrice;
|
|
|
|
|
-import org.jeecg.modules.rooms.mapper.CesRoomLayoutPriceMapper;
|
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.math.BigInteger;
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @Description: 免房券领取使用表
|
|
* @Description: 免房券领取使用表
|
|
@@ -42,7 +44,8 @@ public class BusMarketCouponsUsedServiceImpl extends ServiceImpl<BusMarketCoupon
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private BusMarketCouponsMapper busMarketCouponsMapper;
|
|
private BusMarketCouponsMapper busMarketCouponsMapper;
|
|
|
-
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
/**
|
|
/**
|
|
|
* 生成16位数字+prefix
|
|
* 生成16位数字+prefix
|
|
|
* @param prefix
|
|
* @param prefix
|
|
@@ -85,4 +88,100 @@ public class BusMarketCouponsUsedServiceImpl extends ServiceImpl<BusMarketCoupon
|
|
|
this.saveBatch(busMarketCouponsUsedList);
|
|
this.saveBatch(busMarketCouponsUsedList);
|
|
|
return Result.ok("创建成功");
|
|
return Result.ok("创建成功");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发放免房券给非会员
|
|
|
|
|
+ * @param dto
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result gainCouponsUsedToNoMember(ProvideCouponsUsedDto dto) {
|
|
|
|
|
+ if (ObjectUtils.isEmpty(dto.getCouponsId())) return Result.error("免房券id不能为空");
|
|
|
|
|
+ if (dto.getNum() <= 0) return Result.error("每人发放张数不能小于1!");
|
|
|
|
|
+ if (dto.getMobiles() == null || dto.getMobiles().size() <= 0) return Result.error("手机号不能为空!");
|
|
|
|
|
+ BusMarketCoupons coupons = busMarketCouponsMapper.selectById(dto.getCouponsId());
|
|
|
|
|
+ if (ObjectUtils.isEmpty(coupons)) {
|
|
|
|
|
+ return Result.error("免房券活动不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dto.getNum() > coupons.getKlqzs()) {
|
|
|
|
|
+ return Result.error("每人最多可领取" + coupons.getKlqzs());
|
|
|
|
|
+ }
|
|
|
|
|
+ int totalNum = dto.getMobiles().size() * dto.getNum();
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<BusMarketCouponsUsed> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(BusMarketCouponsUsed::getStatus, CouponsStatusEnum.notClaimed.getKey());
|
|
|
|
|
+ queryWrapper.eq(BusMarketCouponsUsed::getCouponsId, dto.getCouponsId());
|
|
|
|
|
+
|
|
|
|
|
+ Page<BusMarketCouponsUsed> page = new Page<BusMarketCouponsUsed>(1, totalNum);
|
|
|
|
|
+ IPage<BusMarketCouponsUsed> pageList = this.page(page, queryWrapper);
|
|
|
|
|
+ int count = pageList.getRecords().size();
|
|
|
|
|
+// Long count= this.count(queryWrapper);
|
|
|
|
|
+ if (totalNum > count) {
|
|
|
|
|
+ return Result.error("待领取数量" + count + ",不够发放");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<BusMarketCouponsUsed> list = pageList.getRecords();
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+// AtomicReference<Boolean> isBreak = new AtomicReference<>(false);
|
|
|
|
|
+ String message = "创建成功";
|
|
|
|
|
+ try {
|
|
|
|
|
+// for (int i = 0; i < dto.getMobiles().size(); i++) {
|
|
|
|
|
+// int num = dto.getNum();
|
|
|
|
|
+ //以防手机号相同用分组实现
|
|
|
|
|
+ Map<String, List<MobileDto>> map= dto.getMobiles().stream().collect(Collectors.groupingBy(t->t.getValue()));
|
|
|
|
|
+ for (String key:map.keySet()) {
|
|
|
|
|
+ int num = dto.getNum()*map.get(key).size();
|
|
|
|
|
+ if (num> coupons.getKlqzs()) {
|
|
|
|
|
+ throw new JeecgBootException("每人最多可领取" + coupons.getKlqzs());
|
|
|
|
|
+ }
|
|
|
|
|
+ while (num > 0) {
|
|
|
|
|
+ LambdaQueryWrapper<BusMarketCouponsUsed> queryWrapper2 = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper2.eq(BusMarketCouponsUsed::getCouponsId, dto.getCouponsId());
|
|
|
|
|
+// queryWrapper2.eq(BusMarketCouponsUsed::getMobile, dto.getMobiles().get(i).getValue());
|
|
|
|
|
+ queryWrapper2.eq(BusMarketCouponsUsed::getMobile, key);
|
|
|
|
|
+ Long gainCount = this.count(queryWrapper2);
|
|
|
|
|
+ if (gainCount > coupons.getKlqzs()) {
|
|
|
|
|
+ throw new JeecgBootException("每人限领数量" + coupons.getKlqzs());
|
|
|
|
|
+ }
|
|
|
|
|
+ BusMarketCouponsUsed model = list.get(index);
|
|
|
|
|
+ String keyString = String.format("sys:cache:couponsused::%s", model.getId());
|
|
|
|
|
+ if (redisUtil.hasKey(keyString)) {
|
|
|
|
|
+// isBreak.set(true);
|
|
|
|
|
+// break;
|
|
|
|
|
+ throw new JeecgBootException("该免房券已被领取,请勿同时操作该功能");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ redisUtil.set(keyString, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ //这里到时候要根据会员表查询一下是否存在会员信息,现在没有会员表
|
|
|
|
|
+// model.setMobile(dto.getMobiles().get(i).getValue());
|
|
|
|
|
+ model.setMobile(key);
|
|
|
|
|
+ model.setGainTime(DateTime.now());
|
|
|
|
|
+ model.setStatus(CouponsStatusEnum.received.getKey());
|
|
|
|
|
+ index++;
|
|
|
|
|
+ num--;
|
|
|
|
|
+ }
|
|
|
|
|
+// if (isBreak.get()) {
|
|
|
|
|
+// //删除redis缓存
|
|
|
|
|
+// list.forEach(item -> {
|
|
|
|
|
+// String keyString = String.format("sys:cache:couponsused::%s", item.getId());
|
|
|
|
|
+// redisUtil.del(keyString);
|
|
|
|
|
+// });
|
|
|
|
|
+// return Result.error("该免房券已被领取,请勿同时操作该功能");
|
|
|
|
|
+// }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.updateBatchById(list);
|
|
|
|
|
+ } catch (JeecgBootException ex) {
|
|
|
|
|
+ message = ex.getMessage();
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ message = "创建失败";
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ //删除redis缓存
|
|
|
|
|
+ list.forEach(item -> {
|
|
|
|
|
+ String keyString = String.format("sys:cache:couponsused::%s", item.getId());
|
|
|
|
|
+ redisUtil.del(keyString);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return message == "创建成功" ? Result.ok(message) : Result.error(message);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|