Commit 680cbd7e by wuwenlong

order status opt;

parent 81bbee19
...@@ -8,9 +8,7 @@ public enum OrderStatusEnum { ...@@ -8,9 +8,7 @@ public enum OrderStatusEnum {
UNUSED(0,"待使用/已预约"), UNUSED(0,"待使用/已预约"),
INUSE(1,"使用中"), INUSE(1,"使用中"),
USED(2,"已使用"), USED(2,"已使用"),
CANCEL(3,"已取消"), CANCEL(3,"已取消");
AUDIT(4,"审核中"),
REFUNDED(5,"已退款");
private Integer code; private Integer code;
...@@ -30,6 +28,7 @@ public enum OrderStatusEnum { ...@@ -30,6 +28,7 @@ public enum OrderStatusEnum {
return null; return null;
} }
public Integer getCode(){ public Integer getCode(){
return code; return code;
} }
......
...@@ -5,8 +5,8 @@ package share.common.enums; ...@@ -5,8 +5,8 @@ package share.common.enums;
* @Date 2023/10/18 17:33 * @Date 2023/10/18 17:33
*/ */
public enum RoomStatusEnum { public enum RoomStatusEnum {
FREE(1,"空闲"), FREE(0,"空闲"),
HOLD(2,"占用"); HOLD(1,"占用");
private Integer value; private Integer value;
private String name; private String name;
......
...@@ -13,20 +13,14 @@ import org.springframework.transaction.support.TransactionTemplate; ...@@ -13,20 +13,14 @@ import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import share.common.constant.Constants; import share.common.constant.Constants;
import share.common.core.redis.RedisUtil; import share.common.core.redis.RedisUtil;
import share.common.enums.CouponStatusEnum; import share.common.enums.*;
import share.common.enums.OrderStatusEnum;
import share.common.enums.RefundStatusEnum;
import share.common.enums.YesNoEnum;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import share.system.domain.SConsumer; import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon; import share.system.domain.SConsumerCoupon;
import share.system.domain.SOrder; import share.system.domain.SOrder;
import share.system.domain.SRoom; import share.system.domain.SRoom;
import share.system.mapper.SRoomMapper; import share.system.mapper.SRoomMapper;
import share.system.service.ISConsumerCouponService; import share.system.service.*;
import share.system.service.ISOrderService;
import share.system.service.ISysConfigService;
import share.system.service.SConsumerService;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -61,7 +55,7 @@ public class OrderTask { ...@@ -61,7 +55,7 @@ public class OrderTask {
private TransactionTemplate transactionTemplate; private TransactionTemplate transactionTemplate;
@Autowired @Autowired
private SRoomMapper roomMapper; private ISRoomService roomService;
public void autoCancel() { public void autoCancel() {
String redisKey = Constants.ORDER_AUTO_CANCEL_KEY; String redisKey = Constants.ORDER_AUTO_CANCEL_KEY;
...@@ -179,7 +173,7 @@ public class OrderTask { ...@@ -179,7 +173,7 @@ public class OrderTask {
SOrder tempOrder = new SOrder(); SOrder tempOrder = new SOrder();
tempOrder.setId(sOrder.getId()); tempOrder.setId(sOrder.getId());
tempOrder.setStatus(OrderStatusEnum.REFUNDED.getCode()); tempOrder.setStatus(OrderStatusEnum.CANCEL.getCode());
tempOrder.setRefundStatus(RefundStatusEnum.REFUNDED.getCode()); tempOrder.setRefundStatus(RefundStatusEnum.REFUNDED.getCode());
Boolean execute = Boolean.FALSE; Boolean execute = Boolean.FALSE;
...@@ -208,29 +202,38 @@ public class OrderTask { ...@@ -208,29 +202,38 @@ public class OrderTask {
//预约订单到期自动更新订单状态,更新房间状态 //预约订单到期自动更新订单状态,更新房间状态
public void autoToStore() { public void autoToStore() {
//查询所有已支付的订单 //查询所有已支付的订单
SOrder order = new SOrder(); List<SOrder> sOrders = orderService.validOrder();
order.setPayStatus(1);
order.setStatus(0);
order.setRefundStatus(0);
List<SOrder> sOrders = orderService.selectSOrderList(order);
if (CollectionUtils.isEmpty(sOrders)) { if (CollectionUtils.isEmpty(sOrders)) {
return; return;
} }
sOrders.forEach(item -> { List<Long> roomIds = sOrders.stream().map(SOrder::getRoomId).collect(Collectors.toList());
List<SRoom> roomList = roomService.listByIds(roomIds);
sOrders.stream().forEach(item -> {
//判断预约开始时间是否已到期 //判断预约开始时间是否已到期
if ((Math.abs(item.getPreStartDate().getTime() - new Date().getTime())) / (60 * 1000) == 0) { if ((Math.abs(item.getPreStartDate().getTime() - new Date().getTime())) / (60 * 1000) == 0) {
//更改订单状态,房间状态,开始时间,结束时间 //更改订单状态,房间状态,开始时间,结束时间
item.setStatus(1); item.setStatus(OrderStatusEnum.INUSE.getCode());
item.setUpdateTime(new Date()); item.setUpdateTime(new Date());
item.setStartDate(item.getPreStartDate()); item.setStartDate(item.getPreStartDate());
item.setEndDate(item.getPreEndDate()); item.setEndDate(item.getPreEndDate());
orderService.updateSOrder(item); orderService.updateSOrder(item);
SRoom sRoom = roomMapper.selectById(item.getRoomId()); roomList.stream().forEach( room -> {
sRoom.setStatus("2"); if(room.getId().compareTo(item.getRoomId())==0) {
sRoom.setUpdateTime(new Date()); room.setStatus(RoomStatusEnum.HOLD.getValue());
roomMapper.updateById(sRoom); room.setUpdateTime(new Date());
}
});
} }
}); });
boolean execute = transactionTemplate.execute( e -> {
orderService.updateBatchById(sOrders,sOrders.size());
roomService.updateBatchById(roomList,roomList.size());
return true;
});
if(!execute){
logger.error("预约订单到期自动更新订单状态失败!");
throw new BaseException("预约订单到期自动更新订单状态失败!");
}
} }
} }
...@@ -110,7 +110,7 @@ public class SOrder extends BaseEntity ...@@ -110,7 +110,7 @@ public class SOrder extends BaseEntity
private Date endDate; private Date endDate;
/** 订单状态(0:待使用/已预约,1:使用中,2:已使用,3:已取消预约/退款中,4:审核中,5:已退费) */ /** 订单状态(0:待使用/已预约,1:使用中,2:已使用,3:已取消预约/退款中,4:审核中,5:已退费) */
@Excel(name = "订单状态(0:待使用/已预约,1:使用中,2:已使用,3:已取消预约/退款中,4:审核中,5:已退费)") @Excel(name = "订单状态(0:待使用/已预约,1:使用中,2:已使用,3:已取消预约/申请退款,4:退款中,5:已退费)")
private Integer status; private Integer status;
@ApiModelProperty(value = "0 未退款 1 申请中 2 退款中 3 已退款 4 拒绝退款") @ApiModelProperty(value = "0 未退款 1 申请中 2 退款中 3 已退款 4 拒绝退款")
......
...@@ -46,9 +46,9 @@ public class SRoom extends BaseEntity ...@@ -46,9 +46,9 @@ public class SRoom extends BaseEntity
@Excel(name = "房间详情介绍") @Excel(name = "房间详情介绍")
private String info; private String info;
/** 房间状态(空闲、保洁中、使用中、维护中) */ /** 房间状态(空闲、占用) */
@Excel(name = "房间状态(空闲、保洁中、使用中、维护中)") @Excel(name = "房间状态(空闲、占用)")
private String status; private Integer status;
/** 房间单价(默认单位:元/小时) */ /** 房间单价(默认单位:元/小时) */
@Excel(name = "房间单价(默认单位:元/小时)") @Excel(name = "房间单价(默认单位:元/小时)")
......
...@@ -110,4 +110,10 @@ public interface ISOrderService extends IService<SOrder> ...@@ -110,4 +110,10 @@ public interface ISOrderService extends IService<SOrder>
boolean refundAudit(OrderRefundRequest request); boolean refundAudit(OrderRefundRequest request);
List<SOrder> queryList(); List<SOrder> queryList();
/**
* 查询所有有效订单(未使用,申请退款未审批)
* @return
*/
List<SOrder> validOrder();
} }
...@@ -235,7 +235,7 @@ public class CallbackServiceImpl implements CallbackService { ...@@ -235,7 +235,7 @@ public class CallbackServiceImpl implements CallbackService {
logger.warn("微信退款订单已确认成功==>" + refundRecord.getColumns() + ", rawData==>" + xmlInfo + ", data==>" + notifyRecord); logger.warn("微信退款订单已确认成功==>" + refundRecord.getColumns() + ", rawData==>" + xmlInfo + ", data==>" + notifyRecord);
return refundRecord.getStr("returnXml"); return refundRecord.getStr("returnXml");
} }
sOrder.setStatus(OrderStatusEnum.AUDIT.getCode()); sOrder.setStatus(OrderStatusEnum.CANCEL.getCode());
sOrder.setRefundStatus(RefundStatusEnum.INREFUND.getCode()); sOrder.setRefundStatus(RefundStatusEnum.INREFUND.getCode());
boolean update = sOrderService.updateById(sOrder); boolean update = sOrderService.updateById(sOrder);
if (update) { if (update) {
......
...@@ -312,11 +312,16 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen ...@@ -312,11 +312,16 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
} }
} }
//修改订单退款状态,为退款中 //修改订单退款状态,为退款中
sOrder.setStatus(OrderStatusEnum.AUDIT.getCode());
sOrder.setRefundStatus(RefundStatusEnum.INREFUND.getCode()); sOrder.setRefundStatus(RefundStatusEnum.INREFUND.getCode());
sOrder.setRefundPrice(request.getAmount()); sOrder.setRefundPrice(request.getAmount());
break; break;
case REJECT: case REJECT:
//判断订单预约开始时间是否大于当前时间
if(sOrder.getPreStartDate().compareTo(new Date())>0){
sOrder.setStatus(OrderStatusEnum.USED.getCode());
}else{
sOrder.setStatus(OrderStatusEnum.UNUSED.getCode());
}
sOrder.setRefundStatus(RefundStatusEnum.REJECT.getCode()); sOrder.setRefundStatus(RefundStatusEnum.REJECT.getCode());
break; break;
default: default:
...@@ -362,6 +367,15 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen ...@@ -362,6 +367,15 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
} }
@Override @Override
public List<SOrder> validOrder() {
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SOrder::getStatus,OrderStatusEnum.UNUSED.getCode());
queryWrapper.in(SOrder::getRefundStatus,RefundStatusEnum.getNotRefundStatus());
List<SOrder> result = list(queryWrapper);
return result;
}
@Override
public String openDoor(Long id) { public String openDoor(Long id) {
SOrder sOrder = sOrderMapper.selectSOrderById(id); SOrder sOrder = sOrderMapper.selectSOrderById(id);
if (Objects.isNull(sOrder)) { if (Objects.isNull(sOrder)) {
......
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