admin
2019-08-12 f2a36b0b93939c9d7a14585e0afae80ec70402a0
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
package com.yeshi.fanli.service.impl.lable;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.taobao.TbImgUtil;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.dao.mybatis.TaoBaoClassRelationMapper;
import com.yeshi.fanli.dao.mybatis.lable.LabelGoodsMapper;
import com.yeshi.fanli.dao.mybatis.lable.QualityFactoryMapper;
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper;
import com.yeshi.fanli.entity.bus.lable.Label;
import com.yeshi.fanli.entity.bus.lable.LabelGoods;
import com.yeshi.fanli.entity.bus.lable.QualityFactory;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.lable.LabelService;
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
 
import net.sf.json.JSONArray;
 
@Service
public class QualityGoodsServiceImpl implements QualityGoodsService {
 
    @Resource
    private RedisManager redisManager;
    @Resource
    private QualityFactoryMapper qualityFactoryMapper;
    @Resource
    private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
    @Resource
    private LabelGoodsMapper labelGoodsMapper;
    @Resource
    private LabelService labelService;
    @Resource
    private TaoBaoGoodsBriefMapper taoBaoGoodsBriefMapper;
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
 
    @Resource
    private TaoBaoClassRelationMapper taoBaoClassRelationMapper;
 
    @Resource
    private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
    
    @Resource
    private HongBaoManageService hongBaoManageService;
    
    @Resource
    private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
    
 
    @Override
    @Cacheable(value = "qualityCache", key = "'listQueryByCouponAmount-'+#start+'-'+#key+'-'+#endAmount+'-'+#startPropor")
    public List<QualityFactory> listQueryByCouponAmount(long start, int count, Integer key, Integer endAmount,
            Integer startPropor) {
        return qualityFactoryMapper.listQueryByCouponAmount(start, count, key, endAmount, startPropor);
    }
 
    @Override
    @Cacheable(value = "qualityCache", key = "'countQueryByCouponAmount-'+#key+'-'+#endAmount+'-'+#startPropor")
    public long countQueryByCouponAmount(Integer key, Integer endAmount, Integer startPropor) {
        return qualityFactoryMapper.countQueryByCouponAmount(key, endAmount, startPropor);
    }
 
    @Override
    @Cacheable(value = "qualityCache", key = "'listQueryByFlashSale-'+#start")
    public List<QualityFactory> listQueryByFlashSale(long start, int count) {
        return qualityFactoryMapper.listQueryByFlashSale(start, count);
    }
 
    @Override
    // @Cacheable(value = "qualityCache",key="'countQueryByFlashSale-'")
    public long countQueryByFlashSale() {
        return qualityFactoryMapper.countQueryByFlashSale();
    }
 
    @Override
    public List<QualityFactory> listFlashSaleRandGoods() {
        return qualityFactoryMapper.listFlashSaleRandGoods();
    }
 
    /**
     * 小金额查询:9.9/19.9/29.9/49.9
     * 
     * @param start
     * @param count
     * @param key
     * @param classId
     *            分类id
     * @param labId
     *            标签id
     * @return
     */
    @Override
    @Cacheable(value = "quality9K9Cache", key = "'get9k9ClassGoods-'+#start+'-'+#biz30day+'-'+#zkPrice+'-'+#minQuanPrice+'-'+#maxQuanPrice+'-'+#cids")
    public List<QualityFactory> get9k9ClassGoods(long start, int count, Integer biz30day, BigDecimal zkPrice,
            BigDecimal minQuanPrice, BigDecimal maxQuanPrice, String cids) {
        return qualityFactoryMapper.get9k9ClassGoods(start, count, biz30day, zkPrice, minQuanPrice, maxQuanPrice, cids);
    }
 
    /**
     * 对应小金额查询:9.9/19.9/29.9/49.9
     */
    @Override
    @Cacheable(value = "quality9K9Cache", key = "'count9k9ClassGoods-'+#biz30day+'-'+#zkPrice+'-'+#minQuanPrice+'-'+#maxQuanPrice+'-'+#cids")
    public long count9k9ClassGoods(Integer biz30day, BigDecimal zkPrice, BigDecimal minQuanPrice,
            BigDecimal maxQuanPrice, String cids) {
        return qualityFactoryMapper.count9k9ClassGoods(biz30day, zkPrice, minQuanPrice, maxQuanPrice, cids);
    }
 
    /**
     * 查询标签
     * 
     * @param start
     * @param count
     * @param key
     * @param labId
     * @return
     */
    public List<QualityFactory> listQueryByKeyAndlabIDs(long start, int count, String key, List<Long> listId,
            Integer sort, Long systemCid, Integer hasQuan, Integer userType, Integer biz30day, Integer startprice,
            Integer endprice) {
        return qualityFactoryMapper.listQueryByKeyAndlabIDs(start, count, key, listId, sort, systemCid, hasQuan,
                userType, biz30day, startprice, endprice);
    }
 
    public long countQueryKeyAndlabIDs(String key, List<Long> listId, Long systemCid, Integer hasQuan, Integer userType,
            Integer biz30day, Integer startprice, Integer endprice) {
        return qualityFactoryMapper.countQueryKeyAndlabIDs(key, listId, systemCid, hasQuan, userType, biz30day,
                startprice, endprice);
    }
 
    /**
     * 关键词搜索
     * 
     * @param start
     * @param count
     * @param key
     * @param labId
     * @return
     */
    @Override
    public List<QualityFactory> listQueryByKey(long start, int count, String key, Integer sort, Long systemCid,
            Integer hasQuan, Integer userType, Integer biz30day, Integer startprice, Integer endprice) {
        return qualityFactoryMapper.listQueryByKey(start, count, key, sort, systemCid, hasQuan, userType, biz30day,
                startprice, endprice);
    }
 
    public long countQueryByKey(String key, Long systemCid, Integer hasQuan, Integer userType, Integer biz30day,
            Integer startprice, Integer endprice) {
 
        return qualityFactoryMapper.countQueryByKey(key, systemCid, hasQuan, userType, biz30day, startprice, endprice);
    }
 
    /**
     * 一级分类查询精选库数据
     * 
     * @param start
     * @param count
     * @param key
     * @param labId
     * @return
     */
    @Override
    @Cacheable(value = "qualityCache", key = "'listQueryByClassId-'+#start+'-'+#cid")
    public List<QualityFactory> listQueryByClassId(long start, int count, Long cid) {
        List<QualityFactory> list = qualityFactoryMapper.listQuery(start, count, null, cid, null, null, 1);
    
        if (list == null) {
            list = new ArrayList<QualityFactory>();
        }
        
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        for (QualityFactory qf : list)
            goodsList.add(qf.getTaoBaoGoodsBrief());
        //过滤商品信息
        goodsList=taoBaoGoodsUpdateService.filterImportantTaoBaoGoods(goodsList);
        goodsList = daTaoKeGoodsDetailService.filterTaoBaoGoods(goodsList);// 过滤大淘客标题
        for (int i = 0; i < list.size(); i++) {
            if (i < goodsList.size())
                list.get(i).setTaoBaoGoodsBrief(goodsList.get(i));
 
        }
        return list;
    }
 
    @Override
    @Cacheable(value = "qualityCache", key = "'countQueryClassId-'+#cid")
    public long countQueryClassId(Long cid) {
        return qualityFactoryMapper.countQuery(null, cid, null, null, 1);
    }
 
    @Override
    @Cacheable(value = "qualityCache", key = "'listQueryByRebateAmount-'+#start+'-'+#proportion+'-'+#endAmount+'-'+#endAmount+'-'+#tkRate")
    public List<QualityFactory> listQueryByRebateAmount(long start, int count, String proportion, Integer startAmount,
            Integer endAmount, double tkRate) {
        return qualityFactoryMapper.listQueryByRebateAmount(start, count, proportion, startAmount, endAmount, tkRate);
    }
 
    @Override
    @Cacheable(value = "qualityCache", key = "'countQueryByRebateAmount-'+#proportion+'-'+#endAmount+'-'+#endAmount+'-'+#tkRate")
    public long countQueryByRebateAmount(String proportion, Integer startAmount, Integer endAmount, double tkRate) {
        return qualityFactoryMapper.countQueryByRebateAmount(proportion, startAmount, endAmount, tkRate);
    }
 
    @Override
    // @Cacheable(value = "qualityCache",key="'queryToCouponColumn-'+#start")
    @Cacheable(value = "taoBaoCouponCache", key = "'queryToCouponColumn'+#start")
    public List<QualityFactory> queryToCouponColumn(long start, int count) {
        return qualityFactoryMapper.queryToCouponColumn(start, count);
    }
 
    @Override
    // @Cacheable(value = "qualityCache",key="'countQueryToCouponColumn'")
    @Cacheable(value = "taoBaoCouponCache", key = "'countQueryToCouponColumn'")
    public long countQueryToCouponColumn() {
        return qualityFactoryMapper.countQueryToCouponColumn();
    }
 
    /**
     * 首页最底部@商品信息流
     */
    @Override
    public List<QualityFactory> listRecommend(long start, int count, Double proportion, Integer commision,
            Integer couponAmount, double tkRate, Double couponRatio) {
        return qualityFactoryMapper.listRecommendToIndex(start, count, proportion, commision, couponAmount, tkRate,
                couponRatio);
    }
    
 
    @Override
    public long countRecommend(Double proportion, Integer commision, Integer couponAmount, double tkRate,
            Double couponRatio) {
        return qualityFactoryMapper.countRecommendToIndex(proportion, commision, couponAmount, tkRate, couponRatio);
    }
 
    @Override
    public List<QualityFactory> listRecommendBykey(long start, int count, String key, Integer hasQuan, Integer userType,
            Double startprice, Double endprice, Double startTkRate, Double endTkRate, Integer sort) {
        return qualityFactoryMapper.listRecommendBykey(start, count, key, hasQuan, userType, startprice, endprice,
                startTkRate, endTkRate, sort);
    }
 
    @Override
    public long countRecommendBykey(String key, Integer hasQuan, Integer userType, Double startprice, Double endprice,
            Double startTkRate, Double endTkRate) {
        return qualityFactoryMapper.countRecommendBykey(key, hasQuan, userType, startprice, endprice, startTkRate,
                endTkRate);
    }
 
    /**
     * 首页最底部@商品信息流
     */
    @Override
    @Cacheable(value = "qualityCache", key = "'listQueryToRecommend-'+#start+'-'+#proportion")
    public JSONArray getRecommendToIndex(long start, int count, String proportion) {
 
        // 返利金额2元以上;
        Integer commision = 2;
        // 优惠券面额高于5元以上
        Integer couponAmount = 5;
        // 佣金比例高的:5%以上;
        double tkRate = 5.0;
        // 优惠率高于10%以上(优惠率=优惠券面额/商品在售价*100%)
        Double couponRatio = 10.0;
 
        Double pop = 50.0;
        if (!StringUtil.isNullOrEmpty(proportion)) {
            pop = Double.parseDouble(proportion);
        }
 
        List<QualityFactory> listQuery = listRecommend(start, count, pop, commision, couponAmount, tkRate, couponRatio);
 
        if (listQuery == null || listQuery.size() == 0) {
            return null;
        }
 
        JSONArray array = new JSONArray();
        Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create();
        // 遍历列表数据
        //
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        for (QualityFactory quality : listQuery) {
            if (quality.getTaoBaoGoodsBrief() != null)
                goodsList.add(quality.getTaoBaoGoodsBrief());
        }
 
        try {
            goodsList = daTaoKeGoodsDetailService.filterTaoBaoGoods(goodsList);
        } catch (Exception e) {
        }
 
        for (TaoBaoGoodsBrief taoBaoGoodsBrief : goodsList) {
            int biz30day = taoBaoGoodsBrief.getBiz30day();
            if (biz30day >= 10000) {
                double sales = biz30day;
                String salesCountMidea = String.format("%.1f", sales / 10000);
                taoBaoGoodsBrief.setSalesCount(salesCountMidea + "万");
            } else {
                taoBaoGoodsBrief.setSalesCount(biz30day + "");
            }
 
            // 改变图片尺寸
            String pictUrl = taoBaoGoodsBrief.getPictUrl();
            if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
                taoBaoGoodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
            }
 
            array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion, null)));
        }
 
        return array;
    }
    
    
    
 
    /**
     * 首页最底部@商品信息流
     */
    @Override
    @Cacheable(value = "qualityCache", key = "'getRecommendToIndexV2-'+#start")
    public JSONArray getRecommendToIndexV2(long start, int count) {
 
        // 返利金额2元以上;
        Integer commision = 2;
        // 优惠券面额高于5元以上
        Integer couponAmount = 5;
        // 佣金比例高的:5%以上;
        double tkRate = 5.0;
        // 优惠率高于10%以上(优惠率=优惠券面额/商品在售价*100%)
        Double couponRatio = 10.0;
 
        BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
        Double pop = 50.0;
        if (fanLiRate != null) {
            pop = Double.parseDouble(fanLiRate.toString());
        }
        
        List<QualityFactory> listQuery = listRecommend(start, count, pop, commision, couponAmount, tkRate, couponRatio);
 
        if (listQuery == null || listQuery.size() == 0) {
            return null;
        }
 
        JSONArray array = new JSONArray();
        Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create();
        // 遍历列表数据
        //
        List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
        for (QualityFactory quality : listQuery) {
            if (quality.getTaoBaoGoodsBrief() != null)
                goodsList.add(quality.getTaoBaoGoodsBrief());
        }
 
        try {
            goodsList = daTaoKeGoodsDetailService.filterTaoBaoGoods(goodsList);
        } catch (Exception e) {
        }
 
        BigDecimal shareRate = hongBaoManageService.getShareRate();
        for (TaoBaoGoodsBrief taoBaoGoodsBrief : goodsList) {
            GoodsDetailVO detailVO = GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, null, fanLiRate, shareRate);
            array.add(gson.toJson(detailVO));
        }
 
        return array;
    }
 
    
    
    @Override
    @Cacheable(value = "qualityCache", key = "'countRecommendToIndex-'+#proportion")
    public long countRecommendToIndex(String proportion) {
 
        // 返利金额2元以上;
        Integer commision = 2;
        // 优惠券面额高于5元以上
        Integer couponAmount = 5;
        // 佣金比例高的:5%以上;
        double tkRate = 5.0;
        // 优惠率高于10%以上(优惠率=优惠券面额/商品在售价*100%)
        Double couponRatio = 10.0;
 
        Double pop = 50.0;
        if (!StringUtil.isNullOrEmpty(proportion)) {
            pop = Double.parseDouble(proportion);
        }
 
        return countRecommend(pop, commision, couponAmount, tkRate, couponRatio);
    }
 
    @Override
    public List<QualityFactory> recommendByAuctionId(Long auctionId) {
 
        List<Long> list = new ArrayList<Long>();
        list.add(auctionId);
        List<QualityFactory> listTaoBaoGoods = qualityFactoryMapper.listQueryByAuctionId(list);
 
        if (listTaoBaoGoods == null || listTaoBaoGoods.size() == 0) {
            return null;
        }
 
        QualityFactory qualityFactory = listTaoBaoGoods.get(0);
        TaoBaoGoodsBrief goodsBrief = qualityFactory.getTaoBaoGoodsBrief();
        if (goodsBrief == null) {
            return null;
        }
 
        List<LabelGoods> listLab = labelGoodsMapper.queryByGoodsId(0, 200, goodsBrief.getId());
        if (listLab == null || listLab.size() == 0) {
            return null;
        }
 
        // 标签id
        List<Long> listId = new ArrayList<Long>();
        for (LabelGoods labelGoods : listLab) {
            Label label = labelGoods.getLabel();
            if (label != null) {
                listId.add(label.getId());
            }
        }
 
        if (listId.size() == 0) {
            return null;
        }
 
        return qualityFactoryMapper.listQueryBylabIDs(0, 10, listId, goodsBrief.getId(), qualityFactory.getSystemCid());
    }
 
    @Override
    public List<QualityFactory> listFreeGoods(long start, int count) {
        return qualityFactoryMapper.listFreeGoods(start, count);
    }
 
    @Override
    public long countFreeGoods() {
        return qualityFactoryMapper.countFreeGoods();
    }
 
    @Override
    public List<QualityFactory> listByShopId(long start, int count, Long shopId) {
        return qualityFactoryMapper.listByShopId(start, count, shopId);
    }
 
    @Override
    public long countByShopId(Long shopId) {
        return qualityFactoryMapper.countByShopId(shopId);
    }
 
    @Override
    public List<QualityFactory> listQueryEverydayRob(long start, int count, BigDecimal zkPrice, BigDecimal minQuanPrice,
            BigDecimal maxQuanPrice) {
        return qualityFactoryMapper.listQueryEverydayRob(start, count, zkPrice, minQuanPrice, maxQuanPrice);
    }
 
    @Override
    public long countQueryEverydayRob(BigDecimal zkPrice, BigDecimal minQuanPrice, BigDecimal maxQuanPrice) {
        return qualityFactoryMapper.countQueryEverydayRob(zkPrice, minQuanPrice, maxQuanPrice);
    }
}