Browse Source

refac[litemall-db]: 采用乐观锁更新操作

Junling Bu 7 years ago
parent
commit
9620879518

+ 2 - 2
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminOrderController.java

@@ -134,7 +134,7 @@ public class AdminOrderController {
         try {
             // 设置订单取消状态
             order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM);
-            orderService.update(order);
+            orderService.updateById(order);
 
             // 商品货品数量增加
             List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId);
@@ -204,7 +204,7 @@ public class AdminOrderController {
         order.setShipSn(shipSn);
         order.setShipChannel(shipChannel);
         order.setShipTime(LocalDateTime.now());
-        orderService.update(order);
+        orderService.updateById(order);
 
         //TODO 发送邮件和短信通知,这里采用异步发送
         // 发货会发送通知短信给用户

+ 15 - 3
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java

@@ -23,6 +23,12 @@ public class LitemallOrderService {
         return orderMapper.insertSelective(order);
     }
 
+    public List<LitemallOrder> query(Integer userId) {
+        LitemallOrderExample example = new LitemallOrderExample();
+        example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
+        return orderMapper.selectByExample(example);
+    }
+
     public int count(Integer userId) {
         LitemallOrderExample example = new LitemallOrderExample();
         example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
@@ -36,7 +42,7 @@ public class LitemallOrderService {
     private String getRandomNum(Integer num) {
         String base = "0123456789";
         Random random = new Random();
-        StringBuilder sb = new StringBuilder();
+        StringBuffer sb = new StringBuffer();
         for (int i = 0; i < num; i++) {
             int number = random.nextInt(base.length());
             sb.append(base.charAt(number));
@@ -44,7 +50,13 @@ public class LitemallOrderService {
         return sb.toString();
     }
 
-    private int countByOrderSn(Integer userId, String orderSn){
+    public LitemallOrder queryByOrderSn(Integer userId, String orderSn){
+        LitemallOrderExample example = new LitemallOrderExample();
+        example.or().andUserIdEqualTo(userId).andOrderSnEqualTo(orderSn).andDeletedEqualTo(false);
+        return orderMapper.selectOneByExample(example);
+    }
+
+    public int countByOrderSn(Integer userId, String orderSn){
         LitemallOrderExample example = new LitemallOrderExample();
         example.or().andUserIdEqualTo(userId).andOrderSnEqualTo(orderSn).andDeletedEqualTo(false);
         return (int)orderMapper.countByExample(example);
@@ -85,7 +97,7 @@ public class LitemallOrderService {
     }
 
     public int update(LitemallOrder order) {
-        return orderMapper.updateWithVersionByPrimaryKeySelective(order.getVersion(), order);
+        return orderMapper.updateByPrimaryKeySelective(order);
     }
 
     public List<LitemallOrder> querySelective(Integer userId, String orderSn, List<Short> orderStatusArray, Integer page, Integer size, String sort, String order) {

+ 3 - 3
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java

@@ -509,7 +509,7 @@ public class WxOrderController {
             // 设置订单已取消状态
             order.setOrderStatus(OrderUtil.STATUS_CANCEL);
             order.setEndTime(LocalDateTime.now());
-            orderService.update(order);
+            orderService.updateById(order);
 
             // 商品货品数量增加
             List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId);
@@ -733,7 +733,7 @@ public class WxOrderController {
 
         // 设置订单申请退款状态
         order.setOrderStatus(OrderUtil.STATUS_REFUND);
-        orderService.update(order);
+        orderService.updateById(order);
 
         //TODO 发送邮件和短信通知,这里采用异步发送
         // 有用户申请退款,邮件通知运营人员
@@ -778,7 +778,7 @@ public class WxOrderController {
 
         order.setOrderStatus(OrderUtil.STATUS_CONFIRM);
         order.setConfirmTime(LocalDateTime.now());
-        orderService.update(order);
+        orderService.updateById(order);
         return ResponseUtil.ok();
     }