From f16e46fc22ba09a799fa2d8bc854c49845b76e8f Mon Sep 17 00:00:00 2001
From: admin <15939171744@163.com>
Date: 星期四, 12 九月 2024 17:35:00 +0800
Subject: [PATCH] 大屏接口

---
 jcdm-main/src/main/java/com/jcdm/main/bigScreen/controller/BigScreenController.java |  201 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 201 insertions(+), 0 deletions(-)

diff --git a/jcdm-main/src/main/java/com/jcdm/main/bigScreen/controller/BigScreenController.java b/jcdm-main/src/main/java/com/jcdm/main/bigScreen/controller/BigScreenController.java
new file mode 100644
index 0000000..4094ad0
--- /dev/null
+++ b/jcdm-main/src/main/java/com/jcdm/main/bigScreen/controller/BigScreenController.java
@@ -0,0 +1,201 @@
+package com.jcdm.main.bigScreen.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.jcdm.common.core.domain.AjaxResult;
+import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
+import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
+import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
+import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@RequestMapping("/bigScreen")
+@RestController
+public class BigScreenController {
+    @Autowired
+    private IOmProductionOrdeInfoService omProductionOrdeInfoService;
+
+    @Autowired
+    private IDaPassingStationCollectionService daPassingStationCollectionService;
+
+    /**
+     * 璁㈠崟鏁版嵁
+     * **/
+    @GetMapping("/getOrderInformation")
+    public AjaxResult getOrderInformation() {
+        Map<String,String> resultMap = new HashMap<>();
+        List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().orderByDesc(OmProductionOrdeInfo::getCreateTime));
+        OmProductionOrdeInfo order = orderList.get(0); // 鑾峰彇鏈�鏂扮殑涓�鏉¤鍗曚俊鎭�
+        String workOrderNo = order.getWorkOrderNo();
+        List<OmProductionOrdeInfo> finishNum = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>()
+                .eq(OmProductionOrdeInfo::getOrderStatus,"3")
+                .eq(OmProductionOrdeInfo::getWorkOrderNo,workOrderNo)
+        );
+        resultMap.put("workOrderNo",workOrderNo);
+        resultMap.put("planQty",order.getPlanQty().toString());
+        resultMap.put("actualQty",String.valueOf(finishNum.size()));
+        return AjaxResult.success(resultMap);
+    }
+
+    /**
+     * 杩戜竷鏃ュ伐鍗曞畬鎴愮姸鎬佹�昏
+     * **/
+    @GetMapping("completedInThePastSevenDays")
+    public AjaxResult completedInThePastSevenDays(){
+        Map<String,List<String>> map = new HashMap<>();
+        List<String> category = new ArrayList<>();
+        List<String> lineData = new ArrayList<>();
+        QueryWrapper<OmProductionOrdeInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("TOP 7 CAST ( create_time AS DATE ) AS orderDate,COUNT ( * ) AS orderCount");
+        queryWrapper.groupBy("CAST ( create_time AS DATE )");
+        queryWrapper.orderByDesc("OrderDate");
+        List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(queryWrapper);
+        for (OmProductionOrdeInfo omProductionOrdeInfo : list) {
+            category.add(omProductionOrdeInfo.getOrderDate());
+            lineData.add(omProductionOrdeInfo.getOrderCount());
+        }
+        map.put("category",category);
+        map.put("lineData",lineData);
+        return AjaxResult.success(map);
+    }
+
+    /**
+     * 鏈伐浠惰妭鎷嶅钩鍧囧浘
+     * **/
+    @GetMapping("averageBeatChartOfFinalWorkpiece")
+    public AjaxResult averageBeatChartOfFinalWorkpiece(){
+        Integer maxBeatTime = 0; // 鏈�澶ц妭鎷嶆椂闂�
+        List<Integer> weekLineData = new ArrayList();
+        Map map = new HashMap<>();
+        QueryWrapper<DaPassingStationCollection> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("sfc_code,\n" +
+                "    location_code,\n" +
+                "    inbound_time,\n" +
+                "    outbound_time,\n" +
+                "    DATEDIFF(SECOND, inbound_time, outbound_time) AS beatTime");
+        queryWrapper.eq("sfc_code","2408270000011");
+        queryWrapper.orderByDesc("location_code");
+        List<DaPassingStationCollection> list = daPassingStationCollectionService.list(queryWrapper);
+        for (DaPassingStationCollection daPassingStationCollection : list) {
+            if(Integer.valueOf(daPassingStationCollection.getBeatTime()) > maxBeatTime){
+                maxBeatTime = Integer.valueOf(daPassingStationCollection.getBeatTime());
+            }
+            weekLineData.add(Integer.valueOf(daPassingStationCollection.getBeatTime()));
+        }
+        map.put("weekLineData", weekLineData);
+        map.put("maxData",roundUp(maxBeatTime));
+        return AjaxResult.success(map);
+    }
+
+    /**
+     * 鏈�鏂板伐浠惰繃绔欒妭鎷嶇粺璁�
+     * **/
+    @GetMapping("latestWorkpieceTransitRhythmStatistics")
+    public AjaxResult latestWorkpieceTransitRhythmStatistics(){
+        List<List<Object>> resultList = new ArrayList();
+        QueryWrapper<DaPassingStationCollection> queryWrapper = new QueryWrapper<>();
+        queryWrapper.select("location_code  AS locationCode");
+        queryWrapper.groupBy("location_code");
+        queryWrapper.orderByAsc("location_code");
+        List<DaPassingStationCollection> list = daPassingStationCollectionService.list(queryWrapper);
+        for (DaPassingStationCollection daPassingStationCollection : list) {
+            List<Object> itemList = new ArrayList<>();
+            QueryWrapper<DaPassingStationCollection> itemQueryWrapper = new QueryWrapper<>();
+            itemQueryWrapper.select("TOP 1 *,DATEDIFF( SECOND, inbound_time, outbound_time ) AS beatTime");
+            itemQueryWrapper.eq("location_code",daPassingStationCollection.getLocationCode());
+            itemQueryWrapper.orderByDesc("inbound_time");
+            List<DaPassingStationCollection> item = daPassingStationCollectionService.list(itemQueryWrapper);
+            itemList.add(daPassingStationCollection.getLocationCode());
+            itemList.add(item.get(0).getBeatTime());
+            resultList.add(itemList);
+        }
+        return AjaxResult.success(resultList);
+    }
+
+    /**
+     * 杩囩珯鍚堟牸鐜囨帓琛�
+     * **/
+    @GetMapping("passingPassRateRanking")
+    public AjaxResult passingPassRateRanking(){
+        Map map = new HashMap();
+        List xList = new ArrayList();
+        List<DaPassingStationCollection> locationCode = daPassingStationCollectionService.list(new QueryWrapper<DaPassingStationCollection>()
+                .select("location_code as locationCode")
+                .groupBy("location_code"));
+        for (DaPassingStationCollection passingStationCollection : locationCode) {
+            Map map2 = new HashMap();
+            map2.put("name", passingStationCollection.getLocationCode());
+            List<DaPassingStationCollection> ok = daPassingStationCollectionService.list(new QueryWrapper<DaPassingStationCollection>()
+                    .eq("out_rs_sign", 1)
+                    .eq("location_code", passingStationCollection.getLocationCode()));
+            List<DaPassingStationCollection> total = daPassingStationCollectionService.list(new QueryWrapper<DaPassingStationCollection>()
+                    .eq("location_code", passingStationCollection.getLocationCode()));
+            if(ok.size()>0){
+                if(ok == total){
+                    map2.put("value", 100);
+                }else {
+                    map2.put("value", locationPassRate(ok.size(), total.size()));
+                }
+                xList.add(map2);
+            }
+        }
+        map.put("xList", xList);
+        return AjaxResult.success(map);
+    }
+
+    /**
+     * 鏈堝伐鍗曞畬鎴愭暟閲忕粺璁�
+     * **/
+    @GetMapping("monthlyWorkOrderCompletionQuantityStatistics")
+    public AjaxResult monthlyWorkOrderCompletionQuantityStatistics(){
+        List<Map> resultList = new ArrayList<>();
+        for (String lastTwoMonth : getLastTwoMonths()) {
+            Map<String, Object> map = new HashMap<>();
+            List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>()
+                    .eq(OmProductionOrdeInfo::getOrderStatus,"3")
+                    .like(OmProductionOrdeInfo::getCreateTime, lastTwoMonth));
+            map.put("name", lastTwoMonth);
+            map.put("value", list.size());
+            resultList.add(map);
+        }
+        return AjaxResult.success(resultList);
+    }
+
+    public static int locationPassRate(int passRate,int total) {
+        double percentage = (double) passRate / total * 100;
+        long roundedNumber = Math.round(percentage);
+        return (int) roundedNumber;
+    }
+
+    public static int roundUp(int num) {
+        if (num >= 0) {
+            return (num + 10 - 1) / 10 * 10;
+        } else {
+            return (num - 10 + 1) / 10 * 10;
+        }
+    }
+
+    public static List<String> getLastTwoMonths() {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+        Calendar calendar = Calendar.getInstance();
+        calendar.add(Calendar.MONTH, -0);
+        String lastMonth = sdf.format(calendar.getTime());
+        calendar.add(Calendar.MONTH, -1);
+        String currentMonth = sdf.format(calendar.getTime());
+
+        List<String> months = new ArrayList<>();
+        months.add(lastMonth);
+        months.add(currentMonth);
+
+        return months;
+    }
+
+
+
+}

--
Gitblit v1.9.3