Procházet zdrojové kódy

fix 下架过期账号车队 阻止用户上车

zoujiajian před 3 roky
rodič
revize
e0e3d6e4f1

+ 1 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/GroupsTrips.java

@@ -148,6 +148,7 @@ public class GroupsTrips {
     public enum Status{
         waiting("等待发车"),
         validity("已发车"),
+        down("下架"),
         close("关闭");
 
         private String desc;

+ 33 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CloseGroupsTripsView.java

@@ -0,0 +1,33 @@
+package com.cyksj.model.views;
+
+import com.cyksj.model.entity.GroupsTrips;
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.SearchBean;
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: netflix
+ *文件名: CloseGroupsTripsView
+ *创建者: JavaZou
+ *创建时间:2023/5/18 14:55
+ */
+@Getter
+@Setter
+@SearchBean(tables = "account a inner join groups_trips gt on gt.account_id = a.id")
+public class CloseGroupsTripsView {
+	@DbField("a.id")
+	private Long accountId;
+
+	@DbField("a.goods_id")
+	private Long goodsId;
+
+	@DbField("gt.id")
+	private Long groupsId;
+
+	@DbField("gt.status")
+	private GroupsTrips.Status groupsStatus;
+
+	@DbField("a.expiry_time")
+	private String expiryTime;
+}

+ 5 - 1
netflix-service/src/main/java/com/cyksj/service/exchange/impl/ExchangeCodeServiceImpl.java

@@ -298,7 +298,11 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 		//寻找差不多过期时间规格的车位
 		relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths(), errorsRelationIds);
 		if (relation == null) {
-			GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, sku.getId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
+			GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
+					.eq(GroupsTrips::getSkuId, sku.getId())
+					.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
+					.ne(GroupsTrips::getStatus, GroupsTrips.Status.down)
+					.orderByAsc(GroupsTrips::getAvailableNum));
 			if (groups == null) {
 				//新增车位 并关联
 				relation = createNewGroupTripsAndRelation(sku, groups, relation);

+ 10 - 2
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -252,7 +252,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 					relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths(), null);
 					if (relation == null) {
 						//TODO 如果没指定座位,等待逻辑确认
-						LambdaQueryWrapper<GroupsTrips> queryWrapper = Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, payRequest.getSkuId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum);
+						LambdaQueryWrapper<GroupsTrips> queryWrapper = Wrappers.lambdaQuery(GroupsTrips.class)
+								.eq(GroupsTrips::getSkuId, payRequest.getSkuId())
+								.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
+								.ne(GroupsTrips::getStatus, GroupsTrips.Status.down)
+								.orderByAsc(GroupsTrips::getAvailableNum);
 						GroupsTrips groups = groupsMapper.selectOne(queryWrapper);
 						if (groups == null) {
 							relation = createNewGroupsTrips(sku);
@@ -1844,7 +1848,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 	 * 校验是否还有多余的车位
 	 */
 	private void checkNoGroupsTripsAndSendMsg(GoodsDonSku sku, OrderDon order) {
-		GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, sku.getId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
+		GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
+				.eq(GroupsTrips::getSkuId, sku.getId())
+				.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
+				.ne(GroupsTrips::getStatus, GroupsTrips.Status.down)
+				.orderByAsc(GroupsTrips::getAvailableNum));
 		if (groups == null) {
 			//新增空车队发送模板消息
 			TASK_POOL.execute(() -> {

+ 25 - 0
netflix-service/src/main/java/com/cyksj/task/Scheduler.java

@@ -19,6 +19,7 @@ import com.cyksj.mapper.manage.sys.WorkOrderMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.views.AccountView;
 import com.cyksj.model.manage.views.GroupsRelationView;
+import com.cyksj.model.views.CloseGroupsTripsView;
 import com.cyksj.model.views.CmsUserVO;
 import com.cyksj.model.views.UserDistributeViews;
 import com.cyksj.redis.RedisService;
@@ -438,4 +439,28 @@ public class Scheduler {
 		    }
 	    });
     }
+
+	/**
+	 * 每日凌晨下架今日过期车队账号
+	 */
+	@Scheduled(cron = "0 0 0 * * ?")
+	public void closeGroupsTrips() {
+		DateTime now = DateTime.now();
+		DateTime nextDay = DateUtil.offsetDay(DateUtil.beginOfDay(now), 1);
+		List<CloseGroupsTripsView> closeGroupsTripsViews = Optional.ofNullable(beanSearcher.searchAll(CloseGroupsTripsView.class, MapUtils.builder()
+				.field(CloseGroupsTripsView::getExpiryTime, nextDay).op(Operator.LessThan)
+				.field(CloseGroupsTripsView::getGoodsId, List.of(18, 26)).op(Operator.InList)
+				.field(CloseGroupsTripsView::getGroupsId).op(Operator.NotNull)
+				.build())).orElse(new ArrayList<>());
+		log.info("下架过期账号数量:{}", closeGroupsTripsViews.size());
+		closeGroupsTripsViews.forEach(account->{
+			int update = groupsMapper.update(null, Wrappers.lambdaUpdate(GroupsTrips.class)
+					.set(GroupsTrips::getStatus, GroupsTrips.Status.down)
+					.eq(GroupsTrips::getId, account.getGroupsId()));
+			if (update == 1) {
+				log.info("将过期账号:{}车队:{}下架", account.getAccountId(), account.getGroupsId());
+			}
+		});
+	}
 }
+

+ 23 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/group/CmsGroupController.java

@@ -16,6 +16,7 @@ import com.cyksj.model.entity.GroupsTrips;
 import com.cyksj.model.entity.GroupsTripsAccountReplaceRecord;
 import com.cyksj.model.request.AccountGroupsReq;
 import com.cyksj.model.request.ReplaceTripsAccountReq;
+import com.cyksj.model.views.CloseGroupsTripsView;
 import com.cyksj.model.views.GoodsDonSkuView;
 import com.cyksj.model.views.GroupsTripsWaitingView;
 import com.cyksj.service.mange.CmsAccountService;
@@ -181,4 +182,26 @@ public class CmsGroupController {
         SearchResult<GroupsTripsAccountReplaceRecord> search = beanSearcher.search(GroupsTripsAccountReplaceRecord.class, MapUtils.flatBuilder(request.getParameterMap()).build());
         return GatewayResponse.SUCCESS.newBuilder().toResult(search);
     }
+
+    /**
+     * 已下架的车队列表展示
+     */
+    @GetMapping("/get/down/trips")
+    public Result<SearchResult<CloseGroupsTripsView>> getDownGroups() {
+        SearchResult<CloseGroupsTripsView> search = beanSearcher.search(CloseGroupsTripsView.class, MapUtils.flatBuilder(request.getParameterMap())
+                .field(CloseGroupsTripsView::getGroupsStatus, GroupsTrips.Status.down.name()).build());
+        return GatewayResponse.SUCCESS.newBuilder().toResult(search);
+    }
+
+    /**
+     * 重新上架过期车队
+     */
+    @PutMapping("/up/trips/{groupsId}")
+    public Result<String> upGroupsTrips(@PathVariable Long groupsId) {
+        groupService.update(null, Wrappers.lambdaUpdate(GroupsTrips.class)
+                .set(GroupsTrips::getStatus, GroupsTrips.Status.validity)
+                .eq(GroupsTrips::getStatus, GroupsTrips.Status.down)
+                .eq(GroupsTrips::getId, groupsId));
+        return GatewayResponse.SUCCESS.newBuilder().toResult("上架成功");
+    }
 }