fanli/src/main/java/com/yeshi/fanli/exception/goods/CommonGoodsException.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
fanli/src/main/java/com/yeshi/fanli/goods/CommonGoods.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
fanli/src/main/java/com/yeshi/fanli/mapping/goods/CommonGoodsMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonGoodsServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/CommonGoodsService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
fanli/src/main/java/com/yeshi/fanli/util/factory/CommonGoodsFactory.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
fanli/src/main/java/com/yeshi/fanli/exception/goods/CommonGoodsException.java
New file @@ -0,0 +1,32 @@ package com.yeshi.fanli.exception.goods; public class CommonGoodsException extends Exception { /** * */ private static final long serialVersionUID = 1L; private int code; private String msg; public int getCode() { return code; } public String getMsg() { return msg; } public CommonGoodsException(int code, String msg) { this.code = code; this.msg = msg; } public CommonGoodsException() { } @Override public String getMessage() { return this.msg; } } fanli/src/main/java/com/yeshi/fanli/goods/CommonGoods.java
New file @@ -0,0 +1,230 @@ package com.yeshi.fanli.goods; import java.math.BigDecimal; import java.util.Date; import org.yeshi.utils.mybatis.Column; import org.yeshi.utils.mybatis.Table; @Table("yeshi_ec_common_goods") public class CommonGoods { public static int GOODS_TYPE_TB = 1;// 淘宝天猫 public static int GOODS_TYPE_JD = 2;// 京东 public static int SHOP_TYPE_TB = 1;// 淘宝 public static int SHOP_TYPE_TM = 2;// 天猫 public static int STATE_NORMAL = 0;// 正常 public static int STATE_OFFLINE = 1;// 下线 @Column(name = "cg_id") private Long id; @Column(name = "cg_title") private String title; @Column(name = "cg_goods_id") private Long goodsId;// 第三方商品ID @Column(name = "cg_goods_type") private Integer goodsType;// 第三方类型 @Column(name = "cg_shop_type") private Integer shopType; @Column(name = "cg_seller_id") private Long sellerId; @Column(name = "cg_seller_name") private String sellerName; @Column(name = "cg_sales") private Integer sales; @Column(name = "cg_rate") private BigDecimal rate; @Column(name = "cg_picture") private String picture; @Column(name = "cg_state") private Integer state; @Column(name = "cg_price") private BigDecimal price; @Column(name = "cg_coupon_info") private String couponInfo; @Column(name = "cg_coupon_startprice") private BigDecimal couponStartPrice; @Column(name = "cg_coupon_amount") private BigDecimal couponAmount; @Column(name = "cg_coupon_left_count") private Integer couponLeftCount; @Column(name = "cg_coupon_total_count") private Integer couponTotalCount; @Column(name = "cg_video_cover") private String videoCover; @Column(name = "cg_video_url") private String videoUrl; @Column(name = "cg_createtime") private Date createTime; @Column(name = "cg_updatetime") private Date updateTime; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Long getGoodsId() { return goodsId; } public void setGoodsId(Long goodsId) { this.goodsId = goodsId; } public Integer getGoodsType() { return goodsType; } public void setGoodsType(Integer goodsType) { this.goodsType = goodsType; } public Integer getShopType() { return shopType; } public void setShopType(Integer shopType) { this.shopType = shopType; } public Long getSellerId() { return sellerId; } public void setSellerId(Long sellerId) { this.sellerId = sellerId; } public String getSellerName() { return sellerName; } public void setSellerName(String sellerName) { this.sellerName = sellerName; } public Integer getSales() { return sales; } public void setSales(Integer sales) { this.sales = sales; } public BigDecimal getRate() { return rate; } public void setRate(BigDecimal rate) { this.rate = rate; } public String getPicture() { return picture; } public void setPicture(String picture) { this.picture = picture; } public Integer getState() { return state; } public void setState(Integer state) { this.state = state; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } public String getCouponInfo() { return couponInfo; } public void setCouponInfo(String couponInfo) { this.couponInfo = couponInfo; } public BigDecimal getCouponStartPrice() { return couponStartPrice; } public void setCouponStartPrice(BigDecimal couponStartPrice) { this.couponStartPrice = couponStartPrice; } public BigDecimal getCouponAmount() { return couponAmount; } public void setCouponAmount(BigDecimal couponAmount) { this.couponAmount = couponAmount; } public Integer getCouponLeftCount() { return couponLeftCount; } public void setCouponLeftCount(Integer couponLeftCount) { this.couponLeftCount = couponLeftCount; } public Integer getCouponTotalCount() { return couponTotalCount; } public void setCouponTotalCount(Integer couponTotalCount) { this.couponTotalCount = couponTotalCount; } 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 String getVideoCover() { return videoCover; } public void setVideoCover(String videoCover) { this.videoCover = videoCover; } public String getVideoUrl() { return videoUrl; } public void setVideoUrl(String videoUrl) { this.videoUrl = videoUrl; } } fanli/src/main/java/com/yeshi/fanli/mapping/goods/CommonGoodsMapper.xml
New file @@ -0,0 +1,162 @@ <?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.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper"> <resultMap id="BaseResultMap" type="com.yeshi.fanli.goods.CommonGoods"> <id column="cg_id" property="id" jdbcType="BIGINT" /> <result column="cg_title" property="title" jdbcType="VARCHAR" /> <result column="cg_goods_id" property="goodsId" jdbcType="BIGINT" /> <result column="cg_goods_type" property="goodsType" jdbcType="INTEGER" /> <result column="cg_shop_type" property="shopType" jdbcType="INTEGER" /> <result column="cg_seller_id" property="sellerId" jdbcType="BIGINT" /> <result column="cg_seller_name" property="sellerName" jdbcType="VARCHAR" /> <result column="cg_sales" property="sales" jdbcType="INTEGER" /> <result column="cg_rate" property="rate" jdbcType="DECIMAL" /> <result column="cg_picture" property="picture" jdbcType="VARCHAR" /> <result column="cg_state" property="state" jdbcType="INTEGER" /> <result column="cg_price" property="price" jdbcType="DECIMAL" /> <result column="cg_coupon_info" property="couponInfo" jdbcType="VARCHAR" /> <result column="cg_coupon_startprice" property="couponStartPrice" jdbcType="DECIMAL" /> <result column="cg_coupon_amount" property="couponAmount" jdbcType="DECIMAL" /> <result column="cg_coupon_left_count" property="couponLeftCount" jdbcType="INTEGER" /> <result column="cg_coupon_total_count" property="couponTotalCount" jdbcType="INTEGER" /> <result column="cg_video_cover" property="videoCover" jdbcType="VARCHAR" /> <result column="cg_video_url" property="videoUrl" jdbcType="VARCHAR" /> <result column="cg_createtime" property="createTime" jdbcType="TIMESTAMP" /> <result column="cg_updatetime" property="updateTime" jdbcType="TIMESTAMP" /> </resultMap> <sql id="Base_Column_List">cg_id,cg_title,cg_goods_id,cg_goods_type,cg_shop_type,cg_seller_id,cg_seller_name,cg_sales,cg_rate,cg_picture,cg_state,cg_price,cg_coupon_info,cg_coupon_startprice,cg_coupon_amount,cg_coupon_left_count,cg_coupon_total_count,cg_video_cover,cg_video_url,cg_createtime,cg_updatetime </sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> select <include refid="Base_Column_List" /> from yeshi_ec_common_goods where cg_id = #{id,jdbcType=BIGINT} </select> <select id="selectByGoodsIdAndGoodsType" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from yeshi_ec_common_goods where cg_goods_id = #{goodsId} and cg_goods_type=#{goodsType} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_common_goods where cg_id = #{id,jdbcType=BIGINT} </delete> <insert id="insert" parameterType="com.yeshi.fanli.goods.CommonGoods" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_common_goods (cg_id,cg_title,cg_goods_id,cg_goods_type,cg_shop_type,cg_seller_id,cg_seller_name,cg_sales,cg_rate,cg_picture,cg_state,cg_price,cg_coupon_info,cg_coupon_startprice,cg_coupon_amount,cg_coupon_left_count,cg_coupon_total_count,cg_video_cover,cg_video_url,cg_createtime,cg_updatetime) values (#{id,jdbcType=BIGINT},#{title,jdbcType=VARCHAR},#{goodsId,jdbcType=BIGINT},#{goodsType,jdbcType=INTEGER},#{shopType,jdbcType=INTEGER},#{sellerId,jdbcType=BIGINT},#{sellerName,jdbcType=VARCHAR},#{sales,jdbcType=INTEGER},#{rate,jdbcType=DECIMAL},#{picture,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{price,jdbcType=DECIMAL},#{couponInfo,jdbcType=VARCHAR},#{couponStartPrice,jdbcType=DECIMAL},#{couponAmount,jdbcType=DECIMAL},#{couponLeftCount,jdbcType=INTEGER},#{couponTotalCount,jdbcType=INTEGER},#{videoCover,jdbcType=VARCHAR},#{videoUrl,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP}) </insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.goods.CommonGoods" useGeneratedKeys="true" keyProperty="id"> insert into yeshi_ec_common_goods <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">cg_id,</if> <if test="title != null">cg_title,</if> <if test="goodsId != null">cg_goods_id,</if> <if test="goodsType != null">cg_goods_type,</if> <if test="shopType != null">cg_shop_type,</if> <if test="sellerId != null">cg_seller_id,</if> <if test="sellerName != null">cg_seller_name,</if> <if test="sales != null">cg_sales,</if> <if test="rate != null">cg_rate,</if> <if test="picture != null">cg_picture,</if> <if test="state != null">cg_state,</if> <if test="price != null">cg_price,</if> <if test="couponInfo != null">cg_coupon_info,</if> <if test="couponStartPrice != null">cg_coupon_startprice,</if> <if test="couponAmount != null">cg_coupon_amount,</if> <if test="couponLeftCount != null">cg_coupon_left_count,</if> <if test="couponTotalCount != null">cg_coupon_total_count,</if> <if test="videoCover != null">cg_video_cover,</if> <if test="videoUrl != null">cg_video_url,</if> <if test="createTime != null">cg_createtime,</if> <if test="updateTime != null">cg_updatetime,</if> </trim> values <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">#{id,jdbcType=BIGINT},</if> <if test="title != null">#{title,jdbcType=VARCHAR},</if> <if test="goodsId != null">#{goodsId,jdbcType=BIGINT},</if> <if test="goodsType != null">#{goodsType,jdbcType=INTEGER},</if> <if test="shopType != null">#{shopType,jdbcType=INTEGER},</if> <if test="sellerId != null">#{sellerId,jdbcType=BIGINT},</if> <if test="sellerName != null">#{sellerName,jdbcType=VARCHAR},</if> <if test="sales != null">#{sales,jdbcType=INTEGER},</if> <if test="rate != null">#{rate,jdbcType=DECIMAL},</if> <if test="picture != null">#{picture,jdbcType=VARCHAR},</if> <if test="state != null">#{state,jdbcType=INTEGER},</if> <if test="price != null">#{price,jdbcType=DECIMAL},</if> <if test="couponInfo != null">#{couponInfo,jdbcType=VARCHAR},</if> <if test="couponStartPrice != null">#{couponStartPrice,jdbcType=DECIMAL},</if> <if test="couponAmount != null">#{couponAmount,jdbcType=DECIMAL},</if> <if test="couponLeftCount != null">#{couponLeftCount,jdbcType=INTEGER},</if> <if test="couponTotalCount != null">#{couponTotalCount,jdbcType=INTEGER},</if> <if test="videoCover != null">#{videoCover,jdbcType=VARCHAR},</if> <if test="videoUrl != null">#{videoUrl,jdbcType=VARCHAR},</if> <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if> <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if> </trim> </insert> <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.goods.CommonGoods">update yeshi_ec_common_goods set cg_title = #{title,jdbcType=VARCHAR},cg_goods_id = #{goodsId,jdbcType=BIGINT},cg_goods_type = #{goodsType,jdbcType=INTEGER},cg_shop_type = #{shopType,jdbcType=INTEGER},cg_seller_id = #{sellerId,jdbcType=BIGINT},cg_seller_name = #{sellerName,jdbcType=VARCHAR},cg_sales = #{sales,jdbcType=INTEGER},cg_rate = #{rate,jdbcType=DECIMAL},cg_picture = #{picture,jdbcType=VARCHAR},cg_state = #{state,jdbcType=INTEGER},cg_price = #{price,jdbcType=DECIMAL},cg_coupon_info = #{couponInfo,jdbcType=VARCHAR},cg_coupon_startprice = #{couponStartPrice,jdbcType=DECIMAL},cg_coupon_amount = #{couponAmount,jdbcType=DECIMAL},cg_coupon_left_count = #{couponLeftCount,jdbcType=INTEGER},cg_coupon_total_count = #{couponTotalCount,jdbcType=INTEGER},cg_video_cover = #{videoCover,jdbcType=VARCHAR},cg_video_url = #{videoUrl,jdbcType=VARCHAR},cg_createtime = #{createTime,jdbcType=TIMESTAMP},cg_updatetime = #{updateTime,jdbcType=TIMESTAMP} where cg_id = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.goods.CommonGoods"> update yeshi_ec_common_goods <set> <if test="title != null">cg_title=#{title,jdbcType=VARCHAR},</if> <if test="goodsId != null">cg_goods_id=#{goodsId,jdbcType=BIGINT},</if> <if test="goodsType != null">cg_goods_type=#{goodsType,jdbcType=INTEGER},</if> <if test="shopType != null">cg_shop_type=#{shopType,jdbcType=INTEGER},</if> <if test="sellerId != null">cg_seller_id=#{sellerId,jdbcType=BIGINT},</if> <if test="sellerName != null">cg_seller_name=#{sellerName,jdbcType=VARCHAR},</if> <if test="sales != null">cg_sales=#{sales,jdbcType=INTEGER},</if> <if test="rate != null">cg_rate=#{rate,jdbcType=DECIMAL},</if> <if test="picture != null">cg_picture=#{picture,jdbcType=VARCHAR},</if> <if test="state != null">cg_state=#{state,jdbcType=INTEGER},</if> <if test="price != null">cg_price=#{price,jdbcType=DECIMAL},</if> <if test="couponInfo != null">cg_coupon_info=#{couponInfo,jdbcType=VARCHAR},</if> <if test="couponStartPrice != null">cg_coupon_startprice=#{couponStartPrice,jdbcType=DECIMAL}, </if> <if test="couponAmount != null">cg_coupon_amount=#{couponAmount,jdbcType=DECIMAL},</if> <if test="couponLeftCount != null">cg_coupon_left_count=#{couponLeftCount,jdbcType=INTEGER}, </if> <if test="couponTotalCount != null">cg_coupon_total_count=#{couponTotalCount,jdbcType=INTEGER}, </if> <if test="videoCover != null">cg_video_cover=#{videoCover,jdbcType=VARCHAR},</if> <if test="videoUrl != null">cg_video_url=#{videoUrl,jdbcType=VARCHAR},</if> <if test="createTime != null">cg_createtime=#{createTime,jdbcType=TIMESTAMP},</if> <if test="updateTime != null">cg_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if> </set> where cg_id = #{id,jdbcType=BIGINT} </update> </mapper> fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonGoodsServiceImpl.java
New file @@ -0,0 +1,97 @@ package com.yeshi.fanli.service.impl.goods; import java.util.Date; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper; import com.yeshi.fanli.exception.goods.CommonGoodsException; import com.yeshi.fanli.goods.CommonGoods; import com.yeshi.fanli.service.inter.goods.CommonGoodsService; import com.yeshi.fanli.util.StringUtil; @Service public class CommonGoodsServiceImpl implements CommonGoodsService { @Resource private CommonGoodsMapper commonGoodsMapper; /** * 验证数据正确性 * * @param commonGoods * @throws CommonGoodsException */ private void filterCommonGoods(CommonGoods commonGoods) throws CommonGoodsException { // 判断信息是否完成 if (commonGoods == null) throw new CommonGoodsException(1, "商品信息为空"); if (commonGoods.getGoodsId() == null) throw new CommonGoodsException(1, "商品信息不完整"); if (commonGoods.getGoodsType() == null) throw new CommonGoodsException(1, "商品信息不完整"); if (StringUtil.isNullOrEmpty(commonGoods.getPicture())) throw new CommonGoodsException(1, "商品信息不完整"); if (commonGoods.getPrice() == null) throw new CommonGoodsException(1, "商品信息不完整"); if (commonGoods.getRate() == null) throw new CommonGoodsException(1, "商品信息不完整"); if (commonGoods.getSales() == null) throw new CommonGoodsException(1, "商品信息不完整"); if (commonGoods.getSellerId() == null) throw new CommonGoodsException(1, "商品信息不完整"); if (commonGoods.getSellerName() == null) throw new CommonGoodsException(1, "商品信息不完整"); if (commonGoods.getShopType() == null) throw new CommonGoodsException(1, "商品信息不完整"); if (StringUtil.isNullOrEmpty(commonGoods.getTitle())) throw new CommonGoodsException(1, "商品信息不完整"); } @Override public CommonGoods addOrUpdateCommonGoods(CommonGoods commonGoods) throws CommonGoodsException { filterCommonGoods(commonGoods); CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(commonGoods.getGoodsId(), commonGoods.getGoodsType()); if (goods != null) { updateCommonGoods(commonGoods); commonGoods.setId(goods.getId()); return commonGoods; } commonGoods.setCreateTime(new Date()); commonGoods.setUpdateTime(new Date()); commonGoodsMapper.insertSelective(commonGoods); return commonGoods; } @Override public void updateCommonGoods(CommonGoods commonGoods) throws CommonGoodsException { // 判断信息是否完整 filterCommonGoods(commonGoods); CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(commonGoods.getGoodsId(), commonGoods.getGoodsType()); if (goods == null) { throw new CommonGoodsException(3, "商品不存在"); } // 更新商品信息 commonGoods.setId(goods.getId()); commonGoods.setCreateTime(null); commonGoods.setUpdateTime(new Date()); commonGoodsMapper.updateByPrimaryKeySelective(commonGoods); } @Override public void offlineCommonGoods(Long goodsId, int goodsType) { CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(goodsId, goodsType); if (goods == null) return; CommonGoods update = new CommonGoods(); update.setId(goods.getId()); update.setUpdateTime(new Date()); update.setState(CommonGoods.STATE_OFFLINE); commonGoodsMapper.updateByPrimaryKeySelective(update); } } fanli/src/main/java/com/yeshi/fanli/service/inter/goods/CommonGoodsService.java
New file @@ -0,0 +1,39 @@ package com.yeshi.fanli.service.inter.goods; import com.yeshi.fanli.exception.goods.CommonGoodsException; import com.yeshi.fanli.goods.CommonGoods; /** * 常规商品库 * * @author Administrator * */ public interface CommonGoodsService { /** * 添加商品(无就添加,有则更新) * * @param commonGoods * @return * @throws CommonGoodsException */ public CommonGoods addOrUpdateCommonGoods(CommonGoods commonGoods) throws CommonGoodsException; /** * 更新商品信息 * * @param commonGoods * @throws CommonGoodsException */ public void updateCommonGoods(CommonGoods commonGoods) throws CommonGoodsException; /** * 商品下线 * * @param goodsId * @param goodsType */ public void offlineCommonGoods(Long goodsId, int goodsType); } fanli/src/main/java/com/yeshi/fanli/util/factory/CommonGoodsFactory.java
New file @@ -0,0 +1,44 @@ package com.yeshi.fanli.util.factory; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.goods.CommonGoods; public class CommonGoodsFactory { /** * 淘宝商品构造 * * @param goods * @return */ public static CommonGoods create(TaoBaoGoodsBrief goods) { if (goods == null) return null; CommonGoods cg = new CommonGoods(); cg.setCouponAmount(goods.getCouponAmount()); cg.setCouponInfo(goods.getCouponInfo()); cg.setCouponLeftCount(goods.getCouponLeftCount()); cg.setCouponStartPrice(goods.getCouponStartFee()); cg.setCouponTotalCount(goods.getCouponTotalCount()); cg.setGoodsId(goods.getAuctionId()); cg.setGoodsType(CommonGoods.GOODS_TYPE_TB); cg.setPicture(goods.getPictUrl()); cg.setPrice(goods.getZkPrice()); cg.setSales(goods.getBiz30day()); cg.setRate(goods.getTkRate()); cg.setSellerId(goods.getSellerId()); cg.setSellerName(goods.getShopTitle()); if (goods.getUserType() == 0) cg.setShopType(CommonGoods.SHOP_TYPE_TB); else cg.setShopType(CommonGoods.SHOP_TYPE_TM); cg.setState(CommonGoods.STATE_NORMAL); cg.setTitle(goods.getTitle()); // 保留字段 cg.setVideoCover(null); cg.setVideoUrl(null); return cg; } }