yujian
2019-12-19 626d711cb15896055c13fe344eb7fcc824589715
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
package com.yeshi.fanli.service.impl.homemodule;
 
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.homemodule.SpecialLabelMapMapper;
import com.yeshi.fanli.dao.mybatis.homemodule.SpecialLabelMapper;
import com.yeshi.fanli.entity.bus.homemodule.SpecialLabel;
import com.yeshi.fanli.entity.bus.homemodule.SpecialLabelMap;
import com.yeshi.fanli.exception.homemodule.SpecialLabelException;
import com.yeshi.fanli.service.inter.homemodule.SpecialLabelService;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class SpecialLabelImpl implements SpecialLabelService {
 
    @Resource
    private SpecialLabelMapper specialLabelMapper;
    
    @Resource
    private SpecialLabelMapMapper specialLabelMapMapper;
    
    
    @Override
    public void save(SpecialLabel record) throws SpecialLabelException{
        String name = record.getName();
        if (StringUtil.isNullOrEmpty(name))
            throw new SpecialLabelException(1, "名称不能为空");
        
        String bgColor = record.getBgColor();
        if (StringUtil.isNullOrEmpty(bgColor))
            throw new SpecialLabelException(1, "背景色不能为空");
        
        if (record.getState() == null)
            record.setState(0);
        
        record.setUpdateTime(new Date());
        
        Long id = record.getId();
        if (id == null) {
            record.setCreateTime(new Date());
            specialLabelMapper.insert(record);
        } else {
            SpecialLabel resultObj = specialLabelMapper.selectByPrimaryKey(id);
            if (resultObj == null)
                throw new SpecialLabelException(1, "操作内容已不存在");
 
            record.setCreateTime(resultObj.getCreateTime());
            specialLabelMapper.updateByPrimaryKey(record);
        }
    }
    
 
    @Override
    public int deleteByPrimaryKeyBatch(List<Long> list){
        return specialLabelMapper.deleteByPrimaryKeyBatch(list);
    }
 
    
 
    @Override
    public List<SpecialLabel> listQuery(long start, int count, String key, Integer state) {
        return specialLabelMapper.listQuery(start, count, key, state);
    }
 
 
    @Override
    public long countQuery(String key, Integer state) {
        return specialLabelMapper.countQuery(key, state);
    }
 
    @Override
    public List<SpecialLabel> getLabelsBySpecialId(Long specialId) {
        return specialLabelMapper.getLabelsBySpecialId(specialId);
    }
 
    
    @Override
    @Transactional(rollbackFor= Exception.class)
    public void stickLabelOnSpecial(List<Long> idList, List<Long> labIdList) {
        if (idList == null || idList.isEmpty())
            return;
        
        // 清空标签
        specialLabelMapMapper.deleteBySpecialIds(idList);
        
        if (labIdList == null || labIdList.isEmpty()) {
            return;
        }
        
        // 新增标签
        Date date = new Date();
        for (Long id:idList) {
            for (Long labid:labIdList) {
                SpecialLabelMap objectMap = new SpecialLabelMap();
                objectMap.setLabId(labid);
                objectMap.setSpid(id);
                objectMap.setCreateTime(date);
                specialLabelMapMapper.insertSelective(objectMap);
            }
        }
    }
    
}