From 9b87b4036158acad06f7355e7506159155e33227 Mon Sep 17 00:00:00 2001 From: luyya Date: Thu, 3 Jul 2025 16:37:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A3=E5=9F=8E=E6=B1=87=E8=81=9A0703?= =?UTF-8?q?=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data2es/api/domain/RemoteGpsInfo.java | 1 + .../data2es/config/SchedulerConfig.java | 23 +++++ .../dromara/data2es/domain/EsGpsInfoVO2.java | 1 + .../extract/mapper/DeviceGpsMapper.java | 2 + .../dromara/extract/schedule/DjjSchedule.java | 55 ++++++++++++ .../extract/service/ITDeviceGpsService.java | 2 + .../service/impl/TDeviceGpsServiceImpl.java | 7 ++ .../main/resources/mapper/DeviceGpsMapper.xml | 9 ++ .../system/config/SchedulerConfig.java | 23 +++++ .../system/IndexStaticsController.java | 49 +++++------ .../org/dromara/system/domain/TDevice.java | 2 + .../dromara/system/domain/bo/TDeviceBo.java | 2 + .../system/domain/vo/DeviceStaticsVo.java | 4 +- .../dromara/system/domain/vo/TDeviceVo.java | 2 + .../system/mapper/DeviceRedisMapper.java | 5 ++ .../system/schedule/DeviceRedisSchedule.java | 19 +++- .../system/service/IDeviceRedisService.java | 2 + .../system/service/ITDeviceService.java | 4 + .../service/impl/DeviceRedisServiceImpl.java | 17 ++++ .../service/impl/SysDeptServiceImpl.java | 20 ++++- .../service/impl/TDeviceServiceImpl.java | 88 +++++++++++++------ .../mapper/system/DeviceRedisMapper.xml | 5 ++ .../resources/mapper/system/TDeviceMapper.xml | 4 +- .../webscoket/config/ThreadConfig.java | 23 ----- .../webscoket/schedule/DeviceSchedule.java | 1 + .../src/main/resources/application.yml | 2 +- .../src/main/resources/logback-plus.xml | 49 +++++++++++ 27 files changed, 339 insertions(+), 82 deletions(-) create mode 100644 stwzhj-modules/wzhj-data2es/src/main/java/org/dromara/data2es/config/SchedulerConfig.java create mode 100644 stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/schedule/DjjSchedule.java create mode 100644 stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/config/SchedulerConfig.java delete mode 100644 stwzhj-modules/wzhj-websocket/src/main/java/org/dromara/webscoket/config/ThreadConfig.java create mode 100644 stwzhj-modules/wzhj-websocket/src/main/resources/logback-plus.xml diff --git a/stwzhj-api/stwzhj-api-data2es/src/main/java/org/dromara/data2es/api/domain/RemoteGpsInfo.java b/stwzhj-api/stwzhj-api-data2es/src/main/java/org/dromara/data2es/api/domain/RemoteGpsInfo.java index 598c0a2f..2cce6ee5 100644 --- a/stwzhj-api/stwzhj-api-data2es/src/main/java/org/dromara/data2es/api/domain/RemoteGpsInfo.java +++ b/stwzhj-api/stwzhj-api-data2es/src/main/java/org/dromara/data2es/api/domain/RemoteGpsInfo.java @@ -37,6 +37,7 @@ public class RemoteGpsInfo implements Serializable { private String policeNo; private String policeName; private String phoneNum; + private String deviceName; private String carNum; private Integer online; diff --git a/stwzhj-modules/wzhj-data2es/src/main/java/org/dromara/data2es/config/SchedulerConfig.java b/stwzhj-modules/wzhj-data2es/src/main/java/org/dromara/data2es/config/SchedulerConfig.java new file mode 100644 index 00000000..4887664a --- /dev/null +++ b/stwzhj-modules/wzhj-data2es/src/main/java/org/dromara/data2es/config/SchedulerConfig.java @@ -0,0 +1,23 @@ +package org.dromara.data2es.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; + +@Configuration +public class SchedulerConfig implements SchedulingConfigurer { + + @Override + public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); + taskScheduler.setPoolSize(5); // 设置线程池大小 + taskScheduler.setThreadNamePrefix("scheduled-task-"); + taskScheduler.setErrorHandler(throwable -> { + // 统一处理未捕获异常 + System.err.println("定时任务异常: " + throwable.getMessage()); + }); + taskScheduler.initialize(); + taskRegistrar.setTaskScheduler(taskScheduler); + } +} diff --git a/stwzhj-modules/wzhj-data2es/src/main/java/org/dromara/data2es/domain/EsGpsInfoVO2.java b/stwzhj-modules/wzhj-data2es/src/main/java/org/dromara/data2es/domain/EsGpsInfoVO2.java index a9d700b6..b9a44dea 100644 --- a/stwzhj-modules/wzhj-data2es/src/main/java/org/dromara/data2es/domain/EsGpsInfoVO2.java +++ b/stwzhj-modules/wzhj-data2es/src/main/java/org/dromara/data2es/domain/EsGpsInfoVO2.java @@ -18,4 +18,5 @@ public class EsGpsInfoVO2 extends EsGpsInfo { private String policeName; private String phoneNum; private String carNum; + private String deviceName; } diff --git a/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/mapper/DeviceGpsMapper.java b/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/mapper/DeviceGpsMapper.java index 1bb591ed..eb7d5dde 100644 --- a/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/mapper/DeviceGpsMapper.java +++ b/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/mapper/DeviceGpsMapper.java @@ -16,4 +16,6 @@ public interface DeviceGpsMapper { EsGpsInfo selectBDGCMaxTime(); + List selectDjjGPS(EsGpsInfo esGpsInfo); + } diff --git a/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/schedule/DjjSchedule.java b/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/schedule/DjjSchedule.java new file mode 100644 index 00000000..16b49384 --- /dev/null +++ b/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/schedule/DjjSchedule.java @@ -0,0 +1,55 @@ +package org.dromara.extract.schedule; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.config.annotation.DubboReference; +import org.dromara.data2es.api.RemoteDataToEsService; +import org.dromara.data2es.api.domain.RemoteGpsInfo; +import org.dromara.extract.domain.EsGpsInfo; +import org.dromara.extract.service.ITDeviceGpsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.Scheduled; + +import java.util.Date; +import java.util.List; + +/* +* 4G对讲机定位抽取 +* */ +@Configuration +@Slf4j +public class DjjSchedule { + + @Value("${ruansi.djj_extract_time}") + private String djjExtractTime; + + @Autowired + ITDeviceGpsService gpsService; + + @DubboReference + RemoteDataToEsService dataToEsService; + + + @Scheduled(cron = "0/10 * * * * ?") + public void djjExtract(){ + EsGpsInfo gpsInfo = new EsGpsInfo(); + gpsInfo.setGpsTime(DateUtil.parseDateTime(djjExtractTime)); + List list = gpsService.selectDjjGPS(gpsInfo); + for (int i = 0; i < list.size(); i++) { + EsGpsInfo info = list.get(i); + if(i == 0){ + djjExtractTime = DateUtil.formatDateTime(info.getGpsTime()); + } + if (DateUtil.between(new Date(),info.getGpsTime(), DateUnit.MINUTE) > 10){ + info.setOnline("0"); + }else { + info.setOnline("1"); + } + } + dataToEsService.saveDataBatch(BeanUtil.copyToList(list, RemoteGpsInfo.class)); + } +} diff --git a/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/service/ITDeviceGpsService.java b/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/service/ITDeviceGpsService.java index f9cb7850..e4c92afc 100644 --- a/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/service/ITDeviceGpsService.java +++ b/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/service/ITDeviceGpsService.java @@ -12,4 +12,6 @@ public interface ITDeviceGpsService { EsGpsInfo selectBDGCMaxTime(); + List selectDjjGPS(EsGpsInfo esGpsInfo); + } diff --git a/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/service/impl/TDeviceGpsServiceImpl.java b/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/service/impl/TDeviceGpsServiceImpl.java index ddaf97b5..6c6a445d 100644 --- a/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/service/impl/TDeviceGpsServiceImpl.java +++ b/stwzhj-modules/wzhj-extract/src/main/java/org/dromara/extract/service/impl/TDeviceGpsServiceImpl.java @@ -2,6 +2,7 @@ package org.dromara.extract.service.impl; +import com.baomidou.dynamic.datasource.annotation.DS; import org.dromara.extract.domain.EsGpsInfo; import org.dromara.extract.mapper.DeviceGpsMapper; import org.dromara.extract.service.ITDeviceGpsService; @@ -26,4 +27,10 @@ public class TDeviceGpsServiceImpl implements ITDeviceGpsService { public EsGpsInfo selectBDGCMaxTime() { return deviceMapper.selectBDGCMaxTime(); } + + @Override + @DS("slave") + public List selectDjjGPS(EsGpsInfo esGpsInfo) { + return deviceMapper.selectDjjGPS(esGpsInfo); + } } diff --git a/stwzhj-modules/wzhj-extract/src/main/resources/mapper/DeviceGpsMapper.xml b/stwzhj-modules/wzhj-extract/src/main/resources/mapper/DeviceGpsMapper.xml index 62b83555..1f6d6a30 100644 --- a/stwzhj-modules/wzhj-extract/src/main/resources/mapper/DeviceGpsMapper.xml +++ b/stwzhj-modules/wzhj-extract/src/main/resources/mapper/DeviceGpsMapper.xml @@ -66,4 +66,13 @@ order by ztgxsj desc + + + diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/config/SchedulerConfig.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/config/SchedulerConfig.java new file mode 100644 index 00000000..b012b6bf --- /dev/null +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/config/SchedulerConfig.java @@ -0,0 +1,23 @@ +package org.dromara.system.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; + +@Configuration +public class SchedulerConfig implements SchedulingConfigurer { + + @Override + public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { + ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); + taskScheduler.setPoolSize(5); // 设置线程池大小 + taskScheduler.setThreadNamePrefix("scheduled-task-"); + taskScheduler.setErrorHandler(throwable -> { + // 统一处理未捕获异常 + System.err.println("定时任务异常: " + throwable.getMessage()); + }); + taskScheduler.initialize(); + taskRegistrar.setTaskScheduler(taskScheduler); + } +} diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/controller/system/IndexStaticsController.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/controller/system/IndexStaticsController.java index 5ba95909..a76484c7 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/controller/system/IndexStaticsController.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/controller/system/IndexStaticsController.java @@ -4,6 +4,7 @@ package org.dromara.system.controller.system; import cn.hutool.core.date.DateUtil; import jdk.dynalink.linker.LinkerServices; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.domain.R; import org.dromara.common.redis.utils.RedisUtils; @@ -27,6 +28,7 @@ import java.util.*; @RequiredArgsConstructor @RestController +@Slf4j public class IndexStaticsController extends BaseController { private final ISysDeptService deptService; @@ -131,32 +133,27 @@ public class IndexStaticsController extends BaseController { * 各地市总数和在线数 * */ @PostMapping("/onLineBar") - public R onLineBar(){ - List deptVoList = deptService.getDsList(); - List staticsVoList = deviceService.countByDs(); + public R onLineBar(@RequestBody TDeviceBo bo){ + SysDeptBo deptBo = new SysDeptBo(); + deptBo.setIsVisible("1"); + deptBo.setParentId(bo.getZzjgdm()); + List deptVoList = deptService.selectDeptList(deptBo); + log.error("单位集合={}",deptVoList.toString()); List list = new ArrayList<>(); //用来接收处理后的统计结果 for (SysDeptVo deptVo : deptVoList) { - boolean bl = false; //用来统计结果是否有当前这个机构 - for (DeviceStaticsVo staticsVo : staticsVoList) { - String deptId = staticsVo.getZzjgdm()+"00000000"; - if (deptId.equals(deptVo.getDeptId())){ - staticsVo.setZzjgdm(deptId); - staticsVo.setZzjgmc(deptVo.getDeptName().replaceAll("公安局","")); - int onlineCo = RedisUtils.searchKeys("org_code:"+staticsVo.getZzjgdm()+"*"); - staticsVo.setOnlineCo(onlineCo); - list.add(staticsVo); - bl = true; - break; - } - } - if (!bl){ - DeviceStaticsVo staticsVo = new DeviceStaticsVo(); - staticsVo.setZzjgdm(deptVo.getDeptId()); - staticsVo.setZzjgmc(deptVo.getDeptName().replaceAll("公安局","")); - staticsVo.setCo(0); - staticsVo.setOnlineCo(0); - list.add(staticsVo); - } + DeviceStaticsVo staticsVo = new DeviceStaticsVo(); + TDeviceBo deviceBo = new TDeviceBo(); + deviceBo.setZzjgdm(deptVo.getDeptId()); + deviceBo.setValid(1); + DeviceRedis redis = new DeviceRedis(); + redis.setZzjgdm(deptVo.getDeptId()); + Long co = deviceService.countByCondition(deviceBo); + Long online = redisService.countByZzjgdm(redis); + staticsVo.setZzjgdm(deptVo.getDeptId()); + staticsVo.setZzjgmc(deptVo.getShortName()); + staticsVo.setCo(co); + staticsVo.setOnlineCo(online); + list.add(staticsVo); } return R.ok(list); } @@ -229,7 +226,7 @@ public class IndexStaticsController extends BaseController { * 终端种类占比 * */ @PostMapping("/deviceTypePen") - public R deviceTypePen(TDeviceBo deviceInfo){ + public R deviceTypePen(@RequestBody TDeviceBo deviceInfo){ List dataList = dictTypeService.selectDictDataByType("zd_device_type"); List list = new ArrayList<>(); for (SysDictDataVo data : dataList) { @@ -247,7 +244,7 @@ public class IndexStaticsController extends BaseController { *终端单位分布 * */ @PostMapping("/deviceBar") - public R deviceBar(TDeviceBo deviceInfo){ + public R deviceBar(@RequestBody TDeviceBo deviceInfo){ SysDeptBo dept = new SysDeptBo(); dept.setParentId(deviceInfo.getZzjgdm()); diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/TDevice.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/TDevice.java index 572858ea..74f3e0c1 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/TDevice.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/TDevice.java @@ -70,6 +70,8 @@ public class TDevice { private String cardNum; + private String deviceName; + /** * 0无效,1有效 */ diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/bo/TDeviceBo.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/bo/TDeviceBo.java index ee607b34..2b10527e 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/bo/TDeviceBo.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/bo/TDeviceBo.java @@ -77,6 +77,8 @@ public class TDeviceBo extends BaseEntity { private String cardNum; + private String deviceName; + /** * 0无效,1有效 */ diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/DeviceStaticsVo.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/DeviceStaticsVo.java index 066241a9..e2d5ba90 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/DeviceStaticsVo.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/DeviceStaticsVo.java @@ -15,8 +15,8 @@ public class DeviceStaticsVo implements Serializable { private String zzjgdm; - private Integer co; + private Long co; - private Integer onlineCo; + private Long onlineCo; } diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/TDeviceVo.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/TDeviceVo.java index c812ca5e..44f943f8 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/TDeviceVo.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/domain/vo/TDeviceVo.java @@ -41,6 +41,8 @@ public class TDeviceVo implements Serializable { private String deviceCode; // 警号、姓名、车牌号组合字段 + + @ExcelProperty(value = "设备名称") private String deviceName; /** diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/mapper/DeviceRedisMapper.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/mapper/DeviceRedisMapper.java index 308e93d8..a9b5139c 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/mapper/DeviceRedisMapper.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/mapper/DeviceRedisMapper.java @@ -1,5 +1,8 @@ package org.dromara.system.mapper; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import org.apache.ibatis.annotations.Param; import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; import org.dromara.system.domain.DeviceRedis; import org.dromara.system.domain.vo.DeviceRedisVo; @@ -11,4 +14,6 @@ public interface DeviceRedisMapper extends BaseMapperPlus list); List countByCondition(DeviceRedis redis); + + Long countByzzjgdm(@Param(Constants.WRAPPER) Wrapper queryWrapper); } diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/schedule/DeviceRedisSchedule.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/schedule/DeviceRedisSchedule.java index bda57b27..bb100ad0 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/schedule/DeviceRedisSchedule.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/schedule/DeviceRedisSchedule.java @@ -39,7 +39,7 @@ public class DeviceRedisSchedule { /* * 把Redis中 online_user数据存入t_device_redis表中 * */ -// @Scheduled(cron = "0/30 * * * * ?") + @Scheduled(cron = "0/30 * * * * ?") public void handleDeviceRedis(){ List jlist = RedisUtils.searchAndGetKeysValues("online_users:*"); redisService.insertBatch(BeanUtil.copyToList(jlist, DeviceRedis.class)); @@ -69,4 +69,21 @@ public class DeviceRedisSchedule { RedisUtils.batchInsert(deviceInfoDataMap,-1); } + /* + * 定时处理记录仪基本数据 10天没有更新的设备设置为删除状态 + * */ + @Scheduled(cron = "0 0 0/1 * * ?") + public void deleteZfjly(){ + deviceService.deleteZfjly(); + } + + + /* + * 定时删除设备状态为删除的定位信息和在线表 + * */ + @Scheduled(cron = "0 0 0/1 * * ?") + public void removeRedis(){ + deviceService.deleteRedis(); + } + } diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/IDeviceRedisService.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/IDeviceRedisService.java index 8870892c..b61ae2b4 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/IDeviceRedisService.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/IDeviceRedisService.java @@ -9,4 +9,6 @@ public interface IDeviceRedisService { int insertBatch(List list); List countByCondition(DeviceRedis redis); + + Long countByZzjgdm(DeviceRedis deviceRedis); } diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/ITDeviceService.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/ITDeviceService.java index c2eeeb66..cc66f87c 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/ITDeviceService.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/ITDeviceService.java @@ -85,4 +85,8 @@ public interface ITDeviceService { TDeviceVo queryByDeviceCode(String deviceCode); List selectDeviceExportList(TDeviceBo bo); + + int deleteZfjly(); + + int deleteRedis(); } diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/DeviceRedisServiceImpl.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/DeviceRedisServiceImpl.java index a66adf19..a5a768b8 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/DeviceRedisServiceImpl.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/DeviceRedisServiceImpl.java @@ -1,15 +1,20 @@ package org.dromara.system.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.config.annotation.DubboReference; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; +import org.dromara.system.api.RemoteDataScopeService; import org.dromara.system.domain.DeviceRedis; +import org.dromara.system.domain.TDevice; import org.dromara.system.domain.vo.DeviceRedisVo; import org.dromara.system.mapper.DeviceRedisMapper; import org.dromara.system.service.IDeviceRedisService; +import org.dromara.system.service.ISysDeptService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,6 +28,9 @@ public class DeviceRedisServiceImpl implements IDeviceRedisService { private final DeviceRedisMapper baseMapper; + @DubboReference + private RemoteDataScopeService remoteDataScopeService; + @Autowired SqlSessionFactory sqlSessionFactory; @@ -61,4 +69,13 @@ public class DeviceRedisServiceImpl implements IDeviceRedisService { public List countByCondition(DeviceRedis redis) { return baseMapper.countByCondition(redis); } + + @Override + public Long countByZzjgdm(DeviceRedis deviceRedis) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.ne(DeviceRedis::getDeviceType,"9"); + String depts = remoteDataScopeService.getDeptAndChild(deviceRedis.getZzjgdm()); + lqw.inSql(DeviceRedis::getZzjgdm,depts); + return baseMapper.countByzzjgdm(lqw); + } } diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java index 96eecc22..82a4ca25 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java @@ -83,6 +83,7 @@ public class SysDeptServiceImpl implements ISysDeptService { lqw.like(StringUtils.isNotBlank(bo.getDeptName()), SysDept::getDeptName, bo.getDeptName()); lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysDept::getStatus, bo.getStatus()); lqw.eq(StringUtils.isNotBlank(bo.getFullName()), SysDept::getFullName, bo.getFullName()); + lqw.eq(StringUtils.isNotBlank(bo.getIsVisible()),SysDept::getIsVisible,bo.getIsVisible()); lqw.orderByAsc(SysDept::getAncestors); lqw.orderByAsc(SysDept::getParentId); lqw.orderByAsc(SysDept::getOrderNum); @@ -104,7 +105,7 @@ public class SysDeptServiceImpl implements ISysDeptService { return TreeBuildUtils.build(depts, (dept, tree) -> tree.setId(dept.getDeptId()) .setParentId(dept.getParentId()) - .setName(dept.getDeptName()) + .setName(dept.getShortName()) .setWeight(dept.getOrderNum())); } @@ -289,6 +290,10 @@ public class SysDeptServiceImpl implements ISysDeptService { // 如果该部门是启用状态,则启用该部门的所有上级部门 updateParentDeptStatusNormal(dept); } + if ("0".equals(dept.getIsVisible())){ //如果隐藏该部门则其子部门全部隐藏 + updateDeptChildrenVisiable(dept.getDeptId(),"0"); + } + return result; } @@ -305,6 +310,19 @@ public class SysDeptServiceImpl implements ISysDeptService { .in(SysDept::getDeptId, Arrays.asList(deptIds))); } + /* + * 修改子部门为隐藏 + * + * */ + private void updateDeptChildrenVisiable(String deptId,String visible){ + List children = baseMapper.selectList(new LambdaQueryWrapper() + .apply(DataBaseHelper.findInSet(deptId, "ancestors"))); + for (SysDept child : children) { + child.setIsVisible(visible); + baseMapper.updateById(child); + } + } + /** * 修改子元素关系 * diff --git a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/TDeviceServiceImpl.java b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/TDeviceServiceImpl.java index 6c1c44b0..9885e885 100644 --- a/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/TDeviceServiceImpl.java +++ b/stwzhj-modules/wzhj-system/src/main/java/org/dromara/system/service/impl/TDeviceServiceImpl.java @@ -14,12 +14,17 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; +import org.dromara.common.redis.utils.RedisUtils; import org.dromara.system.api.RemoteDataScopeService; +import org.dromara.system.domain.DeviceRedis; import org.dromara.system.domain.SysdeptJly; import org.dromara.system.domain.vo.DeviceStaticsVo; import org.dromara.system.domain.vo.SysdeptJlyVo; import org.dromara.system.domain.vo.TDeviceExportVo; +import org.dromara.system.mapper.DeviceRedisMapper; +import org.dromara.system.mapper.SysConfigMapper; import org.dromara.system.mapper.SysDeptJlyMapper; +import org.dromara.system.service.ISysConfigService; import org.springframework.stereotype.Service; import org.dromara.system.domain.bo.TDeviceBo; import org.dromara.system.domain.vo.TDeviceVo; @@ -47,6 +52,12 @@ public class TDeviceServiceImpl implements ITDeviceService { private final SysDeptJlyMapper deptJlyMapper; + private final ISysConfigService configService; + + private final DeviceRedisMapper redisMapper; + + private String lastRemoveTime; + @DubboReference private RemoteDataScopeService remoteDataScopeService; @@ -124,6 +135,53 @@ public class TDeviceServiceImpl implements ITDeviceService { return baseMapper.selectDeviceExportList(lqw); } + + /* + * 删除长时间未更新的执法记录仪 + * */ + @Override + public int deleteZfjly() { + String day = configService.selectConfigByKey("device.remove.day"); + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.inSql(TDevice::getDeviceType,"'5','7','8'"); + lqw.eq(TDevice::getValid,"1"); + lqw.le(TDevice::getUpdateTime,DateUtil.offsetDay(new Date(),Integer.getInteger(day))); + List list = baseMapper.selectList(lqw); + for (TDevice device : list) { + device.setValid(0); + device.setUpdateTime(DateUtil.now()); + baseMapper.updateById(device); + } + return 0; + } + + /* + * 删除状态为删除的设备定位信息和存在t_device_redis的数据 + * */ + + @Override + public int deleteRedis() { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.gt(StringUtils.isNotBlank(lastRemoveTime),TDevice::getUpdateTime,lastRemoveTime); + lqw.eq(TDevice::getValid,0); + lqw.orderByDesc(TDevice::getUpdateTime); + List list = baseMapper.selectVoList(lqw); + try { + if (list.size()>0){ + lastRemoveTime = list.get(0).getUpdateTime(); + for (TDeviceVo deviceVo : list) { + RedisUtils.del("online_users:"+deviceVo.getDeviceType()+":"+deviceVo.getDeviceCode()); + LambdaQueryWrapper dqw = new LambdaQueryWrapper<>(); + dqw.eq(DeviceRedis::getDeviceCode,deviceVo.getDeviceCode()); + redisMapper.delete(dqw); + } + } + }catch (Exception e){ + + } + return 0; + } + @Override public TDeviceVo queryOne(TDeviceBo bo) { LambdaQueryWrapper lqw = buildQueryWrapper(bo); @@ -235,22 +293,20 @@ public class TDeviceServiceImpl implements ITDeviceService { @Override public Boolean batchSaveOrUpdate(List list) { boolean flag = true; - // 先根据 field1 和 field2 查询出已存在的记录 - /*List existingEntities = baseMapper.selectList(new QueryWrapper() - .in("device_code", list.stream().map(TDevice::getDeviceCode).collect(Collectors.toList())) - .in("device_type", list.stream().map(TDevice::getDeviceType).collect(Collectors.toList()))); -*/ // 找到需要更新的记录 List toUpdate = new ArrayList<>(); // 找到需要插入的记录 List toInsert = new ArrayList<>(); - LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + for (TDevice entity : list) { // boolean exists = false; if (entity.getDeviceType().equals("5") || entity.getDeviceType().equals("8") || entity.getDeviceType().equals("7")){ // 记录仪、5G车载、布控球 处理机构 + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(SysdeptJly::getQyCode,entity.getZzjgdm()); SysdeptJlyVo jlyVo = deptJlyMapper.selectVoOne(lqw); + entity.setZzjgdm("341800000000"); + entity.setZzjgmc("宣城市公安局"); if (null != jlyVo){ entity.setZzjgdm(jlyVo.getDeptId()); entity.setZzjgmc(jlyVo.getDeptName()); @@ -258,28 +314,8 @@ public class TDeviceServiceImpl implements ITDeviceService { baseMapper.insertOrUpdateByCodeAndType(entity); } - /*for (TDevice existingEntity : existingEntities) { - if (entity.getDeviceCode().equals(existingEntity.getDeviceCode()) && entity.getDeviceType().equals(existingEntity.getDeviceType())) { - entity.setId(existingEntity.getId()); // 设置 ID 以便更新 - toUpdate.add(entity); - exists = true; - break; - } - } - if (!exists) { - toInsert.add(entity); - }*/ } - // 批量更新 - /*if (!toUpdate.isEmpty()) { - flag = baseMapper.updateBatchById(toUpdate); - } - - // 批量插入 - if (!toInsert.isEmpty()) { - flag = baseMapper.insertBatch(toInsert); // insertBatchSomeColumn 是 MyBatis-Plus 提供的批量插入方法 - }*/ return flag; // return baseMapper.insertOrUpdateBatch(List); } diff --git a/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/DeviceRedisMapper.xml b/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/DeviceRedisMapper.xml index 997e2f2f..aa66df48 100644 --- a/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/DeviceRedisMapper.xml +++ b/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/DeviceRedisMapper.xml @@ -46,4 +46,9 @@ WHERE d.dict_type = 'zd_device_type' + + diff --git a/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/TDeviceMapper.xml b/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/TDeviceMapper.xml index 42a53d6c..23e996b7 100644 --- a/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/TDeviceMapper.xml +++ b/stwzhj-modules/wzhj-system/src/main/resources/mapper/system/TDeviceMapper.xml @@ -49,8 +49,8 @@ #{remark1},#{remark2},#{cardNum},#{createTime},#{updateTime}) ON DUPLICATE KEY UPDATE zzjgdm = values(zzjgdm),zzjgmc = values(zzjgmc),police_no = values(police_no),police_name = values(police_name),phone_num = values(phone_num), - car_num = values(car_num),valid = values(valid),remark1 = values(remark1),remark2 = values(remark2),card_num = values(card_num), - update_time = now() + car_num = values(car_num),valid = '1',remark1 = values(remark1),remark2 = values(remark2),card_num = values(card_num), + update_time = values(update_time) diff --git a/stwzhj-modules/wzhj-websocket/src/main/java/org/dromara/webscoket/config/ThreadConfig.java b/stwzhj-modules/wzhj-websocket/src/main/java/org/dromara/webscoket/config/ThreadConfig.java deleted file mode 100644 index 0c481820..00000000 --- a/stwzhj-modules/wzhj-websocket/src/main/java/org/dromara/webscoket/config/ThreadConfig.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.dromara.webscoket.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.EnableScheduling; - -import java.util.concurrent.ScheduledThreadPoolExecutor; - -/** - *

description:

- * - * @author chenle - * @date 2022-03-15 10:11 - */ -@Configuration -@EnableScheduling -public class ThreadConfig { - @Bean - public ScheduledThreadPoolExecutor scheduledExecutorService() { - ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(8); - return executor; - } -} diff --git a/stwzhj-modules/wzhj-websocket/src/main/java/org/dromara/webscoket/schedule/DeviceSchedule.java b/stwzhj-modules/wzhj-websocket/src/main/java/org/dromara/webscoket/schedule/DeviceSchedule.java index 83a75824..3cac6f68 100644 --- a/stwzhj-modules/wzhj-websocket/src/main/java/org/dromara/webscoket/schedule/DeviceSchedule.java +++ b/stwzhj-modules/wzhj-websocket/src/main/java/org/dromara/webscoket/schedule/DeviceSchedule.java @@ -75,6 +75,7 @@ public class DeviceSchedule { newDevice.setDeviceCode(deviceCode); if (originDevice.getNickname().contains("皖")){ newDevice.setDeviceType("8"); + newDevice.setCarNum(originDevice.getNickname()); }else if(originDevice.getNickname().contains("布控球")) { newDevice.setDeviceType("7"); }else { diff --git a/stwzhj-modules/wzhj-websocket/src/main/resources/application.yml b/stwzhj-modules/wzhj-websocket/src/main/resources/application.yml index 8261485c..a3298e73 100644 --- a/stwzhj-modules/wzhj-websocket/src/main/resources/application.yml +++ b/stwzhj-modules/wzhj-websocket/src/main/resources/application.yml @@ -6,7 +6,7 @@ server: spring: application: # 应用名称 - name: wzhj-webscoket + name: wzhj-websocket profiles: # 环境配置 active: @profiles.active@ diff --git a/stwzhj-modules/wzhj-websocket/src/main/resources/logback-plus.xml b/stwzhj-modules/wzhj-websocket/src/main/resources/logback-plus.xml new file mode 100644 index 00000000..0be6f549 --- /dev/null +++ b/stwzhj-modules/wzhj-websocket/src/main/resources/logback-plus.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + ${log.path}/info.${log.file}.log + + INFO + ACCEPT + DENY + + + ${log.path}/info/info.${log.file}.%d{yyyy-MM-dd}.%i.log.gz + ${MAX_FILE_SIZE} + ${MAX_HISTORY} + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + ${log.path}/error.${log.file}.log + + ERROR + + + ${log.path}/error/error.${log.file}.%d{yyyy-MM-dd}.%i.log.gz + ${MAX_FILE_SIZE} + ${MAX_HISTORY} + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + +