Administrator
2020-02-18 c460c9d4f116be480ab5b6604b77be3bbc76a128
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
package com.yeshi.fanli.service.impl.dynamic;
 
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.UUID;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.yeshi.utils.tencentcloud.COSManager;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.dao.dynamic.GoodsEvaluateDao;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.bus.activity.ActivityUser;
import com.yeshi.fanli.entity.dynamic.CommentInfo;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate;
import com.yeshi.fanli.entity.dynamic.ImgInfo;
import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum;
import com.yeshi.fanli.entity.dynamic.SimpleGoods;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.dynamic.ActivityUserException;
import com.yeshi.fanli.exception.dynamic.GoodsEvaluateException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.activity.ActivityUserService;
import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.FilePathEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.cache.JDGoodsCacheUtil;
import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.vo.goods.CouponInfoVO;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
 
@Service
public class GoodsEvaluateServiceImpl implements GoodsEvaluateService {
 
    @Resource
    private GoodsEvaluateDao goodsEvaluateDao;
 
    @Resource
    private ActivityUserService activityUserService;
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private HongBaoManageService hongBaoManageService;
 
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
 
    @Resource
    private JDGoodsCacheUtil jdGoodsCacheUtil;
 
    @Resource
    private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
 
    @Override
    public void saveHead(MultipartFile file, GoodsEvaluate record) throws GoodsEvaluateException {
        Integer state = record.getState();
        if (state == null) {
            state = 0;
        }
 
        String tilte = record.getTitle();
        if (StringUtil.isNullOrEmpty(tilte)) {
            throw new GoodsEvaluateException(1, "推荐语不能为空");
        }
 
        try {
            ActivityUser activityUser = activityUserService.getActivityUserByNickName(record.getUser(), file);
            if (activityUser == null)
                throw new GoodsEvaluateException(1, "请选择发布者");
            record.setUser(activityUser);
        } catch (ActivityUserException e) {
            throw new GoodsEvaluateException(1, e.getMsg());
        }
 
        if (record.getEndTime() != null) {
            if (record.getEndTime().getTime() <= java.lang.System.currentTimeMillis())
                throw new GoodsEvaluateException(1, "截止时间必须大于当前时间");
 
            if (record.getStartTime() != null && record.getEndTime().getTime() <= record.getStartTime().getTime())
                throw new GoodsEvaluateException(1, "截止时间必须大于开始时间");
        }
 
        if (record.getShareNum() == null)
            record.setShareNum(0);
 
        if (record.getWeight() == null)
            record.setWeight(0.0);
 
        if (record.getStartTime() == null)
            record.setStartTime(new Date());
        record.setPublishTime(record.getStartTime());
 
        if (StringUtil.isNullOrEmpty(record.getId())) {
            record.setId(UUID.randomUUID().toString().replace("-", ""));
            record.setShareNumReal(0);
            record.setCreateTime(new Date());
            goodsEvaluateDao.save(record);
        } else {
            GoodsEvaluate resultObj = goodsEvaluateDao.getById(record.getId());
            if (resultObj == null)
                throw new GoodsEvaluateException(1, "修改内容已不存在");
 
            resultObj.setUser(record.getUser());
            resultObj.setShareNum(record.getShareNum());
            resultObj.setWeight(record.getWeight());
            resultObj.setStartTime(record.getStartTime());
            resultObj.setEndTime(record.getEndTime());
            resultObj.setTitle(tilte);
            goodsEvaluateDao.save(resultObj);
        }
    }
 
    /**
     * 上传图片
     * 
     * @param file
     * @return
     * @throws Exception
     */
    private String uploadPicture(MultipartFile file) throws Exception {
        InputStream inputStream = file.getInputStream();
        String contentType = file.getContentType();
        String type = contentType.substring(contentType.indexOf("/") + 1);
        String filePath = FilePathEnum.goodsEvaluate.getPath() + UUID.randomUUID().toString().replace("-", "") + "."
                + type;
        return COSManager.getInstance().uploadFile(inputStream, filePath).getUrl();
    }
 
    /**
     * 删除图片
     * 
     * @param record
     * @throws Exception
     */
    private void removePicture(String picture) throws Exception {
        if (picture != null && picture.trim().length() > 0) {
            COSManager.getInstance().deleteFile(picture);
        }
    }
 
    @Override
    public void saveSingleGoods(String pid, Long goodsId, Integer goodsType, String videoUrl, Integer picNum,
            String picUrls, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception {
        if (StringUtil.isNullOrEmpty(pid)) {
            throw new GoodsEvaluateException(1, "请保存第一部分信息");
        }
 
        GoodsEvaluate resultObj = goodsEvaluateDao.getById(pid);
        if (resultObj == null)
            throw new GoodsEvaluateException(1, "第一部分信息缺失");
 
        // 原封视频面图
        ImgInfo imgVideo = null;
        List<String> listDel = new ArrayList<String>();
        List<String> listOld = new ArrayList<String>();
 
        // 处理图片
        List<ImgInfo> resultList = resultObj.getImgList();
        if (resultList != null && resultList.size() > 0) {
            for (ImgInfo info : resultList) {
                ImgEnum type = info.getType();
                if (type == ImgEnum.video) {
                    imgVideo = info;
                } else if (type == ImgEnum.goods || type == ImgEnum.img) {
                    String url = info.getUrl();
                    if (!StringUtil.isNullOrEmpty(url)) {
                        listOld.add(url);
                    }
                }
            }
        }
 
        // 视频部分
        if (fileRequest != null) {
            MultipartFile filevideo = fileRequest.getFile("filevideo");
            if (filevideo != null) {
                if (StringUtil.isNullOrEmpty(videoUrl)) {
                    throw new GoodsEvaluateException(1, "视频链接不能为空");
                }
 
                String picLink = uploadPicture(filevideo);
                if (imgVideo != null) {
                    String url = imgVideo.getUrl();
                    if (!StringUtil.isNullOrEmpty(url)) {
                        listDel.add(url);
                    }
                    imgVideo.setUrl(picLink);
                    imgVideo.setUrlHD(picLink);
                } else {
                    imgVideo = new ImgInfo();
                    imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
                    imgVideo.setW(1);
                    imgVideo.setH(1);
                    imgVideo.setLarge(true);
                    imgVideo.setPid(pid);
                    imgVideo.setUrl(picLink);
                    imgVideo.setUrlHD(picLink);
                    imgVideo.setVideoUrl(videoUrl);
                    imgVideo.setType(ImgEnum.video);
                }
            }
        }
 
        List<ImgInfo> listImg = new ArrayList<ImgInfo>();
        if (imgVideo != null) {
            if (!StringUtil.isNullOrEmpty(videoUrl)) {
                if (imgVideo != null && StringUtil.isNullOrEmpty(imgVideo.getUrl())) {
                    throw new GoodsEvaluateException(1, "视频封面图不能为空");
                }
                imgVideo.setVideoUrl(videoUrl);
                listImg.add(imgVideo);
            } else {
                String url = imgVideo.getUrl();
                if (!StringUtil.isNullOrEmpty(url)) {
                    listDel.add(url);
                }
            }
        }
 
        // 编辑图片
        List<String> listpic = null;
        if (!StringUtil.isNullOrEmpty(picUrls)) {
            String[] pics = picUrls.split(",");
            if (pics != null) {
                listpic = new ArrayList<>();
                for (int i = 0; i < pics.length; i++ ) {
                    if(pics[i].startsWith("http")){
                        listpic.add(pics[i]);
                    }
                }
            }
        }
 
        if (fileRequest != null) {
            for (int i = 0; i < 9; i++) {
                MultipartFile file = fileRequest.getFile("file" + i);
                if (file == null) {
                    continue;
                }
                // 上传文件
                String picLink = uploadPicture(file);
                if (listpic != null && listpic.size() > i) {
                    // 需要删除的list
                    String delUrl = listpic.get(i);
                    listDel.add(delUrl);
                    listpic.set(i, picLink);
                    continue;
                }
                listpic.add(picLink);
            }
 
            // 指定主图
            if (picNum == null || picNum > 9 || picNum < 1) {
                picNum = 1;
            }
 
            if (listpic != null && listpic.size() > 0) {
                // 对比图片
                for (int j = 0; j < listOld.size(); j++) {
                    boolean del = true;
                    for (int i = 0; i < listpic.size(); i++) {
                        if (listpic.get(i).equals(listOld.get(j))) {
                            del = false;
                            break;
                        }
                    }
                    if (del)
                        listDel.add(listOld.get(j));
                }
                
                for (int i = 0; i < listpic.size(); i++) {
                    ImgInfo imgInfo0 = new ImgInfo();
                    imgInfo0.setId(UUID.randomUUID().toString().replace("-", ""));
                    imgInfo0.setW(1);
                    imgInfo0.setH(1);
                    imgInfo0.setLarge(false);
                    imgInfo0.setPid(pid);
                    imgInfo0.setUrl(listpic.get(i));
                    imgInfo0.setUrlHD(listpic.get(i));
 
                    if (picNum - 1 == i) {
                        imgInfo0.setType(ImgEnum.goods);
                        // 商品信息
                        GoodsDetailVO goodsDetailVO = null; // TODO
//                                getGoodsDetailVO(goodsId, goodsType);
//                        if (goodsDetailVO == null) {
//                            throw new GoodsEvaluateException(1, "该商品信息不存在");
//                        }
 
                        SimpleGoods simpleGoods = new SimpleGoods();
                        simpleGoods.setGoodsId(goodsId);
                        simpleGoods.setGoodsType(goodsType);
//                        simpleGoods.setPrice(goodsDetailVO.getCouponPrice());
//                        CouponInfoVO couponInfo = goodsDetailVO.getCouponInfo();
//                        if (couponInfo == null) {
//                            simpleGoods.setState(1);
//                        } else {
//                            simpleGoods.setAmount(couponInfo.getAmount());
//                            simpleGoods.setState(0);
//                        }
                        imgInfo0.setGoods(simpleGoods);
                    } else {
                        imgInfo0.setType(ImgEnum.img);
                    }
                    listImg.add(imgInfo0);
                }
            }
        }
        
        // 保存图片信息
        resultObj.setMainPicNum(picNum);
        resultObj.setImgList(listImg);
        goodsEvaluateDao.save(resultObj);
        
        // 删除图片
        if (listDel.size() > 0) {
            for (String url : listDel) {
                if (url.contains(FilePathEnum.goodsEvaluate.getPath())) {
                    removePicture(url);
                }
            }
        }
    }
 
    public GoodsDetailVO getGoodsDetailVO(Long goodsId, Integer goodsType) throws GoodsEvaluateException {
        GoodsDetailVO goodsDetail = null;
        BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
        BigDecimal shareRate = hongBaoManageService.getShareRate();
        BigDecimal vipFanLiRate = hongBaoManageService.getVIPFanLiRate();
        ConfigParamsDTO params = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE, vipFanLiRate);
        if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
            try {
                TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(goodsId);
                goodsDetail = GoodsDetailVOFactory.convertTaoBao(goodsBrief, params);
            } catch (TaobaoGoodsDownException e) {
                throw new GoodsEvaluateException(1, "商品已下架");
            }
        } else if (goodsType == Constant.SOURCE_TYPE_JD) {
            JDGoods goodsInfo = jdGoodsCacheUtil.getGoodsInfo(goodsId);
            goodsDetail = GoodsDetailVOFactory.convertJDGoods(goodsInfo, params);
        } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
            PDDGoodsDetail goodsInfo = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
            goodsDetail = GoodsDetailVOFactory.convertPDDGoods(goodsInfo, params);
        }
        return goodsDetail;
    }
    
    @Override
    public void saveSingleGoodsCoupon(String pid, CommentInfo commentInfo) throws GoodsEvaluateException, Exception {
        if (StringUtil.isNullOrEmpty(pid)) {
            throw new GoodsEvaluateException(1, "请保存第一部分信息");
        }
 
        GoodsEvaluate resultObj = goodsEvaluateDao.getById(pid);
        if (resultObj == null)
            throw new GoodsEvaluateException(1, "第一部分信息缺失");
 
        List<CommentInfo> comments = new ArrayList<>();
        if (commentInfo != null) {
            comments.add(commentInfo);
        }
        resultObj.setComments(comments);
        
        goodsEvaluateDao.save(resultObj);
    }
 
 
    @Override
    public void saveActivityPic(String pid, ImgInfo imgInfo, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception {
        if (StringUtil.isNullOrEmpty(pid)) {
            throw new GoodsEvaluateException(1, "请保存第一部分信息");
        }
 
        GoodsEvaluate resultObj = goodsEvaluateDao.getById(pid);
        if (resultObj == null)
            throw new GoodsEvaluateException(1, "第一部分信息缺失");
 
        String videoPic = null;
        String activityPic = null;
        ImgInfo imgVideo = null;
        ImgInfo imgactivity = null;
        List<ImgInfo> resultList = resultObj.getImgList();
        if (resultList != null && resultList.size() > 0) {
            for(ImgInfo info: resultList) {
                if (info.getType() == ImgEnum.activity) {
                    activityPic = info.getActivityPic();
                    imgVideo = info;
                } else {
                    imgVideo = info;
                    videoPic = info.getUrl();
                }
            }
        }
        
        
        List<ImgInfo> listImg = new ArrayList<ImgInfo>();
        if (fileRequest != null) {
            MultipartFile filevideo = fileRequest.getFile("filevideo");
            if (filevideo != null) {
                removePicture(videoPic);
                String picLink = uploadPicture(filevideo);
                videoPic = picLink;
            }
            
            MultipartFile activityfile = fileRequest.getFile("activityfile");
            if (activityfile != null) {
                removePicture(activityPic);
                String picLink = uploadPicture(activityfile);
                activityPic = picLink;
            }
        }
        
        if (!StringUtil.isNullOrEmpty(videoPic) || !StringUtil.isNullOrEmpty(imgInfo.getVideoUrl())) {
            if (imgVideo != null){
                imgVideo.setUrl(videoPic);
                imgVideo.setUrlHD(videoPic);
                imgVideo.setVideoUrl(imgInfo.getVideoUrl());
            } else {
                imgVideo = new ImgInfo();
                imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
                imgVideo.setW(1);
                imgVideo.setH(1);
                imgVideo.setLarge(true);
                imgVideo.setPid(pid);
                imgVideo.setUrl(videoPic);
                imgVideo.setUrlHD(videoPic);
                imgVideo.setVideoUrl(imgInfo.getVideoUrl());
                imgVideo.setType(ImgEnum.video);
            }
            listImg.add(imgVideo);
        }
        
        if (!StringUtil.isNullOrEmpty(activityPic) || !StringUtil.isNullOrEmpty(imgInfo.getActivityUrl())) {
            if (imgVideo != null){
                imgVideo.setUrl(activityPic);
                imgVideo.setUrlHD(activityPic);
                imgVideo.setVideoUrl(imgInfo.getVideoUrl());
            } else {
                imgVideo = new ImgInfo();
                imgVideo.setId(UUID.randomUUID().toString().replace("-", ""));
                imgVideo.setW(1);
                imgVideo.setH(1);
                imgVideo.setLarge(true);
                imgVideo.setPid(pid);
                imgVideo.setUrl(activityPic);
                imgVideo.setUrlHD(activityPic);
                imgVideo.setActivityUrl(imgInfo.getActivityUrl());
                imgVideo.setType(ImgEnum.activity);
            }
            listImg.add(imgVideo);
        }
        resultObj.setImgList(listImg);
        goodsEvaluateDao.save(resultObj);
    }
 
    
    @Override
    public void deleteBatchByPrimaryKey(List<String> list) {
        if (list == null || list.size() == 0) {
            return;
        }
        for (String id : list) {
            goodsEvaluateDao.deleteById(id);
        }
    }
 
    @Override
    public GoodsEvaluate getById(String id) {
        return goodsEvaluateDao.getById(id);
    }
 
    @Override
    public void saveComment(String pid, CommentInfo commentInfo) throws GoodsEvaluateException {
        GoodsEvaluate goodsEvaluate = goodsEvaluateDao.getById(pid);
        if (goodsEvaluate == null) {
            throw new GoodsEvaluateException(1, "动态已不存在");
        }
 
        String tags = commentInfo.getTags();
        if (!StringUtil.isNullOrEmpty(tags)) {
            String[] arrayTags = tags.split("\\s+");
            if (arrayTags != null && arrayTags.length > 0) {
                String[] arrayTagsColour = null;
                String tagsColour = commentInfo.getTagsColour();
                if (!StringUtil.isNullOrEmpty(tagsColour)) {
                    arrayTagsColour = tagsColour.split("\\s+");
                }
 
                String color = "#E5005C";
                List<ClientTextStyleVO> tagList = new ArrayList<ClientTextStyleVO>();
                for (int i = 0; i < arrayTags.length; i++) {
                    String tag = arrayTags[i];
                    if (arrayTagsColour != null && arrayTagsColour.length == arrayTags.length) {
                        color = arrayTagsColour[i];
                    }
                    ClientTextStyleVO styleVO = new ClientTextStyleVO();
                    styleVO.setColor(color);
                    styleVO.setContent(tag);
                    tagList.add(styleVO);
                }
                commentInfo.setTagList(tagList);
            }
        }
 
        List<CommentInfo> comments = goodsEvaluate.getComments();
        if (comments == null) {
            comments = new ArrayList<>();
        }
 
        Integer weight = commentInfo.getWeight();
        if (weight == null)
            commentInfo.setWeight(1);
 
        comments.add(commentInfo);
 
        Collections.shuffle(comments);
        Comparator<CommentInfo> cm = new Comparator<CommentInfo>() {
            @Override
            public int compare(CommentInfo o1, CommentInfo o2) {
                return o1.getWeight() != null && o2.getWeight() != null ? o2.getWeight() - o1.getWeight() : 0;
            }
        };
        Collections.sort(comments, cm);
 
        goodsEvaluate.setComments(comments);
        goodsEvaluateDao.save(goodsEvaluate);
    }
 
    @Override
    public void deleteComment(String pid, List<String> list) throws GoodsEvaluateException {
        if (list == null || list.size() == 0) {
            return;
        }
        GoodsEvaluate goodsEvaluate = goodsEvaluateDao.getById(pid);
        if (goodsEvaluate == null) {
            throw new GoodsEvaluateException(1, "动态已不存在");
        }
 
        List<CommentInfo> comments = goodsEvaluate.getComments();
        if (comments == null || comments.size() == 0) {
            return;
        }
 
        for (String id : list) {
            for (int i = 0; i < comments.size(); i++) {
                CommentInfo commentInfo = comments.get(i);
                if (id.equals(commentInfo.getId())) {
                    comments.remove(i);
                    i--;
                }
            }
        }
        goodsEvaluate.setComments(comments);
        goodsEvaluateDao.save(goodsEvaluate);
    }
 
    @Override
    public void addShareNum(String id) {
        GoodsEvaluate article = goodsEvaluateDao.getById(id);
        if (article != null) {
            Integer num = article.getShareNum();
            if (num == null) {
                num = 0;
            }
            article.setShareNum(num + 1);
 
            Integer numReal = article.getShareNumReal();
            if (numReal == null) {
                numReal = 0;
            }
            article.setShareNumReal(numReal + 1);
 
            goodsEvaluateDao.save(article);
        }
    }
 
    @Override
    public List<GoodsEvaluate> query(int start, int count, String key, Integer state) {
        return goodsEvaluateDao.query(start, count, key, state);
    }
 
    @Override
    public long count(String key, Integer state) {
        return goodsEvaluateDao.count(key, state);
    }
 
    @Override
    @Cacheable(value = "dynamicCache", key = "'queryValidEvaluateCache-'+#start")
    public List<GoodsEvaluate> queryValidEvaluateCache(int start, int count) {
        List<GoodsEvaluate> list = goodsEvaluateDao.queryValid(start, count);
 
        // 更新商品信息
        executor.execute(new Runnable() {
            @Override
            public void run() {
                updateGoodInfo(list);
            }
        });
 
        return list;
    }
 
    @Override
    public long countValid() {
        return goodsEvaluateDao.countValid();
    }
 
    /**
     * 更新商品信息
     */
    public void updateGoodInfo(List<GoodsEvaluate> list) {
        if (!Constant.IS_OUTNET) {
            return; // 外网进行更新
        }
 
        if (list == null || list.size() == 0) {
            return;
        }
 
        try {
            BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
            BigDecimal shareRate = hongBaoManageService.getShareRate();
            BigDecimal vipFanLiRate = hongBaoManageService.getVIPFanLiRate();
            ConfigParamsDTO paramsDTO = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE,
                    vipFanLiRate);
            for (GoodsEvaluate goodsEvaluate : list) {
                // 是否2个小时之内已更新
                Date updateTime = goodsEvaluate.getUpdateTime();
                if (updateTime != null) {
                    long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
                    long nh = 1000 * 60 * 60;// 一小时的毫秒数
                    long diff = System.currentTimeMillis() - updateTime.getTime();
                    long day = diff / nd;// 计算差多少天
                    long hour = diff % nd / nh + day * 24;// 计算差多少小时
                    if (hour < 2) {
                        continue;
                    }
                }
 
                GoodsDetailVO goods = goodsEvaluate.getGoods();
                if (goods != null) {
                    GoodsDetailVO goodsNew = getGoodsNewInfo(goods.getGoodsId(), goods.getGoodsType(), paramsDTO);
                }
                // 更新商品信息
                List<ImgInfo> imgList = goodsEvaluate.getImgList();
                if (imgList == null || imgList.size() == 0) {
                    continue;
                }
 
            }
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
    }
 
    private GoodsDetailVO getGoodsNewInfo(Long goodsId, int goodsType, ConfigParamsDTO paramsDTO) {
        GoodsDetailVO vo = null;
        if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
 
        } else if (goodsType == Constant.SOURCE_TYPE_JD) {
            JDGoods goodsInfo = jdGoodsCacheUtil.getGoodsInfo(goodsId);
            if (goodsInfo != null) {
                vo = GoodsDetailVOFactory.convertJDGoods(goodsInfo, paramsDTO);
            }
        } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
            PDDGoodsDetail goodsInfo = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
            if (goodsInfo != null)
                vo = GoodsDetailVOFactory.convertPDDGoods(goodsInfo, paramsDTO);
        }
        return vo;
    }
 
}