Files
FT546-WCS/ruoyi-admin/src/main/java/com/ruoyi/api/controller/ScreenController.java
liuhanqing cb2c0c032d 初始化
2025-11-17 16:53:33 +08:00

124 lines
4.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.ruoyi.api.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.device.ssj.domain.DeviceSsj;
import com.ruoyi.device.ssj.service.IDeviceSsjService;
import com.ruoyi.job.domain.MydoJob;
import com.ruoyi.job.service.IMydoJobService;
/**
* 大屏接口Controller
*
* @author ruoyi
*/
@Anonymous
@RestController
@RequestMapping("/api/screen")
public class ScreenController extends BaseController {
@Autowired
private IDeviceSsjService deviceSsjService;
@Autowired
private IMydoJobService mydoJobService;
// 定义各区域输送机编号数组
private static final Map<Integer, List<String>> AREA_SSJ_CODES = new HashMap<>();
// 静态初始化输送机编号数组
static {
// 1区域输送机编号
AREA_SSJ_CODES.put(1, Arrays.asList(
"L2007","L2008","L2005","L2006","L2013"
));
// 2区域输送机编号
AREA_SSJ_CODES.put(2, Arrays.asList(
"L2003","L2004","L2012","L2001","L2002"
));
// 3区域输送机编号
AREA_SSJ_CODES.put(3, Arrays.asList(
"L1001","L1002","L1011"
));
// 4区域输送机编号
AREA_SSJ_CODES.put(4, Arrays.asList(
"L1003","L1004","L1012"
));
}
/**
* 根据区域编号查询输送机列表
*
* @param areaNum 区域编号(1-4)
* @return 输送机数据列表
*/
@PostMapping("/ssj/{areaNum}")
public AjaxResult getSsjListByArea(@PathVariable("areaNum") Integer areaNum) {
if (areaNum < 1 || areaNum > 4) {
return AjaxResult.error("区域编号必须在1-4之间");
}
// 获取该区域的输送机编号数组
List<String> ssjCodes = AREA_SSJ_CODES.get(areaNum);
if (ssjCodes == null || ssjCodes.isEmpty()) {
return AjaxResult.error("未找到该区域的输送机编号配置");
}
// 查询所有输送机
List<DeviceSsj> allSsjList = deviceSsjService.selectDeviceSsjList(null);
// 根据编号数组筛选输送机
List<DeviceSsj> filteredList = allSsjList.stream()
.filter(ssj -> ssj.getDeviceCode() != null && ssjCodes.contains(ssj.getDeviceCode().trim()))
.collect(Collectors.toList());
// 转换为前端需要的数据格式
List<Map<String, Object>> resultList = new ArrayList<>();
// 创建作业信息列表
List<MydoJob> jobList = new ArrayList<>();
for (DeviceSsj ssj : filteredList) {
Map<String, Object> map = new HashMap<>();
map.put("id", ssj.getDeviceCode());
map.put("name", ssj.getName());
map.put("kx", String.valueOf(ssj.getKx()));
map.put("dw", String.valueOf(ssj.getDw()));
map.put("sbzt", ssj.getException());
// map.put("trayCode", ssj.getTrayCode());
map.put("allowPut", String.valueOf(ssj.getAllowPut()));
map.put("traySize", String.valueOf(ssj.getTraySize()));
map.put("exception", String.valueOf(ssj.getException()));
map.put("taskNo", ssj.getTaskNo());
resultList.add(map);
// 如果taskNo大于0,查询对应的作业信息
if (ssj.getTaskNo()> 0) {
MydoJob job = mydoJobService.selectMydoJobByTaskNo(Long.valueOf(ssj.getTaskNo()));
if (job != null) {
jobList.add(job);
}
}
}
// 返回结果包含data和job两个字段
Map<String, Object> result = new HashMap<>();
result.put("ssj", resultList);
result.put("job", jobList);
return AjaxResult.success(result);
}
}