admin
2019-05-06 8f45af9d6cdae97f4f265d2f2a123d990cf1bb1d
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
package com.yeshi.fanli.service.impl.goods;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.fanli.dao.mybatis.TaoBaoClassMapper;
import com.yeshi.fanli.dao.mybatis.TaoBaoClassRelationMapper;
import com.yeshi.fanli.entity.bus.clazz.TaoBaoClass;
import com.yeshi.fanli.entity.bus.clazz.TaoBaoClassRelation;
import com.yeshi.fanli.service.inter.goods.TaoBaoClassService;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class TaoBaoClassServiceImpl implements TaoBaoClassService {
 
    @Resource
    private TaoBaoClassMapper taoBaoClassMapper;
 
    @Resource
    private TaoBaoClassRelationMapper taoBaoClassRelationMapper;
 
    @Override
    public List<TaoBaoClass> listBySystemCid(long start, int count, Long systemCid) {
        return taoBaoClassMapper.listBySystemCid(start, count, systemCid);
    }
 
    @Override
    public String getTaoBaoCatIds(Long classId) {
        List<TaoBaoClass> listCatIds = listBySystemCid(0, 10, classId);
        if (listCatIds == null || listCatIds.size() == 0) {
            return null;
        }
 
        String taobaoCatIds = "";
        for (TaoBaoClass taoBaoClass : listCatIds) {
            Integer categoryId = taoBaoClass.getCategoryId();
 
            if (categoryId == null) {
                continue;
            }
            taobaoCatIds += categoryId + ",";
        }
 
        if (!StringUtil.isNullOrEmpty(taobaoCatIds)) {
            taobaoCatIds = taobaoCatIds.substring(0, taobaoCatIds.length() - 1);
        }
        return taobaoCatIds;
    }
 
    @Override
    public TaoBaoClass getByCategoryId(Integer categoryId) {
        return taoBaoClassMapper.getByCategoryId(categoryId);
    }
 
    @Override
    @Transactional
    public void save(Long classId, List<Long> taobaoCids) {
        if (taobaoCids == null) {
            return;
        }
 
        // 删除之前的,插入现在的
        taoBaoClassRelationMapper.deleteByCid(classId);
        for (Long categoryId : taobaoCids) {
            TaoBaoClass taoBaoClass = taoBaoClassMapper.getByCategoryId(Integer.parseInt(categoryId + ""));
            if (taoBaoClass == null)
                continue;
            TaoBaoClassRelation relation = new TaoBaoClassRelation();
            relation.setCid(classId);
            relation.setTaobaoCid(taoBaoClass.getId());
            relation.setCreatetime(new Date());
            relation.setUpdatetime(new Date());
            relation.setWeight(0.0);
            taoBaoClassRelationMapper.insertSelective(relation);
        }
    }
 
    @Transactional
    @Override
    public void saveSub(Long subClassId, List<Long> taobaoCids) {
        if (taobaoCids == null) {
            return;
        }
 
        // 删除之前的,插入现在的
        taoBaoClassRelationMapper.deleteBySubId(subClassId);
        for (Long categoryId : taobaoCids) {
            TaoBaoClass taoBaoClass = taoBaoClassMapper.getByCategoryId(Integer.parseInt(categoryId + ""));
            if (taoBaoClass == null)
                continue;
            TaoBaoClassRelation relation = new TaoBaoClassRelation();
            relation.setSubId(subClassId);
            relation.setTaobaoCid(taoBaoClass.getId());
            relation.setCreatetime(new Date());
            relation.setUpdatetime(new Date());
            relation.setWeight(0.0);
            taoBaoClassRelationMapper.insertSelective(relation);
        }
    }
 
    @Override
    public List<TaoBaoClass> listBySystemSubCid(long start, int count, Long systemSubCid) {
 
        return taoBaoClassMapper.listBySystemSubCid(start, count, systemSubCid);
    }
 
}