admin
2018-12-05 eb8704f0218814f4c3ebfd0a1a6f5dbbb26db8d1
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
package com.yeshi.fanli.service.impl.goods;
 
import java.util.Date;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.goods.ScanHistoryV2Mapper;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.goods.ScanHistoryV2;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.goods.CommonGoodsException;
import com.yeshi.fanli.exception.goods.ScanHistoryException;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.goods.ScanHistoryV2Service;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.CommonGoodsFactory;
 
@Service
public class ScanHistoryV2ServiceImpl implements ScanHistoryV2Service {
 
    @Resource
    private CommonGoodsService commonGoodsService;
 
    @Resource
    private ScanHistoryV2Mapper scanHistoryV2Mapper;
 
    @Override
    public void addScanHistory(Long uid, String device, TaoBaoGoodsBrief goods)
            throws CommonGoodsException, ScanHistoryException {
        if (uid == null && StringUtil.isNullOrEmpty(device))
            throw new ScanHistoryException(1, "设备或用户信息缺失");
        CommonGoods commonGoods = CommonGoodsFactory.create(goods);
        commonGoods = commonGoodsService.addOrUpdateCommonGoods(commonGoods);
        if (commonGoods == null)
            throw new CommonGoodsException(2, "商品信息不完整");
        // 添加浏览记录
        ScanHistoryV2 scanHistoryV2 = new ScanHistoryV2();
        scanHistoryV2.setCommonGoods(commonGoods);
        scanHistoryV2.setCreateTime(new Date());
        scanHistoryV2.setDevice(device);
        if (uid != null)
            scanHistoryV2.setUserInfo(new UserInfo(uid));
        scanHistoryV2.setUpdateTime(new Date());
        scanHistoryV2Mapper.insertSelective(scanHistoryV2);
    }
 
    @Override
    public void addScanHistory(ScanHistoryV2 history) throws CommonGoodsException, ScanHistoryException {
        if (history == null)
            throw new ScanHistoryException(1, "浏览信息不能为空");
        if (history.getUserInfo() == null && StringUtil.isNullOrEmpty(history.getDevice()))
            throw new ScanHistoryException(1, "设备或用户信息缺失");
 
        CommonGoods commonGoods = commonGoodsService.addOrUpdateCommonGoods(history.getCommonGoods());
        if (commonGoods == null)
            throw new CommonGoodsException(2, "商品信息不完整");
        history.setCommonGoods(commonGoods);
        scanHistoryV2Mapper.insertSelective(history);
    }
 
}