admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.yeshi.fanli.service.impl.brand;
 
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import com.yeshi.fanli.exception.pdd.PDDApiException;
import com.yeshi.fanli.util.Constant;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.brand.BrandShopCaheDao;
import com.yeshi.fanli.dto.jd.JDShopInfo;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
import com.yeshi.fanli.entity.brand.BrandInfo;
import com.yeshi.fanli.entity.brand.BrandShopCahe;
import com.yeshi.common.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.service.inter.brand.BrandShopCaheService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.goods.ShopInfoVOFactory;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.vo.goods.ShopInfoVO;
 
@Service
public class BrandShopCaheServiceImpl implements BrandShopCaheService {
    
    @Resource
    private BrandShopCaheDao brandShopCaheDao;
    
    @Resource
    private TaoBaoShopService taoBaoShopService;
    
    
    /**
     * 淘宝店铺
     * @param brandInfo
     * @return
     */
    @Override
    public boolean addBrandShopTB(BrandInfo brandInfo, String auctionId, Long sellerId) {
        TaoBaoShop taoBaoShop = taoBaoShopService.getTaoBaoShop(auctionId, sellerId);
        if (taoBaoShop == null)
            return true;
        
        ShopInfoVO shopInfoVO = ShopInfoVOFactory.convertTaoBaoShop(taoBaoShop);
        shopInfoVO.setShopIcon(brandInfo.getIcon());
        
        BrandShopCahe brandShop = new BrandShopCahe();
        brandShop.setBrandId(brandInfo.getId());
        brandShop.setShop(shopInfoVO);
        brandShop.setCreateTime(new Date());
        brandShopCaheDao.insert(brandShop);
        return false;
    }
    
    
    /**
     *  京东
     *  
     * @param brandInfo
     * @return
     */
    @Override
    public void addBrandShopJD(BrandInfo brandInfo, JDShopInfo shopInfo) {
        ShopInfoVO shopInfoVO = ShopInfoVOFactory.convertJDShop(shopInfo);
        shopInfoVO.setShopIcon(brandInfo.getIcon());
        
        BrandShopCahe brandShop = new BrandShopCahe();
        brandShop.setBrandId(brandInfo.getId());
        brandShop.setShop(shopInfoVO);
        brandShop.setCreateTime(new Date());
        brandShopCaheDao.insert(brandShop);
    }
    
    
    /**
     * 拼多多
     * @param brandInfo
     * @return
     */
    @Override
    public int addBrandShopPDD(BrandInfo brandInfo) {
        String shopKey = brandInfo.getShopKeyPDD();
        if (StringUtil.isNullOrEmpty(shopKey))
            return 0;
        
        String searchKey = brandInfo.getSearchKeyPDD();
        if (StringUtil.isNullOrEmpty(searchKey))
            searchKey = brandInfo.getName();
        
        ShopInfoVO shopInfoVO = null;
        PDDSearchFilter pddfilter = new PDDSearchFilter();
        pddfilter.setKw(searchKey);
        pddfilter.setPage(1);
        pddfilter.setPageSize(100);
        pddfilter.setSortType(6);
        pddfilter.setMerchantType(3);
 
        PDDGoodsResult result = null;
        try {
            result = PinDuoDuoApiUtil.searchGoods(pddfilter, Constant.PDD_SEARCH_CUSTOMER_PARAMS);
        } catch (PDDApiException e) {
            e.printStackTrace();
        }
        if (result != null && result.getGoodsList() != null && result.getGoodsList().size() > 0) {
            boolean addShop = true;
            List<PDDGoodsDetail> goodsList = result.getGoodsList();
            for (PDDGoodsDetail goods : goodsList) {
                // 包含店铺id 、包含品牌名称
                String mallName = goods.getMallName();
                if(addShop && !StringUtil.isNullOrEmpty(mallName) && mallName.toLowerCase().contains(shopKey.toLowerCase()) 
                        && goods.getMallId() != null){
                    shopInfoVO = new ShopInfoVO();
                    shopInfoVO.setId(goods.getMallId().toString());
                    shopInfoVO.setShopName(mallName);
                    addShop = false;
                    break;
                }
            }
        }
        
        if (shopInfoVO != null) {
            shopInfoVO.setShopIcon(brandInfo.getIcon());
            shopInfoVO.setUserType(30);
            shopInfoVO.setShopLink("https://mobile.yangkeduo.com/mall_page.html?mall_id=" + shopInfoVO.getId());
            BrandShopCahe brandShop = new BrandShopCahe();
            brandShop.setBrandId(brandInfo.getId());
            brandShop.setShop(shopInfoVO);
            brandShop.setCreateTime(new Date());
            brandShopCaheDao.insert(brandShop);
            return 1;
        }
        return 0;
    }
    
    
    
    @Override
    public List<BrandShopCahe> getByBrandId(Long brandId){
        return brandShopCaheDao.getByBrandId(brandId);
    }
    
    
    @Override
    public void removeAgoByDate(Date createTime) {
        brandShopCaheDao.removeAgoByDate(createTime);
    }
    
    @Override
    public void removeByBrandId(Long brandId) {
        brandShopCaheDao.removeByBrandId(brandId);
    }
    
    @Override
    public void removeByDateAndType(Long brandId, int type, Date date) {
        brandShopCaheDao.removeByDate(brandId, type, date);
    }
    
    
}