Ver Fonte

Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	src/main/java/com/uas/ps/product/repository/ProductDao.java
dongbw há 7 anos atrás
pai
commit
83a90bf748

+ 8 - 3
src/main/java/com/uas/ps/product/controller/ProductController.java

@@ -78,7 +78,7 @@ public class ProductController {
     }
 
     /**
-     * 更新物料信息(子应用做验证,这里只负责存)
+     * 批量更新物料信息(子应用做验证,这里只负责存)
      *
      * @param data 物料信息
      * @return
@@ -87,9 +87,14 @@ public class ProductController {
     @ResponseBody
     public ModelMap updateProdInfo(@RequestParam("data") String data) throws UnsupportedEncodingException {
         // TODO 物料信息中的企业UU和用户UU,需要在调用接口之前设置。有id为更新,无id为新增
-        Product productInfo = JSONObject.parseObject(URLDecoder.decode(data, "utf-8"), Product.class);
+        List<Product> productInfo = JSONObject.parseArray(URLDecoder.decode(data, "utf-8"), Product.class);
         ModelMap map = new ModelMap();
-        productInfo = productService.save(productInfo);
+        for (Product product : productInfo) {
+            List<Product> products = productService.findByEnUUAndCmpCodeAndBrand(product.getEnUU(),product.getCmpCode(),product.getBrand());
+            if ( products == null || products.size() == 0 ) {
+                productService.save(product);
+            }
+        }
 //        logger.log("更新物料", "[" + productInfo.getUserUU() + "]更新了id为" + productInfo.getId() + "的["
 //                + productInfo.getTitle() + "]");
         return map;

+ 8 - 0
src/main/java/com/uas/ps/product/repository/ProductDao.java

@@ -31,6 +31,14 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     List<Product> findByEnUUAndSourceAppAndDownloadStatus(Long enUU, String app, Integer status);
 
+    /**
+     * 根据物料所属enUU、原产型号品牌查询物料
+     * @param enUU
+     * @param cmpCode
+     * @param brand
+     * @return
+     */
+    List<Product> findByEnUUAndCmpCodeAndBrand(Long enUU, String cmpCode, String brand);
     /**
      * 通过企业UU,物料名称、规格、品牌(非标准)
      *

+ 10 - 0
src/main/java/com/uas/ps/product/service/ProductService.java

@@ -68,6 +68,16 @@ public interface ProductService {
      */
     List<Product> findByEnUUAndSourceAppAndDownloadStatus(Long enUU, String app, Integer status);
 
+    /**
+     * 通过所属企业UU、型号和器件查询物料信息
+     *
+     * @param enUU
+     * @param cmpCode
+     * @param brand
+     * @return
+     */
+    List<Product> findByEnUUAndCmpCodeAndBrand(Long enUU, String cmpCode, String brand);
+
     /**
      * 物料下载成功,更新下载状态
      *

+ 5 - 0
src/main/java/com/uas/ps/product/service/impl/ProductServiceImpl.java

@@ -146,6 +146,11 @@ public class ProductServiceImpl implements ProductService {
         return productDao.findByEnUUAndSourceAppAndDownloadStatus(enUU, app, status);
     }
 
+    @Override
+    public List<Product> findByEnUUAndCmpCodeAndBrand(Long enUU, String cmpCode, String brand) {
+        return productDao.findByEnUUAndCmpCodeAndBrand(enUU,cmpCode,brand);
+    }
+
     /**
      * 物料下载成功,更新下载状态
      *

+ 0 - 133
src/main/java/com/uas/ps/product/util/FileBuffer.java

@@ -1,133 +0,0 @@
-package com.uas.ps.product.util;
-
-import java.io.*;
-
-/**
- * @author sunyj
- * @since 2018/1/6 17:39
- */
-public class FileBuffer {
-    private String filePath;
-    private BufferedWriter writer;
-    private BufferedReader reader;
-
-    public FileBuffer(String folderPath, String fileName) {
-        File file = new File(folderPath);
-        if (!file.isDirectory()) {
-            file.mkdirs();
-        }
-
-        this.filePath = folderPath + File.separator + fileName;
-    }
-
-    public synchronized boolean append(String content) {
-        if (this.writer == null) {
-            try {
-                File file = new File(this.filePath);
-                if (!file.exists()) {
-                    file.createNewFile();
-                }
-
-                this.writer = new BufferedWriter(new FileWriter(file, true));
-            } catch (IOException var5) {
-                return false;
-            }
-        } else {
-            try {
-                this.writer.write("\r\n");
-            } catch (IOException var4) {
-                return false;
-            }
-        }
-
-        try {
-            this.writer.write(content);
-            this.writer.flush();
-            return true;
-        } catch (IOException var3) {
-            return false;
-        }
-    }
-
-    public synchronized String readLine() {
-        if (this.writer != null) {
-            this.close();
-        }
-
-        if (this.reader == null) {
-            File file = new File(this.filePath);
-            if (file.exists()) {
-                try {
-                    InputStreamReader streamReader = new InputStreamReader(new FileInputStream(file));
-                    this.reader = new BufferedReader(streamReader);
-                } catch (FileNotFoundException var3) {
-                    return null;
-                }
-            }
-        }
-
-        if (this.reader != null) {
-            try {
-                return this.reader.readLine();
-            } catch (IOException var4) {
-                ;
-            }
-        }
-
-        return null;
-    }
-
-    public synchronized void close() {
-        if (this.writer != null) {
-            try {
-                this.writer.close();
-            } catch (IOException var5) {
-                ;
-            } finally {
-                this.writer = null;
-            }
-        }
-
-    }
-
-    public synchronized void delete() {
-        if (this.writer != null) {
-            try {
-                this.writer.close();
-            } catch (IOException var14) {
-                ;
-            } finally {
-                this.writer = null;
-            }
-        }
-
-        if (this.reader != null) {
-            try {
-                this.reader.close();
-            } catch (IOException var12) {
-                ;
-            } finally {
-                this.reader = null;
-            }
-        }
-
-        File file = new File(this.filePath);
-        if (file.exists()) {
-            file.delete();
-        }
-
-    }
-
-    public synchronized boolean isEmpty() {
-        boolean empty = this.writer == null;
-        if (!empty) {
-            File file = new File(this.filePath);
-            empty = !file.exists();
-            if (!empty) {
-                empty = file.length() == 0L;
-            }
-        }
-
-        return empty;
-    }
-}

+ 0 - 81
src/main/java/com/uas/ps/product/util/PathUtils.java

@@ -1,81 +0,0 @@
-package com.uas.ps.product.util;
-
-import com.uas.ps.core.util.ContextUtils;
-
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-/**
- * 路径
- *
- * @author sunyj
- * @since 2018/1/6 17:30
- */
-public class PathUtils {
-
-    private static String classPath;
-
-    private static String appPath;
-
-    private static String filePath;
-
-    /**
-     * classes文件目录
-     *
-     * @return
-     */
-    public static String getClassPath() {
-        if (classPath == null)
-            setClassPath();
-        return classPath;
-    }
-
-    /**
-     * 应用程序目录
-     *
-     * @return
-     */
-    public static String getAppPath() {
-        if (appPath == null)
-            setAppPath();
-        return appPath;
-    }
-
-    /**
-     * 日志、附件文件等存放目录,与程序同级
-     *
-     * @return
-     */
-    public static String getFilePath() {
-        if (filePath == null)
-            setFilePath();
-        return filePath;
-    }
-
-    private static void setClassPath() {
-        Class<?> objClass = ContextUtils.getApplicationContext().getClass();
-        String strRealPath = objClass.getClassLoader().getResource("").getFile();
-        try {
-            strRealPath = URLDecoder.decode(strRealPath, "UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            e.printStackTrace();
-        }
-        File objFile = new File(strRealPath);
-        classPath = objFile.getParent() + File.separator;
-        if (classPath.contains("/")) {
-            classPath = "/" + classPath;
-        }
-    }
-
-    private static void setAppPath() {
-        File file = new File(getClassPath());
-        appPath = file.getParent() + File.separator;
-    }
-
-    private static void setFilePath() {
-        File file = new File(getAppPath());
-        filePath = file.getParent() + File.separator;
-    }
-
-}