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 resultMap = new HashMap<>(); List orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper().orderByDesc(OmProductionOrdeInfo::getCreateTime)); OmProductionOrdeInfo order = orderList.get(0); // 获取最新的一条订单信息 String workOrderNo = order.getWorkOrderNo(); List finishNum = omProductionOrdeInfoService.list(new LambdaQueryWrapper() .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> map = new HashMap<>(); List category = new ArrayList<>(); List lineData = new ArrayList<>(); QueryWrapper 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 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 weekLineData = new ArrayList(); Map map = new HashMap<>(); QueryWrapper 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 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> resultList = new ArrayList(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.select("location_code AS locationCode"); queryWrapper.groupBy("location_code"); queryWrapper.orderByAsc("location_code"); List list = daPassingStationCollectionService.list(queryWrapper); for (DaPassingStationCollection daPassingStationCollection : list) { List itemList = new ArrayList<>(); QueryWrapper 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 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 locationCode = daPassingStationCollectionService.list(new QueryWrapper() .select("location_code as locationCode") .groupBy("location_code")); for (DaPassingStationCollection passingStationCollection : locationCode) { Map map2 = new HashMap(); map2.put("name", passingStationCollection.getLocationCode()); List ok = daPassingStationCollectionService.list(new QueryWrapper() .eq("out_rs_sign", 1) .eq("location_code", passingStationCollection.getLocationCode())); List total = daPassingStationCollectionService.list(new QueryWrapper() .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 resultList = new ArrayList<>(); for (String lastTwoMonth : getLastTwoMonths()) { Map map = new HashMap<>(); List list = omProductionOrdeInfoService.list(new LambdaQueryWrapper() .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 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 months = new ArrayList<>(); months.add(lastMonth); months.add(currentMonth); return months; } }