yzt
2023-05-08 24e1c6a1c3d5331b5a4f1111dcbae3ef148eda1a
src/main/java/com/hxzkoa/controller/HelmetController.java
@@ -1,13 +1,23 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.hxzkoa.controller;
import com.hxzkoa.json.R;
import com.hxzkoa.json.tb_person;
import com.hxzkoa.json.tb_tag;
import com.hxzkoa.services.BasicInfoService;
import com.hxzkoa.services.HelmetService;
import com.hxzkoa.services.LabelService;
import com.hxzkoa.services.SysSettingService;
import com.hxzkoa.tools.SocketUtil;
import com.hxzkoa.util.Config;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,97 +25,194 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.hxzkoa.json.R;
import com.hxzkoa.json.tb_system;
import com.hxzkoa.services.HelmetService;
import com.hxzkoa.services.SysSettingService;
import com.hxzkoa.tools.SocketUtil;
@Controller
public class HelmetController {
   @Autowired
   HelmetService helmetService;
   @Autowired
   SysSettingService sysSettingService;
   @ResponseBody
   @RequestMapping(value="warning.do",method={RequestMethod.POST,RequestMethod.GET})
   public R warning(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      String type = request.getParameter("type");
      switch(type) {
      case "offhat":
         helmetService.offhat(tagid, "1");
         break;
      case "smash":
         helmetService.smash(tagid, "1");
         break;
      case "stopmoving":
         helmetService.stopmoving(tagid,"1");
         break;
      case "high":
         helmetService.high(tagid,"1");
         break;
      case "nearele":
         helmetService.nearele(tagid,"1");
      }
      return R.ok();
   @Autowired
   LabelService labelservice;
   @Autowired
   BasicInfoService basicInfoService;
   public HelmetController() {
   }
   @ResponseBody
   @RequestMapping(value="video.do",method={RequestMethod.POST})
    public R video(MultipartFile file,HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
        File filen = new File(request.getServletContext().getRealPath("/")+"hxzk\\image\\video\\"+tagid+"."+file.getContentType().split("/")[1]);
        if (!file.isEmpty()) {
            try {
               file.transferTo(filen);
               helmetService.video(tagid, tagid+"."+file.getContentType().split("/")[1]);
               return R.ok();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else {
         return R.error("文件不能为空");
        }
    }
   @ResponseBody
   @RequestMapping(value="audio.do",method={RequestMethod.POST})
    public R audio(MultipartFile file,HttpServletRequest request) {
   @RequestMapping(
         value = {"warning.do"},
         method = {RequestMethod.POST, RequestMethod.GET}
   )
   public R warning(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
        File filen = new File(request.getServletContext().getRealPath("/")+"hxzk\\image\\audio\\"+tagid+"."+file.getContentType().split("/")[1]);
        if (!file.isEmpty()) {
            try {
               file.transferTo(filen);
               helmetService.audio(tagid, tagid+"."+file.getContentType().split("/")[1]);
               return R.ok();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else {
         return R.error("文件不能为空");
        }
    }
      switch (request.getParameter("type")) {
         case "offhat":
            this.helmetService.offhat(tagid, "1");
            break;
         case "smash":
            this.helmetService.smash(tagid, "1");
            break;
         case "stopmoving":
            this.helmetService.stopmoving(tagid, "1");
            break;
         case "high":
            this.helmetService.high(tagid, "1");
            break;
         case "nearele":
            this.helmetService.nearele(tagid, "1");
      }
      return R.ok();
   }
   @ResponseBody
   @RequestMapping(value="setgps.do",method={RequestMethod.POST})
   @RequestMapping(
         value = {"video.do"},
         method = {RequestMethod.POST}
   )
   public R video(MultipartFile file, HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      File filen = new File(request.getServletContext().getRealPath("/") + "hxzk\\image\\video\\" + tagid + "." + file.getContentType().split("/")[1]);
      if (!file.isEmpty()) {
         try {
            file.transferTo(filen);
            this.helmetService.video(tagid, tagid + "." + file.getContentType().split("/")[1]);
            return R.ok();
         } catch (IOException var6) {
            throw new RuntimeException(var6);
         }
      } else {
         return R.error("文件不能为空");
      }
   }
   @ResponseBody
   @RequestMapping(
         value = {"audio.do"},
         method = {RequestMethod.POST}
   )
   public R audio(MultipartFile file, HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      File filen = new File(request.getServletContext().getRealPath("/") + "hxzk\\image\\audio\\" + tagid + "." + file.getContentType().split("/")[1]);
      if (!file.isEmpty()) {
         try {
            file.transferTo(filen);
            this.helmetService.audio(tagid, tagid + "." + file.getContentType().split("/")[1]);
            return R.ok();
         } catch (IOException var6) {
            throw new RuntimeException(var6);
         }
      } else {
         return R.error("文件不能为空");
      }
   }
   @ResponseBody
   @RequestMapping(
         value = {"image.do"},
         method = {RequestMethod.POST}
   )
   public R image(MultipartFile file, HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      File filen = new File(request.getServletContext().getRealPath("/") + "hxzk\\image\\image\\" + tagid + "." + file.getContentType().split("/")[1]);
      if (!file.isEmpty()) {
         try {
            file.transferTo(filen);
            this.helmetService.image(tagid, tagid + "." + file.getContentType().split("/")[1]);
            return R.ok();
         } catch (IOException var6) {
            throw new RuntimeException(var6);
         }
      } else {
         return R.error("文件不能为空");
      }
   }
   @ResponseBody
   @RequestMapping(
         value = {"setgps.do"},
         method = {RequestMethod.POST}
   )
   public R setgps(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      String lon = request.getParameter("lon");
      String lat = request.getParameter("lat");
      helmetService.setgps(tagid,lon,lat);
      this.helmetService.setgps(tagid, lon, lat);
      return R.ok();
   }
   @ResponseBody
   @RequestMapping(value="sendmsg.do", method={RequestMethod.POST,RequestMethod.GET})
   @RequestMapping(
         value = {"sendmsg.do"},
         method = {RequestMethod.POST, RequestMethod.GET}
   )
   public R sendmsg(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      String message = request.getParameter("message");
      message = tagid+":"+message;
      new SocketUtil().sendmsg(message);
      message = tagid + ":" + message;
      (new SocketUtil()).sendmsg(message);
      return R.ok();
   }
   @ResponseBody
   @RequestMapping(
         value = {"addtagid.do"},
         method = {RequestMethod.POST, RequestMethod.GET}
   )
   public R addtagid(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      List<tb_tag> tag = this.labelservice.searchLabelManagement(tagid);
      if (tag.size() == 0) {
         tb_tag taga = new tb_tag();
         taga.setTag_id(tagid);
         taga.setState(request.getParameter("name"));
         taga.setGaodu("150");
         taga.setSudu("1000");
         taga.setPinglv("1");
         taga.setVersion(Config.getVersion());
         this.labelservice.labelManagement_add(taga);
         tb_person person = new tb_person();
         person.setP_tagid(taga.getTag_id());
         person.setP_name(taga.getState());
         person.setP_power("100");
         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");
         this.basicInfoService.personManagement_add(person);
      }
      return R.ok();
   }
   @ResponseBody
   @RequestMapping(
         value = {"playstop.do"},
         method = {RequestMethod.POST, RequestMethod.GET}
   )
   public R playstop(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      String type = request.getParameter("type");
      String filename = this.helmetService.removefile(tagid, type);
      File file;
      if (type.equals("baoliu30")) {
         file = new File(request.getServletContext().getRealPath("/") + "hxzk\\image\\video\\" + filename);
         file.delete();
      } else {
         file = new File(request.getServletContext().getRealPath("/") + "hxzk\\image\\audio\\" + filename);
         file.delete();
      }
      this.helmetService.guanbi(tagid, type);
      return R.ok();
   }
}