package com.hxzk.controller; import com.github.pagehelper.PageInfo; import com.hxzk.pojo.TbHksxt; import com.hxzk.pojo.TbShipin; import com.hxzk.service.FenceService; import com.hxzk.service.HkSxtService; import com.hxzk.service.ShiPinService; import com.hxzk.udp.Udp_Out; import com.hxzk.util.result; import com.hxzk.util.resultutil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @RestController @RequestMapping("/") public class HkSxtController { @Autowired ShiPinService shiPinService; @Autowired HkSxtService hkSxtService; @Autowired FenceService fenceService; @GetMapping("findhk") result> findhk(Integer page, Integer limit){ PageInfo cz= hkSxtService.findAll(page, limit); return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } @PostMapping({"HksxtSearch"}) public result> tableSearch(TbHksxt manager, int page, int limit) throws Exception { PageInfo cz = this.hkSxtService.tableSearch(manager, page, limit); return resultutil.returnSuccess(cz.getTotal(), cz.getList()); } @PostMapping("addHk") public ModelAndView addHk(TbHksxt hksxt, HttpServletResponse response) throws Exception { Date date = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); hksxt.setEnterdate(formatter.format(date)); String xieyi = "BSTOCS1,ADD,HKSXT,"+hksxt.getIp()+","+hksxt.getPort()+","+hksxt.getUsername()+","+hksxt.getPassword()+","+hksxt.getShebeiport()+","+hksxt.getEnterdate()+hksxt.getBindregion()+",END"; Udp_Out.udp_to_cs(xieyi); response.sendRedirect("/hxzkuwb/HouTai/JianKongPeiZhi/JianKongPeiZhi.jsp"); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("/hxzkuwb/HouTai/JianKongPeiZhi/JianKongPeiZhi.jsp"); modelAndView.addObject("suoshu", fenceService.findSuoShu()); return modelAndView; } @PostMapping("updateHk") public ModelAndView updateHk(TbHksxt hksxt,HttpServletResponse response) throws Exception { Date date = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); hksxt.setEnterdate(formatter.format(date)); String xieyi = "BSTOCS1,ALTER,HKSXT,"+hksxt.getIp()+","+hksxt.getPort()+","+hksxt.getUsername()+","+hksxt.getPassword()+","+hksxt.getShebeiport()+","+hksxt.getEnterdate()+hksxt.getBindregion()+",END"; Udp_Out.udp_to_cs(xieyi); response.sendRedirect("/hxzkuwb/HouTai/JianKongPeiZhi/JianKongPeiZhi.jsp"); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("/HouTai/JianKongPeiZhi/JianKongPeiZhi.jsp"); modelAndView.addObject("suoshu", fenceService.findSuoShu()); return modelAndView; } @GetMapping("deleteHk") public void deleteHk(String name){ String xieyi = "BSTOCS1,DELETE,HKSXT,"+name+",END"; } public String gettime(){ Date now = new Date(); // 创建日期格式化对象,设置格式为 "yyyy-MM-dd HH:mm" SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // 格式化日期对象,输出字符串结果 String formattedDate = sdf.format(now); return formattedDate; } }