package com.hxzkappboot.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.hxzkappboot.pojo.TbPersonAndDepartment;
import com.hxzkappboot.pojo.TbWarning;
import com.hxzkappboot.service.TbPersonService;
import com.hxzkappboot.service.TbWarningService;
import com.hxzkappboot.udp.Udp_Out;
import com.hxzkappboot.util.R;
import com.hxzkappboot.util.StatusCode;
import com.hxzkappboot.util.result;
import com.hxzkappboot.util.resultutil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
*
* 前端控制器
*
*
* @author wangfei
* @since 2024-03-08
*/
@RestController
//@RequestMapping("/")
public class TbWarningController {
@Autowired
TbWarningService tbWarningService;
@GetMapping("/api/wx/findwarning")
public R findAll(Page page, String objectid,String company,String juese) {
R response;
List ipage = tbWarningService.findAll(page,objectid,company,juese);
response = new R(StatusCode.Success);
response.setData(ipage);
return response;
}
@GetMapping("/api/wx/findWarningNum")
public R findWarningNum(String company ) {
R response;
try {
response = new R(StatusCode.Success);
response.setData(tbWarningService.findWarningNum(company));
} catch (Exception e) {
response = new R(StatusCode.Fail.getCode(), e.getMessage());
}
return response;
}
@PostMapping("/api/wx/processingWarn")
public R processingWarn(@Valid @RequestBody TbWarning warning) {
// R response ;
// response = new R(StatusCode.Success);
// return response;
String xieyi = "BSTOCS1,DELLWARN," +warning.getTagid()+","+warning.getWarntype()+",END";
// String xieyi = "BSTOCS1,DELETEFENCE," + name + ",END";
Udp_Out.udp_to_cs(xieyi);
try {
Thread.sleep(1000);
}catch (InterruptedException e){
Thread.currentThread().interrupt();
// logUtil.error("线程中断"+e.getMessage());
}
R response ;
response = new R(StatusCode.Success);
TbWarning gpsList =tbWarningService.processingWarn(warning);
response.setData(gpsList);
// List fenceList = new ArrayList();
// System.out.println(name);
// fenceList = tbFenceService.earlyWarning();
// TbWarning tbWarning = tbWarningService.findWarningid(warning.getId());
// response.setData(tbWarning);
return response;
}
@GetMapping("/api/wx/delewarn")
public void delewarn(String warningId,String addperson,String perCompany) {
String time = this.gettime();
// BSTOCS1,WARNING,DELETE,warningId,delPerson,perCompany,time,END
String xieyi = "BSTOCS1,WARNING,DELETE," + warningId +","+ addperson +","+ perCompany +","+ time+ ",END";
Udp_Out.udp_to_cs(xieyi);
}
// @PostMapping("/api/wx/moreprocessingWarn")
// public R moreprocessingWarn(@Valid @RequestBody TbWarning warning) {
//// R response ;
//// response = new R(StatusCode.Success);
//// TbWarning gpsList =tbWarningService.processingWarn(warning);
//// response.setData(gpsList);
//// return response;
// for (int i = 0; i < warning.getIds().size(); i++) {
// TbWarning tbWarning = tbWarningService.findWarningid(warning.getIds().get(i));
// String xieyi = "BSTOCS1,DELLWARN," +tbWarning.getTagid()+","+tbWarning.getWarntype()+",END";
//// String xieyi = "BSTOCS1,DELETEFENCE," + name + ",END";
// Udp_Out.udp_to_cs(xieyi);
// }
//
// R response ;
//// List fenceList = new ArrayList();
//// System.out.println(name);
//// fenceList = tbFenceService.earlyWarning();
// response = new R(StatusCode.Success);
//// response.setData(fenceList);
// return response;
// }
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;
}
}