Procházet zdrojové kódy

Merge branch 'groups_close'

# Conflicts:
#	netflix-service/src/main/java/com/cyksj/task/Scheduler.java
zoujiajian před 3 roky
rodič
revize
91b1ccf5fd

+ 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;

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/OrderDon.java

@@ -52,6 +52,11 @@ public class OrderDon extends BaseEntity implements Serializable {
      */
     private BigDecimal refundMoney;
 
+    /**
+     * 退款原因
+     */
+    private String refundDesc;
+
     /**
      * 优惠金额
      */

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/manage/views/OrderDonView.java

@@ -119,6 +119,9 @@ public class OrderDonView {
     @DbField("o.refund_money")
     private BigDecimal refundMoney;
 
+    @DbField("o.refund_desc")
+    private String refundDesc;
+
     @DbField("o.status")
     private OrderDon.Status status;
 

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/request/WxOrderRefundReq.java

@@ -23,4 +23,9 @@ public class WxOrderRefundReq {
 	 */
 	@NotNull(message = "退款金额不为空")
 	private BigDecimal refundMoney;
+
+	/**
+	 * 退款原因
+	 */
+	private String refundDesc;
 }

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/request/ZfbOrderRefundReq.java

@@ -23,4 +23,9 @@ public class ZfbOrderRefundReq {
 	 */
 	@NotNull(message = "退款金额不为空")
 	private BigDecimal refundMoney;
+
+	/**
+	 * 退款原因
+	 */
+	private String refundDesc;
 }

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

@@ -0,0 +1,53 @@
+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;
+
+import java.util.Date;
+
+/*
+ *项目名: 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 id;
+
+	@DbField("a.account")
+	private String account;
+
+	@DbField("a.password")
+	private String password;
+
+	@DbField("a.goods_id")
+	private Long goodsId;
+
+	@DbField("select title from goods_don where id = a.goods_id limit 1")
+	private String title;
+
+	@DbField("gt.sku_id")
+	private Long skuId;
+
+	@DbField("select spec_val from goods_don_sku where id = gt.sku_id limit 1")
+	private String specVal;
+
+	@DbField("gt.id")
+	private Long groupsId;
+
+	@DbField("gt.num")
+	private Integer num;
+
+	@DbField("gt.status")
+	private GroupsTrips.Status groupsStatus;
+
+	@DbField("a.expiry_time")
+	private Date 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);

+ 14 - 4
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);
@@ -958,6 +962,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		//修改订单状态
 		orderDon.setStatus(OrderDon.Status.refund);
 		orderDon.setRefundMoney(wxOrderRefundReq.getRefundMoney());
+		orderDon.setRefundDesc(wxOrderRefundReq.getRefundDesc());
 		if (orderDon.getIsDistribute()) {
 			distributeWaitingSendPointsMapper.updateOrderStatus(orderDon.getId(), DistributeWaitingSendPoints.Status.close);
 		}
@@ -1041,6 +1046,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			if (orderDon.getIsDistribute()) {
 				distributeWaitingSendPointsMapper.updateOrderStatus(orderDon.getId(), DistributeWaitingSendPoints.Status.close);
 			}
+			orderDon.setRefundDesc(zfbOrderRefundReq.getRefundDesc());
 			orderDonMapper.updateById(orderDon);
 			//记录退款信息
 			THREAD_POOL_TASK_EXECUTOR.execute(()->{
@@ -1065,7 +1071,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			}
 			return GatewayResponse.SUCCESS.newBuilder().toResult("退款成功");
 		}
-		throw BusinessRuntimeException.getInstance("退款失败,e:{0}", response.getBody());
+		throw BusinessRuntimeException.getInstance("退款失败,e:{0}", response.getSubMsg());
 	}
 
 	/**
@@ -1214,7 +1220,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			refund.setOrderId(orderDon.getId());
 			refund.setOutRefundNo(outRefundNo);
 			refund.setTotalFee(orderDon.getMoney());
-			refund.setRefundDesc("订单退款");
+			refund.setRefundDesc(orderDon.getRefundDesc());
 			//退款金额
 			refund.setRefundFee(orderDon.getRefundMoney());
 			refund.setUserId(orderDon.getUserId());
@@ -1845,7 +1851,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;
@@ -451,4 +452,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.getId(), account.getGroupsId());
+			}
+		});
+	}
 }
+

+ 24 - 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,27 @@ 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}")
+    @Log(module = "过期账号/上架过期车队", businessType = BusinessType.PUT, isSaveRequestData = true)
+    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("上架成功");
+    }
 }