|
|
@@ -885,6 +885,104 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 气密结果提交前保障 OP206 主结果记录存在。
|
|
|
+ * 仅作用于 CZ060 的 OP206,其他产线和其他气密工位保持原有逻辑。
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void ensureOp206StationRecord(String sn, String oprno, String lineSn, String userCode) {
|
|
|
+ if (StringUtils.isBlank(sn) || StringUtils.isBlank(oprno) || !"CZ060".equals(lineSn)
|
|
|
+ || !"OP206".equals(CommonUitl.formatOprno(oprno))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String normalizedSn = sn.trim();
|
|
|
+ MesProductRecord targetQuery = new MesProductRecord();
|
|
|
+ targetQuery.getSqlMap().getWhere()
|
|
|
+ .and("a.sn", QueryType.EQ, normalizedSn)
|
|
|
+ .and("a.oprno", QueryType.EQ, "OP206")
|
|
|
+ .and("a.craft", QueryType.EQ, "100000")
|
|
|
+ .and("a.line_sn", QueryType.EQ, "CZ060");
|
|
|
+ if (!ListUtils.isEmpty(findList(targetQuery))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ MesProductRecord anchorQuery = new MesProductRecord();
|
|
|
+ anchorQuery.getSqlMap().getWhere()
|
|
|
+ .and("a.sn", QueryType.EQ, normalizedSn)
|
|
|
+ .and("a.line_sn", QueryType.EQ, "CZ060")
|
|
|
+ .and("a.tid", QueryType.NE, "");
|
|
|
+ anchorQuery.setOrderBy("a.serial ASC, a.create_date ASC, a.id ASC");
|
|
|
+ List<MesProductRecord> anchors = findList(anchorQuery);
|
|
|
+ if (ListUtils.isEmpty(anchors)) {
|
|
|
+ throw new ServiceException(text("未找到该工件的生产记录,无法补建 OP206 工位记录!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ MesProductRecord anchor = null;
|
|
|
+ MesTemplateItems op206TemplateItem = null;
|
|
|
+ for (MesProductRecord candidate : anchors) {
|
|
|
+ MesTemplateItems sourceTemplateItem = mesTemplateItemsService.get(candidate.getTid());
|
|
|
+ if (sourceTemplateItem == null || StringUtils.isBlank(sourceTemplateItem.getTemplateId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ MesTemplateItems itemQuery = new MesTemplateItems();
|
|
|
+ itemQuery.setTemplateId(sourceTemplateItem.getTemplateId());
|
|
|
+ itemQuery.setStatus("0");
|
|
|
+ itemQuery.getSqlMap().getWhere()
|
|
|
+ .and("a.oprno", QueryType.EQ, "OP206")
|
|
|
+ .and("a.craft", QueryType.EQ, "100000");
|
|
|
+ MesTemplateItems matchedItem = mesTemplateItemsService.findInfo(itemQuery);
|
|
|
+ if (matchedItem != null) {
|
|
|
+ anchor = candidate;
|
|
|
+ op206TemplateItem = matchedItem;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (anchor == null || op206TemplateItem == null) {
|
|
|
+ throw new ServiceException(text("工件的生产模板未配置 OP206 工位结果,请先执行 OP206 配置脚本!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ MesTemplateItems listQuery = new MesTemplateItems();
|
|
|
+ listQuery.setTemplateId(op206TemplateItem.getTemplateId());
|
|
|
+ listQuery.setStatus("0");
|
|
|
+ List<MesTemplateItems> templateItems = mesTemplateItemsService.findList(listQuery);
|
|
|
+ if (ListUtils.isEmpty(templateItems)) {
|
|
|
+ throw new ServiceException(text("生产模板明细为空,无法补建 OP206 工位记录!"));
|
|
|
+ }
|
|
|
+ int serial = -1;
|
|
|
+ for (int i = 0; i < templateItems.size(); i++) {
|
|
|
+ if (op206TemplateItem.getId().equals(templateItems.get(i).getId())) {
|
|
|
+ serial = i + 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (serial < 0) {
|
|
|
+ throw new ServiceException(text("无法确定 OP206 工位在模板中的排序,请检查生产模板!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ MesProductRecord missingRecord = new MesProductRecord();
|
|
|
+ missingRecord.setSn(normalizedSn);
|
|
|
+ missingRecord.setOprno("OP206");
|
|
|
+ missingRecord.setCraft("100000");
|
|
|
+ missingRecord.setSerial(serial);
|
|
|
+ missingRecord.setCateSn(anchor.getCateSn());
|
|
|
+ missingRecord.setPlanId(anchor.getPlanId());
|
|
|
+ missingRecord.setLineSn("CZ060");
|
|
|
+ missingRecord.setTid(op206TemplateItem.getId());
|
|
|
+ missingRecord.setPid("0");
|
|
|
+ missingRecord.setTreeLevel(0);
|
|
|
+ missingRecord.setCdate(Long.valueOf(CommonUitl.Date2TimeStamp(new Date())));
|
|
|
+ missingRecord.setContent("UDF");
|
|
|
+ missingRecord.setSource("0");
|
|
|
+ if (StringUtils.isNotBlank(userCode)) {
|
|
|
+ missingRecord.setCreateBy(userCode);
|
|
|
+ missingRecord.setUpdateBy(userCode);
|
|
|
+ }
|
|
|
+ save(missingRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 质量上传(总结果) 100000
|
|
|
*/
|
|
|
@Transactional
|