艾金辉
2023-07-21 c7fe55130816044f71f423727fc8ef734dfae13a
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package com.ruoyi.sy.controller;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.ruoyi.client.ARDCarGPSLogInClient;
import com.ruoyi.client.ARDCarSYGPSClient;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.sy.service.IArdSyUserService;
import com.ruoyi.sy.service.SysParaService;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.utils.httpclient.SYCarClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.bytedeco.javacv.CanvasFrame;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sy.domain.ArdSyCar;
import com.ruoyi.sy.service.IArdSyCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * 三一车辆Controller
 * 
 * @author ard
 * @date 2023-06-26
 */
@RestController
@RequestMapping("/sy/syCar")
@Api(tags = "三一车辆管理接口")
public class ArdSyCarController extends BaseController
{
    @Autowired
    private IArdSyCarService ardSyCarService;
 
    @Autowired
    private ISysConfigService sysConfigService;
 
    private Map<Integer,Map<String,String>> logInMap = new HashMap();
 
    @Autowired
    private SysParaService sysParaService;
 
    @Autowired
    private IArdSyUserService iArdSyUserService;
 
    /**
     * 查询三一车辆列表
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArdSyCar ardSyCar)
    {
        startPage();
        List<ArdSyCar> list = ardSyCarService.selectArdSyCarList(ardSyCar);
        return getDataTable(list);
    }
 
    /**
     * 导出三一车辆列表
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:export')")
    @Log(title = "三一车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArdSyCar ardSyCar)
    {
        List<ArdSyCar> list = ardSyCarService.selectArdSyCarList(ardSyCar);
        ExcelUtil<ArdSyCar> util = new ExcelUtil<ArdSyCar>(ArdSyCar.class);
        util.exportExcel(response, list, "三一车辆数据");
    }
 
    /**
     * 获取三一车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ardSyCarService.selectArdSyCarById(id));
    }
 
    /**
     * 新增三一车辆
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:add')")
    @Log(title = "三一车辆", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增三一车辆")
    public AjaxResult add(@RequestBody ArdSyCar ardSyCar)
    {
        String id = IdUtils.simpleUUID();
        ardSyCar.setId(id);
        return toAjax(ardSyCarService.insertArdSyCar(ardSyCar));
    }
 
    /**
     * 修改三一车辆
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:edit')")
    @Log(title = "三一车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改三一车辆")
    public AjaxResult edit(@RequestBody ArdSyCar ardSyCar)
    {
        return toAjax(ardSyCarService.updateArdSyCar(ardSyCar));
    }
 
    /**
     * 删除三一车辆
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:remove')")
    @Log(title = "三一车辆", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除三一车辆")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ardSyCarService.deleteArdSyCarByIds(ids));
    }
 
    /**
     * 获取三一车辆登录信息
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:loginSY')")
    @PostMapping("/loginSY")
    @ApiOperation("获取三一车辆登录信息")
    public Map<String,Object> loginSY(@RequestBody Map<String,String> map){
        //startPage();
        String userId = map.get("userId");
        String password = map.get("password");
        SysConfig config = new SysConfig();
        config.setConfigKey("syCarPT");
        List<SysConfig> sysConfigResult = sysConfigService.selectConfigList(config);
        String syURL = "";
        if(sysConfigResult.size() == 0){
            return error("三一车辆url没有录入");
        }else{
            syURL = sysConfigResult.get(0).getConfigValue();
            Map<String,Object> result = SYCarClient.logIn(syURL,userId, password);
            return success(result);
        }
    }
 
    /**
     * 获取未挂接权限的三一车辆
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarNoRight')")
    @PostMapping("/getArdSyCarNoRight")
    @ApiOperation("获取未挂接权限的三一车辆")
    public Map<String,Object> getArdSyCarNoRight(){
        String userId = SecurityUtils.getUserId();
        Map<String,Object> result = ardSyCarService.getArdSyCarNoRight(userId);
        if(((String)result.get("code")).equals("500")){
            return error((String) result.get("data"));
        }else if(((String)result.get("code")).equals("200")){
            return success(result.get("data"));
        }else{
            return error("");
        }
    }
 
    /**
     * 获取全部的三一车辆
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:getArdSyCarAll')")
    @PostMapping("/getArdSyCarAll")
    @ApiOperation("获取全部的三一车辆")
    public Map<String,Object> getArdSyCarAll(){
        String userId = SecurityUtils.getUserId();
        Map<String,Object> result = ardSyCarService.getArdSyCarAll(userId);
        if(((String)result.get("code")).equals("500")){
            return error((String) result.get("data"));
        }else if(((String)result.get("code")).equals("200")){
            return success(result.get("data"));
        }else{
            return error("");
        }
    }
 
    /**
     * 获取全部车辆模型
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:getAllCarModel')")
    @PostMapping("/getAllCarModel")
    @ApiOperation("获取全部车辆模型")
    public Map<String,Object> getAllCarModel(){
        try{
            List<Map<String,String>> result = ardSyCarService.getAllCarModel();
            return toAjaxList(result);
        } catch(Exception e){
            return toAjaxList(new ArrayList());
        }
    }
 
    /**
     * 上传车辆图片
     */
    @PreAuthorize("@ss.hasPermi('sy:syCar:uploadCarPicture')")
    @PostMapping("/uploadCarPicture")
    @ApiOperation("上传车辆图片")
    public Map<String,Object> uploadCarPicture(@RequestParam(value = "id",required = false,defaultValue = "") String id,@RequestParam("carPicture") MultipartFile carPicture){
        try{
            String result = ardSyCarService.uploadCarPicture(id,carPicture);
            return success(result);
        } catch(Exception e){
            return error("");
        }
    }
 
    @PreAuthorize("@ss.hasPermi('sy:syCar:allListByUser')")
    @PostMapping("allListByUser")
    @ApiOperation("根据用户获取三一列表")
    public Map<String,Object> allListByUser(){
        String usersId = SecurityUtils.getUserId();
        Map<String, String> result = logInMap.get(Integer.parseInt(usersId));
        String syURL = sysParaService.getSYURL();
        if(result == null){
            Map<String,Object> m = iArdSyUserService.selectArdSyUserByUsersId(Integer.parseInt(usersId));
            if(m == null){
                Map<String,Object> map0 = new HashMap();
                map0.put("rspDesc", "当前登录用户未挂接车辆权限");
                map0.put("rspCode", "0");
                return map0;
            }
            Map<String, Object> result0 = ARDCarGPSLogInClient.loginIn(syURL,(String) m.get("userId"), (String) m.get("password"));
            result = new HashMap();
            result.put("userId", (String) m.get("userId"));
            result.put("sessionId", (String) result0.get("sessionId"));
        }
        Map<String,Object> result0 = new HashMap();
        try {
            result0 = ARDCarSYGPSClient.getCarGPSTeamList(syURL,result.get("userId"),result.get("sessionId"));//
        } catch (Exception e) {
            Map<String,Object> map = new HashMap();
            map.put("rspCode", 0);
            map.put("list", new ArrayList());
            return map;
        }
        int online = 0;
        for(Map<String,Object> map : (List<Map<String,Object>>) result0.get("list")){
            Map<String,Object> resultMap = (Map<String, Object>) ARDCarSYGPSClient.getCarListByTeamId(syURL,(String)map.get("teamId"),result.get("sessionId"));
            List<Map<String,Object>> carList = (List<Map<String, Object>>) resultMap.get("carList");
            for(Map<String,Object> m : carList){
                if(((String) m.get("stateCn")).contains("在线")){
                    online = online + 1;
                }else{
                    continue;
                }
            }
            for(Map<String,Object> m : (List<Map<String,Object>>) result0.get("list")){
                if(((String) m.get("teamId")).equals(((String) map.get("teamId")))){
                    map.put("count", Integer.parseInt((String) m.get("carNum")));
                }
            }
            map.put("online", online);
            online = 0;
        }
        return result0;
    }
 
    @PreAuthorize("@ss.hasPermi('sy:syCar:carListById')")
    @GetMapping("carListById")
    @ApiOperation("根据车辆ID获取车辆列表")
    public List<ArdSyCar> carListById(String id){
        return ardSyCarService.carListById(id);
    }
}