喻健
2018-12-15 b3dd60306a2a8d7481c4de103467a351ecf7a685
商品记录表定时清空
6个文件已修改
214 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/taobao/TaoBaoGoodsBriefRecordMapper.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/UpdateTaoBaoGoodsJob.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/taobao/TaoBaoGoodsBriefRecordMapper.xml 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoGoodsBriefRecordServiceImpl.java 137 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/lable/QualityFactoryServiceImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/TaoBaoGoodsBriefRecordService.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/taobao/TaoBaoGoodsBriefRecordMapper.java
@@ -8,6 +8,8 @@
public interface TaoBaoGoodsBriefRecordMapper {
    int deleteByPrimaryKey(Long id);
    // 清空所有数据
    int deleteAllData();
    int insert(TaoBaoGoodsBriefRecord record);
@@ -38,6 +40,6 @@
     * @param list
     * @return
     */
    List<TaoBaoGoodsBrief> queryGoodsByAuctionId(List<String> list);
    List<TaoBaoGoodsBrief> queryByAuctionIdList(List<Long> list);
    
}
fanli/src/main/java/com/yeshi/fanli/job/UpdateTaoBaoGoodsJob.java
@@ -16,6 +16,7 @@
import com.yeshi.fanli.service.inter.activity.ActivityService;
import com.yeshi.fanli.service.inter.config.EveryDayTaskService;
import com.yeshi.fanli.service.inter.goods.RecommendSectionGoodsService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefRecordService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.lable.LabelService;
import com.yeshi.fanli.service.inter.lable.QualityFactoryService;
@@ -58,6 +59,9 @@
    
    @Resource
    private QualityFlashSaleService qualityFlashSaleService;
    @Resource
    private TaoBaoGoodsBriefRecordService taoBaoGoodsBriefRecordService;
    
    
@@ -204,5 +208,29 @@
            }
        }
    }
    /**
     * 清理淘宝商品缓存记录表
     */
    @Scheduled(cron = "0 0 0 * * ? ")
    public void cleanTaoBaoGoodsBriefRecord() {
        if (!Constant.IS_TASK) {
            return;
        }
        try {
            taoBaoGoodsBriefRecordService.deleteAllData();
        } catch (Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/mapping/taobao/TaoBaoGoodsBriefRecordMapper.xml
@@ -112,6 +112,11 @@
 
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_taobao_goods_record where id = #{id,jdbcType=BIGINT}</delete>
  
  <delete id="deleteAllData">
      delete from yeshi_ec_taobao_goods_record
  </delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_taobao_goods (id,rootCatId,eventCreatorId,leafCatId,debugInfo,rootCatScore,sellerId,userType,shopTitle,pictUrl,title,auctionId,couponLink,couponLinkTaoToken,couponActivityId,biz30day,tkRate,nick,includeDxjh,reservePrice,tkCommFee,totalFee,totalNum,zkPrice,dayLeft,tk3rdRate,auctionUrl,rlRate,hasRecommended,hasSame,sameItemPid,couponTotalCount,couponLeftCount,couponAmount,eventRate,couponShortLink,couponInfo,couponStartFee,couponEffectiveStartTime,couponEffectiveEndTime,hasUmpBonus,isBizActivity,umpBonus,rootCategoryName,couponOriLink,userTypeName,createtime,tkMktStatus) values (#{id,jdbcType=BIGINT},#{rootCatId,jdbcType=INTEGER},#{eventCreatorId,jdbcType=INTEGER},#{leafCatId,jdbcType=INTEGER},#{debugInfo,jdbcType=VARCHAR},#{rootCatScore,jdbcType=INTEGER},#{sellerId,jdbcType=BIGINT},#{userType,jdbcType=INTEGER},#{shopTitle,jdbcType=VARCHAR},#{pictUrl,jdbcType=VARCHAR},#{title,jdbcType=VARCHAR},#{auctionId,jdbcType=BIGINT},#{couponLink,jdbcType=VARCHAR},#{couponLinkTaoToken,jdbcType=VARCHAR},#{couponActivityId,jdbcType=VARCHAR},#{biz30day,jdbcType=INTEGER},#{tkRate,jdbcType=DECIMAL},#{nick,jdbcType=VARCHAR},#{includeDxjh,jdbcType=INTEGER},#{reservePrice,jdbcType=DECIMAL},#{tkCommFee,jdbcType=DECIMAL},#{totalFee,jdbcType=DECIMAL},#{totalNum,jdbcType=INTEGER},#{zkPrice,jdbcType=DECIMAL},#{dayLeft,jdbcType=INTEGER},#{tk3rdRate,jdbcType=VARCHAR},#{auctionUrl,jdbcType=VARCHAR},#{rlRate,jdbcType=DECIMAL},#{hasRecommended,jdbcType=INTEGER},#{hasSame,jdbcType=INTEGER},#{sameItemPid,jdbcType=BIGINT},#{couponTotalCount,jdbcType=INTEGER},#{couponLeftCount,jdbcType=INTEGER},#{couponAmount,jdbcType=DECIMAL},#{eventRate,jdbcType=VARCHAR},#{couponShortLink,jdbcType=VARCHAR},#{couponInfo,jdbcType=VARCHAR},#{couponStartFee,jdbcType=DECIMAL},#{couponEffectiveStartTime,jdbcType=VARCHAR},#{couponEffectiveEndTime,jdbcType=VARCHAR},#{hasUmpBonus,jdbcType=VARCHAR},#{isBizActivity,jdbcType=VARCHAR},#{umpBonus,jdbcType=VARCHAR},#{rootCategoryName,jdbcType=VARCHAR},#{couponOriLink,jdbcType=VARCHAR},#{userTypeName,jdbcType=VARCHAR},#{createtime,jdbcType=TIMESTAMP},#{tkMktStatus,jdbcType=VARCHAR})</insert>
 
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_taobao_goods
@@ -338,15 +343,12 @@
   </select>
 
 
  <select id="queryGoodsByAuctionId" resultMap="BaseResultTaoBao">
  <select id="queryByAuctionIdList" resultMap="BaseResultTaoBao">
      <!-- 根据auctionId 查询商品信息 -->
        SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_taobao_goods_record
                WHERE auctionId in
                <foreach collection="list" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            ORDER BY id DESC
    SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_taobao_goods_record
    WHERE auctionId in
        <foreach collection="list" item="item" open="(" close=")"
            separator=",">#{item}</foreach>
   </select>
 
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/TaoBaoGoodsBriefRecordServiceImpl.java
@@ -1,8 +1,9 @@
package com.yeshi.fanli.service.impl.goods;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import javax.annotation.Resource;
@@ -10,7 +11,6 @@
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefRecordMapper;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefRecord;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefRecordService;
@Service
@@ -19,111 +19,68 @@
    @Resource
    private TaoBaoGoodsBriefRecordMapper taoBaoGoodsBriefRecordMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return taoBaoGoodsBriefRecordMapper.deleteByPrimaryKey(id);
    }
    @Override
    public int insert(TaoBaoGoodsBriefRecord record) {
        return taoBaoGoodsBriefRecordMapper.insert(record);
    public int deleteAllData() {
        return taoBaoGoodsBriefRecordMapper.deleteAllData();
    }
    @Override
    public int insertSelective(TaoBaoGoodsBriefRecord record) {
        return taoBaoGoodsBriefRecordMapper.insertSelective(record);
    }
    @Override
    public TaoBaoGoodsBriefRecord selectByPrimaryKey(Long id) {
        return taoBaoGoodsBriefRecordMapper.selectByPrimaryKey(id);
    }
    public void insertBatch(List<TaoBaoGoodsBrief> listAdd) {
    @Override
    public int updateByPrimaryKeySelective(TaoBaoGoodsBriefRecord record) {
        return taoBaoGoodsBriefRecordMapper.updateByPrimaryKeySelective(record);
    }
    @Override
    public int updateByPrimaryKey(TaoBaoGoodsBriefRecord record) {
        return taoBaoGoodsBriefRecordMapper.updateByPrimaryKey(record);
    }
    @Override
    public void insertBatch(List<TaoBaoGoodsBrief> record) {
        /* 数据为空 */
        if (record == null || record.size() == 0) {
        if (listAdd == null || listAdd.size() == 0) {
            return;
        }
        /* 根据auctionId 查询数据库是否存在数据 */
        List<String> auctionIdList = new ArrayList<String>();
        for (int i = 0; i < record.size(); i++) {
            TaoBaoGoodsBrief taoBaoGoodsBrief = record.get(i);
            Long auctionId = taoBaoGoodsBrief.getAuctionId();
            if (auctionId != null) {
                auctionIdList.add(auctionId+"");
        List<Long> auctionIdList = new ArrayList<Long>();
        for (TaoBaoGoodsBrief goodsBrief : listAdd) {
            auctionIdList.add(goodsBrief.getAuctionId());
        }
        if (auctionIdList.size() == 0) {
            return;
        }
        List<TaoBaoGoodsBrief> listHas = taoBaoGoodsBriefRecordMapper.queryByAuctionIdList(auctionIdList);
        if (listHas != null && listHas.size() > 0) {
            for (TaoBaoGoodsBrief taoBaoGoodsBrief : listHas) {
                Long auctionId = taoBaoGoodsBrief.getAuctionId();
                for (TaoBaoGoodsBrief goodsBrief : listAdd) {
                    Long auctionId2 = goodsBrief.getAuctionId();
                    if (auctionId.equals(auctionId2) || auctionId == auctionId2) {
                    }
                }
            }
        }
        /* 查询结果比对*/
        List<String> existAuctionIdList = new ArrayList<String>();
        if (auctionIdList.size() > 0) {
            List<TaoBaoGoodsBrief> existList = taoBaoGoodsBriefRecordMapper.queryGoodsByAuctionId(auctionIdList);
            if (existList != null && existList.size() > 0) {
                for (TaoBaoGoodsBrief taoBaoGoodsBrief : existList) {
                     Long auctionId = taoBaoGoodsBrief.getAuctionId();
                     if (auctionIdList.contains(auctionId+"")) {
                         existAuctionIdList.add(auctionId +"");
                     }
        Iterator<TaoBaoGoodsBrief> listIterator = listHas.iterator();
        while (listIterator.hasNext()) {
            // 已经保存在数据库中的数据
            TaoBaoGoodsBrief taoBaoGoodsBrief = listIterator.next();
            Long auctionId = taoBaoGoodsBrief.getAuctionId();
            // 删除已存在数据
            ListIterator<TaoBaoGoodsBrief> listNew = listAdd.listIterator();
            while (listNew.hasNext()) {
                TaoBaoGoodsBrief goodsBrief = listNew.next();
                Long auctionIdNew = goodsBrief.getAuctionId();
                if (auctionId.equals(auctionIdNew) || auctionId == auctionIdNew) {
                    listAdd.remove(goodsBrief);
                    break;
                }
            }
        }
        /* 每100 数据 插入数据库 */
        int j = 0;
        List<TaoBaoGoodsBrief> newList = new ArrayList<TaoBaoGoodsBrief>();
        for (int i = 0; i < record.size(); i++) {
            TaoBaoGoodsBrief taoBaoGoodsBrief = record.get(i);
            Long auctionId = taoBaoGoodsBrief.getAuctionId();
            if (existAuctionIdList.size() > 0){
                // 已经存在数据库
                if (existAuctionIdList.contains(auctionId+ "")){
                    continue;
                }
            }
            taoBaoGoodsBrief.setCreatetime(new Date());
            j++;
            newList.add(taoBaoGoodsBrief);
            if (j == 100) {
                taoBaoGoodsBriefRecordMapper.insertBatch(newList);
                j = 0;
                newList.clear();
            } else if (i == record.size() - 1) {
                taoBaoGoodsBriefRecordMapper.insertBatch(newList);
            }
        // 插入数据库
        if (listAdd.size() > 0) {
            taoBaoGoodsBriefRecordMapper.insertBatch(listAdd);
        }
    }
    @Override
    public List<TaoBaoGoodsBrief> queryByAuctionId(Long auctionId) {
        return taoBaoGoodsBriefRecordMapper.queryByAuctionId(auctionId);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/lable/QualityFactoryServiceImpl.java
@@ -253,11 +253,7 @@
            }
        }
        List<String> strList = new ArrayList<String>();
        for (Long id : auctionIdList) {
            strList.add(id + "");
        }
        List<TaoBaoGoodsBrief> existList = taoBaoGoodsBriefRecordMapper.queryGoodsByAuctionId(strList);
        List<TaoBaoGoodsBrief> existList = taoBaoGoodsBriefRecordMapper.queryByAuctionIdList(auctionIdList);
        List<QualityFactory> addList = new ArrayList<QualityFactory>();
        List<LabelGoods> addLabelList = new ArrayList<LabelGoods>();
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/TaoBaoGoodsBriefRecordService.java
@@ -4,22 +4,8 @@
import java.util.List;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefRecord;
public interface TaoBaoGoodsBriefRecordService {
    public int deleteByPrimaryKey(Long id);
    public int insert(TaoBaoGoodsBriefRecord record);
    public int insertSelective(TaoBaoGoodsBriefRecord record);
    public TaoBaoGoodsBriefRecord selectByPrimaryKey(Long id);
    public int updateByPrimaryKeySelective(TaoBaoGoodsBriefRecord record);
    public int updateByPrimaryKey(TaoBaoGoodsBriefRecord record);
    
    /**
     *  批量插入数据库
@@ -27,11 +13,10 @@
     */
    public void insertBatch(List<TaoBaoGoodsBrief> list);
    
    /**
     *  根据auctionId查询淘宝信息
     * @param record
     * 清理表数据
     * @return
     */
    public  List<TaoBaoGoodsBrief> queryByAuctionId(Long auctionId);
    public int deleteAllData();
    
}