Commit 4c486c26 by Wangmin

完善 取消订单业务

parent 35f8479e
......@@ -179,6 +179,7 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
* @return 操作结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean accompanyCancellationOfOrder(Integer totalId) {
TotalOrder totalOrder = totalOrderMapper.selectById(totalId);
......@@ -190,14 +191,17 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
DbghOrder dbghOrder = baseMapper.selectOne(Wrappers.<DbghOrder>lambdaQuery().eq(DbghOrder::getOrderId, totalId));
Objects.requireNonNull(dbghOrder, "子订单与主订单不一致!");
// 若设置了就诊时间,在取消订单时需要检查是否在18小时之前
int cancel = 0;
if (dbghOrder.getVisitTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(dbghOrder.getVisitTime().toInstant(), ZoneId.systemDefault());
// 取消次数
Integer cancel = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
if (dbghOrder.getOverTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(dbghOrder.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));
// 若缓存为空,则查询数据表
if (cancel == null) {
// 此处可能会存在员工找不到的NullPointException
cancel = Optional.ofNullable(employeesMapper.selectById(emId).getKillOrder()).orElse(0);
}
// 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
}
......@@ -214,16 +218,19 @@ public class DbghOrderServiceImpl implements IDbghOrderService, ISonOrderService
throw new ServiceException("子订单更新失败");
}
// 若取消次数大于3,则冻结用户账号
if (cancel > 3) {
if (cancel != null && cancel > 3) {
if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder,cancel)
.set(Employees::getKillOrder, cancel)
.eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败");
}
}
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
// 防止NUllPointException
if (cancel != null) {
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
}
return true;
}
}
......@@ -197,6 +197,7 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService
* @return 操作结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean accompanyCancellationOfOrder(Integer totalId) {
TotalOrder totalOrder = totalOrderMapper.selectById(totalId);
Objects.requireNonNull(totalOrder, "主订单不存在");
......@@ -207,14 +208,16 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService
DbmyOrder dbmyOrder = baseMapper.selectOne(Wrappers.<DbmyOrder>lambdaQuery().eq(DbmyOrder::getOrderId, totalId));
Objects.requireNonNull(dbmyOrder, "子订单与主订单不一致!");
// 若设置了就诊时间,在取消订单时需要检查是否在18小时之前
int cancel = 0;
// 取消次数
Integer cancel = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
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));
// 若缓存为空,则查询数据表
if (cancel == null) {
cancel = Optional.ofNullable(employeesMapper.selectById(emId).getKillOrder()).orElse(0);
}
// 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
}
......@@ -231,16 +234,18 @@ public class DbmyOrderServiceImpl implements IDbmyOrderService, ISonOrderService
throw new ServiceException("子订单更新失败");
}
// 若取消次数大于3,则冻结用户账号
if (cancel > 3) {
if (cancel != null && cancel > 3) {
if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder,cancel)
.set(Employees::getKillOrder, cancel)
.eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败");
}
}
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
if (cancel != null) {
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
}
return true;
}
}
......@@ -182,6 +182,7 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
* @return 操作结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean accompanyCancellationOfOrder(Integer totalId) {
TotalOrder totalOrder = totalOrderMapper.selectById(totalId);
Objects.requireNonNull(totalOrder, "主订单不存在");
......@@ -192,14 +193,16 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
DbwzOrder dbwzOrder = baseMapper.selectOne(Wrappers.<DbwzOrder>lambdaQuery().eq(DbwzOrder::getOrderId, totalId));
Objects.requireNonNull(dbwzOrder, "子订单与主订单不一致!");
// 若设置了就诊时间,在取消订单时需要检查是否在18小时之前
int cancel = 0;
if (dbwzOrder.getVisitTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(dbwzOrder.getVisitTime().toInstant(), ZoneId.systemDefault());
// 取消次数
Integer cancel = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
if (dbwzOrder.getOverTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(dbwzOrder.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));
// 若缓存为空,则查询数据表
if (cancel == null) {
cancel = Optional.ofNullable(employeesMapper.selectById(emId).getKillOrder()).orElse(0);
}
// 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
}
......@@ -216,16 +219,18 @@ public class DbwzOrderServiceImpl implements IDbwzOrderService, ISonOrderService
throw new ServiceException("子订单更新失败");
}
// 若取消次数大于3,则冻结用户账号
if (cancel > 3) {
if (cancel != null && cancel > 3) {
if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder,cancel)
.set(Employees::getKillOrder, cancel)
.eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败");
}
}
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
if (cancel != null) {
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
}
return true;
}
}
......@@ -195,14 +195,16 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService
YypzOrder yypzOrder = baseMapper.selectOne(Wrappers.<YypzOrder>lambdaQuery().eq(YypzOrder::getOrderId, totalId));
Objects.requireNonNull(yypzOrder, "子订单与主订单不一致!");
// 若设置了就诊时间,在取消订单时需要检查是否在18小时之前
int cancel = 0;
if (yypzOrder.getVisitTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(yypzOrder.getVisitTime().toInstant(), ZoneId.systemDefault());
// 取消次数
Integer cancel = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
if (yypzOrder.getOverTime() != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(yypzOrder.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));
// 若缓存为空,则查询数据表
if (cancel == null) {
cancel = Optional.ofNullable(employeesMapper.selectById(emId).getKillOrder()).orElse(0);
}
// 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
}
......@@ -219,16 +221,18 @@ public class YypzOrderServiceImpl implements IYypzOrderService, ISonOrderService
throw new ServiceException("子订单更新失败");
}
// 若取消次数大于3,则冻结用户账号
if (cancel > 3) {
if (cancel != null && cancel > 3) {
if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
.set(Employees::getKillOrder,cancel)
.set(Employees::getKillOrder, cancel)
.eq(Employees::getId, emId)) < 0) {
throw new ServiceException("用户冻结失败");
}
}
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
if (cancel != null) {
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
}
return true;
}
}
......@@ -182,6 +182,7 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
* @return 操作结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean accompanyCancellationOfOrder(Integer totalId) {
TotalOrder totalOrder = totalOrderMapper.selectById(totalId);
Objects.requireNonNull(totalOrder, "主订单不存在");
......@@ -191,8 +192,6 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
}
ZyphOrder zyphOrder = baseMapper.selectOne(Wrappers.<ZyphOrder>lambdaQuery().eq(ZyphOrder::getOrderId, totalId));
Objects.requireNonNull(zyphOrder, "子订单与主订单不一致!");
// 若设置了就诊时间,在取消订单时需要检查是否在18小时之前
int cancel = 0;
String dateTimeStr = zyphOrder.getStartDay() + " " + zyphOrder.getEndTime();
Date paseDateTime = null;
try {
......@@ -200,13 +199,16 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
} catch (ParseException e) {
log.error("时间解析失败");
}
// 取消次数
Integer cancel = RedisUtils.<Integer>getCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId));
if (paseDateTime != null) {
LocalDateTime visitTime = LocalDateTime.ofInstant(paseDateTime.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));
// 若缓存为空,则查询数据表
if (cancel == null) {
cancel = Optional.ofNullable(employeesMapper.selectById(emId).getKillOrder()).orElse(0);
}
// 若在18小时前取消订单,需记录取消次数
cancel = cancelCount == null ? 1: cancelCount + 1;
if (visitTime.isBefore(currentDate) || ChronoUnit.HOURS.between(visitTime, currentDate) <= 18) {
cancel++;
}
......@@ -223,7 +225,7 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
throw new ServiceException("子订单更新失败");
}
// 若取消次数大于3,则冻结用户账号
if (cancel > 3) {
if (cancel != null && cancel > 3) {
if (employeesMapper.update(null,
Wrappers.<Employees>lambdaUpdate()
.set(Employees::getStatus, 2)
......@@ -232,7 +234,9 @@ public class ZyphOrderServiceImpl implements IZyphOrderService, ISonOrderService
throw new ServiceException("用户冻结失败");
}
}
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
if (cancel != null) {
RedisUtils.setCacheMapValue(ISonOrderService.ORDER_CANCEL_CACHE_PREFIX, String.valueOf(emId), cancel);
}
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