张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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;
        }
    }
}