339 lines
12 KiB
Java
339 lines
12 KiB
Java
package com.ruoyi.index.controller;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
||
import com.ruoyi.job.domain.MydoJob;
|
||
import com.ruoyi.job.service.IMydoJobService;
|
||
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 com.ruoyi.common.core.controller.BaseController;
|
||
import com.ruoyi.common.core.domain.AjaxResult;
|
||
import com.ruoyi.device.DeviceCar.service.IDeviceCarService;
|
||
import com.ruoyi.queue.agv.service.IAgvQueueService;
|
||
import com.ruoyi.queue.agv.service.IAgvQueueFinishService;
|
||
import com.ruoyi.device.ssj.service.IDeviceSsjService;
|
||
import com.ruoyi.device.DeviceCar.domain.DeviceCar;
|
||
import com.ruoyi.queue.agv.domain.AgvQueue;
|
||
import com.ruoyi.queue.agv.domain.AgvQueueFinish;
|
||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||
|
||
/**
|
||
* 首页数据Controller
|
||
*
|
||
* @author ruoyi
|
||
* @date 2025-01-08
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/index")
|
||
public class IndexController extends BaseController {
|
||
@Autowired
|
||
private IDeviceCarService deviceCarService;
|
||
|
||
@Autowired
|
||
private IAgvQueueService agvQueueService;
|
||
|
||
@Autowired
|
||
private IAgvQueueFinishService agvQueueFinishService;
|
||
|
||
@Autowired
|
||
private IDeviceSsjService deviceSsjService;
|
||
|
||
@Autowired
|
||
private IMsgDdjService msgDdjService;
|
||
|
||
@Autowired
|
||
private IMydoJobService mydoJobService;
|
||
|
||
|
||
/**
|
||
* 获取设备统计数据
|
||
*/
|
||
@GetMapping("/deviceStats")
|
||
public AjaxResult getDeviceStats() {
|
||
try {
|
||
DeviceCar deviceCar = new DeviceCar();
|
||
MsgDdj msgDdj = new MsgDdj();
|
||
DeviceSsj deviceSsj = new DeviceSsj();
|
||
List<DeviceCar> deviceList = deviceCarService.selectDeviceCarList(deviceCar);
|
||
List<MsgDdj> msgDdjList = msgDdjService.selectMsgDdjList(msgDdj);
|
||
List<DeviceSsj> deviceSsjList = deviceSsjService.selectDeviceSsjList(deviceSsj);
|
||
|
||
Map<String, Object> count = new HashMap<>();
|
||
|
||
count.put("agvCount", deviceList.size());
|
||
count.put("ddjCount", msgDdjList.size());
|
||
count.put("ssjCount", deviceSsjList.size());
|
||
|
||
return AjaxResult.success(count);
|
||
} catch (Exception e) {
|
||
return AjaxResult.error("获取设备统计数据失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取任务统计数据
|
||
*/
|
||
@GetMapping("/taskStats")
|
||
public AjaxResult getTaskStats() {
|
||
try {
|
||
MydoJob mydoJob = new MydoJob();
|
||
AgvQueue agvQueue = new AgvQueue();
|
||
List<AgvQueue> queueList = agvQueueService.selectAgvQueueList(agvQueue);
|
||
List<MydoJob> mydoJobList = mydoJobService.selectMydoJobList(mydoJob);
|
||
List<MydoJob> mydoJobFinishList = mydoJobService.selectMydoJobFinishList(mydoJob);
|
||
|
||
int pendingCount = 0;
|
||
int runningCount = 0;
|
||
int finishedCount = 0;
|
||
|
||
for (MydoJob job : mydoJobList) {
|
||
String status = job.getStatus();
|
||
if ("2".equals(status)) {
|
||
pendingCount++;
|
||
} else if ("3".equals(status)) {
|
||
runningCount++;
|
||
}
|
||
}
|
||
|
||
for (MydoJob Fjob : mydoJobFinishList) {
|
||
String status = Fjob.getStatus();
|
||
if ("4".equals(status)) {
|
||
finishedCount++;
|
||
}
|
||
}
|
||
|
||
|
||
Map<String, Object> stats = new HashMap<>();
|
||
stats.put("pendingCount", pendingCount);
|
||
stats.put("runningCount", runningCount);
|
||
stats.put("finishedCount", finishedCount);
|
||
|
||
return AjaxResult.success(stats);
|
||
} catch (Exception e) {
|
||
return AjaxResult.error("获取任务统计数据失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取当前任务队列
|
||
*/
|
||
@GetMapping("/currentTasks")
|
||
public AjaxResult getCurrentTasks() {
|
||
try {
|
||
MydoJob mydoJobParam = new MydoJob();
|
||
mydoJobParam.setStatus("3");
|
||
List<MydoJob> mydoJobList = mydoJobService.selectMydoJobList(mydoJobParam);
|
||
return AjaxResult.success(mydoJobList);
|
||
} catch (Exception e) {
|
||
return AjaxResult.error("获取当前任务队列失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取运行中的设备列表
|
||
*/
|
||
@GetMapping("/deviceList")
|
||
public AjaxResult getDeviceList() {
|
||
try {
|
||
List<Map<String, Object>> runningDevices = new ArrayList<>();
|
||
|
||
// 查询运行中的AGV和CTU设备
|
||
DeviceCar deviceCar = new DeviceCar();
|
||
List<DeviceCar> deviceList = deviceCarService.selectDeviceCarList(deviceCar);
|
||
|
||
for (DeviceCar device : deviceList) {
|
||
String taskNo = device.getTaskNo();
|
||
// 判断是否为运行中设备:taskNo不为空且不为0
|
||
if (taskNo != null && !taskNo.trim().isEmpty() && !"0".equals(taskNo.trim())) {
|
||
Map<String, Object> deviceInfo = new HashMap<>();
|
||
deviceInfo.put("deviceCode", device.getDeviceCode());
|
||
deviceInfo.put("deviceName", device.getName());
|
||
deviceInfo.put("deviceType", "AGV");
|
||
deviceInfo.put("taskNo", device.getTaskNo());
|
||
runningDevices.add(deviceInfo);
|
||
}
|
||
}
|
||
|
||
// 查询运行中的SSJ设备
|
||
DeviceSsj deviceSsj = new DeviceSsj();
|
||
List<DeviceSsj> ssjList = deviceSsjService.selectDeviceSsjList(deviceSsj);
|
||
|
||
for (DeviceSsj ssj : ssjList) {
|
||
int taskNo = ssj.getTaskNo();
|
||
// 判断是否为运行中设备:taskNo不为0
|
||
if (taskNo != 0) {
|
||
Map<String, Object> deviceInfo = new HashMap<>();
|
||
deviceInfo.put("deviceCode", ssj.getDeviceCode());
|
||
deviceInfo.put("deviceName", ssj.getName());
|
||
deviceInfo.put("deviceType", "SSJ");
|
||
deviceInfo.put("taskNo", String.valueOf(ssj.getTaskNo()));
|
||
runningDevices.add(deviceInfo);
|
||
}
|
||
}
|
||
|
||
MsgDdj msgDdj = new MsgDdj();
|
||
List<MsgDdj> msgDdjList = msgDdjService.selectMsgDdjList(msgDdj);
|
||
|
||
for (MsgDdj ddj : msgDdjList){
|
||
Long taskNo = ddj.getRwh();
|
||
if (taskNo != 0){
|
||
HashMap<String, Object> deviceInfo = new HashMap<>();
|
||
deviceInfo.put("deviceCode",ddj.getId());
|
||
deviceInfo.put("deviceName", ddj.getName());
|
||
deviceInfo.put("deviceType", "DDJ");
|
||
deviceInfo.put("taskNo", ddj.getRwh());
|
||
runningDevices.add(deviceInfo);
|
||
}
|
||
}
|
||
|
||
return AjaxResult.success(runningDevices);
|
||
} catch (Exception e) {
|
||
return AjaxResult.error("获取运行中设备列表失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取任务类型分布数据
|
||
*/
|
||
@GetMapping("/taskTypeChart")
|
||
public AjaxResult getTaskTypeChart() {
|
||
try {
|
||
MydoJob mydoJob = new MydoJob();
|
||
List<MydoJob> mydoJobFinishList = mydoJobService.selectMydoJobFinishList(mydoJob);
|
||
|
||
Map<String, Integer> inOrOutCount = new HashMap<>();
|
||
|
||
// 统计完成任务的 inOrOut 类型
|
||
for (MydoJob job : mydoJobFinishList) {
|
||
String inOrOut = job.getInOrOut();
|
||
if (inOrOut != null && !inOrOut.isEmpty()) {
|
||
inOrOutCount.put(inOrOut, inOrOutCount.getOrDefault(inOrOut, 0) + 1);
|
||
}
|
||
}
|
||
|
||
List<Map<String, Object>> chartData = new ArrayList<>();
|
||
for (Map.Entry<String, Integer> entry : inOrOutCount.entrySet()) {
|
||
Map<String, Object> item = new HashMap<>();
|
||
// 使用字典工具类获取字典标签
|
||
String dictLabel = com.ruoyi.common.utils.DictUtils.getDictLabel("in_or_out", entry.getKey());
|
||
// 如果没有找到对应的字典标签,则使用原始值
|
||
item.put("name", dictLabel != null && !dictLabel.isEmpty() ? dictLabel : entry.getKey());
|
||
item.put("value", entry.getValue());
|
||
chartData.add(item);
|
||
}
|
||
|
||
return AjaxResult.success(chartData);
|
||
} catch (Exception e) {
|
||
return AjaxResult.error("获取任务类型分布数据失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取设备状态分布数据
|
||
*/
|
||
@GetMapping("/deviceStatusChart")
|
||
public AjaxResult getDeviceStatusChart() {
|
||
try {
|
||
Map<String, Map<String, Integer>> statusCount = new HashMap<>();
|
||
statusCount.put("AGV", new HashMap<>());
|
||
statusCount.put("DDJ", new HashMap<>());
|
||
statusCount.put("SSJ", new HashMap<>());
|
||
|
||
// 查询DeviceCar数据(AGV)
|
||
DeviceCar deviceCar = new DeviceCar();
|
||
List<DeviceCar> deviceList = deviceCarService.selectDeviceCarList(deviceCar);
|
||
|
||
for (DeviceCar device : deviceList) {
|
||
String taskNo = device.getTaskNo();
|
||
String status = "其他";
|
||
// 根据taskNo判断状态:不等于空或0时为运行状态
|
||
if (taskNo != null && !taskNo.trim().isEmpty() && !"0".equals(taskNo.trim())) {
|
||
status = "运行";
|
||
}
|
||
Map<String, Integer> typeStatusCount = statusCount.get("AGV");
|
||
typeStatusCount.put(status, typeStatusCount.getOrDefault(status, 0) + 1);
|
||
|
||
}
|
||
|
||
// 查询DeviceSsj数据(SSJ)
|
||
DeviceSsj deviceSsj = new DeviceSsj();
|
||
List<DeviceSsj> ssjList = deviceSsjService.selectDeviceSsjList(deviceSsj);
|
||
|
||
for (DeviceSsj ssj : ssjList) {
|
||
int taskNo = ssj.getTaskNo();
|
||
String status = "其他";
|
||
|
||
// 根据taskNo判断状态:不等于空或0时为运行状态
|
||
if (taskNo != 0) {
|
||
status = "运行";
|
||
}
|
||
|
||
Map<String, Integer> typeStatusCount = statusCount.get("SSJ");
|
||
typeStatusCount.put(status, typeStatusCount.getOrDefault(status, 0) + 1);
|
||
}
|
||
|
||
MsgDdj msgDdj = new MsgDdj();
|
||
List<MsgDdj> msgDdjList = msgDdjService.selectMsgDdjList(msgDdj);
|
||
|
||
for (MsgDdj ddj : msgDdjList){
|
||
Long taskNo = ddj.getRwh();
|
||
String status = "其他";
|
||
if (taskNo!=0){
|
||
status = "运行";
|
||
}
|
||
Map<String,Integer> typeStatusCount = statusCount.get("DDJ");
|
||
typeStatusCount.put(status,typeStatusCount.getOrDefault(status,0) + 1);
|
||
}
|
||
|
||
return AjaxResult.success(statusCount);
|
||
} catch (Exception e) {
|
||
return AjaxResult.error("获取设备状态分布数据失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取首页综合数据
|
||
*/
|
||
@GetMapping("/dashboard")
|
||
public AjaxResult getDashboardData() {
|
||
try {
|
||
Map<String, Object> dashboardData = new HashMap<>();
|
||
|
||
// 获取设备统计
|
||
AjaxResult deviceStatsResult = getDeviceStats();
|
||
if (deviceStatsResult.get("code").equals(200)) {
|
||
dashboardData.put("deviceStats", deviceStatsResult.get("data"));
|
||
}
|
||
|
||
// 获取任务统计
|
||
AjaxResult taskStatsResult = getTaskStats();
|
||
if (taskStatsResult.get("code").equals(200)) {
|
||
dashboardData.put("taskStats", taskStatsResult.get("data"));
|
||
}
|
||
|
||
// 获取当前任务
|
||
AjaxResult currentTasksResult = getCurrentTasks();
|
||
if (currentTasksResult.get("code").equals(200)) {
|
||
dashboardData.put("currentTasks", currentTasksResult.get("data"));
|
||
}
|
||
|
||
// 获取设备列表
|
||
AjaxResult deviceListResult = getDeviceList();
|
||
if (deviceListResult.get("code").equals(200)) {
|
||
dashboardData.put("deviceList", deviceListResult.get("data"));
|
||
}
|
||
|
||
return AjaxResult.success(dashboardData);
|
||
} catch (Exception e) {
|
||
return AjaxResult.error("获取首页数据失败");
|
||
}
|
||
}
|
||
}
|