Administrator
2018-12-03 35234960ed0b084e781946d0646f2371d8a93789
Merge remote-tracking branch 'origin/master'
2个文件已修改
3个文件已添加
238 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/goods/CollectionGoodsV2Mapper.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/exception/goods/CollectionGoodsException.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/goods/CollectionGoodsV2Mapper.xml 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CollectionGoodsV2ServiceImpl.java 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/CollectionGoodsV2Service.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/goods/CollectionGoodsV2Mapper.java
@@ -1,5 +1,9 @@
package com.yeshi.fanli.dao.mybatis.goods;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.goods.CollectionGoodsV2;
public interface CollectionGoodsV2Mapper {
@@ -15,4 +19,33 @@
    int updateByPrimaryKeySelective(CollectionGoodsV2 record);
    int updateByPrimaryKey(CollectionGoodsV2 record);
    /**
     * 根据用户ID和商品ID获取收藏记录
     *
     * @param uid
     * @param commonGoodsId
     * @return
     */
    CollectionGoodsV2 selectByUidAndCommonGoodsId(@Param("uid") Long uid, @Param("commonGoodsId") Long commonGoodsId);
    /**
     * 根据用户ID获取收藏记录,按照收藏时间倒叙
     *
     * @param uid
     * @param start
     * @param count
     * @return
     */
    List<CollectionGoodsV2> selectByUidOrderByCreateTimeDesc(@Param("uid") Long uid, @Param("start") long start,
            @Param("count") int count);
    /**
     * 获取收藏的数量
     *
     * @param uid
     * @return
     */
    List<CollectionGoodsV2> selectCountByUid(@Param("uid") Long uid);
}
fanli/src/main/java/com/yeshi/fanli/exception/goods/CollectionGoodsException.java
New file
@@ -0,0 +1,32 @@
package com.yeshi.fanli.exception.goods;
public class CollectionGoodsException 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 CollectionGoodsException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public CollectionGoodsException() {
    }
    @Override
    public String getMessage() {
        return this.msg;
    }
}
fanli/src/main/java/com/yeshi/fanli/mapping/goods/CollectionGoodsV2Mapper.xml
@@ -25,6 +25,36 @@
        <include refid="Base_Column_List" />
        from yeshi_ec_collection_goods_v2 where cg_id = #{id,jdbcType=BIGINT}
    </select>
    <!-- 根据用户ID和商品ID获取收藏记录 -->
    <select id="selectByUidAndCommonGoodsId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_collection_goods_v2 where cg_uid = #{uid} and
        cg_common_goods_id=#{commonGoodsId} limit 1
    </select>
    <!-- 根据用户ID获取收藏记录,按照收藏时间倒叙 -->
    <select id="selectByUidOrderByCreateTimeDesc" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_collection_goods_v2 where cg_uid = #{uid} order by
        cg_createtime desc limit #{start},#{count}
    </select>
    <!-- 获取收藏的数量 -->
    <select id="selectCountByUid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        count(cg_id)
        from yeshi_ec_collection_goods_v2
        where cg_uid = #{uid}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_collection_goods_v2 where cg_id = #{id,jdbcType=BIGINT}
    </delete>
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CollectionGoodsV2ServiceImpl.java
New file
@@ -0,0 +1,93 @@
package com.yeshi.fanli.service.impl.goods;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.goods.CollectionGoodsV2Mapper;
import com.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.goods.CollectionGoodsException;
import com.yeshi.fanli.exception.goods.CommonGoodsException;
import com.yeshi.fanli.goods.CollectionGoodsV2;
import com.yeshi.fanli.goods.CommonGoods;
import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.util.factory.CommonGoodsFactory;
@Service
public class CollectionGoodsV2ServiceImpl implements CollectionGoodsV2Service {
    @Resource
    private CollectionGoodsV2Mapper collectionGoodsV2Mapper;
    @Resource
    private CommonGoodsMapper commonGoodsMapper;
    @Resource
    private CommonGoodsService commonGoodsService;
    @Transactional
    @Override
    public void addCollection(Long uid, TaoBaoGoodsBrief goods) throws CollectionGoodsException {
        if (uid == null || uid == 0)
            throw new CollectionGoodsException(1, "无用户ID");
        CommonGoods commonGoods = CommonGoodsFactory.create(goods);
        if (commonGoods == null)
            throw new CollectionGoodsException(2, "商品信息获取失败");
        // 判断商品是否存在
        try {
            commonGoods = commonGoodsService.addOrUpdateCommonGoods(commonGoods);
        } catch (CommonGoodsException e) {
            commonGoods = null;
        }
        if (commonGoods == null || commonGoods.getId() == null)
            throw new CollectionGoodsException(3, "商品信息添加失败");
        CollectionGoodsV2 collectionGoodsV2 = collectionGoodsV2Mapper.selectByUidAndCommonGoodsId(uid,
                commonGoods.getId());
        if (collectionGoodsV2 != null)
            throw new CollectionGoodsException(4, "商品已被收藏");
        collectionGoodsV2 = new CollectionGoodsV2();
        collectionGoodsV2.setCommonGoods(commonGoods);
        collectionGoodsV2.setCreateTime(new Date());
        collectionGoodsV2.setUpdateTime(new Date());
        collectionGoodsV2.setUserInfo(new UserInfo(uid));
        collectionGoodsV2Mapper.insertSelective(collectionGoodsV2);
    }
    @Transactional
    @Override
    public void cancelCollection(Long uid, Long id) throws CollectionGoodsException {
        if (uid == null || uid == 0)
            throw new CollectionGoodsException(1, "无用户ID");
        if (id == null || id == 0)
            throw new CollectionGoodsException(1, "无收藏");
        CollectionGoodsV2 collectionGoodsV2 = collectionGoodsV2Mapper.selectByPrimaryKey(id);
        if (collectionGoodsV2 == null)
            return;
        if (collectionGoodsV2.getUserInfo().getId() != uid.longValue())
            throw new CollectionGoodsException(2, "无权限");
        collectionGoodsV2Mapper.deleteByPrimaryKey(id);
    }
    @Override
    public List<CollectionGoodsV2> getCollectionGoodsList(Long uid, int page, int pageSize) {
        return null;
    }
    @Override
    public long getCollectionGoodsCount(Long uid) {
        return 0;
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/CollectionGoodsV2Service.java
New file
@@ -0,0 +1,50 @@
package com.yeshi.fanli.service.inter.goods;
import java.util.List;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.goods.CollectionGoodsException;
import com.yeshi.fanli.goods.CollectionGoodsV2;
public interface CollectionGoodsV2Service {
    /**
     *
     * @param uid
     *            用户ID
     * @param goods
     *            商品信息
     * @throws CollectionGoodsException
     */
    public void addCollection(Long uid, TaoBaoGoodsBrief goods) throws CollectionGoodsException;
    /**
     * 取消收藏
     *
     * @param uid
     *            -用户ID
     * @param id
     *            -收藏ID
     * @throws CollectionGoodsException
     */
    public void cancelCollection(Long uid, Long id) throws CollectionGoodsException;
    /**
     * 获取收藏记录
     *
     * @param uid
     * @param page
     * @param pageSize
     * @return
     */
    public List<CollectionGoodsV2> getCollectionGoodsList(Long uid, int page, int pageSize);
    /**
     * 获取收藏数量
     *
     * @param uid
     * @return
     */
    public long getCollectionGoodsCount(Long uid);
}