Browse Source

perf(购物车): 优化获取购物车时间的问题。

yuj 7 years ago
parent
commit
8d9d9fec57

+ 6 - 10
src/main/java/com/uas/platform/b2c/prod/commodity/model/GoodsHistory.java

@@ -3,15 +3,7 @@ package com.uas.platform.b2c.prod.commodity.model;
 import com.uas.platform.b2c.common.account.model.UserBaseInfo;
 import com.uas.platform.b2c.core.utils.FastjsonUtils;
 
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.persistence.Transient;
+import javax.persistence.*;
 import java.util.Date;
 import java.util.List;
 
@@ -22,7 +14,11 @@ import java.util.List;
  *
  */
 @Entity
-@Table(name = "trade$goods_history")
+@Table(name = "trade$goods_history", indexes = {
+		@Index(name = "goods_history_go_batchcode", columnList = "go_batchcode"),
+		@Index(name = "goods_history_log_operateuu", columnList = "log_operateuu")
+		}
+)
 public class GoodsHistory {
 
 	@Id

+ 348 - 0
src/main/java/com/uas/platform/b2c/prod/store/model/StoreInSimple.java

@@ -0,0 +1,348 @@
+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.prod.commodity.model.Goods;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 店铺信息类
+ *
+ * @author huxz
+ * @version 2017-08-02 14:39:53 创建文件
+ */
+@Entity
+@Table(name = "store$info")
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
+public class StoreInSimple implements Serializable {
+
+	private static final long serialVersionUID = -2806666044917530730L;
+
+	@Id
+	@GeneratedValue
+	@Column(name = "id")
+	private Long id;
+
+	/*+************************************************************************
+	 * 店铺信息
+	 **************************************************************************/
+
+	/**
+	 * 店铺UUID
+	 */
+	@Column(name = "st_uuid", unique = true)
+	private String uuid;
+
+	/**
+	 * 店铺名称,实际为企业名称
+	 */
+	@Column(name = "st_name", unique = true)
+	private String storeName;
+
+	/**
+	 * 店铺简称,实际为店铺名称
+	 */
+	@Column(name = "st_short_name")
+	private String storeShortName;
+
+	/**
+	 * 应用领域
+	 */
+	@Column(name="st_application",length = 100)
+	private String storeApplication;
+
+	/**
+	 *	店铺LOGO URL
+	 */
+	@Column(name = "st_logo_url")
+	private String logoUrl;
+
+	/**
+	 * 店铺横幅URL
+	 */
+	@Column(name = "st_banner_url")
+	private String bannerUrl;
+
+	/**
+	 * 主营产品
+	 */
+	@Column(name = "st_description", length = 1000)
+	private String description;
+
+	/**
+	 * 店铺模板UUID
+	 */
+	@Column(name = "st_template_uuid")
+	private String templateUuid;
+
+	/**
+	 * 店铺类型
+	 */
+	@Column(name = "st_type")
+	@Enumerated(value = EnumType.STRING)
+	private StoreType type;
+
+	/**
+	 * 创建时间
+	 */
+	@Column(name = "st_create_time")
+	private Date createTime;
+
+	/**
+	 * 更新时间
+	 */
+	@Column(name = "st_update_time")
+	private Date updateTime;
+
+	/**
+	 * 上架商品总库存
+	 */
+	@Column(name = "st_total_reserve")
+	private long totalReserve;
+
+	/**
+	 * 店铺状态
+	 */
+	@Enumerated(value = EnumType.STRING)
+	@Column(name = "st_status")
+	private StoreStatus status = StoreStatus.OPENED;
+
+	/*+************************************************************************
+	 * 企业信息
+	 **************************************************************************/
+
+	/**
+	 * 店铺企业UU
+	 */
+	@Column(name = "st_enuu")
+	private Long enUU;
+
+	@OneToOne(cascade = { CascadeType.REFRESH })
+	@JoinColumn(name = "st_enuu", insertable = false, updatable = false)
+	private Enterprise enterpriseInfo;
+
+	/**
+	 * 企业信息JSON
+	 */
+	@JsonIgnore
+	@Column(name = "st_en_json", length = 2000 ,columnDefinition="TEXT")
+	private String enterpriseJson;
+
+	/**
+	 * 企业资质类型
+	 */
+	@Column(name = "st_en_type")
+	private String enType;
+
+	/**
+	 * 企业资质信息
+	 */
+	@Column(name = "st_en_qualification" ,columnDefinition="TEXT")
+	private String enQualification;
+
+	/**
+	 * 店铺标签
+	 */
+	@Column(name = "st_tags")
+	private String tags = "[]";
+
+	/**
+	 * 企业分数
+	 */
+	@Column(name = "st_score")
+	private Double score = 0d;
+
+	/*+************************************************************************
+	 * 资质信息
+	 **************************************************************************/
+
+	/**
+	 * 最低价三个批次
+	 */
+	@Transient
+	private List<Goods> goodses;
+
+	public Enterprise getEnterpriseInfo() {
+		return enterpriseInfo;
+	}
+
+	public void setEnterpriseInfo(Enterprise enterpriseInfo) {
+		this.enterpriseInfo = enterpriseInfo;
+	}
+
+	public StoreInSimple() {
+	}
+
+	public String getStoreApplication() {
+		return storeApplication;
+	}
+
+	public void setStoreApplication(String storeApplication) {
+		this.storeApplication = storeApplication;
+	}
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getUuid() {
+		return uuid;
+	}
+
+	public void setUuid(String uuid) {
+		this.uuid = uuid;
+	}
+
+	public String getStoreName() {
+		return storeName;
+	}
+
+	public void setStoreName(String storeName) {
+		this.storeName = storeName;
+	}
+
+	public String getStoreShortName() {
+		return storeShortName;
+	}
+
+	public void setStoreShortName(String storeShortName) {
+		this.storeShortName = storeShortName;
+	}
+
+	public String getLogoUrl() {
+		return logoUrl;
+	}
+
+	public void setLogoUrl(String logoUrl) {
+		this.logoUrl = logoUrl;
+	}
+
+	public String getBannerUrl() {
+		return bannerUrl;
+	}
+
+	public void setBannerUrl(String bannerUrl) {
+		this.bannerUrl = bannerUrl;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public String getTemplateUuid() {
+		return templateUuid;
+	}
+
+	public void setTemplateUuid(String templateUuid) {
+		this.templateUuid = templateUuid;
+	}
+
+	public Date getCreateTime() {
+		return createTime;
+	}
+
+	public void setCreateTime(Date createTime) {
+		this.createTime = createTime;
+	}
+
+	public Date getUpdateTime() {
+		return updateTime;
+	}
+
+	public void setUpdateTime(Date updateTime) {
+		this.updateTime = updateTime;
+	}
+
+	public long getTotalReserve() {
+		return totalReserve;
+	}
+
+	public void setTotalReserve(long totalReserve) {
+		this.totalReserve = totalReserve;
+	}
+
+	public StoreStatus getStatus() {
+		return status;
+	}
+
+	public void setStatus(StoreStatus status) {
+		this.status = status;
+	}
+
+	public Long getEnUU() {
+		return enUU;
+	}
+
+	public void setEnUU(Long enUU) {
+		this.enUU = enUU;
+	}
+
+	public String getEnterpriseJson() {
+		return enterpriseJson;
+	}
+
+	public void setEnterpriseJson(String enterpriseJson) {
+		this.enterpriseJson = enterpriseJson;
+	}
+
+	public String getEnType() {
+		return enType;
+	}
+
+	public void setEnType(String enType) {
+		this.enType = enType;
+	}
+
+	public String getEnQualification() {
+		return enQualification;
+	}
+
+	public void setEnQualification(String enQualification) {
+		this.enQualification = enQualification;
+	}
+
+	public List<Goods> getGoodses() {
+		return goodses;
+	}
+
+	public void setGoodses(List<Goods> goodses) {
+		this.goodses = goodses;
+	}
+
+	public StoreType getType() {
+		return type;
+	}
+
+	public void setType(StoreType type) {
+		this.type = type;
+	}
+
+	public String getTags() {
+		return tags;
+	}
+
+	public void setTags(String tags) {
+		this.tags = tags;
+	}
+
+	public Double getScore() {
+		return score;
+	}
+
+	public void setScore(Double score) {
+		this.score = score;
+	}
+}

+ 4 - 4
src/main/java/com/uas/platform/b2c/trade/presale/model/Cart.java

@@ -3,7 +3,7 @@ package com.uas.platform.b2c.trade.presale.model;
 import com.uas.platform.b2c.core.utils.NumberUtil;
 import com.uas.platform.b2c.prod.commodity.model.Goods;
 import com.uas.platform.b2c.prod.commodity.model.GoodsSimple;
-import com.uas.platform.b2c.prod.store.model.StoreIn;
+import com.uas.platform.b2c.prod.store.model.StoreInSimple;
 import com.uas.platform.b2c.prod.store.model.StoreType;
 import com.uas.platform.b2c.trade.presale.status.cartStatus;
 import com.uas.platform.core.model.Status;
@@ -166,7 +166,7 @@ public class Cart {
 	 */
 	@OneToOne(cascade = { CascadeType.REFRESH }, fetch = FetchType.EAGER)
 	@JoinColumn(name = "cart_store_uuid", referencedColumnName = "st_uuid" ,insertable = false, updatable = false)
-	private StoreIn storeEnterprise;
+	private StoreInSimple storeEnterprise;
 
 	/**
 	 * 店铺名称
@@ -569,11 +569,11 @@ public class Cart {
 		return this;
 	}
 
-	public StoreIn getStoreEnterprise() {
+	public StoreInSimple getStoreEnterprise() {
 		return storeEnterprise;
 	}
 
-	public void setStoreEnterprise(StoreIn storeEnterprise) {
+	public void setStoreEnterprise(StoreInSimple storeEnterprise) {
 		this.storeEnterprise = storeEnterprise;
 	}
 

+ 0 - 15
src/main/java/com/uas/platform/b2c/trade/presale/service/impl/CartServiceImpl.java

@@ -421,8 +421,6 @@ public class CartServiceImpl implements CartService {
 //		info.sorting("storeUuid", Sort.Direction.DESC);
 //		info.sorting("id", Sort.Direction.DESC);
 		info.sorting(Sort.Direction.DESC, "storeUuid", "id");
-		// 获取当前页的购物车记录信息
-		long l = System.currentTimeMillis();
 		Page<Cart> carts = cartDao.findAll(new Specification<Cart>() {
 			@Override
 			public Predicate toPredicate(Root<Cart> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
@@ -430,10 +428,6 @@ public class CartServiceImpl implements CartService {
 				return null;
 			}
 		}, info);
-		long l1 = System.currentTimeMillis();
-		System.out.println((l1 - l) + "获取时间购物车时间");
-		// 将购物车记录按店铺进行分类
-
 		if (!CollectionUtils.isEmpty(carts.getContent())) {
 			cartFillGoodsHistory(carts.getContent());
 			setCartSimilarCount(carts.getContent());
@@ -455,15 +449,9 @@ public class CartServiceImpl implements CartService {
 			batchCodes.add(cart.getBatchCode());
 		}
 		//从历史库存中获取上架信息
-		long l2 = System.currentTimeMillis();
 		List<Long> historyIds = goodsHistoryDao.findMaxIdByBatchCodes(batchCodes);
-		long l3 = System.currentTimeMillis();
-		System.out.println((l3 - l2) + "获取id最大值");
 		if (org.apache.commons.collections.CollectionUtils.isNotEmpty(historyIds)) {
-			long l = System.currentTimeMillis();
 			List<GoodsHistory> histories = goodsHistoryDao.findAll(historyIds);
-			long l1 = System.currentTimeMillis();
-			System.out.println((l1 - l) + "获取历史库存时间");
 			for (GoodsHistory history : histories) {
 				for (Cart cart : carts) {
 					if (cart.getBatchCode().equals(history.getBatchCode())) {
@@ -493,10 +481,7 @@ public class CartServiceImpl implements CartService {
 		String sql = "select cmp_code, go_batchcode from trade$goods where cmp_code in (:codes) and go_status = " + com.uas.platform.b2c.core.constant.Status.AVAILABLE.value();
 		Map<String, Object> codeMaps = new HashMap<>();
 		codeMaps.put("codes", codes);
-		long l = System.currentTimeMillis();
 		List<Map<String, Object>> maps = namedParameterJdbcTemplate.queryForList(sql, codeMaps);
-		long l1 = System.currentTimeMillis();
-		System.out.println((l1 - l) + "获取相似产品时间");
 		for (Map<String, Object> numMap : maps) {
 			Object code = numMap.get("cmp_code");
 			for (Cart cart : carts) {