فهرست منبع

添加电商分数排序

dongbw 7 سال پیش
والد
کامیت
28a0518256

+ 15 - 0
src/main/java/com/uas/platform/b2c/common/account/dao/EnterpriseDao.java

@@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.query.Procedure;
 import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
+import java.math.BigInteger;
 import java.util.List;
 
 @Repository
@@ -43,4 +44,18 @@ public interface EnterpriseDao extends JpaSpecificationExecutor<Enterprise>, Jpa
 	 * @return
 	 */
 	public List<Enterprise> findByEnBussinessCode(String bussinessCode);
+
+	/**
+	 * 根据有价物料数量排序
+	 * @return
+	 */
+	@Query(value = "select pr_enuu from products where pr_price > 0 group by pr_enuu order by count(1) desc", nativeQuery = true)
+    List<BigInteger> findEnRankByPriceProductAmount();
+
+	/**
+	 * 根据有库存物料排序
+	 * @return
+	 */
+	@Query(value = "select pr_enuu from products where pr_reserve > 0 group by pr_enuu order by count(1) desc", nativeQuery = true)
+	List<BigInteger> findEnRankByReserveProductAmount();
 }

+ 13 - 0
src/main/java/com/uas/platform/b2c/common/account/model/Enterprise.java

@@ -204,6 +204,12 @@ public class Enterprise implements Serializable {
 	@Column(name = "en_prodcount")
 	private Long prodCount;
 
+	/**
+	 * 企业分数(根据多个条件计算分数 排序)
+	 */
+	@Column(name = "en_score", columnDefinition = "double DEFAULT 0")
+	private Double score;
+
 	public String getDescription() {
 		return description;
 	}
@@ -526,4 +532,11 @@ public class Enterprise implements Serializable {
 		this.prodCount = prodCount;
 	}
 
+	public double getScore() {
+		return score;
+	}
+
+	public void setScore(double score) {
+		this.score = score;
+	}
 }

+ 8 - 0
src/main/java/com/uas/platform/b2c/prod/store/dao/StoreInDao.java

@@ -5,6 +5,7 @@ import com.uas.platform.b2c.prod.store.model.StoreStatus;
 import com.uas.platform.b2c.prod.store.model.StoreType;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
@@ -100,4 +101,11 @@ public interface StoreInDao extends JpaSpecificationExecutor<StoreIn>, JpaReposi
 	 * @return
 	 */
     Integer countByStatus(StoreStatus status);
+
+	/**
+	 * 根据企业分数,更新店铺中的分数(原厂、经销 排行)
+	 */
+	@Modifying
+	@Query(value = "update store$info set st_score = (select en_score from sec$enterprises where en_uu = st_enuu)", nativeQuery = true)
+	void updateStoreScore();
 }

+ 14 - 1
src/main/java/com/uas/platform/b2c/prod/store/model/StoreIn.java

@@ -3,7 +3,6 @@ package com.uas.platform.b2c.prod.store.model;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.uas.platform.b2c.common.account.model.Enterprise;
-import com.uas.platform.b2c.common.account.model.UserBaseInfo;
 import com.uas.platform.b2c.core.utils.JacksonUtils;
 import com.uas.platform.b2c.prod.commodity.model.Goods;
 import org.springframework.util.StringUtils;
@@ -162,6 +161,12 @@ public class StoreIn implements Serializable {
 	@Column(name = "st_tags")
 	private String tags = "[]";
 
+	/**
+	 * 企业分数
+	 */
+	@Column(name = "st_score" ,columnDefinition="DOUBLE DEFAULT 0")
+	private Double score;
+
 	/*+************************************************************************
 	 * 资质信息
 	 **************************************************************************/
@@ -395,4 +400,12 @@ public class StoreIn implements Serializable {
 	public void setTags(String tags) {
 		this.tags = tags;
 	}
+
+	public Double getScore() {
+		return score;
+	}
+
+	public void setScore(Double score) {
+		this.score = score;
+	}
 }

+ 4 - 1
src/main/java/com/uas/platform/b2c/prod/store/service/impl/StoreInServiceImpl.java

@@ -759,7 +759,10 @@ public class StoreInServiceImpl implements StoreInService {
 		LogicalExpression typeLogicalEx = null;
 		LogicalExpression keywordLogicalEx = null;
 		SimpleExpression nameSimpleEx = null;
-		final PageInfo pageInfo = new PageInfo(params);
+		PageInfo pageInfo = new PageInfo(params);
+
+		// 根据店铺分数排序
+		pageInfo.sorting("score", Sort.Direction.DESC);
 
 		// 搜索店铺类型
 		if (!StringUtils.isEmpty(type)) {

+ 8 - 0
src/main/java/com/uas/platform/b2c/trade/order/dao/PurchaseDao.java

@@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
+import java.math.BigInteger;
 import java.util.List;
 
 /**
@@ -213,4 +214,11 @@ public interface PurchaseDao extends JpaSpecificationExecutor<Purchase>, JpaRepo
 	 */
 	@Query(value = "select p from trade.Purchase p where p.orderid = :orid and p.status = :status")
 	List<Purchase> getPurchaseByOrIdAndStatus(@Param("orid") String orid, @Param("status") Integer status);
+
+	/**
+	 * 根据企业交易额排序 获取企业UU list
+	 * @return
+	 */
+	@Query(value = "select p.pu_sellerenuu from trade$purchase p group by p.pu_sellerenuu order by sum(coalesce(p.ensure_price, 0)) desc", nativeQuery = true)
+	List<BigInteger> rankByStoreTransactionVolume();
 }

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

@@ -128,9 +128,9 @@ public class SeekPurchaseBomServiceImpl implements SeekPurchaseBomService {
      */
     private final int SEEK_TEMPLATE_COLNUM = 5;
     /**
-     * 上限行数
+     * 上限行数 (标签占一行)
      */
-    private final int MAX_SEEK_NUM = 500;
+    private final int MAX_SEEK_NUM = 501;
 
     /**
      * excel列名

+ 12 - 0
src/main/java/com/uas/platform/b2c/trade/vendor/model/VendorIntroduction.java

@@ -95,6 +95,8 @@ public class VendorIntroduction {
      */
     private String enLogoUrl;
 
+    private Double score;
+
     public String getProductInfo() {
         return productInfo;
     }
@@ -231,6 +233,14 @@ public class VendorIntroduction {
         this.enLogoUrl = enLogoUrl;
     }
 
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
     public static VendorIntroduction convertFromStoreIn(StoreIn storeIn) {
         VendorIntroduction vendorIntroduction  = new VendorIntroduction();
         vendorIntroduction.setStoreUuid(storeIn.getUuid());
@@ -245,6 +255,7 @@ public class VendorIntroduction {
         vendorIntroduction.setEnCorporation(storeIn.getEnterpriseInfo().getEnCorporation());
         vendorIntroduction.setEnLogoUrl(storeIn.getEnterpriseInfo().getEnLogoUrl());
         vendorIntroduction.setStoreLogoUrl(storeIn.getLogoUrl());
+        vendorIntroduction.setScore(storeIn.getScore());
         return vendorIntroduction;
     }
 
@@ -260,6 +271,7 @@ public class VendorIntroduction {
         vendorIntroduction.setEnTel(enterprise.getEnTel());
         vendorIntroduction.setEnCorporation(enterprise.getEnCorporation());
         vendorIntroduction.setEnLogoUrl(enterprise.getEnLogoUrl());
+        vendorIntroduction.setScore(enterprise.getScore());
         if (null == enterprise.getIsStore()) {
             vendorIntroduction.setIsStore(new Short((short)0));
         } else {

+ 5 - 0
src/main/java/com/uas/platform/b2c/trade/vendor/service/VendorIntroductionService.java

@@ -60,4 +60,9 @@ public interface VendorIntroductionService {
      * @return 数量信息
      */
     Integer getVendorCount();
+
+    /**
+     * 计算企业分数
+     */
+    void calculateEnterpriseScore();
 }

+ 148 - 4
src/main/java/com/uas/platform/b2c/trade/vendor/service/impl/VendorIntroductionServiceImpl.java

@@ -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;

+ 52 - 0
src/main/java/com/uas/platform/b2c/trade/vendor/task/EnterpriseScoreCalculate.java

@@ -0,0 +1,52 @@
+package com.uas.platform.b2c.trade.vendor.task;
+
+import com.uas.platform.b2c.trade.vendor.service.VendorIntroductionService;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 计算企业分数(排序)
+ * 每天1:0:0执行任务[cron: '0 0 1 1/1 * ?']
+ *
+ * @author dongbw
+ * @version 2018年10月9日 14:29:30
+ */
+@Component
+@EnableAsync
+@EnableScheduling
+public class EnterpriseScoreCalculate {
+
+	private final VendorIntroductionService vendorIntroductionService;
+
+	private final Logger logger = Logger.getLogger(getClass());
+
+	@Autowired
+	public EnterpriseScoreCalculate(VendorIntroductionService vendorIntroductionService) {
+		this.vendorIntroductionService = vendorIntroductionService;
+		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		logger.info(String.format("%s 企业分数统计任务实例化", dateFormat.format(new Date())));
+	}
+
+
+	/**
+	 * 每日更新企业和店铺分数统计  0 55 14 * * ?
+	 *  凌晨一点
+	 */
+	@Async
+	@Scheduled(cron = "0 0 1 * * ?")
+	public void execute() {
+		try {
+			vendorIntroductionService.calculateEnterpriseScore();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+}