7.8
15832144755
2021-07-08 2080267e3245f0df9efc621c279922dc5ebb7c8e
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
package com.hxzkoa.controller;
 
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
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 com.hxzkoa.json.tb_achor;
import com.hxzkoa.json.tb_anchor_nearby;
import com.hxzkoa.json.tb_department;
import com.hxzkoa.json.tb_fence;
import com.hxzkoa.json.tb_shipin;
import com.hxzkoa.json.tb_tongbuanchor;
import com.hxzkoa.json.tb_xunjianbaobiao;
import com.hxzkoa.json.tb_xunjianset;
import com.hxzkoa.services.BasicInfoService;
import com.hxzkoa.services.FenceService;
import com.hxzkoa.services.LabelService;
import com.hxzkoa.udp.GetNowTime;
import com.hxzkoa.udp.Udp_Out;
/*import com.hxzkoa.udp.Udp_Receive;*/
import com.hxzkoa.util.Config;
import com.hxzkoa.util.ExcelUtils;
import com.hxzkoa.util.ModifyConfig;
import com.hxzkoa.util.PageUtil;
import com.hxzkoa.util.RequestUtils;
 
import net.sf.json.JSONObject;
 
@Controller
public class FenceController {
    @Autowired
    private FenceService fenceService;
    @Autowired
    private BasicInfoService basicInfoService;
    @Autowired
    private LabelService labelService;
 
    @RequestMapping(value = "/fenceList.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String fenceList(HttpServletRequest request) throws ParseException {
        String toPage = "forward:/hxzk/fence/fenceList.jsp";
        List<tb_fence> fenceList = fenceService.getFenceList();
        request.setAttribute("fenceList", fenceList);
        List<tb_department> department = basicInfoService.getAllDepartmentManagement();
        request.setAttribute("department", department);
        return toPage;
    }
    
    @RequestMapping(value = "/jiankongManagement.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String jiankongManagement(HttpServletRequest request) {
        String toPage = "forward:/hxzk/fence/jiankongManagement.jsp";
        List<tb_shipin> shipinManagementList = fenceService.getShipinManagement(1);
        request.setAttribute("shipinManagementList", shipinManagementList);
        List<tb_fence> fenceList = fenceService.getFenceList();
        request.setAttribute("fences", fenceList);
        int curPage = 1;
        int count = fenceService.getShipinManagementCount();
        int minPage = PageUtil.getMinPage(count);
        request.setAttribute("pageList", PageUtil.getPage(minPage));
        request.setAttribute("curPage", curPage);
        return toPage;
    }
    
    @RequestMapping(value = "/shipinManagement_add.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void shipinManagement_add(HttpServletRequest request) throws IOException {
            tb_shipin shipin = new tb_shipin();
            shipin.setFencename(request.getParameter("fencename"));
            shipin.setShebeiid(request.getParameter("shebeiid"));
            shipin.setTongdaoid(request.getParameter("tongdaoid"));
            fenceService.shipinManagement_add(shipin);
    }
    
    @RequestMapping(value = "/shipinManagement_modify.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void shipinManagement_modify(HttpServletRequest request) {
        tb_shipin shipin = new tb_shipin();
        String idstr = request.getParameter("id");
        idstr = idstr.replaceAll("\"", "");
        String[] id = idstr.split(",");
        shipin.setId(Integer.parseInt(id[0]));
        shipin.setFencename(request.getParameter("fencename"));
        shipin.setShebeiid(request.getParameter("shebeiid"));
        shipin.setTongdaoid(request.getParameter("tongdaoid"));
        System.out.print(shipin.getId());
        System.out.print(shipin.getFencename());
        System.out.print(shipin.getShebeiid());
        System.out.print(shipin.getTongdaoid());
        fenceService.shipinManagement_modify(shipin);
    }
    
    @ResponseBody
    @RequestMapping(value = "/shipinManagement_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void shipinManagement_delete(HttpServletRequest request) {
        String checkValStr = request.getParameter("checkVal");
        checkValStr = checkValStr.replaceAll("\"", "");
        String[] checkVal = checkValStr.split(",");
        fenceService.shipinManagement_delete(checkVal);
    }
    
    @ResponseBody
    @RequestMapping(value = "/shipinManagement_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void shipinManagement_deleteAll(HttpServletRequest request) {
        fenceService.shipinManagement_deleteAll();
    }
    
    @ResponseBody
    @RequestMapping(value = "/shipinManagement_search.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String shipinManagement_search(HttpServletRequest request) throws IOException {
        JSONObject json = new JSONObject();
        String input = request.getParameter("input");
        System.out.print(input);
        int curPage = 1;
        List<Integer> pageList = new ArrayList<Integer>();
        List<tb_shipin> shipinManagementList = fenceService.searchshipinManagement(input);
        pageList.add(1);
        json.put("dataList", shipinManagementList);
        json.put("pageList", pageList);
        json.put("curPage", curPage);
        System.out.print(json.toString());
        return json.toString();
    }
    
    @ResponseBody
    @RequestMapping(value = "/shipinManagement_page.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String shipinManagement_page(HttpServletRequest request) {
        String pageStr = request.getParameter("page");
        String curPageStr = request.getParameter("curPage");
        int count = fenceService.getShipinManagementCount();
        int minPage = PageUtil.getMinPage(count);
        int curPage = Integer.parseInt(curPageStr);
        int page = 1;
        if ("pre".equals(pageStr)) {
            if (curPage > 1) {
                page = curPage - 1;
            }
        } else if ("next".equals(pageStr)) {
            if (curPage < minPage) {
                page = curPage + 1;
            }
        } else {
            page = Integer.parseInt(pageStr);
        }
        List<tb_shipin> anchorManagementList = fenceService.getShipinManagement(page);
        List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
        JSONObject json = new JSONObject();
        json.put("dataList", anchorManagementList);
        json.put("pageList", pageList);
        json.put("curPage", page);
        return json.toString();
    }
 
    @RequestMapping(value = "/fenceList_modify.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void fenceList_modify(HttpServletRequest request) throws ParseException {
        tb_fence fence = new tb_fence();
        fence.setBumen(request.getParameter("bumen"));
        fence.setName(request.getParameter("name"));
        fence.setZuobiao(request.getParameter("zuobiao"));
        fence.setStart(request.getParameter("start"));
        fence.setStart(request.getParameter("stop"));
        fence.setId(Integer.parseInt(request.getParameter("id")));
        fenceService.fenceList_modify(fence);
        List<tb_fence> fenceListList = fenceService.searchFenceListid(fence.getId());
        String xieyi = "BSTOCS1,ALTERFENCE,"+fenceListList.get(0).getFloor()+","+fenceListList.get(0).getType()+","+fence.getBumen()+","+fence.getName()+","+fence.getZuobiao()+","+fenceListList.get(0).getShape()+","+fence.getStart()+","+fence.getStop()+","+fenceListList.get(0).getAddtime()+","+fenceListList.get(0).getColor()+",END";
        Udp_Out.udp_to_cs(xieyi);
    }
 
    @ResponseBody
    @RequestMapping(value = "/fenceList_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void fenceList_delete(HttpServletRequest request) throws NumberFormatException, ParseException {
        String checkValStr = request.getParameter("checkVal");
        checkValStr = checkValStr.replaceAll("\"", "");
        String[] checkVal = checkValStr.split(",");
        fenceService.fenceList_delete(checkVal);
        for (int i = 0; i < checkVal.length; i++) {
            List<tb_fence> fences = fenceService.searchFenceListid(Integer.parseInt(checkVal[i]));
            tb_fence fence = new tb_fence();
            fence = fences.get(0);
            String xieyi = "BSTOCS1,DELETEFECNCE,"+fence.getName()+",END";
            Udp_Out.udp_to_cs(xieyi);
        }
    }
 
    @ResponseBody
    @RequestMapping(value = "/fenceList_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void fenceList_deleteAll(HttpServletRequest request) {
        fenceService.fenceList_deleteAll();
        String xieyi = "BSTOCS1,DELETEALLFENCE,END";
        Udp_Out.udp_to_cs(xieyi);
    }
 
    @ResponseBody
    @RequestMapping(value = "/fenceList_search.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String fenceList_search(HttpServletRequest request) throws ParseException {
        String input = request.getParameter("input");
        List<tb_fence> fenceListList = fenceService.searchFenceList(input);
        JSONObject json = new JSONObject();
        json.put("dataList", fenceListList);
        return json.toString();
    }
 
    @RequestMapping(value = "/inspectionSettings.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String inspectionSettings(HttpServletRequest request) {
        String toPage = "forward:/hxzk/fence/inspectionSettings.jsp";
        List<tb_xunjianset> inspectionSettingsList = fenceService.getInspectionSettings();
        request.setAttribute("inspectionSettingsList", inspectionSettingsList);
        List<String> tagidList = labelService.getLabelManagementTagid();
        request.setAttribute("tagidList", tagidList);
        return toPage;
    }
 
    @RequestMapping(value = "/inspectionSettings_modify.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void inspectionRecord_modify(HttpServletRequest request) {
        tb_xunjianset xunjianset = new tb_xunjianset();
        xunjianset.setQuyu(request.getParameter("quyu"));
        xunjianset.setXunshu(request.getParameter("xunshu"));
        xunjianset.setTagid(request.getParameter("tagid"));
        xunjianset.setCishu(request.getParameter("cishu"));
        xunjianset.setNeedstoptime(request.getParameter("needstoptime"));
        xunjianset.setStoptime(request.getParameter("stoptime"));
        fenceService.inspectionSettings_modify(xunjianset);
        String xieyi = "BSTOCS1,ALTERXUNJIAN,"+xunjianset.getQuyu()+","+xunjianset.getStoptime()+","+xunjianset.getXunshu()+","+xunjianset.getTagid()+","+xunjianset.getNeedstoptime()+","+xunjianset.getCishu()+",END";
        Udp_Out.udp_to_cs(xieyi);
    }
    
    @RequestMapping(value = "/inspectionRecord.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String inspectionRecord(HttpServletRequest request) {
        String toPage = "forward:/hxzk/fence/inspectionRecord.jsp";
        String pagePath = Config.getPageConfig();
        Integer perPage = Integer.parseInt(ModifyConfig.readData(pagePath, "perPage"));
        List<tb_xunjianbaobiao> inspectionRecordList = fenceService.getInspectionRecord(1,perPage);
        request.setAttribute("inspectionRecordList", inspectionRecordList);
        int curPage = 1;
        int count = fenceService.getInspectionRecordCount();
        int minPage = PageUtil.getMinPage(count);
        request.setAttribute("pageList", PageUtil.getPage(minPage));
        request.setAttribute("curPage", curPage);
        request.setAttribute("perPage",perPage);
        return toPage;
    }
 
    @ResponseBody
    @RequestMapping(value = "/inspectionRecord_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void inspectionRecord_delete(HttpServletRequest request) {
        String checkValStr = request.getParameter("checkVal");
        checkValStr = checkValStr.replaceAll("\"", "");
        String[] checkVal = checkValStr.split(",");
        fenceService.inspectionRecord_delete(checkVal);
    }
 
    @ResponseBody
    @RequestMapping(value = "/inspectionRecord_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void inspectionRecord_deleteAll(HttpServletRequest request) {
        fenceService.inspectionRecord_deleteAll();
    }
 
    @ResponseBody
    @RequestMapping(value = "/inspectionRecord_search.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String inspectionRecord_search(HttpServletRequest request) {
        String input = request.getParameter("input");
        int curPage = 1;
        List<Integer> pageList = new ArrayList<Integer>();
        List<tb_xunjianbaobiao> inspectionRecordList = fenceService.searchInspectionRecord(input);
        pageList.add(1);
        JSONObject json = new JSONObject();
        json.put("dataList", inspectionRecordList);
        json.put("pageList", pageList);
        json.put("curPage", curPage);
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/inspectionRecord_page.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String inspectionRecord_page(HttpServletRequest request) {
        String pageStr = request.getParameter("page");
        String curPageStr = request.getParameter("curPage");
        int count = fenceService.getInspectionRecordCount();
        int minPage = PageUtil.getMinPage(count);
        int curPage = Integer.parseInt(curPageStr);
        int page = 1;
        if ("pre".equals(pageStr)) {
            if (curPage > 1) {
                page = curPage - 1;
            }
        } else if ("next".equals(pageStr)) {
            if (curPage < minPage) {
                page = curPage + 1;
            }
        } else {
            page = Integer.parseInt(pageStr);
        }
        String pagePath = Config.getPageConfig();
        Integer perPage = Integer.parseInt(ModifyConfig.readData(pagePath, "perPage"));
        List<tb_xunjianbaobiao> inspectionRecordList = fenceService.getInspectionRecord(page,perPage);
        List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
        JSONObject json = new JSONObject();
        json.put("dataList", inspectionRecordList);
        json.put("pageList", pageList);
        json.put("curPage", page);
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/inspectionRecord_export.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String fenceList_export(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        String toPage = "forward:/hxzk/fence/inspectionRecord.jsp";
        List<tb_xunjianbaobiao> tb_xunjianbaobiaoList = fenceService.getInspectionRecord();
        String[] rowName = { "序号", "姓名", "设备id", "区域名称", "区域序号", "进入时间", "出去时间", "停留时间/s", "是否完成巡检", "添加时间" };
        List<Object[]> dataList = objectToArray_inspectionRecord(tb_xunjianbaobiaoList);
        ExcelUtils excel = new ExcelUtils("巡检记录", rowName, dataList);
        OutputStream out;
        try {
            String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
            String headStr = "attachment; filename=\"" + fileName + "\"";
            response.setContentType("APPLICATION/OCTET-STREAM");
            response.setHeader("Content-Disposition", headStr);
            out = response.getOutputStream();
            excel.export(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toPage;
    }
 
    // tb_fence 导出表格 对象转数组
    public static List<Object[]> objectToArray_inspectionRecord(List<tb_xunjianbaobiao> tb_xunjianbaobiaoList) {
        List<Object[]> reList = new ArrayList<>();
        for (int i = 0; i < tb_xunjianbaobiaoList.size(); i++) {
            List<String> words = new ArrayList<String>();
            tb_xunjianbaobiao xunjianbaobiao = (tb_xunjianbaobiao) tb_xunjianbaobiaoList.get(i);
            words.add(xunjianbaobiao.getId() + "");
            words.add(xunjianbaobiao.getName());
            words.add(xunjianbaobiao.getTagid());
            words.add(xunjianbaobiao.getQuyu());
            words.add(xunjianbaobiao.getBianhao());
            words.add(xunjianbaobiao.getIntime());
            words.add(xunjianbaobiao.getOuttime());
            words.add(xunjianbaobiao.getAlltime());
            words.add(xunjianbaobiao.getSucc());
            words.add(xunjianbaobiao.getAddtime());
            String[] array = words.toArray(new String[0]);
            reList.add(array);
        }
        return reList;
    }
 
    @ResponseBody
    @RequestMapping(value = "/modifyPerPage.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String modifyPerPage(HttpServletRequest request) {
        JSONObject json = new JSONObject();
        String perPage = request.getParameter("perPage");
        if (perPage=="") {
            perPage = "10";
        }
        String pagePath = Config.getPageConfig();
        ModifyConfig.writeData(pagePath, "perPage", perPage);
        String readData = ModifyConfig.readData(pagePath, "perPage");
        json.put("result", readData);
        return json.toString();
    }
    
    @ResponseBody
    @RequestMapping(value = "/fenceList_bw.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String fenceList_bw(HttpServletRequest request) throws IOException {
        JSONObject json = new JSONObject();
        List<tb_fence> fenceList = fenceService.getFenceList();
        json.put("result", fenceList);
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/xunjiansetList_bw.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String xunjiansetList_bw(HttpServletRequest request) {
        JSONObject json = new JSONObject();
        List<tb_xunjianset> inspectionSettingsList = fenceService.getInspectionSettings();
        json.put("result", inspectionSettingsList);
        return json.toString();
    }
    
    @ResponseBody
    @RequestMapping(value = "/xunjianbaobiaoList_bw.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String xunjianbaobiaoList_bw(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        tb_xunjianbaobiao xunjianbaobiao = (tb_xunjianbaobiao) JSONObject.toBean(JSONObject.fromObject(jsonString),
                tb_xunjianbaobiao.class);
        String tagid = xunjianbaobiao.getTagid();
        String quyu = xunjianbaobiao.getQuyu();
        JSONObject json = new JSONObject();
        List<tb_xunjianbaobiao> xunjianbaobiaoList = fenceService.getXunjianbaobiao(tagid,quyu);
        if (xunjianbaobiaoList.size()>0){
            json.put("result", xunjianbaobiaoList);
        } else {
            json.put("result", "null");
        }
        return json.toString();
    }
 
    @RequestMapping(value = "/xunjianbaobiao_bw_add.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void xunjianbaobiao_bw_add(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        tb_xunjianbaobiao xunjianbaobiao = (tb_xunjianbaobiao) JSONObject.toBean(JSONObject.fromObject(jsonString),
                tb_xunjianbaobiao.class);
        //显示sql
        String sqlString = "INSERT tb_xunjianbaobiao (name,tagid,quyu,bianhao,addtime) VALUES ("+xunjianbaobiao.getName()+
                "," +xunjianbaobiao.getTagid()+","+xunjianbaobiao.getQuyu()+","+xunjianbaobiao.getBianhao()+","+GetNowTime.timestamp2()+")";
        String messageJson =  GetNowTime.timestamp2()+ " 收:"+ sqlString ;
        String BaowenPath = Config.getBaowenConfig();
        String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
        if (baowenStatus.equals("1")){
            /* Udp_Receive.mysqlMessage.add(messageJson); */
        }
        //
        fenceService.xunjianbaobiao_add(xunjianbaobiao);
    }
    
    @RequestMapping(value = "/xunjianbaobiao_bw_modify.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void xunjianbaobiao_bw_modify(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        tb_xunjianbaobiao xunjianbaobiao = (tb_xunjianbaobiao) JSONObject.toBean(JSONObject.fromObject(jsonString),
                tb_xunjianbaobiao.class);
        //显示sql
        String sqlString = "INSERT tb_xunjianbaobiao (name,tagid,quyu,bianhao,intime,addtime) VALUES ("+xunjianbaobiao.getName()+
                "," +xunjianbaobiao.getTagid()+","+xunjianbaobiao.getQuyu()+","+xunjianbaobiao.getBianhao()+","+GetNowTime.timestamp2()+GetNowTime.timestamp2()+")";
        String messageJson =  GetNowTime.timestamp2()+ " 收:"+ sqlString ;
        String BaowenPath = Config.getBaowenConfig();
        String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
        if (baowenStatus.equals("1")){
            /* Udp_Receive.mysqlMessage.add(messageJson); */
        }
        //
        fenceService.xunjianbaobiao_add(xunjianbaobiao);
    }
}