|
|
@@ -131,6 +131,11 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
*/
|
|
|
private static final Integer THIRD_PRODUCT_AMOUNT_SCORE = 5;
|
|
|
|
|
|
+ /**
|
|
|
+ * sql执行条数
|
|
|
+ */
|
|
|
+ private static final Integer SQL_COMMIT_AMOUNT = 500;
|
|
|
+
|
|
|
/* =========================================企业分数计算end==================================================== */
|
|
|
|
|
|
/**
|
|
|
@@ -263,9 +268,13 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
public void calculateEnterpriseScore() {
|
|
|
long start = System.currentTimeMillis();
|
|
|
List<Enterprise> enterprises = enterpriseDao.findAll();
|
|
|
+ logger.info("查找全部企业信息,条数:{},耗时:{}", enterprises.size(), (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
if (!CollectionUtils.isEmpty(enterprises)) {
|
|
|
// 商家信息 企业介绍 联系方式
|
|
|
StringBuilder infoSqls = new StringBuilder();
|
|
|
+
|
|
|
+ int enSum = 0;
|
|
|
for (Enterprise enterprise : enterprises) {
|
|
|
// 初始化分数 所有企业
|
|
|
int info = 0;
|
|
|
@@ -277,32 +286,69 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
}
|
|
|
infoSqls.append("update sec$enterprises set en_score = ").append(info).append(" where en_uu = ")
|
|
|
.append(enterprise.getUu()).append(";");
|
|
|
+ enSum++;
|
|
|
+
|
|
|
+ // 到达执行条数时就执行一次,避免sql语句太长,执行超时
|
|
|
+ if (enSum == SQL_COMMIT_AMOUNT) {
|
|
|
+ commonDao.getJdbcTemplate().execute(infoSqls.toString());
|
|
|
+ logger.info("商家信息分数更新,条数:{},耗时:{}", enSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 重置语句和计数
|
|
|
+ infoSqls = new StringBuilder();
|
|
|
+ enSum = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新余下的企业分数
|
|
|
+ if (!StringUtils.isEmpty(infoSqls)) {
|
|
|
+ commonDao.getJdbcTemplate().execute(infoSqls.toString());
|
|
|
+ logger.info("商家信息分数更新,条数:{},耗时:{}", enSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
}
|
|
|
- commonDao.getJdbcTemplate().execute(infoSqls.toString());
|
|
|
- logger.info("商家信息分数更新,条数:{},耗时:{}", enterprises.size(), (System.currentTimeMillis() - start));
|
|
|
- start = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
// 主营产品
|
|
|
List<Long> storeUUs = commonDao.queryForList("select st_enuu from store$info where st_description is not null", Long.class);
|
|
|
if (!CollectionUtils.isEmpty(storeUUs)) {
|
|
|
+ // 店铺更新计数
|
|
|
+ int storeSum = 0;
|
|
|
+
|
|
|
// 主营产品更新执行语句
|
|
|
StringBuilder storeUpdateSqls = new StringBuilder();
|
|
|
for (Long storeUU : storeUUs) {
|
|
|
// 添加主营产品分数增加语句
|
|
|
storeUpdateSqls.append("update sec$enterprises set en_score = convert((en_score + ").append(MAIN_PRODUCT_SCORE)
|
|
|
.append("),DECIMAL(20,6)) where en_uu = ").append(storeUU).append(";");
|
|
|
+ storeSum++;
|
|
|
+ // 每满一次,提交一次,避免语句过长
|
|
|
+ if (storeSum == SQL_COMMIT_AMOUNT) {
|
|
|
+ commonDao.getJdbcTemplate().execute(storeUpdateSqls.toString());
|
|
|
+ logger.info("主营产品分数更新,条数:{},耗时:{}", storeSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 重置
|
|
|
+ storeSum = 0;
|
|
|
+ storeUpdateSqls = new StringBuilder();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新余下的
|
|
|
+ if (!StringUtils.isEmpty(storeUpdateSqls)) {
|
|
|
+ commonDao.getJdbcTemplate().execute(storeUpdateSqls.toString());
|
|
|
+ logger.info("主营产品分数更新,条数:{},耗时:{}", storeSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
}
|
|
|
- commonDao.getJdbcTemplate().execute(storeUpdateSqls.toString());
|
|
|
- logger.info("主营产品分数更新,条数:{},耗时:{}", storeUUs.size(), (System.currentTimeMillis() - start));
|
|
|
- start = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
// 产品数量
|
|
|
List<ProductAmount> productAmounts = commonDao.query("select * from (select pr_enuu as enUU,count(1) as amount from products group by pr_enuu) a where a.amount > 10", ProductAmount.class);
|
|
|
if (!CollectionUtils.isEmpty(productAmounts)) {
|
|
|
- StringBuilder productAmountUpdateSqls = new StringBuilder();
|
|
|
- for (ProductAmount productAmount : productAmounts) {
|
|
|
+ // 产品数量企业 计数
|
|
|
+ int productSum = 0;
|
|
|
+ StringBuilder productAmountUpdateSqls = new StringBuilder();
|
|
|
+ for (ProductAmount productAmount : productAmounts) {
|
|
|
+
|
|
|
if (productAmount.getAmount() > FIRST_PRODUCT_AMOUNT_BASE) {
|
|
|
// 产品数量分数更新执行语句
|
|
|
productAmountUpdateSqls.append("update sec$enterprises set en_score = convert((en_score + ").append(FIRST_PRODUCT_AMOUNT_SCORE)
|
|
|
@@ -314,11 +360,27 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
productAmountUpdateSqls.append("update sec$enterprises set en_score = convert((en_score + ").append(THIRD_PRODUCT_AMOUNT_SCORE)
|
|
|
.append("),DECIMAL(20,6)) where en_uu = ").append(productAmount.getEnUU()).append(";");
|
|
|
}
|
|
|
+ productSum++;
|
|
|
+
|
|
|
+ // 到达限制就提交
|
|
|
+ if (productSum == SQL_COMMIT_AMOUNT) {
|
|
|
+ commonDao.getJdbcTemplate().execute(productAmountUpdateSqls.toString());
|
|
|
+ logger.info("产品数量分数更新,条数:{},耗时:{}", productSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 重置
|
|
|
+ productSum = 0;
|
|
|
+ productAmountUpdateSqls = new StringBuilder();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- commonDao.getJdbcTemplate().execute(productAmountUpdateSqls.toString());
|
|
|
- logger.info("产品数量分数更新,条数:{},耗时:{}", productAmounts.size(), (System.currentTimeMillis() - start));
|
|
|
- start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 剩余更新
|
|
|
+ if (!StringUtils.isEmpty(productAmountUpdateSqls)) {
|
|
|
+ commonDao.getJdbcTemplate().execute(productAmountUpdateSqls.toString());
|
|
|
+ logger.info("产品数量分数更新,条数:{},耗时:{}", productSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 有价数量
|
|
|
@@ -326,6 +388,8 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
List<BigInteger> priceUUs = enterpriseDao.findEnRankByPriceProductAmount();
|
|
|
Double i = 1d;
|
|
|
if (!CollectionUtils.isEmpty(priceUUs)) {
|
|
|
+ // 有价数量企业 计数
|
|
|
+ int priceSum = 0;
|
|
|
// 价格排行更新执行语句
|
|
|
StringBuilder priceUpdateSqls = new StringBuilder();
|
|
|
for (BigInteger priceUU : priceUUs) {
|
|
|
@@ -337,16 +401,31 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
break;
|
|
|
}
|
|
|
i++;
|
|
|
+
|
|
|
+ priceSum++;
|
|
|
+ if (priceSum == SQL_COMMIT_AMOUNT) {
|
|
|
+ commonDao.getJdbcTemplate().execute(priceUpdateSqls.toString());
|
|
|
+ logger.info("有价数量分数更新,条数:{},耗时:{}", priceSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 重置
|
|
|
+ priceSum = 0;
|
|
|
+ priceUpdateSqls = new StringBuilder();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(priceUpdateSqls)) {
|
|
|
+ commonDao.getJdbcTemplate().execute(priceUpdateSqls.toString());
|
|
|
+ logger.info("有价数量分数更新,条数:{},耗时:{}", priceSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
}
|
|
|
- commonDao.getJdbcTemplate().execute(priceUpdateSqls.toString());
|
|
|
- logger.info("有价数量分数更新,条数:{},耗时:{}", priceUUs.size(), (System.currentTimeMillis() - start));
|
|
|
- start = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
// 有库存数量
|
|
|
// 有库存数量排序
|
|
|
List<BigInteger> reserveUUs = enterpriseDao.findEnRankByReserveProductAmount();
|
|
|
if (!CollectionUtils.isEmpty(reserveUUs)) {
|
|
|
+ // 有库存计数
|
|
|
+ int reserveSum = 0;
|
|
|
// 价格排行更新执行语句
|
|
|
StringBuilder reserveUpdateSqls = new StringBuilder();
|
|
|
i = 1d;
|
|
|
@@ -359,10 +438,23 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
break;
|
|
|
}
|
|
|
i++;
|
|
|
+
|
|
|
+ reserveSum++;
|
|
|
+ if (reserveSum == SQL_COMMIT_AMOUNT) {
|
|
|
+ commonDao.getJdbcTemplate().execute(reserveUpdateSqls.toString());
|
|
|
+ logger.info("有库存数量分数更新,条数:{},耗时:{}", reserveSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 重置
|
|
|
+ reserveSum = 0;
|
|
|
+ reserveUpdateSqls = new StringBuilder();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(reserveUpdateSqls)) {
|
|
|
+ commonDao.getJdbcTemplate().execute(reserveUpdateSqls.toString());
|
|
|
+ logger.info("有库存数量分数更新,条数:{},耗时:{}", reserveSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
}
|
|
|
- commonDao.getJdbcTemplate().execute(reserveUpdateSqls.toString());
|
|
|
- logger.info("有库存数量分数更新,条数:{},耗时:{}", reserveUUs.size(), (System.currentTimeMillis() - start));
|
|
|
- start = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
// 回价数量
|
|
|
@@ -371,6 +463,8 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
// 价格排行更新执行语句
|
|
|
StringBuilder replyUpdateSqls = new StringBuilder();
|
|
|
if (!CollectionUtils.isEmpty(replyUUs)) {
|
|
|
+ int replySum = 0;
|
|
|
+
|
|
|
i = 1d;
|
|
|
for (Long replyUU : replyUUs) {
|
|
|
Double score = new BigDecimal(INQUIRY_REPLU_BASE_SCORE / i).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
@@ -381,10 +475,23 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
break;
|
|
|
}
|
|
|
i++;
|
|
|
+
|
|
|
+ replySum++;
|
|
|
+ if (replySum == SQL_COMMIT_AMOUNT) {
|
|
|
+ commonDao.getJdbcTemplate().execute(replyUpdateSqls.toString());
|
|
|
+ logger.info("回价数量分数更新,条数:{},耗时:{}", replySum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 重置
|
|
|
+ replySum = 0;
|
|
|
+ replyUpdateSqls = new StringBuilder();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(replyUpdateSqls)) {
|
|
|
+ commonDao.getJdbcTemplate().execute(replyUpdateSqls.toString());
|
|
|
+ logger.info("回价数量分数更新,条数:{},耗时:{}", replySum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
}
|
|
|
- commonDao.getJdbcTemplate().execute(replyUpdateSqls.toString());
|
|
|
- logger.info("回价数量分数更新,条数:{},耗时:{}", replyUUs.size(), (System.currentTimeMillis() - start));
|
|
|
- start = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
// 交易额
|
|
|
@@ -393,6 +500,9 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
// 价格排行更新执行语句
|
|
|
StringBuilder purchaseUpdateSqls = new StringBuilder();
|
|
|
if (!CollectionUtils.isEmpty(purchaseUUs)) {
|
|
|
+ // 交易额 企业 计数
|
|
|
+ int purchaseSum = 0;
|
|
|
+
|
|
|
i = 1d;
|
|
|
for (BigInteger purchaseUU : purchaseUUs) {
|
|
|
Double score = new BigDecimal(PURCHASE_AMOUNT_BASE_SCORE / i).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
@@ -403,10 +513,23 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
break;
|
|
|
}
|
|
|
i++;
|
|
|
+
|
|
|
+ purchaseSum++;
|
|
|
+ if (purchaseSum == SQL_COMMIT_AMOUNT) {
|
|
|
+ commonDao.getJdbcTemplate().execute(purchaseUpdateSqls.toString());
|
|
|
+ logger.info("交易额数量分数更新,条数:{},耗时:{}", purchaseSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 重置
|
|
|
+ purchaseSum = 0;
|
|
|
+ purchaseUpdateSqls = new StringBuilder();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(purchaseUpdateSqls)) {
|
|
|
+ commonDao.getJdbcTemplate().execute(purchaseUpdateSqls.toString());
|
|
|
+ logger.info("交易额数量分数更新,条数:{},耗时:{}", purchaseSum, (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
}
|
|
|
- commonDao.getJdbcTemplate().execute(purchaseUpdateSqls.toString());
|
|
|
- logger.info("交易额数量分数更新,条数:{},耗时:{}", purchaseUUs.size(), (System.currentTimeMillis() - start));
|
|
|
- start = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
// 更新店铺中的分数(原厂、经销排行)
|