diff --git a/stwzhj-api/pom.xml b/stwzhj-api/pom.xml index 38a3e4a9..7628b723 100644 --- a/stwzhj-api/pom.xml +++ b/stwzhj-api/pom.xml @@ -14,6 +14,7 @@ stwzhj-api-resource stwzhj-api-workflow stwzhj-api-data2es + stwzhj-api-location stwzhj-api diff --git a/stwzhj-api/stwzhj-api-bom/pom.xml b/stwzhj-api/stwzhj-api-bom/pom.xml index f1e1c317..97770712 100644 --- a/stwzhj-api/stwzhj-api-bom/pom.xml +++ b/stwzhj-api/stwzhj-api-bom/pom.xml @@ -47,6 +47,12 @@ ${revision} + + org.dromara + stwzhj-api-location + ${revision} + + diff --git a/stwzhj-api/stwzhj-api-location/pom.xml b/stwzhj-api/stwzhj-api-location/pom.xml new file mode 100644 index 00000000..08f5be64 --- /dev/null +++ b/stwzhj-api/stwzhj-api-location/pom.xml @@ -0,0 +1,33 @@ + + + + org.dromara + stwzhj-api + ${revision} + + 4.0.0 + + stwzhj-api-location + + + stwzhj-api-location + + + + + + + org.dromara + stwzhj-common-core + + + + org.dromara + stwzhj-common-excel + + + + + diff --git a/stwzhj-api/stwzhj-api-location/src/main/java/org/dromara/location/api/RemoteElasticSearchService.java b/stwzhj-api/stwzhj-api-location/src/main/java/org/dromara/location/api/RemoteElasticSearchService.java new file mode 100644 index 00000000..fcaa62fb --- /dev/null +++ b/stwzhj-api/stwzhj-api-location/src/main/java/org/dromara/location/api/RemoteElasticSearchService.java @@ -0,0 +1,8 @@ +package org.dromara.location.api; + +import java.util.List; + +public interface RemoteElasticSearchService { + + List linstenDataStatus(); +} diff --git a/stwzhj-modules/stwzhj-consumer/src/main/resources/logback-plus.xml b/stwzhj-modules/stwzhj-consumer/src/main/resources/logback-plus.xml index caaa3455..efdad6ff 100644 --- a/stwzhj-modules/stwzhj-consumer/src/main/resources/logback-plus.xml +++ b/stwzhj-modules/stwzhj-consumer/src/main/resources/logback-plus.xml @@ -6,13 +6,13 @@ - + @@ -21,8 +21,66 @@ - - - + + + + + + ERROR + + DENY + + ACCEPT + + + ${LOG_PATH}${LOG_FILE} + + UTF-8 + %date [%level] [%thread] %logger{60} [%file : %line] %msg%n + + + ${LOG_PATH}info/${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz + 50MB + 20 + + + + + + + + Error + + + ${LOG_PATH}error.${LOG_FILE} + + + + ${LOG_PATH}error/${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz + + 50MB + 180 + + + + + + UTF-8 + %date [%level] [%thread] %logger{60} [%file : %line] %msg%n + + + + + + + + diff --git a/stwzhj-modules/stwzhj-location/pom.xml b/stwzhj-modules/stwzhj-location/pom.xml index 17f45728..f7f7750d 100644 --- a/stwzhj-modules/stwzhj-location/pom.xml +++ b/stwzhj-modules/stwzhj-location/pom.xml @@ -103,6 +103,12 @@ org.dromara stwzhj-api-resource + + + org.dromara + stwzhj-api-location + + org.elasticsearch diff --git a/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/dubbo/RemoteElasticSearchServiceImpl.java b/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/dubbo/RemoteElasticSearchServiceImpl.java new file mode 100644 index 00000000..020a27a3 --- /dev/null +++ b/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/dubbo/RemoteElasticSearchServiceImpl.java @@ -0,0 +1,23 @@ +package org.dromara.location.dubbo; + +import lombok.RequiredArgsConstructor; +import org.apache.dubbo.config.annotation.DubboService; +import org.dromara.location.api.RemoteElasticSearchService; +import org.dromara.location.service.ISearchService; +import org.springframework.stereotype.Service; + +import java.util.List; + +@RequiredArgsConstructor +@Service +@DubboService +public class RemoteElasticSearchServiceImpl implements RemoteElasticSearchService { + + private final ISearchService searchService; + + + @Override + public List linstenDataStatus() { + return searchService.linstenDataStatus(); + } +} diff --git a/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/service/ISearchService.java b/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/service/ISearchService.java index 55915b5d..068d08e3 100644 --- a/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/service/ISearchService.java +++ b/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/service/ISearchService.java @@ -1,5 +1,7 @@ package org.dromara.location.service; +import org.dromara.system.api.domain.vo.RemoteDictDataVo; + import java.util.List; import java.util.Map; @@ -7,5 +9,10 @@ import java.util.Map; public interface ISearchService { public List searchCar(String deviceCode, String startTime, String endTime,String deviceType) ; + /* + * 监听ES不同设备数据状态 + * */ + public List linstenDataStatus(); + } diff --git a/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/service/impl/SearchServiceImpl.java b/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/service/impl/SearchServiceImpl.java index 2e60d742..0df807c0 100644 --- a/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/service/impl/SearchServiceImpl.java +++ b/stwzhj-modules/stwzhj-location/src/main/java/org/dromara/location/service/impl/SearchServiceImpl.java @@ -2,9 +2,14 @@ package org.dromara.location.service.impl; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; import lombok.RequiredArgsConstructor; +import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.location.service.ISearchService; +import org.dromara.system.api.RemoteDictService; +import org.dromara.system.api.domain.vo.RemoteDictDataVo; import org.elasticsearch.action.search.*; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.RequestOptions; @@ -13,20 +18,22 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.TermQueryBuilder; +import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.IOException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -38,6 +45,11 @@ public class SearchServiceImpl implements ISearchService { @Autowired private RestHighLevelClient restHighLevelClient; + @DubboReference + RemoteDictService dictService; + + + @Override public List searchCar(String deviceCode, String startTime, String endTime,String deviceType) throws RuntimeException{ @@ -117,8 +129,47 @@ public class SearchServiceImpl implements ISearchService { return sourceList; } + @Override + public List linstenDataStatus() { + List list = dictService.selectDictDataByType("zd_device_type"); + List maps = new ArrayList<>(); + for (RemoteDictDataVo dataVo : list) { + try { + BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery(); + // 匹配第二个 + TermQueryBuilder termTerminalBuilder2 = QueryBuilders.termQuery("deviceType", dataVo.getDictValue()); + boolBuilder.must(termTerminalBuilder2); + SearchRequest searchRequest = new SearchRequest(); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + //排序条件 + searchSourceBuilder.sort("gpsTime", SortOrder.DESC); + searchSourceBuilder.query(boolBuilder); + searchSourceBuilder.size(1); + searchRequest.source(searchSourceBuilder); + // 执行查询,然后处理响应结果 + SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); + // 根据状态和数据条数验证是否返回了数据 + if (RestStatus.OK.equals(searchResponse.status()) && searchResponse.getHits().getTotalHits().value > 0) { + SearchHits hits = searchResponse.getHits(); + for (SearchHit hit : hits) { + // 将 JSON 转换成对象 + Map sourceAsMap = hit.getSourceAsMap(); + String time = sourceAsMap.get("gpsTime").toString(); + if (DateUtil.between(new Date(),DateUtil.parseDateTime(time) , DateUnit.MINUTE)>=30){ + maps.add(dataVo.getDictLabel()); + } + } + } + }catch (Exception e){ + e.printStackTrace(); + } + + } + return maps; + } + private List findEsIndexByTime(String startTime, String endTime) { startTime = startTime.substring(0, 10).replaceAll("-","");//yyyyMMdd diff --git a/stwzhj-modules/stwzhj-system/pom.xml b/stwzhj-modules/stwzhj-system/pom.xml index 2f608feb..e638f8c2 100644 --- a/stwzhj-modules/stwzhj-system/pom.xml +++ b/stwzhj-modules/stwzhj-system/pom.xml @@ -104,6 +104,11 @@ stwzhj-api-resource + + org.dromara + stwzhj-api-location + + com.github.jeffreyning mybatisplus-plus diff --git a/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/controller/system/IndexStaticsController.java b/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/controller/system/IndexStaticsController.java index 0fb2b008..0d5049d5 100644 --- a/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/controller/system/IndexStaticsController.java +++ b/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/controller/system/IndexStaticsController.java @@ -4,14 +4,20 @@ package org.dromara.system.controller.system; import cn.hutool.core.date.DateUtil; import jdk.dynalink.linker.LinkerServices; import lombok.RequiredArgsConstructor; +import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.domain.R; import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.web.core.BaseController; +import org.dromara.location.api.RemoteElasticSearchService; import org.dromara.system.domain.DeviceRedis; +import org.dromara.system.domain.SysNotice; import org.dromara.system.domain.bo.SysDeptBo; +import org.dromara.system.domain.bo.SysNoticeBo; import org.dromara.system.domain.bo.TDeviceBo; import org.dromara.system.domain.vo.*; import org.dromara.system.service.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.*; import java.util.*; @@ -28,6 +34,12 @@ public class IndexStaticsController extends BaseController { private final IDeviceRedisService redisService; + private final ISysNoticeService noticeService; + + @DubboReference + RemoteElasticSearchService elasticSearchService; + + /* @@ -75,6 +87,27 @@ public class IndexStaticsController extends BaseController { return R.ok(maps); } + /* + * 通过ES来监听各类设备定位是否正常 + * */ + @Scheduled(cron = "0 */30 * * * ?") + public void listen(){ + List strs = elasticSearchService.linstenDataStatus(); + if (strs.size() >0){ + List nlist = noticeService.selectTodayNoticeList(); + if (nlist.size() <=2){ + // -- todo 发送短信 + SysNoticeBo noticeBo = new SysNoticeBo(); + noticeBo.setNoticeTitle("手机号码"); + noticeBo.setNoticeType("3"); + noticeBo.setNoticeContent(strs.toString()+"数据不正常,请检查服务是否正常"); + noticeBo.setCreateTime(DateUtil.date()); + noticeService.insertNotice(noticeBo); + } + + } + } + /* * 各地市总数和在线数 * */ diff --git a/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/service/ISysNoticeService.java b/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/service/ISysNoticeService.java index 8ec999d0..f24596ec 100644 --- a/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/service/ISysNoticeService.java +++ b/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/service/ISysNoticeService.java @@ -33,6 +33,8 @@ public interface ISysNoticeService { */ List selectNoticeList(SysNoticeBo notice); + List selectTodayNoticeList(); + /** * 新增公告 * diff --git a/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/service/impl/SysNoticeServiceImpl.java b/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/service/impl/SysNoticeServiceImpl.java index db63e61d..226a6fb3 100644 --- a/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/service/impl/SysNoticeServiceImpl.java +++ b/stwzhj-modules/stwzhj-system/src/main/java/org/dromara/system/service/impl/SysNoticeServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.system.service.impl; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -20,6 +21,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.Arrays; +import java.util.Date; import java.util.List; /** @@ -64,6 +66,14 @@ public class SysNoticeServiceImpl implements ISysNoticeService { return baseMapper.selectVoList(lqw); } + @Override + public List selectTodayNoticeList() { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.likeRight(SysNotice::getCreateTime, DateUtil.formatDate(new Date())); + lqw.eq(SysNotice::getNoticeType,"3"); + return baseMapper.selectVoList(lqw); + } + private LambdaQueryWrapper buildQueryWrapper(SysNoticeBo bo) { LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.like(StringUtils.isNotBlank(bo.getNoticeTitle()), SysNotice::getNoticeTitle, bo.getNoticeTitle());