wang-hao-jie
2022-08-25 57dcc73636bb7d8dce89c808eb8cc988a7512264
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
package com.ruoyi.web.controller.station;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.IdUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.station.domain.MjDoor;
import com.ruoyi.station.service.IMjDoorService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.station.domain.MjHnweEvent;
import com.ruoyi.station.service.IMjHnweEventService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * 霍尼韦尔事件Controller
 * 
 * @author ruoyi
 * @date 2020-09-18
 */
@Controller
@RequestMapping("/station/event")
public class MjHnweEventController extends BaseController
{
    private String prefix = "station/event";
 
    @Autowired
    private IMjHnweEventService mjHnweEventService;
    @Autowired
    private IMjDoorService doorService;
 
    @GetMapping()
    public String event()
    {
        return prefix + "/event";
    }
 
    /**
     * 查询霍尼韦尔事件列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MjHnweEvent mjHnweEvent)
    {
        startPage();
        List<MjHnweEvent> list = mjHnweEventService.selectMjHnweEventList(mjHnweEvent);
        TableDataInfo dataTable = getDataTable(list);
        HttpServletRequest request = getRequest();
        String pageNum = request.getParameter("pageNum");
        dataTable.setPage(Integer.valueOf(pageNum));
        return dataTable;
    }
 
    /**
     * 导出霍尼韦尔事件列表
     */
    @RequiresPermissions("station:event:export")
    @Log(title = "霍尼韦尔事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MjHnweEvent mjHnweEvent)
    {
        List<MjHnweEvent> list = mjHnweEventService.selectMjHnweEventList(mjHnweEvent);
        ExcelUtil<MjHnweEvent> util = new ExcelUtil<MjHnweEvent>(MjHnweEvent.class);
        return util.exportExcel(list, "event");
    }
 
    /**
     * 新增霍尼韦尔事件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }
 
    /**
     * 新增保存霍尼韦尔事件
     */
    @PostMapping("/add")
    @ResponseBody
    public Object addSave(String content, HttpServletRequest request) throws IOException {
        //System.out.println("1=========="+request.getParameter("content"));
        request.setCharacterEncoding("utf-8");
        BufferedReader br = request.getReader();
        String str, wholeStr = "";
        while((str = br.readLine()) != null){
            wholeStr += str;
        }
        //System.out.println("2=========="+wholeStr);
        //System.out.println("3=========="+content);
 
        //String s = "raw:"+wholeStr;
 
        JSONObject jsonObject = JSON.parseObject(wholeStr);
        if(jsonObject.get("EventID")==null){
            return toAjax(false);
        }
        String eventID = jsonObject.get("EventID").toString();
        String hid = jsonObject.get("HID").toString();
        MjHnweEvent event = new MjHnweEvent();
        event.setCardHolderName(URLDecoderString(jsonObject.get("Card_Holder_Name").toString()));
        event.setCardNo(jsonObject.get("Card_No").toString());
        event.setCnt(jsonObject.get("Cnt").toString());
        event.setCommserverId(jsonObject.get("CommServerID").toString());
        event.setDeviceId(jsonObject.get("DeviceID").toString());
        event.setEventId(eventID);
        event.setHid(hid);
        event.setId(IdUtils.fastSimpleUUID());
        event.setStatus(URLDecoderString(jsonObject.get("Status").toString()));
        //event.setIdx(jsonObject.get("idx").toString());
        event.setNote(URLDecoderString(jsonObject.get("Note").toString()));
        event.setPrio(jsonObject.get("Prio").toString());
        event.setReaderPoint(URLDecoderString(jsonObject.get("Reader_Point").toString()));
        event.setSite(URLDecoderString(jsonObject.get("Site").toString()));
 
        MjDoor mjDoors = doorService.selectMjDoorByHid(hid);
        if(mjDoors!=null){
            event.setIdx(mjDoors.getId());
            if(eventID.equals("719")) {
                mjDoors.setExpandStatus(0);
                doorService.updateMjDoor(mjDoors);
            }
            if(eventID.equals("721")) {
                mjDoors.setExpandStatus(1);
                doorService.updateMjDoor(mjDoors);
            }
 
        }
        mjHnweEventService.insertMjHnweEvent(event);
 
        return toAjax(true);
        //return s;
    }
 
    public static String URLDecoderString(String str) {
        String result = "";
        if (null == str) {
            return "";
        }
        try {
            result = java.net.URLDecoder.decode(str, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }
 
    /**
     * 修改霍尼韦尔事件
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MjHnweEvent mjHnweEvent = mjHnweEventService.selectMjHnweEventById(id);
        mmap.put("mjHnweEvent", mjHnweEvent);
        return prefix + "/edit";
    }
 
    /**
     * 修改保存霍尼韦尔事件
     */
    @RequiresPermissions("station:event:edit")
    @Log(title = "霍尼韦尔事件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MjHnweEvent mjHnweEvent)
    {
        return toAjax(mjHnweEventService.updateMjHnweEvent(mjHnweEvent));
    }
 
    /**
     * 删除霍尼韦尔事件
     */
    @RequiresPermissions("station:event:remove")
    @Log(title = "霍尼韦尔事件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mjHnweEventService.deleteMjHnweEventByIds(ids));
    }
}