Преглед изворни кода

● fix(piecework): 修复update方法未设置piecework_date的问题
问题:
- 客户端提交工位结果调用的是update()方法
- 之前只在save()中添加了计件时间逻辑
- 导致实际业务中piecework_date未被设置

修复:
- 新增setPieceworkDateIfNeeded()私有方法
- 在save()中调用setPieceworkDateIfNeeded()
- 在所有super.update()调用前(共7处)添加setPieceworkDateIfNeeded()
- 修改3个统计查询方法:getSj/getSjOk/getSjOkType改用piecework_date

保护逻辑:
- 优先检查传入对象的piecework_date是否已有值
- 如果有值直接返回,不修改
- 只在首次从UDF变为OK/NG且piecework_date为null时才设置
- 防止人为改成UDF再改回OK时覆盖已有的计件时间

影响范围:
- MesProductRecord.java (新增piecework_date字段)
- MesProductRecordService.java (新增方法+修改save和7处update)

wangxichen пре 1 дан
родитељ
комит
a21c0d178d
1 измењених фајлова са 26 додато и 11 уклоњено
  1. 26 11
      src/main/java/com/jeesite/modules/mes/service/MesProductRecordService.java

+ 26 - 11
src/main/java/com/jeesite/modules/mes/service/MesProductRecordService.java

@@ -123,23 +123,31 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 	@Autowired
 	private MesProductDhbService mesProductDhbService;
 
+	/**
+	 * 设置计件时间:首次从UDF变为OK或NG时记录
+	 */
+	private void setPieceworkDateIfNeeded(MesProductRecord mesProductRecord) {
+		if (StringUtils.isEmpty(mesProductRecord.getId()) || mesProductRecord.getPieceworkDate() != null) {
+			return;
+		}
+
+		MesProductRecord oldRecord = super.get(mesProductRecord);
+		if (oldRecord != null
+			&& "UDF".equals(oldRecord.getContent())
+			&& !"UDF".equals(mesProductRecord.getContent())
+			&& !StringUtils.isEmpty(mesProductRecord.getContent())) {
+			mesProductRecord.setPieceworkDate(new Date());
+		}
+	}
+
 	@Override
 	public void save(MesProductRecord mesProductRecord) {
 		if (StringUtils.isEmpty(mesProductRecord.getSource())) {
 			mesProductRecord.setSource("0");
 		}
 
-		// 计件时间逻辑:首次从UDF变为OK或NG时,记录计件时间
-		if (!StringUtils.isEmpty(mesProductRecord.getId())) {
-			MesProductRecord oldRecord = super.get(mesProductRecord);
-			if (oldRecord != null
-				&& "UDF".equals(oldRecord.getContent())
-				&& !"UDF".equals(mesProductRecord.getContent())
-				&& !StringUtils.isEmpty(mesProductRecord.getContent())
-				&& mesProductRecord.getPieceworkDate() == null) {
-				mesProductRecord.setPieceworkDate(new Date());
-			}
-		}
+		// 设置计件时间
+		setPieceworkDateIfNeeded(mesProductRecord);
 
 		super.save(mesProductRecord);
 	}
@@ -776,6 +784,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 							mesProductRecord.setOprno(oldOprno);
 						}
 						mesProductRecord.setSource("0");
+						setPieceworkDateIfNeeded(mesProductRecord);
 						super.update(mesProductRecord);
 						break;
 					}
@@ -789,6 +798,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 				}
 				mesProductRecord.setMaterielSn(mesLineProcess1.getDevices());
 				mesProductRecord.setContent("OK");
+				setPieceworkDateIfNeeded(mesProductRecord);
 				super.update(mesProductRecord);
 			}else if(mesProductRecord.getCraft().equals("400003")){
 				if(!oldOprno.equals(oprno)){
@@ -796,6 +806,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 				}
 				mesProductRecord.setMaterielSn(mesLineProcess1.getGzs());
 				mesProductRecord.setContent("OK");
+				setPieceworkDateIfNeeded(mesProductRecord);
 				super.update(mesProductRecord);
 			}
 
@@ -811,6 +822,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 
 				mesProductRecord.setMaterielSn(materielSn);
 				mesProductRecord.setContent(content);
+				setPieceworkDateIfNeeded(mesProductRecord);
 				super.update(mesProductRecord);
 			}
 		}
@@ -1153,6 +1165,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 		mesProductRecord.setMaterielSn(materielSn);
 		mesProductRecord.setContent(content);
 		mesProductRecord.setSource("0");
+		setPieceworkDateIfNeeded(mesProductRecord);
 		super.update(mesProductRecord);
 
 		/*if(CommonUitl.formatOprno(oprno).equals("OP290") && craft.equals("400002")){
@@ -1242,6 +1255,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 
 		mesProductRecord.setMaterielSn(materielSn);
 		mesProductRecord.setContent(content);
+		setPieceworkDateIfNeeded(mesProductRecord);
 		super.update(mesProductRecord);
 
 		// 更新用户
@@ -1273,6 +1287,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 
 		mesProductRecord.setMaterielSn("");
 		mesProductRecord.setContent(content);
+		setPieceworkDateIfNeeded(mesProductRecord);
 		super.update(mesProductRecord);
 
 		if(!craft.equals("400001")){ // 不是绑定操作人员的