Pārlūkot izejas kodu

获取餐饮数据接口

王先生 2 gadi atpakaļ
vecāks
revīzija
c0a549ea83

+ 21 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/order/repository/DmOrderRecordRepository.java

@@ -48,6 +48,13 @@ public interface DmOrderRecordRepository extends JpaRepository<DmOrderRecord, Lo
     @Query(value = "SELECT IF(SUM(amt) is null,0,SUM(amt)) FROM dm_order_record WHERE create_date BETWEEN DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 DAY),'%Y-%m-%d 00:00:00') AND DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 DAY),'%Y-%m-%d 23:59:59') ",nativeQuery = true)
     Integer countIncome();
 
+    /**
+     * 今日营业额
+     * @return
+     */
+    @Query(value = "SELECT IF(SUM(amt) is null,0,SUM(amt)) FROM dm_order_record WHERE create_date BETWEEN DATE_FORMAT(CURDATE(),'%Y-%m-%d 00:00:00') AND DATE_FORMAT(CURDATE(),'%Y-%m-%d 23:59:59') ",nativeQuery = true)
+    Integer countNowIncome();
+
     /**
      * 昨日消费人数
      * @return
@@ -57,6 +64,13 @@ public interface DmOrderRecordRepository extends JpaRepository<DmOrderRecord, Lo
             " ) a ",nativeQuery = true)
     Integer countConsumerNumber();
 
+    /**
+     * 今日消费人数
+     * @return
+     */
+    @Query(value = "SELECT count(1) from (SELECT DISTINCT mob FROM dm_order_record WHERE create_date BETWEEN DATE_FORMAT(CURDATE(),'%Y-%m-%d 00:00:00') AND DATE_FORMAT(CURDATE(),'%Y-%m-%d 23:59:59')) a ",nativeQuery = true)
+    Integer countConsumerNowNumber();
+
     @Query(value = "SELECT a.`id`, a.`bh`, a.`money`, a.`mob`, a.`user_code`, a.`user_name`, a.`dept_id`, " +
             "a.`user_type`, a.`phone`, a.`create_date`, a.`total_money`, a.`zk_money`, a.`seq`, a.`card`, " +
             "a.`card_no`, a.`part`, a.`term`, a.`shop`, a.`term_name`, a.`shop_name`, a.`amt`, a.`balance`, " +
@@ -109,4 +123,11 @@ public interface DmOrderRecordRepository extends JpaRepository<DmOrderRecord, Lo
      */
     @Query(value = "SELECT if(AVG(pj.pj_star) is null,0,AVG(pj.pj_star)) as grade, COUNT(DISTINCT(pj.user_code)) as code_num,count(pj.food_code) as food_num FROM dm_order_record as record INNER JOIN dm_order_item as item on item.bh = record.bh left join dm_food_pj as pj on pj.order_bh = item.bh where DATE_FORMAT(record.create_date,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') and pj.food_code = :cateId ",nativeQuery = true)
     Map<String,Object> selectOrderSumByCateId(@Param("cateId") String cateId);
+
+    /**
+     * 销售前端的商品
+     * @return
+     */
+    @Query(value = "SELECT item.pid,item.name,COUNT(item.pid) as countPid FROM dm_order_record rec LEFT JOIN  dm_order_item item on rec.seq = item.seq WHERE rec.create_date BETWEEN  DATE_FORMAT(date_sub(CURDATE(),interval 1 day),'%Y-%m-%d 00:00:00') AND DATE_FORMAT(date_sub(CURDATE(),interval 1 day),'%Y-%m-%d 23:59:59')  GROUP BY item.pid ORDER BY countPid desc LIMIT 0,3",nativeQuery = true)
+    List<Map<String,Object>> countCateTheTopThree();
 }

+ 17 - 0
eladmin-system/src/main/java/me/zhengjie/modules/thirdparty/v1/OpenApiController.java

@@ -323,4 +323,21 @@ public class OpenApiController {
         dmUserInformationService.create(criteria.getQuery());
         return new BaseResponse<>(true);
     }
+
+    @AnonymousGetMapping(value = "/getCanYinData")
+    @Log("获取餐饮数据")
+    @ApiOperation("获取餐饮数据")
+    public BaseResponse<Object> getCanYinData(){
+        JSONObject jsonObject = new JSONObject();
+        // 查询今日营业额
+        Integer nowIncome = dmOrderRecordRepository.countNowIncome();
+        jsonObject.put("nowIncome",nowIncome);
+        // 今日销售人数
+         Integer consumerNowNumber = dmOrderRecordRepository.countConsumerNowNumber();
+        jsonObject.put("consumerNowNumber",consumerNowNumber);
+         // 昨日销量排前三的菜品名称已经销量
+        List<Map<String,Object>> countTheTopThree =  dmOrderRecordRepository.countCateTheTopThree();
+        jsonObject.put("countTheTopThree",countTheTopThree);
+        return new BaseResponse<>(jsonObject);
+    }
 }