From 3a6a9b536eada87d1ac0e90133fb66093444cf9f Mon Sep 17 00:00:00 2001
From: zhangxinqi <m15726637040@163.com>
Date: Sun, 26 Jun 2022 00:42:25 +0800
Subject: [PATCH] 前进前进,继续上代码

---
 soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java           |  5 +++++
 soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java                    |  2 ++
 soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java                | 17 ++++++++++++++---
 soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java         | 20 ++++++++++++++++++++
 soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java         | 35 ++++++++++++++++++++++++++++++++++-
 soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java |  1 +
 soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java          |  7 +++++++
 soss-system/src/main/resources/mapper/system/OrderMapper.xml                         | 10 ++++++++++
 soss-system/src/main/resources/mapper/system/ShopMapper.xml                          |  2 +-
 9 files changed, 94 insertions(+), 5 deletions(-)

diff --git a/soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java b/soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java
index a7bbfbf..5834dba 100644
--- a/soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java
+++ b/soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java
@@ -77,6 +77,11 @@ public class AppController extends BaseController {
         String info = orderService.getWaitTime(order);
         return AjaxResult.success("操作成功",info);
     }
+    @RequestMapping("/getWaitTineByOrderId")
+    public AjaxResult getWaitTineByOrderId( Long orderId){
+        String info = orderService.getWaitTimeByOrderId(orderId);
+        return AjaxResult.success("操作成功",info);
+    }
 
 
 
diff --git a/soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java b/soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java
index 6d2f42c..9c9c987 100644
--- a/soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java
+++ b/soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java
@@ -83,4 +83,6 @@ public interface OrderMapper
     void updateCancel(@Param("status") String unpaid, @Param("timeout") int i);
 
     List<Order> selectOrderByTime(@Param("status")String unpaid, @Param("timeout")int i);
+
+    List<Order> selectBeforeOrder(@Param("status")List<String> status, @Param("orderId")Long orderId);
 }
diff --git a/soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java b/soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java
index c736904..3d85198 100644
--- a/soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java
+++ b/soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java
@@ -5,6 +5,7 @@ import com.soss.system.domain.Order;
 import com.soss.system.domain.OrderOperationLog;
 import com.soss.system.mapper.OrderMapper;
 import com.soss.system.mapper.OrderOperationLogMapper;
+import com.soss.system.service.impl.OrderServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -18,15 +19,25 @@ public class OrderSchedule {
     @Autowired
     private OrderMapper orderMapper;
     @Value("${timeout}")
-    private String timeout;
+    private Integer timeout;
     @Autowired
     private OrderOperationLogMapper operationLogMapper;
+    @Autowired
+    private OrderServiceImpl orderService;
 
     @Scheduled(fixedDelay = 60*1000)
     private void process() {
-        orderMapper.updateTimeOut(OrderStatusConstant.productionCompleted,timeout);
+        //orderMapper.updateTimeOut(OrderStatusConstant.productionCompleted,timeout);
+        List<Order> orders1 = orderMapper.selectOrderByTime(OrderStatusConstant.productionCompleted, timeout);
+        if(orders1!=null &&orders1.size()>0){
+            for (Order order : orders1) {
+                order.setState(OrderStatusConstant.timeout);
+                order.setUpdatedAt(new Date());
+                orderService.updateOrder(order);
+            }
+        }
         //orderMapper.updateCancel(OrderStatusConstant.Unpaid,15);
-        List<Order> orders = orderMapper.selectOrderByTime(OrderStatusConstant.Unpaid, 15);
+        List<Order> orders = orderMapper.selectOrderByTime(OrderStatusConstant.Unpaid, 15*60);
         if(orders!=null &&orders.size()>0){
             for (Order order : orders) {
                 order.setState(OrderStatusConstant.UnpaidCancel);
diff --git a/soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java
index eb6c773..ed88220 100644
--- a/soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java
+++ b/soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java
@@ -5,10 +5,12 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.soss.common.exception.ServiceException;
 import com.soss.common.utils.GenerateCode;
 import com.soss.common.utils.StringUtils;
 import com.soss.system.domain.*;
+import com.soss.system.jiguang.impl.JiGuangPushServiceImpl;
 import com.soss.system.service.IGoodsService;
 import com.soss.system.mapper.*;
 import lombok.extern.slf4j.Slf4j;
@@ -45,6 +47,10 @@ public class GoodsServiceImpl implements IGoodsService
     private GoodsCategoryMapper goodsCategoryMapper;
     @Autowired
     private ShopRecommendMapper shopRecommendMapper;
+    @Autowired
+    private MachineMapper machineMapper;
+    @Autowired
+    private JiGuangPushServiceImpl jiGuangPushService;
 
 
     /**
@@ -312,10 +318,24 @@ public class GoodsServiceImpl implements IGoodsService
             shopGoodsSkuMapper.deleteShopGoodsSkuByGoodsId(shopGoods1.getGoodsId());
             List<String> goodsIds = Arrays.asList(String.valueOf(shopGoods1.getGoodsId()));
             shopRecommendMapper.deleteByShopIdGoods(shopGoods1.getShopId(),goodsIds);
+            updateApplication(shopGoods1.getShopId());
         }
 
         return i+"";
     }
+    public void updateApplication(long shopId){
+        Machine machine = new Machine();
+        machine.setShopId(shopId);
+        List<Machine> machines = machineMapper.selectMachineList(machine);
+        if(!machines.isEmpty()){
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("action","GOODS_CHANGED");
+            jsonObject.put("timestamp",System.currentTimeMillis());
+            jiGuangPushService.push(machines.get(0).getCode(),jsonObject);
+        }
+
+
+    }
 
     @Override
     public String deleteGoodsById(Long id, boolean boo) {
diff --git a/soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java
index ffac5ac..06633da 100644
--- a/soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java
+++ b/soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java
@@ -212,6 +212,9 @@ public class OrderServiceImpl implements IOrderService
             case OrderStatusConstant.completed:
                 completedState(order);
                 break;
+            case OrderStatusConstant.timeout:
+                timeoutState(order);
+                break;
             case OrderStatusConstant.UnpaidCancel:
             case OrderStatusConstant.PaidCancel:
                 unpaidCancelState(order);
@@ -229,6 +232,10 @@ public class OrderServiceImpl implements IOrderService
         return orderMapper.updateOrder(order);
     }
 
+    private void timeoutState(Order order) {
+        jiGuangPushService.pushOrderState(order);
+    }
+
     /**
      * 部分退款
      * @param order
@@ -517,7 +524,7 @@ public class OrderServiceImpl implements IOrderService
         orderDetail.setOrderId(order.getId());
         List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(orderDetail);
         order.setOrderDetails(orderDetails);
-        String waitTime = getWaitTime(order);
+        String waitTime = getWaitTimeByOrderId(order.getId());
         Map<String,String> map =new HashMap<>();
         map.put("waitTime",waitTime);
         map.put("pickCode",order.getPickCode());
@@ -554,6 +561,32 @@ public class OrderServiceImpl implements IOrderService
 
     }
 
+    public String getWaitTimeByOrderId(Long orderId) {
+        List<String> status = Arrays.asList(OrderStatusConstant.Paid,OrderStatusConstant.production);
+        List<Order> orders = orderMapper.selectBeforeOrder(status, orderId);
+        List<OrderDetail> list = new ArrayList<>();
+        for (Order order1 : orders) {
+            OrderDetail orderDetail = new OrderDetail();
+            orderDetail.setOrderId(order1.getId());
+            List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(orderDetail);
+            if(CollectionUtils.isEmpty(orderDetails)){
+
+            }else{
+                list.addAll(orderDetails);
+            }
+        }
+        Long takeTimeCount =0L;
+        for (OrderDetail orderDetail : list) {
+            Long takeTime = goodsMapper.selectGoodsById(orderDetail.getGoodsId()).getTakeTime();
+            takeTime = Integer.parseInt(orderDetail.getNum())*takeTime;
+            takeTimeCount+=takeTime;
+        }
+
+        return  String.valueOf((int)(takeTimeCount/60));
+
+    }
+
+
     public  List<GoodsVo> getNextOrder(String orderId,String shopId) {
         OrderDetail orderDetail = new OrderDetail();
         orderDetail.setOrderId(Long.parseLong(orderId));
diff --git a/soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java
index 1b46955..0b37f75 100644
--- a/soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java
+++ b/soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java
@@ -174,6 +174,7 @@ public class ShopRecommendServiceImpl implements IShopRecommendService
         last.setTurn(turn);
         shopRecommendMapper.updateShopRecommend(frist);
         shopRecommendMapper.updateShopRecommend(last);
+        updateApplication(Long.parseLong(shopRecommend.getShopId()));
         return null;
     }
 
diff --git a/soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java
index 607acd2..17125da 100644
--- a/soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java
+++ b/soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java
@@ -308,6 +308,13 @@ public class ShopServiceImpl implements IShopService
         lastShopGoods.setTurn(turn);
         shopGoodsMapper.updateShopGoods(fristShopGoods);
         shopGoodsMapper.updateShopGoods(lastShopGoods);
+        Machine machine = new Machine();
+        machine.setShopId(shopId);
+        List<Machine> machines = machineMapper.selectMachineList(machine);
+        if(!machines.isEmpty()){
+            Machine machine1 =machines .get(0);
+            updateApplication(machine1.getCode());
+        }
         return null;
     }
 
diff --git a/soss-system/src/main/resources/mapper/system/OrderMapper.xml b/soss-system/src/main/resources/mapper/system/OrderMapper.xml
index 06e8152..12efd6d 100644
--- a/soss-system/src/main/resources/mapper/system/OrderMapper.xml
+++ b/soss-system/src/main/resources/mapper/system/OrderMapper.xml
@@ -244,6 +244,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectOrderVo"/>
         where state =#{status} and updated_at &lt; DATE_SUB(NOW() ,interval #{timeout} SECOND)
     </select>
+    <select id="selectBeforeOrder" resultType="com.soss.system.domain.Order">
+        select id, order_no, order_num, user_id, user_name, user_phone, pay_time, finish_time, amount, goods_num, pick_code, shop_id, machine_id, source, state, created_at, updated_at
+        from `order` o where o.id &lt;#{orderId} and o.shop_id =(select DISTINCT a.shop_id  from `order` a where a.id=#{orderId})
+
+        and state in
+        <foreach item="item" index="index" collection="status"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
     <update id="updateCancel">
         update `order`  set state='8' where state =#{status} and updated_at &lt; DATE_SUB(NOW() ,interval #{timeout} SECOND)
     </update>
diff --git a/soss-system/src/main/resources/mapper/system/ShopMapper.xml b/soss-system/src/main/resources/mapper/system/ShopMapper.xml
index 9757d95..5c0305b 100644
--- a/soss-system/src/main/resources/mapper/system/ShopMapper.xml
+++ b/soss-system/src/main/resources/mapper/system/ShopMapper.xml
@@ -45,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createdAt != null "> and s.created_at = #{createdAt}</if>
             <if test="updatedAt != null "> and s.updated_at = #{updatedAt}</if>
             <if test="isDefault != null "> and s.is_default = #{isDefault}</if>
-            <if test="machineCode!=null"> and m.code =#{machineCode}</if>
+            <if test="machineCode!=null and machineCode != ''"> and m.code =#{machineCode}</if>
         </where>
     </select>
     
--
libgit2 0.26.0