| | |
| | | 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;
|
| | |
|
| | |
| | |
|
| | | 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
|
| | |
| | | @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);
|
| | | }
|
| | | |
| | | }
|