New file |
| | |
| | | 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 org.apache.commons.lang3.StringUtils;
|
| | | 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;
|
| | |
|
| | | /**
|
| | | * Created by a on 2017/4/24.
|
| | | */
|
| | | @Controller
|
| | | @CrossOrigin(origins = "*", maxAge = 3600)
|
| | | public class ApiController {
|
| | | @Resource
|
| | | ApiService apiService;
|
| | |
|
| | | //11终端采集
|
| | | @RequestMapping(value = "reportDevice")
|
| | | @ResponseBody
|
| | | public ApiData reportDevice(HttpServletRequest request ,
|
| | | @RequestParam(value ="uid") String uid,
|
| | | @RequestParam(value ="device_name") String device_name,
|
| | | @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();
|
| | | }
|
| | | //插入或更新设备表信息
|
| | | ApiData apiData = new ApiData();
|
| | | if(StringUtils.isBlank(mac)){
|
| | | apiData.setData("");
|
| | | apiData.setMessage("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);
|
| | | 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"; }
|
| | |
|
| | | apiService.updateFromequipmentBymac(device_name, address, longitude, latitude, uid, mac);
|
| | | apiData.setData("");
|
| | | apiData.setMessage("更新设备成功");
|
| | | apiData.setErrno(0);
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | //1登录
|
| | | @RequestMapping(value = "accountlogin")
|
| | | @ResponseBody
|
| | | public ApiData login(String username, String password ){
|
| | |
|
| | | ApiData apiData = new ApiData();
|
| | |
|
| | | //查找用户
|
| | | User user = apiService.selectFromuserBynameAndpassword(username, password);//username为mobile
|
| | | if (user==null){
|
| | | apiData.setErrno(1);
|
| | | apiData.setMessage("登陆失败,账号或密码错误");
|
| | | apiData.setData("{}");
|
| | | return apiData;
|
| | |
|
| | | }else {
|
| | | ApiUser apiUser = new ApiUser();
|
| | |
|
| | | apiUser.setUid(user.getId());
|
| | | apiUser.setUsername(user.getName());
|
| | | apiUser.setOrganization_name(user.getOrganization());
|
| | | apiUser.setEmail(user.getEmail());
|
| | | apiUser.setWeixin(user.getWeixin());
|
| | | apiUser.setTel(user.getMobile());
|
| | | apiUser.setUser_type(user.getUser_type());
|
| | | apiUser.setCreate_time(DateConvert.dateConvert(user.getCreate_time()));
|
| | | apiUser.setNickname(user.getNickname());
|
| | |
|
| | | JSONObject json = JSONObject.fromObject(apiUser);
|
| | | String strJson=json.toString();
|
| | |
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("用户登录成功");
|
| | | apiData.setData(strJson);
|
| | | return apiData;
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | //2忘记密码短信接口
|
| | | @RequestMapping(value = "sendSms")
|
| | | @ResponseBody
|
| | | public ApiData sendSms(String mobile){
|
| | | ApiData apiData = new ApiData();
|
| | |
|
| | | if (StringUtils.isBlank(mobile)){
|
| | | apiData.setErrno(1);
|
| | | apiData.setMessage("没有输入手机号码");
|
| | | apiData.setData("{}");
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | //根据mobile 查找用户
|
| | | User user = apiService.selectFromUserBymobile(mobile);
|
| | | if (user==null){
|
| | | apiData.setErrno(1);
|
| | | apiData.setMessage("手机号没有关联用户");
|
| | | apiData.setData("{}");
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | //生成验证码
|
| | | int code = (int) ((Math.random() * 9 + 1) * 100000);
|
| | | //保存或更新
|
| | | apiService.updateusercode(mobile,String.valueOf(code));
|
| | | //发送到手机
|
| | | try {
|
| | | int state = Captcha.captcha(mobile,String.valueOf(code));
|
| | | if(state==0){
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("发送验证码成功");
|
| | | apiData.setData("{}");
|
| | | return apiData;
|
| | |
|
| | | }
|
| | |
|
| | | if(state==1){
|
| | | apiData.setErrno(1);
|
| | | apiData.setMessage("发送验证码失败");
|
| | | apiData.setData("{}");
|
| | | return apiData;
|
| | |
|
| | | }
|
| | |
|
| | | } catch (ApiException e) {
|
| | | e.printStackTrace();
|
| | |
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | |
|
| | | //3忘记密码手机修改密码
|
| | | @RequestMapping(value = "password")
|
| | | @ResponseBody
|
| | | public ApiData password(String username,String password,String code){//username-->mobile
|
| | | ApiData apiData = new ApiData();
|
| | |
|
| | | if (StringUtils.isBlank(code)){
|
| | | apiData.setErrno(1);
|
| | | apiData.setMessage("重置密码失败,没有输出验证码");
|
| | | apiData.setData("{}");
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | //根据mobile 查找用户
|
| | | User user = apiService.selectFromUserBymobile(username);
|
| | | if (user==null){
|
| | | apiData.setErrno(1);
|
| | | apiData.setMessage("重置密码失败,手机号没有关联用户");
|
| | | apiData.setData("{}");
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | if (user.getCode().equals(code)){
|
| | | apiService.updateuserByid(password,String.valueOf(user.getId()));
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("重置密码成功");
|
| | | apiData.setData("{}");
|
| | |
|
| | | int rcode = (int) ((Math.random() * 9 + 1) * 100000);
|
| | | apiService.updateusercode(username,String.valueOf(rcode));
|
| | |
|
| | | return apiData;
|
| | | }else {
|
| | | apiData.setErrno(1);
|
| | | apiData.setMessage("输入验证码不正确");
|
| | | apiData.setData("{}");
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | //4修改密码
|
| | | @RequestMapping(value = "upPassword")
|
| | | @ResponseBody
|
| | | public ApiData upPassword(String uid,String password,String newpassword){
|
| | | ApiData apiData = new ApiData();
|
| | | //根据uid 和 password 查找用户
|
| | | User user = apiService.selectFromuserByidAndpassword(uid, password);
|
| | | JSONObject jsonObject = JSONObject.fromObject(user);
|
| | | String s = jsonObject.toString();
|
| | |
|
| | | if (user!=null){
|
| | | //更新password字段
|
| | | apiService.updateuserByid(newpassword,uid);
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("修密码改成功");
|
| | | apiData.setData(s);
|
| | | return apiData;
|
| | | }
|
| | |
|
| | |
|
| | | apiData.setMessage("旧密码错误修改密码失败");
|
| | | apiData.setData(s);
|
| | | apiData.setErrno(1);
|
| | |
|
| | | return apiData;
|
| | | }
|
| | |
|
| | |
|
| | | //5我安装的设备(分页)
|
| | | @RequestMapping(value = "myRelease")
|
| | | @ResponseBody
|
| | | public ApiData myRelease(String uid,String pageIndex,String pageSize){
|
| | | ApiData apiData = new ApiData();
|
| | |
|
| | | int pindex=Integer.parseInt(pageIndex);
|
| | | int psize=Integer.parseInt(pageSize);
|
| | | int index =(pindex-1)*psize;
|
| | | List<Equipment> equipments = apiService.selectFromequipmentByinstaller(uid,index,psize);
|
| | |
|
| | | if (equipments.size()==0){
|
| | | JSONArray jsonArray1 = JSONArray.fromObject(equipments);
|
| | | String s1 = jsonArray1.toString();
|
| | | apiData.setData(s1);
|
| | | apiData.setMessage("此安装人员没有安装的设备");
|
| | | apiData.setErrno(0);
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | ArrayList<ApiEquipment> apiEquipments = new ArrayList<ApiEquipment>();
|
| | |
|
| | | for(Equipment e: equipments){
|
| | | ApiEquipment ae = new ApiEquipment();
|
| | | ae.setId(e.getId());
|
| | | ae.setDevice_name(e.getName());
|
| | | ae.setMac(e.getMac());
|
| | | ae.setStatus(e.getState());
|
| | | ae.setFei(e.getFei());
|
| | | // ae.setCreate_time(DateConvert.dateConvert(e.getTime()));
|
| | | apiEquipments.add(ae);
|
| | |
|
| | | }
|
| | |
|
| | | JSONArray jsonArray = JSONArray.fromObject(apiEquipments);
|
| | | String s = jsonArray.toString();
|
| | |
|
| | | apiData.setData(s);
|
| | | apiData.setMessage("返回安装的设备");
|
| | | apiData.setErrno(0);
|
| | |
|
| | | return apiData;
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | //6我的运维设备,(分页条件 和 模糊搜索)
|
| | | @RequestMapping(value = "myRepair")
|
| | | @ResponseBody
|
| | | public ApiData myRepair(RepairQuery repairQuery ){
|
| | | ApiData apiData = new ApiData();
|
| | |
|
| | | /* int index=Integer.parseInt(pageIndex);
|
| | | int size=Integer.parseInt(pageSize);
|
| | | int t=Integer.parseInt(type);*/
|
| | |
|
| | | int pageIndex = repairQuery.getPageIndex();
|
| | | int pageSize = repairQuery.getPageSize();
|
| | | int index=(pageIndex-1)*pageSize;
|
| | | repairQuery.setPageIndex(index);
|
| | |
|
| | |
|
| | | List<Equipment> equipments = apiService.selectFromequipmentByrepairman(repairQuery);
|
| | |
|
| | | if (equipments.size()==0){
|
| | | JSONArray jsonArray = JSONArray.fromObject(equipments);
|
| | | String s = jsonArray.toString();
|
| | | apiData.setData(s);
|
| | | apiData.setMessage("此运维人员没有运维的设备");
|
| | | apiData.setErrno(0);
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | ArrayList<ApiEquipment> apiEquipments = new ArrayList<ApiEquipment>();
|
| | |
|
| | | for(Equipment e: equipments){
|
| | | ApiEquipment ae = new ApiEquipment();
|
| | | ae.setId(e.getId());
|
| | | ae.setDevice_name(e.getName());
|
| | | ae.setMac(e.getMac());
|
| | | ae.setStatus(e.getState());
|
| | | ae.setFei(e.getFei());
|
| | | ae.setCreate_time(DateConvert.dateConvert(e.getTime()));
|
| | | apiEquipments.add(ae);
|
| | |
|
| | | }
|
| | |
|
| | | JSONArray jsonArray = JSONArray.fromObject(apiEquipments);
|
| | | String s = jsonArray.toString();
|
| | |
|
| | | apiData.setData(s);
|
| | | apiData.setMessage("返回运维的设备");
|
| | | apiData.setErrno(0);
|
| | |
|
| | | return apiData;
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | //7客户的设备(分页)
|
| | |
|
| | |
|
| | | //8、设备详情,暂时没有客户方面的信息
|
| | | @RequestMapping(value = "deviceInfo")
|
| | | @ResponseBody
|
| | | public ApiData deviceInfo(String id){
|
| | | ApiData apiData = new ApiData();
|
| | | ApiEquipmentInfo apiEquipmentInfo = new ApiEquipmentInfo();
|
| | |
|
| | | Equipment equipment = apiService.selectFromequipmentByid(id);
|
| | |
|
| | |
|
| | | if (equipment==null){
|
| | | JSONObject json = JSONObject.fromObject(equipment);
|
| | | String strJson=json.toString();
|
| | |
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("没有找到这个设备");
|
| | | apiData.setData(strJson);
|
| | | return apiData;
|
| | |
|
| | | }
|
| | |
|
| | | apiEquipmentInfo.setId(equipment.getId());
|
| | | apiEquipmentInfo.setDevice_name(equipment.getName());
|
| | | apiEquipmentInfo.setAddress(equipment.getAddress());
|
| | | apiEquipmentInfo.setMac(equipment.getMac());
|
| | | apiEquipmentInfo.setLongitude(String.valueOf(equipment.getLongitude()));
|
| | | apiEquipmentInfo.setLatitude(String.valueOf(equipment.getLatitude()));
|
| | | apiEquipmentInfo.setCreate_time(DateConvert.dateConvert(equipment.getTime()));
|
| | | apiEquipmentInfo.setStatus(equipment.getState());
|
| | |
|
| | |
|
| | | String installer = equipment.getInstaller();
|
| | | if (!(installer==null||StringUtils.isBlank(installer))){
|
| | | //根据id查找User表
|
| | | User user = apiService.selectFromuserByid(installer);
|
| | | if (user!=null){
|
| | | apiEquipmentInfo.setRelease_uid(String.valueOf(user.getId()));
|
| | | apiEquipmentInfo.setRelease_name(user.getName());
|
| | | }
|
| | | }
|
| | |
|
| | | String repairman = equipment.getRepairman();
|
| | | if(!(repairman==null||StringUtils.isBlank(repairman))){
|
| | | User user = apiService.selectFromuserByid(repairman);
|
| | | if (user!=null){
|
| | | apiEquipmentInfo.setRepair_uid(String.valueOf(user.getId()));
|
| | | apiEquipmentInfo.setRepair_name(user.getName());
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | JSONObject json = JSONObject.fromObject(apiEquipmentInfo);
|
| | | String strJson=json.toString();
|
| | | apiData.setErrno(0);
|
| | | apiData.setData(strJson);
|
| | | apiData.setMessage("返回设备详情数据");
|
| | |
|
| | | return apiData;
|
| | | }
|
| | |
|
| | | //9、上报维修单
|
| | | @RequestMapping(value = "report")
|
| | | @ResponseBody
|
| | | public ApiData report(String uid,String device_mac,String device_name,String device_status,String device_ext,String device_data1,String device_data2){
|
| | | ApiData apiData = new ApiData();
|
| | |
|
| | | if(StringUtils.isBlank(uid)||StringUtils.isBlank(device_mac)){
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("上报维修单失败,没有维护人或没有维护设备");
|
| | | apiData.setData("");
|
| | | return apiData;
|
| | | }
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("上报维修单成功");
|
| | | apiData.setData("");
|
| | | apiService.insertIntoreport(uid, device_mac, device_name, device_status, device_ext, device_data1, device_data2);
|
| | | return apiData;
|
| | | }
|
| | |
|
| | |
|
| | | //10、维修记录(分页)
|
| | | @RequestMapping(value = "reportList")
|
| | | @ResponseBody
|
| | | public ApiData reportList(String uid,String pageIndex,String pageSize){
|
| | | ApiData apiData = new ApiData();
|
| | |
|
| | | int pindex=Integer.parseInt(pageIndex);
|
| | | int psize=Integer.parseInt(pageSize);
|
| | | int index =(pindex-1)*psize;
|
| | |
|
| | | List<Report> reports = apiService.selectAllfromreportByrepaiman(uid,index,psize);
|
| | | for (Report r: reports){
|
| | | String create_time = r.getCreate_time();
|
| | | if (create_time!=null){
|
| | | String substring = create_time.substring(0, create_time.lastIndexOf("."));
|
| | | r.setCreate_time(substring);
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | JSONArray jsonArray = JSONArray.fromObject(reports);
|
| | | String s = jsonArray.toString();
|
| | | apiData.setErrno(0);
|
| | | apiData.setMessage("返回维修记录成功");
|
| | | apiData.setData(s);
|
| | | return apiData;
|
| | | }
|
| | | }
|
| | |
|