Commit 898df538 by Wangmin

完善 陪诊员完成服务

parent 68cc5918
......@@ -159,5 +159,4 @@ public class AccompanyController extends BaseController {
public R<Boolean> updateAccompanyAddress(@Validated(EditGroup.class) @RequestBody AccompanyAddressBo bo) {
return R.ok(dbmyOrderService.updateAccompanyAddress(bo));
}
}
package com.pz.system.datastructure;
import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.bo.TotalOrderBo;
import com.pz.system.mapper.TotalOrderMapper;
import com.pz.system.service.ITotalOrderService;
import com.pz.system.service.IZqghOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
......@@ -13,38 +7,26 @@ import java.util.concurrent.DelayQueue;
@Component
public class OrderDelayQueue {
private final DelayQueue<TotalOrder> delayQueue = new DelayQueue<>();
@Autowired
private IZqghOrderService iZqghOrderService;
private final DelayQueue<TotalOrderDelayOperator> delayQueue = new DelayQueue<>();
// 添加订单到延时队列
public void addOrder(TotalOrder order) {
public void addOrder(TotalOrderDelayOperator order) {
delayQueue.put(order);
}
// 处理过期订单
@Scheduled(fixedDelay = 5000) // 每5秒触发一次任务
@Scheduled(fixedDelay = 30 * 60 * 1000) // 每30分钟触发一次任务
public void processExpiredOrders() {
long currentTime = System.currentTimeMillis();
while (true) {
TotalOrder order = delayQueue.peek();
TotalOrderDelayOperator order = delayQueue.peek();
if (order == null || order.getExpirationTime() > currentTime) {
break;
}
order = delayQueue.poll();
cancelOrder(order);
order.operator();
}
}
// 取消订单的逻辑
private void cancelOrder(TotalOrder order) {
TotalOrderBo totalOrderBo = new TotalOrderBo();
totalOrderBo.setId(order.getId());
// 执行取消订单的相关操作
iZqghOrderService.cancelOrder(totalOrderBo);
}
}
package com.pz.system.datastructure;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
* <p>created in 2023/9/15 14:55
*
* @author WangMin
* @version 1.0
*/
@Data
@Slf4j
public class TotalOrderDelayOperator implements Delayed {
/**
* 主订单ID
*/
private Long orderId;
public TotalOrderDelayOperator(Long orderId, long expirationTime, Consumer<Long> action) {
this.orderId = orderId;
this.expirationTime = expirationTime;
this.action = action;
}
/**
* 订单过期时间
*/
private long expirationTime;
/**
* 订单过期执行操作
*/
private Consumer<Long> action;
@Override
public long getDelay(@NotNull TimeUnit unit) {
// 计算订单到期时间和当前时间的时间差,并返回以指定时间单位表示的延迟时间
long diff = expirationTime - System.currentTimeMillis();
return unit.convert(diff, TimeUnit.MILLISECONDS);
}
@Override
public int compareTo(@NotNull Delayed o) {
// 比较订单到期时间先后顺序
return Long.compare(expirationTime, ((TotalOrderDelayOperator) o).getExpirationTime());
}
/**
* 订单过期操作
*/
public void operator() {
try {
if (action != null && orderId != null) {
action.accept(orderId);
}
} catch (Exception e) {
log.error("订单延迟任务执行失败 cause:{}", e.getMessage());
}
}
}
......@@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("total_order")
public class TotalOrder extends BaseEntity implements Delayed {
public class TotalOrder extends BaseEntity{
private static final long serialVersionUID = 1L;
......@@ -90,20 +90,4 @@ public class TotalOrder extends BaseEntity implements Delayed {
*/
@TableLogic
private String delFlag;
@TableField(exist = false)
private long expirationTime; // 订单过期时间
@Override
public long getDelay(@NotNull TimeUnit unit) {
// 计算订单到期时间和当前时间的时间差,并返回以指定时间单位表示的延迟时间
long diff = expirationTime - System.currentTimeMillis();
return unit.convert(diff, TimeUnit.MILLISECONDS);
}
@Override
public int compareTo(@NotNull Delayed o) {
// 比较订单到期时间先后顺序
return Long.compare(expirationTime, ((TotalOrder) o).expirationTime);
}
}
......@@ -145,5 +145,4 @@ public interface ITotalOrderService {
* @return
*/
Object selectLogisticsStatus(TotalOrderBo totalOrderBo);
}
......@@ -54,12 +54,6 @@ public interface IZqghOrderService {
*/
Boolean updateByBo(ZqghOrderBo bo);
/**
* 取消订单
* @param bo
* @return
*/
Boolean cancelOrder(TotalOrderBo bo);
/**
* 校验并批量删除诊前挂号订单信息
......
......@@ -14,6 +14,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService;
import com.pz.system.datastructure.OrderDelayQueue;
import com.pz.system.datastructure.TotalOrderDelayOperator;
import com.pz.system.domain.DbwzOrder;
import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.YypzOrder;
......@@ -33,6 +35,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 代办挂号订单Service业务层处理
......@@ -52,6 +55,9 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
/**
* 查询代办挂号订单
*/
......@@ -304,6 +310,13 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常");
}
// 子订单完成后,24小时后自动将主订单状态修改为完成
long expirationTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(24);
TotalOrderDelayOperator task = new TotalOrderDelayOperator(totalOrder.getId(), expirationTime, id -> {
totalOrderMapper.update(null,
Wrappers.<TotalOrder>lambdaUpdate().set(TotalOrder::getStatus, 2).eq(TotalOrder::getId, id));
});
delayQueue.addOrder(task);
return true;
}
}
......@@ -14,6 +14,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService;
import com.pz.system.datastructure.OrderDelayQueue;
import com.pz.system.datastructure.TotalOrderDelayOperator;
import com.pz.system.domain.DbwzOrder;
import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.YypzOrder;
......@@ -33,6 +35,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 代办买药订单Service业务层处理
......@@ -46,7 +49,7 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService
private final DbmyOrderMapper baseMapper;
private final TotalOrderMapper totalOrderMapper;
private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
/**
* 查询代办买药订单
......@@ -286,6 +289,13 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常");
}
// 子订单完成后,24小时后自动将主订单状态修改为完成
long expirationTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(24);
TotalOrderDelayOperator task = new TotalOrderDelayOperator(totalOrder.getId(), expirationTime, id -> {
totalOrderMapper.update(null,
Wrappers.<TotalOrder>lambdaUpdate().set(TotalOrder::getStatus, 2).eq(TotalOrder::getId, id));
});
delayQueue.addOrder(task);
return true;
}
}
......@@ -13,6 +13,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService;
import com.pz.system.datastructure.OrderDelayQueue;
import com.pz.system.datastructure.TotalOrderDelayOperator;
import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.YypzOrder;
import com.pz.system.domain.bo.OrderFinishedBo;
......@@ -31,6 +33,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 代办问诊订单Service业务层处理
......@@ -46,6 +49,7 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
private final UserVsitorMapper userVsitorMapper;
private final TotalOrderMapper totalOrderMapper;
private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
/**
* 查询代办问诊订单
......@@ -307,6 +311,13 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常");
}
// 子订单完成后,24小时后自动将主订单状态修改为完成
long expirationTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(24);
TotalOrderDelayOperator task = new TotalOrderDelayOperator(totalOrder.getId(), expirationTime, id -> {
totalOrderMapper.update(null,
Wrappers.<TotalOrder>lambdaUpdate().set(TotalOrder::getStatus, 2).eq(TotalOrder::getId, id));
});
delayQueue.addOrder(task);
return true;
}
}
......@@ -13,6 +13,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService;
import com.pz.system.datastructure.OrderDelayQueue;
import com.pz.system.datastructure.TotalOrderDelayOperator;
import com.pz.system.domain.DbwzOrder;
import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.bo.OrderFinishedBo;
......@@ -34,6 +36,7 @@ import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 预约陪诊订单Service业务层处理
......@@ -49,6 +52,7 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService
private final TotalOrderMapper totalOrderMapper;
private final UserVsitorMapper userVsitorMapper;
private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
/**
* 查询预约陪诊订单
......@@ -307,6 +311,13 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常");
}
// 子订单完成后,24小时后自动将主订单状态修改为完成
long expirationTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(24);
TotalOrderDelayOperator task = new TotalOrderDelayOperator(totalOrder.getId(), expirationTime, id -> {
totalOrderMapper.update(null,
Wrappers.<TotalOrder>lambdaUpdate().set(TotalOrder::getStatus, 2).eq(TotalOrder::getId, id));
});
delayQueue.addOrder(task);
return true;
}
}
......@@ -139,18 +139,6 @@ public class ZqghOrderServiceImpl implements IZqghOrderService, ISonOrderService
return baseMapper.updateById(update) > 0;
}
@Override
public Boolean cancelOrder(TotalOrderBo bo) {
TotalOrder totalOrder = totalOrderMapper.selectById(bo.getId());
if(totalOrder.getEmId() == 0){//预约陪诊
//yypzOrderMapper.selectOne(new LambdaQueryWrapper<YypzOrder>().eq(YypzOrder::getOrderId,totalOrder));
totalOrder.setStatus(TotalOrderStatus.CANCEL.getCode());
return totalOrderMapper.updateById(totalOrder) > 0;
}else {
throw new ServiceException("该订单已分配给陪诊员,不允许取消订单!");
}
}
/**
* 保存前的数据校验
*/
......
......@@ -13,6 +13,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService;
import com.pz.system.datastructure.OrderDelayQueue;
import com.pz.system.datastructure.TotalOrderDelayOperator;
import com.pz.system.domain.DbwzOrder;
import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.YypzOrder;
......@@ -34,6 +36,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 住院陪诊订单Service业务层处理
......@@ -49,6 +52,7 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
private final ZyphOrderMapper baseMapper;
private final TotalOrderMapper totalOrderMapper;
private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
private static final SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
......@@ -318,6 +322,13 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常");
}
// 子订单完成后,24小时后自动将主订单状态修改为完成
long expirationTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(24);
TotalOrderDelayOperator task = new TotalOrderDelayOperator(totalOrder.getId(), expirationTime, id -> {
totalOrderMapper.update(null,
Wrappers.<TotalOrder>lambdaUpdate().set(TotalOrder::getStatus, 2).eq(TotalOrder::getId, id));
});
delayQueue.addOrder(task);
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment