Commit 64d6368e by Wangmin

完善 取消订单业务

parent d1a52aea
...@@ -27,7 +27,7 @@ captcha: ...@@ -27,7 +27,7 @@ captcha:
# 开发环境配置 # 开发环境配置
server: server:
# 服务器的HTTP端口,默认为8080 # 服务器的HTTP端口,默认为8080
port: 9524 port: 8089
servlet: servlet:
# 应用的访问路径 # 应用的访问路径
context-path: / context-path: /
......
...@@ -49,7 +49,6 @@ public interface ISonOrderService { ...@@ -49,7 +49,6 @@ public interface ISonOrderService {
* @param totalId 取消订单 * @param totalId 取消订单
* @return 操作结果 * @return 操作结果
*/ */
default boolean accompanyCancellationOfOrder(Integer totalId){ boolean accompanyCancellationOfOrder(Integer totalId);
return true;}
} }
...@@ -194,11 +194,12 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService ...@@ -194,11 +194,12 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
if (dbghOrder.getVisitTime() != null) { if (dbghOrder.getVisitTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(dbghOrder.getVisitTime().toInstant(), ZoneId.systemDefault()); LocalDateTime visitTime = LocalDateTime.ofInstant(dbghOrder.getVisitTime().toInstant(), ZoneId.systemDefault());
LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault()); LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault());
// 若在18小时前取消订单,需记录取消次数
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
// 取消次数 // 取消次数
Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId)); Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
cancel = cancelCount == null ? 1 : cancelCount + 1; // 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
} }
} }
// 更新主订单数据 // 更新主订单数据
...@@ -215,7 +216,9 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService ...@@ -215,7 +216,9 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
// 若取消次数大于3,则冻结用户账号 // 若取消次数大于3,则冻结用户账号
if (cancel > 3) { if (cancel > 3) {
if (employeesMapper.update(null, if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate().set(Employees::getStatus, 2) Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder,cancel)
.eq(Employees::getId, emId)) < 0) { .eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败"); throw new ServiceException("用户冻结失败");
} }
......
...@@ -8,10 +8,17 @@ import com.pz.common.core.domain.PageQuery; ...@@ -8,10 +8,17 @@ import com.pz.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pz.common.exception.ServiceException;
import com.pz.common.utils.redis.RedisUtils;
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.service.ISonOrderService; import com.pz.merchant.service.ISonOrderService;
import com.pz.system.domain.DbwzOrder; import com.pz.system.domain.DbwzOrder;
import com.pz.system.domain.TotalOrder;
import com.pz.system.domain.YypzOrder;
import com.pz.system.domain.bo.AccompanyAddressBo; import com.pz.system.domain.bo.AccompanyAddressBo;
import com.pz.system.mapper.TotalOrderMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.pz.system.domain.bo.DbmyOrderBo; import com.pz.system.domain.bo.DbmyOrderBo;
...@@ -21,10 +28,10 @@ import com.pz.system.mapper.DbmyOrderMapper; ...@@ -21,10 +28,10 @@ import com.pz.system.mapper.DbmyOrderMapper;
import com.pz.system.service.IDbmyOrderService; import com.pz.system.service.IDbmyOrderService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.time.LocalDateTime;
import java.util.Map; import java.time.ZoneId;
import java.util.Collection; import java.time.temporal.ChronoUnit;
import java.util.Objects; import java.util.*;
/** /**
* 代办买药订单Service业务层处理 * 代办买药订单Service业务层处理
...@@ -37,6 +44,8 @@ import java.util.Objects; ...@@ -37,6 +44,8 @@ import java.util.Objects;
public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService { public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService {
private final DbmyOrderMapper baseMapper; private final DbmyOrderMapper baseMapper;
private final TotalOrderMapper totalOrderMapper;
private final EmployeesMapper employeesMapper;
/** /**
* 查询代办买药订单 * 查询代办买药订单
...@@ -180,4 +189,58 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService ...@@ -180,4 +189,58 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService
public Object getSonOrderDetailDataByTotalId(Integer totalId) { public Object getSonOrderDetailDataByTotalId(Integer totalId) {
return baseMapper.selectDbmyOrderDetailDataByTotalId(totalId); return baseMapper.selectDbmyOrderDetailDataByTotalId(totalId);
} }
/**
* 陪诊员取消代办买药订单
*
* @param totalId 取消订单
* @return 操作结果
*/
@Override
public boolean accompanyCancellationOfOrder(Integer totalId) {
TotalOrder totalOrder = totalOrderMapper.selectById(totalId);
Objects.requireNonNull(totalOrder, "主订单不存在");
Integer emId = totalOrder.getEmId();
if (emId == 0) {
throw new ServiceException("订单暂未分配陪诊员,拒绝该操作");
}
DbmyOrder dbmyOrder = baseMapper.selectOne(Wrappers.<DbmyOrder>lambdaQuery().eq(DbmyOrder::getOrderId, totalId));
Objects.requireNonNull(dbmyOrder, "子订单与主订单不一致!");
// 若设置了就诊时间,在取消订单时需要检查是否在18小时之前
int cancel = 0;
if (dbmyOrder.getOverTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(dbmyOrder.getOverTime().toInstant(), ZoneId.systemDefault());
LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault());
// 取消次数
Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
// 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
}
}
// 更新主订单数据
totalOrder.setEmId(0);
totalOrder.setSuborderStatus(0);
if (totalOrderMapper.updateById(totalOrder) < 0) {
throw new ServiceException("更新主订单失败");
}
// 更新子订单
dbmyOrder.setStatus(0);
if (baseMapper.updateById(dbmyOrder) < 0) {
throw new ServiceException("子订单更新失败");
}
// 若取消次数大于3,则冻结用户账号
if (cancel > 3) {
if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder,cancel)
.eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败");
}
}
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
return true;
}
} }
...@@ -196,11 +196,12 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService ...@@ -196,11 +196,12 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
if (dbwzOrder.getVisitTime() != null) { if (dbwzOrder.getVisitTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(dbwzOrder.getVisitTime().toInstant(), ZoneId.systemDefault()); LocalDateTime visitTime = LocalDateTime.ofInstant(dbwzOrder.getVisitTime().toInstant(), ZoneId.systemDefault());
LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault()); LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault());
// 若在18小时前取消订单,需记录取消次数
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
// 取消次数 // 取消次数
Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId)); Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
cancel = cancelCount == null ? 1 : cancelCount + 1; // 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
} }
} }
// 更新主订单数据 // 更新主订单数据
...@@ -217,7 +218,9 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService ...@@ -217,7 +218,9 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
// 若取消次数大于3,则冻结用户账号 // 若取消次数大于3,则冻结用户账号
if (cancel > 3) { if (cancel > 3) {
if (employeesMapper.update(null, if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate().set(Employees::getStatus, 2) Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder,cancel)
.eq(Employees::getId, emId)) < 0) { .eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败"); throw new ServiceException("用户冻结失败");
} }
......
...@@ -199,11 +199,12 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService ...@@ -199,11 +199,12 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService
if (yypzOrder.getVisitTime() != null) { if (yypzOrder.getVisitTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(yypzOrder.getVisitTime().toInstant(), ZoneId.systemDefault()); LocalDateTime visitTime = LocalDateTime.ofInstant(yypzOrder.getVisitTime().toInstant(), ZoneId.systemDefault());
LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault()); LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault());
// 若在18小时前取消订单,需记录取消次数
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
// 取消次数 // 取消次数
Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId)); Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
cancel = cancelCount == null ? 1 : cancelCount + 1; // 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
} }
} }
// 更新主订单数据 // 更新主订单数据
...@@ -220,7 +221,9 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService ...@@ -220,7 +221,9 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService
// 若取消次数大于3,则冻结用户账号 // 若取消次数大于3,则冻结用户账号
if (cancel > 3) { if (cancel > 3) {
if (employeesMapper.update(null, if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate().set(Employees::getStatus, 2) Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder,cancel)
.eq(Employees::getId, emId)) < 0) { .eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败"); throw new ServiceException("用户冻结失败");
} }
......
...@@ -153,4 +153,9 @@ public class ZqghOrderServiceImpl implements IZqghOrderService, ISonOrderService ...@@ -153,4 +153,9 @@ public class ZqghOrderServiceImpl implements IZqghOrderService, ISonOrderService
// return baseMapper.selectZqghOrderDetailDateByTotalId(totalId); // return baseMapper.selectZqghOrderDetailDateByTotalId(totalId);
return ISonOrderService.super.getSonOrderDetailDataByTotalId(totalId); return ISonOrderService.super.getSonOrderDetailDataByTotalId(totalId);
} }
@Override
public boolean accompanyCancellationOfOrder(Integer totalId) {
throw new UnsupportedOperationException("不支持该操作");
}
} }
...@@ -203,11 +203,12 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService ...@@ -203,11 +203,12 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
if (paseDateTime != null) { if (paseDateTime != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(paseDateTime.toInstant(), ZoneId.systemDefault()); LocalDateTime visitTime = LocalDateTime.ofInstant(paseDateTime.toInstant(), ZoneId.systemDefault());
LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault()); LocalDateTime currentDate = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault());
// 若在18小时前取消订单,需记录取消次数
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
// 取消次数 // 取消次数
Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId)); Integer cancelCount = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
cancel = cancelCount == null ? 1 : cancelCount + 1; // 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
} }
} }
// 更新主订单数据 // 更新主订单数据
...@@ -224,7 +225,9 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService ...@@ -224,7 +225,9 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
// 若取消次数大于3,则冻结用户账号 // 若取消次数大于3,则冻结用户账号
if (cancel > 3) { if (cancel > 3) {
if (employeesMapper.update(null, if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate().set(Employees::getStatus, 2) Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder, cancel)
.eq(Employees::getId, emId)) < 0) { .eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败"); throw new ServiceException("用户冻结失败");
} }
......
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