admin
2019-09-06 2012b3b5db3c6b06535a68f775bcc81b16151b90
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
package com.yeshi.fanli.service.impl.brand;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper;
import com.yeshi.fanli.entity.brand.BrandInfo;
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.exception.brand.BrandInfoException;
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
import com.yeshi.fanli.service.inter.brand.BrandInfoService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.vo.brand.BrandInfoVO;
import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
 
@Service
public class BrandInfoServiceImpl implements BrandInfoService {
    
    @Resource
    private BrandInfoMapper brandInfoMapper;
    
    @Resource
    private HongBaoManageService hongBaoManageService;
 
    @Resource
    private QualityGoodsService qualityGoodsService;
 
    @Resource
    private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
 
    @Resource
    private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
    
    @Resource
    private BrandClassShopService brandClassShopService;
 
    
    @Override
    public void saveObject(BrandInfo record) throws BrandInfoException{
        String name = record.getName();
        if (name == null || name.trim().length() == 0)
            throw new BrandInfoException(1, "名称不能为空");
        
        Integer state = record.getState();
        if (state == null)
            record.setState(0);
        
        Long id = record.getId();
        if (id == null) {
            record.setCreateTime(new Date());
            record.setUpdateTime(new Date());
            brandInfoMapper.insert(record);
        } else {
            BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id);
            if (resultObj == null)
                throw new BrandInfoException(1, "修改内容已不存在");
            
            record.setCreateTime(resultObj.getCreateTime());
            record.setUpdateTime(new Date());
            brandInfoMapper.updateByPrimaryKey(record);
        }
    }
    
    
    @Override
    public int deleteBatchByPrimaryKey(List<Long> list) {
        return brandInfoMapper.deleteBatchByPrimaryKey(list);
    }
 
    
    @Override
    public List<BrandInfo> listQuery(long start, int count, String key, Integer state) {
        return null;
    }
 
 
    @Override
    public long countQuery(String key, Integer state) {
        return 0;
    }
    
    @Override
    @Cacheable(value = "brandCache", key = "'listValidBrandInfoCache-'+#cid")
    public List<BrandInfo> listValidBrandInfoCache(Long cid) {
        List<BrandInfo> listInfo = new ArrayList<BrandInfo>();
        
        List<TaoBaoShop> listShop = brandClassShopService.listEffectiveClassShop(cid);
        if (listShop == null || listShop.size() == 0)
            return listInfo;
        for (TaoBaoShop taoBaoShop : listShop) {
            BrandInfo brandInfo = new BrandInfo();
            brandInfo.setId(taoBaoShop.getId());
            brandInfo.setName(taoBaoShop.getShopName());
            brandInfo.setIcon(taoBaoShop.getShopIcon());
            listInfo.add(brandInfo);
        }
        return listInfo;
    }
    
    
    @Override
    @Cacheable(value = "brandCache", key = "'listBrandInfoCache-'+#start+'-'+#start +'-'+#cid")
    public List<BrandInfoVO> listBrandInfoCache(long start, int count, Long cid) {
        List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>();
        
        List<TaoBaoShopVO> listShop = brandClassShopService.listEffectiveShop(start, count, cid);
        if (listShop == null || listShop.size() == 0)
            return listInfo;
        
        for (TaoBaoShopVO taoBaoShopVO : listShop) {
            String shopNameCustom = taoBaoShopVO.getShopNameCustom();
            if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
                taoBaoShopVO.setShopName(shopNameCustom);
            }
            String shopIconCustom = taoBaoShopVO.getShopIconCustom();
            if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
                taoBaoShopVO.setShopIcon(shopIconCustom);
            }
            
            BrandInfoVO brandInfoVO = new BrandInfoVO();
            brandInfoVO.setId(taoBaoShopVO.getId());
            brandInfoVO.setName(taoBaoShopVO.getShopName());
            brandInfoVO.setIcon(taoBaoShopVO.getShopIcon());
            brandInfoVO.setListGoods(taoBaoShopVO.getListGoodsVO());
            listInfo.add(brandInfoVO);
        }
        return listInfo;
    }
 
    
    @Override
    public long countBrandInfo(Long cid){
        return brandClassShopService.countBrandShopinfo(cid);
    }
}