Преглед на файлове

智能看板和智享生活商超模块柱状图数据接口修改

ZhangManMan преди 2 години
родител
ревизия
c22de5c810

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

@@ -1,5 +1,6 @@
 package com.sky.ioc.controller.dashboard;
 
+import com.sky.ioc.entity.params.IocParam;
 import com.sky.ioc.service.supermarket.SupermarketService;
 import com.sky.ioc.tool.ReturnMsg;
 import io.swagger.annotations.Api;
@@ -8,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -35,16 +37,16 @@ public class SupermarketController {
 
     @ApiOperation("查询智能看板统计画像的商超核心指标")
     @GetMapping("getSupermarketCoreIndicators")
-    public ReturnMsg getSupermarketCoreIndicators(){
-        return supermarketService.getSupermarketCoreIndicators();
+    public ReturnMsg getSupermarketCoreIndicators(@RequestBody IocParam iocParam){
+        return supermarketService.getSupermarketCoreIndicators(iocParam);
     }
 
 
 
     @ApiOperation("查询智能看板统计画像的商超信息报表")
     @GetMapping("getSupermarketInfoList")
-    public ReturnMsg  getSupermarketInfoList(){
-        return supermarketService.getSupermarketInfoList();
+    public ReturnMsg  getSupermarketInfoList(@RequestBody IocParam iocParam){
+        return supermarketService.getSupermarketInfoList(iocParam);
     }
 
 

+ 2 - 2
src/main/java/com/sky/ioc/service/supermarket/SupermarketService.java

@@ -18,7 +18,7 @@ public interface SupermarketService {
 
     ReturnMsg getProductRanking(IocParam iocParam);
 
-    ReturnMsg getSupermarketInfoList();
+    ReturnMsg getSupermarketInfoList(IocParam iocParam);
 
-    ReturnMsg getSupermarketCoreIndicators();
+    ReturnMsg getSupermarketCoreIndicators(IocParam iocParam);
 }

+ 75 - 8
src/main/java/com/sky/ioc/service/supermarket/impl/SupermarketServiceImpl.java

@@ -5,8 +5,10 @@ import com.sky.ioc.entity.Indeicator;
 import com.sky.ioc.entity.Label;
 import com.sky.ioc.entity.domain.supermarket.SupermarketOrder;
 import com.sky.ioc.entity.params.IocParam;
+import com.sky.ioc.entity.params.IocTimeRange;
 import com.sky.ioc.mapper.SupermarketOrderMapper;
 import com.sky.ioc.service.supermarket.SupermarketService;
+import com.sky.ioc.tool.DateUtil;
 import com.sky.ioc.tool.FalseData;
 import com.sky.ioc.tool.GeneralMethod;
 import com.sky.ioc.tool.ReturnMsg;
@@ -16,6 +18,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.DecimalFormat;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ThreadLocalRandom;
@@ -80,8 +83,50 @@ 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月"};
-        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]);
+       // String[] labKey = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
+       // List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
+        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]+" 12:00:00");
+            iocParam1.setTimeRange(iocTimeRange);
+            IocParam iocParam2 = new IocParam();
+            IocTimeRange iocTimeRange2 = new IocTimeRange();
+            iocTimeRange2.setStartDate(labKey[i]+" 12:00:01");
+            iocTimeRange2.setEndDate(labKey[i]+" 23:59:59");
+            iocParam2.setTimeRange(iocTimeRange2);
+            //上午
+            Double totalPrice = supermarketOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam1);
+            totalPrice = totalPrice == null ? 0 : Double.valueOf(decimalFormat.format(totalPrice));
+            Integer totalOrder = supermarketOrderMapper.getTotalOrderByCompanyIdAndDeptId(iocParam1);
+            //下午
+            Double afternoonTotalPrice = supermarketOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam2);
+            afternoonTotalPrice = afternoonTotalPrice == null ? 0 : Double.valueOf(decimalFormat.format(afternoonTotalPrice));
+            Integer afternoonTotalOrder = supermarketOrderMapper.getTotalOrderByCompanyIdAndDeptId(iocParam2);
+            BigDecimal bigDecimal = new BigDecimal(totalPrice+afternoonTotalPrice);
+            double avgPrice = 0d;
+            if (totalPrice+afternoonTotalPrice > 0) {
+                BigDecimal avgPriceDec = bigDecimal.divide(new BigDecimal(totalOrder+afternoonTotalOrder), 2, RoundingMode.HALF_UP);
+                avgPrice = avgPriceDec.doubleValue();
+            }
+            jsonObject.put(param[0],totalPrice);
+            jsonObject.put(param[1],afternoonTotalPrice);
+            jsonObject.put(param[2],totalOrder);
+            jsonObject.put(param[3],afternoonTotalOrder);
+            jsonObject.put(param[4],avgPrice);
+            label.setJsonObject(jsonObject);
+            label.setLabel(labKey[i]);
+            labels1.add(label);
+        }
         return ReturnMsg.ok(labels1);
     }
 
@@ -92,22 +137,44 @@ public class SupermarketServiceImpl implements SupermarketService {
     }
 
     @Override
-    public ReturnMsg getSupermarketInfoList() {
+    public ReturnMsg getSupermarketInfoList(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 = GeneralMethod.getInstance().dataGeneration(param, labKey);
+        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:59");
+            iocParam1.setTimeRange(iocTimeRange);
+            Double totalPrice = supermarketOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam1);
+            totalPrice = totalPrice == null ? 0 : Double.valueOf(decimalFormat.format(totalPrice));
+            Integer totalOrder = supermarketOrderMapper.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);
     }
 
     @Override
-    public ReturnMsg getSupermarketCoreIndicators() {
+    public ReturnMsg getSupermarketCoreIndicators(IocParam iocParam) {
         Indeicator indeicator = new Indeicator();
         List<JSONObject> objects = indeicator.getList();
         DecimalFormat decimalFormat = new DecimalFormat("#.0");
-        Double totalPrice = supermarketOrderMapper.getTotalPriceByCompanyIdAndDeptId(null);
+        Double totalPrice = supermarketOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam);
         totalPrice = totalPrice == null ? 0 : Double.valueOf(decimalFormat.format(totalPrice));
         BigDecimal bigDecimal = new BigDecimal(totalPrice);
-        Integer totalOrder = supermarketOrderMapper.getTotalOrderByCompanyIdAndDeptId(null);
+        Integer totalOrder = supermarketOrderMapper.getTotalOrderByCompanyIdAndDeptId(iocParam);
         double avgPrice = 0d;
         if (totalPrice > 0) {
             BigDecimal avgPriceDec = bigDecimal.divide(new BigDecimal(totalOrder), 2, RoundingMode.HALF_UP);

+ 40 - 1
src/main/java/com/sky/ioc/tool/DateUtil.java

@@ -412,9 +412,43 @@ public class DateUtil {
 
     }
 
+    /**
+     *  获取两个日期之间的所有日期 (年月日)
+     *
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    public static List<String> getBetweenDays(String startTime, String endTime){
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
+        // 声明保存日期集合
+        List<String> list = new ArrayList<String>();
+        try {
+            // 转化成日期类型
+            Date startDate = sdf.parse(startTime);
+            Date endDate = sdf.parse(endTime);
+            //用Calendar 进行日期比较判断
+            Calendar calendar = Calendar.getInstance();
+            while (startDate.getTime()<=endDate.getTime()){
+                // 把日期添加到集合
+                list.add(sdf.format(startDate));
+                // 设置日期
+                calendar.setTime(startDate);
+                //把日期增加一天
+                calendar.add(Calendar.DATE, 1);
+                // 获取增加后的日期
+                startDate=calendar.getTime();
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return list;
+    }
+
+
     public static void main(String[] args) throws Exception {
 
-        Map todayTime = getTodayTime();
+      /*  Map todayTime = getTodayTime();
         System.out.println("今天:" + todayTime.toString());
 
         Map yesterdayTime = getYesterdayTime();
@@ -425,6 +459,11 @@ public class DateUtil {
 
         Map lastMonthTime = getLastMonthTime();
         System.out.println("上个月:" + lastMonthTime.toString());
+*/
+        String startStr = "2021-02-26 00:00:00";
+        String endStr = "2021-03-09 00:00:00";
+        List<String> list = getBetweenDays(startStr, endStr);
+        System.out.println(list);
     }
 
 }

+ 1 - 0
src/main/java/com/sky/ioc/tool/GeneralMethod.java

@@ -50,4 +50,5 @@ public class GeneralMethod {
         }
         return list;
     }
+
 }