package com.taoke.autopay.service.impl;
|
|
import com.taoke.autopay.dao.ClientAdditionalInfoMapper;
|
import com.taoke.autopay.entity.ClientAdditionalInfo;
|
import com.taoke.autopay.entity.SystemConfigKeyEnum;
|
import com.taoke.autopay.exception.LoginException;
|
import com.taoke.autopay.service.ClientAdditionalInfoService;
|
import com.taoke.autopay.service.SystemConfigService;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* 客户端附加信息服务
|
*/
|
@Service
|
public class ClientAdditionalInfoServiceImpl implements ClientAdditionalInfoService {
|
@Resource
|
private ClientAdditionalInfoMapper clientAdditionalInfoMapper;
|
|
@Resource
|
private SystemConfigService systemConfigService;
|
|
/**
|
* 增加客户端附加信息
|
*
|
* @param clientAdditionalInfo 客户端附加信息
|
* @return 是否添加成功
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean addClientAdditionalInfo(ClientAdditionalInfo clientAdditionalInfo) {
|
if (clientAdditionalInfo == null) {
|
return false;
|
}
|
clientAdditionalInfo.setCreateTime(new Date());
|
clientAdditionalInfo.setUpdateTime(new Date());
|
return clientAdditionalInfoMapper.insert(clientAdditionalInfo) > 0;
|
}
|
|
/**
|
* 更新客户端附加信息
|
*
|
* @param clientAdditionalInfo 客户端附加信息
|
* @return 是否更新成功
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public boolean updateClientAdditionalInfo(ClientAdditionalInfo clientAdditionalInfo) {
|
if (clientAdditionalInfo == null || clientAdditionalInfo.getId() == null) {
|
return false;
|
}
|
clientAdditionalInfo.setUpdateTime(new Date());
|
return clientAdditionalInfoMapper.updateByPrimaryKey(clientAdditionalInfo) > 0;
|
}
|
|
/**
|
* 根据设备ID列表获取信息的map
|
*
|
* @param clientIds 设备ID列表
|
* @return 客户端附加信息映射Map,key为客户端ID,value为客户端附加信息
|
*/
|
@Override
|
public Map<Long, ClientAdditionalInfo> getClientAdditionalInfoMap(List<Long> clientIds) {
|
if (clientIds == null || clientIds.isEmpty()) {
|
return new HashMap<>();
|
}
|
List<ClientAdditionalInfo> clientAdditionalInfos = clientAdditionalInfoMapper.listByIds(clientIds);
|
return clientAdditionalInfos.stream()
|
.collect(Collectors.toMap(ClientAdditionalInfo::getId, info -> info));
|
}
|
|
/**
|
* 根据设备ID获取信息
|
*
|
* @param clientId 设备ID
|
* @return 客户端附加信息
|
*/
|
@Override
|
public ClientAdditionalInfo getClientAdditionalInfoByClientId(Long clientId) {
|
if (clientId == null) {
|
return null;
|
}
|
return clientAdditionalInfoMapper.selectByPrimaryKey(clientId);
|
}
|
}
|