day01-init vor 2 Wochen
Ursprung
Commit
ad0e31cff2

+ 49 - 5
src/com/mes/ui/DataUtil.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson2.JSONObject;
 import com.mes.netty.NettyClient;
 import com.mes.util.DateLocalUtils;
 import com.mes.util.JdbcUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.*;
 import java.net.HttpURLConnection;
@@ -13,6 +15,8 @@ import java.util.Properties;
 
 public class DataUtil {
 
+    private static final Logger log = LoggerFactory.getLogger(DataUtil.class);
+
     public static Boolean synrTcp(NettyClient nettyClient,String mes_gw){
         try{
             //TCP连接后,直接先发同步报文
@@ -57,11 +61,14 @@ public class DataUtil {
     }
 
     public static Boolean checkQuality(NettyClient nettyClient, String sn, String user){
+        return checkQuality(nettyClient, sn, user, null);
+    }
+
+    public static Boolean checkQuality(NettyClient nettyClient, String sn, String user, String gwOverride){
         try{
             String msgType = "AQDW";
             String gy = "100000";
-            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"00","");
-            return aqdw_str;
+            return sendMessage(nettyClient, msgType, gy, "", sn, "", user, "00", "", gwOverride);
         }catch (Exception e){
             return false;
         }
@@ -112,13 +119,45 @@ public class DataUtil {
         }
     }
 
+    public static JSONObject sendQuality(String sn, String ret, String user) {
+        return sendQuality(sn, ret, user, null);
+    }
+
+    public static JSONObject sendQuality(String sn, String ret, String user, String oprnoOverride) {
+        try {
+            String mes_server_ip = MesClient.mes_server_ip;
+            String oprno = (oprnoOverride != null && !oprnoOverride.trim().isEmpty())
+                    ? oprnoOverride.trim()
+                    : (MesClient.mes_gw == null ? "" : MesClient.mes_gw.trim());
+            String lineSn = MesClient.mes_line_sn == null ? "" : MesClient.mes_line_sn.trim();
+            String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/pcresult";
+            String params = "__ajax=json&oprno=" + oprno + "&lineSn=" + lineSn + "&sn=" + sn + "&result=" + ret + "&ucode=" + user;
+            log.info("params={}", params);
+            String result = doPost(url, params);
+            log.info("result={}", result);
+
+            if (result == null || result.trim().isEmpty() || result.equalsIgnoreCase("false")) {
+                return null;
+            }
+            JdbcUtils.insertData(oprno, "100000", params, "MQDW", sn);
+            return JSONObject.parseObject(result);
+        } catch (Exception e) {
+            log.info("e={}", e.getMessage());
+            return null;
+        }
+    }
+
+    /** @deprecated 使用 HTTP 接口 {@link #sendQuality(String, String, String)} */
     public static Boolean sendQuality(NettyClient nettyClient,String sn,String ret,String user){
+        return sendQuality(nettyClient, sn, ret, user, null);
+    }
+
+    public static Boolean sendQuality(NettyClient nettyClient,String sn,String ret,String user, String gwOverride){
         try{
             String msgType = "MQDW";
             String gy = "100000";
             String param = "";
-            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,ret,user,"00",param);
-            return aqdw_str;
+            return sendMessage(nettyClient,msgType,gy,"",sn,ret,user,"00",param, gwOverride);
         }catch (Exception e){
             return false;
         }
@@ -153,13 +192,18 @@ public class DataUtil {
     }
 
     public static Boolean sendMessage(NettyClient nettyClient,String msgType,String craft,String lx,String sn,String result,String user,String paramNums,String params){
+        return sendMessage(nettyClient, msgType, craft, lx, sn, result, user, paramNums, params, null);
+    }
+
+    public static Boolean sendMessage(NettyClient nettyClient,String msgType,String craft,String lx,String sn,String result,String user,String paramNums,String params, String gwOverride){
         try{
             String enconding = "UTF-8";
             InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
             Properties pro = new Properties();
             BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
             pro.load(br);
-            String gw = "GW"+rightPad(pro.getProperty("mes.gw"), 6);
+            String gwCode = (gwOverride != null && !gwOverride.trim().isEmpty()) ? gwOverride : pro.getProperty("mes.gw");
+            String gw = "GW"+rightPad(gwCode, 6);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad(lx, 2);

Datei-Diff unterdrückt, da er zu groß ist
+ 559 - 536
src/com/mes/ui/MesClient.java


+ 40 - 12
src/com/mes/ui/MesRevice.java

@@ -14,15 +14,37 @@ public class MesRevice {
         try{
             if(processMsgRet.equalsIgnoreCase("UD")) {
                 MesClient.status_menu.setForeground(Color.GREEN);
-                MesClient.check_quality_result = true;//质量合格,可以绑定加工
+                MesClient.check_quality_result = true;
                 MesClient.status_menu.setText("该工件可以加工");
-                MesClient.work_status = 1;
-                MesClient.f_scan_data_bt_1.setEnabled(false);
-//                MesClient.finish_ok_bt.setEnabled(true);
-//                MesClient.finish_ng_bt.setEnabled(true);
-                MesClient.f_scan_data_bt_1.setEnabled(true);
+                String gw = ProtocolParam.getOprno(mes_msg).trim();
+                boolean isBack = MesClient.OPRNO_BACK.equals(gw);
+                boolean isFront = MesClient.OPRNO_FRONT.equals(gw);
+                if (!isBack && !isFront) {
+                    if (MesClient.scan_side == 1) {
+                        isBack = true;
+                    } else if (MesClient.scan_side == 2) {
+                        isFront = true;
+                    }
+                }
+                if (isBack) {
+                    MesClient.work_status_f = 1;
+                    MesClient.check_quality_result_f = true;
+                    MesClient.f_scan_data_bt_1.setEnabled(true);
+                    MesClient.setMenuStatus("反面工件校验通过,开始拍照", 0);
+                    SwingUtilities.invokeLater(() -> MesClient.takePhotosAndSubmit(false));
+                } else if (isFront) {
+                    MesClient.work_status_z = 1;
+                    MesClient.check_quality_result_z = true;
+                    MesClient.f_scan_data_bt_2.setEnabled(true);
+                    MesClient.setMenuStatus("正面工件校验通过,开始拍照", 0);
+                    SwingUtilities.invokeLater(() -> MesClient.takePhotosAndSubmit(true));
+                } else {
+                    MesClient.work_status = 1;
+                    MesClient.f_scan_data_bt_1.setEnabled(true);
+                    MesClient.f_scan_data_bt_2.setEnabled(true);
+                }
 
-                String oprno = ProtocolParam.getOprno(mes_msg).trim();
+                String oprno = gw;
                 if(oprno.equals("OP400")){
                     String lx = ProtocolParam.getLx(mes_msg);
                     if(lx.equals("FX")){
@@ -113,11 +135,17 @@ public class MesRevice {
     public static void updateResultRevice(String processMsgRet,String mes_msg){
         try{
             if(processMsgRet.equalsIgnoreCase("OK")) {
-
-                MesClient.resetScanA();
-                MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
-                MesClient.scan_type = 1;
-                MesClient.scanBarcode();
+                String gw = ProtocolParam.getOprno(mes_msg).trim();
+                if (MesClient.OPRNO_BACK.equals(gw)) {
+                    MesClient.resetScanBack();
+                    MesClient.setMenuStatus("反面提交成功,请扫下一件", 0);
+                } else if (MesClient.OPRNO_FRONT.equals(gw)) {
+                    MesClient.resetScanFront();
+                    MesClient.setMenuStatus("正面提交成功,请扫下一件", 0);
+                } else {
+                    MesClient.resetScanA();
+                    MesClient.setMenuStatus("结果提交成功,请扫下一件", 0);
+                }
 
             }else{
                 MesClient.setMenuStatus("结果提交失败,请重试",-1);

+ 1 - 1
src/com/mes/ui/OprnoUtil.java

@@ -15,7 +15,7 @@ public class OprnoUtil {
             "OP360", "OP370", "OP380", "OP390", "OP400",
             "OP410", "OP420", "OP430", "OP440", "OP450",
             "OP460", "OP470", "OP480", "OP490", "OP500",
-            "OP510", "OP520", "OP550"
+            "OP510", "OP470", "OP550"
     };
     public static String[] xtoprnodes = new String[]{
             "右边梁镭雕二维码","CMT框架一序焊接",

+ 91 - 18
src/com/mes/util/CameraUtils.java

@@ -90,6 +90,10 @@ public class CameraUtils {
     * return boolean
     * */
     public Boolean getCameraImage(String filename,String exposureTime){
+        return getCameraImage(filename, exposureTime, null);
+    }
+
+    public Boolean getCameraImage(String filename,String exposureTime,String tempDirPath){
         int nRet = MV_OK;
         try{
             // Open selected device
@@ -111,7 +115,8 @@ public class CameraUtils {
 
             // 调焦,调整亮度, 值越大越亮
 //            nRet = MvCameraControl.MV_CC_SetEnumValueByString(hCamera, "ExposureTime", "268724.0000");
-            nRet = MvCameraControl.MV_CC_SetFloatValue(hCamera, "ExposureTime", Float.parseFloat(exposureTime));
+            String exp = (exposureTime == null || exposureTime.trim().isEmpty()) ? "88724" : exposureTime.trim();
+            nRet = MvCameraControl.MV_CC_SetFloatValue(hCamera, "ExposureTime", Float.parseFloat(exp));
             if (MV_OK != nRet)
             {
                 this.error = "ExposureTime failed, errcode:" + nRet;
@@ -145,7 +150,7 @@ public class CameraUtils {
             }
 //            System.err.println("11111111111111111");
 //            nRet = SaveImage(MV_SAVE_IAMGE_TYPE.MV_Image_Jpeg,pData,stImageInfo,sn+"_"+record_time,filename);
-            nRet = SaveImageTemp(MV_SAVE_IAMGE_TYPE.MV_Image_Jpeg,pData,stImageInfo,filename);
+            nRet = SaveImageTemp(MV_SAVE_IAMGE_TYPE.MV_Image_Jpeg,pData,stImageInfo,filename,tempDirPath);
 //            nRet = SaveImageTemp(MV_SAVE_IAMGE_TYPE.MV_Image_Bmp,pData,stImageInfo,filename);
             if(MV_OK != nRet)
             {
@@ -315,6 +320,11 @@ public class CameraUtils {
     // 保存图片到临时目录
     public int SaveImageTemp(MV_SAVE_IAMGE_TYPE enSaveImageType,byte[] dataToSave,MV_FRAME_OUT_INFO stImageInfo,String fileName)
     {
+        return SaveImageTemp(enSaveImageType, dataToSave, stImageInfo, fileName, null);
+    }
+
+    public int SaveImageTemp(MV_SAVE_IAMGE_TYPE enSaveImageType,byte[] dataToSave,MV_FRAME_OUT_INFO stImageInfo,String fileName,String tempDirPath)
+    {
         MV_SAVE_IMAGE_TO_FILE_PARAM_EX stSaveFileParam = new MV_SAVE_IMAGE_TO_FILE_PARAM_EX();
 
         stSaveFileParam.imageType = enSaveImageType;						// ch:需要保存的图像类型 | en:Image format to save
@@ -325,7 +335,9 @@ public class CameraUtils {
         stSaveFileParam.data      = dataToSave;
         stSaveFileParam.methodValue = 1;
 
-        String saveTempDir = MesClient.saveTempDir;
+        String saveTempDir = (tempDirPath != null && !tempDirPath.trim().isEmpty())
+                ? tempDirPath
+                : MesClient.getPhotoTempDir();
         log.info("saveTempDir:"+saveTempDir);
         File file = new File(saveTempDir);
         if (!file.exists()) {
@@ -364,12 +376,26 @@ public class CameraUtils {
     }
 
 
+    public static void ensureTempDirectory(String tempDirPath) {
+        try {
+            Files.createDirectories(Paths.get(tempDirPath));
+        } catch (IOException e) {
+            log.error("创建临时目录失败: {}", tempDirPath, e);
+        }
+    }
+
+    public static boolean hasImageFiles(String directoryPath) {
+        List<File> files = getImageFilesInDirectory(directoryPath);
+        return files != null && !files.isEmpty();
+    }
+
     /**
      * 清空临时目录下的所有内容(保留目录本身)
      * @param tempDirPath 临时目录路径
      * @return 是否成功清空
      */
     public static boolean cleanTempDirectory(String tempDirPath) {
+        ensureTempDirectory(tempDirPath);
         Path tempDir = Paths.get(tempDirPath);
 
         try {
@@ -417,21 +443,48 @@ public class CameraUtils {
     }
 
 
+    /** 将临时目录中的图片复制到 D 盘正式目录,不删除临时文件 */
+    public static String copyTempImagesToDirectory(String tempDirPath, String targetFolderName) {
+        try {
+            if (!hasImageFiles(tempDirPath)) {
+                log.warn("临时文件夹无图片: {}", tempDirPath);
+                return "";
+            }
+            Path targetPath = Paths.get(MesClient.saveDir, targetFolderName);
+            Files.createDirectories(targetPath);
+            List<File> imageFiles = getImageFilesInDirectory(tempDirPath);
+            if (imageFiles == null || imageFiles.isEmpty()) {
+                log.warn("临时目录下无图片文件: {}", tempDirPath);
+                return "";
+            }
+            for (File src : imageFiles) {
+                Path dest = targetPath.resolve(src.getName());
+                Files.copy(src.toPath(), dest, StandardCopyOption.REPLACE_EXISTING);
+            }
+            log.info("照片已保存到: {}", targetPath);
+            return targetPath.toString();
+        } catch (IOException e) {
+            log.error("照片保存失败: {} -> {}", tempDirPath, targetFolderName, e);
+        }
+        return "";
+    }
+
     //提交-临时文件夹重命名
-    public static  String renameTempDirectory(String tempDirPath, String newFolderName)  {
+    public static String renameTempDirectory(String tempDirPath, String newFolderName) {
         try {
-            // 1. 检查临时文件夹是否存在
             Path sourcePath = Paths.get(tempDirPath);
-            if (!Files.exists(sourcePath)) {
-                log.info("临时文件夹不存在: {}", tempDirPath);
-
+            if (!Files.exists(sourcePath) || !hasImageFiles(tempDirPath)) {
+                log.warn("临时文件夹不存在或无图片: {}", tempDirPath);
+                return "";
             }
 
-            // 2. 生成目标文件夹路径(同一父目录下)
             Path parentDir = sourcePath.getParent();
+            if (parentDir == null) {
+                log.error("无法解析父目录: {}", tempDirPath);
+                return "";
+            }
             Path targetPath = parentDir.resolve(newFolderName);
 
-            // 3. 执行重命名(原子操作,允许覆盖已存在文件夹)
             Files.move(
                     sourcePath,
                     targetPath,
@@ -439,18 +492,22 @@ public class CameraUtils {
                     StandardCopyOption.REPLACE_EXISTING
             );
 
-            //重命名文件夹后,把重命名后文件夹下的图片上传到服务器
-//            uploadAllImagesFromDirectory(targetPath.toString());
-            log.info("文件夹重命名成功: " + targetPath);
+            ensureTempDirectory(tempDirPath);
+            log.info("文件夹重命名成功: {}", targetPath);
             return targetPath.toString();
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("文件夹重命名失败: {} -> {}", tempDirPath, newFolderName, e);
         }
         return "";
     }
 
+    public static void uploadAllImagesFromDirectory(String directoryPath, String folderName) {
+        String sn = MesClient.product_sn_z != null ? MesClient.product_sn_z.getText().trim() : "";
+        uploadAllImagesFromDirectory(directoryPath, folderName, sn, MesClient.OPRNO_FRONT, false);
+    }
+
     //指定文件夹下文件上传
-    public static  void uploadAllImagesFromDirectory(String directoryPath,String folderName)  {
+    public static void uploadAllImagesFromDirectory(String directoryPath, String folderName, String sn, String oprno, boolean resetSideOnSuccess) {
         // 1. 获取目录下所有图片文件
         List<File> imageFiles = getImageFilesInDirectory(directoryPath);
         if (imageFiles.isEmpty()) {
@@ -463,8 +520,8 @@ public class CameraUtils {
 
         HashMap<String, String> hashMap = new HashMap<>();
 
-        hashMap.put("sn",MesClient.product_sn.getText());
-        hashMap.put("oprno",MesClient.mes_gw);
+        hashMap.put("sn", sn);
+        hashMap.put("oprno", oprno);
         hashMap.put("cateSn","LXXT");
         hashMap.put("lineSn",MesClient.mes_line_sn);
         hashMap.put("remark",folderName);
@@ -472,7 +529,23 @@ public class CameraUtils {
             CommonResp<String> resp = HttpUtils.uploadFilesWithParams(imageFiles, url, hashMap);
             if ("true".equals(resp.getResult())){
                 MesClient.setMenuStatus("上传成功",0);
-                MesClient.resetScanA();
+                MesClient.getUser();
+                String ucode = MesClient.user_menu != null ? MesClient.user_menu.getText().trim() : "";
+                JSONObject qualityResp = com.mes.ui.DataUtil.sendQuality(sn, "OK", ucode, oprno);
+                if (qualityResp == null || !Boolean.TRUE.equals(qualityResp.getBoolean("result"))) {
+                    MesClient.setMenuStatus("图片已上传,质量提交失败请重试", -1);
+                    return;
+                }
+                if (MesClient.OPRNO_BACK.equals(oprno)) {
+                    MesClient.resetScanBack();
+                    MesClient.setMenuStatus("反面提交成功,请扫下一件", 0);
+                } else if (MesClient.OPRNO_FRONT.equals(oprno)) {
+                    MesClient.resetScanFront();
+                    MesClient.setMenuStatus("正面提交成功,请扫下一件", 0);
+                } else {
+                    MesClient.resetScanA();
+                    MesClient.setMenuStatus("结果提交成功,请扫下一件", 0);
+                }
             }else{
                 MesClient.setMenuStatus("上传失败-"+resp.getMessage(),-1);
             }

+ 2 - 2
src/resources/config/config.properties

@@ -1,6 +1,6 @@
-mes.gw=OP520A
+mes.gw=OP470A
 #mes.server_ip=127.0.0.1
-mes.server_ip=192.168.21.99
+mes.server_ip=192.168.22.99
 mes.tcp_port=3000
 
 mes.heart_beat_cycle=60