Przeglądaj źródła

首页信息处理

wukai 1 rok temu
rodzic
commit
35037549f1

+ 161 - 27
dayun-admin/src/main/java/com/jjt/biz/controller/IndexController.java

@@ -10,17 +10,21 @@ 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.enums.BusinessType;
+import com.jjt.common.utils.DateUtils;
+import com.jjt.common.utils.StringUtils;
 import com.jjt.common.utils.poi.ExcelUtil;
+import com.jjt.system.service.ISysConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -40,51 +44,172 @@ public class IndexController extends BaseController {
     private IWifiInfoService wifiInfoService;
     @Resource
     private IVenueInfoService venueInfoService;
+    @Resource
+    private ISysConfigService configService;
 
     /**
      * 首页信息
      */
     @GetMapping("/info")
-    public Map<String, Object> info() {
+    public Map<String, Object> info(InfoReq req) {
+        LocalDate nowDate = LocalDate.now();
+        String filter = "";
+        if (req.getFilter() != null) {
+            //为了兼容以前的代码,不至于程序报错,所以这样写
+            filter = req.getFilter();
+        }
+        switch (filter) {
+            case "1":
+                //当天
+                req.setStart(nowDate.toString());
+                req.setStart(nowDate.toString());
+                break;
+            case "2":
+                //本周
+                LocalDate monday = nowDate.with(DayOfWeek.MONDAY);
+                req.setStart(monday.toString());
+                req.setStart(DateUtils.getDate());
+                break;
+            case "3":
+                //本月
+                LocalDate month1 = nowDate.withDayOfMonth(1);
+                req.setStart(month1.toString());
+                req.setStart(nowDate.toString());
+                break;
+            case "4":
+                //本年
+                LocalDate year1 = nowDate.withDayOfYear(1);
+                req.setStart(year1.toString());
+                req.setStart(nowDate.toString());
+                break;
+           /* case "5":
+                //全部
+                req.setStart("");
+                req.setStart("");
+                break;*/
+            case "6":
+                //自定义,直接使用前台传的不管
+                break;
+            default:
+                //默认查询全部
+                req.setStart("");
+                req.setStart("");
+        }
+
+        Map<String, Object> params = new HashMap<>();
+        params.put("beginTime", req.getStart());
+        params.put("endTime", req.getEnd());
+
         Map<String, Object> map = new HashMap<>(16);
         List deviceInfos = deviceInfoService.selectDeviceInfoList(new DeviceInfo());
         map.put("deviceNO", deviceInfos.size());
-        List<WifiInfo> wifiInfos = wifiInfoService.selectWifiInfoList(new WifiInfo());
-        List wifis = wifiInfos.stream()
+
+        //查询wifi数
+        WifiInfo wifiInfo = new WifiInfo();
+        wifiInfo.setParams(params);
+
+        List<WifiInfo> wifiInfos = wifiInfoService.selectWifiInfoList(wifiInfo);
+        List<WifiInfo> illegalWifi = wifiInfos.stream()
                 .filter(bean -> bean.getIsIllegal().equals("Y"))
                 .collect(Collectors.toList());
         map.put("totalWifiNO", wifiInfos.size());
-        map.put("wifiNO", wifis.size());
-        List<BluetoothInfo> bluetoothInfos = bluetoothInfoService.selectBluetoothInfoList(new BluetoothInfo());
-        List blues = bluetoothInfos.stream()
+        map.put("wifiNO", illegalWifi.size());
+
+        //查询蓝牙数
+        BluetoothInfo bluetoothInfo = new BluetoothInfo();
+        bluetoothInfo.setParams(params);
+        List<BluetoothInfo> bluetoothInfos = bluetoothInfoService.selectBluetoothInfoList(bluetoothInfo);
+
+        List<BluetoothInfo> illegalBlue = bluetoothInfos.stream()
                 .filter(bean -> bean.getIsIllegal().equals("Y"))
                 .collect(Collectors.toList());
         map.put("totalBluetoothNO", bluetoothInfos.size());
-        map.put("bluetoothNO", blues.size());
+        map.put("bluetoothNO", illegalBlue.size());
         List venueInfos = venueInfoService.selectVenueInfoList(new VenueInfo());
         map.put("venueNO", venueInfos.size());
+        Integer precision = Integer.parseInt(configService.selectConfigByKey("custom.precision"));
+        Map<String, List<WifiInfo>> wifiGroups = wifiInfos.stream().collect(Collectors.groupingBy(info -> fetchGroupWifi(info, precision)));
+        Map<String, List<BluetoothInfo>> blueGroups = bluetoothInfos.stream().collect(Collectors.groupingBy(info -> fetchGroupBlue(info, precision)));
+
+
         List<InfoVO> infoVOS = new ArrayList<>();
-        InfoVO vo = new InfoVO();
-        vo.setBluetooth(12);
-        vo.setTotalBluetooth(100);
-        vo.setTotalWifi(300);
-        vo.setWifi(15);
-        vo.setLat("30.593938");
-        vo.setLng("104.243116");
-        infoVOS.add(vo);
-        vo = new InfoVO();
-        vo.setBluetooth(5);
-        vo.setTotalBluetooth(15);
-        vo.setWifi(21);
-        vo.setTotalWifi(400);
-        vo.setLat("30.546");
-        vo.setLng("104.113");
+        InfoVO vo;
+        for (String s : wifiGroups.keySet()) {
+            vo = new InfoVO();
+            String[] ss = s.split("#");
+            vo.setLat(ss[0]);
+            vo.setLng(ss[1]);
+
+            vo.setTotalWifi(wifiGroups.get(s).size());
+            List<WifiInfo> wifiList = wifiGroups.get(s).stream()
+                    .filter(bean -> bean.getIsIllegal().equals("Y"))
+                    .collect(Collectors.toList());
+            vo.setWifi(wifiList.size());
+            if (blueGroups.get(s) != null) {
+                //如果相同坐标下还有恶意蓝牙
+                vo.setTotalBluetooth(blueGroups.get(s).size());
+                List<BluetoothInfo> blueList = bluetoothInfos.stream()
+                        .filter(bean -> bean.getIsIllegal().equals("Y"))
+                        .collect(Collectors.toList());
+                vo.setBluetooth(blueList.size());
+            } else {
+                vo.setTotalBluetooth(0);
+                vo.setBluetooth(0);
+            }
+
+            if (vo.getWifi() >= 0 || vo.getBluetooth() > 0) {
+                infoVOS.add(vo);
+            }
+        }
+
+        for (String s : blueGroups.keySet()) {
+            vo = new InfoVO();
+            String[] ss = s.split("#");
+            vo.setLat(ss[0]);
+            vo.setLng(ss[1]);
+            vo.setWifi(0);
+            vo.setTotalWifi(0);
+            vo.setTotalBluetooth(blueGroups.get(s).size());
+            List<BluetoothInfo> blueList = bluetoothInfos.stream()
+                    .filter(bean -> bean.getIsIllegal().equals("Y"))
+                    .collect(Collectors.toList());
+            vo.setBluetooth(blueList.size());
+
+            if (vo.getWifi() >= 0 || vo.getBluetooth() > 0) {
+                infoVOS.add(vo);
+            }
+        }
+
         map.put("info", infoVOS);
-        infoVOS.add(vo);
+
         return map;
     }
 
     /**
+     * 组装分组条件
+     */
+    private static String fetchGroupWifi(WifiInfo info, int precision) {
+        BigDecimal lat = new BigDecimal(info.getLat());
+        BigDecimal lng = new BigDecimal(info.getLng());
+        lat = lat.setScale(precision, RoundingMode.HALF_UP);
+        lng = lng.setScale(precision, RoundingMode.HALF_UP);
+        String key = lat + "#" + lng;
+        return key;
+    }
+
+    /**
+     * 组装分组条件
+     */
+    private static String fetchGroupBlue(BluetoothInfo info, int precision) {
+        BigDecimal lat = new BigDecimal(info.getLat());
+        BigDecimal lng = new BigDecimal(info.getLng());
+        lat = lat.setScale(precision, RoundingMode.HALF_UP);
+        lng = lng.setScale(precision, RoundingMode.HALF_UP);
+        String key = lat + "#" + lng;
+        return key;
+    }
+
+    /**
      * 首页信息
      */
     @GetMapping("/top")
@@ -105,4 +230,13 @@ public class IndexController extends BaseController {
         }
         return list;
     }
+
+    /**
+     * 首页信息
+     */
+    @GetMapping("/realTimeInfo")
+    public List<RealTimeInfoVO> realTimeInfo() {
+        List<RealTimeInfoVO> list = wifiInfoService.selectRealTimeInfoList();
+        return list;
+    }
 }

+ 60 - 0
dayun-admin/src/main/java/com/jjt/biz/domain/InfoReq.java

@@ -0,0 +1,60 @@
+package com.jjt.biz.domain;
+
+import com.jjt.common.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * WIFI信息对象 wifi_info
+ *
+ * @author ruoyi
+ * @date 2023-07-06
+ */
+public class InfoReq {
+    private static final long serialVersionUID = 1L;
+
+
+    /**
+     * 条件
+     */
+    private String filter;
+    /**
+     * 开始时间
+     */
+    private String start;
+
+    private String end;
+
+    public String getFilter() {
+        return filter;
+    }
+
+    public void setFilter(String filter) {
+        this.filter = filter;
+    }
+
+    public String getStart() {
+        return start;
+    }
+
+    public void setStart(String start) {
+        this.start = start;
+    }
+
+    public String getEnd() {
+        return end;
+    }
+
+    public void setEnd(String end) {
+        this.end = end;
+    }
+
+    @Override
+    public String toString() {
+        return "InfoReq{" +
+                "filter='" + filter + '\'' +
+                ", start='" + start + '\'' +
+                ", end='" + end + '\'' +
+                '}';
+    }
+}

+ 61 - 0
dayun-admin/src/main/java/com/jjt/biz/domain/RealTimeInfoVO.java

@@ -0,0 +1,61 @@
+package com.jjt.biz.domain;
+
+/**
+ * WIFI信息对象 wifi_info
+ *
+ * @author ruoyi
+ * @date 2023-07-06
+ */
+public class RealTimeInfoVO {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 纬度
+     */
+
+    private String lat;
+    /**
+     * 经度
+     */
+    private String lng;
+    /**
+     * 类型  WIFI/蓝牙
+     */
+    private String type;
+    /**
+     * 正常/恶意
+     */
+    private String state;
+
+
+    public String getLat() {
+        return lat;
+    }
+
+    public void setLat(String lat) {
+        this.lat = lat;
+    }
+
+    public String getLng() {
+        return lng;
+    }
+
+    public void setLng(String lng) {
+        this.lng = lng;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+}

+ 8 - 0
dayun-admin/src/main/java/com/jjt/biz/mapper/WifiInfoMapper.java

@@ -1,6 +1,8 @@
 package com.jjt.biz.mapper;
 
 import java.util.List;
+
+import com.jjt.biz.domain.RealTimeInfoVO;
 import com.jjt.biz.domain.WifiInfo;
 
 /**
@@ -58,4 +60,10 @@ public interface WifiInfoMapper
      * @return 结果
      */
     public int deleteWifiInfoByWifiInfoIds(Long[] wifiInfoIds);
+    /**
+     * 查询实时记录
+     *
+     * @return
+     */
+    List<RealTimeInfoVO> selectRealTimeInfoList();
 }

+ 17 - 9
dayun-admin/src/main/java/com/jjt/biz/service/IWifiInfoService.java

@@ -1,19 +1,20 @@
 package com.jjt.biz.service;
 
 import java.util.List;
+
+import com.jjt.biz.domain.RealTimeInfoVO;
 import com.jjt.biz.domain.WifiInfo;
 
 /**
  * WIFI信息Service接口
- * 
+ *
  * @author ruoyi
  * @date 2023-07-06
  */
-public interface IWifiInfoService 
-{
+public interface IWifiInfoService {
     /**
      * 查询WIFI信息
-     * 
+     *
      * @param wifiInfoId WIFI信息主键
      * @return WIFI信息
      */
@@ -21,7 +22,7 @@ public interface IWifiInfoService
 
     /**
      * 查询WIFI信息列表
-     * 
+     *
      * @param wifiInfo WIFI信息
      * @return WIFI信息集合
      */
@@ -29,7 +30,7 @@ public interface IWifiInfoService
 
     /**
      * 新增WIFI信息
-     * 
+     *
      * @param wifiInfo WIFI信息
      * @return 结果
      */
@@ -37,7 +38,7 @@ public interface IWifiInfoService
 
     /**
      * 修改WIFI信息
-     * 
+     *
      * @param wifiInfo WIFI信息
      * @return 结果
      */
@@ -45,7 +46,7 @@ public interface IWifiInfoService
 
     /**
      * 批量删除WIFI信息
-     * 
+     *
      * @param wifiInfoIds 需要删除的WIFI信息主键集合
      * @return 结果
      */
@@ -53,9 +54,16 @@ public interface IWifiInfoService
 
     /**
      * 删除WIFI信息信息
-     * 
+     *
      * @param wifiInfoId WIFI信息主键
      * @return 结果
      */
     public int deleteWifiInfoByWifiInfoId(Long wifiInfoId);
+
+    /**
+     * 查询实时记录
+     *
+     * @return
+     */
+    List<RealTimeInfoVO> selectRealTimeInfoList();
 }

+ 29 - 22
dayun-admin/src/main/java/com/jjt/biz/service/impl/WifiInfoServiceImpl.java

@@ -1,93 +1,100 @@
 package com.jjt.biz.service.impl;
 
 import java.util.List;
+
+import com.jjt.biz.domain.RealTimeInfoVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.jjt.biz.mapper.WifiInfoMapper;
 import com.jjt.biz.domain.WifiInfo;
 import com.jjt.biz.service.IWifiInfoService;
 
+import javax.annotation.Resource;
+
 /**
  * WIFI信息Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2023-07-06
  */
 @Service
-public class WifiInfoServiceImpl implements IWifiInfoService 
-{
-    @Autowired
+public class WifiInfoServiceImpl implements IWifiInfoService {
+    @Resource
     private WifiInfoMapper wifiInfoMapper;
 
     /**
      * 查询WIFI信息
-     * 
+     *
      * @param wifiInfoId WIFI信息主键
      * @return WIFI信息
      */
     @Override
-    public WifiInfo selectWifiInfoByWifiInfoId(Long wifiInfoId)
-    {
+    public WifiInfo selectWifiInfoByWifiInfoId(Long wifiInfoId) {
         return wifiInfoMapper.selectWifiInfoByWifiInfoId(wifiInfoId);
     }
 
     /**
      * 查询WIFI信息列表
-     * 
+     *
      * @param wifiInfo WIFI信息
      * @return WIFI信息
      */
     @Override
-    public List<WifiInfo> selectWifiInfoList(WifiInfo wifiInfo)
-    {
+    public List<WifiInfo> selectWifiInfoList(WifiInfo wifiInfo) {
         return wifiInfoMapper.selectWifiInfoList(wifiInfo);
     }
 
     /**
      * 新增WIFI信息
-     * 
+     *
      * @param wifiInfo WIFI信息
      * @return 结果
      */
     @Override
-    public int insertWifiInfo(WifiInfo wifiInfo)
-    {
+    public int insertWifiInfo(WifiInfo wifiInfo) {
         return wifiInfoMapper.insertWifiInfo(wifiInfo);
     }
 
     /**
      * 修改WIFI信息
-     * 
+     *
      * @param wifiInfo WIFI信息
      * @return 结果
      */
     @Override
-    public int updateWifiInfo(WifiInfo wifiInfo)
-    {
+    public int updateWifiInfo(WifiInfo wifiInfo) {
         return wifiInfoMapper.updateWifiInfo(wifiInfo);
     }
 
     /**
      * 批量删除WIFI信息
-     * 
+     *
      * @param wifiInfoIds 需要删除的WIFI信息主键
      * @return 结果
      */
     @Override
-    public int deleteWifiInfoByWifiInfoIds(Long[] wifiInfoIds)
-    {
+    public int deleteWifiInfoByWifiInfoIds(Long[] wifiInfoIds) {
         return wifiInfoMapper.deleteWifiInfoByWifiInfoIds(wifiInfoIds);
     }
 
     /**
      * 删除WIFI信息信息
-     * 
+     *
      * @param wifiInfoId WIFI信息主键
      * @return 结果
      */
     @Override
-    public int deleteWifiInfoByWifiInfoId(Long wifiInfoId)
-    {
+    public int deleteWifiInfoByWifiInfoId(Long wifiInfoId) {
         return wifiInfoMapper.deleteWifiInfoByWifiInfoId(wifiInfoId);
     }
+
+    /**
+     * 查询实时记录
+     *
+     * @return
+     */
+    @Override
+    public List<RealTimeInfoVO> selectRealTimeInfoList() {
+        return wifiInfoMapper.selectRealTimeInfoList();
+    }
 }

+ 3 - 5
dayun-admin/src/main/resources/mapper/biz/BluetoothInfoMapper.xml

@@ -39,10 +39,7 @@
     </sql>
 
     <select id="selectBluetoothInfoList" parameterType="BluetoothInfo" resultMap="BluetoothInfoResult">
-        select * from (select B_INFO_ID, DEVICE_ID, a.VENUE_ID,b.VENUE_NAME, a.AREA_ID,c.area_name, MAC, NAME,
-        FILE_NAME, FILE_PATH, IS_ILLEGAL, KEY_TYPE,LAT,LNG, TIME from bluetooth_info a left join venue_info b on
-        a.venue_id=b.venue_id left join venue_area
-        c on a.AREA_ID=c.area_id ) t
+        <include refid="selectBluetoothInfoVo"/>
         <where>
             <if test="deviceId != null  and deviceId != ''">and DEVICE_ID = #{deviceId}</if>
             <if test="venueId != null ">and VENUE_ID = #{venueId}</if>
@@ -54,8 +51,9 @@
             <if test="isIllegal != null  and isIllegal != ''">and IS_ILLEGAL = #{isIllegal}</if>
             <if test="keyType != null  and keyType != ''">and KEY_TYPE like concat('%', #{keyType}, '%')</if>
             <if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''">
-                and TIME between #{params.beginTime} and #{params.endTime}
+                and date_format(TIME,'%Y-%m-%d') between #{params.beginTime} and #{params.endTime}
             </if>
+            and lat is not null and lng is not null
         </where>
     </select>
 

+ 16 - 5
dayun-admin/src/main/resources/mapper/biz/WifiInfoMapper.xml

@@ -37,10 +37,7 @@
     </sql>
 
     <select id="selectWifiInfoList" parameterType="WifiInfo" resultMap="WifiInfoResult">
-        select * from (select WIFI_INFO_ID, DEVICE_ID, a.VENUE_ID,b.VENUE_NAME, a.AREA_ID,c.area_name, BSSID, SSID,
-        AUTH_PAGE,
-        IS_ILLEGAL, KEY_TYPE,LAT,LNG, TIME from wifi_info a left join venue_info b on a.venue_id=b.venue_id left join venue_area
-        c on a.AREA_ID=c.area_id ) t
+        <include refid="selectWifiInfoVo"/>
         <where>
             <if test="deviceId != null  and deviceId != ''">and DEVICE_ID = #{deviceId}</if>
             <if test="venueId != null ">and VENUE_ID = #{venueId}</if>
@@ -52,8 +49,9 @@
             <if test="keyType != null  and keyType != ''">and KEY_TYPE = #{keyType}</if>
             <if test="time != null ">and TIME = #{time}</if>
             <if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''">
-                and TIME between #{params.beginTime} and #{params.endTime}
+                and date_format(TIME,'%Y-%m-%d') between #{params.beginTime} and #{params.endTime}
             </if>
+            and lat is not null and lng is not null
         </where>
     </select>
 
@@ -61,6 +59,19 @@
         <include refid="selectWifiInfoVo"/>
         where WIFI_INFO_ID = #{wifiInfoId}
     </select>
+    <select id="selectRealTimeInfoList" resultType="com.jjt.biz.domain.RealTimeInfoVO">
+        select *
+        from (SELECT *
+              FROM (SELECT lat, lng, 'WIFI' TYPE, case is_illegal when 'Y' then '恶意' ELSE '正常' END state, time
+                    FROM wifi_info
+                    ORDER BY TIME DESC LIMIT 40) a
+              UNION ALL
+              SELECT *
+              FROM (SELECT lat, lng, '蓝牙' type, case is_illegal when 'Y' then '恶意' ELSE '正常' END state, time
+                    FROM bluetooth_info
+                    ORDER BY TIME DESC LIMIT 40) b) t
+        order by time desc limit 20
+    </select>
 
     <insert id="insertWifiInfo" parameterType="WifiInfo" useGeneratedKeys="true" keyProperty="wifiInfoId">
         insert into wifi_info

+ 11 - 2
dayun-admin/src/test/java/Test.java

@@ -1,16 +1,25 @@
 import com.jjt.common.utils.sign.Base64;
+import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
 
 import java.nio.charset.StandardCharsets;
+import java.text.SimpleDateFormat;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.Date;
 
 public class Test {
     public static void main(String[] args) {
         String yy = Base64.encode(xx.getBytes(StandardCharsets.UTF_8));
         System.err.println(yy);
         String str = "http://localhost:8080/profile/upload/2023/07/10/drawio修改记录_20230710141959A001.txt";
-        String xx=str.substring(str.indexOf("profile"));
-        System.err.println(xx);
+        String xx = str.substring(str.indexOf("profile"));
+        System.err.println(new SimpleDateFormat("yyyy").format(new Date()) + "-01-01");
 //        String zz = new String(Base64.decode(yy), StandardCharsets.UTF_8);
 //        System.err.println(zz);
+        LocalDate date = LocalDate.now().withDayOfMonth(1);
+        System.err.println(date.toString());
+         date = LocalDate.now().withDayOfYear(1);
+        System.err.println(date.toString());
     }
 
     static String xx = "<!DOCTYPE html>\n" +