package com.moral.monitor.controller;
|
|
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.lang.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import com.alibaba.fastjson.JSON;
|
import com.moral.monitor.entity.AccountEntity;
|
import com.moral.monitor.entity.Equipment;
|
import com.moral.monitor.entity.State;
|
import com.moral.monitor.service.ScreenApiService;
|
import com.moral.monitor.service.ScreenService;
|
import com.moral.monitor.util.Crypto;
|
import com.moral.monitor.util.ScreenApiData;
|
|
/**
|
* Created by a on 2017/7/12.
|
*/
|
@RestController
|
@RequestMapping(value = "screen")
|
public class ScreenApiController {
|
|
@Autowired
|
ScreenApiService screenApiService;
|
|
@Autowired
|
private ScreenService screenService;
|
/**
|
* 所有区域/指定区域 设备状态:总数,正常,离线,报警。返回数量信息
|
* @param area 地区信息,值为空 字符串则查询所有设备
|
* @return
|
*/
|
@RequestMapping(value = "equcount")
|
@ResponseBody
|
public ScreenApiData equstatus(String area){
|
|
area = area.trim();
|
|
ScreenApiData screenApiData = new ScreenApiData();
|
LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
|
|
int total = screenApiService.equstatus_total(area);
|
int ok = screenApiService.equstatus_online(area);
|
int warn = screenApiService.equstatus_warn(area);
|
int offline = screenApiService.equstatus_offline(area);
|
|
map.put("total",total);
|
map.put("ok",ok);
|
map.put("warn",warn);
|
map.put("offline",offline);
|
|
String data = JSON.toJSONString(map);
|
screenApiData.setData(data);
|
return screenApiData;
|
}
|
|
|
/**
|
* 所有/区域 设备列表:总数,正常,离线,报警。返回实体信息列表。 ,
|
* @param area 值为空字符串则查询所有区域
|
* @param pageIndex pageIndex ,pageSize 默认为 1 ,10
|
* @param pageSize
|
* @param status status值约定为 在线 离线 报警,为空字符串则为 查询所有状态
|
* @return
|
*/
|
@RequestMapping(value = "equlist")
|
@ResponseBody
|
public ScreenApiData equlist(String area,String pageIndex,String pageSize,String status){
|
|
area = area.trim();
|
status = status.trim();
|
|
int index=Integer.parseInt(pageIndex);
|
int size=Integer.parseInt(pageSize);
|
index =(index-1)*size;
|
|
List<Equipment> equlist = screenApiService.equlist(area, index, size, status);
|
int total = screenApiService.equlist_size(area, status);
|
|
int totalpages;
|
if (total % size == 0) {
|
totalpages = total / size;
|
} else {
|
totalpages = total / size + 1;
|
}
|
|
ScreenApiData screenApiData = new ScreenApiData();
|
screenApiData.setData(equlist);
|
screenApiData.setExtData(totalpages);
|
return screenApiData;
|
}
|
|
|
/*按名称搜索设备信息。返回实体信息*/
|
@RequestMapping(value = "equinfo")
|
@ResponseBody
|
public ScreenApiData equinfo(String name,String pageIndex,String pageSize){
|
|
int index=Integer.parseInt(pageIndex);
|
int size=Integer.parseInt(pageSize);
|
index =(index-1)*size;
|
|
List<Equipment> equinfo = screenApiService.equinfo(name,index,size);
|
int total = screenApiService.equinfo_size(name);
|
|
int totalpages;
|
if (total % size == 0) {
|
totalpages = total / size;
|
} else {
|
totalpages = total / size + 1;
|
}
|
|
ScreenApiData screenApiData = new ScreenApiData();
|
screenApiData.setData(equinfo);
|
screenApiData.setExtData(totalpages);
|
return screenApiData;
|
|
}
|
|
|
|
/* 设备传感器即时数据 */
|
@RequestMapping(value = "equsensorstate")
|
@ResponseBody
|
public ScreenApiData equsensorstate(String mac){
|
List<State> equsensorstate = screenApiService.equsensorstate(mac);
|
LinkedHashMap<String, Double> map = new LinkedHashMap<String, Double>();
|
for (State s: equsensorstate){
|
map.put(s.getSensor(),s.getMac_value());
|
}
|
String data = JSON.toJSONString(map);
|
ScreenApiData screenApiData = new ScreenApiData();
|
screenApiData.setData(data);
|
return screenApiData;
|
}
|
|
|
|
/**
|
* Screen login.
|
*
|
* @param request the request
|
* @return the map
|
*/
|
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
public Map<String, Object> screenLogin(HttpServletRequest request) {
|
Map<String, Object> resultMap = new HashMap<String, Object>();
|
String msg = "";
|
Integer accountId = -1;
|
String account = request.getParameter("account");
|
String password = request.getParameter("password");
|
if (StringUtils.isBlank(account) || StringUtils.isBlank(password)) {
|
msg = "用户名及密码不允许为空!";
|
} else {
|
try {
|
password = Crypto.md5(password);
|
List<AccountEntity> accountLists = screenService.getAccountLists(account, password);
|
if (CollectionUtils.isEmpty(accountLists) || accountLists.size() != 1) {
|
msg = "用户名及密码输入错误!";
|
} else {
|
AccountEntity accountEntity = accountLists.get(0);
|
if ("1".equals(accountEntity.getEnable())) {
|
msg = "登录成功!";
|
accountId = accountEntity.getId();
|
} else {
|
msg = "您的账号已禁用,请联系管理员!";
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
msg = "系统正忙,请稍后再试!";
|
}
|
}
|
resultMap.put("msg", msg);
|
resultMap.put("accountId", accountId);
|
return resultMap;
|
}
|
|
}
|