ApiController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package com.jjt.biz.controller;
  2. import com.jjt.biz.domain.*;
  3. import com.jjt.biz.service.*;
  4. import com.jjt.biz.vo.*;
  5. import com.jjt.common.annotation.Log;
  6. import com.jjt.common.config.RuoYiConfig;
  7. import com.jjt.common.core.controller.BaseController;
  8. import com.jjt.common.core.domain.AjaxResult;
  9. import com.jjt.common.core.page.TableDataInfo;
  10. import com.jjt.common.core.redis.RedisCache;
  11. import com.jjt.common.enums.BusinessType;
  12. import com.jjt.common.utils.StringUtils;
  13. import com.jjt.common.utils.file.FileUploadUtils;
  14. import com.jjt.common.utils.file.FileUtils;
  15. import com.jjt.common.utils.poi.ExcelUtil;
  16. import com.jjt.common.utils.sign.Base64;
  17. import com.jjt.common.utils.spring.SpringUtils;
  18. import com.jjt.framework.config.ServerConfig;
  19. import org.springframework.beans.BeanUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.security.access.prepost.PreAuthorize;
  22. import org.springframework.web.bind.annotation.*;
  23. import org.springframework.web.multipart.MultipartFile;
  24. import javax.annotation.Resource;
  25. import javax.servlet.http.HttpServletResponse;
  26. import java.nio.charset.StandardCharsets;
  27. import java.util.ArrayList;
  28. import java.util.Arrays;
  29. import java.util.Date;
  30. import java.util.List;
  31. /**
  32. * 关键字Controller
  33. *
  34. * @author ruoyi
  35. * @date 2023-07-06
  36. */
  37. @RestController
  38. @RequestMapping("/api")
  39. public class ApiController extends BaseController {
  40. @Resource
  41. private IDeviceInfoService deviceInfoService;
  42. @Resource
  43. private IWifiInfoService wifiInfoService;
  44. @Resource
  45. private IBluetoothInfoService bluetoothInfoService;
  46. @Resource
  47. private IVenueInfoService venueInfoService;
  48. @Resource
  49. private IVenueAreaService areaService;
  50. @Resource
  51. private ServerConfig serverConfig;
  52. @Resource
  53. private IKeyInfoService keyInfoService;
  54. /**
  55. * 设备注册接口
  56. */
  57. @PostMapping("/device")
  58. public AjaxResult device(@RequestBody DeviceInfo deviceInfo) {
  59. deviceInfo.setRegisterTime(new Date());
  60. int i = 0;
  61. try {
  62. i = deviceInfoService.insertDeviceInfo(deviceInfo);
  63. } catch (Exception e) {
  64. if (e.getMessage().contains("Duplicate entry")) {
  65. return AjaxResult.error("DEVICE_ID重复");
  66. } else {
  67. return AjaxResult.error(e.getMessage());
  68. }
  69. }
  70. return toAjax(1);
  71. }
  72. /**
  73. * WIFI上传
  74. */
  75. @PostMapping("/wifi")
  76. public AjaxResult wifi(@RequestBody List<WifiInfoVO> infoList) {
  77. keyInfoList = keyInfoService.selectKeyInfoList(new KeyInfo());
  78. infoList.forEach(vo -> {
  79. WifiInfo info = new WifiInfo();
  80. info.setDeviceId(vo.getDeviceId());
  81. String[] vaId = vo.getVenueId().split("-");
  82. Long vId = Long.parseLong(vaId[0]);
  83. info.setVenueId(vId);
  84. info.setIsIllegal("N");
  85. if (vaId.length > 1) {
  86. Long aId = Long.parseLong(vaId[1]);
  87. info.setAreaId(aId);
  88. }
  89. if (StringUtils.isNotEmpty(vo.getAuthPage())) {
  90. String page = new String(Base64.decode(vo.getAuthPage()), StandardCharsets.UTF_8);
  91. IllegalVO illegal = isIllegal(page);
  92. if (illegal.isIllegal()) {
  93. info.setIsIllegal("Y");
  94. info.setKeyType(illegal.getKeyType());
  95. }
  96. isIllegal(vo.getSsid());
  97. info.setAuthPage(page);
  98. }
  99. info.setBssid(vo.getBssid());
  100. info.setSsid(vo.getSsid());
  101. info.setTime(vo.getTime());
  102. IllegalVO illegal = isIllegal(vo.getSsid());
  103. if (illegal.isIllegal()) {
  104. info.setIsIllegal("Y");
  105. info.setKeyType(illegal.getKeyType());
  106. }
  107. wifiInfoService.insertWifiInfo(info);
  108. });
  109. return AjaxResult.success();
  110. }
  111. private List<KeyInfo> keyInfoList;
  112. private IllegalVO isIllegal(String content) {
  113. IllegalVO result = new IllegalVO();
  114. result.setIllegal(false);
  115. for (KeyInfo keyInfo : keyInfoList) {
  116. String[] keys = keyInfo.getKeyWords().split(",");
  117. for (String key : keys) {
  118. if (content.contains(key)) {
  119. result.setIllegal(true);
  120. result.setKeyType(keyInfo.getKeyType());
  121. return result;
  122. }
  123. }
  124. }
  125. return result;
  126. }
  127. /**
  128. * 蓝牙上传
  129. */
  130. @PostMapping("/bluetooth")
  131. public AjaxResult bluetooth(@RequestBody List<BluetoothInfoVO> infoList) {
  132. keyInfoList = keyInfoService.selectKeyInfoList(new KeyInfo());
  133. infoList.forEach(vo -> {
  134. BluetoothInfo info = new BluetoothInfo();
  135. info.setDeviceId(vo.getDeviceId());
  136. String[] vaId = vo.getVenueId().split("-");
  137. Long vId = Long.parseLong(vaId[0]);
  138. info.setVenueId(vId);
  139. info.setIsIllegal("N");
  140. if (vaId.length > 1) {
  141. Long aId = Long.parseLong(vaId[1]);
  142. info.setAreaId(aId);
  143. }
  144. info.setMac(vo.getMac());
  145. info.setName(vo.getName());
  146. info.setFileName(vo.getFileName());
  147. info.setFilePath(vo.getFilePath());
  148. info.setTime(vo.getTime());
  149. IllegalVO illegal = isIllegal(vo.getName());
  150. if (illegal.isIllegal()) {
  151. info.setIsIllegal("Y");
  152. info.setKeyType(illegal.getKeyType());
  153. }
  154. illegal = isIllegal(vo.getFileName());
  155. if (illegal.isIllegal()) {
  156. info.setIsIllegal("Y");
  157. info.setKeyType(illegal.getKeyType());
  158. }
  159. bluetoothInfoService.insertBluetoothInfo(info);
  160. });
  161. return AjaxResult.success();
  162. }
  163. /**
  164. * 通用上传请求(单个)
  165. */
  166. @PostMapping("/upload")
  167. public AjaxResult upload(MultipartFile file) {
  168. try {
  169. // 上传文件路径
  170. String filePath = RuoYiConfig.getUploadPath();
  171. // 上传并返回新文件名称
  172. String fileName = FileUploadUtils.upload(filePath, file);
  173. String url = serverConfig.getUrl() + fileName;
  174. AjaxResult ajax = AjaxResult.success();
  175. ajax.put("url", url);
  176. // ajax.put("fileName", fileName);
  177. // ajax.put("newFileName", FileUtils.getName(fileName));
  178. ajax.put("fileName", file.getOriginalFilename());
  179. return ajax;
  180. } catch (Exception e) {
  181. return AjaxResult.error(e.getMessage());
  182. }
  183. }
  184. /**
  185. * 获取场馆信息
  186. */
  187. @GetMapping("/venue")
  188. public TableDataInfo venue() {
  189. List<VenueInfo> list = venueInfoService.selectVenueInfoList(null);
  190. List<VenueInfoVO> result = new ArrayList<>();
  191. VenueArea area = new VenueArea();
  192. for (VenueInfo info : list) {
  193. VenueInfoVO vo = new VenueInfoVO();
  194. BeanUtils.copyProperties(info, vo);
  195. area.setVenueId(info.getVenueId());
  196. List<VenueArea> areaList = areaService.selectVenueAreaList(area);
  197. List<VenueAreaVO> areaVOList = new ArrayList<>();
  198. areaList.forEach(bean -> {
  199. VenueAreaVO avo = new VenueAreaVO();
  200. BeanUtils.copyProperties(bean, avo);
  201. areaVOList.add(avo);
  202. });
  203. vo.setArea(areaVOList);
  204. result.add(vo);
  205. }
  206. return getDataTable(result);
  207. }
  208. /**
  209. * 获取场馆信息
  210. */
  211. @GetMapping("/venueA")
  212. public TableDataInfo venueA() {
  213. List<VenueInfo> list = venueInfoService.selectVenueInfoList(null);
  214. List<VenueInfoAVO> result = new ArrayList<>();
  215. VenueArea area = new VenueArea();
  216. for (VenueInfo info : list) {
  217. area.setVenueId(info.getVenueId());
  218. List<VenueArea> areaList = areaService.selectVenueAreaList(area);
  219. if (areaList.size() > 0) {
  220. areaList.forEach(bean -> {
  221. VenueInfoAVO vo = new VenueInfoAVO();
  222. String id = info.getVenueId() + "-" + bean.getAreaId();
  223. String name = info.getVenueName() + "-" + bean.getAreaName();
  224. vo.setVenueId(id);
  225. vo.setVenueName(name);
  226. result.add(vo);
  227. });
  228. } else {
  229. VenueInfoAVO vo = new VenueInfoAVO();
  230. String id = info.getVenueId() + "";
  231. String name = info.getVenueName();
  232. vo.setVenueId(id);
  233. vo.setVenueName(name);
  234. result.add(vo);
  235. }
  236. }
  237. return getDataTable(result);
  238. }
  239. }