diff --git a/ruoyi-admin/src/main/java/com/ruoyi/pt/entity/Keyperson.java b/ruoyi-admin/src/main/java/com/ruoyi/pt/entity/Keyperson.java new file mode 100644 index 0000000..a327f09 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/pt/entity/Keyperson.java @@ -0,0 +1,37 @@ +package com.ruoyi.pt.entity; + + +import cn.hutool.core.annotation.Alias; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.io.Serializable; + + +/** + * (Keyperson)表实体类 + * + * @author wu + * @since 2024-04-26 17:24:36 + */ +@Data +@ApiModel("实体类") +@TableName(value = "keyperson") +public class Keyperson implements Serializable { + + private static final long serialVersionUID = -45344189272733752L; + @TableId(type = IdType.AUTO) + private Long id; + @Alias(value = "RYLX_NAME") + private String aspect1; + @Alias(value = "RYLXDETAIL_NAME") + private String aspect2; + @Alias(value = "XM") + private String keypersonName; + @Alias(value = "LXDH") + private String keypersonTel; +} + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/pt/mapper/KeypersonMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/pt/mapper/KeypersonMapper.java new file mode 100644 index 0000000..79e361d --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/pt/mapper/KeypersonMapper.java @@ -0,0 +1,19 @@ +package com.ruoyi.pt.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.pt.entity.Keyperson; + +/** + * (Keyperson)表数据库访问层 + * + * @author wu + * @since 2024-04-26 17:24:36 + */ +public interface KeypersonMapper extends BaseMapper { + + /** + * 删除重点人员数据 + */ + void delAll(); +} + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/pt/quartz/KeypersonQuartz.java b/ruoyi-admin/src/main/java/com/ruoyi/pt/quartz/KeypersonQuartz.java new file mode 100644 index 0000000..ed28220 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/pt/quartz/KeypersonQuartz.java @@ -0,0 +1,64 @@ +package com.ruoyi.pt.quartz; + +import cn.hutool.http.HttpRequest; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.pt.entity.Keyperson; +import com.ruoyi.pt.service.KeypersonService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.List; + +/** + * 获取重点人员数据 + * + * @author wu + * @since 2024/4/26 下午5:30 + */ +@Component +@EnableScheduling +@Async +@Transactional(rollbackFor = Exception.class) +//@RestController +//@RequestMapping("remoteCall/test") +//@Api(tags = "获取重点人员数据") +public class KeypersonQuartz { + + public static final Logger log = LoggerFactory.getLogger(KeypersonQuartz.class); + + @Resource + private KeypersonService keypersonService; + + @Value("${keyPersonUrl}") + private String keyPersonUrl; + + // @GetMapping("/zdry") +// @ApiOperation(value = "获取重点人员数据") + @Scheduled(cron = "0 30 2 * * ?") + public synchronized void pushData() { + log.info("==============获取重点人员数据开始" + LocalDateTime.now() + "============"); + + String res = HttpRequest.get(keyPersonUrl) + .header("appId", "szjsc") + .header("appSecret", "cUuC51fB").execute().body(); + JSONObject resObj = JSON.parseObject(res); + String dataList = resObj.getString("data"); + List list = JSONUtil.toList(dataList, Keyperson.class); + log.info("==============获取重点人员数据条数" + list.size() + "============"); + // 删除重点人员数据 + keypersonService.delAll(); + // 保存重点人员数据 + keypersonService.saveBatch(list); + log.info("==============获取重点人员数据结束" + LocalDateTime.now() + "============"); + } +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/pt/service/KeypersonService.java b/ruoyi-admin/src/main/java/com/ruoyi/pt/service/KeypersonService.java new file mode 100644 index 0000000..f8d91ac --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/pt/service/KeypersonService.java @@ -0,0 +1,19 @@ +package com.ruoyi.pt.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.pt.entity.Keyperson; + +/** + * (Keyperson)表服务接口 + * + * @author wu + * @since 2024-04-26 17:24:36 + */ +public interface KeypersonService extends IService { + + /** + * 删除重点人员数据 + */ + void delAll(); +} + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/pt/service/impl/KeypersonServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/pt/service/impl/KeypersonServiceImpl.java new file mode 100644 index 0000000..e909582 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/pt/service/impl/KeypersonServiceImpl.java @@ -0,0 +1,26 @@ +package com.ruoyi.pt.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.pt.mapper.KeypersonMapper; +import com.ruoyi.pt.entity.Keyperson; +import com.ruoyi.pt.service.KeypersonService; +import org.springframework.stereotype.Service; + +/** + * (Keyperson)表服务实现类 + * + * @author wu + * @since 2024-04-26 17:24:36 + */ +@Service("keypersonService") +public class KeypersonServiceImpl extends ServiceImpl implements KeypersonService { + + /** + * 删除重点人员数据 + */ + @Override + public void delAll() { + baseMapper.delAll(); + } +} + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/pt/service/impl/RemoteCallsServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/pt/service/impl/RemoteCallsServiceImpl.java index ae27be8..c58b20a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/pt/service/impl/RemoteCallsServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/pt/service/impl/RemoteCallsServiceImpl.java @@ -4,12 +4,14 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpException; import cn.hutool.http.HttpRequest; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.pt.entity.CasesImport; import com.ruoyi.pt.entity.Events; import com.ruoyi.pt.entity.dto.RemoteCallsDTO; @@ -62,6 +64,9 @@ public class RemoteCallsServiceImpl implements RemoteCallsService { @Resource private CasesImportService casesImportService; + @Resource + private RedisCache redisCache; + /** * 获取填充信息后的map * @@ -106,74 +111,87 @@ public class RemoteCallsServiceImpl implements RemoteCallsService { QueryWrapper queryWrapper = new QueryWrapper<>(); if (allPush != null && allPush == 1) { // 获取当天的日期 -// LocalDate localDate = LocalDate.now(); -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); -// // 当天 -// String eventTime = localDate.format(formatter); - //获取上个小时 - String eventTime = DateUtil.offsetHour(DateUtil.date(), -1).toString("yyyy-MM-dd HH"); - queryWrapper.and(wrapper -> wrapper.gt("eventTime", eventTime)); + // LocalDate localDate = LocalDate.now(); + // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + // // 当天 + // String eventTime = localDate.format(formatter); + String eventTime; + // 获取redis上次异常的时间 + Object obj = redisCache.getCacheObject("eventTime"); + if (BeanUtil.isNotEmpty(obj)) { + eventTime = (String) obj; + redisCache.deleteObject("eventTime"); + } else { + //获取上个小时 + eventTime = DateUtil.offsetHour(DateUtil.date(), -1).toString("yyyy-MM-dd HH"); + } + queryWrapper.and(wrapper -> wrapper.ge("eventTime", eventTime)); } - queryWrapper.and(wrapper -> wrapper.isNotNull("innerEventId").ne("innerEventId", "")).isNull("state"); - // 创建SimpleDateFormat对象,指定日期格式为yyyy-MM-dd HH:mm:ss - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - // 循环获取所有数据 - while (true) { - IPage dataPage = eventsService.page(page, queryWrapper); - List data = dataPage.getRecords(); - List dtos = BeanUtil.copyToList(data, RemoteCallsDTO.class); - num += dtos.size(); - log.info("==========推送数据条数=========> " + dtos.size()); - dtos.forEach(x -> { - x.setContent(x.getTitle()); - // 使用SimpleDateFormat对象将Date对象格式化为字符串 - String firstWarnTime = sdf.format(x.getFirstWarnTimeDate()); - String eventTime = sdf.format(x.getEventTimeDate()); - x.setFirstWarnTime(firstWarnTime); - x.setEventTime(firstWarnTime); - x.setLastWarnTime(eventTime); - // 获取relationNums转成数组 - JSONArray jsonArray = JSONUtil.parseArray(x.getRelationNums()); - List list = jsonArray.toList(String.class); - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("CASE_SERIAL", list.get(0)); - CasesImport casesImport = casesImportService.getOne(wrapper); - if (BeanUtil.isNotEmpty(casesImport)) { - // 如果是紧急事件content使用原始工单的content - if ("3".equals(x.getScenceType())) { - x.setContent(casesImport.getCaseContent()); - } else { - x.setContent(x.getTitle()); - } - // 如果类型是同人事件,上报⼈姓名和电话不取原始工单,直接从预警因素字段取,顿号分隔。 - if ("2".equals(x.getScenceType())) { - String warnFactor = x.getWarnFactor(); - String[] split = warnFactor.split("、"); - if (split.length == 2) { - x.setEventCreatorTel(split[0]); - x.setEventCreator(split[1]); + try { + queryWrapper.and(wrapper -> wrapper.isNotNull("innerEventId").ne("innerEventId", "")).isNull("state"); + // 创建SimpleDateFormat对象,指定日期格式为yyyy-MM-dd HH:mm:ss + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 循环获取所有数据 + while (true) { + IPage dataPage = eventsService.page(page, queryWrapper); + List data = dataPage.getRecords(); + List dtos = BeanUtil.copyToList(data, RemoteCallsDTO.class); + num += dtos.size(); + log.info("==========推送数据条数=========> " + dtos.size()); + dtos.forEach(x -> { + x.setContent(x.getTitle()); + // 使用SimpleDateFormat对象将Date对象格式化为字符串 + String firstWarnTime = sdf.format(x.getFirstWarnTimeDate()); + String eventTime = sdf.format(x.getEventTimeDate()); + x.setFirstWarnTime(firstWarnTime); + x.setEventTime(firstWarnTime); + x.setLastWarnTime(eventTime); + // 获取relationNums转成数组 + JSONArray jsonArray = JSONUtil.parseArray(x.getRelationNums()); + List list = jsonArray.toList(String.class); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("CASE_SERIAL", list.get(0)); + CasesImport casesImport = casesImportService.getOne(wrapper); + if (BeanUtil.isNotEmpty(casesImport)) { + // 如果是紧急事件content使用原始工单的content + if ("3".equals(x.getScenceType())) { + x.setContent(casesImport.getCaseContent()); + } else { + x.setContent(x.getTitle()); + } + // 如果类型是同人事件,上报⼈姓名和电话不取原始工单,直接从预警因素字段取,顿号分隔。 + if ("2".equals(x.getScenceType())) { + String warnFactor = x.getWarnFactor(); + String[] split = warnFactor.split("、"); + if (split.length == 2) { + x.setEventCreatorTel(split[0]); + x.setEventCreator(split[1]); + } else { + x.setEventCreatorTel(split[0]); + } } else { - x.setEventCreatorTel(split[0]); + x.setEventCreator(casesImport.getCreatorName()); + x.setEventCreatorTel(casesImport.getCreatorTel()); } - } else { - x.setEventCreator(casesImport.getCreatorName()); - x.setEventCreatorTel(casesImport.getCreatorTel()); + x.setEventPlaceName(casesImport.getCaseAddress()); + x.setEventCoordinate(casesImport.getCaseLnglat()); } - x.setEventPlaceName(casesImport.getCaseAddress()); - x.setEventCoordinate(casesImport.getCaseLnglat()); + }); + String jsonStr = JSONUtil.toJsonStr(dtos); + HttpRequest.post(url + "/gateway/event/event/eventData/imports").header("Authorization", "Bearer " + accessToken).body(jsonStr).execute().body(); + // 判断是否还有下一页 + if (dataPage.getPages() > dataPage.getCurrent()) { + // 设置下一页的页码 + page.setCurrent(page.getCurrent() + 1); + } else { + log.info("==========推送完成========="); + // 已经获取完所有数据,结束循环 + return num; } - }); - String jsonStr = JSONUtil.toJsonStr(dtos); - HttpRequest.post(url + "/gateway/event/event/eventData/imports").header("Authorization", "Bearer " + accessToken).body(jsonStr).execute().body(); - // 判断是否还有下一页 - if (dataPage.getPages() > dataPage.getCurrent()) { - // 设置下一页的页码 - page.setCurrent(page.getCurrent() + 1); - } else { - log.info("==========推送完成========="); - // 已经获取完所有数据,结束循环 - return num; } + } catch (HttpException e) { + redisCache.setCacheObject("eventTime", DateUtil.offsetHour(DateUtil.date(), -1).toString("yyyy-MM-dd HH")); + return 0; } } @@ -362,9 +380,7 @@ public class RemoteCallsServiceImpl implements RemoteCallsService { log.info("一共获取" + list.size() + "条数据"); if (CollectionUtil.isNotEmpty(list)) { // 过滤数据 - List filteredList = list.stream() - .filter(casesImport -> !casesImport.getEventExt().contains("12345便民-咨询")) - .collect(Collectors.toList()); + List filteredList = list.stream().filter(casesImport -> !casesImport.getEventExt().contains("12345便民-咨询")).collect(Collectors.toList()); log.info("======================================="); log.info("过滤后剩下" + filteredList.size() + "条数据"); num += filteredList.size(); diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 91c4f95..2765810 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -133,4 +133,6 @@ remote: url: https://4.15.24.101:10443 appKey: 7ae6c089a348b3565af38313f5610968 appSecret: 633e549c5b382cb8da14e36d9eeca3bc - grantType: client_credentials \ No newline at end of file + grantType: client_credentials + +keyPersonUrl: http://3.15.23.11/dc-easyapi/server/zhcg/getWsryToSF \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/mapper/pt/KeypersonMapper.xml b/ruoyi-admin/src/main/resources/mapper/pt/KeypersonMapper.xml new file mode 100644 index 0000000..ebbb9b0 --- /dev/null +++ b/ruoyi-admin/src/main/resources/mapper/pt/KeypersonMapper.xml @@ -0,0 +1,11 @@ + + + + + + + TRUNCATE TABLE keyperson + + \ No newline at end of file