zhitong.yu
2024-10-11 4f58a93c95ff123d51adcb8fa2e521333e8ab022
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
package com.hxzk.controller;
 
import com.github.pagehelper.PageInfo;
import com.hxzk.pojo.TbHksxt;
import com.hxzk.pojo.TbShipin;
import com.hxzk.pojo.TbUser;
import com.hxzk.service.HkSxtService;
import com.hxzk.service.ShiPinService;
import com.hxzk.udp.Udp_Out;
import com.hxzk.util.SessionManager;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
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
    SessionManager sessionManager;
    @GetMapping("findhk")
    result<List<TbHksxt>> findhk(Integer page, Integer limit){
        PageInfo<TbHksxt> cz= hkSxtService.findAll(page, limit);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
 
    @GetMapping("addHk")
    public void addHk(TbHksxt hksxt, HttpServletResponse response, HttpServletRequest request) throws IOException {
        TbUser user = sessionManager.getCurrentUser(request);
        String xieyi = "BSTOCS1,ADD,HKSXT,"+hksxt.getIp()+","+hksxt.getPort()+","+hksxt.getUsername()+","+hksxt.getPassword()+","+hksxt.getShebeiport()+",END";
        Udp_Out.udp_to_cs(xieyi);
        String content = "添加了一个监控配置,该监控名称为:"+hksxt.getUsername();
        String contentew = "Добавлена конфигурация мониторинга, которая называется:"+hksxt.getUsername();
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew);
        response.sendRedirect("/hxzkuwb/HouTai/JianKongPeiZhi/JianKongPeiZhi.jsp");
    }
    @GetMapping("updateHk")
    public void updateHk(TbHksxt hksxt,HttpServletResponse response, HttpServletRequest request) throws IOException {
        TbUser user = sessionManager.getCurrentUser(request);
        String xieyi = "BSTOCS1,ALTER,HKSXT,"+hksxt.getIp()+","+hksxt.getPort()+","+hksxt.getUsername()+","+hksxt.getPassword()+","+hksxt.getShebeiport()+",END";
        Udp_Out.udp_to_cs(xieyi);
        String content = "修改了一个监控配置,该监控名称为:"+hksxt.getUsername();
        String contentew = "Изменена конфигурация мониторинга, которая называется:"+hksxt.getUsername();
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew);
        response.sendRedirect("/hxzkuwb/HouTai/JianKongPeiZhi/JianKongPeiZhi.jsp");
    }
    @GetMapping("deleteHk")
    public void deleteHk(String name, HttpServletRequest request){
        TbUser user = sessionManager.getCurrentUser(request);
        String xieyi = "BSTOCS1,DELETE,HKSXT,"+name+",END";
        Udp_Out.udp_to_cs(xieyi);
        String content = "删除了一个监控配置,该监控名称为:"+name;
        String contentew = "Удалена конфигурация мониторинга, которая называется:"+name;
        SystemLogController.InsertSystemLog(user.getUsername(),gettime(),content,contentew);
    }
 
    @GetMapping("UpJianKong")
    public void UpJianKongs(TbHksxt hksxt, HttpServletRequest request){
        hkSxtService.UpJianKongs(hksxt);
    }
 
    @GetMapping("FindUserNameSxt")
    public TbHksxt FindUserNameSxt(TbHksxt tbHksxt){
        return hkSxtService.FindUserNameSxt(tbHksxt);
    }
    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;
    }
}