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 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 list = mjHnweEventService.selectMjHnweEventList(mjHnweEvent); ExcelUtil util = new ExcelUtil(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)); } }