|
|
|
|
@ -0,0 +1,176 @@
|
|
|
|
|
package com.aucma.production.controller;
|
|
|
|
|
|
|
|
|
|
import com.aucma.base.domain.BaseProcessStation;
|
|
|
|
|
import com.aucma.base.service.IBaseProcessStationService;
|
|
|
|
|
import com.aucma.common.constant.AnDonConstants;
|
|
|
|
|
import com.aucma.common.core.domain.AjaxResult;
|
|
|
|
|
import com.aucma.common.utils.DateUtils;
|
|
|
|
|
import com.aucma.common.utils.SecurityUtils;
|
|
|
|
|
import com.aucma.common.utils.StringUtils;
|
|
|
|
|
import com.aucma.production.domain.AndonEvent;
|
|
|
|
|
import com.aucma.production.domain.AndonRule;
|
|
|
|
|
import com.aucma.production.mapper.AndonRuleMapper;
|
|
|
|
|
import com.aucma.production.service.IAndonEventService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 手持设备安灯呼叫接口(极简版)
|
|
|
|
|
*
|
|
|
|
|
* 业务流程:
|
|
|
|
|
* 1. 手持PDA已绑定工位(stationCode)
|
|
|
|
|
* 2. 用户点击安灯按钮,PDA调用 /call-types 获取该工位可用的呼叫类型
|
|
|
|
|
* 3. PDA显示呼叫类型按钮,用户选择一个
|
|
|
|
|
* 4. PDA调用 /call 发送 stationCode + callTypeCode
|
|
|
|
|
* 5. 后台匹配安灯规则,生成事件并自动派工
|
|
|
|
|
* 6. 大屏看板实时显示事件
|
|
|
|
|
*
|
|
|
|
|
* @author Yinq
|
|
|
|
|
* @date 2025-12-29
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/production/andon/mobile")
|
|
|
|
|
public class AndonMobileController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IBaseProcessStationService baseProcessStationService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AndonRuleMapper andonRuleMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IAndonEventService andonEventService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 【接口1】获取工位可用的呼叫类型列表
|
|
|
|
|
*
|
|
|
|
|
* PDA先调用此接口获取该工位配置的所有呼叫类型,然后显示按钮让用户选择
|
|
|
|
|
*
|
|
|
|
|
* @param stationCode 工位编码
|
|
|
|
|
* @return 呼叫类型列表 [{callTypeCode, callTypeName, ruleName}]
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/call-types")
|
|
|
|
|
public AjaxResult getCallTypes(@RequestParam String stationCode) {
|
|
|
|
|
if (StringUtils.isEmpty(stationCode)) {
|
|
|
|
|
return AjaxResult.error("工位编码不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询该工位配置的所有安灯规则
|
|
|
|
|
AndonRule ruleQuery = new AndonRule();
|
|
|
|
|
ruleQuery.setStationCode(stationCode);
|
|
|
|
|
ruleQuery.setIsFlag(AnDonConstants.FLAG_VALID);
|
|
|
|
|
List<AndonRule> rules = andonRuleMapper.selectAndonRuleList(ruleQuery);
|
|
|
|
|
|
|
|
|
|
if (rules == null || rules.isEmpty()) {
|
|
|
|
|
return AjaxResult.error("该工位未配置安灯规则,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建返回数据
|
|
|
|
|
List<Map<String, Object>> callTypes = new ArrayList<>();
|
|
|
|
|
for (AndonRule rule : rules) {
|
|
|
|
|
Map<String, Object> item = new LinkedHashMap<>();
|
|
|
|
|
item.put("callTypeCode", rule.getCallTypeCode());
|
|
|
|
|
item.put("ruleName", rule.getRuleName());
|
|
|
|
|
item.put("ruleId", rule.getRuleId());
|
|
|
|
|
callTypes.add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success(callTypes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 【接口2】提交安灯呼叫
|
|
|
|
|
*
|
|
|
|
|
* @param stationCode 工位编码(必填)
|
|
|
|
|
* @param callTypeCode 呼叫类型编码(必填)- 从 /call-types 接口获取
|
|
|
|
|
* @return 创建的安灯事件信息
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/call")
|
|
|
|
|
public AjaxResult submitAndonCall(@RequestParam String stationCode,
|
|
|
|
|
@RequestParam String callTypeCode) {
|
|
|
|
|
System.out.println("stationCode: " + stationCode + ", callTypeCode: " + callTypeCode);
|
|
|
|
|
// 参数校验
|
|
|
|
|
if (StringUtils.isEmpty(stationCode)) {
|
|
|
|
|
return AjaxResult.error("工位编码不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isEmpty(callTypeCode)) {
|
|
|
|
|
return AjaxResult.error("呼叫类型不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1. 根据 stationCode 查询工位信息
|
|
|
|
|
BaseProcessStation stationQuery = new BaseProcessStation();
|
|
|
|
|
stationQuery.setProcessCode(stationCode);
|
|
|
|
|
List<BaseProcessStation> stations = baseProcessStationService.selectBaseProcessStationList(stationQuery);
|
|
|
|
|
if (stations == null || stations.isEmpty()) {
|
|
|
|
|
return AjaxResult.error("工位不存在:" + stationCode);
|
|
|
|
|
}
|
|
|
|
|
BaseProcessStation station = stations.get(0);
|
|
|
|
|
String productLineCode = station.getProductLineCode();
|
|
|
|
|
|
|
|
|
|
// 2. 根据 stationCode + callTypeCode 匹配安灯规则
|
|
|
|
|
AndonRule ruleQuery = new AndonRule();
|
|
|
|
|
ruleQuery.setStationCode(stationCode);
|
|
|
|
|
ruleQuery.setCallTypeCode(callTypeCode);
|
|
|
|
|
ruleQuery.setIsFlag(AnDonConstants.FLAG_VALID);
|
|
|
|
|
List<AndonRule> rules = andonRuleMapper.selectAndonRuleList(ruleQuery);
|
|
|
|
|
if (rules == null || rules.isEmpty()) {
|
|
|
|
|
return AjaxResult.error("未找到该工位+呼叫类型的安灯规则");
|
|
|
|
|
}
|
|
|
|
|
AndonRule rule = rules.get(0);
|
|
|
|
|
|
|
|
|
|
// 3. 构建安灯事件
|
|
|
|
|
AndonEvent event = new AndonEvent();
|
|
|
|
|
|
|
|
|
|
// 生成呼叫单号
|
|
|
|
|
event.setCallCode(generateCallCode());
|
|
|
|
|
|
|
|
|
|
// 从规则获取呼叫类型
|
|
|
|
|
event.setCallTypeCode(rule.getCallTypeCode());
|
|
|
|
|
|
|
|
|
|
// 从工位获取产线
|
|
|
|
|
event.setProductLineCode(productLineCode);
|
|
|
|
|
event.setStationCode(stationCode);
|
|
|
|
|
|
|
|
|
|
// 呼叫人(可选,默认为PDA)
|
|
|
|
|
event.setCreateBy(SecurityUtils.getLoginUser().getUserId() != null ? SecurityUtils.getLoginUser().getUserId().toString() : "PDA");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 触发源类型:工位
|
|
|
|
|
event.setSourceType(AnDonConstants.SourceType.STATION);
|
|
|
|
|
|
|
|
|
|
// 初始状态
|
|
|
|
|
event.setEventStatus(AnDonConstants.EventStatus.PENDING);
|
|
|
|
|
event.setIsFlag(AnDonConstants.FLAG_VALID);
|
|
|
|
|
event.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
|
|
|
|
|
// 4. 调用服务保存(自动匹配规则、计算时限、创建派工)
|
|
|
|
|
int result = andonEventService.insertAndonEvent(event);
|
|
|
|
|
|
|
|
|
|
if (result > 0) {
|
|
|
|
|
Map<String, Object> data = new LinkedHashMap<>();
|
|
|
|
|
data.put("eventId", event.getEventId());
|
|
|
|
|
data.put("callCode", event.getCallCode());
|
|
|
|
|
data.put("stationName", station.getStationName() != null ? station.getStationName() : station.getProcessName());
|
|
|
|
|
data.put("callType", rule.getRuleName());
|
|
|
|
|
data.put("message", "安灯呼叫成功,已通知相关人员");
|
|
|
|
|
return AjaxResult.success(data);
|
|
|
|
|
} else {
|
|
|
|
|
return AjaxResult.error("安灯呼叫失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成呼叫单号
|
|
|
|
|
* 格式:AD + 年月日时分秒 + 3位随机数
|
|
|
|
|
*/
|
|
|
|
|
private String generateCallCode() {
|
|
|
|
|
String dateStr = DateUtils.dateTimeNow("yyyyMMddHHmmss");
|
|
|
|
|
int random = (int) (Math.random() * 900) + 100; // 100-999
|
|
|
|
|
return "AD" + dateStr + random;
|
|
|
|
|
}
|
|
|
|
|
}
|