3.7
fxl
2023-03-07 632a18ee7c83441a6036b90577424d2daad8d19c
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
package com.hxzkoa.controller;
 
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 
import com.hxzkoa.json.R;
import com.hxzkoa.json.tb_system;
import com.hxzkoa.services.HelmetService;
import com.hxzkoa.services.SysSettingService;
import com.hxzkoa.tools.SocketUtil;
 
@Controller
public class HelmetController {
    
    @Autowired
    HelmetService helmetService;
    @Autowired
    SysSettingService sysSettingService;
    
    @ResponseBody
    @RequestMapping(value="warning.do",method={RequestMethod.POST,RequestMethod.GET})
    public R warning(HttpServletRequest request) {
        String tagid = request.getParameter("tagid");
        String type = request.getParameter("type");
        switch(type) {
        case "offhat":
            helmetService.offhat(tagid, "1");
            break;
        case "smash":
            helmetService.smash(tagid, "1");
            break;
        case "stopmoving":
            helmetService.stopmoving(tagid,"1");
            break;
        case "high":
            helmetService.high(tagid,"1");
            break;
        case "nearele":
            helmetService.nearele(tagid,"1");
        }
        return R.ok();
    }
    
    @ResponseBody
    @RequestMapping(value="video.do",method={RequestMethod.POST})
    public R video(MultipartFile file,HttpServletRequest request) {
        String tagid = request.getParameter("tagid");
        File filen = new File(request.getServletContext().getRealPath("/")+"hxzk\\image\\video\\"+tagid+"."+file.getContentType().split("/")[1]);
        if (!file.isEmpty()) {
            try {
                file.transferTo(filen);
                helmetService.video(tagid, tagid+"."+file.getContentType().split("/")[1]);
                return R.ok();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else {
            return R.error("文件不能为空");
        }
    }
 
    @ResponseBody
    @RequestMapping(value="audio.do",method={RequestMethod.POST})
    public R audio(MultipartFile file,HttpServletRequest request) {
        String tagid = request.getParameter("tagid");
        File filen = new File(request.getServletContext().getRealPath("/")+"hxzk\\image\\audio\\"+tagid+"."+file.getContentType().split("/")[1]);
        if (!file.isEmpty()) {
            try {
                file.transferTo(filen);
                helmetService.audio(tagid, tagid+"."+file.getContentType().split("/")[1]);
                return R.ok();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else {
            return R.error("文件不能为空");
        }
    }
    
    @ResponseBody
    @RequestMapping(value="setgps.do",method={RequestMethod.POST})
    public R setgps(HttpServletRequest request) {
        String tagid = request.getParameter("tagid");
        String lon = request.getParameter("lon");
        String lat = request.getParameter("lat");
        helmetService.setgps(tagid,lon,lat);
        return R.ok();
    }
    
    @ResponseBody
    @RequestMapping(value="sendmsg.do", method={RequestMethod.POST,RequestMethod.GET})
    public R sendmsg(HttpServletRequest request) {
        String tagid = request.getParameter("tagid");
        String message = request.getParameter("message");
        message = tagid+":"+message;
        new SocketUtil().sendmsg(message);
        return R.ok();
    }
}