|
@@ -46,6 +46,11 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
@Service
|
|
@Service
|
|
|
public class MesProductRecordService extends CrudService<MesProductRecordDao, MesProductRecord> {
|
|
public class MesProductRecordService extends CrudService<MesProductRecordDao, MesProductRecord> {
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 无计划拦截总开关配置key(js_sys_config.config_key)
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final String PLAN_INTERCEPT_CONFIG = "mes.plan.intercept";
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MesProductRecordDao mesProductRecordDao;
|
|
private MesProductRecordDao mesProductRecordDao;
|
|
|
|
|
|
|
@@ -160,13 +165,38 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
if (StringUtils.isEmpty(mesProductRecord.getSource())) {
|
|
if (StringUtils.isEmpty(mesProductRecord.getSource())) {
|
|
|
mesProductRecord.setSource("0");
|
|
mesProductRecord.setSource("0");
|
|
|
}
|
|
}
|
|
|
|
|
+ // 兜底补计划:记录未带计划时,按工件已关联的计划补齐(只补空,不覆盖已有计划)
|
|
|
|
|
+ if (StringUtils.isBlank(mesProductRecord.getPlanId())
|
|
|
|
|
+ && StringUtils.isNotBlank(mesProductRecord.getSn())) {
|
|
|
|
|
+ String planId = mesProductPlanService.getPlanIdByProductSn(mesProductRecord.getSn());
|
|
|
|
|
+ if (StringUtils.isNotBlank(planId)) {
|
|
|
|
|
+ mesProductRecord.setPlanId(planId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
super.save(mesProductRecord);
|
|
super.save(mesProductRecord);
|
|
|
}
|
|
}
|
|
|
public Long insertBatch(List<MesProductRecord> mesProductRecordList,int num) {
|
|
public Long insertBatch(List<MesProductRecord> mesProductRecordList,int num) {
|
|
|
|
|
+ boolean needPlan = false;
|
|
|
|
|
+ String sn = null;
|
|
|
for (MesProductRecord record : mesProductRecordList) {
|
|
for (MesProductRecord record : mesProductRecordList) {
|
|
|
if (StringUtils.isEmpty(record.getSource())) {
|
|
if (StringUtils.isEmpty(record.getSource())) {
|
|
|
record.setSource("0");
|
|
record.setSource("0");
|
|
|
}
|
|
}
|
|
|
|
|
+ if (StringUtils.isBlank(record.getPlanId()) && StringUtils.isNotBlank(record.getSn())) {
|
|
|
|
|
+ needPlan = true;
|
|
|
|
|
+ sn = record.getSn();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 兜底补计划:整批记录未带计划时,按工件已关联的计划一次性补齐(只补空,不覆盖已有计划)
|
|
|
|
|
+ if (needPlan) {
|
|
|
|
|
+ String planId = mesProductPlanService.getPlanIdByProductSn(sn);
|
|
|
|
|
+ if (StringUtils.isNotBlank(planId)) {
|
|
|
|
|
+ for (MesProductRecord record : mesProductRecordList) {
|
|
|
|
|
+ if (StringUtils.isBlank(record.getPlanId()) && sn.equals(record.getSn())) {
|
|
|
|
|
+ record.setPlanId(planId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return mesProductRecordDao.insertBatch(mesProductRecordList,num);
|
|
return mesProductRecordDao.insertBatch(mesProductRecordList,num);
|
|
|
}
|
|
}
|
|
@@ -274,6 +304,88 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
return mesProductPlan;
|
|
return mesProductPlan;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 无计划拦截总开关(js_sys_config:mes.plan.intercept)。
|
|
|
|
|
+ * 0=关闭拦截(应急/灰度),其它值(含未配置)=开启拦截。
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean isPlanInterceptEnabled() {
|
|
|
|
|
+ String cfg = Global.getConfig(PLAN_INTERCEPT_CONFIG);
|
|
|
|
|
+ if (cfg == null) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return !"0".equals(cfg.trim());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 提交工位结果前校验生产计划:工件必须关联有效的生产计划,否则拦截作业。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 计划来源依次为:
|
|
|
|
|
+ * 1) 当前记录上的 plan_id(新建工件时已写入)
|
|
|
|
|
+ * 2) 工件级 mes_product.plan_id
|
|
|
|
|
+ * 3) 该工件其它记录上的 plan_id
|
|
|
|
|
+ * 4) 按当前班次(班次开始日期+班次+工件类型)自动匹配,匹配到即回写自愈
|
|
|
|
|
+ * 都取不到则拦截。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param sn 工件码
|
|
|
|
|
+ * @param cateSn 工件类型
|
|
|
|
|
+ * @param isRepair 是否返修(1=返修,返修不拦截,沿用原记录计划)
|
|
|
|
|
+ * @param recordPlanId 当前记录已带的生产计划id(可为空)
|
|
|
|
|
+ * @return 命中的生产计划;拦截关闭或返修时返回 null
|
|
|
|
|
+ */
|
|
|
|
|
+ private MesProductPlan requirePlan(String sn, String cateSn, String isRepair, String recordPlanId) {
|
|
|
|
|
+ if (!isPlanInterceptEnabled()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("1".equals(isRepair)) { // 返修不拦截,返修件不占用计划产量
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String planId = recordPlanId;
|
|
|
|
|
+ if (StringUtils.isBlank(planId)) {
|
|
|
|
|
+ planId = mesProductPlanService.getPlanIdByProductSn(sn);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(planId)) {
|
|
|
|
|
+ planId = mesProductRecordDao.findPlanIdBySn(sn);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(planId)) {
|
|
|
|
|
+ // 已有计划:校验计划有效性(计划失效、订单未下发在此抛出)
|
|
|
|
|
+ return mesProductPlanService.getValidPlan(planId);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 无计划:按当前班次自动匹配并回写(自愈)
|
|
|
|
|
+ MesProductPlan plan = autoBindCurrentPlan(sn, cateSn);
|
|
|
|
|
+ if (plan == null) {
|
|
|
|
|
+ throw new ServiceException(text("该工件未关联生产计划(订单-计划-工件),当前班次无有效生产计划,不能作业!"));
|
|
|
|
|
+ }
|
|
|
|
|
+ return plan;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 无计划工件按当前班次自动匹配生产计划,并把计划回写到工件与生产记录上。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param sn 工件码
|
|
|
|
|
+ * @param cateSn 工件类型
|
|
|
|
|
+ * @return 匹配到的生产计划;无匹配时返回 null
|
|
|
|
|
+ */
|
|
|
|
|
+ private MesProductPlan autoBindCurrentPlan(String sn, String cateSn) {
|
|
|
|
|
+ if (StringUtils.isBlank(cateSn)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ MesProductPlan plan = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ plan = mesProductPlanService.getCurrentPlan(cateSn);
|
|
|
|
|
+ } catch (ServiceException e) {
|
|
|
|
|
+ // 未匹配到班次、计划重复等异常,交由上层给出明确提示
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ } catch (RuntimeException e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (plan == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ mesProductPlanService.bindPlanToProduct(sn, plan.getId());
|
|
|
|
|
+ mesProductRecordDao.updatePlanIdBySn(sn, plan.getId());
|
|
|
|
|
+ return plan;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 保存数据(插入或更新)
|
|
* 保存数据(插入或更新)
|
|
@@ -327,6 +439,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
mpr1.setTid(mesTemplateItems.getId());
|
|
mpr1.setTid(mesTemplateItems.getId());
|
|
|
mpr1.setCdate(cdate);
|
|
mpr1.setCdate(cdate);
|
|
|
mpr1.setContent("UDF");
|
|
mpr1.setContent("UDF");
|
|
|
|
|
+ mpr1.setPlanId(mesProductPlan.getId());
|
|
|
if(mesTemplateItems.getOprno().equals(oprno)){
|
|
if(mesTemplateItems.getOprno().equals(oprno)){
|
|
|
mpr1.setOprno(mesProductRecord.getOprno());
|
|
mpr1.setOprno(mesProductRecord.getOprno());
|
|
|
mpr1.setContent("OK");
|
|
mpr1.setContent("OK");
|
|
@@ -387,6 +500,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
mpr1.setCdate(cdate);
|
|
mpr1.setCdate(cdate);
|
|
|
mpr1.setContent("UDF");
|
|
mpr1.setContent("UDF");
|
|
|
mpr1.setSource(source);
|
|
mpr1.setSource(source);
|
|
|
|
|
+ mpr1.setPlanId(mesProductPlan.getId());
|
|
|
if(mesTemplateItems.getOprno().equals(oprno)){
|
|
if(mesTemplateItems.getOprno().equals(oprno)){
|
|
|
mpr1.setOprno(mesProductRecord.getOprno());
|
|
mpr1.setOprno(mesProductRecord.getOprno());
|
|
|
mpr1.setContent(mesProductRecord.getContent());
|
|
mpr1.setContent(mesProductRecord.getContent());
|
|
@@ -520,6 +634,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
mpr1.setTreeLevel(0);
|
|
mpr1.setTreeLevel(0);
|
|
|
mpr1.setCdate(cdate);
|
|
mpr1.setCdate(cdate);
|
|
|
mpr1.setContent("UDF");
|
|
mpr1.setContent("UDF");
|
|
|
|
|
+ mpr1.setPlanId(mesProductPlan.getId());
|
|
|
if(mesTemplateItems.getOprno().equals(oprno)){
|
|
if(mesTemplateItems.getOprno().equals(oprno)){
|
|
|
mpr1.setOprno(mesProductRecord.getOprno());
|
|
mpr1.setOprno(mesProductRecord.getOprno());
|
|
|
mpr1.setContent(mesProductRecord.getContent());
|
|
mpr1.setContent(mesProductRecord.getContent());
|
|
@@ -616,11 +731,18 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
content = content.equals("OK")?"OK":"NG";
|
|
content = content.equals("OK")?"OK":"NG";
|
|
|
|
|
|
|
|
String cateSn = "";
|
|
String cateSn = "";
|
|
|
|
|
+ String recordPlanId = null;
|
|
|
for (MesProductRecord mesProductRecord : lists){
|
|
for (MesProductRecord mesProductRecord : lists){
|
|
|
cateSn = mesProductRecord.getCateSn();
|
|
cateSn = mesProductRecord.getCateSn();
|
|
|
|
|
+ if (StringUtils.isBlank(recordPlanId)) {
|
|
|
|
|
+ recordPlanId = mesProductRecord.getPlanId();
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 无计划拦截:提交工位结果前,工件必须关联有效的生产计划(订单-计划-工件)
|
|
|
|
|
+ requirePlan(sn, cateSn, isRepair, recordPlanId);
|
|
|
|
|
+
|
|
|
if(bmlists!=null&&bmlists.size() > 0){
|
|
if(bmlists!=null&&bmlists.size() > 0){
|
|
|
for (BindMaterialResp bindMaterialResp:bmlists){
|
|
for (BindMaterialResp bindMaterialResp:bmlists){
|
|
|
ParamsResp paramsResp = new ParamsResp();
|
|
ParamsResp paramsResp = new ParamsResp();
|
|
@@ -719,7 +841,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
mesProductModifyRecord1.setLineSn(mesProductRecord.getLineSn());
|
|
mesProductModifyRecord1.setLineSn(mesProductRecord.getLineSn());
|
|
|
mesProductModifyRecord1.setContent(content);
|
|
mesProductModifyRecord1.setContent(content);
|
|
|
mesProductModifyRecord1.setContentOld(oldcontent);
|
|
mesProductModifyRecord1.setContentOld(oldcontent);
|
|
|
- if(isRepair.equals("1")){
|
|
|
|
|
|
|
+ if("1".equals(isRepair)){
|
|
|
mesProductModifyRecord1.setSource("3"); // 来自返修
|
|
mesProductModifyRecord1.setSource("3"); // 来自返修
|
|
|
}else{
|
|
}else{
|
|
|
mesProductModifyRecord1.setSource("0");
|
|
mesProductModifyRecord1.setSource("0");
|
|
@@ -1016,6 +1138,9 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
throw new ServiceException(text("记录不存在!"));
|
|
throw new ServiceException(text("记录不存在!"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 无计划拦截:提交工位结果前,工件必须关联有效的生产计划(订单-计划-工件)
|
|
|
|
|
+ requirePlan(sn, mesProductRecord.getCateSn(), null, mesProductRecord.getPlanId());
|
|
|
|
|
+
|
|
|
if(oldOprno.length() == 6){
|
|
if(oldOprno.length() == 6){
|
|
|
mesProductRecord.setOprno(oldOprno);
|
|
mesProductRecord.setOprno(oldOprno);
|
|
|
}
|
|
}
|
|
@@ -1065,6 +1190,9 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
throw new ServiceException(text("记录不存在!"));
|
|
throw new ServiceException(text("记录不存在!"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 无计划拦截:提交工位结果前,工件必须关联有效的生产计划(订单-计划-工件)
|
|
|
|
|
+ requirePlan(sn, mesProductRecord.getCateSn(), null, mesProductRecord.getPlanId());
|
|
|
|
|
+
|
|
|
if(oldOprno.length() == 6){
|
|
if(oldOprno.length() == 6){
|
|
|
mesProductRecord.setOprno(oldOprno);
|
|
mesProductRecord.setOprno(oldOprno);
|
|
|
}
|
|
}
|
|
@@ -1096,6 +1224,9 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
|
|
|
throw new ServiceException(text("记录不存在!"));
|
|
throw new ServiceException(text("记录不存在!"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 无计划拦截:提交工位结果前,工件必须关联有效的生产计划(订单-计划-工件)
|
|
|
|
|
+ requirePlan(sn, mesProductRecord.getCateSn(), null, mesProductRecord.getPlanId());
|
|
|
|
|
+
|
|
|
if(oldOprno.length() == 6){
|
|
if(oldOprno.length() == 6){
|
|
|
mesProductRecord.setOprno(oldOprno);
|
|
mesProductRecord.setOprno(oldOprno);
|
|
|
}
|
|
}
|