feat: 订单催促

This commit is contained in:
huchuansai
2025-09-24 10:49:50 +08:00
parent e391058b30
commit e777adf6b0
3 changed files with 63 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
package com.starry.admin.modules.order.controller; package com.starry.admin.modules.order.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.starry.admin.common.exception.CustomException; import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity; import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity;
import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService; import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService;
@@ -24,6 +25,7 @@ import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -54,6 +56,8 @@ public class PlayOrderInfoController {
private IPlayOrderRefundInfoService playOrderRefundInfoService; private IPlayOrderRefundInfoService playOrderRefundInfoService;
@Resource @Resource
private IPlayCustomUserInfoService customUserInfoService; private IPlayCustomUserInfoService customUserInfoService;
@Resource
private IPlayClerkUserInfoService clerkUserInfoService;
/** /**
* 分页查询订单列表 * 分页查询订单列表
@@ -66,6 +70,17 @@ public class PlayOrderInfoController {
return R.ok(orderInfoService.selectOrderInfoPage(vo)); return R.ok(orderInfoService.selectOrderInfoPage(vo));
} }
@ApiOperation(value = "发送订单微信通知", notes = "发送订单微信通知")
@ApiResponses({
@ApiResponse(code = 200, message = "操作成功", response = Boolean.class, responseContainer = "Page")})
@PostMapping("/sendNotice")
public R sendNotice(String orderId) {
PlayOrderInfoEntity orderInfo = orderInfoService.selectOrderInfoById(orderId);
List<PlayClerkUserInfoEntity> clerkList = clerkUserInfoService.list(Wrappers.lambdaQuery(PlayClerkUserInfoEntity.class).isNotNull(PlayClerkUserInfoEntity::getOpenid).eq(PlayClerkUserInfoEntity::getLevelId, orderInfo.getLevelId()).eq(PlayClerkUserInfoEntity::getClerkState, "1").eq(PlayClerkUserInfoEntity::getSex, orderInfo.getSex()));
wxCustomMpService.sendCreateOrderMessageBatch(clerkList, orderInfo.getOrderNo(), orderInfo.getOrderMoney().toString(), orderInfo.getCommodityName(), orderId);
return R.ok();
}
/** /**
* 订单退款 * 订单退款
*/ */

View File

@@ -1,14 +1,18 @@
package com.starry.admin.modules.order.job; package com.starry.admin.modules.order.job;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.starry.admin.common.exception.CustomException; import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity;
import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService;
import com.starry.admin.modules.order.mapper.PlayOrderInfoMapper; import com.starry.admin.modules.order.mapper.PlayOrderInfoMapper;
import com.starry.admin.modules.order.module.entity.PlayOrderInfoEntity; import com.starry.admin.modules.order.module.entity.PlayOrderInfoEntity;
import com.starry.admin.modules.weichat.service.WxCustomMpService; import com.starry.admin.modules.weichat.service.WxCustomMpService;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -23,6 +27,8 @@ public class OrderJob {
private PlayOrderInfoMapper orderInfoMapper; private PlayOrderInfoMapper orderInfoMapper;
@Resource @Resource
private WxCustomMpService wxCustomMpService; private WxCustomMpService wxCustomMpService;
@Resource
private IPlayClerkUserInfoService clerkUserInfoService;
/** /**
@@ -64,6 +70,30 @@ public class OrderJob {
} }
@Scheduled(fixedRate = 20000, initialDelay = 20000)
public void orderNoticeJob() {
// 查询出所有应该待接单的订单,超过10分钟还没接单
List<PlayOrderInfoEntity> orderInfoEntityList = orderInfoMapper.selectList(Wrappers.lambdaQuery(PlayOrderInfoEntity.class)
.eq(PlayOrderInfoEntity::getOrderStatus, "0")
.eq(PlayOrderInfoEntity::getPlaceType, "1")
.lt(PlayOrderInfoEntity::getCreatedTime, DateUtil.offsetMinute(new Date(), -10)
));
if (CollectionUtils.isEmpty(orderInfoEntityList)) return;
orderInfoEntityList.forEach(orderInfo -> {
try {
List<PlayClerkUserInfoEntity> clerkList = clerkUserInfoService.list(Wrappers.lambdaQuery(PlayClerkUserInfoEntity.class).isNotNull(PlayClerkUserInfoEntity::getOpenid).eq(PlayClerkUserInfoEntity::getLevelId, orderInfo.getLevelId()).eq(PlayClerkUserInfoEntity::getClerkState, "1")
.eq(PlayClerkUserInfoEntity::getSex, orderInfo.getSex()).eq(PlayClerkUserInfoEntity::getTenantId, orderInfo.getTenantId()));
wxCustomMpService.sendCreateOrderMessageBatch(clerkList, orderInfo.getOrderNo(), orderInfo.getOrderMoney().toString(), orderInfo.getCommodityName(), orderInfo.getId());
} catch (Exception e) {
log.error(e.getMessage(), e);
log.error("订单催促失败:{}", orderInfo.getOrderNo());
}
});
}
private Integer getServiceDuration(String serviceDuration) { private Integer getServiceDuration(String serviceDuration) {
if (StringUtils.isEmpty(serviceDuration)) { if (StringUtils.isEmpty(serviceDuration)) {
throw new CustomException("服务时长不能为空"); throw new CustomException("服务时长不能为空");

View File

@@ -76,6 +76,20 @@ public class WxCustomMpService {
wxMpService.addConfigStorage(entity.getAppId(), config); wxMpService.addConfigStorage(entity.getAppId(), config);
return wxMpService.switchoverTo(entity.getAppId()); return wxMpService.switchoverTo(entity.getAppId());
} }
public WxMpService proxyWxMpService(String tenantId) {
if (StrUtil.isBlankIfStr(tenantId)) {
throw new CustomException("系统错误,租户ID不能为空");
}
SysTenantEntity entity = tenantService.selectSysTenantByTenantId(tenantId);
if (entity == null) {
throw new CustomException("系统错误,租户ID不能为空");
}
WxMpMapConfigImpl config = new WxMpMapConfigImpl();
config.setAppId(entity.getAppId());
config.setSecret(entity.getSecret());
wxMpService.addConfigStorage(entity.getAppId(), config);
return wxMpService.switchoverTo(entity.getAppId());
}
public WxPayService getWxPay() { public WxPayService getWxPay() {
String tenantId = SecurityUtils.getTenantId(); String tenantId = SecurityUtils.getTenantId();
@@ -161,7 +175,7 @@ public class WxCustomMpService {
data.add(new WxMpTemplateData("amount8", money)); data.add(new WxMpTemplateData("amount8", money));
templateMessage.setData(data); templateMessage.setData(data);
try { try {
proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage); proxyWxMpService(tenantId).getTemplateMsgService().sendTemplateMsg(templateMessage);
} catch (WxErrorException e) { } catch (WxErrorException e) {
log.error("接单成功发送消息异常", e); log.error("接单成功发送消息异常", e);
} }
@@ -324,7 +338,7 @@ public class WxCustomMpService {
data.add(new WxMpTemplateData("thing13", order.getCommodityName())); data.add(new WxMpTemplateData("thing13", order.getCommodityName()));
templateMessage.setData(data); templateMessage.setData(data);
try { try {
proxyWxMpService().getTemplateMsgService().sendTemplateMsg(templateMessage); proxyWxMpService(tenant.getTenantId()).getTemplateMsgService().sendTemplateMsg(templateMessage);
} catch (WxErrorException e) { } catch (WxErrorException e) {
log.error("订单完成发送消息异常", e); log.error("订单完成发送消息异常", e);
} }