| | |
| | | package com.moral.monitor.controller;
|
| | |
|
| | | import com.moral.monitor.entity.Equipment;
|
| | | import com.moral.monitor.entity.User;
|
| | | import com.moral.monitor.entity.apientity.*;
|
| | | import com.moral.monitor.listener.message.Captcha;
|
| | | import com.moral.monitor.service.ApiService;
|
| | | import com.moral.monitor.util.ApiData;
|
| | | import com.moral.monitor.util.DateConvert;
|
| | | import com.taobao.api.ApiException;
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | | import java.sql.Connection;
|
| | | import java.sql.DriverManager;
|
| | | import java.sql.SQLException;
|
| | | import java.sql.Statement;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.apache.log4j.Logger;
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.CrossOrigin;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.bind.annotation.ResponseBody;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.moral.monitor.entity.Equipment;
|
| | | import com.moral.monitor.entity.EquipmentExample;
|
| | | import com.moral.monitor.entity.MonitorPoint;
|
| | | import com.moral.monitor.entity.MonitorPointExample;
|
| | | import com.moral.monitor.entity.Organization;
|
| | | import com.moral.monitor.entity.OrganizationExample;
|
| | | import com.moral.monitor.entity.User;
|
| | | import com.moral.monitor.entity.apientity.ApiEquipment;
|
| | | import com.moral.monitor.entity.apientity.ApiEquipmentInfo;
|
| | | import com.moral.monitor.entity.apientity.ApiUser;
|
| | | import com.moral.monitor.entity.apientity.RepairQuery;
|
| | | import com.moral.monitor.entity.apientity.Report;
|
| | | import com.moral.monitor.listener.message.Captcha;
|
| | | import com.moral.monitor.service.ApiService;
|
| | | import com.moral.monitor.service.EquipmentService;
|
| | | import com.moral.monitor.service.MonitorpointService;
|
| | | import com.moral.monitor.service.OrganizationService;
|
| | | import com.moral.monitor.util.ApiData;
|
| | | import com.moral.monitor.util.Crypto;
|
| | | import com.moral.monitor.util.DateConvert;
|
| | | import com.taobao.api.ApiException;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | /**
|
| | | * Created by a on 2017/4/24.
|
| | |
| | | @Controller
|
| | | @CrossOrigin(origins = "*", maxAge = 3600)
|
| | | public class ApiController {
|
| | | private static Logger log = Logger.getLogger(ApiController.class);
|
| | | @Resource
|
| | | ApiService apiService;
|
| | |
|
| | | //11终端采集
|
| | | @RequestMapping(value = "reportDevice")
|
| | | @ResponseBody
|
| | |
| | | @RequestParam(value ="address") String address,
|
| | | @RequestParam(value ="longitude") String longitude,
|
| | | @RequestParam(value ="latitude") String latitude,
|
| | | @RequestParam(value ="mac") String mac ){
|
| | |
|
| | | try {
|
| | | System.out.println("");
|
| | | System.out.println("");
|
| | | System.out.println("");
|
| | | request.setCharacterEncoding("UTF-8");
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | @RequestParam(value ="mac") String mac,
|
| | | @RequestParam(value ="monitorpoint") String monitorpoint,
|
| | | @RequestParam(value ="ownerId") String ownerId
|
| | | ){
|
| | | //插入或更新设备表信息
|
| | | ApiData apiData = new ApiData();
|
| | | if(StringUtils.isBlank(mac)){
|
| | |
| | | apiData.setErrno(0);
|
| | | return apiData;
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | Equipment equipment = apiService.selectFromequipmentBymac(mac);
|
| | | if (equipment==null){
|
| | | if (StringUtils.isBlank(longitude)){ longitude="0"; }
|
| | | if (StringUtils.isBlank(latitude)) { latitude="0"; }
|
| | | //插入
|
| | | apiService.insertIntoequipment(device_name,address,longitude,latitude,uid,mac);
|
| | | if (StringUtils.isBlank(longitude)){ longitude="0"; }
|
| | | if (StringUtils.isBlank(latitude)) { latitude="0"; }
|
| | | Equipment equipment =new Equipment();
|
| | | equipment.setInstaller(uid);
|
| | | equipment.setName(device_name);
|
| | | equipment.setAddress(address);
|
| | | equipment.setLongitude(Double.valueOf(longitude));
|
| | | equipment.setLatitude(Double.valueOf(latitude));
|
| | | equipment.setMac(mac);
|
| | | equipment.setMonitorpoint(monitorpoint);
|
| | | equipment.setOwnerId(ownerId);
|
| | | //添加时间
|
| | | equipment.setTime(new Date());
|
| | | EquipmentExample example = new EquipmentExample();
|
| | | example.or().andMacEqualTo(mac);
|
| | | long count = equipmentService.queryCountByExample(example);
|
| | | |
| | | if (count==0){ //插入
|
| | | equipmentService.insertRecord(equipment);
|
| | | apiData.setData("");
|
| | | apiData.setMessage("添加设备成功");
|
| | | apiData.setErrno(0);
|
| | | return apiData;
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | //更新
|
| | | if (!StringUtils.isBlank(mac)) {
|
| | |
|
| | | if (StringUtils.isBlank(longitude)){ longitude="0"; }
|
| | | if (StringUtils.isBlank(latitude)) { latitude="0"; }
|
| | |
|
| | | } else { //更新
|
| | | apiService.updateFromequipmentBymac(device_name, address, longitude, latitude, uid, mac);
|
| | | apiData.setData("");
|
| | | equipmentService.updateByMac(equipment);
|
| | | apiData.setMessage("更新设备成功");
|
| | | apiData.setErrno(0);
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | return null;
|
| | | /////////////////////////////////////////////////////////
|
| | | // 更新 - 新版本后台数据库
|
| | | updateLocation(device_name, address, mac, longitude, latitude);
|
| | | /////////////////////////////////////////////////////////
|
| | | }
|
| | | return apiData;
|
| | | }
|
| | |
|
| | |
|
| | | public void updateLocation(String device, String address, String mac, String lng, String lat) {
|
| | | Connection conn = null;
|
| | | String sql;
|
| | | String url = "jdbc:mysql://172.16.206.7:3306/monitor_db?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&user=root&password=xOlx8z9L7Pt6y9YI";
|
| | | try {
|
| | | Class.forName("com.mysql.jdbc.Driver");
|
| | | conn = DriverManager.getConnection(url);
|
| | | Statement stmt = conn.createStatement();
|
| | | sql = "UPDATE device SET `name`='" + device + "', address='" + address + "', longitude='" + lng + "', latitude='" + lat + "' WHERE mac='" + mac + "'";
|
| | | System.out.println(sql);
|
| | | int result = stmt.executeUpdate(sql);
|
| | | System.out.println("Update the location of the equipment: " + result);
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | try {
|
| | | conn.close();
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //1登录
|
| | | @RequestMapping(value = "accountlogin")
|
| | |
| | | ApiData apiData = new ApiData();
|
| | |
|
| | | //查找用户
|
| | | User user = apiService.selectFromuserBynameAndpassword(username, password);//username为mobile
|
| | | User user = apiService.selectFromuserBynameAndpassword(username, Crypto.md5(password));//username为mobile
|
| | | if (user==null){
|
| | | apiData.setErrno(1);
|
| | | apiData.setMessage("登陆失败,账号或密码错误");
|
| | |
| | | }
|
| | |
|
| | | if (user.getCode().equals(code)){
|
| | | apiService.updateuserByid(password,String.valueOf(user.getId()));
|
| | | apiService.updateuserByid(Crypto.md5(password),String.valueOf(user.getId()));
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("重置密码成功");
|
| | | apiData.setData("{}");
|
| | |
| | | public ApiData upPassword(String uid,String password,String newpassword){
|
| | | ApiData apiData = new ApiData();
|
| | | //根据uid 和 password 查找用户
|
| | | User user = apiService.selectFromuserByidAndpassword(uid, password);
|
| | | User user = apiService.selectFromuserByidAndpassword(uid, Crypto.md5(password));
|
| | | JSONObject jsonObject = JSONObject.fromObject(user);
|
| | | String s = jsonObject.toString();
|
| | |
|
| | | if (user!=null){
|
| | | //更新password字段
|
| | | apiService.updateuserByid(newpassword,uid);
|
| | | apiService.updateuserByid(Crypto.md5(newpassword),uid);
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("修密码改成功");
|
| | | apiData.setData(s);
|
| | |
| | | ae.setDevice_name(e.getName());
|
| | | ae.setMac(e.getMac());
|
| | | ae.setStatus(e.getState());
|
| | | ae.setFei(e.getFei());
|
| | | // ae.setFei(e.get);
|
| | | // ae.setCreate_time(DateConvert.dateConvert(e.getTime()));
|
| | | apiEquipments.add(ae);
|
| | |
|
| | |
| | | ae.setDevice_name(e.getName());
|
| | | ae.setMac(e.getMac());
|
| | | ae.setStatus(e.getState());
|
| | | ae.setFei(e.getFei());
|
| | | // ae.setFei(e.getFei());
|
| | | ae.setCreate_time(DateConvert.dateConvert(e.getTime()));
|
| | | apiEquipments.add(ae);
|
| | |
|
| | |
| | | apiData.setData(s);
|
| | | return apiData;
|
| | | }
|
| | | @Resource
|
| | | private EquipmentService equipmentService;
|
| | | //11、根据mac地址获取设备信息,没有数据则为空
|
| | | @RequestMapping(value = "getEquInfoByMac")
|
| | | @ResponseBody |
| | | public ApiData getEquInfoByMac(String mac) {
|
| | | ApiData apiData = new ApiData();
|
| | | try {
|
| | | if(!StringUtils.isEmpty(mac)) {
|
| | | EquipmentExample example = new EquipmentExample();
|
| | | example.or().andMacEqualTo(mac);
|
| | | List<Equipment> equList = equipmentService.queryListByExample(example);
|
| | | if(equList!=null&&equList.size()>0) {
|
| | | Equipment equipment = equList.get(0);
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("根据mac地址获取设备信息成功");
|
| | | apiData.setData(JSON.toJSONString(equipment));
|
| | | }else {
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("根据mac地址未获取到设备信息");
|
| | | apiData.setData(null);
|
| | | }
|
| | | }else {
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("mac地址不能为空");
|
| | | apiData.setData(null);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | log.error(e);
|
| | | }
|
| | | return apiData;
|
| | | }
|
| | | @Resource
|
| | | private MonitorpointService monitorpointService;
|
| | | //12、根据县级市或者区的名称,获取监控点。
|
| | | @RequestMapping(value = "getMpointsByAreaName")
|
| | | @ResponseBody |
| | | public ApiData getMpointsByAreaName(String areaName) {
|
| | | ApiData apiData = new ApiData();
|
| | | try {
|
| | | if(!StringUtils.isEmpty(areaName)) {
|
| | | MonitorPointExample example = new MonitorPointExample();
|
| | | // example.or().andTbAreaNameEqualTo(areaName);
|
| | | List<MonitorPoint> list = monitorpointService.queryListByExample(example);
|
| | | if(list!=null&&list.size()>0) {
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("根据县级市(或行政区)名称获取数据成功");
|
| | | apiData.setData(JSON.toJSONString(list));
|
| | | }else {
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("该县级市(或行政区)未设置检测点");
|
| | | apiData.setData(null);
|
| | | }
|
| | | }else {
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("县级市(或行政区)名称不能为空");
|
| | | apiData.setData(null);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | log.error(e);
|
| | | }
|
| | | return apiData;
|
| | | }
|
| | | @Resource
|
| | | OrganizationService organizationService;
|
| | | //13、根据县级市或者区的名称,获取组织。
|
| | | @RequestMapping(value = "getOrgsByAreaName")
|
| | | @ResponseBody |
| | | public ApiData getOrgsByAreaName(String areaName) {
|
| | | ApiData apiData = new ApiData();
|
| | | try {
|
| | | if(!StringUtils.isEmpty(areaName)) {
|
| | | OrganizationExample example = new OrganizationExample();
|
| | | example.or().andTbAreaNameEqualTo(areaName).andEnableEqualTo(1);
|
| | | List<Organization> list = organizationService.queryListByExample(example);
|
| | | if(list!=null&&list.size()>0) {
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("该县级市(或行政区)名称获取数据成功");
|
| | | apiData.setData(JSON.toJSONString(list));
|
| | | }else {
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("该县级市(或行政区)未设置组织机构");
|
| | | apiData.setData(null);
|
| | | }
|
| | | }else {
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("县级市(或行政区)名称不能为空");
|
| | | apiData.setData(null);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | log.error(e);
|
| | | }
|
| | | return apiData;
|
| | | }
|
| | | }
|
| | |
|