Przeglądaj źródła

fix(OP105): PDA 码绑定成功后自动提交工位 OK

- 绑定与 OP105 报工在同一事务完成,报工失败时回滚绑定
- OP105 记录当次提交时间,OP100 优先使用打码入库时间,无入库记录时沿用 OP105 提交时间
- 同一对码重试保留原报工时间,解绑时恢复 OP105 待报工状态
wangxichen 6 dni temu
rodzic
commit
905991e43e

+ 2 - 0
src/main/java/com/jeesite/modules/mes/dao/MesProductHmbDao.java

@@ -15,6 +15,8 @@ import org.apache.ibatis.annotations.Param;
 public interface MesProductHmbDao extends CrudDao<MesProductHmb> {
     MesProductHmb findInfo(MesProductHmb mesProductHmb);
 
+    MesProductHmb findForBinding(@Param("sn") String sn);
+
     // 统计计划下已下发的长码数(OP100 打码工位按发码数计数)
     int countByPlan(@Param("planId") String planId);
 }

+ 3 - 0
src/main/java/com/jeesite/modules/mes/dao/MesProductRecordDao.java

@@ -25,6 +25,9 @@ public interface MesProductRecordDao extends CrudDao<MesProductRecord> {
     Boolean updateDate(MesProductRecord mesProductRecord);
     int updateResultByCheckFirst(MesProductRecord mesProductRecord);
 
+    MesProductRecord lockOp105Result(@Param("sn") String sn, @Param("lineSn") String lineSn,
+                                     @Param("oprno") String oprno);
+
     int completeBoundOp100(@Param("sn") String sn, @Param("lineSn") String lineSn,
                            @Param("op105RecordId") String op105RecordId);
 

+ 4 - 0
src/main/java/com/jeesite/modules/mes/service/MesProductHmbService.java

@@ -49,6 +49,10 @@ public class MesProductHmbService extends CrudService<MesProductHmbDao, MesProdu
 	}
 
 
+	public MesProductHmb findForBinding(String sn) {
+		return mesProductHmbDao.findForBinding(sn);
+	}
+
 	public MesProductHmb findInfo(MesProductHmb mesProductHmb) {
 		return mesProductHmbDao.findInfo(mesProductHmb);
 	}

+ 24 - 3
src/main/java/com/jeesite/modules/mes/service/MesProductRecordService.java

@@ -855,6 +855,14 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 		return result;
 	}
 
+	public MesProductRecord requireOp105ResultForUpdate(String sn, String lineSn, String oprno) {
+		MesProductRecord record = mesProductRecordDao.lockOp105Result(sn, lineSn, oprno);
+		if (record == null) {
+			throw new ServiceException(text("未找到 OP105 工位主结果记录"));
+		}
+		return record;
+	}
+
 	/**
 	 * 质量上传(总结果) 100000
 	 */
@@ -871,6 +879,16 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 		String oldOprno = oprno;
 		oprno = CommonUitl.formatOprno(oprno);
 		sn = sn.trim();
+		boolean completeOp105Binding = !checkPlan && "CZ060".equals(lineSn) && "OP105".equals(oprno)
+				&& "100000".equals(craft) && "OK".equals(content);
+		if (completeOp105Binding) {
+			MesProductRecord current = requireOp105ResultForUpdate(sn, lineSn, oldOprno);
+			if ("OK".equals(current.getContent()) && !"1".equals(isRepair)
+					&& !"1".equals(current.getSource()) && !"2".equals(current.getSource())) {
+				mesProductRecordDao.completeBoundOp100(sn, lineSn, current.getId());
+				return;
+			}
+		}
 
 		MesProductRecord mesProductRecord1 = new MesProductRecord();
 		mesProductRecord1.setSn(sn);
@@ -985,10 +1003,14 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 					mesProductRecord.setUpdateBy(userCode);
 				}
 				String oldcontent = mesProductRecord.getContent();
+				String oldSource = mesProductRecord.getSource();
 				mesProductRecord.setMaterielSn(materielSn);
 				mesProductRecord.setContent(content);
+				if (completeOp105Binding) {
+					mesProductRecord.setSource("0");
+				}
 				super.update(mesProductRecord);
-				mesPieceworkService.recordCompletion(mesProductRecord, oldcontent, mesProductRecord.getSource());
+				mesPieceworkService.recordCompletion(mesProductRecord, oldcontent, oldSource);
 
 				FileUploadUtils.saveFileUpload(mesProductRecord, mesProductRecord.getId(), "mesProductRecord_image");
 				FileUploadUtils.saveFileUpload(mesProductRecord, mesProductRecord.getId(), "mesProductRecord_file");
@@ -1012,8 +1034,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 				mesProductModifyRecordService.save(mesProductModifyRecord1);
 
 				// CZ060 PDA 提交 OP105 OK 后补记 OP100,缺少打码入库记录时沿用本次 OP105 时间。
-				if (!checkPlan && "CZ060".equals(lineSn) && "OP105".equals(oprno)
-						&& "100000".equals(craft) && "OK".equals(content)) {
+				if (completeOp105Binding) {
 					mesProductRecordDao.completeBoundOp100(sn, lineSn, mesProductRecord.getId());
 				}
 

+ 56 - 48
src/main/java/com/jeesite/modules/mes/web/MesProductRecordController.java

@@ -17,6 +17,7 @@ import com.jeesite.common.collect.MapUtils;
 import com.jeesite.common.lang.DateUtils;
 import com.jeesite.common.lang.StringUtils;
 import com.jeesite.common.mybatis.mapper.query.QueryType;
+import com.jeesite.common.service.ServiceException;
 import com.jeesite.common.utils.excel.ExcelExport;
 import com.jeesite.modules.file.entity.FileUpload;
 import com.jeesite.modules.file.service.FileUploadService;
@@ -33,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.ui.Model;
@@ -3290,24 +3292,19 @@ public class MesProductRecordController extends BaseController {
 	// 客户端绑定物料接口
 	@PostMapping(value = "pcbind")
 	@ResponseBody
-	@Transactional
+	@Transactional(isolation = Isolation.READ_COMMITTED)
 	public String pcbind(HttpServletRequest request) {
 		mesLogService.apisavexz(request);
 		String sn = request.getParameter("sn");
 		String oprno = request.getParameter("oprno");
 		String lineSn = request.getParameter("lineSn");
-		String userCode = request.getParameter("ucode");
-		String craft = request.getParameter("craft");
+		String userCode = StringUtils.trimToEmpty(request.getParameter("ucode"));
 		String wsn = request.getParameter("wsn");
 
-		String oldOprno = oprno;
-		if(oldOprno.length()==5){
-			oldOprno += "A";
-		}
-
 		if(StringUtils.isEmpty(sn) || StringUtils.isEmpty(oprno) || StringUtils.isEmpty(lineSn) || StringUtils.isEmpty(wsn)){
 			return renderResult(Global.FALSE, text("参数错误!"));
 		}
+		String oldOprno = oprno.length() == 5 ? oprno + "A" : oprno;
 
 		sn = mesProductHmbService.formatHmbSn(sn,oprno,lineSn);
 
@@ -3315,7 +3312,7 @@ public class MesProductRecordController extends BaseController {
 			if(CommonUitl.formatOprno(oldOprno).equals("OP105")){ // 后膨胀梁打码,检查后面板码是否已被绑定
 				// 检验工件码
 				String checkProductSn = Global.getConfig("mes.check.productSn");
-				if(checkProductSn.equals("1")){
+				if("1".equals(checkProductSn)){
 					// 兼容:后梁码规则校验通过(新24位/老28位)或产品型号配置匹配,任一满足即可
 					if(!CommonUitl.checkProductSnHmb(wsn)){
 						MesProductModel mesProductModel = mesProductModelService.checkSnObj(wsn);
@@ -3334,49 +3331,53 @@ public class MesProductRecordController extends BaseController {
 					return renderResult(Global.FALSE, text("底板码与膨胀梁码型号不匹配!"));
 				}
 
-				// 检查前工件码是否已绑定后面板码
-				MesProductHmb mesProductHmb2 = new MesProductHmb();
-				mesProductHmb2.setQsn(sn);
-				MesProductHmb mesProductHmb3 = mesProductHmbService.findInfo(mesProductHmb2);
-				if(!ObjectUtils.isEmpty(mesProductHmb3)){
-					return renderResult(Global.FALSE, text("该工件已绑定后面板码"));
+				boolean submitResult = "CZ060".equals(lineSn);
+				if (submitResult) {
+					mesProductRecordService.requireOp105ResultForUpdate(sn, lineSn, oldOprno);
 				}
 
-				MesProductHmb mesProductHmb = new MesProductHmb();
-				mesProductHmb.setSn(wsn);
-				MesProductHmb mesProductHmb1 = mesProductHmbService.findInfo(mesProductHmb);
-				if(ObjectUtils.isEmpty(mesProductHmb1)){
-					// 补录:长码未录入时自动登记为已验证,并一次性写入绑定关系
-					MesProductHmb mesProductHmbNew = new MesProductHmb();
-					mesProductHmbNew.setSn(wsn);
-					mesProductHmbNew.setState("1");
-					mesProductHmbNew.setQsn(sn);
-					mesProductHmbNew.setLineSn(lineSn);
-					mesProductHmbNew.setCreateBy(userCode);
-					mesProductHmbNew.setUpdateBy(userCode);
-					mesProductHmbService.save(mesProductHmbNew);
-					logger.info("pcbind补录并绑定长码:" + wsn + ",短码:" + sn + ",lineSn:" + lineSn + ",user:" + userCode);
-					return renderResult(Global.TRUE, text("操作成功!"));
+				MesProductHmb boundQuery = new MesProductHmb();
+				boundQuery.setQsn(sn);
+				MesProductHmb bound = mesProductHmbService.findInfo(boundQuery);
+				boolean sameBinding = submitResult && bound != null && wsn.equals(bound.getSn())
+						&& lineSn.equals(bound.getLineSn());
+				if (bound != null && !sameBinding) {
+					return renderResult(Global.FALSE, text("该工件已绑定后面板码"));
 				}
 
-				if(mesProductHmb1.getState().equals("0")){
+				MesProductHmb hmb = mesProductHmbService.findForBinding(wsn);
+				if (hmb == null) {
+					hmb = new MesProductHmb();
+					hmb.setSn(wsn);
+					hmb.setState("1");
+					hmb.setCreateBy(userCode);
+					hmb.setUpdateBy(userCode);
+				}
+				if (!"1".equals(hmb.getState())) {
 					return renderResult(Global.FALSE, text("后面板码未验证"));
 				}
-
-				if(!StringUtils.isEmpty(mesProductHmb1.getQsn())){
+				boolean alreadyBound = sameBinding && sn.equals(hmb.getQsn()) && lineSn.equals(hmb.getLineSn());
+				if (StringUtils.isNotEmpty(hmb.getQsn()) && !alreadyBound) {
 					return renderResult(Global.FALSE, text("后面板码已被绑定"));
 				}
-
-				mesProductHmb1.setQsn(sn);
-				mesProductHmb1.setLineSn(lineSn);
-				mesProductHmbService.save(mesProductHmb1);
+				if (!alreadyBound) {
+					hmb.setQsn(sn);
+					hmb.setLineSn(lineSn);
+					mesProductHmbService.save(hmb);
+				}
+				if (submitResult) {
+					List<BindMaterialResp> materials = mesLineProcessMaterialService.getBindMaterial(oldOprno, lineSn);
+					mesProductRecordService.updateRecordResult(request, sn, oldOprno, "100000", wsn, "OK",
+							userCode, new ArrayList<>(), lineSn, true, materials, "0", false);
+				}
 			}else{
 				return renderResult(Global.FALSE, text("工位不支持绑定!"));
 			}
-			// 本站 OK 由 pcresult 提交时写入,此处不再写记录
 		}catch (Exception e){
-			logger.info(e.getMessage());
-			return renderResult(Global.FALSE, text("操作失败!"));
+			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+			logger.warn("OP105 码绑定或结果提交失败", e);
+			String message = e instanceof ServiceException ? e.getMessage() : "操作失败!";
+			return renderResult(Global.FALSE, text(message));
 		}
 
 		return renderResult(Global.TRUE, text("操作成功!"));
@@ -3408,21 +3409,28 @@ public class MesProductRecordController extends BaseController {
 
 		try{
 			if(CommonUitl.formatOprno(oldOprno).equals("OP105")){ // 后膨胀梁打码,检查后面板码是否已被绑定
-				MesProductHmb mesProductHmb = new MesProductHmb();
-				mesProductHmb.setSn(wsn);
-				mesProductHmb.setQsn(sn);
-				MesProductHmb mesProductHmb1 = mesProductHmbService.findInfo(mesProductHmb);
-				if(ObjectUtils.isEmpty(mesProductHmb1)){
+				boolean cz060 = "CZ060".equals(lineSn);
+				if (cz060) {
+					mesProductRecordService.requireOp105ResultForUpdate(sn, lineSn, oldOprno);
+				}
+				MesProductHmb hmb = mesProductHmbService.findForBinding(wsn);
+				if (hmb == null || !sn.equals(hmb.getQsn()) || (cz060 && !lineSn.equals(hmb.getLineSn()))) {
 					return renderResult(Global.FALSE, text("后面板码未录入系统或未绑定"));
 				}
 
-				mesProductHmb1.setQsn("");
-				mesProductHmbService.save(mesProductHmb1);
+				hmb.setQsn("");
+				mesProductHmbService.save(hmb);
+				if (cz060 && !"100000".equals(craft)) {
+					mesProductRecordService.updateRecord(sn, oldOprno, "100000", "", "UDF", userCode, lineSn);
+				}
+				if (!cz060 || StringUtils.isNotBlank(craft)) {
+					mesProductRecordService.updateRecord(sn, oldOprno, craft, "", "UDF", userCode, lineSn);
+				}
 			}else{
 				return renderResult(Global.FALSE, text("工位不支持解绑!"));
 			}
-			mesProductRecordService.updateRecord(sn,oldOprno,craft,"","UDF",userCode,lineSn);
 		}catch (Exception e){
+			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 			logger.info(e.getMessage());
 			return renderResult(Global.FALSE, text("操作失败!"));
 		}

+ 9 - 0
src/main/resources/mappings/modules/mes/MesProductHmbDao.xml

@@ -22,6 +22,15 @@
         LIMIT 1
     </select>
 
+    <select id="findForBinding" resultType="com.jeesite.modules.mes.entity.MesProductHmb">
+        SELECT id, sn, qsn, state, line_sn AS lineSn, plan_id AS planId,
+               create_by AS createBy, create_date AS createDate,
+               update_by AS updateBy, update_date AS updateDate
+        FROM mes_product_hmb
+        WHERE sn = #{sn}
+        FOR UPDATE
+    </select>
+
     <!-- 统计计划下已下发的长码数(OP100 按发码数计数) -->
     <select id="countByPlan" resultType="int">
         SELECT COUNT(DISTINCT sn)

+ 11 - 0
src/main/resources/mappings/modules/mes/MesProductRecordDao.xml

@@ -83,6 +83,16 @@
         <!-- where sn = #{sn} and oprno = #{oprno} and line_sn = #{lineSn} and craft = #{craft} -->
         where sn = #{sn} and oprno = #{oprno} and craft = #{craft}
     </update>
+    <select id="lockOp105Result" resultType="com.jeesite.modules.mes.entity.MesProductRecord">
+        SELECT id, content, source
+        FROM mes_product_record
+        WHERE sn = #{sn} AND line_sn = #{lineSn} AND craft = '100000'
+          AND oprno IN ('OP105', #{oprno})
+        ORDER BY CASE WHEN oprno = #{oprno} THEN 0 ELSE 1 END, id
+        LIMIT 1
+        FOR UPDATE
+    </select>
+
     <!-- 长码入库时间优先,PDA 补录等无入库记录的情况沿用本次 OP105 OK 的提交时间。 -->
     <update id="completeBoundOp100">
         UPDATE mes_product_record r
@@ -107,6 +117,7 @@
             r.update_by = CASE WHEN bound_hmb.printed_at IS NULL THEN op105.update_by ELSE bound_hmb.create_by END,
             r.update_date = COALESCE(bound_hmb.printed_at, op105.update_date)
         WHERE r.sn = #{sn}
+          AND r.line_sn = #{lineSn}
           AND r.oprno IN ('OP100', 'OP100A')
           AND r.craft = '100000'
           AND r.content = 'UDF'