Browse Source

打码:长码按客户端所选产品生成,流水号按产品独立累计

  - 镭雕码获取接口新增产品参数(195/196/198),必填,决定长码中的物料代码
  - 未传或传错直接返回提示,不再默认按 195 生成,避免打错产品码
  - 长码固定按产品规则生成,后台打码规则配置不再影响长码
  - 同一产品当天流水号接续递增,不与已有码重复
  - 生成的长码记录所属产线,供包装环节产线校验使用
  - 镭雕码获取接口新增产品参数(195/196/198),必填,决定长码中的物料代码
  - 未传或传错直接返回提示,不再默认按 195 生成,避免打错产品码
  - 长码固定按产品规则生成,后台打码规则配置不再影响长码
  - 同一产品当天流水号接续递增,不与已有码重复
  - 生成的长码记录所属产线,供包装环节产线校验使用
wangxichen 4 days ago
parent
commit
4e554a2b8b

+ 17 - 14
src/main/java/com/jeesite/modules/mes/service/MesProductPreService.java

@@ -65,29 +65,27 @@ public class MesProductPreService extends CrudService<MesProductPreDao, MesProdu
 		return mesProductPreDao.findInfo(mesProductPre);
 	}
 
-	public String getNewSn(String lineSn,String cate){
-		return getNewSn(lineSn,cate,"");
-	}
-
-	// pn:CZ060 产品PN号(195/196/198),为空或不合法时默认195
+	// pn:CZ060 产品PN号(195/196/198),长码必传;前工序码为空或不合法时默认195
 	public String getNewSn(String lineSn,String cate,String pn){
 		//500104004355C230001  cate=1
 		//0050010400435E6348245C120001   cate=2
-		String pre = "CZ060195";
-		if("195".equals(pn) || "196".equals(pn) || "198".equals(pn)){
-			pre = "CZ060" + pn;
+		// pn 为空或非法时按195(长码的必填校验在 getContent 接口层)
+		if(!"195".equals(pn) && !"196".equals(pn) && !"198".equals(pn)){
+			pn = "195";
 		}
-		String pre2 = "F956210325195AI2";
-		if(lineSn.equals("CZ061")){
+		String pre = "CZ060" + pn;
+		// 长码前缀:物料代码最后一位随产品号变化(195->5、196->6、198->8),AI2 为原有固定位
+		String pre2 = "F95621032519" + pn.substring(2) + "AI2";
+		if("CZ061".equals(lineSn)){
 
 		}
 
 		String todayStr = CommonUitl.getYearLastChar()+CommonUitl.getMonthChar()+CommonUitl.getDayChar();
 		String sn = "";
 		String newSn = "";
-		// 检查当前是否配置规则
+		// 检查当前是否配置规则;长码(cate=2)固定按产品拼装,不受规则配置影响
 		MesProductPreConfig mesProductPreConfig = mesProductPreConfigService.checkRuleCate(lineSn,cate);
-		if(!ObjectUtils.isEmpty(mesProductPreConfig)){
+		if(!ObjectUtils.isEmpty(mesProductPreConfig) && !cate.equals("2")){
 			Integer isAuto = 0;
 			List<RuleResp> rules = JSON.parseArray(mesProductPreConfig.getContent(), RuleResp.class);
 			if(!ListUtils.isEmpty(rules)){
@@ -193,6 +191,10 @@ public class MesProductPreService extends CrudService<MesProductPreDao, MesProdu
 				mesProductPre.setCate(cate);
 				mesProductPre.setLineSn(lineSn);
 				mesProductPre.getSqlMap().getWhere().and("a.sn", QueryType.RIGHT_LIKE,sn);
+				if(cate.equals("2")){
+					// 取最大流水,避免重复试探
+					mesProductPre.getSqlMap().getOrder().setOrderBy("a.sn desc");
+				}
 				MesProductPre mesProductPre1 = this.findInfo(mesProductPre);
 				if(!ObjectUtils.isEmpty(mesProductPre1)){
 					if(cate.equals("1")){
@@ -203,9 +205,10 @@ public class MesProductPreService extends CrudService<MesProductPreDao, MesProdu
 							number = no + 1 + i;
 						}
 					}else{
-						String snDate = mesProductPre1.getSn().substring(20,24);
+						// 24位码:前缀(16)+年月日(4)+流水号(4),流水号取第20位之后
+						String snDate = mesProductPre1.getSn().substring(16,20);
 						if(snDate.equals(todayStr)){
-							int no = Integer.valueOf(mesProductPre1.getSn().substring(24,28));
+							int no = Integer.valueOf(mesProductPre1.getSn().substring(20,24));
 							number = no + 1 + i;
 						}
 					}

+ 17 - 1
src/main/java/com/jeesite/modules/mes/web/MesProductHmbController.java

@@ -198,7 +198,22 @@ public class MesProductHmbController extends BaseController {
 			return resp;
 		}
 
-		String sn = mesProductPreService.getNewSn(lineSn,"2");
+		// 产品PN号:195/196/198,必填,决定长码物料段;兼容镭雕机文档里的 type 参数名
+		String pn = request.getParameter("pn");
+		if(StringUtils.isEmpty(pn)){
+			pn = request.getParameter("type");
+		}
+		if(StringUtils.isEmpty(pn)){
+			resp.setResult(Global.FALSE);
+			resp.setMessage("工件类型不能为空");
+			return resp;
+		}
+		if(!"195".equals(pn) && !"196".equals(pn) && !"198".equals(pn)){
+			resp.setResult(Global.FALSE);
+			resp.setMessage("工件类型错误");
+			return resp;
+		}
+		String sn = mesProductPreService.getNewSn(lineSn,"2",pn);
 		if(sn.isEmpty()){
 			resp.setResult(Global.FALSE);
 			resp.setMessage("没有符合要求的镭雕码可生成");
@@ -211,6 +226,7 @@ public class MesProductHmbController extends BaseController {
 		if(check.equals("1")){
 			mesProductHmb3.setState("0");
 		}
+		mesProductHmb3.setLineSn(lineSn);
 		mesProductHmb3.setCreateBy(userCode);
 		mesProductHmb3.setUpdateBy(userCode);
 		this.save(mesProductHmb3);