admin
2024-09-12 f16e46fc22ba09a799fa2d8bc854c49845b76e8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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;
    }
 
 
 
}