admin
2019-07-30 573c491b4a1ba60e12a5678a01c1546c0077c1ee
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
package com.yeshi.fanli.service.impl.push;
 
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.push.DeviceTokenHWMapper;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.push.DeviceTokenHW;
import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class DeviceTokenHWServiceImpl implements DeviceTokenHWService {
 
    @Resource
    private DeviceTokenHWMapper deviceTokenHWMapper;
 
    @Override
    public List<DeviceTokenHW> getDeviceTokenList(int page, int pageSize) {
        return deviceTokenHWMapper.selectList((page - 1) * pageSize, pageSize);
    }
 
    @Override
    public Long getDeviceTokenCount() {
        Long count = deviceTokenHWMapper.selectCount();
        return count == null ? 0 : count;
    }
 
    @Override
    public void addDeviceToken(String token, String device, Long uid) {
        if (StringUtil.isNullOrEmpty(device))
            return;
        //
        if (uid != null && uid == 0)
            uid = null;
 
        List<DeviceTokenHW> list = deviceTokenHWMapper.selectByDevice(device);
        if (list == null || list.size() == 0) {
            DeviceTokenHW deviceTokenHW = new DeviceTokenHW();
            deviceTokenHW.setDevice(device);
            deviceTokenHW.setDeviceToken(token);
            deviceTokenHW.setDeviceTokenMd5(StringUtil.Md5(token));
            deviceTokenHW.setUpdateTime(new Date());
            if (uid != null)
                deviceTokenHW.setUser(new UserInfo(uid));
            deviceTokenHWMapper.insertSelective(deviceTokenHW);
        } else {
            for (DeviceTokenHW deviceTokenHW : list) {
                DeviceTokenHW update = new DeviceTokenHW();
                update.setId(deviceTokenHW.getId());
                if (!StringUtil.isNullOrEmpty(token)) {
                    update.setDeviceToken(token);
                    update.setDeviceTokenMd5(StringUtil.Md5(token));
                }
                update.setUpdateTime(new Date());
                if (uid != null)
                    update.setUser(new UserInfo(uid));
                deviceTokenHWMapper.updateByPrimaryKeySelective(update);
            }
        }
    }
 
    @Override
    public List<DeviceTokenHW> getDeviceTokenByUid(Long uid) {
        if (uid == null)
            return null;
        return deviceTokenHWMapper.selectByUid(uid);
    }
 
    @Override
    public void unBindDeviceToken(String device) {
        List<DeviceTokenHW> list = deviceTokenHWMapper.selectByDevice(device);
        if (list == null || list.size() == 0)
            return;
        for (DeviceTokenHW deviceTokenHW : list) {
            deviceTokenHW.setUser(null);
            deviceTokenHW.setUpdateTime(new Date());
            deviceTokenHWMapper.updateByPrimaryKey(deviceTokenHW);
        }
    }
 
    @Override
    public void bindUid(String device, Long uid) {
        deviceTokenHWMapper.bindUidByDevice(uid, device);
    }
 
}