Commit aaf0ecfe by 吕明尚

订单换房增加历史订单

parent 350b7477
package share.system.domain; package share.system.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
...@@ -14,7 +11,8 @@ import org.springframework.validation.annotation.Validated; ...@@ -14,7 +11,8 @@ import org.springframework.validation.annotation.Validated;
import share.common.annotation.Excel; import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity; import share.common.core.domain.BaseEntity;
import javax.validation.constraints.NotBlank; import java.math.BigDecimal;
import java.util.Date;
/** /**
* 订单对象 s_order * 订单对象 s_order
...@@ -36,6 +34,9 @@ public class SOrder extends BaseEntity ...@@ -36,6 +34,9 @@ public class SOrder extends BaseEntity
@Excel(name = "订单编号") @Excel(name = "订单编号")
private String orderNo; private String orderNo;
@Excel(name = "历史订单号")
private String historicalOrderNo;
@Excel(name = "商户订单号") @Excel(name = "商户订单号")
private String outTradeNo; private String outTradeNo;
......
...@@ -116,8 +116,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -116,8 +116,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Autowired @Autowired
private OrderRefundArtificialService orderRefundArtificialService; private OrderRefundArtificialService orderRefundArtificialService;
@Autowired
private RedisUtil redisUtils;
@Autowired @Autowired
private ISCouponService sCouponService; private ISCouponService sCouponService;
...@@ -459,7 +457,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -459,7 +457,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
map.put("orderNo", one.getOrderNo()); map.put("orderNo", one.getOrderNo());
map.put("expirationTime", one.getEndDate().toString()); map.put("expirationTime", one.getEndDate().toString());
JSONObject jsonObject = new JSONObject(map); JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + one.getOrderNo(), jsonObject.toString()); redisUtil.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + one.getOrderNo(), jsonObject.toString());
} else { } else {
// 使用中订单断电, 延时3分钟断电 // 使用中订单断电, 延时3分钟断电
deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(), deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(),
...@@ -470,7 +468,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -470,7 +468,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
map.put("orderNo", one.getOrderNo()); map.put("orderNo", one.getOrderNo());
map.put("expirationTime", one.getEndDate().toString()); map.put("expirationTime", one.getEndDate().toString());
JSONObject jsonObject = new JSONObject(map); JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + one.getOrderNo(), jsonObject.toString()); redisUtil.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + one.getOrderNo(), jsonObject.toString());
} }
} }
// 如果订单使用中,房间修改状态 // 如果订单使用中,房间修改状态
...@@ -576,28 +574,28 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -576,28 +574,28 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Override @Override
public Boolean changeRoom(SOrderDto dto) { public Boolean changeRoom(SOrderDto dto) {
SOrder sOrder = getById(dto.getId()); SOrder oldSOrder = getById(dto.getId());
//订单状态不等于待使用或者使用中都报错 //订单状态不等于待使用或者使用中都报错
if (!sOrder.getStatus().equals(OrderStatusEnum.UNUSED.getCode()) && !sOrder.getStatus().equals(OrderStatusEnum.INUSE.getCode())) { if (!oldSOrder.getStatus().equals(OrderStatusEnum.UNUSED.getCode()) && !oldSOrder.getStatus().equals(OrderStatusEnum.INUSE.getCode())) {
throw new BaseException("订单异常,不能换房"); throw new BaseException("订单异常,不能换房");
} }
SOrder oldSOrder = new SOrder(); SOrder newOrder = new SOrder();
LambdaQueryWrapper<SRoom> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SRoom> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SRoom::getStoreId, sOrder.getStoreId()); queryWrapper.eq(SRoom::getStoreId, oldSOrder.getStoreId());
List<SRoom> list = roomService.list(queryWrapper); List<SRoom> list = roomService.list(queryWrapper);
BeanUtils.copyProperties(sOrder, oldSOrder); BeanUtils.copyProperties(oldSOrder, newOrder);
LambdaQueryWrapper<SOrder> sOrderLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SOrder> sOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
sOrderLambdaQueryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus()); sOrderLambdaQueryWrapper.notIn(SOrder::getRefundStatus, RefundStatusEnum.getRefundedStatus());
sOrderLambdaQueryWrapper.in(SOrder::getStatus, OrderStatusEnum.getUnfinishOrderStatus()); sOrderLambdaQueryWrapper.in(SOrder::getStatus, OrderStatusEnum.getUnfinishOrderStatus());
sOrderLambdaQueryWrapper.eq(SOrder::getIsDelete, YesNoEnum.no.getIndex()); sOrderLambdaQueryWrapper.eq(SOrder::getIsDelete, YesNoEnum.no.getIndex());
sOrderLambdaQueryWrapper.eq(SOrder::getStoreId, sOrder.getStoreId()); sOrderLambdaQueryWrapper.eq(SOrder::getStoreId, oldSOrder.getStoreId());
sOrderLambdaQueryWrapper.eq(SOrder::getRoomId, dto.getRoomId()); sOrderLambdaQueryWrapper.eq(SOrder::getRoomId, dto.getRoomId());
sOrderLambdaQueryWrapper.apply("(IFNULL(start_date,pre_start_date) BETWEEN '" sOrderLambdaQueryWrapper.apply("(IFNULL(start_date,pre_start_date) BETWEEN '"
+ DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, sOrder.getPreStartDate()) + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, oldSOrder.getPreStartDate())
+ "' AND '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(sOrder.getPreEndDate(), Constants.ROOM_LOCK_DELAY_MINUTE)) + "' " + + "' AND '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(oldSOrder.getPreEndDate(), Constants.ROOM_LOCK_DELAY_MINUTE)) + "' " +
"OR IFNULL(end_date,pre_end_date) BETWEEN '" "OR IFNULL(end_date,pre_end_date) BETWEEN '"
+ DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(sOrder.getPreStartDate(), -Constants.ROOM_LOCK_DELAY_MINUTE)) + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addMinutes(oldSOrder.getPreStartDate(), -Constants.ROOM_LOCK_DELAY_MINUTE))
+ "' AND '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, sOrder.getPreEndDate()) + "' )"); + "' AND '" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, oldSOrder.getPreEndDate()) + "' )");
List<SOrder> orderList = list(sOrderLambdaQueryWrapper); List<SOrder> orderList = list(sOrderLambdaQueryWrapper);
if (CollectionUtils.isNotEmpty(orderList)) { if (CollectionUtils.isNotEmpty(orderList)) {
return false; return false;
...@@ -605,37 +603,53 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -605,37 +603,53 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
// 判断原房间是否生成保洁 // 判断原房间是否生成保洁
if (dto.getIsClean().equals(YesNoEnum.yes.getIndex())) { if (dto.getIsClean().equals(YesNoEnum.yes.getIndex())) {
//判断订单是否已经添加保洁记录 //判断订单是否已经添加保洁记录
SCleanRecords cleanRecords = isCleanRecordsService.lastCleanByRoomId(sOrder.getRoomId()); SCleanRecords cleanRecords = isCleanRecordsService.lastCleanByRoomId(oldSOrder.getRoomId());
if (ObjectUtil.isEmpty(getOne(new LambdaQueryWrapper<SOrder>().eq(SOrder::getRoomId, sOrder.getRoomId()).eq(SOrder::getStatus, OrderStatusEnum.INUSE.getCode()))) && if (ObjectUtil.isEmpty(getOne(new LambdaQueryWrapper<SOrder>().eq(SOrder::getRoomId, oldSOrder.getRoomId()).eq(SOrder::getStatus, OrderStatusEnum.INUSE.getCode()))) &&
(ObjectUtil.isEmpty(cleanRecords) || cleanRecords.getStatus().equals(CleaningStatusEnum.CLEANED.getCode()))) { (ObjectUtil.isEmpty(cleanRecords) || cleanRecords.getStatus().equals(CleaningStatusEnum.CLEANED.getCode()))) {
//房间添加保洁记录 //房间添加保洁记录
isCleanRecordsService.addSCleanRecords(sOrder.getStoreId(), sOrder.getRoomId()); isCleanRecordsService.addSCleanRecords(oldSOrder.getStoreId(), oldSOrder.getRoomId());
} }
} }
//判断极端条件,在订单换房时原订单在自动开始的订单中变为订单开始状态 //判断极端条件,在订单换房时原订单在自动开始的订单中变为订单开始状态
boolean inuse = redisUtils.exists(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + sOrder.getOrderNo()); boolean inuse = redisUtil.exists(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + oldSOrder.getOrderNo());
String cj = BaseUtil.getOrderNo("CJ");
//原订单是否使用中 //原订单是否使用中
if (sOrder.getStatus().equals(OrderStatusEnum.INUSE.getCode()) | inuse) { if (oldSOrder.getStatus().equals(OrderStatusEnum.INUSE.getCode()) | inuse) {
// 使用中订单断电, 延时3分钟断电 // 使用中订单断电, 延时3分钟断电
deviceOpService.openOrCloseDevice(sOrder.getRoomId(), sOrder.getConsumerPhone(), deviceOpService.openOrCloseDevice(oldSOrder.getRoomId(), oldSOrder.getConsumerPhone(),
OpTypeEnum.CUT_ELECTRIC.getCode(), false, 0, DeviceOpSourceEnum.DEVICE_SOURCE_20.getCode()); OpTypeEnum.CUT_ELECTRIC.getCode(), false, 0, DeviceOpSourceEnum.DEVICE_SOURCE_20.getCode());
//修改原房间状态 //修改原房间状态
SRoom sRoom = new SRoom(); SRoom sRoom = new SRoom();
sRoom.setId(sOrder.getRoomId()); sRoom.setId(oldSOrder.getRoomId());
sRoom.setStatus(RoomStatusEnum.FREE.getValue()); sRoom.setStatus(RoomStatusEnum.FREE.getValue());
roomService.updateById(sRoom); roomService.updateById(sRoom);
//修改新房间状态 //修改新房间状态
sRoom.setId(dto.getRoomId()); sRoom.setId(dto.getRoomId());
sRoom.setStatus(RoomStatusEnum.HOLD.getValue()); sRoom.setStatus(RoomStatusEnum.HOLD.getValue());
//删除原来的redis
roomService.updateById(sRoom); roomService.updateById(sRoom);
} //生成新的redis
sOrder.setIsDelete(YesNoEnum.yes.getIndex()); Map<String, String> map = new HashMap<>();
sOrder.setRemark("订单:" + sOrder.getOrderNo() + "由原来的" + list.stream().filter(item -> item.getId().equals(sOrder.getRoomId())).findFirst().orElse(null).getName() map.put("orderNo", cj);
+ "换到" + list.stream().filter(item -> item.getId().equals(dto.getRoomId())).findFirst().orElse(null).getName() + "房间"); map.put("expirationTime", oldSOrder.getEndDate().toString());
sOrder.setCreateTime(new Date()); JSONObject jsonObject = new JSONObject(map);
save(sOrder); redisUtil.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + cj, jsonObject.toString());
oldSOrder.setRoomId(dto.getRoomId()); redisUtil.delete(oldSOrder.getOrderNo());
return updateById(oldSOrder); } else if (oldSOrder.getStatus().equals(OrderStatusEnum.UNUSED.getCode())) {
//未使用订单
Map<String, String> map = new HashMap<>();
map.put("orderNo", cj);
map.put("expirationTime", oldSOrder.getPreStartDate().toString());
JSONObject jsonObject = new JSONObject(map);
redisUtil.set(ReceiptRdeisEnum.ORDER_NO.getValue() + cj, jsonObject.toString());
redisUtil.delete(oldSOrder.getOrderNo());
}
oldSOrder.setIsDelete(YesNoEnum.yes.getIndex());
newOrder.setHistoricalOrderNo(oldSOrder.getOrderNo());
newOrder.setOrderNo(cj);
newOrder.setRoomId(dto.getRoomId());
save(newOrder);
return removeById(oldSOrder);
} }
@Override @Override
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<result property="id" column="id"/> <result property="id" column="id"/>
<result property="orderNo" column="order_no"/> <result property="orderNo" column="order_no"/>
<result property="outTradeNo" column="out_trade_no"/> <result property="outTradeNo" column="out_trade_no"/>
<result property="historicalOrderNo" column="historical_order_no"/>
<result property="orderType" column="order_type"/> <result property="orderType" column="order_type"/>
<result property="payType" column="pay_type"/> <result property="payType" column="pay_type"/>
<result property="payStatus" column="pay_status"/> <result property="payStatus" column="pay_status"/>
...@@ -46,6 +47,7 @@ ...@@ -46,6 +47,7 @@
select id, select id,
order_no, order_no,
out_trade_no, out_trade_no,
historical_order_no,
order_type, order_type,
pay_type, pay_type,
pay_status, pay_status,
...@@ -86,6 +88,9 @@ ...@@ -86,6 +88,9 @@
where pay_status = 1 where pay_status = 1
and is_delete = 0 and is_delete = 0
<if test="orderNo != null and orderNo != ''">and order_no = #{orderNo}</if> <if test="orderNo != null and orderNo != ''">and order_no = #{orderNo}</if>
<if test="historicalOrderNo != null and historicalOrderNo != ''">and historical_order_no =
#{historicalOrderNo}
</if>
<if test="outTradeNo != null and outTradeNo != ''">and out_trade_no = #{outTradeNo}</if> <if test="outTradeNo != null and outTradeNo != ''">and out_trade_no = #{outTradeNo}</if>
<if test="orderType != null and orderType != ''">and order_type = #{orderType}</if> <if test="orderType != null and orderType != ''">and order_type = #{orderType}</if>
<if test="payType != null and payType != ''">and pay_type = #{payType}</if> <if test="payType != null and payType != ''">and pay_type = #{payType}</if>
...@@ -155,6 +160,7 @@ ...@@ -155,6 +160,7 @@
insert into s_order insert into s_order
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="orderNo != null and orderNo != ''">order_no,</if> <if test="orderNo != null and orderNo != ''">order_no,</if>
<if test="historicalOrderNo != null and historicalOrderNo != ''">historical_order_no,</if>
<if test="outTradeNo != null and outTradeNo != ''">out_trade_no,</if> <if test="outTradeNo != null and outTradeNo != ''">out_trade_no,</if>
<if test="orderType != null and orderType != ''">order_type,</if> <if test="orderType != null and orderType != ''">order_type,</if>
<if test="payType != null and payType != ''">pay_type,</if> <if test="payType != null and payType != ''">pay_type,</if>
...@@ -188,6 +194,7 @@ ...@@ -188,6 +194,7 @@
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderNo != null">#{orderNo},</if> <if test="orderNo != null">#{orderNo},</if>
<if test="historicalOrderNo != null">#{historicalOrderNo},</if>
<if test="outTradeNo != null ">#{outTradeNo},</if> <if test="outTradeNo != null ">#{outTradeNo},</if>
<if test="orderType != null">#{orderType},</if> <if test="orderType != null">#{orderType},</if>
<if test="payType != null">#{payType},</if> <if test="payType != null">#{payType},</if>
...@@ -225,6 +232,7 @@ ...@@ -225,6 +232,7 @@
update s_order update s_order
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="orderNo != null">order_no = #{orderNo},</if> <if test="orderNo != null">order_no = #{orderNo},</if>
<if test="historicalOrderNo != null">historical_order_no = #{historicalOrderNo},</if>
<if test="outTradeNo != null">out_trade_no = #{outTradeNo},</if> <if test="outTradeNo != null">out_trade_no = #{outTradeNo},</if>
<if test="orderType != null">order_type = #{orderType},</if> <if test="orderType != null">order_type = #{orderType},</if>
<if test="payType != null">pay_type = #{payType},</if> <if test="payType != null">pay_type = #{payType},</if>
......
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