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() {
|
List list = new ArrayList<>();
|
Map<String,Object> 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)
|
);
|
double percent = (double) finishNum.size() / order.getPlanQty() * 100; // 将百分比表示为小数
|
int roundedPercent = (int) Math.round(percent); // 四舍五入到整数
|
list.add(roundedPercent);
|
list.add(roundedPercent);
|
resultMap.put("workOrderNo",workOrderNo);
|
resultMap.put("planQty",order.getPlanQty().toString());
|
resultMap.put("actualQty",String.valueOf(finishNum.size()));
|
resultMap.put("waterLevel",list);
|
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("barData",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",getLatestCompletedWorkpiece());
|
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);
|
}
|
|
// 获得最新完成工件状态为5
|
public String getLatestCompletedWorkpiece(){
|
QueryWrapper<OmProductionOrdeInfo> wrapper = new QueryWrapper<>();
|
wrapper.select("TOP 1 *");
|
wrapper.eq("order_status","5");
|
wrapper.orderByDesc("actual_end_time");
|
OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(wrapper);
|
return one.getProductNum();
|
}
|
|
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;
|
}
|
|
|
|
}
|