Răsfoiți Sursa

车票到期每日弹窗

zoujiajian 2 ani în urmă
părinte
comite
f8ab284c8e

+ 2 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -831,6 +831,8 @@ public class RedisService {
         CHATGPT_CAR_SCORES("chatgpt:car:scores","chatGpt 车队分数", 48 * 60 * 60L),
         CHATGPT_CAR_HIGH_CHAT("chatgpt:car:high:chat:","chatGpt gpt4 对话次数", 48 * 60 * 60L),
         CHATGPT_CAR_LOW_CHAT("chatgpt:car:low:chat:","chatGpt 3.5 对话次数", 48 * 60 * 60L),
+        //车票到期前每日通知key
+        TICKET_EXPIRY_NOTIFY_DAY("ticket_expiry_notify_day:%s:%s", "车票到期前每日通知key", 60 * 60 * 24L),
         ;
 
         private String name;

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/relation/GroupRelationFrontService.java

@@ -53,4 +53,6 @@ public interface GroupRelationFrontService {
 	Integer getUserCodeNumBySkuId(Long userId, Long skuId, Boolean isHasVerifyCode);
 
 	List<RenewalView>  getHasPayGoods(long userId);
+
+	List<RenewalView> getExpiryRenewalNotify(Long userId);
 }

+ 48 - 0
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -44,6 +44,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
 import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
@@ -608,6 +610,52 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		return list;
 	}
 
+	@Override
+	public List<RenewalView> getExpiryRenewalNotify(Long userId) {
+		DateTime now = DateTime.now();
+		DateTime thisZero = DateUtil.beginOfDay(now);
+		String thisDate = thisZero.toDateStr();
+		Object exists = redisService.get(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId));
+		if (exists != null) {
+			return null;
+		}
+		User u = userMapper.selectById(userId);
+		if (u == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
+		if (u.getIsBlack()) {
+			redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
+			return null;
+		}
+		List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
+		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
+		SearchResult<RenewalView> list = beanSearcher.search(RenewalView.class, builder
+				.field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
+				.field(RenewalView::getUserId, userIds).op(Operator.InList)
+				.field("condition", String.format("(gr.expiry_time is null or gr.expiry_time > '%s')", now))
+				.field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
+				.orderBy(RenewalView::getExpiryTime).asc()
+				.build());
+		if (list.getDataList().size() > 5) {
+			redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
+			return null;
+		}
+		//提前7天
+		AtomicInteger day = new AtomicInteger(7);
+		List<RenewalView> expiryTickets = list.getDataList().stream().filter(ticket -> {
+			Long skuNum = ticket.getSkuNum();
+			Date expiryTime = ticket.getExpiryTime();
+			//年付 提前一个月
+			if (skuNum >= 12) {
+				day.set(30);
+			}
+			if (DateUtil.beginOfDay(expiryTime).compareTo(DateUtil.offsetDay(thisZero, day.get())) <= 0) {
+				return true;
+			}
+			return false;
+		}).collect(Collectors.toList());
+		redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
+		return expiryTickets;
+	}
+
 	public String getDifferentGoodsCode(Long goodsId, String body, Integer type) {
 		String code = null;
 		//奈飞

+ 10 - 0
netflix-web/src/main/java/com/cyksj/web/controller/group/GroupRelationController.java

@@ -753,4 +753,14 @@ public class GroupRelationController {
         cmsOrderDonService.unifiedRefund(refundReq);
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
+
+    /**
+     * 每日车票到期弹窗
+     */
+    @GetMapping("/get/expiry/notify")
+    public Result<List<RenewalView>> getExpiryRenewalNotify() {
+        Long userId = StpUserUtil.getLoginIdAsLong();
+        List<RenewalView> expiryRenewals = groupRelationFrontService.getExpiryRenewalNotify(userId);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(expiryRenewals);
+    }
 }