Commit 898df538 by Wangmin

完善 陪诊员完成服务

parent 68cc5918
...@@ -159,5 +159,4 @@ public class AccompanyController extends BaseController { ...@@ -159,5 +159,4 @@ public class AccompanyController extends BaseController {
public R<Boolean> updateAccompanyAddress(@Validated(EditGroup.class) @RequestBody AccompanyAddressBo bo) { public R<Boolean> updateAccompanyAddress(@Validated(EditGroup.class) @RequestBody AccompanyAddressBo bo) {
return R.ok(dbmyOrderService.updateAccompanyAddress(bo)); return R.ok(dbmyOrderService.updateAccompanyAddress(bo));
} }
} }
package com.pz.system.datastructure; 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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -13,38 +7,26 @@ import java.util.concurrent.DelayQueue; ...@@ -13,38 +7,26 @@ import java.util.concurrent.DelayQueue;
@Component @Component
public class OrderDelayQueue { public class OrderDelayQueue {
private final DelayQueue<TotalOrder> delayQueue = new DelayQueue<>(); private final DelayQueue<TotalOrderDelayOperator> delayQueue = new DelayQueue<>();
@Autowired
private IZqghOrderService iZqghOrderService;
// 添加订单到延时队列 // 添加订单到延时队列
public void addOrder(TotalOrder order) { public void addOrder(TotalOrderDelayOperator order) {
delayQueue.put(order); delayQueue.put(order);
} }
// 处理过期订单 // 处理过期订单
@Scheduled(fixedDelay = 5000) // 每5秒触发一次任务 @Scheduled(fixedDelay = 30 * 60 * 1000) // 每30分钟触发一次任务
public void processExpiredOrders() { public void processExpiredOrders() {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
while (true) { while (true) {
TotalOrder order = delayQueue.peek(); TotalOrderDelayOperator order = delayQueue.peek();
if (order == null || order.getExpirationTime() > currentTime) { if (order == null || order.getExpirationTime() > currentTime) {
break; break;
} }
order = delayQueue.poll(); 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; ...@@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName("total_order") @TableName("total_order")
public class TotalOrder extends BaseEntity implements Delayed { public class TotalOrder extends BaseEntity{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -90,20 +90,4 @@ public class TotalOrder extends BaseEntity implements Delayed { ...@@ -90,20 +90,4 @@ public class TotalOrder extends BaseEntity implements Delayed {
*/ */
@TableLogic @TableLogic
private String delFlag; 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 { ...@@ -145,5 +145,4 @@ public interface ITotalOrderService {
* @return * @return
*/ */
Object selectLogisticsStatus(TotalOrderBo totalOrderBo); Object selectLogisticsStatus(TotalOrderBo totalOrderBo);
} }
...@@ -54,12 +54,6 @@ public interface IZqghOrderService { ...@@ -54,12 +54,6 @@ public interface IZqghOrderService {
*/ */
Boolean updateByBo(ZqghOrderBo bo); Boolean updateByBo(ZqghOrderBo bo);
/**
* 取消订单
* @param bo
* @return
*/
Boolean cancelOrder(TotalOrderBo bo);
/** /**
* 校验并批量删除诊前挂号订单信息 * 校验并批量删除诊前挂号订单信息
......
...@@ -14,6 +14,8 @@ import com.pz.merchant.domain.Employees; ...@@ -14,6 +14,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo; import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper; import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService; 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.DbwzOrder;
import com.pz.system.domain.TotalOrder; import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.YypzOrder; import com.pz.system.domain.YypzOrder;
...@@ -33,6 +35,7 @@ import java.time.LocalDateTime; ...@@ -33,6 +35,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* 代办挂号订单Service业务层处理 * 代办挂号订单Service业务层处理
...@@ -52,6 +55,9 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService ...@@ -52,6 +55,9 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
private final EmployeesMapper employeesMapper; private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
/** /**
* 查询代办挂号订单 * 查询代办挂号订单
*/ */
...@@ -304,6 +310,13 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService ...@@ -304,6 +310,13 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) { if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常"); 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; return true;
} }
} }
...@@ -14,6 +14,8 @@ import com.pz.merchant.domain.Employees; ...@@ -14,6 +14,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo; import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper; import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService; 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.DbwzOrder;
import com.pz.system.domain.TotalOrder; import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.YypzOrder; import com.pz.system.domain.YypzOrder;
...@@ -33,6 +35,7 @@ import java.time.LocalDateTime; ...@@ -33,6 +35,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* 代办买药订单Service业务层处理 * 代办买药订单Service业务层处理
...@@ -46,7 +49,7 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService ...@@ -46,7 +49,7 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService
private final DbmyOrderMapper baseMapper; private final DbmyOrderMapper baseMapper;
private final TotalOrderMapper totalOrderMapper; private final TotalOrderMapper totalOrderMapper;
private final EmployeesMapper employeesMapper; private final OrderDelayQueue delayQueue;
/** /**
* 查询代办买药订单 * 查询代办买药订单
...@@ -286,6 +289,13 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService ...@@ -286,6 +289,13 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) { if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常"); 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; return true;
} }
} }
...@@ -13,6 +13,8 @@ import com.pz.merchant.domain.Employees; ...@@ -13,6 +13,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo; import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper; import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService; 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.TotalOrder;
import com.pz.system.domain.YypzOrder; import com.pz.system.domain.YypzOrder;
import com.pz.system.domain.bo.OrderFinishedBo; import com.pz.system.domain.bo.OrderFinishedBo;
...@@ -31,6 +33,7 @@ import java.time.LocalDateTime; ...@@ -31,6 +33,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* 代办问诊订单Service业务层处理 * 代办问诊订单Service业务层处理
...@@ -46,6 +49,7 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService ...@@ -46,6 +49,7 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
private final UserVsitorMapper userVsitorMapper; private final UserVsitorMapper userVsitorMapper;
private final TotalOrderMapper totalOrderMapper; private final TotalOrderMapper totalOrderMapper;
private final EmployeesMapper employeesMapper; private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
/** /**
* 查询代办问诊订单 * 查询代办问诊订单
...@@ -307,6 +311,13 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService ...@@ -307,6 +311,13 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) { if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常"); 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; return true;
} }
} }
...@@ -28,6 +28,7 @@ import com.pz.merchant.service.ISonOrderService; ...@@ -28,6 +28,7 @@ import com.pz.merchant.service.ISonOrderService;
import com.pz.merchant.service.impl.SonOrderServiceBuilder; import com.pz.merchant.service.impl.SonOrderServiceBuilder;
import com.pz.common.helper.LoginHelper; import com.pz.common.helper.LoginHelper;
import com.pz.system.datastructure.OrderDelayQueue; import com.pz.system.datastructure.OrderDelayQueue;
import com.pz.system.datastructure.TotalOrderDelayOperator;
import com.pz.system.domain.*; import com.pz.system.domain.*;
import com.pz.system.domain.bo.CreateOrderBo; import com.pz.system.domain.bo.CreateOrderBo;
import com.pz.system.domain.vo.AccompanyDemandVo; import com.pz.system.domain.vo.AccompanyDemandVo;
...@@ -44,6 +45,7 @@ import com.pz.system.domain.bo.TotalOrderBo; ...@@ -44,6 +45,7 @@ import com.pz.system.domain.bo.TotalOrderBo;
import com.pz.system.domain.vo.TotalOrderVo; import com.pz.system.domain.vo.TotalOrderVo;
import com.pz.system.service.ITotalOrderService; import com.pz.system.service.ITotalOrderService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Map; import java.util.Map;
...@@ -129,7 +131,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -129,7 +131,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
totalOrderVo.setServiceStatus( totalOrderVo.setServiceStatus(
yypzOrder.getStatus() yypzOrder.getStatus()
); );
//totalOrderVo = BeanUtil.toBean(yypzOrder, TotalOrderVo.class); // totalOrderVo = BeanUtil.toBean(yypzOrder, TotalOrderVo.class);
totalOrderVo.setHospital(hospitalMapper.selectById(yypzOrder.getHid()).getName()); totalOrderVo.setHospital(hospitalMapper.selectById(yypzOrder.getHid()).getName());
totalOrderVo.setVisitor(userVsitorMapper.selectById(yypzOrder.getVisitor()).getName()); totalOrderVo.setVisitor(userVsitorMapper.selectById(yypzOrder.getVisitor()).getName());
totalOrderVo.setDepartment(departmentMapper.selectById(yypzOrder.getDid()).getTitle()); totalOrderVo.setDepartment(departmentMapper.selectById(yypzOrder.getDid()).getTitle());
...@@ -145,7 +147,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -145,7 +147,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
totalOrderVo.setServiceStatus( totalOrderVo.setServiceStatus(
dbghOrder.getStatus() dbghOrder.getStatus()
); );
//totalOrderVo = BeanUtil.toBean(dbghOrder, TotalOrderVo.class); // totalOrderVo = BeanUtil.toBean(dbghOrder, TotalOrderVo.class);
totalOrderVo.setHospital(hospitalMapper.selectById(dbghOrder.getHid()).getName()); totalOrderVo.setHospital(hospitalMapper.selectById(dbghOrder.getHid()).getName());
totalOrderVo.setDepartment(departmentMapper.selectById(dbghOrder.getDid()).getTitle()); totalOrderVo.setDepartment(departmentMapper.selectById(dbghOrder.getDid()).getTitle());
totalOrderVo.setVisitor(userVsitorMapper.selectById(dbghOrder.getVisitor()).getName()); totalOrderVo.setVisitor(userVsitorMapper.selectById(dbghOrder.getVisitor()).getName());
...@@ -154,14 +156,13 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -154,14 +156,13 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
totalOrderVo.setVoucher(dbghOrder.getVoucher()); totalOrderVo.setVoucher(dbghOrder.getVoucher());
} else if (totalOrderVo.getBusinessId() == 3) {// 代办问诊 } else if (totalOrderVo.getBusinessId() == 3) {// 代办问诊
DbwzOrder dbwzOrder = dbwzOrderMapper.selectOne(new LambdaQueryWrapper<DbwzOrder>().eq(DbwzOrder::getOrderId, totalOrderVo.getId())); DbwzOrder dbwzOrder = dbwzOrderMapper.selectOne(new LambdaQueryWrapper<DbwzOrder>().eq(DbwzOrder::getOrderId, totalOrderVo.getId()));
totalOrderVo.setServiceStatus( totalOrderVo.setServiceStatus(
dbwzOrder.getStatus() dbwzOrder.getStatus()
); );
//totalOrderVo = BeanUtil.toBean(dbwzOrder, TotalOrderVo.class); // totalOrderVo = BeanUtil.toBean(dbwzOrder, TotalOrderVo.class);
totalOrderVo.setDepartment(departmentMapper.selectById(dbwzOrder.getDid()).getTitle()); totalOrderVo.setDepartment(departmentMapper.selectById(dbwzOrder.getDid()).getTitle());
totalOrderVo.setVisitor(userVsitorMapper.selectById(dbwzOrder.getVisitor()).getName()); totalOrderVo.setVisitor(userVsitorMapper.selectById(dbwzOrder.getVisitor()).getName());
totalOrderVo.setVisitTime(dbwzOrder.getVisitTime()); totalOrderVo.setVisitTime(dbwzOrder.getVisitTime());
...@@ -182,12 +183,12 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -182,12 +183,12 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
totalOrderVo.setServiceStatus( totalOrderVo.setServiceStatus(
zyphOrder.getStatus() zyphOrder.getStatus()
); );
//totalOrderVo = BeanUtil.toBean(zyphOrder, TotalOrderVo.class); // totalOrderVo = BeanUtil.toBean(zyphOrder, TotalOrderVo.class);
totalOrderVo.setHospital(hospitalMapper.selectById(zyphOrder.getHid()).getName()); totalOrderVo.setHospital(hospitalMapper.selectById(zyphOrder.getHid()).getName());
totalOrderVo.setVisitor(userVsitorMapper.selectById(zyphOrder.getVisitor()).getName()); totalOrderVo.setVisitor(userVsitorMapper.selectById(zyphOrder.getVisitor()).getName());
totalOrderVo.setDepartment(departmentMapper.selectById(zyphOrder.getDid()).getTitle()); totalOrderVo.setDepartment(departmentMapper.selectById(zyphOrder.getDid()).getTitle());
totalOrderVo.setPhrq(zyphOrder.getStartDay()+"-"+zyphOrder.getEndDay()); totalOrderVo.setPhrq(zyphOrder.getStartDay() + "-" + zyphOrder.getEndDay());
totalOrderVo.setPhsj(zyphOrder.getStartTime()+"-"+zyphOrder.getEndTime()); totalOrderVo.setPhsj(zyphOrder.getStartTime() + "-" + zyphOrder.getEndTime());
totalOrderVo.setOverTime(zyphOrder.getOverTime()); totalOrderVo.setOverTime(zyphOrder.getOverTime());
totalOrderVo.setVoucher(zyphOrder.getVoucher()); totalOrderVo.setVoucher(zyphOrder.getVoucher());
...@@ -267,7 +268,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -267,7 +268,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
// 服务封面 // 服务封面
Services services = servicesMapper.selectById(totalOrderVo.getServiceId()); Services services = servicesMapper.selectById(totalOrderVo.getServiceId());
if(null != services){ if (null != services) {
totalOrderVo.setCover(services.getCover()); totalOrderVo.setCover(services.getCover());
} }
...@@ -391,14 +392,21 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -391,14 +392,21 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
// 计算订单过期时间(当前时间加上30分钟) // 计算订单过期时间(当前时间加上30分钟)
long expirationTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(24); long expirationTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(24);
totalOrder.setExpirationTime(expirationTime);
// 未付款的订单延迟24小时自动取消 // 未付款的订单延迟24小时自动取消
delayQueue.addOrder(totalOrder); TotalOrderDelayOperator totalOrderDelayOperator = new TotalOrderDelayOperator(totalOrder.getId(), expirationTime, id -> {
TotalOrder order = baseMapper.selectById(id);
if (order.getEmId() == 0) {// 预约陪诊
order.setStatus(TotalOrderStatus.CANCEL.getCode());
baseMapper.updateById(totalOrder);
} else {
throw new ServiceException("该订单已分配给陪诊员,不允许取消订单!");
}
});
delayQueue.addOrder(totalOrderDelayOperator);
if (bo.getBusinessId() == 1) {// 预约陪诊 if (bo.getBusinessId() == 1) {// 预约陪诊
YypzOrder yypzOrder = BeanUtil.toBean(bo, YypzOrder.class); YypzOrder yypzOrder = BeanUtil.toBean(bo, YypzOrder.class);
yypzOrder.setHid(bo.getHospitalId()); yypzOrder.setHid(bo.getHospitalId());
yypzOrder.setDid(bo.getDepartmentId()); yypzOrder.setDid(bo.getDepartmentId());
...@@ -466,8 +474,8 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -466,8 +474,8 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
@Override @Override
public Boolean cancelOrder(TotalOrderBo bo) { public Boolean cancelOrder(TotalOrderBo bo) {
TotalOrder totalOrder = baseMapper.selectById(bo.getId()); TotalOrder totalOrder = baseMapper.selectById(bo.getId());
if(totalOrder.getEmId() == 0){//预约陪诊 if (totalOrder.getEmId() == 0) {// 预约陪诊
//yypzOrderMapper.selectOne(new LambdaQueryWrapper<YypzOrder>().eq(YypzOrder::getOrderId,totalOrder)); // yypzOrderMapper.selectOne(new LambdaQueryWrapper<YypzOrder>().eq(YypzOrder::getOrderId,totalOrder));
totalOrder.setStatus(TotalOrderStatus.CANCEL.getCode()); totalOrder.setStatus(TotalOrderStatus.CANCEL.getCode());
return baseMapper.updateById(totalOrder) > 0; return baseMapper.updateById(totalOrder) > 0;
} else { } else {
...@@ -513,11 +521,11 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -513,11 +521,11 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
public boolean orderPayCallBack(WxPayOrderNotifyResult result) { public boolean orderPayCallBack(WxPayOrderNotifyResult result) {
String orderNum = result.getOutTradeNo(); String orderNum = result.getOutTradeNo();
TotalOrder totalOrder = baseMapper.selectOne(new LambdaQueryWrapper<TotalOrder>().eq(TotalOrder::getOrderSn, orderNum)); TotalOrder totalOrder = baseMapper.selectOne(new LambdaQueryWrapper<TotalOrder>().eq(TotalOrder::getOrderSn, orderNum));
if(totalOrder.getStatus() == 0){ if (totalOrder.getStatus() == 0) {
//修改订单状态为已支付 // 修改订单状态为已支付
totalOrder.setStatus(1); totalOrder.setStatus(1);
baseMapper.updateById(totalOrder); baseMapper.updateById(totalOrder);
//添加支付记录 // 添加支付记录
PaymentRecord paymentRecord = new PaymentRecord(); PaymentRecord paymentRecord = new PaymentRecord();
paymentRecord.setPayType(0); paymentRecord.setPayType(0);
paymentRecord.setOrderId(totalOrder.getId().intValue()); paymentRecord.setOrderId(totalOrder.getId().intValue());
...@@ -533,13 +541,13 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -533,13 +541,13 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
public boolean orderRefundCallBack(WxPayRefundNotifyResult wxPayRefundNotifyResult) { public boolean orderRefundCallBack(WxPayRefundNotifyResult wxPayRefundNotifyResult) {
WxPayRefundNotifyResult.ReqInfo reqInfo = wxPayRefundNotifyResult.getReqInfo(); WxPayRefundNotifyResult.ReqInfo reqInfo = wxPayRefundNotifyResult.getReqInfo();
//订单号 // 订单号
String outTradeNo = reqInfo.getOutTradeNo(); String outTradeNo = reqInfo.getOutTradeNo();
TotalOrder totalOrder = baseMapper.selectOne(new LambdaQueryWrapper<TotalOrder>().eq(TotalOrder::getOrderSn, outTradeNo)); TotalOrder totalOrder = baseMapper.selectOne(new LambdaQueryWrapper<TotalOrder>().eq(TotalOrder::getOrderSn, outTradeNo));
totalOrder.setStatus(TotalOrderStatus.REFUND.getCode()); totalOrder.setStatus(TotalOrderStatus.REFUND.getCode());
if(baseMapper.updateById(totalOrder) > 0){ if (baseMapper.updateById(totalOrder) > 0) {
//添加退款记录 // 添加退款记录
PaymentRecord paymentRecord = new PaymentRecord(); PaymentRecord paymentRecord = new PaymentRecord();
paymentRecord.setPayType(1); paymentRecord.setPayType(1);
paymentRecord.setOrderId(totalOrder.getId().intValue()); paymentRecord.setOrderId(totalOrder.getId().intValue());
...@@ -769,6 +777,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -769,6 +777,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
return true; return true;
} }
/** /**
* 查询订单信息 * 查询订单信息
* *
...@@ -798,7 +807,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -798,7 +807,7 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
String path = "/api"; String path = "/api";
String requestMethod = "POST"; String requestMethod = "POST";
Map<String, String> headers = new HashMap<String, String>(); Map<String, String> headers = new HashMap<String, String>();
//根据API的要求,定义相对应的Content-Type // 根据API的要求,定义相对应的Content-Type
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map<String, String> querys = new HashMap<String, String>(); Map<String, String> querys = new HashMap<String, String>();
Map<String, String> bodys = new HashMap<String, String>(); Map<String, String> bodys = new HashMap<String, String>();
...@@ -819,10 +828,10 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -819,10 +828,10 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
bodys.put("sign", sign); bodys.put("sign", sign);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
Map<String, String> data = new HashMap<String, String>(); Map<String, String> data = new HashMap<String, String>();
data.put("waybill_codes",totalOrderBo.getLogisticsCode()); data.put("waybill_codes", totalOrderBo.getLogisticsCode());
data.put("result_sort","0"); data.put("result_sort", "0");
if(null != totalOrderBo.getPhone() && !totalOrderBo.getPhone().equals("")){ if (null != totalOrderBo.getPhone() && !totalOrderBo.getPhone().equals("")) {
data.put("phone","1"); data.put("phone", "1");
} }
String jsonStr = null; String jsonStr = null;
try { try {
...@@ -879,12 +888,13 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -879,12 +888,13 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
} }
return numberList; return numberList;
} }
// 计算md5 // 计算md5
public static String getMD5(String plainText, int length) { public static String getMD5(String plainText, int length) {
try { try {
MessageDigest md = MessageDigest.getInstance("MD5");//获取MD5实例 MessageDigest md = MessageDigest.getInstance("MD5");// 获取MD5实例
md.update(plainText.getBytes());//此处传入要加密的byte类型值 md.update(plainText.getBytes());// 此处传入要加密的byte类型值
byte[] digest = md.digest();//此处得到的是md5加密后的byte类型值 byte[] digest = md.digest();// 此处得到的是md5加密后的byte类型值
/* /*
下边的运算就是自己添加的一些二次小加密,记住这个千万不能弄错乱, 下边的运算就是自己添加的一些二次小加密,记住这个千万不能弄错乱,
...@@ -901,9 +911,9 @@ public class TotalOrderServiceImpl implements ITotalOrderService { ...@@ -901,9 +911,9 @@ public class TotalOrderServiceImpl implements ITotalOrderService {
i += 256; i += 256;
if (i < 16) if (i < 16)
sb.append(0); sb.append(0);
sb.append(Integer.toHexString(i));//通过Integer.toHexString方法把值变为16进制 sb.append(Integer.toHexString(i));// 通过Integer.toHexString方法把值变为16进制
} }
return sb.toString().substring(0, length);//从下标0开始,length目的是截取多少长度的值 return sb.toString().substring(0, length);// 从下标0开始,length目的是截取多少长度的值
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
......
...@@ -13,6 +13,8 @@ import com.pz.merchant.domain.Employees; ...@@ -13,6 +13,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo; import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper; import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService; 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.DbwzOrder;
import com.pz.system.domain.TotalOrder; import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.bo.OrderFinishedBo; import com.pz.system.domain.bo.OrderFinishedBo;
...@@ -34,6 +36,7 @@ import java.time.ZoneId; ...@@ -34,6 +36,7 @@ import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* 预约陪诊订单Service业务层处理 * 预约陪诊订单Service业务层处理
...@@ -49,6 +52,7 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService ...@@ -49,6 +52,7 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService
private final TotalOrderMapper totalOrderMapper; private final TotalOrderMapper totalOrderMapper;
private final UserVsitorMapper userVsitorMapper; private final UserVsitorMapper userVsitorMapper;
private final EmployeesMapper employeesMapper; private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
/** /**
* 查询预约陪诊订单 * 查询预约陪诊订单
...@@ -307,6 +311,13 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService ...@@ -307,6 +311,13 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) { if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常"); 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; return true;
} }
} }
...@@ -139,18 +139,6 @@ public class ZqghOrderServiceImpl implements IZqghOrderService, ISonOrderService ...@@ -139,18 +139,6 @@ public class ZqghOrderServiceImpl implements IZqghOrderService, ISonOrderService
return baseMapper.updateById(update) > 0; 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; ...@@ -13,6 +13,8 @@ import com.pz.merchant.domain.Employees;
import com.pz.merchant.domain.vo.SonOrderVo; import com.pz.merchant.domain.vo.SonOrderVo;
import com.pz.merchant.mapper.EmployeesMapper; import com.pz.merchant.mapper.EmployeesMapper;
import com.pz.merchant.service.ISonOrderService; 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.DbwzOrder;
import com.pz.system.domain.TotalOrder; import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.YypzOrder; import com.pz.system.domain.YypzOrder;
...@@ -34,6 +36,7 @@ import java.time.LocalDateTime; ...@@ -34,6 +36,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* 住院陪诊订单Service业务层处理 * 住院陪诊订单Service业务层处理
...@@ -49,6 +52,7 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService ...@@ -49,6 +52,7 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
private final ZyphOrderMapper baseMapper; private final ZyphOrderMapper baseMapper;
private final TotalOrderMapper totalOrderMapper; private final TotalOrderMapper totalOrderMapper;
private final EmployeesMapper employeesMapper; private final EmployeesMapper employeesMapper;
private final OrderDelayQueue delayQueue;
private static final SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static final SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
...@@ -318,6 +322,13 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService ...@@ -318,6 +322,13 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
if (totalOrderMapper.updateById(totalOrder) < 0) { if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("操作失败,主订单异常"); 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; 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