Browse Source

判断在表格中是否重复。

yujia 7 years ago
parent
commit
a945a3cc18

+ 19 - 15
src/main/java/com/uas/platform/b2c/common/psmessage/util/JsonObjectUtil.java

@@ -9,6 +9,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.util.StringUtils;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -23,21 +24,24 @@ public class JsonObjectUtil {
      * jsonobject 转换成page
      * @return
      */
-    public static Page<Object> convertToPage(JSONObject jsonObject, Class cls) {
-//        String content  = String.valueOf(jsonObject.get("content"));
-//        if (!StringUtils.isEmpty(content)) {
-//            try {
-//                List<? extends Class> array = FastjsonUtils.fromJsonArray(content, cls.getClass());
-//                Object number = jsonObject.get("number");
-//                PageImpl<T> page = new PageImpl<T>(array);
-//            } catch (Exception e) {
-//                e.printStackTrace();
-//                return new PageImpl<?>(Collections.<T>emptyList(), new PageInfo(new PageParams(1, 10, null, null)), 0);
-//            }
-//        }
-//        return new PageImpl<T>(Collections.<T>emptyList(), new PageInfo(new PageParams(1, 10, null, null)), 0);
-        //TODO
-        return null;
+    public static <T> Page<T> convertToPage(JSONObject jsonObject, Class<T> cls) {
+        String content  = String.valueOf(jsonObject.get("content"));
+        if (!StringUtils.isEmpty(content)) {
+            try {
+                List<? extends Class> list = FastjsonUtils.fromJsonArray(content, cls.getClass());
+                List<T> listT = new ArrayList<>();
+                for (Class aClass : list) {
+                    T t = cls.cast(aClass);
+                    listT.add(t);
+                }
+                Object number = jsonObject.get("number");
+                PageImpl<T> page = new PageImpl<T>(listT);
+            } catch (Exception e) {
+                e.printStackTrace();
+                return new PageImpl<T>(Collections.<T>emptyList(), new PageInfo(new PageParams(1, 10, null, null)), 0);
+            }
+        }
+        return new PageImpl<T>(Collections.<T>emptyList(), new PageInfo(new PageParams(1, 10, null, null)), 0);
     }
 
 

+ 1 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ReleaseProductByBatchDao.java

@@ -89,7 +89,7 @@ public interface ReleaseProductByBatchDao
 	 * @param isPersonal 是否是个人
 	 * @param enuu 公司enuu
 	 */
-	@Procedure(procedureName = "PRODUCT_RELEASE_EXIST_VALID_V1")
+	@Procedure(procedureName = "PRODUCT_RELEASE_EXIST_VALID_V2")
 	void callReleaseExistValidProcedure(String batch, Boolean isPersonal, Long enuu);
 
 	/**

+ 126 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java

@@ -1838,4 +1838,130 @@ public class ReleaseProductByBatch implements Serializable {
 		this.productid = productid;
 		return this;
 	}
+
+	@Override
+	public String toString() {
+		return "ReleaseProductByBatch{" +
+				"id=" + id +
+				", relbatchid='" + relbatchid + '\'' +
+				", batchCode='" + batchCode + '\'' +
+				", status=" + status +
+				", statusStr='" + statusStr + '\'' +
+				", saleMethod='" + saleMethod + '\'' +
+				", brandNameCn='" + brandNameCn + '\'' +
+				", brandNameEn='" + brandNameEn + '\'' +
+				", b2cBrandcn='" + b2cBrandcn + '\'' +
+				", b2cBranden='" + b2cBranden + '\'' +
+				", brandId=" + brandId +
+				", branduuid='" + branduuid + '\'' +
+				", code='" + code + '\'' +
+				", b2cCode='" + b2cCode + '\'' +
+				", componentUuId='" + componentUuId + '\'' +
+				", unit='" + unit + '\'' +
+				", original=" + original +
+				", reserve=" + reserve +
+				", reserveStr='" + reserveStr + '\'' +
+				", minBuyQty=" + minBuyQty +
+				", minBuyQtyStr='" + minBuyQtyStr + '\'' +
+				", qtyPrice='" + qtyPrice + '\'' +
+				", prices=" + prices +
+				", productDate='" + productDate + '\'' +
+				", createDate=" + createDate +
+				", minPackage=" + minPackage +
+				", minPackageStr='" + minPackageStr + '\'' +
+				", breakUp=" + breakUp +
+				", breakUpStr='" + breakUpStr + '\'' +
+				", packaging='" + packaging + '\'' +
+				", encapsulation='" + encapsulation + '\'' +
+				", tagstr='" + tagstr + '\'' +
+				", tag='" + tag + '\'' +
+				", selfMaxDelivery=" + selfMaxDelivery +
+				", selfMinDelivery=" + selfMinDelivery +
+				", selfMaxDeliveryStr='" + selfMaxDeliveryStr + '\'' +
+				", selfMinDeliveryStr='" + selfMinDeliveryStr + '\'' +
+				", size='" + size + '\'' +
+				", color='" + color + '\'' +
+				", thickCopper='" + thickCopper + '\'' +
+				", thick='" + thick + '\'' +
+				", remark='" + remark + '\'' +
+				", publisherName='" + publisherName + '\'' +
+				", publisherUu=" + publisherUu +
+				", publisherTel='" + publisherTel + '\'' +
+				", currency='" + currency + '\'' +
+				", sampleqty=" + sampleqty +
+				", rmbTaxRate=" + rmbTaxRate +
+				", usdTaxRate=" + usdTaxRate +
+				", returnInWeek=" + returnInWeek +
+				", releaseCode=" + releaseCode +
+				", releaseStatus='" + releaseStatus + '\'' +
+				", shipArea='" + shipArea + '\'' +
+				", rmbMinPackPrice=" + rmbMinPackPrice +
+				", usdMinPackPrice=" + usdMinPackPrice +
+				", minPackPriceStr='" + minPackPriceStr + '\'' +
+				", img='" + img + '\'' +
+				", kindName='" + kindName + '\'' +
+				", kindUuid=" + kindUuid +
+				", qty1Str='" + qty1Str + '\'' +
+				", qty2Str='" + qty2Str + '\'' +
+				", qty3Str='" + qty3Str + '\'' +
+				", price1='" + price1 + '\'' +
+				", price2='" + price2 + '\'' +
+				", price3='" + price3 + '\'' +
+				", errmsg='" + errmsg + '\'' +
+				", minPriceRMB=" + minPriceRMB +
+				", maxPriceRMB=" + maxPriceRMB +
+				", minPriceUSD=" + minPriceUSD +
+				", maxPriceUSD=" + maxPriceUSD +
+				", storeid='" + storeid + '\'' +
+				", storeName='" + storeName + '\'' +
+				", spec='" + spec + '\'' +
+				", productid=" + productid +
+				", attach='" + attach + '\'' +
+				", goodsCount=" + goodsCount +
+				'}';
+	}
+
+	/**
+	 *
+	 * @param batch 上架批次
+	 * @return 相同则true,否则false
+	 */
+	public Boolean compareSameProductTagInfo(ReleaseProductByBatch batch) {
+		if (batch != null) {
+			return StringUtilB2C.equals(batch.getB2cBranden(), this.b2cBranden) && StringUtilB2C.equals(batch.getB2cCode(), this.b2cCode) && StringUtilB2C.equals(batch.getTag(), this.tag);
+		} else {
+			return Boolean.FALSE;
+		}
+	}
+
+	/**
+	 * 六要素比较
+	 */
+
+	public Boolean compareSameProductSixEle(ReleaseProductByBatch batch) {
+		if (batch != null) {
+			Boolean result = false;
+			if (StringUtils.isEmpty(batch.getMinBuyQtyStr()) || StringUtils.isEmpty(this.getMinBuyQtyStr()) || (!StringUtilB2C.equals(batch.getMinBuyQtyStr(), this.getMinBuyQtyStr()))) {
+				return false;
+			}
+			if (StringUtils.isEmpty(batch.getProductDate()) || StringUtils.isEmpty(this.getProductDate()) || (!StringUtilB2C.equals(batch.getProductDate(), this.getProductDate()))) {
+				return false;
+			}
+			if (StringUtils.isEmpty(batch.getPackaging()) || StringUtils.isEmpty(this.getPackaging()) || (!StringUtilB2C.equals(batch.getPackaging(), this.getPackaging()))) {
+				return false;
+			}
+			if (StringUtils.isEmpty(batch.getMinPackageStr()) || StringUtils.isEmpty(this.getMinPackageStr()) || (!StringUtilB2C.equals(batch.getMinPackageStr(), this.getMinPackageStr()))) {
+				return false;
+			}
+			if (StringUtils.isEmpty(batch.getSelfMaxDeliveryStr()) || StringUtils.isEmpty(this.getSelfMaxDeliveryStr()) || (!StringUtilB2C.equals(batch.getSelfMaxDeliveryStr(), this.getSelfMaxDeliveryStr()))) {
+				return false;
+			}
+			if (StringUtils.isEmpty(batch.getSelfMinDeliveryStr()) || StringUtils.isEmpty(this.getSelfMinDeliveryStr()) || (!StringUtilB2C.equals(batch.getSelfMinDeliveryStr(), this.getSelfMinDeliveryStr()))) {
+				return false;
+			}
+			return true;
+		} else {
+			return Boolean.FALSE;
+		}
+	}
 }

+ 21 - 4
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ReleaseProductByBatchServiceImpl.java

@@ -222,20 +222,37 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				}
 			}
 		}
+		System.out.println("获取订单信息缺失");
 		long l1 = System.currentTimeMillis();
 		System.err.println("l1--------------l" + (l1 - l));
 		Long userUU = SystemSession.getUser().getUserUU();
 		Long enUU = SystemSession.getUser().getEnterprise().getUu();
-		List<ReleaseProductByBatch> addList = new ArrayList<>(releaseProductByBatchs.size());
-		addList.addAll(releaseProductByBatchs);
-        commonDao.save(addList, ReleaseProductByBatch.class);
+		if (!isAPerson) {
+			//1:比较品牌、型号、自定义标签是否重复,2:比较六要素是否重复
+			for(int i = releaseProductByBatchs.size(); i > 0; i--) {
+				ReleaseProductByBatch releaseProductByBatch = releaseProductByBatchs.get(i);
+				for(int j = i - 1; j > 0; j--) {
+					ReleaseProductByBatch byBatch = releaseProductByBatchs.get(j);
+					if(releaseProductByBatch.compareSameProductTagInfo(byBatch)) {
+						releaseProductByBatch.setTag("");
+						releaseProductByBatch.setTagstr("");
+						if (releaseProductByBatch.compareSameProductSixEle(byBatch)) {
+							releaseProductByBatch.addErrmsg(ErrorInfoConstant.REPEAT_IN_EXCEL.getInfo());
+							releaseProductByBatch.setReleaseStatus(ReleaseStatus.had_exists.getPhrase());
+							releaseProductByBatch.setReleaseCode(ReleaseStatus.had_exists.value());
+						}
+					}
+				}
+			}
+		}
+		commonDao.save(releaseProductByBatchs, ReleaseProductByBatch.class);
 		long l2 = System.currentTimeMillis();
 		System.err.println("l2--------------l1" + (l2 - l1));
         releaseProductByBatchDao.callReleaseExistValidProcedure(batch, isAPerson, enUU);
 		long l3 = System.currentTimeMillis();
 		System.err.println("l3--------------l2" + (l3 - l2));
 		if (isAPerson) {
-			for (ReleaseProductByBatch releaseProductByBatch : addList) {
+			for (ReleaseProductByBatch releaseProductByBatch : releaseProductByBatchs) {
                 Long productid = releaseProductByBatch.getProductid();
                 if (productid != null) {
                     List<ProductPerson> productPersonList = productPersonDao.findByProductId(productid);