admin
2019-06-28 455c7eddac87682e76d0168891be16a8ab1820d2
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
package com.yeshi.fanli.service.impl.clazz;
 
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.fanli.dao.mybatis.clazz.GoodsSubClassLabelMapMapper;
import com.yeshi.fanli.dao.mybatis.clazz.GoodsSubClassLabelMapper;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClassLabel;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClassLabelMap;
import com.yeshi.fanli.exception.GoodsClassException;
import com.yeshi.fanli.service.inter.clazz.GoodsSubClassLabelService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.vo.goods.GoodsSubClassLabelVO;
 
@Service
public class GoodsSubClassLabelServiceImpl implements GoodsSubClassLabelService {
 
    @Resource
    private GoodsSubClassLabelMapper goodsSubClassLabelMapper;
 
    @Resource
    private GoodsSubClassLabelMapMapper goodsSubClassLabelMapMapper;
 
    @Override
    public void addSubClassLabel(GoodsSubClassLabel label) throws GoodsClassException {
 
        if (label == null || label.getGoodsClass() == null || StringUtil.isNullOrEmpty(label.getName()))
            throw new GoodsClassException(1, "数据不完整");
        GoodsSubClassLabel oldLabel = goodsSubClassLabelMapper.selectByClassIdAndName(label.getName(),
                label.getGoodsClass().getId());
        if (oldLabel != null)
            throw new GoodsClassException(2, "分类标签名称已经存在");
        label.setCreateTime(new Date());
        goodsSubClassLabelMapper.insertSelective(label);
    }
 
    @Override
    public void addSubClassLabelMap(GoodsSubClassLabelMap map) throws GoodsClassException {
        if (map.getGoodsSubClass() == null || map.getLabel() == null)
            throw new GoodsClassException(1, "数据不完整");
 
        GoodsSubClassLabelMap oldMap = goodsSubClassLabelMapMapper.selectByLabelIdAndSubClassId(map.getLabel().getId(),
                map.getGoodsSubClass().getId());
        if (oldMap != null)
            throw new GoodsClassException(2, "对应关系已经存在");
        // 通过subClassId查询
 
        GoodsSubClassLabelMap omap = goodsSubClassLabelMapMapper.selectBySubClassId(map.getGoodsSubClass().getId());
        if (omap != null)
            goodsSubClassLabelMapMapper.deleteByPrimaryKey(omap.getId());
 
        map.setCreateTime(new Date());
        goodsSubClassLabelMapMapper.insertSelective(map);
    }
 
    @Override
    public List<GoodsSubClassLabel> listLabelByClassId(Long classId) {
 
        return goodsSubClassLabelMapper.listByClassId(classId);
    }
 
    @Override
    public List<GoodsSubClassLabelMap> listMapByLabelId(Long labelId) {
        return goodsSubClassLabelMapMapper.listMapByLabelId(labelId);
    }
 
    @Transactional
    @Override
    public void deleteLabel(Long labelId) {
 
        List<GoodsSubClassLabelMap> maplist = listMapByLabelId(labelId);
        if (maplist != null)
            for (GoodsSubClassLabelMap map : maplist) {
                goodsSubClassLabelMapMapper.deleteByPrimaryKey(map.getId());
            }
        goodsSubClassLabelMapper.deleteByPrimaryKey(labelId);
    }
 
    @Override
    public void updateSubClassLabel(GoodsSubClassLabel label) {
        goodsSubClassLabelMapper.updateByPrimaryKeySelective(label);
    }
 
    @Override
    public GoodsSubClassLabelMap selectBySubClassId(Long subClassId) {
        return goodsSubClassLabelMapMapper.selectBySubClassId(subClassId);
    }
 
    @Override
    @Cacheable(value = "classCache", key = "'listSubMapCache-'+#classId")
    public List<GoodsSubClassLabelVO> listSubMapCache(Long classId) {
        List<GoodsSubClassLabelVO> list = goodsSubClassLabelMapper.listSubMapByClassId(classId,
                Calendar.getInstance().get(Calendar.MONTH) + 1);
        if (list == null || list.size() == 0) {
            return list;
        }
 
        for (int i = 0; i < list.size(); i++) {
            GoodsSubClassLabelVO labelVO = list.get(i);
            List<GoodsSubClass> listSub = labelVO.getListSub();
            if (listSub == null || listSub.size() == 0) {
                list.remove(labelVO);
                i--;
                continue;
            }
 
            for (GoodsSubClass goodsSubClass : listSub) {
                String pictureSecond = goodsSubClass.getPictureSecond();
                if (!StringUtil.isNullOrEmpty(pictureSecond)) {
                    goodsSubClass.setPicture(pictureSecond);
                }
            }
 
            labelVO.setListSub(listSub);
        }
        return list;
    }
 
}