package com.gk.hotwork.Service.ServiceImpl;
|
|
import com.gk.hotwork.Domain.DeviceLocation;
|
import com.gk.hotwork.Domain.Exception.BusinessException;
|
import com.gk.hotwork.Domain.UserInfo;
|
import com.gk.hotwork.Domain.Utils.StringUtils;
|
import com.gk.hotwork.Mapper.DeviceLocationMapper;
|
import com.gk.hotwork.Service.DeviceLocationService;
|
import com.gk.hotwork.Service.UserService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Date;
|
import java.util.List;
|
|
@Service("deviceLocationService")
|
public class DeviceLocationServiceImpl implements DeviceLocationService {
|
|
@Autowired
|
private DeviceLocationMapper deviceLocationMapper;
|
@Autowired
|
private UserService userService;
|
|
|
@Override
|
public void insertRecord(DeviceLocation location) {
|
//根据locaiton的uid(设备Id)进行用户的对应
|
UserInfo user = userService.getByDeviceNo(location.getUid());
|
if (user == null)
|
throw new BusinessException("用户设备号不存在:"+location.getUid());
|
String slice = user.getSlice();
|
if (StringUtils.isBlank(slice))
|
throw new BusinessException("系统用户分表标识不存在");
|
deviceLocationMapper.insertOne(slice,location);
|
}
|
|
@Override
|
public DeviceLocation selectByUser(UserInfo user) {
|
if (user.getId() == null)
|
throw new BusinessException("用户信息不能为空");
|
if (StringUtils.isBlank(user.getSlice()))
|
throw new BusinessException("系统错误,用户分表标识为空");
|
return deviceLocationMapper.selectLatestUserLocation(user.getSlice(),user.getDeviceNo());
|
}
|
|
@Override
|
public List<DeviceLocation> selectUserLocations(String username, Date starttime, Date endtime) {
|
if (StringUtils.isBlank(username))
|
throw new BusinessException("用户名为空");
|
UserInfo userInfo = userService.selectByUser(username);
|
if (userInfo == null)
|
throw new BusinessException("用户信息不存在");
|
if (StringUtils.isBlank(userInfo.getSlice()))
|
throw new BusinessException("系统用户分表标识不存在");
|
|
return deviceLocationMapper.selectUserLocations(userInfo.getSlice(),userInfo.getDeviceNo(),starttime,endtime);
|
}
|
|
@Override
|
public void cleanUp(Integer sliceSize,Integer days) {
|
for (int i = 1; i <= sliceSize; i++) {
|
deviceLocationMapper.deleteRecordBeforeDays(i + "", days);
|
}
|
}
|
}
|