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 caozuoName){
|
String xieyi = "BSTOCS1,DELETETAG," + id + ",END";
|
TbSystemOperationLog systemOperationLog = new TbSystemOperationLog();
|
systemOperationLog.setName(caozuoName);
|
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,String caozuoName) 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(caozuoName);
|
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,String caozuoName) 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(caozuoName);
|
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){
|
TbTag tag = new TbTag();
|
tag.setTagId(tagid);
|
TbTag tag1 = tagService.findSearchOne(tag);
|
String xieyi = "BSTOCS1,TOMESSAGE," + tag1.getTagId() + "," + 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;
|
}
|
}
|