admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/push/DeviceTokenHWServiceImpl.java
@@ -1,106 +1,106 @@
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 org.springframework.transaction.annotation.Transactional;
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, List<Integer> versionList, Date minUpdateTime) {
        return deviceTokenHWMapper.selectList((page - 1) * pageSize, pageSize, minUpdateTime, versionList);
    }
    @Override
    public Long countDeviceToken(List<Integer> versionList,Date minUpdateTime) {
        Long count = deviceTokenHWMapper.selectCount(versionList,minUpdateTime);
        return count == null ? 0 : count;
    }
    @Transactional
    @Override
    public void addDeviceToken(String token, String device, Long uid, int version) {
        if (StringUtil.isNullOrEmpty(device))
            return;
        //
        if (uid != null && uid == 0)
            uid = null;
        List<DeviceTokenHW> list = deviceTokenHWMapper.selectByDeviceForUpdate(device);
        if (list == null || list.size() == 0) {
            DeviceTokenHW deviceTokenHW = new DeviceTokenHW();
            deviceTokenHW.setDevice(device);
            deviceTokenHW.setDeviceToken(token);
            deviceTokenHW.setDeviceTokenMd5(StringUtil.Md5(token));
            deviceTokenHW.setVersion(version);
            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.setVersion(version);
                }
                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, null);
    }
    @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);
    }
    @Override
    public List<DeviceTokenHW> getDeviceTokenByUid(Long uid, List<Integer> versionList) {
        if (uid == null)
            return null;
        if (versionList != null && versionList.size() == 0)
            return null;
        return deviceTokenHWMapper.selectByUid(uid, versionList);
    }
}
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 org.springframework.transaction.annotation.Transactional;
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, List<Integer> versionList, Date minUpdateTime) {
        return deviceTokenHWMapper.selectList((page - 1) * pageSize, pageSize, minUpdateTime, versionList);
    }
    @Override
    public Long countDeviceToken(List<Integer> versionList,Date minUpdateTime) {
        Long count = deviceTokenHWMapper.selectCount(versionList,minUpdateTime);
        return count == null ? 0 : count;
    }
    @Transactional
    @Override
    public void addDeviceToken(String token, String device, Long uid, int version) {
        if (StringUtil.isNullOrEmpty(device))
            return;
        //
        if (uid != null && uid == 0)
            uid = null;
        List<DeviceTokenHW> list = deviceTokenHWMapper.selectByDeviceForUpdate(device);
        if (list == null || list.size() == 0) {
            DeviceTokenHW deviceTokenHW = new DeviceTokenHW();
            deviceTokenHW.setDevice(device);
            deviceTokenHW.setDeviceToken(token);
            deviceTokenHW.setDeviceTokenMd5(StringUtil.Md5(token));
            deviceTokenHW.setVersion(version);
            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.setVersion(version);
                }
                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, null);
    }
    @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);
    }
    @Override
    public List<DeviceTokenHW> getDeviceTokenByUid(Long uid, List<Integer> versionList) {
        if (uid == null)
            return null;
        if (versionList != null && versionList.size() == 0)
            return null;
        return deviceTokenHWMapper.selectByUid(uid, versionList);
    }
}