package com.thhy.materials.modules.biz.gpsdevice.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.thhy.general.config.SysUserInfo;
|
import com.thhy.general.utils.UserInfoUtils;
|
import com.thhy.materials.modules.biz.gpsdevice.entity.GpsDevice;
|
import com.thhy.materials.modules.biz.gpsdevice.entity.GpsDeviceDto;
|
import com.thhy.materials.modules.biz.gpsdevice.entity.GpsDto;
|
import com.thhy.materials.modules.biz.gpsdevice.entity.PipeOutInfo;
|
import com.thhy.materials.modules.biz.gpsdevice.mapper.GpsDeviceMapper;
|
import com.thhy.materials.modules.biz.gpsdevice.service.GpsDeviceService;
|
import com.thhy.materials.modules.biz.gpshis.entity.GpsHistory;
|
import com.thhy.materials.modules.biz.gpshis.mapper.GpsHistoryMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.io.Serializable;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* 服务实现类
|
* @author zhang_xiao_bo
|
* @since 2023-08-25 11:22:58
|
*/
|
@Service
|
public class GpsDeviceServiceImpl implements GpsDeviceService {
|
|
|
|
@Autowired
|
private GpsDeviceMapper gpsDeviceMapper;
|
|
@Autowired
|
private GpsHistoryMapper historyMapper;
|
|
public GpsDevice get(Serializable id){
|
return gpsDeviceMapper.queryById(id);
|
}
|
|
public List<GpsDevice> findList(GpsDevice gpsDevice){
|
SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
|
if(gpsDevice==null) gpsDevice = new GpsDevice();
|
gpsDevice.setCompanyId(userInfo.getCompanyId());
|
return gpsDeviceMapper.findList(gpsDevice);
|
}
|
|
@Override
|
public List<GpsDevice> findAll(GpsDeviceDto gpsDeviceDto) {
|
SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
|
if(gpsDeviceDto==null) gpsDeviceDto = new GpsDeviceDto();
|
gpsDeviceDto.setCompanyId(userInfo.getCompanyId());
|
return gpsDeviceMapper.findAll(gpsDeviceDto);
|
}
|
|
/**
|
* 增加和修改
|
* @param gpsDevice
|
*/
|
@Transactional
|
public void addGpsDevice(GpsDevice gpsDevice){
|
SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
|
if(gpsDevice.getGdId() == null){
|
//增加操作
|
gpsDevice.setCompanyId(userInfo.getCompanyId());
|
gpsDevice.setCreateUser(userInfo.getUserId());
|
gpsDeviceMapper.insert(gpsDevice);
|
}else{
|
//修改操作
|
gpsDeviceMapper.update(gpsDevice);
|
}
|
|
}
|
|
/**
|
* 修改
|
* @param gpsDevice
|
*/
|
public void update(GpsDevice gpsDevice){
|
gpsDeviceMapper.update(gpsDevice);
|
}
|
|
/**
|
* 删除
|
* @param gdId
|
*/
|
public void delete(Serializable gdId){
|
gpsDeviceMapper.deletelogic(gdId);
|
}
|
|
@Override
|
public List<GpsHistory> gpsView(GpsDto gpsDto) {
|
PipeOutInfo pipeOutInfo = gpsDeviceMapper.queryOut(gpsDto.getPipeOutId());
|
if(pipeOutInfo.getEndTime().getTime()<new Date().getTime()){
|
//视为已结束
|
GpsHistory gpsHistory = new GpsHistory();
|
gpsHistory.setPipeOutId(gpsDto.getPipeOutId());
|
gpsHistory.setImei(pipeOutInfo.getGdImei());
|
List<GpsHistory> historyList = historyMapper.findList(gpsHistory);
|
return historyList;
|
}else{
|
Map<String,Object> map = new HashMap<>();
|
map.put("imei",pipeOutInfo.getGdImei());
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
map.put("startTime",sdf.format(pipeOutInfo.getStartTime()));
|
map.put("endTime",sdf.format(pipeOutInfo.getEndTime()));
|
map.put("locTypes",0);
|
map.put("pageSize",100);
|
// String result = GpsUtils.lochistory(map);
|
// JSONObject resultJson = JSON.parseObject(result);
|
// if(resultJson.containsKey("code")&&resultJson.getInteger("code")==0){
|
// List<GpsHistory> historyList = JSONArray.parseArray(resultJson.getString("data"), GpsHistory.class);
|
// for(GpsHistory gpsHistory : historyList){
|
// gpsHistory.setPipeOutId(gpsDto.getPipeOutId());
|
// gpsHistory.setGpsTimeStr(sdf.format(gpsHistory.getGpsTime()));
|
// historyMapper.insert(gpsHistory);
|
// }
|
// return historyList;
|
// }else{
|
// return new ArrayList<>();
|
// }
|
return null;
|
}
|
}
|
}
|