|
|
@@ -685,64 +685,89 @@ public class MesProductRecordController extends BaseController {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- // 独立接口:创建订单报文
|
|
|
+ /**
|
|
|
+ * 创建订单的API接口
|
|
|
+ * @param request HttpServletRequest对象,包含请求参数
|
|
|
+ * @return 返回CommonResp对象,包含处理结果和数据
|
|
|
+ **/
|
|
|
@PostMapping(value = "createOrder")
|
|
|
@ResponseBody
|
|
|
public CommonResp createOrderApi(HttpServletRequest request) {
|
|
|
+
|
|
|
+ // 创建通用响应对象
|
|
|
CommonResp<Object> resp = new CommonResp<>();
|
|
|
|
|
|
+ // 记录API调用日志
|
|
|
mesLogService.apisave(request);
|
|
|
- String ret = "";
|
|
|
- String sn = request.getParameter("sn");
|
|
|
- String oprno = request.getParameter("oprno");
|
|
|
- String lineSn = request.getParameter("lineSn");
|
|
|
- String userCode = request.getParameter("ucode");
|
|
|
- String result = request.getParameter("result");
|
|
|
+
|
|
|
+ String ret = ""; // 用于存储处理结果
|
|
|
+
|
|
|
+ // 从请求中获取参数
|
|
|
+ String sn = request.getParameter("sn"); // 产品二维码
|
|
|
+ String oprno = request.getParameter("oprno"); // 工位号
|
|
|
+ String lineSn = request.getParameter("lineSn"); // 产线编号
|
|
|
+ String userCode = request.getParameter("ucode"); // 用户代码
|
|
|
+ String result = request.getParameter("result"); // 结果(OK/NG)
|
|
|
+
|
|
|
+ // 处理工位号,如果长度为5则添加'A'后缀
|
|
|
String oldOprno = oprno;
|
|
|
if (oldOprno.length() == 5) {
|
|
|
oprno += "A";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ // 校验产品二维码是否为空
|
|
|
if (StringUtils.isEmpty(sn)) {
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("PE", "RS"));
|
|
|
resp.setResult(Global.FALSE);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+ // 获取当前产线上的工位信息
|
|
|
MesLineProcess mesLineProcess1 = mesLineProcessService.getOnLineOprno(lineSn);
|
|
|
if (ObjectUtils.isEmpty(mesLineProcess1)) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("OL", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
+
|
|
|
+ // 校验工位号是否匹配
|
|
|
if (!CommonUitl.formatOprno(oprno).equals(mesLineProcess1.getOprno())) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("OM", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
+
|
|
|
+ // 校验结果是否为OK或NG
|
|
|
if (!result.equals("OK") && !result.equals("NG")) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("RM", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+ // 获取产线分类编号
|
|
|
String cateSn = mesLineService.findInfoCate(lineSn);
|
|
|
if (StringUtils.isEmpty(cateSn)) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("CM", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
+
|
|
|
+ // 校验产品二维码是否存在
|
|
|
if (!mesProductCateService.checkSn(sn)) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("GS", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
+
|
|
|
+ // 检查检验记录
|
|
|
if (!mesProcessCheckRecordService.checkRecord(oprno, lineSn)) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("DJ", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+ // 检查产品记录是否已存在
|
|
|
MesProductRecord mpr = mesProductRecordService.findBySnCate(sn, cateSn);
|
|
|
if (!ObjectUtils.isEmpty(mpr)) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
@@ -750,6 +775,8 @@ public class MesProductRecordController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ // 创建产品记录对象
|
|
|
MesProductRecord mesProductRecord = new MesProductRecord();
|
|
|
mesProductRecord.setSn(sn);
|
|
|
mesProductRecord.setOprno(oprno);
|
|
|
@@ -758,27 +785,40 @@ public class MesProductRecordController extends BaseController {
|
|
|
mesProductRecord.setCreateBy(userCode);
|
|
|
mesProductRecord.setCateSn(cateSn);
|
|
|
|
|
|
+
|
|
|
+ // 获取质量参数
|
|
|
List<ParamsResp> params = mesProductRecordService.getQualityParam(oprno, lineSn,result);
|
|
|
+
|
|
|
+ // 添加默认参数
|
|
|
ParamsResp paramsResp2 = new ParamsResp();
|
|
|
paramsResp2.setCraft("100000");
|
|
|
paramsResp2.setResult("OK");
|
|
|
params.add(paramsResp2);
|
|
|
try {
|
|
|
+
|
|
|
+ // 获取绑定物料信息
|
|
|
List<BindMaterialResp> bmlists = mesLineProcessMaterialService.getBindMaterial(oprno, lineSn);
|
|
|
if (!ListUtils.isEmpty(bmlists)) {
|
|
|
+ // 遍历绑定物料列表
|
|
|
for (BindMaterialResp bindMaterialResp : bmlists) {
|
|
|
+
|
|
|
+ // 校验批次号是否为空
|
|
|
if (StringUtils.isEmpty(bindMaterialResp.getBatchSn())) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("BM", "RS"));
|
|
|
return resp;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ // 校验剩余次数
|
|
|
Integer lastTimes = Integer.valueOf(bindMaterialResp.getLastTimes());
|
|
|
if (lastTimes < 1) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("BM", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
+
|
|
|
+ // 创建参数响应对象
|
|
|
ParamsResp paramsRespm = new ParamsResp();
|
|
|
paramsRespm.setCraft(bindMaterialResp.getCraft());
|
|
|
paramsRespm.setResult("OK");
|
|
|
@@ -786,9 +826,12 @@ public class MesProductRecordController extends BaseController {
|
|
|
params.add(paramsRespm);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 添加产品记录
|
|
|
ret = mesProductRecordService.add(mesProductRecord, params, bmlists);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
+ // 异常处理
|
|
|
e.printStackTrace();//RSNS
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("FL", "RS"));
|
|
|
@@ -798,58 +841,83 @@ public class MesProductRecordController extends BaseController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // 返回成功响应
|
|
|
resp.setResult(Global.TRUE);
|
|
|
resp.setData(ret);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
- // 独立接口:工位开始工作报文
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始工作的API接口
|
|
|
+ * @param request HTTP请求对象,包含前端传递的参数
|
|
|
+ * @return 返回一个CommonResp对象,包含操作结果和数据
|
|
|
+ */
|
|
|
@PostMapping(value = "startWork")
|
|
|
@ResponseBody
|
|
|
public CommonResp startWorkApi(HttpServletRequest request) {
|
|
|
+ // 创建响应对象
|
|
|
CommonResp resp = new CommonResp();
|
|
|
|
|
|
+ // 从请求中获取参数:设备序列号(sn)、操作员编号(oprno)、产品类别(productCate)、用户编码(ucode)
|
|
|
String sn = request.getParameter("sn");
|
|
|
String oprno = request.getParameter("oprno");
|
|
|
String productCate = request.getParameter("lineSn");
|
|
|
String ucode = request.getParameter("ucode");
|
|
|
+ // 验证必要参数是否为空
|
|
|
if (StringUtils.isEmpty(sn) || StringUtils.isEmpty(oprno) || StringUtils.isEmpty(productCate)) {
|
|
|
+ // 如果参数为空,设置响应结果为失败,并返回错误信息
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("PE", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
+ // 创建设备时间记录对象
|
|
|
MesDeviceTime mesDeviceTime = new MesDeviceTime();
|
|
|
+ // 设置设备时间记录的属性
|
|
|
mesDeviceTime.setOprno(oprno);
|
|
|
mesDeviceTime.setSn(sn);
|
|
|
mesDeviceTime.setStartDate(new Date());
|
|
|
mesDeviceTime.setProductCate(productCate);
|
|
|
mesDeviceTime.setCreateBy(ucode);
|
|
|
mesDeviceTime.setUpdateBy(ucode);
|
|
|
+ // 初始化返回结果为"RSNS"
|
|
|
String ret = "RSNS";
|
|
|
try {
|
|
|
+ // 调用服务层方法添加设备时间记录,并获取返回结果
|
|
|
ret = mesDeviceTimeService.add(mesDeviceTime);
|
|
|
} catch (Exception e) {
|
|
|
+ // 如果发生异常,设置返回结果为"RSNS"
|
|
|
ret = "RSNS";
|
|
|
}
|
|
|
+ // 设置响应结果为成功,并返回操作结果
|
|
|
resp.setResult(Global.TRUE);
|
|
|
resp.setData(ret);
|
|
|
return resp;
|
|
|
}
|
|
|
-
|
|
|
- // 独立接口:绑定报文
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理产品绑定记录的接口
|
|
|
+ * @param request HTTP请求对象,包含请求参数
|
|
|
+ * @return 返回通用响应对象,包含处理结果和数据
|
|
|
+ */
|
|
|
@PostMapping(value = "bindRecord")
|
|
|
@ResponseBody
|
|
|
public CommonResp bindRecordApi(HttpServletRequest request) {
|
|
|
+ // 创建通用响应对象
|
|
|
CommonResp<Object> resp = new CommonResp<>();
|
|
|
|
|
|
+ // 默认返回值
|
|
|
String ret = "RSNS";
|
|
|
|
|
|
+ // 从请求中获取各个参数
|
|
|
String oprno = request.getParameter("oprno");
|
|
|
String craft = request.getParameter("craft").trim();
|
|
|
String sn = request.getParameter("sn").trim();
|
|
|
String materielSn = request.getParameter("materielSn").trim();
|
|
|
String userCode = request.getParameter("userCode").trim();
|
|
|
String lineSn = request.getParameter("lineSn").trim();
|
|
|
+ // 检查必要参数是否为空
|
|
|
if (StringUtils.isEmpty(craft) || StringUtils.isEmpty(oprno) || StringUtils.isEmpty(sn)
|
|
|
|| StringUtils.isEmpty(lineSn) || StringUtils.isEmpty(materielSn)) {
|
|
|
resp.setResult(Global.FALSE);
|
|
|
@@ -857,31 +925,46 @@ public class MesProductRecordController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
try {
|
|
|
+ // 格式化工位号
|
|
|
String fOprno = CommonUitl.formatOprno(oprno);
|
|
|
+ // 查询模板项列表
|
|
|
List<MesTemplateItems> mesTemplateItemsList = mesTemplateItemsService.findListByOprno(fOprno);
|
|
|
+ // 查询产品记录列表
|
|
|
List<MesProductRecord> mesProductRecordList = mesProductRecordService.findBySnAndOprnoLike(sn, fOprno);
|
|
|
+ // 如果模板项列表不为空
|
|
|
if (!ListUtils.isEmpty(mesTemplateItemsList)) {
|
|
|
+ // 创建已存在工艺的集合
|
|
|
Set<String> existCrafts = new HashSet<>();
|
|
|
+ // 如果产品记录列表不为空,将已存在的工艺添加到集合中
|
|
|
if (!ListUtils.isEmpty(mesProductRecordList)) {
|
|
|
for (MesProductRecord record : mesProductRecordList) {
|
|
|
existCrafts.add(record.getCraft());
|
|
|
}
|
|
|
}
|
|
|
+ // 创建缺失项列表
|
|
|
List<MesTemplateItems> missingItems = new ArrayList<>();
|
|
|
+ // 检查哪些模板项工艺不存在于已存在工艺集合中
|
|
|
for (MesTemplateItems templateItem : mesTemplateItemsList) {
|
|
|
if (!existCrafts.contains(templateItem.getCraft())) {
|
|
|
missingItems.add(templateItem);
|
|
|
}
|
|
|
}
|
|
|
+ // 如果存在缺失项
|
|
|
if (!ListUtils.isEmpty(missingItems)) {
|
|
|
+ // 记录警告日志
|
|
|
logger.warn("产品SN:{}, 工位:{}, 缺失模板项数量:{}", sn, fOprno, missingItems.size());
|
|
|
+ // 查询产品信息
|
|
|
MesProduct mesProduct = mesProductService.findBySn(sn);
|
|
|
if (ObjectUtils.isEmpty(mesProduct)) {
|
|
|
throw new ServiceException(text("产品不存在!"));
|
|
|
}
|
|
|
+ // 获取当前时间戳
|
|
|
Long cdate = Long.valueOf(CommonUitl.Date2TimeStamp(new Date()));
|
|
|
+ // 创建要添加的记录列表
|
|
|
List<MesProductRecord> recordsToAdd = new ArrayList<>();
|
|
|
+ // 初始化最大序列号
|
|
|
int maxSerial = 0;
|
|
|
+ // 如果产品记录列表不为空,找出最大序列号
|
|
|
if (!ListUtils.isEmpty(mesProductRecordList)) {
|
|
|
for (MesProductRecord record : mesProductRecordList) {
|
|
|
if (record.getSerial() != null && record.getSerial() > maxSerial) {
|
|
|
@@ -889,6 +972,7 @@ public class MesProductRecordController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // 为每个缺失项创建新的产品记录
|
|
|
for (MesTemplateItems missingItem : missingItems) {
|
|
|
MesProductRecord newRecord = new MesProductRecord();
|
|
|
newRecord.setSn(sn);
|
|
|
@@ -907,25 +991,30 @@ public class MesProductRecordController extends BaseController {
|
|
|
newRecord.setUpdateDate(new Date());
|
|
|
recordsToAdd.add(newRecord);
|
|
|
}
|
|
|
+ // 如果有待添加的记录,批量插入
|
|
|
if (!ListUtils.isEmpty(recordsToAdd)) {
|
|
|
mesProductRecordService.insertBatch(recordsToAdd, recordsToAdd.size());
|
|
|
+ // 记录信息日志
|
|
|
logger.info("产品SN:{}, 补充创建记录数量:{}", sn, recordsToAdd.size());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // 更新产品记录
|
|
|
mesProductRecordService.updateRecord(sn, oprno, craft, materielSn, "OK", userCode, lineSn);
|
|
|
} catch (Exception e) {
|
|
|
+ // 打印异常堆栈
|
|
|
e.printStackTrace();
|
|
|
resp.setResult(Global.FALSE);
|
|
|
resp.setMessage(ErrorMsg.getErrorMsg("FL", "RS"));
|
|
|
return resp;
|
|
|
}
|
|
|
+ // 设置响应结果和数据
|
|
|
resp.setResult(Global.TRUE);
|
|
|
resp.setData(ret);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
- // 独立接口:解绑报文
|
|
|
+
|
|
|
@PostMapping(value = "unbindRecord")
|
|
|
@ResponseBody
|
|
|
public CommonResp unbindRecordApi(HttpServletRequest request) {
|
|
|
@@ -956,7 +1045,7 @@ public class MesProductRecordController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
- // 独立接口:查询质量报文
|
|
|
+
|
|
|
@PostMapping(value = "checkQualityMsg")
|
|
|
@ResponseBody
|
|
|
public CommonResp checkQualityMsgApi(HttpServletRequest request) {
|
|
|
@@ -983,7 +1072,7 @@ public class MesProductRecordController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
- // 独立接口:上传质量结果报文
|
|
|
+
|
|
|
@PostMapping(value = "updateQualityMsg")
|
|
|
@ResponseBody
|
|
|
public CommonResp updateQualityMsgApi(HttpServletRequest request) {
|
|
|
@@ -1042,7 +1131,7 @@ public class MesProductRecordController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
- // 独立接口:上传设备状态报文
|
|
|
+
|
|
|
@PostMapping(value = "deviceState")
|
|
|
@ResponseBody
|
|
|
public CommonResp deviceStateApi(HttpServletRequest request) {
|
|
|
@@ -1102,7 +1191,7 @@ public class MesProductRecordController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
- // 独立接口:上传参数报文
|
|
|
+
|
|
|
@PostMapping(value = "updateParams")
|
|
|
@ResponseBody
|
|
|
public CommonResp updateParamsApi(HttpServletRequest request) {
|
|
|
@@ -2809,6 +2898,8 @@ public class MesProductRecordController extends BaseController {
|
|
|
return renderResult(Global.TRUE, text("操作成功!"));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// 绑定底护板
|
|
|
@PostMapping(value = "binddhb")
|
|
|
@ResponseBody
|
|
|
@@ -4379,4 +4470,5 @@ public class MesProductRecordController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|