package com.hxzkoa.controller;
|
|
import java.awt.Image;
|
import java.io.File;
|
import java.io.IOException;
|
import java.io.OutputStream;
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.Comparator;
|
import java.util.List;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.swing.ImageIcon;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import com.hxzkoa.json.tb_adress_and_port;
|
import com.hxzkoa.json.tb_department;
|
import com.hxzkoa.json.tb_history_power;
|
import com.hxzkoa.json.tb_person;
|
import com.hxzkoa.json.tb_tag;
|
import com.hxzkoa.json.tb_tagpower;
|
import com.hxzkoa.json.tb_wifi;
|
import com.hxzkoa.json.vo_tp_t_p;
|
import com.hxzkoa.services.AnchorService;
|
import com.hxzkoa.services.BasicInfoService;
|
import com.hxzkoa.services.LabelService;
|
import com.hxzkoa.udp.ControTag;
|
import com.hxzkoa.udp.GetNowTime;
|
import com.hxzkoa.udp.IDcard;
|
import com.hxzkoa.udp.Udp_Out;
|
/*import com.hxzkoa.udp.Udp_Receive;*/
|
import com.hxzkoa.udp.bmpToJPG;
|
import com.hxzkoa.util.Config;
|
import com.hxzkoa.util.ExcelUtils;
|
import com.hxzkoa.util.HttpUtil;
|
import com.hxzkoa.util.LineXy;
|
import com.hxzkoa.util.ModifyConfig;
|
import com.hxzkoa.util.PageUtil;
|
import com.hxzkoa.util.RequestUtils;
|
|
import jxl.Sheet;
|
import jxl.Workbook;
|
import jxl.read.biff.BiffException;
|
import net.sf.json.JSONObject;
|
|
@Controller
|
public class LabelController {
|
@Autowired
|
private LabelService labelService;
|
@Autowired
|
private BasicInfoService basicInfoService;
|
@Autowired
|
private AnchorService anchorService;
|
|
@ResponseBody
|
@RequestMapping(value = "/to_cs_pinlv.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void pinlv(HttpServletRequest request) {
|
String tag_id = request.getParameter("tag_id");
|
String hz = request.getParameter("hz");
|
String xieyi = "55BB,ALERT_TAG_HZ,"+hz+","+tag_id+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/to_cs_xiumian_time.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void xiumiantime(HttpServletRequest request) {
|
String tag_id = request.getParameter("tag_id");
|
String hz = request.getParameter("hz");
|
String xieyi = "55BB,ALERT_SLEEP_TIME,"+hz+","+tag_id+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/to_cs_xiumian_.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void xiumian(HttpServletRequest request) {
|
String tag_id = request.getParameter("tag_id");
|
String hz = request.getParameter("hz");
|
String xieyi = "55BB,OPEN_OR_CLOSE_SLEEP,"+hz+","+tag_id+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/to_cs_zhendong_.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void zhendong(HttpServletRequest request) {
|
String tag_id = request.getParameter("tag_id");
|
String hz = request.getParameter("hz");
|
String xieyi = "55BB,TAG_SHAKE,"+hz+","+tag_id+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
}
|
|
@RequestMapping(value = "/labelManagement.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelManagement(HttpServletRequest request) {
|
String toPage = "forward:/hxzk/label/labelManagement.jsp";
|
List<tb_tag> labelManagementList = labelService.getLabelManagement(1);
|
request.setAttribute("labelManagementList", labelManagementList);
|
int curPage = 1;
|
int count = labelService.getLabelManagementCount();
|
int minPage = PageUtil.getMinPage(count);
|
System.out.print(minPage);
|
request.setAttribute("pageList", PageUtil.getPage(minPage));
|
request.setAttribute("curPage", curPage);
|
return toPage;
|
}
|
|
@RequestMapping(value = "/labelManagement_add.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelManagement_add(HttpServletRequest request) throws IOException {
|
tb_tag tag = new tb_tag();
|
String tag_id = request.getParameter("tag_id");
|
if (("").equals(tag_id) || tag_id == null) {
|
// 接口处理逻辑
|
String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
|
tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class);
|
tag_id = tag.getTag_id();
|
} else {
|
// 网页请求逻辑
|
tag.setTag_id(request.getParameter("tag_id"));
|
tag.setState(request.getParameter("state"));
|
tag.setGaodu(request.getParameter("gaodu"));
|
tag.setSudu(request.getParameter("sudu"));
|
tag.setPinglv(request.getParameter("pinglv"));
|
tag.setVersion(Config.getVersion());
|
}
|
// 如果该tag_id不存在,新增一条
|
List<tb_tag> searchLabelManagement = labelService.searchLabelManagement(tag_id);
|
if (searchLabelManagement.size() == 0) {
|
labelService.labelManagement_add(tag);
|
if(("").equals(tag.getState())){
|
tag.setState("未绑定");
|
}
|
if(("").equals(tag.getGaodu())){
|
tag.setGaodu("150");
|
}
|
if(("").equals(tag.getSudu())){
|
tag.setSudu("1000");
|
}
|
String xieyi = "BSTOCS1,ADDTAG,"+tag.getTag_id()+","+tag.getState()+","+tag.getGaodu()+","+tag.getSudu()+","+tag.getPinglv()+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
// 新增标签同时需要在tb_person中插入一条数据
|
tb_person person = new tb_person();
|
person.setP_tagid(tag.getTag_id());
|
person.setP_name(tag.getState());
|
person.setP_power(tag.getPower());
|
person.setP_sex("男");
|
person.setP_minzu("汉");
|
person.setP_phone("131******88");
|
person.setP_department("系统默认");
|
person.setP_x("0");
|
person.setP_y("0");
|
person.setP_floor("0");
|
person.setP_sos("0");
|
person.setP_online("0");
|
person.setP_kaoqing("0");
|
person.setP_fence("0");
|
person.setP_image("image/targeticon/default.png");
|
basicInfoService.personManagement_add(person);
|
}
|
}
|
|
@RequestMapping(value = "/labelManagement_modify.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelManagement_modify(HttpServletRequest request) {
|
tb_tag tag = new tb_tag();
|
tag.setTag_id(request.getParameter("tag_id"));
|
tag.setState(request.getParameter("state"));
|
tag.setGaodu(request.getParameter("gaodu"));
|
tag.setSudu(request.getParameter("sudu"));
|
tag.setPinglv(request.getParameter("pinglv"));
|
labelService.labelManagement_modify(tag);
|
String xieyi = "BSTOCS1,ALTERTAG,"+tag.getTag_id()+","+tag.getState()+","+tag.getGaodu()+","+tag.getSudu()+","+tag.getPinglv()+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
// 修改标签同时需要修改tb_person 需要先查再改否则覆盖空
|
List<tb_person> searchPersonManagement = basicInfoService.searchPersonManagement(tag.getTag_id());
|
if(searchPersonManagement!=null){
|
tb_person person = searchPersonManagement.get(0);
|
person.setP_tagid(tag.getTag_id());
|
person.setP_name(tag.getState());
|
person.setP_power(tag.getPower());
|
basicInfoService.personManagement_modify(person);
|
}
|
}
|
|
@RequestMapping(value = "/labelManagement_modifyAll.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelManagement_modifyAll(HttpServletRequest request) {
|
tb_tag tag = new tb_tag();
|
tag.setGaodu(request.getParameter("gaodu"));
|
tag.setSudu(request.getParameter("sudu"));
|
tag.setPinglv(request.getParameter("pinglv"));
|
labelService.labelManagement_modifyAll(tag);
|
String xieyi = "BSTOCS1,ALTERALLTAG,"+tag.getGaodu()+","+tag.getSudu()+","+tag.getPinglv()+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
// 需要遍历修改
|
List<tb_tag> labelList = labelService.getLabelManagement();
|
for (int i = 0; i < labelList.size(); i++) {
|
String tag_id = labelList.get(i).getTag_id();
|
// 修改标签同时需要修改tb_person 需要先查再改否则覆盖空
|
List<tb_person> searchPersonManagement = basicInfoService.searchPersonManagement(tag_id);
|
if(searchPersonManagement!=null){
|
tb_person person = searchPersonManagement.get(0);
|
person.setP_tagid(tag.getTag_id());
|
person.setP_name(tag.getState());
|
person.setP_power(tag.getPower());
|
basicInfoService.personManagement_modify(person);
|
}
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelManagement_delete(HttpServletRequest request) {
|
String checkValStr = request.getParameter("checkVal");
|
checkValStr = checkValStr.replaceAll("\"", "");
|
String[] checkVal = checkValStr.split(",");
|
labelService.labelManagement_delete(checkVal);
|
for (int i = 0; i < checkVal.length; i++) {
|
String xieyi = "BSTOCS1,DELETETAG,"+checkVal[i]+",END";
|
Udp_Out.udp_to_cs(xieyi);
|
}
|
// 删除标签同时需要删除tb_person
|
labelService.labelperson_delete(checkVal);
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelManagement_deleteAll(HttpServletRequest request) {
|
labelService.labelManagement_deleteAll();
|
String xieyi = "BSTOCS1,DELETEALLTAG,END";
|
Udp_Out.udp_to_cs(xieyi);
|
// 删除标签同时需要删除tb_person
|
basicInfoService.personManagement_deleteAll();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_search.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelManagement_search(HttpServletRequest request) throws IOException {
|
JSONObject json = new JSONObject();
|
String input = request.getParameter("input");
|
if (("").equals(input) || input == null) {
|
String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
|
tb_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class);
|
input = tag.getTag_id();
|
List<tb_tag> labelManagementList = labelService.searchLabelManagement(input);
|
if (labelManagementList.size() > 0) {
|
json.put("result", labelManagementList.get(0));
|
} else {
|
json.put("result", "null");
|
}
|
|
} else {
|
int curPage = 1;
|
List<Integer> pageList = new ArrayList<Integer>();
|
List<tb_tag> labelManagementList = labelService.searchLabelManagement(input);
|
pageList.add(1);
|
json.put("dataList", labelManagementList);
|
json.put("pageList", pageList);
|
json.put("curPage", curPage);
|
}
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_page.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelManagement_page(HttpServletRequest request) {
|
String pageStr = request.getParameter("page");
|
String curPageStr = request.getParameter("curPage");
|
int count = labelService.getLabelManagementCount();
|
int minPage = PageUtil.getMinPage(count);
|
int curPage = Integer.parseInt(curPageStr);
|
int page = 1;
|
if ("pre".equals(pageStr)) {
|
if (curPage > 1) {
|
page = curPage - 1;
|
}
|
} else if ("next".equals(pageStr)) {
|
if (curPage < minPage) {
|
page = curPage + 1;
|
}
|
} else {
|
page = Integer.parseInt(pageStr);
|
}
|
List<tb_tag> labelManagementList = labelService.getLabelManagement(page);
|
List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
|
JSONObject json = new JSONObject();
|
json.put("dataList", labelManagementList);
|
json.put("pageList", pageList);
|
json.put("curPage", page);
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_exportTemplate.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelManagement_exportTemplate(HttpServletRequest request, HttpServletResponse response) {
|
String toPage = "forward:/hxzk/label/labelManagement.jsp";
|
List<tb_tag> labelTemplateList = labelService.getLabelManagement(1);
|
String[] rowName = { "标签ID", "绑定对象"};
|
List<Object[]> dataList = labelTemplateobjectToArray(labelTemplateList);
|
ExcelUtils excel = new ExcelUtils("标签管理", rowName, dataList);
|
OutputStream out;
|
try {
|
String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
|
String headStr = "attachment; filename=\"" + fileName + "\"";
|
response.setContentType("APPLICATION/OCTET-STREAM");
|
response.setHeader("Content-Disposition", headStr);
|
out = response.getOutputStream();
|
excel.export(out);
|
out.flush();
|
out.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return toPage;
|
}
|
|
// 对象转数组
|
public static List<Object[]> labelTemplateobjectToArray(List<tb_tag> labelList) {
|
List<Object[]> reList = new ArrayList<>();
|
for (int i = 0; i < labelList.size(); i++) {
|
List<String> words = new ArrayList<String>();
|
tb_tag tag = (tb_tag) labelList.get(i);
|
words.add(tag.getTag_id());
|
words.add(tag.getState());
|
String[] array = words.toArray(new String[0]);
|
reList.add(array);
|
}
|
return reList;
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_import.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelManagement_import(HttpServletRequest request) {
|
String path = request.getParameter("path");
|
if (path.indexOf("fakepath") != -1) {
|
String[] fileNameArr = path.split("\\\\");
|
String fileName = fileNameArr[fileNameArr.length - 1];
|
path = "C:/hxzkoa/" + fileName;
|
}
|
;
|
int result = 0;
|
// 选取Excel文件得到工作薄
|
Workbook workbook;
|
try {
|
File file = new File(path);
|
workbook = Workbook.getWorkbook(file);
|
// 选择工作表,通过Workbook的getSheet方法选择第一个工作表(从0开始)
|
Sheet sheet = workbook.getSheet(0);
|
int rows = sheet.getRows();
|
// 选择Cell,读取单元格 通过Sheet的getCell方法选择位置为C2的单元格(两个参数都从0开始)
|
for (int i = 1; i < rows; i++) {
|
// 读取信息,通过Cell的getContents方法读取单元格的值把单元格中的信息以字符的形式读取出来
|
String status = sheet.getCell(0, i).getContents();
|
String tag_id = sheet.getCell(1, i).getContents();
|
String state = sheet.getCell(2, i).getContents();
|
String power = sheet.getCell(3, i).getContents();
|
String gaodu = sheet.getCell(4, i).getContents();
|
String sudu = sheet.getCell(5, i).getContents();
|
String pinglv = sheet.getCell(6, i).getContents();
|
String version = sheet.getCell(7, i).getContents();
|
if (!("").equals(tag_id)) {
|
tb_tag tag = new tb_tag();
|
tag.setStatus(status);
|
tag.setTag_id(tag_id);
|
tag.setState(state);
|
tag.setPower(power);
|
tag.setGaodu(gaodu);
|
tag.setSudu(sudu);
|
tag.setPinglv(pinglv);
|
tag.setVersion(version);
|
labelService.labelManagement_add(tag);
|
}
|
}
|
// 释放资源
|
workbook.close();
|
} catch (BiffException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
JSONObject json = new JSONObject();
|
json.put("result", result);
|
return json.toString();
|
}
|
|
@RequestMapping(value = "/uploadLabel.do")
|
public String uploadPerson(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) {
|
String toPage = "forward:/hxzk/label/labelManagement.jsp";
|
String filePath = request.getServletContext().getRealPath("/") + "hxzk\\upload\\";
|
String filename = files[0].getOriginalFilename();
|
try {
|
File existFile = new File(filePath);
|
if (!existFile.exists()) {
|
existFile.mkdir();
|
}
|
for (MultipartFile file : files) {
|
file.transferTo(new File(filePath + file.getOriginalFilename()));
|
System.out.print(file.getOriginalFilename());
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
int result = 0;
|
String path = filePath + filename;
|
// 选取Excel文件得到工作薄
|
Workbook workbook;
|
try {
|
File file = new File(path);
|
workbook = Workbook.getWorkbook(file);
|
// 选择工作表,通过Workbook的getSheet方法选择第一个工作表(从0开始)
|
Sheet sheet = workbook.getSheet(0);
|
int rows = sheet.getRows();
|
// 选择Cell,读取单元格 通过Sheet的getCell方法选择位置为C2的单元格(两个参数都从0开始)
|
for (int i = 3; i < rows; i++) {
|
// 读取信息,通过Cell的getContents方法读取单元格的值把单元格中的信息以字符的形式读取出来
|
// String status = sheet.getCell(0, i).getContents();
|
String tag_id = sheet.getCell(0, i).getContents();
|
String state = sheet.getCell(1, i).getContents();
|
if (!("").equals(tag_id)) {
|
tb_tag tag = new tb_tag();
|
// tag.setStatus(status);
|
tag.setTag_id(tag_id);
|
tag.setState(state);
|
tag.setPower("100");
|
tag.setGaodu("150");
|
tag.setSudu("无");
|
tag.setPinglv("无");
|
tag.setVersion("无");
|
result = labelService.labelManagement_add(tag);
|
}
|
}
|
// 释放资源
|
workbook.close();
|
} catch (BiffException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
request.setAttribute("resultList", result);
|
List<tb_tag> labelManagementList = labelService.getLabelManagement(1);
|
request.setAttribute("labelManagementList", labelManagementList);
|
int curPage = 1;
|
int count = labelService.getLabelManagementCount();
|
int minPage = PageUtil.getMinPage(count);
|
request.setAttribute("pageList", PageUtil.getPage(minPage));
|
request.setAttribute("curPage", curPage);
|
File file = new File(path);
|
file.delete();
|
return toPage;
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_export.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelManagement_export(HttpServletRequest request, HttpServletResponse response) {
|
String toPage = "forward:/hxzk/label/labelManagement.jsp";
|
List<tb_tag> tb_tagList = labelService.getLabelManagement();
|
String[] rowName = { "标签ID", "绑定对象", "电量%", "佩戴高度/cm", "速度限制cm/s", "定位频率(HZ)", "版本", "添加时间" };
|
List<Object[]> dataList = objectToArray_labelManagement(tb_tagList);
|
ExcelUtils excel = new ExcelUtils("标签管理", rowName, dataList);
|
OutputStream out;
|
try {
|
String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
|
String headStr = "attachment; filename=\"" + fileName + "\"";
|
response.setContentType("APPLICATION/OCTET-STREAM");
|
response.setHeader("Content-Disposition", headStr);
|
out = response.getOutputStream();
|
excel.export(out);
|
out.flush();
|
out.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return toPage;
|
}
|
|
// tb_tag 导出表格 对象转数组
|
public static List<Object[]> objectToArray_labelManagement(List<tb_tag> tb_tagList) {
|
List<Object[]> reList = new ArrayList<>();
|
for (int i = 0; i < tb_tagList.size(); i++) {
|
List<String> words = new ArrayList<String>();
|
tb_tag tag = (tb_tag) tb_tagList.get(i);
|
words.add(tag.getTag_id());
|
words.add(tag.getState());
|
words.add(tag.getPower());
|
words.add(tag.getGaodu());
|
words.add(tag.getSudu());
|
words.add(tag.getPinglv());
|
words.add(tag.getVersion());
|
words.add(tag.getAddtime());
|
String[] array = words.toArray(new String[0]);
|
reList.add(array);
|
}
|
return reList;
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_tagid.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelManagement_tagid(HttpServletRequest request) {
|
JSONObject json = new JSONObject();
|
List<tb_tag> labelManagementList = labelService.getLabelManagement();
|
List<String> reList = new ArrayList<String>();
|
for (int i = 0; i < labelManagementList.size(); i++) {
|
reList.add(labelManagementList.get(i).getTag_id());
|
}
|
json.put("dataList", reList);
|
return json.toString();
|
}
|
|
@RequestMapping(value = "/labelManagement_more.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelManagement_more(HttpServletRequest request) {
|
tb_tag tag = new tb_tag();
|
tag.setTag_id(request.getParameter("tag_id"));
|
tag.setSleep_satus(request.getParameter("sleep_satus"));
|
tag.setSleep_time(request.getParameter("sleep_time"));
|
tag.setGongfang(request.getParameter("gongfang"));
|
tag.setPinglv(request.getParameter("pinglv"));
|
tag.setImu(request.getParameter("imu"));
|
tag.setDong_status(request.getParameter("dong_status"));
|
labelService.labelManagement_more(tag);
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelManagement_tag.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelManagement_tag(HttpServletRequest request) {
|
JSONObject json = new JSONObject();
|
String tagid = request.getParameter("tag_id");
|
String tag = request.getParameter("tag");
|
String hz = request.getParameter("hz");
|
String result = "";
|
List<tb_tag> tagList = null;
|
if (("ALL").equals(tagid)) {
|
tagList = labelService.getLabelManagement();
|
}
|
// 获取 port,wifi_mode
|
tb_wifi wifiManagement = anchorService.getWifiManagement();
|
String port = wifiManagement.getPort();
|
String wifi_mode = wifiManagement.getModel();
|
// 1.开启或者关闭标签休眠
|
// 2.修改标签休眠时间
|
// 3.修改标签的功率
|
// 4.下发标签振动
|
// 5.修改标签的频率
|
// 6.修改加速度计阈值
|
// 7.修改静止时间
|
// 8.开启或者关闭标签振动功能
|
if (("1").equals(tag)) {
|
// 1.开启或者关闭标签休眠
|
int sleep_open = Integer.parseInt(hz);
|
ControTag.set_tag_sleep_open(sleep_open, tagid, tagList, port, wifi_mode);
|
result = "休眠指令已经下发完成!";
|
} else if (("2").equals(tag)) {
|
// 2.修改标签休眠时间
|
int sleeptime = Integer.parseInt(hz);
|
ControTag.set_tag_sleep_time(sleeptime, tagid, tagList, port, wifi_mode);
|
result = "休眠时间修改指令下发完成!";
|
} else if (("3").equals(tag)) {
|
// 3.修改标签的功率
|
int gonglv = Integer.parseInt(hz);
|
ControTag.set_tag_gonglv(gonglv, tagid, tagList, port, wifi_mode);
|
result = "功率修改指令下发完成!";
|
} else if (("4").equals(tag)) {
|
// 4.下发标签振动
|
if (hz == null || ("").equals(hz)) {
|
result = "振动时间不能为空!";
|
} else {
|
int time = Integer.parseInt(hz);
|
if (time > 255) {
|
result = "振动时间为0~255秒!";
|
} else {
|
ControTag.set_tag_zhendong(time, tagid, tagList, port, wifi_mode);
|
result = "振动指令已下发完毕!";
|
}
|
}
|
} else if (("5").equals(tag)) {
|
// 5.修改标签的频率
|
ControTag.set_tag_hz(hz, tagid, tagList, port, wifi_mode);
|
result = "修改频率指令已下发完毕!";
|
} else if (("6").equals(tag)) {
|
// 6.修改加速度计阈值
|
int yuzhi = Integer.parseInt(hz);
|
ControTag.set_tag_jiasu(yuzhi, tagid, tagList, port, wifi_mode);
|
result = "修改加速度计阈值指令下发完成!";
|
} else if (("7").equals(tag)) {
|
// 7.修改静止时间
|
int time = Integer.parseInt(hz);
|
ControTag.set_tag_jingzhi(time, tagid, tagList, port, wifi_mode);
|
result = "静止时间修改指令下发完成!";
|
} else if (("8").equals(tag)) {
|
// 8.开启或者关闭标签振动功能
|
int jck_move = Integer.parseInt(hz);
|
ControTag.set_tag_move(jck_move, tagid, tagList, port, wifi_mode);
|
if (jck_move == 1) {
|
result = "开启振动改指令下发完成!";
|
} else {
|
result = "关闭振动指令下发完成!";
|
}
|
}
|
json.put("result", result);
|
return json.toString();
|
}
|
|
@RequestMapping(value = "/labelDeliver.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelDeliver(HttpServletRequest request) {
|
String toPage = "forward:/hxzk/label/labelDeliver.jsp";
|
List<tb_department> department = basicInfoService.getAllDepartmentManagement();
|
request.setAttribute("department", department);
|
return toPage;
|
}
|
|
@RequestMapping(value = "/labelDeliver_add.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelDeliver_add(HttpServletRequest request) {
|
String p_tagid = request.getParameter("p_tagid");
|
String p_name = request.getParameter("p_name");
|
tb_person person = new tb_person();
|
String p_sos = "0";
|
String p_online = "0";
|
String p_power = "100";
|
person.setP_tagid(p_tagid);
|
person.setP_name(p_name);
|
person.setP_sex(request.getParameter("p_sex"));
|
person.setP_minzu(request.getParameter("p_minzu"));
|
person.setP_phone(request.getParameter("p_phone"));
|
person.setP_department(request.getParameter("p_department"));
|
person.setP_idcardnum(request.getParameter("p_idcardnum"));
|
person.setP_adress(request.getParameter("p_adress"));
|
person.setP_sos(p_sos);
|
person.setP_online(p_online);
|
person.setP_power(p_power);
|
int exist = labelService.labelDeliver_exist(p_tagid);
|
if (exist > 0) {
|
labelService.labelDeliver_modify(person);
|
} else {
|
labelService.labelDeliver_add(person);
|
}
|
labelService.labelManagement_state(p_name, p_tagid);
|
}
|
|
@RequestMapping(value = "/labelDeliver_remove.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelDeliver_remove(HttpServletRequest request) {
|
String p_tagid = request.getParameter("p_tagid");
|
String p_name = "未绑定";
|
tb_person person = new tb_person();
|
person.setP_tagid(p_tagid);
|
person.setP_name(p_name);
|
person.setP_sex(request.getParameter("p_sex"));
|
person.setP_minzu(request.getParameter("p_minzu"));
|
person.setP_phone(request.getParameter("p_phone"));
|
person.setP_department(request.getParameter("p_department"));
|
person.setP_idcardnum(request.getParameter("p_idcardnum"));
|
person.setP_adress(request.getParameter("p_adress"));
|
int exist = labelService.labelDeliver_exist(p_tagid);
|
if (exist > 0) {
|
labelService.labelDeliver_modify(person);
|
labelService.labelManagement_state(p_name, p_tagid);
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelDeliver_conn.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelDeliver_conn(HttpServletRequest request) {
|
JSONObject json = new JSONObject();
|
List<tb_adress_and_port> adress_and_port = labelService.getAdress_and_port();
|
String result = "0";
|
String state = IDcard.chushi(adress_and_port);
|
if (("发卡设备准备就绪...").equals(state)) {
|
result = "1";
|
}
|
json.put("result", result);
|
json.put("port", adress_and_port.get(0).getPort());
|
json.put("btl", adress_and_port.get(0).getBaoliu());
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelDeliver_readIDcard.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelDeliver_readIDcard(HttpServletRequest request) {
|
JSONObject json = new JSONObject();
|
List<tb_adress_and_port> adress_and_port = labelService.getAdress_and_port();
|
String result;
|
String state = IDcard.chushi(adress_and_port);
|
String idcard = "";
|
String imageStr = "";
|
if (("发卡设备准备就绪...").equals(state)) {
|
int i = 0;
|
// 卡认证
|
while (i < 3) {
|
boolean rz = IDcard.CVR_Authenticate();
|
if (rz) {
|
i = 8;
|
System.out.println("卡认证成功...");
|
break;
|
} else {
|
try {
|
Thread.sleep(3000);
|
} catch (InterruptedException e1) {
|
e1.printStackTrace();
|
}
|
System.out.println(i + "请放身份证...");
|
result = i + "请放身份证...";
|
i++;
|
}
|
}
|
|
if (i == 8) {
|
result = "卡认证成功...";
|
if (IDcard.RedaCard() == 1) {
|
idcard = IDcard.name + "_";
|
idcard = IDcard.sex + "_";
|
idcard = IDcard.minzu + "_";
|
idcard = IDcard.chushengdate + "_";
|
idcard = IDcard.startdate + "-" + IDcard.jizhidate + "_";
|
idcard = IDcard.idnum + "_";
|
idcard = IDcard.address + "_";
|
idcard = IDcard.fazhengjiguan;
|
}
|
try {
|
bmpToJPG.bmp2jpg();
|
} catch (IOException e1) {
|
e1.printStackTrace();
|
}
|
// 身份证照片
|
// image.setIcon(bmpToJPG.getImages());
|
ImageIcon images = bmpToJPG.getImages();
|
Image image = images.getImage();
|
imageStr = image.toString();
|
} else {
|
result = "卡认证失败...";
|
}
|
} else {
|
result = "发卡设备状态不正常!请先连接设备...";
|
}
|
json.put("idcard", idcard);
|
json.put("result", result);
|
json.put("image", imageStr);
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labelDeliver_readPoscard.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String labelDeliver_readPoscard(HttpServletRequest request) {
|
JSONObject json = new JSONObject();
|
List<tb_adress_and_port> adress_and_port = labelService.getAdress_and_port();
|
String rfidnum = "";
|
if(IDcard.M1_MF_HL_Request(adress_and_port)==144) {
|
rfidnum=String.valueOf(IDcard.kaohao);
|
};
|
json.put("rfidnum", rfidnum);
|
return json.toString();
|
}
|
|
@RequestMapping(value = "/labelDeliver_savePort.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void labelDeliver_savePort(HttpServletRequest request) throws IOException {
|
String p_port = request.getParameter("p_port");
|
String p_btl = request.getParameter("p_btl");
|
tb_adress_and_port port = new tb_adress_and_port();
|
port.setBaoliu(p_port);
|
port.setBaoliu2(p_btl);
|
port.setName("faka ");
|
labelService.updateAdress_and_port(port);
|
}
|
|
@RequestMapping(value = "/realTimePower.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String realTimePower(HttpServletRequest request) {
|
String toPage = "forward:/hxzk/label/realTimePower.jsp";
|
List<tb_tagpower> realTimePowerList = labelService.getRealTimePower(1);
|
request.setAttribute("realTimePowerList", realTimePowerList);
|
int curPage = 1;
|
int count = labelService.getRealTimePowerCount();
|
int minPage = PageUtil.getMinPage(count);
|
request.setAttribute("pageList", PageUtil.getPage(minPage));
|
request.setAttribute("curPage", curPage);
|
return toPage;
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/realTimePower_search.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String realTimePower_search(HttpServletRequest request) {
|
String input = request.getParameter("input");
|
int curPage = 1;
|
List<Integer> pageList = new ArrayList<Integer>();
|
List<vo_tp_t_p> realTimePowerList = labelService.searchRealTimePower(input);
|
pageList.add(1);
|
JSONObject json = new JSONObject();
|
json.put("dataList", realTimePowerList);
|
json.put("pageList", pageList);
|
json.put("curPage", curPage);
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/realTimePower_page.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String realTimePower_page(HttpServletRequest request) {
|
String pageStr = request.getParameter("page");
|
String curPageStr = request.getParameter("curPage");
|
int count = labelService.getRealTimePowerCount();
|
int minPage = PageUtil.getMinPage(count);
|
int curPage = Integer.parseInt(curPageStr);
|
int page = 1;
|
if ("pre".equals(pageStr)) {
|
if (curPage > 1) {
|
page = curPage - 1;
|
}
|
} else if ("next".equals(pageStr)) {
|
if (curPage < minPage) {
|
page = curPage + 1;
|
}
|
} else {
|
page = Integer.parseInt(pageStr);
|
}
|
List<tb_tagpower> realTimePowerList = labelService.getRealTimePower(page);
|
List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
|
JSONObject json = new JSONObject();
|
json.put("dataList", realTimePowerList);
|
json.put("pageList", pageList);
|
json.put("curPage", page);
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/realTimePower_export.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String realTimePower_export(HttpServletRequest request, HttpServletResponse response) {
|
String toPage = "forward:/hxzk/label/realTimePower.jsp";
|
List<vo_tp_t_p> realTimePowerList = labelService.getRealTimePower();
|
String[] rowName = { "姓名", "标签ID", "标签频率(HZ)", "电量%", "更新时间" };
|
List<Object[]> dataList = objectToArray_realTimePower(realTimePowerList);
|
ExcelUtils excel = new ExcelUtils("实时电量", rowName, dataList);
|
OutputStream out;
|
try {
|
String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
|
String headStr = "attachment; filename=\"" + fileName + "\"";
|
response.setContentType("APPLICATION/OCTET-STREAM");
|
response.setHeader("Content-Disposition", headStr);
|
out = response.getOutputStream();
|
excel.export(out);
|
out.flush();
|
out.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return toPage;
|
}
|
|
// vo_tp_t_p 导出表格 对象转数组
|
public static List<Object[]> objectToArray_realTimePower(List<vo_tp_t_p> vo_tp_t_pList) {
|
List<Object[]> reList = new ArrayList<>();
|
for (int i = 0; i < vo_tp_t_pList.size(); i++) {
|
List<String> words = new ArrayList<String>();
|
vo_tp_t_p tp_t_p = (vo_tp_t_p) vo_tp_t_pList.get(i);
|
words.add(tp_t_p.getP_name());
|
words.add(tp_t_p.getTagid());
|
words.add(tp_t_p.getPinglv());
|
words.add(tp_t_p.getPower());
|
words.add(tp_t_p.getTime());
|
String[] array = words.toArray(new String[0]);
|
reList.add(array);
|
}
|
return reList;
|
}
|
|
@RequestMapping(value = "/historicalPower.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String historicalPower(HttpServletRequest request) {
|
String toPage = "forward:/hxzk/label/historicalPower.jsp";
|
List<tb_history_power> historicalPowerList = labelService.getHistoricalPower(1);
|
request.setAttribute("historicalPowerList", historicalPowerList);
|
int curPage = 1;
|
int count = labelService.getHistoricalPowerCount();
|
int minPage = PageUtil.getMinPage(count);
|
request.setAttribute("pageList", PageUtil.getPage(minPage));
|
request.setAttribute("curPage", curPage);
|
return toPage;
|
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/historicalPower_search.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String historicalPower_search(HttpServletRequest request) {
|
String input = request.getParameter("input");
|
int curPage = 1;
|
List<Integer> pageList = new ArrayList<Integer>();
|
List<tb_history_power> historicalPowerList = labelService.searchHistoricalPower(input);
|
pageList.add(1);
|
JSONObject json = new JSONObject();
|
json.put("dataList", historicalPowerList);
|
json.put("pageList", pageList);
|
json.put("curPage", curPage);
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/historicalPower_powerAnalysis.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String historicalPower_powerAnalysis(HttpServletRequest request) throws Exception {
|
String input = request.getParameter("input");
|
int curPage = 1;
|
List<Integer> pageList = new ArrayList<Integer>();
|
List<tb_history_power> historicalPowerList = labelService.searchPowerAnalysis(input);
|
String sysPath = request.getServletContext().getRealPath("/");
|
LineXy.getJFreeChart_hp(input, historicalPowerList,sysPath);
|
pageList.add(1);
|
JSONObject json = new JSONObject();
|
String filePath = "hxzk/image/powerAnalysis/" + input + "电量分析.jpeg";
|
json.put("dataList", historicalPowerList);
|
json.put("pageList", pageList);
|
json.put("curPage", curPage);
|
json.put("path", filePath);
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/historicalPower_page.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String historicalPower_page(HttpServletRequest request) {
|
String pageStr = request.getParameter("page");
|
String curPageStr = request.getParameter("curPage");
|
int count = labelService.getHistoricalPowerCount();
|
int minPage = PageUtil.getMinPage(count);
|
int curPage = Integer.parseInt(curPageStr);
|
int page = 1;
|
if ("pre".equals(pageStr)) {
|
if (curPage > 1) {
|
page = curPage - 1;
|
}
|
} else if ("next".equals(pageStr)) {
|
if (curPage < minPage) {
|
page = curPage + 1;
|
}
|
} else {
|
page = Integer.parseInt(pageStr);
|
}
|
List<tb_history_power> historicalPowerList = labelService.getHistoricalPower(page);
|
List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
|
JSONObject json = new JSONObject();
|
json.put("dataList", historicalPowerList);
|
json.put("pageList", pageList);
|
json.put("curPage", page);
|
return json.toString();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/historicalPower_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void historicalPower_delete(HttpServletRequest request) {
|
String checkValStr = request.getParameter("checkVal");
|
checkValStr = checkValStr.replaceAll("\"", "");
|
String[] checkVal = checkValStr.split(",");
|
labelService.historicalPower_delete(checkVal);
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/historicalPower_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void historicalPower_deleteAll(HttpServletRequest request) {
|
labelService.historicalPower_deleteAll();
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/historicalPower_export.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public String historicalPower_export(HttpServletRequest request, HttpServletResponse response) {
|
String toPage = "forward:/hxzk/label/historicalPower.jsp";
|
List<tb_history_power> historicalPowerList = labelService.getHistoricalPower();
|
String[] rowName = { "序号", "标签ID", "电量%", "时间" };
|
List<Object[]> dataList = objectToArray_historicalPower(historicalPowerList);
|
ExcelUtils excel = new ExcelUtils("历史电量", rowName, dataList);
|
OutputStream out;
|
try {
|
String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
|
String headStr = "attachment; filename=\"" + fileName + "\"";
|
response.setContentType("APPLICATION/OCTET-STREAM");
|
response.setHeader("Content-Disposition", headStr);
|
out = response.getOutputStream();
|
excel.export(out);
|
out.flush();
|
out.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return toPage;
|
}
|
|
// tb_history_power 导出表格 对象转数组
|
public static List<Object[]> objectToArray_historicalPower(List<tb_history_power> history_powerList) {
|
List<Object[]> reList = new ArrayList<>();
|
for (int i = 0; i < history_powerList.size(); i++) {
|
List<String> words = new ArrayList<String>();
|
tb_history_power history_power = (tb_history_power) history_powerList.get(i);
|
words.add(history_power.getId() + "");
|
words.add(history_power.getTagid());
|
words.add(history_power.getPower());
|
words.add(history_power.getTime());
|
String[] array = words.toArray(new String[0]);
|
reList.add(array);
|
}
|
return reList;
|
}
|
|
// 报文收取 改标签的状态和电量信息
|
@RequestMapping(value = "/label_bw_power.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public void label_bw_power(HttpServletRequest request) throws IOException {
|
String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
|
tb_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class);
|
// 显示sql
|
String sqlString = "UPDATE tb_tag SET power=" + tag.getPower() + " WHERE tag_id=" + tag.getTag_id();
|
String messageJson = GetNowTime.timestamp2()+ " 收:"+ sqlString ;
|
String BaowenPath = Config.getBaowenConfig();
|
String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
|
if (baowenStatus.equals("1")){
|
/* Udp_Receive.mysqlMessage.add(messageJson); */
|
}
|
//
|
labelService.label_bw_power(tag);
|
}
|
|
@ResponseBody
|
@RequestMapping(value = "/labeltag_id_search.do", method = { RequestMethod.POST, RequestMethod.GET })
|
public int labeltag_id_search(HttpServletRequest request) throws IOException {
|
JSONObject json = new JSONObject();
|
String tag_id = request.getParameter("tag_id");
|
List<tb_tag> labelManagementList = null;
|
int nn;
|
if (("").equals(tag_id) || tag_id == null) {
|
String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
|
tb_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class);
|
tag_id = tag.getTag_id();
|
labelManagementList = labelService.searchLabelManagement(tag_id);
|
if (labelManagementList.size() > 0) {
|
json.put("result", labelManagementList.get(0));
|
} else {
|
json.put("result", "null");
|
}
|
|
} else {
|
int curPage = 1;
|
List<Integer> pageList = new ArrayList<Integer>();
|
labelManagementList = labelService.searchLabelManagement(tag_id);
|
pageList.add(1);
|
json.put("dataList", labelManagementList);
|
json.put("pageList", pageList);
|
json.put("curPage", curPage);
|
}
|
if(null == labelManagementList || labelManagementList.size() ==0 ) {
|
nn=0;
|
}else {
|
nn=1;
|
}
|
return nn;
|
}
|
}
|