Authored by mali

价格走势

package com.yohoufo.dal.product;
import com.yohoufo.dal.product.model.PriceTrendDay;
public interface PriceTrendDayMapper {
int deleteByPrimaryKey(Integer id);
int insert(PriceTrendDay record);
int insertSelective(PriceTrendDay record);
PriceTrendDay selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(PriceTrendDay record);
int updateByPrimaryKey(PriceTrendDay record);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.product.model;
import java.math.BigDecimal;
public class PriceTrendDay {
private Integer id;
private Integer productId;
private Integer sizeId;
private BigDecimal sknPrice;
private BigDecimal skuPrice;
private Integer createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getSizeId() {
return sizeId;
}
public void setSizeId(Integer sizeId) {
this.sizeId = sizeId;
}
public BigDecimal getSknPrice() {
return sknPrice;
}
public void setSknPrice(BigDecimal sknPrice) {
this.sknPrice = sknPrice;
}
public BigDecimal getSkuPrice() {
return skuPrice;
}
public void setSkuPrice(BigDecimal skuPrice) {
this.skuPrice = skuPrice;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yohoufo.dal.product.PriceTrendDayMapper" >
<resultMap id="BaseResultMap" type="com.yohoufo.dal.product.model.PriceTrendDay" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="product_id" property="productId" jdbcType="INTEGER" />
<result column="size_id" property="sizeId" jdbcType="INTEGER" />
<result column="skn_price" property="sknPrice" jdbcType="DECIMAL" />
<result column="sku_price" property="skuPrice" jdbcType="DECIMAL" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, product_id, size_id, skn_price, sku_price, create_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from price_trend_day
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from price_trend_day
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yohoufo.dal.product.model.PriceTrendDay" >
insert into price_trend_day (id, product_id, size_id,
skn_price, sku_price, create_time
)
values (#{id,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{sizeId,jdbcType=INTEGER},
#{sknPrice,jdbcType=DECIMAL}, #{skuPrice,jdbcType=DECIMAL}, #{createTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.product.model.PriceTrendDay" >
insert into price_trend_day
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="productId != null" >
product_id,
</if>
<if test="sizeId != null" >
size_id,
</if>
<if test="sknPrice != null" >
skn_price,
</if>
<if test="skuPrice != null" >
sku_price,
</if>
<if test="createTime != null" >
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="productId != null" >
#{productId,jdbcType=INTEGER},
</if>
<if test="sizeId != null" >
#{sizeId,jdbcType=INTEGER},
</if>
<if test="sknPrice != null" >
#{sknPrice,jdbcType=DECIMAL},
</if>
<if test="skuPrice != null" >
#{skuPrice,jdbcType=DECIMAL},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.product.model.PriceTrendDay" >
update price_trend_day
<set >
<if test="productId != null" >
product_id = #{productId,jdbcType=INTEGER},
</if>
<if test="sizeId != null" >
size_id = #{sizeId,jdbcType=INTEGER},
</if>
<if test="sknPrice != null" >
skn_price = #{sknPrice,jdbcType=DECIMAL},
</if>
<if test="skuPrice != null" >
sku_price = #{skuPrice,jdbcType=DECIMAL},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.product.model.PriceTrendDay" >
update price_trend_day
set product_id = #{productId,jdbcType=INTEGER},
size_id = #{sizeId,jdbcType=INTEGER},
skn_price = #{sknPrice,jdbcType=DECIMAL},
sku_price = #{skuPrice,jdbcType=DECIMAL},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -488,18 +488,5 @@ public class ProductController {
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("sku-p detail").build();
}
@ApiOperation(name = "ufo.product.sizes", desc="商品的尺码列表")
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.sizes")
@Cachable(expire = 180)
public ApiResponse queryProductSizeById(@RequestParam(value = "product_id") Integer productId) {
if (null == productId) {
LOG.info("in method=ufo.product.sizes product_id Is Null");
return new ApiResponse(400, "product_id Is Null", null);
}
LOG.info("in method=ufo.product.sizes product_id={}", productId);
ProductDetailResp resp = productService.queryProductSizeById(productId);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product size data").build();
}
}
\ No newline at end of file
... ...
... ... @@ -6,6 +6,7 @@ import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.product.model.PriceTrendResp;
import com.yohoufo.product.service.impl.ProductPriceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -14,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created by li.ma on 2019/1/8.
*/
... ... @@ -24,19 +27,31 @@ public class ProductPriceController {
@Autowired
private ProductPriceService productPriceService;
@ApiOperation(name = "ufo.product.data", desc="商品详情")
@ApiOperation(name = "ufo.product.priceTrend", desc="商品价格走势详情")
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.priceTrend")
@Cachable(expire = 180)
public ApiResponse queryProductPriceTrend(@RequestParam(value = "product_id") Integer productId,
@RequestParam(value = "size_id", required = false) Integer sizeId) {
@RequestParam(value = "size_id", required = false) Integer sizeId,
@RequestParam(value = "trend_type")Integer trendType) {
LOG.info("in method=ufo.product.data product_id={}, size_id is {}, trend_type is {}", productId, sizeId, trendType);
List<PriceTrendResp> resp = productPriceService.queryProductPriceTrend(productId, sizeId, trendType);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product data").build();
}
@ApiOperation(name = "ufo.product.sizes", desc="商品的尺码列表")
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.sizes")
@Cachable(expire = 180)
public ApiResponse queryProductSizeById(@RequestParam(value = "product_id") Integer productId) {
if (null == productId) {
LOG.info("in method=ufo.product.data product_id Is Null");
LOG.info("in method=ufo.product.sizes product_id Is Null");
return new ApiResponse(400, "product_id Is Null", null);
}
LOG.info("in method=ufo.product.data product_id={}", productId);
ProductDetailResp resp = productPriceService.queryProductPriceTrend(productId);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product data").build();
LOG.info("in method=ufo.product.sizes product_id={}", productId);
ProductDetailResp resp = productPriceService.queryProductSizeById(productId);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product size data").build();
}
}
... ...
package com.yohoufo.product.helper;
/**
* Created by li.ma on 2019/1/8.
*/
public enum TrendTypeEnum {
/**
* 当前的价格走势
*/
PRICE_TREND_DAY(1, "PriceTrendDayService"),
/**
* 180的价格走势
*/
PRICE_TREND_HALFYEAR(2, "PriceTrendHalfYearService"),
/**
* 30的价格走势
*/
PRICE_TREND_MONTH(3, "PriceTrendMonthService"),
/**
* 当前的价格走势
*/
PRICE_TREND_SIXTYDAY(4, "PriceTrendSixtyDayService");
private Integer code;
private String beanName;
/**
*
* @param code db中code
* @param beanName db中code的含义
*/
TrendTypeEnum(int code, String beanName) {
this.code = code;
this.beanName = beanName;
}
public Integer getCode() {
return code;
}
public String getBeanName() {
return beanName;
}
public static String getBeanNameByCode(Integer code) {
for (TrendTypeEnum item : values()) {
if (item.getCode().equals(code)) {
return item.getBeanName();
}
}
return null;
}
}
... ...
package com.yohoufo.product.model;
/**
* Created by li.ma on 2019/1/8.
*/
public class PriceTrendResp {
}
... ...
... ... @@ -83,11 +83,4 @@ public interface ProductService {
* @return
*/
SkupDetailForScreenResp getSkuPDetailForShopsScreen(Integer skuP, Integer storeId);
/**
* 根据
* @param productId
* @return
*/
ProductDetailResp queryProductSizeById(Integer productId);
}
... ...
package com.yohoufo.product.service.impl;
import com.yohobuy.ufo.model.response.ProductDetailResp;
import com.yohoufo.product.helper.TrendTypeEnum;
import com.yohoufo.product.model.PriceTrendResp;
import com.yohoufo.product.service.impl.pricetrend.PriceTrendServiceInf;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* Created by li.ma on 2019/1/8.
*/
@Service
public class ProductPriceService {
public class ProductPriceService implements ApplicationContextAware{
private ApplicationContext applicationContext;
public List<PriceTrendResp> queryProductPriceTrend(Integer productId, Integer sizeId, Integer trendType) {
Map<String, PriceTrendServiceInf> beansOfType = applicationContext.getBeansOfType(PriceTrendServiceInf.class);
String beanNameByCode = TrendTypeEnum.getBeanNameByCode(trendType);
if (Optional.of(beanNameByCode))
beansOfType.getOrDefault()
return beansOfType.queryProductPriceTrend(productId, sizeId);
}
public ProductDetailResp queryProductSizeById(Integer productId) {
return null;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
... ...
package com.yohoufo.product.service.impl.pricetrend;
import org.springframework.stereotype.Service;
/**
* Created by li.ma on 2019/1/8.
*/
@Service(value = "PriceTrendDayService")
public class PriceTrendDayService implements PriceTrendServiceInf{
}
... ...
package com.yohoufo.product.service.impl.pricetrend;
import org.springframework.stereotype.Service;
/**
* Created by li.ma on 2019/1/8.
*/
@Service(value = "PriceTrendHalfYearService")
public class PriceTrendHalfYearService implements PriceTrendServiceInf{
}
... ...
package com.yohoufo.product.service.impl.pricetrend;
import org.springframework.stereotype.Service;
/**
* Created by li.ma on 2019/1/8.
*/
@Service(value = "PriceTrendMonthService")
public class PriceTrendMonthService implements PriceTrendServiceInf{
}
... ...
package com.yohoufo.product.service.impl.pricetrend;
/**
* Created by li.ma on 2019/1/8.
*/
public interface PriceTrendServiceInf {
}
... ...
package com.yohoufo.product.service.impl.pricetrend;
import org.springframework.stereotype.Service;
/**
* Created by li.ma on 2019/1/8.
*/
@Service
public class PriceTrendSixtyDayService implements PriceTrendServiceInf{
}
... ...