123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- package com.jjt.biz.controller;
- import com.jjt.biz.domain.*;
- import com.jjt.biz.service.*;
- import com.jjt.biz.vo.*;
- import com.jjt.common.annotation.Log;
- import com.jjt.common.config.RuoYiConfig;
- import com.jjt.common.core.controller.BaseController;
- import com.jjt.common.core.domain.AjaxResult;
- import com.jjt.common.core.page.TableDataInfo;
- import com.jjt.common.core.redis.RedisCache;
- import com.jjt.common.enums.BusinessType;
- import com.jjt.common.utils.StringUtils;
- import com.jjt.common.utils.file.FileUploadUtils;
- import com.jjt.common.utils.file.FileUtils;
- import com.jjt.common.utils.poi.ExcelUtil;
- import com.jjt.common.utils.sign.Base64;
- import com.jjt.common.utils.spring.SpringUtils;
- import com.jjt.framework.config.ServerConfig;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletResponse;
- import java.nio.charset.StandardCharsets;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- /**
- * 关键字Controller
- *
- * @author ruoyi
- * @date 2023-07-06
- */
- @RestController
- @RequestMapping("/api")
- public class ApiController extends BaseController {
- @Resource
- private IDeviceInfoService deviceInfoService;
- @Resource
- private IWifiInfoService wifiInfoService;
- @Resource
- private IBluetoothInfoService bluetoothInfoService;
- @Resource
- private IVenueInfoService venueInfoService;
- @Resource
- private IVenueAreaService areaService;
- @Resource
- private ServerConfig serverConfig;
- @Resource
- private IKeyInfoService keyInfoService;
- /**
- * 设备注册接口
- */
- @PostMapping("/device")
- public AjaxResult device(@RequestBody DeviceInfo deviceInfo) {
- deviceInfo.setRegisterTime(new Date());
- int i = 0;
- try {
- i = deviceInfoService.insertDeviceInfo(deviceInfo);
- } catch (Exception e) {
- if (e.getMessage().contains("Duplicate entry")) {
- return AjaxResult.error("DEVICE_ID重复");
- } else {
- return AjaxResult.error(e.getMessage());
- }
- }
- return toAjax(1);
- }
- /**
- * WIFI上传
- */
- @PostMapping("/wifi")
- public AjaxResult wifi(@RequestBody List<WifiInfoVO> infoList) {
- keyInfoList = keyInfoService.selectKeyInfoList(new KeyInfo());
- infoList.forEach(vo -> {
- WifiInfo info = new WifiInfo();
- info.setDeviceId(vo.getDeviceId());
- String[] vaId = vo.getVenueId().split("-");
- Long vId = Long.parseLong(vaId[0]);
- info.setVenueId(vId);
- info.setIsIllegal("N");
- if (vaId.length > 1) {
- Long aId = Long.parseLong(vaId[1]);
- info.setAreaId(aId);
- }
- if (StringUtils.isNotEmpty(vo.getAuthPage())) {
- String page = new String(Base64.decode(vo.getAuthPage()), StandardCharsets.UTF_8);
- IllegalVO illegal = isIllegal(page);
- if (illegal.isIllegal()) {
- info.setIsIllegal("Y");
- info.setKeyType(illegal.getKeyType());
- }
- isIllegal(vo.getSsid());
- info.setAuthPage(page);
- }
- info.setBssid(vo.getBssid());
- info.setSsid(vo.getSsid());
- info.setTime(vo.getTime());
- IllegalVO illegal = isIllegal(vo.getSsid());
- if (illegal.isIllegal()) {
- info.setIsIllegal("Y");
- info.setKeyType(illegal.getKeyType());
- }
- wifiInfoService.insertWifiInfo(info);
- });
- return AjaxResult.success();
- }
- private List<KeyInfo> keyInfoList;
- private IllegalVO isIllegal(String content) {
- IllegalVO result = new IllegalVO();
- result.setIllegal(false);
- for (KeyInfo keyInfo : keyInfoList) {
- String[] keys = keyInfo.getKeyWords().split(",");
- for (String key : keys) {
- if (content.contains(key)) {
- result.setIllegal(true);
- result.setKeyType(keyInfo.getKeyType());
- return result;
- }
- }
- }
- return result;
- }
- /**
- * 蓝牙上传
- */
- @PostMapping("/bluetooth")
- public AjaxResult bluetooth(@RequestBody List<BluetoothInfoVO> infoList) {
- keyInfoList = keyInfoService.selectKeyInfoList(new KeyInfo());
- infoList.forEach(vo -> {
- BluetoothInfo info = new BluetoothInfo();
- info.setDeviceId(vo.getDeviceId());
- String[] vaId = vo.getVenueId().split("-");
- Long vId = Long.parseLong(vaId[0]);
- info.setVenueId(vId);
- info.setIsIllegal("N");
- if (vaId.length > 1) {
- Long aId = Long.parseLong(vaId[1]);
- info.setAreaId(aId);
- }
- info.setMac(vo.getMac());
- info.setName(vo.getName());
- info.setFileName(vo.getFileName());
- info.setFilePath(vo.getFilePath());
- info.setTime(vo.getTime());
- IllegalVO illegal = isIllegal(vo.getName());
- if (illegal.isIllegal()) {
- info.setIsIllegal("Y");
- info.setKeyType(illegal.getKeyType());
- }
- illegal = isIllegal(vo.getFileName());
- if (illegal.isIllegal()) {
- info.setIsIllegal("Y");
- info.setKeyType(illegal.getKeyType());
- }
- bluetoothInfoService.insertBluetoothInfo(info);
- });
- return AjaxResult.success();
- }
- /**
- * 通用上传请求(单个)
- */
- @PostMapping("/upload")
- public AjaxResult upload(MultipartFile file) {
- try {
- // 上传文件路径
- String filePath = RuoYiConfig.getUploadPath();
- // 上传并返回新文件名称
- String fileName = FileUploadUtils.upload(filePath, file);
- String url = serverConfig.getUrl() + fileName;
- AjaxResult ajax = AjaxResult.success();
- ajax.put("url", url);
- // ajax.put("fileName", fileName);
- // ajax.put("newFileName", FileUtils.getName(fileName));
- ajax.put("fileName", file.getOriginalFilename());
- return ajax;
- } catch (Exception e) {
- return AjaxResult.error(e.getMessage());
- }
- }
- /**
- * 获取场馆信息
- */
- @GetMapping("/venue")
- public TableDataInfo venue() {
- List<VenueInfo> list = venueInfoService.selectVenueInfoList(null);
- List<VenueInfoVO> result = new ArrayList<>();
- VenueArea area = new VenueArea();
- for (VenueInfo info : list) {
- VenueInfoVO vo = new VenueInfoVO();
- BeanUtils.copyProperties(info, vo);
- area.setVenueId(info.getVenueId());
- List<VenueArea> areaList = areaService.selectVenueAreaList(area);
- List<VenueAreaVO> areaVOList = new ArrayList<>();
- areaList.forEach(bean -> {
- VenueAreaVO avo = new VenueAreaVO();
- BeanUtils.copyProperties(bean, avo);
- areaVOList.add(avo);
- });
- vo.setArea(areaVOList);
- result.add(vo);
- }
- return getDataTable(result);
- }
- /**
- * 获取场馆信息
- */
- @GetMapping("/venueA")
- public TableDataInfo venueA() {
- List<VenueInfo> list = venueInfoService.selectVenueInfoList(null);
- List<VenueInfoAVO> result = new ArrayList<>();
- VenueArea area = new VenueArea();
- for (VenueInfo info : list) {
- area.setVenueId(info.getVenueId());
- List<VenueArea> areaList = areaService.selectVenueAreaList(area);
- if (areaList.size() > 0) {
- areaList.forEach(bean -> {
- VenueInfoAVO vo = new VenueInfoAVO();
- String id = info.getVenueId() + "-" + bean.getAreaId();
- String name = info.getVenueName() + "-" + bean.getAreaName();
- vo.setVenueId(id);
- vo.setVenueName(name);
- result.add(vo);
- });
- } else {
- VenueInfoAVO vo = new VenueInfoAVO();
- String id = info.getVenueId() + "";
- String name = info.getVenueName();
- vo.setVenueId(id);
- vo.setVenueName(name);
- result.add(vo);
- }
- }
- return getDataTable(result);
- }
- }
|