Commit aaf0ecfe by 吕明尚

订单换房增加历史订单

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