|
|
@@ -8,15 +8,21 @@ import com.uas.platform.b2c.common.search.util.SPage;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.V_ProductPrivateDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
|
|
|
import com.uas.platform.b2c.prod.store.dao.StoreInDao;
|
|
|
+import com.uas.platform.b2c.trade.order.dao.PurchaseDao;
|
|
|
import com.uas.platform.b2c.trade.vendor.model.VendorIntroduction;
|
|
|
import com.uas.platform.b2c.trade.vendor.service.VendorIntroductionService;
|
|
|
import com.uas.ps.core.util.CollectionUtils;
|
|
|
import com.uas.sso.support.Page;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -42,6 +48,11 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
@Autowired
|
|
|
private StoreInDao storeInDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PurchaseDao purchaseDao;
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(VendorIntroductionServiceImpl.class);
|
|
|
+
|
|
|
/**
|
|
|
* 类目
|
|
|
*/
|
|
|
@@ -57,6 +68,21 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
*/
|
|
|
private static final String PBRANDEN_EQUAL = "brand";
|
|
|
|
|
|
+ /**
|
|
|
+ * 价格排行和库存排行分数基数
|
|
|
+ */
|
|
|
+ private static final Integer PRICE_RESERVE_BASE = 15;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回价分数基数
|
|
|
+ */
|
|
|
+ private static final Integer INQUIRY_REPLU_BASE = 10;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 交易额分数基数
|
|
|
+ */
|
|
|
+ private static final Integer PURCHASE_AMOUNT_BASE = 20;
|
|
|
+
|
|
|
/**
|
|
|
* 根据关键词(非必填)精确匹配来获取供应商资源列表
|
|
|
*
|
|
|
@@ -179,6 +205,124 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
return getTotalCount(null, null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算企业分数
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void calculateEnterpriseScore() {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ List<Enterprise> enterprises = enterpriseDao.findAll();
|
|
|
+ // 商家信息
|
|
|
+ StringBuilder infoSqls = new StringBuilder();
|
|
|
+ for (Enterprise enterprise : enterprises) {
|
|
|
+ int info = 0;
|
|
|
+ if (StringUtils.hasText(enterprise.getEnIndustry())) {
|
|
|
+ info += 5;
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(enterprise.getDescription())) {
|
|
|
+ info += 4;
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(enterprise.getEnTel())) {
|
|
|
+ info += 4;
|
|
|
+ }
|
|
|
+ infoSqls.append("update sec$enterprises set en_score = ").append(info).append(" where en_uu = ")
|
|
|
+ .append(enterprise.getUu()).append(";");
|
|
|
+ }
|
|
|
+ commonDao.getJdbcTemplate().execute(infoSqls.toString());
|
|
|
+ logger.info("商家信息分数更新,耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 有价数量
|
|
|
+ // 有价数量排序
|
|
|
+// StringBuilder priceSql = new StringBuilder().append("select pr_enuu from products where pr_price > 0 group by pr_enuu order by count(1) desc");
|
|
|
+// List<Long> priceUUs = commonDao.query(priceSql.toString(), Long.class);
|
|
|
+ List<BigInteger> priceUUs = enterpriseDao.findEnRankByPriceProductAmount();
|
|
|
+ // 价格排行更新执行语句
|
|
|
+ StringBuilder priceUpdateSqls = new StringBuilder();
|
|
|
+ Double i = 1d;
|
|
|
+ for (BigInteger priceUU : priceUUs) {
|
|
|
+ Double score = new BigDecimal(PRICE_RESERVE_BASE / i).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ if (score > 0) {
|
|
|
+ priceUpdateSqls.append("update sec$enterprises set en_score = convert((en_score + ").append(score)
|
|
|
+ .append("),DECIMAL(20,6)) where en_uu = ").append(priceUU.longValue()).append(";");
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ commonDao.getJdbcTemplate().execute(priceUpdateSqls.toString());
|
|
|
+ logger.info("有价数量分数更新,耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 有库存数量
|
|
|
+ // 有库存数量排序
|
|
|
+// StringBuilder reserveSql = new StringBuilder().append("select pr_enuu from products where pr_reserve > 0 group by pr_enuu order by count(1) desc");
|
|
|
+// List<Long> reserveUUs = commonDao.query(reserveSql.toString(), Long.class);
|
|
|
+ List<BigInteger> reserveUUs = enterpriseDao.findEnRankByReserveProductAmount();
|
|
|
+ // 价格排行更新执行语句
|
|
|
+ StringBuilder reserveUpdateSqls = new StringBuilder();
|
|
|
+ i = 1d;
|
|
|
+ for (BigInteger reserveUU : reserveUUs) {
|
|
|
+ Double score = new BigDecimal(PRICE_RESERVE_BASE / i).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ if (score > 0) {
|
|
|
+ reserveUpdateSqls.append("update sec$enterprises set en_score = convert((en_score + ").append(score)
|
|
|
+ .append("),DECIMAL(20,6)) where en_uu = ").append(reserveUU.longValue()).append(";");
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ commonDao.getJdbcTemplate().execute(reserveUpdateSqls.toString());
|
|
|
+ logger.info("有库存数量分数更新,耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 回价数量
|
|
|
+ // 回价数量排序
|
|
|
+ List<Long> replyUUs = commonDao.queryForList("select id_venduu from public$inquiryitems group by id_venduu order by count(1) desc", Long.class);
|
|
|
+ // 价格排行更新执行语句
|
|
|
+ StringBuilder replyUpdateSqls = new StringBuilder();
|
|
|
+ i = 1d;
|
|
|
+ for (Long replyUU : replyUUs) {
|
|
|
+ Double score = new BigDecimal(INQUIRY_REPLU_BASE / i).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ if (score > 0) {
|
|
|
+ replyUpdateSqls.append("update sec$enterprises set en_score = convert((en_score + ").append(score)
|
|
|
+ .append("),DECIMAL(20,6)) where en_uu = ").append(replyUU).append(";");
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ commonDao.getJdbcTemplate().execute(replyUpdateSqls.toString());
|
|
|
+ logger.info("回价数量分数更新,耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 交易额
|
|
|
+ // 交易额排序
|
|
|
+ List<BigInteger> purchaseUUs = purchaseDao.rankByStoreTransactionVolume();
|
|
|
+ // 价格排行更新执行语句
|
|
|
+ StringBuilder purchaseUpdateSqls = new StringBuilder();
|
|
|
+ i = 1d;
|
|
|
+ for (BigInteger purchaseUU : purchaseUUs) {
|
|
|
+ Double score = new BigDecimal(PURCHASE_AMOUNT_BASE / i).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ if (score > 0) {
|
|
|
+ purchaseUpdateSqls.append("update sec$enterprises set en_score = convert((en_score + ").append(score)
|
|
|
+ .append("),DECIMAL(20,6)) where en_uu = ").append(purchaseUU.longValue()).append(";");
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ commonDao.getJdbcTemplate().execute(purchaseUpdateSqls.toString());
|
|
|
+ logger.info("交易额数量分数更新,耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ // 更新店铺中的分数(原厂、经销排行)
|
|
|
+ storeInDao.updateStoreScore();
|
|
|
+ logger.info("对应店铺分数更新,耗时:{}", (System.currentTimeMillis() - start));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取供应商资源信息
|
|
|
* @param enterpriseCondition 企业搜索条件
|
|
|
@@ -194,14 +338,14 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
String noProductenUUSql = getEnUUGroupByEnUUOrderByCount(enterpriseCondition, null);
|
|
|
// 获取企业sql
|
|
|
enterpriseSql.append("select en.en_uu enUU, en.en_name enName, en.en_shortname enShortname, st.st_logo_url storeLogoUrl, en.en_logurl enLogoUrl, en.en_address enAddress, en.en_tel enTel, " +
|
|
|
- " en.en_email enEmail, en.en_corporation enCorporation, en.en_businesscode enBusinesscode, en.en_industry enIndustry, en.en_Businessscope enBusinessScope " +
|
|
|
+ " en.en_email enEmail, en.en_corporation enCorporation, en.en_businesscode enBusinesscode, en.en_industry enIndustry, en.en_Businessscope enBusinessScope, en.en_score score " +
|
|
|
",st.st_uuid,st.st_status from sec$enterprises en left join store$info st on st.st_enuu = en.en_uu right join (")
|
|
|
.append(enUUSql).append(" union ").append(noProductenUUSql)
|
|
|
.append(" ) a on en.en_uu = a.en_uu order by en.en_weight desc");
|
|
|
// 查找非供应商的卖当前商品的企业UU
|
|
|
StringBuilder vendorIntroductionUusSql = new StringBuilder();
|
|
|
// 行数 控制
|
|
|
- String rownumSql = ") s order by isStore desc,enUU asc limit " + (page - 1) * size + "," + size ;
|
|
|
+ String rownumSql = ") s order by isStore desc,score desc limit " + (page - 1) * size + "," + size ;
|
|
|
vendorIntroductionUusSql.append("select s.*, if( st_uuid is not null and st_status = 'OPENED', 1, null) isStore from (")
|
|
|
.append(enterpriseSql).append(rownumSql);
|
|
|
return commonDao.query(vendorIntroductionUusSql.toString(), VendorIntroduction.class);
|
|
|
@@ -218,13 +362,13 @@ public class VendorIntroductionServiceImpl implements VendorIntroductionService
|
|
|
StringBuilder enterpriseSql = new StringBuilder();
|
|
|
// 获取企业sql
|
|
|
enterpriseSql.append("select en.en_uu enUU, en.en_name enName, en.en_shortname enShortname, st.st_logo_url storeLogoUrl, en.en_logurl enLogoUrl, en.en_address enAddress, en.en_tel enTel, " +
|
|
|
- "en.en_email enEmail, en.en_corporation enCorporation, en.en_businesscode enBusinesscode, en.en_industry enIndustry, en.en_Businessscope enBusinessScope " +
|
|
|
+ "en.en_email enEmail, en.en_corporation enCorporation, en.en_businesscode enBusinesscode, en.en_industry enIndustry, en.en_Businessscope enBusinessScope, en.en_score score " +
|
|
|
",st.st_enuu,st.st_status from sec$enterprises en left join store$info st on st.st_enuu = en.en_uu where en_name not like '%测试%' and en_name not like '%test%' " +
|
|
|
"and (length(en_businesscode) > 12 or en_name like '%香港%' or en_name like '%HONG KONG%' or en_area like '%香港%') and " +
|
|
|
" (en_name not REGEXP '^[0-9]*$' and (en_name like '%ltd%' or en_name like '%limited%' or en_name like '%tcl%' or en_name not regexp '[\\u4e00-\\u9fa5_a-zA-Z0-9]'))")
|
|
|
.append(" and ").append(enterpriseCondition);
|
|
|
// rownum 控制
|
|
|
- String rownumSql = ") s order by isStore desc,enUU asc limit " + (page - 1) * size + "," + size ;
|
|
|
+ String rownumSql = ") s order by isStore desc,score desc limit " + (page - 1) * size + "," + size ;
|
|
|
// 查询企业是否开店语句
|
|
|
String vendorIntroductionUusSql = "select s.*, if( st_enuu is not null and st_status = 'OPENED', 1, 0) isStore from ("
|
|
|
+ enterpriseSql + rownumSql;
|