Browse Source

BOM求购字段简化

yangc 7 years ago
parent
commit
afcbe6a9b5

+ 4 - 1
src/main/java/com/uas/platform/b2c/trade/seek/dao/SeekPurchaseBomListDao.java

@@ -14,6 +14,9 @@ import org.springframework.stereotype.Repository;
 @Repository
 public interface SeekPurchaseBomListDao extends JpaSpecificationExecutor<SeekPurchaseBomList>,
         JpaRepository<SeekPurchaseBomList, Long> {
-
+    /**
+     * 通过BomId删除明细列表
+     */
+    void deleteByBomId(Long bomId);
 }
 

+ 91 - 104
src/main/java/com/uas/platform/b2c/trade/seek/service/impl/SeekPurchaseBomServiceImpl.java

@@ -99,7 +99,13 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
 
     private static final UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
 
-    private int mallColNum = 10;
+    /**
+     * 模板列
+     */
+    private int mallColNum = 6;
+    /**
+     * 上限行数
+     */
     private int mallRowNum = 500;
 
     /**
@@ -109,12 +115,12 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
     public static final int BRANDNUM = 1;
     public static final int DEADLINENUM = 2;
     public static final int AMOUNTNUM = 3;
-    public static final int CURRENCYNUM = 4;
-    public static final int UNITPRICENUM = 5;
-    public static final int ENCAPSULATIONNUM = 8;
-    public static final int PRODUCEDATENUM = 9;
-    public static final int KINDNUM = 6;
-    public static final int SPECNUM = 7;
+//    public static final int CURRENCYNUM = 6;
+//    public static final int UNITPRICENUM = 7;
+//    public static final int ENCAPSULATIONNUM = 8;
+//    public static final int PRODUCEDATENUM = 9;
+    public static final int KINDNUM = 4;
+    public static final int SPECNUM = 5;
 
 
     /**
@@ -192,10 +198,10 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
         Object brandCellObj = readWorkBookCell(row.getCell(BRANDNUM), Cell.CELL_TYPE_STRING,
                 0, BRANDNUM);
         String brandString = StringUtilB2C.getStr(brandCellObj);
-        Object produceDateCellObj = readWorkBookCell(row.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
-                0, PRODUCEDATENUM);
-        String produceDateString = StringUtilB2C.getStr(produceDateCellObj);
-        if ("只能填数字、英文、英文特殊符号".equals(codeString) || "请勿用中文特殊符号".equals(brandString) || "不超过6个汉字或12个字符".equals(produceDateString)) {
+//        Object produceDateCellObj = readWorkBookCell(row.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
+//                0, PRODUCEDATENUM);
+//        String produceDateString = StringUtilB2C.getStr(produceDateCellObj);
+        if ("只能填数字、英文、英文特殊符号".equals(codeString) || "请勿用中文特殊符号".equals(brandString)) {
             return true;
         }
         return false;
@@ -222,14 +228,27 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
         if (!"截止时间".equals(StringUtilB2C.getStr(deadlineCellObj))) {
             return false;
         }
-        Object produceDateCellObj = readWorkBookCell(headerRow.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
-                0, PRODUCEDATENUM);
-        if (!"生产日期".equals(StringUtilB2C.getStr(produceDateCellObj))) {
-            return false;
-        }
+//        Object produceDateCellObj = readWorkBookCell(headerRow.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
+//                0, PRODUCEDATENUM);
+//        if (!"生产日期".equals(StringUtilB2C.getStr(produceDateCellObj))) {
+//            return false;
+//        }
         return true;
     }
 
+
+    private String convert(Object obj, int length) {
+        String result = StringUtilB2C.getStr(obj).trim();
+        try {
+            result = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(result, length);
+            result = match(result);
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+            result = null;
+        }
+        return result;
+    }
+
     /**
      * 将列信息注入到求购临时实体中
      * @param row
@@ -246,16 +265,7 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
         if (StringUtils.isEmpty(codeValue)) {
             result += 1;
         } else {
-            String code = StringUtilB2C.getStr(codeValue).trim();
-            try {
-                code = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(code, 100);
-                if (!match(code)) {
-                    code = null;
-                }
-            } catch (UnsupportedEncodingException e) {
-                e.printStackTrace();
-            }
-            seekPurchaseByBatch.setCode(code);
+            seekPurchaseByBatch.setCode(convert(codeValue, 100));
         }
 
         // 品牌
@@ -264,16 +274,7 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
         if (StringUtils.isEmpty(brandValue)) {
             result += 1;
         } else {
-            String brand = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(brandValue));
-            try {
-                brand = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(brand, 50);
-                if (!match(brand)) {
-                    brand = null;
-                }
-            } catch (UnsupportedEncodingException e) {
-                e.printStackTrace();
-            }
-            seekPurchaseByBatch.setBrand(brand);
+            seekPurchaseByBatch.setBrand(convert(brandValue, 50));
         }
 
         // 截止日期
@@ -322,90 +323,75 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
         }
 
         // 币别
-        Object currencyValue = readWorkBookCell(row.getCell(CURRENCYNUM), Cell.CELL_TYPE_STRING,
-                rowNum, CURRENCYNUM);
-        if (!StringUtils.isEmpty(currencyValue)) {
-            try {
-                String currency = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(currencyValue));
-                seekPurchaseByBatch.setCurrency(currency);
-            } catch (Exception e) {
-                seekPurchaseByBatch.setCurrency(null);
-            }
-        }
+//        Object currencyValue = readWorkBookCell(row.getCell(CURRENCYNUM), Cell.CELL_TYPE_STRING,
+//                rowNum, CURRENCYNUM);
+//        if (!StringUtils.isEmpty(currencyValue)) {
+//            try {
+//                String currency = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(currencyValue));
+//                seekPurchaseByBatch.setCurrency(currency);
+//            } catch (Exception e) {
+//                seekPurchaseByBatch.setCurrency(null);
+//            }
+//        }
 
         // 单价
-        Object unitPriceValue = readWorkBookCell(row.getCell(UNITPRICENUM), Cell.CELL_TYPE_STRING,
-                rowNum, UNITPRICENUM);
-        if (!StringUtils.isEmpty(unitPriceValue)) {
-            try {
-                Double unitPrice = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(unitPriceValue)));
-                if (unitPrice <= 0 || unitPrice >= 10000) {
-                    unitPrice = null;
-                }
-                seekPurchaseByBatch.setUnitPrice(unitPrice);
-            } catch (NumberFormatException e) {
-                seekPurchaseByBatch.setUnitPrice(null);
-            }
-        }
+//        Object unitPriceValue = readWorkBookCell(row.getCell(UNITPRICENUM), Cell.CELL_TYPE_STRING,
+//                rowNum, UNITPRICENUM);
+//        if (!StringUtils.isEmpty(unitPriceValue)) {
+//            try {
+//                Double unitPrice = Double.valueOf(StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(unitPriceValue)));
+//                if (unitPrice <= 0 || unitPrice >= 10000) {
+//                    unitPrice = null;
+//                }
+//                seekPurchaseByBatch.setUnitPrice(unitPrice);
+//            } catch (NumberFormatException e) {
+//                seekPurchaseByBatch.setUnitPrice(null);
+//            }
+//        }
         // 如果填了单价又不选币种,导入的时候系统就默认人民币吧
-        if (!StringUtils.isEmpty(unitPriceValue) && StringUtils.isEmpty(currencyValue)) {
-            seekPurchaseByBatch.setCurrency("RMB");
-        }
+//        if (!StringUtils.isEmpty(unitPriceValue) && StringUtils.isEmpty(currencyValue)) {
+//            seekPurchaseByBatch.setCurrency("RMB");
+//        }
 
         // 封装
-        Object encapsulationValue = readWorkBookCell(row.getCell(ENCAPSULATIONNUM), Cell.CELL_TYPE_STRING,
-                rowNum, ENCAPSULATIONNUM);
-        if (!StringUtils.isEmpty(encapsulationValue)) {
-            try {
-                String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
-                encapsulation = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(encapsulation, 20);
-                seekPurchaseByBatch.setEncapsulation(encapsulation);
-            } catch (Exception e) {
-                seekPurchaseByBatch.setEncapsulation(null);
-            }
-        }
+//        Object encapsulationValue = readWorkBookCell(row.getCell(ENCAPSULATIONNUM), Cell.CELL_TYPE_STRING,
+//                rowNum, ENCAPSULATIONNUM);
+//        if (!StringUtils.isEmpty(encapsulationValue)) {
+//            try {
+//                String encapsulation = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(encapsulationValue));
+//                encapsulation = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(encapsulation, 20);
+//                seekPurchaseByBatch.setEncapsulation(encapsulation);
+//            } catch (Exception e) {
+//                seekPurchaseByBatch.setEncapsulation(null);
+//            }
+//        }
 
 
         // 生产日期
-        Object produceDateValue = readWorkBookCell(row.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
-                rowNum, PRODUCEDATENUM);
-        if (!StringUtils.isEmpty(produceDateValue)) {
-            try {
-                String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
-                produceDate = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(produceDate, 20);
-                seekPurchaseByBatch.setProduceDate(produceDate);
-            } catch (Exception e) {
-                seekPurchaseByBatch.setProduceDate(null);
-            }
-        }
+//        Object produceDateValue = readWorkBookCell(row.getCell(PRODUCEDATENUM), Cell.CELL_TYPE_STRING,
+//                rowNum, PRODUCEDATENUM);
+//        if (!StringUtils.isEmpty(produceDateValue)) {
+//            try {
+//                String produceDate = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(produceDateValue));
+//                produceDate = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(produceDate, 20);
+//                seekPurchaseByBatch.setProduceDate(produceDate);
+//            } catch (Exception e) {
+//                seekPurchaseByBatch.setProduceDate(null);
+//            }
+//        }
 
         // 规格
         Object specValue = readWorkBookCell(row.getCell(SPECNUM), Cell.CELL_TYPE_STRING,
                 rowNum, SPECNUM);
         if (!StringUtils.isEmpty(specValue)) {
-            try {
-                String spec = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(specValue));
-                spec = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(spec, 50);
-                if (!match(spec)) {
-                    spec = null;
-                }
-                seekPurchaseByBatch.setSpec(spec);
-            } catch (Exception e) {
-                seekPurchaseByBatch.setSpec(null);
-            }
+            seekPurchaseByBatch.setSpec(convert(specValue, 50));
         }
 
         // 类目
         Object kindValue = readWorkBookCell(row.getCell(KINDNUM), Cell.CELL_TYPE_STRING,
                 rowNum, KINDNUM);
         if (!StringUtils.isEmpty(kindValue)) {
-            try {
-                String kind = StringUtilB2C.replaceLineBreak(StringUtilB2C.getStr(kindValue));
-                kind = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutString(kind, 20);
-                seekPurchaseByBatch.setKind(kind);
-            } catch (Exception e) {
-                seekPurchaseByBatch.setKind(null);
-            }
+            seekPurchaseByBatch.setKind(convert(kindValue, 50));
         }
         return result;
     }
@@ -415,14 +401,14 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
      * @param code
      * @return
      */
-    private boolean match(String code) {
+    private String match(String code) {
         List<String> filterList = Arrays.asList("空", "没", "无", "—", "-", "null", "#N/A");
         for (String s : filterList) {
             if (s.equals(code)){
-                return false;
+                return null;
             }
         }
-        return true;
+        return code;
     }
 
     /**
@@ -588,6 +574,7 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
         }
         // 删除bom的临时数据
         seekPurchaseBomDao.delete(seekPurchaseBom.getId());
+        seekPurchaseBomListDao.deleteByBomId(seekPurchaseBom.getId());
         Map<String, Object> result = new HashMap<>();
         result.put("successAmount", inquiryItems.size());
         result.put("goodsAmount", haveGoodsCount);

BIN
src/main/resources/jxls-tpl/trade/seekPurchaseByBatch.xls