Ver código fonte

fix: 修复MES辅助模块

wangxichen 6 dias atrás
pai
commit
b4f8680cbf

+ 22 - 0
src/main/java/com/jeesite/modules/mes/service/MesLineProcessService.java

@@ -1,5 +1,6 @@
 package com.jeesite.modules.mes.service;
 package com.jeesite.modules.mes.service;
 
 
+import java.util.Collections;
 import java.util.List;
 import java.util.List;
 
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
@@ -48,6 +49,27 @@ public class MesLineProcessService extends CrudService<MesLineProcessDao, MesLin
 		return entity;
 		return entity;
 	}
 	}
 
 
+	public MesLineProcess findActiveStation(String lineSn, String oprno) {
+		MesLineProcess query = new MesLineProcess();
+		query.setStatus("0");
+		query.getSqlMap().getWhere()
+				.and("b.sn", QueryType.EQ, lineSn)
+				.and("a.oprno", QueryType.EQ, oprno);
+		return findInfo(query);
+	}
+
+	public List<MesLineProcess> findActiveSubProcesses(String lineSn, String parentOprno) {
+		MesLineProcess parent = findActiveStation(lineSn, parentOprno);
+		if (parent == null || StringUtils.isNotBlank(parent.getPid())) {
+			return Collections.emptyList();
+		}
+		MesLineProcess query = new MesLineProcess();
+		query.setStatus("0");
+		query.setPid(parent.getId());
+		query.getSqlMap().getWhere().and("b.sn", QueryType.EQ, lineSn);
+		return findList(query);
+	}
+
 	public MesLineProcess findInfo(MesLineProcess mesLineProcess){
 	public MesLineProcess findInfo(MesLineProcess mesLineProcess){
 		return mesLineProcessDao.findInfo(mesLineProcess);
 		return mesLineProcessDao.findInfo(mesLineProcess);
 	}
 	}

+ 5 - 0
src/main/java/com/jeesite/modules/mes/util/CommonUitl.java

@@ -56,6 +56,11 @@ public class CommonUitl {
         return  str;
         return  str;
     }
     }
 
 
+    /** 兼容只传工件或工位参数的旧 PDA。 */
+    public static String resolvePdaQueryLine(String lineSn) {
+        return StringUtils.isBlank(lineSn) || "XT".equals(lineSn.trim()) ? "CZ060" : lineSn.trim();
+    }
+
     /**
     /**
      * 格式化工位号
      * 格式化工位号
      * @param oprno
      * @param oprno

+ 9 - 15
src/main/java/com/jeesite/modules/mes/web/MesLineProcessController.java

@@ -641,23 +641,17 @@ public class MesLineProcessController extends BaseController {
 	@RequestMapping(value = "subProcessList")
 	@RequestMapping(value = "subProcessList")
 	@ResponseBody
 	@ResponseBody
 	public CommonResp subProcessList(HttpServletRequest req) {
 	public CommonResp subProcessList(HttpServletRequest req) {
-		String lineSn = req.getParameter("lineSn");
-		String oprno = CommonUitl.formatOprno(req.getParameter("oprno"));
 		CommonResp<Map<String, Object>> resp = new CommonResp<>();
 		CommonResp<Map<String, Object>> resp = new CommonResp<>();
-		Map<String, Object> map = MapUtils.newHashMap();
-		MesLineProcess mesLineProcess = new MesLineProcess();
-		mesLineProcess.setStatus("0");
-		mesLineProcess.setOprno(oprno);
-		mesLineProcess.setLineSn(lineSn);
-		mesLineProcess.getSqlMap().getWhere().and("a.pid",QueryType.IS_NOT_NULL,"");
-		List<MesLineProcess> lists = mesLineProcessService.findList(mesLineProcess);
-		if(ListUtils.isEmpty(lists)){
-			List<MesLineProcess> list1 = new ArrayList<>();
-			map.put("lists", list1);
-		}else{
-			map.put("lists", lists);
+		String oprno = req.getParameter("oprno");
+		if (StringUtils.isBlank(oprno)) {
+			resp.setResult(Global.FALSE);
+			resp.setMessage("工位号不能为空");
+			return resp;
 		}
 		}
-		resp.setData(map);
+		String lineSn = CommonUitl.resolvePdaQueryLine(req.getParameter("lineSn"));
+		Map<String, Object> data = MapUtils.newHashMap();
+		data.put("lists", mesLineProcessService.findActiveSubProcesses(lineSn, CommonUitl.formatOprno(oprno.trim())));
+		resp.setData(data);
 		resp.setResult(Global.TRUE);
 		resp.setResult(Global.TRUE);
 		return resp;
 		return resp;
 	}
 	}

+ 109 - 101
src/main/java/com/jeesite/modules/mes/web/MesProductRecordController.java

@@ -7,6 +7,7 @@ import java.text.SimpleDateFormat;
 import java.time.*;
 import java.time.*;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.*;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
@@ -5010,31 +5011,31 @@ public class MesProductRecordController extends BaseController {
 	public CommonResp queryProduct(HttpServletRequest request) {
 	public CommonResp queryProduct(HttpServletRequest request) {
 		CommonResp<String> resp = new CommonResp<>();
 		CommonResp<String> resp = new CommonResp<>();
 		String sn = request.getParameter("sn");
 		String sn = request.getParameter("sn");
-		String lineSn = request.getParameter("lineSn");
-		if(StringUtils.isEmpty(lineSn)){
-			lineSn = "XT"; // Compatibility with clients that only submit sn.
-		}
-		if(StringUtils.isEmpty(sn)){
+		if (StringUtils.isBlank(sn)) {
 			resp.setResult(Global.FALSE);
 			resp.setResult(Global.FALSE);
 			resp.setMessage("参数错误");
 			resp.setMessage("参数错误");
 			return resp;
 			return resp;
 		}
 		}
-		String cate = mesLineService.findInfoCate(lineSn);
-		if(StringUtils.isEmpty(cate)){
-			resp.setResult(Global.FALSE);
-			resp.setMessage("产线不存在或未绑定产品");
-			return resp;
-		}
-		if("XT".equals(lineSn) && sn.length() == 28){
-			sn = mesProductHmbService.formatHmbSn(sn,"OP115",lineSn);
-		}
 
 
-		MesProductRecord mesProductRecord = mesProductRecordService.findBySnCate(sn,cate);
-		if(ObjectUtils.isEmpty(mesProductRecord)){
-			resp.setData("0");
-		}else{
-			resp.setData("1");
+		String lineSn = CommonUitl.resolvePdaQueryLine(request.getParameter("lineSn"));
+		MesProductRecord record;
+		if ("CZ060".equals(lineSn)) {
+			sn = mesProductHmbService.formatHmbSn(sn.trim());
+			MesProductRecord query = new MesProductRecord();
+			query.getSqlMap().getWhere()
+					.and("a.sn", QueryType.EQ, sn)
+					.and("a.line_sn", QueryType.EQ, lineSn);
+			record = mesProductRecordService.findInfo(query);
+		} else {
+			String cate = mesLineService.findInfoCate(lineSn);
+			if (StringUtils.isEmpty(cate)) {
+				resp.setResult(Global.FALSE);
+				resp.setMessage("产线不存在或未绑定产品");
+				return resp;
+			}
+			record = mesProductRecordService.findBySnCate(sn, cate);
 		}
 		}
+		resp.setData(ObjectUtils.isEmpty(record) ? "0" : "1");
 		resp.setResult(Global.TRUE);
 		resp.setResult(Global.TRUE);
 		return resp;
 		return resp;
 	}
 	}
@@ -5486,27 +5487,30 @@ public class MesProductRecordController extends BaseController {
 	public CommonResp checkProduct(HttpServletRequest request) {
 	public CommonResp checkProduct(HttpServletRequest request) {
 		CommonResp<Map<String, Object>> resp = new CommonResp<>();
 		CommonResp<Map<String, Object>> resp = new CommonResp<>();
 		String sn = request.getParameter("sn");
 		String sn = request.getParameter("sn");
-		if(StringUtils.isEmpty(sn)){
+		if (StringUtils.isBlank(sn)) {
 			resp.setResult(Global.FALSE);
 			resp.setResult(Global.FALSE);
 			resp.setMessage("参数错误");
 			resp.setMessage("参数错误");
 			return resp;
 			return resp;
 		}
 		}
 
 
-		String cate = "ZHXT";
-		if(sn.length() == 28){
-			sn = mesProductHmbService.formatHmbSn(sn,"OP130","XT");
+		String lineSn = CommonUitl.resolvePdaQueryLine(request.getParameter("lineSn"));
+		MesProductRecord query = new MesProductRecord();
+		query.getSqlMap().getWhere().and("a.craft", QueryType.EQ, "100000");
+		if ("CZ060".equals(lineSn)) {
+			sn = mesProductHmbService.formatHmbSn(sn.trim());
+			query.getSqlMap().getWhere().and("a.line_sn", QueryType.EQ, lineSn);
+		} else {
+			if (sn.length() == 28) {
+				sn = mesProductHmbService.formatHmbSn(sn, "OP130", "XT");
+			}
+			query.getSqlMap().getWhere().and("a.cate_sn", QueryType.EQ, "ZHXT");
 		}
 		}
+		query.getSqlMap().getWhere().and("a.sn", QueryType.EQ, sn);
 
 
-		Map<String, Object> map = MapUtils.newHashMap();
-		map.put("sn",sn);
-		MesProductRecord mesProductRecord = new MesProductRecord();
-		mesProductRecord.getSqlMap().getWhere()
-				.and("craft", QueryType.EQ,"100000")
-				.and("cate_sn", QueryType.EQ,cate)
-				.and("sn", QueryType.EQ,sn);
-		List<MesProductRecord> lists = mesProductRecordService.findList(mesProductRecord);
-		map.put("lists", lists);
-		resp.setData(map);
+		Map<String, Object> data = MapUtils.newHashMap();
+		data.put("sn", sn);
+		data.put("lists", mesProductRecordService.findList(query));
+		resp.setData(data);
 		resp.setResult(Global.TRUE);
 		resp.setResult(Global.TRUE);
 		return resp;
 		return resp;
 	}
 	}
@@ -5514,95 +5518,100 @@ public class MesProductRecordController extends BaseController {
 	// 修改工位
 	// 修改工位
 	@PostMapping(value = "editProduct")
 	@PostMapping(value = "editProduct")
 	@ResponseBody
 	@ResponseBody
+	@Transactional(rollbackFor = Exception.class)
 	public CommonResp editProduct(HttpServletRequest request) {
 	public CommonResp editProduct(HttpServletRequest request) {
 		CommonResp<String> resp = new CommonResp<>();
 		CommonResp<String> resp = new CommonResp<>();
 		String sn = request.getParameter("sn");
 		String sn = request.getParameter("sn");
 		String oprno = request.getParameter("oprno");
 		String oprno = request.getParameter("oprno");
 		String content = request.getParameter("content");
 		String content = request.getParameter("content");
-		if(StringUtils.isEmpty(sn) || StringUtils.isEmpty(oprno) || StringUtils.isEmpty(content)){
+		if (StringUtils.isBlank(sn) || StringUtils.isBlank(oprno) || StringUtils.isBlank(content)) {
 			resp.setResult(Global.FALSE);
 			resp.setResult(Global.FALSE);
 			resp.setMessage("参数错误");
 			resp.setMessage("参数错误");
 			return resp;
 			return resp;
 		}
 		}
-		if(!content.equals("UDF") && !content.equals("OK") && !content.equals("NG")){
+		if (!"UDF".equals(content) && !"OK".equals(content) && !"NG".equals(content)) {
 			resp.setResult(Global.FALSE);
 			resp.setResult(Global.FALSE);
 			resp.setMessage("结果值错误");
 			resp.setMessage("结果值错误");
 			return resp;
 			return resp;
 		}
 		}
 
 
-		sn = mesProductHmbService.formatHmbSn(sn,oprno,"XT");
-
-		MesProductRecord mesProductRecord2 = mesProductRecordService.findBySn(sn);
-		if(ObjectUtils.isEmpty(mesProductRecord2)){
+		String lineSn = CommonUitl.resolvePdaQueryLine(request.getParameter("lineSn"));
+		sn = mesProductHmbService.formatHmbSn(sn.trim());
+		oprno = oprno.trim();
+		String parentOprno = CommonUitl.formatOprno(oprno);
+		MesLineProcess parent = mesLineProcessService.findActiveStation(lineSn, parentOprno);
+		if (parent == null || StringUtils.isNotBlank(parent.getPid())) {
 			resp.setResult(Global.FALSE);
 			resp.setResult(Global.FALSE);
-			resp.setMessage("工件信息不存在");
+			resp.setMessage("当前产线没有可用的主工位");
 			return resp;
 			return resp;
 		}
 		}
-
-		MesProductRecord mesProductRecord = new MesProductRecord();
-		mesProductRecord.setCraft("100000");
-		mesProductRecord.setOprno(CommonUitl.formatOprno(oprno));
-		mesProductRecord.setSn(sn);
-		MesProductRecord mesProductRecord1 =  mesProductRecordService.findInfo(mesProductRecord);
-		if(content.equals("UDF")){
-			mesProductRecord1.setOprno(CommonUitl.formatOprno(oprno));
-		}else{
-			mesProductRecord1.setOprno(oprno);
+		if (!parentOprno.equals(oprno)) {
+			MesLineProcess selected = mesLineProcessService.findActiveStation(lineSn, oprno);
+			if (selected == null || !parent.getId().equals(selected.getPid())) {
+				resp.setResult(Global.FALSE);
+				resp.setMessage("所选子工位不属于当前产线或主工位");
+				return resp;
+			}
 		}
 		}
-		String contentOld = mesProductRecord1.getContent();
-		mesProductRecord1.setContent(content);
-		mesProductRecord1.setSource("2");
-		mesProductRecordService.save(mesProductRecord1);
 
 
-		//添加到产品修改记录100000
-		MesProductModifyRecord mesProductModifyRecord = new MesProductModifyRecord();
-		mesProductModifyRecord.setSn(sn);
-		if(content.equals("UDF")){
-			mesProductModifyRecord.setOprno(CommonUitl.formatOprno(oprno));
-		}else{
-			mesProductModifyRecord.setOprno(oprno);
+		MesProductRecord query = new MesProductRecord();
+		query.setSn(sn);
+		query.setCraft("100000");
+		query.setOprno(parentOprno);
+		query.getSqlMap().getWhere().and("a.line_sn", QueryType.EQ, lineSn);
+		List<MesProductRecord> stationRecords = mesProductRecordService.findList(query).stream()
+				.filter(record -> parentOprno.equals(CommonUitl.formatOprno(record.getOprno())))
+				.collect(Collectors.toList());
+		MesProductRecord record = stationRecords.stream()
+				.filter(item -> parentOprno.equals(item.getOprno()))
+				.findFirst().orElse(null);
+		if (record == null) {
+			record = stationRecords.size() == 1 ? stationRecords.get(0) : null;
+		}
+		if (record == null) {
+			resp.setResult(Global.FALSE);
+			resp.setMessage(stationRecords.isEmpty() ? "当前产线没有该工件的工位结果记录" : "找到多条工位结果记录,无法确定要修改的记录");
+			return resp;
 		}
 		}
-		mesProductModifyRecord.setCraft("100000");
-		mesProductModifyRecord.setContentOld(contentOld);
-		mesProductModifyRecord.setContent(content);
-		mesProductModifyRecord.setSource("2");
-		mesProductModifyRecordService.save(mesProductModifyRecord);
 
 
-		String state = "0";
-		List<String> ngList = new ArrayList<>();
-		if(CommonUitl.isOfflineOprno(oprno, mesProductRecord2.getLineSn())){
-			MesProductRecord mesProductRecord3 = new MesProductRecord();
-			mesProductRecord3.setSn(sn);
-			mesProductRecord3.setCraft("100000");
-			List<MesProductRecord> lists = mesProductRecordService.findList(mesProductRecord3);
-			for(MesProductRecord mesProductRecord4:lists){
-				if(mesProductRecord4.getContent().equals("NG")){
-					ngList.add(mesProductRecord4.getOprno());
-				}
-			}
-			if(!ngList.isEmpty()){
-				state= "4";
-			}else {
-				state= "1";
-			}
-			if(content.equals("UDF")){
-				MesProduct mesProduct = new MesProduct();
-				mesProduct.setSn(sn);
-				MesProduct mp = mesProductService.findInfo(mesProduct);
-				if(!ObjectUtils.isEmpty(mp)){
-					mp.setState("0");
-					mesProductService.update(mp);
-				}
+		String savedOprno = "UDF".equals(content) ? parentOprno : oprno;
+		String oldContent = record.getContent();
+		record.setOprno(savedOprno);
+		record.setContent(content);
+		record.setSource("2");
+		mesProductRecordService.save(record);
+
+		MesProductModifyRecord change = new MesProductModifyRecord();
+		change.setSn(sn);
+		change.setLineSn(lineSn);
+		change.setOprno(savedOprno);
+		change.setCraft("100000");
+		change.setContentOld(oldContent);
+		change.setContent(content);
+		change.setSource("2");
+		mesProductModifyRecordService.save(change);
+
+		// 工件主表没有产线字段,同码跨产线时仅保存当前产线的工位结果。
+		MesProductRecord otherLine = new MesProductRecord();
+		otherLine.setSn(sn);
+		otherLine.getSqlMap().getWhere().and("a.line_sn", QueryType.NE, lineSn);
+		if (mesProductRecordService.findCount(otherLine) == 0) {
+			String state = "0";
+			if (CommonUitl.isOfflineOprno(oprno, lineSn)) {
+				MesProductRecord failures = new MesProductRecord();
+				failures.setSn(sn);
+				failures.setCraft("100000");
+				failures.setContent("NG");
+				failures.getSqlMap().getWhere().and("a.line_sn", QueryType.EQ, lineSn);
+				state = mesProductRecordService.findCount(failures) > 0 ? "4" : "1";
+			}
+			MesProduct productQuery = new MesProduct();
+			productQuery.setSn(sn);
+			MesProduct product = mesProductService.findInfo(productQuery);
+			if (product != null) {
+				product.setState(state);
+				mesProductService.save(product);
 			}
 			}
-		}else {
-			state= "0";
-		}
-		MesProduct mesProduct = new MesProduct();
-		mesProduct.setSn(sn);
-		MesProduct mm = mesProductService.findInfo(mesProduct);
-		if(!ObjectUtils.isEmpty(mm)){
-			mm.setState(state);
-			mesProductService.save(mm);
 		}
 		}
 		resp.setResult(Global.TRUE);
 		resp.setResult(Global.TRUE);
 		resp.setMessage("操作成功");
 		resp.setMessage("操作成功");
@@ -5610,7 +5619,6 @@ public class MesProductRecordController extends BaseController {
 	}
 	}
 
 
 
 
-
 	/**
 	/**
 	 * 查询列表NG预警
 	 * 查询列表NG预警
 	 */
 	 */