yujian
2019-12-16 3b956ac2380929552bd53fad5a9a0515a3b0d62f
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
package com.yeshi.fanli.service.impl.brand;
 
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.fanli.dao.mybatis.brand.BrandInfoRecordMapper;
import com.yeshi.fanli.entity.brand.BrandInfo;
import com.yeshi.fanli.entity.brand.BrandInfoRecord;
import com.yeshi.fanli.service.inter.brand.BrandInfoRecordService;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class BrandInfoRecordServiceImpl implements BrandInfoRecordService {
    
    @Resource
    private BrandInfoRecordMapper brandInfoRecordMapper;
 
    
    @Override
    @Transactional
    public void deleteRecord(List<String> list, Long uid, String device) {
        if (list == null || list.size() == 0)
            return;
        
        if ((uid == null || uid == 0) && StringUtil.isNullOrEmpty(device))
            return;
        
        // 优先用户为主
        if (uid != null && uid > 0)
            device = null;
        
        for (String brandId: list) {
            brandInfoRecordMapper.updateState(Long.parseLong(brandId), uid, device);
        }
    }
    
    @Async()
    @Override
    public void addRecord(Long brandId, Long uid, String device) {
        if (brandId == null || brandId == 0)
            return;
        
        if ((uid == null || uid == 0) && StringUtil.isNullOrEmpty(device))
            return;
        
        // 优先用户为主
        if (uid != null && uid > 0)
            device = null;
        
        BrandInfoRecord record = brandInfoRecordMapper.getRecord(brandId, uid, device);
        if (record != null) {
            BrandInfoRecord update = new BrandInfoRecord();
            update.setState(0);
            update.setId(record.getId());
            update.setUpdateTime(new Date());
            brandInfoRecordMapper.updateByPrimaryKeySelective(update);
        } else {
            record = new BrandInfoRecord();
            record.setUid(uid);
            record.setDevice(device);
            record.setBrandInfo(new BrandInfo(brandId));
            record.setCreateTime(new Date());
            record.setUpdateTime(new Date());
            brandInfoRecordMapper.insertSelective(record);
        }
    }
    
    @Override
    public List<BrandInfoRecord> listRecord(long start, int count, Long uid, String device) {
        if ((uid == null || uid == 0) && StringUtil.isNullOrEmpty(device))
            return null;
        
        // 优先用户为主
        if (uid != null && uid > 0)
            device = null;
        
        return brandInfoRecordMapper.listRecord(start, count, uid, device);
    }
 
    @Override
    public long countRecord(Long uid, String device) {
        if ((uid == null || uid == 0) && StringUtil.isNullOrEmpty(device))
            return 0;
        
        // 优先用户为主
        if (uid != null && uid > 0)
            device = null;
        return brandInfoRecordMapper.countRecord(uid, device);
    }
 
}