feat(cloud-manage-server): 添加小程序码下载功能并优化预约单过期处理
- 新增 downloadQRCode2 方法,用于下载小程序码 - 优化 orderSwapBatteryExpired 方法,改进预约单过期处理逻辑 - 移除 WechatPayServiceImpl 中的冗余日志输出
This commit is contained in:
parent
6191a2b98b
commit
550bb94f2c
@ -97,6 +97,10 @@ public class BatteryStationController {
|
|||||||
public void createQRCode2(String path, @RequestParam(required = false) String width, HttpServletResponse response) {
|
public void createQRCode2(String path, @RequestParam(required = false) String width, HttpServletResponse response) {
|
||||||
batteryStationService.createQRCode2(path, width, response);
|
batteryStationService.createQRCode2(path, width, response);
|
||||||
}
|
}
|
||||||
|
@Operation(summary = "下载小程序码")
|
||||||
|
@GetMapping("/qrcode/downloadQRCode2")
|
||||||
|
public void downloadQRCode2(@RequestParam String path, @RequestParam String width, HttpServletResponse response) {
|
||||||
|
batteryStationService.downloadQRCode2(path, width, response);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,4 +28,5 @@ public interface BatteryStationService {
|
|||||||
|
|
||||||
public void createQRCode2(String path, String width, HttpServletResponse response);
|
public void createQRCode2(String path, String width, HttpServletResponse response);
|
||||||
|
|
||||||
|
public void downloadQRCode2(String path, String width, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -242,4 +242,34 @@ public class BatteryStationServiceImpl implements BatteryStationService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadQRCode2(String path, String width, HttpServletResponse response) {
|
||||||
|
String qrCode2Str = wechatService.createQRCode2(path, width);
|
||||||
|
byte[] res = Base64.getDecoder().decode(qrCode2Str);
|
||||||
|
|
||||||
|
String fileName = "小程序二维码" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".png";
|
||||||
|
response.setContentType("image/png");
|
||||||
|
response.setContentLength(res.length);
|
||||||
|
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
|
response.setHeader("Pragma", "no-cache");
|
||||||
|
response.setHeader("Expires", "0");
|
||||||
|
|
||||||
|
try {
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ServletOutputStream out = null;
|
||||||
|
try {
|
||||||
|
out = response.getOutputStream();
|
||||||
|
out.write(res);
|
||||||
|
out.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
IoUtil.close(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,16 +22,16 @@ public class OrderSwapBatteryTask {
|
|||||||
@Resource
|
@Resource
|
||||||
private OrderSwapBatteryPreDao orderSwapBatteryPreDao;
|
private OrderSwapBatteryPreDao orderSwapBatteryPreDao;
|
||||||
|
|
||||||
// @Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
|
@Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
|
||||||
public void orderSwapBatteryExpired() {
|
public void orderSwapBatteryExpired() {
|
||||||
log.info("===>>> 开始查找预约单更新预约状态...");
|
log.info("\r\n===>>> 开始查找预约单更新预约状态..");
|
||||||
|
|
||||||
try {
|
// 查询条件,排除已过期和无效状态
|
||||||
// 查询条件:排除已过期(3)和无效(4)的订单
|
|
||||||
QueryWrapper<OrderSwapBatteryPre> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<OrderSwapBatteryPre> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.ne("status", 4) // 无效
|
queryWrapper
|
||||||
|
.ne("status", 4)//无效
|
||||||
.ne("status", 3) //过期
|
.ne("status", 3) //过期
|
||||||
.isNotNull("reservation_time"); // 确保预约时间不为空
|
.ne("status", 2); //过期
|
||||||
|
|
||||||
List<OrderSwapBatteryPre> orderSwapBatteryPreList = orderSwapBatteryPreDao.selectList(queryWrapper);
|
List<OrderSwapBatteryPre> orderSwapBatteryPreList = orderSwapBatteryPreDao.selectList(queryWrapper);
|
||||||
|
|
||||||
@ -40,41 +40,23 @@ public class OrderSwapBatteryTask {
|
|||||||
int expiredCount = 0; // 记录过期的预约单数量
|
int expiredCount = 0; // 记录过期的预约单数量
|
||||||
|
|
||||||
for (OrderSwapBatteryPre order : orderSwapBatteryPreList) {
|
for (OrderSwapBatteryPre order : orderSwapBatteryPreList) {
|
||||||
// 计算时间差(毫秒)
|
// 检查预约时间是否已过期
|
||||||
long timeDiff = currentTime.getTime() - order.getReservationTime().getTime();
|
if (order.getReservationTime() != null && order.getReservationTime().before(currentTime)) {
|
||||||
// 24小时 = 24 * 60 * 60 * 1000 毫秒
|
|
||||||
if (timeDiff >= 24 * 60 * 60 * 1000) {
|
|
||||||
try {
|
|
||||||
// 更新状态为过期
|
// 更新状态为过期
|
||||||
order.setStatus(3); // 设置为过期状态
|
order.setStatus(4); // 设置为过期状态
|
||||||
order.setUptime(currentTime); // 更新修改时间
|
try {
|
||||||
orderSwapBatteryPreDao.updateById(order);
|
orderSwapBatteryPreDao.updateById(order);
|
||||||
|
//发送公众号过期提醒
|
||||||
|
//templateMessageService.orderMessageSend(order, 4);
|
||||||
expiredCount++;
|
expiredCount++;
|
||||||
|
log.info("预约单已过期,订单ID: {}", order.getSourceId()); // 记录过期的订单ID
|
||||||
log.info("预约单已过期 - 预约人: {}, 订单ID: {}, 预约时间: {}",
|
|
||||||
order.getUname(),
|
|
||||||
order.getPkId(),
|
|
||||||
DateUtil.format(order.getReservationTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("更新预约单状态失败 - 预约人: {}, 订单ID: {}, 预约时间: {}, 错误信息: {}",
|
log.error("更新预约单状态失败,预约人:{},订单ID: {}, 错误信息: {}",order.getUname(), order.getPkId(), e.getMessage());
|
||||||
order.getUname(),
|
|
||||||
order.getPkId(),
|
|
||||||
DateUtil.format(order.getReservationTime(), "yyyy-MM-dd HH:mm:ss"),
|
|
||||||
e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expiredCount > 0) {
|
log.info("\r\n===>>> 预约单过期:{} 条数据", expiredCount);
|
||||||
log.info("===>>> 本次处理过期预约单:{} 条", expiredCount);
|
|
||||||
} else {
|
|
||||||
log.info("===>>> 本次没有需要处理的过期预约单");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理过期预约单时发生异常: {}", e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,7 +92,6 @@ public class WechatPayServiceImpl implements WechatPayService {
|
|||||||
|
|
||||||
//检查账户是否存在
|
//检查账户是否存在
|
||||||
JSONObject entries = JSONUtil.parseObj(prePay.getAttach());
|
JSONObject entries = JSONUtil.parseObj(prePay.getAttach());
|
||||||
log.info("PrePayVO==================> {}",JSONUtil.parseObj(prePay));
|
|
||||||
if (!StringUtils.hasText(entries.getStr("walletCode"))) {
|
if (!StringUtils.hasText(entries.getStr("walletCode"))) {
|
||||||
Result<String> walleCode = cloudService.getWalleCode(prePay.getWuid());
|
Result<String> walleCode = cloudService.getWalleCode(prePay.getWuid());
|
||||||
if (!walleCode.getCode().equals(CodeMsg.SUCCESS.getCode())) {
|
if (!walleCode.getCode().equals(CodeMsg.SUCCESS.getCode())) {
|
||||||
@ -148,6 +147,8 @@ public class WechatPayServiceImpl implements WechatPayService {
|
|||||||
preOrder.setDeviceId(prePay.getDeviceId());
|
preOrder.setDeviceId(prePay.getDeviceId());
|
||||||
}
|
}
|
||||||
PrepayWithRequestPaymentResponse response = WechatPayUtil.jsapiPrepay(config, request);
|
PrepayWithRequestPaymentResponse response = WechatPayUtil.jsapiPrepay(config, request);
|
||||||
|
//判断是充值订单还是订单支付
|
||||||
|
|
||||||
// System.out.println("\r\n=====response>>>>>" + response);
|
// System.out.println("\r\n=====response>>>>>" + response);
|
||||||
// 写表
|
// 写表
|
||||||
BeanUtils.copyProperties(request, preOrder);
|
BeanUtils.copyProperties(request, preOrder);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user