|
@@ -0,0 +1,275 @@
|
|
|
+package com.uas.erp.test;
|
|
|
+
|
|
|
+import com.uas.api.b2c_erp.baisc.service.ComponentService;
|
|
|
+import com.uas.api.b2c_erp.seller.model.Prod;
|
|
|
+import com.uas.api.b2c_erp.seller.service.ProdService;
|
|
|
+import com.uas.api.crypto.util.SecretUtil;
|
|
|
+import com.uas.erp.schedular.UasSchedulingApplication;
|
|
|
+import com.uas.erp.schedular.entity.Master;
|
|
|
+import com.uas.erp.schedular.mall.constant.StringConstant;
|
|
|
+import com.uas.erp.schedular.mall.task.AbstractTask;
|
|
|
+import com.uas.erp.schedular.util.ContextHolder;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * description
|
|
|
+ *
|
|
|
+ * @author yuj 2018-05-15 18:54
|
|
|
+ */
|
|
|
+@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = UasSchedulingApplication.class)
|
|
|
+public class ProdTest extends AbstractTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProdService prodService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ComponentService componentService;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void uploadProduct() {
|
|
|
+ Master master = new Master();
|
|
|
+ master.setMa_user("USOFT_MALL");
|
|
|
+ master.setMa_uu(10042875L);
|
|
|
+ master.setMa_accesssecret("b8d3184fde5c444f87dc55c123f1a690");
|
|
|
+ master.setMa_env("test");
|
|
|
+ master.setMa_name("USOFT_MALL");
|
|
|
+ SecretUtil.set(Long.toString(master.getMa_uu()), master.getMa_accesssecret());
|
|
|
+ ContextHolder.setMaster(master);
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ List<String> sqls = null;
|
|
|
+ List<Prod> prods = prodService.findNewProdUploadMallERP(i);
|
|
|
+ while (!CollectionUtils.isEmpty(prods)) {
|
|
|
+ sqls = new ArrayList<>();
|
|
|
+ for (com.uas.api.b2c_erp.seller.model.Prod prod : prods) {
|
|
|
+ String sqlString = prod.toSqlString();
|
|
|
+ String sql = sqlString.replaceAll("'null'", "''");
|
|
|
+ sqls.add(sql);
|
|
|
+ }
|
|
|
+ List<String> list = batchSaveProd(sqls, StringConstant.PRODUCT_TYPE);
|
|
|
+// if (!CollectionUtils.isEmpty(list)) {
|
|
|
+// prodService.updateNewProdDowned(list);
|
|
|
+// }
|
|
|
+ prods = prodService.findNewProdUploadMallERP(i);
|
|
|
+ System.out.println(prods.size());
|
|
|
+ }
|
|
|
+// int totalPages = (int) Math.ceil((double) prods.getTotalElements() / 500);
|
|
|
+// while (i <= totalPages) {
|
|
|
+// List<String> sqls = new ArrayList<>();
|
|
|
+//
|
|
|
+//
|
|
|
+// int nextTotalPages = (int) Math.ceil((double) prods.getTotalElements() / 500);
|
|
|
+// if (totalPages == nextTotalPages) {
|
|
|
+// i++;
|
|
|
+// } else {
|
|
|
+// i = 1;
|
|
|
+// totalPages = nextTotalPages;
|
|
|
+// }
|
|
|
+// System.out.println(i + "------------" + totalPages);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void uploadProduct1() {
|
|
|
+ Master master = new Master();
|
|
|
+ master.setMa_user("USOFT_MALL");
|
|
|
+ master.setMa_uu(10042875L);
|
|
|
+ master.setMa_accesssecret("b8d3184fde5c444f87dc55c123f1a690");
|
|
|
+ master.setMa_env("test");
|
|
|
+ master.setMa_name("USOFT_MALL");
|
|
|
+ SecretUtil.set(Long.toString(master.getMa_uu()), master.getMa_accesssecret());
|
|
|
+ ContextHolder.setMaster(master);
|
|
|
+
|
|
|
+ int i = 1;
|
|
|
+ List<Prod> prods = componentService.findNewComponentUploadMallERP(i);
|
|
|
+// int totalPages = (int) Math.ceil((double) prods.getTotalElements() / 500);
|
|
|
+ while (!CollectionUtils.isEmpty(prods)) {
|
|
|
+ List<String> sqls = new ArrayList<>();
|
|
|
+ for (com.uas.api.b2c_erp.seller.model.Prod prod : prods) {
|
|
|
+ String sqlString = prod.toSqlString();
|
|
|
+ String sql = sqlString.replaceAll("'null'", "''");
|
|
|
+ sqls.add(sql);
|
|
|
+ }
|
|
|
+ List<String> list = batchSaveProd(sqls, StringConstant.CMP_TYPE);
|
|
|
+// componentService.updateNewComponentDowned(list);
|
|
|
+ prods = componentService.findNewComponentUploadMallERP(i);
|
|
|
+// int nextTotalPages = (int) Math.ceil((double) prods.getTotalElements() / 500);
|
|
|
+// if (totalPages == nextTotalPages) {
|
|
|
+// i++;
|
|
|
+// } else {
|
|
|
+// i = 1;
|
|
|
+// totalPages = nextTotalPages;
|
|
|
+// }
|
|
|
+// System.out.println(i + "------------" + totalPages);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拆分批量保存
|
|
|
+ * @param sqls
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> splitList(List<String> sqls, String type) {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(sqls)) {
|
|
|
+ if (sqls.size() < 2) {
|
|
|
+ try {
|
|
|
+ if (sqls.size() > 0) {
|
|
|
+ jdbcTemplate.execute(sqls.get(0));
|
|
|
+ List<String> list1 = null;
|
|
|
+ if (type.equals(StringConstant.PRODUCT_TYPE)) {
|
|
|
+ list1 = analyzeMaterialCodeAndBrand(sqls);
|
|
|
+ } else {
|
|
|
+ list1 = analyzeMaterialNum(sqls);
|
|
|
+ }
|
|
|
+ list.addAll(list1);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ String message = e.getMessage();
|
|
|
+ if (!StringUtils.isEmpty(message)) {
|
|
|
+ boolean brand_orispeccode = message.contains("PRODUCT_BRAND_ORISPECCODE");
|
|
|
+ if (brand_orispeccode) {
|
|
|
+ List<String> list1 = null;
|
|
|
+ if (type.equals(StringConstant.PRODUCT_TYPE)) {
|
|
|
+ list1 = analyzeMaterialCodeAndBrand(sqls);
|
|
|
+ } else {
|
|
|
+ list1 = analyzeMaterialNum(sqls);
|
|
|
+ }
|
|
|
+ list.addAll(list1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<String> sql1 = new ArrayList<>();
|
|
|
+ List<String> sql2 = new ArrayList<>();
|
|
|
+ int size = sqls.size()/2;
|
|
|
+ for (int i = 0; i < sqls.size(); i++) {
|
|
|
+ if (i < size) {
|
|
|
+ sql1.add(sqls.get(i));
|
|
|
+ } else {
|
|
|
+ sql2.add(sqls.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> list3 = batchSaveProd(sql1, type);
|
|
|
+ if (list3 != null) {
|
|
|
+ list.addAll(list3);
|
|
|
+ }
|
|
|
+ List<String> list4 = batchSaveProd(sql2, type);
|
|
|
+ if (list4 != null) {
|
|
|
+ list.addAll(list4);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量保存物料信息
|
|
|
+ * @param sqls 需要保存的信息
|
|
|
+ * @return 以保存的物料编号
|
|
|
+ */
|
|
|
+ public List<String> batchSaveProd(List<String> sqls, String type) {
|
|
|
+ List<String> list = null;
|
|
|
+ try {
|
|
|
+ jdbcTemplate.batchExecute(sqls);
|
|
|
+ if (type.equals(StringConstant.PRODUCT_TYPE)) {
|
|
|
+ list = analyzeMaterialCodeAndBrand(sqls);
|
|
|
+ } else {
|
|
|
+ list = analyzeMaterialNum(sqls);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ list = splitList(sqls, type);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析物料编号
|
|
|
+ * @param sqls
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> analyzeMaterialNum(List<String> sqls) {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(sqls)) {
|
|
|
+ for (String sql : sqls) {
|
|
|
+ String substring = sql.substring(220);
|
|
|
+ String[] split = substring.split("'");
|
|
|
+ if (!StringUtils.isEmpty(split[0])) {
|
|
|
+ list.add(split[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析型号和品牌,用中划线链接
|
|
|
+ * @param sqls
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> analyzeMaterialCodeAndBrand(List<String> sqls) {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(sqls)) {
|
|
|
+ for (String sql : sqls) {
|
|
|
+ String code = analyzeMaterialCode(sql);
|
|
|
+ String brand = analyzeMaterialBrand(sql);
|
|
|
+ list.add(code + "-----" + brand);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析出型号
|
|
|
+ * @param sql 拼接的插入数据库
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String analyzeMaterialCode(String sql) {
|
|
|
+ if (!StringUtils.isEmpty(sql)) {
|
|
|
+ String[] split = sql.split("','已审核','余佳','");
|
|
|
+ String first = split[0];
|
|
|
+ if (!StringUtils.isEmpty(first)) {
|
|
|
+ String[] split1 = first.split("'");
|
|
|
+ return split1[split1.length - 1];
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析品牌
|
|
|
+ * @param sql 拼接的插入数据库
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String analyzeMaterialBrand(String sql) {
|
|
|
+ if (!StringUtils.isEmpty(sql)) {
|
|
|
+ String[] split = sql.split("','已审核','余佳','");
|
|
|
+ String first = split[split.length - 1];
|
|
|
+ if (!StringUtils.isEmpty(first)) {
|
|
|
+ String[] split1 = first.split("'");
|
|
|
+ return split1[0];
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|