Ver Fonte

1.IOC运营平台智能看板-统计画像商超接口数据修改
2.IOC运营平台智享生活无人商超核心指标数据修改

ZhangManMan há 2 anos atrás
pai
commit
22ed928b7f

+ 63 - 5
src/main/java/com/sky/ioc/mapper/SupermarketOrderMapper.java

@@ -3,20 +3,78 @@ package com.sky.ioc.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sky.ioc.entity.domain.supermarket.SupermarketOrder;
 import com.sky.ioc.entity.params.IocParam;
+import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
 import java.util.Map;
 
+@Mapper
 public interface SupermarketOrderMapper extends BaseMapper<SupermarketOrder> {
 
-    @Select("SELECT  count(1) as salesVolume,s.name,s.img,s.price " +
+    @Select("<script> " +
+            "SELECT  count(1) as salesVolume,s.name,s.img,s.price " +
             " from supermarket_order o " +
-            " JOIN supermarket s on s.name=o.product_name " +
-            " WHERE dept_id=#{iocParam.deptId} and company_id=#{iocParam.companyId} and order_time" +
-            " BETWEEN #{iocParam.timeRange.startDate} AND #{iocParam.timeRange.endDate} " +
+            " JOIN supermarket s on s.name=o.product_name  where 1=1 " +
+            "<if test='iocParam!=null and iocParam.deptId != null '>" +
+            " and dept_id=#{iocParam.deptId} " +
+            "</if>"+
+            "<if test='iocParam!=null and iocParam.companyId != null '>" +
+            " and company_id=#{iocParam.companyId} " +
+            "</if>"+
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            " and order_time BETWEEN #{iocParam.timeRange.startDate} AND #{iocParam.timeRange.endDate} " +
+            "</if>"+
             "GROUP BY product_name,s.name,s.img,s.price " +
-            "ORDER by salesVolume DESC")
+            "ORDER by salesVolume DESC " +
+            "</script> ")
     List<Map<String,String>> getListByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);
+
+    @Select("<script>" +
+            "SELECT sum(order_price) FROM supermarket_order where 1=1 " +
+             "<if test='iocParam!=null and iocParam.deptId != null '>" +
+            " and dept_id=#{iocParam.deptId} " +
+            "</if>"+
+            "<if test='iocParam!=null and iocParam.companyId != null '>" +
+            " and company_id=#{iocParam.companyId} " +
+            "</if>"+
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            " and order_time BETWEEN #{iocParam.timeRange.startDate} AND #{iocParam.timeRange.endDate} " +
+            "</if>"+
+            "</script>")
+    Double getTotalPriceByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);
+
+    @Select("<script>" +
+            "SELECT count(1) FROM supermarket_order where 1=1 " +
+            "<if test='iocParam!=null and iocParam.deptId != null '>" +
+            " and dept_id=#{iocParam.deptId} " +
+            "</if>"+
+            "<if test='iocParam!=null and iocParam.companyId != null '>" +
+            " and company_id=#{iocParam.companyId} " +
+            "</if>"+
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            " and order_time BETWEEN #{iocParam.timeRange.startDate} AND #{iocParam.timeRange.endDate} " +
+            "</if>"+
+            "</script>")
+    Integer getTotalOrderByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);
+
+    @Select("<script> " +
+            "SELECT count(DISTINCT user_id) FROM supermarket_order  where 1=1 " +
+            "<if test='iocParam!=null and iocParam.deptId != null '>" +
+            " and dept_id=#{iocParam.deptId} " +
+            "</if>"+
+            "<if test='iocParam!=null and iocParam.companyId != null '>" +
+            " and company_id=#{iocParam.companyId} " +
+            "</if>"+
+            "<if test='iocParam!=null and iocParam.timeRange != null '>" +
+            " and order_time BETWEEN #{iocParam.timeRange.startDate} AND #{iocParam.timeRange.endDate} " +
+            "</if>" +
+            "</script>")
+    Integer getTotalPersonByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);
+
+    @Select("SELECT sum(order_price) FROM supermarket_order " +
+            "WHERE order_type='微信' ")
+    Double getThirdTotalPriceByCompanyIdAndDeptId();
+
 }

+ 59 - 55
src/main/java/com/sky/ioc/service/supermarket/impl/SupermarketServiceImpl.java

@@ -13,6 +13,8 @@ import com.sky.ioc.tool.ReturnMsg;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.util.List;
 import java.util.Map;
@@ -35,43 +37,41 @@ public class SupermarketServiceImpl implements SupermarketService {
     public ReturnMsg getCoreIndicators(IocParam iocParam) {
         Indeicator indeicator = new Indeicator();
         List<JSONObject> objects = indeicator.getList();
-        /*ThreadLocalRandom random = ThreadLocalRandom.current();
-        int orderCount = random.nextInt(100, 3000);
-        int orderprice = random.nextInt(50,150);
-        int price = random.nextInt(1,20);
-
-        BigDecimal bigDecimal = new BigDecimal(orderprice*orderCount);
-        BigDecimal decimal = bigDecimal.divide(new BigDecimal("10000"));
-        DecimalFormat formater = new DecimalFormat("#.0");
-
-        // 格式化完成之后得出结果
-        double totalPrice = Double.parseDouble(formater.format(decimal));
-        float compare = (float) Math.random();
+        Double totalPrice = supermarketOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam);
+        totalPrice = totalPrice == null ? 0 : totalPrice;
+        BigDecimal bigDecimal = new BigDecimal(totalPrice);
+        // 转换为万元(除以10000)保留两位小数
+        BigDecimal decimal = bigDecimal.divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP);
+        totalPrice = decimal.doubleValue();
+        Integer totalOrder = supermarketOrderMapper.getTotalOrderByCompanyIdAndDeptId(iocParam);
+        Integer totalPerson = supermarketOrderMapper.getTotalPersonByCompanyIdAndDeptId(iocParam);
+        double avgPrice = 0d;
+        double avgPersonPrice = 0d;
+        if (totalPrice > 0) {
+            if (totalOrder > 0) {
+                BigDecimal avgPriceDec = bigDecimal.divide(new BigDecimal(totalOrder), 2, RoundingMode.HALF_UP);
+                avgPrice = avgPriceDec.doubleValue();
+            }
+            if (totalPerson > 0) {
+                BigDecimal avgPersonPriceDec = bigDecimal.divide(new BigDecimal(totalPerson), 2, RoundingMode.HALF_UP);
+                avgPersonPrice = avgPersonPriceDec.doubleValue();
+            }
+        }
+        ThreadLocalRandom random = ThreadLocalRandom.current();
+        double compare = random.nextDouble(-1, 1);
         DecimalFormat decimalFormat = new DecimalFormat("#.0");
-        compare = Float.parseFloat(decimalFormat.format(compare));
-
-        objects.get(0).put("value",totalPrice);
-        objects.get(0).put("compare",compare);
-
-        objects.get(1).put("value",orderCount);
-        objects.get(1).put("compare",compare);
-
-        objects.get(2).put("value",orderprice);
-        objects.get(2).put("compare",-compare);
+        compare = Double.parseDouble(decimalFormat.format(compare));
+        objects.get(0).put("value", totalPrice);
+        objects.get(0).put("compare", compare);
 
-        objects.get(3).put("value",price);
-        objects.get(3).put("compare",compare);*/
-        objects.get(0).put("value",100);
-        objects.get(0).put("compare",0.4);
+        objects.get(1).put("value", totalOrder);
+        objects.get(1).put("compare", compare);
 
-        objects.get(1).put("value",2100);
-        objects.get(1).put("compare",0.4);
+        objects.get(2).put("value", avgPersonPrice);
+        objects.get(2).put("compare", compare);
 
-        objects.get(2).put("value",21);
-        objects.get(2).put("compare",-0.4);
-
-        objects.get(3).put("value",1);
-        objects.get(3).put("compare",0.4);
+        objects.get(3).put("value", avgPrice);
+        objects.get(3).put("compare", compare);
         indeicator.setWorthAttention("本月盈利将达12万元");
         indeicator.setList(objects);
         return ReturnMsg.ok(indeicator);
@@ -79,22 +79,22 @@ public class SupermarketServiceImpl implements SupermarketService {
 
     @Override
     public ReturnMsg getQuotientAnalysiss(IocParam iocParam) {
-        String[] param = {"morningTotal","afternoonTotal","morningOrder","afternoonOrder","averageOrder"};
-        String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
+        String[] param = {"morningTotal", "afternoonTotal", "morningOrder", "afternoonOrder", "averageOrder"};
+        String[] labKey = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
         List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
         return ReturnMsg.ok(labels1);
     }
 
     @Override
     public ReturnMsg getProductRanking(IocParam iocParam) {
-        List<Map<String,String>> list =   supermarketOrderMapper.getListByCompanyIdAndDeptId(iocParam);
+        List<Map<String, String>> list = supermarketOrderMapper.getListByCompanyIdAndDeptId(iocParam);
         return ReturnMsg.ok(list);
     }
 
     @Override
     public ReturnMsg getSupermarketInfoList() {
-        String[] param = {"consumptionAmount","consumptionOrder"};
-        String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
+        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);
         return ReturnMsg.ok(labels1);
     }
@@ -103,28 +103,32 @@ public class SupermarketServiceImpl implements SupermarketService {
     public ReturnMsg getSupermarketCoreIndicators() {
         Indeicator indeicator = new Indeicator();
         List<JSONObject> objects = indeicator.getList();
-        ThreadLocalRandom random = ThreadLocalRandom.current();
-        int orderConut = random.nextInt(500, 3000);//订单数
-        int price = random.nextInt(10,50);//单价
-        int thirdPay = random.nextInt(1000,10000);//第三方支付
-        int totalPrice = orderConut*price;//总金额
-        while (thirdPay>totalPrice){
-            thirdPay = random.nextInt(1000,10000);//第三方支付
-        }
-        float compare = (float) Math.random();
         DecimalFormat decimalFormat = new DecimalFormat("#.0");
-        compare = Float.parseFloat(decimalFormat.format(compare));
+        Double totalPrice = supermarketOrderMapper.getTotalPriceByCompanyIdAndDeptId(null);
+        totalPrice = totalPrice == null ? 0 : Double.valueOf(decimalFormat.format(totalPrice));
+        BigDecimal bigDecimal = new BigDecimal(totalPrice);
+        Integer totalOrder = supermarketOrderMapper.getTotalOrderByCompanyIdAndDeptId(null);
+        double avgPrice = 0d;
+        if (totalPrice > 0) {
+            BigDecimal avgPriceDec = bigDecimal.divide(new BigDecimal(totalOrder), 2, RoundingMode.HALF_UP);
+            avgPrice = avgPriceDec.doubleValue();
+        }
+        ThreadLocalRandom random = ThreadLocalRandom.current();
+        Double thirdPay = supermarketOrderMapper.getThirdTotalPriceByCompanyIdAndDeptId();
+        thirdPay = thirdPay == null ? 0 : Double.valueOf(decimalFormat.format(thirdPay));
+        double compare = random.nextDouble(-1, 1);
+        compare = Double.parseDouble(decimalFormat.format(compare));
 
-        objects.get(0).put("value",totalPrice);
-        objects.get(0).put("compare",compare);
+        objects.get(0).put("value", totalPrice);
+        objects.get(0).put("compare", compare);
 
-        objects.get(1).put("value",orderConut);
-        objects.get(1).put("compare",compare);
+        objects.get(1).put("value", totalOrder);
+        objects.get(1).put("compare", compare);
 
-        objects.get(2).put("value",price);
-        objects.get(2).put("compare",compare);
+        objects.get(2).put("value", avgPrice);
+        objects.get(2).put("compare", compare);
 
-        objects.get(3).put("value",thirdPay);
+        objects.get(3).put("value", thirdPay);
 
         indeicator.setWorthAttention("提高合同额");
         indeicator.setList(objects);