Browse Source

智能看板--餐厅数据接口

ZhangManMan 2 years ago
parent
commit
16d8083fd0

+ 6 - 4
src/main/java/com/sky/ioc/controller/dashboard/DiningRoomController.java

@@ -1,5 +1,6 @@
 package com.sky.ioc.controller.dashboard;
 
+import com.sky.ioc.entity.params.IocParam;
 import com.sky.ioc.service.canteen.RestaurantService;
 import com.sky.ioc.tool.ReturnMsg;
 import io.swagger.annotations.Api;
@@ -7,6 +8,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -28,16 +30,16 @@ public class DiningRoomController {
 
     @ApiOperation("查询智能看板统计画像的餐厅消费态势的核心指标")
     @PostMapping("getRestaurantConsumption")
-    public ReturnMsg getRestaurantConsumption(){
-        return restaurantService.getRestaurantConsumption();
+    public ReturnMsg getRestaurantConsumption(@RequestBody IocParam iocParam){
+        return restaurantService.getRestaurantConsumption(iocParam);
     }
 
 
 
     @ApiOperation("查询智能看板统计画像的餐厅统计消费信息报表")
     @PostMapping("getRestaurantConsumptionChart")
-    public ReturnMsg  getPersonnelInfoList(){
-        return restaurantService.getRestaurantConsumptionChart();
+    public ReturnMsg  getPersonnelInfoList(@RequestBody IocParam iocParam){
+        return restaurantService.getRestaurantConsumptionChart(iocParam);
     }
 
 

+ 8 - 3
src/main/java/com/sky/ioc/mapper/SupermarketOrderMapper.java

@@ -73,8 +73,13 @@ public interface SupermarketOrderMapper extends BaseMapper<SupermarketOrder> {
             "</script>")
     Integer getTotalPersonByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);
 
-    @Select("SELECT sum(order_price) FROM supermarket_order " +
-            "WHERE order_type='微信' ")
-    Double getThirdTotalPriceByCompanyIdAndDeptId();
+    @Select("<script> " +
+            "SELECT sum(order_price) FROM supermarket_order " +
+            "WHERE order_type='微信' " +
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            " and order_time BETWEEN #{iocParam.timeRange.startDate} AND #{iocParam.timeRange.endDate} " +
+            "</if>" +
+            " </script>")
+    Double getThirdTotalPriceByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);
 
 }

+ 3 - 2
src/main/java/com/sky/ioc/service/canteen/RestaurantService.java

@@ -2,6 +2,7 @@ package com.sky.ioc.service.canteen;
 
 import com.sky.ioc.entity.params.IocParam;
 import com.sky.ioc.tool.ReturnMsg;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import java.text.ParseException;
 
@@ -26,7 +27,7 @@ public interface RestaurantService {
 
     ReturnMsg getMealAnalysis(IocParam iocParam);
 
-    ReturnMsg getRestaurantConsumption();
+    ReturnMsg getRestaurantConsumption(IocParam iocParam);
 
-    ReturnMsg getRestaurantConsumptionChart();
+    ReturnMsg getRestaurantConsumptionChart(IocParam iocParam);
 }

+ 46 - 19
src/main/java/com/sky/ioc/service/canteen/impl/RestaurantServiceImpl.java

@@ -316,30 +316,34 @@ public class RestaurantServiceImpl implements RestaurantService {
      * @date 2023/2/22 15:22
      */
     @Override
-    public ReturnMsg getRestaurantConsumption() {
+    public ReturnMsg getRestaurantConsumption(IocParam iocParam) {
         Indeicator indeicator = new Indeicator();
         List<JSONObject> objects = indeicator.getList();
+        double thirdPay = 0d;
         ThreadLocalRandom random = ThreadLocalRandom.current();
-        DecimalFormat decimalFormat = new DecimalFormat("#.0");
-        int orderConut = random.nextInt(800, 2000);//订单数
-        int price = random.nextInt(10,30);//单价
-        int thirdPay = random.nextInt(1000,10000);//第三方支付
-        int totalPrice = orderConut*price;//总金额
-        while (thirdPay>totalPrice){
-            thirdPay = random.nextInt(1000,10000);//第三方支付
+        Double totalPrice = cuisineOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam,null);
+        totalPrice = totalPrice == null ? 0 : totalPrice;
+        BigDecimal bigDecimal = new BigDecimal(totalPrice);
+        Integer totalOrder = cuisineOrderMapper.getTotalOrderByCompanyIdAndDeptId(iocParam);
+        double avgPrice = 0d;
+        if (totalPrice > 0) {
+            if (totalOrder > 0) {
+                BigDecimal avgPriceDec = bigDecimal.divide(new BigDecimal(totalOrder), 2, RoundingMode.HALF_UP);
+                avgPrice = avgPriceDec.doubleValue();
+            }
         }
-        BigDecimal bigDecimal2 = new BigDecimal(thirdPay);
-        double thirdPay2 = (bigDecimal2.divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP).doubleValue()*6);
+        DecimalFormat decimalFormat = new DecimalFormat("#.0");
+        totalPrice = Double.parseDouble(decimalFormat.format(totalPrice));
         double compare = random.nextDouble(-1, 1);
         compare = Double.parseDouble(decimalFormat.format(compare));
         objects.get(0).put("value",totalPrice);
-        objects.get(0).put("compare",0.4);
-        objects.get(1).put("value",orderConut);
-        objects.get(1).put("compare",0.4);
-        objects.get(2).put("value",price);
-        objects.get(2).put("compare",0.4);
+        objects.get(0).put("compare",compare);
+        objects.get(1).put("value",totalOrder);
+        objects.get(1).put("compare",compare);
+        objects.get(2).put("value",avgPrice);
+        objects.get(2).put("compare",compare);
 
-        objects.get(3).put("value",thirdPay2);
+        objects.get(3).put("value",thirdPay);
         indeicator.setWorthAttention("提高合同额");
         indeicator.setList(objects);
         return ReturnMsg.ok(indeicator);
@@ -354,10 +358,33 @@ public class RestaurantServiceImpl implements RestaurantService {
      * @date 2023/2/22 15:22
      */
     @Override
-    public ReturnMsg getRestaurantConsumptionChart() {
+    public ReturnMsg getRestaurantConsumptionChart(IocParam iocParam) {
         String[] param = {"consumptionAmount","consumptionOrder"};
-        String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
-        List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
+        String startStr = iocParam.getTimeRange().getStartDate();
+        String endStr = iocParam.getTimeRange().getEndDate();
+        List<String> list = DateUtil.getBetweenDays(startStr, endStr);
+        String[] labKey = list.toArray(new String[0]);
+        List<Label> labels1 = new ArrayList<>();
+        DecimalFormat decimalFormat = new DecimalFormat("#.0");
+        for (int i = 0; i < labKey.length; i++) {
+            Label label = new Label();
+            JSONObject jsonObject = new JSONObject();
+            IocParam iocParam1 = new IocParam();
+            IocTimeRange iocTimeRange = new IocTimeRange();
+            iocTimeRange.setStartDate(labKey[i]+" 00:00:00");
+            iocTimeRange.setEndDate(labKey[i]+" 23:59:00");
+            iocParam1.setTimeRange(iocTimeRange);
+            Double totalPrice = cuisineOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam1,null);
+            totalPrice = totalPrice == null ? 0 : totalPrice;
+            totalPrice = Double.valueOf(decimalFormat.format(totalPrice));
+            Integer totalOrder = cuisineOrderMapper.getTotalOrderByCompanyIdAndDeptId(iocParam1);
+            jsonObject.put(param[0],totalPrice);
+            jsonObject.put(param[1],totalOrder);
+
+            label.setJsonObject(jsonObject);
+            label.setLabel(labKey[i]);
+            labels1.add(label);
+        }
         return ReturnMsg.ok(labels1);
     }
 }

+ 2 - 1
src/main/java/com/sky/ioc/service/supermarket/impl/SupermarketServiceImpl.java

@@ -181,12 +181,13 @@ public class SupermarketServiceImpl implements SupermarketService {
             avgPrice = avgPriceDec.doubleValue();
         }
         ThreadLocalRandom random = ThreadLocalRandom.current();
-        Double thirdPay = supermarketOrderMapper.getThirdTotalPriceByCompanyIdAndDeptId();
+        Double thirdPay = supermarketOrderMapper.getThirdTotalPriceByCompanyIdAndDeptId(iocParam);
         thirdPay = thirdPay == null ? 0 : Double.valueOf(decimalFormat.format(thirdPay));
         if(thirdPay>0){
             BigDecimal bigDecimal2 = new BigDecimal(thirdPay);
             thirdPay =  bigDecimal2.divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP).doubleValue()*6;
         }
+        thirdPay = Double.valueOf(decimalFormat.format(thirdPay));
         double compare = random.nextDouble(-1, 1);
         compare = Double.parseDouble(decimalFormat.format(compare));