zhitong.yu
2024-03-21 6beef2ce75f15a8b3d4394b83da62071c686eb3d
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.hxzk.controller;
 
import com.github.pagehelper.PageInfo;
import com.hxzk.pojo.TbAchor;
import com.hxzk.pojo.TbMessageHistory;
import com.hxzk.pojo.TbSystemOperationLog;
import com.hxzk.pojo.TbTag;
import com.hxzk.service.MessageService;
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 javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
@RestController
@RequestMapping("/")
public class TagController {
 
    @Autowired
    TagService tagService;
 
    @Autowired
    SystemLogService systemLogService;
 
    @Autowired
    MessageService messageService;
 
    //查询所有标签设备信息
    @GetMapping("findTag")
    result<List<TbTag>> findTag(Integer page, Integer limit){
        PageInfo<TbTag> cz= tagService.findAll(page, limit);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
 
 
    //删除标签
    @GetMapping("deletetag")
    public void deletetag(Integer id){
        String xieyi = "BSTOCS1,DELETETAG," + id + ",END";
        TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
        systemOperationLog.setName(UserController.username);
        systemOperationLog.setTime(gettime());
        systemOperationLog.setContent("删除了一个标签,该标签为:"+id);
        systemLogService.insertSystem(systemOperationLog);
        Udp_Out.udp_to_cs(xieyi);
    }
    //查重
    @GetMapping("tagCha")
    public int tagCha(Integer id){
        return tagService.tagCha(id);
    }
    //新增标签
    @PostMapping("addTag")
    @ResponseBody
    public void addTag(TbTag tag, HttpServletResponse response) throws IOException {
        String xieyi = "BSTOCS1,ADDTAG," + tag.getTagId() +",未绑定,150,10000,1,"+tag.getType()+",END";
        Udp_Out.udp_to_cs(xieyi);
        TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
        systemOperationLog.setName(UserController.username);
        systemOperationLog.setTime(gettime());
        systemOperationLog.setContent("增加了一个标签,该标签为:"+tag.getTagId());
        systemLogService.insertSystem(systemOperationLog);
        response.sendRedirect("/hxzkuwb/HouTai/Tag/Tag.jsp");
 
    }
    //修改标签
    @PostMapping("upTag")
    @ResponseBody
    public void upTag(TbTag tag, HttpServletResponse response) throws IOException {
        String xieyi = "BSTOCS1,ALTERTAG,"  + tag.getTagId() +",未绑定,150,10000,1,"+tag.getType()+",END";
        Udp_Out.udp_to_cs(xieyi);
        TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
        systemOperationLog.setName(UserController.username);
        systemOperationLog.setTime(gettime());
        systemOperationLog.setContent("修改了标签信息,该标签为:"+tag.getTagId());
        systemLogService.insertSystem(systemOperationLog);
        response.sendRedirect("/hxzkuwb/HouTai/Tag/Tag.jsp");
    }
    //查找标签电量
    @PostMapping("findPowerTag")
    @ResponseBody
    public List<TbTag> findPowerTag(){
        return tagService.findPowerTag();
    }
 
    //表格搜索
    @PostMapping("findtableSearch")
    result<List<TbTag>> findtableSearch(Integer page, Integer limit, TbTag tag){
        PageInfo<TbTag> cz= tagService.findSearch(page, limit,tag);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
    //给标签发送语音消息
    @GetMapping("sendMsg")
    public void sendMsg(String username,String context,String tagid){
        String xieyi = "BSTOCS1,TOMESSAGE," + tagid + "," + context + "," + username + ",END";
        Udp_Out.udp_to_cs(xieyi);
        //获取发送人员,发送对象,发送时间,发送内容
        TbMessageHistory tbMessageHistory = new TbMessageHistory();
        tbMessageHistory.setTime(gettime());
        tbMessageHistory.setUser(username);
        tbMessageHistory.setTagid(tagid);
        tbMessageHistory.setNeirong(context);
        messageService.addMessage(tbMessageHistory);
    }
    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;
    }
}