package com.hxzk.controller;
|
|
import cn.hutool.json.JSONObject;
|
import com.github.pagehelper.PageInfo;
|
import com.hxzk.pojo.TbFence;
|
import com.hxzk.pojo.TbMap;
|
import com.hxzk.pojo.TbSystemOperationLog;
|
import com.hxzk.pojo.TbTag;
|
import com.hxzk.service.DiTuService;
|
import com.hxzk.service.FenceService;
|
import com.hxzk.service.SystemLogService;
|
import com.hxzk.service.TagService;
|
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.*;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import javax.print.DocFlavor;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("/")
|
public class FenceController {
|
@Autowired
|
FenceService fenceService;
|
|
@Autowired
|
DiTuService diTuService;
|
|
@Autowired
|
SystemLogService systemLogService;
|
|
|
//查询所有围栏设备信息
|
@GetMapping("findfence")
|
result<List<TbFence>> findfence(Integer page, Integer limit){
|
PageInfo<TbFence> cz= fenceService.findAll(page, limit);
|
return resultutil.returnSuccess(cz.getTotal(), cz.getList());
|
}
|
|
@GetMapping("findfenceSearch")
|
result<List<TbFence>> findfenceSearch(Integer page, Integer limit,TbFence fence){
|
PageInfo<TbFence> cz= fenceService.findfenceSearch(page, limit,fence);
|
return resultutil.returnSuccess(cz.getTotal(), cz.getList());
|
}
|
//删除围栏
|
@GetMapping("deletewl")
|
public void deletewl(String name){
|
String xieyi = "BSTOCS1,DELETEFENCE," + name + ",END";
|
TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
|
systemOperationLog.setName(UserController.username);
|
systemOperationLog.setTime(gettime());
|
systemOperationLog.setContent("删除了一个围栏,该围栏为:"+name);
|
systemLogService.insertSystem(systemOperationLog);
|
Udp_Out.udp_to_cs(xieyi);
|
}
|
//新增围栏
|
@PostMapping("addbaidufence")
|
public String addbaidufence(HttpServletRequest request){
|
LocalDateTime now = LocalDateTime.now();
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
String formattedDateTime = now.format(formatter);
|
String layer = request.getParameter("layer");
|
String weilanleixing = request.getParameter("weilanleixing");
|
String guanlianduixiang = request.getParameter("guanlianduixiang");
|
String quyumingcheng = request.getParameter("quyumingcheng");
|
String xingzhuang = request.getParameter("xingzhuang");
|
String yanse = request.getParameter("yanse");
|
String zuobiao = request.getParameter("zuobiao");
|
String s = zuobiao.replaceAll("\\,", "\\:");
|
String shengxiao = "00:00:00";
|
String shixiao = "23:59:59";
|
String xieyi = "BSTOCS1,ADDFENCE," + layer + ","+weilanleixing+","+guanlianduixiang+","+quyumingcheng+","+s+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
|
systemOperationLog.setName(UserController.username);
|
systemOperationLog.setTime(gettime());
|
systemOperationLog.setContent("添加了一个围栏,该围栏为:"+quyumingcheng);
|
systemLogService.insertSystem(systemOperationLog);
|
return "success";
|
}
|
|
|
//修改围栏
|
// @PostMapping("upWeiLan")
|
// public void upWeiLan(TbFence fence, HttpServletResponse response) throws IOException {
|
// LocalDateTime now = LocalDateTime.now();
|
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
// String formattedDateTime = now.format(formatter);
|
// String yanse = "红色";
|
// String xingzhuang = "多边形";
|
// String shengxiao = "00:00:00";
|
// String shixiao = "23:59:59";
|
// String xieyi = "BSTOCS1,DELETEWL," + fence.getFloor() + ","+fence.getType()+","+fence.getBumen()+","+fence.getName()+","+fence.getZuobiao()+","+xingzhuang+","+shengxiao+","+shixiao+","+formattedDateTime+","+yanse+",END";
|
// Udp_Out.udp_to_cs(xieyi);
|
// TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
|
// systemOperationLog.setName(UserController.username);
|
// systemOperationLog.setTime(gettime());
|
// systemOperationLog.setContent("修改了一个围栏,该围栏为:"+fence.getName());
|
// response.sendRedirect("/hxzkuwb/HouTai/WeiLanList/WeiLanList.jsp");
|
// }
|
|
|
//旧
|
@PostMapping("getFloorFence")
|
List<TbFence> getFloorFence(HttpServletRequest request){
|
String floor_number = request.getParameter("value");
|
List<TbFence> fenceList = this.fenceService.getFence(floor_number);
|
List<TbFence> fenceList2 = new ArrayList();
|
for(int i = 0; i < fenceList.size(); ++i) {
|
if (!((TbFence)fenceList.get(i)).getType().equals("变电站")) {
|
fenceList2.add(fenceList.get(i));
|
}
|
}
|
return fenceList;
|
}
|
|
@RequestMapping(value = {"/getFloorFence_all.do"}, method = {RequestMethod.POST, RequestMethod.GET})
|
@ResponseBody
|
public List<TbFence> getFloorFence_all(HttpServletRequest request) {
|
List<TbFence> fenceList = fenceService.getFence_all();
|
for (int i = 0 ; i <fenceList.size();i++){
|
String str = fenceList.get(i).getZuobiao();
|
String replacedStr = str.replace(";", ",");
|
fenceList.get(i).setZuobiao(replacedStr);
|
|
}
|
return fenceList;
|
}
|
|
@GetMapping("findFenceType")
|
public List<TbFence> findFenceType(){
|
return fenceService.findFenceType();
|
}
|
|
@GetMapping("FenceKaiQi")
|
public void fenceKai(TbFence fence){
|
String xieyi = "BSTOCS1,FENCE,OPEN," +fence.getName()+",END";
|
|
Udp_Out.udp_to_cs(xieyi);
|
}
|
@GetMapping("FenceGuanBi")
|
public void fenceGuan(TbFence fence){
|
String xieyi = "BSTOCS1,FENCE,CLOSE," +fence.getName()+",END";
|
System.out.println();
|
Udp_Out.udp_to_cs(xieyi);
|
}
|
|
@PostMapping("upWeiLanTiShiYu")
|
public void upWeiLanTiShiYu(TbFence fence,HttpServletResponse response) throws IOException {
|
fenceService.upWeiLanTiShiYu(fence);
|
response.sendRedirect("/hxzkuwb/HouTai/WeiLanList/WeiLanList.jsp");
|
}
|
|
|
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;
|
}
|
|
@GetMapping("baidufence.do")
|
public String baidufence(HttpServletRequest request) {
|
JSONObject json = new JSONObject();
|
List<TbFence> fences = this.fenceService.getFenceList();
|
List<String> fences2 = new ArrayList();
|
|
for(int i = 0; i < fences.size(); ++i) {
|
fences2.add(((TbFence)fences.get(i)).getBaoliu8());
|
}
|
|
json.put("fences", fences2);
|
return json.toString();
|
}
|
}
|